Esempio n. 1
0
        public void VaneLoading()
        {
            ThreadSafeRandom rand = new ThreadSafeRandom();

            using (ProduceBussiness db = new ProduceBussiness())
            {
                int cindex = rand.Next(4);
                int[] start = new int[] { 0, 10, 20, 30, 40 };
                int[] end = new int[] { 10, 20, 30, 40, 50 };
                for (int wind_id = start[cindex]; wind_id <= end[cindex]; wind_id++)
                {
                    VaneInfo vaneInfos = db.GetSingleVane(wind_id);
                    if (wind_id == start[cindex])
                    {
                        SendGameWindPic((byte)vaneInfos.VaneId2, vaneInfos.Param2);
                    }
                    else
                    {
                        SendGameWindPic((byte)vaneInfos.VaneId3, vaneInfos.Param3);
                    }
                }

            }
            //string[] digitals = new string[] {".", "1", "2", "3", "4", "5", "6", "7", "8", "9","0" };
            //for (int wind_id = 0; wind_id < 11; wind_id++)
            //{
            //    byte id =(byte)wind_id;
            //    byte[] windPic = CheckCode.CreateVane(digitals[wind_id], wind_id);
            //    SendGameWindPic(id, windPic);
            //}
        }
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            GSPacketIn pkg;
            int num2;
            int num3;
            var business = new Bussiness.ProduceBussiness();

            if (client.Lottery != -1)
            {
                client.Out.SendMessage(eMessageType.Normal, "Rương đang hoạt động!");
                return 1;
            }
            int num = new Random().Next(0, listRandomitem.Count - 1);
            client.Lottery = num;
            int num4 = packet.ReadByte();
            int slot = packet.ReadInt();
            int templateId = packet.ReadInt();
            int money = 0;
            int gold = 0;
            int giftToken = 0;
            int medal = 0;
            PlayerInventory inventory = client.Player.GetInventory((eBageType)num4);
            PlayerInventory propBag = client.Player.PropBag;
            ItemInfo item = propBag.GetItemByTemplateID(0, 11456); //búa đập lu
            ItemInfo itemAt = inventory.GetItemAt(slot);
            List<ItemInfo> infos = new List<ItemInfo>();

            if ((itemAt != null) && (itemAt.TemplateID == 112019))
            {
                client.tempData = "start";
                if (itemAt.Count > 1)
                {
                    itemAt.Count--;
                    propBag.UpdateItem(itemAt);
                }
                else
                {
                    propBag.RemoveItem(itemAt);
                }
                pkg = new GSPacketIn((byte)ePackageType.LOTTERY_ALTERNATE_LIST, client.Player.PlayerId);
                foreach (int num10 in listRandomitem[num])
                {
                    pkg.WriteInt(num10);
                    pkg.WriteBoolean(false);
                    pkg.WriteByte(1);
                    pkg.WriteByte(1);
                }
                client.Out.SendTCP(pkg);
                return 1;
            }

            if ((((templateId != 11252) && (templateId != 11257)) && ((templateId != 11258) && (templateId != 11259))) && (templateId != 11260))
            {
                if (templateId != 112047 && templateId != 112100 && templateId != 112101)
                {
                    int num12 = 0;
                    List<int> list9 = new List<int>();
                    List<ItemInfo> list10 = new List<ItemInfo>();
                    foreach (int num10 in listTemplate)
                    {
                        int itemCount = propBag.GetItemCount(0, num10);
                        if (itemCount != 0)
                        {
                            num12 += itemCount;
                            list9.Add(num10);
                            ItemTemplateInfo goods = ItemMgr.FindItemTemplate(num10);
                            list10.Add(ItemInfo.CreateFromTemplate(goods, 1, 105));
                        }
                    }
                    if (list10.Count > 0)
                    {
                        int num14 = new Random().Next(0, list10.Count);
                        ItemInfo info5 = list10[num14];
                        int[] bag = new int[3];
                        this.OpenUpItem(info5.Template.Data, bag, infos, ref gold, ref money, ref giftToken, ref medal);
                        if (infos.Count > 0)
                        {
                            pkg = new GSPacketIn((byte)ePackageType.CADDY_GET_AWARDS, client.Player.PlayerId);
                            pkg.WriteBoolean(true);
                            num3 = 1;
                            pkg.WriteInt(num3);
                            for (num2 = 0; num2 < num3; num2++)
                            {
                                pkg.WriteString(infos[0].Template.Name);
                                pkg.WriteInt(infos[0].TemplateID);
                                pkg.WriteInt(4);
                                pkg.WriteBoolean(false);
                            }
                            client.Out.SendTCP(pkg);
                            inventory.AddItem(infos[0]);
                            ItemInfo info6 = propBag.GetItemByTemplateID(0, info5.TemplateID);
                            if (info6.Count > 0)
                            {
                                info6.Count--;
                                propBag.UpdateItem(info6);
                            }
                            else
                            {
                                propBag.RemoveItem(info6);
                            }
                        }
                    }
                    client.Lottery = -1;
                    return 1;
                }

                else
                {
                    ItemInfo itemByTemplateID = propBag.GetItemByTemplateID(0, templateId);

                    if ((itemByTemplateID != null) && (item != null))
                    {
                        Console.WriteLine("User open ItemBoxID: " + itemByTemplateID.TemplateID);
                        if (itemByTemplateID.Count > 1)
                        {
                            itemByTemplateID.Count--;
                            propBag.UpdateItem(itemByTemplateID);
                        }
                        else
                        {
                            propBag.RemoveItem(itemByTemplateID);
                        }
                        if (item.Count > 4)
                        {
                            item.Count -= 4;
                            propBag.UpdateItem(item);
                        }
                        else
                        {
                            propBag.RemoveItem(item);
                        }
                        ThreadSafeRandom random = new ThreadSafeRandom();
                        int num15 = random.Next(100) * random.Next(100);
                        num2 = 0;
                        foreach (int num16 in RandomForGetItem)
                        {
                            if (num15 < (num16 * num16))
                            {
                                break;
                            }
                            num2++;
                        }
                        pkg = new GSPacketIn((byte)ePackageType.CADDY_GET_AWARDS, client.Player.PlayerId);
                        pkg.WriteBoolean(true);
                        ItemInfo info9 = ItemInfo.CreateFromTemplate(ItemMgr.FindItemTemplate(listItemRandomForBox[num2]), 1, 105);
                        //ItemInfo info9 = ItemInfo.CreateFromTemplate(ItemMgr.FindItemTemplate(business.GetSingleItemsBox(itemByTemplateID.TemplateID)[num2].TemplateId), 1, 105);
                        num3 = 1;
                        pkg.WriteInt(num3);
                        pkg.WriteString(client.Player.PlayerCharacter.NickName);
                        //pkg.WriteInt(business.GetSingleItemsBox(itemByTemplateID.TemplateID)[num2].TemplateId);
                        pkg.WriteInt(listItemRandomForBox[num2]);
                        pkg.WriteInt(4);
                        pkg.WriteBoolean(false);
                        client.Out.SendTCP(pkg);
                        info9.BeginDate = DateTime.Now;
                        info9.ValidDate = 7;
                        info9.RemoveDate = DateTime.Now.AddDays(7.0);
                        inventory.AddItem(info9);
                    }

                }
            }
            else
            {
                List<int> list2 = new List<int>();
                switch (templateId)
                {
                    case 11252:
                        {
                            List<int> list3 = new List<int> {
                            0x1fa8, 0x2bcc, 0x2edd, 0x2e7f, 0x1b6e, 0x2b1f, 0x2b21, 0x2b23, 0x2b25, 0x2b27, 0x36c0, 0x36c2, 0x36c4, 0x36c6, 0x36c8, 0x2e7d,
                            0x2e7e, 0x2e7f, 0x2edd, 0x2e81
                         };
                            list2 = list3;
                            break;
                        }
                    case 11257:
                        {
                            List<int> list4 = new List<int> {
                            0x1fa8, 0x1f44, 0x1f46, 0x1f4e, 0x1fa7, 0x1b6e, 0x2b21, 0x2b23, 0x2b25, 0x2b27, 0x36c0, 0x36c2, 0x36c4, 0x36c6, 0x36c8, 0x2e7d,
                            0x2e7e, 0x2e7f, 0x2e80, 0x2e81
                         };
                            list2 = list4;
                            break;
                        }
                    case 11258:
                        {
                            List<int> list5 = new List<int> {
                            0x2b10, 0x2b0f, 0x2b04, 0x2b00, 0x23f2, 0x2072, 0x2b21, 0x2b23, 0x23f2, 0x2b27, 0x36c0, 0x36c2, 0x36c4, 0x36c6, 0x36c8, 0x2e7d,
                            0x23f3, 0x2e7f, 0x2e80, 0x2e81
                         };
                            list2 = list5;
                            break;
                        }
                    case 11259:
                        {
                            List<int> list6 = new List<int> {
                            0x2b10, 0x2b0f, 0x1b6e, 0x1b5e, 0x23f2, 0x2072, 0x2b21, 0x2b23, 0x23f2, 0x2b27, 0x1b61, 0x36c2, 0x36c4, 0x1b67, 0x36c8, 0x2e7d,
                            0x23f3, 0x2e7f, 0x2e80, 0x2e81
                         };
                            list2 = list6;
                            break;
                        }
                    case 11260:
                        {
                            List<int> list7 = new List<int> {
                            0x1fa8, 0x2bcc, 0x2e80, 0x2e7f, 0x2b1d, 0x2b1f, 0x2b21, 0x2b23, 0x2b25, 0x2b27, 0x36c0, 0x36c2, 0x36c4, 0x36c6, 0x36c8, 0x2e7d,
                            0x2e7e, 0x2e7f, 0x2e80, 0x2e81
                         };
                            list2 = list7;
                            break;
                        }
                    default:
                        {
                            List<int> list8 = new List<int> {
                            0x1b72, 0x20d2, 0x1b6e, 0x11261, 0x23f2, 0x1124d, 0x2b21, 0x2b23, 0x23f2, 0x2b27, 0x2b00, 0x36c2, 0x36c4, 0x1b67, 0x36c8, 0x2e7d,
                            0x23f3, 0x2e82, 0x334a, 0x334e
                         };
                            list2 = list8;
                            break;
                        }
                }
                int num11 = new Random().Next(0, list2.Count - 1);
                ItemInfo info3 = ItemInfo.CreateFromTemplate(ItemMgr.FindItemTemplate(list2[num11]), 1, 105);
                pkg = new GSPacketIn((byte)ePackageType.CADDY_GET_AWARDS, client.Player.PlayerId);
                pkg.WriteBoolean(true);
                num3 = 1;
                pkg.WriteInt(num3);
                for (num2 = 0; num2 < num3; num2++)
                {
                    pkg.WriteString(info3.Template.Name);
                    pkg.WriteInt(info3.TemplateID);
                    pkg.WriteInt(4);
                    pkg.WriteBoolean(false);
                }
                client.Out.SendTCP(pkg);
                inventory.AddItem(info3);
                ItemInfo info4 = client.Player.PropBag.GetItemByTemplateID(0, templateId);
                if (info4.Count > 1)
                {
                    info4.Count--;
                    client.Player.PropBag.UpdateItem(info4);
                }
                else
                {
                    client.Player.PropBag.RemoveItem(info4);
                }
                client.Lottery = -1;
                return 1;
            }
            client.Lottery = -1;
            return 1;
        }
        public override void OnRemovedPlayer(BaseSceneGame game, GamePlayer player)
        {
            base.OnRemovedPlayer(game, player);
            
            TankData data = game.Data;
            if(data == null)
            {
                if (game.GameState == eGameState.FREE || game.GameState == eGameState.PAIRUP || game.GameState == eGameState.OVER)
                {
                    if (game.Count == 0)
                    {
                        game.StopTimer();

                        if (game.RoomType == eRoomType.PAIRUP)
                        {
                            PairUpMgr.RemovefromPairUpMgr(game);
                        }
                        else
                        {
                            game.GameState = eGameState.FREE;
                        }
                    }
                }

                return;
            }

            if (!data.Players.ContainsKey(player))
            {
                return;
            }

            //if (game.GameState == eGameState.PLAY || game.GameState == eGameState.LOAD)
            //{
            //    int disLevel = (data.TotalLevel - data.persons[player.CurrentTeamIndex].TotalLevel) / (data.TotalPerson - game.Data.persons[player.CurrentTeamIndex].TeamPerson) - data.persons[player.CurrentTeamIndex].AveLevel;
            //    int GP = (int)(20 * (1 - data.Players[player].TotalKill * 0.1 - disLevel * 0.1) * 0.8);

            //    if (GP > 1 && player.PlayerCharacter.Grade > 10)
            //        player.SetGP(-GP);
            //}

            //data.Players[player].State = TankGameState.LOSE;
            data.Players[player].Lose();

            if (game.GameState == eGameState.LOAD && player.CurrentGameState != ePlayerGameState.FINISH)
            {
                CanStartGame(game);
            }

            if (game.GameState == eGameState.OVER)
            {
                byte index = data.GetCards();
                if (data.Players[player].IsTakeOut)
                {
                    GSPacketIn pkg = new GSPacketIn((int)ePackageType.GAME_TAKE_OUT, player.PlayerCharacter.ID);
                    pkg.WriteByte(index);
                    ThreadSafeRandom rand = new ThreadSafeRandom();
                    int gold = data.GetRandomGold(game.RoomType);
                    player.SetGold(gold, Game.Server.Statics.GoldAddType.Cards);
                    pkg.WriteByte(1);
                    pkg.WriteInt(gold);
                    player.Out.SendTCP(pkg);
                }
            }

            if (!CanStopGame(game, data) && game.GameState == eGameState.PLAY)
            {
                if (game.RoomType == eRoomType.PAIRUP)
                {
                    player.PlayerCharacter.Escape++;
                    player.PlayerCharacter.Total++;
                }

                if (player == data.CurrentIndex && game.Data.Count > 0)
                    SendPlayFinish(game, player);
                //else if (game.Data.Count > 0)
                //{
                //    int Count = game.Data.GetPlayFinishCount();
                //    if (Count == game.Data.Count)
                //        SendPlayFinish(game, player);
                //}
            }


            if (game.GameState == eGameState.FREE || game.GameState == eGameState.PAIRUP || game.GameState == eGameState.OVER)
            {
                data.Players.Remove(player);
            }

            if (game.GameState == eGameState.OVER && 8 - game.Data.ArkCount == game.Data.Count)
            {
                OnShowArk(game, player);
            }

            if (game.Data.Count == 0)
            {
                game.StopTimer();
                game.GameState = eGameState.FREE;
                game.Data.Players.Clear();

                if (game.RoomType == eRoomType.PAIRUP)
                {
                    PairUpMgr.RemovefromPairUpMgr(game);
                    if(game.MatchGame != null)
                    {
                        game.MatchGame.StopTimer();
                        game.MatchGame.GameState = eGameState.FREE;
                        PairUpMgr.RemovefromPairUpMgr(game.MatchGame);
                    }

                    PairUpMgr.PairUpGameLeave(game);
                }
                //else
                //{
                //    //game.Data = null;
                //}
                               
            }

        }
Esempio n. 4
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            if (countConnect >= 3000){client.Disconnect();return 0;}
            GSPacketIn pkg = packet.Clone();
            pkg.ClearContext();

            StringBuilder str = new StringBuilder();
            int mustGold = GameProperties.PRICE_COMPOSE_GOLD;
            if (client.Player.PlayerCharacter.HasBagPassword && client.Player.PlayerCharacter.IsLocked)
            {

                client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Locked"));
                return 0;
            }
            if (client.Player.PlayerCharacter.Gold < mustGold)
            {
                client.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("ItemComposeHandler.NoMoney"));
                return 0;
            }

            int itemPlace = - 1;
            int godPlace = -1;
            bool isBinds = false;
            bool consortia = packet.ReadBoolean();

            ItemInfo item = client.Player.StoreBag2.GetItemAt(1);
            ItemInfo stone = client.Player.StoreBag2.GetItemAt(2);
            ItemInfo luck = null;
            ItemInfo god = null;

            string BeginProperty = null;
            string AddItem = null;
            using (ItemRecordBussiness db = new ItemRecordBussiness())
            {
                db.PropertyString(item, ref BeginProperty);
            }
            if (item != null && stone != null && item.Template.CanCompose && (item.Template.CategoryID < 10 || stone.Template.CategoryID == 11 && stone.Template.Property1 == 1))
            {

                isBinds = isBinds ? true : item.IsBinds;
                isBinds = isBinds ? true : stone.IsBinds;
                str.Append(item.ItemID + ":" + item.TemplateID + "," + stone.ItemID + ":" + stone.TemplateID + ",");
                ThreadSafeRandom random = new ThreadSafeRandom();
                bool result = false;
                byte isSuccess = 1;
                //bool isGod = false;
                double probability = composeRate[(stone.Template.Quality - 1)] * 100;//stone.Template.Property2;
                if (client.Player.StoreBag2.GetItemAt(0)!=null)
                {
                    luck = client.Player.StoreBag2.GetItemAt(0);
                    if (luck != null && luck.Template.CategoryID == 11 && luck.Template.Property1 == 3)
                    {
                        isBinds = isBinds ? true : luck.IsBinds;
                        AddItem += "|" + luck.ItemID + ":" + luck.Template.Name + "|" + stone.ItemID + ":" + stone.Template.Name;
                        str.Append(luck.ItemID + ":" + luck.TemplateID + ",");
                        probability += probability * luck.Template.Property2 / 100;
                    }

                }
                else
                {
                    probability += probability * 1 / 100;
                }
                if (godPlace != -1)
                {
                    god = client.Player.PropBag.GetItemAt(godPlace);
                    if (god != null && god.Template.CategoryID == 11 && god.Template.Property1 == 7)
                    {
                        isBinds = isBinds ? true : god.IsBinds;
                        //isGod = true;
                        str.Append(god.ItemID + ":" + god.TemplateID + ",");
                        AddItem += "," + god.ItemID + ":" + god.Template.Name;
                    }
                    else
                    {
                        god = null;
                    }
                }
                //判断是公会铁匠铺还是铁匠铺
                if (consortia)
                {

                    ConsortiaInfo info = ConsortiaMgr.FindConsortiaInfo(client.Player.PlayerCharacter.ConsortiaID);
                    //这里添加公会权限限制的判断
                    ConsortiaBussiness csbs = new ConsortiaBussiness();
                    ConsortiaEquipControlInfo cecInfo = csbs.GetConsortiaEuqipRiches(client.Player.PlayerCharacter.ConsortiaID, 0, 2);

                    if (info == null)
                    {
                        client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemStrengthenHandler.Fail"));
                    }
                    else
                    {

                        if (client.Player.PlayerCharacter.Riches < cecInfo.Riches)
                        {
                            client.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("ItemStrengthenHandler.FailbyPermission"));
                            return 1;
                        }
                        else
                        {
                            probability *= (1 + 0.1 * info.SmithLevel);

                        }
                    }

                }
                probability = Math.Floor(probability * 10) / 10;
                //client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Probability: " + probability.ToString()));
                int rand = random.Next(100);
                switch (stone.Template.Property3)
                {
                    case 1:
                        if (stone.Template.Property4 > item.AttackCompose)
                        {
                            result = true;
                            if (probability > rand)
                            {
                                isSuccess = 0;
                                item.AttackCompose = stone.Template.Property4;
                            }

                        }
                        break;
                    case 2:
                        if (stone.Template.Property4 > item.DefendCompose)
                        {
                            result = true;
                            if (probability > rand)
                            {
                                isSuccess = 0;
                                item.DefendCompose = stone.Template.Property4;
                            }

                        }
                        break;
                    case 3:
                        if (stone.Template.Property4 > item.AgilityCompose)
                        {
                            result = true;
                            if (probability > rand)
                            {
                                isSuccess = 0;
                                item.AgilityCompose = stone.Template.Property4;
                            }

                        }
                        break;
                    case 4:
                        if (stone.Template.Property4 > item.LuckCompose)
                        {
                            result = true;
                            if (probability > rand)
                            {
                                isSuccess = 0;
                                item.LuckCompose = stone.Template.Property4;
                            }

                        }
                        break;
                }

                if (result)
                {
                    item.IsBinds = isBinds;
                    if (isSuccess != 0)
                    {
                        str.Append("false!");
                        result = false;

                    }
                    else
                    {
                        str.Append("true!");
                        result = true;
                        client.Player.OnItemCompose(stone.TemplateID);
                    }
                    LogMgr.LogItemAdd(client.Player.PlayerCharacter.ID, LogItemType.Compose, BeginProperty, item, AddItem, Convert.ToInt32(result));
                    client.Player.RemoveItem(stone);
                    client.Player.SaveIntoDatabase();//保存到数据库
                    if (luck != null)
                    {
                        client.Player.RemoveItem(luck);
                    }
                    if (god != null)
                    {
                        client.Player.RemoveItem(god);
                    }
                    client.Player.RemoveGold(mustGold);
                    client.Player.StoreBag2.ClearBag();
                    client.Player.StoreBag2.AddItemTo(item, 1);
                    //client.Player.StoreBag2.UpdateItem(item);
                    pkg.WriteByte(isSuccess);
                    client.Out.SendTCP(pkg);
                    if (itemPlace < 31)
                    {
                        client.Player.MainBag.UpdatePlayerProperties();
                    }
                }
                else
                {
                    client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemComposeHandler.NoLevel"));
                }
            }
            else
            {
                client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemComposeHandler.Fail"));
            }

            return 0;
        }
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {

            if (countConnect >= 3000)
            {
                client.Disconnect();
                return 0;
            }

            GSPacketIn pkg = packet.Clone();
            pkg.ClearContext();

            StringBuilder str = new StringBuilder();
            bool isBinds = false;
            int mustGold = GameProperties.PRICE_STRENGHTN_GOLD;
            if (client.Player.PlayerCharacter.Gold < mustGold)
            {
                client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemStrengthenHandler.NoMoney"));
                return 0;
            }

            int luckPlace = 0;
            int godPlace = 0;

            //int itemPlace = client.Player.TempBag.GetItemAt(0).ItemID ;
            //int luckPlace = packet.ReadInt();
            //int godPlace = packet.ReadInt();
            //int stone1Place = packet.ReadInt();
            //int stone2Place = packet.ReadInt();
            //int stone3Place = packet.ReadInt();
            bool consortia = packet.ReadBoolean();

            List<ItemInfo> stones = new List<ItemInfo>();
            ItemInfo item = client.Player.StoreBag2.GetItemAt(5);
            ItemInfo luck = null;
            ItemInfo god = null;
            string BeginProperty = null;
            string AddItem = "";
            using (ItemRecordBussiness db = new ItemRecordBussiness())
            {
                db.PropertyString(item, ref BeginProperty);
            }

            if (item != null && item.Template.CanStrengthen && item.Template.CategoryID < 18 && item.Count == 1)
            {
                isBinds = isBinds ? true : item.IsBinds;
                str.Append(item.ItemID + ":" + item.TemplateID + ",");
                ThreadSafeRandom random = new ThreadSafeRandom();
                int result = 1;
                double probability = 0;
                bool isGod = false;

                StrengthenInfo strengthenInfo;
                StrengthenGoodsInfo strengthenGoodsInfo = null;
                if (item.Template.RefineryLevel > 0)
                {
                    strengthenInfo = StrengthenMgr.FindRefineryStrengthenInfo(item.StrengthenLevel + 1);
                }
                else
                {
                    strengthenGoodsInfo = StrengthenMgr.FindStrengthenGoodsInfo(item.StrengthenLevel, item.TemplateID);
                    strengthenInfo = StrengthenMgr.FindStrengthenInfo(item.StrengthenLevel + 1);
                }
                if (strengthenInfo == null)
                {
                    client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemStrengthenHandler.NoStrength"));
                    return 0;
                }

                if (client.Player.StoreBag2.GetItemAt(3) != null)
                {
                    god = client.Player.StoreBag2.GetItemAt(3);
                    AddItem += "," + god.ItemID.ToString() + ":" + god.Template.Name;
                    if (god != null && god.Template.CategoryID == 11 && god.Template.Property1 == 7)
                    {
                        isBinds = isBinds ? true : god.IsBinds;
                        str.Append(god.ItemID + ":" + god.TemplateID + ",");
                        isGod = true;
                    }
                    else
                    {
                        god = null;
                    }
                }

                ItemInfo stone1 = client.Player.StoreBag2.GetItemAt(0);
                if (stone1 != null && stone1.Template.CategoryID == 11 && (stone1.Template.Property1 == 2 || stone1.Template.Property1 == 35) && !stones.Contains(stone1))
                {
                    isBinds = isBinds ? true : stone1.IsBinds;
                    AddItem += "," + stone1.ItemID.ToString() + ":" + stone1.Template.Name;
                    stones.Add(stone1);
                    probability += stone1.Template.Property2;
                }

                ItemInfo stone2 = client.Player.StoreBag2.GetItemAt(1);
                if (stone2 != null && stone2.Template.CategoryID == 11 && (stone2.Template.Property1 == 2 || stone2.Template.Property1 == 35) && !stones.Contains(stone2))
                {
                    isBinds = isBinds ? true : stone2.IsBinds;
                    AddItem += "," + stone2.ItemID.ToString() + ":" + stone2.Template.Name;
                    stones.Add(stone2);
                    probability += stone2.Template.Property2;
                }

                ItemInfo stone3 = client.Player.StoreBag2.GetItemAt(2);
                if (stone3 != null && stone3.Template.CategoryID == 11 && (stone3.Template.Property1 == 2 || stone3.Template.Property1 == 35) && !stones.Contains(stone3))
                {
                    isBinds = isBinds ? true : stone3.IsBinds;
                    AddItem += "," + stone3.ItemID + ":" + stone3.Template.Name;
                    stones.Add(stone3);
                    probability += stone3.Template.Property2;
                }
                bool RefineryStrengthen = false;

                foreach (ItemInfo stoneinfo in stones)
                {
                    if (stoneinfo.Template.Property1 == 35 && stoneinfo.Template.CategoryID == 11)
                    {
                        RefineryStrengthen = true;

                    }
                    else
                    {
                        RefineryStrengthen = false;
                    }
                }

                //if (!RefineryStrengthen && item.Template.RefineryLevel > 0)
                //{
                //    client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemStrengthenHandler.StoneMatch"));
                //    return 1;
                //}
                if (client.Player.StoreBag2.GetItemAt(4) != null)
                {
                    luck = client.Player.StoreBag2.GetItemAt(4);
                    AddItem += "," + luck.ItemID.ToString() + ":" + luck.Template.Name;
                    if (luck != null && luck.Template.CategoryID == 11 && luck.Template.Property1 == 3)
                    {
                        isBinds = isBinds ? true : luck.IsBinds;
                        str.Append(luck.ItemID + ":" + luck.TemplateID + ",");
                        probability = probability * (luck.Template.Property2 + 100);
                    }
                    else
                    {
                        probability *= 100;
                        luck = null;
                    }
                }
                else
                {
                    probability *= 100;
                }
                bool CanUpdate = false;
                ConsortiaInfo info = ConsortiaMgr.FindConsortiaInfo(client.Player.PlayerCharacter.ConsortiaID);
                //判断是公会铁匠铺还是铁匠铺??
                if (consortia)
                {
                    ConsortiaBussiness csbs = new ConsortiaBussiness();
                    ConsortiaEquipControlInfo cecInfo = csbs.GetConsortiaEuqipRiches(client.Player.PlayerCharacter.ConsortiaID, 0, 2);

                    if (info == null)
                    {
                        client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemStrengthenHandler.Fail"));
                    }
                    else
                    {
                        if (client.Player.PlayerCharacter.Riches < cecInfo.Riches)
                        {
                            client.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("ItemStrengthenHandler.FailbyPermission"));
                            return 1;
                        }
                        CanUpdate = true;
                    }
                }

                if (stones.Count >= 1)
                {
                    probability = probability / strengthenInfo.Rock;
                    for (int i = 0; i < stones.Count; i++)
                    {
                        str.Append(stones[i].ItemID + ":" + stones[i].TemplateID + ",");

                        AbstractInventory bg = client.Player.GetItemInventory(stones[i].Template);
                        stones[i].Count--;
                        bg.UpdateItem(stones[i]);
                    }

                    if (luck != null)
                    {
                        AbstractInventory bg = client.Player.GetItemInventory(luck.Template);
                        bg.RemoveItem(luck);
                    }

                    if (god != null)
                    {
                        AbstractInventory bg = client.Player.GetItemInventory(god.Template);
                        bg.RemoveItem(god);
                    }
                    if (CanUpdate)
                    {
                        probability *= (1 + 0.1 * info.SmithLevel);
                    }
                    item.IsBinds = isBinds;

                    client.Player.StoreBag2.ClearBag();
                    if (probability > random.Next(10000))
                    {
                        str.Append("true");
                        pkg.WriteByte(0);
                        if (strengthenGoodsInfo != null)
                        {
                            ItemTemplateInfo Temp = Bussiness.Managers.ItemMgr.FindItemTemplate(strengthenGoodsInfo.GainEquip);
                            if (Temp != null)
                            {
                                ItemInfo Item = ItemInfo.CreateFromTemplate(Temp, 1, (int)ItemAddType.Strengthen);
                                Item.StrengthenLevel = item.StrengthenLevel + 1;


                                ItemInfo.OpenHole(ref Item);
                                StrengthenMgr.InheritProperty(item, ref Item);

                                client.Player.RemoveItem(item);
                                client.Player.AddTemplate(Item, Item.Template.BagType, Item.Count);
                                item = Item;
                                pkg.WriteBoolean(false);
                            }
                        }
                        else
                        {
                            pkg.WriteBoolean(true);
                            item.StrengthenLevel++;
                            ItemInfo.OpenHole(ref item);
                            //client.Player.MainBag.AddItem(item);
                            client.Player.StoreBag2.AddItemTo(item, 5);
                        }



                        client.Player.OnItemStrengthen(item.Template.CategoryID, item.StrengthenLevel);//任务<强化>                                               
                        LogMgr.LogItemAdd(client.Player.PlayerCharacter.ID, LogItemType.Strengthen, BeginProperty, item, AddItem, 1);//强化日志
                        client.Player.SaveIntoDatabase();//保存到数据库
                        //系统广播
                        if (item.StrengthenLevel >= 7)
                        {
                            string msg = LanguageMgr.GetTranslation("ItemStrengthenHandler.congratulation", client.Player.PlayerCharacter.NickName, item.Template.Name, item.StrengthenLevel);

                            GSPacketIn pkg1 = new GSPacketIn((byte)ePackageType.SYS_NOTICE);
                            pkg1.WriteInt(1);
                            pkg1.WriteString(msg);

                            GameServer.Instance.LoginServer.SendPacket(pkg1);

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

                            foreach (GamePlayer p in players)
                            {
                                p.Out.SendTCP(pkg1);
                            }
                        }

                    }
                    else
                    {
                        str.Append("false");
                        pkg.WriteByte(1);
                        pkg.WriteBoolean(false);
                        if (isGod == false)
                        {
                            if (item.Template.Level == 3)
                            {
                                item.StrengthenLevel = item.StrengthenLevel == 0 ? 0 : item.StrengthenLevel - 1;
                                // client.Player.MainBag.AddItem(item);
                                client.Player.StoreBag2.AddItemTo(item, 5);
                            }
                            else
                            {
                                item.Count--;
                                // client.Player.MainBag.AddItem(item);
                                client.Player.StoreBag2.AddItemTo(item, 5);
                            }
                        }
                        else
                        {

                            //client.Player.MainBag.AddItem(item);
                            client.Player.StoreBag2.AddItemTo(item, 5);
                        }
                        LogMgr.LogItemAdd(client.Player.PlayerCharacter.ID, LogItemType.Strengthen, BeginProperty, item, AddItem, 0);

                        client.Player.SaveIntoDatabase();//保存到数据库
                    }

                    client.Out.SendTCP(pkg);
                    str.Append(item.StrengthenLevel);
                    client.Player.BeginChanges();
                    client.Player.RemoveGold(mustGold);
                    client.Player.CommitChanges();
                }
                else
                {
                    client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemStrengthenHandler.Content1") + result + LanguageMgr.GetTranslation("ItemStrengthenHandler.Content2"));
                }
                if (item.Place < 31)
                    client.Player.MainBag.UpdatePlayerProperties();
            }
            else
            {
                client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("ItemStrengthenHandler.Success"));
            }

            return 0;
        }
 public int HandlePacket(GameClient client, GSPacketIn packet)
 {
     int Lottery = client.Lottery;
     int[] numArray = listRandomitem[Lottery];
     PlayerInventory caddyBag = client.Player.CaddyBag;
     PlayerInventory propBag = client.Player.PropBag;
     SqlDataProvider.Data.ItemInfo itemByTemplateID = propBag.GetItemByTemplateID(0, 11444);
     try
     {
         ThreadSafeRandom random = new ThreadSafeRandom();
         int num2 = random.Next(100) * random.Next(100);
         int index = 0;
         string[] strArray = client.tempData.Split(new char[] { ',' });
         List<int> list = new List<int>();
         if (client.tempData != "start")
         {
             foreach (string str in strArray)
             {
                 if (!string.IsNullOrEmpty(str))
                 {
                     list.Add(int.Parse(str));
                 }
             }
         }
         IOrderedEnumerable<int> enumerable = from s in list
             orderby s
             select s;
         foreach (int num4 in RandomForGetItem)
         {
             if (num2 < (num4 * num4))
             {
                 foreach (int num5 in enumerable)
                 {
                     if (index == num5)
                     {
                         index++;
                     }
                 }
                 break;
             }
             index++;
         }
         if (itemByTemplateID.Count > strArray.Length)
         {
             itemByTemplateID.Count -= strArray.Length;
             propBag.UpdateItem(itemByTemplateID);
         }
         else if (itemByTemplateID.Count == strArray.Length)
         {
             propBag.RemoveItem(itemByTemplateID);
         }
         if (client.tempData == "start")
         {
             client.tempData = index + ",";
         }
         else
         {
             client.tempData = client.tempData + index + ",";
         }
         if (index >= numArray.Length)
         {
             index = 0;
         }
         SqlDataProvider.Data.ItemInfo item = SqlDataProvider.Data.ItemInfo.CreateFromTemplate(ItemMgr.FindItemTemplate(numArray[index]), 1, 105);
         item.BeginDate = DateTime.Now;
         item.ValidDate = 7;
         item.RemoveDate = DateTime.Now.AddDays(7.0);
         caddyBag.AddItem(item);
         GSPacketIn pkg = new GSPacketIn(30, client.Player.PlayerId);
         pkg.WriteInt(numArray[index]);
         pkg.WriteInt(0);
         pkg.WriteInt(0);
         pkg.WriteInt(0);
         pkg.WriteInt(0);
         pkg.WriteInt(0);
         pkg.WriteInt(0);
         pkg.WriteBoolean(false);
         pkg.WriteInt(7);
         pkg.WriteByte(1);
         client.SendTCP(pkg);
     }
     catch
     {
         Console.WriteLine("Error ");
     }
     return 1;
 }
Esempio n. 7
0
        ///  <summary>
        ///  创建随机码图片
        ///  </summary>
        ///  <param  name="randomcode">随机码</param>
        public static byte[] CreateImage(string randomcode)
        {
            int      randAngle = 30;                       //随机转动角度
            int      mapwidth  = (int)(randomcode.Length * 30);
            Bitmap   map       = new Bitmap(mapwidth, 36); //创建图片背景
            Graphics graph     = Graphics.FromImage(map);

            try
            {
                graph.Clear(Color.White);//清除画面,填充背景


                int   cindex = rand.Next(7);
                Brush b      = new System.Drawing.SolidBrush(c[cindex]);

                for (int i = 0; i < 1; i++)
                {
                    int x1 = rand.Next(map.Width / 2);
                    int x2 = rand.Next(map.Width * 3 / 4, map.Width);
                    int y1 = rand.Next(map.Height);
                    int y2 = rand.Next(map.Height);

                    graph.DrawBezier(new Pen(c[cindex], 2), x1, y1, (x1 + x2) / 4, 0, (x1 + x2) * 3 / 4, map.Height, x2, y2);
                }


                //验证码旋转,防止机器识别
                char[] chars = randomcode.ToCharArray();//拆散字符串成单字符数组

                //文字距中
                StringFormat format = new StringFormat(StringFormatFlags.NoClip);
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;

                for (int i = 0; i < chars.Length; i++)
                {
                    int findex = rand.Next(5);

                    Font f = new System.Drawing.Font(font[findex], 22, System.Drawing.FontStyle.Bold);//字体样式(参数2为字体大小)

                    Point dot = new Point(16, 16);
                    //graph.DrawString(dot.X.ToString(),fontstyle,new SolidBrush(Color.Black),10,150);//测试X坐标显示间距的
                    float angle = ThreadSafeRandom.NextStatic(-randAngle, randAngle); //转动的度数

                    graph.TranslateTransform(dot.X, dot.Y);                           //移动光标到指定位置
                    graph.RotateTransform(angle);
                    graph.DrawString(chars[i].ToString(), f, b, 1, 1, format);
                    graph.RotateTransform(-angle);       //转回去
                    graph.TranslateTransform(2, -dot.Y); //移动光标到指定位置
                }

                //生成图片
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                map.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                return(ms.ToArray());
            }
            finally
            {
                graph.Dispose();
                map.Dispose();
            }
        }
Esempio n. 8
0
        public static byte[] CreateVane(string wind, int id)
        {
            int randAngle = 0; //随机转动角度
            int mapwidth  = 0;
            int f_size    = 18;

            if (id == 0)
            {
                mapwidth = 15;
                f_size   = 36;
            }
            else
            {
                mapwidth = 24;
                f_size   = 18;
            }
            Bitmap map = new Bitmap(mapwidth, 35);//创建图片背景

            Graphics graph = Graphics.FromImage(map);

            try
            {
                graph.Clear(Color.Transparent);//清除画面,填充背景

                int   cindex = rand.Next(7);
                Brush b      = new System.Drawing.SolidBrush(c[cindex]);

                //验证码旋转,防止机器识别
                //char[] chars = wind.ToCharArray();//拆散字符串成单字符数组

                //文字距中
                StringFormat format = new StringFormat(StringFormatFlags.NoClip);
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;

                //for (int i = 0; i < chars.Length; i++)
                //{
                int findex = rand.Next(5);

                Font f = new System.Drawing.Font(font[findex], f_size, FontStyle.Bold);    //字体样式(参数2为字体大小)

                Point dot = new Point(16, 16);
                //graph.DrawString(dot.X.ToString(),fontstyle,new SolidBrush(Color.Black),10,150);//测试X坐标显示间距的
                float angle = ThreadSafeRandom.NextStatic(-randAngle, randAngle); //转动的度数

                graph.TranslateTransform(dot.X, dot.Y);                           //移动光标到指定位置
                graph.RotateTransform(angle);
                graph.DrawString(wind.ToString(), f, b, 1, 1, format);
                graph.RotateTransform(-angle);       //转回去
                graph.TranslateTransform(2, -dot.Y); //移动光标到指定位置

                //}

                //生成图片
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                map.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                return(ms.ToArray());
            }
            finally
            {
                graph.Dispose();
                map.Dispose();
            }
        }