Package org.pokenet.server.backend.entity

Examples of org.pokenet.server.backend.entity.NonPlayerChar


  private boolean m_running;

  public void run() {
    System.out.println("INFO: Npc sleep timer started");
    Random r = new Random();
    NonPlayerChar n = null;
    ServerMap m = null;
    while(m_running) {
      /*
       * Loop through every map
       */
      for(int x = 0; x < 100; x++) {
        for(int y = 0; y < 100; y++) {
          m = GameServer.getServiceManager().
            getMovementService().getMapMatrix().getMapByRealPosition(x, y);
          if(m != null) {
            /*
             * Loop through every npc on the map
             * If they're sleeping, check if its time to wake them
             */
            for(int i = 0; i < m.getNpcs().size(); i++) {
              n = m.getNpcs().get(i);
              if(n != null && !n.canBattle() &&
                  System.currentTimeMillis() - n.getLastBattleTime()
                  >= 300000 + r.nextInt(300000)) {
                n.setLastBattleTime(0);
              }
            }
            try {
              Thread.sleep(500);
            } catch (Exception e) {}
View Full Code Here


   * Called by starting the thread
   */
  public void run() {
    try {
      Scanner reader = new Scanner(m_file);
      NonPlayerChar npc = null;
      WarpTile warp = null;
      HMObject hmObject = null;
      TradeChar t = null;
      String line;
      String [] details;
      String direction = "Down";
      while(reader.hasNextLine()) {
        line = reader.nextLine();
        if(line.equalsIgnoreCase("[npc]")) {
          npc = new NonPlayerChar();
          npc.setName(reader.nextLine());
          direction = reader.nextLine();
          if(direction.equalsIgnoreCase("UP")) {
            npc.setFacing(Direction.Up);
          } else if(direction.equalsIgnoreCase("LEFT")) {
            npc.setFacing(Direction.Left);
          } else if(direction.equalsIgnoreCase("RIGHT")) {
            npc.setFacing(Direction.Right);
          } else {
            npc.setFacing(Direction.Down);
          }
          npc.setSprite(Integer.parseInt(reader.nextLine()));
          npc.setX((Integer.parseInt(reader.nextLine())) * 32);
          npc.setY(((Integer.parseInt(reader.nextLine())) * 32) - 8);
          //Load possible Pokemons
          line = reader.nextLine();
          if(!line.equalsIgnoreCase("NULL")) {
            details = line.split(",");
            HashMap<String, Integer> pokes = new HashMap<String, Integer>();
            for(int i = 0; i < details.length; i = i + 2) {
              pokes.put(details[i], Integer.parseInt(details[i + 1]));
            }
            npc.setPossiblePokemon(pokes);
          }
          //Set minimum party level
          npc.setPartySize(Integer.parseInt(reader.nextLine()));
          npc.setBadge(Integer.parseInt(reader.nextLine()));
          //Add all speech, if any
          line = reader.nextLine();
          if(!line.equalsIgnoreCase("NULL")) {
            details = line.split(",");
            for(int i = 0; i < details.length; i++) {
              npc.addSpeech(Integer.parseInt(details[i]));
            }
          }
          npc.setHealer(Boolean.parseBoolean(reader.nextLine().toLowerCase()));
          npc.setBox(Boolean.parseBoolean(reader.nextLine().toLowerCase()));
         
          //Setting ShopKeeper as an int.
          String shop = reader.nextLine();
          try {
            npc.setShopKeeper(Integer.parseInt(shop.trim()));
          } catch(Exception e) {
            try {
              /* Must be an old shop */
              if(Boolean.parseBoolean(shop.trim().toLowerCase())){
                npc.setShopKeeper(1); //Its an old shop! Yay!
              } else {
                npc.setShopKeeper(0); //Its an old npc. Not a shop.
              }
            } catch(Exception ex) {
              npc.setShopKeeper(0);//Dunno what the hell it is, but its not a shop.
            }
          }
        } else if(line.equalsIgnoreCase("[/npc]")) {
          m_map.addChar(npc);
        } else if(line.equalsIgnoreCase("[warp]")) {
View Full Code Here

   * Starts an npc battle with the player if the player was challenged
   * @param p
   * @return
   */
  public boolean isNpcBattle(PlayerChar p) {
    NonPlayerChar n = null;
    for(int i = 0; i < m_npcs.size(); i++) {
      n = m_npcs.get(i);
      if(n != null && n.isTrainer() && !n.isGymLeader()) {
        /*
         * For the npc to be able to challenge the player, the must be on the same
         * axis as the player, the x axis or the y axis
         */
        if(n.getX() == p.getX()) {
          /* Same column */
          if(n.getY() > p.getY()) {
            /* NPC is above the player */
            if(n.getFacing() == Direction.Up && n.canSee(p)) {
              NpcBattleLauncher l = new NpcBattleLauncher(n, p);
              l.start();
              return true;
            }
          } else {
            /* NPC is below the player */
            if(n.getFacing() == Direction.Down && n.canSee(p)) {
              NpcBattleLauncher l = new NpcBattleLauncher(n, p);
              l.start();
              return true;
            }
          }
        } else if(n.getY() == p.getY()) {
          /* Same row */
          if(n.getX() > p.getX()) {
            /* NPC is right of the player */
            if(n.getFacing() == Direction.Left && n.canSee(p)) {
              NpcBattleLauncher l = new NpcBattleLauncher(n, p);
              l.start();
              return true;
            }
          } else {
            /* NPC is left of the player */
            if(n.getFacing() == Direction.Right && n.canSee(p)) {
              NpcBattleLauncher l = new NpcBattleLauncher(n, p);
              l.start();
              return true;
            }
          }
View Full Code Here

TOP

Related Classes of org.pokenet.server.backend.entity.NonPlayerChar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.