Skip to content

Commit

Permalink
Dredge Harvest Zone
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Aug 16, 2024
1 parent 9e86004 commit ef868dc
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"y": 0.0,
"z": -354.0
},
"colliderType": "SPHERE",
"radius": 50,
"harvestableItems": [ "exampleitems.rainbowfiddlercrab" ],
"day": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"location": {
"x": 0,
"y": 0,
"z": -300
},
"colliderType": "BOX",
"size": {
"x": 3000,
"y": 500,
"z": 3000
},
"harvestableItems": [ "exampleitems.diamond" ],
"day": true,
"night": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"y": 0.0,
"z": -354.0
},
"colliderType": "SPHERE",
"radius": 50,
"harvestableItems": [ "exampleitems.mccod" ],
"day": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"location": {
"x": 0,
"y": 0,
"z": -300
},
"colliderType": "BOX",
"size": {
"x": 3000,
"y": 500,
"z": 3000
},
"harvestableItems": [ "exampleitems.musicdisc" ],
"day": false,
"night": true
}
10 changes: 9 additions & 1 deletion Winch/Serialization/HarvestZone/CustomHarvestZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ namespace Winch.Serialization.HarvestZone;

public class CustomHarvestZone : SerializedScriptableObject
{
public Vector3 location = Vector3.zero;
public Vector3 location = new Vector3(0, 0, -300);
public ColliderType colliderType = ColliderType.SPHERE;
public float radius = 200;
public Vector3 size = new Vector3(3000, 500, 3000);
public List<string> harvestableItems = new List<string>();
public bool day = true;
public bool night = true;

public List<HarvestableItemData> HarvestableItems => ItemUtil.TryGetHarvestables(harvestableItems);

public enum ColliderType
{
SPHERE,
BOX
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ public class CustomHarvestZoneConverter : DredgeTypeConverter<CustomHarvestZone>
{
private readonly Dictionary<string, FieldDefinition> _definitions = new()
{
{ "location", new( Vector3.zero, o=> DredgeTypeHelpers.ParseVector3(o)) },
{ "location", new( new Vector3(0, 0, -300), o=> DredgeTypeHelpers.ParseVector3(o)) },
{ "colliderType", new( CustomHarvestZone.ColliderType.SPHERE, o=> DredgeTypeHelpers.GetEnumValue<CustomHarvestZone.ColliderType>(o)) },
{ "radius", new( 200, o=> float.Parse(o.ToString())) },
{ "size", new( new Vector3(3000, 500, 3000), o=> DredgeTypeHelpers.ParseVector3(o)) },
{ "harvestableItems", new( new List<string>(), o => DredgeTypeHelpers.ParseStringList((JArray)o)) },
{ "day", new( true, o => bool.Parse(o.ToString())) },
{ "night", new( true, o => bool.Parse(o.ToString())) },
Expand Down
18 changes: 14 additions & 4 deletions Winch/Util/HarvestZoneUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ internal static GameObject CreateGameObjectFromCustomHarvestZone(CustomHarvestZo
harvestZoneObj.transform.SetParent(GameObject.Find("HarvestZones/FullZones").transform);
harvestZoneObj.transform.position = customHarvestZone.location;

var sphereCollider = harvestZoneObj.AddComponent<SphereCollider>();
sphereCollider.radius = customHarvestZone.radius;
sphereCollider.enabled = true;
sphereCollider.contactOffset = 0.01f;
if (customHarvestZone.colliderType == CustomHarvestZone.ColliderType.SPHERE)
{
var sphereCollider = harvestZoneObj.AddComponent<SphereCollider>();
sphereCollider.radius = customHarvestZone.radius;
sphereCollider.enabled = true;
sphereCollider.contactOffset = 0.01f;
}
else if (customHarvestZone.colliderType == CustomHarvestZone.ColliderType.BOX)
{
var boxCollider = harvestZoneObj.AddComponent<BoxCollider>();
boxCollider.size = customHarvestZone.size;
boxCollider.enabled = true;
boxCollider.contactOffset = 0.01f;
}

var harvestZone = harvestZoneObj.AddComponent<HarvestZone>();
harvestZone.harvestableItems = customHarvestZone.HarvestableItems.ToArray();
Expand Down

0 comments on commit ef868dc

Please sign in to comment.