AddDamageTo() public method

public AddDamageTo ( float dmgAmount, bool player, bool npc, bool entity ) : void
dmgAmount float
player bool
npc bool
entity bool
return void
コード例 #1
0
        // BaseAnimal.OnAttacked()
        public static void NPCHurt(BaseAnimal animal, HitInfo info)
        {
            // works
            var npc = new NPC(animal);

            if (info.Initiator != null)
            {
                Player      p     = new Player(info.Initiator as BasePlayer);
                PlayerStats stats = new PlayerStats(p.SteamID);
                stats.AddDamageTo(info.damageAmount, false, true, false);
                p.Stats = stats;
            }

            if (!Realm.Server() || (double)animal.myHealth <= 0.0)
            {
                return;
            }

            if ((animal.myHealth - info.damageAmount) > 0.0f)
            {
                OnNPCHurt.OnNext(new Events.NPCHurtEvent(npc, info));
            }

            animal.myHealth -= info.damageAmount;
            if ((double)animal.myHealth > 0.0)
            {
                return;
            }
            animal.Die(info);
        }
コード例 #2
0
        // BasePlayer.OnAttacked()
        public static void PlayerHurt(BasePlayer player, HitInfo info)
        {
            // not tested
            var p = new Player(player);

            if (info == null)   // it should never accour, but just in case
            {
                info = new HitInfo();
                info.damageAmount = 0.0f;
                info.damageType   = player.metabolism.lastDamage;
                info.Initiator    = player as BaseEntity;
            }

            bool        fromPlayer = (info.Initiator is BasePlayer);
            PlayerStats statV      = p.Stats;

            statV.AddDamageFrom(info.damageAmount, fromPlayer, !fromPlayer, false);
            p.Stats = statV;

            if (fromPlayer)
            {
                string      sid   = info.Initiator.ToPlayer().userID.ToString();
                PlayerStats statA = new PlayerStats(sid);
                statA.AddDamageTo(info.damageAmount, true, false, false);
                Server.GetServer().serverData.Add("PlayerStats", sid, statA);
            }

            if (!player.TestAttack(info) || !Realm.Server() || (info.damageAmount <= 0.0f))
            {
                return;
            }
            player.metabolism.bleeding.Add(Mathf.InverseLerp(0.0f, 100f, info.damageAmount));
            player.metabolism.SubtractHealth(info.damageAmount);
            player.TakeDamageIndicator(info.damageAmount, player.transform.position - info.PointStart);
            player.CheckDeathCondition(info);

            if (!player.IsDead())
            {
                OnPlayerHurt.OnNext(new Events.PlayerHurtEvent(p, info));
            }

            player.SendEffect("takedamage_hit");
        }
コード例 #3
0
        // BuildingBlock.OnAttacked()
        public static void EntityAttacked(BuildingBlock bb, HitInfo info)
        {
            // works, event needed
            if (info.Initiator != null)
            {
                Player      p     = new Player(info.Initiator as BasePlayer);
                PlayerStats stats = new PlayerStats(p.SteamID);
                stats.AddDamageTo(info.damageAmount, false, false, true);
                p.Stats = stats;
            }

            var bp = new BuildingPart(bb);

            // if entity will be destroyed call the method below
            if ((bb.health - info.damageAmount) <= 0.0f)
            {
                BuildingPartDestroyed(bp, info);
                if ((bb.health - info.damageAmount) <= 0.0f)
                {
                    return;
                }
            }
            OnBuildingPartAttacked.OnNext(new BuildingHurtEvent(bp, info));
        }