Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using OpenRA.Traits;
  3.  
  4. namespace OpenRA.Mods.RA
  5. {
  6.     public class UnitStanceReturnFireInfo : ITraitInfo
  7.     {
  8.         public readonly bool Default = false;
  9.  
  10.         public object Create(ActorInitializer init) { return new UnitStanceReturnFire(init.self, this); }
  11.     }
  12.  
  13.     public class UnitStanceReturnFire : UnitStance, INotifyDamage
  14.     {
  15.         public readonly UnitStanceReturnFireInfo Info;
  16.  
  17.         public UnitStanceReturnFire(Actor self, UnitStanceReturnFireInfo info)
  18.         {
  19.             Info = info;
  20.             Active = Info.Default;
  21.         }
  22.  
  23.         public virtual void Damaged(Actor self, AttackInfo e)
  24.         {
  25.             if (!Active) return;
  26.             if (!self.IsIdle) return;
  27.             if (e.Attacker.Destroyed) return;
  28.  
  29.             var attack = self.TraitOrDefault<AttackBase>();
  30.  
  31.             // this unit cannot fight back at all (no guns)
  32.             if (attack == null) return;
  33.  
  34.             // don't fight back if we dont have the guns to do so
  35.             if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return;
  36.  
  37.             // don't retaliate against allies
  38.             if (self.Owner.Stances[e.Attacker.Owner] == Stance.Ally) return;
  39.  
  40.             // don't retaliate against healers
  41.             if (e.Damage < 0) return;  
  42.  
  43.             // perform the attack, the 'true' makes sure it sends out the Attack order
  44.             self.Trait<AttackBase>().AttackTarget(self, e.Attacker, true);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement