public GameEvent_MobAIPropSpotted() : base() { EventType = GameEvent.eEventType.mob_ai_prop_spotted; SpottedMobID = -1; Position = new Point3d(); }
public override void Perform(MobUpdateContext context) { NavMesh navMesh= context.moveRequest.Room.runtime_nav_mesh; float max_range= 5.0f; // Compute max range from mob type uint[] navCells = navMesh.ComputeNavCellsInRadius(context.mob.Position, max_range, false); Random rng = context.mob.AIState.behavior_data.GetMobRandomNumberGenerator(); RNGUtilities.DeterministicKnuthShuffle(rng, navCells); Point3d targetPosition = new Point3d(context.mob.Position); // Pick the first random nav cell in range that we have line of sight to foreach (uint navCellIndex in navCells) { Point3d testTarget = navMesh.ComputeNavCellCenter(navCellIndex); bool canSee = navMesh.PointCanSeeOtherPoint(context.mob.Position, testTarget); if (canSee) { targetPosition = testTarget; break; } } // Compute the side effect of actually moving the mob on the update context context.MoveMob(targetPosition); context.MobPostDialog("Soo bored..."); }
public static float DistanceSquared(Point3d a, Point3d b) { float xDelta = b.x - a.x; float yDelta = b.y - a.y; return (xDelta * xDelta) + (yDelta * yDelta); }
public Point3d ClipPoint(Point3d p) { return new Point3d( Math.Min(Math.Max(p.x, m_pMin.x), m_pMax.x), Math.Min(Math.Max(p.y, m_pMin.y), m_pMax.y), Math.Min(Math.Max(p.z, m_pMin.z), m_pMax.z)); }
public GameEvent_MobPlayerPropSpotted() : base() { EventType = GameEvent.eEventType.mob_player_prop_spotted; CharacterID = -1; Position = new Point3d(); }
public PortalRequestProcessor( int character_id, Point3d portal_position, float portal_angle, int portal_id) { m_character_id = character_id; m_portal_position = new Point3d(portal_position); m_portal_angle = portal_angle; m_portal_id = portal_id; m_world = null; m_room = null; m_opposing_room = null; m_portal = null; m_opposing_portal = null; m_opposing_portal_position = new Point3d(); m_current_room_key = null; m_opposing_room_key = null; m_current_character_position = new Point3d(); m_current_character_angle = 0.0f; m_game_id = -1; m_move_to_target = false; m_result_event_list = null; }
public GameEvent_MobPlayerPropLostTrack() : base() { EventType = GameEvent.eEventType.mob_player_prop_lost_track; CharacterID = -1; Position = new Point3d(); }
public EnergyTank() { m_room_key = new RoomKey(); m_energy_tank_id = -1; m_position = new Point3d(); m_energy = 0; m_faction = GameConstants.eFaction.neutral; }
public MobSpawner() { m_room_key = new RoomKey(); m_mob_spawner_id = -1; m_position = new Point3d(); m_spawn_table = null; m_remaining_spawn_count = 0; m_random_seed = 0; }
public EnergyTankEntity(int energyTankId) { SessionData sessionData = SessionData.GetInstance(); _energyTankId = energyTankId; _energyTankData = sessionData.CurrentGameData.CurrentRoom.GetEnergyTankById(_energyTankId); _position = new Point3d(_energyTankData.position); _energyTankWidget = null; }
public EnergyTankData() { energy_tank_id = -1; energy = 0; ownership = GameConstants.eFaction.neutral; position = new Point3d(); boundingBox = new AABB3d(); room_key = new RoomKey(); }
public PathfindingComponent(IEntity entity) { m_entity = entity; m_destinationPoint = new Point3d(entity.Position); m_destinationFacing = new Vector2d(entity.Facing); m_pathCompleteCallback = null; ClearPath(); }
private Dictionary<int, MobData> m_mobs; // mob_id -> Mob Data #endregion Fields #region Constructors public RoomData() { RoomKey = new RoomKey(); WorldPosition = new Point3d(); RoomPortals = new List<RoomPortal>(); StaticRoomData = new StaticRoomData(); m_mobs = new Dictionary<int, MobData>(); m_energyTanks = new Dictionary<int, EnergyTankData>(); }
public Mob() { m_room_key = new RoomKey(); m_mob_id= -1; m_position = new Point3d(); m_angle = 0f; m_mob_type = null; m_health= 0; m_energy= 0; m_ai_data = null; }
public GameEvent_CharacterMoved() : base() { EventType = GameEvent.eEventType.character_moved; CharacterID = -1; CurrentRoomKey = new RoomKey(); FromPosition = new Point3d(); FromAngle = 0; ToPosition = new Point3d(); ToAngle = 0; }
public CharacterEntity(int characterId) { SessionData sessionData = SessionData.GetInstance(); m_characterId = characterId; m_characterData = sessionData.CurrentGameData.GetCharacterById(m_characterId); m_position = new Point3d(m_characterData.x, m_characterData.y, m_characterData.z); m_facing = MathConstants.GetUnitVectorForAngle(m_characterData.angle); m_characterWidget = null; m_pathfindingComponent = null; m_steeringComponent = null; }
public GameEvent_MobMoved() : base() { EventType = GameEvent.eEventType.mob_moved; MobID = -1; CurrentRoomKey = new RoomKey(); FromPosition = new Point3d(); FromAngle = 0; ToPosition = new Point3d(); ToAngle = 0; }
public Player() { m_character_id = -1; m_character_name = ""; m_archetype = GameConstants.eArchetype.warrior; m_gender = GameConstants.eGender.Female; m_picture_id = -1; m_power_level = 0; m_energy = 0; m_health = 0; m_room_key = new RoomKey(); m_position = new Point3d(); m_energy = 0; }
public GameEvent_CharacterPortaled() : base() { EventType = GameEvent.eEventType.character_portaled; CharacterID = -1; FromRoomKey = new RoomKey(); ToRoomKey = new RoomKey(); FromPosition = new Point3d(); FromAngle = 0; ToPosition = new Point3d(); ToAngle = 0; }
public MobEntity(int characterId) { SessionData sessionData = SessionData.GetInstance(); m_mobId = characterId; m_mobData = sessionData.CurrentGameData.CurrentRoom.GetMobById(m_mobId); m_position = new Point3d(m_mobData.x, m_mobData.y, m_mobData.z); m_facing = MathConstants.GetUnitVectorForAngle(m_mobData.angle); m_dialogTimer = -1.0f; m_mobWidget = null; m_pathfindingComponent = null; m_steeringComponent = null; }
public AsyncCharacterMoveRequest(GameObject requestOwnerObject, CharacterEntity entity, Point3d target) { // Remember where we came from in case the server rejects our predictive movement request CharacterData characterData = entity.MyCharacterData; OriginalPosition = new Point3d(characterData.x, characterData.y, characterData.z); OriginalFacingAngle = characterData.angle; TargetPosition = new Point3d(target); TagetFacingAngle = OriginalFacingAngle; m_entity = entity; m_requestOwnerObject = requestOwnerObject; Status = eRequestStatus.preflight; ResultCode = eResult.none; ResultDetails = ""; ServerResponse = null; }
public HackEnergyTankRequestProcessor( int character_id, int energy_tank_id) { m_character_id = character_id; m_energy_tank_id = energy_tank_id; m_world = null; m_room = null; m_energy_tank = null; m_current_room_key = null; m_current_character_position = new Point3d(); m_current_character_angle = 0.0f; m_game_id = -1; m_move_to_target = false; m_ai_relevant_events = new List<GameEventParameters>(); m_result_event_list = null; }
public MoveRequestProcessor( int character_id, Point3d target_position, float target_angle) { m_character_id = character_id; m_target_position = new Point3d(target_position); m_target_angle = target_angle; m_world = null; m_room = null; m_current_room_key = null; m_current_character_position = new Point3d(); m_current_character_angle = 0.0f; m_game_id = -1; m_ai_relevant_events = new List<GameEventParameters>(); m_result_event_list = null; }
public AsyncDrainEnergyTankRequest( GameObject requestOwnerObject, CharacterEntity entity, Point3d entryPoint, EnergyTankData energyTank) { // Remember where we came from in case the server rejects our predictive movement request CharacterData characterData = entity.MyCharacterData; OriginalPosition = new Point3d(characterData.x, characterData.y, characterData.z); TargetEnergyTank = energyTank; EnergyTankApproachPoint = entryPoint; m_entity = entity; m_requestOwnerObject = requestOwnerObject; Status = eRequestStatus.preflight; ResultCode = eResult.none; ResultDetails = ""; ServerResponse = null; }
public static bool AddPathRequest( RoomKey roomKey, Point3d startPoint, Point3d endPoint, PathComputer.OnPathComputerComplete onComplete) { bool success = false; if (m_instance != null) { PathComputer pathComputer = new PathComputer(); AsyncRPGSharedLib.Navigation.NavMesh navMesh = GetNavMesh(roomKey); if (pathComputer.NonBlockingPathRequest(navMesh, roomKey, startPoint, endPoint, onComplete)) { m_instance.m_requestQueue.Add(pathComputer); success = true; } } return success; }
public AsyncCharacterPortalRequest( GameObject requestOwnerObject, CharacterEntity entity, Point3d entryPoint, RoomPortal portal) { // Remember where we came from in case the server rejects our predictive movement request CharacterData characterData = entity.MyCharacterData; OriginalPosition = new Point3d(characterData.x, characterData.y, characterData.z); OriginalFacingAngle = characterData.angle; OriginalRoomKey = characterData.CurrentRoomKey; OriginPortal = portal; OriginPortalEntryPoint = entryPoint; m_entity = entity; m_requestOwnerObject = requestOwnerObject; Status = eRequestStatus.preflight; ResultCode = eResult.none; ResultDetails = ""; ServerResponse = null; }
public void RequestHackEnergyTank(Point3d entryPoint, EnergyTankData energyTankData) { Debug.Log("GameWorldModel:requestHackEnergyTank - Hacking energy tank id=" +energyTankData.energy_tank_id+" at position ("+ entryPoint.x + ", " + entryPoint.y + ")"); if (!IsHackEnergyTankRequestPending) { GameData gameData = SessionData.GetInstance().CurrentGameData; CharacterEntity entity = GetCharacterEntity(CurrentCharacterID); AsyncHackEnergyTankRequest hackEnergyTankRequest = null; IsHackEnergyTankRequestPending = true; hackEnergyTankRequest = new AsyncHackEnergyTankRequest(m_gameWorldController.gameObject, entity, entryPoint, energyTankData); hackEnergyTankRequest.Execute( (AsyncHackEnergyTankRequest asyncRequest) => { IsHackEnergyTankRequestPending = false; switch (asyncRequest.ResultCode) { case AsyncHackEnergyTankRequest.eResult.success: { Debug.Log("GameWorldModel:requestHackEnergyTank - Hack Succeeded!"); // Tell anyone listening on IRC that the game state changed m_gameWorldController.SendCharacterUpdatedGameEvent(); // Parse any incoming game events if (asyncRequest.ServerResponse != null) { gameData.ParseEventResponse(asyncRequest.ServerResponse); } // If there were new events, notify the controller so that // it can start playing the events back if (!gameData.IsEventCursorAtLastEvent) { m_gameWorldController.OnGameHasNewEvents(); } } break; case AsyncHackEnergyTankRequest.eResult.failed_path: case AsyncHackEnergyTankRequest.eResult.failed_server_denied: { Debug.LogError("GameWorldModel:requestHackEnergyTank - " + asyncRequest.ResultDetails); m_gameWorldController.OnCharacterActionDisallowed(asyncRequest); } break; case AsyncHackEnergyTankRequest.eResult.failed_server_connection: { Debug.LogError("GameWorldModel:requestHackEnergyTank - " + asyncRequest.ResultDetails); m_gameWorldController.OnRequestFailed("Connection Failed!"); } break; } }); } }
// Utilities public bool IsWorldPointOnNavMesh(Point3d testPoint) { GameData gameData = CurrentGame; RoomData roomData = gameData.GetCachedRoomData(gameData.CurrentRoomKey); bool pointOnNavMesh = false; if (roomData != null) { AsyncRPGSharedLib.Navigation.NavMesh navMesh = roomData.StaticRoomData.NavMesh; NavRef navRef = navMesh.ComputeNavRefAtPoint(testPoint); if (navRef != null && navRef.IsValid) { pointOnNavMesh= true; } } return pointOnNavMesh; }
protected override void ParseParameters(JsonData parameters) { int game_id = SessionData.GetInstance().GameID; base.ParseParameters(parameters); this.CharacterID = JsonUtilities.ParseInt(parameters, "character_id"); this.CurrentRoomKey = new RoomKey( game_id, JsonUtilities.ParseInt(parameters, "room_x"), JsonUtilities.ParseInt(parameters, "room_y"), JsonUtilities.ParseInt(parameters, "room_z")); this.FromPosition = new Point3d( JsonUtilities.ParseFloat(parameters, "from_x"), JsonUtilities.ParseFloat(parameters, "from_y"), JsonUtilities.ParseFloat(parameters, "from_z")); this.FromAngle = JsonUtilities.ParseFloat(parameters, "from_angle"); this.ToPosition = new Point3d( JsonUtilities.ParseFloat(parameters, "to_x"), JsonUtilities.ParseFloat(parameters, "to_y"), JsonUtilities.ParseFloat(parameters, "to_z")); this.ToAngle = JsonUtilities.ParseFloat(parameters, "to_angle"); }
private bool LookupOpposingPortal( RequestCache requestCache, out string result_code) { bool success; // If the opposing portal doesn't exist yet, // create a new room adjacent to the current room with an opposing portal if (m_portal.target_portal_id != -1) { //If an opposing portal exists, retrieve it from the DB m_opposing_portal= WorldQueries.GetPortal( requestCache.DatabaseContext, m_portal.target_portal_id); m_opposing_room_key = new RoomKey( m_game_id, m_opposing_portal.room_x, m_opposing_portal.room_y, m_opposing_portal.room_z); // Compute our target position in the new room // Clamp the players position into the bounding box of the portal in the new room m_opposing_portal_position = m_opposing_portal.bounding_box.ClipPoint(m_portal_position); result_code = SuccessMessages.GENERAL_SUCCESS; success = true; } else { result_code = ErrorMessages.CACHE_ERROR; success = false; } return success; }