private void SetupBattle(
            IEnumerable <int> localPlayerFruitonIds,
            IEnumerable <Position> localPlayerPositions,
            IEnumerable <int> opponentFruitonIds,
            IEnumerable <Position> opponentPositions,
            Player localPlayer,
            Player opponent
            )
        {
            IEnumerable <GameObject> localTeam    = ClientFruitonFactory.CreateClientFruitonTeam(localPlayerFruitonIds, battleViewer.Board);
            IEnumerable <GameObject> opponentTeam = ClientFruitonFactory.CreateClientFruitonTeam(opponentFruitonIds, battleViewer.Board);

            battleViewer.InitializeTeam(localTeam, localPlayer, true, localPlayerPositions.ToArray());
            battleViewer.InitializeTeam(opponentTeam, opponent, false, opponentPositions.ToArray());

            // Remove fruitons from factory and use fruitons from given state instead
            foreach (GameObject o in battleViewer.FruitonsGrid)
            {
                ClientFruiton clientFruiton;
                if (o != null &&
                    (clientFruiton = o.GetComponent <ClientFruiton>()) != null)
                {
                    KFruiton kernelFruiton = clientFruiton.KernelFruiton;
                    KFruiton realFruiton   = Kernel.currentState.field.get(kernelFruiton.position).fruiton;
                    clientFruiton.KernelFruiton = realFruiton;
                }
            }

            BattleReady();
            if (!IsLocalPlayerFirst)
            {
                battleViewer.FlipFruitons();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initializes fruiton drag from the team grid if player is in team edit view mode.
 /// </summary>
 /// <param name="fruiton">fruiton to be draged</param>
 /// <param name="position">position in team from which fruiton is dragged</param>
 protected override void OnBeginDragFromTeamListener(Fruiton fruiton, Position position)
 {
     if (viewMode == ViewMode.TeamEdit)
     {
         BeginFruitonDrag(fruiton, position);
     }
 }
Beispiel #3
0
        public List <Point> ComputePossibleAttacks(Point potentialPosition, Fruiton kernelFruiton)
        {
            var possibleAttacks  = new List <Point>();
            var attackGenerators = kernelFruiton.attackGenerators.CastToList <AttackGenerator>();

            foreach (var attackGenerator in attackGenerators)
            {
                var attacks = attackGenerator.getAttacks(potentialPosition, kernelFruiton.currentAttributes.damage)
                              .CastToList <AttackAction>();
                foreach (var attack in attacks)
                {
                    var target = ((AttackActionContext)attack.actionContext).target;
                    if (Kernel.currentState.field.exists(target))
                    {
                        var potentialTarget = Kernel.currentState.field.get(target).fruiton;
                        if (potentialTarget != null &&
                            potentialTarget.owner.id != Kernel.currentState.get_activePlayer().id)
                        {
                            possibleAttacks.Add(potentialTarget.position);
                        }
                    }
                }
            }
            return(possibleAttacks);
        }
        private void UpdateAndShowTooltip(GameObject fruitonObject)
        {
            var     clientFruiton = fruitonObject.GetComponent <ClientFruiton>();
            Fruiton kernelFruiton = clientFruiton.KernelFruiton;
            var     fruitonInfo   = TooltipUtil.GenerateTooltip(kernelFruiton);

            FruitonInfoPanel.SetActive(true);
            FruitonInfoPanel.GetComponentInChildren <Text>().text = fruitonInfo;
        }
Beispiel #5
0
        /// <summary>
        /// Add a fruiton to currently selected team.
        /// </summary>
        /// <param name="fruiton">fruiton to add</param>
        /// <param name="position">position in team where the fruiton should be added</param>
        private void AddFruitonToTeam(Fruiton fruiton, Position position)
        {
            FridgeFruiton fridgeFruiton = dbFridgeMapping[fruiton.dbId];

            fridgeFruiton.Count--;
            var team = teams[selectedTeamIndex].KernelTeam;

            team.FruitonIDs.Add(fruiton.dbId);
            team.Positions.Add(position);
            MyTeamGrid.AddFruitonAt(fruiton, position);
        }
        private void VisualizePossibleAttacks(KVector2 potentialPosition, KFruiton kernelFruiton)
        {
            var potentialTargets = battle.ComputePossibleAttacks(potentialPosition, kernelFruiton);

            foreach (var potentialTarget in potentialTargets)
            {
                if (!GridLayoutManager.IsTileAttack(potentialTarget.x, potentialTarget.y))
                {
                    GridLayoutManager.HighlightCell(potentialTarget.x, potentialTarget.y, Color.yellow);
                }
            }
        }
        public LazyDictionary <int, List <TargetableAction> > VisualizeAvailableTargetableActions(KVector2 indices)
        {
            var           result        = new LazyDictionary <int, List <TargetableAction> >();
            List <Action> allActions    = battle.GetAllValidActionFrom(indices);
            Fruiton       kernelFruiton = battle.GetFruiton(indices);

            foreach (Action action in allActions)
            {
                VisualizeAction(action, kernelFruiton);
                TargetableAction castAction = action as TargetableAction;
                if (castAction != null)
                {
                    result[action.getId()].Add(castAction);
                }
            }
            return(result);
        }
        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);
            }
        }