Beispiel #1
0
        public void AddItem(GameObject item, NitroxId containerId)
        {
            Optional <GameObject> owner = NitroxIdentifier.GetObjectFrom(containerId);

            if (owner.IsEmpty())
            {
                Log.Info("Unable to find inventory container with id: " + containerId);
                return;
            }

            Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner.Get());

            if (opContainer.IsPresent())
            {
                ItemsContainer container  = opContainer.Get();
                Pickupable     pickupable = item.RequireComponent <Pickupable>();

                using (packetSender.Suppress <ItemContainerAdd>())
                {
                    container.UnsafeAdd(new InventoryItem(pickupable));
                }
            }
            else
            {
                Log.Error("Could not find container field on object " + owner.Get().name);
            }
        }
Beispiel #2
0
        public override void Process(ExosuitArmActionPacket packet)
        {
            Optional <GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(packet.ArmId);

            if (opGameObject.IsEmpty())
            {
                Log.Error("Could not find exosuit arm");
                return;
            }
            GameObject gameObject = opGameObject.Get();

            switch (packet.TechType)
            {
            case TechType.ExosuitClawArmModule:
                exosuitModuleEvent.UseClaw(gameObject.GetComponent <ExosuitClawArm>(), packet.ArmAction);
                break;

            case TechType.ExosuitDrillArmModule:
                exosuitModuleEvent.UseDrill(gameObject.GetComponent <ExosuitDrillArm>(), packet.ArmAction);
                break;

            case TechType.ExosuitGrapplingArmModule:
                exosuitModuleEvent.UseGrappling(gameObject.GetComponent <ExosuitGrapplingArm>(), packet.ArmAction, packet.OpVector);
                break;

            case TechType.ExosuitTorpedoArmModule:
                exosuitModuleEvent.UseTorpedo(gameObject.GetComponent <ExosuitTorpedoArm>(), packet.ArmAction, packet.OpVector, packet.OpRotation);
                break;

            default:
                Log.Error("Got an arm tech that is not handled: " + packet.TechType + " with action: " + packet.ArmAction + " for id " + packet.ArmId);
                break;
            }
        }
Beispiel #3
0
        public override void Process(EntityTransformUpdates packet)
        {
            foreach (EntityTransformUpdate entity in packet.Updates)
            {
                Optional <GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(entity.Id);

                if (opGameObject.IsPresent())
                {
                    GameObject gameObject = opGameObject.Get();

                    float         distance      = Vector3.Distance(gameObject.transform.position, entity.Position);
                    SwimBehaviour swimBehaviour = gameObject.GetComponent <SwimBehaviour>();

                    if (distance > 5 || swimBehaviour == null)
                    {
                        gameObject.transform.position = entity.Position;
                        gameObject.transform.rotation = entity.Rotation;
                    }
                    else
                    {
                        swimBehaviour.SwimTo(entity.Position, 3f);
                    }
                }
            }
        }
        public override void Process(CyclopsDestroyed packet)
        {
            Optional <GameObject> cyclops = NitroxIdentifier.GetObjectFrom(packet.Id);

            // Despite me telling it to kill itself when I call LiveMixin.TakeDamage with massive damage, it doesn't seem to trigger like it should.
            // To get around this problem, I manually set the health to 0, then call for Kill(). Since Kill() does not trigger the necessary events, I do
            // it all manually below. At least this way I can make the screen shake hard enough to cause motion sickness, or disable it if I wanted to.
            if (cyclops.IsPresent())
            {
                Log.Debug("[CyclopsDestroyedProcessor Id: " + packet.Id + "]");

                SubRoot subRoot = cyclops.Get().RequireComponent <SubRoot>();

                cyclops.Get().RequireComponent <LiveMixin>().ReflectionSet("health", 0f, true, false);
                cyclops.Get().RequireComponent <LiveMixin>().Kill();

                // Copied from SubRoot.OnTakeDamage(DamageInfo info)
                subRoot.voiceNotificationManager.ClearQueue();
                subRoot.voiceNotificationManager.PlayVoiceNotification(subRoot.abandonShipNotification, false, true);
                subRoot.Invoke("PowerDownCyclops", 13f);
                subRoot.Invoke("DestroyCyclopsSubRoot", 18f);
                float num = Vector3.Distance(subRoot.transform.position, Player.main.transform.position);
                if (num < 20f)
                {
                    MainCameraControl.main.ShakeCamera(1.5f, 20f, MainCameraControl.ShakeMode.Linear, 1f);
                }
                if (subRoot.damageManager != null)
                {
                    subRoot.damageManager.SendMessage("OnTakeDamage", null, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
Beispiel #5
0
        // As the normal spawn is suppressed, spawn default batteries afterwards
        private void SpawnDefaultBatteries(GameObject constructedObject, List <InteractiveChildObjectIdentifier> childIdentifiers)
        {
            Optional <EnergyMixin> opEnergy = Optional <EnergyMixin> .OfNullable(constructedObject.GetComponent <EnergyMixin>());

            if (opEnergy.IsPresent())
            {
                EnergyMixin mixin = opEnergy.Get();
                mixin.ReflectionSet("allowedToPlaySounds", false);
                mixin.SetBattery(mixin.defaultBattery, 1);
                mixin.ReflectionSet("allowedToPlaySounds", true);
            }

            foreach (InteractiveChildObjectIdentifier identifier in childIdentifiers)
            {
                Optional <GameObject> opChildGameObject = NitroxIdentifier.GetObjectFrom(identifier.Id);

                if (opChildGameObject.IsPresent())
                {
                    Optional <EnergyMixin> opEnergyMixin = Optional <EnergyMixin> .OfNullable(opChildGameObject.Get().GetComponent <EnergyMixin>());

                    if (opEnergyMixin.IsPresent())
                    {
                        EnergyMixin mixin = opEnergyMixin.Get();
                        mixin.ReflectionSet("allowedToPlaySounds", false);
                        mixin.SetBattery(mixin.defaultBattery, 1);
                        mixin.ReflectionSet("allowedToPlaySounds", true);
                    }
                }
            }
        }
Beispiel #6
0
 public void UpdateVehicleChildren(NitroxId id, List<InteractiveChildObjectIdentifier> interactiveChildrenGuids)
 {
     Optional<GameObject> Object = NitroxIdentifier.GetObjectFrom(id);
     if (Object.IsPresent())
     {
         GameObject T = Object.Get();
         VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(T, interactiveChildrenGuids);
     }
 }
        public override void Process(ItemPosition drop)
        {
            Optional <GameObject> opItem = NitroxIdentifier.GetObjectFrom(drop.Id);

            if (opItem.IsPresent())
            {
                MovementHelper.MoveRotateGameObject(opItem.Get(), drop.Position, drop.Rotation, ITEM_TRANSFORM_SMOOTH_PERIOD);
            }
        }
Beispiel #8
0
        public override void Process(CreatureActionChanged packet)
        {
            Optional <GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(packet.Id);

            if (opGameObject.IsPresent())
            {
                CreatureAction action = packet.NewAction.GetCreatureAction(opGameObject.Get());
                ActionByCreatureId[packet.Id] = action;
            }
        }
        public override void Process(PickupItem pickup)
        {
            Optional <GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(pickup.Id);

            if (opGameObject.IsPresent())
            {
                UnityEngine.Object.Destroy(opGameObject.Get());
                entities.RemoveEntity(pickup.Id);
            }
        }
Beispiel #10
0
        public void OnRadioRepair(NitroxId id)
        {
            Optional <GameObject> radObj = NitroxIdentifier.GetObjectFrom(id);

            if (radObj.IsPresent())
            {
                Radio radio = radObj.Get().GetComponent <Radio>();

                // StoryGoalManager.main.PulsePendingMessages();
                radio.liveMixin.health = radio.liveMixin.maxHealth;
                radio.repairNotification.Play();
            }
        }
        private void StartBroadcastingEntityPosition(NitroxId id)
        {
            Optional <GameObject> gameObject = NitroxIdentifier.GetObjectFrom(id);

            if (gameObject.IsPresent())
            {
                EntityPositionBroadcaster.WatchEntity(id, gameObject.Get());
            }
            else
            {
                Log.Error("Expected to simulate an unknown entity: " + id);
            }
        }
Beispiel #12
0
        private void UpdatePosition(Entity entity)
        {
            Optional <GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(entity.Id);

            if (opGameObject.IsPresent())
            {
                opGameObject.Get().transform.position = entity.Position;
                opGameObject.Get().transform.localRotation = entity.Rotation;
                opGameObject.Get().transform.localScale = entity.Scale;
            }
            else
            {
                Log.Error("Entity was already spawned but not found(is it in another chunk?) NitroxId: " + entity.Id + " TechType: " + entity.TechType + " ClassId: " + entity.ClassId + " Position: " + entity.Position);
            }
        }
Beispiel #13
0
        public void DestroyVehicle(NitroxId id, bool isPiloting) //Destroy Vehicle From network
        {
            Optional<GameObject> Object = NitroxIdentifier.GetObjectFrom(id);
            if (Object.IsPresent())
            {
                GameObject T = Object.Get();
                Vehicle vehicle = T.RequireComponent<Vehicle>();

                if (isPiloting) //Check Remote Object Have Player inside
                {
                    ushort pilot = ushort.Parse(vehicle.pilotId);
                    Optional<RemotePlayer> remotePilot = playerManager.Find(pilot);

                    if (remotePilot.IsPresent()) // Get Remote Player Inside == vehicle.pilotId  Remove From Vehicle Before Destroy
                    {
                        RemotePlayer remotePlayer = remotePilot.Get();
                        remotePlayer.SetVehicle(null);
                        remotePlayer.SetSubRoot(null);
                        remotePlayer.SetPilotingChair(null);
                        remotePlayer.AnimationController.UpdatePlayerAnimations = true;
                    }
                }

                if (vehicle.GetPilotingMode()) //Check Local Object Have Player inside
                {
                    vehicle.ReflectionCall("OnPilotModeEnd", false, false, null);

                    if (!Player.main.ToNormalMode(true))
                    {
                        Player.main.ToNormalMode(false);
                        Player.main.transform.parent = null;
                    }
                }

                if (vehicle.gameObject != null) // Destroy Vehicle
                {
                    if (vehicle.destructionEffect)
                    {
                        GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(vehicle.destructionEffect);
                        gameObject.transform.position = vehicle.transform.position;
                        gameObject.transform.rotation = vehicle.transform.rotation;
                    }

                    UnityEngine.Object.Destroy(vehicle.gameObject);
                    RemoveVehicle(id);
                }
            }
        }
Beispiel #14
0
        public override void Process(InitialPlayerSync packet)
        {
            using (packetSender.Suppress <ItemContainerAdd>())
            {
                foreach (EquippedItemData equippedItem in packet.EquippedItems)
                {
                    GameObject gameObject = SerializationHelper.GetGameObject(equippedItem.SerializedData);
                    NitroxIdentifier.SetNewId(gameObject, equippedItem.ItemId);

                    Pickupable            pickupable   = gameObject.RequireComponent <Pickupable>();
                    Optional <GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(equippedItem.ContainerId);

                    if (opGameObject.IsPresent())
                    {
                        GameObject owner = opGameObject.Get();

                        Optional <Equipment> opEquipment = EquipmentHelper.GetBasedOnOwnersType(owner);

                        if (opEquipment.IsPresent())
                        {
                            Equipment     equipment     = opEquipment.Get();
                            InventoryItem inventoryItem = new InventoryItem(pickupable);
                            inventoryItem.container = equipment;
                            inventoryItem.item.Reparent(equipment.tr);

                            Dictionary <string, InventoryItem> itemsBySlot = (Dictionary <string, InventoryItem>)equipment.ReflectionGet("equipment");
                            itemsBySlot[equippedItem.Slot] = inventoryItem;

                            equipment.ReflectionCall("UpdateCount", false, false, new object[] { pickupable.GetTechType(), true });
                            Equipment.SendEquipmentEvent(pickupable, 0, owner, equippedItem.Slot);
                            equipment.ReflectionCall("NotifyEquip", false, false, new object[] { equippedItem.Slot, inventoryItem });
                        }
                        else
                        {
                            Log.Info("Could not find equipment type for " + gameObject.name);
                        }
                    }
                    else
                    {
                        Log.Info("Could not find Container for " + gameObject.name);
                    }
                }
            }
        }
Beispiel #15
0
        // Will be called at a later, because it is needed that the modules are installed and may need power to not immediatly be shut off
        public void SetAdvancedModes(CyclopsModel cyclopsModel)
        {
            // We need to wait till the cyclops is powered up to start all advanced modes
            // At this time all Equipment will be loaded into the cyclops, so we do not need other structures
            SubRoot root = NitroxIdentifier.GetObjectFrom(cyclopsModel.Id).Get().GetComponent <SubRoot>();

            UWE.Event <PowerRelay> .HandleFunction handleFunction = null;
            handleFunction = new UWE.Event <PowerRelay> .HandleFunction((relay) =>
            {
                ChangeSilentRunning(cyclopsModel.Id, cyclopsModel.SilentRunningOn);
                ChangeShieldMode(cyclopsModel.Id, cyclopsModel.ShieldOn);
                ChangeSonarMode(cyclopsModel.Id, cyclopsModel.SonarOn);

                // After registering all modes. Remove the handler
                root.powerRelay.powerUpEvent.RemoveHandler(root, handleFunction);
            });

            root.powerRelay.powerUpEvent.AddHandler(root, handleFunction);
        }
Beispiel #16
0
        public void SetOnPilotMode(NitroxId vehicleId, ushort playerId, bool isPiloting)
        {
            Optional<GameObject> opVehicle = NitroxIdentifier.GetObjectFrom(vehicleId);

            if (opVehicle.IsPresent())
            {
                GameObject gameObject = opVehicle.Get();
                Vehicle vehicle = gameObject.GetComponent<Vehicle>();

                if (vehicle != null)
                {
                    if (isPiloting)
                    {
                        vehicle.pilotId = playerId.ToString();
                    }
                    else
                    {
                        vehicle.pilotId = string.Empty;
                    }
                }
            }
        }
Beispiel #17
0
        public override void Process(InitialPlayerSync packet)
        {
            foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData)
            {
                List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.Enum()).ToList();
                RemotePlayer    player            = remotePlayerManager.Create(playerData.PlayerContext, equippedTechTypes);

                if (playerData.SubRootId.IsPresent())
                {
                    Optional <GameObject> sub = NitroxIdentifier.GetObjectFrom(playerData.SubRootId.Get());

                    if (sub.IsPresent())
                    {
                        player.SetSubRoot(sub.Get().GetComponent <SubRoot>());
                    }
                    else
                    {
                        Log.Error("Could not spawn remote player into subroot with id: " + playerData.SubRootId.Get());
                    }
                }
            }
        }
Beispiel #18
0
        public override void Process(InitialPlayerSync packet)
        {
            Vector3             position  = packet.PlayerSpawnData;
            Optional <NitroxId> subRootId = packet.PlayerSubRootId;

            if (position.x == 0 && position.y == 0 && position.z == 0)
            {
                position = Player.mainObject.transform.position;
            }
            Player.main.SetPosition(position);

            if (subRootId.IsPresent())
            {
                Optional <GameObject> sub = NitroxIdentifier.GetObjectFrom(subRootId.Get());

                if (sub.IsPresent())
                {
                    SubRoot root = sub.Get().GetComponent <SubRoot>();
                    // Player position is relative to a subroot if in a subroot
                    if (root != null && !root.isBase)
                    {
                        Player.main.SetCurrentSub(root);
                        Quaternion vehicleAngle = root.transform.rotation;
                        position = vehicleAngle * position;
                        position = position + root.transform.position;
                        Player.main.SetPosition(position);
                    }
                    else
                    {
                        Log.Error("Could not find subroot for player for subroot with id: " + subRootId.Get());
                    }
                }
                else
                {
                    Log.Error("Could not spawn player into subroot with id: " + subRootId.Get());
                }
            }
        }
        public override void Process(ModuleAdded packet)
        {
            EquippedItemData equippedItemData = packet.EquippedItemData;
            GameObject       gameObject       = SerializationHelper.GetGameObject(equippedItemData.SerializedData);

            Pickupable pickupable = gameObject.RequireComponent <Pickupable>();

            Optional <GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(equippedItemData.ContainerId);

            if (opGameObject.IsPresent())
            {
                GameObject           owner       = opGameObject.Get();
                Optional <Equipment> opEquipment = EquipmentHelper.GetBasedOnOwnersType(owner);

                if (opEquipment.IsPresent())
                {
                    Equipment     equipment     = opEquipment.Get();
                    InventoryItem inventoryItem = new InventoryItem(pickupable);
                    inventoryItem.container = equipment;
                    inventoryItem.item.Reparent(equipment.tr);

                    Dictionary <string, InventoryItem> itemsBySlot = (Dictionary <string, InventoryItem>)equipment.ReflectionGet("equipment");
                    itemsBySlot[equippedItemData.Slot] = inventoryItem;

                    equipment.ReflectionCall("UpdateCount", false, false, new object[] { pickupable.GetTechType(), true });
                    Equipment.SendEquipmentEvent(pickupable, EQUIP_EVENT_TYPE_ID, owner, equippedItemData.Slot);
                    equipment.ReflectionCall("NotifyEquip", false, false, new object[] { equippedItemData.Slot, inventoryItem });
                }
                else
                {
                    Log.Error("Could not find equipment type for " + gameObject.name);
                }
            }
            else
            {
                Log.Info("Could not find Container for " + gameObject.name);
            }
        }
Beispiel #20
0
        public void UpdateVehiclePosition(VehicleMovementData vehicleModel, Optional<RemotePlayer> player)
        {
            Vector3 remotePosition = vehicleModel.Position;
            Vector3 remoteVelocity = vehicleModel.Velocity;
            Quaternion remoteRotation = vehicleModel.Rotation;
            Vector3 angularVelocity = vehicleModel.AngularVelocity;

            Vehicle vehicle = null;
            SubRoot subRoot = null;

            Optional<GameObject> opGameObject = NitroxIdentifier.GetObjectFrom(vehicleModel.Id);

            if (opGameObject.IsPresent())
            {
                GameObject gameObject = opGameObject.Get();

                vehicle = gameObject.GetComponent<Vehicle>();
                subRoot = gameObject.GetComponent<SubRoot>();

                MultiplayerVehicleControl mvc = null;

                if (subRoot != null)
                {
                    mvc = subRoot.gameObject.EnsureComponent<MultiplayerCyclops>();
                }
                else if (vehicle != null)
                {
                    SeaMoth seamoth = vehicle as SeaMoth;
                    Exosuit exosuit = vehicle as Exosuit;

                    if (seamoth)
                    {
                        mvc = seamoth.gameObject.EnsureComponent<MultiplayerSeaMoth>();
                    }
                    else if (exosuit)
                    {
                        mvc = exosuit.gameObject.EnsureComponent<MultiplayerExosuit>();
                        if (vehicleModel.GetType() == typeof(ExosuitMovementData))
                        {
                            ExosuitMovementData exoSuitMovement = (ExosuitMovementData)vehicleModel;
                            mvc.SetArmPositions(exoSuitMovement.LeftAimTarget, exoSuitMovement.RightAimTarget);
                        } else
                        {
                            Log.Error("Got exosuit vehicle but no ExosuitMovementData");
                        }
                    }
                }

                if (mvc != null)
                {
                    mvc.SetPositionVelocityRotation(remotePosition, remoteVelocity, remoteRotation, angularVelocity);
                    mvc.SetThrottle(vehicleModel.AppliedThrottle);
                    mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch);
                }
            }

            if (player.IsPresent())
            {
                RemotePlayer playerInstance = player.Get();
                playerInstance.SetVehicle(vehicle);
                playerInstance.SetSubRoot(subRoot);
                playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren<PilotingChair>());
                playerInstance.AnimationController.UpdatePlayerAnimations = false;
            }
        }