Пример #1
0
 public int getRandomQuantity() {
   if (this.maximum == 1) {
     return 1;
   } else {
     return Randomizer.nextInt(this.maximum - this.minimum) + this.minimum;
   }
 }
Пример #2
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   if (!c.getPlayer().isAlive()) {
     c.announce(MaplePacketCreator.enableActions());
     return;
   }
   slea.readInt();
   byte slot = (byte) slea.readShort();
   int itemId = slea.readInt();
   MapleCharacter player = c.getPlayer();
   IItem toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
   if (toUse != null && toUse.getQuantity() == 1) {
     if (toUse.getItemId() != itemId) {
       return;
     }
     Map<String, Integer> skilldata =
         MapleItemInformationProvider.getInstance()
             .getSkillStats(toUse.getItemId(), c.getPlayer().getJob().getId());
     boolean canuse = false;
     boolean success = false;
     int skill = 0;
     int maxlevel = 0;
     if (skilldata == null) {
       return;
     }
     if (skilldata.get("skillid") == 0) {
       canuse = false;
     } else if (player.getMasterLevel(SkillFactory.getSkill(skilldata.get("skillid")))
             >= skilldata.get("reqSkillLevel")
         || skilldata.get("reqSkillLevel") == 0) {
       canuse = true;
       if (Randomizer.nextInt(101) < skilldata.get("success") && skilldata.get("success") != 0) {
         success = true;
         ISkill skill2 = SkillFactory.getSkill(skilldata.get("skillid"));
         player.changeSkillLevel(
             skill2,
             player.getSkillLevel(skill2),
             Math.max(skilldata.get("masterLevel"), player.getMasterLevel(skill2)),
             -1);
       } else {
         success = false;
         player.message(
             "The skill book lights up, but the skill winds up as if nothing happened.");
       }
       MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
     } else {
       canuse = false;
     }
     player
         .getClient()
         .announce(MaplePacketCreator.skillBookSuccess(player, skill, maxlevel, canuse, success));
   }
 }
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {

    String pic = slea.readMapleAsciiString();
    int charId = slea.readInt();
    byte world = (byte) slea.readInt(); // world
    c.setWorld(world);
    byte channel =
        (byte) Randomizer.rand(0, Server.getInstance().getWorld(world).getChannels().size());
    c.setChannel(channel);
    String macs = slea.readMapleAsciiString();
    c.updateMacs(macs);

    if (c.hasBannedMac()) {
      c.getSession().close(true);
      return;
    }
    if (c.checkPic(pic)) {
      try {
        if (c.getIdleTask() != null) {
          c.getIdleTask().cancel(true);
        }
        c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);

        String channelServerIP =
            MapleClient.getChannelServerIPFromSubnet(
                c.getSession().getRemoteAddress().toString().replace("/", "").split(":")[0],
                channel);
        if (channelServerIP.equals("0.0.0.0")) {
          String[] socket = Server.getInstance().getIP(world, channel).split(":");

          c.announce(
              MaplePacketCreator.getServerIP(
                  InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]), charId));
        } else {
          String[] socket = Server.getInstance().getIP(world, channel).split(":");
          c.announce(
              MaplePacketCreator.getServerIP(
                  InetAddress.getByName(channelServerIP), Integer.parseInt(socket[1]), charId));
        }
      } catch (UnknownHostException e) {
        log.error("Host not found", e);
      }

    } else {

      c.announce(MaplePacketCreator.wrongPic());
    }
  }
Пример #4
0
 public void applyEffect(MapleCharacter player, MapleMonster monster, boolean skill) {
   MapleDisease disease = null;
   Map<MonsterStatus, Integer> stats = new ArrayMap<MonsterStatus, Integer>();
   List<Integer> reflection = new LinkedList<Integer>();
   switch (skillId) {
     case 100:
     case 110:
     case 150:
       stats.put(MonsterStatus.WEAPON_ATTACK_UP, Integer.valueOf(x));
       break;
     case 101:
     case 111:
     case 151:
       stats.put(MonsterStatus.MAGIC_ATTACK_UP, Integer.valueOf(x));
       break;
     case 102:
     case 112:
     case 152:
       stats.put(MonsterStatus.WEAPON_DEFENSE_UP, Integer.valueOf(x));
       break;
     case 103:
     case 113:
     case 153:
       stats.put(MonsterStatus.MAGIC_DEFENSE_UP, Integer.valueOf(x));
       break;
     case 114:
       if (lt != null && rb != null && skill) {
         List<MapleMapObject> objects = getObjectsInRange(monster, MapleMapObjectType.MONSTER);
         final int hps = (getX() / 1000) * (int) (950 + 1050 * Math.random());
         for (MapleMapObject mons : objects) {
           ((MapleMonster) mons).heal(hps, getY());
         }
       } else {
         monster.heal(getX(), getY());
       }
       break;
     case 120:
       disease = MapleDisease.SEAL;
       break;
     case 121:
       disease = MapleDisease.DARKNESS;
       break;
     case 122:
       disease = MapleDisease.WEAKEN;
       break;
     case 123:
       disease = MapleDisease.STUN;
       break;
     case 124:
       disease = MapleDisease.CURSE;
       break;
     case 125:
       disease = MapleDisease.POISON;
       break;
     case 126: // Slow
       disease = MapleDisease.SLOW;
       break;
     case 127:
       if (lt != null && rb != null && skill) {
         for (MapleCharacter character : getPlayersInRange(monster, player)) {
           character.dispel();
         }
       } else {
         player.dispel();
       }
       break;
     case 128: // Seduce
       disease = MapleDisease.SEDUCE;
       break;
     case 129: // Banish
       if (lt != null && rb != null && skill) {
         for (MapleCharacter chr : getPlayersInRange(monster, player)) {
           chr.changeMapBanish(
               monster.getBanish().getMap(),
               monster.getBanish().getPortal(),
               monster.getBanish().getMsg());
         }
       } else {
         player.changeMapBanish(
             monster.getBanish().getMap(),
             monster.getBanish().getPortal(),
             monster.getBanish().getMsg());
       }
       break;
     case 131: // Mist
       monster
           .getMap()
           .spawnMist(
               new MapleMist(calculateBoundingBox(monster.getPosition(), true), monster, this),
               x * 10,
               false,
               false);
       break;
     case 132:
       disease = MapleDisease.CONFUSE;
       break;
     case 133: // zombify
       break;
     case 140:
       if (makeChanceResult() && !monster.isBuffed(MonsterStatus.MAGIC_IMMUNITY)) {
         stats.put(MonsterStatus.WEAPON_IMMUNITY, Integer.valueOf(x));
       }
       break;
     case 141:
       if (makeChanceResult() && !monster.isBuffed(MonsterStatus.WEAPON_IMMUNITY)) {
         stats.put(MonsterStatus.MAGIC_IMMUNITY, Integer.valueOf(x));
       }
       break;
     case 143: // Weapon Reflect
       stats.put(MonsterStatus.WEAPON_REFLECT, Integer.valueOf(x));
       stats.put(MonsterStatus.WEAPON_IMMUNITY, Integer.valueOf(x));
       reflection.add(x);
       break;
     case 144: // Magic Reflect
       stats.put(MonsterStatus.MAGIC_REFLECT, Integer.valueOf(x));
       stats.put(MonsterStatus.MAGIC_IMMUNITY, Integer.valueOf(x));
       reflection.add(x);
       break;
     case 145: // Weapon / Magic reflect
       stats.put(MonsterStatus.WEAPON_REFLECT, Integer.valueOf(x));
       stats.put(MonsterStatus.WEAPON_IMMUNITY, Integer.valueOf(x));
       stats.put(MonsterStatus.MAGIC_REFLECT, Integer.valueOf(x));
       stats.put(MonsterStatus.MAGIC_IMMUNITY, Integer.valueOf(x));
       reflection.add(x);
       break;
     case 154: // accuracy up
     case 155: // avoid up
     case 156: // speed up
       break;
     case 200:
       if (monster.getMap().getSpawnedMonstersOnMap() < 80) {
         for (Integer mobId : getSummons()) {
           MapleMonster toSpawn = MapleLifeFactory.getMonster(mobId);
           toSpawn.setPosition(monster.getPosition());
           int ypos, xpos;
           xpos = (int) monster.getPosition().getX();
           ypos = (int) monster.getPosition().getY();
           switch (mobId) {
             case 8500003: // Pap bomb high
               toSpawn.setFh((int) Math.ceil(Math.random() * 19.0));
               ypos = -590;
               break;
             case 8500004: // Pap bomb
               xpos = (int) (monster.getPosition().getX() + Randomizer.nextInt(1000) - 500);
               if (ypos != -590) {
                 ypos = (int) monster.getPosition().getY();
               }
               break;
             case 8510100: // Pianus bomb
               if (Math.ceil(Math.random() * 5) == 1) {
                 ypos = 78;
                 xpos = (int) Randomizer.nextInt(5) + (Randomizer.nextInt(2) == 1 ? 180 : 0);
               } else {
                 xpos = (int) (monster.getPosition().getX() + Randomizer.nextInt(1000) - 500);
               }
               break;
           }
           switch (monster.getMap().getId()) {
             case 220080001: // Pap map
               if (xpos < -890) {
                 xpos = (int) (Math.ceil(Math.random() * 150) - 890);
               } else if (xpos > 230) {
                 xpos = (int) (230 - Math.ceil(Math.random() * 150));
               }
               break;
             case 230040420: // Pianus map
               if (xpos < -239) {
                 xpos = (int) (Math.ceil(Math.random() * 150) - 239);
               } else if (xpos > 371) {
                 xpos = (int) (371 - Math.ceil(Math.random() * 150));
               }
               break;
           }
           toSpawn.setPosition(new Point(xpos, ypos));
           monster
               .getMap()
               .spawnMonsterWithEffect(toSpawn, getSpawnEffect(), toSpawn.getPosition());
         }
       }
       break;
   }
   if (stats.size() > 0) {
     if (lt != null && rb != null && skill) {
       for (MapleMapObject mons : getObjectsInRange(monster, MapleMapObjectType.MONSTER)) {
         ((MapleMonster) mons)
             .applyMonsterBuff(stats, getX(), getSkillId(), getDuration(), this, reflection);
       }
     } else {
       monster.applyMonsterBuff(stats, getX(), getSkillId(), getDuration(), this, reflection);
     }
   }
   if (disease != null) {
     if (lt != null && rb != null && skill) {
       int i = 0;
       for (MapleCharacter character : getPlayersInRange(monster, player)) {
         if (!character.isActiveBuffedValue(2321005)) {
           if (disease.equals(MapleDisease.SEDUCE)) {
             if (i < 10) {
               character.giveDebuff(MapleDisease.SEDUCE, this);
               i++;
             }
           } else {
             character.giveDebuff(disease, this);
           }
         }
       }
     } else {
       player.giveDebuff(disease, this);
     }
   }
   monster.usedSkill(skillId, skillLevel, cooltime);
   monster.setMp(monster.getMp() - getMpCon());
 }
Пример #5
0
 public MapleOxQuiz(MapleMap map) {
   this.map = map;
   this.round = Randomizer.getInstance().nextInt(9);
   this.question = 1;
 }
Пример #6
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   int objectid = slea.readInt();
   short moveid = slea.readShort();
   MapleMapObject mmo = c.getPlayer().getMap().getMapObject(objectid);
   if (mmo == null || mmo.getType() != MapleMapObjectType.MONSTER) {
     return;
   }
   MapleMonster monster = (MapleMonster) mmo;
   List<LifeMovementFragment> res = null;
   byte skillByte = slea.readByte();
   byte skill = slea.readByte();
   int skill_1 = slea.readByte() & 0xFF;
   byte skill_2 = slea.readByte();
   byte skill_3 = slea.readByte();
   slea.readByte();
   slea.readLong(); // v88 change
   MobSkill toUse = null;
   if (skillByte == 1 && monster.getNoSkills() > 0) {
     int random = Randomizer.getInstance().nextInt(monster.getNoSkills());
     Pair<Integer, Integer> skillToUse = monster.getSkills().get(random);
     toUse = MobSkillFactory.getMobSkill(skillToUse.getLeft(), skillToUse.getRight());
     int percHpLeft = (monster.getHp() / monster.getMaxHp()) * 100;
     if (toUse.getHP() < percHpLeft || !monster.canUseSkill(toUse)) {
       toUse = null;
     }
   }
   if ((skill_1 >= 100 && skill_1 <= 200) && monster.hasSkill(skill_1, skill_2)) {
     MobSkill skillData = MobSkillFactory.getMobSkill(skill_1, skill_2);
     if (skillData != null && monster.canUseSkill(skillData)) {
       skillData.applyEffect(c.getPlayer(), monster, true);
     }
   }
   slea.readByte();
   slea.readInt(); // whatever
   slea.skip(12); // v88 skip
   short start_x = slea.readShort(); // hmm.. startpos?
   short start_y = slea.readShort(); // hmm...
   slea.readInt(); // v88 skip
   Point startPos = new Point(start_x, start_y);
   res = parseMovement(slea);
   if (monster.getController() != c.getPlayer()) {
     if (monster.isAttackedBy(c.getPlayer())) { // aggro and controller change
       monster.switchController(c.getPlayer(), true);
     } else {
       return;
     }
   } else if (skill == -1
       && monster.isControllerKnowsAboutAggro()
       && !monster.isMobile()
       && !monster.isFirstAttack()) {
     monster.setControllerHasAggro(false);
     monster.setControllerKnowsAboutAggro(false);
   }
   boolean aggro = monster.isControllerHasAggro();
   if (toUse != null) {
     c.getSession()
         .write(
             MaplePacketCreator.moveMonsterResponse(
                 objectid,
                 moveid,
                 monster.getMp(),
                 aggro,
                 toUse.getSkillId(),
                 toUse.getSkillLevel()));
   } else {
     c.getSession()
         .write(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro));
   }
   if (aggro) {
     monster.setControllerKnowsAboutAggro(true);
   }
   if (res != null && slea.available() == 17) {
     c.getPlayer()
         .getMap()
         .broadcastMessage(
             c.getPlayer(),
             MaplePacketCreator.moveMonster(
                 skillByte, skill, skill_1, skill_2, skill_3, objectid, startPos, res),
             monster.getPosition());
     updatePosition(res, monster, -1);
     c.getPlayer().getMap().moveMonster(monster, monster.getPosition());
   }
 }
Пример #7
0
  public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    slea.readInt(); // whatever...
    byte slot = (byte) slea.readShort();
    byte dst = (byte) slea.readShort();
    byte ws = (byte) slea.readShort();
    boolean whiteScroll = false; // white scroll being used?
    boolean legendarySpirit = false; // legendary spirit skill
    if ((ws & 2) == 2) {
      whiteScroll = true;
    }
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    IEquip toScroll = (IEquip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
    ISkill LegendarySpirit = SkillFactory.getSkill(1003);
    if (c.getPlayer().getSkillLevel(LegendarySpirit) > 0 && dst >= 0) {
      legendarySpirit = true;
      toScroll = (IEquip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(dst);
    }
    byte oldLevel = toScroll.getLevel();
    if (((IEquip) toScroll).getUpgradeSlots() < 1) {
      c.announce(MaplePacketCreator.getInventoryFull());
      return;
    }
    MapleInventory useInventory = c.getPlayer().getInventory(MapleInventoryType.USE);
    IItem scroll = useInventory.getItem(slot);
    IItem wscroll = null;
    List<Integer> scrollReqs = ii.getScrollReqs(scroll.getItemId());
    if (scrollReqs.size() > 0 && !scrollReqs.contains(toScroll.getItemId())) {
      c.announce(MaplePacketCreator.getInventoryFull());
      return;
    }
    if (whiteScroll) {
      wscroll = useInventory.findById(2340000);
      if (wscroll == null || wscroll.getItemId() != 2340000) {
        whiteScroll = false;
      }
    }
    if (scroll.getItemId() != 2049100 && !isCleanSlate(scroll.getItemId())) {
      if (!canScroll(scroll.getItemId(), toScroll.getItemId())) {
        return;
      }
    }
    if (scroll.getQuantity() < 1) {
      return;
    }
    try {
      IEquip scrolled = null;
      ScrollResult scrollSuccess = null;
      int sExpAdd = 0;
      Enchantment enchantment =
          (Enchantment) c.getPlayer().getPowerSkill(PowerSkillType.ENCHANTMENT);
      boolean isMultiScroll = enchantment.getMultiScrollChance() > Randomizer.nextFloat();
      int scrollMulti = 1 + (isMultiScroll ? enchantment.getMultiScrollAmount() : 0);
      if (scrollMulti > 1) sExpAdd += Randomizer.rand(0, 4);
      boolean removeSlot = enchantment.getNoSlotUse() > Randomizer.nextFloat();
      if (scrollMulti > scroll.getQuantity()) {
        scrollMulti = scroll.getQuantity();
      }
      int scrollCount = 0;
      while (scroll.getQuantity() > 0 && scrollMulti > 0) {
        scrollMulti--;
        scrollCount++;
        int scrollRerolls = enchantment.getRerolls();
        sExpAdd += scrollRerolls;

        float statMultiplier = 1 + enchantment.getExtraStats();
        if (statMultiplier > 1) sExpAdd++;

        scrolled =
            (IEquip)
                ii.scrollEquipWithId(
                    toScroll,
                    scroll.getItemId(),
                    whiteScroll,
                    removeSlot,
                    scrollRerolls,
                    statMultiplier,
                    c.getPlayer().isGM());

        if (scrolled != null && enchantment.getDoubleScroll() > Randomizer.nextFloat()) {
          scrolled =
              (IEquip)
                  ii.scrollEquipWithId(
                      scrolled,
                      scroll.getItemId(),
                      whiteScroll,
                      removeSlot,
                      scrollRerolls,
                      statMultiplier,
                      c.getPlayer().isGM());
        }

        scrollSuccess = IEquip.ScrollResult.FAIL; // fail
        if (scrolled == null) {
          scrollSuccess = IEquip.ScrollResult.CURSE;
        } else if (scrolled.getLevel() > oldLevel
            || (isCleanSlate(scroll.getItemId()) && scrolled.getLevel() == oldLevel + 1)) {
          scrollSuccess = IEquip.ScrollResult.SUCCESS;
        }
        useInventory.removeItem(scroll.getPosition(), (short) 1, false);
        if (whiteScroll) {
          useInventory.removeItem(wscroll.getPosition(), (short) 1, false);
          if (wscroll.getQuantity() < 1) {
            c.announce(
                MaplePacketCreator.clearInventoryItem(
                    MapleInventoryType.USE, wscroll.getPosition(), false));
          } else {
            c.announce(
                MaplePacketCreator.updateInventorySlot(MapleInventoryType.USE, (Item) wscroll));
          }
        }
        c.getPlayer()
            .getMap()
            .broadcastMessage(
                MaplePacketCreator.getScrollEffect(
                    c.getPlayer().getId(), scrollSuccess, legendarySpirit));
        if (scrollSuccess == IEquip.ScrollResult.CURSE) {
          break;
        }
      }
      if (scrollSuccess == IEquip.ScrollResult.CURSE) {
        scrollMulti = 0;
        c.announce(MaplePacketCreator.scrolledItem(scroll, toScroll, true));
        if (dst < 0) {
          c.getPlayer()
              .getInventory(MapleInventoryType.EQUIPPED)
              .removeItem(toScroll.getPosition());
        } else {
          c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeItem(toScroll.getPosition());
        }
      } else {
        c.announce(MaplePacketCreator.scrolledItem(scroll, scrolled, false));
      }
      if (dst < 0
          && (scrollSuccess == IEquip.ScrollResult.SUCCESS
              || scrollSuccess == IEquip.ScrollResult.CURSE)) {
        c.getPlayer().equipChanged();
      }
      // sExpAdd /= initMulti;
      if (scrollCount > 1)
        c.getPlayer().message("You have successfully multi-scrolled " + scrollCount + " times!");
      c.getPlayer().addPowerSkillExp(PowerSkillType.ENCHANTMENT, sExpAdd + Randomizer.nextInt(4));
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }