Rework interaction layer onto ZenProxyFramework proxy API

Furniture (sink/fridge/lekarnicka/vending) are house proxies, not entities, so
actions are now driven by ZenProxyFramework: actions target proxies by name
(GetZenProxyNameTarget), the proxy world position is synced to the server via
ActionData, repair spawns an invisible ZenProxySinkTest marker (presence =
repaired), and gather-water checks for it. Registry is keyed by proxy name;
loot tables / cooldowns / settings JSON kept.

NOTE: superseded approach - ZenProxyFramework does not compile on DayZ 1.29
(HouseType type-name collision). Next: a self-contained @YAProxy framework
(based on ZenProxyFramework + ShowMeInfoV2's geometry-LOD proxy scan) that
YAInteraction will depend on instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
smthspec 2026-06-19 09:07:02 +03:00
parent 1f63096cdb
commit e4cb0e4009
9 changed files with 309 additions and 351 deletions

View file

@ -8,7 +8,8 @@ class CfgPatches
requiredAddons[] = requiredAddons[] =
{ {
"DZ_Data", "DZ_Data",
"DZ_Scripts" "DZ_Scripts",
"ZenProxyFramework" // dependency: ensures ZPF loads before us (proxy API + ZenProxySinkTest)
}; };
}; };
}; };

View file

@ -1,15 +1,12 @@
// ============================================================================ // ============================================================================
// ActionYAGatherWater // ActionYAGatherWater
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Stage 2 of the sink. Only usable once the sink has been repaired (state in // Stage 2 of the sink. Attached to the liquid container in the player's hands
// YAInteractionManager). Fills a liquid container in the player's hands (or // (Bottle_Base). Only usable once the sink is repaired (a ZenProxySinkTest
// the first fillable container in their inventory) with a random amount of // entity exists at the proxy world position). Fills the held container with a
// clean water. // random amount of water from config, gated by a per-player cooldown.
// //
// Cooldown model (v1): per-player, keyed by player UID, in a static map. // Registered on Bottle_Base (see YAInteractionInit) - item-based.
// Resets on server restart.
// TODO (v2): swap the static map for CF persistence in IsOnCooldown()/
// StampCooldown().
// ============================================================================ // ============================================================================
class ActionYAGatherWaterCB : ActionContinuousBaseCB class ActionYAGatherWaterCB : ActionContinuousBaseCB
@ -22,49 +19,54 @@ class ActionYAGatherWaterCB : ActionContinuousBaseCB
class ActionYAGatherWater : ActionContinuousBase class ActionYAGatherWater : ActionContinuousBase
{ {
// playerUID -> server time (ms) when the cooldown expires.
protected static ref map<string, int> m_PlayerCooldowns = new map<string, int>();
void ActionYAGatherWater() void ActionYAGatherWater()
{ {
m_CallbackClass = ActionYAGatherWaterCB; m_CallbackClass = ActionYAGatherWaterCB;
m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_FILLBOTTLEWELL; // reuse "fill from fixture" anim m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_FILLBOTTLEWELL;
m_FullBody = true; m_FullBody = true;
m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH; m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
m_Text = "Gather Water";
} }
override typename GetInputType() override string GetText()
{ {
return ContinuousInteractActionInput; return "Gather Water";
} }
override void CreateConditionComponents() override bool HasZenProxyTarget()
{
m_ConditionItem = new CCINone();
m_ConditionTarget = new CCTNonRuined(UAMaxDistances.DEFAULT);
}
override bool HasTarget()
{ {
return true; return true;
} }
// Sink interactable + repaired + player carries a fillable container. override string GetZenProxyNameTarget()
{
return YAInteractionManager.GetRepairWaterProxyNames();
}
override void CreateConditionComponents()
{
m_ConditionItem = new CCINonRuined(); // the container in hands
m_ConditionTarget = new CCTCursorParent(UAMaxDistances.SMALL);
}
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item) override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
{ {
Object targetObject = target.GetObject(); if (!CanFill(item))
if (!targetObject)
return false; return false;
YAInteractableEntry entry = YAInteractionManager.GetEntry(targetObject.GetType()); if (!IsTargetingZenActionProxy(player, target, item))
if (!entry || entry.ActionType != YAInteractionConfig.ACTION_REPAIR_WATER)
return false; return false;
if (!YAInteractionManager.IsRepaired(targetObject.GetNetworkIDString())) // Client-only: only available when the sink is repaired (entity exists).
return false; if (GetGame().IsClient())
{
vector ls, ws;
string houseType;
GetZenActionProxyTargetEx(player, target, item, ls, ws, houseType);
if (!GetProxyObject(ws, YAInteractionConfig.SINK_PROXY_ENTITY))
return false;
}
return FindFillableContainer(player) != null; return true;
} }
override bool IsLockTargetOnUse() override bool IsLockTargetOnUse()
@ -75,113 +77,53 @@ class ActionYAGatherWater : ActionContinuousBase
override void OnFinishProgressServer(ActionData action_data) override void OnFinishProgressServer(ActionData action_data)
{ {
PlayerBase player = action_data.m_Player; PlayerBase player = action_data.m_Player;
Object targetObject = action_data.m_Target.GetObject(); if (!player || !player.GetIdentity())
if (!player || !player.GetIdentity() || !targetObject)
return; return;
YAInteractableEntry entry = YAInteractionManager.GetEntry(targetObject.GetType()); vector proxyWS = GetZenProxyTargetWS(action_data);
if (!entry)
return;
// Defensive re-check (repair state could change mid-progress). // Defensive: sink must be repaired.
if (!YAInteractionManager.IsRepaired(targetObject.GetNetworkIDString())) if (!GetProxyObject(proxyWS, YAInteractionConfig.SINK_PROXY_ENTITY))
{ {
player.MessageStatus("The sink needs to be repaired first."); player.MessageStatus("The sink needs to be repaired first.");
return; return;
} }
string uid = player.GetIdentity().GetId(); string uid = player.GetIdentity().GetId();
if (YAInteractionManager.IsWaterOnCooldown(uid))
// --- Per-player cooldown gate ---
if (IsOnCooldown(uid))
{ {
int remaining = GetCooldownRemaining(uid); int remaining = YAInteractionManager.GetWaterCooldownRemaining(uid);
Print(string.Format("[YAInteraction] GatherWater on cooldown (%1s) for %2", remaining, uid));
player.MessageStatus(string.Format("You need to wait before gathering water again. (%1s)", remaining)); player.MessageStatus(string.Format("You need to wait before gathering water again. (%1s)", remaining));
return; return;
} }
ItemBase container = FindFillableContainer(player); ItemBase container = ItemBase.Cast(action_data.m_MainItem);
if (!container) if (!CanFill(container))
{ {
player.MessageStatus("You have nothing to fill with water."); player.MessageStatus("This container can't hold any more water.");
return; return;
} }
float amount = Math.RandomFloatInclusive(YAInteractionConfigLoader.Settings.WaterAmountMin, YAInteractionConfigLoader.Settings.WaterAmountMax); float amount = Math.RandomFloatInclusive(YAInteractionConfigLoader.Settings.WaterAmountMin, YAInteractionConfigLoader.Settings.WaterAmountMax);
Liquid.FillContainer(container, YAInteractionConfig.WATER_LIQUID_TYPE, amount); Liquid.FillContainer(container, YAInteractionConfig.WATER_LIQUID_TYPE, amount);
StampCooldown(uid, entry.CooldownSec); // Cooldown comes from the sink's registry entry.
YAInteractableEntry entry = YAInteractionManager.GetEntryByProxyName(GetZenProxyTargetType(action_data));
float cd = YAInteractionConfigLoader.Settings.SinkPlayerCooldownSec;
if (entry && entry.CooldownSec > 0)
cd = entry.CooldownSec;
YAInteractionManager.StampWaterCooldown(uid, cd);
Print(string.Format("[YAInteraction] %1 gathered %2 water into '%3'", uid, amount, container.GetType())); Print(string.Format("[YAInteraction] %1 gathered %2 water into '%3'", uid, amount, container.GetType()));
player.MessageStatus(string.Format("You filled %1 with %2 ml of water.", container.GetDisplayName(), Math.Round(amount))); player.MessageStatus(string.Format("You filled %1 with %2 ml of water.", container.GetDisplayName(), Math.Round(amount)));
} }
// ------------------------------------------------------------------
// Container discovery: hands first, then inventory.
// ------------------------------------------------------------------
protected ItemBase FindFillableContainer(PlayerBase player)
{
if (!player)
return null;
ItemBase inHands = ItemBase.Cast(player.GetItemInHands());
if (CanFill(inHands))
return inHands;
array<EntityAI> items = new array<EntityAI>();
player.GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER, items);
foreach (EntityAI ent : items)
{
ItemBase candidate = ItemBase.Cast(ent);
if (CanFill(candidate))
return candidate;
}
return null;
}
protected bool CanFill(ItemBase item) protected bool CanFill(ItemBase item)
{ {
if (!item || !item.IsLiquidContainer()) if (!item || !item.IsLiquidContainer())
return false; return false;
if (item.GetQuantity() >= item.GetQuantityMax()) if (item.GetQuantity() >= item.GetQuantityMax())
return false; // already full return false;
return Liquid.CanFillContainer(item, YAInteractionConfig.WATER_LIQUID_TYPE); return Liquid.CanFillContainer(item, YAInteractionConfig.WATER_LIQUID_TYPE);
} }
// ------------------------------------------------------------------
// Cooldown helpers (persistence-aware surface area).
// ------------------------------------------------------------------
// TODO (v2): read last-gather time from CF storage instead of the static map.
protected static bool IsOnCooldown(string uid)
{
int expiry;
if (!m_PlayerCooldowns.Find(uid, expiry))
return false;
return GetGame().GetTime() < expiry;
}
protected static int GetCooldownRemaining(string uid)
{
int expiry;
if (!m_PlayerCooldowns.Find(uid, expiry))
return 0;
int remainingMs = expiry - GetGame().GetTime();
if (remainingMs < 0)
remainingMs = 0;
return remainingMs / 1000;
}
// TODO (v2): persist this stamp via CF so it survives server restarts.
protected static void StampCooldown(string uid, float cooldownSec)
{
int expiry = GetGame().GetTime() + (int)(cooldownSec * 1000);
m_PlayerCooldowns.Set(uid, expiry);
Print(string.Format("[YAInteraction] Water cooldown stamped for %1 (%2s)", uid, cooldownSec));
}
} }

View file

@ -1,13 +1,13 @@
// ============================================================================ // ============================================================================
// ActionYARepairSink // ActionYARepairSink
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Stage 1 of the sink. Requires a Wrench or PipeWrench in hands and an // Stage 1 of the sink. Requires a wrench/pipe wrench (the item this action is
// un-repaired sink. On completion it flags the object as repaired in the // attached to). On completion it spawns a ZenProxySinkTest entity at the sink
// per-object repair map (YAInteractionManager), which then unlocks // proxy's world position - the entity's PRESENCE represents "repaired" and is
// ActionYAGatherWater on the same object. // networked to all clients (ZenProxyFramework pattern).
// //
// Repair state is in-memory and resets on server restart. // Registered on Wrench + PipeWrench (see YAInteractionInit) - item-based, so
// TODO (v2): persist repair state via CF (see YAInteractionManager). // it is unaffected by PlayerBase action load-order issues.
// ============================================================================ // ============================================================================
class ActionYARepairSinkCB : ActionContinuousBaseCB class ActionYARepairSinkCB : ActionContinuousBaseCB
@ -23,43 +23,48 @@ class ActionYARepairSink : ActionContinuousBase
void ActionYARepairSink() void ActionYARepairSink()
{ {
m_CallbackClass = ActionYARepairSinkCB; m_CallbackClass = ActionYARepairSinkCB;
m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_CRAFTING; // kneeling craft/repair anim m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
m_FullBody = true; m_FullBody = true;
m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH; m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
m_Text = "Repair Sink";
} }
override typename GetInputType() override string GetText()
{ {
return ContinuousInteractActionInput; return "Repair Sink";
} }
override void CreateConditionComponents() override bool HasZenProxyTarget()
{
m_ConditionItem = new CCINone(); // tool requirement checked in ActionCondition
m_ConditionTarget = new CCTNonRuined(UAMaxDistances.DEFAULT);
}
override bool HasTarget()
{ {
return true; return true;
} }
// Sink interactable + a wrench in hands + not already repaired. override string GetZenProxyNameTarget()
{
return YAInteractionManager.GetRepairWaterProxyNames();
}
override void CreateConditionComponents()
{
m_ConditionItem = new CCINonRuined(); // the wrench in hands
m_ConditionTarget = new CCTCursorParent(UAMaxDistances.SMALL);
}
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item) override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
{ {
Object targetObject = target.GetObject(); if (!IsTargetingZenActionProxy(player, target, item))
if (!targetObject)
return false; return false;
YAInteractableEntry entry = YAInteractionManager.GetEntry(targetObject.GetType()); // Client-only: hide if the sink is already repaired (entity exists).
if (!entry || entry.ActionType != YAInteractionConfig.ACTION_REPAIR_WATER) if (GetGame().IsClient())
return false; {
vector ls, ws;
string houseType;
GetZenActionProxyTargetEx(player, target, item, ls, ws, houseType);
if (GetProxyObject(ws, YAInteractionConfig.SINK_PROXY_ENTITY))
return false;
}
if (!IsRepairTool(item)) return true;
return false;
return !YAInteractionManager.IsRepaired(targetObject.GetNetworkIDString());
} }
override bool IsLockTargetOnUse() override bool IsLockTargetOnUse()
@ -70,30 +75,24 @@ class ActionYARepairSink : ActionContinuousBase
override void OnFinishProgressServer(ActionData action_data) override void OnFinishProgressServer(ActionData action_data)
{ {
PlayerBase player = action_data.m_Player; PlayerBase player = action_data.m_Player;
Object targetObject = action_data.m_Target.GetObject(); vector proxyWS = GetZenProxyTargetWS(action_data);
if (!player || !targetObject)
return;
string key = targetObject.GetNetworkIDString(); // Already repaired? (entity present)
if (GetProxyObject(proxyWS, YAInteractionConfig.SINK_PROXY_ENTITY))
// Re-check on the server (state may have changed during the progress).
if (YAInteractionManager.IsRepaired(key))
{ {
player.MessageStatus("This sink is already repaired."); if (player)
player.MessageStatus("This sink is already repaired.");
return; return;
} }
YAInteractionManager.SetRepaired(key, true); Object marker = GetGame().CreateObjectEx(YAInteractionConfig.SINK_PROXY_ENTITY, proxyWS, ECE_FULL);
if (!marker)
{
Print("[YAInteraction] FAILED to spawn sink marker @ " + proxyWS.ToString(false));
return;
}
Print(string.Format("[YAInteraction] %1 repaired sink %2", player.GetIdentity().GetId(), key)); Print(string.Format("[YAInteraction] %1 repaired sink @ %2", player.GetIdentity().GetId(), proxyWS.ToString(false)));
player.MessageStatus("You repaired the sink. You can now gather water."); player.MessageStatus("You repaired the sink. You can now gather water.");
} }
// A wrench-type tool held in hands. IsKindOf covers any modded variants.
protected bool IsRepairTool(ItemBase item)
{
if (!item)
return false;
return item.IsKindOf("Wrench") || item.IsKindOf("PipeWrench");
}
} }

View file

@ -1,14 +1,14 @@
// ============================================================================ // ============================================================================
// ActionYASearch // ActionYASearch
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Generic "Search" action. The target's registry entry (resolved by classname // Empty-handed "Search" on a searchable furniture PROXY (fridge / med cabinet
// via YAInteractionManager) decides the loot table and the per-object cooldown. // / vending machine). Uses ZenProxyFramework: the action targets proxies by
// No classnames live here - everything comes from config. // name (GetZenProxyNameTarget) and the proxy world position is synced to the
// server via ActionData, so OnFinishProgressServer can roll loot + gate the
// per-object cooldown by that position.
// //
// Cooldown model (v1): per-object, keyed by network id, in a static map. // Registered on PlayerBase (see YAInteractionInit). Cooldown is in-memory.
// Resets on server restart. // TODO (v2): persist the per-proxy cooldown via CF.
// TODO (v2): swap the static map for CF persistence in IsOnCooldown()/
// StampCooldown() - those two methods are the only persistence surface.
// ============================================================================ // ============================================================================
class ActionYASearchCB : ActionContinuousBaseCB class ActionYASearchCB : ActionContinuousBaseCB
@ -21,46 +21,41 @@ class ActionYASearchCB : ActionContinuousBaseCB
class ActionYASearch : ActionContinuousBase class ActionYASearch : ActionContinuousBase
{ {
// network id string -> server time (ms) when the cooldown expires.
protected static ref map<string, int> m_ObjectCooldowns = new map<string, int>();
void ActionYASearch() void ActionYASearch()
{ {
m_CallbackClass = ActionYASearchCB; m_CallbackClass = ActionYASearchCB;
m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT; // generic full-body interact anim m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
m_FullBody = true; m_FullBody = true;
m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH; m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
m_Text = "Search";
} }
override typename GetInputType() override string GetText()
{ {
return ContinuousInteractActionInput; return "Search";
}
override bool HasZenProxyTarget()
{
return true;
}
override string GetZenProxyNameTarget()
{
return YAInteractionManager.GetSearchProxyNames();
} }
override void CreateConditionComponents() override void CreateConditionComponents()
{ {
m_ConditionItem = new CCINone(); m_ConditionItem = new CCINone();
m_ConditionTarget = new CCTNonRuined(UAMaxDistances.DEFAULT); m_ConditionTarget = new CCTCursorParent(UAMaxDistances.SMALL);
} }
override bool HasTarget()
{
return true;
}
// Empty-handed; target must be a registered "search" interactable.
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item) override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
{ {
Object targetObject = target.GetObject();
if (!targetObject)
return false;
if (player.GetItemInHands()) if (player.GetItemInHands())
return false; return false;
YAInteractableEntry entry = YAInteractionManager.GetEntry(targetObject.GetType()); return IsTargetingZenActionProxy(player, target, item);
return entry != null && entry.ActionType == YAInteractionConfig.ACTION_SEARCH;
} }
override bool IsLockTargetOnUse() override bool IsLockTargetOnUse()
@ -71,71 +66,36 @@ class ActionYASearch : ActionContinuousBase
override void OnFinishProgressServer(ActionData action_data) override void OnFinishProgressServer(ActionData action_data)
{ {
PlayerBase player = action_data.m_Player; PlayerBase player = action_data.m_Player;
Object targetObject = action_data.m_Target.GetObject(); if (!player)
if (!player || !targetObject)
return; return;
YAInteractableEntry entry = YAInteractionManager.GetEntry(targetObject.GetType()); string proxyType = GetZenProxyTargetType(action_data);
vector proxyWS = GetZenProxyTargetWS(action_data);
YAInteractableEntry entry = YAInteractionManager.GetEntryByProxyName(proxyType);
if (!entry || entry.ActionType != YAInteractionConfig.ACTION_SEARCH) if (!entry || entry.ActionType != YAInteractionConfig.ACTION_SEARCH)
return; return;
string key = targetObject.GetNetworkIDString(); string posKey = proxyWS.ToString(false);
// --- Per-object cooldown gate --- if (YAInteractionManager.IsSearchOnCooldown(posKey))
if (IsOnCooldown(key))
{ {
int remaining = GetCooldownRemaining(key); int remaining = YAInteractionManager.GetSearchCooldownRemaining(posKey);
Print(string.Format("[YAInteraction] Search on cooldown (%1s left) for %2", remaining, key));
player.MessageStatus(string.Format("You already searched this. (%1s)", remaining)); player.MessageStatus(string.Format("You already searched this. (%1s)", remaining));
return; return;
} }
// --- Roll & spawn ---
array<ref YALootEntry> table = YAInteractionManager.GetLootTableForEntry(entry); array<ref YALootEntry> table = YAInteractionManager.GetLootTableForEntry(entry);
int rolls = Math.RandomIntInclusive(YAInteractionConfig.SEARCH_ROLLS_MIN, YAInteractionConfig.SEARCH_ROLLS_MAX); int rolls = Math.RandomIntInclusive(YAInteractionConfig.SEARCH_ROLLS_MIN, YAInteractionConfig.SEARCH_ROLLS_MAX);
array<EntityAI> spawned = YALootTableManager.GetInstance().SpawnFromTable(table, rolls, player, player.GetPosition()); array<EntityAI> spawned = YALootTableManager.GetInstance().SpawnFromTable(table, rolls, player, player.GetPosition());
// Stamp cooldown even on an empty result so the object is gated either way. YAInteractionManager.StampSearchCooldown(posKey, entry.CooldownSec);
StampCooldown(key, entry.CooldownSec);
Print(string.Format("[YAInteraction] %1 searched '%2' -> %3 item(s)", player.GetIdentity().GetId(), targetObject.GetType(), spawned.Count())); Print(string.Format("[YAInteraction] %1 searched proxy '%2' @ %3 -> %4 item(s)", player.GetIdentity().GetId(), proxyType, posKey, spawned.Count()));
if (spawned.Count() > 0) if (spawned.Count() > 0)
player.MessageStatus(string.Format("You found %1 item(s).", spawned.Count())); player.MessageStatus(string.Format("You found %1 item(s).", spawned.Count()));
else else
player.MessageStatus("You found nothing useful."); player.MessageStatus("You found nothing useful.");
} }
// ------------------------------------------------------------------
// Cooldown helpers (the only persistence-aware surface area).
// ------------------------------------------------------------------
// TODO (v2): read last-search time from CF storage instead of the static map.
protected static bool IsOnCooldown(string key)
{
int expiry;
if (!m_ObjectCooldowns.Find(key, expiry))
return false;
return GetGame().GetTime() < expiry;
}
protected static int GetCooldownRemaining(string key)
{
int expiry;
if (!m_ObjectCooldowns.Find(key, expiry))
return 0;
int remainingMs = expiry - GetGame().GetTime();
if (remainingMs < 0)
remainingMs = 0;
return remainingMs / 1000;
}
// TODO (v2): persist this stamp via CF so it survives server restarts.
protected static void StampCooldown(string key, float cooldownSec)
{
int expiry = GetGame().GetTime() + (int)(cooldownSec * 1000);
m_ObjectCooldowns.Set(key, expiry);
Print(string.Format("[YAInteraction] Search cooldown stamped for %1 (%2s)", key, cooldownSec));
}
} }

View file

@ -1,12 +1,9 @@
// ============================================================================ // ============================================================================
// YAInteractionConfig - compile-time constants only // YAInteractionConfig - compile-time constants only
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// The registry, loot tables and scalar tunables have moved to JSON // Registry, loot tables and scalar tunables live in JSON (YAInteractionSettings
// (YAInteractionSettings + YAInteractionData, loaded by // + YAInteractionData via YAInteractionConfigLoader). These are the engine-side
// YAInteractionConfigLoader). What remains here are the engine-side constants // constants that aren't user-tunable.
// that are NOT user-tunable: action-type / loot-table id strings (which must
// match the JSON values), the water liquid type, search roll range and the
// action progress-bar durations.
// ============================================================================ // ============================================================================
class YAInteractionConfig class YAInteractionConfig
{ {
@ -19,10 +16,13 @@ class YAInteractionConfig
static const string TABLE_FOOD = "FoodTable"; static const string TABLE_FOOD = "FoodTable";
static const string TABLE_VENDING = "VendingTable"; static const string TABLE_VENDING = "VendingTable";
// ZenProxyFramework entity reused as the sink "repaired" marker.
static const string SINK_PROXY_ENTITY = "ZenProxySinkTest";
// Non-JSON engine constants. // Non-JSON engine constants.
static const int WATER_LIQUID_TYPE = LIQUID_CLEANWATER; static const int WATER_LIQUID_TYPE = LIQUID_WATER;
static const int SEARCH_ROLLS_MIN = 1; // weighted picks per search (min) static const int SEARCH_ROLLS_MIN = 1;
static const int SEARCH_ROLLS_MAX = 2; // weighted picks per search (max) static const int SEARCH_ROLLS_MAX = 2;
// Progress-bar durations (seconds). // Progress-bar durations (seconds).
static const float SEARCH_TIME = 3.0; static const float SEARCH_TIME = 3.0;

View file

@ -102,12 +102,15 @@ class YAInteractionConfigLoader
YAInteractionData d = new YAInteractionData(); YAInteractionData d = new YAInteractionData();
// --- Interactable registry --- // --- Interactable registry (keyed by ZenProxyFramework PROXY NAME) ---
// (classname, actionType, lootTableName, cooldownSec) // (proxyName, actionType, lootTableName, cooldownSec)
d.Interactables.Insert(MakeEntry("StaticObj_Furniture_case_sink_a", YAInteractionConfig.ACTION_REPAIR_WATER, "", Settings.SinkPlayerCooldownSec)); // "case_sink_a" is confirmed (it's in ZenProxyConstants.SINKS). The search
d.Interactables.Insert(MakeEntry("StaticObj_Furniture_lekarnicka", YAInteractionConfig.ACTION_SEARCH, YAInteractionConfig.TABLE_MED, Settings.ObjectCooldownSec)); // names are best guesses - confirm via ZPF's proxy dump / debug F-key and
d.Interactables.Insert(MakeEntry("StaticObj_Furniture_fridge", YAInteractionConfig.ACTION_SEARCH, YAInteractionConfig.TABLE_FOOD, Settings.ObjectCooldownSec)); // correct them in interactables.json (or here + rebuild).
d.Interactables.Insert(MakeEntry("StaticObj_Furniture_vending_machine", YAInteractionConfig.ACTION_SEARCH, YAInteractionConfig.TABLE_VENDING, Settings.ObjectCooldownSec)); d.Interactables.Insert(MakeEntry("case_sink_a", YAInteractionConfig.ACTION_REPAIR_WATER, "", Settings.SinkPlayerCooldownSec));
d.Interactables.Insert(MakeEntry("lekarnicka", YAInteractionConfig.ACTION_SEARCH, YAInteractionConfig.TABLE_MED, Settings.ObjectCooldownSec));
d.Interactables.Insert(MakeEntry("fridge", YAInteractionConfig.ACTION_SEARCH, YAInteractionConfig.TABLE_FOOD, Settings.ObjectCooldownSec));
d.Interactables.Insert(MakeEntry("vending_machine", YAInteractionConfig.ACTION_SEARCH, YAInteractionConfig.TABLE_VENDING, Settings.ObjectCooldownSec));
// --- Loot tables (classnames verified in P:\DZ) --- // --- Loot tables (classnames verified in P:\DZ) ---
YALootTable med = MakeTable(YAInteractionConfig.TABLE_MED); YALootTable med = MakeTable(YAInteractionConfig.TABLE_MED);
@ -142,10 +145,10 @@ class YAInteractionConfigLoader
// --- Factory helpers (data classes have no parameterised ctor so the // --- Factory helpers (data classes have no parameterised ctor so the
// JSON serializer can default-construct them). --- // JSON serializer can default-construct them). ---
private static YAInteractableEntry MakeEntry(string className, string actionType, string lootTableName, float cooldownSec) private static YAInteractableEntry MakeEntry(string proxyName, string actionType, string lootTableName, float cooldownSec)
{ {
YAInteractableEntry e = new YAInteractableEntry(); YAInteractableEntry e = new YAInteractableEntry();
e.ClassName = className; e.ProxyName = proxyName;
e.ActionType = actionType; e.ActionType = actionType;
e.LootTableName = lootTableName; e.LootTableName = lootTableName;
e.CooldownSec = cooldownSec; e.CooldownSec = cooldownSec;

View file

@ -1,41 +1,40 @@
// ============================================================================ // ============================================================================
// YAInteractionData (+ YALootEntry, YALootTable, YAInteractableEntry) // YAInteractionData (+ YALootEntry, YALootTable, YAInteractableEntry)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Serializable model for <ProfileFolder>/YAInteraction/interactables.json: // Serializable model for <ProfileFolder>/YAInteraction/interactables.json.
// the interactable registry and all loot tables.
// //
// Field names MUST match the JSON keys exactly. Arrays are initialised inline // Interactables are keyed by PROXY NAME - the in-house furniture proxy
// with `new array<...>()` so the JSON serializer can populate them and so a // selection name reported by ZenProxyFramework (e.g. "case_sink_a", "fridge").
// freshly-constructed instance is never null. No explicit constructors: the // Discover names with ZPF's debug mode (DebugOn + press F) or its dumped
// serializer instantiates each class via its default constructor. // proxy JSON, then set them here.
//
// Field names MUST match the JSON keys. Arrays are initialised inline so the
// serializer can populate them. No explicit constructors (serializer needs the
// default ctor).
// ============================================================================ // ============================================================================
// One row of a loot table. Weight is float to round-trip JSON values like 40.0.
class YALootEntry class YALootEntry
{ {
string ClassName; // item classname string ClassName; // item classname
float Weight; // relative weight within its table (higher = more likely) float Weight; // relative weight within its table
int MinQty; // min stack quantity (<=0 => leave item default) int MinQty; // min stack qty (<=0 => item default)
int MaxQty; // max stack quantity (<=0 => leave item default) int MaxQty; // max stack qty (<=0 => item default)
} }
// A named loot table: a name plus its weighted entries.
class YALootTable class YALootTable
{ {
string Name; string Name;
ref array<ref YALootEntry> Entries = new array<ref YALootEntry>(); ref array<ref YALootEntry> Entries = new array<ref YALootEntry>();
} }
// One registered interactable object.
class YAInteractableEntry class YAInteractableEntry
{ {
string ClassName; // target object classname string ProxyName; // in-house proxy selection name (ZenProxyFramework)
string ActionType; // "search" or "repair_water" (YAInteractionConfig.ACTION_*) string ActionType; // "search" or "repair_water" (YAInteractionConfig.ACTION_*)
string LootTableName; // named loot table (empty for repair_water) string LootTableName; // named loot table (empty for repair_water)
float CooldownSec; // search: per-object cooldown / water: per-player cooldown float CooldownSec; // search: per-object cooldown / water: per-player cooldown
} }
// Root document for interactables.json.
class YAInteractionData class YAInteractionData
{ {
ref array<ref YAInteractableEntry> Interactables = new array<ref YAInteractableEntry>(); ref array<ref YAInteractableEntry> Interactables = new array<ref YAInteractableEntry>();

View file

@ -1,34 +1,39 @@
// ============================================================================ // ============================================================================
// YAInteractionManager // YAInteractionManager
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Builds runtime lookup maps from the loaded config (YAInteractionConfigLoader // Builds runtime lookups from the loaded config (keyed by ZenProxyFramework
// .Data) and owns per-object repair state. Nothing here contains a hardcoded // proxy name) and owns the in-memory cooldowns.
// target classname - everything is derived from the loaded registry.
// //
// RebuildLookups() is called by the loader after Data is (re)loaded. Lookups // Repair state is NOT tracked here - it's represented by the presence of a
// are also lazily ensured so client-side action injection works even though // ZenProxySinkTest entity spawned at the sink (ZenProxyFramework pattern), so
// the loader's full Init() only runs on the server. // it is networked to clients for free.
//
// Cooldowns (reset on restart):
// * Search - per-object, keyed by proxy world-position string.
// * Water - per-player, keyed by player UID.
// TODO (v2): persist cooldowns via CF, keyed by proxy world position.
// ============================================================================ // ============================================================================
class YAInteractionManager class YAInteractionManager
{ {
// lowercased classname -> registry entry private static ref map<string, ref YAInteractableEntry> m_EntryByProxy = new map<string, ref YAInteractableEntry>();
private static ref map<string, ref YAInteractableEntry> m_EntryByClass = new map<string, ref YAInteractableEntry>();
// loot table name -> table
private static ref map<string, ref YALootTable> m_TableByName = new map<string, ref YALootTable>(); private static ref map<string, ref YALootTable> m_TableByName = new map<string, ref YALootTable>();
// per-object repair state, keyed by network id string.
// TODO (v2): back this with CF persistence so repairs survive a restart. private static ref map<string, int> m_SearchCooldowns = new map<string, int>(); // proxyWorldPos -> expiry ms
private static ref map<string, bool> m_RepairState = new map<string, bool>(); private static ref map<string, int> m_WaterCooldowns = new map<string, int>(); // playerUID -> expiry ms
// Cached comma-joined proxy-name lists for the actions' GetZenProxyNameTarget().
private static string m_SearchProxyNames = "";
private static string m_RepairWaterProxyNames = "";
private static bool m_Ready = false; private static bool m_Ready = false;
// ------------------------------------------------------------------
// Fold the loaded Data into case-insensitive lookup maps.
// Called by YAInteractionConfigLoader after (re)loading Data.
// ------------------------------------------------------------------ // ------------------------------------------------------------------
static void RebuildLookups() static void RebuildLookups()
{ {
m_EntryByClass.Clear(); m_EntryByProxy.Clear();
m_TableByName.Clear(); m_TableByName.Clear();
m_SearchProxyNames = "";
m_RepairWaterProxyNames = "";
if (!YAInteractionConfigLoader.Data) if (!YAInteractionConfigLoader.Data)
{ {
@ -39,11 +44,17 @@ class YAInteractionManager
foreach (YAInteractableEntry e : YAInteractionConfigLoader.Data.Interactables) foreach (YAInteractableEntry e : YAInteractionConfigLoader.Data.Interactables)
{ {
if (!e || e.ClassName == "") if (!e || e.ProxyName == "")
continue; continue;
string key = e.ClassName;
string key = e.ProxyName;
key.ToLower(); key.ToLower();
m_EntryByClass.Set(key, e); m_EntryByProxy.Set(key, e);
if (e.ActionType == YAInteractionConfig.ACTION_SEARCH)
m_SearchProxyNames = AppendName(m_SearchProxyNames, e.ProxyName);
else if (e.ActionType == YAInteractionConfig.ACTION_REPAIR_WATER)
m_RepairWaterProxyNames = AppendName(m_RepairWaterProxyNames, e.ProxyName);
} }
foreach (YALootTable t : YAInteractionConfigLoader.Data.LootTables) foreach (YALootTable t : YAInteractionConfigLoader.Data.LootTables)
@ -54,100 +65,115 @@ class YAInteractionManager
} }
m_Ready = true; m_Ready = true;
Print(string.Format("[YAInteraction] Lookups built: %1 interactable(s), %2 loot table(s)", m_EntryByClass.Count(), m_TableByName.Count())); Print(string.Format("[YAInteraction] Lookups built: %1 interactable(s), %2 loot table(s). search='%3' repair_water='%4'",
m_EntryByProxy.Count(), m_TableByName.Count(), m_SearchProxyNames, m_RepairWaterProxyNames));
}
private static string AppendName(string csv, string name)
{
if (csv == "")
return name;
return csv + "," + name;
} }
// Ensure config + lookups exist. On the server Init() has already run; on a
// client this lazily builds in-code defaults (no file I/O).
private static void EnsureReady() private static void EnsureReady()
{ {
if (m_Ready) if (m_Ready)
return; return;
YAInteractionConfigLoader.EnsureDefaults(); YAInteractionConfigLoader.EnsureDefaults();
RebuildLookups(); RebuildLookups();
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Registry lookups. // Proxy-name targeting lists for the actions.
// ------------------------------------------------------------------ // ------------------------------------------------------------------
static YAInteractableEntry GetEntry(string className) static string GetSearchProxyNames()
{ {
EnsureReady(); EnsureReady();
return m_SearchProxyNames;
if (className == "")
return null;
string key = className;
key.ToLower();
YAInteractableEntry e;
if (m_EntryByClass.Find(key, e))
return e;
return null;
} }
static bool IsInteractable(string className) static string GetRepairWaterProxyNames()
{ {
return GetEntry(className) != null; EnsureReady();
return m_RepairWaterProxyNames;
}
// Case-insensitive lookup by proxy name.
static YAInteractableEntry GetEntryByProxyName(string proxyName)
{
EnsureReady();
if (proxyName == "")
return null;
string key = proxyName;
key.ToLower();
YAInteractableEntry e;
if (m_EntryByProxy.Find(key, e))
return e;
return null;
} }
static array<ref YALootEntry> GetLootTableForEntry(YAInteractableEntry entry) static array<ref YALootEntry> GetLootTableForEntry(YAInteractableEntry entry)
{ {
EnsureReady(); EnsureReady();
if (!entry || entry.LootTableName == "") if (!entry || entry.LootTableName == "")
return null; return null;
YALootTable t; YALootTable t;
if (m_TableByName.Find(entry.LootTableName, t)) if (m_TableByName.Find(entry.LootTableName, t))
return t.Entries; return t.Entries;
Print(string.Format("[YAInteraction] Loot table '%1' for proxy '%2' not found", entry.LootTableName, entry.ProxyName));
Print(string.Format("[YAInteraction] Loot table '%1' referenced by '%2' not found", entry.LootTableName, entry.ClassName));
return null; return null;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Action injection mapping. Returns the action typenames to register // Search cooldown (per object, keyed by proxy world position).
// on a classname. Keeps YAInteractionInit free of classname strings.
// ------------------------------------------------------------------ // ------------------------------------------------------------------
static array<typename> GetActionTypesFor(string className) static bool IsSearchOnCooldown(string posKey)
{ {
array<typename> result = new array<typename>(); int expiry;
if (!m_SearchCooldowns.Find(posKey, expiry))
return false;
return GetGame().GetTime() < expiry;
}
YAInteractableEntry entry = GetEntry(className); static int GetSearchCooldownRemaining(string posKey)
if (!entry) {
return result; int expiry;
if (!m_SearchCooldowns.Find(posKey, expiry))
return 0;
int rem = expiry - GetGame().GetTime();
if (rem < 0) rem = 0;
return rem / 1000;
}
if (entry.ActionType == YAInteractionConfig.ACTION_SEARCH) static void StampSearchCooldown(string posKey, float cooldownSec)
{ {
result.Insert(ActionYASearch); m_SearchCooldowns.Set(posKey, GetGame().GetTime() + (int)(cooldownSec * 1000));
}
else if (entry.ActionType == YAInteractionConfig.ACTION_REPAIR_WATER)
{
// Both always registered; their ActionCondition gates which is usable.
result.Insert(ActionYARepairSink);
result.Insert(ActionYAGatherWater);
}
return result;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Per-object repair state (sinks). // Water cooldown (per player).
// TODO (v2): read/write through CF persistence instead of the static map.
// ------------------------------------------------------------------ // ------------------------------------------------------------------
static bool IsRepaired(string networkKey) static bool IsWaterOnCooldown(string uid)
{ {
bool repaired; int expiry;
if (m_RepairState.Find(networkKey, repaired)) if (!m_WaterCooldowns.Find(uid, expiry))
return repaired; return false;
return false; return GetGame().GetTime() < expiry;
} }
static void SetRepaired(string networkKey, bool value = true) static int GetWaterCooldownRemaining(string uid)
{ {
m_RepairState.Set(networkKey, value); int expiry;
Print(string.Format("[YAInteraction] Repair state for %1 set to %2", networkKey, value)); if (!m_WaterCooldowns.Find(uid, expiry))
return 0;
int rem = expiry - GetGame().GetTime();
if (rem < 0) rem = 0;
return rem / 1000;
}
static void StampWaterCooldown(string uid, float cooldownSec)
{
m_WaterCooldowns.Set(uid, GetGame().GetTime() + (int)(cooldownSec * 1000));
} }
} }

View file

@ -1,37 +1,65 @@
// ============================================================================ // ============================================================================
// YAInteractionInit // YAInteractionInit
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Injects the mod's actions onto the target objects, driven entirely by the // Wires the actions into the game, following the ZenProxyFramework pattern:
// config registry. There are no classname strings and no action-type branching
// here - YAInteractionManager.GetActionTypesFor() returns exactly which actions
// to register for a given classname.
// //
// BASE CLASS - verified against P:\scripts and P:\DZ: // * ActionConstructor - register custom actions so GetAction() resolves them
// The four targets are config classes that inherit: // (otherwise AddAction() dereferences null -> crash).
// StaticObj_Furniture_* -> HouseNoDestruct -> House -> Static // * PlayerBase - Search (empty-handed; the only player-side action).
// There is NO script class named StaticObj or HouseNoDestruct; "House" is the // * Wrench / PipeWrench - Repair Sink (item-in-hands; load-order safe).
// first script-backed ancestor (House : BuildingBase). So every one of these // * Bottle_Base - Gather Water (item-in-hands; load-order safe).
// objects resolves to the BuildingBase script class - that is where we hook.
// //
// We override SetActions() rather than GetActions(): BuildingBase implements // Furniture identification + position sync is handled by ZenProxyFramework's
// a GetActions()/SetActions() split where GetActions() lazily calls // modded ActionBase (GetZenProxyNameTarget / GetZenProxyTargetWS).
// SetActions() ONCE and caches the result per object type. SetActions() is
// therefore the correct extension point. (Overriding GetActions() directly
// would re-append to the cached array on every query and duplicate actions.)
// Calling super.SetActions() first preserves any inherited/base actions.
// ============================================================================ // ============================================================================
modded class BuildingBase modded class ActionConstructor
{
override void RegisterActions(TTypenameArray actions)
{
super.RegisterActions(actions);
actions.Insert(ActionYASearch);
actions.Insert(ActionYARepairSink);
actions.Insert(ActionYAGatherWater);
}
}
modded class PlayerBase
{
override void SetActions(out TInputActionMap InputActionMap)
{
super.SetActions(InputActionMap);
AddAction(ActionYASearch, InputActionMap);
Print("[YAInteraction] Registered player action (Search)");
}
}
modded class Wrench
{ {
override void SetActions() override void SetActions()
{ {
super.SetActions(); // preserve inherited actions (doors, fireplaces, etc.) super.SetActions();
AddAction(ActionYARepairSink);
array<typename> actionsToAdd = YAInteractionManager.GetActionTypesFor(GetType()); }
foreach (typename actionType : actionsToAdd) }
{
AddAction(actionType); modded class PipeWrench
Print("[YAInteraction] Registered " + actionType + " on '" + GetType() + "'"); {
} override void SetActions()
{
super.SetActions();
AddAction(ActionYARepairSink);
}
}
modded class Bottle_Base
{
override void SetActions()
{
super.SetActions();
AddAction(ActionYAGatherWater);
} }
} }