diff --git a/1.3/Assemblies/ZombieLand.dll b/1.3/Assemblies/ZombieLand.dll index 332ab177..c4dff28a 100644 Binary files a/1.3/Assemblies/ZombieLand.dll and b/1.3/Assemblies/ZombieLand.dll differ diff --git a/About/About.xml b/About/About.xml index cb546fb0..fc39f352 100644 --- a/About/About.xml +++ b/About/About.xml @@ -16,6 +16,9 @@ https://github.com/pardeike/HarmonyRimWorld/releases/latest + +
  • betterscenes.rimconnect
  • +
  • ceteam.combatextended
  • diff --git a/About/Manifest.xml b/About/Manifest.xml index a3d0c844..798761db 100644 --- a/About/Manifest.xml +++ b/About/Manifest.xml @@ -1,7 +1,7 @@  net.pardeike.rimworld.mod.zombieland - 2.3.2.0 + 2.3.3.0
  • 1.0.0
  • 1.1.0
  • @@ -13,8 +13,10 @@ +
  • betterscenes.rimconnect
  • +
  • ceteam.combatextended
  • https://raw.githubusercontent.com/pardeike/Zombieland/latest/About/Manifest.xml https://github.com/pardeike/Zombieland/releases/latest diff --git a/Source/Dialog_ZombieDebugActionMenu.cs b/Source/Dialog_ZombieDebugActionMenu.cs index c140037d..31b65df7 100644 --- a/Source/Dialog_ZombieDebugActionMenu.cs +++ b/Source/Dialog_ZombieDebugActionMenu.cs @@ -89,7 +89,7 @@ public override void DoListingItems() { base.DebugToolMap($"Trigger: Zombie incident ({size})", delegate { - var success = ZombiesRising.TryExecute(map, size, IntVec3.Invalid); + var success = ZombiesRising.TryExecute(map, size, IntVec3.Invalid, false, false); if (success == false) Log.Error("Incident creation failed. Most likely no valid spawn point found."); }, highlightedIndex == i++); @@ -97,19 +97,19 @@ public override void DoListingItems() } base.DebugToolMap("Spawn: Zombie incident (4)", delegate { - _ = ZombiesRising.TryExecute(map, 4, UI.MouseCell(), true); + _ = ZombiesRising.TryExecute(map, 4, UI.MouseCell(), false, true); }, highlightedIndex == i++); base.DebugToolMap("Spawn: Zombie incident (25)", delegate { - _ = ZombiesRising.TryExecute(map, 25, UI.MouseCell(), true); + _ = ZombiesRising.TryExecute(map, 25, UI.MouseCell(), false, true); }, highlightedIndex == i++); base.DebugToolMap("Spawn: Zombie incident (100)", delegate { - _ = ZombiesRising.TryExecute(map, 100, UI.MouseCell(), true); + _ = ZombiesRising.TryExecute(map, 100, UI.MouseCell(), false, true); }, highlightedIndex == i++); base.DebugToolMap("Spawn: Zombie incident (200)", delegate { - _ = ZombiesRising.TryExecute(map, 200, UI.MouseCell(), true); + _ = ZombiesRising.TryExecute(map, 200, UI.MouseCell(), false, true); }, highlightedIndex == i++); base.DebugToolMap("Convert: Make Zombie", delegate { diff --git a/Source/Patches.cs b/Source/Patches.cs index 25b9ad68..79fb98de 100644 --- a/Source/Patches.cs +++ b/Source/Patches.cs @@ -2121,7 +2121,7 @@ static bool Prefix(ref bool __result, IncidentParms parms) var oldMode = ZombieSettings.Values.spawnHowType; ZombieSettings.Values.spawnHowType = parms.raidArrivalMode.walkIn ? SpawnHowType.FromTheEdges : SpawnHowType.AllOverTheMap; - _ = ZombiesRising.TryExecute(Find.CurrentMap, Mathf.FloorToInt(parms.points), parms.spawnCenter); + _ = ZombiesRising.TryExecute(Find.CurrentMap, Mathf.FloorToInt(parms.points), parms.spawnCenter, false, false); ZombieSettings.Values.spawnHowType = oldMode; __result = false; return false; diff --git a/Source/RimConnectSupport.cs b/Source/RimConnectSupport.cs index 01a234f3..4eca60b0 100644 --- a/Source/RimConnectSupport.cs +++ b/Source/RimConnectSupport.cs @@ -1,229 +1,228 @@ using HarmonyLib; +using RimWorld; using System; using System.Collections; using System.Collections.Generic; -using System.IO; +using System.Linq; using System.Reflection; -using System.Security.Cryptography; -using System.Text; -using System.Xml; +using System.Reflection.Emit; +using UnityEngine; using Verse; namespace ZombieLand { - [HarmonyPatch] - static class RimConnectAPI_PostValidCommands_Patch + [StaticConstructorOnStartup] + public class RimConnectSupport { - static readonly string configDefault = @" - - - Zombies (albino) - 20 - - - Zombies (dark slimer) - 15 - - - Zombies (electrifier) - 10 - - - Zombies (miner) - 5 - - - Zombies (normal) - 2 - - - Zombies (random) - 25 - - - Zombies (bomber) - 20 - - - Zombies (tanky) - 20 - - - Zombies (toxic) - 20 - - ".Replace('\'', '"'); - - static bool Prepare() - { - return TargetMethod() != null; - } - - static MethodBase TargetMethod() - { - var tRimConnectAPI = AccessTools.TypeByName("RimConnection.RimConnectAPI"); - if (tRimConnectAPI == null) return null; - return AccessTools.Method(tRimConnectAPI, "PostValidCommands"); - } + static readonly Dictionary> actions = new Dictionary>(); - static void Prefix(object commandList) + static RimConnectSupport() { - var list = Traverse.Create(commandList).Property("validCommands").GetValue() as IList; - var path = $"{GenFilePaths.ConfigFolderPath}{Path.DirectorySeparatorChar}ZombieLand-RimConnect.xml"; - if (File.Exists(path) == false) - File.WriteAllText(path, configDefault); - - var contents = File.ReadAllText(path); - var xmlReaderSettings = new XmlReaderSettings { IgnoreComments = true, IgnoreWhitespace = true, CheckCharacters = false }; - using var stringReader = new StringReader(contents); - using XmlReader xmlReader = XmlReader.Create(stringReader, xmlReaderSettings); - var xmlDoc = new XmlDocument(); - xmlDoc.Load(xmlReader); - foreach (XmlNode command in xmlDoc.DocumentElement.ChildNodes) - { - if (Enum.TryParse(command.Attributes["type"].Value, out var confType)) - { - var confName = ""; - var confCosts = -1; - for (var i = 0; i < command.ChildNodes.Count; i++) - { - var name = command.ChildNodes[i].Name; - var value = command.ChildNodes[i].InnerText; - switch (name) - { - case "name": - confName = value; - break; - case "costs": - confCosts = int.Parse(value); - break; - } - } - if (confCosts > 0 && confName != "") - RimConnectSupport.AddCommand(list, confName, $"Creates {confName}", confCosts, (Map map, int amount, string user) => - { - var success = ZombiesRising.TryExecute(map, amount, IntVec3.Invalid, true, confType); - }); - } - } + var tActionList = AccessTools.TypeByName("RimConnection.ActionList"); + if (tActionList == null) return; + + var tAction = AccessTools.TypeByName("RimConnection.Action"); + if (tAction == null) return; + var mExecute = AccessTools.Method(tAction, "Execute"); + if (mExecute == null) return; + var mBadEventNotification = AccessTools.Method("RimConnection.AlertManager:BadEventNotification", new[] { typeof(string), typeof(IntVec3) }); + if (mBadEventNotification == null) return; + + var harmony = new Harmony("net.pardeike.zombieland.rimconnect"); + var postfix = new HarmonyMethod(AccessTools.Method(typeof(RimConnectSupport), nameof(Postfix))); + var mGenerateActionList = AccessTools.Method(tActionList, "GenerateActionList"); + _ = harmony.Patch(mGenerateActionList, postfix: postfix); } - } - [HarmonyPatch] - static class RimConnectAPI_GetCommands_Patch - { - static bool Prepare() + static void Postfix(ref IList __result) { - return TargetMethod() != null; + var cat = "Zombies"; + _ = __result.Add(CreateActionClass("RandomZombieAction", "Random Zombie Event", "Creates some normal zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.Random))); + _ = __result.Add(CreateActionClass("SuicideZombieAction", "Suicide Zombie Event", "Creates some suicide bomber zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.SuicideBomber))); + _ = __result.Add(CreateActionClass("ToxicZombieAction", "Toxic Zombie Event", "Creates some toxic goo zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.ToxicSplasher))); + _ = __result.Add(CreateActionClass("TankZombieAction", "Tank Zombie Event", "Creates some heavy tank zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.TankyOperator))); + _ = __result.Add(CreateActionClass("MinerZombieAction", "Miner Zombie Event", "Creates some mining zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.Miner))); + _ = __result.Add(CreateActionClass("ElectricZombieAction", "Electric Zombie Event", "Creates some electrical zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.Electrifier))); + _ = __result.Add(CreateActionClass("AlbinoZombieAction", "Albino Zombie Event", "Creates some albino zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.Albino))); + _ = __result.Add(CreateActionClass("DarkZombieAction", "Dark Zombie Event", "Creates some dark slimer zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.DarkSlimer))); + _ = __result.Add(CreateActionClass("NormalZombieAction", "Normal Zombie Event", "Creates some normal zombies", cat, (amount, boughtBy) => SpawnZombies(amount, boughtBy, ZombieType.Normal))); + _ = __result.Add(CreateActionClass("KillAllZombies", "Kill All Zombies", "Instantly kills all zombies on the map", cat, (amount, boughtBy) => KillAllZombies(boughtBy))); + _ = __result.Add(CreateActionClass("AllZombiesRage", "Zombies Rage Event", "Makes all zombies rage", cat, (amount, boughtBy) => AllZombiesRage(boughtBy))); + _ = __result.Add(CreateActionClass("SuperZombieDropRaid", "Super Zombie Drop", "Creates a drop raid with super zombies", cat, (amount, boughtBy) => SuperZombieDropRaid(amount, boughtBy))); } - static MethodBase TargetMethod() + public static (string, IntVec3) SpawnZombies(int amount, string boughtBy, ZombieType type) { - var tRimConnectAPI = AccessTools.TypeByName("RimConnection.RimConnectAPI"); - if (tRimConnectAPI == null) return null; - return AccessTools.Method(tRimConnectAPI, "GetCommands"); + var map = Find.CurrentMap; + if (map == null) return (null, IntVec3.Invalid); + var tickManager = map.GetComponent(); + if (tickManager == null) return (null, IntVec3.Invalid); + var available = Mathf.Max(0, ZombieSettings.Values.maximumNumberOfZombies - tickManager.ZombieCount()); + amount = Mathf.Min(available, amount); + if (amount == 0) return (null, IntVec3.Invalid); + + var cellValidator = Tools.ZombieSpawnLocator(map, true); + var spot = ZombiesRising.GetValidSpot(map, IntVec3.Invalid, cellValidator); + tickManager.rimConnectActions.Enqueue(map => ZombiesRising.TryExecute(map, amount, spot, false, true, type)); + return ($"{boughtBy} created an event with {amount} {type.ToString().ToLower()} zombies", spot); } - static void Postfix(IList __result) + public static (string, IntVec3) KillAllZombies(string boughtBy) { - var zlObj = new List(); - foreach (var obj in __result) + var map = Find.CurrentMap; + if (map == null) return (null, IntVec3.Invalid); + var tickManager = map.GetComponent(); + if (tickManager == null) return (null, IntVec3.Invalid); + tickManager.allZombiesCached.Do(zombie => { - var cmd = RimConnectSupport.Command.Convert(obj); - var action = RimConnectSupport.LookupAction(cmd.actionHash); - if (action != null) + for (int i = 0; i < 1000; i++) { - RimConnectSupport.QueueRimConnectAction(map => action(map, cmd.amount, cmd.boughtBy)); - zlObj.Add(obj); + var dinfo = new DamageInfo(DamageDefOf.Crush, 100f, 100f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null, true, true); + dinfo.SetIgnoreInstantKillProtection(true); + _ = zombie.TakeDamage(dinfo); + if (zombie.Destroyed) + break; } - } - foreach (var obj in zlObj) - __result.Remove(obj); + }); + return ($"{boughtBy} killed all zombies on the map", IntVec3.Invalid); } - } - public class RimConnectSupport - { - public delegate void ZombieAction(Map map, int amount, string user); - public static Dictionary zlCommands = new Dictionary(); + public static (string, IntVec3) AllZombiesRage(string boughtBy) + { + var map = Find.CurrentMap; + if (map == null) return (null, IntVec3.Invalid); + var tickManager = map.GetComponent(); + if (tickManager == null) return (null, IntVec3.Invalid); + tickManager.allZombiesCached.Do(zombie => ZombieStateHandler.StartRage(zombie)); + return ($"{boughtBy} made all zombies on the map rage", IntVec3.Invalid); + } - public class ValidCommand + public static (string, IntVec3) SuperZombieDropRaid(int amount, string boughtBy) { -#pragma warning disable IDE1006 - public string actionHash { get; set; } - public string name { get; set; } - public string description { get; set; } - public string category { get; set; } - public string prefix { get; set; } - public bool shouldShowAmount { get; set; } - public int localCooldownMs { get; set; } - public int globalCooldownMs { get; set; } - public int costSilverStore { get; set; } - public string bitStoreSKU { get; set; } -#pragma warning restore IDE1006 - - public void UpdateActionHash() + var map = Find.CurrentMap; + if (map == null) return (null, IntVec3.Invalid); + var tickManager = map.GetComponent(); + if (tickManager == null) return (null, IntVec3.Invalid); + var available = Mathf.Max(0, ZombieSettings.Values.maximumNumberOfZombies - tickManager.ZombieCount()); + amount = Mathf.Min(available, amount); + if (amount == 0) return (null, IntVec3.Invalid); + + if (DropCellFinder.TryFindRaidDropCenterClose(out var spot, map) == false) return (null, IntVec3.Invalid); + + var zombies = new List(); + for (var i = 1; i <= amount; i++) { - var input = $"{name}{description}{category}{prefix}"; - var hash = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(input)); + var enumerator = ZombieGenerator.SpawnZombieIterativ(IntVec3.Invalid, map, ZombieType.Normal, zombie => + { + zombie.rubbleCounter = Constants.RUBBLE_AMOUNT; + zombie.state = ZombieState.Wandering; + PawnComponentsUtility.AddComponentsForSpawn(zombie); + var job = JobMaker.MakeJob(CustomDefs.Stumble, zombie); + zombie.jobs.StartJob(job); + + zombies.Add(zombie); + }); + while (enumerator.MoveNext()) ; + } - var sb = new StringBuilder(); - foreach (byte b in hash) _ = sb.Append(b.ToString("X2")); + DropPodUtility.DropThingsNear(spot, map, zombies, 0, false, false, true, false); - actionHash = sb.ToString(); - } + return ($"{boughtBy} created an drop raid with {amount} super zombies", spot); } - public class Command + public static object CreateActionClass(string className, string name, string description, string category, Func action) { -#pragma warning disable IDE1006 - public string actionHash { get; set; } - public int amount { get; set; } - public string boughtBy { get; set; } -#pragma warning restore IDE1006 + var tAction = AccessTools.TypeByName("RimConnection.Action"); + var mExecute = AccessTools.Method(tAction, "Execute"); + var fValueTuple_Item1 = AccessTools.Field(typeof(ValueTuple), "Item1"); + var fValueTuple_Item2 = AccessTools.Field(typeof(ValueTuple), "Item2"); + + var assemblyName = new AssemblyName("RimConnectSupport"); + var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); + var moduleBuilder = assemblyBuilder.DefineDynamicModule("DefaultModule"); + var attr1 = TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.ExplicitLayout; + var typeBuilder = moduleBuilder.DefineType(className, attr1, tAction); + + var constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]); + var gen1 = constructorBuilder.GetILGenerator(); + gen1.Emit(OpCodes.Ldarg_0); + gen1.Emit(OpCodes.Call, AccessTools.DeclaredConstructor(tAction, new Type[0])); + gen1.Emit(OpCodes.Ldarg_0); + gen1.Emit(OpCodes.Ldstr, name); + gen1.Emit(OpCodes.Call, AccessTools.PropertySetter(tAction, "Name")); + gen1.Emit(OpCodes.Ldarg_0); + gen1.Emit(OpCodes.Ldstr, description); + gen1.Emit(OpCodes.Call, AccessTools.PropertySetter(tAction, "Description")); + gen1.Emit(OpCodes.Ldarg_0); + gen1.Emit(OpCodes.Ldstr, category); + gen1.Emit(OpCodes.Call, AccessTools.PropertySetter(tAction, "Category")); + gen1.Emit(OpCodes.Ret); + + var attr2 = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final; + var methodBuilder = typeBuilder.DefineMethod("Execute", attr2, CallingConventions.HasThis, typeof(void), new[] { typeof(int), typeof(string) }); + var gen2 = methodBuilder.GetILGenerator(); + gen2.Emit(OpCodes.Ldstr, name); + gen2.Emit(OpCodes.Ldarg_1); + gen2.Emit(OpCodes.Ldarg_2); + gen2.Emit(OpCodes.Call, AccessTools.Method(typeof(RimConnectSupport), nameof(RimConnectSupport.Execute))); + gen2.Emit(OpCodes.Call, SymbolExtensions.GetMethodInfo(() => BadEventNotification(default))); + gen2.Emit(OpCodes.Ret); + typeBuilder.DefineMethodOverride(methodBuilder, mExecute); + + actions[name] = action; + return Activator.CreateInstance(typeBuilder.CreateType()); + } - public static Command Convert(object cmd) - { - var trv = Traverse.Create(cmd); - var actionHash = trv.Property("actionHash").GetValue(); - var amount = trv.Property("amount").GetValue(); - var boughtBy = trv.Property("boughtBy").GetValue(); - return new Command() { actionHash = actionHash, amount = amount, boughtBy = boughtBy }; - } + static readonly MethodInfo mBadEventNotification = AccessTools.Method("RimConnection.AlertManager:BadEventNotification", new[] { typeof(string), typeof(IntVec3) }); + public static void BadEventNotification(ValueTuple tuple) + { + if (tuple.Item1.NullOrEmpty() == false) + _ = mBadEventNotification.Invoke(null, new object[] { tuple.Item1, tuple.Item2 }); } - public static void AddCommand(IList list, string name, string description, int costs, ZombieAction action) + public static (string, IntVec3) Execute(string name, int amount, string boughtBy) { - var cmd = new ValidCommand - { - name = name, - description = description, - category = "Event", - prefix = "Spawn", - localCooldownMs = 120000, - globalCooldownMs = 60000, - costSilverStore = costs, - bitStoreSKU = "" - }; - cmd.UpdateActionHash(); - - zlCommands[cmd.actionHash] = action; - - var tValidCommand = AccessTools.TypeByName("RimConnection.ValidCommand"); - _ = list.Add(AccessTools.MakeDeepCopy(cmd, tValidCommand)); + if (actions.TryGetValue(name, out var action)) + return action(amount, boughtBy); + return (null, IntVec3.Invalid); } + } - public static ZombieAction LookupAction(string actionHash) + [HarmonyPatch] + class RimConnection_Settings_CommandOptionSettings_Patch + { + static IEnumerable TargetMethods() { - if (zlCommands.TryGetValue(actionHash, out var action)) - return action; - return null; + var method = AccessTools.Method("RimConnection.Settings.CommandOptionSettings:DoWindowContents"); + if (method != null) + yield return method; } - public static void QueueRimConnectAction(Action action) + static IEnumerable Transpiler(IEnumerable instructions) { - var tickManager = Find.CurrentMap?.GetComponent(); - tickManager?.rimConnectActions.Enqueue(action); + var list = instructions.ToList(); + for (var i = 0; i < list.Count; i++) + { + var code = list[i]; + if (code.opcode == OpCodes.Ldarga_S || code.opcode == OpCodes.Ldarga) + { + code = list[i - 1]; + if (code.opcode == OpCodes.Ldc_R4) + { + var value = (float)code.operand; + if (value >= 180) + code.operand = value + 30f; + } + } + } + var idx = list.FindLastIndex(code => code.opcode == OpCodes.Sub); + if (idx > 0 && idx < list.Count) + list.InsertRange(idx + 1, new[] + { + new CodeInstruction(OpCodes.Ldc_R4, 30f), + new CodeInstruction(OpCodes.Sub) + }); + return list.AsEnumerable(); } } } diff --git a/Source/TickManager.cs b/Source/TickManager.cs index ec882746..7f39885a 100644 --- a/Source/TickManager.cs +++ b/Source/TickManager.cs @@ -278,7 +278,7 @@ void HandleIncidents() if (ZombiesRising.ZombiesForNewIncident(this)) { - var success = ZombiesRising.TryExecute(map, incidentInfo.parameters.incidentSize, IntVec3.Invalid); + var success = ZombiesRising.TryExecute(map, incidentInfo.parameters.incidentSize, IntVec3.Invalid, true); if (success == false) Log.Warning("Incident creation failed. Most likely no valid spawn point found."); } diff --git a/Source/ZombieGenerator.cs b/Source/ZombieGenerator.cs index 7d7b9a3a..8859d6d6 100644 --- a/Source/ZombieGenerator.cs +++ b/Source/ZombieGenerator.cs @@ -454,7 +454,8 @@ public static IEnumerator SpawnZombieIterativ(IntVec3 cell, Map map, ZombieType } if (zombie.IsSuicideBomber) zombie.lastBombTick = Find.TickManager.TicksAbs + Rand.Range(0, (int)zombie.bombTickingInterval); - _ = GenPlace.TryPlaceThing(zombie, cell, map, ThingPlaceMode.Direct); + if (cell.IsValid) + _ = GenPlace.TryPlaceThing(zombie, cell, map, ThingPlaceMode.Direct); yield return null; callback?.Invoke(zombie); ZombiesSpawning--; diff --git a/Source/ZombieIncidents.cs b/Source/ZombieIncidents.cs index 87e3ce1a..407efa13 100644 --- a/Source/ZombieIncidents.cs +++ b/Source/ZombieIncidents.cs @@ -201,7 +201,7 @@ public static Predicate SpotValidator(Predicate cellValidator) }; } - static IEnumerator SpawnEventProcess(Map map, int incidentSize, IntVec3 spot, Predicate cellValidator, bool ignoreLimit, ZombieType zombieType = ZombieType.Random) + static IEnumerator SpawnEventProcess(Map map, int incidentSize, IntVec3 spot, Predicate cellValidator, bool useAlert, bool ignoreLimit, ZombieType zombieType = ZombieType.Random) { var zombiesSpawning = 0; var counter = 1; @@ -228,16 +228,19 @@ static IEnumerator SpawnEventProcess(Map map, int incidentSize, IntVec3 spot, Pr if (zombiesSpawning > 3) { - var headline = "LetterLabelZombiesRising".Translate(); - var text = "ZombiesRising".Translate(); - if (ZombieSettings.Values.spawnHowType == SpawnHowType.AllOverTheMap) + if (useAlert) { - headline = "LetterLabelZombiesRisingNearYourBase".Translate(); - text = "ZombiesRisingNearYourBase".Translate(); - } + var headline = "LetterLabelZombiesRising".Translate(); + var text = "ZombiesRising".Translate(); + if (ZombieSettings.Values.spawnHowType == SpawnHowType.AllOverTheMap) + { + headline = "LetterLabelZombiesRisingNearYourBase".Translate(); + text = "ZombiesRisingNearYourBase".Translate(); + } - var location = new GlobalTargetInfo(spot, map); - Find.LetterStack.ReceiveLetter(headline, text, LetterDefOf.ThreatSmall, location); + var location = new GlobalTargetInfo(spot, map); + Find.LetterStack.ReceiveLetter(headline, text, LetterDefOf.ThreatSmall, location); + } var isSubstantialZombieCount = zombiesSpawning > Tools.CapableColonists(map) * 4; if (isSubstantialZombieCount && Constants.USE_SOUND && Prefs.VolumeAmbient > 0f) @@ -245,9 +248,8 @@ static IEnumerator SpawnEventProcess(Map map, int incidentSize, IntVec3 spot, Pr } } - public static bool TryExecute(Map map, int incidentSize, IntVec3 spot, bool ignoreLimit = false, ZombieType zombieType = ZombieType.Random) + public static IntVec3 GetValidSpot(Map map, IntVec3 spot, Predicate cellValidator) { - var cellValidator = Tools.ZombieSpawnLocator(map, true); var spotValidator = SpotValidator(cellValidator); for (var counter = 1; counter <= 10; counter++) @@ -258,10 +260,15 @@ public static bool TryExecute(Map map, int incidentSize, IntVec3 spot, bool igno var allOverTheMap = ZombieSettings.Values.spawnHowType == SpawnHowType.AllOverTheMap; spot = Tools.RandomSpawnCell(map, allOverTheMap == false, spotValidator); } - if (spot.IsValid == false) - return false; + return spot; + } - _ = Find.CameraDriver.StartCoroutine(SpawnEventProcess(map, incidentSize, spot, cellValidator, ignoreLimit, zombieType)); + public static bool TryExecute(Map map, int incidentSize, IntVec3 spot, bool useAlert, bool ignoreLimit = false, ZombieType zombieType = ZombieType.Random) + { + var cellValidator = Tools.ZombieSpawnLocator(map, true); + spot = GetValidSpot(map, spot, cellValidator); + if (spot.IsValid == false) return false; + _ = Find.CameraDriver.StartCoroutine(SpawnEventProcess(map, incidentSize, spot, cellValidator, useAlert, ignoreLimit, zombieType)); return true; } } diff --git a/Source/ZombieLand.csproj b/Source/ZombieLand.csproj index 4f07be69..1a29e08a 100644 --- a/Source/ZombieLand.csproj +++ b/Source/ZombieLand.csproj @@ -10,7 +10,7 @@ ..\1.3\Assemblies\ true false - 2.3.2.0 + 2.3.3.0 Copyright © 2017