Ejemplo n.º 1
0
        public void Awake()
        {
            InitConfig();

            //On.RoR2.PurchaseInteraction.OnTeleporterBeginCharging += PurchaseInteraction_OnTeleporterBeginCharging;

            On.RoR2.OutsideInteractableLocker.LockPurchasable += OutsideInteractableLocker_LockPurchasable;

            On.RoR2.SceneDirector.PlaceTeleporter += (orig, self) =>
                                                     //On.RoR2.SceneDirector.PopulateScene += (orig, self) =>
            {
                orig(self);
                if (!RoR2Application.isInSinglePlayer)
                {
                    SpawnShrineOfDio(self);
                }
            };

            On.RoR2.ShrineHealingBehavior.FixedUpdate += (orig, self) =>
            {
                orig(self);
                if (!NetworkServer.active)
                {
                    if (clientCost == UNINITIALIZED)
                    {
                        int piCost = self.GetFieldValue <PurchaseInteraction>("purchaseInteraction").cost;
                        if (piCost != clientCost)
                        {
                            clientCost = piCost;
                            if (clientCost == BALANCED_MODE)
                            {
                                isBalancedMode = true;
                            }
                            else
                            {
                                isBalancedMode = false;
                            }
                            Type[] arr = ((IEnumerable <System.Type>) typeof(ChestRevealer).Assembly.GetTypes()).Where <System.Type>((Func <System.Type, bool>)(t => typeof(IInteractable).IsAssignableFrom(t))).ToArray <System.Type>();
                            for (int i = 0; i < arr.Length; i++)
                            {
                                foreach (UnityEngine.MonoBehaviour instances in InstanceTracker.FindInstancesEnumerable(arr[i]))
                                {
                                    if (((IInteractable)instances).ShouldShowOnScanner())
                                    {
                                        string item = ((IInteractable)instances).ToString().ToLower();
                                        if (item.Contains("shrinehealing"))
                                        {
                                            UpdateShrineDisplay(instances.GetComponentInParent <ShrineHealingBehavior>());
                                        }
                                    }
                                    ;
                                }
                            }
                        }
                    }
                }
            };

            On.RoR2.Stage.Start += (orig, self) =>
            {
                orig(self);
                if (!RoR2Application.isInSinglePlayer && NetworkServer.active)
                {
                    isDead.Clear();
                }
            };

            On.RoR2.ShrineHealingBehavior.Awake += (orig, self) =>
            {
                orig(self);
                if (!RoR2Application.isInSinglePlayer)
                {
                    PurchaseInteraction pi = self.GetFieldValue <PurchaseInteraction>("purchaseInteraction");
                    pi.contextToken                = "Offer to the Shrine of Dio";
                    pi.displayNameToken            = "Shrine of Dio";
                    self.costMultiplierPerPurchase = 1f;


                    if (NetworkServer.active)
                    {
                        isBalancedMode = UseBalancedMode.Value;
                        if (UseBalancedMode.Value)
                        {
                            pi.costType = CostTypeIndex.None;
                            pi.cost     = BALANCED_MODE;
                            pi.GetComponent <HologramProjector>().displayDistance   = 0f;
                            self.GetComponent <HologramProjector>().displayDistance = 0f;
                        }
                        else
                        {
                            pi.costType = CostTypeIndex.Money;
                            pi.cost     = ResurrectionCost.Value;
                        }
                    }
                    else
                    {
                        clientCost = UNINITIALIZED;
                    }
                }
            };

            On.RoR2.ShrineHealingBehavior.AddShrineStack += (orig, self, interactor) =>
            {
                if (!RoR2Application.isInSinglePlayer)
                {
                    if (NetworkServer.active)
                    {
                        PlayerCharacterMasterController deadCharacter = GetRandomDeadCharacter();
                        isDead.Remove(deadCharacter.networkUser);

                        GameObject prefab = BodyCatalog.GetBodyPrefab(deadCharacter.networkUser.NetworkbodyIndexPreference);
                        if (prefab != null)
                        {
                            deadCharacter.master.bodyPrefab = prefab;
                        }
                        deadCharacter.master.Respawn(deadCharacter.master.GetFieldValue <Vector3>("deathFootPosition"), deadCharacter.master.transform.rotation, true);

                        string resurrectionMessage = $"<color=#beeca1>{interactor.GetComponent<CharacterBody>().GetUserName()}</color> resurrected <color=#beeca1>{deadCharacter.networkUser.userName}</color>";
                        Chat.SendBroadcastChat(new Chat.SimpleChatMessage
                        {
                            baseToken = resurrectionMessage
                        });

                        GameObject spawnEffect = Resources.Load <GameObject>("Prefabs/Effects/HippoRezEffect");
                        EffectManager.SpawnEffect(spawnEffect, new EffectData
                        {
                            origin   = deadCharacter.master.GetBody().footPosition,
                            rotation = deadCharacter.master.gameObject.transform.rotation
                        }, true);
                        self.SetFieldValue("waitingForRefresh", true);
                        self.SetFieldValue("refreshTimer", 2f);
                        EffectManager.SpawnEffect(Resources.Load <GameObject>("Prefabs/Effects/ShrineUseEffect"), new EffectData()
                        {
                            origin   = self.transform.position,
                            rotation = Quaternion.identity,
                            scale    = 1f,
                            color    = (Color32)Color.green
                        }, true);
                        // dio
                        CharacterBody cb = interactor.GetComponent <CharacterBody>();
                        if (UseBalancedMode.Value)
                        {
                            PurchaseInteraction pi = self.GetComponent <PurchaseInteraction>();
                            PurchaseInteraction.CreateItemTakenOrb(cb.corePosition, pi.gameObject, ItemIndex.ExtraLife);
                            cb.inventory.RemoveItem(ItemIndex.ExtraLife, 1);
                            cb.inventory.GiveItem(ItemIndex.ExtraLifeConsumed, 1);
                        }
                    }
                }
                else
                {
                    orig(self, interactor);
                }
            };

            On.RoR2.CharacterMaster.OnBodyDeath += (orig, self, masterbody) =>
            {
                orig(self, masterbody);
                if (!RoR2Application.isInSinglePlayer)
                {
                    if (NetworkServer.active)
                    {
                        if (masterbody.isPlayerControlled)
                        {
                            PlayerCharacterMasterController player = self.GetComponent <PlayerCharacterMasterController>();
                            if (!isDead.Contains(player.networkUser))
                            {
                                isDead.Add(player.networkUser);
                            }
                        }
                    }
                }
            };

            On.RoR2.PurchaseInteraction.CanBeAffordedByInteractor += (orig, self, interactor) =>
            {
                if (!RoR2Application.isInSinglePlayer)
                {
                    if (self.displayNameToken.Contains("Shrine of Dio") || self.displayNameToken.Contains("SHRINE_HEALING"))
                    {
                        if (isBalancedMode)
                        {
                            if (interactor.GetComponent <CharacterBody>().inventory.GetItemCount(ItemIndex.ExtraLife) > 0)
                            {
                                if (IsAnyoneDead())
                                {
                                    return(true);
                                }
                            }
                            return(false);
                        }
                        else
                        {
                            if (IsAnyoneDead())
                            {
                                return(orig(self, interactor));
                            }
                            return(false);
                        }
                    }
                    return(orig(self, interactor));
                }
                return(orig(self, interactor));
            };
        }
        public void Awake()
        {
            On.RoR2.SceneDirector.PopulateScene += (orig, self) =>
            {
                orig(self);
                if (RoR2.SceneInfo.instance.sceneDef.stageOrder == 5)
                {
                    SpawnShrineOfDio(self);
                }
            };

            On.RoR2.ShrineHealingBehavior.FixedUpdate += (orig, self) =>
            {
                if (RoR2.SceneInfo.instance.sceneDef.stageOrder != 5)
                {
                    orig(self);
                    return;
                }
                orig(self);

                if (clientCost == UNINITIALIZED)
                {
                    int piCost = self.GetFieldValue <PurchaseInteraction>("purchaseInteraction").cost;
                    if (piCost != clientCost)
                    {
                        clientCost = piCost;
                        if (clientCost == BALANCED_MODE)
                        {
                            isBalancedMode = true;
                        }
                        else
                        {
                            isBalancedMode = false;
                        }
                        Type[] arr = ((IEnumerable <System.Type>) typeof(ChestRevealer).Assembly.GetTypes()).Where <System.Type>((Func <System.Type, bool>)(t => typeof(IInteractable).IsAssignableFrom(t))).ToArray <System.Type>();
                        for (int i = 0; i < arr.Length; i++)
                        {
                            foreach (UnityEngine.MonoBehaviour instances in InstanceTracker.FindInstancesEnumerable(arr[i]))
                            {
                                if (((IInteractable)instances).ShouldShowOnScanner())
                                {
                                    string item = ((IInteractable)instances).ToString().ToLower();
                                    if (item.Contains("shrinehealing"))
                                    {
                                        UpdateShrineDisplay(instances.GetComponentInParent <ShrineHealingBehavior>());
                                    }
                                }
                                ;
                            }
                        }
                    }
                }
            };

            On.RoR2.ShrineHealingBehavior.Awake += (orig, self) =>
            {
                if (RoR2.SceneInfo.instance.sceneDef.stageOrder != 5)
                {
                    orig(self);
                    return;
                }
                orig(self);

                PurchaseInteraction pi = self.GetFieldValue <PurchaseInteraction>("purchaseInteraction");
                pi.contextToken                = "Offer to the Shrine of empowered Dio";
                pi.displayNameToken            = "Shrine of empowered Dio";
                self.costMultiplierPerPurchase = 4f;



                pi.costType = CostTypeIndex.Money;
                //pi.cost = ResurrectionCost.Value * useCount;
                pi.cost = GetDifficultyScaledCost(ResurrectionCost);
            };

            On.RoR2.ShrineHealingBehavior.AddShrineStack += (orig, self, interactor) =>
            {
                if (RoR2.SceneInfo.instance.sceneDef.stageOrder != 5)
                {
                    orig(self, interactor);
                    return;
                }
                string resurrectionMessage = $"<color=#beeca1>{interactor.GetComponent<CharacterBody>().GetUserName()}</color> gained a <color=#beeca1>Dio</color>";
                Chat.SendBroadcastChat(new Chat.SimpleChatMessage
                {
                    baseToken = resurrectionMessage
                });
                self.SetFieldValue("waitingForRefresh", true);
                self.SetFieldValue("refreshTimer", 2f);
                EffectManager.SpawnEffect(Resources.Load <GameObject>("Prefabs/Effects/ShrineUseEffect"), new EffectData()
                {
                    origin   = self.transform.position,
                    rotation = Quaternion.identity,
                    scale    = 1f,
                    color    = (Color32)Color.red
                }, true);
                // dio
                CharacterBody cb = interactor.GetComponent <CharacterBody>();

                PurchaseInteraction pi = self.GetComponent <PurchaseInteraction>();
                PurchaseInteraction.CreateItemTakenOrb(cb.corePosition, pi.gameObject, RoR2.RoR2Content.Items.ExtraLife.itemIndex);
                cb.inventory.RemoveItem(RoR2.RoR2Content.Items.ExtraLifeConsumed.itemIndex, 1);
                cb.inventory.GiveItem(RoR2.RoR2Content.Items.ExtraLife.itemIndex, 1);
                useCount++;
            };

            On.RoR2.PurchaseInteraction.CanBeAffordedByInteractor += (orig, self, interactor) =>
            {
                if (self.displayNameToken.Contains("Shrine of empowered Dio"))
                {
                    if (interactor.GetComponent <CharacterBody>().inventory.GetItemCount(RoR2.RoR2Content.Items.ExtraLifeConsumed) > 0)
                    {
                        return(orig(self, interactor));
                    }
                    return(false);
                }
                return(orig(self, interactor));
            };
        }
Ejemplo n.º 3
0
        private void PurchaseInteraction_OnInteractionBegin(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
        {
            if (isCurrentStageBazaar())
            {
                NetworkUser  networkUser  = Util.LookUpBodyNetworkUser(activator.gameObject);
                BazaarPlayer bazaarPlayer = bazaar.GetBazaarPlayer(networkUser);
                if (!self.CanBeAffordedByInteractor(activator))
                {
                    return;
                }

                if (bazaar.IsMoneyLunarPodAvailable())
                {
                    if (bazaar.IsMoneyLunarPod(self.gameObject))
                    {
                        if (bazaarPlayer.lunarExchanges < ModConfig.maxLunarExchanges.Value || ModConfig.infiniteLunarExchanges)
                        {
                            bazaarPlayer.lunarExchanges++;
                            int money = bazaar.GetLunarCoinExchangeMoney();
                            if (!ModConfig.IsShareSuiteMoneySharing())
                            {
                                activator.GetComponent <CharacterBody>().master.money += ((uint)money);
                            }
                            else
                            {
                                //ShareSuite.MoneySharingHooks.AddMoneyExternal(money);
                                bazaar.ShareSuiteMoneyFix(activator, money);
                            }
                            //activator.GetComponent<CharacterBody>().master.money += ((uint)money);
                            //activator.GetComponent<CharacterBody>().master.GiveMoney((uint)money);
                            networkUser.DeductLunarCoins((uint)self.cost);
                            var        goldReward          = (int)((double)ModConfig.lunarCoinWorth.Value * (double)bazaar.CurrentDifficultyCoefficient);
                            GameObject coinEmitterResource = Resources.Load <GameObject>("Prefabs/Effects/CoinEmitter");
                            EffectManager.SpawnEffect(coinEmitterResource, new EffectData()
                            {
                                origin       = self.transform.position,
                                genericFloat = (float)goldReward
                            }, true);
                            EffectManager.SpawnEffect(coinEmitterResource, new EffectData()
                            {
                                origin       = self.transform.position,
                                genericFloat = (float)goldReward
                            }, true);
                            Util.PlaySound("Play_UI_coin", self.gameObject);
                        }

                        return;
                    }
                }
                // New addition that made everything less nice. Added to check if player still has purchases left
                int bazaarChestIndex            = -1;
                List <BazaarItem>   bazaarItems = bazaar.GetBazaarItems();
                PurchaseInteraction bazaarPI;
                for (int i = 0; i < bazaarItems.Count; i++)
                {
                    // Fix for SavedGames. SavedGames somehow breaks the BiggerBazaar chests and BiggerBazaar breaks everything else in return :)
                    if (bazaarItems[i].chestBehavior == null)
                    {
                        continue;
                    }
                    bazaarPI = bazaarItems[i].chestBehavior.GetComponent <PurchaseInteraction>();
                    if (bazaarPI.Equals(self))
                    {
                        if (!bazaar.PlayerHasPurchasesLeft(bazaarPlayer))
                        {
                            return;
                        }

                        //ItemTier tier = ItemCatalog.GetItemDef(PickupCatalog.GetPickupDef(bazaarItems[i].pickupIndex).itemIndex).tier;
                        PickupTier pickupTier = PickupIndexToPickupTier(bazaarItems[i].pickupIndex);
                        if (!bazaar.PlayerHasTierPurchasesLeft(pickupTier, bazaarPlayer))
                        {
                            return;
                        }
                        if (ModConfig.ShareSuite != null && ModConfig.ShareSuiteTotalPurchaseSharing.Value)
                        {
                            bazaar.GetBazaarPlayers().ForEach(x => x.chestPurchases++);
                        }
                        else
                        {
                            bazaarPlayer.chestPurchases++;
                        }

                        bazaarPlayer.IncreaseTierPurchase(pickupTier);
                        bazaarChestIndex = i;
                        break;
                    }
                }
                // Special case for ShareSuite
                if (ModConfig.isShareSuiteActive() && !ModConfig.ShareSuiteItemSharingEnabled.Value)
                {
                    if (bazaarChestIndex != -1)
                    {
                        CharacterMaster master      = activator.GetComponent <CharacterBody>().master;
                        var             isEquipment = PickupCatalog.GetPickupDef(bazaarItems[bazaarChestIndex].pickupIndex).equipmentIndex == EquipmentIndex.None ? false : true;
                        if (!isEquipment)
                        {
                            master.inventory.GiveItem(PickupCatalog.GetPickupDef(bazaarItems[bazaarChestIndex].pickupIndex).itemIndex);
                        }
                        else
                        {
                            if (!ModConfig.isShareSuiteEquipmentSharing())
                            {
                                PickupDropletController.CreatePickupDroplet(PickupCatalog.FindPickupIndex(master.inventory.GetEquipmentIndex()), master.GetBody().gameObject.transform.position + Vector3.up * 1.5f, Vector3.up * 20f + self.transform.forward * 2f);
                            }
                            master.inventory.SetEquipmentIndex(PickupCatalog.GetPickupDef(bazaarItems[bazaarChestIndex].pickupIndex).equipmentIndex);
                        }


                        if (ModConfig.chestCostType.Value == 1)
                        {
                            var netUser = Util.LookUpBodyNetworkUser(master.GetBody());
                            netUser.DeductLunarCoins((uint)self.cost);
                        }
                        else
                        {
                            if (!ModConfig.IsShareSuiteMoneySharing())
                            {
                                master.money -= (uint)self.cost;
                            }
                            else
                            {
                                //ShareSuite.MoneySharingHooks.AddMoneyExternal(-self.cost);
                                bazaar.ShareSuiteMoneyFix(activator, -self.cost);
                            }
                        }

                        bazaarItems[bazaarChestIndex].purchaseCount++;
                        if (!bazaar.IsChestStillAvailable(bazaarItems[bazaarChestIndex]))
                        {
                            self.GetComponent <PurchaseInteraction>().SetAvailable(false);
                        }

                        Vector3 effectPos = self.transform.position;
                        effectPos.y -= 1;
                        EffectManager.SpawnEffect(Resources.Load <GameObject>("Prefabs/Effects/ShrineUseEffect"), new EffectData()
                        {
                            origin   = effectPos,
                            rotation = Quaternion.identity,
                            scale    = 0.01f,
                            color    = (Color32)Color.yellow
                        }, true);
                        PurchaseInteraction.CreateItemTakenOrb(self.gameObject.transform.position, activator.GetComponent <CharacterBody>().gameObject, PickupCatalog.GetPickupDef(bazaarItems[bazaarChestIndex].pickupIndex).itemIndex);

                        return;
                    }
                }
            }
            orig(self, activator);
        }