Exemplo n.º 1
0
        // Call when district is upgraded
        public override void OnUpgrade(ConstructedTileProject upgradee)
        {
            District old = (District)upgradee;

            ResourceMods = old.ResourceMods;
            Buildings    = old.Buildings;
            Name         = old.Name;
        }
Exemplo n.º 2
0
        public ConstructedTileProject(string id, Dictionary <string, int> baseCost)
        {
            ID = id;
            baseResourceCost = baseCost;

            placed   = false;
            upgradee = null;
        }
Exemplo n.º 3
0
        public bool IsConstructable(City city, GameMaster game)
        {
            // TODO: Move to a IsAfforable(position, city, game) method
            // Determine if an empty valid tile is affordable
            bool normalCost = true;

            foreach (KeyValuePair <string, int> resource in GetResourceCost(city, game))
            {
                if (game.GlobalInventory.GetResourceCount(resource.Key) < resource.Value)
                {
                    normalCost = false;
                    break;
                }
            }

            // Iterate through City Range and return if there is a valid and afforable tile
            foreach (Vector3Int position in city.GetCityRange(game.World))
            {
                if (IsValidTile(position, game.World, city))
                {
                    // If the valid tile is not empty, check if it can be upgraded and afforded
                    if (game.World.GetConstructedTile(position) != null && IsUpgradeableTile(position, game.World))
                    {
                        upgradee = (game.World.GetConstructedTile(position)).Project;
                        bool upgradeCost = true;
                        foreach (KeyValuePair <string, int> resource in GetResourceCost(city, game))
                        {
                            if (game.GlobalInventory.GetResourceCount(resource.Key) < resource.Value)
                            {
                                upgradeCost = false;
                                break;
                            }
                        }
                        upgradee = null;

                        if (upgradeCost)
                        {
                            return(true);
                        }
                    }

                    // If the valid tile is empty, check if the normal cost is affordable
                    else if (normalCost)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 4
0
 public override bool IsUpgradeableTile(Vector3Int position, World world)
 {
     if ((world.GetConstructedTile(position)).Completed)
     {
         ConstructedTileProject old = (world.GetConstructedTile(position)).Project;
         //TODO: move district levels to a higher level class
         string[] levels = { "lower district", "middle district", "upper district" };
         if (old.ProjectType == "District")
         {
             int level = -1;
             for (int i = 0; i < levels.Length - 1; i++)
             {
                 if (ID == levels[i])
                 {
                     level = i;
                     break;
                 }
             }
             return(levels[level + 1] == old.ID);
         }
     }
     return(false);
 }
Exemplo n.º 5
0
 public override void OnUpgrade(ConstructedTileProject upgradee)
 {
     //City.RemoveTileImprovement((Tile Improvement) upgradee);
 }
Exemplo n.º 6
0
 public virtual void OnPlacement(Vector3Int position, ConstructedTileProject upgradee = null)
 {
     placed        = true;
     this.position = position;
     this.upgradee = upgradee;
 }
Exemplo n.º 7
0
 public abstract void OnUpgrade(ConstructedTileProject upgradee);
Exemplo n.º 8
0
 public override void OnUpgrade(ConstructedTileProject upgradee)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 9
0
        private IEnumerator WaitForPlacement(City city, World world, ConstructedTileProject project, GUIStateManager state)
        {
            state.SetState(GUIStateManager.GHOST_TILE);
            char sepChar = System.IO.Path.DirectorySeparatorChar;

            spriteRenderer.sprite = Resources.Load <Sprite>("Projects" + sepChar + "Constructed Tiles" + sepChar + project.ID);
            spriteRenderer.color  = new Color(0.5f, 0.5f, 0.5f);

            Vector3Int gridPos = world.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition));

            HashSet <Vector3Int> range = city.GetCityRange(world);

            UnityEngine.Tilemaps.Tile green = Resources.Load <UnityEngine.Tilemaps.Tile>(System.IO.Path.Combine("Tiles", "Green"));
            foreach (Vector3Int pos in range)
            {
                if (IsValidTile(pos, city, world, project))
                {
                    world.SetMovementTile(pos, green);
                }
            }

            yield return(new WaitForSeconds(0.1f));

            bool click = Input.GetMouseButtonUp(0);

            while (!click || !IsValidTile(gridPos, city, world, project))
            {
                gridPos            = world.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition));
                transform.position = world.CellToWorld(gridPos);

                string text = project.GetTooltipText(gridPos, world);
                if (text != null)
                {
                    if (!canvas.gameObject.activeSelf)
                    {
                        canvas.gameObject.SetActive(true);
                    }
                    tooltipText.text = text;
                }
                else
                {
                    if (canvas.gameObject.activeSelf)
                    {
                        canvas.gameObject.SetActive(false);
                    }
                }

                if (!IsValidTile(gridPos, city, world, project))
                {
                    spriteRenderer.color = new Color(0, 0, 0);
                }
                else
                {
                    spriteRenderer.color = new Color(0.5f, 0.5f, 0.5f);
                }

                click = Input.GetMouseButtonUp(0);
                yield return(null);
            }

            ConstructedTile tile = Resources.Load <ConstructedTile>("Projects" + sepChar + "Constructed Tiles" + sepChar + project.ID);

            if (world.GetConstructedTile(gridPos) != null)
            {
                project.OnPlacement(gridPos, (world.GetConstructedTile(gridPos)).Project);
            }
            else
            {
                project.OnPlacement(gridPos);
            }

            world.StartConstructionOfCityTile(tile, gridPos);

            foreach (Vector3Int pos in range)
            {
                world.SetMovementTile(pos, null);
            }

            Debug.Log("Tile Selected");
            state.SetState(GUIStateManager.CITY);
            yield break;
        }
Exemplo n.º 10
0
 public Coroutine Place(City city, World world, ConstructedTileProject project, GUIStateManager state)
 {
     gameObject.SetActive(true);
     return(StartCoroutine(WaitForPlacement(city, world, project, state)));
 }
Exemplo n.º 11
0
        private bool IsValidTile(Vector3Int pos, City city, World world, ConstructedTileProject project)
        {
            bool upgradeable = world.GetConstructedTile(pos) == null || project.IsUpgradeableTile(pos, world);

            return(city.WithinCityRange(pos) && project.IsValidTile(pos, world, city) && upgradeable);
        }