Esempio n. 1
0
        public void BroadcastArmAction(TechType techType, IExosuitArm exosuitArm, ExosuitArmAction armAction, Optional <Vector3> opVector = null, Optional <Quaternion> opRotation = null)
        {
            NitroxId id = NitroxIdentifier.GetId(exosuitArm.GetGameObject());
            ExosuitArmActionPacket packet = new ExosuitArmActionPacket(techType, id, armAction, opVector, opRotation);

            packetSender.Send(packet);
        }
        public static List <InteractiveChildObjectIdentifier> ExtractInteractiveChildren(GameObject constructedObject)
        {
            List <InteractiveChildObjectIdentifier> interactiveChildren = new List <InteractiveChildObjectIdentifier>();

            string constructedObjectsName = constructedObject.GetFullName();

            foreach (Type type in interactiveChildTypes)
            {
                Component[] components = constructedObject.GetComponentsInChildren(type, true);

                foreach (Component component in components)
                {
                    NitroxId id               = NitroxIdentifier.GetId(component.gameObject);
                    string   componentName    = component.gameObject.GetFullName();
                    string   relativePathName = componentName.Replace(constructedObjectsName, "");

                    // It can happen, that the game object is the constructed object itself. This code prevents to add itself to the child objects
                    if (relativePathName.Length != 0)
                    {
                        relativePathName = relativePathName.TrimStart('/');
                        interactiveChildren.Add(new InteractiveChildObjectIdentifier(id, relativePathName));
                    }
                }
            }

            return(interactiveChildren);
        }
Esempio n. 3
0
        public static void Prefix(Base __instance)
        {
            if (__instance == null)
            {
                return;
            }

            Transform[] cellObjects = (Transform[] )__instance.ReflectionGet("cellObjects");

            if (cellObjects == null)
            {
                return;
            }

            foreach (Transform cellObject in cellObjects)
            {
                if (cellObject != null)
                {
                    for (int i = 0; i < cellObject.childCount; i++)
                    {
                        Transform child = cellObject.GetChild(i);

                        if (child != null && child.gameObject != null)
                        {
                            if (child.gameObject.GetComponent <UniqueIdentifier>() != null)
                            {
                                NitroxId id  = NitroxIdentifier.GetId(child.gameObject);
                                string   key = getObjectKey(child.gameObject.name, child.position);
                                NitroxIdByObjectKey[key] = id;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public static void Postfix(CyclopsFireSuppressionSystemButton __instance)
        {
            SubRoot  cyclops = __instance.subRoot;
            NitroxId id      = NitroxIdentifier.GetId(cyclops.gameObject);

            NitroxServiceLocator.LocateService <Cyclops>().BroadcastActivateFireSuppression(id);
        }
Esempio n. 5
0
        public static void Prefix(BaseDeconstructable __instance)
        {
            NitroxId id = NitroxIdentifier.GetId(__instance.gameObject);

            Log.Info("Deconstructing " + id);
            TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, id);
        }
Esempio n. 6
0
        public void BroadcastItemRemoval(Pickupable pickupable, Transform ownerTransform)
        {
            NitroxId ownerId = null;

            bool isCyclopsLocker    = Regex.IsMatch(ownerTransform.gameObject.name, @"Locker0([0-9])StorageRoot$", RegexOptions.IgnoreCase);
            bool isEscapePodStorage = ownerTransform.parent.name.StartsWith("EscapePod");

            if (isCyclopsLocker)
            {
                ownerId = GetCyclopsLockerId(ownerTransform);
            }
            else if (isEscapePodStorage)
            {
                ownerId = GetEscapePodStorageId(ownerTransform);
            }
            else
            {
                ownerId = NitroxIdentifier.GetId(ownerTransform.transform.parent.gameObject);
            }

            NitroxId            itemId = NitroxIdentifier.GetId(pickupable.gameObject);
            ItemContainerRemove remove = new ItemContainerRemove(ownerId, itemId);

            packetSender.Send(remove);
        }
Esempio n. 7
0
        public void BroadcastOnPilotModeChanged(Vehicle vehicle, bool isPiloting)
        {
            ushort playerId = multiplayerSession.Reservation.PlayerId;

            VehicleOnPilotModeChanged packet = new VehicleOnPilotModeChanged(NitroxIdentifier.GetId(vehicle.gameObject), playerId, isPiloting);
            packetSender.Send(packet);
        }
Esempio n. 8
0
        /// <summary>
        /// Send out a <see cref="CyclopsDamage"/> packet
        /// </summary>
        private void BroadcastDamageState(SubRoot subRoot, Optional <DamageInfo> info)
        {
            NitroxId  subId     = NitroxIdentifier.GetId(subRoot.gameObject);
            LiveMixin subHealth = subRoot.gameObject.RequireComponent <LiveMixin>();

            if (subHealth.health > 0)
            {
                CyclopsDamageInfoData damageInfo = null;

                if (info.IsPresent())
                {
                    DamageInfo damage = info.Get();
                    // Source of the damage. Used if the damage done to the Cyclops was not calculated on other clients. Currently it's just used to figure out what sounds and
                    // visual effects should be used.
                    CyclopsDamageInfoData serializedDamageInfo = new CyclopsDamageInfoData(subId,
                                                                                           damage.dealer != null ? NitroxIdentifier.GetId(damage.dealer) : null,
                                                                                           damage.originalDamage,
                                                                                           damage.damage,
                                                                                           damage.position,
                                                                                           damage.type);
                }

                int[]             damagePointIndexes = GetActiveDamagePoints(subRoot).ToArray();
                CyclopsFireData[] firePoints         = GetActiveRoomFires(subRoot.GetComponent <SubFire>()).ToArray();

                CyclopsDamage packet = new CyclopsDamage(subId, subRoot.GetComponent <LiveMixin>().health, subRoot.damageManager.subLiveMixin.health, subRoot.GetComponent <SubFire>().liveMixin.health, damagePointIndexes, firePoints, damageInfo);
                packetSender.Send(packet);
            }
            else
            {
                // RIP
                CyclopsDestroyed packet = new CyclopsDestroyed(subId);
                packetSender.Send(packet);
            }
        }
Esempio n. 9
0
        public static void Postfix(CyclopsSonarButton __instance)
        {
            NitroxId id          = NitroxIdentifier.GetId(__instance.subRoot.gameObject);
            bool     activeSonar = Traverse.Create(__instance).Field("sonarActive").GetValue <bool>();

            NitroxServiceLocator.LocateService <Cyclops>().BroadcastChangeSonarState(id, activeSonar);
        }
Esempio n. 10
0
        public void FabricatorCrafingStarted(GameObject crafter, TechType techType, float duration)
        {
            NitroxId crafterId = NitroxIdentifier.GetId(crafter);
            FabricatorBeginCrafting fabricatorBeginCrafting = new FabricatorBeginCrafting(crafterId, techType.Model(), duration);

            packetSender.Send(fabricatorBeginCrafting);
        }
Esempio n. 11
0
        public void ConstructionComplete(GameObject ghost)
        {
            NitroxId          baseId            = null;
            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            NitroxId id = NitroxIdentifier.GetId(ghost);

            if (opConstructedBase.IsPresent())
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Get();
                baseId = NitroxIdentifier.GetId(constructedBase);
            }

            // For base pieces, we must switch the id from the ghost to the newly constructed piece.
            // Furniture just uses the same game object as the ghost for the final product.
            if (ghost.GetComponent <ConstructableBase>() != null)
            {
                Optional <object> opBasePiece   = TransientLocalObjectManager.Get(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE);
                GameObject        finishedPiece = (GameObject)opBasePiece.Get();

                UnityEngine.Object.Destroy(ghost);
                NitroxIdentifier.SetNewId(finishedPiece, id);

                if (baseId == null)
                {
                    baseId = NitroxIdentifier.GetId(finishedPiece.GetComponentInParent <Base>().gameObject);
                }
            }

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(id, baseId);

            packetSender.Send(constructionCompleted);
        }
        public static bool Prefix(DockedVehicleHandTarget __instance, GUIHand hand)
        {
            vehicleDockingBay = __instance.dockingBay;
            Vehicle vehicle = vehicleDockingBay.GetDockedVehicle();

            if (skipPrefix || vehicle == null)
            {
                return(true);
            }

            dockedVehicle = __instance;
            guiHand       = hand;

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            NitroxId id = NitroxIdentifier.GetId(vehicle.gameObject);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on this vehicle: {id}");
                return(true);
            }

            simulationOwnership.RequestSimulationLock(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse);

            return(false);
        }
Esempio n. 13
0
        public void BroadcastItemAdd(Pickupable pickupable, Transform ownerTransform)
        {
            NitroxId ownerId            = null;
            bool     isCyclopsLocker    = Regex.IsMatch(ownerTransform.gameObject.name, @"Locker0([0-9])StorageRoot$", RegexOptions.IgnoreCase);
            bool     isEscapePodStorage = ownerTransform.parent.name.StartsWith("EscapePod");

            if (isCyclopsLocker)
            {
                ownerId = GetCyclopsLockerId(ownerTransform);
            }
            else if (isEscapePodStorage)
            {
                ownerId = GetEscapePodStorageId(ownerTransform);
            }
            else
            {
                ownerId = NitroxIdentifier.GetId(ownerTransform.transform.parent.gameObject);
            }

            NitroxId itemId = NitroxIdentifier.GetId(pickupable.gameObject);

            byte[] bytes = SerializationHelper.GetBytes(pickupable.gameObject);

            ItemData         itemData = new ItemData(ownerId, itemId, bytes);
            ItemContainerAdd add      = new ItemContainerAdd(itemData);

            packetSender.Send(add);
        }
Esempio n. 14
0
        public void PlaceFurniture(GameObject gameObject, TechType techType, Vector3 itemPosition, Quaternion quaternion)
        {
            if (!Builder.isPlacing) //prevent possible echoing
            {
                return;
            }

            NitroxId id = NitroxIdentifier.GetId(gameObject);

            Optional <NitroxId> subId = Optional <NitroxId> .Empty();

            SubRoot sub = Player.main.currentSub;

            if (sub != null)
            {
                subId = Optional <NitroxId> .Of(NitroxIdentifier.GetId(sub.gameObject));
            }

            Transform camera = Camera.main.transform;
            Optional <RotationMetadata> rotationMetadata = Optional <RotationMetadata> .Empty();

            BasePiece      basePiece       = new BasePiece(id, itemPosition, quaternion, camera.position, camera.rotation, techType.Model(), subId, true, rotationMetadata);
            PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece);

            packetSender.Send(placedBasePiece);
        }
Esempio n. 15
0
        public void BroadcastVehicleDocking(VehicleDockingBay dockingBay, Vehicle vehicle)
        {
            NitroxId dockId;

            if (dockingBay.GetSubRoot() is BaseRoot)
            {
                dockId = NitroxIdentifier.GetId(dockingBay.GetComponentInParent<BaseRoot>().gameObject);
            }
            else if (dockingBay.GetSubRoot() is SubRoot)
            {
                dockId = NitroxIdentifier.GetId(dockingBay.GetSubRoot().gameObject);
            }
            else
            {
                dockId = NitroxIdentifier.GetId(dockingBay.GetComponentInParent<ConstructableBase>().gameObject);
            }

            NitroxId vehicleId = NitroxIdentifier.GetId(vehicle.gameObject);
            ushort playerId = multiplayerSession.Reservation.PlayerId;

            VehicleDocking packet = new VehicleDocking(vehicleId, dockId, playerId);
            packetSender.Send(packet);

            PacketSuppressor<Movement> movementSuppressor = packetSender.Suppress<Movement>();
            vehicle.StartCoroutine(AllowMovementPacketsAfterDockingAnimation(movementSuppressor));
        }
Esempio n. 16
0
        public void PickedUp(GameObject gameObject, TechType techType)
        {
            NitroxId id           = NitroxIdentifier.GetId(gameObject);
            Vector3  itemPosition = gameObject.transform.position;

            PickedUp(itemPosition, id, techType);
        }
Esempio n. 17
0
        public void BroadcastDestroyedVehicle(Vehicle vehicle)
        {
            using (packetSender.Suppress<VehicleOnPilotModeChanged>())
            {
                NitroxId id = NitroxIdentifier.GetId(vehicle.gameObject);
                LocalPlayer localPlayer = NitroxServiceLocator.LocateService<LocalPlayer>();

                VehicleDestroyed vehicleDestroyed = new VehicleDestroyed(id, localPlayer.PlayerName, vehicle.GetPilotingMode());
                packetSender.Send(vehicleDestroyed);
                
                // If there is a pilotId then there is a remote player.  We must
                // detach the remote player before destroying the game object.
                if (!string.IsNullOrEmpty(vehicle.pilotId)) 
                {
                    ushort pilot = ushort.Parse(vehicle.pilotId);
                    Optional<RemotePlayer> remotePilot = playerManager.Find(pilot);

                    if (remotePilot.IsPresent())
                    {
                        RemotePlayer remotePlayer = remotePilot.Get();
                        remotePlayer.SetVehicle(null);
                        remotePlayer.SetSubRoot(null);
                        remotePlayer.SetPilotingChair(null);
                        remotePlayer.AnimationController.UpdatePlayerAnimations = true;
                    }
                }
            }
        }
Esempio n. 18
0
        public static bool Prefix(PilotingChair __instance, GUIHand hand)
        {
            if (skipPrefix)
            {
                return(true);
            }

            pilotingChair = __instance;
            guiHand       = hand;

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            SubRoot subRoot = __instance.GetComponentInParent <SubRoot>();

            Validate.NotNull(subRoot, "PilotingChair cannot find it's corresponding SubRoot!");
            NitroxId id = NitroxIdentifier.GetId(subRoot.gameObject);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on the piloting chair: {id}");
                return(true);
            }

            simulationOwnership.RequestSimulationLock(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse);

            return(false);
        }
Esempio n. 19
0
        public void BroadcastUnequip(Pickupable pickupable, GameObject owner, string slot)
        {
            NitroxId itemId = NitroxIdentifier.GetId(pickupable.gameObject);
            Player   player = owner.GetComponent <Player>();

            if (player != null)
            {
                TechType techType = pickupable.GetTechType();
                PlayerEquipmentRemoved equipmentAdded = new PlayerEquipmentRemoved(techType.Model(), itemId);
                packetSender.Send(equipmentAdded);

                return;
            }

            NitroxId ownerId = NitroxIdentifier.GetId(owner);

            if (pickupable.GetTechType() == TechType.VehicleStorageModule)
            {
                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(owner);
                VehicleChildUpdate vehicleChildInteractiveData           = new VehicleChildUpdate(ownerId, childIdentifiers);
                packetSender.Send(vehicleChildInteractiveData);
            }

            ModuleRemoved moduleRemoved = new ModuleRemoved(ownerId, slot, itemId);

            packetSender.Send(moduleRemoved);
        }
Esempio n. 20
0
        public void BroadcastEquip(Pickupable pickupable, GameObject owner, string slot)
        {
            NitroxId ownerId  = NitroxIdentifier.GetId(owner);
            NitroxId itemId   = NitroxIdentifier.GetId(pickupable.gameObject);
            TechType techType = pickupable.GetTechType();

            if (techType == TechType.VehicleStorageModule)
            {
                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(owner);
                VehicleChildUpdate vehicleChildInteractiveData           = new VehicleChildUpdate(ownerId, childIdentifiers);
                packetSender.Send(vehicleChildInteractiveData);
            }

            Transform parent = pickupable.gameObject.transform.parent;

            pickupable.gameObject.transform.SetParent(null);
            byte[] bytes = SerializationHelper.GetBytes(pickupable.gameObject);

            EquippedItemData equippedItem = new EquippedItemData(ownerId, itemId, bytes, slot, techType.Model());
            Player           player       = owner.GetComponent <Player>();

            if (player != null)
            {
                PlayerEquipmentAdded equipmentAdded = new PlayerEquipmentAdded(techType.Model(), equippedItem);
                packetSender.Send(equipmentAdded);
                pickupable.gameObject.transform.SetParent(parent);

                return;
            }

            ModuleAdded moduleAdded = new ModuleAdded(equippedItem);

            packetSender.Send(moduleAdded);
            pickupable.gameObject.transform.SetParent(parent);
        }
Esempio n. 21
0
        public void DeconstructionBegin(GameObject gameObject)
        {
            NitroxId id = NitroxIdentifier.GetId(gameObject);

            DeconstructionBegin deconstructionBegin = new DeconstructionBegin(id);

            packetSender.Send(deconstructionBegin);
        }
Esempio n. 22
0
        public void BroadcastItemRemoval(GameObject gameObject)
        {
            NitroxId id = NitroxIdentifier.GetId(gameObject);

            StorageSlotItemRemove slotItemRemove = new StorageSlotItemRemove(id);

            packetSender.Send(slotItemRemove);
        }
Esempio n. 23
0
        /// <summary>
        /// Triggered when <see cref="SubFire.CreateFire(SubFire.RoomFire)"/> is executed. To create a new fire manually,
        /// call <see cref="Create(string, Optional{string}, Optional{CyclopsRooms}, Optional{int})"/>
        /// </summary>
        public void OnCreate(Fire fire, SubFire.RoomFire room, int nodeIndex)
        {
            NitroxId subRootId = NitroxIdentifier.GetId(fire.fireSubRoot.gameObject);

            CyclopsFireCreated packet = new CyclopsFireCreated(NitroxIdentifier.GetId(fire.gameObject), subRootId, room.roomLinks.room, nodeIndex);

            packetSender.Send(packet);
        }
Esempio n. 24
0
        public void DeconstructionComplete(GameObject gameObject)
        {
            NitroxId id = NitroxIdentifier.GetId(gameObject);

            DeconstructionCompleted deconstructionCompleted = new DeconstructionCompleted(id);

            packetSender.Send(deconstructionCompleted);
        }
Esempio n. 25
0
        public static void Postfix(CyclopsShieldButton __instance)
        {
            NitroxId id = NitroxIdentifier.GetId(__instance.subRoot.gameObject);
            // Shield is activated, if activeSprite is set as sprite
            bool isActive = (__instance.activeSprite == __instance.image.sprite);

            NitroxServiceLocator.LocateService <Cyclops>().BroadcastChangeShieldState(id, isActive);
        }
Esempio n. 26
0
 public static void Postfix(CyclopsLightingPanel __instance, bool __state)
 {
     if (__state != __instance.lightingOn)
     {
         NitroxId id = NitroxIdentifier.GetId(__instance.cyclopsRoot.gameObject);
         NitroxServiceLocator.LocateService <Cyclops>().BroadcastToggleInternalLight(id, __instance.lightingOn);
     }
 }
Esempio n. 27
0
 public static void Postfix(CyclopsMotorModeButton __instance, bool __state)
 {
     if (__state)
     {
         SubRoot  cyclops = (SubRoot)__instance.ReflectionGet("subRoot");
         NitroxId id      = NitroxIdentifier.GetId(cyclops.gameObject);
         NitroxServiceLocator.LocateService <Cyclops>().BroadcastChangeEngineMode(id, __instance.motorModeIndex);
     }
 }
Esempio n. 28
0
        public static void Prefix(Vehicle __instance)
        {
            NitroxServiceLocator.LocateService <Vehicles>().BroadcastOnPilotModeChanged(__instance, false);

            NitroxId            id = NitroxIdentifier.GetId(__instance.gameObject);
            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            simulationOwnership.RequestSimulationLock(id, SimulationLockType.TRANSIENT, null);
        }
Esempio n. 29
0
        public static bool Prefix(CyclopsLightingPanel __instance)
        {
            // Suppress powered on if a cyclops´s floodlight is set to false
            GameObject   gameObject = __instance.gameObject;
            NitroxId     id         = NitroxIdentifier.GetId(gameObject);
            CyclopsModel model      = NitroxServiceLocator.LocateService <Vehicles>().GetVehicles <CyclopsModel>(id);

            return(model.FloodLightsOn);
        }
Esempio n. 30
0
        public void FabricatorItemPickedUp(GameObject gameObject, TechType techType)
        {
            NitroxId crafterId = NitroxIdentifier.GetId(gameObject);

            FabricatorItemPickup fabricatorItemPickup = new FabricatorItemPickup(crafterId, techType.Model());

            packetSender.Send(fabricatorItemPickup);
            Log.Debug(fabricatorItemPickup);
        }