示例#1
0
        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);
            }
        }
示例#2
0
 private void WriteOutputs(InstructionContext context)
 {
     foreach (var input in Inputs)
     {
         context.Variables.TryAddEmpty(input.Name);
     }
 }
示例#3
0
        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);
        }
示例#4
0
        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));
        }
示例#5
0
 public override void Begin(InstructionContext context)
 {
     foreach (var statement in Statements)
     {
         statement.Execute(context);
     }
 }
示例#6
0
 public void Interact(InstructionContext context)
 {
     if (Instructions != null && Instructions.Instruction != null)
     {
         InstructionManager.Instance.StartCoroutine(Instructions.Run(context, this));
     }
 }
示例#7
0
文件: Skill.cs 项目: larsolm/Archives
 private void WriteInputs(InstructionContext context)
 {
     foreach (var input in Inputs)
     {
         context.Variables.Copy(input.Name, input);
     }
 }
示例#8
0
 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);
 }
示例#9
0
        public ExpressionResult Execute(InstructionContext context)
        {
            if (_expression == null)
            {
                throw new ExpressionEvaluationException(_expression, "expression is null");
            }

            return(_expression.Evaluate(context));
        }
示例#10
0
        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);
        }
示例#11
0
        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);
            }
        }
示例#12
0
        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);
            }
        }
示例#13
0
        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)));
        }
示例#14
0
        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);
            }
        }
示例#15
0
        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);
            }
        }
示例#16
0
        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);
            }
        }
示例#17
0
        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);
            }
        }
示例#18
0
        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);
                }
            }
        }
示例#19
0
        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);
            }
        }
示例#20
0
        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);
        }
示例#21
0
        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("");
        }
示例#22
0
        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);
                    }
                }
            }
        }
示例#23
0
        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);
                }
            }
        }
示例#24
0
        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);
        }
示例#25
0
        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);
            }
        }
示例#26
0
        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);
                }
            }
        }
示例#27
0
        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");
            }
        }
示例#28
0
        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);
            }
        }
示例#29
0
        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);
                }
            }
        }
示例#30
0
        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");
            }
        }