This commit is contained in:
jona605a
2020-08-04 10:24:44 +02:00
32 changed files with 853 additions and 24332 deletions

View File

@ -1,11 +1,16 @@
"""A collection of all Gwendolyn functions."""
__all__ = ["helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToNumber", "fiarReactionTest", "deleteGame", "stopServer", "checkBalance", "giveMoney", "addMoney", "triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "spellFunc", "monsterFunc", "nameGen", "tavernGen", "movieFunc", "roll_dice", "parseChar", "parseRoll", "critRoll", "parseDestiny"]
from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer
from .swfuncs import *
from .games import checkBalance, giveMoney, addMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI
from .lookup import *
from .lookup import spellFunc, monsterFunc
from .other import *
from .other import nameGen, tavernGen, movieFunc
from .games import *
from .roll import roll_dice
from .swfuncs import parseChar, parseRoll, parseDestiny, critRoll
from .roll import *

View File

@ -1,3 +1,7 @@
"""Functions for games Gwendolyn can play."""
__all__ = ["checkBalance", "giveMoney", "addMoney","triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI"]
from .money import checkBalance, giveMoney, addMoney
from .trivia import triviaCountPoints, triviaStart, triviaAnswer
from .blackjack import blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit

View File

@ -146,7 +146,7 @@ def blackjackContinue(channel):
data["blackjack games"][channel]["user hands"][user]["hit"] = False
if data["blackjack games"][channel]["user hands"][user]["split"]:
if data["blackjack games"][channel]["user hands"][user]["split"] > 0:
if data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] == False:
data["blackjack games"][channel]["user hands"][user]["other hand"]["standing"] = True
@ -160,6 +160,34 @@ def blackjackContinue(channel):
data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] = False
if data["blackjack games"][channel]["user hands"][user]["split"] > 1:
if data["blackjack games"][channel]["user hands"][user]["third hand"]["hit"] == False:
data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] = True
if data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] == False:
allStanding = False
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["third hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["third hand"]["doubled"]:
data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] = True
else:
preAllStanding = False
data["blackjack games"][channel]["user hands"][user]["third hand"]["hit"] = False
if data["blackjack games"][channel]["user hands"][user]["split"] > 2:
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hit"] == False:
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] = True
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] == False:
allStanding = False
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["fourth hand"]["doubled"]:
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] = True
else:
preAllStanding = False
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hit"] = False
if allStanding:
data["blackjack games"][channel]["all standing"] = True
with open("resources/games/games.json", "w") as f:
@ -190,17 +218,19 @@ def blackjackHit(channel,user,handNumber = 0):
data = json.load(f)
if user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
otherHand = True
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to hit without specifying which hand")
return "You have to specify the hand you're hitting with."
@ -219,8 +249,12 @@ def blackjackHit(channel,user,handNumber = 0):
if handValue > 21:
hand["busted"] = True
if otherHand:
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
elif handNumber == 4:
data["blackjack games"][channel]["user hands"][user]["fourth hand"] = hand
else:
data["blackjack games"][channel]["user hands"][user] = hand
@ -234,10 +268,18 @@ def blackjackHit(channel,user,handNumber = 0):
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" is already standing")
@ -258,31 +300,31 @@ def blackjackDouble(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
correctRound = 1
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
otherHand = True
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to double without specifying which hand")
return "You have to specify the hand you're doubling down.",""
else:
logThis(user+" tried to double without specifying which hand")
return "You have to specify the hand you're doubling down.",""
correctRound = 2
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
if data["blackjack games"][channel]["round"] == correctRound:
if len(hand["hand"]) == 2:
bet = hand["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
@ -300,8 +342,12 @@ def blackjackDouble(channel,user,handNumber = 0):
if handValue > 21:
hand["busted"] = True
if otherHand:
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
elif handNumber == 4:
data["blackjack games"][channel]["user hands"][user]["fourth hand"] = hand
else:
data["blackjack games"][channel]["user hands"][user] = hand
@ -314,10 +360,18 @@ def blackjackDouble(channel,user,handNumber = 0):
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return "Adding another "+str(bet)+" GwendoBucks to "+user+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
@ -342,17 +396,19 @@ def blackjackStand(channel,user,handNumber = 0):
data = json.load(f)
if user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
otherHand = True
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to hit without specifying which hand")
return "You have to specify the hand you're hitting with."
@ -374,10 +430,18 @@ def blackjackStand(channel,user,handNumber = 0):
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" is already standing")
@ -393,79 +457,136 @@ def blackjackStand(channel,user,handNumber = 0):
return "You have to enter the game before you can stand"
# When players try to split
def blackjackSplit(channel,user):
def blackjackSplit(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if data["blackjack games"][channel]["round"] > 0:
if data["blackjack games"][channel]["user hands"][user]["hit"] == False:
if data["blackjack games"][channel]["user hands"][user]["standing"] == False:
if data["blackjack games"][channel]["round"] == 1:
firstCard = calcHandValue([data["blackjack games"][channel]["user hands"][user]["hand"][0]])
secondCard = calcHandValue([data["blackjack games"][channel]["user hands"][user]["hand"][1]])
if firstCard == secondCard:
bet = data["blackjack games"][channel]["user hands"][user]["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
data["blackjack games"][channel]["user hands"][user]["hit"] = True
data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] = True
data["blackjack games"][channel]["user hands"][user]["split"] = True
data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"] = data["blackjack games"][channel]["user hands"][user]["bet"]
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(data["blackjack games"][channel]["user hands"][user]["hand"].pop(1))
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(drawCard(channel))
data["blackjack games"][channel]["user hands"][user]["hand"].append(drawCard(channel))
handValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"])
otherHandValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"])
if handValue > 21:
data["blackjack games"][channel]["user hands"][user]["busted"] = True
elif handValue == 21:
data["blackjack games"][channel]["user hands"][user]["blackjack"] = True
if otherHandValue > 21:
data["blackjack games"][channel]["user hands"][user]["other hand"]["busted"] = True
elif otherHandValue == 21:
data["blackjack games"][channel]["user hands"][user]["other hand"]["blackjack"] = True
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
roundDone = True
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" doesn't have enough GwendoBucks")
return "You don't have enough GwendoBucks",""
else:
logThis(user+" tried to split 2 different cards")
return "Your cards need to have the same value to split",""
else:
logThis(user+" tried to split on round "+data["blackjack games"][channel]["round"])
return "You can only split on the first round",""
else:
logThis(user+" is already standing")
return "You can't split when you're standing",""
else:
logThis(user+" has already hit this round")
return "You've already hit this round",""
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
newHand = data["blackjack games"][channel]["user hands"][user]["other hand"]
handNumber = 0
otherHand = 2
else:
logThis(user+" tried to split on the 0th round")
return "You can't split before you see your cards",""
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
else:
logThis(user+" tried to hit without specifying which hand")
return "You have to specify the hand you're hitting with."
if data["blackjack games"][channel]["user hands"][user]["split"] == 1:
newHand = data["blackjack games"][channel]["user hands"][user]["third hand"]
otherHand = 3
else:
newHand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
otherHand = 4
else:
logThis(user+" tried to split without specifying which hand")
return "You have to specify the hand you're splitting.",""
if data["blackjack games"][channel]["user hands"][user]["split"] < 3:
if data["blackjack games"][channel]["round"] != 0:
if hand["hit"] == False:
if hand["standing"] == False:
if len(hand["hand"]) == 2:
firstCard = calcHandValue([hand["hand"][0]])
secondCard = calcHandValue([hand["hand"][1]])
if firstCard == secondCard:
bet = hand["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
hand["hit"] = True
newHand["hit"] = True
newHand = {
"hand":[],"bet":0,"standing":False,"busted":False,
"blackjack":False,"hit":True,"doubled":False}
newHand["bet"] = hand["bet"]
newHand["hand"].append(hand["hand"].pop(1))
newHand["hand"].append(drawCard(channel))
hand["hand"].append(drawCard(channel))
handValue = calcHandValue(hand["hand"])
otherHandValue = calcHandValue(newHand["hand"])
if handValue > 21:
hand["busted"] = True
elif handValue == 21:
hand["blackjack"] = True
if otherHandValue > 21:
newHand["busted"] = True
elif otherHandValue == 21:
newHand["blackjack"] = True
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
else:
data["blackjack games"][channel]["user hands"][user] = hand
if otherHand == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = newHand
elif otherHand == 4:
data["blackjack games"][channel]["user hands"][user]["fourth hand"] = newHand
else:
data["blackjack games"][channel]["user hands"][user]["other hand"] = newHand
data["blackjack games"][channel]["user hands"][user]["split"] += 1
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
roundDone = True
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" doesn't have enough GwendoBucks")
return "You don't have enough GwendoBucks",""
else:
logThis(user+" tried to split 2 different cards")
return "Your cards need to have the same value to split",""
else:
logThis(user+" tried to split later than they could")
return "You can only split on the first round",""
else:
logThis(user+" is already standing")
return "You can't split when you're standing",""
else:
logThis(user+" has already hit this round")
return "You've already hit this round",""
else:
logThis(user+" tried to split on the 0th round")
return "You can't split before you see your cards",""
else:
logThis(user+" tried to split more than three times")
return "You can only split 3 times",""
# Player enters the game and draws a hand
def blackjackPlayerDrawHand(channel,user,bet):
@ -491,15 +612,11 @@ def blackjackPlayerDrawHand(channel,user,bet):
if handValue == 21:
data["blackjack games"][channel]["user hands"][user] = {"hand":playerHand,
"bet":bet,"standing":False,"busted":False,"blackjack":True,"hit":True,
"doubled":False,"split":False,"other hand":{
"hand":[],"bet":0,"standing":False,"busted":False,"blackjack":False,"hit":True,
"doubled":False}}
"doubled":False,"split":0,"other hand":{},"third hand":{},"fourth hand":{}}
else:
data["blackjack games"][channel]["user hands"][user] = {"hand":playerHand,
"bet":bet,"standing":False,"busted":False,"blackjack":False,"hit":True,
"doubled":False,"split":False,"other hand":{
"hand":[],"bet":0,"standing":False,"busted":False,"blackjack":False,"hit":True,
"doubled":False}}
"doubled":False,"split":0,"other hand":{},"third hand":{},"fourth hand":{}}
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
@ -560,69 +677,32 @@ def blackjackFinish(channel):
data = json.load(f)
dealerValue = calcHandValue(data["blackjack games"][channel]["dealer hand"])
reason = ""
dealerBlackjack = data["blackjack games"][channel]["dealer blackjack"]
dealerBusted = data["blackjack games"][channel]["dealer busted"]
for user in data["blackjack games"][channel]["user hands"]:
winnings = -1 * data["blackjack games"][channel]["user hands"][user]["bet"]
if data["blackjack games"][channel]["user hands"][user]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason = "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["busted"]:
reason = "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason = "(dealer busted)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) > dealerValue:
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["bet"]
reason = "(highest value)"
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) == dealerValue:
reason = "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["bet"]
else:
reason = "(highest value)"
try:
for user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"]:
winnings -= data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
if data["blackjack games"][channel]["user hands"][user]["other hand"]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["other hand"]["busted"]:
reason += "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason += "(dealer busted)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"]) > dealerValue:
reason += "(highest value)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"]) == dealerValue:
reason += "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
try:
winnings, netWinnings, reason = calcWinnings(data["blackjack games"][channel]["user hands"][user],dealerValue,True,dealerBlackjack,dealerBusted)
except:
logThis("Error calculating winnings for "+str(user)+" (error code 1312)")
if winnings < 0:
if winnings == -1:
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n"
else:
reason += "(highest value)"
if winnings < 0:
if winnings == -1:
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n"
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n"
else:
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n"
else:
if winnings == 1:
finalWinnings += user+" won "+str(winnings)+" GwendoBuck "+reason+"\n"
else:
finalWinnings += user+" won "+str(winnings)+" GwendoBucks "+reason+"\n"
netWinnings = winnings + data["blackjack games"][channel]["user hands"][user]["bet"] + data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
if winnings == 1:
finalWinnings += user+" won "+str(winnings)+" GwendoBuck "+reason+"\n"
else:
finalWinnings += user+" won "+str(winnings)+" GwendoBucks "+reason+"\n"
money.addMoney(user,netWinnings)
money.addMoney(user,netWinnings)
except:
logThis("Error calculating winnings (error code 1311)")
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -633,3 +713,56 @@ def blackjackFinish(channel):
json.dump(data,f,indent=4)
return finalWinnings
def calcWinnings(hand, dealerValue, topLevel, dealerBlackjack, dealerBusted):
logThis("Calculating winnings")
reason = ""
bet = hand["bet"]
winnings = -1 * bet
netWinnings = 0
handValue = calcHandValue(hand["hand"])
if hand["blackjack"] and dealerBlackjack == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * bet)
netWinnings += math.floor(2.5 * bet)
elif dealerBlackjack:
reason += "(dealer blackjack)"
elif hand["busted"]:
reason += "(busted)"
else:
if dealerBusted:
reason = "(dealer busted)"
winnings += 2 * bet
netWinnings += 2 * bet
elif handValue > dealerValue:
winnings += 2 * bet
netWinnings += 2 * bet
reason = "(highest value)"
elif handValue == dealerValue:
reason = "(pushed)"
winnings += bet
netWinnings += bet
else:
reason = "(highest value)"
if topLevel:
if hand["split"] >= 1:
winningsTemp, netWinningsTemp, reasonTemp = calcWinnings(hand["other hand"],dealerValue,False,dealerBlackjack,dealerBusted)
winnings += winningsTemp
netWinnings += netWinningsTemp
reason += reasonTemp
if hand["split"] >= 2:
winningsTemp, netWinningsTemp, reasonTemp = calcWinnings(hand["third hand"],dealerValue,False,dealerBlackjack,dealerBusted)
winnings += winningsTemp
netWinnings += netWinningsTemp
reason += reasonTemp
if hand["split"] >= 3:
winningsTemp, netWinningsTemp, reasonTemp = calcWinnings(hand["fourth hand"],dealerValue,False,dealerBlackjack,dealerBusted)
winnings += winningsTemp
netWinnings += netWinningsTemp
reason += reasonTemp
return winnings, netWinnings, reason

View File

@ -1,4 +1,4 @@
import json, random
import json
from PIL import Image, ImageDraw, ImageFont
@ -33,7 +33,21 @@ def drawImage(channel):
key, value = list(hands.items())[x]
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
if value["split"]:
if value["split"] == 3:
table.paste(userHand,(32-borderSmol+(384*placement[x]),280-borderSmol),userHand)
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userOtherHand)
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userOtherHand)
userFourthHand = drawHand(value["fourth hand"]["hand"],False,value["fourth hand"]["busted"],value["fourth hand"]["blackjack"])
table.paste(userFourthHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
elif value["split"] == 2:
table.paste(userHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userHand)
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userOtherHand)
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
elif value["split"] == 1:
table.paste(userHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userHand)
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)

View File

@ -8,7 +8,7 @@ def checkBalance(user):
logThis("checking "+user+"'s account balance")
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if user in data["users"]:
return data["users"][user]
else: return 0

View File

@ -1 +1,5 @@
"""Gwendolyn functions for looking things up."""
__all__ = ["spellFunc", "monsterFunc"]
from .lookupFuncs import spellFunc, monsterFunc

View File

@ -1,5 +1,5 @@
import math
import discord
#import discord
import json
from funcs import cap, logThis
@ -24,9 +24,9 @@ def monsterFunc(command):
return("I don't know that monster... (error code 601)","","","","","")
else:
# Opens "mensters.json"
data = json.load(open('resources/monsters.json', encoding = "utf8"))
data = json.load(open('resources/lookup/monsters.json', encoding = "utf8"))
for monster in data:
if str(command) == monster["name"]:
if "name" in monster and str(command) == monster["name"]:
logThis("Found it!")
# Looks at the information about the monster and returns that information
@ -125,7 +125,7 @@ def spellFunc(command):
logThis("Looking up "+command)
# Opens "spells.json"
data = json.load(open('resources/spells.json', encoding = "utf8"))
data = json.load(open('resources/lookup/spells.json', encoding = "utf8"))
if str(command) in data:
logThis("Returning spell information")
spell_output = ("***"+str(command)+"***\n*"+str(data[str(command)]["level"])+" level "+str(data[str(command)]["school"])+"\nCasting Time: "+str(data[str(command)]["casting_time"])+"\nRange: "+str(data[str(command)]["range"])+"\nComponents: "+str(data[str(command)]["components"])+"\nDuration: "+str(data[str(command)]["duration"])+"*\n \n"+str(data[str(command)]["description"]))

View File

@ -1,16 +1,12 @@
import lxml.etree # Used by imageFunc
import re # Used by roll_dice
import datetime # Used by helloFunc
import json # Used by spellFunc
#import random # Used by imageFunc
import random # Used by imageFunc
import urllib # Used by imageFunc
import imdb # Used by movieFunc
import time # Used for logging
import logging # Used for... you know... logging
import wikia # Used by findWikiPage
import os
from .roll import dice
import os # Used by makeFiles
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
@ -54,29 +50,32 @@ def helloFunc(author):
# Finds a random picture online
def imageFunc():
# Picks a type of camera, which decides the naming scheme
cams = ("one","two","three","four")
cam = random.choice(cams)
logThis("Chose cam type "+cam)
if cam == "one":
a = str(random.randint(0 ,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("img_"+a+b+c+d)
elif cam == "two":
a = str(random.randint(2012,2016))
b = str(random.randint(1,12)).zfill(2)
c = str(random.randint(1,29)).zfill(2)
search = ("IMG_"+a+b+c)
elif cam == "three":
a = str(random.randint(1,500)).zfill(4)
search = ("IMAG_"+a)
elif cam == "four":
a = str(random.randint(0,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("DSC_"+a+b+c+d)
try:
cams = ("one","two","three","four")
cam = random.choice(cams)
logThis("Chose cam type "+cam)
if cam == "one":
a = str(random.randint(0 ,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("img_"+a+b+c+d)
elif cam == "two":
a = str(random.randint(2012,2016))
b = str(random.randint(1,12)).zfill(2)
c = str(random.randint(1,29)).zfill(2)
search = ("IMG_"+a+b+c)
elif cam == "three":
a = str(random.randint(1,500)).zfill(4)
search = ("IMAG_"+a)
elif cam == "four":
a = str(random.randint(0,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("DSC_"+a+b+c+d)
except:
logThis("error picking camera type (error code 702)")
logThis("Searching for "+search)
@ -138,11 +137,11 @@ def findWikiPage(search : str):
def makeFiles():
# Creates swcharacters.json if it doesn't exist
try:
f = open("resources/swcharacters.json","r")
f = open("resources/starWars/swcharacters.json","r")
except:
logThis("swcharacters.json didn't exist. Making it now.")
emptyDict = {}
with open("resources/swcharacters.json","w") as f:
with open("resources/starWars/swcharacters.json","w") as f:
json.dump(emptyDict,f,indent = 4)
finally:
f.close()
@ -158,16 +157,59 @@ def makeFiles():
finally:
f.close()
# Creates monsters.json if it doesn't exist
try:
f = open("resources/lookup/monsters.json","r")
except:
logThis("monsters.json didn't exist. Making it now.")
with open("resources/lookup/lookupExamples.json") as f:
data = json.load(f)["monster"]
with open("resources/lookup/monsters.json","w") as f:
json.dump(data,f,indent = 4)
finally:
f.close()
# Creates spells.json if it doesn't exist
try:
f = open("resources/lookup/spells.json","r")
except:
logThis("spells.json didn't exist. Making it now.")
with open("resources/lookup/lookupExamples.json") as f:
data = json.load(f)["spell"]
with open("resources/lookup/spells.json","w") as f:
json.dump(data,f,indent = 4)
finally:
f.close()
# Creates destinyPoints.txt if it doesn't exist
try:
f = open("resources/destinyPoints.txt","r")
f = open("resources/starWars/destinyPoints.txt","r")
except:
logThis("destinyPoints.txt didn't exist. Making it now.")
with open("resources/destinyPoints.txt","w") as f:
with open("resources/starWars/destinyPoints.txt","w") as f:
f.write("")
finally:
f.close()
# Creates movies.txt if it doesn't exist
try:
f = open("resources/movies.txt","r")
except:
logThis("movies.txt didn't exist. Making it now.")
with open("resources/movies.txt","w") as f:
f.write("The Room")
finally:
f.close()
# Creates names.txt if it doesn't exist
try:
f = open("resources/names.txt","r")
except:
logThis("names.txt didn't exist. Making it now.")
with open("resources/names.txt","w") as f:
f.write("Gandalf")
finally:
f.close()
# Creates token.txt if it doesn't exist
try:

View File

@ -1,2 +1,6 @@
"""Misc. functions for Gwendolyn."""
__all__ = ["nameGen", "tavernGen", "movieFunc"]
from .generators import nameGen, tavernGen
from .movie import movieFunc

View File

@ -1,4 +1,4 @@
import numpy as np
#import numpy as np
import random
from funcs import logThis

View File

@ -17,7 +17,7 @@ def movieFunc():
movs.close()
except:
logThis("Problem picking the movie (error code 801)")
return("error","801","","")
return("error","804","","")
try:
logThis("Searching for "+mov)
@ -42,5 +42,5 @@ def movieFunc():
logThis("Successfully ran !movie")
return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2])
except:
logThis("Something bad happened... (error code 800)")
return("error","800","","")
logThis("Something bad happened... (error code 801)")
return("error","801","","")

View File

@ -1 +1,5 @@
"""I stole this."""
__all__ = ["roll_dice"]
from .dice import roll_dice

View File

@ -1,3 +1,7 @@
"""Functions related to the Star Wars TTRPG."""
__all__ = ["parseChar", "parseRoll", "critRoll", "parseDestiny"]
from .swchar import parseChar
from .swroll import parseRoll, critRoll
from .swdestiny import parseDestiny

View File

@ -5,7 +5,7 @@ from funcs import logThis
def getName(user : str):
logThis("Getting name for "+user+"'s character")
with open("resources/swcharacters.json", "r") as f:
with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f)
if user in data:
@ -238,7 +238,7 @@ def characterSheet(character : dict):
return name, text1+text2+"\n\n"+text3+divider+text4+"\n"+divider+text5+text6+text7+text8
def charData(user : str,cmd : str):
with open("resources/swcharacters.json", "r") as f:
with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f)
key = string.capwords(cmd.split(" ")[0])
@ -285,7 +285,7 @@ def charData(user : str,cmd : str):
cmd[1] = cmd[1][1:]
logThis("Adding "+cmd[0]+" to "+key)
data[user][key][cmd[0]] = cmd[1]
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return cmd[0]+" added to "+key+" for " + data[user]["Name"]
@ -299,18 +299,18 @@ def charData(user : str,cmd : str):
except:
logThis("Fucked that up (error code 949)")
return "Wrong data type (error code 949)"
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return cmd[0]+" added to "+key+" for " + data[user]["Name"]
elif key == "Weapons":
with open("resources/swtemplates.json", "r") as f:
with open("resources/starWars/swtemplates.json", "r") as f:
templates = json.load(f)
newWeapon = templates["Weapon"]
logThis("Adding "+cmd+" to "+key)
data[user][key][cmd] = newWeapon
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return cmd+" added to weapons for " + data[user]["Name"]
@ -332,7 +332,7 @@ def charData(user : str,cmd : str):
logThis("Trying to remove "+cmd+" from "+key)
if cmd in data[user][key]:
del data[user][key][cmd]
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
logThis("I did that")
return cmd+" removed from "+key+" from "+data[user]["Name"]
@ -356,7 +356,7 @@ def charData(user : str,cmd : str):
if type(lookUpResult) is dict:
data[user][key] = lookUpResult
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Changed " + data[user]["Name"] + "'s " + key
else:
@ -383,7 +383,7 @@ def charData(user : str,cmd : str):
logThis("Adding "+cmd+" to "+key)
beforeData = data[user][key]
data[user][key] = beforeData+ int(cmd)
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except:
@ -393,7 +393,7 @@ def charData(user : str,cmd : str):
try:
logThis("Adding "+cmd+" to "+key)
data[user][key].append(cmd)
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except:
@ -417,7 +417,7 @@ def charData(user : str,cmd : str):
logThis("Subtracting "+cmd+" from "+key)
beforeData = data[user][key]
data[user][key] = beforeData - int(cmd)
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Subtracted " + cmd + " from " + data[user]["Name"] + "'s " + key
except:
@ -432,7 +432,7 @@ def charData(user : str,cmd : str):
except:
logThis("They can only remove stuff that's actually in the list")
return "Not in list (error code 944b)"
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Removed " + cmd + " from " + data[user]["Name"] + "'s " + key
except:
@ -455,7 +455,7 @@ def charData(user : str,cmd : str):
logThis("I don't wanna tho (error code 945a)")
return "Can't do that (error code 945a)"
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd
else:
@ -487,7 +487,7 @@ def parseChar(user : str, cmd : str):
cmd = replaceSpaces(cmd)
with open("resources/swcharacters.json", "r") as f:
with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f)
if cmd == " ":
@ -504,31 +504,31 @@ def parseChar(user : str, cmd : str):
return text1, replaceWithSpaces(text2)
else:
logThis("Makin' a character for "+user)
with open("resources/swtemplates.json", "r") as f:
with open("resources/starWars/swtemplates.json", "r") as f:
templates = json.load(f)
newChar = templates["Character"]
data[user] = newChar
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "", "Character for " + user + " created"
else:
if cmd == "Purge":
logThis("Deleting "+user+"'s character")
del data[user]
with open("resources/swcharacters.json", "w") as f:
with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "", "Character for " + user + " deleted"
return "", replaceWithSpaces(str(charData(user,cmd)))
def lightsaberChar(user : str):
with open("resources/swcharacters.json", "r") as f:
with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f)
if user in data:
return data[user]["Lightsaber-characteristic"]
def userHasChar(user : str):
with open("resources/swcharacters.json", "r") as f:
with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f)
return user in data

View File

@ -7,13 +7,13 @@ def destinyNew(num : int):
roll, diceResults = swroll.roll(0,0,0,0,0,0,num)
roll = "".join(sorted(roll))
with open("resources/destinyPoints.txt","wt") as f:
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(roll)
return "Rolled for Destiny Points and got:\n"+swroll.diceResultToEmoji(diceResults)+"\n"+swroll.resultToEmoji(roll)
def destinyUse(user : str):
with open("resources/destinyPoints.txt","rt") as f:
with open("resources/starWars/destinyPoints.txt","rt") as f:
points = f.read()
if user == "Nikolaj":
@ -21,7 +21,7 @@ def destinyUse(user : str):
if 'B' in points:
points = points.replace("B","L",1)
points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f:
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
logThis("Did it")
return "Used a dark side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points)
@ -33,7 +33,7 @@ def destinyUse(user : str):
if 'L' in points:
points = points.replace("L","B",1)
points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f:
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
logThis("Did it")
return "Used a light side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points)
@ -51,7 +51,7 @@ def parseDestiny(user : str, cmd : str):
if cmd == "":
logThis("Retrieving destiny pool info")
with open("resources/destinyPoints.txt","rt") as f:
with open("resources/starWars/destinyPoints.txt","rt") as f:
return swroll.resultToEmoji(f.read())
else:
commands = cmd.upper().split(" ")

View File

@ -2,12 +2,11 @@ import random
import re
import string
import json
import os
from . import swchar
from funcs import logThis
with open("resources/swskills.json", "r") as f:
with open("resources/starWars/swskills.json", "r") as f:
skillData = json.load(f)
# Rolls the specified dice
@ -224,7 +223,7 @@ def diceToEmoji(dice : list):
# Rolls for obligation
def obligationRoll():
logThis("Rolling for obligation")
with open("resources/swcharacters.json", "r") as f:
with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f)
table = []