XGM Forum
Сайт - Статьи - Проекты - Ресурсы - Блоги

Форуме в режиме ТОЛЬКО ЧТЕНИЕ. Вы можете задать вопросы в Q/A на сайте, либо создать свой проект или ресурс.
Вернуться   XGM Forum > Warcraft> Академия: форум для вопросов> Jass
Ник
Пароль
Войти через VK в один клик
Сайт использует только имя.

Ответ
 
FKoFF
Venomancer 89lvl. Europe
offline
Опыт: 5,975
Активность:
Item Craft System
Вообщем суть такая, решил я оптимизировать сбор предметов на максимум с помощью следующего решения.
Все пердметы (рунные\нормальные\деактивированные) заносятся в переменные по общим массивом.
В хэштаблицу под названием "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&​quot;, 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.

Отредактировано FKoFF, 25.11.2010 в 08:36.
Старый 25.11.2010, 07:40
FKoFF
Venomancer 89lvl. Europe
offline
Опыт: 5,975
Активность:
После длительных эксперементов написал уже четвертую или пятую по счету систему. Однако по какой то причине не отзывается дебаг check, ни первый, ни второй.
Просьба умельцев заставить это работать и по возможности подогнать еще это под возможность крафтить когда в рецепте учавствует более одного одинакового предмета.
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&​quot;, u, "origin"))
endfunction

 function GetItemIndex takes item i returns integer
local integer loop1
local integer int
set loop1 = 1
loop
exitwhen loop1 > udg_DB_ITEMCOUNT
if GetItemTypeId(i) == udg_ITS_Item_Normal[loop1] or GetItemTypeId(i) == udg_ITS_Item_Rune[loop1] then
set int = loop1
//                                              debug
call BJDebugMsg("Предмет опознан " + I2S(loop1))
//                                               enddebug
else
endif
set loop1 = loop1 +1
endloop

return int
endfunction


function Itempick takes nothing returns nothing
local integer A = 1
local integer B = 1
local integer C = 1
local integer D = 1
local integer E = 1
local integer F = 0
local unit u = GetManipulatingUnit()
local integer array inslot
local integer array inrecipe
local hashtable SS = udg_SS_Recipes
local integer check = 0
local integer crafted = 0
local item i =null
local item mi = GetManipulatedItem()

loop
exitwhen E > udg_DB_ITEMCOUNT
if ( GetItemTypeId(mi) == udg_ITS_Item_Rune[E] ) then

loop
exitwhen A > 6
if (UnitItemInSlot(u,A) != null ) then
set inslot[A] = GetItemIndex(UnitItemInSlot(u,A))
else
set inslot[A] = 999
endif
set A = A+1
endloop

set inslot[7] = GetItemIndex(mi)

if GetItemUserData(mi) == 0  or GetItemUserData(mi) == GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1 then


set A = 1
loop
exitwhen A > udg_SS_Recipe_Count

set B = 1
loop
exitwhen B > LoadInteger(SS,A, 1)
                                            

  if LoadInteger(SS,A,B) == inslot[7] then
    set F = F +1
    set inrecipe[F] = A
    else
    endif
set B = B+1
endloop

set A = A+1
endloop

set A = 1
loop
exitwhen A > F
//                                              debug
call BJDebugMsg("Третий Этап. Цикл 'A' " + I2S(A))
//   
    set C = 2
    set check = 0
    loop
    exitwhen C > LoadInteger(SS,A,1)
      set D = 1
      loop
      exitwhen D > 7
      
       if LoadInteger(SS,A,C) == inslot[D] then
       set check = check+1
//                                              debug
call BJDebugMsg("Check First " +I2S(check))
//                                               enddebug
       if LoadInteger(SS,A,1) == check+1 then
//                                              debug
call BJDebugMsg("Check Second" +I2S(check))
//  
       call CraftItem(u, A)
       set A = udg_SS_Recipe_Count
       set crafted = 1
       else
       endif

       exitwhen check == check
       else
//                                              debug
call BJDebugMsg("Совпадений не найдено")
//   
       endif
      set D = D+1
      endloop
    set C = C+1
    endloop
    
set A = A+1
endloop


if crafted == 0 then 
if UnitInventoryCount(u) < 6 then
set i = UnitAddItemById(u, udg_ITS_Item_Normal[inslot[7]])
call SetItemUserData(i, GetItemUserData(mi))
else
set i = CreateItem(udg_ITS_Item_Rune[inslot[7]], GetUnitX(u),GetUnitY(u))
endif
else
endif




else

set i = UnitAddItemById(u, udg_ITS_Item_Disabled[inslot[7]])
call SetItemUserData(i,GetItemUserData(mi))
set i = null
endif

else
endif

set E = E +1
endloop

set mi = null
set SS = 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

Отредактировано FKoFF, 26.11.2010 в 14:24.
Старый 26.11.2010, 13:18
Ответ

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы можете скачивать файлы

BB-коды Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход



Часовой пояс GMT +3, время: 10:15.