protected override void PerformNextAction()
        {
            Kernel         kernel  = battle.GetKernelClone();
            List <KAction> actions = kernel.getAllValidActions().CastToList <KAction>();

            Debug.Assert(actions.Count > 0);
            if (actions.Count == 1)
            {
                Debug.Assert(actions[0].GetType() == typeof(EndTurnAction));
                battle.PerformAction(null, null, EndTurnAction.ID);
            }
            else
            {
                var     nonEndTurnActions = actions.Where(x => x.GetType() != typeof(EndTurnAction)).ToList();
                int     rndIdx            = rnd.Next(nonEndTurnActions.Count);
                KAction randomAction      = nonEndTurnActions[rndIdx];
                UDebug.Log(Name + ": " + randomAction.toString());
                var randomTargetable = randomAction as TargetableAction;
                if (randomTargetable != null)
                {
                    battle.PerformAction(randomTargetable.getContext().source, randomTargetable.getContext().target, randomAction.getId());
                }
                else
                {
                    battle.PerformAction(null, null, randomAction.getId());
                }
            }
        }
Example #2
0
        private void PlayRandomAction <TAction>(IList <TAction> nonEndTurnActions)
            where TAction : KAction
        {
            KAction randomAction = nonEndTurnActions.GetRandomElement(rnd);

            PerformAction(randomAction);
        }
        protected void PerformAction(KAction action)
        {
            Debug.Log(Name + ": " + action.toString());

            var targetableAction = action as TargetableAction;

            if (targetableAction != null)
            {
                battle.PerformAction(targetableAction.getContext().source, targetableAction.getContext().target, action.getId());
            }
            else
            {
                battle.PerformAction(null, null, action.getId());
            }
        }
Example #4
0
        private void PerformAction(Action performedAction)
        {
            List <Event> events = Kernel.performAction(performedAction).CastToList <Event>();

            for (int i = 0; i < Kernel.currentState.fruitons.length; i++)
            {
                var           fruiton       = Kernel.currentState.fruitons[i] as Fruiton;
                ClientFruiton clientFruiton = clientFruitons[fruiton.id];
                clientFruiton.KernelFruiton = fruiton;
            }

            foreach (Event item in events)
            {
                battleViewer.ProcessEvent(item);
            }
        }
        private void VisualizeAction(KAction action, KFruiton kernelFruiton)
        {
            var type = action.GetType();

            if (type == typeof(MoveAction))
            {
                var moveAction = (MoveAction)action;
                var target     = ((MoveActionContext)moveAction.actionContext).target;
                GridLayoutManager.HighlightCell(target.x, target.y, Color.blue);
                VisualizePossibleAttacks(target, kernelFruiton);
            }
            else if (type == typeof(AttackAction))
            {
                var attackAction = (AttackAction)action;
                var target       = ((AttackActionContext)attackAction.actionContext).target;
                GridLayoutManager.HighlightCell(target.x, target.y, Color.red);
            }
            else if (type == typeof(HealAction))
            {
                var healAction = (HealAction)action;
                var target     = ((HealActionContext)healAction.actionContext).target;
                GridLayoutManager.HighlightCell(target.x, target.y, Color.green);
            }
        }