Esempio n. 1
0
        /// <summary>
        /// 保存到数据库中
        /// </summary>
        public void SaveToDatabase()
        {
            using (PlayerBussiness pb = new PlayerBussiness())
            {
                lock (_lock)
                {
                    for (int i = 0; i < _items.Length; i++)
                    {
                        ItemInfo item = _items[i];
                        if (item != null)
                        {
                            if (item.IsDirty)
                            {
                                if (item.ItemID > 0)
                                {
                                    pb.UpdateGoods(item);
                                }
                                else
                                {
                                    pb.AddGoods(item);
                                }
                            }
                        }
                    }

                    foreach (ItemInfo item in _removedList)
                    {
                        pb.UpdateGoods(item);
                    }
                    _removedList.Clear();
                }
            }        
        }
        public void SendGoodManCard(string receiverName, int receiverID, string senderName, int senderID, PlayerBussiness db)
        {
            ItemTemplateInfo goodMan = ItemMgr.FindItemTemplate(11105);
            ItemInfo goodManCard = ItemInfo.CreateFromTemplate(goodMan, 1, (int)ItemAddType.webing);
            goodManCard.IsBinds = true;

            goodManCard.UserID = 0;
            db.AddGoods(goodManCard);

            MailInfo mail = new MailInfo();
            mail.Annex1 = goodManCard.ItemID.ToString();
            mail.Content = LanguageMgr.GetTranslation("MarryApplyReplyHandler.Content");
            mail.Gold = 0;
            mail.IsExist = true;
            mail.Money = 0;
            mail.Receiver = receiverName;
            mail.ReceiverID = receiverID;
            mail.Sender = senderName;
            mail.SenderID = senderID;
            mail.Title = LanguageMgr.GetTranslation("MarryApplyReplyHandler.Title");
            mail.Type = (int)eMailType.Marry;
            db.SendMail(mail);
            //Spouse.Out.SendMailResponse(mail.ReceiverID, eMailRespose.Receiver);
        }
Esempio n. 3
0
        public bool HandleCommand(TankMarryLogicProcessor process, GamePlayer player, GSPacketIn packet)
        {
            if (player.CurrentMarryRoom == null || player.CurrentMarryRoom.RoomState != eRoomState.FREE)
            {
                return false;
            }

            if(player.PlayerCharacter.ID != player.CurrentMarryRoom.Info.GroomID && player.PlayerCharacter.ID != player.CurrentMarryRoom.Info.BrideID )
            {
                return false;
            }

            int needMoney = GameProperties.PRICE_PROPOSE;
            if(player.CurrentMarryRoom.Info.IsHymeneal)
            {
                if (player.PlayerCharacter.Money < needMoney)
                {
                    player.Out.SendMessage(eMessageType.ChatNormal, LanguageMgr.GetTranslation("UserFirecrackersCommand.MoneyNotEnough"));
                    return false;
                }
            }

            GamePlayer Groom = player.CurrentMarryRoom.GetPlayerByUserID(player.CurrentMarryRoom.Info.GroomID);
            if(Groom == null)
            {
                player.Out.SendMessage(eMessageType.ChatNormal, LanguageMgr.GetTranslation("HymenealCommand.NoGroom"));
                return false;
            }

            GamePlayer Bride = player.CurrentMarryRoom.GetPlayerByUserID(player.CurrentMarryRoom.Info.BrideID);
            if (Bride == null)
            {
                player.Out.SendMessage(eMessageType.ChatNormal, LanguageMgr.GetTranslation("HymenealCommand.NoBride"));
                return false;
            }

            bool result = false;
            bool isFirst = false;
            GSPacketIn pkg = packet.Clone();

            int hymenealState = packet.ReadInt();

            if (1 == hymenealState)
            {
                player.CurrentMarryRoom.RoomState = eRoomState.FREE;
            }
            else
            {
                player.CurrentMarryRoom.RoomState = eRoomState.Hymeneal;
                player.CurrentMarryRoom.BeginTimerForHymeneal(170 * 1000);

                if (!player.PlayerCharacter.IsGotRing)
                {
                    isFirst = true;
                    ItemTemplateInfo ringTemplate = ItemMgr.FindItemTemplate(9022);
                    ItemInfo ring1 = ItemInfo.CreateFromTemplate(ringTemplate, 1, (int)ItemAddType.webing);
                    ring1.IsBinds = true;
                    //Groom.CurrentInventory.AddItem(ring1, 11);
                    using (PlayerBussiness pb = new PlayerBussiness())
                    {
                        ring1.UserID = 0;
                        pb.AddGoods(ring1);

                        string content = LanguageMgr.GetTranslation("HymenealCommand.Content", Bride.PlayerCharacter.NickName);

                        MailInfo mail = new MailInfo();
                        mail.Annex1 = ring1.ItemID.ToString();
                        mail.Content = content;
                        mail.Gold = 0;
                        mail.IsExist = true;
                        mail.Money = 0;
                        mail.Receiver = Groom.PlayerCharacter.NickName;
                        mail.ReceiverID = Groom.PlayerCharacter.ID;
                        mail.Sender = LanguageMgr.GetTranslation("HymenealCommand.Sender");
                        mail.SenderID = 0;
                        mail.Title = LanguageMgr.GetTranslation("HymenealCommand.Title");
                        mail.Type = (int)eMailType.Marry;
                        if (pb.SendMail(mail))
                        {
                            result = true;
                        }
                        player.Out.SendMailResponse(mail.ReceiverID, eMailRespose.Receiver);
                    }

                    ItemInfo ring2 = ItemInfo.CreateFromTemplate(ringTemplate, 1, (int)ItemAddType.webing);
                    ring2.IsBinds = true;
                    //Bride.CurrentInventory.AddItem(ring2, 11);
                    using (PlayerBussiness pb = new PlayerBussiness())
                    {
                        ring2.UserID = 0;
                        pb.AddGoods(ring2);

                        string content = LanguageMgr.GetTranslation("HymenealCommand.Content", Groom.PlayerCharacter.NickName);

                        MailInfo mail = new MailInfo();
                        mail.Annex1 = ring2.ItemID.ToString();
                        mail.Content = content;
                        mail.Gold = 0;
                        mail.IsExist = true;
                        mail.Money = 0;
                        mail.Receiver = Bride.PlayerCharacter.NickName;
                        mail.ReceiverID = Bride.PlayerCharacter.ID;
                        mail.Sender = LanguageMgr.GetTranslation("HymenealCommand.Sender");
                        mail.SenderID = 0;
                        mail.Title = LanguageMgr.GetTranslation("HymenealCommand.Title");
                        mail.Type = (int)eMailType.Marry;
                        if (pb.SendMail(mail))
                        {
                            result = true;
                        }
                        player.Out.SendMailResponse(mail.ReceiverID, eMailRespose.Receiver);
                    }

                    player.CurrentMarryRoom.Info.IsHymeneal = true;

                    using (PlayerBussiness db = new PlayerBussiness())
                    {
                        db.UpdateMarryRoomInfo(player.CurrentMarryRoom.Info);

                        //更新IsGotRing的数据库
                        db.UpdatePlayerGotRingProp(Groom.PlayerCharacter.ID,Bride.PlayerCharacter.ID);

                        //通过数据库读入PlayerCharacter内存
                        Groom.LoadMarryProp();
                        Bride.LoadMarryProp();
                    }

                    //Groom.PlayerCharacter.IsGotRing = true;
                    //Bride.PlayerCharacter.IsGotRing = true;

                }
                else
                {
                    isFirst = false;
                    result = true;
                }

                if (!isFirst)
                {
                    //player.SetMoney(-needMoney, MoneyRemoveType.Marry);
                    player.RemoveMoney(needMoney);
                    LogMgr.LogMoneyAdd(LogMoneyType.Marry, LogMoneyType.Marry_Hymeneal, player.PlayerCharacter.ID, needMoney, player.PlayerCharacter.Money, 0, 0, 0,0, "", "", "");
                    CountBussiness.InsertSystemPayCount(player.PlayerCharacter.ID, needMoney, 0, (int)eConsumerType.Marry, (int)eSubConsumerType.Marry_Hymeneal);
                }

                pkg.WriteInt(player.CurrentMarryRoom.Info.ID);
                pkg.WriteBoolean(result);
                //0 player.CurrentMarryRoom.SendToAll(pkg);
                //0 player.CurrentMarryRoom.SendToAllForScene(pkg,1);
                player.CurrentMarryRoom.SendToAll(pkg);

                if(result)
                {
                    string msg = LanguageMgr.GetTranslation("HymenealCommand.Succeed", Groom.PlayerCharacter.NickName, Bride.PlayerCharacter.NickName);
                    GSPacketIn message = player.Out.SendMessage(eMessageType.ChatNormal, msg);
                    player.CurrentMarryRoom.SendToPlayerExceptSelfForScene(message, player);
                }
            }

            return true;
        }
Esempio n. 4
0
        //0表示男女,1男2女
        //type 1表示物品,2表示金币,3表示点券,4表示经验,5表示功勋,6表示BUFF
        public static bool AddDailyAward(GamePlayer player)
        {
            if (DateTime.Now.Date == player.PlayerCharacter.LastAward.Date)
            {
                return false;
            }

            //if (player.PlayerCharacter.DayLoginCount > 0)
            //    return false;

            player.PlayerCharacter.DayLoginCount++;
            player.PlayerCharacter.LastAward = DateTime.Now;
            DailyAwardInfo[] infos = GetAllAwardInfo();
            StringBuilder msg = new StringBuilder();
            string full = string.Empty;
            bool has = false;
            foreach (DailyAwardInfo info in infos)
            {
                if (info.Sex != 0 && (player.PlayerCharacter.Sex ? 1 : 2) != info.Sex)
                    continue;

                has = true;
                switch (info.Type)
                {
                    case 1:
                        ItemTemplateInfo itemTemplateInfo = Bussiness.Managers.ItemMgr.FindItemTemplate(info.TemplateID);
                        if (itemTemplateInfo != null)
                        {
                            int itemCount = info.Count;
                            for (int len = 0; len < itemCount; len += itemTemplateInfo.MaxCount)
                            {
                                int count = len + itemTemplateInfo.MaxCount > itemCount ? itemCount - len : itemTemplateInfo.MaxCount;
                                ItemInfo item = ItemInfo.CreateFromTemplate(itemTemplateInfo, count, (int)ItemAddType.DailyAward);
                                item.ValidDate = info.ValidDate;
                                item.IsBinds = info.IsBinds;

                                //if (player.AddItem(item, Game.Server.Statics.ItemAddType.DailyAward, item.GetBagType()) == -1)
                                if (!player.AddTemplate(item,item.Template.BagType,item.Count))
                                {
                                    using (PlayerBussiness db = new PlayerBussiness())
                                    {
                                        item.UserID = 0;
                                        db.AddGoods(item);

                                        MailInfo message = new MailInfo();
                                        message.Annex1 = item.ItemID.ToString();
                                        message.Content = LanguageMgr.GetTranslation("AwardMgr.AddDailyAward.Content", item.Template.Name);
                                        message.Gold = 0;
                                        message.Money = 0;
                                        message.Receiver = player.PlayerCharacter.NickName;
                                        message.ReceiverID = player.PlayerCharacter.ID;
                                        message.Sender = message.Receiver;
                                        message.SenderID = message.ReceiverID;
                                        message.Title = LanguageMgr.GetTranslation("AwardMgr.AddDailyAward.Title", item.Template.Name);
                                        message.Type = (int)eMailType.DailyAward;
                                        db.SendMail(message);

                                        full = LanguageMgr.GetTranslation("AwardMgr.AddDailyAward.Mail");
                                    }
                                }
                            }
                        }
                        break;
                    case 2:
                        player.AddGold(info.Count);
                        break;
                    case 3:
                        player.AddMoney(info.Count);
                        LogMgr.LogMoneyAdd(LogMoneyType.Award, LogMoneyType.Award_Daily, player.PlayerCharacter.ID, info.Count, player.PlayerCharacter.Money, 0, 0, 0, 0, "", "", "");
                        break;
                    case 4:
                        player.AddGP(info.Count);
                        break;
                    case 5:
                        player.AddOffer(info.Count, false);
                        break;
                    case 6:
                        ItemTemplateInfo template = Bussiness.Managers.ItemMgr.FindItemTemplate(info.TemplateID);
                        if (template != null)
                        {
                            AbstractBuffer buffer = BufferList.CreateBufferHour(template, info.ValidDate);
                            buffer.Start(player);
                        }
                        break;
                }
            }

            if (has)
            {
                //player.Out.SendMessage(eMessageType.DailyAward, full + msg.ToString());

                if (!string.IsNullOrEmpty(full))
                {
                    player.Out.SendMailResponse(player.PlayerCharacter.ID, eMailRespose.Receiver);
                }
            }

            return true;
        }
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            int gold = 0;            //表示金币
            int money = 0;           //表示点券
            int offer = 0;           //表示功勋
            int gifttoken = 0;       //表示礼劵
            StringBuilder payGoods = new StringBuilder();                    //表示支付物品ID
            eMessageType eMsg = eMessageType.Normal;
            string msg = "GoodsPresentHandler.Success";

            string content = packet.ReadString();       //赠送人留言
            string nickName = packet.ReadString();      //购买人昵称
            List<int> needitemsinfo = new List<int>();  //存放兑换物品的templateID,Count

            if (client.Player.PlayerCharacter.HasBagPassword && client.Player.PlayerCharacter.IsLocked)
            {
                client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked"));
                return 0;
            }

            using (PlayerBussiness db = new PlayerBussiness())
            {
                PlayerInfo receiver = db.GetUserSingleByNickName(nickName);
                if (receiver != null)
                {
                    List<ItemInfo> items = new List<ItemInfo>();
                    StringBuilder types = new StringBuilder();

                    int count = packet.ReadInt();
                    for (int i = 0; i < count; i++)
                    {
                        int GoodsID = packet.ReadInt();         //序号
                        int type = packet.ReadInt();       //购买方式
                        string color = packet.ReadString();//颜色
                        string skin = packet.ReadString(); //皮肤

                        ShopItemInfo shopItem = Bussiness.Managers.ShopMgr.GetShopItemInfoById(GoodsID);                   //获取商品信息

                        if (shopItem == null)                                                                              //商品不存在
                        {
                            continue;
                        }

                        ItemTemplateInfo goods = Bussiness.Managers.ItemMgr.FindItemTemplate(shopItem.TemplateID);              //查找物品属性
                        ItemInfo item = ItemInfo.CreateFromTemplate(goods, 1, (int)ItemAddType.Gift);                           //构建物品临时属性

                        if (item == null)
                            continue;

                        //未开始
                        //if (shopitem.AValue1 <= 0 || shopitem.Beat <= 0)
                        //    continue;

                        item.Color = color == null ? "" : color;
                        item.Skin = skin == null ? "" : skin;

                        if (item == null)
                            continue;

                        types.Append(type);
                        types.Append(",");
                        items.Add(item);

                        needitemsinfo = ItemInfo.SetItemType(shopItem, type, ref gold, ref money, ref offer, ref gifttoken);
                    }

                    if (items.Count == 0)
                        return 1;

                    //////////////////////////////////////////////////////////////////////////////////////
                    //玩家背包中是否有兑换物品所需要的物品
                    int icount = client.Player.MainBag.GetItems().Count;       //获取个数
                    bool result = true;
                    for (int j = 0; j < needitemsinfo.Count; j += 2)
                    {
                        if (client.Player.GetItemCount(needitemsinfo[j]) < needitemsinfo[j + 1])
                        {
                            result = false;
                        }
                    }

                    if (!result)
                    {
                        eMsg = eMessageType.ERROR;
                        msg = "UserBuyItemHandler.NoBuyItem";
                        return 1;
                    }
                    /////////////////////////////////////////////////////////////

                    if (gold <= client.Player.PlayerCharacter.Gold && money <= client.Player.PlayerCharacter.Money && offer <= client.Player.PlayerCharacter.Offer && gifttoken <= client.Player.PlayerCharacter.GiftToken)
                    {

                        types.Remove(types.Length - 1, 1);
                        client.Player.RemoveMoney(money);
                        client.Player.RemoveGold(gold);
                        client.Player.RemoveOffer(offer);
                        client.Player.RemoveGiftToken(gifttoken);
                        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        //从玩家背包中删除兑换所需要的物品
                        for (int j = 0; j < needitemsinfo.Count; j += 2)
                        {
                            client.Player.RemoveTemplate(needitemsinfo[j], needitemsinfo[j + 1]);
                            payGoods.Append(needitemsinfo[j].ToString() + ":");
                        }
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                        string itemIDs = "";
                        int annexIndex = 0;
                        MailInfo message = new MailInfo();
                        StringBuilder annexRemark = new StringBuilder();
                        annexRemark.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark"));

                        foreach (ItemInfo item in items)
                        {
                            itemIDs += (itemIDs == "" ? item.TemplateID.ToString() : "," + item.TemplateID.ToString());
                            item.UserID = 0;
                            db.AddGoods(item);

                            annexIndex++;
                            annexRemark.Append(annexIndex);
                            annexRemark.Append("、");
                            annexRemark.Append(item.Template.Name);
                            annexRemark.Append("x");
                            annexRemark.Append(item.Count);
                            annexRemark.Append(";");

                            switch (annexIndex)
                            {
                                case 1:
                                    message.Annex1 = item.ItemID.ToString();
                                    message.Annex1Name = item.Template.Name;
                                    break;
                                case 2:
                                    message.Annex2 = item.ItemID.ToString();
                                    message.Annex2Name = item.Template.Name;
                                    break;
                                case 3:
                                    message.Annex3 = item.ItemID.ToString();
                                    message.Annex3Name = item.Template.Name;
                                    break;
                                case 4:
                                    message.Annex4 = item.ItemID.ToString();
                                    message.Annex4Name = item.Template.Name;
                                    break;
                                case 5:
                                    message.Annex5 = item.ItemID.ToString();
                                    message.Annex5Name = item.Template.Name;
                                    break;
                            }

                            if (annexIndex == 5)
                            {
                                annexIndex = 0;
                                message.AnnexRemark = annexRemark.ToString();
                                annexRemark.Remove(0, annexRemark.Length);
                                annexRemark.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark"));
                                message.Content = content;
                                message.Gold = 0;
                                message.Money = 0;
                                message.Receiver = receiver.NickName;
                                message.ReceiverID = receiver.ID;
                                message.Sender = client.Player.PlayerCharacter.NickName;
                                message.SenderID = client.Player.PlayerCharacter.ID;
                                message.Title = message.Sender + LanguageMgr.GetTranslation("GoodsPresentHandler.Content") + message.Annex1Name + "]";
                                message.Type = (int)eMailType.PresentItem;
                                db.SendMail(message);

                                message.Revert();
                            }
                        }

                        if (annexIndex > 0)
                        {
                            message.AnnexRemark = annexRemark.ToString();
                            message.Content = content;
                            message.Gold = 0;
                            message.Money = 0;
                            message.Receiver = receiver.NickName;
                            message.ReceiverID = receiver.ID;
                            message.Sender = client.Player.PlayerCharacter.NickName;
                            message.SenderID = client.Player.PlayerCharacter.ID;
                            message.Title = message.Sender + LanguageMgr.GetTranslation("GoodsPresentHandler.Content") + message.Annex1Name + "]";
                            message.Type = (int)eMailType.PresentItem;
                            db.SendMail(message);
                        }
                        LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_Present, client.Player.PlayerCharacter.ID, money, client.Player.PlayerCharacter.Money, gold, gifttoken, offer, payGoods.ToString(), itemIDs, types.ToString());
                        client.Out.SendMailResponse(receiver.ID, eMailRespose.Receiver);
                        client.Out.SendMailResponse(client.Player.PlayerCharacter.ID, eMailRespose.Send);
                    }
                    else
                    {
                        eMsg = eMessageType.ERROR;
                        msg = "GoodsPresentHandler.NoMoney";
                    }
                }
                else
                {
                    eMsg = eMessageType.ERROR;
                    msg = "GoodsPresentHandler.NoUser";
                }
            }
            client.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg));
            return 0;
        }
Esempio n. 6
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            if (countConnect >= 3000) { client.Disconnect(); return 0; }

            int gold = 0;            //表示金币
            int money = 0;           //表示点券
            int offer = 0;           //表示功勋
            int gifttoken = 0;       //表示礼劵
            int medal = 0;
            StringBuilder payGoods = new StringBuilder();                    //表示支付物品ID
            eMessageType eMsg = eMessageType.Normal;
            string msg = "UserBuyItemHandler.Success";

            List<ItemInfo> buyitems = new List<ItemInfo>();                  //购买物品列表
            //List<int> needitemsinfo = new List<int>();                       //购买所需物品列表
            List<bool> dresses = new List<bool>();
            List<int> places = new List<int>();
            StringBuilder types = new StringBuilder();

            bool isBind = false;
            ConsortiaInfo consotia = ConsortiaMgr.FindConsortiaInfo(client.Player.PlayerCharacter.ConsortiaID);

            int count = packet.ReadInt();
            for (int i = 0; i < count; i++)
            {
                int buyFrom = packet.ReadInt();
                int GoodsID = packet.ReadInt();
                int type = packet.ReadInt();
                string color = packet.ReadString();
                bool dress = packet.ReadBoolean();
                string skin = packet.ReadString();
                int place = packet.ReadInt();

                //这里开始处理公会商店
                ShopItemInfo shopItem = Bussiness.Managers.ShopMgr.GetShopItemInfoById(GoodsID);                   //获取商品信息
                //if (shopItem.ShopID == 2 || !Bussiness.Managers.ShopMgr.CanBuy(shopItem.ShopID, consotia == null ? 1 : consotia.ShopLevel, ref isBind, client.Player.PlayerCharacter.ConsortiaID, client.Player.PlayerCharacter.Riches))
                if (!Bussiness.Managers.ShopMgr.CanBuy(shopItem.ShopID, consotia == null ? 1 : consotia.ShopLevel, ref isBind, client.Player.PlayerCharacter.ConsortiaID, client.Player.PlayerCharacter.Riches))
                {
                    client.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("UserBuyItemHandler.FailByPermission"));
                    return 1;
                }

                //if (shopItem == null)
                //{
                //    continue;
                //}

                ItemTemplateInfo goods = Bussiness.Managers.ItemMgr.FindItemTemplate(shopItem.TemplateID);              //获取物品属性

                ItemInfo item = ItemInfo.CreateFromTemplate(goods, 1, (int)ItemAddType.Buy);                            //创建物品模板

                ////////////////////////////////////////////////////////////////////////////////////////////////////
                //判断有限期
                if (0 == shopItem.BuyType)                              //时间购买类型
                {
                    if (1 == type)
                    {
                        item.ValidDate = shopItem.AUnit;
                    }
                    if (2 == type)
                    {
                        item.ValidDate = shopItem.BUnit;
                    }
                    if (3 == type)
                    {
                        item.ValidDate = shopItem.CUnit;
                    }
                }
                else                                                  //数量购买类型
                {
                    if (1 == type)
                    {
                        item.Count = shopItem.AUnit;
                    }
                    if (2 == type)
                    {
                        item.Count = shopItem.BUnit;
                    }
                    if (3 == type)
                    {
                        item.Count = shopItem.CUnit;
                    }
                }
                ////////////////////////////////////////////////////////////////////////////////////////////////////////

                if (item == null && shopItem == null)
                    continue;
                item.Color = color == null ? "" : color;
                item.Skin = skin == null ? "" : skin;
                if (isBind == true)
                {
                    item.IsBinds = true;
                }
                else
                {
                    item.IsBinds = Convert.ToBoolean(shopItem.IsBind);
                }

                types.Append(type);
                types.Append(",");
                buyitems.Add(item);
                dresses.Add(dress);
                places.Add(place);

                ItemInfo.SetItemType(shopItem, type, ref gold, ref money, ref offer, ref gifttoken, ref medal);

            }

            if (buyitems.Count == 0)
                return 1;
            if (client.Player.PlayerCharacter.HasBagPassword && client.Player.PlayerCharacter.IsLocked)
            {
                client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked"));
                return 1;
            }

            //判断金币或礼券等是否足够
            if (gold <= client.Player.PlayerCharacter.Gold &&
                money <= client.Player.PlayerCharacter.Money &&
                offer <= client.Player.PlayerCharacter.Offer &&
                gifttoken <= client.Player.PlayerCharacter.GiftToken)// &&
                //medal <= client.Player.PlayerCharacter.medal)
            {
                client.Player.RemoveMoney(money);
                client.Player.RemoveGold(gold);
                client.Player.RemoveOffer(offer);
                client.Player.RemoveGiftToken(gifttoken);
                //client.Player.RemoveMedal(medal);

                string itemIDs = "";
                int annexIndex = 0;
                MailInfo message = new MailInfo();
                StringBuilder annexRemark = new StringBuilder();
                annexRemark.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark"));

                for (int i = 0; i < buyitems.Count; i++)
                {
                    itemIDs += (itemIDs == "" ? buyitems[i].TemplateID.ToString() : "," + buyitems[i].TemplateID.ToString());
                    if (client.Player.AddTemplate(buyitems[i], buyitems[i].Template.BagType, buyitems[i].Count))
                    {
                        if (dresses[i] && buyitems[i].CanEquip())
                        {
                            int slot = client.Player.MainBag.FindItemEpuipSlot(buyitems[i].Template);
                            if ((slot == 9 || slot == 10) && (places[i] == 9 || places[i] == 10))
                            {
                                slot = places[i];
                            }
                            else if ((slot == 7 || slot == 8) && (places[i] == 7 || places[i] == 8))
                            {
                                slot = places[i];
                            }

                            client.Player.MainBag.MoveItem(buyitems[i].Place, slot, 0);
                            msg = "UserBuyItemHandler.Save";
                        }
                    }
                    else
                    {
                        using (PlayerBussiness db = new PlayerBussiness())
                        {
                            buyitems[i].UserID = 0;
                            db.AddGoods(buyitems[i]);

                            annexIndex++;
                            annexRemark.Append(annexIndex);
                            annexRemark.Append("、");
                            annexRemark.Append(buyitems[i].Template.Name);
                            annexRemark.Append("x");
                            annexRemark.Append(buyitems[i].Count);
                            annexRemark.Append(";");
                            switch (annexIndex)
                            {
                                case 1:
                                    message.Annex1 = buyitems[i].ItemID.ToString();
                                    message.Annex1Name = buyitems[i].Template.Name;
                                    break;
                                case 2:
                                    message.Annex2 = buyitems[i].ItemID.ToString();
                                    message.Annex2Name = buyitems[i].Template.Name;
                                    break;
                                case 3:
                                    message.Annex3 = buyitems[i].ItemID.ToString();
                                    message.Annex3Name = buyitems[i].Template.Name;
                                    break;
                                case 4:
                                    message.Annex4 = buyitems[i].ItemID.ToString();
                                    message.Annex4Name = buyitems[i].Template.Name;
                                    break;
                                case 5:
                                    message.Annex5 = buyitems[i].ItemID.ToString();
                                    message.Annex5Name = buyitems[i].Template.Name;
                                    break;
                            }

                            if (annexIndex == 5)
                            {
                                annexIndex = 0;
                                message.AnnexRemark = annexRemark.ToString();
                                annexRemark.Remove(0, annexRemark.Length);
                                annexRemark.Append(LanguageMgr.GetTranslation("GoodsPresentHandler.AnnexRemark"));

                                message.Content = LanguageMgr.GetTranslation("UserBuyItemHandler.Title") + message.Annex1Name + "]";
                                message.Gold = 0;
                                message.Money = 0;
                                message.Receiver = client.Player.PlayerCharacter.NickName;
                                message.ReceiverID = client.Player.PlayerCharacter.ID;
                                message.Sender = message.Receiver;
                                message.SenderID = message.ReceiverID;
                                message.Title = message.Content;
                                message.Type = (int)eMailType.BuyItem;
                                db.SendMail(message);

                                eMsg = eMessageType.ERROR;
                                msg = "UserBuyItemHandler.Mail";

                                message.Revert();
                            }
                        }
                    }
                }

                if (annexIndex > 0)
                {
                    using (PlayerBussiness db = new PlayerBussiness())
                    {
                        message.AnnexRemark = annexRemark.ToString();
                        message.Content = LanguageMgr.GetTranslation("UserBuyItemHandler.Title") + message.Annex1Name + "]";
                        message.Gold = 0;
                        message.Money = 0;
                        message.Receiver = client.Player.PlayerCharacter.NickName;
                        message.ReceiverID = client.Player.PlayerCharacter.ID;
                        message.Sender = message.Receiver;
                        message.SenderID = message.ReceiverID;
                        message.Title = message.Content;
                        message.Type = (int)eMailType.BuyItem;
                        db.SendMail(message);

                        eMsg = eMessageType.ERROR;
                        msg = "UserBuyItemHandler.Mail";
                    }
                }

                if (eMsg == eMessageType.ERROR)
                {
                    client.Out.SendMailResponse(client.Player.PlayerCharacter.ID, eMailRespose.Receiver);
                }

                client.Player.OnPaid(money, gold, offer, gifttoken, medal, payGoods.ToString());//触发任务事件

                LogMgr.LogMoneyAdd(LogMoneyType.Shop, LogMoneyType.Shop_Buy, client.Player.PlayerCharacter.ID, money, client.Player.PlayerCharacter.Money, gold, gifttoken, offer, medal, "牌子编号", itemIDs, types.ToString());
            }
            else
            {
                if (gold > client.Player.PlayerCharacter.Gold)
                {
                    msg = "UserBuyItemHandler.NoGold";
                }
                if (offer > client.Player.PlayerCharacter.Offer)
                {
                    msg = "UserBuyItemHandler.NoOffer";
                }
                if (gifttoken > client.Player.PlayerCharacter.GiftToken)
                {
                    msg = "UserBuyItemHandler.GiftToken";
                }
                if (medal > client.Player.PlayerCharacter.medal)
                {
                    msg = "UserBuyItemHandler.Medal";
                }
                eMsg = eMessageType.ERROR;
            }

            client.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg));
            return 0;
        }
Esempio n. 7
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            int bagType = packet.ReadByte();
            int place = packet.ReadInt();

            PlayerInventory arkBag = client.Player.GetInventory((eBageType)bagType);
            ItemInfo goods = arkBag.GetItemAt(place);
            string full = "";

            List<ItemInfo> infos = new List<ItemInfo>();
            if (goods != null && goods.IsValidItem() &&
                goods.Template.CategoryID == 11 &&
                goods.Template.Property1 == 6 &&
                client.Player.PlayerCharacter.Grade >= goods.Template.NeedLevel)
            {
                int money = 0;
                int gold = 0;
                int giftToken = 0;
                int medal = 0;
                int[] bags = new int[3];
                OpenUpItem(goods.Template.Data, bags, infos, ref gold, ref money,ref giftToken, ref medal);
                bags[goods.GetBagType()]--;

                if (client.Player.RemoveTemplate(goods.TemplateID, 1)) //trminhpc
                {
                    //格式如:你获得了 数量 点券,数量 金币,武器/装备/美容,数量 道具
                     StringBuilder notice = new StringBuilder();
                    int index = 0;
                    StringBuilder msg = new StringBuilder();
                    msg.Append(LanguageMgr.GetTranslation("OpenUpArkHandler.Start"));

                    if (money != 0)
                    {
                        msg.Append(money + LanguageMgr.GetTranslation("OpenUpArkHandler.Money"));
                        client.Player.AddMoney(money);
                        LogMgr.LogMoneyAdd(LogMoneyType.Box, LogMoneyType.Box_Open, client.Player.PlayerCharacter.ID, money, client.Player.PlayerCharacter.Money, gold, 0, 0,0, "", "", "");//添加日志
                    }
                    if (gold != 0)
                    {
                        msg.Append(gold + LanguageMgr.GetTranslation("OpenUpArkHandler.Gold"));
                        client.Player.AddGold(gold);
                    }
                    if (giftToken != 0)
                    {
                        msg.Append(giftToken + LanguageMgr.GetTranslation("OpenUpArkHandler.GiftToken"));
                        client.Player.AddGiftToken(giftToken);
                    }
                    if (medal != 0) //trminhpc
                    {
                        msg.Append(medal + LanguageMgr.GetTranslation("OpenUpArkHandler.Medal"));
                        client.Player.AddMedal(medal);
                    }
                    StringBuilder msga = new StringBuilder();
                    foreach (ItemInfo info in infos)
                    {
                        //IBag bag = client.Player.GetBag(info.GetBagType());
                        //bag.AddItem(info);
                        //msg.Append((info.GetBagType() == 0 ? "" : info.Count.ToString()) + " " + info.Template.Name + ",");

                        msga.Append(info.Template.Name + "x" + info.Count.ToString() + ",");

                        if ((info.Template.Quality >= goods.Template.Property2) & (goods.Template.Property2 != 0))
                        {
                            notice.Append(info.Template.Name + ",");
                            index++;

                        }
                        //msg.Append(info.Template.Name + "x" + info.Count.ToString() + ",");
                        if (!client.Player.AddTemplate(info, info.Template.BagType, info.Count))
                        {
                            using (PlayerBussiness db = new PlayerBussiness())
                            {
                                info.UserID = 0;
                                db.AddGoods(info);

                                MailInfo message = new MailInfo();
                                message.Annex1 = info.ItemID.ToString();
                                message.Content = LanguageMgr.GetTranslation("OpenUpArkHandler.Content1") + info.Template.Name + LanguageMgr.GetTranslation("OpenUpArkHandler.Content2");
                                message.Gold = 0;
                                message.Money = 0;
                                message.Receiver = client.Player.PlayerCharacter.NickName;
                                message.ReceiverID = client.Player.PlayerCharacter.ID;
                                message.Sender = message.Receiver;
                                message.SenderID = message.ReceiverID;
                                message.Title = LanguageMgr.GetTranslation("OpenUpArkHandler.Title") + info.Template.Name + "]";
                                message.Type = (int)eMailType.OpenUpArk;
                                db.SendMail(message);
                                full = LanguageMgr.GetTranslation("OpenUpArkHandler.Mail");
                            }
                        }
                    }
                    if (msga.Length > 0)
                    {
                        msga.Remove(msga.Length - 1, 1);
                        string[] msgstr = msga.ToString().Split(',');
                        for (int i = 0; i < msgstr.Length; i++)
                        {
                            int counts = 1;  //统计重复数量

                            //先统计重复数量
                            for (int j = i + 1; j < msgstr.Length; j++)
                            {
                                //重复,则更变字符串;
                                if (msgstr[i].Contains(msgstr[j]) && msgstr[j].Length == msgstr[i].Length)
                                {
                                    counts++;
                                    msgstr[j] = j.ToString();
                                }
                            }

                            //重复数字入串
                            if (counts > 1)
                            {
                                msgstr[i] = msgstr[i].Remove(msgstr[i].Length - 1, 1);
                                msgstr[i] = msgstr[i] + counts.ToString();
                            }

                            //判断是否留字符串
                            if (msgstr[i] != i.ToString())
                            {
                                msgstr[i] = msgstr[i] + ",";
                                msg.Append(msgstr[i]);
                            }

                        }
                    }
                    if (goods.Template.Property2 != 0 & index > 0)
                    {
                        string msg1 = LanguageMgr.GetTranslation("OpenUpArkHandler.Notice", client.Player.PlayerCharacter.NickName, goods.Template.Name, notice, notice.Remove(notice.Length - 1, 1));

                        //client.Out.SendSystemNotice(msg);

                        GSPacketIn pkg1 = new GSPacketIn((byte)ePackageType.SYS_NOTICE);
                        pkg1.WriteInt(2);
                        pkg1.WriteString(msg1);

                        GameServer.Instance.LoginServer.SendPacket(pkg1);

                        GamePlayer[] players = Game.Server.Managers.WorldMgr.GetAllPlayers();

                        foreach (GamePlayer p in players)
                        {
                            if (p != client.Player)
                                p.Out.SendTCP(pkg1);
                        }
                    }
                    msg.Remove(msg.Length - 1, 1);
                    msg.Append(".");
                    client.Out.SendMessage(eMessageType.Normal, full + msg.ToString());

                    if (!string.IsNullOrEmpty(full))
                    {
                        //GameServer.Instance.LoginServer.SendMailResponse(client.Player.PlayerCharacter.ID);
                        client.Out.SendMailResponse(client.Player.PlayerCharacter.ID, eMailRespose.Receiver);
                    }
                }
            }
            return 1;
        }