• 🏆 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!

[Trigger] Ignoring Mana Shield

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
So when an unit is attacked or recieves damage I want to check if the attacked unit has Mana Shield on AND attacking unit is behind the attacked unit, if the attacking unit is behind the attacked unit, then what can I do for the damage to ignore mana shield and damage directly to life?

I have this trigger:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Picked unit) has buff Mana Shield) Equal to True
      • ((Facing of (Triggering unit)) + 120.00) Greater than or equal to (Facing of (Picked unit))
      • ((Facing of (Triggering unit)) - 120.00) Less than or equal to (Facing of (Picked unit))
    • Then - Actions
      • Unit - Cause (Triggering unit) to damage (Picked unit), dealing 100.00 damage of attack type Normal and damage type Normal
    • Else - Actions
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Your angle logic might have issues due to the circular nature of angles.

For damage you modify the unit's life. The damage has already been computed by the DDS so you use that to modify the health directly, possibly refunding the mana in the process. If the damage will be fatal, you then remove Mana Shield and deal damage which will be fatal.
 
Level 11
Joined
Oct 9, 2015
Messages
721
I already did the "Set unit life to: (life of unit - damage)" before, however I was looking for a solution that works with attack types, because I want to use the native attack type x armor type balance, is there any ways to do that ? btw thanks for the fast reply, it don't took so long for someone to answer :)
 
Level 11
Joined
Oct 9, 2015
Messages
721
I may have found a solution or a workaround for it, plus without having to use an damage detection system:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Picked unit) has buff Mana Shield ) Equal to True
      • ((Facing of (Triggering unit)) + 120.00) Greater than or equal to (Facing of (Picked unit))
      • ((Facing of (Triggering unit)) - 120.00) Less than or equal to (Facing of (Picked unit))
    • Then - Actions
      • Set unitmana[(Player number of (Owner of (Picked unit)))] = (Mana of (Picked unit))
      • Unit - Set mana of (Picked unit) to 0.00
      • Unit - Cause (Triggering unit) to damage (Picked unit), dealing 10.00 damage of attack type Normal and damage type Normal
      • Unit - Set mana of (Picked unit) to unitmana[(Player number of (Owner of (Picked unit)))]
      • Unit - Order (Picked unit) to Neutral Naga Sea Witch - Activate Mana Shield
    • Else - Actions
I think this may work, what you guys think ?
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
If triggering unit is facing <120 degrees (0 degrees is to the right) then the logic will break because facing of picked unit will only ever return positive angles.

You are also not detecting the position of the unit. Only its facing which is wrong? It is possible it could be facing the wrong way for some reason but still be behind.

Use the symmetrical properties of sine or cosine to get around this. This has been demonstrated in many threads in the past. You get the deviance angle from the angle you want to find and then put it through cosine. Due to how cosine works you can compare this against the cosine of the maximum deviation you want in order to get a range of angles for which the condition is true. This will work independent of what the deviance angle value is, since cosine is infinitely repeating and defined for all standard input values.

For example... Get angle of caster to victim, subtract it by the facing of the victim and shove it through cosine. If this value is less or equal to cosine (180 - 120 = 60) then it is behind the unit +/- 120 degrees.
 
Level 11
Joined
Oct 9, 2015
Messages
721
I've set to 120 so it also covers the flanks, did I did it right? I also have another function to check if the attacking unit is facing properly:

  • (Acos((Cos(((Facing of (Triggering unit)) - (Angle from Loc1 to Loc2)))))) Less than or equal to 50.00
I did it wrong or right?

ps: thanks for the fast answers, you guys are awesome!
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
is there a better way to do what I did?
The way I described. One uses inequalities on the value of cosine. The inequalities are satisfied by a range of angles that repeat every 360 degrees. As such the comparison is defined for any angle input. It is basically what you did, except avoiding the Acos function by instead using cosine on the desired angle range.

In your case it would look something like...
  • (Cos(((Facing of (Triggering unit)) - (Angle from Loc1 to Loc2)))) Greater than or equal to (Cos(50.00))
This would be true if the other point is within +/- 50 degrees facing of the unit.

Another approach is to modulus the angle difference to be within a certain range, eg -180 to +180 or 0 to 360. Since the modulus would be defined for all input angles it is safe. You can then do your standard angular comparisons on the values avoiding the need for cosine altogether.

Which approach is faster (better?) I do not know. I am guessing the cosine approach is because JASS lacks native modulus support, instead relying on emulating a modulus for reals. The cosine execution time is trivial compared with the JASS execution overhead for simulated modulus.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
  • Mana Shield Fix
    • Events
      • Game - DamageModifierEvent becomes Equal to 4.00
    • Conditions
      • (DamageEventTarget has buff Mana Shield) Equal to True
    • Actions
      • -------- Mana Shield handling. For it to work, you need to set the mana shield Damage Absorbed % --------
      • -------- to 0.00 for Mana Shield (Neutral Hostile) and for all 3 levels of Mana Shield for the Naga Sea Witch. --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any conditions are True
            • IsDamageSpell Equal to True
            • Abs((Facing of DamageEventTarget) - (Facing of DamageEventSource)) Greater than 90.00
        • Then - Actions
          • -------- --------
          • Set DmgEvMana = (Mana of DamageEventTarget)
          • -------- Get the shielding mana multiplier from the target unit based on the unit or hero ability (&quot;multiplier&quot; mana per HP) --------
          • -------- If you have custom mana shield abilities or have modified the normal ones, add or configure those here. --------
          • Set DmgEvMSlvl = (Level of Mana Shield for DamageEventTarget)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • DmgEvMSlvl Equal to 0
            • Then - Actions
              • Set DmgEvManaMult = 2.00
            • Else - Actions
              • Set DmgEvManaMult = ((0.50 x (Real(DmgEvMSlvl))) + 0.50)
          • Set DmgEvMana = (DmgEvMana x DmgEvManaMult)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • DamageEventAmount Less than (DmgEvMana - 0.01)
            • Then - Actions
              • Set DmgEvMana = (DmgEvMana - DamageEventAmount)
              • Set DamageEventAmount = 0.00
              • Set DmgEvMana = (DmgEvMana / DmgEvManaMult)
              • -------- You can remove this damage type change if you want, it's mostly for the purpose of the test map. --------
              • Set DamageEventType = DamageTypeBlocked
            • Else - Actions
              • Set DamageEventAmount = (DamageEventAmount - DmgEvMana)
              • Set DmgEvMana = 0.00
              • Unit - Order DamageEventTarget to Neutral Naga Sea Witch - Deactivate Mana Shield
              • -------- You can remove this damage type change if you want, it's mostly for the purpose of the test map. --------
              • Set DamageEventType = DamageTypeReduced
          • Unit - Set mana of DamageEventTarget to DmgEvMana
        • Else - Actions
          • -------- Attack is a "backstab". Do not reduce damage --------
 
Status
Not open for further replies.
Top