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>(); } } } }
// bazaar building private void SpawnBazaarItemAt(Vector3 position, Vector3 rotation, PickupTier pickupTier, int cost) { // chest players interact with SpawnCard chestCard; if (ModConfig.chestCostType.Value == 0) { chestCard = Resources.Load <SpawnCard>("SpawnCards/InteractableSpawnCard/iscChest1"); } else { chestCard = Resources.Load <SpawnCard>("SpawnCards/InteractableSpawnCard/iscLunarChest"); } DirectorPlacementRule placementRule = new DirectorPlacementRule(); placementRule.placementMode = DirectorPlacementRule.PlacementMode.Direct; GameObject chest = chestCard.DoSpawn(position, Quaternion.Euler(new Vector3(0f, 0f, 0f)), new DirectorSpawnRequest(chestCard, placementRule, Run.instance.runRNG)).spawnedInstance; chest.transform.eulerAngles = rotation; ItemIndex rItem; PickupIndex rPickupIndex; List <PickupIndex> availableItems = GetAvailableItems(pickupTier); //if(availableItems.Count > 0) //{ int rItemIndex = r.Next(availableItems.Count); rPickupIndex = availableItems[rItemIndex]; //rItem = PickupCatalog.GetPickupDef(rPickupIndex).itemIndex; //} //else //{ // List<ItemIndex> drops = ItemDropAPI.GetDefaultDropList(pickupTier); // int rItemIndex = r.Next(drops.Count); // rItem = drops[rItemIndex]; //} GameObject itemGameObject = UnityEngine.Object.Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/NetworkedObjects/GenericPickup"), position, Quaternion.identity); itemGameObject.GetComponent <GenericPickupController>().transform.Translate(-2f, 4f, -3f, Space.World); itemGameObject.GetComponent <GenericPickupController>().NetworkpickupIndex = rPickupIndex; displayItems.Add(itemGameObject); NetworkServer.Spawn(itemGameObject); var chestPI = chest.GetComponent <PurchaseInteraction>(); if (ModConfig.chestCostType.Value == 1) { chestPI.costType = CostTypeIndex.LunarCoin; chestPI.Networkcost = cost; //chestPI.SetDirtyBit(12u); } else if (cost == -1) { if (ModConfig.nextLevelChestPriceScaling.Value) { //next level price scaling chestPI.Networkcost = Run.instance.GetDifficultyScaledCost(chestPI.cost); chestPI.Networkcost = (int)(chestPI.Networkcost * ModConfig.GetTierUnitConfig(pickupTier).cost); } else { //previous level price scaling chestPI.Networkcost = GetDifficultyScaledCostFromItemTier(chestPI.cost); chestPI.Networkcost = (int)(chestPI.Networkcost * ModConfig.GetTierUnitConfig(pickupTier).cost); } } else { chestPI.Networkcost = GetDifficultyScaledCost(cost); } BazaarItem bazaarItem = new BazaarItem(); bazaarItem.chestBehavior = chest.GetComponent <ChestBehavior>(); bazaarItem.genericPickupController = itemGameObject.GetComponent <GenericPickupController>(); bazaarItem.pickupIndex = rPickupIndex; bazaarItem.purchaseCount = 0; bazaarItem.maxPurchases = ModConfig.GetTierUnitConfig(pickupTier).maxChestPurchases; bazaarItems.Add(bazaarItem); itemGameObject.GetComponent <GenericPickupController>().pickupIndex = PickupIndex.none; }