private void OnHeadYawChanged(object sender, PropertyChangedEventArgs <float> e) { uint eid = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty); byte headyaw = (byte)(AttachedObject.GetValue(EntityLookComponent.HeadYawProperty) / 360 * 255); AttachedObject.QueueOperation(() => AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator().EntityHeadLook(eid, headyaw)); }
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 virtual bool AcceptsItem(IQSBOWItem item) { var itemType = item.GetItemType(); var acceptableType = AttachedObject.GetValue <ItemType>("_acceptableType"); return((itemType & acceptableType) == itemType); }
private List <Shape> GetAttachedShapes() { if (AttachedObject == null) { return(new List <Shape>()); } var visibilityTrackers = AttachedObject.GetValue <VisibilityTracker[]>("_visibilityTrackers"); if (visibilityTrackers == null || visibilityTrackers.Length == 0) { DebugLog.ToConsole($"Warning - {AttachedObject.name} has null visibility trackers!", MessageType.Warning); return(new List <Shape>()); } if (visibilityTrackers.Any(x => x.GetType() == typeof(RendererVisibilityTracker))) { DebugLog.ToConsole($"Warning - {AttachedObject.name} has a RendererVisibilityTracker!", MessageType.Warning); return(new List <Shape>()); } var totalShapes = new List <Shape>(); foreach (var tracker in visibilityTrackers) { var shapes = tracker.GetValue <Shape[]>("_shapes"); totalShapes.AddRange(shapes); } return(totalShapes); }
protected override void OnAttached() { if (AttachedObject.GetValue(IsEnabledComponent.IsEnabledProperty)) { InstallPropertyChangedHandlers(); } }
private void OnEntityWorldPositionChanged(object sender, PropertyChangedEventArgs <EntityWorldPos> e) { var generator = AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator(); // Update Collider var pos = e.NewValue; var box = new Cuboid(new Point3d(pos.X, pos.Z, pos.Y), new Size(0.6f, 0.6f, 1.75f)); AttachedObject.SetLocalValue(ColliderComponent.ColliderShapeProperty, box); // Check if we need to send UpdateViewPosition packet. If the player walk cross chunk borders, send it. var oldChunkPos = e.OldValue.ToChunkWorldPos(); var newChunkPos = e.NewValue.ToChunkWorldPos(); if (oldChunkPos != newChunkPos) { generator.UpdateViewPosition(newChunkPos.X, newChunkPos.Z); } // Broadcast to trackers _broadcastComponent = _broadcastComponent ?? AttachedObject.GetComponent <ChunkEventBroadcastComponent>(); _broadcastComponent.GetGenerator(AttachedObject) .EntityRelativeMove( AttachedObject.EntityId, GetDelta(e.OldValue.X, e.NewValue.X), GetDelta(e.OldValue.Y, e.NewValue.Y), GetDelta(e.OldValue.Z, e.NewValue.Z), AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty)); }
private void InitValues() { _startLocalPos = AttachedObject.GetValue <Vector3>("_startLocalPos"); _endLocalPos = AttachedObject.GetValue <Vector3>("_endLocalPos"); _interactVolume = AttachedObject.GetValue <SingleInteractionVolume>("_interactVolume"); _owAudioSourceOneShot = AttachedObject.GetValue <OWAudioSource>("_owAudioSourceOneShot"); _owAudioSourceLP = AttachedObject.GetValue <OWAudioSource>("_owAudioSourceLP"); }
public IEnumerable <int> GetTranslatedIds() { var rings = AttachedObject.GetValue <NomaiVesselComputerRing[]>("_computerRings"); return(rings .Where(ring => AttachedObject.IsTranslated(ring.GetEntryID())) .Select(ring => ring.GetEntryID())); }
protected override Task SendSpawnPacket(ClientPlayPacketGenerator generator) { var metadata = new EntityMetadata.Player { Health = AttachedObject.GetValue(HealthComponent.HealthProperty) }; return(generator.SpawnPlayer(AttachedObject.EntityId, AttachedObject.UUID, AttachedObject.Position, AttachedObject.Pitch, AttachedObject.HeadYaw, metadata)); }
private void OnPositionChanged(object sender, PropertyChangedEventArgs <EntityWorldPos> e) { uint eid = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty); short x = (short)((e.NewValue.X - e.OldValue.X) * 32 * 128); short y = (short)((e.NewValue.Y - e.OldValue.Y) * 32 * 128); short z = (short)((e.NewValue.Z - e.OldValue.Z) * 32 * 128); bool isOnGround = AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty); AttachedObject.QueueOperation(() => AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator().EntityRelativeMove(eid, x, y, z, isOnGround)); }
public void ShuffleObjects(int[] indexArray) { var shuffledObjects = AttachedObject.GetValue <Transform[]>("_shuffledObjects"); var localPositions = AttachedObject.GetValue <Vector3[]>("_localPositions"); for (var i = 0; i < shuffledObjects.Length; i++) { shuffledObjects[i].localPosition = localPositions[indexArray[i]]; } }
private void OnPitchChanged(object sender, PropertyChangedEventArgs <float> e) { uint eid = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty); byte yaw = (byte)(AttachedObject.GetValue(EntityLookComponent.YawProperty) / 360 * 255); byte pitch = (byte)(AttachedObject.GetValue(EntityLookComponent.PitchProperty) / 360 * 255); bool onGround = AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty); // return AttachedObject.GetComponent<ChunkEventBroadcastComponent>().GetGenerator().EntityLook(eid, yaw, pitch, onGround); AttachedObject.QueueOperation(() => AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator().EntityLookAndRelativeMove(eid, 0, 0, 0, yaw, pitch, onGround)); }
private void CreateAi(MobType mobType) { Func <CreatureState> getter = () => AttachedObject.GetValue(CreatureStateProperty); Action <CreatureState> setter = v => AttachedObject.SetLocalValue(CreatureStateProperty, v); CreatureAi ai; switch (mobType) { case Entities.MobType.Chicken: ai = new AiChicken(getter, setter); break; case Entities.MobType.Cow: ai = new AiCow(getter, setter); break; case Entities.MobType.Creeper: ai = new AiCreeper(getter, setter); break; case Entities.MobType.Pig: ai = new AiPig(getter, setter); break; case Entities.MobType.Sheep: ai = new AiSheep(getter, setter); break; case Entities.MobType.Skeleton: ai = new AiSkeleton(getter, setter); break; case Entities.MobType.Spider: ai = new AiSpider(getter, setter); break; case Entities.MobType.Squid: // TODO new ai for squid ai = new AiChicken(getter, setter); break; case Entities.MobType.Zombie: ai = new AiZombie(getter, setter); break; default: // TODO add more ai Logger.LogWarning("AI of this mob has not been implemented: {0}.", mobType); ai = null; break; } _ai = ai; }
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 override void Init(MultiStateQuantumObject attachedObject, int id) { ObjectId = id; AttachedObject = attachedObject; QuantumStates = AttachedObject.GetValue <QuantumState[]>("_states").ToList().Select(x => QSBWorldSync.GetWorldFromUnity <QSBQuantumState, QuantumState>(x)).ToList(); if (QSBCore.DebugMode) { DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, CurrentState.ToString()).GetComponent <Text>(); } base.Init(attachedObject, id); }
private Task OnPositionChanged(object sender, PropertyChangedEventArgs <EntityWorldPos> e) { uint eid = AttachedObject.GetValue(EntityIdComponent.EntityIdProperty); short x = (short)((e.NewValue.X - e.OldValue.X) * 32 * 128); short y = (short)((e.NewValue.Y - e.OldValue.Y) * 32 * 128); short z = (short)((e.NewValue.Z - e.OldValue.Z) * 32 * 128); byte yaw = (byte)(AttachedObject.GetValue(EntityLookComponent.YawProperty) / 360 * 255); byte pitch = (byte)(AttachedObject.GetValue(EntityLookComponent.PitchProperty) / 360 * 255); bool isOnGround = AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty); return(AttachedObject.GetComponent <ChunkEventBroadcastComponent>().GetGenerator().EntityLookAndRelativeMove(eid, x, y, z, yaw, pitch, isOnGround)); }
private void OnEntityPitchChanged(object sender, PropertyChangedEventArgs <float> e) { var yaw = AttachedObject.GetValue(EntityLookComponent.YawProperty); var pitch = AttachedObject.GetValue(EntityLookComponent.PitchProperty); _broadcastComponent = _broadcastComponent ?? AttachedObject.GetComponent <ChunkEventBroadcastComponent>(); _broadcastComponent.GetGenerator(AttachedObject) .EntityLook( AttachedObject.EntityId, GetAngle(yaw), GetAngle(pitch), AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty)); }
private async Task OnColliderShapeChanged(PropertyChangedEventArgs <Shape> e) { var shape = ColliderShape; var key = AttachedObject.GetValue(AddressByPartitionKeyComponent.AddressByPartitionKeyProperty); if (shape != null) { await GrainFactory.GetGrain <ICollectableFinder>(key).RegisterCollider(AttachedObject, shape); } else { await GrainFactory.GetGrain <ICollectableFinder>(key).UnregisterCollider(AttachedObject); } }
public virtual void DropItem(Vector3 position, Vector3 normal, Sector sector) { AttachedObject.transform.SetParent(sector.transform); AttachedObject.transform.localScale = Vector3.one; var localDropNormal = AttachedObject.GetValue <Vector3>("_localDropNormal"); var lhs = Quaternion.FromToRotation(AttachedObject.transform.TransformDirection(localDropNormal), normal); AttachedObject.transform.rotation = lhs * AttachedObject.transform.rotation; var localDropOffset = AttachedObject.GetValue <Vector3>("_localDropOffset"); AttachedObject.transform.position = sector.transform.TransformPoint(position) + AttachedObject.transform.TransformDirection(localDropOffset); AttachedObject.SetSector(sector); AttachedObject.SetColliderActivation(true); HoldingPlayer = 0; }
private void OnEntityWorldPositionChanged(object sender, PropertyChangedEventArgs <EntityWorldPos> e) { var pos = e.NewValue; var box = new Cuboid(new Point3d(pos.X, pos.Z, pos.Y), new Size(0.6f, 0.6f, 1.75f)); AttachedObject.SetLocalValue(ColliderComponent.ColliderShapeProperty, box); _broadcastComponent = _broadcastComponent ?? AttachedObject.GetComponent <ChunkEventBroadcastComponent>(); _broadcastComponent.GetGenerator(AttachedObject) .EntityRelativeMove( AttachedObject.EntityId, GetDelta(e.OldValue.X, e.NewValue.X), GetDelta(e.OldValue.Y, e.NewValue.Y), GetDelta(e.OldValue.Z, e.NewValue.Z), AttachedObject.GetValue(EntityOnGroundComponent.IsOnGroundProperty)); }
async Task IHandle <SpawnMob> .Handle(SpawnMob message) { Func <CreatureState> getter = () => AttachedObject.GetValue(CreatureStateProperty); Action <CreatureState> setter = v => AttachedObject.SetLocalValue(CreatureStateProperty, v).Wait(); CreatureAi ai; switch (message.MobType) { case MobType.Chicken: ai = new AiChicken(getter, setter); break; case MobType.Cow: ai = new AiCow(getter, setter); break; case MobType.Creeper: ai = new AiCreeper(getter, setter); break; case MobType.Pig: ai = new AiPig(getter, setter); break; case MobType.Sheep: ai = new AiSheep(getter, setter); break; case MobType.Skeleton: ai = new AiSkeleton(getter, setter); break; case MobType.Squid: // TODO new ai for squid ai = new AiChicken(getter, setter); break; case MobType.Zombie: ai = new AiZombie(getter, setter); break; default: // TODO add more ai throw new NotImplementedException("AI of this mob has not been implemented."); } await AttachedObject.SetLocalValue(AiTypeProperty, ai); }
private async Task Respawn() { var generator = AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator(); var teleportComponent = AttachedObject.GetComponent <TeleportComponent>(); var world = AttachedObject.GetWorld(); var spawnPos = await world.GetSpawnPosition(); await teleportComponent.Teleport(spawnPos, 0, 0); await generator.Respawn(Dimension.Overworld, await world.GetSeed(), new GameMode { ModeClass = GameMode.Class.Survival, IsHardcore = false }, LevelTypes.Default); AttachedObject.SetLocalValue(HealthComponent.HealthProperty, AttachedObject.GetValue(HealthComponent.MaxHealthProperty)); AttachedObject.SetLocalValue(FoodComponent.FoodProperty, AttachedObject.GetValue(FoodComponent.MaxFoodProperty)); AttachedObject.SetLocalValue(DeathComponent.IsDeathProperty, false); }
private Task ActionStop() { float theta = (float)(random.NextDouble() * 360); float yaw = AttachedObject.GetValue(EntityLookComponent.YawProperty); if (random.Next(20) == 0) { AttachedObject.SetLocalValue(EntityLookComponent.YawProperty, theta); AttachedObject.SetLocalValue(EntityLookComponent.HeadYawProperty, theta); } else { // AttachedObject.SetLocalValue(EntityLookComponent.YawProperty, yaw); AttachedObject.SetLocalValue(EntityLookComponent.HeadYawProperty, yaw); } return(Task.CompletedTask); }
public IEnumerable <int> GetTranslatedIds() { var activeList = AttachedObject.GetValue <List <NomaiComputerRing> >("_activeRingList"); foreach (var item in activeList) { if (AttachedObject.IsTranslated(item.GetEntryID())) { yield return(item.GetEntryID()); } } var inactiveList = AttachedObject.GetValue <List <NomaiComputerRing> >("_inactiveRingList"); foreach (var item in inactiveList) { if (AttachedObject.IsTranslated(item.GetEntryID())) { yield return(item.GetEntryID()); } } }
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 Task ActionEscape() { float yaw = AttachedObject.GetValue(EntityLookComponent.YawProperty); return(Task.CompletedTask); }
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 override void Init(Elevator elevator, int id) { AttachedObject = elevator; ObjectId = id; QSBCore.UnityEvents.RunWhen(() => AttachedObject.GetValue <SingleInteractionVolume>("_interactVolume") != null, InitValues); }
async Task IHandle <Disable> .Handle(Disable message) { var key = AttachedObject.GetValue(AddressByPartitionKeyComponent.AddressByPartitionKeyProperty); await GrainFactory.GetGrain <ICollectableFinder>(key).UnregisterCollider(AttachedObject); }
public IEnumerable <int> GetTranslatedIds() { var dict = AttachedObject.GetValue <Dictionary <int, OWTreeNode <NomaiTextLine> > >("_idToNodeDict"); return(dict.Keys.Where(key => AttachedObject.IsTranslated(key))); }