package ItemData import initlater PlayerData import ItemTypeGen integer currItemTimestamp // Item API: public function xSpawnItem(int raw, vec2 pos) returns item let itm = createItem(raw, pos) new ItemData(itm) return itm public function xSpawnItem(string name, vec2 pos) returns item return xSpawnItem(itemName2Raw(name), pos) public function xCreateItemForPlayerHero(int playerId, string itemName) returns item return xCreateItemForHero(xGetPlayerHero(playerId), itemName) public function xCreateItemForHero(unit hero, int itemRaw) returns item item itm = null if hero != null itm = xSpawnItem(itemRaw, hero.getPos()) UnitAddItem(hero, itm) return itm public function xCreateItemForHero(unit hero, string itemName) returns item item itm = null if hero != null itm = xSpawnItem(itemName, hero.getPos()) UnitAddItem(hero, itm) return itm public function item.xGetItemData() returns ItemData return this.getUserData() castTo ItemData public function getItemTimestamp() returns int return currItemTimestamp public function increaseItemTimestamp() currItemTimestamp++ // ---- public class ItemData item i protected int boundTo protected int itemTimestamp construct(item i) i.setUserData(this castTo int) boundTo = -1 itemTimestamp = currItemTimestamp function bind(int playerId) boundTo = playerId function getBound() returns int return boundTo // Bind sold items and assign them a ItemData object function itemSoldAction() let itm = GetSoldItem() let hero = GetBuyingUnit() new ItemData(itm).bind(hero.getOwner().getId()) init currItemTimestamp = 1 CreateTrigger() ..registerPlayerUnitEvent(Player(PLAYER_NEUTRAL_PASSIVE), EVENT_PLAYER_UNIT_SELL_ITEM, null) ..addAction(function itemSoldAction)