-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoryProgressionSystem.asc
250 lines (226 loc) · 8.9 KB
/
StoryProgressionSystem.asc
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#define STORY_PARTS 2000
// Story progression system, used with linear story. Set scene to be played when interacting with specific object/hotspot/character etc.
/*
Ways to access data with id 2:
character[2];
character[2].Room;
object[2];
hotspot[2];
*/
int currentStoryProgression = 0;
//objects & hotspots in current room
Dictionary* storyObjects;
Dictionary* storyHotspots;
//not storing characters, because those are global
Dictionary* storyObjectDefaultText;
Dictionary* storyHotspotDefaultText;
Dictionary* defaultDialogsPerCharacter;//charId, dialogId
int freeStorySlot = 0;//used to fill the array at correct index since there is no "push"
StoryProgression Story[STORY_PARTS];
bool isInRange(int min, int max, int value){
if(value >= min && value <= max) return true;
return false;
}
//Once I figure out how to use custom events so I can invoke them, then I would allow for custom functions to handle the state
//Bur for now, we have to do all in here:
//Used with Objects/Hotspots to set their custom text.
//This will repeat each time the story is executed and will keep repeating certain actions if the conditions match.
function UpdateGameState(){
int storyId = Story[currentStoryProgression].ID;
int objectId = Story[currentStoryProgression].objectId;
int hotspotId = Story[currentStoryProgression].hotspotId;
int characterId = Story[currentStoryProgression].characterId;
int roomId = Story[currentStoryProgression].roomId;
int dialogId = Story[currentStoryProgression].dialogId;
String cutAwayName = Story[currentStoryProgression].cutAwayName;
//Default setup for all objects/hotspots
if(isInRange(1000, 1000, storyId)){
//set objects default text
storyObjectDefaultText.Set("oBoots", "Why is this floating boot doing here?!!");
//set hotspots default text
storyHotspotDefaultText.Set("Couch hotspot", "I should not touch this couch");
}
if(isInRange(1002, 1002, storyId)){
String bootObj = storyObjects.Get("oBoots");
int bootId = bootObj.AsInt;
object[bootId].Move(200, 100, 10, eNoBlock, eAnywhere);
storyObjectDefaultText.Set("oBoots", "Weird...");
}
if(isInRange(1003, 1003, storyId)){
cEgo.Walk(50, cEgo.y, eBlock, eWalkableAreas);
}
}
GUIControl *questLabel;
void StoryProgression::Init(){
this.objectId = -1;
this.hotspotId = -1;
this.characterId = -1;
this.roomId = -1;
this.dialogId = -1;
this.cutAwayName = "";
this.interactionType = eInteract;
this.ID = -1;
}
void StoryProgression::Execute(){
//play the story i.e. dialog
if(this.dialogId >= 0) dialog[this.dialogId].Start();
currentStoryProgression++;//progress the story.
UpdateGameState();
}
static void StoryProgression::Add(LocationType type, int typeId, int storyId, int dialogId, String cutAwayName, int roomId, InteractionType interactionType, InventoryItem *item){
if(freeStorySlot >= STORY_PARTS - 1) {
Display("Reached story limit, can't add more");
return;
}
Story[freeStorySlot].Init();
Story[freeStorySlot].roomId = roomId;
Story[freeStorySlot].dialogId = dialogId;
Story[freeStorySlot].ID = storyId;
Story[freeStorySlot].cutAwayName = cutAwayName;
Story[freeStorySlot].interactionType = interactionType;
Story[freeStorySlot].item = item;
if(item != null) Story[freeStorySlot].item = item;
if(type == eLocationCharacter){
Story[freeStorySlot].characterId = typeId;
}
else if(type == eLocationHotspot){
Story[freeStorySlot].hotspotId = typeId;
}
else if(type == eLocationObject){
Story[freeStorySlot].objectId = typeId;
}
freeStorySlot++;//increment story slot before next one is added to the array.
}
static void StoryProgression::AddDefaultDialogs(Character *characterRef, Dialog *dialogRef){
defaultDialogsPerCharacter.Set(String.Format("%d",characterRef.ID), String.Format("%d",dialogRef.ID));
}
static void StoryProgression::InitializeQuestSystem(GUIControl *label){
questLabel = label;
}
static void StoryProgression::UpdateQuest(){
if(questLabel == null) return;
questLabel.AsLabel.Text = "";
String nameTxt = "";
int id = currentStoryProgression;
if(Story[id].characterId >= 0){
nameTxt = character[Story[id].characterId].Name;
}
if(Story[id].hotspotId >= 0){
nameTxt = hotspot[Story[id].hotspotId].Name;
}
if(Story[id].objectId >= 0){
nameTxt = object[Story[id].objectId].Name;
}
if(Story[id].item != null){
questLabel.AsLabel.Text = questLabel.AsLabel.Text.Append(String.Format("Use %s on ", Story[id].item.Name));
}
else{
questLabel.AsLabel.Text = questLabel.AsLabel.Text.Append("Click on ");
}
questLabel.AsLabel.Text = questLabel.AsLabel.Text.Append(nameTxt);
}
static int StoryProgression::GetCurrentStoryId(){
return Story[currentStoryProgression].ID;
}
static bool StoryProgression::IsStoryInRange(int min, int max){
return isInRange(min, max, StoryProgression.GetCurrentStoryId());
}
//===========================================================================
//
// game_start()
// Setup the Story array and Init it's values.
//
//===========================================================================
function game_start(){
//Story = new Story[STORY_PARTS];
for(int i = 0; i < STORY_PARTS; i++){
Story[i].Init();
}
defaultDialogsPerCharacter = Dictionary.Create(eSorted);
}
//===========================================================================
//
// on_mouse_click (MouseButton button)
// Handle the event of player interacting with objects/hotspots/characters
// Used with the story progression system
//
//===========================================================================
function on_mouse_click (MouseButton button)
{
if(button != eMouseLeft) return;
LocationType locationType = GetLocationType(mouse.x, mouse.y);
//hotspot interaction + use item
if(locationType == eLocationHotspot)
{
Hotspot *hotspotRef = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
int hotspotId = Story[currentStoryProgression].hotspotId;
int roomId = Story[currentStoryProgression].roomId;
bool haveItem = true;
InventoryItem *itemNeeded = Story[currentStoryProgression].item;
if(player.ActiveInventory != itemNeeded) haveItem = false;
if(hotspotId == hotspotRef.ID && roomId == player.Room && haveItem){
Story[currentStoryProgression].Execute();
}
else {
String text = storyHotspotDefaultText.Get(hotspotRef.Name);
if(text != null){
player.Say(text);
}
}
}
//object interaction + use item
if(locationType == eLocationObject)
{
Object *objectRef = Object.GetAtScreenXY(mouse.x, mouse.y);
int objectId = Story[currentStoryProgression].objectId;
int roomId = Story[currentStoryProgression].roomId;
bool haveItem = true;
InventoryItem *itemNeeded = Story[currentStoryProgression].item;
if(player.ActiveInventory != itemNeeded) haveItem = false;
if(objectId == objectRef.ID && roomId == player.Room && haveItem){
Story[currentStoryProgression].Execute();
}
else {
String text = storyObjectDefaultText.Get(objectRef.Name);
if(text != null){
player.Say(text);
}
}
}
//character interaction + use item
if(locationType == eLocationCharacter)
{
Character *characterRef = Character.GetAtScreenXY(mouse.x, mouse.y);
int characterId = Story[currentStoryProgression].characterId;
bool haveItem = true;
InventoryItem *itemNeeded = Story[currentStoryProgression].item;
if(player.ActiveInventory != itemNeeded) haveItem = false;
//Not comparing to a room since characters can be anywhere.
if(characterId == characterRef.ID && haveItem){
Story[currentStoryProgression].Execute();
}
else{
String dialogId = defaultDialogsPerCharacter.Get(String.Format("%d",characterRef.ID));
if(dialogId != null){
dialog[dialogId.AsInt].Start();
}
}
}
StoryProgression.UpdateQuest();
}
function on_event (EventType event, int data){
if(event == eEventEnterRoomBeforeFadein){
storyObjects = Dictionary.Create(eSorted);
storyObjectDefaultText = Dictionary.Create(eSorted);
storyHotspots = Dictionary.Create(eSorted);
storyHotspotDefaultText = Dictionary.Create(eSorted);
for(int i = 0; i < Room.ObjectCount; i++){
storyObjects.Set(object[i].Name, String.Format("%d",object[i].ID));
}
for(int i = 0; i < AGS_MAX_HOTSPOTS; i++){
storyHotspots.Set(hotspot[i].Name, String.Format("%d",hotspot[i].ID));
}
StoryProgression.UpdateQuest();
UpdateGameState();
}
}