Ejemplo n.º 1
0
        //[MessageHandler(typeof(CCreateNickReqMessage))]
        //public async Task CreateNickHandler(GameSession session, CCreateNickReqMessage message)
        //{
        //    if (session.Player == null || !string.IsNullOrWhiteSpace(session.Player.Account.Nickname))
        //    {
        //        session.CloseAsync();
        //        return;
        //    }

        //    Logger.ForAccount(session)
        //        .Information("Creating nickname {nickname}", message.Nickname);

        //    if (!await IsNickAvailableAsync(message.Nickname))
        //    {
        //        Logger.ForAccount(session)
        //            .Error("Nickname not available: {nickname}", message.Nickname);

        //        session.SendAsync(new NickCheckAckMessage(false));
        //        return;
        //    }

        //    session.Player.Account.Nickname = message.Nickname;
        //    using (var db = AuthDatabase.Open())
        //    {
        //        var mapping = OrmConfiguration
        //            .GetDefaultEntityMapping<AccountDto>()
        //            .Clone()
        //            .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true, nameof(AccountDto.Nickname));

        //        await db.UpdateAsync(new AccountDto { Id = (int)session.Player.Account.Id, Nickname = message.Nickname },
        //                    statement => statement.WithEntityMappingOverride(mapping));

        //    }
        //    //session.Send(new SCreateNickAckMessage { Nickname = msg.Nickname });
        //    await session.SendAsync(new ServerResultAckMessage(ServerResult.CreateNicknameSuccess));

        //    Logger.ForAccount(session)
        //        .Information("Created nickname {nickname}", message.Nickname);

        //    await LoginAsync(session);
        //}

        private static async Task LoginAsync(GameSession session)
        {
            var plr = session.Player;

            plr.LoggedIn = true;

            await session.SendAsync(new ItemInventoryInfoAckMessage
            {
                Items = plr.Inventory.Select(i => i.Map <PlayerItem, ItemDto>()).ToArray()
            });

            // Todo random shop
            //await session.SendAsync(new SRandomShopChanceInfoAckMessage { Progress = 10000 });
            await session.SendAsync(new CharacterCurrentSlotInfoAckMessage
            {
                ActiveCharacter = plr.CharacterManager.CurrentSlot,
                CharacterCount  = (byte)plr.CharacterManager.Count,
                MaxSlots        = 3
            });

            foreach (var @char in plr.CharacterManager)
            {
                await session.SendAsync(new CharacterCurrentInfoAckMessage
                {
                    Slot  = @char.Slot,
                    Style = new CharacterStyle(@char.Gender, @char.Hair.Variation, @char.Face.Variation,
                                               @char.Shirt.Variation, @char.Pants.Variation, @char.Slot)
                });


                var message = new CharacterCurrentItemInfoAckMessage
                {
                    Slot    = @char.Slot,
                    Weapons = @char.Weapons.GetItems().Select(i => i?.Id ?? 0).ToArray(),
                    Skills  = new[] { @char.Skills.GetItem(SkillSlot.Skill)?.Id ?? 0 },
                    Clothes = @char.Costumes.GetItems().Select(i => i?.Id ?? 0).ToArray()
                };

                await session.SendAsync(message);
            }

            await session.SendAsync(new ClubMyInfoAckMessage(plr.Map <Player, MyInfoDto>()));

            await session.SendAsync(new MoneyRefreshCashInfoAckMessage { PEN = plr.PEN, AP = plr.AP });

            await session.SendAsync(new MoenyRefreshCoinInfoAckMessage { ArcadeCoins = plr.Coins1, BuffCoins = plr.Coins2 });

            await session.SendAsync(new PlayerAccountInfoAckMessage(plr.Map <Player, PlayerAccountInfoDto>()));

            if (plr.Inventory.Count == 0)
            {
                IEnumerable <StartItemDto> startItems;
                using (var db = GameDatabase.Open())
                {
                    startItems = await db.FindAsync <StartItemDto>(statement => statement
                                                                   .Where(
                                                                       $"{nameof(StartItemDto.RequiredSecurityLevel):C} <= @{nameof(plr.Account.SecurityLevel)}")
                                                                   .WithParameters(new { plr.Account.SecurityLevel }));
                }

                foreach (var startItem in startItems)
                {
                    var shop     = GameServer.Instance.ResourceCache.GetShop();
                    var item     = shop.Items.Values.First(group => group.GetItemInfo(startItem.ShopItemInfoId) != null);
                    var itemInfo = item.GetItemInfo(startItem.ShopItemInfoId);
                    var effect   = itemInfo.EffectGroup.GetEffect(startItem.ShopEffectId);

                    var price = itemInfo.PriceGroup.GetPrice(startItem.ShopPriceId);
                    if (price == null)
                    {
                        Logger.Warning("Cant find ShopPrice for Start item {startItemId} - Forgot to reload the cache?",
                                       startItem.Id);
                        continue;
                    }

                    var color = startItem.Color;
                    if (color > item.ColorGroup)
                    {
                        Logger.Warning("Start item {startItemId} has an invalid color {color}", startItem.Id, color);
                        color = 0;
                    }

                    var count = startItem.Count;
                    if (count > 0 && item.ItemNumber.Category <= ItemCategory.Skill)
                    {
                        Logger.Warning("Start item {startItemId} cant have stacks(quantity={count})", startItem.Id,
                                       count);
                        count = 0;
                    }

                    if (count < 0)
                    {
                        count = 0;
                    }
                    var reteff = new List <uint>();
                    reteff.Add(effect.Effect);
                    plr.Inventory.Create(itemInfo, price, color, reteff.ToArray(), (uint)count);
                }
            }
            //session.Send(new ItemEquipBoostItemInfoAckMessage());
            await session.SendAsync(new ItemClearInvalidEquipItemAckMessage());

            await session.SendAsync(new ServerResultAckMessage(ServerResult.WelcomeToS4World));
        }
Ejemplo n.º 2
0
        //[MessageHandler(typeof(CCreateNickReqMessage))]
        //public async Task CreateNickHandler(GameSession session, CCreateNickReqMessage message)
        //{
        //    if (session.Player == null || !string.IsNullOrWhiteSpace(session.Player.Account.Nickname))
        //    {
        //        session.CloseAsync();
        //        return;
        //    }

        //    Logger.ForAccount(session)
        //        .Information("Creating nickname {nickname}", message.Nickname);

        //    if (!await IsNickAvailableAsync(message.Nickname))
        //    {
        //        Logger.ForAccount(session)
        //            .Error("Nickname not available: {nickname}", message.Nickname);

        //        session.SendAsync(new NickCheckAckMessage(false));
        //        return;
        //    }

        //    session.Player.Account.Nickname = message.Nickname;
        //    using (var db = AuthDatabase.Open())
        //    {
        //        var mapping = OrmConfiguration
        //            .GetDefaultEntityMapping<AccountDto>()
        //            .Clone()
        //            .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true, nameof(AccountDto.Nickname));

        //        await db.UpdateAsync(new AccountDto { Id = (int)session.Player.Account.Id, Nickname = message.Nickname },
        //                    statement => statement.WithEntityMappingOverride(mapping));

        //    }
        //    //session.Send(new SCreateNickAckMessage { Nickname = msg.Nickname });
        //    await session.SendAsync(new ServerResultAckMessage(ServerResult.CreateNicknameSuccess));

        //    Logger.ForAccount(session)
        //        .Information("Created nickname {nickname}", message.Nickname);

        //    await LoginAsync(session);
        //}

        private static async Task LoginAsync(GameSession session)
        {
            var plr = session.Player;

            await session.SendAsync(new ItemInventoryInfoAckMessage
            {
                Items = plr.Inventory.Select(i => i.Map <PlayerItem, ItemDto>()).ToArray()
            });

            // Todo random shop
            //await session.SendAsync(new SRandomShopChanceInfoAckMessage { Progress = 10000 });
            await session.SendAsync(new CharacterCurrentSlotInfoAckMessage
            {
                ActiveCharacter = plr.CharacterManager.CurrentSlot,
                CharacterCount  = (byte)plr.CharacterManager.Count,
                MaxSlots        = 3
            });

            foreach (var @char in plr.CharacterManager)
            {
                await session.SendAsync(new CharacterCurrentInfoAckMessage
                {
                    Slot  = @char.Slot,
                    Style = new CharacterStyle(@char.Gender, @char.Hair.Variation, @char.Face.Variation, @char.Shirt.Variation, @char.Pants.Variation, @char.Slot)
                });


                //var weps = @char.Weapons.GetItems().Select(i => i?.Id ?? 0).ToArray();
                //var skills = new[] { @char.Skills.GetItem(SkillSlot.Skill)?.Id ?? 0 };
                //var cloths = @char.Costumes.GetItems().Select(i => i?.Id ?? 0).ToArray();
                //
                //
                //List<CharacterItemBuffer> _Weapons = new List<CharacterItemBuffer>();
                //List<CharacterItemBuffer> _Skills = new List<CharacterItemBuffer>();
                //List<CharacterItemBuffer> _Clothes = new List<CharacterItemBuffer>();
                //
                //int foreachcount = 0;
                //foreach (var item in weps)
                //{
                //    _Weapons.Add(new CharacterItemBuffer { slotid = (byte)foreachcount, itemid = item });
                //    foreachcount++;
                //}
                //foreachcount = 0;
                //foreach (var item in skills)
                //{
                //    _Skills.Add(new CharacterItemBuffer { slotid = (byte)foreachcount, itemid = item });
                //    foreachcount++;
                //}
                //foreachcount = 0;
                //foreach (var item in cloths)
                //{
                //    _Clothes.Add(new CharacterItemBuffer { slotid = (byte)foreachcount, itemid = item });
                //    foreachcount++;
                //}

                var message = new CharacterCurrentItemInfoAckMessage
                {
                    Slot = @char.Slot,

                    Weapons = @char.Weapons.GetItems().Select(i => i?.Id ?? 0).ToArray(),
                    Skills  = new[] { @char.Skills.GetItem(SkillSlot.Skill)?.Id ?? 0 },
                    Clothes = @char.Costumes.GetItems().Select(i => i?.Id ?? 0).ToArray(),
                };


                //var weapons = @char.Weapons.GetItems().Select(i => i?.Id ?? 0).ToArray();
                //Array.Copy(weapons, 0, message.Weapons, 6, weapons.Length);

                await session.SendAsync(message);
            }

            await session.SendAsync(new MoneyRefreshCashInfoAckMessage
            {
                PEN = plr.PEN,
                AP  = plr.AP
            });

            await session.SendAsync(new MoenyRefreshCoinInfoAckMessage
            {
                ArcadeCoins = plr.Coins1,
                BuffCoins   = plr.Coins2
            });

            await session.SendAsync(new ServerResultAckMessage(ServerResult.WelcomeToS4World));

            await session.SendAsync(new PlayerAccountInfoAckMessage(plr.Map <Player, PlayerAccountInfoDto>()));

            //ItemDto testitem = new ItemDto
            //{
            //    Id = 570,
            //    @ItemNumber = 6000001,
            //    PriceType = ItemPriceType.None,
            //    PeriodType = ItemPeriodType.None,
            //    Period =0,
            //    Color = 0,
            //    ExpireTime = DateTimeOffset.Now,
            //    Durability = 800,
            //    Effects = new ItemEffectDto[] { },
            //    EnchantMP = 0,
            //    EnchantLevel = 0,
            //};
            //session.SendAsync(new ItemUpdateInventoryAckMessage(InventoryAction.Add, testitem));



            //await session.SendAsync(new ServerResultAckMessage(ServerResult.WelcomeToS4World2));

            if (plr.Inventory.Count == 0)
            {
                IEnumerable <StartItemDto> startItems;
                using (var db = GameDatabase.Open())
                {
                    startItems = await db.FindAsync <StartItemDto>(statement => statement
                                                                   .Where($"{nameof(StartItemDto.RequiredSecurityLevel):C} <= @{nameof(plr.Account.SecurityLevel)}")
                                                                   .WithParameters(new { plr.Account.SecurityLevel }));
                }

                foreach (var startItem in startItems)
                {
                    var shop     = GameServer.Instance.ResourceCache.GetShop();
                    var item     = shop.Items.Values.First(group => group.GetItemInfo(startItem.ShopItemInfoId) != null);
                    var itemInfo = item.GetItemInfo(startItem.ShopItemInfoId);
                    var effect   = itemInfo.EffectGroup.GetEffect(startItem.ShopEffectId);

                    if (itemInfo == null)
                    {
                        Logger.Warning("Cant find ShopItemInfo for Start item {startItemId} - Forgot to reload the cache?", startItem.Id);
                        continue;
                    }

                    var price = itemInfo.PriceGroup.GetPrice(startItem.ShopPriceId);
                    if (price == null)
                    {
                        Logger.Warning("Cant find ShopPrice for Start item {startItemId} - Forgot to reload the cache?", startItem.Id);
                        continue;
                    }

                    var color = startItem.Color;
                    if (color > item.ColorGroup)
                    {
                        Logger.Warning("Start item {startItemId} has an invalid color {color}", startItem.Id, color);
                        color = 0;
                    }

                    var count = startItem.Count;
                    if (count > 0 && item.ItemNumber.Category <= ItemCategory.Skill)
                    {
                        Logger.Warning("Start item {startItemId} cant have stacks(quantity={count})", startItem.Id, count);
                        count = 0;
                    }

                    if (count < 0)
                    {
                        count = 0;
                    }

                    plr.Inventory.Create(itemInfo, price, color, effect.Effect, (uint)count);
                }
            }

            //session.Send(new ItemEquipBoostItemInfoAckMessage());
            //session.Send(new ItemClearInvalidEquipItemAckMessage());
        }
Ejemplo n.º 3
0
        public static async Task LoginAsync(GameSession session)
        {
            var plr = session.Player;

            plr.LoggedIn = true;

            await session.SendAsync(new MoneyRefreshCashInfoAckMessage { PEN = plr.PEN, AP = plr.AP });

            await session.SendAsync(new CharacterCurrentSlotInfoAckMessage
            {
                ActiveCharacter = plr.CharacterManager.CurrentSlot,
                CharacterCount  = (byte)plr.CharacterManager.Count,
                MaxSlots        = 3
            });

            await session.SendAsync(
                new MoenyRefreshCoinInfoAckMessage { ArcadeCoins = plr.Coins1, BuffCoins = plr.Coins2 });

            await session.SendAsync(new ShoppingBasketListInfoAckMessage());

            await session.SendAsync(new PlayeArcadeMapInfoAckMessage());

            await session.SendAsync(new PlayerArcadeStageInfoAckMessage());

            await session.SendAsync(new ClubMyInfoAckMessage(plr.Map <Player, ClubMyInfoDto>()));

            await session.SendAsync(new ItemInventoryInfoAckMessage
            {
                Items = plr.Inventory.Select(i => i.Map <PlayerItem, ItemDto>()).ToArray()
            });

            foreach (var @char in plr.CharacterManager)
            {
                await session.SendAsync(new CharacterCurrentInfoAckMessage
                {
                    Slot  = @char.Slot,
                    Style = new CharacterStyle(@char.Gender, @char.Hair.Variation, @char.Face.Variation,
                                               @char.Shirt.Variation, @char.Pants.Variation, @char.Slot)
                });


                var message = new CharacterCurrentItemInfoAckMessage
                {
                    Slot    = @char.Slot,
                    Weapons = @char.Weapons.GetItems().Select(i => i?.Id ?? 0).ToArray(),
                    Skills  = new[] { @char.Skills.GetItem(SkillSlot.Skill)?.Id ?? 0 },
                    Clothes = @char.Costumes.GetItems().Select(i => i?.Id ?? 0).ToArray()
                };

                await session.SendAsync(message);
            }

            await session.SendAsync(new ItemEquipBoostItemInfoAckMessage());

            await session.SendAsync(new PlayerAccountInfoAckMessage(plr.Map <Player, PlayerAccountInfoDto>()));



            await session.SendAsync(new ItemClearInvalidEquipItemAckMessage());

            await session.SendAsync(new ItemClearEsperChipAckMessage());

            await session.SendAsync(new MapOpenInfosMessage());

            await session.SendAsync(new ServerResultAckMessage(ServerResult.WelcomeToS4World));
        }