def analysePosition(gID, uID, board, pos): # analyses the player's position to see what operations need to be made on a square alert = {} alert['boolean'] = False square = board[pos] if square['category'] == 'tax': alert = pay(gID, uID, 0, square['amount'] ) #pay the bank the tax amount required on this square return alert if square["category"] == "special": if square['name'] == 'goToJail': alert = updateLocation(gID, uID, "GTJ") elif square['category'] == 'card': alert = drawCard(gID, uID) elif square['category'] == 'property': deed = r.getDeeds(gID)[square['pID']] if deed['status'] == "owned": rent = rentCalculator(gID, deed) alert = pay(gID, uID, deed['owner'], rent) alert["activity"] = "rent" return alert elif deed['status'] == "mortgaged": pass elif deed['status'] == "notOwned": player = r.getPlayers(gID)[uID] player['options'] += ["BUY"] player['options'] += ["AUCTION"] player["canBuy"] = square["pID"] r.setPlayer(gID, uID, player) return alert
def isMortgageable(gID, pID, playerNo): # returns boolean if property is mortgageable alert = {} deeds = r.getDeeds(gID) alert['value'] = False if deeds[pID]['owner'] == playerNo: for _pID in deeds: if deeds[_pID]['group'] == deeds[pID]['group']: if deeds[_pID]['buildings'] == None: alert['value'] = "CANNOT MORTGAGE. SELL PROPERTY." break return alert
def pCannotTrade(gID, jOffer, jFor): alert = {} alert["boolean"] = False if "property" in jOffer or "property" in jFor: deeds = r.getDeeds(gID) for pID in deeds: if deeds[pID] in jOffer["property"] or deeds[pID] in jFor[ "property"]: if deeds[pID]["buildings"] > 0: alert["boolean"] = True alert["alert"] = "CANNOT SELL DEVELOPED PROPERTY" return alert return alert
def payMort(json): gID = json["gID"] uID = json["uID"] pID = json['pID'] deeds = r.getDeeds(gID) deed = deeds[pID] mortgageAmount = int(deed["mortgage"] * 1.1) alert = pay(gID, uID, 0, mortgageAmount) if alert["boolean"]: ret = helpers.getReturnData(gID, uID, [], [], alert['alert']) else: deeds[pID]["status"] = "owned" r.setDeeds(gID, deeds) ret = helpers.getReturnData(gID, uID) return ret
def mortgage(json): # used to mortgage a property gID = json['gID'] uID = json['uID'] pID = json['pID'] deeds = r.getDeeds(gID) deed = deeds[pID] player = r.getPlayers(gID)[uID] mortgageable = isMortgageable(gID, pID, player['public']['number']) if mortgageable['value'] == False: deed["status"] = "mortgaged" player['money'] += deed['mortgage'] r.setPlayer(gID, uID, player) r.setDeeds(gID, deeds) ret = helpers.getReturnData(gID, uID) else: ret = helpers.getReturnData(gID, uID, [], [], mortgageable['value']) return ret
def mCannotTrade(gID, sender, receiver, jOffer, jFor): alert = {} alert["boolean"] = False sTotal = 0 rTotal = 0 if "property" in jOffer or "property" in jFor: deeds = r.getDeeds(gID) if "property" in jOffer: for pID in jOffer["property"]: if deeds[pID]["status"] == "mortgaged": sTotal += deeds[pID]["mortgage"] / 10 if "property" in jFor: for pID in jFor["property"]: if deeds[pID]["status"] == "mortgaged": rTotal += deeds[pID]["mortgage"] / 10 sMortgage = sTotal rMortgage = rTotal sTotal = 0 rTotal = 0 if "money" in jOffer: sTotal += jOffer["money"] - sMortgage if "money" in jFor: rTotal += jFor["money"] - rMortgage if rTotal != 0 or sTotal != 0: if sTotal > rTotal: if sTotal < sTotal - rTotal: alert["alert"] = "INSUFFICENT FUNDS" alert["boolean"] = True else: pass elif sTotal < rTotal: if rTotal < rTotal - sTotal: alert["alert"] = receiver['public'][ 'name'] + "CANNOT MAKE THIS DEAL AT THIS TIME" alert["boolean"] = True else: pass if not alert["boolean"]: alert["sTotal"] = sTotal alert["rTotal"] = rTotal alert["sMortgage"] = sMortgage alert["rMortgage"] = rMortgage return alert
def measureAssets(gID, uID, amountNeeded): alert = {} alert["boolean"] = False players = r.getPlayers(gID) deeds = r.getDeeds(gID) assetsTotal = 0 if players[uID]['money'] < amountNeeded: for group in players[uID]["public"]["properties"]: for pID in players[uID]["public"]["properties"][group]["owned"]: if deeds[pID]['status'] != "mortgaged": assetsTotal += (deeds[pID]["house1"] * deeds[pID]['buildings']) / 2 assetsTotal += deeds[pID]["mortgage"] assetsTotal += players[uID]['money'] if assetsTotal < amountNeeded: alert["boolean"] = True alert["alert"] = "BANKRUPT" killPlayer(gID, uID) return alert return alert
def buy(json): # if player has option to buy a certain property and chooses to buy gID = json['gID'] uID = json['uID'] pID = json["pID"] players = r.getPlayers(gID) player = players[uID] if player["canBuy"] == pID: deed = r.getDeeds(gID)[pID] alert = pay(gID, uID, 0, deed['price']) if not alert['boolean']: giveProperty(gID, uID, deed) if incrementTurn(gID): ret = helpers.getReturnData(gID, uID, [], ["BUY", "AUCTION", "ROLLED"]) else: ret = helpers.getReturnData(gID, uID, ["ROLL"], ["BUY", "AUCTION", "ROLLED"]) else: ret = helpers.getReturnData(gID, uID, [], [], alert['alert']) return ret
def close(): if hBidder == None or int(hBidder) == 0: for _uID in players: players[_uID]['options'].remove("BID") if "AUCTION" in players[_uID]["options"]: players[_uID]['options'].remove("AUCTION") if "BUY" in players[_uID]["options"]: players[_uID]['options'].remove("BUY") players[_uID]["canBuy"] = None r.setPlayers(gID, players) game['state'] = "PLAYING" r.setGame(gID, game) incrementTurn(gID) return helpers.getReturnData(gID, uID) if int(hBidder) != 0: payUID = None for _uID in players: if players[_uID]["public"]["number"] == int(hBidder): payUID = _uID break alert = pay(gID, payUID, 0, hBidAmount) if not alert['boolean']: deed = r.getDeeds(gID)[game['auction']['pID']] giveProperty(gID, payUID, deed) for _uID in players: players[_uID]['options'].remove("BID") if "AUCTION" in players[_uID]["options"]: players[_uID]['options'].remove("AUCTION") if "BUY" in players[_uID]["options"]: players[_uID]['options'].remove("BUY") players[_uID]["canBuy"] = None r.setPlayers(gID, players) game['state'] = "PLAYING" r.setGame(gID, game) incrementTurn(gID) return helpers.getReturnData(gID, uID) else: return helpers.getReturnData(gID, uID, [], [], alert['alert'])
def auction(json): # moves the game state into an auction for 30 seconds gID = json['gID'] uID = json['uID'] players = r.getPlayers(gID) player = players[uID] pID = json["pID"] if player["canBuy"] == pID: deed = r.getDeeds(gID)[pID] for _uID in players: players[_uID]['options'] += ["BID"] r.setPlayer(gID, _uID, players[_uID]) game = r.getGame(gID) game['auction'] = {} game['auction']['pID'] = pID game['auction']['highest'] = {0: deed['price'] / 2} game['auction']['out'] = [] game['lastActivity'] = helpers.getTime() game['state'] = "AUCTION" r.setGame(gID, game) ret = helpers.getReturnData(gID, uID, [], ["AUCTION", "BUY"]) return ret
def build(json, dem=False): # build/demolish gID = json['gID'] uID = json['uID'] pID = json['pID'] if canBuild(gID, uID, pID): deed = r.getDeeds(gID)[pID] cost = deed['housePrice'] if dem: incrementMoney(gID, uID, cost / 2) deed['buildings'] += 1 else: alert = pay(gID, uID, 0, cost) if alert: ret = helpers.getReturnData(gID, uID, [], [], alert) return ret deed['buildings'] += 1 setDeed(gID, uID, pID) ret = helpers.getReturnData(gID, uID) else: alert = "CANNOT BUILD" ret = helpers.getReturnData(gID, uID, [], [], alert) return ret
def canBuild(gID, uID, pID, dem=False): # returns True if a player can build/demolish deeds = r.getDeeds(gID) deed = deeds['pID'] canBuild = False if not housingShortage(gID) and hasMonopoly(gID, uID, deed['group']): canBuild = True if deed['group'] != "service" or deed['group'] != "transport": propertyBuildings = [] for _pID in deeds: if deeds[_pID]['group'] == deed['group']: propertyBuildings.append(deeds[_pID]['buildings']) canBuild = canBuild and ( max(propertyBuildings) - min(propertyBuildings) <= 1) if dem: canBuild = canBuild and (deed['buildings'] == max(propertyBuildings)) and ( deed['buildings'] != 0) else: canBuild = canBuild and (deed['buildings'] == min(propertyBuildings)) and ( deed['buildings'] != 5) return canBuild
def getReturnData(gID, uID, optionsToAdd=[], optionsToRemove=[], alert={}, card=False): ret = {} game = r.getGame(gID) players = r.getPlayers(gID) player = players[uID] ret['players'] = {} for _uID in players: ret['players'][players[_uID]['public'] ['name']] = players[_uID]['public'] if game['state'] != "LOBBY": ret['board'] = r.getBoard(gID) ret['deeds'] = r.getDeeds(gID) ret["chat"] = r.getChat(gID) ret["trade"] = {} if len(player["trade"]["recieved"]) > 0: ret["trade"]["recieved"] = player["trade"]["recieved"][0] if len(player["trade"]["sent"]) > 0: for tID in player["trade"]["sent"]: if player["trade"]["sent"][tID] == "declined": game["trade"].pop(tID, None) ret["trade"]["sent"] = player["trade"]["sent"][tID][ "declined"] + "declined your trade offer" player["trade"]["sent"].pop(tID, None) r.setPlayer(gID, uID, player) r.setGame(gID, game) break if player["trade"]["sent"][tID] == "accepted": game["trade"].pop(tID, None) ret["trade"]["sent"] = player["trade"]["sent"][tID][ "accepted"] + "accepted your trade offer" player["trade"]["sent"].pop(tID, None) r.setPlayer(gID, uID, player) r.setGame(gID, game) break if len(optionsToAdd) + len(optionsToRemove) > 0: for option in optionsToAdd: if option not in player['options']: player['options'] += [option] for option in optionsToRemove: try: if option == "BUY": player["canBuy"] = None player['options'].remove(option) except: pass r.setPlayer(gID, uID, player) ret['options'] = player['options'] if len(alert) != 0: ret['alert'] = alert if card: ret['card'] = card ret['game'] = game ret['player'] = player # if game['state'] != "LOBBY" and (game["turn"] == player["public"]["number"]): # print ("Return Data") # print("name: " + player["public"]["name"]) # print("turn: " + str(game["turn"])) # print("options: " + str(ret['options'])) # if "card" in ret: # print (card['type']) # if 'alert' in ret: # print (alert) # print("") return ret
def setDeed(gID, uID, deed): # sets deed to deeds deeds = r.getDeeds(gID) deeds[deed['pID']] = deed r.setDeeds(gID, deeds)
def tradeProp(gID, aUID, bUID, pID, aPlayer, bPlayer): deed = r.getDeeds(gID)[pID] bPlayer['public']["properties"][deed["group"]].remove(pID) r.setPlayer(gID, bUID, bPlayer) giveProperty(gID, aUID, aPlayer, deed, deed["status"])