Example #1
0
        void Reset()
        {
            //bd = null;

            bt = TBDatabase.GetBuildingType(building.Type);
            //bd = bt.GetDefine(building.Level);
            bdNext = bt.GetDefine(building.Level + 1);
            //bdLast = bt.GetDefLast();

            textTitle.text = "Upgrade " + bt.Name + " to Level " + (building.Level + 1).ToString() + " ?";
            imgIcon.sprite = Resources.Load <Sprite>("Icons/Building/" + bt.Name);

            for (int i = 0; i < progresses.Length; ++i)
            {
                progresses[i].gameObject.SetActive(true);
            }

            // display progresses of building by building type
            if (bt.ID == 0)
            {
                // incase building si town hall, show gold capacity, elixir capacit and hitpoint
                building.UIFillProgressWithNext(progresses[0], BDInfo.CapacityGold);
                building.UIFillProgressWithNext(progresses[1], BDInfo.CapacityElixir);
                building.UIFillProgressWithNext(progresses[2], BDInfo.HitPoint);
            }
            else if (bt.ID == 1)
            {
                // incase building is house, only show hitpoint, and disable other progresses
                building.UIFillProgressWithNext(progresses[0], BDInfo.HitPoint);
                progresses[1].gameObject.SetActive(false);
                progresses[2].gameObject.SetActive(false);
            }
            else if (bt.ID == 2)
            {
                building.UIFillProgressWithNext(progresses[0], BDInfo.HitPoint);
                progresses[1].gameObject.SetActive(false);
                progresses[2].gameObject.SetActive(false);
            }
            else if ((bt.ID == 3) || (bt.ID == 4))
            {
                building.UIFillProgressWithNext(progresses[0], BDInfo.Capacity);
                building.UIFillProgressWithNext(progresses[1], BDInfo.ProductionRate);
                building.UIFillProgressWithNext(progresses[2], BDInfo.HitPoint);
            }
            else if ((bt.ID == 5) || (bt.ID == 6))
            {
                building.UIFillProgressWithNext(progresses[0], BDInfo.StorageCapacity);
                building.UIFillProgressWithNext(progresses[1], BDInfo.HitPoint);
                progresses[2].gameObject.SetActive(false);
            }
            else if (bt.ID == 7)
            {
                //"Training Capacity : 0/20";
                //"HitPoint"
            }
            else if (bt.ID == 8)
            {
                //"Total troop Capacity : 0/20";
                //"HitPoint"
                // show troops icon (click to remove unit) "Remove Troops?"
            }
            else if (bt.ID == 9)
            {
                //"Damage per second:15";
                //"HitPoint"
                //Range : 9 Tiles
                //Damage Type: Single Target
                //Targets: Ground
                //Favorite target: Any
            }
            else if (bt.ID == 10)
            {
            }
            else
            {
            }

            // get townhall to check upgrade requires next townhall
            Building buildingTown = BEGround.instance.Buildings[0][0];

            if (bdNext.TownHallLevelRequired > buildingTown.Level)
            {
                goNote.SetActive(true);
                NoteInfo.text = "To upgrade this building, you first need\n Town Hall Level " + bdNext.TownHallLevelRequired.ToString() + "!";
                TownLevelOk   = false;
                goNormal.SetActive(false);
            }
            else
            {
                goNote.SetActive(false);
                TownLevelOk = true;
                goNormal.SetActive(true);

                // set infos about upgrade
                bdNext.PriceInfoApply(PriceIcon, Price);
                textBuildTime.text = BENumber.SecToString(bdNext.BuildTime);
                GemCount           = (bdNext.BuildTime + 1) / 60;     // 1 gem per minute
                PriceGem.text      = GemCount.ToString("#,##0");
                PriceGem.color     = (SceneTown.Gem.Target() < GemCount) ? Color.red : Color.white;
            }
        }
Example #2
0
        // initialize with building
        public void Init(BuildingType _bt)
        {
            bt        = _bt;
            Name.text = bt.Name;
            Info.text = bt.Info;

            // check if current building count of this type is larger then max count
            int CountMax = (_bt.ID == 1) ? 5 : BEGround.instance.GetBuildingCountMax(bt.ID);
            int Count    = BEGround.instance.GetBuildingCount(bt.ID);

            if (Count >= CountMax)
            {
                // if can't create more building
                CountAvailable = false;

                // get next available townhall level
                int NextTownLevel = bt.GetMoreBuildTownLevel(Count);
                if (NextTownLevel == -1)
                {
                    DisabledInfo.text = "Reach Maximum Count";
                }
                else
                {
                    DisabledInfo.text = "Upgrade Town Hall to level " + NextTownLevel.ToString() + " to build more";
                }
                goDisabled.SetActive(true);
            }

            bd = bt.Defs[0];

            // if building type is house (house's price is related to current house count)
            // change price
            if (_bt.ID == 1)
            {
                if (Count == 1)
                {
                    bd.BuildGemPrice = 400;
                }
                else if (Count == 2)
                {
                    bd.BuildGemPrice = 800;
                }
                else if (Count == 3)
                {
                    bd.BuildGemPrice = 1600;
                }
                else if (Count == 4)
                {
                    bd.BuildGemPrice = 3200;
                }
                else
                {
                }
            }

            // set ui info
            bd.PriceInfoApply(PriceIcon, Price);
            BuildTimeInfo.text  = "Build time:";
            BuildTime.text      = BENumber.SecToString(bd.BuildTime);
            BuildCountInfo.text = "Built:";
            BuildCount.text     = Count.ToString() + "/" + CountMax.ToString();

            Border.color = CountAvailable ? new Color32(0, 150, 186, 255) : new Color32(133, 119, 108, 255);
            Icon.sprite  = Resources.Load <Sprite>("Icons/Building/" + bt.Name);
            Icon.color   = CountAvailable ? new Color32(255, 255, 255, 255) : new Color32(133, 119, 108, 255);
        }
Example #3
0
 public void Add(BuildingDef def)
 {
     Defs.Add(def);
     // set mesh prefab to each Building definition
     def.prefab = Resources.Load("Prefabs/Building/" + Name + "_" + Defs.Count.ToString()) as GameObject;
 }