Example #1
0
        /// <summary>
        /// Registers a hit by the provided projectile. If the unit that the projectile hit
        /// is killed by the projectile, that is handled in this function.
        /// </summary>
        /// <param name="p">The projectile that struck its target</param>
        public void RegisterProjectileHit(Projectile p)
        {
            if (!p.Target.TargetBehavior.IsDead)
            {
                // Debug.Log(p.Target + " was hit by an attack for " + p.Damage + " damage!");
                p.Target.TargetBehavior.TakeDamage(p.Damage);
                if (p.Target.TargetBehavior.IsDead)
                {
                    // TODO: this block fires when a unit is killed by a projectile, maybe do particle stuff
                    p.Target.KillUnit();
                    p.Target.MovementBehavior.CurrentLocation.Occupants.Remove(p.Target);
                    _slainUnits[p.Target.UnitType] = 5;
                    _activeUnits.Remove(p.Target);

                    SoundPlayer.getInstance ().Play (sounds.death);
                }
            }

            p.MarkForDestruction();
            _deadProjectiles.Add(p);
        }