|
[jass]
//***************************************************************************
//* *
//* Azeroth' Arcane Arena Inventory System *
//* *
//* By Blade.dk - [email protected] *
//* *
//* http://aaa.wc3jass.com - http://www.wc3campaigns.net *
//* *
//***************************************************************************
//===========================================================================
// Configuration functions
constant function Cancel_ItemID takes nothing returns integer
return 'I00K' // Rawcode of the Cancel item.
endfunction
constant function BackpackMenu_ItemID takes nothing returns integer
return 'I009' // Rawcode of the Backpack item.
endfunction
constant function SwitchPage_ItemID takes nothing returns integer
return 'I00N' // Rawcode of the Switch Page item.
endfunction
constant function EquipmentMenu_ItemID takes nothing returns integer
return 'I00L' // Rawcode of the Equipment Menu item.
endfunction
constant function HeadFiller_ItemID takes nothing returns integer
return 'I00M' // Rawcode of the Head item.
endfunction
constant function ArmorFiller_ItemID takes nothing returns integer
return 'I00G' // Rawcode of the Armor item.
endfunction
constant function WeaponFiller_ItemID takes nothing returns integer
return 'I00H' // Rawcode of the Weapon item.
endfunction
constant function ShieldFiller_ItemID takes nothing returns integer
return 'I00I' // Rawcode of the Shield item.
endfunction
constant function AccessoryFiller_ItemID takes nothing returns integer
return 'I00J' // Rawcode of the Accessory item.
endfunction
constant function BackpackSize takes nothing returns integer
return 16 // The number of items that can be in a Hero's Backpack. MUST be a multiple of 4.
endfunction
constant function InventorySafeX takes nothing returns real
return -2040.00 // The X coordinate of a safe place to place items, so computer units won't be able to pick the up.
endfunction
constant function InventorySafeY takes nothing returns real
return 2040.00 // The Y coordinate of a safe place to place items, so computer units won't be able to pick the up.
endfunction
//===========================================================================
// Private functions - Do not modify them unless you know what you are doing!
function InventoryCache takes nothing returns gamecache
if udg_AAAInventory == null then
call FlushGameCache(InitGameCache("AAAInv.w3v"))
set udg_AAAInventory = InitGameCache("AAAInv.w3v")
endif
return udg_AAAInventory
endfunction
function SetItemBonuses takes item i, integer dmg, integer arm, integer hp, integer mp, integer str, integer agi, integer int, integer abil_a,integer abil_b,integer abil_c,integer abil_d, string equipSlot, string equipFunc, string unequipFunc returns nothing
local gamecache g = InventoryCache()
local string s = I2S(CS_H2I(i))
if equipSlot == "Head" or equipSlot == "Armor" or equipSlot == "Weapon" or equipSlot == "Shield" or equipSlot == "Accessory" then
call StoreString(g, s, "equipmentslot", equipSlot)
if dmg > 0 then
call StoreInteger(g, s, "damage", dmg)
endif
if arm > 0 then
call StoreInteger(g, s, "armor", arm)
endif
if hp > 0 then
call StoreInteger(g, s, "hitpoints", hp)
endif
if mp > 0 then
call StoreInteger(g, s, "manapoints", mp)
endif
if str > 0 then
call StoreInteger(g, s, "strength", str)
endif
if agi > 0 then
call StoreInteger(g, s, "agility", agi)
endif
if int > 0 then
call StoreInteger(g, s, "intelligence", int)
endif
//=====================================================
if abil_a> 0 then
call StoreInteger(g, s, "ability_a", PreloadAbility(abil_a))
endif
if abil_b> 0 then
call StoreInteger(g, s, "ability_b", PreloadAbility(abil_b))
endif
if abil_c> 0 then
call StoreInteger(g, s, "ability_c", PreloadAbility(abil_c))
endif
if abil_d> 0 then
call StoreInteger(g, s, "ability_d", PreloadAbility(abil_d))
endif
//==============================================================
if equipFunc != "" and equipFunc != null then
call StoreString(g, s, "OnEquip", equipFunc)
endif
if unequipFunc != "" and unequipFunc != null then
call StoreString(g, s, "OnDrop", unequipFunc)
endif
endif
set g = null
endfunction
//===========================================================================
//===========================================================================
function BackpackHasEmptySlots takes string s returns boolean
local integer a = 1
loop
exitwhen a > BackpackSize()
if GetTableItem(s, "BackpackItem"+I2S(a)) == null then
return true
endif
set a = a+1
endloop
return false
endfunction
function QuickMenuHasEmptySlots takes string s returns boolean
return GetTableItem(s, "QuickMenuItem1") == null or GetTableItem(s, "QuickMenuItem2") == null or GetTableItem(s, "QuickMenuItem3") == null or GetTableItem(s, "QuickMenuItem4") == null
endfunction
function IsItemFiller takes item i returns boolean
local integer id = GetItemTypeId(i)
return id == HeadFiller_ItemID() or id == ArmorFiller_ItemID() or id == WeaponFiller_ItemID() or id == ShieldFiller_ItemID() or id == AccessoryFiller_ItemID()
endfunction
function BackpackContainsItem takes string s, item i returns boolean
local integer a = 1
loop
exitwhen a > BackpackSize()
if GetTableItem(s, "BackpackItem"+I2S(a)) == i then
return true
endif
set a = a+1
endloop
return false
endfunction
function QuickMenuContainsItem takes string s, item i returns boolean
return GetTableItem(s, "QuickMenuItem1") == i or GetTableItem(s, "QuickMenuItem2") == i or GetTableItem(s, "QuickMenuItem3") == i or GetTableItem(s, "QuickMenuItem4") == i
endfunction
function IsEquipmentSlotValid takes string es returns boolean
return es == "Head" or es == "Armor" or es == "Weapon" or es == "Shield" or es == "Accessory"
endfunction
function GetItemEquipmentSlot takes item i returns string
return GetStoredString(InventoryCache(), I2S(CS_H2I(i)), "equipmentslot")
endfunction
function GetItemSlot takes unit u, item i returns integer
local integer a = 0
loop
exitwhen a > 5
if UnitItemInSlot(u, a) == i then
return a
endif
set a = a + 1
endloop
return -1
endfunction
function SlotToFillerName takes integer s returns string
if s == 0 then
return "Head"
elseif s == 1 then
return "Armor"
elseif s == 2 then
return "Weapon"
elseif s == 3 then
return "Shield"
elseif s == 4 then
return "Accessory"
else
return "Cancel"
endif
endfunction
function FillerNameToSlot takes string es returns integer
if es == "Head" then
return 0
elseif es == "Armor" then
return 1
elseif es == "Weapon" then
return 2
elseif es == "Shield" then
return 3
elseif es == "Accessory" then
return 4
endif
return 5
endfunction
function InventoryRemoveItem takes unit u, item i returns nothing
call SetItemUserData(i, 1)
call UnitRemoveItem(u, i)
call SetItemPosition(i, InventorySafeX(), InventorySafeY())
call SetItemVisible(i, false)
endfunction
function InventoryAddItem takes unit u, item i returns nothing
call SetItemUserData(i, 0)
call SetItemVisible(i, true)
call UnitAddItem(u, i)
endfunction
function CreateExtendedInventory takes unit u returns nothing
local item i
local string s = NewTable()
local integer a = 0
loop
exitwhen a > 5
call RemoveItem(UnitItemInSlot(u, a))
set a = a + 1
endloop
call GroupAddUnit(udg_AAAInventoryGroup, u)
call AttachString(u, "InventoryTable", s)
call SetTableInt(s, "CurrentMenu", 0)
call SetTableInt(s, "CurrentBackpackPage", 1)
call UnitAddItemToSlotById(u, EquipmentMenu_ItemID(), 4)
set i = UnitItemInSlot(u, 4)
call SetTableObject(s, "EquipmentMenu", i)
call UnitAddItemToSlotById(u, BackpackMenu_ItemID(), 5)
set i = UnitItemInSlot(u, 5)
call SetTableObject(s, "BackpackMenu", i)
set i = CreateItem(Cancel_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "Cancel", i)
set i = CreateItem(SwitchPage_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "SwitchPage", i)
call SetItemCharges(i, 1)
set i = CreateItem(HeadFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "HeadFiller", i)
call SetTableObject(s, "HeadItem", i)
set i = CreateItem(ArmorFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "ArmorFiller", i)
call SetTableObject(s, "ArmorItem", i)
set i = CreateItem(WeaponFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "WeaponFiller", i)
call SetTableObject(s, "WeaponItem", i)
set i = CreateItem(ShieldFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "ShieldFiller", i)
call SetTableObject(s, "ShieldItem", i)
set i = CreateItem(AccessoryFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "AccessoryFiller", i)
call SetTableObject(s, "AccessoryItem", i)
set i = null
endfunction
function DestroyExtendedInventory takes unit u returns nothing
local string s = GetAttachedString(u, "InventoryTable")
local item i
local item t
local integer a = 1
if s == "" then
set i = null
set t = null
return
endif
loop
exitwhen a > BackpackSize()
call RemoveItem(GetTableItem(s, "BackpackItem"+I2S(a)))
set a = a + 1
endloop
set a = 1
loop
exitwhen a > 4
call RemoveItem(GetTableItem(s, "QuickPage"+I2S(a)))
set a = a + 1
endloop
call RemoveItem(GetTableItem(s, "EquipmentMenu"))
call RemoveItem(GetTableItem(s, "BackpackMenu"))
call RemoveItem(GetTableItem(s, "Cancel"))
call RemoveItem(GetTableItem(s, "SwitchPage"))
set a = 0
loop
exitwhen a > 4
set i = GetTableItem(s, SlotToFillerName(a)+"Item")
set t = GetTableItem(s, SlotToFillerName(a)+"Filler")
if i != t then
call RemoveItem(i)
endif
call RemoveItem(t)
set a = a + 1
endloop
call DestroyTable(s)
call GroupRemoveUnit(udg_AAAInventoryGroup, u)
call AttachString(u, "InventoryTable", "")
set i = null
set t = null
endfunction
function InventoryError takes unit u, string e returns nothing
call CS_Error(GetOwningPlayer(u), e)
call PauseUnit(u, true)
call IssueImmediateOrder(u, "stop")
call PauseUnit(u, false)
endfunction
function CompressBackpack takes string s returns nothing
local integer a = 1
local item array t
local integer b = 1
local integer m = 0
local integer e = 1
local string l
loop
exitwhen a > BackpackSize()
set l = "BackpackItem"+I2S(a)
set t[a] = GetTableItem(s, l)
call SetTableObject(s, l, null)
set a = a + 1
endloop
set a = 1
loop
exitwhen a > BackpackSize()
set b = e
loop
exitwhen b > BackpackSize()
if t != null then
call SetTableObject(s, "BackpackItem"+I2S(a), t)
set e = b+1
set m = m + 1
set b = BackpackSize()+1
endif
set b = b + 1
endloop
set a = a + 1
endloop
set a = 1
loop
exitwhen a > BackpackSize()
set t[a] = null
set a = a + 1
endloop
call SetTableInt(s, "BackpackItemsCount", m)
endfunction
function AddItemToBackpack takes unit u, string s, item i returns nothing
local integer a
call CompressBackpack(s)
set a = GetTableInt(s, "BackpackItemsCount")+1
call SetTableObject(s, "BackpackItem"+I2S(a), i)
call InventoryRemoveItem(u, i)
call SetItemCharges(GetTableItem(s, "BackpackMenu"), a)
call SetTableInt(s, "BackpackItemsCount", a)
endfunction
function AddItemToQuickMenu takes unit u, string s, item i, boolean f returns nothing
local integer a = 1
local string c
local item t
local string m
loop
exitwhen a > 4
set c = "QuickMenuItem"+I2S(a)
if GetTableItem(s, c) == null then
call SetTableObject(s, c, i)
call InventoryRemoveItem(u, i)
set a = 4
endif
set a = a + 1
endloop
if f then
call CompressBackpack(s)
endif
set t = null
endfunction
function InventorySwapMenu takes unit c, string s, integer o, integer m, integer op, integer np returns nothing
local integer a = 1
local integer b = 0
local item i
if o == 0 then
loop
exitwhen a > 6
set i = UnitItemInSlot(c, a-1)
if a < 5 then
call SetTableObject(s, "QuickMenuItem"+I2S(a), i)
endif
call InventoryRemoveItem(c, i)
set a = a + 1
endloop
elseif o == 1 then
set a = 0
loop
exitwhen a > 4
set i = UnitItemInSlot(c, a)
call SetTableObject(s, SlotToFillerName(a)+"Item", i)
call InventoryRemoveItem(c, i)
set a = a + 1
endloop
set i = UnitItemInSlot(c, 5)
call SetTableObject(s, "Cancel", i)
call InventoryRemoveItem(c, i)
elseif o == 2 then
loop
exitwhen a > 6
set i = UnitItemInSlot(c, a-1)
if a < 5 then
call SetTableObject(s, "BackpackItem"+I2S((4*(op-1))+a), i)
endif
call InventoryRemoveItem(c, i)
set a = a + 1
endloop
endif
set a = 1
call SetTableInt(s, "CurrentMenu", m)
if m == 0 then
loop
exitwhen a > 4
set i = GetTableItem(s, "QuickMenuItem"+I2S(a))
call InventoryAddItem(c, i)
call SetItemPawnable(i, true)
set a = a + 1
endloop
set i = GetTableItem(s, "EquipmentMenu")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 4)
set i = GetTableItem(s, "BackpackMenu")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 5)
call SetItemCharges(i, GetTableInt(s, "BackpackItemsCount"))
call SetTableInt(s, "CurrentBackpackPage", 1)
elseif m == 1 then
set a = 0
loop
exitwhen a > 4
set i = GetTableItem(s, SlotToFillerName(a)+"Item")
call InventoryAddItem(c, i)
call SetItemPawnable(i, false)
set a = a + 1
endloop
set i = GetTableItem(s, "Cancel")
call InventoryAddItem(c, i)
elseif m == 2 then
call CompressBackpack(s)
loop
exitwhen b >= 4 or a > BackpackSize()
set i = GetTableItem(s, "BackpackItem"+I2S((4*(np-1))+a))
if i != null then
set b = b + 1
call InventoryAddItem(c, i)
call SetItemPawnable(i, false)
endif
set a = a + 1
endloop
call SetTableInt(s, "CurrentBackpackPage", np)
set i = GetTableItem(s, "SwitchPage")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 4)
call SetItemCharges(i, np)
set i = GetTableItem(s, "Cancel")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 5)
endif
if GetLocalPlayer() == GetOwningPlayer(c) then
call ClearTextMessages()
endif
set i = null
endfunction
function EquipItem takes unit c, string s, item i, string es returns nothing
local item e = GetTableItem(s, es+"Item")
local item f = GetTableItem(s, es+"Filler")
local string x
local gamecache g = InventoryCache()
local string m = I2S(CS_H2I(e))
local integer v
local string a
local integer l
call InventoryRemoveItem(c, i)
call SetTableObject(s, es+"Item", i)
if e != f then
set x = GetStoredString(g, m, "OnDrop")
if x != "" and x != null then
call ExecuteFunc(x)
endif
set v = GetStoredInteger(g, m, "damage")
if v > 0 then
call UnitAddBonus(c, 0, -v)
endif
set v = GetStoredInteger(g, m, "armor")
if v > 0 then
call UnitAddBonus(c, 1, -v)
endif
set v = GetStoredInteger(g, m, "hitpoints")
if v > 0 then
call UnitAddBonus(c, 2, -v)
endif
set v = GetStoredInteger(g, m, "manapoints")
if v > 0 then
call UnitAddBonus(c, 3, -v)
endif
set v = GetStoredInteger(g, m, "strength")
if v > 0 then
call SetHeroStr(c, GetHeroStr(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "agility")
if v > 0 then
call SetHeroAgi(c, GetHeroAgi(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "intelligence")
if v > 0 then
call SetHeroInt(c, GetHeroInt(c, false)-v, true)
endif
//===================================================
set v = GetStoredInteger(g, m, "ability_a")
if v > 0 then
set a = "Ability_a"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
set v = GetStoredInteger(g, m, "ability_b")
if v > 0 then
set a = "Ability_b"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
set v = GetStoredInteger(g, m, "ability_c")
if v > 0 then
set a = "Ability_c"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
set v = GetStoredInteger(g, m, "ability_d")
if v > 0 then
set a = "Ability_d"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
//=======================================================
call InventoryAddItem(c, e)
endif
set m = I2S(CS_H2I(i))
set x = GetStoredString(g, m, "OnEquip")
if x != "" and x != null then
call ExecuteFunc(x)
endif
set v = GetStoredInteger(g, m, "damage")
if v > 0 then
call UnitAddBonus(c, 0, v)
endif
set v = GetStoredInteger(g, m, "armor")
if v > 0 then
call UnitAddBonus(c, 1, v)
endif
set v = GetStoredInteger(g, m, "hitpoints")
if v > 0 then
call UnitAddBonus(c, 2, v)
endif
set v = GetStoredInteger(g, m, "manapoints")
if v > 0 then
call UnitAddBonus(c, 3, v)
endif
set v = GetStoredInteger(g, m, "strength")
if v > 0 then
call SetHeroStr(c, GetHeroStr(c, false)+v, true)
endif
set v = GetStoredInteger(g, m, "agility")
if v > 0 then
call SetHeroAgi(c, GetHeroAgi(c, false)+v, true)
endif
set v = GetStoredInteger(g, m, "intelligence")
if v > 0 then
call SetHeroInt(c, GetHeroInt(c, false)+v, true)
endif
//================================================
set v = GetStoredInteger(g, m, "ability_a")
if v > 0 then
set a = "Ability_a"+I2S(v)
set l = GetTableInt(s, a)+1
call SetTableInt(s, a, l)
call UnitAddAbility(c, v)
endif
set v = GetStoredInteger(g, m, "ability_b")
if v > 0 then
set a = "Ability_b"+I2S(v)
set l = GetTableInt(s, a)+1
call SetTableInt(s, a, l)
call UnitAddAbility(c, v)
endif
set v = GetStoredInteger(g, m, "ability_c")
if v > 0 then
set a = "Ability_c"+I2S(v)
set l = GetTableInt(s, a)+1
call SetTableInt(s, a, l)
call UnitAddAbility(c, v)
endif
set v = GetStoredInteger(g, m, "ability_d")
if v > 0 then
set a = "Ability_d"+I2S(v)
set l = GetTableInt(s, a)+1
call SetTableInt(s, a, l)
call UnitAddAbility(c, v)
endif
//==============================================
call InventorySwapMenu(c, s, 0, 0, 0, 0)
set e = null
set f = null
set g = null
endfunction
function UnequipItem takes unit c, string s, item i, string es returns nothing
local item f = GetTableItem(s, es+"Filler")
local string x
local gamecache g = InventoryCache()
local string m = I2S(CS_H2I(i))
local integer v
local string a
local integer l
call AddItemToQuickMenu(c, s, i, false)
call SetTableObject(s, es+"Item", f)
call InventoryAddItem(c, f)
call UnitDropItemSlot(c, f, FillerNameToSlot(es))
set x = GetStoredString(g, m, "OnDrop")
if x != "" and x != null then
call ExecuteFunc(x)
endif
set v = GetStoredInteger(g, m, "damage")
if v > 0 then
call UnitAddBonus(c, 0, -v)
endif
set v = GetStoredInteger(g, m, "armor")
if v > 0 then
call UnitAddBonus(c, 1, -v)
endif
set v = GetStoredInteger(g, m, "hitpoints")
if v > 0 then
call UnitAddBonus(c, 2, -v)
endif
set v = GetStoredInteger(g, m, "manapoints")
if v > 0 then
call UnitAddBonus(c, 3, -v)
endif
set v = GetStoredInteger(g, m, "strength")
if v > 0 then
call SetHeroStr(c, GetHeroStr(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "agility")
if v > 0 then
call SetHeroAgi(c, GetHeroAgi(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "intelligence")
if v > 0 then
call SetHeroInt(c, GetHeroInt(c, false)-v, true)
endif
//============================================
set v = GetStoredInteger(g, m, "ability_a")
if v > 0 then
set a = "Ability_a"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
set v = GetStoredInteger(g, m, "ability_b")
if v > 0 then
set a = "Ability_b"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
set v = GetStoredInteger(g, m, "ability_c")
if v > 0 then
set a = "Ability_c"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
set v = GetStoredInteger(g, m, "ability_d")
if v > 0 then
set a = "Ability_d"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
//============================================
set f = null
set g = null
endfunction
function InventoryDragItemConditions takes nothing returns boolean
local integer i = GetIssuedOrderId()
return i > 852001 and i < 852008 and IsUnitInGroup(GetOrderedUnit(), udg_AAAInventoryGroup) and GetOrderTargetItem() != UnitItemInSlot(GetOrderedUnit(), i-852002)
endfunction
function InventoryDragItemActions takes nothing returns nothing
local unit c = GetOrderedUnit()
local string s = GetAttachedString(c, "InventoryTable")
local item d = GetOrderTargetItem()
local integer ts = GetIssuedOrderId()-852002
local item t = UnitItemInSlot(c, ts)
local integer m = GetTableInt(s, "CurrentMenu")
local integer i = GetItemSlot(c, d)
local item e = GetTableItem(s, "EquipmentMenu")
local item b = GetTableItem(s, "BackpackMenu")
local item ca = GetTableItem(s, "Cancel")
local item sw = GetTableItem(s, "SwitchPage")
local integer p = GetTableInt(s, "CurrentBackpackPage")
local string es = GetItemEquipmentSlot(d)
if m == 0 then
if t == GetTableItem(s, "BackpackMenu") and d != e then
if BackpackHasEmptySlots(s) then
call AddItemToBackpack(c, s, d)
elseif d != t and t == b then
call InventoryError(c, "Backpack is full.")
endif
else
if d == e and ts != 4 then
call InventoryError(c, "Unable to drop this item.")
elseif d == b and ts != 5 then
call InventoryError(c, "Unable to drop this item.")
elseif t == e and d != b then
if IsEquipmentSlotValid(es) then
call EquipItem(c, s, d, es)
else
call InventoryError(c, "Item is not equipable.")
endif
elseif ts == 5 and d != b then
call InventoryError(c, "Can not add this item to your backpack.")
endif
endif
elseif m == 1 then
if t == ca then
if QuickMenuHasEmptySlots(s) then
call UnequipItem(c, s, d, es)
else
call InventoryError(c, "Quick page is full.")
endif
else
call InventoryError(c, "Unable to drop this item.")
endif
elseif m == 2 then
if t == ca and d != sw then
if QuickMenuHasEmptySlots(s) then
call AddItemToQuickMenu(c, s, d, true)
call InventorySwapMenu(c, s, 2, 2, p, p)
else
call InventoryError(c, "Quick page is full.")
endif
elseif t == sw then
call InventoryError(c, "Unable to drop this item.")
elseif t == ca and d != sw then
call InventoryError(c, "Unable to drop this item.")
elseif d == ca and ts != 5 then
call InventoryError(c, "Unable to drop this item.")
elseif d == sw and ts != 4 then
call InventoryError(c, "Unable to drop this item.")
endif
endif
set c = null
set d = null
set t = null
set e = null
set b = null
set ca = null
set sw = null
endfunction
function InventoryUnitUsesItemConditions takes nothing returns boolean
local integer i = GetItemTypeId(GetManipulatedItem())
return IsUnitInGroup(GetManipulatingUnit(), udg_AAAInventoryGroup) and (i == Cancel_ItemID() or i == BackpackMenu_ItemID() or i == SwitchPage_ItemID() or i == EquipmentMenu_ItemID())
endfunction
function InventoryUnitUsesItemActions takes nothing returns nothing
local unit c = GetManipulatingUnit()
local string s = GetAttachedString(c, "InventoryTable")
local item m = GetManipulatedItem()
local integer g = GetItemCharges(m)
local string ts = ""
local integer ti = 0
local integer a
local integer e = GetTableInt(s, "CurrentMenu")
local integer i = GetItemTypeId(m)
local integer o = GetTableInt(s, "CurrentBackpackPage")
local integer n = o + 1
if n > BackpackSize()/4 then
set n = 1
endif
if m == GetTableItem(s, "Cancel") then
set ti = Cancel_ItemID()
set ts = "Cancel"
elseif m == GetTableItem(s, "BackpackMenu") then
set ti = BackpackMenu_ItemID()
set ts = "BackpackMenu"
elseif m == GetTableItem(s, "EquipmentMenu") then
set ti = EquipmentMenu_ItemID()
set ts = "EquipmentMenu"
elseif m == GetTableItem(s, "SwitchPage") then
set ti = SwitchPage_ItemID()
set ts = "SwitchPage"
endif
if g == 0 and (i == BackpackMenu_ItemID() or i == SwitchPage_ItemID()) then
set a = GetItemSlot(c, m)
call RemoveItem(m)
call UnitAddItemToSlotById(c, ti, a)
set m = UnitItemInSlot(c, a)
call SetTableObject(s, ts, m)
call SetItemCharges(m, g+1)
else
call SetItemCharges(m, 0)
endif
call CompressBackpack(s)
if i == EquipmentMenu_ItemID() then
call InventorySwapMenu(c, s, e, 1, 0, 0)
elseif i == BackpackMenu_ItemID() then
call InventorySwapMenu(c, s, e, 2, o, o)
elseif i == SwitchPage_ItemID() then
call InventorySwapMenu(c, s, e, 2, o, n)
elseif i == Cancel_ItemID() then
call InventorySwapMenu(c, s, e, 0, o, o)
call SetItemCharges(GetTableItem(s, "BackpackMenu"), GetTableInt(s, "BackpackItemsCount"))
endif
set c = null
set m = null
endfunction
function UnitReAddItem_Child takes nothing returns nothing
local timer t = GetExpiredTimer()
local string s = GetAttachmentTable(t)
local unit u = GetTableUnit(s, "Unit")
local item i = GetTableItem(s, "Item")
if IsItemOwned(i) and not UnitHasItem(u, i) then
call SetItemUserData(i, 2)
endif
call UnitAddItem(u, i)
call UnitDropItemSlot(u, i, GetTableInt(s, "Slot"))
call ClearTable(s)
call DestroyTimer(t)
set t = null
set u = null
set i = null
endfunction
function UnitReAddItem takes unit u, item i, integer s returns nothing
local timer t = CreateTimer()
local string a = GetAttachmentTable(t)
call SetTableObject(a, "Unit", u)
call SetTableObject(a, "Item", i)
call SetTableInt(a, "Slot", s)
call TimerStart(t, 0, false, function UnitReAddItem_Child)
set t = null
endfunction
function InventoryDropItemConditions takes nothing returns boolean
local integer i = GetItemTypeId(GetManipulatedItem())
if not IsUnitInGroup(GetManipulatingUnit(), udg_AAAInventoryGroup) then
return false
endif
if (i == EquipmentMenu_ItemID() or i == BackpackMenu_ItemID() or i == Cancel_ItemID() or i == SwitchPage_ItemID()) and (GetItemUserData(GetManipulatedItem()) == 0) then
return true
endif
if GetItemUserData(GetManipulatedItem()) == 2 then
call SetItemUserData(GetManipulatedItem(), 0)
return false
endif
return GetTableInt(GetAttachedString(GetManipulatingUnit(), "InventoryTable"), "CurrentMenu") > 0 and (GetItemUserData(GetManipulatedItem()) == 0)
endfunction
function InventoryDropItemActions takes nothing returns nothing
local unit c = GetManipulatingUnit()
local string s = GetAttachedString(c, "InventoryTable")
local item i = GetManipulatedItem()
local integer d = GetItemTypeId(i)
if GetItemType(i) == ITEM_TYPE_CHARGED and GetItemCharges(i) == 0 then
set d = GetTableInt(s, "CurrentBackpackPage")
call InventorySwapMenu(c, s, 2, 2, d, d)
elseif d == EquipmentMenu_ItemID() or d == SwitchPage_ItemID() then
call UnitReAddItem(c, i, 4)
call CS_Error(GetOwningPlayer(c), "Unable to drop this item.")
elseif d == BackpackMenu_ItemID() or d == Cancel_ItemID() then
call UnitReAddItem(c, i, 5)
call CS_Error(GetOwningPlayer(c), "Unable to drop this item.")
elseif GetTableInt(s, "CurrentMenu") > 0 then
call UnitReAddItem(c, i, GetItemSlot(c, i))
call CS_Error(GetOwningPlayer(c), "Can only drop items from the quick menu.")
endif
set c = null
set i = null
endfunction
function InventoryOrderConditions takes nothing returns boolean
if not IsUnitInGroup(GetOrderedUnit(), udg_AAAInventoryGroup) or GetIssuedOrderId() != OrderId("smart") or GetOrderTargetItem() == null then
return false
endif
return GetTableInt(GetAttachedString(GetOrderedUnit(), "InventoryTable"), "CurrentMenu") > 0
endfunction
function InventoryOrderActions takes nothing returns nothing
local unit c = GetOrderedUnit()
local string s = GetAttachedString(c, "InventoryTable")
call InventorySwapMenu(c, s, GetTableInt(s, "CurrentMenu"), 0, GetTableInt(s, "CurrentBackpackPage"), 0)
call IssueTargetOrder(c, "smart", GetOrderTargetItem())
set c = null
endfunction
function Init_AAAInventory takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger u = CreateTrigger()
local trigger d = CreateTrigger()
local trigger o = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddCondition(t, Condition( function InventoryDragItemConditions))
call TriggerAddAction(t, function InventoryDragItemActions)
call TriggerRegisterAnyUnitEventBJ( u, EVENT_PLAYER_UNIT_USE_ITEM )
call TriggerAddCondition(u, Condition(function InventoryUnitUsesItemConditions))
call TriggerAddAction(u, function InventoryUnitUsesItemActions)
call TriggerRegisterAnyUnitEventBJ( d, EVENT_PLAYER_UNIT_DROP_ITEM )
call TriggerAddCondition(d, Condition(function InventoryDropItemConditions))
call TriggerAddAction(d, function InventoryDropItemActions)
call TriggerRegisterAnyUnitEventBJ(o, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddCondition(o, Condition(function InventoryOrderConditions))
call TriggerAddAction(o, function InventoryOrderActions)
set t = null
set u = null
set d = null
set o = null
endfunction
//===========================================================================
function InitTrig_AAAInventory takes nothing returns nothing
call ExecuteFunc("Init_AAAInventory")
endfunction
[/jass] |
|