-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScene_ItemBase.js
136 lines (116 loc) · 3.6 KB
/
Scene_ItemBase.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
//-----------------------------------------------------------------------------
// Scene_ItemBase
//
// The superclass of Scene_Item and Scene_Skill.
function Scene_ItemBase() {
this.initialize.apply(this, arguments);
}
Scene_ItemBase.prototype = Object.create(Scene_MenuBase.prototype);
Scene_ItemBase.prototype.constructor = Scene_ItemBase;
Scene_ItemBase.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_ItemBase.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
};
Scene_ItemBase.prototype.createActorWindow = function() {
this._actorWindow = new Window_MenuActor();
this._actorWindow.setHandler('ok', this.onActorOk.bind(this));
this._actorWindow.setHandler('cancel', this.onActorCancel.bind(this));
this.addWindow(this._actorWindow);
};
Scene_ItemBase.prototype.item = function() {
return this._itemWindow.item();
};
Scene_ItemBase.prototype.user = function() {
return null;
};
Scene_ItemBase.prototype.isCursorLeft = function() {
return this._itemWindow.index() % 2 === 0;
};
Scene_ItemBase.prototype.showSubWindow = function(window) {
window.x = this.isCursorLeft() ? Graphics.boxWidth - window.width : 0;
window.show();
window.activate();
};
Scene_ItemBase.prototype.hideSubWindow = function(window) {
window.hide();
window.deactivate();
this.activateItemWindow();
};
Scene_ItemBase.prototype.onActorOk = function() {
if (this.canUse()) {
this.useItem();
} else {
SoundManager.playBuzzer();
}
};
Scene_ItemBase.prototype.onActorCancel = function() {
this.hideSubWindow(this._actorWindow);
};
Scene_ItemBase.prototype.action=function(){
var action = new Game_Action(this.user());
action.setItemObject(this.item());
return action;
};
Scene_ItemBase.prototype.determineItem = function() {
var action = this.action();
if (action.isForFriend()) {
this.showSubWindow(this._actorWindow);
this._actorWindow.selectForItem(this.item());
} else {
this.useItem();
this.activateItemWindow();
}
};
Scene_ItemBase.prototype.useItem = function() {
this.playSeForItem();
this.user().useItem(this.item());
this.applyItem();
this.checkCommonEvent();
this.checkGameover();
this._actorWindow.refresh();
};
Scene_ItemBase.prototype.activateItemWindow = function() {
this._itemWindow.refresh();
this._itemWindow.activate();
};
Scene_ItemBase.prototype.itemTargetActors =function(){
var action = this.action();
if (!action.isForFriend()) {
return [];
} else if (action.isForAll()) {
return $gameParty.members();
} else {
return [$gameParty.members()[this._actorWindow.index()]];
}
};
Scene_ItemBase.prototype.canUse = function() {
var user = this.user();
if(user){
return user.canUse(this.item()) && this.isItemEffectsValid();
}
return false;
};
Scene_ItemBase.prototype.isItemEffectsValid = function() {
var action = this.action();
return this.itemTargetActors().some(function(target) {
return action.testApply(target);
}, this);
};
Scene_ItemBase.prototype.applyItem =function(){
var action = this.action();
var targets = this.itemTargetActors();
targets.forEach(function(battler) {
var repeats = action.numRepeats();
for (var i = 0; i < repeats; i++) {
action.apply(battler);
}
});
action.applyGlobal();
};
Scene_ItemBase.prototype.checkCommonEvent = function() {
if ($gameTemp.isCommonEventReserved()) {
SceneManager.goto(Scene_Map);
}
};