Ejemplo n.º 1
0
        private void AetherShop(CommandArgs e)
        {
            if (!dropOpt || !shopOpt)
            {
                return;
            }
            string cmd = e.Message.Substring(e.Message.IndexOf(' ') + 1);
            string opt = string.Empty;

            if (cmd.Contains(' '))
            {
                opt = cmd.Substring(cmd.IndexOf(' ') + 1);
            }
            string text = string.Empty;
            int    who  = e.Player.Index;

            foreach (Item inv in Main.player[who].inventory)
            {
                foreach (var ai in invp[who].aether)
                {
                    if (ai.item.IsTheSameAs(inv))
                    {
                        ai.item.owner = who;
                    }
                }
            }
            switch (cmd.Contains(" ") ? cmd.Substring(0, cmd.IndexOf(" ")) : cmd)
            {
            case "list":
                foreach (var ai in invp[who].aether)
                {
                    if (ai.newOwner == who || !NotCoin(ai.item) || ai.newOwner != 255)
                    {
                        ai.unbuyable = true;
                        continue;
                    }
                    if (!string.IsNullOrEmpty(ai.item.Name))
                    {
                        text += string.Concat(ai.item.Name, " (", ai.item.value, " copper) ");
                    }
                }
                e.Player.SendInfoMessage(text == string.Empty ? "The items have expired or been reacquired." : text);
                break;

            case "buy":
                foreach (var ai in invp[who].aether)
                {
                    if (ai.unbuyable || ai.newOwner == who || ai.newOwner != 255 || !NotCoin(ai.item))
                    {
                        continue;
                    }
                    invp[who].coinBank = CoinPurse.CoinInit(who);
                    buyBack[who]       = true;
                    int value = ai.item.shopCustomPrice.HasValue ? ai.item.shopCustomPrice.Value : ai.item.value;
                    if (opt.ToLower().Replace(" ", "") == ai.item.Name.ToLower().Replace(" ", ""))
                    {
                        if (CoinPurse.ShopItem(who, value))
                        {
                            Item clone = ai.item.Clone();
                            foreach (Item i in Main.item)
                            {
                                if (i.IsTheSameAs(ai.item))
                                {
                                    i.active = false;
                                    i.SetDefaults(0);
                                    break;
                                }
                            }
                            e.Player.GiveItem(clone.type, clone.Name, clone.width, clone.height, clone.stack, clone.prefix);
                            e.Player.SendSuccessMessage(string.Concat("Reacquiring ", ai.item.Name, " complete."));
                            invp[who].aether.Remove(ai);
                            break;
                        }
                        else
                        {
                            e.Player.SendInfoMessage("The cost necessary for this item has not been acquired.");
                        }
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
 private void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled)
     {
         if (e.MsgID == PacketTypes.PlayerSlot)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 byte  id     = br.ReadByte();
                 byte  slot   = br.ReadByte();
                 short stack  = br.ReadInt16();
                 byte  prefix = br.ReadByte();
                 short netID  = br.ReadInt16();
             }
         }
         if (e.MsgID == PacketTypes.ChestGetContents)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 short tileX = br.ReadInt16();
                 short tileY = br.ReadInt16();
                 foreach (ShopChest sc in shop)
                 {
                     if (sc != null)
                     {
                         var r = new RUDD.Region("", new Vector2(tileX - 1, tileY - 1), new Vector2(tileX + 1, tileY + 1));
                         if (r.Contains(sc.x, sc.y))
                         {
                             for (int i = 0; i < sc.chest.item.Length; i++)
                             {
                                 if (sc.contents[i] != null)
                                 {
                                     if (sc.refill || resetContents[sc.index2])
                                     {
                                         Main.chest[sc.index].item[i].netDefaults(sc.contents[i].type);
                                         Main.chest[sc.index].item[i].stack  = sc.contents[i].stack;
                                         Main.chest[sc.index].item[i].prefix = sc.contents[i].prefix;
                                         TShock.Players[sc.owner].SendData(PacketTypes.ChestItem, "", sc.index, i, Main.chest[sc.index].item[i].stack, Main.chest[sc.index].item[i].prefix, Main.chest[sc.index].item[i].type);
                                     }
                                 }
                             }
                             resetContents[sc.index2] = false;
                             break;
                         }
                     }
                 }
             }
         }
         if (e.MsgID == PacketTypes.ChestItem)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 short cID    = br.ReadInt16();
                 byte  slot   = br.ReadByte();
                 short stack  = br.ReadInt16();
                 byte  prefix = br.ReadByte();
                 short itemID = br.ReadInt16();
                 foreach (ShopChest sc in shop)
                 {
                     if (sc != null)
                     {
                         if (sc.index == cID)
                         {
                             Player player = null;
                             foreach (Player p in Main.player)
                             {
                                 if (p.chest == sc.index)
                                 {
                                     player = p;
                                     break;
                                 }
                             }
                             if (player != null)
                             {
                                 if (itemID == 0)
                                 {
                                     if (sc.contents != null)
                                     {
                                         if (sc.contents[slot] != null)
                                         {
                                             if (sc.contents[slot].type != 0)
                                             {
                                                 int value = sc.contents[slot].value == 0 ? sc.chest.item[slot].value : sc.contents[slot].value;
                                                 value = Main.hardMode && priceDouble ? value * 2 : value;
                                                 if (!CoinPurse.ShopItem(player.whoAmI, value))
                                                 {
                                                     active[player.whoAmI]         = new ShopChest();
                                                     active[player.whoAmI].invalid = new Item();
                                                     active[player.whoAmI].invalid.netDefaults(sc.contents[slot].type);
                                                     active[player.whoAmI].invalid.stack  = sc.contents[slot].stack;
                                                     active[player.whoAmI].invalid.prefix = sc.contents[slot].prefix;
                                                     TShock.Players[player.whoAmI].SendInfoMessage(string.Concat("This item requires ", value, " copper."));
                                                     justBought[player.whoAmI] = true;
                                                     resetContents[sc.index2]  = true;
                                                 }
                                                 else
                                                 {
                                                     var block = CoinStorage.data.GetBlock(TShock.Players[player.whoAmI].UUID);
                                                     block.WriteValue("Deliver", "True");
                                                     block.IncreaseValue("Coins", value);
                                                     soldItem[sc.owner] = true;
                                                     if (!sc.refill)
                                                     {
                                                         sc.contents[slot].type = 0;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         }
                     }
                 }
             }
         }
         else if (e.MsgID == PacketTypes.ChestOpen)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 short id = br.ReadInt16();
                 short x  = br.ReadInt16();
                 short y  = br.ReadInt16();
             }
         }
         else if (e.MsgID == PacketTypes.PlaceChest)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 byte  id    = br.ReadByte();
                 short tileX = br.ReadInt16();
                 short tileY = br.ReadInt16();
             }
         }
         if (e.MsgID == PacketTypes.Tile)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 byte  action = br.ReadByte();
                 short x      = br.ReadInt16();
                 short y      = br.ReadInt16();
                 if (action == 0)
                 {
                     foreach (Player player in Main.player)
                     {
                         if (player.active)
                         {
                             if (canSelect[player.whoAmI])
                             {
                                 if (Main.tile[x, y].type == TileID.Containers)
                                 {
                                     for (int i = 0; i < shop.Length; i++)
                                     {
                                         if (shop[i] == null || !shop[i].enabled)
                                         {
                                             for (int j = 0; j < Main.chest.Length; j++)
                                             {
                                                 if (new Microsoft.Xna.Framework.Rectangle(Main.chest[j].x * 16, Main.chest[j].y * 16, 32, 32).Contains(x * 16 + 8, y * 16 + 8))
                                                 {
                                                     shop[i]          = new ShopChest();
                                                     shop[i].chest    = Main.chest[j];
                                                     shop[i].contents = ShopItem.Convert(Main.chest[j].item, priceFloor[player.whoAmI]);
                                                     shop[i].index    = j;
                                                     shop[i].index2   = i;
                                                     shop[i].x        = Main.chest[j].x;
                                                     shop[i].y        = Main.chest[j].y;
                                                     shop[i].enabled  = true;
                                                     shop[i].active   = true;
                                                     shop[i].owner    = player.whoAmI;
                                                     shop[i].value    = priceFloor[player.whoAmI];
                                                     shop[i].refill   = chestRefill[player.whoAmI];
                                                     CoinStorage.WriteBlock(TShock.Players[player.whoAmI]);
                                                     if (data.BlockExists("Chest" + j))
                                                     {
                                                         var block = data.GetBlock("Chest" + j);
                                                         block.WriteValue("ChestX", x.ToString());
                                                         block.WriteValue("ChestY", y.ToString());
                                                         block.WriteValue("Index", j.ToString());
                                                         block.WriteValue("OwnerID", player.whoAmI.ToString());
                                                         block.WriteValue("Price", priceFloor[player.whoAmI].ToString());
                                                         block.WriteValue("Refill", chestRefill[player.whoAmI].ToString());
                                                         for (int m = 0; m < shop[i].contents.Length; m++)
                                                         {
                                                             block.WriteValue("Slot" + m, shop[i].contents[m].type.ToString());
                                                         }
                                                     }
                                                     canSelect[player.whoAmI]  = false;
                                                     priceFloor[player.whoAmI] = 0;
                                                     TShock.Players[player.whoAmI].SendSuccessMessage("The chest is now set as a shop.");
                                                     break;
                                                 }
                                             }
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }