Пример #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
    void ActionButtonHoverChanged(Button button, bool isEntering)
    {
        if (button == this.uiRefs.fireNowButton)
        {
            BattleMech mech = this.selectedTile.mech;

            if (isEntering)
            {
                float newAP = mech.actionPoints - mech.GetAPCostForStandingFire().ap;
                this.UpdateActionPointsPreview(newAP);
            }
            else
            {
                this.ResetActionPointsPreview();
            }
        }
    }
Пример #3
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();
        }
    }
Пример #4
0
    void UpdateRightPanel()
    {
        this.AdjustTileInfoTabButtonGraphics();

        bool hasTile = this.selectedTile != null;
        bool hasMech = hasTile && this.selectedTile.mech != null;

        hasMech = hasMech && this.CanTeamSeeTile(this.currentTeam, this.selectedTile);
        BattleMech mech = hasMech ? this.selectedTile.mech : null;

        this.uiRefs.tileInfoBorder.SetActive(hasTile);
        this.uiRefs.mechTabButton.interactable  = hasMech;
        this.uiRefs.pilotTabButton.interactable = hasMech;
        this.uiRefs.tileTabButton.interactable  = hasTile;

        this.uiRefs.tileTab.SetActive(false);
        this.uiRefs.pilotTab.SetActive(false);
        this.uiRefs.mechTab.SetActive(false);

        this.uiRefs.actionsPanel.SetActive(hasMech);

        if (hasTile)
        {
            TileData tileData = this.selectedTile.data;
            this.uiRefs.tileTabName.text        = tileData.name;
            this.uiRefs.tileTabDescription.text = tileData.description;

            if (hasMech)
            {
                this.uiRefs.mechTab.SetActive(true);
                this.uiRefs.mechTabButton.interactable = true;
                this.uiRefs.mechTabName.text           = mech.data.name;
                this.uiRefs.mechTabHP.text             = "HP: " + mech.hp + " / " + mech.data.maxHP;

                this.uiRefs.pilotTabButton.interactable = true;

                // TODO: not this
                this.TileInfoTabButtonClicked(this.uiRefs.mechTabButton);

                bool isOurTurn = mech.team == this.currentTeam;
                if (isOurTurn)
                {
                    this.uiRefs.actionsPanel.SetActive(true);
                    this.uiRefs.fireAutoToggle.isOn = mech.fireAuto;

                    this.ResetActionPointsPreview();

                    if (mech.target)
                    {
                        bool canSeeTarget = this.TestLOS(mech.tile, mech.target.tile);
                        if (canSeeTarget)
                        {
                            this.uiRefs.fireNowButton.interactable = mech.GetAPCostForStandingFire().isValid;
                        }
                        else
                        {
                            this.uiRefs.fireNowButton.interactable = false;
                        }
                    }
                    else
                    {
                        this.uiRefs.fireNowButton.interactable = false;
                    }
                }
                else
                {
                    this.uiRefs.actionsPanel.SetActive(false);
                }
            }
            else
            {
                this.uiRefs.tileTab.SetActive(true);

                this.TileInfoTabButtonClicked(this.uiRefs.tileTabButton);
            }
        }
    }