Advertisement
blackmorning

Blackmorning - Ace Actor Alignment

Nov 4th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.84 KB | None | 0 0
  1. #===============================================================================
  2. # ** Blackmorning -> Actor Alignment
  3. # -----------------------------------------------------------------------------
  4. #  Blackmorning
  5. #  Version 1.03
  6. #  released 01/29/2014
  7. #  updated 07/04/2015
  8. #-better showing of alignment
  9. #==============================================================================
  10. #  - INTRODUCTION -
  11. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  12. # - assign your actors an "alignment" between good and evil or however you
  13. #   choose to define it.
  14. # - set an initial alignment
  15. # - add or subtract from alignment through script calls
  16. # - assign alignment to variables for events
  17. #===============================================================================
  18. # Instructions
  19. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. # To install this script, open up your script editor and copy/paste this script
  21. # to an open slot below BM - Base but above ? Main. Remember to save.
  22. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. # Actor's Notetage
  24. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  25. # To set an actor's initial alignment, enter:
  26. #       <INI_ALIGN: number>
  27. #   into the actor's notebox (all actors are neutral alignment by default).
  28. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  29. # Message Codes
  30. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  31. # \nal[x]    - Writes out alignment x's name.
  32. # \aal[x]    - Write name of the alignment for actor x.
  33. # \pal       - Write name of the alignment for party.
  34. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  35. # Event Script Calls
  36. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  37. # - to add or subtract actor alignment points, use script call:
  38. #       change_actor_alignment(actor_id, amount)
  39. # - to add or subtract party alignment points, use script call:
  40. #       change_party_alignment(amount)
  41. # - to assign party alignment (average actor alignment) to a variable,
  42. #   use script call:
  43. #       check_party_alignment(var_id)
  44. # - to temporarily assign actor alignment to a variable,
  45. #   use script call:
  46. #       check_actor_alignment(actor, var_id)
  47. # - to temporarily assign actor alignment name to a variable,
  48. #   use script call:
  49. #       check_actor_alignment_name(actor, var_id)
  50. # - to temporarily assign party alignment name to a variable,
  51. #   use script call:
  52. #       check_actor_alignment_name(var_id)
  53. #===============================================================================
  54. module BM
  55.   module ALIGN
  56.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  57.     # Alignment Customization
  58.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  59.     MAX = 100  # Change the upper of the bar.
  60.     # For example, if you set this to 100, the lowest alignment will be 0 and
  61.     # the maximum will be 100.
  62.     LIST = {
  63.       #id => ["name", text color],
  64.       0 => ["Demonic", 18],
  65.       1 => ["Evil",    10],
  66.       2 => ["Bad",      2],
  67.       3 => ["Neutral",  8],
  68.       4 => ["Good",    14],
  69.       5 => ["Saintly",  6],
  70.       6 => ["Divine",   0],
  71.     } # Do Not Remove
  72.     # The end slots of the array define what the alignment is if it exceeds your
  73.     # set maximum or minimum value.
  74.     # What this means is that your actor will not become, for example, "Divine"
  75.     # or "Pure Evil" unless his alignment goes above 200, if your MAX = 200, or
  76.     # dips below 0.
  77.     # Add as many alignments as you like as long as there are an odd number.
  78.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  79.     # Visual Options
  80.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  81.     FONT_SIZE = 16
  82.     SHOW_ON_MENU = true # shows alignment gauge on main menu
  83.     SHOW_ON_FACE = true # shows alignment gauge on faces in status, skill, etc
  84.     SHOW_NUMBER = true  # shows numerical value of alignment on gauge
  85.     SHOW_NAME = true    # shows alignment name on gauge
  86.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  87.     # Alignment Calculations
  88.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  89.     PARTY_INCLUDE_RESERVE = false
  90.     # if true, party alignment includes all members,
  91.     # if false, only includes battle members
  92.   end
  93. end
  94. #===============================================================================
  95. # Editting anything past this point may potentially result in causing computer
  96. # damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
  97. # Therefore, edit at your own risk.
  98. #===============================================================================
  99. module BM
  100.   def self.required(name, req, version, type = nil)
  101.     if !$imported[:bm_base]
  102.       msg = "The script '%s' requires the script\n"
  103.       msg += "'BM - Base' v%s or higher above it to work properly\n"
  104.       msg += "Go to bmscripts.weebly.com to download this script."
  105.       msgbox(sprintf(msg, self.script_name(name), version))
  106.       exit
  107.     else
  108.       self.required_script(name, req, version, type)
  109.     end
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * script_name
  113.   #   Get the script name base on the imported value
  114.   #--------------------------------------------------------------------------
  115.   def self.script_name(name, ext = "BM")
  116.     name = name.to_s.gsub("_", " ").upcase.split
  117.     name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
  118.     name.join(" ")
  119.   end
  120. end
  121. $imported ||= {}
  122. $imported[:bm_align] = 1.03
  123. BM.required(:bm_align, :bm_base, 1.00, :above)
  124. #==============================================================================
  125. module BM
  126.   module REGEXP
  127.     module ACTOR
  128.       INITIAL_ALIGN = /<(?:initial align|INI_ALIGN):[ ](\d+)>/i
  129.       MAX_ALIGN = /<(?:max align|MAX_ALIGN):[ ](\d+)>/i
  130.       MIN_ALIGN = /<(?:min align|MIN_ALIGN):[ ](\d+)>/i
  131.     end
  132.   end
  133. end
  134. #==============================================================================
  135. # ** Vocab
  136. #==============================================================================
  137. module Vocab
  138.   def self.alignment(id)
  139.     return "" unless BM::ALIGN::LIST.include?(id)
  140.     return BM::ALIGN::LIST[id][0]
  141.   end
  142. end
  143. #==============================================================================
  144. # ** DataManager
  145. #==============================================================================
  146. module DataManager  
  147.   #--------------------------------------------------------------------------
  148.   # * Alias: load_database
  149.   #--------------------------------------------------------------------------
  150.   class << self; alias :bm_align_ld :load_database; end
  151.   def self.load_database
  152.     bm_align_ld
  153.     load_notetags_bm_align
  154.   end  
  155.   #--------------------------------------------------------------------------
  156.   # * New Method: load_notetags_bm_align
  157.   #--------------------------------------------------------------------------
  158.   def self.load_notetags_bm_align
  159.     groups = [$data_actors]
  160.     for group in groups
  161.       for obj in group
  162.         next if obj.nil?
  163.         obj.load_notetags_bm_align
  164.       end
  165.     end
  166.   end
  167. end
  168. #==============================================================================
  169. # ** RPG::Actor
  170. #==============================================================================
  171. class RPG::Actor < RPG::BaseItem
  172.   #--------------------------------------------------------------------------
  173.   # * Public Instance Variables
  174.   #--------------------------------------------------------------------------
  175.   attr_accessor :align
  176.   attr_accessor :align_max
  177.   attr_accessor :align_min
  178.   #--------------------------------------------------------------------------
  179.   # * Cache: load_notetags_bm_align
  180.   #--------------------------------------------------------------------------
  181.   def load_notetags_bm_align
  182.     @align = (BM::ALIGN::MAX/2).to_i
  183.     @align_max = BM::ALIGN::MAX
  184.     @align_min = 0
  185.     self.note.split(/[\r\n]+/).each { |line|
  186.       case line
  187.       #---
  188.       when BM::REGEXP::ACTOR::INITIAL_ALIGN
  189.         @align = $1.to_i
  190.       when BM::REGEXP::ACTOR::MAX_ALIGN
  191.         @align_max = $1.to_i
  192.       when BM::REGEXP::ACTOR::MIN_ALIGN
  193.         @align_min = $1.to_i
  194.       #---
  195.       end
  196.     } # self.note.split
  197.   end
  198. end
  199. #==============================================================================
  200. # ** Game_Actor
  201. #==============================================================================
  202. class Game_Actor < Game_Battler
  203.   #--------------------------------------------------------------------------
  204.   # * Public Instance Variables
  205.   #--------------------------------------------------------------------------
  206.   attr_accessor :align
  207.   attr_accessor :align_id
  208.   attr_accessor :align_name
  209.   #--------------------------------------------------------------------------
  210.   # Alias: Setup
  211.   #--------------------------------------------------------------------------
  212.   alias :bm_align_setup :setup
  213.   def setup(actor_id)
  214.     bm_align_setup(actor_id)
  215.     init_align
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # * New Method: init_align
  219.   #--------------------------------------------------------------------------
  220.   def init_align
  221.     @align = actor.align
  222.     @align_max = actor.align_max
  223.     @align_min = actor.align_min
  224.   end
  225.   #--------------------------------------------------------------------------
  226.   # New Method: align id
  227.   #--------------------------------------------------------------------------
  228.   def align_id
  229.     increment = BM::ALIGN::MAX/(BM::ALIGN::LIST.size-1)
  230.     for i in 0..BM::ALIGN::LIST.size-1
  231.       if @align < (increment * 0.5  + increment * i).to_i
  232.         return @align_id = i
  233.       else
  234.         @align_id = i
  235.       end
  236.     end
  237.     return @align_id
  238.   end  
  239.   #--------------------------------------------------------------------------
  240.   # New Method: align rate
  241.   #--------------------------------------------------------------------------
  242.   def align_rate
  243.     align = [[@align, @align_max].min, @align_min].max
  244.     align.to_f / @align_max
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # New Method: align name
  248.   #--------------------------------------------------------------------------
  249.   def align_name; @align_name = Vocab.alignment(@align_id);  end
  250. end
  251.  
  252. #==============================================================================
  253. # ** Window_Base
  254. #==============================================================================
  255. class Window_Base < Window
  256.   #--------------------------------------------------------------------------
  257.   # * Alias: convert_escape_characters
  258.   #--------------------------------------------------------------------------
  259.   alias :bm_align_cec :convert_escape_characters
  260.   def convert_escape_characters(text)
  261.     result = bm_align_cec(text)
  262.     result = convert_bm_align_characters(result)    
  263.     return result
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   def convert_bm_align_characters(result)
  267.     result.gsub!(/\eNAL\[(\d+)\]/i)  { Vocab.alignment($1.to_i) rescue "" }
  268.     result.gsub!(/\eAAL\[([-+]?\d+)\]/i) {  escape_actor_alignment($1.to_i) }
  269.     result.gsub!(/\ePAL/i)           { escape_party_alignment }
  270.     return result
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # new method: escape_actor_alignment
  274.   #--------------------------------------------------------------------------
  275.   def escape_actor_alignment(actor_id)
  276.     actor_id = $game_party.members[actor_id.abs].id if actor_id <= 0
  277.     actor = $game_actors[actor_id]
  278.     return "" if actor.nil?
  279.     return Vocab.alignment(actor.align_id)
  280.     return actor.align_name
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # * New Method: check party alignment
  284.   #--------------------------------------------------------------------------
  285.   def check_party_alignment
  286.     total = 0
  287.     members = $game_party.battle_members
  288.     members = $game_party.members if BM::ALIGN::PARTY_INCLUDE_RESERVE
  289.     for actor in members
  290.       total += actor.align
  291.     end
  292.     return total/members.size
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # new method: escape_party_alignment
  296.   #--------------------------------------------------------------------------
  297.   def escape_party_alignment
  298.     align = check_party_alignment
  299.     increment = BM::ALIGN::MAX/(BM::ALIGN::LIST.size-1)
  300.     for i in 0..BM::ALIGN::LIST.size-1
  301.       if align < (increment * 0.5  + increment * i).to_i
  302.         align_id = i
  303.         return Vocab.alignment(align_id)
  304.       else
  305.         align_id = i
  306.       end
  307.     end
  308.     return Vocab.alignment(align_id)
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # New Method: Draw Actor Align with gauge
  312.   #--------------------------------------------------------------------------
  313.   def draw_actor_align_gauge(actor, x, y, width = 96)
  314.     contents.font.size = BM::ALIGN::FONT_SIZE
  315.     fill_w = width * actor.align_rate
  316.     draw_gauge(x, y, width, actor.align_rate, align_color1, align_color(actor))
  317.     iw = width/(BM::ALIGN::LIST.size-1)
  318.     size = (BM::ALIGN::LIST.size-1)/2
  319.     cx = x + width/2
  320.     for i in 0..size
  321.       contents.fill_rect(cx + i*iw, y + 14, 1, 10, align_color1)
  322.       contents.fill_rect(cx - i*iw, y + 14, 1, 10, align_color1)
  323.     end
  324.     contents.font.color = align_color(actor)
  325.     draw_text(x, y + 14, width, line_height, actor.align_name, 1) if BM::ALIGN::SHOW_NAME
  326.     draw_text(x, y, width, line_height, actor.align, 1) if BM::ALIGN::SHOW_NUMBER
  327.     reset_font_settings
  328.   end  
  329.   #--------------------------------------------------------------------------
  330.   # * Alias: Draw Actor Face Graphic
  331.   #--------------------------------------------------------------------------
  332.   alias :bm_align_daf :draw_actor_face
  333.   def draw_actor_face(actor, x, y, *args)
  334.     bm_align_daf(actor, x, y, *args)
  335.     return unless BM::ALIGN::SHOW_ON_FACE
  336.     draw_actor_align_gauge(actor, x, y)
  337.   end
  338.   #--------------------------------------------------------------------------
  339.   # New Method: alignment colors
  340.   #--------------------------------------------------------------------------
  341.   def align_color1; text_color(8); end
  342.   def align_color(actor); text_color(BM::ALIGN::LIST[actor.align_id][1]); end
  343. end
  344. #=============================================================================#
  345. # ** Window_MenuStatus
  346. #=============================================================================#
  347. class Window_MenuStatus < Window_Selectable
  348.   #--------------------------------------------------------------------------
  349.   # * Alias: Draw Actor Face Graphic
  350.   #--------------------------------------------------------------------------
  351.   alias :bm_align_daag :draw_actor_align_gauge
  352.   def draw_actor_align_gauge(actor, x, y, width = 90)
  353.     width = item_width-4 if $imported[:bm_menustatus] && BM::MENU::ACTOR_OPTIONS[:style] == 0
  354.     bm_align_daag(actor, x, y, width)
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # * Alias: Draw Actor Face Graphic
  358.   #--------------------------------------------------------------------------
  359.   def draw_actor_face(actor, x, y, *args)
  360.     bm_align_daf(actor, x, y, *args)
  361.     return unless BM::ALIGN::SHOW_ON_MENU
  362.     return if $imported[:bm_menustatus] && BM::MENU::ACTOR_OPTIONS[:style] == 0
  363.     draw_actor_align_gauge(actor, x, y)
  364.   end
  365. end
  366. #==============================================================================#
  367. # ** Game_Interpreter
  368. #==============================================================================#
  369. class Game_Interpreter
  370.   #--------------------------------------------------------------------------
  371.   # * New Method: change alignment
  372.   #--------------------------------------------------------------------------
  373.   def change_actor_alignment(actor_id, amount)
  374.     actor_id = $game_party.members[actor_id.abs].id if actor_id <= 0
  375.     actor = $game_actors[actor_id]
  376.     return 0 if actor.nil?
  377.     actor.align += amount
  378.   end
  379.   #--------------------------------------------------------------------------
  380.   # * New Method: change party alignment
  381.   #--------------------------------------------------------------------------
  382.   def change_party_alignment(amount)
  383.     members = $game_party.battle_members
  384.     members = $game_party.members if BM::ALIGN::PARTY_INCLUDE_RESERVE
  385.     for actor in members
  386.       actor.align += amount
  387.     end
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # * New Method: check party alignment
  391.   #--------------------------------------------------------------------------
  392.   def check_party_alignment(var_id)
  393.     total = 0
  394.     members = $game_party.battle_members
  395.     members = $game_party.members if BM::ALIGN::PARTY_INCLUDE_RESERVE
  396.     for actor in members
  397.       total += actor.align
  398.     end
  399.     return $game_variables[var_id] = total/members.size
  400.   end
  401.   #--------------------------------------------------------------------------
  402.   # * New Method: check actor alignment
  403.   #--------------------------------------------------------------------------
  404.   def check_actor_alignment(actor_id, var_id)
  405.     actor_id = $game_party.members[actor_id.abs].id if actor_id <= 0
  406.     actor = $game_actors[actor_id]
  407.     return 0 if actor.nil?
  408.     return $game_variables[var_id] = actor.align
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * New Method: check actor alignment name
  412.   #--------------------------------------------------------------------------
  413.   def check_actor_alignment_name(actor_id, var_id)
  414.     actor_id = $game_party.members[actor_id.abs].id if actor_id <= 0
  415.     actor = $game_actors[actor_id]
  416.     return 0 if actor.nil?
  417.     return $game_variables[var_id] = actor.align_name
  418.   end
  419.   #--------------------------------------------------------------------------
  420.   # * New Method: check party alignment name
  421.   #--------------------------------------------------------------------------
  422.   def check_party_alignment_name(var_id)
  423.     align = check_party_alignment(var_id)
  424.     increment = BM::ALIGN::MAX/(BM::ALIGN::LIST.size-1)
  425.     for i in 0..BM::ALIGN::LIST.size-1
  426.       if align < (increment * 0.5  + increment * i).to_i
  427.         align_id = i
  428.         return $game_variables[var_id] = Vocab.alignment(align_id)
  429.       else
  430.         align_id = i
  431.       end
  432.     end
  433.     return $game_variables[var_id] = Vocab.alignment(align_id)
  434.   end  
  435. end
  436. #===============================================================================
  437. #
  438. # END OF FILE
  439. #
  440. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement