Beispiel #1
0
 public void Initialize( )
 {
     name = Dungeon.ModuleName(ParentDungeon.name, ModuleNumber);
     OcclusionGroup.cullingGroupMasterName = name;
     if (Application.isPlaying)
     {
         ModuleGroup = WIGroups.GetOrAdd(name, ParentDungeon.DungeonGroup, null);
     }
 }
Beispiel #2
0
 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();
     }
 }
Beispiel #3
0
 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();
     }
 }
Beispiel #4
0
        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
        }
Beispiel #5
0
        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
        }
Beispiel #6
0
        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;
        }
Beispiel #7
0
 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));
 }
Beispiel #8
0
        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;
        }
Beispiel #9
0
        public IEnumerator GetInventoryContainer(int currentIndex, bool forward, GetInventoryContainerResult result)
        {
            if (result == null)
            {
                yield break;
            }

            mOnAccessInventory.SafeInvoke();

            if (mContainerEnabler == null)
            {
                //if we don't have an enabler, we need one now
                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();
                //create a new container enabler for our stuff
                mContainerEnabler = Stacks.Create.StackEnabler(CharacterInventoryGroup);
            }

            int       totalContainers = 1;
            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
                int nextIndex = currentIndex;
                List <Container> containers = new List <Container> ();
                if (WIGroups.GetAllContainers(worlditem.Group, containers))
                {
                    if (forward)
                    {
                        nextIndex = containers.NextIndex <Container> (currentIndex);
                    }
                    else
                    {
                        nextIndex = containers.PrevIndex <Container> (currentIndex);
                    }
                    //tell the container that we're opening it, then wait a tick for it to fill
                    try {
                        containers [nextIndex].OnOpenContainer();
                    } catch (Exception e) {
                        Debug.LogException(e);
                        yield break;
                    }
                    yield return(null);

                    mContainerEnabler.EnablerStack.Items.Clear();
                    Stacks.Display.ItemInEnabler(containers [nextIndex].worlditem, mContainerEnabler);
                    result.ContainerEnabler = mContainerEnabler;
                    result.ContainerIndex   = nextIndex;
                    result.TotalContainers  = containers.Count;
                }
            }
            else
            {
                //if we're not a shop owner
                //then there's exactly one container, our inventory container
                //if we're holding a temporary item then there are two
                if (IsHoldingTemporaryItem)
                {
                    Debug.Log("We're holding item so we'll return 2 containers");
                    //index 0 is our container enabler
                    //index 1 is our temporary item
                    result.TotalContainers = 2;
                    if (currentIndex == 0)                      //toggle to our held item
                    //Stacks.Display.ItemInEnabler (worlditem, mTemporaryItemEnabler);
                    {
                        result.ContainerIndex   = 1;
                        result.ContainerEnabler = mTemporaryItemEnabler;
                    }
                    else                        //toggle to our container enabler
                    {
                        Stacks.Display.ItemInEnabler(worlditem, mContainerEnabler);
                        result.ContainerIndex   = 0;
                        result.ContainerEnabler = mContainerEnabler;
                    }
                }
                else
                {
                    Stacks.Display.ItemInEnabler(worlditem, mContainerEnabler);
                    result.ContainerIndex   = 0;
                    result.TotalContainers  = 1;
                    result.ContainerEnabler = mContainerEnabler;
                }
                //this is always the same
                result.InventoryBank = InventoryBank;
            }
            yield break;
        }