Esempio n. 1
0
        public static void OnShopPurchase()
        {
            On.RoR2.PurchaseInteraction.OnInteractionBegin += (orig, self, activator) =>
            {
                if (!ShareSuite.ModIsEnabled.Value)
                {
                    orig(self, activator);
                    return;
                }

                // Return if you can't afford the item
                if (!self.CanBeAffordedByInteractor(activator))
                {
                    return;
                }

                var characterBody = activator.GetComponent <CharacterBody>();
                var inventory     = characterBody.inventory;

                if (ShareSuite.MoneyIsShared.Value)
                {
                    //TODO add comments on what this does
                    switch (self.costType)
                    {
                    case CostTypeIndex.Money:
                    {
                        orig(self, activator);
                        SharedMoneyValue -= self.cost;
                        return;
                    }

                    case CostTypeIndex.PercentHealth:
                    {
                        orig(self, activator);
                        var teamMaxHealth = 0;
                        foreach (var playerCharacterMasterController in PlayerCharacterMasterController.instances)
                        {
                            var charMaxHealth = playerCharacterMasterController.master.GetBody().maxHealth;
                            if (charMaxHealth > teamMaxHealth)
                            {
                                teamMaxHealth = (int)charMaxHealth;
                            }
                        }

                        var purchaseInteraction = self.GetComponent <PurchaseInteraction>();
                        var shrineBloodBehavior = self.GetComponent <ShrineBloodBehavior>();
                        var amount = (uint)(teamMaxHealth * purchaseInteraction.cost / 100.0 *
                                            shrineBloodBehavior.goldToPaidHpRatio);

                        if (ShareSuite.MoneyScalarEnabled.Value)
                        {
                            amount *= (uint)ShareSuite.MoneyScalar.Value;
                        }

                        SharedMoneyValue += (int)amount;
                        return;
                    }
                    }
                }

                // If this is not a multi-player server or the fix is disabled, do the normal drop action
                if (!IsMultiplayer() || !ShareSuite.PrinterCauldronFixEnabled.Value)
                {
                    orig(self, activator);
                    return;
                }

                var shop = self.GetComponent <ShopTerminalBehavior>();

                // If the cost type is an item, give the user the item directly and send the pickup message
                if (self.costType == CostTypeIndex.WhiteItem ||
                    self.costType == CostTypeIndex.GreenItem ||
                    self.costType == CostTypeIndex.RedItem)
                {
                    var item = shop.CurrentPickupIndex().itemIndex;
                    inventory.GiveItem(item);
                    SendPickupMessage.Invoke(null,
                                             new object[] { inventory.GetComponent <CharacterMaster>(), shop.CurrentPickupIndex() });
                }

                orig(self, activator);
            };
        }
        public static void OnShopPurchase()
        {
            On.RoR2.PurchaseInteraction.OnInteractionBegin += (orig, self, activator) =>
            {
                if (!ShareSuite.ModIsEnabled.Value)
                {
                    orig(self, activator);
                    return;
                }

                // Return if you can't afford the item
                if (!self.CanBeAffordedByInteractor(activator))
                {
                    return;
                }

                var characterBody = activator.GetComponent <CharacterBody>();
                var inventory     = characterBody.inventory;

                #region Sharedmoney

                if (ShareSuite.MoneyIsShared.Value)
                {
                    switch (self.costType)
                    {
                    case CostTypeIndex.Money:
                    {
                        // Remove money from shared money pool
                        orig(self, activator);
                        MoneySharingHooks.SharedMoneyValue -= self.cost;
                        return;
                    }

                    case CostTypeIndex.PercentHealth:
                    {
                        // Share the damage taken from a sacrifice
                        // as it generates shared money
                        orig(self, activator);
                        var teamMaxHealth = 0;
                        foreach (var playerCharacterMasterController in PlayerCharacterMasterController.instances)
                        {
                            var charMaxHealth = playerCharacterMasterController.master.GetBody().maxHealth;
                            if (charMaxHealth > teamMaxHealth)
                            {
                                teamMaxHealth = (int)charMaxHealth;
                            }
                        }

                        var purchaseInteraction = self.GetComponent <PurchaseInteraction>();
                        var shrineBloodBehavior = self.GetComponent <ShrineBloodBehavior>();
                        var amount = (uint)(teamMaxHealth * purchaseInteraction.cost / 100.0 *
                                            shrineBloodBehavior.goldToPaidHpRatio);

                        if (ShareSuite.MoneyScalarEnabled.Value)
                        {
                            amount *= (uint)ShareSuite.MoneyScalar.Value;
                        }

                        MoneySharingHooks.SharedMoneyValue += (int)amount;
                        return;
                    }
                    }
                }

                #endregion

                #region Cauldronfix

                // If this is not a multi-player server or the fix is disabled, do the normal drop action
                if (!GeneralHooks.IsMultiplayer() || !ShareSuite.PrinterCauldronFixEnabled.Value)
                {
                    orig(self, activator);
                    return;
                }

                var shop = self.GetComponent <ShopTerminalBehavior>();

                // If the cost type is an item, give the user the item directly and send the pickup message
                if (self.costType == CostTypeIndex.WhiteItem ||
                    self.costType == CostTypeIndex.GreenItem ||
                    self.costType == CostTypeIndex.RedItem ||
                    self.costType == CostTypeIndex.BossItem ||
                    self.costType == CostTypeIndex.LunarItemOrEquipment)
                {
                    var item = PickupCatalog.GetPickupDef(shop.CurrentPickupIndex()).itemIndex;
                    inventory.GiveItem(item);
                    SendPickupMessage.Invoke(null,
                                             new object[] { inventory.GetComponent <CharacterMaster>(), shop.CurrentPickupIndex() });
                }

                #endregion Cauldronfix

                orig(self, activator);
            };
        }