use of tools.Pair in project HeavenMS by ronancpl.
the class AbstractPlayerInteraction method canHoldAll.
private boolean canHoldAll(List<Integer> itemids, List<Integer> quantity, boolean isInteger) {
int size = Math.min(itemids.size(), quantity.size());
List<Pair<Item, MapleInventoryType>> addedItems = new LinkedList<>();
for (int i = 0; i < size; i++) {
Item it = new Item(itemids.get(i), (short) 0, quantity.get(i).shortValue());
addedItems.add(new Pair<>(it, ItemConstants.getInventoryType(itemids.get(i))));
}
return MapleInventory.checkSpots(c.getPlayer(), addedItems);
}
use of tools.Pair in project HeavenMS by ronancpl.
the class Commands method executeHeavenMsCommandLv0.
public static boolean executeHeavenMsCommandLv0(Channel cserv, Server srv, MapleClient c, String[] sub) {
// Player
MapleCharacter player = c.getPlayer();
switch(sub[0]) {
case "help":
case "commands":
case "playercommands":
c.getAbstractPlayerInteraction().openNpc(9201143, "commands");
break;
case "droplimit":
int dropCount = c.getPlayer().getMap().getDroppedItemCount();
if (((float) dropCount) / ServerConstants.ITEM_LIMIT_ON_MAP < 0.75f) {
c.getPlayer().showHint("Current drop count: #b" + dropCount + "#k / #e" + ServerConstants.ITEM_LIMIT_ON_MAP + "#n", 300);
} else {
c.getPlayer().showHint("Current drop count: #r" + dropCount + "#k / #e" + ServerConstants.ITEM_LIMIT_ON_MAP + "#n", 300);
}
break;
case "time":
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone(ServerConstants.TIMEZONE));
player.yellowMessage("Solaxia Server Time: " + dateFormat.format(new Date()));
break;
case "credits":
case "staff":
c.getAbstractPlayerInteraction().openNpc(2010007, "credits");
break;
case "lastrestart":
case "uptime":
long milliseconds = System.currentTimeMillis() - Server.uptime;
int seconds = (int) (milliseconds / 1000) % 60;
int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
int days = (int) ((milliseconds / (1000 * 60 * 60 * 24)));
player.yellowMessage("Server has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds.");
break;
case "gacha":
Gachapon gacha = null;
String search = joinStringFrom(sub, 1);
String gachaName = "";
String[] names = { "Henesys", "Ellinia", "Perion", "Kerning City", "Sleepywood", "Mushroom Shrine", "Showa Spa Male", "Showa Spa Female", "New Leaf City", "Nautilus Harbor" };
int[] ids = { 9100100, 9100101, 9100102, 9100103, 9100104, 9100105, 9100106, 9100107, 9100109, 9100117 };
for (int i = 0; i < names.length; i++) {
if (search.equalsIgnoreCase(names[i])) {
gachaName = names[i];
gacha = Gachapon.getByNpcId(ids[i]);
}
}
if (gacha == null) {
player.yellowMessage("Please use @gacha <name> where name corresponds to one of the below:");
for (String name : names) {
player.yellowMessage(name);
}
break;
}
String output = "The #b" + gachaName + "#k Gachapon contains the following items.\r\n\r\n";
for (int i = 0; i < 2; i++) {
for (int id : gacha.getItems(i)) {
output += "-" + MapleItemInformationProvider.getInstance().getName(id) + "\r\n";
}
}
output += "\r\nPlease keep in mind that there are items that are in all gachapons and are not listed here.";
c.announce(MaplePacketCreator.getNPCTalk(9010000, (byte) 0, output, "00 00", (byte) 0));
break;
case "whatdropsfrom":
if (sub.length < 2) {
player.dropMessage(5, "Please do @whatdropsfrom <monster name>");
break;
}
String monsterName = joinStringFrom(sub, 1);
output = "";
int limit = 3;
Iterator<Pair<Integer, String>> listIterator = MapleMonsterInformationProvider.getMobsIDsFromName(monsterName).iterator();
for (int i = 0; i < limit; i++) {
if (listIterator.hasNext()) {
Pair<Integer, String> data = listIterator.next();
int mobId = data.getLeft();
String mobName = data.getRight();
output += mobName + " drops the following items:\r\n\r\n";
for (MonsterDropEntry drop : MapleMonsterInformationProvider.getInstance().retrieveDrop(mobId)) {
try {
String name = MapleItemInformationProvider.getInstance().getName(drop.itemId);
if (name.equals("null") || drop.chance == 0) {
continue;
}
float chance = 1000000 / drop.chance / player.getDropRate();
output += "- " + name + " (1/" + (int) chance + ")\r\n";
} catch (Exception ex) {
ex.printStackTrace();
continue;
}
}
output += "\r\n";
}
}
c.announce(MaplePacketCreator.getNPCTalk(9010000, (byte) 0, output, "00 00", (byte) 0));
break;
case "whodrops":
if (sub.length < 2) {
player.dropMessage(5, "Please do @whodrops <item name>");
break;
}
String searchString = joinStringFrom(sub, 1);
output = "";
listIterator = MapleItemInformationProvider.getInstance().getItemDataByName(searchString).iterator();
if (listIterator.hasNext()) {
int count = 1;
while (listIterator.hasNext() && count <= 3) {
Pair<Integer, String> data = listIterator.next();
output += "#b" + data.getRight() + "#k is dropped by:\r\n";
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT dropperid FROM drop_data WHERE itemid = ? LIMIT 50");
ps.setInt(1, data.getLeft());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String resultName = MapleMonsterInformationProvider.getMobNameFromID(rs.getInt("dropperid"));
if (resultName != null) {
output += resultName + ", ";
}
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
player.dropMessage(6, "There was a problem retrieving the required data. Please try again.");
e.printStackTrace();
break;
}
output += "\r\n\r\n";
count++;
}
} else {
player.dropMessage(5, "The item you searched for doesn't exist.");
break;
}
c.announce(MaplePacketCreator.getNPCTalk(9010000, (byte) 0, output, "00 00", (byte) 0));
break;
case "dispose":
NPCScriptManager.getInstance().dispose(c);
c.announce(MaplePacketCreator.enableActions());
c.removeClickedNPC();
player.message("You've been disposed.");
break;
case "equiplv":
player.showAllEquipFeatures();
break;
case "showrates":
String showMsg = "#eEXP RATE#n" + "\r\n";
showMsg += "Server EXP Rate: #k" + c.getWorldServer().getExpRate() + "x#k" + "\r\n";
showMsg += "Player EXP Rate: #k" + player.getRawExpRate() + "x#k" + "\r\n";
if (player.getCouponExpRate() != 1)
showMsg += "Coupon EXP Rate: #k" + player.getCouponExpRate() + "x#k" + "\r\n";
showMsg += "EXP Rate: #e#b" + player.getExpRate() + "x#k#n" + "\r\n";
showMsg += "\r\n" + "#eMESO RATE#n" + "\r\n";
showMsg += "Server MESO Rate: #k" + c.getWorldServer().getMesoRate() + "x#k" + "\r\n";
showMsg += "Player MESO Rate: #k" + player.getRawMesoRate() + "x#k" + "\r\n";
if (player.getCouponMesoRate() != 1)
showMsg += "Coupon MESO Rate: #k" + player.getCouponMesoRate() + "x#k" + "\r\n";
showMsg += "MESO Rate: #e#b" + player.getMesoRate() + "x#k#n" + "\r\n";
showMsg += "\r\n" + "#eDROP RATE#n" + "\r\n";
showMsg += "Server DROP Rate: #k" + c.getWorldServer().getDropRate() + "x#k" + "\r\n";
showMsg += "Player DROP Rate: #k" + player.getRawDropRate() + "x#k" + "\r\n";
if (player.getCouponDropRate() != 1)
showMsg += "Coupon DROP Rate: #k" + player.getCouponDropRate() + "x#k" + "\r\n";
showMsg += "DROP Rate: #e#b" + player.getDropRate() + "x#k#n" + "\r\n";
if (ServerConstants.USE_QUEST_RATE) {
showMsg += "\r\n" + "#eQUEST RATE#n" + "\r\n";
showMsg += "Server QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n";
}
player.showHint(showMsg, 300);
break;
case "rates":
String showMsg_ = "#eCHARACTER RATES#n" + "\r\n\r\n";
showMsg_ += "EXP Rate: #e#b" + player.getExpRate() + "x#k#n" + "\r\n";
showMsg_ += "MESO Rate: #e#b" + player.getMesoRate() + "x#k#n" + "\r\n";
showMsg_ += "DROP Rate: #e#b" + player.getDropRate() + "x#k#n" + "\r\n";
if (ServerConstants.USE_QUEST_RATE)
showMsg_ += "QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n";
player.showHint(showMsg_, 300);
break;
case "online":
for (Channel ch : Server.getInstance().getChannelsFromWorld(player.getWorld())) {
player.yellowMessage("Players in Channel " + ch.getId() + ":");
for (MapleCharacter chr : ch.getPlayerStorage().getAllCharacters()) {
if (!chr.isGM()) {
player.message(" >> " + MapleCharacter.makeMapleReadable(chr.getName()) + " is at " + chr.getMap().getMapName() + ".");
}
}
}
break;
case "gm":
if (sub.length < 3) {
// #goodbye 'hi'
player.dropMessage(5, "Your message was too short. Please provide as much detail as possible.");
break;
}
String message = joinStringFrom(sub, 1);
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[GM MESSAGE]:" + MapleCharacter.makeMapleReadable(player.getName()) + ": " + message));
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(1, message));
FilePrinter.printError("gm.txt", MapleCharacter.makeMapleReadable(player.getName()) + ": " + message + "\r\n");
player.dropMessage(5, "Your message '" + message + "' was sent to GMs.");
player.dropMessage(5, tips[Randomizer.nextInt(tips.length)]);
break;
case "bug":
if (sub.length < 2) {
player.dropMessage(5, "Message too short and not sent. Please do @bug <bug>");
break;
}
message = joinStringFrom(sub, 1);
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[BUG]:" + MapleCharacter.makeMapleReadable(player.getName()) + ": " + message));
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(1, message));
FilePrinter.printError("bug.txt", MapleCharacter.makeMapleReadable(player.getName()) + ": " + message + "\r\n");
player.dropMessage(5, "Your bug '" + message + "' was submitted successfully to our developers. Thank you!");
break;
/*
case "points":
player.dropMessage(5, "You have " + c.getVotePoints() + " vote point(s).");
if (c.hasVotedAlready()) {
Date currentDate = new Date();
int time = (int) ((int) 86400 - ((currentDate.getTime() / 1000) - c.getVoteTime())); //ugly as fuck
hours = time / 3600;
minutes = time % 3600 / 60;
seconds = time % 3600 % 60;
player.yellowMessage("You have already voted. You can vote again in " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds.");
} else {
player.yellowMessage("You are free to vote! Make sure to vote to gain a vote point!");
}
break;
*/
case "joinevent":
if (!FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) {
MapleEvent event = c.getChannelServer().getEvent();
if (event != null) {
if (event.getMapId() != player.getMapId()) {
if (event.getLimit() > 0) {
player.saveLocation("EVENT");
if (event.getMapId() == 109080000 || event.getMapId() == 109060001)
player.setTeam(event.getLimit() % 2);
event.minusLimit();
player.changeMap(event.getMapId());
} else {
player.dropMessage(5, "The limit of players for the event has already been reached.");
}
} else {
player.dropMessage(5, "You are already in the event.");
}
} else {
player.dropMessage(5, "There is currently no event in progress.");
}
} else {
player.dropMessage(5, "You are currently in a map where you can't join an event.");
}
break;
case "leaveevent":
int returnMap = player.getSavedLocation("EVENT");
if (returnMap != -1) {
if (player.getOla() != null) {
player.getOla().resetTimes();
player.setOla(null);
}
if (player.getFitness() != null) {
player.getFitness().resetTimes();
player.setFitness(null);
}
player.changeMap(returnMap);
if (c.getChannelServer().getEvent() != null) {
c.getChannelServer().getEvent().addLimit();
}
} else {
player.dropMessage(5, "You are not currently in an event.");
}
break;
case "bosshp":
for (MapleMonster monster : player.getMap().getMonsters()) {
if (monster != null && monster.isBoss() && monster.getHp() > 0) {
long percent = monster.getHp() * 100L / monster.getMaxHp();
String bar = "[";
for (int i = 0; i < 100; i++) {
bar += i < percent ? "|" : ".";
}
bar += "]";
player.yellowMessage(monster.getName() + " (" + monster.getId() + ") has " + percent + "% HP left.");
player.yellowMessage("HP: " + bar);
}
}
break;
case "ranks":
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` = '0' AND `accounts`.`banned` = '0' ORDER BY level DESC, exp DESC LIMIT 50");
rs = ps.executeQuery();
player.announce(MaplePacketCreator.showPlayerRanks(9010000, rs));
ps.close();
rs.close();
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
break;
default:
return false;
}
return true;
}
use of tools.Pair in project HeavenMS by ronancpl.
the class MapleCharacter method resetStats.
public void resetStats() {
List<Pair<MapleStat, Integer>> statup = new ArrayList<>(5);
int tap = 0, tsp = 1;
int tstr = 4, tdex = 4, tint = 4, tluk = 4;
int levelap = (isCygnus() ? 6 : 5);
switch(job.getId()) {
case 100:
case 1100:
case 2100:
tstr = 35;
tap = ((getLevel() - 10) * levelap) + 14;
tsp += ((getLevel() - 10) * 3);
break;
case 200:
case 1200:
tint = 20;
tap = ((getLevel() - 8) * levelap) + 29;
tsp += ((getLevel() - 8) * 3);
break;
case 300:
case 1300:
case 400:
case 1400:
tdex = 25;
tap = ((getLevel() - 10) * levelap) + 24;
tsp += ((getLevel() - 10) * 3);
break;
case 500:
case 1500:
tdex = 20;
tap = ((getLevel() - 10) * levelap) + 29;
tsp += ((getLevel() - 10) * 3);
break;
}
this.remainingAp = tap;
this.remainingSp[GameConstants.getSkillBook(job.getId())] = tsp;
this.dex = tdex;
this.int_ = tint;
this.str = tstr;
this.luk = tluk;
statup.add(new Pair<>(MapleStat.AVAILABLEAP, tap));
statup.add(new Pair<>(MapleStat.AVAILABLESP, tsp));
statup.add(new Pair<>(MapleStat.STR, tstr));
statup.add(new Pair<>(MapleStat.DEX, tdex));
statup.add(new Pair<>(MapleStat.INT, tint));
statup.add(new Pair<>(MapleStat.LUK, tluk));
announce(MaplePacketCreator.updatePlayerStats(statup, this));
}
use of tools.Pair in project HeavenMS by ronancpl.
the class MapleCharacter method insertNewChar.
public final boolean insertNewChar() {
Connection con = null;
PreparedStatement ps = null;
try {
con = DatabaseConnection.getConnection();
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
ps = con.prepareStatement("INSERT INTO characters (str, dex, luk, `int`, gm, skincolor, gender, job, hair, face, map, meso, spawnpoint, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, 12);
ps.setInt(2, 5);
ps.setInt(3, 4);
ps.setInt(4, 4);
ps.setInt(5, gmLevel);
ps.setInt(6, skinColor.getId());
ps.setInt(7, gender);
ps.setInt(8, getJob().getId());
ps.setInt(9, hair);
ps.setInt(10, face);
ps.setInt(11, mapid);
ps.setInt(12, Math.abs(meso.get()));
ps.setInt(13, 0);
ps.setInt(14, accountid);
ps.setString(15, name);
ps.setInt(16, world);
int updateRows = ps.executeUpdate();
if (updateRows < 1) {
ps.close();
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Error trying to insert " + name);
return false;
}
ResultSet rs = ps.getGeneratedKeys();
if (rs.next()) {
this.id = rs.getInt(1);
rs.close();
ps.close();
} else {
rs.close();
ps.close();
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Inserting char failed " + name);
return false;
}
// Select a keybinding method
int[] selectedKey;
int[] selectedType;
int[] selectedAction;
if (ServerConstants.USE_CUSTOM_KEYSET) {
selectedKey = GameConstants.getCustomKey(true);
selectedType = GameConstants.getCustomType(true);
selectedAction = GameConstants.getCustomAction(true);
} else {
selectedKey = GameConstants.getCustomKey(false);
selectedType = GameConstants.getCustomType(false);
selectedAction = GameConstants.getCustomAction(false);
}
ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
ps.setInt(1, id);
for (int i = 0; i < selectedKey.length; i++) {
ps.setInt(2, selectedKey[i]);
ps.setInt(3, selectedType[i]);
ps.setInt(4, selectedAction[i]);
ps.execute();
}
ps.close();
final List<Pair<Item, MapleInventoryType>> itemsWithType = new ArrayList<>();
for (MapleInventory iv : inventory) {
for (Item item : iv.list()) {
itemsWithType.add(new Pair<>(item, iv.getType()));
}
}
ItemFactory.INVENTORY.saveItems(itemsWithType, id, con);
con.commit();
return true;
} catch (Throwable t) {
FilePrinter.printError(FilePrinter.INSERT_CHAR, t, "Error creating " + name + " Level: " + level + " Job: " + job.getId());
try {
con.rollback();
} catch (SQLException se) {
FilePrinter.printError(FilePrinter.INSERT_CHAR, se, "Error trying to rollback " + name);
}
return false;
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
con.setAutoCommit(true);
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
use of tools.Pair in project HeavenMS by ronancpl.
the class MapleCharacter method changeJob.
public void changeJob(MapleJob newJob) {
if (newJob == null) {
// the fuck you doing idiot!
return;
}
this.job = newJob;
remainingSp[GameConstants.getSkillBook(newJob.getId())] += 1;
if (GameConstants.hasSPTable(newJob)) {
remainingSp[GameConstants.getSkillBook(newJob.getId())] += 2;
} else {
if (newJob.getId() % 10 == 2) {
remainingSp[GameConstants.getSkillBook(newJob.getId())] += 2;
}
}
if (newJob.getId() % 10 > 1) {
this.remainingAp += 5;
}
// lame temp "fix"
int job_ = job.getId() % 1000;
if (job_ == 100) {
// 1st warrior
maxhp += Randomizer.rand(200, 250);
} else if (job_ == 200) {
// 1st mage
maxmp += Randomizer.rand(100, 150);
} else if (job_ % 100 == 0) {
// 1st others
maxhp += Randomizer.rand(100, 150);
maxhp += Randomizer.rand(25, 50);
} else if (job_ > 0 && job_ < 200) {
// 2nd~4th warrior
maxhp += Randomizer.rand(300, 350);
} else if (job_ < 300) {
// 2nd~4th mage
maxmp += Randomizer.rand(450, 500);
} else if (job_ > 0) {
// 2nd~4th others
maxhp += Randomizer.rand(300, 350);
maxmp += Randomizer.rand(150, 200);
}
if (maxhp >= 30000) {
maxhp = 30000;
}
if (maxmp >= 30000) {
maxmp = 30000;
}
if (!isGM()) {
for (byte i = 1; i < 5; i++) {
gainSlots(i, 4, true);
}
}
List<Pair<MapleStat, Integer>> statup = new ArrayList<>(5);
statup.add(new Pair<>(MapleStat.MAXHP, Integer.valueOf(maxhp)));
statup.add(new Pair<>(MapleStat.MAXMP, Integer.valueOf(maxmp)));
statup.add(new Pair<>(MapleStat.AVAILABLEAP, remainingAp));
statup.add(new Pair<>(MapleStat.AVAILABLESP, remainingSp[GameConstants.getSkillBook(job.getId())]));
statup.add(new Pair<>(MapleStat.JOB, Integer.valueOf(job.getId())));
client.announce(MaplePacketCreator.updatePlayerStats(statup, this));
if (dragon != null) {
getMap().broadcastMessage(MaplePacketCreator.removeDragon(dragon.getObjectId()));
dragon = null;
}
recalcLocalStats();
silentPartyUpdate();
if (this.guildid > 0) {
getGuild().broadcast(MaplePacketCreator.jobMessage(0, job.getId(), name), this.getId());
}
setMasteries(this.job.getId());
guildUpdate();
getMap().broadcastMessage(this, MaplePacketCreator.removePlayerFromMap(this.getId()), false);
getMap().broadcastMessage(this, MaplePacketCreator.spawnPlayerMapObject(this), false);
getMap().broadcastMessage(this, MaplePacketCreator.showForeignEffect(getId(), 8), false);
if (GameConstants.hasSPTable(newJob) && newJob.getId() != 2001) {
if (getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
cancelBuffStats(MapleBuffStat.MONSTER_RIDING);
}
createDragon();
}
}
Aggregations