public void OpenUpItem(string data, List <ItemInfo> infos, ref int gold, ref int money, ref int giftToken, ref int medal)
 {
     if (!string.IsNullOrEmpty(data))
     {
         ItemBoxMgr.CreateItemBox(Convert.ToInt32(data), infos, ref gold, ref money, ref giftToken, ref medal);
     }
 }
예제 #2
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            int num       = packet.ReadInt();
            int receiebox = packet.ReadInt();

            packet.ReadInt();
            packet.ReadInt();
            bool            result     = false;
            List <ItemInfo> list       = new List <ItemInfo>();
            int             iD         = client.Player.PlayerCharacter.ID;
            int             receiebox2 = client.Player.PlayerCharacter.receiebox;
            string          message    = "Nhận rương thời gian thành công!";

            switch (num)
            {
            case 0:
                client.Player.UpdateTimeBox(receiebox, 20, 0);
                client.Out.SendGetBoxTime(iD, receiebox2, result);
                break;

            case 1:
                result = true;
                list   = ItemBoxMgr.GetItemBoxAward(ItemMgr.FindItemBoxTemplate(receiebox2).TemplateID);
                foreach (ItemInfo current in list)
                {
                    if (!client.Player.AddTemplate(current, current.Template.BagType, current.Count))
                    {
                        using (PlayerBussiness playerBussiness = new PlayerBussiness())
                        {
                            current.UserID = 0;
                            playerBussiness.AddGoods(current);
                            MailInfo mailInfo = new MailInfo();
                            mailInfo.Annex1     = current.ItemID.ToString();
                            mailInfo.Content    = "Phần thưởng từ rương thời gian.";
                            mailInfo.Gold       = 0;
                            mailInfo.Money      = 0;
                            mailInfo.Receiver   = client.Player.PlayerCharacter.NickName;
                            mailInfo.ReceiverID = client.Player.PlayerCharacter.ID;
                            mailInfo.Sender     = mailInfo.Receiver;
                            mailInfo.SenderID   = mailInfo.ReceiverID;
                            mailInfo.Title      = "Mở rương thời gian!";
                            mailInfo.Type       = 12;
                            playerBussiness.SendMail(mailInfo);
                            message = "Túi đã đầy, vật phẩm đã được chuyển vào thư!";
                        }
                        client.Out.SendMailResponse(client.Player.PlayerCharacter.ID, eMailRespose.Receiver);
                    }
                }
                client.Out.SendGetBoxTime(iD, receiebox2, result);
                client.Out.SendMessage(eMessageType.Normal, message);
                break;
            }
            return(0);
        }
예제 #3
0
        public override bool Start()
        {
            if (m_isRunning)
            {
                return(false);
            }
            try
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                Thread.CurrentThread.Priority = ThreadPriority.Normal;

                GameProperties.Refresh();


                if (!InitComponent(RecompileScripts(), "Recompile Scripts"))
                {
                    return(false);
                }

                if (!InitComponent(StartScriptComponents(), "Script components"))
                {
                    return(false);
                }

                if (!InitComponent((GameProperties.EDITION == Edition), "Edition:" + Edition))
                {
                    return(false);
                }

                if (!InitComponent(InitSocket(IPAddress.Parse(Configuration.Ip), Configuration.Port), "InitSocket Port:" + Configuration.Port))
                {
                    return(false);
                }

                if (!InitComponent(AllocatePacketBuffers(), "AllocatePacketBuffers()"))
                {
                    return(false);
                }

                if (!InitComponent(LogMgr.Setup(Configuration.GAME_TYPE, Configuration.ServerID, Configuration.AreaID), "LogMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(WorldMgr.Init(), "WorldMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(MapMgr.Init(), "MapMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(ItemMgr.Init(), "ItemMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(ItemBoxMgr.Init(), "ItemBox Init"))
                {
                    return(false);
                }

                if (!InitComponent(BallMgr.Init(), "BallMgr Init"))
                {
                    return(false);
                }
                if (!InitComponent(BallConfigMgr.Init(), "BallConfigMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(FusionMgr.Init(), "FusionMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(AwardMgr.Init(), "AwardMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(NPCInfoMgr.Init(), "NPCInfoMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(MissionInfoMgr.Init(), "MissionInfoMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(PveInfoMgr.Init(), "PveInfoMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(DropMgr.Init(), "Drop Init"))
                {
                    return(false);
                }

                if (!InitComponent(FightRateMgr.Init(), "FightRateMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(ConsortiaLevelMgr.Init(), "ConsortiaLevelMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(RefineryMgr.Init(), "RefineryMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(StrengthenMgr.Init(), "StrengthenMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(PropItemMgr.Init(), "PropItemMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(ShopMgr.Init(), "ShopMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(QuestMgr.Init(), "QuestMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(RoomMgr.Setup(Configuration.MaxRoomCount), "RoomMgr.Setup"))
                {
                    return(false);
                }

                if (!InitComponent(GameMgr.Setup(Configuration.ServerID, GameProperties.BOX_APPEAR_CONDITION), "GameMgr.Start()"))
                {
                    return(false);
                }

                if (!InitComponent(ConsortiaMgr.Init(), "ConsortiaMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(LanguageMgr.Setup(@""), "LanguageMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(RateMgr.Init(Configuration), "ExperienceRateMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(MacroDropMgr.Init(), "MacroDropMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(BattleMgr.Setup(), "BattleMgr Setup"))
                {
                    return(false);
                }

                if (!InitComponent(InitGlobalTimer(), "Init Global Timers"))
                {
                    return(false);
                }

                if (!InitComponent(MarryRoomMgr.Init(), "MarryRoomMgr Init"))
                {
                    return(false);
                }
                if (!InitComponent(LogMgr.Setup(1, 4, 4), "LogMgr Setup"))
                {
                    return(false);
                }
                GameEventMgr.Notify(ScriptEvent.Loaded);

                if (!InitComponent(InitLoginServer(), "Login To CenterServer"))
                {
                    return(false);
                }

                RoomMgr.Start();
                GameMgr.Start();
                BattleMgr.Start();
                MacroDropMgr.Start();

                if (!InitComponent(base.Start(), "base.Start()"))
                {
                    return(false);
                }



                GameEventMgr.Notify(GameServerEvent.Started, this);

                GC.Collect(GC.MaxGeneration);

                if (log.IsInfoEnabled)
                {
                    log.Info("GameServer is now open for connections!");
                }

                m_isRunning = true;
                return(true);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Failed to start the server", e);
                }

                return(false);
            }
        }
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            new ProduceBussiness();
            if (client.Lottery != -1)
            {
                client.Out.SendMessage(eMessageType.Normal, "Rương đang hoạt động!");
                return(1);
            }
            int             bageType  = (int)packet.ReadByte();
            int             slot      = packet.ReadInt();
            int             num       = packet.ReadInt();
            PlayerInventory inventory = client.Player.GetInventory((eBageType)bageType);

            inventory.GetItemAt(slot);
            if (inventory.FindFirstEmptySlot() == -1)
            {
                client.Out.SendMessage(eMessageType.Normal, "Rương đã đầy không thể mở thêm!");
                return(1);
            }

            PlayerInventory propBag          = client.Player.PropBag;
            ItemInfo        itemByTemplateID = propBag.GetItemByTemplateID(0, 11456);

            new List <ItemInfo>();
            StringBuilder      stringBuilder = new StringBuilder();
            List <ItemBoxInfo> list          = ItemBoxMgr.FindItemBoxAward(num);
            int index = ThreadSafeRandom.NextStatic(list.Count);

            ItemMgr.FindItemTemplate(num);
            ItemInfo itemInfo = ItemInfo.CreateFromTemplate(ItemMgr.FindItemTemplate(list[index].TemplateId), 1, 105);
            bool     val      = true;
            int      num2     = num;
            string   str;

            int             result          = 0;
            PlayerInventory playerInventory = null;

            if (itemInfo != null && itemInfo.TemplateID == 112019)
            {
                client.tempData = "start";
                if (itemInfo.Count > 1)
                {
                    itemInfo.Count--;
                    playerInventory.UpdateItem(itemInfo);
                }
                else
                {
                    playerInventory.RemoveItem(itemInfo);
                }
                GSPacketIn gSPacketIn = new GSPacketIn(29, client.Player.PlayerId);
                int[]      array      = LotteryOpenBoxHandler.listRandomitem[num];
                for (int i = 0; i < array.Length; i++)
                {
                    int num6 = array[i];
                    gSPacketIn.WriteInt(num6);
                    gSPacketIn.WriteBoolean(false);
                    gSPacketIn.WriteByte(1);
                    gSPacketIn.WriteByte(1);
                }
                client.Out.SendTCP(gSPacketIn);
                result = 1;
                return(result);
            }

            if (num2 != 112047)
            {
                switch (num2)
                {
                case 112100:
                case 112101:
                    break;

                default:
                    str = itemInfo.Template.Name;
                    goto IL_17F;
                }
            }
            str = client.Player.PlayerCharacter.NickName;
            itemInfo.BeginDate  = DateTime.Now;
            itemInfo.ValidDate  = 7;
            itemInfo.RemoveDate = DateTime.Now.AddDays(7.0);
            if (itemByTemplateID.Count > 4)
            {
                itemByTemplateID.Count -= 4;
                propBag.UpdateItem(itemByTemplateID);
            }
            else
            {
                propBag.RemoveItem(itemByTemplateID);
            }
IL_17F:
            GSPacketIn pkg = new GSPacketIn(245, client.Player.PlayerId);

            pkg.WriteBoolean(val);
            pkg.WriteInt(1);
            pkg.WriteString(str);
            pkg.WriteInt(itemInfo.TemplateID);
            pkg.WriteInt(4);
            pkg.WriteBoolean(false);
            client.Out.SendTCP(pkg);
            inventory.AddItem(itemInfo);
            stringBuilder.Append(itemInfo.Template.Name);
            ItemInfo itemByTemplateID2 = client.Player.PropBag.GetItemByTemplateID(0, num);

            if (itemByTemplateID2.Count > 1)
            {
                itemByTemplateID2.Count--;
                client.Player.PropBag.UpdateItem(itemByTemplateID2);
            }
            else
            {
                client.Player.PropBag.RemoveItem(itemByTemplateID2);
            }
            client.Lottery = -1;
            if (stringBuilder != null)
            {
                client.Out.SendMessage(eMessageType.Normal, "Bạn nhận được " + stringBuilder.ToString());
            }
            return(1);
        }
예제 #5
0
        public override int HandlePacket(GamePlayer player, GSPacketIn packet)
        {
            int     operate = packet.ReadInt();
            BoxInfo box     = null;
            int     result2;

            if (operate == 0)
            {
                int time       = packet.ReadInt();
                int onlineTime = (int)DateTime.Now.Subtract(player.BoxBeginTime).TotalMinutes;
                box = BoxMgr.FindTemplateByCondition(0, player.PlayerCharacter.Grade, player.PlayerCharacter.BoxProgression);
                if (box != null && onlineTime >= time && box.Condition == time)
                {
                    using (ProduceBussiness db = new ProduceBussiness())
                    {
                        db.UpdateBoxProgression(player.PlayerCharacter.ID, player.PlayerCharacter.BoxProgression, player.PlayerCharacter.GetBoxLevel, player.PlayerCharacter.AddGPLastDate, DateTime.Now, time);
                        player.PlayerCharacter.AlreadyGetBox = time;
                        player.PlayerCharacter.BoxGetDate    = DateTime.Now;
                    }
                }
                result2 = 0;
            }
            else
            {
                int        type = packet.ReadInt();
                GSPacketIn pkg  = packet.Clone();
                pkg.ClearContext();
                bool updatedb = false;
                bool result   = true;
                if (type == 0)
                {
                    int onlineTime = (int)DateTime.Now.Subtract(player.BoxBeginTime).TotalMinutes;
                    box = BoxMgr.FindTemplateByCondition(0, player.PlayerCharacter.Grade, player.PlayerCharacter.BoxProgression);
                    if (box != null && (onlineTime >= box.Condition || player.PlayerCharacter.AlreadyGetBox == box.Condition))
                    {
                        using (ProduceBussiness db = new ProduceBussiness())
                        {
                            if (db.UpdateBoxProgression(player.PlayerCharacter.ID, box.Condition, player.PlayerCharacter.GetBoxLevel, player.PlayerCharacter.AddGPLastDate, DateTime.Now.Date, 0))
                            {
                                player.PlayerCharacter.BoxProgression = box.Condition;
                                player.PlayerCharacter.BoxGetDate     = DateTime.Now.Date;
                                player.PlayerCharacter.AlreadyGetBox  = 0;
                                updatedb = true;
                            }
                        }
                    }
                }
                else
                {
                    box = BoxMgr.FindTemplateByCondition(1, player.PlayerCharacter.GetBoxLevel, Convert.ToInt32(player.PlayerCharacter.Sex));
                    if (box != null && player.PlayerCharacter.Grade >= box.Level)
                    {
                        using (ProduceBussiness db = new ProduceBussiness())
                        {
                            if (db.UpdateBoxProgression(player.PlayerCharacter.ID, player.PlayerCharacter.BoxProgression, box.Level, player.PlayerCharacter.AddGPLastDate, player.PlayerCharacter.BoxGetDate, 0))
                            {
                                player.PlayerCharacter.GetBoxLevel = box.Level;
                                updatedb = true;
                            }
                        }
                    }
                }
                if (updatedb)
                {
                    if (box != null)
                    {
                        List <ItemInfo> mailList  = new List <ItemInfo>();
                        List <ItemInfo> items     = new List <ItemInfo>();
                        int             gold      = 0;
                        int             money     = 0;
                        int             giftToken = 0;
                        int             gp        = 0;
                        ItemBoxMgr.CreateItemBox(Convert.ToInt32(box.Template), items, ref gold, ref money, ref giftToken, ref gp);
                        if (gold > 0)
                        {
                            player.AddGold(gold);
                        }
                        if (money > 0)
                        {
                            player.AddMoney(money, LogMoneyType.Award, LogMoneyType.Award);
                        }
                        if (giftToken > 0)
                        {
                            player.AddGiftToken(giftToken);
                        }
                        if (gp > 0)
                        {
                            player.AddGP(gp);
                        }
                        foreach (ItemInfo item in items)
                        {
                            item.RemoveType = 120;
                            if (!player.AddItem(item))
                            {
                                mailList.Add(item);
                            }
                        }
                        if (type == 0)
                        {
                            player.BoxBeginTime = DateTime.Now;
                            box = BoxMgr.FindTemplateByCondition(0, player.PlayerCharacter.Grade, player.PlayerCharacter.BoxProgression);
                            if (box != null)
                            {
                                player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserGetTimeBoxHandler.success", new object[]
                                {
                                    box.Condition
                                }));
                            }
                            else
                            {
                                player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserGetTimeBoxHandler.todayOver", new object[0]));
                            }
                        }
                        else
                        {
                            box = BoxMgr.FindTemplateByCondition(1, player.PlayerCharacter.GetBoxLevel, Convert.ToInt32(player.PlayerCharacter.Sex));
                            if (box != null)
                            {
                                player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserGetTimeBoxHandler.level", new object[]
                                {
                                    box.Level
                                }));
                            }
                            else
                            {
                                player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserGetTimeBoxHandler.over", new object[0]));
                            }
                        }
                        if (mailList.Count > 0)
                        {
                            if (player.SendItemsToMail(mailList, LanguageMgr.GetTranslation("UserGetTimeBoxHandler.mail", new object[0]), LanguageMgr.GetTranslation("UserGetTimeBoxHandler.title", new object[0]), eMailType.OpenUpArk))
                            {
                                player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserGetTimeBixHandler..full", new object[0]));
                                result = true;
                                player.Out.SendMailResponse(player.PlayerCharacter.ID, eMailRespose.Receiver);
                            }
                        }
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("UserGetTimeBoxHandler.fail", new object[0]));
                }
                if (type == 0)
                {
                    pkg.WriteBoolean(result);
                    pkg.WriteInt(player.PlayerCharacter.BoxProgression);
                    player.SendTCP(pkg);
                }
                result2 = 0;
            }
            return(result2);
        }
예제 #6
0
        private void Init(Object sender, EventArgs e)
        {
            LogProvider.Default = new LogProvider(new LogConfig
            {
                UseMessageBox = true,
                LogView       = LogView,
                UseLogView    = true,
                FilePath      = @".\log\",
                UseFile       = true
            });
            var log = LogProvider.Default;

            this.runmgr = new RunMgr();
            Web.Server.WebServer.Runmgr = this.runmgr;

            new Thread(() =>
            {
                if (!Sql_DbObject.TryConnection())
                {
                    log.Error("Fail to connect to SQL!");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to to connect to SQL!");
                }
                if (!LanguageMgr.Load())
                {
                    log.Error("Fail to load language");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load language");
                }
                if (!MapMgr.Init())
                {
                    log.Error("Fail to load map");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load map");
                }
                if (!ItemMgr.Init())
                {
                    log.Error("Fail to load item");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load item");
                }
                if (!PropItemMgr.Init())
                {
                    log.Error("Fail to load propitem");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load propitem");
                }
                if (!BallMgr.Init())
                {
                    log.Error("Fail to load ball");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load ball");
                }
                if (!DropMgr.Init())
                {
                    log.Error("Fail to load drop");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load drop");
                }
                if (!NPCInfoMgr.Init())
                {
                    log.Error("Fail to load npc");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load npc");
                }

                if (!ItemBoxMgr.Init())
                {
                    log.Error("Fail to load itembox");
                    WinForm.Notice("初始化失败,请查看日志。");
                    return;
                }
                else
                {
                    log.Info("Succeed to load itembox");
                }
                flag = true;
            }).Start();

            Thread thread = new Thread(run);

            thread.Start();
        }