public void CollectResource(Tile.TileTypes type, int amount) { switch (type) { case Tile.TileTypes.SOCIAL: Social += amount; txtSocial.GetComponent <Animator>().SetTrigger("ResourceGet"); break; case Tile.TileTypes.HEALTH: Health += amount; txtHealth.GetComponent <Animator>().SetTrigger("ResourceGet"); break; case Tile.TileTypes.MONEY: Money += amount; txtMoney.GetComponent <Animator>().SetTrigger("ResourceGet"); break; case Tile.TileTypes.TIME: Time += amount; txtTime.GetComponent <Animator>().SetTrigger("ResourceGet"); break; default: break; } UpdateStats(); }
override public void Construct(BuildingTypes bt, Tile t, GameManager gm) { if (Building.neighborsScaleEfficiency.Contains(bt)) { Tile.TileTypes nt = Building.Neighbor_Type[bt]; int m1 = Building.Neighbor_minmax[bt].Item1; int m2 = Building.Neighbor_minmax[bt].Item2; int neighborCount = 0; foreach (Tile n in t._neighborTiles) { if (n._type == nt) { neighborCount++; } } } GM = gm; _jobManager = gm.gameObject.GetComponent(typeof(JobManager)) as JobManager; _type = bt; t._building = this; _tile = t; GM._buildings.Add(this); //deducting resources used in construction GM._resourcesInWarehouse[GameManager.ResourceTypes.Planks] -= Building.cost_plank[bt]; GM._money -= Building.cost_money[bt]; }
public bool CanBeBuiltOn(Tile.TileTypes tile) { if (tile == Tile.TileTypes.Water) { return(water_can_be_built_on); } if (tile == Tile.TileTypes.Sand) { return(sand_can_be_built_on); } if (tile == Tile.TileTypes.Grass) { return(grass_can_be_built_on); } if (tile == Tile.TileTypes.Forest) { return(forest_can_be_built_on); } if (tile == Tile.TileTypes.Stone) { return(stone_can_be_built_on); } if (tile == Tile.TileTypes.Mountain) { return(mountain_can_be_built_on); } return(false); }
override public void Construct(BuildingTypes bt, Tile t, GameManager gm) { _placementEfficiency = 1f; if (ProductionBuilding.neighborsScaleEfficiency.Contains(bt)) { Tile.TileTypes nt = ProductionBuilding.Neighbor_Type[bt]; int m1 = ProductionBuilding.Neighbor_minmax[bt].Item1; int m2 = ProductionBuilding.Neighbor_minmax[bt].Item2; int neighborCount = 0; foreach (Tile n in t._neighborTiles) { if (n._type == nt) { neighborCount++; } } _placementEfficiency = Math.Max(0f, Math.Min(1f, (float)(1 + neighborCount - m1) / (float)(1 + m2 - m1)));//calculates efficiency factor } waitTime = ProductionBuilding.resourceGeneration[bt]; GM = gm; _jobManager = gm.gameObject.GetComponent(typeof(JobManager)) as JobManager; _type = bt; t._building = this; GM._buildings.Add(this); _tile = t; //deducting resources used in construction GM._resourcesInWarehouse[GameManager.ResourceTypes.Planks] -= Building.cost_plank[bt]; GM._money -= Building.cost_money[bt]; }
public static bool Constructable(BuildingTypes bt, Tile t, GameManager GM) { bool placeable = true; UnityEngine.Debug.Assert(GM._buildingPrefabs.Dict.ContainsKey(bt), "Building Type has no model assigned.", GM); UnityEngine.Debug.Assert(t._building is null, "This spot allready has a building.", GM); //determines if building is placed on right tile. UnityEngine.Debug.Assert(Building.TileOptions.ContainsKey(bt), "Building has no tile type assigned.", GM); UnityEngine.Debug.Assert(Building.TileOptions[bt].Contains(t._type), "Building can't be placed on this tile type.", GM); UnityEngine.Debug.Assert(GM._resourcesInWarehouse[GameManager.ResourceTypes.Planks] >= Building.cost_plank[bt], "Not enough planks.", GM); UnityEngine.Debug.Assert(GM._money >= Building.cost_money[bt], "Not enough money.", GM); if (Building.neighborsScaleEfficiency.Contains(bt)) { Tile.TileTypes nt = Building.Neighbor_Type[bt]; int m1 = Building.Neighbor_minmax[bt].Item1; int neighborCount = 0; foreach (Tile n in t._neighborTiles) { if (n._type == nt) { neighborCount++; } } UnityEngine.Debug.Assert(neighborCount >= m1, "Not enough neighbors of the correct type.", GM); placeable = placeable && (neighborCount >= m1); } placeable = placeable && (t._building is null) && (Building.TileOptions.ContainsKey(bt)) && (Building.TileOptions[bt].Contains(t._type)) && (GM._resourcesInWarehouse[GameManager.ResourceTypes.Planks] >= Building.cost_plank[bt]) && (GM._money >= Building.cost_money[bt]); return(placeable); }
/// <summary> /// Function that can change the type of the tile and replace its self in the grid array /// </summary> /// <param name="newType">New Type to switch to</param> /// <param name="originalTile">The Tile to switch from</param> /// <returns>Reference to the new Tile</returns> public static BaseTile ChangeTo(Tile.TileTypes newType, BaseTile originalTile) { BaseTile newTile = null; switch (newType) { case TileTypes.Tile: newTile = originalTile.gameObject.AddComponent <Tile>(); break; case TileTypes.Satalite: newTile = originalTile.gameObject.AddComponent <Satellite>(); break; case TileTypes.CombineSatellite: newTile = originalTile.gameObject.AddComponent <CombineSatellite>(); break; case TileTypes.LightOutput: newTile = originalTile.gameObject.AddComponent <LightOutput>(); break; case TileTypes.LightTarget: newTile = originalTile.gameObject.AddComponent <TargetTile>(); break; case TileTypes.Asteroid: newTile = originalTile.gameObject.AddComponent <AsteroidTile>(); break; case TileTypes.LightTrigger: newTile = originalTile.gameObject.AddComponent <LightTrigger>(); break; case TileTypes.LightGate: newTile = originalTile.gameObject.AddComponent <LightGate>(); break; case TileTypes.SatelliteSplitter: newTile = originalTile.gameObject.AddComponent <SplitterSatellite>(); break; case TileTypes.LightFilter: newTile = originalTile.gameObject.AddComponent <FilterTile>(); break; } if (newTile == null) { //report an Error and Back out Debug.LogError("Could not Change Tile target"); return(null); } originalTile.RemoveTile(); newTile.AssignNewTile(originalTile.arrayPosition, originalTile.creator, Color.black); //Tile will sort its self out DestroyImmediate(originalTile); return(newTile); }
private List <Tile> FindScalingNeighbors(Tile.TileTypes requireTileType, List <Tile> neighbors) { List <Tile> result = new List <Tile>(); foreach (Tile tile in neighbors) { if (tile._type == requireTileType) { result.Add(tile); } } return(result); }
public void UpdateTurf() { Tile.TileTypes new_turfDescriptor = gameObject.GetComponent <Tile>().TileDescriptor; if (new_turfDescriptor != turfDescriptor) { turfDescriptor = new_turfDescriptor; BuildTurf(); } else { UpdateUpper(); UpdateLower(); } }
private void OnGUI() { buildMode = EditorGUILayout.Toggle("Enable Editor:", buildMode); editorFunction = (EditorFunction)EditorGUILayout.EnumPopup("Editor Function:", editorFunction); deleteMode = EditorGUILayout.Toggle("Delete?:", deleteMode); y_select = EditorGUILayout.IntField("Y-Level: ", y_select); DrawUILine(Color.gray); switch (editorFunction) { case (EditorFunction.add_tiles): selectedTileType = (Tile.TileTypes)EditorGUILayout.EnumPopup("TileType:", selectedTileType); upperTurfStat = EditorGUILayout.IntField("Upper Turf Status:", upperTurfStat); lowerTurfStat = EditorGUILayout.IntField("Lower Turf Status:", lowerTurfStat); break; case (EditorFunction.build_furniture): buildOrientation = EditorGUILayout.IntField("Orientation:", buildOrientation); LoadFurnitureTypes(); LoadPrefabFurniture(furnitureTypes[furnitureTypes_index]); //buildTarget = EditorGUILayout.ObjectField("Build Target: ", buildTarget, typeof(GameObject), false) as GameObject; break; case (EditorFunction.build_disposal): //buildTarget = EditorGUILayout.ObjectField("Build Target: ", buildTarget, typeof(GameObject), false) as GameObject; pipeConnectN = EditorGUILayout.Toggle("Connect N:", pipeConnectN); pipeConnectE = EditorGUILayout.Toggle("Connect E:", pipeConnectE); pipeConnectS = EditorGUILayout.Toggle("Connect S:", pipeConnectS); pipeConnectW = EditorGUILayout.Toggle("Connect W:", pipeConnectW); pipeConnectAuto = EditorGUILayout.Toggle("Auto Connect:", pipeConnectAuto); break; case (EditorFunction.build_blue): //buildTarget = EditorGUILayout.ObjectField("Build Target: ", buildTarget, typeof(GameObject), false) as GameObject; pipeConnectN = EditorGUILayout.Toggle("Connect N:", pipeConnectN); pipeConnectE = EditorGUILayout.Toggle("Connect E:", pipeConnectE); pipeConnectS = EditorGUILayout.Toggle("Connect S:", pipeConnectS); pipeConnectW = EditorGUILayout.Toggle("Connect W:", pipeConnectW); pipeConnectAuto = EditorGUILayout.Toggle("Auto Connect:", pipeConnectAuto); break; case (EditorFunction.build_red): //buildTarget = EditorGUILayout.ObjectField("Build Target: ", buildTarget, typeof(GameObject), false) as GameObject; pipeConnectN = EditorGUILayout.Toggle("Connect N:", pipeConnectN); pipeConnectE = EditorGUILayout.Toggle("Connect E:", pipeConnectE); pipeConnectS = EditorGUILayout.Toggle("Connect S:", pipeConnectS); pipeConnectW = EditorGUILayout.Toggle("Connect W:", pipeConnectW); pipeConnectAuto = EditorGUILayout.Toggle("Auto Connect:", pipeConnectAuto); break; } }
private void PropertiesWindow(int id) { EditorGUILayout.BeginVertical(); // Show tile properties if any tile is selected if (selectedTileId >= 0) { Tile selectedTile = tilemap.Tiles[selectedTileId]; EditorGUI.BeginChangeCheck(); Tile.TileTypes type = (Tile.TileTypes)EditorGUILayout.EnumPopup("Tile Type:", selectedTile.TileType); if (EditorGUI.EndChangeCheck() && type != selectedTile.TileType) { // Change underlying tile's type only when change really happened instead of changing it every frame // Otherwise, all components' values will be constantly reset because of Tile's set TileTypes method selectedTile.TileType = type; AddComponentsToTile(selectedTile); } switch (selectedTile.TileType) { case Tile.TileTypes.Destructible: case Tile.TileTypes.Enemy: case Tile.TileTypes.Player: Destructible destructible = selectedTile.FindComponent <Destructible>(); destructible.Lives = EditorGUILayout.IntSlider("Health", destructible.Lives, 1, 5); break; case Tile.TileTypes.Item: Item item = selectedTile.FindComponent <Item>(); item.RestoreHealthBy = EditorGUILayout.IntSlider("Restore Health by", item.RestoreHealthBy, 0, 5); item.IncreaseBombsBy = EditorGUILayout.IntSlider("Increase # of bombs by", item.IncreaseBombsBy, 0, 3); break; default: break; } if (spritesheet != null) { EditorGUILayout.LabelField("Sprite"); //Draw sprite selectedTile.SpriteId = EditorGUILayout.IntSlider(selectedTile.SpriteId, 0, tilemap.Sprites.Count - 1); GUI.DrawTextureWithTexCoords(new Rect(10, 150, 64, 64), spritesheet, tilemap.Sprites[selectedTile.SpriteId].DrawArea); } EditorGUILayout.EndVertical(); } }
// TODO: I am not sure how to compute efficiency. Here is my understanding: // Efficiency is the average of // - surrounding tiles // - number of employees // - happiness of employees float ComputeEfficiency() { float result = 1f; // compute efficiency based on surrounding tiles if (this._scalesWithNeighboringTiles) { Tile.TileTypes tt = Tile.TileTypes.Empty; switch (this._type) { case BuildingType.Fishery: tt = Tile.TileTypes.Water; break; case BuildingType.Lumberjack: tt = Tile.TileTypes.Forest; break; case BuildingType.SheepFarm: case BuildingType.PotatoFarm: tt = Tile.TileTypes.Grass; break; } int surroundingTiles = this._tile._neighbourTiles.FindAll(t => t._type == tt).Count; if (this._maxNeighbors <= surroundingTiles) { result = 1f; } if (this._minNeighbors > surroundingTiles) { result = 0f; } result = (float)surroundingTiles / this._maxNeighbors; } // add effiency based on the precentage of employment result += (float)_workers.Count / this._jobsCapacity; // add effiency based on happiness of workers if (_workers.Count > 0) { result += (float)_workers.Sum(w => w._happiness) / _workers.Count; } Debug.Log("Efficiency: " + result); return((float)result * 1 / 3); }
// Update is called once per frame void Update() { SetMousePosition(); AdjustClock(); if (curMode == Mode.Run) { if (Input.GetButtonDown("Fire1") && !EventSystem.current.IsPointerOverGameObject()) { Debug.Log(mouseOverTile.GetTileType()); Tile.TileTypes tType = mouseOverTile.GetTileType(); if (tType == Tile.TileTypes.Building) { ui.SetBuildingSelector(mouseOverTile as BuildableTile); } else if (tType == Tile.TileTypes.BuildingChild) { ui.SetBuildingSelector(((BuildableTileChild)mouseOverTile).GetParent()); } else { ui.HideBuildingSelector(); } } } else if (curMode == Mode.Build) { buildMode.Build(mouseOverTile); if (Input.GetButtonDown("Fire1") && !EventSystem.current.IsPointerOverGameObject()) { buildMode.AttemptToBuild(); } } if (Input.GetKeyDown(KeyCode.Escape)) { StartRunMode(); ui.HideBuildMenu(); ui.HideBuildingSelector(); } }
public Tile ParseTileData(string spriteName) { //Default type Tile.TileTypes newType = Tile.TileTypes.HEALTH; string[] split = spriteName.Split('_'); string type = split[0]; int tileValue = Convert.ToInt32(split[1]); switch (type.ToLower()) { case "health": newType = Tile.TileTypes.HEALTH; break; case "money": newType = Tile.TileTypes.MONEY; break; case "social": newType = Tile.TileTypes.SOCIAL; break; case "time": newType = Tile.TileTypes.TIME; break; default: break; } Tile newTile = new Tile(newType, tileValue); newTileToSwap = newTile; return(newTile); }
private void ValidateCard(Tile.TileTypes type, int amount) { switch (type) { case Tile.TileTypes.SOCIAL: if (PlayerInventory.Social < amount) { this.enabled = false; } break; case Tile.TileTypes.HEALTH: if (PlayerInventory.Health < amount) { this.enabled = false; } break; case Tile.TileTypes.MONEY: if (PlayerInventory.Money < amount) { this.enabled = false; } break; case Tile.TileTypes.TIME: if (PlayerInventory.Time < amount) { this.enabled = false; } break; default: break; } }
void ChangeTo(Tile.TileTypes newType) { BaseTile.ChangeTo(newType, (BaseTile)target); }
public static void GetResources(Tile.TileTypes Type, GameObject MapStart, out GameObject ATile) { ATile = Instantiate(Tools.FindPfbPerName("tile_pfb"), MapStart.transform) as GameObject; ATile.SetActive(false); Sprite spr; switch (Type) { case Tile.TileTypes.TILE_START: // start spr = Tools.FindSpritePerName("tile_start"); break; case Tile.TileTypes.TILE_BOMB: // bomb spr = Tools.FindSpritePerName("tile_bomb"); break; case Tile.TileTypes.TILE_DICE: // dice spr = Tools.FindSpritePerName("tile_dice"); break; case Tile.TileTypes.TILE_REWARD: // reward spr = Tools.FindSpritePerName("tile_reward"); break; case Tile.TileTypes.TILE_SWITCH: // switch spr = Tools.FindSpritePerName("tile_switch"); break; case Tile.TileTypes.TILE_CATCHCOINS: // catchcoins spr = Tools.FindSpritePerName("tile_catchcoins"); break; case Tile.TileTypes.TILE_GUESSBOX: // guessbox spr = Tools.FindSpritePerName("tile_guessbox"); break; case Tile.TileTypes.TILE_BOXREWARD_1: // box1 spr = Tools.FindSpritePerName("tile_boxreward_1"); break; case Tile.TileTypes.TILE_BOXREWARD_2: // box2 spr = Tools.FindSpritePerName("tile_boxreward_2"); break; case Tile.TileTypes.TILE_CUP: // cup spr = Tools.FindSpritePerName("tile_cup"); break; case Tile.TileTypes.TILE_BOSS: // boss spr = Tools.FindSpritePerName("tile_boss"); break; case Tile.TileTypes.TILE_APPLE: // apple spr = Tools.FindSpritePerName("tile_apple"); break; case Tile.TileTypes.TILE_BUG: // bugs spr = Tools.FindSpritePerName("tile_bug"); break; case Tile.TileTypes.TILE_FOOD: // foods spr = Tools.FindSpritePerName("tile_food"); break; case Tile.TileTypes.TILE_HISTORY: // history spr = Tools.FindSpritePerName("tile_history"); break; case Tile.TileTypes.TILE_HUMAN: // human spr = Tools.FindSpritePerName("tile_human"); break; default: spr = Tools.FindSpritePerName("tile_dice"); break; } Tools.SetObjAndSprSameSize(ATile, spr); ATile.GetComponent <Image>().sprite = spr; }
public CreatureGeneModifier(Tile.TileTypes tileType, CreatureStatType statType, float modValue) { this.tileType = tileType; this.statType = statType; this.modifierValue = modValue; }
/// <summary> /// Call this to put a message back to its default state. /// </summary> public override void Reset() { mPosition_In = Vector2.Zero; mType_In = Tile.TileTypes.Empty; mPreviousType_Out = Tile.TileTypes.Empty; }
public void DoEvent(Tile.TileTypes Type, GM inGM) { GameObject ca = GameObject.FindGameObjectWithTag("PopCanvas"); switch (Type) { case Tile.TileTypes.TILE_START: // start // 不会发生任何事情 break; case Tile.TileTypes.TILE_BOMB: // bomb GameObject ExplodePfb = Instantiate(Tools.FindPfbPerName("explode_pfb"), GameObject.FindGameObjectWithTag("mapcanvas").transform) as GameObject; ExplodePfb.transform.position = inGM.Niko.Position.TilePfb.transform.position; ExplodePfb.SetActive(true); ExplodePfb.transform.DOLocalMoveY(ExplodePfb.transform.localPosition.y + 100, 1).OnComplete(() => { GameObject.Destroy(ExplodePfb); }); // StartCoroutine(PlayAnimation()); inGM.PlayerGoBack(); break; case Tile.TileTypes.TILE_DICE: // dice inGM.PlayerGoForward(UnityEngine.Random.Range(1, 4)); break; case Tile.TileTypes.TILE_REWARD: // reward GameObject CpinsPfb = Instantiate(Tools.FindPfbPerName("coins_pfb"), GameObject.FindGameObjectWithTag("mapcanvas").transform) as GameObject; CpinsPfb.transform.position = inGM.Niko.Position.TilePfb.transform.position; CpinsPfb.SetActive(true); CpinsPfb.transform.DOLocalMoveY(CpinsPfb.transform.localPosition.y + 100, 1).OnComplete(() => { GameObject.Destroy(CpinsPfb); }); break; case Tile.TileTypes.TILE_SWITCH: // switch break; case Tile.TileTypes.TILE_CATCHCOINS: // catchcoins GameObject CollectGame = Instantiate(Tools.FindPfbPerName("collectgame_pfb"), ca.transform) as GameObject; CollectGame.GetComponent <CollectGameClick>().TM = this; CollectGame.SetActive(true); break; case Tile.TileTypes.TILE_GUESSBOX: // guessbox GameObject GuessBox = Instantiate(Tools.FindPfbPerName("guessbox_pfb"), ca.transform) as GameObject; GuessBox.GetComponent <ChooseBoxClick>().TM = this; GuessBox.SetActive(true); break; case Tile.TileTypes.TILE_BOXREWARD_1: // box1 case Tile.TileTypes.TILE_BOXREWARD_2: // box2 ca.transform.Find("GetReward").gameObject.SetActive(true); break; case Tile.TileTypes.TILE_CUP: // cup break; case Tile.TileTypes.TILE_BOSS: // boss case Tile.TileTypes.TILE_APPLE: // apple case Tile.TileTypes.TILE_BUG: // bugs case Tile.TileTypes.TILE_FOOD: // foods case Tile.TileTypes.TILE_HISTORY: // history case Tile.TileTypes.TILE_HUMAN: // human GameObject WordGame = Instantiate(Tools.FindPfbPerName("wordgame_pfb"), ca.transform) as GameObject; WordGame.GetComponent <WordGameClick>().TM = this; WordGame.GetComponent <WordGameClick>().inGM = inGM; WordGame.SetActive(true); break; default: break; } inGM.ResetDice(); if (Type != Tile.TileTypes.TILE_BOMB) { inGM.LocateCamera(); } }
public void SetTile(Tile.TileTypes tileType) { this.n_TileType = (byte)tileType; // set dirtyBit Trigger 001<Tile> 010<Turf> 100<Pipe> SetDirtyBit(base.syncVarDirtyBits ^ 0b001); }