Calc for Equipment based on shards

So I'm looking to make some armor (and probably some weapons later, too)  that gets better based on the number of Elemental Shards you own. However, I don't see a way to make the calculation based on that criteria.  For example, in a spell, you have something like:

Code: xml
  1. <Calculate InternalName="Calc" ValueOwner="CastingUnit">
  2.      <Expression <! [CDATA[[UnitOwner_GetNumFireShards] * 2]]></Expression>

Other values I see as appropriate for ValueOwner are "Target Unit","OwnerCity","TargetCity", and "Player_#"

None of which seems to be applicable for what I need.  I would need something like "EquippedUnit" but can't find an example of such a hook value.

Any ideas or help here?

8,388 views 11 replies
Reply #1 Top

Use CastingUnit, it will do what you want.

Reply #2 Top

Quoting Heavenfall, reply 1
Use CastingUnit, it will do what you want.
End of Heavenfall's quote

Nice - seems like someone got a little lazy with their semantics! ;)

It would probably better serve to be called something else - though to be fair a more generic catch all term escapes me at the moment so I might have just left if I was in the same situation too! :)

Reply #3 Top


magic equipped

item user

shard item

shard user

 

Reply #4 Top

Quoting Heavenfall, reply 1
Use CastingUnit, it will do what you want.
End of Heavenfall's quote

After several attempts on both armor and weapons, this is incorrect. I've added something like this to a weapon

Code: xml
  1. <GameModifier>                
  2.     <ModType>Unit</ModType>                
  3.     <Attribute>AdjustUnitStat</Attribute>                
  4.     <StrVal>UnitStat_Attack_Lightning</StrVal>                
  5.     <Calculate InternalName="Value" ValueOwner="CastingUnit">        
  6.         <Expression><![CDATA[UnitOwner_GetNumAirShards]]></Expression>     
  7.     </Calculate>
  8.     <Provides>+1 Lightning Attack per Air Shard</Provides>
  9. </GameModifier>

This will not add +1 Lightning attack to the unit.  I suppose I'd have to do a MeleeAppliesSpell and create a custom effect.  I'll try that.

Reply #5 Top

Ah, I assumed you were already doing it from inside a spelldef. That is the only place where calculations like this work (and some improvements).

Reply #6 Top

Quoting Heavenfall, reply 6
Ah, I assumed you were already doing it from inside a spelldef. That is the only place where calculations like this work (and some improvements).
End of Heavenfall's quote

 

the problem with having it in a spell def is you can't use the calculations based on simply equipping the item.  For example, if you want to give 10 Fire Resitance on an item for every Fire Shard, you are SOL, as far as I can tell

 

I hope Stardock could consider letting something either hook on to equipping or allow for calcs the way I tried.  Would make things a lot easier.

Reply #7 Top

Unlikely, because it's likely a memory and cpu issue. Consider all the various checks that they have in place to make sure that everything on a unit is up to date. Every modifier needs to be constantly checked. There are likely over a million gameodifiers active in each game. To introduce a new rule that they have to check for calculation (and possible changes) from equipment modifiers could have vast performance consequences.

What you can do is have the item give a modifier that is battleautocastspell trigger. Then equipping the item means the unit will autocast a spell on itself at start of combat. The calculation would be run then, and since shards never change once battle has commenced it would work. Of course, it is far from ideal because it means it won't show up on unit details until you're in battle, which also impacts things like combat rating and AI evaluation.

Reply #8 Top

Even with moving this to a spell def, things are very odd with the Calc.  Consider the below:

Code: xml
  1.     <SpellDef InternalName="FireShard1_Effect">
  2.         <DisplayName>Fire Damage Shard</DisplayName>
  3.         <Description>Does %d Fire Damage</Description>
  4.         <Image>T_Slow_Painting.png</Image> <!-- Fix this -->
  5.         <IconFG>T_Slow_Icon.png</IconFG><!-- Fix this -->
  6.         <IconBG>T_Slow_Icon_BG.png</IconBG><!-- Fix this -->
  7.         <IconColor>139,243,255</IconColor><!-- Fix this -->
  8.         <CanStack>1</CanStack>
  9.         <SpellBookSortCategory>Unit</SpellBookSortCategory>
  10.         <SpellBookSortSubCategory>UnitDamage</SpellBookSortSubCategory>
  11.         <SpellType>Tactical</SpellType>
  12.         <SpellClass>Offensive</SpellClass>
  13.         <SpellSubClass>Damage</SpellSubClass>
  14.         <SpellTargetType>EnemyUnit</SpellTargetType>
  15.         <HideInHiergamenon>1</HideInHiergamenon>
  16.         <IsCastable>0</IsCastable>
  17.         <GameModifier>
  18.             <ModType>Unit</ModType>
  19.             <Attribute>DefendableDamage</Attribute>
  20.             <AttackStat>UnitStat_Attack_Fire</AttackStat>
  21.             <Calculate InternalName="Calc" ValueOwner="CastingUnit">
  22.                 <Expression><![CDATA[UnitOwner_GetNumFireShards]]></Expression>
  23.             </Calculate>
  24.             <Calculate InternalName="Value">
  25.                 <Expression><![[CDATA[Calc] * 6]]></Expression>
  26.             </Calculate>
  27.         </GameModifier>
  28.         <GameModifier>
  29.             <ModType>Unit</ModType>
  30.             <Attribute>DefendableDamage</Attribute>
  31.             <AttackStat>UnitStat_Attack_Cold</AttackStat>
  32.             <Calculate InternalName="Calc" ValueOwner="CastingUnit">
  33.                 <Expression><![CDATA[UnitOwner_GetNumWaterShards]]></Expression>
  34.             </Calculate>
  35.             <Calculate InternalName="Value">
  36.                 <Expression><![[CDATA[Calc] * 6]]></Expression>
  37.             </Calculate>
  38.         </GameModifier>
  39.         <AIData AIPersonality="AI_General">
  40.             <AIPriority>5</AIPriority>
  41.         </AIData>
  42.         <HitSoundFX>Spell_Barbs_01</HitSoundFX>
  43.     </SpellDef>

This effect, when placed on a weapon, should look at the number of shards and deal Fire Damage equal to 6x the number of fire shards and Cold Damage equal to 6x the water shards. It's a ridiculous effect, I know - I added the multiplier to see what was going on. According to the details, this effect was doing 3-6 damage per hit on pretty much any enemy when I had access to 5 fire and 5 water shards shards.  it was doing basically nothing without the *6.  I put the effect on short sword. 

I'm not 100% sure about the underlying mechanics of the damage done to enemies with defendable fire damage, but I would think have 60 damage on the spell shouldn't get reduced to 6. 

Really wish I could get this to work because <perLevel> is a ridiculous effect and I feel the shards are seriously underrepresented in the game

Reply #9 Top

That calculation tag looks really wrong, you need to count the [ and ]s and get it right.

<Expression><![CDATA[UnitOwner_GetNumWaterShards]]></Expression>

ought to be

<Expression><![CDATA[[UnitOwner_GetNumWaterShards]]]></Expression>

same every other place. Look at how it's done in CoreSpells.xml

 


Reply #10 Top

Man - I can't believe I missed that.  I must be getting old (heh - or in the case of XML, new).  I'll get that fixed up tonight. 

 

Reply #11 Top

OK - So I've gone ahead and did all the leg work and something is just not quite right. So lets say instead of the Burning Axe doing 9 cutting damage and 2 fire damage, you want it to do 9 cutting, 1 fire, and a further 1 fire damage for each Fire Shard you control.  here is the XML I used

Burning Axe Changes (i've marked the only change other than the stat change from 2 to 1 on the fire bit)

Code: xml
  1. &lt;GameItemType InternalName="Axe_Burning"&gt;
  2.         &lt;DisplayName&gt;Burning Axe&lt;/DisplayName&gt;
  3.         &lt;Description&gt;This axe smoulders with an internal fire, but when its handle is gripped the blade bursts into flame.&lt;/Description&gt;
  4.         &lt;Type&gt;Weapon&lt;/Type&gt;
  5.         &lt;WeaponType&gt;Blunt&lt;/WeaponType&gt;
  6.         &lt;CanBeEquipped&gt;1&lt;/CanBeEquipped&gt;
  7.         &lt;AdditionalTrainingTurns&gt;12&lt;/AdditionalTrainingTurns&gt;
  8.         &lt;ShopValue&gt;150&lt;/ShopValue&gt;
  9.         &lt;ProductionRequirement&gt;
  10.             &lt;Type&gt;Resource&lt;/Type&gt;
  11.             &lt;Attribute&gt;RefinedCrystal&lt;/Attribute&gt;
  12.             &lt;Value&gt;3&lt;/Value&gt;
  13.         &lt;/ProductionRequirement&gt;
  14.         &lt;GameModifier&gt;
  15.             &lt;ModType&gt;Unit&lt;/ModType&gt;
  16.             &lt;Attribute&gt;AdjustUnitStat&lt;/Attribute&gt;
  17.             &lt;StrVal&gt;UnitStat_Attack_Cutting&lt;/StrVal&gt;
  18.             &lt;Value&gt;9&lt;/Value&gt;
  19.         &lt;/GameModifier&gt;
  20.         &lt;GameModifier&gt;
  21.             &lt;ModType&gt;Unit&lt;/ModType&gt;
  22.             &lt;Attribute&gt;AdjustUnitStat&lt;/Attribute&gt;
  23.             &lt;StrVal&gt;UnitStat_CombatSpeed&lt;/StrVal&gt;
  24.             &lt;Value&gt;-2&lt;/Value&gt;
  25.         &lt;/GameModifier&gt;
  26.         &lt;GameModifier&gt;
  27.             &lt;ModType&gt;Unit&lt;/ModType&gt;
  28.             &lt;Attribute&gt;AdjustUnitStat&lt;/Attribute&gt;
  29.             &lt;StrVal&gt;UnitStat_CurrentWeight&lt;/StrVal&gt;
  30.             &lt;Value&gt;10&lt;/Value&gt;
  31.         &lt;/GameModifier&gt;
  32.    &lt;GameModifier&gt;
  33.              &lt;ModType&gt;Unit&lt;/ModType&gt;
  34.              &lt;Attribute&gt;AdjustUnitStat&lt;/Attribute&gt;
  35.              &lt;StrVal&gt;UnitStat_Attack_Fire&lt;/StrVal&gt;
  36.              &lt;Value&gt;1&lt;/Value&gt;
  37.          &lt;/GameModifier&gt;
  38. &lt;!-- IMPORTANT PART HERE --&gt;
  39.    &lt;GameModifier&gt;
  40.                 &lt;ModType&gt;Unit&lt;/ModType&gt;
  41.                 &lt;Attribute&gt;MeleeAppliesSpell&lt;/Attribute&gt;
  42.                 &lt;StrVal&gt;FireShard1_Effect&lt;/StrVal&gt;
  43.                 &lt;Provides&gt;Fire Damage equal to the number of Fire Shards you control&lt;/Provides&gt;
  44.    &lt;/GameModifier&gt;
  45. &lt;!-- END IMPORTANT PART --&gt;
  46.              &lt;GameModifier&gt;
  47.                 &lt;ModType&gt;Unit&lt;/ModType&gt;
  48.                 &lt;Attribute&gt;AdjustUnitStat&lt;/Attribute&gt;
  49.                 &lt;StrVal&gt;UnitStat_BackswingChance&lt;/StrVal&gt;
  50.                 &lt;Value&gt;100&lt;/Value&gt;
  51.                  &lt;Provides&gt;Backswing- If the attack misses the unit gets a second attack against the same target&lt;/Provides&gt;
  52.             &lt;/GameModifier&gt;
  53.         &lt;IsAvailableForSovereignCustomization&gt;0&lt;/IsAvailableForSovereignCustomization&gt;
  54.         &lt;Likelihood&gt;400&lt;/Likelihood&gt;
  55.         &lt;RarityDisplay&gt;Common&lt;/RarityDisplay&gt;
  56.         &lt;Prereq&gt;
  57.             &lt;Type&gt;Tech&lt;/Type&gt;
  58.             &lt;Attribute&gt;Enchantment&lt;/Attribute&gt;
  59.         &lt;/Prereq&gt;
  60.         &lt;AIData AIPersonality="AI_General"&gt;
  61.             &lt;AIPrefType&gt;AIPrefType_CUTTING&lt;/AIPrefType&gt;
  62.             &lt;AIPriority&gt;200&lt;/AIPriority&gt;
  63.         &lt;/AIData&gt;
  64.         &lt;ArtDef&gt;Axe_Burning_ArtDef&lt;/ArtDef&gt;
  65.         &lt;GameItemTypeArtDef InternalName="Axe_Burning_ArtDef"&gt;
  66.             &lt;GameItemTypeModelPack InternalName="Axe_Burning_Default"&gt;
  67.                 &lt;IconFile&gt;W_Axe_Burning_Icon_01.png&lt;/IconFile&gt;
  68.                 &lt;TintR&gt;0&lt;/TintR&gt;
  69.                 &lt;TintG&gt;0&lt;/TintG&gt;
  70.                 &lt;TintB&gt;0&lt;/TintB&gt;
  71.                 &lt;AttackSFX&gt;Hit_Hammer1&lt;/AttackSFX&gt;
  72.                 &lt;AttackSFX&gt;Hit_Hammer2&lt;/AttackSFX&gt;
  73.                 &lt;AttackSFX&gt;Hit_Hammer3&lt;/AttackSFX&gt;
  74.                 &lt;EquipSFX&gt;Equip_WoodenItem_01&lt;/EquipSFX&gt;
  75.                 &lt;EquipSFX&gt;Equip_WoodenItem_02&lt;/EquipSFX&gt;
  76.                 &lt;EquipSFX&gt;Equip_WoodenItem_03&lt;/EquipSFX&gt;
  77.                 &lt;OnHitParticleName&gt;Hit_Fire1&lt;/OnHitParticleName&gt;
  78.                 &lt;GameItemTypeModel&gt;
  79.                     &lt;ModelFile&gt;gfx/hkb/Weapons/W_Axe_Burning_01.hkb&lt;/ModelFile&gt;
  80.                     &lt;Texture_All&gt;gfx/hkb/Weapons/FE_Weapons_01.png&lt;/Texture_All&gt;
  81.                     &lt;Attachment&gt;hand_right_Lcf&lt;/Attachment&gt;
  82.                     &lt;Color_Metal&gt;90,87,87&lt;/Color_Metal&gt;
  83.                             &lt;EffectAttachment&gt;
  84.                                 &lt;Attachment&gt;Effect_Loc_01&lt;/Attachment&gt;
  85.                                 &lt;EffectName&gt;A_BurningAxe_Particle&lt;/EffectName&gt;
  86.                                 &lt;EffectPosition&gt;6,0,0&lt;/EffectPosition&gt;
  87.                                 &lt;EffectRotation&gt;0,0,0&lt;/EffectRotation&gt;
  88.                                 &lt;EffectScale&gt;0.25&lt;/EffectScale&gt;
  89.                             &lt;/EffectAttachment&gt;
  90.                   &lt;/GameItemTypeModel&gt;
  91.               &lt;/GameItemTypeModelPack&gt;
  92.         &lt;/GameItemTypeArtDef&gt;
  93.  &lt;/GameItemType&gt;

 

and here is the code for FireShard1_Effect

Code: xml
  1. &lt;SpellDef InternalName="FireShard1_Effect"&gt;
  2.         &lt;DisplayName&gt;Fire Shard Damage&lt;/DisplayName&gt;
  3.         &lt;Description&gt;Does 1 Fire Damage per Fire Shard&lt;/Description&gt;
  4.         &lt;SpellBookSortCategory&gt;Unit&lt;/SpellBookSortCategory&gt;
  5.         &lt;SpellBookSortSubCategory&gt;UnitDamage&lt;/SpellBookSortSubCategory&gt;
  6.         &lt;SpellType&gt;Tactical&lt;/SpellType&gt;
  7.         &lt;SpellClass&gt;Offensive&lt;/SpellClass&gt;
  8.         &lt;SpellSubClass&gt;Damage&lt;/SpellSubClass&gt;
  9.         &lt;SpellTargetType&gt;EnemyUnit&lt;/SpellTargetType&gt;
  10.         &lt;HideInHiergamenon&gt;1&lt;/HideInHiergamenon&gt;
  11.         &lt;IsCastable&gt;0&lt;/IsCastable&gt;
  12.         &lt;GameModifier&gt;
  13.             &lt;ModType&gt;Unit&lt;/ModType&gt;
  14.             &lt;Attribute&gt;DefendableDamage&lt;/Attribute&gt;
  15.             &lt;AttackStat&gt;UnitStat_Attack_Fire&lt;/AttackStat&gt;
  16.             &lt;Calculate InternalName="Calc" ValueOwner="CastingUnit"&gt;
  17.                 &lt;Expression&gt;&lt;![CDATA[[UnitOwner_GetNumFireShards]]]&gt;&lt;/Expression&gt;
  18.             &lt;/Calculate&gt;
  19.             &lt;Calculate InternalName="Value"&gt;
  20.                 &lt;Expression&gt;&lt;![CDATA[[Calc]]]&gt;&lt;/Expression&gt;
  21.             &lt;/Calculate&gt;
  22.         &lt;/GameModifier&gt;
  23.         &lt;AIData AIPersonality="AI_General"&gt;
  24.             &lt;AIPriority&gt;5&lt;/AIPriority&gt;
  25.         &lt;/AIData&gt;
  26.         &lt;HitSoundFX&gt;Spell_Barbs_01&lt;/HitSoundFX&gt;
  27.     &lt;/SpellDef&gt;

And here is the result when I have ZERO fire shards:

http://www.classicquarter.com/HUH_FE_AXE.jpg

Which as you can see, is NOT what you'd expect.  Should be the 9 cutting damage, 1 fire damage with NO chance of fire shard damage as a result of the spell def.

Any help here would be hot