import time
from hermes import *
import Hack
import LLL
import Leech
def initializePrefs():
prefs.data.playsPerDay = 3
prefs.data.bbsCallsPerPlay = 10
prefs.data.leechCallsPerPlay = 3
prefs.data.bankHacksPerPlay = 3
prefs.data.unlimitedSysopPlay = True
def initializeBbs():
bbs.data.highScores = []
bbs.data.lllBulletinByline = 'Michael Alyn Miller'
bbs.data.lllBulletin = """Welcome to Leech 2000!
Leech for a whole new millenium!
Or something like that..."""
def initializeUser():
user.data.playsToday = 0
user.data.firstTimePlayed = time.localtime()
user.data.lastTimePlayed = time.localtime()
user.data.level = 1
user.data.totalMegs = 10
user.data.drivesLeftToNextLevel = 10
user.data.softwareType = 0
user.data.backupType = 0
user.data.fastBackups = 1
user.data.trojanHorses = 1
user.data.money = 10
user.data.moneyInBank = 0
def initializeInstance():
instance.data.megsLeft = user.data.totalMegs
instance.data.bankHacks = 0
instance.data.bbsCalls = 0
instance.data.leechCalls = 0
def newDay():
user.data.playsToday = 0
def callBbs():
if instance.data.bbsCalls >= prefs.data.bbsCallsPerPlay:
print
print NoticeStyle('You have already called %d BBSs this play.' % (
prefs.data.bbsCallsPerPlay))
return
clearScreen()
print 'Welcome to %s!' % (Leech.Software[user.data.softwareType].name)
print
print 'At the prompt, enter the number of the BBS you want to call. This'
print 'is also the number of hard drives you will have to crash to hack'
print 'that BBS. The larger the number, the harder the BBS will be to'
print 'defeat. But it will also be worth more if you beat it...'
while True:
print
response = textPrompt(
'Enter the number of the BBS to call (1-99, ? for list): ',
maxChars=2, forceUppercase=2, validChars='0123456789?Q')
if response == 'Q':
break
elif response == '?':
bbsList = Leech.BbsList.items()
bbsList.sort(lambda a, b: a[0] - b[0])
bbsListPages = splitPages(
bbsList, rowsPerPage=user.screenHeight - 3, numColumns=3)
firstPage = True
for pageNumber, page in enumerate(bbsListPages):
if pageNumber > 0:
pausePrompt()
clearScreen()
print Leech.HeaderStyle(
'## %-21s ## %-21s ## %-21s' % (
'BBS Name', 'BBS Name', 'BBS Name'))
print Leech.HeaderStyle(
'%s %s %s' % (
'='*24, '='*24, '='*24))
for row in page:
for number, bbs in row:
print Leech.BbsListNumberStyle('%2d' % number),
print Leech.BbsListNameStyle('%-21s' % bbs.name),
print '',
print
continue
try:
bbsToCall = int(response)
if not 0 < bbsToCall <= 99:
raise ValueError, 'Invalid BBS number.'
except ValueError:
print
print NoticeStyle('Invalid BBS number, try again.')
continue
instance.data.bbsCalls += 1
print
print PromptHeaderStyle(
'Dialing %s...' % (Leech.BbsList[bbsToCall].name))
Leech.dialModem(
Leech.BbsList[bbsToCall].phoneNumber.replace('-', ''), 2400)
Hack.hackBbs(bbsToCall)
print
Leech.hangupModem()
break
def hackLeech():
if instance.data.leechCalls >= prefs.data.leechCallsPerPlay:
print
print NoticeStyle('You have already called %d Leeches this play.' % (
prefs.data.leechCallsPerPlay))
return
print
name = textPrompt(
'Enter the name of the leech to call: ', 32, forceUppercase=True)
if not name:
print 'Aborted.'
return
try:
otherUser = bbs.users[name]
except KeyError:
print 'Unknown user.'
return
if not otherUser.data:
print 'That user is not playing Leech!'
return
if otherUser == user:
print 'You want to hack your own computer? Try FORMAT...'
return
if otherUser in external.activeUsers:
print 'That user is currently playing Leech... better wait until they logoff.'
return
instance.data.leechCalls += 1
print
print PromptHeaderStyle('Dialing %s...' % (otherUser.name))
Leech.dialModem(str(instance.randrange(2000000, 9999999)), 2400)
Hack.hackUser(otherUser)
print
Leech.hangupModem()
def resetPlayer():
print
if not yesNoPrompt(
'Format hard drive -- will erase all stats. Are you sure? '):
print 'Aborted.'
return
playsToday = user.data.playsToday
initializeUser()
initializeInstance()
user.data.playsToday = playsToday
print 'Your hard drive has been erased. You are now a complete n00b.'
def deposit():
user.data.moneyInBank += user.data.money
user.data.money = 0
print
print 'Deposit complete. %s in possession. %s in LLL bank account.' % (
formatCurrency(user.data.money, 0),
formatCurrency(user.data.moneyInBank, 0))
def withdraw():
user.data.money += user.data.moneyInBank
user.data.moneyInBank = 0
print
print 'Withdraw complete. %s in possession. %s in LLL bank account.' % (
formatCurrency(user.data.money, 0),
formatCurrency(user.data.moneyInBank, 0))
def unerase():
deletedMegs = user.data.totalMegs - instance.data.megsLeft
perMegRecoveryPrice = user.data.level * 4
if not deletedMegs:
print
print 'All of your megs are fine.'
return
print
print PromptHeaderStyle(
'You have %d deleted megs.' % (
deletedMegs))
print PromptHeaderStyle(
'It costs %s to recover each meg (%s for all megs).' % (
formatCurrency(perMegRecoveryPrice, 0),
formatCurrency(deletedMegs * perMegRecoveryPrice, 0)))
print PromptHeaderStyle(
'You have %s on you (%s in the bank).' % (
formatCurrency(user.data.money, 0),
formatCurrency(user.data.moneyInBank, 0)))
response = multipleChoicePrompt(
'Unerase [A]ll megs, [S]ome megs, or [N]o megs? ',
defaultChar='N',
choiceList = {
'A': ('All megs', 'all'),
'S': ('Some megs', 'some'),
'N': ('No megs', None),
})
if not response:
print
print 'No megs recovered.'
return
if response == 'all':
megsToRecover = deletedMegs
else:
megsToRecover = numericPrompt(
'How many megs to unerase? ',
minValue=0, maxValue=deletedMegs, requireResponse=False)
if not megsToRecover:
print
print 'No megs recovered.'
return
recoveryPrice = megsToRecover * perMegRecoveryPrice
if recoveryPrice > user.data.money:
print
print NoticeStyle(
'It costs %s to recover that many megs. You need more money!' % (
formatCurrency(recoveryPrice, 0)))
return
instance.data.megsLeft += megsToRecover
user.data.money -= recoveryPrice
print
print Style(fgGreen)('We unerased %d %s.' % (
megsToRecover, plural(megsToRecover, 'meg', 'megs')))
def quit():
print
if yesNoPrompt('Are you sure you want to exit the game? '):
instance.data.stillPlaying = False
def lllBattle():
clearScreen()
print Style(fgGreen)('Congratulations, %s!' % (user.name))
print
print 'You have become a level 31 leech. It is now time for the BIG'
print 'challenge. You have to crash the LLL computer! You have all'
print "of your megs back, but you'll need them against the LLL. If"
print 'you fail, the LLL will be mad and demote you to level 30'
print
print 'Good luck!'
instance.data.megsLeft = user.data.totalMegs
print
print PromptHeaderStyle('Dialing the LLL BBS...')
Leech.dialModem(LLL.phoneNumber, 2400)
Hack.hackLLL()
print
Leech.hangupModem()
def main():
if not prefs.data:
initializePrefs()
if not bbs.data:
initializeBbs()
printTextFile('Welcome')
if user not in external.users:
print 'Looks like you are a new leech!'
if not yesNoPrompt('Do you want to join the game? '):
return
initializeUser()
if user.data.lastTimePlayed[:3] != time.localtime()[:3]:
newDay()
unlimitedPlays = user.sysop and prefs.data.unlimitedSysopPlay
if not unlimitedPlays and user.data.playsToday >= prefs.data.playsPerDay:
print 'Hey, you ARE a leech! Only %d plays per day!' % (
prefs.data.playsPerDay)
return
user.data.playsToday += 1
user.data.lastTimePlayed = time.localtime()
initializeInstance()
Leech.printTopScores()
print
Leech.printBulletin()
print
pausePrompt()
mainMenuCommands = {
'': lambda: printTextFile('MainMenu'),
'?': lambda: printTextFile('MainMenu'),
'DIR': lambda: printTextFile('MainMenu'),
'HELP': lambda: printTextFile('Instructions'),
'LLL': LLL.menu,
'CALL': callBbs,
'HACK': hackLeech,
'FORMAT': resetPlayer,
'STATUS': Leech.printStats,
'CREDITS': lambda: printTextFile('Credits'),
'+': deposit,
'-': withdraw,
'UE': unerase,
'QUIT': quit,
}
printTextFile('MainMenu')
instance.data.stillPlaying = True
while instance.data.stillPlaying:
if user.data.level > 30:
lllBattle()
continue
print
cmdName = textPrompt(
'C:\> ', maxChars=8, autoAccept=False, forceUppercase=True)
if mainMenuCommands.has_key(cmdName):
cmd = mainMenuCommands[cmdName]
cmd()
else:
print 'Unknown command! Type ? or DIR for the menu.'
print
print 'Now returning you to an environment with even WORSE users...'
print
if __name__ == '__main__':
main()