library Item initializer init requires /*
*/ BonusMod, /* http://www.wc3c.net/showthread.php?t=107940
*/ Movespeed /* http://www.hiveworkshop.com/threads/movespeed.287539/
*/
globals
private integer array abilities
private integer abilities_count = 0
endglobals
private function abilities_init_4 takes integer a1, integer a2, integer a3, integer a4 returns nothing
set abilities_count = abilities_count + 1
set abilities[abilities_count] = a1
set abilities_count = abilities_count + 1
set abilities[abilities_count] = a2
set abilities_count = abilities_count + 1
set abilities[abilities_count] = a3
set abilities_count = abilities_count + 1
set abilities[abilities_count] = a4
endfunction
private function init takes nothing returns nothing
call abilities_init_4('AHbz', 'AHwe', 'AHab', 'AHmt')
call abilities_init_4('AHtb', 'AHtc', 'AHbh', 'AHav')
call abilities_init_4('AHhb', 'AHds', 'AHad', 'AHre')
call abilities_init_4('AHfs', 'AHbn', 'AHdr', 'AHpx')
call abilities_init_4('AOwk', 'AOmi', 'AOcr', 'AOww')
call abilities_init_4('AOcl', 'AOfs', 'AOsf', 'AOeq')
call abilities_init_4('AOsh', 'AOws', 'AOae', 'AOre')
call abilities_init_4('AOhw', 'AOhx', 'AOsw', 'AOvd')
call abilities_init_4('AUdc', 'AUdp', 'AUau', 'AUan')
call abilities_init_4('AUcs', 'AUsl', 'AUav', 'AUin')
call abilities_init_4('AUfn', 'AUfu', 'AUdr', 'AUdd')
call abilities_init_4('AUim', 'AUts', 'AUcb', 'AUls')
call abilities_init_4('AEmb', 'AEim', 'AEev', 'AEme')
call abilities_init_4('AEer', 'AEfn', 'AEah', 'AEtq')
call abilities_init_4('AEst', 'AHfa', 'AEar', 'AEsf')
call abilities_init_4('AEfk', 'AEbl', 'AEsh', 'AEsv')
call abilities_init_4('ANsg', 'ANsq', 'ANsw', 'ANst')
call abilities_init_4('ANbf', 'ANdh', 'ANdb', 'ANef')
call abilities_init_4('ANfl', 'ANms', 'ANfa', 'ANto')
call abilities_init_4('ANsi', 'ANdr', 'ANba', 'ANch')
call abilities_init_4('ANrf', 'ANht', 'ANca', 'ANdo')
call abilities_init_4('ANsy', 'ANcs', 'ANeg', 'ANrg')
call abilities_init_4('ANhs', 'ANab', 'ANcr', 'ANtm')
call abilities_init_4('ANso', 'ANia', 'ANlm', 'ANvc')
endfunction
struct Item
string name
integer ability_id = 0
integer ability_level = 0
integer dmg = 0
integer arm = 0
integer str = 0
integer agi = 0
integer int = 0
real ms_perc = 0.0
integer ms_flat = 0
Movespeed ms
integer as = 0
integer life_reg = 0
integer mana_perc_reg = 0
static method create takes string name returns thistype
local thistype this = allocate()
set this.name = name
return this
endmethod
method ability takes integer id, integer level returns thistype
set this.ability_id = abilities[id]
set this.ability_level = level
return this
endmethod
method damage takes integer v returns thistype
set this.dmg = v
return this
endmethod
method armor takes integer v returns thistype
set this.arm = v
return this
endmethod
method strength takes integer v returns thistype
set this.str = v
return this
endmethod
method agility takes integer v returns thistype
set this.agi = v
return this
endmethod
method intelligence takes integer v returns thistype
set this.int = v
return this
endmethod
method movespeed takes real perc, integer flat returns thistype
set this.ms_perc = perc
set this.ms_flat = flat
return this
endmethod
method attackspeed takes integer as returns thistype
set this.as = as
return this
endmethod
method life_regen takes integer v returns thistype
set this.life_reg = v
return this
endmethod
method mana_perc_regen takes integer v returns thistype
set this.mana_perc_reg = v
return this
endmethod
method on_pickup takes unit u returns nothing
local boolean is_hero = IsHeroUnitId(GetUnitTypeId(u))
if this.ability_id != 0 then
call UnitAddAbility(u, this.ability_id)
call SetUnitAbilityLevel(u, this.ability_id, this.ability_level)
call UnitMakeAbilityPermanent(u, /*permanent:*/ true, this.ability_id)
endif
if this.dmg != 0 then
call AddUnitBonus(u, BONUS_DAMAGE, this.dmg)
endif
if this.arm != 0 then
call AddUnitBonus(u, BONUS_ARMOR, this.arm)
endif
if is_hero then
if this.str != 0 then
call AddUnitBonus(u, BONUS_STRENGTH, this.str)
endif
if this.agi != 0 then
call AddUnitBonus(u, BONUS_AGILITY, this.agi)
endif
if this.int != 0 then
call AddUnitBonus(u, BONUS_INTELLIGENCE, this.int)
endif
endif
if this.ms_flat != 0 or this.ms_perc != 0.0 then
set this.ms = Movespeed.create(u, this.ms_perc, this.ms_flat)
endif
if this.as != 0 then
call AddUnitBonus(u, BONUS_ATTACK_SPEED, this.as)
endif
if this.life_reg != 0 then
call AddUnitBonus(u, BONUS_LIFE_REGEN, this.life_reg)
endif
if this.mana_perc_reg != 0 then
call AddUnitBonus(u, BONUS_MANA_REGEN_PERCENT, this.mana_perc_reg)
endif
endmethod
method on_drop takes unit u returns nothing
local boolean is_hero = IsHeroUnitId(GetUnitTypeId(u))
if this.ability_id != 0 then
call UnitRemoveAbility(u, this.ability_id)
endif
if this.dmg != 0 then
call AddUnitBonus(u, BONUS_DAMAGE, -this.dmg)
endif
if this.arm != 0 then
call AddUnitBonus(u, BONUS_ARMOR, -this.arm)
endif
if is_hero then
if this.str != 0 then
call AddUnitBonus(u, BONUS_STRENGTH, -this.str)
endif
if this.agi != 0 then
call AddUnitBonus(u, BONUS_AGILITY, -this.agi)
endif
if this.int != 0 then
call AddUnitBonus(u, BONUS_INTELLIGENCE, -this.int)
endif
endif
if this.ms_flat != 0 or this.ms_perc != 0.0 then
call this.ms.destroy()
endif
if this.as != 0 then
call AddUnitBonus(u, BONUS_ATTACK_SPEED, -this.as)
endif
if this.life_reg != 0 then
call AddUnitBonus(u, BONUS_LIFE_REGEN, -this.life_reg)
endif
if this.mana_perc_reg != 0 then
call AddUnitBonus(u, BONUS_MANA_REGEN_PERCENT, -this.mana_perc_reg)
endif
endmethod
endstruct
endlibrary
library UseItem initializer init requires Item
globals
Item array items
endglobals
private function items_init takes nothing returns nothing
set items[1] = Item.create("Item 1").ability(1, 1).damage(2).armor(3)
set items[2] = Item.create("Item 2").ability(2, 2).strength(3).agility(4).intelligence(5)
set items[3] = Item.create("Item 3").ability(3, 3).movespeed(0.25, 0).attackspeed(20)
set items[4] = Item.create("Item 4").ability(4, 1).life_regen(2).mana_perc_regen(50)
set items[5] = Item.create("Item 5").ability(5, 2).damage(5).strength(10).movespeed(-0.10, 0).life_regen(4)
set items[6] = Item.create("Item 6").ability(6, 3).life_regen(2).mana_perc_regen(50)
// etc.
endfunction
function unit_add_item takes unit u, integer item_id, Item it returns nothing
local item it_handle = UnitAddItemById(u, item_id)
call SetItemUserData(it_handle, it)
call it.on_pickup(u)
set it_handle = null
endfunction
function on_item_pickup takes nothing returns nothing
local Item it = GetItemUserData(GetManipulatedItem())
if it != 0 then
call dd("picking up Item(" + I2S(it) + ")")
call it.on_pickup(GetTriggerUnit())
endif
endfunction
function on_item_drop takes nothing returns nothing
local Item it = GetItemUserData(GetManipulatedItem())
if it != 0 then
call dd("dropping Item(" + I2S(it) + ")")
call it.on_drop(GetTriggerUnit())
endif
endfunction
private function init takes nothing returns nothing
local trigger t
call items_init()
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(t, function on_item_pickup)
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerAddAction(t, function on_item_drop)
endfunction
endlibrary