Exemplo n.º 1
0
        private void ChestBehavior_Open(On.RoR2.ChestBehavior.orig_Open orig, ChestBehavior self)
        {
            if (NetworkServer.active)
            {
                if (isCurrentStageBazaar())
                {
                    bool isCreatingDroplet = false;
                    if (!ModConfig.isShareSuiteLoaded || !ModConfig.isShareSuiteActive())
                    {
                        isCreatingDroplet = true;
                    }
                    else
                    {
                        if (ModConfig.ShareSuiteItemSharingEnabled.Value)
                        {
                            isCreatingDroplet = true;
                        }
                    }
                    if (isCreatingDroplet)
                    {
                        List <BazaarItem> bazaarItems = bazaar.GetBazaarItems();
                        for (int i = 0; i < bazaar.GetBazaarItemAmount(); i++)
                        {
                            if (bazaarItems[i].chestBehavior.Equals(self))
                            {
                                PickupDropletController.CreatePickupDroplet(bazaarItems[i].pickupIndex, self.transform.position + Vector3.up * 1.5f, Vector3.up * 20f + self.transform.forward * 2f);
                                bazaarItems[i].purchaseCount++;
                                if (bazaar.IsChestStillAvailable(bazaarItems[i]))
                                {
                                    self.GetComponent <PurchaseInteraction>().SetAvailable(true);
                                }

                                return;
                            }
                        }
                    }
                }
                ;
            }
            orig(self);
        }
Exemplo n.º 2
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);
        }