Пример #1
0
        /// <summary>
        /// Reverts a replacement.
        /// </summary>
        /// <param name="replacement">Replacement record to revert</param>
        /// <param name="removeEntries">True to remove the reverted entries from the list of replacements, false to leave the list unchanged</param>
        /// <returns>True if the entire building record was removed from the list (due to no remaining replacements for that prefab), false if the prefab remains in the list (has other active replacements)</returns>
        protected virtual bool Revert(BOBBuildingReplacement replacement, bool removeEntries)
        {
            // Safety check for calls without any current replacement.
            if (replacement?.targetInfo == null || replacement.references == null)
            {
                return(false);
            }

            if (replacement.references != null)
            {
                // Revert all entries in list.
                RevertReferences(replacement.targetInfo, replacement.references);

                // Remove replacement entry from list of replacements, if we're doing so.
                if (removeEntries)
                {
                    // Remove from replacement list.
                    ReplacementList(replacement.BuildingInfo).Remove(replacement);

                    // See if we've got a parent building element record, and if so, if it has any remaining replacement entries.
                    BOBBuildingElement thisElement = BuildingElement(replacement.BuildingInfo);
                    if (thisElement != null && (thisElement.replacements == null || thisElement.replacements.Count == 0))
                    {
                        // No replacement entries left - delete entire building entry and return true to indicate that we've done so.
                        BuildingElementList.Remove(thisElement);
                        return(true);
                    }
                }
            }

            // If we got here, we didn't remove any building entries from the list; return false.
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Deserialises an individual building prop replacement list.
        /// </summary>
        /// <param name="elementList">Building element list to deserialise</param>
        private static void DeserializeIndividual(BOBBuildingElement buildingElement)
        {
            // Try to find target network.
            BuildingInfo buildingInfo = (BuildingInfo)PrefabCollection <BuildingInfo> .FindLoaded(buildingElement.building);

            if (buildingInfo == null)
            {
                Logging.Message("Couldn't find target building ", buildingElement.building);
                return;
            }

            // Iterate through each element in the provided list.
            foreach (BOBBuildingReplacement replacement in buildingElement.replacements)
            {
                // Try to find target prefab.
                PrefabInfo targetPrefab = replacement.tree ? (PrefabInfo)PrefabCollection <TreeInfo> .FindLoaded(replacement.target) : (PrefabInfo)PrefabCollection <PropInfo> .FindLoaded(replacement.target);

                if (targetPrefab == null)
                {
                    Logging.Message("Couldn't find target prefab ", replacement.target);
                    continue;
                }

                // Try to find replacement prefab.
                PrefabInfo replacementPrefab = FindReplacementPrefab(replacement.Replacement, replacement.tree);
                if (replacementPrefab == null)
                {
                    Logging.Message("Couldn't find replacement prefab ", replacement.Replacement);
                    continue;
                }

                // If we got here, it's all good; apply the building replacement.
                IndividualReplacement.instance.Apply(buildingInfo, targetPrefab, replacement.index, replacementPrefab, replacement.angle, replacement.offsetX, replacement.offsetY, replacement.offsetZ, replacement.probability);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the relevant building replacement list entry from the active configuration file, creating a new building entry if none already exists.
        /// </summary>
        /// <param name="buildingInfo">Building prefab</param>
        /// <returns>Replacement list for the specified building prefab</returns>
        protected virtual List <BOBBuildingReplacement> ReplacementEntry(BuildingInfo buildingInfo)
        {
            // Get existing entry for this building.
            BOBBuildingElement thisBuilding = BuildingElement(buildingInfo);

            // If no existing entry, create a new one.
            if (thisBuilding == null)
            {
                thisBuilding = new BOBBuildingElement(buildingInfo);
                BuildingElementList.Add(thisBuilding);
            }

            // Return replacement list from this entry.
            return(thisBuilding.replacements);
        }