Ejemplo n.º 1
0
    void Update()
    {
        UpdateHUD();
        //Deselect units on enemy turn
        if (!playerTurn && selectedUnit != null)
        {
            DeselectAllUnits();
        }

        if (playerTurn && mapConfig.stateController.CheckCurrentState(StateController.GameState.TacticalMode) && EnemyTargeting == false)
        {
            //Select next unit
            if (Input.GetKeyDown(nextTarget) && selectedUnit.CheckUnitState(UnitConfig.UnitState.Idle))
            {
                KeyboardSelect(true, playerUnits, selectedUnit);
            }
            //Select previous unit
            else if (Input.GetKeyDown(previousTarget) && selectedUnit.CheckUnitState(UnitConfig.UnitState.Idle))
            {
                KeyboardSelect(false, playerUnits, selectedUnit);
            }
        }


        if (playerTurn && mapConfig.stateController.CheckCurrentState(StateController.GameState.AttackMode))
        {
            //Select next enemy unit
            if (Input.GetKeyDown(nextTarget))
            {
                if (EnemyTargeting)
                {
                    KeyboardSelect(true, enemyUnits, selectedTarget);
                }
                else
                {
                    KeyboardSelect(true, playerUnits, selectedTarget);
                }
            }
            //Select previous enemy unit
            if (Input.GetKeyDown(previousTarget))
            {
                if (EnemyTargeting)
                {
                    KeyboardSelect(false, enemyUnits, selectedTarget);
                }
                else
                {
                    KeyboardSelect(false, playerUnits, selectedTarget);
                }
            }
        }
        //Use mouse to target player units
        if (Input.GetMouseButtonDown(0) && playerTurn)
        {
            MouseSelect();
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        //Rotate health UI to camera rotation
        transform.GetChild(0).localEulerAngles = new Vector3(0, Camera.main.transform.root.GetChild(0).rotation.eulerAngles.y, 0);

        //HACK: AI Movement?
        if (isMyTurn && !mapConfig.turnSystem.playerTurn && unitConfig.actionPoints.CheckAvailableActions(unitConfig.unitClassStats.moveCost) && unitConfig.CheckUnitState(UnitConfig.UnitState.Idle))
        {
            int currentActions = unitConfig.actionPoints.ReturnAvailableActions();
            foreach (UnitConfig unit in unitConfig.mapConfig.turnSystem.playerUnits)
            {
                IsPlayerNextToMe(unit.tileX, unit.tileY);
                if (isAttacking)
                {
                    break;
                }
            }

            if (!isAttacking)
            {
                FindClosestPlayerUnit();
            }

            unitConfig.EnemyMoveNextTile();
            if (currentActions == unitConfig.actionPoints.ReturnAvailableActions())
            {
                unitConfig.actionPoints.SubtractAllActions();
            }
        }
        if (isMyTurn && !unitConfig.actionPoints.CheckAvailableActions(1) && unitConfig.CheckUnitState(UnitConfig.UnitState.Idle))
        {
            if (mapConfig.turnSystem.enemyUnits.Count > mapConfig.turnSystem.enemyIndex)
            {
                isAttacking = false;
                isMyTurn    = false;
                mapConfig.turnSystem.StartNextEnemy();
            }
        }
    }
Ejemplo n.º 3
0
 public void SelectUnit(UnitConfig selected)
 {
     if (selected == null)
     {
         return;
     }
     if (!selected.CheckUnitState(UnitConfig.UnitState.Idle))
     {
         return;
     }
     if (selected.isFriendly)
     {
         selectedUnit = selected;
         //selected = selectedUnit;
         selectedUnit.isSelected = true;
         //Move the marker to selected unit
         MoveMarker(unitMarker, selectedUnit.transform.position);
         //Update grid colors
         mapConfig.tileMap.ChangeGridColor(selected.movePoints, selected.actionPoints.ReturnAvailableActions(), selected);
         //Update Displayed Name
         unitName.text  = selectedUnit.unitName;
         className.text = selectedUnit.unitClassStats.unitClassName;
         UpdateHUD();
         //Clear old abilities
         generateAbilityButtons.ClearCurrentButtons();
         //Generate new abilities buttons if its a player unit
         generateAbilityButtons.GenerateCurrentButtons(selectedUnit.unitAbilities);
         //Move the camera to selected Unit/target
         cameraControl.MoveToTarget(selectedUnit.transform.position);
     }
     if (!selected.isFriendly)
     {
         //HACK: If you're targeting an enemy, what do?
         selectedTarget = selected;
         //Move the camera to selected Unit/target
         cameraControl.MoveToTarget(selectedTarget.transform.position);
     }
 }
Ejemplo n.º 4
0
 void Update()
 {
     if (animator != null)
     {
         if (unitConfig.CheckUnitState(UnitConfig.UnitState.Idle))
         {
             animator.SetInteger("state", 0);
         }
         if (unitConfig.CheckUnitState(UnitConfig.UnitState.Walking))
         {
             animator.SetInteger("state", 1);
         }
         if (unitConfig.CheckUnitState(UnitConfig.UnitState.Sprinting))
         {
             animator.SetInteger("state", 2);
         }
         if (unitConfig.CheckUnitState(UnitConfig.UnitState.Shooting))
         {
             animator.SetInteger("state", 3);
             if (target == null)
             {
                 if (TurnSystem.selectedUnit == TurnSystem.selectedTarget)
                 {
                     target = TurnSystem.selectedUnit;
                 }
                 else
                 {
                     target = TurnSystem.selectedTarget;
                 }
             }
             if (target != null)
             {
                 transform.parent.LookAt(target.transform.position);
                 Vector3 eulerAngles = transform.parent.rotation.eulerAngles;
                 eulerAngles.x = 0;
                 eulerAngles.z = 0;
                 // Set the altered rotation back
                 transform.parent.rotation = Quaternion.Euler(eulerAngles);
             }
         }
         //Death animation
         if ((unitConfig.CheckUnitState(UnitConfig.UnitState.Dead)))
         {
             animator.SetInteger("state", 4);
         }
         //walking rotation
         if (animator.GetInteger("state") > 0 && animator.GetInteger("state") != 3) // HACK: What!?
         {
             direction    = transform.root.position - lastPosition;
             lastPosition = transform.root.position;
             lookRotation = Quaternion.LookRotation((direction == Vector3.zero) ? Vector3.forward : direction);
             transform.parent.rotation = Quaternion.Lerp(transform.parent.rotation, lookRotation, Time.deltaTime * 10);
         }
         else if (animator.GetInteger("state") != 3)
         {
             Quaternion a = transform.parent.rotation;
             Quaternion b = Quaternion.LookRotation((direction == Vector3.zero) ? Vector3.forward : direction);
             transform.parent.rotation = Quaternion.Lerp(a, b, Time.deltaTime * 10);
         }
     }
 }
Ejemplo n.º 5
0
    //Cycle through list of targets
    public void KeyboardSelect(bool ChooseNext, List <UnitConfig> unitList, UnitConfig selected)
    {
        //Check if unit is idle
        if (selected != null && !selected.CheckUnitState(UnitConfig.UnitState.Idle))
        {
            return;
        }
        //if list is empty, exit function
        if (unitList == null)
        {
            return;
        }
        //If selected is null, pick the first unit in the list
        if (selected == null)
        {
            selected = unitList[0];
        }
        int chosenUnitIndex = unitList.FindIndex(a => a == selected);

        DeselectUnit(selected);

        if (selected.isFriendly)
        {
            //Check if any friendly units have actions left
            //Makes sure you can't target anything at the end of your turn
            bool UnitHasActionsLeft = false;
            foreach (UnitConfig unit in unitList)
            {
                if (unit.actionPoints.CheckAvailableActions(1))
                {
                    UnitHasActionsLeft = true;
                    break;
                }
            }
            if (UnitHasActionsLeft == false)
            {
                return;
            }
        }
        //After all the checks are done, we can start choosing a target
        for (int i = 0; i < unitList.Count; i++)
        {
            //loops around the list
            //Go up the list
            if (ChooseNext)
            {
                chosenUnitIndex++;
            }
            //Go down the list
            else if (!ChooseNext)
            {
                chosenUnitIndex--;
            }
            //If its too high, loop around
            if (chosenUnitIndex >= unitList.Count)
            {
                chosenUnitIndex = 0;
            }
            //If its too low, loop around
            else if (chosenUnitIndex < 0)
            {
                chosenUnitIndex = unitList.Count - 1;
            }
            //Check if enemy unit is targetable
            if (!unitList[chosenUnitIndex].isFriendly && !selected.CheckUnitState(UnitConfig.UnitState.Dead))
            {
                selected       = unitList[chosenUnitIndex];
                selectedTarget = selected;
                selectedUnit.GetAccuracy(selectedTarget.tileX, selectedTarget.tileY);
                if (!selected.isFriendly && playerTurn)
                {
                    //HACK: Hard coded, fix for multiple abilities
                    generateAbilityButtons.abilityName.text        = selectedUnit.unitAbilities.abilities[0].abilityName;
                    generateAbilityButtons.abilityChanceToHit.text = "Chance to hit: " + UnitConfig.accuracy + "%";
                    generateAbilityButtons.abilityTooltip.text     = selectedUnit.unitAbilities.abilities[0].tooltip;
                    //HACK: quick calculations
                    int minDamage = selectedUnit.unitWeapon.baseDamage + selectedUnit.unitWeapon.numberOfDiceDamage;
                    int maxDamage = selectedUnit.unitWeapon.baseDamage + selectedUnit.unitWeapon.numberOfDiceDamage * selectedUnit.unitWeapon.numberOfSidesDamage;
                    generateAbilityButtons.abilityEffect.text = minDamage + " - " + maxDamage + " Damage";
                }

                break;
            }
            if (unitList[chosenUnitIndex].isFriendly && unitList[chosenUnitIndex].actionPoints.CheckAvailableActions(1))
            {
                selected     = unitList[chosenUnitIndex];
                selectedUnit = selected;
                break;
            }
        }

        //Select the next/previous unit
        SelectUnit(selected);
    }