Exemplo n.º 1
0
        public static IQSBQuantumObject GetObject(QuantumObject unityObject)
        {
            IQSBQuantumObject worldObj = null;

            if (unityObject.GetType() == typeof(SocketedQuantumObject) || unityObject.GetType() == typeof(QuantumShrine))
            {
                worldObj = QSBWorldSync.GetWorldFromUnity <QSBSocketedQuantumObject, SocketedQuantumObject>((SocketedQuantumObject)unityObject);
            }
            else if (unityObject.GetType() == typeof(MultiStateQuantumObject))
            {
                worldObj = QSBWorldSync.GetWorldFromUnity <QSBMultiStateQuantumObject, MultiStateQuantumObject>((MultiStateQuantumObject)unityObject);
            }
            else if (unityObject.GetType() == typeof(QuantumShuffleObject))
            {
                worldObj = QSBWorldSync.GetWorldFromUnity <QSBQuantumShuffleObject, QuantumShuffleObject>((QuantumShuffleObject)unityObject);
            }
            else if (unityObject.GetType() == typeof(QuantumMoon))
            {
                worldObj = QSBWorldSync.GetWorldFromUnity <QSBQuantumMoon, QuantumMoon>((QuantumMoon)unityObject);
            }
            else if (unityObject.GetType() == typeof(EyeProxyQuantumMoon))
            {
                worldObj = QSBWorldSync.GetWorldFromUnity <QSBEyeProxyQuantumMoon, EyeProxyQuantumMoon>((EyeProxyQuantumMoon)unityObject);
            }
            else
            {
                DebugLog.ToConsole($"Warning - couldn't work out type of QuantumObject {unityObject.name}.", MessageType.Warning);
            }
            return(worldObj);
        }
Exemplo n.º 2
0
        public static bool Shrine_ChangeQuantumState(QuantumShrine __instance)
        {
            var shrineWorldObject = QSBWorldSync.GetWorldFromUnity <QSBSocketedQuantumObject, SocketedQuantumObject>(__instance);
            var isInControl       = shrineWorldObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId;

            return(isInControl);
        }
Exemplo n.º 3
0
        public static bool Shuffle_ChangeQuantumState(
            QuantumShuffleObject __instance,
            ref List <int> ____indexList,
            ref Vector3[] ____localPositions,
            ref Transform[] ____shuffledObjects,
            ref bool __result)
        {
            var shuffleWorldObject = QSBWorldSync.GetWorldFromUnity <QSBQuantumShuffleObject, QuantumShuffleObject>(__instance);

            if (shuffleWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId)
            {
                return(false);
            }

            ____indexList.Clear();
            ____indexList = Enumerable.Range(0, ____localPositions.Length).ToList();
            for (var i = 0; i < ____indexList.Count; ++i)
            {
                var random = UnityEngine.Random.Range(i, ____indexList.Count);
                var temp   = ____indexList[i];
                ____indexList[i]      = ____indexList[random];
                ____indexList[random] = temp;
            }
            for (var j = 0; j < ____shuffledObjects.Length; j++)
            {
                ____shuffledObjects[j].localPosition = ____localPositions[____indexList[j]];
            }
            QSBEventManager.FireEvent(
                EventNames.QSBQuantumShuffle,
                shuffleWorldObject.ObjectId,
                ____indexList.ToArray());
            __result = true;
            return(false);
        }
Exemplo n.º 4
0
        public static bool MultiState_Start(MultiStateQuantumObject __instance, Sector ____sector, bool ____collapseOnStart)
        {
            var qsbObj = QSBWorldSync.GetWorldFromUnity <QSBMultiStateQuantumObject, MultiStateQuantumObject>(__instance);

            if (qsbObj.ControllingPlayer == 0)
            {
                return(true);
            }

            foreach (var state in qsbObj.QuantumStates)
            {
                if (!state.IsMeantToBeEnabled)
                {
                    state.SetVisible(false);
                }
            }

            if (____sector == null)
            {
                __instance.GetType().GetMethod("CheckEnabled", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null);
            }
            if (____collapseOnStart)
            {
                __instance.GetType().GetMethod("Collapse", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true });
            }

            return(false);
        }
Exemplo n.º 5
0
        public static void Socketed_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket)
        {
            if (socket == null)
            {
                DebugLog.ToConsole($"Error - Trying to move {__instance.name} to a null socket!", MessageType.Error);
                return;
            }
            var objectWorldObject = QSBWorldSync.GetWorldFromUnity <QSBSocketedQuantumObject, SocketedQuantumObject>(__instance);
            var socketWorldObject = QSBWorldSync.GetWorldFromUnity <QSBQuantumSocket, QuantumSocket>(socket);

            if (objectWorldObject == null)
            {
                DebugLog.ToConsole($"Worldobject is null for {__instance.name}!");
                return;
            }

            if (objectWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId)
            {
                return;
            }

            QSBEventManager.FireEvent(
                EventNames.QSBSocketStateChange,
                objectWorldObject.ObjectId,
                socketWorldObject.ObjectId,
                __instance.transform.localRotation);
        }
        public override void Serialize(QNetworkWriter writer)
        {
            base.Serialize(writer);
            writer.Write(ObjectId);
            writer.Write(Position);
            writer.Write(Normal);
            var qsbSector = QSBWorldSync.GetWorldFromUnity <QSBSector, Sector>(Sector);

            writer.Write(qsbSector.ObjectId);
        }
Exemplo n.º 7
0
        private void Handler(Campfire campfire, bool roasting)
        {
            if (campfire == null)
            {
                SendEvent(CreateMessage(-1, roasting));
                return;
            }
            var qsbObj = QSBWorldSync.GetWorldFromUnity <QSBCampfire, Campfire>(campfire);

            SendEvent(CreateMessage(qsbObj.ObjectId, roasting));
        }
Exemplo n.º 8
0
        public static bool MultiState_ChangeQuantumState(MultiStateQuantumObject __instance)
        {
            var qsbObj = QSBWorldSync.GetWorldFromUnity <QSBMultiStateQuantumObject, MultiStateQuantumObject>(__instance);

            if (qsbObj.ControllingPlayer == 0 && qsbObj.CurrentState == -1)
            {
                return(true);
            }
            var isInControl = qsbObj.ControllingPlayer == QSBPlayerManager.LocalPlayerId;

            return(isInControl);
        }
Exemplo n.º 9
0
 public override void Init(T attachedObject, int id)
 {
     InitialParent   = attachedObject.transform.parent;
     InitialPosition = attachedObject.transform.localPosition;
     InitialRotation = attachedObject.transform.localRotation;
     InitialSector   = QSBWorldSync.GetWorldFromUnity <QSBSector, Sector>(attachedObject.GetSector());
     if (InitialParent.GetComponent <OWItemSocket>() != null)
     {
         var qsbObj = ItemManager.GetObject(InitialParent.GetComponent <OWItemSocket>());
         InitialSocket = qsbObj;
     }
     QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
 }
Exemplo n.º 10
0
        private void AddSector(Sector sector)
        {
            var worldObject = QSBWorldSync.GetWorldFromUnity <QSBSector, Sector>(sector);

            if (worldObject == null)
            {
                DebugLog.ToConsole($"Error - Can't find QSBSector for sector {sector.name}!", MessageType.Error);
            }
            if (SectorList.Contains(worldObject))
            {
                DebugLog.ToConsole($"Warning - Trying to add {sector.name} for {gameObject.name}, but is already in list", MessageType.Warning);
                return;
            }
            SectorList.Add(worldObject);
        }
Exemplo n.º 11
0
        public static bool Campfire_OnPressInteract(Campfire __instance, Campfire.State ____state)
        {
            var qsbCampfire = QSBWorldSync.GetWorldFromUnity <QSBCampfire, Campfire>(__instance);

            if (____state == Campfire.State.LIT)
            {
                qsbCampfire.StartRoasting();
            }
            else
            {
                qsbCampfire.SetState(Campfire.State.LIT);
                QSBEventManager.FireEvent(EventNames.QSBCampfireState, qsbCampfire.ObjectId, Campfire.State.LIT);
                Locator.GetFlashlight().TurnOff(false);
            }
            return(false);
        }
Exemplo n.º 12
0
        public static void QuantumState_SetVisible(QuantumState __instance, bool visible)
        {
            if (!visible)
            {
                return;
            }
            var allMultiStates = QSBWorldSync.GetWorldObjects <QSBMultiStateQuantumObject>();
            var stateObject    = QSBWorldSync.GetWorldFromUnity <QSBQuantumState, QuantumState>(__instance);
            var owner          = allMultiStates.First(x => x.QuantumStates.Contains(stateObject));

            if (owner.ControllingPlayer != QSBPlayerManager.LocalPlayerId)
            {
                return;
            }
            var stateIndex = owner.QuantumStates.IndexOf(stateObject);

            QSBEventManager.FireEvent(
                EventNames.QSBMultiStateChange,
                owner.ObjectId,
                stateIndex);
        }
Exemplo n.º 13
0
 public override void Init(MultiStateQuantumObject attachedObject, int id)
 {
     ObjectId       = id;
     AttachedObject = attachedObject;
     QuantumStates  = AttachedObject.GetValue <QuantumState[]>("_states").ToList().Select(x => QSBWorldSync.GetWorldFromUnity <QSBQuantumState, QuantumState>(x)).ToList();
     if (QSBCore.DebugMode)
     {
         DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, CurrentState.ToString()).GetComponent <Text>();
     }
     base.Init(attachedObject, id);
 }
Exemplo n.º 14
0
        public static bool Socketed_ChangeQuantumState(
            SocketedQuantumObject __instance,
            ref bool __result,
            bool skipInstantVisibilityCheck,
            List <QuantumSocket> ____childSockets,
            List <QuantumSocket> ____socketList,
            ref QuantumSocket ____recentlyObscuredSocket,
            QuantumSocket ____occupiedSocket)
        {
            var socketedWorldObject = QSBWorldSync.GetWorldFromUnity <QSBSocketedQuantumObject, SocketedQuantumObject>(__instance);

            if (socketedWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId)
            {
                return(false);
            }

            foreach (var socket in ____childSockets)
            {
                if (socket.IsOccupied())
                {
                    __result = false;
                    return(false);
                }
            }

            if (____socketList.Count <= 1)
            {
                DebugLog.ToConsole($"Error - Not enough quantum sockets in list for {__instance.name}!", MessageType.Error);
                __result = false;
                return(false);
            }

            var list = new List <QuantumSocket>();

            foreach (var socket in ____socketList)
            {
                if (!socket.IsOccupied() && socket.IsActive())
                {
                    list.Add(socket);
                }
            }

            if (list.Count == 0)
            {
                __result = false;
                return(false);
            }

            if (____recentlyObscuredSocket != null)
            {
                __instance.GetType().GetMethod("MoveToSocket", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____recentlyObscuredSocket });
                ____recentlyObscuredSocket = null;
                __result = true;
                return(false);
            }

            var occupiedSocket = ____occupiedSocket;

            for (var i = 0; i < 20; i++)
            {
                var index = UnityEngine.Random.Range(0, list.Count);
                __instance.GetType().GetMethod("MoveToSocket", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { list[index] });
                if (skipInstantVisibilityCheck)
                {
                    __result = true;
                    return(false);
                }
                bool socketNotSuitable;
                var  isSocketIlluminated = (bool)__instance.GetType().GetMethod("CheckIllumination", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null);

                var playersEntangled = QuantumManager.GetEntangledPlayers(__instance);
                if (playersEntangled.Count() != 0)
                {
                    // socket not suitable if illuminated
                    socketNotSuitable = isSocketIlluminated;
                }
                else
                {
                    var checkVisInstant = (bool)__instance.GetType().GetMethod("CheckVisibilityInstantly", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, null);
                    if (isSocketIlluminated)
                    {
                        // socket not suitable if object is visible
                        socketNotSuitable = checkVisInstant;
                    }
                    else
                    {
                        // socket not suitable if player is inside object
                        socketNotSuitable = playersEntangled.Any(x => __instance.CheckPointInside(x.CameraBody.transform.position));
                    }
                }

                if (!socketNotSuitable)
                {
                    __result = true;
                    return(false);
                }
                list.RemoveAt(index);
                if (list.Count == 0)
                {
                    break;
                }
            }
            __instance.GetType().GetMethod("MoveToSocket", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { occupiedSocket });
            __result = false;
            return(false);
        }