forked from aaixy/rm-mvmz-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYEP_ItemCore.js
2136 lines (1942 loc) · 73.9 KB
/
YEP_ItemCore.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
//=============================================================================
// Yanfly Engine Plugins - Item Core
// YEP_ItemCore.js
//=============================================================================
var Imported = Imported || {};
Imported.YEP_ItemCore = true;
var Yanfly = Yanfly || {};
Yanfly.Item = Yanfly.Item || {};
Yanfly.Item.version = 1.26;
//=============================================================================
/*:
* @plugindesc AXY edit on 2019.11.27 for compatiable helpextend.js. v1.26 Changes the way Items are handled for your game
* and the Item Scene, too.
* @author Yanfly Engine Plugins
*
* @param ---General---
* @default
*
* @param Max Items
* @desc Maximum number of items. If this is set to 0, then there
* will be no independent items.
* @default 0
*
* @param Max Weapons
* @desc Maximum number of weapons. If this is set to 0, then there
* will be no independent weapons.
* @default 100
*
* @param Max Armors
* @desc Maximum number of armors. If this is set to 0, then there
* will be no independent armors.
* @default 100
*
* @param Starting ID
* @desc This will be the starting ID number for independent items
* so that they don't interfere with default items.
* @default 3000
*
* @param Random Variance
* @desc Randomize the stats found for non shop items by this value
* either positive or negative. Set as 0 for no random.
* @default 0
*
* @param Negative Variance
* @desc If using random variance, allow random variance equipment
* stats to go under 0? NO - false YES - true
* @default false
*
* @param Name Format
* @desc How item names will be ordered and structured.
* %1 - Prefix, %2 - Base Name, %3 - Suffix, %4 Boost
* @default %1%2%3%4
*
* @param Name Spacing
* @desc Place a space between name prefixes and suffixes?
* NO - false YES - true
* @default true
*
* @param Boost Format
* @desc This is the text format for a boosted independent item.
* %1 - Boost Amount
* @default (+%1)
*
* @param ---Item Scene---
* @default
*
* @param Updated Scene Item
* @desc Enabling this will change Scene Item's visual appearance.
* NO - false YES - true (recommended)
* @default true
*
* @param List Equipped Items
* @desc Show equipped independent items in the item lists?
* NO - false YES - true
* @default true
*
* @param Show Icon
* @desc Show the icon in the status window?
* NO - false YES - true
* @default true
*
* @param Icon Size
* @desc This will be the width and height of the icon to be drawn.
* This is normally 4x the default Icon Width and Icon Height.
* @default 128
*
* @param Font Size
* @desc This changes the font size for description items.
* Default: 28
* @default 20
*
* @param Command Alignment
* @desc This is the text alignment for the command windows.
* left center right
* @default center
*
* @param Recovery Format
* @desc This is the text format for HP/MP Recovery.
* @default %1 Heal
*
* @param Add State
* @desc This is the text for adding states.
* @default +State
*
* @param Add Buff
* @desc This is the text for adding buffs.
* @default +Buff
*
* @param Remove State
* @desc This is the text for remove states.
* @default -State
*
* @param Remove Buff
* @desc This is the text for remove buffs.
* @default -Buff
*
* @param Maximum Icons
* @desc Maximum number of icons drawn for states and buffs.
* @default 4
*
* @param Use Command
* @desc Command text for using the selected item.
* %1 - Item Icon and Name
* @default Use %1
*
* @param Carry Format
* @desc This is the visual text format for independent item ID.
* %1 - Item Index %2 - Maximum
* @default %1/%2
*
* @param --Independent Items--
* @default
*
* @param Midgame Note Parsing
* @desc Allow midgame note parsing or do it at beginning?
* NO - false YES - true Recommended: false
* @default false
*
* @help
* ============================================================================
* Introduction
* ============================================================================
*
* This plugin makes a couple of main changes to your game and the way items
* are handled to allow a base core for future plugins.
*
* 1. Independent Items
* If you choose to have maximum limit on your items, weapons, and/or armors,
* those items will become independent and have their own individual stats and
* whatnot. Independent items are capable of being upgraded, altered, modified,
* etc. and retain those changed properties independent of other items of the
* same type. Items without a maximum limit (aka 0), will continue working as
* they normally did in RPG Maker MV.
*
* 2. New Scene_Item
* The item scene has been revamped to look a little bit different. With the
* new layout, the item list is no longer two columns, but one. Added are a few
* more windows, such as the item status window (which displays basic item
* information), an item information window (which shows information applied to
* the item via upgrades, etc.), and an item action window, which appears when
* you select an item and it will ask you if you wish to Use the item or any
* action added via plugins (such as upgrading the item). If you wish to not
* use this revamp, you can disable it from the parameters.
*
* 3. Random Variance
* Newly acquired items that aren't from shop can be given randomized stats to
* a small degree for items that are independent. Items can be above the stock
* value or below the stock value by the variance value. If you wish for an
* item to not have a variance value, you can use a notetag to set the variance
* value to 0. If you wish for all of your items to not have a variance value,
* you can set the parameter to 0.
*
* Note: During battle test, independent items are disabled.
*
* ============================================================================
* Notetags
* ============================================================================
*
* If you are using independent items, items that aren't gained through the
* shop can have a random variance applied to its stats.
*
* Item, Weapon, Armor Notetag
* <Random Variance: x>
* If this item is acquired through non-shop means, it will have random
* stats offset by x amount in either a positive or negative value.
*
* <Not Independent Item>
* Sets an item that is independent by default to become a nonindependent
* item, allowing it to stack and making it unable to be affected by
* independent item modifiers.
*
* <Priority Name>
* This sets the item, weapon, or armor's priority name to its database
* entry so that name schemes cannot affect the item.
*
* <Text Color: x>
* This sets the text color of this item, weapon, or armor to use text color
* x from the window skin.
*
* ============================================================================
* Plugin Commands
* ============================================================================
*
* If you wish to be able to add items to your player's inventory without the
* random variance being applied to it, you can use the following plugin
* commands to adjust the settings for that.
*
* Plugin Command:
* EnableVarianceStock - Causes all items acquired from this point forward
* to have its variance give stock (nonrandom) values.
* DisableVarianceStock - Causes all items acquired from this point forward
* to have its variance give random values.
*
* A small note is that if you enabled the variance stock values, if the player
* restarts the game by either going through the title screen or just turning
* off the program and starting it back up, the random variance will be in
* effect again. This plugin command is meant to exist as a short term disable.
*
* ============================================================================
* Eventing Changes
* ============================================================================
*
* A few changes have been made to eventing in order to adjust for independent
* items. They are as follows:
*
* Event Page Conditions and Conditional Branches:
* Checking to see if an item exists in the party's inventory will differ if
* the item can be independent. Instead, the condition can be fulfilled if
* there is an item, even when upgraded, that has the selected item as the base
* item. This means your Long Sword (+1) will fulfill the condition of having
* the target Long Sword item in the event editor.
*
* Actor Has X Equip:
* Just like the previous condition, this condition will be fulfilled if the
* actor has a weapon whose base item matches the event editor's target item.
* The Long Sword (+1) will fulfill the condition of needing the actor to have
* a Long Sword item equipped.
*
* Change Equipment:
* If the target equipment is independent, the game will first check to see
* if the actor has an item equipped with the matching base item. If not, the
* game will then check to see if the party has a matching base item in the
* inventory first and use that. If not, then the game will create a new stock
* version of the item and equip that to the actor.
*
* ============================================================================
* Item Name System
* ============================================================================
*
* For independent items, they have a unique name handling system. Independent
* items consist of four parts:
*
* Prefix Base Name Suffix Boost Count
*
* The prefix, base name, suffix, and boost count are adjusted by plugins.
* Depending on the effects applied, they can be altered or changed. Using the
* name system, an item with a prefix of 'Fiery', base name of 'Sword', suffix
* being 'of Might', and a boost count of 5 will end up looking like:
*
* Fiery Sword of Might (+5)
*
* This item would appear that way only if its various name parts have been
* altered some way or another. However, there is a fifth name convention, and
* that is the priority name. If an item has a priority name, it will completely
* overwrite the current name scheme with just the priority name itself. So even
* if the item's name is 'Fiery Sword of Might (+5)', if the item's priority
* name is 'Legendary Blade', then 'Legendary Blade' will take priority.
*
* ============================================================================
* Lunatic Mode - On Independent Item Creation
* ============================================================================
*
* For those with JavaScript experience, you can use the following Lunatic Mode
* to run JavaScript code upon the creation of the item. This only applies to
* newly made independent items.
*
* Item, Weapon, Armor
*
* <On Creation Eval>
* item.price = baseItem.price;
* item.price += Math.floor(Random() * 100);
* </On Creation Eval>
* The 'item' variable refers to the independent item being made. 'baseItem'
* refers to the item's base item. Any alterations made to the 'item' will be
* applied to the independent item.
*
* ============================================================================
* Lunatic Mode - Custom Info Window Display
* ============================================================================
*
* If you want to display unique and custom stuff into your info window on the
* side, you can use the following notetags:
*
* <Info Text Top>
* text
* text
* </Info Text Top>
* Type in extra information you wish to type in for the item info window
* here, whether it is lore or other information. Text codes can be used.
* Information here is is displayed towards the top of the info window.
*
* <Info Text Bottom>
* text
* text
* </Info Text Bottom>
* Type in extra information you wish to type in for the item info window
* here, whether it is lore or other information. Text codes can be used.
* Information here is is displayed towards the bottom of the info window.
*
* <Info Eval>
* var variableId = 1;
* var value = 500;
* $gameVariables.setValue(variableId, value);
* </Info Eval>
* If you know JavaScript, you can use these notetags to run some code before
* displaying any new info. This way, if you plan on using text codes that
* display variable values, you can run a bit of code before displaying them
* to synch up what's shown in the item info window.
*
* ============================================================================
* Independent Items and Midgame Note Parsing
* ============================================================================
*
* The "Midgame Note Parsing" option in the plugin parameters is made for any
* plugins that may only parse notetags midgame as opposed to at the loading of
* the game. This is an option that you should enable AT YOUR OWN RISK.
*
* Why is it at your own risk? Because enabling this option means independent
* items will keep their notedata, thus, increasing the file sizes of your save
* files several times bigger, and it can cause lag midgame, too.
*
* ============================================================================
* Changelog
* ============================================================================
*
* Version 1.26:
* - Lunatic Mode fail safes added.
*
* Version 1.25:
* - Optimization Update
*
* Version 1.24a:
* - Fixed a typo within the code. Please update Item Core, Item Disassemble,
* Attachable Augments, and More Currencies if you are using those plugins.
* - Random variance is now disabled from fresh plugin installation by default.
*
* Version 1.23:
* - Fixed an issue custom info text when using different font sizes.
*
* Version 1.22:
* - Fixed a removal bug that caused weapon and armor ID's to clash.
*
* Version 1.21:
* - Fixed an error with sorting algorithm when items have the same base ID.
*
* Version 1.20:
* - Added <On Creation Eval> Lunatic Mode notetag. Read the help file for more
* information about it.
*
* Version 1.19:
* - Updated for RPG Maker MV version 1.1.0.
*
* Version 1.18a:
* - Added 'Midgame Note Parsing' plugin parameter.
* - Fixed a visual error with MP recovery displaying a 0 instead of ---.
*
* Version 1.17:
* - Added <Text Color: x> notetag for items, weapons, and armors.
*
* Version 1.16:
* - Fixed a bug that made mid-game actor initialization not display items
* correctly in the item menu.
*
* Version 1.15:
* - Fixed a bug with independent items getting values that crash the game.
*
* Version 1.14:
* - Fixed an unintended function of the game not granting a piece of equipment
* through events.
*
* Version 1.13:
* - Fixed a bug that didn't unequip items properly.
*
* Version 1.12:
* - Added 'Negative Variance' parameter.
*
* Version 1.11:
* - Fixed a bug that caused random variance to not calculate correctly.
* - Fixed a bug that didn't return the correct conditional branch results.
* - Fixed the display in the shop window to show number of independent items
* owned by the player rather than just 0.
*
* Version 1.10:
* - Added Lunatic Mode - Custom Info Window Display.
*
* Version 1.09:
* - Fixed a bug with evented item removal that didn't remove equipped items if
* the 'Include Equipment' checkbox was checked.
*
* Version 1.08:
* - Fixed a bug with the Control Variable event that would not gather the
* right amount of independent items.
*
* Version 1.07:
* - Fixed a bug with the Change Equipment event where armors wouldn't equip.
*
* Version 1.06:
* - Fixed a bug and rewrote the initializing equipment process.
*
* Version 1.05:
* - Compatibility update with ItemBook.
*
* Version 1.04:
* - Added 'List Equipped Items' parameter to allow for equipment restricted
* actors to be able to alt their equipment.
*
* Version 1.03:
* - Fixed a bug where using events to remove independent items weren't working
* properly and instead added more items.
* - Fixed a bug where a Random Variance of 0 still gave random stats.
*
* Version 1.02:
* - Fixed a bug where initializing equipment slots didn't work properly and/or
* added incorrect equips from the wrong actors into the inventory.
*
* Version 1.01:
* - Fixed bug where if you are using no independent pieces of equipment,
* actors would fail to start with initial equipment.
*
* Version 1.00:
* - Finished plugin!
*/
//=============================================================================
//=============================================================================
// Parameter Variables
//=============================================================================
Yanfly.Parameters = PluginManager.parameters('YEP_ItemCore');
Yanfly.Param = Yanfly.Param || {};
Yanfly.Param.ItemMaxItems = Number(Yanfly.Parameters['Max Items']);
Yanfly.Param.ItemMaxWeapons = Number(Yanfly.Parameters['Max Weapons']);
Yanfly.Param.ItemMaxArmors = Number(Yanfly.Parameters['Max Armors']);
Yanfly.Param.ItemStartingId = Number(Yanfly.Parameters['Starting ID']);
Yanfly.Param.ItemRandomVariance = Number(Yanfly.Parameters['Random Variance']);
Yanfly.Param.ItemNegVar = eval(String(Yanfly.Parameters['Negative Variance']));
Yanfly.Param.ItemNameFmt = String(Yanfly.Parameters['Name Format']);
Yanfly.Param.ItemNameSpacing = String(Yanfly.Parameters['Name Spacing']);
Yanfly.Param.ItemBoostFmt = String(Yanfly.Parameters['Boost Format']);
Yanfly.Param.ItemSceneItem = String(Yanfly.Parameters['Updated Scene Item']);
Yanfly.Param.ItemSceneItem = eval(Yanfly.Param.ItemSceneItem);
Yanfly.Param.ItemShEquipped = String(Yanfly.Parameters['List Equipped Items']);
Yanfly.Param.ItemShEquipped = eval(Yanfly.Param.ItemShEquipped);
Yanfly.Param.ItemShowIcon = String(Yanfly.Parameters['Show Icon']);
Yanfly.Param.ItemShowIcon = eval(Yanfly.Param.ItemShowIcon);
Yanfly.Param.ItemIconSize = Number(Yanfly.Parameters['Icon Size']);
Yanfly.Param.ItemFontSize = Number(Yanfly.Parameters['Font Size']);
Yanfly.Param.ItemCmdAlign = String(Yanfly.Parameters['Command Alignment']);
Yanfly.Param.ItemRecoverFmt = String(Yanfly.Parameters['Recovery Format']);
Yanfly.Param.ItemAddState = String(Yanfly.Parameters['Add State']);
Yanfly.Param.ItemAddBuff = String(Yanfly.Parameters['Add Buff']);
Yanfly.Param.ItemRemoveState = String(Yanfly.Parameters['Remove State']);
Yanfly.Param.ItemRemoveBuff = String(Yanfly.Parameters['Remove Buff']);
Yanfly.Param.ItemMaxIcons = Number(Yanfly.Parameters['Maximum Icons']);
Yanfly.Param.ItemUseCmd = String(Yanfly.Parameters['Use Command']);
Yanfly.Param.ItemCarryFmt = String(Yanfly.Parameters['Carry Format']);
Yanfly.Param.ItemNoteParse = String(Yanfly.Parameters['Midgame Note Parsing']);
Yanfly.Param.ItemNoteParse = eval(Yanfly.Param.ItemNoteParse);
//=============================================================================
// DataManager
//=============================================================================
Yanfly.Item.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function () {
if (!Yanfly.Item.DataManager_isDatabaseLoaded.call(this)) return false;
if (!Yanfly._loaded_YEP_ItemCore) {
this.setDatabaseLengths();
this.processItemCoreNotetags($dataItems);
this.processItemCoreNotetags($dataWeapons);
this.processItemCoreNotetags($dataArmors);
Yanfly._loaded_YEP_ItemCore = true;
}
return true;
};
DataManager.processItemCoreNotetags = function (group) {
var note1 = /<(?:RANDOM VARIANCE):[ ](\d+)>/i;
var note2 = /<(?:NONINDEPENDENT ITEM|not independent item)>/i;
var note3 = /<(?:PRIORITY NAME)>/i;
for (var n = 1; n < group.length; n++) {
var obj = group[n];
var notedata = obj.note.split(/[\r\n]+/);
obj.randomVariance = Yanfly.Param.ItemRandomVariance;
obj.textColor = 0;
if (Imported.YEP_CoreEngine) obj.textColor = Yanfly.Param.ColorNormal;
obj.nonIndependent = false;
obj.setPriorityName = false;
obj.infoEval = '';
obj.infoTextTop = '';
obj.infoTextBottom = '';
obj.onCreationEval = '';
var evalMode = 'none';
for (var i = 0; i < notedata.length; i++) {
var line = notedata[i];
if (line.match(note1)) {
obj.randomVariance = parseInt(RegExp.$1);
} else if (line.match(note2)) {
obj.nonIndependent = true;
} else if (line.match(note3)) {
obj.setPriorityName = true;
} else if (line.match(/<(?:INFO EVAL)>/i)) {
evalMode = 'info eval';
} else if (line.match(/<\/(?:INFO EVAL)>/i)) {
evalMode = 'none';
} else if (line.match(/<(?:INFO TEXT TOP)>/i)) {
evalMode = 'info text top';
} else if (line.match(/<\/(?:INFO TEXT TOP)>/i)) {
evalMode = 'none';
} else if (line.match(/<(?:INFO TEXT BOTTOM)>/i)) {
evalMode = 'info text bottom';
} else if (line.match(/<\/(?:INFO TEXT BOTTOM)>/i)) {
evalMode = 'none';
} else if (evalMode === 'info eval') {
obj.infoEval = obj.infoEval + line + '\n';
} else if (evalMode === 'info text top') {
if (obj.infoTextTop !== '') obj.infoTextTop += '\n';
obj.infoTextTop = obj.infoTextTop + line;
} else if (evalMode === 'info text bottom') {
if (obj.infoTextBottom !== '') obj.infoTextBottom += '\n';
obj.infoTextBottom = obj.infoTextBottom + line;
} else if (line.match(/<(?:TEXT COLOR):[ ](\d+)>/i)) {
obj.textColor = parseInt(RegExp.$1);
} else if (line.match(/<(?:ON CREATE EVAL|ON CREATION EVAL)>/i)) {
evalMode = 'on create eval';
} else if (line.match(/<\/(?:ON CREATE EVAL|ON CREATION EVAL)>/i)) {
evalMode = 'none';
} else if (evalMode === 'on create eval') {
obj.onCreationEval = obj.onCreationEval + line + '\n';
}
}
}
};
DataManager.setDatabaseLengths = function () {
this._baseItemsLength = $dataItems.length
this._baseWeaponsLength = $dataWeapons.length
this._baseArmorsLength = $dataArmors.length
};
Yanfly.Item.DataManager_createGameObjects =
DataManager.createGameObjects;
DataManager.createGameObjects = function () {
Yanfly.Item.DataManager_createGameObjects.call(this);
this.createIndependentObjects();
};
DataManager.createIndependentObjects = function () {
DataManager.createIndependentGroups();
this.loadIndependentItems();
};
DataManager.loadIndependentItems = function () {
if (Yanfly.Param.ItemMaxItems > 0) {
var difItems = $dataItems.length - DataManager._baseItemsLength;
$dataItems.splice(DataManager._baseItemsLength, difItems);
this.setIndependentLength($dataItems);
$dataItems = $dataItems.concat(this._independentItems);
}
if (Yanfly.Param.ItemMaxWeapons > 0) {
var difWeapons = $dataWeapons.length - DataManager._baseWeaponsLength;
$dataWeapons.splice(DataManager._baseWeaponsLength, difWeapons);
this.setIndependentLength($dataWeapons);
$dataWeapons = $dataWeapons.concat(this._independentWeapons);
}
if (Yanfly.Param.ItemMaxArmors > 0) {
var difArmors = $dataArmors.length - DataManager._baseArmorsLength;
$dataArmors.splice(DataManager._baseArmorsLength, difArmors);
this.setIndependentLength($dataArmors);
$dataArmors = $dataArmors.concat(this._independentArmors);
}
};
DataManager.setIndependentLength = function (group) {
for (;;) {
if (group.length > Yanfly.Param.ItemStartingId) break;
group.push(null);
}
};
DataManager.saveGameWithoutRescue = function (savefileId) {
var json = JsonEx.stringify(this.makeSaveContents());
StorageManager.save(savefileId, json);
this._lastAccessedId = savefileId;
var globalInfo = this.loadGlobalInfo() || [];
globalInfo[savefileId] = this.makeSavefileInfo();
this.saveGlobalInfo(globalInfo);
return true;
};
Yanfly.Item.DataManager_makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function () {
var contents = Yanfly.Item.DataManager_makeSaveContents.call(this);
contents.items = this._independentItems;
contents.weapons = this._independentWeapons;
contents.armors = this._independentArmors;
return contents;
};
Yanfly.Item.DataManager_extractSaveContents =
DataManager.extractSaveContents;
DataManager.extractSaveContents = function (contents) {
Yanfly.Item.DataManager_extractSaveContents.call(this, contents);
this._independentItems = contents.items || [];
this._independentWeapons = contents.weapons || [];
this._independentArmors = contents.armors || [];
this.loadIndependentItems();
};
DataManager.createIndependentGroups = function () {
this._independentItems = [];
this._independentWeapons = [];
this._independentArmors = [];
};
DataManager.isIndependent = function (item) {
if (!item) return false;
if (DataManager.isBattleTest()) return false;
if (item.nonIndependent) return false;
if (DataManager.isItem(item)) return Yanfly.Param.ItemMaxItems > 0;
if (DataManager.isWeapon(item)) return Yanfly.Param.ItemMaxWeapons > 0;
if (DataManager.isArmor(item)) return Yanfly.Param.ItemMaxArmors > 0;
return false;
};
DataManager.registerNewItem = function (item) {
if (!this.isNewItemValid(item)) return item;
var newItem = JsonEx.makeDeepCopy(item);
this.addNewIndependentItem(item, newItem);
return newItem;
};
DataManager.isNewItemValid = function (item) {
if (!item) return false;
if (item.baseItemId) return false;
return item.id === this.getDatabase(item).indexOf(item);
};
DataManager.addNewIndependentItem = function (baseItem, newItem) {
newItem.id = this.getDatabase(baseItem).length;
ItemManager.setNewIndependentItem(baseItem, newItem);
ItemManager.customizeNewIndependentItem(baseItem, newItem);
ItemManager.onCreationEval(baseItem, newItem);
this.getDatabase(baseItem).push(newItem);
this.getContainer(baseItem).push(newItem);
};
DataManager.removeIndependentItem = function (item) {
if (!item) return;
if (this.independentItemIsUsed(item)) return;
var container = this.getContainer(item);
var database = this.getDatabase(item);
var index = container.indexOf(item);
container[index] = null;
var index = database.indexOf(item);
database[index] = null;
};
DataManager.independentItemIsUsed = function (item) {
if ($gameParty.numItems(item) > 0) return false;
for (var i = 0; i < $dataActors.length; ++i) {
var actor = $gameActors.actor(i);
if (!actor) continue;
if (actor.equips().contains(item)) return true;
}
return false;
};
DataManager.getDatabase = function (item) {
if (!item) return [];
if (DataManager.isItem(item)) return $dataItems;
if (DataManager.isWeapon(item)) return $dataWeapons;
if (DataManager.isArmor(item)) return $dataArmors;
return [];
};
DataManager.getContainer = function (item) {
if (!item) return [];
if (DataManager.isItem(item)) return this._independentItems;
if (DataManager.isWeapon(item)) return this._independentWeapons;
if (DataManager.isArmor(item)) return this._independentArmors;
return [];
};
DataManager.getBaseItem = function (item) {
if (!this.isIndependent(item)) return item;
if (!item.baseItemId) return item;
var baseItemId = item.baseItemId;
var baseItem = this.getDatabase(item)[baseItemId];
return baseItem;
};
//=============================================================================
// ItemManager
//=============================================================================
function ItemManager() {
throw new Error('This is a static class');
};
ItemManager.setNewIndependentItem = function (baseItem, newItem) {
newItem.baseItemId = baseItem.id;
newItem.baseItemName = baseItem.name;
newItem.baseItemPrice = baseItem.price;
newItem.baseItemIconIndex = baseItem.iconIndex;
newItem.namePrefix = '';
newItem.nameSuffix = '';
if (baseItem.setPriorityName) {
newItem.priorityName = baseItem.name;
} else {
newItem.priorityName = '';
}
newItem.boostCount = 0;
if (!Yanfly.Param.ItemNoteParse) newItem.note = '';
};
ItemManager.customizeNewIndependentItem = function (baseItem, newItem) {
this.randomizeInitialItem(baseItem, newItem);
this.updateItemName(newItem);
};
ItemManager.randomizeInitialItem = function (baseItem, newItem) {
if ($gameTemp.varianceStock()) return;
if (DataManager.isItem(baseItem)) {
this.randomizeInitialEffects(baseItem, newItem);
} else {
this.randomizeInitialStats(baseItem, newItem);
}
};
ItemManager.randomizeInitialEffects = function (baseItem, newItem) {
if (baseItem.randomVariance <= 0) return;
var randomValue = baseItem.randomVariance * 2 + 1;
var offset = baseItem.randomVariance;
newItem.effects.forEach(function (effect) {
if (effect.code === Game_Action.EFFECT_RECOVER_HP) {
if (effect.value1 !== 0) {
var boost = Math.floor(Math.random() * randomValue - offset);
effect.value1 += boost * 0.01;
effect.value1 = parseFloat(effect.value1.toFixed(2));
effect.value1 = effect.value1.clamp(0, 1);
}
if (effect.value2 !== 0) {
effect.value2 += Math.floor(Math.random() * randomValue - offset);
}
}
if (effect.code === Game_Action.EFFECT_RECOVER_MP) {
if (effect.value1 !== 0) {
var boost = Math.floor(Math.random() * randomValue - offset);
effect.value1 += boost * 0.01;
effect.value1 = parseFloat(effect.value1.toFixed(2));
effect.value1 = effect.value1.clamp(0, 1);
}
if (effect.value2 !== 0) {
effect.value2 += Math.floor(Math.random() * randomValue - offset);
}
}
}, this);
};
ItemManager.randomizeInitialStats = function (baseItem, newItem) {
if (baseItem.randomVariance <= 0) return;
var randomValue = baseItem.randomVariance * 2 + 1;
var offset = baseItem.randomVariance;
for (var i = 0; i < 8; ++i) {
if (newItem.params[i] === 0) continue;
newItem.params[i] += Math.floor(Math.random() * randomValue - offset);
if (!Yanfly.Param.ItemNegVar && baseItem.params[i] >= 0) {
newItem.params[i] = Math.max(newItem.params[i], 0);
}
}
if (DataManager.isItem(baseItem)) {
type = 0
} else if (DataManager.isWeapon(baseItem)) {
type = 1
} else if (DataManager.isArmor(baseItem)) {
type = 2
}
newItem.note = baseItem.note
if (RJO && RJO.HE) {
RJO.HE.getDescParams(newItem, type);
}
};
ItemManager.setBaseName = function (item, value) {
item.baseItemName = value;
};
ItemManager.setNamePrefix = function (item, value) {
item.namePrefix = value;
if (eval(Yanfly.Param.ItemNameSpacing) && item.namePrefix.length > 0) {
item.namePrefix = item.namePrefix + ' ';
}
};
ItemManager.setNameSuffix = function (item, value) {
item.nameSuffix = value;
if (eval(Yanfly.Param.ItemNameSpacing) && item.nameSuffix.length > 0) {
item.nameSuffix = ' ' + item.nameSuffix;
}
};
ItemManager.setPriorityName = function (item, value) {
item.priorityName = value;
};
ItemManager.updateItemName = function (item) {
if (item.priorityName && item.priorityName.length > 0) {
item.name = item.priorityName;
return;
}
var prefix = item.namePrefix || '';
var baseName = item.baseItemName || '';
var suffix = item.nameSuffix || '';
var boostCount = item.boostCount || 0;
var fmt = Yanfly.Param.ItemBoostFmt;
var boostText = fmt.format(Yanfly.Util.toGroup(boostCount))
if (boostText === fmt.format(0)) {
boostText = '';
} else if (eval(Yanfly.Param.ItemNameSpacing)) {
boostText = ' ' + boostText;
}
fmt = Yanfly.Param.ItemNameFmt;
item.name = fmt.format(prefix, baseName, suffix, boostText);
};
ItemManager.increaseItemBoostCount = function (item, value) {
value = value || 1;
if (!item.boostCount) item.boostCount = 0;
item.boostCount += value;
this.updateItemName(item);
};
ItemManager.onCreationEval = function (baseItem, newItem) {
var item = newItem;
if (item.onCreationEval === '') return;
var weapon = item;
var armor = item;
var baseWeapon = baseItem;
var baseArmor = baseItem;
var s = $gameSwitches._data;
var v = $gameVariables._data;
var code = item.onCreationEval;
try {
eval(code);
} catch (e) {
Yanfly.Util.displayError(e, code, 'ITEM CREATION CUSTOM CODE ERROR');
}
item.onCreationEval = '';
};
//=============================================================================
// Game_Temp
//=============================================================================
Game_Temp.prototype.enableVarianceStock = function () {
this._independentStock = true;
};
Game_Temp.prototype.disableVarianceStock = function () {
this._independentStock = false;
};
Game_Temp.prototype.varianceStock = function () {
return this._independentStock;
};
//=============================================================================
// Game_Actor
//=============================================================================
Yanfly.Item.Game_Actor_setup = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function (actorId) {
Yanfly.Item.Game_Actor_setup.call(this, actorId);
if ($gameTemp._initializeStartingMemberEquipment) return;
this.initIndependentEquips($dataActors[actorId].equips);
};
Game_Actor.prototype.initIndependentEquips = function (equips) {
var equips = this.convertInitEquips(equips);
this.equipInitIndependentEquips(equips);
this.releaseUnequippableItems(true);
this.recoverAll();
this.refresh();
};
Game_Actor.prototype.convertInitEquips = function (equips) {
var items = [];
for (var i = 0; i < equips.length; ++i) {
var equipId = equips[i];
if (equipId <= 0) continue;
var equipType = $dataSystem.equipTypes[i + 1];
if (equipType === $dataSystem.equipTypes[1] ||
(i === 1 && this.isDualWield())) {
var equip = $dataWeapons[equipId];
} else {
var equip = $dataArmors[equipId];
}
items.push(equip);
}
return items;
};
Game_Actor.prototype.equipInitIndependentEquips = function (equips) {
var slots = this.equipSlots();
var maxSlots = slots.length;
this._equips = [];
for (var i = 0; i < maxSlots; ++i) {
this._equips[i] = new Game_Item();
}
for (var i = 0; i < maxSlots; ++i) {
var slotType = slots[i];
var equip = this.grabInitEquips(equips, slotType);
if (DataManager.isIndependent(equip) && this.canEquip(equip)) {
var array = $gameParty.gainIndependentItem(equip, 1)
if (array instanceof Array) {
newItem = array[0];
this.changeEquip(i, newItem);
}
} else if (this.canEquip(equip)) {
this._equips[i].setObject(equip);
}
}
};
Game_Actor.prototype.grabInitEquips = function (equips, slotType) {
var item = null;
for (var i = 0; i < equips.length; ++i) {
var equip = equips[i];
if (!equip) continue;
if (slotType === 1 && DataManager.isWeapon(equip)) {
item = equip;
break;
} else if (equip.etypeId === slotType) {
item = equip;
break;
}
}
if (item) equips[i] = null;
return item;
};
Yanfly.Item.Game_Actor_hasWeapon = Game_Actor.prototype.hasWeapon;
Game_Actor.prototype.hasWeapon = function (weapon) {
if (this.hasBaseItem(weapon)) return true;
return Yanfly.Item.Game_Actor_hasWeapon.call(this, weapon);
};
Yanfly.Item.Game_Actor_hasArmor = Game_Actor.prototype.hasArmor;
Game_Actor.prototype.hasArmor = function (armor) {
if (this.hasBaseItem(armor)) return true;
return Yanfly.Item.Game_Actor_hasArmor.call(this, armor);
};
Game_Actor.prototype.hasBaseItem = function (baseItem) {
if (!DataManager.isIndependent(baseItem)) return false;
var type = (DataManager.isWeapon(baseItem)) ? 'weapon' : 'armor';
for (var i = 0; i < this.equips().length; ++i) {
var equip = this.equips()[i];
if (!equip) continue;
if (!equip.baseItemId) continue;
if (DataManager.isWeapon(equip) && type === 'weapon') {
if (equip.baseItemId === baseItem.id) return true;
} else if (DataManager.isArmor(equip) && type === 'armor') {
if (equip.baseItemId === baseItem.id) return true;
}
}
return false;
};
Yanfly.Item.Game_Actor_changeEquipById = Game_Actor.prototype.changeEquipById;
Game_Actor.prototype.changeEquipById = function (etypeId, itemId) {
if (itemId > 0) {
var slotId = etypeId - 1;
if (this.equipSlots()[slotId] === 1) {
var baseItem = $dataWeapons[itemId];
} else {
var baseItem = $dataArmors[itemId];
}
if (!$gameParty.hasItem(baseItem)) {
$gameParty.gainItem(baseItem, 1);
}