设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 313|回复: 1
打印 上一主题 下一主题

[有事请教] 请问,"防御"指令如何替换?

[复制链接]

Lv2.观梦者

梦石
0
星屑
769
在线时间
505 小时
注册时间
2011-1-16
帖子
60
跳转到指定楼层
1
发表于 2024-7-13 22:47:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
请问,"防御"指令如何通过人物、职业、装备、状态等的备注
进行替换?
并且"攻击""防御"指令的更改优先级都是人物<职业<装备<状态???

Lv2.观梦者

梦石
0
星屑
769
在线时间
505 小时
注册时间
2011-1-16
帖子
60
2
 楼主| 发表于 昨天 19:47 | 只看该作者
用deepseek设计的"防御"指令替换,不知道这样设计的可以吗?
有人可以指正进步的吗,谢谢?
  1. /*:
  2. * @target MZ
  3. * @plugindesc 通过备注栏替换攻击/防御指令,优先级:人物 < 职业 < 装备 < 状态
  4. * @author Your Name
  5. *
  6. * @help
  7. * ============================================================================
  8. * 介绍
  9. * ============================================================================
  10. *
  11. * 本插件允许您通过角色、职业、装备和状态的备注栏替换战斗中的"攻击"和"防御"指令。
  12. * 消耗显示仅显示数值。
  13. *
  14. * 优先级: 人物 < 职业 < 装备 < 状态(状态优先级最高)
  15. *
  16. * 使用备注标签:
  17. *   <替换攻击: 技能ID>
  18. *   <替换防御: 技能ID>
  19. *
  20. * 例如: <替换攻击: 10> 将把攻击指令替换为ID为10的技能
  21. *
  22. * ============================================================================
  23. * 使用说明
  24. * ============================================================================
  25. *
  26. * 1. 在角色、职业、装备或状态的备注栏中添加上述标签
  27. * 2. 在战斗中,攻击/防御指令将被替换为指定的技能
  28. * 3. 指令名称会显示为技能名称,并显示相应的消耗(MP/TP)
  29. *
  30. * 注意: 如果多个状态有相同标签,优先级高的状态(数据库中的优先级)将生效
  31. *
  32. * ============================================================================
  33. * 更新日志
  34. * ============================================================================
  35. *
  36. * 版本 1.1.1:
  37. *   - 移除了消耗显示中的"TP:"和"MP:"前缀
  38. *   - 保持版本1.1的核心功能
  39. *
  40. * 版本 1.1:
  41. *   - 调整优先级顺序为:人物 < 职业 < 装备 < 状态
  42. *   - 优化显示逻辑,无替换时保持原样
  43. *
  44. * 版本 1.0:
  45. *   - 初始发布
  46. *
  47. */

  48. (() => {
  49.     // 提取技能ID的正则表达式
  50.     const extractSkillId = (note, tag) => {
  51.         if (!note) return null;
  52.         const regex = new RegExp(`<${tag}:\\s*(\\d+)>`, 'i');
  53.         const match = note.match(regex);
  54.         return match ? parseInt(match[1]) : null;
  55.     };

  56.     // 获取替换技能ID(更新优先级顺序)
  57.     Game_Actor.prototype.getReplacementSkillId = function(command, originalId) {
  58.         let skillId = null;
  59.         
  60.         // 1. 检查人物(最低优先级)
  61.         const actor = $dataActors[this.actorId()];
  62.         if (actor) {
  63.             skillId = extractSkillId(actor.note, `替换${command}`) || skillId;
  64.         }
  65.         
  66.         // 2. 检查职业
  67.         const currentClass = this.currentClass();
  68.         if (currentClass) {
  69.             const classSkillId = extractSkillId(currentClass.note, `替换${command}`);
  70.             if (classSkillId !== null) skillId = classSkillId;
  71.         }
  72.         
  73.         // 3. 检查装备(装备间优先级:后装备的覆盖先装备的)
  74.         const equips = this.equips();
  75.         for (let i = equips.length - 1; i >= 0; i--) {
  76.             const equip = equips[i];
  77.             if (!equip) continue;
  78.             const equipSkillId = extractSkillId(equip.note, `替换${command}`);
  79.             if (equipSkillId !== null) skillId = equipSkillId;
  80.         }
  81.         
  82.         // 4. 检查状态(最高优先级,按状态优先级排序)
  83.         const states = this.states().sort((a, b) => b.priority - a.priority);
  84.         for (const state of states) {
  85.             const stateSkillId = extractSkillId(state.note, `替换${command}`);
  86.             if (stateSkillId !== null) {
  87.                 skillId = stateSkillId;
  88.                 break; // 找到最高优先级状态后停止搜索
  89.             }
  90.         }
  91.         
  92.         // 返回有效技能ID或原始ID
  93.         return (skillId !== null && $dataSkills[skillId]) ? skillId : originalId;
  94.     };

  95.     // 覆盖攻击技能ID
  96.     Game_Actor.prototype.attackSkillId = function() {
  97.         return this.getReplacementSkillId('攻击', 1);
  98.     };

  99.     // 覆盖防御技能ID
  100.     Game_Actor.prototype.guardSkillId = function() {
  101.         return this.getReplacementSkillId('防御', 2);
  102.     };

  103.     // 在指令窗口绘制技能消耗(优化:仅显示数值,无前缀)
  104.     const _Window_ActorCommand_drawItem = Window_ActorCommand.prototype.drawItem;
  105.     Window_ActorCommand.prototype.drawItem = function(index) {
  106.         const rect = this.itemLineRect(index);
  107.         const commandSymbol = this.commandSymbol(index);
  108.         
  109.         // 检查是否是攻击或防御指令
  110.         if (commandSymbol === 'attack' || commandSymbol === 'guard') {
  111.             const actor = this.actor();
  112.             if (!actor) return;
  113.             
  114.             let skillId, originalId;
  115.             if (commandSymbol === 'attack') {
  116.                 originalId = 1;
  117.                 skillId = actor.attackSkillId();
  118.             } else {
  119.                 originalId = 2;
  120.                 skillId = actor.guardSkillId();
  121.             }
  122.             
  123.             // 没有替换时保持原样
  124.             if (skillId === originalId) {
  125.                 _Window_ActorCommand_drawItem.call(this, index);
  126.                 return;
  127.             }
  128.             
  129.             const skill = $dataSkills[skillId];
  130.             if (!skill) return;
  131.             
  132.             // 绘制技能名称
  133.             this.resetTextColor();
  134.             this.drawText(skill.name, rect.x, rect.y, rect.width - 40); // 为消耗留出空间
  135.             
  136.             // 绘制技能消耗(仅显示数值)
  137.             this.drawSkillCost(skill, rect.x, rect.y, rect.width);
  138.         } else {
  139.             _Window_ActorCommand_drawItem.call(this, index);
  140.         }
  141.     };

  142.     // 绘制技能消耗(仅显示数值)
  143.     Window_ActorCommand.prototype.drawSkillCost = function(skill, x, y, width) {
  144.         const actor = this.actor();
  145.         if (!actor) return;
  146.         
  147.         // 计算实际消耗
  148.         const mpCost = actor.skillMpCost(skill);
  149.         const tpCost = actor.skillTpCost(skill);
  150.         
  151.         // 绘制消耗数值(无前缀)
  152.         if (tpCost > 0) {
  153.             this.changeTextColor(ColorManager.tpCostColor());
  154.             this.drawText(tpCost, x, y, width, 'right');
  155.         } else if (mpCost > 0) {
  156.             this.changeTextColor(ColorManager.mpCostColor());
  157.             this.drawText(mpCost, x, y, width, 'right');
  158.         }
  159.     };

  160.     // 在状态菜单中显示正确的攻击/防御名称
  161.     const _Window_Status_drawBlock1 = Window_Status.prototype.drawBlock1;
  162.     Window_Status.prototype.drawBlock1 = function(y) {
  163.         _Window_Status_drawBlock1.call(this, y);
  164.         
  165.         const actor = this.actor();
  166.         if (!actor) return;
  167.         
  168.         // 绘制攻击名称
  169.         const attackId = actor.attackSkillId();
  170.         const attackSkill = $dataSkills[attackId];
  171.         const attackName = attackSkill ? attackSkill.name : TextManager.attack;
  172.         
  173.         // 绘制防御名称
  174.         const guardId = actor.guardSkillId();
  175.         const guardSkill = $dataSkills[guardId];
  176.         const guardName = guardSkill ? guardSkill.name : TextManager.guard;
  177.         
  178.         const lineHeight = this.lineHeight();
  179.         const x = this.standardPadding();
  180.         const width = this.contents.width - this.standardPadding() * 2;
  181.         
  182.         // 清除原有区域
  183.         this.contents.clearRect(x, y + lineHeight * 0, width, lineHeight);
  184.         this.contents.clearRect(x, y + lineHeight * 1, width, lineHeight);
  185.         
  186.         // 绘制新的攻击/防御名称
  187.         this.drawText(TextManager.attack + ':', x, y + lineHeight * 0, 120);
  188.         this.drawText(attackName, x + 120, y + lineHeight * 0);
  189.         
  190.         this.drawText(TextManager.guard + ':', x, y + lineHeight * 1, 120);
  191.         this.drawText(guardName, x + 120, y + lineHeight * 1);
  192.     };
  193. })();
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-8-2 00:30

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表