// 효과범위의 회전을 결정하기 위한 메서드. protected CentralAxis GetCentralAxis(TileForMove myPos, TileForMove targetPos) { int xDisplacement = targetPos.GetX() - myPos.GetX(); int yDisplacement = targetPos.GetY() - myPos.GetY(); if (Mathf.Abs(yDisplacement) >= Mathf.Abs(xDisplacement)) { if (yDisplacement >= 0) { return(CentralAxis.Y); } else { return(CentralAxis.InverseY); } } else { if (xDisplacement >= 0) { return(CentralAxis.X); } else { return(CentralAxis.InverseX); } } }
public Direction GetDirectionFromOtherTileForMove(TileForMove t) { int distanceX = this.GetX() - t.GetX(); int distanceY = this.GetY() - t.GetY(); if (distanceX == 0 && distanceY == 0) { return(Direction.None); } if (Mathf.Abs(distanceX) > Mathf.Abs(distanceY)) //x축 이동 { if (distanceX > 0) //t가 작은 경우 { return(Direction.UpLeft); } else { return(Direction.DownRight); } } else // y축 이동 { if (distanceY > 0) //t가 작은 경우 { return(Direction.UpRight); } else { return(Direction.DownLeft); } } }
public Direction GetDirectionFromOtherTileForMove(TileForMove tileForMove) { Direction direction = Direction.DownLeft; int distanceX = GetCurTileForMove().GetX() - tileForMove.GetX(); int distanceY = GetCurTileForMove().GetY() - tileForMove.GetY(); int absX = Mathf.Abs(distanceX); int absY = Mathf.Abs(distanceY); if (absX == 0 && absY == 0) { direction = Direction.None; // 겹침 return(direction); } if (distanceX >= 0 && distanceY >= 0) { if (absX > absY) { direction = Direction.DownRight; } else { direction = Direction.DownLeft; } } else if (distanceX >= 0 && distanceY < 0) //Right { if (absX > absY) { direction = Direction.DownRight; } else { direction = Direction.UpRight; } } else if (distanceX < 0 && distanceY >= 0) //Left { if (absX > absY) { direction = Direction.UpLeft; } else { direction = Direction.DownLeft; } } else { if (absX > absY) { direction = Direction.UpLeft; } else { direction = Direction.UpRight; } } return(direction); }
// 몬스터 리젠을 위해 사냥터 영역을 받는 함수. public void AddTerritory(TileForMove input) { // 키 값이 "x.y"형태로 저장됨. string keyXY = input.GetX().ToString() + "." + input.GetY().ToString(); territory.Add(keyXY, input); occupiedTerritory.Add(keyXY, false); }
/// <summary> /// 효과받는 타일을 구해서 effectedAreas에 Add /// </summary> /// <param name="mainTarget">효과범위의 중심이 되는 Actor</param> protected void GetArea(ICombatant mainTarget) { TileLayer tileLayer = GameManager.Instance.GetTileLayer(0); TileForMove mainTargetPos = mainTarget.GetCurTileForMove(); effectedAreas.Clear(); CentralAxis centralAxis = GetCentralAxis(owner.GetCurTileForMove(), mainTarget.GetCurTileForMove()); switch (centralAxis) { case CentralAxis.Y: foreach (Coverage item in coverages) { effectedAreas.Add(tileLayer.GetTileForMove(mainTargetPos.GetX() + item.x, mainTargetPos.GetY() + item.y)); } break; case CentralAxis.InverseY: foreach (Coverage item in coverages) { effectedAreas.Add(tileLayer.GetTileForMove(mainTargetPos.GetX() - item.x, mainTargetPos.GetY() - item.y)); } break; case CentralAxis.X: foreach (Coverage item in coverages) { effectedAreas.Add(tileLayer.GetTileForMove(mainTargetPos.GetX() + item.y, mainTargetPos.GetY() + item.x)); } break; case CentralAxis.InverseX: foreach (Coverage item in coverages) { effectedAreas.Add(tileLayer.GetTileForMove(mainTargetPos.GetX() - item.y, mainTargetPos.GetY() - item.x)); } break; } }
public int GetDistance(TileForMove another) { return(Mathf.Abs(x - another.GetX()) + Mathf.Abs(y - another.GetY())); }
protected int DistanceBetween(TileForMove pos1, TileForMove pos2) { return(Mathf.Abs(pos1.GetX() - pos2.GetX()) + Mathf.Abs(pos1.GetY() - pos2.GetY())); }
// dX = 1 : UR // dX = -1: DL // dY = 1 : DR // dY = -1: UL protected List <TileForMove> GetWayTileForMove(List <PathVertex> path, TileForMove destTileForMove) { List <TileForMove> moveWayTFM = GetWay(path); TileLayer tileLayer = GameManager.Instance.GetTileLayer().GetComponent <TileLayer>(); TileForMove lastTFM = moveWayTFM[moveWayTFM.Count - 1]; int xDiff = destTileForMove.GetX() - lastTFM.GetX(); int yDiff = destTileForMove.GetY() - lastTFM.GetY(); int xSeq, ySeq; if (xDiff == 0) { xSeq = 0; } else { xSeq = xDiff / Mathf.Abs(xDiff); } if (yDiff == 0) { ySeq = 0; } else { ySeq = yDiff / Mathf.Abs(yDiff); } #if DEBUG_GETWAY Debug.Log("원래 끝 TFM : [" + lastTFM.GetX() + ", " + lastTFM.GetY()); Debug.Log("xDiff : " + xDiff + ", xSeq : " + xSeq); Debug.Log("xDiff : " + yDiff + ", xSeq : " + ySeq); #endif //for (int i = 0; i != xDiff; i += xSeq) //{ // moveWayTFM.Add(tileLayer.GetTileForMove(lastTFM.GetX() + xSeq + i, lastTFM.GetY())); //} float randNum = Random.Range(0.0f, 1.0f); if (randNum >= 0.5f) { for (int i = 0; i != xDiff; i += xSeq) { moveWayTFM.Add(tileLayer.GetTileForMove(lastTFM.GetX() + xSeq + i, lastTFM.GetY())); } } else { for (int i = 0; i != yDiff; i += ySeq) { moveWayTFM.Add(tileLayer.GetTileForMove(lastTFM.GetX(), lastTFM.GetY() + ySeq + i)); } } lastTFM = moveWayTFM[moveWayTFM.Count - 1]; //for (int i = 0; i != yDiff; i += ySeq) //{ // moveWayTFM.Add(tileLayer.GetTileForMove(lastTFM.GetX(), lastTFM.GetY() + ySeq + i)); //} if (randNum >= 0.5f) { for (int i = 0; i != yDiff; i += ySeq) { moveWayTFM.Add(tileLayer.GetTileForMove(lastTFM.GetX(), lastTFM.GetY() + ySeq + i)); } } else { for (int i = 0; i != xDiff; i += xSeq) { moveWayTFM.Add(tileLayer.GetTileForMove(lastTFM.GetX() + xSeq + i, lastTFM.GetY())); } } #if DEBUG_GETWAY Debug.Log("끝 타일1 : " + moveWayTFM[moveWayTFM.Count - 1].GetParent().GetX() + ", " + moveWayTFM[moveWayTFM.Count - 1].GetParent().GetY()); Debug.Log("끝 TFM1 : " + moveWayTFM[moveWayTFM.Count - 1].GetX() + ", " + moveWayTFM[moveWayTFM.Count - 1].GetY()); Debug.Log("시작지 TFM : " + curTileForMove.GetX() + ", " + curTileForMove.GetY()); for (int i = 0; i < moveWayTFM.Count; i++) { if (i == 0) { Debug.Log("출발"); } Debug.Log("[" + moveWayTFM[i].GetX() + ", " + moveWayTFM[i].GetY()); if (i == moveWayTFM.Count - 1) { Debug.Log("끝"); } } Debug.Log("끝 타일2 : " + destTileForMove.GetParent().GetX() + ", " + destTileForMove.GetParent().GetY()); Debug.Log("끝 TFM2 : " + destTileForMove.GetX() + ", " + destTileForMove.GetY()); #endif return(moveWayTFM); }
public TileForMoveCoordinates(TileForMove input) { x = input.GetX(); y = input.GetY(); }