Esempio n. 1
0
	def process(self):
		res = lib.process(self.duel)
		l = lib.get_message(self.duel, ffi.cast('byte *', self.buf))
		data = ffi.unpack(self.buf, l)
		self.cm.call_callbacks('debug', event_type='process', result=res, data=data.decode('latin1'))
		data = self.process_messages(data)
		return res
Esempio n. 2
0
def process_duel_replay(duel):
    res = lib.process(duel.duel)
    l = lib.get_message(duel.duel, ffi.cast('byte *', duel.buf))
    data = ffi.unpack(duel.buf, l)
    cb = duel.cm.callbacks
    duel.cm.callbacks = collections.defaultdict(list)

    def tp(t):
        duel.tp = t

    duel.cm.register_callback('new_turn', tp)

    def recover(player, amount):
        duel.lp[player] += amount

    def damage(player, amount):
        duel.lp[player] -= amount

    def tag_swap(player):
        c = duel.players[player]
        n = duel.tag_players[player]
        duel.players[player] = n
        duel.watchers[player] = c
        duel.tag_players[player] = c

    duel.cm.register_callback('recover', recover)
    duel.cm.register_callback('damage', damage)
    duel.cm.register_callback('tag_swap', tag_swap)
    duel.process_messages(data)
    duel.cm.callbacks = cb
    return data