jass基礎-任務5

// 送水任務代碼
library demo initializer test
? ? globals
? ? ? ? // 接送水任務id
? ? ? ? integer i1 = 'I001'
? ? ? ? // 提交送水任務id
? ? ? ? integer i2 = 'I000'
? ? ? ? // 商店id
? ? ? ? integer i3 = 'h000'
? ? ? ? // bzbf
? ? endglobals
? ? function GetItemIndex takes unit u, integer itemId returns integer
? ? ? ? local integer i = 0
? ? ? ? loop
? ? ? ? ? ? exitwhen i == 6
? ? ? ? ? ? if GetItemTypeId(UnitItemInSlot(u, i)) == itemId then
? ? ? ? ? ? ? ? return i
? ? ? ? ? ? else
? ? ? ? ? ? ? ? return - 1
? ? ? ? ? ? endif
? ? ? ? ? ? set i = i + 1
? ? ? ? endloop
? ? endfunction
? ? function soldItemAction takes nothing returns nothing
? ? ? ? local unit u = GetBuyingUnit()
? ? ? ? local integer index
? ? ? ? if GetItemTypeId(GetSoldItem()) == i1 then
? ? ? ? ? ? if GetItemIndex(u, 'bzbe') >= 0 then
? ? ? ? ? ? ? ? return
? ? ? ? ? ? endif
? ? ? ? ? ? call BJDebugMsg("接了送水任務")
? ? ? ? ? ? call UnitAddItemById(u, 'bzbe')
? ? ? ? endif
? ? ? ? if GetItemTypeId(GetSoldItem()) == i2 then
? ? ? ? ? ? if GetItemIndex(u, 'bzbf') < 0 then
? ? ? ? ? ? ? ? return
? ? ? ? ? ? endif
? ? ? ? ? ? call BJDebugMsg("提交送水任務")
? ? ? ? ? ? set index = GetItemIndex(u, 'bzbf')
? ? ? ? ? ? call RemoveItem(UnitRemoveItemFromSlot(u, index))
? ? ? ? endif
? ? endfunction
? ? function enterRegionAction takes nothing returns nothing
? ? ? ? local unit u = GetTriggerUnit()
? ? ? ? local integer index = GetItemIndex(u, 'bzbe')
? ? ? ? call RemoveItem(UnitRemoveItemFromSlot(u, index))
? ? ? ? call UnitAddItemById(u, 'bzbf')
? ? ? ? call BJDebugMsg("進了區(qū)域")
? ? endfunction
? ? function test takes nothing returns nothing
? ? ? ? local trigger t1 = CreateTrigger()
? ? ? ? local rect re = Rect(- 146, 497, 150, 666)
? ? ? ? local trigger t2 = CreateTrigger()
? ? ? ? local region reg = CreateRegion()
? ? ? ? local unit shop = CreateUnit(Player(0), i3, 100, 100, 0)
? ? ? ? call RegionAddRect(reg, re)
? ? ? ? call TriggerRegisterUnitEvent(t1, shop, EVENT_UNIT_SELL_ITEM)
? ? ? ? call TriggerAddAction(t1, function soldItemAction)
? ? ? ? call TriggerRegisterEnterRegion(t2, reg, null)
? ? ? ? call TriggerAddAction(t2, function enterRegionAction)
? ? ? ? call FogEnable(false)
? ? ? ? call FogMaskEnable(false)
? ? ? ? call CreateUnit(Player(0), 'Hpal', 0, 0, 0)
? ? endfunction
endlibrary