use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.
the class Commands method executeHeavenMsCommandLv2.
public static boolean executeHeavenMsCommandLv2(Channel cserv, Server srv, MapleClient c, String[] sub) {
// JrGM
MapleCharacter player = c.getPlayer();
MapleCharacter victim;
Skill skill;
switch(sub[0]) {
case "hide":
SkillFactory.getSkill(9101004).getEffect(SkillFactory.getSkill(9101004).getMaxLevel()).applyTo(player);
break;
case "unhide":
SkillFactory.getSkill(9101004).getEffect(SkillFactory.getSkill(9101004).getMaxLevel()).applyTo(player);
break;
case "sp":
if (sub.length < 2) {
player.yellowMessage("Syntax: !sp [<playername>] <newsp>");
break;
}
if (sub.length == 2) {
int newSp = Integer.parseInt(sub[1]);
if (newSp < 0)
newSp = 0;
else if (newSp > ServerConstants.MAX_AP)
newSp = ServerConstants.MAX_AP;
player.setRemainingSp(newSp);
player.updateSingleStat(MapleStat.AVAILABLESP, player.getRemainingSp());
} else {
victim = c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
int newSp = Integer.parseInt(sub[2]);
if (newSp < 0)
newSp = 0;
else if (newSp > ServerConstants.MAX_AP)
newSp = ServerConstants.MAX_AP;
victim.setRemainingSp(newSp);
victim.updateSingleStat(MapleStat.AVAILABLESP, player.getRemainingSp());
player.dropMessage(5, "SP given.");
} else {
player.message("Player '" + sub[1] + "' could not be found on this channel.");
}
}
break;
case "ap":
if (sub.length < 2) {
player.yellowMessage("Syntax: !ap [<playername>] <newap>");
break;
}
if (sub.length < 3) {
int newAp = Integer.parseInt(sub[1]);
if (newAp < 0)
newAp = 0;
else if (newAp > ServerConstants.MAX_AP)
newAp = ServerConstants.MAX_AP;
player.setRemainingAp(newAp);
player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
} else {
victim = c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
int newAp = Integer.parseInt(sub[2]);
if (newAp < 0)
newAp = 0;
else if (newAp > ServerConstants.MAX_AP)
newAp = ServerConstants.MAX_AP;
victim.setRemainingAp(newAp);
victim.updateSingleStat(MapleStat.AVAILABLEAP, victim.getRemainingAp());
} else {
player.message("Player '" + sub[1] + "' could not be found on this channel.");
}
}
break;
case "empowerme":
final int[] array = { 2311003, 2301004, 1301007, 4101004, 2001002, 1101007, 1005, 2301003, 5121009, 1111002, 4111001, 4111002, 4211003, 4211005, 1321000, 2321004, 3121002 };
for (int i : array) {
SkillFactory.getSkill(i).getEffect(SkillFactory.getSkill(i).getMaxLevel()).applyTo(player);
}
break;
case "buffmap":
SkillFactory.getSkill(9101001).getEffect(SkillFactory.getSkill(9101001).getMaxLevel()).applyTo(player, true);
SkillFactory.getSkill(9101002).getEffect(SkillFactory.getSkill(9101002).getMaxLevel()).applyTo(player, true);
SkillFactory.getSkill(9101003).getEffect(SkillFactory.getSkill(9101003).getMaxLevel()).applyTo(player, true);
SkillFactory.getSkill(9101008).getEffect(SkillFactory.getSkill(9101008).getMaxLevel()).applyTo(player, true);
SkillFactory.getSkill(1005).getEffect(SkillFactory.getSkill(1005).getMaxLevel()).applyTo(player, true);
break;
case "buff":
if (sub.length < 2) {
player.yellowMessage("Syntax: !buff <buffid>");
break;
}
int skillid = Integer.parseInt(sub[1]);
skill = SkillFactory.getSkill(skillid);
if (skill != null)
skill.getEffect(skill.getMaxLevel()).applyTo(player);
break;
case "bomb":
if (sub.length > 1) {
victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
victim.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(9300166), victim.getPosition());
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(5, player.getName() + " used !bomb on " + victim.getName()));
} else {
player.message("Player '" + sub[1] + "' could not be found on this world.");
}
} else {
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(9300166), player.getPosition());
}
break;
case "dc":
if (sub.length < 2) {
player.yellowMessage("Syntax: !dc <playername>");
break;
}
victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
if (victim == null) {
victim = c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
if (victim == null) {
victim = player.getMap().getCharacterByName(sub[1]);
if (victim != null) {
try {
// sometimes bugged because the map = null
victim.getClient().disconnect(true, false);
player.getMap().removePlayer(victim);
} catch (Exception e) {
e.printStackTrace();
}
} else {
break;
}
}
}
if (player.gmLevel() < victim.gmLevel()) {
victim = player;
}
victim.getClient().disconnect(false, false);
break;
case "cleardrops":
player.getMap().clearDrops(player);
player.dropMessage(5, "Cleared dropped items");
break;
case "clearslot":
if (sub.length < 2) {
player.yellowMessage("Syntax: !clearslot <all, equip, use, setup, etc or cash.>");
break;
}
String type = sub[1];
if (type.equals("all")) {
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.EQUIP, (byte) i, tempItem.getQuantity(), false, true);
}
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, (byte) i, tempItem.getQuantity(), false, true);
}
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.ETC).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.ETC, (byte) i, tempItem.getQuantity(), false, true);
}
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.SETUP).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.SETUP, (byte) i, tempItem.getQuantity(), false, true);
}
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.CASH).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.CASH, (byte) i, tempItem.getQuantity(), false, true);
}
player.yellowMessage("All Slots Cleared.");
} else if (type.equals("equip")) {
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.EQUIP, (byte) i, tempItem.getQuantity(), false, true);
}
player.yellowMessage("Equipment Slot Cleared.");
} else if (type.equals("use")) {
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, (byte) i, tempItem.getQuantity(), false, true);
}
player.yellowMessage("Use Slot Cleared.");
} else if (type.equals("setup")) {
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.SETUP).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.SETUP, (byte) i, tempItem.getQuantity(), false, true);
}
player.yellowMessage("Set-Up Slot Cleared.");
} else if (type.equals("etc")) {
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.ETC).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.ETC, (byte) i, tempItem.getQuantity(), false, true);
}
player.yellowMessage("ETC Slot Cleared.");
} else if (type.equals("cash")) {
for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.CASH).getItem((byte) i);
if (tempItem == null)
continue;
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.CASH, (byte) i, tempItem.getQuantity(), false, true);
}
player.yellowMessage("Cash Slot Cleared.");
} else
player.yellowMessage("Slot" + type + " does not exist!");
break;
case "warp":
if (sub.length < 2) {
player.yellowMessage("Syntax: !warp <mapid>");
break;
}
try {
MapleMap target = c.getChannelServer().getMapFactory().getMap(Integer.parseInt(sub[1]));
if (target == null) {
player.yellowMessage("Map ID " + sub[1] + " is invalid.");
break;
}
if (player.getEventInstance() != null) {
player.getEventInstance().leftParty(player);
}
player.changeMap(target, target.getRandomPlayerSpawnpoint());
} catch (Exception ex) {
player.yellowMessage("Map ID " + sub[1] + " is invalid.");
break;
}
break;
case "warpto":
if (sub.length < 3) {
player.yellowMessage("Syntax: !warpto <playername> <mapid>");
break;
}
victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
if (victim == null) {
// If victim isn't on current channel or isnt a character try and find him by loop all channels on current world.
for (Channel ch : srv.getChannelsFromWorld(c.getWorld())) {
victim = ch.getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
// We found the person, no need to continue the loop.
break;
}
}
}
if (victim != null) {
// Remove warper from current event instance.
if (player.getEventInstance() != null) {
player.getEventInstance().unregisterPlayer(player);
}
// Attempt to join the victims warp instance.
if (victim.getEventInstance() != null) {
if (victim.getClient().getChannel() == player.getClient().getChannel()) {
// just in case.. you never know...
// victim.getEventInstance().registerPlayer(player);
player.changeMap(victim.getEventInstance().getMapInstance(victim.getMapId()), victim.getMap().findClosestPortal(victim.getPosition()));
} else {
player.dropMessage(6, "Please change to channel " + victim.getClient().getChannel());
}
} else {
// If victim isn't in an event instance, just warp them.
player.changeMap(victim.getMapId(), victim.getMap().findClosestPortal(victim.getPosition()));
}
if (player.getClient().getChannel() != victim.getClient().getChannel()) {
// And then change channel if needed.
player.dropMessage("Changing channel, please wait a moment.");
player.getClient().changeChannel(victim.getClient().getChannel());
}
} else {
player.dropMessage(6, "Unknown player.");
}
break;
case "warphere":
case "summon":
if (sub.length < 2) {
player.yellowMessage("Syntax: !warphere <playername>");
break;
}
victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
if (victim == null) {
// If victim isn't on current channel, loop all channels on current world.
for (Channel ch : srv.getChannelsFromWorld(c.getWorld())) {
victim = ch.getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
// We found the person, no need to continue the loop.
break;
}
}
}
if (victim != null) {
boolean changingEvent = true;
if (victim.getEventInstance() != null) {
if (player.getEventInstance() != null && victim.getEventInstance().getLeaderId() == player.getEventInstance().getLeaderId()) {
changingEvent = false;
} else {
victim.getEventInstance().unregisterPlayer(victim);
}
}
// Attempt to join the warpers instance.
if (player.getEventInstance() != null && changingEvent) {
if (player.getClient().getChannel() == victim.getClient().getChannel()) {
// just in case.. you never know...
player.getEventInstance().registerPlayer(victim);
victim.changeMap(player.getEventInstance().getMapInstance(player.getMapId()), player.getMap().findClosestPortal(player.getPosition()));
} else {
player.dropMessage("Target isn't on your channel, not able to warp into event instance.");
}
} else {
// If victim isn't in an event instance or is in the same event instance as the one the caller is, just warp them.
victim.changeMap(player.getMapId(), player.getMap().findClosestPortal(player.getPosition()));
}
if (player.getClient().getChannel() != victim.getClient().getChannel()) {
// And then change channel if needed.
victim.dropMessage("Changing channel, please wait a moment.");
victim.getClient().changeChannel(player.getClient().getChannel());
}
} else {
player.dropMessage(6, "Unknown player.");
}
break;
case "reach":
if (sub.length < 2) {
player.yellowMessage("Syntax: !reach <playername>");
break;
}
victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null && victim.isLoggedin()) {
if (player.getClient().getChannel() != victim.getClient().getChannel()) {
player.dropMessage(5, "Player '" + victim.getName() + "' is at channel " + victim.getClient().getChannel() + ".");
} else {
MapleMap map = victim.getMap();
player.changeMap(map, map.findClosestPortal(victim.getPosition()));
}
} else {
player.dropMessage(6, "Unknown player.");
}
break;
case "gmshop":
MapleShopFactory.getInstance().getShop(1337).sendShop(c);
break;
case "heal":
player.setHpMp(30000);
break;
case "item":
case "drop":
if (sub.length < 2) {
player.yellowMessage("Syntax: !item <itemid> <quantity>");
break;
}
int itemId = Integer.parseInt(sub[1]);
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (ii.getName(itemId) == null) {
player.yellowMessage("Item id '" + sub[1] + "' does not exist.");
break;
}
short quantity = 1;
if (sub.length >= 3)
quantity = Short.parseShort(sub[2]);
if (ServerConstants.BLOCK_GENERATE_CASH_ITEM && ii.isCash(itemId)) {
player.yellowMessage("You cannot create a cash item with this command.");
break;
}
if (ItemConstants.isPet(itemId)) {
if (sub.length >= 3) {
// thanks to istreety & TacoBell
quantity = 1;
long days = Math.max(1, Integer.parseInt(sub[2]));
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
int petid = MaplePet.createPet(itemId);
if (sub[0].equals("item")) {
MapleInventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, expiration);
} else {
Item toDrop = new Item(itemId, (short) 0, quantity, petid);
toDrop.setExpiration(expiration);
toDrop.setOwner("");
if (player.gmLevel() < 3) {
byte b = toDrop.getFlag();
b |= ItemConstants.ACCOUNT_SHARING;
b |= ItemConstants.UNTRADEABLE;
toDrop.setFlag(b);
}
c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true, true);
}
break;
} else {
player.yellowMessage("Pet Syntax: !item <itemid> <expiration>");
break;
}
}
if (sub[0].equals("item")) {
byte flag = 0;
if (player.gmLevel() < 3) {
flag |= ItemConstants.ACCOUNT_SHARING;
flag |= ItemConstants.UNTRADEABLE;
}
MapleInventoryManipulator.addById(c, itemId, quantity, player.getName(), -1, flag, -1);
} else {
Item toDrop;
if (ItemConstants.getInventoryType(itemId) == MapleInventoryType.EQUIP) {
toDrop = ii.getEquipById(itemId);
} else {
toDrop = new Item(itemId, (short) 0, quantity);
}
toDrop.setOwner(player.getName());
if (player.gmLevel() < 3) {
byte b = toDrop.getFlag();
b |= ItemConstants.ACCOUNT_SHARING;
b |= ItemConstants.UNTRADEABLE;
toDrop.setFlag(b);
}
c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true, true);
}
break;
case "level":
if (sub.length < 2) {
player.yellowMessage("Syntax: !level <newlevel>");
break;
}
player.loseExp(player.getExp(), false, false);
player.setLevel(Math.min(Integer.parseInt(sub[1]), player.getMaxClassLevel()) - 1);
player.resetPlayerRates();
if (ServerConstants.USE_ADD_RATES_BY_LEVEL == true)
player.setPlayerRates();
player.setWorldRates();
player.levelUp(false);
break;
case "levelpro":
if (sub.length < 2) {
player.yellowMessage("Syntax: !levelpro <newlevel>");
break;
}
while (player.getLevel() < Math.min(player.getMaxClassLevel(), Integer.parseInt(sub[1]))) {
player.levelUp(false);
}
break;
case "setstat":
if (sub.length < 2) {
player.yellowMessage("Syntax: !setstat <newstat>");
break;
}
int x;
try {
x = Integer.parseInt(sub[1]);
if (x > Short.MAX_VALUE)
x = Short.MAX_VALUE;
else if (x < 0)
x = 0;
player.setStr(x);
player.setDex(x);
player.setInt(x);
player.setLuk(x);
player.updateSingleStat(MapleStat.STR, x);
player.updateSingleStat(MapleStat.DEX, x);
player.updateSingleStat(MapleStat.INT, x);
player.updateSingleStat(MapleStat.LUK, x);
} catch (NumberFormatException nfe) {
}
break;
case "maxstat":
final String[] s = { "setstat", String.valueOf(Short.MAX_VALUE) };
executeHeavenMsCommandLv2(cserv, srv, c, s);
player.loseExp(player.getExp(), false, false);
player.setLevel(255);
player.resetPlayerRates();
if (ServerConstants.USE_ADD_RATES_BY_LEVEL == true)
player.setPlayerRates();
player.setWorldRates();
player.setFame(13337);
player.setMaxHp(30000);
player.setMaxMp(30000);
player.updateSingleStat(MapleStat.LEVEL, 255);
player.updateSingleStat(MapleStat.FAME, 13337);
player.updateSingleStat(MapleStat.MAXHP, 30000);
player.updateSingleStat(MapleStat.MAXMP, 30000);
player.yellowMessage("Stats maxed out.");
break;
case "maxskill":
for (MapleData skill_ : MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz")).getData("Skill.img").getChildren()) {
try {
skill = SkillFactory.getSkill(Integer.parseInt(skill_.getName()));
player.changeSkillLevel(skill, (byte) skill.getMaxLevel(), skill.getMaxLevel(), -1);
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
break;
} catch (NullPointerException npe) {
continue;
}
}
if (player.getJob().isA(MapleJob.ARAN1) || player.getJob().isA(MapleJob.LEGEND)) {
skill = SkillFactory.getSkill(5001005);
player.changeSkillLevel(skill, (byte) -1, -1, -1);
} else {
skill = SkillFactory.getSkill(21001001);
player.changeSkillLevel(skill, (byte) -1, -1, -1);
}
player.yellowMessage("Skills maxed out.");
break;
case "mesos":
if (sub.length >= 2) {
player.gainMeso(Integer.parseInt(sub[1]), true);
}
break;
case "search":
if (sub.length < 3) {
player.yellowMessage("Syntax: !search <type> <name>");
break;
}
StringBuilder sb = new StringBuilder();
String search = joinStringFrom(sub, 2);
// for the lulz
long start = System.currentTimeMillis();
MapleData data = null;
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File("wz/String.wz"));
if (!sub[1].equalsIgnoreCase("ITEM")) {
if (sub[1].equalsIgnoreCase("NPC")) {
data = dataProvider.getData("Npc.img");
} else if (sub[1].equalsIgnoreCase("MOB") || sub[1].equalsIgnoreCase("MONSTER")) {
data = dataProvider.getData("Mob.img");
} else if (sub[1].equalsIgnoreCase("SKILL")) {
data = dataProvider.getData("Skill.img");
/*} else if (sub[1].equalsIgnoreCase("MAP")) {
TODO
*/
} else {
sb.append("#bInvalid search.\r\nSyntax: '!search [type] [name]', where [type] is NPC, ITEM, MOB, or SKILL.");
}
if (data != null) {
String name;
for (MapleData searchData : data.getChildren()) {
name = MapleDataTool.getString(searchData.getChildByPath("name"), "NO-NAME");
if (name.toLowerCase().contains(search.toLowerCase())) {
sb.append("#b").append(Integer.parseInt(searchData.getName())).append("#k - #r").append(name).append("\r\n");
}
}
}
} else {
for (Pair<Integer, String> itemPair : MapleItemInformationProvider.getInstance().getAllItems()) {
if (sb.length() < 32654) {
// ohlol
if (itemPair.getRight().toLowerCase().contains(search.toLowerCase())) {
// #v").append(id).append("# #k-
sb.append("#b").append(itemPair.getLeft()).append("#k - #r").append(itemPair.getRight()).append("\r\n");
}
} else {
sb.append("#bCouldn't load all items, there are too many results.\r\n");
break;
}
}
}
if (sb.length() == 0) {
sb.append("#bNo ").append(sub[1].toLowerCase()).append("s found.\r\n");
}
// because I can, and it's free
sb.append("\r\n#kLoaded within ").append((double) (System.currentTimeMillis() - start) / 1000).append(" seconds.");
c.announce(MaplePacketCreator.getNPCTalk(9010000, (byte) 0, sb.toString(), "00 00", (byte) 0));
break;
case "jail":
if (sub.length < 2) {
player.yellowMessage("Syntax: !jail <playername> [<minutes>]");
break;
}
int minutesJailed = 5;
if (sub.length >= 3) {
minutesJailed = Integer.valueOf(sub[2]);
if (minutesJailed <= 0) {
player.yellowMessage("Syntax: !jail <playername> [<minutes>]");
break;
}
}
victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
victim.addJailExpirationTime(minutesJailed * 60 * 1000);
int mapid = 300000012;
if (victim.getMapId() != mapid) {
// those gone to jail won't be changing map anyway
MapleMap target = cserv.getMapFactory().getMap(mapid);
MaplePortal targetPortal = target.getPortal(0);
victim.changeMap(target, targetPortal);
player.message(victim.getName() + " was jailed for " + minutesJailed + " minutes.");
} else {
player.message(victim.getName() + "'s time in jail has been extended for " + minutesJailed + " minutes.");
}
} else {
player.message("Player '" + sub[1] + "' could not be found on this channel.");
}
break;
case "unjail":
if (sub.length < 2) {
player.yellowMessage("Syntax: !unjail <playername>");
break;
}
victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
if (victim.getJailExpirationTimeLeft() <= 0) {
player.message("This player is already free.");
break;
}
victim.removeJailExpirationTime();
victim.message("By lack of concrete proof you are now unjailed. Enjoy freedom!");
player.message(victim.getName() + " was unjailed.");
} else {
player.message("Player '" + sub[1] + "' could not be found on this channel.");
}
break;
case "job":
if (sub.length == 2) {
int jobid = Integer.parseInt(sub[1]);
if (jobid < 0 || jobid >= 2200) {
player.message("Jobid " + jobid + " is not available.");
break;
}
player.changeJob(MapleJob.getById(jobid));
player.equipChanged();
} else if (sub.length == 3) {
victim = c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
if (victim != null) {
int jobid = Integer.parseInt(sub[2]);
if (jobid < 0 || jobid >= 2200) {
player.message("Jobid " + jobid + " is not available.");
break;
}
victim.changeJob(MapleJob.getById(jobid));
player.equipChanged();
} else {
player.message("Player '" + sub[1] + "' could not be found on this channel.");
}
} else {
player.message("Syntax: !job <job id> <opt: IGN of another person>");
}
break;
case "unbug":
c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.enableActions());
break;
default:
return false;
}
return true;
}
use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.
the class Equip method gainItemExp.
public void gainItemExp(MapleClient c, int gain) {
// Ronan's Equip Exp gain method
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (!ii.isUpgradeable(this.getItemId()) || itemLevel >= 30)
return;
int reqLevel = ii.getEquipStats(this.getItemId()).get("reqLevel");
float masteryModifier = (float) ExpTable.getExpNeededForLevel(1) / (float) normalizedMasteryExp(reqLevel);
float elementModifier = (isElemental) ? 0.85f : 0.6f;
float baseExpGain = gain * elementModifier * masteryModifier;
itemExp += baseExpGain;
int expNeeded = ExpTable.getEquipExpNeededForLevel(itemLevel);
if (ServerConstants.USE_DEBUG_SHOW_INFO_EQPEXP)
System.out.println("'" + ii.getName(this.getItemId()) + "' -> EXP Gain: " + gain + " Mastery: " + masteryModifier + " Base gain: " + baseExpGain + " exp: " + itemExp + " / " + expNeeded + ", Kills TNL: " + expNeeded / (baseExpGain / c.getPlayer().getExpRate()));
if (itemExp >= expNeeded) {
while (itemExp >= expNeeded) {
itemExp = (itemExp - expNeeded);
gainLevel(c);
if (itemLevel == ServerConstants.USE_EQUIPMNT_LVLUP) {
itemExp = 0.0f;
break;
}
expNeeded = ExpTable.getEquipExpNeededForLevel(itemLevel);
}
} else {
c.getPlayer().forceUpdateItem(this);
// if(ServerConstants.USE_DEBUG) c.getPlayer().dropMessage("'" + ii.getName(this.getItemId()) + "': " + itemExp + " / " + expNeeded);
}
}
use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.
the class Equip method showEquipFeatures.
public String showEquipFeatures(MapleClient c) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (!ii.isUpgradeable(this.getItemId()))
return "";
String eqpName = ii.getName(getItemId());
String eqpInfo = reachedMaxLevel(eqpName) ? " #e#rMAX LEVEL#k#n" : (" EXP: #e#b" + (int) itemExp + "#k#n / " + ExpTable.getEquipExpNeededForLevel(itemLevel));
return "'" + eqpName + "' -> LV: #e#b" + itemLevel + "#k#n " + eqpInfo + "\r\n";
}
use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.
the class PlayerInteractionHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte mode = slea.readByte();
MapleCharacter chr = c.getPlayer();
if (mode == Action.CREATE.getCode()) {
byte createType = slea.readByte();
if (createType == 3) {
// trade
MapleTrade.startTrade(chr);
} else if (createType == 1) {
// omok mini game
if (chr.getChalkboard() != null || FieldLimit.CANNOTMINIGAME.check(chr.getMap().getFieldLimit())) {
return;
}
String desc = slea.readMapleAsciiString();
// 20 6E 4E
slea.readByte();
// 20 6E 4E
int type = slea.readByte();
MapleMiniGame game = new MapleMiniGame(chr, desc);
chr.setMiniGame(game);
game.setPieceType(type);
game.setGameType("omok");
chr.getMap().addMapObject(game);
chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(chr, 1, 0));
game.sendOmok(c, type);
} else if (createType == 2) {
// matchcard
if (chr.getChalkboard() != null) {
return;
}
String desc = slea.readMapleAsciiString();
// 20 6E 4E
slea.readByte();
// 20 6E 4E
int type = slea.readByte();
MapleMiniGame game = new MapleMiniGame(chr, desc);
game.setPieceType(type);
if (type == 0) {
game.setMatchesToWin(6);
} else if (type == 1) {
game.setMatchesToWin(10);
} else if (type == 2) {
game.setMatchesToWin(15);
}
game.setGameType("matchcard");
chr.setMiniGame(game);
chr.getMap().addMapObject(game);
chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(chr, 1, 0));
game.sendMatchCard(c, type);
} else if (createType == 4 || createType == 5) {
// shop
if (!chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapleMapObjectType.SHOP, MapleMapObjectType.HIRED_MERCHANT)).isEmpty()) {
return;
}
String desc = slea.readMapleAsciiString();
slea.skip(3);
int itemId = slea.readInt();
if (chr.getInventory(MapleInventoryType.CASH).countById(itemId) < 1) {
return;
}
if (GameConstants.isFreeMarketRoom(chr.getMapId()) || itemId > 5030000 && itemId < 5030012 || itemId > 5140000 && itemId < 5140006) {
if (createType == 4) {
MaplePlayerShop shop = new MaplePlayerShop(c.getPlayer(), desc);
chr.setPlayerShop(shop);
chr.getMap().addMapObject(shop);
shop.sendShop(c);
c.getWorldServer().registerPlayerShop(shop);
// c.announce(MaplePacketCreator.getPlayerShopRemoveVisitor(1));
} else {
MapleHiredMerchant merchant = new MapleHiredMerchant(chr, itemId, desc);
chr.setHiredMerchant(merchant);
c.getWorldServer().registerHiredMerchant(merchant);
chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
chr.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, true));
}
}
}
} else if (mode == Action.INVITE.getCode()) {
int otherPlayer = slea.readInt();
if (chr.getId() == chr.getMap().getCharacterById(otherPlayer).getId()) {
return;
}
MapleTrade.inviteTrade(chr, chr.getMap().getCharacterById(otherPlayer));
} else if (mode == Action.DECLINE.getCode()) {
MapleTrade.declineTrade(chr);
} else if (mode == Action.VISIT.getCode()) {
if (chr.getTrade() != null && chr.getTrade().getPartner() != null) {
if (!chr.getTrade().isFullTrade() && !chr.getTrade().getPartner().isFullTrade()) {
MapleTrade.visitTrade(chr, chr.getTrade().getPartner().getChr());
} else {
// Ill be nice and not dc u
c.announce(MaplePacketCreator.enableActions());
return;
}
} else {
int oid = slea.readInt();
MapleMapObject ob = chr.getMap().getMapObject(oid);
if (ob instanceof MaplePlayerShop) {
MaplePlayerShop shop = (MaplePlayerShop) ob;
shop.visitShop(chr);
} else if (ob instanceof MapleMiniGame) {
MapleMiniGame game = (MapleMiniGame) ob;
if (game.hasFreeSlot() && !game.isVisitor(c.getPlayer())) {
game.addVisitor(c.getPlayer());
chr.setMiniGame(game);
switch(game.getGameType()) {
case "omok":
game.sendOmok(c, game.getPieceType());
break;
case "matchcard":
game.sendMatchCard(c, game.getPieceType());
break;
}
} else {
chr.getClient().announce(MaplePacketCreator.getMiniGameFull());
}
} else if (ob instanceof MapleHiredMerchant && chr.getHiredMerchant() == null) {
MapleHiredMerchant merchant = (MapleHiredMerchant) ob;
if (merchant.isOwner(c.getPlayer())) {
merchant.setOpen(false);
merchant.removeAllVisitors();
c.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, false));
} else if (!merchant.isOpen()) {
c.announce(MaplePacketCreator.hiredMerchantMaintenanceMessage());
return;
} else if (!merchant.addVisitor(c.getPlayer())) {
chr.dropMessage(1, "This shop has reached it's maximum capacity, please come by later.");
return;
} else {
c.announce(MaplePacketCreator.getHiredMerchant(c.getPlayer(), merchant, false));
}
chr.setHiredMerchant(merchant);
}
}
} else if (mode == Action.CHAT.getCode()) {
// chat lol
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (chr.getTrade() != null) {
chr.getTrade().chat(slea.readMapleAsciiString());
} else if (chr.getPlayerShop() != null) {
// mini game
MaplePlayerShop shop = chr.getPlayerShop();
if (shop != null) {
shop.chat(c, slea.readMapleAsciiString());
}
} else if (chr.getMiniGame() != null) {
MapleMiniGame game = chr.getMiniGame();
if (game != null) {
game.chat(c, slea.readMapleAsciiString());
}
} else if (merchant != null) {
merchant.sendMessage(c.getPlayer(), slea.readMapleAsciiString());
}
} else if (mode == Action.EXIT.getCode()) {
if (chr.getTrade() != null) {
MapleTrade.cancelTrade(c.getPlayer());
} else {
chr.closePlayerShop();
chr.closeMiniGame();
chr.closeHiredMerchant(true);
}
} else if (mode == Action.OPEN.getCode()) {
MaplePlayerShop shop = chr.getPlayerShop();
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isOwner(c.getPlayer())) {
// 01
slea.readByte();
if (ServerConstants.USE_ERASE_PERMIT_ON_OPENSHOP) {
try {
MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5140000, 1, true, false);
}// fella does not have a player shop permit...
catch (RuntimeException re) {
}
}
chr.getMap().broadcastMessage(MaplePacketCreator.addCharBox(c.getPlayer(), 4));
shop.setOpen(true);
} else if (merchant != null && merchant.isOwner(c.getPlayer())) {
chr.setHasMerchant(true);
merchant.setOpen(true);
chr.getMap().addMapObject(merchant);
chr.setHiredMerchant(null);
chr.getMap().broadcastMessage(MaplePacketCreator.spawnHiredMerchant(merchant));
slea.readByte();
}
} else if (mode == Action.READY.getCode()) {
MapleMiniGame game = chr.getMiniGame();
game.broadcast(MaplePacketCreator.getMiniGameReady(game));
} else if (mode == Action.UN_READY.getCode()) {
MapleMiniGame game = chr.getMiniGame();
game.broadcast(MaplePacketCreator.getMiniGameUnReady(game));
} else if (mode == Action.START.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.getGameType().equals("omok")) {
game.broadcast(MaplePacketCreator.getMiniGameStart(game, game.getLoser()));
chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(game.getOwner(), 2, 1));
}
if (game.getGameType().equals("matchcard")) {
game.shuffleList();
game.broadcast(MaplePacketCreator.getMatchCardStart(game, game.getLoser()));
chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(game.getOwner(), 2, 1));
}
} else if (mode == Action.GIVE_UP.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.getGameType().equals("omok")) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMiniGameOwnerForfeit(game));
} else {
game.broadcast(MaplePacketCreator.getMiniGameVisitorForfeit(game));
}
}
if (game.getGameType().equals("matchcard")) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardVisitorWin(game));
} else {
game.broadcast(MaplePacketCreator.getMatchCardOwnerWin(game));
}
}
} else if (mode == Action.REQUEST_TIE.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.isOwner(c.getPlayer())) {
game.broadcastToVisitor(MaplePacketCreator.getMiniGameRequestTie(game));
} else {
game.getOwner().getClient().announce(MaplePacketCreator.getMiniGameRequestTie(game));
}
} else if (mode == Action.ANSWER_TIE.getCode()) {
MapleMiniGame game = chr.getMiniGame();
slea.readByte();
if (game.getGameType().equals("omok")) {
game.broadcast(MaplePacketCreator.getMiniGameTie(game));
}
if (game.getGameType().equals("matchcard")) {
game.broadcast(MaplePacketCreator.getMatchCardTie(game));
}
} else if (mode == Action.SKIP.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMiniGameSkipOwner(game));
} else {
game.broadcast(MaplePacketCreator.getMiniGameSkipVisitor(game));
}
} else if (mode == Action.MOVE_OMOK.getCode()) {
// x point
int x = slea.readInt();
// y point
int y = slea.readInt();
// piece ( 1 or 2; Owner has one piece, visitor has another, it switches every game.)
int type = slea.readByte();
chr.getMiniGame().setPiece(x, y, type, c.getPlayer());
} else if (mode == Action.SELECT_CARD.getCode()) {
// 1st turn = 1; 2nd turn = 0
int turn = slea.readByte();
// slot
int slot = slea.readByte();
MapleMiniGame game = chr.getMiniGame();
int firstslot = game.getFirstSlot();
if (turn == 1) {
game.setFirstSlot(slot);
if (game.isOwner(c.getPlayer())) {
game.broadcastToVisitor(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
} else {
game.getOwner().getClient().announce(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
}
} else if ((game.getCardId(firstslot + 1)) == (game.getCardId(slot + 1))) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 2));
game.setOwnerPoints();
} else {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 3));
game.setVisitorPoints();
}
} else if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 0));
} else {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 1));
}
} else if (mode == Action.SET_MESO.getCode()) {
chr.getTrade().setMeso(slea.readInt());
} else if (mode == Action.SET_ITEMS.getCode()) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
Item item = chr.getInventory(ivType).getItem(slea.readShort());
short quantity = slea.readShort();
byte targetSlot = slea.readByte();
if (quantity < 1 || quantity > item.getQuantity()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getTrade() != null) {
if ((quantity <= item.getQuantity() && quantity >= 0) || ItemConstants.isRechargable(item.getItemId())) {
if (ii.isDropRestricted(item.getItemId())) {
// ensure that undroppable items do not make it to the trade window
if (!((item.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA)) {
c.announce(MaplePacketCreator.enableActions());
return;
}
}
Item tradeItem = item.copy();
if (ItemConstants.isRechargable(item.getItemId())) {
tradeItem.setQuantity(item.getQuantity());
MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), item.getQuantity(), true);
} else {
tradeItem.setQuantity(quantity);
MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), quantity, true);
}
tradeItem.setPosition(targetSlot);
chr.getTrade().addItem(tradeItem);
}
}
} else if (mode == Action.CONFIRM.getCode()) {
MapleTrade.completeTrade(c.getPlayer());
} else if (mode == Action.ADD_ITEM.getCode() || mode == Action.PUT_ITEM.getCode()) {
MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
short slot = slea.readShort();
short bundles = slea.readShort();
if (chr.getInventory(ivType).getItem(slot) == null || chr.getItemQuantity(chr.getInventory(ivType).getItem(slot).getItemId(), false) < bundles || chr.getInventory(ivType).getItem(slot).getFlag() == ItemConstants.UNTRADEABLE) {
return;
}
short perBundle = slea.readShort();
int price = slea.readInt();
if (perBundle <= 0 || perBundle * bundles > 2000 || bundles <= 0 || price <= 0 || price > Integer.MAX_VALUE) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with hired merchants.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " might of possibly packet edited Hired Merchants\nperBundle: " + perBundle + "\nperBundle * bundles (This multiplied cannot be greater than 2000): " + perBundle * bundles + "\nbundles: " + bundles + "\nprice: " + price);
return;
}
Item ivItem = chr.getInventory(ivType).getItem(slot);
Item sellItem = ivItem.copy();
if (chr.getItemQuantity(ivItem.getItemId(), false) < perBundle * bundles) {
return;
} else if (ServerConstants.USE_ENFORCE_UNMERCHABLE_PET && ItemConstants.isPet(ivItem.getItemId())) {
c.announce(MaplePacketCreator.serverNotice(1, "Pets are not allowed to be sold on the Player Shop."));
return;
}
sellItem.setQuantity(perBundle);
MaplePlayerShopItem shopItem = new MaplePlayerShopItem(sellItem, bundles, price);
MaplePlayerShop shop = chr.getPlayerShop();
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isOwner(c.getPlayer())) {
if (ivItem != null && ivItem.getQuantity() >= bundles * perBundle) {
shop.addItem(shopItem);
c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
}
} else if (merchant != null && merchant.isOwner(c.getPlayer())) {
merchant.addItem(shopItem);
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
if (ItemConstants.isRechargable(ivItem.getItemId())) {
MapleInventoryManipulator.removeFromSlot(c, ivType, slot, ivItem.getQuantity(), true);
} else {
MapleInventoryManipulator.removeFromSlot(c, ivType, slot, (short) (bundles * perBundle), true);
}
} else if (mode == Action.REMOVE_ITEM.getCode()) {
MaplePlayerShop shop = chr.getPlayerShop();
if (shop != null && shop.isOwner(c.getPlayer())) {
int slot = slea.readShort();
if (slot >= shop.getItems().size() || slot < 0) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a player shop.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to remove item at slot " + slot + "\r\n");
c.disconnect(true, false);
return;
}
MaplePlayerShopItem shopItem = shop.getItems().get(slot);
Item ivItem = shopItem.getItem().copy();
shop.removeItem(slot);
ivItem.setQuantity(shopItem.getBundles());
MapleInventoryManipulator.addFromDrop(c, ivItem, false);
c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
}
} else if (mode == Action.MERCHANT_MESO.getCode()) {
// Hmmmm
/*if (!chr.getHiredMerchant().isOwner(chr) || chr.getMerchantMeso() < 1) return;
int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
if (possible > 0) {
if (possible < chr.getMerchantMeso()) {
chr.gainMeso(possible, false);
chr.setMerchantMeso(chr.getMerchantMeso() - possible);
} else {
chr.gainMeso(chr.getMerchantMeso(), false);
chr.setMerchantMeso(0);
}
c.announce(MaplePacketCreator.updateHiredMerchant(chr.getHiredMerchant(), chr));
}*/
} else if (mode == Action.MERCHANT_ORGANIZE.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (!merchant.isOwner(chr))
return;
if (chr.getMerchantMeso() > 0) {
int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
if (possible > 0) {
if (possible < chr.getMerchantMeso()) {
chr.gainMeso(possible, false);
chr.setMerchantMeso(chr.getMerchantMeso() - possible);
} else {
chr.gainMeso(chr.getMerchantMeso(), false);
chr.setMerchantMeso(0);
}
}
}
for (int i = 0; i < merchant.getItems().size(); i++) {
if (!merchant.getItems().get(i).isExist())
merchant.removeFromSlot(i);
}
if (merchant.getItems().isEmpty()) {
c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
merchant.closeShop(c, false);
chr.setHasMerchant(false);
return;
}
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, chr));
} else if (mode == Action.BUY.getCode() || mode == Action.MERCHANT_BUY.getCode()) {
int itemid = slea.readByte();
short quantity = slea.readShort();
if (quantity < 1) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a hired merchant and or player shop.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to buy item " + itemid + " with quantity " + quantity + "\r\n");
c.disconnect(true, false);
return;
}
MaplePlayerShop shop = chr.getPlayerShop();
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isVisitor(c.getPlayer())) {
shop.buy(c, itemid, quantity);
shop.broadcast(MaplePacketCreator.getPlayerShopItemUpdate(shop));
} else if (merchant != null && !merchant.isOwner(chr)) {
merchant.buy(c, itemid, quantity);
merchant.broadcastToVisitorsThreadsafe(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
} else if (mode == Action.TAKE_ITEM_BACK.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null && merchant.isOwner(c.getPlayer())) {
int slot = slea.readShort();
MaplePlayerShopItem shopItem = merchant.getItems().get(slot);
if (!MapleInventory.checkSpot(chr, shopItem.getItem())) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (shopItem.getBundles() > 0) {
Item iitem = shopItem.getItem();
iitem.setQuantity((short) (shopItem.getItem().getQuantity() * shopItem.getBundles()));
MapleInventoryManipulator.addFromDrop(c, iitem, true);
}
merchant.removeFromSlot(slot);
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
} else if (mode == Action.CLOSE_MERCHANT.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null && merchant.isOwner(c.getPlayer())) {
c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
merchant.closeShop(c, false);
chr.setHasMerchant(false);
}
} else if (mode == Action.MAINTENANCE_OFF.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null) {
if (merchant.getItems().isEmpty() && merchant.isOwner(c.getPlayer())) {
merchant.closeShop(c, false);
chr.setHasMerchant(false);
}
if (merchant.isOwner(c.getPlayer())) {
merchant.clearMessages();
merchant.setOpen(true);
}
}
chr.setHiredMerchant(null);
c.announce(MaplePacketCreator.enableActions());
} else if (mode == Action.BAN_PLAYER.getCode()) {
slea.skip(1);
if (chr.getPlayerShop() != null && chr.getPlayerShop().isOwner(c.getPlayer())) {
chr.getPlayerShop().banPlayer(slea.readMapleAsciiString());
}
}
}
use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.
the class UseCashItemHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
final MapleCharacter player = c.getPlayer();
if (System.currentTimeMillis() - player.getLastUsedCashItem() < 3000) {
player.dropMessage(1, "You have used a cash item recently. Wait a moment, then try again.");
c.announce(MaplePacketCreator.enableActions());
return;
}
player.setLastUsedCashItem(System.currentTimeMillis());
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
slea.readShort();
int itemId = slea.readInt();
int itemType = itemId / 10000;
Item toUse = c.getPlayer().getInventory(MapleInventoryType.CASH).getItem(c.getPlayer().getInventory(MapleInventoryType.CASH).findById(itemId).getPosition());
String medal = "";
Item medalItem = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -49);
if (medalItem != null) {
medal = "<" + ii.getName(medalItem.getItemId()) + "> ";
}
if (toUse == null || toUse.getItemId() != itemId || toUse.getQuantity() < 1) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (itemType == 505) {
// AP/SP reset
if (!player.isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (itemId > 5050000) {
int SPTo = slea.readInt();
int SPFrom = slea.readInt();
Skill skillSPTo = SkillFactory.getSkill(SPTo);
Skill skillSPFrom = SkillFactory.getSkill(SPFrom);
byte curLevel = player.getSkillLevel(skillSPTo);
byte curLevelSPFrom = player.getSkillLevel(skillSPFrom);
if ((curLevel < skillSPTo.getMaxLevel()) && curLevelSPFrom > 0) {
player.changeSkillLevel(skillSPFrom, (byte) (curLevelSPFrom - 1), player.getMasterLevel(skillSPFrom), -1);
player.changeSkillLevel(skillSPTo, (byte) (curLevel + 1), player.getMasterLevel(skillSPTo), -1);
}
} else {
List<Pair<MapleStat, Integer>> statupdate = new ArrayList<>(2);
int APTo = slea.readInt();
int APFrom = slea.readInt();
switch(APFrom) {
case // str
64:
if (player.getStr() < 5) {
c.getPlayer().message("You don't have the minimum STR required to swap.");
c.announce(MaplePacketCreator.enableActions());
return;
}
player.addStat(1, -1);
break;
case // dex
128:
if (player.getDex() < 5) {
c.getPlayer().message("You don't have the minimum DEX required to swap.");
c.announce(MaplePacketCreator.enableActions());
return;
}
player.addStat(2, -1);
break;
case // int
256:
if (player.getInt() < 5) {
c.getPlayer().message("You don't have the minimum INT required to swap.");
c.announce(MaplePacketCreator.enableActions());
return;
}
player.addStat(3, -1);
break;
case // luk
512:
if (player.getLuk() < 5) {
c.getPlayer().message("You don't have the minimum LUK required to swap.");
c.announce(MaplePacketCreator.enableActions());
return;
}
player.addStat(4, -1);
break;
case // HP
2048:
if (ServerConstants.USE_ENFORCE_HPMP_SWAP) {
if (APTo != 8192) {
c.getPlayer().message("You can only swap HP ability points to MP.");
c.announce(MaplePacketCreator.enableActions());
return;
}
}
if (player.getHpMpApUsed() < 1) {
c.getPlayer().message("You don't have enough HPMP stat points to spend on AP Reset.");
c.announce(MaplePacketCreator.enableActions());
return;
}
int hp = player.getMaxHp();
int level_ = player.getLevel();
boolean canWash_ = true;
if (hp < level_ * 14 + 148) {
canWash_ = false;
}
if (!canWash_) {
c.getPlayer().message("You don't have the minimum HP pool required to swap.");
c.announce(MaplePacketCreator.enableActions());
return;
}
player.setHpMpApUsed(player.getHpMpApUsed() - 1);
int hplose = -DistributeAPHandler.takeHp(player, player.getJob());
int nextHp = Math.max(1, player.getHp() + hplose), nextMaxHp = Math.max(50, player.getMaxHp() + hplose);
player.setHp(nextHp);
player.setMaxHp(nextMaxHp);
statupdate.add(new Pair<>(MapleStat.HP, nextHp));
statupdate.add(new Pair<>(MapleStat.MAXHP, nextMaxHp));
break;
case // MP
8192:
if (ServerConstants.USE_ENFORCE_HPMP_SWAP) {
if (APTo != 2048) {
c.getPlayer().message("You can only swap MP ability points to HP.");
c.announce(MaplePacketCreator.enableActions());
return;
}
}
if (player.getHpMpApUsed() < 1) {
c.getPlayer().message("You don't have enough HPMP stat points to spend on AP Reset.");
c.announce(MaplePacketCreator.enableActions());
return;
}
int mp = player.getMaxMp();
int level = player.getLevel();
MapleJob job = player.getJob();
boolean canWash = true;
if (job.isA(MapleJob.SPEARMAN) && mp < 4 * level + 156) {
canWash = false;
} else if (job.isA(MapleJob.FIGHTER) && mp < 4 * level + 56) {
canWash = false;
} else if (job.isA(MapleJob.THIEF) && job.getId() % 100 > 0 && mp < level * 14 - 4) {
canWash = false;
} else if (mp < level * 14 + 148) {
canWash = false;
}
if (!canWash) {
c.getPlayer().message("You don't have the minimum MP pool required to swap.");
c.announce(MaplePacketCreator.enableActions());
return;
}
player.setHpMpApUsed(player.getHpMpApUsed() - 1);
int mplose = -DistributeAPHandler.takeMp(player, job);
int nextMp = Math.max(0, player.getMp() + mplose), nextMaxMp = Math.max(5, player.getMaxMp() + mplose);
player.setMp(nextMp);
player.setMaxMp(nextMaxMp);
statupdate.add(new Pair<>(MapleStat.MP, nextMp));
statupdate.add(new Pair<>(MapleStat.MAXMP, nextMaxMp));
break;
default:
c.announce(MaplePacketCreator.updatePlayerStats(MaplePacketCreator.EMPTY_STATUPDATE, true, c.getPlayer()));
return;
}
DistributeAPHandler.addStat(c, APTo, true);
c.announce(MaplePacketCreator.updatePlayerStats(statupdate, true, c.getPlayer()));
}
remove(c, itemId);
} else if (itemType == 506) {
Item eq = null;
if (itemId == 5060000) {
// Item tag.
int equipSlot = slea.readShort();
if (equipSlot == 0) {
return;
}
eq = player.getInventory(MapleInventoryType.EQUIPPED).getItem((short) equipSlot);
eq.setOwner(player.getName());
} else if (itemId == 5060001 || itemId == 5061000 || itemId == 5061001 || itemId == 5061002 || itemId == 5061003) {
// Sealing lock
MapleInventoryType type = MapleInventoryType.getByType((byte) slea.readInt());
eq = c.getPlayer().getInventory(type).getItem((short) slea.readInt());
if (eq == null) {
// Check if the type is EQUIPMENT?
return;
}
byte flag = eq.getFlag();
flag |= ItemConstants.LOCK;
if (eq.getExpiration() > -1) {
// No perma items pls
return;
}
eq.setFlag(flag);
long period = 0;
if (itemId == 5061000) {
period = 7;
} else if (itemId == 5061001) {
period = 30;
} else if (itemId == 5061002) {
period = 90;
} else if (itemId == 5061003) {
period = 365;
}
if (period > 0) {
eq.setExpiration(System.currentTimeMillis() + (period * 60 * 60 * 24 * 1000));
}
remove(c, itemId);
} else if (itemId == 5060002) {
// Incubator
byte inventory2 = (byte) slea.readInt();
short slot2 = (short) slea.readInt();
Item item2 = c.getPlayer().getInventory(MapleInventoryType.getByType(inventory2)).getItem(slot2);
if (// hacking
item2 == null) {
return;
}
if (getIncubatedItem(c, itemId)) {
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.getByType(inventory2), slot2, (short) 1, false);
remove(c, itemId);
}
return;
}
// time stamp
slea.readInt();
if (eq != null) {
player.forceUpdateItem(eq);
remove(c, itemId);
}
} else if (itemType == 507) {
boolean whisper;
switch(itemId / 1000 % 10) {
case // Megaphone
1:
if (player.getLevel() > 9) {
player.getClient().getChannelServer().broadcastPacket(MaplePacketCreator.serverNotice(2, medal + player.getName() + " : " + slea.readMapleAsciiString()));
} else {
player.dropMessage(1, "You may not use this until you're level 10.");
}
break;
case // Super megaphone
2:
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + slea.readMapleAsciiString(), (slea.readByte() != 0)));
break;
case // Maple TV
5:
int tvType = itemId % 10;
boolean megassenger = false;
boolean ear = false;
MapleCharacter victim = null;
if (tvType != 1) {
if (tvType >= 3) {
megassenger = true;
if (tvType == 3) {
slea.readByte();
}
ear = 1 == slea.readByte();
} else if (tvType != 2) {
slea.readByte();
}
if (tvType != 4) {
victim = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
}
}
List<String> messages = new LinkedList<>();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 5; i++) {
String message = slea.readMapleAsciiString();
if (megassenger) {
builder.append(" ").append(message);
}
messages.add(message);
}
slea.readInt();
if (megassenger) {
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + builder.toString(), ear));
}
if (!MapleTVEffect.isActive()) {
new MapleTVEffect(player, victim, messages, tvType);
remove(c, itemId);
} else {
player.dropMessage(1, "MapleTV is already in use.");
return;
}
break;
case // item megaphone
6:
String msg = medal + c.getPlayer().getName() + " : " + slea.readMapleAsciiString();
whisper = slea.readByte() == 1;
Item item = null;
if (slea.readByte() == 1) {
// item
item = c.getPlayer().getInventory(MapleInventoryType.getByType((byte) slea.readInt())).getItem((short) slea.readInt());
if (// hack
item == null) {
return;
} else if (((item.getFlag() & ItemConstants.UNTRADEABLE) == ItemConstants.UNTRADEABLE) || ii.isDropRestricted(item.getItemId())) {
player.dropMessage(1, "You cannot trade this item.");
c.announce(MaplePacketCreator.enableActions());
return;
}
}
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.itemMegaphone(msg, whisper, c.getChannel(), item));
break;
case // triple megaphone
7:
int lines = slea.readByte();
if (// hack
lines < 1 || lines > 3) {
return;
}
String[] msg2 = new String[lines];
for (int i = 0; i < lines; i++) {
msg2[i] = medal + c.getPlayer().getName() + " : " + slea.readMapleAsciiString();
}
whisper = slea.readByte() == 1;
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.getMultiMegaphone(msg2, c.getChannel(), whisper));
break;
}
remove(c, itemId);
} else if (itemType == 508) {
// graduation banner
// message, separated by 0A for lines
slea.readMapleAsciiString();
c.announce(MaplePacketCreator.enableActions());
} else if (itemType == 509) {
String sendTo = slea.readMapleAsciiString();
String msg = slea.readMapleAsciiString();
try {
player.sendNote(sendTo, msg, (byte) 0);
} catch (SQLException e) {
e.printStackTrace();
}
remove(c, itemId);
} else if (itemType == 510) {
player.getMap().broadcastMessage(MaplePacketCreator.musicChange("Jukebox/Congratulation"));
remove(c, itemId);
} else if (itemType == 512) {
if (ii.getStateChangeItem(itemId) != 0) {
for (MapleCharacter mChar : c.getPlayer().getMap().getCharacters()) {
ii.getItemEffect(ii.getStateChangeItem(itemId)).applyTo(mChar);
}
}
player.getMap().startMapEffect(ii.getMsg(itemId).replaceFirst("%s", c.getPlayer().getName()).replaceFirst("%s", slea.readMapleAsciiString()), itemId);
remove(c, itemId);
} else if (itemType == 517) {
MaplePet pet = player.getPet(0);
if (pet == null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
String newName = slea.readMapleAsciiString();
pet.setName(newName);
pet.saveToDb();
Item item = player.getInventory(MapleInventoryType.CASH).getItem(pet.getPosition());
if (item != null)
player.forceUpdateItem(item);
player.getMap().broadcastMessage(player, MaplePacketCreator.changePetName(player, newName, 1), true);
c.announce(MaplePacketCreator.enableActions());
remove(c, itemId);
} else if (itemType == 504) {
// vip teleport rock
String error1 = "Either the player could not be found or you were trying to teleport to an illegal location.";
boolean vip = slea.readByte() == 1;
remove(c, itemId);
if (!vip) {
int mapId = slea.readInt();
if (c.getChannelServer().getMapFactory().getMap(mapId).getForcedReturnId() == 999999999) {
player.changeMap(c.getChannelServer().getMapFactory().getMap(mapId));
} else {
MapleInventoryManipulator.addById(c, itemId, (short) 1);
c.getPlayer().dropMessage(1, error1);
c.announce(MaplePacketCreator.enableActions());
}
} else {
String name = slea.readMapleAsciiString();
MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(name);
boolean success = false;
if (victim != null) {
MapleMap target = victim.getMap();
if (c.getChannelServer().getMapFactory().getMap(victim.getMapId()).getForcedReturnId() == 999999999 || victim.getMapId() < 100000000) {
if (victim.gmLevel() <= player.gmLevel()) {
if (itemId == 5041000 || victim.getMapId() / player.getMapId() == 1) {
// viprock & same continent
player.changeMap(target, target.findClosestPlayerSpawnpoint(victim.getPosition()));
success = true;
} else {
player.dropMessage(1, "You cannot teleport between continents with this teleport rock.");
}
} else {
player.dropMessage(1, error1);
}
} else {
player.dropMessage(1, "You cannot teleport to this map.");
}
} else {
player.dropMessage(1, "Player could not be found in this channel.");
}
if (!success) {
MapleInventoryManipulator.addById(c, itemId, (short) 1);
c.announce(MaplePacketCreator.enableActions());
}
}
} else if (itemType == 520) {
player.gainMeso(ii.getMeso(itemId), true, false, true);
remove(c, itemId);
c.announce(MaplePacketCreator.enableActions());
} else if (itemType == 523) {
int itemid = slea.readInt();
if (!ServerConstants.USE_ENFORCE_OWL_SUGGESTIONS)
c.getWorldServer().addOwlItemSearch(itemid);
player.setOwlSearch(itemid);
List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> hmsAvailable = c.getWorldServer().getAvailableItemBundles(itemid);
if (!hmsAvailable.isEmpty())
remove(c, itemId);
c.announce(MaplePacketCreator.owlOfMinerva(c, itemid, hmsAvailable));
c.announce(MaplePacketCreator.enableActions());
} else if (itemType == 524) {
for (byte i = 0; i < 3; i++) {
MaplePet pet = player.getPet(i);
if (pet != null) {
if (pet.canConsume(itemId)) {
pet.gainClosenessFullness(player, 100, 100, 1);
remove(c, itemId);
break;
}
} else {
break;
}
}
c.announce(MaplePacketCreator.enableActions());
} else if (itemType == 530) {
ii.getItemEffect(itemId).applyTo(player);
remove(c, itemId);
} else if (itemType == 533) {
NPCScriptManager.getInstance().start(c, 9010009, null);
} else if (itemType == 537) {
player.setChalkboard(slea.readMapleAsciiString());
player.getMap().broadcastMessage(MaplePacketCreator.useChalkboard(player, false));
player.getClient().announce(MaplePacketCreator.enableActions());
} else if (itemType == 539) {
List<String> strLines = new LinkedList<>();
for (int i = 0; i < 4; i++) {
strLines.add(slea.readMapleAsciiString());
}
final int world = c.getWorld();
Server.getInstance().broadcastMessage(world, MaplePacketCreator.getAvatarMega(c.getPlayer(), medal, c.getChannel(), itemId, strLines, (slea.readByte() != 0)));
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
Server.getInstance().broadcastMessage(world, MaplePacketCreator.byeAvatarMega());
}
}, 1000 * 10);
remove(c, itemId);
} else if (itemType == 545) {
// MiuMiu's travel store
if (player.getShop() == null) {
MapleShop shop = MapleShopFactory.getInstance().getShop(1338);
if (shop != null) {
shop.sendShop(c);
remove(c, itemId);
}
} else {
c.announce(MaplePacketCreator.enableActions());
}
} else if (itemType == 550) {
// Extend item expiration
c.announce(MaplePacketCreator.enableActions());
} else if (itemType == 552) {
MapleInventoryType type = MapleInventoryType.getByType((byte) slea.readInt());
short slot = (short) slea.readInt();
Item item = c.getPlayer().getInventory(type).getItem(slot);
if (item == null || item.getQuantity() <= 0 || (item.getFlag() & ItemConstants.KARMA) > 0 && ii.isKarmaAble(item.getItemId())) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (!type.equals(MapleInventoryType.USE)) {
item.setFlag((byte) ItemConstants.KARMA);
}
c.getPlayer().forceUpdateItem(item);
remove(c, itemId);
c.announce(MaplePacketCreator.enableActions());
} else if (itemType == 552) {
// DS EGG THING
c.announce(MaplePacketCreator.enableActions());
} else if (itemType == 557) {
slea.readInt();
int itemSlot = slea.readInt();
slea.readInt();
final Equip equip = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) itemSlot);
if (equip.getVicious() == 2 || c.getPlayer().getInventory(MapleInventoryType.CASH).findById(5570000) == null) {
return;
}
equip.setVicious(equip.getVicious() + 1);
equip.setUpgradeSlots(equip.getUpgradeSlots() + 1);
remove(c, itemId);
c.announce(MaplePacketCreator.enableActions());
c.announce(MaplePacketCreator.sendHammerData(equip.getVicious()));
player.forceUpdateItem(equip);
} else if (itemType == 561) {
// VEGA'S SPELL
if (slea.readInt() != 1) {
return;
}
final byte eSlot = (byte) slea.readInt();
final Item eitem = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(eSlot);
if (slea.readInt() != 2) {
return;
}
final byte uSlot = (byte) slea.readInt();
final Item uitem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(uSlot);
if (eitem == null || uitem == null) {
return;
}
Equip toScroll = (Equip) eitem;
if (toScroll.getUpgradeSlots() < 1) {
c.getSession().write(MaplePacketCreator.getInventoryFull());
return;
}
// should have a check here against PE hacks
if (itemId / 1000000 != 5)
itemId = 0;
c.getPlayer().toggleBlockCashShop();
final int curlevel = toScroll.getLevel();
c.getSession().write(MaplePacketCreator.sendVegaScroll(0x40));
final Equip scrolled = (Equip) ii.scrollEquipWithId(toScroll, uitem.getItemId(), false, itemId, c.getPlayer().isGM());
c.getSession().write(MaplePacketCreator.sendVegaScroll(scrolled.getLevel() > curlevel ? 0x41 : 0x43));
// opcodes 0x42, 0x44: "this item cannot be used"; 0x39, 0x45: crashes
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, uSlot, (short) 1, false);
remove(c, itemId);
final MapleClient client = c;
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
if (!player.isLoggedin())
return;
player.toggleBlockCashShop();
final List<ModifyInventory> mods = new ArrayList<>();
mods.add(new ModifyInventory(3, scrolled));
mods.add(new ModifyInventory(0, scrolled));
client.announce(MaplePacketCreator.modifyInventory(true, mods));
ScrollResult scrollResult = scrolled.getLevel() > curlevel ? ScrollResult.SUCCESS : ScrollResult.FAIL;
player.getMap().broadcastMessage(MaplePacketCreator.getScrollEffect(player.getId(), scrollResult, false));
if (eSlot < 0 && (scrollResult == ScrollResult.SUCCESS)) {
player.equipChanged();
}
client.getSession().write(MaplePacketCreator.enableActions());
}
}, 1000 * 3);
} else {
System.out.println("NEW CASH ITEM: " + itemType + "\n" + slea.toString());
c.announce(MaplePacketCreator.enableActions());
}
}
Aggregations