mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 08:09:02 +00:00
设计 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.Entity;
|
||||||
using Milimoe.FunGame.Core.Interface.Base;
|
using Milimoe.FunGame.Core.Interface.Base;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Api.Factory
|
namespace Milimoe.FunGame.Core.Api.Factory
|
||||||
{
|
{
|
||||||
internal class ItemFactory : IFactory<Item>
|
internal class ItemFactory : IFactory<Item>
|
||||||
{
|
{
|
||||||
public Type EntityType => _EntityType;
|
public Type EntityType => typeof(Item);
|
||||||
|
|
||||||
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 Item Create()
|
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.Entity;
|
||||||
|
using Milimoe.FunGame.Core.Interface.Entity;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Api.Utility
|
namespace Milimoe.FunGame.Core.Api.Utility
|
||||||
@ -13,6 +14,27 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<string> WriteLine { get; }
|
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>
|
||||||
/// 当前的行动顺序
|
/// 当前的行动顺序
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -52,12 +74,17 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
/// 角色被插队次数
|
/// 角色被插队次数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly Dictionary<Character, int> _cutCount = [];
|
protected readonly Dictionary<Character, int> _cutCount = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 助攻伤害
|
/// 助攻伤害
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly Dictionary<Character, AssistDetail> _assistDamage = [];
|
protected readonly Dictionary<Character, AssistDetail> _assistDamage = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 角色数据
|
||||||
|
/// </summary>
|
||||||
|
protected readonly Dictionary<Character, CharacterStatistics> _stats = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 游戏是否结束
|
/// 游戏是否结束
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -91,6 +118,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
Character character = group.First();
|
Character character = group.First();
|
||||||
AddCharacter(character, Calculation.Round2Digits(_queue.Count * 0.1), false);
|
AddCharacter(character, Calculation.Round2Digits(_queue.Count * 0.1), false);
|
||||||
_assistDamage.Add(character, new AssistDetail(character, characters.Where(c => c != character)));
|
_assistDamage.Add(character, new AssistDetail(character, characters.Where(c => c != character)));
|
||||||
|
_stats.Add(character, new());
|
||||||
// 初始化技能
|
// 初始化技能
|
||||||
foreach (Skill skill in character.Skills)
|
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);
|
AddCharacter(selectedCharacter, Calculation.Round2Digits(_queue.Count * 0.1), false);
|
||||||
_assistDamage.Add(selectedCharacter, new AssistDetail(selectedCharacter, characters.Where(c => c != selectedCharacter)));
|
_assistDamage.Add(selectedCharacter, new AssistDetail(selectedCharacter, characters.Where(c => c != selectedCharacter)));
|
||||||
|
_stats.Add(selectedCharacter, new());
|
||||||
// 初始化技能
|
// 初始化技能
|
||||||
foreach (Skill skill in selectedCharacter.Skills)
|
foreach (Skill skill in selectedCharacter.Skills)
|
||||||
{
|
{
|
||||||
@ -284,6 +313,8 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
/// <returns>是否结束游戏</returns>
|
/// <returns>是否结束游戏</returns>
|
||||||
public bool ProcessTurn(Character character)
|
public bool ProcessTurn(Character character)
|
||||||
{
|
{
|
||||||
|
TotalRound++;
|
||||||
|
|
||||||
if (!BeforeTurn(character))
|
if (!BeforeTurn(character))
|
||||||
{
|
{
|
||||||
return _isGameEnd;
|
return _isGameEnd;
|
||||||
@ -307,107 +338,124 @@ 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 &&
|
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)))];
|
(((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;
|
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())
|
||||||
{
|
{
|
||||||
// 行动受限,只能使用特殊物品
|
actionTypeTemp = e.AlterActionTypeBeforeAction(character, character.CharacterState, ref canUseItem, ref canCastSkill, ref pUseItem, ref pCastSkill, ref pNormalAttack);
|
||||||
if (character.Items.Count > 0)
|
|
||||||
{
|
|
||||||
type = CharacterActionType.UseItem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (character.CharacterState == CharacterState.BattleRestricted)
|
if (actionTypeTemp != CharacterActionType.None && actionTypeTemp != CharacterActionType.CastSkill && actionTypeTemp != CharacterActionType.CastSuperSkill)
|
||||||
{
|
{
|
||||||
// 战斗不能,只能使用物品
|
type = actionTypeTemp;
|
||||||
if (character.Items.Count > 0)
|
|
||||||
{
|
|
||||||
type = CharacterActionType.UseItem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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.CharacterState == CharacterState.Actionable)
|
||||||
if (character.Items.Count > 0)
|
|
||||||
{
|
{
|
||||||
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
|
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
|
else
|
||||||
{
|
{
|
||||||
// 可以任意行动
|
WriteLine("[ " + character + $" ] 完全行动不能!");
|
||||||
bool canUseItem = character.Items.Count > 0;
|
type = CharacterActionType.None;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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> enemysTemp = new(enemys);
|
||||||
List<Character> teammatesTemp = new(teammates);
|
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.CurrentCD = Calculation.Round2Digits(Math.Max(1, skill.CD * (1 - character.CDR)));
|
||||||
skill.Enable = false;
|
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);
|
skill.OnSkillCasted(this, character, enemys, teammates);
|
||||||
|
|
||||||
foreach (Effect effect in character.Effects.Where(e => e.Level > 0).ToList())
|
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.CurrentCD = Calculation.Round2Digits(Math.Max(1, skill.CD * (1 - character.CDR)));
|
||||||
skill.Enable = false;
|
skill.Enable = false;
|
||||||
|
|
||||||
WriteLine("[ " + character + $" ] 消耗了 {cost:f2} 点魔法值,释放了技能 {skill.Name}!");
|
WriteLine("[ " + character + $" ] 消耗了 {cost:0.##} 点魔法值,释放了技能 {skill.Name}!");
|
||||||
skill.OnSkillCasted(this, character, enemys, teammates);
|
skill.OnSkillCasted(this, character, enemys, teammates);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -518,7 +566,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
skill.CurrentCD = Calculation.Round2Digits(Math.Max(1, skill.CD * (1 - character.CDR)));
|
skill.CurrentCD = Calculation.Round2Digits(Math.Max(1, skill.CD * (1 - character.CDR)));
|
||||||
skill.Enable = false;
|
skill.Enable = false;
|
||||||
|
|
||||||
WriteLine("[ " + character + $" ] 消耗了 {cost:f2} 点能量值,释放了爆发技 {skill.Name}!");
|
WriteLine("[ " + character + $" ] 消耗了 {cost:0.##} 点能量值,释放了爆发技 {skill.Name}!");
|
||||||
skill.OnSkillCasted(this, character, enemys, teammates);
|
skill.OnSkillCasted(this, character, enemys, teammates);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -613,14 +661,22 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
|
|
||||||
// 获取第一个角色的硬直时间
|
// 获取第一个角色的硬直时间
|
||||||
double timeToReduce = _hardnessTimes[_queue[0]];
|
double timeToReduce = _hardnessTimes[_queue[0]];
|
||||||
|
TotalTime = Calculation.Round2Digits(TotalTime + timeToReduce);
|
||||||
|
|
||||||
WriteLine("时间流逝:" + timeToReduce);
|
WriteLine("时间流逝:" + timeToReduce);
|
||||||
|
|
||||||
// 减少所有角色的硬直时间
|
|
||||||
foreach (Character character in _queue)
|
foreach (Character character in _queue)
|
||||||
{
|
{
|
||||||
|
// 减少所有角色的硬直时间
|
||||||
_hardnessTimes[character] = Calculation.Round2Digits(_hardnessTimes[character] - timeToReduce);
|
_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 recoveryHP = Calculation.Round2Digits(character.HR * timeToReduce);
|
||||||
double recoveryMP = Calculation.Round2Digits(character.MR * timeToReduce);
|
double recoveryMP = Calculation.Round2Digits(character.MR * timeToReduce);
|
||||||
@ -727,6 +783,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
else WriteLine("[ " + enemy + $" ] 受到了 {damage} 点物理伤害!");
|
else WriteLine("[ " + enemy + $" ] 受到了 {damage} 点物理伤害!");
|
||||||
enemy.HP = Calculation.Round2Digits(enemy.HP - damage);
|
enemy.HP = Calculation.Round2Digits(enemy.HP - damage);
|
||||||
|
|
||||||
|
// 统计伤害
|
||||||
|
CalculateCharacterDamageStatistics(actor, damage, isMagicDamage);
|
||||||
|
|
||||||
// 计算助攻
|
// 计算助攻
|
||||||
_assistDamage[actor][enemy] += damage;
|
_assistDamage[actor][enemy] += damage;
|
||||||
|
|
||||||
@ -789,7 +848,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
{
|
{
|
||||||
bool isMagic = false;
|
bool isMagic = false;
|
||||||
MagicType magicType = MagicType.None;
|
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);
|
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.Starmark => enemy.MDF.Starmark,
|
||||||
MagicType.PurityNatural => enemy.MDF.PurityNatural,
|
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));
|
finalDamage = Calculation.Round2Digits(expectedDamage * (1 - MDF));
|
||||||
@ -1008,7 +1067,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
{
|
{
|
||||||
WriteLine("[ " + killer + " ] 已经" + continuousKilling + "!拜托谁去杀了他吧!!!");
|
WriteLine("[ " + killer + " ] 已经" + continuousKilling + "!拜托谁去杀了他吧!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_earnedMoney.TryAdd(killer, money)) _earnedMoney[killer] += money;
|
if (!_earnedMoney.TryAdd(killer, money)) _earnedMoney[killer] += money;
|
||||||
|
|
||||||
_eliminated.Add(death);
|
_eliminated.Add(death);
|
||||||
@ -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 CharacterFactory CharacterFactory = new();
|
||||||
private readonly static InventoryFactory InventoryFactory = 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 ItemFactory ItemFactory = new();
|
||||||
private readonly static RoomFactory RoomFactory = new();
|
private readonly static RoomFactory RoomFactory = new();
|
||||||
private readonly static UserFactory UserFactory = new();
|
private readonly static UserFactory UserFactory = new();
|
||||||
@ -32,14 +34,31 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
return InventoryFactory.Create();
|
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>
|
||||||
/// 获取物品实例
|
/// 获取物品实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">Item类型 主动 或 被动</param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Item GetItem(ItemType type = ItemType.Passive)
|
public static Item GetItem()
|
||||||
{
|
{
|
||||||
return ItemFactory.Create(type);
|
return ItemFactory.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -245,6 +245,42 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
/// <param name="options"></param>
|
/// <param name="options"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T? JsonDeserializeFromHashtable<T>(Hashtable hashtable, string key, JsonSerializerOptions options) => Service.JsonManager.GetObject<T>(hashtable, key, options);
|
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
|
#endregion
|
||||||
|
|||||||
@ -37,6 +37,11 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public CharacterProfile Profile { get; set; }
|
public CharacterProfile Profile { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 角色的详细资料
|
||||||
|
/// </summary>
|
||||||
|
public EquipSlot EquipSlot { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 魔法属性
|
/// 魔法属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -140,7 +145,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
/// 角色目前被特效施加的状态 [ 用于设置角色是否被控制的状态 ]
|
/// 角色目前被特效施加的状态 [ 用于设置角色是否被控制的状态 ]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<Effect, List<CharacterState>> CharacterEffectStates { get; } = [];
|
public Dictionary<Effect, List<CharacterState>> CharacterEffectStates { get; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 角色目前被特效施加的控制效果 [ 用于特效判断是否需要在移除特效时更改角色状态 ]
|
/// 角色目前被特效施加的控制效果 [ 用于特效判断是否需要在移除特效时更改角色状态 ]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -366,7 +371,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 魔法抗性(%) [ 与技能和物品相关 ]
|
/// 魔法抗性(%) [ 与技能和物品相关 ]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MDF MDF { get; set; }
|
public MagicResistance MDF { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 物理穿透(%) [ 与技能和物品相关 ]
|
/// 物理穿透(%) [ 与技能和物品相关 ]
|
||||||
@ -723,12 +728,12 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
/// 生命值
|
/// 生命值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private double _HP = 0;
|
private double _HP = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 魔法值
|
/// 魔法值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private double _MP = 0;
|
private double _MP = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 能量值
|
/// 能量值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -748,6 +753,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
{
|
{
|
||||||
User = General.UnknownUserInstance;
|
User = General.UnknownUserInstance;
|
||||||
Profile = new(Name, FirstName, NickName);
|
Profile = new(Name, FirstName, NickName);
|
||||||
|
EquipSlot = new();
|
||||||
MDF = new();
|
MDF = new();
|
||||||
NormalAttack = new(this);
|
NormalAttack = new(this);
|
||||||
}
|
}
|
||||||
@ -767,7 +773,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
MP = MaxMP;
|
MP = MaxMP;
|
||||||
if (EP != -1) this.EP = EP;
|
if (EP != -1) this.EP = EP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 按时间回复状态
|
/// 按时间回复状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -810,13 +816,13 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 比较一个角色(只比较 <see cref="Name"/>)
|
/// 比较一个角色(只比较 <see cref="ToString"/>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="other"></param>
|
/// <param name="other"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override bool Equals(IBaseEntity? other)
|
public override bool Equals(IBaseEntity? other)
|
||||||
{
|
{
|
||||||
return other is Character c && c.Name == Name;
|
return other is Character c && c.ToString() == ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -891,8 +897,8 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
builder.AppendLine($"能量值:{EP} / 200");
|
builder.AppendLine($"能量值:{EP} / 200");
|
||||||
builder.AppendLine($"攻击力:{ATK}" + (ExATK + ExATK2 > 0 ? $" [{BaseATK} + {ExATK + ExATK2}]" : ""));
|
builder.AppendLine($"攻击力:{ATK}" + (ExATK + ExATK2 > 0 ? $" [{BaseATK} + {ExATK + ExATK2}]" : ""));
|
||||||
builder.AppendLine($"物理护甲:{DEF}" + (ExDEF + ExDEF2 > 0 ? $" [{BaseDEF} + {ExDEF + ExDEF2}]" : "") + $" ({PDR * 100:f2}%)");
|
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 +
|
double mdf = Calculation.Round4Digits((MDF.None + MDF.Starmark + MDF.PurityNatural + MDF.PurityContemporary +
|
||||||
MDF.Bright.Value + MDF.Shadow.Value + MDF.Element.Value + MDF.Fleabane.Value + MDF.Particle.Value) / 9);
|
MDF.Bright + MDF.Shadow + MDF.Element + MDF.Fleabane + MDF.Particle) / 9);
|
||||||
builder.AppendLine($"魔法抗性:{mdf * 100:f2}%(平均)");
|
builder.AppendLine($"魔法抗性:{mdf * 100:f2}%(平均)");
|
||||||
double exSPD = Calculation.Round2Digits(AGI * 0.65 + ExSPD);
|
double exSPD = Calculation.Round2Digits(AGI * 0.65 + ExSPD);
|
||||||
builder.AppendLine($"行动速度:{SPD}" + (exSPD > 0 ? $" [{InitialSPD} + {exSPD}]" : "") + $" ({ActionCoefficient * 100:f2}%)");
|
builder.AppendLine($"行动速度:{SPD}" + (exSPD > 0 ? $" [{InitialSPD} + {exSPD}]" : "") + $" ({ActionCoefficient * 100:f2}%)");
|
||||||
@ -945,7 +951,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
builder.Append(item.ToString());
|
builder.Append(item.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Effects.Count > 0)
|
if (Effects.Count > 0)
|
||||||
{
|
{
|
||||||
builder.AppendLine("== 状态栏 ==");
|
builder.AppendLine("== 状态栏 ==");
|
||||||
|
|||||||
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Entity
|
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)
|
public class CharacterProfile(string name, string firstname, string nickname)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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 double None { get; set; } = 0;
|
||||||
public MagicResistance Starmark { get; } = new(MagicType.Starmark);
|
public double Starmark { get; set; } = 0;
|
||||||
public MagicResistance PurityNatural { get; } = new(MagicType.PurityNatural);
|
public double PurityNatural { get; set; } = 0;
|
||||||
public MagicResistance PurityContemporary { get; } = new(MagicType.PurityContemporary);
|
public double PurityContemporary { get; set; } = 0;
|
||||||
public MagicResistance Bright { get; } = new(MagicType.Bright);
|
public double Bright { get; set; } = 0;
|
||||||
public MagicResistance Shadow { get; } = new(MagicType.Shadow);
|
public double Shadow { get; set; } = 0;
|
||||||
public MagicResistance Element { get; } = new(MagicType.Element);
|
public double Element { get; set; } = 0;
|
||||||
public MagicResistance Fleabane { get; } = new(MagicType.Fleabane);
|
public double Fleabane { get; set; } = 0;
|
||||||
public MagicResistance Particle { get; } = new(MagicType.Particle);
|
public double Particle { get; set; } = 0;
|
||||||
}
|
|
||||||
|
|
||||||
public class MagicResistance(MagicType type = MagicType.None, double value = 0)
|
|
||||||
{
|
|
||||||
public MagicType MagicType { get; } = type;
|
|
||||||
public double Value { get; set; } = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
namespace Milimoe.FunGame.Core.Entity
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 和 <see cref="Skill"/> 一样,需要继承构造
|
||||||
|
/// </summary>
|
||||||
public class Item : BaseEntity, IItem
|
public class Item : BaseEntity, IItem
|
||||||
{
|
{
|
||||||
public string Describe { get; set; } = "";
|
/// <summary>
|
||||||
public double Price { get; set; }
|
/// 物品的描述
|
||||||
public char Key { get; set; }
|
/// </summary>
|
||||||
public bool IsActive { get; set; }
|
public string Description { get; } = "";
|
||||||
public bool Enable { get; set; }
|
|
||||||
public Character? Character { get; set; } = null;
|
|
||||||
public Skill? Skill { get; set; } = null;
|
|
||||||
|
|
||||||
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)
|
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>
|
||||||
/// 特殊效果类,需要继承
|
/// 特殊效果类,需要继承
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class Effect(Skill skill) : BaseEntity
|
public class Effect : BaseEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属的技能
|
/// 所属的技能
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Skill Skill { get; } = skill;
|
public Skill Skill { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 特殊效果类型<para/>
|
/// 特殊效果类型<para/>
|
||||||
@ -101,6 +101,16 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Effect(Skill skill)
|
||||||
|
{
|
||||||
|
Skill = skill;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Effect()
|
||||||
|
{
|
||||||
|
Skill = Factory.GetSkill();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得此特效时
|
/// 获得此特效时
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -131,7 +141,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在伤害计算前修改预期伤害
|
/// 在伤害计算前修改预期伤害
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -359,6 +369,22 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
return false;
|
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>
|
/// <summary>
|
||||||
/// 对敌人造成技能伤害 [ 强烈建议使用此方法造成伤害而不是自行调用 <see cref="ActionQueue.DamageToEnemy"/> ]
|
/// 对敌人造成技能伤害 [ 强烈建议使用此方法造成伤害而不是自行调用 <see cref="ActionQueue.DamageToEnemy"/> ]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -415,7 +441,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override bool Equals(IBaseEntity? other)
|
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>
|
/// </summary>
|
||||||
public virtual string Description { get; set; } = "";
|
public virtual string Description { get; set; } = "";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 快捷键
|
|
||||||
/// </summary>
|
|
||||||
public char Key { get; set; } = '/';
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 技能等级,等于 0 时可以称之为尚未学习
|
/// 技能等级,等于 0 时可以称之为尚未学习
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -43,11 +38,11 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 技能 [ 此项为最高优先级 ]
|
/// 技能类型 [ 此项为最高优先级 ]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[InitRequired]
|
[InitRequired]
|
||||||
public SkillType SkillType { get; set; }
|
public SkillType SkillType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否是主动技能 [ 此项为高优先级 ]
|
/// 是否是主动技能 [ 此项为高优先级 ]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -138,12 +133,22 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ActionQueue? ActionQueue { get; set; } = null;
|
public ActionQueue? ActionQueue { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 继承此类实现时,调用基类的构造函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="character"></param>
|
||||||
protected Skill(SkillType type, Character? character = null)
|
protected Skill(SkillType type, Character? character = null)
|
||||||
{
|
{
|
||||||
SkillType = type;
|
SkillType = type;
|
||||||
Character = character;
|
Character = character;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用于构造 JSON
|
||||||
|
/// </summary>
|
||||||
|
internal Skill() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 触发技能升级
|
/// 触发技能升级
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -185,7 +190,7 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
e.OnSkillCasting(caster);
|
e.OnSkillCasting(caster);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 触发技能效果
|
/// 触发技能效果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -257,9 +262,14 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断两个技能是否相同 检查Id.Name
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public override bool Equals(IBaseEntity? other)
|
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>
|
/// <summary>
|
||||||
|
|||||||
@ -1,24 +1,32 @@
|
|||||||
using System.Collections;
|
namespace Milimoe.FunGame.Core.Entity
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Entity
|
|
||||||
{
|
{
|
||||||
public class CharacterStatistics
|
public class CharacterStatistics
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public double TotalDamage { get; set; } = 0;
|
||||||
public Character? Character { get; set; } = null;
|
public double TotalPhysicalDamage { get; set; } = 0;
|
||||||
public Hashtable? DamageStats { get; set; } = new Hashtable();
|
public double TotalMagicDamage { get; set; } = 0;
|
||||||
public Hashtable? PhysicalDamageStats { get; set; } = new Hashtable();
|
public double TotalRealDamage { get; set; } = 0;
|
||||||
public Hashtable? MagicDamageStats { get; set; } = new Hashtable();
|
public double AvgDamage { get; set; } = 0;
|
||||||
public Hashtable? RealDamageStats { get; set; } = new Hashtable();
|
public double AvgPhysicalDamage { get; set; } = 0;
|
||||||
public Hashtable? AvgDamageStats { get; set; } = new Hashtable();
|
public double AvgMagicDamage { get; set; } = 0;
|
||||||
public Hashtable? AvgLiveRoundStats { get; set; } = new Hashtable();
|
public double AvgRealDamage { get; set; } = 0;
|
||||||
public Hashtable? AvgDamageRoundStats { get; set; } = new Hashtable();
|
public int LiveRound { get; set; } = 0;
|
||||||
public Hashtable? KillStats { get; set; } = new Hashtable();
|
public int AvgLiveRound { get; set; } = 0;
|
||||||
public Hashtable? DeathStats { get; set; } = new Hashtable();
|
public int ActionTurn { get; set; } = 0;
|
||||||
public Hashtable? AssistStats { get; set; } = new Hashtable();
|
public int AvgActionTurn { get; set; } = 0;
|
||||||
public Hashtable? Plays { get; set; } = new Hashtable();
|
public double LiveTime { get; set; } = 0;
|
||||||
public Hashtable? Wins { get; set; } = new Hashtable();
|
public double AvgLiveTime { get; set; } = 0;
|
||||||
public Hashtable? Loses { get; set; } = new Hashtable();
|
public double DamagePerRound { get; set; } = 0;
|
||||||
public Hashtable? Winrates { get; set; } = new Hashtable();
|
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 interface IItem : IActiveEnable, IRelateCharacter
|
||||||
{
|
{
|
||||||
public string Describe { get; set; }
|
public string Description { get; }
|
||||||
public double Price { get; set; }
|
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):
|
case nameof(Character.NickName):
|
||||||
result.NickName = reader.GetString() ?? "";
|
result.NickName = reader.GetString() ?? "";
|
||||||
break;
|
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):
|
case nameof(Character.MagicType):
|
||||||
result.MagicType = (MagicType)reader.GetInt32();
|
result.MagicType = (MagicType)reader.GetInt32();
|
||||||
break;
|
break;
|
||||||
@ -84,7 +90,7 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|||||||
result.ExDEF2 = reader.GetDouble();
|
result.ExDEF2 = reader.GetDouble();
|
||||||
break;
|
break;
|
||||||
case nameof(Character.MDF):
|
case nameof(Character.MDF):
|
||||||
result.MDF = NetworkUtility.JsonDeserialize<MDF>(ref reader, options) ?? new();
|
result.MDF = NetworkUtility.JsonDeserialize<MagicResistance>(ref reader, options) ?? new();
|
||||||
break;
|
break;
|
||||||
case nameof(Character.PhysicalPenetration):
|
case nameof(Character.PhysicalPenetration):
|
||||||
result.PhysicalPenetration = reader.GetDouble();
|
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.Name), value.Name);
|
||||||
writer.WriteString(nameof(Character.FirstName), value.FirstName);
|
writer.WriteString(nameof(Character.FirstName), value.FirstName);
|
||||||
writer.WriteString(nameof(Character.NickName), value.NickName);
|
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.MagicType), (int)value.MagicType);
|
||||||
writer.WriteNumber(nameof(Character.FirstRoleType), (int)value.FirstRoleType);
|
writer.WriteNumber(nameof(Character.FirstRoleType), (int)value.FirstRoleType);
|
||||||
writer.WriteNumber(nameof(Character.SecondRoleType), (int)value.SecondRoleType);
|
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 System.Text.Json;
|
||||||
using Milimoe.FunGame.Core.Api.Utility;
|
|
||||||
using Milimoe.FunGame.Core.Entity;
|
using Milimoe.FunGame.Core.Entity;
|
||||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
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 class MagicResistanceConverter : BaseEntityConverter<MagicResistance>
|
||||||
{
|
{
|
||||||
public override MagicResistance NewInstance()
|
public override MagicResistance NewInstance()
|
||||||
@ -130,11 +15,32 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|||||||
{
|
{
|
||||||
switch (propertyName)
|
switch (propertyName)
|
||||||
{
|
{
|
||||||
case nameof(MagicResistance.MagicType):
|
case nameof(MagicResistance.None):
|
||||||
result = new((MagicType)reader.GetInt32(), result.Value);
|
result.None = reader.GetDouble();
|
||||||
break;
|
break;
|
||||||
case nameof(MagicResistance.Value):
|
case nameof(MagicResistance.Starmark):
|
||||||
result.Value = reader.GetDouble();
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,8 +48,17 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|||||||
public override void Write(Utf8JsonWriter writer, MagicResistance value, JsonSerializerOptions options)
|
public override void Write(Utf8JsonWriter writer, MagicResistance value, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
writer.WriteStartObject();
|
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();
|
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>
|
/// <summary>
|
||||||
/// 被动,编号 4xxx
|
/// 被动,编号 4xxx
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Passive
|
Passive,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 物品的主动技能,编号 5xxx
|
||||||
|
/// </summary>
|
||||||
|
Item
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -217,7 +222,7 @@ namespace Milimoe.FunGame.Core.Library.Constant
|
|||||||
/// 标记,目标受到某些技能的标记
|
/// 标记,目标受到某些技能的标记
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Mark,
|
Mark,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 眩晕,目标无法行动
|
/// 眩晕,目标无法行动
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -406,8 +411,71 @@ namespace Milimoe.FunGame.Core.Library.Constant
|
|||||||
|
|
||||||
public enum ItemType
|
public enum ItemType
|
||||||
{
|
{
|
||||||
Active,
|
/// <summary>
|
||||||
Passive
|
/// 魔法卡包 编号 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
|
public enum EntityType
|
||||||
|
|||||||
@ -19,7 +19,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||||
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||||
Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter(), new UserConverter(), new RoomConverter(),
|
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>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user