tgonta
Pixelated Sora Coder
offline
Опыт:
3,160
Активность:
|
Recipe System - помогите исправить...
» Вот здесь код.
function GetUnitItemSlot takes unit u, integer itemID returns integer
local integer i = 0
local item it
loop
exitwhen i > 5
set it = UnitItemInSlot(u,i)
if GetItemTypeId(it) == itemID then
return i
endif
set it = null
set i = i + 1
endloop
return -1
endfunction
function GetItemRecipeIndex takes integer nitype returns integer
local integer i = 0
local integer i2
loop
exitwhen i > udg_TotalRecipes
set i2 = 1
loop
exitwhen i2 > 7
if LoadInteger(udg_RecipeHash,i,i2) == nitype then
return i
endif
set i2 = i2 + 1
endloop
set i = i + 1
endloop
return -1
endfunction
function IsItemRecipe takes integer nitype returns boolean
if GetItemRecipeIndex(nitype) > -1 then
return true
endif
return false
endfunction
function GetUnitItemTypeCount takes unit u, integer itype returns integer
local integer i = 0
local integer c = 0
loop
exitwhen i > 5
if GetItemTypeId(UnitItemInSlot(u,i)) == itype then
set c = c + 1
endif
set i = i + 1
endloop
return c
endfunction
function CountRecipeComponents takes integer index returns integer
local integer i = 1
loop
exitwhen i > 7
if LoadInteger(udg_RecipeHash,index,i) == null then
return i - 1
endif
set i = i + 1
endloop
return 0
endfunction
function CheckRecipeComponents takes unit u, integer index, integer pitemid returns boolean
local integer i = 1
local integer ctype
local integer slot
local boolean b
loop
exitwhen i > CountRecipeComponents(index)
set ctype = LoadInteger(udg_RecipeHash,index,i)
if ctype == pitemid and b == false then
set b = true
else
set slot = GetUnitItemSlot(u,ctype)
if slot == -1 then
return false
endif
endif
set i = i + 1
endloop
return true
endfunction
function MakeRecipe takes unit u, integer rindex, integer pitemid returns nothing
local integer array cmp
local integer i = 1
local boolean is
local integer slot
loop
exitwhen i > CountRecipeComponents(rindex)
set cmp[i] = LoadInteger(udg_RecipeHash,rindex,i)
if cmp[i] == pitemid and is == false then
set is = true
else
set slot = GetUnitItemSlot(u,cmp[i])
call RemoveItem(UnitItemInSlot(u,slot))
endif
set i = i + 1
endloop
call UnitAddItemById(u,LoadInteger(udg_RecipeHash,rindex,0))
endfunction
Эта группа функций работает некорректно - если покупается любой из компонентов любого рецепта, то условия всегда выдают true.
» Код добавления предмета юниту - обратите внимание на первое условие.
function GiveItemToUnit takes item ri, unit u returns boolean
local integer riid = GetItemTypeId(ri)
local integer niid = RuneToNorm(riid)
local item uiis = GetUnitItemOfType(u,niid)
if UnitHasEmptySlot(u) then
if IsItemRecipe(niid) and CheckRecipeComponents(u,GetItemRecipeIndex(niid),niid) then
call MakeRecipe(u,GetItemRecipeIndex(niid),niid)
elseif uiis != null and GetItemCharges(uiis) > 0 then
call CombineItemCharges(uiis,ri)
elseif GetItemCharges(ri) > 0 then
set uiis = UnitAddItemById(u,niid)
call SetItemCharges(uiis,GetItemCharges(ri))
else
call UnitAddItemById(u,niid)
endif
set uiis = null
return true
else
if IsItemRecipe(niid) and CheckRecipeComponents(u,GetItemRecipeIndex(niid),niid) then
call MakeRecipe(u,GetItemRecipeIndex(niid),niid)
elseif uiis != null and GetItemCharges(uiis) > 0 then
call CombineItemCharges(uiis,ri)
set uiis = null
return true
endif
set uiis = null
endif
return false
endfunction
|