public override void Parse(string line, TranspilerContext context) { if (line.StartsWith("#delay")) { var data = GetData(line); var amount = int.Parse(data["amount"].Value); var unit = data["unit"].Value.TrimEnd('s'); switch (unit) { case "minute": amount *= 60; break; case "hour": amount *= 3600; break; } var timerNumber = context.CreateTimer(); context.AddToScript(context.ApplyStacks(new Defrule(new[] { "true" }, new[] { $"enable-timer {timerNumber} {amount}", "disable-self" }))); context.ConditionStack.Push(new Condition($"timer-triggered {timerNumber}")); } else { context.ConditionStack.Pop(); } }
public override void Parse(string line, TranspilerContext context) { var data = GetData(line); var resources = data["resourcelist"].Value .ReplaceIfNullOrEmpty("wood and food and gold") .Replace("all", "wood and food and gold and stone") .Split(" and "); var threshold = data["threshold"].Value.ReplaceIfNullOrEmpty("300"); var interval = data["time"].Value.ReplaceIfNullOrEmpty("60"); var rules = new List <Defrule>(); var timer = context.CreateTimer(); rules.Add(new Defrule(new[] { "true" }, new[] { $"enable-timer {timer} {interval}", "disable-self" })); (var escrowRules, var goalToResourceMap) = CreateNonEscrowedResourceGoals(context, resources); rules.AddRange(escrowRules); foreach (var rule in GetBalanceRules(8, int.Parse(threshold), goalToResourceMap, goalToResourceMap.Keys)) { rule.Conditions.Add(new Condition($"timer-triggered {timer}")); rules.Add(rule); } rules.Add(new Defrule(new[] { $"timer-triggered {timer}" }, new[] { $"disable-timer {timer}", $"enable-timer {timer} {interval}" })); context.AddToScript(context.ApplyStacks(rules)); context.FreeVolatileGoals(goalToResourceMap.Keys); }