The faction merchants' 90 jokes, their generic lines and their names now read from merchants.json. Merchant names use the game's own creature tokens where one matches, so they arrive translated in every language Valheim ships; the Dverg keeps a key of its own, since vanilla's token reads "Dvergr Rogue". The Dvergar and Trol troop names and terms, and the Sverm hive's goods, refusals, stage names and brood kinds, follow. Their panels fill TMP texts themselves, so they localize the names where they draw them. The jokes have English text only for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
4 KiB
C#
80 lines
4 KiB
C#
using System.Collections.Generic;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
// Turns a freshly spawned vanilla mob into a trader the moment it wakes up, if its
|
|
// prefab is one of the ones listed in FactionMerchantCatalog. Everything needed to
|
|
// reuse vanilla Trader/StoreGui (buy list, dialogue, look-at rig) is wired up here;
|
|
// the actual "sell your stuff back" second column lives in FactionMerchantSellPanel.
|
|
[HarmonyPatch(typeof(Character), "Awake")]
|
|
public static class FactionMerchantSetupPatch
|
|
{
|
|
// 6s to match the "battuta visibile 6 secondi" rule.
|
|
private const float DialogHideDelay = 6f;
|
|
|
|
private static readonly string[] GenericGreets = { "..." };
|
|
private static readonly string[] GenericGoodbye = { "..." };
|
|
private static readonly string[] GenericStartTrade = { "$rov_merchant_start_trade" };
|
|
private static readonly string[] GenericBuy = { "$rov_merchant_buy" };
|
|
private static readonly string[] GenericSell = { "$rov_merchant_sell" };
|
|
|
|
public static void Postfix(Character __instance)
|
|
{
|
|
if (!FactionsConfig.Merchants) return;
|
|
if (__instance == null) return;
|
|
GameObject go = ((Component)__instance).gameObject;
|
|
if (go.GetComponent<FactionMerchant>() != null) return; // already set up
|
|
|
|
string prefabName = go.name.Replace("(Clone)", "").Trim();
|
|
if (!FactionMerchantCatalog.Shops.TryGetValue(prefabName, out var shop)) return;
|
|
|
|
var merchant = go.AddComponent<FactionMerchant>();
|
|
merchant.Shop = shop;
|
|
|
|
Trader trader = go.GetComponent<Trader>() ?? go.AddComponent<Trader>();
|
|
trader.m_name = shop.DisplayName;
|
|
trader.m_hideDialogDelay = DialogHideDelay;
|
|
|
|
trader.m_items.Clear();
|
|
foreach (var entry in shop.Items)
|
|
{
|
|
GameObject itemPrefab = ObjectDB.instance != null ? ObjectDB.instance.GetItemPrefab(entry.PrefabName) : null;
|
|
ItemDrop itemDrop = itemPrefab != null ? itemPrefab.GetComponent<ItemDrop>() : null;
|
|
if (itemDrop == null)
|
|
{
|
|
Debug.LogWarning($"[Factions] {shop.DisplayName}: unrecognized item prefab '{entry.PrefabName}', skipped.");
|
|
continue;
|
|
}
|
|
trader.m_items.Add(new Trader.TradeItem
|
|
{
|
|
m_prefab = itemDrop,
|
|
m_stack = 1,
|
|
m_price = entry.Price,
|
|
// Valheim 1.0 fields that StoreGui dereferences without a null check:
|
|
// FillList reads m_tooltip.Length, BuySelectedItem calls
|
|
// m_buyPlayerEffects.Create. Empty means "use the item's own".
|
|
m_name = string.Empty,
|
|
m_tooltip = string.Empty,
|
|
m_buyKey = string.Empty,
|
|
m_incrementKey = string.Empty,
|
|
m_buyPlayerEffects = new EffectList(),
|
|
});
|
|
}
|
|
|
|
// Vanilla Trader.RandomTalk() indexes into these lists unconditionally, so they
|
|
// can never be left empty even though we do not care about the flavour text here.
|
|
trader.m_randomGreets = new List<string>(GenericGreets);
|
|
trader.m_randomGoodbye = new List<string>(GenericGoodbye);
|
|
trader.m_randomStartTrade = new List<string>(GenericStartTrade);
|
|
trader.m_randomBuy = new List<string>(GenericBuy);
|
|
trader.m_randomSell = new List<string>(GenericSell);
|
|
trader.m_randomTalk = new List<string>(FactionMerchantJokes.Lines.TryGetValue(shop.JokeCategory, out var lines) ? lines : GenericGreets);
|
|
|
|
// Trader.Update() is skipped entirely for these (FactionMerchantSuppressAmbientPatch),
|
|
// so none of its proximity-driven greet/stand/look-at logic ever runs and a LookAt
|
|
// component would never be used - not added here on purpose.
|
|
}
|
|
}
|
|
}
|