private void HandlePlayerConnected(RealmEventBase playerConnectedEventData) { PlayerConnectedEvent playerConnectedEvent = playerConnectedEventData as PlayerConnectedEvent; string playerSessionId = playerConnectedEvent.playerSessionId; string playerId = playerConnectedEvent.playerId; Debug.Log("Player Connected {playerId: " + playerId + ", playerSessionId: " + playerSessionId); Vector3Int spawnPosition = RealmStateManager.GetRealmState().GetMapState().GetSpawnPosition(); GameObject playerAvatar = Instantiate(playerAvatarPrefab, mapGrid.CellToWorld(spawnPosition), Quaternion.identity); playerAvatar.GetComponent <Player>().playerId = playerId; IReadPlayerState playerState = RealmStateManager.GetRealmState().GetPlayerState(playerId); Color playerColor = new Color(); if (ColorUtility.TryParseHtmlString(playerState.GetColor(), out playerColor)) { playerAvatar.GetComponent <MeshRenderer>().material.color = playerColor; } if (playerGameObjects.ContainsKey(playerId)) { Debug.LogError("Player with ID attmempted to connect twice: " + playerId); } playerGameObjects.Add(playerId, playerAvatar); }
public static void TriggerEvent(string eventType, RealmEventBase eventData) { RealmEventTopic thisEvent = null; if (instance.realmEventDictionary.TryGetValue(eventType, out thisEvent)) { thisEvent.Invoke(eventData); } }
private static string GetEventType(RealmEventBase realmEventData) { var attribute = realmEventData.GetType().GetCustomAttributes(typeof(RealmEventDataAttribute), false).FirstOrDefault() as RealmEventDataAttribute; if (attribute != null) { return(attribute.eventType); } else { Debug.LogError("Missing attribute RealmEvent on class " + realmEventData.GetType()); return(null); } }
private void HandlePlayerMove(RealmEventBase baseEvent) { PlayerMoveEvent playerMoveEvent = baseEvent as PlayerMoveEvent; Vector2Int playerPosition = RealmStateManager.GetRealmState().GetPlayerState(playerMoveEvent.playerId).GetPosition(); IReadHexState hexState = RealmStateManager.GetRealmState().GetMapState().GetHexState(playerPosition); if (hexState.IsVisible()) { if (hexState.GetTerrain().Equals("GRASS")) { instance.tilemap.SetTile((Vector3Int)playerPosition, instance.grassTile); } else { instance.tilemap.SetTile((Vector3Int)playerPosition, instance.waterTile); } } }
private void HandlePlayerDisconnected(RealmEventBase playerDisconnectedEventData) { PlayerDisconnectedEvent playerDisconnectedEvent = playerDisconnectedEventData as PlayerDisconnectedEvent; string playerSessionId = playerDisconnectedEvent.playerSessionId; string playerId = playerDisconnectedEvent.playerId; Debug.Log("Player Disconnected {playerId: " + playerId + ", playerSessionId: " + playerSessionId); GameObject playerAvatar; if (playerGameObjects.TryGetValue(playerId, out playerAvatar)) { Destroy(playerAvatar); playerGameObjects.Remove(playerId); } else { Debug.LogError("Unrecognized Player Disconnected: " + playerId); } }
public static void TriggerEvent(RealmEventBase eventData) { TriggerEvent(GetEventType(eventData), eventData); }
public void HandlePlayerMove(RealmEventBase baseEvent) { PlayerMoveEvent playerMoveEvent = baseEvent as PlayerMoveEvent; if (playerMoveEvent.playerId.Equals(playerId)) { Vector3Int currentCell = mapGrid.WorldToCell(transform.position); Vector3Int destinationCell = currentCell; switch (playerMoveEvent.direction) { case "1": destinationCell.x = currentCell.x + 1; destinationCell.y = currentCell.y; break; case "2": if (currentCell.y % 2 == 0) { destinationCell.x = currentCell.x; } else { destinationCell.x = currentCell.x + 1; } destinationCell.y = currentCell.y - 1; break; case "3": if (currentCell.y % 2 == 0) { destinationCell.x = currentCell.x - 1; } else { destinationCell.x = currentCell.x; } destinationCell.y = currentCell.y - 1; break; case "4": destinationCell.x = currentCell.x - 1; destinationCell.y = currentCell.y; break; case "5": if (currentCell.y % 2 == 0) { destinationCell.x = currentCell.x - 1; } else { destinationCell.x = currentCell.x; } destinationCell.y = currentCell.y + 1; break; case "6": if (currentCell.y % 2 == 0) { destinationCell.x = currentCell.x; } else { destinationCell.x = currentCell.x + 1; } destinationCell.y = currentCell.y + 1; break; default: break; } this.transform.position = mapGrid.CellToWorld(destinationCell); } }
private void HandlePlayerMove(RealmEventBase baseEvent) { PlayerMoveEvent playerMoveEvent = baseEvent as PlayerMoveEvent; Debug.Log("Player Moved: " + playerMoveEvent.direction); }