-
[Release] Hired Merchant Fixes (BubblesDev)
PHP Code:
package server.maps;
import java.sql.PreparedStatement;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import client.IItem;
import client.MapleCharacter;
import client.MapleClient;
import tools.DatabaseConnection;
import net.MaplePacket;
import server.MapleInventoryManipulator;
import server.MaplePlayerShopItem;
import server.TimerManager;
import tools.MaplePacketCreator;
/**
*
* @author XoticStory
*/
public class HiredMerchant extends AbstractMapleMapObject {
private int ownerId;
private int itemId;
private String ownerName = "";
private String description = "";
private MapleCharacter[] visitors = new MapleCharacter[3];
private List<MaplePlayerShopItem> items = new LinkedList<MaplePlayerShopItem>();
private boolean open;
public ScheduledFuture<?> schedule = null;
private MapleMap map;
public HiredMerchant(final MapleCharacter owner, int itemId, String desc) {
this.setPosition(owner.getPosition());
this.ownerId = owner.getId();
this.itemId = itemId;
this.ownerName = owner.getName();
this.description = desc;
this.map = owner.getMap();
this.schedule = TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
HiredMerchant.this.closeShop(owner.getClient());
}
}, 1000 * 60 * 60 * 24);
}
public void broadcastToVisitors(MaplePacket packet) {
for (MapleCharacter visitor : visitors)
if (visitor != null)
visitor.getClient().getSession().write(packet);
}
public void addVisitor(MapleCharacter visitor) {
int i = this.getFreeSlot();
if (i > -1) {
visitors[i] = visitor;
broadcastToVisitors(MaplePacketCreator.hiredMerchantVisitorAdd(visitor, i + 1));
}
}
public void removeVisitor(MapleCharacter visitor) {
int slot = getVisitorSlot(visitor);
if (visitors[slot] == visitor) {
visitors[slot] = null;
broadcastToVisitors(MaplePacketCreator.hiredMerchantVisitorLeave(slot + 1, false));
}
}
public int getVisitorSlot(MapleCharacter visitor) {
for (int i = 0; i < 3; i++)
if (visitors[i] == visitor)
return i;
return 1;
}
public void removeAllVisitors(String message) {
for (int i = 0; i < 3; i++)
if (visitors[i] != null) {
visitors[i].getClient().getSession().write(MaplePacketCreator.hiredMerchantForceLeave1());
visitors[i].getClient().getSession().write(MaplePacketCreator.hiredMerchantForceLeave2());
if (message.length() > 0)
visitors[i].dropMessage(1, message);
visitors[i] = null;
}
}
public void buy(MapleClient c, int item, short quantity) {
MaplePlayerShopItem pItem = items.get(item);
synchronized (items) {
IItem newItem = pItem.getItem().copy();
newItem.setQuantity((short) (newItem.getQuantity() * quantity));
if (c.getPlayer().getMeso() >= pItem.getPrice() * quantity) {
c.getPlayer().gainMeso(-pItem.getPrice() * quantity, false);
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET MerchantMesos = MerchantMesos + " + pItem.getPrice() * quantity + " WHERE id = ?");
ps.setInt(1, ownerId);
ps.executeUpdate();
ps.close();
} catch (Exception e) {
}
MapleInventoryManipulator.addFromDrop(c, newItem, true);
pItem.setBundles((short) (pItem.getBundles() - quantity));
if (pItem.getBundles() < 1)
pItem.setDoesExist(false);
} else
c.getPlayer().dropMessage(1, "You do not have enough mesos.");
}
}
public void closeShop(MapleClient c) {
map.removeMapObject(this);
map.broadcastMessage(MaplePacketCreator.destroyHiredMerchant(ownerId));
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET HasMerchant = 0 WHERE id = ?");
ps.setInt(1, ownerId);
ps.executeUpdate();
ps.close();
for (MaplePlayerShopItem mpsi : getItems())
if (mpsi.getBundles() > 2)
MapleInventoryManipulator.addById(c, mpsi.getItem().getItemId(), (short) mpsi.getBundles(), null, -1);
else if (mpsi.isExist())
MapleInventoryManipulator.addFromDrop(c, mpsi.getItem(), true);
} catch (Exception e) {
}
schedule.cancel(false);
}
public String getOwner() {
return ownerName;
}
public int getOwnerId() {
return ownerId;
}
public String getDescription() {
return description;
}
public MapleCharacter[] getVisitors() {
return visitors;
}
public List<MaplePlayerShopItem> getItems() {
return Collections.unmodifiableList(items);
}
public void addItem(MaplePlayerShopItem item) {
items.add(item);
}
public void removeFromSlot(int slot) {
items.remove(slot);
}
public int getFreeSlot() {
for (int i = 0; i < 3; i++)
if (visitors[i] == null)
return i;
return -1;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isOpen() {
return open;
}
public void setOpen(boolean set) {
this.open = set;
}
public int getItemId() {
return itemId;
}
public boolean isOwner(MapleCharacter chr) {
return chr.getId() == ownerId && chr.getName().equals(ownerName);
}
@Override
public void sendDestroyData(MapleClient client) {
throw new UnsupportedOperationException();
}
@Override
public MapleMapObjectType getType() {
return MapleMapObjectType.HIRED_MERCHANT;
}
@Override
public void sendSpawnData(MapleClient client) {
client.getSession().write(MaplePacketCreator.spawnHiredMerchant(this));
}
}
and this
PHP Code:
package server;
import client.IItem;
/**
*
* @author Matze
*/
public class MaplePlayerShopItem {
private IItem item;
private short bundles;
private int price;
private boolean doesExist;
public MaplePlayerShopItem(IItem item, short bundles, int price) {
this.item = item;
this.bundles = bundles;
this.price = price;
this.doesExist = true;
}
public void setDoesExist(boolean tf) {
this.doesExist = tf;
}
public boolean isExist() {
return doesExist;
}
public IItem getItem() {
return item;
}
public short getBundles() {
return bundles;
}
public int getPrice() {
return price;
}
public void setBundles(short bundles) {
this.bundles = bundles;
}
}
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
what exactly does this fix about them?
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Wow i dun see the point in posting this... Moogra posted the fix in the Section already -.-
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Please post a user friendly guide next time for everyone, not many people know where that goes. And i guess this is in bublesdev already o.O
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
its not in bubblesdev yet but Moogra released it in the BubblesDev post.. he just reposted it
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
This was already posted in his thread.
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Quote:
Originally Posted by
Stampede
This was already posted in his thread.
Thats wut i said lol... he always does this w/e
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
first file is HiredMerchant.java
second file is MaplePlayerShopItem.java
the file names are written on the fucking files
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Quote:
Originally Posted by
Anti-Racist
first file is HiredMerchant.java
second file is MaplePlayerShopItem.java
the file names are written on the fucking files
Lol you took the words right outta my mouth :D
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
who ever this kid is, is a leaching noob who rips others work <3 PZ NOW GO RQ! (rq means RageQuit)
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Quote:
Originally Posted by
scarlet12379
who ever this kid is, is a leaching noob who rips others work <3 PZ NOW GO RQ! (rq means RageQuit)
he was trying to help?
don't judge people too quickly.
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Quote:
Originally Posted by
Moogra
i think ^^^ is a pretty cool guy. eh releases on an account not well known and doesn't afraid of anything
Nice && Isn't*?
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Quote:
Originally Posted by
Moogra
i think ^^^ is a pretty cool guy. eh releases on an account not well known and doesn't afraid of anything
i agree :)
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
well im mean and well its kinda dumb to post something some one already posted =/
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Quote:
Originally Posted by
scarlet12379
well im mean and well its kinda dumb to post something some one already posted =/
How do you think most things get here?
from other forums/posts.
he was doing that o-o's,
End of topic lol
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
Quote:
Originally Posted by
yogiram1235
i agree :)
i think yogiram1235 is a pretty cool guy. eh agrees and doesn't afraid of anything.
http://encyclopediadramatica.com/Pretty_cool_guy
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
I think ^^^ is a pretty cool guy. eh lieks yogiram and doesn't afraid of anything
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
I think OreansSucks is a pretty cool guy. eh triple posts and doesn't afraid of anything.
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
I think MyEnterprises is a pretty cool guy. eh has cool bats and doesn't afraid of anything.
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
I think OreansSucks is a pretty cool guy. eh steals other account and doesn't afraid of anything.
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
I think MyEnterprises is a pretty cool guy. hates KidFlow like everyone else and doesn't afraid of anything.
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
I think Alyan is a pretty cool guy, has a lot of posts, the higher his post count, the bigger his penis is.
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
I think Eternitron is a pretty cool guy. eh doesn't know the phrase and doesn't afraid of anything
-
Re: [Release] Hired Merchant Fixes (BubblesDev)
where do you put these.. 1 and 2nd