Advertisement
Guest User

CriticalOnFinalHit

a guest
Jan 7th, 2023
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // CriticalOnFinalHit.js
  3. //=============================================================================
  4. /*:
  5. * @target MZ
  6. * @plugindesc v1.0.0 อนุญาตให้คุณสามารถกำหนดอัตราคริติคอลให้การโจมตีครั้งสุดท้ายได้
  7. * @author jojo741963
  8. * @help CriticalOnFinalHit.js
  9. *
  10. * Log:
  11. * v1.0.0 - Release
  12. *
  13. * ปลั๊กอินนี้จะทำให้คุณกำหนดอัตราคริติคอลในการโจมตีครั้งสุดท้ายได้
  14. * (แม้การโจมตีนั้นจะมีครั้งเดียว คุณก็สามารถกำหนดคริติคอลได้เช่นกัน)
  15. *
  16. * วิธีการใช้ :
  17. * 1. ไปที่ Skill หรือ Item ที่ต้องการ
  18. * 2. ใน Note ให้เพิ่มข้อความดังนี้
  19. *  
  20. *       <LastHitCriRate:X>
  21. *
  22. *   เมื่อ X คือ อัตราคริติคอลที่กำหนด (ค่าระหว่าง 0-1)
  23. *
  24. *   เช่น        <LastHitCriRate:1>      การโจมตีครั้งสุดท้ายจะติดคริติคอลแน่นอน
  25. *           <LastHitCriRate:.04>    การโจมตีครั้งสุดท้ายจะติดคริติคอล 4%
  26. *
  27. * หมายเหตุ :
  28. *   - ทั้งนี้ อัตราคริติคอลในปลั๊กอินนี้เป็นการเขียนทับ (กำหนดค่าใหม่ลงไป)
  29. *     ไม่มีผลกับอัตราคริเดิมของผู้ใช้สกิล และอัตราการหลบหลีกของเป้าหมาย
  30. *   - ไม่สามารถกำหนดค่าเป็นสมการหรือเรียกใช้ตัวแปรอื่น ๆ ได้
  31. *   - สามารถใช้ร่วมกันได้กับสกิลที่โจมตีครั้งเดียว (Repeat 1 ครั้ง)
  32. *     โดยจะเป็นการกำหนดอัตราคริติคอลการโจมตีครั้งนั้น
  33. *   - สกิลที่ถูกกำหนดอัตราคริจะไม่มีผลกับการประเมินดาเมจของสกิล (ของการต่อสู้อัติโนมัติ)
  34. *     โดยความเสียหายของสกิลนี้จะคิดตามปกติ ไม่สนใจการคริติคอลที่กำหนดค่าใหม่ลงไป
  35. *
  36. *   วิธีการคิดอัตราตริติคอลเดิมของระบบ : อัตราคริผู้ใช้สกิล * (1 - อัตราการหลบคริเป้าหมาย)
  37. *
  38. */
  39.  
  40. (() => {
  41.     const pluginName = "CriticalOnFinalHit";
  42.  
  43.     //------------------------------------------------------------------------------------
  44.     // add _repeatHitIndex and _lastHit
  45.     var _jojo741963_cuscri_GameAction_initialize = Game_Action.prototype.initialize;
  46.     Game_Action.prototype.initialize = function(subject, forcing) {
  47.         _jojo741963_cuscri_GameAction_initialize.call(this, subject, forcing);
  48.         this._repeatHitIndex = 0;
  49.         this._lastHit = false;
  50.     };
  51.  
  52.     var _jojo741963_cuscri_GameAction_apply = Game_Action.prototype.apply;
  53.     Game_Action.prototype.apply = function(target) {
  54.         this._repeatHitIndex += 1;
  55.         if ( this._repeatHitIndex >= this.numRepeats() ) this._lastHit = true;
  56.         //--------------------------------------------------------
  57.         _jojo741963_cuscri_GameAction_apply.call(this, target);
  58.         //--------------------------------------------------------
  59.         if( this._lastHit ) {
  60.             this._repeatHitIndex = 0;
  61.             this._lastHit = false;
  62.         }
  63.     }
  64.     //------------------------------------------------------------------------------------
  65.  
  66.     Game_Action.prototype.getItemMeta = function() {
  67.         var data = null;
  68.         switch (this._item._dataClass) {
  69.             case "skill":
  70.                 data = $dataSkills[this._item._itemId];
  71.                 break;
  72.             case "item":
  73.                 data = $dataItems[this._item._itemId];
  74.                 break;
  75.         }
  76.         return data.meta;
  77.     }
  78.  
  79.     Game_Action.prototype.IsLastHitCriRate = function() {
  80.         var data = null;
  81.         switch (this._item._dataClass) {
  82.             case "skill":
  83.                 data = $dataSkills[this._item._itemId];
  84.                 break;
  85.             case "item":
  86.                 data = $dataItems[this._item._itemId];
  87.                 break;
  88.         }
  89.         if (data != null) {
  90.             if (data.meta.LastHitCriRate) return true;
  91.             return false;
  92.         } else {
  93.             return false;
  94.         }
  95.     };
  96.  
  97.     var _jojo741963_cuscri_GameAction_itemCri = Game_Action.prototype.itemCri;
  98.     Game_Action.prototype.itemCri = function(target) {
  99.         if ( this._lastHit && this.IsLastHitCriRate() ) {
  100.             return this.getItemMeta().LastHitCriRate;
  101.         } else {
  102.             return _jojo741963_cuscri_GameAction_itemCri.call(this, target)
  103.         }
  104.     };
  105.  
  106. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement