Skip to content

Commit 1982d9d

Browse files
Young Fir Forest
1 parent 2fc2e41 commit 1982d9d

4 files changed

Lines changed: 101 additions & 0 deletions

File tree

src/OpenRP.Framework/Features/BiomeGenerator/Enums/BiomeType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum BiomeType
1414
Farmland,
1515
Plains,
1616
FlintWhetstoneCountyMain,
17+
AngelPineMain,
1718
LosSantosMain,
1819
LosSantosPlains,
1920
SanFierroMain,

src/OpenRP.Framework/Features/BiomeGenerator/Extensions/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public static IServiceCollection AddBiomeGenerator(this IServiceCollection self)
5858
.AddSingleton<IBiomeObjectGenerator, SandJoshPlantGenerator>()
5959
.AddSingleton<IBiomeObjectGenerator, SingleSunflowerGenerator>()
6060
.AddSingleton<IBiomeObjectGenerator, SparseRedwoodTreeGenerator>()
61+
.AddSingleton<IBiomeObjectGenerator, YoungFirTreeGenerator>()
6162
.AddSingleton<BirchForestBiome>()
6263
.AddSingleton<ConiferousWoodlandBiome>()
6364
.AddSingleton<DeadElmForestBiome>()
@@ -91,6 +92,7 @@ public static IServiceCollection AddBiomeGenerator(this IServiceCollection self)
9192
.AddSingleton<SparseElmForestBiome>()
9293
.AddSingleton<SparseRedwoodForestBiome>()
9394
.AddSingleton<SunflowerBiome>()
95+
.AddSingleton<YoungFirForestBiome>()
9496
.AddSingleton<IBiomeObjectFactory, BiomeObjectFactory>();
9597
}
9698
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using OpenRP.Framework.Features.BiomeGenerator.Attributes;
2+
using OpenRP.Framework.Features.BiomeGenerator.Entities;
3+
using OpenRP.Framework.Features.BiomeGenerator.Enums;
4+
using OpenRP.Framework.Features.BiomeGenerator.Helpers;
5+
using SampSharp.Entities.SAMP;
6+
using System;
7+
using System.Collections.Concurrent;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Text;
11+
using System.Threading.Tasks;
12+
13+
namespace OpenRP.Framework.Features.BiomeGenerator.Services.Generators.Biomes
14+
{
15+
[Biome(59, "Young Fir Forest", BiomeType.AngelPineMain)]
16+
public class YoungFirForestBiome : IBiome
17+
{
18+
private readonly IBiomeObjectFactory _factory;
19+
private readonly WeightedRandom<string> _weightedRandom;
20+
private readonly Color _biomeOutputColor;
21+
22+
public YoungFirForestBiome(IBiomeObjectFactory factory)
23+
{
24+
_factory = factory;
25+
// Weights sum to 900 to preserve original probabilities exactly.
26+
_weightedRandom = new WeightedRandom<string>(new Dictionary<string, int>
27+
{
28+
{ "YoungFirTree", 18 },
29+
{ "Flower", 9 },
30+
{ "Grass", 44 },
31+
{ "ConiferousBush", 22 },
32+
{ "Nothing", 807 }
33+
});
34+
_biomeOutputColor = GetBiomeOutputColor();
35+
}
36+
37+
public ConcurrentBag<BiomeObject> Generate(Vector2 virtualPosition, Vector3 gamePosition, Vector3 gameRotation, Vector3 defaultRotation, Vector3 maxAngleRotation)
38+
{
39+
var assets = new ConcurrentBag<BiomeObject>();
40+
string selectedType = _weightedRandom.GetRandomItem();
41+
42+
if (selectedType != "Nothing")
43+
{
44+
// Create the object
45+
BiomeObject element = _factory.Generate(
46+
selectedType,
47+
virtualPosition,
48+
gamePosition,
49+
gameRotation,
50+
defaultRotation,
51+
maxAngleRotation,
52+
_biomeOutputColor
53+
);
54+
55+
assets.Add(element);
56+
}
57+
58+
return assets;
59+
}
60+
61+
public Color GetBiomeOutputColor() => new Color(0, 83, 0);
62+
}
63+
64+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using OpenRP.Framework.Features.BiomeGenerator.Entities;
2+
using SampSharp.Entities.SAMP;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace OpenRP.Framework.Features.BiomeGenerator.Services.Generators.Objects
10+
{
11+
public class YoungFirTreeGenerator : IBiomeObjectGenerator
12+
{
13+
public string ObjectType => "YoungFirTree";
14+
15+
public BiomeObject Generate(Vector2 virtualPosition, Vector3 gamePosition, Vector3 gameRotation, Vector3 defaultRotation, Vector3 maxAngleRotation, Color outputColor)
16+
{
17+
int[] obj_arr_trees = {
18+
881, 687
19+
};
20+
21+
int modelId = obj_arr_trees[Random.Shared.Next(obj_arr_trees.Length)];
22+
23+
BiomeObject treeObject = new BiomeObject(
24+
obj_arr_trees[Random.Shared.Next(obj_arr_trees.Length)],
25+
virtualPosition,
26+
gamePosition,
27+
gameRotation,
28+
outputColor
29+
);
30+
31+
return treeObject;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)