Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions S1API/Entities/NPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ internal static int IncludeNavMeshArea(int areaMask, int areaIndex) =>
RewireChildNpcReferences(prefabRoot, dealer);
RepairDealerPrefabReferences(prefabRoot, dealer);
RepairNpcPrefabReferences(prefabRoot, dealer);
if (sourceNpc != dealer)
RemoveComponentImmediate(sourceNpc);
return dealer;
}

Expand Down
46 changes: 24 additions & 22 deletions S1API/Entities/NPCCustomer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,29 @@ private void WireCoreReferences(S1Economy.Customer customer)
}
}

internal static S1Economy.CustomerData CreateDefaultCustomerData()
{
var data = ScriptableObject.CreateInstance<S1Economy.CustomerData>();
data.DefaultAffinityData = new S1Economy.CustomerAffinityData();
foreach (var drugType in Enum.GetValues(typeof(S1Product.EDrugType)))
{
data.DefaultAffinityData.ProductAffinities.Add(new S1Economy.ProductTypeAffinity
{
DrugType = (S1Product.EDrugType)drugType,
Affinity = 0f
});
}
data.MinWeeklySpend = 100f;
data.MaxWeeklySpend = 400f;
data.MinOrdersPerWeek = 1;
data.MaxOrdersPerWeek = 3;
data.OrderTime = 1200;
data.CanBeDirectlyApproached = true;
data.DependenceMultiplier = 1f;
data.BaseAddiction = 0f;
return data;
}

private void EnsureCustomerData(S1Economy.Customer customer)
{
try
Expand Down Expand Up @@ -329,28 +352,7 @@ private void EnsureCustomerData(S1Economy.Customer customer)

if (data == null)
{
// Create a minimal, safe CustomerData so base game logic has sane defaults
data = ScriptableObject.CreateInstance<S1Economy.CustomerData>();
data.DefaultAffinityData = new S1Economy.CustomerAffinityData();
// Seed affinities for all product types with neutral preference
Array drugTypes = Enum.GetValues(typeof(S1Product.EDrugType));
foreach (var dt in drugTypes)
{
data.DefaultAffinityData.ProductAffinities.Add(new S1Economy.ProductTypeAffinity
{
DrugType = (S1Product.EDrugType)dt,
Affinity = 0f
});
}
// Reasonable defaults
data.MinWeeklySpend = 100f;
data.MaxWeeklySpend = 400f;
data.MinOrdersPerWeek = 1;
data.MaxOrdersPerWeek = 3;
data.OrderTime = 1200;
data.CanBeDirectlyApproached = true;
data.DependenceMultiplier = 1f;
data.BaseAddiction = 0f;
data = CreateDefaultCustomerData();


#if MONOMELON
Expand Down
13 changes: 13 additions & 0 deletions S1API/Entities/NPCPrefabBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ internal NPCPrefabBuilder EnsureCustomerInfrastructure()
customer = prefabRoot.AddComponent<S1Economy.Customer>();
customer.enabled = true;
}
// A joining client's native Awake runs before its managed NPC wrapper can
// create fallback data. Configure the inactive prefab before network spawn.
if (customer.CustomerData == null)
{
var data = NPCCustomer.CreateDefaultCustomerData();
#if MONOMELON
var field = typeof(S1Economy.Customer).GetField("customerData",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
field?.SetValue(customer, data);
#else
customer.customerData = data;
#endif
}
return this;
}

Expand Down
Loading