Пример #1
0
        private void OnRecvSellSilver(IChannel channel, Message message)
        {
            Console.WriteLine("OnRecvSellSilver");
            CSellSilver request = message as CSellSilver;
            Player      player  = (Player)channel.GetContent();
            ConnectDB   connect = new ConnectDB();
            int         result;

            player.SilverNum = request.silverCoin;
            result           = connect.UpdateSilverNum(player.user, request.silverCoin);
            if (result == 0)
            {
                Console.WriteLine("update silverNum failure");
            }

            if (request.sellAll)
            {
                // delete goods from package
                result = connect.DBDeleteFromPackage(player.user, request.goods);
                if (result == 0)
                {
                    Console.WriteLine("delete silver goods failure");
                }
            }
            else
            {
                // modify the goods number in package
                result = connect.UpdateTreasureNum(player.user, request.goods, request.remainNum);
                if (result == 0)
                {
                    Console.WriteLine("update silver goodsNum failure");
                }
            }
        }
Пример #2
0
    public void SellGoods()
    {
        if (itemName != null)
        {
            price_ = int.Parse(price.text);
            if (price_ < 0)
            {
                MessageBox.Show("Input text must > 0!");
                return;
            }

            if (isMall)
            {
                if (price_ > TreasureInfo.playerTreasure[itemName].number)
                {
                    MessageBox.Show("You do not have so many treasure!");
                    return;
                }

                CSellSilver msg = new CSellSilver();
                // sell back to mall, remove treasure from package and add silverCoin number
                PlayerInfo.SilverNum += price_ * TreasureInfo.treasureMall[itemName].price;
                msg.silverCoin        = PlayerInfo.SilverNum;
                msg.goods             = itemName;

                if (TreasureInfo.playerTreasure[itemName].number > price_)
                {
                    TreasureInfo.playerTreasure[itemName].number -= price_;
                    msg.sellAll   = false;
                    msg.remainNum = TreasureInfo.playerTreasure[itemName].number;
                }
                else
                {
                    TreasureInfo.playerTreasure.Remove(itemName);
                    msg.sellAll = true;
                }

                // send message
                MyNetwork.Send(msg);
            }
            else
            {
                // gold treasures, remove treasure from package and add to mall
                TreasureInfo.playerTreasure.Remove(itemName);
                TreasureMall tmp = new TreasureMall()
                {
                    ownerName = PlayerInfo.name,
                    price     = price_,
                    isGold    = true
                };
                TreasureInfo.treasureMall.Add(itemName, tmp);

                // send message
                CSellGold msg2 = new CSellGold()
                {
                    goods = itemName,
                    price = price_
                };
                MyNetwork.Send(msg2);
            }
        }

        if (packageHandler != null)
        {
            packageHandler.ClearAfterAdd();
        }

        // scene
        if (inventoryHandler != null)
        {
            inventoryHandler.UpdateInventory();
        }
    }