Source for my MapleSolaxiaV2 (v83 MapleStory).
This commit is contained in:
ronancpl
2015-11-02 23:17:21 -02:00
parent 324982e94f
commit 972517e7b2
1675 changed files with 261831 additions and 0 deletions

View File

@@ -0,0 +1,371 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
import client.MapleClient;
import java.util.LinkedList;
import java.util.List;
import server.MapleItemInformationProvider;
import tools.MaplePacketCreator;
import tools.Pair;
public class Equip extends Item {
public static enum ScrollResult {
FAIL(0), SUCCESS(1), CURSE(2);
private int value = -1;
private ScrollResult(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
private byte upgradeSlots;
private byte level, flag, itemLevel;
private short str, dex, _int, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, vicious;
private float itemExp;
private int ringid = -1;
private boolean wear = false;
public Equip(int id, short position) {
super(id, position, (short) 1);
this.itemExp = 0;
this.itemLevel = 1;
}
public Equip(int id, short position, int slots) {
super(id, position, (short) 1);
this.upgradeSlots = (byte) slots;
this.itemExp = 0;
this.itemLevel = 1;
}
@Override
public Item copy() {
Equip ret = new Equip(getItemId(), getPosition(), getUpgradeSlots());
ret.str = str;
ret.dex = dex;
ret._int = _int;
ret.luk = luk;
ret.hp = hp;
ret.mp = mp;
ret.matk = matk;
ret.mdef = mdef;
ret.watk = watk;
ret.wdef = wdef;
ret.acc = acc;
ret.avoid = avoid;
ret.hands = hands;
ret.speed = speed;
ret.jump = jump;
ret.flag = flag;
ret.vicious = vicious;
ret.upgradeSlots = upgradeSlots;
ret.itemLevel = itemLevel;
ret.itemExp = itemExp;
ret.level = level;
ret.log = new LinkedList<>(log);
ret.setOwner(getOwner());
ret.setQuantity(getQuantity());
ret.setExpiration(getExpiration());
ret.setGiftFrom(getGiftFrom());
return ret;
}
@Override
public byte getFlag() {
return flag;
}
@Override
public byte getType() {
return 1;
}
public byte getUpgradeSlots() {
return upgradeSlots;
}
public short getStr() {
return str;
}
public short getDex() {
return dex;
}
public short getInt() {
return _int;
}
public short getLuk() {
return luk;
}
public short getHp() {
return hp;
}
public short getMp() {
return mp;
}
public short getWatk() {
return watk;
}
public short getMatk() {
return matk;
}
public short getWdef() {
return wdef;
}
public short getMdef() {
return mdef;
}
public short getAcc() {
return acc;
}
public short getAvoid() {
return avoid;
}
public short getHands() {
return hands;
}
public short getSpeed() {
return speed;
}
public short getJump() {
return jump;
}
public short getVicious() {
return vicious;
}
@Override
public void setFlag(byte flag) {
this.flag = flag;
}
public void setStr(short str) {
this.str = str;
}
public void setDex(short dex) {
this.dex = dex;
}
public void setInt(short _int) {
this._int = _int;
}
public void setLuk(short luk) {
this.luk = luk;
}
public void setHp(short hp) {
this.hp = hp;
}
public void setMp(short mp) {
this.mp = mp;
}
public void setWatk(short watk) {
this.watk = watk;
}
public void setMatk(short matk) {
this.matk = matk;
}
public void setWdef(short wdef) {
this.wdef = wdef;
}
public void setMdef(short mdef) {
this.mdef = mdef;
}
public void setAcc(short acc) {
this.acc = acc;
}
public void setAvoid(short avoid) {
this.avoid = avoid;
}
public void setHands(short hands) {
this.hands = hands;
}
public void setSpeed(short speed) {
this.speed = speed;
}
public void setJump(short jump) {
this.jump = jump;
}
public void setVicious(short vicious) {
this.vicious = vicious;
}
public void setUpgradeSlots(byte upgradeSlots) {
this.upgradeSlots = upgradeSlots;
}
public byte getLevel() {
return level;
}
public void setLevel(byte level) {
this.level = level;
}
public void gainLevel(MapleClient c, boolean timeless) {
List<Pair<String, Integer>> stats = MapleItemInformationProvider.getInstance().getItemLevelupStats(getItemId(), itemLevel, timeless);
for (Pair<String, Integer> stat : stats) {
switch (stat.getLeft()) {
case "incDEX":
dex += stat.getRight();
break;
case "incSTR":
str += stat.getRight();
break;
case "incINT":
_int += stat.getRight();
break;
case "incLUK":
luk += stat.getRight();
break;
case "incMHP":
hp += stat.getRight();
break;
case "incMMP":
mp += stat.getRight();
break;
case "incPAD":
watk += stat.getRight();
break;
case "incMAD":
matk += stat.getRight();
break;
case "incPDD":
wdef += stat.getRight();
break;
case "incMDD":
mdef += stat.getRight();
break;
case "incEVA":
avoid += stat.getRight();
break;
case "incACC":
acc += stat.getRight();
break;
case "incSpeed":
speed += stat.getRight();
break;
case "incJump":
jump += stat.getRight();
break;
}
}
this.itemLevel++;
c.announce(MaplePacketCreator.showEquipmentLevelUp());
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showForeignEffect(c.getPlayer().getId(), 15));
c.getPlayer().forceUpdateItem(this);
}
public int getItemExp() {
return (int) itemExp;
}
public void gainItemExp(MapleClient c, int gain, boolean timeless) {
int expneeded = timeless ? (10 * itemLevel + 70) : (5 * itemLevel + 65);
float modifier = 364 / expneeded;
float exp = (expneeded / (1000000 * modifier * modifier)) * gain;
itemExp += exp;
if (itemExp >= 364) {
itemExp = (itemExp - 364);
gainLevel(c, timeless);
} else {
c.getPlayer().forceUpdateItem(this);
}
}
public void setItemExp(int exp) {
this.itemExp = exp;
}
public void setItemLevel(byte level) {
this.itemLevel = level;
}
@Override
public void setQuantity(short quantity) {
if (quantity < 0 || quantity > 1) {
throw new RuntimeException("Setting the quantity to " + quantity + " on an equip (itemid: " + getItemId() + ")");
}
super.setQuantity(quantity);
}
public void setUpgradeSlots(int i) {
this.upgradeSlots = (byte) i;
}
public void setVicious(int i) {
this.vicious = (short) i;
}
public int getRingId() {
return ringid;
}
public void setRingId(int id) {
this.ringid = id;
}
public boolean isWearing() {
return wear;
}
public void wear(boolean yes) {
wear = yes;
}
public byte getItemLevel() {
return itemLevel;
}
}

View File

@@ -0,0 +1,172 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class Item implements Comparable<Item> {
private int id, cashId, sn;
private short position;
private short quantity;
private int petid = -1;
private MaplePet pet = null;
private String owner = "";
protected List<String> log;
private byte flag;
private long expiration = -1;
private String giftFrom = "";
public Item(int id, short position, short quantity) {
this.id = id;
this.position = position;
this.quantity = quantity;
this.log = new LinkedList<>();
this.flag = 0;
}
public Item(int id, short position, short quantity, int petid) {
this.id = id;
this.position = position;
this.quantity = quantity;
this.petid = petid;
if (petid > -1) this.pet = MaplePet.loadFromDb(id, position, petid);
this.flag = 0;
this.log = new LinkedList<>();
}
public Item copy() {
Item ret = new Item(id, position, quantity, petid);
ret.flag = flag;
ret.owner = owner;
ret.expiration = expiration;
ret.log = new LinkedList<>(log);
return ret;
}
public void setPosition(short position) {
this.position = position;
}
public void setQuantity(short quantity) {
this.quantity = quantity;
}
public int getItemId() {
return id;
}
public int getCashId() {
if (cashId == 0) {
cashId = new Random().nextInt(Integer.MAX_VALUE) + 1;
}
return cashId;
}
public short getPosition() {
return position;
}
public short getQuantity() {
return quantity;
}
public byte getType() {
if (getPetId() > -1) {
return 3;
}
return 2;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public int getPetId() {
return petid;
}
public void setPetId(int id) {
this.petid = id;
}
public int compareTo(Item other) {
if (this.id < other.getItemId()) {
return -1;
} else if (this.id > other.getItemId()) {
return 1;
}
return 0;
}
@Override
public String toString() {
return "Item: " + id + " quantity: " + quantity;
}
public List<String> getLog() {
return Collections.unmodifiableList(log);
}
public byte getFlag() {
return flag;
}
public void setFlag(byte b) {
this.flag = b;
}
public long getExpiration() {
return expiration;
}
public void setExpiration(long expire) {
this.expiration = expire;
}
public int getSN() {
return sn;
}
public void setSN(int sn) {
this.sn = sn;
}
public String getGiftFrom() {
return giftFrom;
}
public void setGiftFrom(String giftFrom) {
this.giftFrom = giftFrom;
}
public MaplePet getPet() {
return pet;
}
}

View File

@@ -0,0 +1,227 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import tools.DatabaseConnection;
import tools.Pair;
/**
*
* @author Flav
*/
public enum ItemFactory {
INVENTORY(1, false),
STORAGE(2, true),
CASH_EXPLORER(3, true),
CASH_CYGNUS(4, false),
CASH_ARAN(5, false),
MERCHANT(6, false);
private int value;
private boolean account;
private static ReentrantLock lock = new ReentrantLock(true);
private ItemFactory(int value, boolean account) {
this.value = value;
this.account = account;
}
public int getValue() {
return value;
}
public List<Pair<Item, MapleInventoryType>> loadItems(int id, boolean login) throws SQLException {
List<Pair<Item, MapleInventoryType>> items = new ArrayList<>();
PreparedStatement ps = null;
ResultSet rs = null;
try {
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM `inventoryitems` LEFT JOIN `inventoryequipment` USING(`inventoryitemid`) WHERE `type` = ? AND `");
query.append(account ? "accountid" : "characterid").append("` = ?");
if (login) {
query.append(" AND `inventorytype` = ").append(MapleInventoryType.EQUIPPED.getType());
}
ps = DatabaseConnection.getConnection().prepareStatement(query.toString());
ps.setInt(1, value);
ps.setInt(2, id);
rs = ps.executeQuery();
while (rs.next()) {
MapleInventoryType mit = MapleInventoryType.getByType(rs.getByte("inventorytype"));
if (mit.equals(MapleInventoryType.EQUIP) || mit.equals(MapleInventoryType.EQUIPPED)) {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"));
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) rs.getInt("quantity"));
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setFlag((byte) rs.getInt("flag"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getByte("level"));
equip.setItemExp(rs.getInt("itemexp"));
equip.setItemLevel(rs.getByte("itemlevel"));
equip.setExpiration(rs.getLong("expiration"));
equip.setGiftFrom(rs.getString("giftFrom"));
equip.setRingId(rs.getInt("ringid"));
items.add(new Pair<Item, MapleInventoryType>(equip, mit));
} else {
Item item = new Item(rs.getInt("itemid"), (byte) rs.getInt("position"), (short) rs.getInt("quantity"), rs.getInt("petid"));
item.setOwner(rs.getString("owner"));
item.setExpiration(rs.getLong("expiration"));
item.setGiftFrom(rs.getString("giftFrom"));
item.setFlag((byte) rs.getInt("flag"));
items.add(new Pair<>(item, mit));
}
}
rs.close();
ps.close();
} finally {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
}
return items;
}
public synchronized void saveItems(List<Pair<Item, MapleInventoryType>> items, int id, Connection con) throws SQLException {
PreparedStatement ps = null;
PreparedStatement pse = null;
ResultSet rs = null;
lock.lock();
try {
StringBuilder query = new StringBuilder();
query.append("DELETE `inventoryitems`, `inventoryequipment` FROM `inventoryitems` LEFT JOIN `inventoryequipment` USING(`inventoryitemid`) WHERE `type` = ? AND `");
query.append(account ? "accountid" : "characterid").append("` = ?");
ps = con.prepareStatement(query.toString());
ps.setInt(1, value);
ps.setInt(2, id);
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("INSERT INTO `inventoryitems` VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
if (!items.isEmpty()) {
for (Pair<Item, MapleInventoryType> pair : items) {
Item item = pair.getLeft();
MapleInventoryType mit = pair.getRight();
ps.setInt(1, value);
ps.setString(2, account ? null : String.valueOf(id));
ps.setString(3, account ? String.valueOf(id) : null);
ps.setInt(4, item.getItemId());
ps.setInt(5, mit.getType());
ps.setInt(6, item.getPosition());
ps.setInt(7, item.getQuantity());
ps.setString(8, item.getOwner());
ps.setInt(9, item.getPetId());
ps.setInt(10, item.getFlag());
ps.setLong(11, item.getExpiration());
ps.setString(12, item.getGiftFrom());
ps.executeUpdate();
pse = con.prepareStatement("INSERT INTO `inventoryequipment` VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if (mit.equals(MapleInventoryType.EQUIP) || mit.equals(MapleInventoryType.EQUIPPED)) {
rs = ps.getGeneratedKeys();
if (!rs.next()) {
throw new RuntimeException("Inserting item failed.");
}
pse.setInt(1, rs.getInt(1));
rs.close();
Equip equip = (Equip) item;
pse.setInt(2, equip.getUpgradeSlots());
pse.setInt(3, equip.getLevel());
pse.setInt(4, equip.getStr());
pse.setInt(5, equip.getDex());
pse.setInt(6, equip.getInt());
pse.setInt(7, equip.getLuk());
pse.setInt(8, equip.getHp());
pse.setInt(9, equip.getMp());
pse.setInt(10, equip.getWatk());
pse.setInt(11, equip.getMatk());
pse.setInt(12, equip.getWdef());
pse.setInt(13, equip.getMdef());
pse.setInt(14, equip.getAcc());
pse.setInt(15, equip.getAvoid());
pse.setInt(16, equip.getHands());
pse.setInt(17, equip.getSpeed());
pse.setInt(18, equip.getJump());
pse.setInt(19, 0);
pse.setInt(20, equip.getVicious());
pse.setInt(21, equip.getItemLevel());
pse.setInt(22, equip.getItemExp());
pse.setInt(23, equip.getRingId());
pse.executeUpdate();
}
pse.close();
}
}
ps.close();
} finally {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (pse != null && !pse.isClosed()) {
pse.close();
}
if(rs != null && !rs.isClosed()) {
rs.close();
}
lock.unlock();
}
}
}

View File

@@ -0,0 +1,281 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import tools.Pair;
import client.MapleCharacter;
import constants.ItemConstants;
/**
*
* @author Matze
*/
public class MapleInventory implements Iterable<Item> {
private Map<Short, Item> inventory = new LinkedHashMap<>();
private byte slotLimit;
private MapleInventoryType type;
private boolean checked = false;
public MapleInventory(MapleInventoryType type, byte slotLimit) {
this.inventory = new LinkedHashMap<>();
this.type = type;
this.slotLimit = slotLimit;
}
public boolean isExtendableInventory() { // not sure about cash, basing this on the previous one.
return !(type.equals(MapleInventoryType.UNDEFINED) || type.equals(MapleInventoryType.EQUIPPED) || type.equals(MapleInventoryType.CASH));
}
public boolean isEquipInventory() {
return type.equals(MapleInventoryType.EQUIP) || type.equals(MapleInventoryType.EQUIPPED);
}
public byte getSlotLimit() {
return slotLimit;
}
public void setSlotLimit(int newLimit) {
slotLimit = (byte) newLimit;
}
public Item findById(int itemId) {
for (Item item : inventory.values()) {
if (item.getItemId() == itemId) {
return item;
}
}
return null;
}
public int countById(int itemId) {
int possesed = 0;
for (Item item : inventory.values()) {
if (item.getItemId() == itemId) {
possesed += item.getQuantity();
}
}
return possesed;
}
public List<Item> listById(int itemId) {
List<Item> ret = new ArrayList<>();
for (Item item : inventory.values()) {
if (item.getItemId() == itemId) {
ret.add(item);
}
}
if (ret.size() > 1) {
Collections.sort(ret);
}
return ret;
}
public Collection<Item> list() {
return inventory.values();
}
public short addItem(Item item) {
short slotId = getNextFreeSlot();
if (slotId < 0 || item == null) {
return -1;
}
inventory.put(slotId, item);
item.setPosition(slotId);
return slotId;
}
public void addFromDB(Item item) {
if (item.getPosition() < 0 && !type.equals(MapleInventoryType.EQUIPPED)) {
return;
}
inventory.put(item.getPosition(), item);
}
public void move(short sSlot, short dSlot, short slotMax) {
Item source = (Item) inventory.get(sSlot);
Item target = (Item) inventory.get(dSlot);
if (source == null) {
return;
}
if (target == null) {
source.setPosition(dSlot);
inventory.put(dSlot, source);
inventory.remove(sSlot);
} else if (target.getItemId() == source.getItemId() && !ItemConstants.isRechargable(source.getItemId())) {
if (type.getType() == MapleInventoryType.EQUIP.getType()) {
swap(target, source);
}
if (source.getQuantity() + target.getQuantity() > slotMax) {
short rest = (short) ((source.getQuantity() + target.getQuantity()) - slotMax);
source.setQuantity(rest);
target.setQuantity(slotMax);
} else {
target.setQuantity((short) (source.getQuantity() + target.getQuantity()));
inventory.remove(sSlot);
}
} else {
swap(target, source);
}
}
private void swap(Item source, Item target) {
inventory.remove(source.getPosition());
inventory.remove(target.getPosition());
short swapPos = source.getPosition();
source.setPosition(target.getPosition());
target.setPosition(swapPos);
inventory.put(source.getPosition(), source);
inventory.put(target.getPosition(), target);
}
public Item getItem(short slot) {
return inventory.get(slot);
}
public void removeItem(short slot) {
removeItem(slot, (short) 1, false);
}
public void removeItem(short slot, short quantity, boolean allowZero) {
Item item = inventory.get(slot);
if (item == null) {// TODO is it ok not to throw an exception here?
return;
}
item.setQuantity((short) (item.getQuantity() - quantity));
if (item.getQuantity() < 0) {
item.setQuantity((short) 0);
}
if (item.getQuantity() == 0 && !allowZero) {
removeSlot(slot);
}
}
public void removeSlot(short slot) {
inventory.remove(slot);
}
public boolean isFull() {
return inventory.size() >= slotLimit;
}
public boolean isFull(int margin) {
return inventory.size() + margin >= slotLimit;
}
public short getNextFreeSlot() {
if (isFull()) {
return -1;
}
for (short i = 1; i <= slotLimit; i++) {
if (!inventory.keySet().contains(i)) {
return i;
}
}
return -1;
}
public short getNumFreeSlot() {
if (isFull()) {
return 0;
}
short free = 0;
for (short i = 1; i <= slotLimit; i++) {
if (!inventory.keySet().contains(i)) {
free++;
}
}
return free;
}
public static boolean checkSpot(MapleCharacter chr, Item item) {
if (chr.getInventory(MapleInventoryType.getByType(item.getType())).isFull()) return false;
return true;
}
public static boolean checkSpots(MapleCharacter chr, List<Pair<Item, MapleInventoryType>> items) {
int equipSlot = 0, useSlot = 0, setupSlot = 0, etcSlot = 0, cashSlot = 0;
for (Pair<Item, MapleInventoryType> item : items) {
if (item.getRight().getType() == MapleInventoryType.EQUIP.getType())
equipSlot++;
if (item.getRight().getType() == MapleInventoryType.USE.getType())
useSlot++;
if (item.getRight().getType() == MapleInventoryType.SETUP.getType())
setupSlot++;
if (item.getRight().getType() == MapleInventoryType.ETC.getType())
etcSlot++;
if (item.getRight().getType() == MapleInventoryType.CASH.getType())
cashSlot++;
}
if (chr.getInventory(MapleInventoryType.EQUIP).isFull(equipSlot - 1)) return false;
else if (chr.getInventory(MapleInventoryType.USE).isFull(useSlot - 1)) return false;
else if (chr.getInventory(MapleInventoryType.SETUP).isFull(setupSlot - 1)) return false;
else if (chr.getInventory(MapleInventoryType.ETC).isFull(etcSlot - 1)) return false;
else if (chr.getInventory(MapleInventoryType.CASH).isFull(cashSlot - 1)) return false;
return true;
}
public MapleInventoryType getType() {
return type;
}
@Override
public Iterator<Item> iterator() {
return Collections.unmodifiableCollection(inventory.values()).iterator();
}
public Collection<MapleInventory> allInventories() {
return Collections.singletonList(this);
}
public Item findByCashId(int cashId) {
boolean isRing = false;
Equip equip = null;
for (Item item : inventory.values()) {
if (item.getType() == MapleInventoryType.EQUIP.getType()) {
equip = (Equip) item;
isRing = equip.getRingId() > -1;
}
if ((item.getPetId() > -1 ? item.getPetId() : isRing ? equip.getRingId() : item.getCashId()) == cashId)
return item;
}
return null;
}
public boolean checked() {
return checked;
}
public void checked(boolean yes) {
checked = yes;
}
}

View File

@@ -0,0 +1,72 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
/**
* @author Matze
*/
public enum MapleInventoryType {
UNDEFINED(0),
EQUIP(1),
USE(2),
SETUP(3),
ETC(4),
CASH(5),
EQUIPPED(-1); //Seems nexon screwed something when removing an item T_T
final byte type;
private MapleInventoryType(int type) {
this.type = (byte) type;
}
public byte getType() {
return type;
}
public short getBitfieldEncoding() {
return (short) (2 << type);
}
public static MapleInventoryType getByType(byte type) {
for (MapleInventoryType l : MapleInventoryType.values()) {
if (l.getType() == type) {
return l;
}
}
return null;
}
public static MapleInventoryType getByWZName(String name) {
if (name.equals("Install")) {
return SETUP;
} else if (name.equals("Consume")) {
return USE;
} else if (name.equals("Etc")) {
return ETC;
} else if (name.equals("Cash")) {
return CASH;
} else if (name.equals("Pet")) {
return CASH;
}
return UNDEFINED;
}
}

View File

@@ -0,0 +1,229 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
import com.mysql.jdbc.Statement;
import java.awt.Point;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import tools.DatabaseConnection;
import server.MapleItemInformationProvider;
import server.movement.AbsoluteLifeMovement;
import server.movement.LifeMovement;
import server.movement.LifeMovementFragment;
/**
*
* @author Matze
*/
public class MaplePet extends Item {
private String name;
private int uniqueid;
private int closeness = 0;
private byte level = 1;
private int fullness = 100;
private int Fh;
private Point pos;
private int stance;
private boolean summoned;
private MaplePet(int id, short position, int uniqueid) {
super(id, position, (short) 1);
this.uniqueid = uniqueid;
}
public static MaplePet loadFromDb(int itemid, short position, int petid) {
try {
MaplePet ret = new MaplePet(itemid, position, petid);
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name, level, closeness, fullness, summoned FROM pets WHERE petid = ?"); // Get pet details..
ps.setInt(1, petid);
ResultSet rs = ps.executeQuery();
rs.next();
ret.setName(rs.getString("name"));
ret.setCloseness(Math.min(rs.getInt("closeness"), 30000));
ret.setLevel((byte) Math.min(rs.getByte("level"), 30));
ret.setFullness(Math.min(rs.getInt("fullness"), 100));
ret.setSummoned(rs.getInt("summoned") == 1);
rs.close();
ps.close();
return ret;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
public void saveToDb() {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE pets SET name = ?, level = ?, closeness = ?, fullness = ?, summoned = ? WHERE petid = ?");
ps.setString(1, getName());
ps.setInt(2, getLevel());
ps.setInt(3, getCloseness());
ps.setInt(4, getFullness());
ps.setInt(5, isSummoned() ? 1 : 0);
ps.setInt(6, getUniqueId());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static int createPet(int itemid) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, 1, 0, 100, 0)", Statement.RETURN_GENERATED_KEYS);
ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
int ret = -1;
if (rs.next()) {
ret = rs.getInt(1);
}
rs.close();
ps.close();
return ret;
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
public static int createPet(int itemid, byte level, int closeness, int fullness) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, ?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS);
ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
ps.setByte(2, level);
ps.setInt(3, closeness);
ps.setInt(4, fullness);
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
int ret = -1;
if (rs.next()) {
ret = rs.getInt(1);
rs.close();
ps.close();
}
return ret;
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getUniqueId() {
return uniqueid;
}
public void setUniqueId(int id) {
this.uniqueid = id;
}
public int getCloseness() {
return closeness;
}
public void setCloseness(int closeness) {
this.closeness = closeness;
}
public void gainCloseness(int x) {
this.closeness += x;
}
public byte getLevel() {
return level;
}
public void setLevel(byte level) {
this.level = level;
}
public int getFullness() {
return fullness;
}
public void setFullness(int fullness) {
this.fullness = fullness;
}
public int getFh() {
return Fh;
}
public void setFh(int Fh) {
this.Fh = Fh;
}
public Point getPos() {
return pos;
}
public void setPos(Point pos) {
this.pos = pos;
}
public int getStance() {
return stance;
}
public void setStance(int stance) {
this.stance = stance;
}
public boolean isSummoned() {
return summoned;
}
public void setSummoned(boolean yes) {
this.summoned = yes;
}
public boolean canConsume(int itemId) {
for (int petId : MapleItemInformationProvider.getInstance().petsCanConsume(itemId)) {
if (petId == this.getItemId()) {
return true;
}
}
return false;
}
public void updatePosition(List<LifeMovementFragment> movement) {
for (LifeMovementFragment move : movement) {
if (move instanceof LifeMovement) {
if (move instanceof AbsoluteLifeMovement) {
this.setPos(((LifeMovement) move).getPosition());
}
this.setStance(((LifeMovement) move).getNewstate());
}
}
}
}

View File

@@ -0,0 +1,54 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
public enum MapleWeaponType {
NOT_A_WEAPON(0),
GENERAL1H_SWING(4.4),
GENERAL1H_STAB(3.2),
GENERAL2H_SWING(4.8),
GENERAL2H_STAB(3.4),
BOW(3.4),
CLAW(3.6),
CROSSBOW(3.6),
DAGGER_THIEVES(3.6),
DAGGER_OTHER(4),
GUN(3.6),
KNUCKLE(4.8),
POLE_ARM_SWING(5.0),
POLE_ARM_STAB(3.0),
SPEAR_STAB(5.0),
SPEAR_SWING(3.0),
STAFF(3.6),
SWORD1H(4.0),
SWORD2H(4.6),
WAND(3.6);
private double damageMultiplier;
private MapleWeaponType(double maxDamageMultiplier) {
this.damageMultiplier = maxDamageMultiplier;
}
public double getMaxDamageMultiplier() {
return damageMultiplier;
}
}

View File

@@ -0,0 +1,53 @@
package client.inventory;
import constants.ItemConstants;
/**
*
* @author kevin
*/
public class ModifyInventory {
private int mode;
private Item item;
private short oldPos;
public ModifyInventory(final int mode, final Item item) {
this.mode = mode;
this.item = item.copy();
}
public ModifyInventory(final int mode, final Item item, final short oldPos) {
this.mode = mode;
this.item = item.copy();
this.oldPos = oldPos;
}
public final int getMode() {
return mode;
}
public final int getInventoryType() {
return ItemConstants.getInventoryType(item.getItemId()).getType();
}
public final short getPosition() {
return item.getPosition();
}
public final short getOldPosition() {
return oldPos;
}
public final short getQuantity() {
return item.getQuantity();
}
public final Item getItem() {
return item;
}
public final void clear() {
this.item = null;
}
}

View File

@@ -0,0 +1,52 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
/*
* @author Leifde
*/
public class PetCommand {
private int petId, skillId, prob, inc;
public PetCommand(int petId, int skillId, int prob, int inc) {
this.petId = petId;
this.skillId = skillId;
this.prob = prob;
this.inc = inc;
}
public int getPetId() {
return petId;
}
public int getSkillId() {
return skillId;
}
public int getProbability() {
return prob;
}
public int getIncrease() {
return inc;
}
}

View File

@@ -0,0 +1,76 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.inventory;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import provider.MapleData;
import provider.MapleDataProvider;
import provider.MapleDataProviderFactory;
import provider.MapleDataTool;
/**
*
* @author Danny (Leifde)
*/
public class PetDataFactory {
private static MapleDataProvider dataRoot = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Item.wz"));
private static Map<String, PetCommand> petCommands = new HashMap<String, PetCommand>();
private static Map<Integer, Integer> petHunger = new HashMap<Integer, Integer>();
public static PetCommand getPetCommand(int petId, int skillId) {
PetCommand ret = petCommands.get(Integer.valueOf(petId) + "" + skillId);
if (ret != null) {
return ret;
}
synchronized (petCommands) {
ret = petCommands.get(petId + "" + skillId);
if (ret == null) {
MapleData skillData = dataRoot.getData("Pet/" + petId + ".img");
int prob = 0;
int inc = 0;
if (skillData != null) {
prob = MapleDataTool.getInt("interact/" + skillId + "/prob", skillData, 0);
inc = MapleDataTool.getInt("interact/" + skillId + "/inc", skillData, 0);
}
ret = new PetCommand(petId, skillId, prob, inc);
petCommands.put(petId + "" + skillId, ret);
}
return ret;
}
}
public static int getHunger(int petId) {
Integer ret = petHunger.get(Integer.valueOf(petId));
if (ret != null) {
return ret;
}
synchronized (petHunger) {
ret = petHunger.get(Integer.valueOf(petId));
if (ret == null) {
ret = Integer.valueOf(MapleDataTool.getInt(dataRoot.getData("Pet/" + petId + ".img").getChildByPath("info/hungry"), 1));
}
return ret;
}
}
}