public void OnPointerClick(PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Left) { if (TryGetBuildingOrigin(out Vector2Int origin) && _selectedBody.Buildings.IsValidBuilding(_building, origin, _rotation)) { Debug.Log($"Building {BuildingSelection.GetSelectedBuilding().DisplayName} at {origin}"); _selectedBody.Buildings.ConstructBuilding(_building, origin, _rotation); foreach (BuildingCost cost in _building.Costs) { _selectedBody.Resources[cost.Resource] -= cost.Amount; } if (!(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { BuildingSelection.CancelSelection(); _building = null; } RedrawBuildings(); RedrawBuildingPreview(); } } else if (eventData.button == PointerEventData.InputButton.Right) { _rotation = (_rotation + 1) % 4; RedrawBuildingPreview(); } }
public IEnumerable <OffsetAndRotation> AllBuildableLocations(BuildingTemplate buildingTemplate, IntegerRect?rect = null) { int boardWidth = Width; int boardHeight = Height; var boundingRect = rect ?? new IntegerRect(0, 0, boardWidth, boardHeight); foreach (var orientation in buildingTemplate.MeaningfulOrientations()) { var rotatedBuilding = new RotatedBuilding(buildingTemplate, orientation); int availableXOffset = boundingRect.xMax - rotatedBuilding.Width + 1; int availableYOffset = boundingRect.yMax - rotatedBuilding.Height + 1; for (int buildingOffsetX = boundingRect.x; buildingOffsetX < availableXOffset; buildingOffsetX++) { for (int buildingOffsetY = boundingRect.y; buildingOffsetY < availableYOffset; buildingOffsetY++) { var buildLocation = new OffsetAndRotation(new Integer2(buildingOffsetX, buildingOffsetY), orientation); if (CanBuildBuilding(buildLocation, rotatedBuilding)) { yield return(buildLocation); } } } } }
public Building GetNewBuilding(string templateName) { BuildingTemplate template = _buildingTemplates[templateName]; BuildingTile[,] tiles = new BuildingTile[template.Size.X, template.Size.Y]; for (int i = 0; i < template.Size.X; i++) { for (int j = 0; j < template.Size.Y; j++) { BulidingTileTemplate tileTemplate = template.Tiles.First(p => p.Position == new Point(i, j)); tiles[i, j] = new BuildingTile() { BuildingTileType = BuildingTileType.Construction, CanAccess = tileTemplate.CanAccess, ItemSpace = 0, Position = new Point(i, j), Texture = tileTemplate.Texture }; } } List <string> requiredMats = new List <string>(); foreach (var buildingMaterialTemplate in template.RequiredMaterials) { for (int i = 0; i < buildingMaterialTemplate.Count; i++) { requiredMats.Add(buildingMaterialTemplate.ItemName); } } Building returnMe = new Building(template.Size, tiles, requiredMats, _owner); returnMe.Id = new Guid(); return(returnMe); }
public void Render(BuildingTemplate buildingTemplate, OffsetAndRotation offsetAndRotation) { if (buildingName != null) { buildingName.text = buildingTemplate.DisplayName; } }
public void SetData(BuildingTemplate building) { _linkedBuilding = building; _icon.sprite = building.Icon; _name.text = building.Name; _buttonComponent.onClick.AddListener(OnClick); }
private void WriteAllOrientations(BuildingTemplate buildingTemplate) { WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.None)); WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.MirrorX)); WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.MirrorY)); WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.MirrorXandY)); WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.Rotate90)); WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.Rotate90MirrorX)); WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.Rotate90MirrorY)); WriteBuilding(new RotatedBuilding(buildingTemplate, BuildingOrientation.Rotate90MirrorXandY)); }
public void RotateLongBuildings() { var buildingTemplate = new BuildingTemplate() { Recipe = new string[, ] { { "1", "2", "3", "4", "5", "6" }, { "x", "-", "-", "-", "-", "-" }, } }; WriteAllOrientations(buildingTemplate); }
/// <summary> /// Called by UI when building is done on this Tile /// </summary> /// <param name="isBuilded"></param> public void SetBuilding(BuildingTemplate buildingTemplate) { print("lancement de la construction " + buildingTemplate.building._name); Vector3 tilePosition = gameObject.transform.position; tilePosition.y += 0.7f; GameObject newBuilding = Instantiate(buildingTemplate.buildingPrefab); newBuilding.transform.SetParent(gameObject.transform); newBuilding.transform.position = tilePosition; this.isBuilded = true; }
public void RotateBuildings() { var buildingTemplate = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x", "x" }, { "x", "-", "-" }, } }; WriteAllOrientations(buildingTemplate); }
// Creates BuildingTemplate to place public void CreateBuildingTemplate(int buildingIndex) { // Destroying buildingTempla selected to place, if there is if (_buildingObject) { _building.SelfDestruction(); Destroy(_buildingObject); } // Creating a building gameObject _buildingObject = Instantiate(_manager.GameConfig.BuildingTemplate, Vector3.back, Quaternion.identity) as GameObject; _building = _buildingObject.GetComponent <BuildingTemplate>(); _building.CreateBuilding(buildingIndex, _manager); }
/// <summary> /// Check to see if construction is possible. /// </summary> /// <param name="targetPos">Where to construct the building.</param> /// <param name="buildingToConstruct">The building to construct.</param> /// <returns>Returns true if the building can be constructed.</returns> public bool CheckConstructionAble(Point targetPos, string buildingToConstruct) { BuildingTemplate toBeConstructed = BuildingFactory.Instance.BuildingTemplates[buildingToConstruct]; for (int i = 0; i < toBeConstructed.Size.X; i++) { for (int j = 0; j < toBeConstructed.Size.Y; j++) { if (!Owner.Environment[targetPos.X + i, targetPos.Y + j].CanAccess) { return(false); } } } return(true); }
public void RotateTallBuildings() { var buildingTemplate = new BuildingTemplate() { Recipe = new string[, ] { { "1", "x" }, { "2", "-" }, { "3", "-" }, { "4", "-" }, { "5", "-" }, { "6", "-" }, } }; WriteAllOrientations(buildingTemplate); }
public void InitBuilding(Vector2 position, Polygon polygon, BuildingTemplate template) { // Place the building on the X and Y axis, then update his Z position transform.position = position; UpdateZ(); // Link this building to its polygon _parentPolygon = polygon; _parentPolygon.LinkedBuilding = this; // Copy templates properties SetMaterial(template.Mat); _growingSpeed = template.GrowSpeed; _resistance = template.Resistance; _attackDamage = template.AttackDamage; _isEnemy = template.IsEnemy; }
private void Update() { if (!_hover) { return; } if (TryGetBuildingOrigin(out Vector2Int newOrigin)) { BuildingTemplate newBuilding = BuildingSelection.GetSelectedBuilding(); if (newBuilding != _building || newOrigin != _origin) { _building = newBuilding; _origin = newOrigin; RedrawBuildingPreview(); } } }
public void ConstructBuilding(BuildingTemplate template, Vector2Int origin, int rotation) { if (!IsValidBuilding(template, origin, rotation)) { Debug.LogError( "Attempting to build invalid configuration.\n" + $"Building{template.DisplayName} origin {origin} rotation {rotation}" ); return; } var building = new BuildingInstance(template, rotation); _buildingOrigin[building] = origin; foreach (BuildingTile tile in template.Tiles) { Vector2Int offset = Rotate(tile.Offset, rotation); _slotToBuilding[origin + offset] = building; } }
private void Update() { optionsPool.Flush(); var board = gameViewRenderer.Lobby.Gameplay.Players[0].Board; var building = new BuildingTemplate() { DisplayName = "Name", Recipe = new string[, ] { { "x", "x" } } }; foreach (var option in board.AllBuildableLocations(building, gameViewRenderer.ThisPlayerSelection.AsIntegerRect)) { var optionRenderer = optionsPool.Grab(holder); optionRenderer.Render(building, option); } }
public bool IsValidBuilding(BuildingTemplate template, Vector2Int origin, int rotation) { if (template == null) { return(false); } foreach (BuildingTile tile in template.Tiles) { Vector2Int position = origin + Rotate(tile.Offset, rotation); if (IsOccupied(position)) { return(false); } if (!InBounds(position)) { return(false); } } return(true); }
public override ProcedureResult Apply(LobbyView view) { var buildingTemplate = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x", "x" }, { "x", null, null }, } }; var rotatedBuilding = new RotatedBuilding(buildingTemplate, Orientation); var gameplayPlayer = view.Gameplay.Players[Player]; for (int x = 0; x < rotatedBuilding.Width; x++) { for (int y = 0; y < rotatedBuilding.Height; y++) { var position = Offset + new Integer2(x, y); string recipeTile = rotatedBuilding[x, y]; var tile = gameplayPlayer.Board[position]; if (recipeTile != null) { tile.Resource = "q"; } } } var placeTile = gameplayPlayer.Board[BuildingPosition]; placeTile.Building = new Building(BuildingIdentifier); return(ProcedureResult.Success); }
private bool CanBuild(BuildingTemplate building) { return(building.Costs.All(cost => _selectedBody.Resources[cost.Resource] >= cost.Amount)); }
public RotatedBuilding(BuildingTemplate template, BuildingOrientation orientation) { Template = template; Orientation = orientation; }
public int Rotation; // Number of times rotated counter-clockwise public BuildingInstance(BuildingTemplate template, int rotation) { Template = template; EffectGroups = template.EffectGroups.Select(group => new EffectGroupInstance(group)).ToArray(); Rotation = rotation; }
public Building(BuildingTemplate template, GameTile tile) { Template = template; Tile = tile; }
void OnBuildButtonClick(BuildingTemplate buildingTemplate) { CurrentTile.SetBuilding(buildingTemplate); this.Display(false); }
public void DetermineAllBuildableLocations() { var board = new GameBoard(4, 4); board[0, 0].Resource = "x"; board[0, 1].Resource = "x"; board[2, 1].Resource = "x"; board[3, 1].Resource = "x"; board[0, 2].Resource = "y"; board[0, 3].Resource = "y"; board[1, 2].Resource = "y"; board[1, 3].Resource = "y"; for (int y = 4 - 1; y >= 0; y--) { for (int x = 0; x < board.Width; x++) { var tile = board[x, y]; Console.Write(tile.ToChar()); } Console.Write("\n"); } Console.Write("\n"); var cottage = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x" } } }; var blockCottage = new BuildingTemplate() { Recipe = new string[, ] { { "y", "y" }, { "y", null } } }; var longCottage = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x", "x" }, { "x", null, null } } }; Console.WriteLine($"--[Cottage]--"); foreach (var location in board.AllBuildableLocations(cottage)) { Console.WriteLine($"{location.Offset} {location.Orientation}"); } Console.WriteLine($"\n--[Block Cottage]--"); foreach (var location in board.AllBuildableLocations(blockCottage)) { Console.WriteLine($"{location.Offset} {location.Orientation}"); } Console.WriteLine($"\n--[Block Cottage]-- (minus bottom)"); foreach (var location in board.AllBuildableLocations(blockCottage, new IntegerRect(0, 2, 4, 2))) { Console.WriteLine($"{location.Offset} {location.Orientation}"); } }
public void DeterminePatternSymmetryAndRotatable() { var pattern1x1 = new BuildingTemplate() { Recipe = new string[, ] { { "x" } } }; var pattern2x1 = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x" } } }; var pattern2x2 = new BuildingTemplate() { Recipe = new string[, ] { { "y", "y" }, { "y", "y" } } }; var pattern2x2MinusLowerLeft = new BuildingTemplate() { Recipe = new string[, ] { { "y", "y" }, { "y", null } } }; var pattern2x2MinusTopRight = new BuildingTemplate() { Recipe = new string[, ] { { null, "y" }, { "y", "y" } } }; var pattern3x2L = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x", "x" }, { "x", null, null } } }; var pattern4x2L = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x", "x", "x" }, { "x", null, null, null } } }; var pattern4x2T = new BuildingTemplate() { Recipe = new string[, ] { { "x", null }, { "x", "x" }, { "x", "x" }, { "x", null }, } }; var pattern4x2TRotated = new BuildingTemplate() { Recipe = new string[, ] { { "x", "x", "x", "x" }, { null, "x", "x", null } } }; Assert.IsTrue(pattern1x1.IsVerticallySymmetric); Assert.IsTrue(pattern1x1.IsHorizontallySymmetric); Assert.IsFalse(pattern1x1.IsRotating); Assert.IsTrue(pattern2x1.IsVerticallySymmetric); Assert.IsTrue(pattern2x1.IsHorizontallySymmetric); Assert.IsTrue(pattern2x1.IsRotating); Assert.IsTrue(pattern2x2.IsVerticallySymmetric); Assert.IsTrue(pattern2x2.IsHorizontallySymmetric); Assert.IsFalse(pattern2x2.IsRotating); Assert.IsFalse(pattern2x2MinusLowerLeft.IsVerticallySymmetric); Assert.IsFalse(pattern2x2MinusLowerLeft.IsHorizontallySymmetric); // Can achieve the same pattern without using rotation Assert.IsFalse(pattern2x2MinusLowerLeft.IsRotating); Assert.IsFalse(pattern2x2MinusTopRight.IsVerticallySymmetric); Assert.IsFalse(pattern2x2MinusTopRight.IsHorizontallySymmetric); // Can achieve the same pattern without using rotation Assert.IsFalse(pattern2x2MinusLowerLeft.IsRotating); Assert.IsFalse(pattern3x2L.IsVerticallySymmetric); Assert.IsFalse(pattern3x2L.IsHorizontallySymmetric); Assert.IsTrue(pattern3x2L.IsRotating); Assert.IsFalse(pattern4x2L.IsVerticallySymmetric); Assert.IsFalse(pattern4x2L.IsHorizontallySymmetric); Assert.IsTrue(pattern4x2L.IsRotating); Assert.IsFalse(pattern4x2T.IsVerticallySymmetric); Assert.IsTrue(pattern4x2T.IsHorizontallySymmetric); Assert.IsTrue(pattern4x2T.IsRotating); Assert.IsTrue(pattern4x2TRotated.IsVerticallySymmetric); Assert.IsFalse(pattern4x2TRotated.IsHorizontallySymmetric); Assert.IsTrue(pattern4x2TRotated.IsRotating); }
internal void CreateFromTemplate(BuildingTemplate bt, float pan) { Template = bt; StartingPopulation = _Population = Template.Population; _Health = Template.StartingHealth; FillRequirement.Add(Element.Electricity, delegate(Building b){ return(b.Statuses[Element.Water].Value > 0 && Statuses[Element.Water].Value > 0); }); FillRequirement.Add(Element.Water, delegate(Building b){ return (( ( ( //side up check if is in water GetNeighbour(b, Side.Up) != null && GetNeighbour(b, Side.Up).Statuses[Element.Water].Value > 0 && ( GetNeighbour(b, Side.Up).Health == 0 || GetNeighbour(b, Side.Up).Statuses[Element.Water].IsSource() ) ) || ( //side down check if is in water GetNeighbour(b, Side.Down) != null && GetNeighbour(b, Side.Down).Statuses[Element.Water].Value > 0 && ( GetNeighbour(b, Side.Down).Health == 0 || GetNeighbour(b, Side.Down).Statuses[Element.Water].IsSource() ) ) || ( //side left check if is in water GetNeighbour(b, Side.Left) != null && GetNeighbour(b, Side.Left).Statuses[Element.Water].Value > 0 && ( GetNeighbour(b, Side.Left).Health == 0 || GetNeighbour(b, Side.Left).Statuses[Element.Water].IsSource() ) ) || ( //side right check if is in water GetNeighbour(b, Side.Right) != null && GetNeighbour(b, Side.Right).Statuses[Element.Water].Value > 0 && ( GetNeighbour(b, Side.Right).Health == 0 || GetNeighbour(b, Side.Right).Statuses[Element.Water].IsSource() ) ) ) ) && ( b.Statuses[Element.Water].Value == 0 || b.Statuses[Element.Water].Value < Statuses[Element.Water].Value )); }); startingPos = GameObjectBuilding.GetComponent <RectTransform>().localPosition; Dictionary <Element, GameObject> elGo = new Dictionary <Element, GameObject>(); elGo.Add(Element.Fire, GameObjectFire); elGo.Add(Element.Water, GameObjectWaterLevel); elGo.Add(Element.SmokeAfterFire, GameObjectSmokeAfterFire); elGo.Add(Element.Electricity, GameObjectElectricity); elGo.Add(Element.Crush, GameObjectCrush); elGo.Add(Element.Die, GameObjectDie); //this is telling the sprite how to resize Dictionary <Element, bool> resizeFromDown = new Dictionary <Element, bool>(); resizeFromDown.Add(Element.Fire, true); resizeFromDown.Add(Element.Water, false); resizeFromDown.Add(Element.SmokeAfterFire, false); resizeFromDown.Add(Element.Electricity, true); resizeFromDown.Add(Element.Crush, false); resizeFromDown.Add(Element.Die, false); //initializing statuses foreach (Element e in new Element[] { Element.Fire, Element.Water, Element.SmokeAfterFire, Element.Electricity, Element.Crush, Element.Die }) { float fillSpeedF = bt.Stats[StatType.FillSpeed][e]; float strikeDamageF = bt.Stats[StatType.StrikeDamage][e]; float effectDamageF = bt.Stats[StatType.EffectDamage][e]; float effectTimeF = bt.Stats[StatType.EffectTime][e]; bool resizeFromDownTmp = resizeFromDown[e]; Statuses.Add(e, new BuildingStatus(elGo[e], bt.Effects[e], SoundManager.Clips[e], effectDamageF, effectTimeF, strikeDamageF, fillSpeedF, SpriteManager.ElementPerBuildingSprites[SpriteManager.DefaultEffectPaths[e]], resizeFromDownTmp, pan)); } }