public static void AIHook(On.Terraria.NPC.orig_AI_007_TownEntities orig, NPC self) { if (SomeUtils.BuffNPC() && (self.townNPC || self.type == NPCID.SkeletonMerchant)) { Rectangle Screen = new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight); if (self.Hitbox.Intersects(Screen)) { NPCOverrideAI.AI_007_TownEntities(self); return; } } orig.Invoke(self); }
public override void Load(TagCompound tag) { var NPCType = tag.Get <List <string> >("NPCType"); var NPCWeapon = tag.Get <List <Item> >("NPCWeapon"); WeaponToNPC = NPCType.Zip(NPCWeapon, (k, v) => new { Key = k, Value = v }).ToDictionary(x => x.Key, x => x.Value); foreach (string type in WeaponToNPC.Keys) { bool IsModdedNPC; string ModName = ""; string ModNPCName = ""; int VanillaType = -1; string[] args = type.Split(':'); if (args.Length < 2) { continue; } if (args[0] == "Vanilla") { IsModdedNPC = false; int result = -1; int.TryParse(args[1], out result); if (result == -1) { continue; } VanillaType = result; } else { IsModdedNPC = true; ModName = args[0]; ModNPCName = args[1]; } if (!IsModdedNPC) { foreach (NPC npc in Main.npc) { if (npc.active) { if (npc.modNPC == null && npc.type == VanillaType) { if (ArmedGNPC.GetWeapon(npc).IsAir) { npc.GetGlobalNPC <ArmedGNPC>().Weapon = SomeUtils.CloneItem(WeaponToNPC[type]); break; } } } } } else { foreach (NPC npc in Main.npc) { if (npc.active) { if (npc.modNPC != null) { if (npc.modNPC.mod.Name == ModName && npc.modNPC.Name == ModNPCName) { if (ArmedGNPC.GetWeapon(npc).IsAir) { npc.GetGlobalNPC <ArmedGNPC>().Weapon = SomeUtils.CloneItem(WeaponToNPC[type]); break; } } } } } } } WeaponToNPC.Clear(); }
public static double StrikeNPCHook(On.Terraria.NPC.orig_StrikeNPC orig, NPC self, int Damage, float knockBack, int hitDirection, bool crit = false, bool noEffect = false, bool fromNet = false) { if ((!self.townNPC && self.type != NPCID.SkeletonMerchant) || SomeUtils.NoMode()) { return(orig.Invoke(self, Damage, knockBack, hitDirection, crit, noEffect, fromNet)); } bool flag = Main.netMode == NetmodeID.SinglePlayer; var ReflectTarget = typeof(NPC).GetField("ignorePlayerInteractions", BindingFlags.NonPublic | BindingFlags.Static); if (flag && (int)ReflectTarget.GetValue(new NPC()) > 0) { ReflectTarget.SetValue(new NPC(), (int)ReflectTarget.GetValue(new NPC()) - 1); flag = false; } if (!self.active || self.life <= 0) { return(0.0); } double num = Damage; int num2 = self.defense; if (self.ichor) { num2 -= 20; } if (self.betsysCurse) { num2 -= 40; } if (num2 < 0) { num2 = 0; } if (NPCLoader.StrikeNPC(self, ref num, num2, ref knockBack, hitDirection, ref crit)) { num = Main.CalculateDamage((int)num, num2); if (crit) { num *= 2.0; } if (self.takenDamageMultiplier > 1f) { num *= self.takenDamageMultiplier; } } if ((self.takenDamageMultiplier > 1f || Damage != 9999) && self.lifeMax > 1) { if (self.friendly) { Color color = crit ? CombatText.DamagedFriendlyCrit : CombatText.DamagedFriendly; CombatText.NewText(new Rectangle((int)self.position.X, (int)self.position.Y, self.width, self.height), color, (int)num, crit, false); } else { Color color2 = crit ? CombatText.DamagedHostileCrit : CombatText.DamagedHostile; if (fromNet) { color2 = (crit ? CombatText.OthersDamagedHostileCrit : CombatText.OthersDamagedHostile); } CombatText.NewText(new Rectangle((int)self.position.X, (int)self.position.Y, self.width, self.height), color2, (int)num, crit, false); } } if (num >= 1.0) { if (flag) { self.PlayerInteraction(Main.myPlayer); } self.justHit = true; if (!SomeUtils.BuffNPC()) { if (self.townNPC) { bool flag2 = self.aiStyle == 7 && (self.ai[0] == 3f || self.ai[0] == 4f || self.ai[0] == 16f || self.ai[0] == 17f); if (flag2) { NPC npc = Main.npc[(int)self.ai[2]]; if (npc.active) { npc.ai[0] = 1f; npc.ai[1] = 300 + Main.rand.Next(300); npc.ai[2] = 0f; npc.localAI[3] = 0f; npc.direction = hitDirection; npc.netUpdate = true; } } self.ai[0] = 1f; self.ai[1] = 300 + Main.rand.Next(300); self.ai[2] = 0f; self.localAI[3] = 0f; self.direction = hitDirection; self.netUpdate = true; } } if (self.townNPC && SomeUtils.AttackMode()) { if (NPCID.Sets.AttackType[self.type] == 3) { knockBack = 0; } } if (self.aiStyle == 8 && Main.netMode != NetmodeID.MultiplayerClient) { if (self.type == NPCID.RuneWizard) { self.ai[0] = 450f; } else if (self.type == NPCID.Necromancer || self.type == NPCID.NecromancerArmored) { if (Main.rand.Next(2) == 0) { self.ai[0] = 390f; self.netUpdate = true; } } else if (self.type == NPCID.DesertDjinn) { if (Main.rand.Next(3) != 0) { self.ai[0] = 181f; self.netUpdate = true; } } else { self.ai[0] = 400f; } self.TargetClosest(true); } if (self.aiStyle == 97 && Main.netMode != NetmodeID.MultiplayerClient) { self.localAI[1] = 1f; self.TargetClosest(true); } if (self.type == NPCID.DetonatingBubble) { num = 0.0; self.ai[0] = 1f; self.ai[1] = 4f; self.dontTakeDamage = true; } if (self.type == NPCID.SantaNK1 && self.life >= self.lifeMax * 0.5 && self.life - num < self.lifeMax * 0.5) { Gore.NewGore(self.position, self.velocity, 517, 1f); } if (self.type == NPCID.SpikedIceSlime) { self.localAI[0] = 60f; } if (self.type == NPCID.SlimeSpiked) { self.localAI[0] = 60f; } if (self.type == NPCID.SnowFlinx) { self.localAI[0] = 1f; } if (!self.immortal) { if (self.realLife >= 0) { Main.npc[self.realLife].life -= (int)num; self.life = Main.npc[self.realLife].life; self.lifeMax = Main.npc[self.realLife].lifeMax; } else { self.life -= (int)num; } } if (knockBack > 0f && self.knockBackResist > 0f) { float num3 = knockBack * self.knockBackResist; if (num3 > 8f) { float num4 = num3 - 8f; num4 *= 0.9f; num3 = 8f + num4; } if (num3 > 10f) { float num5 = num3 - 10f; num5 *= 0.8f; num3 = 10f + num5; } if (num3 > 12f) { float num6 = num3 - 12f; num6 *= 0.7f; num3 = 12f + num6; } if (num3 > 14f) { float num7 = num3 - 14f; num7 *= 0.6f; num3 = 14f + num7; } if (num3 > 16f) { num3 = 16f; } if (crit) { num3 *= 1.4f; } int num8 = (int)num * 10; if (Main.expertMode) { num8 = (int)num * 15; } if (num8 > self.lifeMax) { if (hitDirection < 0 && self.velocity.X > -num3) { if (self.velocity.X > 0f) { self.velocity.X -= num3; } self.velocity.X -= num3; if (self.velocity.X < -num3) { self.velocity.X = -num3; } } else if (hitDirection > 0 && self.velocity.X < num3) { if (self.velocity.X < 0f) { self.velocity.X += num3; } self.velocity.X += num3; if (self.velocity.X > num3) { self.velocity.X = num3; } } if (self.type == NPCID.SnowFlinx) { num3 *= 1.5f; } if (!self.noGravity) { num3 *= -0.75f; } else { num3 *= -0.5f; } if (self.velocity.Y > num3) { self.velocity.Y += num3; if (self.velocity.Y < num3) { self.velocity.Y = num3; } } } else { if (!self.noGravity) { self.velocity.Y = -num3 * 0.75f * self.knockBackResist; } else { self.velocity.Y = -num3 * 0.5f * self.knockBackResist; } self.velocity.X = num3 * hitDirection * self.knockBackResist; } } if ((self.type == NPCID.WallofFlesh || self.type == NPCID.WallofFleshEye) && self.life <= 0) { for (int i = 0; i < 200; i++) { if (Main.npc[i].active && (Main.npc[i].type == NPCID.WallofFlesh || Main.npc[i].type == NPCID.WallofFleshEye)) { Main.npc[i].HitEffect(hitDirection, num); } } } else { self.HitEffect(hitDirection, num); } if (self.HitSound != null) { Main.PlaySound(self.HitSound, self.position); } if (self.realLife >= 0) { Main.npc[self.realLife].checkDead(); } else { self.checkDead(); } return(num); } return(0.0); }