Ejemplo n.º 1
0
 public static void ShopBuy(NetUser Sender, UserData userData, string Command, string[] Args)
 {
     if (!Shop.Enabled || !Shop.CanBuy)
     {
         Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.Buy.NotAvailable", Sender, null), 5f);
     }
     else if (Shop.TradeZoneOnly && (userData.Zone == null || !userData.Zone.CanTrade))
     {
         Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.NoTradeZone", Sender, null), 5f);
     }
     else if (Args != null && Args.Length != 0)
     {
         int      item_index = 0;
         ShopItem shopItem;
         if (int.TryParse(Args[0], out item_index))
         {
             shopItem = Shop.FindItem(item_index);
         }
         else
         {
             shopItem = Shop.FindItem(Args[0]);
         }
         if (shopItem != null)
         {
             if (shopItem.SellPrice != -1)
             {
                 Inventory component = Sender.playerClient.controllable.GetComponent <Inventory>();
                 if (component == null || component.noVacantSlots)
                 {
                     Broadcast.Notice(Sender, "✘", Config.GetMessage("Player.Inventory.IsFull", Sender, null), 5f);
                     return;
                 }
                 int num  = shopItem.SellPrice / shopItem.Quantity;
                 int num2 = shopItem.Quantity;
                 if (Args.Length > 1 && !int.TryParse(Args[1], out num2))
                 {
                     num2 = shopItem.Quantity;
                 }
                 if (num2 < 1)
                 {
                     num2 = shopItem.Quantity;
                 }
                 ulong num3 = (ulong)((long)(num * num2));
                 if (num3 > Economy.GetBalance(Sender.userID))
                 {
                     string text = Config.GetMessage("Economy.Shop.Buy.NotEnoughBalance", Sender, null);
                     text = text.Replace("%TOTALPRICE%", num3.ToString("N0") + Economy.CurrencySign);
                     text = text.Replace("%ITEMNAME%", shopItem.Name);
                     Broadcast.Notice(Sender, Economy.CurrencySign, text, 5f);
                     return;
                 }
                 num2 = Helper.GiveItem(Sender.playerClient, shopItem.itemData, num2, shopItem.Slots);
                 if (num2 == 0)
                 {
                     Broadcast.Notice(Sender, "✘", Config.GetMessage("Player.Inventory.IsFull", Sender, null), 5f);
                     return;
                 }
                 string text2 = "\"" + shopItem.itemData.name + "\"";
                 if (num2 > 1)
                 {
                     text2 = num2.ToString() + " " + text2;
                 }
                 num3 = (ulong)((long)(num2 * num));
                 Economy.BalanceSub(Sender.userID, num3);
                 string text3 = Config.GetMessage("Economy.Shop.Buy.ItemPurchased", Sender, null);
                 text3 = text3.Replace("%TOTALPRICE%", num3.ToString("N0") + Economy.CurrencySign);
                 text3 = text3.Replace("%ITEMNAME%", text2);
                 Broadcast.Notice(Sender, Economy.CurrencySign, text3, 5f);
                 Economy.Balance(Sender, userData, "balance", null);
                 return;
             }
         }
         string newValue = (shopItem != null) ? shopItem.Name : Args[0];
         Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.Buy.ItemNotAvailable", Sender, null).Replace("%ITEMNAME%", newValue), 5f);
     }
     else
     {
         Broadcast.Notice(Sender, "✘", Config.GetMessageCommand("Command.InvalidSyntax", Command, null), 5f);
     }
 }
Ejemplo n.º 2
0
 public static void ShopSell(NetUser Sender, UserData userData, string Command, string[] Args)
 {
     if (!Shop.Enabled || !Shop.CanSell)
     {
         Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.Sell.NotAvailable", Sender, null), 5f);
     }
     else if (Shop.TradeZoneOnly && (userData.Zone == null || !userData.Zone.CanTrade))
     {
         Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.NoTradeZone", Sender, null), 5f);
     }
     else if (Args == null || Args.Length == 0)
     {
         Broadcast.Notice(Sender, "✘", Config.GetMessageCommand("Command.InvalidSyntax", Command, null), 5f);
     }
     else
     {
         int       item_index = 0;
         Inventory component  = Sender.playerClient.controllable.GetComponent <Inventory>();
         if (!Args[0].Equals("ALL", StringComparison.OrdinalIgnoreCase))
         {
             ShopItem shopItem;
             if (int.TryParse(Args[0], out item_index))
             {
                 shopItem = Shop.FindItem(item_index);
             }
             else
             {
                 shopItem = Shop.FindItem(Args[0]);
             }
             if (shopItem != null)
             {
                 if (shopItem.BuyPrice != -1)
                 {
                     int num  = shopItem.BuyPrice / shopItem.Quantity;
                     int num2 = shopItem.Quantity;
                     if (Args.Length > 1 && !int.TryParse(Args[1], out num2))
                     {
                         num2 = shopItem.Quantity;
                     }
                     if (num2 < 1)
                     {
                         num2 = shopItem.Quantity;
                     }
                     int num3 = Helper.InventoryItemCount(component, shopItem.itemData);
                     if (num3 == 0)
                     {
                         Broadcast.Notice(Sender, Economy.CurrencySign, Config.GetMessage("Economy.Shop.Sell.NotEnoughItem", Sender, null).Replace("%ITEMNAME%", shopItem.Name), 5f);
                         return;
                     }
                     if (num2 > num3)
                     {
                         num2 = num3;
                     }
                     num3 = Helper.InventoryItemRemove(component, shopItem.itemData, num2);
                     string text = "\"" + shopItem.Name + "\"";
                     if (num3 > 1)
                     {
                         text = num3.ToString() + " " + text;
                     }
                     ulong amount = (ulong)((long)(num3 * num));
                     Economy.BalanceAdd(Sender.userID, amount);
                     string text2 = Config.GetMessage("Economy.Shop.Sell.ItemSold", Sender, null);
                     text2 = text2.Replace("%TOTALPRICE%", amount.ToString("N0") + Economy.CurrencySign);
                     text2 = text2.Replace("%ITEMNAME%", text);
                     Broadcast.Notice(Sender, Economy.CurrencySign, text2, 5f);
                     Economy.Balance(Sender, userData, "balance", null);
                     return;
                 }
             }
             string newValue = (shopItem != null) ? shopItem.Name : Args[0];
             Broadcast.Notice(Sender, Economy.CurrencySign, Config.GetMessage("Economy.Shop.Sell.ItemNotAvailable", Sender, null).Replace("%ITEMNAME%", newValue), 5f);
         }
         else
         {
             ulong num4 = 0uL;
             List <IInventoryItem>      list             = new List <IInventoryItem>();
             Inventory.OccupiedIterator occupiedIterator = component.occupiedIterator;
             while (occupiedIterator.Next())
             {
                 ShopItem shopItem = Shop.FindItem(occupiedIterator.item.datablock.name);
                 if (shopItem != null && shopItem.BuyPrice != -1)
                 {
                     int   num5 = occupiedIterator.item.datablock._splittable ? occupiedIterator.item.uses : 1;
                     ulong num6 = (ulong)((long)(shopItem.BuyPrice / shopItem.Quantity) * (long)num5);
                     num4 += num6;
                     list.Add(occupiedIterator.item);
                 }
             }
             if (list.Count > 0)
             {
                 foreach (IInventoryItem current in list)
                 {
                     component.RemoveItem(current);
                 }
                 if (num4 > 0uL)
                 {
                     Economy.BalanceAdd(Sender.userID, num4);
                 }
                 string text3 = Config.GetMessage("Economy.Shop.Sell.AllSold", Sender, null);
                 text3 = text3.Replace("%TOTALPRICE%", num4.ToString("N0") + Economy.CurrencySign);
                 text3 = text3.Replace("%TOTALAMOUNT%", list.Count.ToString());
                 Broadcast.Notice(Sender, Economy.CurrencySign, text3, 5f);
             }
             else
             {
                 Broadcast.Notice(Sender, Economy.CurrencySign, Config.GetMessage("Economy.Shop.Sell.NoNothing", Sender, null), 5f);
             }
         }
     }
 }
Ejemplo n.º 3
0
        public static bool RunCommand(NetUser netUser, UserData userData, string Command, string[] Args)
        {
            bool result;

            if (Command != null)
            {
                if (Economy.asad == null)
                {
                    Economy.asad = new Dictionary <string, int>(6)
                    {
                        {
                            "balance",
                            0
                        },
                        {
                            "money",
                            1
                        },
                        {
                            "send",
                            2
                        },
                        {
                            "shop",
                            3
                        },
                        {
                            "buy",
                            4
                        },
                        {
                            "sell",
                            5
                        }
                    };
                }
                int num;
                if (Economy.asad.TryGetValue(Command, out num))
                {
                    switch (num)
                    {
                    case 0:
                        Economy.Balance(netUser, userData, Command, Args);
                        break;

                    case 1:
                        Economy.Balance(netUser, userData, Command, Args);
                        break;

                    case 2:
                        Economy.Send(netUser, userData, Command, Args);
                        break;

                    case 3:
                        Economy.ShopList(netUser, userData, Command, Args);
                        break;

                    case 4:
                        Economy.ShopBuy(netUser, userData, Command, Args);
                        break;

                    case 5:
                        Economy.ShopSell(netUser, userData, Command, Args);
                        break;

                    default:
                        result = false;
                        return(result);
                    }
                    result = true;
                    return(result);
                }
            }
            result = false;
            return(result);
        }