public static float StatusIntervalToFloat(PlayerStatusInterval interval) { double time = Mathf.Infinity; switch (interval) { case PlayerStatusInterval.OnePing: time = WorldClock.HoursToSeconds(0.001f); break; case PlayerStatusInterval.HalfHour: time = WorldClock.HoursToSeconds(0.01f); break; case PlayerStatusInterval.OneHour: time = WorldClock.HoursToSeconds(0.05f); break; case PlayerStatusInterval.TwoHours: time = WorldClock.HoursToSeconds(0.10f); break; case PlayerStatusInterval.HalfDay: time = WorldClock.HoursToSeconds(0.5f); break; case PlayerStatusInterval.OneDay: time = WorldClock.HoursToSeconds(1.0f); break; default: break; } return((float)time); }
public bool TryToWakeUp(string cause) { if (!State.IsSleeping) { return(false); } if (mChildEditor != null) { GUIEditor <MessageCancelDialogResult> editor = mChildEditor.GetComponent <GUIEditor <MessageCancelDialogResult> >(); editor.ActionCancel(WorldClock.AdjustedRealTime); return(false); } Player.Local.Position = mLastBed.BedsidePosition; Player.Local.State.Transform.Position = Player.Local.Position; Player.Local.RestoreControl(false); Player.Get.AvatarActions.ReceiveAction(AvatarAction.SurvivalWakeUp, WorldClock.AdjustedRealTime); WorldClock.Get.SetTargetSpeed(1.0f); State.IsSleeping = false; State.LastSleepInterruption = cause; double timeSlept = WorldClock.SecondsToHours(WorldClock.AdjustedRealTime - State.StartSleepTime); if (timeSlept > Globals.WellRestedHours) { AddCondition("WellRested"); } return(true); }
public void SetGameTimeOffset(double hours, double days, double months, double years) { GameTimeOffset = ( WorldClock.HoursToSeconds(hours) + WorldClock.DaysToSeconds(days) + WorldClock.MonthsToSeconds(months) + WorldClock.YearsToSeconds(years)); }
public override void WakeUp() { base.WakeUp(); Get = this; mParentUnderManager = false; mARTimeScaleTarget = 1.0f; //set this so we can zero out our RT StopWatch.Start(); mRTime = 0f; mRTLastUpdateTime = 0f; SetCycleLength(Globals.DefaultInGameMinutesPerRealTimeSecond); }
public bool TryToSleep(Bed bed, TimeOfDay timeOfDay) { if (State.IsSleeping) { return(false); } if (player.Status.HasCondition("BurnedByFire")) { GUIManager.PostDanger("You're on fire! Put yourself out first!"); return(false); } if (player.Surroundings.IsInDanger) { GUIManager.PostDanger("You can't sleep while you're in danger"); return(false); } mLastBed = bed; //get the time we want to sleep until State.SleepTarget = WorldClock.FutureTime(WorldClock.Get.HoursUntilTimeOfDay(timeOfDay), TimeUnit.Day); //set the player's hijack points player.HijackControl(); player.State.HijackMode = PlayerHijackMode.LookAtTarget; player.SetHijackTargets(bed.CameraTargetPosition, bed.CameraLookTarget); //create the dialog MessageCancelDialogResult result = new MessageCancelDialogResult(); result.Message = "Sleeping..."; result.CanCancel = true; result.CancelButton = "Wake up"; mChildEditor = GUIManager.SpawnNGUIChildEditor(gameObject, GUIManager.Get.NGUIMessageCancelDialog, false); GUIManager.SendEditObjectToChildEditor <MessageCancelDialogResult>(new ChildEditorCallback <MessageCancelDialogResult>(ReceiveFromChildEditor), mChildEditor, result); //start sleeping and send avatar action State.IsSleeping = true; State.StartSleepTime = WorldClock.AdjustedRealTime; Player.Get.AvatarActions.ReceiveAction((AvatarAction.SurvivalSleep), WorldClock.AdjustedRealTime); WorldClock.Get.SetTargetSpeed(WorldClock.gTimeScaleSleep); StartCoroutine(Sleep()); return(true); }
protected void UpdateTraveling() { if (!Paths.HasActivePath) { return; } if (Paths.IsEvaluating) { return; } if (StrengthStatusKeeper.NormalizedValue < 0f) { GUIManager.PostDanger("You're too exhausted to fast travel"); State = FastTravelState.Finished; return; } CurrentSegment = Paths.ActivePath.SegmentFromMeters(PathCurrentMeters); float metersToMove = (float)(TimeScaleTravel * WorldClock.RTDeltaTime); PathCurrentMeters = Paths.MoveAlongPath(PathCurrentMeters, metersToMove, CurrentDirection); CurrentPosition = Paths.ActivePath.PositionFromMeters(PathCurrentMeters); mTerrainHit.feetPosition = CurrentPosition; mTerrainHit.overhangHeight = 2f; mTerrainHit.groundedHeight = 2f; mTerrainHit.ignoreWorldItems = false; CurrentPosition.y = GameWorld.Get.TerrainHeightAtInGamePosition(ref mTerrainHit) + Player.Local.Height.y; if (mTerrainHit.hitWater) { GUIManager.PostDanger("You can't fast travel over water"); CurrentPosition.y += 2f; //TEMP just to be safe CancelTraveling(); return; } #if UNITY_EDITOR if (VRManager.VRMode | VRManager.VRTestingMode && Profile.Get.CurrentPreferences.Video.VRStaticCameraFastTravel) { #else if (VRManager.VRMode && Profile.Get.CurrentPreferences.Video.VRStaticCameraFastTravel) { #endif //if we're in vr mode and we want to use a static camera //just fade out, and hold the fade, then release it once we're done if (!mFadingOutOverTime) { mFadingOutOverTime = true; StartCoroutine(FadeOutOverTime()); } } else { //make sure hijacked position is facing the right direction, etc Player.Local.State.HijackMode = PlayerHijackMode.OrientToTarget; Player.Local.HijackedPosition.position = CurrentPosition; Player.Local.HijackedPosition.rotation = Quaternion.identity; Player.Local.HijackLookSpeed = Globals.PlayerHijackLerp; CurrentOrientation = Paths.ActivePath.OrientationFromMeters(PathCurrentMeters, true); Player.Local.HijackedPosition.transform.Rotate(CurrentOrientation); if (CurrentDirection == PathDirection.Backwards) { Player.Local.HijackedPosition.transform.Rotate(0f, 180f, 0f); } } if (HasReachedOrPassedDestination) { //Debug.Log("Has reached destination..."); ArriveAtDestination(); } //update the passage of time //fast travel time is updated according to how many meters the player has moved since the last update //the number of meters per second is deterimed by the player's motor throttle speed //plus the skill level of fast travel //(i've tried it a half-dozen different ways and this one is the most stable) double timeAdvanced = (metersToMove / Player.Local.MotorAccelerationMultiplier) * 0.1f; StrengthStatusKeeper.ChangeValue(Globals.FastTravelStrengthReducedPerMeterTraveled * metersToMove, StatusSeekType.Negative); WorldClock.AddARTDeltaTime(timeAdvanced); }
protected IEnumerator CheckAttentionItems() { while (AttentionObjects.Count > 0) { //go through each attention object and make sure it's not null or too far away for (int i = AttentionObjects.Count - 1; i >= 0; i--) { IItemOfInterest attentionObject = AttentionObjects [i]; if (attentionObject == null) //if it's null then we're not paying attention to it any more //remove it from checkup too just in case { AttentionObjects.RemoveAt(i); LosingAttentionObjects.Remove(attentionObject); } else if (!LosingAttentionObjects.ContainsKey(attentionObject)) //if we're not ALREADY checking up on this object //this distance check works on motile too because we're attending to the object, not the follower { float distance = Vector3.Distance(Player.Local.Position, attentionObject.Position); if (distance > Globals.PlayerPickUpRange) //if an attention object is out of range { Motile motile = null; if (attentionObject.IOIType == ItemOfInterestType.WorldItem && attentionObject.worlditem.Is <Motile> (out motile)) //if it's motile { Transform follower = motile.GoalObject.transform; if (!mTargetHolder.HasFollower(follower)) //and it's not following us //then it's losing our attention { LosingAttentionObjects.Add(attentionObject, WorldClock.Time); } } else //if it's not motile then just say it's in danger { LosingAttentionObjects.Add(attentionObject, WorldClock.Time); } } } } //wait a bit yield return(null); //now go through the ones that are losing attention List <IItemOfInterest> keepAttentionObjects = new List <IItemOfInterest> (); List <IItemOfInterest> loseAttentionObjects = new List <IItemOfInterest> (); foreach (KeyValuePair <IItemOfInterest, double> losingAttentionObject in LosingAttentionObjects) { bool inRange = false; bool hasTime = false; bool isFollowing = false; //if it's not null start by checking range float distance = Vector3.Distance(Player.Local.Position, losingAttentionObject.Key.Position); inRange = (distance < Globals.PlayerPickUpRange); if (inRange) //wuhoo, we keep attention and no longer need to be checked { keepAttentionObjects.Add(losingAttentionObject.Key); } else //if we're not in range //check if the motile is following us { Motile motile = null; if (losingAttentionObject.Key.IOIType == ItemOfInterestType.WorldItem && losingAttentionObject.Key.worlditem.Is <Motile> (out motile)) //if it's motile { Transform follower = motile.GoalObject.transform; isFollowing = mTargetHolder.HasFollower(follower); } if (isFollowing) //wuhoo, we keep attention and no longer need to be checked { keepAttentionObjects.Add(losingAttentionObject.Key); } else { hasTime = (losingAttentionObject.Value + WorldClock.RTSecondsToGameSeconds(LoseAttentionRT) > WorldClock.Time); if (!hasTime) //if we don't have any time left, we lose focus //time is a last resort so if we DO have time we don't keep focus { loseAttentionObjects.Add(losingAttentionObject.Key); } } } } //wait a tick yield return(null); //alright we have our lists of keeps and loses so update our lists foreach (IItemOfInterest keep in keepAttentionObjects) //if we're keeping attention stop checking up on it { LosingAttentionObjects.Remove(keep); } foreach (IItemOfInterest lose in loseAttentionObjects) //if we've lost attention tell it so and remove it ////Debug.Log ("Finally lost attention of " + lose.name); { AttentionObjects.Remove(lose); lose.gameObject.SendMessage("OnLosePlayerAttention", SendMessageOptions.DontRequireReceiver); //stop checking up on it LosingAttentionObjects.Remove(lose); } } mCheckingAttentionItems = false; yield break; }
public IEnumerator SendPlayerToStartupPosition(PlayerStartupPosition startupPosition) { if (mSpawningPlayer) { //whoops yield break; } mSpawningPlayer = true; if (!GUILoading.IsLoading) { //let that go on its own, don't wait for it StartCoroutine(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack)); } //if the startup position is null //use the character's state as a startup position if (startupPosition == null) { //the player state should be not-null by now Debug.Log("Using player startup position"); startupPosition = Player.Local.GetStartupPosition(); } if (Player.Local.HasSpawned) { Player.Local.Despawn(); } //set the current spawn position CurrentStartupPosition = startupPosition; yield return(null); //set all existing world chunks to unclaimed mLoadingInfo = "Unloading chunks"; //suspend chunk loading so the player's position doesn't get the world confused GameWorld.Get.SuspendChunkLoading = true; for (int i = 0; i < GameWorld.Get.WorldChunks.Count; i++) { if (GameWorld.Get.WorldChunks [i].State.ID != startupPosition.ChunkID) { GameWorld.Get.WorldChunks [i].TargetMode = ChunkMode.Unloaded; } } //suspend worlditem loading so worlditems don't start spawning stuff till we're ready WorldItems.Get.SuspendWorldItemUpdates = true; //WorldItems.Get.SetAllWorldItemsToInvisible(); //wait a moment to let that sink in yield return(null); //put the player in the middle of the chunk to be loaded first WorldChunk startChunk = null; if (GameWorld.Get.ChunkByID(startupPosition.ChunkID, out startChunk)) { Player.Local.Position = startChunk.ChunkOffset + startupPosition.ChunkPosition.Position; } else { mLoadingInfo = "ERROR: Couldn't find startup chunk"; } //we send the player to the chunk / location specified in the world settings mLoadingInfo = "Sending player to startup position"; //re-enable chunk loading so everything can load GameWorld.Get.SuspendChunkLoading = false; WorldItems.Get.SuspendWorldItemUpdates = false; //set the primary chunk and let it load //put the player in the middle of the chunk to be loaded first mLoadingInfo = "Waiting for chunks to load"; while (!GameWorld.Get.ChunksLoaded) { yield return(null); } if (startupPosition.ForceUnloadAllNonPrimaryChunks) { Debug.Log("Force-unloading all primary chunks, structures, worlditems"); //unload all chunks except the primary chunk var unloadChunks = GameWorld.Get.UnloadAllChunks(startupPosition.ChunkID); while (unloadChunks.MoveNext()) { mLoadingInfo = "Unloading all chunks..."; yield return(unloadChunks.Current); } var unloadStructures = Structures.Get.UnloadAllStructures(); while (unloadStructures.MoveNext()) { mLoadingInfo = "Unloading all structures..."; yield return(unloadStructures.Current); } var unloadWorldItems = WorldItems.Get.UnloadAllWorldItems(); while (unloadWorldItems.MoveNext()) { mLoadingInfo = "Unloading all worlditems..."; yield return(unloadWorldItems.Current); } Resources.UnloadUnusedAssets(); } mLoadingInfo = "Chunks unloaded, setting primary chunk"; //set all the non-distant chunks to load GameWorld.Get.SetDistantChunks(Player.Local.Position); if (!GameWorld.Get.SetPrimaryChunk(startupPosition.ChunkID)) { mLoadingInfo = "Couldn't set primary chunk, halting load: " + startupPosition.ChunkID.ToString(); yield break; } //set the startup position so managers know where the player will end up startupPosition.WorldPosition.Position = (GameWorld.Get.PrimaryChunk.ChunkOffset + startupPosition.ChunkPosition.Position); startupPosition.WorldPosition.Rotation = startupPosition.ChunkPosition.Rotation; //set all the non-distant chunks to load GameWorld.Get.SetDistantChunks(startupPosition.WorldPosition.Position); //wait for the rest of the chunk to load while (GameWorld.Get.PrimaryChunk.CurrentMode != ChunkMode.Primary) { //turn on the camera so it starts rendering grass meshes //this will fight with camera FX but that's ok CameraFX.Get.Default.cam.enabled = true; CameraFX.Get.Default.cam.cullingMask = CameraFX.Get.Default.CullingMask; mLoadingInfo = "Waiting for primary chunk to load"; //Debug.Log("waiting for primary chunk to load"); yield return(null); } //initialize time if (startupPosition.RequiresStructure) { mLoadingInfo = "Loading structures"; yield return(StartCoroutine(SendPlayerToStructure( startupPosition.ChunkID, startupPosition.LocationReference, startupPosition.StructureName, startupPosition.Interior, startupPosition.ChunkPosition, startChunk.ChunkOffset))); } else { mLoadingInfo = "Loading location"; yield return(StartCoroutine(SendPlayerToLocation( startupPosition.ChunkID, startupPosition.LocationReference.GroupPath, startupPosition.LocationReference.FileName, startupPosition.ChunkPosition, startChunk.ChunkOffset, 0.1f))); //since we're not inside a structure //we could be standing on something //either a minor structure or chunk prefab if (startupPosition.RequiresMeshTerrain) { //wait for something to show up below the player before letting them go GameWorld.TerrainHeightSearch terrainHit = new GameWorld.TerrainHeightSearch(); terrainHit.feetPosition = startupPosition.WorldPosition.Position; terrainHit.groundedHeight = Globals.DefaultCharacterGroundedHeight; terrainHit.overhangHeight = Globals.DefaultCharacterHeight; bool foundSomethingBelowPlayer = false; double timeOut = WorldClock.RealTime + 30f; mLoadingInfo = "Waiting for mesh below player's feet"; while (WorldClock.RealTime < timeOut) { GameWorld.Get.TerrainHeightAtInGamePosition(ref terrainHit); //see if we hit a mesh if (terrainHit.hitTerrainMesh) { break; } yield return(null); } } } //immediately add the game offset if (startupPosition.AbsoluteTime) { WorldClock.ResetAbsoluteTime(); Profile.Get.CurrentGame.SetWorldTimeOffset( startupPosition.TimeHours, startupPosition.TimeDays, startupPosition.TimeMonths, startupPosition.TimeYears); } else { Profile.Get.CurrentGame.AddWorldTimeOffset( startupPosition.TimeHours, startupPosition.TimeDays, startupPosition.TimeMonths, startupPosition.TimeYears); } //unload anything we're not using //GC.Collect(); //Resources.UnloadUnusedAssets(); //yield return null; yield return(null); if (GUILoading.IsLoading) { StartCoroutine(GUILoading.LoadFinish()); } Player.Local.SpawnAtPosition(startupPosition.WorldPosition); mSpawningPlayer = false; yield break; }