public void Update() { if (Input.GetKeyDown(KeyCode.Y)) { CreatureDen creatureDen = null; WIGroup group = null; if (Player.Local.Surroundings.IsVisitingLocation) { foreach (Location location in Player.Local.Surroundings.VisitingLocations) { if (location.worlditem.Is <CreatureDen> (out creatureDen)) { group = location.LocationGroup; break; } } } if (creatureDen != null) { Creature creature = null; Debug.Log("Spawning dead creature in den " + creatureDen.name); SpawnCreature(creatureDen, group, Vector3.up * 3, true, "Nothing", 0f, out creature); creature.worlditem.tr.parent = group.tr; creature.worlditem.tr.localPosition = Vector3.up * 3; } } }
protected IEnumerator SendPlayerToActionNode(int chunkID, string actionNodeName, float delay) { if (!GUILoading.IsLoading) { yield return(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack)); } Player.Local.Despawn(); //start off by setting the primary chunk GameWorld.Get.SetPrimaryChunk(chunkID); //action nodes won't exist unless it's primary while (GameWorld.Get.PrimaryChunk.CurrentMode != ChunkMode.Primary) //wait for the chunk to load before we send it there //Debug.Log("Waiting for primary chunk to load"); { yield return(null); } ActionNodeState nodeState = null; if (GameWorld.Get.PrimaryChunk.GetNode(actionNodeName, false, out nodeState)) { //send player to location string locationPath = WIGroup.AllButLastInPath(nodeState.ParentGroupPath); string locationName = WIGroup.LastInPath(nodeState.ParentGroupPath); STransform spawnPosition = nodeState.Transform; if (nodeState.IsLoaded) { spawnPosition = new STransform(nodeState.actionNode.transform, false); } yield return(StartCoroutine(SendPlayerToLocation(chunkID, locationPath, locationName, spawnPosition, GameWorld.Get.PrimaryChunk.ChunkOffset, delay))); } if (GUILoading.IsLoading) { yield return(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack)); } yield break; }
public ActionNode SpawnActionNode(WIGroup group, ActionNodeState actionNodeState, Transform nodeParentTransform) { ActionNode actionNode = null; if (!actionNodeState.IsLoaded) { GameObject newNodeGameObject = nodeParentTransform.gameObject.CreateChild(actionNodeState.FullName).gameObject; actionNode = newNodeGameObject.AddComponent <ActionNode> (); actionNode.State = actionNodeState; //since we're spawning this in the chunk we have to apply the group's transforms to the node actionNode.State.Transform.ApplyTo(actionNode.transform); //now move it to the final point actionNode.transform.parent = Transforms.Nodes; actionNode.State.actionNode = actionNode; } else { actionNode = actionNodeState.actionNode; } //add the action node state to the lookup actionNodeState.ParentGroupPath = group.Path; List <ActionNodeState> nodeStates = null; if (!NodeData.NodeStates.TryGetValue(group.Path, out nodeStates)) { nodeStates = new List <ActionNodeState> (); NodeData.NodeStates.Add(group.Path, nodeStates); } nodeStates.SafeAdd(actionNodeState); return(actionNode); }
public void AddChildGroup(WIGroup group) { MaxDepth = Mathf.Max(MaxDepth, group.Depth); AddedChildGroup = WorldClock.RealTime; switch (group.LoadState) { //we may have to back up a few steps for this to work case WIGroupLoadState.Uninitialized: case WIGroupLoadState.Initializing: case WIGroupLoadState.Initialized: case WIGroupLoadState.PreparingToLoad: case WIGroupLoadState.Loading: case WIGroupLoadState.Loaded: case WIGroupLoadState.PreparingToUnload: default: NotPreparedToUnload.SafeAdd(group); break; case WIGroupLoadState.Unloading: Unloading.SafeAdd(group); break; case WIGroupLoadState.Unloaded: ReadyToDestroy.SafeAdd(group); 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); }
//you can only make a load request with a live group //even if that request ends up being fulfilled for a destroyed group public WIGroupLoadRequest(WIGroup group) { Group = group; GroupPath = Group.Path; UniqueID = Group.Props.UniqueID; TimeAdded = WorldClock.AdjustedRealTime; OnHold = false; }
public IEnumerator LoadGroupsOverTime() { Debug.Log("Superloading path " + GroupPath); if (string.IsNullOrEmpty(GroupPath)) { Debug.Log("Path was empty!"); OnFinish(); yield break; } GroupsToLoad = WIGroup.SplitPath(GroupPath); //pop the first - it will be the root GroupsToLoad.Pop(); LastGroupLoaded = WIGroups.Get.Root; LastGroupLoaded.Load(); if (GroupsToLoad.Count > 0) { NextGroupToLoad = GroupsToLoad.Peek(); //start at the root and then load the groups all the way down //we'll keep loading groups until we've loaded everything in the stack while (GroupsToLoad.Count > 0) { State = "Loading group"; WIGroup nextGroup = null; while (!LastGroupLoaded.Is(WIGroupLoadState.Loaded) || !LastGroupLoaded.GetChildGroup(out nextGroup, NextGroupToLoad)) { Debug.Log("Last group " + LastGroupLoaded.name + " loaded? " + LastGroupLoaded.Is(WIGroupLoadState.Loaded).ToString() + "\n" + "Child group available? " + LastGroupLoaded.GetChildGroup(out nextGroup, NextGroupToLoad).ToString()); State = "Waiting for child group " + NextGroupToLoad; Ticks++; yield return(null); } //now that it has its child items, tell it to load its child groups LastGroupLoaded = nextGroup; GroupsToLoad.Pop(); if (GroupsToLoad.Count > 0) { NextGroupToLoad = GroupsToLoad.Peek(); Ticks++; yield return(null); } } yield return(null); //now we search the group to see if it holds the child item we're looking for while (!LastGroupLoaded.FindChildItem(ChildItemFileName, out LoadedWorldItem)) { //LastGroupLoaded.State = WIGroupState.ForceLoad; Ticks++; State = "Waiting for child item " + ChildItemFileName; yield return(null); } } //finished! OnFinish(); yield break; }
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(); } }
public void BuildTransition(StructureTemplateGroup dungeonTransitionGroup, WIGroup dungeonGroup) { //then add the children for (int j = 0; j < dungeonTransitionGroup.StaticStructureLayers.Count; j++) { StructureTemplate.InstantiateStructureLayer(dungeonTransitionGroup.StaticStructureLayers [j], transform); } //create and find triggers StructureTemplate.InstantiateGenericDynamic(dungeonTransitionGroup.GenericDynamic, TriggerParent, dungeonGroup); }
public WIGroupUnloader(WIGroup rootGroup) { RootGroup = rootGroup; TimeStarted = WorldClock.RealTime; NotPreparedToUnload = new List <WIGroup> (); PreparingToUnload = new List <WIGroup> (); ReadyToUnload = new List <WIGroup> (); Unloading = new List <WIGroup> (); FinishedUnloading = new List <WIGroup> (); ReadyToDestroy = new List <WIGroup> (); }
public bool GetOrCreateNode(WIGroup group, Transform parentTransform, string nodeName, out ActionNodeState nodeState) { nodeState = null; if (GetNode(nodeName, false, out nodeState)) { return(true); } else { nodeState = new ActionNodeState(); nodeState.Name = nodeName; SpawnActionNode(group, nodeState, parentTransform); } return(nodeState != null); }
public void OnVisible() { //the spawner will take care of creating any NEW creatures //this function will take care of re-spawning any saved creatures Location location = null; if (worlditem.Is <Location>(out location)) { WIGroup group = location.LocationGroup; if (!string.IsNullOrEmpty(State.DenStructure.TemplateName)) { Structures.AddMinorToload(State.DenStructure, 0, worlditem); } } }
public static Signboard AddBar(Signboard newSign, WorldItem owner, WIGroup locationGroup, STransform offset, string textureName) { newSign = GetOrCreateSignboard(newSign, owner, locationGroup, offset, textureName, "Bar"); switch (newSign.Style) { case SignboardStyle.A: default: Get.BarASignboards.SafeAdd(newSign); break; case SignboardStyle.B: Get.BarBSignboards.SafeAdd(newSign); break; } return(newSign); }
public virtual void TryToRemoveItem(IStackOwner skillUseTarget, WIStack fromStack, WIStack toStack, WIGroup toGroup, Action callBack, int flavor) { LastInventory = null; LastFromStack = fromStack; LastToStack = toStack; LastToGroup = toGroup; LastCallback = callBack; //make sure the item we're moving isn't immune to our skill if (!CheckForSkillImmunity(fromStack.TopItem, this, out mImmunityMessage)) { GUIManager.PostDanger(mImmunityMessage); FailImmediately(); return; } //use the skill against the target Use(skillUseTarget.worlditem, LastSkillFlavor); }
public static bool SpawnCreature(CreatureDen den, WIGroup group, Vector3 spawnPosition, bool isDead, string causeOfDeath, float timeSinceDeath, out Creature newCreature) { if (Globals.MissionDevelopmentMode) { //we don't care about creatures in mission dev mode newCreature = null; return(false); } newCreature = null; CreatureTemplate template = null; if (mTemplateLookup.TryGetValue(den.State.NameOfCreature.ToLower().Trim(), out template)) { WorldItem newCreatureWorldItem = null; if (WorldItems.CloneFromPrefab(Get.CreatureBase.GetComponent <WorldItem> (), group, out newCreatureWorldItem)) { //since this is the first time the creature is spawned //it has no idea what it is //so before we send it back we're going to set its template name newCreature = newCreatureWorldItem.gameObject.GetOrAdd <Creature> (); newCreature.State.TemplateName = template.Name; newCreature.Template = template; if (isDead) { Debug.Log("Spawning dead creature"); newCreature.State.IsDead = true; Damageable damageable = newCreature.GetComponent <Damageable> (); damageable.State.CauseOfDeath = causeOfDeath; damageable.State.DamageTaken = damageable.State.Durability; damageable.State.TimeKilled = WorldClock.AdjustedRealTime - timeSinceDeath; } else { newCreature.State.IsDead = false; } newCreature.Den = den; newCreatureWorldItem.Props.Local.Transform.Position = spawnPosition; newCreatureWorldItem.Props.Local.Transform.Rotation.y = UnityEngine.Random.Range(0f, 360f); //Debug.Log ("Setting position of creature to " + spawnPosition.ToString ()); } } //and that's it! the rest will be taken care of by the creature return(newCreature != null); }
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 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)); }
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; }
//called by Groups manager public IEnumerator CheckGroupLoadStates() { if (!mInitialized) { yield break; } if (RootGroup == null || RootGroup.IsDestroyed) { Debug.Log("ROOT GROUP was null or destroyed in unloader, we're finished"); yield break; } //we may have to backtrack if new groups were added if (NotPreparedToUnload.Count > 0) { LoadState = WIGroupLoadState.Loaded; } else if (PreparingToUnload.Count > 0) { LoadState = WIGroupLoadState.PreparingToUnload; } else if (Unloading.Count > 0) { LoadState = WIGroupLoadState.Unloading; } switch (LoadState) { case WIGroupLoadState.Loaded: //tell everyone in the Loaded list to prepare to unload //then move them all into preparing to unload //---TRANSITION TO PREPARED TO UNLOAD---// for (int i = NotPreparedToUnload.LastIndex(); i >= 0; i--) { if (NotPreparedToUnload [i].PrepareToUnload()) { PreparingToUnload.Add(NotPreparedToUnload [i]); NotPreparedToUnload.RemoveAt(i); } yield return(null); } if (NotPreparedToUnload.Count == 0 && RootGroup.PrepareToUnload()) { LoadState = WIGroupLoadState.PreparingToUnload; //RootGroup.LoadState = WIGroupLoadState.PreparingToUnload; } yield return(null); break; case WIGroupLoadState.PreparingToUnload: //go through each child group and ask if it's ready to unload //this will force the group to ask each of its child items //if it's prepared we move it to the prepared to unload group for (int i = PreparingToUnload.LastIndex(); i >= 0; i--) { WIGroup loadedGroup = PreparingToUnload [i]; if (loadedGroup.ReadyToUnload) { PreparingToUnload.RemoveAt(i); ReadyToUnload.Add(loadedGroup); } yield return(null); //yield return null; } //---TRANSITION TO UNLOADING---// //if all are ready to unload and there are no more not prepared to unload //then begin unload - there's no turning back at this point! if (PreparingToUnload.Count == 0 && RootGroup.ReadyToUnload) { Unloading.AddRange(ReadyToUnload); ReadyToUnload.Clear(); for (int i = 0; i < Unloading.Count; i++) { Unloading [i].BeginUnload(); } RootGroup.BeginUnload(); LoadState = WIGroupLoadState.Unloading; //RootGroup.LoadState = WIGroupLoadState.Unloading; } yield return(null); break; case WIGroupLoadState.Unloading: if (Unloading.Count > 0) { for (int i = Unloading.LastIndex(); i >= 0; i--) { if (Unloading [i].FinishedUnloading) { FinishedUnloading.Add(Unloading [i]); Unloading.RemoveAt(i); //this generates a huge amount of garbage yield break; } #if UNITY_EDITOR else { LastHoldout = Unloading [i].FileName + " " + Unloading [i].HoldoutChildItem; } #endif yield return(null); } } else { if (FinishedUnloading.Count > 0) { for (int i = FinishedUnloading.LastIndex(); i >= 0; i--) { if (FinishedUnloading [i] == null || FinishedUnloading [i].IsDestroyed) { FinishedUnloading.RemoveAt(i); } else { //we see if it's ready to actually be destroyed //no groups greater than [x] depth that have not been destroyed #if UNITY_EDITOR LastHoldout = FinishedUnloading [i].FileName + " " + FinishedUnloading [i].HoldoutChildItem; #endif if (!FinishedUnloading [i].HasChildGroups) { ReadyToDestroy.Add(FinishedUnloading [i]); FinishedUnloading.RemoveAt(i); } } yield return(null); } } else { } } yield return(null); //---TRANSITION TO UNLOADED---// //if we have more than just the root group then we wait until the root group is finished unloading to kill everything if (FinishedUnloading.Count == 0 && ReadyToDestroy.Count == 0) { if (!RootGroup.FinishedUnloading) { //now it will be detsroyed by WIGroups #if UNITY_EDITOR LastHoldout = RootGroup.FileName + " " + RootGroup.HoldoutChildItem; #endif if (RootGroup.PrepareToUnload()) { RootGroup.BeginUnload(); } } else { LoadState = WIGroupLoadState.Unloaded; } } break; case WIGroupLoadState.Unloaded: //nothing left to do break; default: Debug.Log("Weird load state in WIGroupUnloader: " + LoadState.ToString()); break; } yield break; }
public List <ActionNode> AddNodesToGroup(List <ActionNodeState> actionNodeStates, WIGroup group, Transform nodeParentTransform) { List <ActionNode> actionNodes = new List <ActionNode> (); List <ActionNodeState> nodeStates = null; for (int i = 0; i < actionNodeStates.Count; i++) { actionNodes.Add(SpawnActionNode(group, actionNodeStates [i], nodeParentTransform)); } return(actionNodes); }
public IEnumerator GenerateStructureItems() { yield return(null); Transform structureItems = null; WIGroup group = null; State = BuilderState.BuildingItems; WorldChunk chunk = null; switch (Mode) { case BuilderMode.Exterior: default: group = ParentStructure.StructureGroup; chunk = group.GetParentChunk(); structureItems = group.gameObject.FindOrCreateChild("_ITEMS_EXT"); var generateExtItems = StructureBuilder.GenerateExteriorItems( ParentStructure, Template.Exterior, group, structureItems); while (generateExtItems.MoveNext()) { /*if (chunk.TargetMode == ChunkMode.Unloaded) { * Debug.Log("Cancelling build, chunk is unloading"); * yield break; * }*/ yield return(generateExtItems.Current); } break; case BuilderMode.Interior: for (int i = 0; i < InteriorVariants.Count; i++) { int interiorVariant = InteriorVariants [i]; if (!ParentStructure.StructureGroupInteriors.ContainsKey(interiorVariant)) { //Debug.Log ("Didn't find interior variant " + interiorVariant.ToString () + " in " + ParentStructure.name + " - waiting for a bit..."); double timeOut = WorldClock.RealTime + 10f; while (ParentStructure != null && !ParentStructure.worlditem.Is(WIActiveState.Invisible) && !ParentStructure.StructureGroupInteriors.ContainsKey(interiorVariant)) { //waiting for interior groups to spawn /*if (chunk.TargetMode == ChunkMode.Unloaded) { * Debug.Log("Cancelling build, chunk is unloading"); * yield break; * }*/ yield return(null); if (WorldClock.RealTime > timeOut) { //Debug.Log ("Timed out waiting for interior group " + interiorVariant.ToString () + " in " + ParentStructure.name); break; } } } try { group = ParentStructure.StructureGroupInteriors [interiorVariant]; structureItems = group.gameObject.FindOrCreateChild("_ITEMS_INT_" + interiorVariant.ToString()); } catch (Exception e) { Debug.LogError(e.ToString()); continue; } if (!ParentStructure.State.InteriorsLoadedOnce.Contains(interiorVariant) && interiorVariant < Template.InteriorVariants.Count) { /*#if UNITY_EDITOR * Debug.Log ("Generating items for interior variant " + interiorVariant.ToString ()); #endif*/ var generateIntItems = StructureBuilder.GenerateInteriorItems( ParentStructure, interiorVariant, Template.InteriorVariants [interiorVariant], group, structureItems); while (generateIntItems.MoveNext()) { /*if (chunk.TargetMode == ChunkMode.Unloaded) { * Debug.Log("Cancelling build, unloading"); * yield break; * }*/ yield return(generateIntItems.Current); } } /*#if UNITY_EDITOR * else { * Debug.Log ("Didn't generate items for interior variant " + interiorVariant.ToString () + " because it has either been loaded once (" + ParentStructure.State.InteriorsLoadedOnce.Contains (interiorVariant).ToString() + ") or it's out of range (" + (interiorVariant >= Template.InteriorVariants.Count).ToString () + ")"); + } #endif*/ yield return(null); } break; case BuilderMode.Minor: //minor structures don't generate items break; } }
public static Creature SpawnRandomCreature(CreatureFlags flags, ActionNode node, WIGroup group) { Creature newCreature = null; return(newCreature); }
//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; }
protected IEnumerator AddGenericWorldItemsToDungeon(string pieces, Transform parentTransform, bool exterior, WIGroup group) { // ChildPiece[] childPieces = StructureTemplate.ExtractChildPiecesFromLayer (pieces); // for (int i = 0; i < childPieces.Length; i++) { // ChildPiece childPiece = childPieces [i]; // ////Debug.Log ("Adding worlditem " + childPiece.ChildName + " to " + name + " at " + childPiece.Position + " exterior? " + exterior.ToString ()); // WorldItem worlditem = null; // if (WorldItems.CloneWorldItem (childPiece.PackName, childPiece.ChildName, childPiece.Transform, false, group, out worlditem)) { // worlditem.tr.parent = group.transform; // worlditem.Initialize (); // worlditem.Props.Local.Transform.ApplyTo (worlditem.tr); // } else { // Debug.Log ("Couldn't clone generic world item " + childPiece.PackName + ", " + childPiece.ChildName); // } // worlditem.Props.Global.ParentUnderGroup = false; // worlditem.transform.parent = parentTransform; // if (!worlditem.CanEnterInventory && !worlditem.CanBeCarried) { //for large pieces of furniture, etc. // if (exterior) { // mExteriorRenderers.AddRange (worlditem.Renderers); // } else { // mInteriorRenderers.AddRange (worlditem.Renderers); // } // } // } //TODO split this up yield break; }
protected IEnumerator AddUniqueWorldItemsToDungeon(List <StackItem> wiPieces, Transform parentTransform, WIGroup group) { // foreach (StackItem piece in wiPieces) { Debug.Log ("Adding piece " + piece.FileName + " to structure " + name); // WorldItem newWorldItem = null; // if (WorldItems.CloneFromStackItem (piece, group, out newWorldItem)) { // newWorldItem.tr.parent = group.transform; // newWorldItem.Initialize (); // piece.Props.Local.Transform.ApplyTo (newWorldItem.transform); // } // } yield break; }
// = new GenericWorldItem (); public void CreateDarkrotSpawner(Vector3 spawnerPosition, Vector3 spawnerRotation, WIGroup group, int numDarkrotReleaesd, float releaseDelay, float releaseInterval) { StackItem spawnerStackItem = gDarkrotSpawner.ToStackItem(); spawnerStackItem.Transform.Position = spawnerPosition; spawnerStackItem.Transform.Rotation = spawnerRotation; spawnerStackItem.Props.Local.FreezeOnStartup = true; spawnerStackItem.Props.Local.Mode = WIMode.Frozen; WorldItem newSpawner = null; if (WorldItems.CloneFromStackItem(spawnerStackItem, group, out newSpawner)) { newSpawner.Initialize(); DarkrotSpawner ds = newSpawner.Get <DarkrotSpawner> (); ds.State.MaxDarkrotAtOneTime = numDarkrotReleaesd; ds.State.SpawnDelay = releaseDelay; ds.State.SpawnInterval = releaseInterval; } Debug.Log("Created spawner"); }
public void Clear() { Group = null; GroupPath = null; UniqueID = null; }
public static bool SpawnCreature(CreatureDen den, WIGroup group, Vector3 spawnPosition, out Creature newCreature) { return(SpawnCreature(den, group, spawnPosition, false, string.Empty, 0f, out newCreature)); }
public static Creature SpawnCreatureFromStackItem(StackItem stackItem, WIGroup group) { return(null); }