Skip to content

Commit

Permalink
Feat/ladder and minor tweaks (#146)
Browse files Browse the repository at this point in the history
* Remove experimental force sync logic which did not work

* Stabilize ladders, remove tar dumb bugs...no special swim heights inside the ship due to this

* use placepiece name directly, add a todo for tryPlacePiece where we might need to patch

* Fix flying again, works well on forceSyncedRigidbody with full climbing speed

* make the ballast guarding logic less jumpy
  • Loading branch information
zolantris authored Nov 10, 2024
1 parent 8bfbaa5 commit abbf933
Show file tree
Hide file tree
Showing 19 changed files with 581 additions and 318 deletions.
2 changes: 1 addition & 1 deletion src/ValheimRAFT/ValheimRAFT.Patches/Character_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IEnumerable<CodeInstruction> Character_Patch_ApplyGroundForce(
public static void Character_IsInWater(Character __instance,
ref bool __result)
{
var vpc = __instance.transform.root.GetComponent<VehiclePiecesController>();
var vpc = WaterZoneUtils.IsOnboard(__instance);
if (vpc) __result = false;
// var isOnboard = WaterZoneUtils.IsOnboard(__instance);
// if (isOnboard) __result = false;
Expand Down
58 changes: 38 additions & 20 deletions src/ValheimRAFT/ValheimRAFT.Patches/PlanBuild_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class PlanBuild_Patch
{
[HarmonyPatch(typeof(PlanPiece), "CalculateSupported")]
[HarmonyPrefix]
private static bool PlanPiece_CalculateSupported_Prefix(PlanPiece __instance, ref bool __result)
private static bool PlanPiece_CalculateSupported_Prefix(PlanPiece __instance,
ref bool __result)
{
if (__instance.GetComponentInParent<VehiclePiecesController>())
{
__result = true;
return false;
}


if (__instance.GetComponentInParent<MoveableBaseRootComponent>())
{
__result = true;
Expand All @@ -37,18 +37,21 @@ private static bool PlanPiece_CalculateSupported_Prefix(PlanPiece __instance, re

[HarmonyPatch(typeof(PlanPiece), "OnPieceReplaced")]
[HarmonyPrefix]
private static void PlanPiece_OnPieceReplaced_Postfix(GameObject originatingPiece,
private static void PlanPiece_OnPieceReplaced_Postfix(
GameObject originatingPiece,
GameObject placedPiece)
{
var baseVehicle = originatingPiece.GetComponentInParent<VehiclePiecesController>();
var baseVehicle =
originatingPiece.GetComponentInParent<VehiclePiecesController>();

if (baseVehicle)
{
baseVehicle.AddNewPiece(placedPiece.GetComponent<Piece>());
return;
}

var moveableBaseRoot = originatingPiece.GetComponentInParent<MoveableBaseRootComponent>();
var moveableBaseRoot =
originatingPiece.GetComponentInParent<MoveableBaseRootComponent>();
if (moveableBaseRoot)
{
moveableBaseRoot.AddNewPiece(placedPiece.GetComponent<Piece>());
Expand All @@ -57,7 +60,8 @@ private static void PlanPiece_OnPieceReplaced_Postfix(GameObject originatingPiec

[HarmonyPatch(typeof(PlacementComponent), "OnPiecePlaced")]
[HarmonyPrefix]
private static void BlueprintManager_OnPiecePlaced_Postfix(GameObject placedPiece)
private static void BlueprintManager_OnPiecePlaced_Postfix(
GameObject placedPiece)
{
Player_Patch.PlacedPiece(placedPiece);
// ValheimRAFT_Patch.PlacedPiece(Player.m_localPlayer, placedPiece);
Expand All @@ -66,7 +70,8 @@ private static void BlueprintManager_OnPiecePlaced_Postfix(GameObject placedPiec

[HarmonyPatch(typeof(Blueprint), "Capture")]
[HarmonyPrefix]
public static bool Capture(Blueprint __instance, ref bool __result, Selection selection,
public static bool Capture(Blueprint __instance, ref bool __result,
Selection selection,
bool captureCurrentSnapPoints = false, bool keepMarkers = false)
{
Logger.LogDebug("Using ValheimRAFT patch for: PlanBuild.Blueprint.Capture");
Expand All @@ -80,7 +85,8 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
>();
foreach (ZDOID item2 in selection)
{
GameObject gameObject = BlueprintManager.GetGameObject(item2, required: true);
GameObject gameObject =
BlueprintManager.GetGameObject(item2, required: true);
Logger.LogDebug($"GameObject {gameObject.name}");
if (gameObject.name.StartsWith("piece_bpsnappoint"))
{
Expand Down Expand Up @@ -137,7 +143,8 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
Piece component4 = gameObject.GetComponent<Piece>();
if (!BlueprintManager.CanCapture(component4))
{
Jotunn.Logger.LogWarning($"Ignoring piece {component4}, not able to make blueprint");
Jotunn.Logger.LogWarning(
$"Ignoring piece {component4}, not able to make blueprint");
continue;
}

Expand Down Expand Up @@ -190,7 +197,8 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
}

IOrderedEnumerable<Piece> orderedEnumerable = from x in list
orderby x.transform.position.y, x.transform.position.x, x.transform.position.z
orderby x.transform.position.y, x.transform.position.x, x.transform
.position.z
select x;
int num5 = orderedEnumerable.Count();
if (__instance.PieceEntries == null)
Expand All @@ -199,16 +207,19 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
}
else if (__instance.PieceEntries.Length != 0)
{
Array.Clear(__instance.PieceEntries, 0, __instance.PieceEntries.Length - 1);
Array.Clear(__instance.PieceEntries, 0,
__instance.PieceEntries.Length - 1);
Array.Resize(ref __instance.PieceEntries, num5);
}

uint num6 = 0u;
foreach (Piece item4 in orderedEnumerable)
{
Vector3 pos;
var shipBase = item4.m_nview.GetComponentInParent<MoveableBaseRootComponent>();
var vehicleBase = item4.m_nview.GetComponentInParent<VehiclePiecesController>();
var shipBase =
item4.m_nview.GetComponentInParent<MoveableBaseRootComponent>();
var vehicleBase =
item4.m_nview.GetComponentInParent<VehiclePiecesController>();
if (shipBase)
{
Logger.LogDebug(
Expand Down Expand Up @@ -257,10 +268,13 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
}

ItemStand component6 = item4.GetComponent<ItemStand>();
if (component6 != null && component6.HaveAttachment() && (bool)component6.m_nview)
if (component6 != null && component6.HaveAttachment() &&
(bool)component6.m_nview)
{
text = string.Format("{0}:{1}:{2}", component6.m_nview.m_zdo.GetString("item"),
component6.m_nview.m_zdo.GetInt("variant"), component6.m_nview.m_zdo.GetInt("quality"));
text = string.Format("{0}:{1}:{2}",
component6.m_nview.m_zdo.GetString("item"),
component6.m_nview.m_zdo.GetInt("variant"),
component6.m_nview.m_zdo.GetInt("quality"));
}

ArmorStand component7 = item4.GetComponent<ArmorStand>();
Expand All @@ -283,7 +297,8 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
PrivateArea component9 = item4.GetComponent<PrivateArea>();
if (component9 != null && (bool)component9.m_nview)
{
text = string.Format("{0}", component9.m_nview.m_zdo.GetBool("enabled"));
text = string.Format("{0}",
component9.m_nview.m_zdo.GetBool("enabled"));
}

Container component10 = item4.GetComponent<Container>();
Expand All @@ -297,7 +312,8 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
ZNetView component11 = item4.gameObject.GetComponent<ZNetView>();
if ((object)component11 != null && component11.m_zdo != null)
{
GameObject prefab = ZNetScene.instance.GetPrefab(component11.m_zdo.m_prefab);
GameObject prefab =
ZNetScene.instance.GetPrefab(component11.m_zdo.m_prefab);
if ((object)prefab != null)
{
text2 = prefab.name;
Expand All @@ -309,7 +325,8 @@ public static bool Capture(Blueprint __instance, ref bool __result, Selection se
text2 = text2.Replace("_planned", null);
}

__instance.PieceEntries[num6++] = new PieceEntry(text2, item4.m_category.ToString(), pos,
__instance.PieceEntries[num6++] = new PieceEntry(text2,
item4.m_category.ToString(), pos,
rotation, text, localScale);
}

Expand Down Expand Up @@ -347,7 +364,8 @@ where x.Count() == 1
foreach (TerrainModEntry item5 in list3)
{
__instance.TerrainMods[num7++] = new TerrainModEntry(item5.shape,
item5.GetPosition() - vector, item5.radius, item5.rotation, item5.smooth, item5.paint);
item5.GetPosition() - vector, item5.radius, item5.rotation,
item5.smooth, item5.paint);
}

__result = true;
Expand Down
7 changes: 6 additions & 1 deletion src/ValheimRAFT/ValheimRAFT.Patches/Player_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ namespace ValheimRAFT.Patches;

public class Player_Patch
{
/// <summary>
/// TODO may need to add a TryPlacePiece patch to override if blocked by water on boat.
/// </summary>
/// <param name="instructions"></param>
/// <returns></returns>
[HarmonyTranspiler]
[HarmonyPatch(typeof(Player), "PlacePiece")]
[HarmonyPatch(typeof(Player), nameof(Player.PlacePiece))]
private static IEnumerable<CodeInstruction> PlacePieceTranspiler(
IEnumerable<CodeInstruction> instructions)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
_Metallic ("Metallic", Range(0, 1)) = 0
_Cutoff ("Alpha Cutoff", Range(0, 1)) = 0.5
_BumpScale ("Normal scale", Float) = 1
[MaterialToggle] _TwoSidedNormals ("Twosided normals", Float) = 0
[MaterialToggle] _TwoSidedNormals ("Twosided normals", Float) = 1
_SphereNormals ("Spherical Normal", Range(0, 1)) = 0
_SphereOffset ("Spherical offset", Float) = 0
_EmissiveTex ("Emissive (RGB)", 2D) = "white" {}
Expand Down
10 changes: 8 additions & 2 deletions src/ValheimRAFT/ValheimRAFT/RopeLadderComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ private void UpdateSteps()
return;
}

if (Mathf.Abs(transform.rotation.eulerAngles.x) > 40 ||
Mathf.Abs(transform.rotation.eulerAngles.z) > 40)
{
return;
}

if (rayMask == 0)
{
rayMask = LayerMask.GetMask("Default", "static_solid", "Default_small",
Expand Down Expand Up @@ -504,9 +510,9 @@ private float ClampOffset(float offset)
public void OnNearTopExitForwards(Player player)
{
var deltaY = player.transform.position.y - m_exitPoint.position.y;
if (deltaY < 1f)
if (Mathf.Abs(deltaY) < 1f)
{
player.transform.position += GetExitOffset();
player.transform.position = GetExitOffset();
}
}

Expand Down
Loading

0 comments on commit abbf933

Please sign in to comment.