/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Wietlol's Item Set System 1.4.1 11/07/2016
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Description:
// This system is made to create item sets.
// You must configure the item sets that you want them to be and the system will do the rest.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// How to install:
// 1. Copy or create all variables that are used in this map into your map.
// 2. Copy all triggers from the Item Set System (ISS) category and paste it into your map.
// 3. Create and register some items and abilities.
// 4. Enjoy your Item Set System.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Feature list:
// This system can make item sets... thats it :)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variable explaination:
//////////////////////////
// Map Initialization:
// - ISS_Trigger_Create_Set - trigger
// This is the function that saves item-types and abilities to an item set.
//
// - ISS_Hashtable - hashtable
// This is the hashtable that is used to save the data of the item sets.
//
// - No_Ability - ability (integer in JASS)
// This is a null-variable. It is used to set ability variables back to null/0
//
//////////////////////////
// Parameters:
// - ISS_Param_Index - integer
// This is a unique code for each item set.
// Under this integer, the data of the item set is saved.
//
// - ISS_Param_Ability_Array[] - ability[] (integer array in JASS)
// This is an array of the abilities that an item set gives to the unit.
//
// - ISS_Param_Ability_Number - integer
// This is the amount of abilities that an item set has.
//
// - ISS_Param_Buff_Array[] - buff[] (integer array in JASS)
// This is an array of the buffs for instant replacing of the buff.
// It uses ISS_Param_Ability_Number as well for the amount.
//
// - ISS_Param_Item_Type_Array[] - item-type[] (itemtype array in JASS)
// This is an array of all the items that an item set has.
//
// - ISS_Param_Item_Type_Number - integer
// This is the amount of item-types that an item set has.
//
// - ISS_Param_Tooltip - ability (integer in JASS)
// This is the ability that makes the toolip buff for the unit.
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Changelog:
// 1.4.1 - 11/07/2016 - Fixed bug.
// Bug fixed where removing an item of a set would remove the wrong effect.
//
// 1.4 - 01/04/2015 - Buff Configuration Version.
// Fixed double-buff-bug by adding buff removal and buff configuration.
// Now automatically creates index numbers.
// Fixed a few leaks and optimized code a bit.
// Added condition to triggers for people who want to use TriggerEvaluate() instead of TriggerExecute().
//
// 1.3 - 03/02/2015 - Update on review of IcemanBo, Edo494 and Mythic.
// Merged the Save_Set and Save_Ability triggers to one Create_Set trigger.
// Function names are smaller.
// Local variable leaks removed.
//
// 1.2 - 28/01/2015 - Update of reworked system.
// Now all code is inside one trigger.
// Functions can be called using global variables.
//
// 1.1 - First official release on the Hive.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Known bugs:
// - None
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This code is handling item sets on units.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This function adds a stack of an item set.
function ISS_Add_Stack takes nothing returns boolean
local unit u
local integer unitId
local integer index = LoadInteger(udg_ISS_Hashtable, GetItemTypeId(GetManipulatedItem()), 0)
local integer level
local integer abilityId
local integer buffId
local integer tooltip
//The item is not attached to an item set.
if index == 0 then
return false
endif
set u = GetManipulatingUnit()
set unitId = GetHandleId(u)
set level = LoadInteger(udg_ISS_Hashtable, unitId, index)
set abilityId = LoadInteger(udg_ISS_Hashtable, index, level*2 + 1)
set buffId = LoadInteger(udg_ISS_Hashtable, index, level*2)
set tooltip = LoadInteger(udg_ISS_Hashtable, index, 0)
call SaveInteger(udg_ISS_Hashtable, unitId, index, level + 1)
call UnitRemoveAbility(u, buffId)
//Increase the level of the tooltip
if GetUnitAbilityLevel(u, tooltip) > 0 then
call SetUnitAbilityLevel(u, tooltip, level + 1)
else
call UnitAddAbility(u, tooltip)
endif
//Increase the level of the effect.
if abilityId != 0 then
if GetUnitAbilityLevel(u, abilityId) > 0 then
call IncUnitAbilityLevel(u, abilityId)
else
call UnitAddAbility(u, abilityId)
endif
endif
set u = null
return false
endfunction
//This function removes a stack of an item set.
function ISS_Remove_Stack takes nothing returns boolean
local unit u
local integer unitId
local integer index = LoadInteger(udg_ISS_Hashtable, GetItemTypeId(GetManipulatedItem()), 0)
local integer level
local integer abilityId
local integer buffId
local integer tooltip
//The item is not attached to an item set.
if index == 0 then
return false
endif
set u = GetManipulatingUnit()
set unitId = GetHandleId(u)
set level = LoadInteger(udg_ISS_Hashtable, unitId, index) -1
set abilityId = LoadInteger(udg_ISS_Hashtable, index, level*2 + 1)
set buffId = LoadInteger(udg_ISS_Hashtable, index, level*2 +2)
set tooltip = LoadInteger(udg_ISS_Hashtable, index, 0)
call SaveInteger(udg_ISS_Hashtable, unitId, index, level)
call UnitRemoveAbility(u, buffId)
//Decrease the level of the tooltip.
if GetUnitAbilityLevel(u, tooltip) > 1 then
call SetUnitAbilityLevel(u, tooltip, level)
else
call UnitRemoveAbility(u, tooltip)
endif
//Decrease the level of the effect.
if abilityId != 0 then
if GetUnitAbilityLevel(u, abilityId) > 1 then
call DecUnitAbilityLevel(u, abilityId)
else
call UnitRemoveAbility(u, abilityId)
endif
endif
set u = null
return false
endfunction
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This code is the function that this system has.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This function saves the item-types and abilities on an item set.
function ISS_Create_Set takes nothing returns boolean
//Requires:
// - ISS_Item_Type[]
// - ISS_Item_Type_Number
// - ISS_Ability[]
// - ISS_Ability_Number
// - ISS_Tooltip[]
local integer i = 0
local integer index = 0
set udg_ISS_Param_Index = udg_ISS_Param_Index + 1
call SaveInteger(udg_ISS_Hashtable, udg_ISS_Param_Index, 0, udg_ISS_Param_Tooltip)
loop
exitwhen i > udg_ISS_Param_Item_Type_Number
call SaveInteger(udg_ISS_Hashtable, udg_ISS_Param_Item_Type_Array[i], 0, udg_ISS_Param_Index)
set i = i + 1
endloop
set i = 0
loop
exitwhen i > udg_ISS_Param_Ability_Number*2
call SaveInteger(udg_ISS_Hashtable, udg_ISS_Param_Index, i + 1, udg_ISS_Param_Ability_Array[index])
call SaveInteger(udg_ISS_Hashtable, udg_ISS_Param_Index, i + 2, udg_ISS_Param_Buff_Array[index])
set i = i + 2
set index = index + 1
endloop
return false
endfunction
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This code is the initialization of the system and it's functions.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This is the initial function.
function InitTrig_ISS_System takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local integer index = 0
local player p
set udg_ISS_Param_Index = 0
call TriggerAddCondition(t1, Filter(function ISS_Add_Stack))
call TriggerAddCondition(t2, Filter(function ISS_Remove_Stack))
loop
exitwhen index == bj_MAX_PLAYER_SLOTS
set p = Player(index)
call TriggerRegisterPlayerUnitEvent(t1, p, EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
call TriggerRegisterPlayerUnitEvent(t2, p, EVENT_PLAYER_UNIT_DROP_ITEM, null)
set index = index + 1
endloop
set udg_ISS_Trigger_Create_Set = CreateTrigger()
call TriggerAddCondition(udg_ISS_Trigger_Create_Set, Filter(function ISS_Create_Set))
call TriggerAddAction(udg_ISS_Trigger_Create_Set, function ISS_Create_Set)
endfunction
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// End of the gg_trg_ISS_System trigger.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////