Refactor CashShop - add constants for cash types
This commit is contained in:
@@ -2068,7 +2068,7 @@ public class Character extends AbstractCharacterObject {
|
|||||||
this.getCashShop().gainCash(1, nxGain);
|
this.getCashShop().gainCash(1, nxGain);
|
||||||
|
|
||||||
if (YamlConfig.config.server.USE_ANNOUNCE_NX_COUPON_LOOT) {
|
if (YamlConfig.config.server.USE_ANNOUNCE_NX_COUPON_LOOT) {
|
||||||
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
|
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(CashShop.NX_CREDIT) + " NX)", 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getMap().pickItemDrop(pickupPacket, mapitem);
|
this.getMap().pickItemDrop(pickupPacket, mapitem);
|
||||||
@@ -2120,7 +2120,7 @@ public class Character extends AbstractCharacterObject {
|
|||||||
this.getCashShop().gainCash(1, nxGain);
|
this.getCashShop().gainCash(1, nxGain);
|
||||||
|
|
||||||
if (YamlConfig.config.server.USE_ANNOUNCE_NX_COUPON_LOOT) {
|
if (YamlConfig.config.server.USE_ANNOUNCE_NX_COUPON_LOOT) {
|
||||||
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
|
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(CashShop.NX_CREDIT) + " NX)", 300);
|
||||||
}
|
}
|
||||||
} else if (applyConsumeOnPickup(mItem.getItemId())) {
|
} else if (applyConsumeOnPickup(mItem.getItemId())) {
|
||||||
} else if (InventoryManipulator.addFromDrop(client, mItem, true)) {
|
} else if (InventoryManipulator.addFromDrop(client, mItem, true)) {
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
|||||||
CashItem cItem = CashItemFactory.getItem(p.readInt());
|
CashItem cItem = CashItemFactory.getItem(p.readInt());
|
||||||
Map<String, String> recipient = Character.getCharacterFromDatabase(p.readString());
|
Map<String, String> recipient = Character.getCharacterFromDatabase(p.readString());
|
||||||
String message = p.readString();
|
String message = p.readString();
|
||||||
if (!canBuy(chr, cItem, cs.getCash(4)) || message.length() < 1 || message.length() > 73) {
|
if (!canBuy(chr, cItem, cs.getCash(CashShop.NX_PREPAID)) || message.isEmpty() || message.length() > 73) {
|
||||||
c.enableCSActions();
|
c.enableCSActions();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -405,7 +405,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
|||||||
c.sendPacket(PacketCreator.showCash(c.getPlayer()));
|
c.sendPacket(PacketCreator.showCash(c.getPlayer()));
|
||||||
} else if (action == 0x2E) { //name change
|
} else if (action == 0x2E) { //name change
|
||||||
CashItem cItem = CashItemFactory.getItem(p.readInt());
|
CashItem cItem = CashItemFactory.getItem(p.readInt());
|
||||||
if (cItem == null || !canBuy(chr, cItem, cs.getCash(4))) {
|
if (cItem == null || !canBuy(chr, cItem, cs.getCash(CashShop.NX_PREPAID))) {
|
||||||
c.sendPacket(PacketCreator.showCashShopMessage((byte) 0));
|
c.sendPacket(PacketCreator.showCashShopMessage((byte) 0));
|
||||||
c.enableCSActions();
|
c.enableCSActions();
|
||||||
return;
|
return;
|
||||||
@@ -434,7 +434,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
|||||||
c.enableCSActions();
|
c.enableCSActions();
|
||||||
} else if (action == 0x31) { //world transfer
|
} else if (action == 0x31) { //world transfer
|
||||||
CashItem cItem = CashItemFactory.getItem(p.readInt());
|
CashItem cItem = CashItemFactory.getItem(p.readInt());
|
||||||
if (cItem == null || !canBuy(chr, cItem, cs.getCash(4))) {
|
if (cItem == null || !canBuy(chr, cItem, cs.getCash(CashShop.NX_PREPAID))) {
|
||||||
c.sendPacket(PacketCreator.showCashShopMessage((byte) 0));
|
c.sendPacket(PacketCreator.showCashShopMessage((byte) 0));
|
||||||
c.enableCSActions();
|
c.enableCSActions();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import net.server.Server;
|
|||||||
import net.server.channel.Channel;
|
import net.server.channel.Channel;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import server.CashShop;
|
||||||
import server.ItemInformationProvider;
|
import server.ItemInformationProvider;
|
||||||
import server.MTSItemInfo;
|
import server.MTSItemInfo;
|
||||||
import tools.DatabaseConnection;
|
import tools.DatabaseConnection;
|
||||||
@@ -402,7 +403,7 @@ public final class MTSHandler extends AbstractPacketHandler {
|
|||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1); // taxes
|
int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1); // taxes
|
||||||
if (c.getPlayer().getCashShop().getCash(4) >= price) { // FIX
|
if (c.getPlayer().getCashShop().getCash(CashShop.NX_PREPAID) >= price) { // FIX
|
||||||
boolean alwaysnull = true;
|
boolean alwaysnull = true;
|
||||||
for (Channel cserv : Server.getInstance().getAllChannels()) {
|
for (Channel cserv : Server.getInstance().getAllChannels()) {
|
||||||
Character victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
|
Character victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
|
||||||
@@ -459,11 +460,11 @@ public final class MTSHandler extends AbstractPacketHandler {
|
|||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
|
int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
|
||||||
if (c.getPlayer().getCashShop().getCash(4) >= price) {
|
if (c.getPlayer().getCashShop().getCash(CashShop.NX_PREPAID) >= price) {
|
||||||
for (Channel cserv : Server.getInstance().getAllChannels()) {
|
for (Channel cserv : Server.getInstance().getAllChannels()) {
|
||||||
Character victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
|
Character victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
|
||||||
if (victim != null) {
|
if (victim != null) {
|
||||||
victim.getCashShop().gainCash(4, rs.getInt("price"));
|
victim.getCashShop().gainCash(CashShop.NX_PREPAID, rs.getInt("price"));
|
||||||
} else {
|
} else {
|
||||||
try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
|
try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
|
||||||
pse.setInt(1, rs.getInt("seller"));
|
pse.setInt(1, rs.getInt("seller"));
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import provider.DataProviderFactory;
|
|||||||
import provider.DataTool;
|
import provider.DataTool;
|
||||||
import provider.wz.WZFiles;
|
import provider.wz.WZFiles;
|
||||||
import tools.DatabaseConnection;
|
import tools.DatabaseConnection;
|
||||||
import tools.PacketCreator;
|
|
||||||
import tools.Pair;
|
import tools.Pair;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -58,6 +57,71 @@ import static java.util.concurrent.TimeUnit.HOURS;
|
|||||||
* @author Flav
|
* @author Flav
|
||||||
*/
|
*/
|
||||||
public class CashShop {
|
public class CashShop {
|
||||||
|
public static final int NX_CREDIT = 1;
|
||||||
|
public static final int MAPLE_POINT = 2;
|
||||||
|
public static final int NX_PREPAID = 4;
|
||||||
|
|
||||||
|
private final int accountId;
|
||||||
|
private final int characterId;
|
||||||
|
private int nxCredit;
|
||||||
|
private int maplePoint;
|
||||||
|
private int nxPrepaid;
|
||||||
|
private boolean opened;
|
||||||
|
private ItemFactory factory;
|
||||||
|
private final List<Item> inventory = new ArrayList<>();
|
||||||
|
private final List<Integer> wishList = new ArrayList<>();
|
||||||
|
private int notes = 0;
|
||||||
|
private final Lock lock = new ReentrantLock();
|
||||||
|
|
||||||
|
public CashShop(int accountId, int characterId, int jobType) throws SQLException {
|
||||||
|
this.accountId = accountId;
|
||||||
|
this.characterId = characterId;
|
||||||
|
|
||||||
|
if (!YamlConfig.config.server.USE_JOINT_CASHSHOP_INVENTORY) {
|
||||||
|
switch (jobType) {
|
||||||
|
case 0:
|
||||||
|
factory = ItemFactory.CASH_EXPLORER;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
factory = ItemFactory.CASH_CYGNUS;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
factory = ItemFactory.CASH_ARAN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
factory = ItemFactory.CASH_OVERALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
|
try (PreparedStatement ps = con.prepareStatement("SELECT `nxCredit`, `maplePoint`, `nxPrepaid` FROM `accounts` WHERE `id` = ?")) {
|
||||||
|
ps.setInt(1, accountId);
|
||||||
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
this.nxCredit = rs.getInt("nxCredit");
|
||||||
|
this.maplePoint = rs.getInt("maplePoint");
|
||||||
|
this.nxPrepaid = rs.getInt("nxPrepaid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Pair<Item, InventoryType> item : factory.loadItems(accountId, false)) {
|
||||||
|
inventory.add(item.getLeft());
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = con.prepareStatement("SELECT `sn` FROM `wishlists` WHERE `charid` = ?")) {
|
||||||
|
ps.setInt(1, characterId);
|
||||||
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
wishList.add(rs.getInt("sn"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class CashItem {
|
public static class CashItem {
|
||||||
|
|
||||||
private final int sn;
|
private final int sn;
|
||||||
@@ -259,91 +323,21 @@ public class CashShop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int accountId;
|
|
||||||
private final int characterId;
|
|
||||||
private int nxCredit;
|
|
||||||
private int maplePoint;
|
|
||||||
private int nxPrepaid;
|
|
||||||
private boolean opened;
|
|
||||||
private ItemFactory factory;
|
|
||||||
private final List<Item> inventory = new ArrayList<>();
|
|
||||||
private final List<Integer> wishList = new ArrayList<>();
|
|
||||||
private int notes = 0;
|
|
||||||
private final Lock lock = new ReentrantLock();
|
|
||||||
|
|
||||||
public CashShop(int accountId, int characterId, int jobType) throws SQLException {
|
|
||||||
this.accountId = accountId;
|
|
||||||
this.characterId = characterId;
|
|
||||||
|
|
||||||
if (!YamlConfig.config.server.USE_JOINT_CASHSHOP_INVENTORY) {
|
|
||||||
switch (jobType) {
|
|
||||||
case 0:
|
|
||||||
factory = ItemFactory.CASH_EXPLORER;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
factory = ItemFactory.CASH_CYGNUS;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
factory = ItemFactory.CASH_ARAN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
factory = ItemFactory.CASH_OVERALL;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (Connection con = DatabaseConnection.getConnection()) {
|
|
||||||
try (PreparedStatement ps = con.prepareStatement("SELECT `nxCredit`, `maplePoint`, `nxPrepaid` FROM `accounts` WHERE `id` = ?")) {
|
|
||||||
ps.setInt(1, accountId);
|
|
||||||
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
|
||||||
if (rs.next()) {
|
|
||||||
this.nxCredit = rs.getInt("nxCredit");
|
|
||||||
this.maplePoint = rs.getInt("maplePoint");
|
|
||||||
this.nxPrepaid = rs.getInt("nxPrepaid");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Pair<Item, InventoryType> item : factory.loadItems(accountId, false)) {
|
|
||||||
inventory.add(item.getLeft());
|
|
||||||
}
|
|
||||||
|
|
||||||
try (PreparedStatement ps = con.prepareStatement("SELECT `sn` FROM `wishlists` WHERE `charid` = ?")) {
|
|
||||||
ps.setInt(1, characterId);
|
|
||||||
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
|
||||||
while (rs.next()) {
|
|
||||||
wishList.add(rs.getInt("sn"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCash(int type) {
|
public int getCash(int type) {
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case 1:
|
case NX_CREDIT -> nxCredit;
|
||||||
return nxCredit;
|
case MAPLE_POINT -> maplePoint;
|
||||||
case 2:
|
case NX_PREPAID -> nxPrepaid;
|
||||||
return maplePoint;
|
default -> 0;
|
||||||
case 4:
|
};
|
||||||
return nxPrepaid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gainCash(int type, int cash) {
|
public void gainCash(int type, int cash) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 1:
|
case NX_CREDIT -> nxCredit += cash;
|
||||||
nxCredit += cash;
|
case MAPLE_POINT -> maplePoint += cash;
|
||||||
break;
|
case NX_PREPAID -> nxPrepaid += cash;
|
||||||
case 2:
|
|
||||||
maplePoint += cash;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
nxPrepaid += cash;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ import net.server.world.Party;
|
|||||||
import net.server.world.PartyCharacter;
|
import net.server.world.PartyCharacter;
|
||||||
import net.server.world.PartyOperation;
|
import net.server.world.PartyOperation;
|
||||||
import net.server.world.World;
|
import net.server.world.World;
|
||||||
|
import server.CashShop;
|
||||||
import server.CashShop.CashItem;
|
import server.CashShop.CashItem;
|
||||||
import server.CashShop.CashItemFactory;
|
import server.CashShop.CashItemFactory;
|
||||||
import server.CashShop.SpecialCashItem;
|
import server.CashShop.SpecialCashItem;
|
||||||
@@ -5580,8 +5581,8 @@ public class PacketCreator {
|
|||||||
|
|
||||||
public static Packet showMTSCash(Character chr) {
|
public static Packet showMTSCash(Character chr) {
|
||||||
final OutPacket p = OutPacket.create(SendOpcode.MTS_OPERATION2);
|
final OutPacket p = OutPacket.create(SendOpcode.MTS_OPERATION2);
|
||||||
p.writeInt(chr.getCashShop().getCash(4));
|
p.writeInt(chr.getCashShop().getCash(CashShop.NX_PREPAID));
|
||||||
p.writeInt(chr.getCashShop().getCash(2));
|
p.writeInt(chr.getCashShop().getCash(CashShop.MAPLE_POINT));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5689,9 +5690,9 @@ public class PacketCreator {
|
|||||||
|
|
||||||
public static Packet showCash(Character mc) {
|
public static Packet showCash(Character mc) {
|
||||||
final OutPacket p = OutPacket.create(SendOpcode.QUERY_CASH_RESULT);
|
final OutPacket p = OutPacket.create(SendOpcode.QUERY_CASH_RESULT);
|
||||||
p.writeInt(mc.getCashShop().getCash(1));
|
p.writeInt(mc.getCashShop().getCash(CashShop.NX_CREDIT));
|
||||||
p.writeInt(mc.getCashShop().getCash(2));
|
p.writeInt(mc.getCashShop().getCash(CashShop.MAPLE_POINT));
|
||||||
p.writeInt(mc.getCashShop().getCash(4));
|
p.writeInt(mc.getCashShop().getCash(CashShop.NX_PREPAID));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user