Create dice for gambling games.

This commit is contained in:
Howard Abrams 2025-06-21 10:58:53 -07:00
parent c147594489
commit 34820da276
3 changed files with 198 additions and 1 deletions

View file

@ -221,3 +221,34 @@ class CmdOctopus(Command):
class CmdSetOctopus(CmdSet): class CmdSetOctopus(CmdSet):
def at_cmdset_creation(self): def at_cmdset_creation(self):
self.add(CmdOctopus) self.add(CmdOctopus)
class CmdRoll(MuxCommand):
"""
Roll the dice in your inventory.
Usage:
roll
Or:
roll/switches
Will announce your roll to the room. If you have more than one
dice, the following switches are available:
sum : Report the sum of the dice
high : Report only the highest (advantage)
low : Report only the lowest (disadvantage)
"""
key = "roll"
locks = "cmd:holds()"
switch_options = ("sum", "high", "low")
def func(self):
self.obj.roll(self.caller, self.switches)
class CmdSetDice(CmdSet):
def at_cmdset_creation(self):
self.add(CmdRoll)

View file

@ -13,7 +13,8 @@ from commands.misc import (CmdSetPuddle,
CmdSetStick, CmdSetStick,
CmdSetKnock, CmdSetKnock,
CmdSetSmoke, CmdSetSmoke,
CmdSetRummage) CmdSetRummage,
CmdSetDice)
from commands.consumables import CmdSetMakeConsumable from commands.consumables import CmdSetMakeConsumable
from commands.wizards import CmdSetWand from commands.wizards import CmdSetWand
from utils.word_list import routput, choices from utils.word_list import routput, choices
@ -155,6 +156,43 @@ class Ring(Object):
return False return False
class Dice(Object):
"""
Dice that can be rolled.
A "game" should be able to query the dice to get the results.
Override the following default properties to adjust the dice:
@set dice/size = 6
@set dice/number = 1
"""
# Defaults ... should be overridden with db:
number = 1
size = 6
def at_object_creation(self):
self.cmdset.add_default(CmdSetDice)
def roll(self, roller, options):
size = self.db.size or self.size
number = self.db.number or self.number
rolls = [randint(1, size) for d in range(number)]
self.db.last_roll = sum(rolls)
prepend = ""
if number > 1:
if "sum" in options:
prepend = prepend + f" The sum is {sum(rolls)}."
if "high" in options:
prepend = prepend + f" The highest is {max(rolls)}."
if "low" in options:
prepend = prepend + f" The lowest is {min(rolls)}."
roller.announce_action("$You() $conj(roll) a " + iter_to_str(rolls) +
"." + prepend)
class Pipe(Object): class Pipe(Object):
"""Simple abstraction for the following actions. """Simple abstraction for the following actions.

128
world/version3.ev Normal file
View file

@ -0,0 +1,128 @@
# George and the Troll
# Logging in as George, we create a character with the following answers:
# #+begin_example
# large troll
# neutral
# balancing a giant die across its knuckles
# A large troll with long black hair and greasy, green skin. Sporting a purple tunic with a |mWyldwood Bar and Games|n logo and the slogan: |wThe House better Win...or Else!|n
# Troll
# #+end_example
# Create the rules that we can drop on a table or something.
# [[file:../../../projects/mud-games.org::*George and the Troll][George and the Troll:1]]
@create rules: typeclasses.things.Readable
#
@desc rules = A small, worn card with the rules of the game, |yHobbits and Trolls|n printed on it.
# George and the Troll:1 ends here
# And write out the rules:
# [[file:../../../projects/mud-games.org::*George and the Troll][George and the Troll:2]]
@set rules/inside = The rules to |yTrolls and Hobbits|n are simple.
The player playing the |wtroll|n rolls a ten-sided die to set the
|wlevel|n to beat, called the |wknee|n. The player(s) playing the
|whobbits|n then roll two cubical dice to meet or exceed that value.
The higher the knee, the bigger the payout. Rule exceptions:
If knee is 1, the house wins with a |wkick|n.
Knee is 2-3, the house pays 1:1
Knee is 4-6, the house pays 2:1
Knee is 7-9, the house pays 3:1
Knee is 10, the house pays 5:1
If hobbits roll a 2, |wsnake eyes|n, troll is scared, and is a |wpush|n.
If hobbits roll 11 or 12, they overshoot into the |wmaw|n, and are eaten,
and the house wins.
If the hobbits |wtie|n with the troll's knee, they can either accept
the payout, or |wsplit|n, where they double their bet, roll a
second pair of dice that combines with the initial roll to make
two separate bids. The hobbits choose which of the new dice rolls
combine with the old rolls.
# George and the Troll:2 ends here
# Create the dice for others in the game:
# [[file:../../../projects/mud-games.org::*George and the Troll][George and the Troll:3]]
@create pair of dice: typeclasses.things.Dice
#
@desc dice = Couple of cubical blocks painted green.
#
@set dice/number = 2
# George and the Troll:3 ends here
# And create the large d10 for the Troll:
# [[file:../../../projects/mud-games.org::*George and the Troll][George and the Troll:4]]
@create die: typeclasses.things.Dice
#
@desc die = Large chipped bone to make a rollable die.
#
@set dice/size = 10
# George and the Troll:4 ends here
# Transfer the dice:
# [[file:../../../projects/mud-games.org::*George and the Troll][George and the Troll:5]]
nick diceto $1 = @teleport dice = $1
# George and the Troll:5 ends here
# Adjust a characters money:
# [[file:../../../projects/mud-games.org::*George and the Troll][George and the Troll:6]]
@nick pouch $1 = py me.search("$1").create_pouch("pouch", "small, leather pouch", me)
#
@nick purse $1 = py me.search("$1").create_pouch("purse", "small, leather purse", me)
#
@nick gold $1 $2 = py me.search("$1").adjust_coins($2)
#
@nick gold $1 = py me.search("$1").how_many_coins()
# George and the Troll:6 ends here
# The Game Phrases
# Make them =nicks= to make it really easy to type them.
# [[file:../../../projects/mud-games.org::*The Game Phrases][The Game Phrases:1]]
@nick play = say Want to play |yTrollsess and Hobbitsess|n? It fun!
#
@nick play $1 = say/to $1 = Want to play |yTrollsess and Hobbitsess|n? It fun!
#
@nick bet = say What you want to bet?
#
@nick bet $1 = say/to $1 = What you want to bet?
#
@nick start = say Me start game. Me set |wknee|n. Bigger the knee, the more me give you. You roll lower, me keep your coins.
#
@nick next = say Now you |groll|n dice.
#
@nick next $1 = say/to $1 = Now you |groll|n dice.
#
@nick one = say << Hrrm, ^ Goood, ^ Mmmm, ^ >> Me got one! Me kick hobbitsess. Me won.
@nick maw = say << Hrrm, ^ Goood, ^ Mmmm, ^ >> You rolled too high! Me eatsess hobbitsess. Me won.
#
@nick two = say << Hrrm, ^ Ugh ^ Mmmm, ^ >> Me no like snake eyesess. No one win.
# The Game Phrases:1 ends here