public override void MouseOverFar(int i, int j) { // fixFrames(i, j); int x = i; int y = j; while (Main.tile[x, y].frameY % 70 != 0) { y--; } while (Main.tile[x, y].frameX % 54 != 0) { x--; } int vmID = VendingMachineWorld.GetVendingMachineFromCoordinates(x, y); if (vmID < 0) { return; } Player player = Main.player[Main.myPlayer]; if (VendingMachineWorld.vm[vmID].isItem) { Item itm = new Item(); itm.SetDefaults(SoulOfNPC.getTypeFromItemTag(VendingMachineWorld.vm[vmID].id)); if (itm.type != 0) { player.showItemIconText = itm.modItem.DisplayName.GetDefault(); } else { player.showItemIconText = "Vending Machine (Empty)"; } } else { NPC n = SoulOfNPC.getNPCfromNPCTag(VendingMachineWorld.vm[vmID].id); if (n != null && n.type != 0) { if (n.type == NPCID.SkeletonMerchant) { player.showItemIconText = "Vending Machine (Skeleton Merchant)"; } else { player.showItemIconText = "Vending Machine (" + Lang.GetNPCNameValue(n.netID) + ")"; } } else { player.showItemIconText = "Vending Machine (Empty)"; } } player.noThrow = 2; player.showItemIcon2 = -1; player.showItemIcon = true; }
public int getItemID() { if (!isItem || id == null) { return(0); } return(SoulOfNPC.getTypeFromItemTag(id)); }
public int getNPCID() { if (isItem || id == null) { return(0); } return(SoulOfNPC.getTypeFromNPCTag(id)); }
public override void KillMultiTile(int i, int j, int frameX, int frameY) { int x = i; int y = j; int vmID = VendingMachineWorld.GetVendingMachineFromCoordinates(x, y); int k = -1; if (vmID >= 0 && VendingMachineWorld.vm[vmID] != null) { string id = VendingMachineWorld.vm[vmID].Clear(); string[] idSplit = id.Split(';'); bool itm = (idSplit[0] == "Item"); id = idSplit[1]; if (Main.netMode != 1) { if (itm) { k = Item.NewItem(x * 16, y * 16, 48, 64, SoulOfNPC.getTypeFromItemTag(id), 1, false, 0, false, false); } else { k = Item.NewItem(x * 16, y * 16, 48, 64, dropID, 1, false, 0, false, false); VendingMachineItem vmi = Main.item[k].modItem as VendingMachineItem; if (vmi != null) { vmi.setNPCType(SoulOfNPC.getNPCfromNPCTag(id)); } } } } else { if (Main.netMode != 1) { k = Item.NewItem(x * 16, y * 16, 48, 64, dropID, 1, false, 0, false, false); } } if (Main.netMode == 2 && k >= 0) { NetMessage.SendData(21, -1, -1, null, k, 0f, 0f, 0f, 0, 0, 0); } if (Main.netMode != 0) { ModPacket pk = mod.GetPacket(); pk.Write((byte)2); pk.Write((short)vmID); pk.Send(); } }
public static int PlaceNewVendingMachine(int x, int y, int type, int style, int direction = 0) { try { Point16 point = new Point16(x, y); TileObjectData.OriginToTopLeft(type, style, ref point); VendingMachineItem toPlace = (Main.player[Main.myPlayer].inventory[Main.player[Main.myPlayer].selectedItem].modItem) as VendingMachineItem; if (toPlace == null) { return(399); } if (toPlace.hasShop && (toPlace.npcType == null || toPlace.npcType == "")) { toPlace.npcType = SoulOfNPC.ItemToTag(toPlace.item); } for (int i = 0; i < vm.Length; i++) { if (vm[i] != null && vm[i].x == x && vm[i].y == y) { vm[i].setDefaults(point.X, point.Y, toPlace.npcType, toPlace.hasShop); if (Main.netMode != 0) { ModPacket pk = ModLoader.GetMod("VendingMachines").GetPacket(); pk.Write((byte)1); pk.Write((short)i); TagIO.Write(vm[i].Save(), pk); pk.Send(); } return(i); } } for (int i = 0; i < vm.Length; i++) { if (vm[i] == null) { vm[i] = new VendingMachineData(); vm[i].setDefaults(point.X, point.Y, toPlace.npcType, toPlace.hasShop); if (Main.netMode != 0) { ModPacket pk = ModLoader.GetMod("VendingMachines").GetPacket(); pk.Write((byte)1); pk.Write((short)i); TagIO.Write(vm[i].Save(), pk); pk.Send(); } return(i); } else if (vm[i].isClear()) { vm[i].setDefaults(point.X, point.Y, toPlace.npcType, toPlace.hasShop); if (Main.netMode != 0) { ModPacket pk = ModLoader.GetMod("VendingMachines").GetPacket(); pk.Write((byte)1); pk.Write((short)i); TagIO.Write(vm[i].Save(), pk); pk.Send(); } return(i); } } return(399); }catch (Exception e) { Main.NewText(e.ToString()); return(399); } }
public override bool NewRightClick(int i, int j) { int x = i; int y = j; while (Main.tile[x, y].frameY % 70 != 0) { y--; } while (Main.tile[x, y].frameX % 54 != 0) { x--; } int vmID = VendingMachineWorld.GetVendingMachineFromCoordinates(x, y); if (vmID < 0) { Main.NewText("No vending Machine Found..."); return(false); } VendingMachineData vm = VendingMachineWorld.vm[vmID]; if (vm.isItem) { Main.player[Main.myPlayer].chest = -1; Main.npcChatText = ""; int type = SoulOfNPC.getTypeFromItemTag(vm.id); Item itm = new Item(); itm.SetDefaults(type); VendingMachineItem vendor = itm.modItem as VendingMachineItem; if (vendor != null) { if (vendor.replaceRightClick) { vendor.machineRightClick(vm, i, j); } else { Main.npcShop = Main.MaxShopIDs - 1; chooseTalkingNPC(vm); Main.recBigList = false; Main.playerInventory = true; Main.InGuideCraftMenu = false; Main.InReforgeMenu = false; for (int k = 0; k < InvisibleAllShopNPC.shopChest.item.Length; k++) { InvisibleAllShopNPC.shopChest.item[k] = new Item(); } vendor.SetupShop(InvisibleAllShopNPC.shopChest); Main.instance.shop[Main.npcShop].SetupShop(ModContent.NPCType <InvisibleAllShopNPC>()); } } } else { int type = SoulOfNPC.getTypeFromNPCTag(vm.id); Main.npcShop = NPCToShop(type); if (type == NPCID.TravellingMerchant) { Main.player[Main.myPlayer].chest = -1; Main.npcChatText = ""; for (int k = 0; k < 40; k++) { if (Main.instance.shop[Main.npcShop].item[k] == null) { Main.instance.shop[Main.npcShop].item[k] = new Item(); } Main.instance.shop[Main.npcShop].item[k].SetDefaults(Main.travelShop[k]); } Main.InGuideCraftMenu = false; Main.InReforgeMenu = false; Main.recBigList = false; Main.playerInventory = true; chooseTalkingNPC(vm); } /*Nurse code overrides the normal vending machine shop for the behaviour of the nurse heal option.*/ else if (type == NPCID.Nurse) { int num5 = Main.player[Main.myPlayer].statLifeMax2 - Main.player[Main.myPlayer].statLife; for (int k = 0; k < 22; k++) { int num6 = Main.player[Main.myPlayer].buffType[k]; if (Main.debuff[num6] && Main.player[Main.myPlayer].buffTime[k] > 5 && BuffLoader.CanBeCleared(num6)) { num5 += 1000; } } if (Main.player[Main.myPlayer].BuyItem(num5)) { AchievementsHelper.HandleNurseService(num5); Main.PlaySound(SoundID.Item4, -1, -1); Main.player[Main.myPlayer].HealEffect(Main.player[Main.myPlayer].statLifeMax2 - Main.player[Main.myPlayer].statLife, true); Main.player[Main.myPlayer].statLife = Main.player[Main.myPlayer].statLifeMax2; for (int k = 0; k < 22; k++) { int num23 = Main.player[Main.myPlayer].buffType[k]; if (Main.debuff[num23] && Main.player[Main.myPlayer].buffTime[k] > 0 && BuffLoader.CanBeCleared(num23)) { Main.player[Main.myPlayer].DelBuff(k); k = -1; } } return(true); } } else { Main.player[Main.myPlayer].chest = -1; Main.npcChatText = ""; chooseTalkingNPC(vm); Main.recBigList = false; Main.playerInventory = true; Main.InGuideCraftMenu = false; Main.InReforgeMenu = false; Main.instance.shop[Main.npcShop].SetupShop(Main.npcShop < Main.MaxShopIDs - 1 ? Main.npcShop : type); } } return(true); }