public override TagCompound Save() { WeaponToNPC.Clear(); foreach (NPC npc in Main.npc) { if (npc.active && (npc.townNPC || npc.type == NPCID.SkeletonMerchant)) { if (!ArmedGNPC.GetWeapon(npc).IsAir) { string TypeOrName; if (npc.modNPC == null) { TypeOrName = "Vanilla:" + npc.type.ToString(); } else { TypeOrName = npc.modNPC.mod.Name + ":" + npc.modNPC.Name; } WeaponToNPC.Add(TypeOrName, ArmedGNPC.GetWeapon(npc)); //ArmedGNPC.GetWeapon(npc).TurnToAir(); } } } return(new TagCompound { { "NPCType", WeaponToNPC.Keys.ToList() }, { "NPCWeapon", WeaponToNPC.Values.ToList() } }); }
public override bool PreAI(Projectile projectile) { if (projectile.type == ProjectileID.NurseSyringeHeal) { if (projectile.localAI[1] == 0f) { projectile.localAI[1] = projectile.velocity.Length(); } if (!Main.npc[(int)projectile.ai[0]].active || !Main.npc[(int)projectile.ai[0]].townNPC) { projectile.Kill(); return(false); } NPC target = Main.npc[(int)projectile.ai[0]]; Vector2 ShootVel = target.Center - projectile.Center; if (ShootVel.Length() < projectile.localAI[1] || projectile.Hitbox.Intersects(target.Hitbox)) { projectile.Kill(); int DamageTaken = target.lifeMax - target.life; int HealLife = 20; if (SomeUtils.BuffNPC()) { if (NPC.downedMoonlord) { HealLife = 40; } else if (NPC.downedPlantBoss) { HealLife = 30; } else if (Main.hardMode) { HealLife = 25; } if (NPC.AnyNPCs(NPCID.Nurse)) { NPC nurse = Main.npc[NPC.FindFirstNPC(NPCID.Nurse)]; if (!ArmedGNPC.GetWeapon(nurse).IsAir) { HealLife = ArmedGNPC.GetWeapon(nurse).healLife / 2; if (ArmedGNPC.GetWeapon(nurse).buffType > 0) { target.AddBuff(ArmedGNPC.GetWeapon(nurse).buffType, ArmedGNPC.GetWeapon(nurse).buffTime); } if (ArmedGNPC.GetWeapon(nurse).UseSound != null) { Main.PlaySound(ArmedGNPC.GetWeapon(nurse).UseSound, projectile.Center); } } } if (NPC.downedPlantBoss) { for (int i = 0; i < target.buffTime.Length; i++) { if (Main.debuff[target.buffType[i]] && target.buffTime[i] > 0) { target.buffTime[i] = 0; } } } } if (DamageTaken > HealLife) { DamageTaken = HealLife; } if (DamageTaken > 0) { target.life += DamageTaken; target.HealEffect(DamageTaken, true); } return(false); } ShootVel.Normalize(); ShootVel *= projectile.localAI[1]; if (ShootVel.Y < projectile.velocity.Y) { ShootVel.Y = projectile.velocity.Y; } ShootVel.Y += 1f; projectile.velocity = Vector2.Lerp(projectile.velocity, ShootVel, 0.04f); projectile.rotation += projectile.velocity.X * 0.05f; return(false); } if (projectile.npcProj) { if (projectile.type == ProjectileID.BloodCloudRaining || projectile.type == ProjectileID.RainCloudRaining) { if (++projectile.frameCounter > 8) { projectile.frameCounter = 0; if (++projectile.frame > 5) { projectile.frame = 0; } } projectile.ai[1] += 1f; if (projectile.type == 244 && projectile.ai[1] >= 180f) { projectile.alpha += 5; if (projectile.alpha > 255) { projectile.alpha = 255; projectile.Kill(); } } else if (projectile.type == 238 && projectile.ai[1] >= 360f) { projectile.alpha += 5; if (projectile.alpha > 255) { projectile.alpha = 255; projectile.Kill(); } } else { projectile.ai[0] += 1f; if (projectile.type == 244) { if (projectile.ai[0] > 10f) { projectile.ai[0] = 0f; if (projectile.owner == Main.myPlayer) { int num417 = (int)(projectile.position.X + 14f + Main.rand.Next(projectile.width - 28)); int num418 = (int)(projectile.position.Y + projectile.height + 4f); int protmp = Projectile.NewProjectile(num417, num418, 0f, 5f, ProjectileID.BloodRain, projectile.damage, 0f, projectile.owner, 0f, 0f); Main.projectile[protmp].npcProj = true; Main.projectile[protmp].usesLocalNPCImmunity = true; Main.projectile[protmp].localNPCHitCooldown = 10; } } } else if (projectile.ai[0] > 8f) { projectile.ai[0] = 0f; if (projectile.owner == Main.myPlayer) { int num419 = (int)(projectile.position.X + 14f + Main.rand.Next(projectile.width - 28)); int num420 = (int)(projectile.position.Y + projectile.height + 4f); int protmp = Projectile.NewProjectile(num419, num420, 0f, 5f, ProjectileID.RainFriendly, projectile.damage, 0f, projectile.owner, 0f, 0f); Main.projectile[protmp].npcProj = true; Main.projectile[protmp].usesLocalNPCImmunity = true; Main.projectile[protmp].localNPCHitCooldown = 10; } } } return(false); } if (projectile.type == ProjectileID.ClingerStaff) { projectile.position.Y = projectile.ai[0]; projectile.height = (int)projectile.ai[1]; if (projectile.Center.X > Main.player[projectile.owner].Center.X) { projectile.direction = 1; } else { projectile.direction = -1; } projectile.velocity.X = projectile.direction * 1E-06f; float num842 = projectile.width * projectile.height * 0.0045f; int num843 = 0; while (num843 < num842) { int num844 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 75, 0f, 0f, 100, default, 1f);
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(); }