public void save() { for (Pair<String, Integer> pair : portfolio) { try { Connection con = (Connection) DatabaseConnection.getConnection(); PreparedStatement ps; if (newlyAdded.contains(pair)) { ps = con.prepareStatement( "INSERT INTO `maplestocks_data` (`cid`, `stockid`, `shares`) VALUES (?, ?, ?)"); ps.setInt(1, cid); ps.setInt(2, MapleStocks.getInstance().idOf(pair.getLeft())); ps.setInt(3, pair.getRight()); Output.print(ps.toString()); ps.executeUpdate(); } else { ps = con.prepareStatement( "UPDATE maplestocks_data SET shares = ? WHERE cid = ? AND stockid = ?"); ps.setInt(1, pair.getRight()); ps.setInt(2, cid); ps.setInt(3, MapleStocks.getInstance().idOf(pair.getLeft())); Output.print(ps.toString()); ps.executeUpdate(); } } catch (SQLException e) { Output.print("Something went wrong while saving a MapleStockPortfolio."); GameLogger.print(GameLogger.EXCEPTION_CAUGHT, e); } } }
public boolean update(Pair<String, Integer> shares) { Output.print("update() called"); for (Pair<String, Integer> pair : portfolio) { if (pair.getLeft() == shares.getLeft()) { pair.update(pair.getLeft(), pair.getRight() + shares.getRight()); return true; } } return false; }
public boolean remove(MapleStock ms, int quantity) { for (Pair<String, Integer> pair : portfolio) { if (pair.getLeft() == ms.getTicker()) { if (pair.getRight() > quantity) { return this.update(new Pair<String, Integer>(pair.getLeft(), -quantity)); } else if (pair.getRight() == quantity) { portfolio.remove(pair); return true; } } } return false; }
private static int checkRequiredNRemove( final MapleClient c, final List<Pair<Integer, Integer>> recipe) { int itemid = 0; for (final Pair<Integer, Integer> p : recipe) { if (!c.getPlayer().haveItem(p.getLeft(), p.getRight(), false, true)) { return 0; } } for (final Pair<Integer, Integer> p : recipe) { itemid = p.getLeft(); MapleInventoryManipulator.removeById( c, GameConstants.getInventoryType(itemid), itemid, p.getRight(), false, false); } return itemid; }
public CashShop(int accountId, int characterId, int jobType) throws SQLException { this.accountId = accountId; this.characterId = characterId; for (Pair<Item, MapleInventoryType> item : factory.loadItems(false, accountId).values()) { inventory.add(item.getLeft()); } }
@Override public int execute(MapleClient c, String[] splitted) { if (splitted.length < 2) { c.getPlayer().dropMessage(6, splitted[0] + " <数量> <道具名稱>"); return 0; } final String itemName = StringUtil.joinStringFrom(splitted, 2); final short quantity = (short) CommandProcessorUtil.getOptionalIntArg(splitted, 1, 1); int itemId = 0; for (Pair<Integer, String> item : MapleItemInformationProvider.getInstance().getAllItems2()) { if (item.getRight().toLowerCase().equals(itemName.toLowerCase())) { itemId = item.getLeft(); break; } } MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance(); if (!ii.itemExists(itemId)) { c.getPlayer().dropMessage(5, itemName + "不存在"); } else { Item toDrop; if (GameConstants.getInventoryType(itemId) == MapleInventoryType.EQUIP) { toDrop = ii.getEquipById(itemId); } else { toDrop = new client.inventory.Item(itemId, (byte) 0, quantity, (byte) 0); } toDrop.setGMLog(c.getPlayer().getName() + " 使用 " + splitted[0] + " 命令制作"); toDrop.setOwner(c.getPlayer().getName()); c.getPlayer() .getMap() .spawnItemDrop( c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true, true); } return 1; }
public boolean hasStock(MapleStock ms, int quantity) { int amount = 0; for (Pair<String, Integer> pair : portfolio) { if (pair.getLeft().equalsIgnoreCase(ms.getTicker())) { amount += pair.getRight(); } if (amount >= quantity) { Output.print( "hasStock(" + ms.getTicker() + ", " + quantity + ") called; returning " + (amount >= quantity)); return true; } } Output.print( "hasStock(" + ms.getTicker() + ", " + quantity + ") called; returning " + (amount >= quantity)); return (amount >= quantity); }
public MTSCart(int characterId) throws SQLException { this.characterId = characterId; for (Pair<Item, MapleInventoryType> item : ItemLoader.MTS_TRANSFER.loadItems(false, characterId).values()) { transfer.add(item.getLeft()); } loadCart(); loadNotYetSold(); }
public boolean add(Pair<String, Integer> shares) { Output.print("add() called"); if (!this.hasStock(MapleStocks.getInstance().getStock(shares.getLeft()))) { portfolio.add(shares); newlyAdded.add(shares); return true; } return false; }
private static int getRandomGem(final List<Pair<Integer, Integer>> rewards) { int itemid; final List<Integer> items = new ArrayList<>(); for (final Pair p : rewards) { itemid = (Integer) p.getLeft(); for (int i = 0; i < (Integer) p.getRight(); i++) { items.add(itemid); } } return items.get(Randomizer.nextInt(items.size())); }
public static void main(String[] args) { Scanner input = new Scanner(System.in); boolean export; if (args == null) { System.out.println("是否導出全部BUFF訊息? <y/n>"); export = input.next().equalsIgnoreCase("y"); } else { export = true; } if (export) { dumpSkills(); for (Pair c : a) { System.out.println("special char " + c.getRight() + " skill " + c.getLeft()); } } if (args != null) { return; } while (!export) { System.out.println("請輸入技能ID."); int skill; try { skill = input.nextInt(); } catch (Exception ex) { if (!exceptions.contains(ex)) { exceptions.add(ex); } System.out.println("Could not parse skill id."); return; } System.out.println(getSkillInformation(skill).toString()); System.out.println("是否繼續輸入? <y/n>"); export = input.next().equalsIgnoreCase("y"); } if (exceptions.size() > 0) { System.out.println("顯示錯誤異常報錯? <y/n>"); boolean show = input.next().equalsIgnoreCase("y"); if (show) { for (Exception ex : exceptions) { System.out.println(ex.toString()); } } } }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.characterid); out.writeInt(this.accountid); out.writeUTF(this.accountname); out.writeByte(this.channel); out.writeInt(this.ACash); out.writeInt(this.MaplePoints); out.writeUTF(this.name); out.writeInt(this.fame); out.writeInt(this.love); out.writeByte(this.gender); out.writeShort(this.level); out.writeShort(this.str); out.writeShort(this.dex); out.writeShort(this.int_); out.writeShort(this.luk); out.writeInt(this.hp); out.writeInt(this.mp); out.writeInt(this.maxhp); out.writeInt(this.maxmp); out.writeLong(this.exp); out.writeShort(this.hpApUsed); out.writeShort(this.remainingAp); out.writeShort(this.remainingSp); out.writeLong(this.meso); out.writeByte(this.skinColor); out.writeShort(this.job); out.writeInt(this.hair); out.writeInt(this.face); out.writeInt(this.mapid); out.writeByte(this.initialSpawnPoint); out.writeByte(this.world); out.writeInt(this.guildid); out.writeByte(this.guildrank); out.writeInt(this.guildContribution); out.writeByte(this.alliancerank); out.writeInt(this.sidekick); out.writeByte(this.gmLevel); out.writeInt(this.points); out.writeInt(this.vpoints); out.writeByte(this.BlessOfFairy == null ? 0 : 1); if (this.BlessOfFairy != null) { out.writeUTF(this.BlessOfFairy); } out.writeByte(this.BlessOfEmpress == null ? 0 : 1); if (this.BlessOfEmpress != null) { out.writeUTF(this.BlessOfEmpress); } out.writeByte(this.chalkboard == null ? 0 : 1); if (this.chalkboard != null) { out.writeUTF(this.chalkboard); } out.writeObject(this.skillmacro); out.writeLong(this.lastfametime); out.writeObject(this.storage); out.writeObject(this.pvpStats); out.writeObject(this.potionPot); out.writeObject(this.coreAura); out.writeObject(this.cs); out.writeObject(this.battlers); out.writeInt(this.mount_itemid); out.writeByte(this.mount_Fatigue); out.writeByte(this.mount_level); out.writeInt(this.mount_exp); out.writeInt(this.partyid); out.writeInt(this.messengerid); out.writeObject(this.inventorys); out.writeByte(this.fairyExp); out.writeByte(this.subcategory); out.writeShort(this.fatigue); out.writeInt(this.marriageId); out.writeInt(this.familyid); out.writeInt(this.seniorid); out.writeInt(this.junior1); out.writeInt(this.junior2); out.writeInt(this.currentrep); out.writeInt(this.totalrep); out.writeInt(this.gachexp); out.writeInt(this.totalWins); out.writeInt(this.totalLosses); out.writeObject(this.anticheat); out.writeUTF(this.tempIP); out.writeInt(this.pvpExp); out.writeInt(this.pvpPoints); out.writeObject(this.antiMacro); out.writeInt(this.decorate); out.writeInt(this.beans); out.writeInt(this.warning); out.writeInt(this.dollars); out.writeInt(this.shareLots); out.writeInt(this.apstorage); out.writeInt(this.honor); out.writeInt(this.cardStack); out.writeInt(this.morphCount); out.writeInt(this.powerCount); out.writeInt(this.playerPoints); out.writeInt(this.playerEnergy); out.writeInt(this.pvpDeaths); out.writeInt(this.pvpKills); out.writeInt(this.pvpVictory); out.writeInt(this.runningDark); out.writeInt(this.runningDarkSlot); out.writeInt(this.runningLight); out.writeInt(this.runningLightSlot); out.writeShort(this.mbook.size()); for (Map.Entry ms : this.mbook.entrySet()) { out.writeInt(((Integer) ms.getKey())); out.writeInt(((Integer) ms.getValue())); } out.writeShort(this.Skills.size()); for (Map.Entry qs : this.Skills.entrySet()) { out.writeInt(((Integer) qs.getKey())); out.writeInt(((SkillEntry) qs.getValue()).skillLevel); out.writeByte(((SkillEntry) qs.getValue()).masterlevel); out.writeLong(((SkillEntry) qs.getValue()).expiration); out.writeInt(((SkillEntry) qs.getValue()).teachId); out.writeByte(((SkillEntry) qs.getValue()).position); } out.writeByte(this.buddysize); out.writeShort(this.buddies.size()); for (Map.Entry qs : this.buddies.entrySet()) { out.writeInt(((CharacterNameAndId) qs.getKey()).getId()); out.writeUTF(((CharacterNameAndId) qs.getKey()).getName()); out.writeUTF(((CharacterNameAndId) qs.getKey()).getGroup()); out.writeBoolean(((Boolean) qs.getValue())); } out.writeShort(this.Quest.size()); for (Map.Entry qs : this.Quest.entrySet()) { out.writeInt(((Integer) qs.getKey())); out.writeObject(qs.getValue()); } out.writeByte(this.reports.size()); for (Map.Entry ss : this.reports.entrySet()) { out.writeByte(((Byte) ss.getKey())); out.writeInt(((Integer) ss.getValue())); } out.writeByte(this.finishedAchievements.size()); for (Integer zz : this.finishedAchievements) { out.writeInt(zz); } out.writeByte(this.famedcharacters.size()); for (Integer zz : this.famedcharacters) { out.writeInt(zz); } out.writeInt(this.battledaccs.size()); for (Integer zz : this.battledaccs) { out.writeInt(zz); } out.writeByte(this.savedlocation.length); for (int zz : this.savedlocation) { out.writeInt(zz); } out.writeByte(this.wishlist.length); for (int zz : this.wishlist) { out.writeInt(zz); } out.writeByte(this.rocks.length); for (int zz : this.rocks) { out.writeInt(zz); } out.writeByte(this.regrocks.length); for (int zz : this.regrocks) { out.writeInt(zz); } out.writeByte(this.hyperrocks.length); for (int zz : this.hyperrocks) { out.writeInt(zz); } out.writeShort(this.KeyValue.size()); for (Map.Entry key : this.KeyValue.entrySet()) { out.writeUTF((String) key.getKey()); out.writeUTF((String) key.getValue()); } out.writeShort(this.InfoQuest.size()); for (Map.Entry qs : this.InfoQuest.entrySet()) { out.writeInt(((Integer) qs.getKey())); out.writeUTF((String) qs.getValue()); } out.writeInt(this.keymap.size()); for (Map.Entry qs : this.keymap.entrySet()) { out.writeInt(((Integer) qs.getKey())); out.writeByte(((Byte) ((Pair) qs.getValue()).left)); out.writeInt(((Integer) ((Pair) qs.getValue()).right)); } out.writeInt(this.quickslot.size()); for (Pair qs : this.quickslot) { out.writeInt(((Integer) qs.getLeft())); out.writeInt(((Integer) qs.getRight())); } out.writeShort(this.familiars.size()); for (Map.Entry qs : this.familiars.entrySet()) { out.writeInt(((Integer) qs.getKey())); MonsterFamiliar f = (MonsterFamiliar) qs.getValue(); out.writeInt(f.getId()); out.writeInt(f.getFamiliar()); out.writeLong(f.getExpiry()); out.writeUTF(f.getName()); out.writeInt(f.getFatigue()); out.writeByte(f.getVitality()); } out.writeByte(this.petStore); out.writeShort(this.boxed.size()); for (Object boxed1 : this.boxed) { out.writeObject(boxed1); } out.writeShort(this.rebuy.size()); for (MapleShopItem rebuy1 : this.rebuy) { out.writeObject(rebuy1); } out.writeByte(this.imps.length); for (MapleImp imp : this.imps) { if (imp != null) { out.writeByte(1); out.writeInt(imp.getItemId()); out.writeShort(imp.getFullness()); out.writeShort(imp.getCloseness()); out.writeByte(imp.getState()); out.writeByte(imp.getLevel()); } else { out.writeByte(0); } } out.writeLong(this.lastLoveTime); out.writeByte(this.loveCharacters.size()); for (Map.Entry loves : this.loveCharacters.entrySet()) { out.writeInt(((Integer) loves.getKey())); out.writeLong(((Long) loves.getValue())); } }
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()); } }