/// <summary>
 /// Updates maintenence to enable/disable
 /// </summary>
 /// <param name="onOff">The boolean to update the maintenence to</param>
 /// <param name="spot">The specific building spot to update</param>
 public void StartMaintenance(bool onOff, BuildingSpot spot)
 {
     spot.maintenance = onOff;
     startMaintenanceButton.SetActive(!onOff);
     stopMaintenanceButton.SetActive(onOff);
     integrityMeterOutline.color = onOff? GM.I.art.white : GM.I.art.light;
 }
 /// <summary>
 /// Update the production status of buildings
 /// </summary>
 /// <param name="onOff">The boolean to update the production status to</param>
 /// <param name="spot">The specific building spot to update</param>
 public void StopProduction(bool onOff, BuildingSpot spot)
 {
     spot.producing = !onOff;
     stopProduction.SetActive(!onOff);
     resumeProduction.SetActive(onOff);
     spot.UpdateVisual();
 }
    /// <summary>
    /// Processes the status of a specific building
    /// </summary>
    /// <param name="spot">The building spot to process the status of</param>
    /// <param name="updateText">The text to update the status to</param>
    /// <returns></returns>
    public int ProcessStatus(BuildingSpot spot, bool updateText)
    {
        List <string> statuses = new List <string>();
        List <Color>  colors   = new List <Color>();

        return(ProcessStatus(spot, updateText, ref statuses, ref colors));
    }
 /// <summary>
 /// Initializes the project
 /// </summary>
 /// <param name="_project">The project that needs initialized</param>
 /// <param name="spot">The building spot the object should be placed on</param>
 public void Init(Project _project, BuildingSpot spot)
 {
     project               = _project;
     text.text             = project.projectName;
     image.sprite          = project.sprite;
     selectedImage.enabled = spot.currentProject == project;
     tooltip.tip           = project.effectDescription;
     foreach (GameObject marker in levelMarkers)
     {
         marker.SetActive(false);
     }
     additionnalInfo.SetActive(!GM.I.project.IsConstant(project));
     if (GM.I.project.IsConstant(project))
     {
         time.fillAmount = 0f;
     }
     else
     {
         for (var i = 1; i <= GM.I.project.GetLevel(project); i++)
         {
             if (levelMarkers.Count > i - 1)
             {
                 levelMarkers[i - 1].SetActive(true);
             }
         }
         time.fillAmount = (float)GM.I.project.GetTime(project) / (float)GM.I.project.GetLength(project);
     }
 }
Exemple #5
0
 public Palace(BuildingSpot buildingSpot)
     : base(buildingSpot, 3, 3)
 {
     BuildingParams = new TileParams(production: 1, money: 1);
     Level = 1;
     Name = "Palace";
 }
 public BuildingBuildRequest(
     IOnlyProductionObject productionObject,
     BuildingSpot containingBuildingSpot
     )
     : base(productionObject)
 {
     this.containingBuildingSpot = containingBuildingSpot;
 }
Exemple #7
0
 /// <summary>
 /// Gets the other building spot
 /// </summary>
 /// <param name="building">The building to find the other of</param>
 /// <returns>Returns the other building spot</returns>
 public BuildingSpot GetOther(BuildingSpot building)
 {
     if (building == spotStart)
     {
         return(spotEnd);
     }
     else
     {
         return(spotStart);
     }
 }
        public async void ConstructionOnAvailableSpotStarted()
        {
            var size               = "XXL";
            var buildingMetaId     = "Test_ConstructionOnAvailableSpotStarted";
            var buildingSpotMetaId = "Test_ConstructionOnAvailableSpotStarted";
            var playerId           = "Test_ConstructionOnAvailableSpotStarted";

            // Create test builidng meta if it doesn't exist.
            var buildingMeta = await new BuildingMeta(buildingMetaId).LoadAsync();

            if (buildingMeta == null)
            {
                buildingMeta      = new BuildingMeta(buildingMetaId);
                buildingMeta.Size = size;
                await buildingMeta.InsertAsync();
            }

            // Create test builidng spot meta if it doesn't exist.
            var buildingSpotMeta = await new BuildingSpotMeta(buildingSpotMetaId).LoadAsync();

            if (buildingSpotMeta == null)
            {
                buildingSpotMeta      = new BuildingSpotMeta(buildingSpotMetaId);
                buildingSpotMeta.Size = size;
                await buildingSpotMeta.InsertAsync();
            }

            // Create test player and building spot.
            var buildingSpot = new BuildingSpot(buildingSpotMetaId);
            var player       = await Helpers.CreateTestPlayer(playerId, buildingSpot : buildingSpot);

            // Auth player.
            var sessionToken = Helpers.GetSessionToken(playerId);

            // Mock data.
            var data = JToken.Parse($@"{{
                'PlayerId':'{playerId}',
                'SessionToken':'{sessionToken}',
                'BuildingSpotId':'{buildingSpot.Id}',
                'BuildingMetaId':'{buildingMetaId}',
            }}");

            // Execute controller.
            var controller    = new StartBuildingConstructionController();
            var responseToken = await controller.HandleHttpRequestAsync(data);

            // Assert controller response status is OK.
            Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]);

            // Make sure building construction is started.
            player = await player.LoadAsync();

            Assert.False(player.GetBuildingSpotById(buildingSpot.Id).Building.IsConstructed);
        }
    /// <summary>
    /// Shows the information for a specific building spot
    /// </summary>
    /// <param name="spot">The building spot you want to see the info on</param>
    public void ShowBuildingInfo(BuildingSpot spot)
    {
        if (spot != null)
        {
            gameObject.SetActive(true);
            buildingName.color  = spot.currentBuilding.color;
            buildingImage.color = spot.currentBuilding.color;

            productionToggle.gameObject.SetActive(spot.currentBuilding.productor);
            projectToggle.gameObject.SetActive(spot.currentBuilding.research);
            maintenanceToggle.gameObject.SetActive(true);

            if (productionToggle.isOn && spot.currentBuilding.research)
            {
                productionToggle.SetIsOnWithoutNotify(false);
                projectToggle.SetIsOnWithoutNotify(true);
                projectDetail.SetActive(false);
                projectMenu.SetActive(true);
            }
            if (projectToggle.isOn && spot.currentBuilding.productor)
            {
                productionToggle.SetIsOnWithoutNotify(true);
                projectToggle.SetIsOnWithoutNotify(false);
            }
            if ((productionToggle.isOn || projectToggle.isOn) && !spot.currentBuilding.productor && !spot.currentBuilding.research)
            {
                overviewToggle.SetIsOnWithoutNotify(true);
                productionToggle.SetIsOnWithoutNotify(false);
                projectToggle.SetIsOnWithoutNotify(false);
                maintenanceToggle.SetIsOnWithoutNotify(false);
            }

            if (!spot.Built)
            {
                overviewToggle.SetIsOnWithoutNotify(true);
                productionToggle.SetIsOnWithoutNotify(false);
                projectToggle.SetIsOnWithoutNotify(false);
                maintenanceToggle.SetIsOnWithoutNotify(false);
                productionToggle.gameObject.SetActive(false);
                projectToggle.gameObject.SetActive(false);
                maintenanceToggle.gameObject.SetActive(false);
            }

            DestroyMenu(false);
            selectedSpot    = spot;
            selectedProject = null;
            UpdateMenuInfo(spot);
        }
        else
        {
            gameObject.SetActive(false);
            selectedSpot = null;
        }
    }
Exemple #10
0
        public void TestConnectionGetOtherEnd()
        {
            Connection   c = new Connection();
            BuildingSpot s = new BuildingSpot();

            c.spotStart = s;
            c.spotEnd   = new BuildingSpot();

            BuildingSpot bs = c.GetOther(s);

            Assert.AssertEquals(bs, c.spotEnd);
        }
Exemple #11
0
        public void BuildingSpotCreate()
        {
            bs                 = new BuildingSpot();
            bs.district        = "";
            bs.discovered      = true;
            bs.mode            = BuildingSpotMode.Building;
            bs.status          = BuildingStatus.Operating;
            bs.currentBuilding = makeBuildingObject();
            bs.connections     = null;

            bs.built   = true;
            bs.storage = 4;
        }
        /// <summary>
        /// Temp hack while we have only one city.
        /// Creates a default city with wards and spots based on the 'SagaCity' meta.
        /// </summary>
        private async Task <City> CreateSagaCityWithWardsAndSpots()
        {
            // Create 'Saga' city meta if it doesn't already exist.
            var sagaCityMetaId = "SagaCity";
            var sagaCityMeta   = await new CityMeta(sagaCityMetaId).LoadAsync();

            if (sagaCityMeta == null)
            {
                sagaCityMeta = new CityMeta(sagaCityMetaId);
                await sagaCityMeta.InsertAsync();
            }

            var city     = new City(sagaCityMetaId);
            var cityMeta = await city.GetMetaAsync();

            foreach (var wardMetaId in cityMeta.WardMetaIds)
            {
                var wardMeta = await new WardMeta(wardMetaId).LoadAsync();
                if (wardMeta == null)
                {
                    continue;
                }
                var ward = new Ward(wardMetaId);
                if (wardMeta.IsInitiallyUnlocked)
                {
                    ward.IsUnlocked = true;
                }

                foreach (var buildingSpotAddress in wardMeta.BuildingSpotsMap)
                {
                    var newBuildingSpot = new BuildingSpot(buildingSpotAddress.Value);
                    newBuildingSpot.Address = buildingSpotAddress.Key;
                    ward.BuildingSpots.Add(newBuildingSpot);
                }

                city.Wards.Add(ward);
            }

            return(city);
        }
Exemple #13
0
        public static async Task <Player> CreateTestPlayer(string playerId, string playerPassword = "******",
                                                           bool replace = true, Building building = null, BuildingSpot buildingSpot = null, Ward ward = null, City city = null, Character character = null)
        {
            var player = new Player(playerId);

            player.PasswordHash = PasswordHash.CreateHash(playerPassword);

            if (city == null)
            {
                city = new City("Test_CityId");
            }
            player.City = city;

            if (ward == null)
            {
                ward = new Ward("Test_WardId");
            }
            city.Wards.Add(ward);

            if (buildingSpot == null)
            {
                buildingSpot = new BuildingSpot("Test_BuildingSpotId");
            }
            city.Wards[0].BuildingSpots.Add(buildingSpot);

            if (building == null && buildingSpot.MetaId == "Test_BuildingSpotId")
            {
                building = new Building("Test_BuildingId");
            }
            buildingSpot.Building = building;

            if (character != null)
            {
                player.Characters.Add(character);
            }

            return(await CreateTestPlayer(player, replace));
        }
Exemple #14
0
 protected Building(BuildingSpot buildingSpot, int productionPrice, int moneyPrice)
 {
     BuildingSpot = buildingSpot;
     ProductionPrice = productionPrice;
     MoneyPrice = moneyPrice;
 }
    /// <summary>
    ///
    /// </summary>
    /// <param name="spot"></param>
    /// <param name="updateText"></param>
    /// <param name="statuses"></param>
    /// <param name="colors"></param>
    /// <returns></returns>
    public int ProcessStatus(BuildingSpot spot, bool updateText, ref List <string> statuses, ref List <Color> colors)
    {
        if (updateText)
        {
            foreach (Text text in statusTexts)
            {
                text.text = "";
            }
            overviewAlert.SetActive(false);
            productionAlert.SetActive(false);
            projectAlert.SetActive(false);
            maintenanceAlert.SetActive(false);
        }

        if (!spot.Built)
        {
            if (spot.constructionHalted)
            {
                ProcessIndividualStatus("Construction stopped", GM.I.art.red, overviewAlert, ref statuses, ref colors, updateText);
            }
            else
            {
                ProcessIndividualStatus("Under construction", GM.I.art.light, null, ref statuses, ref colors, updateText);
            }
        }
        else
        {
            if (spot.Cost.Limited(GM.I.resource.resources))
            {
                ProcessIndividualStatus("Not enough resources!", GM.I.art.red, maintenanceAlert, ref statuses, ref colors, updateText);
            }
            if (spot.maintenance)
            {
                ProcessIndividualStatus("Under maintenance", GM.I.art.light, maintenanceAlert, ref statuses, ref colors, updateText);
            }
            else if (spot.DangerousIntegrity)
            {
                ProcessIndividualStatus("Needs maintenance!", GM.I.art.red, maintenanceAlert, ref statuses, ref colors, updateText);
            }
            else if (spot.BadIntegrity)
            {
                ProcessIndividualStatus("Needs maintenance", GM.I.art.orange, maintenanceAlert, ref statuses, ref colors, updateText);
            }
            if (spot.currentBuilding.housing)
            {
                if (spot.OverPopulated)
                {
                    ProcessIndividualStatus("Overpopulated!", GM.I.art.red, overviewAlert, ref statuses, ref colors, updateText);
                }
                else if (spot.HighPopulated)
                {
                    ProcessIndividualStatus("Crowded!", GM.I.art.orange, overviewAlert, ref statuses, ref colors, updateText);
                }
            }
            if (spot.currentBuilding.productor)
            {
                if (!spot.producing)
                {
                    ProcessIndividualStatus("Production stopped", GM.I.art.light, productionAlert, ref statuses, ref colors, updateText);
                }
                else if (!spot.maintenance)
                {
                    if (spot.LowPopulated)
                    {
                        ProcessIndividualStatus("Not enough workers", GM.I.art.orange, productionAlert, ref statuses, ref colors, updateText);
                    }
                    if (spot.storage == spot.ResourcePortion())
                    {
                        ProcessIndividualStatus("Storage full", GM.I.art.light, productionAlert, ref statuses, ref colors, updateText);
                    }
                }
            }
            if (spot.currentBuilding.research)
            {
                if (spot.currentProject == null)
                {
                    ProcessIndividualStatus("Needs a project", GM.I.art.pink, projectAlert, ref statuses, ref colors, updateText);
                }
            }
        }

        if (statuses.Count == 0)
        {
            ProcessIndividualStatus("Working correctly", GM.I.art.green, null, ref statuses, ref colors, updateText);
        }
        int statusNumber = 0;

        for (int i = 0; i < statusTexts.Count; i++)
        {
            if (i < statuses.Count)
            {
                if (updateText)
                {
                    statusTexts[i].text  = statuses[i];
                    statusTexts[i].color = colors[i];
                }
                if (colors[i] == GM.I.art.red)
                {
                    statusNumber = 4;
                }
                if (colors[i] == GM.I.art.orange && statusNumber <= 2)
                {
                    statusNumber = 3;
                }
                if (colors[i] == GM.I.art.pink && statusNumber <= 1)
                {
                    statusNumber = 2;
                }
                if (colors[i] == GM.I.art.light && statusNumber == 0)
                {
                    statusNumber = 1;
                }
            }
        }
        return(statusNumber);
    }
    /// <summary>
    /// Updates the information for a specific building spot
    /// </summary>
    /// <param name="spot">The building spot that you want to update</param>
    public void UpdateMenuInfo(BuildingSpot spot)
    {
        buildingImage.sprite = spot.currentBuilding.sprite;
        buildingName.text    = spot.currentBuilding.buildingName + " " + spot.district;
        Color populationColor = spot.OverPopulated ? GM.I.art.red : GM.I.art.white;

        populationName.text = spot.currentBuilding.populationName;
        populationText.text = UIManager.ColoredString(UIManager.HumanNotation(spot.population), populationColor) + " / " + UIManager.HumanNotation(spot.currentBuilding.populationRequirement);

        overviewMenu.SetActive(overviewToggle.isOn);
        productionMenu.SetActive(productionToggle.isOn);
        maintenanceMenu.SetActive(maintenanceToggle.isOn);
        productionToggle.gameObject.SetActive(spot.currentBuilding.productor);
        projectToggle.gameObject.SetActive(spot.currentBuilding.research);
        maintenanceToggle.gameObject.SetActive(true);

        if (projectToggle.isOn)
        {
            UpdateProject();
        }
        else
        {
            projectDetail.SetActive(false);
            projectMenu.SetActive(false);
        }


        costInfo.text       = spot.currentBuilding.costInfo;
        shortageEffect.text = spot.Cost.Limited(GM.I.resource.resources)? spot.currentBuilding.shortageEffect:"";
        integrity.SetActive(spot.Built && !spot.currentBuilding.control);
        buildDate.text            = "Built in " + UIManager.TimeToDate(spot.constructionDate);
        integrityMeterText.text   = UIManager.HumanNotation(spot.integrity);
        maintenanceEffecText.text = spot.currentBuilding.maintenanceEffect;
        integrityMeter.fillAmount = spot.integrity;
        if (spot.BadIntegrity)
        {
            integrityMeter.color    = GM.I.art.orange;
            integrityRiskText.color = GM.I.art.orange;
            integrityRiskText.text  = "FAILURE RISK - MEDIUM";
        }
        else if (spot.DangerousIntegrity)
        {
            integrityMeter.color    = GM.I.art.red;
            integrityRiskText.color = GM.I.art.red;
            integrityRiskText.text  = "FAILURE RISK - HIGH";
        }
        else
        {
            integrityMeter.color    = GM.I.art.light;
            integrityRiskText.color = GM.I.art.light;
            integrityRiskText.text  = "FAILURE RISK - LOW";
        }

        monthlyProduction.UpdateRessourceBox(spot.Production);
        monthlyCost.UpdateRessourceBox(spot.Cost);
        storage.text          = (int)spot.ResourcePortion() + " / " + spot.storage;
        storageBar.fillAmount = spot.ResourcePortion() / spot.storage;
        storageBar.color      = spot.currentBuilding.color;
        storageOutline.color  = spot.currentBuilding.color;
        increaseStorageButton.SetActive(!(spot.increaseStorage || spot.storage == spot.storageMax));
        stopStorageButton.SetActive(!(!spot.increaseStorage || spot.storage == spot.storageMax));
        increaseStorageCost.gameObject.SetActive(spot.storage != spot.storageMax);
        increaseStorageTime.gameObject.SetActive(spot.storage != spot.storageMax);
        increaseStorageCost.UpdateRessourceBox(spot.currentBuilding.storageIncreaseMonthlyCost);
        increaseStorageTime.text = spot.storageCounter + " months";
        StartMaintenance(spot.maintenance);
        StopProduction(!spot.producing);

        ProcessStatus(spot, true);

        for (int i = 0; i < spot.currentBuilding.projects.Count; i++)
        {
            Project project = spot.currentBuilding.projects[i];
            projectChoices[i].Init(project, spot);
        }

        if (spot.currentBuilding.control)
        {
            destroyButton.SetActive(false);
        }
        if (!overviewToggle.isOn)
        {
            DestroyMenu(false);
        }
    }