forked from acegiak/qudkissing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRomanceChatNode.cs
163 lines (137 loc) · 5.28 KB
/
RomanceChatNode.cs
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using Qud.API;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using XRL.Core;
using XRL.UI;
using XRL.World.Parts;
using XRL.World;
using XRL.Rules;
using HistoryKit;
using ConsoleLib.Console;
namespace XRL.World
{
[Serializable]
public class acegiak_RomanceChatNode : ConversationNode
{
float Amount = 0;
string Title = "huh?";
string Back = "ok.";
public acegiak_RomanceChatNode(){}
public acegiak_RomanceChatNode(string id, string title, string text, float opinionamount){
this.Text = text;
this.ID = id;
this.Amount = opinionamount;
this.Title = title;
}
public void AddChoice(string id, string title,string response, float opinionchange,acegiak_RomanceChatChoice.acegiak_ChoiceAction action = null){
acegiak_RomanceChatChoice choice = new acegiak_RomanceChatChoice();
choice.ID = "acegiak_romance_"+id;
choice.Text = title;
choice.ResponseText = response;
choice.OpinionAmount = opinionchange;
choice.GotoID = "acegiak_romance_aboutme";
if(id == "End"){
choice.GotoID = "End";
}
choice.ParentNode = this;
if(action != null){
choice.choiceAction = action;
}
this.Choices.Add(choice);
}
public void InsertMyReaction(
GameObject me, GameObject them)
{
// Must be kissable
var kissable = me.GetPart<acegiak_Kissable>();
if (kissable == null)
{
Text = " &R(this character is not kissable)&y\n\n" + Text;
return;
}
// Find a random applicable kissing-preference
kissable.havePreference();
acegiak_KissingPreferenceResult assess = null;
for (int i = 0; i < 1; ++i)
{
var preference = kissable.preferences.GetRandomElement(Stat.Rnd2);
if (preference == null)
{
acegiak_RomanceText.Log("ERROR drew a null kissing preference");
return;
}
//[Stat.Rnd2.Next(kissable.preferences.Count)];
assess = preference.attractionAmount(me, them);
if (assess.amount != 0f) break;
}
if (assess.amount == 0f)
{
//Text = " &c(no reaction)&y\n\n" + Text;
return;
}
// Generate a reaction
string spiceKey = "<spice.eros.react." + assess.reactPath +
((assess.amount > 0f) ? ".like" : ".dislike") + ".!random>";
string reaction = acegiak_RomanceText.ExpandString(spiceKey, assess.reactVars);
// Apply some formatting and prepend
if (reaction != null && reaction.Count() > 0)
{
Text = " &M" + reaction
// + " &k" + assess.reactPath
+ "&y\n\n" + Text;
}
else
{
Text = " &R"
+ spiceKey.Substring(1,spiceKey.Count()-2)+"&y\n\n" + Text;
}
}
public void ExpandText(
HistoricEntitySnapshot entity,
Dictionary<string, string> vars = null)
{
Text = FilterRandom(Text);
Text = Text
//acegiak_RomanceText.ExpandString(
//Text, entity, vars)
+ "&k"; // Black out village text, mrah
foreach(ConversationChoice choice in Choices){
choice.Text = FilterRandom(choice.Text);
//choice.Text = acegiak_RomanceText.ExpandString(
// choice.Text, entity, vars);
}
}
public static string FilterRandom(string s)
{
return Regex.Replace(s, @"<([^\|>]+\|[^>]+)>", delegate(Match match)
{
string[] v = match.Groups[1].ToString().Split('|');
return v[Stat.Rnd2.Next(v.Length)];
});
}
// public virtual void Visit(GameObject speaker, GameObject player){
// if(speaker != null && speaker.pBrain != null && player != null){
// ParentObject.pBrain.AdjustFeeling(player,Amount);
// }
// base.Visit(speaker,player);
// }
// public void AttachTo(ConversationNode parentNode){
// parentNode.ParentConversation.NodesById.Remove(this.ID);
// parentNode.ParentConversation.AddNode(this);
// ConversationChoice choice = new ConversationChoice();
// choice.ID = this.ID+"_choice";
// choice.GotoID = this.ID;
// choice.Text = this.Title;
// ConversationChoice backchoice = new ConversationChoice();
// backchoice.ID = this.ID+"_return";
// backchoice.GotoID = parentNode.ID;
// backchoice.Text = this.Back;
// this.ParentNode = parentNode;
// parentNode.Choices.RemoveAll(x => x.ID == choice.ID || choice.GotoID);
// parentNode.Choices.Add(choice);
// }
}
}