forked from project-redbud/FunGame-Core
设计 Item 类,添加对应的 Converter;新增伤害统计 (#88)
* 设计 Item 类,添加对应的 Converter * 新增伤害统计和 AlterActionTypeBeforeAction
This commit is contained in:
parent
64ce1f8c92
commit
57219895fb
15
Api/Factory/EffectFactory.cs
Normal file
15
Api/Factory/EffectFactory.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Interface.Base;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Api.Factory
|
||||
{
|
||||
internal class EffectFactory : IFactory<Effect>
|
||||
{
|
||||
public Type EntityType => typeof(Effect);
|
||||
|
||||
public Effect Create()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,29 +1,15 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Interface.Base;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Api.Factory
|
||||
{
|
||||
internal class ItemFactory : IFactory<Item>
|
||||
{
|
||||
public Type EntityType => _EntityType;
|
||||
|
||||
private Type _EntityType = typeof(Item);
|
||||
|
||||
public Item Create(ItemType type = ItemType.Passive)
|
||||
{
|
||||
_EntityType = typeof(Item);
|
||||
return type switch
|
||||
{
|
||||
ItemType.Passive => new(false),
|
||||
ItemType.Active => new(true),
|
||||
_ => new(false)
|
||||
};
|
||||
}
|
||||
public Type EntityType => typeof(Item);
|
||||
|
||||
public Item Create()
|
||||
{
|
||||
return Create(ItemType.Passive);
|
||||
return new();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
Api/Factory/SkillFactory.cs
Normal file
15
Api/Factory/SkillFactory.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Interface.Base;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Api.Factory
|
||||
{
|
||||
internal class SkillFactory : IFactory<Skill>
|
||||
{
|
||||
public Type EntityType => typeof(Skill);
|
||||
|
||||
public Skill Create()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Interface.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Api.Utility
|
||||
@ -13,6 +14,27 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
/// </summary>
|
||||
public Action<string> WriteLine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前已死亡的角色顺序(第一个是最早死的)
|
||||
/// </summary>
|
||||
public List<Character> Eliminated => _eliminated;
|
||||
|
||||
/// <summary>
|
||||
/// 角色数据
|
||||
/// </summary>
|
||||
public Dictionary<Character, CharacterStatistics> CharacterStatistics => _stats;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏运行的时间
|
||||
/// </summary>
|
||||
public double TotalTime { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏运行的回合
|
||||
/// 对于某角色而言,在其行动的回合叫 Turn,而所有角色行动的回合,都称之为 Round。
|
||||
/// </summary>
|
||||
public int TotalRound { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 当前的行动顺序
|
||||
/// </summary>
|
||||
@ -58,6 +80,11 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
/// </summary>
|
||||
protected readonly Dictionary<Character, AssistDetail> _assistDamage = [];
|
||||
|
||||
/// <summary>
|
||||
/// 角色数据
|
||||
/// </summary>
|
||||
protected readonly Dictionary<Character, CharacterStatistics> _stats = [];
|
||||
|
||||
/// <summary>
|
||||
/// 游戏是否结束
|
||||
/// </summary>
|
||||
@ -91,6 +118,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
Character character = group.First();
|
||||
AddCharacter(character, Calculation.Round2Digits(_queue.Count * 0.1), false);
|
||||
_assistDamage.Add(character, new AssistDetail(character, characters.Where(c => c != character)));
|
||||
_stats.Add(character, new());
|
||||
// 初始化技能
|
||||
foreach (Skill skill in character.Skills)
|
||||
{
|
||||
@ -144,6 +172,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
{
|
||||
AddCharacter(selectedCharacter, Calculation.Round2Digits(_queue.Count * 0.1), false);
|
||||
_assistDamage.Add(selectedCharacter, new AssistDetail(selectedCharacter, characters.Where(c => c != selectedCharacter)));
|
||||
_stats.Add(selectedCharacter, new());
|
||||
// 初始化技能
|
||||
foreach (Skill skill in selectedCharacter.Skills)
|
||||
{
|
||||
@ -284,6 +313,8 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
/// <returns>是否结束游戏</returns>
|
||||
public bool ProcessTurn(Character character)
|
||||
{
|
||||
TotalRound++;
|
||||
|
||||
if (!BeforeTurn(character))
|
||||
{
|
||||
return _isGameEnd;
|
||||
@ -308,106 +339,123 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
List<Skill> skills = [.. character.Skills.Where(s => s.Level > 0 && s.SkillType != SkillType.Passive && s.Enable && !s.IsInEffect && s.CurrentCD == 0 &&
|
||||
(((s.SkillType == SkillType.SuperSkill || s.SkillType == SkillType.Skill) && s.EPCost <= character.EP) || (s.SkillType == SkillType.Magic && s.MPCost <= character.MP)))];
|
||||
|
||||
// 物品列表
|
||||
List<Item> items = [.. character.Items.Where(i => i.IsActive && i.Skills.Active != null && i.Enable &&
|
||||
i.Skills.Active.SkillType == SkillType.Item && i.Skills.Active.Enable && !i.Skills.Active.IsInEffect && i.Skills.Active.CurrentCD == 0 && i.Skills.Active.MPCost <= character.MP && i.Skills.Active.EPCost <= character.EP)];
|
||||
|
||||
// 作出了什么行动
|
||||
CharacterActionType type = CharacterActionType.None;
|
||||
|
||||
if (character.CharacterState == CharacterState.Actionable)
|
||||
// 是否能使用物品和释放技能
|
||||
bool canUseItem = items.Count > 0;
|
||||
bool canCastSkill = skills.Count > 0;
|
||||
|
||||
// 使用物品和释放技能、使用普通攻击的概率
|
||||
double pUseItem = 0.33;
|
||||
double pCastSkill = 0.33;
|
||||
double pNormalAttack = 0.34;
|
||||
|
||||
// 不允许在吟唱和预释放状态下,修改角色的行动
|
||||
if (character.CharacterState != CharacterState.Casting && character.CharacterState != CharacterState.PreCastSuperSkill)
|
||||
{
|
||||
if (character.CharacterState == CharacterState.ActionRestricted)
|
||||
CharacterActionType actionTypeTemp = CharacterActionType.None;
|
||||
foreach (Effect e in character.Effects.Where(e => e.Level > 0).ToList())
|
||||
{
|
||||
// 行动受限,只能使用特殊物品
|
||||
if (character.Items.Count > 0)
|
||||
{
|
||||
type = CharacterActionType.UseItem;
|
||||
}
|
||||
actionTypeTemp = e.AlterActionTypeBeforeAction(character, character.CharacterState, ref canUseItem, ref canCastSkill, ref pUseItem, ref pCastSkill, ref pNormalAttack);
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.BattleRestricted)
|
||||
if (actionTypeTemp != CharacterActionType.None && actionTypeTemp != CharacterActionType.CastSkill && actionTypeTemp != CharacterActionType.CastSuperSkill)
|
||||
{
|
||||
// 战斗不能,只能使用物品
|
||||
if (character.Items.Count > 0)
|
||||
{
|
||||
type = CharacterActionType.UseItem;
|
||||
}
|
||||
type = actionTypeTemp;
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.SkillRestricted)
|
||||
}
|
||||
|
||||
if (type == CharacterActionType.None)
|
||||
{
|
||||
if (character.CharacterState != CharacterState.NotActionable && character.CharacterState != CharacterState.Casting && character.CharacterState != CharacterState.PreCastSuperSkill)
|
||||
{
|
||||
// 技能受限,无法使用技能,可以使用物品
|
||||
if (character.Items.Count > 0)
|
||||
if (character.CharacterState == CharacterState.Actionable)
|
||||
{
|
||||
if (new Random().NextDouble() > 0.5)
|
||||
// 可以任意行动
|
||||
if (canUseItem && canCastSkill)
|
||||
{
|
||||
type = CharacterActionType.UseItem;
|
||||
// 不做任何处理
|
||||
}
|
||||
else if (canUseItem && !canCastSkill)
|
||||
{
|
||||
pCastSkill = 0;
|
||||
}
|
||||
else if (!canUseItem && canCastSkill)
|
||||
{
|
||||
pUseItem = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = CharacterActionType.NormalAttack;
|
||||
pUseItem = 0;
|
||||
pCastSkill = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (character.CharacterState == CharacterState.ActionRestricted)
|
||||
{
|
||||
type = CharacterActionType.NormalAttack;
|
||||
// 行动受限,只能使用特殊物品
|
||||
if (canUseItem)
|
||||
{
|
||||
pCastSkill = 0;
|
||||
pNormalAttack = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pUseItem = 0;
|
||||
pCastSkill = 0;
|
||||
pNormalAttack = 0;
|
||||
}
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.BattleRestricted)
|
||||
{
|
||||
// 战斗不能,只能使用物品
|
||||
if (canUseItem)
|
||||
{
|
||||
pCastSkill = 0;
|
||||
pNormalAttack = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pUseItem = 0;
|
||||
pCastSkill = 0;
|
||||
pNormalAttack = 0;
|
||||
}
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.SkillRestricted)
|
||||
{
|
||||
// 技能受限,无法使用技能,可以使用物品
|
||||
if (canUseItem)
|
||||
{
|
||||
pCastSkill = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pUseItem = 0;
|
||||
pCastSkill = 0;
|
||||
}
|
||||
}
|
||||
type = GetActionType(pUseItem, pCastSkill, pNormalAttack);
|
||||
_stats[character].ActionTurn += 1;
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.Casting)
|
||||
{
|
||||
// 如果角色上一次吟唱了魔法,这次的行动则是结算这个魔法
|
||||
type = CharacterActionType.CastSkill;
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.PreCastSuperSkill)
|
||||
{
|
||||
// 角色使用回合外爆发技插队
|
||||
type = CharacterActionType.CastSuperSkill;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 可以任意行动
|
||||
bool canUseItem = character.Items.Count > 0;
|
||||
bool canCastSkill = skills.Count > 0;
|
||||
if (canUseItem && canCastSkill)
|
||||
{
|
||||
double dowhat = new Random().NextDouble();
|
||||
if (dowhat < 0.33)
|
||||
{
|
||||
type = CharacterActionType.UseItem;
|
||||
}
|
||||
else if (dowhat < 0.66)
|
||||
{
|
||||
type = CharacterActionType.PreCastSkill;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = CharacterActionType.NormalAttack;
|
||||
}
|
||||
}
|
||||
else if (canUseItem && !canCastSkill)
|
||||
{
|
||||
if (new Random().NextDouble() > 0.5)
|
||||
{
|
||||
type = CharacterActionType.UseItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = CharacterActionType.NormalAttack;
|
||||
}
|
||||
}
|
||||
else if (!canUseItem && canCastSkill)
|
||||
{
|
||||
if (new Random().NextDouble() > 0.5)
|
||||
{
|
||||
type = CharacterActionType.PreCastSkill;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = CharacterActionType.NormalAttack;
|
||||
}
|
||||
}
|
||||
else type = CharacterActionType.NormalAttack;
|
||||
WriteLine("[ " + character + $" ] 完全行动不能!");
|
||||
type = CharacterActionType.None;
|
||||
}
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.Casting)
|
||||
{
|
||||
// 如果角色上一次吟唱了魔法,这次的行动则是结算这个魔法
|
||||
type = CharacterActionType.CastSkill;
|
||||
}
|
||||
else if (character.CharacterState == CharacterState.PreCastSuperSkill)
|
||||
{
|
||||
// 角色使用回合外爆发技插队
|
||||
type = CharacterActionType.CastSuperSkill;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine("[ " + character + $" ] 完全行动不能!");
|
||||
}
|
||||
|
||||
List<Character> enemysTemp = new(enemys);
|
||||
List<Character> teammatesTemp = new(teammates);
|
||||
@ -463,7 +511,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
skill.CurrentCD = Calculation.Round2Digits(Math.Max(1, skill.CD * (1 - character.CDR)));
|
||||
skill.Enable = false;
|
||||
|
||||
WriteLine("[ " + character + $" ] 消耗了 {cost:f2} 点能量,释放了{(skill.IsSuperSkill ? "爆发技" : "战技")} {skill.Name}!");
|
||||
WriteLine("[ " + character + $" ] 消耗了 {cost:0.##} 点能量,释放了{(skill.IsSuperSkill ? "爆发技" : "战技")} {skill.Name}!");
|
||||
skill.OnSkillCasted(this, character, enemys, teammates);
|
||||
|
||||
foreach (Effect effect in character.Effects.Where(e => e.Level > 0).ToList())
|
||||
@ -488,7 +536,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
skill.CurrentCD = Calculation.Round2Digits(Math.Max(1, skill.CD * (1 - character.CDR)));
|
||||
skill.Enable = false;
|
||||
|
||||
WriteLine("[ " + character + $" ] 消耗了 {cost:f2} 点魔法值,释放了技能 {skill.Name}!");
|
||||
WriteLine("[ " + character + $" ] 消耗了 {cost:0.##} 点魔法值,释放了技能 {skill.Name}!");
|
||||
skill.OnSkillCasted(this, character, enemys, teammates);
|
||||
}
|
||||
else
|
||||
@ -518,7 +566,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
skill.CurrentCD = Calculation.Round2Digits(Math.Max(1, skill.CD * (1 - character.CDR)));
|
||||
skill.Enable = false;
|
||||
|
||||
WriteLine("[ " + character + $" ] 消耗了 {cost:f2} 点能量值,释放了爆发技 {skill.Name}!");
|
||||
WriteLine("[ " + character + $" ] 消耗了 {cost:0.##} 点能量值,释放了爆发技 {skill.Name}!");
|
||||
skill.OnSkillCasted(this, character, enemys, teammates);
|
||||
}
|
||||
else
|
||||
@ -613,14 +661,22 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
|
||||
// 获取第一个角色的硬直时间
|
||||
double timeToReduce = _hardnessTimes[_queue[0]];
|
||||
TotalTime = Calculation.Round2Digits(TotalTime + timeToReduce);
|
||||
|
||||
WriteLine("时间流逝:" + timeToReduce);
|
||||
|
||||
// 减少所有角色的硬直时间
|
||||
foreach (Character character in _queue)
|
||||
{
|
||||
// 减少所有角色的硬直时间
|
||||
_hardnessTimes[character] = Calculation.Round2Digits(_hardnessTimes[character] - timeToReduce);
|
||||
|
||||
// 统计
|
||||
_stats[character].LiveRound += 1;
|
||||
_stats[character].LiveTime = Calculation.Round2Digits(_stats[character].LiveTime + timeToReduce);
|
||||
_stats[character].DamagePerRound = Calculation.Round2Digits(_stats[character].TotalDamage / TotalRound);
|
||||
_stats[character].DamagePerTurn = Calculation.Round2Digits(_stats[character].TotalDamage / _stats[character].LiveRound);
|
||||
_stats[character].DamagePerSecond = Calculation.Round2Digits(_stats[character].TotalDamage / _stats[character].LiveTime);
|
||||
|
||||
// 回血回蓝
|
||||
double recoveryHP = Calculation.Round2Digits(character.HR * timeToReduce);
|
||||
double recoveryMP = Calculation.Round2Digits(character.MR * timeToReduce);
|
||||
@ -727,6 +783,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
else WriteLine("[ " + enemy + $" ] 受到了 {damage} 点物理伤害!");
|
||||
enemy.HP = Calculation.Round2Digits(enemy.HP - damage);
|
||||
|
||||
// 统计伤害
|
||||
CalculateCharacterDamageStatistics(actor, damage, isMagicDamage);
|
||||
|
||||
// 计算助攻
|
||||
_assistDamage[actor][enemy] += damage;
|
||||
|
||||
@ -789,7 +848,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
{
|
||||
bool isMagic = false;
|
||||
MagicType magicType = MagicType.None;
|
||||
foreach(Effect effect in actor.Effects.Union(enemy.Effects).Where(e => e.Level > 0).ToList())
|
||||
foreach (Effect effect in actor.Effects.Union(enemy.Effects).Where(e => e.Level > 0).ToList())
|
||||
{
|
||||
effect.AlterDamageTypeBeforeCalculation(actor, enemy, ref isNormalAttack, ref isMagic, ref magicType);
|
||||
}
|
||||
@ -904,7 +963,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
}
|
||||
}
|
||||
|
||||
MagicResistance magicResistance = magicType switch
|
||||
double MDF = magicType switch
|
||||
{
|
||||
MagicType.Starmark => enemy.MDF.Starmark,
|
||||
MagicType.PurityNatural => enemy.MDF.PurityNatural,
|
||||
@ -918,7 +977,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
};
|
||||
|
||||
// 魔法穿透后的魔法抗性
|
||||
double MDF = Calculation.Round2Digits((1 - actor.MagicalPenetration) * magicResistance.Value);
|
||||
MDF = Calculation.Round2Digits((1 - actor.MagicalPenetration) * MDF);
|
||||
|
||||
// 最终的魔法伤害
|
||||
finalDamage = Calculation.Round2Digits(expectedDamage * (1 - MDF));
|
||||
@ -1146,5 +1205,69 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过概率计算角色要干嘛
|
||||
/// </summary>
|
||||
/// <param name="pUseItem"></param>
|
||||
/// <param name="pCastSkill"></param>
|
||||
/// <param name="pNormalAttack"></param>
|
||||
/// <returns></returns>
|
||||
public static CharacterActionType GetActionType(double pUseItem, double pCastSkill, double pNormalAttack)
|
||||
{
|
||||
if (pUseItem == 0 && pCastSkill == 0 && pNormalAttack == 0)
|
||||
{
|
||||
return CharacterActionType.None;
|
||||
}
|
||||
|
||||
double total = pUseItem + pCastSkill + pNormalAttack;
|
||||
|
||||
// 浮点数比较时处理误差
|
||||
if (Math.Abs(total - 1) > 1e-6)
|
||||
{
|
||||
pUseItem /= total;
|
||||
pCastSkill /= total;
|
||||
pNormalAttack /= total;
|
||||
}
|
||||
|
||||
double rand = new Random().NextDouble();
|
||||
|
||||
// 按概率进行检查
|
||||
if (rand < pUseItem)
|
||||
{
|
||||
return CharacterActionType.UseItem;
|
||||
}
|
||||
|
||||
if (rand < pUseItem + pCastSkill)
|
||||
{
|
||||
return CharacterActionType.PreCastSkill;
|
||||
}
|
||||
|
||||
if (rand < pUseItem + pCastSkill + pNormalAttack)
|
||||
{
|
||||
return CharacterActionType.NormalAttack;
|
||||
}
|
||||
|
||||
return CharacterActionType.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算角色的数据
|
||||
/// </summary>
|
||||
public void CalculateCharacterDamageStatistics(Character character, double damage, bool isMagic)
|
||||
{
|
||||
if (_stats.TryGetValue(character, out CharacterStatistics? stats) && stats != null)
|
||||
{
|
||||
if (isMagic)
|
||||
{
|
||||
stats.TotalMagicDamage = Calculation.Round2Digits(stats.TotalMagicDamage + damage);
|
||||
}
|
||||
else
|
||||
{
|
||||
stats.TotalPhysicalDamage = Calculation.Round2Digits(stats.TotalPhysicalDamage + damage);
|
||||
}
|
||||
stats.TotalDamage = Calculation.Round2Digits(stats.TotalDamage + damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
{
|
||||
private readonly static CharacterFactory CharacterFactory = new();
|
||||
private readonly static InventoryFactory InventoryFactory = new();
|
||||
private readonly static SkillFactory SkillFactory = new();
|
||||
private readonly static EffectFactory EffectFactory = new();
|
||||
private readonly static ItemFactory ItemFactory = new();
|
||||
private readonly static RoomFactory RoomFactory = new();
|
||||
private readonly static UserFactory UserFactory = new();
|
||||
@ -32,14 +34,31 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
return InventoryFactory.Create();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取技能实例
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Skill GetSkill()
|
||||
{
|
||||
return SkillFactory.Create();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取技能特效实例
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Effect GetEffect()
|
||||
{
|
||||
return EffectFactory.Create();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取物品实例
|
||||
/// </summary>
|
||||
/// <param name="type">Item类型 主动 或 被动</param>
|
||||
/// <returns></returns>
|
||||
public static Item GetItem(ItemType type = ItemType.Passive)
|
||||
public static Item GetItem()
|
||||
{
|
||||
return ItemFactory.Create(type);
|
||||
return ItemFactory.Create();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -245,6 +245,42 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public static T? JsonDeserializeFromHashtable<T>(Hashtable hashtable, string key, JsonSerializerOptions options) => Service.JsonManager.GetObject<T>(hashtable, key, options);
|
||||
|
||||
// 创建一个静态 HttpClient 实例,供整个应用程序生命周期使用
|
||||
private static readonly HttpClient client = new();
|
||||
|
||||
/// <summary>
|
||||
/// 发送 GET 请求
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<T?> HttpGet<T>(string url)
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync(url);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
T? result = JsonDeserialize<T>(content);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送 POST 请求
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="json"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<T?> HttpPost<T>(string url, string json)
|
||||
{
|
||||
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(url, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string read = await response.Content.ReadAsStringAsync();
|
||||
T? result = JsonDeserialize<T>(read);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -37,6 +37,11 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// </summary>
|
||||
public CharacterProfile Profile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 角色的详细资料
|
||||
/// </summary>
|
||||
public EquipSlot EquipSlot { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 魔法属性
|
||||
/// </summary>
|
||||
@ -366,7 +371,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <summary>
|
||||
/// 魔法抗性(%) [ 与技能和物品相关 ]
|
||||
/// </summary>
|
||||
public MDF MDF { get; set; }
|
||||
public MagicResistance MDF { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物理穿透(%) [ 与技能和物品相关 ]
|
||||
@ -748,6 +753,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
User = General.UnknownUserInstance;
|
||||
Profile = new(Name, FirstName, NickName);
|
||||
EquipSlot = new();
|
||||
MDF = new();
|
||||
NormalAttack = new(this);
|
||||
}
|
||||
@ -810,13 +816,13 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 比较一个角色(只比较 <see cref="Name"/>)
|
||||
/// 比较一个角色(只比较 <see cref="ToString"/>)
|
||||
/// </summary>
|
||||
/// <param name="other"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(IBaseEntity? other)
|
||||
{
|
||||
return other is Character c && c.Name == Name;
|
||||
return other is Character c && c.ToString() == ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -891,8 +897,8 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
builder.AppendLine($"能量值:{EP} / 200");
|
||||
builder.AppendLine($"攻击力:{ATK}" + (ExATK + ExATK2 > 0 ? $" [{BaseATK} + {ExATK + ExATK2}]" : ""));
|
||||
builder.AppendLine($"物理护甲:{DEF}" + (ExDEF + ExDEF2 > 0 ? $" [{BaseDEF} + {ExDEF + ExDEF2}]" : "") + $" ({PDR * 100:f2}%)");
|
||||
double mdf = Calculation.Round4Digits((MDF.None.Value + MDF.Starmark.Value + MDF.PurityNatural.Value + MDF.PurityContemporary.Value +
|
||||
MDF.Bright.Value + MDF.Shadow.Value + MDF.Element.Value + MDF.Fleabane.Value + MDF.Particle.Value) / 9);
|
||||
double mdf = Calculation.Round4Digits((MDF.None + MDF.Starmark + MDF.PurityNatural + MDF.PurityContemporary +
|
||||
MDF.Bright + MDF.Shadow + MDF.Element + MDF.Fleabane + MDF.Particle) / 9);
|
||||
builder.AppendLine($"魔法抗性:{mdf * 100:f2}%(平均)");
|
||||
double exSPD = Calculation.Round2Digits(AGI * 0.65 + ExSPD);
|
||||
builder.AppendLine($"行动速度:{SPD}" + (exSPD > 0 ? $" [{InitialSPD} + {exSPD}]" : "") + $" ({ActionCoefficient * 100:f2}%)");
|
||||
|
||||
@ -2,6 +2,12 @@
|
||||
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色的一些个人信息
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="firstname"></param>
|
||||
/// <param name="nickname"></param>
|
||||
public class CharacterProfile(string name, string firstname, string nickname)
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
33
Entity/Character/EquipSlot.cs
Normal file
33
Entity/Character/EquipSlot.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色的装备槽位
|
||||
/// </summary>
|
||||
public class EquipSlot()
|
||||
{
|
||||
/// <summary>
|
||||
/// 魔法卡包
|
||||
/// </summary>
|
||||
public Item? MagicCardPack { get; set; } = null;
|
||||
/// <summary>
|
||||
/// 武器
|
||||
/// </summary>
|
||||
public Item? Weapon { get; set; } = null;
|
||||
/// <summary>
|
||||
/// 防具
|
||||
/// </summary>
|
||||
public Item? Armor { get; set; } = null;
|
||||
/// <summary>
|
||||
/// 鞋子
|
||||
/// </summary>
|
||||
public Item? Shoes { get; set; } = null;
|
||||
/// <summary>
|
||||
/// 饰品1
|
||||
/// </summary>
|
||||
public Item? Accessory1 { get; set; } = null;
|
||||
/// <summary>
|
||||
/// 饰品2
|
||||
/// </summary>
|
||||
public Item? Accessory2 { get; set; } = null;
|
||||
}
|
||||
}
|
||||
@ -1,23 +1,18 @@
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
public class MDF()
|
||||
/// <summary>
|
||||
/// 角色的魔法抗性,对不同的魔法类型有不同抗性
|
||||
/// </summary>
|
||||
public class MagicResistance()
|
||||
{
|
||||
public MagicResistance None { get; } = new(MagicType.None);
|
||||
public MagicResistance Starmark { get; } = new(MagicType.Starmark);
|
||||
public MagicResistance PurityNatural { get; } = new(MagicType.PurityNatural);
|
||||
public MagicResistance PurityContemporary { get; } = new(MagicType.PurityContemporary);
|
||||
public MagicResistance Bright { get; } = new(MagicType.Bright);
|
||||
public MagicResistance Shadow { get; } = new(MagicType.Shadow);
|
||||
public MagicResistance Element { get; } = new(MagicType.Element);
|
||||
public MagicResistance Fleabane { get; } = new(MagicType.Fleabane);
|
||||
public MagicResistance Particle { get; } = new(MagicType.Particle);
|
||||
}
|
||||
|
||||
public class MagicResistance(MagicType type = MagicType.None, double value = 0)
|
||||
{
|
||||
public MagicType MagicType { get; } = type;
|
||||
public double Value { get; set; } = value;
|
||||
public double None { get; set; } = 0;
|
||||
public double Starmark { get; set; } = 0;
|
||||
public double PurityNatural { get; set; } = 0;
|
||||
public double PurityContemporary { get; set; } = 0;
|
||||
public double Bright { get; set; } = 0;
|
||||
public double Shadow { get; set; } = 0;
|
||||
public double Element { get; set; } = 0;
|
||||
public double Fleabane { get; set; } = 0;
|
||||
public double Particle { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,25 +1,126 @@
|
||||
using Milimoe.FunGame.Core.Interface.Entity;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Interface.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 和 <see cref="Skill"/> 一样,需要继承构造
|
||||
/// </summary>
|
||||
public class Item : BaseEntity, IItem
|
||||
{
|
||||
public string Describe { get; set; } = "";
|
||||
public double Price { get; set; }
|
||||
public char Key { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool Enable { get; set; }
|
||||
public Character? Character { get; set; } = null;
|
||||
public Skill? Skill { get; set; } = null;
|
||||
/// <summary>
|
||||
/// 物品的描述
|
||||
/// </summary>
|
||||
public string Description { get; } = "";
|
||||
|
||||
internal Item(bool active = false)
|
||||
/// <summary>
|
||||
/// 物品类型
|
||||
/// </summary>
|
||||
public virtual ItemType ItemType { get; set; } = ItemType.Others;
|
||||
|
||||
/// <summary>
|
||||
/// 物品槽位
|
||||
/// </summary>
|
||||
public virtual EquipSlotType EquipSlotType { get; set; } = EquipSlotType.None;
|
||||
|
||||
/// <summary>
|
||||
/// 物品的价格
|
||||
/// </summary>
|
||||
public double Price { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 快捷键
|
||||
/// </summary>
|
||||
public char Key { get; set; } = '/';
|
||||
|
||||
/// <summary>
|
||||
/// 是否是主动物品
|
||||
/// </summary>
|
||||
public bool IsActive => Skills.Active != null;
|
||||
|
||||
/// <summary>
|
||||
/// 是否可用(涉及冷却和禁用等)
|
||||
/// </summary>
|
||||
public bool Enable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 物品所属的角色
|
||||
/// </summary>
|
||||
public Character? Character { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 物品拥有的技能
|
||||
/// </summary>
|
||||
public SkillGroup Skills { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 当获得物品时
|
||||
/// </summary>
|
||||
public void OnItemGained()
|
||||
{
|
||||
IsActive = active;
|
||||
foreach (Skill skill in Skills.Passive)
|
||||
{
|
||||
if (!skill.IsActive && skill.Level > 0)
|
||||
{
|
||||
foreach (Effect e in skill.AddInactiveEffectToCharacter())
|
||||
{
|
||||
e.ActionQueue = skill.ActionQueue;
|
||||
if (Character != null && !Character.Effects.Contains(e))
|
||||
{
|
||||
Character.Effects.Add(e);
|
||||
e.OnEffectGained(Character);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 局内使用物品触发
|
||||
/// </summary>
|
||||
public void UseItem(ActionQueue queue, List<Character> enemys, List<Character> teammates)
|
||||
{
|
||||
if (Skills.Active != null && Character != null)
|
||||
{
|
||||
Skills.Active.OnSkillCasted(queue, Character, enemys, teammates);
|
||||
}
|
||||
OnItemUsed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 局外(库存)使用物品触发
|
||||
/// </summary>
|
||||
public void UseItem(/*Inventory inventory*/)
|
||||
{
|
||||
|
||||
OnItemUsed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当物品被使用时
|
||||
/// </summary>
|
||||
public virtual void OnItemUsed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected Item(ItemType type, EquipSlotType slot = EquipSlotType.None)
|
||||
{
|
||||
ItemType = type;
|
||||
EquipSlotType = slot;
|
||||
}
|
||||
|
||||
internal Item() { }
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个物品是否相同 检查Id.Name
|
||||
/// </summary>
|
||||
/// <param name="other"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(IBaseEntity? other)
|
||||
{
|
||||
return other is Item c && c.Name == Name;
|
||||
return other is Item c && c.Id + "." + c.Name == Id + "." + Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
Entity/Item/SkillGroup.cs
Normal file
18
Entity/Item/SkillGroup.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 物品只有一个主动技能,但是可以有很多个被动技能
|
||||
/// </summary>
|
||||
public class SkillGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一的主动技能
|
||||
/// </summary>
|
||||
public Skill? Active { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 被动技能组
|
||||
/// </summary>
|
||||
public HashSet<Skill> Passive { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@ -8,12 +8,12 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <summary>
|
||||
/// 特殊效果类,需要继承
|
||||
/// </summary>
|
||||
public abstract class Effect(Skill skill) : BaseEntity
|
||||
public class Effect : BaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属的技能
|
||||
/// </summary>
|
||||
public Skill Skill { get; } = skill;
|
||||
public Skill Skill { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 特殊效果类型<para/>
|
||||
@ -101,6 +101,16 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
}
|
||||
}
|
||||
|
||||
protected Effect(Skill skill)
|
||||
{
|
||||
Skill = skill;
|
||||
}
|
||||
|
||||
internal Effect()
|
||||
{
|
||||
Skill = Factory.GetSkill();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得此特效时
|
||||
/// </summary>
|
||||
@ -359,6 +369,22 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 行动开始前,指定角色的行动,而不是使用顺序表自带的逻辑;或者修改对应的操作触发概率
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="canUseItem"></param>
|
||||
/// <param name="canCastSkill"></param>
|
||||
/// <param name="pUseItem"></param>
|
||||
/// <param name="pCastSkill"></param>
|
||||
/// <param name="pNormalAttack"></param>
|
||||
/// <returns></returns>
|
||||
public virtual CharacterActionType AlterActionTypeBeforeAction(Character character, CharacterState state, ref bool canUseItem, ref bool canCastSkill, ref double pUseItem, ref double pCastSkill, ref double pNormalAttack)
|
||||
{
|
||||
return CharacterActionType.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对敌人造成技能伤害 [ 强烈建议使用此方法造成伤害而不是自行调用 <see cref="ActionQueue.DamageToEnemy"/> ]
|
||||
/// </summary>
|
||||
@ -415,7 +441,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <returns></returns>
|
||||
public override bool Equals(IBaseEntity? other)
|
||||
{
|
||||
return other is Effect c && c.Name == Name;
|
||||
return other is Effect c && c.Id + "." + Name == Id + "." + Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,11 +20,6 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// </summary>
|
||||
public virtual string Description { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 快捷键
|
||||
/// </summary>
|
||||
public char Key { get; set; } = '/';
|
||||
|
||||
/// <summary>
|
||||
/// 技能等级,等于 0 时可以称之为尚未学习
|
||||
/// </summary>
|
||||
@ -43,7 +38,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 技能 [ 此项为最高优先级 ]
|
||||
/// 技能类型 [ 此项为最高优先级 ]
|
||||
/// </summary>
|
||||
[InitRequired]
|
||||
public SkillType SkillType { get; set; }
|
||||
@ -138,12 +133,22 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// </summary>
|
||||
public ActionQueue? ActionQueue { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 继承此类实现时,调用基类的构造函数
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="character"></param>
|
||||
protected Skill(SkillType type, Character? character = null)
|
||||
{
|
||||
SkillType = type;
|
||||
Character = character;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于构造 JSON
|
||||
/// </summary>
|
||||
internal Skill() { }
|
||||
|
||||
/// <summary>
|
||||
/// 触发技能升级
|
||||
/// </summary>
|
||||
@ -257,9 +262,14 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个技能是否相同 检查Id.Name
|
||||
/// </summary>
|
||||
/// <param name="other"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(IBaseEntity? other)
|
||||
{
|
||||
return other is Skill c && c.Name == Name;
|
||||
return other is Skill c && c.Id + "." + c.Name == Id + "." + Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,24 +1,32 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
public class CharacterStatistics
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Character? Character { get; set; } = null;
|
||||
public Hashtable? DamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? PhysicalDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? MagicDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? RealDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgLiveRoundStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgDamageRoundStats { get; set; } = new Hashtable();
|
||||
public Hashtable? KillStats { get; set; } = new Hashtable();
|
||||
public Hashtable? DeathStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AssistStats { get; set; } = new Hashtable();
|
||||
public Hashtable? Plays { get; set; } = new Hashtable();
|
||||
public Hashtable? Wins { get; set; } = new Hashtable();
|
||||
public Hashtable? Loses { get; set; } = new Hashtable();
|
||||
public Hashtable? Winrates { get; set; } = new Hashtable();
|
||||
public double TotalDamage { get; set; } = 0;
|
||||
public double TotalPhysicalDamage { get; set; } = 0;
|
||||
public double TotalMagicDamage { get; set; } = 0;
|
||||
public double TotalRealDamage { get; set; } = 0;
|
||||
public double AvgDamage { get; set; } = 0;
|
||||
public double AvgPhysicalDamage { get; set; } = 0;
|
||||
public double AvgMagicDamage { get; set; } = 0;
|
||||
public double AvgRealDamage { get; set; } = 0;
|
||||
public int LiveRound { get; set; } = 0;
|
||||
public int AvgLiveRound { get; set; } = 0;
|
||||
public int ActionTurn { get; set; } = 0;
|
||||
public int AvgActionTurn { get; set; } = 0;
|
||||
public double LiveTime { get; set; } = 0;
|
||||
public double AvgLiveTime { get; set; } = 0;
|
||||
public double DamagePerRound { get; set; } = 0;
|
||||
public double DamagePerTurn { get; set; } = 0;
|
||||
public double DamagePerSecond { get; set; } = 0;
|
||||
public double TotalEarnedMoney { get; set; } = 0;
|
||||
public double AvgEarnedMoney { get; set; } = 0;
|
||||
public double Kills { get; set; } = 0;
|
||||
public double Deaths { get; set; } = 0;
|
||||
public double Assists { get; set; } = 0;
|
||||
public double Plays { get; set; } = 0;
|
||||
public double Wins { get; set; } = 0;
|
||||
public double Loses { get; set; } = 0;
|
||||
public double Winrates { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,7 @@
|
||||
{
|
||||
public interface IItem : IActiveEnable, IRelateCharacter
|
||||
{
|
||||
public string Describe { get; set; }
|
||||
public string Description { get; }
|
||||
public double Price { get; set; }
|
||||
public char Key { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,12 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
case nameof(Character.NickName):
|
||||
result.NickName = reader.GetString() ?? "";
|
||||
break;
|
||||
case nameof(Character.Profile):
|
||||
result.Profile = NetworkUtility.JsonDeserialize<CharacterProfile>(ref reader, options) ?? new(result.Name, result.FirstName, result.NickName);
|
||||
break;
|
||||
case nameof(Character.EquipSlot):
|
||||
result.EquipSlot = NetworkUtility.JsonDeserialize<EquipSlot>(ref reader, options) ?? new();
|
||||
break;
|
||||
case nameof(Character.MagicType):
|
||||
result.MagicType = (MagicType)reader.GetInt32();
|
||||
break;
|
||||
@ -84,7 +90,7 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
result.ExDEF2 = reader.GetDouble();
|
||||
break;
|
||||
case nameof(Character.MDF):
|
||||
result.MDF = NetworkUtility.JsonDeserialize<MDF>(ref reader, options) ?? new();
|
||||
result.MDF = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
break;
|
||||
case nameof(Character.PhysicalPenetration):
|
||||
result.PhysicalPenetration = reader.GetDouble();
|
||||
@ -173,6 +179,10 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
writer.WriteString(nameof(Character.Name), value.Name);
|
||||
writer.WriteString(nameof(Character.FirstName), value.FirstName);
|
||||
writer.WriteString(nameof(Character.NickName), value.NickName);
|
||||
writer.WritePropertyName(nameof(Character.Profile));
|
||||
JsonSerializer.Serialize(writer, value.Profile, options);
|
||||
writer.WritePropertyName(nameof(Character.EquipSlot));
|
||||
JsonSerializer.Serialize(writer, value.EquipSlot, options);
|
||||
writer.WriteNumber(nameof(Character.MagicType), (int)value.MagicType);
|
||||
writer.WriteNumber(nameof(Character.FirstRoleType), (int)value.FirstRoleType);
|
||||
writer.WriteNumber(nameof(Character.SecondRoleType), (int)value.SecondRoleType);
|
||||
|
||||
37
Library/Common/JsonConverter/EffectConverter.cs
Normal file
37
Library/Common/JsonConverter/EffectConverter.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
{
|
||||
public class EffectConverter : BaseEntityConverter<Effect>
|
||||
{
|
||||
public override Effect NewInstance()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref Effect result)
|
||||
{
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(Effect.Id):
|
||||
result.Id = reader.GetInt64();
|
||||
break;
|
||||
case nameof(Effect.Name):
|
||||
result.Name = reader.GetString() ?? "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Effect value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WriteNumber(nameof(Effect.Id), (int)value.Id);
|
||||
writer.WriteString(nameof(Effect.Name), value.Name);
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
90
Library/Common/JsonConverter/EquipSlotConverter.cs
Normal file
90
Library/Common/JsonConverter/EquipSlotConverter.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System.Text.Json;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
{
|
||||
public class EquipSlotConverter : BaseEntityConverter<EquipSlot>
|
||||
{
|
||||
public override EquipSlot NewInstance()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref EquipSlot result)
|
||||
{
|
||||
Item temp;
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(EquipSlot.MagicCardPack):
|
||||
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
||||
if (temp.EquipSlotType == Constant.EquipSlotType.MagicCardPack)
|
||||
{
|
||||
result.MagicCardPack = temp;
|
||||
}
|
||||
break;
|
||||
case nameof(EquipSlot.Weapon):
|
||||
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
||||
if (temp.EquipSlotType == Constant.EquipSlotType.Weapon)
|
||||
{
|
||||
result.Weapon = temp;
|
||||
}
|
||||
break;
|
||||
case nameof(EquipSlot.Armor):
|
||||
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
||||
if (temp.EquipSlotType == Constant.EquipSlotType.Armor)
|
||||
{
|
||||
result.Armor = temp;
|
||||
}
|
||||
break;
|
||||
case nameof(EquipSlot.Shoes):
|
||||
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
||||
if (temp.EquipSlotType == Constant.EquipSlotType.Shoes)
|
||||
{
|
||||
result.Shoes = temp;
|
||||
}
|
||||
break;
|
||||
case nameof(EquipSlot.Accessory1):
|
||||
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
||||
if (temp.EquipSlotType == Constant.EquipSlotType.Accessory1)
|
||||
{
|
||||
result.Accessory1 = temp;
|
||||
}
|
||||
break;
|
||||
case nameof(EquipSlot.Accessory2):
|
||||
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
||||
if (temp.EquipSlotType == Constant.EquipSlotType.Accessory2)
|
||||
{
|
||||
result.Accessory2 = temp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, EquipSlot value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WritePropertyName(nameof(value.MagicCardPack));
|
||||
JsonSerializer.Serialize(writer, value.MagicCardPack, options);
|
||||
|
||||
writer.WritePropertyName(nameof(value.Weapon));
|
||||
JsonSerializer.Serialize(writer, value.Weapon, options);
|
||||
|
||||
writer.WritePropertyName(nameof(value.Armor));
|
||||
JsonSerializer.Serialize(writer, value.Armor, options);
|
||||
|
||||
writer.WritePropertyName(nameof(value.Shoes));
|
||||
JsonSerializer.Serialize(writer, value.Shoes, options);
|
||||
|
||||
writer.WritePropertyName(nameof(value.Accessory1));
|
||||
JsonSerializer.Serialize(writer, value.Accessory1, options);
|
||||
|
||||
writer.WritePropertyName(nameof(value.Accessory2));
|
||||
JsonSerializer.Serialize(writer, value.Accessory2, options);
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Library/Common/JsonConverter/ItemConverter.cs
Normal file
42
Library/Common/JsonConverter/ItemConverter.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Text.Json;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
{
|
||||
public class ItemConverter : BaseEntityConverter<Item>
|
||||
{
|
||||
public override Item NewInstance()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref Item result)
|
||||
{
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(Item.Id):
|
||||
result.Id = reader.GetInt64();
|
||||
break;
|
||||
case nameof(Item.Name):
|
||||
result.Name = reader.GetString() ?? "";
|
||||
break;
|
||||
case nameof(Item.ItemType):
|
||||
result.ItemType = (ItemType)reader.GetInt32();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Item value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WriteNumber(nameof(Item.Id), (int)value.Id);
|
||||
writer.WriteString(nameof(Item.Name), value.Name);
|
||||
writer.WriteNumber(nameof(Item.ItemType), (int)value.ItemType);
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,124 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
{
|
||||
public class MDFConverter : BaseEntityConverter<MDF>
|
||||
{
|
||||
public override MDF NewInstance()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref MDF result)
|
||||
{
|
||||
MagicResistance temp;
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(MDF.None):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.None)
|
||||
{
|
||||
result.None.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.Starmark):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.Starmark)
|
||||
{
|
||||
result.Starmark.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.PurityNatural):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.PurityNatural)
|
||||
{
|
||||
result.PurityNatural.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.PurityContemporary):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.PurityContemporary)
|
||||
{
|
||||
result.PurityContemporary.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.Bright):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.Bright)
|
||||
{
|
||||
result.Bright.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.Shadow):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.Shadow)
|
||||
{
|
||||
result.Shadow.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.Element):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.Element)
|
||||
{
|
||||
result.Element.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.Fleabane):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.Fleabane)
|
||||
{
|
||||
result.Fleabane.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MDF.Particle):
|
||||
temp = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||
if (temp.MagicType == MagicType.Particle)
|
||||
{
|
||||
result.Particle.Value = temp.Value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, MDF value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.None));
|
||||
JsonSerializer.Serialize(writer, value.None, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.Starmark));
|
||||
JsonSerializer.Serialize(writer, value.Starmark, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.PurityNatural));
|
||||
JsonSerializer.Serialize(writer, value.PurityNatural, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.PurityContemporary));
|
||||
JsonSerializer.Serialize(writer, value.PurityContemporary, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.Bright));
|
||||
JsonSerializer.Serialize(writer, value.Bright, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.Shadow));
|
||||
JsonSerializer.Serialize(writer, value.Shadow, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.Element));
|
||||
JsonSerializer.Serialize(writer, value.Element, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.Fleabane));
|
||||
JsonSerializer.Serialize(writer, value.Fleabane, options);
|
||||
|
||||
writer.WritePropertyName(nameof(MDF.Particle));
|
||||
JsonSerializer.Serialize(writer, value.Particle, options);
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
|
||||
public class MagicResistanceConverter : BaseEntityConverter<MagicResistance>
|
||||
{
|
||||
public override MagicResistance NewInstance()
|
||||
@ -130,11 +15,32 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
{
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(MagicResistance.MagicType):
|
||||
result = new((MagicType)reader.GetInt32(), result.Value);
|
||||
case nameof(MagicResistance.None):
|
||||
result.None = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.Value):
|
||||
result.Value = reader.GetDouble();
|
||||
case nameof(MagicResistance.Starmark):
|
||||
result.Starmark = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.PurityNatural):
|
||||
result.PurityNatural = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.PurityContemporary):
|
||||
result.PurityContemporary = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.Bright):
|
||||
result.Bright = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.Shadow):
|
||||
result.Shadow = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.Element):
|
||||
result.Element = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.Fleabane):
|
||||
result.Fleabane = reader.GetDouble();
|
||||
break;
|
||||
case nameof(MagicResistance.Particle):
|
||||
result.Particle = reader.GetDouble();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -142,8 +48,17 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
public override void Write(Utf8JsonWriter writer, MagicResistance value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
writer.WriteNumber(nameof(MagicResistance.MagicType), (int)value.MagicType);
|
||||
writer.WriteNumber(nameof(MagicResistance.Value), value.Value);
|
||||
|
||||
writer.WriteNumber(nameof(MagicResistance.None), value.None);
|
||||
writer.WriteNumber(nameof(MagicResistance.Starmark), value.Starmark);
|
||||
writer.WriteNumber(nameof(MagicResistance.PurityNatural), value.PurityNatural);
|
||||
writer.WriteNumber(nameof(MagicResistance.PurityContemporary), value.PurityContemporary);
|
||||
writer.WriteNumber(nameof(MagicResistance.Bright), value.Bright);
|
||||
writer.WriteNumber(nameof(MagicResistance.Shadow), value.Shadow);
|
||||
writer.WriteNumber(nameof(MagicResistance.Element), value.Element);
|
||||
writer.WriteNumber(nameof(MagicResistance.Fleabane), value.Fleabane);
|
||||
writer.WriteNumber(nameof(MagicResistance.Particle), value.Particle);
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
|
||||
42
Library/Common/JsonConverter/SkillConverter.cs
Normal file
42
Library/Common/JsonConverter/SkillConverter.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Text.Json;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
{
|
||||
public class SkillConverter : BaseEntityConverter<Skill>
|
||||
{
|
||||
public override Skill NewInstance()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref Skill result)
|
||||
{
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(Skill.Id):
|
||||
result.Id = reader.GetInt64();
|
||||
break;
|
||||
case nameof(Skill.Name):
|
||||
result.Name = reader.GetString() ?? "";
|
||||
break;
|
||||
case nameof(Skill.SkillType):
|
||||
result.SkillType = (SkillType)reader.GetInt32();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Skill value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WriteNumber(nameof(Skill.Id), (int)value.Id);
|
||||
writer.WriteString(nameof(Skill.Name), value.Name);
|
||||
writer.WriteNumber(nameof(Skill.SkillType), (int)value.SkillType);
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -200,7 +200,12 @@ namespace Milimoe.FunGame.Core.Library.Constant
|
||||
/// <summary>
|
||||
/// 被动,编号 4xxx
|
||||
/// </summary>
|
||||
Passive
|
||||
Passive,
|
||||
|
||||
/// <summary>
|
||||
/// 物品的主动技能,编号 5xxx
|
||||
/// </summary>
|
||||
Item
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -406,8 +411,71 @@ namespace Milimoe.FunGame.Core.Library.Constant
|
||||
|
||||
public enum ItemType
|
||||
{
|
||||
Active,
|
||||
Passive
|
||||
/// <summary>
|
||||
/// 魔法卡包 编号 10xxx
|
||||
/// </summary>
|
||||
MagicCardPack,
|
||||
|
||||
/// <summary>
|
||||
/// 武器 编号 11xxx
|
||||
/// </summary>
|
||||
Weapon,
|
||||
|
||||
/// <summary>
|
||||
/// 防具 编号 12xxx
|
||||
/// </summary>
|
||||
Armor,
|
||||
|
||||
/// <summary>
|
||||
/// 鞋子 编号 13xxx
|
||||
/// </summary>
|
||||
Shoes,
|
||||
|
||||
/// <summary>
|
||||
/// 饰品 编号 14xxx
|
||||
/// </summary>
|
||||
Accessory,
|
||||
|
||||
/// <summary>
|
||||
/// 消耗品 编号 15xxx
|
||||
/// </summary>
|
||||
Consumable,
|
||||
|
||||
/// <summary>
|
||||
/// 收藏品 编号 16xxx
|
||||
/// </summary>
|
||||
Collectible,
|
||||
|
||||
/// <summary>
|
||||
/// 特殊物品 编号 17xxx
|
||||
/// </summary>
|
||||
SpecialItem,
|
||||
|
||||
/// <summary>
|
||||
/// 任务物品 编号 18xxx
|
||||
/// </summary>
|
||||
QuestItem,
|
||||
|
||||
/// <summary>
|
||||
/// 礼包 编号 19xxx
|
||||
/// </summary>
|
||||
GiftBox,
|
||||
|
||||
/// <summary>
|
||||
/// 其他 编号 20xxx
|
||||
/// </summary>
|
||||
Others
|
||||
}
|
||||
|
||||
public enum EquipSlotType
|
||||
{
|
||||
None,
|
||||
MagicCardPack,
|
||||
Weapon,
|
||||
Armor,
|
||||
Shoes,
|
||||
Accessory1,
|
||||
Accessory2
|
||||
}
|
||||
|
||||
public enum EntityType
|
||||
|
||||
@ -19,7 +19,7 @@ namespace Milimoe.FunGame.Core.Service
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||
Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter(), new UserConverter(), new RoomConverter(),
|
||||
new CharacterConverter(), new MagicResistanceConverter(), new MDFConverter() }
|
||||
new CharacterConverter(), new MagicResistanceConverter(), new EquipSlotConverter(), new SkillConverter(), new EffectConverter(), new ItemConverter() }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user