def __add__(self, other): if isinstance(other, str): return ManaCost(Mana.combine_mana_strings(self.cost, other)) elif isinstance(other, ManaCost): return ManaCost(Mana.combine_mana_strings(self.cost, other.cost)) elif isinstance(other, MultipleCosts): return MultipleCosts([self] + other.costs) elif isinstance(other, Cost): return MultipleCosts([self, other])
def pay(self, source, player): mp = player.manapool # Now I have enough mana - how do I distribute it? payment = mp.distribute(self._final_cost) if not payment: # Ask the player to distribute payment = Mana.convert_mana_string(player.getManaChoice(str(player.manapool), Mana.convert_to_mana_string(self._final_cost))) mp.spend(payment) self.payment = Mana.convert_to_mana_string(payment)
def precompute(self, source, player): mp = player.manapool self._X = 0 if self.hasX(): self._X = player.getX() if self.isHybrid(): cost = player.make_selection([('Pay {%s}'%c,c) for c in Mana.generate_hybrid_choices(self.cost)], 1, prompt="Choose hybrid cost") else: cost = self.cost self._final_cost = Mana.convert_mana_string(cost) self._final_cost[-1] += self._X*self._num_X self.payment = "0" return self._X >= 0
def pay(self, source, player): mp = player.manapool # Now I have enough mana - how do I distribute it? payment = mp.distribute(self._final_cost) if not payment: # Ask the player to distribute payment = Mana.convert_mana_string( player.getManaChoice( str(player.manapool), Mana.convert_to_mana_string(self._final_cost))) mp.spend(payment) self.payment = Mana.convert_to_mana_string(payment)
def precompute(self, source, player): mp = player.manapool self._X = 0 if self.hasX(): self._X = player.getX() if self.isHybrid(): cost = player.make_selection( [('Pay {%s}' % c, c) for c in Mana.generate_hybrid_choices(self.cost)], 1, prompt="Choose hybrid cost") else: cost = self.cost self._final_cost = Mana.convert_mana_string(cost) self._final_cost[-1] += self._X * self._num_X self.payment = "0" return self._X >= 0
def request_mana(self, required, manapool, is_opponent): self.is_opponent = is_opponent if not is_opponent: self.mana = self.mainmana else: self.mana = self.othermana self.activate() self.required_str = required required = Mana.convert_mana_string(required) manapool = Mana.convert_mana_string(manapool) for i, color in enumerate(self.mana.colors): nummana = manapool[i] self.old_vals[color] = nummana req_mana = required[i] spend = min(nummana, req_mana) self.mana.mana[color] -= spend self.mana.pay[color] += spend self.mana.gen_labels() self.set_cost()
def set_cost(self): def convert(val): if val == '': return 0 else: return int(val) mana = [self.mana.pay[c] for c in self.mana.colors] self.required = Mana.convert_mana_string(self.required_str) for i, val in enumerate(mana): for j in range(val): if self.required[i] == 0: self.required[-1] -= 1 else: self.required[i] -= 1 required = ''.join(["{%s}" % c for c in self.required_str]) manastr = ''.join( ["{%s}" % c for c in Mana.convert_to_mana_string(self.required)]) if manastr == "{0}": self.window.msg_controller.ask( u'The mana cost of %s is fulfilled' % required, ("OK", "Cancel")) else: msg = u"Select mana to pay %s\u2028(Total cost is %s)" % (manastr, required) # there's a layout bug if the starting element in a line isn't a glyph #msg = 'Select mana to pay remaining %s (total cost is %s)'%(manastr, required) self.window.msg_controller.notify(msg, "Cancel")
def set_cost(self): def convert(val): if val == "": return 0 else: return int(val) mana = [self.mana.pay[c] for c in self.mana.colors] self.required = Mana.convert_mana_string(self.required_str) for i, val in enumerate(mana): for j in range(val): if self.required[i] == 0: self.required[-1] -= 1 else: self.required[i] -= 1 required = "".join(["{%s}" % c for c in self.required_str]) manastr = "".join(["{%s}" % c for c in Mana.convert_to_mana_string(self.required)]) if manastr == "{0}": self.window.msg_controller.ask(u"The mana cost of %s is fulfilled" % required, ("OK", "Cancel")) else: msg = u"Select mana to pay %s\u2028(Total cost is %s)" % (manastr, required) # there's a layout bug if the starting element in a line isn't a glyph # msg = 'Select mana to pay remaining %s (total cost is %s)'%(manastr, required) self.window.msg_controller.notify(msg, "Cancel")
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: mana = [self.mana.pay[c] for c in self.mana.colors] manastr = "".join([color * int(mana[i]) for i, color in enumerate("WUBRG") if mana[i] != ""]) if mana[-1] > 0: manastr += str(mana[-1]) if manastr == "": manastr = "0" if Mana.compare_mana(self.required_str, manastr): self.window.process_action(Action.ManaSelected(manastr)) self.deactivate() return True elif symbol == key.ESCAPE: self.window.process_action(Action.CancelAction()) self.deactivate() return True
def on_key_press(self, symbol, modifiers): if symbol == key.ENTER: mana = [self.mana.pay[c] for c in self.mana.colors] manastr = ''.join([ color * int(mana[i]) for i, color in enumerate("WUBRG") if mana[i] != '' ]) if mana[-1] > 0: manastr += str(mana[-1]) if manastr == '': manastr = '0' if Mana.compare_mana(self.required_str, manastr): self.window.process_action(Action.ManaSelected(manastr)) self.deactivate() return True elif symbol == key.ESCAPE: self.window.process_action(Action.CancelAction()) self.deactivate() return True
def __init__(self, cost): super(ManaCost, self).__init__() self._mana_amt = cost self._num_X = sum([1 for symbol in cost if symbol == "X"]) self._X = 0 self._final_cost = Mana.convert_mana_string("0")
def __init__(self, cost): super(ManaCost,self).__init__() self._mana_amt = cost self._num_X = sum([1 for symbol in cost if symbol == "X"]) self._X = 0 self._final_cost = Mana.convert_mana_string("0")
def __add__(self, other): if isinstance(other, str): return ManaCost(Mana.combine_mana_strings(self.cost, other)) elif isinstance(other, ManaCost): return ManaCost(Mana.combine_mana_strings(self.cost, other.cost)) elif isinstance(other, MultipleCosts): return MultipleCosts([self]+other.costs) elif isinstance(other, Cost): return MultipleCosts([self, other])
def colors(self): return Mana.convert_to_color(self.cost) #def __eq__(self, other): # XXX compare_mana doesn't work with hybrid # if isinstance(other, str): return Mana.compare_mana(self.cost, other) # elif isinstance(other, ManaCost): return Mana.compare_mana(self.cost, other.cost) def __iadd__(self, other):
def converted_mana_cost(self): return Mana.converted_mana_cost(self.cost)
def colors(self): return Mana.convert_to_color(self.cost)
def playerInput(context, prompt=''): print_header() printer(prompt) process = context['process'] action = False if context.get("get_ability", False): while action == False: txt = text_input("What would you like to do\n(Enter to pass priority): ") if not txt: action = process(Action.PassPriority()) else: try: cardnum = int(txt) card = card_map.get(cardnum, None) if card: action = process(Action.CardSelected(card)) printer("You selected %s in %s"%(card, card.zone)) except: pass if action == False: printer("Invalid action") elif context.get("get_target", False): while action == False: txt = text_input("Select target (P# for player): ").upper() if not txt: action = process(Action.PassPriority()) elif txt == "/": action = process(Action.CancelAction()) else: if txt[0] == "P": try: pnum = int(txt[1:]) if pnum < len(Keeper.players): action = process(Action.PlayerSelected(Keeper.players[pnum])) except: pass else: try: cardnum = int(txt) card = card_map.get(cardnum, None) if card: action = process(Action.CardSelected(card)) printer("You selected %s in %s"%(card, card.zone)) except: pass if action == False: printer("Invalid target") elif context.get("get_cards", False): sellist = context['list'] numselections = context['numselections'] required = context['required'] from_zone = context['from_zone'] from_player = context['from_player'] check_card = context['check_card'] printer("Choose from %s"%', '.join(map(str, sellist))) elif context.get("reveal_card", False): sellist = context['cards'] from_zone = context['from_zone'] from_player = context['from_player'] printer.indent() printer("%s reveals: %s"%(from_player, ', '.join(map(str,sellist)))) printer.unindent() action = True elif context.get("get_selection", False): sellist = context['list'] numselections = context['numselections'] required = context['required'] msg = context['msg'] printer.indent() while action is False: map(printer, ["%d) %s"%(o[1], o[0]) for o in sellist]) txt = text_input(msg+":") if txt: try: num = int(txt) if num < len(sellist): action = process(Action.SingleSelected(num)) except: pass printer.unindent() elif context.get("get_choice", False): msg = context['msg'] notify = context['notify'] if notify: msg += " (Hit enter to continue)" else: msg += "([Y]/N):" text = text_input(msg).upper() if notify: action = Action.OKAction() elif not text or text == "Y": action = Action.OKAction() else: action = Action.CancelAction() elif context.get("get_mana_choice", False): required = context['required'] manapool = context['manapool'] from_player = context['from_player'] while action == False: manastr = text_input("(Required: %s) Mana to use: "%required).upper() if not manastr: action = process(Action.CancelAction()) else: # Make sure it's a valid string try: Mana.convert_mana_string(manastr) if (Mana.compare_mana(required, manastr) and Mana.subset_in_pool(manapool, manastr)): action = process(Action.ManaSelected(manastr)) except: pass elif context.get("get_X", False): from_player = context['from_player'] prompt = "Enter X: " while action == False: text = text_input(prompt) if not text: action = Action.CancelAction() else: try: amount = int(text) if amount >= 0: action = Action.XSelected(amount) else: prompt = "Invalid input. Enter X: " except: prompt = "Invalid input. Enter X: " action = process(action) elif context.get("get_distribution", False): amount = context['amount'] targets = context['targets'] elif context.get("get_damage_assign", False): blocking_list = context['blocking_list'] trample = context['trample'] dump_to_replay.write(action) return action
def playerInput(context, prompt=''): print_header() printer(prompt) process = context['process'] action = False if context.get("get_ability", False): while action == False: txt = text_input( "What would you like to do\n(Enter to pass priority): ") if not txt: action = process(Action.PassPriority()) else: try: cardnum = int(txt) card = card_map.get(cardnum, None) if card: action = process(Action.CardSelected(card)) printer("You selected %s in %s" % (card, card.zone)) except: pass if action == False: printer("Invalid action") elif context.get("get_target", False): while action == False: txt = text_input("Select target (P# for player): ").upper() if not txt: action = process(Action.PassPriority()) elif txt == "/": action = process(Action.CancelAction()) else: if txt[0] == "P": try: pnum = int(txt[1:]) if pnum < len(Keeper.players): action = process( Action.PlayerSelected(Keeper.players[pnum])) except: pass else: try: cardnum = int(txt) card = card_map.get(cardnum, None) if card: action = process(Action.CardSelected(card)) printer("You selected %s in %s" % (card, card.zone)) except: pass if action == False: printer("Invalid target") elif context.get("get_cards", False): sellist = context['list'] numselections = context['numselections'] required = context['required'] from_zone = context['from_zone'] from_player = context['from_player'] check_card = context['check_card'] printer("Choose from %s" % ', '.join(map(str, sellist))) elif context.get("reveal_card", False): sellist = context['cards'] from_zone = context['from_zone'] from_player = context['from_player'] printer.indent() printer("%s reveals: %s" % (from_player, ', '.join(map(str, sellist)))) printer.unindent() action = True elif context.get("get_selection", False): sellist = context['list'] numselections = context['numselections'] required = context['required'] msg = context['msg'] printer.indent() while action is False: map(printer, ["%d) %s" % (o[1], o[0]) for o in sellist]) txt = text_input(msg + ":") if txt: try: num = int(txt) if num < len(sellist): action = process(Action.SingleSelected(num)) except: pass printer.unindent() elif context.get("get_choice", False): msg = context['msg'] notify = context['notify'] if notify: msg += " (Hit enter to continue)" else: msg += "([Y]/N):" text = text_input(msg).upper() if notify: action = Action.OKAction() elif not text or text == "Y": action = Action.OKAction() else: action = Action.CancelAction() elif context.get("get_mana_choice", False): required = context['required'] manapool = context['manapool'] from_player = context['from_player'] while action == False: manastr = text_input("(Required: %s) Mana to use: " % required).upper() if not manastr: action = process(Action.CancelAction()) else: # Make sure it's a valid string try: Mana.convert_mana_string(manastr) if (Mana.compare_mana(required, manastr) and Mana.subset_in_pool(manapool, manastr)): action = process(Action.ManaSelected(manastr)) except: pass elif context.get("get_X", False): from_player = context['from_player'] prompt = "Enter X: " while action == False: text = text_input(prompt) if not text: action = Action.CancelAction() else: try: amount = int(text) if amount >= 0: action = Action.XSelected(amount) else: prompt = "Invalid input. Enter X: " except: prompt = "Invalid input. Enter X: " action = process(action) elif context.get("get_distribution", False): amount = context['amount'] targets = context['targets'] elif context.get("get_damage_assign", False): blocking_list = context['blocking_list'] trample = context['trample'] dump_to_replay.write(action) return action