Ejemplo n.º 1
0
        private async Task ActionLook()
        {
            // 通知周围creature entity看着玩家
            EntityWorldPos    entityPos = AttachedObject.GetValue(EntityWorldPositionComponent.EntityWorldPositionProperty);
            ChunkWorldPos     chunkPos  = entityPos.ToChunkWorldPos();
            IChunkTrackingHub tracker   = GrainFactory.GetGrain <IChunkTrackingHub>(AttachedObject.GetAddressByPartitionKey());
            var list = await tracker.GetTrackedPlayers();

            // TODO 多位玩家的话只看一位
            foreach (IPlayer each in list)
            {
                EntityWorldPos playerPosition = await each.GetPosition();

                // 三格内玩家
                if (EntityWorldPos.Distance(playerPosition, entityPos) < 3)
                {
                    (var yaw, var pitch) = VectorToYawAndPitch(entityPos, playerPosition);

                    await AttachedObject.SetLocalValue(EntityLookComponent.YawProperty, yaw);

                    await AttachedObject.SetLocalValue(EntityLookComponent.HeadYawProperty, yaw);

                    await AttachedObject.SetLocalValue(EntityLookComponent.PitchProperty, pitch);

                    break;
                }
            }
        }
Ejemplo n.º 2
0
 public void TestEntityWorldPos_ToChunkWorldPos()
 {
     Assert.Equal(_cwPos1, _ewPos1.ToChunkWorldPos());
     Assert.Equal(_cwPos2, _ewPos2.ToChunkWorldPos());
     Assert.Equal(_cwPos3, _ewPos3.ToChunkWorldPos());
     Assert.Equal(_cwPos4, _ewPos4.ToChunkWorldPos());
     Assert.Equal(_cwPos5, _ewPos5.ToChunkWorldPos());
 }
Ejemplo n.º 3
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();
            }
        }