-
Notifications
You must be signed in to change notification settings - Fork 6
/
SkillTree.js
2778 lines (2404 loc) · 84.3 KB
/
SkillTree.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
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*:
@target MV MZ
@plugindesc Skill tree v1.8.2
@author unagi ootoro
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/SkillTree.js
@param SpName
@type string
@default SP
@desc
Specify the wording of SP in the game.
@param MaxSp
@type number
@default 9999
@desc
Set the maximum value of SP that can be acquired.
@param EnabledSkillTreeSwitchId
@type switch
@default 0
@desc
Specify the ID of the switch that enables/disables the skill tree with the menu command.
@param EnableGetSpWhenBattleEnd
@type boolean
@default true
@desc
If set to true, SP will be available at the end of battle.
@param EnableGetSpWhenLevelUp
@type boolean
@default true
@desc
If you set true, you will be able to get SP when you level up.
@param ViewMode
@type string
@default wide
@desc
wide: Skill tree will be displayed next to it. long: Skill tree will be displayed vertically.
@param EnableMZLayout
@type boolean
@default false
@desc
Set to true to match the layout format of RPG Maker MZ. (MZ limited)
@param IconWidth
@type number
@default 32
@desc
Specify the width of the icon.
@param IconHeight
@type number
@default 32
@desc
Specifies the vertical width of the icon.
@param IconSpaceWidth
@type number
@default 32
@desc
Specifies the width of the space between the icons.
@param IconSpaceHeight
@type number
@default 32
@desc
Specifies the vertical width of the space between icons.
@param ViewLineWidth
@type number
@default 3
@desc
Specifies the line width.
@param ViewLineColorBase
@type string
@default #000000
@desc
Specifies the color of the line for which the skill has not been learned.
@param ViewLineColorLearned
@type string
@default #00aaff
@desc
Specify the color of the line for which the skill has been acquired.
@param ViewBeginXOffset
@type number
@default 24
@desc
Specifies the X coordinate of the drawing start of the skill tree.
@param ViewBeginYOffset
@type number
@default 24
@desc
Specify the drawing start Y coordinate of the skill tree.
@param ViewCursorOfs
@type number
@default 6
@desc
Specifies the cursor coordinate offset for the skill tree icon.
@param ViewRectColor
@type string
@default #ffff00
@desc
Specifies the color of the border surrounding the acquired skill icon.
@param ViewRectOfs
@type number
@default 1
@desc
Specify the coordinate offset of the border or border image that surrounds the acquired skill icon.
@param LearnSkillSeFileName
@type file
@dir audio/se
@default Item3
@desc
Specify the file name of the SE to play when the skill is acquired.
@param LearnSkillSeVolume
@type number
@default 90
@desc
Specify the volume of SE to play when the skill is acquired.
@param LearnSkillSePitch
@type number
@default 100
@desc
Specify the SE pitch to play when the skill is acquired.
@param LearnSkillSePan
@type number
@default 0
@desc
Specify the SE pan to play when the skill is acquired.
@param MenuSkillTreeText
@type string
@default Skill tree
@desc
Specify the skill tree command name to be displayed in the menu command.
@param NeedSpText
@type string
@default Required %1:
@desc
Specify the required SP text to be displayed in the skill tree window. %1:SP name
@param OpenedNodeText
@type string
@default Acquired
@desc
Specifies the text to display in place of the required SP if the skill is already acquired.
@param NodeOpenConfirmationText
@type string
@default Do you consume %1%2 and get %3?
@desc
Specifies the text for skill acquisition selection. %1:SP value, %2:SP name, %3:skill name to be acquired
@param NodeOpenYesText
@type string
@default Learn
@desc
On the selection screen of whether to acquire the skill, specify the text for acquiring the skill.
@param NodeOpenNoText
@type string
@default Don't learn
@desc
In the selection screen of whether to acquire the skill, specify the text when the skill is not acquired.
@param BattleEndGetSpText
@type string
@default I got %1%2.
@desc
Specifies the text to display when the SP is obtained at the end of the battle. %1:SP value, %2:SP name
@param LevelUpGetSpText
@type string
@default I got %1%2.
@desc
Specify the text to display when you get the SP when you level up. %1:SP value, %2:SP name
@help
A plugin that introduces a skill tree.
Please refer to "SkillTreeConfig.js" for the setting method.
[License]
This plugin is available under the terms of the MIT license.
*/
/*:ja
@target MV MZ
@plugindesc スキルツリー v1.8.2
@author うなぎおおとろ
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/SkillTree.js
@param SpName
@type string
@default SP
@desc
ゲーム中でのSPの文言を指定します。
@param MaxSp
@type number
@default 9999
@desc
取得可能なSPの最大値を設定します。
@param EnabledSkillTreeSwitchId
@type switch
@default 0
@desc
メニューコマンドでスキルツリーを有効/無効を設定するスイッチのIDを指定します。0を指定すると常にスキルツリーは有効になります。
@param EnableGetSpWhenBattleEnd
@type boolean
@default true
@desc
trueを設定すると、戦闘終了時にSPを入手できるようになります。
@param EnableGetSpWhenLevelUp
@type boolean
@default true
@desc
trueを設定すると、レベルアップ時にSPを入手できるようになります。
@param ViewMode
@type string
@default wide
@desc
wideを設定すると、横にスキルツリーを表示します。longを設定すると、縦にスキルツリーを表示します。
@param EnableMZLayout
@type boolean
@default false
@desc
trueを設定すると、RPGツクールMZのレイアウト形式に合わせます。(MZ限定)
@param IconWidth
@type number
@default 32
@desc
アイコンの横幅を指定します。
@param IconHeight
@type number
@default 32
@desc
アイコンの縦幅を指定します。
@param IconSpaceWidth
@type number
@default 32
@desc
アイコン間のスペースの横幅を指定します。
@param IconSpaceHeight
@type number
@default 32
@desc
アイコン間のスペースの縦幅を指定します。
@param ViewLineWidth
@type number
@default 2
@desc
ラインの幅を指定します。
@param ViewLineColorBase
@type string
@default #000000
@desc
スキル未習得の線の色を指定します。
@param ViewLineColorLearned
@type string
@default #00aaff
@desc
スキル習得済みの線の色を指定します。
@param ViewBeginXOffset
@type number
@default 24
@desc
スキルツリーの描画開始X座標を指定します。
@param ViewBeginYOffset
@type number
@default 24
@desc
スキルツリーの描画開始Y座標を指定します。
@param ViewCursorOfs
@type number
@default 6
@desc
スキルツリーのアイコンに対するカーソルの座標オフセットを指定します。
@param ViewRectColor
@type string
@default #ffff00
@desc
取得済みスキルのアイコンを囲む枠線の色を指定します。
@param ViewRectOfs
@type number
@default 1
@desc
取得済みスキルのアイコンを囲む枠線または枠画像の座標オフセットを指定します。
@param LearnSkillSeFileName
@type file
@dir audio/se
@default Item3
@desc
スキルを習得したときに再生するSEのファイル名を指定します。
@param LearnSkillSeVolume
@type number
@default 90
@desc
スキルを習得したときに再生するSEのvolumeを指定します。
@param LearnSkillSePitch
@type number
@default 100
@desc
スキルを習得したときに再生するSEのpitchを指定します。
@param LearnSkillSePan
@type number
@default 0
@desc
スキルを習得したときに再生するSEのpanを指定します。
@param MenuSkillTreeText
@type string
@default スキルツリー
@desc
メニューコマンドに表示するスキルツリーのコマンド名を指定します。
@param NeedSpText
@type string
@default 必要%1:
@desc
スキルツリーウィンドウに表示する必要SPのテキストを指定します。%1:SP名
@param OpenedNodeText
@type string
@default 取得済み
@desc
スキルが取得済みの場合に必要SPの代わりに表示するテキストを指定します。
@param NodeOpenConfirmationText
@type string
@default %1%2を消費して%3を取得しますか?
@desc
スキル取得有無の選択画面で、確認用のテキストを表示します。%1:消費するSP値, %2:SP名, %3:取得するスキル名
@param NodeOpenYesText
@type string
@default 習得する
@desc
スキル取得有無の選択画面で、スキルを取得する場合のテキストを指定します。
@param NodeOpenNoText
@type string
@default 習得しない
@desc
スキル取得有無の選択画面で、スキルを取得しない場合のテキストを指定します。
@param BattleEndGetSpText
@type string
@default %1%2を入手した。
@desc
戦闘終了時にSPを入手したときに表示するテキストを指定します。%1:入手するSP値, %2:SP名
@param LevelUpGetSpText
@type string
@default %1%2を入手した。
@desc
レベルアップ時にSPを入手したときに表示するテキストを指定します。%1:入手するSP値, %2:SP名
@help
スキルツリーを導入するプラグインです。
設定方法については、「SkillTreeConfig.js」を参照してください。
[ライセンス]
このプラグインは、MITライセンスの条件の下で利用可能です。
*/
const SkillTreePluginName = document.currentScript.src.match(/^.*\/(.+)\.js$/)[1];
let $skillTreeData = null;
let $skillTreeConfigLoader = null;
const $skillTreeMapLoaders = {};
const skt_open = (actorId) => {
$gameParty.setMenuActor($gameActors.actor(actorId));
SceneManager.push(SkillTreeClassAlias.Scene_SkillTree);
};
const skt_gainSp = (actorId, value) => {
const actor = $gameParty.members().find(actor => actor.actorId() === actorId);
if (actor) actor.gainSp(value);
};
const skt_skillReset = (actorId) => {
const totalSp = $skillTreeData.totalSpAllTypes(actorId);
$skillTreeData.skillResetAllTypes(actorId);
$skillTreeData.gainSp(actorId, totalSp);
};
const skt_totalSp = (actorId, variableId) => {
const totalSp = $skillTreeData.totalSpAllTypes(actorId);
$gameVariables.setValue(variableId, totalSp)
};
const skt_learn = (actorId, typeName, skillId, force = false) => {
const types = $skillTreeData.types(actorId);
const findedType = types.find(type => type.skillTreeName() === typeName);
if (!findedType) return;
if (force) {
$skillTreeData.forceOpenNode(findedType, skillId);
} else {
$skillTreeData.openNode(findedType, skillId);
}
};
const skt_enableType = (actorId, typeName) => {
const types = $skillTreeData.types(actorId);
let targetType = null;
for (const type of types) {
if (type.skillTreeName() === typeName) {
targetType = type;
}
}
if (!targetType) return;
targetType.setEnabled(true);
}
const skt_disableType = (actorId, typeName) => {
const types = $skillTreeData.types(actorId);
let targetType = null;
for (const type of types) {
if (type.skillTreeName() === typeName) {
targetType = type;
}
}
if (!targetType) return;
targetType.setEnabled(false);
}
const skt_migrationType = (actorId, fromTypeName, toTypeName, reset) => {
let dstType = null;
let srcType = null;
const types = $skillTreeData.types(actorId);
for (const type of types) {
if (type.skillTreeName() === fromTypeName) {
srcType = type;
} else if (type.skillTreeName() === toTypeName) {
dstType = type;
}
}
if (!dstType || !srcType) return;
srcType.setEnabled(false);
dstType.setEnabled(true);
if (reset) {
const resetSp = $skillTreeData.totalSp(srcType);
$skillTreeData.skillReset(srcType);
$skillTreeData.gainSp(actorId, resetSp);
} else {
$skillTreeData.copyTree(dstType, srcType);
$skillTreeData.skillReset(srcType);
}
};
const SkillTreeClassAlias = (() => {
"use strict";
const params = PluginManager.parameters(SkillTreePluginName);
const SpName = params["SpName"];
const MaxSp = parseInt(params["MaxSp"]);
const EnableGetSpWhenBattleEnd = (params["EnableGetSpWhenBattleEnd"] === "true" ? true : false);
const EnableGetSpWhenLevelUp = (params["EnableGetSpWhenLevelUp"] === "true" ? true : false);
const EnabledSkillTreeSwitchId = parseInt(params["EnabledSkillTreeSwitchId"]);
const EnableMZLayout = (params["EnableMZLayout"] === "true" ? true : false);
const ViewMode = params["ViewMode"];
const IconWidth = parseInt(params["IconWidth"]);
const IconHeight = parseInt(params["IconHeight"]);
const IconSpaceWidth = parseInt(params["IconSpaceWidth"]);
const IconSpaceHeight = parseInt(params["IconSpaceHeight"]);
const ViewLineWidth = parseInt(params["ViewLineWidth"]);
const ViewLineColorBase = params["ViewLineColorBase"];
const ViewLineColorLearned = params["ViewLineColorLearned"];
const ViewBeginXOffset = parseInt(params["ViewBeginXOffset"]);
const ViewBeginYOffset = parseInt(params["ViewBeginYOffset"]);
const ViewCursorOfs = parseInt(params["ViewCursorOfs"]);
const ViewRectOfs = parseInt(params["ViewRectOfs"]);
const ViewRectColor = params["ViewRectColor"];
const LearnSkillSeFileName = params["LearnSkillSeFileName"];
const LearnSkillSeVolume = parseInt(params["LearnSkillSeVolume"]);
const LearnSkillSePitch = parseInt(params["LearnSkillSePitch"]);
const LearnSkillSePan = parseInt(params["LearnSkillSePan"]);
const MenuSkillTreeText = params["MenuSkillTreeText"];
const NeedSpText = params["NeedSpText"];
const OpenedNodeText = params["OpenedNodeText"];
const NodeOpenConfirmationText = params["NodeOpenConfirmationText"];
const NodeOpenYesText = params["NodeOpenYesText"];
const NodeOpenNoText = params["NodeOpenNoText"];
const BattleEndGetSpText = params["BattleEndGetSpText"];
const LevelUpGetSpText = params["LevelUpGetSpText"];
class HttpResponse {
constructor(result, xhr, event) {
this._result = result;
this._xhr = xhr;
this._event = event;
}
result() {
return this._result;
}
status() {
return this._xhr.status;
}
response() {
return this._xhr.response;
}
}
class HttpRequest {
static get(path, opt, responseCallback) {
const req = new HttpRequest(path, "GET", opt, responseCallback);
req.send();
return req;
}
static post(path, params, opt, responseCallback) {
const req = new HttpRequest(path, "POST", opt, responseCallback);
req.send(params);
return req;
}
constructor(path, method, opt, responseCallback) {
this._path = path;
this._method = method;
this._responseCallback = responseCallback;
this._mimeType = opt.mimeType;
}
send(params = null) {
const xhr = new XMLHttpRequest();
xhr.open(this._method, this._path);
if (this._mimeType) xhr.overrideMimeType(this._mimeType);
let json = null;
if (params) json = JSON.stringify(params);
xhr.addEventListener("load", (e) => {
this._responseCallback(new HttpResponse("load", xhr, e));
});
xhr.addEventListener("error", (e) => {
this._responseCallback(new HttpResponse("error", xhr, e));
});
xhr.send(json);
}
}
class SkillTreeNodeInfo {
constructor(actorId, skillId, needSp, iconData, helpMessage) {
this._actorId = actorId;
this._skillId = skillId;
this._needSp = needSp;
this._iconData = iconData;
this._helpMessage = helpMessage;
}
actorId() {
return this._actorId;
}
actor() {
const actor = $gameActors.actor(this._actorId);
if (!actor) throw new Error(`actor id: ${this._actorId} is not found.`)
return actor;
}
skillId() {
return this._skillId;
}
skill() {
const skill = $dataSkills[this._skillId];
if (!skill) throw new Error(`skill id: ${this._skillId} is not found.`)
return skill;
}
canLearn(nowSp) {
return nowSp >= this._needSp;
}
learnSkill() {
this.actor().learnSkill(this._skillId);
}
forgetSkill() {
this.actor().forgetSkill(this._skillId);
}
trimIconset(iconIndex) {
const srcBitmap = ImageManager.loadSystem("IconSet");
const dstBitmap = new Bitmap(32, 32);
const sx = iconIndex % 16 * 32;
const sy = Math.floor(iconIndex / 16) * 32;
dstBitmap.blt(srcBitmap, sx, sy, 32, 32, 0, 0);
return dstBitmap;
}
iconBitmap() {
if (this._iconData[0] === "img") {
return ImageManager.loadPicture(this._iconData[1]);
} else if (this._iconData[0] === "icon") {
let iconIndex;
if (this._iconData.length >= 2) {
iconIndex = this._iconData[1];
} else {
iconIndex = this.skill().iconIndex;
}
return this.trimIconset(iconIndex);
}
throw new Error(`Unknown ${this._iconData[0]}`);
}
checkIconBitmapReady() {
if (this._iconData[0] === "img") {
const bitmap = ImageManager.loadPicture(this._iconData[1]);
if (!bitmap.isReady()) return false;
} else if (this._iconData[0] === "icon") {
const iconSet = ImageManager.loadSystem("IconSet");
if (!iconSet.isReady()) return false;
} else if (this._iconData[0] === "icon_ex") {
const iconSet = ImageManager.loadSystem("IconSet");
if (!iconSet.isReady()) return false;
if (typeof this._iconData[1] === "string") {
const backBitmap = ImageManager.loadPicture(this._iconData[1]);
if (!backBitmap.isReady()) return false;
} else {
const backBitmap = ImageManager.loadPicture(this._iconData[1][0]);
if (!backBitmap.isReady()) return false;
}
} else {
throw new Error(`Unknown ${this._iconData[0]}`);
}
return true;
}
needSp() {
return this._needSp;
}
helpMessage() {
return this._helpMessage;
}
}
class SkillTreeNode {
constructor(tag) {
this._tag = tag
this._parents = [];
this._childs = [];
this._info = null;
this._opened = false;
this._point = null;
this._reservedPoint = null;
}
get point() { return this._point; }
set point(_point) { this._point = _point; }
tag() {
return this._tag;
}
info() {
return this._info;
}
reservedPoint() {
return this._reservedPoint;
}
setReservedPoint(point) {
this._reservedPoint = point;
}
parents() {
return this._parents;
}
childs() {
return this._childs;
}
getAllChilds() {
let allChilds = [this];
for (const child of this._childs) {
allChilds = allChilds.concat(child.getAllChilds());
}
return allChilds;
}
parent(index) {
if (index < 0) index = this._parents.length - index;
return this._parents[index % this._parents.length];
}
child(index) {
if (index < 0) index = this._childs.length - index;
return this._childs[index % this._childs.length];
}
addChild(child) {
if (!child) throw new Error("child is none.");
child._parents.push(this);
this._childs.push(child);
}
setup(info) {
this._info = info;
}
isOpenable() {
return this.isSelectable() && !this.isOpened() && this.canCostConsumption();
}
isSelectable() {
for (const parent of this._parents) {
if (!parent.isOpened()) return false;
}
return true;
}
isOpened() {
return this._opened;
}
setOpenedStatus(openStatus) {
this._opened = openStatus;
}
open(costConsume = true) {
this._info.learnSkill();
if (costConsume) this.costConsumption();
this._opened = true;
}
close() {
this._info.forgetSkill();
this._opened = false;
}
canCostConsumption() {
const actorId = this._info.actorId();
return $skillTreeData.sp(actorId) >= this.needSp();
}
costConsumption() {
const actorId = this._info.actorId();
$skillTreeData.gainSp(actorId, -this.needSp());
}
clearPointNode() {
this.point = null;
if (this._childs.length === 0) return;
for (const child of this._childs) {
child.clearPointNode();
}
}
makePointNode(x, y, mode) {
if (this.reservedPoint()) {
this.point = this.reservedPoint();
x = this.reservedPoint().x;
y = this.reservedPoint().y;
} else {
if (this.point) {
if (mode === "wide") {
if (x < this.point.x) {
this.point = { x: this.point.x, y: y };
} else {
this.point = { x: x, y: this.point.y };
}
} else if (mode === "long") {
if (y < this.point.y) {
this.point = { x: x, y: this.point.y };
} else {
this.point = { x: this.point.x, y: y };
}
}
} else {
this.point = { x: x, y: y };
}
}
if (this._childs.length === 0) return 1;
if (mode === "wide") {
let yOfs = 0;
for (const child of this._childs) {
yOfs += child.makePointNode(x + 1, y + yOfs, mode);
}
return yOfs;
} else if (mode === "long") {
let xOfs = 0;
for (const child of this._childs) {
xOfs += child.makePointNode(x + xOfs, y + 1, mode);
}
return xOfs;
}
}
needSp() {
return this._info.needSp();
}
iconBitmap() {
return this._info.iconBitmap();
}
checkIconBitmapReady() {
return this._info.checkIconBitmapReady();
}
helpMessage() {
return this._info.helpMessage();
}
}
class SkillTreeTopNode extends SkillTreeNode {
constructor() {
super(null);
this._opened = true;
const dummyInfo = new SkillTreeNodeInfo(null, null, 0, 0, "");
this.setup(dummyInfo);
}
getAllChilds() {
let allChilds = [];
for (const child of this._childs) {
allChilds = allChilds.concat(child.getAllChilds());
}
return allChilds;
}
skillReset() {
for (const child of this._childs) {
if (child.isOpened()) child.skillReset();
}
}
}
class SkillDataType {
constructor(skillTreeName, actorId, message, helpMessage, enabled) {
this._skillTreeName = skillTreeName;
this._actorId = actorId;
this._message = message;
this._helpMessage = helpMessage;
this._enabled = enabled;
}
message() {
return this._message;
}
skillTreeName() {
return this._skillTreeName;
}
skillTreeTag() {
return `${this._skillTreeName}_actorId${this._actorId}`;
}
helpMessage() {
return this._helpMessage;
}
enabled() {
return this._enabled;
}
setEnabled(enabled) {
this._enabled = enabled;
}
}
class SkillTreeMapLoader {
constructor(mapId) {
this._mapId = mapId;
this._mapData = null;
}
applyMapData(type) {
const allNodes = $skillTreeData.getAllNodesByType(type);
for (const eventData of this.mapData().events) {
if (!eventData) continue;
let nodeTag = eventData.note;
let node = allNodes[nodeTag];
if (!node) continue;
node.setReservedPoint({ x: eventData.x, y: eventData.y });
}
}
isLoaded() {
return this._response;
}
mapData() {
return JSON.parse(this._response);
}
loadMap() {
const fileName = "Map%1.json".format(this._mapId.padZero(3));
this.loadData(fileName);
}
loadData(fileName) {
HttpRequest.get(`data/${fileName}`, { mimeType: "application/json" }, (res) => {
if (res.result() === "error") {
throw new Error(`Unknow file: ${fileName}`);
} else if (res.status() === 200) {
this._response = res.response();
} else {
throw new Error(`Load failed: ${fileName}`);
}
});
}
}
class SkillTreeConfigLoadError extends Error {}
class SkillTreeConfigLoader {
constructor() {
this._configData = loadSkillTreeConfig();
}
configData() {
return this._configData;
}
loadConfig(actorId) {
let types = $skillTreeData.types(actorId);
if (!types) {
types = this.loadTypes(actorId);
$skillTreeData.setTypes(actorId, types);
}
for (const type of types) {
let topNode = $skillTreeData.topNode(type);
if (!topNode) {
topNode = this.loadSkillTreeNodes(type);
$skillTreeData.setTopNode(type, topNode);
this.loadSkillTreeInfo(actorId, $skillTreeData.getAllNodesByType(type));
}
}
}
loadTypes(actorId) {
let cfgTypes = null;
let typesArray = [];
for (const cfg of this._configData.skillTreeTypes) {
if (cfg.actorId === actorId) {
cfgTypes = cfg.types;
break;
}
}
if (!cfgTypes) return [];
for (const cfgType of cfgTypes) {
const enabled = (cfgType.length === 3 ? true : cfgType[3]);
typesArray.push(new SkillDataType(cfgType[0], actorId, cfgType[1], cfgType[2], enabled));
}
return typesArray;
}
loadSkillTreeNodes(type) {
const nodes = {};
let derivative = null;
for (const skillTreeType in this._configData.skillTreeDerivative) {