public override void PostAI() { if (Main.netMode != NetmodeID.Server) { Player player = Main.player[Main.myPlayer]; tsorcRevampPlayer modPlayer = player.GetModPlayer <tsorcRevampPlayer>(); BonfireProjectiles.PiggyBankAI(projectile, ItemID.PiggyBank, -2, ref modPlayer.safe, player, modPlayer); } }
public override void AI() { Player player = Main.player[projectile.owner]; tsorcRevampPlayer modPlayer = player.GetModPlayer <tsorcRevampPlayer>(); if (player.dead) { modPlayer.RTQ2 = false; } if (modPlayer.RTQ2) { projectile.timeLeft = 2; } if (Main.rand.Next(2) == 0) { int dust = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 57, projectile.velocity.X, projectile.velocity.Y, 200, Color.White, 1f); Main.dust[dust].noGravity = true; } }
internal static void PiggyBankAI(Projectile proj, int itemType, int chestType, ref int playerBank, Player p, tsorcRevampPlayer modPlayer) { if (Main.gamePaused && !Main.gameMenu) { return; } Vector2 projPosRelative = proj.position - Main.screenPosition; int pTilePosX = (int)(p.Center.X / 16.0); int pTilePosY = (int)(p.Center.Y / 16.0); int projTilePosX = (int)proj.Center.X / 16; int projTilePosY = (int)proj.Center.Y / 16; int lastTileRangeX = p.lastTileRangeX; int lastTileRangeY = p.lastTileRangeY; if (pTilePosX < projTilePosX - lastTileRangeX || pTilePosX > projTilePosX + lastTileRangeX + 1 || pTilePosY < projTilePosY - lastTileRangeY || pTilePosY > projTilePosY + lastTileRangeY + 1) { if (playerBank == proj.whoAmI) { playerBank = -1; modPlayer.chests = false; } } else { if (Main.mouseX <= projPosRelative.X || Main.mouseX >= projPosRelative.X + proj.width || Main.mouseY <= projPosRelative.Y || Main.mouseY >= projPosRelative.Y + proj.height) { return; } p.noThrow = 2; p.showItemIcon = true; p.showItemIcon2 = itemType; if (PlayerInput.UsingGamepad) { p.GamepadEnableGrappleCooldown(); } if (!Main.mouseRight || !Main.mouseRightRelease || Player.StopMoneyTroughFromWorking != 0) { return; } Main.mouseRightRelease = false; if (p.chest == chestType) { Main.PlaySound(p.chest == -2 ? SoundID.Item59 : new Terraria.Audio.LegacySoundStyle(SoundID.CoinPickup, 0)); p.chest = -1; Recipe.FindRecipes(); return; } bool flag = false; pTilePosX = ((p.SpawnX == -1) ? Main.spawnTileX : p.SpawnX); pTilePosY = ((p.SpawnY == -1) ? Main.spawnTileY : p.SpawnY); if (!SolidTile(projTilePosX, projTilePosY)) { for (int i = 0; i < Main.maxTilesX; i++) { for (int j = 0; j < Main.maxTilesY; j++) { if (pTilePosX - i > 40 && pTilePosY + j < Main.maxTilesY - 40 && SolidTile(pTilePosX - i, pTilePosY + j)) { projTilePosX = pTilePosX - i; projTilePosY = pTilePosY + j; flag = true; break; } if (pTilePosX + i < Main.maxTilesX - 40 && pTilePosY + j < Main.maxTilesY - 40 && SolidTile(pTilePosX + i, pTilePosY + j)) { projTilePosX = pTilePosX + i; projTilePosY = pTilePosY + j; flag = true; break; } if (pTilePosX + i < Main.maxTilesX - 40 && pTilePosY - j > 40 && SolidTile(pTilePosX + i, pTilePosY - j)) { projTilePosX = pTilePosX + i; projTilePosY = pTilePosY - j; flag = true; break; } if (pTilePosX - i > 40 && pTilePosY - j > 40 && SolidTile(pTilePosX - i, pTilePosY - j)) { projTilePosX = pTilePosX - i; projTilePosY = pTilePosY - j; flag = true; break; } } if (flag) { break; } } } playerBank = proj.whoAmI; modPlayer.chests = true; p.chest = chestType; p.chestX = projTilePosX; p.chestY = projTilePosY; p.talkNPC = -1; Main.npcShop = 0; Main.playerInventory = true; Main.PlaySound(p.chest == -2? SoundID.Item59 : new Terraria.Audio.LegacySoundStyle(SoundID.CoinPickup, 0)); Recipe.FindRecipes(); } }