Exemplo n.º 1
0
 public static void BuyItem(this TSPlayer plr, UserAccount owner, PSSign sign, Item item, int stack, int cost)
 {
     if (sign.ChestID != -1)
     {
         if (sign.Shop.UnLimit)
         {
             if (plr.TakeMoney(cost) && UEF.MoneyUp(owner.Name, cost))
             {
                 plr.SendSuccessMessage($"[C/66D093:<PowerfulSign>] 成功购买 {stack} 个 {item.Name}, 花费 {cost} {PSPlugin.Config.MoneyName}.");
                 plr.GiveItemEX(item.type, stack, item.prefix);
             }
             else
             {
                 plr.SendErrorMessage($"[C/66D093:<PowerfulSign>] 发生错误.");
             }
         }
         else
         {
             if (sign.Inventory >= stack)
             {
                 if (plr.Balance() >= cost)
                 {
                     if (plr.IsInventoryAviliable(item, stack))
                     {
                         if (sign.DelItemFromChest(item, stack) && plr.TakeMoney(cost) && UEF.MoneyUp(owner.Name, cost))
                         {
                             plr.SendSuccessMessage($"[C/66D093:<PowerfulSign>] 成功购买 {stack} 个 {item.Name}, 花费 {cost} {PSPlugin.Config.MoneyName}.");
                             plr.GiveItemEX(item.type, stack, item.prefix);
                         }
                         else
                         {
                             plr.SendErrorMessage($"[C/66D093:<PowerfulSign>] 发生错误.");
                         }
                     }
                     else
                     {
                         plr.SendErrorMessage($"[C/66D093:<PowerfulSign>] 背包空间不足, 无法装下 {stack} 个 {item.Name}.");
                     }
                 }
                 else
                 {
                     plr.SendErrorMessage($"[C/66D093:<PowerfulSign>] 你的余额不足. 当前剩余 {plr.Balance()}.");
                 }
             }
             else
             {
                 plr.SendErrorMessage($"[C/66D093:<PowerfulSign>] 商店库存不足, 无法购买. 当前剩余: {sign.Inventory}.");
             }
         }
     }
     else
     {
         plr.SendErrorMessage($"[C/66D093:<PowerfulSign>] 未发现此商店的附属储存空间.");
     }
 }
Exemplo n.º 2
0
        public static int[] BuyItemC(this TSPlayer plr, ShopListConfig shopListConfig, int type, int num, int prefix)
        {
            int[] result = new int[5];
            int   price  = 0;

            shopListConfig.Shoplist.ForEach(item =>
            {
                if (item.type == type && item.prefix == prefix)
                {
                    price = item.price * num;
                }
            });

            if (price == 0)
            {
                //本商店没有这种商品
                result[0] = 1;
                return(result);
            }
            int[] takeMoneyResult = new int[5];
            takeMoneyResult = plr.TakeMoneyFromPlayer(price);
            if (takeMoneyResult[0] == 1)
            {
                //货币不足
                result[0] = 2;
                return(result);
            }
            plr.GiveItemEX(type, num, prefix);
            //购买成功返回0
            return(takeMoneyResult);
        }
Exemplo n.º 3
0
        /**
         * 以铜币为单位从背包中扣除金币
         */
        public static int[] TakeMoneyFromPlayer(this TSPlayer plr, int price)
        {
            int[] result = new int[5];
            plr.DelItemFromInventoryByIndex(51, 10);
            int copper_coin   = 0;
            int silver_coin   = 0;
            int gold_coin     = 0;
            int platinum_coin = 0;
            //铜币为单位的总数
            int total = 0;

            //获取买家的货币数量
            for (int i = 50; i < 54; i++)
            {
                if (plr.TPlayer.inventory[i].type == 71)
                {
                    copper_coin = copper_coin + plr.TPlayer.inventory[i].stack;
                }
                else if (plr.TPlayer.inventory[i].type == 72)
                {
                    silver_coin = silver_coin + plr.TPlayer.inventory[i].stack;
                }
                else if (plr.TPlayer.inventory[i].type == 73)
                {
                    gold_coin = gold_coin + plr.TPlayer.inventory[i].stack;
                }
                else if (plr.TPlayer.inventory[i].type == 74)
                {
                    platinum_coin = platinum_coin + plr.TPlayer.inventory[i].stack;
                }
            }
            total = copper_coin + silver_coin * 100 + gold_coin * 10000 + platinum_coin * 1000000;

            if (price > total)
            {
                //货币数不够
                result[0] = 1;
                return(result);
            }

            //采用先删除后添加的方式
            for (int i = 50; i < 54; i++)
            {
                if (plr.TPlayer.inventory[i] != null)
                {
                    plr.DelItemFromInventoryByIndex(i, 1000);
                }
            }

            total = total - price;
            int total_p = total / 1000000;
            int total_g = (total / 10000) % 100;
            int total_s = (total / 100) % 100;
            int total_c = total % 100;

            if (total_p != 0)
            {
                plr.GiveItemEX(74, total_p, 0);
            }
            if (total_g != 0)
            {
                plr.GiveItemEX(73, total_g, 0);
            }
            if (total_s != 0)
            {
                plr.GiveItemEX(72, total_s, 0);
            }
            if (total_c != 0)
            {
                plr.GiveItemEX(71, total_c, 0);
            }

            result[0] = 0;
            result[1] = price / 1000000;
            result[2] = (price / 10000) % 100;
            result[3] = (price / 100) % 100;
            result[4] = price % 100;
            return(result);
        }