示例#1
0
        private async Task OnFixedUpdate(object sender, GameTickArgs e)
        {
            await _world.OnGameTick(e);

            await Task.WhenAll(from u in _users.Keys
                               select u.OnGameTick(e));
        }
示例#2
0
        private async Task OnTick(object arg)
        {
            var expectedAge = (_stopwatch.ElapsedMilliseconds + _updateMs - 1) / _updateMs;
            var updateTimes = expectedAge - _actualAge;

            if (updateTimes > 0)
            {
                var e = new GameTickArgs {
                    DeltaTime = TimeSpan.FromMilliseconds(50)
                };
                for (int i = 0; i < updateTimes; i++)
                {
                    e.WorldAge  = _worldAge;
                    e.TimeOfDay = _worldAge % 24000;
                    await Tick.InvokeSerial(this, e);

                    _worldAge++;
                    _actualAge++;
                }

                var now       = _stopwatch.Elapsed;
                var deltaTime = now - _lastUpdate;
                _lastUpdate = now;
            }
        }
 private async Task OnGameTick(object sender, GameTickArgs e)
 {
     while (_deferredPacket.TryDequeue(out var packet))
     {
         await DispatchPacket((dynamic)packet);
     }
 }
示例#4
0
 private async Task OnGameTick(object sender, GameTickArgs e)
 {
     while (_deferredPacket.Count != 0)
     {
         await DispatchPacket(_deferredPacket.Dequeue());
     }
 }
示例#5
0
        private Task OnFixedUpdate(object sender, GameTickArgs e)
        {
            var msg = new GameTick {
                Args = e
            };

            return(Task.WhenAll(from t in _tickables select t.Tell(msg)));
        }
示例#6
0
        public Task OnGameTick(GameTickArgs e)
        {
            var msg = new GameTick {
                Args = e
            };

            return(Task.WhenAll(from t in State.Subscription select t.Tell(msg)));
        }
示例#7
0
 private Task OnGameTick(object sender, GameTickArgs e)
 {
     if (_loaded)
     {
         return(_chunkLoader.OnGameTick(e.WorldAge));
     }
     return(Task.CompletedTask);
 }
示例#8
0
        public Task OnGameTick(object sender, GameTickArgs e)
        {
            if (AttachedObject.ValueStorage.IsDirty && (e.WorldAge % _periodTime == 0))
            {
                return(AttachedObject.WriteStateAsync());
            }

            return(Task.CompletedTask);
        }
示例#9
0
        private Task OnGameTick(object sender, GameTickArgs e)
        {
            // Every 40 tick, check whether entities are out of world
            if (e.WorldAge % 40 == 0)
            {
                if (AttachedObject.Position.Y < -64)
                {
                    var health = AttachedObject.GetComponent <HealthComponent>();
                    health.SetHealth(health.Health - 4);
                }
            }

            return(Task.CompletedTask);
        }
 private async Task OnGameTick(object sender, GameTickArgs e)
 {
     if (_isOnline && _keepAliveWaiters.Count >= ClientKeepInterval)
     {
         _isOnline = false;
         await AttachedObject.Tell(new KickPlayer());
     }
     else if (_isOnline && e.WorldAge % 20 == 0)
     {
         var id = _keepAliveId++;
         _keepAliveWaiters.Add(id, DateTime.UtcNow);
         await AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator().KeepAlive(id);
     }
 }
示例#11
0
        public async Task OnGameTick(GameTickArgs e)
        {
            if (_userState == UserState.DownloadingWorld)
            {
                _userState = UserState.Playing;
                await _generator.TimeUpdate(e.WorldAge, e.TimeOfDay);
            }

            if (e.WorldAge % 20 == 0)
            {
                await _generator.TimeUpdate(e.WorldAge, e.TimeOfDay);
            }

            await Tell(new GameTick { Args = e });
        }
示例#12
0
        public async Task OnGameTick(GameTickArgs e)
        {
            if (_userState == UserState.DownloadingWorld)
            {
                // await _player.SendPositionAndLook();
                _userState = UserState.Playing;
            }

            /*
             * if (_state >= UserState.JoinedGame && _state < UserState.Destroying)
             *  await _chunkLoader.OnGameTick(worldAge);*/
            await _generator.TimeUpdate(e.WorldAge, e.TimeOfDay);

            await _autoSave.OnGameTick(this, e);
        }
示例#13
0
        public async Task OnGameTick(GameTickArgs e)
        {
            if (_userState == UserState.DownloadingWorld)
            {
                _userState = UserState.Playing;
                await _generator.TimeUpdate(e.WorldAge, e.TimeOfDay);
            }

            // When server has not sent Join Game, TimeUpdate will cause minecraft client NullPointerException.(Test in 1.15.2)
            if (e.WorldAge % 20 == 0 && _userState == UserState.Playing)
            {
                await _generator.TimeUpdate(e.WorldAge, e.TimeOfDay);
            }

            await Tell(new GameTick { Args = e });
        }
示例#14
0
        private async Task OnGameTick(object sender, GameTickArgs e)
        {
            var state = State;

            if (CanCook())
            {
                if (!state.IsCooking)
                {
                    await StartCooking();
                }
                if (state.CookProgress == 0)
                {
                    await TakeIngredient();
                }
                if (state.FuelLeft == 0)
                {
                    await TakeFuel();
                }

                if (state.CurrentRecipe != null)
                {
                    state.CookProgress++;
                    state.FuelLeft--;
                    MarkDirty();

                    if (FurnaceWindow != null && e.WorldAge % 10 == 0)
                    {
                        await FurnaceWindow.SetProperty(FurnaceWindowPropertyType.ProgressArrow, (short)state.CookProgress);

                        await FurnaceWindow.SetProperty(FurnaceWindowPropertyType.FireIcon, (short)state.FuelLeft);
                    }
                }

                if (state.CookProgress == state.MaxProgress)
                {
                    await Produce();
                }
            }
            else if (state.IsCooking)
            {
                await StopCooking();
            }
        }
示例#15
0
        public async Task OnGameTick(GameTickArgs e, EntityWorldPos playerPosition)
        {
            if (e.WorldAge % 10 == 0)
            {
                for (int i = 0; i < 4 && _sendingChunks.Count <= 4; i++)
                {
                    if (await StreamNextChunk(playerPosition.ToChunkWorldPos()))
                    {
                        break;
                    }
                }
            }

            // unload per 5 seconds
            if (e.WorldAge % 100 == 0)
            {
                await UnloadOutOfRangeChunks();
            }
        }
示例#16
0
        private async Task OnGameTick(object sender, GameTickArgs e)
        {
            if (e.WorldAge % 512 == 0 && e.TimeOfDay > 12000 && e.TimeOfDay < 24000)
            {
                EntityWorldPos playerPosition = AttachedObject.GetValue(EntityWorldPositionComponent.EntityWorldPositionProperty);
                int            x = random.Next(9) - 4 + (int)playerPosition.X;
                int            z = random.Next(9) - 4 + (int)playerPosition.Z;
                BlockWorldPos  monsterBlockPos = new BlockWorldPos(x, 0, z);
                ChunkWorldPos  monsterChunkPos = monsterBlockPos.ToChunkWorldPos();
                var            chunkAccessor   = AttachedObject.GetComponent <ChunkAccessorComponent>();
                BiomeId        biomeId         = await chunkAccessor.GetBlockBiome(monsterBlockPos);

                IWorld            world   = AttachedObject.GetValue(WorldComponent.WorldProperty);
                GeneratorSettings setting = await world.GetGeneratorSettings();

                Biome        biome = Biome.GetBiome((int)biomeId, setting);
                IChunkColumn chunk = await chunkAccessor.GetChunk(monsterChunkPos);

                // TODO
                biome.SpawnMonster(world, GrainFactory, await chunk.GetState(), random, monsterBlockPos);
            }
        }
示例#17
0
        private async Task OnGameTick(object sender, GameTickArgs e)
        {
            if (_ai == null)
            {
                return;
            }

            /*
             * if (e.worldAge % 16 == 0)
             * {
             *  float pitch = AttachedObject.GetValue(EntityLookComponent.PitchProperty);
             *  pitch += 30 * 360.0f / 255;
             *  if (pitch > 360)
             *  {
             *      pitch = 0;
             *  }
             *
             *  AttachedObject.SetLocalValue(EntityLookComponent.PitchProperty, pitch);
             * }
             */

            /*
             * ICreatureAi ai = AttachedObject.GetValue(EntityAiComponent.AiTypeProperty);
             * IWorld world = AttachedObject.GetWorld();
             * var chunkAccessor = AttachedObject.GetComponent<ChunkAccessorComponent>();
             */

            // CreatureAiAction action = AttachedObject.GetValue(EntityAiComponent.CreatureAiActionProperty);
            // action.Action(AttachedObject);
            await GenerateEvent();

            // get state
            var newState = _ai.State;

            switch (newState)
            {
            case CreatureState.Attacking:
                break;

            case CreatureState.Burned:
                break;

            case CreatureState.BurnedBySunshine:
                break;

            case CreatureState.EatingGrass:
                break;

            case CreatureState.Escaping:
                break;

            case CreatureState.Explosion:
                break;

            case CreatureState.Follow:
                await ActionFollow();

                break;

            case CreatureState.Walk:
                await ActionWalk();

                break;

            case CreatureState.Stop:
                await ActionStop();

                break;

            case CreatureState.Look:
                await ActionLook();

                break;

            default:
                System.Console.WriteLine(newState);
                throw new NotSupportedException("Unsupported state.");
            }
        }
示例#18
0
 private Task OnFixedUpdate(object sender, GameTickArgs e)
 {
     return(_tickEmitter.OnGameTick(e));
 }
示例#19
0
 public Task OnGameTick(GameTickArgs e)
 {
     State.WorldAge++;
     MarkDirty();
     return(Task.CompletedTask);
 }