Thread: [Essentials script] Pokémon TCG mod
View Single Post
  #41    
Old September 25th, 2012, 09:23 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
Alright, I did understand what you said there.



I prefer a signle class (PokeBattle_Effects) with different variables that will in the outcome suit every needed situation
and to make it more flexible add a custom_code segment which allows you to evaluate a custom code just for incase there are
some un-defined methods required within the effect

OR

We can do something simmilar to Essentials where we must create a code for every move (which is time more time consuming in
my opinion)

the PokeBattle_Effects class can store any type of effect: Move/Ability/Card and can be activated at selected points:
Turn Started/Turn Ended/Coin Flipped/Coin Heads/Coin Tales/Your Turn/Enemy Turn/ect. using an array you can select multiple
points to activate this at. I also did create a sample of what I mean (I only spent about 5 minutes or so on this so it's
not perfect and may seem a little confusing) but this is what I made:

Spoiler:

Code:
=begin
  This is an example of what I would do for Effects, I can make any changes you wish
  You can add to this as you wish and or modify it. If you don't like this system,
  I can completely reconstruct this to Essential's style.
=end
class PokeBattle_Effects

  attr_accessor :type            # Integer -- 0 = card, 1 = move, 2 = ability
  attr_accessor :activation_type # Integer -- when to activate the effect (0= your turn, 1= enemy's turn, 2= coin flip, 3= before attack, 4= during attack, ect.)
  attr_accessor :hold_effect     # Integer -- how many turns to hold the effect
  attr_accessor :effect          # Integer -- 0 = damage, 1 = status, and so forth
  attr_accessor :effect_attribute# Integer -- how much damage?, which status?, ect.
  attr_accessor :chance          # Integer -- Percentage chance of the succes of the effect
  attr_accessor :custom_function # String  -- A string containing ruby code on what to execute (executes every time called)
  attr_accessor :activated       # Boolean -- Is this effect active?
  attr_accessor :turns           # Integer -- Maximum turns to hold the effect (auto selected by hold_effect)
  
  # startup of the class
  def initialize(type, activation_type, effect, hold_effect = 1, custom_function = "")
    @type = type
    @activation_type = activation_type
    @effect = effect
    @hold_effect = hold_effect
    @custom_function = custom_function
    @turns = hold_effect
  end
  
  # returns wether the ability is avaible to activate
  # if it is activatable it reset the activation turns (unless already active)
  def activatable?(a_type)
    @hold_effect = @turns if @activation_type == a_type && !@activated
    @activated = true if @activation_type == a_type && !@activated
    return @activation_type == a_type
  end
  
  # returns if the effect is currently active
  def updatable?
    return @activated
  end
  
  # updates and returns an array (the length will be 1 if it did not do anything)
  def update
    @hold_effect -= 1
    destroy = @hold_effect > 0
    ret = [destroy]
    if rand(100-@chance) == 0
      ret.push(effect)
      ret.push(effect_attributes)
      ret.push(eval(@custom_function)) if @custom_function != ""
    end
    return ret
  end
    
end



also, if you are going to read data ini-style like essentials does I made a small tool for this too:

Spoiler:


Code:
=begin
  Just a handy tool for reading ini files
  
  Reads ini files and stores them in data.
  
  You can get values like so:
  ini.read_value(section(string or int), variable(string or int), default(anything))
  returns the value of the ini you set, but returns default if it does not exist
=end


class IniReader
  attr_accessor :data
  def initialize(ini)
    array = IO.readlines(ini)
    @data = {}
    startoff_section = "["
    
    section_name = ""
    section_hash = {}
    for i in 0..array.length-1
      if array[i][0] == startoff_section[0]
        if i != 0
          @data[section_name] = section_hash
        end
        section_name = array[i].split("[")[1].split("]")[0]
      elsif array[i].count("=") != 0
        tary = array[i].split("=")
        value = ""
        for i in 0..tary.length-2
          value+=tary[i+1]
        end
        section_hash[tary[0]]=value
      end
    end
    @data[section_name] = section_hash
  end
  
  def read_value(section, variable, default=-1)
    section = "#{section}"
    variable = "#{variable}"
    if @data[section][variable] == nil
      ret = default
    else
      ret = @data[section][variable]
    end
    return ret
  end
  
end


n = IniReader.new("Game.ini")
print n.read_value("Game", "Title")


so if you have a different idea or have improvements for the PokeBattle_Effects class, let me know.