Mersenne Prime Item Gain
Version: 1
Author: Soulpour777
Date: February 18, 2015
Description
For those who are wondering what Mersenne Prime is, here is a brief explanation:
for p an odd prime, the Mersenne number 2p − 1 is prime if and only if 2p − 1 divides S(p − 1) where S(n + 1) = (S(n))2 − 2, and S(1) = 4.
This script allows you to execute and check the Mersenne Primes and adds item, weapon and armor variation item gain. This script calculate all Mersenne primes up to the implementation's maximum precision, or the 47th Mersenne prime. (Which ever comes first) and adds that item on your inventory.
Features
- Mersenne Based Items
- Mersenne Based Weapons
- Mersenne Based Armors
Instructions
Script Calls:prime_change_number(prime_number_value)
where prime_number_value is the value you want to change the UPB_Prime dividing number. For example, the default UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 0 has no changes of how many item is given. If you do: UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 5, this will give only 1 item. Since the default gives you 6 items. 6 - 5, simple, gives you 1.
Script Example:
prime_change_number(4)
gives you 2 items in either item, weapon or armor.
mersenne_gain_item
^ This calls the script's main function, creates the Mersenne Prime and adds item according to this algorithm.
Script
#==============================================================================
# ** Mersenne Prime Item Gain
# Author: Soulpour777
# Script Version 1.0
# February 18, 2015
#------------------------------------------------------------------------------
# Description:
# For those who are wondering what Mersenne Prime is, here is a brief
# explanation:
# for p an odd prime, the Mersenne number 2p − 1 is prime if and
# only if 2p − 1 divides S(p − 1) where S(n + 1) = (S(n))2 − 2, and S(1) = 4.
# This script allows you to execute and check the Mersenne Primes and adds
# item, weapon and armor variation item gain. This script calculate all
# Mersenne primes up to the implementation's maximum precision,
# or the 47th Mersenne prime. (Which ever comes first) and adds that item on
# your inventory.
#------------------------------------------------------------------------------
# Script Calls:
# prime_change_number(prime_number_value)
# where prime_number_value is the value you want to change the UPB_Prime
# dividing number. For example, the default
# UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 0 has no changes of how many
# item is given. If you do: UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 5,
# this will give only 1 item. Since the default gives you 6 items. 6 - 5,
# simple, gives you 1.
# Script Example: prime_change_number(4) - gives you 2 items in either item,
# weapon or armor.
# mersenne_gain_item
# ^ This calls the script's main function, creates the Mersenne Prime and
# adds item according to this algorithm.
#------------------------------------------------------------------------------
# Author's Note: Someone of you would surely ask, why on earth are you,
# Soulpour777 make this kind of script? The answer is because I am tired
# using the old style of randomizing items to gain. This script allows me
# to make more changes than the usual randomizing of things. I also want
# to apply some kind of math into my games, so here's one I could think of.
# You can use this script if you want...but if no one does, I would.
#------------------------------------------------------------------------------
# Terms of Use:
# For Non Commercial use only. For Commercial Use, please contact m
#==============================================================================
module Soul
module MersennePrime
# Would you like to use an SE when you gain this mystery item?
Use_SE = false
# What sound effect do you want to play? Must be in Audio/SE
Item_SE = "Chime1"
# Default Count...don't change this.
Count = 0
Precision = 5 # maximum requested number of decimal places of 2 ** MP-1 #
Long_Bits_Width = Precision / Math.log(2) * Math.log(10)
UPB_Prime = (Long_Bits_Width - 1).to_i / 2 - 0 # no unsigned #
UPB_Count = 45 # find 45 mprimes if int was given enough bits #
#--------------------------------------------------------------------------
# * Mersenne Prime : use method to check if it is a normal prime
#--------------------------------------------------------------------------
def self.is_prime ( p )
return true if p == 2
return false if p <= 1 || p.even?
(3 .. Math.sqrt(p)).step(2) do |i|
return false if p % i == 0
end
true
end
#--------------------------------------------------------------------------
# * Mersenne Prime Check : use method to check if it is a mersenne prime
#--------------------------------------------------------------------------
def self.is_mersenne_prime ( p )
return true if p == 2
m_p = ( 1 << p ) - 1
s = 4
(p-2).times { s = (s ** 2 - 2) % m_p }
s == 0
end
end
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
alias :soul_mersenne_prime_initialize :initialize
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :mersenne_counter
attr_accessor :prime_change
attr_accessor :kind_randomizer
attr_accessor :old_decrease_value
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
def initialize(depth = 0)
soul_mersenne_prime_initialize(depth = 0) # Call original method
@prime_change = Soul::MersennePrime::UPB_Prime # Changes to default
@kind_randomizer = 1 # default, this goes as item
@old_decrease_value = 0
end
#--------------------------------------------------------------------------
# * Prime Change Number :new method
#--------------------------------------------------------------------------
def prime_change_number(prime_number_value)
@old_decrease_value = prime_number_value
@prime_change = (Soul::MersennePrime::Long_Bits_Width - 1).to_i / 2 - @old_decrease_value
end
#--------------------------------------------------------------------------
# * Mersenne Gain Item
#--------------------------------------------------------------------------
def mersenne_gain_item
@mersenne_counter = Soul::MersennePrime::Count
@kind_randomizer = rand(3) + 1
puts @kind_randomizer
for p in 2..@prime_change
if Soul::MersennePrime.is_prime(p) && Soul::MersennePrime.is_mersenne_prime(p)
case @kind_randomizer
when 1 # item
$game_party.gain_item($data_items[p],1,true)
when 2 # Weapon
$game_party.gain_item($data_weapons[p],1,true)
when 3
$game_party.gain_item($data_armors[p],1,true)
end
@mersenne_counter += 1
end
break if @mersenne_counter >= Soul::MersennePrime::UPB_Count
RPG::SE.new(Soul::MersennePrime::Item_SE,100,100).play if Soul::MersennePrime::Use_SE
end
end
end
Credit
Thanks
- Marin Mersenne, creator of the said formula
Support
For support, comment on this post or contact me here on RMRK.
Known Compatibility Issues
None.
Author's Notes
Someone of you would surely ask, why on earth are you, Soulpour777 make this kind of script? The answer is because I am tired using the old style of randomizing items to gain. This script allows me to make more changes than the usual randomizing of things. I also want to apply some kind of math into my games, so here's one I could think of. You can use this script if you want...but if no one does, I would.
Terms of Use
This script is free only for Non Commercial use. For Commercial Uses, please contact me.