• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Inventory API

Level 19
Joined
Mar 18, 2012
Messages
1,716
Inventory API

JASS:
//=========================================================================
// Collection of the entire Inventory API
//=========================================================================

//=========================================================================
// Item classes.
// Every custom item requires an item class
// to determine into which slots the item can go.
// The root of every class is ItemClass.ANY ( 1 )
//=========================================================================
// Example: 
    set ITEM_CLASS_HAND   = ItemClass.create("Hand")
    set ITEM_CLASS_WEAPON = ITEM_CLASS_HAND.createSubClass("Weapon")
    set ITEM_CLASS_SWORD  = ITEM_CLASS_WEAPON.createSubClass("Sword")
    // • An item of class "sword" can only go in a sword slot.
    // • An item of class "hand" can go in an hand, weapon and sword slot.
    // • An item of class "ANY" can go into any slow.
    
    struct ItemClass extends array
    
        // Fiels you can read.
        readonly thistype parent 
        readonly string   name

        // Every item class is based of ANY.
        static constant thistype ANY = 1
    
        // Returns true for this == ANY
        method operator root  takes nothing returns boolean
        
        // Every class is a sub class of ItemClass.ANY.
        static method create  takes string name returns thistype

        // Any -> Hand -> Weapon -> Sword -> Mighty Sword ....
        method createSubClass takes string name returns thistype

//=========================================================================
// Extended item object data.
// These function are ment to call on map init.
//=========================================================================

    //=========================================================================
    // Item registration.
    //=========================================================================

    // Registers an item id as custom item. 
    function RegisterCustomItemId takes integer itemId, ItemClass class returns nothing
    //  • Item ids of type ITEM_TYPE_POWERUP are invalid.
    //  • Item ids of type ITEM_TYPE_PURCHASABLE are valid, but remain in the native inventory interface.

    function IsCustomItemId       takes integer itemId returns boolean
    function IsCustomItem         takes item whichItem returns boolean

    // Returns true if a given item is of ItemClass "class".
    function IsCustomItemClass    takes item whichItem, ItemClass class returns boolean
    function GetCustomItemIdClass takes integer itemId returns ItemClass
    function GetCustomItemClass   takes item whichItem returns ItemClass

    //===================================================================================
    // Icon path and icon disabled path. 
    //===================================================================================
    // If you don't set a DIS path, the default DIS path 
    // from the user setup library is accessed instead. 
    
    // Set paths for the visual objects. 
    // You can use string paths for images or raws for destructable objects or both.
    function SetCustomItemIcon takes integer itemId, string filePath, string DISfilePath, integer destId, integer DISdestId returns nothing
    //  • Example 1: call SetCustomItemIcon('I000', null, null, 'B000', 'B001')
    //  • Example 2: call SetCustomItemIcon('I001', itemImageTextureFilePath.tga", itemImageTextureDisabledFilePath.tga, 0, 0)

    function GetCustomItemIconPath      takes integer itemId returns string
    function GetCustomItemIconDISPath   takes integer itemId returns string
    function GetCustomItemIconId        takes integer itemId returns integer
    function GetCustomItemIconDISId     takes integer itemId returns integer
    
    //===================================================================================
    // Twohanded items. 
    //===================================================================================
    // This function declares an item id as a twohanded item type.
    // By default every item id is not twohanded.
    
    function SetCustomItemTwohand takes integer itemId, boolean flag returns nothing
    function IsCustomItemTwohand  takes item whichItem returns boolean

    //===================================================================================
    // Special effects. Animation properties. Complex special effects.
    //===================================================================================
    // These effects are added when items are equipped.
    
    // AddSpecialEffectTarget(path, inventoryUnit, pos)     
    function SetCustomItemFxFilePath        takes integer itemId, string path, string pos returns nothing
    
    // For effects with multiple attach point names an ability is the best choice.
    // The ability should serve as pure visual and don't add any further bonuses.
    function SetCustomItemFxAbilityId       takes integer itemId, integer abilityId returns nothing
    
    // Animation tag of the item. By default it is "".
    // AddUnitAnimationProperties(inventoryUnit, tag, true)
    function SetCustomItemAnimationProperty takes integer itemId, string tag returns nothing
    
    function GetCustomItemFxFilePath        takes integer itemId returns string
    function GetCustomItemFxPos             takes integer itemId returns string
    function GetCustomItemFxAbilityId       takes integer itemId returns integer
    function GetCustomItemAnimationProperty takes integer itemId returns string

    
    // Complex fx.
    function SetCustomItemFxAbilityId takes integer itemId, integer abilityId returns nothing
        call SaveInteger(Inventory_GetTable(), INVENTORY_KEY_ITEM_DATA + 3, itemId, abilityId)
    endfunction
    
    function GetCustomItemFxAbilityId takes integer itemId returns integer
    
    //===================================================================================
    // Item socket count from min to max. Min == 0, Max == 6
    //===================================================================================
    // BOTH FUNCTIONS ARE NOT WORKING YET.
    
    function SetCustomItemIdSockets takes integer itemId, integer min, integer max returns nothing
    
    // Randomizes a socket count from min - max.
    function GetCustomItemIdSockets takes integer itemId returns integer

    //===================================================================================
    // Item costs and charges.
    //===================================================================================
    
    function GetItemTypeIdGoldCost  takes integer id returns integer
    function GetItemTypeIdWoodCost  takes integer id returns integer
    function GetItemTypeIdCharges   takes integer id returns integer
    function GetItemGoldCost        takes item i returns integer
    function GetItemWoodCost        takes item i returns integer
    
    //===================================================================================
    // Misc wrappers functions of CustomItem 
    //===================================================================================
    
    // ITEM_TYPE_PURCHASABLE
    function IsItemPurchasable takes item whichItem returns boolean

    //===================================================================================
    // Struct CustomItem 
    //===================================================================================
    
    struct CustomItem extends array
    
        // Is the item allocated or not.
        method operator exists takes nothing returns boolean
    
        // Equals GetHandleId(i). Always use CustomItem[]
        static method operator [] takes item i returns thistype
        
        // Returns the item handle of an handle id.
        method getItem      takes nothing returns item
        method getItemId    takes nothing returns integer
        
        // Use getItem() instead.
        method getHandle    takes nothing returns item
        
        // Set an owning unit.
        method getOwner     takes nothing returns unit 
        method setOwner     takes unit source returns nothing

        // Not implemented. ( Item cooldowns )
        method isReady      takes nothing returns boolean

        // Returns true for a total item merging. MAX_CHARGES = 99.
        method mergeCharges takes item add returns boolean 
        
        method getClass     takes nothing returns ItemClass

        // From 0.00 - 1.00 ( 0% - 100%)
        method getQuality   takes nothing returns real
        method setQuality   takes real value returns nothing

        method getWoodCost  takes nothing returns integer
        method getGoldCost  takes nothing returns integer

        // Returns custom name if set. Otherwise GetItemName()
        method getName      takes nothing returns string
        method setName      takes string name returns nothing
        
        method isItemPawnPossible takes unit seller, unit shop returns boolean
        method pawnItem           takes unit shop returns nothing

        // ( Not implemented yet )
        method isItemBuyPossible takes unit buyer, unit seller returns boolean
        
//=========================================================================
// Item affixes.
// These are lists of Bonuses, abilties or ItemPowers
// an item should add to a unit when beeing equipped.
//=========================================================================
    
    // Registers an abiltity to an item id.
    function AddCustomItemIdAbility         takes integer itemId, integer abilityId, integer level returns nothing 
    
    // Requires library BonusMod: Register Bonuses to item id.
    function AddCustomItemIdBonus           takes integer itemId, integer bonus, integer amount returns nothing
    
    // Requires library ItemPower: Registers ItemPowers to item id.
    function AddCustomItemIdItemPower       takes integer itemId, integer power, real amount returns nothing

    // Those functions register affixes directly to item handles.
    // The item parser requires them for dynamic item data,
    // you probably don't need these functions.
    function AddCustomItemAbility           takes item i, integer abilityId, integer level returns nothing 
    function AddCustomItemBonus             takes item i, integer bonus, integer amount returns nothing
    function AddCustomItemItemPower         takes item i, integer power, real amount returns nothing
    function FlushCustomItemAffixes         takes item i returns nothing
    
    
//=========================================================================
// Inventory interface.
//=========================================================================
// Each inventory has a hardcoded size of 1500*833 in plane x / y.

    // Create() and Destroy()
    function CreateInventory       takes unit source, real originX, real originY returns Inventory
    function DestroyInventory      takes unit source returns nothing
    function GetUnitInventory      takes unit source returns Inventory
    
    function AddUnitInventoryDummy takes unit source, integer dummyId, real dummyY returns nothing
    //  • Optional function with adds a portrait to the interface.
    //  • "dummyY" is the offset in plane y inside the dummy window. ( Different per unit id )
     
//===================================================================================
// Inventory events. 
// When an event trigger fires these values allow
// the action code to determine which event was dispatched.
// The functions listed below can be used to get information about the event.
//===================================================================================

    globals
        //=========================================
        // Available Event Ids.
        //=========================================
                         // RegisterInventoryEvent(eventId, code)
        constant integer EVENT_INVENTORY_UNIT_EQUIP_ITEM   = 0
        constant integer EVENT_INVENTORY_UNIT_UNEQUIP_ITEM = 1
        constant integer EVENT_INVENTORY_UNIT_PICKUP_ITEM  = 2
        constant integer EVENT_INVENTORY_UNIT_DROP_ITEM    = 3
        constant integer EVENT_INVENTORY_UNIT_PAWN_ITEM    = 4
        constant integer EVENT_INVENTORY_UNIT_BUY_ITEM     = 5// ( Not working yet )    
        constant integer EVENT_INVENTORY_UNIT_TRADE_ITEM   = 6// ( Not working yet ) 
        // 
        constant integer MAX_INVENTORY_EVENTS              = 7
    endglobals
    
    //=========================================
    // Inventory trigger interface.
    //=========================================
    // Returns the trigger handle for the specified event id,
    // in order to use it with the native trigger interface.
    // Use this function very carefully.
    function GetInventoryTrigger takes integer eventId returns trigger
    
    //=======================================================
    // Trigger Inventory Event API.
    //=======================================================
    // These functions only return their proper information when called
    // from within a registered trigger action function.
    // For incorrect usage they will either return "null", "-1" or "0".
    
    // Returns the triggering Inventory instance.
    constant function GetTriggerInventory takes nothing returns Inventory
    
    // Returns the interacting item.
    constant function Inventory_GetTriggerItem takes nothing returns item
    
    // Returns the interacting unit handle.
    // Can be null for some event ids.
    constant function Inventory_GetEventTargetUnit takes nothing returns unit
    
    // Returns the most recent event id.
    constant function Inventory_GetTriggerEventId takes nothing returns integer
    
    // Returns the inventory owning unit handle.
    constant function Inventory_GetTriggerUnit takes nothing returns unit 

    // Registers code to available inventory events. 
    // Condition function not have to return a boolean, as the function outsmarts PJASS. 
    function RegisterInventoryEvent takes integer eventId, code func returns nothing
     
//=======================================================
// Struct Inventory.
//=======================================================
     
    struct Inventory extends UIScreen
        
        
        readonly unit    source// Owning unit.
        readonly unit    dummy
        readonly real    dummyY
        readonly unit    shop
                         // AddUnitAnimationProperties()
        readonly string  animation
        
        // The global user setup defines a default font for all instances, 
        // you can change it at any time via this.setFont(font).
        private integer fontType             
        method getFont takes nothing returns integer
        method setFont takes integer newFont returns nothing
        
        // The global user setup defines a default color for all instances,
        // you can change it any time via this.setColor(ARGB)
        private integer color
        method getColor takes nothing returns ARGB
        method setColor takes integer newColor returns nothing
        
        method unitHasItemEquipped   takes item whichItem returns boolean
        method unitHasItemIdEquipped takes integer itemId returns boolean
     
        method mergeItems            takes item target, item source returns boolean
        method unitRemoveItem        takes item whichItem returns boolean
        method unitUnequipItemToSlot takes item whichItem, InventoryCell slot returns boolean
        
        // Equips items to the unit.  
        method unitEquipItemToSlot   takes item whichItem, InventoryCell slot, boolean forceAction returns boolean
        method unitEquipItem         takes item whichItem returns boolean

        // Only accepts Backpack cells as slot.
        method unitAddItemToSlot     takes item whichItem, InventoryCell slot returns boolean
        method unitAddItem           takes item whichItem returns boolean
        
        // UNDER CONSTRUCTION.
        method unitPawnItem          takes item whichItem, unit shop returns boolean
        
        // UNDER CONSTRUCTION.
        method unitBuyItem           takes item whichItem, unit shop returns boolean

        // UNDER CONSTRUCTION.
        method unitTradeItem         takes item whichItem, thistype partner returns boolean
        
        // UNDER CONSTRUCTION.
        method socketItem            takes item whichItem, item gem returns boolean
        
        // UNDER CONSTRUCTION.
        method unsocketItem          takes item whichItem returns boolean
   
//=======================================================
// Struct id getters.
//=======================================================
   
    constant function GetInventoryEquipmentTypeId        takes nothing returns integer
    constant function GetInventoryBackpackTypeId         takes nothing returns integer
    constant function GetInventoryMerchantTypeId         takes nothing returns integer
    constant function GetInventoryNativeInventoryTypeId  takes nothing returns integer
    constant function GetInventoryDummyTypeId            takes nothing returns integer
    constant function GetInventoryControllTypeId         takes nothing returns integer
    constant function GetInventoryTradeTypeId            takes nothing returns integer
Last edited:
Top