-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomNPC.cs
More file actions
95 lines (81 loc) · 2.81 KB
/
CustomNPC.cs
File metadata and controls
95 lines (81 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using MelonLoader;
using S1API.GameTime;
using S1API.Leveling;
using S1API.NPCs;
using S1API.Products;
using S1API.Quests;
using S1API.Saveables;
using S1APIExamples;
using UnityEngine;
using Random = UnityEngine.Random;
namespace ExampleMod.QuestTest
{
public class CustomNPC : NPC
{
private const int ProductPerLevel = 5;
private const int ProductVariation = 8;
private const float ProductPriceMultiplier = 1.1f;
[SaveableField("Order")]
private OrderData? _orderData;
public CustomNPC() : base("custom_npc", "Test", "NPC") { }
protected override void OnCreated()
{
TimeManager.OnDayPass += OnDayPass;
}
protected override void OnResponseLoaded(Response response)
{
switch (response.Label)
{
case "ACCEPT":
response.OnTriggered = AcceptOrder;
break;
case "DENY":
response.OnTriggered = DenyOrder;
break;
}
}
private void OnDayPass()
{
// Only send request once per week
if (_orderData == null && TimeManager.CurrentDay == Day.Monday)
SendRequest();
}
private void SendRequest()
{
if (ProductManager.DiscoveredProducts.Length == 0)
return;
ProductDefinition product = ProductManager.DiscoveredProducts[Random.Range(0, ProductManager.DiscoveredProducts.Length)];
int level = (int)LevelManager.Rank;
int amount = level * ProductPerLevel + Random.Range(-ProductVariation, ProductVariation);
int price = Mathf.RoundToInt(product.Price * amount * ProductPriceMultiplier);
_orderData = new OrderData
{
Product = product,
Amount = amount,
Price = price
};
string message = $"Request: {amount}x {product.Name} for ${price}. Accept?";
SendTextMessage(message, new[]
{
new Response { Label = "ACCEPT", Text = "Yes", OnTriggered = AcceptOrder },
new Response { Label = "DENY", Text = "No" , OnTriggered = DenyOrder }
});
}
private void AcceptOrder()
{
if (_orderData?.Product == null)
return;
var quest = (OrderQuest)QuestManager.CreateQuest<OrderQuest>();
quest.SetupAsNew(_orderData);
_orderData = null;
SendTextMessage("Order accepted. Quest added.");
}
private void DenyOrder()
{
_orderData = null;
SendTextMessage("Order denied.");
}
}
}