Skip to content

Commit

Permalink
Fixed exception thrown when mining Leviathans;
Browse files Browse the repository at this point in the history
Added veinmining capability for MineRock types (Leviathan and Glowing Metal)
  • Loading branch information
WiseHorror committed Sep 25, 2021
1 parent cf49025 commit d4b5565
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ What does 2 mean, you ask?

It's simple! A standard 2x2 floor piece has a length of 2, exactly like its name suggests.
# Changelog
## 1.2.3
## 1.2.4
- Fixed an exception that was thrown when mining Leviathans.
- Added veinmining support for Leviathans and Glowing Metal (Flametal Ore).
### 1.2.3
- Fixed a bug that allowed players to veinmine (and gain exp) without a pickaxe.
### 1.2.2
- Possible fix for ore drop quantities (Not sure why they weren't correct, as I don't change drop rates)
Expand Down
71 changes: 69 additions & 2 deletions VeinMine/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,72 @@ class Patches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(MineRock), "Damage")]
public static void MineRock_Damage_Prefix(MineRock __instance, HitData hit)
public static bool MineRock_Damage_Prefix(MineRock __instance, HitData hit)
{
hit.m_point = __instance.GetHitArea(__instance.GetAreaIndex(hit.m_hitCollider)).bounds.center;
if (Input.GetKey(VeinMine.veinMineKey.Value))
{
if (VeinMine.progressiveMode.Value)
{
float radius = VeinMine.progressiveMult.Value * (float)GetSkillLevel(Player.m_localPlayer.GetSkills(), Skills.SkillType.Pickaxes);
Vector3 firstHitPoint = hit.m_point;

foreach (var area in __instance.m_hitAreas)
{
if (GetDistanceFromPlayer(Player.GetClosestPlayer(hit.m_point, 5f).GetTransform().position, area.bounds.center) <= radius && area != null)
{
hit.m_point = area.transform.position;
hit.m_hitCollider = area;
if (hit.m_hitCollider == null)
{
ZLog.Log("Minerock hit has no collider");
return false;
}
int areaIndex = __instance.GetAreaIndex(hit.m_hitCollider);
if (areaIndex == -1)
{
//ZLog.Log("Invalid hit area on " + base.gameObject.name);
return false;
}
ZLog.Log("Hit mine rock area " + areaIndex);
__instance.m_nview.InvokeRPC("Hit", new object[]
{
hit,
areaIndex
});
hit.m_point = firstHitPoint;
}
}
}
else
{
foreach (var area in __instance.m_hitAreas)
{
string hpAreaName = "Health" + __instance.GetAreaIndex(area).ToString();
hit.m_damage.m_pickaxe = __instance.m_nview.GetZDO().GetFloat(hpAreaName, __instance.m_health);
hit.m_point = __instance.GetHitArea(__instance.GetAreaIndex(area)).bounds.center;
hit.m_hitCollider = area;
if (hit.m_hitCollider == null)
{
ZLog.Log("Minerock hit has no collider");
return false;
}
int areaIndex = __instance.GetAreaIndex(hit.m_hitCollider);
if (areaIndex == -1)
{
//ZLog.Log("Invalid hit area on " + base.gameObject.name);
return false;
}
ZLog.Log("Hit mine rock area " + areaIndex);
__instance.m_nview.InvokeRPC("Hit", new object[]
{
hit,
areaIndex
});
}
}
return false;
}
return true;
}

[HarmonyPrefix]
Expand Down Expand Up @@ -221,6 +284,10 @@ public static float GetSkillLevel(Skills playerSkills, Skills.SkillType skillTyp

return 1;
}
public static float GetDistanceFromPlayer(Vector3 playerPos, Vector3 colliderPos)
{
return Vector3.Distance(playerPos, colliderPos);
}

public static HitData SpreadDamage(HitData hit)
{
Expand Down
4 changes: 2 additions & 2 deletions VeinMine/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.3.0")]
[assembly: AssemblyFileVersion("1.2.3.0")]
[assembly: AssemblyVersion("1.2.4.0")]
[assembly: AssemblyFileVersion("1.2.4.0")]
2 changes: 1 addition & 1 deletion VeinMine/VeinMine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class VeinMine : BaseUnityPlugin
{
private const string MOD_ID = "com.wisehorror.Veinmine";
private const string MOD_NAME = "Veinmine";
private const string VERSION = "1.2.3";
private const string VERSION = "1.2.4";

public static ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource("Veinmine");

Expand Down

0 comments on commit d4b5565

Please sign in to comment.