private void CreateStages(DungeonConfig dungeonCfg, DungeonLogic dungeonLogic)
        {
            foreach (StageConfig stageConfig in dungeonCfg.StageList())
            {
                DefaultStage stage = new DefaultStage(defaultEnvironment);
                dungeonLogic.AddStage(stage);

                CreateGoals(stageConfig, stage);

                CreateLosingConditions(stageConfig, stage);

                CreateWaves(stageConfig, stage, dungeonLogic);
            }
        }
        public DungeonFactory(DungeonConfig dungeonConfig, EntitySpawner entitySpawner,
                              CharacterId heroId, List <SsarTuple <int, GameObject> > gateAndId,
                              DamageSystem damageSystem, PromiseWorld world, ConfigManager configManager)
        {
            notNullReference.Check(dungeonConfig, "dungeonConfig");
            notNullReference.Check(entitySpawner, "entitySpawner");
            notNullReference.Check(heroId, "heroId");
            notNullReference.Check(gateAndId, "gateAndId");
            notNullReference.Check(damageSystem, "damageSystem");
            notNullReference.Check(configManager, "configManager");

            heroAndMonsterConfig = configManager.GetConfig <HeroAndMonsterConfig>();
            defaultEnvironment   = new DefaultDungeonEnvironment(entitySpawner, gateAndId);
            this.dungeonConfig   = dungeonConfig;

            world.EntityCreationEventHandler += (sender, arg) =>
            {
                Entity entity = arg.Entity;
                if (arg.EntityType != EntityType.Creature)
                {
                    return;
                }

                if (entity.GetComponent <SkillComponent>().CharacterId.Equals(heroId))
                {
                    defaultEnvironment.SetHero(new DefaultDungeonCharacter(entity, damageSystem));
                }
            };

            damageSystem.EntityDeathEventHandler_Late += (sender, args) =>
            {
                CacheTemplateArgsComponent argsComponent = args.Entity.GetComponent <CacheTemplateArgsComponent>();
                SpawnSourceInfo            source        = argsComponent?.TemplateArgs.GetEntry <SpawnSourceInfo>(TemplateArgsName.SpawnSource) ?? new DungeonSystemSpawnSourceInfo();
                EntityRole role = args.Entity.GetComponent <StatsComponent>().BasicStatsFromConfig.ShowRole();
                defaultEnvironment.AddDeadMonster(new EntityMonster(Time.timeSinceLevelLoad,
                                                                    args.Entity.GetComponent <SkillComponent>().CharacterId, args.Entity.UniqueId, source, role));
            };

            entitySpawner.EntitySpawnEventHandler += (sender, args) =>
            {
                if (args.Entity.Group == EntityGroup.GROUP_A)
                {
                    return;
                }
                defaultEnvironment.AddSpawnedMonster(args.UniqueId, args.BasicStats, args.Entity);
            };
        }