Вообщем суть такая, решил я оптимизировать сбор предметов на максимум с помощью следующего решения.
Все пердметы (рунные\нормальные\деактивированные) заносятся в переменные по общим массивом.
В хэштаблицу под названием "SS_Recipes" заносятся все рецепты.
Первое число = количество предметов нужных для сборки.
Последнее число (значение под номером один + 1) = индекс финального предмета. Промежуточные значения - индексы предметов требуемых для сборки.
Собственно базы уже готовы, осталось написать саму систему. Но вот здесь то что то не так. Код:
function CraftItem takes unit u, integer i returns nothing
local integer loop1=2
loop
exitwhen loop1 > LoadInteger(udg_SS_Recipes, i, 1)
call RemoveItem(GetItemOfTypeFromUnitBJ(u, udg_ITS_Item_Normal[LoadInteger(udg_SS_Recipes, i, loop1)]))
set loop1 = loop1+1
endloop
call UnitAddItemByIdSwapped(udg_ITS_Item_Normal[LoadInteger(udg_SS_Recipes, i, loop1)], u)
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin"))
endfunction
function Itempick takes nothing returns nothing
local unit u = GetManipulatingUnit()
local integer mi = GetItemTypeId(GetManipulatedItem())
local item i = GetManipulatedItem()
local integer array x
local integer array it
local integer array tit
local integer itemcount = udg_DB_ITEMCOUNT
local integer recipecount = udg_SS_Recipe_Count
local integer array recipe
local integer check1 = 0
local integer check2 = 1
if (GetItemUserData(i) == 0 ) or (GetItemUserData(i) == GetPlayerId(GetOwningPlayer(u))+1) then
set x[1] = 1
loop
exitwhen x[1] > 6
set x[2] = 1
loop
exitwhen x[2] > itemcount
if (GetItemTypeId(UnitItemInSlot(u, x[1])) == udg_ITS_Item_Normal[x[1]]) then
set it[x[1]] = x[2]
else
endif
set x[2] = x[2] + 1
endloop
set x[1] = x[1]+1
endloop
set x[1] = 1
loop
exitwhen x[1] > itemcount
if ( mi == udg_ITS_Item_Rune[x[1]]) or ( mi == udg_ITS_Item_Normal[x[1]]) then
set mi = x[1]
else
endif
set x[1] = x[1] +1
endloop
set x[1] = 1
set x[3] = 0
loop
exitwhen x[1] > recipecount
set x[2] = 2
loop
exitwhen x[2] > LoadInteger(udg_SS_Recipes, x[1], 1)
if (LoadInteger(udg_SS_Recipes, x[1], x[2]) == mi) then
set x[3] = x[3] + 1
set recipe[x[3]] = x[1]
else
endif
set x[2] = x[2] + 1
endloop
set x[1] = x[1] + 1
endloop
call BJDebugMsg("Matching Recipes Count: " + I2S(x[3]))
set x[15] = x[3]
if ( x[3] > 0 )then
set x[1] = 1
loop
exitwhen x[1] > x[3]
set check1 = 1
set x[2] = 2
loop
exitwhen x[2] > LoadInteger(udg_SS_Recipes, recipe[x[1]], 1)
set tit[(x[2]-1)] = LoadInteger(udg_SS_Recipes, recipe[x[1]], x[2])
set x[2] = x[2] +1
endloop
set x[2] = 1
loop
exitwhen x[2] > 6
set x[3] = 1
loop
exitwhen x[3] == LoadInteger(udg_SS_Recipes, recipe[x[1]], 1)
if (it[x[2]] == tit[x[3]] ) then
set check1 = check1 + 1
call BJDebugMsg("Recipe Count: " + I2S(x[15]))
call BJDebugMsg("x[2] is " + I2S(x[2]))
call BJDebugMsg("x[3] is " + I2S(x[3]))
call BJDebugMsg("Current Recipe Needs Count of Items :" + I2S(LoadInteger(udg_SS_Recipes, recipe[x[1]], 1)-1))
call BJDebugMsg("Recipe Matching Items: " + I2S(check1))
set tit[x[3]] = 999
else
endif
if (x[2] == 6) and (check1 == LoadInteger(udg_SS_Recipes, recipe[x[1]], 1)-2) then
call CraftItem(u, x[1])
set check2 = 0
else
set check1 = 1
endif
set x[3] = x[3] + 1
endloop
set x[2] = x[2]+1
endloop
set x[1] = x[1]+1
endloop
else
endif
if (check2 == 1 ) then
if (UnitInventoryCount(u) < 6 ) then
call UnitAddItemById(u, udg_ITS_Item_Normal[mi])
call SetItemUserData(GetLastCreatedItem(), GetPlayerId(GetOwningPlayer(u))+1)
else
call CreateItem(udg_ITS_Item_Rune[mi], GetUnitX(u),GetUnitY(u))
call SetItemUserData(GetLastCreatedItem(), GetPlayerId(GetOwningPlayer(u))+1)
endif
else
endif
else
call UnitAddItemById(u, udg_ITS_Item_Disabled[mi])
call SetItemUserData(GetLastCreatedItem(), GetItemUserData(i))
endif
set u = null
set i = null
endfunction
//===========================================================================
function InitTrig_ItemSystem______________________2 takes nothing returns nothing
set gg_trg_ItemSystem______________________2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_ItemSystem______________________2, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_ItemSystem______________________2, function Itempick )
endfunction
смысл в том что почему то дебагмсг выдает Recipe Matching Items всегда 2.