Skip to content

Commit 5bf3c03

Browse files
authored
Rework Pest Weight (#73)
* Update crop weight values * Update pest drop numbers * Update pest calculations and balance against fly pests * Make pests more testable and update tests
1 parent 0e616c1 commit 5bf3c03

File tree

11 files changed

+349
-456
lines changed

11 files changed

+349
-456
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using EliteAPI.Utilities;
2+
using Microsoft.Extensions.Configuration;
3+
4+
namespace EliteAPI.Tests;
5+
6+
public class ConfigurationTests
7+
{
8+
private readonly IConfiguration _configuration;
9+
10+
public ConfigurationTests()
11+
{
12+
var configurationBuilder = new ConfigurationBuilder();
13+
configurationBuilder.RegisterEliteConfigFiles();
14+
_configuration = configurationBuilder.Build();
15+
}
16+
17+
[Fact]
18+
public void TestConfigurationContainsExpectedSection()
19+
{
20+
var farmingWeightSection = _configuration.GetSection("FarmingWeight");
21+
farmingWeightSection.Should().NotBeNull();
22+
}
23+
}

EliteAPI.Tests/EliteAPI.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@
2727
<ProjectReference Include="..\EliteAPI\EliteAPI.csproj" />
2828
</ItemGroup>
2929

30+
<ItemGroup>
31+
<Content Include="..\EliteAPI\Configuration\**\*.json">
32+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
<Link>Configuration\%(RecursiveDir)%(Filename)%(Extension)</Link>
34+
</Content>
35+
</ItemGroup>
3036
</Project>
Lines changed: 38 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,57 @@
11
using EliteAPI.Configuration.Settings;
22
using EliteAPI.Models.Entities.Hypixel;
33
using EliteAPI.Parsers.Farming;
4+
using EliteAPI.Utilities;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Options;
48

59
namespace EliteAPI.Tests.ParserTests;
610

711
public class PestParserTests {
8-
912
[Fact]
1013
public void ParsePestCropCollectionNumbersTest() {
11-
PestParser.CalcUncountedCrops(Pest.Mite, 0).Should().Be(0);
12-
PestParser.CalcUncountedCrops(Pest.Mite, 25).Should().Be(0);
13-
PestParser.CalcUncountedCrops(Pest.Mite, 50).Should().Be(0);
14-
PestParser.CalcUncountedCrops(Pest.Mite, 51).Should()
15-
.Be((int) Math.Ceiling(FarmingItemsConfig.Settings.PestCropDropChances[Pest.Mite].GetCropsDropped(250) * 1));
14+
var configurationBuilder = new ConfigurationBuilder();
15+
configurationBuilder.RegisterEliteConfigFiles();
16+
var configuration = configurationBuilder.Build();
17+
18+
var services = new ServiceCollection();
19+
services.Configure<ConfigFarmingWeightSettings>(configuration.GetSection("FarmingWeight"));
20+
var serviceProvider = services.BuildServiceProvider();
21+
22+
var weightConfig = serviceProvider.GetRequiredService<IOptions<ConfigFarmingWeightSettings>>().Value;
1623

17-
PestParser.CalcUncountedCrops(Pest.Cricket, 426).Should().Be(834343);
24+
PestParser.CalcUncountedCrops(Pest.Mite, 0, weightConfig).Should().Be(0);
25+
PestParser.CalcUncountedCrops(Pest.Mite, 25, weightConfig).Should().Be(0);
26+
PestParser.CalcUncountedCrops(Pest.Mite, 50, weightConfig).Should().Be(0);
27+
PestParser.CalcUncountedCrops(Pest.Mite, 51, weightConfig).Should()
28+
.Be((int) Math.Ceiling(weightConfig.PestCropDropChances[Pest.Mite].GetCropsToSubtract(250, weightConfig: weightConfig) * 1));
29+
30+
PestParser.CalcUncountedCrops(Pest.Cricket, 426, weightConfig).Should().Be(370802);
1831
}
1932

2033
[Fact]
2134
public void PestCollectionsTest() {
22-
FarmingItemsConfig.Settings.PestCropDropChances[Pest.Slug].GetCropsDropped(1300, true, false)
23-
.Should().BeApproximately(2402.13, 0.01);
35+
var configurationBuilder = new ConfigurationBuilder();
36+
configurationBuilder.RegisterEliteConfigFiles();
37+
var configuration = configurationBuilder.Build();
2438

25-
FarmingItemsConfig.Settings.PestCropDropChances[Pest.Slug].GetCropsDropped(0, true, false)
26-
.Should().BeApproximately(211.2, 0.01);
39+
var services = new ServiceCollection();
40+
services.Configure<ConfigFarmingWeightSettings>(configuration.GetSection("FarmingWeight"));
41+
var serviceProvider = services.BuildServiceProvider();
2742

28-
FarmingItemsConfig.Settings.PestCropDropChances[Pest.Fly].GetCropsDropped(1300, true, false)
29-
.Should().BeApproximately(24053.76, 0.01);
43+
var weightConfig = serviceProvider.GetRequiredService<IOptions<ConfigFarmingWeightSettings>>().Value;
3044

31-
FarmingItemsConfig.Settings.PestCropDropChances[Pest.Fly].GetCropsDropped(0, true, false)
32-
.Should().BeApproximately(3162.24, 0.01);
33-
}
34-
35-
36-
public PestParserTests() {
37-
FarmingItemsConfig.Settings.PestDropBrackets = new Dictionary<string, int> {
38-
{ "0", 0 }, { "50", 250 }, { "100", 500 }, { "250", 750 },
39-
{ "500", 1000 }, { "750", 1250 }, { "1000", 1500 }
40-
};
41-
42-
FarmingItemsConfig.Settings.PestCropDropChances = new Dictionary<Pest, PestDropChance> {
43-
{
44-
Pest.Mite, new() {
45-
Base = 160,
46-
Rare = [
47-
new PestRngDrop {
48-
Drops = 25600,
49-
Chance = 0.02
50-
}
51-
]
52-
}
53-
}, {
54-
Pest.Cricket, new() {
55-
Base = 160,
56-
Rare = [
57-
new PestRngDrop {
58-
Drops = 20480,
59-
Chance = 0.03
60-
}
61-
]
62-
}
63-
}, {
64-
Pest.Moth, new() {
65-
Base = 160,
66-
Rare = [
67-
new PestRngDrop {
68-
Drops = 20480,
69-
Chance = 0.03
70-
}
71-
]
72-
}
73-
}, {
74-
Pest.Earthworm, new() {
75-
Base = 160,
76-
Rare = [
77-
new PestRngDrop {
78-
Drops = 25600,
79-
Chance = 0.04
80-
}
81-
]
82-
}
83-
}, {
84-
Pest.Slug, new() {
85-
Base = 160,
86-
Rare = [
87-
new PestRngDrop {
88-
Drops = 5120,
89-
Chance = 0.005
90-
},
91-
new PestRngDrop {
92-
Drops = 5120,
93-
Chance = 0.005
94-
}
95-
]
96-
}
97-
}, {
98-
Pest.Beetle, new() {
99-
Base = 160,
100-
Rare = [
101-
new PestRngDrop {
102-
Drops = 25600,
103-
Chance = 0.03
104-
}
105-
]
106-
}
107-
}, {
108-
Pest.Locust, new() {
109-
Base = 160,
110-
Rare = [
111-
new PestRngDrop {
112-
Drops = 25600,
113-
Chance = 0.03
114-
}
115-
]
116-
}
117-
}, {
118-
Pest.Rat, new() {
119-
Base = 160,
120-
Rare = [
121-
new PestRngDrop {
122-
Drops = 25600,
123-
Chance = 0.01
124-
}
125-
]
126-
}
127-
}, {
128-
Pest.Mosquito, new() {
129-
Base = 160,
130-
Rare = [
131-
new PestRngDrop {
132-
Drops = 25600,
133-
Chance = 0.02
134-
}
135-
]
136-
}
137-
}, {
138-
Pest.Fly, new() {
139-
Base = 1296,
140-
Rare = [
141-
new PestRngDrop {
142-
Drops = 186624,
143-
Chance = 0.01
144-
}
145-
]
146-
}
147-
}
148-
};
45+
weightConfig.PestCropDropChances[Pest.Slug].GetCropsToSubtract(1300, true, false, weightConfig)
46+
.Should().BeApproximately(662.77, 0.01);
47+
48+
weightConfig.PestCropDropChances[Pest.Slug].GetCropsToSubtract(0, true, false, weightConfig)
49+
.Should().BeApproximately(49.26, 0.01);
50+
51+
weightConfig.PestCropDropChances[Pest.Fly].GetCropsToSubtract(1300, true, false, weightConfig)
52+
.Should().BeApproximately(0.0, 0.01);
53+
54+
weightConfig.PestCropDropChances[Pest.Fly].GetCropsToSubtract(0, true, false, weightConfig)
55+
.Should().BeApproximately(0.0, 0.01);
14956
}
15057
}
Lines changed: 11 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using EliteAPI.Configuration.Settings;
2-
using EliteAPI.Models.Entities.Hypixel;
32
using EliteAPI.Models.Entities.Timescale;
43
using EliteAPI.Parsers.Farming;
4+
using EliteAPI.Utilities;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Options;
58

69
namespace EliteAPI.Tests.WeightTests;
710

@@ -58,133 +61,14 @@ public void CropWeightTests() {
5861

5962

6063
public WeightParserTests() {
61-
FarmingWeightConfig.Settings.CropsPerOneWeight = new() {
62-
{ "CACTUS", 177254.45 },
63-
{ "CARROT_ITEM", 302061.86 },
64-
{ "INK_SACK_3", 267174.04 },
65-
{ "MELON", 485308.47 },
66-
{ "MUSHROOM_COLLECTION", 90178.06 },
67-
{ "NETHER_STALK", 250000 },
68-
{ "POTATO_ITEM", 300000 },
69-
{ "PUMPKIN", 98284.71 },
70-
{ "SUGAR_CANE", 200000 },
71-
{ "WHEAT", 100000 }
72-
};
64+
var configurationBuilder = new ConfigurationBuilder();
65+
configurationBuilder.RegisterEliteConfigFiles();
66+
var configuration = configurationBuilder.Build();
7367

74-
FarmingWeightConfig.Settings.CropItemIds = FarmingWeightConfig.Settings.CropsPerOneWeight.Keys
75-
.Select(c => c == "INK_SACK_3" ? "INK_SACK:3" : c).ToList();
68+
var services = new ServiceCollection();
69+
services.Configure<ConfigFarmingWeightSettings>(configuration.GetSection("FarmingWeight"));
70+
var serviceProvider = services.BuildServiceProvider();
7671

77-
FarmingItemsConfig.Settings.PestDropBrackets = new Dictionary<string, int> {
78-
{ "0", 0 }, { "50", 250 }, { "100", 500 }, { "250", 750 },
79-
{ "500", 1000 }, { "750", 1250 }, { "1000", 1500 }
80-
};
81-
82-
FarmingItemsConfig.Settings.PestCropDropChances = new Dictionary<Pest, PestDropChance> {
83-
{
84-
Pest.Mite, new() {
85-
Base = 160,
86-
Rare = [
87-
new PestRngDrop {
88-
Drops = 25600,
89-
Chance = 0.02
90-
}
91-
]
92-
}
93-
}, {
94-
Pest.Cricket, new() {
95-
Base = 160,
96-
Rare = [
97-
new PestRngDrop {
98-
Drops = 20480,
99-
Chance = 0.03
100-
}
101-
]
102-
}
103-
}, {
104-
Pest.Moth, new() {
105-
Base = 160,
106-
Rare = [
107-
new PestRngDrop {
108-
Drops = 20480,
109-
Chance = 0.03
110-
}
111-
]
112-
}
113-
}, {
114-
Pest.Earthworm, new() {
115-
Base = 160,
116-
Rare = [
117-
new PestRngDrop {
118-
Drops = 25600,
119-
Chance = 0.04
120-
}
121-
]
122-
}
123-
}, {
124-
Pest.Slug, new() {
125-
Base = 160,
126-
Rare = [
127-
new PestRngDrop {
128-
Drops = 5120,
129-
Chance = 0.005
130-
},
131-
new PestRngDrop {
132-
Drops = 5120,
133-
Chance = 0.005
134-
}
135-
]
136-
}
137-
}, {
138-
Pest.Beetle, new() {
139-
Base = 160,
140-
Rare = [
141-
new PestRngDrop {
142-
Drops = 25600,
143-
Chance = 0.03
144-
}
145-
]
146-
}
147-
}, {
148-
Pest.Locust, new() {
149-
Base = 160,
150-
Rare = [
151-
new PestRngDrop {
152-
Drops = 25600,
153-
Chance = 0.03
154-
}
155-
]
156-
}
157-
}, {
158-
Pest.Rat, new() {
159-
Base = 160,
160-
Rare = [
161-
new PestRngDrop {
162-
Drops = 25600,
163-
Chance = 0.01
164-
}
165-
]
166-
}
167-
}, {
168-
Pest.Mosquito, new() {
169-
Base = 160,
170-
Rare = [
171-
new PestRngDrop {
172-
Drops = 25600,
173-
Chance = 0.02
174-
}
175-
]
176-
}
177-
}, {
178-
Pest.Fly, new() {
179-
Base = 1296,
180-
Rare = [
181-
new PestRngDrop {
182-
Drops = 186624,
183-
Chance = 0.01
184-
}
185-
]
186-
}
187-
}
188-
};
72+
FarmingWeightConfig.Settings = serviceProvider.GetRequiredService<IOptions<ConfigFarmingWeightSettings>>().Value;
18973
}
19074
}

0 commit comments

Comments
 (0)