Esempio n. 1
0
 public void removelol(Item item, int amount) {
   int am = item.getCount() - amount;
   remove(item, -1);
   if (am > 0) {
     item.setCount(am);
     add(item);
   }
 }
Esempio n. 2
0
 /**
  * Attempts to add a specific slot.
  *
  * @param item The item.
  * @param slot The desired slot.
  * @return <code>true</code> if the item was added, <code>false</code> if not.
  */
 public boolean add(Item item, int slot) {
   if (item == null) return false;
   int newSlot = (slot > -1) ? slot : freeSlot();
   if ((item.getDefinition().isStackable() || type.equals(Type.ALWAYS_STACK))
       && !type.equals(Type.NEVER_STACK)) {
     if (getCount(item.getId()) > 0) {
       newSlot = getSlotById(item.getId());
     }
   }
   if (newSlot == -1) {
     // the free slot is -1
     return false;
   }
   if (get(newSlot) != null) {
     newSlot = freeSlot();
   }
   if ((item.getDefinition().isStackable() || type.equals(Type.ALWAYS_STACK))
       && !type.equals(Type.NEVER_STACK)) {
     for (int i = 0; i < items.length; i++) {
       if (items[i] != null && items[i].getId() == item.getId()) {
         int totalCount = item.getCount() + items[i].getCount();
         if (totalCount >= Constants.MAX_ITEMS || totalCount < 1) {
           return false;
         }
         set(i, new Item(items[i].getId(), items[i].getCount() + item.getCount()));
         return true;
       }
     }
     if (newSlot == -1) {
       return false;
     } else {
       set(slot > -1 ? newSlot : freeSlot(), item);
       return true;
     }
   } else {
     int slots = freeSlots();
     if (slots >= item.getCount()) {
       boolean b = firingEvents;
       firingEvents = false;
       try {
         for (int i = 0; i < item.getCount(); i++) {
           set(slot > -1 ? newSlot : freeSlot(), new Item(item.getId()));
         }
         if (b) {
           fireItemsChanged();
         }
         return true;
       } finally {
         firingEvents = b;
       }
     } else {
       return false;
     }
   }
 }
Esempio n. 3
0
 /**
  * Transfers an item from one container to another.
  *
  * @param from The container to transfer from.
  * @param to The container to transfer to.
  * @param fromSlot The slot in the original container.
  * @param id The item id.
  * @return A flag indicating if the transfer was successful.
  */
 public static boolean transfer(Container from, Container to, int fromSlot, int id) {
   Item fromItem = from.get(fromSlot);
   if (fromItem == null || fromItem.getId() != id) {
     return false;
   }
   if (to.add(fromItem)) {
     from.set(fromSlot, null);
     return true;
   } else {
     return false;
   }
 }
Esempio n. 4
0
 public boolean contains(int id, int amount) {
   int count = 0;
   for (Item item : items) {
     if (item != null) {
       if (item.getId() == id) {
         count += item.getCount();
       }
     }
   }
   if (count >= amount) {
     return true;
   }
   return false;
 }
Esempio n. 5
0
 /**
  * Checks if there is room in the inventory for an item.
  *
  * @param item The item.
  * @return <code>true</code> if so, <code>false</code> if not.
  */
 public boolean hasRoomFor(Item item) {
   if ((item.getDefinition().isStackable() || type.equals(Type.ALWAYS_STACK))
       && !type.equals(Type.NEVER_STACK)) {
     for (int i = 0; i < items.length; i++) {
       if (items[i] != null && items[i].getId() == item.getId()) {
         int totalCount = item.getCount() + items[i].getCount();
         if (totalCount >= Constants.MAX_ITEMS || totalCount < 1) {
           return false;
         }
         return true;
       }
     }
     int slot = freeSlot();
     return slot != -1;
   } else {
     int slots = freeSlots();
     return slots >= item.getCount();
   }
 }
Esempio n. 6
0
 public static CombatAction getActiveCombatAction(Mob mob) {
   if (mob.getDefaultCombatAction() != null) {
     return mob.getDefaultCombatAction();
   }
   if (mob.isWerewolf()) {
     return MeleeCombatAction.getAction();
   }
   if (mob.getCombatState().getQueuedSpell() != null
       || (mob.getAutocastSpell() != null
           && (mob.getCombatState().getCombatStyle() == CombatStyle.AUTOCAST
               || mob.getCombatState().getCombatStyle() == CombatStyle.DEFENSIVE_AUTOCAST))) {
     return MagicCombatAction.getAction();
   }
   Item weapon = mob.getEquipment().get(Equipment.SLOT_WEAPON);
   if (weapon != null) {
     EquipmentDefinition weaponEquipDef = weapon.getEquipmentDefinition();
     if (weaponEquipDef.getBowType() != null || weaponEquipDef.getRangeWeaponType() != null) {
       return RangeCombatAction.getAction();
     }
   }
   return MeleeCombatAction.getAction();
 }
Esempio n. 7
0
  /** Calculates a mob's range max hit. */
  public static int calculateRangeMaxHit(Mob mob, boolean special) {
    if (mob.isNPC()) {
      NPC npc = (NPC) mob;
      return npc.getCombatDefinition().getMaxHit();
    }
    int maxHit = 0;
    double specialMultiplier = 1;
    double prayerMultiplier = 1;
    double otherBonusMultiplier = 1;
    int rangedStrength = mob.getCombatState().getBonus(12);
    Item weapon = mob.getEquipment().get(Equipment.SLOT_WEAPON);
    BowType bow = weapon.getEquipmentDefinition().getBowType();

    if (bow == BowType.CRYSTAL_BOW) {
      /** Crystal Bow does not use arrows, so we don't use the arrows range strength bonus. */
      rangedStrength =
          mob.getEquipment().get(Equipment.SLOT_WEAPON).getEquipmentDefinition().getBonus(12);
    }

    int rangeLevel = mob.getSkills().getLevel(Skills.RANGE);
    int combatStyleBonus = 0;

    switch (mob.getCombatState().getCombatStyle()) {
      case ACCURATE:
        combatStyleBonus = 3;
        break;
    }

    if (fullVoidRange(mob)) {
      otherBonusMultiplier = 1.1;
    }

    int effectiveRangeDamage =
        (int) ((rangeLevel * prayerMultiplier * otherBonusMultiplier) + combatStyleBonus);
    double baseDamage =
        1.3
            + (effectiveRangeDamage / 10)
            + (rangedStrength / 80)
            + ((effectiveRangeDamage * rangedStrength) / 640);

    if (special) {
      if (mob.getEquipment().get(Equipment.SLOT_ARROWS) != null) {
        switch (mob.getEquipment().get(Equipment.SLOT_ARROWS).getId()) {
          case 11212:
            specialMultiplier = 1.5;
            break;
          case 9243:
            specialMultiplier = 1.15;
            break;
          case 9244:
            specialMultiplier = 1.45;
            break;
          case 9245:
            specialMultiplier = 1.15;
            break;
          case 9236:
            specialMultiplier = 1.25;
            break;
          case 882:
          case 884:
          case 886:
          case 888:
          case 890:
          case 892:
            if (mob.getEquipment().get(Equipment.SLOT_WEAPON) != null
                && mob.getEquipment().get(Equipment.SLOT_WEAPON).getId() == 11235) {
              specialMultiplier = 1.3;
            }
            break;
        }
      }
    }

    maxHit = (int) (baseDamage * specialMultiplier);

    return maxHit;
  }
Esempio n. 8
0
 public boolean hasItem(Item item) {
   if (getCount(item.getId()) >= 1) {
     return true;
   }
   return false;
 }
Esempio n. 9
0
 /**
  * Removes an item.
  *
  * @param item The item to remove.
  * @param preferredSlot The preferred slot.
  * @param allowZero If a zero amount item should be allowed.
  * @return The number of items removed.
  */
 public int remove(Item item, int preferredSlot, boolean allowZero) {
   int removed = 0;
   if ((item.getDefinition().isStackable() || type.equals(Type.ALWAYS_STACK))
       && !type.equals(Type.NEVER_STACK)) {
     int slot = getSlotById(item.getId());
     Item stack = get(slot);
     if (stack.getCount() > item.getCount()) {
       removed = item.getCount();
       set(slot, new Item(stack.getId(), stack.getCount() - item.getCount()));
     } else {
       removed = stack.getCount();
       set(slot, allowZero ? new Item(stack.getId(), 0) : null);
     }
   } else {
     for (int i = 0; i < item.getCount(); i++) {
       int slot = getSlotById(item.getId());
       if (i == 0 && preferredSlot != -1) {
         Item inSlot = get(preferredSlot);
         if (inSlot.getId() == item.getId()) {
           slot = preferredSlot;
         }
       }
       if (slot != -1) {
         removed++;
         set(slot, null);
       } else {
         break;
       }
     }
   }
   return removed;
 }