赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 8 |
经验 | 33469 |
最后登录 | 2025-8-1 |
在线时间 | 505 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 769
- 在线时间
- 505 小时
- 注册时间
- 2011-1-16
- 帖子
- 60
|
用deepseek设计的"防御"指令替换,不知道这样设计的可以吗?
有人可以指正进步的吗,谢谢?
- /*:
- * @target MZ
- * @plugindesc 通过备注栏替换攻击/防御指令,优先级:人物 < 职业 < 装备 < 状态
- * @author Your Name
- *
- * @help
- * ============================================================================
- * 介绍
- * ============================================================================
- *
- * 本插件允许您通过角色、职业、装备和状态的备注栏替换战斗中的"攻击"和"防御"指令。
- * 消耗显示仅显示数值。
- *
- * 优先级: 人物 < 职业 < 装备 < 状态(状态优先级最高)
- *
- * 使用备注标签:
- * <替换攻击: 技能ID>
- * <替换防御: 技能ID>
- *
- * 例如: <替换攻击: 10> 将把攻击指令替换为ID为10的技能
- *
- * ============================================================================
- * 使用说明
- * ============================================================================
- *
- * 1. 在角色、职业、装备或状态的备注栏中添加上述标签
- * 2. 在战斗中,攻击/防御指令将被替换为指定的技能
- * 3. 指令名称会显示为技能名称,并显示相应的消耗(MP/TP)
- *
- * 注意: 如果多个状态有相同标签,优先级高的状态(数据库中的优先级)将生效
- *
- * ============================================================================
- * 更新日志
- * ============================================================================
- *
- * 版本 1.1.1:
- * - 移除了消耗显示中的"TP:"和"MP:"前缀
- * - 保持版本1.1的核心功能
- *
- * 版本 1.1:
- * - 调整优先级顺序为:人物 < 职业 < 装备 < 状态
- * - 优化显示逻辑,无替换时保持原样
- *
- * 版本 1.0:
- * - 初始发布
- *
- */
- (() => {
- // 提取技能ID的正则表达式
- const extractSkillId = (note, tag) => {
- if (!note) return null;
- const regex = new RegExp(`<${tag}:\\s*(\\d+)>`, 'i');
- const match = note.match(regex);
- return match ? parseInt(match[1]) : null;
- };
- // 获取替换技能ID(更新优先级顺序)
- Game_Actor.prototype.getReplacementSkillId = function(command, originalId) {
- let skillId = null;
-
- // 1. 检查人物(最低优先级)
- const actor = $dataActors[this.actorId()];
- if (actor) {
- skillId = extractSkillId(actor.note, `替换${command}`) || skillId;
- }
-
- // 2. 检查职业
- const currentClass = this.currentClass();
- if (currentClass) {
- const classSkillId = extractSkillId(currentClass.note, `替换${command}`);
- if (classSkillId !== null) skillId = classSkillId;
- }
-
- // 3. 检查装备(装备间优先级:后装备的覆盖先装备的)
- const equips = this.equips();
- for (let i = equips.length - 1; i >= 0; i--) {
- const equip = equips[i];
- if (!equip) continue;
- const equipSkillId = extractSkillId(equip.note, `替换${command}`);
- if (equipSkillId !== null) skillId = equipSkillId;
- }
-
- // 4. 检查状态(最高优先级,按状态优先级排序)
- const states = this.states().sort((a, b) => b.priority - a.priority);
- for (const state of states) {
- const stateSkillId = extractSkillId(state.note, `替换${command}`);
- if (stateSkillId !== null) {
- skillId = stateSkillId;
- break; // 找到最高优先级状态后停止搜索
- }
- }
-
- // 返回有效技能ID或原始ID
- return (skillId !== null && $dataSkills[skillId]) ? skillId : originalId;
- };
- // 覆盖攻击技能ID
- Game_Actor.prototype.attackSkillId = function() {
- return this.getReplacementSkillId('攻击', 1);
- };
- // 覆盖防御技能ID
- Game_Actor.prototype.guardSkillId = function() {
- return this.getReplacementSkillId('防御', 2);
- };
- // 在指令窗口绘制技能消耗(优化:仅显示数值,无前缀)
- const _Window_ActorCommand_drawItem = Window_ActorCommand.prototype.drawItem;
- Window_ActorCommand.prototype.drawItem = function(index) {
- const rect = this.itemLineRect(index);
- const commandSymbol = this.commandSymbol(index);
-
- // 检查是否是攻击或防御指令
- if (commandSymbol === 'attack' || commandSymbol === 'guard') {
- const actor = this.actor();
- if (!actor) return;
-
- let skillId, originalId;
- if (commandSymbol === 'attack') {
- originalId = 1;
- skillId = actor.attackSkillId();
- } else {
- originalId = 2;
- skillId = actor.guardSkillId();
- }
-
- // 没有替换时保持原样
- if (skillId === originalId) {
- _Window_ActorCommand_drawItem.call(this, index);
- return;
- }
-
- const skill = $dataSkills[skillId];
- if (!skill) return;
-
- // 绘制技能名称
- this.resetTextColor();
- this.drawText(skill.name, rect.x, rect.y, rect.width - 40); // 为消耗留出空间
-
- // 绘制技能消耗(仅显示数值)
- this.drawSkillCost(skill, rect.x, rect.y, rect.width);
- } else {
- _Window_ActorCommand_drawItem.call(this, index);
- }
- };
- // 绘制技能消耗(仅显示数值)
- Window_ActorCommand.prototype.drawSkillCost = function(skill, x, y, width) {
- const actor = this.actor();
- if (!actor) return;
-
- // 计算实际消耗
- const mpCost = actor.skillMpCost(skill);
- const tpCost = actor.skillTpCost(skill);
-
- // 绘制消耗数值(无前缀)
- if (tpCost > 0) {
- this.changeTextColor(ColorManager.tpCostColor());
- this.drawText(tpCost, x, y, width, 'right');
- } else if (mpCost > 0) {
- this.changeTextColor(ColorManager.mpCostColor());
- this.drawText(mpCost, x, y, width, 'right');
- }
- };
- // 在状态菜单中显示正确的攻击/防御名称
- const _Window_Status_drawBlock1 = Window_Status.prototype.drawBlock1;
- Window_Status.prototype.drawBlock1 = function(y) {
- _Window_Status_drawBlock1.call(this, y);
-
- const actor = this.actor();
- if (!actor) return;
-
- // 绘制攻击名称
- const attackId = actor.attackSkillId();
- const attackSkill = $dataSkills[attackId];
- const attackName = attackSkill ? attackSkill.name : TextManager.attack;
-
- // 绘制防御名称
- const guardId = actor.guardSkillId();
- const guardSkill = $dataSkills[guardId];
- const guardName = guardSkill ? guardSkill.name : TextManager.guard;
-
- const lineHeight = this.lineHeight();
- const x = this.standardPadding();
- const width = this.contents.width - this.standardPadding() * 2;
-
- // 清除原有区域
- this.contents.clearRect(x, y + lineHeight * 0, width, lineHeight);
- this.contents.clearRect(x, y + lineHeight * 1, width, lineHeight);
-
- // 绘制新的攻击/防御名称
- this.drawText(TextManager.attack + ':', x, y + lineHeight * 0, 120);
- this.drawText(attackName, x + 120, y + lineHeight * 0);
-
- this.drawText(TextManager.guard + ':', x, y + lineHeight * 1, 120);
- this.drawText(guardName, x + 120, y + lineHeight * 1);
- };
- })();
复制代码 |
|