Skip to content

Commit eeac915

Browse files
author
Heron
committed
Scaffold for conversation manager
1 parent ea12677 commit eeac915

10 files changed

Lines changed: 805 additions & 0 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package script.systems.conversation_manager;
2+
3+
public class conversation_action
4+
{
5+
public String actionSet;
6+
public int order;
7+
public String actionType;
8+
public String arg1;
9+
public String arg2;
10+
public String arg3;
11+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package script.systems.conversation_manager;
2+
3+
import script.dictionary;
4+
import script.library.armor;
5+
import script.library.factions;
6+
import script.library.groundquests;
7+
import script.library.money;
8+
import script.library.utils;
9+
import script.obj_id;
10+
import script.string_id;
11+
12+
public class conversation_actions extends script.base_script
13+
{
14+
public conversation_actions()
15+
{
16+
}
17+
18+
public void executeActionSet(conversation_context ctx, conversation_definition definition, String actionSet) throws InterruptedException
19+
{
20+
if (actionSet == null || actionSet.equals(""))
21+
{
22+
return;
23+
}
24+
for (int order = 0; order < 1000; ++order)
25+
{
26+
for (conversation_action action : definition.actions)
27+
{
28+
if (action.actionSet != null && action.actionSet.equals(actionSet) && action.order == order)
29+
{
30+
debug(ctx, "execute actionSet=" + actionSet + " order=" + action.order + " type=" + action.actionType + " arg1=" + action.arg1);
31+
execute(ctx, action);
32+
}
33+
}
34+
}
35+
}
36+
37+
public void execute(conversation_context ctx, conversation_action action) throws InterruptedException
38+
{
39+
if (action == null || action.actionType == null || action.actionType.equals(""))
40+
{
41+
return;
42+
}
43+
if (action.actionType.equals("grantQuest"))
44+
{
45+
groundquests.grantQuest(ctx.player, action.arg1);
46+
return;
47+
}
48+
if (action.actionType.equals("requestGrantQuest"))
49+
{
50+
groundquests.requestGrantQuest(ctx.player, action.arg1);
51+
return;
52+
}
53+
if (action.actionType.equals("clearQuest"))
54+
{
55+
groundquests.clearQuest(ctx.player, action.arg1);
56+
return;
57+
}
58+
if (action.actionType.equals("sendQuestSignal"))
59+
{
60+
groundquests.sendSignal(ctx.player, action.arg1);
61+
return;
62+
}
63+
if (action.actionType.equals("giveItem"))
64+
{
65+
createObjectInInventoryAllowOverload(action.arg1, ctx.player);
66+
return;
67+
}
68+
if (action.actionType.equals("giveArmorItem"))
69+
{
70+
obj_id armorItem = createObjectInInventoryAllowOverload(action.arg1, ctx.player);
71+
if (isIdValid(armorItem) && action.arg2 != null && !action.arg2.equals(""))
72+
{
73+
float min = utils.stringToFloat(action.arg2);
74+
float max = min;
75+
if (action.arg3 != null && !action.arg3.equals(""))
76+
{
77+
max = utils.stringToFloat(action.arg3);
78+
}
79+
if (!isGameObjectTypeOf(armorItem, GOT_armor_foot) && !isGameObjectTypeOf(armorItem, GOT_armor_hand))
80+
{
81+
armor.setArmorDataPercent(armorItem, 2, 1, min, max);
82+
}
83+
}
84+
return;
85+
}
86+
if (action.actionType.equals("grantSchematic"))
87+
{
88+
grantSchematic(ctx.player, action.arg1);
89+
return;
90+
}
91+
if (action.actionType.equals("rewardFaction"))
92+
{
93+
factions.awardFactionStanding(ctx.player, action.arg1, utils.stringToInt(action.arg2));
94+
return;
95+
}
96+
if (action.actionType.equals("giveCredits"))
97+
{
98+
money.bankTo(money.ACCT_JABBA, ctx.player, utils.stringToInt(action.arg1));
99+
return;
100+
}
101+
if (action.actionType.equals("setObjvar"))
102+
{
103+
setObjVar(ctx.player, action.arg1, action.arg2);
104+
return;
105+
}
106+
if (action.actionType.equals("removeObjvar"))
107+
{
108+
removeObjVar(ctx.player, action.arg1);
109+
return;
110+
}
111+
if (action.actionType.equals("playNpcAnimation"))
112+
{
113+
doAnimationAction(ctx.npc, action.arg1);
114+
return;
115+
}
116+
if (action.actionType.equals("playPlayerAnimation"))
117+
{
118+
doAnimationAction(ctx.player, action.arg1);
119+
return;
120+
}
121+
if (action.actionType.equals("facePlayer"))
122+
{
123+
faceTo(ctx.npc, ctx.player);
124+
return;
125+
}
126+
if (action.actionType.equals("sendMessageNpc"))
127+
{
128+
dictionary params = new dictionary();
129+
params.put("player", ctx.player);
130+
params.put("npc", ctx.npc);
131+
params.put("arg1", action.arg1);
132+
params.put("arg2", action.arg2);
133+
params.put("arg3", action.arg3);
134+
messageTo(ctx.npc, action.arg1, params, 0, false);
135+
return;
136+
}
137+
if (action.actionType.equals("sendSystemMessage"))
138+
{
139+
sendSystemMessage(ctx.player, new string_id(ctx.stringFile, action.arg1));
140+
return;
141+
}
142+
LOG("conversation_manager", "Unknown action type '" + action.actionType + "' for conversation '" + ctx.conversationId + "'");
143+
debug(ctx, "unknown action type=" + action.actionType);
144+
}
145+
146+
public void debug(conversation_context ctx, String message) throws InterruptedException
147+
{
148+
if (ctx == null || !isIdValid(ctx.npc) || !isIdValid(ctx.player))
149+
{
150+
return;
151+
}
152+
if (!hasObjVar(ctx.npc, "conversation_manager.debug"))
153+
{
154+
return;
155+
}
156+
if (!getBooleanObjVar(ctx.npc, "conversation_manager.debug"))
157+
{
158+
return;
159+
}
160+
sendSystemMessage(ctx.player, "[conversation_manager] " + message, null);
161+
}
162+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package script.systems.conversation_manager;
2+
3+
import script.library.features;
4+
import script.library.factions;
5+
import script.library.groundquests;
6+
import script.obj_id;
7+
8+
public class conversation_conditions extends script.base_script
9+
{
10+
public conversation_conditions()
11+
{
12+
}
13+
14+
public boolean passes(conversation_context ctx, String conditionType, String arg1, String arg2) throws InterruptedException
15+
{
16+
if (conditionType == null || conditionType.equals("") || conditionType.equals("always"))
17+
{
18+
return true;
19+
}
20+
if (conditionType.equals("questActive"))
21+
{
22+
return debugResult(ctx, conditionType, arg1, arg2, groundquests.isQuestActive(ctx.player, arg1));
23+
}
24+
if (conditionType.equals("questComplete"))
25+
{
26+
return debugResult(ctx, conditionType, arg1, arg2, groundquests.hasCompletedQuest(ctx.player, arg1));
27+
}
28+
if (conditionType.equals("questActiveOrComplete"))
29+
{
30+
return debugResult(ctx, conditionType, arg1, arg2, groundquests.isQuestActiveOrComplete(ctx.player, arg1));
31+
}
32+
if (conditionType.equals("taskActive"))
33+
{
34+
return debugResult(ctx, conditionType, arg1, arg2, groundquests.isTaskActive(ctx.player, arg1, arg2));
35+
}
36+
if (conditionType.equals("taskComplete"))
37+
{
38+
return debugResult(ctx, conditionType, arg1, arg2, groundquests.hasCompletedTask(ctx.player, arg1, arg2));
39+
}
40+
if (conditionType.equals("hasObjvar"))
41+
{
42+
return debugResult(ctx, conditionType, arg1, arg2, hasObjVar(ctx.player, arg1));
43+
}
44+
if (conditionType.equals("notHasObjvar"))
45+
{
46+
return debugResult(ctx, conditionType, arg1, arg2, !hasObjVar(ctx.player, arg1));
47+
}
48+
if (conditionType.equals("objvarEquals"))
49+
{
50+
return debugResult(ctx, conditionType, arg1, arg2, hasObjVar(ctx.player, arg1) && getStringObjVar(ctx.player, arg1).equals(arg2));
51+
}
52+
if (conditionType.equals("faction"))
53+
{
54+
String playerFaction = factions.getFaction(ctx.player);
55+
return debugResult(ctx, conditionType, arg1, arg2, playerFaction != null && playerFaction.equals(arg1));
56+
}
57+
if (conditionType.equals("hasSkill"))
58+
{
59+
return debugResult(ctx, conditionType, arg1, arg2, hasSkill(ctx.player, arg1));
60+
}
61+
if (conditionType.equals("hasEp3"))
62+
{
63+
return debugResult(ctx, conditionType, arg1, arg2, features.hasEpisode3Expansion(ctx.player));
64+
}
65+
if (conditionType.equals("isGm"))
66+
{
67+
return debugResult(ctx, conditionType, arg1, arg2, hasObjVar(ctx.player, "gm"));
68+
}
69+
LOG("conversation_manager", "Unknown condition type '" + conditionType + "' for conversation '" + ctx.conversationId + "'");
70+
debug(ctx, "unknown condition type=" + conditionType + " arg1=" + arg1 + " arg2=" + arg2);
71+
return false;
72+
}
73+
74+
public boolean passesNode(conversation_context ctx, conversation_node node) throws InterruptedException
75+
{
76+
return passes(ctx, node.conditionType, node.conditionArg1, node.conditionArg2);
77+
}
78+
79+
public boolean passesResponse(conversation_context ctx, conversation_response response) throws InterruptedException
80+
{
81+
return passes(ctx, response.conditionType, response.conditionArg1, response.conditionArg2);
82+
}
83+
84+
public boolean debugResult(conversation_context ctx, String conditionType, String arg1, String arg2, boolean result) throws InterruptedException
85+
{
86+
debug(ctx, "condition type=" + conditionType + " arg1=" + arg1 + " arg2=" + arg2 + " result=" + result);
87+
return result;
88+
}
89+
90+
public void debug(conversation_context ctx, String message) throws InterruptedException
91+
{
92+
if (ctx == null || !isIdValid(ctx.npc) || !isIdValid(ctx.player))
93+
{
94+
return;
95+
}
96+
if (!hasObjVar(ctx.npc, "conversation_manager.debug"))
97+
{
98+
return;
99+
}
100+
if (!getBooleanObjVar(ctx.npc, "conversation_manager.debug"))
101+
{
102+
return;
103+
}
104+
sendSystemMessage(ctx.player, "[conversation_manager] " + message, null);
105+
}
106+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package script.systems.conversation_manager;
2+
3+
import script.obj_id;
4+
5+
public class conversation_context
6+
{
7+
public obj_id npc;
8+
public obj_id player;
9+
public String conversationId;
10+
public String table;
11+
public String stringFile;
12+
13+
public conversation_context(obj_id npc, obj_id player, conversation_definition definition)
14+
{
15+
this.npc = npc;
16+
this.player = player;
17+
this.conversationId = definition.conversationId;
18+
this.table = definition.table;
19+
this.stringFile = definition.stringFile;
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package script.systems.conversation_manager;
2+
3+
public class conversation_definition
4+
{
5+
public String conversationId;
6+
public String table;
7+
public String stringFile;
8+
public conversation_node[] nodes;
9+
public conversation_response[] responses;
10+
public conversation_action[] actions;
11+
12+
public conversation_definition()
13+
{
14+
nodes = new conversation_node[0];
15+
responses = new conversation_response[0];
16+
actions = new conversation_action[0];
17+
}
18+
}

0 commit comments

Comments
 (0)