IceDragon200

IEI - Scopius (WIP2)

Mar 9th, 2012
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.58 KB | None | 0 0
  1. # // 02/28/2012
  2. # // 03/09/2012
  3. # // IEI - Scopius
  4. class RPG::UsableItem  
  5.   class Scope
  6.     class Filter
  7.       def initialize(code, *params)
  8.         @code, @params = code, params
  9.       end
  10.       attr_accessor :code
  11.       attr_accessor :params
  12.     end  
  13.     module Constants
  14.       # // Standard
  15.       CODE_NONE     = 0
  16.       CODE_USER     = 1
  17.       CODE_OPPONENTS= 2
  18.       CODE_FRIENDS  = 3
  19.       CODE_EVERYONE = 4
  20.    
  21.       FILTER_ALIVE  = 0
  22.       FILTER_DEAD   = 1
  23.       FILTER_ANY    = 2
  24.      
  25.       SCOPE_SINGLE  = 0
  26.       SCOPE_ALL     = 1
  27.       SCOPE_RANDOM  = 2
  28.    
  29.       # // Ex
  30.       CODE_GLOBAL   = 5  # // REI - Global System
  31.       FILTER_STYPE  = 12 # // Target if they support n Stype (Skill)
  32.       FILTER_WTYPE  = 13 # // Target if they support n Wtype (Weapon)
  33.       FILTER_ATYPE  = 14 # // Target if they support n Atype (Armor)
  34.       FILTER_STATE  = 15 # // Target if they have n state
  35.     end  
  36.     include Constants
  37.     include Mixin::FeatureConstants
  38.     # // Scope Conversion . x . RGSS2/3 to Scopius
  39.     def self.quick_scope(n)
  40.       case n
  41.       when :everyone
  42.         new(CODE_EVERYONE,FILTER_ALIVE,SCOPE_SINGLE)
  43.       end  
  44.     end  
  45.     def self.[](code)
  46.       case code
  47.       when 0
  48.         new(CODE_NONE)
  49.       # // One Enemy
  50.       when 1  
  51.         new(CODE_OPPONENTS,FILTER_ALIVE,SCOPE_SINGLE)
  52.       # // All Enemies  
  53.       when 2  
  54.         new(CODE_OPPONENTS,FILTER_ALIVE,SCOPE_ALL)  
  55.       # // Random Enemies  
  56.       when 3, 4, 5, 6
  57.         new(CODE_OPPONENTS,FILTER_ALIVE,SCOPE_RANDOM,code-2)
  58.       when 7
  59.         new(CODE_FRIENDS  ,FILTER_ALIVE,SCOPE_SINGLE)
  60.       when 8  
  61.         new(CODE_FRIENDS  ,FILTER_ALIVE,SCOPE_ALL)  
  62.       when 9
  63.         new(CODE_FRIENDS  ,FILTER_DEAD ,SCOPE_SINGLE)
  64.       when 10  
  65.         new(CODE_FRIENDS  ,FILTER_DEAD ,SCOPE_ALL)
  66.       when 11
  67.         new(CODE_USER     ,FILTER_ANY  ,SCOPE_SINGLE)
  68.       else
  69.         new(code,0,0)
  70.       end  
  71.     end  
  72.     def initialize(code=CODE_NONE,filters=[FILTER_ALIVE],scope=SCOPE_SINGLE,*params)
  73.       @code    = code
  74.       @scope   = scope
  75.       @filters = (filters.is_a?(Enumerable) ? filters : [filters])
  76.       @filters.collect!{|f|f.is_a?(Filter) ? f : Filter.new(f)}
  77.       @params  = params
  78.     end  
  79.     def adjust_targets(targets,user)
  80.       result = targets
  81.       @filters.each do |filter|
  82.         case filter.code
  83.         # // Standard
  84.         when FILTER_DEAD
  85.           result.select!{|m|m.dead?}
  86.         when FILTER_ALIVE
  87.           result.select!{|m|m.alive?}
  88.         when FILTER_ANY
  89.           result  
  90.         # // Ex  
  91.         when FILTER_STYPE
  92.           stype_id = filter.params[0]
  93.           result.select!{|m|m.features_set(FEATURE_STYPE_ADD).include?(stype_id)}
  94.         when FILTER_WTYPE
  95.           wtype_id = filter.params[0]
  96.           result.select!{|m|m.features_set(FEATURE_WTYPE_ADD).include?(wtype_id)}
  97.         # // Armor Type  
  98.         when FILTER_ATYPE
  99.           atype_id = filter.params[0]
  100.           result.select!{|m|m.features_set(FEATURE_ATYPE_ADD).include?(atype_id)}
  101.         # // States
  102.         when FILTER_STATE
  103.           state_id = filter.params[0]
  104.           result.select!{|m|!m.states.find(){|s|s.id==state_id}.nil?()}
  105.         # // .x . Level stuff  
  106.         when FILTER_LEVEL  
  107.           # // 1- user.level == target.level
  108.           # // 2- target.level % n == 0
  109.           case filter.param[0]
  110.           when 1
  111.             result.select!{|m|m.level == user.level}
  112.           when 2
  113.             mlevel = param[1]
  114.             result.select!{|m|m.level % mlevel == 0}
  115.           end  
  116.         # ITS TEH FORBIDDEN EVAL (:
  117.         when FILTER_SCRIPT  
  118.           targets = result
  119.           result = eval(filter.params[0])
  120.         # // What the hell?  
  121.         else
  122.           raise "Unknown scope value #{val}"
  123.         end
  124.       end  
  125.       result
  126.     end  
  127.     def target_number()
  128.       @scope == SCOPE_RANDOM ? @params[0] : 0
  129.     end
  130.     # // State
  131.     def dead?
  132.       @values.include?(FILTER_DEAD)
  133.     end
  134.     def alive?
  135.       @values.include?(FILTER_ALIVE)
  136.     end
  137.     def any_state?
  138.       @values.include?(FILTER_ANY)
  139.     end
  140.     # // Target Group
  141.     def friend?
  142.       @code == CODE_FRIENDS
  143.     end  
  144.     def opponent?
  145.       @code == CODE_OPPONENTS
  146.     end  
  147.     def everyone?
  148.       @code == CODE_EVERYONE
  149.     end  
  150.     def none?
  151.       @code == CODE_NONE
  152.     end  
  153.     def user?()
  154.       @code == CODE_USER
  155.     end
  156.     def global?
  157.       @code == CODE_GLOBAL
  158.     end
  159.     def team?
  160.       all? && (opponent? || friend?)
  161.     end  
  162.     # // Scope Checks
  163.     def single?
  164.       @scope == SCOPE_SINGLE
  165.     end  
  166.     def random?
  167.       @scope == SCOPE_RANDOM
  168.     end  
  169.     def all?
  170.       @scope == SCOPE_ALL
  171.     end
  172.     def need_selection?()
  173.       #[SCOPE_SINGLE].include?(@scope) # // >x< If I ever expand it
  174.       @scope == SCOPE_SINGLE
  175.     end  
  176.     def param(n)
  177.       @params[n]
  178.     end  
  179.     attr_accessor :code
  180.     attr_accessor :scope
  181.     attr_accessor :filters
  182.     attr_accessor :params
  183.   end
  184.   def convert_scope()
  185.     @scope = Scope[@scope] unless @scope.is_a?(Scope)
  186.     @scope
  187.   end  
  188.   def scope()
  189.     convert_scope()
  190.   end  
  191.   # // Legacy Support
  192.   def for_opponent?()
  193.     scope.opponent?
  194.   end
  195.   def for_friend?()
  196.     scope.friend?
  197.   end
  198.   def for_dead_friend?
  199.     scope.dead? && scope.friend?
  200.   end
  201.   def for_user?
  202.     scope.user?()
  203.   end
  204.   def for_one?
  205.     scope.single?()
  206.   end
  207.   def for_random?
  208.     scope.random?()
  209.   end
  210.   def for_all?
  211.     scope.all?()
  212.   end
  213.   def need_selection?
  214.     scope.need_selection?()
  215.   end
  216.   def number_of_targets
  217.     for_random? ? scope.params[0] : 0
  218.   end
  219.   def for_everyone?()
  220.     scope.everyone?
  221.   end  
  222.   def for_everyone_alive?()
  223.     for_everyone?() && scope.alive?()
  224.   end  
  225.   def for_everyone_dead?()
  226.     for_everyone?() && scope.dead?()
  227.   end  
  228.   def for_global?()
  229.     scope.global?()
  230.   end  
  231. end
  232. class Game::Action
  233.   def get_scope_targets_basic(scope)
  234.     #consts = RPG::UsableItem::Scope::Constants
  235.     result = []
  236.     if scope.none?()  
  237.       result = []
  238.     elsif scope.user?()
  239.       result = [@subject]
  240.     elsif scope.friend?()
  241.       result = friends_unit.members
  242.     elsif scope.opponent?()
  243.       result = opponents_unit.members
  244.     elsif scope.everyone?()  
  245.       result = friends_unit.members + opponents_unit.members
  246.     elsif scope.global?()
  247.       result = [_map.global]
  248.     end  
  249.     result.uniq
  250.   end
  251.   def adjust_scope_targets(scope, targets)
  252.     # // Filtering
  253.     result = scope.adjust_targets(effect_select_targets(targets),@subject)
  254.     if scope.single?
  255.       result = select_single_targets(result)
  256.       result *= 1 + (attack? ? subject.atk_times_add.to_i : 0)
  257.     elsif scope.random?()
  258.       result = (0...scope.target_number).collect{result.sample}
  259.     elsif scope.all?()
  260.       result = Array.new(result)
  261.     end
  262.     result
  263.   end
  264.   def get_scope_targets(scope)
  265.     adjust_scope_targets(scope, get_scope_targets_basic(scope))
  266.   end  
  267.   def effect_select_targets(targets)
  268.     targets
  269.   end unless method_defined? :effect_select_targets
  270.   def select_single_targets(targets)
  271.     [targets[@target_index]]
  272.   end unless method_defined? :select_single_targets
  273.   def make_targets()
  274.     if !forcing && subject.confusion?
  275.       [confusion_target]
  276.     else
  277.       get_scope_targets(item.scope)
  278.     end
  279.   end  
  280. end  
  281. #=■==========================================================================■=#
  282. #                           // ● End of File ● //                              #
  283. #=■==========================================================================■=#
Advertisement
Add Comment
Please, Sign In to add comment