Exemple #1
0
 /// <summary>
 ///     Output custom location spawns
 /// </summary>
 private void ZoneSystem_SpawnLocation(ZoneSystem.ZoneLocation location, ZoneSystem.SpawnMode mode)
 {
     if (ZoneManager.Instance.Locations.ContainsKey(location.m_prefabName))
     {
         Logger.LogDebug($"spawned {location.m_prefabName}, mode: {mode}");
     }
 }
        /// <summary>
        ///     Create a copy of the <see cref="ZoneSystem.ZoneLocation"/>
        /// </summary>
        /// <param name="zoneLocation">ZoneLocation to copy</param>
        public LocationConfig(ZoneSystem.ZoneLocation zoneLocation)
        {
            Biome     = zoneLocation.m_biome;
            BiomeArea = zoneLocation.m_biomeArea;
            Priotized = zoneLocation.m_prioritized;
            Quantity  = zoneLocation.m_quantity;
#pragma warning disable CS0618 // Type or member is obsolete
            ChanceToSpawn = zoneLocation.m_chanceToSpawn;
#pragma warning restore CS0618 // Type or member is obsolete
            ExteriorRadius         = zoneLocation.m_exteriorRadius;
            ForestTresholdMin      = zoneLocation.m_forestTresholdMin;
            ForestTrasholdMax      = zoneLocation.m_forestTresholdMax;
            MinDistance            = zoneLocation.m_minDistance;
            MaxDistance            = zoneLocation.m_maxDistance;
            MinAltitude            = zoneLocation.m_minAltitude;
            MaxAltitude            = zoneLocation.m_maxAltitude;
            Group                  = zoneLocation.m_group;
            InForest               = zoneLocation.m_inForest;
            MinTerrainDelta        = zoneLocation.m_minTerrainDelta;
            MaxTerrainDelta        = zoneLocation.m_maxTerrainDelta;
            MinDistanceFromSimilar = zoneLocation.m_minDistanceFromSimilar;
            HasInterior            = zoneLocation.m_location && zoneLocation.m_location.m_hasInterior;
            InteriorRadius         = zoneLocation.m_interiorRadius;
            InteriorEnvironment    = zoneLocation.m_location?.m_interiorEnvironment;
            SlopeRotation          = zoneLocation.m_slopeRotation;
            RandomRotation         = zoneLocation.m_randomRotation;
            SnapToWater            = zoneLocation.m_snapToWater;
            IconPlaced             = zoneLocation.m_iconPlaced;
            IconAlways             = zoneLocation.m_iconAlways;
            ClearArea              = zoneLocation.m_location.m_clearArea;
        }
        private static string GetNameBox(ZoneSystem.ZoneLocation zoneLocation, bool hasSprite)
        {
            StringBuilder sb = new StringBuilder(zoneLocation.m_prefab.name);

            if (hasSprite)
            {
                sb.Append($"<br><img src=\"../../images/locations/{zoneLocation.m_prefab.name}.png\">");
            }
            return(sb.ToString());
        }
 private static string GetSpawns(ZoneSystem.ZoneLocation zoneLocation)
 {
     return(string.Join("",
                        zoneLocation.m_prefab.GetComponentsInChildren <CreatureSpawner>()
                        .Select(cs => cs.m_creaturePrefab.name)
                        .Distinct()
                        .OrderByDescending(cs => cs.ToString())
                        .Select(creatureName => $"<li>Spawns {creatureName}</li>")
                        ));
 }
    private static string Serialize(ZoneSystem.ZoneLocation location, IList <CreatureSpawner> spawners)
    {
        if (!ConfigurationManager.GeneralConfig.DontCollapseFile.Value)
        {
            spawners = spawners.GroupBy(x => x.m_creaturePrefab.name).Select(x => x.First()).ToList();
        }

        var biome        = location.m_biome;
        var locationName = location.m_prefabName;

        StringBuilder stringBuilder = new StringBuilder();

        for (int i = 0; i < spawners.Count; ++i)
        {
            var spawner = spawners[i];

            stringBuilder.AppendLine($"## Biome: {biome}, Location: {locationName}, Spawner: {i} ");

            try
            {
                stringBuilder.AppendLine($"[{locationName}.{spawner.m_creaturePrefab.name}]");
            }
            catch (Exception e)
            {
                Log.LogWarning($"Error while attempting to read name of prefab for spawner {spawner}", e);
            }

            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.PrefabName)}={spawner.m_creaturePrefab.name}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.Enabled)}={spawner.enabled}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.SpawnAtDay)}={spawner.m_spawnAtDay}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.SpawnAtNight)}={spawner.m_spawnAtNight}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.LevelMin)}={spawner.m_minLevel}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.LevelMax)}={spawner.m_maxLevel}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.LevelUpChance)}={10}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.RespawnTime)}={spawner.m_respawnTimeMinuts.ToString(CultureInfo.InvariantCulture)}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.TriggerDistance)}={spawner.m_triggerDistance.ToString(CultureInfo.InvariantCulture)}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.TriggerNoise)}={spawner.m_triggerNoise.ToString(CultureInfo.InvariantCulture)}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.SpawnInPlayerBase)}={spawner.m_spawnInPlayerBase}");
            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.SetPatrolPoint)}={spawner.m_setPatrolSpawnPoint}");

            var    character   = spawner.m_creaturePrefab.GetComponent <Character>();
            string factionName = "";

            if (character is not null)
            {
                factionName = character.m_faction.ToString();
            }

            stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.SetFaction)}={factionName}");
            //stringBuilder.AppendLine($"{nameof(CreatureSpawnerConfig.RequireSpawnArea)}={spawner.m_requireSpawnArea}"); //Disabled for now, due to not seemingly being used.
            stringBuilder.AppendLine();
        }

        return(stringBuilder.ToString());
    }
Exemple #6
0
        public void CommonEffect(Player player)
        {
            //Spawn location structure
            var pos = originLocation;
            var rot = Quaternion.LookRotation(originForward) * Quaternion.Euler(0, 90, 0);
            var getLocationMethods = typeof(ZoneSystem).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
            var method             = (from MethodInfo m in getLocationMethods where m.Name == "GetLocation" && m.GetParameters().Any(param => param.ParameterType == typeof(string)) select m).FirstOrDefault();

            if (method == null)
            {
                throw new NullReferenceException("Could not find ZoneSystem.GetLocation method");
            }
            ZoneSystem.ZoneLocation location = (ZoneSystem.ZoneLocation)method.Invoke(ZoneSystem.instance, new object[] { houseLocationName });
            //m_didZoneTest = true;
            List <GameObject> spawnedGhostObjects = new List <GameObject>();

            typeof(ZoneSystem).GetMethod("SpawnLocation", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(ZoneSystem.instance, new object[] { location, spawnSeed, pos, rot, ZoneSystem.SpawnMode.Full, spawnedGhostObjects });

            //Set up for bed spawning
            var bedPos = originLocation + originForward * commonBedDisplacement;
            var bedRot = rot;

            //Get piece table
            var pieceTableName = "_HammerPieceTable";
            var pieceTable     = (from PieceTable table in Resources.FindObjectsOfTypeAll <PieceTable>() where table.gameObject.name == pieceTableName select table).FirstOrDefault();

            if (pieceTable == null || pieceTable.m_pieces.Count <= 0)
            {
                throw new NullReferenceException("Could not find hammer piece table");
            }
            pieceTable.UpdateAvailable(null, null, false, true); //noPlacementCost set to true - other fields don't matter

            //Select piece
            int        category   = -1;
            Vector2Int pieceIndex = pieceTable.GetPieceIndexVec(bedPieceName, ref category);

            pieceTable.SetCategory(category);
            pieceTable.SetSelected(pieceIndex);

            //Place piece
            var piece = pieceTable.GetSelectedPiece();

            piece.m_description = magicBedDesc;
            TerrainModifier.SetTriggerOnPlaced(trigger: true);
            GameObject gameObject = UnityEngine.Object.Instantiate(piece.gameObject, bedPos, bedRot);

            TerrainModifier.SetTriggerOnPlaced(trigger: false);
            WearNTear wear = gameObject.GetComponent <WearNTear>();

            if ((bool)wear)
            {
                wear.OnPlaced();
            }
            piece.m_description = "";
        }
 private string GetProperties(ZoneSystem.ZoneLocation zoneLocation)
 {
     return($"<ul>" +
            $"{(zoneLocation.m_prioritized ? "<li>Prioritized</li>" : "")}" +
            $"{(zoneLocation.m_unique ? "<li>Unique</li>" : "")}" +
            $"{(zoneLocation.m_snapToWater ? "<li>Snap to water</li>" : "")}" +
            $"{(zoneLocation.m_centerFirst ? "<li>Place in center first</li>" : "")}" +
            $"{(zoneLocation.m_location.m_clearArea ? "<li>Clear area</li>" : "")}" +
            GetSpawns(zoneLocation) +
            $"</ul>");
 }
 private string GetInterior(ZoneSystem.ZoneLocation zoneLocation)
 {
     if (!zoneLocation.m_location.m_hasInterior)
     {
         return("");
     }
     return($"<ul>" +
            $"<li>Name: {zoneLocation.m_location.m_interiorPrefab.name}</li>" +
            $"<li>Radius: {zoneLocation.m_interiorRadius}</li>" +
            $"<li>Environment: {zoneLocation.m_location.m_interiorEnvironment}</li>" +
            $"</ul>");
 }
        private string GetFilters(ZoneSystem.ZoneLocation zoneLocation)
        {
            var inForest = zoneLocation.m_inForest && (zoneLocation.m_forestTresholdMin > 0 || zoneLocation.m_forestTresholdMax < 1);

            return("<ul>" +
                   $"<li>Altitude: {RangeString(zoneLocation.m_minAltitude, zoneLocation.m_minAltitude)}</li>" +

                   $"<li>Terrain Delta: {RangeString(zoneLocation.m_minTerrainDelta, zoneLocation.m_maxTerrainDelta)}</li>" +
                   $"{(zoneLocation.m_minDistance != 0 ? $"<li>Min Distance: {zoneLocation.m_minDistance}" : "")}</li>" +
                   $"{(inForest ? "" : $"<li>Forest Threshold: {RangeString(zoneLocation.m_forestTresholdMin, zoneLocation.m_forestTresholdMax)}")}</li>" +
                   $"{(zoneLocation.m_minDistanceFromSimilar != 0 ? $"<li>MinDistanceFromSimilar: {zoneLocation.m_minDistanceFromSimilar}" : "")}</li>" +
                   "</ul>");
        }
            private static bool GenerateLocationsPrefix(ZoneSystem __instance, ZoneSystem.ZoneLocation location)
            {
                var groupName = string.IsNullOrEmpty(location.m_group) ? "<unnamed>" : location.m_group;

                Log($"Generating location of group {groupName}, required {location.m_quantity}, unique {location.m_unique}, name {location.m_prefabName}");
                if (Settings.EnabledForThisWorld)
                {
                    if (Settings.HasSpawnmap)
                    {
                        // Place all locations specified by the spawn map, ignoring counts specified in the prefab
                        int placed = 0;
                        foreach (var normalizedPosition in Settings.GetAllSpawns(location.m_prefabName))
                        {
                            var worldPos = NormalizedToWorld(normalizedPosition);
                            var position = new Vector3(
                                worldPos.x,
                                WorldGenerator.instance.GetHeight(worldPos.x, worldPos.y),
                                worldPos.y
                                );
                            RegisterLocation(__instance, location, position, false);
                            Log($"Position of {location.m_prefabName} ({++placed}/{location.m_quantity}) overriden: set to {position}");
                        }

                        // The vanilla placement algorithm considers already placed zones, but we can early out here anyway if we place them all
                        // (this is required in the case of the StartTemple as we don't want to place it twice if OverrideStartPosition is specified)
                        if (placed >= location.m_quantity)
                        {
                            return(false);
                        }
                    }

                    if (Settings.OverrideStartPosition && location.m_prefabName == "StartTemple")
                    {
                        var position = new Vector3(
                            Settings.StartPositionX,
                            WorldGenerator.instance.GetHeight(Settings.StartPositionX, Settings.StartPositionY),
                            Settings.StartPositionY
                            );
                        RegisterLocation(__instance, location, position, false);
                        Log($"Start position overriden: set to {position}");
                        return(false);
                    }

                    if (location.m_prefabName != "StartTemple" && ConfigDebugSkipDefaultLocationPlacement.Value)
                    {
                        return(false);
                    }
                }
                return(true);
            }
Exemple #11
0
 private static void ZoneSystem_SpawnLocation(ZoneSystem.ZoneLocation location, ZoneSystem.SpawnMode mode) => instance.ZoneSystem_SpawnLocation(location, mode);