Пример #1
0
        public async Task LoadPartialStateAsync(int index, IEnumerable <string> IDs, bool overwrite = false)
        {
            using (var db = new LiteDatabase(ConnectionString))
            {
                if (overwrite)
                {
                    await _runner.FlushEntitesAsync();
                }

                var temp = db.GetCollection <SharperSaveModel>("saves").FindById(index);

                foreach (var id in IDs)
                {
                    if (!temp.Data.ContainsKey(id))
                    {
                        throw new InvalidSaveStateException($"The ID {id} does not exist in the save file.");
                    }
                    var entity = new SharperEntity();
                    foreach (var component in temp.Data[id])
                    {
                        var system = _systems.Find(x => x.GetType().FullName == component.SystemType);
                        if (system == null)
                        {
                            throw new InvalidSaveStateException($"Cannot find System {component.SystemType}");
                        }
                        await system.RegisterComponentAsync(component.Import(entity));
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Add a <see cref="SharperEntity"/> to the Sharper Universe.
 /// </summary>
 /// <returns>An <see cref="EntityBuilder"/>, for adding multiple <see cref="SharperEntity"/> or <see cref="BaseSharperComponent"/> to the Sharper Universe.</returns>
 public EntityBuilder AddEntity()
 {
     ServerLog.LogInfo("Creating new SharperEntity...");
     _currentEntity = new SharperEntity();
     _entities.Add(_currentEntity);
     return(this);
 }
Пример #3
0
        public override async Task CycleUpdateAsync(int deltaMs)
        {
            var commands = await _input.GetEntitiesByCommandInfoTypesAsync(typeof(ExitCommandInfo), typeof(AnswerCommandInfo));

            foreach (var command in commands)
            {
                switch (command.Value)
                {
                case ExitCommandInfo _:
                    _input.GetConnectionByEntity(command.Key).Disconnect();
                    break;

                case AnswerCommandInfo a:
                    _guess       = a.Guess;
                    _inputEntity = command.Key;
                    _gameState   = GameState.Answer;

                    var commandEntityContext = command.Key;
                    var componentICareAbout  = Components.Single(c => c.ControllingEntity == commandEntityContext);

                    break;

                default:
                    break;
                }
            }

            switch (_gameState)
            {
            case GameState.Question:

                //await outputHandler.Invoke($"{left} + {right}");
                if (_inputEntity != null)
                {
                    var left  = _random.Next(1, 10);
                    var right = _random.Next(1, 10);
                    _answer = left + right;
                    _input.GetConnectionByEntity(_inputEntity).Send($"{left} + {right}");
                    _gameState = GameState.Answer;
                }
                break;

            case GameState.Answer:
                if (_guess == _answer)
                {
                    _guess = -1;
                    //await outputHandler.Invoke("Correct!\n");
                    _gameState = GameState.Question;
                    _input.GetConnectionByEntity(_inputEntity).Send($"Correct!");
                }
                break;
            }
        }
Пример #4
0
        public MathGameSystem(GameRunner game, SharperInputSystem input) : base(game)
        {
            _game   = game;
            _input  = input;
            _random = new Random();

            _input.NewInputEntityCreated += async(s, e) =>
            {
                await RegisterComponentAsync(await Game.CreateEntityAsync(), e.Entity);

                _inputEntity = e.Entity;
            };
        }
Пример #5
0
        public async Task LoadAsync(int index)
        {
            using (var db = new LiteDatabase(ConnectionString))
            {
                await _runner.FlushEntitesAsync();

                var temp = db.GetCollection <SharperSaveModel>("saves").FindById(index);
                foreach (var pair in temp.Data)
                {
                    var entity = new SharperEntity();
                    foreach (var component in pair.Value)
                    {
                        var system = _systems.Find(x => x.GetType().FullName == component.SystemType);
                        if (system == null)
                        {
                            throw new InvalidSaveStateException($"Cannot find System {component.SystemType}");
                        }
                        await system.RegisterComponentAsync(component.Import(entity));
                    }
                }
            }
        }
Пример #6
0
 public TestComponent(SharperEntity entity, bool startState, SharperEntity ownerEntity) : base(entity)
 {
     State       = startState;
     OwnerEntity = ownerEntity;
 }
Пример #7
0
 public BarComponent(SharperEntity entity) : base(entity)
 {
 }
 public SharperConnectionComponent(SharperEntity entity, ISharperConnection connection) : base(entity)
 {
     Connection = connection;
 }
Пример #9
0
 public PlayerComponent(SharperEntity entity) : base(entity)
 {
 }
 public FooExportableComponent Import(SharperEntity entity)
 {
     return(new FooExportableComponent(entity));
 }
 public FooExportableComponent(SharperEntity entity) : base(entity)
 {
     Foo = "foo";
 }
Пример #12
0
 public TestComponent(SharperEntity entity, bool startState) : base(entity)
 {
     State = startState;
 }
Пример #13
0
		public BarExportableComponent Import(SharperEntity entity)
		{
			return new BarExportableComponent(entity);
		}
Пример #14
0
 public EmptyComponent(SharperEntity entity) : base(entity)
 {
 }
Пример #15
0
 public RoundComponent(SharperEntity entity) : base(entity)
 {
     State = RoundState.Start;
 }
 protected BaseSharperComponent(SharperEntity entity)
 {
     Entity = entity;
 }
Пример #17
0
 public LocationComponent(SharperEntity entity, Location location, Dictionary <string, int> explorableLocations, bool playerIsHere) : base(entity)
 {
     Location            = location;
     PlayerIsHere        = playerIsHere;
     ExplorableLocations = explorableLocations;
 }
 public MathGameComponent(SharperEntity entity, SharperEntity controlingEntity) : base(entity)
 {
     ControllingEntity = controlingEntity;
 }
Пример #19
0
 public FooComponent(SharperEntity entity) : base(entity)
 {
 }