Example #1
0
        public void Damaged(Actor self, AttackInfo e)
        {
            if (e.Attacker == null)
                return;

            if (e.Attacker.Owner == self.Owner)
                return;

            if (e.Attacker == self.World.WorldActor)
                return;

            // Only track last hit against our base
            if (!self.Info.HasTraitInfo<BuildingInfo>())
                return;

            if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage <= 0)
                return;

            if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)
            {
                var rules = self.World.Map.Rules;
                Game.Sound.PlayNotification(rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);

                if (info.AllyNotification != null)
                    foreach (Player p in self.World.Players)
                        if (p != self.Owner && p.IsAlliedWith(self.Owner) && p != e.Attacker.Owner)
                            Game.Sound.PlayNotification(rules, p, "Speech", info.AllyNotification, p.Faction.InternalName);

                if (radarPings != null)
                    radarPings.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
            }

            lastAttackTime = self.World.WorldTick;
        }
Example #2
0
 public virtual void DamageStateChanged(Actor self, AttackInfo e)
 {
     if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
         anim.ReplaceAnim("damaged-idle");
     else if (e.DamageState < DamageState.Heavy)
         anim.ReplaceAnim("idle");
 }
Example #3
0
        public override void Damaged(Actor self, AttackInfo e)
        {
            var oldState = GetExtendedState(self, e.Damage);
            var newState = GetExtendedState(self, 0);

            if (oldState == newState) return;

            switch (newState)
            {
                case ExtendedDamageState.Normal:
                    seqName = "idle";
                    break;
                case ExtendedDamageState.ThreeQuarter:
                    if (damageStates >= 4)
                        seqName = "minor-damaged-idle";
                    break;
                case ExtendedDamageState.Half:
                    seqName = "damaged-idle";
                    Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound);
                    break;
                case ExtendedDamageState.Quarter:
                    if (damageStates >= 3)
                    {
                        seqName = "critical-idle";
                        Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound);
                    }
                    break;
            }
        }
Example #4
0
        public void Killed(Actor self, AttackInfo e)
        {
            self.World.AddFrameEndTask(w =>
            {
                var td = new TypeDictionary()
                {
                    new LocationInit( self.Location ),
                    new CenterLocationInit(self.CenterLocation),
                    new OwnerInit( self.Owner ),
                    new SkipMakeAnimsInit()
                };

                // Allows the husk to drag to its final position
                var mobile = self.TraitOrDefault<Mobile>();
                if (mobile != null)
                {
                    if (!mobile.CanEnterCell(self.Location, self, false)) return;
                    td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location)));
                }

                var facing = self.TraitOrDefault<IFacing>();
                if (facing != null)
                    td.Add(new FacingInit( facing.Facing ));

                var turreted = self.TraitOrDefault<Turreted>();
                if (turreted != null)
                    td.Add( new TurretFacingInit(turreted.turretFacing) );

                var huskActor = self.TraitsImplementing<IHuskModifier>()
                    .Select(ihm => ihm.HuskActor(self))
                    .FirstOrDefault(a => a != null);

                w.CreateActor(huskActor ?? Info.HuskActor, td);
            });
        }
Example #5
0
        public override void DamageStateChanged(Actor self, AttackInfo e)
        {
            if (lights.CurrentSequence != null)
                lights.ReplaceAnim(NormalizeSequence(self, "lights"));

            base.DamageStateChanged(self, e);
        }
Example #6
0
        public void Damaged(Actor self, AttackInfo e)
        {
            // only track last hit against our base
            if (!self.HasTrait<Building>())
                return;

            if (e.Attacker == null)
                return;

            if (e.Attacker.Owner == self.Owner)
                return;

            if (e.Attacker == self.World.WorldActor)
                return;

            if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage <= 0)
                return;

            if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)
            {
                Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Country.Race);

                if (radarPings != null)
                    radarPings.Add(() => self.Owner == self.World.LocalPlayer, self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
            }

            lastAttackTime = self.World.WorldTick;
        }
Example #7
0
 public void Killed(Actor self, AttackInfo e)
 {
     var bi = self.Info.Traits.Get<BuildingInfo>();
     FootprintUtils.UnpathableTiles(self.Info.Name, bi, self.Location).Do(
         t => self.World.AddFrameEndTask(
             w => w.Add(new Explosion(w, Traits.Util.CenterOfCell(t), "building", false, 0))));
 }
Example #8
0
        public void Damaged(Actor self, AttackInfo e)
        {
            // Damagestate
            if (e.DamageStateChanged)
            {
                if (e.DamageState >= DamageState.Critical)
                    lastDamage = "-critical";
                else if (e.DamageState >= DamageState.Heavy)
                    lastDamage = "-damaged";
                else if (e.DamageState < DamageState.Heavy)
                    lastDamage = "";
                anim.ReplaceAnim(lastDir+lastDamage);
            }

            // Smoking
            if (e.DamageState < DamageState.Heavy) return;
            if (isSmoking) return;

            isSmoking = true;
            var smoke = anims[ "smoke" ].Animation;
            smoke.PlayThen( "idle",
                () => smoke.PlayThen( "loop",
                    () => smoke.PlayBackwardsThen( "end",
                        () => isSmoking = false ) ) );
        }
Example #9
0
        public override void Damaged(Actor self, AttackInfo e)
        {
            if (!e.DamageStateChanged) return;

            var bi = self.Info.Traits.Get<BuildingInfo>();

            if (e.DamageState == DamageState.Medium && anim.HasSequence("scratched-idle"))
                seqName = "scratched-idle";
            else if (e.DamageState <= DamageState.Medium)
                seqName = "idle";
            else if (e.DamageState == DamageState.Critical && anim.HasSequence("critical-idle"))
            {
                seqName = "critical-idle";
                if (e.DamageState > e.PreviousDamageState)
                    Sound.Play(bi.DamagedSound, self.CenterLocation);
            }
            else if (e.DamageState <= DamageState.Critical)
            {
                seqName = "damaged-idle";
                if (e.DamageState > e.PreviousDamageState)
                    Sound.Play(bi.DamagedSound, self.CenterLocation);
            }

            anim.PlayFetchIndex(seqName, () => adjacentWalls);
        }
Example #10
0
 public void Killed(Actor self, AttackInfo e)
 {
     var player = (Info.NotifyAll) ? self.World.LocalPlayer : self.Owner;
     if (Info.Race != null && Info.Race != self.Owner.Country.Race)
         return;
     Sound.PlayToPlayer(player, Info.Notification);
 }
Example #11
0
        public void Damaged(Actor self, AttackInfo e)
        {
            if (!Active) return;
            if (!self.HasTrait<AttackBase>()) return;

            ReturnFire(self, e, false, false, true); // only triggers when standing still
        }
Example #12
0
 public void DamageStateChanged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
         Sound.Play(Info.DestroyedSound, self.CenterLocation);
     else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
         Sound.Play(Info.DamagedSound, self.CenterLocation);
 }
Example #13
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
     {
         DisableGps();
     }
 }
Example #14
0
        public void Killed(Actor self, AttackInfo e)
        {
            var warhead = e.Warhead as DamageWarhead;

            // If the warhead is null, the actor was killed by some non-standard means
            if (info.DeathTypes.Count == 0 || (warhead != null && warhead.DamageTypes.Overlaps(info.DeathTypes)))
                self.PlayVoiceLocal(info.Voice, info.VolumeMultiplier);
        }
Example #15
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
     {
         Sound.PlayVoice("Die", self);
         self.World.AddFrameEndTask(w => w.Add(new Corpse(self, e.Warhead.InfDeath)));
     }
 }
Example #16
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
     {
         self.World.WorldActor.traits.Get<ScreenShaker>().AddEffect(10, self.CenterLocation, 1);
         Sound.Play(Info.DestroyedSound);
     }
 }
Example #17
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
     {
         var player = (Info.NotifyAll) ? self.World.LocalPlayer : self.Owner;
         Sound.PlayToPlayer(player, Info.Notification);
     }
 }
Example #18
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
     {
         Granted = false;
         RefreshGps(self);
     }
 }
Example #19
0
        public override void Damaged(Actor self, AttackInfo e)
        {
            if (!e.DamageStateChanged) return;

            if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
                anim.ReplaceAnim("damaged-idle");
            else if (e.DamageState < DamageState.Heavy)
                anim.ReplaceAnim("idle");
        }
Example #20
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if( e.DamageStateChanged && e.DamageState == DamageState.Dead )
     {
         foreach( var c in cargo )
             c.Destroy();
         cargo.Clear();
     }
 }
Example #21
0
        public void Damaged(Actor self, AttackInfo e)
        {
            if (!Active) return;
            if (TargetType == ETargetType.None) return;
            if (IsReturning) return;
            if (!self.HasTrait<AttackBase>()) return;

            ReturnFire(self, e, false); // only triggers when standing still
        }
Example #22
0
        public void Killed(Actor self, AttackInfo e)
        {
            // Killed by some non-standard means
            if (e.Warhead == null)
                return;

            if (info.DeathTypes.Intersect(e.Warhead.DamageTypes).Any())
                self.PlayVoiceLocal(info.DeathSound, info.VolumeMultiplier);
        }
Example #23
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
     {
         CancelDock(self);
         foreach (var harv in GetLinkedHarvesters())
             harv.Trait.UnlinkProc(harv.Actor, self);
     }
 }
		public void Killed(Actor self, AttackInfo e)
		{
			if (self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location))
				return;

			foreach (var condition in self.TraitsImplementing<IPreventsEjectOnDeath>())
				if (condition.PreventsEjectOnDeath(self))
					return;

			var r = self.World.SharedRandom.Next(1, 100);

			if (r <= 100 - info.SuccessRate)
				return;

			var cp = self.CenterPosition;
			var inAir = !self.IsAtGroundLevel();
			if ((inAir && !info.EjectInAir) || (!inAir && !info.EjectOnGround))
				return;

			var ge = self.TraitOrDefault<GainsExperience>();
			if ((ge == null || ge.Level == 0) && info.SpawnOnlyWhenPromoted)
				return;

			var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
				new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });

			if (ge != null)
			{
				var pge = pilot.TraitOrDefault<GainsExperience>();
				if (pge != null)
				{
					pge.GiveLevels(ge.Level, true);
				}
			}

			if (info.AllowUnsuitableCell || IsSuitableCell(self, pilot))
			{
				if (inAir)
				{
					self.World.AddFrameEndTask(w =>
					{
						w.Add(pilot);
						pilot.QueueActivity(new Parachute(pilot, cp));
					});
					Game.Sound.Play(info.ChuteSound, cp);
				}
				else
				{
					self.World.AddFrameEndTask(w => w.Add(pilot));
					var pilotMobile = pilot.TraitOrDefault<Mobile>();
					if (pilotMobile != null)
						pilotMobile.Nudge(pilot, pilot, true);
				}
			}
			else
				pilot.Dispose();
		}
Example #25
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageState == DamageState.Dead)
     {
         var death = e.Warhead != null ? e.Warhead.InfDeath : 0;
         Sound.PlayVoice("Die", self, self.Owner.Country.Race);
         self.World.AddFrameEndTask(w => w.Add(new Corpse(self, death)));
     }
 }
Example #26
0
        public override void Damaged(Actor self, AttackInfo e)
        {
            if (!e.DamageStateChanged) return;

            if (e.DamageState >= DamageState.Heavy)
                roof.ReplaceAnim("damaged-" + roof.CurrentSequence.Name);
            else
                roof.ReplaceAnim(roof.CurrentSequence.Name.Replace("damaged-",""));
        }
Example #27
0
 public void Damaged(Actor self, AttackInfo e)
 {
     if (e.DamageStateChanged)
     {
         UpdateState();
         if (northNeighbour != null) northNeighbour.UpdateState();
         if (southNeighbour != null) southNeighbour.UpdateState();
     }
 }
Example #28
0
 public void DamageStateChanged(Actor self, AttackInfo e)
 {
     if (e.DamageState >= DamageState.Critical)
         lastDamage = "-critical";
     else if (e.DamageState >= DamageState.Heavy)
         lastDamage = "-damaged";
     else if (e.DamageState < DamageState.Heavy)
         lastDamage = "";
     anim.ReplaceAnim(lastDir+lastDamage);
 }
Example #29
0
        public void Damaged(Actor self, AttackInfo e)
        {
            if (e.Damage.Value <= 0 || !e.Damage.DamageTypes.Overlaps(info.DamageTriggers))
                return;

            if (!IsProne)
                localOffset = info.ProneOffset;

            remainingProneTime = info.ProneTime;
        }
Example #30
0
        public void Damaged(Actor self, AttackInfo e)
        {
            if (e.Damage <= 0 || e.Warhead == null || !e.Warhead.DamageTypes.Any(x => info.DamageTriggers.Contains(x)))
                return;

            if (!IsProne)
                localOffset = info.ProneOffset;

            remainingProneTime = info.ProneTime;
        }
Example #31
0
        public void InflictDamage(Actor self, Actor attacker, int damage, WarheadInfo warhead, bool ignoreModifiers)
        {
            if (IsDead)
            {
                return;                                 /* overkill! don't count extra hits as more kills! */
            }
            var oldState = this.DamageState;
            /* apply the damage modifiers, if we have any. */
            var modifier = self.TraitsImplementing <IDamageModifier>()
                           .Concat(self.Owner.PlayerActor.TraitsImplementing <IDamageModifier>())
                           .Select(t => t.GetDamageModifier(attacker, warhead)).Product();

            if (!ignoreModifiers)
            {
                damage = damage > 0 ? (int)(damage * modifier) : damage;
            }

            hp = Exts.Clamp(hp - damage, 0, MaxHP);

            var ai = new AttackInfo
            {
                Attacker            = attacker,
                Damage              = damage,
                DamageState         = this.DamageState,
                PreviousDamageState = oldState,
                Warhead             = warhead,
            };

            foreach (var nd in self.TraitsImplementing <INotifyDamage>()
                     .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyDamage>()))
            {
                nd.Damaged(self, ai);
            }

            if (DamageState != oldState)
            {
                foreach (var nd in self.TraitsImplementing <INotifyDamageStateChanged>())
                {
                    nd.DamageStateChanged(self, ai);
                }
            }

            if (attacker != null && attacker.IsInWorld && !attacker.IsDead())
            {
                foreach (var nd in attacker.TraitsImplementing <INotifyAppliedDamage>()
                         .Concat(attacker.Owner.PlayerActor.TraitsImplementing <INotifyAppliedDamage>()))
                {
                    nd.AppliedDamage(attacker, self, ai);
                }
            }

            if (hp == 0)
            {
                attacker.Owner.Kills++;
                self.Owner.Deaths++;

                foreach (var nd in self.TraitsImplementing <INotifyKilled>()
                         .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyKilled>()))
                {
                    nd.Killed(self, ai);
                }

                if (RemoveOnDeath)
                {
                    self.Destroy();
                }

                Log.Write("debug", "{0} #{1} killed by {2} #{3}", self.Info.Name, self.ActorID, attacker.Info.Name, attacker.ActorID);
            }
        }
Example #32
0
        public void InflictDamage(Actor self, Actor attacker, int damage, DamageWarhead warhead, bool ignoreModifiers)
        {
            // Overkill! don't count extra hits as more kills!
            if (IsDead)
            {
                return;
            }

            var oldState = DamageState;

            // Apply any damage modifiers
            if (!ignoreModifiers && damage > 0)
            {
                var modifiers = self.TraitsImplementing <IDamageModifier>()
                                .Concat(self.Owner.PlayerActor.TraitsImplementing <IDamageModifier>())
                                .Select(t => t.GetDamageModifier(attacker, warhead));

                damage = Util.ApplyPercentageModifiers(damage, modifiers);
            }

            hp = Exts.Clamp(hp - damage, 0, MaxHP);

            var ai = new AttackInfo
            {
                Attacker            = attacker,
                Damage              = damage,
                DamageState         = DamageState,
                PreviousDamageState = oldState,
                Warhead             = warhead,
            };

            foreach (var nd in self.TraitsImplementing <INotifyDamage>()
                     .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyDamage>()))
            {
                nd.Damaged(self, ai);
            }

            if (DamageState != oldState)
            {
                foreach (var nd in self.TraitsImplementing <INotifyDamageStateChanged>())
                {
                    nd.DamageStateChanged(self, ai);
                }
            }

            if (Info.NotifyAppliedDamage && attacker != null && attacker.IsInWorld && !attacker.IsDead)
            {
                foreach (var nd in attacker.TraitsImplementing <INotifyAppliedDamage>()
                         .Concat(attacker.Owner.PlayerActor.TraitsImplementing <INotifyAppliedDamage>()))
                {
                    nd.AppliedDamage(attacker, self, ai);
                }
            }

            if (hp == 0)
            {
                foreach (var nd in self.TraitsImplementing <INotifyKilled>()
                         .Concat(self.Owner.PlayerActor.TraitsImplementing <INotifyKilled>()))
                {
                    nd.Killed(self, ai);
                }

                if (RemoveOnDeath)
                {
                    self.Destroy();
                }

                Log.Write("debug", "{0} #{1} killed by {2} #{3}", self.Info.Name, self.ActorID, attacker.Info.Name, attacker.ActorID);
            }
        }