O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

Sistema de Atualização de itens (+1 +2... +12)

Iniciado por mandary, 27/03/2015 às 11:54

27/03/2015 às 11:54 Última edição: 20/01/2017 às 09:22 por King Gerar
Bom galera, não sei se voces ja postaram esse sistema, mais estou fazendo minha parte em compartilha-lo. Eu pessoalmente amei esse sistema e o traduzi para facilita o acesso para ele, ate mesmo criei um mini-tutorial, para jovens RPG MAKER (iguais a mim  :ok: )
Bem vamos ao que interessa:
                                                                                                                 Basic Status
Compativel com: RMVXAce
Compatibilidade :Otima
Facilidade de uso: fácil
Lag gerado: nulo (até onde eu testei)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CREDITOS E AVISOS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Que os creditos de edição seja para o "Tsukihime" e ''Dekita'' e a mim por traduzir.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>FUNÇÃO DO SCRIPT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Atualizar os itens aumentando seus atributos.<<

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>IMAGEMS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Spoiler
[close]
Spoiler
[close]
Spoiler
[close]
Spoiler
[close]

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>DOWNLOAD<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Spoiler

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>SCRIPT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Ja esta no jogo, só copiar os 3.


:*-*:  :*-*: Era isso que eu estava procurando!!
Sei muito pouco inglês então muito obrigada por traduzir!

Citação de: Seika online 27/03/2015 às 17:23
:*-*:  :*-*: Era isso que eu estava procurando!!
Sei muito pouco inglês então muito obrigada por traduzir!


Que nada Seika, estamos aqui para ajuda.  :ok:

É um sistema muito bom, principalmente se misturado a outros sistemas que melhoram o equipamento.
Obrigado por compartilhar o/

que nada Alison, se souber de mais scripts, compartilharei com o forum.

18/11/2015 às 17:14 #5 Última edição: 18/11/2015 às 17:28 por mandary
Gente, gostaria de pedir a ajuda de vcs para modificar um bug nesse script. O bug nao permite retirar armadura ou arma do ''comando de eventos''. tem como modificar ou colocar algo que permita novamente retirar alguma arma, ou armadura pelo comando de eventos sem modificar a ação do script. gente por favor pelo menos uma resposta, tentei fala com o criador do script o Dekita mais ele nao respondeu. sera que alguem poderia ajuda?
Aqui ta o script.

Spoiler
module Dekita__Refine_Script
=begin =========================================================================
Dekita's                                                                   v0.9
                       ★ Perfect Equip Refine System™ ★

================================================================================
Script Information:
====================

NOTE :
This is still a work in progress, i plan on increasing effiency and customisation
options quite a lot, so if you have any ideas for improvements or a bug to report
please let me know.

NOTE 2 :
Tsukihime's Custom DataManager script can be used with this script to increase
compatability with other scripts. it is not required.

Refining is a method of enhancing your gear by adding bonus stats to it.
After each successful refine the refinement level of the equipment will
increase up to a maximum of +12(default).
Refining equipment adds any stat that you notetag the equipment with.
e.g if you notetagged a piece of equipment like so...
<ref_mhp>
<ref_atk>
<ref_def>
<ref_luk>
when you refined that equipment you would gain MaxHP, Atk, Def and Luk.
equal to the formula (explained below).

The only required items to refine a piece of equipment are "Mirage Celestones"
BUT there are also refinement aids that will increase your chances of
successful refinements.
You can select how many mirage celestones are required for each piece of
equipment by putting <req mir: X> in the equipment notebox.
where X is the value you need to refine that equipment item.

The higher the upgrade, the more difficult it becomes. Starting from level 1,
your success is not guaranteed. If you fail an upgrade, your item returns to
level 0 unless you use refinement aids which prevent loss (Explained later).

================================================================================
★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆
================================================================================
1. You must give credit to "Dekita"
2. You are NOT allowed to repost this script.(or modified versions)
3. You are NOT allowed to convert this script.(into other game engines e.g RGSS2)
4. You are NOT allowed to use this script for Commercial games.
5. ENJOY!

"FINE PRINT"
By using this script you hereby agree to the above terms and conditions,
if any violation of the above terms occurs "legal action" may be taken.
Not understanding the above terms and conditions does NOT mean that
they do not apply to you.
If you wish to discuss the terms and conditions in further detail you can
contact me at http://dekitarpg.wordpress.com/ or DekitaRPG@gmail.com

================================================================================
History:
=========
D /M /Y
08/12/2o12 - Finished,(v0.9)
20/09/2o12 - Started Script,

================================================================================
Credit and Thanks to :
=======================
Tsukihime - For the custom database script that makes this one more efficient,
             and various other help ^_^
             
================================================================================
Known Bugs:
============
You will not be able to use conditional branch checks for weapons and armors.
I am working on improving this.

If a new bug is found please contact me at
http://dekitarpg.wordpress.com/

================================================================================
INSTRUCTIONS:
==============
Place this script UNDER "▼ Materials" and ABOVE "▼ Main" in your script editor.

================================================================================
=end                     #######################
                         # CUSTOMISATION BEGIN #
                         #######################
 
# VOCAB:
Select_Equip = "Selecionar o equipamento"
S_E_Help_Info = "Selecione o equipamento para atualizar."

Select_Item = "Selecionar a pedra"
S_I_Help_Info = "Escolha a pedra de força."

Start_Refine = "Atualização"
S_R_Help_Info = "Começe o processo de atualização."

S_R_Success = "Sucesso !"
S_R_Fail = "Falhou !"
S_R_Total_Fail = "Seu equipamento nao aguentou !"
S_R_Single_Fail = "Nivel do equipamiento caiu 1."
S_R_NO_Fail = "Equipamento de atualização inalterada."


# for selected equipment info box.
Refine_Symbol =  " +"
# for equip screen.
Refine_Symbols = "+%2d"

Grade_Symbol = "Grade: "


# Notetag for equipments mirage requirement
Mirage_Celestone_Req_Note = /<req mir: (.*)>/i

# Notetags for equipment's stats to increase upon refine
Refine_MHP_Notetag = /<ref_mhp>/i
Refine_MMP_Notetag = /<ref_mmp>/i
Refine_Atk_Notetag = /<ref_atk>/i
Refine_Def_Notetag = /<ref_def>/i
Refine_Mat_Notetag = /<ref_mat>/i
Refine_Mdf_Notetag = /<ref_mdf>/i
Refine_Agi_Notetag = /<ref_agi>/i
Refine_Luk_Notetag = /<ref_luk>/i

# The level of refinement determines the multiple of the base refinement
# bonus you will receive.
# The base refinement value is determined by the equipment grade

# <grade: X>   X = value .
# e.g <grade: 5>
Equipment_Grade_Notetag = /<grade: (.*)>/i

# The refinement bonuses are as follows: (default settings)
##################################################################
# REFINE LV #  BONUS VALUE    #=|=# REFINE LV #  BONUS VALUE     #
#    +1     #  Grade * 1      #=|=#    +7     #  Grade * 9.95    #
#    +2     #  Grade * 2      #=|=#    +8     #  Grade * 13      #
#    +3     #  Grade * 3.05   #=|=#    +9     #  Grade * 17.05   #
#    +4     #  Grade * 4.3    #=|=#    +10    #  Grade * 22.03   #
#    +5     #  Grade * 5.75   #=|=#    +11    #  Grade * 29      #
#    +6     #  Grade * 7.55   #=|=#    +12      #  Grade * 37.5    #
##################################################################
# Refine Lvl    =  Bonus Multiplier
Plus_1_Ref_Val  = 1.0
Plus_2_Ref_Val  = 2.0
Plus_3_Ref_Val  = 3.05
Plus_4_Ref_Val  = 4.3
Plus_5_Ref_Val  = 5.75
Plus_6_Ref_Val  = 7.55
Plus_7_Ref_Val  = 9.95
Plus_8_Ref_Val  = 13.0
Plus_9_Ref_Val  = 17.05
Plus_10_Ref_Val = 22.03
Plus_11_Ref_Val = 29.0
Plus_12_Ref_Val = 37.5

# The basic chances of refining success are as follows: (default settings)
##############################################################################
# Refine Level # Mirage Only # Tienkang Stone # Tisha Stone # Chienkun Stone #
#     +1       #      50%    #        65%     #       53.5%   #      100%      #
#     +2       #      30%    #        45%       #     33.5%     #      25%       #
#     +3       #      30%    #         45%       #     33.5%     #      10%       #
#     +4       #      30%    #         45%       #     33.5%     #      4%        #
#     +5       #      30%    #         45%       #     33.5%     #      1.67%     #
#     +6       #      30%    #         45%       #     33.5%     #      0.77%     #
#     +7       #      30%    #         45%       #     33.5%     #      0.47%     #
#     +8       #      30%    #         45%       #     33.5%     #      0.25%     #
#     +9       #      25%    #         40%       #     28.5%     #      0.13%     #
#     +10      #      20%    #         35%       #     23.5%     #      0.07%     #
#     +11      #      12%    #         27%       #     15.5%     #      0.04%     #
#     +12      #      5%     #         20%     #     8.5%     #      0.02%     #
##############################################################################
# There is also "dragon orbs" that give you 100% success rate (explained later)


# Mirage Celestone ONLY
# If refining fails, the item loses all previous refining and reverts back to +0.

# If you want mirages to show in the refine aid list give it this notetag.
Mirage_Celestone_Note = /<mirage>/i

# Database ID for Mirage Celestones
Mirage_Celestone_ID = 1

# Success Rate's
Plus_1_Mir_Val  = 0.50
Plus_2_Mir_Val  = 0.30
Plus_3_Mir_Val  = 0.30
Plus_4_Mir_Val  = 0.30
Plus_5_Mir_Val  = 0.30
Plus_6_Mir_Val  = 0.30
Plus_7_Mir_Val  = 0.30
Plus_8_Mir_Val  = 0.30
Plus_9_Mir_Val  = 0.25
Plus_10_Mir_Val = 0.20
Plus_11_Mir_Val = 0.12
Plus_12_Mir_Val = 0.05


# Mirage Celestone AND Teinkang Stones 
# Teinkang Stones boost the chances of success.
# If refining fails, the item loses all previous refining and reverts back to +0.

# Notetag for tienkang stones
Tienkang_Stone_Note = /<tienkang>/i

# Success Rate's
Plus_1_Tein_Val  = 0.65
Plus_2_Tein_Val  = 0.45
Plus_3_Tein_Val  = 0.45
Plus_4_Tein_Val  = 0.45
Plus_5_Tein_Val  = 0.45
Plus_6_Tein_Val  = 0.45
Plus_7_Tein_Val  = 0.45
Plus_8_Tein_Val  = 0.45
Plus_9_Tein_Val  = 0.40
Plus_10_Tein_Val = 0.35
Plus_11_Tein_Val = 0.27
Plus_12_Tein_Val = 0.20


# Mirage Celestone AND Tisha Stones
# Tisha Stones boost the chance of success AND prevent the item from
# dropping more than 1 refining level if refining fails.

# Notetag for tisha stones
Tisha_Stone_Note = /<tisha>/i

# Success Rate's
Plus_1_Tish_Val  = 0.535
Plus_2_Tish_Val  = 0.335
Plus_3_Tish_Val  = 0.335
Plus_4_Tish_Val  = 0.335
Plus_5_Tish_Val  = 0.335
Plus_6_Tish_Val  = 0.335
Plus_7_Tish_Val  = 0.335
Plus_8_Tish_Val  = 0.335
Plus_9_Tish_Val  = 0.285
Plus_10_Tish_Val = 0.235
Plus_11_Tish_Val = 0.155
Plus_12_Tish_Val = 0.085

# Mirage Celestone AND Chienkun Stones 
# Chienkun Stones LOWER the chance of success (except refine to lv 1)
# AND prevent the item from dropping ANY level at all with failure.

# Notetag for Chienkun stones
Chienkun_Stone_Note = /<chienkun>/i

# Success Rate's
Plus_1_CKun_Val  = 1.00 # 1.00 = 100% success
Plus_2_CKun_Val  = 0.25
Plus_3_CKun_Val  = 0.10
Plus_4_CKun_Val  = 0.04
Plus_5_CKun_Val  = 0.0167
Plus_6_CKun_Val  = 0.0077
Plus_7_CKun_Val  = 0.0047
Plus_8_CKun_Val  = 0.0025
Plus_9_CKun_Val  = 0.0013
Plus_10_CKun_Val = 0.0007
Plus_11_CKun_Val = 0.0004
Plus_12_CKun_Val = 0.0002


# Mirage Celestone AND Dragon Orb
# Dragon Orbs Guarantee successfull refine as long as the equipments current
# refine level is lower than the dragon orb level.

# <dorb: X>
# replace X with a value between 1 - 12
Dragon_Orb_Note = /<dorb: (.*)>/i

# NOTE: you cannot set this higher than 12, only lower(if you want).
Max_Refine = 12 
   
Wait_Time = 60
end # Dekita__Refine_Script
                           #####################
                           # CUSTOMISATION END #
                           #####################
#===============================================================================#
# ARE YOU MODIFYING BEYOND THIS POINT? \.\.                                     #
# YES?\.\.                                                                      #
# OMG, REALLY?                                                                  #
# WELL SLAP MY FACE AND CALL ME A DRAGON.\..\..                                 #
# I REALLY DIDN'T THINK YOU HAD IT IN YOU.\..\..                                #
#===============================================================================#
module Dekita__Refine_Script

COMMANDS =[
  [:sel_eqp, "Equipamentos"],
  [:sel_itm, "Pedras"],
  [:ref_str, "Atualizar"],
#  [:exit,   "Quit Scene"],
]#DO NOT REMOVE

Refine_Info =[ # // Dont Delete This.
  [:refine_equip, "Equipamento escolhido:"],   
  [:blank, " "],
  [:blank, " "],
  [:blank, " "],
  [:refine_aid,  "Pedra de atualização:"],     
  [:blank, " "],
  [:mirage_cost,  "Custo exigido:"],
] # Do not remove this.

  Item_Refine_Info =[ # // Dont Delete This.
  [:blank, " "],
  [:blank, " "],
  [:blank, " "],
  [:blank, " "],
  [:blank, " "],
  [:blank, " "],
  [:blank, " "],
] # Do not remove this.
 
end # module

$imported = {} if $imported.nil?
$imported["DPB-WCB"] = true

#==============================================================================
class Object
#==============================================================================

def dup!
  Marshal.load(Marshal.dump(self))
end

end

#==============================================================================
module DataManager
#==============================================================================
if !$imported["Tsuki_CustomDataManager"]

def self.save_game_without_rescue(index)
  File.open(make_filename(index), "wb") do |file|
    $game_system.on_before_save
    Marshal.dump(make_save_header, file)
    Marshal.dump(make_save_contents, file)
    Marshal.dump($data_weapons, file)
    Marshal.dump($data_armors, file)
    @last_savefile_index = index
  end
  return true
end

def self.load_game_without_rescue(index)
  File.open(make_filename(index), "rb") do |file|
    Marshal.load(file)
    extract_save_contents(Marshal.load(file))
    $data_weapons = Marshal.load(file)
    $data_armors = Marshal.load(file)
    reload_map_if_updated
    @last_savefile_index = index
  end
  return true
end

end # if $imported["Tsuki_CustomDataManager"]

 
class <<self; alias load_database_refine_level load_database; end
def self.load_database
  load_database_refine_level
  load_notetags_refine_level
end
 
def self.load_notetags_refine_level
  groups = [$data_weapons, $data_armors, $data_items]
  for group in groups
    for obj in group
      next if obj.nil?
      obj.load_notetags_refine_level
    end
  end
end
 
end # DataManager

#==============================================================================
module Dekita_Refine_Script
#==============================================================================

def self.copy_weapon(from_item)
  new_item = from_item.dup!
  make_new_copy(new_item, from_item)
  id = self.gain_weapon_id($data_weapons)
  if id.nil?
    new_item.id = $data_weapons.size
    $custom_weapons.push(new_item) if $imported["Tsuki_CustomDataManager"]
    $data_weapons.push(new_item)
    print "new weapon id #{new_item.id}\n"
    print "weapon array size #{$data_weapons.size}\n"
    print "Custom weapon array size #{$custom_weapons.size}\n" if $imported["Tsuki_CustomDataManager"]
  else
   new_item.id = id
   $data_weapons[id] = new_item   
  end
return new_item
end

def self.copy_armor(from_item)
  new_item = from_item.dup!
  make_new_copy(new_item, from_item)
  id = self.gain_armor_id($data_armors)
  if id.nil?
    new_item.id = $data_armors.size
    $custom_armors.push(new_item) if $imported["Tsuki_CustomDataManager"]
    $data_armors.push(new_item)
    print "new armor id #{new_item.id}\n"
    print "armor array size #{$data_armors.size}\n"
    print "Custom armor array size #{$custom_armors.size}\n" if $imported["Tsuki_CustomDataManager"]
  else
    new_item.id = id
    $data_armors[id] = new_item   
  end
  return new_item
end

def self.gain_weapon_id(database)
  id = 1
  for i in 1...database.size
    weapon = database
    if weapon.nil?
      print id
      return id
    end
    id += 1
  end
  return nil
end

def self.gain_armor_id(database)
  id = 1
  for i in 1...database.size
    armor = database
    if armor.nil?
      print id
      return id
    end
    id += 1
  end
  return nil
end

def self.make_new_copy(new_item, from_item)
  new_item.params = from_item.params.dup! 
  new_item.features = from_item.features.dup!
  new_item.xparams = from_item.xparams.dup! if $imported["DPB-PSPDS"]
  new_item.sparams = from_item.sparams.dup! if $imported["DPB-PSPDS"] 
  new_item.dpbzparams = from_item.dpbzparams.dup! if $imported["DPB-PSPDS"]
  new_item.dpbzformulazS = from_item.dpbzformulazS.dup! if $imported["DPB-ATLANDDFL"]
  new_item.pwistyles = from_item.pwistyles.dup! if $imported["DPB-SoulForce"]
end

end # module

#==============================================================================
class RPG::Item < RPG::UsableItem
#==============================================================================
include Dekita__Refine_Script

attr_accessor :mirage_celestone
attr_accessor :tienkang_stone
attr_accessor :tisha_stone
attr_accessor :chienkun_stone
attr_accessor :dragon_orb
attr_accessor :refine_item
attr_accessor :dpbz_epik_refinez_id_fs_Fs_Fs_fs

def load_notetags_refine_level
  @refine_item = false
  @mirage_celestone = false
  @tienkang_stone = false
  @tisha_stone = false
  @chienkun_stone = false
  @dragon_orb = 0
  @dpbz_epik_refinez_id_fs_Fs_Fs_fs = nil
  self.note.split(/[\r\n]+/).each { |line|
  case line
  when Mirage_Celestone_Note
  @mirage_celestone = true
  @refine_item = true
  when Tienkang_Stone_Note
  @tienkang_stone = true
  @refine_item = true
  when Tisha_Stone_Note
  @tisha_stone = true
  @refine_item = true
  when Chienkun_Stone_Note
  @chienkun_stone = true
  @refine_item = true
  when Dragon_Orb_Note
  @dragon_orb = $1.to_i
  @refine_item = true
  end
  } # self.note.split
end 


end # RPG::Item < RPG::UsableItem

#==============================================================================
class RPG::EquipItem < RPG::BaseItem
#==============================================================================
include Dekita__Refine_Script

attr_accessor :mirage_celestone_req
attr_accessor :refine_mhp
attr_accessor :refine_mmp
attr_accessor :refine_atk
attr_accessor :refine_def
attr_accessor :refine_mat
attr_accessor :refine_mdf
attr_accessor :refine_agi
attr_accessor :refine_luk
attr_accessor :refine_level
attr_accessor :equipment_grade
attr_accessor :times_modified

def load_notetags_refine_level
  @mirage_celestone_req = 0
  @equipment_grade = 0
  @times_modified = 0 
  @refine_level = 0
  @refine_mhp = false
  @refine_mmp = false
  @refine_atk = false
  @refine_def = false
  @refine_mat = false
  @refine_mdf = false
  @refine_agi = false
  @refine_luk = false
  @refine_eva = false
  self.note.split(/[\r\n]+/).each { |line|
  case line
  when Mirage_Celestone_Req_Note
  @mirage_celestone_req = $1.to_i
  when Equipment_Grade_Notetag
  @equipment_grade = $1.to_i
  when Refine_MHP_Notetag
  @refine_mhp = true
  when Refine_MMP_Notetag
  @refine_mmp = true
  when Refine_Atk_Notetag
  @refine_atk = true
  when Refine_Def_Notetag
  @refine_def = true
  when Refine_Mat_Notetag
  @refine_mat = true
  when Refine_Mdf_Notetag
  @refine_mdf = true
  when Refine_Agi_Notetag
  @refine_agi = true
  when Refine_Luk_Notetag
  @refine_luk = true
  end
  } # self.note.split
end 

def max_refine
  return Max_Refine
end

def refine_level_up(item)
  @refine_level += 1
end

def refine_level_down(item)
  health_loss(item) if item.refine_mhp
  mana_loss(item) if item.refine_mmp
  attack_loss(item) if item.refine_atk
  defence_loss(item) if item.refine_def
  magic_loss(item) if item.refine_mat
  magic_def_loss(item) if item.refine_mdf
  agility_loss(item) if item.refine_agi
  luck_loss(item) if item.refine_luk
  item.refine_level -= 1
end

def refine_fail(item)
  health_fail(item) if item.refine_mhp
  mana_fail(item) if item.refine_mmp
  attack_fail(item) if item.refine_atk
  defence_fail(item) if item.refine_def
  magic_fail(item) if item.refine_mat
  magic_def_fail(item) if item.refine_mdf
  agility_fail(item) if item.refine_agi
  luck_fail(item) if item.refine_luk
  @refine_level = 0
end

def determine_refine_bonus(item)
  return if item.refine_level == item.max_refine
  health_refine(item) if item.refine_mhp
  mana_refine(item) if item.refine_mmp
  attack_refine(item) if item.refine_atk
  defence_refine(item) if item.refine_def
  magic_refine(item) if item.refine_mat
  magic_def_refine(item) if item.refine_mdf
  agility_refine(item) if item.refine_agi
  luck_refine(item) if item.refine_luk
  refine_level_up(item)   
end

def health_refine(item)
  if @refine_level == 0
  item.params[0] += (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 1
  item.params[0] += (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 2
  item.params[0] += (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[0] += (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[0] += (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[0] += (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[0] += (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[0] += (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[0] += (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[0] += (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[0] += (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[0] += (item.equipment_grade * Plus_12_Ref_Val - (item.equipment_grade)).to_i
  end
end

def health_loss(item)
  if @refine_level == 0
  elsif @refine_level == 1
  item.params[0] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 2
  item.params[0] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[0] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[0] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[0] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[0] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[0] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[0] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[0] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[0] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[0] -= (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  end
end

def health_fail(item)
  index = 0
  if @refine_level == 0
  elsif @refine_level == 1
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 2
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  end
end

def mana_refine(item)
  if @refine_level == 0
  item.params[1] += (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 1
  item.params[1] += (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 2
  item.params[1] += (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[1] += (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[1] += (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[1] += (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[1] += (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[1] += (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[1] += (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[1] += (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[1] += (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[1] += (item.equipment_grade * Plus_12_Ref_Val - (item.equipment_grade)).to_i
  end
end

def mana_loss(item)
  if @refine_level == 0
  elsif @refine_level == 1
  item.params[1] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 2
  item.params[1] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[1] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[1] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[1] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[1] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[1] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[1] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[1] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[1] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[1] -= (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  end
end

def mana_fail(item)
  index = 1
  if item.refine_level == 0
  elsif item.refine_level == 1
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif item.refine_level == 2
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif item.refine_level == 3
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif item.refine_level == 4
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif item.refine_level == 5
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif item.refine_level == 6
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif item.refine_level == 7
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  end
end

def attack_refine(item)
  if @refine_level == 0
  item.params[2] += item.equipment_grade * Plus_1_Ref_Val
  elsif @refine_level == 1
  item.params[2] += (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 2
  item.params[2] += (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[2] += (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[2] += (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[2] += (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[2] += (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[2] += (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[2] += (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[2] += (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[2] += (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[2] += (item.equipment_grade * Plus_12_Ref_Val - (item.equipment_grade)).to_i
  end
end

def attack_loss(item)
  if @refine_level == 0
  elsif @refine_level == 1
  item.params[2] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 2
  item.params[2] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[2] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[2] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[2] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[2] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[2] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[2] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[2] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[2] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[2] -= (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  end
end

def attack_fail(item)
  index = 2
  if @refine_level == 0
  elsif @refine_level == 1
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 2
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  end
end

def defence_refine(item)
  if @refine_level == 0
  item.params[3] += item.equipment_grade * Plus_1_Ref_Val
  elsif @refine_level == 1
  item.params[3] += (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 2
  item.params[3] += (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[3] += (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[3] += (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[3] += (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[3] += (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[3] += (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[3] += (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[3] += (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[3] += (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[3] += (item.equipment_grade * Plus_12_Ref_Val - (item.equipment_grade)).to_i
  end
end

def defence_loss(item)
  if @refine_level == 0
  elsif @refine_level == 1
  item.params[3] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 2
  item.params[3] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[3] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[3] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[3] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[3] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[3] -= (item.equipment_grade * Plus_7_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 8
  item.params[3] -= (item.equipment_grade * Plus_8_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 9
  item.params[3] -= (item.equipment_grade * Plus_9_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 10
  item.params[3] -= (item.equipment_grade * Plus_10_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 11
  item.params[3] -= (item.equipment_grade * Plus_11_Ref_Val - (item.equipment_grade)).to_i
  end
end

def defence_fail(item)
  index = 3
  if @refine_level == 0
  elsif @refine_level == 1
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  elsif @refine_level == 2
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 3
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 4
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 5
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 6
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipment_grade)).to_i
  elsif @refine_level == 7
  item.params[index] -= (item.equipment_grade * Plus_1_Ref_Val).to_i
  item.params[index] -= (item.equipment_grade * Plus_2_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_3_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_4_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_5_Ref_Val - (item.equipment_grade)).to_i
  item.params[index] -= (item.equipment_grade * Plus_6_Ref_Val - (item.equipme
[close]