From 98693412f198efd4c72d9b127fd025ce17640ee6 Mon Sep 17 00:00:00 2001 From: ShakeFlower Date: Tue, 8 Jul 2025 21:27:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=95=86=E5=BA=97=E6=97=B6=E7=9A=84=E4=B8=80=E4=BA=9B=E5=B0=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8D=E8=A3=85=E5=A4=87?= =?UTF-8?q?=E6=95=B0=E5=80=BC=E6=9C=AA=E6=AD=A3=E7=A1=AE=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ViewModels/Migrator/DataJSMigrator.cs | 2 ++ ViewModels/Migrator/FloorsMigrator.cs | 11 ++++-- ViewModels/Migrator/ItemsJSMigrator.cs | 28 ++++++++++++++- ViewModels/Utils/MotaEventParser.cs | 50 ++++++++++++++++++++++++++ ViewModels/Utils/StringUtils.cs | 2 +- 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 ViewModels/Utils/MotaEventParser.cs diff --git a/ViewModels/Migrator/DataJSMigrator.cs b/ViewModels/Migrator/DataJSMigrator.cs index ad349a1..fdc5161 100644 --- a/ViewModels/Migrator/DataJSMigrator.cs +++ b/ViewModels/Migrator/DataJSMigrator.cs @@ -192,7 +192,9 @@ namespace H5MotaUpdate.ViewModels shopId = shop["id"].ToString(), flagName_Time = "flag:" + shopId + "_times"; // 新设的购买次数变量flag:xxx string priceStr = shopNeed.Replace("times", flagName_Time); //商店价格字符串,用新变量名取代times + shop["text"] = StringUtils.ReplaceInBetweenCurlyBraces(shopText, "times", flagName_Time); + shop["text"] = StringUtils.ReplaceInBetweenCurlyBraces(shopText, "need", priceStr); shop["disablePreview"] = false; if (use == "experience") diff --git a/ViewModels/Migrator/FloorsMigrator.cs b/ViewModels/Migrator/FloorsMigrator.cs index 2bccc89..0c5a1a2 100644 --- a/ViewModels/Migrator/FloorsMigrator.cs +++ b/ViewModels/Migrator/FloorsMigrator.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using H5MotaUpdate.ViewModels.Utils; +using Newtonsoft.Json.Linq; using System.IO; using System.Text; @@ -92,6 +93,12 @@ namespace H5MotaUpdate.ViewModels // 设置每张地图的尺寸。如果自己有就用自己的,否则设为默认长宽。 + foreach (JProperty posEvent in jsonObject["events"]) + { + JToken posEventValue = posEvent.Value; + MotaEventParser.parseMotaEvent(posEventValue); + } + int width, height; if (jsonObject["width"] != null && jsonObject["width"].Type == JTokenType.Integer) @@ -145,7 +152,7 @@ namespace H5MotaUpdate.ViewModels jsonObject["images"] = new JArray(newImages); #endregion - #region + #region 滑冰转移到背景层 JArray mapMatrix = (JArray)jsonObject["map"]; JArray zeroBgMatrix = StringUtils.CreateMatrix(width, height); for (int i = 0; i < mapMatrix.Count; i++) diff --git a/ViewModels/Migrator/ItemsJSMigrator.cs b/ViewModels/Migrator/ItemsJSMigrator.cs index 0d81c49..c99c9c1 100644 --- a/ViewModels/Migrator/ItemsJSMigrator.cs +++ b/ViewModels/Migrator/ItemsJSMigrator.cs @@ -89,11 +89,37 @@ namespace H5MotaUpdate.ViewModels { string key = prop.Name; JObject perData = (JObject)prop.Value; - if (perData["cls"].ToString() == "keys") + + if (perData["cls"]?.ToString() == "keys") { perData["cls"] = "tools"; perData["hideInToolbox"] = true; } + + if (perData["cls"]?.ToString() == "equips") + { + JObject equipValue = (JObject)perData["equip"]; + + if (equipValue != null) + { + JObject valueObj = new JObject(); + + // 装备属性的名字 + string[] keysToMove = { "atk", "def", "mdef", "hp" }; + + foreach (string keyToMove in keysToMove) + { + if (equipValue.ContainsKey(keyToMove)) + { + JToken val = equipValue[keyToMove]; + valueObj[keyToMove] = val; + equipValue.Remove(keyToMove); + } + } + equipValue["value"] = valueObj; + perData["equip"] = equipValue; + } + } } if (newItemDatas.ContainsKey("snow")) { diff --git a/ViewModels/Utils/MotaEventParser.cs b/ViewModels/Utils/MotaEventParser.cs new file mode 100644 index 0000000..7c48266 --- /dev/null +++ b/ViewModels/Utils/MotaEventParser.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace H5MotaUpdate.ViewModels.Utils +{ + internal static class MotaEventParser + { + public static void parseOneMotaEvent(JObject motaEvent) + { + // 如果type为openShop,添加一个open:true的键 + if (motaEvent["type"] is JValue typeValue && typeValue.Value is string typeString && typeString == "openShop") + { + motaEvent["open"] = true; + } + } + + static void parseMotaEventArr(JArray motaEventArr) + { + foreach (JToken motaEventToken in motaEventArr) + { + // 只处理对象事件 字符串不计 + if (motaEventToken.Type == JTokenType.Object) + { + JObject motaEvent = (JObject)motaEventToken; + parseOneMotaEvent(motaEvent); + } + } + } + + public static void parseMotaEvent(JToken motaEvent) + { + if (motaEvent is JArray motaEventArr) + { + parseMotaEventArr(motaEventArr); + } + else if (motaEvent is JObject motaEventObj) + { // 说明有覆盖触发器等,data中才是真正的事件 + if (motaEvent["data"] is JArray dataArr) + { + parseMotaEventArr(dataArr); + } + } + } + } +} diff --git a/ViewModels/Utils/StringUtils.cs b/ViewModels/Utils/StringUtils.cs index b2fee68..96a3083 100644 --- a/ViewModels/Utils/StringUtils.cs +++ b/ViewModels/Utils/StringUtils.cs @@ -50,7 +50,7 @@ namespace H5MotaUpdate.ViewModels // 获取匹配的内容,去掉 ${ 和 } string content = match.Groups[1].Value; // 在匹配的内容中替换 oldWord 为 newWord - string modifiedContent = content.Replace(oldWord, newWord); + string modifiedContent = "(" + content.Replace(oldWord, newWord) + ")"; // 返回替换后的完整匹配字符串,包含 ${ 和 } return "${" + modifiedContent + "}"; });