Hello
Is it possible to return a node from a linked list? I am storing all the custom item data for my rpg in a linked list:
As you can tell, there are a lot of variables in my systems, and I am looking for a way to extract them and use them in my hero system. I have found a way to do it, but it requires textmacros inside it, for each item type, and i cant nest textmacros, such that i could make it for each stat. So i was wondering if i could just make a function that returns the entire node, and i can access it that way?
Somethin like:
And then to go through all the item types, just to make it access all items:
And then accessing it somehow, like:
But now my map wont start. I am afraid that I am doing something "illegal" by JASS or object oriented programming syntax lol
Is it possible to return a node from a linked list? I am storing all the custom item data for my rpg in a linked list:
JASS:
struct itemDataNode
//required
integer itemCode
string name
string icon
string model
string modelLocation
integer weight
//stats
real Armor
real Life
real Mana
real AttackSpeed
real MovementSpeed
real PhysicalDamageModifier
real PhysicalCritBonus
real PhysicalCritChance
real MeleeStunChance
real SpellDamageModifier
real SpellCritBonus
real SpellCritChance
real HealModifier
real HealCritBonus
real HealCritChance
real BlockChance
real ParryChance
real DodgeChance
thistype last
endstruct
struct itemData
itemDataNode last
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
set .last = 0
return this
endmethod
//call itemType.add(itemCode, name, icon, model, modelLocation, weight)
method add takes integer itemCode, string name, string icon, string model, string modelLocation, integer weight returns nothing
local itemDataNode k = itemDataNode.create()
//find the last item
if .last == 0 then
set .last = k
set k.last = 0
else
set k.last = this.last
set .last = k
endif
//
set k.itemCode = itemCode
set k.name = name
set k.icon = icon
set k.model = model
set k.modelLocation = modelLocation
set k.weight = weight
endmethod
//call itemType.addStats(itemCode, firstStat, firstValue, secondStat, secondValue, thirdStat, thirdValue)
method addStatsToItem takes integer itemCode, string firstStat, real firstValue, string secondStat, real secondValue, string thirdStat, real thirdValue returns nothing
local itemDataNode k = .last
loop
exitwhen (k.last == 0 or k.itemCode == itemCode)
set k = k.last
endloop
if k.itemCode == itemCode then
//fix item stats
//! textmacro addStatsToItem takes CASE
if ($CASE$Stat == "Armor") then
set k.Armor = $CASE$Value
elseif ($CASE$Stat == "Life") then
set k.Life = $CASE$Value
elseif ($CASE$Stat == "Mana") then
set k.Mana = $CASE$Value
elseif ($CASE$Stat == "AttackSpeed") then
set k.AttackSpeed = $CASE$Value
elseif ($CASE$Stat == "MovementSpeed") then
set k.MovementSpeed = $CASE$Value
elseif ($CASE$Stat == "PhysicalDamageModifier") then
set k.PhysicalDamageModifier = $CASE$Value
elseif ($CASE$Stat == "PhysicalCritBonus") then
set k.PhysicalCritBonus = $CASE$Value
elseif ($CASE$Stat == "PhysicalCritChance") then
set k.PhysicalCritChance = $CASE$Value
elseif ($CASE$Stat == "MeleeStunChance") then
set k.MeleeStunChance = $CASE$Value
elseif ($CASE$Stat == "SpellDamageModifier") then
set k.SpellDamageModifier = $CASE$Value
elseif ($CASE$Stat == "SpellCritBonus") then
set k.SpellCritBonus = $CASE$Value
elseif ($CASE$Stat == "SpellCritChance") then
set k.SpellCritChance = $CASE$Value
elseif ($CASE$Stat == "HealModifier") then
set k.HealModifier = $CASE$Value
elseif ($CASE$Stat == "HealCritBonus") then
set k.HealCritBonus = $CASE$Value
elseif ($CASE$Stat == "HealCritChance") then
set k.HealCritChance = $CASE$Value
elseif ($CASE$Stat == "BlockChance") then
set k.BlockChance = $CASE$Value
elseif ($CASE$Stat == "ParryChance") then
set k.ParryChance = $CASE$Value
elseif ($CASE$Stat == "DodgeChance") then
set k.DodgeChance = $CASE$Value
endif
//! endtextmacro
//! runtextmacro addStatsToItem("first")
//! runtextmacro addStatsToItem("second")
//! runtextmacro addStatsToItem("third")
call MessageAll("Successfully adding stats!")
else
call MessageAll("Error adding stats to "+I2S(itemCode))
endif
endmethod
As you can tell, there are a lot of variables in my systems, and I am looking for a way to extract them and use them in my hero system. I have found a way to do it, but it requires textmacros inside it, for each item type, and i cant nest textmacros, such that i could make it for each stat. So i was wondering if i could just make a function that returns the entire node, and i can access it that way?
Somethin like:
JASS:
method getItemDataNode takes integer itemCode returns itemDataNode
local itemDataNode k = .last
loop
exitwhen (k.last == 0 or k.itemCode == itemCode)
set k = k.last
endloop
if k.itemCode == itemCode then
return k
else
return null
endmethod
And then to go through all the item types, just to make it access all items:
JASS:
function getItemNodeAll takes integer itemCode returns itemDataNode
local itemDataNode result
//! textmacro itemNodeAll takes ITEMTYPE
if (result == null) then
set result = $ITEMTYPE$.getItemDataNode(itemCode)
else
return result
endif
//! endtextmacro
//! runtextmacro itemNodeAll("OneHandSlashing")
//! runtextmacro itemNodeAll("OneHandPiercing")
//! runtextmacro itemNodeAll("OneHandBlunt")
//! runtextmacro itemNodeAll("TwoHandSlashing")
//! runtextmacro itemNodeAll("TwoHandPiercing")
//! runtextmacro itemNodeAll("TwoHandBlunt")
//! runtextmacro itemNodeAll("Bow")
//! runtextmacro itemNodeAll("Staff")
//! runtextmacro itemNodeAll("OneHandMisc")
//! runtextmacro itemNodeAll("Shield")
//! runtextmacro itemNodeAll("ClothHead")
//! runtextmacro itemNodeAll("ClothChest")
//! runtextmacro itemNodeAll("ClothLegs")
//! runtextmacro itemNodeAll("ClothFeet")
//! runtextmacro itemNodeAll("ClothHands")
//! runtextmacro itemNodeAll("LeatherHead")
//! runtextmacro itemNodeAll("LeatherChest")
//! runtextmacro itemNodeAll("LeatherLegs")
//! runtextmacro itemNodeAll("LeatherFeet")
//! runtextmacro itemNodeAll("LeatherHands")
//! runtextmacro itemNodeAll("ChainHead")
//! runtextmacro itemNodeAll("ChainChest")
//! runtextmacro itemNodeAll("ChainLegs")
//! runtextmacro itemNodeAll("ChainFeet")
//! runtextmacro itemNodeAll("ChainHands")
//! runtextmacro itemNodeAll("PlateHead")
//! runtextmacro itemNodeAll("PlateChest")
//! runtextmacro itemNodeAll("PlateLegs")
//! runtextmacro itemNodeAll("PlateFeet")
//! runtextmacro itemNodeAll("PlateHands")
//! runtextmacro itemNodeAll("Ring")
//! runtextmacro itemNodeAll("Amulet")
return result
endfunction
And then accessing it somehow, like:
JASS:
//part of my hero data structs
method equipItem takes integer itemCode returns nothing
local itemDataNode tempItemData = getItemNodeAll('I00B')
call MessageAll("Armor of item: "+R2S(tempItemData.Armor))
endmethod
But now my map wont start. I am afraid that I am doing something "illegal" by JASS or object oriented programming syntax lol