public Optional <RotationMetadata> From(object baseGhost) { RotationMetadata rotationMetadata = null; if (baseGhost is BaseAddCorridorGhost) { BaseAddCorridorGhost corridorGhost = baseGhost as BaseAddCorridorGhost; int rotation = (int)corridorGhost.ReflectionGet("rotation"); rotationMetadata = new CorridorRotationMetadata(rotation); } else if (baseGhost is BaseAddMapRoomGhost) { BaseAddMapRoomGhost mapRoomGhost = baseGhost as BaseAddMapRoomGhost; Base.CellType cellType = (Base.CellType)mapRoomGhost.ReflectionGet("cellType"); int connectionMask = (int)mapRoomGhost.ReflectionGet("connectionMask"); rotationMetadata = new MapRoomRotationMetadata((byte)cellType, connectionMask); } else if (baseGhost is BaseAddModuleGhost) { BaseAddModuleGhost module = baseGhost as BaseAddModuleGhost; Int3 cell = module.anchoredFace.Value.cell; int direction = (int)module.anchoredFace.Value.direction; rotationMetadata = new BaseModuleRotationMetadata(cell, direction); } return(Optional.OfNullable(rotationMetadata)); }
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(); } }
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"); } }
public void PlaceBasePiece(BaseGhost baseGhost, ConstructableBase constructableBase, Base targetBase, TechType techType, Quaternion quaternion) { if (!Builder.isPlacing) //prevent possible echoing { return; } string guid = GuidHelper.GetGuid(constructableBase.gameObject); string parentBaseGuid = (targetBase == null) ? null : GuidHelper.GetGuid(targetBase.gameObject); Vector3 placedPosition = constructableBase.gameObject.transform.position; Transform camera = Camera.main.transform; Optional <RotationMetadata> rotationMetadata = RotationMetadata.From(baseGhost); BasePiece basePiece = new BasePiece(guid, placedPosition, quaternion, camera.position, camera.rotation, techType, Optional <string> .OfNullable(parentBaseGuid), false, rotationMetadata); PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece); packetSender.Send(placedBasePiece); }
public Optional <RotationMetadata> From(object baseGhost) { RotationMetadata rotationMetadata = null; if (baseGhost is BaseAddCorridorGhost) { BaseAddCorridorGhost corridorGhost = baseGhost as BaseAddCorridorGhost; int rotation = (int)corridorGhost.ReflectionGet("rotation"); rotationMetadata = new CorridorRotationMetadata(rotation); } else if (baseGhost is BaseAddMapRoomGhost) { BaseAddMapRoomGhost mapRoomGhost = baseGhost as BaseAddMapRoomGhost; Base.CellType cellType = (Base.CellType)mapRoomGhost.ReflectionGet("cellType"); int connectionMask = (int)mapRoomGhost.ReflectionGet("connectionMask"); rotationMetadata = new MapRoomRotationMetadata((byte)cellType, connectionMask); } return(Optional <RotationMetadata> .OfNullable(rotationMetadata)); }
public Optional <RotationMetadata> From(object baseGhost) { RotationMetadata rotationMetadata = null; if (baseGhost is BaseAddCorridorGhost) { BaseAddCorridorGhost corridorGhost = baseGhost as BaseAddCorridorGhost; int rotation = (int)corridorGhost.rotation; rotationMetadata = new CorridorRotationMetadata(rotation); } else if (baseGhost is BaseAddMapRoomGhost) { BaseAddMapRoomGhost mapRoomGhost = baseGhost as BaseAddMapRoomGhost; Base.CellType cellType = mapRoomGhost.cellType; int connectionMask = mapRoomGhost.connectionMask; rotationMetadata = new MapRoomRotationMetadata((byte)cellType, connectionMask); } else if (baseGhost is BaseAddModuleGhost) { BaseAddModuleGhost module = baseGhost as BaseAddModuleGhost; Int3 cell = module.anchoredFace.Value.cell; int direction = (int)module.anchoredFace.Value.direction; rotationMetadata = new BaseModuleRotationMetadata(cell.ToDto(), direction); } else if (baseGhost is BaseAddFaceGhost) { BaseAddFaceGhost faceGhost = baseGhost as BaseAddFaceGhost; if (faceGhost.anchoredFace.HasValue) { Base.Face anchoredFace = faceGhost.anchoredFace.Value; rotationMetadata = new AnchoredFaceRotationMetadata(anchoredFace.cell.ToDto(), (int)anchoredFace.direction, (int)faceGhost.faceType); } } return(Optional.OfNullable(rotationMetadata)); }