Пример #1
0
        public Friend AddOrUpdate(ulong friendId, Player plr, FriendState playerState, FriendState friendState)
        {
            using (var db = GameDatabase.Open())
            {
                if (_friends.TryGetValue(friendId, out var friend))
                {
                    var dbFriend = DbUtil.Find <PlayerFriendDto>(db, statement => statement
                                                                 .Where(
                                                                     $"{nameof(PlayerFriendDto.PlayerId):C} = @PlayerId AND {nameof(PlayerFriendDto.FriendId):C} = @FriendId")
                                                                 .WithParameters(new { PlayerId = Player.Account.Id, FriendId = friendId })).FirstOrDefault();

                    if (dbFriend == null)
                    {
                        dbFriend = DbUtil.Find <PlayerFriendDto>(db, statement => statement
                                                                 .Where(
                                                                     $"{nameof(PlayerFriendDto.PlayerId):C} = @PlayerId AND {nameof(PlayerFriendDto.FriendId):C} = @FriendId")
                                                                 .WithParameters(new { PlayerId = friendId, FriendId = Player.Account.Id })).FirstOrDefault();
                    }

                    if (dbFriend == null)
                    {
                        throw new Exception("db and server are de-synced!");
                    }

                    dbFriend.PlayerState = (int)playerState;
                    dbFriend.FriendState = (int)friendState;
                    DbUtil.Update(db, dbFriend);
                    friend.PlayerState = playerState;
                    friend.FriendState = friendState;
                    return(friend);
                }

                var newDbFriend = new PlayerFriendDto()
                {
                    PlayerId    = (int)Player.Account.Id,
                    FriendId    = (int)friendId,
                    PlayerState = (int)playerState,
                    FriendState = (int)friendState
                };

                DbUtil.Insert(db, newDbFriend);

                var newFriend = new Friend(Player.Account.Id, friendId, playerState, friendState);
                if (!_friends.TryAdd(newFriend.FriendId, newFriend))
                {
                    throw new ArgumentException("Player is already added", nameof(Player.Account.Id));
                }

                if (plr != null)
                {
                    var newPlrFriend = new Friend(friendId, Player.Account.Id, friendState, playerState);
                    if (!plr.FriendManager._friends.TryAdd(Player.Account.Id, newPlrFriend))
                    {
                        throw new ArgumentException("Player is already added", nameof(newFriend.FriendId));
                    }
                }

                return(newFriend);
            }
        }
Пример #2
0
        public FriendManager(Player plr, PlayerDto dto)
        {
            Player = plr;

            foreach (var friendDto in dto.Friends)
            {
                var friend = new Friend(friendDto);
                _friends.TryAdd(friend.FriendId, friend);
            }

            using (var db = GameDatabase.Open())
            {
                var friends = DbUtil.Find <PlayerFriendDto>(db, statement => statement
                                                            .Where($"{nameof(PlayerFriendDto.FriendId):C} = @Id")
                                                            .WithParameters(new { Player.Account.Id }));

                foreach (var friendDto in dto.Friends)
                {
                    var friend = new Friend(friendDto);
                    _friends.TryAdd(friend.FriendId, friend);
                }

                foreach (var friendDto in friends)
                {
                    var fstate = friendDto.FriendState;
                    friendDto.FriendId    = friendDto.PlayerId;
                    friendDto.PlayerId    = (int)Player.Account.Id;
                    friendDto.FriendState = friendDto.PlayerState;
                    friendDto.PlayerState = fstate;
                    var friend = new Friend(friendDto);
                    _friends.TryAdd(friend.FriendId, friend);
                }
            }
        }
Пример #3
0
 public static void Initialize()
 {
     using (var db = GameDatabase.Open())
     {
         var result = DbUtil.Find <PlayerDenyDto>(db);
         if (result.Any())
         {
             s_counter = result.Max(item => item.Id);
         }
     }
 }
Пример #4
0
        public bool Remove(ulong friendId, Player plr)
        {
            var friend = _friends[friendId];

            if (friend == null)
            {
                return(false);
            }

            _friends.Remove(friendId);
            if (plr != null)
            {
                plr.FriendManager._friends.Remove(Player.Account.Id);
            }

            using (var db = GameDatabase.Open())
            {
                var dbFriend = DbUtil.Find <PlayerFriendDto>(db, statement => statement
                                                             .Where(
                                                                 $"{nameof(PlayerFriendDto.PlayerId):C} = @PlayerId AND {nameof(PlayerFriendDto.FriendId):C} = @FriendId")
                                                             .WithParameters(new { PlayerId = Player.Account.Id, FriendId = friendId })).FirstOrDefault();

                if (dbFriend == null)
                {
                    dbFriend = DbUtil.Find <PlayerFriendDto>(db, statement => statement
                                                             .Where(
                                                                 $"{nameof(PlayerFriendDto.PlayerId):C} = @PlayerId AND {nameof(PlayerFriendDto.FriendId):C} = @FriendId")
                                                             .WithParameters(new { PlayerId = friendId, FriendId = Player.Account.Id })).FirstOrDefault();
                }

                if (dbFriend == null)
                {
                    throw new Exception("db and server are de-synced!");
                }

                DbUtil.Delete(db, dbFriend);
            }

            return(true);
        }
Пример #5
0
        private static void FillShop()
        {
            if (!Config.Instance.NoobMode)
            {
                return;
            }

            using (var db = GameDatabase.Open())
            {
                if (!DbUtil.Find <ShopVersionDto>(db).Any())
                {
                    var version = new ShopVersionDto
                    {
                        Version = DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss")
                    };
                    DbUtil.Insert(db, version);
                }

                if (DbUtil.Find <ShopEffectGroupDto>(db).Any() || DbUtil.Find <ShopEffectDto>(db).Any() ||
                    DbUtil.Find <ShopPriceGroupDto>(db).Any() || DbUtil.Find <ShopPriceDto>(db).Any() ||
                    DbUtil.Find <ShopItemDto>(db).Any() || DbUtil.Find <ShopItemInfoDto>(db).Any())
                {
                    return;
                }

                Log.Information("NoobMode: Filling the shop with items");

                using (var transaction = DbUtil.BeginTransaction(db))
                {
                    var effects = new Dictionary <string, Tuple <uint[], uint> > // effectids, groupid/effect
                    {
                        { "None", Tuple.Create(Array.Empty <uint>(), (uint)0) },
                        {
                            "Shooting Weapon Defense (Head) +5%",
                            Tuple.Create(new uint[] { 1100313003, 1100315003, 1100317003 }, (uint)1100315002)
                        },
                        { "SP+6", Tuple.Create(new uint[] { 1101301006 }, (uint)1101301006) },
                        { "Attack+1%", Tuple.Create(new uint[] { 1299600001 }, (uint)1299600001) },
                        { "Attack+3%", Tuple.Create(new uint[] { 1299600002 }, (uint)1299600002) },
                        { "Attack+5%", Tuple.Create(new uint[] { 1299600003 }, (uint)1299600003) },
                        { "Attack+8%", Tuple.Create(new uint[] { 1299600005 }, (uint)1299600005) },
                        { "Attack+10%", Tuple.Create(new uint[] { 1299600006 }, (uint)1299600006) },
                        { "Defense+5%", Tuple.Create(new uint[] { 1103302004 }, (uint)1103302004) },
                        { "HP+4", Tuple.Create(new uint[] { 1105300004 }, (uint)1105300004) },
                        { "HP+30", Tuple.Create(new uint[] { 1999300011 }, (uint)1999300011) },
                        { "HP+15", Tuple.Create(new uint[] { 1999300009 }, (uint)1999300009) },
                        { "SP+40", Tuple.Create(new uint[] { 1300301012 }, (uint)1300301012) },
                        { "HP+20 & SP+20", Tuple.Create(new uint[] { 1999300010, 1999301011 }, (uint)30001) },
                        { "HP+25 & SP+25", Tuple.Create(new uint[] { 1999300012, 1999301013 }, (uint)30003) }
                    };

                    #region Effects

                    foreach (var pair in effects.ToArray())
                    {
                        var effectGroup = new ShopEffectGroupDto {
                            Name = pair.Key, Effect = pair.Value.Item2
                        };
                        DbUtil.Insert(db, effectGroup, statement => statement.AttachToTransaction(transaction));
                        effects[pair.Key] = Tuple.Create(pair.Value.Item1, (uint)effectGroup.Id);

                        foreach (var effect in pair.Value.Item1)
                        {
                            DbUtil.Insert(db, new ShopEffectDto {
                                EffectGroupId = effectGroup.Id, Effect = effect
                            },
                                          statement => statement.AttachToTransaction(transaction));
                        }
                    }

                    #endregion

                    #region Price

                    var priceGroup = new ShopPriceGroupDto
                    {
                        Name      = "PEN",
                        PriceType = (byte)ItemPriceType.PEN
                    };
                    var priceGroup2 = new ShopPriceGroupDto
                    {
                        Name      = "Item",
                        PriceType = (byte)ItemPriceType.Premium
                    };
                    var priceGroup3 = new ShopPriceGroupDto
                    {
                        Name      = "AP",
                        PriceType = (byte)ItemPriceType.AP
                    };

                    DbUtil.Insert(db, priceGroup);
                    DbUtil.Insert(db, priceGroup2);
                    DbUtil.Insert(db, priceGroup3);

                    var price_none_perm = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup.Id,
                        PeriodType   = (byte)ItemPeriodType.None,
                        IsRefundable = true,
                        Durability   = 2400,
                        IsEnabled    = true,
                        Price        = 1
                    };

                    var price_unit_one = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 1,
                        IsEnabled    = true,
                        Price        = 1000
                    };

                    var price_unit_two = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 2,
                        IsEnabled    = true,
                        Price        = 2000
                    };

                    var price_unit_five = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 5,
                        IsEnabled    = true,
                        Price        = 4500
                    };

                    var price_unit_ten = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 10,
                        IsEnabled    = true,
                        Price        = 8000
                    };

                    var price_ap_perm = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup3.Id,
                        PeriodType   = (byte)ItemPeriodType.None,
                        IsRefundable = true,
                        Durability   = 2400,
                        IsEnabled    = true,
                        Price        = 1
                    };

                    DbUtil.Insert(db, price_none_perm);
                    DbUtil.Insert(db, price_unit_one);
                    DbUtil.Insert(db, price_unit_two);
                    DbUtil.Insert(db, price_unit_five);
                    DbUtil.Insert(db, price_unit_ten);
                    DbUtil.Insert(db, price_ap_perm);

                    #endregion

                    #region Items

                    var items = GameServer.Instance.ResourceCache.GetItems().Values.ToArray();
                    for (var i = 0; i < items.Length; ++i)
                    {
                        var  item        = items[i];
                        var  effectToUse = effects["None"];
                        byte mainTab     = 0;
                        byte subTab      = 0;
                        bool enabled     = true;

                        switch (item.ItemNumber.Category)
                        {
                        case ItemCategory.Card:
                        case ItemCategory.Coupon:
                            mainTab = 4;
                            subTab  = 6;
                            break;

                        case ItemCategory.EsperChip:
                            mainTab = 4;
                            subTab  = 2;
                            break;

                        case ItemCategory.Boost:
                            switch ((BoostCategory)item.ItemNumber.SubCategory)
                            {
                            case BoostCategory.Pen:
                                mainTab = 4;
                                subTab  = 4;
                                break;

                            case BoostCategory.Exp:
                                mainTab = 4;
                                subTab  = 5;
                                break;

                            case BoostCategory.Mp:
                                mainTab = 4;
                                subTab  = 3;
                                break;

                            case BoostCategory.Unique:
                                mainTab = 4;
                                subTab  = 5;
                                break;
                            }

                            break;

                        case ItemCategory.OneTimeUse:
                            switch ((OneTimeUseCategory)item.ItemNumber.SubCategory)
                            {
                            case OneTimeUseCategory.Namechange:
                                mainTab = 4;
                                subTab  = 0;
                                break;

                            case OneTimeUseCategory.Stat:
                                mainTab = 4;
                                subTab  = 0;
                                break;

                            case OneTimeUseCategory.Capsule: // Clothes + weps
                                mainTab = 1;
                                subTab  = 0;
                                break;

                            case OneTimeUseCategory.FumbiCapsule:
                                mainTab = 1;
                                subTab  = 4;
                                break;

                            case OneTimeUseCategory.Event:
                                mainTab = 4;
                                subTab  = 0;
                                break;

                            case OneTimeUseCategory.Set:
                                mainTab = 1;
                                subTab  = 7;
                                break;

                            default:
                                continue;
                            }

                            break;

                        case ItemCategory.Weapon:
                            effectToUse = effects["Attack+1%"];
                            mainTab     = 2;

                            switch ((WeaponCategory)item.ItemNumber.SubCategory)
                            {
                            case WeaponCategory.Melee:
                                subTab = 1;
                                break;

                            case WeaponCategory.RifleGun:
                                subTab = 2;
                                break;

                            case WeaponCategory.HeavyGun:
                                subTab = 4;
                                break;

                            case WeaponCategory.Sniper:
                                subTab = 5;
                                break;

                            case WeaponCategory.Sentry:
                                subTab = 6;
                                break;

                            case WeaponCategory.Bomb:
                                subTab = 7;
                                break;

                            case WeaponCategory.Mind:
                                subTab = 6;
                                break;
                            }

                            break;

                        case ItemCategory.Skill:
                            mainTab = 2;
                            subTab  = 8;
                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 0) // half hp mastery
                            {
                                effectToUse = effects["HP+15"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 1) // hp mastery
                            {
                                effectToUse = effects["HP+30"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 2) // sp mastery
                            {
                                effectToUse = effects["SP+40"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 3) // dual mastery
                            {
                                effectToUse = effects["HP+20 & SP+20"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 5
                                ) // dual mastery - returner
                            {
                                effectToUse = effects["HP+20 & SP+20"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 7
                                ) // unique dual mastery
                            {
                                effectToUse = effects["HP+25 & SP+25"];
                            }

                            break;

                        case ItemCategory.Costume:
                            mainTab = 3;
                            subTab  = (byte)(item.ItemNumber.SubCategory + 2);
                            switch ((CostumeSlot)item.ItemNumber.SubCategory)
                            {
                            case CostumeSlot.Hair:
                                effectToUse = effects["Shooting Weapon Defense (Head) +5%"];
                                break;

                            case CostumeSlot.Face:
                                effectToUse = effects["SP+6"];
                                break;

                            case CostumeSlot.Shirt:
                                effectToUse = effects["Attack+5%"];
                                break;

                            case CostumeSlot.Pants:
                                effectToUse = effects["Defense+5%"];
                                break;

                            case CostumeSlot.Gloves:
                                effectToUse = effects["HP+4"];
                                break;

                            case CostumeSlot.Shoes:
                                effectToUse = effects["HP+4"];
                                break;

                            case CostumeSlot.Accessory:
                                effectToUse = effects["SP+6"];
                                break;

                            case CostumeSlot.Pet:
                                effectToUse = effects["SP+6"];
                                break;
                            }

                            break;

                        default:
                            effectToUse = effects["None"];
                            mainTab     = 4;
                            subTab      = 6;
                            break;
                        }

                        var shopItem = new ShopItemDto
                        {
                            Id              = item.ItemNumber,
                            RequiredGender  = (byte)item.Gender,
                            RequiredLicense = (byte)item.License,
                            IsDestroyable   = true,
                            MainTab         = mainTab,
                            SubTab          = subTab,
                            Colors          = (byte)item.Colors
                        };

                        DbUtil.Insert(db, shopItem, statement => statement.AttachToTransaction(transaction));

                        var shopItemInfo = new ShopItemInfoDto
                        {
                            ShopItemId    = shopItem.Id,
                            PriceGroupId  = priceGroup.Id,
                            EffectGroupId = (int)effectToUse.Item2,
                            ShopInfoType  = enabled ? (byte)1 : (byte)0,
                        };

                        var shopItemInfo_onetimeuse = new ShopItemInfoDto
                        {
                            ShopItemId    = shopItem.Id,
                            PriceGroupId  = priceGroup2.Id,
                            EffectGroupId = (int)effectToUse.Item2,
                            ShopInfoType  = enabled ? (byte)1 : (byte)0,
                        };

                        if (item.ItemNumber.Category == ItemCategory.Costume || item.ItemNumber.Category ==
                            ItemCategory.Weapon ||
                            item.ItemNumber.Category ==
                            ItemCategory.Skill ||
                            item.ItemNumber.Category ==
                            ItemCategory.EsperChip)
                        {
                            DbUtil.Insert(db, shopItemInfo, statement => statement.AttachToTransaction(transaction));
                        }
                        else
                        {
                            DbUtil.Insert(db, shopItemInfo_onetimeuse,
                                          statement => statement.AttachToTransaction(transaction));
                        }

                        Log.Information($"[{i}/{items.Length}] {item.ItemNumber}: {item.Name} | Colors: {item.Colors}");
                    }

                    #endregion

                    var itemInfos = DbUtil.Find <ShopItemInfoDto>(db, statement => statement
                                                                  .Include <ShopItemDto>(join => join.LeftOuterJoin())
                                                                  .AttachToTransaction(transaction));

                    var caps = GameServer.Instance.ResourceCache._loader.GetWorkingCapsules();

                    foreach (var item in items.Where(x => x.ItemNumber.Category == ItemCategory.OneTimeUse))
                    {
                        var itemInfo = itemInfos.FirstOrDefault(x => x.ShopItemId == item.ItemNumber);
                        if (itemInfo != null)
                        {
                            if (!caps.Contains(item.ItemNumber))
                            {
                                itemInfo.ShopInfoType = 0;
                                DbUtil.Update(db, itemInfo, statement => statement.AttachToTransaction(transaction));
                            }
                        }
                    }

                    try
                    {
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }