public void affectation()
    {
        if (GameVariables.listHabitant.Count != 0 && GameVariables.batimentSelectionne.ListHabitants.Count < GameVariables.batimentSelectionne.nbrMaxHab)
        {
            clone = GameVariables.listHabitant[0];
            clone.random_object.SetActive(false);
            Destroy(clone.random_object);
            GameVariables.listHabitant.Remove(clone);
            clone.Spawn = GameVariables.batimentSelectionne;
            GameObject o = clone.GetComponent <Role>().changementRole(GameVariables.batimentSelectionne.typeHabitant.ToString());
            GameVariables.listHabitantAffecte.Add(clone);

            switch (GameVariables.batimentSelectionne.typeHabitant.ToString())
            {
            case "Combattant":
                GameVariables.listCombattant.Add(o.GetComponent <Combattant>());
                break;

            case "Fermier":
                GameVariables.listFermier.Add(o.GetComponent <Fermier>());
                break;

            case "Mineur":
                GameVariables.listMineur.Add(o.GetComponent <Mineur>());
                break;

            case "Bucheron":
                GameVariables.listBucheron.Add(o.GetComponent <Bucheron>());
                break;

            case "Marchand":
                GameVariables.listMarchand.Add(o.GetComponent <Marchand>());
                break;

            case "Pretre":
                GameVariables.listPretre.Add(o.GetComponent <Pretre>());
                break;
            }

            GameVariables.batimentSelectionne.ListHabitants.Add(o);
        }
    }
    //Milicia
    void addFirstFoundHabitantForType(Batiment.role type)
    {
        if (GameVariables.listHabitant.Count == 0 && GameVariables.batimentSelectionne.ListHabitants.Count < GameVariables.batimentSelectionne.nbrMaxHab)
        {
            return;
        }


        Batiment batiment = null;

        foreach (Batiment bat in GameVariables.listBatiment)
        {
            if (!bat.isEnDeplacement() && bat.typeHabitant == type && bat.ListHabitants.Count < bat.nbrMaxHab)
            {
                batiment = bat;
                break;
            }
        }

        if (batiment == null || batiment.ListHabitants.Count >= batiment.nbrMaxHab)
        {
            return;
        }

        List <Habitant> listMetierBat = GameVariables.getListMetier(batiment.typeHabitant);

        if (listMetierBat == null)
        {
            return;
        }

        Habitant villager = GameVariables.listHabitant[0];

        GameVariables.listHabitant.Remove(villager);

        villager.Spawn = batiment;
        GameObject o = villager.GetComponent <Role>().changementRole(batiment.typeHabitant.ToString());

        GameVariables.listHabitantAffecte.Add(villager);
        listMetierBat.Add(villager);
        batiment.ListHabitants.Add(o);
    }
    void removeFirstFoundHabitantForType(Batiment.role type)
    {
        Batiment batiment = null;

        foreach (Batiment bat in GameVariables.listBatiment)
        {
            if (!bat.isEnDeplacement() && bat.typeHabitant == type && bat.ListHabitants.Count > 0)
            {
                Debug.Log(batiment);
                batiment = bat; break;
            }
        }

        if (batiment == null || batiment.ListHabitants.Count <= 0)
        {
            return;
        }

        GameObject o = batiment.ListHabitants[0];

        if (o.GetComponent <Habitant>() == null)
        {
            return;
        }

        List <Habitant> listMetierBat = GameVariables.getListMetier(batiment.typeHabitant);

        if (listMetierBat == null)
        {
            return;
        }

        Habitant villager = o.GetComponent <Habitant>();

        batiment.ListHabitants.Remove(o);
        listMetierBat.Remove(villager);
        GameVariables.listHabitantAffecte.Remove(villager);

        villager.GetComponent <Role>().changementRole(Batiment.role.Habitant.ToString());
        GameVariables.listHabitant.Add(villager);
    }
示例#4
0
    //Private Functions
    private void initUI()
    {
        //Set Title Text
        titleText.text = GameVariables.batimentSelectionne.nomBatiment;
        //Set Desc Text
        descText.text = GameVariables.batimentSelectionne.description;

        //Check Effectifs UI Needed + Set Pop Manager Actions
        if (GameVariables.batimentSelectionne.nbrMaxHab != 0)
        {
            buildingPopulationManager.gameObject.SetActive(true);
            buildingPopulationManager.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
            secondSeparator.gameObject.SetActive(true);
            secondSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);

            buildingPopulationManager.setUpAction(() => {
                if (GameVariables.listHabitant.Count == 0)
                {
                    return;
                }

                Batiment batiment = GameVariables.batimentSelectionne;
                if (batiment == null || batiment.isEnDeplacement() || batiment.ListHabitants.Count >= batiment.nbrMaxHab)
                {
                    return;
                }

                List <Habitant> listMetierBat = GameVariables.getListMetier(batiment.typeHabitant);
                if (listMetierBat == null)
                {
                    return;
                }

                Habitant villager = GameVariables.listHabitant[0];
                GameVariables.listHabitant.Remove(villager);

                villager.Spawn = batiment;
                GameObject o   = villager.GetComponent <Role>().changementRole(batiment.typeHabitant.ToString());
                GameVariables.listHabitantAffecte.Add(villager);
                listMetierBat.Add(villager);
                batiment.ListHabitants.Add(o);
            });

            buildingPopulationManager.setDownAction(() => {
                Batiment batiment = GameVariables.batimentSelectionne;
                if (batiment == null || batiment.isEnDeplacement())
                {
                    return;
                }
                if (batiment.ListHabitants.Count == 0)
                {
                    return;
                }

                GameObject o = batiment.ListHabitants[0];

                if (o.GetComponent <Habitant>() == null)
                {
                    return;
                }

                List <Habitant> listMetierBat = GameVariables.getListMetier(batiment.typeHabitant);
                if (listMetierBat == null)
                {
                    return;
                }

                Habitant villager = o.GetComponent <Habitant>();
                batiment.ListHabitants.Remove(o);
                listMetierBat.Remove(villager);
                GameVariables.listHabitantAffecte.Remove(villager);

                villager.GetComponent <Role>().changementRole(Batiment.role.Habitant.ToString());
                GameVariables.listHabitant.Add(villager);
            });
        }
        else
        {
            buildingPopulationManager.gameObject.SetActive(false);
            buildingPopulationManager.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
            secondSeparator.gameObject.SetActive(false);
            secondSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
        }

        //Check Prod UI Needed
        if (GameVariables.batimentSelectionne is BatimentRessource)
        {
            buildingProdUI.gameObject.SetActive(true);
            buildingProdUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
            thirdSeparator.gameObject.SetActive(true);
            thirdSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
        }
        else
        {
            buildingProdUI.gameObject.SetActive(false);
            buildingProdUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
            thirdSeparator.gameObject.SetActive(false);
            thirdSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
        }

        //Check Upgrade UI Needed + Set Upgrade Action
        if (GameVariables.batimentSelectionne.batUpgrade != null)
        {
            buildingUpgradeUI.gameObject.SetActive(true);
            buildingUpgradeUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);

            buildingUpgradeUI.setUpgradeAction(() => {
                GameVariables.batimentSelectionne.upgradeStructure();
            });
        }
        else
        {
            buildingUpgradeUI.gameObject.SetActive(false);
            buildingUpgradeUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
        }
    }