minor bugfix and pad support
This commit is contained in:
parent
ce671e7124
commit
6e87be3c77
21 changed files with 574 additions and 85 deletions
|
|
@ -103,6 +103,31 @@ namespace RacesOfValheim
|
|||
/// with every instance the table raises.</summary>
|
||||
public ButlerFamily m_family = ButlerFamily.Forge;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this one stands and fights instead of walking home when trouble comes. Off for the
|
||||
/// Bone Servants, which are pacifists by decision; on for the Sverm's Seeker Workers, which
|
||||
/// keep the forge AND defend the nest. See <see cref="HandsToVanilla"/>.
|
||||
/// </summary>
|
||||
public bool m_fightsBack = false;
|
||||
|
||||
/// <summary>
|
||||
/// How close to the anchor counts as home, and how far past the configured radius it works.
|
||||
/// 2.5 and 0 for a table. A Sverm nest is metres of collider that grows with its stage, so
|
||||
/// SvermWorkerBehaviour sets both to the nest's measured edge - otherwise an idle worker would
|
||||
/// spend its life walking into the trunk, and the work circle would be mostly nest.
|
||||
/// </summary>
|
||||
public float m_homeDistance = 2.5f;
|
||||
public float m_radiusBonus = 0f;
|
||||
|
||||
/// <summary>For a servant that fights back: how close an enemy has to be to stop the work, how
|
||||
/// often that is asked, and how long the fight holds after the last sign of one.</summary>
|
||||
private const float FightRange = 12f;
|
||||
private const float FightScanInterval = 1f;
|
||||
private const float FightLinger = 5f;
|
||||
|
||||
private float m_nextFightScan;
|
||||
private float m_fightUntil;
|
||||
|
||||
private ZNetView m_nview;
|
||||
private Character m_character;
|
||||
private MonsterAI m_ai;
|
||||
|
|
@ -207,13 +232,58 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
/// <summary>Hit by something: stop working and walk home. It never fights back - there is
|
||||
/// nothing in this class that could.</summary>
|
||||
/// nothing in this class that could. A servant that fights back ignores this: vanilla already
|
||||
/// holds the attacker as its target (MonsterAI.OnDamaged calls SetTarget, read off the IL), and
|
||||
/// <see cref="HandsToVanilla"/> gives it the tick on the next frame.</summary>
|
||||
public void NoteDamage()
|
||||
{
|
||||
if (m_fightsBack) return;
|
||||
|
||||
m_fleeUntil = Time.time + FleeSeconds;
|
||||
m_job = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True while vanilla's MonsterAI should have the tick instead of the work - only ever for a
|
||||
/// servant that fights back, and only on the client that runs it.
|
||||
///
|
||||
/// VANILLA DOES THE FIGHTING, this only decides when. Two things start a fight: a target the
|
||||
/// MonsterAI already holds - which covers being hit, see NoteDamage - and an enemy inside
|
||||
/// FightRange, found with BaseAI.FindClosestEnemy. That one is a static sweep of distance and
|
||||
/// IsEnemy with no line of sight (IL), which is why the range is short. Either holds the fight
|
||||
/// for FightLinger seconds, so the worker does not flicker between swinging and walking to the
|
||||
/// chest on alternate ticks.
|
||||
///
|
||||
/// The job is dropped, not the payload: whatever it was carrying stays in the ZDO, and the
|
||||
/// first plan after the fight carries it on to where it was going.
|
||||
/// </summary>
|
||||
public bool HandsToVanilla()
|
||||
{
|
||||
if (!m_fightsBack || m_ai == null || m_character == null || m_character.IsDead()) return false;
|
||||
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return false;
|
||||
|
||||
Character target = m_ai.GetTargetCreature();
|
||||
if (target != null && !target.IsDead())
|
||||
{
|
||||
m_fightUntil = Time.time + FightLinger;
|
||||
}
|
||||
else if (Time.time >= m_nextFightScan)
|
||||
{
|
||||
m_nextFightScan = Time.time + FightScanInterval;
|
||||
if (BaseAI.FindClosestEnemy(m_character, transform.position, FightRange) != null)
|
||||
{
|
||||
m_fightUntil = Time.time + FightLinger;
|
||||
}
|
||||
}
|
||||
|
||||
if (Time.time >= m_fightUntil) return false;
|
||||
|
||||
m_job = null;
|
||||
m_nextPlan = 0f; // the fight moved it; plan afresh the moment it hands back
|
||||
SetStatus("Fighting.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ================================================================ the tick
|
||||
|
||||
/// <summary>Everything. Returns what MonsterAI.UpdateAI would have returned.</summary>
|
||||
|
|
@ -327,7 +397,7 @@ namespace RacesOfValheim
|
|||
List<Piece> pieces = AllPiecesField != null ? AllPiecesField.GetValue(null) as List<Piece> : null;
|
||||
if (pieces == null) return;
|
||||
|
||||
float radius = ButlerConfig.WorkRadius.Value;
|
||||
float radius = ButlerConfig.WorkRadius.Value + m_radiusBonus;
|
||||
float radiusSq = radius * radius;
|
||||
|
||||
for (int i = 0; i < pieces.Count; i++)
|
||||
|
|
@ -923,7 +993,7 @@ namespace RacesOfValheim
|
|||
return;
|
||||
}
|
||||
|
||||
MoveToPoint(dt, anchor.Value, 2.5f, false);
|
||||
MoveToPoint(dt, anchor.Value, m_homeDistance, false);
|
||||
}
|
||||
|
||||
// ================================================================ the ground
|
||||
|
|
@ -1356,6 +1426,10 @@ namespace RacesOfValheim
|
|||
BoneServantAI servant = __instance.GetComponent<BoneServantAI>();
|
||||
if (servant == null) return true;
|
||||
|
||||
// The one way back into vanilla: a servant that fights back hands over the whole tick for
|
||||
// as long as there is a fight. Always false for the Bone Servants themselves.
|
||||
if (servant.HandsToVanilla()) return true;
|
||||
|
||||
__result = servant.Tick(__0);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,11 @@ namespace RacesOfValheim
|
|||
/// "RPC_" prefix in this build - "RPC_AddOre", not "AddOre". A wrong name here is a silent no-op,
|
||||
/// which is exactly the class of bug that takes an evening to find, so the four names below were
|
||||
/// read out of each Awake() rather than remembered.
|
||||
///
|
||||
/// A wrong ARGUMENT LIST is not silent: Valheim 1.0 added a trailing "bool cheated" to every
|
||||
/// add-item RPC (and the Fermenter's now takes the prefab's stable hash, not its name), and the
|
||||
/// old calls threw EndOfStreamException on the receiving end, every tick. The servant's goods
|
||||
/// are real, so cheated is always false.
|
||||
/// </summary>
|
||||
public abstract class ButlerStation
|
||||
{
|
||||
|
|
@ -199,8 +204,9 @@ namespace RacesOfValheim
|
|||
public static readonly MethodInfo CookFireLit = AccessTools.Method(typeof(CookingStation), "IsFireLit");
|
||||
|
||||
public static readonly MethodInfo FermenterStatus = AccessTools.Method(typeof(Fermenter), "GetStatus");
|
||||
// 1.0 dropped the string overload: the Fermenter matches on GetStableHashCode of the name.
|
||||
public static readonly MethodInfo FermenterAllowed =
|
||||
AccessTools.Method(typeof(Fermenter), "IsItemAllowed", new[] { typeof(string) });
|
||||
AccessTools.Method(typeof(Fermenter), "IsItemAllowed", new[] { typeof(int) });
|
||||
|
||||
// CookingStation.Status and Fermenter.Status are private nested enums: they cannot be named
|
||||
// in source, so they travel as ints. Values read from the assembly, not assumed.
|
||||
|
|
@ -270,7 +276,7 @@ namespace RacesOfValheim
|
|||
public override void Add(string prefabName)
|
||||
{
|
||||
Claim();
|
||||
Nview.InvokeRPC("RPC_AddOre", prefabName);
|
||||
Nview.InvokeRPC("RPC_AddOre", prefabName, false);
|
||||
}
|
||||
|
||||
public override bool HasWork { get { return Queued > 0; } }
|
||||
|
|
@ -318,8 +324,9 @@ namespace RacesOfValheim
|
|||
get { return m_cooking.m_slots != null ? m_cooking.m_slots.Length : 0; }
|
||||
}
|
||||
|
||||
/// <summary>GetSlot hands back three values through out parameters, one of which is a
|
||||
/// private enum. Through reflection that means an args array and an int.</summary>
|
||||
/// <summary>GetSlot hands back four values through out parameters, one of which is a
|
||||
/// private enum. Through reflection that means an args array and an int. The fourth, a
|
||||
/// bool "cheated", arrived with 1.0; it is ignored, but the array must have room for it.</summary>
|
||||
private bool ReadSlot(int index, out string name, out float cooked, out int status)
|
||||
{
|
||||
name = null;
|
||||
|
|
@ -328,7 +335,7 @@ namespace RacesOfValheim
|
|||
|
||||
if (Vanilla.CookGetSlot == null) return false;
|
||||
|
||||
object[] args = new object[] { index, null, null, null };
|
||||
object[] args = new object[] { index, null, null, null, null };
|
||||
Vanilla.CookGetSlot.Invoke(m_cooking, args);
|
||||
|
||||
name = args[1] as string;
|
||||
|
|
@ -367,7 +374,7 @@ namespace RacesOfValheim
|
|||
public override void Add(string prefabName)
|
||||
{
|
||||
Claim();
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName);
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName, false);
|
||||
}
|
||||
|
||||
public override bool HasWork { get { return !Vanilla.Call(Vanilla.CookEmpty, m_cooking, true); } }
|
||||
|
|
@ -486,13 +493,14 @@ namespace RacesOfValheim
|
|||
|
||||
public override bool Accepts(string prefabName)
|
||||
{
|
||||
return Vanilla.Allowed(Vanilla.FermenterAllowed, m_fermenter, prefabName);
|
||||
if (Vanilla.FermenterAllowed == null || string.IsNullOrEmpty(prefabName)) return false;
|
||||
return (bool)Vanilla.FermenterAllowed.Invoke(m_fermenter, new object[] { prefabName.GetStableHashCode() });
|
||||
}
|
||||
|
||||
public override void Add(string prefabName)
|
||||
{
|
||||
Claim();
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName);
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName.GetStableHashCode(), false);
|
||||
}
|
||||
|
||||
public override bool HasWork { get { return Status != Vanilla.FermentEmpty; } }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue