-adding casino scripts (Python)

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/trunk/maps@1958 282e977c-c81d-0410-88c4-b93c2d0d6712
master
temitchell 2003-01-19 21:40:58 +00:00
parent 05e257a93c
commit 7328c87be1
6 changed files with 3083 additions and 0 deletions

View File

@ -0,0 +1,49 @@
#CFGamble
# Todd Mitchell
#The Python control file for Slot Machines and other such nonsense
#Please do not put CFPython functions in this file,
#but rather place these in the calling file
import os.path
import shelve
import random
class SlotMachine:
#sets up the file that holds all the slotmachine jackpots
#make sure this points to your writable var/crossfire directory
#you can delete that file to reset all the slotmachine jackpots
slotfile = '/usr/local/CF/var/crossfire/SlotMachine_file'
slotdb = {}
def __init__(self,slotname,slotlist,minpot,maxpot):
slotdb = shelve.open(self.slotfile)
self.slotname = slotname
self.slotlist = slotlist
self.minpot = minpot
self.maxpot = maxpot
def placebet(self,amount):
if not self.slotdb.has_key(self.slotname):
self.slotdb[self.slotname] = self.minpot+amount
else:
temp=self.slotdb[self.slotname]
self.slotdb[self.slotname]=temp+amount
def payoff(self,amount):
temp=self.slotdb[self.slotname]
self.slotdb[self.slotname] = temp-amount
def spin(self,slotnum):
result=[]
while slotnum >=1:
r = self.slotlist[random.randint(0,len(self.slotlist)-1)]
result.append(r)
slotnum=slotnum-1
return result
def checkslot(self):
limit = self.slotdb[self.slotname]
if limit >= self.maxpot:
self.slotdb[self.slotname] = self.maxpot
elif limit < self.minpot:
self.slotdb[self.slotname] = self.minpot
return self.slotdb[self.slotname]

View File

@ -0,0 +1,6 @@
Casino (well so far only slotmachines)
You will need the Python Plugin running (I've only tested on 2.1 or better however).
Copy CFGamble.py to your /maps/python directory
Make sure you change the path where it will write the jackpots to your /var/crossfire directory
Modify the map links of the slotmachines to point to where your slotmachine scripts are and your slotmachine scripts to point to CFGamble.py

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
#SlotMachine configuration file
#to make a new kind of slot machine, copy this file, change the settings and point the slotmachine to the new file.
# Standard type Gold Slots
import CFPython
import sys
sys.path.append('/usr/local/CF/share/crossfire/maps/python')
import CFGamble
activator=CFPython.WhoIsActivator()
activatorname=CFPython.GetName(activator)
whoami=CFPython.WhoAmI()
#gets slot name and adds map name for unique jackpot
slotname= '%s#%s' %(CFPython.GetName(whoami),CFPython.GetMapPath(CFPython.GetMap(whoami)))
x=CFPython.GetXPosition(activator)
y=CFPython.GetYPosition(activator)
cointype = "goldcoin" #What type of coin is this slotmachine using?
minpot = 100 #Minimum slot jackpot size
maxpot = 50000 #Maxiumum slot jackpot size
cost = 1 #Price of usage
#Change the items on the slot spinner or the number of items.
slotlist = ["Club", "Staff", "Shield", "Sword", "Wand", "Scroll", "JackPot"]
spinners = 4 #How many spinners on the slotmachine?
Slots=CFGamble.SlotMachine(slotname,slotlist,minpot,maxpot)
if (CFPython.PayAmount(activator, cost*10)):#goldcoin
Slots.placebet(cost)
results = Slots.spin(spinners)
pay = 0
pot = Slots.checkslot()
CFPython.Write('%s' %results, activator, 7)
for item in results:
#match all but one - pays out by coin e.g 3 to 1 or 4 to 1
if results.count(item) == spinners-1:
if item == "Club":
pay = 1
elif item == "Staff":
pay = 2
elif item == "Shield":
pay = 3
elif item == "Sword":
pay = 4
elif item == "Wand":
pay = 5
elif item == "Scroll":
pay = 10
elif item == "JackPot":
pay = 20
else:
break
CFPython.Write("%d %ss, a minor win!" %(spinners-1,item),activator)
payoff = cost*pay
Slots.payoff(payoff)
id = CFPython.CreateObject(cointype, (x, y))
CFPython.SetQuantity(id, payoff)
message = "you win %d %s!" %(payoff,cointype)
break
elif results.count(item) == spinners:
#all match - pays out as percent of pot
CFPython.Write('%d %ss, a Major win!' %(spinners,item),activator)
if item == "Club":
pay = .10
elif item == "Staff":
pay = .15
elif item == "Shield":
pay = .25
elif item == "Sword":
pay = .25
elif item == "Wand":
pay = .35
elif item == "Scroll":
pay = .50
elif item == "JackPot":
pay = 1
payoff = pot*pay
Slots.payoff(payoff)
id = CFPython.CreateObject(cointype, (x, y))
CFPython.SetQuantity(id, payoff)
message = "you win %d %s!!" %(payoff,cointype)
break
else:
message = "Better luck next time!"
CFPython.Write(message,activator)
CFPython.Write("%d in the Jackpot, Play again?" %Slots.checkslot(),activator)
else:
CFPython.Write("Sorry, you do not have enough money",activator)

View File

@ -0,0 +1,95 @@
#SlotMachine configuration file
#to make a new kind of slot machine, copy this file, change the settings and point the slotmachine to the new file.
# Standard type Platinum Slots
import CFPython
import sys
sys.path.append('/usr/local/CF/share/crossfire/maps/python')
import CFGamble
activator=CFPython.WhoIsActivator()
activatorname=CFPython.GetName(activator)
whoami=CFPython.WhoAmI()
#gets slot name and adds map name for unique jackpot
slotname= '%s#%s' %(CFPython.GetName(whoami),CFPython.GetMapPath(CFPython.GetMap(whoami)))
x=CFPython.GetXPosition(activator)
y=CFPython.GetYPosition(activator)
cointype = "platinacoin" #What type of coin is this slotmachine using?
minpot = 300 #Minimum slot jackpot size
maxpot = 100000 #Maxiumum slot jackpot size
cost = 1 #Price of usage
#Change the items on the slot spinner or the number of items.
slotlist = ["Jester", "Lord", "Lady", "Prince", "Princess", "King", "Queen", "JackPot"]
spinners = 4 #How many spinners on the slotmachine?
Slots=CFGamble.SlotMachine(slotname,slotlist,minpot,maxpot)
if (CFPython.PayAmount(activator, cost*50)):#platinumcoin
Slots.placebet(cost)
results = Slots.spin(spinners)
pay = 0
pot = Slots.checkslot()
CFPython.Write('%s' %results, activator, 7)
for item in results:
#match all but one - pays out by coin e.g 3 to 1 or 4 to 1
if results.count(item) == spinners-1:
if item == "Jester":
pay = 1
elif item == "Lord":
pay = 2
elif item == "Lady":
pay = 3
elif item == "Prince":
pay = 4
elif item == "Princess":
pay = 5
elif item == "Queen":
pay = 10
elif item == "King":
pay = 20
elif item == "Jackpot":
pay = 25
else:
break
CFPython.Write("%d %ss, a minor win!" %(spinners-1,item),activator)
payoff = cost*pay
Slots.payoff(payoff)
id = CFPython.CreateObject(cointype, (x, y))
CFPython.SetQuantity(id, payoff)
message = "you win %d %s!" %(payoff,cointype)
break
elif results.count(item) == spinners:
#all match - pays out as percent of pot
CFPython.Write('%d %ss, a Major win!' %(spinners,item),activator)
if item == "Jester":
pay = .1
elif item == "Lord":
pay = .15
elif item == "Lady":
pay = .25
elif item == "Prince":
pay = .3
elif item == "Princess":
pay = .4
elif item == "Queen":
pay = .5
elif item == "King":
pay = .6
elif item == "JackPot":
pay = 1
payoff = pot*pay
Slots.payoff(payoff)
id = CFPython.CreateObject(cointype, (x, y))
CFPython.SetQuantity(id, payoff)
message = "you win %d %s!!" %(payoff,cointype)
break
else:
message = "Better luck next time!"
CFPython.Write(message,activator)
CFPython.Write("%d in the Jackpot, Play again?" %Slots.checkslot(),activator)
else:
CFPython.Write("Sorry, you do not have enough money",activator)

View File

@ -0,0 +1,90 @@
#SlotMachine configuration file
#to make a new kind of slot machine, copy this file, change the settings and point the slotmachine to the new file.
import CFPython
import sys
sys.path.append('/usr/local/CF/share/crossfire/maps/python')
import CFGamble
activator=CFPython.WhoIsActivator()
activatorname=CFPython.GetName(activator)
whoami=CFPython.WhoAmI()
#gets slot name and adds map name for unique jackpot
slotname= '%s#%s' %(CFPython.GetName(whoami),CFPython.GetMapPath(CFPython.GetMap(whoami)))
x=CFPython.GetXPosition(activator)
y=CFPython.GetYPosition(activator)
cointype = "silvercoin" #What type of coin is this slotmachine using?
minpot = 100 #Minimum slot jackpot size
maxpot = 50000 #Maxiumum slot jackpot size
cost = 1 #Price of usage
#Change the items on the slot spinner or the number of items.
slotlist = ["Maid", "Merchant", "Coin", "Diamond", "Imp", "Devil", "JackPot"]
spinners = 4 #How many spinners on the slotmachine?
Slots=CFGamble.SlotMachine(slotname,slotlist,minpot,maxpot)
if (CFPython.PayAmount(activator, cost)):#silvercoin
Slots.placebet(cost)
results = Slots.spin(spinners)
pay = 0
pot = Slots.checkslot()
CFPython.Write('%s' %results, activator, 7)
for item in results:
#match all but one - pays out by coin e.g 3 to 1 or 4 to 1
if results.count(item) == spinners-1:
if item == "Maid":
pay = 1
elif item == "Merchant":
pay = 2
elif item == "Coin":
pay = 3
elif item == "Diamond":
pay = 4
elif item == "Imp":
pay = 5
elif item == "Devil":
pay = 10
elif item == "JackPot":
pay = 20
else:
break
CFPython.Write("%d %ss, a minor win!" %(spinners-1,item),activator)
payoff = cost*pay
Slots.payoff(payoff)
id = CFPython.CreateObject(cointype, (x, y))
CFPython.SetQuantity(id, payoff)
message = "you win %d %s!" %(payoff,cointype)
break
elif results.count(item) == spinners:
#all match - pays out as percent of pot
CFPython.Write('%d %ss, a Major win!' %(spinners,item),activator)
if item == "Maid":
pay = .10
elif item == "Merchant":
pay = .15
elif item == "Coin":
pay = .25
elif item == "Diamond":
pay = .25
elif item == "Imp":
pay = .35
elif item == "Devil":
pay = .50
elif item == "JackPot":
pay = 1
payoff = pot*pay
Slots.payoff(payoff)
id = CFPython.CreateObject(cointype, (x, y))
CFPython.SetQuantity(id, payoff)
message = "you win %d %s!!" %(payoff,cointype)
break
else:
message = "Better luck next time!"
CFPython.Write(message,activator)
CFPython.Write("%d in the Jackpot, Play again?" %Slots.checkslot(),activator)
else:
CFPython.Write("Sorry, you do not have enough money",activator)