#==============================================================================## ## Paramecium Core V 0.1 ## June 28, 2015 ## ##------------------------------------------------------------------------------## This is my core script, required for some of my other scripts. You may use ## the classes and methods in it in your scripts as long as you give me credit. ##==============================================================================#($imported ||= {})["Paramecium"] = truemodule Paramecium #Uses the Box–Muller transform to generate normally distributed random numbers def self.stnRand() return Math.sqrt( -2 * Math.log(rand())) * Math.cos( 2 * Math:

I * rand()) end # Generates normally distributed numbers with a mean of μ and a standard # deviation of σ. def self.nRand(μ,σ) return μ + stnRand()* σ end # Performs a "skill check" with a difficulty level of 'difficulty'. # returns true if the player (or whoever is performing the skill check) # passes it and false if they fail. When the skill level is equal to the # difficulty level, there is a fifty percent chance of passing. This # method uses a default standard deviation of 2.5, which was chosen arbitrarily. def self.skillCheck(skillLevel, difficulty,s = 2.5) x = nRand(skillLevel, s) return x >= difficulty end def self.show_selection(array) params = [] choices = [] array.each{|item| choices.push(item[0]) } params.push(choices) params.push(0) params[0].each {|s| $game_message.choices.push(s) } #$game_message.choice_cancel_type = params[1] $game_message.choice_proc = Proc.new {|x| $paramecium_choice =(x) } end def self.get_choice(array) array[$paramecium_choice][1] end # This method calls a scene that shows a list of choices for the player and ] # returns an object depending on their choice and the array you put into this # method. The parameter 'array' is an array of the form: #[["string_0",object_0],["string_1",object_1],...,["string_(n-1)",object_(n-1)]]; # with a length of n. The method will display the strings in a choice window, # similar to the one used for events def self.selection(array) show_selection(array) Fiber.yield until not $game_message.busy? get_choice(array) end def self.multipleChoice(array,duplicates=false) array << ["End","End"] results = [] while true r = selection(array) r == "End" ? break : results << r end duplicates ? results : results.uniq || results end def self.invContains?(array,type) case type.downcase[0,1] when "i" getVal = Proc.new {|n| $game_party.item_number($data_items[n])} when "w" getVal = Proc.new {|n| $game_party.item_number($data_weapons[n])} when "a" getVal = Proc.new {|n| $game_party.item_number($data_armors[n])} else return false end array.each {|entry| return false unless getVal.call(entry[0]) >= entry[1] } end def self.changeInv(array,type) case type.downcase[0,1] when "i" change = Proc.new {|n, amount| if n >= 0 $game_party.gain_item($data_items[n], amount) else $game_party.lose_item($data_items[n], amount) end } when "w" change = Proc.new {|n, amount| if n >= 0 $game_party.gain_item($data_items[n], amount) else $game_party.lose_item($data_items[n], amount) end } when "a" change = Proc.new {|n, amount| if n >= 0 $game_party.gain_item($data_items[n], amount) else $game_party.lose_item($data_items[n], amount) end } else return false end array.each {|entry| change.call(entry[0],entry[1]) } end # Returns an array with the specified position(s) in its sub-arrays negated. def self.negatePos(array,pos) r = [] if pos.is_a? Array myCheck = Proc.new {|i| pos.include?(i)} else myCheck = Proc.new {|i| i == pos} end array.each{|entry| entryClone = [] entry.each_index {|i| entryClone.push(myCheck.call(i)? -1*entry
: entry) } r.push(entryClone) } r end class MultiMap def initialize(hash) @data = hash @length = hash.length @domain = hash.keys end def image(x) return @hash[x] end def preImage(y) arr = Array.new for i in 0..@length-1 arr << @domain if @data[@domain].index(y) end return arr end end # This implements a priority queue in which each element consists of an # object (e.g a string, an array, or a number [such as an item id]) and a rank # (e.g actor ID and number of skills), in that order. It is initialized from # an array of the form: # [[object-1,rank-1],[object-2,rank-2],...[object-n,rank-n]]. # The nested array [object-i,rank-i] is called an entry. # # The methods 'max' and 'min' return the entries with the highest and lowest # rankings respectively. When two or more entries have the same rank, it # returns the one that has the lowest index in the array {i.e. that comes # first). # The method 'sort!' sorts the data from highest ranked to lowest ranked. If # two or more entries have the same rank, the one that had the # lowest index before 'sort!' will have the lowest index after, with entries # of equal rank following behind. The method 'add' adds another entry to the # Ranking. # The method 'nextR!' returns the entry with the highest rank (in cases of # equal rank, the same rule as above applies) and removes it from the Ranking. # The method 'next!' returns the object in the entry # with the highest rank and removes its entry from the Ranking. # The 'blackjack(n)' method returns the object with the value closest to but # not exceeding n, like in the card game blackjack the goal is to get as close # to 21 without going over. # The 'blackjack!(n)' method does the same thing as 'blackjack' but also # removes entry of the returned object. class Ranking def initialize(array) @data = array @length = array.length end def min m = @data[0] for i in 1..@length-1 if @data[1]<m[1] m = @data end end return m; end def max() m = @data[0] for i in 1..@length-1 if @data[1]>m[1] m = @data end end return m; end def sort! arr = Array.new for i in 0..@length-1 arr <<self.nextR! end @data = arr end def add(newEntry) if newEntry.is_a?(Array) && newEntry[1].is_a(Numeric) @data << newEntry @length += 1 end end def nextR! m = @data[0] index = 0 for i in 1..@length-1 if @data[1]>m[1] m = @data index = i end end @data.delete_at(index) @length -= 1 return m; end def next! return self.nextR![0] end def blackjack(n) b = @data[0] for i in 1..@length-1 if ((m[1]>n&&@data[1]<=n)||(@data[1]<n&&@data[1]>m[1])) m = @data end end return m end def blackjack!(n) b = @data[0] index = 0 for i in 1..@length-1 if ((m[1]>n&&@data[1]<=n)||(@data[1]<n&&@data[1]>m[1])) m = @data index = i end end @data.delete_at(index) return m end endend# Adds two new methods to the 'Array' classclass Array # Is this array a subset of 'other'? (i.e are all elements of this array # elements of the other array?) def subset?(other) self.each{|item| return false unless other.include?(item) } return true end # Is this array a superset of 'other' (is 'other' a subset of this array)? # (i.e are all elements of the other array elements of this array?) def superset?(other) other.subset?(self) end # Does 'other' have the same elements as 'self' and 'self' the same elements # as 'other'? # [Are the two arrays equal, ignoring order?] def setEquals?(other) self.subset?(other) && self.superset?(other) end unless $imported[:ve_basic_module] def random self[rand(self.length)] end endend