actual freya branch

This commit is contained in:
2026-09-12 15:41:31 +00:00
parent 8049e0a882
commit 68c1cd27d4
3510 changed files with 336689 additions and 302906 deletions
@@ -0,0 +1,89 @@
/*
* 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.l2jserver.gameserver.model.multisell;
import java.util.ArrayList;
import java.util.List;
/**
* @author DS
*/
public class Entry
{
protected int _entryId;
protected boolean _stackable = true;
protected List<Ingredient> _products;
protected List<Ingredient> _ingredients;
public Entry(int entryId)
{
_entryId = entryId;
_products = new ArrayList<>();
_ingredients = new ArrayList<>();
}
/**
* This constructor used in PreparedEntry only ArrayLists not created
*/
protected Entry()
{
}
public final void setEntryId(int id)
{
_entryId = id;
}
public final int getEntryId()
{
return _entryId;
}
public final void addProduct(Ingredient product)
{
_products.add(product);
if (!product.isStackable())
{
_stackable = false;
}
}
public final List<Ingredient> getProducts()
{
return _products;
}
public final void addIngredient(Ingredient ingredient)
{
_ingredients.add(ingredient);
}
public final List<Ingredient> getIngredients()
{
return _ingredients;
}
public final boolean isStackable()
{
return _stackable;
}
public long getTaxAmount()
{
return 0;
}
}
@@ -0,0 +1,139 @@
/*
* 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.l2jserver.gameserver.model.multisell;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.templates.item.L2Armor;
import com.l2jserver.gameserver.templates.item.L2Item;
import com.l2jserver.gameserver.templates.item.L2Weapon;
/**
* @author DS
*/
public class Ingredient implements Cloneable
{
private int _itemId;
private long _itemCount;
private boolean _isTaxIngredient, _maintainIngredient;
private L2Item _template = null;
private ItemInfo _itemInfo = null;
public Ingredient(int itemId, long itemCount, boolean isTaxIngredient, boolean maintainIngredient)
{
_itemId = itemId;
_itemCount = itemCount;
_isTaxIngredient = isTaxIngredient;
_maintainIngredient = maintainIngredient;
if (_itemId > 0)
{
_template = ItemTable.getInstance().getTemplate(_itemId);
}
}
@Override
public final Ingredient clone()
{
try
{
return (Ingredient) super.clone();
}
catch (CloneNotSupportedException e)
{
return null; // should not happens
}
}
public final L2Item getTemplate()
{
return _template;
}
public final void setItemInfo(L2ItemInstance item)
{
_itemInfo = new ItemInfo(item);
}
public final void setItemInfo(ItemInfo info)
{
_itemInfo = info;
}
public final ItemInfo getItemInfo()
{
return _itemInfo;
}
public final int getEnchantLevel()
{
return _itemInfo != null ? _itemInfo.getEnchantLevel() : 0;
}
public final void setItemId(int itemId)
{
_itemId = itemId;
}
public final int getItemId()
{
return _itemId;
}
public final void setItemCount(long itemCount)
{
_itemCount = itemCount;
}
public final long getItemCount()
{
return _itemCount;
}
public final void setIsTaxIngredient(boolean isTaxIngredient)
{
_isTaxIngredient = isTaxIngredient;
}
public final boolean isTaxIngredient()
{
return _isTaxIngredient;
}
public final void setMaintainIngredient(boolean maintainIngredient)
{
_maintainIngredient = maintainIngredient;
}
public final boolean getMaintainIngredient()
{
return _maintainIngredient;
}
public final boolean isStackable()
{
return _template == null ? true : _template.isStackable();
}
public final boolean isArmorOrWeapon()
{
return _template == null ? false : (_template instanceof L2Armor) || (_template instanceof L2Weapon);
}
public final int getWeight()
{
return _template == null ? 0 : _template.getWeight();
}
}
@@ -0,0 +1,82 @@
/*
* 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.l2jserver.gameserver.model.multisell;
import com.l2jserver.gameserver.model.Elementals;
import com.l2jserver.gameserver.model.L2ItemInstance;
/**
* @author DS
*/
public class ItemInfo
{
private final int _enchantLevel, _augmentId;
private final byte _elementId;
private final int _elementPower;
private final int[] _elementals = new int[6];
public ItemInfo(L2ItemInstance item)
{
_enchantLevel = item.getEnchantLevel();
_augmentId = item.getAugmentation() != null ? item.getAugmentation().getAugmentationId() : 0;
_elementId = item.getAttackElementType();
_elementPower = item.getAttackElementPower();
_elementals[0] = item.getElementDefAttr(Elementals.FIRE);
_elementals[1] = item.getElementDefAttr(Elementals.WATER);
_elementals[2] = item.getElementDefAttr(Elementals.WIND);
_elementals[3] = item.getElementDefAttr(Elementals.EARTH);
_elementals[4] = item.getElementDefAttr(Elementals.HOLY);
_elementals[5] = item.getElementDefAttr(Elementals.DARK);
}
public ItemInfo(int enchantLevel)
{
_enchantLevel = enchantLevel;
_augmentId = 0;
_elementId = Elementals.NONE;
_elementPower = 0;
_elementals[0] = 0;
_elementals[1] = 0;
_elementals[2] = 0;
_elementals[3] = 0;
_elementals[4] = 0;
_elementals[5] = 0;
}
public final int getEnchantLevel()
{
return _enchantLevel;
}
public final int getAugmentId()
{
return _augmentId;
}
public final byte getElementId()
{
return _elementId;
}
public final int getElementPower()
{
return _elementPower;
}
public final int[] getElementals()
{
return _elementals;
}
}
@@ -0,0 +1,78 @@
/*
* 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.l2jserver.gameserver.model.multisell;
import java.util.ArrayList;
import java.util.List;
/**
* @author DS
*/
public class ListContainer
{
protected int _listId;
protected boolean _applyTaxes = false;
protected boolean _maintainEnchantment = false;
protected List<Entry> _entries;
public ListContainer()
{
_entries = new ArrayList<>();
}
/**
* This constructor used in PreparedListContainer only ArrayList not created
*/
protected ListContainer(int listId)
{
_listId = listId;
}
public final List<Entry> getEntries()
{
return _entries;
}
public final void setListId(int listId)
{
_listId = listId;
}
public final int getListId()
{
return _listId;
}
public final void setApplyTaxes(boolean applyTaxes)
{
_applyTaxes = applyTaxes;
}
public final boolean getApplyTaxes()
{
return _applyTaxes;
}
public final void setMaintainEnchantment(boolean maintainEnchantment)
{
_maintainEnchantment = maintainEnchantment;
}
public final boolean getMaintainEnchantment()
{
return _maintainEnchantment;
}
}
@@ -0,0 +1,109 @@
/*
* 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.l2jserver.gameserver.model.multisell;
import static com.l2jserver.gameserver.model.itemcontainer.PcInventory.ADENA_ID;
import java.util.ArrayList;
import com.l2jserver.gameserver.model.L2ItemInstance;
/**
* @author DS
*/
public class PreparedEntry extends Entry
{
private long _taxAmount = 0;
public PreparedEntry(Entry template, L2ItemInstance item, boolean applyTaxes, boolean maintainEnchantment, double taxRate)
{
_entryId = template.getEntryId() * 100000;
if (maintainEnchantment && (item != null))
{
_entryId += item.getEnchantLevel();
}
ItemInfo info = null;
long adenaAmount = 0;
_ingredients = new ArrayList<>(template.getIngredients().size());
for (Ingredient ing : template.getIngredients())
{
if (ing.getItemId() == ADENA_ID)
{
// Tax ingredients added only if taxes enabled
if (ing.isTaxIngredient())
{
// if taxes are to be applied, modify/add the adena count based on the template adena/ancient adena count
if (applyTaxes)
{
_taxAmount += Math.round(ing.getItemCount() * taxRate);
}
}
else
{
adenaAmount += ing.getItemCount();
}
continue; // do not yet add this adena amount to the list as non-taxIngredient adena might be entered later (order not guaranteed)
}
else if (maintainEnchantment && (item != null) && ing.isArmorOrWeapon())
{
info = new ItemInfo(item);
final Ingredient newIngredient = ing.clone();
newIngredient.setItemInfo(info);
_ingredients.add(newIngredient);
}
else
{
_ingredients.add(ing);
}
}
// now add the adena, if any.
adenaAmount += _taxAmount; // do not forget tax
if (adenaAmount > 0)
{
_ingredients.add(new Ingredient(ADENA_ID, adenaAmount, false, false));
}
// now copy products
_products = new ArrayList<>(template.getProducts().size());
for (Ingredient ing : template.getProducts())
{
if (!ing.isStackable())
{
_stackable = false;
}
if (maintainEnchantment && ing.isArmorOrWeapon())
{
final Ingredient newProduct = ing.clone();
newProduct.setItemInfo(info);
_products.add(newProduct);
}
else
{
_products.add(ing);
}
}
}
@Override
public final long getTaxAmount()
{
return _taxAmount;
}
}
@@ -0,0 +1,103 @@
/*
* 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.l2jserver.gameserver.model.multisell;
import java.util.ArrayList;
import javolution.util.FastList;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.templates.item.L2Armor;
import com.l2jserver.gameserver.templates.item.L2Weapon;
public class PreparedListContainer extends ListContainer
{
private int _npcObjectId = 0;
public PreparedListContainer(ListContainer template, boolean inventoryOnly, L2PcInstance player, L2Npc npc)
{
super(template.getListId());
_maintainEnchantment = template.getMaintainEnchantment();
_applyTaxes = false;
double taxRate = 0;
if (npc != null)
{
_npcObjectId = npc.getObjectId();
if (template.getApplyTaxes() && npc.getIsInTown() && (npc.getCastle().getOwnerId() > 0))
{
_applyTaxes = true;
taxRate = npc.getCastle().getTaxRate();
}
}
if (inventoryOnly)
{
if (player == null)
{
return;
}
final L2ItemInstance[] items;
if (_maintainEnchantment)
{
items = player.getInventory().getUniqueItemsByEnchantLevel(false, false, false);
}
else
{
items = player.getInventory().getUniqueItems(false, false, false);
}
// size is not known - using FastList
_entries = new FastList<>();
for (L2ItemInstance item : items)
{
// only do the matchup on equipable items that are not currently equipped
// so for each appropriate item, produce a set of entries for the multisell list.
if (!item.isEquipped() && ((item.getItem() instanceof L2Armor) || (item.getItem() instanceof L2Weapon)))
{
// loop through the entries to see which ones we wish to include
for (Entry ent : template.getEntries())
{
// check ingredients of this entry to see if it's an entry we'd like to include.
for (Ingredient ing : ent.getIngredients())
{
if (item.getItemId() == ing.getItemId())
{
_entries.add(new PreparedEntry(ent, item, _applyTaxes, _maintainEnchantment, taxRate));
break; // next entry
}
}
}
}
}
}
else
{
_entries = new ArrayList<>(template.getEntries().size());
for (Entry ent : template.getEntries())
{
_entries.add(new PreparedEntry(ent, null, _applyTaxes, false, taxRate));
}
}
}
public final boolean checkNpcObjectId(int npcObjectId)
{
return _npcObjectId != 0 ? _npcObjectId == npcObjectId : true;
}
}