-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMrTS_QuestLog.js
890 lines (795 loc) · 25.3 KB
/
MrTS_QuestLog.js
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
//=============================================================================
// MrTS_QuestLog.js
//=============================================================================
/*:
* @plugindesc Tracks quests, awards players for completing them.
* @author Mr. Trivel
*
* @param --Icons--
* @default
*
* @param All Quests Icon
* @desc Icon ID for all quests tab.
* Default: 93
* @default 93
*
* @param Ongoing Quests Icon
* @desc Icon ID for ongoing quests.
* Default: 92
* @default 92
*
* @param Completed Quests Icon
* @desc Icon ID for completed quests tab.
* Default: 90
* @default 90
*
* @param Failed Quests Icon
* @desc Icon ID for failed quests tab.
* Default: 91
* @default 91
*
* @param Gold Icon
* @desc Icon ID for gold rewards.
* Default: 313
* @default 313
*
* @param --Text--
* @default
*
* @param Description Text
* @desc Description text.
* Default: Description
* @default Description
*
* @param Objective Text
* @desc Current Objective text.
* Default: Current Objective
* @default Current Objective
*
* @param Rewards Text
* @desc Rewards Text
* Default: Rewards
* @default Rewards
*
* @param Quest Log Text
* @desc Quest Log Text in menu.
* Default: Quest Log
* @default Quest Log
*
* @param No Objective Text
* @desc Text to show in objectives when quest failed or finished.
* Default: - No Objectives
* @default - No Objectives
*
* @param --Colors--
* @default
*
* @param Started Color
* @desc Started quest color.
* Default: #FFFFFF
* @default #FFFFFF
*
* @param Completed Color
* @desc Completed quest color.
* Default: #11FF11
* @default #11FF11
*
* @param Failed Color
* @desc Failed quest color.
* Default: #FF1111
* @default #FF1111
*
* @param --Windows--
* @default
*
* @param Quest Log Menu
* @desc Is Quest log accessible from menu? True/False
* Default: True
* @default True
*
* @param Quest Category X
* @desc X Position of Quest Category Window
* Default: Graphics.boxWidth/2 - 816/2
* @default Graphics.boxWidth/2 - 816/2
*
* @param Quest Category Y
* @desc Y Position of Quest Category Window
* Default: Graphics.boxHeight/2 - 624/2
* @default Graphics.boxHeight/2 - 624/2
*
* @param Quest Category Width
* @desc Quest Category Window's Width
* Default: 266
* @default 266
*
* @param Quest Category Height
* @desc Quest Category Window's Height
* Default: 72
* @default 72
*
* @param Quest List X
* @desc X Position of Quest List
* Default: Graphics.boxWidth/2 - 816/2
* @default Graphics.boxWidth/2 - 816/2
*
* @param Quest List Y
* @desc Y Position of Quest List
* Default: Graphics.boxHeight/2 - 624/2 + 72
* @default Graphics.boxHeight/2 - 624/2 + 72
*
* @param Quest List Width
* @desc Width of Quest List
* Default: 266
* @default 266
*
* @param Quest List Height
* @desc Height of Quest List
* Default: 624-72
* @default 624-72
*
* @param Description X
* @desc X Position of Description window.
* Default: Graphics.boxWidth/2 - 816/2 + 266
* @default Graphics.boxWidth/2 - 816/2 + 266
*
* @param Description Y
* @desc Y Position of Description window.
* Default: Graphics.boxHeight/2 - 624/2
* @default Graphics.boxHeight/2 - 624/2
*
* @param Description Width
* @desc Description window Width.
* Default: 816-266
* @default 816-266
*
* @param Description Height
* @desc Description window Height.
* Default: 624
* @default 624
*
* @help
* --------------------------------------------------------------------------------
* Terms of Use
* --------------------------------------------------------------------------------
* Don't remove the header or claim that you wrote this plugin.
* Credit Mr. Trivel if using this plugin in your project.
* Free for commercial and non-commercial projects.
* --------------------------------------------------------------------------------
* Version 1.0a
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* How to Set Up Quests
* --------------------------------------------------------------------------------
* Create a new file in Data folder:
* Quests.json
*
* Quests file will hold data regarding quests. I highly recommend checking sample
* that file that is located in the demo of this plugin
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Quests.json
* --------------------------------------------------------------------------------
* Quest object looks like this:
* {
* "ID": 1337,
* "Name": "Tutorial Island 1",
* "IconID": 83,
* "Description": "The island on a tutorial or the tutorial on an island.",
* "Rewards": [Reward Object,
* Reward Object,
* Reward Object,
* ...],
* "Steps": ["This is step 1",
* "This shall be step II",
* "And this is not the last step.",
* ...]
* }
*
* You can use special characters in Steps text, just add extra backslash.
* E.g. "Collect rare weapons - \\V[20] from 100"
*
* Reward object looks like this:
* {
* "Type": "weapon"
* "ID": 99999,
* "Amount": 99
* "Text": "Text for text reward type"
* }
* Type being "weapon", "armor", "item", "gold", "exp", "text"
* "gold", "exp" and "text" types don't need "ID".
* If ID is specified for exp, actor of that ID will get the exp.
*
*
* File itself should look like this:
* [
* null,
* Quest Object,
* Quest Object,
* ...
* Quest Object
* ]
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* QuestLog Start ID - Starts quest
* QuestLog Advance ID - Advances quest by a single step
* QuestLog SetStep ID STEP - Sets quest to a specific step
* QuestLog Finish ID - Finishes quest and gives rewards
* QuestLog Fail ID - Fails a quest
* QuestLog Enter - Enters quest log scene
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Script Calls
* --------------------------------------------------------------------------------
* $gameSystem.getQuestStep(id) - returns step number of a quest
* $gameSystem.isQuestStarted(id) - returns true/false is quest started
* $gameSystem.isQuestFinished(id) - returns true/false is quest finished
* $gameSystem.isQuestFailed(id) - returns true/false is quest failed
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.0 - Release
* 1.0a - Window size bug fix.
*/
var $dataQuests = null;
DataManager._databaseFiles.push({name: '$dataQuests', src: 'Quests.json'});
(function() {
var parameters = PluginManager.parameters('MrTS_QuestLog');
var paramAllQuestsIcon = Number(parameters['All Quests Icon'] || 93);
var paramCompletedQuestsIcon = Number(parameters['Completed Quests Icon'] || 90);
var paramFailedQuestsIcon = Number(parameters['Failed Quests Icon'] || 91);
var paramOngoingQuestsIcon = Number(parameters['Ongoing Quests Icon'] || 92);
var paramGoldIcon = Number(parameters['Gold Icon'] || 313);
var paramDescriptionText = String(parameters['Description Text'] || "Description");
var paramObjectiveText = String(parameters['Objective Text'] || "Current Objective");
var paramRewardsText = String(parameters['Rewards Text'] || "Rewards");
var paramQuestLogText = String(parameters['Quest Log Text'] || "Quest Log");
var paramNoObjectivesText = String(parameters['No Objectives Text'] || "- No Objectives");
var paramStartedColor = String(parameters['Started Color'] || "#FFFFFF");
var paramCompletedColor = String(parameters['Completed Color'] || "#11FF11");
var paramFailedColor = String(parameters['Failed Color'] || "#FF1111");
var paramQuestLogMenu = (parameters['Quest Log Menu'] || "True").toLowerCase() === "true";
var paramQuestCategoryX = String(parameters['Quest Category X'] || "Graphics.boxWidth/2 - 816/2");
var paramQuestCategoryY = String(parameters['Quest Category Y'] || "Graphics.boxHeight/2 - 624/2");
var paramQuestCategoryWidth = String(parameters['Quest Category Width'] || "266");
var paramQuestCategoryHeight = String(parameters['Quest Category Height'] || "624");
var paramQuestListX = String(parameters['Quest List X'] || "Graphics.boxWidth/2 - 816/2");
var paramQuestListY = String(parameters['Quest List Y'] || "Graphics.boxHeight/2 - 624/2 + 72");
var paramQuestListWidth = String(parameters['Quest List Width'] || "266");
var paramQuestListHeight = String(parameters['Quest List Height'] || "624 - 72");
var paramQuestDescriptionX = String(parameters['Description X'] || "Graphics.boxWidth/2 - 816/2 + 266");
var paramQuestDescriptionY = String(parameters['Description Y'] || "Graphics.boxHeight/2 - 624/2");
var paramQuestDescriptionWidth = String(parameters['Description Width'] || "816-266");
var paramQuestDescriptionHeight = String(parameters['Description Height'] || "624");
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "questlog") {
switch (args[0].toUpperCase())
{
case 'START':
{
$gameSystem.startQuest(Number(args[1]));
} break;
case 'ADVANCE':
{
var id = Number(args[1]);
var step = $gameSystem.getQuestStep(id);
$gameSystem.setQuestStep(id, step+1);
} break;
case 'SETSTEP':
{
var id = Number(args[1]);
var step = Number(args[2]);
$gameSystem.setQuestStep(id, step);
} break;
case 'FINISH':
{
$gameSystem.finishQuest(Number(args[1]));
} break;
case 'FAIL':
{
$gameSystem.failQuest(Number(args[1]));
} break;
case 'ENTER':
{
SceneManager.push(Scene_QuestLog);
} break;
}
}
};
//--------------------------------------------------------------------------
// Game_System
//
var _Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_Game_System_initialize.call(this);
this.initializeQuestLog();
};
Game_System.prototype.initializeQuestLog = function(first_argument) {
this._quests = [];
for (var i = 0; i < $dataQuests.length; i++) {
if (!$dataQuests[i]) continue;
var quest = {};
var data = $dataQuests[i];
quest.ID = data["ID"];
quest.name = data["Name"];
quest.iconId = data["IconID"];
quest.description = data["Description"];
quest.rewards = data["Rewards"];
quest.steps = data["Steps"];
quest.currentStep = 0;
quest.started = false;
quest.finished = false;
quest.failed = false;
this._quests[i] = quest;
}
};
Game_System.prototype.getAllQuests = function() {
var quests = [];
for (var i = 0; i < this._quests.length; i++) {
if (!this._quests[i]) continue;
if (this._quests[i].started || this._quests[i].finished || this._quests[i].failed)
quests.push(i);
}
return quests;
};
Game_System.prototype.getStartedQuests = function() {
var quests = [];
for (var i = 0; i < this._quests.length; i++) {
if (!this._quests[i]) continue;
if (this._quests[i].started && !this._quests[i].finished && !this._quests[i].failed)
quests.push(i);
}
return quests;
};
Game_System.prototype.getCompletedQuests = function() {
var quests = [];
for (var i = 0; i < this._quests.length; i++) {
if (!this._quests[i]) continue;
if (this._quests[i].finished)
quests.push(i);
}
return quests;
};
Game_System.prototype.getFailedQuests = function() {
var quests = [];
for (var i = 0; i < this._quests.length; i++) {
if (!this._quests[i]) continue;
if (this._quests[i].failed)
quests.push(i);
}
return quests;
};
Game_System.prototype.getQuest = function(id) {
return this._quests[id];
};
Game_System.prototype.getQuestStep = function(id) {
if (!this._quests[id]) {
console.warn("FAILED TO GET QUEST STEP! Quest with ID " + id + " does not exist!");
return -1;
}
return this._quests[id].currentStep;
};
Game_System.prototype.isQuestStarted = function(id) {
if (!this._quests[id]) {
console.warn("FAILED TO GET IS QUEST STARTED! Quest with ID " + id + " does not exist!");
return false;
}
return this._quests[id].started;
};
Game_System.prototype.isQuestFinished = function(id) {
if (!this._quests[id]) {
console.warn("FAILED TO GET IS QUEST FINISHED! Quest with ID " + id + " does not exist!");
return false;
}
return this._quests[id].finished;
};
Game_System.prototype.isQuestFailed = function(id) {
if (!this._quests[id]) {
console.warn("FAILED TO GET IS QUEST FAILED! Quest with ID " + id + " does not exist!");
return false;
}
return this._quests[id].failed;
};
Game_System.prototype.startQuest = function(id) {
if (!this._quests[id]) {
console.warn("FAILED TO START QUEST! Quest with ID " + id + " does not exist!");
return;
}
this._quests[id].started = true;
};
Game_System.prototype.finishQuest = function(id) {
if (!this._quests[id]) {
console.warn("FAILED TO FINISh QUEST! Quest with ID " + id + " does not exist!");
return;
}
this._quests[id].finished = true;
rewards = this._quests[id].rewards;
for (var i = 0; i < rewards.length; i++) {
switch (rewards[i].Type)
{
case 'weapon':
{
var amount = rewards[i].Amount;
$gameParty.gainItem($dataWeapons[rewards[i].ID], amount);
} break;
case 'armor':
{
var amount = rewards[i].Amount;
$gameParty.gainItem($dataArmors[rewards[i].ID], amount);
} break;
case 'item':
{
var amount = rewards[i].Amount;
$gameParty.gainItem($dataItems[rewards[i].ID], amount);
} break;
case 'gold':
{
var amount = rewards[i].Amount;
$gameParty.gainGold(amount);
} break;
case 'exp':
{
var amount = rewards[i].Amount;
var id = rewards[i].ID;
if (id) {
$gameActors.actor(id).gainExp(amount);
}
else {
$gameParty.allMembers().forEach(function(actor) {
actor.gainExp(amount);
});
}
} break;
}
}
};
Game_System.prototype.failQuest = function(id) {
if (!this._quests[id]) {
console.warn("FAILED TO FAIL QUEST! Quest with ID " + id + " does not exist!");
return;
}
this._quests[id].failed = true;
};
Game_System.prototype.setQuestStep = function(id, step) {
if (!this._quests[id]) {
console.warn("FAILED TO SET QUEST TO STEP " + step + "! Quest with ID " + id + " does not exist!");
return;
}
if (!this._quests[id].steps[step]) {
console.warn("FAILED TO SET QUEST TO STEP " + step + "! Step does not exist! Did you mean to finish the quest instead?");
return;
}
this._quests[id].currentStep = step;
};
//--------------------------------------------------------------------------
// Scene_QuestLog
//
// Scene which displays log with quests.
function Scene_QuestLog() {
this.initialize.apply(this, arguments);
};
Scene_QuestLog.prototype = Object.create(Scene_MenuBase.prototype);
Scene_QuestLog.prototype.constructor = Scene_QuestLog;
Scene_QuestLog.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_QuestLog.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createWindowLayer();
};
Scene_QuestLog.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createCategoryWindow();
this.createListWindow();
this.createInfoWindow();
};
Scene_QuestLog.prototype.createCategoryWindow = function() {
var wx = eval(paramQuestCategoryX);
var wy = eval(paramQuestCategoryY);
var ww = eval(paramQuestCategoryWidth);
var wh = eval(paramQuestCategoryHeight);
this._categoryWindow = new Window_QuestLogCategory(wx, wy, ww, wh);
this._categoryWindow.setHandler('ok', this.onCategoryOk.bind(this));
this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
this.addWindow(this._categoryWindow);
this._categoryWindow.activate();
this._categoryWindow.select(0);
};
Scene_QuestLog.prototype.createListWindow = function() {
var wx = eval(paramQuestListX);
var wy = eval(paramQuestListY);
var ww = eval(paramQuestListWidth);
var wh = eval(paramQuestListHeight);
this._listWindow = new Window_QuestLogList(wx, wy, ww, wh);
this._listWindow.setHandler('cancel', this.onListCancel.bind(this));
this.addWindow(this._listWindow);
};
Scene_QuestLog.prototype.createInfoWindow = function() {
var wx = eval(paramQuestDescriptionX);
var wy = eval(paramQuestDescriptionY);
var ww = eval(paramQuestDescriptionWidth);
var wh = eval(paramQuestDescriptionHeight);
this._infoWindow = new Window_QuestLogDescription(wx, wy, ww, wh);
this.addWindow(this._infoWindow);
this._listWindow.setDescriptionWindow(this._infoWindow);
};
Scene_QuestLog.prototype.onCategoryOk = function() {
this._listWindow.activate();
this._listWindow.select(0);
};
Scene_QuestLog.prototype.onListCancel = function() {
this._listWindow.deselect();
this._categoryWindow.activate();
};
Scene_QuestLog.prototype.update = function() {
Scene_MenuBase.prototype.update.call(this);
if (this._cIndex !== this._categoryWindow.index())
{
this._cIndex = this._categoryWindow.index();
switch (this._categoryWindow.index())
{
case 0:
{
this._listWindow._data = $gameSystem.getStartedQuests();
} break;
case 1:
{
this._listWindow._data = $gameSystem.getAllQuests();
} break;
case 2:
{
this._listWindow._data = $gameSystem.getCompletedQuests();
} break;
case 3:
{
this._listWindow._data = $gameSystem.getFailedQuests();
} break;
}
this._listWindow.refresh();
}
};
//--------------------------------------------------------------------------
// Window_QuestLogCategory
//
// Shows icons for quest categories.
function Window_QuestLogCategory() {
this.initialize.apply(this, arguments);
};
Window_QuestLogCategory.prototype = Object.create(Window_Selectable.prototype);
Window_QuestLogCategory.prototype.constructor = Window_QuestLogCategory;
Window_QuestLogCategory.prototype.initialize = function(x, y, w, h) {
Window_Selectable.prototype.initialize.call(this, x, y, w, h);
this.refresh();
};
Window_QuestLogCategory.prototype.maxCols = function() {
return 4;
};
Window_QuestLogCategory.prototype.maxItems = function() {
return 4;
};
Window_QuestLogCategory.prototype.itemHeight = function() {
return Window_Base._iconHeight + 4;
};
Window_QuestLogCategory.prototype.itemWidth = function() {
return Window_Base._iconWidth + 4;
};
Window_QuestLogCategory.prototype.itemRect = function(index) {
var maxCols = this.maxCols();
var rect = new Rectangle();
rect.width = this.itemWidth();
rect.height = this.itemHeight();
var quarter = this.contentsWidth()/4;
rect.x = (quarter*index) - Window_Base._iconWidth/2 + quarter/2;
rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
return rect;
};
Window_QuestLogCategory.prototype.drawItem = function(index) {
var rect = this.itemRect(index);
var icon = 0;
switch (index)
{
case 0:
{
icon = paramOngoingQuestsIcon;
} break;
case 1:
{
icon = paramAllQuestsIcon;
} break;
case 2:
{
icon = paramCompletedQuestsIcon;
} break;
case 3:
{
icon = paramFailedQuestsIcon;
} break;
}
this.drawIcon(icon, rect.x+2, rect.y+2);
};
//--------------------------------------------------------------------------
// Window_QuestLogList
//
// Shows quests depending on category.
function Window_QuestLogList() {
this.initialize.apply(this, arguments);
};
Window_QuestLogList.prototype = Object.create(Window_Selectable.prototype);
Window_QuestLogList.prototype.constructor = Window_QuestLogList;
Window_QuestLogList.prototype.initialize = function(x, y, w, h) {
Window_Selectable.prototype.initialize.call(this, x, y, w, h);
this._data = $gameSystem.getStartedQuests();
this.refresh();
};
Window_QuestLogList.prototype.maxItems = function() {
return this._data ? this._data.length : 1;
};
Window_QuestLogList.prototype.drawItem = function(index) {
var quest = $gameSystem.getQuest(this._data[index]);
if (quest)
{
var rect = this.itemRectForText(index);
var iconId = quest.iconId;
var name = quest.name;
this.drawIcon(iconId, rect.x, rect.y+1);
if (quest.failed)
this.changeTextColor(paramFailedColor);
else if (quest.finished)
this.changeTextColor(paramCompletedColor);
else
this.changeTextColor(paramStartedColor);
this.drawText(name, rect.x+Window_Base._iconWidth, rect.y);
this.resetTextColor();
}
};
Window_QuestLogList.prototype.setDescriptionWindow = function(_window) {
this._descriptionWindow = _window;
};
Window_QuestLogList.prototype.update = function() {
Window_Selectable.prototype.update.call(this);
this.updateDescription();
};
Window_QuestLogList.prototype.updateDescription = function() {
if (!this._descriptionWindow)
return;
this._descriptionWindow.setQuest(this._data[this.index()]);
};
//--------------------------------------------------------------------------
// Window_QuestLogDescription
//
// Shows quest's information.
function Window_QuestLogDescription() {
this.initialize.apply(this, arguments);
};
Window_QuestLogDescription.prototype = Object.create(Window_Base.prototype);
Window_QuestLogDescription.prototype.constructor = Window_QuestLogDescription;
Window_QuestLogDescription.prototype.initialize = function(x, y, w, h) {
Window_Base.prototype.initialize.call(this, x, y, w, h);
};
Window_QuestLogDescription.prototype.refresh = function() {
this.contents.clear();
var quest = $gameSystem.getQuest(this._quest);
if (!quest)
return;
// Name
var textWidth = this.textWidth(quest.name);
var nameWidth = textWidth + Window_Base._iconWidth + 2;
this.drawIcon(quest.iconId, this.contentsWidth()/2 - nameWidth/2, 0);
this.drawText(quest.name, this.contentsWidth()/2 - nameWidth/2 + Window_Base._iconWidth + 2, 0);
// Description
this.changeTextColor(this.systemColor());
this.drawText(paramDescriptionText, 0, this.lineHeight());
this.resetTextColor();
var x = 0;
var y = this.lineHeight()*2;
var tWidth = this.contentsWidth();
var words = quest.description.split(" ");
for (var i = 0; i < words.length; i++) {
var word = words[i];
var width = this.textWidth(word);
var sWidth = this.textWidth(" ");
if (x + width >= tWidth) {
x = 0;
y += this.lineHeight();
}
this.drawText(word + " ", x, y);
x += width + sWidth;
}
y += this.lineHeight()*2;
// Objetive
this.changeTextColor(this.systemColor());
this.drawText(paramObjectiveText, 0, y);
y += this.lineHeight();
this.resetTextColor();
if (quest.finished || quest.failed)
this.drawText(paramNoObjectivesText, 0, y);
else
this.drawTextEx(quest.steps[quest.currentStep], 0, y);
y += this.lineHeight()*2;
// Rewards
this.changeTextColor(this.systemColor());
this.drawText(paramRewardsText, 0, y);
y += this.lineHeight();
this.resetTextColor();
for (var i = 0; i < quest.rewards.length; i++) {
switch (quest.rewards[i].Type)
{
case 'weapon':
{
var amount = quest.rewards[i].Amount;
var txt = amount + "x";
this.drawText(txt, 0, y);
this.drawItemName($dataWeapons[quest.rewards[i].ID], this.textWidth(txt)+2, y);
} break;
case 'armor':
{
var amount = quest.rewards[i].Amount;
var txt = amount + "x";
this.drawText(txt, 0, y);
this.drawItemName($dataArmors[quest.rewards[i].ID], this.textWidth(txt)+2, y);
} break;
case 'item':
{
var amount = quest.rewards[i].Amount;
var txt = amount + "x";
this.drawText(txt, 0, y);
this.drawItemName($dataItems[quest.rewards[i].ID], this.textWidth(txt)+2, y);
} break;
case 'gold':
{
var amount = quest.rewards[i].Amount;
this.drawIcon(paramGoldIcon, 2, y+1);
this.drawText(amount, Window_Base._iconWidth + 4, y);
} break;
case 'exp':
{
var amount = quest.rewards[i].Amount;
var id = quest.rewards[i].ID;
if (id)
this.drawText(amount + " " + TextManager.expA + " for " + $gameActors.actor(id).name(), 0, y);
else
this.drawText(amount + " " + TextManager.expA + " for each party member.", 0, y);
} break;
case 'text':
{
this.drawText(quest.rewards[i].Text, 0, y);
} break;
}
y += this.lineHeight();
}
};
Window_QuestLogDescription.prototype.setQuest = function(id) {
if (this._quest === id)
return;
this._quest = id;
this.refresh();
};
//--------------------------------------------------------------------------
// QuestLog Command
//
var _Scene_Menu_createCommandWindow = Scene_Menu.prototype.createCommandWindow;
Scene_Menu.prototype.createCommandWindow = function() {
_Scene_Menu_createCommandWindow.call(this);
this._commandWindow.setHandler('questlog', this.commandQuestLog.bind(this));
};
Scene_Menu.prototype.commandQuestLog = function() {
SceneManager.push(Scene_QuestLog);
};
Window_MenuCommand.prototype.addOriginalCommands = function() {
if (paramQuestLogMenu) {
this.addCommand(paramQuestLogText, 'questlog', true);
}
};
})();