Ejemplo n.º 1
0
    /**************
     * Event Control
     * *************/
    public override void eventHappened(IGameEvent ge)
    {
        if (!ge.belongsTo(this))
        {
            return;
        }

        switch (ge.Name.ToLower())
        {
        case "turn": {
            if (!this.IsMoving) // If it's moving, just ignore the turn
            {
                object dir = ge.getParameter("direction");
                if (dir != null && dir is Direction)
                {
                    this.turnDirection = (Direction)dir;
                }

                this.turn = true;
            }
        } break;

        case "move": {
            this.moveToCell = (Cell)ge.getParameter("cell");
            this.move       = moveToCell != null;

            distanceToMove = (ge.getParameter("distance") != null)? (int)ge.getParameter("distance"): 0;
            object dir = ge.getParameter("direction");
            if (dir != null && dir is Direction)
            {
                this.turnDirection = (Direction)dir;
                this.turnAfterMove = true;
            }

            this.bcEvent = ge;
        } break;

        case "teleport": {
            teleport       = true;
            teleportToCell = ge.getParameter("Cell") as Cell;
        } break;

        case "stop":
        {
            stop = true;
        } break;
        }
    }
Ejemplo n.º 2
0
        internal static void EventHappened(MonoBehaviour reference, Dictionary <GameEventConfig, MethodInfo> calls, Dictionary <MethodInfo, GameEventAttribute> attrInfo, IGameEvent ge)
        {
            if (reference == null)
            {
                Debug.LogWarning("WTF");
                return;
            }

            if (calls != null && calls.Count > 0)
            {
                var config = new GameEventConfig(ge);
                if (calls.ContainsKey(config))
                {
                    var call = calls[config];

                    if (!attrInfo[call].RequiresReference || ge.belongsTo(reference, reference.GetType().Name))
                    {
                        List <object> parameters = new List <object>();
                        foreach (var p in call.GetParameters())
                        {
                            if (ge.Params.Contains(p.Name.ToLower()))
                            {
                                parameters.Add(ge.getParameter(p.Name));
                            }
                            else
                            {
                                parameters.Add(p.DefaultValue);
                            }
                        }

                        var output = call.Invoke(reference, parameters.ToArray());

                        if (output is IEnumerator)
                        {
                            // If we want to autofinish it we use the controller, else just launch it
                            reference.StartCoroutine(attrInfo[call].AutoFinish ? CoroutineController(ge, output as IEnumerator) : output as IEnumerator);
                        }
                        else if (attrInfo[call].AutoFinish)
                        {
                            // If is not a coroutine and we have to auto finish it, we just do it
                            Game.main.eventFinished(ge);
                        }
                    }
                }
            }
        }