upgrade skill (not throughly tested because the lack of other implementation)

This commit is contained in:
rfi
2023-11-19 21:02:09 +07:00
parent 0705c4373f
commit 897a457584
7 changed files with 132 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ using MongoDB.Driver;
using AscNet.Table.share.character;
using AscNet.Table.share.character.skill;
using AscNet.Common.MsgPack;
using AscNet.Common.Util;
namespace AscNet.Common.Database
{
@@ -83,6 +84,41 @@ namespace AscNet.Common.Database
Characters.Add(characterData);
}
public UpgradeCharacterResult UpgradeCharacterSkillGroup(uint skillGroupId, int count)
{
List<uint> affectedCharacters = new();
int totalCoinCost = 0;
int totalSkillPointCost = 0;
IEnumerable<int> affectedSkills = CharacterSkillGroupTableReader.Instance.All.Where(x => x.Id == skillGroupId).SelectMany(x => x.SkillId);
foreach (var skillId in affectedSkills)
{
foreach (var character in Characters.Where(x => x.SkillList.Any(x => x.Id == skillId)))
{
var characterSkill = character.SkillList.First(x => x.Id == skillId);
int targetLevel = characterSkill.Level + count;
while (characterSkill.Level < targetLevel)
{
var skillUpgrade = CharacterSkillUpgradeTableReader.Instance.All.FirstOrDefault(x => x.SkillId == skillId && Miscs.ParseIntOr(x.Level) == characterSkill.Level);
totalCoinCost += Miscs.ParseIntOr(skillUpgrade?.UseCoin);
totalSkillPointCost += Miscs.ParseIntOr(skillUpgrade?.UseSkillPoint);
characterSkill.Level++;
}
affectedCharacters.Add(character.Id);
}
}
return new UpgradeCharacterResult()
{
AffectedCharacters = affectedCharacters,
CoinCost = totalCoinCost,
SkillPointCost = totalSkillPointCost
};
}
public void AddEquip(uint equipId, int characterId = 0)
{
NotifyEquipDataList.NotifyEquipDataListEquipData equipData = new()
@@ -128,4 +164,11 @@ namespace AscNet.Common.Database
[BsonRequired]
public List<FashionList> Fashions { get; set; }
}
public struct UpgradeCharacterResult
{
public int CoinCost { get; init; }
public int SkillPointCost { get; init; }
public List<uint> AffectedCharacters { get; init; }
}
}

View File

@@ -9,6 +9,34 @@ namespace AscNet.Common.Database
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public class Inventory
{
#region CommonItems
public const int Coin = 1;
public const int PaidGem = 2;
public const int FreeGem = 3;
public const int ActionPoint = 4;
public const int HongKa = 5;
public const int TeamExp = 7;
public const int AndroidHongKa = 8;
public const int IosHongKa = 10;
public const int SkillPoint = 12;
public const int DailyActiveness = 13;
public const int WeeklyActiveness = 14;
public const int HostelElectric = 15;
public const int HostelMat = 16;
public const int OnlineBossTicket = 17;
public const int BountyTaskExp = 18;
public const int DormCoin = 30;
public const int FurnitureCoin = 31;
public const int DormEnterIcon = 36;
public const int BaseEquipCoin = 300;
public const int InfestorActionPoint = 50;
public const int InfestorMoney = 51;
public const int PokemonLevelUpItem = 56;
public const int PokemonStarUpItem = 57;
public const int PokemonLowStarUpItem = 58;
public const int PassportExp = 60;
#endregion
public static readonly IMongoCollection<Inventory> collection = Common.db.GetCollection<Inventory>("inventory");
public static Inventory FromUid(long uid)
@@ -41,6 +69,26 @@ namespace AscNet.Common.Database
return inventory;
}
public void Do(int itemId, int amount)
{
Item? item = Items.FirstOrDefault(x => x.Id == itemId);
if (item is not null)
{
item.Count += amount;
item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds();
}
else
{
Items.Add(new Item()
{
Id = itemId,
Count = amount,
RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(),
CreateTime = DateTimeOffset.Now.ToUnixTimeSeconds()
});
}
}
public void Save()
{
collection.ReplaceOne(Builders<Inventory>.Filter.Eq(x => x.Id, Id), this);

View File

@@ -2002,19 +2002,7 @@ namespace AscNet.Common.MsgPack
[global::MessagePack.MessagePackObject(true)]
public class NotifyItemDataList
{
[global::MessagePack.MessagePackObject(true)]
public class NotifyItemDataListItemData
{
public Int32 Id { get; set; }
public UInt32 Count { get; set; }
public Int32 BuyTimes { get; set; }
public Int32 TotalBuyTimes { get; set; }
public Int32 LastBuyTime { get; set; }
public UInt32 RefreshTime { get; set; }
public UInt32 CreateTime { get; set; }
}
public List<NotifyItemDataListItemData> ItemDataList { get; set; } = new();
public List<Item> ItemDataList { get; set; } = new();
public dynamic? ItemRecycleDict { get; set; }
}