-
-
Save kimukou/1131502 to your computer and use it in GitHub Desktop.
TinTiroRin.groovy (use groovy1.7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// using http://dl.getdropbox.com/u/653108/groovy/console.jnlp | |
// | |
@Grab('net.sf.groovydice:groovydice:1.4.1') | |
import net.sf.groovydice.* | |
ArrayList.metaClass.countBy={ | |
def map=[:] | |
delegate.groupBy(it).each{k,v-> | |
println "$k $v" | |
map[k]=v.size() | |
} | |
println map | |
map | |
} | |
class TinTiroRinPlugin { | |
def dynamicMethods = { api -> | |
api.add(method:'ttr') { dice -> | |
if (dice.allDice.size() != 3) return "ションベン!" | |
def stats = [all:dice.allDice, count:dice.allDice.countBy{it}] | |
switch (stats) { | |
case { it.count.size() == 1 && it.count[1] }: | |
return "$stats.all ピンゾロ(5倍づけ)です。" | |
case { it.count.size() == 1 }: | |
return "$stats.all ${stats.count.findResult{it.key}}のゾロ目(3倍づけ)です。" | |
case { it.count.size() == 2 }: | |
return "$stats.all ${stats.count.find{it.value == 1}.key}です。" | |
case { it.all.sum() == 6 }: | |
return "$stats.all ヒフミ(2倍払い)です。" | |
case { it.all.sum() == 15 }: | |
return "$stats.all シゴロ(2倍づけ)です。" | |
default: | |
return "$stats.all 目無しです。" | |
} | |
} | |
} | |
} | |
def config = new GroovyDice() | |
config.pluginManager.register(new TinTiroRinPlugin()) | |
config.initialize() | |
println 3.d.ttr() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment