Example #1
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("room-"))
            {
                return(true);
            }
            RoomData utilData = AssetDB.room[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;
            obj.layer = (int)Layer.Ship;

            // Colliders
            AssetHelper.BuildColliders(asset, obj, utilData.Scale);

            // Add to Polus
            Vector3 bounds = spriteRenderer.sprite.bounds.center;

            polus.Add(obj, asset, utilData.Scale, bounds.x, bounds.y);

            return(true);
        }
Example #2
0
        public bool Build(MapAsset asset)
        {
            GameObject obj = new GameObject("Custom Asset");

            // Base64
            string base64 = asset.type.Substring(asset.type.IndexOf(",") + 1);

            byte[] data;
            try
            {
                data = System.Convert.FromBase64String(base64);
            }
            catch
            {
                LILogger.LogError("Could not parse custom asset texture");
                return(false);
            }

            // Texture
            Texture2D tex = new Texture2D(1, 1);

            ImageConversion.LoadImage(tex, data);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);

            // Polus
            polus.Add(obj, asset);
            return(true);
        }
Example #3
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("dec-"))
            {
                return(true);
            }
            DecData utilData = AssetDB.dec[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;
            obj.layer = (int)Layer.ShortObjects;

            // Colliders
            AssetHelper.BuildColliders(asset, obj, utilData.Scale);

            polus.Add(obj, asset, utilData.Scale);

            return(true);
        }
Example #4
0
        public bool Build(MapAsset asset)
        {
            SabData utilData = AssetDB.sabs[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;

            // Console
            SystemConsole origConsole = utilData.GameObj.GetComponent <SystemConsole>();
            SystemConsole console     = obj.AddComponent <SystemConsole>();

            console.Image          = spriteRenderer;
            console.FreeplayOnly   = origConsole.FreeplayOnly;
            console.onlyFromBelow  = origConsole.onlyFromBelow;
            console.usableDistance = origConsole.usableDistance;
            console.MinigamePrefab = origConsole.MinigamePrefab;
            console.useIcon        = origConsole.useIcon;

            // Box Collider
            if (utilData.GameObj.GetComponent <CircleCollider2D>() != null)
            {
                CircleCollider2D origBox = utilData.GameObj.GetComponent <CircleCollider2D>();
                CircleCollider2D box     = obj.AddComponent <CircleCollider2D>();
                box.radius    = origBox.radius;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else
            {
                BoxCollider2D origBox = utilData.GameObj.GetComponent <BoxCollider2D>();
                BoxCollider2D box     = obj.AddComponent <BoxCollider2D>();
                box.size      = origBox.size;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }

            // Button
            PassiveButton origBtn = utilData.GameObj.GetComponent <PassiveButton>();
            PassiveButton btn     = obj.AddComponent <PassiveButton>();

            btn.ClickMask   = origBtn.ClickMask;
            btn.OnMouseOver = new UnityEvent();
            btn.OnMouseOut  = new UnityEvent();
            Action action = console.Use;

            btn.OnClick.AddListener(action);

            polus.Add(obj, asset);

            return(true);
        }
Example #5
0
        public bool PreBuild(MapAsset asset)
        {
            if (asset.type != "util-room")
            {
                return(true);
            }

            // Check Collider Count
            if (asset.colliders.Length <= 0)
            {
                LILogger.LogWarn(asset.name + " does not have any colliders!");
                return(false);
            }

            // Object
            GameObject obj = new GameObject(asset.name);

            // Collider
            PolygonCollider2D mainCollider = null;

            foreach (MapCollider collider in asset.colliders)
            {
                PolygonCollider2D polyCollider = obj.AddComponent <PolygonCollider2D>();
                polyCollider.isTrigger = true;
                polyCollider.SetPath(0, collider.GetPoints());
                mainCollider = polyCollider;
            }

            // Room
            PlainShipRoom room = obj.AddComponent <PlainShipRoom>();

            room.RoomId = (SystemTypes)roomId;
            if (asset.colliders.Length > 0)
            {
                room.roomArea = mainCollider;
            }

            // Room DB
            if (!db.ContainsKey(asset.id))
            {
                db.Add(asset.id, (SystemTypes)roomId);
            }

            // Text DB
            TextHandler.Add((SystemTypes)roomId, asset.name);

            // Polus
            polus.shipStatus.AllRooms = AssetHelper.AddToArr(polus.shipStatus.AllRooms, room);
            polus.shipStatus.FastRooms.Add((SystemTypes)roomId, room);
            MinimapGenerator.AddRoom(asset);
            polus.Add(obj, asset);

            roomId++;
            return(true);
        }
Example #6
0
        public bool Build(MapAsset asset)
        {
            RoomData utilData = AssetDB.room[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;

            polus.Add(obj, asset);

            return(true);
        }
Example #7
0
        public bool PreBuild(MapAsset asset)
        {
            if (asset.type != "util-cam")
            {
                return(true);
            }
            UtilData utilData = AssetDB.utils[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;
            obj.layer = (int)Layer.ShortObjects;

            // Camera
            SurvCamera camClone = utilData.GameObj.GetComponent <SurvCamera>();
            SurvCamera camera   = obj.AddComponent <SurvCamera>();

            camera.CamName              = asset.name;
            camera.camNameString        = camClone.camNameString;
            camera.NewName              = camClone.NewName;
            camera.OffAnim              = camClone.OffAnim;
            camera.CamSize              = camClone.CamSize;
            camera.CamAspect            = camClone.CamAspect;
            camera.Offset               = camClone.Offset;
            camera.OnAnim               = camClone.OnAnim;
            camera.Images               = camClone.Images;
            polus.shipStatus.AllCameras = AssetHelper.AddToArr(polus.shipStatus.AllCameras, camera);

            // Colliders
            AssetHelper.BuildColliders(asset, obj);

            // Add to Polus
            polus.Add(obj, asset);

            return(true);
        }
        public bool PreBuild(MapAsset asset)
        {
            if (asset.type != "custom" && asset.spriteType != "custom")
            {
                return(true);
            }

            GameObject obj = new GameObject("Custom Asset");

            SpriteRenderer render = obj.AddComponent <SpriteRenderer>();

            render.sprite = AssetHelper.SpriteFromBase64(asset.type);
            obj.layer     = (int)Layer.Ship;

            // Colliders
            AssetHelper.BuildColliders(asset, obj);

            // Polus
            polus.Add(obj, asset);
            return(true);
        }
Example #9
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("util-vent"))
            {
                return(true);
            }
            UtilData utilData = AssetDB.utils[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;
            obj.layer = (int)Layer.ShortObjects;

            // Animator (If Applicable)
            if (asset.type == "util-vent1")
            {
                SpriteAnim spriteAnimClone = utilData.GameObj.GetComponent <SpriteAnim>();
                SpriteAnim spriteAnim      = obj.AddComponent <SpriteAnim>();

                spriteAnim.Play(spriteAnimClone.m_defaultAnim, spriteAnimClone.Speed);
                //spriteAnim.m_clipPairList = spriteAnimClone.m_clipPairList;
            }


            // Vent
            Vent ventData = utilData.GameObj.GetComponent <Vent>();
            Vent vent     = obj.AddComponent <Vent>();

            vent.EnterVentAnim = ventData.EnterVentAnim;
            vent.ExitVentAnim  = ventData.ExitVentAnim;
            vent.spreadAmount  = ventData.spreadAmount;
            vent.spreadShift   = ventData.spreadShift;
            vent.Offset        = ventData.Offset;
            vent.myRend        = spriteRenderer;
            vent.Buttons       = new UnhollowerBaseLib.Il2CppReferenceArray <ButtonBehavior>(0);
            vent.Id            = this.id;
            this.id++;

            // Arrow Buttons
            GameObject     arrowClone       = utilData.GameObj.transform.FindChild("Arrow").gameObject;
            SpriteRenderer arrowCloneSprite = arrowClone.GetComponent <SpriteRenderer>();
            BoxCollider2D  arrowCloneBox    = arrowClone.GetComponent <BoxCollider2D>();

            for (int i = 0; i < asset.targetIds.Length && i < 3; i++)
            {
                long targetId = asset.targetIds[i];
                if (targetId < 0)
                {
                    continue;
                }
                if (MapHandler.GetById(targetId) == null)
                {
                    continue;
                }

                GameObject arrowObj = new GameObject("Arrow" + targetId);

                // Sprite
                SpriteRenderer arrowSprite = arrowObj.AddComponent <SpriteRenderer>();
                arrowSprite.sprite   = arrowCloneSprite.sprite;
                arrowSprite.material = arrowCloneSprite.material;
                arrowObj.layer       = (int)Layer.UI;

                // Box Collider
                BoxCollider2D arrowBox = arrowObj.AddComponent <BoxCollider2D>();
                arrowBox.size      = arrowCloneBox.size;
                arrowBox.offset    = arrowCloneBox.offset;
                arrowBox.isTrigger = true;

                // Button
                ButtonBehavior arrowBtn = arrowObj.AddComponent <ButtonBehavior>();
                arrowBtn.OnMouseOver = new UnityEvent();
                arrowBtn.OnMouseOut  = new UnityEvent();
                Action action;
                if (i == 0)
                {
                    action = vent.ClickRight;
                }
                else if (i == 1)
                {
                    action = vent.ClickLeft;
                }
                else
                {
                    action = vent.ClickCenter;
                }
                arrowBtn.OnClick.AddListener(action);

                // Transform
                vent.Buttons = AssetHelper.AddToArr(vent.Buttons, arrowBtn);
                arrowObj.transform.SetParent(obj.transform);
                arrowObj.transform.localScale = new Vector3(0.4f, 0.4f, 1.0f);
                arrowObj.active = false;
            }

            // Box Collider
            BoxCollider2D origBox = utilData.GameObj.GetComponent <BoxCollider2D>();
            BoxCollider2D box     = obj.AddComponent <BoxCollider2D>();

            box.size      = origBox.size;
            box.offset    = origBox.offset;
            box.isTrigger = true;

            // Colliders
            AssetHelper.BuildColliders(asset, obj);

            // Polus
            ventDb.Add(asset.id, vent);
            targetDb.Add(asset.id, asset.targetIds);
            polus.shipStatus.AllVents = AssetHelper.AddToArr(polus.shipStatus.AllVents, vent);
            polus.Add(obj, asset);

            // Sounds
            if (!hasSounds)
            {
                polus.shipStatus.VentEnterSound = AssetDB.ss["ss-skeld"].ShipStatus.VentEnterSound;
                polus.shipStatus.VentMoveSounds = AssetDB.ss["ss-skeld"].ShipStatus.VentMoveSounds;
                hasSounds = true;
            }

            return(true);
        }
Example #10
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("task-"))
            {
                return(true);
            }
            TaskData taskData = AssetDB.tasks[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = taskData.SpriteRenderer.sprite;
            spriteRenderer.material = taskData.SpriteRenderer.material;
            obj.layer = (int)Layer.ShortObjects;

            // Target Room
            SystemTypes target = 0;

            if (asset.targetIds.Length > 0)
            {
                if (asset.targetIds[0] > 0)
                {
                    if (ShipRoomBuilder.db.ContainsKey(asset.targetIds[0]))
                    {
                        target = ShipRoomBuilder.db[asset.targetIds[0]];
                    }
                }
            }

            // Divert Power
            if (asset.type == "task-divert2")
            {
                if (divertId >= DIVERT_SYSTEMS.Length)
                {
                    LILogger.LogError("Hit Divert Power's Max System Limit");
                    return(false);
                }

                target = DIVERT_SYSTEMS[divertId];
                divertId++;
            }

            // Console
            Console console;
            Console origConsole = taskData.GameObj.GetComponent <Console>();

            if (asset.type == "task-pistols1" || asset.type == "task-rifles1")
            {
                console = obj.AddComponent <StoreArmsTaskConsole>();
                StoreArmsTaskConsole specialConsole     = console.Cast <StoreArmsTaskConsole>();
                StoreArmsTaskConsole origSpecialConsole = origConsole.Cast <StoreArmsTaskConsole>();

                specialConsole.timesUsed   = origSpecialConsole.timesUsed;
                specialConsole.Images      = origSpecialConsole.Images;
                specialConsole.useSound    = origSpecialConsole.useSound;
                specialConsole.usesPerStep = origSpecialConsole.usesPerStep;
            }
            else if (asset.type.StartsWith("task-towels") && asset.type != "task-towels1")
            {
                console = obj.AddComponent <TowelTaskConsole>();
                TowelTaskConsole specialConsole     = console.Cast <TowelTaskConsole>();
                TowelTaskConsole origSpecialConsole = origConsole.Cast <TowelTaskConsole>();

                specialConsole.useSound = origSpecialConsole.useSound;
            }
            else
            {
                console = obj.AddComponent <Console>();
            }
            console.ConsoleId      = origConsole.ConsoleId;
            console.AllowImpostor  = false;
            console.checkWalls     = false;
            console.GhostsIgnored  = false;
            console.Image          = spriteRenderer;
            console.onlyFromBelow  = asset.onlyFromBottom;
            console.onlySameRoom   = false;
            console.usableDistance = 1;
            console.Room           = target;
            console.TaskTypes      = origConsole.TaskTypes;
            console.ValidTasks     = origConsole.ValidTasks;

            // Box Collider
            if (taskData.GameObj.GetComponent <CircleCollider2D>() != null)
            {
                CircleCollider2D origBox = taskData.GameObj.GetComponent <CircleCollider2D>();
                CircleCollider2D box     = obj.AddComponent <CircleCollider2D>();
                box.radius    = origBox.radius;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else if (taskData.GameObj.GetComponent <BoxCollider2D>() != null)
            {
                BoxCollider2D origBox = taskData.GameObj.GetComponent <BoxCollider2D>();
                BoxCollider2D box     = obj.AddComponent <BoxCollider2D>();
                box.size      = origBox.size;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else if (taskData.GameObj.GetComponent <PolygonCollider2D>() != null)
            {
                PolygonCollider2D origBox = taskData.GameObj.GetComponent <PolygonCollider2D>();
                PolygonCollider2D box     = obj.AddComponent <PolygonCollider2D>();
                box.points    = origBox.points;
                box.pathCount = origBox.pathCount;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }

            // Button
            PassiveButton origBtn = taskData.GameObj.GetComponent <PassiveButton>();

            if (origBtn != null)
            {
                PassiveButton btn = obj.AddComponent <PassiveButton>();
                btn.ClickMask   = origBtn.ClickMask;
                btn.OnMouseOver = new UnityEvent();
                btn.OnMouseOut  = new UnityEvent();
                Action action = console.Use;
                btn.OnClick.AddListener(action);
            }

            // Medscan
            if (asset.type == "task-medscan")
            {
                MedScannerBehaviour medscan  = obj.AddComponent <MedScannerBehaviour>();
                MedScannerBehaviour origscan = taskData.GameObj.GetComponent <MedScannerBehaviour>();

                medscan.Offset = origscan.Offset;

                polus.shipStatus.MedScanner = medscan;
            }

            // Multipart Tasks
            if (asset.type.StartsWith("task-waterwheel"))
            {
                int id = int.Parse(asset.type.Substring(15));
                if (1 <= id && id <= 3)
                {
                    console.ConsoleId = id - 1;
                }
            }
            else if (asset.type.StartsWith("task-waterjug"))
            {
                int id = int.Parse(asset.type.Substring(13));
                if (1 <= id && id <= 2)
                {
                    console.ValidTasks             = new UnhollowerBaseLib.Il2CppReferenceArray <TaskSet>(1);
                    console.ValidTasks[0]          = new TaskSet();
                    console.ValidTasks[0].taskType = TaskTypes.ReplaceWaterJug;
                    console.ValidTasks[0].taskStep = new IntRange(id - 1, id - 1);
                }
            }
            else if (asset.type == "task-node")
            {
                if (nodeId >= 6)
                {
                    LILogger.LogError("Hit Weather Node's Max System Limit");
                    return(false);
                }

                console.ConsoleId = nodeId;
            }
            else if (asset.type == "task-records2")
            {
                if (recordsId >= 9)
                {
                    LILogger.LogError("Hit Records's Max System Limit");
                    return(false);
                }

                console.ConsoleId = recordsId;
                recordsId++;
            }
            else if (asset.type == "task-toilet")
            {
                if (toiletId >= 4)
                {
                    LILogger.LogError("Hit Toilet's Max System Limit");
                    return(false);
                }

                console.ConsoleId = toiletId;
                toiletId++;
            }
            else if (asset.type == "task-breakers")
            {
                if (breakersId >= 7)
                {
                    LILogger.LogError("Hit Breakers's Max System Limit");
                    return(false);
                }

                console.ConsoleId = breakersId;
                breakersId++;
            }
            else if (asset.type.StartsWith("task-towels") && asset.type != "task-towels1")
            {
                if (towelsId >= 14)
                {
                    LILogger.LogError("Hit Towels's Max System Limit");
                    return(false);
                }

                console.ConsoleId = towelsId;
                towelsId++;
            }

            // Task
            if (!string.IsNullOrEmpty(taskData.BehaviorName))
            {
                GameObject taskHolder = new GameObject(asset.id.ToString());
                taskHolder.transform.SetParent(taskMgr.transform);

                NormalPlayerTask origTask = taskData.Behavior;
                NormalPlayerTask task;
                if (asset.type.StartsWith("task-divert"))
                {
                    task = taskHolder.AddComponent <DivertPowerTask>();

                    DivertPowerTask taskNode = task.Cast <DivertPowerTask>();
                    DivertPowerTask origNode = origTask.Cast <DivertPowerTask>();

                    taskNode.TargetSystem = target;
                }
                else if (asset.type == "task-node")
                {
                    task = taskHolder.AddComponent <WeatherNodeTask>();

                    WeatherNodeTask taskNode = task.Cast <WeatherNodeTask>();
                    WeatherNodeTask origNode = origTask.Cast <WeatherNodeTask>();

                    taskNode.Stage2Prefab = origNode.Stage2Prefab;
                    taskNode.NodeId       = nodeId;
                    nodeId++;
                }
                else if (asset.type.StartsWith("task-waterwheel"))
                {
                    task = taskHolder.AddComponent <WaterWayTask>();
                }
                else if (asset.type == "task-towels1")
                {
                    task = taskHolder.AddComponent <TowelTask>();
                }
                else
                {
                    task = taskHolder.AddComponent <NormalPlayerTask>();
                }
                task.StartAt        = target;
                task.taskStep       = origTask.taskStep;
                task.MaxStep        = origTask.MaxStep;
                task.arrowSuspended = origTask.arrowSuspended;
                task.ShowTaskTimer  = origTask.ShowTaskTimer;
                task.ShowTaskStep   = origTask.ShowTaskStep;
                task.TaskTimer      = origTask.TaskTimer;
                task.TimerStarted   = origTask.TimerStarted;
                task.TaskType       = origTask.TaskType;
                task.MinigamePrefab = origTask.MinigamePrefab;
                task.HasLocation    = origTask.HasLocation;
                task.LocationDirty  = origTask.LocationDirty;

                if (taskData.TaskType == TaskType.Common)
                {
                    polus.shipStatus.CommonTasks = AssetHelper.AddToArr(polus.shipStatus.CommonTasks, task);
                }
                if (taskData.TaskType == TaskType.Short)
                {
                    polus.shipStatus.NormalTasks = AssetHelper.AddToArr(polus.shipStatus.NormalTasks, task);
                }
                if (taskData.TaskType == TaskType.Long)
                {
                    polus.shipStatus.LongTasks = AssetHelper.AddToArr(polus.shipStatus.LongTasks, task);
                }
            }

            // Colliders
            AssetHelper.BuildColliders(asset, obj, taskData.Scale);

            // Add to Polus
            polus.shipStatus.AllConsoles = AssetHelper.AddToArr(polus.shipStatus.AllConsoles, console);
            polus.Add(obj, asset, taskData.Scale);
            return(true);
        }
Example #11
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("util-") ||
                asset.type.StartsWith("util-vent") ||
                asset.type.StartsWith("util-spawn") ||
                asset.type == "util-room" ||
                asset.type == "util-player" ||
                asset.type == "util-cam")
            {
                return(true);
            }

            UtilData utilData = AssetDB.utils[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;
            obj.layer = (int)Layer.ShortObjects;

            // Console
            Action action;

            if (utilData.GameObj.GetComponent <SystemConsole>() != null)
            {
                SystemConsole origConsole = utilData.GameObj.GetComponent <SystemConsole>();
                SystemConsole console     = obj.AddComponent <SystemConsole>();
                console.Image          = spriteRenderer;
                console.FreeplayOnly   = origConsole.FreeplayOnly;
                console.onlyFromBelow  = asset.onlyFromBottom;
                console.usableDistance = origConsole.usableDistance;
                console.MinigamePrefab = origConsole.MinigamePrefab;
                if (asset.type == "util-cams2") // Convert Skeld Cams -> Polus/Airship Cams
                {
                    console.MinigamePrefab = AssetDB.utils["util-cams"].GameObj.GetComponent <SystemConsole>().MinigamePrefab;
                }
                console.useIcon = origConsole.useIcon;
                action          = console.Use;
            }
            else
            {
                MapConsole origConsole = utilData.GameObj.GetComponent <MapConsole>();
                MapConsole console     = obj.AddComponent <MapConsole>();
                console.Image          = spriteRenderer;
                console.useIcon        = origConsole.useIcon;
                console.usableDistance = origConsole.usableDistance;
                console.useIcon        = origConsole.useIcon;
                action = console.Use;
            }

            // Box Collider
            if (utilData.GameObj.GetComponent <CircleCollider2D>() != null)
            {
                CircleCollider2D origBox = utilData.GameObj.GetComponent <CircleCollider2D>();
                CircleCollider2D box     = obj.AddComponent <CircleCollider2D>();
                box.radius    = origBox.radius;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else if (utilData.GameObj.GetComponent <BoxCollider2D>() != null)
            {
                BoxCollider2D origBox = utilData.GameObj.GetComponent <BoxCollider2D>();
                BoxCollider2D box     = obj.AddComponent <BoxCollider2D>();
                box.size      = origBox.size;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else if (utilData.GameObj.GetComponent <PolygonCollider2D>() != null)
            {
                PolygonCollider2D origBox = utilData.GameObj.GetComponent <PolygonCollider2D>();
                PolygonCollider2D box     = obj.AddComponent <PolygonCollider2D>();
                box.points    = origBox.points;
                box.pathCount = origBox.pathCount;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }

            // Button
            PassiveButton origBtn = utilData.GameObj.GetComponent <PassiveButton>();
            PassiveButton btn     = obj.AddComponent <PassiveButton>();

            btn.ClickMask   = origBtn.ClickMask;
            btn.OnMouseOver = new UnityEvent();
            btn.OnMouseOut  = new UnityEvent();
            btn.OnClick.AddListener(action);

            // Colliders
            AssetHelper.BuildColliders(asset, obj);

            polus.Add(obj, asset);

            return(true);
        }
Example #12
0
        public bool PreBuild(MapAsset asset)
        {
            if (!SAB_SYSTEMS.ContainsKey(asset.type))
            {
                return(true);
            }
            SystemTypes sys = SAB_SYSTEMS[asset.type];

            // GameObject
            SabData    sabData = AssetDB.sabs[asset.type];
            GameObject obj     = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = sabData.SpriteRenderer.sprite;
            spriteRenderer.material = sabData.SpriteRenderer.material;
            obj.layer = (int)Layer.ShortObjects;

            // Console
            Console origConsole = sabData.GameObj.GetComponent <Console>();
            Console console     = obj.AddComponent <Console>();

            console.ConsoleId      = origConsole.ConsoleId;
            console.AllowImpostor  = true;
            console.checkWalls     = false;
            console.GhostsIgnored  = true;
            console.Image          = spriteRenderer;
            console.onlyFromBelow  = false;
            console.onlySameRoom   = false;
            console.usableDistance = 1;
            console.Room           = sys;
            console.TaskTypes      = origConsole.TaskTypes;
            console.ValidTasks     = origConsole.ValidTasks;

            polus.shipStatus.AllConsoles = AssetHelper.AddToArr(polus.shipStatus.AllConsoles, console);

            // Box Collider
            if (sabData.GameObj.GetComponent <CircleCollider2D>() != null)
            {
                CircleCollider2D origBox = sabData.GameObj.GetComponent <CircleCollider2D>();
                CircleCollider2D box     = obj.AddComponent <CircleCollider2D>();
                box.radius    = origBox.radius;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else if (sabData.GameObj.GetComponent <BoxCollider2D>() != null)
            {
                BoxCollider2D origBox = sabData.GameObj.GetComponent <BoxCollider2D>();
                BoxCollider2D box     = obj.AddComponent <BoxCollider2D>();
                box.size      = origBox.size;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else if (sabData.GameObj.GetComponent <PolygonCollider2D>() != null)
            {
                PolygonCollider2D origBox = sabData.GameObj.GetComponent <PolygonCollider2D>();
                PolygonCollider2D box     = obj.AddComponent <PolygonCollider2D>();
                box.points    = origBox.points;
                box.pathCount = origBox.pathCount;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }

            // Task
            SabotageTask task      = null;
            StringNames  name      = StringNames.ExitButton;
            GameObject   sabHolder = new GameObject(asset.id.ToString());

            sabHolder.transform.SetParent(sabMgr.transform);
            if (asset.type == "sab-comms")
            {
                task = sabHolder.AddComponent <HudOverrideTask>();
                HudOverrideTask castTask  = task.Cast <HudOverrideTask>();
                HudOverrideTask taskClone = sabData.Behavior.Cast <HudOverrideTask>();

                castTask.even       = taskClone.even;
                castTask.isComplete = taskClone.isComplete;
                castTask.system     = polus.shipStatus.Systems[sys].Cast <HudOverrideSystemType>();

                name = StringNames.FixComms;
            }
            else if (asset.type == "sab-electric")
            {
                task = sabHolder.AddComponent <ElectricTask>();
                ElectricTask castTask  = task.Cast <ElectricTask>();
                ElectricTask taskClone = sabData.Behavior.Cast <ElectricTask>();

                castTask.even       = taskClone.even;
                castTask.isComplete = taskClone.isComplete;
                castTask.system     = polus.shipStatus.Systems[sys].Cast <SwitchSystem>();

                name = StringNames.FixLights;
            }
            else if (asset.type == "sab-reactorleft")
            {
                task = sabHolder.AddComponent <ReactorTask>();
                ReactorTask castTask  = task.Cast <ReactorTask>();
                ReactorTask taskClone = sabData.Behavior.Cast <ReactorTask>();

                castTask.even       = taskClone.even;
                castTask.isComplete = taskClone.isComplete;
                castTask.reactor    = polus.shipStatus.Systems[sys].Cast <ICriticalSabotage>();

                name = StringNames.Laboratory;
            }
            if (name != StringNames.ExitButton)
            {
                SabotageTask origTask = sabData.Behavior.Cast <SabotageTask>();
                task.Arrows         = new UnhollowerBaseLib.Il2CppReferenceArray <ArrowBehaviour>(2);
                task.Arrows[0]      = sabArrow1;
                task.Arrows[1]      = sabArrow2;
                task.didContribute  = origTask.didContribute;
                task.Id             = origTask.Id;
                task.Index          = origTask.Index;
                task.LocationDirty  = origTask.LocationDirty;
                task.HasLocation    = origTask.HasLocation;
                task.MinigamePrefab = origTask.MinigamePrefab;
                task.StartAt        = sys;
                task.TaskType       = origTask.TaskType;
                task.Owner          = PlayerControl.LocalPlayer;

                polus.shipStatus.SpecialTasks = AssetHelper.AddToArr(polus.shipStatus.SpecialTasks, task);
                List <StringNames> list = new List <StringNames>(polus.shipStatus.SystemNames);
                list.Add(name);
                polus.shipStatus.SystemNames = list.ToArray();
                SabGenerator.AddSabotage(asset);
            }

            // Add to Polus
            AssetHelper.BuildColliders(asset, obj);
            polus.Add(obj, asset);

            return(true);
        }
Example #13
0
        public bool Build(MapAsset asset)
        {
            TaskData taskData = AssetDB.tasks[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = taskData.SpriteRenderer.sprite;
            spriteRenderer.material = taskData.SpriteRenderer.material;

            // Console
            Console origConsole = taskData.GameObj.GetComponent <Console>();
            Console console     = obj.AddComponent <Console>();

            console.ConsoleId      = origConsole.ConsoleId;
            console.AllowImpostor  = false;
            console.checkWalls     = false;
            console.GhostsIgnored  = false;
            console.Image          = spriteRenderer;
            console.onlyFromBelow  = true;
            console.onlySameRoom   = false;
            console.usableDistance = 1;
            console.TaskTypes      = origConsole.TaskTypes;
            console.ValidTasks     = origConsole.ValidTasks;
            polus.Add(obj, asset);

            // Box Collider
            if (taskData.GameObj.GetComponent <CircleCollider2D>() != null)
            {
                CircleCollider2D origBox = taskData.GameObj.GetComponent <CircleCollider2D>();
                CircleCollider2D box     = obj.AddComponent <CircleCollider2D>();
                box.radius    = origBox.radius;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else
            {
                BoxCollider2D origBox = taskData.GameObj.GetComponent <BoxCollider2D>();
                BoxCollider2D box     = obj.AddComponent <BoxCollider2D>();
                box.size      = origBox.size;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }

            // Button
            PassiveButton origBtn = taskData.GameObj.GetComponent <PassiveButton>();
            PassiveButton btn     = obj.AddComponent <PassiveButton>();

            btn.ClickMask   = origBtn.ClickMask;
            btn.OnMouseOver = new UnityEvent();
            btn.OnMouseOut  = new UnityEvent();
            Action action = console.Use;

            btn.OnClick.AddListener(action);

            // Task
            NormalPlayerTask origTask = taskData.Behavior;
            NormalPlayerTask task     = taskMgr.AddComponent <NormalPlayerTask>();

            //task.Arrow = origTask.Arrow;
            task.taskStep       = origTask.taskStep;
            task.MaxStep        = origTask.MaxStep;
            task.arrowSuspended = origTask.arrowSuspended;
            task.ShowTaskTimer  = origTask.ShowTaskTimer;
            task.ShowTaskStep   = origTask.ShowTaskStep;
            task.TaskTimer      = origTask.TaskTimer;
            task.TimerStarted   = origTask.TimerStarted;
            task.StartAt        = origTask.StartAt;
            task.TaskType       = origTask.TaskType;
            task.MinigamePrefab = origTask.MinigamePrefab;
            task.HasLocation    = origTask.HasLocation;
            task.LocationDirty  = origTask.LocationDirty;

            // Apply to Task List
            polus.shipStatus.AllConsoles = AssetBuilder.AddToArr(polus.shipStatus.AllConsoles, console);
            if (taskData.TaskType == TaskType.Common)
            {
                polus.shipStatus.CommonTasks = AssetBuilder.AddToArr(polus.shipStatus.CommonTasks, task);
            }
            if (taskData.TaskType == TaskType.Short)
            {
                polus.shipStatus.NormalTasks = AssetBuilder.AddToArr(polus.shipStatus.NormalTasks, task);
            }
            if (taskData.TaskType == TaskType.Long)
            {
                polus.shipStatus.LongTasks = AssetBuilder.AddToArr(polus.shipStatus.LongTasks, task);
            }

            return(true);
        }