Advertisement
LunaeStellsr

EquipComparison+

Oct 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 62.86 KB | None | 0 0
  1. #=============================================================================#
  2. #   Extended Equipment Comparison Info                                        #
  3. #   Version: 1.1.0                                                            #  
  4. #   Author: Compeador                                                         #  
  5. #   Last update: 2018.10.21                                                   #  
  6. #=============================================================================#
  7. $imported = {} if $imported.nil?
  8. $imported["COMP_EECI"] = true
  9. #=============================================================================#
  10. #                               ** Update log **                              #
  11. #-----------------------------------------------------------------------------#
  12. #                                                                             #
  13. # -- 2018.10.25: Fix the bug of parameter calculation mistake and add text    #
  14. #                display of items for which have no difference.               #
  15. # -- 2018.10.21: Add inverse color option to value comparison                 #
  16. # -- 2018.10.19: Script completed                                             #
  17. # -- 2018.10.16: Received commission and started                              #
  18. #                                                                             #
  19. #=============================================================================#
  20. #                       ** End-User License Agreement **                      #
  21. #-----------------------------------------------------------------------------#
  22. # ┌─────────────────────────────────────────────────────────────────────────┐ #
  23. # │         ** THIS IS A PAID SCRIPT, RE-DISTRIBUTE WITH CAUTION! **        │ #
  24. # └─────────────────────────────────────────────────────────────────────────┘ #
  25. #  1. Copyright and Redistribution:                                           #
  26. #       All codes were written by me(Compeador), and you(the user) may edit   #
  27. #  the code for your own need without permission (duh).                       #
  28. #  Redistribute this script must agreed by VaiJack8, who commissioned this    #
  29. #  script, and you must share the original version released by the author     #
  30. #  without edits with credits.                                                #
  31. #   If you edited the scripts and claimed it as your own, this will resulted  #
  32. #  in copywrite law violation and also proves you're an a$$hole.              #
  33. #                                                                             #
  34. # 2. Service Information:                                                     #
  35. #       I only responsible for the edits requested by VaiJack8(the client).   #
  36. # If you got this script from the redistribution, I'm not responsible for any #
  37. # bug and malfunction occurred in your project.                               #
  38. #                                                                             #
  39. # *You can still try to request me tho, but I won't 100% guaranteed for reply #
  40. #=============================================================================#
  41. #                              ** User Manual **                              #
  42. #-----------------------------------------------------------------------------#
  43. # > Introduction:                                                             #
  44. #       This script will change the display of original parameter comparison  #
  45. # in Equip Scene when changing the equipments, instead of showing default     #
  46. # paramters, this script will only show changed parameters, including crit.   #
  47. # evasion...etc.                                                              #
  48. #   Most of editable option is in the module below, read the comments to know #
  49. # what's it doing and how to adjust them for your needs.                      #
  50. #=============================================================================#
  51. #                            ** Compatibility **                              #
  52. #-----------------------------------------------------------------------------#
  53. #   > YEA Equip Engine is required                                            #
  54. #   > Support comparison with 'Equipment Set Bonuses' by Modern Algebra       #
  55. #                                                                             #
  56. #       ** Place this script below the scripts mentioned above **             #
  57. #                                                                             #
  58. #   This script 99% will working if and only if in RPG Maker VX Ace. Also,    #
  59. # this is only sutiable for the project uses default RM's parameters/features #
  60. # that can be seen in database. On the other words, if you have tons of       #
  61. # custom parameter and other features, this script may not works well.        #
  62. #=============================================================================#
  63.  
  64. # Enable this script?
  65. COMP_EECI_Enable = true
  66.  
  67. if COMP_EECI_Enable && !$imported["YEA-AceEquipEngine"]
  68.   info = "Yanfly's Equip Engine is not detected, please make sure the script\n" +
  69.          "is placed correctly.\n" +
  70.          "The Equipment Extend Comparison Information will be disabled."
  71.   msgbox(info)
  72.   COMP_EECI_Enable = false
  73. end
  74.  
  75. if COMP_EECI_Enable
  76. #=============================================================================
  77. # * Module of this script
  78. #=============================================================================
  79. module COMP
  80.   #-------------------------------------------------------------------------
  81.   # Abbr. of Extended Equipment Comparison Information
  82.   module EECI
  83.     #--------------------------------------------------------------------------
  84.     # * Constants (Features) from Game_BattlerBase
  85.     # * Don't edit this unless you know what you're doing
  86.     #--------------------------------------------------------------------------
  87.     FEATURE_ELEMENT_RATE    =   Game_BattlerBase::FEATURE_ELEMENT_RATE    # Element Rate
  88.     FEATURE_DEBUFF_RATE     =   Game_BattlerBase::FEATURE_DEBUFF_RATE     # Debuff Rate
  89.     FEATURE_STATE_RATE      =   Game_BattlerBase::FEATURE_STATE_RATE      # State Rate
  90.     FEATURE_STATE_RESIST    =   Game_BattlerBase::FEATURE_STATE_RESIST    # State Resist
  91.     FEATURE_PARAM           =   Game_BattlerBase::FEATURE_PARAM           # Parameter
  92.     FEATURE_XPARAM          =   Game_BattlerBase::FEATURE_XPARAM          # Ex-Parameter
  93.     FEATURE_SPARAM          =   Game_BattlerBase::FEATURE_SPARAM          # Sp-Parameter
  94.     FEATURE_ATK_ELEMENT     =   Game_BattlerBase::FEATURE_ATK_ELEMENT     # Atk Element
  95.     FEATURE_ATK_STATE       =   Game_BattlerBase::FEATURE_ATK_STATE       # Atk State
  96.     FEATURE_ATK_SPEED       =   Game_BattlerBase::FEATURE_ATK_SPEED       # Atk Speed
  97.     FEATURE_ATK_TIMES       =   Game_BattlerBase::FEATURE_ATK_TIMES       # Atk Times+
  98.     FEATURE_STYPE_ADD       =   Game_BattlerBase::FEATURE_STYPE_ADD       # Add Skill Type
  99.     FEATURE_STYPE_SEAL      =   Game_BattlerBase::FEATURE_STYPE_SEAL      # Disable Skill Type
  100.     FEATURE_SKILL_ADD       =   Game_BattlerBase::FEATURE_SKILL_ADD       # Add Skill
  101.     FEATURE_SKILL_SEAL      =   Game_BattlerBase::FEATURE_SKILL_SEAL      # Disable Skill
  102.     FEATURE_EQUIP_WTYPE     =   Game_BattlerBase::FEATURE_EQUIP_WTYPE     # Equip Weapon
  103.     FEATURE_EQUIP_ATYPE     =   Game_BattlerBase::FEATURE_EQUIP_ATYPE     # Equip Armor
  104.     FEATURE_EQUIP_FIX       =   Game_BattlerBase::FEATURE_EQUIP_FIX       # Lock Equip
  105.     FEATURE_EQUIP_SEAL      =   Game_BattlerBase::FEATURE_EQUIP_SEAL      # Seal Equip
  106.     FEATURE_SLOT_TYPE       =   Game_BattlerBase::FEATURE_SLOT_TYPE       # Slot Type
  107.     FEATURE_ACTION_PLUS     =   Game_BattlerBase::FEATURE_ACTION_PLUS     # Action Times+
  108.     FEATURE_SPECIAL_FLAG    =   Game_BattlerBase::FEATURE_SPECIAL_FLAG    # Special Flag
  109.     FEATURE_COLLAPSE_TYPE   =   Game_BattlerBase::FEATURE_COLLAPSE_TYPE   # Collapse Effect
  110.     FEATURE_PARTY_ABILITY   =   Game_BattlerBase::FEATURE_PARTY_ABILITY   # Party Ability
  111.     # ---Feature Flags---
  112.     FLAG_ID_AUTO_BATTLE     =   Game_BattlerBase::FLAG_ID_AUTO_BATTLE     # auto battle
  113.     FLAG_ID_GUARD           =   Game_BattlerBase::FLAG_ID_GUARD           # guard
  114.     FLAG_ID_SUBSTITUTE      =   Game_BattlerBase::FLAG_ID_SUBSTITUTE      # substitute
  115.     FLAG_ID_PRESERVE_TP     =   Game_BattlerBase::FLAG_ID_PRESERVE_TP     # preserve TP
  116.     #=====================================================================#
  117.     # *                     v Free to Edit v                              #
  118.     #=====================================================================#
  119.     # * The next/last page keybind, edit the value for your own need.
  120.     #---------------------------------------------------------------------
  121.     Key_nextpage   = :RIGHT
  122.     Key_lastpage   = :LEFT
  123.     #---------------------------------------------------------------------
  124.     # * Hide the hint if no need to turn pages
  125.     Auto_Hide = true
  126.     #---------------------------------------------------------------------
  127.     # * After how many second to hide the hint after hint is shown?
  128.     #   0 = never
  129.     AutoHideTimer = 5 * Graphics.frame_rate
  130.     #---------------------------------------------------------------------
  131.     # * The hint window that display text about turning pages, uses
  132.     #   ""(double quote) if you don't want to show hint
  133.     Hint_Text     = "Use L/R to turn status pages"
  134.  
  135.     Hint_Position = :BR_actor_status          # at bottom-right of actor status window
  136.     #               :BR_equip_status          # at bottom-right of equipment status window
  137.     #               [x_position, y_position]  # Custom window position
  138.  
  139.     #                           R ,  G ,  B , Opacity
  140.     Hint_BackColor = Color.new(  0,   0,   0, 150)    # Back color of sprite
  141.     Hint_TextColor = Color.new(255, 255, 255, 255)    # Text color
  142.     Hint_Fontsize  = 20                       # Font size
  143.     Hint_Opacity   = 255                      # Opacity of sprite
  144.     Hint_Canva     = [300, 24]                # Max Width/Height of canvas
  145.     #---------------------------------------------------------------------
  146.     # * Text displayed when showing the comparison of set equipment bonus
  147.     SetEquipmentTextStem = "Set bonus"
  148.     SetEquipmentText = SetEquipmentTextStem + " [%s]:" # don't edit this
  149.     #---------------------------------------------------------------------
  150.     # * Id for standard param, chances are no need to edits
  151.     FeatureNormalParam = -1
  152.     #---------------------------------------------------------------------
  153.     # * The param/feature considered to compare
  154.     ComparisonTable = {        
  155.       #    better not touch      edit the text for your need
  156.       #    ↓              ↓                 ↓      
  157.       # symbol        => [id,  display group text showed in comparison]
  158.       :param          => [FeatureNormalParam, ''],                  # Basic parameter
  159.       :xparam         => [FEATURE_XPARAM, ''],                      # Ex-Parameter
  160.       :sparam         => [FEATURE_SPARAM, ''],                      # Sp-Parameter
  161.  
  162.       :param_rate     => [FEATURE_PARAM, 'Param multipler'],        # Parameter
  163.       :special_flag   => [FEATURE_SPECIAL_FLAG, 'Special'],         # Special feature flag
  164.       :element_rate   => [FEATURE_ELEMENT_RATE, 'Element Rate'],    # Element Rate
  165.       :debuff_rate    => [FEATURE_DEBUFF_RATE, 'Debuff Rate'],      # Debuff Rate
  166.       :state_rate     => [FEATURE_STATE_RATE, 'State Rate'],        # State Rate
  167.       :state_resist   => [FEATURE_STATE_RESIST, 'State Resist'],    # State Resist
  168.       :atk_element    => [FEATURE_ATK_ELEMENT, 'Atk Element'],      # Atk Element
  169.       :atk_state      => [FEATURE_ATK_STATE, 'Atk State'],          # Atk State
  170.       :atk_speed      => [FEATURE_ATK_SPEED, 'Feature'],            # Atk Speed
  171.       :atk_times      => [FEATURE_ATK_TIMES, 'Feature'],            # Atk Times+
  172.       :stype_add      => [FEATURE_STYPE_ADD, 'Add Skill Type'],     # Add Skill Type
  173.       :stype_seal     => [FEATURE_STYPE_SEAL, 'Disable Skill Type'],# Disable Skill Type
  174.       :skill_add      => [FEATURE_SKILL_ADD, 'Add Skill'],          # Add Skill
  175.       :skill_seal     => [FEATURE_SKILL_SEAL, 'Disable Skill'],     # Disable Skill
  176.       :equip_wtype    => [FEATURE_EQUIP_WTYPE, 'Equip Weapon'],     # Equip Weapon
  177.       :equip_atype    => [FEATURE_EQUIP_ATYPE, 'Equip Armor'],      # Equip Armor
  178.       :equip_fix      => [FEATURE_EQUIP_FIX, 'Lock Equip'],         # Lock Equip
  179.       :equip_seal     => [FEATURE_EQUIP_SEAL, 'Seal Equip'],        # Seal Equip
  180.       :action_plus    => [FEATURE_ACTION_PLUS, 'Action Times+'],    # Action Times+
  181.       :party_ability  => [FEATURE_PARTY_ABILITY, 'Party ability'],  # Party ability
  182.  
  183.       # kinda useless, so I didn't implement it.
  184.       # :slot_type      => [FEATURE_SLOT_TYPE, 'Slot Type'],          # Slot Type
  185.     }
  186.     #---------------------------------------------------------------------
  187.     # * Id for equipment set, perhaps not necessary to change
  188.     FeatureEquipSet = -2
  189.     #---------------------------------------------------------------------
  190.     # * Compare with MA's equipment set diff
  191.     if $imported[:MA_EquipmentSetBonuses]
  192.       ComparisonTable[:equipset_plus] = [FeatureEquipSet, SetEquipmentText]
  193.     end
  194.     #---------------------------------------------------------------------
  195.     MISC_text = 'Other' # the group text not in this order list
  196.     #---------------------------------------------------------------------
  197.     # * Display order of comparison group text, upper one displayed first
  198.     TextDisplayOrder = [
  199.       '',         # suggestion: better not touch this line
  200.       'Feature',
  201.       'Special',
  202.       'Param multipler',
  203.       'Element Rate',
  204.       'Debuff Rate',
  205.       'State Rate',
  206.       'State Resist',
  207.       'Atk Element',
  208.       'Atk State',
  209.       'Atk Speed',
  210.       'Atk Times+',
  211.       'Add Skill Type',
  212.       'Disable Skill Type',
  213.       'Add Skill',
  214.       'Disable Skill',
  215.       'Equip Weapon',
  216.       'Equip Armor',
  217.       'Lock Equip',
  218.       'Seal Equip',
  219.       'Slot Type',
  220.       'Action Times+',
  221.       'Party ability',
  222.       MISC_text,
  223.       SetEquipmentText,
  224.     ]
  225.     #---------------------------------------------------------------------
  226.     # * Name display for each xparam
  227.     XParamName = {
  228.       0   => "HIT",  # HIT rate
  229.       1   => "EVA",  # EVAsion rate
  230.       2   => "CRI",  # CRItical rate
  231.       3   => "CEV",  # Critical EVasion rate
  232.       4   => "MEV",  # Magic EVasion rate
  233.       5   => "MRF",  # Magic ReFlection rate
  234.       6   => "CNT",  # CouNTer attack rate
  235.       7   => "HRG",  # Hp ReGeneration rate
  236.       8   => "MRG",  # Mp ReGeneration rate
  237.       9   => "TRG",  # Tp ReGeneration rate
  238.     }
  239.     #---------------------------------------------------------------------
  240.     # * Name display for each sparam
  241.     SParamName = {
  242.       0   => "TGR",  # TarGet Rate
  243.       1   => "GRD",  # GuaRD effect rate
  244.       2   => "REC",  # RECovery effect rate
  245.       3   => "PHA",  # PHArmacology
  246.       4   => "MCR",  # Mp Cost Rate
  247.       5   => "TCR",  # Tp Charge Rate
  248.       6   => "PDR",  # Physical Damage Rate
  249.       7   => "MDR",  # Magical Damage Rate
  250.       8   => "FDR",  # Floor Damage Rate
  251.       9   => "EXR",  # EXperience Rate
  252.     }
  253.     #---------------------------------------------------------------------
  254.     # * Name display for party ability
  255.     PartyAbilityName = {
  256.       0   => "Encounter Half",          # halve encounters
  257.       1   => "Encounter None",          # disable encounters
  258.       2   => "Cancel Surprise",         # disable surprise
  259.       3   => "Raise Preemptive",        # increase preemptive strike rate
  260.       4   => "Gold Double",             # double money earned
  261.       5   => "Item Drop Rate Double",   # double item acquisition rate
  262.     }
  263.     #---------------------------------------------------------------------
  264.     # * Name display for special feature
  265.     SpecialFeatureName = {
  266.       0 => "Auto Battle",
  267.       1 => "Guard",
  268.       2 => "Substitute",
  269.       3 => "Preserve TP",
  270.     }
  271.     #--------------------------------------------------------------------------
  272.     # * Text displayed when two equipments have no difference:
  273.     NoDiffText = "No Difference"
  274.     #--------------------------------------------------------------------------
  275.     # * Feature name displayed at first of the line, before value comparison
  276.     OtherFeatureName = {
  277.       # feature id        => display name
  278.       FEATURE_ATK_SPEED   => 'ASP',
  279.       FEATURE_ATK_TIMES   => 'ATS+',
  280.       FEATURE_ACTION_PLUS => '+%d:',
  281.     }
  282.     #---------------------------------------------------------------------
  283.     # * prefix of single feature comparison
  284.     FeatureAddText     = "+" + " %s"
  285.     FeatureRemoveText  = "-" + " %s"
  286.     FeatureEnableText  = "√" + " %s"
  287.     FeatureDisableText = "X" + " %s"
  288.     #---------------------------------------------------------------------
  289.     # * The feature id that is actually not good
  290.     InverseColorFeature = [
  291.       FEATURE_STYPE_SEAL, FEATURE_SKILL_SEAL, FEATURE_EQUIP_FIX,
  292.       FEATURE_EQUIP_SEAL, FEATURE_ELEMENT_RATE,
  293.     ]
  294.     #---------------------------------------------------------------------
  295.     # * The value of given feature id will disaply as percent
  296.     PercentageFeaure = [
  297.       FEATURE_ELEMENT_RATE, FEATURE_DEBUFF_RATE, FEATURE_STATE_RATE,
  298.       FEATURE_PARAM, FEATURE_XPARAM, FEATURE_SPARAM, FEATURE_ATK_STATE,
  299.       FEATURE_ACTION_PLUS,
  300.     ]
  301.     #--------------------------------------------------------------------------
  302.     # * Features that shows in status window when not comparing stuff
  303.     CurFeatureShow = [
  304.       FeatureNormalParam, FEATURE_PARTY_ABILITY, FEATURE_SKILL_ADD, FeatureEquipSet,
  305.     ]
  306.     #=====================================================================#
  307.     # Please don't edit anything below unless you know what you're doing! #
  308.     #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
  309.  
  310.     # Strcuture holds compare result of each difference
  311.     DiffInfo = Struct.new(:feature_id, :data_id, :value, :display_str, :group_text)
  312.     # :feature_id  > what do you expect me to say?
  313.     # :data_id     > data id in grouped feature, such as param
  314.     # :delta       > value changed of that feature, in certain feature id is:
  315.     #   true/false = add/remove after equip
  316.     #
  317.     # :display_str > Other text displayed
  318.     # :group_text  > even need to explain?
  319.  
  320.     # Uses to fill the small blanks where not proper to write more lines
  321.     DummyInfo = DiffInfo.new(nil, nil, nil, '')
  322.     #--------------------------------------------------------------------------
  323.     # * Mapping table for easier query
  324.     StringTable     = {}   # feature_id => group_text
  325.     FeatureIdTable  = {}   # group_text => feature_id
  326.     DisplayOrder    = {}   # group_text => order
  327.     DisplayIdOrder  = {}   # feature_id => order
  328.     ComparisonTable.each do |symbol, info|
  329.       StringTable[info[0]] = info[1]
  330.       FeatureIdTable[info[1]] = info[0]
  331.     end
  332.     TextDisplayOrder.each_with_index do |str, i|
  333.       DisplayOrder[str] = i
  334.       DisplayIdOrder[FeatureIdTable[str]] = i
  335.     end
  336.   end
  337. end
  338.  
  339. #==========================================================================
  340. # ** RPG::BaseItem
  341. #--------------------------------------------------------------------------
  342. #   This class is the super class of all database classes
  343. #==========================================================================
  344. class RPG::BaseItem
  345.   FEATURE_ACTION_PLUS   = 61              # Action Times+
  346.   FEATURE_SPECIAL_FLAG  = 62              # Special Flag
  347.   FEATURE_PARTY_ABILITY = 64              # Party Ability
  348.   #--------------------------------------------------------------------------
  349.   # * Get Feature Object Array (Feature Codes Limited)
  350.   #--------------------------------------------------------------------------
  351.   def features(code = nil)
  352.     return @features if code.nil?
  353.     @features.select {|ft| ft.code == code }
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Get Feature Object Array (Feature Codes and Data IDs Limited)
  357.   #--------------------------------------------------------------------------
  358.   def features_with_id(code, id)
  359.     @features.select {|ft| ft.code == code && ft.data_id == id }
  360.   end
  361.   #--------------------------------------------------------------------------
  362.   # * Calculate Complement of Feature Values
  363.   #--------------------------------------------------------------------------
  364.   def features_pi(code, id)
  365.     result = features_with_id(code, id).inject(1.0) {|r, ft| r *= ft.value }
  366.   end
  367.   #--------------------------------------------------------------------------
  368.   # * Calculate Sum of Feature Values (Specify Data ID)
  369.   #--------------------------------------------------------------------------
  370.   def features_sum(code, id)
  371.     features_with_id(code, id).inject(0.0) {|r, ft| r += ft.value }
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * Calculate Sum of Feature Values (Data ID Unspecified)
  375.   #--------------------------------------------------------------------------
  376.   def features_sum_all(code)
  377.     features(code).inject(0.0) {|r, ft| r += ft.value }
  378.   end
  379.   #--------------------------------------------------------------------------
  380.   # * Calculate Set Sum of Features
  381.   #--------------------------------------------------------------------------
  382.   def features_set(code)
  383.     features(code).inject([]) {|r, ft| r |= [ft.data_id] }
  384.   end
  385.   #--------------------------------------------------------------------------
  386.   # * Get Array of Additional Action Time Probabilities
  387.   #--------------------------------------------------------------------------
  388.   def action_plus_set
  389.     features(FEATURE_ACTION_PLUS).collect {|ft| ft.value }
  390.   end
  391.   #--------------------------------------------------------------------------
  392.   # * Determine if Special Flag
  393.   #--------------------------------------------------------------------------
  394.   def special_flag(flag_id)
  395.     features(FEATURE_SPECIAL_FLAG).any? {|ft| ft.data_id == flag_id }
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   # * Determine Party Ability
  399.   #--------------------------------------------------------------------------
  400.   def party_ability(ability_id)
  401.     features(FEATURE_PARTY_ABILITY).any? {|ft| ft.data_id == ability_id }
  402.   end
  403.   #--------------------------------------------------------------------------
  404. end
  405. #==============================================================================
  406. # ** RPG::EquipItem
  407. #==============================================================================
  408. class RPG::EquipItem < RPG::BaseItem
  409.   #---------------------------------------------------------------------------
  410.   def param(id)
  411.     return @params[id]
  412.   end
  413.   #---------------------------------------------------------------------------
  414. end
  415. #==============================================================================
  416. # ** Sprite
  417. #==============================================================================
  418. class Sprite
  419.   #---------------------------------------------------------------------------
  420.   def show
  421.     self.visible = true
  422.     self
  423.   end
  424.   #---------------------------------------------------------------------------
  425.   def hide
  426.     self.visible = false
  427.     self
  428.   end
  429.   #---------------------------------------------------------------------------
  430.   def visible?
  431.     return self.visible
  432.   end
  433.   #---------------------------------------------------------------------------
  434. end
  435. #==============================================================================
  436. # ** Window_Base
  437. #==============================================================================
  438. class Window_Base < Window
  439.   #---------------------------------------------------------------------------
  440.   def active?
  441.     return self.active
  442.   end
  443.   #---------------------------------------------------------------------------
  444.   def visible?
  445.     return self.visible
  446.   end
  447.   #---------------------------------------------------------------------------
  448. end
  449. #==============================================================================
  450. # ** Module of this script
  451. #==============================================================================
  452. module COMP::EECI
  453.   #--------------------------------------------------------------------------
  454.   # * Dummy equipment for which compare side is nil
  455.   Dummy = RPG::Weapon.new
  456.   Dummy.features.clear
  457. end
  458. #==============================================================================
  459. # ** Scene_Equip
  460. #==============================================================================
  461. class Scene_Equip < Scene_MenuBase
  462.   #--------------------------------------------------------------------------
  463.   Hint_Text      = COMP::EECI::Hint_Text
  464.   Hint_Canva     = COMP::EECI::Hint_Canva
  465.   Hint_Position  = COMP::EECI::Hint_Position
  466.   Hint_BackColor = COMP::EECI::Hint_BackColor
  467.   Hint_Fontsize  = COMP::EECI::Hint_Fontsize
  468.   Hint_Opacity   = COMP::EECI::Hint_Opacity
  469.   Hint_TextColor = COMP::EECI::Hint_TextColor
  470.   #--------------------------------------------------------------------------
  471.   # * alias: start
  472.   #--------------------------------------------------------------------------
  473.   alias start_eeci start
  474.   def start
  475.     start_eeci
  476.     create_eeci_hint_window
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   alias update_eeci update
  480.   def update
  481.     update_autohide_timer if @eeci_hint_timer
  482.     update_eeci
  483.   end
  484.   #--------------------------------------------------------------------------
  485.   def update_autohide_timer
  486.     return unless COMP::EECI::Auto_Hide
  487.     return if COMP::EECI::AutoHideTimer == 0
  488.     return if @eeci_hint_timer < 0
  489.     return unless @hint_sprite.visible?
  490.     @eeci_hint_timer -= 1 if @eeci_hint_timer >= 0
  491.     update_eeci_hint_visibility if @eeci_hint_timer < 0
  492.   end
  493.   #--------------------------------------------------------------------------
  494.   # * alias: slot [OK]
  495.   #--------------------------------------------------------------------------
  496.   alias on_slot_ok_eeci on_slot_ok
  497.   def on_slot_ok
  498.     item = @actor.equips.at(@slot_window.index)
  499.     item = COMP::EECI::Dummy if item.nil?
  500.     @status_window.set_template_item(item)
  501.     on_slot_ok_eeci
  502.   end
  503.   #--------------------------------------------------------------------------
  504.   def create_eeci_hint_window
  505.     return if Hint_Text.length == 0
  506.  
  507.     @eeci_hint_timer = nil
  508.     @hint_sprite = ::Sprite.new(@viewport)
  509.     bw, bh = *Hint_Canva
  510.  
  511.     temp_bmp = Bitmap.new(bw,bh)
  512.     temp_bmp.font.size = Hint_Fontsize
  513.     bw = [temp_bmp.text_size(Hint_Text).width + 4, bw].min
  514.     temp_bmp.dispose; temp_bmp = nil;
  515.  
  516.     @hint_sprite.bitmap = Bitmap.new(bw, bh)
  517.     sx, sy = 0, 0
  518.     if Hint_Position.is_a?(Array)
  519.       sx, sy = *Hint_Position
  520.     elsif Hint_Position == :BR_actor_status
  521.       sx = @actor_window.x + @actor_window.width  - bw
  522.       sy = @actor_window.y + @actor_window.height - bh
  523.     elsif Hint_Position == :BR_equip_status
  524.       sx = @status_window.x + @status_window.width - bw
  525.       sy = @status_window.y + @status_window.height - bh
  526.     end
  527.     @hint_sprite.x, @hint_sprite.y = sx, sy;
  528.     @hint_sprite.opacity = Hint_Opacity
  529.  
  530.     @hint_sprite.bitmap.font.size = Hint_Fontsize
  531.     @hint_sprite.bitmap.font.color.set(Hint_TextColor)
  532.     @hint_sprite.bitmap.fill_rect(0, 0, bw, bh, Hint_BackColor)
  533.     @hint_sprite.bitmap.draw_text(2, 0, bw, bh, Hint_Text)
  534.     @hint_sprite.z = @viewport.z
  535.    
  536.     update_eeci_hint_visibility
  537.   end
  538.   #--------------------------------------------------------------------------
  539.   def update_eeci_hint_visibility
  540.     return unless @hint_sprite
  541.     return @hint_sprite.show if !COMP::EECI::Auto_Hide
  542.     return @hint_sprite.hide if @eeci_hint_timer && @eeci_hint_timer < 0
  543.  
  544.     if @status_window.nil? || @item_window.nil? || !@status_window.visible?
  545.       @hint_sprite.hide
  546.       return
  547.     end
  548.    
  549.     if @item_window.active?
  550.       if @status_window.pages.size > @status_window.line_max
  551.         @hint_sprite.show
  552.         @eeci_hint_timer = COMP::EECI::AutoHideTimer unless @eeci_hint_timer
  553.       else
  554.         @hint_sprite.hide
  555.       end
  556.     else
  557.       if @status_window.base_pages.size > @status_window.line_max
  558.         @hint_sprite.show
  559.         @eeci_hint_timer = COMP::EECI::AutoHideTimer unless @eeci_hint_timer
  560.       else
  561.         @hint_sprite.hide
  562.       end
  563.     end
  564.   end
  565.   #--------------------------------------------------------------------------
  566.   alias :terminate_eeci :terminate
  567.   def terminate
  568.     @hint_sprite.dispose if @hint_sprite
  569.     terminate_eeci
  570.   end
  571. end
  572. #==============================================================================
  573. # ** Window_EquipItem
  574. #==============================================================================
  575. class Window_EquipItem < Window_ItemList
  576.   #--------------------------------------------------------------------------
  577.   # * alias: update help
  578.   #--------------------------------------------------------------------------
  579.   alias update_help_eeci update_help
  580.   def update_help
  581.     @status_window.set_compare_item(item) if @actor && @status_window
  582.     update_help_eeci
  583.   end
  584. end
  585. #==============================================================================
  586. # ** Window_EquipSlot
  587. #==============================================================================
  588. class Window_EquipSlot < Window_Selectable
  589.   #---------------------------------------------------------------------------
  590.   # * alias: refresh
  591.   #---------------------------------------------------------------------------
  592.   alias refresh_eeci refresh
  593.   def refresh
  594.     refresh_eeci
  595.     return unless @status_window
  596.     @status_window.set_base_actor(@actor)
  597.     @status_window.collect_current_feature
  598.     @status_window.draw_current_feature
  599.   end
  600. end
  601. #==============================================================================
  602. # ** Window_EquipStatus
  603. #==============================================================================
  604. class Window_EquipStatus < Window_Base
  605.   include COMP::EECI
  606.   EQS_Enable = $imported[:MA_EquipmentSetBonuses]
  607.   #---------------------------------------------------------------------------
  608.   # * Instance variables
  609.   #---------------------------------------------------------------------------
  610.   attr_reader :template_item, :compare_item, :base_actor, :feature_cache
  611.   attr_reader :pages, :page_index, :base_pages
  612.   #---------------------------------------------------------------------------
  613.   # * Alias method: initialize
  614.   #---------------------------------------------------------------------------
  615.   alias init_eeci initialize
  616.   def initialize(*args)
  617.     @line_max       = nil   # Cache max line for faster query
  618.     @feature_cache  = {}    # Cache feature value for faster query
  619.     @pages          = []    # Comparison result array
  620.     @base_pages     = []    # Actor current status array
  621.     @page_index     = 0     # Current page index
  622.     @base_actor     = nil   # For caching paramters
  623.     @fiber          = nil   # Coroutine fiber
  624.     @cw = nil               # Contents width, for window arrows hacks
  625.     collect_compare_priority
  626.     init_eeci(*args)
  627.     @ori_contents_width = width - standard_padding * 2  # the 'real' contents width
  628.     @visible_height = height
  629.   end
  630.   #---------------------------------------------------------------------------
  631.   # * Comparsion priority according to display order
  632.   #--------------------------------------------------------------------------
  633.   def collect_compare_priority
  634.     @compare_quque = []
  635.     @compare_quque = ComparisonTable.sort_by{|k, dar|
  636.       DisplayOrder[StringTable[dar.first]] ? DisplayOrder[StringTable[dar.first]] : DisplayOrder[MISC_text]
  637.     }.collect{|p| p[0]}
  638.   end
  639.   #---------------------------------------------------------------------------
  640.   # * Dummy method, does nothing
  641.   #---------------------------------------------------------------------------
  642.   def pass(*args, &block)
  643.   end
  644.   #---------------------------------------------------------------------------
  645.   # * Max lines can be displayed in window at once
  646.   #--------------------------------------------------------------------------
  647.   def line_max
  648.     return @line_max if @line_max
  649.     return @line_max = contents_height / line_height
  650.   end
  651.   #---------------------------------------------------------------------------
  652.   # * Alias method: update
  653.   #---------------------------------------------------------------------------
  654.   alias update_eeci update
  655.   def update
  656.     update_eeci
  657.     update_page
  658.   end
  659.   #---------------------------------------------------------------------------
  660.   # * update page next/last
  661.   #---------------------------------------------------------------------------
  662.   def update_page
  663.     if Input.trigger?(Key_nextpage)
  664.       next_page
  665.     elsif Input.trigger?(Key_lastpage) && @page_index > 0
  666.       last_page
  667.     end
  668.   end
  669.   #---------------------------------------------------------------------------
  670.   def next_page
  671.     current_pages = @temp_actor.nil? ? @base_pages : @pages
  672.     next_page = @page_index + 1
  673.     resume_comparison if current_pages[next_page * line_max].nil? && !compare_over?
  674.     if current_pages[next_page * line_max]
  675.       # pre-compare next page if coroutine is still running
  676.       resume_comparison unless compare_over?
  677.       @page_index = next_page
  678.       update_arrows(current_pages)
  679.       draw_page(@temp_actor.nil?, @page_index)
  680.     end
  681.   end
  682.   #---------------------------------------------------------------------------
  683.   def last_page
  684.     current_pages = @temp_actor.nil? ? @base_pages : @pages
  685.     @page_index -= 1
  686.     update_arrows(current_pages)
  687.     draw_page(@temp_actor.nil?, @page_index)
  688.   end
  689.   #---------------------------------------------------------------------------
  690.   def contents_width
  691.     return super if @cw.nil?
  692.     return @cw
  693.   end
  694.   #---------------------------------------------------------------------------
  695.   # * Determine window arrow display
  696.   #---------------------------------------------------------------------------
  697.   def update_arrows(current_pages)
  698.     @dx = 0
  699.     self.ox = 0
  700.     offset = standard_padding * 4
  701.     @cw = @ori_contents_width
  702.     lv = true if @page_index > 0
  703.     rv = current_pages[(@page_index + 1) * line_max].nil? ? false : true
  704.     if lv # show left arrow
  705.       @cw += offset
  706.       @dx     = offset
  707.       self.ox = offset
  708.     end
  709.     @cw += offset if rv # show right arrow
  710.     create_contents
  711.   end
  712.   #---------------------------------------------------------------------------
  713.   def compare_over?
  714.     @fiber == nil
  715.   end
  716.   #---------------------------------------------------------------------------
  717.   def resume_comparison
  718.     return if @fiber.nil?
  719.     begin
  720.       @fiber.resume
  721.     rescue FiberError => e
  722.       @fiber = nil
  723.     end
  724.     SceneManager.scene.update_eeci_hint_visibility
  725.   end
  726.   #---------------------------------------------------------------------------
  727.   def set_template_item(item)
  728.     return if @template_item == item
  729.     @template_item = item
  730.     @template_item = item.nil? ? Dummy : item
  731.   end
  732.   #---------------------------------------------------------------------------
  733.   def set_compare_item(item)
  734.     return if @compare_item == item
  735.     @compare_item = item.nil? ? Dummy : item
  736.   end
  737.   #---------------------------------------------------------------------------
  738.   def set_base_actor(actor)
  739.     @feature_cache.clear
  740.     @base_actor = actor
  741.   end
  742.   #---------------------------------------------------------------------------
  743.   # * Overwrite method: actor=
  744.   #---------------------------------------------------------------------------
  745.   def actor=(actor)
  746.     return if @actor == actor
  747.     @actor = actor
  748.     collect_current_feature
  749.     refresh
  750.   end
  751.   #---------------------------------------------------------------------------
  752.   # * Overwrite method: refresh
  753.   #---------------------------------------------------------------------------
  754.   def refresh
  755.     contents.clear
  756.     @cw = nil
  757.     @pages      = []
  758.     @page_index =  0
  759.     return unless @actor
  760.     start_compare(:diff) if @temp_actor
  761.     stage = (@temp_actor) ? :diff : :current
  762.     resume_comparison
  763.     draw_compare_result(stage == :current)
  764.     SceneManager.scene.update_eeci_hint_visibility
  765.   end
  766.   #---------------------------------------------------------------------------
  767.   def collect_current_feature
  768.     return unless @actor
  769.     start_compare(:current, true)
  770.   end
  771.   #---------------------------------------------------------------------------
  772.   def start_compare(stage = :diff, restart = false)
  773.     if stage == :diff
  774.       save_fiber if !compare_over?
  775.       @fiber = Fiber.new{compare_diffs(stage)}
  776.     elsif stage == :current
  777.       if restart
  778.         release_fiber
  779.         @current_feature = {}
  780.         @base_pages      = []
  781.         @fiber = Fiber.new{compare_diffs(stage)}
  782.       elsif @saved_fiber
  783.         load_fiber
  784.       end
  785.     else
  786.       raise ArgumentError, "Invalid stage symbol (#{stage})"
  787.     end
  788.     resume_comparison
  789.   end
  790.   #---------------------------------------------------------------------------
  791.   def save_fiber
  792.     @saved_fiber = @fiber
  793.   end
  794.   #---------------------------------------------------------------------------
  795.   def load_fiber
  796.     @fiber = @saved_fiber
  797.     release_fiber
  798.   end
  799.   #---------------------------------------------------------------------------
  800.   def release_fiber
  801.     @saved_fiber = nil
  802.   end
  803.   #---------------------------------------------------------------------------
  804.   def process_compare_break(stage)
  805.     @current_line_number = 0
  806.     @draw_break = true
  807.     @showed_group = {}
  808.     Fiber.yield
  809.   end
  810.   #---------------------------------------------------------------------------
  811.   def compare_diffs(stage = :diff)
  812.     return if line_max < 2
  813.     set_compare_item(Dummy) if @compare_item.nil? && stage != :current
  814.     en_prefix   = [FeatureDisableText, FeatureEnableText]  
  815.     @current_line_number = 0 unless stage == :eqset
  816.     last_id = nil
  817.     @showed_group = {}
  818.     @compare_quque.each do |symbol|
  819.       feature_id  = ComparisonTable[symbol].at(0)
  820.       @current_group_text = ComparisonTable[symbol].at(1) || ''
  821.       case symbol
  822.       when :param;        compare_param(stage);
  823.       when :param_rate;   compare_valued_feature(stage,feature_id, true)
  824.       when :xparam;       compare_features_sum(stage,feature_id);
  825.       when :sparam;       compare_features_pi(stage,feature_id);
  826.       when :debuff_rate;  compare_valued_feature(stage, feature_id, true);
  827.       when :skill_add;    compare_features_set(stage,feature_id);
  828.       when :skill_seal;   compare_features_set(stage,feature_id, en_prefix.reverse);
  829.       when :element_rate; compare_features_pi(stage,feature_id);
  830.       when :atk_element;  compare_features_set(stage,feature_id);
  831.       when :atk_state;    compare_valued_feature(stage,feature_id, false);
  832.       when :state_rate;   compare_valued_feature(stage,feature_id, true);
  833.       when :state_resist; compare_features_set(stage,feature_id);
  834.       when :stype_seal;   compare_features_set(stage,feature_id, en_prefix.reverse);
  835.       when :stype_add;    compare_features_set(stage,feature_id, en_prefix);
  836.       when :atk_speed;    compare_features_sum(stage,feature_id);
  837.       when :atk_times;    compare_features_sum(stage,feature_id);
  838.       when :action_plus;  compare_action_plus(stage,feature_id);
  839.       when :special_flag; compare_special_flag(stage,feature_id);
  840.       when :party_ability;compare_party_ability(stage,feature_id);
  841.       when :equip_fix;    compare_features_set(stage, feature_id, en_prefix.reverse);
  842.       when :equip_seal;   compare_features_set(stage, feature_id, en_prefix.reverse);
  843.       when :equip_wtype;  compare_features_set(stage, feature_id);
  844.       when :equip_atype;  compare_features_set(stage, feature_id);
  845.       end
  846.       process_compare_break(stage) if @current_line_number >= line_max && !@draw_break
  847.       if EQS_Enable && stage != :eqset && feature_id == FeatureEquipSet
  848.         collect_equipment_set_diff(stage == :current)
  849.       end
  850.       last_id = feature_id
  851.       @draw_break = false
  852.       process_compare_break(stage) if @current_line_number >= line_max && !@draw_break
  853.     end # ComparisonTable.each
  854.   end
  855.   #---------------------------------------------------------------------------
  856.   def get_cache_feature(id, method, *args, &block)
  857.     return @feature_cache[id] if @feature_cache[id]
  858.     return unless @base_actor
  859.     return (@feature_cache[id] = @base_actor.send(method, *args, &block))
  860.   end
  861.   #---------------------------------------------------------------------------
  862.   def hash_feature_idx(feature_id, index = 0)
  863.     return index * 10000 + feature_id
  864.   end
  865.   #---------------------------------------------------------------------------
  866.   def push_new_comparison(stage, info)
  867.     push_group_info(stage, info)
  868.    
  869.     if stage == :current || (stage == :eqset && @last_stage == :current)
  870.       @base_pages << info
  871.     else
  872.       @pages << info
  873.     end
  874.     @current_line_number += 1
  875.     if @current_line_number >= line_max
  876.       process_compare_break(stage)
  877.     end
  878.   end
  879.   #---------------------------------------------------------------------------
  880.   def push_group_info(stage, info)
  881.     str = []
  882.     # push equipment set name if this is a feature of that
  883.     str.push(sprintf(SetEquipmentText, @set_bonus_item.name)) if @set_bonus_item
  884.     str.push(@current_group_text)
  885.     ori_group = str.dup
  886.     str.select!{|s| s.length > 0}
  887.     str.select!{|s| !@showed_group[s]}
  888.  
  889.     reserve_line  = str.size
  890.     reserve_line += 2 if str.size > 0
  891.  
  892.     if @current_line_number + reserve_line > line_max
  893.       # Stocking with blank infos if no much space left
  894.       (line_max - @current_line_number).times do |_|
  895.         if stage == :current || (stage == :eqset && @last_stage == :current)
  896.           @base_pages.push(DummyInfo)
  897.         else
  898.           @pages.push(DummyInfo)
  899.         end
  900.       end
  901.       process_compare_break(stage)
  902.       str = ori_group
  903.     end
  904.  
  905.     # Push group text line
  906.     str.each do |s|
  907.       @showed_group[s] = true
  908.       @current_line_number += 1
  909.       duminfo = DummyInfo.dup; duminfo.group_text = s;
  910.       if stage == :current || (stage == :eqset && @last_stage == :current)
  911.         @base_pages.push(duminfo)
  912.       else
  913.         @pages.push(duminfo)
  914.       end
  915.     end # each group text
  916.   end
  917.   #---------------------------------------------------------------------------
  918.   def compare_param(stage)
  919.     feature_id = FeatureNormalParam
  920.     ar = get_feature_array(feature_id)
  921.     len = ar.size
  922.     len.times do |i|
  923.       str = get_feature_name(feature_id, i)
  924.       # Show current actor feature status
  925.       if stage == :current
  926.         v = @actor.param(i)
  927.         push_new_comparison(stage, DiffInfo.new(feature_id,i,[v,v],str))
  928.         next
  929.       # Comparison
  930.       else
  931.         a = @compare_item.param(i)
  932.         b = @template_item.param(i)
  933.         next if a - b == 0
  934.         base = (get_cache_feature(i, :param, i) || 0)
  935.         a += base - b
  936.         push_new_comparison(stage, DiffInfo.new(feature_id, i, [a,base], str))
  937.       end
  938.     end
  939.   end
  940.   #---------------------------------------------------------------------------
  941.   def compare_features_sum(stage,feature_id)
  942.     ar = get_feature_array(feature_id); len = ar.size;
  943.     if len == 0
  944.       str = get_feature_name(feature_id)
  945.       # Show current actor feature status
  946.       if stage == :current
  947.         return unless CurFeatureShow.include?(feature_id)
  948.         v = @actor.features_sum_all(feature_id)
  949.         return if v == 0
  950.         push_new_comparison(stage, DiffInfo.new(feature_id,0,[v,v],str))
  951.         return
  952.       else
  953.         # Comparison
  954.         a = @compare_item.features_sum_all(feature_id)
  955.         b = @template_item.features_sum_all(feature_id)
  956.         delta = (a - b)
  957.         delta = delta.round(2) if delta.is_a?(Float)
  958.         return if delta == 0
  959.         base = (get_cache_feature(feature_id, :features_sum_all, feature_id) || 0)
  960.         a += base - b
  961.         push_new_comparison(stage, DiffInfo.new(feature_id, 0, [a,base], str))
  962.       end
  963.     else
  964.       len.times do |i|
  965.         str = get_feature_name(feature_id, i)
  966.         # Show current actor feature status
  967.         if stage == :current
  968.           return unless CurFeatureShow.include?(feature_id)
  969.           v = @actor.features_sum(feature_id, i)
  970.           next if v == 0
  971.           push_new_comparison(stage, DiffInfo.new(feature_id,i,[v,v],str))
  972.           next
  973.         else
  974.           # Comparison
  975.           a = @compare_item.features_sum(feature_id, i)
  976.           b = @template_item.features_sum(feature_id, i)
  977.           delta = (a - b)
  978.           delta = delta.round(2) if delta.is_a?(Float)
  979.           next if delta == 0
  980.           base = (get_cache_feature(hash_feature_idx(feature_id, i), :features_sum, feature_id, i) || 0)
  981.           a += base - b
  982.           push_new_comparison(stage, DiffInfo.new(feature_id, i, [a,base], str))
  983.         end
  984.       end # len.times
  985.     end # if len ==0
  986.   end
  987.   #---------------------------------------------------------------------------
  988.   def compare_features_pi(stage, feature_id)
  989.     ar = get_feature_array(feature_id); len = ar.size;
  990.     len.times do |i|
  991.       str = get_feature_name(feature_id, i)
  992.       # Show current actor feature status
  993.       if stage == :current
  994.         return unless CurFeatureShow.include?(feature_id)
  995.         v = @actor.features_pi(feature_id, i)
  996.         next if v == 1.0
  997.         push_new_comparison(stage, DiffInfo.new(feature_id,i,[v,v],str))
  998.         next
  999.       else
  1000.         # Comparison
  1001.         a = @compare_item.features_pi(feature_id, i)
  1002.         b = @template_item.features_pi(feature_id, i)
  1003.         delta = (a - b)
  1004.         delta = delta.round(2) if delta.is_a?(Float)
  1005.         next if delta == 0
  1006.         base = get_cache_feature(hash_feature_idx(feature_id, i), :features_pi, feature_id, i)
  1007.         base = 1 if base.nil?
  1008.         a *= base
  1009.         a /= b
  1010.         push_new_comparison(stage, DiffInfo.new(feature_id, i, [a,base], str))
  1011.       end
  1012.     end
  1013.   end
  1014.   #---------------------------------------------------------------------------
  1015.   def compare_features_set(stage, feature_id, prefix = [FeatureRemoveText, FeatureAddText])
  1016.     # Show current actor feature status
  1017.     if stage == :current
  1018.       return unless CurFeatureShow.include?(feature_id)
  1019.       feats = @actor.features_set(feature_id)
  1020.       feats.each do |i|
  1021.         str = sprintf(prefix[1], get_feature_name(feature_id, i))
  1022.         push_new_comparison(stage, DiffInfo.new(feature_id,i,true,str))
  1023.       end
  1024.       return
  1025.     else
  1026.       # Comparison
  1027.       after  = @compare_item.features_set(feature_id)
  1028.       before = @template_item.features_set(feature_id)
  1029.      
  1030.       diffs = []
  1031.       after.select{|id| !before.include?(id)}.each do |id|
  1032.         str = sprintf(prefix[1], get_feature_name(feature_id, id))
  1033.         diffs << DiffInfo.new(feature_id, id,  true, str)
  1034.       end
  1035.      
  1036.       before.select{|id| !after.include?(id)}.each do |id|
  1037.         str = sprintf(prefix[0], get_feature_name(feature_id, id))
  1038.         diffs << DiffInfo.new(feature_id, id, false, str)
  1039.       end
  1040.  
  1041.       diffs.each do |info|
  1042.         push_new_comparison(stage, info)
  1043.       end
  1044.  
  1045.     end
  1046.   end
  1047.   #---------------------------------------------------------------------------
  1048.   def compare_valued_feature(stage,feature_id, pi)
  1049.     # Show current actor feature status
  1050.     if stage == :current
  1051.       return unless CurFeatureShow.include?(feature_id)
  1052.       feats = @actor.features_set(feature_id)
  1053.       feats.each do |i|
  1054.         str = get_feature_name(feature_id, i)
  1055.         if pi
  1056.           v = @actor.features_pi(feature_id, i)
  1057.           next if v == 1
  1058.         else
  1059.           v = @actor.features_sum(feature_id, i)
  1060.           next if v == 0
  1061.         end
  1062.         push_new_comparison(stage, DiffInfo.new(feature_id,i,[v,v],str))
  1063.       end # each feat
  1064.       return
  1065.     else
  1066.       # Comparison
  1067.       after  = @compare_item.features_set(feature_id)
  1068.       before = @template_item.features_set(feature_id)
  1069.       prefix = [FeatureRemoveText, FeatureAddText]
  1070.       (after + before).uniq.sort.each do |id|
  1071.         if pi
  1072.           a = @compare_item.features_pi(feature_id, id)
  1073.           b = @template_item.features_pi(feature_id, id)
  1074.           method_symbol = :features_pi
  1075.         else
  1076.           a = @compare_item.features_sum(feature_id, id)
  1077.           b = @template_item.features_sum(feature_id, id)
  1078.           method_symbol = :features_sum
  1079.         end
  1080.         next if a - b == 0
  1081.         if pi
  1082.           base = get_cache_feature(hash_feature_idx(feature_id, id), method_symbol, feature_id, id)
  1083.           base = 1 if base.nil?
  1084.           a *= base / b
  1085.         else
  1086.           base = (get_cache_feature(hash_feature_idx(feature_id, id), method_symbol, feature_id, id) || 0)
  1087.           a += base - b
  1088.         end
  1089.         str = get_feature_name(feature_id, id)
  1090.         push_new_comparison(stage, DiffInfo.new(feature_id, id, [a,base], str))
  1091.       end
  1092.     end
  1093.   end
  1094.   #---------------------------------------------------------------------------
  1095.   def compare_action_plus(stage,feature_id)
  1096.     # Show current actor feature status
  1097.     if stage == :current
  1098.       return unless CurFeatureShow.include?(feature_id)
  1099.       ar = @actor.action_plus_set.sort{|a,b| b <=> a}
  1100.       ar.each_with_index do |v,i|
  1101.         str = sprintf(get_feature_name(feature_id), i+1)
  1102.         push_new_comparison(stage, DiffInfo.new(feature_id,i,[v,v],str))
  1103.       end
  1104.       return
  1105.     else
  1106.       # Comparison
  1107.       after  = @compare_item.action_plus_set.sort{|a,b| b <=> a}
  1108.       before = @template_item.action_plus_set.sort{|a,b| b <=> a}
  1109.       return if after.size == 0 && before.size == 0
  1110.       n = [after.size, before.size].max
  1111.       n.times do |i|
  1112.         a = (after[i]  || 0)
  1113.         b = (before[i] || 0)
  1114.         str = sprintf(get_feature_name(feature_id), i+1)
  1115.         push_new_comparison(stage, DiffInfo.new(feature_id, 0, [a,b], str))
  1116.       end
  1117.     end
  1118.   end
  1119.   #---------------------------------------------------------------------------
  1120.   def compare_special_flag(stage,feature_id, prefix = [FeatureRemoveText, FeatureAddText])
  1121.     ar = SpecialFeatureName
  1122.     ar.each do |i, str|
  1123.       # Show current actor feature status
  1124.       if stage == :current
  1125.         return unless CurFeatureShow.include?(feature_id)
  1126.         en = @actor.special_flag(i)
  1127.         next unless en
  1128.         str = sprintf(prefix[1], str)
  1129.         push_new_comparison(stage, DiffInfo.new(feature_id,i,true,str))
  1130.         next
  1131.       else
  1132.         # Comparison
  1133.         before = @template_item.special_flag(i)
  1134.         after  = @compare_item.special_flag(i)
  1135.         next if before == after
  1136.         enabled = after ? 1 : 0
  1137.         str = sprintf(prefix[enabled], str)
  1138.         push_new_comparison(stage, DiffInfo.new(feature_id, i, after, str))
  1139.       end
  1140.     end
  1141.   end
  1142.   #---------------------------------------------------------------------------
  1143.   def compare_party_ability(stage,feature_id, prefix = [FeatureRemoveText, FeatureAddText])
  1144.     ar = PartyAbilityName
  1145.     ar.each do |i, str|
  1146.       # Show current actor feature status
  1147.       if stage == :current
  1148.         return unless CurFeatureShow.include?(feature_id)
  1149.         en = @actor.party_ability(i)
  1150.         next unless en
  1151.         str = sprintf(prefix[1], str)
  1152.         push_new_comparison(stage, DiffInfo.new(feature_id,i,true,str))
  1153.         next
  1154.       else
  1155.         # Comparison
  1156.         before = @template_item.party_ability(i)
  1157.         after  = @compare_item.party_ability(i)
  1158.         next if before == after
  1159.         enabled = after ? 1 : 0
  1160.         str = sprintf(prefix[enabled], str)
  1161.         push_new_comparison(stage, DiffInfo.new(feature_id, i, after, str))
  1162.       end
  1163.     end
  1164.   end
  1165.   #--------------------------------------------------------------------------
  1166.   # * Get Equipment Slot Name
  1167.   #--------------------------------------------------------------------------
  1168.   def slot_name(index)
  1169.     @actor ? Vocab::etype(@actor.equip_slots[index]) : ""
  1170.   end
  1171.   #---------------------------------------------------------------------------
  1172.   def get_group_text(feature_id)
  1173.     return StringTable[feature_id]
  1174.   end
  1175.   #---------------------------------------------------------------------------
  1176.   def get_feature_name(feature_id, index = nil)
  1177.     name = ''
  1178.     case feature_id
  1179.     when FEATURE_DEBUFF_RATE;   name = Vocab.param(index);
  1180.     when FeatureNormalParam;    name = Vocab.param(index);
  1181.     when FEATURE_ATK_ELEMENT;   name = $data_system.elements[index];
  1182.     when FEATURE_ELEMENT_RATE;  name = $data_system.elements[index];
  1183.     when FEATURE_PARAM;         name = Vocab.param(index);
  1184.     when FEATURE_XPARAM;        name = XParamName[index];
  1185.     when FEATURE_SPARAM;        name = SParamName[index];
  1186.     when FEATURE_SKILL_ADD;     name = ($data_skills[index].name rescue '');
  1187.     when FEATURE_SKILL_SEAL;    name = ($data_skills[index].name rescue '');
  1188.     when FEATURE_STATE_RATE;    name = ($data_states[index].name rescue '');
  1189.     when FEATURE_STATE_RESIST;  name = ($data_states[index].name rescue '');
  1190.     when FEATURE_ATK_STATE;     name = ($data_states[index].name rescue '');
  1191.     when FEATURE_EQUIP_WTYPE;   name = $data_system.weapon_types[index];
  1192.     when FEATURE_EQUIP_ATYPE;   name = $data_system.armor_types[index];
  1193.     when FEATURE_STYPE_ADD;     name = $data_system.skill_types[index];
  1194.     when FEATURE_STYPE_SEAL;    name = $data_system.skill_types[index];
  1195.     when FEATURE_PARTY_ABILITY; name = PartyAbilityName[index];
  1196.     when FEATURE_SPECIAL_FLAG;  name = SpecialFeatureName[index];
  1197.     when FEATURE_EQUIP_FIX;     name = slot_name(index);
  1198.     when FEATURE_EQUIP_SEAL;    name = slot_name(index);
  1199.     else
  1200.       return OtherFeatureName[feature_id] || ""
  1201.     end
  1202.     return name  || ''
  1203.   end
  1204.   #---------------------------------------------------------------------------
  1205.   def get_feature_array(feature_id)
  1206.     case feature_id
  1207.     when FeatureNormalParam;    return Array.new($data_system.terms.params.size);
  1208.     when FEATURE_ATK_ELEMENT;   return $data_system.elements;
  1209.     when FEATURE_ELEMENT_RATE;  return $data_system.elements;
  1210.     when FEATURE_PARAM;         return Array.new($data_system.terms.params.size);
  1211.     when FEATURE_DEBUFF_RATE;   return Array.new($data_system.terms.params.size);
  1212.     when FEATURE_XPARAM;        return Array.new(XParamName.size);
  1213.     when FEATURE_SPARAM;        return Array.new(SParamName.size);
  1214.     when FEATURE_SKILL_ADD;     return $data_skills;
  1215.     when FEATURE_SKILL_SEAL;    return $data_skills;
  1216.     when FEATURE_STATE_RATE;    return $data_states;
  1217.     when FEATURE_STATE_RESIST;  return $data_states;
  1218.     when FEATURE_ATK_STATE;     return $data_states;
  1219.     when FEATURE_EQUIP_WTYPE;   return $data_system.weapon_types;
  1220.     when FEATURE_EQUIP_WTYPE;   return $data_system.armor_types;
  1221.     when FEATURE_STYPE_ADD;     return $data_system.skill_types;
  1222.     when FEATURE_STYPE_SEAL;    return $data_system.skill_types;
  1223.     when FEATURE_PARTY_ABILITY; return PartyAbilityName;
  1224.     when FEATURE_SPECIAL_FLAG;  return SpecialFeatureName;
  1225.     when FEATURE_EQUIP_FIX;     return $data_system.terms.etypes;
  1226.     when FEATURE_EQUIP_SEAL;    return $data_system.terms.etypes;
  1227.     else
  1228.       return []
  1229.     end
  1230.   end
  1231.   #---------------------------------------------------------------------------
  1232.   def draw_current_feature
  1233.     resume_comparison
  1234.     draw_compare_result(true)
  1235.   end
  1236.   #---------------------------------------------------------------------------
  1237.   def draw_page(cur_feat, index)
  1238.     head = index * line_max
  1239.     rear = (index + 1) * line_max - 1
  1240.     # the lines for current page
  1241.     list = cur_feat ? @base_pages[head..[@base_pages.size-1, rear].min] : @pages[head..[@pages.size, rear].min]
  1242.     return if list.nil?
  1243.     contents.clear
  1244.     last_display_group = ''
  1245.     @comparing = !cur_feat
  1246.     return draw_nodiff_text if list.size == 0
  1247.     dy = 0
  1248.     list.each_with_index do |info, i|
  1249.       feature_id = info.feature_id
  1250.       if (info.group_text || '').length > 0
  1251.         if EQS_Enable && info.group_text.match(SetEquipmentTextStem)
  1252.           draw_equipset_title(@dx, dy, info.group_text || '')
  1253.           dy += line_height
  1254.         elsif last_display_group != info.group_text
  1255.           last_display_group = info.group_text
  1256.           rect = Rect.new(@dx, dy, @ori_contents_width, line_height)
  1257.           draw_text(rect, info.group_text)
  1258.           dy += line_height
  1259.         end
  1260.       end
  1261.       next if info.feature_id.nil?
  1262.       draw_item(@dx, dy, info)
  1263.       dy += line_height
  1264.     end
  1265.   end
  1266.   #---------------------------------------------------------------------------
  1267.   def draw_nodiff_text
  1268.     self.contents.draw_text(@dx, 4, @ori_contents_width, line_height, NoDiffText)
  1269.   end
  1270.   #---------------------------------------------------------------------------
  1271.   def draw_compare_result(cur_feat = false)
  1272.     resume_comparison
  1273.     update_arrows(cur_feat ? @base_pages : @pages)
  1274.     draw_page(cur_feat, 0)
  1275.   end
  1276.   #---------------------------------------------------------------------------
  1277.   # * Draw the name of equipment set
  1278.   #---------------------------------------------------------------------------
  1279.   def draw_equipset_title(dx, dy, str)
  1280.     return if str.length == 0
  1281.     change_color(crisis_color)
  1282.     draw_text(dx, dy, @ori_contents_width, line_height, str)
  1283.     change_color(normal_color)
  1284.   end
  1285.   #---------------------------------------------------------------------------
  1286.   # * Overwrite: draw_item
  1287.   #---------------------------------------------------------------------------
  1288.   def draw_item(dx, dy, info)
  1289.     # YEA Equip Engine code
  1290.     if $imported["YEA-AceEquipEngine"]
  1291.       self.contents.font.size = YEA::EQUIP::STATUS_FONT_SIZE
  1292.       draw_background_colour(dx, dy)
  1293.     end
  1294.  
  1295.     # Draw feature add/remove
  1296.     if info.value == true || info.value == false
  1297.       a = (info.value ? 1 : 0)
  1298.       b = (info.value ? 0 : 1)
  1299.       # Inverse the color effect if feature is not good
  1300.       inverse = InverseColorFeature.include?(info.feature_id)
  1301.      
  1302.       if inverse
  1303.         a ^= 1; b ^= 1;
  1304.       end
  1305.      
  1306.       change_color(param_change_color(a - b))
  1307.  
  1308.       # draw skill change with the icon
  1309.       if [FEATURE_SKILL_ADD, FEATURE_SKILL_SEAL].include?(info.feature_id)
  1310.         draw_skill_change(dx + 2, dy, info)
  1311.       else
  1312.         draw_info_change(dx, dy, info.display_str)
  1313.       end
  1314.       change_color(normal_color)
  1315.     else
  1316.       draw_info_name(dx + 4, dy, info.display_str)
  1317.       draw_info_diff(dx, dy, info)
  1318.     end
  1319.     reset_font_settings if $imported["YEA-AceEquipEngine"]
  1320.   end
  1321.   #---------------------------------------------------------------------------
  1322.   # * Draw add/remove/enable/disable text
  1323.   #---------------------------------------------------------------------------
  1324.   def draw_info_change(dx, dy, str)
  1325.     rect = Rect.new(dx, dy, @ori_contents_width-4, line_height)
  1326.     draw_text(rect, str, 2)
  1327.   end
  1328.   #---------------------------------------------------------------------------
  1329.   def draw_skill_change(dx, dy, info)
  1330.     str = info.display_str
  1331.     return draw_info_change(dx, dy, str) unless (info.data_id || 0) > 0
  1332.     text_width = self.contents.text_size(str).width
  1333.     dx = dx + @ori_contents_width - text_width - 34
  1334.     prefix = str[0]; str = str[1...str.length];
  1335.     rect = Rect.new(dx, dy, self.contents.text_size(prefix).width + 3, line_height)
  1336.     draw_text(rect, prefix)
  1337.     offset = rect.width + 24
  1338.     draw_icon($data_skills[info.data_id].icon_index, dx + rect.width, dy)
  1339.     rect.x += offset; rect.width = text_width;
  1340.     draw_text(rect, str)
  1341.   end
  1342.   #---------------------------------------------------------------------------
  1343.   def draw_info_name(dx, dy, str)
  1344.     change_color(system_color)
  1345.     draw_text(dx, dy, @ori_contents_width, line_height, str)
  1346.     change_color(normal_color)
  1347.   end
  1348.   #---------------------------------------------------------------------------
  1349.   def draw_info_diff(dx, dy, info)
  1350.     value = info.value
  1351.     is_percent = PercentageFeaure.include?(info.feature_id)
  1352.  
  1353.     dw = (@ori_contents_width + 54) / 2
  1354.     crect = Rect.new(dx, dy, dw, line_height)
  1355.     nrect = Rect.new(dx, dy, @ori_contents_width - 8, line_height)
  1356.     drx = dx + (@ori_contents_width + 54) / 2
  1357.     draw_diff_value(crect, value[1], is_percent) if @comparing
  1358.     draw_right_arrow(drx, dy)                    if @comparing
  1359.     delta = value[0] - value[1]
  1360.     delta *= -1 if InverseColorFeature.include?(info.feature_id)
  1361.     change_color(param_change_color(delta))
  1362.     draw_diff_value(nrect, value[0], is_percent)
  1363.     change_color(normal_color)
  1364.   end
  1365.   #---------------------------------------------------------------------------
  1366.   def draw_diff_value(rect, value, is_percent)
  1367.     str = value.to_s
  1368.     str = sprintf("%d\%", (value * 100).round(2).to_i) if is_percent
  1369.     draw_text(rect, str, 2)
  1370.   end
  1371.   #--------------------------------------------------------------------------
  1372.   def draw_background_colour(dx, dy)
  1373.     colour = Color.new(0, 0, 0, translucent_alpha/2)
  1374.     rect = Rect.new(dx+1, dy+1, @ori_contents_width - 2, line_height - 2)
  1375.     contents.fill_rect(rect, colour)
  1376.   end
  1377.   #--------------------------------------------------------------------------
  1378. #-#
  1379.   #---------------------------------------------------------------------------
  1380.   # * Compare the equipment set bonus
  1381.   #---------------------------------------------------------------------------
  1382. if $imported[:MA_EquipmentSetBonuses]
  1383.   #---------------------------------------------------------------------------
  1384.   # * Collect equipment set difference, current_only: collect currently
  1385.   #   activated equipment set.
  1386.   def collect_equipment_set_diff(current_only = false)
  1387.     return unless @actor
  1388.     before = @actor.maesb_sets || []
  1389.     feature_id = FeatureEquipSet
  1390.     return if current_only && before.size == 0
  1391.     btmp_item = @template_item ? @template_item.dup : nil
  1392.     @last_stage = current_only ? :current : :diff
  1393.     if current_only
  1394.       start_index = @base_pages.size
  1395.       bcmp_item = @compare_item ? @compare_item.dup : nil
  1396.       @template_item = Dummy
  1397.       before.each do |obj|
  1398.         @compare_item = obj
  1399.         @set_bonus_item = obj
  1400.         compare_diffs(:eqset)
  1401.       end
  1402.     else
  1403.       return unless @temp_actor
  1404.       after  = @temp_actor.maesb_sets || []
  1405.       bcmp_item = @compare_item ? @compare_item.dup : nil
  1406.       start_index = @pages.size
  1407.       @template_item = Dummy
  1408.       after.select{|obj| !before.include?(obj)}.each do |obj|
  1409.         @compare_item = obj
  1410.         @set_bonus_item = obj
  1411.         compare_diffs(:eqset)
  1412.       end
  1413.       @compare_item = Dummy
  1414.       before.select{|obj| !after.include?(obj)}.each do |obj|
  1415.         @pages << DummyInfo
  1416.         @template_item = obj
  1417.         @set_bonus_item = obj
  1418.         compare_diffs(:eqset)
  1419.       end
  1420.     end
  1421.     @last_stage = nil
  1422.     @set_bonus_item = nil
  1423.     @template_item = btmp_item
  1424.     @compare_item = bcmp_item
  1425.   end
  1426. end
  1427.   #---------------------------------------------------------------------------
  1428. #-#
  1429. end # class Window_EQ status
  1430. end # enable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement