private void OnPlayerKillsNPC(NpcKilledEvent args) { try { SkillPlayer player = PlayerManager.GetPlayer(args.PlayerIndex); SkillInformation info = player.GetSkillInformation(Name); if (info == null) { info = new SkillInformation() { Name = this.Name, Value = 0 }; player.SetSkillInformation(info); return; } if (info.Value > 0) { FireRocket(player, args.Damage, info.Value); } } catch (Exception e) { Console.WriteLine(e.Message); } }
private void KilledHandler(Terraria.NPC terrariaNpc) { Debug.Assert(terrariaNpc != null); var npc = GetNpc(terrariaNpc); var evt = new NpcKilledEvent(npc); _events.Raise(evt, _log); }
private void OnNpcDamaged(TSPlayer player, int npcIndex, int damage, float knockback, byte direction, bool critical) { //DEBUG TShock.Log.ConsoleInfo("DEBUG [NPCDamage] NPCIndex {0}", npcIndex); //DEBUG NPC npc = Main.npc[npcIndex]; double damageDone = Main.CalculateDamage(damage, npc.ichor ? npc.defense - 20 : npc.defense); if (critical) { damageDone *= 2; } //Damage event var e = new NpcDamageEvent { NpcIndex = npcIndex, PlayerIndex = player.Index, Damage = damage, Knockback = knockback, Direction = direction, CriticalHit = critical, NpcHealth = Math.Max(0, npc.life - (int)damageDone) }; eventManager.InvokeHandler(e, EventType.NpcDamage); //This damage will kill the NPC. if (npc.active && npc.life > 0 && damageDone >= npc.life) { CustomNPCVars npcvar = NPCManager.NPCs[npcIndex]; if (npcvar != null) { npcvar.markDead(); } //Kill event var killedArgs = new NpcKilledEvent { NpcIndex = npcIndex, PlayerIndex = player.Index, Damage = damage, Knockback = knockback, Direction = direction, CriticalHit = critical, LastPosition = npc.position }; var SEconReward = new Money(npcvar.customNPC.SEconReward); // TODO: Improve Seconomy Code if needed // My Implementation of Seconomy Rewards, it's bountys for the last player who hits and kills the enemy, Not sure if this is the best way to do this // Remove when a actual fix is provide if (npcvar != null) { var economyPlayer = SEconomyPlugin.Instance.GetBankAccount(TSPlayer.Server.User.ID); if (!UsingSEConomy || !economyPlayer.IsAccountEnabled) { if (!economyPlayer.IsAccountEnabled) { TShock.Log.Error("You cannot gain any bounty because your account is disabled."); } } else { if (npcvar.customNPC.SEconReward > 0) { IBankAccount Player = SEconomyPlugin.Instance.GetBankAccount(TSPlayer.Server.User.ID); SEconomyPlugin.Instance.WorldAccount.TransferToAsync(Player, SEconReward, BankAccountTransferOptions.AnnounceToReceiver, npcvar.customNPC.customName + " Bountie", "Custom Npc Kill"); SEconReward = 0; } } } eventManager.InvokeHandler(killedArgs, EventType.NpcKill); if (npcvar != null && npcvar.isInvasion) { NPCManager.CustomNPCInvasion.WaveSize--; } } }