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);
        }
Exemple #2
0
        public void StartBazaar(BiggerBazaar biggerBazaar)
        {
            isUsingexperimentalScaling = false;
            if (!ModConfig.disableTransferMoney.Value)
            {
                for (int i = 0; i < PlayerCharacterMasterController.instances.Count; i++)
                {
                    for (int j = 0; j < bazaarPlayers.Count; j++)
                    {
                        if (bazaarPlayers[j].networkUser == PlayerCharacterMasterController.instances[i].networkUser)
                        {
                            if (!ModConfig.IsShareSuiteMoneySharing())
                            {
                                PlayerCharacterMasterController.instances[i].master.money = bazaarPlayers[j].money;
                                break;
                            }

                            //ShareSuite.MoneySharingHooks.AddMoneyExternal((int)this.bazaarPlayers[j].money);
                            biggerBazaar.StartCoroutine(TriggerInteractorBarrelInteraction(PlayerCharacterMasterController.instances[i].master, GetShareSuiteSharedMoneyValue()));
                            goto done;
                        }
                    }
                }
                done :;
            }

            ClearBazaarItems();
            List <PickupTier> bazaarItemTiers = PickRandomWeightedBazaarItemTiers(bazaarItemAmount);

            //uint playerMoney = 0;
            //for (int i = 0; i < bazaarPlayers.Count; i++)
            //{
            //    playerMoney += bazaarPlayers[i].money;
            //}
            if (AreAnyItemsAvailable() && bazaarItemTiers != null)
            {
                if (ModConfig.chestCostType.Value == 1)
                {
                    for (int i = 0; i < bazaarItemTiers.Count; i++)
                    {
                        SpawnBazaarItemAt(bazaarItemPositions[i], bazaarItemRotations[i], bazaarItemTiers[i], ModConfig.GetTierUnitConfig(bazaarItemTiers[i]).costLunar);
                    }
                    //}
                    // experimental price scaling
                    //else if (ModConfig.experimentalPriceScaling.Value && DoPlayersHaveTooMuchMoney(playerMoney, bazaarItemTiers))
                    //{
                    //    isUsingexperimentalScaling = true;
                    //    uint unscaledPlayerMoney = GetDifficultyUnscaledCost(playerMoney);
                    //    float chestUnits = 0f;

                    //    for (int i = 0; i < bazaarItemTiers.Count; i++)
                    //    {
                    //        if (bazaarItemTiers[i] == ItemTier.Tier1)
                    //        {
                    //            chestUnits += 1f * ModConfig.maxChestPurchasesTier1.Value;
                    //        }
                    //        else if (bazaarItemTiers[i] == ItemTier.Tier2)
                    //        {
                    //            chestUnits += tierRatio[bazaarItemTiers[i]] * ModConfig.maxChestPurchasesTier2.Value;
                    //        }
                    //        else if (bazaarItemTiers[i] == ItemTier.Tier3)
                    //        {
                    //            chestUnits += tierRatio[bazaarItemTiers[i]] * ModConfig.maxChestPurchasesTier3.Value;
                    //        }
                    //    }

                    //    int tier1BaseCost = (int)(unscaledPlayerMoney / chestUnits);
                    //    double randomMult = r.NextDouble() * (ModConfig.experimentalPriceScalingMaxPercent.Value - ModConfig.experimentalPriceScalingMinPercent.Value) + ModConfig.experimentalPriceScalingMinPercent.Value;
                    //    for (int i = 0; i < bazaarItemTiers.Count; i++)
                    //    {
                    //        tierRatio.TryGetValue(bazaarItemTiers[i], out float val);
                    //        int scaledCost = (int)(tier1BaseCost * ((1f / randomMult) * val));
                    //        //Debug.Log("Tier " + bazaarItemTiers[i] + ": " + scaledCost);
                    //        SpawnBazaarItemAt(bazaarItemPositions[i], bazaarItemRotations[i], bazaarItemTiers[i], scaledCost);
                    //    }
                    //    priceScaledLunarPodBaseCost = (int)(tier1BaseCost * ((1f / randomMult) * tierRatio[ItemTier.Tier2]));
                }
                else
                // regular price
                {
                    for (int i = 0; i < bazaarItemTiers.Count; i++)
                    {
                        SpawnBazaarItemAt(bazaarItemPositions[i], bazaarItemRotations[i], bazaarItemTiers[i], -1);
                    }
                }
                if (ModConfig.maxLunarExchanges.Value != 0)
                {
                    SpawnMoneyLunarPod(moneyPodPosition);
                }

                if (ModConfig.isShareSuiteLoaded)
                {
                    // if money sharing spawn a barrel interaction that handles giving money because of the ShareSuite money sharing issue
                    if (ModConfig.IsShareSuiteMoneySharing())
                    {
                        SpawnCard             barrelCard     = Resources.Load <SpawnCard>("SpawnCards/InteractableSpawnCard/iscBarrel1");
                        Vector3               barrelPosition = new Vector3(200f, 200f, 200f);
                        DirectorPlacementRule placementRule  = new DirectorPlacementRule();
                        placementRule.placementMode = DirectorPlacementRule.PlacementMode.Direct;
                        GameObject barrelGameObject = barrelCard.DoSpawn(barrelPosition, Quaternion.identity, new DirectorSpawnRequest(barrelCard, placementRule, Run.instance.runRNG)).spawnedInstance;
                        barrelInteraction = barrelGameObject.GetComponent <BarrelInteraction>();
                    }
                }
            }
        }