Esempio n. 1
0
    EnemyDecision FindBestAttackAt(Vector3Int move)
    {
        UnitTracker       ut = GetComponent <UnitTracker>();
        List <Vector3Int> possibleAttacks = ut.PossibleAttacksAtTile(move);
        Vector3Int        bestAttack      = new Vector3Int(-1, -1, -1);
        float             bestRating      = 0;
        bool freeAttackFound = false;

        foreach (Vector3Int attack in possibleAttacks)
        {
            if (TileManager.instance.allUnits.ContainsKey(attack) && TileManager.instance.allUnits[attack].tag != tag)
            {
                GameObject       target = TileManager.instance.allUnits[attack];
                BattleSimulation battle = new BattleSimulation(gameObject, target, move, target.GetComponent <UnitTracker>().GetLocation());

                if (!freeAttackFound && battle.GetDefenderAttacks() == 0)
                {
                    freeAttackFound = true;
                    bestRating      = CalculateRating(battle);
                    bestAttack      = attack;
                }
                else if (!freeAttackFound && battle.GetDefenderAttacks() != 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestAttack = attack;
                    }
                }
                else if (battle.GetDefenderAttacks() == 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestAttack = attack;
                    }
                }
            }
        }

        return(new EnemyDecision(bestAttack));
    }
Esempio n. 2
0
    Vector3Int WhereToAttack(List <Vector3Int> possibleAttackMoves, GameObject target)
    {
        Vector3Int bestMove        = new Vector3Int(-1, -1, -1);
        float      bestRating      = 0;
        bool       freeAttackFound = false;

        foreach (Vector3Int move in possibleAttackMoves)
        {
            BattleSimulation battle = new BattleSimulation(gameObject, target, move, target.GetComponent <UnitTracker>().GetLocation());
            if (!TileManager.instance.allUnits.ContainsKey(move))
            {
                if (!freeAttackFound && battle.GetDefenderAttacks() == 0)
                {
                    freeAttackFound = true;
                    bestRating      = CalculateRating(battle);
                    bestMove        = move;
                }
                else if (!freeAttackFound && battle.GetDefenderAttacks() != 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestMove   = move;
                    }
                }
                else if (battle.GetDefenderAttacks() == 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestMove   = move;
                    }
                }
            }
        }

        return(bestMove);
    }
Esempio n. 3
0
    EnemyDecision FindBestMoveAttack(List <Vector3Int> possibleMoves)
    {
        UnitTracker ut = GetComponent <UnitTracker>();

        if (possibleMoves.Count == 0)
        {
            return(FindBestAttackAt(ut.GetLocation()));
        }

        Vector3Int bestMove        = new Vector3Int(-1, -1, -1);
        Vector3Int bestAttack      = new Vector3Int(-1, -1, -1);
        float      bestRating      = 0;
        bool       freeAttackFound = false;

        foreach (Vector3Int move in possibleMoves)                                                                         //Loop through every possible move a character can make
        {
            foreach (Vector3Int attack in ut.PossibleAttacksAtTile(move))                                                  //Loop through every possible attack at each move
            {
                if (TileManager.instance.allUnits.ContainsKey(attack) && TileManager.instance.allUnits[attack].tag != tag) //Check to see if there is an attackable unit
                {
                    GameObject       target = TileManager.instance.allUnits[attack];
                    BattleSimulation battle = new BattleSimulation(gameObject, target, move, target.GetComponent <UnitTracker>().GetLocation());
                    if (!TileManager.instance.allUnits.ContainsKey(move))
                    {
                        if (!freeAttackFound && battle.GetDefenderAttacks() == 0)
                        {
                            freeAttackFound = true;
                            bestRating      = CalculateRating(battle);
                            bestMove        = move;
                            bestAttack      = attack;
                        }
                        else if (!freeAttackFound && battle.GetDefenderAttacks() != 0)
                        {
                            float tempRating = CalculateRating(battle);
                            if (tempRating > bestRating)
                            {
                                bestRating = tempRating;
                                bestMove   = move;
                                bestAttack = attack;
                            }
                        }
                        else if (battle.GetDefenderAttacks() == 0)
                        {
                            float tempRating = CalculateRating(battle);
                            if (tempRating > bestRating)
                            {
                                bestRating = tempRating;
                                bestMove   = move;
                                bestAttack = attack;
                            }
                        }
                    }
                }
            }
        }

        if (bestMove.z == -1 && bestAttack.z == -1)
        {
            return(new EnemyDecision());
        }
        List <Vector3Int> path = ShortestPath.instance.FindPath(gameObject.GetComponent <UnitTracker>().GetLocation(), bestMove, "Red");

        return(new EnemyDecision(path, bestAttack));
    }
Esempio n. 4
0
    IEnumerator Combat(GameObject attacker, GameObject defender, GameObject aPanel, GameObject dPanel, int range)
    {
        attacking = true;
        int aDamage     = battle.GetAttackerDamage();
        int aAccuracy   = battle.GetAttackerAccuracy();
        int aCritDamage = battle.GetAttackerCritDamage();
        int aAttacks    = battle.GetAttackerAttacks();
        int dAttacks    = battle.GetDefenderAttacks();
        int dDamage     = battle.GetDefenderDamage();
        int dAccuracy   = battle.GetDefenderAccuracy();
        int dCritDamage = battle.GetDefenderCritDamage();


        while (attacking)
        {
            //Initiator attacks
            if (aAttacks > 0)
            {
                aAttacks--;
                attacker.GetComponent <AttackAnimations>().Strike(defender);
                if (Random.Range(0, 100) < aAccuracy)
                {
                    print(attacker.name + " will deal " + aDamage + " - " + (aDamage + aCritDamage) + " damage!");
                    //Regular hit
                    int damageDealt = CalculateDamage(aDamage, aCritDamage);
                    print("Hit! " + attacker.name + " dealt " + damageDealt + " damage to " + defender.name + "!");
                    DamageVFX(attacker, defender);
                    SoundEffectsManager.instance.PlayStrike();
                    defender.GetComponent <CharacterStats>().TakeDamage(damageDealt);
                    dPanel.GetComponent <CombatPanel>().DeductHealth(damageDealt, defender.GetComponent <CharacterStats>().GetMaxHealth());
                }
                else
                {
                    //Miss...
                    StartCoroutine(MissVFX(defender));
                    SoundEffectsManager.instance.PlayMiss();
                    print(attacker.name + " missed!");
                }

                yield return(new WaitForSeconds(1));

                //Check if the defender died to the attacker's strike
                if (defender.GetComponent <CharacterStats>().GetHealth() == 0)
                {
                    defender.GetComponent <UnitTracker>().Die();
                    break;
                }
            }


            //Defender attacks, if they can
            if (dAttacks > 0)
            {
                dAttacks--;
                defender.GetComponent <AttackAnimations>().Strike(attacker);
                if (Random.Range(0, 100) < dAccuracy)
                {
                    print(attacker.name + " will deal " + dDamage + " - " + (dDamage + dCritDamage) + " damage!");
                    //Regular hit
                    int damageDealt = CalculateDamage(dDamage, dCritDamage);
                    print("Hit! " + defender.name + " dealt " + dDamage + " damage to " + attacker.name + "!");
                    DamageVFX(defender, attacker);
                    SoundEffectsManager.instance.PlayStrike();
                    attacker.GetComponent <CharacterStats>().TakeDamage(damageDealt);
                    aPanel.GetComponent <CombatPanel>().DeductHealth(damageDealt, defender.GetComponent <CharacterStats>().GetMaxHealth());
                }
                else
                {
                    //Miss...
                    StartCoroutine(MissVFX(attacker));
                    SoundEffectsManager.instance.PlayMiss();
                    print(defender.name + " missed!");
                }

                yield return(new WaitForSeconds(1));

                //Check if the attacker died to the defender's strike
                if (attacker.GetComponent <CharacterStats>().GetHealth() == 0)
                {
                    attacker.GetComponent <UnitTracker>().Die();
                    break;
                }
            }


            if (aAttacks == 0 && dAttacks == 0)
            {
                break;
            }
        }

        //What should happen after combat completes
        //For now, just disable the combat ui and finish the turn
        RevertToIdle(attacker, defender);
        attacking = false;
        HideBattleForecast();
        MouseControl.instance.currentState = MouseControl.MouseState.FINISHED;
    }
Esempio n. 5
0
    void ToggleCombatDetails(GameObject attacker, GameObject defender, Vector3Int playerPos, Vector3Int enemyPos)
    {
        battle = new BattleSimulation(attacker, defender, playerPos, enemyPos);

        CharacterStats a = attacker.GetComponent <CharacterStats>();
        CharacterStats d = defender.GetComponent <CharacterStats>();

        if (attacker.tag == "Blue" || attacker.tag == "Green")
        {
            PLAYERINFO.GetComponent <CombatPanel>().InitializeInfo(attacker.name, a.GetMaxHealth(), a.GetHealth(),
                                                                   a.GetWeapon(), a.GetArmor(), battle.GetAttackerDamage().ToString(),
                                                                   battle.GetAttackerAccuracy().ToString(), battle.GetAttackerCritDamage().ToString(), battle.GetAttackerAttacks());
            ENEMYINFO.GetComponent <CombatPanel>().InitializeInfo(defender.name, d.GetMaxHealth(), d.GetHealth(),
                                                                  d.GetWeapon(), d.GetArmor(), battle.GetDefenderDamage().ToString(),
                                                                  battle.GetDefenderAccuracy().ToString(), battle.GetDefenderCritDamage().ToString(), battle.GetDefenderAttacks());
        }
        else
        {
            ENEMYINFO.GetComponent <CombatPanel>().InitializeInfo(attacker.name, a.GetMaxHealth(), a.GetHealth(),
                                                                  a.GetWeapon(), a.GetArmor(), battle.GetAttackerDamage().ToString(),
                                                                  battle.GetAttackerAccuracy().ToString(), battle.GetAttackerCritDamage().ToString(), battle.GetAttackerAttacks());
            PLAYERINFO.GetComponent <CombatPanel>().InitializeInfo(defender.name, d.GetMaxHealth(), d.GetHealth(),
                                                                   d.GetWeapon(), d.GetArmor(), battle.GetDefenderDamage().ToString(),
                                                                   battle.GetDefenderAccuracy().ToString(), battle.GetDefenderCritDamage().ToString(), battle.GetDefenderAttacks());
        }
    }