Reformat and clean up "client" package

This commit is contained in:
P0nk
2021-09-09 23:21:39 +02:00
parent 07f55fa53c
commit 9bf1b68924
108 changed files with 1770 additions and 1543 deletions

View File

@@ -20,7 +20,6 @@
package client; package client;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public interface AbstractCharacterListener { public interface AbstractCharacterListener {

View File

@@ -40,31 +40,32 @@ public class BuddyList {
public enum BuddyAddResult { public enum BuddyAddResult {
BUDDYLIST_FULL, ALREADY_ON_LIST, OK BUDDYLIST_FULL, ALREADY_ON_LIST, OK
} }
private Map<Integer, BuddylistEntry> buddies = new LinkedHashMap<>();
private final Map<Integer, BuddylistEntry> buddies = new LinkedHashMap<>();
private int capacity; private int capacity;
private Deque<CharacterNameAndId> pendingRequests = new LinkedList<>(); private final Deque<CharacterNameAndId> pendingRequests = new LinkedList<>();
public BuddyList(int capacity) { public BuddyList(int capacity) {
this.capacity = capacity; this.capacity = capacity;
} }
public boolean contains(int characterId) { public boolean contains(int characterId) {
synchronized(buddies) { synchronized (buddies) {
return buddies.containsKey(characterId); return buddies.containsKey(characterId);
} }
} }
public boolean containsVisible(int characterId) { public boolean containsVisible(int characterId) {
BuddylistEntry ble; BuddylistEntry ble;
synchronized(buddies) { synchronized (buddies) {
ble = buddies.get(characterId); ble = buddies.get(characterId);
} }
if (ble == null) { if (ble == null) {
return false; return false;
} }
return ble.isVisible(); return ble.isVisible();
} }
public int getCapacity() { public int getCapacity() {
@@ -76,7 +77,7 @@ public class BuddyList {
} }
public BuddylistEntry get(int characterId) { public BuddylistEntry get(int characterId) {
synchronized(buddies) { synchronized (buddies) {
return buddies.get(characterId); return buddies.get(characterId);
} }
} }
@@ -88,36 +89,36 @@ public class BuddyList {
return ble; return ble;
} }
} }
return null; return null;
} }
public void put(BuddylistEntry entry) { public void put(BuddylistEntry entry) {
synchronized(buddies) { synchronized (buddies) {
buddies.put(entry.getCharacterId(), entry); buddies.put(entry.getCharacterId(), entry);
} }
} }
public void remove(int characterId) { public void remove(int characterId) {
synchronized(buddies) { synchronized (buddies) {
buddies.remove(characterId); buddies.remove(characterId);
} }
} }
public Collection<BuddylistEntry> getBuddies() { public Collection<BuddylistEntry> getBuddies() {
synchronized(buddies) { synchronized (buddies) {
return Collections.unmodifiableCollection(buddies.values()); return Collections.unmodifiableCollection(buddies.values());
} }
} }
public boolean isFull() { public boolean isFull() {
synchronized(buddies) { synchronized (buddies) {
return buddies.size() >= capacity; return buddies.size() >= capacity;
} }
} }
public int[] getBuddyIds() { public int[] getBuddyIds() {
synchronized(buddies) { synchronized (buddies) {
int[] buddyIds = new int[buddies.size()]; int[] buddyIds = new int[buddies.size()];
int i = 0; int i = 0;
for (BuddylistEntry ble : buddies.values()) { for (BuddylistEntry ble : buddies.values()) {
@@ -126,12 +127,12 @@ public class BuddyList {
return buddyIds; return buddyIds;
} }
} }
public void broadcast(Packet packet, PlayerStorage pstorage) { public void broadcast(Packet packet, PlayerStorage pstorage) {
for(int bid : getBuddyIds()) { for (int bid : getBuddyIds()) {
Character chr = pstorage.getCharacterById(bid); Character chr = pstorage.getCharacterById(bid);
if(chr != null && chr.isLoggedinWorld()) { if (chr != null && chr.isLoggedinWorld()) {
chr.sendPacket(packet); chr.sendPacket(packet);
} }
} }

View File

@@ -22,17 +22,16 @@
package client; package client;
public class BuddylistEntry { public class BuddylistEntry {
private String name; private final String name;
private String group; private String group;
private int cid; private final int cid;
private int channel; private int channel;
private boolean visible; private boolean visible;
/** /**
*
* @param name * @param name
* @param characterId * @param characterId
* @param channel should be -1 if the buddy is offline * @param channel should be -1 if the buddy is offline
* @param visible * @param visible
*/ */
public BuddylistEntry(String name, String group, int characterId, int channel, boolean visible) { public BuddylistEntry(String name, String group, int characterId, int channel, boolean visible) {
@@ -102,9 +101,6 @@ public class BuddylistEntry {
return false; return false;
} }
final BuddylistEntry other = (BuddylistEntry) obj; final BuddylistEntry other = (BuddylistEntry) obj;
if (cid != other.cid) { return cid == other.cid;
return false;
}
return true;
} }
} }

View File

@@ -22,8 +22,8 @@
package client; package client;
public class CharacterNameAndId { public class CharacterNameAndId {
private int id; private final int id;
private String name; private final String name;
public CharacterNameAndId(int id, String name) { public CharacterNameAndId(int id, String name) {
super(); super();

View File

@@ -153,7 +153,7 @@ public class Client extends ChannelInboundHandlerAdapter {
} }
public static Client createMock() { public static Client createMock() {
return new Client(null, -1,null, null, -123, -123); return new Client(null, -1, null, null, -123, -123);
} }
@Override @Override

View File

@@ -447,7 +447,9 @@ public class FamilyEntry {
public synchronized boolean isJunior(FamilyEntry entry) { //require locking since result accuracy is vital public synchronized boolean isJunior(FamilyEntry entry) { //require locking since result accuracy is vital
if (juniors[0] == entry) { if (juniors[0] == entry) {
return true; return true;
} else return juniors[1] == entry; } else {
return juniors[1] == entry;
}
} }
public synchronized boolean removeJunior(FamilyEntry junior) { public synchronized boolean removeJunior(FamilyEntry junior) {

View File

@@ -37,12 +37,12 @@ import java.util.concurrent.locks.Lock;
public final class MonsterBook { public final class MonsterBook {
private static final Semaphore semaphore = new Semaphore(10); private static final Semaphore semaphore = new Semaphore(10);
private int specialCard = 0; private int specialCard = 0;
private int normalCard = 0; private int normalCard = 0;
private int bookLevel = 1; private int bookLevel = 1;
private Map<Integer, Integer> cards = new LinkedHashMap<>(); private final Map<Integer, Integer> cards = new LinkedHashMap<>();
private Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.BOOK); private final Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.BOOK);
public Set<Entry<Integer, Integer>> getCardSet() { public Set<Entry<Integer, Integer>> getCardSet() {
lock.lock(); lock.lock();
@@ -52,23 +52,23 @@ public final class MonsterBook {
lock.unlock(); lock.unlock();
} }
} }
public void addCard(final Client c, final int cardid) { public void addCard(final Client c, final int cardid) {
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), PacketCreator.showForeignCardEffect(c.getPlayer().getId()), false); c.getPlayer().getMap().broadcastMessage(c.getPlayer(), PacketCreator.showForeignCardEffect(c.getPlayer().getId()), false);
Integer qty; Integer qty;
lock.lock(); lock.lock();
try { try {
qty = cards.get(cardid); qty = cards.get(cardid);
if(qty != null) { if (qty != null) {
if(qty < 5) { if (qty < 5) {
cards.put(cardid, qty + 1); cards.put(cardid, qty + 1);
} }
} else { } else {
cards.put(cardid, 1); cards.put(cardid, 1);
qty = 0; qty = 0;
if (cardid / 1000 >= 2388) { if (cardid / 1000 >= 2388) {
specialCard++; specialCard++;
} else { } else {
@@ -78,12 +78,12 @@ public final class MonsterBook {
} finally { } finally {
lock.unlock(); lock.unlock();
} }
if(qty < 5) { if (qty < 5) {
if (qty == 0) { // leveling system only accounts unique cards if (qty == 0) { // leveling system only accounts unique cards
calculateLevel(); calculateLevel();
} }
c.sendPacket(PacketCreator.addCard(false, cardid, qty + 1)); c.sendPacket(PacketCreator.addCard(false, cardid, qty + 1));
c.sendPacket(PacketCreator.showGainCard()); c.sendPacket(PacketCreator.showGainCard());
} else { } else {
@@ -95,13 +95,13 @@ public final class MonsterBook {
lock.lock(); lock.lock();
try { try {
int collectionExp = (normalCard + specialCard); int collectionExp = (normalCard + specialCard);
int level = 0, expToNextlevel = 1; int level = 0, expToNextlevel = 1;
do { do {
level++; level++;
expToNextlevel += level * 10; expToNextlevel += level * 10;
} while (collectionExp >= expToNextlevel); } while (collectionExp >= expToNextlevel);
bookLevel = level; // thanks IxianMace for noticing book level differing between book UI and character info UI bookLevel = level; // thanks IxianMace for noticing book level differing between book UI and character info UI
} finally { } finally {
lock.unlock(); lock.unlock();
@@ -183,16 +183,16 @@ public final class MonsterBook {
private static int saveStringConcat(char[] data, int pos, Integer i) { private static int saveStringConcat(char[] data, int pos, Integer i) {
return saveStringConcat(data, pos, i.toString()); return saveStringConcat(data, pos, i.toString());
} }
private static int saveStringConcat(char[] data, int pos, String s) { private static int saveStringConcat(char[] data, int pos, String s) {
int len = s.length(); int len = s.length();
for(int j = 0; j < len; j++) { for (int j = 0; j < len; j++) {
data[pos + j] = s.charAt(j); data[pos + j] = s.charAt(j);
} }
return pos + len; return pos + len;
} }
private static String getSaveString(Integer charid, Set<Entry<Integer, Integer>> cardSet) { private static String getSaveString(Integer charid, Set<Entry<Integer, Integer>> cardSet) {
semaphore.acquireUninterruptibly(); semaphore.acquireUninterruptibly();
try { try {
@@ -210,13 +210,13 @@ public final class MonsterBook {
i = saveStringConcat(save, i, all.getValue()); //1 char due to being 0 ~ 5 i = saveStringConcat(save, i, all.getValue()); //1 char due to being 0 ~ 5
i = saveStringConcat(save, i, "),"); i = saveStringConcat(save, i, "),");
} }
return new String(save, 0, i - 1); return new String(save, 0, i - 1);
} finally { } finally {
semaphore.release(); semaphore.release();
} }
} }
public void saveCards(final int charid) { public void saveCards(final int charid) {
Set<Entry<Integer, Integer>> cardSet = getCardSet(); Set<Entry<Integer, Integer>> cardSet = getCardSet();
@@ -237,7 +237,7 @@ public final class MonsterBook {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static int[] getCardTierSize() { public static int[] getCardTierSize() {
try (Connection con = DatabaseConnection.getConnection(); try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM monstercarddata GROUP BY floor(cardid / 1000);", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM monstercarddata GROUP BY floor(cardid / 1000);", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

View File

@@ -28,11 +28,11 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Skill { public class Skill {
private int id; private final int id;
private List<StatEffect> effects = new ArrayList<>(); private final List<StatEffect> effects = new ArrayList<>();
private Element element; private Element element;
private int animationTime; private int animationTime;
private int job; private final int job;
private boolean action; private boolean action;
public Skill(int id) { public Skill(int id) {
@@ -54,18 +54,18 @@ public class Skill {
public boolean isFourthJob() { public boolean isFourthJob() {
if (job == 2212) { if (job == 2212) {
return false; return false;
} }
if (id == 22170001 || id == 22171003 || id == 22171004 || id == 22181002 || id == 22181003) { if (id == 22170001 || id == 22171003 || id == 22171004 || id == 22181002 || id == 22181003) {
return true; return true;
} }
return job % 10 == 2; return job % 10 == 2;
} }
public void setElement(Element elem) { public void setElement(Element elem) {
element = elem; element = elem;
} }
public Element getElement() { public Element getElement() {
return element; return element;
} }
@@ -73,11 +73,11 @@ public class Skill {
public int getAnimationTime() { public int getAnimationTime() {
return animationTime; return animationTime;
} }
public void setAnimationTime(int time) { public void setAnimationTime(int time) {
animationTime = time; animationTime = time;
} }
public void incAnimationTime(int time) { public void incAnimationTime(int time) {
animationTime += time; animationTime += time;
} }
@@ -85,7 +85,7 @@ public class Skill {
public boolean isBeginnerSkill() { public boolean isBeginnerSkill() {
return id % 10000000 < 10000; return id % 10000000 < 10000;
} }
public void setAction(boolean act) { public void setAction(boolean act) {
action = act; action = act;
} }
@@ -93,7 +93,7 @@ public class Skill {
public boolean getAction() { public boolean getAction() {
return action; return action;
} }
public void addLevelEffect(StatEffect effect) { public void addLevelEffect(StatEffect effect) {
effects.add(effect); effects.add(effect);
} }

View File

@@ -58,7 +58,7 @@ public class SkillFactory {
skills = loadedSkills; skills = loadedSkills;
} }
private static Skill loadFromData(int id, Data data) { private static Skill loadFromData(int id, Data data) {
Skill ret = new Skill(id); Skill ret = new Skill(id);
boolean isBuff = false; boolean isBuff = false;
@@ -77,7 +77,7 @@ public class SkillFactory {
} else { } else {
Data action_ = data.getChildByPath("action"); Data action_ = data.getChildByPath("action");
boolean action = false; boolean action = false;
if (action_ == null) { if (action_ == null) {
if (data.getChildByPath("prepare/action") != null) { if (data.getChildByPath("prepare/action") != null) {
action = true; action = true;
} else { } else {
@@ -88,10 +88,10 @@ public class SkillFactory {
break; break;
} }
} }
} else { } else {
action = true; action = true;
} }
ret.setAction(action); ret.setAction(action);
Data hit = data.getChildByPath("hit"); Data hit = data.getChildByPath("hit");
Data ball = data.getChildByPath("ball"); Data ball = data.getChildByPath("ball");
isBuff = effect != null && hit == null && ball == null; isBuff = effect != null && hit == null && ball == null;
@@ -185,7 +185,7 @@ public class SkillFactory {
case ILMage.SEAL: case ILMage.SEAL:
case ILWizard.SLOW: case ILWizard.SLOW:
case ILMage.SPELL_BOOSTER: case ILMage.SPELL_BOOSTER:
case ILArchMage.HEROS_WILL: case ILArchMage.HEROS_WILL:
case ILArchMage.INFINITY: case ILArchMage.INFINITY:
case ILArchMage.MANA_REFLECTION: case ILArchMage.MANA_REFLECTION:
case ILArchMage.MAPLE_WARRIOR: case ILArchMage.MAPLE_WARRIOR:
@@ -227,7 +227,7 @@ public class SkillFactory {
case Bandit.DAGGER_BOOSTER: case Bandit.DAGGER_BOOSTER:
case Bandit.HASTE: case Bandit.HASTE:
case ChiefBandit.MESO_GUARD: case ChiefBandit.MESO_GUARD:
case ChiefBandit.PICKPOCKET: case ChiefBandit.PICKPOCKET:
case Shadower.HEROS_WILL: case Shadower.HEROS_WILL:
case Shadower.MAPLE_WARRIOR: case Shadower.MAPLE_WARRIOR:
case Shadower.NINJA_AMBUSH: case Shadower.NINJA_AMBUSH:
@@ -339,8 +339,9 @@ public class SkillFactory {
} }
if (data.getChildByPath(skill.toString()) != null) { if (data.getChildByPath(skill.toString()) != null) {
for (Data skilldata : data.getChildByPath(skill.toString()).getChildren()) { for (Data skilldata : data.getChildByPath(skill.toString()).getChildren()) {
if (skilldata.getName().equals("name")) if (skilldata.getName().equals("name")) {
return DataTool.getString(skilldata, null); return DataTool.getString(skilldata, null);
}
} }
} }

View File

@@ -25,9 +25,9 @@ public class SkillMacro {
private int skill1; private int skill1;
private int skill2; private int skill2;
private int skill3; private int skill3;
private String name; private final String name;
private int shout; private final int shout;
private int position; private final int position;
public SkillMacro(int skill1, int skill2, int skill3, String name, int shout, int position) { public SkillMacro(int skill1, int skill2, int skill3, String name, int shout, int position) {
this.skill1 = skill1; this.skill1 = skill1;
@@ -49,7 +49,7 @@ public class SkillMacro {
public int getSkill3() { public int getSkill3() {
return skill3; return skill3;
} }
public void setSkill1(int skill) { public void setSkill1(int skill) {
skill1 = skill; skill1 = skill;
} }

View File

@@ -30,75 +30,74 @@ import tools.FilePrinter;
import tools.PacketCreator; import tools.PacketCreator;
/** /**
*
* @author kevintjuh93 * @author kevintjuh93
*/ */
public enum AutobanFactory { public enum AutobanFactory {
MOB_COUNT, MOB_COUNT,
GENERAL, GENERAL,
FIX_DAMAGE, FIX_DAMAGE,
DAMAGE_HACK(15, 60 * 1000), DAMAGE_HACK(15, 60 * 1000),
DISTANCE_HACK(10, 120 * 1000), DISTANCE_HACK(10, 120 * 1000),
PORTAL_DISTANCE(5, 30000), PORTAL_DISTANCE(5, 30000),
PACKET_EDIT, PACKET_EDIT,
ACC_HACK, ACC_HACK,
CREATION_GENERATOR, CREATION_GENERATOR,
HIGH_HP_HEALING, HIGH_HP_HEALING,
FAST_HP_HEALING(15), FAST_HP_HEALING(15),
FAST_MP_HEALING(20, 30000), FAST_MP_HEALING(20, 30000),
GACHA_EXP, GACHA_EXP,
TUBI(20, 15000), TUBI(20, 15000),
SHORT_ITEM_VAC, SHORT_ITEM_VAC,
ITEM_VAC, ITEM_VAC,
FAST_ITEM_PICKUP(5, 30000), FAST_ITEM_PICKUP(5, 30000),
FAST_ATTACK(10, 30000), FAST_ATTACK(10, 30000),
MPCON(25, 30000); MPCON(25, 30000);
private int points; private final int points;
private long expiretime; private final long expiretime;
private AutobanFactory() { AutobanFactory() {
this(1, -1); this(1, -1);
} }
private AutobanFactory(int points) { AutobanFactory(int points) {
this.points = points; this.points = points;
this.expiretime = -1; this.expiretime = -1;
} }
private AutobanFactory(int points, long expire) { AutobanFactory(int points, long expire) {
this.points = points; this.points = points;
this.expiretime = expire; this.expiretime = expire;
} }
public int getMaximum() { public int getMaximum() {
return points; return points;
} }
public long getExpire() { public long getExpire() {
return expiretime; return expiretime;
} }
public void addPoint(AutobanManager ban, String reason) { public void addPoint(AutobanManager ban, String reason) {
ban.addPoint(this, reason); ban.addPoint(this, reason);
} }
public void alert(Character chr, String reason) { public void alert(Character chr, String reason) {
if(YamlConfig.config.server.USE_AUTOBAN == true) { if (YamlConfig.config.server.USE_AUTOBAN == true) {
if (chr != null && MapleLogger.ignored.contains(chr.getId())){ if (chr != null && MapleLogger.ignored.contains(chr.getId())) {
return; return;
}
Server.getInstance().broadcastGMMessage((chr != null ? chr.getWorld() : 0), PacketCreator.sendYellowTip((chr != null ? Character.makeMapleReadable(chr.getName()) : "") + " caused " + this.name() + " " + reason));
} }
Server.getInstance().broadcastGMMessage((chr != null ? chr.getWorld() : 0), PacketCreator.sendYellowTip((chr != null ? Character.makeMapleReadable(chr.getName()) : "") + " caused " + this.name() + " " + reason));
}
if (YamlConfig.config.server.USE_AUTOBAN_LOG) { if (YamlConfig.config.server.USE_AUTOBAN_LOG) {
FilePrinter.print(FilePrinter.AUTOBAN_WARNING, (chr != null ? Character.makeMapleReadable(chr.getName()) : "") + " caused " + this.name() + " " + reason); FilePrinter.print(FilePrinter.AUTOBAN_WARNING, (chr != null ? Character.makeMapleReadable(chr.getName()) : "") + " caused " + this.name() + " " + reason);
} }
} }
public void autoban(Character chr, String value) { public void autoban(Character chr, String value) {
if(YamlConfig.config.server.USE_AUTOBAN == true) { if (YamlConfig.config.server.USE_AUTOBAN == true) {
chr.autoban("Autobanned for (" + this.name() + ": " + value + ")"); chr.autoban("Autobanned for (" + this.name() + ": " + value + ")");
//chr.sendPolice("You will be disconnected for (" + this.name() + ": " + value + ")"); //chr.sendPolice("You will be disconnected for (" + this.name() + ": " + value + ")");
} }
} }
} }

View File

@@ -14,19 +14,18 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
*
* @author kevintjuh93 * @author kevintjuh93
*/ */
public class AutobanManager { public class AutobanManager {
private Character chr; private final Character chr;
private Map<AutobanFactory, Integer> points = new HashMap<>(); private final Map<AutobanFactory, Integer> points = new HashMap<>();
private Map<AutobanFactory, Long> lastTime = new HashMap<>(); private final Map<AutobanFactory, Long> lastTime = new HashMap<>();
private int misses = 0; private int misses = 0;
private int lastmisses = 0; private int lastmisses = 0;
private int samemisscount = 0; private int samemisscount = 0;
private long[] spam = new long[20]; private final long[] spam = new long[20];
private int[] timestamp = new int[20]; private final int[] timestamp = new int[20];
private byte[] timestampcounter = new byte[20]; private final byte[] timestampcounter = new byte[20];
public AutobanManager(Character chr) { public AutobanManager(Character chr) {
@@ -34,23 +33,25 @@ public class AutobanManager {
} }
public void addPoint(AutobanFactory fac, String reason) { public void addPoint(AutobanFactory fac, String reason) {
if (YamlConfig.config.server.USE_AUTOBAN) { if (YamlConfig.config.server.USE_AUTOBAN) {
if (chr.isGM() || chr.isBanned()){ if (chr.isGM() || chr.isBanned()) {
return; return;
} }
if (lastTime.containsKey(fac)) { if (lastTime.containsKey(fac)) {
if (lastTime.get(fac) < (Server.getInstance().getCurrentTime() - fac.getExpire())) { if (lastTime.get(fac) < (Server.getInstance().getCurrentTime() - fac.getExpire())) {
points.put(fac, points.get(fac) / 2); //So the points are not completely gone. points.put(fac, points.get(fac) / 2); //So the points are not completely gone.
} }
} }
if (fac.getExpire() != -1) if (fac.getExpire() != -1) {
lastTime.put(fac, Server.getInstance().getCurrentTime()); lastTime.put(fac, Server.getInstance().getCurrentTime());
}
if (points.containsKey(fac)) { if (points.containsKey(fac)) {
points.put(fac, points.get(fac) + 1); points.put(fac, points.get(fac) + 1);
} else } else {
points.put(fac, 1); points.put(fac, 1);
}
if (points.get(fac) >= fac.getMaximum()) { if (points.get(fac) >= fac.getMaximum()) {
chr.autoban(reason); chr.autoban(reason);
@@ -70,20 +71,21 @@ public class AutobanManager {
if (lastmisses == misses && misses > 6) { if (lastmisses == misses && misses > 6) {
samemisscount++; samemisscount++;
} }
if (samemisscount > 4) if (samemisscount > 4) {
chr.sendPolice("You will be disconnected for miss godmode."); chr.sendPolice("You will be disconnected for miss godmode.");
//chr.autoban("Autobanned for : " + misses + " Miss godmode", 1); }
else if (samemisscount > 0) //chr.autoban("Autobanned for : " + misses + " Miss godmode", 1);
else if (samemisscount > 0) {
this.lastmisses = misses; this.lastmisses = misses;
}
this.misses = 0; this.misses = 0;
} }
//Don't use the same type for more than 1 thing //Don't use the same type for more than 1 thing
public void spam(int type) { public void spam(int type) {
this.spam[type] = Server.getInstance().getCurrentTime(); this.spam[type] = Server.getInstance().getCurrentTime();
} }
public void spam(int type, int timestamp) { public void spam(int type, int timestamp) {
this.spam[type] = timestamp; this.spam[type] = timestamp;
} }
@@ -95,7 +97,7 @@ public class AutobanManager {
/** /**
* Timestamp checker * Timestamp checker
* *
* <code>type</code>:<br> * <code>type</code>:<br>
* 1: Pet Food<br> * 1: Pet Food<br>
* 2: InventoryMerge<br> * 2: InventoryMerge<br>
* 3: InventorySort<br> * 3: InventorySort<br>
@@ -110,13 +112,13 @@ public class AutobanManager {
* @return Timestamp checker * @return Timestamp checker
*/ */
public void setTimestamp(int type, int time, int times) { public void setTimestamp(int type, int time, int times) {
if (this.timestamp[type] == time) { if (this.timestamp[type] == time) {
this.timestampcounter[type]++; this.timestampcounter[type]++;
if (this.timestampcounter[type] >= times) { if (this.timestampcounter[type] >= times) {
if (YamlConfig.config.server.USE_AUTOBAN) { if (YamlConfig.config.server.USE_AUTOBAN) {
chr.getClient().disconnect(false, false); chr.getClient().disconnect(false, false);
} }
FilePrinter.print(FilePrinter.EXPLOITS, "Player " + chr + " was caught spamming TYPE " + type + " and has been disconnected."); FilePrinter.print(FilePrinter.EXPLOITS, "Player " + chr + " was caught spamming TYPE " + type + " and has been disconnected.");
} }
} else { } else {

View File

@@ -39,7 +39,7 @@ public abstract class Command {
protected void setDescription(String description) { protected void setDescription(String description) {
this.description = description; this.description = description;
} }
public int getRank() { public int getRank() {
return rank; return rank;
} }

View File

@@ -38,29 +38,29 @@ import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
public class CommandsExecutor { public class CommandsExecutor {
public static CommandsExecutor instance = new CommandsExecutor(); public static CommandsExecutor instance = new CommandsExecutor();
public static CommandsExecutor getInstance() { public static CommandsExecutor getInstance() {
return instance; return instance;
} }
private static final char USER_HEADING = '@'; private static final char USER_HEADING = '@';
private static final char GM_HEADING = '!'; private static final char GM_HEADING = '!';
public static boolean isCommand(Client client, String content){ public static boolean isCommand(Client client, String content) {
char heading = content.charAt(0); char heading = content.charAt(0);
if (client.getPlayer().isGM()){ if (client.getPlayer().isGM()) {
return heading == USER_HEADING || heading == GM_HEADING; return heading == USER_HEADING || heading == GM_HEADING;
} }
return heading == USER_HEADING; return heading == USER_HEADING;
} }
private HashMap<String, Command> registeredCommands = new HashMap<>(); private final HashMap<String, Command> registeredCommands = new HashMap<>();
private Pair<List<String>, List<String>> levelCommandsCursor; private Pair<List<String>, List<String>> levelCommandsCursor;
private List<Pair<List<String>, List<String>>> commandsNameDesc = new ArrayList<>(); private final List<Pair<List<String>, List<String>>> commandsNameDesc = new ArrayList<>();
private CommandsExecutor(){ private CommandsExecutor() {
registerLv0Commands(); registerLv0Commands();
registerLv1Commands(); registerLv1Commands();
registerLv2Commands(); registerLv2Commands();
@@ -73,8 +73,8 @@ public class CommandsExecutor {
public List<Pair<List<String>, List<String>>> getGmCommands() { public List<Pair<List<String>, List<String>>> getGmCommands() {
return commandsNameDesc; return commandsNameDesc;
} }
public void handle(Client client, String message){ public void handle(Client client, String message) {
if (client.tryacquireClient()) { if (client.tryacquireClient()) {
try { try {
handleInternal(client, message); handleInternal(client, message);
@@ -85,8 +85,8 @@ public class CommandsExecutor {
client.getPlayer().dropMessage(5, "Try again in a while... Latest commands are currently being processed."); client.getPlayer().dropMessage(5, "Try again in a while... Latest commands are currently being processed.");
} }
} }
private void handleInternal(Client client, String message){ private void handleInternal(Client client, String message) {
if (client.getPlayer().getMapId() == 300000012) { if (client.getPlayer().getMapId() == 300000012) {
client.getPlayer().yellowMessage("You do not have permission to use commands while in jail."); client.getPlayer().yellowMessage("You do not have permission to use commands while in jail.");
return; return;
@@ -96,17 +96,17 @@ public class CommandsExecutor {
if (splitedMessage.length < 2) { if (splitedMessage.length < 2) {
splitedMessage = new String[]{splitedMessage[0], ""}; splitedMessage = new String[]{splitedMessage[0], ""};
} }
client.getPlayer().setLastCommandMessage(splitedMessage[1]); // thanks Tochi & Nulliphite for noticing string messages being marshalled lowercase client.getPlayer().setLastCommandMessage(splitedMessage[1]); // thanks Tochi & Nulliphite for noticing string messages being marshalled lowercase
final String commandName = splitedMessage[0].toLowerCase(); final String commandName = splitedMessage[0].toLowerCase();
final String[] lowercaseParams = splitedMessage[1].toLowerCase().split(splitRegex); final String[] lowercaseParams = splitedMessage[1].toLowerCase().split(splitRegex);
final Command command = registeredCommands.get(commandName); final Command command = registeredCommands.get(commandName);
if (command == null){ if (command == null) {
client.getPlayer().yellowMessage("Command '" + commandName + "' is not available. See @commands for a list of available commands."); client.getPlayer().yellowMessage("Command '" + commandName + "' is not available. See @commands for a list of available commands.");
return; return;
} }
if (client.getPlayer().gmLevel() < command.getRank()){ if (client.getPlayer().gmLevel() < command.getRank()) {
client.getPlayer().yellowMessage("You do not have permission to use this command."); client.getPlayer().yellowMessage("You do not have permission to use this command.");
return; return;
} }
@@ -116,12 +116,12 @@ public class CommandsExecutor {
} else { } else {
params = new String[]{}; params = new String[]{};
} }
command.execute(client, params); command.execute(client, params);
writeLog(client, message); writeLog(client, message);
} }
private void writeLog(Client client, String command){ private void writeLog(Client client, String command) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm"); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm");
FilePrinter.print(FilePrinter.USED_COMMANDS, client.getPlayer().getName() + " used: " + command + " on " FilePrinter.print(FilePrinter.USED_COMMANDS, client.getPlayer().getName() + " used: " + command + " on "
+ sdf.format(Calendar.getInstance().getTime())); + sdf.format(Calendar.getInstance().getTime()));
@@ -131,41 +131,42 @@ public class CommandsExecutor {
try { try {
levelCommandsCursor.getRight().add(commandClass.newInstance().getDescription()); levelCommandsCursor.getRight().add(commandClass.newInstance().getDescription());
levelCommandsCursor.getLeft().add(name); levelCommandsCursor.getLeft().add(name);
} catch(Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private void addCommand(String[] syntaxs, Class<? extends Command> commandClass){ private void addCommand(String[] syntaxs, Class<? extends Command> commandClass) {
for (String syntax : syntaxs){ for (String syntax : syntaxs) {
addCommand(syntax, 0, commandClass); addCommand(syntax, 0, commandClass);
} }
} }
private void addCommand(String syntax, Class<? extends Command> commandClass){
private void addCommand(String syntax, Class<? extends Command> commandClass) {
//for (String syntax : syntaxs){ //for (String syntax : syntaxs){
addCommand(syntax, 0, commandClass); addCommand(syntax, 0, commandClass);
//} //}
} }
private void addCommand(String[] surtaxes, int rank, Class<? extends Command> commandClass){ private void addCommand(String[] surtaxes, int rank, Class<? extends Command> commandClass) {
for (String syntax : surtaxes){ for (String syntax : surtaxes) {
addCommand(syntax, rank, commandClass); addCommand(syntax, rank, commandClass);
} }
} }
private void addCommand(String syntax, int rank, Class<? extends Command> commandClass){ private void addCommand(String syntax, int rank, Class<? extends Command> commandClass) {
if (registeredCommands.containsKey(syntax.toLowerCase())){ if (registeredCommands.containsKey(syntax.toLowerCase())) {
System.out.println("Error on register command with name: " + syntax + ". Already exists."); System.out.println("Error on register command with name: " + syntax + ". Already exists.");
return; return;
} }
String commandName = syntax.toLowerCase(); String commandName = syntax.toLowerCase();
addCommandInfo(commandName, commandClass); addCommandInfo(commandName, commandClass);
try { try {
Command commandInstance = commandClass.newInstance(); // thanks Halcyon for noticing commands getting reinstanced every call Command commandInstance = commandClass.newInstance(); // thanks Halcyon for noticing commands getting reinstanced every call
commandInstance.setRank(rank); commandInstance.setRank(rank);
registeredCommands.put(commandName, commandInstance); registeredCommands.put(commandName, commandInstance);
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
@@ -174,9 +175,9 @@ public class CommandsExecutor {
} }
} }
private void registerLv0Commands(){ private void registerLv0Commands() {
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>());
addCommand(new String[]{"help", "commands"}, HelpCommand.class); addCommand(new String[]{"help", "commands"}, HelpCommand.class);
addCommand("droplimit", DropLimitCommand.class); addCommand("droplimit", DropLimitCommand.class);
addCommand("time", TimeCommand.class); addCommand("time", TimeCommand.class);
@@ -186,7 +187,7 @@ public class CommandsExecutor {
addCommand("gacha", GachaCommand.class); addCommand("gacha", GachaCommand.class);
addCommand("dispose", DisposeCommand.class); addCommand("dispose", DisposeCommand.class);
addCommand("changel", ChangeLanguageCommand.class); addCommand("changel", ChangeLanguageCommand.class);
addCommand("equiplv", EquipLvCommand.class); addCommand("equiplv", EquipLvCommand.class);
addCommand("showrates", ShowRatesCommand.class); addCommand("showrates", ShowRatesCommand.class);
addCommand("rates", RatesCommand.class); addCommand("rates", RatesCommand.class);
addCommand("online", OnlineCommand.class); addCommand("online", OnlineCommand.class);
@@ -205,26 +206,26 @@ public class CommandsExecutor {
addCommand("mylawn", MapOwnerClaimCommand.class); addCommand("mylawn", MapOwnerClaimCommand.class);
addCommand("bosshp", BossHpCommand.class); addCommand("bosshp", BossHpCommand.class);
addCommand("mobhp", MobHpCommand.class); addCommand("mobhp", MobHpCommand.class);
commandsNameDesc.add(levelCommandsCursor); commandsNameDesc.add(levelCommandsCursor);
} }
private void registerLv1Commands() { private void registerLv1Commands() {
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>());
addCommand("whatdropsfrom", 1, WhatDropsFromCommand.class); addCommand("whatdropsfrom", 1, WhatDropsFromCommand.class);
addCommand("whodrops", 1, WhoDropsCommand.class); addCommand("whodrops", 1, WhoDropsCommand.class);
addCommand("buffme", 1, BuffMeCommand.class); addCommand("buffme", 1, BuffMeCommand.class);
addCommand("goto", 1, GotoCommand.class); addCommand("goto", 1, GotoCommand.class);
commandsNameDesc.add(levelCommandsCursor); commandsNameDesc.add(levelCommandsCursor);
} }
private void registerLv2Commands(){ private void registerLv2Commands() {
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>());
addCommand("recharge", 2, RechargeCommand.class); addCommand("recharge", 2, RechargeCommand.class);
addCommand("whereami", 2, WhereaMiCommand.class); addCommand("whereami", 2, WhereaMiCommand.class);
addCommand("hide", 2, HideCommand.class); addCommand("hide", 2, HideCommand.class);
@@ -261,13 +262,13 @@ public class CommandsExecutor {
addCommand("id", 2, IdCommand.class); addCommand("id", 2, IdCommand.class);
addCommand("gachalist", GachaListCommand.class); addCommand("gachalist", GachaListCommand.class);
addCommand("loot", LootCommand.class); addCommand("loot", LootCommand.class);
commandsNameDesc.add(levelCommandsCursor); commandsNameDesc.add(levelCommandsCursor);
} }
private void registerLv3Commands() { private void registerLv3Commands() {
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>());
addCommand("debuff", 3, DebuffCommand.class); addCommand("debuff", 3, DebuffCommand.class);
addCommand("fly", 3, FlyCommand.class); addCommand("fly", 3, FlyCommand.class);
addCommand("spawn", 3, SpawnCommand.class); addCommand("spawn", 3, SpawnCommand.class);
@@ -331,9 +332,9 @@ public class CommandsExecutor {
commandsNameDesc.add(levelCommandsCursor); commandsNameDesc.add(levelCommandsCursor);
} }
private void registerLv4Commands(){ private void registerLv4Commands() {
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>());
addCommand("servermessage", 4, ServerMessageCommand.class); addCommand("servermessage", 4, ServerMessageCommand.class);
addCommand("proitem", 4, ProItemCommand.class); addCommand("proitem", 4, ProItemCommand.class);
addCommand("seteqstat", 4, SetEqStatCommand.class); addCommand("seteqstat", 4, SetEqStatCommand.class);
@@ -358,26 +359,26 @@ public class CommandsExecutor {
addCommand("pnpcremove", 4, PnpcRemoveCommand.class); addCommand("pnpcremove", 4, PnpcRemoveCommand.class);
addCommand("pmob", 4, PmobCommand.class); addCommand("pmob", 4, PmobCommand.class);
addCommand("pmobremove", 4, PmobRemoveCommand.class); addCommand("pmobremove", 4, PmobRemoveCommand.class);
commandsNameDesc.add(levelCommandsCursor); commandsNameDesc.add(levelCommandsCursor);
} }
private void registerLv5Commands(){ private void registerLv5Commands() {
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>());
addCommand("debug", 5, DebugCommand.class); addCommand("debug", 5, DebugCommand.class);
addCommand("set", 5, SetCommand.class); addCommand("set", 5, SetCommand.class);
addCommand("showpackets", 5, ShowPacketsCommand.class); addCommand("showpackets", 5, ShowPacketsCommand.class);
addCommand("showmovelife", 5, ShowMoveLifeCommand.class); addCommand("showmovelife", 5, ShowMoveLifeCommand.class);
addCommand("showsessions", 5, ShowSessionsCommand.class); addCommand("showsessions", 5, ShowSessionsCommand.class);
addCommand("iplist", 5, IpListCommand.class); addCommand("iplist", 5, IpListCommand.class);
commandsNameDesc.add(levelCommandsCursor); commandsNameDesc.add(levelCommandsCursor);
} }
private void registerLv6Commands(){ private void registerLv6Commands() {
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>());
addCommand("setgmlevel", 6, SetGmLevelCommand.class); addCommand("setgmlevel", 6, SetGmLevelCommand.class);
addCommand("warpworld", 6, WarpWorldCommand.class); addCommand("warpworld", 6, WarpWorldCommand.class);
addCommand("saveall", 6, SaveAllCommand.class); addCommand("saveall", 6, SaveAllCommand.class);
@@ -394,7 +395,7 @@ public class CommandsExecutor {
addCommand("addworld", 6, ServerAddWorldCommand.class); addCommand("addworld", 6, ServerAddWorldCommand.class);
addCommand("removechannel", 6, ServerRemoveChannelCommand.class); addCommand("removechannel", 6, ServerRemoveChannelCommand.class);
addCommand("removeworld", 6, ServerRemoveWorldCommand.class); addCommand("removeworld", 6, ServerRemoveWorldCommand.class);
commandsNameDesc.add(levelCommandsCursor); commandsNameDesc.add(levelCommandsCursor);
} }

View File

@@ -31,14 +31,14 @@ public class BuyBackCommand extends Command {
{ {
setDescription("Revive yourself after a death."); setDescription("Revive yourself after a death.");
} }
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
if (params.length < 1) { if (params.length < 1) {
c.getPlayer().yellowMessage("Syntax: @buyback <info|now>"); c.getPlayer().yellowMessage("Syntax: @buyback <info|now>");
return; return;
} }
if (params[0].contentEquals("now")) { if (params[0].contentEquals("now")) {
BuybackProcessor.processBuyback(c); BuybackProcessor.processBuyback(c);
} else { } else {

View File

@@ -33,7 +33,7 @@ public class DisposeCommand extends Command {
{ {
setDescription("Dispose to fix NPC chat."); setDescription("Dispose to fix NPC chat.");
} }
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
NPCScriptManager.getInstance().dispose(c); NPCScriptManager.getInstance().dispose(c);

View File

@@ -31,11 +31,11 @@ public class DropLimitCommand extends Command {
{ {
setDescription("Check drop limit of current map."); setDescription("Check drop limit of current map.");
} }
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
int dropCount = c.getPlayer().getMap().getDroppedItemCount(); int dropCount = c.getPlayer().getMap().getDroppedItemCount();
if(((float) dropCount) / YamlConfig.config.server.ITEM_LIMIT_ON_MAP < 0.75f) { if (((float) dropCount) / YamlConfig.config.server.ITEM_LIMIT_ON_MAP < 0.75f) {
c.getPlayer().showHint("Current drop count: #b" + dropCount + "#k / #e" + YamlConfig.config.server.ITEM_LIMIT_ON_MAP + "#n", 300); c.getPlayer().showHint("Current drop count: #b" + dropCount + "#k / #e" + YamlConfig.config.server.ITEM_LIMIT_ON_MAP + "#n", 300);
} else { } else {
c.getPlayer().showHint("Current drop count: #r" + dropCount + "#k / #e" + YamlConfig.config.server.ITEM_LIMIT_ON_MAP + "#n", 300); c.getPlayer().showHint("Current drop count: #r" + dropCount + "#k / #e" + YamlConfig.config.server.ITEM_LIMIT_ON_MAP + "#n", 300);

View File

@@ -38,29 +38,29 @@ public class GachaCommand extends Command {
Gachapon.GachaponType gacha = null; Gachapon.GachaponType gacha = null;
String search = c.getPlayer().getLastCommandMessage(); String search = c.getPlayer().getLastCommandMessage();
String gachaName = ""; String gachaName = "";
String [] names = {"Henesys", "Ellinia", "Perion", "Kerning City", "Sleepywood", "Mushroom Shrine", "Showa Spa Male", "Showa Spa Female", "New Leaf City", "Nautilus Harbor"}; 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}; int[] ids = {9100100, 9100101, 9100102, 9100103, 9100104, 9100105, 9100106, 9100107, 9100109, 9100117};
for (int i = 0; i < names.length; i++){ for (int i = 0; i < names.length; i++) {
if (search.equalsIgnoreCase(names[i])){ if (search.equalsIgnoreCase(names[i])) {
gachaName = names[i]; gachaName = names[i];
gacha = Gachapon.GachaponType.getByNpcId(ids[i]); gacha = Gachapon.GachaponType.getByNpcId(ids[i]);
} }
} }
if (gacha == null){ if (gacha == null) {
c.getPlayer().yellowMessage("Please use @gacha <name> where name corresponds to one of the below:"); c.getPlayer().yellowMessage("Please use @gacha <name> where name corresponds to one of the below:");
for (String name : names){ for (String name : names) {
c.getPlayer().yellowMessage(name); c.getPlayer().yellowMessage(name);
} }
return; return;
} }
String talkStr = "The #b" + gachaName + "#k Gachapon contains the following items.\r\n\r\n"; String talkStr = "The #b" + gachaName + "#k Gachapon contains the following items.\r\n\r\n";
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++) {
for (int id : gacha.getItems(i)){ for (int id : gacha.getItems(i)) {
talkStr += "-" + ItemInformationProvider.getInstance().getName(id) + "\r\n"; talkStr += "-" + ItemInformationProvider.getInstance().getName(id) + "\r\n";
} }
} }
talkStr += "\r\nPlease keep in mind that there are items that are in all gachapons and are not listed here."; talkStr += "\r\nPlease keep in mind that there are items that are in all gachapons and are not listed here.";
c.getAbstractPlayerInteraction().npcTalk(9010000, talkStr); c.getAbstractPlayerInteraction().npcTalk(9010000, talkStr);
} }
} }

View File

@@ -37,15 +37,16 @@ public class JoinEventCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if(!FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) { if (!FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) {
Event event = c.getChannelServer().getEvent(); Event event = c.getChannelServer().getEvent();
if(event != null) { if (event != null) {
if(event.getMapId() != player.getMapId()) { if (event.getMapId() != player.getMapId()) {
if(event.getLimit() > 0) { if (event.getLimit() > 0) {
player.saveLocation("EVENT"); player.saveLocation("EVENT");
if(event.getMapId() == 109080000 || event.getMapId() == 109060001) if (event.getMapId() == 109080000 || event.getMapId() == 109060001) {
player.setTeam(event.getLimit() % 2); player.setTeam(event.getLimit() % 2);
}
event.minusLimit(); event.minusLimit();

View File

@@ -36,19 +36,19 @@ public class LeaveEventCommand extends Command {
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
int returnMap = player.getSavedLocation("EVENT"); int returnMap = player.getSavedLocation("EVENT");
if(returnMap != -1) { if (returnMap != -1) {
if(player.getOla() != null) { if (player.getOla() != null) {
player.getOla().resetTimes(); player.getOla().resetTimes();
player.setOla(null); player.setOla(null);
} }
if(player.getFitness() != null) { if (player.getFitness() != null) {
player.getFitness().resetTimes(); player.getFitness().resetTimes();
player.setFitness(null); player.setFitness(null);
} }
player.saveLocationOnWarp(); player.saveLocationOnWarp();
player.changeMap(returnMap); player.changeMap(returnMap);
if(c.getChannelServer().getEvent() != null) { if (c.getChannelServer().getEvent() != null) {
c.getChannelServer().getEvent().addLimit(); c.getChannelServer().getEvent().addLimit();
} }
} else { } else {

View File

@@ -39,7 +39,7 @@ public class MapOwnerClaimCommand extends Command {
if (c.tryacquireClient()) { if (c.tryacquireClient()) {
try { try {
Character chr = c.getPlayer(); Character chr = c.getPlayer();
if (YamlConfig.config.server.USE_MAP_OWNERSHIP_SYSTEM) { if (YamlConfig.config.server.USE_MAP_OWNERSHIP_SYSTEM) {
if (chr.getEventInstance() == null) { if (chr.getEventInstance() == null) {
MapleMap map = chr.getMap(); MapleMap map = chr.getMap();

View File

@@ -40,7 +40,7 @@ public class RanksCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
List<Pair<String, Integer>> worldRanking = Server.getInstance().getWorldPlayerRanking(player.getWorld()); List<Pair<String, Integer>> worldRanking = Server.getInstance().getWorldPlayerRanking(player.getWorld());
player.sendPacket(GuildPackets.showPlayerRanks(9010000, worldRanking)); player.sendPacket(GuildPackets.showPlayerRanks(9010000, worldRanking));
} }

View File

@@ -36,14 +36,16 @@ public class RatesCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
// travel rates not applicable since it's intrinsically a server/environment rate rather than a character rate // travel rates not applicable since it's intrinsically a server/environment rate rather than a character rate
String showMsg_ = "#eCHARACTER RATES#n" + "\r\n\r\n"; String showMsg_ = "#eCHARACTER RATES#n" + "\r\n\r\n";
showMsg_ += "EXP Rate: #e#b" + player.getExpRate() + "x#k#n" + (player.hasNoviceExpRate() ? " - novice rate" : "") + "\r\n"; showMsg_ += "EXP Rate: #e#b" + player.getExpRate() + "x#k#n" + (player.hasNoviceExpRate() ? " - novice rate" : "") + "\r\n";
showMsg_ += "MESO Rate: #e#b" + player.getMesoRate() + "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"; showMsg_ += "DROP Rate: #e#b" + player.getDropRate() + "x#k#n" + "\r\n";
showMsg_ += "BOSS DROP Rate: #e#b" + player.getBossDropRate() + "x#k#n" + "\r\n"; showMsg_ += "BOSS DROP Rate: #e#b" + player.getBossDropRate() + "x#k#n" + "\r\n";
if(YamlConfig.config.server.USE_QUEST_RATE) showMsg_ += "QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n"; if (YamlConfig.config.server.USE_QUEST_RATE) {
showMsg_ += "QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n";
}
player.showHint(showMsg_, 300); player.showHint(showMsg_, 300);
} }

View File

@@ -39,32 +39,40 @@ public class ShowRatesCommand extends Command {
String showMsg = "#eEXP RATE#n" + "\r\n"; String showMsg = "#eEXP RATE#n" + "\r\n";
showMsg += "World EXP Rate: #k" + c.getWorldServer().getExpRate() + "x#k" + "\r\n"; showMsg += "World EXP Rate: #k" + c.getWorldServer().getExpRate() + "x#k" + "\r\n";
showMsg += "Player EXP Rate: #k" + player.getRawExpRate() + "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"; 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" + (player.hasNoviceExpRate() ? " - novice rate" : "") + "\r\n"; showMsg += "EXP Rate: #e#b" + player.getExpRate() + "x#k#n" + (player.hasNoviceExpRate() ? " - novice rate" : "") + "\r\n";
showMsg += "\r\n" + "#eMESO RATE#n" + "\r\n"; showMsg += "\r\n" + "#eMESO RATE#n" + "\r\n";
showMsg += "World MESO Rate: #k" + c.getWorldServer().getMesoRate() + "x#k" + "\r\n"; showMsg += "World MESO Rate: #k" + c.getWorldServer().getMesoRate() + "x#k" + "\r\n";
showMsg += "Player MESO Rate: #k" + player.getRawMesoRate() + "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"; 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 += "MESO Rate: #e#b" + player.getMesoRate() + "x#k#n" + "\r\n";
showMsg += "\r\n" + "#eDROP RATE#n" + "\r\n"; showMsg += "\r\n" + "#eDROP RATE#n" + "\r\n";
showMsg += "World DROP Rate: #k" + c.getWorldServer().getDropRate() + "x#k" + "\r\n"; showMsg += "World DROP Rate: #k" + c.getWorldServer().getDropRate() + "x#k" + "\r\n";
showMsg += "Player DROP Rate: #k" + player.getRawDropRate() + "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"; 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"; showMsg += "DROP Rate: #e#b" + player.getDropRate() + "x#k#n" + "\r\n";
showMsg += "\r\n" + "#eBOSS DROP RATE#n" + "\r\n"; showMsg += "\r\n" + "#eBOSS DROP RATE#n" + "\r\n";
showMsg += "World BOSS DROP Rate: #k" + c.getWorldServer().getBossDropRate() + "x#k" + "\r\n"; showMsg += "World BOSS DROP Rate: #k" + c.getWorldServer().getBossDropRate() + "x#k" + "\r\n";
showMsg += "Player DROP Rate: #k" + player.getRawDropRate() + "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"; if (player.getCouponDropRate() != 1) {
showMsg += "Coupon DROP Rate: #k" + player.getCouponDropRate() + "x#k" + "\r\n";
}
showMsg += "BOSS DROP Rate: #e#b" + player.getBossDropRate() + "x#k#n" + "\r\n"; showMsg += "BOSS DROP Rate: #e#b" + player.getBossDropRate() + "x#k#n" + "\r\n";
if(YamlConfig.config.server.USE_QUEST_RATE) { if (YamlConfig.config.server.USE_QUEST_RATE) {
showMsg += "\r\n" + "#eQUEST RATE#n" + "\r\n"; showMsg += "\r\n" + "#eQUEST RATE#n" + "\r\n";
showMsg += "World QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n"; showMsg += "World QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n";
} }
showMsg += "\r\n"; showMsg += "\r\n";
showMsg += "World TRAVEL Rate: #e#b" + c.getWorldServer().getTravelRate() + "x#k#n" + "\r\n"; showMsg += "World TRAVEL Rate: #e#b" + c.getWorldServer().getTravelRate() + "x#k#n" + "\r\n";

View File

@@ -48,7 +48,7 @@ public class StatStrCommand extends Command {
} else { } else {
amount = Math.min(remainingAp, YamlConfig.config.server.MAX_AP - player.getStr()); amount = Math.min(remainingAp, YamlConfig.config.server.MAX_AP - player.getStr());
} }
if (!player.assignStr(Math.max(amount, 0))) { if (!player.assignStr(Math.max(amount, 0))) {
player.dropMessage("Please make sure your AP is not over " + YamlConfig.config.server.MAX_AP + " and you have enough to distribute."); player.dropMessage("Please make sure your AP is not over " + YamlConfig.config.server.MAX_AP + " and you have enough to distribute.");
} }

View File

@@ -35,7 +35,7 @@ public class TimeCommand extends Command {
{ {
setDescription("Show current server time."); setDescription("Show current server time.");
} }
@Override @Override
public void execute(Client client, String[] params) { public void execute(Client client, String[] params) {
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

View File

@@ -35,10 +35,10 @@ public class UptimeCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
long milliseconds = System.currentTimeMillis() - Server.uptime; long milliseconds = System.currentTimeMillis() - Server.uptime;
int seconds = (int) (milliseconds / 1000) % 60 ; int seconds = (int) (milliseconds / 1000) % 60;
int minutes = (int) ((milliseconds / (1000*60)) % 60); int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
int hours = (int) ((milliseconds / (1000*60*60)) % 24); int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
int days = (int) ((milliseconds / (1000*60*60*24))); int days = (int) ((milliseconds / (1000 * 60 * 60 * 24)));
c.getPlayer().yellowMessage("Server has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds."); c.getPlayer().yellowMessage("Server has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds.");
} }
} }

View File

@@ -36,11 +36,11 @@ public class BossHpCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
for(Monster monster : player.getMap().getAllMonsters()) { for (Monster monster : player.getMap().getAllMonsters()) {
if(monster != null && monster.isBoss() && monster.getHp() > 0) { if (monster != null && monster.isBoss() && monster.getHp() > 0) {
long percent = monster.getHp() * 100L / monster.getMaxHp(); long percent = monster.getHp() * 100L / monster.getMaxHp();
String bar = "["; String bar = "[";
for (int i = 0; i < 100; i++){ for (int i = 0; i < 100; i++) {
bar += i < percent ? "|" : "."; bar += i < percent ? "|" : ".";
} }
bar += "]"; bar += "]";

View File

@@ -36,16 +36,16 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class GotoCommand extends Command { public class GotoCommand extends Command {
{ {
setDescription("Warp to a predefined map."); setDescription("Warp to a predefined map.");
List<Entry<String, Integer>> towns = new ArrayList<>(GameConstants.GOTO_TOWNS.entrySet()); List<Entry<String, Integer>> towns = new ArrayList<>(GameConstants.GOTO_TOWNS.entrySet());
sortGotoEntries(towns); sortGotoEntries(towns);
try { try {
// thanks shavit for noticing goto areas getting loaded from wz needlessly only for the name retrieval // thanks shavit for noticing goto areas getting loaded from wz needlessly only for the name retrieval
for (Map.Entry<String, Integer> e : towns) { for (Map.Entry<String, Integer> e : towns) {
GOTO_TOWNS_INFO += ("'" + e.getKey() + "' - #b" + (MapFactory.loadPlaceName(e.getValue())) + "#k\r\n"); GOTO_TOWNS_INFO += ("'" + e.getKey() + "' - #b" + (MapFactory.loadPlaceName(e.getValue())) + "#k\r\n");
} }
@@ -57,16 +57,16 @@ public class GotoCommand extends Command {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
GOTO_TOWNS_INFO = "(none)"; GOTO_TOWNS_INFO = "(none)";
GOTO_AREAS_INFO = "(none)"; GOTO_AREAS_INFO = "(none)";
} }
} }
public static String GOTO_TOWNS_INFO = ""; public static String GOTO_TOWNS_INFO = "";
public static String GOTO_AREAS_INFO = ""; public static String GOTO_AREAS_INFO = "";
private static void sortGotoEntries(List<Entry<String, Integer>> listEntries) { private static void sortGotoEntries(List<Entry<String, Integer>> listEntries) {
listEntries.sort((e1, e2) -> e1.getValue().compareTo(e2.getValue())); listEntries.sort((e1, e2) -> e1.getValue().compareTo(e2.getValue()));
} }
@@ -74,16 +74,16 @@ public class GotoCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1){ if (params.length < 1) {
String sendStr = "Syntax: #b@goto <map name>#k. Available areas:\r\n\r\n#rTowns:#k\r\n" + GOTO_TOWNS_INFO; String sendStr = "Syntax: #b@goto <map name>#k. Available areas:\r\n\r\n#rTowns:#k\r\n" + GOTO_TOWNS_INFO;
if (player.isGM()) { if (player.isGM()) {
sendStr += ("\r\n#rAreas:#k\r\n" + GOTO_AREAS_INFO); sendStr += ("\r\n#rAreas:#k\r\n" + GOTO_AREAS_INFO);
} }
player.getAbstractPlayerInteraction().npcTalk(9000020, sendStr); player.getAbstractPlayerInteraction().npcTalk(9000020, sendStr);
return; return;
} }
if (!player.isAlive()) { if (!player.isAlive()) {
player.dropMessage(1, "This command cannot be used when you're dead."); player.dropMessage(1, "This command cannot be used when you're dead.");
return; return;
@@ -103,10 +103,10 @@ public class GotoCommand extends Command {
} else { } else {
gotomaps = GameConstants.GOTO_TOWNS; gotomaps = GameConstants.GOTO_TOWNS;
} }
if (gotomaps.containsKey(params[0])) { if (gotomaps.containsKey(params[0])) {
MapleMap target = c.getChannelServer().getMapFactory().getMap(gotomaps.get(params[0])); MapleMap target = c.getChannelServer().getMapFactory().getMap(gotomaps.get(params[0]));
// expedition issue with this command detected thanks to Masterrulax // expedition issue with this command detected thanks to Masterrulax
Portal targetPortal = target.getRandomPlayerSpawnpoint(); Portal targetPortal = target.getRandomPlayerSpawnpoint();
player.saveLocationOnWarp(); player.saveLocationOnWarp();
@@ -117,7 +117,7 @@ public class GotoCommand extends Command {
if (player.isGM()) { if (player.isGM()) {
sendStr += ("\r\n#rAreas:#k\r\n" + GOTO_AREAS_INFO); sendStr += ("\r\n#rAreas:#k\r\n" + GOTO_AREAS_INFO);
} }
player.getAbstractPlayerInteraction().npcTalk(9000020, sendStr); player.getAbstractPlayerInteraction().npcTalk(9000020, sendStr);
} }
} }

View File

@@ -36,7 +36,7 @@ public class MobHpCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
for(Monster monster : player.getMap().getAllMonsters()) { for (Monster monster : player.getMap().getAllMonsters()) {
if (monster != null && monster.getHp() > 0) { if (monster != null && monster.getHp() > 0) {
player.yellowMessage(monster.getName() + " (" + monster.getId() + ") has " + monster.getHp() + " / " + monster.getMaxHp() + " HP."); player.yellowMessage(monster.getName() + " (" + monster.getId() + ") has " + monster.getHp() + " / " + monster.getMaxHp() + " HP.");

View File

@@ -50,20 +50,20 @@ public class WhatDropsFromCommand extends Command {
int limit = 3; int limit = 3;
Iterator<Pair<Integer, String>> listIterator = MonsterInformationProvider.getMobsIDsFromName(monsterName).iterator(); Iterator<Pair<Integer, String>> listIterator = MonsterInformationProvider.getMobsIDsFromName(monsterName).iterator();
for (int i = 0; i < limit; i++) { for (int i = 0; i < limit; i++) {
if(listIterator.hasNext()) { if (listIterator.hasNext()) {
Pair<Integer, String> data = listIterator.next(); Pair<Integer, String> data = listIterator.next();
int mobId = data.getLeft(); int mobId = data.getLeft();
String mobName = data.getRight(); String mobName = data.getRight();
output += mobName + " drops the following items:\r\n\r\n"; output += mobName + " drops the following items:\r\n\r\n";
for (MonsterDropEntry drop : MonsterInformationProvider.getInstance().retrieveDrop(mobId)){ for (MonsterDropEntry drop : MonsterInformationProvider.getInstance().retrieveDrop(mobId)) {
try { try {
String name = ItemInformationProvider.getInstance().getName(drop.itemId); String name = ItemInformationProvider.getInstance().getName(drop.itemId);
if (name == null || name.equals("null") || drop.chance == 0){ if (name == null || name.equals("null") || drop.chance == 0) {
continue; continue;
} }
float chance = Math.max(1000000 / drop.chance / (!MonsterInformationProvider.getInstance().isBoss(mobId) ? player.getDropRate() : player.getBossDropRate()), 1); float chance = Math.max(1000000 / drop.chance / (!MonsterInformationProvider.getInstance().isBoss(mobId) ? player.getDropRate() : player.getBossDropRate()), 1);
output += "- " + name + " (1/" + (int) chance + ")\r\n"; output += "- " + name + " (1/" + (int) chance + ")\r\n";
} catch (Exception ex){ } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
continue; continue;
} }
@@ -71,7 +71,7 @@ public class WhatDropsFromCommand extends Command {
output += "\r\n"; output += "\r\n";
} }
} }
c.getAbstractPlayerInteraction().npcTalk(9010000, output); c.getAbstractPlayerInteraction().npcTalk(9010000, output);
} }
} }

View File

@@ -43,16 +43,22 @@ public class ApCommand extends Command {
if (params.length < 2) { if (params.length < 2) {
int newAp = Integer.parseInt(params[0]); int newAp = Integer.parseInt(params[0]);
if (newAp < 0) newAp = 0; if (newAp < 0) {
else if (newAp > YamlConfig.config.server.MAX_AP) newAp = YamlConfig.config.server.MAX_AP; newAp = 0;
} else if (newAp > YamlConfig.config.server.MAX_AP) {
newAp = YamlConfig.config.server.MAX_AP;
}
player.changeRemainingAp(newAp, false); player.changeRemainingAp(newAp, false);
} else { } else {
Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]);
if (victim != null) { if (victim != null) {
int newAp = Integer.parseInt(params[1]); int newAp = Integer.parseInt(params[1]);
if (newAp < 0) newAp = 0; if (newAp < 0) {
else if (newAp > YamlConfig.config.server.MAX_AP) newAp = YamlConfig.config.server.MAX_AP; newAp = 0;
} else if (newAp > YamlConfig.config.server.MAX_AP) {
newAp = YamlConfig.config.server.MAX_AP;
}
victim.changeRemainingAp(newAp, false); victim.changeRemainingAp(newAp, false);
} else { } else {

View File

@@ -44,6 +44,8 @@ public class BuffCommand extends Command {
int skillid = Integer.parseInt(params[0]); int skillid = Integer.parseInt(params[0]);
Skill skill = SkillFactory.getSkill(skillid); Skill skill = SkillFactory.getSkill(skillid);
if (skill != null) skill.getEffect(skill.getMaxLevel()).applyTo(player); if (skill != null) {
skill.getEffect(skill.getMaxLevel()).applyTo(player);
}
} }
} }

View File

@@ -36,7 +36,7 @@ public class ClearSavedLocationsCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(), victim; Character player = c.getPlayer(), victim;
if (params.length > 0) { if (params.length > 0) {
victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]);
if (victim == null) { if (victim == null) {
@@ -46,11 +46,11 @@ public class ClearSavedLocationsCommand extends Command {
} else { } else {
victim = c.getPlayer(); victim = c.getPlayer();
} }
for (SavedLocationType type : SavedLocationType.values()) { for (SavedLocationType type : SavedLocationType.values()) {
victim.clearSavedLocation(type); victim.clearSavedLocation(type);
} }
player.message("Cleared " + params[0] + "'s saved locations."); player.message("Cleared " + params[0] + "'s saved locations.");
} }
} }

View File

@@ -47,32 +47,37 @@ public class ClearSlotCommand extends Command {
case "all": case "all":
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.EQUIP).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.EQUIP).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.EQUIP, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.EQUIP, (byte) i, tempItem.getQuantity(), false, false);
} }
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.USE).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.USE).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.USE, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.USE, (byte) i, tempItem.getQuantity(), false, false);
} }
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.ETC).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.ETC).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.ETC, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.ETC, (byte) i, tempItem.getQuantity(), false, false);
} }
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.SETUP).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.SETUP).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.SETUP, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.SETUP, (byte) i, tempItem.getQuantity(), false, false);
} }
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.CASH).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.CASH).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.CASH, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.CASH, (byte) i, tempItem.getQuantity(), false, false);
} }
player.yellowMessage("All Slots Cleared."); player.yellowMessage("All Slots Cleared.");
@@ -80,8 +85,9 @@ public class ClearSlotCommand extends Command {
case "equip": case "equip":
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.EQUIP).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.EQUIP).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.EQUIP, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.EQUIP, (byte) i, tempItem.getQuantity(), false, false);
} }
player.yellowMessage("Equipment Slot Cleared."); player.yellowMessage("Equipment Slot Cleared.");
@@ -89,8 +95,9 @@ public class ClearSlotCommand extends Command {
case "use": case "use":
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.USE).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.USE).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.USE, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.USE, (byte) i, tempItem.getQuantity(), false, false);
} }
player.yellowMessage("Use Slot Cleared."); player.yellowMessage("Use Slot Cleared.");
@@ -98,8 +105,9 @@ public class ClearSlotCommand extends Command {
case "setup": case "setup":
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.SETUP).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.SETUP).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.SETUP, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.SETUP, (byte) i, tempItem.getQuantity(), false, false);
} }
player.yellowMessage("Set-Up Slot Cleared."); player.yellowMessage("Set-Up Slot Cleared.");
@@ -107,8 +115,9 @@ public class ClearSlotCommand extends Command {
case "etc": case "etc":
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.ETC).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.ETC).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.ETC, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.ETC, (byte) i, tempItem.getQuantity(), false, false);
} }
player.yellowMessage("ETC Slot Cleared."); player.yellowMessage("ETC Slot Cleared.");
@@ -116,8 +125,9 @@ public class ClearSlotCommand extends Command {
case "cash": case "cash":
for (int i = 0; i < 101; i++) { for (int i = 0; i < 101; i++) {
Item tempItem = c.getPlayer().getInventory(InventoryType.CASH).getItem((byte) i); Item tempItem = c.getPlayer().getInventory(InventoryType.CASH).getItem((byte) i);
if (tempItem == null) if (tempItem == null) {
continue; continue;
}
InventoryManipulator.removeFromSlot(c, InventoryType.CASH, (byte) i, tempItem.getQuantity(), false, false); InventoryManipulator.removeFromSlot(c, InventoryType.CASH, (byte) i, tempItem.getQuantity(), false, false);
} }
player.yellowMessage("Cash Slot Cleared."); player.yellowMessage("Cash Slot Cleared.");

View File

@@ -23,7 +23,6 @@ import client.Client;
import client.command.Command; import client.command.Command;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class GachaListCommand extends Command { public class GachaListCommand extends Command {

View File

@@ -47,7 +47,7 @@ public class IdCommand extends Command {
if (resultList.size() > 0) { if (resultList.size() > 0) {
int count = 0; int count = 0;
for (Map.Entry<String, String> entry: resultList.entrySet()) { for (Map.Entry<String, String> entry : resultList.entrySet()) {
sb.append(String.format("Id for %s is: #b%s#k", entry.getKey(), entry.getValue()) + "\r\n"); sb.append(String.format("Id for %s is: #b%s#k", entry.getKey(), entry.getValue()) + "\r\n");
if (++count > 100) { if (++count > 100) {
break; break;
@@ -65,7 +65,7 @@ public class IdCommand extends Command {
player.yellowMessage("Error reading file, please contact your administrator."); player.yellowMessage("Error reading file, please contact your administrator.");
} }
}; };
ThreadManager.getInstance().newTask(queryRunnable); ThreadManager.getInstance().newTask(queryRunnable);
} }
@@ -85,16 +85,20 @@ public class IdCommand extends Command {
} }
private String joinStringArr(String[] arr, String separator) { private String joinStringArr(String[] arr, String separator) {
if (null == arr || 0 == arr.length) return ""; if (null == arr || 0 == arr.length) {
return "";
}
StringBuilder sb = new StringBuilder(256); StringBuilder sb = new StringBuilder(256);
sb.append(arr[0]); sb.append(arr[0]);
for (int i = 1; i < arr.length; i++) sb.append(separator).append(arr[i]); for (int i = 1; i < arr.length; i++) {
sb.append(separator).append(arr[i]);
}
return sb.toString(); return sb.toString();
} }
private Map<String, String> fetchResults(Map<String, String> queryMap, String queryItem) { private Map<String, String> fetchResults(Map<String, String> queryMap, String queryItem) {
Map<String, String> results = new HashMap<>(); Map<String, String> results = new HashMap<>();
for (String item: queryMap.keySet()) { for (String item : queryMap.keySet()) {
if (item.indexOf(queryItem) != -1) { if (item.indexOf(queryItem) != -1) {
results.put(item, queryMap.get(item)); results.put(item, queryMap.get(item));
} }

View File

@@ -40,7 +40,7 @@ public class ItemCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1) { if (params.length < 1) {
player.yellowMessage("Syntax: !item <itemid> <quantity>"); player.yellowMessage("Syntax: !item <itemid> <quantity>");
return; return;
@@ -49,13 +49,15 @@ public class ItemCommand extends Command {
int itemId = Integer.parseInt(params[0]); int itemId = Integer.parseInt(params[0]);
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
if(ii.getName(itemId) == null) { if (ii.getName(itemId) == null) {
player.yellowMessage("Item id '" + params[0] + "' does not exist."); player.yellowMessage("Item id '" + params[0] + "' does not exist.");
return; return;
} }
short quantity = 1; short quantity = 1;
if(params.length >= 2) quantity = Short.parseShort(params[1]); if (params.length >= 2) {
quantity = Short.parseShort(params[1]);
}
if (YamlConfig.config.server.BLOCK_GENERATE_CASH_ITEM && ii.isCash(itemId)) { if (YamlConfig.config.server.BLOCK_GENERATE_CASH_ITEM && ii.isCash(itemId)) {
player.yellowMessage("You cannot create a cash item with this command."); player.yellowMessage("You cannot create a cash item with this command.");
@@ -63,26 +65,26 @@ public class ItemCommand extends Command {
} }
if (ItemConstants.isPet(itemId)) { if (ItemConstants.isPet(itemId)) {
if (params.length >= 2){ // thanks to istreety & TacoBell if (params.length >= 2) { // thanks to istreety & TacoBell
quantity = 1; quantity = 1;
long days = Math.max(1, Integer.parseInt(params[1])); long days = Math.max(1, Integer.parseInt(params[1]));
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000); long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
int petid = Pet.createPet(itemId); int petid = Pet.createPet(itemId);
InventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, expiration); InventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, expiration);
return; return;
} else { } else {
player.yellowMessage("Pet Syntax: !item <itemid> <expiration>"); player.yellowMessage("Pet Syntax: !item <itemid> <expiration>");
return; return;
} }
} }
short flag = 0; short flag = 0;
if(player.gmLevel() < 3) { if (player.gmLevel() < 3) {
flag |= ItemConstants.ACCOUNT_SHARING; flag |= ItemConstants.ACCOUNT_SHARING;
flag |= ItemConstants.UNTRADEABLE; flag |= ItemConstants.UNTRADEABLE;
} }
InventoryManipulator.addById(c, itemId, quantity, player.getName(), -1, flag, -1); InventoryManipulator.addById(c, itemId, quantity, player.getName(), -1, flag, -1);
} }
} }

View File

@@ -41,7 +41,7 @@ public class ItemDropCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1) { if (params.length < 1) {
player.yellowMessage("Syntax: !drop <itemid> <quantity>"); player.yellowMessage("Syntax: !drop <itemid> <quantity>");
return; return;
@@ -50,13 +50,15 @@ public class ItemDropCommand extends Command {
int itemId = Integer.parseInt(params[0]); int itemId = Integer.parseInt(params[0]);
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
if(ii.getName(itemId) == null) { if (ii.getName(itemId) == null) {
player.yellowMessage("Item id '" + params[0] + "' does not exist."); player.yellowMessage("Item id '" + params[0] + "' does not exist.");
return; return;
} }
short quantity = 1; short quantity = 1;
if(params.length >= 2) quantity = Short.parseShort(params[1]); if (params.length >= 2) {
quantity = Short.parseShort(params[1]);
}
if (YamlConfig.config.server.BLOCK_GENERATE_CASH_ITEM && ii.isCash(itemId)) { if (YamlConfig.config.server.BLOCK_GENERATE_CASH_ITEM && ii.isCash(itemId)) {
player.yellowMessage("You cannot create a cash item with this command."); player.yellowMessage("You cannot create a cash item with this command.");
@@ -64,7 +66,7 @@ public class ItemDropCommand extends Command {
} }
if (ItemConstants.isPet(itemId)) { if (ItemConstants.isPet(itemId)) {
if (params.length >= 2){ // thanks to istreety & TacoBell if (params.length >= 2) { // thanks to istreety & TacoBell
quantity = 1; quantity = 1;
long days = Math.max(1, Integer.parseInt(params[1])); long days = Math.max(1, Integer.parseInt(params[1]));
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000); long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000);
@@ -74,12 +76,12 @@ public class ItemDropCommand extends Command {
toDrop.setExpiration(expiration); toDrop.setExpiration(expiration);
toDrop.setOwner(""); toDrop.setOwner("");
if(player.gmLevel() < 3) { if (player.gmLevel() < 3) {
short f = toDrop.getFlag(); short f = toDrop.getFlag();
f |= ItemConstants.ACCOUNT_SHARING; f |= ItemConstants.ACCOUNT_SHARING;
f |= ItemConstants.UNTRADEABLE; f |= ItemConstants.UNTRADEABLE;
f |= ItemConstants.SANDBOX; f |= ItemConstants.SANDBOX;
toDrop.setFlag(f); toDrop.setFlag(f);
toDrop.setOwner("TRIAL-MODE"); toDrop.setOwner("TRIAL-MODE");
} }
@@ -89,10 +91,10 @@ public class ItemDropCommand extends Command {
return; return;
} else { } else {
player.yellowMessage("Pet Syntax: !drop <itemid> <expiration>"); player.yellowMessage("Pet Syntax: !drop <itemid> <expiration>");
return; return;
} }
} }
Item toDrop; Item toDrop;
if (ItemConstants.getInventoryType(itemId) == InventoryType.EQUIP) { if (ItemConstants.getInventoryType(itemId) == InventoryType.EQUIP) {
toDrop = ii.getEquipById(itemId); toDrop = ii.getEquipById(itemId);
@@ -101,7 +103,7 @@ public class ItemDropCommand extends Command {
} }
toDrop.setOwner(player.getName()); toDrop.setOwner(player.getName());
if(player.gmLevel() < 3) { if (player.gmLevel() < 3) {
short f = toDrop.getFlag(); short f = toDrop.getFlag();
f |= ItemConstants.ACCOUNT_SHARING; f |= ItemConstants.ACCOUNT_SHARING;
f |= ItemConstants.UNTRADEABLE; f |= ItemConstants.UNTRADEABLE;

View File

@@ -45,7 +45,9 @@ public class LevelCommand extends Command {
player.setLevel(Math.min(Integer.parseInt(params[0]), player.getMaxClassLevel()) - 1); player.setLevel(Math.min(Integer.parseInt(params[0]), player.getMaxClassLevel()) - 1);
player.resetPlayerRates(); player.resetPlayerRates();
if (YamlConfig.config.server.USE_ADD_RATES_BY_LEVEL) player.setPlayerRates(); if (YamlConfig.config.server.USE_ADD_RATES_BY_LEVEL) {
player.setPlayerRates();
}
player.setWorldRates(); player.setWorldRates();
player.levelUp(false); player.levelUp(false);

View File

@@ -45,7 +45,8 @@ public class MaxSkillCommand extends Command {
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
nfe.printStackTrace(); nfe.printStackTrace();
break; break;
} catch (NullPointerException npe) { } } catch (NullPointerException npe) {
}
} }
if (player.getJob().isA(Job.ARAN1) || player.getJob().isA(Job.LEGEND)) { if (player.getJob().isA(Job.ARAN1) || player.getJob().isA(Job.LEGEND)) {

View File

@@ -40,7 +40,9 @@ public class MaxStatCommand extends Command {
player.loseExp(player.getExp(), false, false); player.loseExp(player.getExp(), false, false);
player.setLevel(255); player.setLevel(255);
player.resetPlayerRates(); player.resetPlayerRates();
if (YamlConfig.config.server.USE_ADD_RATES_BY_LEVEL) player.setPlayerRates(); if (YamlConfig.config.server.USE_ADD_RATES_BY_LEVEL) {
player.setPlayerRates();
}
player.setWorldRates(); player.setWorldRates();
player.updateStrDexIntLuk(Short.MAX_VALUE); player.updateStrDexIntLuk(Short.MAX_VALUE);
player.setFame(13337); player.setFame(13337);

View File

@@ -41,16 +41,16 @@ public class RechargeCommand extends Command {
Character player = c.getPlayer(); Character player = c.getPlayer();
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
for (Item torecharge : c.getPlayer().getInventory(InventoryType.USE).list()) { for (Item torecharge : c.getPlayer().getInventory(InventoryType.USE).list()) {
if (ItemConstants.isThrowingStar(torecharge.getItemId())){ if (ItemConstants.isThrowingStar(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId())); torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge); c.getPlayer().forceUpdateItem(torecharge);
} else if (ItemConstants.isArrow(torecharge.getItemId())){ } else if (ItemConstants.isArrow(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId())); torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge); c.getPlayer().forceUpdateItem(torecharge);
} else if (ItemConstants.isBullet(torecharge.getItemId())){ } else if (ItemConstants.isBullet(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId())); torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge); c.getPlayer().forceUpdateItem(torecharge);
} else if (ItemConstants.isConsumable(torecharge.getItemId())){ } else if (ItemConstants.isConsumable(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId())); torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge); c.getPlayer().forceUpdateItem(torecharge);
} }

View File

@@ -40,10 +40,10 @@ public class SearchCommand extends Command {
private static Data mobStringData; private static Data mobStringData;
private static Data skillStringData; private static Data skillStringData;
private static Data mapStringData; private static Data mapStringData;
{ {
setDescription("Search String.wz."); setDescription("Search String.wz.");
DataProvider dataProvider = DataProviderFactory.getDataProvider(WZFiles.STRING); DataProvider dataProvider = DataProviderFactory.getDataProvider(WZFiles.STRING);
npcStringData = dataProvider.getData("Npc.img"); npcStringData = dataProvider.getData("Npc.img");
mobStringData = dataProvider.getData("Mob.img"); mobStringData = dataProvider.getData("Mob.img");
@@ -60,12 +60,12 @@ public class SearchCommand extends Command {
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String search = joinStringFrom(params,1); String search = joinStringFrom(params, 1);
long start = System.currentTimeMillis();//for the lulz long start = System.currentTimeMillis();//for the lulz
Data data = null; Data data = null;
if (!params[0].equalsIgnoreCase("ITEM")) { if (!params[0].equalsIgnoreCase("ITEM")) {
int searchType = 0; int searchType = 0;
if (params[0].equalsIgnoreCase("NPC")) { if (params[0].equalsIgnoreCase("NPC")) {
data = npcStringData; data = npcStringData;
} else if (params[0].equalsIgnoreCase("MOB") || params[0].equalsIgnoreCase("MONSTER")) { } else if (params[0].equalsIgnoreCase("MOB") || params[0].equalsIgnoreCase("MONSTER")) {
@@ -83,7 +83,7 @@ public class SearchCommand extends Command {
} }
if (data != null) { if (data != null) {
String name; String name;
if (searchType == 0) { if (searchType == 0) {
for (Data searchData : data.getChildren()) { for (Data searchData : data.getChildren()) {
name = DataTool.getString(searchData.getChildByPath("name"), "NO-NAME"); name = DataTool.getString(searchData.getChildByPath("name"), "NO-NAME");
@@ -93,12 +93,12 @@ public class SearchCommand extends Command {
} }
} else if (searchType == 1) { } else if (searchType == 1) {
String mapName, streetName; String mapName, streetName;
for (Data searchDataDir : data.getChildren()) { for (Data searchDataDir : data.getChildren()) {
for (Data searchData : searchDataDir.getChildren()) { for (Data searchData : searchDataDir.getChildren()) {
mapName = DataTool.getString(searchData.getChildByPath("mapName"), "NO-NAME"); mapName = DataTool.getString(searchData.getChildByPath("mapName"), "NO-NAME");
streetName = DataTool.getString(searchData.getChildByPath("streetName"), "NO-NAME"); streetName = DataTool.getString(searchData.getChildByPath("streetName"), "NO-NAME");
if (mapName.toLowerCase().contains(search.toLowerCase()) || streetName.toLowerCase().contains(search.toLowerCase())) { if (mapName.toLowerCase().contains(search.toLowerCase()) || streetName.toLowerCase().contains(search.toLowerCase())) {
sb.append("#b").append(Integer.parseInt(searchData.getName())).append("#k - #r").append(streetName).append(" - ").append(mapName).append("\r\n"); sb.append("#b").append(Integer.parseInt(searchData.getName())).append("#k - #r").append(streetName).append(" - ").append(mapName).append("\r\n");
} }
@@ -107,7 +107,7 @@ public class SearchCommand extends Command {
} else { } else {
for (Quest mq : Quest.getMatchedQuests(search)) { for (Quest mq : Quest.getMatchedQuests(search)) {
sb.append("#b").append(mq.getId()).append("#k - #r"); sb.append("#b").append(mq.getId()).append("#k - #r");
String parentName = mq.getParentName(); String parentName = mq.getParentName();
if (!parentName.isEmpty()) { if (!parentName.isEmpty()) {
sb.append(parentName).append(" - "); sb.append(parentName).append(" - ");

View File

@@ -39,17 +39,17 @@ public class SetSlotCommand extends Command {
player.yellowMessage("Syntax: !setslot <newlevel>"); player.yellowMessage("Syntax: !setslot <newlevel>");
return; return;
} }
int slots = (Integer.parseInt(params[0]) / 4) * 4; int slots = (Integer.parseInt(params[0]) / 4) * 4;
for (int i = 1; i < 5; i++) { for (int i = 1; i < 5; i++) {
int curSlots = player.getSlots(i); int curSlots = player.getSlots(i);
if (slots <= -curSlots) { if (slots <= -curSlots) {
continue; continue;
} }
player.gainSlots(i, slots - curSlots, true); player.gainSlots(i, slots - curSlots, true);
} }
player.yellowMessage("Slots updated."); player.yellowMessage("Slots updated.");
} }
} }

View File

@@ -43,10 +43,14 @@ public class SetStatCommand extends Command {
try { try {
int x = Integer.parseInt(params[0]); int x = Integer.parseInt(params[0]);
if (x > Short.MAX_VALUE) x = Short.MAX_VALUE; if (x > Short.MAX_VALUE) {
else if (x < 4) x = 4; // thanks Vcoc for pointing the minimal allowed stat value here x = Short.MAX_VALUE;
} else if (x < 4) {
x = 4; // thanks Vcoc for pointing the minimal allowed stat value here
}
player.updateStrDexIntLuk(x); player.updateStrDexIntLuk(x);
} catch (NumberFormatException nfe) {} } catch (NumberFormatException nfe) {
}
} }
} }

View File

@@ -43,16 +43,22 @@ public class SpCommand extends Command {
if (params.length == 1) { if (params.length == 1) {
int newSp = Integer.parseInt(params[0]); int newSp = Integer.parseInt(params[0]);
if (newSp < 0) newSp = 0; if (newSp < 0) {
else if (newSp > YamlConfig.config.server.MAX_AP) newSp = YamlConfig.config.server.MAX_AP; newSp = 0;
} else if (newSp > YamlConfig.config.server.MAX_AP) {
newSp = YamlConfig.config.server.MAX_AP;
}
player.updateRemainingSp(newSp); player.updateRemainingSp(newSp);
} else { } else {
Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]);
if (victim != null) { if (victim != null) {
int newSp = Integer.parseInt(params[1]); int newSp = Integer.parseInt(params[1]);
if (newSp < 0) newSp = 0; if (newSp < 0) {
else if (newSp > YamlConfig.config.server.MAX_AP) newSp = YamlConfig.config.server.MAX_AP; newSp = 0;
} else if (newSp > YamlConfig.config.server.MAX_AP) {
newSp = YamlConfig.config.server.MAX_AP;
}
victim.updateRemainingSp(newSp); victim.updateRemainingSp(newSp);

View File

@@ -46,7 +46,7 @@ public class SummonCommand extends Command {
Character victim = c.getChannelServer().getPlayerStorage().getCharacterByName(params[0]); Character victim = c.getChannelServer().getPlayerStorage().getCharacterByName(params[0]);
if (victim == null) { if (victim == null) {
//If victim isn't on current channel, loop all channels on current world. //If victim isn't on current channel, loop all channels on current world.
for (Channel ch : Server.getInstance().getChannelsFromWorld(c.getWorld())) { for (Channel ch : Server.getInstance().getChannelsFromWorld(c.getWorld())) {
victim = ch.getPlayerStorage().getCharacterByName(params[0]); victim = ch.getPlayerStorage().getCharacterByName(params[0]);
if (victim != null) { if (victim != null) {
@@ -59,19 +59,22 @@ public class SummonCommand extends Command {
player.dropMessage(6, "Player currently not logged in or unreachable."); player.dropMessage(6, "Player currently not logged in or unreachable.");
return; return;
} }
if (player.getClient().getChannel() != victim.getClient().getChannel()) {//And then change channel if needed. if (player.getClient().getChannel() != victim.getClient().getChannel()) {//And then change channel if needed.
victim.dropMessage("Changing channel, please wait a moment."); victim.dropMessage("Changing channel, please wait a moment.");
victim.getClient().changeChannel(player.getClient().getChannel()); victim.getClient().changeChannel(player.getClient().getChannel());
} }
try { try {
for (int i = 0; i < 7; i++) { // poll for a while until the player reconnects for (int i = 0; i < 7; i++) { // poll for a while until the player reconnects
if (victim.isLoggedinWorld()) break; if (victim.isLoggedinWorld()) {
break;
}
Thread.sleep(1777); Thread.sleep(1777);
} }
} catch (InterruptedException e) {} } catch (InterruptedException e) {
}
MapleMap map = player.getMap(); MapleMap map = player.getMap();
victim.saveLocationOnWarp(); victim.saveLocationOnWarp();
victim.forceChangeMap(map, map.findClosestPortal(player.getPosition())); victim.forceChangeMap(map, map.findClosestPortal(player.getPosition()));

View File

@@ -54,7 +54,7 @@ public class WarpAreaCommand extends Command {
Point pos = player.getPosition(); Point pos = player.getPosition();
Collection<Character> characters = player.getMap().getAllPlayers(); Collection<Character> characters = player.getMap().getAllPlayers();
for (Character victim : characters) { for (Character victim : characters) {
if (victim.getPosition().distanceSq(pos) <= 50000) { if (victim.getPosition().distanceSq(pos) <= 50000) {
victim.saveLocationOnWarp(); victim.saveLocationOnWarp();

View File

@@ -49,19 +49,19 @@ public class WarpCommand extends Command {
player.yellowMessage("Map ID " + params[0] + " is invalid."); player.yellowMessage("Map ID " + params[0] + " is invalid.");
return; return;
} }
if (!player.isAlive()) { if (!player.isAlive()) {
player.dropMessage(1, "This command cannot be used when you're dead."); player.dropMessage(1, "This command cannot be used when you're dead.");
return; return;
} }
if (!player.isGM()) { if (!player.isGM()) {
if (player.getEventInstance() != null || MiniDungeonInfo.isDungeonMap(player.getMapId()) || FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) { if (player.getEventInstance() != null || MiniDungeonInfo.isDungeonMap(player.getMapId()) || FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) {
player.dropMessage(1, "This command cannot be used in this map."); player.dropMessage(1, "This command cannot be used in this map.");
return; return;
} }
} }
// expedition issue with this command detected thanks to Masterrulax // expedition issue with this command detected thanks to Masterrulax
player.saveLocationOnWarp(); player.saveLocationOnWarp();
player.changeMap(target, target.getRandomPlayerSpawnpoint()); player.changeMap(target, target.getRandomPlayerSpawnpoint());

View File

@@ -51,7 +51,7 @@ public class WarpMapCommand extends Command {
} }
Collection<Character> characters = player.getMap().getAllPlayers(); Collection<Character> characters = player.getMap().getAllPlayers();
for (Character victim : characters) { for (Character victim : characters) {
victim.saveLocationOnWarp(); victim.saveLocationOnWarp();
victim.changeMap(target, target.getRandomPlayerSpawnpoint()); victim.changeMap(target, target.getRandomPlayerSpawnpoint());

View File

@@ -41,12 +41,12 @@ public class WhereaMiCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
HashSet<Character> chars = new HashSet<>(); HashSet<Character> chars = new HashSet<>();
HashSet<NPC> npcs = new HashSet<>(); HashSet<NPC> npcs = new HashSet<>();
HashSet<PlayerNPC> playernpcs = new HashSet<>(); HashSet<PlayerNPC> playernpcs = new HashSet<>();
HashSet<Monster> mobs = new HashSet<>(); HashSet<Monster> mobs = new HashSet<>();
for (MapObject mmo : player.getMap().getMapObjects()) { for (MapObject mmo : player.getMap().getMapObjects()) {
if (mmo instanceof NPC) { if (mmo instanceof NPC) {
NPC npc = (NPC) mmo; NPC npc = (NPC) mmo;
@@ -64,28 +64,28 @@ public class WhereaMiCommand extends Command {
playernpcs.add(npc); playernpcs.add(npc);
} }
} }
player.yellowMessage("Map ID: " + player.getMap().getId()); player.yellowMessage("Map ID: " + player.getMap().getId());
player.yellowMessage("Players on this map:"); player.yellowMessage("Players on this map:");
for (Character chr : chars) { for (Character chr : chars) {
player.dropMessage(5, ">> " + chr.getName() + " - " + chr.getId() + " - Oid: " + chr.getObjectId()); player.dropMessage(5, ">> " + chr.getName() + " - " + chr.getId() + " - Oid: " + chr.getObjectId());
} }
if (!playernpcs.isEmpty()) { if (!playernpcs.isEmpty()) {
player.yellowMessage("PlayerNPCs on this map:"); player.yellowMessage("PlayerNPCs on this map:");
for (PlayerNPC pnpc : playernpcs) { for (PlayerNPC pnpc : playernpcs) {
player.dropMessage(5, ">> " + pnpc.getName() + " - Scriptid: " + pnpc.getScriptId() + " - Oid: " + pnpc.getObjectId()); player.dropMessage(5, ">> " + pnpc.getName() + " - Scriptid: " + pnpc.getScriptId() + " - Oid: " + pnpc.getObjectId());
} }
} }
if (!npcs.isEmpty()) { if (!npcs.isEmpty()) {
player.yellowMessage("NPCs on this map:"); player.yellowMessage("NPCs on this map:");
for (NPC npc : npcs) { for (NPC npc : npcs) {
player.dropMessage(5, ">> " + npc.getName() + " - " + npc.getId() + " - Oid: " + npc.getObjectId()); player.dropMessage(5, ">> " + npc.getName() + " - " + npc.getId() + " - Oid: " + npc.getObjectId());
} }
} }
if (!mobs.isEmpty()) { if (!mobs.isEmpty()) {
player.yellowMessage("Monsters on this map:"); player.yellowMessage("Monsters on this map:");
for (Monster mob : mobs) { for (Monster mob : mobs) {

View File

@@ -42,8 +42,12 @@ public class CheckDmgCommand extends Command {
Integer watkBuff = victim.getBuffedValue(BuffStat.WATK); Integer watkBuff = victim.getBuffedValue(BuffStat.WATK);
Integer matkBuff = victim.getBuffedValue(BuffStat.MATK); Integer matkBuff = victim.getBuffedValue(BuffStat.MATK);
int blessing = victim.getSkillLevel(10000000 * player.getJobType() + 12); int blessing = victim.getSkillLevel(10000000 * player.getJobType() + 12);
if (watkBuff == null) watkBuff = 0; if (watkBuff == null) {
if (matkBuff == null) matkBuff = 0; watkBuff = 0;
}
if (matkBuff == null) {
matkBuff = 0;
}
player.dropMessage(5, "Cur Str: " + victim.getTotalStr() + " Cur Dex: " + victim.getTotalDex() + " Cur Int: " + victim.getTotalInt() + " Cur Luk: " + victim.getTotalLuk()); player.dropMessage(5, "Cur Str: " + victim.getTotalStr() + " Cur Dex: " + victim.getTotalDex() + " Cur Int: " + victim.getTotalInt() + " Cur Luk: " + victim.getTotalLuk());
player.dropMessage(5, "Cur WATK: " + victim.getTotalWatk() + " Cur MATK: " + victim.getTotalMagic()); player.dropMessage(5, "Cur WATK: " + victim.getTotalWatk() + " Cur MATK: " + victim.getTotalMagic());

View File

@@ -46,12 +46,16 @@ public class FlyCommand extends Command {
String sendStr = ""; String sendStr = "";
if (params[0].equalsIgnoreCase("on")) { if (params[0].equalsIgnoreCase("on")) {
sendStr += "Enabled Fly feature (F1). With fly active, you cannot attack."; sendStr += "Enabled Fly feature (F1). With fly active, you cannot attack.";
if (!srv.canFly(accid)) sendStr += " Re-login to take effect."; if (!srv.canFly(accid)) {
sendStr += " Re-login to take effect.";
}
srv.changeFly(c.getAccID(), true); srv.changeFly(c.getAccID(), true);
} else { } else {
sendStr += "Disabled Fly feature. You can now attack."; sendStr += "Disabled Fly feature. You can now attack.";
if (srv.canFly(accid)) sendStr += " Re-login to take effect."; if (srv.canFly(accid)) {
sendStr += " Re-login to take effect.";
}
srv.changeFly(c.getAccID(), false); srv.changeFly(c.getAccID(), false);
} }

View File

@@ -42,7 +42,7 @@ public class GiveMesosCommand extends Command {
String recv_, value_; String recv_, value_;
long mesos_ = 0; long mesos_ = 0;
if (params.length == 2) { if (params.length == 2) {
recv_ = params[0]; recv_ = params[0];
value_ = params[1]; value_ = params[1];
@@ -50,7 +50,7 @@ public class GiveMesosCommand extends Command {
recv_ = c.getPlayer().getName(); recv_ = c.getPlayer().getName();
value_ = params[0]; value_ = params[0];
} }
try { try {
mesos_ = Long.parseLong(value_); mesos_ = Long.parseLong(value_);
if (mesos_ > Integer.MAX_VALUE) { if (mesos_ > Integer.MAX_VALUE) {
@@ -65,7 +65,7 @@ public class GiveMesosCommand extends Command {
mesos_ = Integer.MIN_VALUE; mesos_ = Integer.MIN_VALUE;
} }
} }
Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(recv_); Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(recv_);
if (victim != null) { if (victim != null) {
victim.gainMeso((int) mesos_, true); victim.gainMeso((int) mesos_, true);

View File

@@ -55,7 +55,7 @@ public class GiveNxCommand extends Command {
type = 1; type = 1;
} }
typeStr = params[0]; typeStr = params[0];
if (params.length > 2) { if (params.length > 2) {
recv = params[1]; recv = params[1];
value = Integer.parseInt(params[2]); value = Integer.parseInt(params[2]);

View File

@@ -21,7 +21,7 @@ public class GiveRpCommand extends Command {
if (victim != null) { if (victim != null) {
victim.setRewardPoints(victim.getRewardPoints() + Integer.parseInt(params[1])); victim.setRewardPoints(victim.getRewardPoints() + Integer.parseInt(params[1]));
player.message("RP given. Player " + params[0] + " now has " + victim.getRewardPoints() player.message("RP given. Player " + params[0] + " now has " + victim.getRewardPoints()
+ " reward points." ); + " reward points.");
} else { } else {
player.message("Player '" + params[0] + "' could not be found."); player.message("Player '" + params[0] + "' could not be found.");
} }

View File

@@ -36,7 +36,7 @@ public class MaxHpMpCommand extends Command {
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
Character victim = player; Character victim = player;
int statUpdate = 1; int statUpdate = 1;
if (params.length >= 2) { if (params.length >= 2) {
victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]);
@@ -46,7 +46,7 @@ public class MaxHpMpCommand extends Command {
} else { } else {
player.yellowMessage("Syntax: !maxhpmp [<playername>] <value>"); player.yellowMessage("Syntax: !maxhpmp [<playername>] <value>");
} }
if (victim != null) { if (victim != null) {
int extraHp = victim.getCurrentMaxHp() - victim.getClientMaxHp(); int extraHp = victim.getCurrentMaxHp() - victim.getClientMaxHp();
int extraMp = victim.getCurrentMaxMp() - victim.getClientMaxMp(); int extraMp = victim.getCurrentMaxMp() - victim.getClientMaxMp();

View File

@@ -39,24 +39,24 @@ public class MusicCommand extends Command {
for (String s : GameConstants.GAME_SONGS) { for (String s : GameConstants.GAME_SONGS) {
songList += (" " + s + "\r\n"); songList += (" " + s + "\r\n");
} }
return songList; return songList;
} }
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1) { if (params.length < 1) {
String sendMsg = ""; String sendMsg = "";
sendMsg += "Syntax: #r!music <song>#k\r\n\r\n"; sendMsg += "Syntax: #r!music <song>#k\r\n\r\n";
sendMsg += getSongList(); sendMsg += getSongList();
c.sendPacket(PacketCreator.getNPCTalk(1052015, (byte) 0, sendMsg, "00 00", (byte) 0)); c.sendPacket(PacketCreator.getNPCTalk(1052015, (byte) 0, sendMsg, "00 00", (byte) 0));
return; return;
} }
String song = player.getLastCommandMessage(); String song = player.getLastCommandMessage();
for (String s : GameConstants.GAME_SONGS) { for (String s : GameConstants.GAME_SONGS) {
if (s.equalsIgnoreCase(song)) { // thanks Masterrulax for finding an issue here if (s.equalsIgnoreCase(song)) { // thanks Masterrulax for finding an issue here
@@ -65,11 +65,11 @@ public class MusicCommand extends Command {
return; return;
} }
} }
String sendMsg = ""; String sendMsg = "";
sendMsg += "Song not found, please enter a song below.\r\n\r\n"; sendMsg += "Song not found, please enter a song below.\r\n\r\n";
sendMsg += getSongList(); sendMsg += getSongList();
c.sendPacket(PacketCreator.getNPCTalk(1052015, (byte) 0, sendMsg, "00 00", (byte) 0)); c.sendPacket(PacketCreator.getNPCTalk(1052015, (byte) 0, sendMsg, "00 00", (byte) 0));
} }
} }

View File

@@ -36,8 +36,8 @@ public class QuestCompleteCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1){ if (params.length < 1) {
player.yellowMessage("Syntax: !completequest <questid>"); player.yellowMessage("Syntax: !completequest <questid>");
return; return;
} }
@@ -51,7 +51,7 @@ public class QuestCompleteCommand extends Command {
} else { } else {
c.getAbstractPlayerInteraction().forceCompleteQuest(questId); c.getAbstractPlayerInteraction().forceCompleteQuest(questId);
} }
player.dropMessage(5, "QUEST " + questId + " completed."); player.dropMessage(5, "QUEST " + questId + " completed.");
} else { } else {
player.dropMessage(5, "QUESTID " + questId + " not started or already completed."); player.dropMessage(5, "QUESTID " + questId + " not started or already completed.");

View File

@@ -36,8 +36,8 @@ public class QuestResetCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1){ if (params.length < 1) {
player.yellowMessage("Syntax: !resetquest <questid>"); player.yellowMessage("Syntax: !resetquest <questid>");
return; return;
} }

View File

@@ -36,8 +36,8 @@ public class QuestStartCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1){ if (params.length < 1) {
player.yellowMessage("Syntax: !startquest <questid>"); player.yellowMessage("Syntax: !startquest <questid>");
return; return;
} }
@@ -51,7 +51,7 @@ public class QuestStartCommand extends Command {
} else { } else {
c.getAbstractPlayerInteraction().forceStartQuest(questid); c.getAbstractPlayerInteraction().forceStartQuest(questid);
} }
player.dropMessage(5, "QUEST " + questid + " started."); player.dropMessage(5, "QUEST " + questid + " started.");
} else { } else {
player.dropMessage(5, "QUESTID " + questid + " already started/completed."); player.dropMessage(5, "QUESTID " + questid + " already started/completed.");

View File

@@ -42,12 +42,13 @@ public class ReloadMapCommand extends Command {
int callerid = c.getPlayer().getId(); int callerid = c.getPlayer().getId();
Collection<Character> characters = player.getMap().getAllPlayers(); Collection<Character> characters = player.getMap().getAllPlayers();
for (Character chr : characters) { for (Character chr : characters) {
chr.saveLocationOnWarp(); chr.saveLocationOnWarp();
chr.changeMap(newMap); chr.changeMap(newMap);
if (chr.getId() != callerid) if (chr.getId() != callerid) {
chr.dropMessage("You have been relocated due to map reloading. Sorry for the inconvenience."); chr.dropMessage("You have been relocated due to map reloading. Sorry for the inconvenience.");
}
} }
newMap.respawn(); newMap.respawn();
} }

View File

@@ -39,8 +39,9 @@ public class StartEventCommand extends Command {
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
int players = 50; int players = 50;
if (params.length > 1) if (params.length > 1) {
players = Integer.parseInt(params[0]); players = Integer.parseInt(params[0]);
}
c.getChannelServer().setEvent(new Event(player.getMapId(), players)); c.getChannelServer().setEvent(new Event(player.getMapId(), players));
Server.getInstance().broadcastMessage(c.getWorld(), PacketCreator.earnTitleMessage( Server.getInstance().broadcastMessage(c.getWorld(), PacketCreator.earnTitleMessage(
"[Event] An event has started on " "[Event] An event has started on "

View File

@@ -25,7 +25,6 @@ import client.command.Command;
import tools.PacketCreator; import tools.PacketCreator;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class BossDropRateCommand extends Command { public class BossDropRateCommand extends Command {

View File

@@ -50,7 +50,9 @@ public class ForceVacCommand extends Command {
mapItem.lockItem(); mapItem.lockItem();
try { try {
if (mapItem.isPickedUp()) continue; if (mapItem.isPickedUp()) {
continue;
}
if (mapItem.getMeso() > 0) { if (mapItem.getMeso() > 0) {
player.gainMeso(mapItem.getMeso(), true); player.gainMeso(mapItem.getMeso(), true);

View File

@@ -36,7 +36,7 @@ public class PapCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
// thanks Conrad for noticing mobid typo here // thanks Conrad for noticing mobid typo here
player.getMap().spawnMonsterOnGroundBelow(LifeFactory.getMonster(8500001), player.getPosition()); player.getMap().spawnMonsterOnGroundBelow(LifeFactory.getMonster(8500001), player.getPosition());
} }

View File

@@ -47,14 +47,14 @@ public class PnpcRemoveCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
int mapId = player.getMapId(); int mapId = player.getMapId();
int npcId = params.length > 0 ? Integer.parseInt(params[0]) : -1; int npcId = params.length > 0 ? Integer.parseInt(params[0]) : -1;
Point pos = player.getPosition(); Point pos = player.getPosition();
int xpos = pos.x; int xpos = pos.x;
int ypos = pos.y; int ypos = pos.y;
List<Pair<Integer, Pair<Integer, Integer>>> toRemove = new LinkedList<>(); List<Pair<Integer, Pair<Integer, Integer>>> toRemove = new LinkedList<>();
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
final PreparedStatement ps; final PreparedStatement ps;
@@ -76,7 +76,7 @@ public class PnpcRemoveCommand extends Command {
ps.setInt(6, ypos - 50); ps.setInt(6, ypos - 50);
ps.setInt(7, ypos + 50); ps.setInt(7, ypos + 50);
} }
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
while (true) { while (true) {
rs.beforeFirst(); rs.beforeFirst();
@@ -94,9 +94,9 @@ public class PnpcRemoveCommand extends Command {
e.printStackTrace(); e.printStackTrace();
player.dropMessage(5, "Failed to remove pNPC from the database."); player.dropMessage(5, "Failed to remove pNPC from the database.");
} }
if (!toRemove.isEmpty()) { if (!toRemove.isEmpty()) {
for (Channel ch: player.getWorldServer().getChannels()) { for (Channel ch : player.getWorldServer().getChannels()) {
MapleMap map = ch.getMapFactory().getMap(mapId); MapleMap map = ch.getMapFactory().getMap(mapId);
for (Pair<Integer, Pair<Integer, Integer>> r : toRemove) { for (Pair<Integer, Pair<Integer, Integer>> r : toRemove) {
@@ -104,7 +104,7 @@ public class PnpcRemoveCommand extends Command {
} }
} }
} }
player.yellowMessage("Cleared " + toRemove.size() + " pNPC placements."); player.yellowMessage("Cleared " + toRemove.size() + " pNPC placements.");
} }
} }

View File

@@ -45,18 +45,18 @@ public class ProItemCommand extends Command {
player.yellowMessage("Syntax: !proitem <itemid> <stat value> [<spdjmp value>]"); player.yellowMessage("Syntax: !proitem <itemid> <stat value> [<spdjmp value>]");
return; return;
} }
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
int itemid = Integer.parseInt(params[0]); int itemid = Integer.parseInt(params[0]);
if(ii.getName(itemid) == null) { if (ii.getName(itemid) == null) {
player.yellowMessage("Item id '" + params[0] + "' does not exist."); player.yellowMessage("Item id '" + params[0] + "' does not exist.");
return; return;
} }
short stat = (short) Math.max(0, Short.parseShort(params[1])); short stat = (short) Math.max(0, Short.parseShort(params[1]));
short spdjmp = params.length >= 3 ? (short) Math.max(0, Short.parseShort(params[2])) : 0; short spdjmp = params.length >= 3 ? (short) Math.max(0, Short.parseShort(params[2])) : 0;
InventoryType type = ItemConstants.getInventoryType(itemid); InventoryType type = ItemConstants.getInventoryType(itemid);
if (type.equals(InventoryType.EQUIP)) { if (type.equals(InventoryType.EQUIP)) {
Item it = ii.getEquipById(itemid); Item it = ii.getEquipById(itemid);
@@ -68,6 +68,7 @@ public class ProItemCommand extends Command {
player.dropMessage(6, "Make sure it's an equippable item."); player.dropMessage(6, "Make sure it's an equippable item.");
} }
} }
private static void hardsetItemStats(Equip equip, short stat, short spdjmp) { private static void hardsetItemStats(Equip equip, short stat, short spdjmp) {
equip.setStr(stat); equip.setStr(stat);
equip.setDex(stat); equip.setDex(stat);

View File

@@ -47,11 +47,13 @@ public class SetEqStatCommand extends Command {
short newStat = (short) Math.max(0, Integer.parseInt(params[0])); short newStat = (short) Math.max(0, Integer.parseInt(params[0]));
short newSpdJmp = params.length >= 2 ? (short) Integer.parseInt(params[1]) : 0; short newSpdJmp = params.length >= 2 ? (short) Integer.parseInt(params[1]) : 0;
Inventory equip = player.getInventory(InventoryType.EQUIP); Inventory equip = player.getInventory(InventoryType.EQUIP);
for (byte i = 1; i <= equip.getSlotLimit(); i++) { for (byte i = 1; i <= equip.getSlotLimit(); i++) {
try { try {
Equip eq = (Equip) equip.getItem(i); Equip eq = (Equip) equip.getItem(i);
if (eq == null) continue; if (eq == null) {
continue;
}
eq.setWdef(newStat); eq.setWdef(newStat);
eq.setAcc(newStat); eq.setAcc(newStat);

View File

@@ -41,7 +41,7 @@ import java.util.List;
public class DebugCommand extends Command { public class DebugCommand extends Command {
private final static String[] debugTypes = {"monster", "packet", "portal", "spawnpoint", "pos", "map", "mobsp", "event", "areas", "reactors", "servercoupons", "playercoupons", "timer", "marriage", "buff", ""}; private final static String[] debugTypes = {"monster", "packet", "portal", "spawnpoint", "pos", "map", "mobsp", "event", "areas", "reactors", "servercoupons", "playercoupons", "timer", "marriage", "buff", ""};
{ {
setDescription("Show a debug message."); setDescription("Show a debug message.");
} }
@@ -59,13 +59,13 @@ public class DebugCommand extends Command {
case "type": case "type":
case "help": case "help":
String msgTypes = "Available #bdebug types#k:\r\n\r\n"; String msgTypes = "Available #bdebug types#k:\r\n\r\n";
for(int i = 0; i < debugTypes.length; i++) { for (int i = 0; i < debugTypes.length; i++) {
msgTypes += ("#L" + i + "#" + debugTypes[i] + "#l\r\n"); msgTypes += ("#L" + i + "#" + debugTypes[i] + "#l\r\n");
} }
c.getAbstractPlayerInteraction().npcTalk(9201143, msgTypes); c.getAbstractPlayerInteraction().npcTalk(9201143, msgTypes);
break; break;
case "monster": case "monster":
List<MapObject> monsters = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapObjectType.MONSTER)); List<MapObject> monsters = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapObjectType.MONSTER));
for (MapObject monstermo : monsters) { for (MapObject monstermo : monsters) {
@@ -81,16 +81,20 @@ public class DebugCommand extends Command {
case "portal": case "portal":
Portal portal = player.getMap().findClosestPortal(player.getPosition()); Portal portal = player.getMap().findClosestPortal(player.getPosition());
if (portal != null) if (portal != null) {
player.dropMessage(6, "Closest portal: " + portal.getId() + " '" + portal.getName() + "' Type: " + portal.getType() + " --> toMap: " + portal.getTargetMapId() + " scriptname: '" + portal.getScriptName() + "' state: " + (portal.getPortalState() ? 1 : 0) + "."); player.dropMessage(6, "Closest portal: " + portal.getId() + " '" + portal.getName() + "' Type: " + portal.getType() + " --> toMap: " + portal.getTargetMapId() + " scriptname: '" + portal.getScriptName() + "' state: " + (portal.getPortalState() ? 1 : 0) + ".");
else player.dropMessage(6, "There is no portal on this map."); } else {
player.dropMessage(6, "There is no portal on this map.");
}
break; break;
case "spawnpoint": case "spawnpoint":
SpawnPoint sp = player.getMap().findClosestSpawnpoint(player.getPosition()); SpawnPoint sp = player.getMap().findClosestSpawnpoint(player.getPosition());
if (sp != null) if (sp != null) {
player.dropMessage(6, "Closest mob spawn point: " + " Position: x " + sp.getPosition().getX() + " y " + sp.getPosition().getY() + " Spawns mobid: '" + sp.getMonsterId() + "' --> canSpawn: " + !sp.getDenySpawn() + " canSpawnRightNow: " + sp.shouldSpawn() + "."); player.dropMessage(6, "Closest mob spawn point: " + " Position: x " + sp.getPosition().getX() + " y " + sp.getPosition().getY() + " Spawns mobid: '" + sp.getMonsterId() + "' --> canSpawn: " + !sp.getDenySpawn() + " canSpawnRightNow: " + sp.shouldSpawn() + ".");
else player.dropMessage(6, "There is no mob spawn point on this map."); } else {
player.dropMessage(6, "There is no mob spawn point on this map.");
}
break; break;
case "pos": case "pos":
@@ -106,8 +110,11 @@ public class DebugCommand extends Command {
break; break;
case "event": case "event":
if (player.getEventInstance() == null) player.dropMessage(6, "Player currently not in an event."); if (player.getEventInstance() == null) {
else player.dropMessage(6, "Current event name: " + player.getEventInstance().getName() + "."); player.dropMessage(6, "Player currently not in an event.");
} else {
player.dropMessage(6, "Current event name: " + player.getEventInstance().getName() + ".");
}
break; break;
case "areas": case "areas":
@@ -156,7 +163,7 @@ public class DebugCommand extends Command {
case "marriage": case "marriage":
c.getChannelServer().debugMarriageStatus(); c.getChannelServer().debugMarriageStatus();
break; break;
case "buff": case "buff":
c.getPlayer().debugListAllBuffs(); c.getPlayer().debugListAllBuffs();
break; break;

View File

@@ -29,7 +29,6 @@ import net.server.world.World;
import java.util.Collection; import java.util.Collection;
/** /**
*
* @author Mist * @author Mist
* @author Blood (Tochi) * @author Blood (Tochi)
* @author Ronan * @author Ronan
@@ -42,20 +41,20 @@ public class IpListCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
String str = "Player-IP relation:"; String str = "Player-IP relation:";
for (World w : Server.getInstance().getWorlds()) { for (World w : Server.getInstance().getWorlds()) {
Collection<Character> chars = w.getPlayerStorage().getAllCharacters(); Collection<Character> chars = w.getPlayerStorage().getAllCharacters();
if (!chars.isEmpty()) { if (!chars.isEmpty()) {
str += "\r\n" + GameConstants.WORLD_NAMES[w.getId()] + "\r\n"; str += "\r\n" + GameConstants.WORLD_NAMES[w.getId()] + "\r\n";
for (Character chr : chars) { for (Character chr : chars) {
str += " " + chr.getName() + " - " + chr.getClient().getRemoteAddress() + "\r\n"; str += " " + chr.getName() + " - " + chr.getClient().getRemoteAddress() + "\r\n";
} }
} }
} }
c.getAbstractPlayerInteraction().npcTalk(22000, str); c.getAbstractPlayerInteraction().npcTalk(22000, str);
} }
} }

View File

@@ -24,7 +24,6 @@ import client.command.Command;
import net.server.coordinator.session.SessionCoordinator; import net.server.coordinator.session.SessionCoordinator;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class ShowSessionsCommand extends Command { public class ShowSessionsCommand extends Command {

View File

@@ -37,7 +37,7 @@ public class ServerAddChannelCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
final Character player = c.getPlayer(); final Character player = c.getPlayer();
if (params.length < 1) { if (params.length < 1) {
player.dropMessage(5, "Syntax: @addchannel <worldid>"); player.dropMessage(5, "Syntax: @addchannel <worldid>");
return; return;
@@ -47,15 +47,15 @@ public class ServerAddChannelCommand extends Command {
ThreadManager.getInstance().newTask(() -> { ThreadManager.getInstance().newTask(() -> {
int chid = Server.getInstance().addChannel(worldid); int chid = Server.getInstance().addChannel(worldid);
if(player.isLoggedinWorld()) { if (player.isLoggedinWorld()) {
if(chid >= 0) { if (chid >= 0) {
player.dropMessage(5, "NEW Channel " + chid + " successfully deployed on world " + worldid + "."); player.dropMessage(5, "NEW Channel " + chid + " successfully deployed on world " + worldid + ".");
} else { } else {
if(chid == -3) { if (chid == -3) {
player.dropMessage(5, "Invalid worldid detected. Channel creation aborted."); player.dropMessage(5, "Invalid worldid detected. Channel creation aborted.");
} else if(chid == -2) { } else if (chid == -2) {
player.dropMessage(5, "Reached channel limit on worldid " + worldid + ". Channel creation aborted."); player.dropMessage(5, "Reached channel limit on worldid " + worldid + ". Channel creation aborted.");
} else if(chid == -1) { } else if (chid == -1) {
player.dropMessage(5, "Error detected when loading the 'world.ini' file. Channel creation aborted."); player.dropMessage(5, "Error detected when loading the 'world.ini' file. Channel creation aborted.");
} else { } else {
player.dropMessage(5, "NEW Channel failed to be deployed. Check if the needed port is already in use or other limitations are taking place."); player.dropMessage(5, "NEW Channel failed to be deployed. Check if the needed port is already in use or other limitations are taking place.");

View File

@@ -37,15 +37,15 @@ public class ServerAddWorldCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
final Character player = c.getPlayer(); final Character player = c.getPlayer();
ThreadManager.getInstance().newTask(() -> { ThreadManager.getInstance().newTask(() -> {
int wid = Server.getInstance().addWorld(); int wid = Server.getInstance().addWorld();
if(player.isLoggedinWorld()) { if (player.isLoggedinWorld()) {
if(wid >= 0) { if (wid >= 0) {
player.dropMessage(5, "NEW World " + wid + " successfully deployed."); player.dropMessage(5, "NEW World " + wid + " successfully deployed.");
} else { } else {
if(wid == -2) { if (wid == -2) {
player.dropMessage(5, "Error detected when loading the 'world.ini' file. World creation aborted."); player.dropMessage(5, "Error detected when loading the 'world.ini' file. World creation aborted.");
} else { } else {
player.dropMessage(5, "NEW World failed to be deployed. Check if needed ports are already in use or maximum world count has been reached."); player.dropMessage(5, "NEW World failed to be deployed. Check if needed ports are already in use or maximum world count has been reached.");

View File

@@ -37,7 +37,7 @@ public class ServerRemoveChannelCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
final Character player = c.getPlayer(); final Character player = c.getPlayer();
if (params.length < 1) { if (params.length < 1) {
player.dropMessage(5, "Syntax: @removechannel <worldid>"); player.dropMessage(5, "Syntax: @removechannel <worldid>");
return; return;
@@ -45,12 +45,12 @@ public class ServerRemoveChannelCommand extends Command {
final int worldId = Integer.parseInt(params[0]); final int worldId = Integer.parseInt(params[0]);
ThreadManager.getInstance().newTask(() -> { ThreadManager.getInstance().newTask(() -> {
if(Server.getInstance().removeChannel(worldId)) { if (Server.getInstance().removeChannel(worldId)) {
if(player.isLoggedinWorld()) { if (player.isLoggedinWorld()) {
player.dropMessage(5, "Successfully removed a channel on World " + worldId + ". Current channel count: " + Server.getInstance().getWorld(worldId).getChannelsSize() + "."); player.dropMessage(5, "Successfully removed a channel on World " + worldId + ". Current channel count: " + Server.getInstance().getWorld(worldId).getChannelsSize() + ".");
} }
} else { } else {
if(player.isLoggedinWorld()) { if (player.isLoggedinWorld()) {
player.dropMessage(5, "Failed to remove last Channel on world " + worldId + ". Check if either that world exists or there are people currently playing there."); player.dropMessage(5, "Failed to remove last Channel on world " + worldId + ". Check if either that world exists or there are people currently playing there.");
} }
} }

View File

@@ -37,21 +37,21 @@ public class ServerRemoveWorldCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
final Character player = c.getPlayer(); final Character player = c.getPlayer();
final int rwid = Server.getInstance().getWorldsSize() - 1; final int rwid = Server.getInstance().getWorldsSize() - 1;
if(rwid <= 0) { if (rwid <= 0) {
player.dropMessage(5, "Unable to remove world 0."); player.dropMessage(5, "Unable to remove world 0.");
return; return;
} }
ThreadManager.getInstance().newTask(() -> { ThreadManager.getInstance().newTask(() -> {
if(Server.getInstance().removeWorld()) { if (Server.getInstance().removeWorld()) {
if(player.isLoggedinWorld()) { if (player.isLoggedinWorld()) {
player.dropMessage(5, "Successfully removed a world. Current world count: " + Server.getInstance().getWorldsSize() + "."); player.dropMessage(5, "Successfully removed a world. Current world count: " + Server.getInstance().getWorldsSize() + ".");
} }
} else { } else {
if(player.isLoggedinWorld()) { if (player.isLoggedinWorld()) {
if(rwid < 0) { if (rwid < 0) {
player.dropMessage(5, "No registered worlds to remove."); player.dropMessage(5, "No registered worlds to remove.");
} else { } else {
player.dropMessage(5, "Failed to remove world " + rwid + ". Check if there are people currently playing there."); player.dropMessage(5, "Failed to remove world " + rwid + ". Check if there are people currently playing there.");

View File

@@ -38,13 +38,13 @@ public class ShutdownCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
if (params.length < 1){ if (params.length < 1) {
player.yellowMessage("Syntax: !shutdown [<time>|NOW]"); player.yellowMessage("Syntax: !shutdown [<time>|NOW]");
return; return;
} }
int time = 60000; int time = 60000;
if (params[0].equalsIgnoreCase("now")){ if (params[0].equalsIgnoreCase("now")) {
time = 1; time = 1;
} else { } else {
time *= Integer.parseInt(params[0]); time *= Integer.parseInt(params[0]);
@@ -57,8 +57,12 @@ public class ShutdownCommand extends Command {
int days = (time / (1000 * 60 * 60 * 24)); int days = (time / (1000 * 60 * 60 * 24));
String strTime = ""; String strTime = "";
if (days > 0) strTime += days + " days, "; if (days > 0) {
if (hours > 0) strTime += hours + " hours, "; strTime += days + " days, ";
}
if (hours > 0) {
strTime += hours + " hours, ";
}
strTime += minutes + " minutes, "; strTime += minutes + " minutes, ";
strTime += seconds + " seconds"; strTime += seconds + " seconds";
@@ -68,7 +72,7 @@ public class ShutdownCommand extends Command {
} }
} }
} }
TimerManager.getInstance().schedule(Server.getInstance().shutdown(false), time); TimerManager.getInstance().schedule(Server.getInstance().shutdown(false), time);
} }
} }

View File

@@ -36,7 +36,7 @@ public class SupplyRateCouponCommand extends Command {
player.dropMessage(5, "Syntax: !supplyratecoupon <yes|no>"); player.dropMessage(5, "Syntax: !supplyratecoupon <yes|no>");
return; return;
} }
YamlConfig.config.server.USE_SUPPLY_RATE_COUPONS = params[0].compareToIgnoreCase("no") != 0; YamlConfig.config.server.USE_SUPPLY_RATE_COUPONS = params[0].compareToIgnoreCase("no") != 0;
player.dropMessage(5, "Rate coupons are now " + (YamlConfig.config.server.USE_SUPPLY_RATE_COUPONS ? "enabled" : "disabled") + " for purchase at the Cash Shop."); player.dropMessage(5, "Rate coupons are now " + (YamlConfig.config.server.USE_SUPPLY_RATE_COUPONS ? "enabled" : "disabled") + " for purchase at the Cash Shop.");
} }

View File

@@ -32,70 +32,69 @@ import tools.FilePrinter;
import tools.PacketCreator; import tools.PacketCreator;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public abstract class CharacterFactory { public abstract class CharacterFactory {
protected synchronized static int createNewCharacter(Client c, String name, int face, int hair, int skin, int gender, CharacterFactoryRecipe recipe) { protected synchronized static int createNewCharacter(Client c, String name, int face, int hair, int skin, int gender, CharacterFactoryRecipe recipe) {
if (YamlConfig.config.server.COLLECTIVE_CHARSLOT ? c.getAvailableCharacterSlots() <= 0 : c.getAvailableCharacterWorldSlots() <= 0) { if (YamlConfig.config.server.COLLECTIVE_CHARSLOT ? c.getAvailableCharacterSlots() <= 0 : c.getAvailableCharacterWorldSlots() <= 0) {
return -3; return -3;
} }
if (!Character.canCreateChar(name)) { if (!Character.canCreateChar(name)) {
return -1; return -1;
} }
Character newchar = Character.getDefault(c); Character newchar = Character.getDefault(c);
newchar.setWorld(c.getWorld()); newchar.setWorld(c.getWorld());
newchar.setSkinColor(SkinColor.getById(skin)); newchar.setSkinColor(SkinColor.getById(skin));
newchar.setGender(gender); newchar.setGender(gender);
newchar.setName(name); newchar.setName(name);
newchar.setHair(hair); newchar.setHair(hair);
newchar.setFace(face); newchar.setFace(face);
newchar.setLevel(recipe.getLevel()); newchar.setLevel(recipe.getLevel());
newchar.setJob(recipe.getJob()); newchar.setJob(recipe.getJob());
newchar.setMapId(recipe.getMap()); newchar.setMapId(recipe.getMap());
Inventory equipped = newchar.getInventory(InventoryType.EQUIPPED); Inventory equipped = newchar.getInventory(InventoryType.EQUIPPED);
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
int top = recipe.getTop(), bottom = recipe.getBottom(), shoes = recipe.getShoes(), weapon = recipe.getWeapon(); int top = recipe.getTop(), bottom = recipe.getBottom(), shoes = recipe.getShoes(), weapon = recipe.getWeapon();
if(top > 0) { if (top > 0) {
Item eq_top = ii.getEquipById(top); Item eq_top = ii.getEquipById(top);
eq_top.setPosition((byte) -5); eq_top.setPosition((byte) -5);
equipped.addItemFromDB(eq_top); equipped.addItemFromDB(eq_top);
} }
if(bottom > 0) { if (bottom > 0) {
Item eq_bottom = ii.getEquipById(bottom); Item eq_bottom = ii.getEquipById(bottom);
eq_bottom.setPosition((byte) -6); eq_bottom.setPosition((byte) -6);
equipped.addItemFromDB(eq_bottom); equipped.addItemFromDB(eq_bottom);
} }
if(shoes > 0) { if (shoes > 0) {
Item eq_shoes = ii.getEquipById(shoes); Item eq_shoes = ii.getEquipById(shoes);
eq_shoes.setPosition((byte) -7); eq_shoes.setPosition((byte) -7);
equipped.addItemFromDB(eq_shoes); equipped.addItemFromDB(eq_shoes);
} }
if(weapon > 0) { if (weapon > 0) {
Item eq_weapon = ii.getEquipById(weapon); Item eq_weapon = ii.getEquipById(weapon);
eq_weapon.setPosition((byte) -11); eq_weapon.setPosition((byte) -11);
equipped.addItemFromDB(eq_weapon.copy()); equipped.addItemFromDB(eq_weapon.copy());
} }
if (!newchar.insertNewChar(recipe)) { if (!newchar.insertNewChar(recipe)) {
return -2; return -2;
} }
c.sendPacket(PacketCreator.addNewCharEntry(newchar)); c.sendPacket(PacketCreator.addNewCharEntry(newchar));
Server.getInstance().createCharacterEntry(newchar); Server.getInstance().createCharacterEntry(newchar);
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.sendYellowTip("[New Char]: " + c.getAccountName() + " has created a new character with IGN " + name)); Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.sendYellowTip("[New Char]: " + c.getAccountName() + " has created a new character with IGN " + name));
FilePrinter.print(FilePrinter.CREATED_CHAR + c.getAccountName() + ".txt", c.getAccountName() + " created character with IGN " + name); FilePrinter.print(FilePrinter.CREATED_CHAR + c.getAccountName() + ".txt", c.getAccountName() + " created character with IGN " + name);
return 0; return 0;
} }
} }

View File

@@ -33,21 +33,25 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class CharacterFactoryRecipe { public class CharacterFactoryRecipe {
private Job job; private final Job job;
private int level, map, top, bottom, shoes, weapon; private final int level;
private final int map;
private final int top;
private final int bottom;
private final int shoes;
private final int weapon;
private int str = 4, dex = 4, int_ = 4, luk = 4; private int str = 4, dex = 4, int_ = 4, luk = 4;
private int maxHp = 50, maxMp = 5; private int maxHp = 50, maxMp = 5;
private int ap = 0, sp = 0; private int ap = 0, sp = 0;
private int meso = 0; private int meso = 0;
private List<Pair<Skill, Integer>> skills = new LinkedList<>(); private final List<Pair<Skill, Integer>> skills = new LinkedList<>();
private List<Pair<Item, InventoryType>> itemsWithType = new LinkedList<>(); private final List<Pair<Item, InventoryType>> itemsWithType = new LinkedList<>();
private Map<InventoryType, AtomicInteger> runningTypePosition = new LinkedHashMap<>(); private final Map<InventoryType, AtomicInteger> runningTypePosition = new LinkedHashMap<>();
public CharacterFactoryRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) { public CharacterFactoryRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
this.job = job; this.job = job;
this.level = level; this.level = level;
@@ -56,7 +60,7 @@ public class CharacterFactoryRecipe {
this.bottom = bottom; this.bottom = bottom;
this.shoes = shoes; this.shoes = shoes;
this.weapon = weapon; this.weapon = weapon;
if (!YamlConfig.config.server.USE_STARTING_AP_4) { if (!YamlConfig.config.server.USE_STARTING_AP_4) {
if (YamlConfig.config.server.USE_AUTOASSIGN_STARTERS_AP) { if (YamlConfig.config.server.USE_AUTOASSIGN_STARTERS_AP) {
str = 12; str = 12;
@@ -66,129 +70,129 @@ public class CharacterFactoryRecipe {
} }
} }
} }
public void setStr(int v) { public void setStr(int v) {
str = v; str = v;
} }
public void setDex(int v) { public void setDex(int v) {
dex = v; dex = v;
} }
public void setInt(int v) { public void setInt(int v) {
int_ = v; int_ = v;
} }
public void setLuk(int v) { public void setLuk(int v) {
luk = v; luk = v;
} }
public void setMaxHp(int v) { public void setMaxHp(int v) {
maxHp = v; maxHp = v;
} }
public void setMaxMp(int v) { public void setMaxMp(int v) {
maxMp = v; maxMp = v;
} }
public void setRemainingAp(int v) { public void setRemainingAp(int v) {
ap = v; ap = v;
} }
public void setRemainingSp(int v) { public void setRemainingSp(int v) {
sp = v; sp = v;
} }
public void setMeso(int v) { public void setMeso(int v) {
meso = v; meso = v;
} }
public void addStartingSkillLevel(Skill skill, int level) { public void addStartingSkillLevel(Skill skill, int level) {
skills.add(new Pair<>(skill, level)); skills.add(new Pair<>(skill, level));
} }
public void addStartingEquipment(Item eqpItem) { public void addStartingEquipment(Item eqpItem) {
itemsWithType.add(new Pair<>(eqpItem, InventoryType.EQUIP)); itemsWithType.add(new Pair<>(eqpItem, InventoryType.EQUIP));
} }
public void addStartingItem(int itemid, int quantity, InventoryType itemType) { public void addStartingItem(int itemid, int quantity, InventoryType itemType) {
AtomicInteger p = runningTypePosition.get(itemType); AtomicInteger p = runningTypePosition.get(itemType);
if(p == null) { if (p == null) {
p = new AtomicInteger(0); p = new AtomicInteger(0);
runningTypePosition.put(itemType, p); runningTypePosition.put(itemType, p);
} }
itemsWithType.add(new Pair<>(new Item(itemid, (short) p.getAndIncrement(), (short) quantity), itemType)); itemsWithType.add(new Pair<>(new Item(itemid, (short) p.getAndIncrement(), (short) quantity), itemType));
} }
public Job getJob() { public Job getJob() {
return job; return job;
} }
public int getLevel() { public int getLevel() {
return level; return level;
} }
public int getMap() { public int getMap() {
return map; return map;
} }
public int getTop() { public int getTop() {
return top; return top;
} }
public int getBottom() { public int getBottom() {
return bottom; return bottom;
} }
public int getShoes() { public int getShoes() {
return shoes; return shoes;
} }
public int getWeapon() { public int getWeapon() {
return weapon; return weapon;
} }
public int getStr() { public int getStr() {
return str; return str;
} }
public int getDex() { public int getDex() {
return dex; return dex;
} }
public int getInt() { public int getInt() {
return int_; return int_;
} }
public int getLuk() { public int getLuk() {
return luk; return luk;
} }
public int getMaxHp() { public int getMaxHp() {
return maxHp; return maxHp;
} }
public int getMaxMp() { public int getMaxMp() {
return maxMp; return maxMp;
} }
public int getRemainingAp() { public int getRemainingAp() {
return ap; return ap;
} }
public int getRemainingSp() { public int getRemainingSp() {
return sp; return sp;
} }
public int getMeso() { public int getMeso() {
return meso; return meso;
} }
public List<Pair<Skill, Integer>> getStartingSkillLevel() { public List<Pair<Skill, Integer>> getStartingSkillLevel() {
return skills; return skills;
} }
public List<Pair<Item, InventoryType>> getStartingItems() { public List<Pair<Item, InventoryType>> getStartingItems() {
return itemsWithType; return itemsWithType;
} }

View File

@@ -26,23 +26,22 @@ import client.creator.CharacterFactoryRecipe;
import client.inventory.InventoryType; import client.inventory.InventoryType;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class BeginnerCreator extends CharacterFactory { public class BeginnerCreator extends CharacterFactory {
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) { private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
giveItem(recipe, 4161001, 1, InventoryType.ETC); giveItem(recipe, 4161001, 1, InventoryType.ETC);
return recipe; return recipe;
} }
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) { private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType); recipe.addStartingItem(itemid, quantity, itemType);
} }
public static int createCharacter(Client c, String name, int face, int hair, int skin, int top, int bottom, int shoes, int weapon, int gender) { public static int createCharacter(Client c, String name, int face, int hair, int skin, int top, int bottom, int shoes, int weapon, int gender) {
int status = createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.BEGINNER, 1, 10000, top, bottom, shoes, weapon)); int status = createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.BEGINNER, 1, 10000, top, bottom, shoes, weapon));
return status; return status;
} }
} }

View File

@@ -26,23 +26,22 @@ import client.creator.CharacterFactoryRecipe;
import client.inventory.InventoryType; import client.inventory.InventoryType;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class LegendCreator extends CharacterFactory { public class LegendCreator extends CharacterFactory {
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) { private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
giveItem(recipe, 4161048, 1, InventoryType.ETC); giveItem(recipe, 4161048, 1, InventoryType.ETC);
return recipe; return recipe;
} }
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) { private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType); recipe.addStartingItem(itemid, quantity, itemType);
} }
public static int createCharacter(Client c, String name, int face, int hair, int skin, int top, int bottom, int shoes, int weapon, int gender) { public static int createCharacter(Client c, String name, int face, int hair, int skin, int top, int bottom, int shoes, int weapon, int gender) {
int status = createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.LEGEND, 1, 914000000, top, bottom, shoes, weapon)); int status = createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.LEGEND, 1, 914000000, top, bottom, shoes, weapon));
return status; return status;
} }
} }

View File

@@ -26,23 +26,22 @@ import client.creator.CharacterFactoryRecipe;
import client.inventory.InventoryType; import client.inventory.InventoryType;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class NoblesseCreator extends CharacterFactory { public class NoblesseCreator extends CharacterFactory {
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) { private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
giveItem(recipe, 4161047, 1, InventoryType.ETC); giveItem(recipe, 4161047, 1, InventoryType.ETC);
return recipe; return recipe;
} }
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) { private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType); recipe.addStartingItem(itemid, quantity, itemType);
} }
public static int createCharacter(Client c, String name, int face, int hair, int skin, int top, int bottom, int shoes, int weapon, int gender) { public static int createCharacter(Client c, String name, int face, int hair, int skin, int top, int bottom, int shoes, int weapon, int gender) {
int status = createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.NOBLESSE, 1, 130030000, top, bottom, shoes, weapon)); int status = createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.NOBLESSE, 1, 130030000, top, bottom, shoes, weapon));
return status; return status;
} }
} }

View File

@@ -28,48 +28,47 @@ import client.inventory.Item;
import server.ItemInformationProvider; import server.ItemInformationProvider;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class BowmanCreator extends CharacterFactory { public class BowmanCreator extends CharacterFactory {
private static int[] equips = {1040067, 1041054, 1060056, 1061050, 1072081}; private static final int[] equips = {1040067, 1041054, 1060056, 1061050, 1072081};
private static int[] weapons = {1452005, 1462000}; private static final int[] weapons = {1452005, 1462000};
private static int[] startingHpMp = {797, 404}; private static final int[] startingHpMp = {797, 404};
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setDex(25);
recipe.setRemainingAp(133);
recipe.setRemainingSp(61);
recipe.setMaxHp(startingHpMp[0]); private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
recipe.setMaxMp(startingHpMp[1]); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setMeso(100000);
for(int i = 1; i < weapons.length; i++) { recipe.setDex(25);
giveEquipment(recipe, ii, weapons[i]); recipe.setRemainingAp(133);
} recipe.setRemainingSp(61);
giveItem(recipe, 2000002, 100, InventoryType.USE); recipe.setMaxHp(startingHpMp[0]);
giveItem(recipe, 2000003, 100, InventoryType.USE); recipe.setMaxMp(startingHpMp[1]);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
recipe.setMeso(100000);
return recipe;
} for (int i = 1; i < weapons.length; i++) {
giveEquipment(recipe, ii, weapons[i]);
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) {
Item nEquip = ii.getEquipById(equipid);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.BOWMAN, 30, 100000000, equips[gender], equips[2 + gender], equips[4], weapons[0]));
} }
giveItem(recipe, 2000002, 100, InventoryType.USE);
giveItem(recipe, 2000003, 100, InventoryType.USE);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
return recipe;
}
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) {
Item nEquip = ii.getEquipById(equipid);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.BOWMAN, 30, 100000000, equips[gender], equips[2 + gender], equips[4], weapons[0]));
}
} }

View File

@@ -31,68 +31,67 @@ import constants.skills.Magician;
import server.ItemInformationProvider; import server.ItemInformationProvider;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class MagicianCreator extends CharacterFactory { public class MagicianCreator extends CharacterFactory {
private static int[] equips = {0, 1041041, 0, 1061034, 1072075}; private static final int[] equips = {0, 1041041, 0, 1061034, 1072075};
private static int[] weapons = {1372003, 1382017}; private static final int[] weapons = {1372003, 1382017};
private static int[] startingHpMp = {405, 729}; private static final int[] startingHpMp = {405, 729};
private static int[] mpGain = {0, 40, 80, 118, 156, 194, 230, 266, 302, 336, 370}; private static final int[] mpGain = {0, 40, 80, 118, 156, 194, 230, 266, 302, 336, 370};
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon, int gender, int improveSp) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setInt(20);
recipe.setRemainingAp(138);
recipe.setRemainingSp(67);
recipe.setMaxHp(startingHpMp[0]); private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon, int gender, int improveSp) {
recipe.setMaxMp(startingHpMp[1] + mpGain[improveSp]); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setMeso(100000);
if(gender == 0) {
giveEquipment(recipe, ii, 1050003);
}
for(int i = 1; i < weapons.length; i++) { recipe.setInt(20);
giveEquipment(recipe, ii, weapons[i]); recipe.setRemainingAp(138);
} recipe.setRemainingSp(67);
giveItem(recipe, 2000001, 100, InventoryType.USE); recipe.setMaxHp(startingHpMp[0]);
giveItem(recipe, 2000006, 100, InventoryType.USE); recipe.setMaxMp(startingHpMp[1] + mpGain[improveSp]);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
if(improveSp > 0) {
improveSp += 5;
recipe.setRemainingSp(recipe.getRemainingSp() - improveSp);
int toUseSp = 5; recipe.setMeso(100000);
Skill improveMpRec = SkillFactory.getSkill(Magician.IMPROVED_MP_RECOVERY);
recipe.addStartingSkillLevel(improveMpRec, toUseSp);
improveSp -= toUseSp;
if(improveSp > 0) { if (gender == 0) {
Skill improveMaxMp = SkillFactory.getSkill(Magician.IMPROVED_MAX_MP_INCREASE); giveEquipment(recipe, ii, 1050003);
recipe.addStartingSkillLevel(improveMaxMp, improveSp);
}
}
return recipe;
} }
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) { for (int i = 1; i < weapons.length; i++) {
Item nEquip = ii.getEquipById(equipid); giveEquipment(recipe, ii, weapons[i]);
recipe.addStartingEquipment(nEquip);
} }
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) { giveItem(recipe, 2000001, 100, InventoryType.USE);
recipe.addStartingItem(itemid, quantity, itemType); giveItem(recipe, 2000006, 100, InventoryType.USE);
} giveItem(recipe, 3010000, 1, InventoryType.SETUP);
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) { if (improveSp > 0) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.MAGICIAN, 30, 101000000, equips[gender], equips[2 + gender], equips[4], weapons[0], gender, improveSp)); improveSp += 5;
recipe.setRemainingSp(recipe.getRemainingSp() - improveSp);
int toUseSp = 5;
Skill improveMpRec = SkillFactory.getSkill(Magician.IMPROVED_MP_RECOVERY);
recipe.addStartingSkillLevel(improveMpRec, toUseSp);
improveSp -= toUseSp;
if (improveSp > 0) {
Skill improveMaxMp = SkillFactory.getSkill(Magician.IMPROVED_MAX_MP_INCREASE);
recipe.addStartingSkillLevel(improveMaxMp, improveSp);
}
} }
return recipe;
}
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) {
Item nEquip = ii.getEquipById(equipid);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.MAGICIAN, 30, 101000000, equips[gender], equips[2 + gender], equips[4], weapons[0], gender, improveSp));
}
} }

View File

@@ -28,52 +28,51 @@ import client.inventory.Item;
import server.ItemInformationProvider; import server.ItemInformationProvider;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class PirateCreator extends CharacterFactory { public class PirateCreator extends CharacterFactory {
private static int[] equips = {0, 0, 0, 0, 1072294}; private static final int[] equips = {0, 0, 0, 0, 1072294};
private static int[] weapons = {1482004, 1492004}; private static final int[] weapons = {1482004, 1492004};
private static int[] startingHpMp = {846, 503}; private static final int[] startingHpMp = {846, 503};
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setDex(20);
recipe.setRemainingAp(138);
recipe.setRemainingSp(61);
recipe.setMaxHp(startingHpMp[0]); private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
recipe.setMaxMp(startingHpMp[1]); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setMeso(100000);
giveEquipment(recipe, ii, 1052107);
for(int i = 1; i < weapons.length; i++) { recipe.setDex(20);
giveEquipment(recipe, ii, weapons[i]); recipe.setRemainingAp(138);
} recipe.setRemainingSp(61);
giveItem(recipe, 2330000, 800, InventoryType.USE);
giveItem(recipe, 2000002, 100, InventoryType.USE); recipe.setMaxHp(startingHpMp[0]);
giveItem(recipe, 2000003, 100, InventoryType.USE); recipe.setMaxMp(startingHpMp[1]);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
recipe.setMeso(100000);
return recipe;
} giveEquipment(recipe, ii, 1052107);
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) { for (int i = 1; i < weapons.length; i++) {
Item nEquip = ii.getEquipById(equipid); giveEquipment(recipe, ii, weapons[i]);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.PIRATE, 30, 120000000, equips[gender], equips[2 + gender], equips[4], weapons[0]));
} }
giveItem(recipe, 2330000, 800, InventoryType.USE);
giveItem(recipe, 2000002, 100, InventoryType.USE);
giveItem(recipe, 2000003, 100, InventoryType.USE);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
return recipe;
}
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) {
Item nEquip = ii.getEquipById(equipid);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.PIRATE, 30, 120000000, equips[gender], equips[2 + gender], equips[4], weapons[0]));
}
} }

View File

@@ -28,50 +28,49 @@ import client.inventory.Item;
import server.ItemInformationProvider; import server.ItemInformationProvider;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class ThiefCreator extends CharacterFactory { public class ThiefCreator extends CharacterFactory {
private static int[] equips = {1040057, 1041047, 1060043, 1061043, 1072032}; private static final int[] equips = {1040057, 1041047, 1060043, 1061043, 1072032};
private static int[] weapons = {1472008, 1332012}; private static final int[] weapons = {1472008, 1332012};
private static int[] startingHpMp = {794, 407}; private static final int[] startingHpMp = {794, 407};
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setDex(25);
recipe.setRemainingAp(133);
recipe.setRemainingSp(61);
recipe.setMaxHp(startingHpMp[0]); private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon) {
recipe.setMaxMp(startingHpMp[1]); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setMeso(100000);
for(int i = 1; i < weapons.length; i++) { recipe.setDex(25);
giveEquipment(recipe, ii, weapons[i]); recipe.setRemainingAp(133);
} recipe.setRemainingSp(61);
giveItem(recipe, 2070000, 500, InventoryType.USE);
giveItem(recipe, 2000002, 100, InventoryType.USE); recipe.setMaxHp(startingHpMp[0]);
giveItem(recipe, 2000003, 100, InventoryType.USE); recipe.setMaxMp(startingHpMp[1]);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
recipe.setMeso(100000);
return recipe;
} for (int i = 1; i < weapons.length; i++) {
giveEquipment(recipe, ii, weapons[i]);
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) {
Item nEquip = ii.getEquipById(equipid);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.THIEF, 30, 103000000, equips[gender], equips[2 + gender], equips[4], weapons[0]));
} }
giveItem(recipe, 2070000, 500, InventoryType.USE);
giveItem(recipe, 2000002, 100, InventoryType.USE);
giveItem(recipe, 2000003, 100, InventoryType.USE);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
return recipe;
}
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) {
Item nEquip = ii.getEquipById(equipid);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.THIEF, 30, 103000000, equips[gender], equips[2 + gender], equips[4], weapons[0]));
}
} }

View File

@@ -31,68 +31,67 @@ import constants.skills.Warrior;
import server.ItemInformationProvider; import server.ItemInformationProvider;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class WarriorCreator extends CharacterFactory { public class WarriorCreator extends CharacterFactory {
private static int[] equips = {1040021, 0, 1060016, 0, 1072039}; private static final int[] equips = {1040021, 0, 1060016, 0, 1072039};
private static int[] weapons = {1302008, 1442001, 1422001, 1312005}; private static final int[] weapons = {1302008, 1442001, 1422001, 1312005};
private static int[] startingHpMp = {905, 208}; private static final int[] startingHpMp = {905, 208};
private static int[] hpGain = {0, 72, 144, 212, 280, 348, 412, 476, 540, 600, 660}; private static final int[] hpGain = {0, 72, 144, 212, 280, 348, 412, 476, 540, 600, 660};
private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon, int gender, int improveSp) {
CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setStr(35);
recipe.setRemainingAp(123);
recipe.setRemainingSp(61);
recipe.setMaxHp(startingHpMp[0] + hpGain[improveSp]); private static CharacterFactoryRecipe createRecipe(Job job, int level, int map, int top, int bottom, int shoes, int weapon, int gender, int improveSp) {
recipe.setMaxMp(startingHpMp[1]); CharacterFactoryRecipe recipe = new CharacterFactoryRecipe(job, level, map, top, bottom, shoes, weapon);
ItemInformationProvider ii = ItemInformationProvider.getInstance();
recipe.setMeso(100000);
if(gender == 1) {
giveEquipment(recipe, ii, 1051010);
}
for(int i = 1; i < weapons.length; i++) { recipe.setStr(35);
giveEquipment(recipe, ii, weapons[i]); recipe.setRemainingAp(123);
} recipe.setRemainingSp(61);
if(improveSp > 0) {
improveSp += 5;
recipe.setRemainingSp(recipe.getRemainingSp() - improveSp);
int toUseSp = 5; recipe.setMaxHp(startingHpMp[0] + hpGain[improveSp]);
Skill improveHpRec = SkillFactory.getSkill(Warrior.IMPROVED_HPREC); recipe.setMaxMp(startingHpMp[1]);
recipe.addStartingSkillLevel(improveHpRec, toUseSp);
improveSp -= toUseSp;
if(improveSp > 0) { recipe.setMeso(100000);
Skill improveMaxHp = SkillFactory.getSkill(Warrior.IMPROVED_MAXHP);
recipe.addStartingSkillLevel(improveMaxHp, improveSp);
}
}
giveItem(recipe, 2000002, 100, InventoryType.USE); if (gender == 1) {
giveItem(recipe, 2000003, 100, InventoryType.USE); giveEquipment(recipe, ii, 1051010);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
return recipe;
} }
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) { for (int i = 1; i < weapons.length; i++) {
Item nEquip = ii.getEquipById(equipid); giveEquipment(recipe, ii, weapons[i]);
recipe.addStartingEquipment(nEquip);
} }
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) { if (improveSp > 0) {
recipe.addStartingItem(itemid, quantity, itemType); improveSp += 5;
} recipe.setRemainingSp(recipe.getRemainingSp() - improveSp);
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) { int toUseSp = 5;
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.WARRIOR, 30, 102000000, equips[gender], equips[2 + gender], equips[4], weapons[0], gender, improveSp)); Skill improveHpRec = SkillFactory.getSkill(Warrior.IMPROVED_HPREC);
recipe.addStartingSkillLevel(improveHpRec, toUseSp);
improveSp -= toUseSp;
if (improveSp > 0) {
Skill improveMaxHp = SkillFactory.getSkill(Warrior.IMPROVED_MAXHP);
recipe.addStartingSkillLevel(improveMaxHp, improveSp);
}
} }
giveItem(recipe, 2000002, 100, InventoryType.USE);
giveItem(recipe, 2000003, 100, InventoryType.USE);
giveItem(recipe, 3010000, 1, InventoryType.SETUP);
return recipe;
}
private static void giveEquipment(CharacterFactoryRecipe recipe, ItemInformationProvider ii, int equipid) {
Item nEquip = ii.getEquipById(equipid);
recipe.addStartingEquipment(nEquip);
}
private static void giveItem(CharacterFactoryRecipe recipe, int itemid, int quantity, InventoryType itemType) {
recipe.addStartingItem(itemid, quantity, itemType);
}
public static int createCharacter(Client c, String name, int face, int hair, int skin, int gender, int improveSp) {
return createNewCharacter(c, name, face, hair, skin, gender, createRecipe(Job.WARRIOR, 30, 102000000, equips[gender], equips[2 + gender], equips[4], weapons[0], gender, improveSp));
}
} }

View File

@@ -37,12 +37,12 @@ import java.util.Map;
public class Equip extends Item { public class Equip extends Item {
public static enum ScrollResult { public enum ScrollResult {
FAIL(0), SUCCESS(1), CURSE(2); FAIL(0), SUCCESS(1), CURSE(2);
private int value = -1; private int value = -1;
private ScrollResult(int value) { ScrollResult(int value) {
this.value = value; this.value = value;
} }
@@ -50,8 +50,8 @@ public class Equip extends Item {
return value; return value;
} }
} }
public static enum StatUpgrade { public enum StatUpgrade {
incDEX(0), incSTR(1), incINT(2), incLUK(3), incDEX(0), incSTR(1), incINT(2), incLUK(3),
incMHP(4), incMMP(5), incPAD(6), incMAD(7), incMHP(4), incMMP(5), incPAD(6), incMAD(7),
@@ -59,11 +59,11 @@ public class Equip extends Item {
incSpeed(12), incJump(13), incVicious(14), incSlot(15); incSpeed(12), incJump(13), incVicious(14), incSlot(15);
private int value = -1; private int value = -1;
private StatUpgrade(int value) { StatUpgrade(int value) {
this.value = value; this.value = value;
} }
} }
private byte upgradeSlots; private byte upgradeSlots;
private byte level, itemLevel; private byte level, itemLevel;
private short flag; private short flag;
@@ -82,7 +82,7 @@ public class Equip extends Item {
this.upgradeSlots = (byte) slots; this.upgradeSlots = (byte) slots;
this.itemExp = 0; this.itemExp = 0;
this.itemLevel = 1; this.itemLevel = 1;
this.isElemental = (ItemInformationProvider.getInstance().getEquipLevel(id, false) > 1); this.isElemental = (ItemInformationProvider.getInstance().getEquipLevel(id, false) > 1);
} }
@@ -127,7 +127,7 @@ public class Equip extends Item {
public byte getItemType() { public byte getItemType() {
return 1; return 1;
} }
public byte getUpgradeSlots() { public byte getUpgradeSlots() {
return upgradeSlots; return upgradeSlots;
} }
@@ -279,108 +279,167 @@ public class Equip extends Item {
private static int getStatModifier(boolean isAttribute) { private static int getStatModifier(boolean isAttribute) {
// each set of stat points grants a chance for a bonus stat point upgrade at equip level up. // each set of stat points grants a chance for a bonus stat point upgrade at equip level up.
if(YamlConfig.config.server.USE_EQUIPMNT_LVLUP_POWER) { if (YamlConfig.config.server.USE_EQUIPMNT_LVLUP_POWER) {
if(isAttribute) return 2; if (isAttribute) {
else return 4; return 2;
} } else {
else { return 4;
if(isAttribute) return 4; }
else return 16; } else {
if (isAttribute) {
return 4;
} else {
return 16;
}
} }
} }
private static int randomizeStatUpgrade(int top) { private static int randomizeStatUpgrade(int top) {
int limit = Math.min(top, YamlConfig.config.server.MAX_EQUIPMNT_LVLUP_STAT_UP); int limit = Math.min(top, YamlConfig.config.server.MAX_EQUIPMNT_LVLUP_STAT_UP);
int poolCount = (limit * (limit + 1) / 2) + limit; int poolCount = (limit * (limit + 1) / 2) + limit;
int rnd = Randomizer.rand(0, poolCount); int rnd = Randomizer.rand(0, poolCount);
int stat = 0; int stat = 0;
if(rnd >= limit) { if (rnd >= limit) {
rnd -= limit; rnd -= limit;
stat = 1 + (int)Math.floor((-1 + Math.sqrt((8 * rnd) + 1)) / 2); // optimized randomizeStatUpgrade author: David A. stat = 1 + (int) Math.floor((-1 + Math.sqrt((8 * rnd) + 1)) / 2); // optimized randomizeStatUpgrade author: David A.
} }
return stat; return stat;
} }
private static boolean isPhysicalWeapon(int itemid) { private static boolean isPhysicalWeapon(int itemid) {
Equip eqp = (Equip) ItemInformationProvider.getInstance().getEquipById(itemid); Equip eqp = (Equip) ItemInformationProvider.getInstance().getEquipById(itemid);
return eqp.getWatk() >= eqp.getMatk(); return eqp.getWatk() >= eqp.getMatk();
} }
private boolean isNotWeaponAffinity(StatUpgrade name) { private boolean isNotWeaponAffinity(StatUpgrade name) {
// Vcoc's idea - WATK/MATK expected gains lessens outside of weapon affinity (physical/magic) // Vcoc's idea - WATK/MATK expected gains lessens outside of weapon affinity (physical/magic)
if (ItemConstants.isWeapon(this.getItemId())) { if (ItemConstants.isWeapon(this.getItemId())) {
if (name.equals(StatUpgrade.incPAD)) { if (name.equals(StatUpgrade.incPAD)) {
if (!isPhysicalWeapon(this.getItemId())) { return !isPhysicalWeapon(this.getItemId());
return true;
}
} else if (name.equals(StatUpgrade.incMAD)) { } else if (name.equals(StatUpgrade.incMAD)) {
if (isPhysicalWeapon(this.getItemId())) { return isPhysicalWeapon(this.getItemId());
return true;
}
} }
} }
return false; return false;
} }
private void getUnitStatUpgrade(List<Pair<StatUpgrade, Integer>> stats, StatUpgrade name, int curStat, boolean isAttribute) { private void getUnitStatUpgrade(List<Pair<StatUpgrade, Integer>> stats, StatUpgrade name, int curStat, boolean isAttribute) {
isUpgradeable = true; isUpgradeable = true;
int maxUpgrade = randomizeStatUpgrade((int)(1 + (curStat / (getStatModifier(isAttribute) * (isNotWeaponAffinity(name) ? 2.7 : 1))))); int maxUpgrade = randomizeStatUpgrade((int) (1 + (curStat / (getStatModifier(isAttribute) * (isNotWeaponAffinity(name) ? 2.7 : 1)))));
if(maxUpgrade == 0) return; if (maxUpgrade == 0) {
return;
}
stats.add(new Pair<>(name, maxUpgrade)); stats.add(new Pair<>(name, maxUpgrade));
} }
private static void getUnitSlotUpgrade(List<Pair<StatUpgrade, Integer>> stats, StatUpgrade name) { private static void getUnitSlotUpgrade(List<Pair<StatUpgrade, Integer>> stats, StatUpgrade name) {
if(Math.random() < 0.1) { if (Math.random() < 0.1) {
stats.add(new Pair<>(name, 1)); // 10% success on getting a slot upgrade. stats.add(new Pair<>(name, 1)); // 10% success on getting a slot upgrade.
} }
} }
private void improveDefaultStats(List<Pair<StatUpgrade, Integer>> stats) { private void improveDefaultStats(List<Pair<StatUpgrade, Integer>> stats) {
if(dex > 0) getUnitStatUpgrade(stats, StatUpgrade.incDEX, dex, true); if (dex > 0) {
if(str > 0) getUnitStatUpgrade(stats, StatUpgrade.incSTR, str, true); getUnitStatUpgrade(stats, StatUpgrade.incDEX, dex, true);
if(_int > 0) getUnitStatUpgrade(stats, StatUpgrade.incINT,_int, true); }
if(luk > 0) getUnitStatUpgrade(stats, StatUpgrade.incLUK, luk, true); if (str > 0) {
if(hp > 0) getUnitStatUpgrade(stats, StatUpgrade.incMHP, hp, false); getUnitStatUpgrade(stats, StatUpgrade.incSTR, str, true);
if(mp > 0) getUnitStatUpgrade(stats, StatUpgrade.incMMP, mp, false); }
if(watk > 0) getUnitStatUpgrade(stats, StatUpgrade.incPAD, watk, false); if (_int > 0) {
if(matk > 0) getUnitStatUpgrade(stats, StatUpgrade.incMAD, matk, false); getUnitStatUpgrade(stats, StatUpgrade.incINT, _int, true);
if(wdef > 0) getUnitStatUpgrade(stats, StatUpgrade.incPDD, wdef, false); }
if(mdef > 0) getUnitStatUpgrade(stats, StatUpgrade.incMDD, mdef, false); if (luk > 0) {
if(avoid > 0) getUnitStatUpgrade(stats, StatUpgrade.incEVA, avoid, false); getUnitStatUpgrade(stats, StatUpgrade.incLUK, luk, true);
if(acc > 0) getUnitStatUpgrade(stats, StatUpgrade.incACC, acc, false); }
if(speed > 0) getUnitStatUpgrade(stats, StatUpgrade.incSpeed, speed, false); if (hp > 0) {
if(jump > 0) getUnitStatUpgrade(stats, StatUpgrade.incJump, jump, false); getUnitStatUpgrade(stats, StatUpgrade.incMHP, hp, false);
}
if (mp > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incMMP, mp, false);
}
if (watk > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incPAD, watk, false);
}
if (matk > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incMAD, matk, false);
}
if (wdef > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incPDD, wdef, false);
}
if (mdef > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incMDD, mdef, false);
}
if (avoid > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incEVA, avoid, false);
}
if (acc > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incACC, acc, false);
}
if (speed > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incSpeed, speed, false);
}
if (jump > 0) {
getUnitStatUpgrade(stats, StatUpgrade.incJump, jump, false);
}
} }
public Map<StatUpgrade, Short> getStats() { public Map<StatUpgrade, Short> getStats() {
Map<StatUpgrade, Short> stats = new HashMap<>(5); Map<StatUpgrade, Short> stats = new HashMap<>(5);
if(dex > 0) stats.put(StatUpgrade.incDEX, dex); if (dex > 0) {
if(str > 0) stats.put(StatUpgrade.incSTR, str); stats.put(StatUpgrade.incDEX, dex);
if(_int > 0) stats.put(StatUpgrade.incINT,_int); }
if(luk > 0) stats.put(StatUpgrade.incLUK, luk); if (str > 0) {
if(hp > 0) stats.put(StatUpgrade.incMHP, hp); stats.put(StatUpgrade.incSTR, str);
if(mp > 0) stats.put(StatUpgrade.incMMP, mp); }
if(watk > 0) stats.put(StatUpgrade.incPAD, watk); if (_int > 0) {
if(matk > 0) stats.put(StatUpgrade.incMAD, matk); stats.put(StatUpgrade.incINT, _int);
if(wdef > 0) stats.put(StatUpgrade.incPDD, wdef); }
if(mdef > 0) stats.put(StatUpgrade.incMDD, mdef); if (luk > 0) {
if(avoid > 0) stats.put(StatUpgrade.incEVA, avoid); stats.put(StatUpgrade.incLUK, luk);
if(acc > 0) stats.put(StatUpgrade.incACC, acc); }
if(speed > 0) stats.put(StatUpgrade.incSpeed, speed); if (hp > 0) {
if(jump > 0) stats.put(StatUpgrade.incJump, jump); stats.put(StatUpgrade.incMHP, hp);
}
if (mp > 0) {
stats.put(StatUpgrade.incMMP, mp);
}
if (watk > 0) {
stats.put(StatUpgrade.incPAD, watk);
}
if (matk > 0) {
stats.put(StatUpgrade.incMAD, matk);
}
if (wdef > 0) {
stats.put(StatUpgrade.incPDD, wdef);
}
if (mdef > 0) {
stats.put(StatUpgrade.incMDD, mdef);
}
if (avoid > 0) {
stats.put(StatUpgrade.incEVA, avoid);
}
if (acc > 0) {
stats.put(StatUpgrade.incACC, acc);
}
if (speed > 0) {
stats.put(StatUpgrade.incSpeed, speed);
}
if (jump > 0) {
stats.put(StatUpgrade.incJump, jump);
}
return stats; return stats;
} }
public Pair<String, Pair<Boolean, Boolean>> gainStats(List<Pair<StatUpgrade, Integer>> stats) { public Pair<String, Pair<Boolean, Boolean>> gainStats(List<Pair<StatUpgrade, Integer>> stats) {
boolean gotSlot = false, gotVicious = false; boolean gotSlot = false, gotVicious = false;
String lvupStr = ""; String lvupStr = "";
@@ -457,7 +516,7 @@ public class Equip extends Item {
jump += statUp; jump += statUp;
lvupStr += "+" + statUp + "JUMP "; lvupStr += "+" + statUp + "JUMP ";
break; break;
case incVicious: case incVicious:
vicious -= stat.getRight(); vicious -= stat.getRight();
gotVicious = true; gotVicious = true;
@@ -468,56 +527,64 @@ public class Equip extends Item {
break; break;
} }
} }
return new Pair<>(lvupStr, new Pair<>(gotSlot, gotVicious)); return new Pair<>(lvupStr, new Pair<>(gotSlot, gotVicious));
} }
private void gainLevel(Client c) { private void gainLevel(Client c) {
List<Pair<StatUpgrade, Integer>> stats = new LinkedList<>(); List<Pair<StatUpgrade, Integer>> stats = new LinkedList<>();
if(isElemental) { if (isElemental) {
List<Pair<String, Integer>> elementalStats = ItemInformationProvider.getInstance().getItemLevelupStats(getItemId(), itemLevel); List<Pair<String, Integer>> elementalStats = ItemInformationProvider.getInstance().getItemLevelupStats(getItemId(), itemLevel);
for(Pair<String, Integer> p: elementalStats) { for (Pair<String, Integer> p : elementalStats) {
if(p.getRight() > 0) stats.add(new Pair<>(StatUpgrade.valueOf(p.getLeft()), p.getRight())); if (p.getRight() > 0) {
stats.add(new Pair<>(StatUpgrade.valueOf(p.getLeft()), p.getRight()));
}
} }
} }
if(!stats.isEmpty()) { if (!stats.isEmpty()) {
if(YamlConfig.config.server.USE_EQUIPMNT_LVLUP_SLOTS) { if (YamlConfig.config.server.USE_EQUIPMNT_LVLUP_SLOTS) {
if(vicious > 0) getUnitSlotUpgrade(stats, StatUpgrade.incVicious); if (vicious > 0) {
getUnitSlotUpgrade(stats, StatUpgrade.incVicious);
}
getUnitSlotUpgrade(stats, StatUpgrade.incSlot); getUnitSlotUpgrade(stats, StatUpgrade.incSlot);
} }
} else { } else {
isUpgradeable = false; isUpgradeable = false;
improveDefaultStats(stats); improveDefaultStats(stats);
if(YamlConfig.config.server.USE_EQUIPMNT_LVLUP_SLOTS) { if (YamlConfig.config.server.USE_EQUIPMNT_LVLUP_SLOTS) {
if(vicious > 0) getUnitSlotUpgrade(stats, StatUpgrade.incVicious); if (vicious > 0) {
getUnitSlotUpgrade(stats, StatUpgrade.incVicious);
}
getUnitSlotUpgrade(stats, StatUpgrade.incSlot); getUnitSlotUpgrade(stats, StatUpgrade.incSlot);
} }
if(isUpgradeable) { if (isUpgradeable) {
while(stats.isEmpty()) { while (stats.isEmpty()) {
improveDefaultStats(stats); improveDefaultStats(stats);
if(YamlConfig.config.server.USE_EQUIPMNT_LVLUP_SLOTS) { if (YamlConfig.config.server.USE_EQUIPMNT_LVLUP_SLOTS) {
if(vicious > 0) getUnitSlotUpgrade(stats, StatUpgrade.incVicious); if (vicious > 0) {
getUnitSlotUpgrade(stats, StatUpgrade.incVicious);
}
getUnitSlotUpgrade(stats, StatUpgrade.incSlot); getUnitSlotUpgrade(stats, StatUpgrade.incSlot);
} }
} }
} }
} }
itemLevel++; itemLevel++;
String lvupStr = "'" + ItemInformationProvider.getInstance().getName(this.getItemId()) + "' is now level " + itemLevel + "! "; String lvupStr = "'" + ItemInformationProvider.getInstance().getName(this.getItemId()) + "' is now level " + itemLevel + "! ";
String showStr = "#e'" + ItemInformationProvider.getInstance().getName(this.getItemId()) + "'#b is now #elevel #r" + itemLevel + "#k#b!"; String showStr = "#e'" + ItemInformationProvider.getInstance().getName(this.getItemId()) + "'#b is now #elevel #r" + itemLevel + "#k#b!";
Pair<String, Pair<Boolean, Boolean>> res = this.gainStats(stats); Pair<String, Pair<Boolean, Boolean>> res = this.gainStats(stats);
lvupStr += res.getLeft(); lvupStr += res.getLeft();
boolean gotSlot = res.getRight().getLeft(); boolean gotSlot = res.getRight().getLeft();
boolean gotVicious = res.getRight().getRight(); boolean gotVicious = res.getRight().getRight();
if (gotVicious) { if (gotVicious) {
//c.getPlayer().dropMessage(6, "A new Vicious Hammer opportunity has been found on the '" + ItemInformationProvider.getInstance().getName(getItemId()) + "'!"); //c.getPlayer().dropMessage(6, "A new Vicious Hammer opportunity has been found on the '" + ItemInformationProvider.getInstance().getName(getItemId()) + "'!");
lvupStr += "+VICIOUS "; lvupStr += "+VICIOUS ";
@@ -526,12 +593,12 @@ public class Equip extends Item {
//c.getPlayer().dropMessage(6, "A new upgrade slot has been found on the '" + ItemInformationProvider.getInstance().getName(getItemId()) + "'!"); //c.getPlayer().dropMessage(6, "A new upgrade slot has been found on the '" + ItemInformationProvider.getInstance().getName(getItemId()) + "'!");
lvupStr += "+UPGSLOT "; lvupStr += "+UPGSLOT ";
} }
c.getPlayer().equipChanged(); c.getPlayer().equipChanged();
showLevelupMessage(showStr, c); // thanks to Polaris dev team ! showLevelupMessage(showStr, c); // thanks to Polaris dev team !
c.getPlayer().dropMessage(6, lvupStr); c.getPlayer().dropMessage(6, lvupStr);
c.sendPacket(PacketCreator.showEquipmentLevelUp()); c.sendPacket(PacketCreator.showEquipmentLevelUp());
c.getPlayer().getMap().broadcastPacket(c.getPlayer(), PacketCreator.showForeignEffect(c.getPlayer().getId(), 15)); c.getPlayer().getMap().broadcastPacket(c.getPlayer(), PacketCreator.showForeignEffect(c.getPlayer().getId(), 15));
c.getPlayer().forceUpdateItem(this); c.getPlayer().forceUpdateItem(this);
@@ -540,89 +607,93 @@ public class Equip extends Item {
public int getItemExp() { public int getItemExp() {
return (int) itemExp; return (int) itemExp;
} }
private static double normalizedMasteryExp(int reqLevel) { private static double normalizedMasteryExp(int reqLevel) {
// Conversion factor between mob exp and equip exp gain. Through many calculations, the expected for equipment levelup // Conversion factor between mob exp and equip exp gain. Through many calculations, the expected for equipment levelup
// from level 1 to 2 is killing about 100~200 mobs of the same level range, on a 1x EXP rate scenario. // from level 1 to 2 is killing about 100~200 mobs of the same level range, on a 1x EXP rate scenario.
if(reqLevel < 5) { if (reqLevel < 5) {
return 42; return 42;
} else if(reqLevel >= 78) { } else if (reqLevel >= 78) {
return Math.max((10413.648 * Math.exp(reqLevel * 0.03275)), 15); return Math.max((10413.648 * Math.exp(reqLevel * 0.03275)), 15);
} else if(reqLevel >= 38) { } else if (reqLevel >= 38) {
return Math.max(( 4985.818 * Math.exp(reqLevel * 0.02007)), 15); return Math.max((4985.818 * Math.exp(reqLevel * 0.02007)), 15);
} else if(reqLevel >= 18) { } else if (reqLevel >= 18) {
return Math.max(( 248.219 * Math.exp(reqLevel * 0.11093)), 15); return Math.max((248.219 * Math.exp(reqLevel * 0.11093)), 15);
} else { } else {
return Math.max(((1334.564 * Math.log(reqLevel)) - 1731.976), 15); return Math.max(((1334.564 * Math.log(reqLevel)) - 1731.976), 15);
} }
} }
public synchronized void gainItemExp(Client c, int gain) { // Ronan's Equip Exp gain method public synchronized void gainItemExp(Client c, int gain) { // Ronan's Equip Exp gain method
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
if(!ii.isUpgradeable(this.getItemId())) { if (!ii.isUpgradeable(this.getItemId())) {
return; return;
} }
int equipMaxLevel = Math.min(30, Math.max(ii.getEquipLevel(this.getItemId(), true), YamlConfig.config.server.USE_EQUIPMNT_LVLUP)); int equipMaxLevel = Math.min(30, Math.max(ii.getEquipLevel(this.getItemId(), true), YamlConfig.config.server.USE_EQUIPMNT_LVLUP));
if (itemLevel >= equipMaxLevel) { if (itemLevel >= equipMaxLevel) {
return; return;
} }
int reqLevel = ii.getEquipLevelReq(this.getItemId()); int reqLevel = ii.getEquipLevelReq(this.getItemId());
float masteryModifier = (float)(YamlConfig.config.server.EQUIP_EXP_RATE * ExpTable.getExpNeededForLevel(1)) / (float)normalizedMasteryExp(reqLevel); float masteryModifier = (float) (YamlConfig.config.server.EQUIP_EXP_RATE * ExpTable.getExpNeededForLevel(1)) / (float) normalizedMasteryExp(reqLevel);
float elementModifier = (isElemental) ? 0.85f : 0.6f; float elementModifier = (isElemental) ? 0.85f : 0.6f;
float baseExpGain = gain * elementModifier * masteryModifier; float baseExpGain = gain * elementModifier * masteryModifier;
itemExp += baseExpGain; itemExp += baseExpGain;
int expNeeded = ExpTable.getEquipExpNeededForLevel(itemLevel); int expNeeded = ExpTable.getEquipExpNeededForLevel(itemLevel);
if(YamlConfig.config.server.USE_DEBUG_SHOW_INFO_EQPEXP) System.out.println("'" + ii.getName(this.getItemId()) + "' -> EXP Gain: " + gain + " Mastery: " + masteryModifier + " Base gain: " + baseExpGain + " exp: " + itemExp + " / " + expNeeded + ", Kills TNL: " + expNeeded / (baseExpGain / c.getPlayer().getExpRate())); if (YamlConfig.config.server.USE_DEBUG_SHOW_INFO_EQPEXP) {
System.out.println("'" + ii.getName(this.getItemId()) + "' -> EXP Gain: " + gain + " Mastery: " + masteryModifier + " Base gain: " + baseExpGain + " exp: " + itemExp + " / " + expNeeded + ", Kills TNL: " + expNeeded / (baseExpGain / c.getPlayer().getExpRate()));
}
if (itemExp >= expNeeded) { if (itemExp >= expNeeded) {
while(itemExp >= expNeeded) { while (itemExp >= expNeeded) {
itemExp -= expNeeded; itemExp -= expNeeded;
gainLevel(c); gainLevel(c);
if(itemLevel >= equipMaxLevel) { if (itemLevel >= equipMaxLevel) {
itemExp = 0.0f; itemExp = 0.0f;
break; break;
} }
expNeeded = ExpTable.getEquipExpNeededForLevel(itemLevel); expNeeded = ExpTable.getEquipExpNeededForLevel(itemLevel);
} }
} }
c.getPlayer().forceUpdateItem(this); c.getPlayer().forceUpdateItem(this);
//if(YamlConfig.config.server.USE_DEBUG) c.getPlayer().dropMessage("'" + ii.getName(this.getItemId()) + "': " + itemExp + " / " + expNeeded); //if(YamlConfig.config.server.USE_DEBUG) c.getPlayer().dropMessage("'" + ii.getName(this.getItemId()) + "': " + itemExp + " / " + expNeeded);
} }
private boolean reachedMaxLevel() { private boolean reachedMaxLevel() {
if (isElemental) { if (isElemental) {
if (itemLevel < ItemInformationProvider.getInstance().getEquipLevel(getItemId(), true)) { if (itemLevel < ItemInformationProvider.getInstance().getEquipLevel(getItemId(), true)) {
return false; return false;
} }
} }
return itemLevel >= YamlConfig.config.server.USE_EQUIPMNT_LVLUP; return itemLevel >= YamlConfig.config.server.USE_EQUIPMNT_LVLUP;
} }
public String showEquipFeatures(Client c) { public String showEquipFeatures(Client c) {
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
if(!ii.isUpgradeable(this.getItemId())) return ""; if (!ii.isUpgradeable(this.getItemId())) {
return "";
}
String eqpName = ii.getName(getItemId()); String eqpName = ii.getName(getItemId());
String eqpInfo = reachedMaxLevel() ? " #e#rMAX LEVEL#k#n" : (" EXP: #e#b" + (int)itemExp + "#k#n / " + ExpTable.getEquipExpNeededForLevel(itemLevel)); String eqpInfo = reachedMaxLevel() ? " #e#rMAX LEVEL#k#n" : (" EXP: #e#b" + (int) itemExp + "#k#n / " + ExpTable.getEquipExpNeededForLevel(itemLevel));
return "'" + eqpName + "' -> LV: #e#b" + itemLevel + "#k#n " + eqpInfo + "\r\n"; return "'" + eqpName + "' -> LV: #e#b" + itemLevel + "#k#n " + eqpInfo + "\r\n";
} }
private static void showLevelupMessage(String msg, Client c) { private static void showLevelupMessage(String msg, Client c) {
c.getPlayer().showHint(msg, 300); c.getPlayer().showHint(msg, 300);
} }
public void setItemExp(int exp) { public void setItemExp(int exp) {
this.itemExp = exp; this.itemExp = exp;
} }

View File

@@ -32,9 +32,11 @@ import java.util.concurrent.atomic.AtomicInteger;
public class Item implements Comparable<Item> { public class Item implements Comparable<Item> {
private static AtomicInteger runningCashId = new AtomicInteger(777000000); // pets & rings shares cashid values private static final AtomicInteger runningCashId = new AtomicInteger(777000000); // pets & rings shares cashid values
private int id, cashId, sn; private final int id;
private int cashId;
private int sn;
private short position; private short position;
private short quantity; private short quantity;
private int petid = -1; private int petid = -1;
@@ -79,7 +81,9 @@ public class Item implements Comparable<Item> {
public void setPosition(short position) { public void setPosition(short position) {
this.position = position; this.position = position;
if (this.pet != null) this.pet.setPosition(position); if (this.pet != null) {
this.pet.setPosition(position);
}
} }
public void setQuantity(short quantity) { public void setQuantity(short quantity) {
@@ -108,7 +112,7 @@ public class Item implements Comparable<Item> {
public InventoryType getInventoryType() { public InventoryType getInventoryType() {
return ItemConstants.getInventoryType(id); return ItemConstants.getInventoryType(id);
} }
public byte getItemType() { // 1: equip, 3: pet, 2: other public byte getItemType() { // 1: equip, 3: pet, 2: other
if (getPetId() > -1) { if (getPetId() > -1) {
return 3; return 3;
@@ -127,7 +131,7 @@ public class Item implements Comparable<Item> {
public int getPetId() { public int getPetId() {
return petid; return petid;
} }
@Override @Override
public int compareTo(Item other) { public int compareTo(Item other) {
if (this.id < other.getItemId()) { if (this.id < other.getItemId()) {
@@ -137,7 +141,7 @@ public class Item implements Comparable<Item> {
} }
return 0; return 0;
} }
@Override @Override
public String toString() { public String toString() {
return "Item: " + id + " quantity: " + quantity; return "Item: " + id + " quantity: " + quantity;
@@ -156,7 +160,7 @@ public class Item implements Comparable<Item> {
if (ii.isAccountRestricted(id)) { if (ii.isAccountRestricted(id)) {
b |= ItemConstants.ACCOUNT_SHARING; // thanks Shinigami15 for noticing ACCOUNT_SHARING flag not being applied properly to items server-side b |= ItemConstants.ACCOUNT_SHARING; // thanks Shinigami15 for noticing ACCOUNT_SHARING flag not being applied properly to items server-side
} }
this.flag = b; this.flag = b;
} }
@@ -187,7 +191,7 @@ public class Item implements Comparable<Item> {
public Pet getPet() { public Pet getPet() {
return pet; return pet;
} }
public boolean isUntradeable() { public boolean isUntradeable() {
return ((this.getFlag() & ItemConstants.UNTRADEABLE) == ItemConstants.UNTRADEABLE) || (ItemInformationProvider.getInstance().isDropRestricted(this.getItemId()) && !KarmaManipulator.hasKarmaFlag(this)); return ((this.getFlag() & ItemConstants.UNTRADEABLE) == ItemConstants.UNTRADEABLE) || (ItemInformationProvider.getInstance().isDropRestricted(this.getItemId()) && !KarmaManipulator.hasKarmaFlag(this));
} }

View File

@@ -31,7 +31,6 @@ import java.util.List;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
/** /**
*
* @author Flav * @author Flav
*/ */
public enum ItemFactory { public enum ItemFactory {
@@ -47,17 +46,17 @@ public enum ItemFactory {
DUEY(9, false); DUEY(9, false);
private final int value; private final int value;
private final boolean account; private final boolean account;
private static final int lockCount = 400; private static final int lockCount = 400;
private static final Lock[] locks = new Lock[lockCount]; // thanks Masterrulax for pointing out a bottleneck issue here private static final Lock[] locks = new Lock[lockCount]; // thanks Masterrulax for pointing out a bottleneck issue here
static { static {
for (int i = 0; i < lockCount; i++) { for (int i = 0; i < lockCount; i++) {
locks[i] = MonitoredReentrantLockFactory.createLock(MonitoredLockType.ITEM, true); locks[i] = MonitoredReentrantLockFactory.createLock(MonitoredLockType.ITEM, true);
} }
} }
private ItemFactory(int value, boolean account) { ItemFactory(int value, boolean account) {
this.value = value; this.value = value;
this.account = account; this.account = account;
} }
@@ -67,21 +66,27 @@ public enum ItemFactory {
} }
public List<Pair<Item, InventoryType>> loadItems(int id, boolean login) throws SQLException { public List<Pair<Item, InventoryType>> loadItems(int id, boolean login) throws SQLException {
if(value != 6) return loadItemsCommon(id, login); if (value != 6) {
else return loadItemsMerchant(id, login); return loadItemsCommon(id, login);
} else {
return loadItemsMerchant(id, login);
}
} }
public void saveItems(List<Pair<Item, InventoryType>> items, int id, Connection con) throws SQLException { public void saveItems(List<Pair<Item, InventoryType>> items, int id, Connection con) throws SQLException {
saveItems(items, null, id, con); saveItems(items, null, id, con);
} }
public void saveItems(List<Pair<Item, InventoryType>> items, List<Short> bundlesList, int id, Connection con) throws SQLException { public void saveItems(List<Pair<Item, InventoryType>> items, List<Short> bundlesList, int id, Connection con) throws SQLException {
// thanks Arufonsu, MedicOP, BHB for pointing a "synchronized" bottleneck here // thanks Arufonsu, MedicOP, BHB for pointing a "synchronized" bottleneck here
if(value != 6) saveItemsCommon(items, id, con); if (value != 6) {
else saveItemsMerchant(items, bundlesList, id, con); saveItemsCommon(items, id, con);
} else {
saveItemsMerchant(items, bundlesList, id, con);
}
} }
private static Equip loadEquipFromResultSet(ResultSet rs) throws SQLException { private static Equip loadEquipFromResultSet(ResultSet rs) throws SQLException {
Equip equip = new Equip(rs.getInt("itemid"), (short) rs.getInt("position")); Equip equip = new Equip(rs.getInt("itemid"), (short) rs.getInt("position"));
equip.setOwner(rs.getString("owner")); equip.setOwner(rs.getString("owner"));
@@ -110,13 +115,13 @@ public enum ItemFactory {
equip.setExpiration(rs.getLong("expiration")); equip.setExpiration(rs.getLong("expiration"));
equip.setGiftFrom(rs.getString("giftFrom")); equip.setGiftFrom(rs.getString("giftFrom"));
equip.setRingId(rs.getInt("ringid")); equip.setRingId(rs.getInt("ringid"));
return equip; return equip;
} }
public static List<Pair<Item, Integer>> loadEquippedItems(int id, boolean isAccount, boolean login) throws SQLException { public static List<Pair<Item, Integer>> loadEquippedItems(int id, boolean isAccount, boolean login) throws SQLException {
List<Pair<Item, Integer>> items = new ArrayList<>(); List<Pair<Item, Integer>> items = new ArrayList<>();
StringBuilder query = new StringBuilder(); StringBuilder query = new StringBuilder();
query.append("SELECT * FROM "); query.append("SELECT * FROM ");
query.append("(SELECT id, accountid FROM characters) AS accountterm "); query.append("(SELECT id, accountid FROM characters) AS accountterm ");
@@ -127,11 +132,11 @@ public enum ItemFactory {
query.append(isAccount ? "accountid" : "characterid"); query.append(isAccount ? "accountid" : "characterid");
query.append("` = ?"); query.append("` = ?");
query.append(login ? " AND `inventorytype` = " + InventoryType.EQUIPPED.getType() : ""); query.append(login ? " AND `inventorytype` = " + InventoryType.EQUIPPED.getType() : "");
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
try (PreparedStatement ps = con.prepareStatement(query.toString())) { try (PreparedStatement ps = con.prepareStatement(query.toString())) {
ps.setInt(1, id); ps.setInt(1, id);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) { while (rs.next()) {
Integer cid = rs.getInt("characterid"); Integer cid = rs.getInt("characterid");
@@ -140,10 +145,10 @@ public enum ItemFactory {
} }
} }
} }
return items; return items;
} }
private List<Pair<Item, InventoryType>> loadItemsCommon(int id, boolean login) throws SQLException { private List<Pair<Item, InventoryType>> loadItemsCommon(int id, boolean login) throws SQLException {
List<Pair<Item, InventoryType>> items = new ArrayList<>(); List<Pair<Item, InventoryType>> items = new ArrayList<>();
@@ -262,7 +267,7 @@ public enum ItemFactory {
lock.unlock(); lock.unlock();
} }
} }
private List<Pair<Item, InventoryType>> loadItemsMerchant(int id, boolean login) throws SQLException { private List<Pair<Item, InventoryType>> loadItemsMerchant(int id, boolean login) throws SQLException {
List<Pair<Item, InventoryType>> items = new ArrayList<>(); List<Pair<Item, InventoryType>> items = new ArrayList<>();

View File

@@ -1,12 +1,11 @@
package client.inventory; package client.inventory;
/** /**
*
* @author kevin * @author kevin
*/ */
public class ModifyInventory { public class ModifyInventory {
private int mode; private final int mode;
private Item item; private Item item;
private short oldPos; private short oldPos;
@@ -20,7 +19,7 @@ public class ModifyInventory {
this.item = item.copy(); this.item = item.copy();
this.oldPos = oldPos; this.oldPos = oldPos;
} }
public final int getMode() { public final int getMode() {
return mode; return mode;
} }
@@ -36,7 +35,7 @@ public class ModifyInventory {
public final short getOldPosition() { public final short getOldPosition() {
return oldPos; return oldPos;
} }
public final short getQuantity() { public final short getQuantity() {
return item.getQuantity(); return item.getQuantity();
} }

View File

@@ -25,7 +25,10 @@ package client.inventory;
* @author Leifde * @author Leifde
*/ */
public class PetCommand { public class PetCommand {
private int petId, skillId, prob, inc; private final int petId;
private final int skillId;
private final int prob;
private final int inc;
public PetCommand(int petId, int skillId, int prob, int inc) { public PetCommand(int petId, int skillId, int prob, int inc) {
this.petId = petId; this.petId = petId;

View File

@@ -31,13 +31,12 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
*
* @author Danny (Leifde) * @author Danny (Leifde)
*/ */
public class PetDataFactory { public class PetDataFactory {
private static DataProvider dataRoot = DataProviderFactory.getDataProvider(WZFiles.ITEM); private static final DataProvider dataRoot = DataProviderFactory.getDataProvider(WZFiles.ITEM);
private static Map<String, PetCommand> petCommands = new HashMap<>(); private static final Map<String, PetCommand> petCommands = new HashMap<>();
private static Map<Integer, Integer> petHunger = new HashMap<>(); private static final Map<Integer, Integer> petHunger = new HashMap<>();
public static PetCommand getPetCommand(int petId, int skillId) { public static PetCommand getPetCommand(int petId, int skillId) {
PetCommand ret = petCommands.get(petId + "" + skillId); PetCommand ret = petCommands.get(petId + "" + skillId);

View File

@@ -678,10 +678,14 @@ public class InventoryManipulator {
} else if (ii.isCash(it.getItemId())) { } else if (ii.isCash(it.getItemId())) {
if (YamlConfig.config.server.USE_ENFORCE_UNMERCHABLE_CASH) { // thanks Ari for noticing cash drops not available server-side if (YamlConfig.config.server.USE_ENFORCE_UNMERCHABLE_CASH) { // thanks Ari for noticing cash drops not available server-side
return true; return true;
} else return ItemConstants.isPet(it.getItemId()) && YamlConfig.config.server.USE_ENFORCE_UNMERCHABLE_PET; } else {
return ItemConstants.isPet(it.getItemId()) && YamlConfig.config.server.USE_ENFORCE_UNMERCHABLE_PET;
}
} else if (isDroppedItemRestricted(it)) { } else if (isDroppedItemRestricted(it)) {
return true; return true;
} else return ItemConstants.isWeddingRing(it.getItemId()); } else {
return ItemConstants.isWeddingRing(it.getItemId());
}
} }
public static void drop(Client c, InventoryType type, short src, short quantity) { public static void drop(Client c, InventoryType type, short src, short quantity) {

View File

@@ -34,103 +34,102 @@ import java.util.Set;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
/** /**
*
* @author Ronan - credits to Eric for showing the New Year opcodes and handler layout * @author Ronan - credits to Eric for showing the New Year opcodes and handler layout
*/ */
public class NewYearCardRecord { public class NewYearCardRecord {
private int id; private int id;
private int senderId; private final int senderId;
private String senderName; private final String senderName;
private boolean senderDiscardCard; private boolean senderDiscardCard;
private int receiverId; private final int receiverId;
private String receiverName; private final String receiverName;
private boolean receiverDiscardCard; private boolean receiverDiscardCard;
private boolean receiverReceivedCard; private boolean receiverReceivedCard;
private String stringContent; private final String stringContent;
private long dateSent = 0; private long dateSent = 0;
private long dateReceived = 0; private long dateReceived = 0;
private ScheduledFuture<?> sendTask = null; private ScheduledFuture<?> sendTask = null;
public NewYearCardRecord(int senderid, String sender, int receiverid, String receiver, String message) { public NewYearCardRecord(int senderid, String sender, int receiverid, String receiver, String message) {
this.id = -1; this.id = -1;
this.senderId = senderid; this.senderId = senderid;
this.senderName = sender; this.senderName = sender;
this.senderDiscardCard = false; this.senderDiscardCard = false;
this.receiverId = receiverid; this.receiverId = receiverid;
this.receiverName = receiver; this.receiverName = receiver;
this.receiverDiscardCard = false; this.receiverDiscardCard = false;
this.receiverReceivedCard = false; this.receiverReceivedCard = false;
this.stringContent = message; this.stringContent = message;
this.dateSent = System.currentTimeMillis(); this.dateSent = System.currentTimeMillis();
this.dateReceived = 0; this.dateReceived = 0;
} }
private void setExtraNewYearCardRecord(int id, boolean senderDiscardCard, boolean receiverDiscardCard, boolean receiverReceivedCard, long dateSent, long dateReceived) { private void setExtraNewYearCardRecord(int id, boolean senderDiscardCard, boolean receiverDiscardCard, boolean receiverReceivedCard, long dateSent, long dateReceived) {
this.id = id; this.id = id;
this.senderDiscardCard = senderDiscardCard; this.senderDiscardCard = senderDiscardCard;
this.receiverDiscardCard = receiverDiscardCard; this.receiverDiscardCard = receiverDiscardCard;
this.receiverReceivedCard = receiverReceivedCard; this.receiverReceivedCard = receiverReceivedCard;
this.dateSent = dateSent; this.dateSent = dateSent;
this.dateReceived = dateReceived; this.dateReceived = dateReceived;
} }
public void setId(int cardid) { public void setId(int cardid) {
this.id = cardid; this.id = cardid;
} }
public int getId() { public int getId() {
return this.id; return this.id;
} }
public int getSenderId() { public int getSenderId() {
return senderId; return senderId;
} }
public String getSenderName() { public String getSenderName() {
return senderName; return senderName;
} }
public boolean isSenderCardDiscarded() { public boolean isSenderCardDiscarded() {
return senderDiscardCard; return senderDiscardCard;
} }
public int getReceiverId() { public int getReceiverId() {
return receiverId; return receiverId;
} }
public String getReceiverName() { public String getReceiverName() {
return receiverName; return receiverName;
} }
public boolean isReceiverCardDiscarded() { public boolean isReceiverCardDiscarded() {
return receiverDiscardCard; return receiverDiscardCard;
} }
public boolean isReceiverCardReceived() { public boolean isReceiverCardReceived() {
return receiverReceivedCard; return receiverReceivedCard;
} }
public String getMessage() { public String getMessage() {
return stringContent; return stringContent;
} }
public long getDateSent() { public long getDateSent() {
return dateSent; return dateSent;
} }
public long getDateReceived() { public long getDateReceived() {
return dateReceived; return dateReceived;
} }
public static void saveNewYearCard(NewYearCardRecord newyear) { public static void saveNewYearCard(NewYearCardRecord newyear) {
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("INSERT INTO newyear VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { try (PreparedStatement ps = con.prepareStatement("INSERT INTO newyear VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
@@ -138,47 +137,49 @@ public class NewYearCardRecord {
ps.setString(2, newyear.senderName); ps.setString(2, newyear.senderName);
ps.setInt(3, newyear.receiverId); ps.setInt(3, newyear.receiverId);
ps.setString(4, newyear.receiverName); ps.setString(4, newyear.receiverName);
ps.setString(5, newyear.stringContent); ps.setString(5, newyear.stringContent);
ps.setBoolean(6, newyear.senderDiscardCard); ps.setBoolean(6, newyear.senderDiscardCard);
ps.setBoolean(7, newyear.receiverDiscardCard); ps.setBoolean(7, newyear.receiverDiscardCard);
ps.setBoolean(8, newyear.receiverReceivedCard); ps.setBoolean(8, newyear.receiverReceivedCard);
ps.setLong(9, newyear.dateSent); ps.setLong(9, newyear.dateSent);
ps.setLong(10, newyear.dateReceived); ps.setLong(10, newyear.dateReceived);
ps.executeUpdate(); ps.executeUpdate();
try (ResultSet rs = ps.getGeneratedKeys()) { try (ResultSet rs = ps.getGeneratedKeys()) {
rs.next(); rs.next();
newyear.id = rs.getInt(1); newyear.id = rs.getInt(1);
} }
} }
} catch(SQLException sqle) { } catch (SQLException sqle) {
sqle.printStackTrace(); sqle.printStackTrace();
} }
} }
public static void updateNewYearCard(NewYearCardRecord newyear) { public static void updateNewYearCard(NewYearCardRecord newyear) {
newyear.receiverReceivedCard = true; newyear.receiverReceivedCard = true;
newyear.dateReceived = System.currentTimeMillis(); newyear.dateReceived = System.currentTimeMillis();
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("UPDATE newyear SET received=1, timereceived=? WHERE id=?")) { try (PreparedStatement ps = con.prepareStatement("UPDATE newyear SET received=1, timereceived=? WHERE id=?")) {
ps.setLong(1, newyear.dateReceived); ps.setLong(1, newyear.dateReceived);
ps.setInt(2, newyear.id); ps.setInt(2, newyear.id);
ps.executeUpdate(); ps.executeUpdate();
} }
} catch(SQLException sqle) { } catch (SQLException sqle) {
sqle.printStackTrace(); sqle.printStackTrace();
} }
} }
public static NewYearCardRecord loadNewYearCard(int cardid) { public static NewYearCardRecord loadNewYearCard(int cardid) {
NewYearCardRecord nyc = Server.getInstance().getNewYearCard(cardid); NewYearCardRecord nyc = Server.getInstance().getNewYearCard(cardid);
if(nyc != null) return nyc; if (nyc != null) {
return nyc;
}
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM newyear WHERE id = ?")) { try (PreparedStatement ps = con.prepareStatement("SELECT * FROM newyear WHERE id = ?")) {
ps.setInt(1, cardid); ps.setInt(1, cardid);
@@ -186,19 +187,19 @@ public class NewYearCardRecord {
if (rs.next()) { if (rs.next()) {
NewYearCardRecord newyear = new NewYearCardRecord(rs.getInt("senderid"), rs.getString("sendername"), rs.getInt("receiverid"), rs.getString("receivername"), rs.getString("message")); NewYearCardRecord newyear = new NewYearCardRecord(rs.getInt("senderid"), rs.getString("sendername"), rs.getInt("receiverid"), rs.getString("receivername"), rs.getString("message"));
newyear.setExtraNewYearCardRecord(rs.getInt("id"), rs.getBoolean("senderdiscard"), rs.getBoolean("receiverdiscard"), rs.getBoolean("received"), rs.getLong("timesent"), rs.getLong("timereceived")); newyear.setExtraNewYearCardRecord(rs.getInt("id"), rs.getBoolean("senderdiscard"), rs.getBoolean("receiverdiscard"), rs.getBoolean("received"), rs.getLong("timesent"), rs.getLong("timereceived"));
Server.getInstance().setNewYearCard(newyear); Server.getInstance().setNewYearCard(newyear);
return newyear; return newyear;
} }
} }
} }
} catch(SQLException sqle) { } catch (SQLException sqle) {
sqle.printStackTrace(); sqle.printStackTrace();
} }
return null; return null;
} }
public static void loadPlayerNewYearCards(Character chr) { public static void loadPlayerNewYearCards(Character chr) {
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM newyear WHERE senderid = ? OR receiverid = ?")) { try (PreparedStatement ps = con.prepareStatement("SELECT * FROM newyear WHERE senderid = ? OR receiverid = ?")) {
@@ -208,47 +209,49 @@ public class NewYearCardRecord {
while (rs.next()) { while (rs.next()) {
NewYearCardRecord newyear = new NewYearCardRecord(rs.getInt("senderid"), rs.getString("sendername"), rs.getInt("receiverid"), rs.getString("receivername"), rs.getString("message")); NewYearCardRecord newyear = new NewYearCardRecord(rs.getInt("senderid"), rs.getString("sendername"), rs.getInt("receiverid"), rs.getString("receivername"), rs.getString("message"));
newyear.setExtraNewYearCardRecord(rs.getInt("id"), rs.getBoolean("senderdiscard"), rs.getBoolean("receiverdiscard"), rs.getBoolean("received"), rs.getLong("timesent"), rs.getLong("timereceived")); newyear.setExtraNewYearCardRecord(rs.getInt("id"), rs.getBoolean("senderdiscard"), rs.getBoolean("receiverdiscard"), rs.getBoolean("received"), rs.getLong("timesent"), rs.getLong("timereceived"));
chr.addNewYearRecord(newyear); chr.addNewYearRecord(newyear);
} }
} }
} }
} catch(SQLException sqle) { } catch (SQLException sqle) {
sqle.printStackTrace(); sqle.printStackTrace();
} }
} }
public static void printNewYearRecords(Character chr) { public static void printNewYearRecords(Character chr) {
chr.dropMessage(5, "New Years: " + chr.getNewYearRecords().size()); chr.dropMessage(5, "New Years: " + chr.getNewYearRecords().size());
for(NewYearCardRecord nyc : chr.getNewYearRecords()) { for (NewYearCardRecord nyc : chr.getNewYearRecords()) {
chr.dropMessage(5, "-------------------------------"); chr.dropMessage(5, "-------------------------------");
chr.dropMessage(5, "Id: " + nyc.id); chr.dropMessage(5, "Id: " + nyc.id);
chr.dropMessage(5, "Sender id: " + nyc.senderId); chr.dropMessage(5, "Sender id: " + nyc.senderId);
chr.dropMessage(5, "Sender name: " + nyc.senderName); chr.dropMessage(5, "Sender name: " + nyc.senderName);
chr.dropMessage(5, "Sender discard: " + nyc.senderDiscardCard); chr.dropMessage(5, "Sender discard: " + nyc.senderDiscardCard);
chr.dropMessage(5, "Receiver id: " + nyc.receiverId); chr.dropMessage(5, "Receiver id: " + nyc.receiverId);
chr.dropMessage(5, "Receiver name: " + nyc.receiverName); chr.dropMessage(5, "Receiver name: " + nyc.receiverName);
chr.dropMessage(5, "Receiver discard: " + nyc.receiverDiscardCard); chr.dropMessage(5, "Receiver discard: " + nyc.receiverDiscardCard);
chr.dropMessage(5, "Received: " + nyc.receiverReceivedCard); chr.dropMessage(5, "Received: " + nyc.receiverReceivedCard);
chr.dropMessage(5, "Message: " + nyc.stringContent); chr.dropMessage(5, "Message: " + nyc.stringContent);
chr.dropMessage(5, "Date sent: " + nyc.dateSent); chr.dropMessage(5, "Date sent: " + nyc.dateSent);
chr.dropMessage(5, "Date recv: " + nyc.dateReceived); chr.dropMessage(5, "Date recv: " + nyc.dateReceived);
} }
} }
public void startNewYearCardTask() { public void startNewYearCardTask() {
if(sendTask != null) return; if (sendTask != null) {
return;
}
sendTask = TimerManager.getInstance().register(() -> { sendTask = TimerManager.getInstance().register(() -> {
Server server = Server.getInstance(); Server server = Server.getInstance();
int world = server.getCharacterWorld(receiverId); int world = server.getCharacterWorld(receiverId);
if(world == -1) { if (world == -1) {
sendTask.cancel(false); sendTask.cancel(false);
sendTask = null; sendTask = null;
@@ -256,32 +259,32 @@ public class NewYearCardRecord {
} }
Character target = server.getWorld(world).getPlayerStorage().getCharacterById(receiverId); Character target = server.getWorld(world).getPlayerStorage().getCharacterById(receiverId);
if(target != null && target.isLoggedinWorld()) { if (target != null && target.isLoggedinWorld()) {
target.sendPacket(PacketCreator.onNewYearCardRes(target, NewYearCardRecord.this, 0xC, 0)); target.sendPacket(PacketCreator.onNewYearCardRes(target, NewYearCardRecord.this, 0xC, 0));
} }
}, 1000 * 60 * 60); //1 Hour }, 1000 * 60 * 60); //1 Hour
} }
public void stopNewYearCardTask() { public void stopNewYearCardTask() {
if(sendTask != null) { if (sendTask != null) {
sendTask.cancel(false); sendTask.cancel(false);
sendTask = null; sendTask = null;
} }
} }
private static void deleteNewYearCard(int id) { private static void deleteNewYearCard(int id) {
Server.getInstance().removeNewYearCard(id); Server.getInstance().removeNewYearCard(id);
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("DELETE FROM newyear WHERE id = ?")) { try (PreparedStatement ps = con.prepareStatement("DELETE FROM newyear WHERE id = ?")) {
ps.setInt(1, id); ps.setInt(1, id);
ps.executeUpdate(); ps.executeUpdate();
} }
} catch(SQLException sqle) { } catch (SQLException sqle) {
sqle.printStackTrace(); sqle.printStackTrace();
} }
} }
public static void removeAllNewYearCard(boolean send, Character chr) { public static void removeAllNewYearCard(boolean send, Character chr) {
int cid = chr.getId(); int cid = chr.getId();
@@ -297,21 +300,21 @@ public class NewYearCardRecord {
sqle.printStackTrace(); sqle.printStackTrace();
} }
*/ */
Set<NewYearCardRecord> set = new HashSet<>(chr.getNewYearRecords()); Set<NewYearCardRecord> set = new HashSet<>(chr.getNewYearRecords());
for(NewYearCardRecord nyc : set) { for (NewYearCardRecord nyc : set) {
if(send) { if (send) {
if(nyc.senderId == cid) { if (nyc.senderId == cid) {
nyc.senderDiscardCard = true; nyc.senderDiscardCard = true;
nyc.receiverReceivedCard = false; nyc.receiverReceivedCard = false;
chr.removeNewYearRecord(nyc); chr.removeNewYearRecord(nyc);
deleteNewYearCard(nyc.id); deleteNewYearCard(nyc.id);
chr.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(chr, nyc, 0xE, 0)); chr.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(chr, nyc, 0xE, 0));
Character other = chr.getClient().getWorldServer().getPlayerStorage().getCharacterById(nyc.getReceiverId()); Character other = chr.getClient().getWorldServer().getPlayerStorage().getCharacterById(nyc.getReceiverId());
if(other != null && other.isLoggedinWorld()) { if (other != null && other.isLoggedinWorld()) {
other.removeNewYearRecord(nyc); other.removeNewYearRecord(nyc);
other.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(other, nyc, 0xE, 0)); other.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(other, nyc, 0xE, 0));
@@ -319,17 +322,17 @@ public class NewYearCardRecord {
} }
} }
} else { } else {
if(nyc.receiverId == cid) { if (nyc.receiverId == cid) {
nyc.receiverDiscardCard = true; nyc.receiverDiscardCard = true;
nyc.receiverReceivedCard = false; nyc.receiverReceivedCard = false;
chr.removeNewYearRecord(nyc); chr.removeNewYearRecord(nyc);
deleteNewYearCard(nyc.id); deleteNewYearCard(nyc.id);
chr.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(chr, nyc, 0xE, 0)); chr.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(chr, nyc, 0xE, 0));
Character other = chr.getClient().getWorldServer().getPlayerStorage().getCharacterById(nyc.getSenderId()); Character other = chr.getClient().getWorldServer().getPlayerStorage().getCharacterById(nyc.getSenderId());
if(other != null && other.isLoggedinWorld()) { if (other != null && other.isLoggedinWorld()) {
other.removeNewYearRecord(nyc); other.removeNewYearRecord(nyc);
other.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(other, nyc, 0xE, 0)); other.getMap().broadcastMessage(PacketCreator.onNewYearCardRes(other, nyc, 0xE, 0));

View File

@@ -25,15 +25,14 @@ import server.maps.MapleMap;
import tools.PacketCreator; import tools.PacketCreator;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class BuybackProcessor { public class BuybackProcessor {
public static void processBuyback(Client c) { public static void processBuyback(Client c) {
Character chr = c.getPlayer(); Character chr = c.getPlayer();
boolean buyback; boolean buyback;
c.lockClient(); c.lockClient();
try { try {
buyback = !chr.isAlive() && chr.couldBuyback(); buyback = !chr.isAlive() && chr.couldBuyback();
@@ -43,7 +42,7 @@ public class BuybackProcessor {
if (buyback) { if (buyback) {
String jobString; String jobString;
switch(chr.getJobStyle()) { switch (chr.getJobStyle()) {
case WARRIOR: case WARRIOR:
jobString = "warrior"; jobString = "warrior";
break; break;
@@ -72,7 +71,7 @@ public class BuybackProcessor {
chr.healHpMp(); chr.healHpMp();
chr.purgeDebuffs(); chr.purgeDebuffs();
chr.broadcastStance(chr.isFacingLeft() ? 5 : 4); chr.broadcastStance(chr.isFacingLeft() ? 5 : 4);
MapleMap map = chr.getMap(); MapleMap map = chr.getMap();
map.broadcastMessage(PacketCreator.playSound("Buyback/" + jobString)); map.broadcastMessage(PacketCreator.playSound("Buyback/" + jobString));
map.broadcastMessage(PacketCreator.earnTitleMessage(chr.getName() + " just bought back into the game!")); map.broadcastMessage(PacketCreator.earnTitleMessage(chr.getName() + " just bought back into the game!"));

View File

@@ -42,12 +42,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class MakerProcessor { public class MakerProcessor {
private static ItemInformationProvider ii = ItemInformationProvider.getInstance(); private static final ItemInformationProvider ii = ItemInformationProvider.getInstance();
public static void makerAction(InPacket p, Client c) { public static void makerAction(InPacket p, Client c) {
if (c.tryacquireClient()) { if (c.tryacquireClient()) {
@@ -61,26 +60,26 @@ public class MakerProcessor {
Map<Integer, Short> reagentids = new LinkedHashMap<>(); Map<Integer, Short> reagentids = new LinkedHashMap<>();
int stimulantid = -1; int stimulantid = -1;
if(type == 3) { // building monster crystal if (type == 3) { // building monster crystal
int fromLeftover = toCreate; int fromLeftover = toCreate;
toCreate = ii.getMakerCrystalFromLeftover(toCreate); toCreate = ii.getMakerCrystalFromLeftover(toCreate);
if(toCreate == -1) { if (toCreate == -1) {
c.sendPacket(PacketCreator.serverNotice(1, ii.getName(fromLeftover) + " is unavailable for Monster Crystal conversion.")); c.sendPacket(PacketCreator.serverNotice(1, ii.getName(fromLeftover) + " is unavailable for Monster Crystal conversion."));
c.sendPacket(PacketCreator.makerEnableActions()); c.sendPacket(PacketCreator.makerEnableActions());
return; return;
} }
recipe = MakerItemFactory.generateLeftoverCrystalEntry(fromLeftover, toCreate); recipe = MakerItemFactory.generateLeftoverCrystalEntry(fromLeftover, toCreate);
} else if(type == 4) { // disassembling } else if (type == 4) { // disassembling
p.readInt(); // 1... probably inventory type p.readInt(); // 1... probably inventory type
pos = p.readInt(); pos = p.readInt();
Item it = c.getPlayer().getInventory(InventoryType.EQUIP).getItem((short) pos); Item it = c.getPlayer().getInventory(InventoryType.EQUIP).getItem((short) pos);
if(it != null && it.getItemId() == toCreate) { if (it != null && it.getItemId() == toCreate) {
toDisassemble = toCreate; toDisassemble = toCreate;
Pair<Integer, List<Pair<Integer, Integer>>> pair = generateDisassemblyInfo(toDisassemble); Pair<Integer, List<Pair<Integer, Integer>>> pair = generateDisassemblyInfo(toDisassemble);
if(pair != null) { if (pair != null) {
recipe = MakerItemFactory.generateDisassemblyCrystalEntry(toDisassemble, pair.getLeft(), pair.getRight()); recipe = MakerItemFactory.generateDisassemblyCrystalEntry(toDisassemble, pair.getLeft(), pair.getRight());
} else { } else {
c.sendPacket(PacketCreator.serverNotice(1, ii.getName(toCreate) + " is unavailable for Monster Crystal disassembly.")); c.sendPacket(PacketCreator.serverNotice(1, ii.getName(toCreate) + " is unavailable for Monster Crystal disassembly."));
@@ -93,20 +92,20 @@ public class MakerProcessor {
return; return;
} }
} else { } else {
if(ItemConstants.isEquipment(toCreate)) { // only equips uses stimulant and reagents if (ItemConstants.isEquipment(toCreate)) { // only equips uses stimulant and reagents
if(p.readByte() != 0) { // stimulant if (p.readByte() != 0) { // stimulant
stimulantid = ii.getMakerStimulant(toCreate); stimulantid = ii.getMakerStimulant(toCreate);
if(!c.getAbstractPlayerInteraction().haveItem(stimulantid)) { if (!c.getAbstractPlayerInteraction().haveItem(stimulantid)) {
stimulantid = -1; stimulantid = -1;
} }
} }
int reagents = Math.min(p.readInt(), getMakerReagentSlots(toCreate)); int reagents = Math.min(p.readInt(), getMakerReagentSlots(toCreate));
for(int i = 0; i < reagents; i++) { // crystals for (int i = 0; i < reagents; i++) { // crystals
int reagentid = p.readInt(); int reagentid = p.readInt();
if(ItemConstants.isMakerReagent(reagentid)) { if (ItemConstants.isMakerReagent(reagentid)) {
Short rs = reagentids.get(reagentid); Short rs = reagentids.get(reagentid);
if(rs == null) { if (rs == null) {
reagentids.put(reagentid, (short) 1); reagentids.put(reagentid, (short) 1);
} else { } else {
reagentids.put(reagentid, (short) (rs + 1)); reagentids.put(reagentid, (short) (rs + 1));
@@ -115,18 +114,18 @@ public class MakerProcessor {
} }
List<Pair<Integer, Short>> toUpdate = new LinkedList<>(); List<Pair<Integer, Short>> toUpdate = new LinkedList<>();
for(Map.Entry<Integer, Short> r : reagentids.entrySet()) { for (Map.Entry<Integer, Short> r : reagentids.entrySet()) {
int qty = c.getAbstractPlayerInteraction().getItemQuantity(r.getKey()); int qty = c.getAbstractPlayerInteraction().getItemQuantity(r.getKey());
if(qty < r.getValue()) { if (qty < r.getValue()) {
toUpdate.add(new Pair<>(r.getKey(), (short) qty)); toUpdate.add(new Pair<>(r.getKey(), (short) qty));
} }
} }
// remove those not present on player inventory // remove those not present on player inventory
if(!toUpdate.isEmpty()) { if (!toUpdate.isEmpty()) {
for(Pair<Integer, Short> rp : toUpdate) { for (Pair<Integer, Short> rp : toUpdate) {
if(rp.getRight() > 0) { if (rp.getRight() > 0) {
reagentids.put(rp.getLeft(), rp.getRight()); reagentids.put(rp.getLeft(), rp.getRight());
} else { } else {
reagentids.remove(rp.getLeft()); reagentids.remove(rp.getLeft());
@@ -134,8 +133,8 @@ public class MakerProcessor {
} }
} }
if(!reagentids.isEmpty()) { if (!reagentids.isEmpty()) {
if(!removeOddMakerReagents(toCreate, reagentids)) { if (!removeOddMakerReagents(toCreate, reagentids)) {
c.sendPacket(PacketCreator.serverNotice(1, "You can only use WATK and MATK Strengthening Gems on weapon items.")); c.sendPacket(PacketCreator.serverNotice(1, "You can only use WATK and MATK Strengthening Gems on weapon items."));
c.sendPacket(PacketCreator.makerEnableActions()); c.sendPacket(PacketCreator.makerEnableActions());
return; return;
@@ -148,7 +147,7 @@ public class MakerProcessor {
short createStatus = getCreateStatus(c, recipe); short createStatus = getCreateStatus(c, recipe);
switch(createStatus) { switch (createStatus) {
case -1:// non-available for Maker itemid has been tried to forge case -1:// non-available for Maker itemid has been tried to forge
FilePrinter.printError(FilePrinter.EXPLOITS, "Player " + c.getPlayer().getName() + " tried to craft itemid " + toCreate + " using the Maker skill."); FilePrinter.printError(FilePrinter.EXPLOITS, "Player " + c.getPlayer().getName() + " tried to craft itemid " + toCreate + " using the Maker skill.");
c.sendPacket(PacketCreator.serverNotice(1, "The requested item could not be crafted on this operation.")); c.sendPacket(PacketCreator.serverNotice(1, "The requested item could not be crafted on this operation."));
@@ -174,14 +173,14 @@ public class MakerProcessor {
c.sendPacket(PacketCreator.serverNotice(1, "You don't have enough Maker level to complete this operation.")); c.sendPacket(PacketCreator.serverNotice(1, "You don't have enough Maker level to complete this operation."));
c.sendPacket(PacketCreator.makerEnableActions()); c.sendPacket(PacketCreator.makerEnableActions());
break; break;
case 5: // inventory full case 5: // inventory full
c.sendPacket(PacketCreator.serverNotice(1, "Your inventory is full.")); c.sendPacket(PacketCreator.serverNotice(1, "Your inventory is full."));
c.sendPacket(PacketCreator.makerEnableActions()); c.sendPacket(PacketCreator.makerEnableActions());
break; break;
default: default:
if(toDisassemble != -1) { if (toDisassemble != -1) {
InventoryManipulator.removeFromSlot(c, InventoryType.EQUIP, (short) pos, (short) 1, false); InventoryManipulator.removeFromSlot(c, InventoryType.EQUIP, (short) pos, (short) 1, false);
} else { } else {
for (Pair<Integer, Integer> pair : recipe.getReqItems()) { for (Pair<Integer, Integer> pair : recipe.getReqItems()) {
@@ -190,9 +189,11 @@ public class MakerProcessor {
} }
int cost = recipe.getCost(); int cost = recipe.getCost();
if(stimulantid == -1 && reagentids.isEmpty()) { if (stimulantid == -1 && reagentids.isEmpty()) {
if(cost > 0) c.getPlayer().gainMeso(-cost, false); if (cost > 0) {
c.getPlayer().gainMeso(-cost, false);
}
for (Pair<Integer, Integer> pair : recipe.getGainItems()) { for (Pair<Integer, Integer> pair : recipe.getGainItems()) {
c.getPlayer().setCS(true); c.getPlayer().setCS(true);
c.getAbstractPlayerInteraction().gainItem(pair.getLeft(), pair.getRight().shortValue(), false); c.getAbstractPlayerInteraction().gainItem(pair.getLeft(), pair.getRight().shortValue(), false);
@@ -200,15 +201,19 @@ public class MakerProcessor {
} }
} else { } else {
toCreate = recipe.getGainItems().get(0).getLeft(); toCreate = recipe.getGainItems().get(0).getLeft();
if(stimulantid != -1) c.getAbstractPlayerInteraction().gainItem(stimulantid, (short) -1, false); if (stimulantid != -1) {
if(!reagentids.isEmpty()) { c.getAbstractPlayerInteraction().gainItem(stimulantid, (short) -1, false);
for(Map.Entry<Integer, Short> r : reagentids.entrySet()) { }
if (!reagentids.isEmpty()) {
for (Map.Entry<Integer, Short> r : reagentids.entrySet()) {
c.getAbstractPlayerInteraction().gainItem(r.getKey(), (short) (-1 * r.getValue()), false); c.getAbstractPlayerInteraction().gainItem(r.getKey(), (short) (-1 * r.getValue()), false);
} }
} }
if(cost > 0) c.getPlayer().gainMeso(-cost, false); if (cost > 0) {
c.getPlayer().gainMeso(-cost, false);
}
makerSucceeded = addBoostedMakerItem(c, toCreate, stimulantid, reagentids); makerSucceeded = addBoostedMakerItem(c, toCreate, stimulantid, reagentids);
} }
@@ -220,11 +225,11 @@ public class MakerProcessor {
} else { } else {
c.sendPacket(PacketCreator.makerResult(makerSucceeded, recipe.getGainItems().get(0).getLeft(), recipe.getGainItems().get(0).getRight(), recipe.getCost(), recipe.getReqItems(), stimulantid, new LinkedList<>(reagentids.keySet()))); c.sendPacket(PacketCreator.makerResult(makerSucceeded, recipe.getGainItems().get(0).getLeft(), recipe.getGainItems().get(0).getRight(), recipe.getCost(), recipe.getReqItems(), stimulantid, new LinkedList<>(reagentids.keySet())));
} }
c.sendPacket(PacketCreator.showMakerEffect(makerSucceeded)); c.sendPacket(PacketCreator.showMakerEffect(makerSucceeded));
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), PacketCreator.showForeignMakerEffect(c.getPlayer().getId(), makerSucceeded), false); c.getPlayer().getMap().broadcastMessage(c.getPlayer(), PacketCreator.showForeignMakerEffect(c.getPlayer().getId(), makerSucceeded), false);
if(toCreate == 4260003 && type == 3 && c.getPlayer().getQuestStatus(6033) == 1) { if (toCreate == 4260003 && type == 3 && c.getPlayer().getQuestStatus(6033) == 1) {
c.getAbstractPlayerInteraction().setQuestProgress(6033, 1); c.getAbstractPlayerInteraction().setQuestProgress(6033, 1);
} }
} }
@@ -233,25 +238,25 @@ public class MakerProcessor {
} }
} }
} }
// checks and prevents hackers from PE'ing Maker operations with invalid operations // checks and prevents hackers from PE'ing Maker operations with invalid operations
private static boolean removeOddMakerReagents(int toCreate, Map<Integer, Short> reagentids) { private static boolean removeOddMakerReagents(int toCreate, Map<Integer, Short> reagentids) {
Map<Integer, Integer> reagentType = new LinkedHashMap<>(); Map<Integer, Integer> reagentType = new LinkedHashMap<>();
List<Integer> toRemove = new LinkedList<>(); List<Integer> toRemove = new LinkedList<>();
boolean isWeapon = ItemConstants.isWeapon(toCreate) || YamlConfig.config.server.USE_MAKER_PERMISSIVE_ATKUP; // thanks Vcoc for finding a case where a weapon wouldn't be counted as such due to a bounding on isWeapon boolean isWeapon = ItemConstants.isWeapon(toCreate) || YamlConfig.config.server.USE_MAKER_PERMISSIVE_ATKUP; // thanks Vcoc for finding a case where a weapon wouldn't be counted as such due to a bounding on isWeapon
for(Map.Entry<Integer, Short> r : reagentids.entrySet()) { for (Map.Entry<Integer, Short> r : reagentids.entrySet()) {
int curRid = r.getKey(); int curRid = r.getKey();
int type = r.getKey() / 100; int type = r.getKey() / 100;
if(type < 42502 && !isWeapon) { // only weapons should gain w.att/m.att from these. if (type < 42502 && !isWeapon) { // only weapons should gain w.att/m.att from these.
return false; //toRemove.add(curRid); return false; //toRemove.add(curRid);
} else { } else {
Integer tableRid = reagentType.get(type); Integer tableRid = reagentType.get(type);
if(tableRid != null) { if (tableRid != null) {
if(tableRid < curRid) { if (tableRid < curRid) {
toRemove.add(tableRid); toRemove.add(tableRid);
reagentType.put(type, curRid); reagentType.put(type, curRid);
} else { } else {
@@ -262,92 +267,92 @@ public class MakerProcessor {
} }
} }
} }
// removing less effective gems of repeated type // removing less effective gems of repeated type
for(Integer i : toRemove) { for (Integer i : toRemove) {
reagentids.remove(i); reagentids.remove(i);
} }
// the Maker skill will use only one of each gem // the Maker skill will use only one of each gem
for(Integer i : reagentids.keySet()) { for (Integer i : reagentids.keySet()) {
reagentids.put(i, (short) 1); reagentids.put(i, (short) 1);
} }
return true; return true;
} }
private static int getMakerReagentSlots(int itemId) { private static int getMakerReagentSlots(int itemId) {
try { try {
int eqpLevel = ii.getEquipLevelReq(itemId); int eqpLevel = ii.getEquipLevelReq(itemId);
if(eqpLevel < 78) { if (eqpLevel < 78) {
return 1; return 1;
} else if(eqpLevel >= 78 && eqpLevel < 108) { } else if (eqpLevel >= 78 && eqpLevel < 108) {
return 2; return 2;
} else { } else {
return 3; return 3;
} }
} catch(NullPointerException npe) { } catch (NullPointerException npe) {
return 0; return 0;
} }
} }
private static Pair<Integer, List<Pair<Integer, Integer>>> generateDisassemblyInfo(int itemId) { private static Pair<Integer, List<Pair<Integer, Integer>>> generateDisassemblyInfo(int itemId) {
int recvFee = ii.getMakerDisassembledFee(itemId); int recvFee = ii.getMakerDisassembledFee(itemId);
if(recvFee > -1) { if (recvFee > -1) {
List<Pair<Integer, Integer>> gains = ii.getMakerDisassembledItems(itemId); List<Pair<Integer, Integer>> gains = ii.getMakerDisassembledItems(itemId);
if(!gains.isEmpty()) { if (!gains.isEmpty()) {
return new Pair<>(recvFee, gains); return new Pair<>(recvFee, gains);
} }
} }
return null; return null;
} }
public static int getMakerSkillLevel(Character chr) { public static int getMakerSkillLevel(Character chr) {
return chr.getSkillLevel((chr.getJob().getId() / 1000) * 10000000 + 1007); return chr.getSkillLevel((chr.getJob().getId() / 1000) * 10000000 + 1007);
} }
private static short getCreateStatus(Client c, MakerItemCreateEntry recipe) { private static short getCreateStatus(Client c, MakerItemCreateEntry recipe) {
if(recipe.isInvalid()) { if (recipe.isInvalid()) {
return -1; return -1;
} }
if(!hasItems(c, recipe)) { if (!hasItems(c, recipe)) {
return 1; return 1;
} }
if(c.getPlayer().getMeso() < recipe.getCost()) { if (c.getPlayer().getMeso() < recipe.getCost()) {
return 2; return 2;
} }
if(c.getPlayer().getLevel() < recipe.getReqLevel()) { if (c.getPlayer().getLevel() < recipe.getReqLevel()) {
return 3; return 3;
} }
if(getMakerSkillLevel(c.getPlayer()) < recipe.getReqSkillLevel()) { if (getMakerSkillLevel(c.getPlayer()) < recipe.getReqSkillLevel()) {
return 4; return 4;
} }
List<Integer> addItemids = new LinkedList<>(); List<Integer> addItemids = new LinkedList<>();
List<Integer> addQuantity = new LinkedList<>(); List<Integer> addQuantity = new LinkedList<>();
List<Integer> rmvItemids = new LinkedList<>(); List<Integer> rmvItemids = new LinkedList<>();
List<Integer> rmvQuantity = new LinkedList<>(); List<Integer> rmvQuantity = new LinkedList<>();
for (Pair<Integer, Integer> p : recipe.getReqItems()) { for (Pair<Integer, Integer> p : recipe.getReqItems()) {
rmvItemids.add(p.getLeft()); rmvItemids.add(p.getLeft());
rmvQuantity.add(p.getRight()); rmvQuantity.add(p.getRight());
} }
for (Pair<Integer, Integer> p : recipe.getGainItems()) { for (Pair<Integer, Integer> p : recipe.getGainItems()) {
addItemids.add(p.getLeft()); addItemids.add(p.getLeft());
addQuantity.add(p.getRight()); addQuantity.add(p.getRight());
} }
if (!c.getAbstractPlayerInteraction().canHoldAllAfterRemoving(addItemids, addQuantity, rmvItemids, rmvQuantity)) { if (!c.getAbstractPlayerInteraction().canHoldAllAfterRemoving(addItemids, addQuantity, rmvItemids, rmvQuantity)) {
return 5; return 5;
} }
return 0; return 0;
} }
@@ -360,58 +365,62 @@ public class MakerProcessor {
} }
return true; return true;
} }
private static boolean addBoostedMakerItem(Client c, int itemid, int stimulantid, Map<Integer, Short> reagentids) { private static boolean addBoostedMakerItem(Client c, int itemid, int stimulantid, Map<Integer, Short> reagentids) {
if(stimulantid != -1 && !ii.rollSuccessChance(90.0)) { if (stimulantid != -1 && !ItemInformationProvider.rollSuccessChance(90.0)) {
return false; return false;
} }
Item item = ii.getEquipById(itemid); Item item = ii.getEquipById(itemid);
if(item == null) return false; if (item == null) {
return false;
}
Equip eqp = (Equip)item; Equip eqp = (Equip) item;
if(ItemConstants.isAccessory(item.getItemId()) && eqp.getUpgradeSlots() <= 0) eqp.setUpgradeSlots(3); if (ItemConstants.isAccessory(item.getItemId()) && eqp.getUpgradeSlots() <= 0) {
eqp.setUpgradeSlots(3);
}
if(YamlConfig.config.server.USE_ENHANCED_CRAFTING == true) { if (YamlConfig.config.server.USE_ENHANCED_CRAFTING == true) {
if(!(c.getPlayer().isGM() && YamlConfig.config.server.USE_PERFECT_GM_SCROLL)) { if (!(c.getPlayer().isGM() && YamlConfig.config.server.USE_PERFECT_GM_SCROLL)) {
eqp.setUpgradeSlots((byte)(eqp.getUpgradeSlots() + 1)); eqp.setUpgradeSlots((byte) (eqp.getUpgradeSlots() + 1));
} }
item = ItemInformationProvider.getInstance().scrollEquipWithId(eqp, 2049100, true, 2049100, c.getPlayer().isGM()); item = ItemInformationProvider.getInstance().scrollEquipWithId(eqp, 2049100, true, 2049100, c.getPlayer().isGM());
} }
if(!reagentids.isEmpty()) { if (!reagentids.isEmpty()) {
Map<String, Integer> stats = new LinkedHashMap<>(); Map<String, Integer> stats = new LinkedHashMap<>();
List<Short> randOption = new LinkedList<>(); List<Short> randOption = new LinkedList<>();
List<Short> randStat = new LinkedList<>(); List<Short> randStat = new LinkedList<>();
for(Map.Entry<Integer, Short> r : reagentids.entrySet()) { for (Map.Entry<Integer, Short> r : reagentids.entrySet()) {
Pair<String, Integer> reagentBuff = ii.getMakerReagentStatUpgrade(r.getKey()); Pair<String, Integer> reagentBuff = ii.getMakerReagentStatUpgrade(r.getKey());
if(reagentBuff != null) { if (reagentBuff != null) {
String s = reagentBuff.getLeft(); String s = reagentBuff.getLeft();
if(s.substring(0, 4).contains("rand")) { if (s.substring(0, 4).contains("rand")) {
if(s.substring(4).equals("Stat")) { if (s.substring(4).equals("Stat")) {
randStat.add((short) (reagentBuff.getRight() * r.getValue())); randStat.add((short) (reagentBuff.getRight() * r.getValue()));
} else { } else {
randOption.add((short) (reagentBuff.getRight() * r.getValue())); randOption.add((short) (reagentBuff.getRight() * r.getValue()));
} }
} else { } else {
String stat = s.substring(3); String stat = s.substring(3);
if(!stat.equals("ReqLevel")) { // improve req level... really? if (!stat.equals("ReqLevel")) { // improve req level... really?
switch (stat) { switch (stat) {
case "MaxHP": case "MaxHP":
stat = "MHP"; stat = "MHP";
break; break;
case "MaxMP": case "MaxMP":
stat = "MMP"; stat = "MMP";
break; break;
} }
Integer d = stats.get(stat); Integer d = stats.get(stat);
if(d == null) { if (d == null) {
stats.put(stat, reagentBuff.getRight() * r.getValue()); stats.put(stat, reagentBuff.getRight() * r.getValue());
} else { } else {
stats.put(stat, d + (reagentBuff.getRight() * r.getValue())); stats.put(stat, d + (reagentBuff.getRight() * r.getValue()));
@@ -420,22 +429,22 @@ public class MakerProcessor {
} }
} }
} }
ii.improveEquipStats(eqp, stats); ItemInformationProvider.improveEquipStats(eqp, stats);
for(Short sh : randStat) { for (Short sh : randStat) {
ii.scrollOptionEquipWithChaos(eqp, sh, false); ii.scrollOptionEquipWithChaos(eqp, sh, false);
} }
for(Short sh : randOption) { for (Short sh : randOption) {
ii.scrollOptionEquipWithChaos(eqp, sh, true); ii.scrollOptionEquipWithChaos(eqp, sh, true);
} }
} }
if(stimulantid != -1) { if (stimulantid != -1) {
eqp = ii.randomizeUpgradeStats(eqp); eqp = ii.randomizeUpgradeStats(eqp);
} }
InventoryManipulator.addFromDrop(c, item, false, -1); InventoryManipulator.addFromDrop(c, item, false, -1);
return true; return true;
} }

View File

@@ -35,34 +35,33 @@ import tools.PacketCreator;
import java.util.List; import java.util.List;
/** /**
*
* @author Ronan - multi-pot consumption feature * @author Ronan - multi-pot consumption feature
*/ */
public class PetAutopotProcessor { public class PetAutopotProcessor {
private static class AutopotAction { private static class AutopotAction {
private Client c; private final Client c;
private short slot; private short slot;
private int itemId; private final int itemId;
private Item toUse; private Item toUse;
private List<Item> toUseList; private List<Item> toUseList;
private boolean hasHpGain, hasMpGain; private boolean hasHpGain, hasMpGain;
private int maxHp, maxMp, curHp, curMp; private int maxHp, maxMp, curHp, curMp;
private double incHp, incMp; private double incHp, incMp;
private boolean cursorOnNextAvailablePot(Character chr) { private boolean cursorOnNextAvailablePot(Character chr) {
if(toUseList == null) { if (toUseList == null) {
toUseList = chr.getInventory(InventoryType.USE).linkedListById(itemId); toUseList = chr.getInventory(InventoryType.USE).linkedListById(itemId);
} }
toUse = null; toUse = null;
while(!toUseList.isEmpty()) { while (!toUseList.isEmpty()) {
Item it = toUseList.remove(0); Item it = toUseList.remove(0);
if(it.getQuantity() > 0) { if (it.getQuantity() > 0) {
toUse = it; toUse = it;
slot = it.getPosition(); slot = it.getPosition();
@@ -72,13 +71,13 @@ public class PetAutopotProcessor {
return false; return false;
} }
public AutopotAction(Client c, short slot, int itemId) { public AutopotAction(Client c, short slot, int itemId) {
this.c = c; this.c = c;
this.slot = slot; this.slot = slot;
this.itemId = itemId; this.itemId = itemId;
} }
public void run() { public void run() {
Client c = this.c; Client c = this.c;
Character chr = c.getPlayer(); Character chr = c.getPlayer();
@@ -86,10 +85,10 @@ public class PetAutopotProcessor {
c.sendPacket(PacketCreator.enableActions()); c.sendPacket(PacketCreator.enableActions());
return; return;
} }
int useCount = 0, qtyCount = 0; int useCount = 0, qtyCount = 0;
StatEffect stat = null; StatEffect stat = null;
maxHp = chr.getCurrentMaxHp(); maxHp = chr.getCurrentMaxHp();
maxMp = chr.getCurrentMaxMp(); maxMp = chr.getCurrentMaxMp();
@@ -119,12 +118,16 @@ public class PetAutopotProcessor {
stat = ItemInformationProvider.getInstance().getItemEffect(toUse.getItemId()); stat = ItemInformationProvider.getInstance().getItemEffect(toUse.getItemId());
hasHpGain = stat.getHp() > 0 || stat.getHpRate() > 0.0; hasHpGain = stat.getHp() > 0 || stat.getHpRate() > 0.0;
hasMpGain = stat.getMp() > 0 || stat.getMpRate() > 0.0; hasMpGain = stat.getMp() > 0 || stat.getMpRate() > 0.0;
incHp = stat.getHp(); incHp = stat.getHp();
if(incHp <= 0 && hasHpGain) incHp = Math.ceil(maxHp * stat.getHpRate()); if (incHp <= 0 && hasHpGain) {
incHp = Math.ceil(maxHp * stat.getHpRate());
}
incMp = stat.getMp(); incMp = stat.getMp();
if(incMp <= 0 && hasMpGain) incMp = Math.ceil(maxMp * stat.getMpRate()); if (incMp <= 0 && hasMpGain) {
incMp = Math.ceil(maxMp * stat.getMpRate());
}
if (YamlConfig.config.server.USE_COMPULSORY_AUTOPOT) { if (YamlConfig.config.server.USE_COMPULSORY_AUTOPOT) {
if (hasHpGain) { if (hasHpGain) {
@@ -140,7 +143,7 @@ public class PetAutopotProcessor {
qtyCount = Math.max(qtyCount, (int) Math.ceil(mpRatio / incMp)); qtyCount = Math.max(qtyCount, (int) Math.ceil(mpRatio / incMp));
} }
} }
if (qtyCount < 0) { // thanks Flint, Kevs for noticing an issue where negative counts were getting achieved if (qtyCount < 0) { // thanks Flint, Kevs for noticing an issue where negative counts were getting achieved
qtyCount = 0; qtyCount = 0;
} }
@@ -158,10 +161,10 @@ public class PetAutopotProcessor {
useCount += qtyToUse; useCount += qtyToUse;
qtyCount -= qtyToUse; qtyCount -= qtyToUse;
if(toUse.getQuantity() == 0 && qtyCount > 0) { if (toUse.getQuantity() == 0 && qtyCount > 0) {
// depleted out the current slot, fetch for more // depleted out the current slot, fetch for more
if(!cursorOnNextAvailablePot(chr)) { if (!cursorOnNextAvailablePot(chr)) {
break; // no more pots available break; // no more pots available
} }
} else { } else {
@@ -182,10 +185,10 @@ public class PetAutopotProcessor {
chr.sendPacket(PacketCreator.enableActions()); chr.sendPacket(PacketCreator.enableActions());
} }
} }
public static void runAutopotAction(Client c, short slot, int itemid) { public static void runAutopotAction(Client c, short slot, int itemid) {
AutopotAction action = new AutopotAction(c, slot, itemid); AutopotAction action = new AutopotAction(c, slot, itemid);
action.run(); action.run();
} }
} }

Some files were not shown because too many files have changed in this diff Show More