//===========Change these!=========================
constant function Capitalism_Aura_Id1 takes nothing returns integer
return 'B000'//The raw code of the "Capitalism Aura" buff (Level 1)
endfunction
constant function Capitalism_Aura_Id2 takes nothing returns integer
return 'B001'//The raw code of the "Capitalism Aura" buff (Level 2)
endfunction
constant function Capitalism_Aura_Id3 takes nothing returns integer
return 'B002'//The raw code of the "Capitalism Aura" buff (Level 3)
endfunction
//===============================================
constant function H2I takes handle h returns integer
return h
return 0
endfunction
function Data takes nothing returns gamecache
return InitGameCache( "CapitalismAura.w3v" )
endfunction
function AttachHandle takes handle attached, handle attacher, string s returns nothing
call StoreInteger(Data(), I2S(H2I(attacher)), s, H2I(attached))
endfunction
function AttachInt takes integer attached, handle attacher, string s returns nothing
call StoreInteger(Data(), I2S(H2I(attacher)), s, attached)
endfunction
function RetrieveUnit takes handle attacher, string s returns unit
return GetStoredInteger(Data(), I2S(H2I(attacher)), s)
return null
endfunction
function RetrieveInt takes handle attacher, string s returns integer
return GetStoredInteger(Data(), I2S(H2I(attacher)), s)
endfunction
function Clear takes handle attacher returns nothing
call FlushStoredMission(Data(), I2S(H2I(attacher)))
endfunction
function DetectLevel takes unit u returns integer
local integer lvl = 0
if GetUnitAbilityLevel(u, Capitalism_Aura_Id1()) > 0 then
set lvl = 1
elseif GetUnitAbilityLevel(u, Capitalism_Aura_Id2()) > 0 then
set lvl = 2
elseif GetUnitAbilityLevel(u, Capitalism_Aura_Id3()) > 0 then
set lvl = 3
else
set lvl = 0
endif
return lvl
endfunction
function Capitalism_AuraChild takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = RetrieveUnit(t, "u")
local unit u2 = RetrieveUnit(t, "u2")
local player p = GetOwningPlayer(u2)
local integer lvl = RetrieveInt(t, "lvl")
local integer money = RetrieveInt(t, "m")
local integer money2 = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)
local integer add = (money2 - money) * 3
local texttag array text
local integer i = 0
call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, money2 + add)
loop
set i = i + 1
set text[i] = CreateTextTagUnitBJ( "+"+I2S(add/3), u, 0, 10, 100.00, 85.00, 15.00, 0 )
call SetTextTagPermanentBJ( text[i], false )
call SetTextTagLifespanBJ( text[i], 2.00 )
call SetTextTagFadepointBJ( text[i], 1.00 )
call SetTextTagVelocityBJ( text[i], 60.00, GetRandomReal(0, 360) )
set text[i] = null
exitwhen i == lvl
endloop
call Clear(t)
call DestroyTimer(t)
set t = null
set u = null
set u2 = null
set p = null
endfunction
function Capitalism_Aura takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit u2 = GetEventDamageSource()
local player p = GetOwningPlayer(u2)
local timer t = CreateTimer()
local integer money = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)
local integer lvl = DetectLevel(u)
if lvl > 0 and GetWidgetLife(u) - GetEventDamage() <= 0.405 then
call AttachHandle(u, t, "u")
call AttachHandle(u2, t, "u2")
call AttachInt(money, t, "m")
call AttachInt(lvl, t, "lvl")
call TimerStart(t, 0., false, function Capitalism_AuraChild)
else
endif
set u = null
set u2 = null
set p = null
set t = null
endfunction
//===========================================================================
function InitTrig_Capitalism_Aura takes nothing returns nothing
local trigger t = CreateTrigger()
call RegisterDmg(function Capitalism_Aura)
set t = null
endfunction