Fixed Talking Island and Faeron Village scrolls of escape.
Dropped Batalion Zone due to lack of further development. Added Various missing syncs from L2jServer Ertheia.
This commit is contained in:
@ -1,855 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server 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.
|
||||
*
|
||||
* L2J Server 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.l2jserver.gameserver.instancemanager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.gameserver.enums.MailType;
|
||||
import com.l2jserver.gameserver.model.entity.Message;
|
||||
import com.l2jserver.gameserver.model.items.L2Item;
|
||||
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
|
||||
/**
|
||||
* @author Erlandys
|
||||
*/
|
||||
public class AuctionHouseManager
|
||||
{
|
||||
Connection con = null;
|
||||
private static final Logger _log = Logger.getLogger(AuctionHouseManager.class.getName());
|
||||
private static List<Auctions> auctions = new CopyOnWriteArrayList<>();
|
||||
private static HashMap<Integer, Integer> convertedCategories;
|
||||
private static HashMap<Integer, Integer> mainCategories;
|
||||
|
||||
public AuctionHouseManager()
|
||||
{
|
||||
_log.info(getClass().getSimpleName() + ": Initializing.");
|
||||
loadCategoryConverter();
|
||||
loadMainCategoriesConverter();
|
||||
_log.info(getClass().getSimpleName() + ": Loaded " + mainCategories.size() + " Auction Sections.");
|
||||
load();
|
||||
_log.info(getClass().getSimpleName() + ": Loaded " + auctions.size() + " Auctions.");
|
||||
}
|
||||
|
||||
private void load()
|
||||
{
|
||||
auctions.clear();
|
||||
int auctionID = 0;
|
||||
int sellerID = 0;
|
||||
int count = 0;
|
||||
int category = 0;
|
||||
int duration = 0;
|
||||
int itemOID = 0;
|
||||
int itemID = 0;
|
||||
long price = 0;
|
||||
long finishTime = 0;
|
||||
String itemName = "";
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM auction_house");)
|
||||
{
|
||||
ResultSet rset = statement.executeQuery();
|
||||
while (rset.next())
|
||||
{
|
||||
auctionID = (rset.getInt("auctionID"));
|
||||
sellerID = (rset.getInt("sellerID"));
|
||||
itemName = (rset.getString("itemName"));
|
||||
itemOID = (rset.getInt("itemOID"));
|
||||
price = (rset.getLong("price"));
|
||||
count = (rset.getInt("count"));
|
||||
category = (rset.getInt("category"));
|
||||
duration = (rset.getInt("duration"));
|
||||
finishTime = (rset.getLong("finishTime"));
|
||||
itemID = (rset.getInt("itemID"));
|
||||
L2ItemInstance item = new L2ItemInstance(itemOID, itemID);
|
||||
createAuction(auctionID, sellerID, itemOID, item, itemName, price, count, duration, finishTime, category);
|
||||
}
|
||||
statement.execute();
|
||||
|
||||
rset.close();
|
||||
statement.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed loading auction. " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertAuction(Auctions auction)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("INSERT INTO auction_house (auctionID, sellerID, itemName, itemOID, price, count, category, duration, finishTime, itemID) values (?,?,?,?,?,?,?,?,?,?)");)
|
||||
{
|
||||
statement.setInt(1, auction.getAuctionId());
|
||||
statement.setInt(2, auction.getPlayerID());
|
||||
statement.setString(3, auction.getItemName());
|
||||
statement.setInt(4, auction.getItemOID());
|
||||
statement.setLong(5, auction.getPrice());
|
||||
statement.setLong(6, auction.getCount());
|
||||
statement.setInt(7, auction.getCategory());
|
||||
statement.setInt(8, auction.getDuration());
|
||||
statement.setLong(9, auction.getFinishTime());
|
||||
statement.setInt(10, auction.getItem().getId());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "Could not insert auction: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAuction(int auctionID)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("DELETE FROM auction_house WHERE auctionID=?");)
|
||||
{
|
||||
|
||||
statement.setInt(1, auctionID);
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "Could not delete auction: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCategoryConverter()
|
||||
{
|
||||
convertedCategories = new HashMap<>();
|
||||
|
||||
convertedCategories.put(4294967, 1);
|
||||
convertedCategories.put(8589934, 2);
|
||||
convertedCategories.put(12884901, 3);
|
||||
convertedCategories.put(17179869, 4);
|
||||
convertedCategories.put(21474836, 5);
|
||||
convertedCategories.put(25769803, 6);
|
||||
convertedCategories.put(30064771, 7);
|
||||
convertedCategories.put(34359738, 8);
|
||||
convertedCategories.put(38654705, 9);
|
||||
convertedCategories.put(42949672, 10);
|
||||
convertedCategories.put(47244640, 11);
|
||||
convertedCategories.put(51539607, 12);
|
||||
convertedCategories.put(55834574, 13);
|
||||
convertedCategories.put(60129542, 14);
|
||||
convertedCategories.put(64424509, 15);
|
||||
convertedCategories.put(68719476, 16);
|
||||
convertedCategories.put(73014444, 17);
|
||||
convertedCategories.put(77309411, 18);
|
||||
|
||||
convertedCategories.put(81604378, 19);
|
||||
convertedCategories.put(85899345, 20);
|
||||
convertedCategories.put(90194313, 21);
|
||||
convertedCategories.put(94489280, 22);
|
||||
convertedCategories.put(98784247, 23);
|
||||
convertedCategories.put(103079215, 24);
|
||||
convertedCategories.put(107374182, 25);
|
||||
convertedCategories.put(111669149, 26);
|
||||
convertedCategories.put(115964116, 27);
|
||||
convertedCategories.put(120259084, 28);
|
||||
convertedCategories.put(124554051, 29);
|
||||
convertedCategories.put(128849018, 30);
|
||||
convertedCategories.put(133143986, 31);
|
||||
convertedCategories.put(137438953, 32);
|
||||
convertedCategories.put(141733920, 33);
|
||||
convertedCategories.put(146028888, 34);
|
||||
|
||||
convertedCategories.put(150323855, 35);
|
||||
convertedCategories.put(154618822, 36);
|
||||
convertedCategories.put(158913789, 37);
|
||||
convertedCategories.put(163208757, 38);
|
||||
convertedCategories.put(167503724, 39);
|
||||
convertedCategories.put(171798691, 40);
|
||||
|
||||
convertedCategories.put(180388626, 41);
|
||||
convertedCategories.put(184683593, 42);
|
||||
|
||||
convertedCategories.put(188978561, 43);
|
||||
convertedCategories.put(193273528, 44);
|
||||
convertedCategories.put(197568495, 45);
|
||||
convertedCategories.put(201863462, 46);
|
||||
convertedCategories.put(206158430, 47);
|
||||
convertedCategories.put(210453397, 48);
|
||||
convertedCategories.put(214748364, 49);
|
||||
convertedCategories.put(219043332, 50);
|
||||
convertedCategories.put(223338299, 51);
|
||||
convertedCategories.put(227633266, 52);
|
||||
convertedCategories.put(231928233, 53);
|
||||
convertedCategories.put(236223201, 54);
|
||||
convertedCategories.put(240518168, 55);
|
||||
convertedCategories.put(244813135, 56);
|
||||
convertedCategories.put(249108103, 57);
|
||||
convertedCategories.put(253403070, 58);
|
||||
}
|
||||
|
||||
private void loadMainCategoriesConverter()
|
||||
{
|
||||
mainCategories = new HashMap<>();
|
||||
|
||||
mainCategories.put(4294967, 61);
|
||||
mainCategories.put(8589934, 62);
|
||||
mainCategories.put(12884901, 63);
|
||||
mainCategories.put(17179869, 64);
|
||||
mainCategories.put(21474836, 65);
|
||||
}
|
||||
|
||||
public int getClientCategory(int category)
|
||||
{
|
||||
if (convertedCategories.get(category) != null)
|
||||
{
|
||||
return convertedCategories.get(category);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getMainClientCategory(int category)
|
||||
{
|
||||
if (mainCategories.get(category) != null)
|
||||
{
|
||||
return mainCategories.get(category);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void createAuction(int auctionID, int playerOID, int itemOID, L2ItemInstance item, String itemName, long price, long count, int duration, long finishTime, int category)
|
||||
{
|
||||
auctions.add(new Auctions(auctionID, itemName, itemOID, item, price, count, duration, playerOID, finishTime, category));
|
||||
}
|
||||
|
||||
public void deleteAuction(long auctionID)
|
||||
{
|
||||
for (int i = 0; i < auctions.size(); i++)
|
||||
{
|
||||
if (auctions.get(i).getAuctionId() == auctionID)
|
||||
{
|
||||
deleteItemFromPlayer(auctions.get(i).getItemOID(), auctions.get(i).getPlayerID());
|
||||
removeAuction(auctions.get(i).getAuctionId());
|
||||
auctions.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteItemFromPlayer(int playerID, int itemOID)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("DELETE FROM items WHERE owner_id=? AND object_id=? AND loc='AUCTION_HOUSE'");)
|
||||
{
|
||||
statement.setInt(1, playerID);
|
||||
statement.setInt(2, itemOID);
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "Could not delete auction: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForAuctionsDeletion()
|
||||
{
|
||||
int i = 0;
|
||||
if (!auctions.isEmpty())
|
||||
{
|
||||
for (Auctions auction : auctions)
|
||||
{
|
||||
if ((System.currentTimeMillis() / 1000) >= auction.getFinishTime())
|
||||
{
|
||||
Message msg = new Message(auction.getPlayerID(), "CommissionBuyTitle", "Auction Manager", SystemMessageId.THE_REGISTRATION_PERIOD_FOR_THE_ITEM_YOU_REGISTERED_HAS_EXPIRED.getId(), SystemMessageId.THE_AUCTION_HOUSE_REGISTRATION_PERIOD_HAS_EXPIRED_AND_THE_CORRESPONDING_ITEM_IS_BEING_FORWARDED.getId(), MailType.SYSTEM);
|
||||
msg.createAttachments().addItem("DeleteAuction", auction.getItem().getId(), auction.getCount(), null, null);
|
||||
MailManager.getInstance().sendMessage(msg);
|
||||
removeAuction(auction.getAuctionId());
|
||||
deleteItemFromPlayer(auction.getItemOID(), auction.getPlayerID());
|
||||
auctions.remove(i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Auctions getAuctionById(int id)
|
||||
{
|
||||
for (Auctions auction : auctions)
|
||||
{
|
||||
if (auction.getAuctionId() == id)
|
||||
{
|
||||
return auction;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Auctions getAuctionById(long id)
|
||||
{
|
||||
for (Auctions auction : auctions)
|
||||
{
|
||||
if (auction.getAuctionId() == id)
|
||||
{
|
||||
return auction;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getAuctionsSizeById(int grade, String search)
|
||||
{
|
||||
int i = 0;
|
||||
for (Auctions auction : auctions)
|
||||
{
|
||||
if (grade == -1)
|
||||
{
|
||||
if (auction.getItem().getName().contains(search))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (grade != -1)
|
||||
{
|
||||
if ((grade == auction.getItem().getItem().getCrystalType().getId()) && auction.getItem().getName().contains(search))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int getAuctionsSizeById(long id, int grade, String search)
|
||||
{
|
||||
int ids[][] =
|
||||
{
|
||||
//@formatter:off
|
||||
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18},
|
||||
{19, 20, 21, 22, 23, 24, 25, 26, 27, 28},
|
||||
{29, 30, 31, 32, 33, 34},
|
||||
{35, 36, 37, 38, 39, 40},
|
||||
{41, 42},
|
||||
{43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58}
|
||||
//@formatter:on
|
||||
};
|
||||
int i = 0;
|
||||
int IDS[] = null;
|
||||
if (id == 61)
|
||||
{
|
||||
IDS = ids[1];
|
||||
}
|
||||
else if (id == 62)
|
||||
{
|
||||
IDS = ids[2];
|
||||
}
|
||||
else if (id == 63)
|
||||
{
|
||||
IDS = ids[3];
|
||||
}
|
||||
else if (id == 64)
|
||||
{
|
||||
IDS = ids[4];
|
||||
}
|
||||
else if (id == 65)
|
||||
{
|
||||
IDS = ids[5];
|
||||
}
|
||||
else if (id == 101)
|
||||
{
|
||||
IDS = ids[0];
|
||||
}
|
||||
|
||||
if ((((id > 60) && (id < 66)) || (id == 101)) && (IDS != null))
|
||||
{
|
||||
for (int ID : IDS)
|
||||
{
|
||||
for (Auctions auction : auctions)
|
||||
{
|
||||
if ((grade == -1) && search.equals(""))
|
||||
{
|
||||
if (auction.getCategory() == ID)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (grade != -1)
|
||||
{
|
||||
if (search.equals(""))
|
||||
{
|
||||
if ((auction.getCategory() == ID) && (grade == auction.getItem().getItem().getCrystalType().getId()))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (!search.equals(""))
|
||||
{
|
||||
if ((auction.getCategory() == ID) && (grade == auction.getItem().getItem().getCrystalType().getId()) && auction.getItem().getName().contains(search))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!search.equals(""))
|
||||
{
|
||||
if ((auction.getCategory() == ID) && auction.getItem().getName().contains(search))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Auctions auction : auctions)
|
||||
{
|
||||
if ((grade == -1) && search.equals(""))
|
||||
{
|
||||
if (auction.getCategory() == id)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (grade != -1)
|
||||
{
|
||||
if (search.equals(""))
|
||||
{
|
||||
if ((auction.getCategory() == id) && (grade == auction.getItem().getItem().getCrystalType().getId()))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (!search.equals(""))
|
||||
{
|
||||
if ((auction.getCategory() == id) && (grade == auction.getItem().getItem().getCrystalType().getId()) && auction.getItem().getName().contains(search))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!search.equals(""))
|
||||
{
|
||||
if ((auction.getCategory() == id) && auction.getItem().getName().contains(search))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public int getCategoryByItem(L2ItemInstance item)
|
||||
{
|
||||
final String itemName = item.getName().toLowerCase();
|
||||
|
||||
if (item.isWeapon())
|
||||
{
|
||||
if (item.getItem().isPetItem())
|
||||
{
|
||||
return 41; // Pet Equipment
|
||||
}
|
||||
|
||||
switch (item.getWeaponItem().getItemType())
|
||||
{
|
||||
case SWORD:
|
||||
{
|
||||
if (item.getWeaponItem().getBodyPart() == L2Item.SLOT_LR_HAND)
|
||||
{
|
||||
return 5; // 2-H Sword
|
||||
}
|
||||
|
||||
if (item.getWeaponItem().isMagicWeapon())
|
||||
{
|
||||
return 2; // 1-H Magic Sword
|
||||
}
|
||||
|
||||
return 1; // 1-H Sword
|
||||
}
|
||||
case DAGGER:
|
||||
{
|
||||
return 3; // Dagger
|
||||
}
|
||||
case RAPIER:
|
||||
{
|
||||
return 4; // Rapier
|
||||
}
|
||||
case ANCIENTSWORD:
|
||||
{
|
||||
return 6; // Ancient
|
||||
}
|
||||
case DUAL:
|
||||
{
|
||||
return 7; // Dual Swords
|
||||
}
|
||||
case DUALDAGGER:
|
||||
{
|
||||
return 8; // Dual Daggers
|
||||
}
|
||||
case BLUNT:
|
||||
{
|
||||
if (item.getWeaponItem().getBodyPart() == L2Item.SLOT_LR_HAND)
|
||||
{
|
||||
if (item.getWeaponItem().isMagicWeapon())
|
||||
{
|
||||
return 12; // 2-H Magic Blunt
|
||||
}
|
||||
|
||||
return 11; // 2-H Blunt
|
||||
}
|
||||
|
||||
if (item.getWeaponItem().isMagicWeapon())
|
||||
{
|
||||
return 10; // 1-H Magic Blunt
|
||||
}
|
||||
|
||||
return 9; // 1-H Blunt
|
||||
}
|
||||
case DUALBLUNT:
|
||||
{
|
||||
return 13; // Dual Blunt
|
||||
}
|
||||
case BOW:
|
||||
{
|
||||
return 14; // Bow
|
||||
}
|
||||
case CROSSBOW:
|
||||
{
|
||||
return 15; // Crossbow
|
||||
}
|
||||
case DUALFIST:
|
||||
{
|
||||
return 16; // Fist Weapon
|
||||
}
|
||||
case POLE:
|
||||
{
|
||||
return 17; // Spear
|
||||
}
|
||||
default:
|
||||
{
|
||||
return 18; // Other Weapon
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.isArmor())
|
||||
{
|
||||
if (item.getItem().isPetItem())
|
||||
{
|
||||
return 41; // Pet Equipment
|
||||
}
|
||||
|
||||
switch (item.getArmorItem().getBodyPart())
|
||||
{
|
||||
case L2Item.SLOT_HEAD:
|
||||
{
|
||||
return 19; // Helmet
|
||||
}
|
||||
case L2Item.SLOT_CHEST:
|
||||
{
|
||||
return 20; // Armor Top
|
||||
}
|
||||
case L2Item.SLOT_LEGS:
|
||||
{
|
||||
return 21; // Armor Pants
|
||||
}
|
||||
case L2Item.SLOT_FULL_ARMOR:
|
||||
case L2Item.SLOT_ALLDRESS:
|
||||
{
|
||||
return 22; // Full Body
|
||||
}
|
||||
case L2Item.SLOT_GLOVES:
|
||||
{
|
||||
return 23; // Gloves
|
||||
}
|
||||
case L2Item.SLOT_FEET:
|
||||
{
|
||||
return 24; // Feet
|
||||
}
|
||||
case L2Item.SLOT_L_HAND:
|
||||
{
|
||||
if (itemName.contains("sigil"))
|
||||
{
|
||||
return 26; // Sigil
|
||||
}
|
||||
|
||||
return 25; // Shield
|
||||
}
|
||||
case L2Item.SLOT_UNDERWEAR:
|
||||
{
|
||||
return 27; // Underwear
|
||||
}
|
||||
case L2Item.SLOT_BACK:
|
||||
{
|
||||
return 28; // Cloak
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.isEtcItem())
|
||||
{
|
||||
// Accessory
|
||||
switch (item.getEtcItem().getBodyPart())
|
||||
{
|
||||
case L2Item.SLOT_R_FINGER:
|
||||
case L2Item.SLOT_L_FINGER:
|
||||
case L2Item.SLOT_LR_FINGER:
|
||||
{
|
||||
return 29; // Ring
|
||||
}
|
||||
case L2Item.SLOT_R_EAR:
|
||||
case L2Item.SLOT_L_EAR:
|
||||
case L2Item.SLOT_LR_EAR:
|
||||
{
|
||||
return 30; // Earring
|
||||
}
|
||||
case L2Item.SLOT_NECK:
|
||||
{
|
||||
return 31; // Necklace
|
||||
}
|
||||
case L2Item.SLOT_BELT:
|
||||
{
|
||||
return 32; // Belt
|
||||
}
|
||||
case L2Item.SLOT_R_BRACELET:
|
||||
case L2Item.SLOT_L_BRACELET:
|
||||
{
|
||||
return 33; // Bracelet
|
||||
}
|
||||
case L2Item.SLOT_HAIR:
|
||||
case L2Item.SLOT_HAIR2:
|
||||
case L2Item.SLOT_HAIRALL:
|
||||
{
|
||||
return 34; // Hair Accessory
|
||||
}
|
||||
}
|
||||
|
||||
// Supplies
|
||||
if (item.getEtcItem().isPotion() || item.getEtcItem().isElixir())
|
||||
{
|
||||
return 35; // Potion
|
||||
}
|
||||
|
||||
if (item.getEtcItem().getHandlerName() != null)
|
||||
{
|
||||
switch (item.getEtcItem().getHandlerName())
|
||||
{
|
||||
case "EnchantScrolls":
|
||||
{
|
||||
if (itemName.contains("weapon"))
|
||||
{
|
||||
return 36; // Scroll: Enchant Weapon
|
||||
}
|
||||
|
||||
if (itemName.contains("armor"))
|
||||
{
|
||||
return 37; // Scroll: Enchant Armor
|
||||
}
|
||||
}
|
||||
case "SoulShots":
|
||||
{
|
||||
return 39; // Soulshot
|
||||
}
|
||||
case "SpiritShot":
|
||||
{
|
||||
return 40; // SpiritShot
|
||||
}
|
||||
case "PetFood":
|
||||
case "BeastSoulShot":
|
||||
case "BeastSpiritShot":
|
||||
case "SummonItems":
|
||||
{
|
||||
return 42; // Pet Supplies
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemName.contains("scroll"))
|
||||
{
|
||||
return 38; // Scroll: Other
|
||||
}
|
||||
|
||||
// Misc
|
||||
if (itemName.contains("crystal") && itemName.contains("-grade"))
|
||||
{
|
||||
return 43; // Crystal
|
||||
}
|
||||
if (itemName.contains("recipe"))
|
||||
{
|
||||
return 44; // Recipe
|
||||
}
|
||||
if (itemName.contains("life stone"))
|
||||
{
|
||||
return 46; // Life Stone
|
||||
}
|
||||
if (itemName.contains("soul crystal"))
|
||||
{
|
||||
return 47; // Soul Crystal
|
||||
}
|
||||
if (itemName.contains("stone") && (itemName.contains("fire") || itemName.contains("water") || itemName.contains("earth") || itemName.contains("wind") || itemName.contains("dark") || itemName.contains("holy")))
|
||||
{
|
||||
return 48; // Attribute Stone
|
||||
}
|
||||
if (itemName.contains("weapon") && itemName.contains("enchant") && itemName.contains("stone"))
|
||||
{
|
||||
return 49; // Weapon Enchant Stone
|
||||
}
|
||||
if (itemName.contains("armor") && itemName.contains("enchant") && itemName.contains("stone"))
|
||||
{
|
||||
return 50; // Armor Enchant Stone
|
||||
}
|
||||
if (itemName.contains("spellbook") || itemName.contains("forgotten scroll"))
|
||||
{
|
||||
return 51; // Spellbook
|
||||
}
|
||||
if (itemName.contains("gemstone") && itemName.contains("-grade"))
|
||||
{
|
||||
return 52; // Gemstone
|
||||
}
|
||||
if (itemName.contains("magic pouch"))
|
||||
{
|
||||
return 53; // Pouch
|
||||
}
|
||||
if (itemName.contains("magic pin"))
|
||||
{
|
||||
return 54; // Pin
|
||||
}
|
||||
if (itemName.contains("magic rune clip"))
|
||||
{
|
||||
return 55; // Magic Rune Clip
|
||||
}
|
||||
if (itemName.contains("magic ornament"))
|
||||
{
|
||||
return 56; // Magic Ornament
|
||||
}
|
||||
if (itemName.contains("dye") && (itemName.contains("str") || itemName.contains("dex") || itemName.contains("con") || itemName.contains("int") || itemName.contains("wit") || itemName.contains("men") || itemName.contains("luc") || itemName.contains("cha")))
|
||||
{
|
||||
return 57; // Dye
|
||||
}
|
||||
if (itemName.contains("ingredient") || itemName.contains("piece") || itemName.contains("edge") || itemName.contains("beads") || itemName.contains("stave") || itemName.contains("design") || itemName.contains("fragment") || itemName.contains("blade") || itemName.contains("head") || itemName.contains("part") || itemName.contains("gem") || itemName.contains("shaft") || itemName.contains("stone") || itemName.contains("fabric") || itemName.contains("pattern") || itemName.contains("lining"))
|
||||
{
|
||||
return 45; // Major Crafting Ingredients
|
||||
}
|
||||
}
|
||||
|
||||
return 58; // Other Item
|
||||
}
|
||||
|
||||
public List<Auctions> getAuctions()
|
||||
{
|
||||
return auctions;
|
||||
}
|
||||
|
||||
public class Auctions
|
||||
{
|
||||
int auctionID;
|
||||
int itemOID;
|
||||
int duration;
|
||||
int playerID;
|
||||
int category;
|
||||
L2ItemInstance item;
|
||||
long price;
|
||||
long count;
|
||||
long finishTime;
|
||||
String itemName;
|
||||
|
||||
public Auctions(int _auctionID, String _itemName, int _itemOID, L2ItemInstance _item, long _price, long _count, int _duration, int _playerID, long _finishTime, int _category)
|
||||
{
|
||||
auctionID = _auctionID;
|
||||
itemName = _itemName;
|
||||
itemOID = _itemOID;
|
||||
item = _item;
|
||||
price = _price;
|
||||
count = _count;
|
||||
duration = _duration;
|
||||
playerID = _playerID;
|
||||
finishTime = _finishTime;
|
||||
category = _category;
|
||||
}
|
||||
|
||||
public int getAuctionId()
|
||||
{
|
||||
return auctionID;
|
||||
}
|
||||
|
||||
public String getItemName()
|
||||
{
|
||||
return itemName;
|
||||
}
|
||||
|
||||
public int getItemOID()
|
||||
{
|
||||
return itemOID;
|
||||
}
|
||||
|
||||
public L2ItemInstance getItem()
|
||||
{
|
||||
return item;
|
||||
}
|
||||
|
||||
public long getPrice()
|
||||
{
|
||||
return price;
|
||||
}
|
||||
|
||||
public long getCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getDuration()
|
||||
{
|
||||
return duration;
|
||||
}
|
||||
|
||||
public int getPlayerID()
|
||||
{
|
||||
return playerID;
|
||||
}
|
||||
|
||||
public long getFinishTime()
|
||||
{
|
||||
return finishTime;
|
||||
}
|
||||
|
||||
public int getCategory()
|
||||
{
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
public static final AuctionHouseManager getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final AuctionHouseManager _instance = new AuctionHouseManager();
|
||||
}
|
||||
}
|
@ -0,0 +1,478 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server 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.
|
||||
*
|
||||
* L2J Server 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.l2jserver.gameserver.instancemanager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.enums.ItemLocation;
|
||||
import com.l2jserver.gameserver.enums.MailType;
|
||||
import com.l2jserver.gameserver.model.actor.L2Npc;
|
||||
import com.l2jserver.gameserver.model.actor.instance.CommissionManagerInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.commission.CommissionItem;
|
||||
import com.l2jserver.gameserver.model.entity.Message;
|
||||
import com.l2jserver.gameserver.model.itemcontainer.Inventory;
|
||||
import com.l2jserver.gameserver.model.itemcontainer.Mail;
|
||||
import com.l2jserver.gameserver.model.items.L2Item;
|
||||
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.gameserver.network.serverpackets.commission.ExResponseCommissionBuyItem;
|
||||
import com.l2jserver.gameserver.network.serverpackets.commission.ExResponseCommissionDelete;
|
||||
import com.l2jserver.gameserver.network.serverpackets.commission.ExResponseCommissionInfo;
|
||||
import com.l2jserver.gameserver.network.serverpackets.commission.ExResponseCommissionList;
|
||||
import com.l2jserver.gameserver.network.serverpackets.commission.ExResponseCommissionList.CommissionListReplyType;
|
||||
import com.l2jserver.gameserver.network.serverpackets.commission.ExResponseCommissionRegister;
|
||||
|
||||
/**
|
||||
* @author NosBit
|
||||
*/
|
||||
public final class CommissionManager
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(CommissionManager.class.getName());
|
||||
|
||||
private static final int INTERACTION_DISTANCE = 250;
|
||||
private static final int ITEMS_LIMIT_PER_REQUEST = 999;
|
||||
private static final int MAX_ITEMS_REGISTRED_PER_PLAYER = 10;
|
||||
private static final long MIN_REGISTRATION_AND_SALE_FEE = 1000;
|
||||
private static final double REGISTRATION_FEE_PER_DAY = 0.001;
|
||||
private static final double SALE_FEE_PER_DAY = 0.005;
|
||||
|
||||
private static final String SELECT_ALL_ITEMS = "SELECT * FROM `items` WHERE `loc` = ?";
|
||||
private static final String SELECT_ALL_COMMISSION_ITEMS = "SELECT * FROM `commission_items`";
|
||||
private static final String INSERT_COMMISSION_ITEM = "INSERT INTO `commission_items`(`item_object_id`, `price_per_unit`, `start_time`, `duration_in_days`) VALUES (?, ?, ?, ?)";
|
||||
private static final String DELETE_COMMISSION_ITEM = "DELETE FROM `commission_items` WHERE `commission_id` = ?";
|
||||
|
||||
private final Map<Long, CommissionItem> _commissionItems = new ConcurrentSkipListMap<>();
|
||||
|
||||
protected CommissionManager()
|
||||
{
|
||||
final Map<Integer, L2ItemInstance> itemInstances = new HashMap<>();
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection())
|
||||
{
|
||||
try (PreparedStatement ps = con.prepareStatement(SELECT_ALL_ITEMS))
|
||||
{
|
||||
ps.setString(1, ItemLocation.COMMISSION.toString());
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int itemOwnerId = rs.getInt("owner_id");
|
||||
final int itemObjectId = rs.getInt("object_id");
|
||||
final L2ItemInstance itemInstance = L2ItemInstance.restoreFromDb(itemOwnerId, rs);
|
||||
if (itemInstance == null)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": Failed loading item instance with item object id " + itemObjectId + " and owner id " + itemOwnerId + ".");
|
||||
continue;
|
||||
}
|
||||
|
||||
itemInstances.put(itemObjectId, itemInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (Statement st = con.createStatement();
|
||||
ResultSet rs = st.executeQuery(SELECT_ALL_COMMISSION_ITEMS))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final long commissionId = rs.getLong("commission_id");
|
||||
final L2ItemInstance itemInstance = itemInstances.get(rs.getInt("item_object_id"));
|
||||
if (itemInstance == null)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": Failed loading commission item with commission id " + commissionId + " because item instance does not exist or failed to load.");
|
||||
continue;
|
||||
}
|
||||
final CommissionItem commissionItem = new CommissionItem(commissionId, itemInstance, rs.getLong("price_per_unit"), rs.getTimestamp("start_time").toInstant(), rs.getByte("duration_in_days"));
|
||||
_commissionItems.put(commissionItem.getCommissionId(), commissionItem);
|
||||
if (commissionItem.getEndTime().isBefore(Instant.now()))
|
||||
{
|
||||
expireSale(commissionItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
commissionItem.setSaleEndTask(ThreadPoolManager.getInstance().scheduleGeneral(() -> expireSale(commissionItem), Duration.between(Instant.now(), commissionItem.getEndTime()).toMillis()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Failed loading commission items.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the player the auctions filtered by filter.
|
||||
* @param player the player
|
||||
* @param filter the filter
|
||||
*/
|
||||
public void showAuctions(L2PcInstance player, Predicate<L2Item> filter)
|
||||
{
|
||||
//@formatter:off
|
||||
final List<CommissionItem> commissionItems = _commissionItems.values().stream()
|
||||
.filter(c -> filter.test(c.getItemInfo().getItem()))
|
||||
.limit(ITEMS_LIMIT_PER_REQUEST)
|
||||
.collect(Collectors.toList());
|
||||
//@formatter:on
|
||||
|
||||
if (commissionItems.isEmpty())
|
||||
{
|
||||
player.sendPacket(new ExResponseCommissionList(CommissionListReplyType.ITEM_DOES_NOT_EXIST));
|
||||
return;
|
||||
}
|
||||
|
||||
int chunks = commissionItems.size() / ExResponseCommissionList.MAX_CHUNK_SIZE;
|
||||
if (commissionItems.size() > (chunks * ExResponseCommissionList.MAX_CHUNK_SIZE))
|
||||
{
|
||||
chunks++;
|
||||
}
|
||||
|
||||
for (int i = chunks - 1; i >= 0; i--)
|
||||
{
|
||||
player.sendPacket(new ExResponseCommissionList(CommissionListReplyType.AUCTIONS, commissionItems, i, i * ExResponseCommissionList.MAX_CHUNK_SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the player his auctions.
|
||||
* @param player the player
|
||||
*/
|
||||
public void showPlayerAuctions(L2PcInstance player)
|
||||
{
|
||||
//@formatter:off
|
||||
final List<CommissionItem> commissionItems = _commissionItems.values().stream()
|
||||
.filter(c -> c.getItemInstance().getOwnerId() == player.getObjectId())
|
||||
.limit(MAX_ITEMS_REGISTRED_PER_PLAYER)
|
||||
.collect(Collectors.toList());
|
||||
//@formatter:on
|
||||
|
||||
if (!commissionItems.isEmpty())
|
||||
{
|
||||
player.sendPacket(new ExResponseCommissionList(CommissionListReplyType.PLAYER_AUCTIONS, commissionItems));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendPacket(new ExResponseCommissionList(CommissionListReplyType.PLAYER_AUCTIONS_EMPTY));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an item for the given player.
|
||||
* @param player the player
|
||||
* @param itemObjectId the item object id
|
||||
* @param itemCount the item count
|
||||
* @param pricePerUnit the price per unit
|
||||
* @param durationInDays the duration in days
|
||||
*/
|
||||
public void registerItem(L2PcInstance player, int itemObjectId, long itemCount, long pricePerUnit, byte durationInDays)
|
||||
{
|
||||
if (itemCount < 1)
|
||||
{
|
||||
player.sendPacket(SystemMessageId.THE_ITEM_HAS_FAILED_TO_BE_REGISTERED);
|
||||
player.sendPacket(ExResponseCommissionRegister.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
final long totalPrice = itemCount * pricePerUnit;
|
||||
if (totalPrice <= MIN_REGISTRATION_AND_SALE_FEE)
|
||||
{
|
||||
player.sendPacket(SystemMessageId.THE_ITEM_CANNOT_BE_REGISTERED_BECAUSE_REQUIREMENTS_ARE_NOT_MET);
|
||||
player.sendPacket(ExResponseCommissionRegister.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
L2ItemInstance itemInstance = player.getInventory().getItemByObjectId(itemObjectId);
|
||||
if ((itemInstance == null) || !itemInstance.isAvailable(player, false, false) || (itemInstance.getCount() < itemCount))
|
||||
{
|
||||
player.sendPacket(SystemMessageId.THE_ITEM_HAS_FAILED_TO_BE_REGISTERED);
|
||||
player.sendPacket(ExResponseCommissionRegister.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
//@formatter:off
|
||||
final long playerRegisteredItems = _commissionItems.values().stream()
|
||||
.filter(c -> c.getItemInstance().getOwnerId() == player.getObjectId())
|
||||
.count();
|
||||
//@formatter:on
|
||||
|
||||
if (playerRegisteredItems >= MAX_ITEMS_REGISTRED_PER_PLAYER)
|
||||
{
|
||||
player.sendPacket(SystemMessageId.THE_ITEM_HAS_FAILED_TO_BE_REGISTERED);
|
||||
player.sendPacket(ExResponseCommissionRegister.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
final long registrationFee = (long) Math.max(MIN_REGISTRATION_AND_SALE_FEE, (totalPrice * REGISTRATION_FEE_PER_DAY) * durationInDays);
|
||||
if (!player.getInventory().reduceAdena("Commission Registration Fee", registrationFee, player, null))
|
||||
{
|
||||
player.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA_TO_REGISTER_THE_ITEM);
|
||||
player.sendPacket(ExResponseCommissionRegister.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
itemInstance = player.getInventory().detachItem("Commission Registration", itemInstance, itemCount, ItemLocation.COMMISSION, player, null);
|
||||
if (itemInstance == null)
|
||||
{
|
||||
player.getInventory().addAdena("Commission error refund", registrationFee, player, null);
|
||||
player.sendPacket(SystemMessageId.THE_ITEM_HAS_FAILED_TO_BE_REGISTERED);
|
||||
player.sendPacket(ExResponseCommissionRegister.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(INSERT_COMMISSION_ITEM, Statement.RETURN_GENERATED_KEYS))
|
||||
{
|
||||
final Instant startTime = Instant.now();
|
||||
ps.setInt(1, itemInstance.getObjectId());
|
||||
ps.setLong(2, pricePerUnit);
|
||||
ps.setTimestamp(3, Timestamp.from(startTime));
|
||||
ps.setByte(4, durationInDays);
|
||||
ps.executeUpdate();
|
||||
try (ResultSet rs = ps.getGeneratedKeys())
|
||||
{
|
||||
if (rs.next())
|
||||
{
|
||||
final CommissionItem commissionItem = new CommissionItem(rs.getLong(1), itemInstance, pricePerUnit, startTime, durationInDays);
|
||||
final ScheduledFuture<?> saleEndTask = ThreadPoolManager.getInstance().scheduleGeneral(() -> expireSale(commissionItem), Duration.between(Instant.now(), commissionItem.getEndTime()).toMillis());
|
||||
commissionItem.setSaleEndTask(saleEndTask);
|
||||
_commissionItems.put(commissionItem.getCommissionId(), commissionItem);
|
||||
player.getLastCommissionInfos().put(itemInstance.getId(), new ExResponseCommissionInfo(itemInstance.getId(), pricePerUnit, itemCount, (byte) ((durationInDays - 1) / 2)));
|
||||
player.sendPacket(SystemMessageId.THE_ITEM_HAS_BEEN_SUCCESSFULLY_REGISTERED);
|
||||
player.sendPacket(ExResponseCommissionRegister.SUCCEED);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Failed inserting commission item. ItemInstance: " + itemInstance, e);
|
||||
player.sendPacket(SystemMessageId.THE_ITEM_HAS_FAILED_TO_BE_REGISTERED);
|
||||
player.sendPacket(ExResponseCommissionRegister.FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an item and returns it to the player.
|
||||
* @param player the player
|
||||
* @param commissionId the commission id
|
||||
*/
|
||||
public void deleteItem(L2PcInstance player, long commissionId)
|
||||
{
|
||||
final CommissionItem commissionItem = getCommissionItem(commissionId);
|
||||
if (commissionItem == null)
|
||||
{
|
||||
player.sendPacket(SystemMessageId.CANCELLATION_OF_SALE_HAS_FAILED_BECAUSE_REQUIREMENTS_ARE_NOT_MET);
|
||||
player.sendPacket(ExResponseCommissionDelete.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (commissionItem.getItemInstance().getOwnerId() != player.getObjectId())
|
||||
{
|
||||
player.sendPacket(ExResponseCommissionDelete.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((player.getInventory().getSize(false) >= (player.getInventoryLimit() * 0.8)) || (player.getWeightPenalty() >= 3))
|
||||
{
|
||||
player.sendPacket(SystemMessageId.IF_THE_WEIGHT_IS_80_OR_MORE_AND_THE_INVENTORY_NUMBER_IS_90_OR_MORE_PURCHASE_CANCELLATION_IS_NOT_POSSIBLE);
|
||||
player.sendPacket(SystemMessageId.CANCELLATION_OF_SALE_HAS_FAILED_BECAUSE_REQUIREMENTS_ARE_NOT_MET);
|
||||
player.sendPacket(ExResponseCommissionDelete.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_commissionItems.remove(commissionId) == null) || !commissionItem.getSaleEndTask().cancel(false))
|
||||
{
|
||||
player.sendPacket(SystemMessageId.CANCELLATION_OF_SALE_HAS_FAILED_BECAUSE_REQUIREMENTS_ARE_NOT_MET);
|
||||
player.sendPacket(ExResponseCommissionDelete.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deleteItemFromDB(commissionId))
|
||||
{
|
||||
player.getInventory().addItem("Commission Cancellation", commissionItem.getItemInstance(), player, null);
|
||||
player.sendPacket(SystemMessageId.CANCELLATION_OF_SALE_FOR_THE_ITEM_IS_SUCCESSFUL);
|
||||
player.sendPacket(ExResponseCommissionDelete.SUCCEED);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendPacket(SystemMessageId.CANCELLATION_OF_SALE_HAS_FAILED_BECAUSE_REQUIREMENTS_ARE_NOT_MET);
|
||||
player.sendPacket(ExResponseCommissionDelete.FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Buys the item for the given player.
|
||||
* @param player the player
|
||||
* @param commissionId the commission id
|
||||
*/
|
||||
public void buyItem(L2PcInstance player, long commissionId)
|
||||
{
|
||||
final CommissionItem commissionItem = getCommissionItem(commissionId);
|
||||
if (commissionItem == null)
|
||||
{
|
||||
player.sendPacket(SystemMessageId.ITEM_PURCHASE_HAS_FAILED);
|
||||
player.sendPacket(ExResponseCommissionBuyItem.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
final L2ItemInstance itemInstance = commissionItem.getItemInstance();
|
||||
if (itemInstance.getOwnerId() == player.getObjectId())
|
||||
{
|
||||
player.sendPacket(SystemMessageId.ITEM_PURCHASE_HAS_FAILED);
|
||||
player.sendPacket(ExResponseCommissionBuyItem.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((player.getInventory().getSize(false) >= (player.getInventoryLimit() * 0.8)) || (player.getWeightPenalty() >= 3))
|
||||
{
|
||||
player.sendPacket(SystemMessageId.IF_THE_WEIGHT_IS_80_OR_MORE_AND_THE_INVENTORY_NUMBER_IS_90_OR_MORE_PURCHASE_CANCELLATION_IS_NOT_POSSIBLE);
|
||||
player.sendPacket(ExResponseCommissionBuyItem.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
final long totalPrice = itemInstance.getCount() * commissionItem.getPricePerUnit();
|
||||
if (!player.getInventory().reduceAdena("Commission Registration Fee", totalPrice, player, null))
|
||||
{
|
||||
player.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
|
||||
player.sendPacket(ExResponseCommissionBuyItem.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_commissionItems.remove(commissionId) == null) || !commissionItem.getSaleEndTask().cancel(false))
|
||||
{
|
||||
player.getInventory().addAdena("Commission error refund", totalPrice, player, null);
|
||||
player.sendPacket(SystemMessageId.ITEM_PURCHASE_HAS_FAILED);
|
||||
player.sendPacket(ExResponseCommissionBuyItem.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deleteItemFromDB(commissionId))
|
||||
{
|
||||
final long saleFee = (long) Math.max(MIN_REGISTRATION_AND_SALE_FEE, (totalPrice * SALE_FEE_PER_DAY) * commissionItem.getDurationInDays());
|
||||
final Message mail = new Message(itemInstance.getOwnerId(), itemInstance, MailType.COMMISSION_ITEM_SOLD);
|
||||
|
||||
final Mail attachement = mail.createAttachments();
|
||||
attachement.addItem("Commission Item Sold", Inventory.ADENA_ID, totalPrice - saleFee, player, null);
|
||||
MailManager.getInstance().sendMessage(mail);
|
||||
|
||||
player.sendPacket(new ExResponseCommissionBuyItem(commissionItem));
|
||||
player.getInventory().addItem("Commission Buy Item", commissionItem.getItemInstance(), player, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().addAdena("Commission error refund", totalPrice, player, null);
|
||||
player.sendPacket(ExResponseCommissionBuyItem.FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a commission item from database.
|
||||
* @param commissionId the commission item
|
||||
* @return {@code true} if the item was deleted successfully, {@code false} otherwise
|
||||
*/
|
||||
private boolean deleteItemFromDB(long commissionId)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(DELETE_COMMISSION_ITEM))
|
||||
{
|
||||
ps.setLong(1, commissionId);
|
||||
if (ps.executeUpdate() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": Failed deleting commission item. Commission ID: " + commissionId, e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expires the sale of a commission item and sends the item back to the player.
|
||||
* @param commissionItem the comission item
|
||||
*/
|
||||
private void expireSale(CommissionItem commissionItem)
|
||||
{
|
||||
if ((_commissionItems.remove(commissionItem.getCommissionId()) != null) && deleteItemFromDB(commissionItem.getCommissionId()))
|
||||
{
|
||||
final Message mail = new Message(commissionItem.getItemInstance().getOwnerId(), commissionItem.getItemInstance(), MailType.COMMISSION_ITEM_RETURNED);
|
||||
MailManager.getInstance().sendMessage(mail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the commission item.
|
||||
* @param commissionId the commission id to get
|
||||
* @return the commission item if it exists, {@code null} otherwise
|
||||
*/
|
||||
public CommissionItem getCommissionItem(long commissionId)
|
||||
{
|
||||
return _commissionItems.get(commissionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is allowed to interact with commission manager.
|
||||
* @param player the player
|
||||
* @return {@code true} if the player is allowed to interact, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isPlayerAllowedToInteract(L2PcInstance player)
|
||||
{
|
||||
final L2Npc npc = player.getLastFolkNPC();
|
||||
if ((npc != null) && (npc instanceof CommissionManagerInstance))
|
||||
{
|
||||
return npc.calculateDistance(player, true, false) <= INTERACTION_DISTANCE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the single instance.
|
||||
* @return the single instance
|
||||
*/
|
||||
public static CommissionManager getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final CommissionManager _instance = new CommissionManager();
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ package com.l2jserver.gameserver.instancemanager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.entity.Duel;
|
||||
@ -29,20 +30,11 @@ import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
|
||||
public final class DuelManager
|
||||
{
|
||||
private final Map<Integer, Duel> _duels = new ConcurrentHashMap<>();
|
||||
private int _currentDuelId = 0x90;
|
||||
private final AtomicInteger _currentDuelId = new AtomicInteger();
|
||||
|
||||
protected DuelManager()
|
||||
{
|
||||
}
|
||||
|
||||
private int getNextDuelId()
|
||||
{
|
||||
// In case someone wants to run the server forever :)
|
||||
if (++_currentDuelId >= 2147483640)
|
||||
{
|
||||
_currentDuelId = 1;
|
||||
}
|
||||
return _currentDuelId;
|
||||
|
||||
}
|
||||
|
||||
public Duel getDuel(int duelId)
|
||||
@ -104,7 +96,7 @@ public final class DuelManager
|
||||
return;
|
||||
}
|
||||
}
|
||||
final int duelId = getNextDuelId();
|
||||
final int duelId = _currentDuelId.incrementAndGet();
|
||||
_duels.put(duelId, new Duel(playerA, playerB, partyDuel, duelId));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user