Beispiel #1
0
 public void OnObjectDamage(IObject obj, ObjectDamageArgs args)
 {
     // object took damage
     if (args.DamageType != ObjectDamageType.Fire)
     {
         if (args.SourceID != 0)
         {
             Game.WriteToConsole(string.Format("Object {0} took {1} {2} damage from {3} {4}", obj.UniqueID, args.Damage, args.DamageType, (args.IsPlayer ? "player" : "object"), args.SourceID));
         }
         else
         {
             Game.WriteToConsole(string.Format("Object {0} took {1} {2} damage", obj.UniqueID, args.Damage, args.DamageType));
         }
     }
 }
Beispiel #2
0
        private static void OnObjectDamage(IObject obj, ObjectDamageArgs arg)
        {
            if (string.IsNullOrEmpty(obj.CustomID))
            {
                return;
            }

            foreach (var weapon in m_weapons)
            {
                foreach (var component in weapon.Components.ToList())
                {
                    if (obj.UniqueID == component.UniqueID)
                    {
                        weapon.OnDamage(obj, arg);
                    }
                }
            }
        }
Beispiel #3
0
        public override void OnDamage(IObject obj, ObjectDamageArgs args)
        {
            foreach (var dc in m_damageableComponents)
            {
                if (dc.Object.UniqueID == obj.UniqueID)
                {
                    // barrel component is indestructible and there are 4 dc. A cheap solution is
                    // to randomize to have barrel damage instead when other dc takes damage
                    if (RandomHelper.Between(0, 1) < (1f / 3f) - (1f / 4f))
                    {
                        m_damageableComponents.First().OnDamage(args);
                    }

                    dc.OnDamage(args);
                    break;
                }
            }

            // https://www.alanzucconi.com/2015/07/26/enum-flags-and-bitwise-operators/
            if (m_barrel.Health == 0 && !HasDamage(TurretDamage.BarrelDamaged))
            {
                Game.PlayEffect(EffectName.CustomFloatText, RotationCenter + Vector2.UnitY * 5, "Barrel Damaged");
                m_damage = m_damage | TurretDamage.BarrelDamaged;
            }
            if (m_rotor.Health == 0 && !HasDamage(TurretDamage.RotorDamaged))
            {
                OnBodyDamage(TurretDamage.RotorDamaged, "Rotor Damaged");
            }
            if (m_sensor.Health == 0 && !HasDamage(TurretDamage.SensorDamaged))
            {
                OnBodyDamage(TurretDamage.SensorDamaged, "Sensor Damaged");
            }
            if (m_controller.Health == 0 && !HasDamage(TurretDamage.ControllerDamaged))
            {
                OnBodyDamage(TurretDamage.ControllerDamaged, "Controller Damaged");
            }

            if (Totaled() && !IsDestroyed)
            {
                Destroy();
            }
        }
Beispiel #4
0
        public void OnDamage(ObjectDamageArgs args)
        {
            Health -= args.Damage; // IObject.GetHealth() is already recalculated when this event is fired

            if (Object.GetHealth() == 0 && Health > 0)
            {
                Object.SetHealth(Math.Min(Object.GetMaxHealth(), Health));
            }

            if (Health == 0)
            {
                if (RemoveWhenDestroyed)
                {
                    Object.Remove();
                }
                else
                {
                    Object.SetHealth(Object.GetMaxHealth());
                }
            }
        }
Beispiel #5
0
 public virtual void OnDamage(IObject component, ObjectDamageArgs args) { }