use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.
the class MapleCharacter method pickupItem.
public final void pickupItem(MapleMapObject ob, int petIndex) {
// yes, one picks the MapleMapObject, not the MapleMapItem
if (ob == null) {
// pet index refers to the one picking up the item
return;
}
if (ob instanceof MapleMapItem) {
MapleMapItem mapitem = (MapleMapItem) ob;
if (System.currentTimeMillis() - mapitem.getDropTime() < 900 || !mapitem.canBePickedBy(this)) {
client.announce(MaplePacketCreator.enableActions());
return;
}
boolean isPet = petIndex > -1;
final byte[] pickupPacket = MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), (isPet) ? 5 : 2, this.getId(), isPet, petIndex);
boolean hasSpaceInventory = true;
if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866 || mapitem.getMeso() > 0 || ii.isConsumeOnPickup(mapitem.getItemId()) || (hasSpaceInventory = MapleInventoryManipulator.checkSpace(client, mapitem.getItemId(), mapitem.getItem().getQuantity(), mapitem.getItem().getOwner()))) {
if ((this.getMapId() > 209000000 && this.getMapId() < 209000016) || (this.getMapId() >= 990000500 && this.getMapId() <= 990000502)) {
// happyville trees and guild PQ
if (!mapitem.isPlayerDrop() || mapitem.getDropper().getObjectId() == client.getPlayer().getObjectId()) {
if (mapitem.getMeso() > 0) {
this.gainMeso(mapitem.getMeso(), true, true, false);
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
int nxGain = mapitem.getItemId() == 4031865 ? 100 : 250;
this.getCashShop().gainCash(1, nxGain);
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else if (MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else {
client.announce(MaplePacketCreator.enableActions());
return;
}
} else {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
client.announce(MaplePacketCreator.enableActions());
return;
}
synchronized (mapitem) {
if (mapitem.getQuest() > 0 && !this.needQuestItem(mapitem.getQuest(), mapitem.getItemId())) {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
if (mapitem.isPickedUp()) {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
if (mapitem.getMeso() > 0) {
prtLock.lock();
try {
if (this.party != null) {
int mesosamm = mapitem.getMeso();
if (mesosamm > 50000 * this.getMesoRate()) {
return;
}
int partynum = 0;
for (MaplePartyCharacter partymem : this.party.getMembers()) {
if (partymem.isOnline() && partymem.getMapId() == this.getMap().getId() && partymem.getChannel() == client.getChannel()) {
partynum++;
}
}
for (MaplePartyCharacter partymem : this.party.getMembers()) {
if (partymem.isOnline() && partymem.getMapId() == this.getMap().getId()) {
MapleCharacter somecharacter = client.getChannelServer().getPlayerStorage().getCharacterById(partymem.getId());
if (somecharacter != null) {
somecharacter.gainMeso(mesosamm / partynum, true, true, false);
}
}
}
} else {
this.gainMeso(mapitem.getMeso(), true, true, false);
}
} finally {
prtLock.unlock();
}
} else if (mapitem.getItem().getItemId() / 10000 == 243) {
MapleItemInformationProvider.scriptedItem info = ii.getScriptedItemInfo(mapitem.getItem().getItemId());
if (info.runOnPickup()) {
ItemScriptManager ism = ItemScriptManager.getInstance();
String scriptName = info.getScript();
if (ism.scriptExists(scriptName)) {
ism.getItemScript(client, scriptName);
}
} else {
if (!MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
client.announce(MaplePacketCreator.enableActions());
return;
}
}
} else if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
int nxGain = mapitem.getItemId() == 4031865 ? 100 : 250;
this.getCashShop().gainCash(1, nxGain);
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
} else if (useItem(client, mapitem.getItem().getItemId())) {
if (mapitem.getItem().getItemId() / 10000 == 238) {
this.getMonsterBook().addCard(client, mapitem.getItem().getItemId());
}
} else if (MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
} else if (mapitem.getItem().getItemId() == 4031868) {
this.getMap().broadcastMessage(MaplePacketCreator.updateAriantPQRanking(this.getName(), this.getItemQuantity(4031868, false), false));
} else {
client.announce(MaplePacketCreator.enableActions());
return;
}
this.getMap().pickItemDrop(pickupPacket, mapitem);
}
} else if (!hasSpaceInventory) {
client.announce(MaplePacketCreator.getInventoryFull());
client.announce(MaplePacketCreator.getShowInventoryFull());
}
}
client.announce(MaplePacketCreator.enableActions());
}
use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.
the class MapleCharacter method getPartyMembersOnSameMap.
public List<MapleCharacter> getPartyMembersOnSameMap() {
List<MapleCharacter> list = new LinkedList<>();
int thisMapHash = this.getMap().hashCode();
prtLock.lock();
try {
if (party != null) {
for (MaplePartyCharacter partyMembers : party.getMembers()) {
if (partyMembers.getPlayer().getMap().hashCode() == thisMapHash)
list.add(partyMembers.getPlayer());
}
}
} finally {
prtLock.unlock();
}
return list;
}
use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.
the class MapleClient method disconnect.
public final synchronized void disconnect(boolean shutdown, boolean cashshop) {
// once per MapleClient instance
if (disconnecting) {
return;
}
disconnecting = true;
if (player != null && player.isLoggedin() && player.getClient() != null) {
MapleMap map = player.getMap();
final MapleParty party = player.getParty();
final int idz = player.getId();
final int messengerid = player.getMessenger() == null ? 0 : player.getMessenger().getId();
// final int fid = player.getFamilyId();
final BuddyList bl = player.getBuddylist();
final MaplePartyCharacter chrp = new MaplePartyCharacter(player);
final MapleMessengerCharacter chrm = new MapleMessengerCharacter(player, 0);
final MapleGuildCharacter chrg = player.getMGC();
final MapleGuild guild = player.getGuild();
player.cancelMagicDoor();
if (channel == -1 || shutdown) {
if (chrg != null)
chrg.setCharacter(null);
removePlayer();
player.saveCooldowns();
player.saveToDB(true);
player = null;
return;
}
removePlayer();
final World worlda = getWorldServer();
try {
if (!cashshop) {
if (!this.serverTransition) {
// meaning not changing channels
if (messengerid > 0) {
worlda.leaveMessenger(messengerid, chrm);
}
/*
if (fid > 0) {
final MapleFamily family = worlda.getFamily(fid);
family.
}
*/
for (MapleQuestStatus status : player.getStartedQuests()) {
// This is for those quests that you have to stay logged in for a certain amount of time
MapleQuest quest = status.getQuest();
if (quest.getTimeLimit() > 0) {
MapleQuestStatus newStatus = new MapleQuestStatus(quest, MapleQuestStatus.Status.NOT_STARTED);
newStatus.setForfeited(player.getQuest(quest).getForfeited() + 1);
player.updateQuest(newStatus);
}
}
if (guild != null) {
final Server server = Server.getInstance();
server.setGuildMemberOnline(player, false, player.getClient().getChannel());
player.getClient().announce(MaplePacketCreator.showGuildInfo(player));
}
if (party != null) {
chrp.setOnline(false);
worlda.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
if (map != null && party.getLeader().getId() == idz) {
MaplePartyCharacter lchr = null;
for (MaplePartyCharacter pchr : party.getMembers()) {
if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() <= pchr.getLevel())) {
lchr = pchr;
}
}
if (lchr != null) {
worlda.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, lchr);
}
}
}
if (bl != null) {
worlda.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds());
}
}
} else {
if (!this.serverTransition) {
// if dc inside of cash shop.
if (party != null) {
chrp.setOnline(false);
worlda.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
if (map != null && party.getLeader().getId() == idz) {
MaplePartyCharacter lchr = null;
for (MaplePartyCharacter pchr : party.getMembers()) {
if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() <= pchr.getLevel())) {
lchr = pchr;
}
}
if (lchr != null) {
worlda.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, lchr);
}
}
}
if (bl != null) {
worlda.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds());
}
}
}
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, e);
} finally {
getChannelServer().removePlayer(player);
if (!this.serverTransition) {
worlda.removePlayer(player);
player.saveCooldowns();
player.saveToDB(true);
if (player != null) {
// no idea, occur :(
player.empty(false);
}
player.logOff();
} else {
player.saveCooldowns();
player.saveToDB();
}
player = null;
}
}
if (!serverTransition && isLoggedIn()) {
updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
// prevents double dcing during login
session.removeAttribute(MapleClient.CLIENT_KEY);
session.close(false);
}
engines.clear();
}
use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.
the class PartyOperationHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int operation = slea.readByte();
MapleCharacter player = c.getPlayer();
World world = c.getWorldServer();
MapleParty party = player.getParty();
MaplePartyCharacter partyplayer = player.getMPC();
switch(operation) {
case 1:
{
// create
if (player.getLevel() < 10 && !ServerConstants.USE_PARTY_FOR_STARTERS) {
c.announce(MaplePacketCreator.partyStatusMessage(10));
return;
}
if (player.getParty() == null) {
partyplayer = new MaplePartyCharacter(player);
party = world.createParty(partyplayer);
player.setParty(party);
player.setMPC(partyplayer);
player.getMap().addPartyMember(player);
player.silentPartyUpdate();
c.announce(MaplePacketCreator.partyCreated(partyplayer));
} else {
c.announce(MaplePacketCreator.serverNotice(5, "You can't create a party as you are already in one."));
}
break;
}
case 2:
{
// leave/disband
leaveParty(party, partyplayer, c);
break;
}
case 3:
{
// join
int partyid = slea.readInt();
if (c.getPlayer().getParty() == null) {
party = world.getParty(partyid);
if (party != null) {
if (party.getMembers().size() < 6) {
partyplayer = new MaplePartyCharacter(player);
player.getMap().addPartyMember(player);
world.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
player.receivePartyMemberHP();
player.updatePartyMemberHP();
} else {
c.announce(MaplePacketCreator.partyStatusMessage(17));
}
} else {
c.announce(MaplePacketCreator.serverNotice(5, "The person you have invited to the party is already in one."));
}
} else {
c.announce(MaplePacketCreator.serverNotice(5, "You can't join the party as you are already in one."));
}
break;
}
case 4:
{
// invite
String name = slea.readMapleAsciiString();
MapleCharacter invited = world.getPlayerStorage().getCharacterByName(name);
if (invited != null) {
if (invited.getLevel() < 10 && (!ServerConstants.USE_PARTY_FOR_STARTERS || player.getLevel() >= 10)) {
// min requirement is level 10
c.announce(MaplePacketCreator.serverNotice(5, "The player you have invited does not meet the requirements."));
return;
}
if (ServerConstants.USE_PARTY_FOR_STARTERS && invited.getLevel() >= 10 && player.getLevel() < 10) {
// trying to invite high level
c.announce(MaplePacketCreator.serverNotice(5, "The player you have invited does not meet the requirements."));
return;
}
if (invited.getParty() == null) {
if (player.getParty() == null) {
if (player.getLevel() < 10 && !ServerConstants.USE_PARTY_FOR_STARTERS) {
c.announce(MaplePacketCreator.partyStatusMessage(10));
return;
}
partyplayer = new MaplePartyCharacter(player);
party = world.createParty(partyplayer);
player.setParty(party);
player.setMPC(partyplayer);
player.getMap().addPartyMember(player);
c.announce(MaplePacketCreator.partyCreated(partyplayer));
}
if (party.getMembers().size() < 6) {
invited.getClient().announce(MaplePacketCreator.partyInvite(player));
} else {
c.announce(MaplePacketCreator.partyStatusMessage(17));
}
} else {
c.announce(MaplePacketCreator.partyStatusMessage(16));
}
} else {
c.announce(MaplePacketCreator.partyStatusMessage(19));
}
break;
}
case 5:
{
// expel
int cid = slea.readInt();
if (partyplayer.equals(party.getLeader())) {
MaplePartyCharacter expelled = party.getMemberById(cid);
if (expelled != null) {
MapleCharacter emc = expelled.getPlayer();
if (emc != null) {
MapleMap map = emc.getMap();
if (map != null)
map.removePartyMember(emc);
EventInstanceManager eim = emc.getEventInstance();
if (eim != null) {
eim.leftParty(emc);
}
emc.setParty(null);
}
world.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
}
}
break;
}
case 6:
{
// change leader
int newLeader = slea.readInt();
MaplePartyCharacter newLeadr = party.getMemberById(newLeader);
world.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
break;
}
}
}
use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.
the class AbstractPlayerInteraction method givePartyExp.
public void givePartyExp(String PQ, boolean instance) {
// 1 player = +0% bonus (100)
// 2 players = +0% bonus (100)
// 3 players = +0% bonus (100)
// 4 players = +10% bonus (110)
// 5 players = +20% bonus (120)
// 6 players = +30% bonus (130)
MapleParty party = getPlayer().getParty();
int size = party.getMembers().size();
if (instance) {
for (MaplePartyCharacter member : party.getMembers()) {
if (member == null || !member.isOnline() || member.getPlayer().getEventInstance() == null) {
size--;
}
}
}
int bonus = size < 4 ? 100 : 70 + (size * 10);
for (MaplePartyCharacter member : party.getMembers()) {
if (member == null || !member.isOnline()) {
continue;
}
MapleCharacter player = member.getPlayer();
if (instance && player.getEventInstance() == null) {
// They aren't in the instance, don't give EXP.
continue;
}
int base = PartyQuest.getExp(PQ, player.getLevel());
int exp = base * bonus / 100;
player.gainExp(exp, true, true);
if (ServerConstants.PQ_BONUS_EXP_RATE > 0 && System.currentTimeMillis() <= ServerConstants.EVENT_END_TIMESTAMP) {
player.gainExp((int) (exp * ServerConstants.PQ_BONUS_EXP_RATE), true, true);
}
}
}
Aggregations