Exemplo n.º 1
0
 public bool IsUsableNowBase()
 {
     return
         (IsUsableNow() &&
          (UsesLeft > 0 || LimitedUses == false) &&
          myEnergy.IsEnoughEnergyFor(this) &&
          TurnManager.Instance.PlayerHavingTurn == myUnit.PlayerID &&
          AlreadyUsedThisTurn == false &&
          GameStateManager.Instance.IsItPreGame() == false &&
          LegalInPhases.Contains(TurnManager.Instance.CurrentPhase) &&
          (!OnlyInCombat || (OnlyInCombat && myUnit.CheckIfIsInCombat())) &&
          (!UnavailableInCombat || (UnavailableInCombat && !myUnit.CheckIfIsInCombat())) &&
          (!RequiresCanMove || (RequiresCanMove && myUnit.GetComponent <UnitMovement>().CanMove)) &&
          (!RequiresShootingAbility || (RequiresShootingAbility && myUnit.GetComponent <ShootingScript>().IsAbleToShoot())) &&
          (!IsAttack || (IsAttack && myUnit.hasAttacked == false)));
 }
Exemplo n.º 2
0
 public bool PossibleToShootAt(UnitScript target, bool isCursor)
 {
     if (Application.isEditor && Input.GetMouseButton(0) && Input.GetKey(KeyCode.LeftShift))
     {
         Debug.Log(!theUnit.CheckIfIsInCombat() + "," + target != null + "," + IsTargetInRange(target.transform.position) + "," + CanShoot + "," + (GameStateManager.Instance.GameState == GameStates.ShootingState));
     }
     return(
         MouseManager.Instance.SelectedUnit != null &&
         MouseManager.Instance.SelectedUnit == theUnit &&
         !theUnit.CheckIfIsInCombat() && target != null &&
         target != null && target.PlayerID != MouseManager.Instance.SelectedUnit.PlayerID &&
         IsTargetInRange(target.transform.position) &&
         CanShoot &&
         GameStateManager.Instance.GameState == GameStates.ShootingState &&
         theUnit.PlayerID == TurnManager.Instance.PlayerHavingTurn &&
         IsInLineOfSight(transform.position, target.transform.position, isCursor)
         );
 }
Exemplo n.º 3
0
 private void Update()
 {
     if (US.isRealUnit)
     {
         SetInCombat(US.CheckIfIsInCombat());
         AnimateWalking(UM.isMoving);
     }
     if (isHit)
     {
         isHit = false;
         AnimateWound();
     }
 }
Exemplo n.º 4
0
 void OnNewTurn()
 {
     if (TurnManager.Instance.TurnCount > 2 && TurnManager.Instance.PlayerHavingTurn == me.PlayerID)
     {
         CurrentEnergy += EnergyPerTurn;
         if (me.CheckIfIsInCombat() == false)
         {
             CurrentEnergy += EnergyPerTurn;
         }
         if (CurrentEnergy >= MaxEnergy)
         {
             CurrentEnergy = MaxEnergy;
         }
     }
 }
Exemplo n.º 5
0
    void SetMovementRelatedData(UnitMovement unitMovement)
    {
        unitMovement.isMoving = false;

        UnitScript unitScript = unitMovement.GetComponent <UnitScript>();

        if (unitScript.CheckIfIsInCombat())
        {
            unitScript.hasJustArrivedToCombat = true;
        }
        if (unitScript.isQuittingCombat)
        {
            unitScript.isQuittingCombat = false;
        }
    }
Exemplo n.º 6
0
 public bool CanUnitActInThisPhase(UnitScript unit)
 {
     if (TurnManager.Instance.CurrentPhase == TurnPhases.Movement)
     {
         return(unit.GetComponent <UnitMovement>().CanMove);
     }
     if (TurnManager.Instance.CurrentPhase == TurnPhases.Shooting)
     {
         return(unit.GetComponent <ShootingScript>() != null && unit.GetComponent <ShootingScript>().CanShoot);
     }
     if (TurnManager.Instance.CurrentPhase == TurnPhases.Attack)
     {
         return(unit.CheckIfIsInCombat() && unit.hasAttacked == false && unit.CanAttack);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
 bool CanQuitCombat(UnitScript unit)
 {
     if (
         unit.CheckIfIsInCombat() &&
         IsItTimeToMove(unit) &&
         unit.GetComponent <UnitMovement>().CanMove&&
         IsThisTileLegal(MouseManager.Instance.mouseoveredTile, unit.GetComponent <UnitMovement>(), true)
         )
     {
         return(true);
     }
     else
     {
         /*Debug.Log("inCombat: " + unit.CheckIfIsInCombat());
          * Debug.Log("timetoMove: " + IsItTimeToMove(unit));
          * Debug.Log("canMove: " + unit.GetComponent<UnitMovement>().canMove);
          * Debug.Log("LegalTile: " + IsItALegalTileForQC(unit, MouseManager.Instance.mouseoveredTile));*/
         return(false);
     }
 }
Exemplo n.º 8
0
    protected override Queue <UnitScript> GetPossibleUnits()
    {
        Queue <UnitScript> myUnitsToMove = new Queue <UnitScript>(allyList);
        UnitScript         firstUnit     = myUnitsToMove.Peek();

        while (firstUnit.CheckIfIsInCombat() == false || unitsSkippingTurn.Contains(firstUnit) == true || firstUnit.GetComponent <UnitMovement>().CanMove == false || firstUnit.hasJustArrivedToCombat || HasAnyLegalTiles(firstUnit) == false)
        {
            myUnitsToMove.Dequeue();
            if (myUnitsToMove.Count == 0)
            {
                AI_Controller.Instance.ClearAIs();
                AI_Controller.didAllTheQCDecisionsHappen = true;
                return(null);
            }
            else
            {
                firstUnit = myUnitsToMove.Peek();
            }
        }
        return(myUnitsToMove);
    }
Exemplo n.º 9
0
    protected override Queue <UnitScript> GetPossibleUnits()
    {
        Queue <UnitScript> myUnitsToMove = new Queue <UnitScript>(allyList);
        UnitScript         firstUnit     = myUnitsToMove.Peek();

        while (firstUnit.CheckIfIsInCombat() == false || firstUnit.hasAttacked == true)
        {
            myUnitsToMove.Dequeue();
            if (myUnitsToMove.Count == 0)
            {
                AI_Controller.Instance.ClearAIs();
                GameStateManager.NextPhase();
                return(null);
            }
            else
            {
                firstUnit = myUnitsToMove.Peek();
            }
        }
        return(myUnitsToMove);
    }
Exemplo n.º 10
0
    protected override Queue <UnitScript> GetPossibleUnits()
    {
        Queue <UnitScript> myUnitsToMove = new Queue <UnitScript>(allyList);
        UnitScript         firstUnit     = myUnitsToMove.Peek();
        ShootingScript     shooter       = firstUnit.GetComponent <ShootingScript>();

        while (shooter == null || shooter.CanShoot == false || firstUnit.CheckIfIsInCombat() == true)
        {
            myUnitsToMove.Dequeue();

            if (myUnitsToMove.Count == 0)
            {
                GameStateManager.NextPhase();
                return(null);
            }
            else
            {
                firstUnit = myUnitsToMove.Peek();
                shooter   = firstUnit.GetComponent <ShootingScript>();
            }
        }
        return(myUnitsToMove);
    }
Exemplo n.º 11
0
    public override float EvaluateTile(UnitScript currentUnit, Tile tile, int enemiesDirection, Dictionary <UnitMovement, List <Tile> > EnemyMovementRanges)
    {
        float Evaluation = 0f;
        //First, i want to introduce simple evaluation concepts. No tricks and special stuff, only very basic basics.

        // Lets check, if WE are a SHOOTER or a HERO. If yes, we will want to act totally diferently than the rest.

        // THEN if we are a HERO, lets stay in the second line. Lets defend shooters, cause currently we dont have MAGES yet, they will act differently. Lets not want to attack THAT much and lets REALLY not want to get hit. Lets stay close to friends, too!

        // If we are a shooter, lets first not want to get to combat. Lets try to get into shooting position. Lets try REALLY hard not to get hit.

        // SHOOTERS DONT want to stay next to other shooters. Obviously.

        // If we are NEITHER, lets try to first attack if good situation (prio on hero and shooters). Then lets try to protecc shooters and heroes. Also, bonus points for staying together (not only for real purpose, also cause it looks much more pro for player's eyes).
        List <Tile> neighbours = tile.GetNeighbours();

        if (currentUnit.GetComponent <HeroScript>() != null)
        {
            // we ARE a hero.
            // 1. stay close to friends
            // 2. defend shooterz
            // 3. away from enemies
            // 4. attack (especially when singe enemy, weaker, shooter).

            for (int i = 0; i < neighbours.Count; i++)
            {
                if (neighbours[i].myUnit != null && neighbours[i].myUnit.PlayerID == currentUnit.PlayerID && neighbours[i].myUnit != currentUnit)
                {
                    // there is an ally on next tile. Give like +0.1f for it.
                    Evaluation += 0.1f;
                    //  Debug.Log("I: " + i + " Tile: " + tile.transform.position.x + " " + tile.transform.position.z + " Added 0.1 for ally on tile: " + tile.neighbours[i]);
                    if (neighbours[i].myUnit.isRanged && IsDefendingAllyIfStandingHere(tile.transform.position, neighbours[i].myUnit.transform.position, enemiesDirection))
                    {
                        //   Debug.Log("Added 0.1 for shooter: " + tile.neighbours[i].myUnit);
                        Evaluation += 0.2f;
                        foreach (UnitScript uniterino in neighbours[i].myUnit.AllyList)
                        {
                            if (uniterino.isRanged == false && IsDefendingAllyIfStandingHere(uniterino.transform.position, neighbours[i].myUnit.transform.position, enemiesDirection))
                            {
                                // someone already defends this unit, lets deduct like 0.05f for it..
                                Evaluation -= 0.05f;
                            }
                        }
                    }
                    else if (neighbours[i].myUnit.isRanged == false && IsDefendingAllyIfStandingHere(neighbours[i].myUnit.transform.position, tile.transform.position, enemiesDirection))
                    {
                        Evaluation += 0.1f;
                    }
                }
            }



            int enemiesInRange = 0;

            foreach (var enemy in EnemyMovementRanges)
            {
                if (enemy.Value.Contains(tile))
                {
                    float hate = CheckHowMuchIHateToBeAttackedByThisUnit(currentUnit, enemy.Key.GetComponent <UnitScript>());
                    Evaluation -= hate;
                    if (hate > 0)
                    {
                        //   Debug.Log("Tile: " + tile + "'s evaluation got lowered by: " + hate + " because of: " + enemy.Key.gameObject);
                    }
                    enemiesInRange++;
                }
            }

            if (enemiesInRange > 2)
            {
                Evaluation -= enemiesInRange * 0.15f;
                //  Debug.Log("Tile: " + tile + "'s evaluation got lowered by: " + enemiesInRange * 0.1f + " because of " + enemiesInRange + " enemies in range of the tile.");
            }



            if (tile.IsOccupiedByEnemy(ID))
            {
                // Here the hero is attacking an enemy. He will like it, if a) there is only one enemy b) enemy is low on HP c) enemy is shooter. He will not like it, if enemies are 3+, if they are strong and full health etc.

                Evaluation = EvaluateCombatTile(currentUnit, tile, Evaluation);
            }
        }
        else if (currentUnit.GetComponent <ShootingScript>() != null)
        {
            // we ARE shooter.
            // 1. we DONT want to stay close to other shooters
            // 2. we dont want to get attacked
            // 3. we absolutely do not want to get into melee combat like EVER?
            // 4. we want to find the best shooting target and we want to have him in range - especially in "good" range if possibru
            float penaltyForNearbyShooters = 0;
            for (int i = 0; i < neighbours.Count; i++)
            {
                if (neighbours[i].myUnit != null && neighbours[i].myUnit.PlayerID == currentUnit.PlayerID && neighbours[i].myUnit != currentUnit && neighbours[i].myUnit.isRanged)
                {
                    // there is an allied SHOOTER on next tile. Give like -0.2f for it. We do not really like this type of positions.
                    penaltyForNearbyShooters -= 0.4f;
                    // Debug.Log(" Tile: " + tile.transform.position.x + " " + tile.transform.position.z + " Subtracted 0.2 for allied shooter on tile: " + tile.neighbours[i]);
                }
            }
            Evaluation += penaltyForNearbyShooters;

            /*int enemiesInRange = 0;
             * float penaltyForEnemiesInRange = 0;
             *
             * foreach (var enemy in EnemyMovementRanges)
             * {
             *  enemiesInRange++;
             * }
             *
             * if (enemiesInRange > 2)
             * {
             *  penaltyForEnemiesInRange -= enemiesInRange * 0.03f;
             *  // Debug.Log("Tile: " + tile + "'s evaluation got lowered by: " + enemiesInRange * 0.1f + " because of " + enemiesInRange + " enemies in range of the tile.");
             *  foreach (var enemy in EnemyMovementRanges)
             *  {
             *      if (enemy.Value.Contains(tile))
             *      {
             *          float hate = CheckHowMuchIHateToBeAttackedByThisUnit(currentUnit, enemy.Key.GetComponent<UnitScript>());
             *          penaltyForEnemiesInRange -= hate;
             *          if (hate > 0)
             *          {
             *              // Debug.Log("Tile: " + tile + "'s evaluation got lowered by: " + hate + " because of: " + enemy.Key.gameObject);
             *          }
             *      }
             *  }
             *
             * }
             * Evaluation += penaltyForEnemiesInRange;
             */
            if (tile.IsOccupiedByEnemy(ID))
            {
                // we are entering melee combat. Let's FOR NOW give it a -0.5f just for that. We just DO NOT want our shooters to enter melee combat right now.. Then maybe we will give some situations where it will be an OK move?

                /*if (GameStateManager.IsGreenActive() == (VictoryLossChecker.GreenScore < VictoryLossChecker.RedScore + 5))
                 * {
                 *  //we are heavily loosing, and maybe there is a heavily wounded enemy in there?
                 * }
                 *
                 * foreach (ClickableTile c**t in tile.neighbours)
                 * {
                 *  if (c**t.myUnit!= null && c**t.myUnit.GetComponent<HeroScript>() != null && c**t.myUnit.isGreen != GameStateManager.IsGreenActive())
                 *  {
                 *      //there IS an enemy hero in there AND he is heavily wounded.. We MIGHT think about getting in combat maybe?
                 *  }
                 * }*/

                Evaluation -= 5f;
            }

            //NOW LETS find the best shooting target possible! And give some value to it XD?
            float      GoodBoiBonus = 0f;
            float      NoTargetButGoodTileForFutureBonus = 0f;
            UnitScript bestTarget = ShootingAITool.FindBestTarget(currentUnit.GetComponent <ShootingScript>(), tile.transform.position, currentUnit.GetComponent <ShootingScript>().currShootingRange);
            if (bestTarget != null)
            {
                // so if the best target is not null, so it is possible to shoot at SOMEONE from the Tile being evaluated, then..
                if (ShootingScript.WouldItBePossibleToShoot(currentUnit.GetComponent <ShootingScript>(), tile.transform.position, ShootingAITool.FindBestTarget(currentUnit.GetComponent <ShootingScript>(), tile.transform.position, currentUnit.GetComponent <ShootingScript>().currShootingRange).transform.position).Value == true)
                {
                    // if it is in "bad range"
                    var temp = 0.25f + 0.5f * ShootingAITool.EvaluateAsATarget(currentUnit, bestTarget.myTile);
                    // Debug.Log("We just incremented our evaluation for tile: " + tile + " by " + temp + "for this target in bad range: " + bestTarget);
                    GoodBoiBonus += temp;
                }
                else
                {
                    // it is not "bad range"
                    var temp = 0.7f + ShootingAITool.EvaluateAsATarget(currentUnit, bestTarget.myTile);
                    // Debug.Log("We just incremented our evaluation for tile: " + tile + " by " + temp + "for this target in good range: " + bestTarget);
                    GoodBoiBonus += temp;
                }
            }
            else
            {
                // we DONT have any shooting target.. SO we have to not be a pussy and go forward. NOTE that if we wanted AI to play good we would probably build this different way :P
                // HERE i am "missusing" the function. Originally function is for checking if im "in front" of an ally in relation to "most" of the enemies. Here, I am checkign if im "in front" of.. MYSELF, if im on TheTile.
                // So i am checking if going to the Tile is moving towards enemies.
                if (IsDefendingAllyIfStandingHere(tile.transform.position, currentUnit.transform.position, enemiesDirection))
                {
                    NoTargetButGoodTileForFutureBonus += 0.1f;
                }

                // and finally here we want to get to shooting range in 2 turns. Is it good - idk, but it "feels" right xD
                UnitScript NextTurnBestTarget = ShootingAITool.FindBestTarget(currentUnit.GetComponent <ShootingScript>(), tile.transform.position, currentUnit.GetComponent <ShootingScript>().currShootingRange + currentUnit.GetComponent <UnitMovement>().GetCurrentMoveSpeed(false));
                if (NextTurnBestTarget != null)
                {
                    // we do not care if it is bad range cause we are a dumb AI
                    var temp = 0.25f + 0.25f * ShootingAITool.EvaluateAsATarget(currentUnit, NextTurnBestTarget.myTile);
                    // Debug.Log("We just incremented our evaluation for tile: " + tile + " by " + temp + "for this target in next turn range: " + bestTarget);
                    NoTargetButGoodTileForFutureBonus += temp;
                }
            }
            Evaluation += NoTargetButGoodTileForFutureBonus;
            Evaluation += GoodBoiBonus;
        }
        else
        {
            // we are MELELELEE unit. We wan to:
            // 1. FIGHT! (Much more than Hero)
            // 2. Defend shooters and hero (but less than we want to fight)
            // 3. Go "forwarderino" more likely than back.
            if (currentUnit.CheckIfIsInCombat())
            {
                // we are checking the QC.
                foreach (var enemy in currentUnit.EnemyList)
                {
                    if (enemy.isRanged)
                    {
                        Evaluation -= 10f;
                    }
                }
            }
            if (tile.IsOccupiedByEnemy(ID))
            {
                // Here the unit is attacking an enemy. For now, he "wants to fight" the same as the Hero XD. We will fine-tune it all with a UnitAIData script which will contain all the data needed for this ;)
                Evaluation = EvaluateCombatTile(currentUnit, tile, Evaluation);
            }
            for (int i = 0; i < neighbours.Count; i++)
            {
                if (neighbours[i].myUnit != null && neighbours[i].myUnit.PlayerID == currentUnit.PlayerID && neighbours[i].myUnit != currentUnit)
                {
                    // there is an ally on next tile. Give like +0.01f for it.
                    Evaluation += 0.01f;
                    //  Debug.Log("I: " + i + " Tile: " + tile.transform.position.x + " " + tile.transform.position.z + " Added 0.01 for ally on tile: " + tile.neighbours[i]);
                    if (neighbours[i].myUnit.isRanged && IsDefendingAllyIfStandingHere(tile.transform.position, neighbours[i].myUnit.transform.position, enemiesDirection))
                    {
                        //   Debug.Log("Added 0.1 for shooter: " + tile.neighbours[i].myUnit);
                        Evaluation += 0.2f;
                        foreach (UnitScript uniterino in neighbours[i].myUnit.AllyList)
                        {
                            if (uniterino.isRanged == false && uniterino.GetComponent <HeroScript>() == null && IsDefendingAllyIfStandingHere(uniterino.transform.position, neighbours[i].myUnit.transform.position, enemiesDirection))
                            {
                                // someone already defends this unit, lets deduct like 0.01f for it..
                                Evaluation -= 0.01f;
                            }
                        }
                    }
                }
            }

            // HERE i am "missusing" the function. Originally function is for checking if im "in front" of an ally in relation to "most" of the enemies. Here, I am checkign if im "in front" of.. MYSELF, if im on TheTile.
            // So i am checking if going to the Tile is moving towards enemies.
            if (IsDefendingAllyIfStandingHere(tile.transform.position, currentUnit.transform.position, enemiesDirection))
            {
                Evaluation += 0.1f;
            }
        }



        if (tile.name == "Tile_15_9")
        {
            //            Debug.Log("Right Corner's evaluation: " + Evaluation);
        }
        return(Evaluation);
    }