-
Notifications
You must be signed in to change notification settings - Fork 24
/
Tactics_Teleport.js
177 lines (158 loc) · 5.59 KB
/
Tactics_Teleport.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
//=============================================================================
// TeleportSkill.js
//=============================================================================
/*:
* @plugindesc A teleportation skill for an ally or an enemy requested by strik156.
* Requires: TacticsSystem.js.
* @author Bilal El Moussaoui (https://twitter.com/arleq1n)
*
* @param Teleport Distance Formula
* @desc The formula of distance for teleport skill.
* @default a.mat/2
*
* @help
* Use the <Effect:teleport> tag in the note section of a skill to define it as a
* teleport skill.
*
* You can only choose an enemy, an ally or the user as a scope. All other
* parameters of the skill are defined in the same way as a normal skill.
*
* You can also define the distance of the teleportation by a formula that works
* in the same way as the damage formula by the tag <Formula:a.mat/2>.
*/
var TeleportSkill = TeleportSkill || {};
TeleportSkill.Parameters = PluginManager.parameters('Tactics_Teleport');
TeleportSkill.teleportFormula = String(TeleportSkill.Parameters['Teleport Distance Formula']);
//-----------------------------------------------------------------------------
// BattleManager
//
// The static class that manages battle progress.
TeleportSkill.BattleManager_isActive = BattleManager.isActive;
BattleManager.isActive = function() {
if (!this._logWindow.isBusy()) {
switch (this._battlePhase) {
case 'tile':
return true;
}
}
return TeleportSkill.BattleManager_isActive.call(this);
};
TeleportSkill.BattleManager_updatePlayerPhase = BattleManager.updatePlayerPhase;
BattleManager.updatePlayerPhase = function() {
switch (this._battlePhase) {
case 'tile':
this.updateTile();
default:
TeleportSkill.BattleManager_updatePlayerPhase.call(this);
break;
}
};
TeleportSkill.BattleManager_updateTarget = BattleManager.updateTarget;
BattleManager.updateTarget = function() {
TeleportSkill.BattleManager_updateTarget.call(this);
var x = $gameSelector.x;
var y = $gameSelector.y;
var select = $gameSelector.select();
var action = this.inputtingAction();
if ($gameSelector.isOk()) {
if ($gameMap.isOnTiles(x, y) && action.isTargetValid(select)) {
if (action.isTeleport()) {
var distance = action.evalTeleportFormula();
var event = this._subject.event();
$gameMap.makeRange(distance, event, true);
$gameSelector.savePosition();
this._battlePhase = 'tile';
}
}
}
};
BattleManager.updateTile = function() {
var x = $gameSelector.x;
var y = $gameSelector.y;
var select = $gameSelector.select();
var action = this.inputtingAction();
if ($gameSelector.isOk()) {
if ($gameMap.isOnTiles(x, y) && !select) {
SoundManager.playOk();
$gameTemp.setCancel(false);
action.setPosition(x, y);
this.setupAction();
$gameSelector.restorePosition();
} else {
SoundManager.playBuzzer();
}
}
if ($gameSelector.isCancelled()) {
SoundManager.playCancel();
this.previousTarget();
}
};
//-----------------------------------------------------------------------------
// Game_Action
//
// The game object class for a battle action.
TeleportSkill.Game_Action_initialize = Game_Action.prototype.initialize;
Game_Action.prototype.initialize = function(subject, forcing) {
TeleportSkill.Game_Action_initialize.call(this, subject, forcing);
this._positionX = -1;
this._positionY = -1;
};
Game_Action.prototype.isTileTarget = function() {
return this.item().meta['target'];
};
Game_Action.prototype.setPosition = function(x, y) {
this._positionX = x;
this._positionY = y;
};
Game_Action.prototype.isTeleport = function() {
if (this.item()) {
var param = this.item().meta['Effect'];
if (param) {
return param.trim() === 'Teleport';
}
}
return false;
};
Game_Action.prototype.evalTeleportFormula = function(target) {
try {
var item = this.item();
var a = this.subject();
var b = this.makeTargets().shift() || null;
var v = $gameVariables._data;
var value = Math.max(eval(item.meta['Formula'] || TeleportSkill.teleportFormula), 0);
if (isNaN(value)) value = 0;
return value;
} catch (e) {
return 0;
}
};
TeleportSkill.Game_Action_apply = Game_Action.prototype.apply;
Game_Action.prototype.apply = function(target) {
TeleportSkill.Game_Action_apply.call(this, target);
var result = target.result();
var effect = this.item().meta['Effect'];
if (result.isHit() && effect) {
effect.trim().split(',').forEach(function(effect) {
this.applyMetaEffect(target, effect);
}, this);
}
};
Game_Action.prototype.applyMetaEffect = function(target, effect) {
switch (effect) {
case 'Teleport':
this.itemEffectTeleport(target, effect);
break;
}
};
Game_Action.prototype.itemEffectTeleport = function(target, effect) {
target.setPosition(this._positionX, this._positionY);
this.makeSuccess(target);
};
TeleportSkill.Game_Action_testApply = Game_Action.prototype.testApply
Game_Action.prototype.testApply = function(target) {
return TeleportSkill.Game_Action_testApply.call(this, target) || this.isTeleport();
};
TeleportSkill.Game_Action_needCombatScene = Game_Action.prototype.needCombatScene;
Game_Action.prototype.needCombatScene = function() {
return TeleportSkill.Game_Action_needCombatScene.call(this) && !this.isTeleport();
};