upgrade skill (not throughly tested because the lack of other implementation)
This commit is contained in:
parent
0705c4373f
commit
897a457584
|
@ -4,6 +4,7 @@ using MongoDB.Driver;
|
||||||
using AscNet.Table.share.character;
|
using AscNet.Table.share.character;
|
||||||
using AscNet.Table.share.character.skill;
|
using AscNet.Table.share.character.skill;
|
||||||
using AscNet.Common.MsgPack;
|
using AscNet.Common.MsgPack;
|
||||||
|
using AscNet.Common.Util;
|
||||||
|
|
||||||
namespace AscNet.Common.Database
|
namespace AscNet.Common.Database
|
||||||
{
|
{
|
||||||
|
@ -83,6 +84,41 @@ namespace AscNet.Common.Database
|
||||||
Characters.Add(characterData);
|
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)
|
public void AddEquip(uint equipId, int characterId = 0)
|
||||||
{
|
{
|
||||||
NotifyEquipDataList.NotifyEquipDataListEquipData equipData = new()
|
NotifyEquipDataList.NotifyEquipDataListEquipData equipData = new()
|
||||||
|
@ -128,4 +164,11 @@ namespace AscNet.Common.Database
|
||||||
[BsonRequired]
|
[BsonRequired]
|
||||||
public List<FashionList> Fashions { get; set; }
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||||
public class Inventory
|
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 readonly IMongoCollection<Inventory> collection = Common.db.GetCollection<Inventory>("inventory");
|
||||||
|
|
||||||
public static Inventory FromUid(long uid)
|
public static Inventory FromUid(long uid)
|
||||||
|
@ -41,6 +69,26 @@ namespace AscNet.Common.Database
|
||||||
return inventory;
|
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()
|
public void Save()
|
||||||
{
|
{
|
||||||
collection.ReplaceOne(Builders<Inventory>.Filter.Eq(x => x.Id, Id), this);
|
collection.ReplaceOne(Builders<Inventory>.Filter.Eq(x => x.Id, Id), this);
|
||||||
|
|
|
@ -2002,19 +2002,7 @@ namespace AscNet.Common.MsgPack
|
||||||
[global::MessagePack.MessagePackObject(true)]
|
[global::MessagePack.MessagePackObject(true)]
|
||||||
public class NotifyItemDataList
|
public class NotifyItemDataList
|
||||||
{
|
{
|
||||||
[global::MessagePack.MessagePackObject(true)]
|
public List<Item> ItemDataList { get; set; } = new();
|
||||||
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 dynamic? ItemRecycleDict { get; set; }
|
public dynamic? ItemRecycleDict { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@ namespace AscNet.GameServer.Handlers
|
||||||
Id = "0",
|
Id = "0",
|
||||||
Status = 0, // MAIL_STATUS_UNREAD
|
Status = 0, // MAIL_STATUS_UNREAD
|
||||||
SendName = "AscNet Developers",
|
SendName = "AscNet Developers",
|
||||||
Title = "[IMPORTANT] Important Info Regarding This Server Software",
|
Title = "[IMPORTANT] Information Regarding This Server Software [有关本服务器软件的信息]",
|
||||||
Content = @"Hello Commandant!
|
Content = @"Hello Commandant!
|
||||||
Welcome to AscNet, we are happy that you are using this Server Software.
|
Welcome to AscNet, we are happy that you are using this Server Software.
|
||||||
This Server Software is always free and if you are paying to gain access to this you are being SCAMMED, we encourage you to help prevent another buyer like you by making a PSA or telling others whom you may see as potential users.
|
This Server Software is always free and if you are paying to gain access to this you are being SCAMMED, we encourage you to help prevent another buyer like you by making a PSA or telling others whom you may see as potential users.
|
||||||
|
@ -190,7 +190,8 @@ Sorry for the inconvinience.
|
||||||
|
|
||||||
欢迎来到 AscNet,我们很高兴您使用本服务器软件。
|
欢迎来到 AscNet,我们很高兴您使用本服务器软件。
|
||||||
本服务器软件始终是免费的,如果您是通过付费来使用本软件,那您就被骗了,我们鼓励您告诉其他潜在用户,以防止再有像您这样的买家。
|
本服务器软件始终是免费的,如果您是通过付费来使用本软件,那您就被骗了,我们鼓励您告诉其他潜在用户,以防止再有像您这样的买家。
|
||||||
不便之处,敬请原谅。",
|
不便之处,敬请原谅。
|
||||||
|
[中文版为机器翻译,准确内容请参考英文信息]",
|
||||||
CreateTime = ((DateTimeOffset)Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),
|
CreateTime = ((DateTimeOffset)Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),
|
||||||
SendTime = ((DateTimeOffset)Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),
|
SendTime = ((DateTimeOffset)Process.GetCurrentProcess().StartTime).ToUnixTimeSeconds(),
|
||||||
ExpireTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2,
|
ExpireTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2,
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
using AscNet.Common.Database;
|
||||||
|
using AscNet.Common.MsgPack;
|
||||||
|
|
||||||
|
namespace AscNet.GameServer.Handlers
|
||||||
|
{
|
||||||
|
internal class CharacterModule
|
||||||
|
{
|
||||||
|
[RequestPacketHandler("CharacterUpgradeSkillGroupRequest")]
|
||||||
|
public static void CharacterUpgradeSkillGroupRequestHandler(Session session, Packet.Request packet)
|
||||||
|
{
|
||||||
|
CharacterUpgradeSkillGroupRequest request = packet.Deserialize<CharacterUpgradeSkillGroupRequest>();
|
||||||
|
|
||||||
|
var upgradeResult = session.character.UpgradeCharacterSkillGroup(request.SkillGroupId, request.Count);
|
||||||
|
session.inventory.Do(Inventory.Coin, upgradeResult.CoinCost * -1);
|
||||||
|
session.inventory.Do(Inventory.SkillPoint, upgradeResult.SkillPointCost * -1);
|
||||||
|
|
||||||
|
NotifyCharacterDataList notifyCharacterData = new();
|
||||||
|
notifyCharacterData.CharacterDataList.AddRange(session.character.Characters.Where(x => upgradeResult.AffectedCharacters.Contains(x.Id)));
|
||||||
|
|
||||||
|
NotifyItemDataList notifyItemData = new();
|
||||||
|
notifyItemData.ItemDataList.AddRange(session.inventory.Items.Where(x => x.Id == Inventory.Coin || x.Id == Inventory.SkillPoint));
|
||||||
|
|
||||||
|
session.SendPush(notifyCharacterData);
|
||||||
|
session.SendPush(notifyItemData);
|
||||||
|
|
||||||
|
session.SendResponse(new CharacterUpgradeSkillGroupResponse(), packet.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,6 @@ namespace AscNet.GameServer.Handlers
|
||||||
|
|
||||||
internal class MailModule
|
internal class MailModule
|
||||||
{
|
{
|
||||||
|
|
||||||
[RequestPacketHandler("MailReadRequest")]
|
[RequestPacketHandler("MailReadRequest")]
|
||||||
public static void MailReadRequestHandler(Session session, Packet.Request packet)
|
public static void MailReadRequestHandler(Session session, Packet.Request packet)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using System.Reflection;
|
using System.Net.Sockets;
|
||||||
|
using System.Reflection;
|
||||||
|
using AscNet.Common.MsgPack;
|
||||||
using AscNet.Logging;
|
using AscNet.Logging;
|
||||||
using MessagePack;
|
using MessagePack;
|
||||||
|
|
||||||
|
@ -36,6 +38,11 @@ namespace AscNet.GameServer
|
||||||
|
|
||||||
[Key(2)]
|
[Key(2)]
|
||||||
public byte[] Content;
|
public byte[] Content;
|
||||||
|
|
||||||
|
public T Deserialize<T>()
|
||||||
|
{
|
||||||
|
return MessagePackSerializer.Deserialize<T>(Content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MessagePackObject(false)]
|
[MessagePackObject(false)]
|
||||||
|
|
Loading…
Reference in New Issue