public static bool Speedloader_DuplicateFromSpawnLock(Speedloader __instance, ref GameObject __result, FVRViveHand hand)
        {
            //unlike MonoMod the base class can technically be retrived, but it's a PitA so again this is copied from FVRPhysicalObject.DuplicateFromSpawnLock
            GameObject        gameObject = UnityEngine.Object.Instantiate <GameObject>(__instance.ObjectWrapper.GetGameObject(), __instance.Transform.position, __instance.Transform.rotation);
            FVRPhysicalObject fvrObj     = gameObject.GetComponent <FVRPhysicalObject>();

            if (fvrObj is FVREntityProxy)
            {
                (fvrObj as FVREntityProxy).Data.PrimeDataLists((fvrObj as FVREntityProxy).Flags);
            }

            hand.ForceSetInteractable(fvrObj);
            fvrObj.SetQuickBeltSlot(null);
            fvrObj.BeginInteraction(hand);

            Speedloader component = gameObject.GetComponent <Speedloader>();

            for (int i = 0; i < __instance.Chambers.Count; i++)
            {
                component.Chambers[i].Type = __instance.Chambers[i].Type;

                if (__instance.Chambers[i].IsLoaded)
                {
                    component.Chambers[i].Load(__instance.Chambers[i].LoadedClass, false);
                }
                else
                {
                    component.Chambers[i].Unload();
                }
            }
            __result = gameObject;
            return(false);
        }
        public static bool RevolvingShotgun_EjectCylinder(RevolvingShotgun __instance, ref Speedloader __result)
        {
            GameObject  gameObject = UnityEngine.Object.Instantiate <GameObject>(__instance.CylinderPrefab, __instance.CyclinderMountPoint.position, __instance.CyclinderMountPoint.rotation);
            Speedloader component  = gameObject.GetComponent <Speedloader>();

            __instance.PlayAudioEvent(FirearmAudioEventType.MagazineOut, 1f);
            for (int i = 0; i < component.Chambers.Count; i++)
            {
                if (!__instance.Chambers[i].IsFull)
                {
                    component.Chambers[i].Unload();
                }
                else if (__instance.Chambers[i].IsSpent)
                {
                    component.Chambers[i].Type = __instance.Chambers[i].GetRound().RoundType;
                    component.Chambers[i].LoadEmpty(__instance.Chambers[i].GetRound().RoundClass, false);
                }
                else
                {
                    component.Chambers[i].Type = __instance.Chambers[i].GetRound().RoundType;
                    component.Chambers[i].Load(__instance.Chambers[i].GetRound().RoundClass, false);
                }
                __instance.Chambers[i].UpdateProxyDisplay();
            }
            __instance.EjectDelay     = 0.4f;
            __instance.CylinderLoaded = false;
            __instance.ProxyCylinder.gameObject.SetActive(__instance.CylinderLoaded);

            __result = component;
            return(false);
        }
Пример #3
0
        private void DupeMagButton()
        {
            if ((detectedMag == null && detectedSpeedLoader == null) || original.M.GetNumTokens() < DupeCost)
            {
                SM.PlayCoreSound(FVRPooledAudioType.UIChirp, original.AudEvent_Fail, transform.position);
            }

            else
            {
                SM.PlayCoreSound(FVRPooledAudioType.UIChirp, original.AudEvent_Spawn, transform.position);
                original.M.SubtractTokens(DupeCost);
                original.M.Increment(10, false);

                if (detectedMag != null)
                {
                    TNHTweaker.HoldActions[original.M.m_level].Add($"Duplicated {detectedMag.ObjectWrapper.DisplayName}");
                    FirearmUtils.SpawnDuplicateMagazine(detectedMag, original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
                }

                else
                {
                    TNHTweaker.HoldActions[original.M.m_level].Add($"Duplicated {detectedSpeedLoader.ObjectWrapper.DisplayName}");
                    FirearmUtils.SpawnDuplicateSpeedloader(detectedSpeedLoader, original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
                }

                detectedMag         = null;
                detectedSpeedLoader = null;
                UpdateIcons();
            }
        }
Пример #4
0
        private void Scan()
        {
            int colliderCount = Physics.OverlapBoxNonAlloc(original.ScanningVolume.position, original.ScanningVolume.localScale * 0.5f, colBuffer, original.ScanningVolume.rotation, original.ScanningLM, QueryTriggerInteraction.Collide);

            detectedMag         = null;
            detectedSpeedLoader = null;
            purchaseMag         = null;
            upgradeMag          = null;

            for (int i = 0; i < colliderCount; i++)
            {
                if (colBuffer[i].attachedRigidbody != null)
                {
                    FVRFireArm firearm = colBuffer[i].GetComponent <FVRFireArm>();
                    if (purchaseMag == null && firearm != null && !firearm.IsHeld && firearm.QuickbeltSlot == null)
                    {
                        MagazineBlacklistEntry entry = null;
                        if (blacklist.ContainsKey(firearm.ObjectWrapper.ItemID))
                        {
                            entry = blacklist[firearm.ObjectWrapper.ItemID];
                        }
                        List <FVRObject> spawnableMags = FirearmUtils.GetCompatibleMagazines(firearm.ObjectWrapper, -1, -1, false, entry);

                        if (spawnableMags.Count > 0)
                        {
                            purchaseMag = FirearmUtils.GetSmallestCapacityMagazine(spawnableMags);
                        }
                    }

                    FVRFireArmMagazine mag = colBuffer[i].GetComponent <FVRFireArmMagazine>();
                    if (mag != null && mag.FireArm == null && (!mag.IsHeld) && mag.QuickbeltSlot == null && (!mag.IsIntegrated))
                    {
                        detectedMag = mag;
                    }

                    Speedloader speedloader = colBuffer[i].GetComponent <Speedloader>();
                    if (speedloader != null && (!speedloader.IsHeld) && speedloader.QuickbeltSlot == null && speedloader.IsPretendingToBeAMagazine)
                    {
                        detectedSpeedLoader = speedloader;
                    }

                    //If at this point we have a valid ammo container and firearm, we can stop looping
                    if (purchaseMag != null && (detectedMag != null || detectedSpeedLoader != null))
                    {
                        break;
                    }
                }
            }
        }
        public static bool RevolvingShotgun_LoadCylinder(RevolvingShotgun __instance, Speedloader s, ref int ___m_curChamber, ref bool __result)
        {
            if (__instance.CylinderLoaded)
            {
                return(false);
            }

            __instance.CylinderLoaded = true;
            __instance.ProxyCylinder.gameObject.SetActive(__instance.CylinderLoaded);
            __instance.PlayAudioEvent(FirearmAudioEventType.MagazineIn, 1f);
            ___m_curChamber = 0;
            __instance.ProxyCylinder.localRotation = __instance.GetLocalRotationFromCylinder(___m_curChamber);
            for (int i = 0; i < __instance.Chambers.Length; i++)
            {
                if (s.Chambers[i].IsLoaded)
                {
                    __instance.Chambers[i].RoundType = s.Chambers[i].Type;
                    __instance.Chambers[i].Autochamber(s.Chambers[i].LoadedClass);
                    __instance.Chambers[i].IsSpent = s.Chambers[i].IsSpent;
                }
                else
                {
                    __instance.Chambers[i].Unload();
                }

                __instance.Chambers[i].UpdateProxyDisplay();
            }

            __result = true;
            return(false);
        }
        public static bool RevolverCylinder_LoadFromSpeedLoader(RevolverCylinder __instance, Speedloader loader)
        {
            __instance.SpeedLoaderID      = loader.ObjectWrapper.ItemID;
            __instance.m_hasSpeedLoadedIn = true;
            bool flag = false;

            for (int i = 0; i < loader.Chambers.Count; i++)
            {
                if (i < __instance.Revolver.Chambers.Length)
                {
                    if (loader.Chambers[i].IsLoaded)
                    {
                        if (!__instance.Revolver.Chambers[i].IsFull)
                        {
                            __instance.Revolver.Chambers[i].RoundType = loader.Chambers[i].Type;
                            __instance.Revolver.Chambers[i].Autochamber(loader.Chambers[i].Unload());

                            if (loader.Chambers[i].IsSpent)
                            {
                                __instance.Revolver.Chambers[i].Fire();
                            }

                            flag = true;
                        }
                    }
                }
            }
            if (flag)
            {
                __instance.Revolver.PlayAudioEvent(FirearmAudioEventType.MagazineIn, 1f);
                __instance.MoonClip?.SetActive(true);
            }
            return(false);
        }
        public static bool AmmoSpawnerV2_CheckFillButton(AmmoSpawnerV2 __instance, FireArmRoundType ___m_curAmmoType, ref bool ___m_hasHeldType, ref FireArmRoundType ___heldType)
        {
            bool showFill = false;

            for (int i = 0; i < GM.CurrentMovementManager.Hands.Length; i++)
            {
                if (GM.CurrentMovementManager.Hands[i].CurrentInteractable != null && GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRPhysicalObject)
                {
                    FireArmRoundType curAmmoType = ___m_curAmmoType;
                    if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRFireArmMagazine)
                    {
                        FVRFireArmMagazine fvrfireArmMagazine = GM.CurrentMovementManager.Hands[i].CurrentInteractable as FVRFireArmMagazine;
                        ___m_hasHeldType = true;
                        ___heldType      = fvrfireArmMagazine.RoundType;
                        if (TypeCheck(fvrfireArmMagazine.RoundType == curAmmoType))
                        {
                            showFill = true;
                        }
                    }
                    else if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRFireArmClip)
                    {
                        FVRFireArmClip fvrfireArmClip = GM.CurrentMovementManager.Hands[i].CurrentInteractable as FVRFireArmClip;
                        ___m_hasHeldType = true;
                        ___heldType      = fvrfireArmClip.RoundType;
                        if (TypeCheck(fvrfireArmClip.RoundType == curAmmoType))
                        {
                            showFill = true;
                        }
                    }
                    else if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is Speedloader)
                    {
                        Speedloader speedloader = GM.CurrentMovementManager.Hands[i].CurrentInteractable as Speedloader;
                        ___m_hasHeldType = true;
                        ___heldType      = speedloader.Chambers[0].Type;
                        if (TypeCheck(speedloader.Chambers[0].Type == curAmmoType))
                        {
                            showFill = true;
                        }
                    }
                    else if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRFireArm)
                    {
                        FVRFireArm fvrfireArm = GM.CurrentMovementManager.Hands[i].CurrentInteractable as FVRFireArm;
                        ___m_hasHeldType = true;
                        ___heldType      = fvrfireArm.RoundType;
                        if (TypeCheck(fvrfireArm.RoundType == curAmmoType) || (fvrfireArm.Magazine != null || fvrfireArm.Clip != null))
                        {
                            showFill = true;
                        }
                    }
                }
            }
            if (showFill && !__instance.BTNGO_Fill.activeSelf)
            {
                __instance.BTNGO_Fill.SetActive(true);
            }
            else if (!showFill && __instance.BTNGO_Fill.activeSelf)
            {
                __instance.BTNGO_Fill.SetActive(false);
            }
            if (___m_hasHeldType && !__instance.BTNGO_Select.activeSelf)
            {
                __instance.BTNGO_Select.SetActive(true);
            }
            else if (!___m_hasHeldType && __instance.BTNGO_Select.activeSelf)
            {
                __instance.BTNGO_Select.SetActive(false);
            }
            return(false);
        }
        public static bool AmmoSpawnerV2_LoadIntoHeldObjects(FireArmRoundType ___m_curAmmoType, FireArmRoundClass ___m_curAmmoClass)
        {
            FireArmRoundType  curAmmoType  = ___m_curAmmoType;
            FireArmRoundClass curAmmoClass = ___m_curAmmoClass;

            for (int i = 0; i < GM.CurrentMovementManager.Hands.Length; i++)
            {
                if (GM.CurrentMovementManager.Hands[i].CurrentInteractable != null && GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRPhysicalObject)
                {
                    if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRFireArmMagazine)
                    {
                        FVRFireArmMagazine fvrfireArmMagazine = GM.CurrentMovementManager.Hands[i].CurrentInteractable as FVRFireArmMagazine;
                        if (TypeCheck(fvrfireArmMagazine.RoundType == curAmmoType))
                        {
                            fvrfireArmMagazine.m_numRounds = 0;
                            for (int j = 0; j < fvrfireArmMagazine.LoadedRounds.Length; j++)
                            {
                                fvrfireArmMagazine.AddRound(AM.GetRoundSelfPrefab(curAmmoType, curAmmoClass).GetGameObject().GetComponent <FVRFireArmRound>(), false, true);
                            }
                            fvrfireArmMagazine.UpdateBulletDisplay();
                        }
                    }
                    else if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRFireArmClip)
                    {
                        FVRFireArmClip fvrfireArmClip = GM.CurrentMovementManager.Hands[i].CurrentInteractable as FVRFireArmClip;
                        if (TypeCheck(fvrfireArmClip.RoundType == curAmmoType))
                        {
                            fvrfireArmClip.m_numRounds = 0;
                            for (int j = 0; j < fvrfireArmClip.LoadedRounds.Length; j++)
                            {
                                fvrfireArmClip.AddRound(AM.GetRoundSelfPrefab(curAmmoType, curAmmoClass).GetGameObject().GetComponent <FVRFireArmRound>(), false, true);
                            }
                            fvrfireArmClip.UpdateBulletDisplay();
                        }
                    }
                    else if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is Speedloader)
                    {
                        Speedloader speedloader = GM.CurrentMovementManager.Hands[i].CurrentInteractable as Speedloader;
                        if (TypeCheck(speedloader.Chambers[0].Type == curAmmoType))
                        {
                            for (int j = 0; j < speedloader.Chambers.Count; j++)
                            {
                                speedloader.Chambers[j].Type = curAmmoType;
                                speedloader.Chambers[j].Load(curAmmoClass);
                            }
                        }
                    }
                    else if (GM.CurrentMovementManager.Hands[i].CurrentInteractable is FVRFireArm)
                    {
                        FVRFireArm fvrfireArm = GM.CurrentMovementManager.Hands[i].CurrentInteractable as FVRFireArm;
                        if (TypeCheck(fvrfireArm.RoundType == curAmmoType))
                        {
                            for (int j = 0; j < fvrfireArm.FChambers.Count; j++)
                            {
                                fvrfireArm.FChambers[j].SetRound(AM.GetRoundSelfPrefab(curAmmoType, curAmmoClass).GetGameObject().GetComponent <FVRFireArmRound>());
                            }
                        }

                        if (TypeCheck(fvrfireArm.RoundType == curAmmoType) && fvrfireArm.Magazine != null)
                        {
                            fvrfireArm.Magazine.m_numRounds = 0;
                            for (int j = 0; j < fvrfireArm.Magazine.LoadedRounds.Length; j++)
                            {
                                fvrfireArm.Magazine.AddRound(AM.GetRoundSelfPrefab(curAmmoType, curAmmoClass).GetGameObject().GetComponent <FVRFireArmRound>(), false, true);
                            }
                            fvrfireArm.Magazine.UpdateBulletDisplay();
                        }
                        if (TypeCheck(fvrfireArm.RoundType == curAmmoType) && fvrfireArm.Clip != null)
                        {
                            fvrfireArm.Clip.m_numRounds = 0;
                            for (int j = 0; j < fvrfireArm.Clip.LoadedRounds.Length; j++)
                            {
                                fvrfireArm.Clip.AddRound(AM.GetRoundSelfPrefab(curAmmoType, curAmmoClass).GetGameObject().GetComponent <FVRFireArmRound>(), false, true);
                            }
                            fvrfireArm.Clip.UpdateBulletDisplay();
                        }
                    }
                }
            }
            return(false);
        }
Пример #9
0
        public static IEnumerator SpawnFirearm(SavedGunSerializable savedGun, Vector3 position, Quaternion rotation)
        {
            List <GameObject>  toDealWith    = new List <GameObject>();
            List <GameObject>  toMoveToTrays = new List <GameObject>();
            FVRFireArm         myGun         = null;
            FVRFireArmMagazine myMagazine    = null;
            List <int>         validIndexes  = new List <int>();
            Dictionary <GameObject, SavedGunComponent> dicGO = new Dictionary <GameObject, SavedGunComponent>();
            Dictionary <int, GameObject>       dicByIndex    = new Dictionary <int, GameObject>();
            List <AnvilCallback <GameObject> > callbackList  = new List <AnvilCallback <GameObject> >();

            SavedGun gun = savedGun.GetSavedGun();

            for (int i = 0; i < gun.Components.Count; i++)
            {
                callbackList.Add(IM.OD[gun.Components[i].ObjectID].GetGameObjectAsync());
            }
            yield return(callbackList);

            for (int j = 0; j < gun.Components.Count; j++)
            {
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(callbackList[j].Result);

                dicGO.Add(gameObject, gun.Components[j]);
                dicByIndex.Add(gun.Components[j].Index, gameObject);
                if (gun.Components[j].isFirearm)
                {
                    myGun = gameObject.GetComponent <FVRFireArm>();
                    savedGun.ApplyFirearmProperties(myGun);

                    validIndexes.Add(j);
                    gameObject.transform.position = position;
                    gameObject.transform.rotation = Quaternion.identity;
                }
                else if (gun.Components[j].isMagazine)
                {
                    myMagazine = gameObject.GetComponent <FVRFireArmMagazine>();
                    validIndexes.Add(j);
                    if (myMagazine != null)
                    {
                        gameObject.transform.position = myGun.GetMagMountPos(myMagazine.IsBeltBox).position;
                        gameObject.transform.rotation = myGun.GetMagMountPos(myMagazine.IsBeltBox).rotation;
                        myMagazine.Load(myGun);
                        myMagazine.IsInfinite = false;
                    }
                }
                else if (gun.Components[j].isAttachment)
                {
                    toDealWith.Add(gameObject);
                }
                else
                {
                    toMoveToTrays.Add(gameObject);
                    if (gameObject.GetComponent <Speedloader>() != null && gun.LoadedRoundsInMag.Count > 0)
                    {
                        Speedloader component = gameObject.GetComponent <Speedloader>();
                        component.ReloadSpeedLoaderWithList(gun.LoadedRoundsInMag);
                    }
                    else if (gameObject.GetComponent <FVRFireArmClip>() != null && gun.LoadedRoundsInMag.Count > 0)
                    {
                        FVRFireArmClip component2 = gameObject.GetComponent <FVRFireArmClip>();
                        component2.ReloadClipWithList(gun.LoadedRoundsInMag);
                    }
                }
                gameObject.GetComponent <FVRPhysicalObject>().ConfigureFromFlagDic(gun.Components[j].Flags);
            }
            if (myGun.Magazine != null && gun.LoadedRoundsInMag.Count > 0)
            {
                myGun.Magazine.ReloadMagWithList(gun.LoadedRoundsInMag);
                myGun.Magazine.IsInfinite = false;
            }
            int BreakIterator = 200;

            while (toDealWith.Count > 0 && BreakIterator > 0)
            {
                BreakIterator--;
                for (int k = toDealWith.Count - 1; k >= 0; k--)
                {
                    SavedGunComponent savedGunComponent = dicGO[toDealWith[k]];
                    if (validIndexes.Contains(savedGunComponent.ObjectAttachedTo))
                    {
                        GameObject                gameObject2 = toDealWith[k];
                        FVRFireArmAttachment      component3  = gameObject2.GetComponent <FVRFireArmAttachment>();
                        FVRFireArmAttachmentMount mount       = GetMount(dicByIndex[savedGunComponent.ObjectAttachedTo], savedGunComponent.MountAttachedTo);
                        gameObject2.transform.rotation = Quaternion.LookRotation(savedGunComponent.OrientationForward, savedGunComponent.OrientationUp);
                        gameObject2.transform.position = GetPositionRelativeToGun(savedGunComponent, myGun.transform);
                        if (component3.CanScaleToMount && mount.CanThisRescale())
                        {
                            component3.ScaleToMount(mount);
                        }
                        component3.AttachToMount(mount, false);
                        if (component3 is Suppressor)
                        {
                            (component3 as Suppressor).AutoMountWell();
                        }
                        validIndexes.Add(savedGunComponent.Index);
                        toDealWith.RemoveAt(k);
                    }
                }
            }
            int trayIndex = 0;
            int itemIndex = 0;

            for (int l = 0; l < toMoveToTrays.Count; l++)
            {
                toMoveToTrays[l].transform.position = position + (float)itemIndex * 0.1f * Vector3.up;
                toMoveToTrays[l].transform.rotation = rotation;
                itemIndex++;
                trayIndex++;
                if (trayIndex > 2)
                {
                    trayIndex = 0;
                }
            }
            myGun.SetLoadedChambers(gun.LoadedRoundsInChambers);
            myGun.SetFromFlagList(gun.SavedFlags);
            myGun.transform.rotation = rotation;
            yield break;
        }