-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathRS_EX_ToolKit.js
176 lines (161 loc) · 6.09 KB
/
RS_EX_ToolKit.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
//================================================================
// RS_EX_ToolKit.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2020 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc <RS_EX_ToolKit>
* @author biud436
*
* @help
*
*/
(function () {
const Imported = window.Imported || {};
const RS = window.RS || {};
RS.EX_ToolKit = RS.EX_ToolKit || {};
if (Imported.RS_HangulInput) {
/**
* This function allows you to type the event name
* and then get an event object that has a certain name into the map.
* it shows the message and does scroll the screen as target event.
*/
Game_Interpreter.prototype.moveToTargetEvent = function () {
const joinedText = $gameVariables.value(
RS.HangulInput.Params.variableId
);
const ret = $gameMap
.events()
.filter(e => e.event().name === joinedText);
if (ret && ret[0]) {
const target = ret[0];
const sx = $gameMap.deltaX($gamePlayer.x, target.x);
const sy = $gameMap.deltaY($gamePlayer.y, target.y);
let dir = 0;
let dist = 0;
const speed = 6;
const minDist = 6;
const dist2 = $gameMap.distance(
$gamePlayer.x,
$gamePlayer.y,
target.x,
target.y
);
const addScroll = (...args) => {
this._list.push({
// 화면의 스크롤
code: 204,
indent: 0,
parameters: [args[0], args[1], args[2]],
});
};
const addList = (...args) => {
args.forEach(e => {
this._list.push(e);
});
};
if (dist2 >= minDist) {
this._list.splice(-1, 1);
if (Math.abs(sx) >= minDist) {
// eslint-disable-next-line no-nested-ternary
dir = sx < 0 ? 6 : sx > 0 ? 4 : 0;
dist = Math.abs(sx);
addScroll(dir, dist, speed);
}
if (Math.abs(sy) >= minDist) {
// eslint-disable-next-line no-nested-ternary
dir = sy < 0 ? 2 : sy > 0 ? 8 : 0;
dist = Math.abs(sy);
addScroll(dir, dist, speed);
}
addList(
{
code: 230, // 대기
indent: 0,
parameters: [60],
},
{
code: 101, // 문장의 표시
indent: 0,
parameters: ['', 0, 0, 2],
},
{
code: 401,
indent: 0,
parameters: [
`\\말풍선[${target.eventId()}] 아니 내 이름을 어떻게 알았지?`,
],
},
{
// 끝
code: 0,
indent: 0,
parameters: [],
}
);
}
}
};
}
/**
* This function allows you to gain a certain item randomly.
*
* @param {Number} min 아이템 인덱스 최소 범위
* @param {Number} max 아이템 인덱스 최대 범위
* @param {Number} type 아이템의 타입 (1: 아이템, 2: 무기구, 3: 방어구)
* @param {Number} amount 획득할 아이템의 갯수
*/
Game_Party.prototype.gainRandomItem = function (min, max, type, amount) {
if (min <= 0) min = 1;
if (max - min <= 0) {
console.warn(
'아이템 범위를 잘못 적었습니다. 최소값이 최대치를 넘어갑니다.'
);
return;
}
const choose = (_min, _max) => {
return Math.floor(Math.random() * (_max - _min + 1) + _min);
};
if (type <= 0) type = choose(1, 3); // type가 0인 경우, 무기구, 아이템, 방어구 중에 램덤 선택
let item = null;
let isValid = () => {
return false;
};
if (type === 1) {
item = $dataItems;
isValid = DataManager.isItem;
} else if (type === 2) {
item = $dataWeapons;
isValid = DataManager.isWeapon;
} else if (type === 3) {
item = $dataArmors;
isValid = DataManager.isArmor;
}
if (!item) {
console.warn('아이템 컨테이너가 아직 로드되지 않았습니다.');
return;
}
let idx = choose(min, max);
if (idx > item.length - 1) idx = item.length - 1;
if (isValid(item[idx])) {
this.gainItem(item[idx], amount);
}
};
//==================================================================
// Plugin Command
//==================================================================
const aliasPluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
aliasPluginCommand.call(this, command, args);
if (command === 'gain' || command === '획득') {
min = Number(args[0]);
max = Number(args[1]);
type = Number(args[2]);
amount = Number(args[3]);
$gameParty.gainRandomItem(min, max, type, amount);
}
};
})();