Esempio n. 1
0
    public void manageTroop()
    {
        GameObject unitGO = allyTroops[getTroopsToManageCount() - 1];

        if (isUnit(unitGO))
        {
            Unit unitScript = unitGO.GetComponent <Unit>();

            if (unitScript.isTroop()) // Is a Troop
            {
                //Debug.Log("IS TROOP :: : : ");
                TroopScript troop       = unitGO.GetComponent <TroopScript>();
                bool        targetFound = false;
                if (enemyTroopsAlive())
                {
                    foreach (GameObject enemyGO in unitScript.getClosestEnemyTroopWithoutUpdate())
                    {
                        Debug.Log("Behaviour Tree closestEnemy Troop Count " + unitScript.getClosestEnemyTroopWithoutUpdate().Count);

                        Unit enemyUnitScript = enemyGO.GetComponent <Unit>();

                        if ((enemyUnitScript.CurrentTroopClass == sb.getMatchups()[unitScript.CurrentTroopClass]) || (enemyUnitScript.CurrentTroopClass == TroopClass.Gatherer))
                        {
                            troop.moveToGoal(enemyGO);
                            targetFound = true;
                            Task.current.Succeed();
                            break;
                        }
                    }
                    if (targetFound == false)
                    {
                        troop.moveToGoal(unitScript.EnemySpawner.gameObject);
                        Task.current.Succeed();
                    }
                }
                else
                {
                    troop.setGoal(unitScript.EnemySpawner.gameObject);
                    Task.current.Succeed();
                }
            }
            else if (unitScript.isGatherer()) // is a Gatherer
            {
                //GatherersAI gatherer = unitGO.GetComponent<GatherersAI>();
                //if (gatherer.closestResources.First().gameObject != null)
                //{
                //    gatherer.setGoal(gatherer.closestResources.First().gameObject);
                Task.current.Succeed();

                //}
                //else Task.current.Fail();
            }
            else
            {
                Debug.Log("Error in managing troops");
                Task.current.Fail();
            }
            decreaseTroopsLeftToManage();
        }
        else
        {
            Debug.Log("Non unit in allyTroops list");
            Task.current.Fail();
        }
    }