Beispiel #1
0
  /** Constructs a new Engine and loads item and NPC data from configs. */
  public Engine() {

    LoadSmartNPC LSN = new LoadSmartNPC();

    items = new Items(this);
    LoadNPCLists lnl = new LoadNPCLists();
    lnl = null;
    engineThread.start();
  }
Beispiel #2
0
 /**
  * The thread's process.
  *
  * <p>This processes at a rate of 100 milliseconds, and the processing time is subtracted from the
  * amount of time it sleeps to keep at a rate of 100 milliseonds. Packets are checked every 100
  * milliseconds for faster response time, and most other updates are processed every 600
  * milliseconds.
  */
 public void run() {
   // addStaticObject(id, height, x, y, face, type);
   long lastEntityUpdate = 0;
   long lastEntityUpdate2 = 0;
   long curTime;
   Startup();
   while (engineRunning) {
     curTime = System.currentTimeMillis();
     connectAwaitingPlayers();
     packets.parseIncomingPackets();
     if (curTime - lastEntityUpdate2 >= 1000) {
       for (Player p : players) {
         if (p == null || !p.online) {
           continue;
         }
       }
       lastEntityUpdate2 = curTime;
     }
     if (curTime - lastEntityUpdate >= 600) {
       if (updateTime > 0) {
         updateTime--;
       }
       if (updateTime == 0) {
         try {
           Server.GrandExchangeLoader.saveOffers();
         } catch (Exception e) {
         }
         System.exit(0);
       }
       items.process();
       clanWars.process();
       for (Player p : players) {
         // Proccess and player movement, removing disconnected players.
         if (p == null || !p.online) {
           continue;
         }
         if (p.disconnected[0] && p.disconnected[1]) {
           removePlayer(p.playerId);
           continue;
         }
         p.process();
         playerMovement.getNextPlayerMovement(p);
       }
       for (Player p : players) {
         // Update players.
         if (p == null || !p.online) {
           continue;
         }
         playerUpdate.update(p);
       }
       for (Player p : players) {
         // Reset masks and send bytes.
         if (p == null || !p.online) {
           continue;
         }
         playerUpdate.clearUpdateReqs(p);
         Server.socketListener.writeBuffer(p);
       }
       for (NPC n : npcs) {
         if (n == null) {
           continue;
         }
         npcUpdate.clearUpdateMasks(n);
       }
       for (NPC n : npcs) {
         if (n == null) {
           continue;
         }
         n.process();
         if (!n.isDead) {
           if (n.randomWalk) {
             npcMovement.randomWalk(n);
           }
         } else {
           if (!n.deadEmoteDone) {
             n.deadEmoteDone = true;
             n.combatDelay = n.getDeathDelay1();
           } else if (n.deadEmoteDone && !n.hiddenNPC && n.combatDelay <= 0) {
             n.hiddenNPC = true;
           } else if (n.hiddenNPC && n.respawnDelay <= 0) {
             npcs[n.npcId] = null;
             rebuildNPCs();
             if (n.needsRespawn) {
               newNPC(
                   n.npcType,
                   n.makeX,
                   n.makeY,
                   n.heightLevel,
                   n.moveRangeX1,
                   n.moveRangeY1,
                   n.moveRangeX2,
                   n.moveRangeY2,
                   true,
                   0);
             }
           }
         }
         lastEntityUpdate = curTime;
       }
     }
     try {
       Thread.sleep(100 - (System.currentTimeMillis() - curTime));
     } catch (Exception e) {
     }
   }
 }