private void SetPortalData(Portal portal) { PortalData _portalData = Data.GetPortalByName(portal.gameObject.name); _portalData.PortalStatus = portal.DestinationStatus; Data.SetPortalData(_portalData); }
public PortalData GetRandomPortal(PortalData portal) { PortalController sourceController = GetPortalControllerByPortalData(portal); PortalController destinyController = TeleportationDestiny(sourceController); return(destinyController.GetPortalData()); }
void EntryChange(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { PortalData bp = (PortalData)p.blockchangeObject; if (!p.level.CheckAffectPermissions(p, x, y, z, type, extType)) { p.RevertBlock(x, y, z); return; } p.ClearBlockchange(); if (bp.Multi && type == Block.red && bp.entries.Count > 0) { ExitChange(p, x, y, z, type, extType); return; } p.level.Blockchange(p, x, y, z, bp.type); p.SendBlockchange(x, y, z, Block.green); PortalPos Port; Port.mapName = p.level.name; Port.x = x; Port.y = y; Port.z = z; bp.entries.Add(Port); p.blockchangeObject = bp; if (!bp.Multi) { p.Blockchange += ExitChange; Player.SendMessage(p, "&aEntry block placed"); } else { p.Blockchange += EntryChange; Player.SendMessage(p, "&aEntry block placed. &cRed block for exit"); } }
private static void OnEnterPortal(InteractableInfo info) { #if UNITY_EDITOR Debug.Log("Entered Portal"); #endif //Get PortalComponent PortalData data = World.DefaultGameObjectInjectionWorld.EntityManager .GetComponentData <PortalData>(info.TriggerEntity); //Get PortalInfo MapInfo.Portal portal = MapHolder.MapsInfo[MapEvents.CurrentTypeLoaded].Portals[data.Value]; if (!TryEnterPortal(portal.MapTypeLeadingTo, portal.PortalIdLeadingTo)) { #if UNITY_EDITOR Debug.Log("The Portal ur trying to teleport to doesnt exist yet..."); #endif return; } //Get PortalInfo of other map MapInfo.Portal objectivePortal = MapHolder.MapsInfo[portal.MapTypeLeadingTo].Portals[portal.PortalIdLeadingTo]; //Change Map MapEvents.LoadMap(portal.MapTypeLeadingTo); //Set player position/rotation GlobalEvents.PlayerEvents.SetPlayerPosition(objectivePortal.Position); GlobalEvents.PlayerEvents.SetPlayerRotation(objectivePortal.Rotation); }
public void AddPortal(GameObject PortalObj) { string _name = PortalObj.name; Status _status = PortalObj.GetComponent <Portal>().DestinationStatus; PortalData _data = new PortalData(_name, _status); Destinations.Add(_data); }
public void Teleport(PortalData portal) { PortalUI target = portalUIIdentifier.GetPortalUI(portal); Transform targetTransform = target.GetComponent <Transform>(); transform.position = targetTransform.position + (-targetTransform.forward * 4); portalRemover.RemovePortal(portal); }
public void Create(PortalData portalData, Vector3 pos) { _portalData = portalData; _pos = pos; GetComponent <SpriteRenderer>().sortingOrder = (int)(transform.position.y * -10); _a = GetComponent <Animator>(); Initiate(); }
private PortalController GetPortalControllerByPortalData(PortalData portal) { for (int i = 0; i < portalList.Count; i++) { PortalController controller = portalList[i]; if (controller.GetPortalData().Equals(portal)) { return(controller); } } throw new PortalControllerNotFoundException("Portal not found"); }
public void SetFromExplorePortalList(List <ExplorePortalPoint> portals) { for (int i = 0; i < portals.Count; i++) { ExplorePortalPoint explorePortalPoint = portals[i]; if (explorePortalPoint.point > 0 || 0 < explorePortalPoint.used) { PortalData item = new PortalData(explorePortalPoint.portaiId, explorePortalPoint.point, explorePortalPoint.used); ps.Add(item); } } }
public static object Serialize_PortalData(object _obj, System.Type type, OverloadLevelConvertSerializer serializer) { PortalData obj = (PortalData)_obj; serializer.SerializeX(obj, x => x.MasterSegmentIndex); serializer.SerializeX(obj, x => x.MasterSideIndex); serializer.SerializeX(obj, x => x.SlaveSegmentIndex); serializer.SerializeX(obj, x => x.SlaveSideIndex); serializer.SerializeX(obj, x => x.Polygons); // Note: not serializing .DoorData, which is only used in the runtime return(obj); }
public void CreatePortal(PortalUI portalUI) { Guid guid = Guid.NewGuid(); PortalData portalData = new PortalData(guid); PortalController portalController = new PortalController(); portalUI.SetGuid(guid); portalUI.SetPortalData(portalData); portalUI.SetPortalEnterNotifier(portalController); portalController.SetPortalDataOutput(portalUI); portalController.SetPortalRemoveOutput(portalUI); portalsController.AddPortal(portalController); portalUICollection.AddPortalUI(portalUI); }
void ExitChange(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); PortalData bp = (PortalData)p.blockchangeObject; foreach (PortalPos P in bp.Entries) { string lvlName = P.Map; object locker = ThreadSafeCache.DBCache.Get(lvlName); lock (locker) { Database.Backend.CreateTable("Portals" + lvlName, LevelDB.createPortals); Level map = LevelInfo.FindExact(P.Map); if (map != null) { map.hasPortals = true; } int count = 0; using (DataTable portals = Database.Backend.GetRows("Portals" + lvlName, "*", "WHERE EntryX=@0 AND EntryY=@1 AND EntryZ=@2", P.x, P.y, P.z)) { count = portals.Rows.Count; } if (count == 0) { Database.Backend.AddRow("Portals" + lvlName, "EntryX, EntryY, EntryZ, ExitX, ExitY, ExitZ, ExitMap", P.x, P.y, P.z, x, y, z, p.level.name); } else { Database.Backend.UpdateRows("Portals" + lvlName, "ExitMap=@6, ExitX=@3, ExitY=@4, ExitZ=@5", "WHERE EntryX=@0 AND EntryY=@1 AND EntryZ=@2", P.x, P.y, P.z, x, y, z, p.level.name); } } if (P.Map == p.level.name) { p.SendBlockchange(P.x, P.y, P.z, bp.Block, bp.ExtBlock); } } Player.Message(p, "&3Exit %Sblock placed"); if (!p.staticCommands) { return; } bp.Entries.Clear(); p.blockchangeObject = bp; p.Blockchange += EntryChange; }
public void SetPortalData(PortalData portal) { int i; for (i = 0; i < Destinations.Count; i++) { if (Destinations[i].ObjectName == portal.ObjectName) { PortalData _data = Destinations[i]; _data.PortalStatus = portal.PortalStatus; Destinations[i] = _data; break; } } }
private void UpdatePortalData() { GameObject[] portals = GameObject.FindGameObjectsWithTag("Portal"); if (portals.Length == 0) { return; } foreach (GameObject portal in portals) { PortalData _portalData = Data.GetPortalByName(portal.name); Portal _portal = portal.GetComponent <Portal>(); _portal.DestinationStatus = _portalData.PortalStatus; } }
void ExitChange(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); PortalData bp = (PortalData)p.blockchangeObject; foreach (PortalPos pos in bp.entries) { //safe against SQL injections because no user input is given here DataTable Portals = Database.fillData("SELECT * FROM `Portals" + pos.mapName + "` WHERE EntryX=" + (int)pos.x + " AND EntryY=" + (int)pos.y + " AND EntryZ=" + (int)pos.z); Portals.Dispose(); if (Portals.Rows.Count == 0) {//safe against SQL injections because no user input is given here Database.executeQuery("INSERT INTO `Portals" + pos.mapName + "` (EntryX, EntryY, EntryZ, ExitMap, ExitX, ExitY, ExitZ) VALUES (" + (int)pos.x + ", " + (int)pos.y + ", " + (int)pos.z + ", '" + p.level.name + "', " + (int)x + ", " + (int)y + ", " + (int)z + ")"); } else {//safe against SQL injections because no user input is given here Database.executeQuery("UPDATE `Portals" + pos.mapName + "` SET ExitMap='" + p.level.name + "', ExitX=" + (int)x + ", ExitY=" + (int)y + ", ExitZ=" + (int)z + " WHERE EntryX=" + (int)pos.x + " AND EntryY=" + (int)pos.y + " AND EntryZ=" + (int)pos.z); } //DB if (pos.mapName == p.level.name) { p.SendBlockchange(pos.x, pos.y, pos.z, bp.type); } } Player.SendMessage(p, "&3Exit %Sblock placed"); if (!p.staticCommands) { return; } bp.entries.Clear(); p.blockchangeObject = bp; p.Blockchange += EntryChange; }
void EntryChange(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { PortalData data = (PortalData)p.blockchangeObject; byte old = p.level.GetTile(x, y, z); if (!p.level.CheckAffectPermissions(p, x, y, z, old, data.Block, data.ExtBlock)) { p.RevertBlock(x, y, z); return; } p.ClearBlockchange(); if (data.Multi && type == Block.red && data.Entries.Count > 0) { ExitChange(p, x, y, z, type, extType); return; } p.level.Blockchange(p, x, y, z, data.Block, data.ExtBlock); p.SendBlockchange(x, y, z, Block.green); PortalPos Port; Port.Map = p.level.name; Port.x = x; Port.y = y; Port.z = z; data.Entries.Add(Port); p.blockchangeObject = data; if (!data.Multi) { p.Blockchange += ExitChange; Player.Message(p, "&aEntry block placed"); } else { p.Blockchange += EntryChange; Player.Message(p, "&aEntry block placed. &cRed block for exit"); } }
public void OnTeleportationFinished(PortalData portal) { throw new NotImplementedException(); }
public void OnTeleportation(PortalData source) { PortalData destiny = portalRandomizer.GetRandomPortal(source); playerTeleportableOutput.Teleport(destiny); }
public void RemovePortal(PortalData portal) { PortalController portalController = GetPortalControllerByPortalData(portal); RemovePortal(portalController); }
public void Travel(PortalData data) { StartCoroutine(TravelAnimation((int)data.target, data.targetScenePosition)); }
//This is called after a level is loaded. Create the GameManager if this is the first level loaded. //This function should do nothing else. public void Awake() { #if !OVERLOAD_LEVEL_EDITOR // Defer the Awake until after user level loading is complete if (UserLevelLoader.IsLoadingUserLevel) { UserLevelLoader.ExecuteAfterLoading(() => { Awake(); }); return; } Debug.Log("LevelData Awake " + Time.realtimeSinceStartup); //If Game Manager doesn't exist (this is the first level to be loaded), create it if (Object.Equals(GameManager.m_gm, null)) //When the game is shutting down in the editor it apparently re-loads the editor level after closing down the GameManager causing this to be called when m_gm is fake-null. So check for real null. { GameManager.Required(m_game_manager_prefab != null, "Game manager prefab not specified"); Instantiate(m_game_manager_prefab, Vector3.zero, Quaternion.identity); } //Check for geometry data GameManager.Required(m_geometry != null, "Geometry data not specified"); //Save the global for the level initializer object GameManager.m_level_data = this; // Add local player immediately. Remote clients will only add players once scene is loaded both on server and locally. if (NetworkManager.IsServer()) { Client.AddPlayer(); } else { GameManager.m_player_ship = PlayerShip.Instantiate(); GameManager.m_local_player = GameManager.m_player_ship.c_player; } GameObject legacy_player_start = GameObject.FindGameObjectWithTag("LegacyPlayerStart"); if (!GameplayManager.IsMultiplayer) { GameManager.m_player_ship.SetSpawnPosAndRotation(legacy_player_start); } if (legacy_player_start != null) { legacy_player_start.SetActive(false); // start has a camera we want to disable } //Get the viewer component GameManager.m_viewer = Camera.main.GetComponent <Viewer>(); GameManager.Required(GameManager.m_viewer != null, "Must have Viewer component on camera"); //Get the mesh containers GameManager.m_mesh_container = GameObject.Find("_container_level_meshes"); // // Do some processing on this object's data. Don't do anything else here. // //Fix up the door references if (m_portal_to_door_references != null) { foreach (var portal_door_ref in m_portal_to_door_references) { int portal_index = portal_door_ref.PortalIndex; if (portal_index >= 0 && portal_index < m_geometry.Portals.Length) { m_geometry.Portals[portal_index].DoorData = portal_door_ref.ReferenceDoor; } else { Debug.LogError(string.Format("Portal Index {0} is out of range for door {1}", portal_index, portal_door_ref.ReferenceDoor.name)); } } } //Create empty level light and reflection probe arrays if they're not present if (m_level_lights == null) { m_level_lights = new SegmentLightInfo[0]; } if (m_level_reflection_probes == null || m_level_reflection_probes.Length == 0) { List <SegmentReflectionProbeInfo> srpi_list = new List <SegmentReflectionProbeInfo>(); // Gather the reflection probes the hard way (slowly) GameObject userContainerObject = GameObject.Find("!rprobes"); if (userContainerObject != null && userContainerObject.transform.parent == null) { // Gather all the reflection probes under "!probes" ReflectionProbe[] rps = userContainerObject.GetComponentsInChildren <ReflectionProbe>(); int count = rps.Length; for (int i = 0; i < count; i++) { SegmentReflectionProbeInfo srpi = new SegmentReflectionProbeInfo(); srpi.ProbeObject = rps[i].gameObject; srpi.SegmentIndex = FindSegmentContainingWorldPosition(rps[i].transform.position); if (srpi.SegmentIndex < 0) { srpi.SegmentIndex = ChunkManager.FindNearestSegment(rps[i].transform.position); } srpi.ProbeType = SegmentReflectionProbeType.UserPlaced; srpi_list.Add(srpi); } } m_level_reflection_probes = srpi_list.ToArray(); if (m_level_reflection_probes == null) { m_level_reflection_probes = new SegmentReflectionProbeInfo[0]; } } NumSegments = m_geometry.Segments.Length; // Associate lights to segments { Dictionary <int, List <SegmentLightInfo> > mapLightsToSegment = new Dictionary <int, List <SegmentLightInfo> >(); foreach (var llight in m_level_lights) { if (llight.SegmentIndex < 0 || llight.SegmentIndex >= NumSegments) { Debug.LogErrorFormat("Level light at invalid segment index {0}", llight.SegmentIndex); continue; } List <SegmentLightInfo> list; if (!mapLightsToSegment.TryGetValue(llight.SegmentIndex, out list)) { list = new List <SegmentLightInfo>(); mapLightsToSegment.Add(llight.SegmentIndex, list); } if (llight.LightObject != null && llight.LightComp != null) { list.Add(llight); } } foreach (var kvp in mapLightsToSegment) { m_geometry.Segments[kvp.Key].Lights = kvp.Value.ToArray(); } // Provide an empty list for the other segments SegmentLightInfo[] dummyList = new SegmentLightInfo[0]; for (int segIndex = 0; segIndex < NumSegments; ++segIndex) { if (mapLightsToSegment.ContainsKey(segIndex)) { continue; } m_geometry.Segments[segIndex].Lights = dummyList; } } // Associate reflection probes to segments { Dictionary <int, List <SegmentReflectionProbeInfo> > mapProbesToSegment = new Dictionary <int, List <SegmentReflectionProbeInfo> >(); foreach (var lprobe in m_level_reflection_probes) { if (lprobe.SegmentIndex < 0 || lprobe.SegmentIndex >= NumSegments) { Debug.LogErrorFormat("Level reflection probe at invalid segment index {0}", lprobe.SegmentIndex); continue; } List <SegmentReflectionProbeInfo> list; if (!mapProbesToSegment.TryGetValue(lprobe.SegmentIndex, out list)) { list = new List <SegmentReflectionProbeInfo>(); mapProbesToSegment.Add(lprobe.SegmentIndex, list); } if (lprobe.ProbeObject != null) { list.Add(lprobe); } } foreach (var kvp in mapProbesToSegment) { m_geometry.Segments[kvp.Key].ReflectionProbes = kvp.Value.ToArray(); } // Provide an empty list for the other segments SegmentReflectionProbeInfo[] dummyList = new SegmentReflectionProbeInfo[0]; for (int segIndex = 0; segIndex < NumSegments; ++segIndex) { if (mapProbesToSegment.ContainsKey(segIndex)) { continue; } m_geometry.Segments[segIndex].ReflectionProbes = dummyList; } } //Find connecting portals for chunk portals foreach (ChunkPortal chunk_portal in m_geometry.ChunkPortals) { if (chunk_portal.ConnectedPortal == -1) { PortalData seg_portal = m_geometry.Portals[m_geometry.Segments[chunk_portal.Segnum].Portals[chunk_portal.Sidenum]]; int connected_segnum = (seg_portal.MasterSegmentIndex == chunk_portal.Segnum) ? seg_portal.SlaveSegmentIndex : seg_portal.MasterSegmentIndex; foreach (int connected_chunk_portal_index in m_geometry.Chunks[chunk_portal.ConnectedChunk].PortalIndices) { ChunkPortal connected_chunk_portal = m_geometry.ChunkPortals[connected_chunk_portal_index]; if (connected_chunk_portal.Segnum == connected_segnum) { chunk_portal.ConnectedPortal = connected_chunk_portal.Num; connected_chunk_portal.ConnectedPortal = chunk_portal.Num; } } Assert.True(chunk_portal.ConnectedPortal != -1); } } //Make list of Chunks CreateChunkList(); //Set up object to access segment visibility if (m_geometry.SegmentToSegmentVisibility == null) { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); Segment2SegmentVis.ComputeSegmentVisibility(m_geometry, 55.0f); stopWatch.Stop(); UnityEngine.Debug.LogFormat("ComputeSegmentVisibility took {0} ms", stopWatch.ElapsedMilliseconds); } if (m_geometry.SegmentToSegmentVisibility != null) { m_segment_visibility = new IndexAs2D(m_geometry.SegmentToSegmentVisibility, NumSegments); } else { m_segment_visibility = null; } //Make a list of ambient sound sources in the level. Might make sense to keep that list here, but the gather function is a little audio-specific if (GameManager.m_audio != null) //Don't do this on game startup { GameManager.m_audio.GatherAmbientSounds(); } //Find the reactor, if one exists Reactor[] reactors = FindObjectsOfType <Reactor>(); if (reactors.Length == 0) { //Debug.Log("There is no reactor in this level!"); Reactor = null; } else { if (reactors.Length > 1) { Debug.Log("There are " + reactors.Length + " reactors in this level! There should be no more than one! Will only use the first one found"); } Reactor = reactors[0]; } // Find the alien warper if one exists. GameObject alien_warp = GameObject.FindGameObjectWithTag("AlienWarp"); if (alien_warp != null) { m_alien_warp_segment = GameManager.m_level_data.FindSegmentContainingWorldPosition(alien_warp.transform.position); Debug.Log("Alien warper is in segment " + m_alien_warp_segment); } else { m_alien_warp_segment = -1; // It's OK if there is no alien warper, most levels don't have one! } //Reset LevelCustomInfo statics in case the level doesn't have a LevelCustomInfo component LevelCustomInfo.Reset(); //Find segments for spawn points SetSpawnPointSegments(m_robot_spawn_points); SetSpawnPointSegments(m_item_spawn_points); SetSpawnPointSegments(m_player_spawn_points); SetSpawnPointSegments(m_mp_camera_points); TriggerWindTunnel.UpdateSegmentsForWindTunnels(); // Deal with Wind Tunnels (WindTunnels) Forcefield.UpdateSegmentsForForcefields(); // Deal with Forcefields // Deal with teleporters. for (int i = 0; i < GameManager.m_level_data.Segments.Length; i++) { GameManager.m_level_data.Segments[i].WarpDestinationSegs = new int[6]; for (int j = 0; j < 6; j++) { GameManager.m_level_data.Segments[i].WarpDestinationSegs[j] = -1; } } //Find & initialize cryotubes InitCryotubes(); // Explode the hierarchy (for optimization reasons) if (CrushHierarchy) { GameManager.m_mesh_container.transform.DetachChildren(); GameObject container = GameObject.Find("_container_level_lava_meshes"); container.transform.DetachChildren(); //container = GameObject.Find("_container_placed_entities"); //int count = container.transform.childCount; //for (int i = count - 1; i >= 0; i--) { // container.transform.GetChild(i).DetachChildren(); //} LevelCustomInfo.TryToCrush(); } Debug.Log("LevelData Awake DONE " + Time.realtimeSinceStartup); #endif // !OVERLOAD_LEVEL_EDITOR }
public void SetPortalData(PortalData portalData) { this.portalData = portalData; }
// takes the current placed levelObjects and serializes it into the levelData format public static LevelData CreateLevelData() { if (LevelPlacer.generatedLevel != null && editLevel != null) { print("CreateLevelData"); LevelDataMono level = LevelPlacer.generatedLevel; LevelData l = new LevelData(level.levelData.id); // save level info l.author = level.levelData.author; l.id = level.levelData.id; l.presetTime = DoubleToTwoDecimals(level.levelData.presetTime); l.title = level.levelData.title; l.custom = level.levelData.custom; // save moveArea mesh Vector3[] verts = level.moveArea.meshFilter.mesh.vertices; Position2[] posVerts = new Position2[verts.Length]; for (int i = 0; i < verts.Length; i++) { posVerts[i] = new Position2(verts[i].x, verts[i].y); } if (!posVerts.Equals(editLevel.moveVerticies)) { Debug.Log("Different Vertices"); } l.moveVerticies = posVerts; l.moveTriangles = level.moveArea.meshFilter.mesh.triangles; // save spawn Vector3 spawnPos = level.spawn.transform.localPosition; l.objectData.spawnPosition = new Position2(spawnPos.x, spawnPos.y); // save finish Vector3 finishPos = level.finish.transform.localPosition; l.objectData.finishPosition = new Position2(finishPos.x, finishPos.y); // save turrets foreach (Turret t in level.turrets) { Position2 turretPosition = new Position2(t.transform.localPosition.x, t.transform.localPosition.y); TurretData td = new TurretData(turretPosition); td.rotation = new Position3(t.transform.rotation.eulerAngles.x, t.transform.rotation.eulerAngles.y, t.transform.rotation.eulerAngles.z); td.shotDelay = FloatToTwoDecimals(t.shotDelay); td.shotSpeed = FloatToTwoDecimals(t.shotSpeed); td.startupDelay = FloatToTwoDecimals(t.startupDelay); td.constantFire = t.constantFire; l.objectData.turretData.Add(td); } // save attractors foreach (Attractor a in level.attractors) { Position2 aPosition = new Position2(a.transform.localPosition.x, a.transform.localPosition.y); AttractorData ad = new AttractorData(aPosition); ad.pullStrength = (int)a.maxPullForce; ad.radius = (int)a.pullRadius; l.objectData.attractorData.Add(ad); } // save portals foreach (Portal p in level.portals) { Position2 pPosition = new Position2(p.transform.localPosition.x, p.transform.localPosition.y); PortalData pd = new PortalData(pPosition, p.portalID); pd.portalID = p.portalID; pd.linkedPortalID = p.linkedPortalID; l.objectData.portalData.Add(pd); } // save speedstrips foreach (SpeedStrip s in level.speedStrips) { Position2 pPosition = new Position2(s.transform.localPosition.x, s.transform.localPosition.y); SpeedStripData sd = new SpeedStripData(pPosition); sd.rotation = new Position3(s.transform.rotation.eulerAngles.x, s.transform.rotation.eulerAngles.y, s.transform.rotation.eulerAngles.z); sd.pushStrength = (int)s.accelSpeed; l.objectData.speedStripData.Add(sd); } foreach (Bouncer b in level.bouncers) { Position2 bPosition = new Position2(b.transform.localPosition.x, b.transform.localPosition.y); BouncerData bd = new BouncerData(bPosition); bd.rotation = new Position3(b.transform.rotation.eulerAngles.x, b.transform.rotation.eulerAngles.y, b.transform.rotation.eulerAngles.z); bd.bounciness = b.bounciness; bd.width = b.width; l.objectData.bouncerData.Add(bd); } return(l); } return(null); }
public PortalUI GetPortalUI(PortalData portalData) { return(Find(portalData.GetGuid())); }