public async Task Kick() { await AttachedObject.Tell(Disable.Default); if (_user.GetPlayer() == AttachedObject.AsReference <IPlayer>()) { await _user.Kick(); } }
private async Task <IBlockEntity> FindMasterEntity(IBlockEntity neighborEntity) { if (NeighborEntity == null) { return(AttachedObject.AsReference <IBlockEntity>()); } async Task <(IBlockEntity entity, BlockWorldPos position)> GetPosition(IBlockEntity entity) => (entity, await entity.GetPosition()); // 按 X, Z 排序取最小 return((from e in await Task.WhenAll(new[] { GetPosition(AttachedObject.AsReference <IBlockEntity>()), GetPosition(NeighborEntity) }) orderby e.position.X, e.position.Z select e.entity).First()); }
async Task IHandle <UseBy> .Handle(UseBy message) { var masterEntity = await FindMasterEntity(NeighborEntity); if (masterEntity.GetPrimaryKey() == AttachedObject.GetPrimaryKey()) { if (ChestWindow == null) { AttachedObject.SetLocalValue(ChestWindowProperty, GrainFactory.GetGrain <IChestWindow>(Guid.NewGuid())); await ChestWindow.SetEntities((NeighborEntity == null ? new[] { AttachedObject.AsReference <IDependencyObject>() } : new[] { AttachedObject.AsReference <IDependencyObject>(), NeighborEntity }).AsImmutable()); } await message.Entity.Tell(new OpenWindow { Window = ChestWindow }); } else { await masterEntity.Tell(message); } }