public override void Load(TagCompound tag) { try { int value = tag.GetInt("value"); if (value > 0) { loadedValue = value; Point position = new Point(tag.GetInt("x"), tag.GetInt("y")); Item[] deathInventory = new Item[player.inventory.Length]; Item[] deathArmor = new Item[player.armor.Length]; Item[] deathDye = new Item[player.dye.Length]; Item[] deathMiscEquips = new Item[player.miscEquips.Length]; Item[] deathMiscDyes = new Item[player.miscDyes.Length]; loadItemList(tag.Get <List <Item> >("deathInventory"), deathInventory); loadItemList(tag.Get <List <Item> >("deathArmor"), deathArmor); loadItemList(tag.Get <List <Item> >("deathDye"), deathDye); loadItemList(tag.Get <List <Item> >("deathMiscEquips"), deathMiscEquips); loadItemList(tag.Get <List <Item> >("deathMiscDyes"), deathMiscDyes); PlayerDeathInventory inventory = new PlayerDeathInventory(deathInventory, deathArmor, deathDye, deathMiscEquips, deathMiscDyes); playerDeathInventoryMap.Add(position, inventory); } } catch (Exception e) { mod.Logger.Error("Error loading saved tombstone inventory " + e.Message); } }
public override void OnEnterWorld(Player player) { if (playerDeathInventoryMap.Count > 0) { foreach (KeyValuePair <Point, PlayerDeathInventory> entry in playerDeathInventoryMap) { PlayerDeathInventory inventory = entry.Value; Main.NewText("Loaded inventory in tombstone at " + pointToText(entry.Key) + ", valued " + Main.ValueToCoins(loadedValue), 155, 155, 255); } } }
public override TagCompound Save() { int maxValue = 0; Point position = new Point(); PlayerDeathInventory mostValuableDeath = null; foreach (KeyValuePair <Point, PlayerDeathInventory> entry in playerDeathInventoryMap) { int value = entry.Value.getValue(); if (value > maxValue) { maxValue = value; position.X = entry.Key.X; position.Y = entry.Key.Y; mostValuableDeath = entry.Value; } } if (mostValuableDeath == null) { return(null); } mod.Logger.Info("Saving inventory in tombstone at " + position.X + ", " + position.Y + ", valued at " + maxValue); List <Item> deathInventory = new List <Item>(mostValuableDeath.deathInventory); List <Item> deathArmor = new List <Item>(mostValuableDeath.deathArmor); List <Item> deathDye = new List <Item>(mostValuableDeath.deathDye); List <Item> deathMiscEquips = new List <Item>(mostValuableDeath.deathMiscEquips); List <Item> deathMiscDyes = new List <Item>(mostValuableDeath.deathMiscDyes); nullEmptyItems(deathInventory); nullEmptyItems(deathArmor); nullEmptyItems(deathDye); nullEmptyItems(deathMiscEquips); nullEmptyItems(deathMiscDyes); TagCompound tag = new TagCompound(); tag.Add("x", position.X); tag.Add("y", position.Y); tag.Add("value", maxValue); tag.Add("deathInventory", deathInventory); tag.Add("deathArmor", deathArmor); tag.Add("deathDye", deathDye); tag.Add("deathMiscEquips", deathMiscEquips); tag.Add("deathMiscDyes", deathMiscDyes); return(tag); }
//TODO network sync removed gravestone public override void RightClick(int i, int j, int type) { if (type == TileID.Tombstones) { //Get player id and give him his shit bacK Player player = Main.player[Main.myPlayer]; //mod.Logger.Warn("Player ID: " + Main.myPlayer + " " + player.name + " Tried to click on tombstone coordinates: " + i + ", " + j); //ASUMING i and j are x and y coordinates I can do some stuff //Need to check each tile at + and - 1 because the tile is 2x2, but the projectile will only save a single tile coordinate Point[] tombStonePositions = new Point[9]; tombStonePositions[0] = new Point(i, j); tombStonePositions[1] = new Point(i, j + 1); tombStonePositions[2] = new Point(i, j - 1); tombStonePositions[3] = new Point(i + 1, j); tombStonePositions[4] = new Point(i + 1, j + 1); tombStonePositions[5] = new Point(i + 1, j - 1); tombStonePositions[6] = new Point(i - 1, j); tombStonePositions[7] = new Point(i - 1, j + 1); tombStonePositions[8] = new Point(i - 1, j - 1); TombstonePlayer tStonePlayer = player.GetModPlayer <TombstonePlayer>(); Dictionary <Point, PlayerDeathInventory> playerDeathInventoryMap = tStonePlayer.playerDeathInventoryMap; PlayerDeathInventory playerDeathInventory = null; //loop through the 9 tile list for (int pos = 0; pos < tombStonePositions.Length; pos++) { if (playerDeathInventoryMap.TryGetValue(tombStonePositions[pos], out playerDeathInventory)) { //found the player's death inventory, give it to the player who clicked on it //Player player = Main.player[playerId]; //First cause player to drop all items carried, then apply the items straight to his inventory player.DropItems(); //INVENTORY for (int c = 0; c < playerDeathInventory.deathInventory.Length; c++) { //put inventory into separate list player.inventory[c] = playerDeathInventory.deathInventory[c]; } //ARMOR - SOCIAL for (int c = 0; c < playerDeathInventory.deathArmor.Length; c++) { //put armor into separate list player.armor[c] = playerDeathInventory.deathArmor[c]; } //DYES for (int c = 0; c < playerDeathInventory.deathDye.Length; c++) { //put dye into separate list player.dye[c] = playerDeathInventory.deathDye[c]; } //EQUIPMENT for (int c = 0; c < playerDeathInventory.deathMiscEquips.Length; c++) { //put equipment into separate list player.miscEquips[c] = playerDeathInventory.deathMiscEquips[c]; } //EQUIPMENT - DYE for (int c = 0; c < playerDeathInventory.deathMiscDyes.Length; c++) { //put equipment dye into separate list player.miscDyes[c] = playerDeathInventory.deathMiscDyes[c]; } //delete existing player inventory at that spot playerDeathInventoryMap.Remove(tombStonePositions[pos]); WorldGen.KillTile(tombStonePositions[pos].X, tombStonePositions[pos].Y); if (Main.netMode != NetmodeID.SinglePlayer) { //TombstoneDeathMod myMod = (TombstoneDeathMod) mod; //myMod.Send(-1, Main.myPlayer, tombStonePositions[pos].X, tombStonePositions[pos].Y); Send(-1, Main.myPlayer, tombStonePositions[pos].X, tombStonePositions[pos].Y); } break; } } } }
//public override bool PreKill(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource) //{ //} public override void Kill(double damage, int hitDirection, bool pvp, PlayerDeathReason damageSource) { Point playerPosition = player.position.ToTileCoordinates(); int x = playerPosition.X; int y = playerPosition.Y + 4; int startX = x; bool isClearForTombstone = isTileCoordinateClear(x, y); // Check left and right 15 squares, then up one and repeat 15 times int movesY = 0; while (!isClearForTombstone && movesY++ < 15) { x = startX; isClearForTombstone = isTileCoordinateClear(x, y); int movesX = 0; while (!isClearForTombstone && movesX++ < 15) { x = startX - movesX; if (x < 0) { x = 0; } isClearForTombstone = isTileCoordinateClear(x, y); if (!isClearForTombstone) { x = startX + movesX; if (x > Main.maxTilesX) { x = Main.maxTilesX - 1; } isClearForTombstone = isTileCoordinateClear(x, y); } } if (!isClearForTombstone) { y--; if (y < 0) { y = 0; } } } if (!isClearForTombstone) { // Revert to normal death Main.NewText("Unable to place tombstone1. Reverting to normal death.", 255, 100, 100); base.Kill(damage, hitDirection, pvp, damageSource); return; } if (!WorldGen.PlaceTile(x, y, TileID.Tombstones, false, true, 1, 7)) { // Revert to normal death Main.NewText("Unable to place tombstone2. Reverting to normal death.", 255, 100, 100); base.Kill(damage, hitDirection, pvp, damageSource); return; } int sign = Sign.ReadSign(x, y, true); if (sign >= 0) { Sign.TextSign(sign, player.name + "'s Stuff"); } Point tombStonePosition = new Point(x, y); PlayerDeathInventory previousInventory = null; if (playerDeathInventoryMap.TryGetValue(tombStonePosition, out previousInventory)) { int oldItemValue = previousInventory.getValue(); int newItemValue = 0; for (int i = 0; i < player.inventory.Length; i++) { newItemValue += player.inventory[i].value; } for (int i = 0; i < player.armor.Length; i++) { newItemValue += player.armor[i].value; } for (int i = 0; i < player.miscEquips.Length; i++) { newItemValue += player.miscEquips[i].value; } // Remove previous inventory only if new death was more valuable if (newItemValue < oldItemValue) { Main.NewText("Previous more valuable death at same position, not overwriting. Reverting to normal death.", 255, 100, 100); base.Kill(damage, hitDirection, pvp, damageSource); return; } Main.NewText("Previous less valuable death at same position, overwriting.", 255, 100, 100); playerDeathInventoryMap.Remove(tombStonePosition); } Item[] deathInventory = new Item[player.inventory.Length]; Item[] deathArmor = new Item[player.armor.Length]; Item[] deathDye = new Item[player.dye.Length]; Item[] deathMiscEquips = new Item[player.miscEquips.Length]; Item[] deathMiscDyes = new Item[player.miscDyes.Length]; //INVENTORY for (int i = 0; i < player.inventory.Length; i++) { //put inventory into separate list deathInventory[i] = player.inventory[i]; player.inventory[i] = new Item(); } //ARMOR - SOCIAL for (int i = 0; i < player.armor.Length; i++) { //put armor into separate list deathArmor[i] = player.armor[i]; player.armor[i] = new Item(); } //DYES for (int i = 0; i < player.dye.Length; i++) { //put dye into separate list deathDye[i] = player.dye[i]; player.dye[i] = new Item(); } //EQUIPMENT for (int i = 0; i < player.miscEquips.Length; i++) { //put equipment into separate list deathMiscEquips[i] = player.miscEquips[i]; player.miscEquips[i] = new Item(); } //EQUIPMENT - DYE for (int i = 0; i < player.miscDyes.Length; i++) { //put equipment dye into separate list deathMiscDyes[i] = player.miscDyes[i]; player.miscDyes[i] = new Item(); } PlayerDeathInventory playerDeathInventory = new PlayerDeathInventory(deathInventory, deathArmor, deathDye, deathMiscEquips, deathMiscDyes); playerDeathInventoryMap.Add(tombStonePosition, playerDeathInventory); Main.NewText("Inventory saved in tombstone at " + pointToText(tombStonePosition)); base.Kill(damage, hitDirection, pvp, damageSource); }