def start(self): npc = get_npc(self.session, self.parameters.npc_slug) direction = self.parameters.direction if direction not in dirs2: if direction == "player": target = self.session.player else: target = get_npc(self.session, direction) direction = get_direction(npc.tile_pos, target.tile_pos) npc.facing = direction
def start(self): npc = get_npc(self.session, self.parameters.npc_slug) def buy_menu(): self.session.client.pop_state() self.session.client.push_state( "ShopMenuState", buyer=self.session.player, seller=npc, ) def sell_menu(): self.session.client.pop_state() self.session.client.push_state( "ShopMenuState", buyer=None, seller=self.session.player, ) var_menu = [ ("Buy", "Buy", buy_menu), ("Sell", "Sell", sell_menu), ] return self.session.client.push_state("ChoiceState", menu=var_menu, escape_key_exits=True)
def start(self): npc = get_npc(self.session, self.parameters.npc_slug) if self.parameters.inventory_slug == "None": npc.inventory = {} return entry = db.database["inventory"][self.parameters.inventory_slug] npc.inventory = decode_inventory(self.session, npc, entry)
def start(self): npc = get_npc(self.session, self.parameters.npc_slug) if self.parameters.inventory_slug is None: return npc.inventory.update( decode_inventory(self.session, npc, db.database["inventory"][self.parameters.inventory_slug] ) )
def start(self): npc_slug = self.raw_parameters[0] self.npc = get_npc(self.session, npc_slug) if self.npc is None: return path = list(parse_path_parameters(self.npc.tile_pos, self.raw_parameters[1:])) path.reverse() self.npc.path = path self.npc.next_waypoint()
def start(self): # Get the parameters to determine what direction the player will face. direction = self.parameters.direction if direction not in dirs2: target = get_npc(self.session, direction) direction = get_direction(self.session.player.tilepos, target.tilepos) # If we're doing a transition, only change the player's facing when we've reached the apex # of the transition. world_state = self.session.client.get_state_by_name("WorldState") if world_state.in_transition: world_state.delayed_facing = direction else: self.session.player.facing = direction
def test(self, session, condition): """ Checks to see if an npc is at a current position on the map. :param session: The session object :param condition: A dictionary of condition details. See :py:func:`core.map.Map.loadevents` for the format of the dictionary. :type session: tuxemon.core.session.Session :type condition: Dictionary :rtype: Boolean :returns: True or False **Examples:** >>> condition.__dict__ { "type": "npc_at", "parameters": [ "npc_maple", "6", "9" ], "width": 1, "height": 1, "operator": "is", "x": 6, "y": 9, ... } """ player = get_npc(session, condition.parameters[0]) if not player: return False # Get the condition's rectangle area. If we're on a tile in that area, then this condition # should return True. area_x = range(condition.x, condition.x + condition.width) area_y = range(condition.y, condition.y + condition.height) # If the player is at the coordinates and the operator is set to true then return true if round(player.tile_pos[0]) in area_x and round( player.tile_pos[1]) in area_y: return True # If the player is at the coordinates and the operator is set to false then return false else: return False
def start(self): def set_variable(var_value): player.game_variables[self.parameters.variable] = var_value self.session.client.pop_state() # perform text substitutions choices = replace_text(self.session, self.parameters.choices) player = get_npc(self.session, "player") # make menu options for each string between the colons var_list = choices.split(":") var_menu = list() for val in var_list: text = T.translate(val) var_menu.append((text, text, partial(set_variable, val))) self.open_choice_dialog(self.session, var_menu)
def test(self, session, condition): """ Checks to see where an NPC is facing :param session: The session object :param condition: A dictionary of condition details. See :py:func:`core.map.Map.loadevents` for the format of the dictionary. :type session: tuxemon.core.session.Session :type condition: Dictionary :rtype: Boolean :returns: True or False Valid Parameters: npc_slug, direction ("up", "down", "left" or "right") **Examples:** >>> condition.__dict__ { "type": "npc_facing", "parameters": [ "npc_maple", "up" ], "width": 1, "height": 1, "operator": "is", "x": 6, "y": 9, ... } """ player = get_npc(session, condition.parameters[0]) if not player: return False facing = condition.parameters[1] if player.facing == facing: return True else: return False
def start(self): npc = get_npc(self.session, self.parameters.npc_slug) world = self.session.client.get_state_by_name("WorldState") def move(): # Don't interrupt existing movement if npc.moving or npc.path: return # Suspend wandering if a dialog window is open # TODO: this should only be done for the NPC the player is conversing with, not everyone for state in self.session.client.active_states: if state.name == "DialogState": return # Choose a random direction that is free and walk toward it origin = (int(npc.tile_pos[0]), int(npc.tile_pos[1])) exits = world.get_exits(origin) if exits: npc.path = [random.choice(exits)] npc.next_waypoint() def schedule(): # The timer is randomized between 0.5 and 1.0 of the frequency parameter # Frequency can be set to 0 to indicate that we want to stop wandering world.remove_animations_of(schedule) if npc is None or self.parameters.frequency == 0: return else: frequency = 1 if self.parameters.frequency: frequency = min(5, max(0.5, self.parameters.frequency)) time = (0.5 + 0.5 * random.random()) * frequency world.task(schedule, time) move() # Schedule the first move schedule()
def test(self, session, condition): """ Checks to see if a particular NPC object exists in the current list of NPCs. :param session: The session object :param condition: A dictionary of condition details. See :py:func:`core.map.Map.loadevents` for the format of the dictionary. :type session: tuxemon.core.session.Session :type condition: Dictionary :rtype: Boolean :returns: True or False Valid Parameters: npc_slug **Examples:** >>> condition.__dict__ { "type": "npc_exists", "parameters": [ "npc_oak" ], "width": 1, "height": 1, "operator": "is_not", "x": 0, "y": 0, ... } """ world = session.client.get_state_name("WorldState") if not world: return if get_npc(session, condition.parameters[0]): return True else: return False
def test(self, session, condition): """ Checks to see the player is has a monster in his party :type session: tuxemon.core.session.Session :type condition: Dictionary :rtype: Boolean """ try: raw_op = condition.parameters[2].lower() if raw_op == '': raw_op = None except (IndexError, AttributeError): raw_op = None try: op = cmp_dict[raw_op] except KeyError: raise ValueError try: q_test = int(condition.parameters[3]) if q_test < 0: raise ValueError except IndexError: q_test = 1 # TODO: handle missing npc, etc owner_slug, item_slug = condition.parameters[:2] npc = get_npc(session, owner_slug) item_info = npc.inventory.get(item_slug) if item_info is None: # not found in inventory item_quantity = 0 else: item_quantity = item_info['quantity'] return op(item_quantity, q_test)
def start(self): npc = get_npc(self.session, self.parameters[0]) attribute = self.parameters[1] value = self.parameters[2] CommonAction.set_character_attribute(npc, attribute, value)
def start(self): npc = get_npc(self.session, self.parameters.npc_slug) npc.moverate = self.parameters.speed assert 0 < npc.moverate < 20 # just set some sane limit to avoid losing sprites
def test(self, session, condition): """ Checks to see if an NPC is facing a tile position :param session: The session object :param condition: A dictionary of condition details. See :py:func:`core.map.Map.loadevents` for the format of the dictionary. :type session: tuxemon.core.session.Session :type condition: Dictionary :rtype: Boolean :returns: True or False **Examples:** >>> condition.__dict__ { "type": "facing_tile", "parameters": ["npc_maple"], "width": 1, "height": 1, "operator": "is", "x": 6, "y": 9, ... } """ # Get the npc object from the game. npc = get_npc(session, condition.parameters[0]) if not npc: return False tiles = [(condition.x + w, condition.y + h) for w in range(0, condition.width) for h in range(0, condition.height)] tile_location = None for coordinates in tiles: # Next, we check the npc position and see if we're one tile away from # the tile. if coordinates[1] == npc.tile_pos[1]: # Check to see if the tile is to the left of the npc if coordinates[0] == npc.tile_pos[0] - 1: logger.debug("Tile is to the left of the NPC") tile_location = "left" # Check to see if the tile is to the right of the npc elif coordinates[0] == npc.tile_pos[0] + 1: logger.debug("Tile is to the right of the NPC") tile_location = "right" if coordinates[0] == npc.tile_pos[0]: # Check to see if the tile is above the npc if coordinates[1] == npc.tile_pos[1] - 1: logger.debug("Tile is above the NPC") tile_location = "up" elif coordinates[1] == npc.tile_pos[1] + 1: logger.debug("Tile is below the NPC") tile_location = "down" # Then we check to see the npc is facing the Tile if npc.facing == tile_location: return True return False
def test(self, session, condition): """ Checks to see the player is next to and facing a particular NPC :param session: The session object :param condition: A dictionary of condition details. See :py:func:`core.map.Map.loadevents` for the format of the dictionary. :type session: tuxemon.core.session.Session :type condition: Dictionary :rtype: Boolean :returns: True or False Valid Parameters: slug **Examples:** >>> condition.__dict__ { "type": "facing_npc", "parameters": [ "npc_oak" ], "width": 1, "height": 1, "operator": "is", "x": 0, "y": 0, ... } """ npc_location = None npc = get_npc(session, condition.parameters[0]) if not npc: return False # Next, we check the player position and see if we're one tile away from the NPC. if npc.tile_pos[1] == session.player.tile_pos[1]: # Check to see if the NPC is to the left of the player if npc.tile_pos[0] == session.player.tile_pos[0] - 1: logger.debug("NPC is to the left of the player") npc_location = "left" # Check to see if the NPC is to the right of the player elif npc.tile_pos[0] == session.player.tile_pos[0] + 1: logger.debug("NPC is to the right of the player") npc_location = "right" if npc.tile_pos[0] == session.player.tile_pos[0]: # Check to see if the NPC is above the player if npc.tile_pos[1] == session.player.tile_pos[1] - 1: logger.debug("NPC is above the player") npc_location = "up" elif npc.tile_pos[1] == session.player.tile_pos[1] + 1: logger.debug("NPC is below the player") npc_location = "down" # Then we check to see if we're facing the NPC if session.player.facing == npc_location: return True else: return False
def start(self): npc = get_npc(self.session, self.parameters[0]) attribute = self.parameters[1] modifier = self.parameters[2] CommonAction.modify_character_attribute(npc, attribute, modifier)
def start(self): npc = get_npc(self.session, self.parameters.npc_slug) npc.moverate = self.session.client.config.player_walkrate
def start(self): self.npc = get_npc(self.session, self.parameters.npc_slug) self.npc.pathfind( (self.parameters.tile_pos_x, self.parameters.tile_pos_y))