def GetWalkables(party, charid): # get the current tile tile = Character.Coords(party, charid) # recursively add walkables tiles to the list walkables = [tile] for i in range(1, party['chars'][charid]['move'] + 1): walkables.extend(getadjacentwalkables(party, charid, walkables)) # remove current tile from the list filtered_walkables = [] for walkable in walkables: if not walkable == tile: filtered_walkables.append(walkable) walkables = filtered_walkables # remove tiles containing characters from the list filtered_walkables = [] for walkable in walkables: x, y, z = walkable if not party['map']['tiles'][x][y][z].has_key('char'): filtered_walkables.append(walkable) walkables = filtered_walkables return walkables
def execute(server, iterator, source): charid = iterator.getString() x2 = iterator.getUint8() y2 = iterator.getUint8() z2 = iterator.getUint8() party = server.parties[server.sessions[source]['party']] orig = Character.Coords(party, charid) x1 = orig[0] y1 = orig[1] z1 = orig[2] path = Move.GetPath(party, charid, x1, y1, z1, x2, y2, z2) walkables = Move.GetWalkables(party, charid) del party['map']['tiles'][x1][y1][z1]['char'] party['map']['tiles'][x2][y2][z2]['char'] = charid party['chars'][charid]['direction'] = Move.GetNewDirection(x1, y1, x2, y2) party['chars'][charid]['canmove'] = False server.send.MOVED(charid, x2, y2, z2, source) for playerid, playerlogin in enumerate(party['players']): if playerid != server.sessions[source]['player']: server.send.MOVED_PASSIVE(charid, walkables, path, server.players[playerlogin])
def execute(server, iterator, source): charid = iterator.getString() x2 = iterator.getUint8() y2 = iterator.getUint8() z2 = iterator.getUint8() party = server.parties[server.sessions[source]['party']] orig = Character.Coords(party, charid) x1 = orig[0] y1 = orig[1] z1 = orig[2] path = Move.GetPath(party, charid, x1, y1, z1, x2, y2, z2) server.send.PATH(charid, orig, party['chars'][charid]['direction'], (x2, y2, z2), path, source)
def GetAttackables(party, charid): x1, y1, z1 = Character.Coords(party, charid) attackables = [] for x2, y2 in ((x1 - 1, y1), (x1 + 1, y1), (x1, y1 - 1), (x1, y1 + 1)): try: t2 = party['map']['tiles'][x2][y2] if t2 and x2 >= 0 and y2 >= 0: for z2, t3 in enumerate(t2): if t3 and t3['walkable'] and t3[ 'selectable'] and math.fabs(z2 - z1) <= 4: attackables.append((x2, y2, z2)) except: pass return attackables
def IsAttackable(party, charid1, charid2): return Character.Coords(party, charid2) in GetAttackables(party, charid1)