//////////////// private VendorLogic(int npcType) { this.NpcType = npcType; this.TotalPurchases = new Dictionary <int, float>(); this.TotalSpendings = new Dictionary <int, float>(); this.BasePrices = new Dictionary <int, long>(); Chest shop = NPCTownHelpers.GetShop(this.NpcType); ISet <int> foundTypes = new HashSet <int>(); for (int i = 0; i < shop.item.Length; i++) { Item item = shop.item[i]; if (item == null || item.type == 0) { break; } if (foundTypes.Contains(item.type)) { continue; } foundTypes.Add(item.type); item.SetDefaults(item.type); this.BasePrices[item.type] = item.value; this.TotalPurchases[item.type] = 0; this.TotalSpendings[item.type] = 0; } }
//////////////// public static VendorLogic Create(int npcType) { Chest shop = NPCTownHelpers.GetShop(npcType); if (shop == null) { return(null); } return(new VendorLogic(npcType)); }
//////////////// public void Update() { var mymod = RewardsMod.Instance; if (!this.HasCheckedInstantWayfarer && ModContent.NPCType <WayfarerTownNPC>() != 0) { this.HasCheckedInstantWayfarer = true; if (mymod.SettingsConfig.InstantWayfarer) { if (WayfarerTownNPC.CanWayfarerSpawn()) { NPCTownHelpers.Spawn(ModContent.NPCType <WayfarerTownNPC>(), Main.spawnTileX, Main.spawnTileY); } } } lock (WorldLogic.MyLock) { this.UpdateEvents(); } }
private int UpdateShopItem(Item item, Chest shop = null) { var mymod = CapitalismMod.Instance; // Compute new price int price = (int)this.GetPriceOf(item.type); // Female NPCs during a bloodmoon markup their prices bool isGrill = NPCTownHelpers.GetFemaleTownNpcTypes().Contains(this.NpcType); if (Main.bloodMoon && isGrill) { price = (int)((float)price * mymod.Config.FemaleBloodMoonSellPricePercent); } NPC npc = NPCFinderHelpers.FindFirstNpcByType(this.NpcType); Player player = Main.player[Main.myPlayer]; if (npc != null && player != null) { // Stinky players markup prices if (player.FindBuffIndex(120) >= 0) { price = (int)((float)price * mymod.Config.StinkySellPricePercent); } // Love struck NPCs markdown prices if (npc.FindBuffIndex(119) >= 0) { bool isGendered = !NPCTownHelpers.GetNonGenderedTownNpcTypes().Contains(this.NpcType); if (isGendered && (player.Male && isGrill) || (!player.Male && !isGrill)) { price = (int)((float)price * mymod.Config.LovestruckSellPricePercent); } } } return(price); }
//////////////// public void UpdateShop(Chest shop = null) { if (shop == null) { shop = NPCTownHelpers.GetShop(this.NpcType); if (shop == null) { return; } } ISet <int> foundTypes = new HashSet <int>(); for (int i = 0; i < shop.item.Length; i++) { Item item = shop.item[i]; if (item == null || item.type <= 0 || item.stack <= 0) { break; } // Update only the first instance of an item if (foundTypes.Contains(item.type)) { continue; } foundTypes.Add(item.type); int value = this.UpdateShopItem(item, shop); double basePrice = (double)this.BasePrices[item.type]; double markup = ((double)value - basePrice) / basePrice; item.value = value; var itemInfo = item.GetGlobalItem <CapitalismItemInfo>(); itemInfo.MarkupPercentPlus = markup; } }
//////////////// public static void SpawnWayfarer(bool ignoreClones) { var mymod = RewardsMod.Instance; int wayfarerType = ModContent.NPCType <WayfarerTownNPC>(); bool isSpawned = false; for (int i = 0; i < Main.npc.Length; i++) { NPC npc = Main.npc[i]; if (npc == null || !npc.active || npc.type != wayfarerType) { continue; } isSpawned = true; break; } if (!isSpawned || ignoreClones) { NPCTownHelpers.Spawn(ModContent.NPCType <WayfarerTownNPC>(), Main.spawnTileX, Main.spawnTileY); } }