public static void checkDrawConditions(Map map) { foreach (Layer layer in map.Layers.Where(l => l.Properties.ContainsKey("DrawConditions"))) { layer.Properties.AddOrReplace("DrawConditionsResult", PyUtils.checkEventConditions(layer.Properties["DrawConditions"], layer, Game1.currentLocation) ? "T" : "F"); } }
private void registerCPTokens() { if (!Helper.ModRegistry.IsLoaded("Pathoschild.ContentPatcher")) { return; } IContentPatcherAPI api = Helper.ModRegistry.GetApi <IContentPatcherAPI>("Pathoschild.ContentPatcher"); /* * api.RegisterToken(this.ModManifest, "LuaString", () => * { * foreach (string k in tokenStrings.Keys) * if (tokenStrings[k] != PyUtils.getLuaString(k)) * return true; * * return false; * }, () => Context.IsWorldReady, (s) => * { * tokenStrings.AddOrReplace(s, PyUtils.getLuaString(s)); * return new string[] { tokenStrings[s] }; * }, true, true);*/ api.RegisterToken(this.ModManifest, "Conditional", () => { foreach (string k in tokenBoleans.Keys) { if (tokenBoleans[k] != PyUtils.checkEventConditions(k.Split(new[] { " >: " }, StringSplitOptions.RemoveEmptyEntries)[0])) { return(true); } } return(false); }, () => Context.IsWorldReady, (s) => { string[] parts = s.Split(new [] { " >: " }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 2) { return(null); } tokenBoleans.AddOrReplace(s, PyUtils.checkEventConditions(parts[0])); return(new string[] { tokenBoleans[s] ? parts[1] : parts.Length < 3 ? null : parts[2] }); }, true, true); api.RegisterToken( mod: this.ModManifest, name: "ObjectByName", updateContext: () => { if (!PyTK.PyTKMod.UpdateCustomObjects) { return(false); } UpdateCustomObjects = false; return(true); }, isReady: () => Context.IsWorldReady, getValue: GetObjectByNameTokenValue, allowsInput: true, requiresInput: true ); api.RegisterToken( mod: this.ModManifest, name: "LuaString", updateContext: () => { if (!UpdateLuaTokens) { return(false); } UpdateLuaTokens = false; return(true); }, isReady: () => Context.IsWorldReady, getValue: GetLuaString, allowsInput: true, requiresInput: true ); }
private void registerEventPreconditions() { PyUtils.addEventPrecondition("hasmod", (key, values, location) => { string mod = values.Replace("hasmod ", "").Replace(" ", ""); bool result = LuaUtils.hasMod(mod); return(result); }); PyUtils.addEventPrecondition("switch", (key, values, location) => { return(LuaUtils.switches(values.Replace("switch ", ""))); }); PyUtils.addEventPrecondition("npcxy", (key, values, location) => { var v = values.Split(' '); var name = v[0]; if (v.Length == 1) { return(Game1.getCharacterFromName(name) is NPC npcp && npcp.currentLocation == location); } var x = int.Parse(v[1]); if (v.Length == 2) { return(Game1.getCharacterFromName(name) is NPC npcx && npcx.currentLocation == location && npcx.getTileX() == x); } var y = int.Parse(v[2]); return(Game1.getCharacterFromName(name) is NPC npc && npc.currentLocation == location && (x == -1 || npc.getTileX() == x) && (y == -1 || npc.getTileY() == y)); }); PyUtils.addEventPrecondition("items", (key, values, location) => { var v = values.Split(','); List <Item> items = new List <Item>(Game1.player.Items); foreach (string pair in v) { var p = pair.Split(':'); var name = p[0]; var stack = p.Length == 1 ? 1 : int.Parse(p[1]); int count = 0; foreach (Item item in items) { if (item.Name == name) { count += item.Stack; } if (count >= stack) { return(true); } } } return(false); }); PyUtils.addEventPrecondition("counter", (key, values, location) => { var v = values.Split(' '); var c = LuaUtils.counters(v[0]); if (v.Length == 2) { return(c == int.Parse(v[1])); } else { return(PyUtils.calcBoolean("c " + values, new KeyValuePair <string, object>("c", c))); } }); PyUtils.addEventPrecondition("LC", (key, values, location) => { return(PyUtils.checkEventConditions(values.Replace("%div", "/"), location, location)); }); }