Addition of ExWorldExchangeAveragePrice and ExWorldExchangeTotalList packets.

Thanks to Index.
This commit is contained in:
MobiusDevelopment 2023-01-05 22:08:12 +00:00
parent 5adebb658e
commit 449398b7fd
14 changed files with 468 additions and 6 deletions

View File

@ -842,6 +842,16 @@ public class WorldExchangeManager implements IXmlReader
Collections.reverse(sortedList);
break;
}
case PRICE_PER_PIECE_ASCE:
{
sortedList = sortedList.stream().sorted(Comparator.comparingLong(WorldExchangeHolder::getPrice)).collect(Collectors.toList());
break;
}
case PRICE_PER_PIECE_DESC:
{
sortedList = sortedList.stream().sorted(Comparator.comparingLong(WorldExchangeHolder::getPrice).reversed()).collect(Collectors.toList());
break;
}
}
if (sortedList.size() > 399)
@ -1023,6 +1033,28 @@ public class WorldExchangeManager implements IXmlReader
}
}
/**
* Returns the average price of the specified item.
* @param itemId the ID of the item
* @return the average price, or 0 if there are no items with the specified ID
*/
public long getAveragePriceOfItem(int itemId)
{
long totalPrice = 0;
long totalItemCount = 0;
for (WorldExchangeHolder holder : _itemBids.values())
{
if (holder.getItemInstance().getTemplate().getId() != itemId)
{
continue;
}
totalItemCount++;
totalPrice += holder.getPrice();
}
return totalItemCount == 0 ? 0 : totalPrice / totalItemCount;
}
public static WorldExchangeManager getInstance()
{
return WorldExchangeManager.SingletonHolder.INSTANCE;

View File

@ -191,11 +191,13 @@ import org.l2jmobius.gameserver.network.clientpackets.variation.ExVariationClose
import org.l2jmobius.gameserver.network.clientpackets.variation.ExVariationOpenUi;
import org.l2jmobius.gameserver.network.clientpackets.variation.RequestConfirmGemStone;
import org.l2jmobius.gameserver.network.clientpackets.variation.RequestRefine;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeAveragePrice;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeBuyItem;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeItemList;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeRegisterItem;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeSettleList;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeSettleRecvResult;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeTotalList;
/**
* @author Mobius
@ -809,8 +811,8 @@ public enum ExClientPackets
EX_GOODS_GIFT_LIST_INFO(0x256, null, ConnectionState.IN_GAME),
EX_GOODS_GIFT_ACCEPT(0x257, null, ConnectionState.IN_GAME),
EX_GOODS_GIFT_REFUSE(0x258, null, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_AVERAGE_PRICE(0x259, null, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_TOTAL_LIST(0x25A, null, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_AVERAGE_PRICE(0x259, ExWorldExchangeAveragePrice::new, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_TOTAL_LIST(0x25A, ExWorldExchangeTotalList::new, ConnectionState.IN_GAME),
EX_PRISON_USER_INFO(0x25B, null, ConnectionState.IN_GAME),
EX_PRISON_USER_DONATION(0x25C, null, ConnectionState.IN_GAME),
EX_MAX(0x25D, null, ConnectionState.IN_GAME);

View File

@ -0,0 +1,49 @@
/*
* 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 org.l2jmobius.gameserver.network.clientpackets.worldexchange;
import org.l2jmobius.commons.network.ReadablePacket;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.ClientPacket;
import org.l2jmobius.gameserver.network.serverpackets.worldexchange.WorldExchangeAveragePrice;
/**
* @author Mobius
*/
public class ExWorldExchangeAveragePrice implements ClientPacket
{
private int _itemId;
@Override
public void read(ReadablePacket packet)
{
_itemId = packet.readInt();
}
@Override
public void run(GameClient client)
{
final Player player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new WorldExchangeAveragePrice(_itemId));
}
}

View File

@ -33,7 +33,6 @@ import org.l2jmobius.gameserver.network.serverpackets.worldexchange.WorldExchang
/**
* @author Index
*/
public class ExWorldExchangeItemList implements ClientPacket
{
private int _category;

View File

@ -0,0 +1,56 @@
/*
* 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 org.l2jmobius.gameserver.network.clientpackets.worldexchange;
import java.util.LinkedList;
import java.util.List;
import org.l2jmobius.commons.network.ReadablePacket;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.ClientPacket;
import org.l2jmobius.gameserver.network.serverpackets.worldexchange.WorldExchangeTotalList;
/**
* @author Index
*/
public class ExWorldExchangeTotalList implements ClientPacket
{
private final List<Integer> itemIds = new LinkedList<>();
@Override
public void read(ReadablePacket packet)
{
final int size = packet.readInt();
for (int index = 0; index < size; index++)
{
itemIds.add(packet.readInt());
}
}
@Override
public void run(GameClient client)
{
final Player player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new WorldExchangeTotalList(itemIds));
}
}

View File

@ -0,0 +1,44 @@
/*
* 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 org.l2jmobius.gameserver.network.serverpackets.worldexchange;
import org.l2jmobius.gameserver.instancemanager.WorldExchangeManager;
import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
/**
* @author Mobius
*/
public class WorldExchangeAveragePrice extends ServerPacket
{
private final int _itemId;
private final long _averagePrice;
public WorldExchangeAveragePrice(int itemId)
{
_itemId = itemId;
_averagePrice = WorldExchangeManager.getInstance().getAveragePriceOfItem(itemId);
}
@Override
public void write()
{
ServerPackets.EX_WORLD_EXCHANGE_AVERAGE_PRICE.writeId(this);
writeInt(_itemId);
writeLong(_averagePrice);
}
}

View File

@ -0,0 +1,49 @@
/*
* 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 org.l2jmobius.gameserver.network.serverpackets.worldexchange;
import java.util.Collection;
import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
/**
* @author Mobius
*/
public class WorldExchangeTotalList extends ServerPacket
{
private final Collection<Integer> _itemIds;
public WorldExchangeTotalList(Collection<Integer> itemIds)
{
_itemIds = itemIds;
}
@Override
public void write()
{
ServerPackets.EX_WORLD_EXCHANGE_TOTAL_LIST.writeId(this);
writeInt(_itemIds.size());
for (int id : _itemIds)
{
writeInt(id); // ItemClassID
writeLong(0); // MinPricePerPiece
writeLong(0); // Price
writeLong(1); // Amount
}
}
}

View File

@ -848,6 +848,16 @@ public class WorldExchangeManager implements IXmlReader
Collections.reverse(sortedList);
break;
}
case PRICE_PER_PIECE_ASCE:
{
sortedList = sortedList.stream().sorted(Comparator.comparingLong(WorldExchangeHolder::getPrice)).collect(Collectors.toList());
break;
}
case PRICE_PER_PIECE_DESC:
{
sortedList = sortedList.stream().sorted(Comparator.comparingLong(WorldExchangeHolder::getPrice).reversed()).collect(Collectors.toList());
break;
}
}
if (sortedList.size() > 399)
@ -1034,6 +1044,28 @@ public class WorldExchangeManager implements IXmlReader
}
}
/**
* Returns the average price of the specified item.
* @param itemId the ID of the item
* @return the average price, or 0 if there are no items with the specified ID
*/
public long getAveragePriceOfItem(int itemId)
{
long totalPrice = 0;
long totalItemCount = 0;
for (WorldExchangeHolder holder : _itemBids.values())
{
if (holder.getItemInstance().getTemplate().getId() != itemId)
{
continue;
}
totalItemCount++;
totalPrice += holder.getPrice();
}
return totalItemCount == 0 ? 0 : totalPrice / totalItemCount;
}
public static WorldExchangeManager getInstance()
{
return WorldExchangeManager.SingletonHolder.INSTANCE;

View File

@ -213,11 +213,13 @@ import org.l2jmobius.gameserver.network.clientpackets.variation.RequestConfirmGe
import org.l2jmobius.gameserver.network.clientpackets.variation.RequestRefine;
import org.l2jmobius.gameserver.network.clientpackets.vip.ExRequestVipInfo;
import org.l2jmobius.gameserver.network.clientpackets.vip.RequestVipLuckGameInfo;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeAveragePrice;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeBuyItem;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeItemList;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeRegisterItem;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeSettleList;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeSettleRecvResult;
import org.l2jmobius.gameserver.network.clientpackets.worldexchange.ExWorldExchangeTotalList;
/**
* @author Mobius
@ -831,8 +833,8 @@ public enum ExClientPackets
EX_GOODS_GIFT_LIST_INFO(0x256, null, ConnectionState.IN_GAME),
EX_GOODS_GIFT_ACCEPT(0x257, null, ConnectionState.IN_GAME),
EX_GOODS_GIFT_REFUSE(0x258, null, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_AVERAGE_PRICE(0x259, null, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_TOTAL_LIST(0x25A, null, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_AVERAGE_PRICE(0x259, ExWorldExchangeAveragePrice::new, ConnectionState.IN_GAME),
EX_WORLD_EXCHANGE_TOTAL_LIST(0x25A, ExWorldExchangeTotalList::new, ConnectionState.IN_GAME),
EX_PRISON_USER_INFO(0x25B, null, ConnectionState.IN_GAME),
EX_PRISON_USER_DONATION(0x25C, null, ConnectionState.IN_GAME),
EX_MAX(0x25D, null, ConnectionState.IN_GAME);

View File

@ -0,0 +1,49 @@
/*
* 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 org.l2jmobius.gameserver.network.clientpackets.worldexchange;
import org.l2jmobius.commons.network.ReadablePacket;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.ClientPacket;
import org.l2jmobius.gameserver.network.serverpackets.worldexchange.WorldExchangeAveragePrice;
/**
* @author Mobius
*/
public class ExWorldExchangeAveragePrice implements ClientPacket
{
private int _itemId;
@Override
public void read(ReadablePacket packet)
{
_itemId = packet.readInt();
}
@Override
public void run(GameClient client)
{
final Player player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new WorldExchangeAveragePrice(_itemId));
}
}

View File

@ -33,7 +33,6 @@ import org.l2jmobius.gameserver.network.serverpackets.worldexchange.WorldExchang
/**
* @author Index
*/
public class ExWorldExchangeItemList implements ClientPacket
{
private int _category;

View File

@ -0,0 +1,56 @@
/*
* 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 org.l2jmobius.gameserver.network.clientpackets.worldexchange;
import java.util.LinkedList;
import java.util.List;
import org.l2jmobius.commons.network.ReadablePacket;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.ClientPacket;
import org.l2jmobius.gameserver.network.serverpackets.worldexchange.WorldExchangeTotalList;
/**
* @author Index
*/
public class ExWorldExchangeTotalList implements ClientPacket
{
private final List<Integer> itemIds = new LinkedList<>();
@Override
public void read(ReadablePacket packet)
{
final int size = packet.readInt();
for (int index = 0; index < size; index++)
{
itemIds.add(packet.readInt());
}
}
@Override
public void run(GameClient client)
{
final Player player = client.getPlayer();
if (player == null)
{
return;
}
player.sendPacket(new WorldExchangeTotalList(itemIds));
}
}

View File

@ -0,0 +1,44 @@
/*
* 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 org.l2jmobius.gameserver.network.serverpackets.worldexchange;
import org.l2jmobius.gameserver.instancemanager.WorldExchangeManager;
import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
/**
* @author Mobius
*/
public class WorldExchangeAveragePrice extends ServerPacket
{
private final int _itemId;
private final long _averagePrice;
public WorldExchangeAveragePrice(int itemId)
{
_itemId = itemId;
_averagePrice = WorldExchangeManager.getInstance().getAveragePriceOfItem(itemId);
}
@Override
public void write()
{
ServerPackets.EX_WORLD_EXCHANGE_AVERAGE_PRICE.writeId(this);
writeInt(_itemId);
writeLong(_averagePrice);
}
}

View File

@ -0,0 +1,49 @@
/*
* 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 org.l2jmobius.gameserver.network.serverpackets.worldexchange;
import java.util.Collection;
import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
/**
* @author Mobius
*/
public class WorldExchangeTotalList extends ServerPacket
{
private final Collection<Integer> _itemIds;
public WorldExchangeTotalList(Collection<Integer> itemIds)
{
_itemIds = itemIds;
}
@Override
public void write()
{
ServerPackets.EX_WORLD_EXCHANGE_TOTAL_LIST.writeId(this);
writeInt(_itemIds.size());
for (int id : _itemIds)
{
writeInt(id); // ItemClassID
writeLong(0); // MinPricePerPiece
writeLong(0); // Price
writeLong(1); // Amount
}
}
}