Exemplo n.º 1
0
        private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadata rotationMetadata)
        {
            BaseGhost component = ghostModel.GetComponent <BaseGhost>();

            if (component == null)
            {
                Log.Error("Was unable to apply rotation metadata - no BaseGhost found");
            }
            else if (component.GetType() != rotationMetadata.GhostType)
            {
                Log.Error("Was unable to apply rotation metadata - " + component.GetType() + " did not match " + rotationMetadata.GhostType);
            }
            else if (component is BaseAddCorridorGhost corridor)
            {
                Log.Info("Placing BaseAddCorridorGhost Rotation Metadata");

                CorridorRotationMetadata corridorRotationMetadata = (CorridorRotationMetadata)rotationMetadata;
                corridor.rotation = corridorRotationMetadata.Rotation;

                int corridorType = corridor.CalculateCorridorType();
                corridor.ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass);
                corridor.RebuildGhostGeometry();
            }
            else if (component is BaseAddMapRoomGhost mapRoom)
            {
                Log.Info("Placing MapRoomRotationMetadata Rotation Metadata");

                MapRoomRotationMetadata mapRoomRotationMetadata = (MapRoomRotationMetadata)rotationMetadata;
                mapRoom.cellType       = (Base.CellType)mapRoomRotationMetadata.CellType;
                mapRoom.connectionMask = mapRoomRotationMetadata.ConnectionMask;

                mapRoom.ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType);
                mapRoom.RebuildGhostGeometry();
            }
            else if (component is BaseAddModuleGhost ghost)
            {
                BaseModuleRotationMetadata baseModuleRotationMetadata = (BaseModuleRotationMetadata)rotationMetadata;

                ghost.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
                ghost.RebuildGhostGeometry();
            }
            else if (component is BaseAddFaceGhost faceGhost)
            {
                AnchoredFaceRotationMetadata baseModuleRotationMetadata = (AnchoredFaceRotationMetadata)rotationMetadata;
                Log.Info("Applying BaseAddFaceGhost " + baseModuleRotationMetadata);

                Base.Face face = new(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
                faceGhost.anchoredFace = face;

                Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType;
                faceGhost.ghostBase.SetFace(face, faceType);

                faceGhost.RebuildGhostGeometry();
            }
        }
Exemplo n.º 2
0
        private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadata rotationMetadata)
        {
            BaseGhost component = ghostModel.GetComponent <BaseGhost>();

            if (component == null)
            {
                Log.Error("Was unable to apply rotation metadata - no BaseGhost found");
            }
            else if (component.GetType() != rotationMetadata.GhostType)
            {
                Log.Error("Was unable to apply rotation metadata - " + component.GetType() + " did not match " + rotationMetadata.GhostType);
            }
            else if (component is BaseAddCorridorGhost)
            {
                Log.Info("Placing BaseAddCorridorGhost Rotation Metadata");

                CorridorRotationMetadata corridorRotationMetadata = (rotationMetadata as CorridorRotationMetadata);
                BaseAddCorridorGhost     corridor = (component as BaseAddCorridorGhost);
                corridor.ReflectionSet("rotation", corridorRotationMetadata.Rotation);

                int  corridorType = (int)corridor.ReflectionCall("CalculateCorridorType");
                Base ghostBase    = (Base)corridor.ReflectionGet("ghostBase");
                ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass);
                corridor.ReflectionCall("RebuildGhostGeometry");
            }
            else if (component is BaseAddMapRoomGhost)
            {
                Log.Info("Placing MapRoomRotationMetadata Rotation Metadata");

                MapRoomRotationMetadata mapRoomRotationMetadata = (rotationMetadata as MapRoomRotationMetadata);
                BaseAddMapRoomGhost     mapRoom = (component as BaseAddMapRoomGhost);
                mapRoom.ReflectionSet("cellType", mapRoomRotationMetadata.CellType);
                mapRoom.ReflectionSet("connectionMask", mapRoomRotationMetadata.ConnectionMask);

                Base ghostBase = (Base)mapRoom.ReflectionGet("ghostBase");

                ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType);
                mapRoom.ReflectionCall("RebuildGhostGeometry");
            }
            else if (component is BaseAddModuleGhost)
            {
                BaseModuleRotationMetadata baseModuleRotationMetadata = (rotationMetadata as BaseModuleRotationMetadata);
                BaseAddModuleGhost         module = (component as BaseAddModuleGhost);

                module.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.Global(), (Base.Direction)baseModuleRotationMetadata.Direction);
                module.ReflectionCall("RebuildGhostGeometry");
            }
        }
Exemplo n.º 3
0
        private static void ApplyRotationMetadata(BaseGhost baseGhost, BuilderMetadata builderMetadata)
        {
            switch (baseGhost)
            {
            case BaseAddCorridorGhost corridor when builderMetadata is CorridorBuilderMetadata corridorRotationMetadata:
            {
                corridor.rotation = corridorRotationMetadata.Rotation;
                int corridorType = corridor.CalculateCorridorType();
                corridor.ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass);
                corridor.RebuildGhostGeometry();
                break;
            }

            case BaseAddMapRoomGhost mapRoom when builderMetadata is MapRoomBuilderMetadata mapRoomRotationMetadata:
            {
                mapRoom.cellType       = (Base.CellType)mapRoomRotationMetadata.CellType;
                mapRoom.connectionMask = mapRoomRotationMetadata.ConnectionMask;

                mapRoom.ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType);
                mapRoom.RebuildGhostGeometry();
                break;
            }

            case BaseAddModuleGhost ghost when builderMetadata is BaseModuleBuilderMetadata baseModuleRotationMetadata:
            {
                ghost.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
                ghost.RebuildGhostGeometry();
                break;
            }

            case BaseAddFaceGhost faceGhost when builderMetadata is AnchoredFaceBuilderMetadata baseModuleRotationMetadata:
            {
                Base.Face face = new(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
                faceGhost.anchoredFace = face;

                Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType;
                faceGhost.ghostBase.SetFace(face, faceType);

                faceGhost.RebuildGhostGeometry();
                break;
            }

            default:
                Log.Error($"Was unable to apply rotation metadata for {baseGhost.GetType()} and {builderMetadata}");
                break;
            }
        }
Exemplo n.º 4
0
        static public void Place(GameObject gameObject, GameObject target, BaseGhost baseGhost, TechType tech, bool furniture)
        {
            if (Multiplayer.main.blocked)
            {
                return;
            }

            var res = new ClientBuildConstruct();

            res.tech             = tech;
            res.furniture        = furniture;
            res.objectGuid       = GuidHelper.Get(gameObject);
            res.targetGuid       = GuidHelper.Get(target);
            res.subGuid          = GuidHelper.Get(Player.main.GetCurrentSub()?.gameObject);
            res.cameraPosition   = MainCamera.camera.transform.position;
            res.cameraRotation   = MainCamera.camera.transform.rotation;
            res.additiveRotation = Builder.additiveRotation;

            if (furniture == false)
            {
                res.objectPosition = gameObject.transform.position;
                res.objectRotation = gameObject.transform.rotation;
            }
            else
            {
                res.objectPosition = gameObject.transform.localPosition;
                res.objectRotation = gameObject.transform.localRotation;
            }

            if (baseGhost != null)
            {
                Log.Info("Base ghost: type:{0}, target:{1}",
                         baseGhost.GetType().FullName,
                         baseGhost.targetOffset);

                res.ghostGuid = GuidHelper.Get(baseGhost.gameObject);

                var corridorGhost = baseGhost as BaseAddCorridorGhost;
                if (corridorGhost != null)
                {
                    res.direction = (int)corridorGhost.ReflectionGet("rotation");
                }

                var addModuleGhost = baseGhost as BaseAddModuleGhost;
                if (addModuleGhost != null)
                {
                    res.direction = (int)(Base.Direction)addModuleGhost.ReflectionGet("direction");
                }

                var addMapRoom = baseGhost as BaseAddMapRoomGhost;
                if (addMapRoom != null)
                {
                    res.direction = (int)(Base.CellType)addMapRoom.ReflectionGet("cellType");
                }

                var addFaceGhost = baseGhost as BaseAddFaceGhost;
                if (addFaceGhost != null)
                {
                    res.anchor  = addFaceGhost.TargetBase.GetAnchor();
                    res.face    = addFaceGhost.anchoredFace.GetValueOrDefault();
                    res.hasFace = addFaceGhost.anchoredFace.HasValue;
                }
            }

            // Log.Info("Sending ClientBuildConstruct: {0}, {1}, {2}, {3}", res.tech, res.objectGuid, res.targetGuid, res.objectPosition);

            Multiplayer.main.Send(res);

            // ShinkaiPatcher.Unity.SceneDumper.DumpScene();
        }