private void loadFaction(FileInfo factionFile)
 {
     Debug.Log("FactionsManager::loadFaction(" + factionFile + "); -- ");
     if (factionFile != null /* && !factionFile.isDirectory()*/)
     {
         try {
             string    factionFilePath = subPathToResources(factionFile.FullName);
             TextAsset textAsset       = Resources.Load <TextAsset>(factionFilePath); // Не может загрузить TextAsset с расширением tmx только xml и другое гавно!
             Debug.Log("FactionsManager::loadFaction(); -- textAsset:" + textAsset);
             if (textAsset == null)
             {
                 Debug.Log("FactionsManager::loadFaction(); -- Can't load faction:" + factionFilePath);
                 return;
             }
             XmlDocument xmlDoc = new XmlDocument();
             xmlDoc.LoadXml(textAsset.text);
             XmlElement root        = (XmlElement)xmlDoc.FirstChild.NextSibling;
             string     factionName = (root.Attributes["name"] != null)?root.Attributes["name"].Value:null;
             if (factionName != null)
             {
                 Faction     faction = new Faction(factionName);
                 XmlNodeList templateForUnitElements = root.GetElementsByTagName("templateForUnit");
                 foreach (XmlElement templateForUnitElement in templateForUnitElements)
                 {
                     string source = (templateForUnitElement.Attributes["source"] != null)?templateForUnitElement.Attributes["source"].Value:null;
                     if (source != null)
                     {
                         string          templateFile    = MapLoader.findFile(factionFilePath, source);
                         TemplateForUnit templateForUnit = new TemplateForUnit(templateFile);
                         templateForUnit.setFaction(faction);
                         templateForUnit.healthPoints = (int)(templateForUnit.healthPoints * levelOfDifficulty); // simple level of difficulty
                         faction.getTemplateForUnits().Add(templateForUnit);
                         Debug.Log("FactionsManager::loadFaction(); -- faction.getTemplateForUnits().Count:" + faction.getTemplateForUnits().Count);
                     }
                 }
                 XmlNodeList templateForTowerElements = root.GetElementsByTagName("templateForTower");
                 foreach (XmlElement templateForTowerElement in templateForTowerElements)
                 {
                     string source = (templateForTowerElement.Attributes["source"] != null)?templateForTowerElement.Attributes["source"].Value:null;
                     if (source != null)
                     {
                         string           templateFile     = MapLoader.findFile(factionFilePath, source);
                         TemplateForTower templateForTower = new TemplateForTower(templateFile);
                         templateForTower.setFaction(faction);
                         faction.getTemplateForTowers().Add(templateForTower);
                         Debug.Log("FactionsManager::loadFaction(); -- faction.getTemplateForTowers().Count:" + faction.getTemplateForTowers().Count);
                     }
                 }
                 Debug.Log("FactionsManager::loadFaction(); -- faction:" + faction);
                 factions.Add(faction);
             }
         } catch (System.Exception exp) {
             Debug.LogError("FactionsManager::loadFaction(); -- Could not load Faction! Exp:" + exp);
         }
     }
     else
     {
         Debug.LogError("FactionsManager::loadFaction(); -- Could not load Faction! (factionFile == null) or (factionFile.isDirectory() == true)");
     }
 }
Example #2
0
    public Tower createTower(Vector2Int position, TemplateForTower templateForTower, int player)
    {
        Tower tower = new Tower(position, templateForTower, player);

        towers.Add(tower);
        return(tower);
    }
    public TemplateForTower getRandomTemplateForTowerFromAllFaction()
    {
        List <TemplateForTower> allTowers = getAllTemplateForTowers();
        TemplateForTower        template  = allTowers[Random.Range(0, allTowers.Count)];

        Debug.Log("FactionsManager::getRandomTemplateForTowerFromAllFaction(); -- template" + template);
        return(template);
    }
    public TemplateForTower getRandomTemplateForTowerFromFirstFaction()
    {
        Faction faction = factions[0];

        if (faction != null)
        {
            List <TemplateForTower> templateForTowers = faction.getTemplateForTowers();
            TemplateForTower        templateForTower  = templateForTowers[Random.Range(0, templateForTowers.Count)];
            if (templateForTower != null)
            {
                return(templateForTower);
            }
        }
        return(null);
    }
Example #5
0
    public Tower(Vector2Int position, TemplateForTower templateForTower, int player)
    {
        Debug.Log("Tower::Tower(" + position + ", " + templateForTower + "); -- ");
        this.position = position;
        // this.elapsedReloadTime = templateForTower.reloadTime;
        this.templateForTower = templateForTower;

        this.player = player;
        // this.capacity = (templateForTower.capacity != null) ? templateForTower.capacity : 0;
        // this.shells = new Array<Shell>();
        // this.radiusDetectionСircle = new Circle(getCenterGraphicCoord(1), (templateForTower.radiusDetection == null) ? 0f : templateForTower.radiusDetection); // AlexGor
        // if(templateForTower.shellAttackType == ShellAttackType.FirstTarget && templateForTower.radiusFlyShell != null && templateForTower.radiusFlyShell >= templateForTower.radiusDetection) {
        // this.radiusFlyShellСircle = new Circle(getCenterGraphicCoord(1), templateForTower.radiusFlyShell);
        // }
    }
    public void addTowerToFaction(TemplateForTower tower)
    {
        Debug.Log("FactionsManager::addTowerToFaction(); -- Tower name:" + tower.name);
        string newFactionName = tower.getFactionName();

        foreach (Faction faction in factions)
        {
            if (faction.getName().Equals(newFactionName))
            {
                faction.getTemplateForTowers().Add(tower);
                tower.setFaction(faction);
                return;
            }
        }
        Faction newFaction = new Faction(newFactionName);

        newFaction.getTemplateForTowers().Add(tower);
        tower.setFaction(newFaction);
        factions.Add(newFaction);
    }
Example #7
0
    public bool createTower(int buildX, int buildZ, TemplateForTower templateForTower, int player)
    {
        Debug.Log("GameField::createTower(); -- buildX:" + buildX + " buildZ:" + buildZ + " templateForTower:" + templateForTower + " player:" + player);
        if (gamerGold >= templateForTower.cost)
        {
            int towerSize = templateForTower.size;
            int startX = 0, startZ = 0, finishX = 0, finishZ = 0;
            if (towerSize != 1)
            {
                // Нижняя карта
                if (towerSize % 2 == 0)
                {
                    startX  = -(towerSize / 2);
                    startZ  = -(towerSize / 2);
                    finishX = (towerSize / 2) - 1;
                    finishZ = (towerSize / 2) - 1;
                }
                else
                {
                    startX  = -(towerSize / 2);
                    startZ  = -(towerSize / 2);
                    finishX = (towerSize / 2);
                    finishZ = (towerSize / 2);
                }
                // Правая карта
//                if (towerSize % 2 == 0) {
//                    startX = -(towerSize / 2);
//                    startZ = -((towerSize / 2) - 1);
//                    finishX = ((towerSize / 2) - 1);
//                    finishZ = (towerSize / 2);
//                } else {
//                    startX = -(towerSize / 2);
//                    startZ = -(towerSize / 2);
//                    finishX = (towerSize / 2);
//                    finishZ = (towerSize / 2);
//                }
            }
            // Debug.Log("GameField::createTower(); -- test1");
            for (int tmpX = startX; tmpX <= finishX; tmpX++)
            {
                for (int tmpZ = startZ; tmpZ <= finishZ; tmpZ++)
                {
                    if (!cellIsEmpty(buildX + tmpX, buildZ + tmpZ))
                    {
                        return(false);
                    }
                }
            }

            // Debug.Log("GameField::createTower(); -- test2");
            // GOVNO CODE
            Vector2Int position = new Vector2Int(buildX, buildZ);
            Tower      tower    = towersManager.createTower(position, templateForTower, player);
            // Debug.Log("GameField::createTower(); -- test3 tower:" + tower);
            // Debug.Log("GameField::createTower()", "-- templateForTower.towerAttackType:" + templateForTower.towerAttackType);
            // if (templateForTower.towerAttackType != TowerAttackType.Pit) {
            for (int tmpX = startX; tmpX <= finishX; tmpX++)
            {
                for (int tmpZ = startZ; tmpZ <= finishZ; tmpZ++)
                {
                    Cell cell = field[buildX + tmpX, buildZ + tmpZ];
                    cell.setTower(tower);
                    Vector3 pos = field[buildX + tmpX, buildZ + tmpZ].graphicCoordinates;
                    pos.Set(pos.x - 1.5f, pos.y, pos.z - 1.5f);
                    // Vector3 scal = gameObject.transform.localScale;
                    // gameObject.transform.localScale.Set(scal.x*2f, scal.y*2f, scal.z*2f);
                    GameObject gameObject = (GameObject)Instantiate(tower.getTemplateForTower().modelObject, pos, Quaternion.identity, cell.transform);
                    gameObject.transform.localScale = new Vector3(3.0f, 3.0f, 3.0f);
                    // pathFinder.nodeMatrix[buildZ + tmpZ][buildX + tmpX].setKey('T');
                    tower.gameObject = gameObject;
                    // surface.BuildNavMesh();
                    foreach (var agents in  Creeps.GetComponentsInChildren <NavMeshAgent>())
                    {
                        agents.SetDestination(new Vector3(96, 0, 96));
                    }
                    Debug.Log("GameField::createTower(); -- Instantiate gameObject:" + gameObject);
                }
            }
            // }
            // GOVNO CODE

            // rerouteForAllCreeps();
            gamerGold -= templateForTower.cost;
            Debug.Log("GameField::createTower(); -- Now gamerGold:" + gamerGold);
            return(true);
        }
        else
        {
            return(false);
        }
    }