示例#1
0
 /**
  * Updates this player's movement.
  *
  * @param packet The packet.
  */
 private void updateThisPlayerMovement(final PacketBuilder packet) {
   if (player.isTeleporting() || player.isMapRegionChanging()) {
     packet.putBits(1, 1);
     packet.putBits(2, 3);
     packet.putBits(7, player.getLocation().getLocalX(player.getLastKnownRegion()));
     packet.putBits(1, 1);
     packet.putBits(2, player.getLocation().getZ());
     packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
     packet.putBits(7, player.getLocation().getLocalY(player.getLastKnownRegion()));
   } else {
     if (player.getSprites().getPrimarySprite() == -1) {
       packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
       if (player.getUpdateFlags().isUpdateRequired()) {
         packet.putBits(2, 0);
       }
     } else {
       if (player.getSprites().getSecondarySprite() != -1) {
         packet.putBits(1, 1);
         packet.putBits(2, 2);
         packet.putBits(3, player.getSprites().getPrimarySprite());
         packet.putBits(3, player.getSprites().getSecondarySprite());
         packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
       } else {
         packet.putBits(1, 1);
         packet.putBits(2, 1);
         packet.putBits(3, player.getSprites().getPrimarySprite());
         packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
       }
     }
   }
 }
示例#2
0
  /**
   * Find a position for the player to stand that is not inside a block. Blocks above the player
   * will be iteratively tested until there is a series of two free blocks. The player will be
   * teleported to that free position.
   *
   * @param player
   */
  public static void findFreePosition(Player player) {
    Location loc = player.getLocation();
    int x = loc.getBlockX();
    int y = Math.max(0, loc.getBlockY());
    int origY = y;
    int z = loc.getBlockZ();
    World world = player.getWorld();

    byte free = 0;

    while (y <= world.getMaxHeight() + 1) {
      if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
        free++;
      } else {
        free = 0;
      }

      if (free == 2) {
        if (y - 1 != origY || y == 1) {
          loc.setX(x + 0.5);
          loc.setY(y);
          loc.setZ(z + 0.5);
          if (y <= 2 && world.getBlockAt(x, 0, z).getTypeId() == BlockID.AIR) {
            world.getBlockAt(x, 0, z).setTypeId(20);
            loc.setY(2);
          }
          player.setFallDistance(0F);
          player.teleport(loc);
        }
        return;
      }

      y++;
    }
  }
示例#3
0
  protected static boolean damagePlayers(World world, int x, int y, int z, int damage, String id) {
    y = getSafeY(world, x, y, z);

    boolean damaged = false;
    for (Player player : etc.getServer().getPlayerList()) {
      Location pLoc = player.getLocation();
      Vector pVec = new Vector(pLoc.x, pLoc.y, pLoc.z);

      if (player.getWorld() == world
          && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1)
          && pVec.getBlockY() == y
          && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) {
        if (!id.isEmpty()) {
          if ((id.charAt(0) == 'g' && player.isInGroup(id.substring(2)))
              || (id.charAt(0) == 'p' && player.getName().equalsIgnoreCase(id.substring(2)))) {
            player.getEntity().a(ODamageSource.j, damage);
            damaged = true;
          }
        } else {
          player.getEntity().a(ODamageSource.j, damage);
          damaged = true;
        }
      }
    }

    return damaged;
  }
示例#4
0
 /**
  * Adds a new player.
  *
  * @param packet The packet.
  * @param otherPlayer The player.
  */
 public void addNewPlayer(PacketBuilder packet, Player otherPlayer) {
   packet.putBits(11, otherPlayer.getIndex());
   int yPos = otherPlayer.getLocation().getY() - player.getLocation().getY();
   int xPos = otherPlayer.getLocation().getX() - player.getLocation().getX();
   if (xPos < 0) {
     xPos += 32;
   }
   if (yPos < 0) {
     yPos += 32;
   }
   packet.putBits(5, xPos);
   packet.putBits(1, 1);
   packet.putBits(3, 1);
   packet.putBits(1, 1);
   packet.putBits(5, yPos);
 }
示例#5
0
  public String playerNavigate(String direction, Player player) throws MapControlException {
    Game game = PemberleyGame.getCurrentGame();
    Room currentRoom = player.getLocation();
    Room nextRoom;
    switch (direction) {
      case "E":
      case "EAST":
        nextRoom = currentRoom.getEast();
        break;
      case "S":
      case "SOUTH":
        nextRoom = currentRoom.getSouth();
        break;
      case "N":
      case "NORTH":
        nextRoom = currentRoom.getNorth();
        break;
      case "W":
      case "WEST":
        nextRoom = currentRoom.getWest();
        break;

      default:
        return "Not sure where you are going.";
    }
    if (nextRoom == null) {
      throw new MapControlException("You can't go that direction");
    } else {
      player.setLocation(nextRoom);
      currentRoom = player.getLocation();
      String[] roomArray = currentRoom.getRoomDrawing();
      if (roomArray == null) {
        String[] roomDrawing = this.renderRoom(nextRoom);
        nextRoom.setRoomDrawing(roomDrawing);

        String mapDrawing = this.renderMap(nextRoom);
        Map currentMap = nextRoom.getMap();
        currentMap.setMapDrawing(mapDrawing);
      }

      GameControl gameControl = new GameControl();
      gameControl.updateGame();

      String playerMessage = nextRoom.getName() + "\n" + this.lookAtRoom();
      return playerMessage;
    }
  }
示例#6
0
 public void refresh(Player p) {
   for (FloorItem f : items) {
     if (p.getLocation().withinDistance(f.getLocation())
         && !f.isDestroyed()
         && (p == f.getPlayer() || f.getPlayer() == null)) {
       p.getActionSender().sendCreateGroundItem(f);
     }
   }
 }
    @EventHandler
    public void onProjectileHit(ProjectileHitEvent projectile) {
      Heroes.debug.startTask("HeroesSkillListener");

      if (!(projectile.getEntity() instanceof Arrow)) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Arrow arrow = (Arrow) projectile.getEntity();

      if (!(arrow.getShooter() instanceof Player)) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Player player = (Player) arrow.getShooter();
      Hero hero = SkillExplodingArrow.this.plugin.getCharacterManager().getHero(player);
      if (!hero.hasEffect("ExplodingArrowBuff")) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      int radius =
          (int)
              Math.pow(
                  SkillConfigManager.getUseSetting(hero, this.skill, "radius", 5, false), 2.0D);

      float damage = SkillConfigManager.getUseSetting(hero, this.skill, "DAMAGE", 5, false);
      float blockdamage = damage;
      int block_dmg = SkillConfigManager.getUseSetting(hero, this.skill, "block-dmg", 0, false);

      if (block_dmg == 0) {
        blockdamage = 0.0F;

        for (Entity t_entity : player.getWorld().getEntities()) {
          if ((t_entity instanceof Player)) {
            Player heroes = (Player) t_entity;
            if ((heroes.equals(player))
                || (heroes.getLocation().distanceSquared(arrow.getLocation()) > radius)) continue;
            damageEntity(
                heroes, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
          } else if ((t_entity instanceof Creature)) {
            Creature mob = (Creature) t_entity;
            if (t_entity.getLocation().distanceSquared(arrow.getLocation()) <= radius) {
              damageEntity(
                  mob, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
            }
          }
        }
      }

      arrow.getWorld().createExplosion(arrow.getLocation(), blockdamage);

      Heroes.debug.stopTask("HeroesSkillListener");
    }
示例#8
0
  /**
   * ********************************************************** getPos()
   * **********************************************************
   */
  public void getPos(Player player, Command cmd, String label, String[] args) {
    Location loc = player.getLocation();
    World world = loc.getWorld();
    Chunk chunk = loc.getChunk();

    this.plugin.chat.info(player, "World  : " + world.getName());
    this.plugin.chat.info(player, "Chunk  : x=" + chunk.getX() + " z=" + chunk.getZ());
    this.plugin.chat.info(
        player,
        "Coords : x=" + loc.getBlockX() + " y=" + loc.getBlockY() + " z=" + loc.getBlockZ());
  }
示例#9
0
 /**
  * Refreshes a floor item.
  *
  * @param floor
  */
 private void refresh(FloorItem floor) {
   if (floor.getDroppedAt() >= 60000 * 2) {
     for (Player p : World.getInstance().getPlayerList()) {
       p.getActionSender().sendDestroyGroundItem(floor);
     }
   }
   if (floor.isDestroyed()) {
     if (floor.getPlayer() == null) {
       for (Player p : World.getInstance().getPlayerList()) {
         if (p.getLocation().withinDistance(floor.getLocation())) {
           p.getActionSender().sendDestroyGroundItem(floor);
         }
       }
     } else {
       if (floor.getPlayer().isDisconnected()) {
         floor.setPlayer(null);
       } else {
         if (floor.getPlayer().getLocation().withinDistance(floor.getLocation())) {
           floor.getPlayer().getActionSender().sendDestroyGroundItem(floor);
         }
       }
     }
     return;
   }
   if (floor.getPlayer() == null) {
     for (Player p : World.getInstance().getPlayerList()) {
       if (p.getLocation().withinDistance(floor.getLocation())) {
         p.getActionSender().sendCreateGroundItem(floor);
       }
     }
   } else {
     if (floor.getPlayer().isDisconnected()) {
       floor.setPlayer(null);
     } else {
       if (floor.getPlayer().getLocation().withinDistance(floor.getLocation())) {
         floor.getPlayer().getActionSender().sendCreateGroundItem(floor);
       }
     }
   }
 }
示例#10
0
 /** Test of setLocation method, of class Player. */
 @Test
 public void testSetLocation() {
   System.out.println("setLocation");
   int[] location = {2, 2};
   Player instance =
       new Player(
           new PlayerInfo("String", 0, "String"),
           new RouteRunner(new int[] {1, 1}, "String", "String"));
   instance.setLocation(location);
   int[] expResult = {2, 2};
   int[] result = instance.getLocation();
   assertArrayEquals(expResult, result);
 }
示例#11
0
 /** Test of getLocation method, of class Player. */
 @Test
 public void testGetLocation() {
   System.out.println("getLocation");
   PlayerInfo pManning = new PlayerInfo("Peyton Manning", 18);
   int[] alkupaikka1 = {5, 5};
   RouteRunner testiOff = new RouteRunner(alkupaikka1, "879987", "Q");
   Player qb = new Player(pManning, testiOff);
   qb.setLocation(alkupaikka1);
   Player instance = qb;
   int[] expResult = new int[] {5, 5};
   int[] result = instance.getLocation();
   assertArrayEquals(expResult, result);
 }
示例#12
0
  /**
   * ********************************************************** setPos1()
   * **********************************************************
   */
  public void setPos1(Player player, Command cmd, String label, String[] args) {
    this.pos1 = player.getLocation();

    this.plugin.chat.info(
        player,
        "Position 1 set to : "
            + "x="
            + this.pos1.getBlockX()
            + " y="
            + this.pos1.getBlockY()
            + " z="
            + this.pos1.getBlockZ());
  }
示例#13
0
  public void updatePosition() {
    long now = GameEngine.getAccurateTimestamp();
    Player victim = findVictim();

    if (!isBusy() && def.isAggressive() && now - getCombatTimer() > 3000 && victim != null) {
      resetPath();

      victim.resetPath();
      victim.resetAll();
      victim.setStatus(Action.FIGHTING_MOB);
      victim.getActionSender().sendSound("underattack");
      victim.getActionSender().sendMessage("You are under attack!");

      if (victim.isSleeping()) {
        victim.getActionSender().sendWakeUp(false, false);
        victim.getActionSender().sendFatigue(victim.getFatigue());
      }

      this.setLocation(victim.getLocation(), true);

      for (Player p : getViewArea().getPlayersInView()) {
        p.removeWatchedNpc(this);
      }

      victim.setBusy(true);
      victim.setSprite(9);
      victim.setOpponent(this);
      victim.setCombatTimer();

      setBusy(true);
      setSprite(8);
      setOpponent(victim);
      setCombatTimer();
      FightEvent fighting = new FightEvent(victim, this, true);
      fighting.setLastRun(0);
      World.getWorld().getDelayedEventHandler().add(fighting);
    }

    if (now - lastMovement > 2200) {
      lastMovement = now;
      int rand = DataConversions.random(0, 1);
      if (!isBusy() && finishedPath() && rand == 1 && !isRemoved()) {
        int newX = DataConversions.random(loc.minX(), loc.maxX());
        int newY = DataConversions.random(loc.minY(), loc.maxY());
        setPath(new Path(getX(), getY(), newX, newY));
      }
    }

    super.updatePosition();
  }
 @Test
 public void testGameTokensOnGoAtGameStart() {
   List<Player> listOfPlayers = new ArrayList<>();
   GameSetup gameSetup = new GameSetup();
   listOfPlayers = gameSetup.initializePlayers(6);
   boolean didItFail = false;
   for (Player player : listOfPlayers) {
     int location = player.getLocation();
     if (location != 0) {
       didItFail = true;
     }
   }
   assertFalse(didItFail);
 }
示例#15
0
 public static void addSeconds(final Player player, final int seconds) {
   if (!b******g.fdsjfhkdsjfdsjhk().getServerHandler().isEOTW()
       && DTRBitmaskType.SAFE_ZONE.appliesAt(player.getLocation())) {
     return;
   }
   if (isTagged(player)) {
     final int secondsTaggedFor =
         (int)
             ((SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis())
                 / 1000L);
     final int newSeconds = Math.min(secondsTaggedFor + seconds, 60);
     SpawnTagHandler.spawnTags.put(
         player.getName(), System.currentTimeMillis() + newSeconds * 1000L);
   } else {
     player.sendMessage(
         ChatColor.YELLOW + "You have been spawn-tagged for §c" + seconds + " §eseconds!");
     SpawnTagHandler.spawnTags.put(player.getName(), System.currentTimeMillis() + seconds * 1000L);
   }
 }
示例#16
0
 private Location findDiamondsAround(Player player, int minRadius, int maxRadius) {
   double x = player.getX() - maxRadius;
   for (; x < player.getX() + maxRadius; x += 1.0D) {
     double z = player.getZ() - maxRadius;
     for (; z < player.getZ() + maxRadius; z += 1.0D) {
       if (iLoveYou.distance(player.getLocation(), new Location(x, player.getY(), z))
           < minRadius) {
         continue;
       }
       for (double y = player.getY(); y > 0.0D; y -= 1.0D) {
         if (player
                 .getWorld()
                 .getBlockIdAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z))
             == 56) {
           return new Location(x, y, z);
         }
       }
     }
   }
   return null;
 }
示例#17
0
  private Player findVictim() {
    if (goingToAttack) {
      return null;
    }
    if (hasRan()) {
      return null;
    }

    long now = GameEngine.getAccurateTimestamp();

    if (getChasing() != null) {
      return null;
    }
    /*
    if(getViewArea().getPlayersInView() == null) {
    	return null;
    } */

    try {
      Iterable<Player> viewablePlayers = Area.getViewablePlayers(this.getLocation(), 2);
      if (viewablePlayers == null) return null;

      for (Player p : viewablePlayers) {
        if (p.inCombat()) {
          continue;
        } // || !p.nextTo(this) || p.isNonaggro()
        if (p.isBusy()
            || p.isNonaggro()
            || now - p.getCombatTimer()
                < (p.getCombatState() == CombatState.RUNNING
                        || p.getCombatState() == CombatState.WAITING
                    ? 3000
                    : 1500)
            || !p.nextTo(this)
            || !p.getLocation().inBounds(loc.minX - 4, loc.minY - 4, loc.maxX + 4, loc.maxY + 4)) {
          continue;
        } // || !p.nextTo(this)  || p.isNonaggro()
        if (!(p.isBusy()
                || p.isNonaggro()
                || now - p.getCombatTimer()
                    < (p.getCombatState() == CombatState.RUNNING
                            || p.getCombatState() == CombatState.WAITING
                        ? 3000
                        : 1500))
            || !p.nextTo(this)) {
          if (p.getCombatLevel() <= ((this.getCombatLevel() * 2) + 1) || location.inWilderness()) {
            return p;
          }
        }
      }
    } catch (Exception e) {
      // e.printStackTrace();
    }
    /*
    ActiveTile[][] tiles = getViewArea().getViewedArea(2, 2, 2, 2);
    for (int x = 0; x < tiles.length; x++) {
        for (int y = 0; y < tiles[x].length; y++) {
            ActiveTile t = tiles[x][y];
            if (t != null) {
                for (Player p : t.getPlayers()) {
                    if (p.inCombat()) {
                        continue;
                    }
                    if (p.isBusy() || p.isNonaggro() || now - p.getCombatTimer() < (p.getCombatState() == CombatState.RUNNING || p.getCombatState() == CombatState.WAITING ? 3000 : 1500) || !p.nextTo(this) || !p.getLocation().inBounds(loc.minX - 4, loc.minY - 4, loc.maxX + 4, loc.maxY + 4)) {
                        continue;
                    }
                    if (!(p.isBusy() || p.isNonaggro() || now - p.getCombatTimer() < (p.getCombatState() == CombatState.RUNNING || p.getCombatState() == CombatState.WAITING ? 3000 : 1500) || !p.nextTo(this))) {
                        if (p.getCombatLevel() <= ((this.getCombatLevel() * 2) + 1) || location.inWilderness()) {
                            return p;
                        }
                    }
                }
            }
        }
    } */
    return null;
  }
示例#18
0
 static void play(Player player) {
   String playerInput;
   boolean gameOn = true;
   boolean start = true;
   boolean goblinAlive = true;
   playerInput = "help";
   while (gameOn == true) {
     Scanner input = new Scanner(System.in);
     if (!start) {
       playerInput = input.next();
     }
     start = false;
     switch (playerInput.toLowerCase()) {
       case "north":
         player.moveTo(player.getLocation().north());
         break;
       case "south":
         player.moveTo(player.getLocation().south());
         break;
       case "east":
         player.moveTo(player.getLocation().east());
         break;
       case "west":
         player.moveTo(player.getLocation().west());
         break;
       case "look":
         player.look();
         break;
       case "drop":
         player.drop(input.next());
         break;
       case "pickup":
         player.pickup(input.next());
         break;
       case "inventory":
         player.inventory();
         break;
       case "quit":
         gameOn = false;
         break;
       case "xyzzy":
         if (player.getLocation().getName().equals("Room 5")) {
           System.out.println(
               "A red portal opens in front of you, and you walk into it without thinking. \nYou are still inside the cave. You see a chest in the center of the room.");
           player.moveTo(player.getLocation().xyzzy());
         } else {
           System.out.println("Nothing happens.");
         }
         break;
       case "help":
         printInstructions();
         break;
       case "use":
         switch (input.next()) {
           case "man":
             if (player.getLocation().getName().equals("Room 1")) {
               player.use();
             }
           case "well":
             if (player.getLocation().getName().equals("Room 7")) {
               player.use();
             }
           case "skeleton":
             if (player.getLocation().getName().equals("Room 2")) {
               player.use();
             }
           case "writing":
             if (player.getLocation().getName().equals("Room 8")) {
               player.use();
             }
           case "ears":
             if (player.getLocation().getName().equals("Room 3")) {
               player.use();
             }
           case "chest":
             if (player.getLocation().getName().equals("Room 6")) {
               player.use();
             }
         }
         break;
       default:
         System.out.println("What?");
     }
     if (player.getLocation().getName().equals("Room 4") && goblinAlive) {
       gameOn = goblinChase(player);
       goblinAlive = false;
     }
   }
   System.out.println("Game Over");
 }
示例#19
0
 static boolean goblinChase(Player player) {
   String playerInput = "";
   System.out.println("As you enter the room a goblin jumps out of the darkness and runs at you.");
   System.out.println("You feel the urge to either fight or run.");
   for (int i = 5; i > 0; i--) {
     Scanner input = new Scanner(System.in);
     playerInput = input.next();
     switch (playerInput.toLowerCase()) {
       case "north":
         player.moveTo(player.getLocation().north());
         break;
       case "south":
         player.moveTo(player.getLocation().south());
         break;
       case "east":
         player.moveTo(player.getLocation().east());
         break;
       case "west":
         player.moveTo(player.getLocation().west());
         break;
       case "look":
         player.look();
         break;
       case "drop":
         player.drop(input.next());
         break;
       case "pickup":
         player.pickup(input.next());
         break;
       case "inventory":
         player.inventory();
         break;
       case "quit":
         return false;
       case "xyzzy":
         if (player.getLocation().getName().equals("Room 5")) {
           System.out.println(
               "A red portal opens in front of you, and you walk into it without thinking. \n You are still inside the cave. You see a chest in the center of the room.");
           player.moveTo(player.getLocation().xyzzy());
         } else {
           System.out.println("Nothing happens.");
         }
         break;
       case "help":
         printInstructions();
         break;
       case "use":
         switch (input.next()) {
           case "man":
             if (player.getLocation().getName().equals("Room 1")) {
               player.use();
             }
           case "well":
             if (player.getLocation().getName().equals("Room 7")) {
               player.use();
             }
           case "skeleton":
             if (player.getLocation().getName().equals("Room 2")) {
               player.use();
             }
           case "writing":
             if (player.getLocation().getName().equals("Room 8")) {
               player.use();
             }
           case "ears":
             if (player.getLocation().getName().equals("Room 3")) {
               player.use();
             }
           case "chest":
             if (player.getLocation().getName().equals("Room 6")) {
               player.use();
             }
         }
       case "fight":
         if (player.getInventory().contains("sword")) {
           System.out.println("You decide to turn and fight.");
           System.out.println(
               "You pull out the sword you picked up earlier, the only weapon you have.");
           System.out.println(
               "As the goblin charges, you stand your ground and take a fighting stance.");
           System.out.println(
               "You plunge your sword into the goblin's chest with one decisive thrust.");
           System.out.println(
               "The goblin falls to the ground in front of you as you pull out the bloody sword.");
           System.out.println("You examine the body. The goblin is dead.");
           player.getLocation().drop("goblin");
           return true;
         } else {
           if (player.getLocation().getName().equals("Room 7")) {
             System.out.println("You decide to turn and fight.");
             System.out.println("As the goblin charges, you swing at him with all of your might.");
             System.out.println("The goblin is knocked back slightly and trips over a rock.");
             System.out.println(
                 "The goblin falls into the well situated in the center of the room.");
             System.out.println("As he falls you hear him screech, and eventually a loud THUNK!");
             System.out.println(
                 "You approach the well and look inside it, but you can't see anything, even with the lamp.");
             return true;
           } else {
             if (1 == 1) {
               System.out.println("The goblin grabs you and tears your arm off.");
               System.out.println(
                   "Wounded, you slowly bleed out as you watch the goblin eat your severed arm.");
               return false;
             }
           }
         }
         break;
       default:
         System.out.println("What?");
     }
     switch (i) {
       case 5:
         System.out.println(
             "The goblin seems dazed by the light of the lantern and trips over a rock.");
         break;
       case 4:
         System.out.println("The goblin gets up and persues you.");
         break;
       case 3:
         System.out.println(
             "You try to escape the goblin's pursuit, but he is slowly getting closer.");
         ;
         break;
       case 2:
         System.out.println("The goblin has nearly caught up to you.");
         break;
       case 1:
         System.out.println("The goblin is right behind you, there is no hope for escape.");
         break;
     }
   }
   System.out.println("The goblin grabs you and tears your arm off.");
   System.out.println(
       "Wounded, you slowly bleed out as you watch the goblin eat your severed arm.");
   return false;
 }
  /**
   * Stops players not in an arena from damaging players in that arena,<br>
   * players in an arena from damaging players not in that arena,<br>
   * and players on the same team from damaging each other if the team has friendly fire off.<br>
   * Calls the game's onEntityDamageByEntity event if the damage is allowed.
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
      Player player = (Player) event.getEntity();
      String playerName = player.getName();
      PlayerManager playerManager = ultimateGames.getPlayerManager();
      if (playerManager.isPlayerInArena(playerName)) {
        Arena arena = playerManager.getPlayerArena(playerName);

        Entity damagerEntity = event.getDamager();
        Player damager = null;
        if (damagerEntity instanceof Player) {
          damager = (Player) damagerEntity;
        } else if (damagerEntity instanceof Projectile) {
          Projectile projectile = (Projectile) damagerEntity;
          LivingEntity shooter = projectile.getShooter();
          if (shooter instanceof Player) {
            damager = (Player) shooter;
          }
        }

        if (damager != null) {
          String damagerName = damager.getName();
          if (playerManager.isPlayerInArena(damagerName)
              && playerManager.getPlayerArena(damagerName).equals(arena)) {
            TeamManager teamManager = ultimateGames.getTeamManager();
            Team playerTeam = teamManager.getPlayerTeam(playerName);
            Team damagerTeam = teamManager.getPlayerTeam(damagerName);
            if (playerTeam != null
                && playerTeam.equals(damagerTeam)
                && !playerTeam.hasFriendlyFire()) {
              ultimateGames.getMessenger().sendMessage(damager, "teams.friendlyfire");
              event.setCancelled(true);
            } else {
              arena.getGame().getGamePlugin().onEntityDamageByEntity(arena, event);
            }
          } else {
            event.setCancelled(true);
          }
        }
      } else if (playerManager.isPlayerSpectatingArena(playerName)) {
        Entity damagerEntity = event.getDamager();
        if (damagerEntity instanceof Projectile) {
          Projectile projectile = (Projectile) damagerEntity;

          player.teleport(player.getLocation().add(0, 5, 0));
          player.setFlying(true);

          Projectile newProjectile =
              projectile.getWorld().spawn(projectile.getLocation(), projectile.getClass());
          newProjectile.setShooter(projectile.getShooter());
          newProjectile.setVelocity(projectile.getVelocity());
          newProjectile.setBounce(false);

          event.setCancelled(true);
          projectile.remove();
        }
      }
    } else {
      Arena arena =
          ultimateGames.getArenaManager().getLocationArena(event.getEntity().getLocation());
      if (arena != null) {
        arena.getGame().getGamePlugin().onEntityDamageByEntity(arena, event);
      }
    }
  }
示例#21
0
  public void handlePacket(rscproject.gs.connection.Packet p, IoSession session) throws Exception {
    byte loginCode = p.readByte();
    if (world.getPlayer(player.getUsernameHash()) != null) {
      Exception e =
          new Exception(
              "Double log from " + player.getUsername() + " | " + player.getUsernameHash());
      e.printStackTrace();
      loginCode = 5;
      player.destroy(true);
      player.getSession().close();
      return;
    }
    boolean newchar = false;
    RSCPacketBuilder pb = new RSCPacketBuilder();
    pb.setBare(true);
    pb.addByte(loginCode);
    player.getSession().write(pb.toPacket());
    if (loginCode == 0 || loginCode == 1 || loginCode == 99) {
      player.setOwner(p.readInt());
      player.setGroupID(p.readInt());

      player.setSubscriptionExpires(p.readLong());

      player.setLastIP(DataConversions.IPToString(p.readLong()));
      player.setLastLogin(p.readLong());
      /** Check if account is a new account */
      if (player.getLastLogin() == 0L) {
        player.setLocation(Point.location(121, 647), true);
        int x = p.readShort();
        int y = p.readShort();
        newchar = true;
      } else {
        player.setLocation(Point.location(p.readShort(), p.readShort()), true);
      }
      player.setFatigue(p.readShort());
      player.setCombatStyle((int) p.readByte());

      player.setPrivacySetting(0, p.readByte() == 1);
      player.setPrivacySetting(1, p.readByte() == 1);
      player.setPrivacySetting(2, p.readByte() == 1);
      player.setPrivacySetting(3, p.readByte() == 1);

      player.setGameSetting(0, p.readByte() == 1);
      player.setGameSetting(2, p.readByte() == 1);
      player.setGameSetting(3, p.readByte() == 1);
      player.setGameSetting(4, p.readByte() == 1);
      player.setGameSetting(5, p.readByte() == 1);
      player.setGameSetting(6, p.readByte() == 1);

      PlayerAppearance appearance =
          new PlayerAppearance(
              p.readShort(),
              p.readShort(),
              p.readShort(),
              p.readShort(),
              p.readShort(),
              p.readShort());
      if (!appearance.isValid()) {
        loginCode = 7;
        player.destroy(true);
        player.getSession().close();
      }

      /*
       * if(World.isMembers() && !player.isMod()) { loginCode = 7;
       * player.destroy(true); player.getSession().close(); }
       */
      player.setAppearance(appearance);
      player.setWornItems(player.getPlayerAppearance().getSprites());

      player.setMale(p.readByte() == 1);
      long skull = p.readLong();
      if (skull > 0) player.addSkull(skull);

      for (int i = 0; i < 18; i++) {
        int exp = (int) p.readLong();
        player.setExp(i, exp);
        player.setMaxStat(i, Formulae.experienceToLevel(exp));
        player.setCurStat(i, p.readShort());
      }

      player.setCombatLevel(Formulae.getCombatlevel(player.getMaxStats()));

      Inventory inventory = new Inventory(player);
      int invCount = p.readShort();
      for (int i = 0; i < invCount; i++) {
        InvItem item = new InvItem(p.readShort(), p.readInt());
        if (p.readByte() == 1 && item.isWieldable()) {
          item.setWield(true);
          player.updateWornItems(
              item.getWieldableDef().getWieldPos(), item.getWieldableDef().getSprite());
        }
        inventory.add(item);
      }

      player.setInventory(inventory);

      Bank bank = new Bank();
      int bnkCount = p.readShort();
      for (int i = 0; i < bnkCount; i++) bank.add(new InvItem(p.readShort(), p.readInt()));

      player.setBank(bank);

      int friendCount = p.readShort();
      for (int i = 0; i < friendCount; i++) player.addFriend(p.readLong(), p.readShort());

      int ignoreCount = p.readShort();
      for (int i = 0; i < ignoreCount; i++) player.addIgnore(p.readLong());

      player.setQuestPoints(p.readShort(), false);
      int questCount = p.readShort();
      // System.out.println(questCount);
      for (int i = 0; i < questCount; i++)
        player.setQuestStage(p.readShort(), p.readShort(), false, false);

      /* Muted */

      player.setMuted(p.readLong());
      if (player.isMuted()) {
        player
            .getActionSender()
            .sendMessage("@red@You are muted for " + player.getDaysMuted() + " days!");
      }

      long eventcd = p.readLong();
      player.setEventCD(eventcd);

      /* End of loading methods */

      /* Send client data */
      world.registerPlayer(player);

      player.updateViewedPlayers();
      player.updateViewedObjects();

      rscproject.gs.builders.MiscPacketBuilder sender = player.getActionSender();
      sender.sendServerInfo();
      sender.sendFatigue();
      sender.sendWorldInfo(); // sends info for the client to load terrain
      sender.sendInventory();
      sender.sendEquipmentStats();
      sender.sendStats();
      sender.sendPrivacySettings();
      sender.sendGameSettings();
      sender.sendFriendList();
      sender.sendIgnoreList();
      sender.sendCombatStyle();
      sender.sendQuestData();
      sender.sendQuestInfo();

      for (InvItem i : player.getInventory().getItems()) {
        if (i.isWielded() && (i.getID() == 407 || i.getID() == 401)) {
          int count = 0;
          for (Quest q : World.getQuestManager().getQuests()) {
            if (player.getQuestStage(q.getUniqueID()) == Quest.COMPLETE) count++;
          }
          if (player.getCurStat(6) < 31
              || count <= World.getQuestManager().getQuests().size() - 1) {
            player
                .getActionSender()
                .sendMessage(
                    "You must have at least 31 magic & completed "
                        + (World.getQuestManager().getQuests().size() - 1)
                        + " quests");
            WieldHandler.unWieldItem(player, i, true);
            player.getActionSender().sendInventory();
          }
        }
        if (i.getID() == 1288 && i.isWielded()) {
          boolean found = false;
          for (int it = 0; it < 18; it++) {
            if (player.getMaxStat(it) == 99) {
              found = true;
              break;
            }
          }
          if (!found) {
            player
                .getActionSender()
                .sendMessage("Sorry, you need any skill of level 99 to wield this cape of legends");
            WieldHandler.unWieldItem(player, i, true);
          }
        }
      }
      if (player.getLocation().inWilderness()) player.p2pWildy();

      int timeTillShutdown = Instance.getServer().timeTillShutdown();
      if (timeTillShutdown > -1) sender.startShutdown((int) (timeTillShutdown / 1000));

      if (player.getLastLogin() == 0L) {
        player.getInventory().add(new InvItem(4));
        player.getInventory().add(new InvItem(70));
        player.getInventory().add(new InvItem(376));
        player.getInventory().add(new InvItem(156));
        player.getInventory().add(new InvItem(87));
        player.getInventory().add(new InvItem(1263));
        player.getActionSender().sendInventory();
        player.setChangingAppearance(true);
        sender.sendAppearanceScreen();
      }

      player.getActionSender().sendWakeUp(false);
      sender.sendLoginBox();
      sender.sendMessage(Constants.GameServer.MOTD);
      sender.sendOnlinePlayers();

      if (World.getCtf().isEventRunning) {
        sender.sendMessage(
            "%#adm#"
                + "@yel@Server@whi@"
                + ": @gre@"
                + "@gre@Capture the Flag@whi@ is running! (Levels "
                + CTF.getLevelString(CTF.currentLevelRank)
                + ")");
        sender.sendMessage("%#adm#" + "@yel@Server@whi@" + ": @gre@" + "Type ::ctf to join!");
      }
      if (newchar)
        player
            .getActionSender()
            .sendMessage(
                "@ran@Talk to the Community Instructor for information about "
                    + Constants.GameServer.SERVER_NAME);

      if (player.clientWarn()) {
        player
            .getActionSender()
            .sendAlert(
                "@red@Alert! @whi@You are using an old client, please download the new client from our website. This client WILL stop working @red@soon.",
                false);
        player
            .getActionSender()
            .sendMessage(
                "@red@Alert! @whi@You are using an old client, please download the new client from our website. This client WILL stop working on @red@soon.");
      }

      // player.getActionSender().sendAlert("Happy Birthday RSCAngel!!! XP rates are TIMES TWO for
      // today only. Check our website/twitter for more info.",
      // false);

      // sender.sendMessage("Subscriber?: " + player.isSubscriber());

      if (player.isAdmin() || player.isPMod()) {
        player.setnopk(true);
        player.setnonaggro(true);
      }

      player.setLoggedIn(true);
      player.setBusy(false);
      /** Call minigame login check */
      World.getWar().handlePlayerLogin(player);
      World.getCtf().handlePlayerLogin(player);
      World.getLoto().handlePlayerLogin(player);
    } else player.destroy(true);
  }
示例#22
0
  public void handlePacket(Packet p, IoSession session) throws Exception {
    Player player = (Player) session.getAttachment();
    if (player.isBusy()) {
      if (player.inCombat()) {
        player.getActionSender().sendMessage("You cannot do that whilst fighting!");
      }
      return;
    }
    player.resetAll();
    int idx = (int) p.readShort();
    if (idx < 0 || idx >= player.getInventory().size()) {
      player.setSuspiciousPlayer(true);
      return;
    }
    final InvItem item = player.getInventory().get(idx);
    if (item == null || item.getDef().getCommand().equals("")) {
      player.setSuspiciousPlayer(true);
      return;
    }
    if (item.isEdible()) {
      player.setBusy(true);
      player.getActionSender().sendSound("eat");
      player.getActionSender().sendMessage("You eat the " + item.getDef().getName() + ".");
      final boolean heals = player.getCurStat(3) < player.getMaxStat(3);
      if (heals) {
        int newHp = player.getCurStat(3) + item.eatingHeals();
        if (newHp > player.getMaxStat(3)) {
          newHp = player.getMaxStat(3);
        }
        player.setCurStat(3, newHp);
        player.getActionSender().sendStat(3);
      }
      world
          .getDelayedEventHandler()
          .add(
              new SingleEvent(player, 200) {
                public void action() {
                  if (heals) {
                    owner.getActionSender().sendMessage("It heals some health.");
                  }
                  owner.getInventory().remove(item);
                  switch (item.getID()) {
                    case 326: // Meat pizza
                      owner.getInventory().add(new InvItem(328));
                      break;
                    case 327: // Anchovie pizza
                      owner.getInventory().add(new InvItem(329));
                      break;
                    case 330: // Cake
                      owner.getInventory().add(new InvItem(333));
                      break;
                    case 333: // Partical cake
                      owner.getInventory().add(new InvItem(335));
                      break;
                    case 332: // Choc cake
                      owner.getInventory().add(new InvItem(334));
                      break;
                    case 334: // Partical choc cake
                      owner.getInventory().add(new InvItem(336));
                      break;
                    case 257: // Apple pie
                      owner.getInventory().add(new InvItem(263));
                      break;
                    case 261: // Half apple pie
                      owner.getInventory().add(new InvItem(251));
                      break;
                    case 258: // Redberry pie
                      owner.getInventory().add(new InvItem(262));
                      break;
                    case 262: // Half redberry pie
                      owner.getInventory().add(new InvItem(251));
                      break;
                    case 259: // Meat pie
                      owner.getInventory().add(new InvItem(261));
                      break;
                    case 263: // Half meat pie
                      owner.getInventory().add(new InvItem(251));
                      break;
                  }
                  owner.getActionSender().sendInventory();
                  owner.setBusy(false);
                }
              });
    } else if (item.getDef().getCommand().equalsIgnoreCase("bury")) {
      player.setBusy(true);
      player.getActionSender().sendMessage("You dig a hole in the ground.");
      world
          .getDelayedEventHandler()
          .add(
              new MiniEvent(player) {
                public void action() {
                  owner
                      .getActionSender()
                      .sendMessage("You bury the " + item.getDef().getName() + ".");
                  owner.getInventory().remove(item);
                  switch (item.getID()) {
                    case 20: // Bones
                    case 604: // Bat bones
                      owner.incExp(5, 8 * 10, true);
                      break;
                    case 413: // Big bones
                      owner.incExp(5, 24 * 10, true);
                      break;
                    case 814: // Dragon bones
                      owner.incExp(5, 90 * 10, true);
                      break;
                  }
                  owner.getActionSender().sendStat(5);
                  owner.getActionSender().sendInventory();
                  owner.setBusy(false);
                }
              });
    } else if (item.getDef().getCommand().equalsIgnoreCase("clean")) {
      if (!player.getQuestManager().completed("Druidic Ritual")) {
        player
            .getActionSender()
            .sendMessage(
                "You can not use Herblaw until you have completed the Druidic Ritual quest.");
        return;
      }
      ItemUnIdentHerbDef herb = item.getUnIdentHerbDef();
      if (herb == null) {
        return;
      }
      if (player.getMaxStat(15) < herb.getLevelRequired()) {
        player
            .getActionSender()
            .sendMessage("Your herblaw ability is not high enough to clean this herb.");
        return;
      }
      player.setBusy(true);
      world
          .getDelayedEventHandler()
          .add(
              new MiniEvent(player) {
                public void action() {
                  ItemUnIdentHerbDef herb = item.getUnIdentHerbDef();
                  InvItem newItem = new InvItem(herb.getNewId());
                  owner.getInventory().remove(item);
                  owner.getInventory().add(newItem);
                  owner
                      .getActionSender()
                      .sendMessage("You clean the mud off the " + newItem.getDef().getName() + ".");
                  owner.incExp(15, herb.getExp() * 10, true);
                  owner.getActionSender().sendStat(15);
                  owner.getActionSender().sendInventory();
                  owner.setBusy(false);
                }
              });
    } else if (item.getDef().getCommand().equalsIgnoreCase("drink")) {
      switch (item.getID()) {
        case 739: // Tea
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("It's nice and refreshing.");
                      owner.getInventory().remove(item);
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 193: // Beer
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 142: // Wine
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 8);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(140));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 246: // Half Jug of Wine
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 1);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(140));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 180: // Bad Wine
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("Yuck! Your head starts to hurt.");
                      owner.setCurStat(0, owner.getCurStat(0) - 8);
                      owner.getActionSender().sendStat(0);
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(140));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 830: // Greenmans Ale
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("It has a strange taste.");
                      for (int stat = 0; stat < 3; stat++) {
                        owner.setCurStat(stat, owner.getCurStat(stat) - 4);
                        owner.getActionSender().sendStat(stat);
                      }
                      if (owner.getCurStat(15) <= owner.getMaxStat(15)) {
                        owner.setCurStat(15, owner.getCurStat(15) + 1);
                        owner.getActionSender().sendStat(15);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 268: // Mind Bomb
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel very strange.");
                      for (int stat = 0; stat < 3; stat++) {
                        owner.setCurStat(stat, owner.getCurStat(stat) - 4);
                        owner.getActionSender().sendStat(stat);
                      }
                      if (owner.getCurStat(6) <= owner.getMaxStat(6)) {
                        owner.setCurStat(6, owner.getCurStat(6) + 2);
                        owner.getActionSender().sendStat(6);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 269: // Dwarven Stout
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("It tastes foul.");
                      for (int stat = 0; stat < 3; stat++) {
                        owner.setCurStat(stat, owner.getCurStat(stat) - 4);
                        owner.getActionSender().sendStat(stat);
                      }
                      if (owner.getCurStat(13) <= owner.getMaxStat(13)) {
                        owner.setCurStat(13, owner.getCurStat(13) + 1);
                        owner.getActionSender().sendStat(13);
                      }
                      if (owner.getCurStat(14) <= owner.getMaxStat(14)) {
                        owner.setCurStat(14, owner.getCurStat(14) + 1);
                        owner.getActionSender().sendStat(14);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 267: // Asgarnian Ale
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly reinvigorated");
                      owner.getActionSender().sendMessage("And slightly dizzy too.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 829: // Dragon Bitter
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
          /** HANDLE WINE+ CURE POISON AND ANTIDOTE AND ZAMAROCK POTIONS * */
        case 221: // Strength Potion - 4 dose
          useNormalPotion(player, item, 2, 10, 2, 222, 3);
          break;
        case 222: // Strength Potion - 3 dose
          useNormalPotion(player, item, 2, 10, 2, 223, 2);
          break;
        case 223: // Strength Potion - 2 dose
          useNormalPotion(player, item, 2, 10, 2, 224, 1);
          break;
        case 224: // Strength Potion - 1 dose
          useNormalPotion(player, item, 2, 10, 2, 465, 0);
          break;
        case 474: // attack Potion - 3 dose
          useNormalPotion(player, item, 0, 10, 2, 475, 2);
          break;
        case 475: // attack Potion - 2 dose
          useNormalPotion(player, item, 0, 10, 2, 476, 1);
          break;
        case 476: // attack Potion - 1 dose
          useNormalPotion(player, item, 0, 10, 2, 465, 0);
          break;
        case 477: // stat restoration Potion - 3 dose
          useStatRestorePotion(player, item, 478, 2);
          break;
        case 478: // stat restoration Potion - 2 dose
          useStatRestorePotion(player, item, 479, 1);
          break;
        case 479: // stat restoration Potion - 1 dose
          useStatRestorePotion(player, item, 465, 0);
          break;
        case 480: // defense Potion - 3 dose
          useNormalPotion(player, item, 1, 10, 2, 481, 2);
          break;
        case 481: // defense Potion - 2 dose
          useNormalPotion(player, item, 1, 10, 2, 482, 1);
          break;
        case 482: // defense Potion - 1 dose
          useNormalPotion(player, item, 1, 10, 2, 465, 0);
          break;
        case 483: // restore prayer Potion - 3 dose
          usePrayerPotion(player, item, 484, 2);
          break;
        case 484: // restore prayer Potion - 2 dose
          usePrayerPotion(player, item, 485, 1);
          break;
        case 485: // restore prayer Potion - 1 dose
          usePrayerPotion(player, item, 465, 0);
          break;
        case 486: // Super attack Potion - 3 dose
          useNormalPotion(player, item, 0, 15, 4, 487, 2);
          break;
        case 487: // Super attack Potion - 2 dose
          useNormalPotion(player, item, 0, 15, 4, 488, 1);
          break;
        case 488: // Super attack Potion - 1 dose
          useNormalPotion(player, item, 0, 15, 4, 465, 0);
          break;
        case 489: // fishing Potion - 3 dose
          useFishingPotion(player, item, 490, 2);
          break;
        case 490: // fishing Potion - 2 dose
          useFishingPotion(player, item, 491, 1);
          break;
        case 491: // fishing Potion - 1 dose
          useFishingPotion(player, item, 465, 0);
          break;
        case 492: // Super strength Potion - 3 dose
          useNormalPotion(player, item, 2, 15, 4, 493, 2);
          break;
        case 493: // Super strength Potion - 2 dose
          useNormalPotion(player, item, 2, 15, 4, 494, 1);
          break;
        case 494: // Super strength Potion - 1 dose
          useNormalPotion(player, item, 2, 15, 4, 465, 0);
          break;
        case 495: // Super defense Potion - 3 dose
          useNormalPotion(player, item, 1, 15, 4, 496, 2);
          break;
        case 496: // Super defense Potion - 2 dose
          useNormalPotion(player, item, 1, 15, 4, 497, 1);
          break;
        case 497: // Super defense Potion - 1 dose
          useNormalPotion(player, item, 1, 15, 4, 465, 0);
          break;
        case 498: // ranging Potion - 3 dose
          useNormalPotion(player, item, 4, 10, 2, 499, 2);
          break;
        case 499: // ranging Potion - 2 dose
          useNormalPotion(player, item, 4, 10, 2, 500, 1);
          break;
        case 500: // ranging Potion - 1 dose
          useNormalPotion(player, item, 4, 10, 2, 465, 0);
          break;
        default:
          player.getActionSender().sendMessage("Nothing interesting happens.");
          return;
      }
    } else {
      switch (item.getID()) {
        case 597: // Charged Dragonstone amulet
          player.getActionSender().sendMessage("You rub the amulet...");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      String[] options =
                          new String[] {
                            "Edgeville",
                            "Karamja",
                            "Draynor Village",
                            "Al Kharid",
                            "Mage Arena",
                            "Seers",
                            "Yanille"
                          };
                      owner.setMenuHandler(
                          new MenuHandler(options) {
                            public void handleReply(final int option, final String reply) {
                              if (owner.isBusy() || owner.getInventory().get(item) == null) {
                                return;
                              }
                              if (owner.getLocation().wildernessLevel() >= 30
                                  || (owner.getLocation().inModRoom() && !owner.isMod())
                                  || (owner.getLocation().inJail() && !owner.isMod())) {
                                owner
                                    .getActionSender()
                                    .sendMessage("A magical force stops you from teleporting.");
                                return;
                              }
                              owner.getActionSender().sendSound("spellok");
                              switch (option) {
                                case 0: // Edgeville
                                  owner.teleport(193, 435, true);
                                  break;
                                case 1: // Karamja
                                  owner.teleport(360, 696, true);
                                  break;
                                case 2: // Draynor Village
                                  owner.teleport(214, 632, true);
                                  break;
                                case 3: // Al Kharid
                                  owner.teleport(72, 696, true);
                                  break;
                                case 4: // Mage Arena
                                  owner.teleport(447, 3371, true);
                                  break;
                                case 5: // Seers
                                  owner.teleport(516, 460, true);
                                  break;
                                case 6: // Yanille
                                  owner.teleport(587, 761, true);
                                  break;
                                default:
                                  return;
                              }
                              if (DataConversions.random(0, 5) == 1
                                  && owner.getInventory().remove(item) > -1) {
                                owner.getInventory().add(new InvItem(522, 1));
                                owner.getActionSender().sendInventory();
                              }
                            }
                          });
                      owner.getActionSender().sendMenu(options);
                    }
                  });
          break;
        case 387: // Disk of Returning
          if (player.getLocation().wildernessLevel() >= 30
              || (player.getLocation().inModRoom() && !player.isMod())) {
            player.getActionSender().sendMessage("The disk doesn't seem to work here.");
            return;
          }
          player.getActionSender().sendMessage("The disk starts to spin...");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.resetPath();
                      owner.teleport(219, 455, true);
                      owner.getInventory().remove(item);
                      owner
                          .getActionSender()
                          .sendMessage("You find yourself back in Varrock with a sore bottom.");
                      owner.getActionSender().sendMessage("The disk has now gone");
                      owner.getActionSender().sendInventory();
                    }
                  });
          break;
        case 1263: // Sleeping Bag
          player.resetPath();
          player.getActionSender().sendMessage("You rest in the Sleeping Bag.");
          switch (rand(0, 10)) {
            case 0:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Quarter", "Quadah", "Korter", "Twenyfavcent", "Nubface"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 0) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;

            case 1:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"N00b", "Newbie", "Noobletz", "Noobz", "Noobcakez"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 1) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 2:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Jaquet", "Jaket", "Jackit", "Brangelina", "Jacket"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 4) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 3:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Marwolf", "Mar", "Wolf", "Mar!11", "Halp"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 2) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 4:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Dawg", "Dawggie", "Homeslice", "Dog", "Snoop"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 3) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 5:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Gangstar", "Gangsta", "Gangster", "Sean Brooks", "Thug lyfe yo"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 2) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 6:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Like", "Lyk", "Liek", "I suck at this", "I give up"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 0) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 7:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Wrong Answer",
                                "Right Answer",
                                "Wrong Answer",
                                "Wrong Answer",
                                "Wrong Answer"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 1) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 8:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Charictor", "Charactor", "Charector", "Carhuh?", "Character"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 4) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 9:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Hatianz", "Zombies", "Botnetz", "Tom Cruise!1", "Elephantz"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 1) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();

                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;

            case 10:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Deposet", "Deposat", "Despot", "Rapidshit", "Deposit"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 4) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });

              break;
          }
        default:
          player.getActionSender().sendMessage("Match the word with the correct spelling.");
          return;
      }
    }
  }
示例#23
0
  @Override
  public void execute(GameEngine context) {
    /*
     * If the map region changed send the new one. We do this immediately as
     * the client can begin loading it before the actual packet is received.
     */
    if (player.isMapRegionChanging()) {
      player.getActionSender().sendMapRegion();
    }

    /*
     * The update block packet holds update blocks and is send after the
     * main packet.
     */
    final PacketBuilder updateBlock = new PacketBuilder();

    /*
     * The main packet is written in bits instead of bytes and holds
     * information about the local list, players to add and remove, movement
     * and which updates are required.
     */
    final PacketBuilder updatePacket = new PacketBuilder(216, Packet.Type.VARIABLE_SHORT);
    updatePacket.startBitAccess();

    /*
     * Updates this player.
     */
    updateThisPlayerMovement(updatePacket);
    updatePlayer(updateBlock, player, false);

    /*
     * Write the current size of the player list.
     */
    updatePacket.putBits(8, player.getLocalPlayers().size());

    /*
     * Iterate through the local player list.
     */
    for (final Iterator<Player> it$ = player.getLocalPlayers().iterator(); it$.hasNext(); ) {
      /*
       * Get the next player.
       */
      final Player otherPlayer = it$.next();

      /*
       * If the player should still be in our list.
       */
      if (World.getWorld().getPlayers().contains(otherPlayer)
          && !otherPlayer.isTeleporting()
          && otherPlayer.getLocation().isWithinDistance(player.getLocation(), 16)) {

        /*
         * Update the movement.
         */
        updatePlayerMovement(updatePacket, otherPlayer);

        /*
         * Check if an update is required, and if so, send the update.
         */
        if (otherPlayer.getUpdateFlags().isUpdateRequired()) {
          updatePlayer(updateBlock, otherPlayer, false);
        }
      } else {
        /*
         * Otherwise, remove the player from the list.
         */
        it$.remove();

        /*
         * Tell the client to remove the player from the list.
         */
        updatePacket.putBits(1, 1);
        updatePacket.putBits(2, 3);
      }
    }
    /*
     * Loop through every player.
     */
    for (final Player otherPlayer : World.getWorld().getRegionManager().getLocalPlayers(player)) {
      /*
       * Check if there is room left in the local list.
       */
      if (player.getLocalPlayers().size() >= 255) {
        /*
         * There is no more room left in the local list. We cannot add
         * more players, so we just ignore the extra ones. They will be
         * added as other players get removed.
         */
        break;
      }

      /*
       * If they should not be added ignore them.
       */
      if (otherPlayer == player || player.getLocalPlayers().contains(otherPlayer)) {
        continue;
      }

      /*
       * Add the player to the local list if it is within distance.
       */
      player.getLocalPlayers().add(otherPlayer);

      /*
       * Add the player in the packet.
       */
      addNewPlayer(updatePacket, otherPlayer);
      /*
       * Update the player, forcing the appearance flag.
       */
      updatePlayer(updateBlock, otherPlayer, true);
    }

    /*
     * Check if the update block is not empty.
     */
    if (!updateBlock.isEmpty()) {
      /*
       * Write a magic id indicating an update block follows.
       */
      updatePacket.putBits(11, 2047);
      updatePacket.finishBitAccess();
      /*
       * Add the update block at the end of this packet.
       */
      updatePacket.put(updateBlock.toPacket().getPayload());
    } else {
      /*
       * Terminate the packet normally.
       */
      updatePacket.finishBitAccess();
    }
    /*
     * Write the packet.
     */
    player.write(updatePacket.toPacket());
  }
示例#24
0
 private static void appendFaceCoordinateUpdate(final Player p, final PacketBuilder updateBlock) {
   updateBlock.putLEShort(p.getLocation().getX()).putShortA(p.getLocation().getY());
 }