scope SlotChangeRestriction
struct SlotChangeRestriction extends array
implement Alloc
private integer tempIndex
private unit tempUnit
private item tempItem
private static trigger moveTrigger
private static method moveCallback takes nothing returns nothing
local thistype this=ReleaseTimer(GetExpiredTimer())
call DisableTrigger(thistype.moveTrigger)
call IssueTargetOrderById(this.tempUnit,this.tempIndex,this.tempItem)
call EnableTrigger(thistype.moveTrigger)
call this.deallocate()
endmethod
static method create takes unit triggerUnit,item triggerItem returns thistype
local thistype this=thistype.allocate()
local integer i=0
set this.tempUnit=triggerUnit
set this.tempItem=triggerItem
loop
if UnitItemInSlot(this.tempUnit,i)==this.tempItem then
set this.tempIndex=i+852002
endif
set i=i+1
exitwhen i==6
endloop
call TimerStart(NewTimerEx(this),.01,false,function thistype.moveCallback)
return this
endmethod
private static method onMove takes nothing returns boolean
if GetIssuedOrderId()>852001 and GetIssuedOrderId()<852008 then
call thistype.create(GetTriggerUnit(),GetOrderTargetItem())
endif
return false
endmethod
private static method onInit takes nothing returns nothing
set thistype.moveTrigger=CreateTrigger()
call TriggerRegisterPlayerUnitEvent(thistype.moveTrigger,Player(0),EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER,null)
call TriggerAddCondition(thistype.moveTrigger,Condition(function thistype.onMove))
endmethod
endstruct
endscope