private static bool ResolveAutopilotBeginTravel(AutopilotBeginAction action, EncounterState state) { var playerPosition = state.Player.GetComponent <PositionComponent>().EncounterPosition; EncounterZone zone = state.GetZoneById(action.ZoneId); var foundPath = Pathfinder.AStarWithNewGrid(playerPosition, zone.Center, state, 9000); int autopilotTries = 0; while (foundPath == null && autopilotTries < 5) { foundPath = Pathfinder.AStarWithNewGrid(playerPosition, zone.RandomEmptyPosition(state.EncounterRand, state), state, 9000); autopilotTries++; } if (foundPath != null && autopilotTries > 0) { state.LogMessage(String.Format("Autopilot could not find path to center of [b]{0}[/b]; autopiloting to randomly chosen position in [b]{0}[/b].", zone.ZoneName)); state.Player.GetComponent <PlayerComponent>().LayInAutopilotPathForTravel(new EncounterPath(foundPath)); return(true); } else if (foundPath != null) { state.LogMessage(String.Format("Autopiloting to [b]{0}[/b]", zone.ZoneName)); state.Player.GetComponent <PlayerComponent>().LayInAutopilotPathForTravel(new EncounterPath(foundPath)); return(true); } else { state.LogMessage(String.Format("Autopilot failed to plot course to to [b]{0}[/b]", zone.ZoneName), failed: true); return(false); } }
/** * A zone is considered "explored" when: * 1: All storables have been found * 1a: If your inventory is not full, all storable items have been picked up * 2: All non-storable features have been seen * * Actual % of FoW revealed is not important. This is kinda cheaty, because it implies the autopilot knows intel for the * area, but also, who cares? It's fine. Likewise it doesn't factor into account having destroyed the enemies because if * there is an encounter, you'll definitely run into it! */ private static bool ResolveAutopilotContinueExplore(EncounterState state) { var player = state.Player; var playerComponent = player.GetComponent <PlayerComponent>(); var playerPos = player.GetComponent <PositionComponent>().EncounterPosition; var path = playerComponent.AutopilotPath; var zone = state.GetZoneById(playerComponent.AutopilotZoneId); var nextUngottenStorable = zone.ReadoutItems.Concat(zone.ReadoutFeatures) .FirstOrDefault(i => state.GetEntityById(i.EntityId) != null && state.GetEntityById(i.EntityId).GetComponent <StorableComponent>() != null); // We rely on the fact that there's no ungettable features other than stairs, and that there's only one stair, to make this // work. If there were multiple ungettable features you'd want to put them into a list and autopilot between them so you // could cycle the 'x' button to find the one you want. var stairs = zone.ReadoutFeatures.FirstOrDefault(r => state.GetEntityById(r.EntityId).GetComponent <StairsComponent>() != null && state.GetEntityById(r.EntityId).GetComponent <PositionComponent>().EncounterPosition != playerPos ); if (PlayerSeesEnemies(state)) { ResolveAction(new AutopilotEndAction(player.EntityId, AutopilotEndReason.ENEMY_DETECTED), state); return(false); } // If you are already on a path, progress on the path else if (path != null) { if (path.AtEnd) { playerComponent.ClearAutopilotPath(); return(false); } else { Rulebook.ResolveAction(new MoveAction(player.EntityId, path.Step()), state); return(true); } } // If you're on top of a storable item, get it else if (state.EntitiesAtPosition(playerPos.X, playerPos.Y).Any(e => e.GetComponent <StorableComponent>() != null)) { var nextStorable = state.EntitiesAtPosition(playerPos.X, playerPos.Y).First(e => e.GetComponent <StorableComponent>() != null); if (ResolveAction(new GetItemAction(player.EntityId), state)) { return(true); } else { ResolveAction(new AutopilotEndAction(player.EntityId, AutopilotEndReason.INVENTORY_FULL), state); return(false); } } // If there are any storable items, move towards them else if (nextUngottenStorable != null) { var nextPos = state.GetEntityById(nextUngottenStorable.EntityId).GetComponent <PositionComponent>().EncounterPosition; var foundPath = Pathfinder.AStarWithNewGrid(playerPos, nextPos, state, 900); if (foundPath == null) { ResolveAction(new AutopilotEndAction(player.EntityId, AutopilotEndReason.NO_PATH), state); return(false); } else { foundPath.Add(nextPos); playerComponent.LayInAutopilotPathForExploration(new EncounterPath(foundPath)); return(true); } } // If this is the stairs zone, go to the stairs else if (stairs != null) { var nextPos = state.GetEntityById(stairs.EntityId).GetComponent <PositionComponent>().EncounterPosition; var foundPath = Pathfinder.AStarWithNewGrid(playerPos, nextPos, state, 900); if (foundPath == null) { ResolveAction(new AutopilotEndAction(player.EntityId, AutopilotEndReason.NO_PATH), state); return(false); } else { foundPath.Add(nextPos); playerComponent.LayInAutopilotPathForExploration(new EncounterPath(foundPath)); return(true); } } // Otherwise you're done! else { ResolveAction(new AutopilotEndAction(player.EntityId, AutopilotEndReason.TASK_COMPLETED), state); return(false); } }