public IEnumerator Run(InstructionContext context, UnityObject parent) { if (context.IsRunning) { yield break; } var frame = context.OpenFrame(); WriteOutputs(context); WriteInputs(context); context.Run(Instruction, parent); yield return(null); while (context.FrameCount > frame) { context.Update(); yield return(null); } ReadOutputs(context); context.CloseFrame(); while (context.IsRunning) { context.Update(); yield return(null); } }
private void WriteOutputs(InstructionContext context) { foreach (var input in Inputs) { context.Variables.TryAddEmpty(input.Name); } }
public string GetString(InstructionContext context) { if (string.IsNullOrEmpty(Message)) { return(""); } else if (Input != null && Input.Length > 0) { if (_parameters == null || _parameters.Length != Input.Length) { _parameters = new string[Input.Length]; } for (var i = 0; i < Input.Length; i++) { _parameters[i] = GetVariableString(Input[i], context); } try { return(string.Format(Message, _parameters)); } catch { Debug.Log("PromptString has the wrong number of inputs", context.Owner); } } return(Message); }
public override ExpressionResult Evaluate(InstructionContext context) { var store = context.GetStore(Variable); if (store != null) { bool boolean; int integer; float number; if (store.TryGet(Variable.Name, out boolean)) { return(new ExpressionResult(boolean)); } else if (store.TryGet(Variable.Name, out integer)) { return(new ExpressionResult(integer)); } else if (store.TryGet(Variable.Name, out number)) { return(new ExpressionResult(number)); } } Debug.LogFormat("Unable to find variable {0} in expression", Variable.Name); return(new ExpressionResult(false)); }
public override void Begin(InstructionContext context) { foreach (var statement in Statements) { statement.Execute(context); } }
public void Interact(InstructionContext context) { if (Instructions != null && Instructions.Instruction != null) { InstructionManager.Instance.StartCoroutine(Instructions.Run(context, this)); } }
private void WriteInputs(InstructionContext context) { foreach (var input in Inputs) { context.Variables.Copy(input.Name, input); } }
public override void End(InstructionContext context) { //var target = ComponentFinder.GetAsComponent<MoveController>(context.GetObject(Target)); //if (target != null) // target.Thaw(); //else // Debug.LogFormat("unable to find the object {0} to move", Target.Name); }
public ExpressionResult Execute(InstructionContext context) { if (_expression == null) { throw new ExpressionEvaluationException(_expression, "expression is null"); } return(_expression.Evaluate(context)); }
public void Prompt(PromptInstruction instruction, object data, InstructionContext context) { Debug.Assert(_instruction == null && _data == null && _context == null, "a listener cannot receive multiple prompts at once", this); _instruction = instruction; _data = data; _context = context; OnPrompt(instruction, data, context); }
public override void End(InstructionContext context) { var store = context.GetStore(Result); var won = _data.Winner.GetComponent <Player>() == Player.Instance; if (store != null) { store.SetOrAdd(Result.Name, won); } }
private void Awake() { _context = new WorldInstructionContext(gameObject, Variable.Name + " Responder", null); _store = _context.GetStore(Variable); if (_store != null) { var variable = _store.GetVariable(Variable.Name); _store.Subscribe(this, null); Trigger(variable); } }
public override ExpressionResult Evaluate(InstructionContext context) { var number = Left.Evaluate(context); var exponent = Right.Evaluate(context); if (number.Type == ExpressionResultType.Number || exponent.Type == ExpressionResultType.Number) { return(new ExpressionResult((float)Math.Pow(number.Number, exponent.Number))); } return(new ExpressionResult(MathHelper.IntExponent(number.Integer, exponent.Integer))); }
public override void Begin(InstructionContext context) { var target = context.GetObject <MoveController>(Target); if (target != null) { target.Freeze(); } else { Debug.LogFormat("unable to find the controller {0} to freeze", Target.Name); } }
public override void Begin(InstructionContext context) { var store = context.GetStore(Variable); if (store != null) { store.ChangeOrAdd(Variable.Name, Value); } else { Debug.LogFormat(this, "Variable store not found while attempting to set {0}", Variable.Name); } }
public override void Begin(InstructionContext context) { var target = context.GetObject <GameObject>(Target); if (target != null) { Destroy(target); } else { Debug.LogFormat("unable to find the object {0} to destroy", Target.Name); } }
public override void Begin(InstructionContext context) { var target = context.GetObject <MoveController>(Target); if (target != null) { _move = target.StartCoroutine(Move(target)); } else { Debug.LogFormat("unable to find the object {0} to move", Target.Name); } }
public IEnumerator UpdateTraits(InstructionContext context, string trait) { Instruction instruction; if (Species.Ecosystem.CreatureUpdateInstructions.TryGetValue(trait, out instruction)) { var enumerator = context.Execute(instruction, this); while (enumerator.MoveNext()) { yield return(null); } } }
protected override void OnDismissed(InstructionContext context) { if (TextControl && TextControl.IsActivated) { TextControl.Deactivate(); TextControl.gameObject.SetActive(false); } if (SelectionControl && SelectionControl.IsActivated) { SelectionControl.Deactivate(); SelectionControl.gameObject.SetActive(false); } }
public override void Begin(InstructionContext context) { var trainers = new List <Trainer>(); foreach (var variable in Trainers) { var trainer = context.GetObject <Trainer>(variable); if (trainer != null) { trainers.Add(trainer); } } _data = BattleManager.Instance.StartBattle(Battle, trainers); }
private string GetVariableString(VariableReference variable, InstructionContext context) { var store = context.GetStore(variable); if (store != null) { var value = store.GetVariable(variable.Name); if (value != null) { return(value.ToString()); } } return(""); }
public IEnumerator UpdateSkills(InstructionContext context, string name) { // TODO: probably a better way to store this rather than iterating the entire list foreach (var skill in Species.Skills) { if (skill.Triggers.Contains(name)) { var enumerator = TeachSkill(context, skill); while (enumerator.MoveNext()) { yield return(null); } } } }
public IEnumerator TeachSkill(InstructionContext context, Skill skill) { var count = LearnCount(skill); if (count < skill.LearnLimit) { LearnedSkills[skill.Name] = count + 1; var enumerator = skill.Instruction.Run(context, this); while (enumerator.MoveNext()) { yield return(null); } } }
public override ExpressionResult Evaluate(InstructionContext context) { var result = new ExpressionResult(int.MinValue); foreach (var parameter in Parameters) { var p = parameter.Evaluate(context); if ((p.Type == ExpressionResultType.Number && p.Number > result.Number) || (p.Type == ExpressionResultType.Integer && p.Integer > result.Integer)) { result = p; } } return(result); }
protected override void OnPrompt(PromptInstruction instruction, object data, InstructionContext context) { var message = instruction as MessagePrompt; if (message) { Debug.Log(message.Message); } var selection = instruction as SelectionInstruction; if (selection) { _options = data as object[]; Debug.Log(selection.Message); Debug.Log(_options); } }
private void WriteInputs(InstructionContext context) { foreach (var input in Inputs) { var variable = input.Value; if (input.IsReference) { var store = context.GetStore(input.Reference); variable = store != null?store.GetVariable(input.Reference.Name) : null; } if (variable != null) { context.Variables.Copy(input.Name, variable); } } }
public override ExpressionResult Evaluate(InstructionContext context) { if (Parameters.Count == 1) { var result = Parameters[0].Evaluate(context); switch (result.Type) { case ExpressionResultType.Boolean: return(new ExpressionResult(false)); case ExpressionResultType.Number: return(new ExpressionResult(Mathf.FloorToInt(result.Number))); } return(result); } else { throw new ExpressionEvaluationException(this, "Floor can only accept exactly 1 parameter"); } }
public override void Begin(InstructionContext context) { T value; Instruction instruction; var store = context.GetStore(Variable); if (store != null && store.TryGet(Variable.Name, out value)) { instruction = GetInstruction(value) ?? Default; } else { instruction = Unset; } if (instruction != null) { context.Run(instruction, context.Parent); } }
protected override void OnPrompt(PromptInstruction instruction, object data, InstructionContext context) { var message = instruction as MessagePrompt; if (message) { if (TextControl) { TextControl.Activate(this, message.Message.GetString(context)); TextControl.gameObject.SetActive(true); } else { Debug.LogFormat("UIDialogListener for catagory {0} must have a TextControl to respond to messages.", Category); } } var selection = instruction as SelectionInstruction; if (selection) { if (SelectionControl) { SelectionControl.Activate(this, data as object[]); if (TextControl) { TextControl.Activate(this, SelectionControl, selection.Message.GetString(context)); TextControl.gameObject.SetActive(true); } else { Debug.LogFormat("UIDialogListener for catagory {0} must have a TextControl to respond to selections with messages.", Category); } } else { Debug.LogFormat("UIDialogListener for catagory {0} must have a SelectionControl to respond to selections.", Category); } } }
public override ExpressionResult Evaluate(InstructionContext context) { if (Parameters.Count == 0) { return(new ExpressionResult(Random.value)); } else if (Parameters.Count == 1) { var max = Parameters[0].Evaluate(context); if (max.Type == ExpressionResultType.Integer) { return(new ExpressionResult(Random.Range(0, max.Integer))); } else { return(new ExpressionResult(Random.Range(0.0f, max.Number))); } } else if (Parameters.Count == 2) { var min = Parameters[0].Evaluate(context); var max = Parameters[1].Evaluate(context); if (min.Type == ExpressionResultType.Integer && max.Type == ExpressionResultType.Integer) { return(new ExpressionResult(Random.Range(min.Integer, max.Integer))); } else { return(new ExpressionResult(Random.Range(min.Number, max.Number))); } } else { throw new ExpressionEvaluationException(this, "Random can only accept 0, 1, or 2 parameters"); } }