コード例 #1
0
ファイル: ItemContainers.cs プロジェクト: veter12/Nitrox
        public void AddItem(ItemData itemData)
        {
            Optional <GameObject> owner = GuidHelper.GetObjectFrom(itemData.ContainerGuid);

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

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

            if (opContainer.IsPresent())
            {
                ItemsContainer container  = opContainer.Get();
                GameObject     item       = SerializationHelper.GetGameObject(itemData.SerializedData);
                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);
            }
        }
コード例 #2
0
        public void BroadcastDestroyedVehicle(Vehicle vehicle)
        {
            using (packetSender.Suppress <VehicleOnPilotModeChanged>())
            {
                string      guid        = GuidHelper.GetGuid(vehicle.gameObject);
                LocalPlayer localPlayer = NitroxServiceLocator.LocateService <LocalPlayer>();

                VehicleDestroyed vehicleDestroyed = new VehicleDestroyed(guid, localPlayer.PlayerName, vehicle.GetPilotingMode());
                packetSender.Send(vehicleDestroyed);

                // Remove vehicle guid (Detach Player From Vehicle Call OnPilotMode Event if Guid is Empty Dont Send That Event)
                GuidHelper.SetNewGuid(vehicle.gameObject, string.Empty);

                // 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;
                    }
                }
            }
        }
コード例 #3
0
ファイル: ItemContainers.cs プロジェクト: nallston/Nitrox
        public void AddItem(GameObject item, NitroxId containerId)
        {
            Optional <GameObject> owner = NitroxEntity.GetObjectFrom(containerId);

            if (!owner.HasValue)
            {
                Log.Info("Unable to find inventory container with id: " + containerId);
                return;
            }
            Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner.Value);

            if (!opContainer.HasValue)
            {
                Log.Error("Could not find container field on object " + owner.Value.name);
                return;
            }

            ItemsContainer container  = opContainer.Value;
            Pickupable     pickupable = item.RequireComponent <Pickupable>();

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                container.UnsafeAdd(new InventoryItem(pickupable));
            }
        }
コード例 #4
0
        public void BroadcastDestroyedVehicle(Vehicle vehicle)
        {
            using (packetSender.Suppress <VehicleOnPilotModeChanged>())
            {
                NitroxId    id          = NitroxEntity.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.HasValue)
                    {
                        RemotePlayer remotePlayer = remotePilot.Value;
                        remotePlayer.SetVehicle(null);
                        remotePlayer.SetSubRoot(null);
                        remotePlayer.SetPilotingChair(null);
                        remotePlayer.AnimationController.UpdatePlayerAnimations = true;
                    }
                }
            }
        }
コード例 #5
0
        public override void Process(PDAEntryProgress packet)
        {
            using (packetSender.Suppress <PDAEntryAdd>())
                using (packetSender.Suppress <PDAEntryProgress>())
                {
                    TechType             techType  = packet.TechType.ToUnity();
                    PDAScanner.EntryData entryData = PDAScanner.GetEntryData(techType);

                    PDAScanner.Entry entry;
                    if (PDAScanner.GetPartialEntryByKey(techType, out entry))
                    {
                        if (packet.Unlocked > entry.unlocked)
                        {
                            Log.Info("PDAEntryProgress Upldate Old:" + entry.unlocked + " New" + packet.Unlocked);
                            entry.unlocked = packet.Unlocked;
                        }
                    }
                    else
                    {
                        Log.Info("PDAEntryProgress New TechType:" + techType + " Unlocked:" + packet.Unlocked);
                        MethodInfo methodAdd = typeof(PDAScanner).GetMethod("Add", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(TechType), typeof(int) }, null);
                        entry = (PDAScanner.Entry)methodAdd.Invoke(null, new object[] { techType, packet.Unlocked });
                    }
                }
        }
コード例 #6
0
        public void AddItem(GameObject item, NitroxId containerId)
        {
            Optional <GameObject> owner = NitroxEntity.GetObjectFrom(containerId);

            if (!owner.HasValue)
            {
                Log.Error($"Unable to find inventory container with id {containerId} for {item.name}");
                return;
            }
            Optional <ItemsContainer> opContainer = InventoryContainerHelper.TryGetContainerByOwner(owner.Value);

            if (!opContainer.HasValue)
            {
                Log.Error($"Could not find container field on GameObject {owner.Value.GetHierarchyPath()}");
                return;
            }

            ItemsContainer container  = opContainer.Value;
            Pickupable     pickupable = item.RequireComponent <Pickupable>();

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                container.UnsafeAdd(new InventoryItem(pickupable));
                Log.Debug($"Received: Added item {pickupable.GetTechType()} to container {owner.Value.GetHierarchyPath()}");
            }
        }
コード例 #7
0
        public override void Process(PDAEntryAdd packet)
        {
            using (packetSender.Suppress <PDAEntryAdd>())
                using (packetSender.Suppress <PDAEntryProgress>())
                {
                    TechType             techType  = packet.TechType.ToUnity();
                    PDAScanner.EntryData entryData = PDAScanner.GetEntryData(techType);

                    if (!PDAScanner.GetPartialEntryByKey(techType, out PDAScanner.Entry entry))
                    {
                        entry = PDAScanner.Add(techType, packet.Unlocked);
                    }

                    if (entry != null)
                    {
                        entry.unlocked++;

                        if (entry.unlocked >= entryData.totalFragments)
                        {
                            PDAScanner.partial.Remove(entry);
                            PDAScanner.complete.Add(entry.techType);
                        }
                        else
                        {
                            int totalFragments = entryData.totalFragments;
                            if (totalFragments > 1)
                            {
                                float num2 = (float)entry.unlocked / (float)totalFragments;
                                float arg  = (float)Mathf.RoundToInt(num2 * 100f);
                                ErrorMessage.AddError(Language.main.GetFormat <string, float, int, int>("ScannerInstanceScanned", Language.main.Get(entry.techType.AsString(false)), arg, entry.unlocked, totalFragments));
                            }
                        }
                    }
                }
        }
コード例 #8
0
        public override void Process(PDAEntryProgress packet)
        {
            using (packetSender.Suppress <PDAEntryAdd>())
                using (packetSender.Suppress <PDAEntryProgress>())
                {
                    TechType techType = packet.TechType.ToUnity();

                    if (PDAScanner.GetPartialEntryByKey(techType, out PDAScanner.Entry entry))
                    {
                        if (packet.Unlocked == entry.unlocked)
                        {
                            // Add the entry as a cached progress
                            if (!PDAManagerEntry.CachedEntries.TryGetValue(packet.TechType, out PDAProgressEntry pdaProgressEntry))
                            {
                                PDAManagerEntry.CachedEntries.Add(packet.TechType, pdaProgressEntry = new PDAProgressEntry(packet.TechType, new Dictionary <NitroxId, float>()));
                            }
                            pdaProgressEntry.Entries[packet.NitroxId] = packet.Progress;
                        }
                        else if (packet.Unlocked > entry.unlocked)
                        {
                            Log.Info($"PDAEntryProgress Update For TechType:{techType} Old:{entry.unlocked} New:{packet.Unlocked}");
                            entry.unlocked = packet.Unlocked;
                        }
                    }
                    else
                    {
                        Log.Info($"PDAEntryProgress New TechType:{techType} Unlocked:{packet.Unlocked}");
                        methodAdd.Invoke(null, new object[] { techType, packet.Unlocked });
                    }
                }
        }
コード例 #9
0
        public override void Process(StoryEventSend packet)
        {
            switch (packet.Type)
            {
            case StoryEventSend.EventType.PDA:
            case StoryEventSend.EventType.RADIO:
            case StoryEventSend.EventType.ENCYCLOPEDIA:
            case StoryEventSend.EventType.STORY:
                using (packetSender.Suppress <StoryEventSend>())
                    using (packetSender.Suppress <PDALogEntryAdd>())
                    {
                        StoryGoal.Execute(packet.Key, packet.Type.ToUnity());
                    }
                break;

            case StoryEventSend.EventType.EXTRA:
                ExecuteExtraEvent(packet.Key);
                break;

            case StoryEventSend.EventType.PDA_EXTRA:
                PDALog.entries.Remove(packet.Key);
                StoryGoal.Execute(packet.Key, Story.GoalType.PDA);
                break;
            }
        }
コード例 #10
0
        public override void Process(CyclopsDamagePointRepaired packet)
        {
            GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.Id);
            SubRoot    cyclops    = gameObject.RequireComponent <SubRoot>();

            using (packetSender.Suppress <CyclopsDamage>())
                using (packetSender.Suppress <CyclopsDamagePointRepaired>())
                {
                    cyclops.damageManager.damagePoints[packet.DamagePointIndex].liveMixin.AddHealth(packet.RepairAmount);
                }
        }
コード例 #11
0
        private void SetEncyclopediaEntry(List <string> entries)
        {
            Log.Info("Received initial sync packet with " + entries.Count + " encyclopedia entries");

            using (packetSender.Suppress <PDAEncyclopediaEntryAdd>())
            {
                foreach (string entry in entries)
                {
                    PDAEncyclopedia.Add(entry, false);
                }
            }
        }
コード例 #12
0
 private void CompletePreflightCheck(PreflightCheckSwitch preflightCheckSwitch)
 {
     using (packetSender.Suppress <RocketPreflightComplete>())
     {
         preflightCheckSwitch.preflightCheckManager?.CompletePreflightCheck(preflightCheckSwitch.preflightCheck);
     }
 }
コード例 #13
0
 public override void Process(PDAEncyclopediaEntryAdd packet)
 {
     using (packetSender.Suppress <PDAEncyclopediaEntryAdd>())
     {
         PDAEncyclopedia.Add(packet.Key, true);
     }
 }
コード例 #14
0
 public override void Process(KnownTechEntryAdd packet)
 {
     using (packetSender.Suppress <KnownTechEntryAdd>())
     {
         KnownTech.Add(packet.TechType.ToUnity(), packet.Verbose);
     }
 }
コード例 #15
0
 public override void Process(VehicleDestroyed packet)
 {
     using (packetSender.Suppress <VehicleDestroyed>())
     {
         vehicles.DestroyVehicle(packet.Id, packet.GetPilotingMode);
     }
 }
コード例 #16
0
 public override void Process(InitialPlayerSync packet)
 {
     using (packetSender.Suppress <ModuleAdded>())
     {
         equipmentSlots.AddItems(packet.Modules);
     }
 }
コード例 #17
0
        public override void Process(CyclopsActivateSonar sonarPacket)
        {
            GameObject         cyclops = GuidHelper.RequireObjectFrom(sonarPacket.Guid);
            CyclopsSonarButton sonar   = cyclops.RequireComponentInChildren <CyclopsSonarButton>();

            using (packetSender.Suppress <CyclopsActivateSonar>())
            {
                // At this moment the code is "non functional" as for some reason changing the sprite will never happen
                // Also setting sonar as active will never work

                MethodInfo sonarSetActiveInfo = sonar.GetType().GetMethod("set_sonarActive", BindingFlags.NonPublic | BindingFlags.Instance);
                if (sonarSetActiveInfo != null)
                {
                    sonarSetActiveInfo.Invoke(sonar, new object[] { sonarPacket.Active });
                }
                if (sonarPacket.Active)
                {
                    sonar.image.sprite = sonar.activeSprite;
                }
                else
                {
                    sonar.image.sprite = sonar.inactiveSprite;
                }
            }
        }
コード例 #18
0
 public override void Process(PDALogEntryAdd packet)
 {
     using (packetSender.Suppress <PDALogEntryAdd>())
     {
         PDALog.Add(packet.Key);
     }
 }
コード例 #19
0
        public override void Process(CyclopsToggleEngineState enginePacket)
        {
            GameObject cyclops = GuidHelper.RequireObjectFrom(enginePacket.Guid);
            CyclopsEngineChangeState engineState = cyclops.RequireComponentInChildren <CyclopsEngineChangeState>();
            CyclopsMotorMode         motorMode   = cyclops.RequireComponentInChildren <CyclopsMotorMode>();

            if (enginePacket.IsOn == engineState.motorMode.engineOn)
            {
                if ((enginePacket.IsStarting != (bool)engineState.ReflectionGet("startEngine")) != enginePacket.IsOn)
                {
                    if (Player.main.currentSub != engineState.subRoot)
                    {
                        engineState.ReflectionSet("startEngine", !enginePacket.IsOn);
                        engineState.ReflectionSet("invalidButton", true);
                        engineState.Invoke("ResetInvalidButton", 2.5f);
                        engineState.subRoot.BroadcastMessage("InvokeChangeEngineState", !enginePacket.IsOn, SendMessageOptions.RequireReceiver);
                    }
                    else
                    {
                        engineState.ReflectionSet("invalidButton", false);
                        using (packetSender.Suppress <CyclopsToggleInternalLighting>())
                        {
                            engineState.OnClick();
                        }
                    }
                }
            }
        }
コード例 #20
0
        public override void Process(VehicleNameChange namePacket)
        {
            SubNameInput subNameInput;

            if (namePacket.ParentId.HasValue)
            {
                GameObject moonpool = NitroxEntity.RequireObjectFrom(namePacket.ParentId.Value);
                GameObject baseCell = moonpool.RequireComponentInParent <BaseCell>().gameObject;

                subNameInput = baseCell.GetComponentInChildren <SubNameInput>();
            }
            else
            {
                GameObject vehicleObject = NitroxEntity.RequireObjectFrom(namePacket.VehicleId);
                subNameInput = vehicleObject.GetComponentInChildren <SubNameInput>();
            }

            using (packetSender.Suppress <VehicleNameChange>())
            {
                if (subNameInput && subNameInput.target)
                {
                    // OnColorChange calls these two methods, in order to update the vehicle name on the ingame panel:
                    subNameInput.target.SetName(namePacket.Name);
                    subNameInput.SetName(namePacket.Name);
                }
                else
                {
                    Log.Error($"[VehicleNameChangeProcessor] SubNameInput or targeted SubName is null with {namePacket}.");
                }
            }
        }
コード例 #21
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int storageSlotsSynced = 0;

            HashSet <NitroxId> onlinePlayers = new HashSet <NitroxId> {
                packet.PlayerGameObjectId
            };

            onlinePlayers.AddRange(packet.RemotePlayerData.Select(playerData => playerData.PlayerContext.PlayerNitroxId));

            // Removes any batteries which are in inventories from offline players
            List <ItemData> currentlyIgnoredItems = packet.InventoryItems.Where(item => !onlinePlayers.Any(player => player.Equals(item.ContainerId))).ToList();

            packet.StorageSlotItems.RemoveAll(storageItem => currentlyIgnoredItems.Any(ignoredItem => ignoredItem.ItemId.Equals(storageItem.ContainerId)));

            using (packetSender.Suppress <StorageSlotItemAdd>())
            {
                foreach (ItemData itemData in packet.StorageSlotItems)
                {
                    waitScreenItem.SetProgress(storageSlotsSynced, packet.StorageSlotItems.Count);

                    GameObject item = SerializationHelper.GetGameObject(itemData.SerializedData);

                    Log.Debug($"Initial StorageSlot item data for {item.name} giving to container {itemData.ContainerId}");

                    NitroxEntity.SetNewId(item, itemData.ItemId);
                    slots.AddItem(item, itemData.ContainerId, true);

                    storageSlotsSynced++;
                    yield return(null);
                }
            }
        }
コード例 #22
0
ファイル: LocalPlayer.cs プロジェクト: joeeyaura/Nitrox
        private GameObject CreateBodyPrototype()
        {
            GameObject prototype = Body;

            // Cheap fix for showing head, much easier since male_geo contains many different heads
            prototype.GetComponentInParent <Player>().head.shadowCastingMode = ShadowCastingMode.On;
            GameObject clone = Object.Instantiate(prototype, Multiplayer.Main.transform);

            prototype.GetComponentInParent <Player>().head.shadowCastingMode = ShadowCastingMode.ShadowsOnly;

            clone.SetActive(false);
            clone.name = "RemotePlayerPrototype";

            // Removing items that are held in hand
            foreach (Transform child in clone.transform.Find($"player_view/{PlayerEquipmentConstants.ITEM_ATTACH_POINT_GAME_OBJECT_NAME}"))
            {
                if (!child.gameObject.name.Contains("attach1_"))
                {
                    using (packetSender.Suppress <ItemContainerRemove>())
                    {
                        Object.DestroyImmediate(child.gameObject);
                    }
                }
            }

            return(clone);
        }
コード例 #23
0
        public override void Process(PingRenamed packet)
        {
            Optional <GameObject> obj = NitroxEntity.GetObjectFrom(packet.Id);

            if (!obj.HasValue)
            {
                // Not the object we're looking for.
                return;
            }
            Beacon beacon = obj.Value.GetComponent <Beacon>();

            if (!beacon)
            {
                // This can be ok if origin of ping instance component was not from a beacon (but from signal or other).
                return;
            }
            if (beacon.GetComponent <Player>())
            {
                // Skip over beacon component on player GameObjects
                return;
            }

            using (sender.Suppress <PingRenamed>())
            {
                beacon.beaconLabel.SetLabel(packet.Name);
                Log.Debug($"Received ping rename: '{packet.Name}' on object '{obj.Value.GetFullName()}' with Nitrox id: '{packet.Id}'");
            }
        }
コード例 #24
0
 public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
 {
     using (packetSender.Suppress <ModuleAdded>())
     {
         equipmentSlots.AddItems(packet.Modules);
         yield return(null);
     }
 }
コード例 #25
0
        /// <summary>
        /// Finds and executes <see cref="Fire.Douse(float)"/>. If the fire is extinguished, it will pass a large float to trigger the private
        /// <see cref="Fire.Extinguish()"/> method.
        /// </summary>
        public override void Process(FireDoused packet)
        {
            GameObject fireGameObject = NitroxEntity.RequireObjectFrom(packet.Id);

            using (packetSender.Suppress <FireDoused>())
            {
                fireGameObject.RequireComponent <Fire>().Douse(packet.DouseAmount);
            }
        }
コード例 #26
0
    public override void Process(PlayFMODCustomEmitter packet)
    {
        GameObject            soundSource           = NitroxEntity.RequireObjectFrom(packet.Id);
        FMODEmitterController fmodEmitterController = soundSource.RequireComponent <FMODEmitterController>();

        using (packetSender.Suppress <PlayFMODCustomEmitter>())
            using (packetSender.Suppress <PlayFMODCustomLoopingEmitter>())
            {
                if (packet.Play)
                {
                    fmodEmitterController.PlayCustomEmitter(packet.AssetPath);
                }
                else
                {
                    fmodEmitterController.StopCustomEmitter(packet.AssetPath);
                }
            }
    }
コード例 #27
0
        public override void Process(OpenableStateChanged packet)
        {
            GameObject gameObject = GuidHelper.RequireObjectFrom(packet.Guid);
            Openable   openable   = gameObject.RequireComponent <Openable>();

            using (packetSender.Suppress <OpenableStateChanged>())
            {
                openable.PlayOpenAnimation(packet.IsOpen, packet.Duration);
            }
        }
コード例 #28
0
        public override void Process(VehicleNameChange namePacket)
        {
            GameObject   target       = GuidHelper.RequireObjectFrom(namePacket.Guid);
            SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>();

            using (packetSender.Suppress <VehicleNameChange>())
            {
                subNameInput.OnNameChange(namePacket.Name);
            }
        }
コード例 #29
0
        public override void Process(SeamothModulesAction packet)
        {
            using (packetSender.Suppress <SeamothModulesAction>())
                using (packetSender.Suppress <ItemContainerRemove>())
                {
                    GameObject _gameObject = NitroxEntity.RequireObjectFrom(packet.Id);
                    SeaMoth    seamoth     = _gameObject.GetComponent <SeaMoth>();
                    if (seamoth != null)
                    {
                        TechType techType = packet.TechType.ToUnity();

                        if (techType == TechType.SeamothElectricalDefense)
                        {
                            float[]           chargearray = (float[])seamoth.ReflectionGet("quickSlotCharge");
                            float             charge      = chargearray[packet.SlotID];
                            float             slotCharge  = seamoth.GetSlotCharge(packet.SlotID);
                            GameObject        gameObject  = global::Utils.SpawnZeroedAt(seamoth.seamothElectricalDefensePrefab, seamoth.transform, false);
                            ElectricalDefense component   = gameObject.GetComponent <ElectricalDefense>();
                            component.charge       = charge;
                            component.chargeScalar = slotCharge;
                        }

                        if (techType == TechType.SeamothTorpedoModule)
                        {
                            Transform      muzzle        = (packet.SlotID != seamoth.GetSlotIndex("SeamothModule1") && packet.SlotID != seamoth.GetSlotIndex("SeamothModule3")) ? seamoth.torpedoTubeRight : seamoth.torpedoTubeLeft;
                            ItemsContainer storageInSlot = seamoth.GetStorageInSlot(packet.SlotID, TechType.SeamothTorpedoModule);
                            TorpedoType    torpedoType   = null;

                            for (int i = 0; i < seamoth.torpedoTypes.Length; i++)
                            {
                                if (storageInSlot.Contains(seamoth.torpedoTypes[i].techType))
                                {
                                    torpedoType = seamoth.torpedoTypes[i];
                                    break;
                                }
                            }

                            //Original Function use Player Camera need parse owner camera values
                            TorpedoShot(storageInSlot, torpedoType, muzzle, packet.Forward.ToUnity(), packet.Rotation.ToUnity());
                        }
                    }
                }
        }
コード例 #30
0
        public override void Process(EnergyMixinValueChanged energyMixinPacket)
        {
            GameObject  target      = NitroxEntity.RequireObjectFrom(energyMixinPacket.Id);
            EnergyMixin energyMixin = target.RequireComponent <EnergyMixin>();

            using (packetSender.Suppress <EnergyMixinValueChanged>())
            {
                energyMixin.ModifyCharge(energyMixinPacket.Value - energyMixin.charge);
            }
        }