コード例 #1
0
ファイル: Actor.cs プロジェクト: EuropeanSnail/DungeonTycoon
    public void SetDestinationTileLoad(TileCoordinates input)
    {
        //Debug.Log("[SetDestinationTileLoad] input is null : " + (input == null));
        tileLayer = GameManager.Instance.GetTileLayer(0);
        if (input != null)
        {
            destinationTile = tileLayer.GetTileAsComponent(input.x, input.y);
        }
        else
        {
            destinationTile = null;
        }

        //Debug.Log("[SetDestinationTileLoad] destTile is null: " + (destinationTile == null));
    }
コード例 #2
0
ファイル: Actor.cs プロジェクト: EuropeanSnail/DungeonTycoon
 public void SetCurTileLoad(TileCoordinates input)
 {
     if (input != null)
     {
         curTile = tileLayer.GetTileAsComponent(input.x, input.y);
         //if (curTile == null)
         //    Debug.Log("[" + input.x + ", " + input.y + "] curTile 로드 실패!");
         //else
         //    Debug.Log("[" + curTile.x + ", " + curTile.y + "] curTile 로드 성공");
     }
     else
     {
         curTile = null;
     }
 }
コード例 #3
0
    // 위까지 생략하되 constructing에 설정하는 건 가져와줘야.
    public void ConstructStructure()
    {
        //Gold 소모

        Structure structure = constructing.GetComponent <Structure>();

        if (GameManager.Instance.GetPlayerGold() >= structure.expenses)
        {
            GameManager.Instance.playerGold -= structure.expenses;
        }
        else
        {
            return;
        }
        Tile tile = structure.point;

        int[,] extent = structure.GetExtent();
        TileLayer tileLayer = tile.GetLayer();

        Debug.Log("Constructed!!!!");
        constructing.tag = "Structure";

        structure.EndMove();
        ResetConstructingAreas();

        // 인덱스 값 넣어줌.
        structure.index = structures.Count;

        // 리스트에 추가
        structures.Add(structure);


        for (int i = 0; i < structure.extentHeight; i++)
        {
            for (int j = 0; j < structure.extentWidth; j++)
            {
                Tile tempTile = tileLayer.GetTileAsComponent(tile.GetX() + j, tile.GetY() + i);

                if (extent[j, i] == 1)
                {
                    tempTile.SetIsBuildingArea(false);
                    tempTile.SetIsStructed(true);
                    tempTile.SetStructure(structure);
                    tempTile.SetTileColor(new Color(1.0f, 0.3f, 0.2f));
                }
                else if (extent[j, i] == 2)
                {
                    //tempTile.SetIsStructed(false);
                    //tempTile.SetIsEntrance(true);
                    if (tempTile.GetBuildingArea())
                    {
                        structure.addEntrance(tempTile);
                        tempTile.SetTileColor(new Color(0.2f, 0.2f, 1.0f));
                    }
                }
            }
        }

        CheckEntrance();

        constructing   = null;
        isConstructing = false;
    }
コード例 #4
0
    public void Simulate(System.Object threadContext)
    {
        latest_simulate = new PathVertex(null, myCurPos, destination);
        bestKey         = latest_simulate.X * 1000 + latest_simulate.Y;
        closeList.Add(latest_simulate.X * 1000 + latest_simulate.Y, latest_simulate);

        // Close 리스트에 집어넣음
        visited[latest_simulate.Y, latest_simulate.X].isClosed = true;
#if DEBUG_PF
        Debug.Log("in");
#endif

        while (!latest_simulate.myTilePos.Equals(destination)) // Dest에 도착하지 않은 동안
        {
            // 주위 4칸 확인.
            for (int i = 0; i < 4; i++)
            {
                // 타일이 있고 이동가능할 때
                // next 는 다음 타일 오픈리스트에서 하나 가져와서 주위 타일 검사.
                if ((next = tileLayer.GetTileAsComponent((int)(latest_simulate.myTilePos.GetX() + DirectionVectors[i].x), (int)(latest_simulate.myTilePos.GetY() + DirectionVectors[i].y))) != null && validateTile(next))
                {
                    // Closed가 아닐 때
                    if (visited[next.GetY(), next.GetX()].isClosed == false)
                    {
                        // Visited가 아닐 때. 그러니깐 다른 노드에서 계산한 적 없을때는 그냥 새값을 넣음.
                        if (visited[next.GetY(), next.GetX()].isVisited == false)
                        {
                            // 뭔지 모르겠음
                            if (openList.Count <= openList.useCount)
                            {
                                openList.Add(tempVertex = new PathVertex(latest_simulate, next, destination));
                                visited[next.GetY(), next.GetX()].isVisited = true;
                                visited[next.GetY(), next.GetX()].F         = tempVertex.F;
                            }
                            else
                            {
                                openList[openList.useCount].ReUse(latest_simulate, next, destination);
                                tempVertex = openList[openList.useCount];
                                index      = openList.useCount;
                                openList.useCount++;
                                bool keepGoing = true;

                                while (keepGoing)
                                {
                                    if (index == 0)
                                    {
                                        break;
                                    }
                                    parentIndex = (index - 1) / 2;
                                    keepGoing   = openList.CompareAndSwap(index, parentIndex);
                                    if (keepGoing)
                                    {
                                        index = parentIndex;
                                    }
                                }
                                visited[next.GetY(), next.GetX()].isVisited = true;
                                visited[next.GetY(), next.GetX()].F         = tempVertex.F;
                            }
                        }
                        else // visited 있는경우 - 최적의 값 비교.
                        {
                            // openList안에서 찾는것이 우선 . . .  F (F = G + H / 현재까지 온 거리 +남은 거리 최소값) 기준으로 정렬됨.
                            // 새 F값이 기존 F값보다 작을 때
                            if (visited[next.GetY(), next.GetX()].F > (latest_simulate.G + 1 + (Mathf.Abs(destination.GetX() - next.GetX()) + Mathf.Abs(destination.GetY() - next.GetY()))))
                            {
                                bool find = false;
                                for (int u = 0; u < openList.useCount; u++)
                                {
                                    // 이전에 오픈리스트에 넣었던 걸 빼줌
                                    if (openList[u].X == next.GetX() && openList[u].Y == next.GetY())
                                    {
                                        find  = true;
                                        index = u;
                                        break;
                                    }
                                }

                                // 새로 계산한 F값, 새로 배정한 부모를 가진 PathVertex를 오픈리스트에 넣어줌.
                                if (find == true)
                                {
                                    openList.RemoveAt(index);

                                    if (openList.Count <= openList.useCount)
                                    {
                                        openList.Add(tempVertex = new PathVertex(latest_simulate, next, destination));
                                        visited[next.GetY(), next.GetX()].isVisited = true;
                                        visited[next.GetY(), next.GetX()].F         = tempVertex.F;
                                    }
                                    else
                                    {
                                        //items.Add(item);
                                        //reuse 할때도 priority queue ~~~
                                        openList[openList.useCount].ReUse(latest_simulate, next, destination);
                                        tempVertex = openList[openList.useCount];
                                        index      = openList.useCount;
                                        openList.useCount++;
                                        bool keepGoing = true;

                                        while (keepGoing)
                                        {
                                            if (index == 0)
                                            {
                                                break;
                                            }
                                            parentIndex = (index - 1) / 2;
                                            keepGoing   = openList.CompareAndSwap(index, parentIndex);
                                            if (keepGoing)
                                            {
                                                index = parentIndex;
                                            }
                                        }
                                        visited[next.GetY(), next.GetX()].isVisited = true;
                                        visited[next.GetY(), next.GetX()].F         = tempVertex.F;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (openList.useCount != 0)
            {
                best    = openList.Pop();
                bestKey = best.X * 1000 + best.Y;
            }
            else
            {
                isNoPath = true;
                isEnd    = true;
                //not found
                break;
            }
            if (!closeList.ContainsKey(bestKey))
            {
                closeList.Add(bestKey, best);
                best.myTilePos.AddedCloseList();
            }
            latest_simulate = best;
        }
        latest = latest_simulate;
        isEnd  = true;
    }
コード例 #5
0
    public void ConstructBossArea(int areaNum, int areaIndex, GameObject pointTile)
    {
        #region InstantiateStructure()
        string stageNum    = "stage" + SceneManager.GetActiveScene().name;
        int    bossAreaNum = areaNum;
        //Debug.Log("stageNum : " + stageNum + " areaNum : " + huntingAreaNum);
        //Debug.Log("디버그2: " + huntingAreaJson[stageNum][huntingAreaNum]["name"]);
        //Debug.Log("HuntingArea/HuntingAreaPrefabs/" + stageNum + "/" + huntingAreaNum);
        constructing = (GameObject)Instantiate(Resources.Load("CombatArea/BossAreaPrefabs/" + stageNum + "/" + bossAreaNum.ToString()));

        constructing.transform.parent = rootCombatAreaObject.transform;

        //임시
        BossArea bossArea = constructing.GetComponent <BossArea>();
        bossArea.name = bossAreaJson[stageNum][bossAreaNum]["name"];

        // 보스 생성. 우선 번호부터.
        int bossNum        = bossAreaJson[stageNum][bossAreaNum]["bossNum"].AsInt;
        int challengeLevel = bossAreaJson[stageNum][bossAreaNum]["challengeLevel"].AsInt;
        int bonus          = bossAreaJson[stageNum][bossAreaNum]["bonus"].AsInt;
        //Debug.Log("bonus : " + bonus);
        GameObject boss = LoadMonsterFromJson("Boss", bossNum);

        // 세이브 로드용
        bossArea.stageNum    = stageNum;
        bossArea.bossAreaNum = areaNum;
        bossArea.index       = areaIndex;

        //건설공간 지정
        int x = bossAreaJson[stageNum][bossAreaNum]["sitewidth"].AsInt;
        bossArea.extentWidth = x;

        int y = bossAreaJson[stageNum][bossAreaNum]["siteheight"].AsInt;
        bossArea.extentHeight = y;

#if DEBUG_CREATE_HA
        Debug.Log("siteWidth = " + x + ", siteHeight = " + y + ", Extent[0][0] = " + huntingAreaJson[stageNum][huntingAreaNum]["site"][0]);
#endif

        bossArea.extent = new int[x, y];
        for (int i = 0; i < x * y; i++)
        {
            bossArea.extent[i % x, i / x] = bossAreaJson[stageNum][bossAreaNum]["site"][i].AsInt;
        }
        #endregion

        #region AllocateStructure()
        // 건설할 건물의 position 설정
        constructing.transform.position = pointTile.transform.position; // 문제 생길지도 모름. 수정요망

        TileLayer tileLayer = TileMapGenerator.Instance.tileMap_Object.transform.GetChild(0).GetComponent <TileLayer>();

        SetBossAreaPoint(pointTile.GetComponent <Tile>());
        #endregion

        #region ConstructStructure()
        Tile tile = bossArea.point;
        int[,] extent = bossArea.GetExtent();

        constructing.tag = "CombatArea";

        // 인덱스 값 넣어줌.
        bossArea.index = bossAreas.Count;

        // 리스트에 추가
        bossAreas.Add(bossArea);

        for (int i = 0; i < bossArea.extentHeight; i++)
        {
            //string debugStr = "";
            for (int j = 0; j < bossArea.extentWidth; j++)
            {
                Tile thatTile = tileLayer.GetTileAsComponent(tile.GetX() + j, tile.GetY() + i);

                //debugStr += " ";
                //debugStr += extent[j, i];
                if (extent[j, i] == 1)
                {
                    thatTile.SetIsBuildingArea(false);
                    //thatTile.SetIsStructed(true);
                    thatTile.SetIsHuntingArea(true);

                    //디버깅용임시
                    thatTile.gameObject.GetComponent <SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f);
                    //
                    for (int k = 0; k < 4; k++)
                    {
                        bossArea.AddTerritory(thatTile.childs[k]);
                    }
                }
                else if (extent[j, i] == 2) //입구
                {
                    //thatTile.SetIsStructed(false);
                    //thatTile.SetIsEntrance(true);
                    thatTile.gameObject.GetComponent <SpriteRenderer>().color = new Color(0.5f, 0.5f, 1.0f);
                    //if (thatTile.GetBuildable())
                    //{
                    bossArea.addEntrance(thatTile);
                    //}
                }
                else if (extent[j, i] == 3)
                {
                    thatTile.SetIsActive(false);
                    thatTile.gameObject.GetComponent <SpriteRenderer>().color = new Color(0.0f, 0.0f, 0.0f);
                    thatTile.SetIsWall(true);
                }
            }

            //Debug.Log(debugStr);
        }

        bossArea.InitBossArea(boss, challengeLevel, bonus);
        boss.GetComponent <Monster>().SetHabitat(bossArea);
        constructing = null;
        #endregion
    }
コード例 #6
0
    // 사냥터 건설
    public void ConstructHuntingArea(int areaNum, int areaIndex, GameObject pointTile)
    {
        #region InstantiateStructure()
        string stageNum       = "stage" + SceneManager.GetActiveScene().name;
        int    huntingAreaNum = areaNum;
        //Debug.Log("stageNum : " + stageNum + " areaNum : " + huntingAreaNum);
        //Debug.Log("디버그2: " + huntingAreaJson[stageNum][huntingAreaNum]["name"]);
        //Debug.Log("HuntingArea/HuntingAreaPrefabs/" + stageNum + "/" + huntingAreaNum);
        constructing = (GameObject)Instantiate(Resources.Load("CombatArea/HuntingAreaPrefabs/" + stageNum + "/" + huntingAreaNum.ToString()));

        constructing.transform.parent = rootCombatAreaObject.transform;

        //임시
        HuntingArea huntingArea = constructing.GetComponent <HuntingArea>();
        huntingArea.name = huntingAreaJson[stageNum][huntingAreaNum]["name"];

        int  conquerCondition = huntingAreaJson[stageNum][huntingAreaNum]["conquerCondition"].AsInt;
        bool isBossArea       = huntingAreaJson[stageNum][huntingAreaNum]["isBossArea"].AsBool; //서로 알 필요 없지않나?
        //Debug.Log(huntingAreaJson[stageNum][huntingAreaNum]["isBossRoom"].AsBool);
        int   levelMax         = huntingAreaJson[stageNum][huntingAreaNum]["levelMax"].AsInt;
        int   monsterMax       = huntingAreaJson[stageNum][huntingAreaNum]["monsterMax"].AsInt;
        int   monsterPerRegen  = huntingAreaJson[stageNum][huntingAreaNum]["monsterPerRegen"].AsInt;
        float monsterRegenRate = huntingAreaJson[stageNum][huntingAreaNum]["monsterRegenRate"].AsFloat;
        float monsterRatio     = huntingAreaJson[stageNum][huntingAreaNum]["monsterRatio"].AsFloat;

        // 몬스터 프로토타입 넣기. 우선 번호부터.
        string monsterSet = huntingAreaJson[stageNum][huntingAreaNum]["monsterSet"];

        int monsterSample1Num = huntingAreaJson[stageNum][huntingAreaNum]["monsterSample1Num"].AsInt;
        int monsterSample2Num = huntingAreaJson[stageNum][huntingAreaNum]["monsterSample2Num"].AsInt;

        // 몬스터 샘플 instantiate
        //GameObject monsterSample1, monsterSample2;
        //LoadMonsterSamples(monsterSet, monsterSample1Num, monsterSample2Num, out monsterSample1, out monsterSample2);
        GameObject monsterSample1 = LoadMonsterFromJson(monsterSet, monsterSample1Num);
        GameObject monsterSample2 = LoadMonsterFromJson(monsterSet, monsterSample2Num);

        huntingArea.InitHuntingArea(conquerCondition, isBossArea, levelMax, monsterMax, monsterPerRegen, monsterRegenRate, monsterRatio, monsterSample1, monsterSample2);
        huntingArea.areaConquered += OnHuntingAreaConquered;

        // 저장용.
        huntingArea.stageNum       = stageNum;
        huntingArea.huntingAreaNum = areaNum;
        huntingArea.index          = areaIndex;

        //관광 수치 저장해야할 수도 있음. 수정요망.

        //건설공간 지정
        int x = huntingAreaJson[stageNum][huntingAreaNum]["sitewidth"].AsInt;
        huntingArea.extentWidth = x;

        int y = huntingAreaJson[stageNum][huntingAreaNum]["siteheight"].AsInt;
        huntingArea.extentHeight = y;

#if DEBUG_CREATE_HA
        Debug.Log("siteWidth = " + x + ", siteHeight = " + y + ", Extent[0][0] = " + huntingAreaJson[stageNum][huntingAreaNum]["site"][0]);
#endif

        huntingArea.extent = new int[x, y];
        for (int i = 0; i < x * y; i++)
        {
            huntingArea.extent[i % x, i / x] = huntingAreaJson[stageNum][huntingAreaNum]["site"][i].AsInt;
        }
        #endregion

        #region AllocateStructure()
        // 건설할 건물의 position 설정
        constructing.transform.position = pointTile.transform.position; // 문제 생길지도 모름. 수정요망

        TileLayer tileLayer = TileMapGenerator.Instance.tileMap_Object.transform.GetChild(0).GetComponent <TileLayer>();

        SetHuntingAreaPoint(pointTile.GetComponent <Tile>());
        #endregion

        #region ConstructStructure()
        Tile tile = huntingArea.point;
        int[,] extent = huntingArea.GetExtent();

        constructing.tag = "CombatArea";

        // 인덱스 값 넣어줌.
        huntingArea.index = huntingAreas.Count;

        // 리스트에 추가
        huntingAreas.Add(huntingArea);

        for (int i = 0; i < huntingArea.extentHeight; i++)
        {
            for (int j = 0; j < huntingArea.extentWidth; j++)
            {
                Tile thatTile = tileLayer.GetTileAsComponent(tile.GetX() + j, tile.GetY() + i);

                if (extent[j, i] == 1)
                {
                    thatTile.SetIsBuildingArea(false);
                    thatTile.SetIsStructed(false);
                    thatTile.SetIsHuntingArea(true);

                    //디버깅용임시
                    thatTile.gameObject.GetComponent <SpriteRenderer>().color = new Color(0, 1.0f, 1.0f);
                    //
#if DEBUG_CREATE_HA
                    Debug.Log(thatTile);
#endif
                    // 여기서 딕셔너리에 TileForMove 영역을 추가해주자.
                    //foreach(TileForMove child in thatTile.childs)
                    //{
                    //    huntingArea.AddTerritory(child);
                    //}
                    // 디버깅용임시
                    // thatTile.SetPassable(true);
                    for (int k = 0; k < 4; k++)
                    {
                        huntingArea.AddTerritory(thatTile.childs[k]);
                    }

                    //thatTile.SetStructure(structure); // 일단 쓰는 곳 없어서 안넣고 둠.
                }
                else if (extent[j, i] == 2)
                {
                    //thatTile.SetIsStructed(true);
                    thatTile.gameObject.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 0);
                    //if (thatTile.GetBuildable())
                    //{
                    huntingArea.addEntrance(thatTile);
                    //}
                }
                else if (extent[j, i] == 3)
                {
                    thatTile.SetIsActive(false);
                    thatTile.gameObject.GetComponent <SpriteRenderer>().color = new Color(0.0f, 0.0f, 0.0f);
                    thatTile.SetIsWall(true);
                }
            }
        }

        constructing = null;
        #endregion
    }