- Joined
- Mar 18, 2012
- Messages
- 1,716
EDIT: Moved to spell section ItemPower
In the map I am working on at the moment I'm using MUI Advanced Equipment System. But i felt like something is missing. So I wrote this small system which adds an individual damage multiplier to each registered item.
The idea behind this is to call GetPower(unit, powerid) in any spell struct, which gives the opportunity calculate damage more dynamic.
For example:
A unit carries a staff which adds 20% damage to all fire spells and a cap that adds 5 % to fire spells
Now it casts such a spell
In the spell struct we set damage to 10*AbilityLevel*GetPower(unit, integer for fire). The result will be damage = 10*AbililtyLevel*1.25
Since it is the most frequent downloaded inventory system on THW, this could turn out to be really useful.
As this is only an expansion to an already existing resource, I don't think it belongs into the spell section, but rather in the lab.
Also this is not 100% finished. It misses a destroy method and does not support the ChangeEquipmentOwner function (yet). For my needs this is complete, dependent on the resonance I'll write those missing lines of code.
Opinions and suggestions are very welcome.
Requires: Table, Alloc, UnitIndexer, AdvancedEquipmentSystem
Edit: Actually it is not bound to AdvancedEquipmentSystem and can be used for any equipment system. You just need a custom trigger for onEquip and onUnequip.
In the map I am working on at the moment I'm using MUI Advanced Equipment System. But i felt like something is missing. So I wrote this small system which adds an individual damage multiplier to each registered item.
The idea behind this is to call GetPower(unit, powerid) in any spell struct, which gives the opportunity calculate damage more dynamic.
For example:
A unit carries a staff which adds 20% damage to all fire spells and a cap that adds 5 % to fire spells
Now it casts such a spell
In the spell struct we set damage to 10*AbilityLevel*GetPower(unit, integer for fire). The result will be damage = 10*AbililtyLevel*1.25
Since it is the most frequent downloaded inventory system on THW, this could turn out to be really useful.
As this is only an expansion to an already existing resource, I don't think it belongs into the spell section, but rather in the lab.
Also this is not 100% finished. It misses a destroy method and does not support the ChangeEquipmentOwner function (yet). For my needs this is complete, dependent on the resonance I'll write those missing lines of code.
Opinions and suggestions are very welcome.
Requires: Table, Alloc, UnitIndexer, AdvancedEquipmentSystem
JASS:
library SpellPower uses Alloc, UnitIndexer, AdvancedEquipmentSystem, Table
private struct Power extends array
implement Alloc
private static TableArray tb
private static thistype array unitIndex
private static hashtable hash = InitHashtable()
private static method removePower takes nothing returns boolean
local integer id = GetTriggeringItemId()
local thistype this = unitIndex[GetUnitId(GetEquippingUnit())]
local integer i = 1
loop
exitwhen i == 10
set tb[this].real[i] = tb[this].real[i] - LoadReal(hash, id, i)
set tb[this][i] = tb[this][i] - LoadInteger(hash, id, i)
set i = i + 1
endloop
return false
endmethod
private static method addPower takes nothing returns boolean
local integer id = GetTriggeringItemId()
local thistype this = unitIndex[GetUnitId(GetEquippingUnit())]
local integer i = 1
loop
exitwhen i == 10
set tb[this].real[i] = tb[this].real[i] + LoadReal(hash, id, i)
set tb[this][i] = tb[this][i] + LoadInteger(hash, id, i)
set i = i + 1
endloop
return false
endmethod
static method getRealPower takes unit WhichUnit, integer WhichPower returns real
return tb[unitIndex[GetUnitId(WhichUnit)]].real[WhichPower]
endmethod
static method getIntPower takes unit WhichUnit, integer WhichPower returns integer
return tb[unitIndex[GetUnitId(WhichUnit)]][WhichPower]
endmethod
static method createPower takes unit WhichUnit returns nothing
local thistype this = allocate()
set unitIndex[GetUnitId(WhichUnit)] = this
set tb[this].real[1] = 1.//Fire
set tb[this].real[2] = 1.//Twohand
set tb[this].real[3] = 0.00//Crit Chance
set tb[this].real[4] = 1.00//Crit Factor
set tb[this].real[5] = 0.00//Block Change
set tb[this].real[6] = 0//Min Block Amount
set tb[this].real[7] = 0//Max Block Damage
set tb[this].real[8] = 0//Min Bonus Damage
set tb[this].real[9] = 0//Max Bonus Damage
set tb[this][1] = 0//IntFire
set tb[this][2] = 0//IntTwohand
set tb[this][3] = 0//IntCrit
set tb[this][4] = 0//IntCritFactor
set tb[this][5] = 0//IntBlockC
set tb[this][6] = 0//IntBlockMin
set tb[this][7] = 0//IntBlockMax
set tb[this][8] = 0//IntDamMin
set tb[this][9] = 0//IntDamMax
endmethod
static method registerItem takes integer WhichItem, integer WhichSpellPower, real RealAmount, integer IntAmount returns nothing
call SaveReal(hash,WhichItem, WhichSpellPower, RealAmount)
call SaveInteger(hash, WhichItem, WhichSpellPower, IntAmount)
endmethod
private static method onInit takes nothing returns nothing
set tb = TableArray[0x2000]//[200] could be enough
call RegisterItemEquipEvent(function thistype.addPower)
call RegisterItemUnequipEvent(function thistype.removePower)
endmethod
endstruct
public function RegisterSpellPowerItem takes integer WhichItem, integer WhichPower, real RealAmount, integer IntAmount returns nothing
call Power.registerItem(WhichItem, WhichPower, RealAmount, IntAmount)
endfunction
function GetRealPower takes unit WhichUnit, integer WhichPower returns real//Returns real: good for calculation
return Power.getRealPower(WhichUnit, WhichPower)
endfunction
function GetIntPower takes unit WhichUnit, integer WhichPower returns integer//Returns integer: good for display(Multiboard, Textag)
return Power.getIntPower(WhichUnit, WhichPower)
endfunction
function InitPowerSystemForUnit takes unit u returns nothing
call Power.createPower(u)
endfunction
endlibrary
Edit: Actually it is not bound to AdvancedEquipmentSystem and can be used for any equipment system. You just need a custom trigger for onEquip and onUnequip.
Last edited: