using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using ValheimDynasty.Camps; using ValheimDynasty.Core; using ValheimDynasty.DebugTools; using ValheimDynasty.Needs; using ValheimDynasty.Net; using ValheimDynasty.Quests; using ValheimDynasty.Raids; using ValheimDynasty.Recruitment; using ValheimDynasty.Seasons; using ValheimDynasty.Villagers; using ValheimDynasty.Villages; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("LivingWorld")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.10.0.0")] [assembly: AssemblyInformationalVersion("0.10.0")] [assembly: AssemblyProduct("LivingWorld")] [assembly: AssemblyTitle("LivingWorld")] [assembly: AssemblyVersion("0.10.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ValheimDynasty { [BepInPlugin("com.firstphase.livingworld", "Living World", "0.19.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class DynastyPlugin : BaseUnityPlugin { public const string ModGuid = "com.firstphase.livingworld"; public const string ModName = "Living World"; public const string ModVersion = "0.19.0"; private Harmony _harmony; private ModuleHost _modules; internal static bool HideOwnUi; internal static DynastyPlugin Instance { get; private set; } internal static ManualLogSource Log { get; private set; } internal static bool VerboseOn { get { if (ModConfig.VerboseLog != null) { return ModConfig.VerboseLog.Value; } return false; } } private void Awake() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; ModConfig.Bind(((BaseUnityPlugin)this).Config); NeedsConfig.Bind(((BaseUnityPlugin)this).Config); SeasonsConfig.Bind(((BaseUnityPlugin)this).Config); VillagersConfig.Bind(((BaseUnityPlugin)this).Config); VillagesConfig.Bind(((BaseUnityPlugin)this).Config); RecruitConfig.Bind(((BaseUnityPlugin)this).Config); CampConfig.Bind(((BaseUnityPlugin)this).Config); QuestConfig.Bind(((BaseUnityPlugin)this).Config); _harmony = new Harmony("com.firstphase.livingworld"); GamePatches.Apply(_harmony); SeasonPatches.Apply(_harmony); DevCommandFile.Apply(_harmony); VillageScreen.Apply(_harmony); CampDeathPatch.Apply(_harmony); CampWar.Apply(_harmony); NetSync.Init(); DebugCommands.Register(); NeedsItems.Register(); VillagerPrefab.Register(); BanditPrefab.Register(); VillageTotemPiece.Register(); _modules = new ModuleHost(); _modules.Register(new GameCalendar()); _modules.Register(new NeedsModule()); _modules.Register(new SeasonsModule()); _modules.InitAll(); Log.LogInfo((object)"Living World 0.19.0 loaded. This is an unofficial mod, not supported by Iron Gate."); } private void Update() { float deltaTime = Time.deltaTime; Perf.Frame(); Safe.Run("WorldLifecycle", WorldLifecycle.Tick); Safe.Run("WorldScan", WorldScan.Tick); Safe.Run("NetSync", NetSync.Tick); _modules?.TickAll(deltaTime); Safe.Run("DebugOverlay.Input", DebugOverlay.HandleInput); Safe.Run("DevCommandFile", DevCommandFile.Tick); Safe.Run("VillageScreen", VillageScreen.Tick); Safe.Run("TalkScreen", TalkScreen.Tick); Safe.Run("Wanderers", WandererSpawner.Tick); Safe.Run("WandererPins", WandererPins.Tick); Safe.Run("CampSim", CampSim.Tick); Safe.Run("CampMaterializer", CampMaterializer.Tick); Safe.Run("QuestSim", QuestSim.Tick); Safe.Run("QuestWorld", QuestWorld.Tick); Safe.Run("QuestLog", QuestLog.Tick); Safe.Run("TownCatchUp", TownCatchUp.Tick); Safe.Run("Guide", GuideScreen.Tick); Safe.Run("VillageProgress", VillageProgress.Tick); } private void OnGUI() { if (!HideOwnUi) { Safe.Run("DebugOverlay.Draw", delegate { DebugOverlay.Draw(_modules); }); Safe.Run("NeedsHud.Draw", NeedsHud.Draw); Safe.Run("TownPlanView.Draw", TownPlanView.Draw); Safe.Run("VillageScreen.Draw", VillageScreen.Draw); Safe.Run("TalkScreen.Draw", TalkScreen.Draw); Safe.Run("QuestLog.Draw", QuestLog.Draw); Safe.Run("Guide.Draw", GuideScreen.Draw); } } private void OnApplicationQuit() { ModData.SaveIfServer("application quit"); } private void OnDestroy() { ModData.SaveIfServer("plugin destroyed"); _modules?.ShutdownAll(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } } namespace ValheimDynasty.Villages { internal static class Blueprints { public enum Use { Structure, Bed, Workbench, Chest, Furniture } internal sealed class Part { public string Prefab; public string[] Alt; public Vector3 Local; public float Yaw; public Use Use; public int MinStage; public bool OnGround; public Part(string prefab, float x, float y, float z, float yaw, Use use = Use.Structure, params string[] alt) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) Prefab = prefab; Local = new Vector3(x, y, z); Yaw = yaw; Use = use; Alt = alt; } } internal sealed class Plan { public string Name; public float Raise; public Vector2 Half; public int Length; public List Parts = new List(); public int Stairs; public float DoorX; public bool HasDoor; } internal sealed class Site { public Plan Plan; public float Yaw; public string Tag; public string Key; public Func Make; public int MinStairs; public Vector3 Pos; public Quaternion Rot; public float Base; public bool Started; public bool Walkable; public float Floor => Base + Plan.Raise; public Vector3 World(Part p) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Pos + Rot * new Vector3(p.Local.x, 0f, p.Local.z); val.y = ((p.OnGround && (Object)(object)ZoneSystem.instance != (Object)null) ? (ZoneSystem.instance.GetGroundHeight(val) + p.Local.y) : (Base + Plan.Raise + p.Local.y)); return val; } public Quaternion WorldRot(Part p) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) return Rot * Quaternion.Euler(0f, p.Yaw, 0f); } public Vector3 Local(Vector3 w) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) return Quaternion.Inverse(Rot) * (w - Pos); } public bool Contains(Vector3 w, float margin) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Local(w); if (Mathf.Abs(val.x) <= Plan.Half.x + margin && val.z >= 0f - Plan.Half.y - margin) { return val.z <= Plan.Half.y + 2f * (float)Plan.Stairs + margin; } return false; } public bool Inside(Vector3 w, float margin) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Local(w); if (Mathf.Abs(val.x) <= Plan.Half.x + margin) { return Mathf.Abs(val.z) <= Plan.Half.y + margin; } return false; } public Vector3 Outside(Vector3 w) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Local(w); float num = Plan.Half.x + 0.9f; float num2 = Plan.Half.y + 0.9f; Vector3[] obj = new Vector3[4] { new Vector3(0f - num, 0f, Mathf.Clamp(val.z, 0f - Plan.Half.y, Plan.Half.y)), new Vector3(num, 0f, Mathf.Clamp(val.z, 0f - Plan.Half.y, Plan.Half.y)), new Vector3(Mathf.Clamp(val.x, 0f - Plan.Half.x, Plan.Half.x), 0f, 0f - num2), new Vector3(Mathf.Clamp(val.x, 0f - Plan.Half.x, Plan.Half.x), 0f, num2) }; Vector3 val2 = obj[0]; float num3 = float.MaxValue; Vector3[] array = (Vector3[])(object)obj; foreach (Vector3 val3 in array) { Vector3 val4 = val3 - new Vector3(val.x, 0f, val.z); float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude; if (sqrMagnitude < num3) { num3 = sqrMagnitude; val2 = val3; } } Vector3 val5 = Pos + Rot * val2; val5.y = ZoneSystem.instance.GetGroundHeight(val5); return val5; } public Vector3 Ground(float x, float z) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Pos + Rot * new Vector3(x, 0f, z); val.y = ZoneSystem.instance.GetGroundHeight(val); return val; } } private sealed class PlanCache { public float At; public List Sites; } internal sealed class PlanEdit { public bool Cancel; public float Dx; public float Dz; public float Rot; } private struct Range { public float Lo; public float Hi; public float At; } private sealed class TownCache { public float At; public List Sites = new List(); } private static readonly Dictionary WorkshopCache = new Dictionary(); private static readonly Dictionary StorehouseCache = new Dictionary(); public const int HutBeds = 3; private static readonly Dictionary HutCache = new Dictionary(); public static readonly int[] HouseLengths = new int[4] { 6, 8, 10, 12 }; public const int MaxStairs = 6; public const float MaxDrop = 4f; private static readonly Dictionary HouseCache = new Dictionary(); private static readonly Vector2[] HouseDirs = (Vector2[])(object)new Vector2[4] { new Vector2(-1f, 0f), new Vector2(0f, 1f), new Vector2(0f, -1f), new Vector2(-1f, -1f) }; private static readonly float[] HouseYaws = new float[4] { 90f, 180f, 0f, 45f }; private static readonly float[] HouseGap = new float[4] { 6f, 6f, 19f, 14f }; private static readonly float[] PushBack = new float[3] { 0f, 2f, 4f }; private static readonly List Theirs = new List(); public const string KSite = "vd_site"; private static readonly List Hits = new List(); private static readonly Vector3[] StoreSpots = (Vector3[])(object)new Vector3[4] { new Vector3(11f, 0f, -8f), new Vector3(11f, 0f, 9f), new Vector3(-11f, 0f, -9f), new Vector3(19f, 0f, 0f) }; private static readonly float[] StoreYaws = new float[4] { -90f, -90f, 90f, -90f }; private static readonly Vector3[] OldStoreSpots = (Vector3[])(object)new Vector3[1] { new Vector3(10f, 0f, 10f) }; private static readonly float[] OldStoreYaws = new float[1] { -135f }; private static readonly Dictionary SiteCache = new Dictionary(); private static Dictionary _edits = new Dictionary(); private static readonly Dictionary Ranges = new Dictionary(); private static readonly Dictionary Towns = new Dictionary(); public static Plan Workshop => WorkshopWith(1); public static Plan Storehouse => StorehouseWith(1); private static void Skirt(List L, float hx, float hz, float doorX, bool frontOpen) { for (float num = 0f - hz + 1f; num < hz; num += 2f) { L.Add(new Part("wood_wall_half", 0f - hx, -0.5f, num, 90f, Use.Structure)); L.Add(new Part("wood_wall_half", hx, -0.5f, num, 90f, Use.Structure)); } for (float num2 = 0f - hx + 1f; num2 < hx; num2 += 2f) { L.Add(new Part("wood_wall_half", num2, -0.5f, 0f - hz, 0f, Use.Structure)); if (!frontOpen && Mathf.Abs(num2 - doorX) > 0.5f) { L.Add(new Part("wood_wall_half", num2, -0.5f, hz, 0f, Use.Structure)); } } } private static void StairsDown(List L, float x, float hz, int n) { for (int i = 0; i < n; i++) { L.Add(new Part("wood_stair", x, -1f - (float)i, hz + 1f + 2f * (float)i, 0f, Use.Structure)); } float z = hz + 2f * (float)n + 0.7f; float[] array = new float[2] { -1.6f, 1.6f }; foreach (float num in array) { L.Add(new Part("piece_groundtorch_wood", x + num, 0f, z, 0f, Use.Furniture) { OnGround = true, MinStage = 2 }); } } public static Plan WorkshopWith(int stairs) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) if (WorkshopCache.TryGetValue(stairs, out var value)) { return value; } Plan plan = new Plan { Name = "workshop", Raise = 0.3f, Half = new Vector2(2f, 3f), Stairs = stairs, DoorX = 0f, HasDoor = true }; List parts = plan.Parts; float[] array = new float[2] { -2f, 2f }; foreach (float x in array) { float[] array2 = new float[4] { -3f, -1f, 1f, 3f }; foreach (float z in array2) { parts.Add(new Part("wood_pole2", x, -1f, z, 0f, Use.Structure)); } } array = new float[2] { -1f, 1f }; foreach (float x2 in array) { float[] array2 = new float[3] { -2f, 0f, 2f }; foreach (float z2 in array2) { parts.Add(new Part("wood_floor", x2, 0f, z2, 0f, Use.Structure)); } } parts.Add(new Part("piece_chest_wood", 1.3f, 0f, 0.6f, 90f, Use.Chest)); parts.Add(new Part("piece_workbench", 0f, 0f, -2.2f, 0f, Use.Workbench)); parts.Add(new Part("piece_workbench_ext1", -1.3f, 0f, 1f, 0f, Use.Furniture) { MinStage = 2 }); parts.Add(new Part("piece_workbench_ext2", -1.45f, 0f, -0.9f, 90f, Use.Furniture) { MinStage = 2 }); parts.Add(new Part("piece_workbench_ext3", 1.35f, 0f, -1.3f, -90f, Use.Furniture) { MinStage = 2 }); parts.Add(new Part("piece_workbench_ext4", 1.85f, 1.1f, 2f, -90f, Use.Furniture) { MinStage = 2 }); parts.Add(new Part("forge", 3.8f, 0f, -1.2f, 90f, Use.Furniture) { MinStage = 2, OnGround = true }); parts.Add(new Part("smelter", 3.9f, 0f, 1.7f, 90f, Use.Furniture) { MinStage = 2, OnGround = true }); parts.Add(new Part("charcoal_kiln", 3.9f, 0f, 4.6f, 90f, Use.Furniture) { MinStage = 2, OnGround = true }); StairsDown(parts, 0f, 3f, stairs); Skirt(parts, 2f, 3f, 0f, frontOpen: true); array = new float[2] { 1f, 3f }; foreach (float y in array) { float[] array2 = new float[2] { -1f, 1f }; foreach (float x3 in array2) { parts.Add(new Part("woodwall", x3, y, -3f, 0f, Use.Structure)); } array2 = new float[3] { -2f, 0f, 2f }; foreach (float z3 in array2) { parts.Add(new Part("woodwall", -2f, y, z3, 90f, Use.Structure)); parts.Add(new Part("woodwall", 2f, y, z3, 90f, Use.Structure)); } } array = new float[3] { -2f, 0f, 2f }; foreach (float z4 in array) { parts.Add(new Part("wood_roof", 1f, 4f, z4, 90f, Use.Structure)); parts.Add(new Part("wood_roof", -1f, 4f, z4, -90f, Use.Structure)); } parts.Add(new Part("wood_wall_roof", 1f, 4f, -3f, 180f, Use.Structure)); parts.Add(new Part("wood_wall_roof", -1f, 4f, -3f, 0f, Use.Structure)); WorkshopCache[stairs] = plan; return plan; } public static Plan StorehouseWith(int stairs) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) if (StorehouseCache.TryGetValue(stairs, out var value)) { return value; } Plan plan = new Plan { Name = "storehouse", Raise = 0.3f, Half = new Vector2(3f, 3f), Stairs = stairs, DoorX = 0f, HasDoor = true }; List parts = plan.Parts; float[] array = new float[4] { -3f, -1f, 1f, 3f }; foreach (float num in array) { float[] array2 = new float[4] { -3f, -1f, 1f, 3f }; foreach (float num2 in array2) { if (Mathf.Abs(num) == 3f || Mathf.Abs(num2) == 3f) { parts.Add(new Part("wood_pole2", num, -1f, num2, 0f, Use.Structure)); } } } array = new float[3] { -2f, 0f, 2f }; foreach (float x in array) { float[] array2 = new float[3] { -2f, 0f, 2f }; foreach (float z in array2) { parts.Add(new Part("wood_floor", x, 0f, z, 0f, Use.Structure)); } } StairsDown(parts, 0f, 3f, stairs); Skirt(parts, 3f, 3f, 0f, frontOpen: false); array = new float[2] { 1f, 3f }; foreach (float num3 in array) { float[] array2 = new float[3] { -2f, 0f, 2f }; foreach (float z2 in array2) { parts.Add(new Part("woodwall", -3f, num3, z2, 90f, Use.Structure)); parts.Add(new Part("woodwall", 3f, num3, z2, 90f, Use.Structure)); } array2 = new float[3] { -2f, 0f, 2f }; foreach (float num4 in array2) { parts.Add(new Part("woodwall", num4, num3, -3f, 0f, Use.Structure)); parts.Add((num3 < 2f && num4 == 0f) ? new Part("wood_door", num4, num3, 3f, 0f, Use.Structure) : new Part("woodwall", num4, num3, 3f, 0f, Use.Structure)); } } array = new float[3] { -2f, 0f, 2f }; foreach (float z3 in array) { parts.Add(new Part("wood_roof", 2f, 4f, z3, 90f, Use.Structure)); parts.Add(new Part("wood_roof", -2f, 4f, z3, -90f, Use.Structure)); parts.Add(new Part("wood_roof", 0.5f, 4.75f, z3, 90f, Use.Structure)); parts.Add(new Part("wood_roof", -0.5f, 4.75f, z3, -90f, Use.Structure)); } array = new float[2] { -3f, 3f }; foreach (float z4 in array) { parts.Add(new Part("wood_wall_roof", 2f, 4f, z4, 180f, Use.Structure)); parts.Add(new Part("wood_wall_roof", -2f, 4f, z4, 0f, Use.Structure)); parts.Add(new Part("wood_wall_half", 0f, 4.5f, z4, 0f, Use.Structure)); } array = new float[3] { -1.9f, 0f, 1.9f }; foreach (float x2 in array) { parts.Add(new Part("piece_chest_wood", x2, 0f, -2.45f, 0f, Use.Chest)); } array = new float[2] { -0.9f, 0.9f }; foreach (float z5 in array) { parts.Add(new Part("piece_chest_wood", -2.45f, 0f, z5, 90f, Use.Chest)); parts.Add(new Part("piece_chest_wood", 2.45f, 0f, z5, -90f, Use.Chest)); } StorehouseCache[stairs] = plan; return plan; } public static Plan HutWith(int stairs) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) if (HutCache.TryGetValue(stairs, out var value)) { return value; } value = new Plan { Name = "hut", Raise = 0.3f, Half = new Vector2(2f, 3f), Length = 6, Stairs = stairs, DoorX = 1f, HasDoor = true }; List parts = value.Parts; float[] array = new float[2] { -2f, 2f }; foreach (float x in array) { float[] array2 = new float[4] { -3f, -1f, 1f, 3f }; foreach (float z in array2) { parts.Add(new Part("wood_pole2", x, -1f, z, 0f, Use.Structure)); } } array = new float[2] { -1f, 1f }; foreach (float x2 in array) { float[] array2 = new float[3] { -2f, 0f, 2f }; foreach (float z2 in array2) { parts.Add(new Part("wood_floor", x2, 0f, z2, 0f, Use.Structure)); } } array = new float[3] { -2.2f, -0.8f, 0.6f }; foreach (float z3 in array) { parts.Add(new Part("bed", -0.55f, 0f, z3, 90f, Use.Bed)); } StairsDown(parts, 1f, 3f, stairs); Skirt(parts, 2f, 3f, 1f, frontOpen: false); array = new float[3] { -2f, 0f, 2f }; foreach (float z4 in array) { parts.Add(new Part("woodwall", -2f, 1f, z4, 90f, Use.Structure)); parts.Add(new Part("woodwall", 2f, 1f, z4, 90f, Use.Structure)); } array = new float[2] { -1f, 1f }; foreach (float num in array) { parts.Add(new Part("woodwall", num, 1f, -3f, 0f, Use.Structure)); parts.Add((num == 1f) ? new Part("wood_door", num, 1f, 3f, 0f, Use.Structure) : new Part("woodwall", num, 1f, 3f, 0f, Use.Structure)); } array = new float[3] { -2f, 0f, 2f }; foreach (float z5 in array) { parts.Add(new Part("wood_roof", 1f, 2f, z5, 90f, Use.Structure)); parts.Add(new Part("wood_roof", -1f, 2f, z5, -90f, Use.Structure)); } array = new float[2] { -3f, 3f }; foreach (float z6 in array) { parts.Add(new Part("wood_wall_roof", 1f, 2f, z6, 180f, Use.Structure)); parts.Add(new Part("wood_wall_roof", -1f, 2f, z6, 0f, Use.Structure)); } HutCache[stairs] = value; return value; } public static int Capacity(int length) { return 2 * Mathf.FloorToInt(((float)length - 3.4f) / 1.6f); } public static int LengthFor(int beds) { int[] houseLengths = HouseLengths; foreach (int num in houseLengths) { if (Capacity(num) >= beds) { return num; } } return HouseLengths[HouseLengths.Length - 1]; } public static float Drop(Site s) { GroundRange(s, out var lo, out var hi); return hi - lo; } public static Plan Longhouse(int length, int beds, int stairs) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) string key = length + "|" + beds + "|" + stairs; if (HouseCache.TryGetValue(key, out var value)) { return value; } float num = (float)length / 2f; value = new Plan { Name = "longhouse", Raise = 1f, Half = new Vector2(4f, num), Length = length, Stairs = stairs, DoorX = 1f, HasDoor = true }; List parts = value.Parts; List list = new List(); for (float num2 = 0f - num; num2 <= num + 0.01f; num2 += 2f) { list.Add(num2); } float[] array = new float[3] { -4f, 0f, 4f }; foreach (float x in array) { foreach (float item in list) { parts.Add(new Part("wood_pole2", x, -1f, item, 0f, Use.Structure)); } } List list2 = new List(); for (float num3 = 0f - num + 1f; num3 < num; num3 += 2f) { list2.Add(num3); } array = new float[4] { -3f, -1f, 1f, 3f }; foreach (float x2 in array) { foreach (float item2 in list2) { parts.Add(new Part("wood_floor", x2, 0f, item2, 0f, Use.Structure)); } } int num4 = Capacity(length) / 2; int num5 = 0; for (int j = 0; j < num4; j++) { if (num5 >= beds) { break; } float z = 0f - num + 0.95f + 1.6f * (float)j; parts.Add(new Part("bed", -2.45f, 0f, z, 90f, Use.Bed)); num5++; if (num5 < beds) { parts.Add(new Part("bed", 2.45f, 0f, z, -90f, Use.Bed)); num5++; } } StairsDown(parts, 1f, num, stairs); Skirt(parts, 4f, num, 1f, frontOpen: false); array = new float[2] { 1f, 3f }; foreach (float num6 in array) { foreach (float item3 in list2) { parts.Add(new Part("woodwall", -4f, num6, item3, 90f, Use.Structure)); parts.Add(new Part("woodwall", 4f, num6, item3, 90f, Use.Structure)); } float[] array2 = new float[4] { -3f, -1f, 1f, 3f }; foreach (float num7 in array2) { parts.Add(new Part("woodwall", num7, num6, 0f - num, 0f, Use.Structure)); parts.Add((num6 < 2f && num7 == 1f) ? new Part("wood_door", num7, num6, num, 0f, Use.Structure) : new Part("woodwall", num7, num6, num, 0f, Use.Structure)); } } foreach (float item4 in list2) { parts.Add(new Part("wood_roof", 3f, 4f, item4, 90f, Use.Structure)); parts.Add(new Part("wood_roof", -3f, 4f, item4, -90f, Use.Structure)); parts.Add(new Part("wood_roof", 1f, 5f, item4, 90f, Use.Structure)); parts.Add(new Part("wood_roof", -1f, 5f, item4, -90f, Use.Structure)); } array = new float[2] { 0f - num, num }; foreach (float z2 in array) { parts.Add(new Part("wood_wall_roof", 3f, 4f, z2, 180f, Use.Structure)); parts.Add(new Part("wood_wall_roof", -3f, 4f, z2, 0f, Use.Structure)); parts.Add(new Part("wood_wall_half", 1f, 4.5f, z2, 0f, Use.Structure)); parts.Add(new Part("wood_wall_half", -1f, 4.5f, z2, 0f, Use.Structure)); parts.Add(new Part("wood_wall_roof", 1f, 5f, z2, 180f, Use.Structure)); parts.Add(new Part("wood_wall_roof", -1f, 5f, z2, 0f, Use.Structure)); } parts.Add(new Part("piece_table", -1.6f, 0f, num - 1.5f, 0f, Use.Furniture) { MinStage = 1 }); parts.Add(new Part("piece_bench01", -1.6f, 0f, num - 2.5f, 0f, Use.Furniture, "piece_logbench01") { MinStage = 1 }); parts.Add(new Part("piece_bench01", -1.6f, 0f, num - 0.5f, 180f, Use.Furniture, "piece_logbench01") { MinStage = 1 }); HouseCache[key] = value; return value; } private static void HouseFrame(Vector3 villageCenter, Quaternion face, int slot, int length, out Vector3 pos, out Quaternion rot, float extra = 0f) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) float num = HouseGap[slot] + extra + (float)length / 2f; Vector2 normalized = ((Vector2)(ref HouseDirs[slot])).normalized; pos = villageCenter + face * new Vector3(normalized.x * num, 0f, normalized.y * num); pos.y = 0f; rot = face * Quaternion.Euler(0f, HouseYaws[slot], 0f); } private static int StairsFor(Site s, float doorX, int min) { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) float floor = s.Floor; float y = s.Plan.Half.y; if (s.Started) { int num = 0; for (int i = 0; i < 6; i++) { Vector3 at = s.Pos + s.Rot * new Vector3(doorX, 0f, y + 1f + 2f * (float)i); at.y = floor - 1f - (float)i; if (!VillageLayout.Built("wood_stair", at)) { break; } num = i + 1; } if (num > 0) { return Mathf.Max(num, min); } } if (min <= 0 && s.Ground(doorX, y + 0.8f).y >= floor - 0.2f) { return 0; } int j; for (j = 1; j < 6 && !(s.Ground(doorX, y + 2f * (float)j).y >= floor - (float)j - 0.1f); j++) { } return j; } private static Site Place(Vector3 c, Quaternion face, Vector3 local, float yaw, float baseHeight, Func make, int minStairs, string key = null) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) Site site = new Site { Yaw = yaw, Base = baseHeight, Plan = make(1), Key = key, Make = make, MinStairs = minStairs }; site.Pos = c + face * local; site.Pos.y = 0f; site.Rot = face * Quaternion.Euler(0f, yaw, 0f); Edit(site, face); ResolveBase(site); site.Plan = make(Mathf.Max(minStairs, StairsFor(site, site.Plan.DoorX, minStairs))); Footings(site); return site; } private static void Footings(Site s) { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZoneSystem.instance == (Object)null) { return; } List list = null; foreach (Part part in s.Plan.Parts) { float num; if (part.Prefab == "wood_pole2" && part.Local.y <= -0.9f) { num = part.Local.y - 1f; } else { if (!(part.Prefab == "wood_stair")) { continue; } num = part.Local.y; } Vector3 val = s.Pos + s.Rot * new Vector3(part.Local.x, 0f, part.Local.z); float num2 = s.Floor + num - ZoneSystem.instance.GetGroundHeight(val); if (num2 < 0.4f) { continue; } int num3 = Mathf.Min(4, Mathf.CeilToInt((num2 - 0.2f) / 2f)); for (int i = 1; i <= num3; i++) { if (list == null) { list = new List(); } list.Add(new Part("wood_pole2", part.Local.x, num - 1f - 2f * (float)(i - 1), part.Local.z, part.Yaw, Use.Structure)); } } if (list != null) { list.Sort((Part a, Part b) => a.Local.y.CompareTo(b.Local.y)); Plan plan = new Plan { Name = s.Plan.Name, Raise = s.Plan.Raise, Half = s.Plan.Half, Length = s.Plan.Length, Stairs = s.Plan.Stairs, DoorX = s.Plan.DoorX, HasDoor = s.Plan.HasDoor }; plan.Parts.AddRange(list); plan.Parts.AddRange(s.Plan.Parts); s.Plan = plan; } } private static Site HouseSite(Vector3 villageCenter, Quaternion face, int slot, int length, int beds, float baseHeight, float extra = 0f) { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) Site site = new Site(); site.Yaw = HouseYaws[slot]; site.Base = baseHeight; site.Tag = "L|" + slot + "|" + length + "|" + extra.ToString(CultureInfo.InvariantCulture); site.Key = "house" + slot; site.Make = (int n) => Longhouse(length, beds, n); site.MinStairs = 1; Site site2 = site; HouseFrame(villageCenter, face, slot, length, out site2.Pos, out site2.Rot, extra); Edit(site2, face); site2.Plan = Longhouse(length, beds, 1); ResolveBase(site2); site2.Plan = Longhouse(length, beds, StairsFor(site2, 1f, 1)); Footings(site2); return site2; } public static bool Overlaps(Site a, Site b, float margin) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) float num = a.Plan.Half.y + 2f * (float)a.Plan.Stairs; for (float num2 = 0f - a.Plan.Half.x; num2 <= a.Plan.Half.x + 0.01f; num2 += 1f) { for (float num3 = 0f - a.Plan.Half.y; num3 <= num + 0.01f; num3 += 1f) { if (b.Contains(a.Pos + a.Rot * new Vector3(num2, 0f, num3), margin)) { return true; } } } return false; } private static bool OnCommons(Site a, Vector3 villageCenter, Quaternion face) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) Quaternion val = Quaternion.Inverse(face); float num = a.Plan.Half.y + 2f * (float)a.Plan.Stairs; for (float num2 = 0f - a.Plan.Half.x; num2 <= a.Plan.Half.x + 0.01f; num2 += 1f) { for (float num3 = 0f - a.Plan.Half.y; num3 <= num + 0.01f; num3 += 1f) { Vector3 val2 = val * (a.Pos + a.Rot * new Vector3(num2, 0f, num3) - new Vector3(villageCenter.x, 0f, villageCenter.z)); if (val2.x * val2.x + val2.z * val2.z < 20.25f) { return true; } if (val2.x > -5.5f && val2.x < 5.5f && val2.z > -17.5f && val2.z < -6.5f) { return true; } } } return false; } private static bool Fits(Site s, List placed, Vector3 c, Quaternion face) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (s.Started) { return true; } if (OnCommons(s, c, face)) { return false; } if (PlayerBuiltOn(s)) { return false; } foreach (Site item in placed) { if (item.Plan.Parts.Count > 0 && (Overlaps(s, item, 1.5f) || Overlaps(item, s, 1.5f))) { return false; } } return true; } private static Site Demolish(string name, Vector3 pos, Quaternion rot, Vector2 half, int stairs) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) return new Site { Pos = pos, Rot = rot, Plan = new Plan { Name = name, Raise = 0.3f, Half = half, Stairs = stairs } }; } private static bool AnythingBuilt(Site s) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) PieceIndex.Near(s.Pos, ((Vector2)(ref s.Plan.Half)).magnitude + 1f, Hits); foreach (Piece hit in Hits) { if (hit.GetCreator() == 0L && s.Inside(((Component)hit).transform.position, 0f)) { switch (PieceIndex.NameOf(hit)) { case "wood_pole2": case "wood_floor": case "woodwall": return true; } } } return false; } public static bool PlayerBuiltOn(Site s, float margin = 2f) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) PieceIndex.Near(s.Pos, ((Vector2)(ref s.Plan.Half)).magnitude + 2f * (float)s.Plan.Stairs + margin + 1f, Theirs); foreach (Piece their in Theirs) { if (their.GetCreator() != 0L && !((Object)(object)((Component)their).GetComponent() != (Object)null) && s.Contains(((Component)their).transform.position, margin)) { return true; } } return false; } public static int PlayerBeds(VillageInfo v) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) int num = 0; foreach (Bed item in VillagerPlaces.BedsNear(v.Center, v.Radius)) { Piece val = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponent() : null); if ((Object)(object)val != (Object)null && val.GetCreator() != 0L && !VillagerPlaces.PlayersOwn(item)) { num++; } } return num; } public static int BedsWanted(VillageInfo v, int people) { int num = Mathf.Min(Mathf.Max(people, 1), VillageProgress.MaxVillagers()); return Mathf.Max(0, num - PlayerBeds(v)); } public static bool PlayerWorkbench(Vector3 villageCenter, float radius) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) PieceIndex.Near(villageCenter, radius, Theirs); foreach (Piece their in Theirs) { if (their.GetCreator() != 0L && PieceIndex.NameOf(their) == "piece_workbench") { return true; } } return false; } private static bool Stamped(Vector3 villageCenter, string prefix, out string tag) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) tag = null; PieceIndex.Near(villageCenter, 34f, Hits); foreach (Piece hit in Hits) { if (hit.GetCreator() != 0L) { continue; } ZNetView component = ((Component)hit).GetComponent(); if (!((Object)(object)component == (Object)null) && component.IsValid()) { string text = component.GetZDO().GetString("vd_site", ""); if (text.StartsWith(prefix)) { tag = text; return true; } } } return false; } private static int CornersAt(Vector3 villageCenter, Quaternion face, int slot, int length, float extra = 0f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) HouseFrame(villageCenter, face, slot, length, out var pos, out var rot, extra); int num = 0; float[] array = new float[2] { -4f, 4f }; foreach (float num2 in array) { float[] array2 = new float[2] { (float)(-length) / 2f, (float)length / 2f }; foreach (float num3 in array2) { Vector3 at = pos + rot * new Vector3(num2, 0f, num3); if ((Object)(object)PieceIndex.At("wood_pole2", at, 0.3f, 1000f, villagersOnly: true) != (Object)null) { num++; } } } return num; } private static bool StorehouseFull(Site s) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) if (!s.Started) { return false; } foreach (Part part in s.Plan.Parts) { if (part.Use != Use.Chest) { continue; } Vector3 val = s.World(part); Container val2 = null; foreach (Component item in WorldScan.All(3f)) { Container val3 = (Container)(object)((item is Container) ? item : null); if (!((Object)(object)val3 == (Object)null)) { Vector3 val4 = ((Component)val3).transform.position - val; if (val4.x * val4.x + val4.z * val4.z < 0.20249999f && Mathf.Abs(val4.y) < 0.4f) { val2 = val3; break; } } } if ((Object)(object)val2 == (Object)null || val2.GetInventory().HaveEmptySlot()) { return false; } } return true; } public static List Sites(Vector3 villageCenter, float baseHeight, int beds, int stage = 3, bool needStorage = false) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) string key = Mathf.RoundToInt(villageCenter.x) + "|" + Mathf.RoundToInt(villageCenter.z) + "|" + baseHeight.ToString("0.0") + "|" + beds; if (!SiteCache.TryGetValue(key, out var value) || Time.time - value.At >= 4f) { if (SiteCache.Count > 64) { SiteCache.Clear(); } List list = AllSites(villageCenter, baseHeight, beds); List collection = list.FindAll((Site x) => x.Plan.Name == "hut" || x.Plan.Name == "longhouse"); list.RemoveAll((Site x) => x.Plan.Name == "hut" || x.Plan.Name == "longhouse"); list.InsertRange(0, collection); value = new PlanCache { At = Time.time, Sites = list }; SiteCache[key] = value; } if (stage >= 3) { return value.Sites; } List list2 = new List(value.Sites); list2.RemoveAll((Site s) => !s.Started && ((s.Plan.Name == "workshop" && stage < 1) || (s.Plan.Name == "storehouse" && stage < 2 && !needStorage))); return list2; } public static void ForgetPlans() { SiteCache.Clear(); Ranges.Clear(); } private static List AllSites(Vector3 villageCenter, float baseHeight, int beds) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_054c: Unknown result type (might be due to invalid IL or missing references) //IL_054d: Unknown result type (might be due to invalid IL or missing references) //IL_0555: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03d2: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_039b: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_0423: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0438: Unknown result type (might be due to invalid IL or missing references) //IL_0439: Unknown result type (might be due to invalid IL or missing references) //IL_0512: Unknown result type (might be due to invalid IL or missing references) //IL_0513: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0717: Unknown result type (might be due to invalid IL or missing references) //IL_0718: Unknown result type (might be due to invalid IL or missing references) //IL_0720: Unknown result type (might be due to invalid IL or missing references) //IL_0725: Unknown result type (might be due to invalid IL or missing references) //IL_072a: Unknown result type (might be due to invalid IL or missing references) //IL_072f: Unknown result type (might be due to invalid IL or missing references) //IL_0742: Unknown result type (might be due to invalid IL or missing references) //IL_0747: Unknown result type (might be due to invalid IL or missing references) //IL_0756: Unknown result type (might be due to invalid IL or missing references) //IL_0684: Unknown result type (might be due to invalid IL or missing references) //IL_0685: Unknown result type (might be due to invalid IL or missing references) //IL_04b4: Unknown result type (might be due to invalid IL or missing references) //IL_04b5: Unknown result type (might be due to invalid IL or missing references) //IL_04c9: Unknown result type (might be due to invalid IL or missing references) //IL_04ca: Unknown result type (might be due to invalid IL or missing references) //IL_078a: Unknown result type (might be due to invalid IL or missing references) Quaternion val = VillageLayout.Facing(villageCenter); _edits = EditsFor(villageCenter); Site site = Place(villageCenter, val, new Vector3(9f, 0f, 0f), -90f, baseHeight, WorkshopWith, 0, "workshop"); List list = new List(); if (site.Started || (!Cancelled("workshop") && !PlayerBuiltOn(site) && !PlayerWorkbench(villageCenter, 30f))) { list.Add(site); } List list2 = new List(); int num = beds; for (int i = 0; i < HouseDirs.Length; i++) { int num2 = -1; int num3 = 2; float extra = 0f; if (Stamped(villageCenter, "L|" + i + "|", out var tag)) { string[] array = tag.Split(new char[1] { '|' }); if (array.Length >= 4 && int.TryParse(array[2], out var result) && float.TryParse(array[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2)) { num2 = result; extra = result2; } } else { int[] houseLengths = HouseLengths; foreach (int num4 in houseLengths) { int num5 = CornersAt(villageCenter, val, i, num4); if (num5 >= num3) { num3 = num5; num2 = num4; } } } if (num2 < 0 && Cancelled("house" + i) && (i != 0 || Cancelled("hut") || num <= 0 || num > 3)) { continue; } if (i == 0 && num2 < 0 && !Cancelled("hut")) { Site site2 = null; Site site3 = null; float result3 = -1f; if (Stamped(villageCenter, "H|", out tag)) { float.TryParse(tag.Split(new char[1] { '|' })[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result3); } float[] pushBack = PushBack; for (int j = 0; j < pushBack.Length; j++) { float num6 = pushBack[j]; if (!(result3 >= 0f) || num6 == result3) { Site site4 = new Site { Yaw = HouseYaws[0], Base = baseHeight, Plan = HutWith(1), Tag = "H|" + num6.ToString(CultureInfo.InvariantCulture), Key = "hut", Make = HutWith, MinStairs = 0 }; HouseFrame(villageCenter, val, 0, 6, out site4.Pos, out site4.Rot, num6); Edit(site4, val); ResolveBase(site4); site4.Plan = HutWith(StairsFor(site4, 1f, 0)); Footings(site4); if (site4.Started || result3 >= 0f) { site2 = site4; break; } if (!OnCommons(site4, villageCenter, val) && !PlayerBuiltOn(site4) && (site3 == null || (!SiteReady(site3) && SiteReady(site4)) || (SiteReady(site4) && Drop(site4) + 0.5f < Drop(site3)))) { site3 = site4; } } } if (site2 == null && num > 0 && num <= 3) { site2 = site3; } if (site2 != null) { list.Add(site2); num -= Mathf.Min(num, 3); continue; } } if (num <= 0) { if (num2 > 0) { list.Add(HouseSite(villageCenter, val, i, num2, Capacity(num2), baseHeight, extra)); } continue; } Site site5 = null; int num7; if (num2 > 0) { num7 = Mathf.Min(num, Capacity(num2)); site5 = HouseSite(villageCenter, val, i, num2, num7, baseHeight, extra); } else { num2 = LengthFor(Mathf.Min(num, Capacity(12))); num7 = Mathf.Min(num, Capacity(num2)); Site site6 = null; float[] pushBack = PushBack; foreach (float extra2 in pushBack) { Site site7 = HouseSite(villageCenter, val, i, num2, num7, baseHeight, extra2); if (!Fits(site7, list, villageCenter, val)) { continue; } if (SiteReady(site7)) { if (site5 == null || Drop(site7) + 0.5f < Drop(site5)) { site5 = site7; } if (Drop(site7) <= 1.6f) { break; } } else if (site6 == null) { site6 = site7; } } if (site5 == null && site6 != null) { bool flag = false; for (int k = i + 1; k < HouseDirs.Length; k++) { if (flag) { break; } pushBack = PushBack; foreach (float extra3 in pushBack) { Site s = HouseSite(villageCenter, val, k, num2, num7, baseHeight, extra3); if (Fits(s, list, villageCenter, val) && SiteReady(s)) { flag = true; break; } } } if (!flag) { site5 = site6; } } } if (site5 != null && Fits(site5, list, villageCenter, val)) { list.Add(site5); num -= num7; } } List list3 = new List(); for (int l = 0; l < StoreSpots.Length; l++) { list3.Add(Place(villageCenter, val, StoreSpots[l], StoreYaws[l], baseHeight, StorehouseWith, 0, "store" + l)); } List list4 = new List(); foreach (Site item in list3) { if (item.Started) { list4.Add(item); } } list3.RemoveAll((Site site10) => !site10.Started && Cancelled(site10.Key)); if (list4.Count == 0 || list4.TrueForAll(StorehouseFull)) { Site site8 = null; foreach (Site o in list3) { if (!o.Started && Fits(o, list, villageCenter, val) && !list4.Exists((Site x) => Overlaps(o, x, 1.5f))) { if (SiteReady(o)) { site8 = o; break; } if (site8 == null) { site8 = o; } } } if (site8 != null) { list4.Add(site8); } } list.AddRange(list4); if (list4.Count > 0) { _ = list4[0]; } for (int num8 = 0; num8 < OldStoreSpots.Length; num8++) { Site site9 = Demolish("old storehouse", villageCenter + val * OldStoreSpots[num8], val * Quaternion.Euler(0f, OldStoreYaws[num8], 0f), new Vector2(3.2f, 3.2f), 1); site9.Pos.y = 0f; bool flag2 = false; foreach (Site item2 in list) { if (item2.Contains(site9.Pos, 1f)) { flag2 = true; } } if (!flag2 && AnythingBuilt(site9)) { list2.Add(site9); } } list.AddRange(list2); return list; } public static string EditKey(string villageId) { return "vplan." + villageId; } public static Dictionary ParseEdits(string spec) { Dictionary dictionary = new Dictionary(); if (string.IsNullOrEmpty(spec)) { return dictionary; } CultureInfo invariantCulture = CultureInfo.InvariantCulture; string[] array = spec.Split(new char[1] { '|' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }); if (array2.Length >= 5) { PlanEdit planEdit = new PlanEdit { Cancel = (array2[1] == "1") }; float.TryParse(array2[2], NumberStyles.Float, invariantCulture, out planEdit.Dx); float.TryParse(array2[3], NumberStyles.Float, invariantCulture, out planEdit.Dz); float.TryParse(array2[4], NumberStyles.Float, invariantCulture, out planEdit.Rot); dictionary[array2[0]] = planEdit; } } return dictionary; } public static string EncodeEdits(Dictionary d) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; List list = new List(); foreach (KeyValuePair item in d) { PlanEdit value = item.Value; if (value.Cancel || value.Dx != 0f || value.Dz != 0f || value.Rot != 0f) { list.Add(item.Key + ":" + (value.Cancel ? "1" : "0") + ":" + value.Dx.ToString("0.#", invariantCulture) + ":" + value.Dz.ToString("0.#", invariantCulture) + ":" + value.Rot.ToString("0", invariantCulture)); } } return string.Join("|", list.ToArray()); } private static Dictionary EditsFor(Vector3 villageCenter) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) VillageInfo villageInfo = VillageInfo.At(villageCenter); if (villageInfo == null) { return new Dictionary(); } return ParseEdits(ModData.Get(EditKey(villageInfo.Id))); } private static bool Cancelled(string key) { if (key != null && _edits.TryGetValue(key, out var value)) { return value.Cancel; } return false; } private static void Edit(Site s, Quaternion face) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (s.Key != null && _edits.TryGetValue(s.Key, out var value) && (value.Dx != 0f || value.Dz != 0f || value.Rot != 0f)) { s.Pos += face * new Vector3(value.Dx, 0f, value.Dz); s.Rot *= Quaternion.Euler(0f, value.Rot, 0f); s.Yaw += value.Rot; if (s.Tag != null) { s.Tag = s.Tag + "|" + value.Dx.ToString("0.#", CultureInfo.InvariantCulture) + "|" + value.Dz.ToString("0.#", CultureInfo.InvariantCulture) + "|" + value.Rot.ToString("0", CultureInfo.InvariantCulture); } } } public static List CancelledKeys(VillageInfo v) { List list = new List(); foreach (KeyValuePair item in ParseEdits(ModData.Get(EditKey(v.Id)))) { if (item.Value.Cancel) { list.Add(item.Key); } } return list; } public static string DebugHouses(Vector3 villageCenter, float baseHeight, int beds) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) Quaternion face = VillageLayout.Facing(villageCenter); _edits = EditsFor(villageCenter); List list = new List { Place(villageCenter, face, new Vector3(9f, 0f, 0f), -90f, baseHeight, WorkshopWith, 0, "workshop") }; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < HouseDirs.Length; i++) { int length = LengthFor(Mathf.Min(beds, Capacity(12))); float[] pushBack = PushBack; foreach (float num in pushBack) { Site site = HouseSite(villageCenter, face, i, length, Mathf.Min(beds, Capacity(length)), baseHeight, num); bool flag = OnCommons(site, villageCenter, face); bool flag2 = false; foreach (Site item in list) { if (Overlaps(site, item, 1.5f) || Overlaps(item, site, 1.5f)) { flag2 = true; } } stringBuilder.Append($" slot{i}+{num}: stairs {site.Plan.Stairs} commons {flag} clash {flag2};"); } } return stringBuilder.ToString(); } private static void GroundRange(Site s, out float lo, out float hi) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) long key = ((long)Mathf.RoundToInt(s.Pos.x * 4f) << 40) ^ ((long)Mathf.RoundToInt(s.Pos.z * 4f) << 16) ^ Mathf.RoundToInt(((Quaternion)(ref s.Rot)).eulerAngles.y) ^ ((long)(s.Plan.Half.x * 8f) << 9) ^ ((long)(s.Plan.Half.y * 8f) << 3); if (Ranges.TryGetValue(key, out var value) && Time.time - value.At < 8f) { lo = value.Lo; hi = value.Hi; return; } GroundRangeNow(s, out lo, out hi); if (Ranges.Count > 512) { Ranges.Clear(); } Ranges[key] = new Range { Lo = lo, Hi = hi, At = Time.time }; } private static void GroundRangeNow(Site s, out float lo, out float hi) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) lo = float.MaxValue; hi = float.MinValue; for (int i = 0; i < 25; i++) { float num = (float)(i % 5 - 2) / 2f * (s.Plan.Half.x - 0.3f); float num2 = (float)(i / 5 - 2) / 2f * (Mathf.Min(s.Plan.Half.y, 4f) - 0.3f); float groundHeight = ZoneSystem.instance.GetGroundHeight(s.Pos + s.Rot * new Vector3(num, 0f, num2)); lo = Mathf.Min(lo, groundHeight); hi = Mathf.Max(hi, groundHeight); } } public static void ResolveBase(Site s) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) int num = 0; PieceIndex.Near(s.Pos, ((Vector2)(ref s.Plan.Half)).magnitude + 1f, Hits); foreach (Piece hit in Hits) { if (hit.GetCreator() == 0L && s.Inside(((Component)hit).transform.position, 0.5f)) { num++; } } if (num == 0) { GroundRange(s, out var _, out var hi); s.Base = hi; return; } foreach (Part part in s.Plan.Parts) { if (part.Use != Use.Structure) { continue; } Vector3 val = s.Pos + s.Rot * new Vector3(part.Local.x, 0f, part.Local.z); float groundHeight = ZoneSystem.instance.GetGroundHeight(val); PieceIndex.Near(val, 0.3f, Hits); foreach (Piece hit2 in Hits) { if (hit2.GetCreator() == 0L && !(PieceIndex.NameOf(hit2) != part.Prefab) && !(Mathf.Abs(((Component)hit2).transform.position.y - (groundHeight + s.Plan.Raise + part.Local.y)) > 3f)) { s.Base = ((Component)hit2).transform.position.y - s.Plan.Raise - part.Local.y; s.Started = true; GroundRange(s, out var _, out var hi2); if (num <= 3 && Mathf.Abs(s.Base - hi2) > 1.5f) { s.Base = hi2; s.Started = false; } return; } } } GroundRange(s, out var _, out var hi3); s.Base = hi3; } public static bool SiteReady(Site s) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) if (s.Started) { return true; } GroundRange(s, out var lo, out var hi); if (hi - lo > 4f) { return false; } float num = hi + s.Plan.Raise; float y = s.Plan.Half.y; if (s.Ground(s.Plan.DoorX, y + 0.8f).y >= num - 0.2f) { return true; } for (int i = 1; i <= 6; i++) { if (s.Ground(s.Plan.DoorX, y + 2f * (float)i).y >= num - (float)i - 0.1f) { return true; } } return false; } public static List Doors(VillageInfo v) { //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) if (!Towns.TryGetValue(v.Id, out var value)) { value = new TownCache { At = -100f }; Towns[v.Id] = value; } if (Time.time - value.At < 6f) { return value.Sites; } value.At = Time.time; value.Sites.Clear(); if ((Object)(object)ZoneSystem.instance == (Object)null) { return value.Sites; } int stage = 3; float h; int beds; if (CampTown.IsCamp(v)) { h = CampTown.Height(v); beds = CampTown.Beds(v); CampInfo campInfo = CampTown.Camp(v); if (campInfo != null) { stage = campInfo.Stage; } } else { if (!VillageGround.Target(v, out h)) { return value.Sites; } beds = BedsWanted(v, Wanderer.VillagersIn(v)); } foreach (Site item in Sites(v.Center, h, beds, stage)) { if (!item.Plan.HasDoor || !item.Started) { continue; } foreach (Part part in item.Plan.Parts) { if (part.Prefab == "wood_stair") { item.Walkable = VillageLayout.Built(part.Prefab, item.World(part)); break; } } if (item.Plan.Stairs == 0) { item.Walkable = true; } if (item.Walkable) { value.Sites.Add(item); } } return value.Sites; } public static bool Route(Vector3 me, Vector3 goal, out Vector3 via) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) via = goal; VillageInfo villageInfo = VillageInfo.At(goal) ?? VillageInfo.At(me) ?? CampTown.At(goal) ?? CampTown.At(me); if (villageInfo == null) { return false; } foreach (Site item in Doors(villageInfo)) { float floor = item.Floor; bool flag = item.Inside(goal, -0.3f) && goal.y > floor - 0.8f; bool flag2 = item.Inside(me, 0.1f) && me.y > floor - 0.6f; if (flag != flag2) { Vector3 val = item.Local(me); float doorX = item.Plan.DoorX; float y = item.Plan.Half.y; float num = 2f * (float)item.Plan.Stairs; bool flag3 = Mathf.Abs(val.x - doorX) < 1.6f && val.z > y - 2.3f && val.z < y + num + 2.5f; Vector3 val2 = item.Pos + item.Rot * new Vector3(doorX, 0f, y - 1.1f); val2.y = floor; Vector3 val3 = item.Pos + item.Rot * new Vector3(doorX, 0f, y + num + 1f); val3.y = ZoneSystem.instance.GetGroundHeight(val3); if (flag) { via = (flag3 ? val2 : val3); } else { via = (flag3 ? val3 : val2); } return true; } } return false; } } internal static class Landmarks { private static readonly MethodInfo ListMethod = AccessTools.Method(typeof(ZoneSystem), "GetLocationList", (Type[])null, (Type[])null); private static readonly FieldInfo ListField = AccessTools.Field(typeof(ZoneSystem), "m_locationInstances"); public static bool Near(Vector3 p, float clearance, out string name, float startTempleClearance = 0f) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) name = null; ZoneSystem instance = ZoneSystem.instance; if ((Object)(object)instance == (Object)null) { return false; } IEnumerable enumerable = null; try { enumerable = ((ListMethod != null) ? (ListMethod.Invoke(instance, null) as IEnumerable) : null); } catch { } if (enumerable == null && ListField != null && ListField.GetValue(instance) is IDictionary dictionary) { enumerable = dictionary.Values; } if (enumerable == null) { return false; } foreach (object item in enumerable) { if (item == null) { continue; } Traverse obj2 = Traverse.Create(item); Vector3 value = obj2.Field("m_position").GetValue(); object value2 = obj2.Field("m_location").GetValue(); if (value2 != null) { Traverse obj3 = Traverse.Create(value2); string text = obj3.Field("m_prefabName").GetValue() ?? ""; float num = Mathf.Min(obj3.Field("m_exteriorRadius").GetValue(), 32f); float num2 = clearance + num; if (text == "StartTemple") { num2 = Mathf.Max(num2, startTempleClearance); } Vector3 val = value - p; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude < num2 * num2) { name = Pretty(text); return true; } } } return false; } public static bool OnTop(Vector3 p, out string name) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) name = null; ZoneSystem instance = ZoneSystem.instance; if ((Object)(object)instance == (Object)null) { return false; } IEnumerable enumerable = null; try { enumerable = ((ListMethod != null) ? (ListMethod.Invoke(instance, null) as IEnumerable) : null); } catch { } if (enumerable == null && ListField != null && ListField.GetValue(instance) is IDictionary dictionary) { enumerable = dictionary.Values; } if (enumerable == null) { return false; } foreach (object item in enumerable) { if (item == null) { continue; } Traverse obj2 = Traverse.Create(item); Vector3 value = obj2.Field("m_position").GetValue(); object value2 = obj2.Field("m_location").GetValue(); if (value2 != null) { Traverse val = Traverse.Create(value2); string text = val.Field("m_prefabName").GetValue() ?? ""; float num = ((text == "StartTemple") ? 30f : Mathf.Min(val.Field("m_exteriorRadius").GetValue(), 12f)); Vector3 val2 = value - p; val2.y = 0f; if (((Vector3)(ref val2)).sqrMagnitude < num * num) { name = Pretty(text) + $" ({((Vector3)(ref val2)).magnitude:0} m away)"; return true; } } } return false; } public static string Pretty(string prefab) { if (prefab == "StartTemple") { return "the sacrificial stones"; } if (prefab.StartsWith("Runestone")) { return "a runestone"; } if (prefab.StartsWith("Vendor") || prefab.Contains("Haldor")) { return "the trader"; } if (prefab.Contains("Eikthyrnir") || prefab.Contains("GDKing") || prefab.Contains("Bonemass") || prefab.Contains("Dragonqueen") || prefab.Contains("GoblinKing")) { return "a boss altar"; } if (prefab.Contains("Crypt") || prefab.Contains("Cave") || prefab.Contains("Burial")) { return "a dungeon"; } return "a landmark (" + prefab.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') + ")"; } } internal static class TownCatchUp { private sealed class Town { public VillageInfo V; public int Stage; public bool Camp; } private sealed class Work { public int Budget; public float Hours; public int Cleared; public int Levelled; public int Built; public bool Settle; } private const string KWorked = "vd_worked"; private const float PiecesPerWorkerHour = 3f; private const float MaxHours = 48f; private static float _next; private static readonly Dictionary Pending = new Dictionary(); private const int ClearPerStep = 8; private const int LevelPerStep = 3; private const int BuildPerStep = 12; private static readonly Dictionary LastNote = new Dictionary(); public static void Tick() { //IL_0142: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null || Time.time < _next) { return; } _next = Time.time + ((Pending.Count > 0) ? 1.5f : 5f); List list = new List(); foreach (VillageInfo item in VillageInfo.All()) { list.Add(new Town { V = item, Stage = 3 }); } foreach (CampInfo item2 in CampInfo.All()) { if (!item2.Hostile && !CampWar.Ruined(item2)) { list.Add(new Town { V = CampTown.Of(item2), Stage = item2.Stage, Camp = true }); } } foreach (Town t in list) { if (ZoneSystem.instance.IsZoneLoaded(t.V.Center)) { Safe.Run("TownCatchUp", delegate { CatchUp(t); }); } } } private static ZNetView Clock(VillageInfo v) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) VillageTotem villageTotem = null; float num = 100f; foreach (Component item in WorldScan.All(3f)) { VillageTotem villageTotem2 = item as VillageTotem; if (!((Object)(object)villageTotem2 == (Object)null)) { Vector3 val = ((Component)villageTotem2).transform.position - v.Center; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude < num) { num = ((Vector3)(ref val)).sqrMagnitude; villageTotem = villageTotem2; } } } if ((Object)(object)villageTotem != (Object)null) { ZNetView component = ((Component)villageTotem).GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid()) { return component; } } Fireplace val2 = Anchor(v); if (!((Object)(object)val2 != (Object)null)) { return null; } return ((Component)val2).GetComponent(); } private static Fireplace Anchor(VillageInfo v) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) Fireplace result = null; float num = 196f; foreach (Component item in WorldScan.All(3f)) { Fireplace val = (Fireplace)(object)((item is Fireplace) ? item : null); if (!((Object)(object)val == (Object)null) && !val.m_infiniteFuel) { Vector3 val2 = ((Component)val).transform.position - v.Center; val2.y = 0f; if (((Vector3)(ref val2)).sqrMagnitude < num) { num = ((Vector3)(ref val2)).sqrMagnitude; result = val; } } } return result; } private static List People(Town t) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) List list = new List(); string text = (t.Camp ? t.V.Id.Substring("camp:".Length) : null); foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item == (Object)null || ((Character)item).IsDead() || item.IsWanderer) { continue; } bool num; if (!t.Camp) { if (!string.IsNullOrEmpty(item.CampId)) { continue; } num = t.V.Contains(item.Home); } else { num = item.CampId == text; } if (num) { list.Add(item); } } return list; } private static void CatchUp(Town t) { //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_04e7: Unknown result type (might be due to invalid IL or missing references) //IL_0500: Unknown result type (might be due to invalid IL or missing references) //IL_050f: Unknown result type (might be due to invalid IL or missing references) //IL_051a: Unknown result type (might be due to invalid IL or missing references) //IL_052c: Unknown result type (might be due to invalid IL or missing references) //IL_068f: Unknown result type (might be due to invalid IL or missing references) //IL_0694: Unknown result type (might be due to invalid IL or missing references) //IL_069d: Unknown result type (might be due to invalid IL or missing references) //IL_06c0: Unknown result type (might be due to invalid IL or missing references) //IL_0754: Unknown result type (might be due to invalid IL or missing references) //IL_076e: Unknown result type (might be due to invalid IL or missing references) //IL_0786: Unknown result type (might be due to invalid IL or missing references) //IL_0794: Unknown result type (might be due to invalid IL or missing references) //IL_079a: Unknown result type (might be due to invalid IL or missing references) ZNetView val = Clock(t.V); if ((Object)(object)val == (Object)null || !val.IsValid()) { Note(t, "no totem or fire to keep the clock on yet"); return; } if (!val.IsOwner()) { Note(t, "another player is running this town"); return; } ZDO zDO = val.GetZDO(); double netTime = GameApi.NetTime; double num = zDO.GetFloat("vd_worked", -1f); if (num < 0.0) { zDO.Set("vd_worked", (float)netTime); Note(t, "clock started"); return; } List list = People(t); if (list.Count == 0) { Note(t, "nobody home yet"); return; } VillagerCharacter v = list[0]; float value = VillagersConfig.HomeRadius.Value; if (!Pending.TryGetValue(t.V.Id, out var value2)) { double num2 = netTime - num; if (num2 >= 150.0) { Note(t, $"away {num2:0} s with {list.Count} people"); } if (num2 < 150.0) { if (num2 > 30.0) { zDO.Set("vd_worked", (float)netTime); } return; } zDO.Set("vd_worked", (float)netTime); float num3 = Mathf.Min((float)(num2 / (GameApi.DayLengthSeconds / 24.0)), 48f); value2 = new Work { Hours = num3, Budget = Mathf.Min(Mathf.RoundToInt((float)list.Count * num3 * 3f), 400) }; if (!t.Camp) { int num4 = 0; int num5 = 0; foreach (VillagerCharacter item in list) { if (item.Job == VillagerJob.Woodcutter) { num4 += Mathf.RoundToInt(num3 * 4f); } else if (item.Job == VillagerJob.Miner) { num5 += Mathf.RoundToInt(num3 * 2f); } else if (item.Job == VillagerJob.Gatherer) { num4 += Mathf.RoundToInt(num3 * 2f); num5 += Mathf.RoundToInt(num3 * 1f); } } Stock(t.V, "Wood", Mathf.Min(num4, 200)); Stock(t.V, "Stone", Mathf.Min(num5, 120)); } if (!t.Camp && !VillageInfo.VillagersBuild(t.V)) { return; } Pending[t.V.Id] = value2; } else { zDO.Set("vd_worked", (float)netTime); } if (!t.Camp && !VillageInfo.VillagersBuild(t.V)) { Finish(t, value2); return; } float h; int num6; if (t.Camp) { h = CampTown.Height(t.V); num6 = CampTown.Beds(t.V); } else { if (!VillageGround.Target(t.V, out h)) { Finish(t, value2); return; } num6 = Blueprints.BedsWanted(t.V, Wanderer.VillagersIn(t.V)); } List list2 = Village.Chests(t.V.Center, value); bool needStorage = list2.Count >= 2 || (list2.Count > 0 && (Object)(object)Village.ChestWithRoom(t.V.Center, value, t.V.Center) == (Object)null); List list3 = Blueprints.Sites(t.V.Center, h, num6, t.Stage, needStorage); VillageGround.SetPads(t.V, list3); int num7 = 0; int num8 = 0; int num9 = 0; foreach (Blueprints.Site item2 in list3) { if (item2.Plan.Parts.Count == 0) { continue; } foreach (GameObject item3 in new List(TownClearing.OnSite(t.V, item2, 1.5f))) { if (value2.Budget <= 0 || num7 >= 8) { break; } if ((Object)(object)item3 == (Object)null) { continue; } if ((Object)(object)item3.GetComponent() != (Object)null || (Object)(object)item3.GetComponent() != (Object)null) { TownClearing.RemoveCleanly(item3); } else { ZNetView component = item3.GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { continue; } if (!component.IsOwner()) { component.ClaimOwnership(); } ZNetScene.instance.Destroy(item3); } value2.Budget--; num7++; } } if (num7 == 0) { foreach (Vector3 item4 in VillageGround.Cells(t.V)) { if (value2.Budget <= 0 || num8 >= 3) { break; } if (VillageGround.IsPad(t.V, item4)) { float h2 = VillageGround.TargetAt(t.V, item4, h); if (VillageGround.Check(item4, h2) == VillageGround.CellState.Todo) { VillageGround.Level(t.V, item4, h2); value2.Budget--; num8++; } } } } value2.Cleared += num7; value2.Levelled += num8; if (num7 > 0 || num8 > 0) { value2.Settle = true; FinishIfSpent(t, value2); return; } if (value2.Settle) { value2.Settle = false; Blueprints.ForgetPlans(); return; } int num10 = 0; foreach (Blueprints.Site item5 in list3) { if (value2.Budget <= 0 || num9 >= 12) { break; } if (item5.Plan.Parts.Count == 0 || !Blueprints.SiteReady(item5) || !TownClearing.SiteClear(t.V, item5)) { continue; } foreach (Blueprints.Part part in item5.Plan.Parts) { if (value2.Budget <= 0 || num9 >= 12) { break; } if ((part.Use == Blueprints.Use.Bed && num10++ >= num6) || part.MinStage > t.Stage || part.Use == Blueprints.Use.Chest) { continue; } Vector3 val2 = item5.World(part); if (VillageLayout.Built(part.Prefab, val2)) { continue; } bool flag = false; string[] alt = part.Alt; for (int i = 0; i < alt.Length; i++) { if (VillageLayout.Built(alt[i], val2)) { flag = true; } } if (flag) { continue; } GameObject prefab = ZNetScene.instance.GetPrefab(part.Prefab); Piece val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent() : null); if ((Object)(object)val3 == (Object)null) { continue; } if (!t.Camp && !VillageProgress.Knows(t.V, val3.m_name)) { if (part.Use == Blueprints.Use.Structure) { break; } } else if (!Village.CanAfford(v, val3.m_resources, t.V.Center, value)) { if (part.Use != Blueprints.Use.Furniture) { break; } } else if (!SomeoneThere(val2)) { Village.Pay(v, val3.m_resources, t.V.Center, value); Place(prefab, val2, item5.WorldRot(part), item5.Tag); value2.Budget--; num9++; } } } value2.Built += num9; if (num9 < 12 || value2.Budget <= 0) { Finish(t, value2); } } private static void FinishIfSpent(Town t, Work w) { if (w.Budget <= 0) { Finish(t, w); } } private static void Finish(Town t, Work w) { Pending.Remove(t.V.Id); if (w.Cleared + w.Levelled + w.Built > 0) { DynastyPlugin.Log.LogInfo((object)$"{t.V.Name}: caught up on {w.Hours:0} hours away: cleared {w.Cleared}, levelled {w.Levelled}, built {w.Built} piece(s)."); } } private static void Note(Town t, string what) { if (DynastyPlugin.VerboseOn && (!LastNote.TryGetValue(t.V.Id, out var value) || !(value == what))) { LastNote[t.V.Id] = what; DynastyPlugin.Log.LogInfo((object)(t.V.Name + ": catch-up: " + what + ".")); } } private static bool SomeoneThere(Vector3 w) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) foreach (Character allCharacter in Character.GetAllCharacters()) { if (!((Object)(object)allCharacter == (Object)null) && !allCharacter.IsDead()) { Vector3 val = ((Component)allCharacter).transform.position - w; if (val.x * val.x + val.z * val.z < 3.61f && Mathf.Abs(val.y) < 3f) { return true; } } } return false; } private static void Place(GameObject prefab, Vector3 at, Quaternion rot, string tag) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Object.Instantiate(prefab, at, rot); ZNetView component = obj.GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid()) { component.GetZDO().Set("vdyn_built", true); if (!string.IsNullOrEmpty(tag)) { component.GetZDO().Set("vd_site", tag); } } WorldScan.Add((Component)(object)obj.GetComponent()); WorldScan.Add((Component)(object)obj.GetComponent()); WorldScan.Add((Component)(object)obj.GetComponent()); WorldScan.Invalidate(); VillagerPlaces.Invalidate(); } private static void Stock(VillageInfo v, string prefabName, int n) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (n <= 0) { return; } GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefabName) : null); if ((Object)(object)val == (Object)null) { return; } foreach (Container item in Village.Chests(v.Center, VillagersConfig.HomeRadius.Value)) { if (n <= 0) { break; } ZNetView component = ((Component)item).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid() || item.IsInUse()) { continue; } component.ClaimOwnership(); Inventory inventory = item.GetInventory(); int num = Mathf.Max(1, val.GetComponent().m_itemData.m_shared.m_maxStackSize); while (n > 0 && inventory.CanAddItem(val, 1)) { int num2 = Mathf.Min(n, num); int num3 = inventory.CountItems(val.GetComponent().m_itemData.m_shared.m_name, -1, true); if (!inventory.AddItem(val, num2)) { break; } int num4 = inventory.CountItems(val.GetComponent().m_itemData.m_shared.m_name, -1, true) - num3; if (num4 <= 0) { break; } n -= num4; } } } } internal static class TownClearing { private sealed class Cache { public float At; public List Things = new List(); } private static readonly Dictionary ByVillage = new Dictionary(); public static bool IsObstruction(Component c) { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Invalid comparison between Unknown and I4 if ((Object)(object)c == (Object)null) { return false; } GameObject gameObject = c.gameObject; ZNetView component = gameObject.GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return false; } if ((Object)(object)gameObject.GetComponentInParent() != (Object)null || (Object)(object)gameObject.GetComponent() != (Object)null || (Object)(object)gameObject.GetComponentInParent() != (Object)null || (Object)(object)gameObject.GetComponent() != (Object)null || (Object)(object)gameObject.GetComponentInParent() != (Object)null) { return false; } Destructible val = (Destructible)(object)((c is Destructible) ? c : null); if ((Object)(object)val != (Object)null) { if ((int)val.m_destructibleType == 4) { return false; } if ((Object)(object)gameObject.GetComponent() != (Object)null && Utils.GetPrefabName(gameObject).StartsWith("Pickable_")) { return false; } } return true; } public static List In(VillageInfo v) { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) if (!ByVillage.TryGetValue(v.Id, out var value)) { value = new Cache { At = -100f }; ByVillage[v.Id] = value; } if (Time.time - value.At < 4f) { value.Things.RemoveAll((GameObject g) => (Object)(object)g == (Object)null); return value.Things; } value.At = Time.time; value.Things.Clear(); float r = v.Radius + 2f; Add(value.Things, WorldScan.All(8f), v.Center, r); Add(value.Things, WorldScan.All(4f), v.Center, r); Add(value.Things, WorldScan.All(8f), v.Center, r); Add(value.Things, WorldScan.All(10f), v.Center, r); Add(value.Things, WorldScan.All(10f), v.Center, r); return value.Things; } private static void Add(List into, List from, Vector3 center, float r) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) foreach (Component item in from) { if (!((Object)(object)item == (Object)null)) { Vector3 val = item.transform.position - center; val.y = 0f; if (!(((Vector3)(ref val)).sqrMagnitude > r * r) && IsObstruction(item)) { into.Add(item.gameObject); } } } } public static IEnumerable OnSite(VillageInfo v, Blueprints.Site site, float margin) { foreach (GameObject item in In(v)) { if ((Object)(object)item != (Object)null && site.Contains(Centre(item), margin)) { yield return item; } } } public static bool SiteClear(VillageInfo v, Blueprints.Site site) { using (IEnumerator enumerator = OnSite(v, site, 1.5f).GetEnumerator()) { if (enumerator.MoveNext()) { _ = enumerator.Current; return false; } } return true; } public static Vector3 Centre(GameObject g) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)g.GetComponent() == (Object)null) { return g.transform.position; } Collider[] componentsInChildren = g.GetComponentsInChildren(); if (componentsInChildren.Length == 0) { return g.transform.position; } Bounds bounds = componentsInChildren[0].bounds; Collider[] array = componentsInChildren; foreach (Collider val in array) { if ((Object)(object)val != (Object)null && val.enabled) { ((Bounds)(ref bounds)).Encapsulate(val.bounds); } } return ((Bounds)(ref bounds)).center; } public static bool InTown(Vector3 p, float margin = 4f) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) foreach (VillageInfo item in VillageInfo.All()) { Vector3 val = p - item.Center; val.y = 0f; if (((Vector3)(ref val)).magnitude < item.Radius + margin) { return true; } } return false; } public static void RemoveCleanly(GameObject g) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)g == (Object)null) { return; } ZNetView component = g.GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return; } Vector3 position = g.transform.position; List list = new List(); TreeBase component2 = g.GetComponent(); if ((Object)(object)component2 != (Object)null) { if (component2.m_dropWhenDestroyed != null) { list.AddRange(component2.m_dropWhenDestroyed.GetDropList()); } if ((Object)(object)component2.m_logPrefab != (Object)null) { LogDrops(component2.m_logPrefab.GetComponent(), list, 0); } } TreeLog component3 = g.GetComponent(); if ((Object)(object)component3 != (Object)null) { LogDrops(component3, list, 0); } foreach (GameObject item in list) { if (!((Object)(object)item == (Object)null)) { Vector3 val = position + Vector3.up * 0.8f + new Vector3(Random.Range(-0.8f, 0.8f), 0f, Random.Range(-0.8f, 0.8f)); Object.Instantiate(item, val, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f)); } } if (!component.IsOwner()) { component.ClaimOwnership(); } ZNetScene.instance.Destroy(g); WorldScan.Invalidate(); } private static void LogDrops(TreeLog log, List into, int depth) { if ((Object)(object)log == (Object)null || depth > 3) { return; } if (log.m_dropWhenDestroyed != null) { into.AddRange(log.m_dropWhenDestroyed.GetDropList()); } if ((Object)(object)log.m_subLogPrefab != (Object)null) { TreeLog component = log.m_subLogPrefab.GetComponent(); int num = ((log.m_subLogPoints != null) ? log.m_subLogPoints.Length : 0); for (int i = 0; i < num; i++) { LogDrops(component, into, depth + 1); } } } } internal enum Duty { Trade, Build, Supply, Food, Haul, Guard } internal static class TownManager { internal sealed class Plan { public float At = -100f; public readonly Dictionary Duties = new Dictionary(); public readonly Dictionary SupplyItem = new Dictionary(); public bool Building; public readonly List Short = new List(); public float FoodDays = 99f; public int Loose; public int People; public string Summary = ""; } private sealed class BuildNews { public float Until; public float DoneAt = -1000f; public readonly Dictionary Short = new Dictionary(); } public const float Refresh = 10f; private const float FoodPerPersonDay = 3f; private const float LowFoodDays = 2f; private static readonly Dictionary Plans = new Dictionary(); private static readonly Dictionary News = new Dictionary(); public static void ReportBuildWork(string townId) { if (townId != null) { Get(townId).Until = Time.time + 30f; } } public static void ReportShort(string townId, IEnumerable items) { if (townId == null) { return; } BuildNews buildNews = Get(townId); buildNews.Until = Time.time + 60f; foreach (string item in items) { buildNews.Short[item] = Time.time + 60f; } } public static void ReportBuildDone(string townId) { if (townId != null) { BuildNews buildNews = Get(townId); buildNews.Until = 0f; buildNews.DoneAt = Time.time; buildNews.Short.Clear(); } } private static BuildNews Get(string townId) { if (!News.TryGetValue(townId, out var value)) { value = new BuildNews(); News[townId] = value; } return value; } public static Duty DutyOf(VillagerCharacter v, VillageInfo town, out string item) { item = null; if ((Object)(object)v == (Object)null || town == null) { return Duty.Trade; } Plan plan = PlanFor(town); if (!plan.Duties.TryGetValue(((Object)v).GetInstanceID(), out var value)) { if (v.Job != VillagerJob.Guard) { return Duty.Trade; } return Duty.Guard; } plan.SupplyItem.TryGetValue(((Object)v).GetInstanceID(), out item); return value; } public static Plan PlanFor(VillageInfo town) { if (!Plans.TryGetValue(town.Id, out var plan)) { plan = new Plan(); Plans[town.Id] = plan; } if (Time.time - plan.At >= 10f) { plan.At = Time.time; Safe.Run("TownManager.Assign", delegate { Assign(town, plan); }); } return plan; } public static string SummaryOf(VillageInfo town) { if (town != null) { return PlanFor(town).Summary; } return ""; } private static List PeopleOf(VillageInfo town) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) List list = new List(); bool flag = CampTown.IsCamp(town); string text = (flag ? town.Id.Substring("camp:".Length) : null); foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item == (Object)null || ((Character)item).IsDead() || item.IsWanderer) { continue; } bool num; if (!flag) { if (!string.IsNullOrEmpty(item.CampId)) { continue; } num = town.Contains(item.Home); } else { num = item.CampId == text; } if (num) { list.Add(item); } } list.Sort((VillagerCharacter a, VillagerCharacter b) => string.CompareOrdinal(a.VillagerName ?? "", b.VillagerName ?? "")); return list; } private static bool IsFood(ItemData it) { if (it != null) { return it.m_shared.m_food > 0f; } return false; } private static void Assign(VillageInfo town, Plan plan) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Expected O, but got Unknown //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Invalid comparison between Unknown and I4 //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Invalid comparison between Unknown and I4 List list = PeopleOf(town); Dictionary dictionary = new Dictionary(plan.Duties); plan.Duties.Clear(); plan.SupplyItem.Clear(); plan.Short.Clear(); plan.People = list.Count; if (list.Count == 0) { plan.Summary = ""; return; } float value = VillagersConfig.HomeRadius.Value; int num = 0; foreach (Container item2 in Village.Chests(town.Center, value)) { foreach (ItemData allItem in item2.GetInventory().GetAllItems()) { if (IsFood(allItem)) { num += allItem.m_stack; } } } plan.FoodDays = (float)num / (3f * (float)list.Count); int num2 = 0; foreach (ItemDrop item3 in WorldScan.All(2f)) { ItemDrop val = item3; if ((Object)(object)val == (Object)null) { continue; } ItemType itemType = val.m_itemData.m_shared.m_itemType; if ((int)itemType == 1 || (int)itemType == 2) { Vector3 val2 = ((Component)val).transform.position - town.Center; val2.y = 0f; if (((Vector3)(ref val2)).magnitude <= town.Radius) { num2++; } } } plan.Loose = num2; bool flag = VillagersConfig.AutoBuild.Value && VillagersConfig.Buildings.Value && VillageInfo.VillagersBuild(town); plan.Building = flag && (!News.TryGetValue(town.Id, out var value2) || value2.Until > Time.time || Time.time - value2.DoneAt > 90f); if (plan.Building && News.TryGetValue(town.Id, out value2)) { foreach (KeyValuePair item4 in value2.Short) { if (item4.Value > Time.time) { plan.Short.Add(item4.Key); } } } List list2 = new List(); foreach (VillagerCharacter item5 in list) { if (item5.Job == VillagerJob.Guard) { plan.Duties[((Object)item5).GetInstanceID()] = Duty.Guard; } else { list2.Add(item5); } } if (plan.FoodDays < 2f && list2.Count > 0) { int num3 = ((!(plan.FoodDays < 0.5f) || list2.Count < 4) ? 1 : 2); for (int i = 0; i < num3; i++) { if (list2.Count <= 0) { break; } VillagerCharacter villagerCharacter = Pick(list2, dictionary, Duty.Food, (VillagerCharacter p) => (p.Job != VillagerJob.Hunter && p.Job != VillagerJob.Farmer && p.Job != VillagerJob.Cook) ? ((p.Job == VillagerJob.Gatherer) ? 1 : 0) : 2); plan.Duties[((Object)villagerCharacter).GetInstanceID()] = Duty.Food; } } if (plan.Building) { foreach (string item in plan.Short) { for (int num4 = 0; num4 < 2; num4++) { if (list2.Count <= 1) { break; } VillagerCharacter villagerCharacter2 = Pick(list2, dictionary, Duty.Supply, (VillagerCharacter p) => Makes(p.Job, item)); int num5 = Makes(villagerCharacter2.Job, item); if (num5 == 0 || (num4 > 0 && num5 < 2)) { list2.Add(villagerCharacter2); break; } plan.Duties[((Object)villagerCharacter2).GetInstanceID()] = Duty.Supply; plan.SupplyItem[((Object)villagerCharacter2).GetInstanceID()] = item; } } } bool flag2 = false; foreach (Duty value3 in dictionary.Values) { if (value3 == Duty.Haul) { flag2 = true; } } if (num2 >= (flag2 ? 3 : 6) && list2.Count > 1) { VillagerCharacter villagerCharacter3 = Pick(list2, dictionary, Duty.Haul, (VillagerCharacter p) => (p.Job == VillagerJob.Gatherer) ? 2 : 0); plan.Duties[((Object)villagerCharacter3).GetInstanceID()] = Duty.Haul; } foreach (VillagerCharacter item6 in list2) { plan.Duties[((Object)item6).GetInstanceID()] = (plan.Building ? Duty.Build : Duty.Trade); } plan.Summary = Describe(plan); if (DynastyPlugin.VerboseOn && Changed(dictionary, plan.Duties)) { DynastyPlugin.Log.LogInfo((object)(town.Name + " foreman: " + plan.Summary + " [" + Roster(list, plan) + "]")); } } private static VillagerCharacter Pick(List free, Dictionary old, Duty duty, Func suit) { VillagerCharacter villagerCharacter = null; int num = int.MinValue; foreach (VillagerCharacter item in free) { Duty value; int num2 = suit(item) * 10 + ((old.TryGetValue(((Object)item).GetInstanceID(), out value) && value == duty) ? 5 : 0); if (num2 > num) { num = num2; villagerCharacter = item; } } free.Remove(villagerCharacter); return villagerCharacter; } public static int Makes(VillagerJob job, string item) { switch (item) { case "Wood": if (job != VillagerJob.Woodcutter) { return (job == VillagerJob.Gatherer) ? 1 : 0; } return 2; case "Stone": case "Flint": if (job != VillagerJob.Miner) { return (job == VillagerJob.Gatherer) ? 1 : 0; } return 2; case "LeatherScraps": case "DeerHide": if (job != VillagerJob.Hunter) { return 0; } return 2; case "Resin": if (job != VillagerJob.Woodcutter && job != VillagerJob.Gatherer) { return 0; } return 1; default: return 0; } } private static bool Changed(Dictionary a, Dictionary b) { if (a.Count != b.Count) { return true; } foreach (KeyValuePair item in b) { if (!a.TryGetValue(item.Key, out var value) || value != item.Value) { return true; } } return false; } private static string Describe(Plan plan) { int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; using (Dictionary.ValueCollection.Enumerator enumerator = plan.Duties.Values.GetEnumerator()) { while (enumerator.MoveNext()) { switch (enumerator.Current) { case Duty.Build: num++; break; case Duty.Supply: num2++; break; case Duty.Food: num3++; break; case Duty.Haul: num4++; break; case Duty.Guard: num5++; break; default: num6++; break; } } } List list = new List(); if (num > 0) { list.Add($"{num} building"); } if (num2 > 0) { list.Add(string.Format("{0} fetching {1} for the builders", num2, string.Join(" and ", plan.Short.ToArray()).ToLowerInvariant())); } if (num3 > 0) { list.Add($"{num3} bringing in food (stores low)"); } if (num4 > 0) { list.Add($"{num4} putting things away"); } if (num6 > 0) { list.Add($"{num6} at their trades"); } if (num5 > 0) { list.Add($"{num5} on guard"); } return string.Join(" · ", list.ToArray()); } private static string Roster(List people, Plan plan) { StringBuilder stringBuilder = new StringBuilder(); foreach (VillagerCharacter person in people) { plan.Duties.TryGetValue(((Object)person).GetInstanceID(), out var value); plan.SupplyItem.TryGetValue(((Object)person).GetInstanceID(), out var value2); if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(person.VillagerName).Append('=').Append(value) .Append((value2 != null) ? (":" + value2) : ""); } return stringBuilder.ToString(); } } internal static class TownPlanView { internal sealed class Entry { public Blueprints.Site Site; public string Key; public string Name; public string State; public int Built; public int Total; public bool Started; public bool Cancelled; public bool Finished; } private static readonly Dictionary>> Cache = new Dictionary>>(); private static readonly Dictionary Where = new Dictionary { { "workshop", "east" }, { "hut", "west" }, { "house0", "west" }, { "house1", "north" }, { "house2", "south" }, { "house3", "south-west" }, { "store0", "south-east" }, { "store1", "north-east" }, { "store2", "south-west" }, { "store3", "far east" } }; public const float MaxMove = 16f; private static readonly Dictionary> Sent = new Dictionary>(); private static Texture2D _px; private static string Title(string plan) { if (plan.Length <= 0) { return plan; } return char.ToUpperInvariant(plan[0]) + plan.Substring(1); } public static string Label(string key, string plan) { if (!Where.TryGetValue(key ?? "", out var value)) { return Title(plan); } return Title(plan) + " (" + value + ")"; } public static List Entries(VillageInfo v) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) if (Cache.TryGetValue(v.Id, out var value) && Time.time - value.Key < 2f) { return value.Value; } List list = new List(); if (VillageGround.Target(v, out var h)) { int beds = Blueprints.BedsWanted(v, Wanderer.VillagersIn(v)); TownManager.Plan plan = TownManager.PlanFor(v); foreach (Blueprints.Site item in Blueprints.Sites(v.Center, h, beds)) { if (item.Plan.Parts.Count == 0 || item.Key == null) { continue; } Entry entry = new Entry { Site = item, Key = item.Key, Name = Label(item.Key, item.Plan.Name), Started = item.Started, Total = item.Plan.Parts.Count }; foreach (Blueprints.Part part in item.Plan.Parts) { Vector3 at = item.World(part); if (VillageLayout.Built(part.Prefab, at)) { entry.Built++; continue; } string[] alt = part.Alt; for (int i = 0; i < alt.Length; i++) { if (VillageLayout.Built(alt[i], at)) { entry.Built++; break; } } } entry.Finished = entry.Built >= entry.Total; if (entry.Finished) { entry.State = "finished"; } else if (!VillageInfo.VillagersBuild(v)) { entry.State = "villagers' building is switched off"; } else if (!TownClearing.SiteClear(v, item)) { entry.State = "clearing the ground"; } else if (!Blueprints.SiteReady(item)) { entry.State = ((Blueprints.Drop(item) > 4f) ? "too steep here: move it or remove it" : "the stairs can't reach the ground here: move it"); } else if (plan.Short.Count > 0 && entry.Started) { entry.State = "waiting on " + string.Join(", ", plan.Short.ToArray()).ToLowerInvariant(); } else { entry.State = (entry.Started ? "going up" : "planned"); } list.Add(entry); } foreach (string key in Blueprints.CancelledKeys(v)) { if (!list.Exists((Entry x) => x.Key == key)) { list.Add(new Entry { Key = key, Name = Label(key, key.StartsWith("store") ? "storehouse" : (key.StartsWith("house") ? "longhouse" : key)), Cancelled = true, State = "removed from the plan" }); } } } Cache[v.Id] = new KeyValuePair>(Time.time, list); return list; } public static void Forget(string villageId) { Cache.Remove(villageId); Blueprints.ForgetPlans(); } public static void Change(VillageInfo v, string key, Action change) { string spec = ModData.Get(Blueprints.EditKey(v.Id)); if (Sent.TryGetValue(v.Id, out var value) && Time.time - value.Key < 3f) { spec = value.Value; } Dictionary dictionary = Blueprints.ParseEdits(spec); if (!dictionary.TryGetValue(key, out var value2)) { value2 = (dictionary[key] = new Blueprints.PlanEdit()); } change(value2); value2.Dx = Mathf.Clamp(value2.Dx, -16f, 16f); value2.Dz = Mathf.Clamp(value2.Dz, -16f, 16f); string text = Blueprints.EncodeEdits(dictionary); Sent[v.Id] = new KeyValuePair(Time.time, text); VillageNet.SetPlan(v.Id, text); Forget(v.Id); } private static bool HoldingHammer() { Player localPlayer = Player.m_localPlayer; ItemData val = (((Object)(object)localPlayer != (Object)null) ? ((Humanoid)localPlayer).GetCurrentWeapon() : null); if (val != null && val.m_shared != null) { return val.m_shared.m_name == "$item_hammer"; } return false; } public static void Draw() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0562: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_036a: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_037b: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_040a: Unknown result type (might be due to invalid IL or missing references) //IL_040c: Unknown result type (might be due to invalid IL or missing references) //IL_038b: Unknown result type (might be due to invalid IL or missing references) //IL_0483: Unknown result type (might be due to invalid IL or missing references) //IL_048d: Expected O, but got Unknown //IL_0488: Unknown result type (might be due to invalid IL or missing references) //IL_048d: Unknown result type (might be due to invalid IL or missing references) //IL_048f: Unknown result type (might be due to invalid IL or missing references) //IL_0496: Unknown result type (might be due to invalid IL or missing references) //IL_04b0: Unknown result type (might be due to invalid IL or missing references) //IL_04be: Unknown result type (might be due to invalid IL or missing references) //IL_04d0: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Unknown result type (might be due to invalid IL or missing references) //IL_04f3: Unknown result type (might be due to invalid IL or missing references) //IL_04fe: Unknown result type (might be due to invalid IL or missing references) //IL_0512: Unknown result type (might be due to invalid IL or missing references) //IL_0517: Unknown result type (might be due to invalid IL or missing references) //IL_051e: Unknown result type (might be due to invalid IL or missing references) //IL_0525: Unknown result type (might be due to invalid IL or missing references) //IL_052f: Expected O, but got Unknown //IL_0536: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Camera mainCamera = Utils.GetMainCamera(); if ((Object)(object)localPlayer == (Object)null || (Object)(object)mainCamera == (Object)null || (!HoldingHammer() && !VillageScreen.BuildingsTabOpen)) { return; } VillageInfo villageInfo = VillageInfo.At(((Component)localPlayer).transform.position); if (villageInfo == null || !villageInfo.IsMember(VillageInfo.LocalPlayerId)) { return; } if ((Object)(object)_px == (Object)null) { _px = UiTex.Solid(Color.white); } foreach (Entry item in Entries(villageInfo)) { if (item.Site == null || item.Finished) { continue; } Blueprints.Site site = item.Site; Color val = (item.Started ? new Color(1f, 0.78f, 0.3f, 0.9f) : new Color(0.55f, 0.9f, 1f, 0.8f)); if (item.State.StartsWith("clearing") || item.State.StartsWith("levelling")) { ((Color)(ref val))..ctor(1f, 0.55f, 0.45f, 0.85f); } float num = site.Floor + 0.05f; Vector3[] array = (Vector3[])(object)new Vector3[4]; int num2 = 0; Vector2[] array2 = (Vector2[])(object)new Vector2[4] { new Vector2(-1f, -1f), new Vector2(1f, -1f), new Vector2(1f, 1f), new Vector2(-1f, 1f) }; foreach (Vector2 val2 in array2) { Vector3 val3 = site.Pos + site.Rot * new Vector3(val2.x * site.Plan.Half.x, 0f, val2.y * site.Plan.Half.y); val3.y = num; array[num2++] = val3; } bool flag = true; Vector2[] array3 = (Vector2[])(object)new Vector2[4]; for (int j = 0; j < 4; j++) { Vector3 val4 = mainCamera.WorldToScreenPoint(array[j]); if (val4.z < 0.5f) { flag = false; break; } array3[j] = new Vector2(val4.x, (float)Screen.height - val4.y); } if (flag) { for (int k = 0; k < 4; k++) { Line(array3[k], array3[(k + 1) % 4], val, 3f); } Vector3 val5 = site.Pos + site.Rot * new Vector3(site.Plan.DoorX, 0f, site.Plan.Half.y); val5.y = num; Vector3 val6 = site.Pos + site.Rot * new Vector3(site.Plan.DoorX, 0f, site.Plan.Half.y + 1.2f); val6.y = num; Vector3 val7 = mainCamera.WorldToScreenPoint(val5); Vector3 val8 = mainCamera.WorldToScreenPoint(val6); if (val7.z > 0.5f && val8.z > 0.5f) { Line(new Vector2(val7.x, (float)Screen.height - val7.y), new Vector2(val8.x, (float)Screen.height - val8.y), val, 4f); } Vector3 val9 = mainCamera.WorldToScreenPoint(site.Pos + Vector3.up * (num - site.Pos.y + 3.5f)); if (val9.z > 0.5f) { string text = $"{item.Name}\n{item.Built}/{item.Total} · {item.State}"; Vector2 val10 = GUI.skin.label.CalcSize(new GUIContent(item.Name + " 000/000 · " + item.State)); Rect val11 = new Rect(val9.x - val10.x / 2f - 6f, (float)Screen.height - val9.y - 22f, val10.x + 12f, 42f); GUI.color = new Color(0f, 0f, 0f, 0.6f); GUI.DrawTexture(val11, (Texture)(object)_px); GUI.color = Color.white; GUIStyle val12 = new GUIStyle(GUI.skin.label) { alignment = (TextAnchor)4, richText = true, fontSize = 13 }; val12.normal.textColor = val; GUI.Label(val11, text, val12); } } } GUI.color = Color.white; } private static void Line(Vector2 a, Vector2 b, Color col, float width) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) Vector2 val = b - a; float magnitude = ((Vector2)(ref val)).magnitude; if (!(magnitude < 1f) && !(magnitude > 6000f)) { float num = Mathf.Atan2(val.y, val.x) * 57.29578f; Matrix4x4 matrix = GUI.matrix; GUIUtility.RotateAroundPivot(num, a); GUI.color = col; GUI.DrawTexture(new Rect(a.x, a.y - width / 2f, magnitude, width), (Texture)(object)_px); GUI.matrix = matrix; GUI.color = Color.white; } } } internal static class VillageGround { public enum CellState { Level, Todo, Skip } public const float Cell = 4f; public const float Core = 20f; public const float MaxDiff = 2f; public const float Tolerance = 0.25f; private static readonly Dictionary> CellCache = new Dictionary>(); private static readonly Dictionary> Pads = new Dictionary>(); public const float Plaza = 6f; private static readonly List PieceHits = new List(); private static readonly Dictionary Tries = new Dictionary(); private static readonly Dictionary NothingUntil = new Dictionary(); private static bool _logged; private static readonly Vector2[] Spots = (Vector2[])(object)new Vector2[5] { Vector2.zero, new Vector2(-1.1f, -1.1f), new Vector2(1.1f, -1.1f), new Vector2(-1.1f, 1.1f), new Vector2(1.1f, 1.1f) }; public static string Key(string villageId) { return "vlevel." + villageId; } public static bool Target(VillageInfo v, out float h) { h = 0f; string text = ModData.Get(Key(v.Id)); if (!string.IsNullOrEmpty(text)) { return float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out h); } return false; } public static float Decide(VillageInfo v) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) List list = new List(); for (int i = 0; i < 9; i++) { Vector3 val = v.Center + ((i == 0) ? Vector3.zero : (Quaternion.Euler(0f, (float)i * 45f, 0f) * Vector3.forward * 5f)); list.Add(ZoneSystem.instance.GetGroundHeight(val)); } list.Sort(); float num = list[list.Count / 2]; ZPackage obj = NetSync.BeginVillage(VillageNet.Action.VillageLevel, v.Id); obj.Write(num); NetSync.SendVillage(obj); return num; } public static List Cells(VillageInfo v) { //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) string key = v.Id + "|" + v.Center.x.ToString("0", CultureInfo.InvariantCulture) + "|" + v.Center.z.ToString("0", CultureInfo.InvariantCulture) + "|" + v.Radius; if (CellCache.TryGetValue(key, out var value)) { return value; } value = new List(); int num = Mathf.CeilToInt(v.Radius / 4f); Vector3 val = default(Vector3); for (int i = -num; i <= num; i++) { for (int j = -num; j <= num; j++) { ((Vector3)(ref val))..ctor((float)i * 4f, 0f, (float)j * 4f); if (!(((Vector3)(ref val)).magnitude + 2f > v.Radius)) { value.Add(v.Center + val); } } } Vector3 c = v.Center; value.Sort(delegate(Vector3 a, Vector3 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) Vector3 val2 = a - c; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; val2 = b - c; return sqrMagnitude.CompareTo(((Vector3)(ref val2)).sqrMagnitude); }); CellCache[key] = value; return value; } public static void SetPads(VillageInfo v, List sites) { Pads[v.Id] = sites; } public static bool IsPad(VillageInfo v, Vector3 cell) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) if (Flat(cell - v.Center) <= 6f) { return true; } if (!Pads.TryGetValue(v.Id, out var value)) { return false; } foreach (Blueprints.Site item in value) { if (item.Plan.Parts.Count > 0 && item.Contains(cell, 1.5f)) { return true; } } return false; } public static float TargetAt(VillageInfo v, Vector3 cell, float h) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (!Pads.TryGetValue(v.Id, out var value)) { return h; } foreach (Blueprints.Site item in value) { if (item.Started && item.Plan.Parts.Count > 0 && item.Contains(cell, 1.5f)) { return item.Base; } } return h; } private static long CellKey(Vector3 c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) return ((long)Mathf.RoundToInt(c.x) << 32) ^ (uint)Mathf.RoundToInt(c.z); } public static CellState Check(Vector3 cell, float h) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) float waterLevel = ZoneSystem.instance.m_waterLevel; float num = float.MaxValue; float num2 = float.MinValue; for (int i = 0; i < 5; i++) { Vector3 val = cell + (Vector3)((i == 0) ? Vector3.zero : new Vector3(((i & 1) == 0) ? (-1.6f) : 1.6f, 0f, (i < 3) ? (-1.6f) : 1.6f)); float groundHeight = ZoneSystem.instance.GetGroundHeight(val); num = Mathf.Min(num, groundHeight); num2 = Mathf.Max(num2, groundHeight); } if (num < waterLevel + 0.5f) { return CellState.Skip; } if (Mathf.Abs(num - h) < 0.25f && Mathf.Abs(num2 - h) < 0.25f) { return CellState.Level; } if (Mathf.Abs(num - h) > 2f || Mathf.Abs(num2 - h) > 2f) { return CellState.Skip; } PieceHits.Clear(); Piece.GetAllPiecesInRadius(cell, 3.2f, PieceHits); if (PieceHits.Count > 0) { return CellState.Skip; } foreach (Component item in WorldScan.All(10f)) { if ((Object)(object)item != (Object)null && Flat(item.transform.position - cell) < 3f) { return CellState.Skip; } } foreach (Component item2 in WorldScan.All(10f)) { if ((Object)(object)item2 != (Object)null && Flat(item2.transform.position - cell) < 4f) { return CellState.Skip; } } foreach (Component item3 in WorldScan.All(8f)) { Destructible val2 = (Destructible)(object)((item3 is Destructible) ? item3 : null); if ((Object)(object)val2 != (Object)null && IsStump(val2) && Flat(((Component)val2).transform.position - cell) < 3f) { return CellState.Skip; } } if (Tries.TryGetValue(CellKey(cell), out var value) && value >= 1) { return CellState.Skip; } return CellState.Todo; } private static float Flat(Vector3 d) { d.y = 0f; return ((Vector3)(ref d)).magnitude; } public static bool IsStump(Destructible d) { if ((Object)(object)d == (Object)null) { return false; } return Utils.GetPrefabName(((Component)d).gameObject).ToLowerInvariant().Contains("stub"); } public static Vector3? Next(VillageInfo v, float h, bool coreOnly, Object who) { string key = v.Id + (coreOnly ? "|core" : "|all"); if (NothingUntil.TryGetValue(key, out var value) && Time.time < value) { return null; } Vector3? result = Find(v, h, coreOnly, who); if (!result.HasValue) { NothingUntil[key] = Time.time + 20f; } return result; } private static Vector3? Find(VillageInfo v, float h, bool coreOnly, Object who) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) foreach (Vector3 item in Cells(v)) { if (coreOnly && Flat(item - v.Center) > 20f) { break; } if (!IsPad(v, item)) { continue; } float num = TargetAt(v, item, h); if (Check(item, num) == CellState.Todo) { Vector3 at = item; at.y = num; if (VillageLayout.Claim(at, who)) { return item; } } } return null; } public static void Progress(VillageInfo v, out int level, out int todo) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) level = 0; todo = 0; if (!Target(v, out var h)) { todo = Cells(v).Count; return; } foreach (Vector3 item in Cells(v)) { if (IsPad(v, item)) { switch (Check(item, TargetAt(v, item, h))) { case CellState.Level: level++; break; case CellState.Todo: todo++; break; } } } } private static void Op(string prefabName, Vector3 at) { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(prefabName) : null); if ((Object)(object)val == (Object)null) { return; } if (!_logged) { _logged = true; TerrainOp component = val.GetComponent(); if ((Object)(object)component != (Object)null) { DynastyPlugin.Log.LogInfo((object)$"Levelling with {prefabName}: level {component.m_settings.m_level} r{component.m_settings.m_levelRadius}, paint r{component.m_settings.m_paintRadius}."); } } Object.Instantiate(val, at, Quaternion.identity); } public static void Level(VillageInfo v, Vector3 cell, float h) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) Tries.TryGetValue(CellKey(cell), out var value); Tries[CellKey(cell)] = value + 1; Vector2[] spots = Spots; foreach (Vector2 val in spots) { Op("mud_road", new Vector3(cell.x + val.x, h, cell.z + val.y)); } } } [Flags] internal enum VillagePerm { None = 0, Jobs = 1, Homes = 2, Invite = 4, Recruit = 8, Storage = 0x10, Default = 0x1B } internal sealed class VillageInfo { public const string KeyPrefix = "village."; public string Id; public string Name; public long Leader; public string LeaderName; public Vector3 Center; public float Radius; public VillagePerm MemberPerms = VillagePerm.Default; public readonly Dictionary Members = new Dictionary(); private static float _cacheTime = -1f; private static readonly List Cache = new List(); public string Key => "village." + Id; public bool BuildsOn => VillagersBuild(this); public static long LocalPlayerId { get { if (!((Object)(object)Player.m_localPlayer != (Object)null)) { return 0L; } return Player.m_localPlayer.GetPlayerID(); } } public static string LocalPlayerName { get { if (!((Object)(object)Player.m_localPlayer != (Object)null)) { return ""; } return Player.m_localPlayer.GetPlayerName(); } } public static bool VillagersBuild(VillageInfo v) { if (v != null && !v.Id.StartsWith("camp:")) { return string.IsNullOrEmpty(ModData.Get("vnobuild." + v.Id)); } return true; } public bool IsMember(long playerId) { if (playerId != 0L) { return Members.ContainsKey(playerId); } return false; } public bool IsLeader(long playerId) { if (playerId != 0L) { return playerId == Leader; } return false; } public bool Can(long playerId, VillagePerm perm) { if (!IsLeader(playerId)) { if (IsMember(playerId)) { return (MemberPerms & perm) == perm; } return false; } return true; } public bool Contains(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = p - Center; val.y = 0f; return ((Vector3)(ref val)).sqrMagnitude <= Radius * Radius; } private static string Clean(string s) { if (string.IsNullOrEmpty(s)) { return ""; } StringBuilder stringBuilder = new StringBuilder(s.Length); foreach (char c in s) { stringBuilder.Append((c == '|' || c == ',' || c == ':' || char.IsControl(c)) ? ' ' : c); } string text = stringBuilder.ToString().Trim(); if (text.Length <= 40) { return text; } return text.Substring(0, 40); } public string Serialize() { CultureInfo invariantCulture = CultureInfo.InvariantCulture; List list = new List(); foreach (KeyValuePair member in Members) { list.Add(member.Key.ToString(invariantCulture) + ":" + Clean(member.Value)); } string[] obj = new string[10] { "v1", Clean(Name), Leader.ToString(invariantCulture), Clean(LeaderName), Center.x.ToString("0.##", invariantCulture), Center.y.ToString("0.##", invariantCulture), Center.z.ToString("0.##", invariantCulture), Radius.ToString("0.#", invariantCulture), null, null }; int memberPerms = (int)MemberPerms; obj[8] = memberPerms.ToString(invariantCulture); obj[9] = string.Join(",", list.ToArray()); return string.Join("|", obj); } public static VillageInfo Parse(string id, string s) { //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(s)) { return null; } string[] array = s.Split(new char[1] { '|' }); if (array.Length < 10 || array[0] != "v1") { return null; } CultureInfo invariantCulture = CultureInfo.InvariantCulture; VillageInfo villageInfo = new VillageInfo { Id = id, Name = array[1], LeaderName = array[3] }; if (!long.TryParse(array[2], NumberStyles.Integer, invariantCulture, out villageInfo.Leader)) { return null; } float.TryParse(array[4], NumberStyles.Float, invariantCulture, out var result); float.TryParse(array[5], NumberStyles.Float, invariantCulture, out var result2); float.TryParse(array[6], NumberStyles.Float, invariantCulture, out var result3); float.TryParse(array[7], NumberStyles.Float, invariantCulture, out var result4); int.TryParse(array[8], NumberStyles.Integer, invariantCulture, out var result5); villageInfo.Center = new Vector3(result, result2, result3); villageInfo.Radius = ((result4 > 0f) ? result4 : 40f); villageInfo.MemberPerms = (VillagePerm)result5; string[] array2 = array[9].Split(new char[1] { ',' }); for (int i = 0; i < array2.Length; i++) { string[] array3 = array2[i].Split(new char[1] { ':' }); if (array3.Length >= 2 && long.TryParse(array3[0], NumberStyles.Integer, invariantCulture, out var result6)) { villageInfo.Members[result6] = array3[1]; } } return villageInfo; } public static List All() { if (Time.time - _cacheTime < 0.5f && _cacheTime >= 0f) { return Cache; } _cacheTime = Time.time; Cache.Clear(); foreach (string item in ModData.Keys()) { if (item.StartsWith("village.")) { VillageInfo villageInfo = Parse(item.Substring("village.".Length), ModData.Get(item)); if (villageInfo != null) { Cache.Add(villageInfo); } } } return Cache; } public static void Invalidate() { _cacheTime = -1f; } public static VillageInfo At(Vector3 p) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) VillageInfo result = null; float num = float.MaxValue; foreach (VillageInfo item in All()) { if (item.Contains(p)) { Vector3 val = item.Center - p; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; result = item; } } } return result; } public static VillageInfo ById(string id) { foreach (VillageInfo item in All()) { if (item.Id == id) { return item; } } return null; } public static VillageInfo LedBy(long playerId) { foreach (VillageInfo item in All()) { if (item.Leader == playerId) { return item; } } return null; } } internal static class VillageMover { public static bool FindSpot(VillageInfo v, out Vector3 spot) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Invalid comparison between Unknown and I4 //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) spot = Vector3.zero; float waterLevel = ZoneSystem.instance.m_waterLevel; for (float num = 60f; num <= 110f; num += 10f) { for (int i = 0; i < 24; i++) { Vector3 val = v.Center + Quaternion.Euler(0f, (float)i * 15f, 0f) * Vector3.forward * num; val.y = WorldGenerator.instance.GetHeight(val); if (val.y < waterLevel + 2f || (int)WorldGenerator.instance.GetBiome(val) != 1 || !ZoneSystem.instance.IsZoneLoaded(val) || !CampSim.Flat(val, 16f, 2f) || Landmarks.OnTop(val, out var _)) { continue; } bool flag = false; foreach (VillageInfo item in VillageInfo.All()) { if (item.Id != v.Id && Vector3.Distance(item.Center, val) < item.Radius + v.Radius) { flag = true; } } foreach (CampInfo item2 in CampInfo.All()) { if (Vector3.Distance(item2.Center, val) < v.Radius + 30f) { flag = true; } } if (!flag) { spot = val; return true; } } } return false; } public static string Move(VillageInfo v, Vector3 to) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) if (!ZoneSystem.instance.IsZoneLoaded(to)) { return "That spot isn't loaded; stand closer to it."; } to.y = ZoneSystem.instance.GetGroundHeight(to); Vector3 center = v.Center; Vector3 val = to - center; val.y = 0f; float num = v.Radius * v.Radius; int num2 = 0; int num3 = 0; List list = new List(); Piece[] array = Object.FindObjectsOfType(); foreach (Piece val2 in array) { if ((Object)(object)val2 == (Object)null) { continue; } Vector3 val3 = ((Component)val2).transform.position - center; val3.y = 0f; if (!(((Vector3)(ref val3)).sqrMagnitude > num) && ((Object)(object)((Component)val2).GetComponent() != (Object)null || val2.GetCreator() == 0L) && !((Object)(object)((Component)val2).GetComponent() != (Object)null)) { string prefabName = Utils.GetPrefabName(((Component)val2).gameObject); if (prefabName == "wood_pole2" || prefabName == "wood_floor") { list.Add(val2); continue; } Vector3 position = ((Component)val2).transform.position; Vector3 val4 = position + val; val4.y = ZoneSystem.instance.GetGroundHeight(val4) + (position.y - ZoneSystem.instance.GetGroundHeight(position)); VillageLayout.Move(((Component)val2).gameObject, new VillageLayout.Slot { Pos = val4, Rot = ((Component)val2).transform.rotation }); num2++; } } foreach (VillagerCharacter item in VillagerCharacter.All) { if (!((Object)(object)item == (Object)null) && !((Character)item).IsDead() && string.IsNullOrEmpty(item.CampId)) { Vector3 home = item.Home; Vector3 val5 = home - center; val5.y = 0f; if (!(((Vector3)(ref val5)).sqrMagnitude > num)) { ZNetView component = ((Component)item).GetComponent(); component.ClaimOwnership(); Vector3 val6 = home + val; val6.y = ZoneSystem.instance.GetGroundHeight(val6); component.GetZDO().Set("vdyn_home", val6); } } } v.Center = to; ModData.ServerApply(v.Key, v.Serialize()); VillageInfo.Invalidate(); WorldScan.Invalidate(); WorldScan.Invalidate(); WorldScan.Invalidate(); WorldScan.Invalidate(); VillagerPlaces.Invalidate(); foreach (Piece item2 in list) { VillageLayout.Dismantle(item2, to, v.Radius); num3++; } string text = VillageLayout.Tidy(to, v.Radius); string text2 = $"Moved {v.Name} {((Vector3)(ref val)).magnitude:0} m: {num2} building(s) moved, {num3} hall piece(s) taken down to rebuild. {text}"; DynastyPlugin.Log.LogInfo((object)text2); return text2; } } internal static class VillageNeeds { private sealed class Wants { public float At; public List> Items = new List>(); public Dictionary For = new Dictionary(); } private static readonly Dictionary NextLearn = new Dictionary(); private static readonly Dictionary> Handled = new Dictionary>(); private static List _pieces; private static readonly Dictionary WantCache = new Dictionary(); private static readonly ItemType[] ArmorSlots; private static readonly Dictionary> Obtainable; private static readonly HashSet Common; private static readonly Dictionary> YieldCache; public static HashSet Materials(VillageInfo v) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) if (!Handled.TryGetValue(v.Id, out var value)) { value = new HashSet(); Handled[v.Id] = value; } foreach (Container item in Village.Chests(v.Center, v.Radius)) { foreach (ItemData allItem in item.GetInventory().GetAllItems()) { value.Add(allItem.m_shared.m_name); } } foreach (VillagerCharacter item2 in VillagerCharacter.All) { if (!((Object)(object)item2 != (Object)null) || ((Character)item2).IsDead() || item2.IsWanderer || !v.Contains(item2.Home)) { continue; } foreach (ItemData allItem2 in ((Humanoid)item2).GetInventory().GetAllItems()) { value.Add(allItem2.m_shared.m_name); } } return value; } private static bool AllIn(Requirement[] reqs, HashSet mats) { if (reqs == null) { return false; } int num = 0; foreach (Requirement val in reqs) { if (val != null && !((Object)(object)val.m_resItem == (Object)null) && val.m_amount > 0 && !Village.UpgradeOnly(val)) { if (!mats.Contains(val.m_resItem.m_itemData.m_shared.m_name)) { return false; } num++; } } return num > 0; } public static List AllPieces() { if (_pieces != null && _pieces.Count > 0) { return _pieces; } _pieces = new List(); if ((Object)(object)ObjectDB.instance == (Object)null) { return _pieces; } foreach (GameObject item in ObjectDB.instance.m_items) { ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent() : null); PieceTable val2 = (((Object)(object)val != (Object)null) ? val.m_itemData.m_shared.m_buildPieces : null); if ((Object)(object)val2 == (Object)null || val2.m_pieces == null) { continue; } foreach (GameObject piece in val2.m_pieces) { Piece val3 = (((Object)(object)piece != (Object)null) ? piece.GetComponent() : null); if ((Object)(object)val3 != (Object)null && !_pieces.Contains(val3)) { _pieces.Add(val3); } } } return _pieces; } public static void Learn(VillageInfo v) { if (!VillagesConfig.LearnOnTheirOwn.Value || !VillagesConfig.FollowProgression.Value || (Object)(object)ObjectDB.instance == (Object)null || (NextLearn.TryGetValue(v.Id, out var value) && Time.time < value)) { return; } NextLearn[v.Id] = Time.time + 20f; HashSet hashSet = VillageProgress.Known(v.Id); if (hashSet == null) { return; } HashSet hashSet2 = Materials(v); if (hashSet2.Count == 0) { return; } List list = new List(); foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if (!((Object)(object)recipe == (Object)null) && recipe.m_enabled && !((Object)(object)recipe.m_item == (Object)null) && !recipe.m_requireOnlyOneIngredient) { string name = recipe.m_item.m_itemData.m_shared.m_name; if (!hashSet.Contains(name) && !list.Contains(name) && AllIn(recipe.m_resources, hashSet2)) { list.Add(name); } } } foreach (Piece item in AllPieces()) { if (item.m_enabled && !hashSet.Contains(item.m_name) && !list.Contains(item.m_name) && AllIn(item.m_resources, hashSet2)) { list.Add(item.m_name); } } if (list.Count != 0) { if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)string.Format("{0} worked out {1} new thing(s) from its own materials: {2}", v.Name, list.Count, string.Join(", ", list.GetRange(0, Mathf.Min(8, list.Count)).ToArray()))); } VillageProgress.Teach(v, list); } } public static List> Wanted(VillageInfo v, VillagerCharacter asker, out Dictionary purpose) { //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_0488: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) if (!WantCache.TryGetValue(v.Id, out var value)) { value = new Wants { At = -100f }; WantCache[v.Id] = value; } purpose = value.For; if (Time.time - value.At < 20f) { return value.Items; } value.At = Time.time; value.Items.Clear(); value.For.Clear(); Dictionary dictionary = new Dictionary(); List list = new List(); int num = 0; if (VillageGround.Target(v, out var h) && (Object)(object)ZoneSystem.instance != (Object)null) { int beds = Blueprints.BedsWanted(v, Wanderer.VillagersIn(v)); HashSet hashSet = new HashSet(); foreach (Blueprints.Site item in Blueprints.Sites(v.Center, h, beds)) { foreach (Blueprints.Part part in item.Plan.Parts) { if (num >= 4) { break; } if (part.Use == Blueprints.Use.Chest || part.Use == Blueprints.Use.Bed || (hashSet.Contains(part.Prefab) && part.Use == Blueprints.Use.Structure)) { continue; } GameObject prefab = ZNetScene.instance.GetPrefab(part.Prefab); Piece val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent() : null); if ((Object)(object)val == (Object)null || (!VillageProgress.Knows(v, val.m_name) && (part.Use == Blueprints.Use.Structure || !VillagesConfig.LearnOnTheirOwn.Value)) || VillageLayout.Built(part.Prefab, item.World(part))) { continue; } bool flag = false; string[] alt = part.Alt; for (int i = 0; i < alt.Length; i++) { if (VillageLayout.Built(alt[i], item.World(part))) { flag = true; } } if (!flag) { hashSet.Add(part.Prefab); if ((VillageProgress.Knows(v, val.m_name) || Reachable(v, val.m_resources)) && Short(v, asker, val.m_resources, dictionary, list, value.For, Localization.instance.Localize(val.m_name))) { num++; } } } } } HashSet hashSet2 = new HashSet(); foreach (VillagerCharacter item2 in VillagerCharacter.All) { if ((Object)(object)item2 != (Object)null && !((Character)item2).IsDead() && !item2.IsWanderer && v.Contains(item2.Home)) { hashSet2.Add(item2.Job); } } foreach (VillagerJob item3 in hashSet2) { Recipe val2 = null; float num2 = 0f; foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if (!((Object)(object)recipe == (Object)null) && recipe.m_enabled && !((Object)(object)recipe.m_item == (Object)null) && !recipe.m_requireOnlyOneIngredient && recipe.m_resources != null && (VillageProgress.Knows(v, recipe.m_item.m_itemData.m_shared.m_name) || VillagesConfig.LearnOnTheirOwn.Value) && (!((Object)(object)recipe.m_craftingStation != (Object)null) || !((Object)(object)CraftingStation.FindClosestStationInRange(recipe.m_craftingStation.m_name, v.Center, v.Radius) == (Object)null))) { float num3 = VillagerWorker.Score(recipe.m_item.m_itemData, item3); if (!(num3 <= num2) && (VillageProgress.Knows(v, recipe.m_item.m_itemData.m_shared.m_name) || Reachable(v, recipe.m_resources))) { num2 = num3; val2 = recipe; } } } if ((Object)(object)val2 == (Object)null) { continue; } bool flag2 = false; foreach (VillagerCharacter item4 in VillagerCharacter.All) { if ((Object)(object)item4 != (Object)null && item4.Job == item3 && v.Contains(item4.Home) && ((Humanoid)item4).GetInventory().CountItems(val2.m_item.m_itemData.m_shared.m_name, -1, true) > 0) { flag2 = true; } } if (!flag2) { Short(v, asker, val2.m_resources, dictionary, list, value.For, Localization.instance.Localize(val2.m_item.m_itemData.m_shared.m_name)); } } ArmorWants(v, asker, dictionary, list, value.For); for (int j = 0; j < 3; j++) { foreach (string item5 in new List(list)) { Expand(v, asker, item5, dictionary, list, value.For); } } foreach (string item6 in list) { value.Items.Add(new KeyValuePair(item6, dictionary[item6])); } if (DynastyPlugin.VerboseOn && value.Items.Count > 0) { StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair item7 in value.Items) { stringBuilder.Append($" {item7.Key} x{item7.Value} ({value.For[item7.Key]})"); } DynastyPlugin.Log.LogInfo((object)$"{v.Name} needs:{stringBuilder}"); } return value.Items; } private static float WornArmor(VillagerCharacter p, ItemType slot) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) float num = 0f; foreach (ItemData allItem in ((Humanoid)p).GetInventory().GetAllItems()) { if (allItem.m_shared.m_itemType == slot && !VillagerCharacter.Broken(allItem)) { num = Mathf.Max(num, allItem.GetArmor()); } } return num; } private static void ArmorWants(VillageInfo v, VillagerCharacter asker, Dictionary need, List order, Dictionary forWhat) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) List list = new List(); foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item != (Object)null && !((Character)item).IsDead() && !item.IsWanderer && v.Contains(item.Home)) { list.Add(item); } } if (list.Count == 0) { return; } int num = 0; ItemType[] armorSlots = ArmorSlots; foreach (ItemType val in armorSlots) { if (num >= 2) { break; } Recipe val2 = null; float num2 = 0f; foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe == (Object)null || !recipe.m_enabled || (Object)(object)recipe.m_item == (Object)null || recipe.m_requireOnlyOneIngredient || recipe.m_resources == null) { continue; } ItemData itemData = recipe.m_item.m_itemData; if (itemData.m_shared.m_itemType != val || (!VillageProgress.Knows(v, itemData.m_shared.m_name) && !VillagesConfig.LearnOnTheirOwn.Value) || ((Object)(object)recipe.m_craftingStation != (Object)null && (Object)(object)CraftingStation.FindClosestStationInRange(recipe.m_craftingStation.m_name, v.Center, v.Radius) == (Object)null && (!(recipe.m_craftingStation.m_name == "$piece_forge") || !VillageProgress.Knows(v, "$piece_forge")))) { continue; } float armor = itemData.GetArmor(); if (armor <= num2) { continue; } bool flag = false; foreach (VillagerCharacter item2 in list) { if (WornArmor(item2, val) < armor) { flag = true; break; } } if (flag && Reachable(v, recipe.m_resources)) { val2 = recipe; num2 = armor; } } if ((Object)(object)val2 != (Object)null && Short(v, asker, val2.m_resources, need, order, forWhat, Localization.instance.Localize(val2.m_item.m_itemData.m_shared.m_name))) { num++; } } } private static void Expand(VillageInfo v, VillagerCharacter asker, string item, Dictionary need, List order, Dictionary forWhat) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) if (FoundNearby(item) || !need.TryGetValue(item, out var value) || value <= 0) { return; } forWhat.TryGetValue(item, out var value2); foreach (Smelter item2 in WorldScan.All(5f)) { Smelter val = item2; if ((Object)(object)val == (Object)null || val.m_conversion == null || !v.Contains(((Component)val).transform.position)) { continue; } foreach (ItemConversion item3 in val.m_conversion) { if (item3 != null && !((Object)(object)item3.m_from == (Object)null) && !((Object)(object)item3.m_to == (Object)null) && !(((Object)((Component)item3.m_to).gameObject).name != item)) { Add(v, asker, item3.m_from, value, need, order, forWhat, value2); if ((Object)(object)val.m_fuelItem != (Object)null) { Add(v, asker, val.m_fuelItem, Mathf.CeilToInt((float)(value * Mathf.Max(1, val.m_fuelPerProduct))), need, order, forWhat, value2); } return; } } } foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe == (Object)null || !recipe.m_enabled || (Object)(object)recipe.m_item == (Object)null || recipe.m_resources == null || ((Object)((Component)recipe.m_item).gameObject).name != item || !VillageProgress.Knows(v, recipe.m_item.m_itemData.m_shared.m_name)) { continue; } int num = Mathf.CeilToInt((float)value / (float)Mathf.Max(1, recipe.m_amount)); Requirement[] resources = recipe.m_resources; foreach (Requirement val2 in resources) { if (val2 != null && (Object)(object)val2.m_resItem != (Object)null && val2.m_amount > 0 && !Village.UpgradeOnly(val2)) { Add(v, asker, val2.m_resItem, val2.m_amount * num, need, order, forWhat, value2); } } break; } } private static void Add(VillageInfo v, VillagerCharacter asker, ItemDrop item, int amount, Dictionary need, List order, Dictionary forWhat, string goal) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) string name = ((Object)((Component)item).gameObject).name; int num = Village.Count(asker, item.m_itemData.m_shared.m_name, v.Center, v.Radius); int num2 = amount - num; if (num2 > 0) { need.TryGetValue(name, out var value); need[name] = Mathf.Max(value, num2); if (!order.Contains(name)) { order.Add(name); forWhat[name] = goal ?? "village"; } } } private static bool Short(VillageInfo v, VillagerCharacter asker, Requirement[] reqs, Dictionary need, List order, Dictionary forWhat, string goal) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) if (reqs == null) { return false; } bool result = false; foreach (Requirement val in reqs) { if (val == null || (Object)(object)val.m_resItem == (Object)null || val.m_amount <= 0 || Village.UpgradeOnly(val)) { continue; } string name = ((Object)((Component)val.m_resItem).gameObject).name; int num = Village.Count(asker, val.m_resItem.m_itemData.m_shared.m_name, v.Center, v.Radius); int num2 = val.m_amount - num; if (num2 > 0) { result = true; need.TryGetValue(name, out var value); need[name] = Mathf.Max(value, num2); if (!order.Contains(name)) { order.Add(name); forWhat[name] = goal; } } } return result; } private static bool Reachable(VillageInfo v, Requirement[] reqs) { if (reqs == null) { return false; } HashSet hashSet = Materials(v); int num = 0; foreach (Requirement val in reqs) { if (val != null && !((Object)(object)val.m_resItem == (Object)null) && val.m_amount > 0 && !Village.UpgradeOnly(val)) { num++; if (!hashSet.Contains(val.m_resItem.m_itemData.m_shared.m_name) && !FoundNearby(((Object)((Component)val.m_resItem).gameObject).name) && !MadeHere(v, ((Object)((Component)val.m_resItem).gameObject).name, hashSet, 0)) { return false; } } } return num > 0; } private static bool MadeHere(VillageInfo v, string item, HashSet have, int depth) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) if (depth > 2) { return false; } foreach (Smelter item2 in WorldScan.All(5f)) { Smelter val = item2; if ((Object)(object)val == (Object)null || val.m_conversion == null || !v.Contains(((Component)val).transform.position)) { continue; } foreach (ItemConversion item3 in val.m_conversion) { if (item3 != null && (Object)(object)item3.m_from != (Object)null && (Object)(object)item3.m_to != (Object)null && ((Object)((Component)item3.m_to).gameObject).name == item && (have.Contains(item3.m_from.m_itemData.m_shared.m_name) || FoundNearby(((Object)((Component)item3.m_from).gameObject).name))) { return true; } } } foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe == (Object)null || !recipe.m_enabled || (Object)(object)recipe.m_item == (Object)null || recipe.m_resources == null || ((Object)((Component)recipe.m_item).gameObject).name != item || !VillageProgress.Knows(v, recipe.m_item.m_itemData.m_shared.m_name)) { continue; } bool flag = true; Requirement[] resources = recipe.m_resources; foreach (Requirement val2 in resources) { if (val2 != null && !((Object)(object)val2.m_resItem == (Object)null) && val2.m_amount > 0 && !Village.UpgradeOnly(val2) && !have.Contains(val2.m_resItem.m_itemData.m_shared.m_name) && !FoundNearby(((Object)((Component)val2.m_resItem).gameObject).name) && !MadeHere(v, ((Object)((Component)val2.m_resItem).gameObject).name, have, depth + 1)) { flag = false; break; } } if (flag) { return true; } } return false; } public static bool FoundNearby(string item) { //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Invalid comparison between Unknown and I4 if (Common.Contains(item)) { return true; } if (Obtainable.TryGetValue(item, out var value) && Time.time - value.Key < 60f) { return value.Value; } bool flag = false; foreach (Component item2 in WorldScan.All(8f)) { if ((Object)(object)item2 != (Object)null && Yields(item2.gameObject).Contains(item)) { flag = true; break; } } if (!flag) { foreach (Component item3 in WorldScan.All(10f)) { TreeBase val = (TreeBase)(object)((item3 is TreeBase) ? item3 : null); if ((Object)(object)val != (Object)null && val.m_minToolTier <= 1 && Yields(((Component)val).gameObject).Contains(item)) { flag = true; break; } } } if (!flag) { foreach (Component item4 in WorldScan.All(8f)) { Destructible val2 = (Destructible)(object)((item4 is Destructible) ? item4 : null); if ((Object)(object)val2 != (Object)null && val2.m_minToolTier <= 1 && Yields(((Component)val2).gameObject).Contains(item)) { flag = true; break; } } } if (!flag) { foreach (Component item5 in WorldScan.All(10f)) { MineRock5 val3 = (MineRock5)(object)((item5 is MineRock5) ? item5 : null); if ((Object)(object)val3 != (Object)null && val3.m_minToolTier <= 1 && Yields(((Component)val3).gameObject).Contains(item)) { flag = true; break; } } } if (!flag) { foreach (Character allCharacter in Character.GetAllCharacters()) { if ((Object)(object)allCharacter != (Object)null && !allCharacter.IsDead() && (int)allCharacter.m_faction == 1 && Yields(((Component)allCharacter).gameObject).Contains(item)) { flag = true; break; } } } Obtainable[item] = new KeyValuePair(Time.time, flag); return flag; } public static HashSet Yields(GameObject go) { string prefabName = Utils.GetPrefabName(go); if (YieldCache.TryGetValue(prefabName, out var value)) { return value; } value = new HashSet(); Pickable component = go.GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)component.m_itemPrefab != (Object)null) { value.Add(((Object)component.m_itemPrefab).name); } TreeBase component2 = go.GetComponent(); if ((Object)(object)component2 != (Object)null) { AddTable(value, component2.m_dropWhenDestroyed); if ((Object)(object)component2.m_logPrefab != (Object)null) { AddLog(value, component2.m_logPrefab.GetComponent(), 0); } } AddLog(value, go.GetComponent(), 0); DropOnDestroyed component3 = go.GetComponent(); if ((Object)(object)component3 != (Object)null) { AddTable(value, component3.m_dropWhenDestroyed); } MineRock component4 = go.GetComponent(); if ((Object)(object)component4 != (Object)null) { AddTable(value, component4.m_dropItems); } MineRock5 component5 = go.GetComponent(); if ((Object)(object)component5 != (Object)null) { AddTable(value, component5.m_dropItems); } CharacterDrop component6 = go.GetComponent(); if ((Object)(object)component6 != (Object)null && component6.m_drops != null) { foreach (Drop drop in component6.m_drops) { if (drop != null && (Object)(object)drop.m_prefab != (Object)null && drop.m_chance > 0.2f) { value.Add(((Object)drop.m_prefab).name); } } } YieldCache[prefabName] = value; return value; } private static void AddTable(HashSet set, DropTable t) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) if (t == null || t.m_drops == null) { return; } foreach (DropData drop in t.m_drops) { if ((Object)(object)drop.m_item != (Object)null && drop.m_weight > 0f) { set.Add(((Object)drop.m_item).name); } } } private static void AddLog(HashSet set, TreeLog log, int depth) { if (!((Object)(object)log == (Object)null) && depth <= 3) { AddTable(set, log.m_dropWhenDestroyed); if ((Object)(object)log.m_subLogPrefab != (Object)null) { AddLog(set, log.m_subLogPrefab.GetComponent(), depth + 1); } } } static VillageNeeds() { ItemType[] array = new ItemType[4]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); ArmorSlots = (ItemType[])(object)array; Obtainable = new Dictionary>(); Common = new HashSet { "Wood", "Stone", "Flint", "Resin", "LeatherScraps", "DeerHide", "Feathers", "Raspberry", "Mushroom", "GreydwarfEye", "BoneFragments" }; YieldCache = new Dictionary>(); } } internal static class VillageNet { internal enum Action : byte { Found = 1, Rename = 2, Invite = 3, Kick = 4, Leave = 5, SetPerms = 6, Disband = 7, CampRep = 20, CampLosePerson = 21, CampWar = 26, CampBuilt = 27, RaidDone = 22, CampTakeStock = 23, CampSimDays = 24, CampRegen = 25, VillageStats = 8, VillageKnow = 10, VillageLevel = 11, SetBuild = 12, SetPlan = 13, QuestAccept = 30, QuestJoin = 31, QuestDeliver = 32, QuestKill = 33, QuestRescued = 34, QuestClaim = 35, QuestAbandon = 36, TreasuryTake = 40, SetTaxRate = 41, QuestPost = 45 } public static void CampRep(string campId, float delta) { ZPackage obj = NetSync.BeginVillage(Action.CampRep, campId); obj.Write(delta); NetSync.SendVillage(obj); } public static void CampLosePerson(string campId) { NetSync.SendVillage(NetSync.BeginVillage(Action.CampLosePerson, campId)); } public static void CampBuilt(string campId, int stage) { ZPackage obj = NetSync.BeginVillage(Action.CampBuilt, campId); obj.Write(stage); NetSync.SendVillage(obj); } public static void CampWar(string campId, int fighters) { ZPackage obj = NetSync.BeginVillage(Action.CampWar, campId); obj.Write(fighters); NetSync.SendVillage(obj); } public static void RaidDone(string villageId) { NetSync.SendVillage(NetSync.BeginVillage(Action.RaidDone, villageId)); } public static void CampTakeStock(string campId) { NetSync.SendVillage(NetSync.BeginVillage(Action.CampTakeStock, campId)); } public static void CampSimDays(int days) { ZPackage obj = NetSync.BeginVillage(Action.CampSimDays, ""); obj.Write(days); NetSync.SendVillage(obj); } public static void CampRegen() { NetSync.SendVillage(NetSync.BeginVillage(Action.CampRegen, "")); } private static void CampHandle(long sender, long who, Action action, string id, ZPackage pkg, Action reply) { CampInfo.Invalidate(); switch (action) { case Action.CampSimDays: case Action.CampRegen: { if (!GameApi.SenderIsAdmin(sender)) { reply("Living World: only admins can do that."); return; } if (action == Action.CampRegen) { foreach (CampInfo item in new List(CampInfo.All())) { ModData.ServerApply(item.Key, null); } ModData.ServerApply("camps.generated", null); CampInfo.Invalidate(); reply($"Living World: placed {CampSim.Generate()} camp(s)."); return; } int num = Mathf.Clamp(pkg.ReadInt(), 1, 60); foreach (CampInfo item2 in new List(CampInfo.All())) { CampSim.SimulateTo(item2, item2.LastDay + num); } CampInfo.Invalidate(); reply($"Living World: camps lived {num} more day(s)."); return; } case Action.RaidDone: ModData.ServerApply("raid." + id, null); return; } CampInfo campInfo = CampInfo.ById(id); if (campInfo == null) { return; } switch (action) { case Action.CampRep: { float num4 = Mathf.Clamp(pkg.ReadSingle(), -50f, 50f); float num5 = Mathf.Clamp(CampInfo.Rep(id, who) + num4, -100f, 100f); ModData.ServerApply(CampInfo.RepKey(id, who), num5.ToString("0.#", CultureInfo.InvariantCulture)); break; } case Action.CampLosePerson: campInfo.People = Mathf.Max(0, campInfo.People - 1); if (campInfo.People == 0 && campInfo.Hostile && string.IsNullOrEmpty(ModData.Get(ValheimDynasty.Camps.CampWar.RuinKey(campInfo.Id)))) { ModData.ServerApply("vwar." + campInfo.Id, null); ModData.ServerApply(ValheimDynasty.Camps.CampWar.RuinKey(campInfo.Id), CampConfig.RuinDays.Value.ToString()); DynastyPlugin.Log.LogInfo((object)(campInfo.Name + " has fallen.")); } ModData.ServerApply(campInfo.Key, campInfo.Serialize()); break; case Action.CampBuilt: { int num6 = Mathf.Clamp(pkg.ReadInt(), -1, 3); if (num6 > CampTown.BuiltStage(campInfo)) { ModData.ServerApply(CampTown.BuiltKey(campInfo.Id), num6.ToString()); } break; } case Action.CampWar: { if (campInfo.Hostile) { break; } int num2 = Mathf.Clamp(pkg.ReadInt(), 1, 30); campInfo.Hostile = true; campInfo.People = num2; ModData.ServerApply("vwar." + campInfo.Id, who.ToString()); ModData.ServerApply(campInfo.Key, campInfo.Serialize()); foreach (CampInfo item3 in new List(CampInfo.All())) { float num3 = Mathf.Clamp(CampInfo.Rep(item3.Id, who) - ((item3.Id == campInfo.Id) ? 100f : 15f), -100f, 100f); ModData.ServerApply(CampInfo.RepKey(item3.Id, who), num3.ToString("0.#", CultureInfo.InvariantCulture)); } DynastyPlugin.Log.LogInfo((object)$"{campInfo.Name} is at war with player {who} ({num2} fighters)."); break; } case Action.CampTakeStock: campInfo.Food *= 0.5f; campInfo.Wood = 0f; campInfo.Stone = 0f; ModData.ServerApply(campInfo.Key, campInfo.Serialize()); break; } CampInfo.Invalidate(); } public static void Found(string name, Vector3 center, float radius) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) ZPackage obj = NetSync.BeginVillage(Action.Found, ""); obj.Write(name ?? ""); obj.Write(center); obj.Write(radius); obj.Write(VillageInfo.LocalPlayerName); NetSync.SendVillage(obj); } public static void Rename(string id, string name) { ZPackage obj = NetSync.BeginVillage(Action.Rename, id); obj.Write(name ?? ""); NetSync.SendVillage(obj); } public static void Invite(string id, long playerId, string name) { ZPackage obj = NetSync.BeginVillage(Action.Invite, id); obj.Write(playerId); obj.Write(name ?? ""); NetSync.SendVillage(obj); } public static void Kick(string id, long playerId) { ZPackage obj = NetSync.BeginVillage(Action.Kick, id); obj.Write(playerId); NetSync.SendVillage(obj); } public static void Leave(string id) { NetSync.SendVillage(NetSync.BeginVillage(Action.Leave, id)); } public static void SetPerms(string id, VillagePerm perms) { ZPackage obj = NetSync.BeginVillage(Action.SetPerms, id); obj.Write((int)perms); NetSync.SendVillage(obj); } public static void Stats(string id, int freeBeds, int food, int people, float mood) { ZPackage obj = NetSync.BeginVillage(Action.VillageStats, id); obj.Write(freeBeds); obj.Write(food); obj.Write(people); obj.Write(mood); NetSync.SendVillage(obj); } public static void SetPlan(string id, string edits) { ZPackage obj = NetSync.BeginVillage(Action.SetPlan, id); obj.Write(edits ?? ""); NetSync.SendVillage(obj); } public static void SetBuild(string id, bool on) { ZPackage obj = NetSync.BeginVillage(Action.SetBuild, id); obj.Write(on); NetSync.SendVillage(obj); } public static void Disband(string id) { NetSync.SendVillage(NetSync.BeginVillage(Action.Disband, id)); } private static long PlayerIdOf(long sender) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) if (sender == GameApi.LocalSessionId && (Object)(object)Player.m_localPlayer != (Object)null) { return Player.m_localPlayer.GetPlayerID(); } ZNet instance = ZNet.instance; ZNetPeer val = (((Object)(object)instance != (Object)null) ? instance.GetPeer(sender) : null); if (val == null || ZDOMan.instance == null) { return 0L; } ZDO zDO = ZDOMan.instance.GetZDO(val.m_characterID); if (zDO == null) { return 0L; } return zDO.GetLong("playerID", 0L); } internal static void ServerHandle(long sender, Action action, string id, ZPackage pkg, Action reply) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) long num = PlayerIdOf(sender); if (num == 0L) { reply("Living World: you need to be in the world to manage a village."); return; } VillageInfo.Invalidate(); if ((int)action >= 30) { QuestNet.ServerHandle(num, action, id, pkg, reply); return; } if ((int)action >= 20) { CampHandle(sender, num, action, id, pkg, reply); return; } if (action == Action.Found) { string text = pkg.ReadString(); Vector3 val = pkg.ReadVector3(); float num2 = Mathf.Clamp(pkg.ReadSingle(), 20f, 80f); string text2 = pkg.ReadString(); if (VillageInfo.LedBy(num) != null && !VillagesConfig.AllowMultiple.Value) { reply("Living World: you already lead a village."); return; } foreach (VillageInfo item in VillageInfo.All()) { if (Vector3.Distance(item.Center, val) < item.Radius + num2) { reply("Living World: too close to " + item.Name + "."); return; } } foreach (CampInfo item2 in CampInfo.All()) { if (Vector3.Distance(item2.Center, val) < num2 + 30f) { reply("Living World: too close to the camp " + item2.Name + "."); return; } } if (Landmarks.OnTop(val, out var name)) { reply("Living World: too close to " + name + ". Found your village somewhere else."); return; } VillageInfo villageInfo = new VillageInfo { Id = num.ToString("x") + "-" + DateTime.UtcNow.Ticks.ToString("x"), Name = (string.IsNullOrEmpty(text.Trim()) ? (text2 + "'s village") : text), Leader = num, LeaderName = text2, Center = val, Radius = num2 }; villageInfo.Members[num] = text2; Save(villageInfo); DynastyPlugin.Log.LogInfo((object)$"Village founded: {villageInfo.Name} by {text2} at {val}."); reply("Living World: founded " + villageInfo.Name + "."); return; } VillageInfo villageInfo2 = VillageInfo.ById(id); if (villageInfo2 == null) { reply("Living World: that village no longer exists."); return; } switch (action) { case Action.Rename: { string text3 = pkg.ReadString(); if (!villageInfo2.IsLeader(num)) { reply("Living World: only the leader can rename the village."); return; } if (string.IsNullOrEmpty(text3.Trim())) { return; } villageInfo2.Name = text3; Save(villageInfo2); break; } case Action.Invite: { long num9 = pkg.ReadLong(); string text4 = pkg.ReadString(); if (!villageInfo2.Can(num, VillagePerm.Invite)) { reply("Living World: you're not allowed to invite players."); return; } if (num9 == 0L || villageInfo2.IsMember(num9)) { return; } villageInfo2.Members[num9] = text4; Save(villageInfo2); reply("Living World: " + text4 + " joined " + villageInfo2.Name + "."); break; } case Action.Kick: { long num3 = pkg.ReadLong(); if (!villageInfo2.IsLeader(num) || num3 == villageInfo2.Leader) { reply("Living World: only the leader can remove members."); return; } if (villageInfo2.Members.Remove(num3)) { Save(villageInfo2); } break; } case Action.Leave: if (villageInfo2.IsLeader(num)) { reply("Living World: the leader can't leave; disband the village instead."); return; } if (villageInfo2.Members.Remove(num)) { Save(villageInfo2); } break; case Action.SetPerms: { int memberPerms = pkg.ReadInt(); if (!villageInfo2.IsLeader(num)) { reply("Living World: only the leader can change permissions."); return; } villageInfo2.MemberPerms = (VillagePerm)memberPerms; Save(villageInfo2); break; } case Action.VillageLevel: { float num8 = pkg.ReadSingle(); if (villageInfo2.IsMember(num) && string.IsNullOrEmpty(ModData.Get(VillageGround.Key(villageInfo2.Id)))) { ModData.ServerApply(VillageGround.Key(villageInfo2.Id), num8.ToString("0.##", CultureInfo.InvariantCulture)); DynastyPlugin.Log.LogInfo((object)$"{villageInfo2.Name} will be levelled to height {num8:0.0}."); } return; } case Action.SetPlan: { string text5 = pkg.ReadString(); if (!villageInfo2.IsLeader(num)) { reply("Living World: only the leader can change the town plan."); } else { ModData.ServerApply(Blueprints.EditKey(villageInfo2.Id), string.IsNullOrEmpty(text5) ? null : text5); } return; } case Action.SetBuild: { bool flag = pkg.ReadBool(); if (!villageInfo2.IsLeader(num)) { reply("Living World: only the leader can change that."); return; } ModData.ServerApply("vnobuild." + villageInfo2.Id, flag ? null : "1"); DynastyPlugin.Log.LogInfo((object)(villageInfo2.Name + ": villagers " + (flag ? "build" : "don't build") + ".")); return; } case Action.VillageKnow: if (villageInfo2.IsMember(num)) { VillageProgress.ServerMerge(villageInfo2, pkg.ReadString()); } return; case Action.VillageStats: { int num4 = pkg.ReadInt(); int num5 = pkg.ReadInt(); int num6 = pkg.ReadInt(); float num7 = 60f; try { num7 = pkg.ReadSingle(); } catch { } if (villageInfo2.IsMember(num)) { ModData.ServerApply("vstats." + villageInfo2.Id, string.Format("{0}|{1}|{2}|{3}", num4, num5, num6, num7.ToString("0", CultureInfo.InvariantCulture))); } return; } case Action.Disband: if (!villageInfo2.IsLeader(num)) { reply("Living World: only the leader can disband the village."); return; } ModData.ServerApply(villageInfo2.Key, null); DynastyPlugin.Log.LogInfo((object)("Village disbanded: " + villageInfo2.Name + ".")); reply("Living World: " + villageInfo2.Name + " was disbanded."); break; } VillageInfo.Invalidate(); } private static void Save(VillageInfo v) { ModData.ServerApply(v.Key, v.Serialize()); VillageInfo.Invalidate(); } } internal static class VillageProgress { private static readonly FieldInfo KnownField = AccessTools.Field(typeof(Player), "m_knownRecipes"); private static readonly Dictionary>> Cache = new Dictionary>>(); private static float _nextReport; public static readonly string[] BossKeys = new string[7] { "defeated_eikthyr", "defeated_gdking", "defeated_bonemass", "defeated_dragon", "defeated_goblinking", "defeated_queen", "defeated_fader" }; public static readonly string[] BossNames = new string[7] { "Eikthyr", "The Elder", "Bonemass", "Moder", "Yagluth", "The Queen", "Fader" }; public static string KnowKey(string villageId) { return "vknow." + villageId; } public static HashSet Known(string villageId) { string text = ModData.Get(KnowKey(villageId)); if (string.IsNullOrEmpty(text)) { return null; } if (Cache.TryGetValue(villageId, out var value) && (object)value.Key == text) { return value.Value; } HashSet hashSet = new HashSet(text.Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries)); Cache[villageId] = new KeyValuePair>(text, hashSet); return hashSet; } public static bool Knows(VillageInfo village, string name) { if (village == null || string.IsNullOrEmpty(name) || !VillagesConfig.FollowProgression.Value) { return true; } return Known(village.Id)?.Contains(name) ?? true; } public static void Tick() { //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !ModData.IsLoaded || Time.time < _nextReport) { return; } _nextReport = Time.time + 15f; HashSet hashSet = ((KnownField != null) ? (KnownField.GetValue(localPlayer) as HashSet) : null); if (hashSet == null || hashSet.Count == 0) { return; } long playerID = localPlayer.GetPlayerID(); foreach (VillageInfo v in new List(VillageInfo.All())) { if (!v.IsMember(playerID)) { continue; } Vector3 val = v.Center - ((Component)localPlayer).transform.position; if (((Vector3)(ref val)).sqrMagnitude < 14400f) { Safe.Run("VillageNeeds.Learn", delegate { VillageNeeds.Learn(v); }); } HashSet hashSet2 = Known(v.Id); List list = new List(); foreach (string item in hashSet) { if (hashSet2 == null || !hashSet2.Contains(item)) { list.Add(item); } } if (list.Count == 0) { continue; } List list2 = new List(); int num = 0; foreach (string item2 in list) { if (num + item2.Length > 6000) { Send(v.Id, list2); list2 = new List(); num = 0; } list2.Add(item2); num += item2.Length + 1; } if (list2.Count > 0) { Send(v.Id, list2); } } } public static void Teach(VillageInfo v, List names) { if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { ServerMerge(v, string.Join("\n", names.ToArray())); } else { Send(v.Id, names); } } private static void Send(string villageId, List names) { ZPackage obj = NetSync.BeginVillage(VillageNet.Action.VillageKnow, villageId); obj.Write(string.Join("\n", names.ToArray())); NetSync.SendVillage(obj); } public static void ServerMerge(VillageInfo v, string names) { HashSet hashSet = Known(v.Id); hashSet = ((hashSet != null) ? new HashSet(hashSet) : new HashSet()); int count = hashSet.Count; string[] array = names.Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { if (text.Length < 80) { hashSet.Add(text); } } if (hashSet.Count != count) { string[] array2 = new string[hashSet.Count]; hashSet.CopyTo(array2); Array.Sort(array2, (IComparer?)StringComparer.Ordinal); ModData.ServerApply(KnowKey(v.Id), string.Join("\n", array2)); DynastyPlugin.Log.LogInfo((object)$"{v.Name} learned {hashSet.Count - count} new thing(s) from its members ({hashSet.Count} known)."); } } public static bool Has(string key) { if ((Object)(object)ZoneSystem.instance != (Object)null) { return ZoneSystem.instance.GetGlobalKey(key); } return false; } public static int BossesDown() { int num = 0; string[] bossKeys = BossKeys; for (int i = 0; i < bossKeys.Length; i++) { if (Has(bossKeys[i])) { num++; } } return num; } public static int MaxVillagers() { if (!VillagesConfig.FollowProgression.Value) { return 999; } return VillagesConfig.BaseVillagers.Value + VillagesConfig.VillagersPerBoss.Value * BossesDown(); } public static string NextBoss() { for (int i = 0; i < BossKeys.Length; i++) { if (!Has(BossKeys[i])) { return BossNames[i]; } } return null; } } internal static class VillagesConfig { public static ConfigEntry ScreenKey; public static ConfigEntry Radius; public static ConfigEntry AllowMultiple; public static ConfigEntry FollowProgression; public static ConfigEntry LearnOnTheirOwn; public static ConfigEntry BaseVillagers; public static ConfigEntry VillagersPerBoss; public static void Bind(ConfigFile config) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Expected O, but got Unknown //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Expected O, but got Unknown //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Expected O, but got Unknown //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Expected O, but got Unknown ScreenKey = config.Bind("1 - Client", "VillageScreenKey", (KeyCode)288, "Opens the village screen while you're in a village."); Radius = config.Bind("11 - Villages", "Radius", 45f, new ConfigDescription("Size of a village founded at a Village Totem, in meters.", (AcceptableValueBase)(object)new AcceptableValueRange(20f, 80f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); AllowMultiple = config.Bind("11 - Villages", "AllowMultiplePerPlayer", false, new ConfigDescription("Let one player lead more than one village.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); FollowProgression = config.Bind("11 - Villages", "FollowProgression", true, new ConfigDescription("Villagers only craft and build what the village's players have learned, and villages grow as bosses fall.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); LearnOnTheirOwn = config.Bind("11 - Villages", "LearnOnTheirOwn", true, new ConfigDescription("Villages also learn recipes and pieces from the materials in their own chests (like a player discovering materials), so they move forward without you. Boss-gated materials still need the boss.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); BaseVillagers = config.Bind("11 - Villages", "BaseVillagers", 4, new ConfigDescription("How many villagers a village can house before any boss is beaten.", (AcceptableValueBase)(object)new AcceptableValueRange(1, 50), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); VillagersPerBoss = config.Bind("11 - Villages", "VillagersPerBoss", 3, new ConfigDescription("More room for each boss beaten in the world.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 20), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } } internal static class VillageScreen { private sealed class StockEntry { public string Name; public int Count; public bool Food; } private static string _villageId; private static int _tab; private static Vector2 _scroll; private static Rect _rect = new Rect(0f, 0f, 860f, 520f); private static string _renameText; private static float _disbandArmed; private static float _nextStats; private static float _nextLevelCount; private static string _levelText; private static GUIStyle _label; private static GUIStyle _small; private static GUIStyle _header; private static GUIStyle _row; private static GUIStyle _window; private static GUIStyle _rowBg; private static float _nextYours; private static string _yours; private static float _stockTime; private static Dictionary _stock = new Dictionary(); private static readonly VillagePerm[] PermFlags = new VillagePerm[5] { VillagePerm.Jobs, VillagePerm.Homes, VillagePerm.Invite, VillagePerm.Recruit, VillagePerm.Storage }; private static readonly string[] PermLabels = new string[5] { "Change jobs", "Assign beds", "Invite players", "Recruit villagers", "Use village storage" }; public static bool IsOpen => _villageId != null; public static bool BuildingsTabOpen { get { if (IsOpen) { return _tab == 3; } return false; } } private static Texture2D Solid(Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return UiTex.Solid(c); } public static void Open(string villageId) { _villageId = villageId; _renameText = null; ((Rect)(ref _rect)).x = ((float)Screen.width - ((Rect)(ref _rect)).width) / 2f; ((Rect)(ref _rect)).y = ((float)Screen.height - ((Rect)(ref _rect)).height) / 2f; } public static void Close() { if (_villageId != null) { AfterWindow(); } _villageId = null; } public static void AfterWindow() { PlayerController.SetTakeInputDelay(0.35f); } public static void Tick() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null) { _villageId = null; return; } if (Input.GetKeyDown(VillagesConfig.ScreenKey.Value) && !Console.IsVisible() && ((Object)(object)Chat.instance == (Object)null || !Chat.instance.HasFocus())) { if (IsOpen) { Close(); } else { VillageInfo villageInfo = VillageInfo.At(((Component)Player.m_localPlayer).transform.position); if (villageInfo != null) { Open(villageInfo.Id); } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "You're not in a village. Build a Village Totem to found one.", 0, (Sprite)null, false); } } } if (IsOpen && VillageInfo.ById(_villageId) == null) { Close(); } if (Time.time > _nextStats) { _nextStats = Time.time + 30f; VillageInfo villageInfo2 = VillageInfo.At(((Component)Player.m_localPlayer).transform.position); if (villageInfo2 != null && villageInfo2.IsMember(VillageInfo.LocalPlayerId)) { VillageNet.Stats(villageInfo2.Id, Wanderer.FreeBeds(villageInfo2), Wanderer.FoodIn(villageInfo2), Wanderer.VillagersIn(villageInfo2), Mood(villageInfo2)); } } } private static float Mood(VillageInfo v) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) float num = 0f; int num2 = 0; foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item != (Object)null && !((Character)item).IsDead() && string.IsNullOrEmpty(item.CampId) && !item.IsWanderer && v.Contains(item.Home)) { num += item.Happiness; num2++; } } if (num2 <= 0) { return 60f; } return num / (float)num2; } public static void Apply(Harmony harmony) { Safe.Run("VillageScreen.Patch", delegate { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(VillageScreen), "TakeInput_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo methodInfo2 = AccessTools.Method(typeof(PlayerController), "TakeInput", (Type[])null, (Type[])null); if (methodInfo2 != null) { harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(VillageScreen), "TakeInput_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { DynastyPlugin.Log.LogWarning((object)"PlayerController.TakeInput not found: clicks in menus may swing your weapon."); } MethodInfo methodInfo3 = AccessTools.Method(typeof(Menu), "Update", (Type[])null, (Type[])null); if (methodInfo3 != null) { harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(VillageScreen), "MenuUpdate_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo methodInfo4 = AccessTools.Method(typeof(GameCamera), "UpdateMouseCapture", (Type[])null, (Type[])null); if (methodInfo4 != null) { harmony.Patch((MethodBase)methodInfo4, new HarmonyMethod(typeof(VillageScreen), "MouseCapture_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } }); } private static void TakeInput_Postfix(ref bool __result) { if (IsOpen || TalkScreen.IsOpen || QuestLog.IsOpen || GuideScreen.IsOpen) { __result = false; } } private static bool MenuUpdate_Prefix() { if (!IsOpen && !TalkScreen.IsOpen && !QuestLog.IsOpen && !GuideScreen.IsOpen) { return true; } if (Input.GetKeyDown((KeyCode)27)) { if (GuideScreen.IsOpen) { GuideScreen.Close(); } else if (QuestLog.IsOpen) { QuestLog.Close(); } else if (TalkScreen.IsOpen) { TalkScreen.Close(); } else { Close(); } } return false; } private static bool MouseCapture_Prefix() { if (!IsOpen && !TalkScreen.IsOpen && !QuestLog.IsOpen && !GuideScreen.IsOpen) { return true; } Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; return false; } public static void Draw() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if (!IsOpen) { return; } VillageInfo v = VillageInfo.ById(_villageId); if (v != null) { Styles(); Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; _rect = GUI.Window(32026, _rect, (WindowFunction)delegate { Window(v); }, "", _window); } } private static void Styles() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown //IL_0100: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Expected O, but got Unknown //IL_017d: Expected O, but got Unknown //IL_019b: Unknown result type (might be due to invalid IL or missing references) if (_label == null || UiTex.Lost(_window)) { GUIStyle val = new GUIStyle(GUI.skin.label) { fontSize = 15 }; val.normal.textColor = new Color(0.95f, 0.9f, 0.8f); _label = val; GUIStyle val2 = new GUIStyle(_label) { fontSize = 13 }; val2.normal.textColor = new Color(0.78f, 0.74f, 0.66f); _small = val2; GUIStyle val3 = new GUIStyle(_label) { fontSize = 22, fontStyle = (FontStyle)1 }; val3.normal.textColor = new Color(1f, 0.85f, 0.55f); _header = val3; _row = new GUIStyle(_label) { fontSize = 14 }; _window = new GUIStyle(GUI.skin.window) { padding = new RectOffset(14, 14, 12, 12) }; _window.normal.background = Solid(new Color(0.11f, 0.09f, 0.07f, 0.98f)); _window.onNormal.background = _window.normal.background; _rowBg = new GUIStyle(GUI.skin.box) { margin = new RectOffset(0, 0, 1, 1), padding = new RectOffset(4, 4, 2, 2) }; _rowBg.normal.background = Solid(new Color(1f, 1f, 1f, 0.05f)); } } private static List Villagers(VillageInfo v) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) List list = new List(); foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item != (Object)null && !((Character)item).IsDead() && v.Contains(item.Home)) { list.Add(item); } } list.Sort((VillagerCharacter a, VillagerCharacter b) => string.CompareOrdinal(a.VillagerName, b.VillagerName)); return list; } private static void Window(VillageInfo v) { //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0617: Unknown result type (might be due to invalid IL or missing references) //IL_0621: Unknown result type (might be due to invalid IL or missing references) //IL_0626: Unknown result type (might be due to invalid IL or missing references) //IL_067d: Unknown result type (might be due to invalid IL or missing references) long localPlayerId = VillageInfo.LocalPlayerId; List list = Villagers(v); GUILayout.BeginHorizontal(Array.Empty()); if (v.IsLeader(localPlayerId)) { if (_renameText == null) { _renameText = v.Name; } _renameText = GUILayout.TextField(_renameText, 40, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(300f), GUILayout.Height(30f) }); if (_renameText != v.Name && GUILayout.Button("Rename", (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(80f), GUILayout.Height(30f) })) { VillageNet.Rename(v.Id, _renameText); } } else { GUILayout.Label(v.Name, _header, Array.Empty()); } GUILayout.FlexibleSpace(); GUI.enabled = v.Can(localPlayerId, VillagePerm.Homes); if (GUILayout.Button("Guide", (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(70f), GUILayout.Height(30f) })) { GuideScreen.Open(2); } if (GUILayout.Button("Tidy up camp", (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(120f), GUILayout.Height(30f) })) { string text = VillageLayout.Tidy(v.Center, v.Radius); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false); } } GUI.enabled = true; if (GUILayout.Button("Close (" + ((object)VillagesConfig.ScreenKey.Value/*cast due to .constrained prefix*/).ToString() + ")", (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(110f), GUILayout.Height(30f) })) { Close(); } GUILayout.EndHorizontal(); Dictionary dictionary = Stock(v); int num = 0; foreach (KeyValuePair item in dictionary) { if (item.Value.Food) { num += item.Value.Count; } } Stock(v).TryGetValue("$item_wood", out var value); int num2 = value?.Count ?? 0; int count = VillagerPlaces.BedsNear(v.Center, v.Radius).Count; bool flag = (Object)(object)VillagerPlaces.NearestBurningFire(v.Center, v.Radius) != (Object)null; float num3 = 0f; foreach (VillagerCharacter item2 in list) { num3 += item2.Happiness; } if (list.Count > 0) { num3 /= (float)list.Count; } string text2 = ((list.Count > 0) ? ((float)num / (float)list.Count).ToString("0.#") : "-"); GUILayout.Label($"Leader {v.LeaderName} · {v.Members.Count} member(s) · {list.Count} villager(s) · {count} bed(s) · happiness {num3:0}%", _small, Array.Empty()); GUILayout.Label(string.Format("Food in store: {0} ({1} days) · Firewood: {2} · Fire: {3}", num, text2, num2, flag ? "burning" : "out"), _small, Array.Empty()); if (QuestConfig.Enable.Value) { Treasury(v, localPlayerId); } if (VillagersConfig.LevelGround.Value && Time.time > _nextLevelCount) { _nextLevelCount = Time.time + 5f; VillageGround.Progress(v, out var level, out var todo); _levelText = ((todo == 0) ? "Ground: the town is level" : $"Ground: {level} of {level + todo} squares level (villagers level the rest with a hoe, centre first)"); } bool buildsOn = v.BuildsOn; if (VillagersConfig.LevelGround.Value && _levelText != null && buildsOn) { GUILayout.Label(_levelText, _small, Array.Empty()); } if (v.IsLeader(localPlayerId)) { bool flag2 = GUILayout.Toggle(buildsOn, buildsOn ? " Villagers build the town (buildings, levelling, clearing)" : " Villagers build the town: OFF (you build; they just do their jobs)", Array.Empty()); if (flag2 != buildsOn) { VillageNet.SetBuild(v.Id, flag2); } } else if (!buildsOn) { GUILayout.Label("Villagers don't build here: the leader builds this town", _small, Array.Empty()); } if (Time.time > _nextYours) { _nextYours = Time.time + 3f; _yours = YoursLine(v); } if (!string.IsNullOrEmpty(_yours)) { GUILayout.Label(_yours, _small, Array.Empty()); } if (VillagersConfig.SmartTowns.Value) { string text3 = TownManager.SummaryOf(v); if (!string.IsNullOrEmpty(text3)) { GUILayout.Label("Today: " + text3, _small, Array.Empty()); } } if (VillagesConfig.FollowProgression.Value) { int num4 = VillageProgress.MaxVillagers(); string text4 = VillageProgress.NextBoss(); HashSet hashSet = VillageProgress.Known(v.Id); GUILayout.Label(string.Format("Room for {0} villagers ({1} now){2} · villagers can make what your members have learned ({3})", num4, list.Count, (text4 != null) ? $" · beat {text4} for {VillagesConfig.VillagersPerBoss.Value} more" : "", (hashSet != null) ? (hashSet.Count + " recipes and pieces") : "waiting for a member to report"), _small, Array.Empty()); } GUILayout.Space(4f); _tab = GUILayout.Toolbar(_tab, new string[4] { "Villagers", "Storage", "Members", "Buildings" }, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }); GUILayout.Space(4f); _scroll = GUILayout.BeginScrollView(_scroll, Array.Empty()); if (_tab == 0) { VillagersTab(v, list, localPlayerId); } else if (_tab == 1) { StorageTab(dictionary); } else if (_tab == 2) { MembersTab(v, localPlayerId); } else { BuildingsTab(v, localPlayerId); } GUILayout.EndScrollView(); GUI.DragWindow(new Rect(0f, 0f, 10000f, 40f)); } private static string YoursLine(VillageInfo v) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) int num = Blueprints.PlayerBeds(v); int num2 = 0; foreach (Container item in Village.Chests(v.Center, v.Radius)) { Piece component = ((Component)item).GetComponent(); if ((Object)(object)component != (Object)null && component.GetCreator() != 0L) { num2++; } } bool num3 = Blueprints.PlayerWorkbench(v.Center, v.Radius); List list = new List(); if (num > 0) { list.Add((num == 1) ? "1 bed" : (num + " beds")); } if (num3) { list.Add("a workbench"); } if (num2 > 0) { list.Add((num2 == 1) ? "1 chest" : (num2 + " chests")); } if (list.Count == 0) { return null; } return "Built by you: " + string.Join(" · ", list.ToArray()) + " (the villagers use these, and build around your buildings)"; } private static void Treasury(VillageInfo v, long me) { int num = QuestNet.TreasuryOf(v.Id); int num2 = QuestNet.TaxRateOf(v.Id); int num3 = num2 switch { 1 => QuestConfig.TaxFair.Value, 0 => 0, _ => QuestConfig.TaxHeavy.Value, }; GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label($"Treasury: {num} coins · taxes paid each season ({num3} per villager, less if they're unhappy) · rate:", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }); GUI.enabled = v.IsLeader(me); int num4 = GUILayout.Toolbar(num2, QuestNet.RateNames, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(200f), GUILayout.Height(22f) }); if (num4 != num2) { QuestNet.SetTaxRate(v.Id, num4); } GUI.enabled = v.Can(me, VillagePerm.Storage) && num > 0; if (GUILayout.Button("Take coins", (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(100f), GUILayout.Height(22f) })) { QuestNet.TakeTreasury(v.Id, num); } GUI.enabled = true; GUILayout.EndHorizontal(); switch (num2) { case 2: GUILayout.Label("Heavy taxes make villagers unhappy.", _small, Array.Empty()); break; case 0: GUILayout.Label("No taxes: villagers are a little happier.", _small, Array.Empty()); break; } } private static void VillagersTab(VillageInfo v, List people, long me) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) if (people.Count == 0) { GUILayout.Label("No villagers live here yet.", _label, Array.Empty()); return; } bool flag = v.Can(me, VillagePerm.Jobs); bool flag2 = v.Can(me, VillagePerm.Homes); List list = VillagerPlaces.BedsNear(v.Center, v.Radius); GUILayout.BeginHorizontal(Array.Empty()); Col("Name", 120f); Col("Job", 170f); Col("Home", 140f); Col("Happy", 60f); Col("Food", 50f); Col("Rest", 50f); Col("Health", 60f); Col("Doing", 200f); GUILayout.EndHorizontal(); foreach (VillagerCharacter person in people) { GUILayout.BeginHorizontal(_rowBg, Array.Empty()); GUILayout.Label(person.VillagerName, _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) }); GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(170f) }); GUI.enabled = flag; if (GUILayout.Button("<", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) })) { person.SetJob(Step(person.Job, -1)); } GUILayout.Label(person.Job.ToString(), _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) }); if (GUILayout.Button(">", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) })) { person.SetJob(Step(person.Job, 1)); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }); int num = BedIndex(person, list); GUILayout.Label((num >= 0) ? ("Bed " + (num + 1)) : "none", _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }); GUI.enabled = flag2 && list.Count > 0; if (GUILayout.Button("Next bed", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(74f) })) { AssignNextBed(person, list, num); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.Label(Pct(person.Happiness), _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }); GUILayout.Label(Pct(person.Hunger), _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }); GUILayout.Label(Pct(person.Energy), _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }); GUILayout.Label(Pct(person.HealthPercent), _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }); GUILayout.Label(person.DescribeActivity(), _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) }); GUILayout.EndHorizontal(); } if (!flag) { GUILayout.Label("The leader hasn't given members permission to change jobs.", _small, Array.Empty()); } } private static string Pct(float f) { string arg = ((f >= 60f) ? "#c8e6a0" : ((f >= 30f) ? "#f0d080" : "#ff8866")); return $"{f:0}%"; } private static void Col(string t, float w) { GUILayout.Label("" + t + "", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(w) }); } private static VillagerJob Step(VillagerJob j, int d) { int length = Enum.GetValues(typeof(VillagerJob)).Length; return (VillagerJob)(((int)(j + d) % length + length) % length); } private static int BedIndex(VillagerCharacter c, List beds) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) ZNetView component = ((Component)c).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return -1; } ZDOID val = VillagerCharacter.BedId(component.GetZDO()); for (int i = 0; i < beds.Count; i++) { ZNetView val2 = (((Object)(object)beds[i] != (Object)null) ? ((Component)beds[i]).GetComponent() : null); if ((Object)(object)val2 != (Object)null && val2.IsValid() && val2.GetZDO().m_uid == val) { return i; } } return -1; } private static void AssignNextBed(VillagerCharacter c, List beds, int current) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) int index = (current + 1) % beds.Count; ZNetView component = ((Component)beds[index]).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return; } ZDOID uid = component.GetZDO().m_uid; foreach (VillagerCharacter item in VillagerCharacter.All) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item == (Object)(object)c)) { ZNetView component2 = ((Component)item).GetComponent(); if ((Object)(object)component2 != (Object)null && component2.IsValid() && VillagerCharacter.BedId(component2.GetZDO()) == uid) { component2.ClaimOwnership(); VillagerCharacter.SetBed(component2.GetZDO(), null); } } } ZNetView component3 = ((Component)c).GetComponent(); component3.ClaimOwnership(); VillagerCharacter.SetBed(component3.GetZDO(), beds[index]); } private static Dictionary Stock(VillageInfo v) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (Time.time - _stockTime < 1f) { return _stock; } _stockTime = Time.time; Dictionary dictionary = new Dictionary(); foreach (Container item in Village.Chests(v.Center, v.Radius)) { foreach (ItemData allItem in item.GetInventory().GetAllItems()) { if (!dictionary.TryGetValue(allItem.m_shared.m_name, out var value)) { value = new StockEntry { Name = ((Localization.instance != null) ? Localization.instance.Localize(allItem.m_shared.m_name) : allItem.m_shared.m_name), Food = Village.Edible(allItem) }; dictionary[allItem.m_shared.m_name] = value; } value.Count += allItem.m_stack; } } _stock = dictionary; return dictionary; } private static void BuildingsTab(VillageInfo v, long me) { bool flag = v.IsLeader(me); GUILayout.Label("Hold your hammer in town to see the plan's outlines on the ground." + (flag ? " Buildings that haven't been started can be moved, turned or removed." : ""), _small, Array.Empty()); List list = TownPlanView.Entries(v); if (list.Count == 0) { GUILayout.Label("No buildings planned yet (the town needs its ground height first: a villager will work it out).", _small, Array.Empty()); return; } foreach (TownPlanView.Entry item in list) { GUILayout.BeginHorizontal(Array.Empty()); string text = (item.Cancelled ? "" : $"{item.Built}/{item.Total} · "); GUILayout.Label("" + item.Name + " " + text + item.State, _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(400f) }); GUILayout.FlexibleSpace(); if (flag) { if (item.Cancelled) { if (GUILayout.Button("Put back", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Cancel = false; }); } } else if (!item.Started) { if (GUILayout.Button("◄", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Dx -= 2f; }); } if (GUILayout.Button("►", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Dx += 2f; }); } if (GUILayout.Button("▲", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Dz += 2f; }); } if (GUILayout.Button("▼", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Dz -= 2f; }); } if (GUILayout.Button("Turn", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Rot = (x.Rot + 90f) % 360f; }); } if (GUILayout.Button("Reset", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Dx = 0f; x.Dz = 0f; x.Rot = 0f; }); } if (GUILayout.Button("Remove", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(66f) })) { TownPlanView.Change(v, item.Key, delegate(Blueprints.PlanEdit x) { x.Cancel = true; }); } } else { GUILayout.Label("started", _small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }); } } GUILayout.EndHorizontal(); } GUILayout.Space(6f); string text2 = YoursLine(v); GUILayout.Label(string.IsNullOrEmpty(text2) ? "Your own buildings: none in town yet. Beds, a workbench and chests you build count for the town, and villagers build around them." : text2, _small, Array.Empty()); } private static void StorageTab(Dictionary stock) { if (stock.Count == 0) { GUILayout.Label("The village chests are empty.", _label, Array.Empty()); return; } List list = new List(stock.Values); list.Sort((StockEntry a, StockEntry b) => b.Count.CompareTo(a.Count)); int num = 0; GUILayout.BeginHorizontal(Array.Empty()); foreach (StockEntry item in list) { GUILayout.Label((item.Food ? "" : "") + item.Name + (item.Food ? "" : "") + " " + item.Count + "", _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) }); if (++num % 4 == 0) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); } } GUILayout.EndHorizontal(); GUILayout.Label("Green = food. Villagers eat from these chests every evening.", _small, Array.Empty()); } private static void MembersTab(VillageInfo v, long me) { //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) bool flag = v.IsLeader(me); foreach (KeyValuePair member in v.Members) { GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label(member.Value + ((member.Key == v.Leader) ? " (leader)" : ""), _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) }); if (flag && member.Key != v.Leader && GUILayout.Button("Remove", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) })) { VillageNet.Kick(v.Id, member.Key); } GUILayout.EndHorizontal(); } GUILayout.Space(8f); if (v.Can(me, VillagePerm.Invite)) { GUILayout.Label("Invite players standing near you:", _small, Array.Empty()); bool flag2 = false; foreach (Player allPlayer in Player.GetAllPlayers()) { if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)allPlayer == (Object)(object)Player.m_localPlayer) && !v.IsMember(allPlayer.GetPlayerID()) && !(Vector3.Distance(((Component)allPlayer).transform.position, ((Component)Player.m_localPlayer).transform.position) > 30f)) { flag2 = true; if (GUILayout.Button("Invite " + allPlayer.GetPlayerName(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(220f) })) { VillageNet.Invite(v.Id, allPlayer.GetPlayerID(), allPlayer.GetPlayerName()); } } } if (!flag2) { GUILayout.Label(" (nobody nearby)", _small, Array.Empty()); } } GUILayout.Space(8f); GUILayout.Label("What members may do:", _small, Array.Empty()); GUI.enabled = flag; VillagePerm memberPerms = v.MemberPerms; for (int i = 0; i < PermFlags.Length; i++) { bool flag3 = (memberPerms & PermFlags[i]) != 0; bool flag4 = GUILayout.Toggle(flag3, " " + PermLabels[i], Array.Empty()); if (flag4 != flag3) { VillageNet.SetPerms(v.Id, flag4 ? (memberPerms | PermFlags[i]) : (memberPerms & ~PermFlags[i])); } } GUI.enabled = true; GUILayout.Space(10f); if (flag) { bool flag5 = Time.time - _disbandArmed < 4f; if (GUILayout.Button(flag5 ? "Click again to disband" : "Disband village", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) })) { if (flag5) { VillageNet.Disband(v.Id); Close(); } else { _disbandArmed = Time.time; } } } else if (v.IsMember(me) && GUILayout.Button("Leave village", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) })) { VillageNet.Leave(v.Id); Close(); } } } internal static class VillageTotemPiece { public const string Name = "VD_VillageTotem"; public static void Register() { PrefabManager.OnVanillaPrefabsAvailable += Create; } private static void Create() { PrefabManager.OnVanillaPrefabsAvailable -= Create; Safe.Run("VillageTotem.Build", delegate { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Expected O, but got Unknown string text = (((Object)(object)PrefabManager.Instance.GetPrefab("piece_banner01") != (Object)null) ? "piece_banner01" : "sign"); GameObject val = PrefabManager.Instance.CreateClonedPrefab("VD_VillageTotem", text); if ((Object)(object)val == (Object)null) { DynastyPlugin.Log.LogError((object)"Villages: couldn't build the Village Totem piece."); } else { Component[] array = (from c in val.GetComponents() where (Object)(object)c != (Object)null && ((object)c).GetType().Name == "Sign" select c).ToArray(); for (int num = 0; num < array.Length; num++) { Object.DestroyImmediate((Object)(object)array[num]); } val.AddComponent(); PieceConfig val2 = new PieceConfig(); val2.Name = "Village Totem"; val2.Description = "Found a village here. Villagers whose home is nearby join it; open the village screen to manage them."; val2.PieceTable = "Hammer"; val2.Category = "Misc"; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2] { new RequirementConfig("Wood", 10, 0, true), new RequirementConfig("Resin", 4, 0, true) }; PieceConfig val3 = val2; PieceManager.Instance.AddPiece(new CustomPiece(val, false, val3)); DynastyPlugin.Log.LogInfo((object)("Village Totem piece ready (from " + text + ").")); } }); } } public class VillageTotem : MonoBehaviour, Hoverable, Interactable { private ZNetView _nview; private Piece _piece; private float _foundTried; private float _waitUntil = -1f; private void Awake() { _nview = ((Component)this).GetComponent(); _piece = ((Component)this).GetComponent(); } private void Update() { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_nview == (Object)null || !_nview.IsValid() || (Object)(object)_piece == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || _nview.GetZDO().GetBool("vdyn_founded", false) || !string.IsNullOrEmpty(_nview.GetZDO().GetString("vdyn_camp", ""))) { return; } Player localPlayer = Player.m_localPlayer; if (_piece.GetCreator() != localPlayer.GetPlayerID()) { return; } if (_waitUntil > 0f) { if (VillageInfo.At(((Component)this).transform.position) != null) { Founded(); } else if (!(Time.time < _waitUntil)) { TakeDown("Couldn't found a village here (the reason is shown above)."); } } else { if (Time.time - _foundTried < 2f) { return; } _foundTried = Time.time; if (VillageInfo.At(((Component)this).transform.position) != null) { Founded(); return; } VillageInfo villageInfo = VillageInfo.LedBy(localPlayer.GetPlayerID()); if (villageInfo != null && !VillagesConfig.AllowMultiple.Value) { TakeDown("You already lead " + villageInfo.Name + ". One village per player on this server: build totems inside " + villageInfo.Name + ", or disband it first (F7, Members tab)."); return; } float value = VillagesConfig.Radius.Value; foreach (VillageInfo item in VillageInfo.All()) { if (Vector3.Distance(item.Center, ((Component)this).transform.position) < item.Radius + value) { TakeDown("Too close to " + item.Name + "."); return; } } foreach (CampInfo item2 in CampInfo.All()) { if (Vector3.Distance(item2.Center, ((Component)this).transform.position) < value + 30f) { TakeDown("Too close to the camp " + item2.Name + ". Camps can't be claimed; win their people over by talking and trading."); return; } } VillageNet.Found("", ((Component)this).transform.position, value); _waitUntil = Time.time + 8f; } } private void Founded() { _nview.ClaimOwnership(); _nview.GetZDO().Set("vdyn_founded", true); _waitUntil = -1f; } private void TakeDown(string why) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; ((Character)localPlayer).Message((MessageType)2, why, 0, (Sprite)null, false); DynastyPlugin.Log.LogInfo((object)("Village Totem taken down: " + why)); Requirement[] resources = _piece.m_resources; foreach (Requirement val in resources) { if (val != null && !((Object)(object)val.m_resItem == (Object)null) && val.m_amount > 0) { Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory.CanAddItem(((Component)val.m_resItem).gameObject, val.m_amount)) { inventory.AddItem(((Component)val.m_resItem).gameObject, val.m_amount); } else { Object.Instantiate(((Component)val.m_resItem).gameObject, ((Component)this).transform.position + Vector3.up, Quaternion.identity).GetComponent().SetStack(val.m_amount); } } } _nview.ClaimOwnership(); ZNetScene.instance.Destroy(((Component)this).gameObject); } public string GetHoverName() { return "Village Totem"; } public float GetHoverOffset() { return 0f; } public string GetHoverText() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) string text = CampMaterializer.CampOf((Component)(object)this); if (!string.IsNullOrEmpty(text)) { CampInfo campInfo = CampInfo.ById(text); if (campInfo == null) { return "Camp"; } return $"{campInfo.Title}\n{campInfo.People} people"; } VillageInfo villageInfo = VillageInfo.At(((Component)this).transform.position); string obj = ((villageInfo != null) ? villageInfo.Name : "Village Totem"); string text2 = ((villageInfo != null) ? $"Leader: {villageInfo.LeaderName} · {villageInfo.Members.Count} member(s)" : "No village here"); string text3 = obj + "\n" + text2 + "\n[$KEY_Use] Open village screen"; if (Localization.instance == null) { return text3; } return Localization.instance.Localize(text3); } public bool Interact(Humanoid user, bool hold, bool alt) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (hold || !(user is Player)) { return false; } string text = CampMaterializer.CampOf((Component)(object)this); if (!string.IsNullOrEmpty(text)) { CampInfo campInfo = CampInfo.ById(text); if (campInfo != null) { ((Character)(Player)user).Message((MessageType)2, campInfo.Hostile ? (campInfo.Name + " has been taken by bandits.") : $"{campInfo.Title}: {campInfo.People} people. Talk to them to earn their trust.", 0, (Sprite)null, false); } return true; } VillageInfo villageInfo = VillageInfo.At(((Component)this).transform.position); if (villageInfo == null) { VillageNet.Found("", ((Component)this).transform.position, VillagesConfig.Radius.Value); return true; } VillageScreen.Open(villageInfo.Id); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } } } namespace ValheimDynasty.Villagers { internal static class Farming { internal sealed class Crop { public GameObject Piece; public Plant Plant; public Requirement[] Cost; public HashSet Yields = new HashSet(); public bool IsTree; public string Name; } private static List _crops; private static GameObject _cultivate; private static string _cultivatorToken; public static List Crops { get { Load(); return _crops; } } public static GameObject CultivatePiece { get { Load(); return _cultivate; } } public static string CultivatorToken { get { Load(); return _cultivatorToken; } } private static void Load() { if (_crops != null || (Object)(object)ObjectDB.instance == (Object)null) { return; } _crops = new List(); GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Cultivator"); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent() : null); if ((Object)(object)val == (Object)null || (Object)(object)val.m_itemData.m_shared.m_buildPieces == (Object)null) { DynastyPlugin.Log.LogWarning((object)"Farming: couldn't read the Cultivator's build menu; villagers won't farm."); return; } _cultivatorToken = val.m_itemData.m_shared.m_name; foreach (GameObject piece in val.m_itemData.m_shared.m_buildPieces.m_pieces) { if ((Object)(object)piece == (Object)null) { continue; } TerrainOp component = piece.GetComponent(); if ((Object)(object)component != (Object)null && component.m_settings != null && ((object)Unsafe.As(ref component.m_settings.m_paintType)/*cast due to .constrained prefix*/).ToString() == "Cultivate" && (Object)(object)_cultivate == (Object)null) { _cultivate = piece; continue; } Plant component2 = piece.GetComponent(); Piece component3 = piece.GetComponent(); if ((Object)(object)component2 == (Object)null || (Object)(object)component3 == (Object)null || component2.m_grownPrefabs == null) { continue; } Crop crop = new Crop { Piece = piece, Plant = component2, Cost = component3.m_resources, Name = component3.m_name }; GameObject[] grownPrefabs = component2.m_grownPrefabs; foreach (GameObject val2 in grownPrefabs) { if (!((Object)(object)val2 == (Object)null)) { if ((Object)(object)val2.GetComponent() != (Object)null) { crop.IsTree = true; } Pickable component4 = val2.GetComponent(); if ((Object)(object)component4 != (Object)null && (Object)(object)component4.m_itemPrefab != (Object)null) { crop.Yields.Add(((Object)component4.m_itemPrefab).name); } } } _crops.Add(crop); } DynastyPlugin.Log.LogInfo((object)string.Format("Farming: {0} plantable crops and saplings, cultivate tool {1}.", _crops.Count, ((Object)(object)_cultivate != (Object)null) ? ((Object)_cultivate).name : "missing")); } public static bool IsCrop(Pickable p) { if ((Object)(object)p == (Object)null || (Object)(object)p.m_itemPrefab == (Object)null || (Object)(object)((Component)p).GetComponent() != (Object)null) { return false; } foreach (Crop crop in Crops) { if (!crop.IsTree && crop.Yields.Contains(((Object)p.m_itemPrefab).name)) { return true; } } return false; } public static Crop CropYielding(string itemPrefab) { foreach (Crop crop in Crops) { if (!crop.IsTree && crop.Yields.Contains(itemPrefab)) { return crop; } } return null; } public static bool GrowsHere(Crop c, Vector3 p) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 if ((int)c.Plant.m_biome == 0) { return true; } Biome val = Heightmap.FindBiome(p); return (c.Plant.m_biome & val) > 0; } public static bool IsCultivated(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) Heightmap val = Heightmap.FindHeightmap(p); if ((Object)(object)val != (Object)null) { return val.IsCultivated(p); } return false; } public static bool Crowded(Vector3 p, float r) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) float num = r * r; Vector3 val2; foreach (Plant item in WorldScan.All(3f)) { Plant val = item; if ((Object)(object)val != (Object)null) { val2 = ((Component)val).transform.position - p; if (((Vector3)(ref val2)).sqrMagnitude < num) { return true; } } } foreach (Pickable item2 in WorldScan.All(8f)) { Pickable val3 = item2; if ((Object)(object)val3 != (Object)null) { val2 = ((Component)val3).transform.position - p; if (((Vector3)(ref val2)).sqrMagnitude < num) { return true; } } } return false; } public static int FieldCount(Vector3 center, float radius) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) int num = 0; float num2 = radius * radius; Vector3 val2; foreach (Plant item in WorldScan.All(3f)) { Plant val = item; if ((Object)(object)val != (Object)null) { val2 = ((Component)val).transform.position - center; if (((Vector3)(ref val2)).sqrMagnitude < num2 && val.m_needCultivatedGround) { num++; } } } foreach (Pickable item2 in WorldScan.All(8f)) { Pickable val3 = item2; if ((Object)(object)val3 != (Object)null) { val2 = ((Component)val3).transform.position - center; if (((Vector3)(ref val2)).sqrMagnitude < num2 && IsCrop(val3)) { num++; } } } return num; } public static Vector3 FieldCenter(Vector3 home) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) return VillageLayout.FieldCenter(home); } } internal static class PieceIndex { private const float Cell = 4f; private static readonly Dictionary> Grid = new Dictionary>(); private static readonly Dictionary Names = new Dictionary(); private static readonly Stack> Spare = new Stack>(); private static int _version = -1; private static readonly List Tmp = new List(); private static long Key(int x, int z) { return ((long)x << 32) ^ (uint)z; } private static void Refresh() { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) List list = WorldScan.All(1f); if (_version == WorldScan.PiecesVersion) { return; } _version = WorldScan.PiecesVersion; foreach (List value2 in Grid.Values) { value2.Clear(); Spare.Push(value2); } Grid.Clear(); Names.Clear(); foreach (Component item in list) { Piece val = (Piece)(object)((item is Piece) ? item : null); if (!((Object)(object)val == (Object)null)) { Vector3 position = ((Component)val).transform.position; long key = Key(Mathf.FloorToInt(position.x / 4f), Mathf.FloorToInt(position.z / 4f)); if (!Grid.TryGetValue(key, out var value)) { value = ((Spare.Count > 0) ? Spare.Pop() : new List()); Grid[key] = value; } value.Add(val); } } } public static string NameOf(Piece p) { int instanceID = ((Object)p).GetInstanceID(); if (!Names.TryGetValue(instanceID, out var value)) { value = Utils.GetPrefabName(((Component)p).gameObject); Names[instanceID] = value; } return value; } public static void Near(Vector3 at, float r, List into) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) Refresh(); into.Clear(); int num = Mathf.FloorToInt((at.x - r) / 4f); int num2 = Mathf.FloorToInt((at.x + r) / 4f); int num3 = Mathf.FloorToInt((at.z - r) / 4f); int num4 = Mathf.FloorToInt((at.z + r) / 4f); float num5 = r * r; for (int i = num; i <= num2; i++) { for (int j = num3; j <= num4; j++) { if (!Grid.TryGetValue(Key(i, j), out var value)) { continue; } foreach (Piece item in value) { if (!((Object)(object)item == (Object)null)) { Vector3 val = ((Component)item).transform.position - at; if (val.x * val.x + val.z * val.z <= num5) { into.Add(item); } } } } } } public static Piece At(string prefabName, Vector3 at, float r, float dy = 1000f, bool villagersOnly = false) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) Near(at, r, Tmp); foreach (Piece item in Tmp) { if ((!villagersOnly || item.GetCreator() == 0L) && !(Mathf.Abs(((Component)item).transform.position.y - at.y) > dy) && NameOf(item) == prefabName) { return item; } } return null; } } internal static class WorldScan { private sealed class Claim { public VillagerAI By; public float Until; } private static readonly Dictionary> Cache = new Dictionary>(); private static readonly Dictionary> Building = new Dictionary>(); private static readonly List Types = new List(); private static readonly List PassTypes = new List(); private static readonly List Snapshot = new List(); private static readonly FieldInfo InstancesField = AccessTools.Field(typeof(ZNetScene), "m_instances"); private static readonly FieldInfo AllPiecesField = AccessTools.Field(typeof(Piece), "s_allPieces"); private static int _cursor = -1; private static float _nextPass; private static float _piecesAt = -1f; private const int PerFrame = 250; private const float Period = 2f; private static readonly List PieceList = new List(); public static int PiecesVersion; private static readonly Dictionary Claims = new Dictionary(); public static List All(float maxAge) where T : Component { Type typeFromHandle = typeof(T); if (typeFromHandle == typeof(Piece)) { return Pieces(maxAge); } if (!Cache.TryGetValue(typeFromHandle, out var value)) { value = new List(); T[] array = Object.FindObjectsOfType(); foreach (T val in array) { value.Add((Component)(object)val); } Cache[typeFromHandle] = value; Types.Add(typeFromHandle); } return value; } private static List Pieces(float maxAge) { if (_piecesAt >= 0f && Time.time - _piecesAt < Mathf.Min(maxAge, 1f)) { return PieceList; } _piecesAt = Time.time; PiecesVersion++; PieceList.Clear(); List list = ((AllPiecesField != null) ? (AllPiecesField.GetValue(null) as List) : null); if (list != null) { foreach (Piece item2 in list) { if ((Object)(object)item2 != (Object)null) { PieceList.Add((Component)(object)item2); } } } else { Piece[] array = Object.FindObjectsOfType(); foreach (Piece item in array) { PieceList.Add((Component)(object)item); } } return PieceList; } public static void Tick() { if (Types.Count == 0 || (Object)(object)ZNetScene.instance == (Object)null) { return; } if (_cursor < 0) { if (Time.time < _nextPass) { return; } Dictionary dictionary = ((InstancesField != null) ? (InstancesField.GetValue(ZNetScene.instance) as Dictionary) : null); if (dictionary == null) { return; } Snapshot.Clear(); Snapshot.AddRange(dictionary.Values); PassTypes.Clear(); PassTypes.AddRange(Types); foreach (Type passType in PassTypes) { if (!Building.TryGetValue(passType, out var value)) { value = (Building[passType] = new List()); } value.Clear(); } _cursor = 0; } int num = Mathf.Min(_cursor + 250, Snapshot.Count); for (int i = _cursor; i < num; i++) { ZNetView val = Snapshot[i]; if ((Object)(object)val == (Object)null) { continue; } for (int j = 0; j < PassTypes.Count; j++) { Component component = ((Component)val).GetComponent(PassTypes[j]); if ((Object)(object)component != (Object)null) { Building[PassTypes[j]].Add(component); } } } _cursor = num; if (_cursor < Snapshot.Count) { return; } foreach (Type passType2 in PassTypes) { List value2 = Building[passType2]; Building[passType2] = Cache[passType2]; Cache[passType2] = value2; } Snapshot.Clear(); _cursor = -1; _nextPass = Time.time + 2f; } public static void Add(Component c) { if (!((Object)(object)c == (Object)null) && Cache.TryGetValue(((object)c).GetType(), out var value) && !value.Contains(c)) { value.Add(c); } } public static void Invalidate() { if (typeof(T) == typeof(Piece)) { _piecesAt = -1f; } else if (_cursor < 0) { _nextPass = 0f; } } public static bool Reserve(Object o, VillagerAI by, float seconds) { if (o == (Object)null) { return false; } int instanceID = o.GetInstanceID(); if (Claims.TryGetValue(instanceID, out var value) && (Object)(object)value.By != (Object)null && (Object)(object)value.By != (Object)(object)by && value.Until > Time.time) { return false; } Claims[instanceID] = new Claim { By = by, Until = Time.time + seconds }; return true; } public static bool ReservedByOther(Object o, VillagerAI me) { if (o == (Object)null) { return true; } if (Claims.TryGetValue(o.GetInstanceID(), out var value) && (Object)(object)value.By != (Object)null && (Object)(object)value.By != (Object)(object)me) { return value.Until > Time.time; } return false; } public static void Release(Object o, VillagerAI by) { if (!(o == (Object)null) && Claims.TryGetValue(o.GetInstanceID(), out var value) && (Object)(object)value.By == (Object)(object)by) { Claims.Remove(o.GetInstanceID()); } } } internal static class Village { public static List Chests(Vector3 home, float range) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) List list = new List(); foreach (Container item in WorldScan.All(5f)) { Container val = item; if ((Object)(object)val == (Object)null || (Object)(object)val.m_wagon != (Object)null || (Object)(object)((Component)val).GetComponent() != (Object)null || (Object)(object)((Component)val).GetComponent() == (Object)null) { continue; } ZNetView component = ((Component)val).GetComponent(); if (!((Object)(object)component == (Object)null) && component.IsValid()) { Vector3 val2 = ((Component)val).transform.position - home; if (!(((Vector3)(ref val2)).sqrMagnitude > range * range)) { list.Add(val); } } } return list; } public static CraftingStation Station(string stationName, Vector3 home, float range) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return CraftingStation.FindClosestStationInRange(stationName, home, range); } public static bool HaveStation(string prefabName, Vector3 home, float range) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(prefabName) : null); CraftingStation val2 = (((Object)(object)val != (Object)null) ? val.GetComponent() : null); if ((Object)(object)val2 != (Object)null) { return (Object)(object)Station(val2.m_name, home, range) != (Object)null; } return false; } private static bool CanUse(Container c) { if ((Object)(object)c != (Object)null) { return !c.IsInUse(); } return false; } public static List Neighbours(VillagerCharacter v, Vector3 home) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) List list = new List { v }; foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)v && !((Character)item).IsDead() && !item.IsWanderer) { Vector3 val = item.Home - home; if (((Vector3)(ref val)).sqrMagnitude < 225f) { list.Add(item); } } } return list; } public static int Count(VillagerCharacter v, string itemName, Vector3 home, float range) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) int num = 0; foreach (VillagerCharacter item in Neighbours(v, home)) { num += ((Humanoid)item).GetInventory().CountItems(itemName, -1, false); } foreach (Container item2 in Chests(home, range)) { if (CanUse(item2)) { num += item2.GetInventory().CountItems(itemName, -1, false); } } return num; } public static void Take(VillagerCharacter v, string itemName, int amount, Vector3 home, float range) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) foreach (VillagerCharacter item in Neighbours(v, home)) { if (amount <= 0) { break; } Inventory inventory = ((Humanoid)item).GetInventory(); int num = Mathf.Min(amount, inventory.CountItems(itemName, -1, false)); if (num > 0) { inventory.RemoveItem(itemName, num, -1, false); amount -= num; } } foreach (Container item2 in Chests(home, range)) { if (amount <= 0) { break; } if (CanUse(item2)) { int num2 = Mathf.Min(amount, item2.GetInventory().CountItems(itemName, -1, false)); if (num2 > 0) { ((Component)item2).GetComponent().ClaimOwnership(); item2.GetInventory().RemoveItem(itemName, num2, -1, false); amount -= num2; } } } } public static string TakeFood(VillagerCharacter v, Vector3 home, float range) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) ItemData val = null; Inventory val2 = null; Container val3 = null; foreach (ItemData allItem in ((Humanoid)v).GetInventory().GetAllItems()) { if (Edible(allItem) && (val == null || allItem.m_shared.m_food > val.m_shared.m_food)) { val = allItem; val2 = ((Humanoid)v).GetInventory(); val3 = null; } } foreach (Container item in Chests(home, range)) { if (!CanUse(item)) { continue; } foreach (ItemData allItem2 in item.GetInventory().GetAllItems()) { if (Edible(allItem2) && (val == null || allItem2.m_shared.m_food > val.m_shared.m_food)) { val = allItem2; val2 = item.GetInventory(); val3 = item; } } } if (val == null) { return null; } if ((Object)(object)val3 != (Object)null) { ((Component)val3).GetComponent().ClaimOwnership(); } string name = val.m_shared.m_name; val2.RemoveItem(val, 1); return name; } public static bool Edible(ItemData it) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Invalid comparison between Unknown and I4 if (it != null && it.m_shared.m_food > 0f) { return (int)it.m_shared.m_itemType == 2; } return false; } public static Container ChestWithRoom(Vector3 home, float range, Vector3 near) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) Container result = null; float num = float.MaxValue; foreach (Container item in Chests(home, range)) { if (CanUse(item) && item.GetInventory().HaveEmptySlot()) { Vector3 val = ((Component)item).transform.position - near; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; result = item; } } } return result; } public static bool UpgradeOnly(Requirement r) { if (r.m_upgraderResource) { return true; } if ((Object)(object)r.m_resItem != (Object)null) { return ((Object)((Component)r.m_resItem).gameObject).name.EndsWith("BattleIdol"); } return false; } public static bool CanAfford(VillagerCharacter v, Requirement[] reqs, Vector3 home, float range) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (reqs == null) { return true; } foreach (Requirement val in reqs) { if (val != null && !((Object)(object)val.m_resItem == (Object)null) && !UpgradeOnly(val)) { int amount = val.GetAmount(1); if (amount > 0 && Count(v, val.m_resItem.m_itemData.m_shared.m_name, home, range) < amount) { return false; } } } return true; } public static void Pay(VillagerCharacter v, Requirement[] reqs, Vector3 home, float range) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (reqs == null) { return; } foreach (Requirement val in reqs) { if (val != null && !((Object)(object)val.m_resItem == (Object)null) && !UpgradeOnly(val)) { int amount = val.GetAmount(1); if (amount > 0) { Take(v, val.m_resItem.m_itemData.m_shared.m_name, amount, home, range); } } } } public static string Summary(Vector3 home, float range) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = new Dictionary(); int num = 0; foreach (Container item in Chests(home, range)) { num++; foreach (ItemData allItem in item.GetInventory().GetAllItems()) { string key = ((Localization.instance != null) ? Localization.instance.Localize(allItem.m_shared.m_name) : allItem.m_shared.m_name); dictionary.TryGetValue(key, out var value); dictionary[key] = value + allItem.m_stack; } } List list = new List(); foreach (KeyValuePair item2 in dictionary) { list.Add(item2.Key + " " + item2.Value); } list.Sort(); return $"{num} chest(s): " + ((list.Count > 0) ? string.Join(", ", list.ToArray()) : "empty"); } } internal static class VillageAlarm { private const float Lifetime = 12f; private static Character _enemy; private static Vector3 _where; private static float _time = -999f; private static string _raisedBy; public static void Raise(Character enemy, Vector3 where, string by) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)enemy == (Object)null) { return; } bool num = Time.time - _time > 12f || (Object)(object)_enemy == (Object)null || _enemy.IsDead(); _enemy = enemy; _where = where; _time = Time.time; if (num) { _raisedBy = by; if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)$"Village alarm: {by} spotted {enemy.m_name} at {where}."); } } } public static Character Near(Vector3 home, float range) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_enemy == (Object)null || _enemy.IsDead() || Time.time - _time > 12f) { return null; } Vector3 val = _where - home; if (((Vector3)(ref val)).sqrMagnitude > (range + 20f) * (range + 20f)) { return null; } return _enemy; } public static string Describe() { if ((Object)(object)_enemy == (Object)null || _enemy.IsDead() || Time.time - _time > 12f) { return "no alarm"; } return $"alarm: {_raisedBy} spotted {_enemy.m_name} {Time.time - _time:0}s ago"; } } internal static class VillageLayout { internal enum Kind { Fire, Workbench, Chest, Bed, Wall } internal struct Slot { public Vector3 Pos; public Quaternion Rot; } internal struct Part { public string Prefab; public Slot Slot; public bool Lower; public bool Upper; public Vector3 Below; } private static readonly Dictionary Footprints = new Dictionary(); private static readonly Dictionary Heights = new Dictionary(); public const float HallHeight = 4f; private static readonly Dictionary> Claims = new Dictionary>(); private static int _mask = -1; public static string LastBlocker = ""; private static readonly Collider[] Hits = (Collider[])(object)new Collider[32]; private static float _nextBlockLog; public static Vector3 Center(Vector3 home) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) Vector3 val = VillageInfo.At(home)?.Center ?? home; if ((Object)(object)ZoneSystem.instance != (Object)null) { val.y = ZoneSystem.instance.GetGroundHeight(val); } return val; } public static Quaternion Facing(Vector3 center) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Abs((Mathf.RoundToInt(center.x * 0.5f) * 73856093) ^ (Mathf.RoundToInt(center.z * 0.5f) * 19349663)); return Quaternion.Euler(0f, (float)(num % 4) * 90f, 0f); } public static Kind? KindOf(string prefabName) { return prefabName switch { "fire_pit" => Kind.Fire, "piece_workbench" => Kind.Workbench, "piece_chest_wood" => Kind.Chest, "bed" => Kind.Bed, "stake_wall" => Kind.Wall, _ => null, }; } public static Vector3 Footprint(GameObject prefab) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) if (Footprints.TryGetValue(((Object)prefab).name, out var value)) { return value; } Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 val2 = -val; Transform transform = prefab.transform; bool flag = false; Collider[] componentsInChildren = prefab.GetComponentsInChildren(true); Bounds bounds = default(Bounds); foreach (Collider val3 in componentsInChildren) { if ((Object)(object)val3 == (Object)null || val3.isTrigger) { continue; } BoxCollider val4 = (BoxCollider)(object)((val3 is BoxCollider) ? val3 : null); if (val4 != null) { ((Bounds)(ref bounds))..ctor(val4.center, val4.size); } else { MeshCollider val5 = (MeshCollider)(object)((val3 is MeshCollider) ? val3 : null); if (val5 != null && (Object)(object)val5.sharedMesh != (Object)null) { bounds = val5.sharedMesh.bounds; } else { CapsuleCollider val6 = (CapsuleCollider)(object)((val3 is CapsuleCollider) ? val3 : null); if (val6 == null) { continue; } ((Bounds)(ref bounds))..ctor(val6.center, Vector3.one * val6.radius * 2f); } } for (int j = 0; j < 8; j++) { Vector3 val7 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1)))); Vector3 val8 = transform.InverseTransformPoint(((Component)val3).transform.TransformPoint(val7)); val = Vector3.Min(val, val8); val2 = Vector3.Max(val2, val8); flag = true; } } value = (Vector3)(flag ? (val2 - val) : new Vector3(1.5f, 1f, 1.5f)); value.x = Mathf.Clamp(value.x, 0.5f, 6f); value.z = Mathf.Clamp(value.z, 0.5f, 6f); Footprints[((Object)prefab).name] = value; return value; } private static GameObject Prefab(string name) { if (!((Object)(object)ZNetScene.instance != (Object)null)) { return null; } return ZNetScene.instance.GetPrefab(name); } public static List Slots(Kind kind, Vector3 center) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) Quaternion face = Facing(center); List list = new List(); switch (kind) { case Kind.Fire: { list.Add(Make(center, face, Vector3.zero, 0f)); for (float num5 = 2.5f; num5 <= 6.6f; num5 += 2f) { for (int l = 0; l < 8; l++) { list.Add(Make(center, face, Quaternion.Euler(0f, (float)l * 45f, 0f) * new Vector3(0f, 0f, num5), 0f)); } } break; } case Kind.Workbench: list.Add(Make(center, face, new Vector3(5f, 0f, 0f), -90f)); break; case Kind.Chest: { GameObject val3 = Prefab("piece_chest_wood"); Vector3 val4 = (Vector3)(((Object)(object)val3 != (Object)null) ? Footprint(val3) : new Vector3(1.4f, 1f, 0.9f)); float num4 = val4.x + 0.25f; for (int j = 0; j < 3; j++) { for (int k = 0; k < 4; k++) { list.Add(Make(center, face, new Vector3(7.2f + (float)j * (val4.z + 0.5f), 0f, ((float)k - 1.5f) * num4), -90f)); } } break; } case Kind.Bed: { GameObject val5 = Prefab("bed"); Vector3 val6 = (Vector3)(((Object)(object)val5 != (Object)null) ? Footprint(val5) : new Vector3(1.2f, 1f, 2.3f)); bool num6 = val6.z >= val6.x; float num7 = (num6 ? val6.z : val6.x); float num8 = (num6 ? val6.x : val6.z); float yaw = (num6 ? 90f : 0f); float num9 = num8 + 0.35f; for (int m = 0; m < 3; m++) { for (int n = 0; n < 6; n++) { list.Add(Make(center, face, new Vector3(0f - (4.5f + num7 / 2f + (float)m * (num7 + 0.9f)), 0f, ((float)n - 2.5f) * num9), yaw)); } } break; } case Kind.Wall: { GameObject val = Prefab("stake_wall"); float num = (((Object)(object)val != (Object)null) ? Mathf.Max(1f, Footprint(val).x) : 2f); int num2 = Mathf.CeilToInt((float)Math.PI * 32f / num); for (int i = 0; i < num2; i++) { float num3 = (float)i * 360f / (float)num2; if (!(Mathf.Abs(Mathf.DeltaAngle(num3, 0f)) < 360f / (float)num2 * 1.1f)) { Vector3 val2 = Quaternion.Euler(0f, num3, 0f) * Vector3.forward; list.Add(Make(center, face, val2 * 16f, num3)); } } break; } } return list; } public static Vector2 Height(GameObject prefab) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) if (Heights.TryGetValue(((Object)prefab).name, out var value)) { return value; } float num = float.MaxValue; float num2 = float.MinValue; Collider[] componentsInChildren = prefab.GetComponentsInChildren(true); Bounds bounds = default(Bounds); foreach (Collider val in componentsInChildren) { if ((Object)(object)val == (Object)null || val.isTrigger) { continue; } BoxCollider val2 = (BoxCollider)(object)((val is BoxCollider) ? val : null); if (val2 != null) { ((Bounds)(ref bounds))..ctor(val2.center, val2.size); } else { MeshCollider val3 = (MeshCollider)(object)((val is MeshCollider) ? val : null); if (val3 == null || !((Object)(object)val3.sharedMesh != (Object)null)) { continue; } bounds = val3.sharedMesh.bounds; } for (int j = 0; j < 8; j++) { Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1)))); float y = prefab.transform.InverseTransformPoint(((Component)val).transform.TransformPoint(val4)).y; num = Mathf.Min(num, y); num2 = Mathf.Max(num2, y); } } value = ((num == float.MaxValue) ? new Vector2(0f, 2f) : new Vector2(num, num2)); Heights[((Object)prefab).name] = value; return value; } private static void BedRows(out float length, out float step) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) GameObject val = Prefab("bed"); Vector3 val2 = (Vector3)(((Object)(object)val != (Object)null) ? Footprint(val) : new Vector3(1.2f, 1f, 2.3f)); bool flag = val2.z >= val2.x; length = (flag ? val2.z : val2.x); float num = (flag ? val2.x : val2.z); step = num + 0.35f; } private static float ColumnX(int column) { BedRows(out var length, out var _); return 0f - (4.5f + length / 2f + (float)column * (length + 0.9f)); } public static Vector3 HallCenter(Vector3 center, int column) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return center + Facing(center) * new Vector3(ColumnX(column), 0f, 0f); } public static List ShelterParts(Vector3 center, int column) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) List list = new List(); GameObject val = Prefab("wood_pole2"); GameObject val2 = Prefab("wood_floor"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return list; } Quaternion val3 = Facing(center); float num = ColumnX(column); float num2 = float.MaxValue; for (int i = -1; i <= 1; i += 2) { for (int j = -5; j <= 5; j += 5) { num2 = Mathf.Min(num2, Ground(center + val3 * new Vector3(num + (float)i * 2f, 0f, (float)j))); } } Vector2 val4 = Height(val); float num3 = val4.y - val4.x; float num4 = num2 + 2f * num3 + 0.05f; Vector2 val5 = Height(val2); List list2 = new List(); List list3 = new List(); int[] array = new int[2] { -1, 1 }; foreach (int num5 in array) { int[] array2 = new int[3] { -5, 0, 5 }; foreach (int num6 in array2) { Vector3 pos; Vector3 val6 = (pos = center + val3 * new Vector3(num + (float)num5 * 2f, 0f, (float)num6)); pos.y = num4 - val4.y; Vector3 val7 = val6; val7.y = num4 - num3 - val4.y; list2.Add(new Part { Prefab = "wood_pole2", Slot = new Slot { Pos = val7, Rot = val3 }, Lower = true }); list3.Add(new Part { Prefab = "wood_pole2", Slot = new Slot { Pos = pos, Rot = val3 }, Upper = true, Below = val7 }); } } list.AddRange(list2); list.AddRange(list3); array = new int[2] { -1, 1 }; foreach (int num7 in array) { for (int m = -2; m <= 2; m++) { Vector3 pos2 = center + val3 * new Vector3(num + (float)num7 * 1f, 0f, (float)m * 2f); pos2.y = num4 - 0.05f - val5.x; list.Add(new Part { Prefab = "wood_floor", Slot = new Slot { Pos = pos2, Rot = val3 } }); } } return list; } public static Piece StrayHallPiece(Vector3 center, int columns) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) List list = new List(); for (int i = 0; i < columns; i++) { foreach (Part item in ShelterParts(center, i)) { list.Add(item.Slot.Pos); } } for (int j = 0; j < 2; j++) { Vector3 val = HallCenter(center, j); foreach (Piece item2 in WorldScan.All(3f)) { Piece val2 = item2; if ((Object)(object)val2 == (Object)null || val2.GetCreator() != 0L) { continue; } ZNetView component = ((Component)val2).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { continue; } string prefabName = Utils.GetPrefabName(((Component)val2).gameObject); if (prefabName != "wood_pole2" && prefabName != "wood_floor") { continue; } Vector3 val3 = ((Component)val2).transform.position - val; val3.y = 0f; if (((Vector3)(ref val3)).sqrMagnitude > 64f) { continue; } bool flag = false; foreach (Vector3 item3 in list) { Vector3 val4 = item3 - ((Component)val2).transform.position; if (((Vector3)(ref val4)).sqrMagnitude < 0.122499995f) { flag = true; break; } } if (!flag) { return val2; } } } return null; } public static void Dismantle(Piece p, Vector3 center, float radius) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) ZNetView val = (((Object)(object)p != (Object)null) ? ((Component)p).GetComponent() : null); if ((Object)(object)val == (Object)null || !val.IsValid()) { WorldScan.Invalidate(); return; } List> list = new List>(); Refund(p, list); Remove(p); WorldScan.Invalidate(); foreach (KeyValuePair item in list) { Container val2 = Village.ChestWithRoom(center, radius, center); if ((Object)(object)val2 != (Object)null) { ((Component)val2).GetComponent().ClaimOwnership(); val2.GetInventory().AddItem(item.Key, item.Value); } } } private static float Ground(Vector3 p) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)ZoneSystem.instance != (Object)null)) { return p.y; } return ZoneSystem.instance.GetGroundHeight(p); } public static bool Claim(Vector3 at, Object who) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) string key = Mathf.RoundToInt(at.x * 2f) + "," + Mathf.RoundToInt(at.y * 2f) + "," + Mathf.RoundToInt(at.z * 2f); if (Claims.TryGetValue(key, out var value) && value.Value > Time.time && value.Key != (Object)null && value.Key != who) { return false; } Claims[key] = new KeyValuePair(who, Time.time + 45f); return true; } public static bool Built(string prefabName, Vector3 at, bool fresh = false) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) if (fresh) { Collider[] array = Physics.OverlapSphere(at, 0.6f); foreach (Collider val in array) { Piece val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInParent() : null); if ((Object)(object)val2 != (Object)null) { Vector3 val3 = ((Component)val2).transform.position - at; if (((Vector3)(ref val3)).sqrMagnitude < 0.122499995f && Utils.GetPrefabName(((Component)val2).gameObject) == prefabName) { return true; } } } return false; } return (Object)(object)PieceIndex.At(prefabName, at, 0.35f, 0.35f) != (Object)null; } public static Vector3 FieldCenter(Vector3 home) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Center(home); Vector3 val2 = val + Facing(val) * new Vector3(0f, 0f, -12f); if ((Object)(object)ZoneSystem.instance != (Object)null) { val2.y = ZoneSystem.instance.GetGroundHeight(val2); } return val2; } private static Slot Make(Vector3 center, Quaternion face, Vector3 local, float yaw) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) Vector3 val = center + face * local; if ((Object)(object)ZoneSystem.instance != (Object)null) { val.y = ZoneSystem.instance.GetGroundHeight(val); } return new Slot { Pos = val, Rot = face * Quaternion.Euler(0f, yaw, 0f) }; } public static bool Free(Slot s, GameObject prefab, HashSet ignore = null) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) if (_mask == -1) { _mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "vehicle" }); } Vector3 val = Footprint(prefab); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(val.x * 0.5f - 0.05f, 0.6f, val.z * 0.5f - 0.05f); int num = Physics.OverlapBoxNonAlloc(s.Pos + Vector3.up * 0.75f, val2, Hits, s.Rot, _mask, (QueryTriggerInteraction)1); for (int i = 0; i < num; i++) { Collider val3 = Hits[i]; if ((Object)(object)val3 == (Object)null) { continue; } if (ignore != null) { Piece componentInParent = ((Component)val3).GetComponentInParent(); if ((Object)(object)componentInParent != (Object)null && ignore.Contains(componentInParent)) { continue; } } if (!((Object)(object)((Component)val3).GetComponentInParent() != (Object)null) && !((Object)(object)((Component)val3).GetComponentInParent() != (Object)null) && (!((Object)(object)prefab.GetComponent() != (Object)null) || !((Object)(object)((Component)val3).GetComponentInParent() != (Object)null))) { LastBlocker = ((Object)((Component)val3).transform.root).name; return false; } } if ((Object)(object)ZoneSystem.instance != (Object)null) { for (int j = 0; j < 4; j++) { Vector3 val4 = s.Pos + s.Rot * new Vector3((float)(((j & 1) != 0) ? 1 : (-1)) * val.x * 0.5f, 0f, (float)(((j & 2) != 0) ? 1 : (-1)) * val.z * 0.5f); if (Mathf.Abs(ZoneSystem.instance.GetGroundHeight(val4) - s.Pos.y) > 0.9f) { return false; } } } return true; } public static bool NextFree(Kind kind, Vector3 center, GameObject prefab, out Slot slot) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) foreach (Slot item in Slots(kind, center)) { if (Free(item, prefab)) { slot = item; return true; } } if (Time.time > _nextBlockLog) { _nextBlockLog = Time.time + 60f; if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)$"Camp plan: no free spot for a {kind} (last blocked by {LastBlocker})."); } } slot = default(Slot); return false; } public static string Tidy(Vector3 center, float radius) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_047f: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_04bb: Unknown result type (might be due to invalid IL or missing references) //IL_04c0: Unknown result type (might be due to invalid IL or missing references) //IL_04ce: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_0498: Unknown result type (might be due to invalid IL or missing references) //IL_0645: Unknown result type (might be due to invalid IL or missing references) //IL_064c: Unknown result type (might be due to invalid IL or missing references) //IL_05ad: Unknown result type (might be due to invalid IL or missing references) //IL_05c0: Unknown result type (might be due to invalid IL or missing references) //IL_05c5: Unknown result type (might be due to invalid IL or missing references) //IL_05ca: Unknown result type (might be due to invalid IL or missing references) int num = 0; Vector3 val; foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item != (Object)null && !((Character)item).IsDead()) { val = item.Home - center; if (((Vector3)(ref val)).sqrMagnitude < radius * radius) { num++; } } } Dictionary> dictionary = new Dictionary>(); List list = new List(); List list2 = new List(); Piece[] array = Object.FindObjectsOfType(); foreach (Piece val2 in array) { if ((Object)(object)val2 == (Object)null || val2.GetCreator() != 0L) { continue; } ZNetView component = ((Component)val2).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { continue; } val = ((Component)val2).transform.position - center; if (((Vector3)(ref val)).sqrMagnitude > radius * radius) { continue; } string prefabName = Utils.GetPrefabName(((Component)val2).gameObject); switch (prefabName) { case "piece_cookingstation": list.Add(val2); continue; case "wood_pole2": case "wood_floor": list2.Add(val2); continue; } Kind? kind = KindOf(prefabName); if (kind.HasValue) { if (!dictionary.TryGetValue(kind.Value, out var value)) { value = (dictionary[kind.Value] = new List()); } value.Add(val2); } } HashSet hashSet = new HashSet(list); foreach (List value3 in dictionary.Values) { foreach (Piece item2 in value3) { hashSet.Add(item2); } } int num2 = 0; int num3 = 0; Slot? slot = null; List> list4 = new List>(); List>> list5 = new List>>(dictionary); list5.Sort((KeyValuePair> a, KeyValuePair> b) => ((int)a.Key).CompareTo((int)b.Key)); foreach (KeyValuePair> item3 in list5) { List value2 = item3.Value; value2.Sort(delegate(Piece a, Piece b) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Vector3 val5 = ((Component)a).transform.position - center; float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude; val5 = ((Component)b).transform.position - center; return sqrMagnitude.CompareTo(((Vector3)(ref val5)).sqrMagnitude); }); int num4 = ((item3.Key == Kind.Bed) ? Mathf.Max(1, num) : ((item3.Key != Kind.Chest) ? 1 : int.MaxValue)); List list6 = Slots(item3.Key, center); int num5 = 0; for (int num6 = 0; num6 < value2.Count; num6++) { GameObject prefab = Prefab(Utils.GetPrefabName(((Component)value2[num6]).gameObject)) ?? ((Component)value2[num6]).gameObject; if (num6 >= num4) { if (item3.Key != Kind.Chest) { Refund(value2[num6], list4); Remove(value2[num6]); num3++; } continue; } if (item3.Key == Kind.Fire) { int num7; for (num7 = 0; num7 < list6.Count - 1 && !Free(list6[num7], prefab, hashSet); num7++) { } Move(((Component)value2[num6]).gameObject, list6[num7]); num2++; slot = list6[num7]; continue; } for (; num5 < list6.Count && !Free(list6[num5], prefab, hashSet); num5++) { if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)$"Tidy: {item3.Key} slot {num5} blocked by {LastBlocker}."); } } if (num5 < list6.Count) { Move(((Component)value2[num6]).gameObject, list6[num5++]); num2++; } } } Slot s; if (slot.HasValue) { s = slot.Value; } else { Fireplace val3 = VillagerPlaces.NearestBurningFire(center, radius); s = (((Object)(object)val3 != (Object)null) ? new Slot { Pos = ((Component)val3).transform.position, Rot = ((Component)val3).transform.rotation } : Slots(Kind.Fire, center)[0]); } for (int num8 = 0; num8 < list.Count; num8++) { if (num8 == 0) { Move(((Component)list[num8]).gameObject, s); num2++; } else { Refund(list[num8], list4); Remove(list[num8]); num3++; } } for (int num9 = 0; num9 < list2.Count; num9++) { if ((Object)(object)list2[num9] == (Object)null) { continue; } string prefabName2 = Utils.GetPrefabName(((Component)list2[num9]).gameObject); for (int num10 = num9 + 1; num10 < list2.Count; num10++) { if (!((Object)(object)list2[num10] == (Object)null) && !(Utils.GetPrefabName(((Component)list2[num10]).gameObject) != prefabName2)) { val = ((Component)list2[num9]).transform.position - ((Component)list2[num10]).transform.position; if (!(((Vector3)(ref val)).sqrMagnitude > 0.122499995f)) { Refund(list2[num10], list4); Remove(list2[num10]); list2[num10] = null; num3++; } } } } foreach (KeyValuePair item4 in list4) { Container val4 = Village.ChestWithRoom(center, radius, center); if ((Object)(object)val4 != (Object)null) { ((Component)val4).GetComponent().ClaimOwnership(); val4.GetInventory().AddItem(item4.Key, item4.Value); } } WorldScan.Invalidate(); WorldScan.Invalidate(); WorldScan.Invalidate(); VillagerPlaces.Invalidate(); string text = $"Tidied the camp: moved {num2} building(s) into place, took down {num3} extra."; DynastyPlugin.Log.LogInfo((object)text); return text; } internal static void Move(GameObject go, Slot s) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) ZNetView component = go.GetComponent(); component.ClaimOwnership(); go.transform.SetPositionAndRotation(s.Pos, s.Rot); component.GetZDO().SetPosition(s.Pos); component.GetZDO().SetRotation(s.Rot); } internal static void Refund(Piece p, List> refunds) { if (p.m_resources == null) { return; } Requirement[] resources = p.m_resources; foreach (Requirement val in resources) { if (val != null && (Object)(object)val.m_resItem != (Object)null && val.m_recover && val.m_amount > 0) { refunds.Add(new KeyValuePair(((Component)val.m_resItem).gameObject, val.m_amount)); } } } internal static void Remove(Piece p) { ZNetView val = (((Object)(object)p != (Object)null) ? ((Component)p).GetComponent() : null); if (!((Object)(object)val == (Object)null) && val.IsValid()) { val.ClaimOwnership(); ZNetScene.instance.Destroy(((Component)p).gameObject); } } } public class VillagerAI : BaseAI { private VillagerCharacter _villager; private Rigidbody _rb; private float _nextThink; private float _nextBedLook; private float _needsTimer; private VillagerActivity _activity; private Vector3 _target; private Bed _bed; private Fireplace _fire; private bool _attached; private string _attachAnim; private Character _enemy; private float _nextAttack; private float _lastHealth = -1f; private float _lastHurt = -999f; private float _nextDoorCheck; private readonly List> _openedDoors = new List>(); private VillagerWorker _worker; private Vector3 _stuckCheckPos; private float _stuckCheckTime; private int _stuckCount; private Vector3 _avoid; private float _nextAvoid; private float _yieldUntil; private float _blockedSince; private float _sidestepUntil; private Vector3 _sidestep; private Vector3 _lastPos; private Vector3 _strollTo; private float _nextStroll; private Vector3 _routeFor; private Vector3 _routeVia; private float _nextRoute; private bool _routed; private Vector3 _progressGoal; private float _progressBest; private float _progressAt; private float _packTimer; private float _nextFloorCheck; private static readonly RaycastHit[] UpHits = (RaycastHit[])(object)new RaycastHit[8]; private float _destPicked; private bool _following; private string _reason = ""; private bool _exhausted; private float _breakEnd; private string _breakReason = ""; private bool _onBreak; private float _lastThreatTime = -99f; private VillagerActivity _wantActivity; private float _wantSince; private int _swingsTried; private int _swingsMade; private static readonly Collider[] DoorHits = (Collider[])(object)new Collider[16]; private RigidbodyConstraints _savedConstraints = (RigidbodyConstraints)112; internal VillagerWorker Worker => _worker; private float PersonalDelay => 2f + (float)(Mathf.Abs(_villager.VillagerName.GetHashCode()) % 2400) / 100f; protected override void Awake() { ((BaseAI)this).Awake(); _villager = ((Component)this).GetComponent(); _rb = ((Component)this).GetComponent(); _worker = new VillagerWorker(this, _villager); } internal bool WMoveTo(float dt, Vector3 p, float dist, bool run) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) return SmartMove(dt, p, dist, run); } private void WatchProgress(Vector3 me, Vector3 goal, float dist) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) Vector3 val = goal - me; val.y = 0f; float magnitude = ((Vector3)(ref val)).magnitude; Vector3 val2 = goal - _progressGoal; if (((Vector3)(ref val2)).sqrMagnitude > 1f) { _progressGoal = goal; _progressBest = magnitude; _progressAt = Time.time; } else if (magnitude < _progressBest - 1f) { _progressBest = magnitude; _progressAt = Time.time; } else { if (magnitude <= dist + 1f || Time.time - _progressAt < 14f) { return; } _progressAt = Time.time; _progressBest = magnitude; if (!(magnitude > 30f)) { Vector3 val3 = goal - ((Vector3)(ref val)).normalized * Mathf.Min(1f, magnitude); val3.y = Mathf.Max(goal.y, ((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.GetGroundHeight(val3) : goal.y) + 0.2f; if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)string.Format("{0} was pacing without getting closer ({1:0.0} m off, {2}); moving them there.", _villager.VillagerName, magnitude, _routed ? "by the door" : "straight")); } ((Component)this).transform.position = val3; _routed = false; _nextRoute = 0f; } } } private bool SmartMove(float dt, Vector3 goal, float dist, bool run) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) Vector3 me = ((Component)this).transform.position; WatchProgress(me, goal, dist); if (!(Time.time >= _nextRoute)) { Vector3 val = goal - _routeFor; if (!(((Vector3)(ref val)).sqrMagnitude > 0.5f)) { goto IL_00ae; } } _nextRoute = Time.time + 0.4f; _routeFor = goal; Vector3 g = goal; Vector3 via; Vector3? val2 = Safe.Get("AI.Route", () => (!Blueprints.Route(me, g, out via)) ? ((Vector3?)null) : new Vector3?(via), null); _routed = val2.HasValue; if (_routed) { _routeVia = val2.Value; } goto IL_00ae; IL_00ae: if (_routed) { SteerTo(dt, me, _routeVia, 0.5f, run); return false; } return SteerTo(dt, me, goal, dist, run); } private bool SteerTo(float dt, Vector3 me, Vector3 goal, float dist, bool run) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_03ee: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03be: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_03d8: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) Vector3 val = goal - me; val.y = 0f; ((Character)_villager).SetWalk(!run && ((Vector3)(ref val)).magnitude < 30f); Vector3? val2 = AroundFire(me, goal); if (val2.HasValue) { ((BaseAI)this).MoveTo(dt, val2.Value, 0.4f, run); return false; } if (Time.time >= _nextAvoid) { _nextAvoid = Time.time + 0.2f; _avoid = Vector3.zero; Vector3 forward = ((Component)this).transform.forward; forward.y = 0f; bool flag = DoorNear(me); foreach (Character allCharacter in Character.GetAllCharacters()) { if ((Object)(object)allCharacter == (Object)null || (Object)(object)allCharacter == (Object)(object)_villager || allCharacter.IsDead()) { continue; } Vector3 val3 = me - ((Component)allCharacter).transform.position; val3.y = 0f; float magnitude = ((Vector3)(ref val3)).magnitude; if (!(magnitude > 1.6f) && !(magnitude < 0.01f)) { _avoid += val3 / magnitude * (1.6f - magnitude) / 1.6f; if (Vector3.Dot(forward, -val3 / magnitude) > 0.7f && magnitude < 1.3f) { _avoid += Vector3.Cross(Vector3.up, forward) * 0.8f; } VillagerCharacter villagerCharacter = allCharacter as VillagerCharacter; if (flag && (Object)(object)villagerCharacter != (Object)null && magnitude < 1.4f && ((Object)villagerCharacter).GetInstanceID() < ((Object)_villager).GetInstanceID() && Time.time > _yieldUntil + 2f) { _yieldUntil = Time.time + 1.2f; } } } } if (Time.time < _yieldUntil) { ((BaseAI)this).StopMoving(); return false; } Vector3 val4 = me - _lastPos; float magnitude2 = ((Vector3)(ref val4)).magnitude; _lastPos = me; Vector3 val5 = goal - me; val5.y = 0f; if (((Vector3)(ref val5)).magnitude > dist + 0.5f && magnitude2 < 0.3f * dt) { if (_blockedSince <= 0f) { _blockedSince = Time.time; } } else { _blockedSince = 0f; } if (_blockedSince > 0f && Time.time - _blockedSince > 1.2f && Time.time > _sidestepUntil) { Vector3 val6 = Vector3.Cross(Vector3.up, ((Vector3)(ref val5)).normalized) * ((Random.value < 0.5f) ? (-1f) : 1f); _sidestep = me + val6 * 2f - ((Vector3)(ref val5)).normalized * 0.5f; _sidestepUntil = Time.time + 1f; _blockedSince = 0f; } if (Time.time < _sidestepUntil) { ((BaseAI)this).MoveTo(dt, _sidestep, 0.3f, run); return false; } if (((Vector3)(ref _avoid)).sqrMagnitude > 0.01f && ((Vector3)(ref val5)).magnitude > 2f) { val4 = ((Vector3)(ref val5)).normalized * 2f + _avoid * 1.5f; Vector3 val7 = ((Vector3)(ref val4)).normalized * 2.5f; ((BaseAI)this).MoveTo(dt, me + val7, 0.3f, run); return false; } return ((BaseAI)this).MoveTo(dt, goal, dist, run); } private static Vector3? AroundFire(Vector3 me, Vector3 goal) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) Vector3 val = goal - me; val.y = 0f; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; foreach (Component item in WorldScan.All(3f)) { Fireplace val2 = (Fireplace)(object)((item is Fireplace) ? item : null); if ((Object)(object)val2 == (Object)null || !val2.IsBurning()) { continue; } Vector3 position = ((Component)val2).transform.position; Vector3 val3 = position - me; val3.y = 0f; if (((Vector3)(ref val3)).sqrMagnitude > 100f || Mathf.Abs(position.y - me.y) > 2.5f) { continue; } Vector3 val4 = goal - position; val4.y = 0f; if (((Vector3)(ref val3)).magnitude < 1.1f) { Vector3 val5 = -((Vector3)(ref val3)).normalized; if (((Vector3)(ref val5)).sqrMagnitude < 0.01f) { val5 = Vector3.forward; } return position + val5 * 2.2f; } if (((Vector3)(ref val4)).magnitude < 1.3f || sqrMagnitude < 0.01f) { continue; } float num = Mathf.Clamp01(Vector3.Dot(val3, val) / sqrMagnitude); Vector3 val6 = me + val * num; val6.y = position.y; Vector3 val7 = val6 - position; val7.y = 0f; if (!(((Vector3)(ref val7)).magnitude >= 1.6f)) { Vector3 val8 = Vector3.Cross(Vector3.up, ((Vector3)(ref val)).normalized); if (Vector3.Dot(val8, val7) < 0f) { val8 = -val8; } return position + val8 * 2.5f; } } return null; } private static bool DoorNear(Vector3 p) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) foreach (Component item in WorldScan.All(5f)) { if ((Object)(object)item != (Object)null) { Vector3 val = item.transform.position - p; if (((Vector3)(ref val)).sqrMagnitude < 6.25f) { return true; } } } return false; } internal void WStop() { ((BaseAI)this).StopMoving(); } internal void WLookAt(Vector3 p) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ((BaseAI)this).LookAt(p); } internal void WRandomMove(float dt, Vector3 around, float range) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) ((BaseAI)this).RandomMovementArroundPoint(dt, around, range, false); } internal void WCheckStuck() { CheckStuck(); } public override bool UpdateAI(float dt) { if (!((BaseAI)this).UpdateAI(dt)) { return false; } if ((Object)(object)_villager == (Object)null || (Object)(object)base.m_nview == (Object)null || !base.m_nview.IsOwner()) { return false; } if (!VillagersConfig.Enable.Value) { ((BaseAI)this).StopMoving(); return true; } Safe.Run("VillagerAI.Tick", delegate { Tick(dt); }); return true; } private static bool UnderFloor(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) int num = Physics.RaycastNonAlloc(p + Vector3.up * 0.05f, Vector3.up, UpHits, 1.7f); for (int i = 0; i < num; i++) { Piece val = (((Object)(object)((RaycastHit)(ref UpHits[i])).collider != (Object)null) ? ((Component)((RaycastHit)(ref UpHits[i])).collider).GetComponentInParent() : null); if ((Object)(object)val != (Object)null && Utils.GetPrefabName(((Component)val).gameObject) == "wood_floor" && ((RaycastHit)(ref UpHits[i])).point.y > p.y + 0.12f) { return true; } } return false; } private void OutFromUnderFloor() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)this).transform.position; if (!UnderFloor(position)) { return; } for (float num = 4f; num <= 16f; num += 3f) { for (int i = 0; i < 12; i++) { Vector3 val = position + Quaternion.Euler(0f, (float)i * 30f, 0f) * Vector3.forward * num; val.y = ZoneSystem.instance.GetGroundHeight(val); if (!UnderFloor(val) && !(Mathf.Abs(val.y - position.y) > 3f)) { ((BaseAI)this).StopMoving(); ((Component)this).transform.position = val + Vector3.up * 0.2f; if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)(_villager.VillagerName + " was stuck under a floor; climbed out.")); } return; } } } } private void Tick(float dt) { Safe.Run("AI.Needs", delegate { UpdateNeeds(dt); }); _packTimer += dt; if (_packTimer > 4f) { _packTimer = 0f; Safe.Run("AI.SavePack", _villager.SavePack); } if (Time.time >= _nextThink) { _nextThink = Time.time + 1f; Safe.Run("AI.Decide", Decide); } if (Time.time >= _nextFloorCheck) { _nextFloorCheck = Time.time + 3f; Safe.Run("AI.UnderFloor", OutFromUnderFloor); } Safe.Run("AI.Act", delegate { Act(dt); }); } private void UpdateNeeds(float dt) { _needsTimer += dt; if (_needsTimer < 2f) { return; } double num = (double)_needsTimer / GameApi.DayLengthSeconds; _needsTimer = 0f; ZDO zDO = base.m_nview.GetZDO(); if (_villager.IsWanderer) { zDO.Set("vdyn_hunger", 80f); zDO.Set("vdyn_energy", 80f); zDO.Set("vdyn_happy", 60f); Heal(); return; } float num2 = VillagersConfig.Health.Value + _villager.CombatSkill * 0.5f; if (Mathf.Abs(((Character)_villager).GetMaxHealth() - num2) > 0.5f) { ((Character)_villager).SetMaxHealth(num2); } float num3 = zDO.GetFloat("vdyn_hunger", 100f); float num4 = zDO.GetFloat("vdyn_energy", 100f); num3 -= (float)(num * (double)VillagersConfig.HungerPerDay.Value); num4 = ((_activity == VillagerActivity.Sleeping) ? (num4 + (float)(num * 24.0 * 15.0)) : ((_activity == VillagerActivity.AtFire) ? (num4 + (float)(num * 24.0 * 4.0)) : ((_activity != VillagerActivity.Sheltering) ? (num4 - (float)(num * 70.0)) : (num4 + (float)(num * 24.0 * 5.0))))); zDO.Set("vdyn_hunger", Mathf.Clamp(num3, 0f, 100f)); zDO.Set("vdyn_energy", Mathf.Clamp(num4, 0f, 100f)); UpdateHappiness(zDO, num); Heal(); } private void Heal() { float health = ((Character)_villager).GetHealth(); float maxHealth = ((Character)_villager).GetMaxHealth(); if (_lastHealth >= 0f && health < _lastHealth - 0.01f) { _lastHurt = Time.time; } if (health < maxHealth && !((Character)_villager).IsDead() && Time.time - _lastHurt > 10f && _activity != VillagerActivity.Fighting) { float num = ((_activity == VillagerActivity.Sleeping) ? 3f : ((_activity == VillagerActivity.AtFire || _activity == VillagerActivity.Sheltering) ? 1.5f : 0.4f)); if (_villager.Hunger <= 0f) { num *= 0.25f; } ((Character)_villager).Heal(num * 2f, false); } _lastHealth = ((Character)_villager).GetHealth(); } private void UpdateHappiness(ZDO zdo, double days) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) float num = 30f; float hunger = _villager.Hunger; float energy = _villager.Energy; num += ((hunger > 50f) ? 20f : ((hunger > 20f) ? 8f : (-12f))); num += ((energy > 50f) ? 10f : ((energy < 15f) ? (-10f) : 0f)); num += ((VillagerCharacter.BedId(zdo) != ZDOID.None) ? 15f : (-5f)); num += (((Object)(object)VillagerPlaces.NearestBurningFire(_villager.Home, VillagersConfig.HomeRadius.Value) != (Object)null) ? 10f : 0f); num += ((_villager.IsArmed || _villager.Job == VillagerJob.Gatherer) ? 5f : 0f); num += (((Object)(object)VillageAlarm.Near(_villager.Home, VillagersConfig.HomeRadius.Value) != (Object)null) ? (-15f) : 5f); num += ((_villager.HealthPercent < 50f) ? (-10f) : 0f); VillageInfo villageInfo = (string.IsNullOrEmpty(_villager.CampId) ? VillageInfo.At(_villager.Home) : null); if (villageInfo != null) { num += QuestNet.TaxRateOf(villageInfo.Id) switch { 2 => -12f, 0 => 5f, _ => 0f, }; if (QuestSim.Joyful(villageInfo.Id)) { num += 15f; } } num = Mathf.Clamp(num, 0f, 100f); float num2 = zdo.GetFloat("vdyn_happy", 60f); float num3 = (float)(days * 24.0 * 8.0); num2 = Mathf.MoveTowards(num2, num, num3); zdo.Set("vdyn_happy", num2); } private void EatMeal() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) string text = Village.TakeFood(_villager, _villager.Home, VillagersConfig.HomeRadius.Value); float num = base.m_nview.GetZDO().GetFloat("vdyn_hunger", 100f); base.m_nview.GetZDO().Set("vdyn_hunger", (text != null) ? 100f : Mathf.Min(100f, num + 30f)); if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)((text != null) ? ("Villager " + _villager.VillagerName + " ate " + text + " from the stores.") : ("Villager " + _villager.VillagerName + " found no food in the stores."))); } } private void Decide() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Invalid comparison between Unknown and I4 //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_03f5: Unknown result type (might be due to invalid IL or missing references) //IL_03fa: Unknown result type (might be due to invalid IL or missing references) //IL_0495: Unknown result type (might be due to invalid IL or missing references) //IL_049e: Unknown result type (might be due to invalid IL or missing references) //IL_06f8: Unknown result type (might be due to invalid IL or missing references) //IL_0760: Unknown result type (might be due to invalid IL or missing references) //IL_071f: Unknown result type (might be due to invalid IL or missing references) //IL_0855: Unknown result type (might be due to invalid IL or missing references) //IL_0856: Unknown result type (might be due to invalid IL or missing references) //IL_07bc: Unknown result type (might be due to invalid IL or missing references) //IL_0770: Unknown result type (might be due to invalid IL or missing references) //IL_07e2: Unknown result type (might be due to invalid IL or missing references) //IL_07e7: Unknown result type (might be due to invalid IL or missing references) //IL_07ec: Unknown result type (might be due to invalid IL or missing references) //IL_07ef: Unknown result type (might be due to invalid IL or missing references) //IL_07a3: Unknown result type (might be due to invalid IL or missing references) //IL_07a8: Unknown result type (might be due to invalid IL or missing references) //IL_074e: Unknown result type (might be due to invalid IL or missing references) //IL_0753: Unknown result type (might be due to invalid IL or missing references) //IL_0846: Unknown result type (might be due to invalid IL or missing references) //IL_0847: Unknown result type (might be due to invalid IL or missing references) //IL_078e: Unknown result type (might be due to invalid IL or missing references) //IL_078f: Unknown result type (might be due to invalid IL or missing references) //IL_05e8: Unknown result type (might be due to invalid IL or missing references) //IL_0690: Unknown result type (might be due to invalid IL or missing references) //IL_0698: Unknown result type (might be due to invalid IL or missing references) //IL_060b: Unknown result type (might be due to invalid IL or missing references) //IL_0610: Unknown result type (might be due to invalid IL or missing references) //IL_0615: Unknown result type (might be due to invalid IL or missing references) //IL_0618: Unknown result type (might be due to invalid IL or missing references) //IL_0832: Unknown result type (might be due to invalid IL or missing references) //IL_0834: Unknown result type (might be due to invalid IL or missing references) //IL_066f: Unknown result type (might be due to invalid IL or missing references) //IL_0671: Unknown result type (might be due to invalid IL or missing references) if (Wanderer.TalkingTo(_villager) != 0L) { SetActivity(VillagerActivity.Idle); _target = ((Component)this).transform.position; Player closestPlayer = Player.GetClosestPlayer(((Component)this).transform.position, 12f); if ((Object)(object)closestPlayer != (Object)null) { ((BaseAI)this).LookAt(((Character)closestPlayer).GetHeadPoint()); } return; } if (_villager.IsWanderer) { DecideWanderer(); return; } Vector3 home = _villager.Home; float value = VillagersConfig.HomeRadius.Value; Character seen = null; Safe.Run("AI.FindEnemy", delegate { seen = ((BaseAI)this).FindEnemy(); }); if ((Object)(object)seen != (Object)null && (seen.IsDead() || (Object)(object)((Component)seen).GetComponent() == (Object)null || (int)seen.m_faction == 1)) { seen = null; } if ((Object)(object)seen != (Object)null && Vector3.Distance(((Component)seen).transform.position, ((Component)this).transform.position) < VillagersConfig.AlarmRange.Value) { VillageAlarm.Raise(seen, ((Component)seen).transform.position, _villager.VillagerName); if (!string.IsNullOrEmpty(_villager.CampId)) { CampMaterializer.AskForHelp(_villager); } } Character val = seen ?? VillageAlarm.Near(home, value); if ((Object)(object)val != (Object)null) { _lastThreatTime = Time.time; } else if ((_activity == VillagerActivity.Fighting || _activity == VillagerActivity.Fleeing) && (Object)(object)_enemy != (Object)null && !_enemy.IsDead() && Time.time - _lastThreatTime < 6f && Vector3.Distance(((Component)_enemy).transform.position, home) < value * 1.5f) { val = _enemy; } if ((Object)(object)val != (Object)null && _villager.Job != VillagerJob.Guard) { MonsterAI component = ((Component)val).GetComponent(); bool num = (Object)(object)component != (Object)null && (Object)(object)((BaseAI)component).GetTargetCreature() == (Object)(object)_villager; bool flag = Time.time - _lastHurt < 8f; bool flag2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) < 4f; bool flag3 = _activity == VillagerActivity.Fighting && (Object)(object)_enemy == (Object)(object)val; if (!num && !flag && !flag2 && !flag3) { val = null; } } if ((Object)(object)val != (Object)null) { float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position); float num3 = Vector3.Distance(((Component)val).transform.position, home); float num4 = VillagersConfig.RetreatHealthPercent.Value + ((_activity == VillagerActivity.Fleeing) ? 25f : 0f); bool flag4 = _villager.HealthPercent > num4; bool flag5 = num3 < value * 1.5f; _reason = $"threat {val.m_name} {num2:0} m away, armed {_villager.IsArmed}, health {_villager.HealthPercent:0}%"; bool flag6 = val.GetMaxHealth() <= 60f; if (VillagersConfig.FightBack.Value && (_villager.IsArmed || flag6) && flag4 && flag5) { _enemy = val; SetActivity(VillagerActivity.Fighting); return; } bool flag7 = num3 < value; if (num2 < VillagersConfig.FleeDistance.Value || (!_villager.IsArmed && flag7) || (!flag4 && num2 < value)) { _enemy = val; SetActivity(VillagerActivity.Fleeing); _target = ((Component)val).transform.position; return; } } _enemy = null; if ((Object)(object)_bed == (Object)null && Time.time >= _nextBedLook) { _nextBedLook = Time.time + 8f; _bed = ClaimBed(home, value); } bool flag8 = EnvMan.IsNight(); float num5 = (((Object)(object)EnvMan.instance != (Object)null) ? EnvMan.instance.GetDayFraction() : 0.5f); bool flag9 = !flag8 && num5 >= 0.66f; bool flag10 = EnvMan.IsWet() || EnvMan.IsFreezing() || EnvMan.IsCold(); List list = VillagerPlaces.BedsNear(home, value); Fireplace val2 = VillagerPlaces.NearestBurningFire(home, value); _reason = string.Format("night {0}, evening {1}, weather {2}, beds {3}, fire {4}, day {5:0.00}", flag8, flag9, flag10, list.Count, ((Object)(object)val2 != (Object)null) ? "burning" : "none", num5); _exhausted = _villager.Energy < 10f || (_exhausted && _villager.Energy < 60f); bool exhausted = _exhausted; if (VillagersConfig.EnableWork.Value) { bool flag11 = !flag8 && !flag9 && !EnvMan.IsFreezing() && !exhausted; if (flag11 && _activity == VillagerActivity.Working && _worker.IdleFor > 15f && Time.time > _breakEnd && !_worker.BuildPending) { _breakEnd = Time.time + 90f; _breakReason = _villager.Task; } if (flag11 && Time.time < _breakEnd) { Fireplace val3 = VillagerPlaces.NearestBurningFire(home, value); if ((Object)(object)val3 != (Object)null) { _fire = val3; Vector3 val4 = SeatAt(((Component)val3).transform.position); bool flag12 = Close(val4, 1.2f) || _activity == VillagerActivity.AtFire; _onBreak = true; SetActivity(flag12 ? VillagerActivity.AtFire : VillagerActivity.GoingToFire); _villager.SetTask("Taking a break (" + _breakReason.ToLowerInvariant() + ")"); _target = val4; return; } } _onBreak = false; bool flag13 = !flag11 && _worker.Carrying > 0 && (Object)(object)Village.ChestWithRoom(home, value, ((Component)this).transform.position) != (Object)null; if (flag11 || flag13) { SetActivity(VillagerActivity.Working); bool depositOnly = !flag11; Safe.Run("AI.Think", delegate { _worker.Think(depositOnly); }); return; } } if (flag8 || exhausted) { _bed = ClaimBed(home, value); if ((Object)(object)_bed != (Object)null) { SetActivity((Close(((Component)_bed).transform.position, 1.6f) || _activity == VillagerActivity.Sleeping) ? VillagerActivity.Sleeping : VillagerActivity.GoingToBed); _target = ((Component)_bed).transform.position; return; } } if ((flag8 || exhausted) && (Object)(object)VillagerPlaces.NearestBurningFire(home, value) == (Object)null) { if (!Close(home, 6f) && _activity != VillagerActivity.Sheltering) { SetActivity(VillagerActivity.Idle); _target = home; } else { SetActivity(VillagerActivity.Sheltering); _target = ((Component)this).transform.position; } return; } if (flag8 || flag9 || flag10) { _fire = VillagerPlaces.NearestBurningFire(home, value); if ((Object)(object)_fire != (Object)null) { Vector3 val5 = SeatAt(((Component)_fire).transform.position); bool flag14 = Close(val5, 1.2f) || _activity == VillagerActivity.AtFire || _activity == VillagerActivity.Sheltering; SetActivity((!flag14) ? VillagerActivity.GoingToFire : ((flag10 && !flag9 && !flag8) ? VillagerActivity.Sheltering : VillagerActivity.AtFire)); _target = val5; return; } if (flag8) { SetActivity(VillagerActivity.Idle); _target = home; return; } } SetActivity(VillagerActivity.Wandering); _target = home; } private void DecideWanderer() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Invalid comparison between Unknown and I4 //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0351: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) ZDO zDO = base.m_nview.GetZDO(); Character val = ((BaseAI)this).FindEnemy(); if ((Object)(object)(string.IsNullOrEmpty(QuestWorld.LostQuest(_villager)) ? null : QuestWorld.FollowTarget(_villager)) != (Object)null && (Object)(object)val != (Object)null && Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) > 2.5f) { val = null; } if ((Object)(object)val != (Object)null && !val.IsDead() && (Object)(object)((Component)val).GetComponent() != (Object)null && (int)val.m_faction != 1 && Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) < VillagersConfig.FleeDistance.Value) { _enemy = val; bool flag = _villager.IsArmed && _villager.HealthPercent > 50f && val.GetMaxHealth() <= 60f; SetActivity(flag ? VillagerActivity.Fighting : VillagerActivity.Fleeing); _target = ((Component)val).transform.position; return; } _enemy = null; _following = false; if (!string.IsNullOrEmpty(QuestWorld.LostQuest(_villager))) { Player val2 = QuestWorld.FollowTarget(_villager); if ((Object)(object)val2 != (Object)null && Vector3.Distance(((Component)val2).transform.position, ((Component)this).transform.position) > 3.5f) { _following = true; _reason = "following " + val2.GetPlayerName(); SetActivity(VillagerActivity.Idle); _target = ((Component)val2).transform.position; return; } SetActivity((!((Object)(object)val2 != (Object)null)) ? VillagerActivity.Sheltering : VillagerActivity.Idle); _target = ((Component)this).transform.position; if ((Object)(object)val2 != (Object)null) { ((BaseAI)this).LookAt(((Character)val2).GetHeadPoint()); } return; } Player closestPlayer = Player.GetClosestPlayer(((Component)this).transform.position, 6f); if (Wanderer.TalkingTo(_villager) != 0L || (Object)(object)closestPlayer != (Object)null) { SetActivity(VillagerActivity.Idle); _target = ((Component)this).transform.position; if ((Object)(object)closestPlayer != (Object)null) { ((BaseAI)this).LookAt(((Character)closestPlayer).GetHeadPoint()); } return; } if (EnvMan.IsNight() || ((Object)(object)EnvMan.instance != (Object)null && EnvMan.instance.GetDayFraction() >= 0.7f)) { SetActivity(VillagerActivity.Sheltering); _target = ((Component)this).transform.position; return; } Vector3 val3 = zDO.GetVec3("vdyn_dest", Vector3.zero); if (val3 == Vector3.zero || Close(val3, 5f) || Time.time - _destPicked > 240f) { for (int i = 0; i < 12; i++) { Vector3 val4 = ((Component)this).transform.position + Quaternion.Euler(0f, Random.Range(0f, 360f), 0f) * Vector3.forward * Random.Range(60f, 140f); if (WandererSpawner.GoodSpot(val4)) { val4.y = ZoneSystem.instance.GetGroundHeight(val4); val3 = val4; zDO.Set("vdyn_dest", val3); zDO.Set("vdyn_home", val3); _destPicked = Time.time; break; } } } _reason = "travelling"; SetActivity(VillagerActivity.Idle); _target = ((val3 == Vector3.zero) ? ((Component)this).transform.position : val3); } private Bed ClaimBed(Vector3 home, float range) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) ZDO zDO = base.m_nview.GetZDO(); ZDOID val = VillagerCharacter.BedId(zDO); if (val != ZDOID.None && (Object)(object)ZNetScene.instance != (Object)null) { GameObject val2 = ZNetScene.instance.FindInstance(val); Bed val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent() : null); if ((Object)(object)val3 != (Object)null && !VillagerPlaces.PlayersOwn(val3)) { return val3; } } foreach (Bed item in VillagerPlaces.BedsNear(home, range)) { ZNetView component = ((Component)item).GetComponent(); if (!((Object)(object)component == (Object)null) && component.IsValid()) { ZDOID uid = component.GetZDO().m_uid; if (!BedTakenByOther(uid) && !VillagerPlaces.PlayersOwn(item)) { VillagerCharacter.SetBed(zDO, item); return item; } } } return null; } private bool BedTakenByOther(ZDOID bed) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) foreach (VillagerCharacter item in VillagerCharacter.All) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item == (Object)(object)_villager)) { ZNetView component = ((Component)item).GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid() && VillagerCharacter.BedId(component.GetZDO()) == bed) { return true; } } } return false; } private Vector3 SeatAt(Vector3 fire) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) float num = (float)(Mathf.Abs(((object)Unsafe.As(ref base.m_nview.GetZDO().m_uid)/*cast due to .constrained prefix*/).GetHashCode()) % 8) * (float)Math.PI * 2f / 8f; return fire + new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * 2.2f; } private void SetActivity(VillagerActivity a) { //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) if (a == _activity) { return; } if ((a == VillagerActivity.GoingToBed || a == VillagerActivity.GoingToFire) && (_activity == VillagerActivity.Working || _activity == VillagerActivity.Wandering || _activity == VillagerActivity.Idle)) { if (_wantActivity != a) { _wantActivity = a; _wantSince = Time.time; return; } if (Time.time - _wantSince < PersonalDelay) { return; } } _wantActivity = VillagerActivity.Idle; VillagerActivity activity = _activity; if (activity == VillagerActivity.Fighting) { if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)$"Villager {_villager.VillagerName}: swung {_swingsMade} times ({_swingsTried} tries), health {_villager.HealthPercent:0}%."); } _swingsTried = (_swingsMade = 0); } if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)$"Villager {_villager.VillagerName}: {activity} -> {a} ({_reason})"); } _activity = a; if (_attached && a != VillagerActivity.Sleeping && a != VillagerActivity.AtFire && a != VillagerActivity.Sheltering) { Detach(); } if (activity != VillagerActivity.AtFire && a == VillagerActivity.AtFire && !_onBreak) { EatMeal(); } base.m_nview.GetZDO().Set("vdyn_activity", (int)a); if (activity == VillagerActivity.Working) { _worker.Reset(); _villager.SetTask(""); } _stuckCount = 0; _stuckCheckTime = Time.time; _stuckCheckPos = ((Component)this).transform.position; } private void Act(float dt) { //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) if (_activity == VillagerActivity.Fleeing || _activity == VillagerActivity.Fighting) { ((Character)_villager).SetWalk(false); } switch (_activity) { case VillagerActivity.Fleeing: Detach(); HandleDoors(); RunToSafety(dt); return; case VillagerActivity.Fighting: Detach(); HandleDoors(); Fight(dt); return; case VillagerActivity.Sleeping: if ((Object)(object)_bed == (Object)null) { _nextThink = 0f; return; } if (!_attached) { Attach(((Object)(object)_bed.m_spawnPoint != (Object)null) ? _bed.m_spawnPoint : ((Component)_bed).transform, "attach_bed"); } HoldAttached(); return; case VillagerActivity.AtFire: case VillagerActivity.Sheltering: if (!_attached) { ((BaseAI)this).StopMoving(); if ((Object)(object)_fire != (Object)null) { ((BaseAI)this).LookAt(((Component)_fire).transform.position); } Attach(null, "emote_sit"); } HoldAttached(); return; case VillagerActivity.GoingToFire: case VillagerActivity.GoingToBed: Detach(); HandleDoors(); if (SmartMove(dt, _target, 0.8f, run: false)) { _nextThink = 0f; } CheckStuck(); return; case VillagerActivity.Working: Detach(); HandleDoors(); _worker.Act(dt); return; case VillagerActivity.Wandering: Detach(); if (Time.time > _nextStroll || _strollTo == Vector3.zero) { _nextStroll = Time.time + Random.Range(10f, 22f); for (int i = 0; i < 6; i++) { Vector3 val = _villager.Home + Quaternion.Euler(0f, Random.Range(0f, 360f), 0f) * Vector3.forward * Random.Range(3f, VillagersConfig.WanderRadius.Value); val.y = ZoneSystem.instance.GetGroundHeight(val); if (!AroundFire(val, val + Vector3.forward * 0.01f).HasValue) { _strollTo = val; break; } } } if (_strollTo != Vector3.zero) { SmartMove(dt, _strollTo, 1f, run: false); } return; } Detach(); if (!Close(_target, 3f)) { SmartMove(dt, _target, 2f, _following && !Close(_target, 8f)); if (_following) { CheckStuck(); } } else { ((BaseAI)this).StopMoving(); } } private void Fight(float dt) { //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_enemy == (Object)null || _enemy.IsDead()) { if ((Object)(object)_enemy != (Object)null && DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)("Villager " + _villager.VillagerName + ": enemy down.")); } _enemy = null; ((BaseAI)this).StopMoving(); _nextThink = 0f; return; } ItemData currentWeapon = ((Humanoid)_villager).GetCurrentWeapon(); float num = ((currentWeapon != null && currentWeapon.m_shared.m_aiAttackRange > 0f) ? currentWeapon.m_shared.m_aiAttackRange : 2f); num = Mathf.Clamp(num, 1.5f, 3f); Vector3 position = ((Component)_enemy).transform.position; float num2 = Vector3.Distance(((Component)this).transform.position, position); if (num2 > num * 0.75f) { ((BaseAI)this).MoveTo(dt, position, num * 0.6f, true); } else { ((BaseAI)this).StopMoving(); } if (num2 > num + 0.5f) { return; } ((BaseAI)this).LookAt(_enemy.GetCenterPoint()); Vector3 val = position - ((Component)this).transform.position; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude > 0.01f) { ((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(val), 720f * dt); } if ((((Vector3)(ref val)).sqrMagnitude < 0.01f || Vector3.Angle(((Component)this).transform.forward, val) < 45f) && Time.time >= _nextAttack && !((Character)_villager).InAttack()) { _swingsTried++; if (((Character)_villager).StartAttack(_enemy, false)) { _swingsMade++; _villager.WearWeapon(); float num3 = ((currentWeapon != null && currentWeapon.m_shared.m_aiAttackInterval > 0f) ? currentWeapon.m_shared.m_aiAttackInterval : 1.5f); float num4 = Mathf.Lerp(1.8f, 1f, _villager.CombatSkill / 100f); _nextAttack = Time.time + Mathf.Max(1f, num3) * num4; _villager.AddSkill(0.5f); } } } private void RunToSafety(float dt) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (((Object)(object)_enemy != (Object)null) ? ((Component)_enemy).transform.position : _target); Vector3 val2 = (((Object)(object)_bed != (Object)null) ? ((Component)_bed).transform.position : _villager.Home); if (Vector3.Distance(val2, val) > 10f && !Close(val2, 2f)) { ((BaseAI)this).MoveTo(dt, val2, 1.5f, true); CheckStuck(); } else if (Vector3.Distance(((Component)this).transform.position, val) < VillagersConfig.FleeDistance.Value) { ((BaseAI)this).Flee(dt, val); } else { ((BaseAI)this).StopMoving(); } } private void HandleDoors() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) CloseDoorsBehind(); if (Time.time < _nextDoorCheck) { return; } _nextDoorCheck = Time.time + 0.4f; int num = Physics.OverlapSphereNonAlloc(((Component)this).transform.position + ((Component)this).transform.forward * 1f + Vector3.up, 1.3f, DoorHits, -1, (QueryTriggerInteraction)1); for (int i = 0; i < num; i++) { Door door = (((Object)(object)DoorHits[i] != (Object)null) ? ((Component)DoorHits[i]).GetComponentInParent() : null); if ((Object)(object)door == (Object)null || (Object)(object)door.m_keyItem != (Object)null) { continue; } ZNetView component = ((Component)door).GetComponent(); if (!((Object)(object)component == (Object)null) && component.IsValid() && component.GetZDO().GetInt("state", 0) == 0) { component.ClaimOwnership(); bool flag = Vector3.Dot(((Component)door).transform.forward, ((Component)this).transform.position - ((Component)door).transform.position) < 0f; component.GetZDO().Set("state", flag ? 1 : (-1)); Safe.Run("Villager.DoorFx", delegate { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) door.m_openEffects.Create(((Component)door).transform.position, ((Component)door).transform.rotation, (Transform)null, 1f, -1, default(ZDOID)); }); _openedDoors.Add(new KeyValuePair(door, Time.time)); } } } private void CloseDoorsBehind() { //IL_007e: Unknown result type (might be due to invalid IL or missing references) for (int num = _openedDoors.Count - 1; num >= 0; num--) { Door door = _openedDoors[num].Key; if ((Object)(object)door == (Object)null) { _openedDoors.RemoveAt(num); } else if (!(Time.time - _openedDoors[num].Value < 5f) && !SomeoneNear(((Component)door).transform.position, 3f)) { ZNetView component = ((Component)door).GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid()) { component.ClaimOwnership(); component.GetZDO().Set("state", 0); Safe.Run("Villager.DoorFx", delegate { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) door.m_closeEffects.Create(((Component)door).transform.position, ((Component)door).transform.rotation, (Transform)null, 1f, -1, default(ZDOID)); }); } _openedDoors.RemoveAt(num); } } } private static bool SomeoneNear(Vector3 p, float d) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) Vector3 val; foreach (VillagerCharacter item in VillagerCharacter.All) { if ((Object)(object)item != (Object)null) { val = ((Component)item).transform.position - p; if (((Vector3)(ref val)).sqrMagnitude < d * d) { return true; } } } foreach (Player allPlayer in Player.GetAllPlayers()) { if ((Object)(object)allPlayer != (Object)null) { val = ((Component)allPlayer).transform.position - p; if (((Vector3)(ref val)).sqrMagnitude < d * d) { return true; } } } return false; } private void Attach(Transform point, string anim) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)point != (Object)null) { ((Component)this).transform.position = point.position; ((Component)this).transform.rotation = point.rotation; } if ((Object)(object)_rb != (Object)null) { _savedConstraints = _rb.constraints; _rb.constraints = (RigidbodyConstraints)126; } ZSyncAnimation animator = base.m_animator; if (animator != null) { animator.SetBool(anim, true); } _attachAnim = anim; _attached = true; } private void HoldAttached() { ((BaseAI)this).StopMoving(); } private void Detach() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) if (!_attached) { return; } if (_attachAnim != null) { ZSyncAnimation animator = base.m_animator; if (animator != null) { animator.SetBool(_attachAnim, false); } } if ((Object)(object)_rb != (Object)null) { _rb.constraints = _savedConstraints; } if (_attachAnim == "attach_bed") { Transform transform = ((Component)this).transform; transform.position += ((Component)this).transform.forward * 0.6f + Vector3.up * 0.3f; } _attached = false; _attachAnim = null; } private void CheckStuck() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) if (Time.time - _stuckCheckTime < 6f) { return; } float num = Vector3.Distance(((Component)this).transform.position, _stuckCheckPos); _stuckCheckTime = Time.time; _stuckCheckPos = ((Component)this).transform.position; if (num > 0.6f) { _stuckCount = 0; return; } _stuckCount++; if (_stuckCount >= 3 && Vector3.Distance(((Component)this).transform.position, _target) < 30f) { if (DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)(_villager.VillagerName + " was stuck; moving them to their destination.")); } ((Component)this).transform.position = _target + Vector3.up * 0.2f; _stuckCount = 0; } } private bool Close(Vector3 p, float d) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)this).transform.position - p; return ((Vector3)(ref val)).sqrMagnitude < d * d; } internal string Describe() { //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) return $"{_villager.VillagerName}: {_activity}, health {((Character)_villager).GetHealth():0}/{((Character)_villager).GetMaxHealth():0}, armed {_villager.IsArmed}, skill {_villager.CombatSkill:0}, hunger {_villager.Hunger:0}%, energy {_villager.Energy:0}%, " + string.Format("bed {0}, {1:0} m from home, job {2}, work {3}", ((Object)(object)_bed != (Object)null) ? "yes" : "no", Vector3.Distance(((Component)this).transform.position, _villager.Home), _villager.Job, _worker.Describe()); } } internal enum VillagerActivity { Idle, Wandering, GoingToFire, AtFire, GoingToBed, Sleeping, Sheltering, Fleeing, Fighting, Working } internal enum VillagerJob { Gatherer, Woodcutter, Miner, Hunter, Guard, Farmer, Cook } public class VillagerCharacter : Humanoid, Interactable { internal const string KName = "vdyn_name"; internal const string KFemale = "vdyn_female"; internal const string KHair = "vdyn_hair"; internal const string KBeard = "vdyn_beard"; internal const string KSkin = "vdyn_skin"; internal const string KHairColor = "vdyn_haircolor"; internal const string KHome = "vdyn_home"; internal const string KHunger = "vdyn_hunger"; internal const string KEnergy = "vdyn_energy"; internal const string KBed = "vdyn_bed"; internal const string KActivity = "vdyn_activity"; internal const string KInit = "vdyn_init"; internal const string KBedPos = "vdyn_bedpos"; internal const string KSkill = "vdyn_skill"; internal const string KGear = "vdyn_gear"; internal const string KJob = "vdyn_job"; internal const string KTask = "vdyn_task"; public static readonly List All = new List(); private float _lastTalk; private static readonly FieldInfo LastHitField = AccessTools.Field(typeof(Character), "m_lastHit"); internal const string KPack = "vdyn_pack"; internal const string KHappy = "vdyn_happy"; internal VillagerJob Job { get { ZDO zdo = Zdo; if (zdo == null) { return VillagerJob.Gatherer; } return (VillagerJob)zdo.GetInt("vdyn_job", 0); } } public string Task { get { ZDO zdo = Zdo; return ((zdo != null) ? zdo.GetString("vdyn_task", "") : null) ?? ""; } } public float CombatSkill { get { ZDO zdo = Zdo; if (zdo == null) { return 0f; } return zdo.GetFloat("vdyn_skill", 0f); } } public bool IsArmed { get { ItemData currentWeapon = ((Humanoid)this).GetCurrentWeapon(); if (currentWeapon == null || !IsWeapon(currentWeapon)) { return false; } if (!((Object)(object)base.m_unarmedWeapon == (Object)null)) { return currentWeapon != base.m_unarmedWeapon.m_itemData; } return true; } } public float HealthPercent { get { if (!(((Character)this).GetMaxHealth() > 0f)) { return 100f; } return ((Character)this).GetHealth() / ((Character)this).GetMaxHealth() * 100f; } } private ZDO Zdo { get { if (!((Object)(object)((Character)this).m_nview != (Object)null) || !((Character)this).m_nview.IsValid()) { return null; } return ((Character)this).m_nview.GetZDO(); } } internal ZDO Zdo2 => Zdo; public bool IsWanderer { get { if (Zdo != null) { return Zdo.GetBool("vdyn_wanderer", false); } return false; } } public string CampId { get { if (Zdo == null) { return ""; } return Zdo.GetString("vdyn_camp", ""); } } public string VillagerName { get { ZDO zdo = Zdo; return ((zdo != null) ? zdo.GetString("vdyn_name", "Villager") : null) ?? "Villager"; } } public bool IsFemale { get { if (Zdo != null) { return Zdo.GetBool("vdyn_female", false); } return false; } } public Vector3 Home { get { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (Zdo == null) { return ((Component)this).transform.position; } return Zdo.GetVec3("vdyn_home", ((Component)this).transform.position); } } internal VillagerActivity Activity { get { ZDO zdo = Zdo; if (zdo == null) { return VillagerActivity.Idle; } return (VillagerActivity)zdo.GetInt("vdyn_activity", 0); } } public float Hunger { get { ZDO zdo = Zdo; if (zdo == null) { return 100f; } return zdo.GetFloat("vdyn_hunger", 100f); } } public float Energy { get { ZDO zdo = Zdo; if (zdo == null) { return 100f; } return zdo.GetFloat("vdyn_energy", 100f); } } public float Happiness { get { ZDO zdo = Zdo; if (zdo == null) { return 60f; } return zdo.GetFloat("vdyn_happy", 60f); } } public float WorkSpeed => Mathf.Lerp(0.6f, 1.25f, Happiness / 100f); internal static void SetBed(ZDO zdo, Bed bed) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) ZNetView val = (((Object)(object)bed != (Object)null) ? ((Component)bed).GetComponent() : null); if ((Object)(object)val == (Object)null || !val.IsValid()) { zdo.Set("vdyn_bed", ZDOID.None); zdo.Set("vdyn_bedpos", Vector3.zero); } else { zdo.Set("vdyn_bed", val.GetZDO().m_uid); zdo.Set("vdyn_bedpos", ((Component)bed).transform.position); } } internal static ZDOID BedId(ZDO zdo) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) if (zdo == null) { return ZDOID.None; } ZDOID zDOID = zdo.GetZDOID("vdyn_bed"); if (zDOID != ZDOID.None && (Object)(object)ZNetScene.instance != (Object)null && (Object)(object)ZNetScene.instance.FindInstance(zDOID) != (Object)null) { return zDOID; } Vector3 vec = zdo.GetVec3("vdyn_bedpos", Vector3.zero); if (vec == Vector3.zero) { return ZDOID.None; } foreach (Bed item in VillagerPlaces.BedsNear(vec, 0.6f)) { ZNetView component = ((Component)item).GetComponent(); if (!((Object)(object)component == (Object)null) && component.IsValid()) { ZDOID uid = component.GetZDO().m_uid; if (zdo.IsOwner()) { zdo.Set("vdyn_bed", uid); } return uid; } } return ZDOID.None; } internal void SetJob(VillagerJob job) { if (Zdo != null) { ((Character)this).m_nview.ClaimOwnership(); Zdo.Set("vdyn_job", (int)job); Zdo.Set("vdyn_task", ""); } } internal void SetTask(string task) { if (Zdo != null && ((Character)this).m_nview.IsOwner() && Zdo.GetString("vdyn_task", "") != task) { Zdo.Set("vdyn_task", task); } } internal static string JobName(VillagerJob j) { return j.ToString(); } protected override void Awake() { ((Humanoid)this).Awake(); All.Add(this); } protected override void Start() { ((Humanoid)this).Start(); if (!((Object)(object)((Character)this).m_nview == (Object)null) && ((Character)this).m_nview.IsValid() && ((Character)this).m_nview.IsOwner()) { Safe.Run("Villager.Init", InitIdentity); Safe.Run("Villager.RestoreGear", RestoreGear); Safe.Run("Villager.RestorePack", RestorePack); } } private string DeathCause() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) HitData val = (HitData)((LastHitField != null) ? /*isinst with value type is only supported in some contexts*/: null); if (val == null) { return " (no hit recorded)"; } Character attacker = val.GetAttacker(); DamageTypes damage = val.m_damage; StringBuilder stringBuilder = new StringBuilder(" (last hit"); stringBuilder.Append(((Object)(object)attacker != (Object)null) ? (" by " + Utils.GetPrefabName(((Component)attacker).gameObject)) : " by nobody"); stringBuilder.Append($": {val.GetTotalDamage():0} total, type {val.m_hitType}"); if (damage.m_blunt > 0f) { stringBuilder.Append($", blunt {damage.m_blunt:0}"); } if (damage.m_slash > 0f) { stringBuilder.Append($", slash {damage.m_slash:0}"); } if (damage.m_pierce > 0f) { stringBuilder.Append($", pierce {damage.m_pierce:0}"); } if (damage.m_fire > 0f) { stringBuilder.Append($", fire {damage.m_fire:0}"); } if (damage.m_damage > 0f) { stringBuilder.Append($", plain {damage.m_damage:0}"); } if (damage.m_poison > 0f) { stringBuilder.Append($", poison {damage.m_poison:0}"); } stringBuilder.Append($"; health was {((Character)this).GetMaxHealth():0} max)"); return stringBuilder.ToString(); } public override void OnDeath() { //IL_0060: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)((Character)this).m_nview != (Object)null && ((Character)this).m_nview.IsValid() && ((Character)this).m_nview.IsOwner()) { string name = VillagerName; DynastyPlugin.Log.LogInfo((object)string.Format("Villager {0} died at {1}{2}.", name, ((Component)this).transform.position, Safe.Get("Villager.DeathCause", DeathCause, ""))); if (!string.IsNullOrEmpty(CampId)) { VillageNet.CampLosePerson(CampId); } Safe.Run("Villager.DeathMessage", delegate { //IL_000b: Unknown result type (might be due to invalid IL or missing references) Player.MessageAllInRange(((Component)this).transform.position, 100f, (MessageType)2, name + " has died.", (Sprite)null); }); Safe.Run("Villager.DropGear", DropGear); } ((Character)this).OnDeath(); } private void DropGear() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) foreach (ItemData item in new List(((Humanoid)this).GetInventory().GetAllItems())) { if (!((Object)(object)item.m_dropPrefab == (Object)null) && IsGear(item) && !IsDefaultClothing(item)) { ItemDrop.DropItem(item, item.m_stack, ((Component)this).transform.position + Vector3.up, Quaternion.identity); } } } internal void AddSkill(float amount) { if (Zdo != null && ((Character)this).m_nview.IsOwner()) { Zdo.Set("vdyn_skill", Mathf.Clamp(CombatSkill + amount, 0f, 100f)); } } internal static bool IsWeapon(ItemData item) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Invalid comparison between Unknown and I4 //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 if (item == null || item.m_shared == null) { return false; } ItemType itemType = item.m_shared.m_itemType; if ((int)itemType != 3 && (int)itemType != 14) { return (int)itemType == 22; } return true; } internal static bool IsKeptGear(ItemData item) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Invalid comparison between Unknown and I4 //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Invalid comparison between Unknown and I4 //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Invalid comparison between Unknown and I4 //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Invalid comparison between Unknown and I4 if (item == null || item.m_shared == null) { return false; } ItemType itemType = item.m_shared.m_itemType; if (!IsGear(item) && (int)itemType != 4 && (int)itemType != 9 && (int)itemType != 19) { return (int)itemType == 15; } return true; } internal void SaveGearPublic() { SaveGear(); } internal void SavePack() { if (Zdo == null || !((Character)this).m_nview.IsOwner()) { return; } List list = new List(); foreach (ItemData allItem in ((Humanoid)this).GetInventory().GetAllItems()) { if (!allItem.m_equipped && (Object)(object)allItem.m_dropPrefab != (Object)null) { list.Add(((Object)allItem.m_dropPrefab).name + ":" + allItem.m_stack + ":" + allItem.m_quality + ":" + allItem.m_durability.ToString("0.#", CultureInfo.InvariantCulture)); } } string text = string.Join(";", list.ToArray()); if (Zdo.GetString("vdyn_pack", "") != text) { Zdo.Set("vdyn_pack", text); } } private void RestorePack() { string text = Zdo.GetString("vdyn_pack", ""); if (string.IsNullOrEmpty(text) || (Object)(object)ObjectDB.instance == (Object)null) { return; } int num = 0; string[] array = text.Split(new char[1] { ';' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }); if (array2.Length < 2) { continue; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(array2[0]); if (!((Object)(object)itemPrefab == (Object)null) && int.TryParse(array2[1], out var result) && result > 0) { ItemData val = itemPrefab.GetComponent().m_itemData.Clone(); val.m_dropPrefab = itemPrefab; val.m_stack = result; if (array2.Length > 2 && int.TryParse(array2[2], out var result2)) { val.m_quality = result2; } val.m_durability = val.GetMaxDurability(); if (array2.Length > 3 && float.TryParse(array2[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3)) { val.m_durability = result3; } if (((Humanoid)this).GetInventory().AddItem(val)) { num += result; } } } if (num > 0 && DynastyPlugin.VerboseOn) { DynastyPlugin.Log.LogInfo((object)$"Villager {VillagerName}: restored {num} carried item(s)."); } } private static bool IsGear(ItemData item) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Invalid comparison between Unknown and I4 //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Invalid comparison between Unknown and I4 if (item == null || item.m_shared == null) { return false; } ItemType itemType = item.m_shared.m_itemType; if (!IsWeapon(item) && (int)itemType != 5 && (int)itemType != 6 && (int)itemType != 7 && (int)itemType != 11) { return (int)itemType == 17; } return true; } private static bool IsDefaultClothing(ItemData item) { string text = (((Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : ""); if (!(text == "ArmorRagsChest")) { return text == "ArmorRagsLegs"; } return true; } internal void WearWeapon() { ItemData currentWeapon = ((Humanoid)this).GetCurrentWeapon(); if (currentWeapon != null && currentWeapon.m_shared != null && currentWeapon.m_shared.m_useDurability && (!((Object)(object)base.m_unarmedWeapon != (Object)null) || currentWeapon != base.m_unarmedWeapon.m_itemData)) { currentWeapon.m_durability = Mathf.Max(0f, currentWeapon.m_durability - currentWeapon.m_shared.m_useDurabilityDrain * Game.m_durabilityRate); if (currentWeapon.m_durability <= 0f) { ((Humanoid)this).UnequipItem(currentWeapon, false); SaveGear(); string text = ((Localization.instance != null) ? Localization.instance.Localize(currentWeapon.m_shared.m_name) : currentWeapon.m_shared.m_name); DynastyPlugin.Log.LogInfo((object)("Villager " + VillagerName + ": their " + text + " broke.")); } } } internal static bool Broken(ItemData it) { if (it != null && it.m_shared.m_useDurability) { return it.m_durability <= 0f; } return false; } internal bool GiveItemPrefab(string prefabName) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ObjectDB.instance == (Object)null) { return false; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent() : null); if ((Object)(object)val == (Object)null) { return false; } ((Character)this).m_nview.ClaimOwnership(); ItemData val2 = val.m_itemData.Clone(); val2.m_dropPrefab = itemPrefab; val2.m_stack = 1; foreach (ItemData item in new List(((Humanoid)this).GetInventory().GetAllItems())) { if (item.m_shared.m_itemType == val2.m_shared.m_itemType || (IsWeapon(item) && IsWeapon(val2))) { if (item.m_equipped) { ((Humanoid)this).UnequipItem(item, false); } ((Humanoid)this).GetInventory().RemoveItem(item); } } ((Humanoid)this).GetInventory().AddItem(val2); ((Humanoid)this).EquipItem(val2, true); SaveGear(); return true; } public bool UseItem(Humanoid user, ItemData item) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Invalid comparison between Unknown and I4 //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Invalid comparison between Unknown and I4 //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) Player val = (Player)(object)((user is Player) ? user : null); if (val == null || item == null || item.m_shared == null) { return false; } if (!string.IsNullOrEmpty(CampId)) { if (item.m_shared.m_food <= 0f && (int)item.m_shared.m_itemType != 1) { return false; } float delta = ((item.m_shared.m_food > 0f) ? (3f + item.m_shared.m_food / 20f) : 1f); ((Humanoid)val).GetInventory().RemoveItem(item, 1); VillageNet.CampRep(CampId, delta); ((Character)val).Message((MessageType)2, VillagerName + " takes the " + Localization.instance.Localize(item.m_shared.m_name) + " for the camp.", 0, (Sprite)null, false); return true; } if (IsWanderer) { if (item.m_shared.m_food <= 0f && (int)item.m_shared.m_itemType != 1) { return false; } float amount = ((item.m_shared.m_food > 0f) ? (4f + item.m_shared.m_food / 15f) : 1.5f); ((Humanoid)val).GetInventory().RemoveItem(item, 1); Wanderer.AddRep(this, val.GetPlayerID(), amount); ((Character)val).Message((MessageType)2, VillagerName + " thanks you for the " + Localization.instance.Localize(item.m_shared.m_name) + ".", 0, (Sprite)null, false); return true; } if (item.m_shared.m_food > 0f) { ((Character)this).m_nview.ClaimOwnership(); Zdo.Set("vdyn_hunger", Mathf.Min(100f, Hunger + 40f)); ((Humanoid)val).GetInventory().RemoveItem(item, 1); ((Character)val).Message((MessageType)2, VillagerName + " eats gratefully.", 0, (Sprite)null, false); return true; } if (!IsGear(item)) { return false; } ((Character)this).m_nview.ClaimOwnership(); ItemData val2 = item.Clone(); val2.m_stack = 1; val2.m_equipped = false; ((Humanoid)val).UnequipItem(item, false); ((Humanoid)val).GetInventory().RemoveItem(item, 1); foreach (ItemData item2 in new List(((Humanoid)this).GetInventory().GetAllItems())) { if (item2.m_shared.m_itemType == val2.m_shared.m_itemType || (IsWeapon(item2) && IsWeapon(val2))) { if (item2.m_equipped) { ((Humanoid)this).UnequipItem(item2, false); } if (!IsDefaultClothing(item2) && (Object)(object)item2.m_dropPrefab != (Object)null) { ((Humanoid)val).GetInventory().AddItem(item2); } ((Humanoid)this).GetInventory().RemoveItem(item2); } } ((Humanoid)this).GetInventory().AddItem(val2); ((Humanoid)this).EquipItem(val2, true); SaveGear(); string text = ((Localization.instance != null) ? Localization.instance.Localize(val2.m_shared.m_name) : val2.m_shared.m_name); ((Character)val).Message((MessageType)2, VillagerName + " takes the " + text + ".", 0, (Sprite)null, false); return true; } private void SaveGear() { List list = new List(); foreach (ItemData allItem in ((Humanoid)this).GetInventory().GetAllItems()) { if (allItem.m_equipped && (Object)(object)allItem.m_dropPrefab != (Object)null && !IsDefaultClothing(allItem)) { list.Add(((Object)allItem.m_dropPrefab).name + ":" + allItem.m_quality + ":" + allItem.m_durability.ToString("0.#", CultureInfo.InvariantCulture)); } } Zdo.Set("vdyn_gear", string.Join(";", list.ToArray())); } private void RestoreGear() { string text = Zdo.GetString("vdyn_gear", ""); if (string.IsNullOrEmpty(text) || (Object)(object)ObjectDB.instance == (Object)null) { return; } string[] array = text.Split(new char[1] { ';' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }); GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(array2[0]); if ((Object)(object)itemPrefab == (Object)null) { continue; } bool flag = false; foreach (ItemData allItem in ((Humanoid)this).GetInventory().GetAllItems()) { if ((Object)(object)allItem.m_dropPrefab == (Object)(object)itemPrefab) { flag = true; break; } } if (!flag) { ItemData val = itemPrefab.GetComponent().m_itemData.Clone(); val.m_dropPrefab = itemPrefab; val.m_stack = 1; if (array2.Length > 1 && int.TryParse(array2[1], out var result)) { val.m_quality = result; } val.m_durability = val.GetMaxDurability(); if (array2.Length > 2 && float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2)) { val.m_durability = result2; } ((Humanoid)this).GetInventory().AddItem(val); ((Humanoid)this).EquipItem(val, false); } } } protected override void OnDestroy() { All.Remove(this); ((Humanoid)this).OnDestroy(); } private void InitIdentity() { //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) ZDO zdo = Zdo; if (!zdo.GetBool("vdyn_init", false)) { Random random = new Random(Random.Range(int.MinValue, int.MaxValue) ^ ((object)Unsafe.As(ref zdo.m_uid)/*cast due to .constrained prefix*/).GetHashCode()); bool flag = random.Next(2) == 0; zdo.Set("vdyn_female", flag); zdo.Set("vdyn_name", VillagerNames.PickUnique(flag, random, NamesInUse())); zdo.Set("vdyn_hair", flag ? ("Hair" + random.Next(1, 15)) : ((random.Next(5) == 0) ? "HairNone" : ("Hair" + random.Next(1, 15)))); zdo.Set("vdyn_beard", flag ? "BeardNone" : ("Beard" + random.Next(1, 11))); float num = (float)random.NextDouble(); zdo.Set("vdyn_skin", Vector3.Lerp(new Vector3(1f, 1f, 1f), new Vector3(0.5f, 0.42f, 0.36f), num * 0.8f)); zdo.Set("vdyn_haircolor", VillagerNames.HairColors[random.Next(VillagerNames.HairColors.Length)]); if (zdo.GetVec3("vdyn_home", Vector3.zero) == Vector3.zero) { zdo.Set("vdyn_home", ((Component)this).transform.position); } zdo.Set("vdyn_hunger", 100f); zdo.Set("vdyn_energy", 100f); zdo.Set("vdyn_init", true); DynastyPlugin.Log.LogInfo((object)("New villager: " + VillagerName + ".")); } else { foreach (VillagerCharacter item in All) { if ((Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)this && item.Zdo != null && item.VillagerName == VillagerName && Older(item.Zdo.m_uid, zdo.m_uid)) { Random rng = new Random(((object)Unsafe.As(ref zdo.m_uid)/*cast due to .constrained prefix*/).GetHashCode()); string villagerName = VillagerName; zdo.Set("vdyn_name", VillagerNames.PickUnique(zdo.GetBool("vdyn_female", false), rng, NamesInUse())); DynastyPlugin.Log.LogInfo((object)("Villager " + villagerName + " shared a name with another; now " + VillagerName + ".")); break; } } } ApplyLook(); ((Character)this).m_name = VillagerName; } private static bool Older(ZDOID a, ZDOID b) { if (((ZDOID)(ref a)).UserID == ((ZDOID)(ref b)).UserID) { return ((ZDOID)(ref a)).ID < ((ZDOID)(ref b)).ID; } return ((ZDOID)(ref a)).UserID < ((ZDOID)(ref b)).UserID; } private HashSet NamesInUse() { HashSet hashSet = new HashSet(); foreach (VillagerCharacter item in All) { if ((Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)this && item.Zdo != null) { hashSet.Add(item.VillagerName); } } return hashSet; } internal void ApplyLook() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) ZDO zdo = Zdo; VisEquipment component = ((Component)this).GetComponent(); if (zdo != null && !((Object)(object)component == (Object)null)) { component.SetModel(zdo.GetBool("vdyn_female", false) ? 1 : 0); component.SetHairItem(Hash(zdo.GetString("vdyn_hair", "Hair1"))); component.SetBeardItem(Hash(zdo.GetString("vdyn_beard", "BeardNone"))); component.SetSkinColor(zdo.GetVec3("vdyn_skin", Vector3.one)); component.SetHairColor(zdo.GetVec3("vdyn_haircolor", VillagerNames.HairColors[0])); } } private static int Hash(string item) { if (!string.IsNullOrEmpty(item) && !item.EndsWith("None")) { return StringExtensionMethods.GetStableHashCode(item); } return 0; } internal void SetHome(Vector3 pos) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)((Character)this).m_nview != (Object)null && ((Character)this).m_nview.IsOwner()) { Zdo.Set("vdyn_home", pos); } } public override string GetHoverName() { return VillagerName; } public override string GetHoverText() { StringBuilder stringBuilder = new StringBuilder(); if (IsWanderer) { long num = (((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.GetPlayerID() : 0); float rep = Wanderer.Rep(this, num); stringBuilder.Append(VillagerName).Append(" (wandering trader)\n"); stringBuilder.Append("Good at ").Append(Wanderer.PreferredJob(this)).Append(" work · ") .Append(Wanderer.RepLevel(rep)) .Append("\n"); long num2 = Wanderer.TalkingTo(this); if (num2 != 0L && num2 != num) { stringBuilder.Append("Busy talking to someone"); } else { stringBuilder.Append("[$KEY_Use] Talk (use food on them as a gift)"); } if (Localization.instance == null) { return stringBuilder.ToString(); } return Localization.instance.Localize(stringBuilder.ToString()); } if (!string.IsNullOrEmpty(CampId)) { CampInfo campInfo = CampInfo.ById(CampId); long pid = (((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.GetPlayerID() : 0); stringBuilder.Append(VillagerName).Append(" (").Append((campInfo != null) ? campInfo.Name : "camp") .Append(")\n"); stringBuilder.Append("").Append(DescribeActivity()).Append(" · they think you're ") .Append(Wanderer.RepLevel(CampInfo.Rep(CampId, pid))) .Append("\n"); stringBuilder.Append("[$KEY_Use] Talk"); if (Localization.instance == null) { return stringBuilder.ToString(); } return Localization.instance.Localize(stringBuilder.ToString()); } stringBuilder.Append(VillagerName).Append(" (villager)\n"); stringBuilder.Append("").Append(Mood()).Append(" · ") .Append(DescribeActivity()) .Append("\n"); ItemData currentWeapon = ((Humanoid)this).GetCurrentWeapon(); string value = ((IsArmed && Localization.instance != null) ? Localization.instance.Localize(currentWeapon.m_shared.m_name) : "unarmed"); stringBuilder.Append("Job: ").Append(JobName(Job)).Append(" · Armed: ") .Append(value) .Append(" · Fighting skill ") .Append(CombatSkill.ToString("0")) .Append("\n"); stringBuilder.Append("[$KEY_Use] Talk [$KEY_AltPlace + $KEY_Use] Change job\n"); stringBuilder.Append("Use a weapon, armor or food on them to give it"); if (Localization.instance == null) { return stringBuilder.ToString(); } return Localization.instance.Localize(stringBuilder.ToString()); } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || Time.time - _lastTalk < 0.4f) { return false; } _lastTalk = Time.time; if ((IsWanderer || !alt) && user is Player && TalkScreen.Open(this)) { return true; } if (alt && !string.IsNullOrEmpty(CampId)) { return false; } if (alt) { VillagerJob villagerJob = (VillagerJob)((int)(Job + 1) % Enum.GetValues(typeof(VillagerJob)).Length); SetJob(villagerJob); Player val = (Player)(object)((user is Player) ? user : null); if (val != null) { ((Character)val).Message((MessageType)2, VillagerName + " is now a " + JobName(villagerJob) + ".", 0, (Sprite)null, false); } DynastyPlugin.Log.LogInfo((object)$"Villager {VillagerName}: job set to {villagerJob}."); return true; } Player val2 = (Player)(object)((user is Player) ? user : null); if (val2 != null) { ((Character)val2).Message((MessageType)2, VillagerName + ": \"" + Line() + "\"", 0, (Sprite)null, false); } return true; } internal string Mood() { float happiness = Happiness; if (happiness >= 80f) { return "Happy"; } if (happiness >= 55f) { return "Content"; } if (happiness >= 30f) { return "Unhappy"; } return "Miserable"; } internal string DescribeActivity() { if (!string.IsNullOrEmpty(QuestWorld.LostQuest(this)) && Activity != VillagerActivity.Fleeing && Activity != VillagerActivity.Fighting) { if (!((Object)(object)QuestWorld.FollowTarget(this) != (Object)null)) { return "Lost, waiting for help"; } return "Following you home"; } switch (Activity) { case VillagerActivity.Wandering: return "Going about the day"; case VillagerActivity.Working: if (!string.IsNullOrEmpty(Task)) { return Task; } return "Working"; case VillagerActivity.GoingToFire: return "Heading to the fire"; case VillagerActivity.AtFire: if (!Task.StartsWith("Taking a break")) { return "Warming by the fire"; } return Task; case VillagerActivity.GoingToBed: return "Going to bed"; case VillagerActivity.Sleeping: return "Sleeping"; case VillagerActivity.Sheltering: return "Sheltering from the weather"; case VillagerActivity.Fleeing: return "Running for safety!"; case VillagerActivity.Fighting: return "Fighting!"; default: if (!IsWanderer) { return "Resting"; } return "Travelling"; } } private string Line() { switch (Activity) { case VillagerActivity.Sleeping: return "Zzz... let me sleep."; case VillagerActivity.Fleeing: return "Help! Get away from here!"; case VillagerActivity.Fighting: return "For our homes!"; case VillagerActivity.Working: if (!string.IsNullOrEmpty(Task)) { return Task + ". Work doesn't do itself."; } return "Busy. Lots to do."; case VillagerActivity.Sheltering: return "Nasty weather. I'm staying close to the fire."; case VillagerActivity.AtFire: if (!(Hunger < 50f)) { return "A good fire, a full belly. Can't ask for more."; } return "Is there anything to eat?"; default: { if (Energy < 30f) { return "I can barely keep my eyes open."; } if (Hunger < 30f) { return "My stomach's growling."; } string[] array = new string[5] { "Good day to you.", "Fine weather for work.", "Have you seen any greylings about?", "Our village will grow, you'll see.", "The fields need tending soon." }; return array[Random.Range(0, array.Length)]; } } } } internal static class VillagerNames { private static readonly string[] Male = new string[30] { "Arne", "Bjorn", "Eirik", "Gunnar", "Halfdan", "Ivar", "Knut", "Leif", "Orm", "Ragnar", "Sigurd", "Sten", "Torvald", "Ulf", "Vidar", "Asger", "Brand", "Einar", "Frode", "Hakon", "Ketil", "Njal", "Olaf", "Rolf", "Sven", "Toke", "Grim", "Hrafn", "Kol", "Yngvar" }; private static readonly string[] Female = new string[30] { "Astrid", "Bodil", "Dagny", "Eira", "Freydis", "Gudrun", "Helga", "Inga", "Jorunn", "Liv", "Ragnhild", "Sigrid", "Solveig", "Thora", "Ylva", "Asa", "Brynja", "Gyda", "Hild", "Ingrid", "Ragna", "Runa", "Signy", "Tove", "Unn", "Valdis", "Alfhild", "Embla", "Saga", "Yrsa" }; public static readonly Vector3[] HairColors = (Vector3[])(object)new Vector3[5] { new Vector3(1f, 0.86f, 0.55f), new Vector3(0.75f, 0.55f, 0.3f), new Vector3(0.45f, 0.28f, 0.14f), new Vector3(0.18f, 0.12f, 0.08f), new Vector3(0.7f, 0.3f, 0.12f) }; public static string Pick(bool female, Random rng) { string[] array = (female ? Female : Male); return array[rng.Next(array.Length)]; } public static string PickUnique(bool female, Random rng, HashSet taken) { string[] array = (female ? Female : Male); int num = rng.Next(array.Length); for (int i = 0; i < array.Length; i++) { string text = array[(num + i) % array.Length]; if (!taken.Contains(text)) { return text; } } return array[num]; } } internal static class VillagerPlaces { private static readonly List Beds = new List(); private static readonly List Fires = new List(); private static float _nextRefresh; public static void Invalidate() { _nextRefresh = 0f; WorldScan.Invalidate(); } private static void Refresh() { if (Time.time < _nextRefresh) { return; } _nextRefresh = Time.time + 1f; Beds.Clear(); Fires.Clear(); foreach (Component item in WorldScan.All(5f)) { Bed val = (Bed)(object)((item is Bed) ? item : null); if ((Object)(object)val != (Object)null) { Beds.Add(val); } } foreach (Component item2 in WorldScan.All(5f)) { Fireplace val2 = (Fireplace)(object)((item2 is Fireplace) ? item2 : null); if ((Object)(object)val2 != (Object)null) { Fires.Add(val2); } } } public static string Describe(Vector3 near, float range) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) Refresh(); int num = 0; int num2 = 0; int num3 = 0; foreach (Bed bed in Beds) { if ((Object)(object)bed != (Object)null && Vector3.Distance(((Component)bed).transform.position, near) < range) { num++; } } foreach (Fireplace fire in Fires) { if ((Object)(object)fire != (Object)null && Vector3.Distance(((Component)fire).transform.position, near) < range) { num2++; if (fire.IsBurning()) { num3++; } } } return $"beds {num}, fires {num2} ({num3} burning) within {range:0} m"; } public static Fireplace NearestBurningFire(Vector3 near, float range) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) Refresh(); Fireplace result = null; float num = range * range; foreach (Fireplace fire in Fires) { if (!((Object)(object)fire == (Object)null) && fire.IsBurning()) { Vector3 val = ((Component)fire).transform.position - near; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; result = fire; } } } return result; } public static bool PlayersOwn(Bed b) { ZNetView val = (((Object)(object)b != (Object)null) ? ((Component)b).GetComponent() : null); if ((Object)(object)val != (Object)null && val.IsValid()) { return val.GetZDO().GetLong(ZDOVars.s_owner, 0L) != 0; } return false; } public static List BedsNear(Vector3 near, float range) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) Refresh(); List list = new List(); float num = range * range; foreach (Bed bed in Beds) { if ((Object)(object)bed != (Object)null) { Vector3 val = ((Component)bed).transform.position - near; if (((Vector3)(ref val)).sqrMagnitude < num) { list.Add(bed); } } } list.Sort(delegate(Bed a, Bed b) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Vector3 val2 = ((Component)a).transform.position - near; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; val2 = ((Component)b).transform.position - near; return sqrMagnitude.CompareTo(((Vector3)(ref val2)).sqrMagnitude); }); return list; } } internal static class VillagerPrefab { public const string Name = "VD_Villager"; private static readonly string[] PlayerOnly = new string[4] { "PlayerController", "Talker", "Skills", "Player" }; public static GameObject Prefab { get; private set; } public static void Register() { PrefabManager.OnVanillaPrefabsAvailable += Create; } private static void Create() { PrefabManager.OnVanillaPrefabsAvailable -= Create; Safe.Run("VillagerPrefab.Build", Build); } private static void Build() { //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Expected O, but got Unknown //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Expected O, but got Unknown //IL_0274: Unknown result type (might be due to invalid IL or missing references) GameObject val = PrefabManager.Instance.CreateClonedPrefab("VD_Villager", "Player"); if ((Object)(object)val == (Object)null) { DynastyPlugin.Log.LogError((object)"Villagers: could not clone the player prefab."); return; } DynastyPlugin.Log.LogInfo((object)("Villager prefab from: " + string.Join(", ", (from c in val.GetComponents() select ((object)c).GetType().Name).ToArray()))); Player component = val.GetComponent(); VillagerCharacter villagerCharacter = val.AddComponent(); if ((Object)(object)component != (Object)null) { CopyDeclaredFields(typeof(Character), component, villagerCharacter); CopyDeclaredFields(typeof(Humanoid), component, villagerCharacter); } string[] playerOnly = PlayerOnly; foreach (string text in playerOnly) { Component[] components = val.GetComponents(); foreach (Component val2 in components) { if ((Object)(object)val2 != (Object)null && ((object)val2).GetType().Name == text) { Object.DestroyImmediate((Object)(object)val2); } } } ((Character)villagerCharacter).m_name = "Villager"; ((Character)villagerCharacter).m_faction = (Faction)0; ((Character)villagerCharacter).m_health = VillagersConfig.Health.Value; ((Humanoid)villagerCharacter).m_defaultItems = ((IEnumerable)(object)new GameObject[2] { Item("ArmorRagsChest"), Item("ArmorRagsLegs") }).Where((GameObject g) => (Object)(object)g != (Object)null).ToArray(); ((Humanoid)villagerCharacter).m_randomWeapon = (GameObject[])(object)new GameObject[0]; ((Humanoid)villagerCharacter).m_randomArmor = (GameObject[])(object)new GameObject[0]; ((Humanoid)villagerCharacter).m_randomShield = (GameObject[])(object)new GameObject[0]; ((Humanoid)villagerCharacter).m_randomSets = (ItemSet[])(object)new ItemSet[0]; ((Character)villagerCharacter).m_walkSpeed = 2.4f; ZNetView component2 = val.GetComponent(); if ((Object)(object)component2 != (Object)null) { component2.m_persistent = true; component2.m_type = (ObjectType)0; } VillagerAI villagerAI = val.AddComponent(); GameObject prefab = PrefabManager.Instance.GetPrefab("Dverger"); BaseAI val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent() : null); if ((Object)(object)val3 != (Object)null) { CopyDeclaredFields(typeof(BaseAI), val3, villagerAI); } else { ((BaseAI)villagerAI).m_alertedEffects = new EffectList(); ((BaseAI)villagerAI).m_idleSound = new EffectList(); } ((BaseAI)villagerAI).m_viewRange = 30f; ((BaseAI)villagerAI).m_viewAngle = 100f; ((BaseAI)villagerAI).m_hearRange = 20f; ((BaseAI)villagerAI).m_pathAgentType = (AgentType)1; ((BaseAI)villagerAI).m_randomMoveRange = VillagersConfig.WanderRadius.Value; ((BaseAI)villagerAI).m_randomMoveInterval = 16f; ((BaseAI)villagerAI).m_avoidFire = false; ((BaseAI)villagerAI).m_afraidOfFire = false; ((BaseAI)villagerAI).m_avoidWater = true; ((BaseAI)villagerAI).m_aggravatable = false; ((BaseAI)villagerAI).m_passiveAggresive = false; ((BaseAI)villagerAI).m_fleeRange = 25f; ((BaseAI)villagerAI).m_spawnMessage = ""; ((BaseAI)villagerAI).m_deathMessage = ""; ((BaseAI)villagerAI).m_alertedMessage = ""; PrefabManager.Instance.AddPrefab(val); Prefab = val; DynastyPlugin.Log.LogInfo((object)("Villager prefab ready: " + string.Join(", ", (from c in val.GetComponents() select ((object)c).GetType().Name).ToArray()))); } private static GameObject Item(string name) { return PrefabManager.Instance.GetPrefab(name); } internal static void CopyDeclaredFields(Type type, object from, object to) { FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly) { try { fieldInfo.SetValue(to, fieldInfo.GetValue(from)); } catch (Exception) { } } } } public static VillagerCharacter Spawn(Vector3 pos, Vector3 home) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Prefab == (Object)null) { return null; } GameObject obj = Object.Instantiate(Prefab, pos, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f)); ZNetView component = obj.GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid()) { component.GetZDO().Set("vdyn_home", home); } return obj.GetComponent(); } } internal static class VillagersConfig { public static ConfigEntry Enable; public static ConfigEntry Health; public static ConfigEntry HomeRadius; public static ConfigEntry WanderRadius; public static ConfigEntry HungerPerDay; public static ConfigEntry FleeDistance; public static ConfigEntry FightBack; public static ConfigEntry RetreatHealthPercent; public static ConfigEntry AlarmRange; public static ConfigEntry BanditHealth; public static ConfigEntry EnableWork; public static ConfigEntry WorkRadius; public static ConfigEntry DepositAt; public static ConfigEntry AutoBuild; public static ConfigEntry FieldPlots; public static ConfigEntry ReplantTrees; public static ConfigEntry WoodStock; public static ConfigEntry MaterialStock; public static ConfigEntry BuildShelters; public static ConfigEntry LevelGround; public static ConfigEntry Buildings; public static ConfigEntry SmartTowns; public static void Bind(ConfigFile config) { Enable = config.Bind("2 - Modules", "EnableVillagers", true, AdminOnly("Living villagers.")); Health = config.Bind("8 - Villagers", "Health", 100f, AdminOnly("Villager health.", (AcceptableValueBase)(object)new AcceptableValueRange(10f, 1000f))); HomeRadius = config.Bind("8 - Villagers", "HomeRadius", 40f, AdminOnly("How far from home a villager looks for a bed and a fire, in meters.", (AcceptableValueBase)(object)new AcceptableValueRange(10f, 150f))); WanderRadius = config.Bind("8 - Villagers", "WanderRadius", 12f, AdminOnly("How far from home villagers walk around during the day, in meters.", (AcceptableValueBase)(object)new AcceptableValueRange(3f, 60f))); HungerPerDay = config.Bind("8 - Villagers", "HungerPerDay", 50f, AdminOnly("Percent hunger a villager loses per day. They eat their evening meal by the fire.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 300f))); FleeDistance = config.Bind("8 - Villagers", "FleeDistance", 15f, AdminOnly("Villagers run from enemies closer than this, in meters. Armed villagers fight instead, unless badly hurt.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 60f))); BindCombat(config); EnableWork = config.Bind("10 - Work", "EnableWork", true, AdminOnly("Villagers work their jobs by day: gather, chop, mine, hunt, craft their own tools, and fill the village chests.")); WorkRadius = config.Bind("10 - Work", "WorkRadius", 50f, AdminOnly("How far from home villagers go to work, in meters.", (AcceptableValueBase)(object)new AcceptableValueRange(15f, 150f))); DepositAt = config.Bind("10 - Work", "DepositAt", 30, AdminOnly("Villagers carry their haul to a chest once they hold this many items.", (AcceptableValueBase)(object)new AcceptableValueRange(5, 200))); AutoBuild = config.Bind("10 - Work", "AutoBuild", true, AdminOnly("Villagers build a wood chest and a workbench near home if the village has none and they have the wood.")); FieldPlots = config.Bind("10 - Work", "FieldPlots", 90, AdminOnly("Most crops farmers keep in the village field (a 10 x 9 m plot south of the fire, in rows).", (AcceptableValueBase)(object)new AcceptableValueRange(0, 200))); ReplantTrees = config.Bind("10 - Work", "ReplantTrees", true, AdminOnly("Woodcutters plant a sapling where they fell a tree, if the village has seeds and a cultivator.")); WoodStock = config.Bind("10 - Work", "WoodStock", 600, AdminOnly("Woodcutters stop felling trees once the village has this much wood stored, and plant and forage instead.", (AcceptableValueBase)(object)new AcceptableValueRange(50, 10000))); MaterialStock = config.Bind("10 - Work", "MaterialStock", 300, AdminOnly("Villagers stop gathering a material (stone, flint, resin...) once the village has this much. Food is always gathered.", (AcceptableValueBase)(object)new AcceptableValueRange(20, 10000))); BuildShelters = config.Bind("10 - Work", "BuildShelters", true, AdminOnly("Villagers raise a covered sleeping hall (posts and a plank roof) over their beds.")); LevelGround = config.Bind("10 - Work", "LevelGround", true, AdminOnly("Villagers level their town's ground with a hoe, centre first, so they can build on it. Never under buildings, trees or rocks.")); Buildings = config.Bind("10 - Work", "BuildBuildings", true, AdminOnly("Villages build real buildings from blueprints: a workshop for the workbench and chests, and longhouses (raised floor, walls, door, stairs, roof) with beds and furniture inside.")); SmartTowns = config.Bind("10 - Work", "SmartTowns", true, AdminOnly("Each town has a foreman who hands out the work (building, fetching what the builders are short of, food when the stores run low, putting things away), and villagers weigh their duty, energy and the time of day when picking what to do next. Off: the simpler fixed order from 0.17.")); } public static void BindCombat(ConfigFile config) { FightBack = config.Bind("9 - Defense", "FightBack", true, AdminOnly("Armed villagers fight enemies that come into the village. Give them weapons by using one on them.")); RetreatHealthPercent = config.Bind("9 - Defense", "RetreatHealthPercent", 35f, AdminOnly("Villagers stop fighting and run home below this much health.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 90f))); AlarmRange = config.Bind("9 - Defense", "AlarmRange", 30f, AdminOnly("A villager who sees an enemy this close raises the alarm for the whole village, in meters.", (AcceptableValueBase)(object)new AcceptableValueRange(5f, 80f))); BanditHealth = config.Bind("9 - Defense", "BanditHealth", 60f, AdminOnly("Bandit health.", (AcceptableValueBase)(object)new AcceptableValueRange(10f, 1000f))); } private static ConfigDescription AdminOnly(string text, AcceptableValueBase range = null) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown return new ConfigDescription(text, range, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } }); } } internal sealed class VillagerWorker { private enum Step { None, Pick, Chop, Collect, Deposit, Craft, Build, Hunt, Patrol, Idle, Repair, Plant, Cultivate, Fuel, Cook, Level, Withdraw, Smelt } private struct Option { public float Score; public int Order; public string Name; public Func Try; } private static readonly MethodInfo SmelterQueue = AccessTools.Method(typeof(Smelter), "GetQueueSize", (Type[])null, (Type[])null); private static readonly MethodInfo SmelterFuel = AccessTools.Method(typeof(Smelter), "GetFuel", (Type[])null, (Type[])null); private static readonly MethodInfo SmelterProcessed = AccessTools.Method(typeof(Smelter), "GetProcessedQueueSize", (Type[])null, (Type[])null); private Smelter _smelter; private Container _smeltChest; private ItemDrop _smeltItem; private int _smeltCount; private int _smeltPhase; private bool _smeltFuel; private bool _smeltEmpty; private float _nextSmeltLook; private float _nextMakeLook; private readonly VillagerAI _ai; private readonly VillagerCharacter _v; private Step _step; private float _stepStart; private float _timer; private float _nextSwing; private float _hitCheckAt; private float _healthBefore; private float _directHitAt = -1f; private int _noDamageSwings; private Pickable _pickable; private GameObject _target; private ItemDrop _drop; private Container _chest; private Recipe _recipe; private CraftingStation _station; private GameObject _buildPrefab; private Vector3 _buildPos; private Character _prey; private Vector3 _lootPoint; private float _lootUntil; private readonly HashSet _ignore = new HashSet(); private ItemData _repairItem; private bool _harvest; private bool _wasTree; private Farming.Crop _plantCrop; private Vector3 _plantPos; private readonly List _replantCrops = new List(); private readonly List _replantTrees = new List(); private float _ignoreReset; private bool _directDamage; private GameObject _directFor; private static readonly HashSet GatherItems = new HashSet { "Wood", "Stone", "Flint", "Raspberry", "Blueberries", "Mushroom", "MushroomYellow", "Dandelion", "Thistle", "Cloudberry", "CarrotSeeds", "TurnipSeeds", "OnionSeeds" }; private static readonly HashSet MinerItems = new HashSet { "Stone", "Flint" }; private static readonly HashSet FoodItems = new HashSet { "Raspberry", "Blueberries", "Mushroom", "MushroomYellow", "Cloudberry", "Carrot", "Turnip" }; private static readonly HashSet Basics = new HashSet { "Wood", "Stone", "Flint" }; private float _idleSince = float.MaxValue; private float _restUntil; private Vector3 _stepStartPos; private static readonly Dictionary BuildLock = new Dictionary(); private Vector3 _levelAt; private float _hoeNote; private float _levelH; private bool _clearing; private int _clearSwings; private readonly List