Damage structure, wraps a player slot and the amount of damage they have done.
Exemplo n.º 1
0
        /// <summary>
        /// Adds damage done by a player to an NPC slot.  When the NPC dies the rewards for it will fill out.
        /// </summary>
        protected void AddNPCDamage(NPC NPC, Player Player, int Damage, bool crit = false)
        {
            List <PlayerDamage> damageList   = null;
            PlayerDamage        playerDamage = null;
            double dmg;


            if (Player == null || NPC.active == false || NPC.life <= 0)
            {
                return;
            }

            lock (__dictionaryMutex)
            {
                if (DamageDictionary.ContainsKey(NPC))
                {
                    damageList = DamageDictionary[NPC];
                }
                else
                {
                    damageList = new List <PlayerDamage>(1);
                    DamageDictionary.Add(NPC, damageList);
                }
            }

            lock (__NPCDamageMutex)
            {
                if ((playerDamage = damageList.FirstOrDefault(i => i.Player == Player)) == null)
                {
                    playerDamage = new PlayerDamage()
                    {
                        Player = Player
                    };
                    damageList.Add(playerDamage);
                }

                if ((dmg = (crit ? 2 : 1) * Main.CalculateDamageNPCsTake(Damage, NPC.ichor ? NPC.defense - 20 : NPC.defense)) > NPC.life)
                {
                    dmg = NPC.life;
                }
            }
            playerDamage.Damage += dmg;

            if (playerDamage.Damage > NPC.lifeMax)
            {
                playerDamage.Damage -= playerDamage.Damage % NPC.lifeMax;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds damage done by a player to an NPC slot.  When the NPC dies the rewards for it will fill out.
        /// </summary>
        protected void AddNPCDamage(Terraria.NPC NPC, Terraria.Player Player, int Damage, bool crit = false)
        {
            List<PlayerDamage> damageList = null;
            PlayerDamage playerDamage = null;
            double dmg;

            if (Player == null || NPC.active == false || NPC.life <= 0) {
                return;
            }

            lock (__dictionaryMutex) {
                if (DamageDictionary.ContainsKey(NPC)) {
                    damageList = DamageDictionary[NPC];
                } else {
                    damageList = new List<PlayerDamage>(1);
                    DamageDictionary.Add(NPC, damageList);
                }
            }

            lock (__NPCDamageMutex) {
                if ((playerDamage = damageList.FirstOrDefault(i => i.Player == Player)) == null) {
                    playerDamage = new PlayerDamage() { Player = Player };
                    damageList.Add(playerDamage);
                }

                if ((dmg = (crit ? 2 : 1) * Main.CalculateDamage(Damage, NPC.ichor ? NPC.defense - 20 : NPC.defense)) > NPC.life) {
                    dmg = NPC.life;
                }
            }

            playerDamage.Damage += dmg;
        }