private void OnHotspotClicked( HotspotWidget hotspotWidget, WidgetEvent widgetEvent) { if (m_currentNavRef.IsValid) { WidgetEvent.MouseClickEventParameters eventParameters = widgetEvent.EventParameters as WidgetEvent.MouseClickEventParameters; Point2d clickPoint = new Point2d(eventParameters.worldX, eventParameters.worldY); HotspotInfo hotspotInfo = hotspotWidget.Userdata as HotspotInfo; switch (hotspotInfo.hotspotType) { case eHotspotType.energy_tank: { EnergyTankData energyTankData = hotspotInfo.hotspotEntity as EnergyTankData; m_contextOverlayController.OnEnergyTankClicked(clickPoint, energyTankData); } break; case eHotspotType.portal: { RoomPortal portal = hotspotInfo.hotspotEntity as RoomPortal; m_contextOverlayController.OnPortalClicked(clickPoint, portal); } break; } } }
// Gross public EnergyTankWidget(WidgetGroup parentGroup, EnergyTankWidgetStyle style, EnergyTankData energyTankData) : base(parentGroup, style.Width, style.Height, GameConstants.ConvertRoomPositionToPixelPosition(energyTankData.position).x, GameConstants.ConvertRoomPositionToPixelPosition(energyTankData.position).y) { m_style= style; m_title = new LabelWidget( this, m_style.LabelWidth, m_style.LabelHeight, (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x m_style.Height, // local y "0"); // text m_title.Alignment = TextAnchor.UpperCenter; // Create the sprite game object m_spriteObject = GameObject.Instantiate( Resources.Load<GameObject>("Gfx/Sprites/Items/EnergyTank/EnergyTank_sprite")) as GameObject; m_spriteAnimator = m_spriteObject.GetComponent<Animator>(); UpdateWorldPosition(); // Set the initial animation controller parameters UpdateState(energyTankData); }
public EnergyTankWidget(WidgetGroup parentGroup, EnergyTankWidgetStyle style, EnergyTankData energyTankData) : base( parentGroup, style.Width, style.Height, GameConstants.ConvertRoomPositionToPixelPosition(energyTankData.position).x, GameConstants.ConvertRoomPositionToPixelPosition(energyTankData.position).y) // Gross { m_style = style; m_title = new LabelWidget( this, m_style.LabelWidth, m_style.LabelHeight, (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x m_style.Height, // local y "0"); // text m_title.Alignment = TextAnchor.UpperCenter; // Create the sprite game object m_spriteObject = GameObject.Instantiate( Resources.Load <GameObject>("Gfx/Sprites/Items/EnergyTank/EnergyTank_sprite")) as GameObject; m_spriteAnimator = m_spriteObject.GetComponent <Animator>(); UpdateWorldPosition(); // Set the initial animation controller parameters UpdateState(energyTankData); }
// Parsing public static RoomData FromObject(JsonData jsonData) { RoomData roomData = new RoomData(); int gameID = SessionData.GetInstance().GameID; int room_x = (int)jsonData["room_x"]; int room_y = (int)jsonData["room_y"]; int room_z = (int)jsonData["room_z"]; float world_x = jsonData["world_x"].IsInt ? (float)((int)jsonData["world_x"]) : (float)((double)jsonData["world_x"]); float world_y = jsonData["world_y"].IsInt ? (float)((int)jsonData["world_y"]) : (float)((double)jsonData["world_y"]); float world_z = jsonData["world_z"].IsInt ? (float)((int)jsonData["world_z"]) : (float)((double)jsonData["world_z"]); roomData.RoomKey.Set(gameID, room_x, room_y, room_z); roomData.WorldPosition.Set(world_x, world_y, world_z); roomData.StaticRoomData = StaticRoomData.FromObject(roomData.RoomKey, jsonData["data"]); { JsonData portalList = jsonData["portals"]; for (int portalIndex = 0; portalIndex < portalList.Count; portalIndex++) { JsonData portalObject = portalList[portalIndex]; RoomPortal portal = RoomPortal.FromObject(portalObject); roomData.RoomPortals.Add(portal); } } { JsonData mobObjects = jsonData["mobs"]; roomData.m_mobs = new Dictionary <int, MobData>(); for (int mobIndex = 0; mobIndex < mobObjects.Count; mobIndex++) { JsonData mobObject = mobObjects[mobIndex]; MobData mobData = MobData.FromObject(mobObject); roomData.SetMobById(mobData.mob_id, mobData); } } { JsonData energyTankObjects = jsonData["energyTanks"]; roomData.m_energyTanks = new Dictionary <int, EnergyTankData>(); for (int energyTankIndex = 0; energyTankIndex < energyTankObjects.Count; energyTankIndex++) { JsonData energyTankObject = energyTankObjects[energyTankIndex]; EnergyTankData energyTankData = EnergyTankData.FromObject(energyTankObject); roomData.SetEnergyTankById(energyTankData.energy_tank_id, energyTankData); } } return(roomData); }
public EnergyTankEntity(int energyTankId) { SessionData sessionData = SessionData.GetInstance(); _energyTankId = energyTankId; _energyTankData = sessionData.CurrentGameData.CurrentRoom.GetEnergyTankById(_energyTankId); _position = new Point3d(_energyTankData.position); _energyTankWidget = 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 AsyncHackEnergyTankRequest( 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 void OnEnergyTankClicked(Point3d entryPoint, EnergyTankData energyTankData) { if (!m_gameWorldModel.IsAsyncRequestPending && m_gameWorldModel.IsEventCursorAtLastEvent && !m_gameWorldModel.IsEventPlaybackActive && m_gameWorldModel.IsWorldPointOnNavMesh(entryPoint)) { if (energyTankData.ownership != GameConstants.eFaction.player) { // If we don't control the tank, hack it! m_gameWorldModel.RequestHackEnergyTank(entryPoint, energyTankData); } else if (energyTankData.energy > 0) { // If it's got energy, drain it! m_gameWorldModel.RequestDrainEnergyTank(entryPoint, energyTankData); } else { // Just move to it m_gameWorldModel.RequestCharacterMove(entryPoint); } } }
public static EnergyTankData FromObject(JsonData jsonData) { EnergyTankData energyTank = new EnergyTankData(); // Upper left hand corner of the energy tank float x = jsonData["x"].IsInt ? (float)((int)jsonData["x"]) : (float)((double)jsonData["x"]); float y = jsonData["y"].IsInt ? (float)((int)jsonData["y"]) : (float)((double)jsonData["y"]); int game_id = SessionData.GetInstance().GameID; int room_x = (int)jsonData["room_x"]; int room_y = (int)jsonData["room_y"]; int room_z = (int)jsonData["room_z"]; energyTank.room_key = new RoomKey(game_id, room_x, room_y, room_z); energyTank.energy_tank_id = (int)jsonData["energy_tank_id"]; energyTank.energy = (uint)((int)jsonData["energy"]); energyTank.ownership = (GameConstants.eFaction)((int)jsonData["ownership"]); energyTank.position.Set(x, y, 0.0f); energyTank.boundingBox.SetBounds2d( x, y - ENERGY_TANK_WORLD_UNIT_SIZE, x + ENERGY_TANK_WORLD_UNIT_SIZE, y); return(energyTank); }
public static EnergyTankData FromObject(JsonData jsonData) { EnergyTankData energyTank = new EnergyTankData(); // Upper left hand corner of the energy tank float x = jsonData["x"].IsInt ? (float)((int)jsonData["x"]) : (float)((double)jsonData["x"]); float y = jsonData["y"].IsInt ? (float)((int)jsonData["y"]) : (float)((double)jsonData["y"]); int game_id = SessionData.GetInstance().GameID; int room_x = (int)jsonData["room_x"]; int room_y = (int)jsonData["room_y"]; int room_z = (int)jsonData["room_z"]; energyTank.room_key = new RoomKey(game_id, room_x, room_y, room_z); energyTank.energy_tank_id = (int)jsonData["energy_tank_id"]; energyTank.energy = (uint)((int)jsonData["energy"]); energyTank.ownership = (GameConstants.eFaction)((int)jsonData["ownership"]); energyTank.position.Set(x, y, 0.0f); energyTank.boundingBox.SetBounds2d( x, y - ENERGY_TANK_WORLD_UNIT_SIZE, x + ENERGY_TANK_WORLD_UNIT_SIZE, y); return energyTank; }
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; } }); } }
public void RequestDrainEnergyTank(Point3d entryPoint, EnergyTankData energyTankData) { Debug.Log("GameWorldModel:requestDrainEnergyTank - Draining energy tank id=" + energyTankData.energy_tank_id + " at position (" + entryPoint.x + ", " + entryPoint.y + ")"); if (!IsDrainEnergyTankRequestPending) { GameData gameData = SessionData.GetInstance().CurrentGameData; CharacterEntity entity = GetCharacterEntity(CurrentCharacterID); AsyncDrainEnergyTankRequest drainEnergyTankRequest = null; IsDrainEnergyTankRequestPending = true; drainEnergyTankRequest = new AsyncDrainEnergyTankRequest(m_gameWorldController.gameObject, entity, entryPoint, energyTankData); drainEnergyTankRequest.Execute( (AsyncDrainEnergyTankRequest asyncRequest) => { IsDrainEnergyTankRequestPending = false; switch (asyncRequest.ResultCode) { case AsyncDrainEnergyTankRequest.eResult.success: { Debug.Log("GameWorldModel:requestDrainEnergyTank - Drain 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 AsyncDrainEnergyTankRequest.eResult.failed_path: case AsyncDrainEnergyTankRequest.eResult.failed_server_denied: { Debug.LogError("GameWorldModel:requestDrainEnergyTank - " + asyncRequest.ResultDetails); m_gameWorldController.OnCharacterActionDisallowed(asyncRequest); } break; case AsyncDrainEnergyTankRequest.eResult.failed_server_connection: { Debug.LogError("GameWorldModel:requestDrainEnergyTank - " + asyncRequest.ResultDetails); m_gameWorldController.OnRequestFailed("Connection Failed!"); } break; } }); } }
public void OnEnergyTankClicked(Point2d entryPixelPoint, EnergyTankData energyTankData) { Point3d entryWorldPoint = GameConstants.ConvertPixelPositionToRoomPosition(entryPixelPoint); m_gameWorldController.OnEnergyTankClicked(entryWorldPoint, energyTankData); }
public void SetEnergyTankById(int energy_tank_id, EnergyTankData energyTank) { m_energyTanks.Add(energy_tank_id, energyTank); }
public EnergyTankWidget AddEnergyTankWidget(EnergyTankData energyTankData) { // Constructor adds the widget to the entity widget group return(new EnergyTankWidget(m_entityGroup, energyTankStyle, energyTankData)); }
public EnergyTankWidget AddEnergyTankWidget(EnergyTankData energyTankData) { // Constructor adds the widget to the entity widget group return new EnergyTankWidget(m_entityGroup, energyTankStyle, energyTankData); }
public void UpdateState(EnergyTankData energyTankData) { this.Energy = energyTankData.energy; this.Ownership = energyTankData.ownership; }
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); } } }
public EnergyTankData GetEnergyTankById(int energy_tank_id) { EnergyTankData result = null; return(m_energyTanks.TryGetValue(energy_tank_id, out result) ? result : null); }