public static bool StartPatch_SetProperty(CtrlRegistration __instance, CharacterUpgradableProperty property, int value) { var Tpoint = Traverse.Create(__instance).Field("point"); int num = Tpoint.GetValue <int>() - value; if (num < 0) { return(false); } var data = Traverse.Create(__instance).Field("player_info_data").GetValue <CharacterInfoData>(); int num2 = data.GetUpgradeablePropertyLevel(property); num2 = (int)Mathf.Lerp((float)num2, (float)(num2 + value), 1f); if (num2 < newAttributeValues[property]) { return(false); } data.SetUpgradeablePropertyLevel(property, num2); Tpoint.SetValue(num); UpdateAttributes(__instance); return(false); }
private static bool AddLuaParams(Script script, T item) { if (!UserData.IsTypeRegistered(typeof(T))) { UserData.RegisterType(typeof(T)); } if (item.GetType() != typeof(Npc)) { script.Globals["item"] = item; } else { // 传NPC信息没太大用处,改传CharacterInfo的信息 Npc npc = item as Npc; try { CharacterExteriorData exterior = null; CharacterInfoData info = null; if (!npc.ExteriorId.IsNullOrEmpty()) { exterior = Game.GameData.Exterior[npc.ExteriorId]; } if (exterior != null && !exterior.InfoId.IsNullOrEmpty()) { info = Game.GameData.Character[exterior.InfoId]; } else if (!npc.CharacterInfoId.IsNullOrEmpty()) { info = Game.GameData.Character[npc.CharacterInfoId]; } if (info == null || info.Id.IsNullOrEmpty()) { return(false); } if (info.Property[CharacterProperty.Max_HP].Value <= 0) { return(false); } if (!UserData.IsTypeRegistered <CharacterInfoData>()) { UserData.RegisterType <CharacterInfoData>(InteropAccessMode.Default, null); } script.Globals["item"] = info; foreach (object obj in Enum.GetValues(typeof(CharacterUpgradableProperty))) { CharacterUpgradableProperty prop = (CharacterUpgradableProperty)obj; int value = info.GetUpgradeableProperty(prop); script.Globals[obj.ToString().ToLower()] = value; } foreach (object obj2 in Enum.GetValues(typeof(CharacterProperty))) { CharacterProperty prop2 = (CharacterProperty)obj2; int value2 = info.Property[prop2].Value; script.Globals[obj2.ToString().ToLower()] = value2; } } catch { Console.WriteLine(string.Format("NPC信息出错 npc={0}, exId={1}, infoId={2}", npc.Id, npc.ExteriorId, npc.CharacterInfoId)); return(false); } } return(true); }