/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <[email protected]>
Matthias Butz <[email protected]>
Jan Christian Meyer <[email protected]>
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;
import java.util.LinkedList;
import java.util.List;
import server.MapleItemInformationProvider;
import tools.MaplePacketCreator;
import tools.Pair;
public class Equip extends Item implements IEquip {
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;
private int skill0, skill1, skill2, skill3;
public byte stars, potential;
public short potent1;
public short potent2;
public short potent3;
public Equip(int id, byte position) {
super(id, position, (short) 1);
this.itemExp = 0;
this.itemLevel = 1;
}
public Equip(int id, byte position, byte potential) {
super(id, position, (short) 1);
this.itemExp = 0;
this.itemLevel = 0;
this.ringid = -1;
if(potential > 1) {
this.potential = (byte) (potential + 4); // 1 =5, 2 = 6, etc
} else {
this.potential = potential;
}
}
public Equip(int id, byte position, int slots) {
super(id, position, (short) 1);
this.upgradeSlots = (byte) slots;
this.itemExp = 0;
this.itemLevel = 1;
}
@Override
public byte getStarsByte(){
if(potential == (byte)0){
return 0;
} else {
return stars;
}
}
@Override
public IItem 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.potential = potential;
ret.stars = stars;
ret.potent1 = potent1;
ret.potent2 = potent2;
ret.potent3 = potent3;
ret.log = new LinkedList<String>(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 IItem.EQUIP;
}
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;
}
public byte getPotential() {
return potential;
}
public short getPotent1() {
return potent1;
}
public short getPotent2() {
return potent2;
}
public short getPotent3() {
return potent3;
}
@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 setPotential(byte potent) {
this.potential = potent;
}
public void setPotent1(short potent) {
this.potent1 = potent;
}
public void setPotent2(short potent) {
this.potent2 = potent;
}
public void setPotent3(short potent) {
this.potent3 = potent;
}
public void gainLevel(MapleClient c, boolean timeless) {
List<Pair<String, Integer>> stats = MapleItemInformationProvider.getInstance().getItemLevelupStats(getItemId(), itemLevel, timeless);
for (Pair<String, Integer> stat : stats) {
if (stat.getLeft().equals("incDEX"))
dex += stat.getRight();
else if (stat.getLeft().equals("incSTR"))
str += stat.getRight();
else if (stat.getLeft().equals("incINT"))
_int += stat.getRight();
else if (stat.getLeft().equals("incLUK"))
luk += stat.getRight();
else if (stat.getLeft().equals("incMHP"))
hp += stat.getRight();
else if (stat.getLeft().equals("incMMP"))
mp += stat.getRight();
else if (stat.getLeft().equals("incPAD"))
watk += stat.getRight();
else if (stat.getLeft().equals("incMAD"))
matk += stat.getRight();
else if (stat.getLeft().equals("incPDD"))
wdef += stat.getRight();
else if (stat.getLeft().equals("incMDD"))
mdef += stat.getRight();
else if (stat.getLeft().equals("incEVA"))
avoid += stat.getRight();
else if (stat.getLeft().equals("incACC"))
acc += stat.getRight();
else if (stat.getLeft().equals("incSpeed"))
speed += stat.getRight();
else if (stat.getLeft().equals("incJump"))
jump += stat.getRight();
else if (stat.getLeft().equals("Skill0"))
skill0 = stat.getRight();
else if (stat.getLeft().equals("Skill1"))
skill1 = stat.getRight();
else if (stat.getLeft().equals("Skill2"))
skill2 = stat.getRight();
else if (stat.getLeft().equals("Skill3"))
skill3 = stat.getRight();
}
this.itemLevel++;
c.announce(MaplePacketCreator.showEquipmentLevelUp());
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showForeignEffect(c.getPlayer().getId(), 15));
c.getPlayer().forceUpdateItem(MapleInventoryType.EQUIPPED, 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(MapleInventoryType.EQUIPPED, 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;
}
}