Esempio n. 1
0
    def newGame(self, fn, root):
        """Start a new game"""

        #create the new save file
        self.savegame = save.Save(fn)

        #get the new game node from the game xml file
        newgameNode = data.getChild(root, "newgame")

        #create the map, loading connections since it's the active one
        self.map = tilemap.Tilemap(
            os.path.join(settings.path, "data",
                         data.getAttr(newgameNode, "map", data.D_STRING)))
        self.map.loadConnections()

        #create the player
        playerNode = data.getChild(root, "player")
        self.player = player.Player(
            playerNode, self.map,
            data.getAttr(newgameNode, "position", data.D_INT2LIST),
            data.getAttr(newgameNode, "level", data.D_INT))

        #if there's a new game script, run it
        script = data.getOptionalChild(newgameNode, "script")
        if script is not None:
            s = script_engine.Script(script)
            self.scriptEngine.run(s)
Esempio n. 2
0
    def newGame(self, fn, root):
        """Start a new game"""

        # create the new save file
        self.savegame = save.Save(fn)

        # get the new game node from the game xml file
        newgameNode = data.getChild(root, "newgame")

        # create the map, loading connections since it's the active one
        self.map = tilemap.Tilemap(os.path.join(settings.path, "data", data.getAttr(newgameNode, "map", data.D_STRING)))
        self.map.loadConnections()

        # create the player
        playerNode = data.getChild(root, "player")
        self.player = player.Player(
            playerNode,
            self.map,
            data.getAttr(newgameNode, "position", data.D_INT2LIST),
            data.getAttr(newgameNode, "level", data.D_INT),
        )

        # if there's a new game script, run it
        script = data.getOptionalChild(newgameNode, "script")
        if script is not None:
            s = script_engine.Script(script)
            self.scriptEngine.run(s)
Esempio n. 3
0
   def getBattler(self):
      graphicsNode = data.getChild(self.speciesNode, "graphics")
      battleNode = data.getChild(graphicsNode, "battle")
      battler = data.getImage(os.path.join(settings.path, "data", data.getAttr(battleNode, "front", data.D_STRING)), battleNode.ditto_fn)
      trans = data.getAttr(battleNode, "transparency", data.D_INT3LIST)
      battler.set_colorkey(trans)

      return battler
Esempio n. 4
0
    def getBattler(self):
        graphicsNode = data.getChild(self.speciesNode, "graphics")
        battleNode = data.getChild(graphicsNode, "battle")
        battler = data.getImage(
            os.path.join(settings.path, "data",
                         data.getAttr(battleNode, "front", data.D_STRING)),
            battleNode.ditto_fn)
        trans = data.getAttr(battleNode, "transparency", data.D_INT3LIST)
        battler.set_colorkey(trans)

        return battler
Esempio n. 5
0
   def loadPage(self):
      """
      Load a new page.

      Based off the currentPage attribute.
      """

      #depending on currentPage, create the required page 
      if self.currentPage == 0:
         self.page = InfoPage(self.screen, data.getChild(self.menuNode, "info"), self.poke)
      elif self.currentPage == 1:
         self.page = SkillsPage(self.screen, data.getChild(self.menuNode, "skills"), self.poke)
      elif self.currentPage == 2:
         self.page = MovesPage(self.screen, data.getChild(self.menuNode, "moves"), self.poke)
Esempio n. 6
0
   def __init__(self, screen, partyNode, font, location, poke):
      self.screen = screen
      self.font = font
      self.location = location
      self.poke = poke

      self.speciesNode = poke.speciesNode

      graphicsNode = data.getChild(self.speciesNode, "graphics")
      iconNode = data.getChild(graphicsNode, "icon")
      fn = os.path.join(settings.path, "data", data.getAttr(iconNode, "file", data.D_STRING))
      image = data.getImage(fn, iconNode.ditto_fn)
      self.iconSize = data.getAttr(iconNode, "size", data.D_INT2LIST)
      self.icon = image.subsurface((0,0), self.iconSize)
      self.icon.set_colorkey(data.getAttr(iconNode, "transparency", data.D_INT3LIST))
Esempio n. 7
0
   def setup(self, game):
      """
      Get the script engine ready to run scripts.

      game - the Game object to run scripts on.
      """

      #store game object
      self.game = game


      self.font = font.Font(os.path.join(settings.path, "data", globs.FONT)) #create the font

      #initialise variables needed to run
      self.running = False
      self.queue = []
      self.currentCommand = 0
      self.waiting = False
      self.waitingFor = None
      self.countDown = 0

      #initialise script variables
      self.variables = {}
      self.result = None

      #determine behaviour scripts
      tree = data.getTree(globs.BEHAVIOURS)
      root = tree.getroot()
      self.behaviours = {}
      for behaviourNode in data.getChildren(root, "behaviour", globs.BEHAVIOURS):
         i = data.getAttr(behaviourNode, "index", data.D_INT, globs.BEHAVIOURS)
         s = data.getChild(behaviourNode, "script", globs.BEHAVIOURS)
         self.behaviours[i] = Script(s, False)
Esempio n. 8
0
    def setup(self, game):
        """
      Get the script engine ready to run scripts.

      game - the Game object to run scripts on.
      """

        #store game object
        self.game = game

        self.font = font.Font(os.path.join(settings.path, "data",
                                           globs.FONT))  #create the font

        #initialise variables needed to run
        self.running = False
        self.queue = []
        self.currentCommand = 0
        self.waiting = False
        self.waitingFor = None
        self.countDown = 0

        #initialise script variables
        self.variables = {}
        self.result = None

        #determine behaviour scripts
        tree = data.getTree(globs.BEHAVIOURS)
        root = tree.getroot()
        self.behaviours = {}
        for behaviourNode in data.getChildren(root, "behaviour",
                                              globs.BEHAVIOURS):
            i = data.getAttr(behaviourNode, "index", data.D_INT,
                             globs.BEHAVIOURS)
            s = data.getChild(behaviourNode, "script", globs.BEHAVIOURS)
            self.behaviours[i] = Script(s, False)
Esempio n. 9
0
    def openSave(self, fn, root):
        """
      Open a save file.

      fn - the path to the save file.
      root - the root <game> node.
      """

        # open the file for reading, load the save game, and close
        try:
            f = open(fn, "r")
            self.savegame = pickle.load(f)
            f.close()
        except pickle.PickleError:
            raise error.DittoInvalidResourceException("Ditto main", fn)
        except IOError:
            raise error.DittoIOException("Ditto main", fn)

        # create the current map and load its connections
        self.map = tilemap.Tilemap(self.savegame.currentMap)
        self.map.loadConnections()

        # create the player
        playerNode = data.getChild(root, "player")
        self.player = player.Player(playerNode, self.map, self.savegame.currentPosition, self.savegame.currentLevel)
        self.player.direction = self.savegame.currentDirection
        self.player.party = self.savegame.party
Esempio n. 10
0
    def openSave(self, fn, root):
        """
      Open a save file.

      fn - the path to the save file.
      root - the root <game> node.
      """

        #open the file for reading, load the save game, and close
        try:
            f = open(fn, "r")
            self.savegame = pickle.load(f)
            f.close()
        except pickle.PickleError:
            raise error.DittoInvalidResourceException("Ditto main", fn)
        except IOError:
            raise error.DittoIOException("Ditto main", fn)

        #create the current map and load its connections
        self.map = tilemap.Tilemap(self.savegame.currentMap)
        self.map.loadConnections()

        #create the player
        playerNode = data.getChild(root, "player")
        self.player = player.Player(playerNode, self.map,
                                    self.savegame.currentPosition,
                                    self.savegame.currentLevel)
        self.player.direction = self.savegame.currentDirection
        self.player.party = self.savegame.party
Esempio n. 11
0
   def loadPokemon(self):
      """
      Load the pokemon, and create the main pokemon box common to all pages.

      Uses the currentPoke attribute to search party for correct pokemon.
      """

      #get the required pokemon
      self.poke = self.party[self.currentPoke]
      speciesNode = self.poke.speciesNode

      #get the <main> child of the <pokemon> node
      mainNode = data.getChild(self.menuNode, "main")

      #create the font
      fFont = font.Font(os.path.join(settings.path, "data", data.getAttr(mainNode, "font", data.D_STRING)))

      #create the main box, which will cover the top left quarter of the screen
      size = ((self.screen.get_width()/2)-(OBJECTBUFFER*2), (self.screen.get_height()/2)-(OBJECTBUFFER*2))
      fn = os.path.join(settings.path, "data", data.getAttr(mainNode, "box", data.D_STRING))
      self.mainBox = box.Box(size, fn).convert(self.screen)

      #write the pokemon level and name, then draw the pokemon
      fFont.writeText("Lv%i" % self.poke.level, self.mainBox, (BORDER, BORDER)) #top left
      fFont.writeText(self.poke.getName(), self.mainBox, ((size[0]-fFont.calcWidth(self.poke.getName()))/2, BORDER)) #top centre
      self.battler = self.poke.getBattler()
      self.mainBox.blit(self.battler, ((size[0]-self.battler.get_width())/2, size[1]-self.battler.get_height()-BORDER)) #bottom centre
Esempio n. 12
0
   def __init__(self, screen, partyNode, location):
      self.screen = screen
      self.location = location

      emptyNode = data.getChild(partyNode, "empty")
      fn = os.path.join(settings.path, "data", data.getAttr(emptyNode, "file", data.D_STRING))
      self.box = pygame.image.load(fn).convert(self.screen)
      self.box.set_colorkey(data.getAttr(partyNode, "transparency", data.D_INT3LIST))
Esempio n. 13
0
    def setup(self):
        """Initialize pygame, find the main game file and parse it."""

        #initialise pygame
        pygame.init()

        #find the main game file and parse it
        if settings.path is not None:
            fn = os.path.join(settings.path, "data", "game.xml")
        else:
            raise error.DittoInvalidResourceException("settings.py", "path")
        root = data.getTreeRoot(fn, "Ditto Main")
        for p in data.getChildren(root, "property"):
            if data.getAttr(p, "name", data.D_STRING) == "tilesize":
                globs.TILESIZE = data.getAttr(p, "value", data.D_INT2LIST)
            elif data.getAttr(p, "name", data.D_STRING) == "font":
                globs.FONT = data.getAttr(p, "value", data.D_STRING)
            elif data.getAttr(p, "name", data.D_STRING) == "dialog":
                globs.DIALOG = data.getAttr(p, "value", data.D_STRING)
            elif data.getAttr(p, "name", data.D_STRING) == "pokemon":
                globs.POKEMON = data.getAttr(p, "value", data.D_STRING)
            elif data.getAttr(p, "name", data.D_STRING) == "soundeffects":
                soundPath = os.path.join(
                    settings.path, "data",
                    data.getAttr(p, "value", data.D_STRING))
            elif data.getAttr(p, "name", data.D_STRING) == "moves":
                globs.MOVES = os.path.join(
                    settings.path, "data",
                    data.getAttr(p, "value", data.D_STRING))
            elif data.getAttr(p, "name", data.D_STRING) == "behaviours":
                globs.BEHAVIOURS = os.path.join(
                    settings.path, "data",
                    data.getAttr(p, "value", data.D_STRING))

        #if there's an icon specified, use it
        if len(data.getChildren(root, "icon")) > 0:
            node = data.getChild(root, "icon")
            iconPath = os.path.join(settings.path, "data",
                                    data.getAttr(node, "file", data.D_STRING))
            icon = data.getImage(iconPath, fn)
            pygame.display.set_icon(icon)

        #set up the main window
        windowSize = settings.screenSize[0] * globs.TILESIZE[
            0], settings.screenSize[1] * globs.TILESIZE[1]
        self.screen = pygame.display.set_mode(windowSize)
        pygame.display.set_caption("%s --- Ditto Engine" %
                                   data.getAttr(root, "title", data.D_STRING))

        #create a clock object
        self.clock = pygame.time.Clock()

        #initialise sound
        sound.init(soundPath)

        #set up the initial scene, the intro
        self.activeScene = intro.Intro(self.screen)
Esempio n. 14
0
 def choose(self, choice):
     if choice == "POKEMON":
         node = data.getChild(self.menuNode, "party")
         self.foregroundObject = party_screen.PartyScreen(
             self.screen, node, self.game.player.party)
     elif choice == "EXIT":
         self.busy = False
     else:
         print choice
Esempio n. 15
0
    def loadPage(self):
        """
      Load a new page.

      Based off the currentPage attribute.
      """

        #depending on currentPage, create the required page
        if self.currentPage == 0:
            self.page = InfoPage(self.screen,
                                 data.getChild(self.menuNode, "info"),
                                 self.poke)
        elif self.currentPage == 1:
            self.page = SkillsPage(self.screen,
                                   data.getChild(self.menuNode, "skills"),
                                   self.poke)
        elif self.currentPage == 2:
            self.page = MovesPage(self.screen,
                                  data.getChild(self.menuNode, "moves"),
                                  self.poke)
Esempio n. 16
0
   def calcStats(self):
      statsNode = data.getChild(self.speciesNode, "basestats")
      
      baseStats = {}
      baseStats[ST_HP] = data.getAttr(statsNode, "hp", data.D_INT)
      baseStats[ST_ATTACK] = data.getAttr(statsNode, "attack", data.D_INT)
      baseStats[ST_DEFENSE] = data.getAttr(statsNode, "defense", data.D_INT)
      baseStats[ST_SPATTACK] = data.getAttr(statsNode, "spatk", data.D_INT)
      baseStats[ST_SPDEFENSE] = data.getAttr(statsNode, "spdef", data.D_INT)
      baseStats[ST_SPEED] = data.getAttr(statsNode, "speed", data.D_INT)

      self.stats[ST_HP] = (((self.IVs[ST_HP]+(2*baseStats[ST_HP])+(self.EVs[ST_HP]/4)+100)*self.level)/100)+10

      for stat in [ST_ATTACK, ST_DEFENSE, ST_SPATTACK, ST_SPDEFENSE, ST_SPEED]:
         self.stats[stat] = (((self.IVs[stat]+(2*baseStats[stat])+(self.EVs[stat]/4))*self.level)/100)+5
Esempio n. 17
0
   def setup(self):
      """Initialize pygame, find the main game file and parse it."""

      #initialise pygame
      pygame.init()

      #find the main game file and parse it
      if settings.path is not None:
         fn = os.path.join(settings.path, "data", "game.xml")
      else:
         raise error.DittoInvalidResourceException("settings.py", "path")
      root = data.getTreeRoot(fn, "Ditto Main")
      for p in data.getChildren(root, "property"):
         if data.getAttr(p, "name", data.D_STRING) == "tilesize":
            globs.TILESIZE = data.getAttr(p, "value", data.D_INT2LIST)
         elif data.getAttr(p, "name", data.D_STRING) == "font":
            globs.FONT = data.getAttr(p, "value", data.D_STRING)
         elif data.getAttr(p, "name", data.D_STRING) == "dialog":
            globs.DIALOG = data.getAttr(p, "value", data.D_STRING)
         elif data.getAttr(p, "name", data.D_STRING) == "pokemon":
            globs.POKEMON = data.getAttr(p, "value", data.D_STRING)
         elif data.getAttr(p, "name", data.D_STRING) == "soundeffects":
            soundPath = os.path.join(settings.path, "data", data.getAttr(p, "value", data.D_STRING))
         elif data.getAttr(p, "name", data.D_STRING) == "moves":
            globs.MOVES = os.path.join(settings.path, "data", data.getAttr(p, "value", data.D_STRING))
         elif data.getAttr(p, "name", data.D_STRING) == "behaviours":
            globs.BEHAVIOURS = os.path.join(settings.path, "data", data.getAttr(p, "value", data.D_STRING))

      #if there's an icon specified, use it      
      if len(data.getChildren(root, "icon")) > 0:
         node = data.getChild(root, "icon")
         iconPath = os.path.join(settings.path, "data", data.getAttr(node, "file", data.D_STRING))
         icon = data.getImage(iconPath, fn)
         pygame.display.set_icon(icon)

      #set up the main window
      windowSize = settings.screenSize[0]*globs.TILESIZE[0], settings.screenSize[1]*globs.TILESIZE[1]   
      self.screen = pygame.display.set_mode(windowSize)
      pygame.display.set_caption("%s --- Ditto Engine" % data.getAttr(root, "title", data.D_STRING))

      #create a clock object
      self.clock = pygame.time.Clock()

      #initialise sound
      sound.init(soundPath)

      #set up the initial scene, the intro
      self.activeScene = intro.Intro(self.screen)
Esempio n. 18
0
   def __init__(self, screen, partyNode, font, hpBar, location, poke):
      PartyBox.__init__(self, screen, partyNode, font, location, poke)

      self.border = 3
      self.lineBuffer = 0

      sideNode = data.getChild(partyNode, "side")
      fn = os.path.join(settings.path, "data", data.getAttr(sideNode, "file", data.D_STRING))
      self.box = pygame.image.load(fn).convert(self.screen)
      self.box.set_colorkey(data.getAttr(partyNode, "transparency", data.D_INT3LIST))

      self.box.blit(hpBar, (self.box.get_width()-hpBar.get_width()-self.border, self.border))
      self.font.writeText(poke.getName(), self.box, (self.iconSize[0]+self.border, self.border))
      self.font.writeText("Lv%s" % poke.level, self.box, (self.iconSize[0]+self.border, self.border+self.font.height+self.lineBuffer))
      text = "%s/%s" % (poke.currentHP, poke.stats[pokemon.ST_HP])
      self.font.writeText(text, self.box, (self.box.get_width()-self.font.calcWidth(text)-self.border, self.border+hpBar.get_height()))
   def setup(self, game):
      self.symbols = symbols.Symbols(game, self)

      self.script = None
      self.result = False
      self.currentCmd = 0

      self.caller = None

      self.waitingFor = None

      #determine behaviour scripts
      root = data.getTreeRoot(globs.BEHAVIOURS)
      self.behaviours = {}
      for behaviourNode in data.getChildren(root, "behaviour"):
         i = data.getAttr(behaviourNode, "index", data.D_INT)
         s = data.getChild(behaviourNode, "script")
         self.behaviours[i] = script.Script(s, False)
Esempio n. 20
0
    def setup(self, game):
        self.symbols = symbols.Symbols(game, self)

        self.script = None
        self.result = False
        self.currentCmd = 0

        self.caller = None

        self.waitingFor = None

        #determine behaviour scripts
        root = data.getTreeRoot(globs.BEHAVIOURS)
        self.behaviours = {}
        for behaviourNode in data.getChildren(root, "behaviour"):
            i = data.getAttr(behaviourNode, "index", data.D_INT)
            s = data.getChild(behaviourNode, "script")
            self.behaviours[i] = script.Script(s, False)
Esempio n. 21
0
 def inputButton(self, button):
    if self.foregroundObject is None:
       if button == game_input.BT_A:
          self.foregroundObject = pokemon_screen.PokemonScreen(self.screen, data.getChild(self.partyNode, "pokemon"), self.party, self.current)
       elif button == game_input.BT_B:
          self.busy = False
       elif button == game_input.BT_UP:
          if self.current > 1:
             self.current -= 1
       elif button == game_input.BT_DOWN:
          if self.current < len(self.party)-1:
             self.current += 1
       elif button == game_input.BT_LEFT:
          self.current = 0
       elif button == game_input.BT_RIGHT:
          if self.current == 0:
             self.current = 1
    else:
       self.foregroundObject.inputButton(button)
Esempio n. 22
0
    def calcStats(self):
        statsNode = data.getChild(self.speciesNode, "basestats")

        baseStats = {}
        baseStats[ST_HP] = data.getAttr(statsNode, "hp", data.D_INT)
        baseStats[ST_ATTACK] = data.getAttr(statsNode, "attack", data.D_INT)
        baseStats[ST_DEFENSE] = data.getAttr(statsNode, "defense", data.D_INT)
        baseStats[ST_SPATTACK] = data.getAttr(statsNode, "spatk", data.D_INT)
        baseStats[ST_SPDEFENSE] = data.getAttr(statsNode, "spdef", data.D_INT)
        baseStats[ST_SPEED] = data.getAttr(statsNode, "speed", data.D_INT)

        self.stats[ST_HP] = ((
            (self.IVs[ST_HP] + (2 * baseStats[ST_HP]) +
             (self.EVs[ST_HP] / 4) + 100) * self.level) / 100) + 10

        for stat in [
                ST_ATTACK, ST_DEFENSE, ST_SPATTACK, ST_SPDEFENSE, ST_SPEED
        ]:
            self.stats[stat] = ((
                (self.IVs[stat] + (2 * baseStats[stat]) +
                 (self.EVs[stat] / 4)) * self.level) / 100) + 5
Esempio n. 23
0
    def loadPokemon(self):
        """
      Load the pokemon, and create the main pokemon box common to all pages.

      Uses the currentPoke attribute to search party for correct pokemon.
      """

        #get the required pokemon
        self.poke = self.party[self.currentPoke]
        speciesNode = self.poke.speciesNode

        #get the <main> child of the <pokemon> node
        mainNode = data.getChild(self.menuNode, "main")

        #create the font
        fFont = font.Font(
            os.path.join(settings.path, "data",
                         data.getAttr(mainNode, "font", data.D_STRING)))

        #create the main box, which will cover the top left quarter of the screen
        size = ((self.screen.get_width() / 2) - (OBJECTBUFFER * 2),
                (self.screen.get_height() / 2) - (OBJECTBUFFER * 2))
        fn = os.path.join(settings.path, "data",
                          data.getAttr(mainNode, "box", data.D_STRING))
        self.mainBox = box.Box(size, fn).convert(self.screen)

        #write the pokemon level and name, then draw the pokemon
        fFont.writeText("Lv%i" % self.poke.level, self.mainBox,
                        (BORDER, BORDER))  #top left
        fFont.writeText(self.poke.getName(), self.mainBox,
                        ((size[0] - fFont.calcWidth(self.poke.getName())) / 2,
                         BORDER))  #top centre
        self.battler = self.poke.getBattler()
        self.mainBox.blit(self.battler,
                          ((size[0] - self.battler.get_width()) / 2, size[1] -
                           self.battler.get_height() - BORDER))  #bottom centre
Esempio n. 24
0
   def __init__(self, species, level):
      self.species = species

      fn = os.path.join(settings.path, "data", globs.POKEMON)
      root = data.getTreeRoot(fn, "Ditto main")

      for sp in data.getChildren(root, "species"):
         if data.getAttr(sp, "id", data.D_STRING) == self.species:
            self.speciesNode = sp
            break                           
      
      self.nickname = None
      
      self.level = level
      self.exp = 0

      typeNode = data.getChild(self.speciesNode, "type")
      self.type1 = data.getAttr(typeNode, "primary", data.D_STRING)
      self.type2 = data.getOptionalAttr(typeNode, "secondary", data.D_STRING, None)

      self.PID = random.randint(0, 4294967295)
      self.trainer = None
      self.trainerID = None

      self.ability = None

      self.gender = G_MALE
      self.nature = 0
      self.shiny = False

      self.form = 0
      self.happiness = 0
      self.pokerus = False
      
      self.EVs = {ST_HP: 0,
                  ST_ATTACK: 0,
                  ST_DEFENSE: 0,
                  ST_SPEED: 0,
                  ST_SPATTACK: 0,
                  ST_SPDEFENSE: 0}
      
      self.IVs = {ST_HP: random.randint(0,31),
                  ST_ATTACK: random.randint(0,31),
                  ST_DEFENSE: random.randint(0,31),
                  ST_SPEED: random.randint(0,31),
                  ST_SPATTACK: random.randint(0,31),
                  ST_SPDEFENSE: random.randint(0,31)}

      self.stats = {}
      self.calcStats()

      self.currentHP = self.stats[ST_HP]
      self.status = None

      self.moves = [None, None, None, None]
      movesNode = data.getChild(self.speciesNode, "attacks")
      moveNodes = sorted(data.getChildren(movesNode, "move"), key=lambda n: int(n.attrib["level"]))
      i = 0
      for node in moveNodes[-4:]:
         self.moves[i] = moves.Move(data.getAttr(node, "id", data.D_STRING))
         i += 1
      
      self.ballCaughtIn = 0

      self.heldItem = None
Esempio n. 25
0
    def __init__(self, species, level):
        self.species = species

        fn = os.path.join(settings.path, "data", globs.POKEMON)
        root = data.getTreeRoot(fn, "Ditto main")

        for sp in data.getChildren(root, "species"):
            if data.getAttr(sp, "id", data.D_STRING) == self.species:
                self.speciesNode = sp
                break

        self.nickname = None

        self.level = level
        self.exp = 0

        typeNode = data.getChild(self.speciesNode, "type")
        self.type1 = data.getAttr(typeNode, "primary", data.D_STRING)
        self.type2 = data.getOptionalAttr(typeNode, "secondary", data.D_STRING,
                                          None)

        self.PID = random.randint(0, 4294967295)
        self.trainer = None
        self.trainerID = None

        self.ability = None

        self.gender = G_MALE
        self.nature = 0
        self.shiny = False

        self.form = 0
        self.happiness = 0
        self.pokerus = False

        self.EVs = {
            ST_HP: 0,
            ST_ATTACK: 0,
            ST_DEFENSE: 0,
            ST_SPEED: 0,
            ST_SPATTACK: 0,
            ST_SPDEFENSE: 0
        }

        self.IVs = {
            ST_HP: random.randint(0, 31),
            ST_ATTACK: random.randint(0, 31),
            ST_DEFENSE: random.randint(0, 31),
            ST_SPEED: random.randint(0, 31),
            ST_SPATTACK: random.randint(0, 31),
            ST_SPDEFENSE: random.randint(0, 31)
        }

        self.stats = {}
        self.calcStats()

        self.currentHP = self.stats[ST_HP]
        self.status = None

        self.moves = [None, None, None, None]
        movesNode = data.getChild(self.speciesNode, "attacks")
        moveNodes = sorted(data.getChildren(movesNode, "move"),
                           key=lambda n: int(n.attrib["level"]))
        i = 0
        for node in moveNodes[-4:]:
            self.moves[i] = moves.Move(data.getAttr(node, "id", data.D_STRING))
            i += 1

        self.ballCaughtIn = 0

        self.heldItem = None
Esempio n. 26
0
   def __init__(self, fn):
      """
      Open the map data file, set border tiles and connections, and add NPCs and other events.

      fn - the filename of the map XML file.
      """

      #for the scripting engine
      script_engine.ScriptableObject.__init__(self)

      #store variables we'll need later
      self.fn = fn

      #get a script engine (singleton)
      self.scriptEngine = script_engine.ScriptEngine()

      #parse the XML file
      root = data.getTreeRoot(fn)
      self.music = os.path.join(settings.path, "data", data.getAttr(root, "music", data.D_STRING))

      #open the actual map data file to create the map tile data
      mapPath = os.path.join(settings.path, "data", data.getAttr(root, "file", data.D_STRING))
      self.openMap(mapPath)

      #create the tileset
      tilesetPath = os.path.join(settings.path, "data", data.getAttr(root, "tileset", data.D_STRING))
      self.tileset = tileset.Tileset(tilesetPath)

      #set the border tiles
      self.borderTiles = {}
      borderNode = data.getChild(root, "border")

      #set each border node with the correct tile indexes, subtracting 1 because the tileset starts at 1 not 0
      self.borderTiles[BD_NW] = data.getAttr(borderNode, "nw", data.D_INT)-1
      self.borderTiles[BD_NE] = data.getAttr(borderNode, "ne", data.D_INT)-1
      self.borderTiles[BD_SW] = data.getAttr(borderNode, "sw", data.D_INT)-1
      self.borderTiles[BD_SE] = data.getAttr(borderNode, "se", data.D_INT)-1
      
      #create any connections from the map
      #connected maps will not be loaded until the map becomes the main game map
      #connections are stored as {direction: (filename, offset)}
      self.connections = {}
      self.connectedMaps = {}
      for c in data.getChildren(root, "connection"):
         side = data.getAttr(c, "side", data.D_STRING)
         fp = os.path.join(settings.path, "data", data.getAttr(c, "map", data.D_STRING))
         offset = data.getAttr(c, "offset", data.D_INT)
         
         if side == "left":
            self.connections[sprite.DIR_LEFT] = (fp, offset)
         elif side == "right":
            self.connections[sprite.DIR_RIGHT] = (fp, offset)
         elif side == "up":
            self.connections[sprite.DIR_UP] = (fp, offset)
         elif side == "down":
            self.connections[sprite.DIR_DOWN] = (fp, offset)

      #create any NPCs, adding them to the sprite dictionary
      self.sprites = {}
      for n in data.getChildren(root, "npc"):
         spr = npc.NPC(n, self)
         self.sprites[spr.id] = spr

      #create a dictionary to hold positions reserved by moving sprites
      self.reservedPositions = {}

      #create script and warp events, adding them to the events dictionary
      #if a load script is defined, create it
      self.events = {}
      loadScript = None
      for s in data.getChildren(root, "script"):
         trigger = data.getAttr(s, "trigger", data.D_STRING)
         if trigger == "load":
            loadScript = script_engine.Script(s)   
         else:
            position = tuple(data.getAttr(s, "position", data.D_INT2LIST)) 
            self.events[position] = events.ScriptEvent(s, self)
            
      for w in root.findall("warp"):
         position = tuple(data.getAttr(w, "position", data.D_INT2LIST))
         self.events[position] = events.Warp(w, self)

      #if there is a load script, run it
      if loadScript is not None:
         self.scriptEngine.run(loadScript, self)
Esempio n. 27
0
    def __init__(self, fn):
        """
      Open the map data file, set border tiles and connections, and add NPCs and other events.

      fn - the filename of the map XML file.
      """

        #for the scripting engine
        script_engine.ScriptableObject.__init__(self)

        #store variables we'll need later
        self.fn = fn

        #get a script engine (singleton)
        self.scriptEngine = script_engine.ScriptEngine()

        #parse the XML file
        root = data.getTreeRoot(fn)
        self.music = os.path.join(settings.path, "data",
                                  data.getAttr(root, "music", data.D_STRING))

        #open the actual map data file to create the map tile data
        mapPath = os.path.join(settings.path, "data",
                               data.getAttr(root, "file", data.D_STRING))
        self.openMap(mapPath)

        #create the tileset
        tilesetPath = os.path.join(
            settings.path, "data", data.getAttr(root, "tileset",
                                                data.D_STRING))
        self.tileset = tileset.Tileset(tilesetPath)

        #set the border tiles
        self.borderTiles = {}
        borderNode = data.getChild(root, "border")

        #set each border node with the correct tile indexes, subtracting 1 because the tileset starts at 1 not 0
        self.borderTiles[BD_NW] = data.getAttr(borderNode, "nw",
                                               data.D_INT) - 1
        self.borderTiles[BD_NE] = data.getAttr(borderNode, "ne",
                                               data.D_INT) - 1
        self.borderTiles[BD_SW] = data.getAttr(borderNode, "sw",
                                               data.D_INT) - 1
        self.borderTiles[BD_SE] = data.getAttr(borderNode, "se",
                                               data.D_INT) - 1

        #create any connections from the map
        #connected maps will not be loaded until the map becomes the main game map
        #connections are stored as {direction: (filename, offset)}
        self.connections = {}
        self.connectedMaps = {}
        for c in data.getChildren(root, "connection"):
            side = data.getAttr(c, "side", data.D_STRING)
            fp = os.path.join(settings.path, "data",
                              data.getAttr(c, "map", data.D_STRING))
            offset = data.getAttr(c, "offset", data.D_INT)

            if side == "left":
                self.connections[sprite.DIR_LEFT] = (fp, offset)
            elif side == "right":
                self.connections[sprite.DIR_RIGHT] = (fp, offset)
            elif side == "up":
                self.connections[sprite.DIR_UP] = (fp, offset)
            elif side == "down":
                self.connections[sprite.DIR_DOWN] = (fp, offset)

        #create any NPCs, adding them to the sprite dictionary
        self.sprites = {}
        for n in data.getChildren(root, "npc"):
            spr = npc.NPC(n, self)
            self.sprites[spr.id] = spr

        #create a dictionary to hold positions reserved by moving sprites
        self.reservedPositions = {}

        #create script and warp events, adding them to the events dictionary
        #if a load script is defined, create it
        self.events = {}
        loadScript = None
        for s in data.getChildren(root, "script"):
            trigger = data.getAttr(s, "trigger", data.D_STRING)
            if trigger == "load":
                loadScript = script_engine.Script(s)
            else:
                position = tuple(data.getAttr(s, "position", data.D_INT2LIST))
                self.events[position] = events.ScriptEvent(s, self)

        for w in root.findall("warp"):
            position = tuple(data.getAttr(w, "position", data.D_INT2LIST))
            self.events[position] = events.Warp(w, self)

        #if there is a load script, run it
        if loadScript is not None:
            self.scriptEngine.run(loadScript, self)