void OnTriggerEnter2D(Collider2D other) { if (friend == null) { if (other.gameObject.GetComponent<PlayerUnit>() != null) { friend = other.gameObject.GetComponent<PlayerUnit>(); } } }
// Update is called once per frame void Update() { if (isServer) { timelived += Time.deltaTime; if (timelived >= lifetime) { Destroy(gameObject); return; } if (enemy != null) { Vector3 velocity = enemy.transform.position - transform.position; velocity.z = 0; transform.Translate(velocity.normalized * movementSpeed * Time.smoothDeltaTime); } else { PlayerUnit[] players = Object.FindObjectsOfType<PlayerUnit>(); PlayerUnit closestPlayer = null; float closestDistance = 1000000; foreach (PlayerUnit player in players) { float distanceFromPlayer = (new Vector2(player.transform.position.x - transform.position.x, player.transform.position.y - transform.position.y)).magnitude; if (closestPlayer == null || distanceFromPlayer < closestDistance) { closestPlayer = player; closestDistance = distanceFromPlayer; } } if (closestPlayer != null) { enemy = closestPlayer; } } } }
//trigger when the unit heals public void trigger_heal(PlayerUnit self) { }
/// <summary> /// Choose target position when want to attack a group /// </summary> bool SetTargetAttackGroup(List <PlayerUnit> groupToAttack) { bool targetChange = false; canTargetAGroup = true; var lines = unitData.abilities.Where(x => x is Line).ToList(); choosedAbility = lines.ElementAt(Random.Range(0, lines.Count())); if (groupToAttack[0].positionGrid.x == groupToAttack[1].positionGrid.x) { int maxY = groupToAttack.OrderBy(x => x.positionGrid.y).ToList().Last().positionGrid.y; int minY = groupToAttack.OrderBy(x => x.positionGrid.y).ToList().First().positionGrid.y; if (Vector3Int.Distance(positionGrid, new Vector3Int(groupToAttack[0].positionGrid.x, maxY + choosedAbility.range, 0)) < Vector3Int.Distance(positionGrid, new Vector3Int(groupToAttack[0].positionGrid.x, minY - choosedAbility.range, 0))) { //verifier si cette position est accessible Vector3Int v = new Vector3Int(groupToAttack[0].positionGrid.x, maxY + choosedAbility.range, 0); targetChange = true; target = v; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(v.x, maxY, 0)] as PlayerUnit; if (!MorePointAction(true)) { Vector3Int pos = new Vector3Int(groupToAttack[0].positionGrid.x, minY - choosedAbility.range, 0); target = pos; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(v.x, minY, 0)] as PlayerUnit; } } else { //verifier si cette position est accessible Vector3Int v = new Vector3Int(groupToAttack[0].positionGrid.x, minY - choosedAbility.range, 0); targetChange = true; target = v; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(v.x, minY, 0)] as PlayerUnit; if (!MorePointAction(true)) { Vector3Int pos = new Vector3Int(groupToAttack[0].positionGrid.x, maxY + choosedAbility.range, 0); target = pos; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(v.x, maxY, 0)] as PlayerUnit; } } } else { int maxX = groupToAttack.OrderBy(x => x.positionGrid.x).ToList().Last().positionGrid.x; int minX = groupToAttack.OrderBy(x => x.positionGrid.x).ToList().First().positionGrid.x; if (Vector3Int.Distance(positionGrid, new Vector3Int(maxX + choosedAbility.range, groupToAttack[0].positionGrid.y, 0)) < Vector3Int.Distance(positionGrid, new Vector3Int(minX - choosedAbility.range, groupToAttack[0].positionGrid.y, 0))) { //verifier si cette position est accessible Vector3Int v = new Vector3Int(maxX + choosedAbility.range, groupToAttack[0].positionGrid.y, 0); target = v; targetChange = true; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(maxX, v.y, 0)] as PlayerUnit; if (!MorePointAction(true)) { Vector3Int pos = new Vector3Int(minX - choosedAbility.range, groupToAttack[0].positionGrid.y, 0); target = pos; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(minX, v.y, 0)] as PlayerUnit; } } else { //verifier si cette position est accessible Vector3Int v = new Vector3Int(minX - choosedAbility.range, groupToAttack[0].positionGrid.y, 0); target = v; targetChange = true; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(minX, v.y, 0)] as PlayerUnit; if (!MorePointAction(true)) { Vector3Int pos = new Vector3Int(maxX + choosedAbility.range, groupToAttack[0].positionGrid.y, 0); target = pos; targetPlayer = UnitManager.Instance.unitDictionnary[new Vector3Int(maxX, v.y, 0)] as PlayerUnit; } } } return(targetChange); }
public SelectingTarget(BattleManager battleManager) : base(battleManager) { player = BattleManager.playerInstance; BattleManager.OnSelectTarget += HandleSelectTarget; }
/// <summary> /// When player clicked on a tile /// </summary> /// <param name="selectedTile"></param> public void PlayerSelectedTile(GridTileInfo selectedTile) { // Player cannot select tile during an unit animation if (inPlayerUnitAnimation) { return; } // If it's currently in evolve phase if (GameManager.inEvolvePhase) { // If player selected a clone unit if (selectedTile.containingObject != null) { // Open evolve shop for the selected unit GameManager.sGameManager.StartEvolve(selectedTile.containingObject.GetComponent <PlayerUnit>()); } return; } // If one of the player's unit is ready to reproduce if (playerUnitReproducing) { // If the player selected a valid tile if (selectedTile.marks[0].activeInHierarchy) { inPlayerUnitAnimation = true; // Start animation StartCoroutine(currentSelectedUnitTile.containingObject.GetComponent <PlayerUnit>().UnitReproduce(selectedTile)); } // Stop player from doing other things before finish the reproduction phase return; } // Player cannot select tile when it's not player's turn if (!playerTurn) { return; } // If there is no unit that has moved but did not finish act yet if (!playerUnitAct) { // If the player selected a tile with a player unit if (selectedTile.containingObject != null && selectedTile.containingObject.GetComponent <PlayerUnit>()) { PlayerUnit selectedUnit = selectedTile.containingObject.GetComponent <PlayerUnit>(); // If the unit has not moved in this turn yet and is not reproducing if (!selectedUnit.hasMoved && !selectedUnit.isReproducing) { currentSelectedUnitTile = selectedTile; // Show move range of just selected unit ShowRange(selectedTile, selectedUnit.moveRange, true); } } // If the player selected a tile with no object and there is already a selected unit and the selected tile is within move range if (currentSelectedUnitTile != null && selectedTile.containingObject == null && selectedTile.marks[1].activeInHierarchy) { // Clear previous map marks bool[] clearFlags = { true, true }; ClearMapMarks(clearFlags); // If their is a valid path to the selected tile List <GridTileInfo> path = MapManager.sMapManager.FindPath(currentSelectedUnitTile, selectedTile); if (path != null) { inPlayerUnitAnimation = true; // Start animation // Start move player unit StartCoroutine(currentSelectedUnitTile.containingObject.GetComponent <PlayerUnit>().UnitMove(path)); } } } else { // If the player selected an enemy that's within range if (selectedTile.marks[0].activeInHierarchy && selectedTile.containingObject != null && selectedTile.containingObject.GetComponent <EnemyUnit>()) { inPlayerUnitAnimation = true; // Start animation StartCoroutine(currentSelectedUnitTile.containingObject.GetComponent <PlayerUnit>().UnitAttack(selectedTile.containingObject.GetComponent <EnemyUnit>())); // Unit attack selected enemy } } }
public void DisableUnit(PlayerUnit pu) { GetTile(pu).UnitId = NameAll.NULL_UNIT_ID; }
public static PlayerUnit create_punit(int ID, int owner_ID) { PlayerUnit pu = null; if (ID == WARRIOR) { pu = new Warrior(); } else if (ID == SPEARMAN) { pu = new Spearman(); } else if (ID == ARCHER) { pu = new Archer(); } else if (ID == MINER) { pu = new Miner(); } else if (ID == INSPIRATOR) { pu = new Inspirator(); } else if (ID == SEEKER) { pu = new Seeker(); } else if (ID == GUARDIAN) { pu = new Guardian(); } else if (ID == ARBALEST) { pu = new Arbalest(); } else if (ID == SKIRMISHER) { pu = new Skirmisher(); } else if (ID == PALADIN) { pu = new Paladin(); } else if (ID == MENDER) { pu = new Mender(); } else if (ID == DRUMMER) { pu = new Drummer(); } else if (ID == PIKEMAN) { pu = new Pikeman(); } else if (ID == CARTER) { pu = new Carter(); } else if (ID == DRAGOON) { pu = new Dragoon(); } else if (ID == SCOUT) { pu = new Scout(); } else if (ID == SHIELD_MAIDEN) { pu = new ShieldMaiden(); } pu.owner_ID = owner_ID; return(pu); }
public void BattleStarted() { players = new List <PlayerUnit>(); current = null; }
private static PathTrail GetPathTrail(PlayerUnit player, PathTile fromTile, PathTile toTile) { searchFrontierPhase += 2; if (searchFrontier == null) { searchFrontier = new PathTilePriorityQueue(); } else { searchFrontier.Clear(); } fromTile.SearchPhase = searchFrontierPhase; fromTile.Distance = player.PathTrail == null ? 0 : player.PathTrail.PathTo.Distance; searchFrontier.Enqueue(fromTile); //references int distance = 0; int movePoints = player.MaxMovePoints; int oldPriority = 0; PathTile current = null; PathTile neighbor = null; //HexEdgeType edgeType; while (searchFrontier.Count > 0) { current = searchFrontier.Dequeue(); current.SearchPhase += 1; for (int d = 0; d <= 3; d++) { neighbor = current.Tile.GetNeighbour(d) != null?current.Tile.GetNeighbour(d).PathTile : null; if (neighbor == null || neighbor.Tile == null || neighbor.SearchPhase > searchFrontierPhase) { continue; } if (neighbor.Tile.tileTerrain == TileTerrain.ShallowSea && !player.canCrossSS) { continue; } if (neighbor.Tile.tileTerrain == TileTerrain.DeepSea && !player.canCrossDS) { continue; } if (neighbor.Tile.tileTerrain == TileTerrain.River && !player.canCrossRiver) { continue; } /* * if (neighbor.Tile.IsUnderwater || neighbor.Tile.Unit) * { * continue; * } * edgeType = current.Tile.GetEdgeType(neighbor.Tile); * if (edgeType == HexEdgeType.Cliff) * { * continue; * } */ int moveCost = 1; if (neighbor.Tile.tileTerrain >= TileTerrain.Mountain) { moveCost++; } if (neighbor.Tile.tileTerrain >= TileTerrain.Snow) { moveCost++; } /* * * if (neighbor.Tile.HasRiver) * { * moveCost = current.Tile.HasRoadThroughEdge(d) ? 10 : 20; * } * else if (current.Tile.HasRoadThroughEdge(d)) * { * moveCost = 4; * } * else if (current.Tile.Walled != neighbor.Tile.Walled) * { * continue; * } * else * { * moveCost = edgeType == HexEdgeType.Flat ? 5 : 10; * moveCost += neighbor.Tile.UrbanLevel + neighbor.Tile.FarmLevel + neighbor.Tile.PlantLevel; * } */ distance = current.Distance + moveCost; if (neighbor.SearchPhase < searchFrontierPhase) { neighbor.SearchPhase = searchFrontierPhase; neighbor.MoveCost = moveCost; neighbor.Distance = distance; neighbor.PathFrom = current; neighbor.SearchHeuristic = neighbor.Tile.DistanceTo(toTile.Tile.coordinates); searchFrontier.Enqueue(neighbor); } else if (distance < neighbor.Distance) { oldPriority = neighbor.SearchPriority; neighbor.Distance = distance; neighbor.PathFrom = current; searchFrontier.Change(neighbor, oldPriority); } } if (current == toTile) { return(new PathTrail(fromTile, toTile)); } } return(null); }
public static void AddPath(PlayerUnit player, GameTile fromTile, GameTile toTile) { player.PathTrail = new PathTrail(previewTrail); }
public BuildState(PlayerUnit _unit) { unit = _unit; }
public void SelectUnit(PlayerUnit unit) { selectedPlayerUnit = unit; }
private void Awake() { instance = this; GameEvents.instance.pushDungeonData += PushDungeonData; }
void OnTriggerEnter(Collider col) { if(onlyOne) if (col.gameObject.tag == "PlayerBody") { onlyOne = false; player = col.gameObject; playerUnit = col.gameObject.GetComponent<PlayerUnit>(); playerUnit.powerUp(playerUnit.powerUpPotion); applyItem(); StartCoroutine("effect"); Destroy(this.gameObject); } }
// Use this for initialization void Start() { pl = GameObject.FindWithTag("PlayerBody").GetComponent<PlayerUnit>(); this.GetComponent<ParticleSystem>().startSize = pl.AuraRange*pl.rangeUpPotionScale/10; }
public void UpdatePlayerUnitTileSwap(PlayerUnit pu, Tile newTile) { //Point p = new Point(pu.TileX, pu.TileY); //this tile has already been updated with the actor who swapped in //GetTile(p).UnitId = NameAll.NULL_UNIT_ID; GetTile(newTile.pos).UnitId = pu.TurnOrder; }
//get mimetargettile, called in CalcResolveAction public Tile GetMimeTargetTile(PlayerUnit actor, PlayerUnit mime, Tile targetTile) { Tile actorTile = GetTile(actor); Tile mimeTile = GetTile(mime); //targeting self, retur the mime coordinates if (actorTile == targetTile) { return(mimeTile); } int forwardOffset; int sideOffset; int xOffset = Mathf.Abs(targetTile.pos.x - actorTile.pos.x); int yOffset = Mathf.Abs(targetTile.pos.y - actorTile.pos.y); bool isRight; //is sideOffset to the right or left of the actor. if dead on, this doesn't matter (just adding 0) int xMimeChange = 0; //added at the end to get the new point int yMimeChange = 0; //added at the end to get the new point //gets the direction the actor will be facing Directions attackDir = actorTile.GetDirectionAttack(targetTile); if (attackDir == Directions.East) { //side offset is >= N/S offset, thus the forward offset is the xOffset forwardOffset = xOffset; sideOffset = yOffset; if (targetTile.pos.y < actorTile.pos.y) { isRight = true; } else { isRight = false; } } else if (attackDir == Directions.West) { //side offset is >= N/S offset, thus the forward offset is the xOffset forwardOffset = xOffset; sideOffset = yOffset; if (targetTile.pos.y > actorTile.pos.y) { isRight = true; } else { isRight = false; } } else if (attackDir == Directions.North) { //side offset is < N/S offset, thus the forward offset is the y offset forwardOffset = yOffset; sideOffset = xOffset; if (targetTile.pos.x > actorTile.pos.x) { isRight = true; } else { isRight = false; } } else //SOUTH { //side offset is < N/S offset, thus the forward offset is the y offset forwardOffset = yOffset; sideOffset = xOffset; if (targetTile.pos.x < actorTile.pos.x) { isRight = true; } else { isRight = false; } } if (mime.Dir == Directions.East) { xMimeChange = forwardOffset; if (isRight) { yMimeChange = sideOffset * -1; //off to the right is DOWN the y axis } else { yMimeChange = sideOffset; } Debug.Log("E " + forwardOffset + " " + sideOffset); } else if (mime.Dir == Directions.West) { xMimeChange = forwardOffset * -1; if (isRight) { yMimeChange = sideOffset; //off to the right is UP the y axis } else { yMimeChange = sideOffset * -1; } Debug.Log("W " + forwardOffset + " " + sideOffset); } else if (mime.Dir == Directions.North) { yMimeChange = forwardOffset; if (isRight) { xMimeChange = sideOffset; //off to the right is UP the x axis } else { xMimeChange = sideOffset * -1; } Debug.Log("N " + forwardOffset + " " + sideOffset); } else //south { yMimeChange = forwardOffset * -1; if (isRight) { xMimeChange = sideOffset * -1; //off to the right is DOWN the x axis } else { xMimeChange = sideOffset; } Debug.Log("S " + forwardOffset + " " + sideOffset); } Point p = new Point(mimeTile.pos.x + xMimeChange, mimeTile.pos.y + yMimeChange); return(GetTile(p)); //can return null, null check done in CalcResolveAction }
// Use this for initialization void Start () { if (!isServer && hasAuthority) { localSingleton = this; } }
protected abstract void GrantEffect(PlayerUnit playerUnit);