public override void OnActivated() { if (IgnorePreviousVisits) { WIGroups.SuperLoadStackItem(LocationReference.GroupPath, LocationReference.FileName, new IWIBaseCallback(FinishCheckingPreviousVisits)); } }
protected IEnumerator SpawnInBedOverTime(MobileReference bedReference, Action <Bed> OnFinishAction) { if (mSpawningPlayer) { //whoops yield break; } mSpawningPlayer = true; CurrentStartupPosition = null; Bed loadedBed = null; mSpawnBedWorldItem = null; //super-load the item StartCoroutine(WIGroups.SuperLoadChildItem(bedReference.GroupPath, bedReference.FileName, SpawnBedLoaded, 0f)); while (mSpawnBedWorldItem == null || !mSpawnBedWorldItem.Is(WILoadState.Initialized)) { //waiting for bed yield return(null); } loadedBed = mSpawnBedWorldItem.Get <Bed> (); OnFinishAction(loadedBed); mSpawningPlayer = false; yield break; }
protected bool FindGuardCharacter() { if (GuardCharacter == null) { //use the guard node to get the character if (GuardNode.HasOccupant) { if (!GuardNode.Occupant.Is <Character> (out GuardCharacter) || GuardCharacter.IsDead) { //Debug.Log ("Couldn't get character from guard node occupant, quitting in " + name); return(false); } DailyRoutine dr = null; if (GuardNode.Occupant.Has <DailyRoutine> (out dr)) { //guard nodes don't get to have routines dr.Finish(); } } else { //Debug.Log ("Guard node didn't have occupant, quitting in " + name); WIGroup group = null; if (WIGroups.FindGroup(GuardNode.State.ParentGroupPath, out group)) { Characters.GetOrSpawnCharacter(GuardNode, GuardNode.State.OccupantName, group, out GuardCharacter); } return(GuardCharacter != null); } } return(true); }
public override void CheckIfCompleted() { if (mLoadingStackItem) { return; } WIGroups.SuperLoadStackItem(ItemReference.GroupPath, ItemReference.FileName, new IWIBaseCallback(FinishChecking)); }
public void Initialize( ) { name = Dungeon.ModuleName(ParentDungeon.name, ModuleNumber); OcclusionGroup.cullingGroupMasterName = name; if (Application.isPlaying) { ModuleGroup = WIGroups.GetOrAdd(name, ParentDungeon.DungeonGroup, null); } }
public void CreateDungeonGroup() { if (!HasDungeonGroup) { //create a dungeon group in the chunk's WI/BG group WIGroup belowGroundWorldItems = ParentChunk.Transforms.BelowGroundWorldItems.GetComponent <WIGroup> (); DungeonGroup = WIGroups.GetOrAdd(name, belowGroundWorldItems, null); DungeonGroup.Load(); } }
protected void CreateLocationGroup(bool load) { if (mLocationGroup == null) { mLocationGroup = WIGroups.GetOrAdd(gameObject, State.Name.FileName, worlditem.Group, worlditem); mLocationGroup.OnLoadStateChange += OnGroupLoadStateChange; } if (load) { mLocationGroup.Load(); } }
public IEnumerator DetectOverTime() { //get all the scripts that this affects List <WorldItem> detectedItems = new List <WorldItem>(); //start in the chunk group var getAllChildrenByType = WIGroups.GetAllChildrenByType( GameWorld.Get.PrimaryChunk.ChunkGroup.Props.PathName, Usage.TargetWIScriptNames, detectedItems, Player.Local.Position, EffectRadius, gMaxDetectedItems); while (getAllChildrenByType.MoveNext()) { yield return(getAllChildrenByType.Current); } //did we detect anything? if (detectedItems.Count > 0) { //tell these items to light up temporarily foreach (WorldItem detectedItem in detectedItems) { if (!string.IsNullOrEmpty(Usage.SendMessageArgument)) { detectedItem.SendMessage(Usage.SendMessageToTargetObject, Usage.SendMessageArgument, SendMessageOptions.DontRequireReceiver); } else { detectedItem.SendMessage(Usage.SendMessageToTargetObject, SendMessageOptions.DontRequireReceiver); } //spawn any vfx on detection if (!string.IsNullOrEmpty(Effects.FXOnSuccess)) { FXManager.Get.SpawnFX(detectedItem.transform.position, Effects.FXOnSuccess); if (!string.IsNullOrEmpty(Effects.FXOnSuccessMasteredBooster)) { //if we have a 'mastered' booster effect //spawn that if we've mastered FXManager.Get.SpawnFX(detectedItem.transform.position, Effects.FXOnSuccessMasteredBooster); } } double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 1f; while (Frontiers.WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } } OnSuccess(); } yield break; }
public override void OnActivated() { WorldItem structureWorldItem = null; StackItem structureStackitem = null; if (WIGroups.FindChildItem(StructurePath, out structureWorldItem)) { if (Player.Local.Surroundings.IsVisitingStructure(structureWorldItem.Get <Structure> ())) { HasCompleted = true; } } }
public void LookForDemolitionController( ) { WorldItem demolitionControllerWorldItem = null; if (WIGroups.FindChildItem(State.DemolitionControllerPath, out demolitionControllerWorldItem)) { DemolitionController = demolitionControllerWorldItem.Get <StructureDemolitionController> (); DemolitionController.AddDemolishable(this); //don't let our colliders turn off worlditem.ActiveState = WIActiveState.Active; worlditem.ActiveStateLocked = true; } }
protected IEnumerator SendPlayerToStructure(int chunkID, MobileReference locationReference, string structureName, bool interior, STransform chunkPosition, Vector3 chunkOffset) { mStartupStructure = null; StartCoroutine(WIGroups.SuperLoadChildItem( locationReference.GroupPath, locationReference.FileName, StartupStructureLoaded, 0f)); while (mStartupStructure == null) { yield return(null); } double startBuildTime = WorldClock.RealTime; mStartupStructure.LoadPriority = StructureLoadPriority.SpawnPoint; Structures.AddExteriorToLoad(mStartupStructure); while (!mStartupStructure.Is(StructureLoadState.ExteriorLoaded | StructureLoadState.InteriorLoading | StructureLoadState.InteriorLoaded)) { mLoadingInfo = "Waiting for exterior to build"; if ((WorldClock.RealTime - startBuildTime) > 60f) { mLoadingInfo = "Exterior build timeout!"; yield break; } yield return(null); } Structures.AddInteriorToLoad(mStartupStructure); startBuildTime = WorldClock.RealTime; while (!mStartupStructure.Is(StructureLoadState.InteriorLoaded)) { mLoadingInfo = "Waiting for interior to build"; if ((WorldClock.RealTime - startBuildTime) > 60f) { mLoadingInfo = "Interior build timeout!"; yield break; } yield return(null); } mLoadingInfo = "Interior structure is built"; Player.Local.Surroundings.StartupStructure = mStartupStructure; yield return(null); yield break; }
public bool HasItem(IWIBase item, out WIStack stack) { stack = null; if (mContainerEnabler == null) { return(false); } if (!mContainerEnabler.HasEnablerStack) { return(false); } WIStack nextStack = null; List <WIStack> enablerStacks = mContainerEnabler.EnablerStacks; for (int i = 0; i < enablerStacks.Count; i++) { nextStack = enablerStacks [i]; if (nextStack.Items.Contains(item)) { stack = nextStack; break; } } if (stack == null) { ShopOwner shopOwner = null; if (worlditem.Is <ShopOwner> (out shopOwner)) { //are we alive? if so, this can mean any containers that are owned by us in the group //start in the group that List <Container> containers = new List <Container> (); if (WIGroups.GetAllContainers(worlditem.Group, containers)) { foreach (Container container in containers) { if (Stacks.Find.Item(container.worlditem.StackContainer, item, out stack)) { Debug.Log("Found item in shop owner container"); break; } } } } } return(stack != null); }
public void CreateLocalPlayer() { PlayerIDFlag ID = PlayerIDFlag.Player01; //get remote ID GameObject localPlayerBaseObject = GameObject.Instantiate(LocalPlayerBasePrefab) as GameObject; localPlayerBaseObject.transform.parent = transform; localPlayerBaseObject.name = "LocalPlayer"; LocalPlayer localPlayer = localPlayerBaseObject.AddComponent <LocalPlayer>(); mPlayers.Add(ID, localPlayer); localPlayer.ID = ID; localPlayer.Group = WIGroups.GetOrAdd(ID.ToString(), WIGroups.Get.Player, localPlayer); localPlayer.Body = Characters.Get.PlayerBody(localPlayer); Local = localPlayer; //local player will initialize itself after finding/creating all its parts }
public PlayerBase CreateRemotePlayer(string remoteCharacterData) { //creates a remote player object //adds it to the lookup //creates its body //creates its group PlayerIDFlag ID = PlayerIDFlag.Player01; //get remote ID RemotePlayer remotePlayer = gameObject.CreateChild(ID.ToString()).gameObject.AddComponent <RemotePlayer>(); mPlayers.Add(ID, remotePlayer); remotePlayer.ID = ID; remotePlayer.Group = WIGroups.GetOrAdd(ID.ToString(), WIGroups.Get.Player, remotePlayer); remotePlayer.Body = Characters.Get.PlayerBody(remotePlayer); return(remotePlayer); //remote player will initialize itself after finding/creating all its parts }
public bool WaitForStructure( ) { if (TargetStructure == null) { WorldItem childItem = null; if (WIGroups.FindChildItem(TargetStructureReference.GroupPath, TargetStructureReference.FileName, out childItem)) { TargetStructure = childItem.Get <Structure> (); if (TargetStructure != null) { TargetStructure.worlditem.ActiveState = WIActiveState.Active; //TODO remove this lock, could be dangerous TargetStructure.worlditem.ActiveStateLocked = true; Structures.AddInteriorToLoad(TargetStructure); } else { Debug.LogError("Target structure " + TargetStructureReference.FullPath + " had no structure wiscript"); return(true); } } else { Debug.LogError("Couldn't find structure " + TargetStructureReference.FullPath); return(true); } } if (TargetStructure.Is(TargetLoadState)) { if (mPaddedStartTime < 0) { mPaddedStartTime = WorldClock.AdjustedRealTime + 1.5; return(true); } else if (WorldClock.AdjustedRealTime > mPaddedStartTime) { return(false); } } else { mPaddedStartTime = -1; } return(true); }
protected IEnumerator PostIntrospectionOverTime() { //wait for cutscenes / loading / etc. to finsih while (!GameManager.Is(FGameState.InGame) || !Player.Local.HasSpawned) { double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 0.1f; while (Frontiers.WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } } yield return(null); for (int i = 0; i < State.IntrospectionMessages.Count; i++) //if this is the last one, trigger the mission (if any) { if (i == State.IntrospectionMessages.Count - 1) { if (State.ActivateMission) { GUI.GUIManager.PostIntrospection(State.IntrospectionMessages[i], State.ActivatedMissionName, State.Delay); } else { GUI.GUIManager.PostIntrospection(State.IntrospectionMessages[i], State.Delay); } } else { GUI.GUIManager.PostIntrospection(State.IntrospectionMessages[i], State.Delay); } } if (State.PayAttentionToItem) { WorldItem attentionItem = null; if (WIGroups.FindChildItem(State.AttentionItem.GroupPath, State.AttentionItem.FileName, out attentionItem)) { Player.Local.Focus.GetOrReleaseAttention(attentionItem); } } mPostingIntrospectionOverTime = false; yield break; }
public override bool OnPlayerEnter() { if (mDimmingLanterns) { return(false); } if (LanternsToDim.Count == 0) { WorldItem lanternWorldItem = null; for (int i = 0; i < State.LanternsToDim.Count; i++) { MobileReference mr = State.LanternsToDim[i]; if (WIGroups.FindChildItem(mr.GroupPath, mr.FileName, out lanternWorldItem)) { LanternsToDim.Add(lanternWorldItem); } } if (State.LanternsToDim.Count == 0) { return(false); } } if (GuardInterventionTrigger == null) { WorldTriggerState wts = null; if (ParentChunk.GetTriggerState(State.GuardInterventionTriggerName, out wts)) { GuardInterventionTrigger = wts.trigger as TriggerGuardIntervention; } else { return(false); } } mDimmingLanterns = true; mStartTime = WorldClock.AdjustedRealTime; StartCoroutine(DimLanternsOverTime()); return(true); }
public override bool OnPlayerEnter() { if (TargetWorlditem == null) { if (!WIGroups.FindChildItem(State.WorlditemPath, out TargetWorlditem)) { return(false); } } if (!string.IsNullOrEmpty(State.OriginalState)) { if (TargetWorlditem.State != State.OriginalState) { return(false); } } TargetWorlditem.State = State.NewState; return(true); }
protected virtual void OnSuccess( ) { if (!string.IsNullOrEmpty(State.MissionName) && !string.IsNullOrEmpty(State.VariableNameOnSuccess)) { WorldItem itemToDestroy = null; for (int i = 0; i < State.WorldItemsToDestroy.Count; i++) { if (WIGroups.FindChildItem(State.WorldItemsToDestroy [i].FullPath, out itemToDestroy)) { itemToDestroy.RemoveFromGame(); } else { Debug.Log("Couldn't find child item " + State.WorldItemsToDestroy [i].FullPath); } } Missions.Get.ChangeVariableValue(State.MissionName, State.VariableNameOnSuccess, State.VariableValueOnSuccess, State.ChangeTypeOnSuccess); } }
public IEnumerator LoadChunkGroups() { ChunkGroup.Load(); while (!ChunkGroup.Is(WIGroupLoadState.Loaded)) { //be patient yield return(null); } if (WorldItemsGroup == null) { WorldItemsGroup = WIGroups.GetOrAdd(Transforms.WorldItems.gameObject, Transforms.WorldItems.name, ChunkGroup, null); } WorldItemsGroup.Load(); while (!WorldItemsGroup.Is(WIGroupLoadState.Loaded)) { //be patient yield return(null); } if (AboveGroundGroup == null) { AboveGroundGroup = WIGroups.GetOrAdd(Transforms.AboveGroundWorldItems.gameObject, Transforms.AboveGroundWorldItems.name, WorldItemsGroup, null); AboveGroundGroup.Props.IgnoreOnSave = true; AboveGroundGroup.Props.TerrainType = LocationTerrainType.AboveGround; } if (BelowGroundGroup == null) { BelowGroundGroup = WIGroups.GetOrAdd(Transforms.BelowGroundWorldItems.gameObject, Transforms.BelowGroundWorldItems.name, WorldItemsGroup, null); BelowGroundGroup.Props.IgnoreOnSave = true; BelowGroundGroup.Props.TerrainType = LocationTerrainType.BelowGround; } AboveGroundGroup.Load(); BelowGroundGroup.Load(); yield break; }
public void OnPlayerUseWorldItemSecondary(object secondaryResult) { WIListResult dialogResult = secondaryResult as WIListResult; switch (dialogResult.SecondaryResult) { case "Pluck": WIStackError error = WIStackError.None; WorldItem pluckedWorldItem = null; if (WorldItems.CloneWorldItem(PluckedItem, STransform.zero, false, WIGroups.GetCurrent(), out pluckedWorldItem)) { pluckedWorldItem.Initialize(); } Player.Local.Inventory.AddItems(pluckedWorldItem, ref error); creature.OnTakeDamage(); creature.FleeFromThing(Player.Local); break; default: break; } }
protected IEnumerator RevealAllOverTime() { Queue <StackItem> itemsToReveal = new Queue <StackItem> (); Debug.Log("Searching for items..."); yield return(StartCoroutine(WIGroups.GetAllStackItemsByType(WIGroups.Get.World.Path, new List <string> () { "Location" }, GroupSearchType.SavedOnly, itemsToReveal))); Debug.Log("Adding items to revealed list..."); while (itemsToReveal.Count > 0) { StackItem item = itemsToReveal.Dequeue(); if (item != null) { RevealedLocations.SafeAdd(item.StaticReference); } yield return(null); } Debug.Log("Done revealing"); }
public WIStack HoldTemporaryItem(WIStack stackToHold) { //create a temporary item stack if we don't have one if (mTemporaryItemEnabler == null) { if (CharacterInventoryGroup == null) { //if we don't have a character group, we'll need to create it to store our stuff CharacterInventoryGroup = WIGroups.GetOrAdd(worlditem.FileName, WIGroups.Get.World, worlditem); } //make sure the group is loaded CharacterInventoryGroup.Load(); mTemporaryItemEnabler = Stacks.Create.StackEnabler(CharacterInventoryGroup); mTemporaryItemEnabler.UseRawContainer = true; } else { //drop anything we're holding currently DropTemporaryItem(); } return(Stacks.Display.ItemsInContainer(stackToHold, mTemporaryItemEnabler.EnablerContainer)); }
protected IEnumerator WaitForBodiesOfWater() { bool waitForTop = !string.IsNullOrEmpty(State.TopBodyOfWaterPath); bool waitForBottom = !string.IsNullOrEmpty(State.BottomBodyOfWaterPath); while (waitForTop | waitForBottom) { if (waitForTop) { WorldItem bodyOfWaterWorlditem = null; if (WIGroups.FindChildItem(State.TopBodyOfWaterPath, out bodyOfWaterWorlditem)) { BodyOfWater bodyOfWater = bodyOfWaterWorlditem.Get <BodyOfWater> (); WaterfallTopFollow = bodyOfWater.WaterPivot.transform; waitForTop = false; } } if (waitForBottom) { WorldItem bodyOfWaterWorlditem = null; if (WIGroups.FindChildItem(State.BottomBodyOfWaterPath, out bodyOfWaterWorlditem)) { BodyOfWater bodyOfWater = bodyOfWaterWorlditem.Get <BodyOfWater> (); WaterfallBottomFollow = bodyOfWater.WaterPivot.transform; waitForBottom = false; } } double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 0.5f; while (Frontiers.WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } //Debug.Log ("Waiting for top / bottom: " + waitForTop.ToString () + " / " + waitForBottom.ToString ()); } enabled = true; yield break; }
protected IEnumerator SendPlayerToLocation(int chunkID, string locationPath, string locationName, STransform spawnPosition, Vector3 chunkOffset, float delay) { //save our target info for when the location loads mTargetSpawnPosition = ObjectClone.Clone <STransform> (spawnPosition); mTargetSpawnPosition.Position = chunkOffset + mTargetSpawnPosition.Position; mTargetLocationName = locationName; //set the primary chunk GameWorld.Get.SetPrimaryChunk(chunkID); //set all the non-distant chunks to load GameWorld.Get.SetDistantChunks(mTargetSpawnPosition.Position); while (GameWorld.Get.PrimaryChunk.CurrentMode != ChunkMode.Primary) { mLoadingInfo = "Waiting for primary chunk to load"; //Debug.Log("Waiting for primary chunk to load"); yield return(null); } //use a SuperLoader to load the location yield return(WIGroups.SuperLoadChildItem(locationPath, locationName, null, delay)); //alright! we've found the location //now we can send the player to our target position and spawn //send the player to the target position yield break; }
//searches chunks and loads location data into the locationData list //only searches for locations added using the SetMapData function public IEnumerator LocationsForChunks(string chunkName, int chunkID, Queue <WorldMapLocation> locationData, List <MapMarker> activeMapMarkers) { //Debug.Log ("WorldMap: LocationsForChunks"); List <MobileReference> locationList = null; if (!mRevealableToShow.TryGetValue(chunkName, out locationList)) { //Debug.Log ("WorldMap: We have no locations for this chunk from SetMapData, returning immediately"); yield break; } Vector3 chunkPosition; //add markers for (int i = 0; i < activeMapMarkers.Count; i++) { if (activeMapMarkers [i].ChunkID == chunkID) { chunkPosition = activeMapMarkers [i].ChunkPosition; WorldMapLocation wml = new WorldMapLocation( null, 1, "Marker", string.Empty, string.Empty, true, false, "MapIconMapMarker", Color.white, MapIconStyle.Medium, MapLabelStyle.None, Vector3.zero, chunkPosition, false, false, LocationTypesToDisplay); locationData.Enqueue(wml); } } MobileReference currentLocation = null; for (int i = 0; i < locationList.Count; i++) { if (!LoadData) { //Debug.Log ("WorldMap: Load data is false, returning"); yield break; } currentLocation = locationList [i]; StackItem stackItem = null; if (WIGroups.LoadStackItem(currentLocation, out stackItem)) { chunkPosition = stackItem.ChunkPosition; //Debug.Log ("WorldMap: found stack item " + stackItem.DisplayName); //next we need to get the location state from the stack item LocationState ls = null; RevealableState rs = null; VisitableState vs = null; bool isNewLocation = false; bool isMarked = false; if (NewLocations.Count > 0) { for (int j = NewLocations.LastIndex(); j >= 0; j--) { if (NewLocations [j] == currentLocation) { NewLocations.RemoveAt(j); isNewLocation = true; break; } } } //Debug.Log ("current location " + currentLocation.FullPath + " is marked? " + isMarked.ToString ( )); isMarked = MarkedLocations.Contains(currentLocation); if (stackItem.GetStateData <RevealableState> (out rs)) { stackItem.GetStateData <LocationState> (out ls); stackItem.GetStateData <VisitableState> (out vs); //now convert it into a world map location WorldMapLocation wml = null; if (rs.CustomMapSettings || ls == null) { //non-custom settings come from the location //so we can only use custom settings if ls is not null //Debug.Log ("Custom settings for revealable with " + rs.IconName + " icon name"); wml = new WorldMapLocation( currentLocation, stackItem.Props.Local.ActiveRadius, ls != null ? ls.Name.CommonName : string.Empty, ls != null ? ls.Name.ProperName : string.Empty, ls != null ? ls.Name.NickName : string.Empty, vs != null ? vs.HasBeenVisited : true, rs.MarkedForTriangulation, rs.IconName, rs.IconColor, rs.IconStyle, rs.LabelStyle, rs.IconOffset, chunkPosition, isNewLocation, isMarked, LocationTypesToDisplay); locationData.Enqueue(wml); } else { string iconName = "Outpost"; MapIconStyle iconStyle = MapIconStyle.None; MapLabelStyle labelStyle = MapLabelStyle.None; Color32 iconColor = Color.gray; Vector3 iconOffset = Vector3.zero; GetIconProperties(stackItem, ls, rs, vs, ref iconName, ref iconStyle, ref labelStyle, ref iconColor, ref iconOffset); wml = new WorldMapLocation( currentLocation, stackItem.Props.Local.ActiveRadius, ls != null ? ls.Name.CommonName : string.Empty, ls != null ? ls.Name.ProperName : string.Empty, ls != null ? ls.Name.NickName : string.Empty, vs != null ? vs.HasBeenVisited : true, rs.MarkedForTriangulation, iconName, iconColor, iconStyle, labelStyle, iconOffset, chunkPosition, isNewLocation, isMarked, LocationTypesToDisplay); locationData.Enqueue(wml); } } else { //Debug.Log ("Didn't get revealable state data in " + currentLocation.FileName); } } else { //Debug.Log ("Didin't get stack item for location " + currentLocation.FullPath); } //clear the stack item, we don't need it any more if (stackItem != null) { stackItem.Clear(); } yield return(null); } locationList.Clear(); yield break; }
protected IEnumerator UpdateTransitionOverTime() { //player sets off an explosion FXManager.Get.SpawnExplosionFX(State.ExplosionFXType, transform, State.ExplosionPosition); MasterAudio.PlaySound(State.ExplosionSoundType, transform, State.ExplosionSound); Player.Local.Audio.Cough(); //explosion makes them go blind CameraFX.Get.SetBlind(true); CameraFX.Get.AddDamageOverlay(1f); double waitUntil = WorldClock.AdjustedRealTime + State.CharacterDTSDelay; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } //robert says some DTS Frontiers.GUI.NGUIScreenDialog.AddSpeech(State.CharacterDTSText, State.CharacterDTSName, State.CharacterDTSDuration); Player.Local.Audio.Cough(); Player.Local.MovementLocked = true; //force the two camps to rebuild for (int i = 0; i < State.ForceRebuildLocations.Count; i++) { WorldItem activeLocation = null; if (WIGroups.FindChildItem(State.ForceRebuildLocations[i], out activeLocation)) { activeLocation.Get <MissionInteriorController>().ForceRebuild(); } else { Debug.Log("Couldn't load location " + State.ForceRebuildLocations[i]); } } //wait for a bit while that settles in waitUntil = WorldClock.AdjustedRealTime + State.CharacterDTSDuration; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } //player is moved to temple entrance GameWorld.Get.ShowAboveGround(true); Player.Local.Surroundings.ExitUnderground(); waitUntil = WorldClock.AdjustedRealTime + 0.1f; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } //give gameworld a sec to catch up //lock the player's position for a moment //kill the guard at the temple door WorldTriggerState triggerState = null; List <WorldTrigger> triggers = GameWorld.Get.PrimaryChunk.Triggers; for (int i = 0; i < triggers.Count; i++) { if (triggers[i].name == "TriggerWarlockCampGuardIntervention") { //get the trigger and kill the guard //(due to the cave-in) TriggerGuardIntervention tgi = triggers[i].GetComponent <TriggerGuardIntervention>(); tgi.KillGuard(); break; } } Player.Local.Position = State.PlayerWakeUpPosition; //blindness goes away CameraFX.Get.SetBlind(false); //as the player wakes up have him look at Robert Player.Local.HijackControl(); double startHijackedTime = WorldClock.AdjustedRealTime; HijackedPosition = gameObject.CreateChild("HijackedPosition"); HijackedLookTarget = gameObject.CreateChild("HijackedLookTarget"); HijackedPosition.position = State.PlayerWakeUpPosition; HijackedLookTarget.position = State.PlayerWakeUpLookTarget; while (WorldClock.AdjustedRealTime < startHijackedTime + State.HijackedTimeDuration) { Player.Local.SetHijackTargets(HijackedPosition, HijackedLookTarget); yield return(null); } Character character = null; if (!Characters.Get.SpawnedCharacter("Robert", out character)) { //spawn Robert if we haven't already CharacterSpawnRequest spawnRequest = new CharacterSpawnRequest(); spawnRequest.ActionNodeName = "RobertPiecesTempleSpawn"; spawnRequest.FinishOnSpawn = true; spawnRequest.CharacterName = "Robert"; spawnRequest.MinimumDistanceFromPlayer = 3f; spawnRequest.SpawnBehindPlayer = false; spawnRequest.UseGenericTemplate = false; spawnRequest.CustomConversation = "Robert-Enc-Act-02-Pieces-05"; Player.Local.CharacterSpawner.AddSpawnRequest(spawnRequest); } Player.Local.RestoreControl(true); Player.Local.MovementLocked = false; GameObject.Destroy(HijackedPosition.gameObject, 0.5f); GameObject.Destroy(HijackedLookTarget.gameObject, 0.5f); //and we're done! yield break; }
protected IEnumerator FindValuablesOverTime() { //give ourselves a second before looking for a flower double waitUntil = WorldClock.AdjustedRealTime + 1f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } while (!mDestroyed) { while (WorldClock.AdjustedRealTime < StartleTimeEnd) { yield return(null); } while (GameWorld.Get.PrimaryChunk == null || GameWorld.Get.PrimaryChunk.AboveGroundGroup == null) { yield return(null); } if (CurrentValuable == null) { List <WorldItem> valuables = new List <WorldItem> (); //find something between the player and the critter, closer if it's friendlier //TODO make this work in immediate groups var searchEnum = WIGroups.GetAllChildrenByTypeInLocation(GameWorld.Get.PrimaryChunk.AboveGroundGroup.Path, ValuableScripts, valuables, Position, SearchRadius, false, 1); while (searchEnum.MoveNext()) { yield return(searchEnum.Current); } if (valuables.Count > 0) { valuableIsHeldByPlayer = false; CurrentValuable = valuables [0]; mCurrentValuablePosition = valuables [0].worlditem.FocusPosition; mRandomValuablePosition = valuables [0].worlditem.FocusPosition; } } if (CurrentValuable == null) { //find something between the player and the critter, closer if it's friendlier //TODO make this work in immediate groups List <WorldItem> valuables = WIGroups.Get.Player.GetChildrenOfType(ValuableScripts); if (valuables.Count > 0) { valuableIsHeldByPlayer = true; CurrentValuable = valuables [0]; mCurrentValuablePosition = valuables [0].worlditem.FocusPosition; mRandomValuablePosition = valuables [0].worlditem.FocusPosition; } } waitUntil = WorldClock.AdjustedRealTime + 1.5f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } yield return(null); } }
//this function is meant to be used with the HouseOfHealing skill //i've only been able to get this process to work a few times //the idea is to super-load the last visited HOH //then load its interior and put the player in one of its beds //great in theory but in practice something always f***s up protected IEnumerator SpawnInClosestStructureOverTime(Vector3 despawnPosition, List <MobileReference> structureReferences, Action <Bed> OnFinishAction) { if (mSpawningPlayer) { //whoops yield break; } mSpawningPlayer = true; CurrentStartupPosition = null; float closestDistanceSoFar = Mathf.Infinity; StackItem closestStructureStateSoFar = null; StackItem currentStructureState = null; MobileReference currentStructureReference = null; MobileReference closestStructureReferenceSoFar = null; Vector3 closestStructurePositionSoFar = despawnPosition; WorldChunk currentChunk = null; //find out which structure is the closest for (int i = 0; i < structureReferences.Count; i++) { currentStructureReference = structureReferences [i]; //Debug.Log ("SPAWNMANAGER: Checking structure reference " + currentStructureReference.FullPath.ToString ()); if (WIGroups.LoadStackItem(currentStructureReference, out currentStructureState)) { if (currentStructureState.Is <Structure> ()) { //get the chunk for this item if (GameWorld.Get.ChunkByID(currentStructureReference.ChunkID, out currentChunk)) { Vector3 structureWorldPosition = WorldChunk.ChunkPositionToWorldPosition(currentChunk.ChunkBounds, currentStructureState.ChunkPosition); structureWorldPosition += currentChunk.ChunkOffset; float currentDistance = Vector3.Distance(despawnPosition, structureWorldPosition); if (currentDistance < closestDistanceSoFar) { closestDistanceSoFar = currentDistance; closestStructureStateSoFar = currentStructureState; closestStructureReferenceSoFar = currentStructureReference; closestStructurePositionSoFar = structureWorldPosition; } } } } } if (closestStructureStateSoFar == null) { yield break; } //move the player to the position of the new item //this will help us to super-load the structure Player.Local.Position = closestStructurePositionSoFar; //reset the current loading structure mSpawnStructureWorldItem = null; Structure spawnStructure = null; Bed loadedBed = null; //super-load the item //yield return null; //WorldItems.Get.SuspendActiveStateChecking = true; StartCoroutine(WIGroups.SuperLoadChildItem(closestStructureReferenceSoFar.GroupPath, closestStructureReferenceSoFar.FileName, SpawnStructureLoaded, 0f)); WIGroup lastGroupLoaded = null; while (mSpawnStructureWorldItem == null) { yield return(null); } //WorldItems.Get.SuspendActiveStateChecking = false; //okay next we have to load the structure interior mSpawnStructureWorldItem.ActiveStateLocked = false; mSpawnStructureWorldItem.ActiveState = WIActiveState.Active; mSpawnStructureWorldItem.ActiveStateLocked = true; yield return(null); //now that the player is where they're supposed to be we can resume active state checking //but keep the structure itself locked //Player.Local.Position = mSpawnStructureWorldItem.Position; //ColoredDebug.Log ("Sending player to spawn structure position " + mSpawnStructureWorldItem.Position.ToString (), "Yellow"); spawnStructure = mSpawnStructureWorldItem.Get <Structure> (); spawnStructure.LoadPriority = StructureLoadPriority.SpawnPoint; if (spawnStructure.Is(StructureLoadState.ExteriorUnloaded)) { yield return(StartCoroutine(spawnStructure.CreateStructureGroups(StructureLoadState.ExteriorLoaded))); Structures.AddExteriorToLoad(spawnStructure); while (spawnStructure.Is(StructureLoadState.ExteriorLoading | StructureLoadState.ExteriorWaitingToLoad)) { yield return(null); } } if (spawnStructure.Is(StructureLoadState.ExteriorLoaded)) { Structures.AddInteriorToLoad(spawnStructure); while (spawnStructure.Is(StructureLoadState.InteriorWaitingToLoad | StructureLoadState.InteriorLoading)) { yield return(null); } spawnStructure.RefreshColliders(true); spawnStructure.RefreshRenderers(true); //finally we search for a bed } spawnStructure.StructureGroup.Load(); while (!spawnStructure.StructureGroup.Is(WIGroupLoadState.Loaded)) { yield return(null); } yield return(null); //wait a tick to let the group catch up //wait a tick to let the group catch up yield return(null); List <WorldItem> bedWorldItems = new List <WorldItem> (); while (bedWorldItems.Count == 0) { yield return(StartCoroutine(WIGroups.GetAllChildrenByType(spawnStructure.StructureGroup.Props.PathName, new List <string> () { "Bed" }, bedWorldItems, spawnStructure.worlditem.Position, Mathf.Infinity, 1))); //can't use WaitForSeconds because timescale will be zero double waitUntil = WorldClock.RealTime + 0.1f; while (WorldClock.RealTime < waitUntil) { yield return(null); } } WorldItem bedWorldItem = bedWorldItems [0]; while (!bedWorldItem.Is(WILoadState.Initialized)) { yield return(null); } loadedBed = bedWorldItem.Get <Bed> (); //Player.Local.Position = loadedBed.BedsidePosition; mSpawningPlayer = false; mSpawnStructureWorldItem.ActiveStateLocked = false; OnFinishAction(loadedBed); Player.Local.Surroundings.StructureEnter(spawnStructure); yield break; }
public void Initialize() { //this just creates a basic chunk object if (mInitialized) { return; } mChunkName = ChunkName(State); mChunkDataDirectory = ChunkDataDirectory(mChunkName); gameObject.name = mChunkName; //initialize assumes that the chunk state has been loaded transform.position = State.TileOffset; ChunkGroup = WIGroups.GetOrAdd(gameObject, mChunkName, WIGroups.Get.World, null); ChunkGroup.Props.IgnoreOnSave = true; Transforms.WorldItems.gameObject.SetActive(true); Transforms.AboveGroundWorldItems.gameObject.SetActive(true); Transforms.BelowGroundWorldItems.gameObject.SetActive(true); Transforms.AboveGroundStaticDistant.gameObject.SetActive(true); Mods.Get.Runtime.LoadMod <ChunkTriggerData> (ref TriggerData, mChunkDataDirectory, "Triggers"); Mods.Get.Runtime.LoadMod <ChunkNodeData> (ref NodeData, mChunkDataDirectory, "Nodes"); //Mods.Get.Runtime.LoadMod <ChunkSceneryData> (ref SceneryData, mChunkDataDirectory, "Scenery"); Mods.Get.Runtime.LoadMod <ChunkTerrainData> (ref TerrainData, mChunkDataDirectory, "Terrain"); /*for (int i = 0; i < SceneryData.AboveGround.RiverNames.Count; i++) { * //Debug.Log("Loading river " + SceneryData.AboveGround.RiverNames[i]); * River river = null; * if (Mods.Get.Runtime.LoadMod <River> (ref river, "River", SceneryData.AboveGround.RiverNames [i])) { * Rivers.Add (river); * } * }*/ CalculateBounds(); mChunkScale.Set(State.SizeX, Globals.ChunkMaximumYBounds, State.SizeZ); //load tree data if (Mods.Get.Runtime.LoadMod <ChunkTreeData> (ref TreeData, mChunkDataDirectory, "Trees")) { //update our tree instances with our offset and create our quad tree //make sure not to use the TreeInstances convenience property for (int i = 0; i < TreeData.TreeInstances.Length; i++) { TreeInstanceTemplate tit = TreeData.TreeInstances [i]; tit.ParentChunk = this; tit.ChunkOffset = ChunkOffset; tit.ChunkScale = ChunkScale; } TreeInstanceQuad = new QuadTree <TreeInstanceTemplate> ( ChunkBounds, Math.Max(TreeInstances.Length / QuadTreeMaxContentScaler, QuadTreeMaxContentMinimum), TreeData.TreeInstances); } //load plant data //make sure not to use the PlantInstances convenience property //it will return an empty array if (Mods.Get.Runtime.LoadMod <ChunkPlantData> (ref PlantData, mChunkDataDirectory, "Plants")) { for (int i = 0; i < PlantData.PlantInstances.Length; i++) { PlantInstanceTemplate pit = PlantData.PlantInstances [i]; pit.HasInstance = false; pit.ChunkOffset = ChunkOffset; pit.ChunkScale = ChunkScale; pit.ParentChunk = this; } PlantInstanceQuad = new QuadTree <PlantInstanceTemplate> ( ChunkBounds, Math.Max(PlantData.PlantInstances.Length / QuadTreeMaxContentScaler, QuadTreeMaxContentMinimum), PlantData.PlantInstances); } //Dictionary <string,Texture2D> matChunkMaps = new Dictionary <string, Texture2D> (); for (int groundIndex = 0; groundIndex < TerrainData.TextureTemplates.Count; groundIndex++) { TerrainTextureTemplate ttt = TerrainData.TextureTemplates [groundIndex]; Texture2D Diffuse = null; if (Mats.Get.GetTerrainGroundTexture(ttt.DiffuseName, out Diffuse)) { ChunkDataMaps.Add("Ground" + groundIndex.ToString(), Diffuse); } } ChunkDataMaps.Add("ColorOverlay", PrimaryTerrain.materialTemplate.GetTexture("_CustomColorMap") as Texture2D); ChunkDataMaps.Add("Splat1", PrimaryTerrain.materialTemplate.GetTexture("_Splat2") as Texture2D); ChunkDataMaps.Add("Splat2", PrimaryTerrain.materialTemplate.GetTexture("_Splat2") as Texture2D); Texture2D chunkMap = null; //Debug.Log ("Getting terrain color overlay in " + Name); /*if (Mods.Get.Runtime.ChunkMap (ref chunkMap, Name, "ColorOverlay")) { * ChunkDataMaps.Add ("ColorOverlay", chunkMap); * }*/ if (GameWorld.Get.ChunkMap(ref chunkMap, Name, "AboveGroundTerrainType")) { ChunkDataMaps.Add("AboveGroundTerrainType", chunkMap); } if (GameWorld.Get.ChunkMap(ref chunkMap, Name, "BelowGroundTerrainType")) { ChunkDataMaps.Add("BelowGroundTerrainType", chunkMap); } if (GameWorld.Get.ChunkMap(ref chunkMap, Name, "RegionData")) { ChunkDataMaps.Add("RegionData", chunkMap); } /*if (Mods.Get.Runtime.ChunkMap (ref chunkMap, Name, "Splat1")) { * ChunkDataMaps.Add ("Splat1", chunkMap); * } * if (Mods.Get.Runtime.ChunkMap (ref chunkMap, Name, "Splat2")) { * ChunkDataMaps.Add ("Splat2", chunkMap); * }*/ //now start coroutines that load the nodes CreateNodesAndTriggers(); //activate the main terrain PrimaryTerrain.gameObject.layer = Globals.LayerNumSolidTerrain; PrimaryTerrain.enabled = true; PrimaryCollider = PrimaryTerrain.GetComponent <TerrainCollider>(); //set the static objects DetailPrototype[] details = PrimaryTerrain.terrainData.detailPrototypes; for (int i = 0; i < details.Length; i++) { if (details[i].usePrototypeMesh) { if (details[i].renderMode == DetailRenderMode.VertexLit) { details[i].renderMode = DetailRenderMode.Grass; } if (details[i].prototype == null) { Debug.Log("DETAIL " + i + " WAS NULL IN CHUNK " + name); } else if (details[i].prototype.name.Contains("Static")) { details[i].dryColor = Colors.Alpha(details[i].dryColor, 0f); details[i].healthyColor = Colors.Alpha(details[i].healthyColor, 0f); } } } PrimaryTerrain.terrainData.detailPrototypes = details; //remove plant instance prefab, replace it with an empty one TreePrototype[] treePrototypes = PrimaryTerrain.terrainData.treePrototypes; for (int i = 0; i < treePrototypes.Length; i++) { if (treePrototypes[i].prefab == Plants.Get.PlantInstancePrefab) { treePrototypes[i].prefab = Plants.Get.RuntimePlantInstancePrefab; } } PrimaryTerrain.terrainData.treePrototypes = treePrototypes; if (ColliderTemplates != null) { Array.Clear(ColliderTemplates, 0, ColliderTemplates.Length); ColliderTemplates = null; Plants.Get.GetTerrainPlantPrototypes(treePrototypes, ref ColliderTemplates); } /*if (!GameManager.Get.NoTreesMode) { * TreePrototype[] treePrototypes = null; * if (ColliderTemplates != null) { * Array.Clear(ColliderTemplates, 0, ColliderTemplates.Length); * ColliderTemplates = null; * } * //Debug.Log("Getting tree prototypes for " + Name); * Plants.Get.GetTerrainPlantPrototypes(TerrainData.TreeTemplates, TreeData.TreeInstances, ref treePrototypes, ref ColliderTemplates); * //PrimaryTerrain.terrainData.treePrototypes = treePrototypes; * }*/ //turn everything off initially Transforms.AboveGroundStaticImmediate.gameObject.SetActive(false); Transforms.AboveGroundStaticAdjascent.gameObject.SetActive(false); Transforms.AboveGroundStaticDistant.gameObject.SetActive(false); Transforms.BelowGroundStatic.gameObject.SetActive(false); mInitialized = true; }