private void AllocateObjects(DungeonZone zone) { // 아이템과 몹 배치 int tileCount = (upperBoundary.y - lowerBoundary.y - 1) * (upperBoundary.x - lowerBoundary.x - 1); int mobCount = (int)(tileCount * Config.MOB_DENSITY); for (int i = 0; i < mobCount; ++i) { // 몹 생성하고 mobs.Add(GeneratoMobParty()); int idx = mobs.Count - 1; zone.mobs.Add(mobs[idx]); // 등록 Int2D mobPosition = RegisterParty(mobs[idx]); } int itemCOunt = (int)(tileCount * Config.ITEM_DENSITY); for (int i = 0; i < itemCOunt; ++i) { // 아이템 생성하고 Item newItem = new ItemToken(); ((ItemToken)newItem).GenerateRandomToken( usersLevel + random.Next( (int)(-usersLevel * Config.MOB_REWARD_ITEM_RANGE), (int)(usersLevel * Config.MOB_REWARD_ITEM_RANGE) ), ItemToken.equipTypePool[random.Next(ItemToken.equipTypePool.Length)]); items.Add(newItem); int idx = items.Count - 1; zone.items.Add(items[idx]); // 등록 Int2D itemPosition = RegisterGameObject(items[idx]); } }
public void GenerateRecursivly() { // Assert(depth <= upperDepth) int shortSpan = Math.Min(upperBoundary.x - lowerBoundary.x, upperBoundary.y - lowerBoundary.y) + 1; if (depth == upperDepth || shortSpan <= Config.MININUM_SPAN) { // 여기서 DungeonZone을 생성하자 // offset을 진행하지만 나중에 통로 지역도 포함하기 위해서 zone의 범위는 offset하기 전으러 설정 = 맵 전체를 커버할 수 있어 DungeonZone newZone = new DungeonZone(zoneList.Count, lowerBoundary, upperBoundary); zoneList.Add(newZone); // 조심해! // 맵 전체를 두번 순회하고 있음 // zone id 기록 for (int i = lowerBoundary.y; i <= upperBoundary.y; ++i) { for (int j = lowerBoundary.x; j <= upperBoundary.x; ++j) { map[i, j].zoneId = newZone.zoneId; } } // leafNode이므로 Bake하고 // 일정 거리를 offset int offset = Math.Min(random.Next(0, Config.MAX_OFFSET), (shortSpan - 3) / 2); Offset(offset); // 실제 맵에다가 타일과 벽을 기록 BakeMap(); // 플레이어, ring, 몹, 아이템들 생성 및 배치 AllocateObjects(newZone); } else { // leafNode가 아니므로 분할한다 leftChild = new DungeonTreeNode(); rightChild = new DungeonTreeNode(); // children 멤버 변수들 초기화 leftChild.parent = rightChild.parent = this; leftChild.siblingDirection = rightChild.siblingDirection = !siblingDirection; leftChild.depth = rightChild.depth = depth + 1; leftChild.upperDepth = rightChild.upperDepth = upperDepth; leftChild.isLeft = true; rightChild.isLeft = false; leftChild.random = rightChild.random = random; leftChild.map = rightChild.map = map; leftChild.mobs = rightChild.mobs = mobs; leftChild.items = rightChild.items = items; leftChild.zoneList = rightChild.zoneList = zoneList; leftChild.usersLevel = rightChild.usersLevel = usersLevel; // 실제로 영역 분할 SliceArea(); // 조심해! // children 단계에서 다시 반복하도록 호출 // 나중에 task로 처리할까... leftChild.GenerateRecursivly(); rightChild.GenerateRecursivly(); // 자식 노드들을 연결한다! LinkArea(); } }