use of client.MapleRing in project HeavenMS by ronancpl.
the class MaplePacketCreator method addRingLook.
private static void addRingLook(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr, boolean crush) {
List<MapleRing> rings;
if (crush) {
rings = chr.getCrushRings();
} else {
rings = chr.getFriendshipRings();
}
boolean yes = false;
for (MapleRing ring : rings) {
if (ring.equipped()) {
if (yes == false) {
yes = true;
mplew.write(1);
}
mplew.writeInt(ring.getRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getPartnerRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getItemId());
}
}
if (yes == false) {
mplew.write(0);
}
}
use of client.MapleRing in project HeavenMS by ronancpl.
the class MaplePacketCreator method addRingInfo.
private static void addRingInfo(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
mplew.writeShort(chr.getCrushRings().size());
for (MapleRing ring : chr.getCrushRings()) {
mplew.writeInt(ring.getPartnerChrId());
mplew.writeAsciiString(getRightPaddedStr(ring.getPartnerName(), '\0', 13));
mplew.writeInt(ring.getRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getPartnerRingId());
mplew.writeInt(0);
}
mplew.writeShort(chr.getFriendshipRings().size());
for (MapleRing ring : chr.getFriendshipRings()) {
mplew.writeInt(ring.getPartnerChrId());
mplew.writeAsciiString(getRightPaddedStr(ring.getPartnerName(), '\0', 13));
mplew.writeInt(ring.getRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getPartnerRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getItemId());
}
mplew.writeShort(chr.getMarriageRing() != null ? 1 : 0);
int marriageId = 30000;
if (chr.getMarriageRing() != null) {
mplew.writeInt(marriageId);
mplew.writeInt(chr.getId());
mplew.writeInt(chr.getMarriageRing().getPartnerChrId());
mplew.writeShort(3);
mplew.writeInt(chr.getMarriageRing().getRingId());
mplew.writeInt(chr.getMarriageRing().getPartnerRingId());
mplew.writeAsciiString(StringUtil.getRightPaddedStr(chr.getGender() == 0 ? chr.getName() : chr.getMarriageRing().getPartnerName(), '\0', 13));
mplew.writeAsciiString(StringUtil.getRightPaddedStr(chr.getGender() == 0 ? chr.getMarriageRing().getPartnerName() : chr.getName(), '\0', 13));
}
}
use of client.MapleRing in project HeavenMS by ronancpl.
the class CashOperationHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
CashShop cs = chr.getCashShop();
if (!cs.isOpened()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
final int action = slea.readByte();
if (action == 0x03 || action == 0x1E) {
slea.readByte();
final int useNX = slea.readInt();
final int snCS = slea.readInt();
CashItem cItem = CashItemFactory.getItem(snCS);
if (cItem == null || !cItem.isOnSale() || cs.getCash(useNX) < cItem.getPrice()) {
FilePrinter.printError(FilePrinter.ITEM, "Denied to sell cash item with SN " + cItem.getSN());
c.announce(MaplePacketCreator.enableActions());
return;
}
if (action == 0x03) {
// Item
Item item = cItem.toItem();
cs.addToInventory(item);
c.announce(MaplePacketCreator.showBoughtCashItem(item, c.getAccID()));
} else {
// Package
List<Item> cashPackage = CashItemFactory.getPackage(cItem.getItemId());
for (Item item : cashPackage) {
cs.addToInventory(item);
}
c.announce(MaplePacketCreator.showBoughtCashPackage(cashPackage, c.getAccID()));
}
cs.gainCash(useNX, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
} else if (action == 0x04) {
// TODO check for gender
int birthday = slea.readInt();
CashItem cItem = CashItemFactory.getItem(slea.readInt());
Map<String, String> recipient = MapleCharacter.getCharacterFromDatabase(slea.readMapleAsciiString());
String message = slea.readMapleAsciiString();
if (!canBuy(cItem, cs.getCash(4)) || message.length() < 1 || message.length() > 73) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (!checkBirthday(c, birthday)) {
c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xC4));
c.announce(MaplePacketCreator.enableActions());
return;
} else if (recipient == null) {
c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA9));
c.announce(MaplePacketCreator.enableActions());
return;
} else if (recipient.get("accountid").equals(String.valueOf(c.getAccID()))) {
c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA8));
c.announce(MaplePacketCreator.enableActions());
return;
}
cs.gift(Integer.parseInt(recipient.get("id")), chr.getName(), message, cItem.getSN());
c.announce(MaplePacketCreator.showGiftSucceed(recipient.get("name"), cItem));
cs.gainCash(4, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
try {
// fame or not
chr.sendNote(recipient.get("name"), chr.getName() + " has sent you a gift! Go check out the Cash Shop.", (byte) 0);
} catch (SQLException ex) {
ex.printStackTrace();
}
MapleCharacter receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient.get("name"));
if (receiver != null)
receiver.showNote();
} else if (action == 0x05) {
// Modify wish list
cs.clearWishList();
for (byte i = 0; i < 10; i++) {
int sn = slea.readInt();
CashItem cItem = CashItemFactory.getItem(sn);
if (cItem != null && cItem.isOnSale() && sn != 0) {
cs.addToWishList(sn);
}
}
c.announce(MaplePacketCreator.showWishList(chr, true));
} else if (action == 0x06) {
// Increase Inventory Slots
slea.skip(1);
int cash = slea.readInt();
byte mode = slea.readByte();
if (mode == 0) {
byte type = slea.readByte();
if (cs.getCash(cash) < 4000) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.gainSlots(type, 4, false)) {
c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
cs.gainCash(cash, -4000);
c.announce(MaplePacketCreator.showCash(chr));
}
} else {
CashItem cItem = CashItemFactory.getItem(slea.readInt());
int type = (cItem.getItemId() - 9110000) / 1000;
if (!canBuy(cItem, cs.getCash(cash))) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.gainSlots(type, 8, false)) {
c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
cs.gainCash(cash, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
}
}
} else if (action == 0x07) {
// Increase Storage Slots
slea.skip(1);
int cash = slea.readInt();
byte mode = slea.readByte();
if (mode == 0) {
if (cs.getCash(cash) < 4000) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getStorage().gainSlots(4)) {
c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
cs.gainCash(cash, -4000);
c.announce(MaplePacketCreator.showCash(chr));
}
} else {
CashItem cItem = CashItemFactory.getItem(slea.readInt());
if (!canBuy(cItem, cs.getCash(cash))) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getStorage().gainSlots(8)) {
c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
cs.gainCash(cash, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
}
}
} else if (action == 0x08) {
// Increase Character Slots
slea.skip(1);
int cash = slea.readInt();
CashItem cItem = CashItemFactory.getItem(slea.readInt());
if (!canBuy(cItem, cs.getCash(cash))) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (c.gainCharacterSlot()) {
c.announce(MaplePacketCreator.showBoughtCharacterSlot(c.getCharacterSlots()));
cs.gainCash(cash, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
}
} else if (action == 0x0D) {
// Take from Cash Inventory
Item item = cs.findByCashId(slea.readInt());
if (item == null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getInventory(item.getInventoryType()).addItem(item) != -1) {
cs.removeFromInventory(item);
c.announce(MaplePacketCreator.takeFromCashInventory(item));
if (item instanceof Equip) {
Equip equip = (Equip) item;
if (equip.getRingId() >= 0) {
MapleRing ring = MapleRing.loadFromDb(equip.getRingId());
if (ring.getItemId() > 1112012) {
chr.addFriendshipRing(ring);
} else {
chr.addCrushRing(ring);
}
}
}
}
} else if (action == 0x0E) {
// Put into Cash Inventory
int cashId = slea.readInt();
slea.skip(4);
MapleInventory mi = chr.getInventory(MapleInventoryType.getByType(slea.readByte()));
Item item = mi.findByCashId(cashId);
if (item == null) {
c.announce(MaplePacketCreator.enableActions());
return;
} else if (c.getPlayer().getPetIndex(item.getPetId()) > -1) {
chr.getClient().announce(MaplePacketCreator.serverNotice(1, "You cannot put the pet you currently equip into the Cash Shop inventory."));
c.announce(MaplePacketCreator.enableActions());
return;
}
cs.addToInventory(item);
mi.removeSlot(item.getPosition());
c.announce(MaplePacketCreator.putIntoCashInventory(item, c.getAccID()));
} else if (action == 0x1D) {
// crush ring (action 28)
// Birthday
slea.readInt();
// if (checkBirthday(c, birthday)) { //We're using a default birthday, so why restrict rings to only people who know of it?
int toCharge = slea.readInt();
int SN = slea.readInt();
String recipientName = slea.readMapleAsciiString();
String text = slea.readMapleAsciiString();
CashItem itemRing = CashItemFactory.getItem(SN);
MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(recipientName);
if (partner == null) {
chr.getClient().announce(MaplePacketCreator.serverNotice(1, "The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel."));
} else {
if (itemRing.toItem() instanceof Equip) {
Equip eqp = (Equip) itemRing.toItem();
int ringid = MapleRing.createRing(itemRing.getItemId(), chr, partner);
eqp.setRingId(ringid);
cs.addToInventory(eqp);
c.announce(MaplePacketCreator.showBoughtCashItem(eqp, c.getAccID()));
cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), (ringid + 1));
cs.gainCash(toCharge, -itemRing.getPrice());
chr.addCrushRing(MapleRing.loadFromDb(ringid));
try {
chr.sendNote(partner.getName(), text, (byte) 1);
} catch (SQLException ex) {
ex.printStackTrace();
}
partner.showNote();
}
}
/* } else {
chr.dropMessage("The birthday you entered was incorrect.");
}*/
c.announce(MaplePacketCreator.showCash(c.getPlayer()));
} else if (action == 0x20) {
// everything is 1 meso...
int itemId = CashItemFactory.getItem(slea.readInt()).getItemId();
if (chr.getMeso() > 0) {
if (chr.canHold(itemId)) {
chr.gainMeso(-1, false);
MapleInventoryManipulator.addById(c, itemId, (short) 1);
c.announce(MaplePacketCreator.showBoughtQuestItem(itemId));
}
}
c.announce(MaplePacketCreator.showCash(c.getPlayer()));
} else if (action == 0x23) {
// Friendship :3
// Birthday
slea.readInt();
// if (checkBirthday(c, birthday)) {
int payment = slea.readByte();
// 0s
slea.skip(3);
int snID = slea.readInt();
CashItem itemRing = CashItemFactory.getItem(snID);
String sentTo = slea.readMapleAsciiString();
int available = slea.readShort() - 1;
String text = slea.readAsciiString(available);
slea.readByte();
MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(sentTo);
if (partner == null) {
chr.dropMessage("The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel.");
} else {
// Need to check to make sure its actually an equip and the right SN...
if (itemRing.toItem() instanceof Equip) {
Equip eqp = (Equip) itemRing.toItem();
int ringid = MapleRing.createRing(itemRing.getItemId(), chr, partner);
eqp.setRingId(ringid);
cs.addToInventory(eqp);
c.announce(MaplePacketCreator.showBoughtCashItem(eqp, c.getAccID()));
cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), (ringid + 1));
cs.gainCash(payment, -itemRing.getPrice());
chr.addFriendshipRing(MapleRing.loadFromDb(ringid));
try {
chr.sendNote(partner.getName(), text, (byte) 1);
} catch (SQLException ex) {
ex.printStackTrace();
}
partner.showNote();
}
}
/* } else {
chr.dropMessage("The birthday you entered was incorrect.");
} */
c.announce(MaplePacketCreator.showCash(c.getPlayer()));
} else {
System.out.println(slea);
}
}
use of client.MapleRing in project HeavenMS by ronancpl.
the class MaplePacketCreator method addMarriageRingLook.
private static void addMarriageRingLook(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
MapleRing ring = chr.getMarriageRing();
if (ring != null && !ring.equipped()) {
mplew.write(0);
return;
}
mplew.writeBool(ring != null);
if (ring != null) {
mplew.writeInt(chr.getId());
mplew.writeInt(ring.getPartnerChrId());
mplew.writeInt(ring.getRingId());
}
}
Aggregations