From 62240398ee835080cabf8d9facc486c64d4560f3 Mon Sep 17 00:00:00 2001 From: milimoe Date: Fri, 20 Sep 2024 20:34:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A3=85=E5=A4=87/=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E8=A3=85=E5=A4=87=E7=89=A9=E5=93=81=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Utility/ActionQueue.cs | 41 ++++-- Entity/Character/Character.cs | 96 ++++++++++--- Entity/Character/EquipSlot.cs | 46 ++++++- Entity/Item/Item.cs | 126 ++++++++++++++++-- .../Common/Addon/Example/ExampleGameModule.cs | 4 +- Library/Common/Addon/ItemModule.cs | 4 +- Library/Common/Addon/SkillModule.cs | 4 +- Library/Common/JsonConverter/ItemConverter.cs | 49 ++++++- Library/Constant/ConstantSet.cs | 2 +- 9 files changed, 323 insertions(+), 49 deletions(-) diff --git a/Api/Utility/ActionQueue.cs b/Api/Utility/ActionQueue.cs index cc919f7..f58a174 100644 --- a/Api/Utility/ActionQueue.cs +++ b/Api/Utility/ActionQueue.cs @@ -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 @@ -482,7 +483,7 @@ namespace Milimoe.FunGame.Core.Api.Utility // 获取随机敌人 if (enemys.Count > 0) { - Character enemy = enemys[new Random().Next(enemys.Count)]; + Character enemy = enemys[Random.Shared.Next(enemys.Count)]; character.NormalAttack.Attack(this, character, enemy); baseTime = character.NormalAttack.HardnessTime; foreach (Effect effect in character.Effects.Where(e => e.Level > 0).ToList()) @@ -496,7 +497,7 @@ namespace Milimoe.FunGame.Core.Api.Utility // 预使用技能,即开始吟唱逻辑 // 注意:FastAuto 模式下,此吟唱逻辑删减了选取目标的逻辑,将选取逻辑放在了实际释放的环节 // 在正常交互式模式下,吟唱前需要先选取目标 - Skill skill = skills[new Random().Next(skills.Count)]; + Skill skill = skills[Random.Shared.Next(skills.Count)]; if (skill.SkillType == SkillType.Magic) { character.CharacterState = CharacterState.Casting; @@ -836,7 +837,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// 最大获取量 public static double GetEP(double a, double b, double max) { - return Calculation.Round2Digits(Math.Min((a + new Random().Next(30)) * b, max)); + return Calculation.Round2Digits(Math.Min((a + Random.Shared.Next(30)) * b, max)); } /// @@ -866,7 +867,7 @@ namespace Milimoe.FunGame.Core.Api.Utility effect.AlterExpectedDamageBeforeCalculation(actor, enemy, ref expectedDamage, isNormalAttack, false, MagicType.None); } - double dice = new Random().NextDouble(); + double dice = Random.Shared.NextDouble(); if (isNormalAttack) { // 闪避判定 @@ -900,7 +901,7 @@ namespace Milimoe.FunGame.Core.Api.Utility finalDamage = Calculation.Round2Digits(expectedDamage * (1 - physicalDamageReduction)); // 暴击判定 - dice = new Random().NextDouble(); + dice = Random.Shared.NextDouble(); if (dice < actor.CritRate) { finalDamage = Calculation.Round2Digits(finalDamage * actor.CritDMG); // 暴击伤害倍率加成 @@ -943,7 +944,7 @@ namespace Milimoe.FunGame.Core.Api.Utility effect.AlterExpectedDamageBeforeCalculation(actor, enemy, ref expectedDamage, isNormalAttack, true, magicType); } - double dice = new Random().NextDouble(); + double dice = Random.Shared.NextDouble(); if (isNormalAttack) { // 闪避判定 @@ -987,7 +988,7 @@ namespace Milimoe.FunGame.Core.Api.Utility finalDamage = Calculation.Round2Digits(expectedDamage * (1 - MDF)); // 暴击判定 - dice = new Random().NextDouble(); + dice = Random.Shared.NextDouble(); if (dice < actor.CritRate) { finalDamage = Calculation.Round2Digits(finalDamage * actor.CritDMG); // 暴击伤害倍率加成 @@ -1013,7 +1014,7 @@ namespace Milimoe.FunGame.Core.Api.Utility if (!_continuousKilling.TryAdd(killer, 1)) _continuousKilling[killer] += 1; _stats[killer].Kills += 1; _stats[death].Deaths += 1; - int money = new Random().Next(250, 350); + int money = Random.Shared.Next(250, 350); Character[] assists = _assistDamage.Keys.Where(c => c != death && _assistDamage[c].GetPercentage(death) > 0.10).ToArray(); double totalDamagePercentage = Calculation.Round4Digits(_assistDamage.Keys.Where(assists.Contains).Select(c => _assistDamage[c].GetPercentage(death)).Sum()); @@ -1037,7 +1038,7 @@ namespace Milimoe.FunGame.Core.Api.Utility // 终结击杀的奖励仍然是全额的 if (_continuousKilling.TryGetValue(death, out int coefficient) && coefficient > 1) { - money += (coefficient + 1) * new Random().Next(50, 100); + money += (coefficient + 1) * Random.Shared.Next(50, 100); string termination = CharacterSet.GetContinuousKilling(coefficient); string msg = $"[ {killer} ] 终结了 [ {death} ]{(termination != "" ? " 的" + termination : "")},获得 {money} 金钱!"; if (assists.Length > 1) @@ -1163,12 +1164,12 @@ namespace Milimoe.FunGame.Core.Api.Utility foreach (Character other in _queue.Where(c => c != character && c.CharacterState == CharacterState.Actionable && _queue.IndexOf(c) >= _queue.Count / 2).ToList()) { // 有 65% 欲望插队 - if (new Random().NextDouble() < 0.65) + if (Random.Shared.NextDouble() < 0.65) { List skills = other.Skills.Where(s => s.Level > 0 && s.SkillType == SkillType.SuperSkill && s.Enable && !s.IsInEffect && s.CurrentCD == 0 && other.EP >= s.RealEPCost).ToList(); if (skills.Count > 0) { - Skill skill = skills[new Random().Next(skills.Count)]; + Skill skill = skills[Random.Shared.Next(skills.Count)]; _castingSuperSkills.Add(other, skill); other.CharacterState = CharacterState.PreCastSuperSkill; _queue.Remove(other); @@ -1237,7 +1238,7 @@ namespace Milimoe.FunGame.Core.Api.Utility pNormalAttack /= total; } - double rand = new Random().NextDouble(); + double rand = Random.Shared.NextDouble(); // 按概率进行检查 if (rand < pUseItem) @@ -1289,13 +1290,27 @@ namespace Milimoe.FunGame.Core.Api.Utility } } + public void Equip(Character character, Item item) + { + if (character.Equip(item)) + { + EquipItemToSlot type = character.EquipSlot.GetEquipItemToSlot(item); + WriteLine($"[ {character} ] 装备了 [ {item.Name} ]。" + (type != EquipItemToSlot.None ? $"({ItemSet.GetEquipSlotTypeName(type)} 栏位)" : "")); + } + } + public void Equip(Character character, EquipItemToSlot type, Item item) { if (character.Equip(item, type)) { WriteLine($"[ {character} ] 装备了 [ {item.Name} ]。({ItemSet.GetEquipSlotTypeName(type)} 栏位)"); } - else + } + + public void UnEquip(Character character, EquipItemToSlot type) + { + Item? item = character.UnEquip(type); + if (item != null) { WriteLine($"[ {character} ] 取消装备了 [ {item.Name} ]。({ItemSet.GetEquipSlotTypeName(type)} 栏位)"); } diff --git a/Entity/Character/Character.cs b/Entity/Character/Character.cs index d4b9dbf..282e00a 100644 --- a/Entity/Character/Character.cs +++ b/Entity/Character/Character.cs @@ -170,12 +170,12 @@ namespace Milimoe.FunGame.Core.Entity /// /// 基础生命值 [ 与初始设定和等级相关 ] [ 与基础力量相关 ] /// - public double BaseHP => Calculation.Round2Digits(InitialHP + (Level - 1) * (17 + 0.68 * InitialHP) + BaseSTR * 17); + public double BaseHP => Calculation.Round2Digits(InitialHP + (Level - 1) * (17 + 0.68 * InitialHP) + BaseSTR * 9); /// /// 额外生命值 [ 与额外力量相关 ] /// - public double ExHP => Calculation.Round2Digits(ExSTR * 17); + public double ExHP => Calculation.Round2Digits(ExSTR * 9); /// /// 额外生命值2 [ 与技能和物品相关 ] @@ -805,7 +805,7 @@ namespace Milimoe.FunGame.Core.Entity } /// - /// 为角色穿戴装备(必须使用此方法而不是自己去给EquipSlot里的物品赋值) + /// 为角色装备物品(必须使用此方法而不是自己去给EquipSlot里的物品赋值) /// /// /// @@ -823,6 +823,7 @@ namespace Milimoe.FunGame.Core.Entity { UnEquip(EquipItemToSlot.MagicCardPack); EquipSlot.MagicCardPack = item; + item.OnItemEquip(this, EquipItemToSlot.MagicCardPack); result = true; } break; @@ -831,7 +832,7 @@ namespace Milimoe.FunGame.Core.Entity { UnEquip(EquipItemToSlot.Weapon); EquipSlot.Weapon = item; - item.OnItemEquip(this); + item.OnItemEquip(this, EquipItemToSlot.Weapon); result = true; } break; @@ -840,7 +841,7 @@ namespace Milimoe.FunGame.Core.Entity { UnEquip(EquipItemToSlot.Armor); EquipSlot.Armor = item; - item.OnItemEquip(this); + item.OnItemEquip(this, EquipItemToSlot.Armor); result = true; } break; @@ -849,7 +850,7 @@ namespace Milimoe.FunGame.Core.Entity { UnEquip(EquipItemToSlot.Shoes); EquipSlot.Shoes = item; - item.OnItemEquip(this); + item.OnItemEquip(this, EquipItemToSlot.Shoes); result = true; } break; @@ -858,7 +859,7 @@ namespace Milimoe.FunGame.Core.Entity { UnEquip(EquipItemToSlot.Accessory1); EquipSlot.Accessory1 = item; - item.OnItemEquip(this); + item.OnItemEquip(this, EquipItemToSlot.Accessory1); result = true; } break; @@ -867,7 +868,7 @@ namespace Milimoe.FunGame.Core.Entity { UnEquip(EquipItemToSlot.Accessory2); EquipSlot.Accessory2 = item; - item.OnItemEquip(this); + item.OnItemEquip(this, EquipItemToSlot.Accessory2); result = true; } break; @@ -880,29 +881,90 @@ namespace Milimoe.FunGame.Core.Entity return result; } - public void UnEquip(EquipItemToSlot type) + /// + /// 为角色装备物品(必须使用此方法而不是自己去给EquipSlot里的物品赋值) + /// 此方法为根据物品类型,优先空位自动装备 + /// + /// + public bool Equip(Item item) { + switch (item.ItemType) + { + case ItemType.MagicCardPack: + return Equip(item, EquipItemToSlot.MagicCardPack); + case ItemType.Weapon: + return Equip(item, EquipItemToSlot.Weapon); + case ItemType.Armor: + return Equip(item, EquipItemToSlot.Armor); + case ItemType.Shoes: + return Equip(item, EquipItemToSlot.Shoes); + case ItemType.Accessory: + if (EquipSlot.Accessory1 != null && EquipSlot.Accessory2 is null) + { + return Equip(item, EquipItemToSlot.Accessory2); + } + else + { + return Equip(item, EquipItemToSlot.Accessory1); + } + } + return false; + } + + /// + /// 取消装备,返回被取消的物品对象 + /// + /// + /// + public Item? UnEquip(EquipItemToSlot type) + { + Item? result = null; switch (type) { case EquipItemToSlot.MagicCardPack: - EquipSlot.MagicCardPack?.OnItemUnequip(); + if (EquipSlot.MagicCardPack != null) + { + result = EquipSlot.MagicCardPack; + EquipSlot.MagicCardPack.OnItemUnEquip(EquipItemToSlot.MagicCardPack); + } break; case EquipItemToSlot.Weapon: - EquipSlot.Weapon?.OnItemUnequip(); + if (EquipSlot.Weapon != null) + { + result = EquipSlot.Weapon; + EquipSlot.Weapon.OnItemUnEquip(EquipItemToSlot.Weapon); + } break; case EquipItemToSlot.Armor: - EquipSlot.Armor?.OnItemUnequip(); + if (EquipSlot.Armor != null) + { + result = EquipSlot.Armor; + EquipSlot.Armor.OnItemUnEquip(EquipItemToSlot.Armor); + } break; case EquipItemToSlot.Shoes: - EquipSlot.Shoes?.OnItemUnequip(); + if (EquipSlot.Shoes != null) + { + result = EquipSlot.Shoes; + EquipSlot.Shoes.OnItemUnEquip(EquipItemToSlot.Shoes); + } break; case EquipItemToSlot.Accessory1: - EquipSlot.Accessory1?.OnItemUnequip(); + if (EquipSlot.Accessory1 != null) + { + result = EquipSlot.Accessory1; + EquipSlot.Accessory1.OnItemUnEquip(EquipItemToSlot.Accessory1); + } break; case EquipItemToSlot.Accessory2: - EquipSlot.Accessory2?.OnItemUnequip(); + if (EquipSlot.Accessory2 != null) + { + result = EquipSlot.Accessory2; + EquipSlot.Accessory2.OnItemUnEquip(EquipItemToSlot.Accessory2); + } break; } + return result; } /// @@ -1046,7 +1108,7 @@ namespace Milimoe.FunGame.Core.Entity } } - if (Items.Count > 0) + if (EquipSlot.Any()) { builder.AppendLine("== 装备栏 =="); if (EquipSlot.MagicCardPack != null) @@ -1081,7 +1143,7 @@ namespace Milimoe.FunGame.Core.Entity } } - if (Effects.Count > 0) + if (Effects.Where(e => e.EffectType != EffectType.Item).Any()) { builder.AppendLine("== 状态栏 =="); foreach (Effect effect in Effects.Where(e => e.EffectType != EffectType.Item)) diff --git a/Entity/Character/EquipSlot.cs b/Entity/Character/EquipSlot.cs index 0e0256f..cd93eb8 100644 --- a/Entity/Character/EquipSlot.cs +++ b/Entity/Character/EquipSlot.cs @@ -1,4 +1,6 @@ -namespace Milimoe.FunGame.Core.Entity +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Core.Entity { /// /// 角色的装备槽位 @@ -29,5 +31,47 @@ /// 饰品2 /// public Item? Accessory2 { get; internal set; } = null; + + /// + /// 是否有任意装备 + /// + /// + public bool Any() + { + return MagicCardPack != null || Weapon != null || Armor != null || Shoes != null || Accessory1 != null || Accessory2 != null; + } + + /// + /// 获取物品所装备的栏位 + /// + /// + public EquipItemToSlot GetEquipItemToSlot(Item item) + { + if (MagicCardPack == item) + { + return EquipItemToSlot.MagicCardPack; + } + else if (Weapon == item) + { + return EquipItemToSlot.Weapon; + } + else if (Armor == item) + { + return EquipItemToSlot.Armor; + } + else if (Shoes == item) + { + return EquipItemToSlot.Shoes; + } + else if (Accessory1 == item) + { + return EquipItemToSlot.Accessory1; + } + else if (Accessory2 == item) + { + return EquipItemToSlot.Accessory2; + } + return EquipItemToSlot.None; + } } } diff --git a/Entity/Item/Item.cs b/Entity/Item/Item.cs index 83875dc..becb820 100644 --- a/Entity/Item/Item.cs +++ b/Entity/Item/Item.cs @@ -1,6 +1,7 @@ using System.Text; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Interface.Entity; +using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Entity @@ -19,6 +20,11 @@ namespace Milimoe.FunGame.Core.Entity /// 物品的通用描述 /// public virtual string GeneralDescription { get; } = ""; + + /// + /// 物品的背景故事 + /// + public virtual string BackgroundStory { get; } = ""; /// /// 物品类型 @@ -134,7 +140,7 @@ namespace Milimoe.FunGame.Core.Entity /// /// 当装备物品时 /// - public void OnItemEquip(Character character) + public void OnItemEquip(Character character, EquipItemToSlot type) { Character = character; Character.Items.Add(this); @@ -153,12 +159,13 @@ namespace Milimoe.FunGame.Core.Entity } } } + if (Character != null) OnItemEquipped(Character, this, type); } /// /// 当取消装备物品时 /// - public void OnItemUnequip() + public void OnItemUnEquip(EquipItemToSlot type) { if (Character != null) { @@ -178,7 +185,29 @@ namespace Milimoe.FunGame.Core.Entity e.OnEffectLost(Character); } } + switch (type) + { + case EquipItemToSlot.MagicCardPack: + Character.EquipSlot.MagicCardPack = null; + break; + case EquipItemToSlot.Weapon: + Character.EquipSlot.Weapon = null; + break; + case EquipItemToSlot.Armor: + Character.EquipSlot.Armor = null; + break; + case EquipItemToSlot.Shoes: + Character.EquipSlot.Shoes = null; + break; + case EquipItemToSlot.Accessory1: + Character.EquipSlot.Accessory1 = null; + break; + case EquipItemToSlot.Accessory2: + Character.EquipSlot.Accessory2 = null; + break; + } Character.Items.Remove(this); + OnItemUnEquipped(Character, this, type); } Character = null; } @@ -188,11 +217,8 @@ namespace Milimoe.FunGame.Core.Entity /// public void UseItem(ActionQueue queue, Character character, List enemys, List teammates) { - if (Skills.Active != null) - { - Skills.Active.OnSkillCasted(queue, character, enemys, teammates); - } - OnItemUsed(); + OnItemUsed(character, this); + Skills.Active?.OnSkillCasted(queue, character, enemys, teammates); } /// @@ -200,17 +226,51 @@ namespace Milimoe.FunGame.Core.Entity /// public void UseItem(/*Inventory inventory*/) { - - OnItemUsed(); + if (User != null) OnItemUsed(User, this); } /// - /// 当物品被使用时 + /// 当物品被角色使用时 /// - public virtual void OnItemUsed() + /// + /// + public virtual void OnItemUsed(Character character, Item item) { } + + /// + /// 当物品被玩家使用时 + /// + /// + /// + public virtual void OnItemUsed(User user, Item item) + { + + } + + /// + /// 当物品被装备时 + /// + /// + /// + /// + public virtual void OnItemEquipped(Character character, Item item, EquipItemToSlot type) + { + + } + + /// + /// 当物品被取消装备时 + /// + /// + /// + /// + public virtual void OnItemUnEquipped(Character character, Item item, EquipItemToSlot type) + { + + } + protected Item(ItemType type, bool isInGame = true, EquipSlotType slot = EquipSlotType.None) { @@ -235,6 +295,16 @@ namespace Milimoe.FunGame.Core.Entity /// /// public override string ToString() + { + return ToString(false); + } + + /// + /// 显示物品的详细信息 + /// + /// 是否显示通用描述,而不是描述 + /// + public string ToString(bool isShowGeneralDescription) { StringBuilder builder = new(); @@ -261,18 +331,32 @@ namespace Milimoe.FunGame.Core.Entity { builder.AppendLine($"此物品将在 {NextSellableTime.ToString(General.GeneralDateTimeFormatChinese)} 后可出售"); } - + if (!IsTradable && NextTradableTime != DateTime.MinValue) { builder.AppendLine($"此物品将在 {NextTradableTime.ToString(General.GeneralDateTimeFormatChinese)} 后可交易"); } + if (isShowGeneralDescription && GeneralDescription != "") + { + builder.AppendLine("物品描述:" + GeneralDescription); + } + else if (Description != "") + { + builder.AppendLine("物品描述:" + Description); + } + if (Skills.Active != null) builder.AppendLine($"{Skills.Active.ToString()}"); foreach (Skill skill in Skills.Passives) { builder.AppendLine($"{skill.ToString()}"); } + if (BackgroundStory != "") + { + builder.AppendLine("\r\n" + BackgroundStory); + } + return builder.ToString(); } @@ -286,6 +370,24 @@ namespace Milimoe.FunGame.Core.Entity return other is Item c && c.Id + "." + c.Name == Id + "." + Name; } + /// + /// 设置一些属性给从 新建来的 + /// 通常,在使用 JSON 反序列化 Item,且从 中获取了实例后,需要使用此方法复制给新实例 + /// + /// + public void SetPropertyToItemModuleNew(Item item) + { + item.WeaponType = WeaponType; + item.EquipSlotType = EquipSlotType; + item.Equipable = Equipable; + item.IsPurchasable = IsPurchasable; + item.Price = Price; + item.IsSellable = IsSellable; + item.NextSellableTime = NextSellableTime; + item.IsTradable = IsTradable; + item.NextTradableTime = NextTradableTime; + } + /// /// 所属的角色 /// diff --git a/Library/Common/Addon/Example/ExampleGameModule.cs b/Library/Common/Addon/Example/ExampleGameModule.cs index 3dee2f4..0ecc9ff 100644 --- a/Library/Common/Addon/Example/ExampleGameModule.cs +++ b/Library/Common/Addon/Example/ExampleGameModule.cs @@ -337,7 +337,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example } } - public override Skill? GetSkill(long id, string name) + public override Skill? GetSkill(long id, string name, SkillType type) { // 此方法将根据id和name,返回一个你继承实现了的类对象。 return Factory.GetSkill(); @@ -367,7 +367,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example } } - public override Item? GetItem(long id, string name) + public override Item? GetItem(long id, string name, ItemType type) { // 此方法将根据id和name,返回一个你继承实现了的类对象。 return Factory.GetItem(); diff --git a/Library/Common/Addon/ItemModule.cs b/Library/Common/Addon/ItemModule.cs index 0de6167..74c253b 100644 --- a/Library/Common/Addon/ItemModule.cs +++ b/Library/Common/Addon/ItemModule.cs @@ -1,5 +1,6 @@ using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Interface.Addons; +using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Library.Common.Addon { @@ -40,8 +41,9 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon /// /// /// + /// /// - public abstract Item? GetItem(long id, string name); + public abstract Item? GetItem(long id, string name, ItemType type); /// /// 加载模组 diff --git a/Library/Common/Addon/SkillModule.cs b/Library/Common/Addon/SkillModule.cs index 62f7da0..b48a4ad 100644 --- a/Library/Common/Addon/SkillModule.cs +++ b/Library/Common/Addon/SkillModule.cs @@ -1,5 +1,6 @@ using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Interface.Addons; +using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Library.Common.Addon { @@ -40,8 +41,9 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon /// /// /// + /// /// - public abstract Skill? GetSkill(long id, string name); + public abstract Skill? GetSkill(long id, string name, SkillType type); /// /// 加载模组 diff --git a/Library/Common/JsonConverter/ItemConverter.cs b/Library/Common/JsonConverter/ItemConverter.cs index 9f395cd..cc9c9fa 100644 --- a/Library/Common/JsonConverter/ItemConverter.cs +++ b/Library/Common/JsonConverter/ItemConverter.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using System; +using System.Text.Json; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Common.Architecture; using Milimoe.FunGame.Core.Library.Constant; @@ -25,6 +26,43 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter case nameof(Item.ItemType): result.ItemType = (ItemType)reader.GetInt32(); break; + case nameof(Item.WeaponType): + result.WeaponType = (WeaponType)reader.GetInt32(); + break; + case nameof(Item.EquipSlotType): + result.EquipSlotType = (EquipSlotType)reader.GetInt32(); + break; + case nameof(Item.Equipable): + result.Equipable = reader.GetBoolean(); + break; + case nameof(Item.IsPurchasable): + result.IsPurchasable = reader.GetBoolean(); + break; + case nameof(Item.Price): + result.Price = reader.GetDouble(); + break; + case nameof(Item.IsSellable): + result.IsSellable = reader.GetBoolean(); + break; + case nameof(Item.NextSellableTime): + string dateString = reader.GetString() ?? ""; + if (DateTime.TryParseExact(dateString, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime date)) + { + result.NextSellableTime = date; + } + else result.NextSellableTime = DateTime.MinValue; + break; + case nameof(Item.IsTradable): + result.IsTradable = reader.GetBoolean(); + break; + case nameof(Item.NextTradableTime): + dateString = reader.GetString() ?? ""; + if (DateTime.TryParseExact(dateString, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out date)) + { + result.NextTradableTime = date; + } + else result.NextTradableTime = DateTime.MinValue; + break; } } @@ -35,6 +73,15 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter writer.WriteNumber(nameof(Item.Id), (int)value.Id); writer.WriteString(nameof(Item.Name), value.Name); writer.WriteNumber(nameof(Item.ItemType), (int)value.ItemType); + writer.WriteNumber(nameof(Item.WeaponType), (int)value.WeaponType); + writer.WriteNumber(nameof(Item.EquipSlotType), (int)value.EquipSlotType); + writer.WriteBoolean(nameof(Item.Equipable), value.Equipable); + writer.WriteBoolean(nameof(Item.IsPurchasable), value.IsPurchasable); + writer.WriteNumber(nameof(Item.Price), value.Price); + writer.WriteBoolean(nameof(Item.IsSellable), value.IsSellable); + writer.WriteString(nameof(Item.NextSellableTime), value.NextSellableTime.ToString(General.GeneralDateTimeFormat)); + writer.WriteBoolean(nameof(Item.IsTradable), value.IsTradable); + writer.WriteString(nameof(Item.NextTradableTime), value.NextTradableTime.ToString(General.GeneralDateTimeFormat)); writer.WriteEndObject(); } diff --git a/Library/Constant/ConstantSet.cs b/Library/Constant/ConstantSet.cs index 96ef5ae..3025b4f 100644 --- a/Library/Constant/ConstantSet.cs +++ b/Library/Constant/ConstantSet.cs @@ -389,7 +389,7 @@ namespace Milimoe.FunGame.Core.Library.Constant EquipItemToSlot.Armor => "防具", EquipItemToSlot.Shoes => "鞋子", EquipItemToSlot.Accessory1 => "饰品1", - EquipItemToSlot.Accessory2 => "饰品", + EquipItemToSlot.Accessory2 => "饰品2", _ => "" }; }