赞 | 32 |
VIP | 44 |
好人卡 | 11 |
积分 | 17 |
经验 | 81722 |
最后登录 | 2020-3-23 |
在线时间 | 1357 小时 |
Lv3.寻梦者 唯一的信徒
- 梦石
- 0
- 星屑
- 1665
- 在线时间
- 1357 小时
- 注册时间
- 2013-1-29
- 帖子
- 1637
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
其实说是拓展实际上就增加了几个方法,VA里面可以带战斗公式里面用。
说明在脚本里面我认为说的够清楚了
然后这样你可以在VA的公式里面写:(a.atk * 4 - b.def * 2) * Rd.gauss(1,0.2)
这样就会生成正态分布的伤害
#encoding:utf-8 #============================================================================== # ■ Rand Formulas #------------------------------------------------------------------------------ # Provides additional random methods, mainly for battle formulas #============================================================================== # ● Rd.gauss(mean : Number, stddev : Number) # 生成高斯分布的一个随机数(貌似是正态分布或者类似),第一个参数是平均值,第二个参数是方差 # Generates a random gaussian distributed number. # Eg. Rd.gauss(1,0.1) #============================================================================== # ● Rd.percentage # 返回一个1~100的数值 # Returns a value between 1 and 100 #============================================================================== # ● Rd.between(min : Number, max : Number) # 平均分布的随机数,位于min与max之间。 # Generates a equally distributed random number between min and max. #============================================================================== # ● Rd.betweenP(min : Number, max : Number) # 平均分布的随机数,位于min/100与max/100之间 # Generates a equally distributed random number between min/100 and max/100 #============================================================================== =begin This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <[url]http://unlicense.org/[/url]> =end class RandomGaussian def initialize(mean, stddev, rand_helper = lambda { Kernel.rand }) @rand_helper = rand_helper @mean = mean @stddev = stddev @valid = false @next = 0 end def rand if @valid then @valid = false return @next else @valid = true x, y = self.class.gaussian(@mean, @stddev, @rand_helper) @next = y return x end end private def self.gaussian(mean, stddev, rand) theta = 2 * Math::PI * rand.call rho = Math.sqrt(-2 * Math.log(1 - rand.call)) scale = stddev * rho x = mean + scale * Math.cos(theta) y = mean + scale * Math.sin(theta) return x, y end end #[url]http://stackoverflow.com/questions/5825680/code-to-generate-gaussian-normally-distributed-random-numbers-in-ruby[/url] module Rd class << self # Number -> Number -> Number def gauss mean, stddev g = RandomGaussian.new(mean, stddev) return g.rand end # Unit -> Number def percentage return Random.new.rand(1..100) end # Number -> Number -> Number def between a, b return Random.new.rand(a..b) end # Number -> Number -> Number def betweenP a, b return between(a,b) / 100.0 end end end
#encoding:utf-8
#==============================================================================
# ■ Rand Formulas
#------------------------------------------------------------------------------
# Provides additional random methods, mainly for battle formulas
#==============================================================================
# ● Rd.gauss(mean : Number, stddev : Number)
# 生成高斯分布的一个随机数(貌似是正态分布或者类似),第一个参数是平均值,第二个参数是方差
# Generates a random gaussian distributed number.
# Eg. Rd.gauss(1,0.1)
#==============================================================================
# ● Rd.percentage
# 返回一个1~100的数值
# Returns a value between 1 and 100
#==============================================================================
# ● Rd.between(min : Number, max : Number)
# 平均分布的随机数,位于min与max之间。
# Generates a equally distributed random number between min and max.
#==============================================================================
# ● Rd.betweenP(min : Number, max : Number)
# 平均分布的随机数,位于min/100与max/100之间
# Generates a equally distributed random number between min/100 and max/100
#==============================================================================
=begin
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <[url]http://unlicense.org/[/url]>
=end
class RandomGaussian
def initialize(mean, stddev, rand_helper = lambda { Kernel.rand })
@rand_helper = rand_helper
@mean = mean
@stddev = stddev
@valid = false
@next = 0
end
def rand
if @valid then
@valid = false
return @next
else
@valid = true
x, y = self.class.gaussian(@mean, @stddev, @rand_helper)
@next = y
return x
end
end
private
def self.gaussian(mean, stddev, rand)
theta = 2 * Math::PI * rand.call
rho = Math.sqrt(-2 * Math.log(1 - rand.call))
scale = stddev * rho
x = mean + scale * Math.cos(theta)
y = mean + scale * Math.sin(theta)
return x, y
end
end
#[url]http://stackoverflow.com/questions/5825680/code-to-generate-gaussian-normally-distributed-random-numbers-in-ruby[/url]
module Rd
class << self
# Number -> Number -> Number
def gauss mean, stddev
g = RandomGaussian.new(mean, stddev)
return g.rand
end
# Unit -> Number
def percentage
return Random.new.rand(1..100)
end
# Number -> Number -> Number
def between a, b
return Random.new.rand(a..b)
end
# Number -> Number -> Number
def betweenP a, b
return between(a,b) / 100.0
end
end
end
|
|