- Joined
- Feb 3, 2013
- Messages
- 277
hellluuuu, below is a simple item drop system, can someone explain to me how I can integrate Table into this system? I am still not sure how Table works... even after reading Bribe's demo - furthermore with this system.
Also a side question -
can someone explain what binary trees are good for with a wc3 example?
Also a side question -
can someone explain what binary trees are good for with a wc3 example?
JASS:
library ItemDropList requires RegisterPlayerUnitEvent, SharedList
private struct DropList extends array
implement SharedList
integer itemId
integer itemChance
static thistype nn
endstruct
struct IDL extends array
implement SharedList
integer unitId
integer initChance
DropList iList
static thistype l
static thistype nn
method addItem takes integer itemId, integer itemChance returns nothing
local DropList tList = .iList.enqueue()
set tList.itemId = itemId
set tList.itemChance = itemChance
endmethod
static method createDropList takes integer unitTypeId, integer chanceToDrop returns thistype
local thistype this = l.enqueue()
set .unitId = unitTypeId
set .initChance = chanceToDrop
set .iList = DropList.create()
return this
endmethod
static method checkForDrops takes nothing returns nothing
local thistype this = l.first
local unit du = GetTriggerUnit()
local DropList tList
loop
exitwhen this == l.sentinel
set nn = .next
//
if GetUnitTypeId(du) == .unitId and GetRandomInt(1, 100) <= .initChance then
set tList = .iList.first
loop
exitwhen tList == .iList.sentinel
set tList.nn = tList.next
if GetRandomInt(1, 100) <= tList.itemChance then
call CreateItem(tList.itemId, GetUnitX(du), GetUnitY(du))
endif
set tList = tList.nn
endloop
endif
//
set this = nn
endloop
set du = null
endmethod
static method onInit takes nothing returns nothing
set l = thistype.create()
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function thistype.checkForDrops)
endmethod
endstruct
endlibrary