public static bool Patch_JsonConvert(string str, ref OutputNode __result)
 {
     if (str.StartsWith("[JSON", StringComparison.CurrentCultureIgnoreCase))
     {
         try
         {
             string jsonStr;
             if (str.StartsWith("[JSONFILE", StringComparison.CurrentCultureIgnoreCase))
             {
                 var array = Game.Resource.LoadBytes(str.Substring(10)); // remove [JSONFILE]
                 jsonStr = Encoding.UTF8.GetString(array);
             }
             else
             {
                 jsonStr = str.Substring(6);           // remove [JSON]
             }
             jsonStr = GlobalLib.ReplaceText(jsonStr); // preprocess
             Console.WriteLine("parse json: " + jsonStr);
             __result = ModJson.FromJsonMod <OutputNode>(jsonStr);
         }
         catch (Exception e)
         {
             Debug.LogError(e);
             Debug.LogError("解析Json错误" + str);
             throw;
         }
         return(false);
     }
     return(true);
 }
Example #2
0
        public static T FromJsonResource <T>(string path, bool replaceText = false) where T : class
        {
            string source = Heluo.Game.Resource.LoadString(path);

            if (replaceText && string.IsNullOrEmpty(source))
            {
                // filename replace
                source = Heluo.Game.Resource.LoadString(GlobalLib.ReplaceText(source));
            }
            if (string.IsNullOrEmpty(source))
            {
                Console.WriteLine("找不到Json资源: " + path);
                return(null);
            }
            if (source[0] != '{')
            {
                // original load from FileHelperEngine
                var fileHelperEngine = new FileHelpers.FileHelperEngine <T>(System.Text.Encoding.UTF8);
                return(fileHelperEngine.ReadString(source)[0]);
            }
            else
            {
                // load from valid json
                if (replaceText)
                {
                    // content replace
                    source = GlobalLib.ReplaceText(source);
                }
                return(FromJsonMod <T>(source));
            }
        }
Example #3
0
        public override bool GetValue()
        {
            bool result;

            if (!Application.isPlaying)
            {
                result = false;
            }
            else
            {
                if (count < 1)
                {
                    return(false);
                }
                for (int i = 0; i < this.count; i++)
                {
                    Props uniqueProps = GlobalLib.CreateUniquePropsByValue(sourceId, value);
                    if (uniqueProps != null)
                    {
                        Game.GameData.Inventory.Add(uniqueProps.Id, 1, true);
                        if (base.Graph != null && (bool)base.Graph.GetVariable("IsShowMessage"))
                        {
                            this.ShowMessage(uniqueProps.Name, 1);
                        }
                    }
                }
                result = true;
            }
            return(result);
        }
Example #4
0
        public static bool Reforge_Execute(CtrlForge __instance)
        {
            if (isReforgeMode)
            {
                var       t             = Traverse.Create(__instance);
                int       categoryIndex = t.Field("categoryIndex").GetValue <int>();
                int       equipIndex    = t.Field("equipIndex").GetValue <int>();
                var       array         = t.Field("sort").Field("array").GetValue() as List <ForgeInfo>[];
                ForgeInfo forgeInfo     = array[categoryIndex][equipIndex];

                Console.WriteLine("重铸");
                string id    = forgeInfo.Equip.Id;
                Props  item  = Game.Data.Get <Props>(id);
                int    price = GetReforgePrice(item);

                Console.WriteLine("id=" + id);
                string sourceId = ModExtensionSaveData.GetUniqueSourceId(id);
                Console.WriteLine("sourceId=" + sourceId);
                Props source = Game.Data.Get <Props>(sourceId);
                Console.WriteLine("sourceName=" + source.Name);

                int.TryParse(item.Remark, out int value);
                value = Math.Max(5, value + UnityEngine.Random.Range(-10, 20));
                Props newProps = GlobalLib.CreateUniquePropsByValue(sourceId, value);
                newProps.Name   = source.Name + "+"; // mark as reforged
                newProps.Remark = value.ToString();  // use remark to save value
                Game.GameData.Inventory.Add(newProps.Id, 1);
                Game.GameData.Inventory.Remove(id, 1);
                if (id != sourceId)
                {
                    ModExtensionSaveData.RemoveUniqueItem <Props>(id);
                }
                Game.GameData.Money -= price;

                ForgeInfo newForgeInfo = new ForgeInfo {
                    Id = newProps.Id, IsConditionPass = true
                };
                Traverse.Create(newForgeInfo).Property("Item").SetValue(new Forge()
                {
                    Id      = newProps.Id,
                    PropsId = newProps.Id,
                });
                Traverse.Create(newForgeInfo).Property("Equip").SetValue(newProps);
                InventoryData inventoryData = Game.GameData.Inventory[id];
                if (inventoryData != null)
                {
                    array[categoryIndex].Add(newForgeInfo);
                }
                else
                {
                    array[categoryIndex][equipIndex] = newForgeInfo;
                }

                t.Field("view").GetValue <UIForge>().UpdateEquip(array[categoryIndex].Count, false, true);
                t.Field("view").GetValue <UIForge>().UpdateMoney(Game.GameData.Money.ToString());
                return(false);
            }
            return(true);
        }
        public static void ModExt_PropsCanUse(Inventory __instance, ref bool __result, string id, string CharacterId)
        {
            // Mod武器大多没写限定,须通过检测武功筛选
            if (__result == false)
            {
                return;
            }
            Props props = Game.Data.Get <Props>(id);

            if (props != null && props.PropsType == PropsType.Weapon)
            {
                __result = GlobalLib.HasSkillType(CharacterId, props.PropsCategory);
            }
        }
Example #6
0
        public override bool GetValue()
        {
            if (Application.isPlaying)
            {
                string                fromId = GlobalLib.ReplaceText(fromInfoId);
                string                toId   = GlobalLib.ReplaceText(toInfoId);
                CharacterInfoData     from   = Game.GameData.Character[fromId];
                CharacterInfoData     to     = Game.GameData.Character[toId];
                CharacterExteriorData toEx   = Game.GameData.Exterior[toId];
                if (from == null || to == null || toEx == null || from == to)
                {
                    return(false);
                }

                float totalDelta = 0;
                for (int i = 0; i < propertyTypes.Length; ++i)
                {
                    var propertyType = propertyTypes[i];
                    totalDelta += from.GetUpgradeableProperty(propertyType) - to.GetUpgradeableProperty(propertyType);
                }
                float scale = scalar * (2f - totalDelta / 2000f);

                List <string> list = new List <string>();
                for (int i = 0; i < propertyTypes.Length; ++i)
                {
                    var propertyType = propertyTypes[i];
                    int delta        = from.GetUpgradeableProperty(propertyType) - to.GetUpgradeableProperty(propertyType) + baseValue;
                    int exp          = (int)Mathf.Max(0f, delta * scale);
                    if (exp >= 100)
                    {
                        to.AddUpgradeablePropertyExp(propertyType, exp);
                        to.UpgradeProperty(false);
                        list.Add(string.Format("{0}提升{1}", Game.Data.Get <StringTable>(messages[i]).Text, exp / 100));
                    }
                }
                if (list.Count > 0)
                {
                    Game.UI.AddMessage(string.Format("{0}经切磋,{1}", toEx.FullName(), string.Join(",", list)), UIPromptMessage.PromptType.Normal);
                }
                else
                {
                    Game.UI.AddMessage(string.Format("{0}由于四维超出对手过多,切磋后未获提升", toEx.FullName()), UIPromptMessage.PromptType.Normal);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static bool Duel_TravelClick(ref CtrlNurturance __instance)
        {
            var t           = Traverse.Create(__instance);
            var travelMovie = t.Field("UIInfo").Field("travelmovienumber");

            if (!travelMovie.GetValue <string>().IsNullOrEmpty() && duelOn.Value)
            {
                // Duel
                string s = travelMovie.GetValue <string>();
                GlobalLib.SetReplaceText("[npc0]", s.Substring(4, 6));   // m605[]
                {
                    new RunCinematicAction
                    {
                        cinematicId = "mmod_duel"
                    }.GetValue();
                }
                travelMovie.SetValue(string.Empty);
                return(false);
            }
            return(true);
        }
Example #8
0
        public void OnUpdate()
        {
            if (!DebugOn.Value)
            {
                return;
            }
            if (Input.GetKeyDown(NodeDocKey.Value))
            {
                string target = DebugOutDir.Value + "游戏指令(OutputNode)文档.json";
                ModOutputNodeConverter.ExportDoc(target);
                target = DebugOutDir.Value + "txt表格(Item)文档.json";
                ItemDocConverter.ExportDoc(target);
            }
            if (Input.GetKeyDown(NodeFileKey.Value) && !string.IsNullOrEmpty(NodeContent.Value))
            {
                // OutputNode
                string     target     = DebugOutDir.Value + NodeFilePath.Value;
                OutputNode obj        = OutputNodeConvert.Deserialize(NodeContent.Value);
                var        strJsonMod = ModJson.ToJsonMod(obj, typeof(OutputNode), JsonPritty.Value);
                Console.WriteLine("Json版 = " + strJsonMod);
                GlobalLib.ToFile(strJsonMod, target);
            }
            if (Input.GetKeyDown(MovieFileKey.Value) && !string.IsNullOrEmpty(MovieFileId.Value))
            {
                // movie
                string source = string.Format(MovieFileType.Value == MovieType.Cinematic ? GameConfig.CinematicPath : GameConfig.SchedulerPath, MovieFileId.Value);
                string target = string.Format(DebugOutDir.Value + MovieFilePath.Value, MovieFileId.Value);
                var    obj    = ModJson.FromJsonResource <ScheduleGraph.Bundle>(source);
                if (JsonFormat.Value)
                {
                    var strJsonMod = ModJson.ToJsonMod(obj, typeof(ScheduleGraph.Bundle), JsonPritty.Value);
                    Console.WriteLine("Json版 = " + strJsonMod);
                    GlobalLib.ToFile(strJsonMod, target);

                    // 测试读取并对比重新通过Json构建的是否有差
                    var obj2 = ModJson.FromJsonMod <ScheduleGraph.Bundle>(strJsonMod);
                    JsonSerializerSettings originalSetting = new JsonSerializerSettings
                    {
                        Converters = new JsonConverter[]
                        {
                            new OutputNodeJsonConverter()
                        }
                    };
                    string str2 = ModJson.ToJson(obj2, typeof(ScheduleGraph.Bundle), originalSetting, JsonPritty.Value);
                    Console.WriteLine("重构脚本 = " + str2);
                }
                else
                {
                    GlobalLib.ToFile(Game.Resource.LoadString(source), target);
                }
            }
            if (Input.GetKeyDown(BattleFileKey.Value) && !string.IsNullOrEmpty(BattleFileId.Value))
            {
                // battle schedule
                string source = string.Format(GameConfig.BattleSchedulePath, GameConfig.Language, BattleFileId.Value + ".json");
                string target = string.Format(DebugOutDir.Value + BattleFilePath.Value, BattleFileId.Value);
                if (JsonFormat.Value)
                {
                    BattleSchedule obj        = ModJson.FromJsonResource <BattleSchedule>(source);
                    var            strJsonMod = ModJson.ToJsonMod(obj, typeof(BattleSchedule), JsonPritty.Value);
                    Console.WriteLine("Json版 = " + strJsonMod);
                    GlobalLib.ToFile(strJsonMod, target);
                }
                else
                {
                    GlobalLib.ToFile(Game.Resource.LoadString(source), target);
                }
            }
            if (Input.GetKeyDown(BuffFileKey.Value) && !string.IsNullOrEmpty(BuffFileId.Value))
            {
                // buff
                string source = string.Format(GameConfig.ButtleBufferPath, GameConfig.Language, BuffFileId.Value + ".json");
                string target = string.Format(DebugOutDir.Value + BuffFilePath.Value, BuffFileId.Value);
                if (JsonFormat.Value)
                {
                    Heluo.Data.Buffer obj = ModJson.FromJsonResource <Heluo.Data.Buffer>(source);
                    var strJsonMod        = ModJson.ToJsonMod(obj, typeof(Heluo.Data.Buffer), true);
                    Console.WriteLine("Json版 = " + strJsonMod);
                    GlobalLib.ToFile(strJsonMod, target);
                }
                else
                {
                    GlobalLib.ToFile(Game.Resource.LoadString(source), target);
                }
            }
        }
        public static bool ModExt_NewPropsUI(CtrlMedicine __instance)
        {
            var mapping = Traverse.Create(__instance).Field("mapping");
            var sort    = Traverse.Create(__instance).Field("sort").GetValue <List <PropsInfo> >();

            mapping.SetValue(GlobalLib.GetUICharacterMapping());
            sort.Clear();
            foreach (KeyValuePair <string, InventoryData> keyValuePair in Game.GameData.Inventory)
            {
                string key   = keyValuePair.Key;
                Props  props = Game.Data.Get <Props>(key);
                if (props != null && props.PropsType == PropsType.Medicine)
                {
                    bool show = false;
                    if (props.CanUseID != null && props.CanUseID.Count > 0)
                    {
                        for (int i = 0; i < props.CanUseID.Count; i++)
                        {
                            string text = props.CanUseID[i];
                            if (!text.IsNullOrEmpty() && text == mapping.GetValue <CharacterMapping>().Id)
                            {
                                show = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        show = true;
                        if (props.PropsCategory >= PropsCategory.Fist_Secret_Scroll && props.PropsCategory <= PropsCategory.Throw_Secret_Scroll && key.StartsWith("p_scroll"))
                        {
                            foreach (var pe in props.PropsEffect)
                            {
                                if (pe is PropsLearnSkill pls)
                                {
                                    PropsCategory skillType = Game.Data.Get <Skill>(pls.Id).Type;
                                    if (!GlobalLib.HasSkillType(mapping.GetValue <CharacterMapping>().InfoId, skillType))
                                    {
                                        show = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (show)
                    {
                        PropsInfo propsInfo = new PropsInfo(key)
                        {
                            ConditionStatus = ((props.UseTime == PropsUseTime.Battle) ? PropsInfo.PropsConditionStatus.UseTimeFail_Battle : PropsInfo.PropsConditionStatus.AllPass)
                        };
                        sort.Add(propsInfo);
                    }
                }
            }
            var view = Traverse.Create(__instance).Field("view").GetValue <UIMedicine>();

            view.UpdateProps(sort.Count);
            if (sort.Count <= 0)
            {
                view.UpdatePropsIntroduction(null);
            }
            return(false);
        }
        static void ModExt_NewProps_DefaultData(DataManager __instance)
        {
            // 为每种心法和招式添加对应秘籍
            var DictProps  = __instance.Get <Props>();
            var DictSkill  = __instance.Get <Skill>();
            var DictMantra = __instance.Get <Mantra>();

            foreach (Skill skill in DictSkill.Values)
            {
                Props props = new Props
                {
                    Id            = "p_scroll_" + skill.Id,
                    Description   = skill.Description,
                    PropsType     = PropsType.Medicine,
                    PropsCategory = GlobalLib.GetScrollType(skill.Type),
                    Name          = skill.Name + "秘籍",
                    PropsEffect   = new List <PropsEffect>
                    {
                        new PropsLearnSkill(skill.Id)
                    },
                    PropsEffectDescription = "学会招式:" + skill.Name
                };
                DictProps.Add(props.Id, props);
            }
            foreach (Mantra mantra in DictMantra.Values)
            {
                Props props2 = new Props
                {
                    Id            = "p_scroll_" + mantra.Id,
                    Description   = mantra.Description,
                    PropsType     = PropsType.Medicine,
                    PropsCategory = PropsCategory.InternalStyle_Secret_Scroll,
                    Name          = mantra.Name + "秘籍",
                    PropsEffect   = new List <PropsEffect>
                    {
                        new PropsLearnMantra(mantra.Id)
                    },
                    PropsEffectDescription = "学会心法:" + mantra.Name
                };
                DictProps.Add(props2.Id, props2);
            }
            // 为每个NPC添加人物加入道具
            var DictNpc    = __instance.Get <Npc>();
            var DictReward = __instance.Get <Reward>();

            foreach (Npc npc in DictNpc.Values)
            {
                Props props3 = new Props
                {
                    Id            = "p_npcj_" + npc.Id,
                    Description   = npc.Name + "加入",
                    PropsType     = PropsType.Quest,
                    PropsCategory = PropsCategory.Other_Quest,
                    Name          = npc.Name + "加入",
                    PropsEffect   = new List <PropsEffect>
                    {
                        new PropsReward("re_npcj_" + npc.Id)
                    },
                    PropsEffectDescription = "加入队友:" + npc.Name
                };
                DictProps.Add(props3.Id, props3);
                string s      = "{\"LogicalNode\":[{\"CommunityAction\":\"" + npc.Id + "\",True}],0}";
                Reward reward = new Reward
                {
                    Id            = "re_npcj_" + npc.Id,
                    Description   = npc.Name + "加入",
                    IsShowMessage = true,
                    Rewards       = new BaseFlowGraph(OutputNodeConvert.Deserialize(s))
                };
                DictReward.Add(reward.Id, reward);
            }
        }
Example #11
0
 public void OnUpdate()
 {
     if (teamManageOn.Value && TeamMemberObject != null && TeamMemberObject.activeInHierarchy)
     {
         var UIHome = Game.UI.Get <UIHome>();
         if (UIHome == null)
         {
             return;
         }
         if (Input.GetKeyDown(teamMemberAdd.Value))
         {
             CharacterMapping cm = GlobalLib.GetUICharacterMapping();
             if (cm != null && cm.Id != GameConfig.Player && !Game.GameData.Party.Contains(cm.Id))
             {
                 Game.GameData.Party.AddParty(cm.Id, false);
                 int count = Traverse.Create(UIHome).Property("controller").Field("characterMapping").Property("Count").GetValue <int>();
                 UIHome.UpdateCommunity(count);
             }
         }
         if (Input.GetKeyDown(teamMemberRemove.Value))
         {
             CharacterMapping cm = GlobalLib.GetUICharacterMapping();
             if (cm != null && cm.Id != GameConfig.Player && Game.GameData.Party.Contains(cm.Id))
             {
                 Game.GameData.Party.RemoveParty(cm.Id);
                 int count = Traverse.Create(UIHome).Property("controller").Field("characterMapping").Property("Count").GetValue <int>();
                 UIHome.UpdateCommunity(count);
             }
         }
         if (Input.GetKeyDown(teamMemberRemoveAll.Value))
         {
             foreach (var pi in Game.GameData.Party.GetRange(0, Game.GameData.Party.Count))
             {
                 if (pi != GameConfig.Player)
                 {
                     Game.GameData.Party.RemoveParty(pi);
                 }
             }
             int count = Traverse.Create(UIHome).Property("controller").Field("characterMapping").Property("Count").GetValue <int>();
             UIHome.UpdateCommunity(count);
         }
         if (Input.GetKeyDown(communityRemove.Value))
         {
             CharacterMapping cm = GlobalLib.GetUICharacterMapping();
             if (cm != null && cm.Id != GameConfig.Player)
             {
                 Game.GameData.Community[cm.Id].isOpen = false;
                 Game.GameData.NurturanceOrder.CloseCommunityOrder(cm.Id);
                 if (Game.GameData.Party.Contains(cm.Id))
                 {
                     Game.GameData.Party.RemoveParty(cm.Id);
                 }
                 Traverse.Create(UIHome).Property("controller").Method("OnShow").GetValue();
                 Traverse.Create(UIHome).Property("controller").Method("HideCommunity").GetValue();
                 Traverse.Create(UIHome).Property("controller").Method("UpdateCommunity").GetValue();
                 string joinPropsId = "p_npcj_" + cm.Id;
                 if (!Game.GameData.Inventory.ContainsKey(joinPropsId))
                 {
                     new RewardProps
                     {
                         method  = Method.Add,
                         propsId = "p_npcj_" + cm.Id,
                         value   = 1
                     }.GetValue();
                 }
             }
         }
     }
 }