Esempio n. 1
0
    def r(caller):
        ints = [i - 1 for i in parse_ints(caller.text)]
        if len(ints) != len(set(ints)):
            return error(pl._("Duplicate values not allowed."))
        if any(i for i in ints if i < 1 or i > len(select_some) - 1):
            return error(pl._("Value out of range."))
        selected = [select_some[i] for i in ints]
        s = []

        for i in range(len(selected)):
            if i == len(selected) - 1:
                break
            c = selected[i]
            for j in range(i + 1, len(selected)):
                c2 = selected[j]
                for l in c.param:
                    for l2 in c2.param:
                        s.append(l + l2)

        s = sorted(set(s))

        if mode == 1 and not check(must_select + selected, val):
            return error(pl._("Levels out of range."))
        if mode == 0 and not any(
            [check_sum(selected, val - m) for m in must_select_levels]):
            return error(pl._("Selected value does not equal %d.") % (val, ))
        lst = [len(ints) + len(must_select)]
        lst.extend([0] * len(must_select))
        lst.extend(ints)
        b = bytes(lst)
        self.set_responseb(b)
        reactor.callLater(0, process_duel, self)
Esempio n. 2
0
 def r(caller):
     ints = parse_ints(caller.text)
     ints = [i & 0xffff for i in ints]
     if len(ints) != len(cards):
         return error(pl._("Please specify %d values.") % len(cards))
     if any(cards[i].counter < val for i, val in enumerate(ints)):
         return error(pl._("Values cannot be greater than counter."))
     if sum(ints) != count:
         return error(
             pl._("Please specify %d values with a sum of %d.") %
             (len(cards), count))
     bytes = struct.pack('h' * len(cards), *ints)
     self.set_responseb(bytes)
     reactor.callLater(0, process_duel, self)
Esempio n. 3
0
 def r(caller):
     if caller.text == 'c':
         self.set_responseb(bytes([255]))
         reactor.callLater(0, process_duel, self)
         return
     ints = [i - 1 for i in parse_ints(caller.text)]
     if len(ints) != len(cards):
         return error(pl._("Please enter %d values.") % len(cards))
     if len(ints) != len(set(ints)):
         return error(pl._("Duplicate values not allowed."))
     if any(i < 0 or i > len(cards) - 1 for i in ints):
         return error(
             pl._("Please enter values between 1 and %d.") % len(cards))
     self.set_responseb(bytes(ints))
     reactor.callLater(0, process_duel, self)
Esempio n. 4
0
	def f(caller):
		cds = [i - 1 for i in parse_ints(caller.text)]
		if len(cds) != len(set(cds)):
			return error(pl._("Duplicate values not allowed."))
		if (not is_tribute and len(cds) < min_cards) or len(cds) > max_cards:
			return error(pl._("Please enter between %d and %d cards.") % (min_cards, max_cards))
		if cds and (min(cds) < 0 or max(cds) > len(cards) - 1):
			return error(pl._("Invalid value."))
		buf = bytes([len(cds)])
		tribute_value = 0
		for i in cds:
			tribute_value += (cards[i].release_param if is_tribute else 0)
			buf += bytes([i])
		if is_tribute and tribute_value < min_cards:
			return error(pl._("Not enough tributes."))
		self.set_responseb(buf)
		reactor.callLater(0, process_duel, self)
Esempio n. 5
0
 def r(caller):
     ints = [i - 1 for i in parse_ints(caller.text)]
     if len(ints) != len(set(ints)):
         return error(pl._("Duplicate values not allowed."))
     if any(i for i in ints if i < 1 or i > len(select_some) - 1):
         return error(pl._("Value out of range."))
     selected = [select_some[i] for i in ints]
     s = [select_some[i].param & 0xffff for i in ints]
     if mode == 1 and (sum(s) < val or sum(s) - min(s) >= val):
         return error(pl._("Levels out of range."))
     if mode == 0 and not check_sum(selected, val - must_select_value):
         return error(pl._("Selected value does not equal %d.") % (val, ))
     lst = [len(ints) + len(must_select)]
     lst.extend([0] * len(must_select))
     lst.extend(ints)
     b = bytes(lst)
     self.set_responseb(b)
     reactor.callLater(0, process_duel, self)
Esempio n. 6
0
 def r(caller):
     ints = parse_ints(caller.text)
     if not ints or ints[0] not in opts:
         return prompt()
     self.set_responsei(opts.index(ints[0]))
     reactor.callLater(0, process_duel, self)