public override string ToChatString(GameWorldController gameWorldController) { string characterName = gameWorldController.Model.GetCharacterData(CharacterID).character_name; float distance = (Point3d.Distance(FromPosition, ToPosition)); MathConstants.eDirection direction = MathConstants.GetDirectionForAngle(ToAngle); string facing = ""; switch (direction) { case MathConstants.eDirection.none: facing = "South"; break; case MathConstants.eDirection.right: facing = "East"; break; case MathConstants.eDirection.up: facing = "North"; break; case MathConstants.eDirection.left: facing = "West"; break; case MathConstants.eDirection.down: facing = "South"; break; } return(base.ToChatString(gameWorldController) + characterName + " moved " + distance.ToString("F1") + " feet, now facing " + facing); }
public override string ToChatString(GameWorldController gameWorldController) { MobData mobData = gameWorldController.Model.GetMobData(MobID); MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name); float distance = Point3d.Distance(FromPosition, ToPosition); MathConstants.eDirection direction = MathConstants.GetDirectionForAngle(ToAngle); string facing = ""; switch (direction) { case MathConstants.eDirection.none: facing = "South"; break; case MathConstants.eDirection.right: facing = "East"; break; case MathConstants.eDirection.up: facing = "North"; break; case MathConstants.eDirection.left: facing = "West"; break; case MathConstants.eDirection.down: facing = "South"; break; } return(base.ToChatString(gameWorldController) + mobType.Name + " moved " + distance.ToString("F1") + " feet, now facing " + facing); }
public void UpdateAnimation(Vector2d facing, Vector2d throttle) { // Compute the speed from throttle vector float speed = throttle.Magnitude() * m_style.MaxSpeed; // Translate the sprite based on the current throttle if (throttle.IsNonZero) { float distance = speed * Time.deltaTime; float dX = throttle.i * distance; float dY = throttle.j * distance; SetLocalPosition(this.LocalX + dX, this.LocalY + dY); } // Update the animation controller parameters m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, speed); m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, facing.i); m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, facing.j); m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false); // Snap the cone facing angle to the cardinal directions m_visionCone.ConeFacing = MathConstants.GetAngleForDirection( MathConstants.GetDirectionForVector(new Vector2d(facing.i, facing.j))); }
private void PostCharacterMovedEvent( RequestCache requestCache) { // Add a game event if the player is moving to the portal if (m_move_to_target) { GameEventParameters gameEvent = new GameEvent_CharacterMoved() { character_id = m_character_id, room_x = m_current_room_key.x, room_y = m_current_room_key.y, room_z = m_current_room_key.z, from_x = m_current_character_position.x, from_y = m_current_character_position.y, from_z = m_current_character_position.z, from_angle = m_current_character_angle, to_x = m_energy_tank.Position.x, to_y = m_energy_tank.Position.y, to_z = m_energy_tank.Position.z, to_angle = MathConstants.GetAngleForDirection(MathConstants.eDirection.down) }; GameEventQueries.AddEvent(requestCache.DatabaseContext, m_game_id, gameEvent); m_ai_relevant_events.Add(gameEvent); } }
private bool UpdateCharacterState( RequestCache requestCache, out string result_code) { bool success; // Update the players position to the new position in the room Player player = requestCache.GetPlayer(m_room.room_key, m_character_id); if (player != null) { player.Position.Set(m_energy_tank.Position); player.Angle = MathConstants.GetAngleForDirection(MathConstants.eDirection.down); player.Energy = m_current_character_energy + m_energy_tank_old_energy; result_code = SuccessMessages.GENERAL_SUCCESS; success = true; } else { result_code = ErrorMessages.CACHE_ERROR + "(Failed to update character position and energy)"; success = false; } return(success); }
public override string ToChatString(GameWorldController gameWorldController) { string characterName = gameWorldController.Model.GetCharacterData(CharacterID).character_name; MathConstants.eDirection direction = MathConstants.GetDirectionForAngle(ToAngle); string facing = ""; switch (direction) { case MathConstants.eDirection.none: facing = "South"; break; case MathConstants.eDirection.right: facing = "East"; break; case MathConstants.eDirection.up: facing = "North"; break; case MathConstants.eDirection.left: facing = "West"; break; case MathConstants.eDirection.down: facing = "South"; break; } return(base.ToChatString(gameWorldController) + characterName + " moved " + facing + " to room at (" + ToRoomKey.x + ", " + ToRoomKey.y + ", " + ToRoomKey.z + ")"); }
public bool MoveMob( Point3d targetPosition) { bool success = false; if (path == null) { PathComputer pathComputer = new PathComputer(); success = pathComputer.BlockingPathRequest( moveRequest.Room.runtime_nav_mesh, moveRequest.Room.room_key, new Point3d(mob.Position), new Point3d(targetPosition)); if (success) { RoomKey roomKey = moveRequest.Room.room_key; PathStep lastPathStep = pathComputer.FinalPath[pathComputer.FinalPath.Count - 1]; PathStep secondLastPathStep = pathComputer.FinalPath[pathComputer.FinalPath.Count - 2]; Vector3d lastPathHeading = lastPathStep.StepPoint - secondLastPathStep.StepPoint; float targetAngle = MathConstants.GetAngleForVector(lastPathHeading); path = new EntityPath() { entity_id = mob.ID, path = pathComputer.FinalPath }; // Post an event that we moved output_game_events.Add( new GameEvent_MobMoved() { mob_id = mob.ID, room_x = roomKey.x, room_y = roomKey.y, room_z = roomKey.z, from_x = mob.Position.x, from_y = mob.Position.y, from_z = mob.Position.z, from_angle = mob.Angle, to_x = targetPosition.x, to_y = targetPosition.y, to_z = targetPosition.z, to_angle = targetAngle }); // Update the mob position and facing mob.Position = targetPosition; mob.Angle = targetAngle; // TODO: Update the mob energy based on the distance traveled } } return(success); }
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 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; }
/// <summary> /// Add a leaf node that is a MathConstant /// </summary> /// <param name="constant"> /// A <see cref="MathConstants"/> /// </param> public new void AddData(MathConstants constant) { if (constant == MathConstants.Pi) { this.data = Math.PI; } else if (constant == MathConstants.Exponential) { this.data = Math.E; } else if (constant == MathConstants.Notanumber) { this.data = double.NaN; } else if (constant == MathConstants.Infinity) { this.data = Double.PositiveInfinity; } // <todo>What do we do with True, False? }
public static bool IsPointInMobVisionCone( Mob mob, Point3d point) { MobType mobType = mob.MobType; Vector2d mobToPoint = (point - mob.Position).ToVector2d(); Vector2d facingVector = MathConstants.GetUnitVectorForAngle(mob.Angle); float cosHalfAngle = (float)Math.Cos(mob.MobType.VisionCone.GetHalfAngle()); float cosAngleToProp = facingVector.Dot(mobToPoint); float pointDistanceSquared = Point2d.DistanceSquared(point, mob.Position); float minVisionCircleDistanceSquared = WorldConstants.ROOM_TILE_SIZE * WorldConstants.ROOM_TILE_SIZE; float minVisionConeDistanceSquared = (float)(mobType.VisionCone.distance * mobType.VisionCone.distance); bool isInVisionCone = (pointDistanceSquared <= minVisionCircleDistanceSquared) || ((cosAngleToProp > cosHalfAngle) && (pointDistanceSquared <= minVisionConeDistanceSquared)); return(isInVisionCone); }
public void SnapTo(Point3d point, float angle) { Point2d pixelPosition = GameConstants.ConvertRoomPositionToPixelPosition(point); // Update the character data m_characterData.x = point.x; m_characterData.y = point.y; m_characterData.z = point.z; m_characterData.angle = angle; // Snap our position m_position.Set(point); m_facing = MathConstants.GetUnitVectorForAngle(angle); m_characterWidget.SetLocalPosition(pixelPosition.x, pixelPosition.y); // Snap out facing and go to idle m_characterWidget.UpdateAnimation(m_facing, Vector2d.ZERO_VECTOR); // Forget about any path we were running m_pathfindingComponent.ClearPath(); }
public void RequestMoveTo( Point3d point, float angle, PathComputer.OnPathComputedCallback onPathComputed) { // Set our new destination. // The position will update as we move along our path m_pathfindingComponent.SubmitPathRequest( point, MathConstants.GetUnitVectorForAngle(angle), (PathComputer pathResult) => { if (pathResult == null) { // No result means we stopped in out tracks m_characterData.x = Position.x; m_characterData.y = Position.y; m_characterData.z = Position.z; m_characterData.angle = angle; onPathComputed(PathComputer.eResult.success); } else { if (pathResult.ResultCode == PathComputer.eResult.success) { // Set the character data immediately to the destination m_characterData.x = point.x; m_characterData.y = point.y; m_characterData.z = point.z; m_characterData.angle = angle; } onPathComputed(pathResult.ResultCode); } }); }
public MobWidget(WidgetGroup parentGroup, MobWidgetStyle style, MobData mobData) : base( parentGroup, style.Width, style.Height, GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).x, GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).y) // Gross { MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name); m_style = style; m_title = new LabelWidget( this, style.LabelWidth, // width style.LabelHeight, // height (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x -m_style.BoundsHeight - style.LabelHeight, // local y mobType.Label); // text m_title.Alignment = TextAnchor.UpperCenter; m_energy = new LabelWidget( this, style.LabelWidth, // width style.LabelHeight, // height (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x 0, // local y ""); // text m_energy.Alignment = TextAnchor.UpperCenter; this.Energy = mobData.energy; // Create the sprite game object { string archetype = mobType.Name; string gameObjectPath = "Gfx/Sprites/Enemies/" + archetype + "/" + archetype + "_sprite"; m_spriteObject = GameObject.Instantiate( Resources.Load <GameObject>(gameObjectPath)) as GameObject; m_spriteAnimator = m_spriteObject.GetComponent <Animator>(); UpdateWorldPosition(); } // Create the dialog label m_dialog = new LabelWidget( this, style.DialogWidth, // width style.DialogHeight, // height (m_style.Width / 2.0f) - (m_style.DialogWidth / 2.0f), // local x m_title.LocalY - style.DialogHeight, // local y ""); // text m_dialog.FontSize = 14; m_dialog.Color = Color.red; m_dialog.Alignment = TextAnchor.UpperCenter; m_dialog.Visible = false; // Set the initial animation controller parameters m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, 0.0f); m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, 0.0f); m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, -1.0f); m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false); // Create the vision cone m_visionCone = new VisionConeWidget( this, mobType.Name + mobData.mob_id.ToString(), mobType.VisionConeDistance, mobType.VisionConeAngleDegrees, 0.0f, 0.0f, 0.0f); m_visionCone.ConeFacing = MathConstants.GetAngleForDirection(MathConstants.eDirection.down); }
private void UpdateMouseCursor(WidgetEvent widgetEvent) { if (widgetEvent.EventType == WidgetEvent.eEventType.mouseOver || widgetEvent.EventType == WidgetEvent.eEventType.mouseOut || widgetEvent.EventType == WidgetEvent.eEventType.mouseMove) { if (widgetEvent.EventSource is HotspotWidget) { HotspotWidget hotspotWidget = widgetEvent.EventSource as HotspotWidget; HotspotInfo hotspotInfo = hotspotWidget.Userdata as HotspotInfo; switch (hotspotInfo.hotspotType) { case eHotspotType.energy_tank: { EnergyTankData energyTankData = hotspotInfo.hotspotEntity as EnergyTankData; if (energyTankData.ownership != GameConstants.eFaction.player) { // If our faction doesn't control the energy tank, we'll have to hack it SetMouseCursorState(eMouseCursorState.hack_energy_tank); } else if (energyTankData.energy > 0) { // If our faction does control the energy tank, then we can drain it if it has energy SetMouseCursorState(eMouseCursorState.drain_energy_tank); } else { // Otherwise all we can do is walk to it SetMouseCursorState(eMouseCursorState.walk); } } break; case eHotspotType.portal: { Point2d hotspotCenter = hotspotWidget.WorldPosition.Offset(new Vector2d(hotspotWidget.Width / 2.0f, hotspotWidget.Height / 2.0f)); Point2d screenCenter = new Point2d(Screen.width / 2.0f, Screen.height / 2.0f); Vector2d vectorToHotspot = hotspotCenter - screenCenter; MathConstants.eDirection currentHotspotDirection = MathConstants.GetDirectionForVector(vectorToHotspot); switch (currentHotspotDirection) { case MathConstants.eDirection.left: SetMouseCursorState(eMouseCursorState.door_left); break; case MathConstants.eDirection.right: SetMouseCursorState(eMouseCursorState.door_right); break; case MathConstants.eDirection.up: SetMouseCursorState(eMouseCursorState.door_up); break; case MathConstants.eDirection.down: SetMouseCursorState(eMouseCursorState.door_down); break; default: SetMouseCursorState(eMouseCursorState.walk); break; } } break; default: { SetMouseCursorState(eMouseCursorState.defaultCursor); } break; } } else if (widgetEvent.EventSource is TileGridWidget) { if (m_currentNavRef.IsValid) { SetMouseCursorState(eMouseCursorState.walk); } else { SetMouseCursorState(eMouseCursorState.defaultCursor); } } else { SetMouseCursorState(eMouseCursorState.defaultCursor); } } }