Esempio n. 1
0
    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);
            }
        }
    }
Esempio n. 2
0
    // 효과범위의 회전을 결정하기 위한 메서드.
    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);
            }
        }
    }
Esempio n. 3
0
    public TileForMove FindNearestBlank(TileForMove curPos)
    {
        RefreshOccupiedTerritory();

        TileForMove nearest = null;
        int         minDist = int.MaxValue;

        foreach (KeyValuePair <string, bool> item in occupiedTerritory)
        {
            if (item.Value == false && territory[item.Key].GetDistance(curPos) <= minDist)
            {
                if (territory[item.Key].GetDistance(curPos) == minDist)
                {
                    if (Random.Range(0, 2) == 1)
                    {
                        nearest = territory[item.Key];
                    }
                }
                else
                {
                    nearest = territory[item.Key];
                    minDist = nearest.GetDistance(curPos);
                }
            }
        }

        return(nearest);
    }
Esempio n. 4
0
    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);
    }
Esempio n. 5
0
    // 몬스터 리젠을 위해 사냥터 영역을 받는 함수.
    public void AddTerritory(TileForMove input)
    {
        // 키 값이 "x.y"형태로 저장됨.
        string keyXY = input.GetX().ToString() + "." + input.GetY().ToString();

        territory.Add(keyXY, input);

        occupiedTerritory.Add(keyXY, false);
    }
Esempio n. 6
0
 public void SetCurTileForMove(TileForMove _tileForMove)
 {
     if (curTileForMove != null)
     {
         curTileForMove.RemoveRecentActor(this);
     }
     curTileForMove = _tileForMove;
     curTileForMove.AddRecentActor(this);
 }
Esempio n. 7
0
 public void SetDetinationTileForMoveLoad(TileForMoveCoordinates input)
 {
     if (input != null)
     {
         destinationTileForMove = tileLayer.GetTileForMove(input.x, input.y);
     }
     else
     {
         destinationTileForMove = null;
     }
 }
Esempio n. 8
0
    public bool SetCurTileForMoveLoad(int childNum)
    {
        if (childNum == -1)
        {
            curTileForMove = null;
            return(false);
        }

        SetCurTileForMove(curTile.GetChild(childNum));
        return(true);
    }
Esempio n. 9
0
 public void SetCurTileForMoveLoad(TileForMoveCoordinates input)
 {
     if (input != null)
     {
         curTileForMove = tileLayer.GetTileForMove(input.x, input.y);
         curTileForMove.AddRecentActor(this);
         //if (curTileForMove == null)
         //    Debug.Log("[" + input.x + ", " + input.y + "] curTFM 로드 실패!");
         //else
         //    Debug.Log("[" + curTileForMove.GetX() + ", " + curTileForMove.GetY() + "] curTFM 로드 성공");
     }
     else
     {
         curTileForMove = null;
     }
 }
Esempio n. 10
0
    // 몬스터 1개를 인자로 받은 타일 위에 생성하는 함수.
    private void MonsterRegen(Tile curTile, TileForMove curTileForMove)
    {
        int lastKey = monstersDisabled.Keys.ToArray <int>()[monstersDisabled.Count - 1];

        Monster tempMonsterComp = monstersDisabled[lastKey].GetComponent <Monster>();

        // 스탯 초기화
        tempMonsterComp.ResetBattleStat();
        tempMonsterComp.SetCurTile(curTile);
        tempMonsterComp.SetCurTileForMove(curTileForMove);
        tempMonsterComp.AlignPositionToCurTileForMove();

        // 객체 풀 관리. 비활성화 리스트에서 활성화 리스트로.
        monstersDisabled[lastKey].SetActive(true);
        monstersEnabled.Add(lastKey, monstersDisabled[lastKey]);
        monstersDisabled.Remove(lastKey);
    }
Esempio n. 11
0
    /// <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;
        }
    }
Esempio n. 12
0
    public Monster FindNearestMonster(Adventurer adv) // 인자로 받은 모험가와 가장 가까운 몬스터 찾아서 반환.
    {
        int monsterCnt = 0;

        foreach (KeyValuePair <int, GameObject> item in monstersEnabled)
        {
            if (item.Value.GetComponent <Monster>().GetState() != State.Dead)
            {
                monsterCnt++;
            }
        }
        if (monsterCnt == 0)
        {
            return(null); //몬스터가 아예 없다면 null 반환.
        }
        //TileForMove advTFM = adv.GetCurTileForMove();
        //Monster nearest = monstersEnabled.Values.ToArray<GameObject>()[0].GetComponent<Monster>();
        //TileForMove monsterTFM = nearest.GetCurTileForMove();
        //int shortestDist = DistanceBetween(advTFM, monsterTFM);
        TileForMove advTFM       = adv.GetCurTileForMove();
        Monster     nearest      = null;
        TileForMove monsterTFM   = null;
        int         shortestDist = int.MaxValue;


        foreach (KeyValuePair <int, GameObject> item in monstersEnabled)
        {
            Monster monster = item.Value.GetComponent <Monster>();
            monsterTFM = monster.GetCurTileForMove();
            if (DistanceBetween(advTFM, monsterTFM) < shortestDist && monster.curState != State.Dead)
            {
                shortestDist = DistanceBetween(advTFM, monsterTFM);
                nearest      = item.Value.GetComponent <Monster>(); // 일단 애드 나고 안나고 떠나서 가까운 거 먼저 치게 돼있음.
            }
        }

        return(nearest);
    }
Esempio n. 13
0
 public int GetDistance(TileForMove another)
 {
     return(Mathf.Abs(x - another.GetX()) + Mathf.Abs(y - another.GetY()));
 }
Esempio n. 14
0
 // Child set
 public void SetChild(int index, TileForMove child)
 {
     childs[index] = child;
     child.SetChildNum(index);
 }
Esempio n. 15
0
 public void AddTileForMove(int x, int y, Vector3 _pos, Tile _parent)
 {
     tilesforMove[x, y] = new TileForMove(x, y, _pos, _parent);
 }
Esempio n. 16
0
    // 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);
    }
Esempio n. 17
0
 protected int DistanceBetween(TileForMove pos1, TileForMove pos2)
 {
     return(Mathf.Abs(pos1.GetX() - pos2.GetX()) + Mathf.Abs(pos1.GetY() - pos2.GetY()));
 }
 public TileForMoveCoordinates(TileForMove input)
 {
     x = input.GetX();
     y = input.GetY();
 }