RPG的掷骰子库。
DiceLib的Python项目详细描述
dicelib
用于RPG的骰子滚动库。
要求
- Python3.5或更新版本。
安装
pip install DiceLib
用法
>>>fromDiceLibimportDie>>># You can create custom dice by specifying the number of faces:...d6=Die(6)>>># Rolling dice is simple:...d6.roll()[6]>>>d6.roll(2)[3,5]>>>d6.roll(7)[2,2,6,4,4,3,1]>>># The value returned might look like a list, and in many way acts like one,...# but it's actually a special class called Rolls:...roll=_>>>type(roll)<class'DiceLib.rolls.Rolls'>>>># Rolls act like lists in many ways:...roll[2,2,6,4,4,3,1]>>>roll[1:3][2,6]>>>roll[1:3]=[5,5]>>>roll[2,5,5,4,4,3,1]>>>roll[0]=6>>>roll[6,5,5,4,4,3,1]>>># But in other ways, Rolls are different:...roll.total28>>>roll.count7>>>roll.highest6>>>roll.lowest1>>>roll[2:5].highest5>>>roll[2:5].total13>>>roll<20False>>>roll>20True>>>roll==28True>>>int(roll)28>>># You can easily add or subtract from a roll:...roll+230...roll-820>>># You can even drop the lowest or highest rolls:...roll.drop_lowest()[6,5,5,4,4,3]>>>roll.drop_lowest(3)[6,5,5,4]>>>roll.drop_highest()[5,5,4,4,3,1]>>>roll.drop_highest(3)[4,4,3,1]>>># Which makes it easy, for example, to roll stats:...stats=dict()>>>forstatin["str","dex","con","int","wis","cha"]:...stat_roll=int(d6.roll(4).drop_lowest())...stats[stat]=stat_roll...>>>stats{'str':12,'dex':15,'con':14,'int':12,'wis':15,'cha':11}