public override bool NewRightClick(int tX, int tY) { Player player = Main.LocalPlayer; GetTileAndChestPosition(tX, tY, out Tile tile, out int left, out int top); Main.mouseRightRelease = false; Main.defaultChestName = chest; // Close sign if open if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } // Swap Chests if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } // Update Chest name if (player.editedChestName) { NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { // If already open, close player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { // If not opened, attempt to open NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; // Close if this is already open if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } // Otherwise, open sesame else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } return(true); }
public void SetUpBankChest(TSPlayer player, DPoint tileLocation, int bankChestIndex, bool checkPermissions = false) { Contract.Requires <ArgumentNullException>(player != null); Contract.Requires <ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation"); Contract.Requires <ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation"); Contract.Requires <ArgumentOutOfRangeException>(bankChestIndex >= 1, "bankChestIndex"); Tile tile = TerrariaUtils.Tiles[tileLocation]; BlockType blockType = (BlockType)tile.type; if (blockType != BlockType.Chest) { throw new InvalidBlockTypeException(blockType); } if (checkPermissions && !player.Group.HasPermission(ProtectorPlugin.SetBankChests_Permission)) { throw new MissingPermissionException(ProtectorPlugin.SetBankChests_Permission); } if ( checkPermissions && !player.Group.HasPermission(ProtectorPlugin.NoBankChestLimits_Permision) ) { if (bankChestIndex > this.Config.MaxBankChestsPerPlayer) { throw new ArgumentOutOfRangeException("bankChestIndex", this.Config.MaxBankChestsPerPlayer, "Global bank chest limit reached."); } int byGroupLimit; if ( this.Config.MaxBankChests.TryGetValue(player.Group.Name, out byGroupLimit) && bankChestIndex > byGroupLimit ) { throw new ArgumentOutOfRangeException("bankChestIndex", byGroupLimit, "Group bank chest limit reached."); } } DPoint chestLocation = TerrariaUtils.Tiles.MeasureObject(tileLocation).OriginTileLocation; ProtectionEntry protection; lock (this.WorldMetadata.Protections) if (!this.WorldMetadata.Protections.TryGetValue(chestLocation, out protection)) { throw new NoProtectionException(chestLocation); } if (!this.CheckBlockAccess(player, chestLocation, true)) { throw new TileProtectedException(chestLocation); } if (protection.RefillChestData != null) { throw new ChestIncompatibilityException(); } int tChestIndex = Chest.FindChest(chestLocation.X, chestLocation.Y); if (tChestIndex == -1 || Main.chest[tChestIndex] == null) { throw new NoChestDataException(chestLocation); } if (protection.BankChestKey != BankChestDataKey.Invalid) { throw new ChestTypeAlreadyDefinedException(); } BankChestDataKey bankChestKey = new BankChestDataKey(player.UserID, bankChestIndex); lock (this.WorldMetadata.Protections) { if (this.WorldMetadata.Protections.Values.Count(p => p.BankChestKey == bankChestKey) > 0) { throw new BankChestAlreadyInstancedException(); } } if (checkPermissions && !player.Group.HasPermission(ProtectorPlugin.BankChestShare_Permission)) { protection.Unshare(); } Chest tChest = Main.chest[tChestIndex]; BankChestMetadata bankChest = this.ServerMetadataHandler.EnqueueGetBankChestMetadata(bankChestKey).Result; if (bankChest == null) { bankChest = new BankChestMetadata(); for (int i = 0; i < Chest.maxItems; i++) { bankChest.Items[i] = ItemData.FromItem(tChest.item[i]); } this.ServerMetadataHandler.EnqueueAddOrUpdateBankChest(bankChestKey, bankChest); } else { for (int i = 0; i < tChest.item.Length; i++) { if (tChest.item[i].stack > 0) { throw new ChestNotEmptyException(chestLocation); } } for (int i = 0; i < Chest.maxItems; i++) { tChest.item[i] = bankChest.Items[i].ToItem(); } } protection.BankChestKey = bankChestKey; }
public override void RightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } }
private bool RequestChestOpen(ref BinaryReader reader, int playerNumber) { if (!ServerSideCharacter.Config.EnableChestProtection) { return(false); } if (Main.netMode == 2) { int x = reader.ReadInt16(); int y = reader.ReadInt16(); int id = Chest.FindChest(x, y); Player player = Main.player[playerNumber]; ServerPlayer sPlayer = player.GetServerPlayer(); ChestManager.Pending pending = ServerSideCharacter.ChestManager.GetPendings(sPlayer); switch (pending) { case ChestManager.Pending.AddFriend: if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer)) { ServerPlayer friend = ServerSideCharacter.ChestManager.GetFriendP(sPlayer); ServerSideCharacter.ChestManager.AddFriend(id, friend); sPlayer.SendSuccessInfo($"{friend.Name} can open this chest now"); } else { sPlayer.SendErrorInfo("You are not the owner of this chest"); } break; case ChestManager.Pending.RemoveFriend: if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer)) { ServerPlayer friend = ServerSideCharacter.ChestManager.GetFriendP(sPlayer); ServerSideCharacter.ChestManager.RemoveFriend(id, friend); sPlayer.SendSuccessInfo($"{friend.Name} can't open this chest now"); } else { sPlayer.SendErrorInfo("You are not the owner of this chest"); } break; case ChestManager.Pending.Public: if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer)) { if (!ServerSideCharacter.ChestManager.IsPublic(id)) { ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, true); sPlayer.SendSuccessInfo("This chest is now Public"); } else { sPlayer.SendErrorInfo("This chest is already public"); } } else { sPlayer.SendErrorInfo("You are not the owner of this chest"); } break; case ChestManager.Pending.UnPublic: if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer)) { if (ServerSideCharacter.ChestManager.IsPublic(id)) { ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false); sPlayer.SendSuccessInfo("This chest is not Public anymore"); } else { sPlayer.SendErrorInfo("This chest is not public"); } } else { sPlayer.SendErrorInfo("You are not the owner of this chest"); } break; case ChestManager.Pending.Protect: if (ServerSideCharacter.ChestManager.IsNull(id)) { ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false); sPlayer.SendSuccessInfo("You now own this chest"); } else if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer)) { sPlayer.SendErrorInfo("You already protected this chest"); } else { sPlayer.SendErrorInfo("This chest as already been protected by other player"); } break; case ChestManager.Pending.DeProtect: if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer)) { ServerSideCharacter.ChestManager.SetOwner(id, -1, false); sPlayer.SendSuccessInfo("This chest is no longer yours"); } else if (ServerSideCharacter.ChestManager.IsNull(id)) { sPlayer.SendErrorInfo("This chest don't have a owner"); } else { sPlayer.SendErrorInfo("You are not the owner of this chest"); } break; case ChestManager.Pending.Info: if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer)) { ChestInfo chest = ServerSideCharacter.ChestManager.ChestInfo[id]; StringBuilder info = new StringBuilder(); if (sPlayer.PermissionGroup.HasPermission("chest")) { info.AppendLine($"Owner: {ServerPlayer.FindPlayer(chest.OwnerID).Name}"); //For Admins } info.AppendLine($"Public Chest: {chest.IsPublic.ToString().ToUpper()}"); info.AppendLine($"Friends ({chest.Friends.Count.ToString()}): {string.Join(", ", chest.Friends.ToArray().Take(10).Select(uuid => ServerPlayer.FindPlayer(uuid).Name))}"); sPlayer.SendInfo(info.ToString()); } else if (ServerSideCharacter.ChestManager.IsNull(id)) { sPlayer.SendErrorInfo("This chest don't have a owner"); } else { sPlayer.SendErrorInfo("You are not the owner of this chest"); } break; default: if (ServerSideCharacter.ChestManager.IsNull(id)) { if (ServerSideCharacter.Config.AutoProtectChests) { ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false); sPlayer.SendSuccessInfo("You now own this chest"); } else { sPlayer.SendErrorInfo("Use '/chest protect' to become the owner of this chest"); } return(false); } else if (ServerSideCharacter.ChestManager.CanOpen(id, sPlayer)) { return(false); } else { sPlayer.SendErrorInfo("You cannot open this chest"); } break; } ServerSideCharacter.ChestManager.RemovePending(sPlayer, pending); } return(true); }
public static bool ChestItemSummonCheck(int x, int y, Mod mod) { if (Main.netMode == 1) { return(false); } int num = Chest.FindChest(x, y); if (num < 0) { return(false); } int numberExampleBlocks = 0; int numberOtherItems = 0; ushort tileType = Main.tile[Main.chest[num].x, Main.chest[num].y].type; int tileStyle = (int)(Main.tile[Main.chest[num].x, Main.chest[num].y].frameX / 36); if (tileType == TileID.Containers && (tileStyle < 5 || tileStyle > 6)) { for (int i = 0; i < 40; i++) { if (Main.chest[num].item[i] != null && Main.chest[num].item[i].type > 0) { if (Main.chest[num].item[i].type == mod.ItemType("SwampChestKey")) { numberExampleBlocks += Main.chest[num].item[i].stack; } else { numberOtherItems++; } } } } if (numberOtherItems == 0 && numberExampleBlocks == 1) { if (Main.tile[x, y].type == 21) { if (Main.tile[x, y].frameX % 36 != 0) { x--; } if (Main.tile[x, y].frameY % 36 != 0) { y--; } int number = Chest.FindChest(x, y); for (int j = x; j <= x + 1; j++) { for (int k = y; k <= y + 1; k++) { if (Main.tile[j, k].type == 21) { Main.tile[j, k].active(false); } } } for (int l = 0; l < 40; l++) { Main.chest[num].item[l] = new Item(); } Chest.DestroyChest(x, y); NetMessage.SendData(34, -1, -1, null, 1, (float)x, (float)y, 0f, number, 0, 0); NetMessage.SendTileSquare(-1, x, y, 3); } int npcToSpawn = mod.NPCType("SwampBigMimic"); int npcIndex = NPC.NewNPC(x * 16 + 16, y * 16 + 32, npcToSpawn, 0, 0f, 0f, 0f, 0f, 255); Main.npc[npcIndex].whoAmI = npcIndex; NetMessage.SendData(23, -1, -1, null, npcIndex, 0f, 0f, 0f, 0, 0, 0); Main.npc[npcIndex].BigMimicSpawnSmoke(); } return(false); }
// NPC.cs @ 56835 public static bool JungleMimicSummonCheck(int x, int y) { if (Main.netMode == NetmodeID.MultiplayerClient || !Main.hardMode) { return(false); } int num13 = Chest.FindChest(x, y); if (num13 < 0) { return(false); } int num11 = 0; int num10 = 0; for (int l = 0; l < 40; l++) { ushort num7 = Main.tile[Main.chest[num13].x, Main.chest[num13].y].type; int num6 = Main.tile[Main.chest[num13].x, Main.chest[num13].y].frameX / 36; if (TileID.Sets.BasicChest[num7] && (num7 != 21 || num6 < 5 || num6 > 6) && Main.chest[num13].item[l] != null && Main.chest[num13].item[l].type > ItemID.None) { if (Main.chest[num13].item[l].type == ItemType <KeyOfFright>()) { num11 += Main.chest[num13].item[l].stack; } else { num10++; } } } if (num10 == 0 && num11 == 1) { _ = 1; if (TileID.Sets.BasicChest[Main.tile[x, y].type]) { if (Main.tile[x, y].frameX % 36 != 0) { x--; } if (Main.tile[x, y].frameY % 36 != 0) { y--; } int number3 = Chest.FindChest(x, y); for (int k = x; k <= x + 1; k++) { for (int i = y; i <= y + 1; i++) { if (TileID.Sets.BasicChest[Main.tile[k, i].type]) { Main.tile[k, i].active(active: false); } } } for (int j = 0; j < 40; j++) { Main.chest[num13].item[j] = new Item(); } Chest.DestroyChest(x, y); int number2 = 1; if (Main.tile[x, y].type == 467) { number2 = 5; } if (Main.tile[x, y].type >= 470) { number2 = 101; } NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, number2, x, y, 0f, number3, Main.tile[x, y].type); NetMessage.SendTileSquare(-1, x, y, 3); } int num8 = NPC.NewNPC(x * 16 + 16, y * 16 + 32, NPCID.BigMimicJungle); Main.npc[num8].whoAmI = num8; NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, num8); Main.npc[num8].BigMimicSpawnSmoke(); } return(false); }
public static bool ChestItemSummonCheck(int x, int y, Mod mod) { if (Main.netMode == NetmodeID.MultiplayerClient || !Main.hardMode) { return(false); } int num = Chest.FindChest(x, y); if (num < 0) { return(false); } int numberExampleBlocks = 0; int numberOtherItems = 0; ushort tileType = Main.tile[Main.chest[num].x, Main.chest[num].y].type; int tileStyle = (int)(Main.tile[Main.chest[num].x, Main.chest[num].y].frameX / 36); if (TileID.Sets.BasicChest[tileType] && (tileStyle < 5 || tileStyle > 6)) { for (int i = 0; i < 40; i++) { if (Main.chest[num].item[i] != null && Main.chest[num].item[i].type > ItemID.None) { if (Main.chest[num].item[i].type == ModContent.ItemType <ExampleBlock>()) { numberExampleBlocks += Main.chest[num].item[i].stack; } else { numberOtherItems++; } } } } if (numberOtherItems == 0 && numberExampleBlocks == 100) { if (TileID.Sets.BasicChest[Main.tile[x, y].type]) { if (Main.tile[x, y].frameX % 36 != 0) { x--; } if (Main.tile[x, y].frameY % 36 != 0) { y--; } int number = Chest.FindChest(x, y); for (int j = x; j <= x + 1; j++) { for (int k = y; k <= y + 1; k++) { if (TileID.Sets.BasicChest[Main.tile[j, k].type]) { Main.tile[j, k].active(false); } } } for (int l = 0; l < 40; l++) { Main.chest[num].item[l] = new Item(); } Chest.DestroyChest(x, y); NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, 1, (float)x, (float)y, 0f, number, 0, 0); NetMessage.SendTileSquare(-1, x, y, 3); } int npcToSpawn = ModContent.NPCType <PartyZombie>(); int npcIndex = NPC.NewNPC(x * 16 + 16, y * 16 + 32, npcToSpawn, 0, 0f, 0f, 0f, 0f, 255); Main.npc[npcIndex].whoAmI = npcIndex; NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, npcIndex, 0f, 0f, 0f, 0, 0, 0); Main.npc[npcIndex].BigMimicSpawnSmoke(); } return(false); }
public void Paste() { var clipboardPath = Tools.GetClipboardPath(plr.User.ID); var data = Tools.LoadWorldData(clipboardPath); var width = data.Width - 1; var height = data.Height - 1; if ((alignment & 1) == 0) { x2 = x + width; } else { x2 = x; x -= width; } if ((alignment & 2) == 0) { y2 = y + height; } else { y2 = y; y -= height; } Tools.PrepareUndo(x, y, x2, y2, plr); for (var i = x; i <= x2; i++) { for (var j = y; j <= y2; j++) { if (i < 0 || j < 0 || i >= Main.maxTilesX || j >= Main.maxTilesY || expression != null && !expression.Evaluate(Main.tile[i, j])) { continue; } var index1 = i - x; var index2 = j - y; Main.tile[i, j] = data.Tiles[index1, index2]; } } foreach (var sign in data.Signs) { var id = Sign.ReadSign(sign.X + x, sign.Y + y); if (id == -1) { continue; } Sign.TextSign(id, sign.Text); } foreach (var itemFrame in data.ItemFrames) { var ifX = itemFrame.X + x; var ifY = itemFrame.Y + y; var id = TEItemFrame.Place(ifX, ifY); if (id == -1) { continue; } WorldGen.PlaceObject(ifX, ifY, TileID.ItemFrame); var frame = (TEItemFrame)TileEntity.ByID[id]; frame.item = new Item(); frame.item.netDefaults(itemFrame.Item.NetId); frame.item.stack = itemFrame.Item.Stack; frame.item.prefix = itemFrame.Item.PrefixId; } foreach (var chest in data.Chests) { int chestX = chest.X + x, chestY = chest.Y + y; int id; if ((id = Chest.FindChest(chestX, chestY)) == -1 && (id = Chest.CreateChest(chestX, chestY)) == -1) { continue; } WorldGen.PlaceChest(chestX, chestY); for (var index = 0; index < chest.Items.Length; index++) { var netItem = chest.Items[index]; var item = new Item(); item.netDefaults(netItem.NetId); item.stack = netItem.Stack; item.prefix = netItem.PrefixId; Main.chest[id].item[index] = item; } } ResetSection(); plr.SendSuccessMessage("Pasted clipboard to selection."); }
public override void RightClick(int i, int j) { Player player = Main.player[Main.myPlayer]; for (int num66 = 0; num66 < 58; num66++) { if (player.inventory[num66].type == mod.ItemType("SpiritChestKey") && player.inventory[num66].stack > 0) { /* player.inventory[num66].stack--; */ Chest.Unlock(i, j); Chest.Unlock(i - 1, j - 1); Chest.Unlock(i, j - 1); Chest.Unlock(i - 1, j); /* if (player.inventory[num66].stack <= 0) * { * player.inventory[num66] = new Item(); * } */ } } Tile tile = Main.tile[i, j]; if (tile.frameX != 72 && tile.frameX != 90) { Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(11, -1, -1, 1); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(12, -1, -1, 1); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(11, -1, -1, 1); } else { NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(11, -1, -1, 1); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? 10 : 12, -1, -1, 1); } Recipe.FindRecipes(); } } } }
public override bool NewRightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; bool anycursedarmor = false; for (int indexX = -70; indexX <= 70; indexX++) { for (int indexY = -90; indexY <= 90; indexY++) { if (Framing.GetTileSafely(indexX + i, indexY + j).type == mod.TileType("CursedArmor")) { WorldGen.KillTile(indexX + i, indexY + j); if (Main.netMode != NetmodeID.SinglePlayer) { NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, indexX + i, indexY + j); } anycursedarmor = true; } } } if (anycursedarmor) { CombatText.NewText(new Rectangle(i * 16, j * 16, 20, 10), Color.GreenYellow, "Trapped!"); return(true); } else if (NPC.AnyNPCs(ModContent.NPCType <Enchanted_Armor>())) { Main.PlaySound(new LegacySoundStyle(SoundID.NPCKilled, 6).WithPitchVariance(0.2f).WithVolume(0.5f), new Vector2(i * 16, j * 16)); foreach (NPC npc in Main.npc.Where(x => x.active && x.type == ModContent.NPCType <Enchanted_Armor>())) { npc.ai[1] = 30; } return(true); } Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == NetmodeID.MultiplayerClient) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } return(true); }
public bool Read(int bufferId, int start, int length) { var buffer = NetMessage.buffer[bufferId]; var player = Main.player[bufferId]; byte b7 = buffer.reader.ReadByte(); int x = (int)buffer.reader.ReadInt16(); int y = (int)buffer.reader.ReadInt16(); int type = (int)buffer.reader.ReadInt16(); if (Math.Abs(player.position.X / 16 - x) >= 7 || Math.Abs(player.position.Y / 16 - y) >= 7) { return(true); } var ctx = new HookContext { Connection = player.Connection.Socket, Player = player, Sender = player }; var args = new TDSMHookArgs.ChestBreakReceived { X = x, Y = y }; TDSMHookPoints.ChestBreakReceived.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) { return(true); } if (ctx.Result == HookResult.IGNORE) { return(true); } if (ctx.Result == HookResult.RECTIFY) { NetMessage.SendTileSquare(bufferId, x, y, 3); return(true); } if (Main.netMode == 2) { if (b7 == 0) { int num107 = WorldGen.PlaceChest(x, y, 21, false, type); if (num107 == -1) { NetMessage.SendData(34, bufferId, -1, "", (int)b7, (float)x, (float)y, (float)type, num107, 0, 0); Item.NewItem(x * 16, y * 16, 32, 32, Chest.chestItemSpawn[type], 1, true, 0, false, false); return(true); } NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, (float)type, num107, 0, 0); return(true); } else if (b7 == 2) { int num108 = WorldGen.PlaceChest(x, y, 88, false, type); if (num108 == -1) { NetMessage.SendData(34, bufferId, -1, "", (int)b7, (float)x, (float)y, (float)type, num108, 0, 0); Item.NewItem(x * 16, y * 16, 32, 32, Chest.dresserItemSpawn[type], 1, true, 0, false, false); return(true); } NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, (float)type, num108, 0, 0); return(true); } else { var tile2 = Main.tile[x, y]; if (tile2.type == 21 && b7 == 1) { if (tile2.frameX % 36 != 0) { x--; } if (tile2.frameY % 36 != 0) { y--; } int number = Chest.FindChest(x, y); WorldGen.KillTile(x, y, false, false, false); if (!tile2.active()) { NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, 0f, number, 0, 0); return(true); } return(true); } else { if (tile2.type != 88 || b7 != 3) { return(true); } x -= (int)(tile2.frameX % 54 / 18); if (tile2.frameY % 36 != 0) { y--; } int number2 = Chest.FindChest(x, y); WorldGen.KillTile(x, y, false, false, false); if (!tile2.active()) { NetMessage.SendData(34, -1, -1, "", (int)b7, (float)x, (float)y, 0f, number2, 0, 0); return(true); } return(true); } } } else { int id = (int)buffer.reader.ReadInt16(); if (b7 == 0) { if (id == -1) { WorldGen.KillTile(x, y, false, false, false); return(true); } WorldGen.PlaceChestDirect(x, y, 21, type, id); return(true); } else { if (b7 != 2) { Chest.DestroyChestDirect(x, y, id); WorldGen.KillTile(x, y, false, false, false); return(true); } if (id == -1) { WorldGen.KillTile(x, y, false, false, false); return(true); } WorldGen.PlaceDresserDirect(x, y, 88, type, id); return(true); } } }
// Straight up copy from removed `DesertMimicSummon` class. public static bool ChestItemSummonCheck(int x, int y, Mod mod) { if (Main.netMode == 1) { return(false); } int num = Chest.FindChest(x, y); if (num < 0) { return(false); } int numberDesertKey = 0; int numberJungleKey = 0; int numberOceanKey = 0; int numberOtherItems = 0; ushort tileType = Main.tile[Main.chest[num].x, Main.chest[num].y].type; int tileStyle = Main.tile[Main.chest[num].x, Main.chest[num].y].frameX / 36; if (TileID.Sets.BasicChest[tileType] && (tileStyle < 5 || tileStyle > 6)) { for (int i = 0; i < 40; i++) { if (Main.chest[num].item[i] != null && Main.chest[num].item[i].type > 0) { if (Main.chest[num].item[i].type == mod.ItemType <KeyofSands>()) { numberDesertKey += Main.chest[num].item[i].stack; } else if (Main.chest[num].item[i].type == mod.ItemType <KeyofTwilight>()) { numberJungleKey += Main.chest[num].item[i].stack; } else if (Main.chest[num].item[i].type == mod.ItemType <KeyofOcean>()) { numberOceanKey += Main.chest[num].item[i].stack; } else { numberOtherItems++; } } } } if (numberOtherItems == 0 && numberDesertKey == 1) { if (TileID.Sets.BasicChest[Main.tile[x, y].type]) { if (Main.tile[x, y].frameX % 36 != 0) { x--; } if (Main.tile[x, y].frameY % 36 != 0) { y--; } int number = Chest.FindChest(x, y); for (int j = x; j <= x + 1; j++) { for (int k = y; k <= y + 1; k++) { if (Main.tile[j, k].type == TileID.Containers) { Main.tile[j, k].active(false); } } } for (int l = 0; l < 40; l++) { Main.chest[num].item[l] = new Item(); } Chest.DestroyChest(x, y); NetMessage.SendData(34, -1, -1, null, 1, x, y, 0f, number, 0, 0); NetMessage.SendTileSquare(-1, x, y, 3); } int npcToSpawn = mod.NPCType <DesertMimic>(); int npcIndex = NPC.NewNPC(x * 16 + 16, y * 16 + 32, npcToSpawn, 0, 0f, 0f, 0f, 0f, 255); Main.npc[npcIndex].whoAmI = npcIndex; NetMessage.SendData(23, -1, -1, null, npcIndex, 0f, 0f, 0f, 0, 0, 0); Main.npc[npcIndex].BigMimicSpawnSmoke(); } else if (numberOtherItems == 0 && numberJungleKey == 1) { if (TileID.Sets.BasicChest[Main.tile[x, y].type]) { if (Main.tile[x, y].frameX % 36 != 0) { x--; } if (Main.tile[x, y].frameY % 36 != 0) { y--; } int number = Chest.FindChest(x, y); for (int j = x; j <= x + 1; j++) { for (int k = y; k <= y + 1; k++) { if (Main.tile[j, k].type == 21) { Main.tile[j, k].active(false); } } } for (int l = 0; l < 40; l++) { Main.chest[num].item[l] = new Item(); } Chest.DestroyChest(x, y); NetMessage.SendData(34, -1, -1, null, 1, x, y, 0f, number, 0, 0); NetMessage.SendTileSquare(-1, x, y, 3); } int npcToSpawn = mod.NPCType("JungleMimic"); int npcIndex = NPC.NewNPC(x * 16 + 16, y * 16 + 32, npcToSpawn, 0, 0f, 0f, 0f, 0f, 255); Main.npc[npcIndex].whoAmI = npcIndex; NetMessage.SendData(23, -1, -1, null, npcIndex, 0f, 0f, 0f, 0, 0, 0); Main.npc[npcIndex].BigMimicSpawnSmoke(); } else if (numberOtherItems == 0 && numberOceanKey == 1) { if (TileID.Sets.BasicChest[Main.tile[x, y].type]) { if (Main.tile[x, y].frameX % 36 != 0) { x--; } if (Main.tile[x, y].frameY % 36 != 0) { y--; } int number = Chest.FindChest(x, y); for (int j = x; j <= x + 1; j++) { for (int k = y; k <= y + 1; k++) { if (Main.tile[j, k].type == 21) { Main.tile[j, k].active(false); } } } for (int l = 0; l < 40; l++) { Main.chest[num].item[l] = new Item(); } Chest.DestroyChest(x, y); NetMessage.SendData(34, -1, -1, null, 1, x, y, 0f, number, 0, 0); NetMessage.SendTileSquare(-1, x, y, 3); } int npcToSpawn = mod.NPCType("OceanMimic"); int npcIndex = NPC.NewNPC(x * 16 + 16, y * 16 + 32, npcToSpawn, 0, 0f, 0f, 0f, 0f, 255); Main.npc[npcIndex].whoAmI = npcIndex; NetMessage.SendData(23, -1, -1, null, npcIndex, 0f, 0f, 0f, 0, 0, 0); Main.npc[npcIndex].BigMimicSpawnSmoke(); } return(false); }
public override void ModifyWorldGenTasks(List <GenPass> tasks, ref float totalWeight) { int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies")); if (ShiniesIndex == -1) { return; } tasks.Insert(ShiniesIndex + 4, new PassLegacy("Generating argite", delegate(GenerationProgress progress) { progress.Message = "Generating argite"; for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++) { int i2 = WorldGen.genRand.Next(0, Main.maxTilesX); int j2 = WorldGen.genRand.Next((int)(Main.maxTilesY * .3f), (int)(Main.maxTilesY * .45f)); WorldGen.OreRunner(i2, j2, WorldGen.genRand.Next(3, 4), WorldGen.genRand.Next(3, 8), (ushort)mod.TileType("ArgiteOre")); } })); tasks.Insert(ShiniesIndex + 8, new PassLegacy("Mod Biomes", delegate(GenerationProgress progress) { progress.Message = "Generating glacier..."; IL_19: int StartPositionX = WorldGen.genRand.Next(0, Main.maxTilesX - 2); int StartPositionY = (int)Main.worldSurface; int StartX = 0; int StartY = 0; int Size = 0; int[] BlockNums = { 23, 25, 147, 161, 163, 164, 200, 0, 2 }; int[] OreNums = { 6, 7, 8, 9, 221, 222, 223, 204, 166, 167, 168, 169, 107, 108, 111, 22 }; if (Main.maxTilesX == 4200 && Main.maxTilesY == 1200) { Size = 105; } if (Main.maxTilesX == 6300 && Main.maxTilesY == 1800) { Size = 198; } if (Main.maxTilesX == 8400 && Main.maxTilesY == 2400) { Size = 270; } if (Main.tile[StartPositionX, StartPositionY].type == TileID.SnowBlock) { StartX = StartPositionX; StartY = StartPositionY; StartX = StartX - 100; StartY = StartY - 100; StartY++; for (int X = StartX - Size; X <= StartX + Size; X++) { for (int Y = StartY - Size; Y <= StartY + Size; Y++) { if (Vector2.Distance(new Vector2(StartX, StartY), new Vector2(X, Y)) <= Size) { if (Main.tile[X, Y].wall == 40 || Main.tile[X, Y].wall == 71) { Main.tile[X, Y].wall = (ushort)mod.WallType("IceWall"); } if (Main.tile[X, Y].type == 23 || Main.tile[X, Y].type == 147 || Main.tile[X, Y].type == 161 || Main.tile[X, Y].type == 25 || Main.tile[X, Y].type == 163 || Main.tile[X, Y].type == 164 || Main.tile[X, Y].type == 200 || Main.tile[X, Y].type == 0 || Main.tile[X, Y].type == 2 || Main.tile[X, Y].type == TileID.Stone || Main.tile[X, Y].type == TileID.Sand) { Main.tile[X, Y].type = (ushort)mod.TileType("IceBlock"); } if (Main.tile[X, Y].liquid == 3) { WorldGen.PlaceTile(X, Y, 162); } if (Main.tile[X, Y].type == 6 || Main.tile[X, Y].type == 7 || Main.tile[X, Y].type == 8 || Main.tile[X, Y].type == 9 || Main.tile[X, Y].type == 221 || Main.tile[X, Y].type == 222 || Main.tile[X, Y].type == 223 || Main.tile[X, Y].type == 204 || Main.tile[X, Y].type == 166 || Main.tile[X, Y].type == 167 || Main.tile[X, Y].type == 168 || Main.tile[X, Y].type == 169 || Main.tile[X, Y].type == 221 || Main.tile[X, Y].type == 107 || Main.tile[X, Y].type == 108 || Main.tile[X, Y].type == 22 || Main.tile[X, Y].type == 111 || Main.tile[X, Y].type == 123 || Main.tile[X, Y].type == 224 || Main.tile[X, Y].type == 40 || Main.tile[X, Y].type == 59) { Main.tile[X, Y].type = (ushort)mod.TileType("IceOre"); } } } } for (int k = 0; k < 1000; k++) { int PositionX = WorldGen.genRand.Next(0, Main.maxTilesX); int PositionY = WorldGen.genRand.Next(0, Main.maxTilesY); if (Main.tile[PositionX, PositionY].type == mod.TileType("IceBlock")) { WorldGen.TileRunner(PositionX, PositionY, WorldGen.genRand.Next(2, 8), WorldGen.genRand.Next(2, 8), (ushort)mod.TileType("IceOre"), false, 0f, 0f, false, true); } } for (int k = 0; k < Main.maxTilesX; k++) { for (int i = 0; i < Main.maxTilesY; i++) { if (Main.tile[k, i].type == mod.TileType("IceBlock")) { if (Main.tile[k + 1, i].active() && Main.tile[k, i - 1].active() && Main.tile[k - 1, i].active() && Main.tile[k, i + 1].active()) { } else { Main.tile[k, i].type = (ushort)mod.TileType("VeryVeryIce"); } } } } while (!Main.tile[StartX, StartY].active() && StartY < Main.worldSurface) { StartY++; } for (int k = 0; k < 16; k++) { for (int l = 0; l < 10; l++) { WorldGen.KillTile(StartX - k, StartY - l, false, false, true); } } for (int k = 0; k < 14; k++) { for (int l = 0; l < 8; l++) { WorldGen.KillWall(StartX - 1 - k, StartY - 1 - l, false); WorldGen.PlaceWall(StartX - 1 - k, StartY - 1 - l, (ushort)mod.WallType("DungeonWall")); } } for (int k = 0; k < 15; k++) { WorldGen.PlaceTile(StartX - k, StartY, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 9; l++) { WorldGen.PlaceTile(StartX, StartY - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 9; l++) { WorldGen.PlaceTile(StartX - 15, StartY - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 15 + k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 5; k++) { WorldGen.PlaceTile(StartX - 6 - k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 2, StartY - 7 - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 3, StartY - 8 - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 4 - k, StartY - 9, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 14, StartY - 7 - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 13, StartY - 8 - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 12 + k, StartY - 9, (ushort)mod.TileType("DungeonBlock")); } WorldGen.PlaceTile(StartX + 1, StartY - 4, (ushort)mod.TileType("DungeonBlock")); WorldGen.PlaceTile(StartX - 16, StartY - 4, (ushort)mod.TileType("DungeonBlock")); WorldGen.PlaceChest(StartX - 13, StartY - 5, (ushort)mod.TileType("IceChest"), false, 2); WorldGen.PlaceChest(StartX - 7, StartY - 5, (ushort)mod.TileType("IceChest"), false, 2); //---------------- StartX = StartPositionX - 42; StartY = StartPositionY - 21; for (int k = 0; k < 16; k++) { for (int l = 0; l < 10; l++) { WorldGen.KillTile(StartX - k, StartY - l, false, false, true); } } for (int k = 0; k < 14; k++) { for (int l = 0; l < 8; l++) { WorldGen.KillWall(StartX - 1 - k, StartY - 1 - l, false); WorldGen.PlaceWall(StartX - 1 - k, StartY - 1 - l, (ushort)mod.WallType("DungeonWall")); } } for (int k = 0; k < 15; k++) { WorldGen.PlaceTile(StartX - k, StartY, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 9; l++) { WorldGen.PlaceTile(StartX, StartY - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 9; l++) { WorldGen.PlaceTile(StartX - 15, StartY - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 15 + k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 5; k++) { WorldGen.PlaceTile(StartX - 6 - k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 2, StartY - 7 - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 3, StartY - 8 - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 4 - k, StartY - 9, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 14, StartY - 7 - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 13, StartY - 8 - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 12 + k, StartY - 9, (ushort)mod.TileType("DungeonBlock")); } WorldGen.PlaceTile(StartX + 1, StartY - 4, (ushort)mod.TileType("DungeonBlock")); WorldGen.PlaceTile(StartX - 16, StartY - 4, (ushort)mod.TileType("DungeonBlock")); WorldGen.PlaceChest(StartX - 13, StartY - 5, (ushort)mod.TileType("IceChest"), false, 2); WorldGen.PlaceChest(StartX - 7, StartY - 5, (ushort)mod.TileType("IceChest"), false, 2); //------------------------- StartX = StartPositionX - 120; StartY = StartPositionY + 50; for (int k = 0; k < 16; k++) { for (int l = 0; l < 10; l++) { WorldGen.KillTile(StartX - k, StartY - l, false, false, true); } } for (int k = 0; k < 14; k++) { for (int l = 0; l < 8; l++) { WorldGen.KillWall(StartX - 1 - k, StartY - 1 - l, false); WorldGen.PlaceWall(StartX - 1 - k, StartY - 1 - l, (ushort)mod.WallType("DungeonWall")); } } for (int k = 0; k < 15; k++) { WorldGen.PlaceTile(StartX - k, StartY, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 9; l++) { WorldGen.PlaceTile(StartX, StartY - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 9; l++) { WorldGen.PlaceTile(StartX - 15, StartY - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 15 + k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 5; k++) { WorldGen.PlaceTile(StartX - 6 - k, StartY - 4, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 2, StartY - 7 - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 3, StartY - 8 - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 4 - k, StartY - 9, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 14, StartY - 7 - l, (ushort)mod.TileType("DungeonBlock")); } for (int l = 0; l < 2; l++) { WorldGen.PlaceTile(StartX - 13, StartY - 8 - l, (ushort)mod.TileType("DungeonBlock")); } for (int k = 0; k < 3; k++) { WorldGen.PlaceTile(StartX - 12 + k, StartY - 9, (ushort)mod.TileType("DungeonBlock")); } WorldGen.PlaceTile(StartX + 1, StartY - 4, (ushort)mod.TileType("DungeonBlock")); WorldGen.PlaceTile(StartX - 16, StartY - 4, (ushort)mod.TileType("DungeonBlock")); WorldGen.PlaceChest(StartX - 13, StartY - 5, (ushort)mod.TileType("IceChest"), false, 2); WorldGen.PlaceChest(StartX - 7, StartY - 5, (ushort)mod.TileType("IceChest"), false, 2); } else { goto IL_19; } })); tasks.Insert(ShiniesIndex + 10, new PassLegacy("Generating dungeon chest", delegate(GenerationProgress progress) { progress.Message = "Placing dungeon chest"; //WorldGen.PlaceChest(Main.dungeonX, Main.dungeonY - 1, (ushort)mod.TileType("IceChest"), false, 2); //int chestIndex = Chest.FindChest(Main.dungeonX, Main.dungeonY - 2); for (int C = 0; C < 2; C++) { WorldGen.PlaceChest(Main.dungeonX + WorldGen.genRand.Next(100, 1000), Main.dungeonY + WorldGen.genRand.Next(100, 1000), (ushort)mod.TileType("IceChest"), false, 2); int chestIndex = Chest.FindChest(Main.dungeonX + WorldGen.genRand.Next(100, 1000), Main.dungeonY + WorldGen.genRand.Next(100, 1000)); } })); }
public override void RightClick(int i, int j) { Player player = Main.player[Main.myPlayer]; if (player.showItemIcon2 == mod.ItemType("GildedKey")) { for (int a = 0; a < 58; a++) { if (player.inventory[a].type == mod.ItemType("GildedKey") && player.inventory[a].stack > 0) { Tile tile2 = Main.tile[i, j]; int left = i; int top = j; if (tile2.frameX % 36 != 0) { left--; } if (tile2.frameY != 0) { top--; } Main.tile[left, top].frameX = 0; Main.tile[left, top + 1].frameX = 0; Main.tile[left + 1, top].frameX = 18; Main.tile[left + 1, top + 1].frameX = 18; NetMessage.SendTileSquare(-1, left, top, 2, TileChangeType.None); Main.PlaySound(22, left * 16, top * 16); } } } Tile tile = Main.tile[i, j]; if (tile.frameX != 72 && tile.frameX != 90) { //thanks to Dan Yami for this code Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(SoundID.MenuOpen); } Recipe.FindRecipes(); } } } }
public static void RegenerateWorld(string path) { Task.Factory.StartNew(() => { using (var reader = new BinaryReader(new GZipStream(new FileStream(path, FileMode.Open), CompressionMode.Decompress))) { if (WorldRegeneration.Config.UseInfiniteChests) { TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/rconvchests"); System.Threading.Thread.Sleep(5000); } #region Reset Specific WorldGen Data WorldGen.SavedOreTiers.Cobalt = -1; WorldGen.SavedOreTiers.Mythril = -1; WorldGen.SavedOreTiers.Adamantite = -1; #endregion Main.worldSurface = reader.ReadDouble(); Main.rockLayer = reader.ReadDouble(); Main.dungeonX = reader.ReadInt32(); Main.dungeonY = reader.ReadInt32(); WorldGen.crimson = reader.ReadBoolean(); WorldGen.SavedOreTiers.Copper = reader.ReadInt32(); WorldGen.SavedOreTiers.Silver = reader.ReadInt32(); WorldGen.SavedOreTiers.Iron = reader.ReadInt32(); WorldGen.SavedOreTiers.Gold = reader.ReadInt32(); WorldGen.SavedOreTiers.Cobalt = reader.ReadInt32(); WorldGen.SavedOreTiers.Mythril = reader.ReadInt32(); WorldGen.SavedOreTiers.Adamantite = reader.ReadInt32(); reader.ReadInt32(); reader.ReadInt32(); int x = 0; int y = 0; int x2 = reader.ReadInt32(); int y2 = reader.ReadInt32(); for (int i = x; i <= x2; i++) { for (int j = y; j <= y2; j++) { Tile tile = reader.ReadTile(); if (i >= 0 && j >= 0 && i < Main.maxTilesX && j < Main.maxTilesY) { if (TShock.Regions.InAreaRegion(i, j).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { continue; } else { if (tile.type == 21) { WorldGen.PlaceChest(i, j, 21, false, (tile.frameX / 2) / 18); } else { Main.tile[i, j] = tile; } } } } } ResetSection(x, y, x2, y2); #region Chest Data int totalChests = reader.ReadInt32(); int chests = 0; int index = 0; if (!WorldRegeneration.Config.IgnoreChests) { for (int a = 0; a < totalChests; a++) { Chest chest = reader.ReadChest(); for (int c = index; c < Main.maxChests; c++) { if (TShock.Regions.InAreaRegion(chest.x, chest.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { break; } else if (Main.chest[c] != null && TShock.Regions.InAreaRegion(Main.chest[c].x, Main.chest[c].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { index++; continue; } else { Main.chest[Chest.FindChest(chest.x, chest.y)] = chest; index++; chests++; break; } } } } else { for (int a = 0; a < totalChests; a++) { reader.ReadChest(); } } #endregion #region Sign Data int totalSigns = reader.ReadInt32(); int signs = 0; index = 0; for (int a = 0; a < totalSigns; a++) { Sign sign = reader.ReadSign(); for (int s = index; s < Sign.maxSigns; s++) { if (TShock.Regions.InAreaRegion(sign.x, sign.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { break; } else if (Main.sign[s] != null && TShock.Regions.InAreaRegion(Main.sign[s].x, Main.sign[s].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { index++; continue; } else { Main.sign[s] = sign; index++; signs++; break; } } } #endregion #region Tile Entitity Data int totalTileEntities = reader.ReadInt32(); for (int i = 0; i < totalTileEntities; i++) { TileEntity tileEntity = TileEntity.Read(reader); for (int j = 0; j < TileEntity.MaxEntitiesPerChunk; j++) { TileEntity entityUsed; if (TileEntity.ByID.TryGetValue(j, out entityUsed)) { if (entityUsed.Position == tileEntity.Position) { break; } continue; } else { tileEntity.ID = j; TileEntity.ByID[tileEntity.ID] = tileEntity; TileEntity.ByPosition[tileEntity.Position] = tileEntity; break; } } } #endregion TSPlayer.All.SendMessage(string.Format("The world has regenerated..."), 50, 255, 130); #region WorldGen Reset Data if (WorldRegeneration.Config.ResetWorldGenStatus) { Main.hardMode = false; NPC.downedBoss1 = false; NPC.downedBoss2 = false; NPC.downedBoss3 = false; NPC.downedQueenBee = false; NPC.downedSlimeKing = false; NPC.downedMechBossAny = false; NPC.downedMechBoss1 = false; NPC.downedMechBoss2 = false; NPC.downedMechBoss3 = false; NPC.downedFishron = false; NPC.downedMartians = false; NPC.downedAncientCultist = false; NPC.downedMoonlord = false; NPC.downedHalloweenKing = false; NPC.downedHalloweenTree = false; NPC.downedChristmasIceQueen = false; NPC.downedChristmasSantank = false; NPC.downedChristmasTree = false; NPC.downedPlantBoss = false; NPC.savedStylist = false; NPC.savedGoblin = false; NPC.savedWizard = false; NPC.savedMech = false; NPC.downedGoblins = false; NPC.downedClown = false; NPC.downedFrost = false; NPC.downedPirates = false; NPC.savedAngler = false; NPC.downedMartians = false; NPC.downedGolemBoss = false; NPC.savedTaxCollector = false; WorldGen.shadowOrbSmashed = false; WorldGen.altarCount = 0; WorldGen.shadowOrbCount = 0; } #endregion if (WorldRegeneration.Config.UseInfiniteChests) { TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/convchests"); System.Threading.Thread.Sleep(10000); TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/prunechests"); } } }); }
public override bool NewRightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == NetmodeID.MultiplayerClient && player.HeldItem.GetGlobalItem <KeyItem>().IsKeybrand) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else if (player.HeldItem.GetGlobalItem <KeyItem>().IsKeybrand) { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuTick : SoundID.MenuOpen); } Recipe.FindRecipes(); } } return(true); }
public override void Process(int whoAmI, byte[] readBuffer, int length, int num) { byte method = ReadByte(readBuffer); int x = (int)ReadInt16(readBuffer); int y = (int)ReadInt16(readBuffer); int type = (int)ReadInt16(readBuffer); var player = Main.player[whoAmI]; var ctx = new HookContext { Connection = player.Connection, Player = player, Sender = player, }; var args = new HookArgs.ChestBreakReceived { X = x, Y = y }; HookPoints.ChestBreakReceived.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) { return; } if (ctx.Result == HookResult.IGNORE) { return; } if (ctx.Result == HookResult.RECTIFY) { NewNetMessage.SendTileSquare(whoAmI, x, y, 3); return; } { if (method == 0) { int num92 = WorldGen.PlaceChest(x, y, 21, false, type); if (num92 == -1) { NewNetMessage.SendData(34, whoAmI, -1, String.Empty, (int)method, (float)x, (float)y, (float)type, num92); Item.NewItem(x * 16, y * 16, 32, 32, Chest.itemSpawn[type], 1, true, 0, false); return; } NewNetMessage.SendData(34, -1, -1, String.Empty, (int)method, (float)x, (float)y, (float)type, num92); return; } else { Tile tile2 = Main.tile[x, y]; if (tile2.type != 21) { return; } if (tile2.frameX % 36 != 0) { x--; } if (tile2.frameY % 36 != 0) { y--; } int number = Chest.FindChest(x, y); WorldGen.KillTile(x, y, false, false, false); if (!tile2.active()) { NewNetMessage.SendData(34, -1, -1, String.Empty, (int)method, (float)x, (float)y, 0f, number); return; } return; } } }
public override void RightClick(int i, int j) { Player player = Main.player[Main.myPlayer]; if (player.showItemIcon2 == mod.ItemType("RuinKey")) { for (int num66 = 0; num66 < 58; num66++) { if (player.inventory[num66].type == mod.ItemType("RuinKey") && player.inventory[num66].stack > 0) { NPC.NewNPC((int)player.Center.X + XOffset, (int)player.Center.Y + YOffset, mod.NPCType("RuinGhost1")); NPC.NewNPC((int)player.Center.X + XOffset, (int)player.Center.Y - YOffset, mod.NPCType("RuinGhost1")); NPC.NewNPC((int)player.Center.X - XOffset, (int)player.Center.Y + YOffset, mod.NPCType("RuinGhost1")); NPC.NewNPC((int)player.Center.X - XOffset, (int)player.Center.Y - YOffset, mod.NPCType("RuinGhost1")); player.inventory[num66].stack--; Chest.Unlock(i, j); Chest.Unlock(i - 1, j - 1); Chest.Unlock(i, j - 1); Chest.Unlock(i - 1, j); } } } Tile tile = Main.tile[i, j]; if (tile.frameX != 72 && tile.frameX != 90) { Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { //NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } } }
internal static void DestroyChest(int x, int y) => DestroyChest(Chest.FindChest(x, y), x, y);
public static void LoadWorldSection(WorldSectionData Data, int?X = null, int?Y = null, bool Tiles = true) { int x = (X ?? Data.X), y = (Y ?? Data.Y); if (Tiles) { for (var i = 0; i < Data.Width; i++) { for (var j = 0; j < Data.Height; j++) { int _x = i + x, _y = j + y; if (!InMapBoundaries(_x, _y)) { continue; } Main.tile[_x, _y] = Data.Tiles[i, j]; Main.tile[_x, _y].skipLiquid(true); } } } ClearObjects(x, y, x + Data.Width, y + Data.Height); foreach (var sign in Data.Signs) { var id = Sign.ReadSign(sign.X + x, sign.Y + y); if ((id == -1) || !InMapBoundaries(sign.X, sign.Y)) { continue; } Sign.TextSign(id, sign.Text); } foreach (var itemFrame in Data.ItemFrames) { var id = TEItemFrame.Place(itemFrame.X + x, itemFrame.Y + y); if (id == -1) { continue; } var frame = (TEItemFrame)TileEntity.ByID[id]; if (!InMapBoundaries(frame.Position.X, frame.Position.Y)) { continue; } frame.item = new Item(); frame.item.netDefaults(itemFrame.Item.NetId); frame.item.stack = itemFrame.Item.Stack; frame.item.prefix = itemFrame.Item.PrefixId; } foreach (var chest in Data.Chests) { int chestX = chest.X + x, chestY = chest.Y + y; int id; if ((id = Chest.FindChest(chestX, chestY)) == -1 && (id = Chest.CreateChest(chestX, chestY)) == -1) { continue; } Chest _chest = Main.chest[id]; if (!InMapBoundaries(chest.X, chest.Y)) { continue; } for (var index = 0; index < chest.Items.Length; index++) { var netItem = chest.Items[index]; var item = new Item(); item.netDefaults(netItem.NetId); item.stack = netItem.Stack; item.prefix = netItem.PrefixId; Main.chest[id].item[index] = item; } } foreach (var logicSensor in Data.LogicSensors) { var id = TELogicSensor.Place(logicSensor.X + x, logicSensor.Y + y); if (id == -1) { continue; } var sensor = (TELogicSensor)TileEntity.ByID[id]; if (!InMapBoundaries(sensor.Position.X, sensor.Position.Y)) { continue; } sensor.logicCheck = logicSensor.Type; } foreach (var trainingDummy in Data.TrainingDummies) { var id = TETrainingDummy.Place(trainingDummy.X + x, trainingDummy.Y + y); if (id == -1) { continue; } var dummy = (TETrainingDummy)TileEntity.ByID[id]; if (!InMapBoundaries(dummy.Position.X, dummy.Position.Y)) { continue; } dummy.npc = -1; } ResetSection(x, y, x + Data.Width, y + Data.Height); }
public override bool NewRightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } bool isLocked = IsLockedChest(left, top); if (Main.netMode == NetmodeID.MultiplayerClient && !isLocked) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { if (isLocked) { int key = ModContent.ItemType <Items.HbjbjbChestKey>(); if (player.ConsumeItem(key) && Chest.Unlock(left, top)) { if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.Unlock, -1, -1, null, player.whoAmI, 1f, (float)left, (float)top); } } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } } return(true); }
public static void OpenChestUI(int i, int j) { Player player = Main.player[Main.myPlayer]; Tile tile = Main.tile[i, j]; Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(11, -1, -1, 1); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(12, -1, -1, 1); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == NetmodeID.MultiplayerClient) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(11, -1, -1, 1); } else { NetMessage.SendData(31, -1, -1, NetworkText.FromLiteral(""), left, top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(11, -1, -1, 1); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? 10 : 12, -1, -1, 1); } Recipe.FindRecipes(); } } }
public override void RightClick(int i, int j) { Player player = Main.LocalPlayer; if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 0) { Main.CancelClothesWindow(true); Main.mouseRightRelease = false; int left = Main.tile[Player.tileTargetX, Player.tileTargetY].frameX / 18; left %= 3; left = Player.tileTargetX - left; int top = Player.tileTargetY - Main.tile[Player.tileTargetX, Player.tileTargetY].frameY / 18; if (player.sign > -1) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = string.Empty; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = string.Empty; } if (player.editedChestName) { //NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest != -1) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { player.flyingPigChest = -1; int num213 = Chest.FindChest(left, top); if (num213 != -1) { Main.stackSplit = 600; if (num213 == player.chest) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else if (num213 != player.chest && player.chest == -1) { player.chest = num213; Main.playerInventory = true; Main.recBigList = false; Main.PlaySound(SoundID.MenuOpen); player.chestX = left; player.chestY = top; } else { player.chest = num213; Main.playerInventory = true; Main.recBigList = false; Main.PlaySound(SoundID.MenuTick); player.chestX = left; player.chestY = top; } Recipe.FindRecipes(); } } } else { Main.playerInventory = false; player.chest = -1; Recipe.FindRecipes(); Main.dresserX = Player.tileTargetX; Main.dresserY = Player.tileTargetY; Main.OpenClothesWindow(); } }
public void ProcessTile(ITile tile, int x, int y) { Tiles[x, y] = tile; if (!tile.active()) { return; } var actualX = x + X; var actualY = y + Y; switch (tile.type) { case TileID.Signs: case TileID.AnnouncementBox: case TileID.Tombstones: if (tile.frameX % 36 == 0 && tile.frameY == 0) { var id = Sign.ReadSign(actualX, actualY, false); if (id != -1) { Signs.Add(new SignData { Text = Main.sign[id].text, X = x, Y = y }); } } break; case TileID.ItemFrame: if (tile.frameX % 36 == 0 && tile.frameY == 0) { var id = TEItemFrame.Find(actualX, actualY); if (id != -1) { var frame = (TEItemFrame)TileEntity.ByID[id]; ItemFrames.Add(new ItemFrameData { Item = new NetItem(frame.item.netID, frame.item.stack, frame.item.prefix), X = x, Y = y }); } } break; case TileID.Containers: case TileID.Dressers: if (tile.frameX % 36 == 0 && tile.frameY == 0) { var id = Chest.FindChest(actualX, actualY); if (id != -1) { var chest = Main.chest[id]; if (chest.item != null) { var items = chest.item.Select(item => new NetItem(item.netID, item.stack, item.prefix)).ToArray(); Chests.Add(new ChestData { Items = items, X = x, Y = y }); } } } break; } }
/// <returns> /// A <c>bool</c> which is <c>false</c> if a refill chest already existed at the given location and thus just its refill /// time was set or <c>true</c> if a new refill chest was actually defined. /// </returns> public bool SetUpRefillChest( TSPlayer player, DPoint tileLocation, TimeSpan?refillTime, bool?oneLootPerPlayer = null, int?lootLimit = null, bool?autoLock = null, bool?autoEmpty = null, bool checkPermissions = false ) { Contract.Requires <ArgumentNullException>(player != null); Contract.Requires <ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation"); Contract.Requires <ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation"); Contract.Requires <ArgumentOutOfRangeException>(lootLimit == null || lootLimit >= -1); Tile tile = TerrariaUtils.Tiles[tileLocation]; BlockType blockType = (BlockType)tile.type; if (blockType != BlockType.Chest) { throw new InvalidBlockTypeException(blockType); } if (checkPermissions && !player.Group.HasPermission(ProtectorPlugin.SetRefillChests_Permission)) { throw new MissingPermissionException(ProtectorPlugin.SetRefillChests_Permission); } DPoint chestLocation = TerrariaUtils.Tiles.MeasureObject(tileLocation).OriginTileLocation; ProtectionEntry protection; lock (this.WorldMetadata.Protections) if (!this.WorldMetadata.Protections.TryGetValue(chestLocation, out protection)) { throw new NoProtectionException(chestLocation); } if ( !player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission) && !this.CheckBlockAccess(player, chestLocation, true) ) { throw new TileProtectedException(chestLocation); } if (protection.BankChestKey != BankChestDataKey.Invalid) { throw new ChestIncompatibilityException(); } RefillChestMetadata refillChestData; if (protection.RefillChestData != null) { refillChestData = protection.RefillChestData; if (refillTime != null) { refillChestData.RefillTimer.TimeSpan = refillTime.Value; } if (oneLootPerPlayer != null) { refillChestData.OneLootPerPlayer = oneLootPerPlayer.Value; } if (lootLimit != null) { refillChestData.RemainingLoots = lootLimit.Value; } if (autoLock != null) { refillChestData.AutoLock = autoLock.Value; } if (autoEmpty != null) { refillChestData.AutoEmpty = autoEmpty.Value; } if (refillChestData.OneLootPerPlayer || refillChestData.RemainingLoots > 0) { if (refillChestData.Looters == null) { refillChestData.Looters = new Collection <int>(); } else { refillChestData.Looters = null; } } lock (this.RefillTimers) if (this.RefillTimers.IsTimerRunning(refillChestData.RefillTimer)) { this.RefillTimers.RemoveTimer(refillChestData.RefillTimer); } return(false); } int tChestIndex = Chest.FindChest(chestLocation.X, chestLocation.Y); if (tChestIndex == -1 || Main.chest[tChestIndex] == null) { throw new NoChestDataException(chestLocation); } TimeSpan actualRefillTime = TimeSpan.Zero; if (refillTime != null) { actualRefillTime = refillTime.Value; } refillChestData = new RefillChestMetadata(player.UserID); refillChestData.RefillTimer = new Timer(actualRefillTime, refillChestData, this.RefillTimerCallbackHandler); if (oneLootPerPlayer != null) { refillChestData.OneLootPerPlayer = oneLootPerPlayer.Value; } if (lootLimit != null) { refillChestData.RemainingLoots = lootLimit.Value; } if (refillChestData.OneLootPerPlayer || refillChestData.RemainingLoots > 0) { refillChestData.Looters = new Collection <int>(); } else { refillChestData.Looters = null; } if (autoLock != null) { refillChestData.AutoLock = autoLock.Value; } if (autoEmpty != null) { refillChestData.AutoEmpty = autoEmpty.Value; } Chest tChest = Main.chest[tChestIndex]; for (int i = 0; i < Chest.maxItems; i++) { refillChestData.RefillItems[i] = ItemData.FromItem(tChest.item[i]); } protection.RefillChestData = refillChestData; return(true); }
private static string GetTileName(string text, Point point, Tile tile) { int mapX = point.X; int mapY = point.Y; int type = Main.Map[mapX, mapY].Type; int containersLU = MapHelper.tileLookup[TileID.Containers]; int fakeContainersLU = MapHelper.tileLookup[TileID.FakeContainers]; int containersCounts = MapHelper.tileOptionCounts[TileID.Containers]; int containers2LU = MapHelper.tileLookup[TileID.Containers2]; int fakeContainers2LU = MapHelper.tileLookup[TileID.FakeContainers2]; int containers2Counts = MapHelper.tileOptionCounts[TileID.Containers2]; int dressersLU = MapHelper.tileLookup[TileID.Dressers]; int dressersCounts = MapHelper.tileOptionCounts[TileID.Dressers]; LocalizedText[] chestType = Lang.chestType; LocalizedText[] chestType2 = Lang.chestType2; if (type >= containersLU && type < containersLU + containersCounts) { int num101 = mapX; int num102 = mapY; if (tile.frameX % 36 != 0) { num101--; } if (tile.frameY % 36 != 0) { num102--; } text = DrawMap_FindChestName(chestType, tile, num101, num102); } else if (type >= containers2LU && type < containers2LU + containers2Counts) { int num103 = mapX; int num104 = mapY; if (tile.frameX % 36 != 0) { num103--; } if (tile.frameY % 36 != 0) { num104--; } text = DrawMap_FindChestName(chestType2, tile, num103, num104); } else if (type >= fakeContainersLU && type < fakeContainersLU + containersCounts) { int num105 = mapX; int num106 = mapY; if (tile.frameX % 36 != 0) { num105--; } if (tile.frameY % 36 != 0) { num106--; } text = chestType[tile.frameX / 36].Value; } else if (type >= fakeContainers2LU && type < fakeContainers2LU + containers2Counts) { int num107 = mapX; int num108 = mapY; if (tile.frameX % 36 != 0) { num107--; } if (tile.frameY % 36 != 0) { num108--; } text = chestType2[tile.frameX / 36].Value; } else if (type >= dressersLU && type < dressersLU + dressersCounts) { //patch file: num91, num92 Tile tile5 = Main.tile[mapX, mapY]; if (tile5 != null) { int num109 = mapY; int x2 = mapX - tile5.frameX % 54 / 18; if (tile5.frameY % 36 != 0) { num109--; } int num110 = Chest.FindChest(x2, num109); text = ((num110 < 0) ? Lang.dresserType[0].Value : ((!(Main.chest[num110].name != "")) ? Lang.dresserType[tile5.frameX / 54].Value : (Lang.dresserType[tile5.frameX / 54].Value + ": " + Main.chest[num110].name))); } } else { text = Lang._mapLegendCache.FromTile(Main.Map[mapX, mapY], mapX, mapY); } return(text); }
public void EnsureProtectionData( out int invalidProtectionsCount, out int invalidRefillChestCount, out int invalidBankChestCount ) { invalidRefillChestCount = 0; invalidBankChestCount = 0; lock (this.WorldMetadata.Protections) { List <DPoint> invalidProtectionLocations = new List <DPoint>(); foreach (KeyValuePair <DPoint, ProtectionEntry> protectionPair in this.WorldMetadata.Protections) { DPoint location = protectionPair.Key; ProtectionEntry protection = protectionPair.Value; Tile tile = TerrariaUtils.Tiles[location]; if (!tile.active() || (BlockType)tile.type != protection.BlockType) { invalidProtectionLocations.Add(location); continue; } if (protection.RefillChestData != null) { int tChestIndex = Chest.FindChest(location.X, location.Y); if (!tile.active() || tile.type != (int)BlockType.Chest || tChestIndex == -1) { protection.RefillChestData = null; invalidRefillChestCount++; continue; } protection.RefillChestData.RefillTimer.Data = protection.RefillChestData; protection.RefillChestData.RefillTimer.Callback = this.RefillTimerCallbackHandler; this.RefillTimers.ContinueTimer(protection.RefillChestData.RefillTimer); } if (protection.BankChestKey != BankChestDataKey.Invalid) { BankChestMetadata bankChest = this.ServerMetadataHandler.EnqueueGetBankChestMetadata(protection.BankChestKey).Result; if (bankChest == null) { protection.BankChestKey = BankChestDataKey.Invalid; invalidBankChestCount++; continue; } int tChestIndex = Chest.FindChest(location.X, location.Y); if (!tile.active() || tile.type != (int)BlockType.Chest || tChestIndex == -1) { protection.BankChestKey = BankChestDataKey.Invalid; invalidBankChestCount++; continue; } Chest tChest = Main.chest[tChestIndex]; for (int i = 0; i < Chest.maxItems; i++) { tChest.item[i] = bankChest.Items[i].ToItem(); } } } foreach (DPoint invalidProtectionLocation in invalidProtectionLocations) { this.WorldMetadata.Protections.Remove(invalidProtectionLocation); } invalidProtectionsCount = invalidProtectionLocations.Count; } }
public static void LoadWorldSection(string path, Rectangle rect, bool useRect = false) { Task.Factory.StartNew(() => { using (var reader = new BinaryReader(new GZipStream(new FileStream(path, FileMode.Open), CompressionMode.Decompress))) { if (WorldRegeneration.Config.UseInfiniteChests) { TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/rconvchests"); System.Threading.Thread.Sleep(5000); } Main.worldSurface = reader.ReadDouble(); Main.rockLayer = reader.ReadDouble(); Main.dungeonX = reader.ReadInt32(); Main.dungeonY = reader.ReadInt32(); WorldGen.crimson = reader.ReadBoolean(); WorldGen.SavedOreTiers.Copper = reader.ReadInt32(); WorldGen.SavedOreTiers.Silver = reader.ReadInt32(); WorldGen.SavedOreTiers.Iron = reader.ReadInt32(); WorldGen.SavedOreTiers.Gold = reader.ReadInt32(); WorldGen.SavedOreTiers.Cobalt = reader.ReadInt32(); WorldGen.SavedOreTiers.Mythril = reader.ReadInt32(); WorldGen.SavedOreTiers.Adamantite = reader.ReadInt32(); reader.ReadInt32(); reader.ReadInt32(); int x = 0; int y = 0; int x2 = reader.ReadInt32(); int y2 = reader.ReadInt32(); for (int i = x; i <= x2; i++) { for (int j = y; j <= y2; j++) { Tile tile = reader.ReadTile(); if (i >= 0 && j >= 0 && i < Main.maxTilesX && j < Main.maxTilesY) { if (TShock.Regions.InAreaRegion(i, j).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { continue; } else if (useRect) { if (rect.Contains(i, j)) { if (tile.type == 21) { WorldGen.PlaceChest(i, j, 21, false, (tile.frameX / 2) / 18); } else { Main.tile[i, j] = tile; } } else { continue; } } else { if (tile.type == 21) { WorldGen.PlaceChest(i, j, 21, false, (tile.frameX / 2) / 18); } else { Main.tile[i, j] = tile; // Paste Tiles } } } } } ResetSection(x, y, x2, y2); TSPlayer.All.SendInfoMessage("Tile Data Loaded..."); if (useRect) { return; } #region Chest Data int totalChests = reader.ReadInt32(); int chests = 0; int index = 0; if (!WorldRegeneration.Config.IgnoreChests) { for (int a = 0; a < totalChests; a++) { Chest chest = reader.ReadChest(); for (int c = index; c < Main.maxChests; c++) { if (TShock.Regions.InAreaRegion(chest.x, chest.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { break; } else if (Main.chest[c] != null && TShock.Regions.InAreaRegion(Main.chest[c].x, Main.chest[c].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { index++; continue; } else { Main.chest[Chest.FindChest(chest.x, chest.y)] = chest; index++; chests++; break; } } } TSPlayer.All.SendInfoMessage("{0} of {1} Chest Data Loaded...", chests, totalChests); } else { for (int a = 0; a < totalChests; a++) { reader.ReadChest(); } TSPlayer.All.SendInfoMessage("{0} Chest Data Ignored...", totalChests); } #endregion #region Sign Data int totalSigns = reader.ReadInt32(); int signs = 0; index = 0; for (int a = 0; a < totalSigns; a++) { Sign sign = reader.ReadSign(); for (int s = index; s < Sign.maxSigns; s++) { if (TShock.Regions.InAreaRegion(sign.x, sign.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { break; } else if (Main.sign[s] != null && TShock.Regions.InAreaRegion(Main.sign[s].x, Main.sign[s].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion)) { index++; continue; } else { Main.sign[s] = sign; index++; signs++; break; } } } TSPlayer.All.SendInfoMessage("{0} of {1} Signs Data Loaded...", signs, totalSigns); #endregion #region Tile Entitity Data int totalTileEntities = reader.ReadInt32(); int num1 = 0; for (int i = 0; i < totalTileEntities; i++) { TileEntity tileEntity = TileEntity.Read(reader); for (int j = 0; j < TileEntity.MaxEntitiesPerChunk; j++) { TileEntity entityUsed; if (TileEntity.ByID.TryGetValue(j, out entityUsed)) { if (entityUsed.Position == tileEntity.Position) { break; } continue; } else { tileEntity.ID = j; TileEntity.ByID[tileEntity.ID] = tileEntity; TileEntity.ByPosition[tileEntity.Position] = tileEntity; TileEntity.TileEntitiesNextID = j++; num1++; break; } } } TSPlayer.All.SendInfoMessage("{0} of {1} Tile Entity Data Loaded...", num1, totalTileEntities); if (WorldRegeneration.Config.UseInfiniteChests) { TSPlayer.All.SendInfoMessage("Using InfiniteChests Commands..."); TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/convchests"); System.Threading.Thread.Sleep(5000); TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/prunechests,"); } TSPlayer.All.SendInfoMessage("Successfully regenerated the world."); #endregion } }); }
public override void RightClick(int i, int j) { Player player = Main.player[Main.myPlayer]; if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 0) { Main.CancelClothesWindow(true); Main.mouseRightRelease = false; int left = Main.tile[Player.tileTargetX, Player.tileTargetY].frameX / 18; left %= 3; left = Player.tileTargetX - left; int top = Player.tileTargetY - Main.tile[Player.tileTargetX, Player.tileTargetY].frameY / 18; if (player.sign > -1) { Main.PlaySound(11, -1, -1, 1); player.sign = -1; Main.editSign = false; Main.npcChatText = string.Empty; } if (Main.editChest) { Main.PlaySound(12, -1, -1, 1); Main.editChest = false; Main.npcChatText = string.Empty; } if (player.editedChestName) { player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest != -1) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(11, -1, -1, 1); } else { Main.stackSplit = 600; } } else { player.flyingPigChest = -1; int num213 = Chest.FindChest(left, top); if (num213 != -1) { Main.stackSplit = 600; if (num213 == player.chest) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(11, -1, -1, 1); } else if (num213 != player.chest && player.chest == -1) { player.chest = num213; Main.playerInventory = true; Main.recBigList = false; Main.PlaySound(10, -1, -1, 1); player.chestX = left; player.chestY = top; } else { player.chest = num213; Main.playerInventory = true; Main.recBigList = false; Main.PlaySound(12, -1, -1, 1); player.chestX = left; player.chestY = top; } Recipe.FindRecipes(); } } } else { Main.playerInventory = false; player.chest = -1; Recipe.FindRecipes(); Main.dresserX = Player.tileTargetX; Main.dresserY = Player.tileTargetY; Main.OpenClothesWindow(); } }
public override void RightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } Item item = player.inventory[player.selectedItem]; if (item.type == mod.ItemType("AutoPickerController")) { Items.AutoPickerController autoPickerController = (Items.AutoPickerController)item.modItem; if (autoPickerController.topLeft.X != -1 && autoPickerController.topLeft.Y != -1) { player.tileInteractionHappened = true; topLeftPicker = Common.AutoStacker.GetOrigin(Player.tileTargetX, Player.tileTargetY); topLeftRecever = autoPickerController.topLeft; picker = new Point16((short)topLeftPicker.X <topLeftRecever.X ? topLeftPicker.X + 3 : topLeftPicker.X - 2, (short)topLeftPicker.Y> topLeftRecever.Y ? topLeftRecever.Y + 2 : topLeftPicker.Y + 2); direction = topLeftPicker.X < topLeftRecever.X ? 1:-1; Main.NewText("Auto Picker Selected to x:" + picker.X + ", y:" + picker.Y + " !"); } else { Main.NewText("Select Reciever Chest before Select Auto Picker!"); } } else { if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } } }