Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope CookSystem initializer InitCookSystem
globals
string CookBar
//*********************************Configurable Variables******************************************************************
constant string StartCookEffect="Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl" //* Effect when the cook starts
constant string EndCookEffect="Abilities\\Spells\\Human\\Feedback\\SpellBreakerAttack.mdl" //* Effect when the cook ends
constant string CookFailedText="Cook Failed!" //* String when cook failed
constant string BarStartingColorCode="|cff80ccff" //* The string of the starting of the bar
constant integer StartCookSpellRawCode='A000' //* Spell rawcode of start-cook
constant integer StopCookSpellRawCode='A001' //* Spell rawcode of stop-cook
constant integer RawMeatCode='I000' //* Item rawcode of raw meat
constant integer HalfCookedMeatCode='I001' //* Item rawcode of half-cooked meat
constant integer NormalMeatCode='I004' //* Item rawcode of normal meat
constant integer PerfectMeatCode='I002' //* Item rawcode of perfect meat
constant integer BurntMeatCode='I003' //* Item rawcode of burnt meat
constant integer CookingFirePitCode='h002' //* Cooking fire pit rawcode
constant integer PercentageAddPerTime=2 //* Percentage add per speed time
constant integer BarColorRed=255 //* Color vertex of bar RED
constant integer BarColorGreen=255 //* Color vertex of bar GREEN
constant integer BarColorBlue=255 //* Color vertex of bar BLUE
constant integer MaxPercentage=130 //* The max percentage the cook system will reach.
constant integer HalfCook=72 //* Percentage of max for half cook
constant integer NormalCook=100 //* Percentage of max for normal cook
constant integer PerfectCook=106 //* Percentage of max for perfect cook
constant real Speed=0 //* Lower value gives faster speed
constant real BarSize=0.017 //* The size of the bar
trigger gg_trg_Cook_Stop=null
endglobals
private constant function CookSystemConditions takes nothing returns boolean
return GetSpellAbilityId() == StartCookSpellRawCode
endfunction
private function CookSystemActions takes nothing returns nothing
local unit fireplace = GetTriggerUnit()
local unit pig
local real x = GetUnitX(fireplace)
local real y = GetUnitY(fireplace)
local integer percentage = 0
local integer loopint = 0
local integer index = GetPlayerId(GetOwningPlayer(fireplace))
local texttag text = CreateTextTag()
local real xvel = 0.04 * Cos(90 * bj_DEGTORAD)
local real yvel = 0.04 * Sin(90 * bj_DEGTORAD)
local item food = UnitItemInSlot(fireplace, 0)
call TriggerSleepAction(0)
if food != null and GetItemTypeId(food) == RawMeatCode then
call DestroyEffect(AddSpecialEffect(StartCookEffect, x, y))
call ShowUnit(fireplace, false)
set pig = CreateUnit(Player(index), CookingFirePitCode, x, y, 270)
if GetLocalPlayer() == Player(index) then
call SelectUnit(pig, true)
endif
loop
exitwhen percentage > MaxPercentage or GetWidgetLife(pig) == 199
if percentage >= NormalCook then
if percentage == NormalCook then
call SetUnitVertexColor(pig,128,64,64,255)
endif
if percentage == PerfectCook then
call SetUnitVertexColor(pig,64,64,64,255)
endif
call SetTextTagText(text, "Ready!" + " [" + I2S(percentage) + "%]", BarSize)
call SetTextTagPos(text, x - 55, y, 0)
call SetTextTagColor(text,BarColorRed, BarColorGreen, BarColorBlue, 255)
call SetTextTagVisibility(text, true)
else
set CookBar = BarStartingColorCode
loop
exitwhen loopint == percentage
set CookBar = CookBar + "l"
set loopint = loopint + PercentageAddPerTime
endloop
set CookBar = CookBar + "|r"
set loopint = 100 - percentage
loop
exitwhen loopint == 0
set CookBar = CookBar + "l"
set loopint = loopint - PercentageAddPerTime
endloop
call SetTextTagText(text, CookBar + " [" + I2S(percentage) + "%]", BarSize)
call SetTextTagPos(text, x - 110, y, 0)
call SetTextTagColor(text,BarColorRed, BarColorGreen, BarColorBlue, 255)
call SetTextTagVisibility(text, true)
if percentage == HalfCook then
call SetUnitVertexColor(pig,128,128,0,255)
endif
endif
call TriggerSleepAction(Speed)
set percentage = percentage + PercentageAddPerTime
endloop
call RemoveItem(food)
call RemoveUnit(pig)
call DestroyEffect(AddSpecialEffect(EndCookEffect, x, y))
call ShowUnit(fireplace, true)
call SetUnitPosition(fireplace, x, y)
if percentage > PerfectCook-1 then
call CreateItem(BurntMeatCode, x, y)
elseif percentage > NormalCook and percentage < PerfectCook then
call CreateItem(PerfectMeatCode, x, y)
elseif percentage > HalfCook-1 and percentage < NormalCook+1 then
call CreateItem(NormalMeatCode, x, y)
else
call CreateItem(HalfCookedMeatCode, x, y)
endif
call SetTextTagLifespan(text, 0.00)
call SetTextTagPermanent(text, false)
else
if food != null then
call UnitRemoveItem(fireplace, food)
endif
call SetTextTagText(text, CookFailedText, 0.017)
call SetTextTagPos(text, x - 60, y, 0)
call SetTextTagColor(text,BarColorRed, BarColorGreen, BarColorBlue, 255)
call SetTextTagLifespan(text, 1.00)
call SetTextTagPermanent(text, false)
call SetTextTagVelocity(text, xvel, yvel)
call SetTextTagVisibility(text, true)
endif
set pig = null
set food = null
set text = null
set fireplace = null
endfunction
private constant function CookStopConditions takes nothing returns boolean
return GetSpellAbilityId() == StopCookSpellRawCode
endfunction
private function CookStopActions takes nothing returns nothing
call SetWidgetLife(GetTriggerUnit(), 199)
endfunction
private constant function NullBoolean takes nothing returns boolean
return true
endfunction
//===========================================================================
function InitCookSystem takes nothing returns nothing
local integer index
set gg_trg_Cook_Stop = CreateTrigger( )
set gg_trg_Cook_System = CreateTrigger( )
set index = 0
loop
call TriggerRegisterPlayerUnitEvent(gg_trg_Cook_Stop, Player(index), EVENT_PLAYER_UNIT_SPELL_CHANNEL, Condition(function NullBoolean))
call TriggerRegisterPlayerUnitEvent(gg_trg_Cook_System, Player(index), EVENT_PLAYER_UNIT_SPELL_CHANNEL, Condition(function NullBoolean))
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition( gg_trg_Cook_Stop, Condition( function CookStopConditions ) )
call TriggerAddAction( gg_trg_Cook_Stop, function CookStopActions )
call TriggerAddCondition( gg_trg_Cook_System, Condition( function CookSystemConditions ) )
call TriggerAddAction( gg_trg_Cook_System, function CookSystemActions )
endfunction
endscope