public Task Teleport(EntityWorldPos position, float yaw, float pitch) { var generator = AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator(); uint teleportId = AttachedObject.GetComponent <TeleportComponent>().StartNew(); return(generator.PositionAndLook(position.X, position.Y, position.Z, yaw, pitch, 0, teleportId)); }
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; } } }
public async Task <EntityWorldPos> GetSpawnPosition() { EntityWorldPos retval = new EntityWorldPos(-8, 256, -8); int height = await this.GetHeight(GrainFactory, new BlockWorldPos(-8, 0, -8)); return(new EntityWorldPos(-8, height, -8)); }
protected Task SendMovePacket(ClientPlayPacketGenerator generator) { uint eid = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty); EntityWorldPos pos = AttachedObject.GetValue(EntityWorldPositionComponent.EntityWorldPositionProperty); short x = (short)(pos.X * 32 * 128); short y = (short)(pos.Y * 32 * 128); short z = (short)(pos.Z * 32 * 128); bool onGround = AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty); return(generator.EntityRelativeMove(eid, x, y, z, onGround)); }
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(); } }
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); } }
private async Task ActionWalk() { float step = 0.2f; float theta = (float)(random.NextDouble() * 2 * Math.PI); float yaw = AttachedObject.GetValue(EntityLookComponent.YawProperty); float head; EntityWorldPos pos = AttachedObject.GetValue(EntityWorldPositionComponent.EntityWorldPositionProperty); if (random.Next(50) == 0) { head = theta; } else { head = (float)(yaw / 180.0f * Math.PI); } await AttachedObject.SetLocalValue(EntityLookComponent.YawProperty, (float)(head / Math.PI * 180.0f)); await AttachedObject.SetLocalValue(EntityLookComponent.HeadYawProperty, (float)(head / Math.PI * 180.0f)); // 新的位置 EntityWorldPos entityPos = new EntityWorldPos(pos.X - step * (float)Math.Sin(head), pos.Y, pos.Z + step * (float)Math.Cos(head)); BlockWorldPos blockPos = entityPos.ToBlockWorldPos(); // 检测行进方向的方块是否满足要求 Cuboid entityBoundbox = new Cuboid(new Point3d(entityPos.X, entityPos.Y, entityPos.Z), new Size(1, 1, 2)); // TODO data from Boundbox component var chunkAccessor = AttachedObject.GetComponent <ChunkAccessorComponent>(); bool isCollided = false; // 检测此位置会不会与方块碰撞 for (int i = 1; blockPos.Y + i < 256 && i <= 3; ++i) { BlockWorldPos upblock = BlockWorldPos.Add(blockPos, 0, i, 0); BlockState upstate = await chunkAccessor.GetBlockState(upblock); if (upstate.IsMobCollided()) { Cuboid blockBoundbox = new Cuboid(new Point3d(upblock.X, upblock.Y, upblock.Z), new Size(1, 1, 1)); if (Collision.IsCollided(entityBoundbox, blockBoundbox)) { isCollided = true; break; } } } // 获得高度变化 int yJumpHeight = 0; bool canWalk = false; for (int i = 0; blockPos.Y + i >= 0 && i >= -2; --i) { BlockState upstate = await chunkAccessor.GetBlockState(BlockWorldPos.Add(blockPos, 0, i + 1, 0)); BlockState state = await chunkAccessor.GetBlockState(BlockWorldPos.Add(blockPos, 0, i, 0)); if (!upstate.IsMobCollided() && state.IsMobCollided() && state.CanMobStand()) { yJumpHeight = i + 1; canWalk = true; break; } } if (!isCollided && canWalk) { await AttachedObject.SetLocalValue( EntityWorldPositionComponent.EntityWorldPositionProperty, EntityWorldPos.Add(entityPos, 0, yJumpHeight, 0)); } }
public static bool TryGetEntityWorldPosition(this DependencyObject d, out EntityWorldPos value) => d.TryGetLocalValue(EntityWorldPositionComponent.EntityWorldPositionProperty, out value);
public void SetPosition(EntityWorldPos entityWorldPos) => AttachedObject.SetLocalValue(EntityWorldPositionProperty, entityWorldPos);