- Joined
- Jul 10, 2007
- Messages
- 6,306
JASS:
library L55 uses Catalog, Table, AVL
globals
private Table heroCatalogTable
private Table array levelCatalogTable
private timer dest = CreateTimer()
private integer array rec
private integer recc = 0
endglobals
private function Dest takes nothing returns nothing
loop
set recc = recc - 1
call CatalogDestroy(rec[recc])
exitwhen 0 == recc
endloop
endfunction
private struct LevelTree extends array
private method lessThan takes thistype val returns boolean
return integer(this)<integer(val)
endmethod
private method greaterThan takes thistype val returns boolean
return integer(this)>integer(val)
endmethod
private method difference takes thistype val returns integer
return integer(this)-integer(val)
endmethod
implement AVL
endstruct
private struct ItemRead extends array
method operator [] takes integer itemTypeId returns integer
return CatalogId(this, itemTypeId)
endmethod
endstruct
struct LevelFilter extends array
method levels takes integer minLevel, integer maxLevel returns ItemRead
local integer cata = CatalogCreate()
loop
set minLevel = LevelTree(this).searchClose(minLevel,false)
call CatalogAddCatalog(cata, levelCatalogTable[this][minLevel])
exitwhen 0 == minLevel or minLevel > maxLevel
set minLevel = minLevel + 1
endloop
set rec[recc] = cata
set recc = recc + 1
call TimerStart(dest,0,false,function Dest)
return cata
endmethod
static method getCatalog takes LevelTree heroCatalog, integer level returns integer
local integer levelPointer
local integer levelCatalog = heroCatalog.search(level)
if (0 == levelCatalog) then
set levelPointer = heroCatalog.add(level)
set levelCatalog = CatalogCreate()
set levelCatalogTable[heroCatalog][levelPointer] = levelCatalog
endif
return levelCatalog
endmethod
endstruct
private struct HeroFilter extends array
static method operator [] takes integer heroTypeId returns LevelFilter
return levelCatalogTable[heroTypeId]
endmethod
static method getCatalog takes integer heroTypeId, integer level returns integer
local LevelTree heroCatalog
if (not heroCatalogTable.has(heroTypeId)) then
set heroCatalog = LevelTree.create()
set heroCatalogTable[heroTypeId] = heroCatalog
set levelCatalogTable[heroCatalog] = Table.create()
else
set heroCatalog = heroCatalogTable[heroTypeId]
endif
return LevelFilter.getCatalog(heroCatalog, level)
endmethod
endstruct
struct ItemCatalog extends array
static method operator [] takes integer heroTypeId returns LevelFilter
return HeroFilter[heroTypeId]
endmethod
method add takes integer itemTypeId, integer heroTypeId, integer level returns nothing
local integer levelCatalog = HeroFilter.getCatalog(heroTypeId, level)
call CatalogAdd(levelCatalog, itemTypeId)
endmethod
private static method onInit takes nothing returns nothing
set heroCatalogTable = Table.create()
endmethod
endstruct
endlibrary
JASS:
function tester takes nothing returns nothing
local integer HERO_ID = 'Hpal'
local integer HERO_MIN_LEVEL = 15
local integer HERO_MAX_LEVEL = 17
local integer ITEM_ID = 'lowc'
local integer itemCatalog = ItemCatalog[HERO_ID].levels(HERO_MIN_LEVEL, HERO_MAX_LEVEL)
local integer itemCatalogId = ItemCatalog[HERO_ID].levels(HERO_MIN_LEVEL, HERO_MAX_LEVEL)[ITEM_ID]
endfunction
So I've pretty much split it up into 1 struct per filter or w/e. This makes it much, much, much easier to add new filters on : ).
For example, if the catalog needed version control, just add a version control filter with yet another array and create the versions as the things are added for specific versions
If the catalog needed slot specific gear, add on another filter and create the slot specific gear things as the items are added
Ofc, u can also create all versions, slot specific gear, etc in onInit, but that ends up being more work : p
Anyways, just thought I'd share my findings ; ). I'll be including how to do all of this in the advanced catalog section of the interactive tutorial I'm writing too : p.
Last edited: