| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- function getRandom1(conf,without,weight_index)
- local sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) then
- sum = sum + conf[i][weight_index]
- end
- end
-
- local r = math.random(1,sum)
- sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) then
- sum = sum + conf[i][weight_index]
- if sum >= r then
- return i
- end
- end
- end
- end
- function getRandom2(conf,without)
- local sum = 0
- for k,v in ipairs(conf) do
- if canCalc(k,without) then
- sum = sum + v.weight
- end
- end
- local r = math.random(1,sum)
- sum = 0
- for k,v in ipairs(conf) do
- if canCalc(k,without) then
- sum = sum + v.weight
- if sum >= r then
- return k
- end
- end
- end
- end
- function getRandom3(conf)
- local sum = 0
- for k,v in ipairs(conf) do
- sum = sum + v.weight
- end
- local r = math.random(1,sum)
- sum = 0
- for k,v in ipairs(conf) do
- sum = sum + v.weight
- if sum >= r then
- return k
- end
- end
- end
- -- µÈ¼¶ÏÞÖÆ
- function getRandom4(conf,without,weight_index,minLvIndex,maxLvIndex,human)
- local sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) and (not conf[i][minLvIndex] or
- human and human.db.lv >= conf[i][minLvIndex] and human.db.lv <= conf[i][maxLvIndex]) then
- sum = sum + conf[i][weight_index]
- end
- end
- local r = math.random(1,sum)
- sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) and (not conf[i][minLvIndex] or
- human and human.db.lv >= conf[i][minLvIndex] and human.db.lv <= conf[i][maxLvIndex]) then
- sum = sum + conf[i][weight_index]
- if sum >= r then
- return i
- end
- end
- end
- end
- function getRandom5(human,conf,without,weight_index,job_index,sex_index)
- local sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) then
- local job = conf[i][job_index]
- local sex = conf[i][sex_index]
- if (job == 0 or human.db.job == job) and (sex == 0 or human.db.sex == sex) then
- sum = sum + conf[i][weight_index]
- end
- end
- end
-
- if sum == 0 then
- assert()
- end
-
- local r = math.random(1,sum)
- sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) then
- local job = conf[i][job_index]
- local sex = conf[i][sex_index]
- if (job == 0 or human.db.job == job) and (sex == 0 or human.db.sex == sex) then
- sum = sum + conf[i][weight_index]
- if sum >= r then
- return i
- end
- end
- end
- end
- end
- function getRandom6(conf,without)
-
- local sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) then
- sum = sum + conf[i]
- end
- end
-
- if sum == 0 then
- assert()
- end
-
- local r = math.random(1,sum)
- sum = 0
- for i = 1 ,#conf do
- if canCalc(i,without) then
- sum = sum + conf[i]
- if sum >= r then
- return i
- end
- end
- end
- end
- function canCalc(index,without)
- if not without then
- return true
- end
- if without then
- for k,v in ipairs(without) do
- if index == v then
- return false
- end
- end
- end
- return true
- end
|