コード例 #1
0
    void ActionButtonPressed(Button button)
    {
        if (button == this.uiRefs.moveButton)
        {
            this.SetState(BattleState.MoveAction);
        }
        else if (button == this.uiRefs.setTargetButton)
        {
            this.SetState(BattleState.SetTargetAction);
        }
        else if (button == this.uiRefs.fireNowButton)
        {
            BattleMech mech = this.selectedTile.mech;

            var move = new BattleMove.StandingFire();
            move.mechIndex       = mech.tile.index;
            move.targetMechIndex = mech.target.tile.index;
            this.ExecuteMove(move);

            this.UpdateRightPanel();
            this.UpdateTargetTile(mech);

            if (mech.target)
            {
                float newAP = mech.actionPoints - mech.GetAPCostForStandingFire().ap;
                this.UpdateActionPointsPreview(newAP);
            }
            this.SetState(BattleState.EndOfAction);
        }
    }
コード例 #2
0
    public void Update()
    {
        // Test: path to a target mech, stop when we can see it and keep firing.
        BattleMech target = null;

        foreach (BattleTeam team in this.battle.teams)
        {
            foreach (BattleMech mech in team.mechs)
            {
                if (team != this.ourMech.team)
                {
                    target = mech;
                    break;
                }
            }
        }

        if (target == null)
        {
            return;
        }

        BattleTile ourTile    = this.ourMech.tile;
        BattleTile targetTile = target.tile;

        bool canSeeTarget = this.battle.TestLOS(ourTile, targetTile);

        // TODO: this is really stupid
        this.battle.pathNetwork.SetNodeEnabled(ourTile, true);
        this.battle.pathNetwork.SetNodeEnabled(targetTile, true);
        PathingResult result = this.battle.pathNetwork.FindPath(ourTile, targetTile);

        this.battle.pathNetwork.SetNodeEnabled(ourTile, false);
        this.battle.pathNetwork.SetNodeEnabled(targetTile, false);

        if (result.isValid == false)
        {
            return;
        }

        BattleTile nextTile = (BattleTile)result.nodes[1];

        if (canSeeTarget && result.distance <= 5)
        {
            var move = new BattleMove.StandingFire();
            move.mechIndex       = ourTile.index;
            move.targetMechIndex = targetTile.index;
            this.battle.ExecuteMove(move);
        }
        else
        {
            var move = new BattleMove.Move();
            move.mechIndex = ourTile.index;
            move.newIndex  = nextTile.index;
            if (canSeeTarget)
            {
                move.isFiring        = true;
                move.targetMechIndex = targetTile.index;
            }
            else
            {
                move.isFiring = false;
            }
            this.battle.ExecuteMove(move);
        }

        this.battle.SetState(BattleState.EndOfAction);
    }