-
Notifications
You must be signed in to change notification settings - Fork 0
/
PartyManager.cs
433 lines (377 loc) · 13.3 KB
/
PartyManager.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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
using UnityEngine;
using System.Collections.Generic;
using PixelCrushers.DialogueSystem;
using UnityEngine.SceneManagement;
public class PartyManager : MonoBehaviour
{
private int portraitWidth;
private int screenWidth;
private int screenHeight;
private int buttonHeight;
private Vector3 pos01;
private Vector3 pos02;
private Vector3 pos03;
private Vector3 pos04;
private Vector3 pos05;
private GameController gameController;
private List<string> inParty = new List<string>();
private List<string> members = new List<string>();
private Texture2D inParty1;
private Texture background;
private GUISkin mySkin;
private Camera mainCamera;
void OnEnable()
{
mainCamera = Camera.main;
mainCamera.GetComponent<MouseOrbitImp>().enabled = false;
mainCamera.GetComponent<RtsCameraImp>().enabled = false;
mainCamera.GetComponent<RtsCameraMouse>().enabled = false;
gameController = GetComponent<GameController>();
gameController.activePC.GetComponent<TargetActivePC>().enabled = false;
GetLists();
// Debug.Log("On");
portraitWidth = (int)(Screen.width * 0.11f);
screenHeight = (int)(Screen.height);
screenWidth = (int)(Screen.width);
buttonHeight = (int)(Screen.height * 0.06f);
background = GetComponent<GeneralWindow>().background;
mySkin = GetComponent<GeneralWindow>().mySkin;
gameController.inDialogue = true;
GetComponent<CameraMap>().TurnOffAllQuests();
gameController.playerConversation.GetComponent<PlayerConversation>().OnConversationStart();
GetComponent<DisplayPortraits>().enabled = false;
gameController.inDialogue = true;
}
void OnGUI ()
{
GUI.skin = mySkin;
GUI.DrawTexture (new Rect(0, 0, screenWidth, screenHeight), background);
GUI.Label(new Rect(Screen.width * 0.15f, Screen.height *0.10f, Screen.width * 0.75f, Screen.height *0.08f), "CHARACTERS IN GAME PARTY");
if (GUI.Button(new Rect(Screen.width * 0.15f, Screen.height * 0.20f, portraitWidth, portraitWidth), inParty1))
{
DialogueManager.ShowAlert("Main character may not leave the party");
}
int lineNo = 1;
for (int cnt = 1; cnt < inParty.Count; cnt++)
{
if (GUI.Button(new Rect(Screen.width * 0.15f + (portraitWidth * lineNo), Screen.height * 0.20f, portraitWidth, portraitWidth), (Texture2D)(Resources.Load("Portraits/" + inParty[cnt]))))
{
string toRemove = inParty[cnt];
members.Add(toRemove);
inParty.RemoveAt (cnt);
}
lineNo++;
}
GUI.Label(new Rect(Screen.width * 0.15f, Screen.height * 0.45f, Screen.width * 0.75f, Screen.height * 0.08f), "ALLIED READY TO JOIN YOUR PARTY");
int lineNo2 = 0;
if (members.Count > 0)
{
for (int cnt = 0; cnt < members.Count; cnt++)
{
if (GUI.Button(new Rect(Screen.width * 0.15f + (portraitWidth * lineNo2), Screen.height * 0.50f, portraitWidth, portraitWidth), (Texture2D)(Resources.Load("Portraits/" + members[cnt]))))
{
if (inParty.Count < 5)
{
string toRemove = members[cnt];
inParty.Add(toRemove);
members.RemoveAt(cnt);
}
else
{
DialogueManager.ShowAlert("Maximum 5 party members");
}
}
lineNo2++;
}
}
if (GUI.Button(new Rect(Screen.width * 0.15f, Screen.height * 0.85f, portraitWidth, buttonHeight), "DONE"))
{
DoneAndExit();
}
}
private void GetLists ()
{
inParty.Clear();
members.Clear();
string listMembers = DialogueLua.GetVariable("listMembers").AsString;
// string listMembers = "Oleg";
string listInParty = DialogueLua.GetVariable("PCList").AsString;
Debug.Log(listInParty);
string [] arrayMembers = listMembers.Split(new string[] { "*" }, System.StringSplitOptions.None);
string [] arrayInParty = listInParty.Split(new string[] { "*" }, System.StringSplitOptions.None);
inParty.Add("Player");
inParty1 = (Texture2D)(Resources.Load("Portraits/Player/Human/Female"));
foreach (string st in arrayInParty)
{
if (st != "null" && st != "")
{
if (st != "Player")
{
inParty.Add(st);
}
}
// Debug.Log(st);
}
if (arrayMembers.Length > 0)
{
if (arrayMembers.Length == 1 && arrayMembers[0] == "null")
{
members.Clear();
}
else
{
for (int cnt = 0; cnt < arrayMembers.Length; cnt++)
{
if (arrayMembers[cnt] != "null")
{
if (arrayMembers[cnt] == "Player" || arrayMembers[cnt] == "Dylan")
{
}
else
{
members.Add(arrayMembers[cnt]);
}
}
else
{
members.Clear();
}
}
}
}
else
{
members.Clear();
Debug.Log(members.Count);
}
}
public void AddNewMember(string newMember)
{
string listMembers = DialogueLua.GetVariable("listMembers").AsString;
if (listMembers == "" || listMembers == null || listMembers == "null")
{
listMembers = newMember;
// Debug.Log(listMembers);
}
else
{
listMembers = listMembers + "*" + newMember;
}
DialogueLua.SetVariable("listMembers", listMembers);
DialogueLua.SetActorField(newMember, "vanguard", "Yes");
Debug.Log(listMembers);
}
private void DoneAndExit ()
{
Debug.Log("DoneAndExit");
Time.timeScale = 1;
SavePCList();
SaveMembers();
// Invoke("AutoSave", 0.05f);
Invoke("InstantiateCharacters", 0.1f);
}
private void SavePCList ()
{
string pcList = "Player";
foreach (string st in inParty)
{
if (st != "Player")
{
pcList = pcList + "*" + st;
}
DialogueLua.SetActorField(st, "inParty", "No");
}
Debug.Log(pcList);
DialogueLua.SetVariable("PCList", pcList);
pos01 = gameController.player.transform.position;
if (gameController.PC2 != null && gameController.PC2 != "DummyPlayer")
{
pos02 = gameController.PC2Obj.transform.position;
}
if (gameController.PC3 != null && gameController.PC3 != "DummyPlayer")
{
pos03 = gameController.PC3Obj.transform.position;
}
if (gameController.PC4 != null && gameController.PC4 != "DummyPlayer")
{
pos04 = gameController.PC4Obj.transform.position;
}
if (gameController.PC5 != null && gameController.PC5 != "DummyPlayer")
{
pos05 = gameController.PC5Obj.transform.position;
}
}
private void SaveMembers ()
{
string memberList = null;
if (members.Count > 0)
{
foreach (string st in members)
{
if (memberList == null)
{
memberList = st;
}
else if (st != "nil" && st != "null")
{
memberList = memberList + "*" + st;
}
DialogueLua.SetActorField(st, "inParty", "No");
}
Debug.Log(memberList);
DialogueLua.SetVariable("listMembers", memberList);
}
else
{
DialogueLua.SetVariable("listMembers", "null");
}
}
private void InstantiateCharacters()
{
Debug.Log("InstantiateCharacter");
foreach (GameObject go in gameController.players)
{
go.name = go.name + "Obsolete";
go.SetActive(false);
}
GetComponent<LoadGame>().pos01 = pos01;
GetComponent<LoadGame>().pos02 = pos02;
GetComponent<LoadGame>().pos03 = pos03;
GetComponent<LoadGame>().pos04 = pos04;
GetComponent<LoadGame>().pos05 = pos05;
GetComponent<LoadGame>().LoadPCList();
EndExit();
}
private void EndExit()
{
gameController.inDialogue = false;
GetComponent<CameraMap>().CheckActiveQuests();
gameController.playerConversation.GetComponent<PlayerConversation>().OnConversationEnd();
GetComponent<GeneralWindow>().LoadPortraits();
// gameController.activePC.GetComponent<TargetActivePC>().enabled = false;
Time.timeScale = 1;
// GetComponent<GeneralWindow>().LoadPortraits();
this.enabled = false;
/*
foreach (GameObject go in gameController.players)
{
if (go.name != "Player")
{
go.GetComponent<TargetActivePC>().target.SetActive(false);
}
}*/
}
private void AddjustPositions ()
{
gameController.player.transform.position = pos01;
if (gameController.PC2 != null && gameController.PC2 != "DummyPlayer")
{
gameController.PC2Obj.transform.position = pos02;
}
if (gameController.PC3 != null && gameController.PC3 != "DummyPlayer")
{
gameController.PC3Obj.transform.position = pos03;
}
if (gameController.PC4 != null && gameController.PC4 != "DummyPlayer")
{
gameController.PC3Obj.transform.position = pos03;
}
if (gameController.PC5 != null && gameController.PC5 != "DummyPlayer")
{
gameController.PC3Obj.transform.position = pos03;
}
}
public void CheckAndRemove (string member)
{
bool inParty = false;
if (gameController == null)
{
OnEnable();
}
foreach (GameObject go in gameController.players)
{
if (go.name == "member")
{
inParty = true;
}
}
RemoveMember(member, inParty);
}
public void RemoveMember (string member, bool intantiateChanges)
{
string tempInParty = null;
string tempMembers = null;
string listMembers = DialogueLua.GetVariable("listMembers").AsString;
string listInParty = DialogueLua.GetVariable("PCList").AsString;
string[] arrayMembers = listMembers.Split(new string[] { "*" }, System.StringSplitOptions.None);
string[] arrayInParty = listInParty.Split(new string[] { "*" }, System.StringSplitOptions.None);
Debug.Log(member + "/" + listMembers + listInParty);
foreach (string st in arrayInParty)
{
if (st != member)
{
if (tempInParty == null)
{
tempInParty = st;
}
else
{
tempInParty = tempInParty + "*" + st;
}
}
}
DialogueLua.SetVariable("PCList", tempInParty);
if (arrayMembers.Length == 1 && arrayMembers[0] == "null")
{
}
else
{
foreach (string st in arrayMembers)
{
Debug.Log(st);
if (st != member)
{
if (tempMembers == null)
{
tempMembers = st;
}
else
{
tempMembers = tempMembers + "*" + st;
}
}
else
{
if (arrayMembers.Length == 1)
{
tempMembers = "null";
}
}
DialogueLua.SetVariable("listMembers", tempMembers);
}
Invoke("InvokeList", 0.1f);
}
if (intantiateChanges == true)
{
DoneAndExit();
}
}
private void InvokeList ()
{
Debug.Log(DialogueLua.GetVariable("listMembers").AsString);
Debug.Log(DialogueLua.GetVariable("PCList").AsString);
}
public void InvokeActiveSelf ()
{
InvokeRepeating("ActiveSelf", 1, 0.5f);
}
private void ActiveSelf ()
{
if (GetComponent<DisplayToolBar>().enabled == true)
{
Debug.Log("Active");
this.enabled = true;
CancelInvoke("ActiveSelf");
}
}
}