public void GenerateGenericEnemyGroup(MapRoom room, AbstractLevelData level, RoomType roomType, int difficulty, MapRegion regionData, int forcedId = -1) { Player player = GameSystem.Instance.CurrentPlayer; int playerLevel = 1; if (player != null) { playerLevel = player.Level; } RegionSize size = RegionSize.SMALL; if (regionData != null) { int sInt = regionData.GetFamilyRegions().Count; if (sInt == 2 || sInt == 3) { size = RegionSize.MEDIUM; } else if (sInt >= 4) { size = RegionSize.LARGE; } } int world = WorldHolder.instance.worldLevel; int selectedId = forcedId; if (forcedId < 0) { int soucet = 0; foreach (MobGroup group in mobGroups) { if (group.minRegionSize != RegionSize.NULL && group.minRegionSize > size) { continue; } if (group.maxRegionSize != RegionSize.NULL && group.maxRegionSize < size) { continue; } if (roomType == group.roomType && group.minLevel <= playerLevel && group.maxLevel >= playerLevel && group.maxWorld >= world && group.minWorld <= world) { soucet += group.frequency; } } int[] sum = new int[soucet]; soucet = 0; foreach (MobGroup group in mobGroups) { if (group.minRegionSize != RegionSize.NULL && group.minRegionSize > size) { continue; } if (group.maxRegionSize != RegionSize.NULL && group.maxRegionSize < size) { continue; } if (roomType == group.roomType && group.minLevel <= playerLevel && group.maxLevel >= playerLevel && group.maxWorld >= world && group.minWorld <= world) { for (int i = 0; i < group.frequency; i++) { sum[soucet + i] = group.id; } soucet += group.frequency; } } if (sum.Length == 0) { return; } int rnd = Random.Range(0, sum.Length); selectedId = sum[rnd]; } if (selectedId < 0) { Debug.LogError("chyba - nenalezena spravna groupa "); return; } bool spawned = false; foreach (MobGroup group in mobGroups) { if (group.id == selectedId) //if ((roomType == group.roomType && group.minLevel <= playerLevel && group.maxLevel >= playerLevel && group.maxWorld >= world && group.minWorld <= world && forcedId < 0) || (forcedId > 0 && group.id == forcedId)) { List <MonsterSpawnInfo> infos = new List <MonsterSpawnInfo>(); int count = 0; foreach (MobData mob in group.mobs) { Tile tile; if (mob.minSize != RegionSize.NULL) { if (size < mob.minSize) { continue; } } if (mob.location == MapRoom.DIRECTION_LARGEST_ROOM) { tile = room.GetLargestSubRoom(mob.exclude); } else { tile = room.GetSubRoom(mob.roomSize, mob.location, mob.exclude); } if (tile == null) { continue; } MonsterSpawnInfo monsterInfo; if (mob.count > 1) { for (int i = 0; i < mob.count; i++) { monsterInfo = level.SpawnMonsterToRoom(room, mob.monsterTypeName, tile, true, mob.level, mob.chance); if (monsterInfo != null) { count++; monsterInfo.tempId = mob.mobId; if (mob.idParent > 0) { try { MonsterSpawnInfo parent = null; foreach (MonsterSpawnInfo inf in infos) { if (inf.tempId == mob.idParent) { parent = inf; break; } } monsterInfo.master = parent; } catch (Exception) { throw new Exception("pokousim se nastavit idparent na " + mob.idParent + " ale takovy mob neexistuje! kouka se jen na moby ktere byly nacteny drive. ID nacitaneho moba je " + mob.mobId); } } infos.Add(monsterInfo); } } } else { monsterInfo = level.SpawnMonsterToRoom(room, mob.monsterTypeName, tile, false, mob.level, mob.chance); if (monsterInfo != null) { count++; monsterInfo.tempId = mob.mobId; if (mob.idParent > 0) { try { MonsterSpawnInfo parent = null; foreach (MonsterSpawnInfo inf in infos) { if (inf.tempId == mob.idParent) { parent = inf; break; } } monsterInfo.master = parent; } catch (Exception) { throw new Exception("pokousim se nastavit idparent na " + mob.idParent + " ale takovy mob neexistuje! kouka se jen na moby ktere byly nacteny drive. ID nacitaneho moba je " + mob.mobId); } } infos.Add(monsterInfo); } } } if (group.extraGroups.Any()) { int minStack = 10000; int maxStack = 0; foreach (ExtraGroupData extraGroup in group.extraGroups) { // spawn all -1 groups if (extraGroup.stackId == -1) { if (Random.Range(0, 100) < extraGroup.chance) { GenerateGenericEnemyGroup(room, level, RoomType.EXTRA_ROOM, difficulty, regionData, extraGroup.groupId); } } else // optimize for next for loop { if (extraGroup.stackId > maxStack) { maxStack = extraGroup.stackId; } if (extraGroup.stackId < minStack) { minStack = extraGroup.stackId; } } } // are there any groups that have stackid set? if (maxStack > 0) { // shuffle System.Random rnd = new System.Random(); IOrderedEnumerable <ExtraGroupData> shuffled = group.extraGroups.OrderBy(item => rnd.Next()); for (int i = minStack; i <= maxStack; i++) { foreach (ExtraGroupData extraGroup in shuffled) { if (extraGroup.stackId == i) { if (Random.Range(0, 100) < extraGroup.chance) { GenerateGenericEnemyGroup(room, level, RoomType.EXTRA_ROOM, difficulty, regionData, extraGroup.groupId); break; // only one spawned group per stack } } } } } } spawned = true; Debug.Log("spawnuto " + count + " ze skup. " + selectedId); break; } } if (!spawned) { Debug.LogError("nenalezena spawngroup do mistnosti typu " + roomType.ToString() + " " + room.region.x + "-" + room.region.y + " in world " + level.ToString()); } if (forcedId > 0 && WorldHolder.instance.activeMap != null) { WorldHolder.instance.activeMap.ConfigureMonstersAfterSpawn(); } }