Beispiel #1
0
        public void Apply(PolusShipStatus shipStatus)
        {
            if (!MapHandler.Load())
            {
                return;
            }

            MapData      map     = MapHandler.GetMap();
            PolusHandler polus   = new PolusHandler(shipStatus);
            AssetBuilder builder = new AssetBuilder(polus);

            polus.ClearTasks();
            polus.MoveToTemp();

            for (int i = 0; i < map.objs.Length; i++)
            {
                MapAsset asset   = map.objs[i];
                bool     success = builder.Build(asset);
                if (!success)
                {
                    LILogger.LogError("Failed to build " + asset.name);
                }
                else if (i % 1000 == 0)
                {
                    LILogger.LogMsg(i + " - Objects");
                }
            }

            polus.DeleteTemp();
            LILogger.LogInfo("Applied Map Data");
        }
Beispiel #2
0
        private bool RouteBuild(MapAsset asset, bool isPost)
        {
            try
            {
                foreach (Builder builder in builders)
                {
                    bool success = false;

                    if (isPost)
                    {
                        success = builder.PostBuild();
                    }
                    else
                    {
                        success = builder.PreBuild(asset);
                    }

                    if (!success)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                LILogger.LogInfo(e.Message + "\n" + e.StackTrace);
                return(false);
            }
        }
Beispiel #3
0
        public static bool Load()
        {
            if (mapLoaded)
            {
                return(true);
            }

            // Get Directory
            string dllDir = System.Reflection.Assembly.GetAssembly(typeof(LevelImposter.MainHarmony)).Location;

            mapDir = Path.Combine(Path.GetDirectoryName(dllDir), "map.json");

            // Load File
            if (!File.Exists(mapDir))
            {
                LILogger.LogError("Could not find map at " + mapDir);
                return(false);
            }
            string mapJson = File.ReadAllText(mapDir);

            // Deserialize
            mapData = Newtonsoft.Json.JsonConvert.DeserializeObject <MapData>(mapJson);

            // Return
            mapLoaded = true;
            LILogger.LogInfo("Found and Deserialized Map Data");
            return(true);
        }
Beispiel #4
0
 public void PostBuild(PolusShipStatus shipStatus)
 {
     // Post Build
     LILogger.LogInfo("...Wrapping Up");
     builder.PostBuild();
     polus.SetExile(MapHandler.mapData.exile);
     LILogger.LogInfo("Finished!");
 }
Beispiel #5
0
 public static void Postfix(AmongUsClient __instance)
 {
     LILogger.LogInfo("Loading Ship Prefabs...");
     foreach (AssetReference assetRef in __instance.ShipPrefabs)
     {
         assetRef.LoadAsset <GameObject>();
     }
     MapHandler.Load();
 }
Beispiel #6
0
 public static void Postfix(AmongUsClient __instance)
 {
     if (__instance.AmHost)
     {
         LILogger.LogInfo("Player Joined: Sending map checksum...");
         var writer = __instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, 42, SendOption.Reliable, -1);
         writer.Write(MapHandler.checksum);
         __instance.FinishRpcImmediately(writer);
     }
 }
Beispiel #7
0
        public void PreBuild(PolusShipStatus shipStatus)
        {
            // Load Map and AssetDB
            if (!AssetDB.Import())
            {
                return;
            }
            if (!MapHandler.Load())
            {
                return;
            }

            // Vars
            map     = MapHandler.GetMap();
            polus   = new PolusHandler(shipStatus);
            builder = new AssetBuilder(polus);
            MinimapGenerator.Reset();

            // Rooms
            LILogger.LogInfo("...Building Rooms");
            for (int i = 0; i < map.objs.Length; i++)
            {
                if (map.objs[i].type != "util-room")
                {
                    continue;
                }
                MapAsset asset   = map.objs[i];
                bool     success = builder.PreBuild(asset);
                if (!success)
                {
                    LILogger.LogError("Failed to build " + asset.name);
                }
            }

            // Objects
            LILogger.LogInfo("...Building Objects");
            for (int i = 0; i < map.objs.Length; i++)
            {
                if (map.objs[i].type == "util-room")
                {
                    continue;
                }
                MapAsset asset   = map.objs[i];
                bool     success = builder.PreBuild(asset);
                if (!success)
                {
                    LILogger.LogError("Failed to build " + asset.name);
                }
                else if (i % 100 == 0 && i != 0)
                {
                    LILogger.LogInfo("..." + i + " Objects Built");
                }
            }
        }
Beispiel #8
0
        public static bool Load()
        {
            if (mapLoaded)
            {
                return(true);
            }

            LILogger.LogInfo("...Deserializing Map Data");

            // Get Directory
            string dllDir = System.Reflection.Assembly.GetAssembly(typeof(LevelImposter.MainHarmony)).Location;

            mapDir = Path.Combine(Path.GetDirectoryName(dllDir), "map.json");

            // Load File
            if (!File.Exists(mapDir))
            {
                LILogger.LogError("Could not find map at " + mapDir);
                return(false);
            }
            string mapJson = File.ReadAllText(mapDir);

            // Settings
            var settings = new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
                MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore
            };

            // Deserialize
            try
            {
                mapData = Newtonsoft.Json.JsonConvert.DeserializeObject <MapData>(mapJson, settings);
            }
            catch (Exception e)
            {
                LILogger.LogError("There was an error deserializing map data:\n" + e.Message);
                return(false);
            }

            // Checksum
            int checkNum = 0;

            foreach (char c in mapJson)
            {
                checkNum += Convert.ToByte(c);
            }
            checksum = checkNum.ToString("X4");

            // Return
            mapLoaded = true;
            return(true);
        }
Beispiel #9
0
        public static bool Import()
        {
            LILogger.LogInfo("...Loading Asset Database");
            var client = GameObject.Find("NetworkManager").GetComponent <AmongUsClient>();

            foreach (AssetReference assetRef in client.ShipPrefabs)
            {
                if (assetRef.IsDone)
                {
                    AssetDB.Import(assetRef.Asset.Cast <GameObject>());
                }
                else
                {
                    LILogger.LogError("There was an error loading the Asset Database!");
                    return(false);
                }
            }
            return(true);
        }
Beispiel #10
0
 public bool Build(MapAsset asset)
 {
     try
     {
         if (asset.spriteType == "existing")
         {
             if (asset.type == "util-player")
             {
                 return(spawnBuilder.Build(asset));
             }
             else if (asset.type == "util-room")
             {
                 return(true);
             }
             else if (asset.type.StartsWith("util-"))
             {
                 return(utilBuilder.Build(asset));
             }
             else if (asset.type.StartsWith("dec-"))
             {
                 return(decBuilder.Build(asset));
             }
             else if (asset.type.StartsWith("room-"))
             {
                 return(roomBuilder.Build(asset));
             }
             else if (asset.type.StartsWith("task-"))
             {
                 return(taskBuilder.Build(asset));
             }
         }
         else if (asset.spriteType == "custom")
         {
             return(customBuilder.Build(asset));
         }
         return(false);
     }
     catch (Exception e)
     {
         LILogger.LogInfo(e.Message + "\n" + e.StackTrace);
         return(false);
     }
 }
Beispiel #11
0
        private static void Import(GameObject map)
        {
            // Ship Status
            ShipStatus shipStatus = map.GetComponent <ShipStatus>();

            // Determine Map Type
            MapType mapType = MapType.Skeld;

            if (map.name == "AprilShip")
            {
                return;
            }
            if (map.name == "MiraShip")
            {
                mapType = MapType.Mira;
            }
            if (map.name == "PolusShip")
            {
                mapType = MapType.Polus;
            }
            if (map.name == "Airship")
            {
                mapType = MapType.Airship;
            }


            // Import Map to Lists
            Import(map, shipStatus, mapType, tasks);
            Import(map, shipStatus, mapType, utils);
            Import(map, shipStatus, mapType, sabs);
            Import(map, shipStatus, mapType, dec);
            Import(map, shipStatus, mapType, room);
            Import(map, shipStatus, mapType, ss);

            LILogger.LogInfo("..." + map.name + " Loaded");
        }