// Player right clicks public void PlayerRightClicksAtWorldPosition(Vector3 worldPosition) { // Return if no selected piece if (!selectedPiece) { return; } // Get clicked on hex GameHex targetHex = gameMap.GetWorldPositionHex(worldPosition); if (targetHex == null) { return; } // Move or attack piece if (actionMap.MoveableToTileAtTileCoords(targetHex.tileCoords)) { gameMap.MovePiece((Unit)selectedPiece, targetHex.hexCoords); actionMap.ClearActionTiles(); return; } if (actionMap.AttackableTileAtTileCoords(targetHex.tileCoords)) { gameMap.AttackPiece(selectedPiece, targetHex.piece); actionMap.ClearActionTiles(); return; } }
void OnPieceClickedSetup(Piece piece, GameHex hex) { if (piece == currentSelectedPiece && IsValidPosition(piece)) { PiecePlaced(piece); } }
private void OnHexMouseDown(GameHex gameHex) { if (mode != EMode.Inactive) { OnPieceClicked.Invoke(this, gameHex); } }
public void Setup() { gameMap = GameMapUTests.CreateTestGameMap(); player1 = PlayerUTests.CreateTestPlayer(1); player2 = PlayerUTests.CreateTestPlayer(2); player1Camera = MapCameraUTests.CreateTestMapCamera(); player2Camera = MapCameraUTests.CreateTestMapCamera(); player1.gameMap = gameMap; player2.gameMap = gameMap; player1.playerCamera = player1Camera; player2.playerCamera = player2Camera; actionMap = player1.actionMap; unit1 = UnitCardUnitITests.CreateTestUnitWithCard(); unit2 = UnitCardUnitITests.CreateTestUnitWithCard(); unit1.player = player1; unit2.player = player2; hexCoords = new Vector3Int(0, 0, 0); targetHexCoords = new Vector3Int(1, -1, 0); mousePosition = gameMap.HexToWorldCoords(hexCoords); player1Camera.MoveCameraToPosition(mousePosition); player2Camera.MoveCameraToPosition(mousePosition); gameMap.AddPiece(unit1, hexCoords); // Get center hex gameHex = gameMap.GetWorldPositionHex(Vector3Int.zero); }
// Get hex piece from world position public GamePiece GetHexPieceFromWorldPosition(Vector3 worldPosition) { GameHex gameHex = GetWorldPositionHex(worldPosition); if (gameHex != null) { return(gameHex.piece); } return(null); }
public void AttacksAndKillsPiece() { Vector3Int targetHexCoords = new Vector3Int(1, -1, 0); gameMap.AddPiece(unit2, targetHexCoords); // Confirm piece is attacked and dies GameHex targetHex = gameMap.GetHexAtHexCoords(targetHexCoords); gameMap.AttackPiece(unit1, unit2); Assert.AreEqual(0, unit2.currentHealth); Assert.IsNull(targetHex.piece); Assert.IsTrue(unit2 == null); }
public void Setup() { gameMap = GameMapUTests.CreateTestGameMap(); player = PlayerUTests.CreateTestPlayer(); player.gameMap = gameMap; unit = UnitCardUnitITests.CreateTestUnitWithCard(); unit.player = player; hexCoords = new Vector3Int(0, 0, 0); gameMap.AddPiece(unit, hexCoords); // Get center hex and set selected piece gameHex = gameMap.GetWorldPositionHex(Vector3Int.zero); player.SetSelectedPiece(gameHex.piece); }
// Create hex based on type public static Hex CreateHex <T>(TileData defaultTile, Vector3Int newHexCoords) where T : Hex { if (typeof(T) == typeof(Hex)) { Hex newHex = new Hex(defaultTile, newHexCoords); return(newHex); } else if (typeof(T) == typeof(GameHex)) { GameHex newHex = new GameHex(defaultTile, newHexCoords); return(newHex); } return(null); }
void OnPieceClickedMain(Piece piece, GameHex hex) { if (!hex.IsPivotHex) { if (!piece.IsRotated()) { piece.SetPivotHex(hex); } } if (piece != currentSelectedPiece && piece.Mode == Piece.EMode.Active) { lastSelectedPiece = null; SelectPiece(piece); } }
public void CreatesHexStaticFunction() { // Create normal hex Hex hex = Hex.CreateHex <Hex>(TileUTests.CreateTestTileData(), Vector3Int.zero); Assert.IsNotNull(hex); Assert.AreEqual(Vector3Int.zero, hex.hexCoords); Assert.AreEqual(Vector3Int.zero, hex.tileCoords); // Create game hex GameHex gameHex = (GameHex)Hex.CreateHex <GameHex>(TileUTests.CreateTestTileData(), Vector3Int.zero); Assert.IsNotNull(gameHex); Assert.AreEqual(Vector3Int.zero, gameHex.hexCoords); Assert.AreEqual(Vector3Int.zero, gameHex.tileCoords); }
public HeroSystemCharacter() { initalizeCharasteristics(); initializeManuevers(); CharacterSenses = new CharacterSenses(this); CharacterMovement = new CharacterMovement(this); Size = new Size(); Size.MultiplierOfHexSize = 1; SegmentNumberThatLastPhaseActivatedOn = 0; PerceptionModifiers = new Dictionary <SenseGroupType, double>(); PerceptionMultipliers = new Dictionary <SenseGroupType, double>(); Hex = new GameHex(1, 1, 1); }
// Add a game piece to the map public bool AddPiece(GamePiece piece, Vector3Int hexCoords) { GameHex gameHex = GetHexAtHexCoords(hexCoords); if (!gameHex.HasPiece()) { // Associate hex with piece gameHex.piece = piece; piece.gameHex = gameHex; piece.SetPosition(this); // Update lists //piece.player.PlayPiece(piece); return(true); } return(false); }
public void MovesPiece1HexAway() { // Add piece GameHex startingHex = gameMap.GetHexAtHexCoords(hexCoords); gameMap.AddPiece(unit1, hexCoords); // Move piece Vector3Int targetHexCoords = new Vector3Int(1, -1, 0); GameHex targetHex = gameMap.GetHexAtHexCoords(targetHexCoords); gameMap.MovePiece(unit1, targetHexCoords); // Confirm piece is moved Assert.IsNull(startingHex.piece); Assert.AreEqual(unit1, targetHex.piece); Assert.AreEqual(4, unit1.remainingSpeed); }
public void CreatesHexStaticFunctionForNonCenterTiles() { // Create normal hex Vector3Int hexCoords = new Vector3Int(1, -1, 0); Vector3Int tileCoords = new Vector3Int(0, 1, 0); Hex hex = Hex.CreateHex <Hex>(TileUTests.CreateTestTileData(), hexCoords); Assert.IsNotNull(hex); Assert.AreEqual(hexCoords, hex.hexCoords); Assert.AreEqual(tileCoords, hex.tileCoords); // Create game hex GameHex gameHex = (GameHex)Hex.CreateHex <GameHex>(TileUTests.CreateTestTileData(), hexCoords); Assert.IsNotNull(gameHex); Assert.AreEqual(hexCoords, gameHex.hexCoords); Assert.AreEqual(tileCoords, gameHex.tileCoords); }
public void FastCharacterWithRunAndFlyAndCharacterInCombat() { Character = Factory.BaseCharacter; Character.SPD.MaxValue = 6; Run = Character.CharacterMovement.Run; RunManuever = Character.Manuevers["Run"] as MovementManuever; Flight = new Movement(Character, "Flight", 100, true); Flight.NonCombatModifer = 4; FlightManuever = Character.Manuevers["Flight"] as MovementManuever; Sequence = new CombatSequence.CombatSequence(); Sequence.AddCharacter(Character); Sequence.StartCombat(); CharacterMovement = Character.CharacterMovement; Character.Hex = new GameHex(0, 0, 0); CharacterHex = Character.Hex; }
// Create action map public void CreateActionMap(GamePiece piece, GameMap gameMap, FogMap fogOfWarMap) { ClearActionTiles(); if (piece == null) { return; } Vector3Int hexCoords = piece.gameHex.hexCoords; List <Vector3Int> visibleTileCoords = fogOfWarMap.GetVisibleTileCoords(); if (piece.pieceType == PieceType.Unit) { Unit unit = (Unit)piece; int remainingSpeed = unit.remainingSpeed; int range = unit.range; // Get hexes in range of unit movement and set tiles List <GameHex> gameHexes = gameMap.GetHexesInRange(gameMap.hexCoordsDict, hexCoords, remainingSpeed + range); for (int i = 0; i < gameHexes.Count; i++) { GameHex gameHex = gameHexes[i]; Vector3Int tileCoords = Hex.HexToTileCoords(gameHex.hexCoords); int distance = Hex.GetDistanceHexCoords(hexCoords, gameHex.hexCoords); // Set tile to appropriate movement tile type if (!gameHex.HasPiece()) { if (distance <= remainingSpeed) { paintedTiles[tileCoords] = movementTile; } } else { if (gameHex.piece.GetPlayerId() != unit.GetPlayerId() && visibleTileCoords.Contains(tileCoords)) { paintedTiles[tileCoords] = attackTile; } } } } }
// Create action map public void CreateActionMap(GamePiece piece, GameMap gameMap) { ClearActionTiles(); if (piece == null) { return; } Vector3Int hexCoords = piece.gameHex.hexCoords; List <GameHex> gameHexes = gameMap.GetHexesInPieceRange(piece); if (piece.pieceType == PieceType.Unit) { Debug.Log("Setting action map for unit"); Unit unit = (Unit)piece; int remainingSpeed = unit.remainingSpeed; Debug.Log("Remaining unit speed: " + remainingSpeed); Debug.Log("Game hex count: " + gameHexes.Count); // Get hexes in range of unit movement and set tiles for (int i = 0; i < gameHexes.Count; i++) { GameHex gameHex = gameHexes[i]; int distance = Hex.GetDistanceHexCoords(hexCoords, gameHex.hexCoords); // Set tile to appropriate movement tile type if (!gameHex.HasPiece() && distance <= remainingSpeed) { Debug.Log("Setting movement tile"); SetTileInTilemap(movementTile, gameHex.tileCoords, movementTiles); } else if (gameHex.HasPiece() && gameHex.piece.GetPlayerId() != unit.GetPlayerId()) { Debug.Log("Setting attack tile"); SetTileInTilemap(attackTile, gameHex.tileCoords, attackTiles); } } } tilemap.RefreshAllTiles(); Debug.Log("(1, -1, 0) tile: " + tilemap.GetTile(Hex.HexToTileCoords(new Vector3Int(1, -1, 0)))); Debug.Log("Set movement tiles : " + movementTiles.Count); Debug.Log("Set attack tiles : " + attackTiles.Count); }
void OnSceneGUI() { Layout.defaultLayout = new Layout(Layout.pointy, new Point(1, 1), new Point(0, 0)); if (Event.current != null) { GameHex gHex = target as GameHex; if (Event.current.type == EventType.MouseUp) { gHex.UpdatePosition(); } else if (Event.current.type == EventType.MouseDrag) { gHex.layer = Mathf.RoundToInt(gHex.transform.localPosition.y * 5); gHex.UpdateHex(new Point(gHex.transform.parent.transform)); gHex.coord = OffsetCoord.RoffsetFromCube(OffsetCoord.EVEN, gHex.hex); } } }
// Create playable map public void CreatePlayableMap(Vector3Int startTileCoords, GameMap gameMap) { ClearActionTiles(); // Get hexes in range of castle Vector3Int startHexCoords = Hex.TileToHexCoords(startTileCoords); List <GameHex> gameHexes = gameMap.GetHexesInRange(gameMap.hexCoordsDict, startHexCoords, 1); for (int i = 0; i < gameHexes.Count; i++) { GameHex gameHex = gameHexes[i]; Vector3Int tileCoords = Hex.HexToTileCoords(gameHex.hexCoords); // Set tile to appropriate movement tile type if (!gameHex.HasPiece()) { paintedTiles[tileCoords] = playableTile; } } }
public void SetPivotHex(GameHex pivotHex, bool force = false) { if (lockPivotHex && !force) { return; } //this could enable an exploit LockRotation(); transform.position = new Vector3(pivotHex.transform.position.x, 0, pivotHex.transform.position.z); Point pivotPoint = pivotHex.GlobalPoint; foreach (GameHex gameHex in GameHexes) { gameHex.UpdateHex(pivotPoint); gameHex.SetColourOuter(OuterSelected); } pivotHex.SetColourOuter(OuterPivot); }
// Moves a piece on the map public void MovePiece(Unit unit, Vector3Int targetHexCoords) { GameHex currentHex = unit.gameHex; GameHex targetHex = GetHexAtHexCoords(targetHexCoords); if (targetHex.HasPiece()) { return; } // Get distance traveled and update new hex int distance = Hex.GetDistanceHexes(currentHex, targetHex); if (distance <= unit.remainingSpeed) { unit.DecreaseSpeed(distance); unit.gameHex = targetHex; targetHex.piece = unit; currentHex.piece = null; unit.SetPosition(this); unit.player.SetSelectedPiece(null); } }
public void Teardown() { gameHex = null; }
public void Setup() { gameHex = CreateTestGameHex(); }
// Creates new game hex public static GameHex CreateTestGameHex() { GameHex newGameHex = new GameHex(TileUTests.CreateTestTileData(), Vector3Int.zero); return(newGameHex); }
public void Teardown() { gameHex = null; C.Destroy(unit.gameObject); C.Destroy(building.gameObject); }
public void Setup() { gameHex = GameHexUTests.CreateTestGameHex(); unit = UnitCardUnitITests.CreateTestUnitWithCard(); building = BuildingCardBuildingITests.CreateTestBuildingWithCard(); }
public void SetsSelectedPieceToNullOnHexWithCurrentlySelectedPieceClick() { gameHex = gameMap.GetWorldPositionHex(Vector3Int.zero); player.SetSelectedPiece(gameHex.piece); Assert.IsNull(player.selectedPiece); }
public void SetsSelectedPieceToNullOnHexWithoutPieceClick() { gameHex = gameMap.GetWorldPositionHex(new Vector3(1, 0.55f)); player.SetSelectedPiece(gameHex.piece); Assert.IsNull(player.selectedPiece); }
private void OnPieceClicked(Piece piece, GameHex hex) { if (currentPhase == GamePhase.Setup) { if (piece == currentSelectedPiece && IsValidPosition(piece)) PiecePlaced(piece); } else if (currentPhase == GamePhase.Main) { if (!hex.IsPivotHex) { if(!piece.IsRotated()) piece.SetPivotHex(hex); } if (piece != currentSelectedPiece && piece.Mode == Piece.EMode.Active) { if (currentSelectedPiece != null) { currentSelectedPiece.ResetRotation(); } lastSelectedPiece = null; currentSelectedPiece = piece; } } }
public static GameHex GameHex() { GameHex gHex = Instantiate(Instance.GameHexPrefab); return(gHex); }
// Update is called once per frame public void Update() { // Get map tile when click on map if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Vector3Int tileCoords = gameMapObject.GetMouseTileCoords(playerCamera.camera, Input.mousePosition); player.SetSelectedCard(null); Debug.Log("got tile coords: " + tileCoords); // Click on map tile if (tileCoords != null) { GameHex gameHex = gameMap.GetHexAtTileCoords(tileCoords); GamePiece piece = gameHex.piece; Debug.Log("got piece: " + piece); // Piece is on tile if (piece != null) { Debug.Log("piece id: " + piece.GetPlayerId() + " player id: " + player.playerId); // Piece is current player's if (piece.GetPlayerId() == player.playerId && player.isTurn) { // Piece is already selected if (piece == player.selectedPiece) { Debug.Log("piece is selected piece, clearing"); player.ClearSelectedPiece(); actionMapObject.PaintActionMap(); } else if (piece.hasActions) { Debug.Log("piece can move, creating map"); player.SetSelectedPiece(piece); actionMapObject.PaintActionMap(); } } // Piece is another player's // SHOW UNIT DETAILS } else { player.ClearSelectedPiece(); } } } // Get map tile when right click on map if (Input.GetMouseButtonDown(1) && !EventSystem.current.IsPointerOverGameObject()) { Vector3Int tileCoords = gameMapObject.GetMouseTileCoords(playerCamera.camera, Input.mousePosition); Debug.Log("got tile coords: " + tileCoords); // Click on map tile if (tileCoords != null) { // Play card from hand if (player.hasSelectedCard && player.actionMap.PlayableToTileAtTileCoords(tileCoords)) { Debug.Log("playing selected card"); PlaySelectedCardAtTile(tileCoords); } // Move or attack piece if (player.HasSelectedPiece()) { Debug.Log("player has selected piece"); // Move to tile if (player.actionMap.MoveableToTileAtTileCoords(tileCoords)) { Debug.Log("moving selected piece"); MovePiece(tileCoords); } // Attack tile else if (player.actionMap.AttackableTileAtTileCoords(tileCoords)) { Debug.Log("attacking piece"); AttackPiece(tileCoords); } } } } }