def handle_buy_quantity(event_id, message_string, sock): if event_id == rcon_event.chat_message.value: js = json.loads(message_string) if js['Message'].startswith("mvice"): cmd = 'pm "{}" "{}" "{}"'.format( js['Name'], "provide a vice name, underscores ( _ ) for spaces, and a valid quantity ex [vices whiskey 2]", "8421376") if len(js['Message'].split(" ")) > 2: vicename = js['Message'].split(" ")[1] vicequantity = js["Message"].split(" ")[2] vice = get_vice(vicename) if vice is not None and vicequantity.isnumeric(): p = find_player(js["Name"]) if p is not None: if p.buy_vice_quantity(vicename, int(vicequantity)): cmd = 'setvice "{}" "{}" "{}"'.format( p.name, vice.v_id, p.vices[vice.v_id]) else: cmd = 'pm "{}" "Insufficient funds, you have {} :gold: and it costs {} :gold: It could also be that you have reached the maximum allowed number of this vice! [{}]" "{}"'.format( js['Name'], p.balance, vice.cost * int(vicequantity), vice.cap, "8421376") else: cmd = 'pm "{}" "Please try again after this round" "8421376"'.format( js["Name"]) send_packet(sock, cmd, rcon_receive.command.value)
def handle_gift(event_id, message_string, sock): if event_id == rcon_event.chat_message.value: # parse the json js = json.loads(message_string) # if the server message is from a player if 'PlayerID' in js and js['PlayerID'] != '-1': if js['Message'].startswith("gift"): cmd = 'pm "{}" "{}" "{}"'.format( js['Name'], "provide a vice name, underscores ( _ ) for spaces, and a valid quantity ex [gift \"coyote and bird\" whiskey 2]", "8421376") m = re.search(r"gift \"(.+?)\" (\w+) (\w+)", js["Message"]) if m is not None: try: gifter = find_player(js["Name"]) giftee = find_player(m.group(1)) v = get_vice(m.group(2)) q = int(m.group(3)) enough_money = gifter.gift_vice(v.alias[0], q) if enough_money: if giftee.vices[v.v_id] + q <= v.cap: giftee.receive_gift_vice(v.alias[0], q) cmd = 'setvice "{}" "{}" "{}"'.format( giftee.name, v.v_id, giftee.vices[v.v_id]) else: cmd = 'pm "{}" "Could not gift vice: The recipient has too many of this vice" "{}"'.format( js['Name'], "8421376") except Exception as e: print(str(e)) cmd = 'pm "{}" "Could not gift vice" "{}"'.format( js['Name'], "8421376") send_packet(sock, cmd, rcon_receive.command.value)
def buy_vice_quantity(self, keyword, quantity): vice = get_vice(keyword) if self.balance >= vice.cost * quantity: if vice.cap == -1 or self.vices[vice.v_id] + quantity <= vice.cap: self.balance -= vice.cost * quantity self.vices[vice.v_id] += quantity return True return False
def buy_vice(self, keyword): vice = get_vice(keyword) if self.balance >= vice.cost: if vice.cap != -1: if self.vices[vice.v_id] < vice.cap: self.balance -= vice.cost self.vices[vice.v_id] += 1 return True return False
def handle_check_price(event_id, message_string, sock): if event_id == rcon_event.chat_message.value: js = json.loads(message_string) if js['Message'].startswith("price"): cmd = 'pm "{}" "{}" "{}"'.format( js['Name'], "provide a vice or weapon name, use underscores ( _ ) for spaces", "8421376") vicename = js['Message'].split(" ")[1] vice = get_vice(vicename) if vice is not None: cmd = 'pm "{}" "Price is {} :gold: Cap is {}. Description: {}" "{}"'.format( js['Name'], str(vice.cost), str(vice.cap), vice_description[vice.v_id], "8421376") else: weapname = js['Message'].split(" ")[1] weap = get_weapon(weapname) if weap is not None: cmd = 'pm "{}" "Price is {} :gold: Weapon bonus is {}" "{}"'.format( js['Name'], str(weap.cost), str(weap.bonus), "8421376") send_packet(sock, cmd, rcon_receive.command.value)
def handle_buy_vice(event_id, message_string, sock): if event_id == rcon_event.chat_message.value: js = json.loads(message_string) if js['Message'].startswith("vice"): cmd = 'pm "{}" "{}" "{}"'.format( js['Name'], "provide a vice name, underscores ( _ ) for spaces", "8421376") if len(js['Message'].split(" ")) > 1: vicename = js['Message'].split(" ")[1] vice = get_vice(vicename) if vice is not None: p = find_player(js["Name"]) if p is not None: if p.buy_vice(vicename): cmd = 'setvice "{}" "{}" "{}"'.format( p.name, vice.v_id, p.vices[vice.v_id]) else: cmd = 'pm "{}" "Insufficient funds, you have {} :gold: and {} costs {} :gold:, It could also be that you have reached the maximum of this vice [{}]" "{}"'.format( js['Name'], p.balance, vice.alias[0], vice.cost, vice.cap, "8421376") else: cmd = 'pm "{}" "Please try again after this round" ""8421376""'.format( js["Name"]) send_packet(sock, cmd, rcon_receive.command.value)
def gift_vice(self, keyword, quantity): vice = get_vice(keyword) if self.balance >= vice.cost * quantity: self.balance -= vice.cost * quantity return True return False
def receive_gift_vice(self, keyword, quantity): vice = get_vice(keyword) self.vices[vice.v_id] += quantity