private bool TryGetTriggerableNPC(out DefaultEcs.Entity npc) { npc = default; if (playerControls.IsLocked || !world.Has <components.ActiveNPC>()) { return(false); } npc = world.Get <components.ActiveNPC>().Entity; var npcDbRow = npc.Get <zzio.db.NpcRow>(); if (string.IsNullOrWhiteSpace(npcDbRow.TriggerScript)) { return(false); } var npcLocation = npc.Get <Location>(); var playerToNpc = (playerLocation.GlobalPosition - npcLocation.GlobalPosition) with { Y = 0.001f }; var cameraDir = cameraLocation.GlobalForward with { Y = 0.001f }; var dirDistance = Vector3.Distance(Vector3.Normalize(playerToNpc), Vector3.Normalize(cameraDir)); return(dirDistance < MaxNpcDirDistance); } } }
protected override void Update(float state, ReadOnlySpan <DefaultEntity> entities) { for (int i = 0; i < entities.Length; i++) { DefaultEntity entity = entities[i]; DefaultSpeed speed = entity.Get <DefaultSpeed>(); ref DefaultPosition position = ref entity.Get <DefaultPosition>(); position.X += speed.X * state; position.Y += speed.Y * state; }
public PlayerTriggers(ITagContainer diContainer) { world = diContainer.GetTag <DefaultEcs.World>(); playerControls = diContainer.GetTag <PlayerControls>(); zzContainer = diContainer.GetTag <IZanzarahContainer>(); zzContainer.OnMouseDown += HandleMouseDown; var game = diContainer.GetTag <Game>(); cameraLocation = diContainer.GetTag <rendering.Camera>().Location; playerLocationLazy = new Lazy <Location>(() => game.PlayerEntity.Get <Location>()); npcMarker = world.CreateEntity(); npcMarker.Set(new Location()); npcMarker.Set(new components.behaviour.Rotate(Vector3.UnitY, 90f)); npcMarker.Set(ManagedResource <ClumpBuffers> .Create( new resources.ClumpInfo(resources.ClumpType.Model, "marker.dff"))); ModelLoader.LoadMaterialsFor(npcMarker, zzio.scn.FOModelRenderType.Solid, zzio.IColor.Green, new zzio.SurfaceProperties(1f, 1f, 1f)); var materials = npcMarker.Get <List <materials.BaseModelInstancedMaterial> >(); foreach (var material in materials) { material.Uniforms.Ref.vertexColorFactor = 1f; } }
public void Update(float deltaTime) { // TODO: Add sound effect for looking at triggers if (TryGetTriggerableNPC(out var npc)) { // TODO: Fix marker distance for flying-type NPCs npcMarker.Set(components.Visibility.Visible); var npcMarkerLoc = npcMarker.Get <Location>(); npcMarkerLoc.LocalPosition = npc.Get <Location>().LocalPosition + Vector3.UnitY * (npc.Get <Sphere>().Radius * 0.5f + NpcMarkerDistance); return; } npcMarker.Remove <components.Visibility>(); // TODO: Add attack item triggers // TODO: Add look at sign triggers }