-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathRandomChoiceOrder.js
82 lines (69 loc) · 2.23 KB
/
RandomChoiceOrder.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
//==============================================================================
// RandomChoiceOrder.js
//==============================================================================
/*:
* @plugindesc Shows choices in a random order when specified switch is turned on.
* @author mjshi
*
* @param Switch ID
* @desc ID of the switch to turn ON to use random choices.
* @type number
* @default 1
*
* @help
* ------------------------------------------------------------------------------
* Random Choice Order v1.0 by mjshi
* Free for both commercial and non-commercial use, with credit.
* ------------------------------------------------------------------------------
*
* > Is something broken? Go to http://mjshi.weebly.com/contact.html and I'll
* try my best to help you!
*/
//Initialize global variables
(function () {
/* BEGIN */
var switchID = PluginManager.parameters('RandomChoiceOrder')["Switch ID"];
/**
* Returns an array of randomized numbers, from 0 to size - 1
*/
function randomNumberArray(size) {
var index = 0, temp;
var randomized = [];
// Populate Array
while (randomized.length < size) {
randomized.push(index);
index++;
}
// Fischer-Yates Shuffle
while (size > 0) {
size--;
index = Math.floor(Math.random() * size);
temp = randomized[size];
randomized[size] = randomized[index];
randomized[index] = temp;
}
return randomized;
}
var alias_window_choicelist_makeCommandList = Window_ChoiceList.prototype.makeCommandList;
Window_ChoiceList.prototype.makeCommandList = function() {
if (!$gameSwitches.value(switchID)) {
alias_window_choicelist_makeCommandList.call(this);
return;
}
this._randomizedChoices = randomNumberArray($gameMessage.choices().length);
for (var i = 0; i < this._randomizedChoices.length; i++) {
this.addCommand($gameMessage.choices()[this._randomizedChoices[i]], 'choice');
}
};
var alias_window_choicelist_callOkHandler = Window_ChoiceList.prototype.callOkHandler;
Window_ChoiceList.prototype.callOkHandler = function() {
if (!$gameSwitches.value(switchID)) {
alias_window_choicelist_callOkHandler.call(this);
return;
}
$gameMessage.onChoice(this._randomizedChoices[this.index()]);
this._messageWindow.terminateMessage();
this.close();
};
/* END */
})();