예제 #1
0
 public void putPacket(int packetId, Player player) {
   if (packetId < 0) {
     throw new IllegalArgumentException("Invalid packet ID: " + packetId);
   }
   if (packetId >= 128) {
     putByte(((packetId >> 8) + 128) + player.getEncodingCipher().nextInt());
     putByte(packetId + player.getEncodingCipher().nextInt());
   } else {
     putByte(packetId + player.getEncodingCipher().nextInt());
   }
 }
예제 #2
0
 /**
  * Handles an interaction with this npc
  *
  * @param player The player performing the interaction
  * @param option The option selected
  * @return True if the interaction was handled, false otherwise
  */
 public boolean interact(Player player, OptionButton option) {
   if (OptionButton.SIX.equals(option)) {
     NpcType npcType = getType(player);
     if (npcType != null) {
       player.getDispatcher().sendGameMessage(npcType.getDescription());
     } else {
       player.getDispatcher().sendGameMessage(getType().getDescription());
     }
     if (PrivilegeLevel.ADMINISTRATOR.equals(player.getPrivilegeLevel())) {
       player.getDispatcher().sendGameMessage(this.toString());
     }
     return true;
   }
   if ("Attack".equalsIgnoreCase(getType().op[option.getId() - 1])) {
     //			if (!player.getCombat().inCombat()) {
     //				player.getCombat().startCombat(this);
     //			}
     player.getCombatSchedule().lock(this);
     return true;
   }
   ScriptEventType eventType;
   switch (option) {
     case ONE:
       eventType = ScriptEventType.OPNPC1;
       break;
     case TWO:
       eventType = ScriptEventType.OPNPC2;
       break;
     case THREE:
       eventType = ScriptEventType.OPNPC3;
       break;
     case FOUR:
       eventType = ScriptEventType.OPNPC4;
       break;
     case FIVE:
       eventType = ScriptEventType.OPNPC5;
       break;
     default:
       eventType = null;
       break;
   }
   ScriptManager scripts = Virtue.getInstance().getScripts();
   if (eventType != null && scripts.hasBinding(eventType, this.getId())) {
     Map<String, Object> args = new HashMap<>();
     args.put("player", player);
     args.put("npc", this);
     scripts.invokeScriptChecked(eventType, this.getId(), args);
     return true;
   }
   return false;
 }
예제 #3
0
 /**
  * Refreshes the action bar.
  *
  * @param slot The slots to refresh.
  */
 public void refresh(int... slot) {
   int maskData = (barIndex + 1) << 5;
   if (locked) {
     maskData |= 0x10; // 35651680 //35651696 // bar 3
   }
   player.getVars().setVarValueInt(682, maskData);
   if (slot.length < 1) {
     slot = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
   }
   for (int s : slot) {
     Keybind k = getActiveBar().getSlots()[s];
     if (s == 12 || s == 13) {
       player.getVars().setVarValueInt(s == 12 ? 4413 : 4414, k != null ? k.getClientId() : 0);
       player.getVars().setVarValueInt(s == 12 ? 4427 : 4428, k != null ? k.getItemId() : -1);
     } else {
       player.getVars().setVarValueInt(727 + s, k != null ? k.getClientId() : 0);
       player.getVars().setVarValueInt(751 + s, 0);
       player.getVars().setVarValueInt(811 + s, k != null ? k.getItemId() : -1);
       player.getVars().setVarValueInt(835 + s, -1);
     } // 2097152			   2195454   11108350
     player
         .getDispatcher()
         .sendWidgetEvents(
             1430, SLOT_CHILD_IDS[s], -1, -1, k == null ? 2098176 : (locked ? 2195454 : 11108350));
   }
   player.getVars().setVarValueInt(679, player.getCombatSchedule().getAdrenaline() * 10);
 }
예제 #4
0
 /**
  * Performs an keybind action.
  *
  * @param slot The keybind slot.
  */
 public void perform(int slot) {
   Keybind bind = getActiveBar().getSlots()[slot];
   if (bind != null) {
     if (bind.getItemId() > 0) {
       // TODO: Item bound action.
     } else {
       Ability ability = ABILITIES.get(bind.getAbilityId());
       if (ability == null) {
         player
             .getDispatcher()
             .sendGameMessage(
                 "Unhandled ability [slot=" + slot + ", id=" + bind.getAbilityId() + "]!");
         return;
       }
       player.getCombatSchedule().run(ability);
     }
   }
 }
예제 #5
0
 public NpcType getType(Player player) {
   return Virtue.getInstance()
       .getConfigProvider()
       .getNpcTypes()
       .getMultiNPC(player.getVars(), Virtue.getInstance().getConfigProvider(), typeId);
 }
예제 #6
0
  /**
   * Handles an interaction with this ground item
   *
   * @param player The player interacting with the object
   * @param option The option selected
   * @return True if the interaction was successful, false otherwise
   */
  public boolean interact(Player player, OptionButton option) {
    if (owner != null && owner.getUserHash() != player.getUserHash()) {
      logger.warn(
          "Player "
              + player.getName()
              + " attempted to interact with item "
              + this.getId()
              + ", which is currently only visible to "
              + owner.getName());
      return true;
    }
    if (OptionButton.SIX.equals(option)) {
      this.examine(player);
      return true;
    }
    ScriptEventType eventType;
    switch (option) {
      case ONE:
        eventType = ScriptEventType.OPOBJ1;
        break;
      case TWO:
        eventType = ScriptEventType.OPOBJ2;
        break;
      case THREE:
        eventType = ScriptEventType.OPOBJ3;
        break;
      case FOUR:
        eventType = ScriptEventType.OPOBJ4;
        break;
      case FIVE:
        eventType = ScriptEventType.OPOBJ5;
        break;
      default:
        eventType = null;
        break;
    }
    ScriptManager scripts = Virtue.getInstance().getScripts();
    if (eventType != null && scripts.hasBinding(eventType, this.getId())) {
      Map<String, Object> args = new HashMap<>();
      args.put("player", player);
      args.put("item", this);
      args.put("coords", tile);
      scripts.invokeScriptChecked(eventType, this.getId(), args);
      return true;
    }

    if (OptionButton.THREE.equals(option)
        && "Take".equalsIgnoreCase(this.getType().op[2])) { // Take
      if (player.getInvs().getContainer(ContainerState.BACKPACK).freeSlots() > 0) {
        Region region = World.getInstance().getRegions().getRegionByID(tile.getRegionID());
        if (region != null) {
          GroundItem oldItem = region.removeItem(tile, this.getId());
          if (oldItem != null) {
            player.getInvs().addBackpackItem(new Item(oldItem));
            return true;
          }
        }
      }
    }
    return false;
  }
예제 #7
0
 public void putCipheredByte(int val, Player player, int shift) {
   putByte((val + player.getEncodingCipher().nextInt()) >> shift);
 }