dead-bunny/js/plugins/Nore_Formation.js
2025-01-12 01:21:39 -06:00

915 lines
25 KiB
JavaScript

var __extends =
(this && this.__extends) ||
(function () {
var extendStatics = function (d, b) {
extendStatics =
Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array &&
function (d, b) {
d.__proto__ = b;
}) ||
function (d, b) {
for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
};
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError(
"Class extends value " + String(b) + " is not a constructor or null"
);
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype =
b === null
? Object.create(b)
: ((__.prototype = b.prototype), new __());
};
})();
/*:ja
* @target MZ
* @author ル
*
*
* @command addRandomActor
* @text ランダムな怪人を追加
* @des ランダムな怪人を追加
*
* @command addGachaActor
* @text ガチャチケで怪人を追加
* @des ガチャチケで怪人を追加
*
*/
var Nore;
(function (Nore) {
var pluginName = "Nore_Formation";
PluginManager.registerCommand(pluginName, "addRandomActor", function (args) {
$slg.formation().addRandomMonster();
});
PluginManager.registerCommand(pluginName, "addGachaActor", function (args) {
$slg.formation().addGachaMonster();
});
})(Nore || (Nore = {}));
var MonsterRare;
(function (MonsterRare) {
MonsterRare[(MonsterRare["none"] = -1)] = "none";
MonsterRare[(MonsterRare["zako"] = 0)] = "zako";
MonsterRare[(MonsterRare["common"] = 1)] = "common";
MonsterRare[(MonsterRare["rare"] = 2)] = "rare";
MonsterRare[(MonsterRare["sr"] = 3)] = "sr";
MonsterRare[(MonsterRare["ssr"] = 4)] = "ssr";
})(MonsterRare || (MonsterRare = {}));
var BattleObject = /** @class */ (function () {
function BattleObject() {
this._x = 0;
this._y = 0;
this._pattern = 0;
this._direction = 2;
this._opacity = 255;
this._animationCount = 0;
this._transparent = false;
}
BattleObject.prototype.id = function () {
return this._id;
};
BattleObject.prototype.actor = function () {
var actor = $gameActors.actor(this._actorId);
if (!actor) {
console.error("actorが見つかりません:" + this._actorId);
}
return actor;
};
BattleObject.prototype.characterName = function () {
return this.actor().characterName();
};
BattleObject.prototype.characterIndex = function () {
return this.actor().characterIndex();
};
BattleObject.prototype.pattern = function () {
return this._pattern < 3 ? this._pattern : 1;
};
BattleObject.prototype.updateAnimation = function () {
this.updateAnimationCount();
if (this._animationCount >= this.animationWait()) {
this.updatePattern();
this._animationCount = 0;
}
};
BattleObject.prototype.animationWait = function () {
return 9;
};
BattleObject.prototype.updateAnimationCount = function () {
this._animationCount++;
};
BattleObject.prototype.updatePattern = function () {
this._pattern = (this._pattern + 1) % this.maxPattern();
};
BattleObject.prototype.maxPattern = function () {
return 4;
};
BattleObject.prototype.direction = function () {
if (this._enemy) {
return 2;
} else {
return 8;
}
return this._direction;
};
BattleObject.prototype.opacity = function () {
return this._opacity;
};
BattleObject.prototype.blendMode = function () {
return 0;
};
BattleObject.prototype.bushDepth = function () {
return 0;
};
BattleObject.prototype.x = function () {
return this._x;
};
BattleObject.prototype.y = function () {
return this._y;
};
BattleObject.prototype.atk = function () {
return this.actor().atk;
};
BattleObject.prototype.isTransparent = function () {
return this._transparent;
};
BattleObject.prototype.tileId = function () {
return 0;
};
return BattleObject;
})();
var BattleUnit = /** @class */ (function (_super) {
__extends(BattleUnit, _super);
function BattleUnit(id, battleActor) {
var _this = _super.call(this) || this;
_this._knockBackFrame = 0;
_this._guardCount = 0;
_this._id = id;
_this._battleActor = battleActor;
_this._actorId = battleActor.actorId();
_this.setup();
return _this;
}
BattleUnit.prototype.setup = function () {
this._hp = this.mhp();
this._x = 0;
this._y = 520;
};
BattleUnit.prototype.mhp = function () {
return this.battleActor().mhp();
};
BattleUnit.prototype.battleActor = function () {
return this._battleActor;
};
BattleUnit.prototype.hp = function () {
return this._hp;
};
BattleUnit.prototype.isDead = function () {
return this._hp <= 0;
};
BattleUnit.prototype.hpRate = function () {
return this.hp() / this.mhp();
};
return BattleUnit;
})(BattleObject);
var BattleUnitDir2 = /** @class */ (function (_super) {
__extends(BattleUnitDir2, _super);
function BattleUnitDir2(battleActor, disable) {
var _this = _super.call(this, -1, battleActor) || this;
_this._battleActor = battleActor;
_this._disable = disable;
return _this;
}
BattleUnitDir2.prototype.direction = function () {
return 2;
};
BattleUnitDir2.prototype.opacity = function () {
if (this._disable) {
return 120;
} else {
return _super.prototype.opacity.call(this);
}
};
BattleUnitDir2.prototype.characterName = function () {
return this._battleActor.characterName();
};
BattleUnitDir2.prototype.characterIndex = function () {
return this._battleActor.characterIndex();
};
BattleUnitDir2.prototype.pattern = function () {
return 1;
};
return BattleUnitDir2;
})(BattleUnit);
var Sprite_SlotUnit = /** @class */ (function (_super) {
__extends(Sprite_SlotUnit, _super);
function Sprite_SlotUnit(battleUnit, rect) {
var _this = _super.call(this, battleUnit) || this;
_this._rect = rect;
_this._battleUnit = battleUnit;
_this._character = battleUnit;
_this.update();
_this._isReady = _this.bitmap.isReady();
return _this;
}
Sprite_SlotUnit.prototype.battleUnit = function () {
return this._battleUnit;
};
Sprite_SlotUnit.prototype.updatePosition = function () {
this.x = this._rect.x + 25;
this.y = this._rect.y;
this.z = 1;
};
Sprite_SlotUnit.prototype.isImageChanged = function () {
if (!this._isReady) {
return true;
}
return _super.prototype.isImageChanged.call(this);
};
Sprite_SlotUnit.prototype.setCharacterBitmap = function () {
_super.prototype.setCharacterBitmap.call(this);
this._isReady = this.bitmap.isReady();
};
return Sprite_SlotUnit;
})(Sprite_Character);
var Slot;
(function (Slot) {
Slot[(Slot["slot1"] = 1)] = "slot1";
Slot[(Slot["slot2"] = 2)] = "slot2";
Slot[(Slot["slot3"] = 3)] = "slot3";
Slot[(Slot["slot4"] = 4)] = "slot4";
Slot[(Slot["slot5"] = 5)] = "slot5";
})(Slot || (Slot = {}));
var Formation = /** @class */ (function () {
function Formation() {
this._allMembers = [];
this._battleMembers = [];
this._changed = false; // 並びやメンバーに変更があった場合
this._filterChanged = false; //
this._levelUp = false; //
this._id = 0;
}
Formation.prototype.isComplete = function () {
return this._allMembers.length == this.totalKaijinNum();
};
Formation.prototype.totalKaijinNum = function () {
var n = 0;
for (var k in KAIJIN_PARAMS) {
n++;
}
return n;
};
Formation.prototype.hasZako = function () {
for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
var b = _a[_i];
if (!b) {
continue;
}
if (b.actor().isZako()) {
return true;
}
}
return false;
};
Formation.prototype.onLevelUp = function () {
this._changed = true;
this._filterChanged = true;
this._levelUp = true;
};
Formation.prototype.isLevelUp = function () {
return this._levelUp;
};
Formation.prototype.clearLevelUp = function () {
this._levelUp = false;
};
Formation.prototype.nextId = function () {
this._id++;
return this._id;
};
Formation.prototype.isBattleMamber = function (actor) {
for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
var b = _a[_i];
if (!b) {
continue;
}
if (b.actorId() == actor.actorId()) {
return true;
}
}
return false;
};
Formation.prototype.kaijinExists = function () {
for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
var b = _a[_i];
if (!b) {
continue;
}
if (b.actor().isKaijin()) {
return true;
}
}
return false;
};
Formation.prototype.kaijinCount = function () {
var n = 0;
for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
var b = _a[_i];
if (!b) {
continue;
}
if (b.actor().isKaijin()) {
n++;
}
}
return n;
};
Formation.prototype.isEmpty = function (slot) {
if (this._battleMembers.length <= slot) {
return false;
}
return this._battleMembers[slot] == 0;
};
Formation.prototype.saveBattle = function () {};
Formation.prototype.restoreBattle = function () {};
Formation.prototype.leader = function () {
if (!this._leader) {
this._leader = new BattleActor(this.nextId(), 10, 1);
}
return this._leader;
};
Formation.prototype.addMember = function (actorId, level) {
var actor = new BattleActor(this.nextId(), actorId, level);
this._allMembers.push(actor);
return actor.id();
};
Formation.prototype.allMembers = function () {
if (!$gameSwitches.value(325)) {
return this._allMembers;
}
var members = [];
for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
var m = _a[_i];
if (!m.isZako()) {
members.push(m);
}
}
return members;
};
Formation.prototype.battleMembers = function () {
var result = [];
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
result.push(this.findBattleActor(n));
} else {
result.push(null);
}
}
return result;
};
Formation.prototype.deadMembers = function () {
var result = [];
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
var b = this.findBattleActor(n);
if (b.isDead()) {
result.push(b);
}
}
}
return result;
};
Formation.prototype.existBattleMembers = function () {
var result = [];
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
result.push(this.findBattleActor(n));
}
}
return result;
};
Formation.prototype.battleMemberIds = function () {
return this._battleMembers.concat();
};
Formation.prototype.findBattleActor = function (id) {
if (id == -1) {
return;
}
for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
var b = _a[_i];
if (b.id() == id) {
return b;
}
}
console.error("IDが" + id + "のBattleActorが見つかりません");
return null;
};
Formation.prototype.findBattleActorByActorId = function (id) {
for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
var b = _a[_i];
if (b.actorId() == id) {
return b;
}
}
console.error("IDが" + id + "のBattleActorが見つかりません");
return null;
};
Formation.prototype.maxBattleMembers = function () {
return 5;
};
Formation.prototype.totalPower = function () {
var n = 0;
for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
var m = _a[_i];
if (m) {
n += m.power();
}
}
return n;
};
Formation.prototype.slotBy = function (id) {
for (var i = 0; i < this._battleMembers.length; i++) {
var m = this._battleMembers[i];
if (m) {
var actor = this.findBattleActor(m);
if (actor && actor.id() == id) {
return i;
}
}
}
return -1;
};
Formation.prototype.battleMemberAt = function (index) {
var id = this._battleMembers[index];
if (id >= 0) {
return this.findBattleActor(id);
}
return null;
};
Formation.prototype.slotOf = function (actor) {
for (var i = 0; i < this._battleMembers.length; i++) {
var m = this._battleMembers[i];
if (m) {
if (actor.id() == m) {
return i;
}
}
}
return -1;
};
Formation.prototype.setActor = function (slotId, actor) {
var currentSlot = this.slotOf(actor);
if (currentSlot >= 0) {
this._battleMembers[currentSlot] = -1;
}
if (actor) {
this._battleMembers[slotId] = actor.id();
} else {
this._battleMembers[slotId] = -1;
}
this._changed = true;
this.calcPassiveSkill();
};
Formation.prototype.swap = function (slotId1, slotId2) {
var temp1 = this._battleMembers[slotId1];
var temp2 = this._battleMembers[slotId2];
this._battleMembers[slotId1] = temp2;
this._battleMembers[slotId2] = temp1;
this._changed = true;
this.calcPassiveSkill();
};
Formation.prototype.calcPassiveSkill = function () {
this._passiveSkills = new PassiveSkills();
var battleMembers = this.battleMembers();
for (var i = 0; i < this.maxBattleMembers(); i++) {
var battleActor = this.battleMemberAt(i);
if (!battleActor) {
continue;
}
var passiveSkills = battleActor.createPassiveSkillList(battleMembers);
if (passiveSkills.length > 0) {
for (
var _i = 0, passiveSkills_1 = passiveSkills;
_i < passiveSkills_1.length;
_i++
) {
var s = passiveSkills_1[_i];
this._passiveSkills.push(s);
}
}
}
for (var _a = 0, _b = this.allMembers(); _a < _b.length; _a++) {
var m = _b[_a];
m.setPassiveSkills(this._passiveSkills);
}
};
Formation.prototype.addRandomMonster = function () {
var actorId = this.selectRandomMonster();
this.joinMonster(actorId);
};
Formation.prototype.addGachaMonster = function () {
var t = $gameParty.useGachaTicket();
if (!t) {
console.error("ガチャチケを持っていません");
return;
}
if ($gameParty.gachaTicket() == 0) {
$gameSwitches.setValue(33, false);
}
var actorId = t.actorId();
this.joinMonster(actorId);
};
Formation.prototype.selectRandomMonster = function () {
var actorId = this.roulette();
if ($slg.facilityInfo().hasFacility(65)) {
if (this.isExists(actorId)) {
p("怪人かぶり1:" + actorId);
actorId = this.roulette();
if ($slg.facilityInfo().hasFacility(66)) {
if (this.isExists(actorId)) {
p("怪人かぶり2:" + actorId);
actorId = this.roulette();
}
if (this.isExists(actorId)) {
p("怪人かぶり3:" + actorId);
actorId = this.roulette();
}
}
}
}
return actorId;
};
Formation.prototype.joinMonster = function (actorId) {
if (actorId < 0) {
console.error("不正な怪人が追加されました");
return;
}
var actor = $gameActors.actor(actorId);
var battleActor = new BattleActor(-1, actorId, 1);
$gameVariables.setValue(59, battleActor.name());
if (this.isExists(actor.actorId())) {
$gameSwitches.setValue(59, true);
var battleActorId = this.levelUp(actor.actorId());
$gameTemp.lastJoinBattleActorId = battleActorId;
$gameTemp.lastJoinBattleActorNew = false;
var g = this.goldByRare(battleActor.rare());
$gameVariables.setValue(90, g);
if (g > 0) {
p("かぶりG:" + g);
$gameParty.gainGold(g);
}
} else {
$gameSwitches.setValue(59, false);
var battleActorId = this.addMember(actor.actorId(), 1);
$gameTemp.lastJoinBattleActorId = battleActorId;
$gameTemp.lastJoinBattleActorNew = true;
}
var rare = this.findBattleActorByActorId(actor.actorId()).rare();
var rareEffect = rare >= MonsterRare.sr;
$gameSwitches.setValue(28, rareEffect);
$gameSwitches.setValue(29, rare == MonsterRare.ssr);
};
Formation.prototype.goldByRare = function (rare) {
switch (rare) {
case MonsterRare.common:
return 50;
case MonsterRare.rare:
return 100;
case MonsterRare.sr:
return 150;
case MonsterRare.ssr:
return 200;
}
return 0;
};
Formation.prototype.roulette = function () {
var rare = new Gacha().decideRare();
var candidates = this.monsterCandidates(rare);
if (candidates.length == 0) {
console.error("怪人を追加できません");
return -1;
}
var random = Math.randomInt(candidates.length);
var actorId = candidates[random];
return actorId;
};
Formation.prototype.isExists = function (actorId) {
for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
var b = _a[_i];
if (b.actorId() == actorId) {
return true;
}
}
return false;
};
Formation.prototype.monsterCandidates = function (r) {
var result = [];
var minLevel = 1;
var maxLevel =
1 + $slg.facilityInfo().findMaxFacilityLevel(FacilityType.monster);
for (var i = 102; i < 150; i++) {
if (!KAIJIN_PARAMS[i]) {
continue;
}
var rare = KAIJIN_PARAMS[i][0];
if (isNaN(rare)) {
console.error("怪人のレベルが不正です:" + i);
continue;
}
if (r == rare) {
result.push(i);
}
}
return result;
};
Formation.prototype.leftTarget = function () {
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
var b = this.findBattleActor(n);
if (b.hp() > 0) {
return b;
}
}
}
return null;
};
Formation.prototype.priorityTarget = function () {
var targets = [];
var battleCount = 0;
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
var b = this.findBattleActor(n);
if (b.hp() > 0) {
var value = this.priorityByBattlerCount(battleCount);
value += this.provokeValue(b);
for (var i = 0; i < value; i++) {
targets.push(b);
}
battleCount++;
}
}
}
if (targets.length == 0) {
return null;
}
var dice = Math.randomInt(targets.length);
return targets[dice];
};
Formation.prototype.aliveTargets = function () {
var targets = [];
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
var b = this.findBattleActor(n);
if (b.hp() > 0) {
targets.push(b);
}
}
}
return targets;
};
Formation.prototype.aliveTargetFrontNum = function (num) {
var targets = this.aliveTargets();
if (targets.length <= num) {
return targets;
}
var result = [];
for (var i = 0; i < num; i++) {
result.push(targets[i]);
}
return result;
};
Formation.prototype.aliveTargetNum = function (num) {
var targets = this.aliveTargets();
if (targets.length <= num) {
return targets;
}
var result = [];
var list = this.aliveTargetCandidates();
for (var i = 0; i < num; i++) {
while (list.length > 0) {
var b = list.pop();
if (result.contains(b)) {
continue;
}
result.push(b);
break;
}
}
return result;
};
Formation.prototype.aliveTargetCandidates = function () {
var result = [];
var battleCount = 0;
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
var b = this.findBattleActor(n);
if (b.hp() > 0) {
var value = this.priorityByBattlerCount(battleCount);
value += this.provokeValue(b);
for (var i = 0; i < value; i++) {
result.push(b);
}
battleCount++;
}
}
}
result = Nore.shuffle(result);
return result;
};
Formation.prototype.provokeValue = function (b) {
return this._passiveSkills.provokeValue(b);
};
Formation.prototype.aliveTargetTop = function () {
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
var b = this.findBattleActor(n);
if (b.hp() > 0) {
return [b];
}
}
}
return [];
};
Formation.prototype.aliveTargetBottom = function () {
for (var i = 0; i < this._battleMembers.length; i++) {
var n = this._battleMembers[this._battleMembers.length - 1 - i];
if (n) {
var b = this.findBattleActor(n);
if (b.hp() > 0) {
return [b];
}
}
}
return [];
};
Formation.prototype.priorityByBattlerCount = function (battleCount) {
switch (battleCount) {
case 0:
return 8;
case 1:
return 5;
case 2:
return 3;
case 3:
return 2;
default:
return 1;
}
};
Formation.prototype.isAllDead = function () {
for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
var n = _a[_i];
if (n) {
var b = this.findBattleActor(n);
if (b.hp() > 0) {
return false;
}
}
}
return true;
};
Formation.prototype.recoverAll = function () {
for (var _i = 0, _a = this.existBattleMembers(); _i < _a.length; _i++) {
var a = _a[_i];
a.recoverAll();
}
};
Formation.prototype.levelUp = function (actorId) {
for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
var b = _a[_i];
if (b.actorId() == actorId) {
b.levelUp();
if (this.trainingInfo().trainingActorId() == actorId) {
this.trainingInfo().clearTraining();
}
return b.id();
}
}
return -1;
};
Formation.prototype.isChanged = function () {
return this._changed;
};
Formation.prototype.clearChanged = function () {
this._changed = false;
};
Formation.prototype.isRareEnabled = function (r) {
if (this.isRareSelected(r)) {
return true;
}
var onCount = 0;
for (var f in this._rareFilter) {
if (this._rareFilter[f]) {
onCount++;
}
}
return onCount == 0;
};
Formation.prototype.isRareSelected = function (r) {
this._rareFilter = this._rareFilter || {};
for (var f in this._rareFilter) {
if (parseInt(f) == r) {
if (this._rareFilter[f]) {
return true;
}
}
}
return false;
};
Formation.prototype.clearRareFilter = function () {
this._rareFilter = {};
this._filterChanged = true;
};
Formation.prototype.clearElementFilter = function () {
this._elementFilter = {};
this._filterChanged = true;
};
Formation.prototype.putRareFilter = function (r) {
this._rareFilter = this._rareFilter || {};
this._rareFilter[r] = !this._rareFilter[r];
this._filterChanged = true;
};
Formation.prototype.isElementEnabled = function (r) {
if (this.isElementSelected(r)) {
return true;
}
var onCount = 0;
for (var f in this._elementFilter) {
if (this._elementFilter[f]) {
onCount++;
}
}
return onCount == 0;
};
Formation.prototype.isElementSelected = function (r) {
this._elementFilter = this._elementFilter || {};
for (var f in this._elementFilter) {
if (parseInt(f) == r) {
if (this._elementFilter[f]) {
return true;
}
}
}
return false;
};
Formation.prototype.putElementFilter = function (e) {
this._elementFilter = this._elementFilter || {};
this._elementFilter[e] = !this._elementFilter[e];
this._filterChanged = true;
};
Formation.prototype.filterChanged = function () {
return this._filterChanged;
};
Formation.prototype.clearFilterChanged = function () {
this._filterChanged = false;
};
Formation.prototype.sortValue = function () {
return MonsterSort.rare; //this._sortValue || MonsterSort.rare;
};
Formation.prototype.changeSort = function () {
this._sortValue = this._sortValue || MonsterSort.newArrival;
this._sortValue++;
if (this._sortValue > MonsterSort.element) {
this._sortValue = MonsterSort.newArrival;
}
this._filterChanged = true;
};
Formation.prototype.trainingInfo = function () {
this._trainingInfo = this._trainingInfo || new TrainingInfo();
return this._trainingInfo;
};
return Formation;
})();
var MonsterElement;
(function (MonsterElement) {
MonsterElement[(MonsterElement["none"] = -1)] = "none";
MonsterElement[(MonsterElement["flame"] = 0)] = "flame";
MonsterElement[(MonsterElement["water"] = 1)] = "water";
MonsterElement[(MonsterElement["wood"] = 2)] = "wood";
})(MonsterElement || (MonsterElement = {}));
var MonsterElementColor;
(function (MonsterElementColor) {
MonsterElementColor[(MonsterElementColor["flame"] = 11141120)] = "flame";
MonsterElementColor[(MonsterElementColor["water"] = 2237149)] = "water";
MonsterElementColor[(MonsterElementColor["wood"] = 43520)] = "wood";
})(MonsterElementColor || (MonsterElementColor = {}));
var MonsterElementStringColor;
(function (MonsterElementStringColor) {
MonsterElementStringColor["flame"] = "#aa0000";
MonsterElementStringColor["water"] = "#0000aa";
MonsterElementStringColor["wood"] = "#00aa00";
})(MonsterElementStringColor || (MonsterElementStringColor = {}));