-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShopsOnly.cs
139 lines (113 loc) · 4.59 KB
/
ShopsOnly.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using BepInEx;
using Nekusoul.ShopsOnly;
using RoR2;
using RoR2.ContentManagement;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace NekuSoul.ShopsOnly
{
[BepInPlugin("de.NekuSoul.ShopsOnly", "ShopsOnly", "3.0.3")]
public class ShopsOnly : BaseUnityPlugin
{
private static readonly string[] ReplacedChoices =
{
"Chest1",
"Chest2",
"CategoryChestDamage",
"CategoryChestHealing",
"CategoryChestUtility",
"CategoryChest2Damage Variant",
"CategoryChest2Healing Variant",
"CategoryChest2Utility Variant"
};
private readonly ContentPackProvider _content = new ContentPackProvider();
public void Awake()
{
On.RoR2.MultiShopController.CreateTerminals += MultiShopController_CreateTerminals;
On.RoR2.SceneDirector.GenerateInteractableCardSelection += SceneDirector_GenerateInteractableCardSelection;
ContentManager.collectContentPackProviders += ContentManager_collectContentPackProviders;
}
private void ContentManager_collectContentPackProviders(ContentManager.AddContentPackProviderDelegate addContentPackProvider)
{
addContentPackProvider(_content);
}
private void MultiShopController_CreateTerminals(On.RoR2.MultiShopController.orig_CreateTerminals orig, MultiShopController self)
{
if (!RunArtifactManager.instance.IsArtifactEnabled(_content.Artifact))
{
orig(self);
return;
}
if (self.doEquipmentInstead)
{
orig(self);
return;
}
var rng = (Xoroshiro128Plus)typeof(MultiShopController).GetField("rng", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(self);
if (rng == null)
{
orig(self);
return;
}
var val = rng.RangeFloat(0, 1);
if (val > 0.975f)
{
self.itemTier = ItemTier.Tier3;
self.baseCost = 400;
}
else if (val > 0.8f)
{
self.itemTier = ItemTier.Tier2;
self.baseCost = 50;
}
else
{
self.itemTier = ItemTier.Tier1;
self.baseCost = 25;
}
self.Networkcost = Run.instance.GetDifficultyScaledCost(self.baseCost);
orig(self);
var terminalGameObjects = (GameObject[])typeof(MultiShopController)
.GetField("_terminalGameObjects", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(self);
foreach (var terminalGameObject in terminalGameObjects)
{
var shopTerminalBehavior = terminalGameObject.GetComponent<ShopTerminalBehavior>();
shopTerminalBehavior.itemTier = self.itemTier;
shopTerminalBehavior.dropTable = null;
var purchaseInteraction = terminalGameObject.GetComponent<PurchaseInteraction>();
purchaseInteraction.Networkcost = self.Networkcost;
}
}
private WeightedSelection<DirectorCard> SceneDirector_GenerateInteractableCardSelection(On.RoR2.SceneDirector.orig_GenerateInteractableCardSelection orig, SceneDirector self)
{
if (!RunArtifactManager.instance.IsArtifactEnabled(_content.Artifact))
{
return orig(self);
}
var weightedSelection = orig(self);
var chestChance = 0f;
for (var i = 0; i < weightedSelection.Count; i++)
{
var choiceInfo = weightedSelection.GetChoice(i);
var prefabName = choiceInfo.value.spawnCard.prefab.name;
if (!ReplacedChoices.Contains(prefabName))
continue;
chestChance += choiceInfo.weight;
choiceInfo.weight = 0f;
weightedSelection.ModifyChoiceWeight(i, 0);
}
for (var i = 0; i < weightedSelection.Count; i++)
{
var choiceInfo = weightedSelection.GetChoice(i);
var prefabName = choiceInfo.value.spawnCard.prefab.name;
if (prefabName != "TripleShop")
continue;
chestChance += choiceInfo.weight;
choiceInfo.weight += chestChance;
weightedSelection.ModifyChoiceWeight(i, choiceInfo.weight);
}
return weightedSelection;
}
}
}