查看: 4131|回复: 1

[原创发布] 翻译BattleManager类

[复制链接]
梦石
0
星屑
669
在线时间
71 小时
注册时间
2022-4-18
回帖
20
发表于 2022-4-24 17:06:36 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
作者:玉米/玉粥/m1615690513

[pre lang="javascript"]/**
* 战斗管理
* @constructor
*/
function BattleManager() {
    throw new Error('This is a static class');
}

/**
* 初始化一场战斗
* @param troopId 敌军部队ID
* @param canEscape 可以逃跑
* @param canLose 可以失败
*/
BattleManager.setup = function (troopId, canEscape, canLose) {
    //初始战斗运行时
    this.initMembers();
    /**
     * 可以逃跑
     */
    this._canEscape = canEscape;
    /**
     * 可以失败
     */
    this._canLose = canLose;
    /**
     * 敌军部队初始化
     */
    $gameTroop.setup(troopId);
    /**
     * 战斗显示内容回调通知
     */
    $gameScreen.onBattleStart();
    /**
     * 生成逃跑率
     */
    this.makeEscapeRatio();
};

/**
* 初始化战斗运行时
*/
BattleManager.initMembers = function () {
    /**
     * 阶段
     * @type {string}
     * @private
     */
    this._phase = 'init';
    /**
     * 可以逃跑
     * @type {boolean}
     * @private
     */
    this._canEscape = false;

    /**
     * 可以失败
     * @type {boolean}
     * @private
     */
    this._canLose = false;
    /**
     * 是否为测试战斗
     * @type {boolean}
     * @private
     */
    this._battleTest = false;
    /**
     * 事件回调
     * @type {function}
     * @private
     */
    this._eventCallback = null;
    /**
     * 先发制人
     * @type {boolean}
     * @private
     */
    this._preemptive = false;
    /**
     * 意外遇敌
     * @type {boolean}
     * @private
     */
    this._surprise = false;
    /**
     * 角色号
     * @type {number}
     * @private
     */
    this._actorIndex = -1;
    /**
     * 强制战斗人员
     * @type {Game_Battler}
     * @private
     */
    this._actionForcedBattler = null;
    /**
     * 地图背景音乐
     * @type {Object}
     * @private
     */
    this._mapBgm = null;
    /**
     * 地图背景音效
     * @type {Object}
     * @private
     */
    this._mapBgs = null;
    /**
     * 可以行动的战斗人员
     * @type {*[]}
     * @private
     */
    this._actionBattlers = [];
    /**
     * 战斗人
     * @type {Game_Battler}
     * @private
     */
    this._subject = null;
    /**
     * 行动指令
     * @type {Game_Action}
     * @private
     */
    this._action = null;
    /**
     * 被作用的目标
     * @type {*[敌人,友方]}
     * @private
     */
    this._targets = [];
    /**
     * 战斗日志窗口
     * @type {Window_BattleLog}
     * @private
     */
    this._logWindow = null;
    /**
     * 战斗状态窗口
     * @type {Window_BattleStatus}
     * @private
     */
    this._statusWindow = null;
    /**
     * 地图屏幕上的精灵集
     * @type {Spriteset_Map}
     * @private
     */
    this._spriteset = null;
    /**
     * 逃跑概率
     * @type {number}
     * @private
     */
    this._escapeRatio = 0;
    /**
     * 逃脱
     * @type {boolean}
     * @private
     */
    this._escaped = false;
    /**
     * 怪物掉落奖励
     * @type {{}}
     * @private
     */
    this._rewards = {};
    /**
     * 强制回合状态
     * @type {boolean}
     * @private
     */
    this._turnForced = false;
};

/**
* 战斗测试
* @returns {boolean}
*/
BattleManager.isBattleTest = function () {
    return this._battleTest;
};

/**
* 设置战斗测试状态
* @param {boolean} battleTest
*/
BattleManager.setBattleTest = function (battleTest) {
    this._battleTest = battleTest;
};

/**
* 设置事件回调
* @param {Function} callback
*/
BattleManager.setEventCallback = function (callback) {
    this._eventCallback = callback;
};

/**
* 设置日志窗口
* @param {Window_BattleLog} logWindow
*/
BattleManager.setLogWindow = function (logWindow) {
    this._logWindow = logWindow;
};

/**
* 设置状态
* @param {Window_BattleStatus} statusWindow
*/
BattleManager.setStatusWindow = function (statusWindow) {
    this._statusWindow = statusWindow;
};

/**
* 设置地图屏幕上的精灵集
* @param {Spriteset_Map} spriteset
*/
BattleManager.setSpriteset = function (spriteset) {
    this._spriteset = spriteset;
};

/**
* 遇敌时
*/
BattleManager.onEncounter = function () {
    //先发制人
    this._preemptive = (Math.random() < this.ratePreemptive());
    //遭遇突袭
    this._surprise = (Math.random() < this.rateSurprise() && !this._preemptive);
};

/**
* 先发制人率
* @returns {Number}
*/
BattleManager.ratePreemptive = function () {
    return $gameParty.ratePreemptive($gameTroop.agility());
};

/**
* 遭遇突袭率
* @returns {Number}
*/
BattleManager.rateSurprise = function () {
    return $gameParty.rateSurprise($gameTroop.agility());
};

/**
* 保存背景音乐和音效
*/
BattleManager.saveBgmAndBgs = function () {
    //地图背景音乐
    this._mapBgm = AudioManager.saveBgm();
    //地图背景音乐
    this._mapBgs = AudioManager.saveBgs();
};

/**
* 播放战斗背景音乐
*/
BattleManager.playBattleBgm = function () {
    AudioManager.playBgm($gameSystem.battleBgm());
    AudioManager.stopBgs();
};

/**
* 播放胜利的音效
*/
BattleManager.playVictoryMe = function () {
    AudioManager.playMe($gameSystem.victoryMe());
};

/**
* 播放失败的音效
*/
BattleManager.playDefeatMe = function () {
    AudioManager.playMe($gameSystem.defeatMe());
};

/**
* 重放播放战斗背景音乐
*/
BattleManager.replayBgmAndBgs = function () {
    if (this._mapBgm) {
        AudioManager.replayBgm(this._mapBgm);
    } else {
        AudioManager.stopBgm();
    }
    if (this._mapBgs) {
        AudioManager.replayBgs(this._mapBgs);
    }
};

/**
* 生成逃跑率
*/
BattleManager.makeEscapeRatio = function () {
    this._escapeRatio = 0.5 * $gameParty.agility() / $gameTroop.agility();
};

/**
* 更新成语变量
*/
BattleManager.update = function () {
    if (!this.isBusy() && !this.updateEvent()) {
        //匹配阶段
        switch (this._phase) {
            //战斗开始
            case 'start':
                this.startInput();
                break;
            //更新回合
            case 'turn':
                this.updateTurn();
                break;
            //指令阶段
            case 'action':
                this.updateAction();
                break;
            //回合结束
            case 'turnEnd':
                this.updateTurnEnd();
                break;
            //战斗结束
            case 'battleEnd':
                this.updateBattleEnd();
                break;
        }
    }
};

/**
* 更新不同阶段的指令事件
* @returns {boolean}
*/
BattleManager.updateEvent = function () {
    switch (this._phase) {
        case 'start':
        case 'turn':
        case 'turnEnd':
            //强制行动
            if (this.isActionForced()) {
                //执行强制行动指令
                this.processForcedAction();
                return true;
            } else {
                //正常行动指令
                return this.updateEventMain();
            }
    }
    //检查中指状态
    return this.checkAbort();
};

/**
* 更新正常事件
* @returns {boolean}
*/
BattleManager.updateEventMain = function () {
    //更新敌军部队指令
    $gameTroop.updateInterpreter();

    //requestMotionRefresh == true
    $gameParty.requestMotionRefresh();
    //敌军事件是否运行||战斗已经结束
    if ($gameTroop.isEventRunning() || this.checkBattleEnd()) {
        return true;
    }
    $gameTroop.setupBattleEvent();
    if ($gameTroop.isEventRunning() || SceneManager.isSceneChanging()) {
        return true;
    }
    return false;
};

/**
* 忙碌状态
* @returns {boolean}
*/
BattleManager.isBusy = function () {
    return ($gameMessage.isBusy() || this._spriteset.isBusy() ||
        this._logWindow.isBusy());
};

/**
* 正在输入
* @returns {boolean}
*/
BattleManager.isInputting = function () {
    return this._phase === 'input';
};

/**
* 正在回合
* @returns {boolean}
*/
BattleManager.isInTurn = function () {
    return this._phase === 'turn';
};

/**
* 已Turn结束
* @returns {boolean}
*/
BattleManager.isTurnEnd = function () {
    return this._phase === 'turnEnd';
};

/**
* 正在中止
* @returns {boolean}
*/
BattleManager.isAborting = function () {
    return this._phase === 'aborting';
};

/**
* 战斗结束
* @returns {boolean}
*/
BattleManager.isBattleEnd = function () {
    return this._phase === 'battleEnd';
};

/**
* 可以逃跑
* @returns {boolean}
*/
BattleManager.canEscape = function () {
    return this._canEscape;
};

/**
* 可以失败
* @returns {boolean}
*/
BattleManager.canLose = function () {
    return this._canLose;
};

/**
* 已经逃走状态
* @returns {boolean}
*/
BattleManager.isEscaped = function () {
    return this._escaped;
};

/**
* 当前行动角色
* @returns {Game_Actor}
*/
BattleManager.actor = function () {
    return this._actorIndex >= 0 ? $gameParty.members()[this._actorIndex] : null;
};

/**
* 清空战斗的角色
*/
BattleManager.clearActor = function () {
    this.changeActor(-1, '');
};

/**
* 变更战斗角色
* @param newActorIndex 战斗角色号
* @param lastActorActionState 最后一次角色行动的状态
*/
BattleManager.changeActor = function (newActorIndex, lastActorActionState) {
    //最近行动的角色
    var lastActor = this.actor();
    //当前的行动的角色号 = 新的角色号
    this._actorIndex = newActorIndex;
    //取得当前行动的角色
    var newActor = this.actor();
    if (lastActor) {
        lastActor.setActionState(lastActorActionState);
    }
    if (newActor) {
        //新角色进入指令输入阶段
        newActor.setActionState('inputting');
    }
};

/**
* 战斗前置操作
*/
BattleManager.startBattle = function () {
    //阶段 = start
    this._phase = 'start';
    //游戏系统更新战斗前置操作
    $gameSystem.onBattleStart();
    //我方队伍的战斗前置操作
    $gameParty.onBattleStart();
    //敌方队伍的战斗前置操作
    $gameTroop.onBattleStart();
    //显示战斗开始的文本内容
    this.displayStartMessages();
};

/**
* 显示战斗开始的文本信息
*/
BattleManager.displayStartMessages = function () {
    //怪物名称
    $gameTroop.enemyNames().forEach(function (name) {
        $gameMessage.add(TextManager.emerge.format(name));
    });
    //先发遇敌
    if (this._preemptive) {
        $gameMessage.add(TextManager.preemptive.format($gameParty.name()));
    } else if (this._surprise) {
        $gameMessage.add(TextManager.surprise.format($gameParty.name()));
    }
};

/**
* 开始输入指令
*/
BattleManager.startInput = function () {
    //战斗阶段 = input
    this._phase = 'input';
    //我方队伍生成行动指令
    $gameParty.makeActions();
    //敌方队伍生成行动指令
    $gameTroop.makeActions();
    //清除指令角色信息
    this.clearActor();
    //被动遇敌
    if (this._surprise || !$gameParty.canInput()) {
        //开始回合
        this.startTurn();
    }
};

/**
* 正在输入行动指令的信息
* @returns {Game_Action}
*/
BattleManager.inputtingAction = function () {
    return this.actor() ? this.actor().inputtingAction() : null;
};

/**
* 选择下一个行动指令
*/
BattleManager.selectNextCommand = function () {
    do {
        if (!this.actor() || !this.actor().selectNextCommand()) {
            this.changeActor(this._actorIndex + 1, 'waiting');
            if (this._actorIndex >= $gameParty.size()) {
                this.startTurn();
                break;
            }
        }
    } while (!this.actor().canInput());
};

/**
* 选择上一个行动指令
*/
BattleManager.selectPreviousCommand = function () {
    do {
        if (!this.actor() || !this.actor().selectPreviousCommand()) {
            this.changeActor(this._actorIndex - 1, 'undecided');
            if (this._actorIndex < 0) {
                return;
            }
        }
    } while (!this.actor().canInput());
};

/**
* 刷新状态信息
*/
BattleManager.refreshStatus = function () {
    this._statusWindow.refresh();
};

/**
* 开始回合
*/
BattleManager.startTurn = function () {
    //战斗阶段 =  turn
    this._phase = 'turn';
    //清除角色信息
    this.clearActor();
    //敌军增加回合
    $gameTroop.increaseTurn();
    //生成行动命令
    this.makeActionOrders();
    //requestMotionRefresh = true
    $gameParty.requestMotionRefresh();
    //开始回合
    this._logWindow.startTurn();
};

/**
* 更新回合
*/
BattleManager.updateTurn = function () {
    //requestMotionRefresh = true
    $gameParty.requestMotionRefresh();
    //当前战斗人
    if (!this._subject) {
        this._subject = this.getNextSubject();
    }
    if (this._subject) {
        //执行回合
        this.processTurn();
    } else {
        //回合结束
        this.endTurn();
    }
};

/**
* 执行回合流程
*/
BattleManager.processTurn = function () {
    //当前战斗人
    var subject = this._subject;
    //当前行动指令
    var action = subject.currentAction();
    if (action) {
        //指令准备阶段
        action.prepare();
        //行动指令验证
        if (action.isValid()) {
            //开始行动行动指令
            this.startAction();
        }
        //移除当前行动指令
        subject.removeCurrentAction();
    } else {
        //行动结束后通知后置行动操作操作
        subject.onAllActionsEnd();
        //刷新状态信息
        this.refreshStatus();
        //显示自动生效的状态
        this._logWindow.displayAutoAffectedStatus(subject);
        //显示当前状态
        this._logWindow.displayCurrentState(subject);
        //显示再生
        this._logWindow.displayRegeneration(subject);
        //下个行动对象
        this._subject = this.getNextSubject();
    }
};

/**
* 结束回合
*/
BattleManager.endTurn = function () {
    //当前战斗阶段 == 回合结束
    this._phase = 'turnEnd';
    //先发制人重置
    this._preemptive = false;
    //意外遇袭重置
    this._surprise = false;
    //所有战斗成员通知回合结束
    this.allBattleMembers().forEach(function (battler) {
        battler.onTurnEnd();
        this.refreshStatus();
        this._logWindow.displayAutoAffectedStatus(battler);
        this._logWindow.displayRegeneration(battler);
    }, this);
    //重置强制回合
    if (this.isForcedTurn()) {
        this._turnForced = false;
    }
};

/**
* 是否为强制回合
* @returns {boolean}
*/
BattleManager.isForcedTurn = function () {
    return this._turnForced;
};

/**
* 回合结束
*/
BattleManager.updateTurnEnd = function () {
    this.startInput();
};

/**
* 下个战斗对象
* @returns {Game_Battler}
*/
BattleManager.getNextSubject = function () {
    for (; ;) {
        var battler = this._actionBattlers.shift();
        if (!battler) {
            return null;
        }
        if (battler.isBattleMember() && battler.isAlive()) {
            return battler;
        }
    }
};

/**
* 所有战斗成员信息(我方队伍+地方队伍)
* @returns {Array:Game_Battler}
*/
BattleManager.allBattleMembers = function () {
    return $gameParty.members().concat($gameTroop.members());
};

/**
* 生成战斗指令
*/
BattleManager.makeActionOrders = function () {
    //战斗成员
    var battlers = [];
    //非意外遇袭
    if (!this._surprise) {
        //获得我方队伍信息
        battlers = battlers.concat($gameParty.members());
    }
    //非先发制人
    if (!this._preemptive) {
        //获得敌方队伍信息
        battlers = battlers.concat($gameTroop.members());
    }

    battlers.forEach(function (battler) {
        //生成速度
        battler.makeSpeed();
    });
    //根据行动速度排序,速度快的先开始行动
    battlers.sort(function (a, b) {
        return b.speed() - a.speed();
    });
    this._actionBattlers = battlers;
};

/**
* 开始行动指令
*/
BattleManager.startAction = function () {
    //当前战斗角色
    var subject = this._subject;
    //当前行动指令
    var action = subject.currentAction();
    //当前指令目标(敌方队伍|我方队伍)
    var targets = action.makeTargets();
    //战斗阶段 = 行动指令
    this._phase = 'action';
    //行动指令
    this._action = action;
    //目标对象
    this._targets = targets;
    //当前战斗角色使用的道具
    subject.useItem(action.item());
    //附加当前行动特性效果
    this._action.applyGlobal();
    //刷新状态
    this.refreshStatus();
    //日志窗口记录当前行动指令信息
    this._logWindow.startAction(subject, action, targets);
};

/**
* 更新行动指令
*/
BattleManager.updateAction = function () {
    var target = this._targets.shift();
    if (target) {
        //执行指令
        this.invokeAction(this._subject, target);
    } else {
        //执行指令结束
        this.endAction();
    }
};

/**
* 执行行动指令结束,进入下一回合
*/
BattleManager.endAction = function () {
    this._logWindow.endAction(this._subject);
    this._phase = 'turn';
};

/**
* 执行行动指令
* @param {Game_Battler} subject 当前行动角色
* @param {Game_Battler} target 当前行动角色的目标角色
*/
BattleManager.invokeAction = function (subject, target) {
    //压入日志进栈
    this._logWindow.push('pushBaseLine');
    //发动反击
    if (Math.random() < this._action.itemCnt(target)) {
        //反击
        this.invokeCounterAttack(subject, target);
        //魔法反弹
    } else if (Math.random() < this._action.itemMrf(target)) {
        //魔法反弹
        this.invokeMagicReflection(subject, target);
    } else {
        //正常行动指令
        this.invokeNormalAction(subject, target);
    }
    //最近一次的目标对象
    subject.setLastTarget(target);
    //压出日志出栈
    this._logWindow.push('popBaseLine');
    //更新状态
    this.refreshStatus();
};

/**
* 正常行动指令
* @param {Game_Battler} subject 当前行动角色
* @param {Game_Battler} target 当前行动角色的目标角色
*/
BattleManager.invokeNormalAction = function (subject, target) {
    var realTarget = this.applySubstitute(target);
    this._action.apply(realTarget);
    this._logWindow.displayActionResults(subject, realTarget);
};

/**
* 反击
* @param {Game_Battler} subject 当前行动角色
* @param {Game_Battler} target 当前行动角色的目标角色
*/
BattleManager.invokeCounterAttack = function (subject, target) {
    var action = new Game_Action(target);
    action.setAttack();
    action.apply(subject);
    this._logWindow.displayCounter(target);
    this._logWindow.displayActionResults(target, subject);
};

/**
* 魔法反弹
* @param {Game_Battler} subject 当前行动角色
* @param {Game_Battler} target 当前行动角色的目标角色
*/
BattleManager.invokeMagicReflection = function (subject, target) {
    this._action._reflectionTarget = target;
    this._logWindow.displayReflection(target);
    this._action.apply(subject);
    this._logWindow.displayActionResults(target, subject);
};

/**
* 如果对象已经死亡,则找切换目标队伍中的其他成员来接收行动指令
* @param {Game_Battler} target 当前行动角色的目标角色
* @returns {Game_Battler}
*/
BattleManager.applySubstitute = function (target) {
    if (this.checkSubstitute(target)) {
        var substitute = target.friendsUnit().substituteBattler();
        if (substitute && target !== substitute) {
            this._logWindow.displaySubstitute(substitute, target);
            return substitute;
        }
    }
    return target;
};

/**
* 检查目标是否死亡
* @param target 目标对象
* @returns {boolean}
*/
BattleManager.checkSubstitute = function (target) {
    //目标已经死了&& 行动指令必中状态
    return target.isDying() && !this._action.isCertainHit();
};

/**
* 强制行动指令
* @returns {boolean}
*/
BattleManager.isActionForced = function () {
    return !!this._actionForcedBattler;
};

/**
* 强制行动指令
* @param battler
*/
BattleManager.forceAction = function (battler) {
    //强制行动的角色
    this._actionForcedBattler = battler;
    var index = this._actionBattlers.indexOf(battler);
    if (index >= 0) {
        this._actionBattlers.splice(index, 1);
    }
};

/**
* 执行强制行动指令
*/
BattleManager.processForcedAction = function () {
    //强制行动角色
    if (this._actionForcedBattler) {
        //回合强制
        this._turnForced = true;
        //当前战斗角色为强制战斗角色
        this._subject = this._actionForcedBattler;
        //强制战斗角色(临时变量)变为空
        this._actionForcedBattler = null;
        //开始行动指令
        this.startAction();
        //一处当前行动指令
        this._subject.removeCurrentAction();
    }
};

/**
* 中止
*/
BattleManager.abort = function () {
    //当前战斗阶段为中止
    this._phase = 'aborting';
};

/**
* 检查战斗结束
* @returns {boolean}
*/
BattleManager.checkBattleEnd = function () {
    if (this._phase) {
        //战斗中止
        if (this.checkAbort()) {
            return true;
            //己方队伍成员全部阵亡
        } else if ($gameParty.isAllDead()) {
            //执行战斗失败流程
            this.processDefeat();
            return true;
            //敌方队伍成员全部阵亡
        } else if ($gameTroop.isAllDead()) {
            //执行战斗胜利流程
            this.processVictory();
            return true;
        }
    }
    return false;
};

/**
* 检查中止状态
* @returns {boolean}
*/
BattleManager.checkAbort = function () {
    //己方队伍为空||中止状态== true
    if ($gameParty.isEmpty() || this.isAborting()) {
        //播放逃跑音效
        SoundManager.playEscape();
        //逃跑成功!!!
        this._escaped = true;
        //中止成功!!!
        this.processAbort();
    }
    return false;
};

/**
* 执行战斗胜利流程
*/
BattleManager.processVictory = function () {
    //移除己方队伍战斗状态
    $gameParty.removeBattleStates();
    //调用己方队伍在胜利的时候通知
    $gameParty.performVictory();
    //播放胜利音效
    this.playVictoryMe();
    //回放背景音乐和背景音效
    this.replayBgmAndBgs();
    //生成奖励
    this.makeRewards();
    //显示战斗成功消息
    this.displayVictoryMessage();
    //显示奖励物品信息
    this.displayRewards();
    //增加奖励物品信息
    this.gainRewards();
    //结束战斗
    this.endBattle(0);
};

/**
* 执行逃跑流程
* @returns {boolean}
*/
BattleManager.processEscape = function () {
    //己方队伍逃跑前置通知
    $gameParty.performEscape();
    //播放逃跑音效
    SoundManager.playEscape();
    //逃跑成功计算(先发制人逃跑一定成功)
    var success = this._preemptive ? true : (Math.random() < this._escapeRatio);
    if (success) {
        //显示逃跑成功文本信息
        this.displayEscapeSuccessMessage();
        //逃跑成功状态 == ture
        this._escaped = true;
        //执行中止流程
        this.processAbort();
    } else {
        //显示逃跑失败的文本信息
        this.displayEscapeFailureMessage();
        //逃跑成功率+0.1
        this._escapeRatio += 0.1;
        //清空指令信息
        $gameParty.clearActions();
        //开始下一回合
        this.startTurn();
    }
    return success;
};

/**
* 执行中止流程
*/
BattleManager.processAbort = function () {
    $gameParty.removeBattleStates();
    this.replayBgmAndBgs();
    this.endBattle(1);
};

/**
* 执行战败流程
*/
BattleManager.processDefeat = function () {
    //显示战败信息
    this.displayDefeatMessage();
    //播放战败音效
    this.playDefeatMe();
    //是否可以失败
    if (this._canLose) {
        //重放背景音乐和背景音效
        this.replayBgmAndBgs();
    } else {
        //停止背景音乐
        AudioManager.stopBgm();
    }
    //结束战斗
    this.endBattle(2);
};

/**
* 战斗结束
* @param result
*/
BattleManager.endBattle = function (result) {
    this._phase = 'battleEnd';
    if (this._eventCallback) {
        //战斗事件回调
        this._eventCallback(result);
    }
    if (result === 0) {
        //战斗成功
        $gameSystem.onBattleWin();
    } else if (this._escaped) {
        //战斗失败,战斗逃跑
        $gameSystem.onBattleEscape();
    }
};

/**
* 更新战斗结束
*/
BattleManager.updateBattleEnd = function () {
    //测试战斗
    if (this.isBattleTest()) {
        //停止播放背景音乐
        AudioManager.stopBgm();
        //关闭场景
        SceneManager.exit();
        //非逃跑成功和己方队伍并非全部阵亡
    } else if (!this._escaped && $gameParty.isAllDead()){
        //允许失败
        if (this._canLose) {
            //救活战斗成员信息
            $gameParty.reviveBattleMembers();
            //场景压出栈
            SceneManager.pop();
        } else {
            //跳转战斗失败
            SceneManager.goto(Scene_Gameover);
        }
    } else {
        SceneManager.pop();
    }
    this._phase = null;
};

/**
* 生成战斗奖励
*/
BattleManager.makeRewards = function () {
    this._rewards = {};
    //敌军队伍的身上金币总数
    this._rewards.gold = $gameTroop.goldTotal();
    //敌军队伍的总经验数
    this._rewards.exp = $gameTroop.expTotal();
    //根据敌军的物品生成掉落物品
    this._rewards.items = $gameTroop.makeDropItems();
};

/**
* 显示战斗胜利的文本
*/
BattleManager.displayVictoryMessage = function () {
    $gameMessage.add(TextManager.victory.format($gameParty.name()));
};

/**
* 显示战败的文本
*/
BattleManager.displayDefeatMessage = function () {
    $gameMessage.add(TextManager.defeat.format($gameParty.name()));
};

/**
* 显示逃跑成功的文本
*/
BattleManager.displayEscapeSuccessMessage = function () {
    $gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
};

/**
* 显示逃跑失败的文本
*/
BattleManager.displayEscapeFailureMessage = function () {
    $gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
    $gameMessage.add('\\.' + TextManager.escapeFailure);
};

/**
* 显示奖励物品
*/
BattleManager.displayRewards = function () {
    //显示经验
    this.displayExp();
    //显示金币
    this.displayGold();
    //显示掉落物品
    this.displayDropItems();
};

/**
* 显示经验
*/
BattleManager.displayExp = function () {
    var exp = this._rewards.exp;
    if (exp > 0) {
        var text = TextManager.obtainExp.format(exp, TextManager.exp);
        $gameMessage.add('\\.' + text);
    }
};

/**
* 显示金币
*/
BattleManager.displayGold = function () {
    var gold = this._rewards.gold;
    if (gold > 0) {
        $gameMessage.add('\\.' + TextManager.obtainGold.format(gold));
    }
};

/**
* 显示掉落物品
*/
BattleManager.displayDropItems = function () {
    var items = this._rewards.items;
    if (items.length > 0) {
        $gameMessage.newPage();
        items.forEach(function (item) {
            $gameMessage.add(TextManager.obtainItem.format(item.name));
        });
    }
};

/**
* 增加奖励
*/
BattleManager.gainRewards = function () {
    //增加经验
    this.gainExp();
    //增加金币
    this.gainGold();
    //增加掉落物品
    this.gainDropItems();
};

/**
* 增加经验
*/
BattleManager.gainExp = function () {
    var exp = this._rewards.exp;
    //己方队伍成员增加经验
    $gameParty.allMembers().forEach(function (actor) {
        actor.gainExp(exp);
    });
};

/**
* 增加金币
*/
BattleManager.gainGold = function () {
    //己方队伍增加金币
    $gameParty.gainGold(this._rewards.gold);
};

/**
* 增加掉落物品
*/
BattleManager.gainDropItems = function () {
    var items = this._rewards.items;
    //己方队伍增加物品
    items.forEach(function (item) {
        $gameParty.gainItem(item, 1);
    });
};[/pre]

评分

参与人数 3赞 +3 收起 理由
wabcmcc + 1
ssrwkx + 1 塞糖
y967 + 1 塞糖

查看全部评分

梦石
0
星屑
3246
在线时间
420 小时
注册时间
2018-10-24
回帖
41
发表于 2022-7-25 09:37:23 | 显示全部楼层
感谢大佬的分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部