/// <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; }
/// <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; }