Addition of prime shop support.

This commit is contained in:
MobiusDev
2018-03-15 07:59:31 +00:00
parent 5ccf1d455c
commit 0ef150f22a
26 changed files with 1423 additions and 7 deletions

View File

@ -649,6 +649,8 @@ public final class Config
public static String[] BOTREPORT_RESETPOINT_HOUR;
public static long BOTREPORT_REPORT_DELAY;
public static boolean BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS;
public static boolean ENABLE_ITEM_MALL;
public static int GAME_POINT_ITEM_ID;
// --------------------------------------------------
// FloodProtector Settings
@ -2039,6 +2041,8 @@ public final class Config
BOTREPORT_RESETPOINT_HOUR = General.getString("BotReportPointsResetHour", "00:00").split(":");
BOTREPORT_REPORT_DELAY = General.getInt("BotReportDelay", 30) * 60000;
BOTREPORT_ALLOW_REPORTS_FROM_SAME_CLAN_MEMBERS = General.getBoolean("AllowReportsFromSameClanMembers", false);
ENABLE_ITEM_MALL = General.getBoolean("EnableItemMall", false);
GAME_POINT_ITEM_ID = General.getInt("GamePointItemId", -1);
ENABLE_FALLING_DAMAGE = General.getBoolean("EnableFallingDamage", true);
// Load FloodProtector L2Properties file

View File

@ -61,6 +61,7 @@ import com.l2jmobius.gameserver.data.xml.impl.HennaData;
import com.l2jmobius.gameserver.data.xml.impl.HitConditionBonusData;
import com.l2jmobius.gameserver.data.xml.impl.InitialEquipmentData;
import com.l2jmobius.gameserver.data.xml.impl.InitialShortcutData;
import com.l2jmobius.gameserver.data.xml.impl.ItemMallData;
import com.l2jmobius.gameserver.data.xml.impl.KarmaData;
import com.l2jmobius.gameserver.data.xml.impl.MultisellData;
import com.l2jmobius.gameserver.data.xml.impl.NpcData;
@ -211,6 +212,7 @@ public final class GameServer
FishingMonstersData.getInstance();
FishingRodsData.getInstance();
HennaData.getInstance();
ItemMallData.getInstance();
printSection("Characters");
ClassListData.getInstance();

View File

@ -0,0 +1,108 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.data.xml.impl;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.model.ItemMallProduct;
import com.l2jmobius.gameserver.model.StatsSet;
import com.l2jmobius.util.data.xml.IXmlReader;
/**
* @author Mobius
*/
public class ItemMallData implements IXmlReader
{
private static final Logger _log = Logger.getLogger(ItemMallData.class.getName());
private final Map<Integer, ItemMallProduct> _mallList = new HashMap<>();
protected ItemMallData()
{
if (!Config.ENABLE_ITEM_MALL)
{
return;
}
load();
}
@Override
public void load()
{
_mallList.clear();
parseDatapackFile("data/ItemMall.xml");
}
@Override
public void parseDocument(Document doc)
{
NamedNodeMap attrs;
Node att;
StatsSet set = null;
for (Node a = doc.getFirstChild(); a != null; a = a.getNextSibling())
{
if ("list".equalsIgnoreCase(a.getNodeName()))
{
for (Node b = a.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("product".equalsIgnoreCase(b.getNodeName()))
{
attrs = b.getAttributes();
set = new StatsSet();
for (int i = 0; i < attrs.getLength(); i++)
{
att = attrs.item(i);
set.set(att.getNodeName(), att.getNodeValue());
}
final ItemMallProduct product = new ItemMallProduct(set.getInt("id"), set.getInt("category"), set.getInt("points"), set.getInt("item"), set.getInt("count"));
_mallList.put(set.getInt("id"), product);
}
}
}
}
_log.info(getClass().getSimpleName() + ": Loaded " + _mallList.size() + " products.");
}
public Collection<ItemMallProduct> getAllItems()
{
return _mallList.values();
}
public ItemMallProduct getProduct(int id)
{
return _mallList.get(id);
}
public static ItemMallData getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final ItemMallData _instance = new ItemMallData();
}
}

View File

@ -0,0 +1,91 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.model;
import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.model.items.L2Item;
/**
* @author Mobius
*/
public class ItemMallProduct
{
private final int _productId;
private final int _category;
private final int _points;
private final int _item;
private final int _count;
private final int _weight;
private final boolean _tradable;
public ItemMallProduct(int productId, int category, int points, int item, int count)
{
_productId = productId;
_category = category;
_points = points;
_item = item;
_count = count;
final L2Item itemTemplate = ItemTable.getInstance().getTemplate(item);
if (itemTemplate != null)
{
_weight = itemTemplate.getWeight();
_tradable = itemTemplate.isTradeable();
}
else
{
_weight = 0;
_tradable = true;
}
}
public int getProductId()
{
return _productId;
}
public int getCategory()
{
return _category;
}
public int getPrice()
{
return _points;
}
public int getItemId()
{
return _item;
}
public int getItemCount()
{
return _count;
}
public int getItemWeight()
{
return _weight;
}
public boolean isTradable()
{
return _tradable;
}
}

View File

@ -921,6 +921,9 @@ public final class L2PcInstance extends L2Playable
private boolean _marryrequest = false;
private boolean _marryaccepted = false;
// Item Mall
private final static String GAME_POINTS_VAR = "PRIME_POINTS"; // Keep compatibility with later clients.
// Save responder name for log it
private String _lastPetitionGmName = null;
@ -14332,4 +14335,24 @@ public final class L2PcInstance extends L2Playable
{
return (getSiegeState() > 0) && isInsideZone(ZoneId.SIEGE) && (getSiegeState() == target.getSiegeState()) && (getSiegeSide() == target.getSiegeSide());
}
/**
* @return the game shop points of the player.
*/
public long getGamePoints()
{
return getAccountVariables().getInt(GAME_POINTS_VAR, 0);
}
/**
* Sets game shop points for current player.
* @param points
*/
public void setGamePoints(long points)
{
// Immediate store upon change
final AccountVariables vars = getAccountVariables();
vars.set(GAME_POINTS_VAR, Math.max(points, 0));
vars.storeMe();
}
}

View File

@ -1768,27 +1768,27 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
}
case 0x89:
{
// RequestBRGamePoint
msg = new RequestBrGamePoint();
break;
}
case 0x8A:
{
// RequestBRProductList
msg = new RequestBrProductList();
break;
}
case 0x8B:
{
// RequestBRProductInfo
msg = new RequestBrProductInfo();
break;
}
case 0x8C:
{
// RequestBRBuyProduct
msg = new RequestBrBuyProduct();
break;
}
case 0x8D:
{
// RequestBRRecentProductList
msg = new RequestBrRecentProductList();
break;
}
case 0x8E:

View File

@ -0,0 +1,135 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.logging.Level;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.xml.impl.ItemMallData;
import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.model.ItemMallProduct;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.items.L2Item;
import com.l2jmobius.gameserver.network.serverpackets.ExBrBuyProduct;
import com.l2jmobius.gameserver.network.serverpackets.ExBrGamePoint;
import com.l2jmobius.gameserver.network.serverpackets.StatusUpdate;
/**
* @author Mobius
*/
public class RequestBrBuyProduct extends L2GameClientPacket
{
private int _productId;
private int _count;
@Override
protected void readImpl()
{
_productId = readD();
_count = readD();
}
@Override
protected void runImpl()
{
final L2PcInstance player = getClient().getActiveChar();
if (player == null)
{
return;
}
if ((_count > 99) || (_count < 0))
{
return;
}
final ItemMallProduct product = ItemMallData.getInstance().getProduct(_productId);
if (product == null)
{
player.sendPacket(new ExBrBuyProduct(ExBrBuyProduct.RESULT_WRONG_PRODUCT));
return;
}
final long totalPoints = product.getPrice() * _count;
if (totalPoints < 0)
{
player.sendPacket(new ExBrBuyProduct(ExBrBuyProduct.RESULT_WRONG_PRODUCT));
return;
}
final long gamePointSize = Config.GAME_POINT_ITEM_ID == -1 ? player.getGamePoints() : player.getInventory().getInventoryItemCount(Config.GAME_POINT_ITEM_ID, -1);
if (totalPoints > gamePointSize)
{
player.sendPacket(new ExBrBuyProduct(ExBrBuyProduct.RESULT_NOT_ENOUGH_POINTS));
return;
}
final L2Item item = ItemTable.getInstance().getTemplate(product.getItemId());
if (item == null)
{
player.sendPacket(new ExBrBuyProduct(ExBrBuyProduct.RESULT_WRONG_PRODUCT));
return;
}
final int totalWeight = product.getItemWeight() * product.getItemCount() * _count;
int totalCount = 0;
totalCount += item.isStackable() ? 1 : product.getItemCount() * _count;
if (!player.getInventory().validateCapacity(totalCount) || !player.getInventory().validateWeight(totalWeight))
{
player.sendPacket(new ExBrBuyProduct(ExBrBuyProduct.RESULT_INVENTORY_FULL));
return;
}
// Pay for Item
if (Config.GAME_POINT_ITEM_ID == -1)
{
player.setGamePoints(player.getGamePoints() - totalPoints);
}
else
{
player.getInventory().destroyItemByItemId("Buy Product" + _productId, Config.GAME_POINT_ITEM_ID, totalPoints, player, null);
}
// Buy Item
player.getInventory().addItem("Buy Product" + _productId, product.getItemId(), product.getItemCount() * _count, player, null);
final StatusUpdate su = new StatusUpdate(player.getObjectId());
su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
player.sendPacket(su);
player.sendPacket(new ExBrGamePoint(player));
player.sendPacket(new ExBrBuyProduct(ExBrBuyProduct.RESULT_OK));
player.broadcastUserInfo();
// Save transaction info at SQL table item_mall_transactions
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("INSERT INTO item_mall_transactions (charId, productId, quantity) values (?,?,?)"))
{
statement.setLong(1, player.getObjectId());
statement.setInt(2, product.getProductId());
statement.setLong(3, _count);
statement.executeUpdate();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Could not save Item Mall transaction: " + e.getMessage(), e);
}
}
}

View File

@ -0,0 +1,42 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.serverpackets.ExBrGamePoint;
/**
* @author Mobius
*/
public class RequestBrGamePoint extends L2GameClientPacket
{
@Override
protected void readImpl()
{
}
@Override
protected void runImpl()
{
final L2PcInstance player = getClient().getActiveChar();
if (player == null)
{
return;
}
player.sendPacket(new ExBrGamePoint(player));
}
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.serverpackets.ExBrProductInfo;
/**
* @author Mobius
*/
public class RequestBrProductInfo extends L2GameClientPacket
{
private int _productId;
@Override
protected void readImpl()
{
_productId = readD();
}
@Override
protected void runImpl()
{
final L2PcInstance player = getClient().getActiveChar();
if (player == null)
{
return;
}
player.sendPacket(new ExBrProductInfo(_productId));
}
}

View File

@ -0,0 +1,43 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.serverpackets.ExBrProductList;
/**
* @author Mobius
*/
public class RequestBrProductList extends L2GameClientPacket
{
@Override
protected void readImpl()
{
}
@Override
protected void runImpl()
{
final L2PcInstance player = getClient().getActiveChar();
if (player == null)
{
return;
}
player.sendPacket(new ExBrProductList());
}
}

View File

@ -0,0 +1,43 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.serverpackets.ExBrRecentProductList;
/**
* @author Mobius
*/
public class RequestBrRecentProductList extends L2GameClientPacket
{
@Override
protected void readImpl()
{
}
@Override
protected void runImpl()
{
final L2PcInstance player = getClient().getActiveChar();
if (player == null)
{
return;
}
player.sendPacket(new ExBrRecentProductList(player));
}
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.serverpackets;
/**
* @author Mobius
*/
public class ExBrBuyProduct extends L2GameServerPacket
{
public static final int RESULT_OK = 1; // ok
public static final int RESULT_NOT_ENOUGH_POINTS = -1;
public static final int RESULT_WRONG_PRODUCT = -2; // also -5
public static final int RESULT_INVENTORY_FULL = -4;
public static final int RESULT_SALE_PERIOD_ENDED = -7; // also -8
public static final int RESULT_WRONG_USER_STATE = -9; // also -11
public static final int RESULT_WRONG_PRODUCT_ITEM = -10;
private final int _result;
public ExBrBuyProduct(int result)
{
_result = result;
}
@Override
protected void writeImpl()
{
writeC(0xFE);
writeH(0xD8);
writeD(_result);
}
}

View File

@ -0,0 +1,53 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.serverpackets;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
/**
* @author Mobius
*/
public class ExBrGamePoint extends L2GameServerPacket
{
private final int _playerObj;
private long _points;
public ExBrGamePoint(L2PcInstance player)
{
_playerObj = player.getObjectId();
if (Config.GAME_POINT_ITEM_ID == -1)
{
_points = player.getGamePoints();
}
else
{
_points = player.getInventory().getInventoryItemCount(Config.GAME_POINT_ITEM_ID, -1);
}
}
@Override
public void writeImpl()
{
writeC(0xFE);
writeH(0xD5);
writeD(_playerObj);
writeQ(_points);
writeD(0x00);
}
}

View File

@ -0,0 +1,53 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.serverpackets;
import com.l2jmobius.gameserver.data.xml.impl.ItemMallData;
import com.l2jmobius.gameserver.model.ItemMallProduct;
/**
* @author Mobius
*/
public class ExBrProductInfo extends L2GameServerPacket
{
private final ItemMallProduct _product;
public ExBrProductInfo(int id)
{
_product = ItemMallData.getInstance().getProduct(id);
}
@Override
protected void writeImpl()
{
if (_product == null)
{
return;
}
writeC(0xFE);
writeH(0xD7);
writeD(_product.getProductId()); // product id
writeD(_product.getPrice()); // points
writeD(1); // components size
writeD(_product.getItemId()); // item id
writeD(_product.getItemCount()); // quality
writeD(_product.getItemWeight()); // weight
writeD(_product.isTradable() ? 1 : 0); // 0 - dont drop/trade
}
}

View File

@ -0,0 +1,81 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.serverpackets;
import java.util.Collection;
import com.l2jmobius.gameserver.data.xml.impl.ItemMallData;
import com.l2jmobius.gameserver.model.ItemMallProduct;
/**
* @author Mobius
*/
public class ExBrProductList extends L2GameServerPacket
{
private final Collection<ItemMallProduct> _itemList = ItemMallData.getInstance().getAllItems();
@Override
protected void writeImpl()
{
writeC(0xFE);
writeH(0xD6);
writeD(_itemList.size());
for (ItemMallProduct product : _itemList)
{
final int category = product.getCategory();
writeD(product.getProductId()); // product id
writeH(category); // category id
writeD(product.getPrice()); // points
switch (category)
{
case 6:
{
writeD(0x01); // event
break;
}
case 7:
{
writeD(0x02); // best
break;
}
case 8:
{
writeD(0x03); // event & best
break;
}
default:
{
writeD(0x00); // normal
break;
}
}
writeD(0x00); // start sale
writeD(0x00); // end sale
writeC(0x00); // day week
writeC(0x00); // start hour
writeC(0x00); // start min
writeC(0x00); // end hour
writeC(0x00); // end min
writeD(0x00); // current stock
writeD(0x00); // max stock
}
}
}

View File

@ -0,0 +1,94 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.serverpackets;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.xml.impl.ItemMallData;
import com.l2jmobius.gameserver.model.ItemMallProduct;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
/**
* @author Mobius
*/
public class ExBrRecentProductList extends L2GameServerPacket
{
private final List<ItemMallProduct> _itemList = new ArrayList<>();
public ExBrRecentProductList(L2PcInstance player)
{
final int playerObj = player.getObjectId();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT productId FROM item_mall_transactions WHERE charId=? ORDER BY transactionTime DESC"))
{
statement.setInt(1, playerObj);
try (ResultSet rset = statement.executeQuery())
{
while (rset.next())
{
final ItemMallProduct product = ItemMallData.getInstance().getProduct(rset.getInt("productId"));
if ((product != null) && !_itemList.contains(product))
{
_itemList.add(product);
}
}
}
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Could not restore Item Mall transaction: " + e.getMessage(), e);
}
}
@Override
protected void writeImpl()
{
if ((_itemList == null) || _itemList.isEmpty())
{
return;
}
writeC(0xFE);
writeH(0xDC);
writeD(_itemList.size());
for (ItemMallProduct product : _itemList)
{
writeD(product.getProductId());
writeH(product.getCategory());
writeD(product.getPrice());
writeD(0x00); // category
writeD(0x00); // start sale
writeD(0x00); // end sale
writeC(0x00); // day week
writeC(0x00); // start hour
writeC(0x00); // start min
writeC(0x00); // end hour
writeC(0x00); // end min
writeD(0x00); // current stock
writeD(0x00); // max stock
}
}
}