Esempio n. 1
0
 /** Makes walkable npcs walk, then updates it's position. */
 public void sendNpcWalk() {
   if (walkType == WalkType.WALK && Misc.randomNumber(10) == 0) {
     int yModifier = 0, xModifier = 0, direction = 0;
     int[][] coordinateModifiers = {
       {-1, 1}, {0, 1}, {1, 1}, {-1, 0}, {1, 0}, {-1, -1}, {0, -1}, {1, -1}
     };
     direction = Misc.randomNumber(8);
     xModifier = coordinateModifiers[direction][0];
     yModifier = coordinateModifiers[direction][1];
     if (minWalk.getX() <= (currentX + xModifier)
         && minWalk.getY() <= (currentY + yModifier)
         && maxWalk.getX() >= (currentX + xModifier)
         && maxWalk.getY() >= (currentY + yModifier)) {
       primaryDirection = direction;
       appendNpcPosition(xModifier, yModifier);
       getUpdateFlags().faceEntity(65535);
     }
   }
 }
Esempio n. 2
0
 public static Position randomPosition(Area area) {
   Position finalPosition =
       new Position(
           area.getSouthWestCorner().getX()
               + Misc.random(area.getNorthEastCorner().getX() - area.getSouthWestCorner().getX()),
           area.getSouthWestCorner().getY()
               + Misc.random(area.getNorthEastCorner().getY() - area.getSouthWestCorner().getY()),
           area.getSouthWestCorner().getZ());
   while (Region.getClipping(finalPosition.getX(), finalPosition.getY(), finalPosition.getZ())
       != 0)
     finalPosition =
         new Position(
             area.getSouthWestCorner().getX()
                 + Misc.random(
                     area.getNorthEastCorner().getX() - area.getSouthWestCorner().getX()),
             area.getSouthWestCorner().getY()
                 + Misc.random(
                     area.getNorthEastCorner().getY() - area.getSouthWestCorner().getY()),
             area.getSouthWestCorner().getZ());
   return finalPosition;
 }
Esempio n. 3
0
  @Override
  public void run() {
    try {
      Thread.currentThread().setName("ServerEngine");
      System.setOut(new Misc.TimestampLogger(System.out));
      System.setErr(new Misc.TimestampLogger(System.err, "./data/err.log"));

      address = new InetSocketAddress(host, port);
      System.out.println("Starting " + Constants.SERVER_NAME + " on " + address + "...");

      // load shutdown hook
      Thread shutdownhook = new ShutDownHook();
      Runtime.getRuntime().addShutdownHook(shutdownhook);

      PacketManager.loadPackets();

      Cache.load();

      // load scripts
      Misc.loadScripts(new File("./data/ruby/"));

      GlobalVariables.patchNotes = Misc.loadPatchNotes();
      GlobalVariables.info = Misc.loadInfo();
      GlobalVariables.npcDump = Misc.getNpcDump();
      GlobalVariables.itemDump = Misc.getItemDump();

      // load all xstream related files.
      XStreamUtil.loadAllFiles();

      // item weights
      ItemDefinition.loadWeight();

      // interfaces
      RSInterface.load();

      // Load plugins
      PluginManager.loadPlugins();

      // Load regions
      ObjectDef.loadConfig();
      Region.load();
      Rangable.load();

      // Load objects
      ObjectLoader objectLoader = new ObjectLoader();
      objectLoader.load();

      GameObjectData.init();

      // load combat manager
      CombatManager.init();

      // Load minute timer
      startMinutesCounter();

      // global drops
      GlobalGroundItem.initialize();

      // load npc ls
      Npc.loadNpcDrops();

      // mage arena timers
      AlchemistPlayground.loadAlchemistPlayGround();
      EnchantingChamber.loadEnchantingChamber();
      CreatureGraveyard.loadCreatureGraveyard();

      // spawning world fishing spots
      FishingSpots.spawnFishingSpots();

      QuestHandler.init();

      NpcLoader.loadAutoSpawn("./data/npcs/spawn-config.cfg");

      HighscoresManager.load();

      // Start up and get a'rollin!
      startup();
      System.out.println("Online!");
      while (!Thread.interrupted()) {
        try {
          cycle();
          sleep();
        } catch (Exception ex) {
          PlayerSave.saveAllPlayers();
          ex.printStackTrace();
        }
      }
      scheduler.schedule(
          new Task() {
            @Override
            protected void execute() {
              if (Thread.interrupted()) {
                PlayerSave.saveAllPlayers();
                stop();
                return;
              }
              try {
                cycle();
              } catch (Exception ex) {
                PlayerSave.saveAllPlayers();
                ex.printStackTrace();
                stop();
              }
            }
          });
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    PluginManager.close();
  }
 /** Applying any extra effects (poisoning, freezing, etc) after the attack. */
 public static void applyMagicEffects(Entity attacker, Entity victim, int hit) {
   if (attacker instanceof Player) {
     Player player = (Player) attacker;
     int spellId =
         player.getMagic().getSpellDefinitions()[player.getMagic().getMagicIndex()].getSpellId();
     switch (spellId) {
       case 12891: // Ice barrage
         FreezeEntity.freezeEntity(victim, true, 34);
         break;
       case 12871: // Ice blitz
         FreezeEntity.freezeEntity(victim, true, 25);
         break;
       case 12881: // Ice burst
         FreezeEntity.freezeEntity(victim, true, 17);
         break;
       case 12861: // Ice burst
         FreezeEntity.freezeEntity(victim, true, 9);
         break;
       case 12929: // Blood barrage
       case 12911: // Blood blitz
       case 12918: // Blood burst
       case 12901: // Blood rush
         int finalHitpoints = player.getSkill().getLevel()[3] + (hit / 4);
         if (finalHitpoints <= player.getSkill().getLevelForXP(player.getSkill().getExp()[3])) {
           player.getSkill().getLevel()[3] = finalHitpoints;
         } else {
           player.getSkill().getLevel()[3] =
               player.getSkill().getLevelForXP(player.getSkill().getExp()[3]);
         }
         player.getSkill().refresh(3);
         break;
       case 13023: // Shadow barrage
         if (victim instanceof Player) {
           Player otherPlayer = (Player) victim;
           int finalAttack =
               (otherPlayer.getSkill().getLevelForXP(otherPlayer.getSkill().getExp()[0])
                   - (int)
                       (otherPlayer.getSkill().getLevelForXP(otherPlayer.getSkill().getExp()[0])
                           * 0.15));
           if (otherPlayer.getSkill().getLevel()[0] > finalAttack) {
             otherPlayer.getSkill().getLevel()[0] = finalAttack;
           }
           otherPlayer.getSkill().refresh(0);
         }
         break;
       case 12999: // Shadow bitz
       case 13011: // Shadow burst
       case 12987: // Shadow rush
         if (victim instanceof Player) {
           Player otherPlayer = (Player) victim;
           int finalAttack =
               (otherPlayer.getSkill().getLevelForXP(otherPlayer.getSkill().getExp()[0])
                   - (int)
                       (otherPlayer.getSkill().getLevelForXP(otherPlayer.getSkill().getExp()[0])
                           * 0.1));
           if (otherPlayer.getSkill().getLevel()[0] > finalAttack) {
             otherPlayer.getSkill().getLevel()[0] = finalAttack;
           }
           otherPlayer.getSkill().refresh(0);
         }
         break;
       case 12975: // Smoke barrage
       case 12951: // Smoke blitz
         if (Misc.randomNumber(10) == 0) Poison.appendPoison(victim, true, 4);
         break;
       case 12963: // Smoke burst
       case 12939: // Smoke rush
         if (Misc.randomNumber(10) == 0) Poison.appendPoison(victim, true, 2);
         break;
     }
   }
 }
 /**
  * Checks if this position is viewable from the other position.
  *
  * @param other the other position
  * @return true if it is viewable, false otherwise
  */
 public boolean isViewableFrom(Position other) {
   Position p = Misc.delta(this, other);
   return p.x <= 14 && p.x >= -15 && p.y <= 14 && p.y >= -15;
 }