Пример #1
0
    // TODO: State dependent behaviour for when a tile can't be clicked
    bool CanClickTile()
    {
        BattleTile tile = this.hoveredTile;

        if (this.state == BattleState.SelectingAction)
        {
            return(true);
        }
        else if (this.state == BattleState.MoveAction)
        {
            if (
                tile == null ||
                tile == this.selectedTile ||
                tile.mech != null ||
                tile.data.allowsMovement == false ||
                this.CanTeamSeeTile(this.selectedTile.mech.team, tile) == false
                )
            {
                return(false);
            }

            if (this.moveActionData.pathingResult == null)
            {
                this.moveActionData.pathingResult = this.pathNetwork.FindPath(
                    this.selectedTile,
                    tile
                    );
            }
            if (this.moveActionData.pathingResult.Value.isValid == false)
            {
                return(false);
            }

            BattleMech mech         = this.selectedTile.mech;
            var        apCostResult = mech.GetAPCostForMove(this.moveActionData.pathingResult.Value.nodes);
            if (apCostResult.isValid == false)
            {
                return(false);
            }

            return(true);
        }
        else if (this.state == BattleState.SetTargetAction)
        {
            return(
                tile != null &&
                tile.mech != null &&
                tile != this.selectedTile &&
                this.CanTeamSeeTile(this.selectedTile.mech.team, tile)
                );
        }
        else
        {
            return(false);
        }
    }
Пример #2
0
    // Note: this will be used for replays and maybe save files, so only use data from the move data
    // and the current state of the map.
    // Hmmmm, this is starting to seem very independent from the rest of this file.
    public void ExecuteMove(object o)
    {
        if (o.GetType() == typeof(BattleMove.Move))
        {
            var move = (BattleMove.Move)o;

            Assert.IsTrue(
                this.GetTile(move.mechIndex).mech != null &&
                this.GetTile(move.newIndex).mech == null &&
                (move.isFiring == false || this.GetTile(move.targetMechIndex).mech != null)
                );

            BattleMech mech       = this.GetTile(move.mechIndex).mech;
            BattleMech targetMech = move.isFiring ? this.GetTile(move.targetMechIndex).mech : null;
            BattleTile fromTile   = mech.tile;
            BattleTile toTile     = this.GetTile(move.newIndex);

            this.pathNetwork.SetNodeEnabled(fromTile, true);

            PathingResult result = this.pathNetwork.FindPath(fromTile, toTile);
            Assert.IsTrue(result.isValid);

            bool       isFiring = move.isFiring;
            BattleTile prevTile = (BattleTile)result.nodes[0];
            for (int n = 1; n < result.nodes.Count; ++n)
            {
                BattleTile currentTile = (BattleTile)result.nodes[n];

                prevTile.mech    = null;
                currentTile.mech = mech;
                mech.tile        = currentTile;

                if (isFiring)
                {
                    bool canSeeTarget = this.TestLOS(currentTile, targetMech.tile);
                    if (canSeeTarget)
                    {
                        this.MechAttack(mech, targetMech);
                        if (targetMech.isDestroyed)
                        {
                            isFiring = false;
                        }
                    }
                }

                prevTile = currentTile;
            }

            mech.PlaceAtMapTile(toTile.mapTile);

            BattleTile    lastTile1 = (BattleTile)result.nodes[result.nodes.Count - 2];
            BattleTile    lastTile2 = (BattleTile)result.nodes[result.nodes.Count - 1];
            bool          right     = lastTile2.transform.position.x > lastTile1.transform.position.x;
            MechDirection newDir    = right ? MechDirection.Right : MechDirection.Left;
            mech.SetDirection(newDir);

            var apCostResult = mech.GetAPCostForMove(result.nodes);
            Assert.IsTrue(mech.actionPoints > 0);
            mech.actionPoints -= apCostResult.ap;

            this.pathNetwork.SetNodeEnabled(toTile, false);

            this.UpdateFogOfWar();
        }
        else if (o.GetType() == typeof(BattleMove.StandingFire))
        {
            var move = (BattleMove.StandingFire)o;

            Assert.IsTrue(
                this.GetTile(move.mechIndex).mech != null &&
                this.GetTile(move.targetMechIndex).mech != null
                );

            BattleMech mech       = this.GetTile(move.mechIndex).mech;
            BattleMech targetMech = this.GetTile(move.targetMechIndex).mech;

            this.MechAttack(mech, targetMech);

            var apCostResult = mech.GetAPCostForStandingFire();
            mech.actionPoints -= apCostResult.ap;
        }
        else if (o.GetType() == typeof(BattleMove.SetTarget))
        {
            var move = (BattleMove.SetTarget)o;

            Assert.IsTrue(
                this.GetTile(move.mechIndex).mech != null &&
                (move.hasTarget == false || this.GetTile(move.targetMechIndex).mech != null)
                );

            BattleMech mech = this.GetTile(move.mechIndex).mech;

            if (move.hasTarget)
            {
                mech.target = this.GetTile(move.targetMechIndex).mech;
            }
            else
            {
                mech.target = null;
            }
        }
        else
        {
            throw new UnityException();
        }

        // Add to battle history.
        this.history.moves.Add(o);

        // Determine if this team's turn is over so we can advance the turn.
        bool hasAP = false;

        foreach (BattleMech mech in this.currentTeam.mechs)
        {
            if (mech.actionPoints > 0)
            {
                hasAP = true;
                break;
            }
        }
        if (hasAP == false)
        {
            this.AdvanceTurn();
        }
    }