等级组件
Inheritance: BaseComponent
コード例 #1
0
        public override Room BuildRoom(LevelComponent level, IEnumerable <Point> points, Action <Point> insideAction,
                                       Action <Point> perimeterAction, Action <Point> outsideAction)
        {
            var room = base.BuildRoom(level, points, insideAction, perimeterAction, outsideAction);

            if (room == null ||
                room.InsidePoints.Count == 0)
            {
                return(room);
            }

            var connectionDefinitions = Connections;

            if (connectionDefinitions.Count == 0)
            {
                connectionDefinitions = new[] { new LevelConnection() };
            }

            var manager = level.Entity.Manager;

            foreach (var levelConnection in connectionDefinitions.Where(c => c.Glyph == null))
            {
                var connectionPoint = level.GenerationRandom.Pick(room.InsidePoints,
                                                                  p => manager.ConnectionsToLevelRelationship[level.EntityId]
                                                                  .All(c => c.Position.LevelCell != p));
                CreateConnection(level, connectionPoint, levelConnection);
            }

            return(room);
        }
コード例 #2
0
        public void Apply(IEntity entity)
        {
            var levelComponent = new LevelComponent();

            UpdateLevel(levelComponent, _level);
            entity.AddComponent(levelComponent);
        }
コード例 #3
0
ファイル: LevelGen.cs プロジェクト: kitbdev/svdr21
 IEnumerator RandomizeRooms()
 {
     // randomize optional room components
     LLog("Randomizing Rooms");
     if (advancedDebug)
     {
         yield return(null);
     }
     foreach (var room in placedRooms)
     {
         // use all required ones
         // LLog("required Room components for " + room.name);
         if (advancedDebug)
         {
             yield return(null);
         }
         var rlcs = room.reqLevelComponents;
         foreach (var reqlc in rlcs)
         {
             room.TryUseLComponent(reqlc);
             if (advancedDebug)
             {
                 yield return(null);
             }
         }
         // todo special components
         // todo stuff like chests, targets, locked gates
         // randomly use optional ones
         var nlcs    = room.normalLevelComponents;
         var nlcsLen = room.normalLevelComponents.Count;
         // LLog("optional Room components for " + room.name + " " + nlcsLen);
         if (advancedDebug)
         {
             yield return(null);
         }
         // choose random ones to use
         for (int i = 0; i < nlcsLen && room.normalLevelComponents.Count > 0; i++)
         {
             bool rUse = Random.value > 0.5f;
             if (rUse)
             {
                 // first one should change, by either getting blocked or used
                 LevelComponent rcomp = room.normalLevelComponents[0];
                 room.TryUseLComponent(rcomp);
                 if (advancedDebug)
                 {
                     yield return(null);
                 }
             }
         }
         if (advancedDebug)
         {
             yield return(null);
         }
     }
     if (advancedDebug)
     {
         yield return(null);
     }
 }
コード例 #4
0
 public static byte[] GetVisibleTerrain(LevelComponent level, Point origin, byte[] visibleTerrain,
                                        bool noFalloff = true)
 {
     level.VisibilityCalculator.ComputeOmnidirectional(
         origin, range: 24, noFalloff, SensorySystem.TileBlocksVisibility, visibleTerrain);
     return(visibleTerrain);
 }
コード例 #5
0
    private void SpawnItemsInLevel(LevelComponent inLevelComponent, PointGroup inGroup)
    {
        RunnerItemManager runnerItemManager = RunnerItemManager.Instance;

        switch (inGroup.mSpawnType)
        {
        case eSpawnType.Coins:
        {
            SpawnCoinStrip(inLevelComponent, inGroup);
            break;
        }

        case eSpawnType.Hazards:
        {
            HazardItem newHazard = (HazardItem)runnerItemManager.GetRandomItemOfType(typeof(HazardItem), mCurrentLevelGroup.LevelGroupID);
            SpawnitemtAtRandomPointInGroup(inLevelComponent, inGroup, newHazard);
            break;
        }

        case eSpawnType.Items:
        {
            RunnerItem newItem = (RunnerItem)runnerItemManager.GetRandomItemOfType(typeof(RunnerItem), mCurrentLevelGroup.LevelGroupID);
            SpawnitemtAtRandomPointInGroup(inLevelComponent, inGroup, newItem);
            break;
        }
        }
    }
コード例 #6
0
        private void UpdateEntityKnowledge(
            GameEntity entity,
            EntityMatcher <GameEntity> matcher,
            GameManager manager,
            Point?additionalCellToTest = null,
            LevelComponent level       = null)
        {
            var position = entity.Position;

            if (position != null)
            {
                level = level ?? position.LevelEntity.Level;
            }

            SenseType sensedType;

            if (position != null &&
                ((sensedType = manager.SensorySystem.SensedByPlayer(entity, position.LevelCell))
                 != SenseType.None ||
                 (additionalCellToTest != null &&
                  (sensedType = manager.SensorySystem.SensedByPlayer(entity, additionalCellToTest.Value))
                  != SenseType.None)))
            {
                foreach (var conflictingKnowledge in
                         manager.LevelKnowledgeToLevelCellIndex[(position.LevelId, position.LevelX, position.LevelY)])
コード例 #7
0
        protected virtual Room TryPlaceStaticMap(LevelComponent level, Rectangle boundingRectangle)
        {
            // TODO: take transformations into account
            var target = boundingRectangle.PlaceInside(PayloadArea, level.GenerationRandom);

            if (!target.HasValue)
            {
                throw new InvalidOperationException($"Couldn't fit fragment {Name} into {boundingRectangle}");
            }

            var doorwayPoints   = new List <Point>();
            var perimeterPoints = new List <Point>();
            var insidePoints    = new List <Point>();
            var points          = new List <Point>();

            WriteMap(target.Value, level, Write, (doorwayPoints, perimeterPoints, insidePoints, points));

            if (!NoRandomDoorways && doorwayPoints.Count == 0)
            {
                // TODO: find doorway candidates in the perimeter walls
            }

            return(new Room(level, new Rectangle(target.Value, PayloadArea.Width, PayloadArea.Height), doorwayPoints,
                            insidePoints));
        }
コード例 #8
0
        public static ConnectionComponent CreateSourceConnection(
            LevelComponent level, Point cell, string targetBranchName, byte targetDepth = 1)
        {
            var game    = level.Game;
            var manager = game.Manager;
            var branch  = game.GetBranch(targetBranchName) ??
                          Branch.Loader.Find(targetBranchName).Instantiate(game);

            var   targetLevel = branch.Levels.FirstOrDefault(l => l.Depth == targetDepth);
            Point?targetCell  = null;

            if (targetLevel != null)
            {
                var matchingConnection = manager.IncomingConnectionsToLevelRelationship[targetLevel.EntityId]
                                         .Select(c => c.Connection)
                                         .FirstOrDefault(c => c.TargetLevelId == level.EntityId && c.TargetLevelX == null);
                if (matchingConnection != null)
                {
                    matchingConnection.TargetLevelCell = cell;
                    targetCell = matchingConnection.Entity.Position.LevelCell;
                }
            }
            else
            {
                targetLevel = LevelGenerator.CreateEmpty(branch, targetDepth, level.GenerationRandom.Seed, manager);
            }

            return(CreateConnection(level, cell, targetLevel.EntityId, targetCell));
        }
コード例 #9
0
ファイル: Level.cs プロジェクト: nduas77/moto-trial-racer-wp
        /// <summary>
        /// Adds a new component to this level
        /// </summary>
        /// <param name="type">The type of the component</param>
        /// <param name="x">The x position of the component</param>
        /// <param name="y">The y position of the component</param>
        /// <param name="angle">The rotation angle of the component</param>
        /// <returns></returns>
        public LevelComponent Add(LevelComponentType type, float x, float y, float angle)
        {
            Vector2        pos       = new Vector2(x, y);
            LevelComponent component = null;

            switch (type)
            {
            case LevelComponentType.grass:
                component = new Ground(world, content, pos, angle, 400, 60);
                break;

            case LevelComponentType.jump:
                component = new Jump(world, content, pos, angle, 150, 85);
                break;

            case LevelComponentType.nail:
                component = new SpikeMat(world, content, pos, angle, 250, 70);
                break;

            case LevelComponentType.finish:
                component = new Finish(world, content, pos, angle, 100, 200);
                break;
            }

            if (component != null)
            {
                components.Add(component);
            }

            return(component);
        }
コード例 #10
0
        private void SetupLevel(LevelComponent levelComponent)
        {
            levelComponent.HasLoaded.Value = false;

            defaultCollection.RemoveEntitiesContaining(typeof(GameBoardComponent),
                                                       typeof(FoodComponent), typeof(WallComponent),
                                                       typeof(EnemyComponent), typeof(ExitComponent));

            Observable.Interval(TimeSpan.FromSeconds(_gameConfiguration.IntroLength))
            .First()
            .Subscribe(x => levelComponent.HasLoaded.Value = true);

            defaultCollection.CreateEntity(new GameBoardBlueprint());

            for (var i = 0; i < levelComponent.FoodCount; i++)
            {
                defaultCollection.CreateEntity(new FoodBlueprint());
            }

            for (var i = 0; i < levelComponent.WallCount; i++)
            {
                defaultCollection.CreateEntity(new WallBlueprint());
            }

            for (var i = 0; i < levelComponent.EnemyCount; i++)
            {
                defaultCollection.CreateEntity(new EnemyBlueprint());
            }

            defaultCollection.CreateEntity(new ExitBlueprint());
        }
コード例 #11
0
        protected static ConnectionComponent CreateConnection(
            LevelComponent level, Point point, int targetLevelId, Point?targetCell)
        {
            var manager = level.Entity.Manager;

            using (var connectionEntityReference = manager.CreateEntity())
            {
                var connectionEntity = connectionEntityReference.Referenced;

                var position = manager.CreateComponent <PositionComponent>(EntityComponent.Position);
                position.LevelEntity = level.Entity;
                position.LevelCell   = point;

                connectionEntity.Position = position;

                var connection = manager.CreateComponent <ConnectionComponent>(EntityComponent.Connection);
                connection.TargetLevelId   = targetLevelId;
                connection.TargetLevelCell = targetCell;

                connectionEntity.Connection = connection;


                return(connection);
            }
        }
コード例 #12
0
ファイル: LevelGroup.cs プロジェクト: aliken9/MyZooPets
    /// <summary>
    /// Gets the component.
    /// </summary>
    /// <returns>level component</returns>
    /// <param name="index">arrya index</param>
    private LevelComponent GetComponent(int index)
    {
        GameObject     lvComponentObj = null;
        LevelComponent retVal         = null;

        try{
            lvComponentObj = levelComponentsGO[index];

            if (componentsInScene.Contains(lvComponentObj.name))
            {
                lvComponentObj = levelComponentsGO.Find(component => componentsInScene.Contains(component.name) == false);
            }

            lvComponentObj.SetActive(true);

            if (lvComponentObj != null)
            {
                componentsInScene.Add(lvComponentObj.name);
                retVal = lvComponentObj.GetComponent <LevelComponent>();
            }
        } catch (ArgumentOutOfRangeException e) {
            Debug.Log("Error message: " + e.Message);
        }

        return(retVal);
    }
コード例 #13
0
        protected override void OnUpdate()
        {
            var commandBuffer   = m_Barrier.CreateCommandBuffer().ToConcurrent();
            var rpcFromEntity   = GetBufferFromEntity <OutgoingRpcDataStreamBufferComponent>();
            var levelFromEntity = GetComponentDataFromEntity <LevelComponent>();
            var levelSingleton  = m_LevelSingleton;
            var rpcQueue        = m_RpcQueue;

            Entities.ForEach((Entity entity, int nativeThreadIndex, in LevelLoadRequest request, in ReceiveRpcCommandRequestComponent requestSource) =>
            {
                commandBuffer.DestroyEntity(nativeThreadIndex, entity);
                // Check for disconnects
                if (!rpcFromEntity.Exists(requestSource.SourceConnection))
                {
                    return;
                }
                // set the level size - fake loading of level
                levelFromEntity[levelSingleton] = new LevelComponent
                {
                    width          = request.width,
                    height         = request.height,
                    playerForce    = request.playerForce,
                    bulletVelocity = request.bulletVelocity
                };
                commandBuffer.AddComponent(nativeThreadIndex, requestSource.SourceConnection, new PlayerStateComponentData());
                commandBuffer.AddComponent(nativeThreadIndex, requestSource.SourceConnection, default(NetworkStreamInGame));
                rpcQueue.Schedule(rpcFromEntity[requestSource.SourceConnection], new RpcLevelLoaded());
            }).Schedule();
コード例 #14
0
        public static bool EnsureGenerated(LevelComponent levelComponent)
        {
            if (levelComponent.Width != 0)
            {
                return(false);
            }

            try
            {
                var fragment = levelComponent.GenerationRandom.Pick(DefiningMapFragment.Loader.GetAsList(),
                                                                    f => f.GetWeight(levelComponent.BranchName, levelComponent.Depth));

                return(Generate(levelComponent, fragment) != null);
            }
            catch (Exception e)
            {
                // TODO: Log parameters if failed
                var msg = $@"Error while generating level '{levelComponent.BranchName}:{levelComponent.Depth
                    }', initial seed {levelComponent.Game.InitialSeed}:
";

                Console.WriteLine(msg);
                Console.WriteLine(e);
                throw new Exception(msg, e);
            }
        }
コード例 #15
0
    private void SelectCurveType(LevelComponent inComponent, PointGroup inGroup, eCurveType inNewSelectedCurve)
    {
        eCurveType currentCurveType = inGroup.mCurveType;

        if (currentCurveType != inNewSelectedCurve)
        {
            // Determine the new point.
            switch (inNewSelectedCurve)
            {
            case eCurveType.Point:
                CutOrAddGroupPointsTo(inComponent, inGroup, 1);
                break;

            case eCurveType.Quadratic:
                CutOrAddGroupPointsTo(inComponent, inGroup, 3);
                break;

            case eCurveType.Cubic:
                CutOrAddGroupPointsTo(inComponent, inGroup, 4);
                break;
            }

            // Set it.
            inGroup.mCurveType = inNewSelectedCurve;
        }
    }
コード例 #16
0
 public void UpdateLevel(LevelComponent levelComponent, int level)
 {
     levelComponent.EnemyCount  = (int)Mathf.Log(level, 2f);
     levelComponent.FoodCount   = Random.Range(_minFood, _maxFood);
     levelComponent.WallCount   = Random.Range(_minWalls, _maxWalls);
     levelComponent.Level.Value = level;
 }
コード例 #17
0
ファイル: LevelGroup.cs プロジェクト: aliken9/MyZooPets
    /// <summary>
    /// Gets the start level component.
    /// </summary>
    /// <returns>The start level component.</returns>
    public LevelComponent GetStartLevelComponent()
    {
        LevelComponent retVal = null;

        retVal = GetComponent(0);

        return(retVal);
    }
コード例 #18
0
 public static byte[] GetVisibleTerrain(
     LevelComponent level, Point origin, Direction heading, byte[] visibleTerrain, bool noFalloff = true)
 {
     level.VisibilityCalculator.ComputeDirected(
         origin, heading, primaryFOVQuadrants: 1, primaryRange: 24, totalFOVQuadrants: 2, secondaryRange: 12,
         noFalloff, SensorySystem.TileBlocksVisibility, visibleTerrain);
     return(visibleTerrain);
 }
コード例 #19
0
    public async void Awake()
    {
        Commander.RegisterInject <LevelController>(this);
        Assert.IsNotNull(loadLevelConfig, "нет конфига загрузки уровней");
        currentLevel = await loadLevelConfig.GetLevelByIndex(currentLvlIndex);

        Commander.Invoke(new LevelReadyGlobalCommand());
    }
コード例 #20
0
        public static ConnectionComponent CreateReceivingConnection(
            LevelComponent level, Point cell, ConnectionComponent incoming)
        {
            incoming.TargetLevelCell = cell;
            var incomingPosition = incoming.Entity.Position;

            return(CreateConnection(level, cell, incomingPosition.LevelId, incomingPosition.LevelCell));
        }
コード例 #21
0
        public TestStandMapping()
        {
            PT_N2   = new PressureComponent(16, "PT_N2", "PT-N2", 400);
            PT_IPA  = new PressureComponent(17, "PT_IPA", "PT-IPA", 50);
            PT_N2O  = new PressureComponent(18, "PT_N2O", "PT-N2O", 50);
            PT_FUEL = new PressureComponent(19, "PT_FUEL", "PT-FUEL", 50);
            PT_OX   = new PressureComponent(20, "PT_OX", "PT-OX", 50);
            PT_CHAM = new PressureComponent(21, "PT_CHAM", "PT-CHAM", 50);

            TC_IPA = new TemperatureComponent(8, "TC_IPA", "TC-IPA", x => x);
            TC_N2O = new TemperatureComponent(9, "TC_N2O", "TC-N2O", x => x);
            TC_1   = new TemperatureComponent(10, "TC_1", "TC-1", x => x);
            TC_2   = new TemperatureComponent(11, "TC_2", "TC-2", x => x);
            TC_3   = new TemperatureComponent(12, "TC_3", "TC-3", x => x);
            TC_4   = new TemperatureComponent(13, "TC_4", "TC-4", x => x);
            TC_5   = new TemperatureComponent(14, "TC_5", "TC-5", x => x);
            TC_6   = new TemperatureComponent(15, "TC_6", "TC-6", x => x);

            LOAD = new LoadComponent(0, "LOAD", "Load cell");

            SV_IPA = new SolenoidComponent(4, "SV_IPA", "SV-IPA", "SV_IPA_SYMBOL");
            SV_N2O = new SolenoidComponent(5, "SV_N2O", "SV-N2O", "SV_N2O_SYMBOL");
            MV_IPA = new ServoComponent(6, "MV_IPA", "MV-IPA", "MV_IPA_SYMBOL");
            MV_N2O = new ServoComponent(7, "MV_N2O", "MV-N2O", "MV_N2O_SYMBOL");

            TARGET_MV_IPA = new SimpleComponent(25, 2, false, "TARGET-MV-IPA", "TARGET-MV-IPA [%]", x => ((float)x) / ushort.MaxValue * 100.0f);
            TARGET_MV_N2O = new SimpleComponent(26, 2, false, "TARGET-MV-N20", "TARGET-MV-N20 [%]", x => ((float)x) / ushort.MaxValue * 100.0f);

            SN_N2O_FILL = new SolenoidComponent(2, "SN_N2O_FILL", "SN-N2O-FILL", "SN_N2O_FILL_SYMBOL");
            SN_FLUSH    = new SolenoidComponent(3, "SN_FLUSH", "SN-FLUSH", "SN_FLUSH_SYMBOL");

            BATTERY = new VoltageComponent(22, "BATTERY", "BATTERY", 12.0f, 14.8f);

            FLO_IPA = new FlowComponent(100, "FLO_IPA", "FLO-IPA", ref PT_FUEL, ref PT_CHAM, () => PreferenceManager.Manager.Preferences.Fluid.Fuel);
            FLO_N2O = new FlowComponent(101, "FLO_N2O", "FLO-N2O", ref PT_N2O, ref PT_CHAM, () => PreferenceManager.Manager.Preferences.Fluid.Oxid);

            T_IPA = new TankComponent(24, "FUEL", "FUEL", "FUEL_GRADIENT", ref FLO_IPA, "Fuel");
            T_N2O = new LevelComponent(1, "OXID", "OXID", "OXID_GRADIENT", 20);

            STACK_HEALTH = new StackHealthComponent(23, "STACK_MAIN", "STACK_ACTUATOR", "STACK_SENSOR", "STACK-HEALTH");
            _states      = new List <State>
            {
                new State(0, "Idle"),
                new State(1, "Ignition"),
                new State(2, "Pre-Stage 1"),
                new State(3, "Pre-Stage 2"),
                new State(4, "Ramp up"),
                new State(5, "Regulated"),
                new State(6, "Shutdown 1"),
                new State(7, "Shutdown 2"),
                new State(8, "Flush")
            };
            EmergencyState = _states[6];

            PreferenceManager.Manager.Preferences.AutoSequenceComponentIDs.ChamberPressureID      = PT_CHAM.BoardID;
            PreferenceManager.Manager.Preferences.AutoSequenceComponentIDs.FuelLinePressureID     = PT_FUEL.BoardID;
            PreferenceManager.Manager.Preferences.AutoSequenceComponentIDs.OxidizerLinePressureID = PT_OX.BoardID;
        }
コード例 #22
0
ファイル: LevelGroup.cs プロジェクト: aliken9/MyZooPets
    /// <summary>
    /// Gets the random component.
    /// </summary>
    /// <returns>The random component.</returns>
    public LevelComponent GetRandomComponent()
    {
        LevelComponent retVal      = null;
        int            randomIndex = UnityEngine.Random.Range(0, levelComponentsGO.Count); //get a random index

        retVal = GetComponent(randomIndex);

        return(retVal);
    }
コード例 #23
0
        public virtual List <Room> Fill(LevelComponent level, DefiningMapFragment fragment)
        {
            InitializeTerrain(level, fragment);
            var rooms = PlaceDefiningMapFragment(level, fragment);

            PlaceSurroundingFragments(level, rooms);

            return(rooms);
        }
コード例 #24
0
        public void Setup(LevelComponent level, PlayerData player)
        {
            Level  = level;
            Player = player;
            var agent = GetComponent <NavMeshAgent>();

            agent.enabled = true;

            CurrentHealth = Health;
        }
コード例 #25
0
 public void StartSystem()
 {
     this.WaitForScene()
     .Subscribe(x =>
     {
         var level       = ObservableGroup.First();
         _levelComponent = level.GetComponent <LevelComponent>();
         SetupSubscriptions();
     });
 }
コード例 #26
0
 public void StartSystem(IGroupAccessor @group)
 {
     this.WaitForScene()
     .Subscribe(x =>
     {
         var level       = @group.Entities.First();
         _levelComponent = level.GetComponent <LevelComponent>();
         SetupSubscriptions();
     });
 }
コード例 #27
0
    private void CreateNewGroup(LevelComponent inSelectedLevel)
    {
        // Create new, blank data.
        // string defaultName = "ID" + inSelectedLevel.NextID;

        // PointGroup newGroup = new PointGroup(defaultName);
        PointGroup newGroup = new PointGroup();

        inSelectedLevel.SetPointGroupInfo(newGroup);
    }
コード例 #28
0
ファイル: LevelGen.cs プロジェクト: kitbdev/svdr21
    IEnumerator GenLevelCo()
    {
        // clear
        ClearLevel();
        yield return(null);

        // start
        Debug.Log("Level Gen start");
        if (stairsRoom != null)
        {
            placedRooms.Add(stairsRoom);
            stairsRoom = null;
        }
        // spawn rooms
        yield return(StartCoroutine(SpawnAllRooms()));

        if (forceRetry)
        {
            ReGenerateLevel();
            yield break;
        }
        nextLevelDoor = mainPath[mainPath.Count - 1].allConnectors[1];
        // detach stairs room so it doesn't get unloaded here
        // stairsRoom.transform
        yield return(null);

        // randomize individual rooms
        yield return(StartCoroutine(RandomizeRooms()));

        yield return(null);

        // add loot
        // finish rooms
        foreach (Room room in placedRooms)
        {
            room.LevelStart();
        }
        // todo
        // spawn enemies

        /*
         * enemies can be anywhere besides start and end rooms
         * ? spawn in rooms
         * ? move to enemy manager
         * ? use enemy generators
         */
        // todo
        if (forceRetry)
        {
            ReGenerateLevel();
            yield break;
        }
        Debug.Log("Level Gen complete");
        GenCompleteEvent.Invoke();
    }
コード例 #29
0
 public void StartSystem(IObservableGroup group)
 {
     this.WaitForScene()
     .Subscribe(x =>
     {
         var level       = @group.First();
         _levelComponent = level.GetComponent <LevelComponent>();
         _levelText      = GameObject.Find("LevelText").GetComponent <Text>();
         SetupSubscriptions();
     });
 }
コード例 #30
0
 protected void InitializeTerrain(LevelComponent level, DefiningMapFragment fragment)
 {
     level.TerrainChanges        = null;
     level.WallNeighboursChanges = null;
     if (fragment.DefaultTerrain != MapFeature.Default)
     {
         for (var index = 0; index < level.Terrain.Length; index++)
         {
             level.Terrain[index] = (byte)fragment.DefaultTerrain;
         }
     }
 }
コード例 #31
0
 // Use this for initialization
 void Start()
 {
     s_Instance = this;
 }
コード例 #32
0
ファイル: Building.cs プロジェクト: shuitian/LonelyCity
 void Awake()
 {
     levelComponent = GetComponent<LevelComponent>();
     attackComponent = GetComponent<AttackComponent>();
 }