1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768 |
- /*
- * 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.model.itemcontainer;
- 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 java.util.logging.Logger;
- import com.l2jserver.Config;
- import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
- import com.l2jserver.gameserver.data.xml.impl.ArmorSetsData;
- import com.l2jserver.gameserver.datatables.ItemTable;
- import com.l2jserver.gameserver.enums.ItemLocation;
- import com.l2jserver.gameserver.enums.PrivateStoreType;
- import com.l2jserver.gameserver.model.L2ArmorSet;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.PcCondOverride;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.holders.SkillHolder;
- import com.l2jserver.gameserver.model.items.L2Item;
- import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
- import com.l2jserver.gameserver.model.items.type.EtcItemType;
- import com.l2jserver.gameserver.model.items.type.WeaponType;
- import com.l2jserver.gameserver.model.skills.Skill;
- import com.l2jserver.gameserver.network.serverpackets.SkillCoolTime;
- import com.l2jserver.util.StringUtil;
- /**
- * This class manages inventory
- * @version $Revision: 1.13.2.9.2.12 $ $Date: 2005/03/29 23:15:15 $ rewritten 23.2.2006 by Advi
- */
- public abstract class Inventory extends ItemContainer
- {
- protected static final Logger _log = Logger.getLogger(Inventory.class.getName());
-
- public interface PaperdollListener
- {
- public void notifyEquiped(int slot, L2ItemInstance inst, Inventory inventory);
-
- public void notifyUnequiped(int slot, L2ItemInstance inst, Inventory inventory);
- }
-
- // Common Items
- public static final int ADENA_ID = 57;
- public static final int ANCIENT_ADENA_ID = 5575;
-
- public static final long MAX_ADENA = Config.MAX_ADENA;
-
- public static final int PAPERDOLL_UNDER = 0;
- public static final int PAPERDOLL_HEAD = 1;
- public static final int PAPERDOLL_HAIR = 2;
- public static final int PAPERDOLL_HAIR2 = 3;
- public static final int PAPERDOLL_NECK = 4;
- public static final int PAPERDOLL_RHAND = 5;
- public static final int PAPERDOLL_CHEST = 6;
- public static final int PAPERDOLL_LHAND = 7;
- public static final int PAPERDOLL_REAR = 8;
- public static final int PAPERDOLL_LEAR = 9;
- public static final int PAPERDOLL_GLOVES = 10;
- public static final int PAPERDOLL_LEGS = 11;
- public static final int PAPERDOLL_FEET = 12;
- public static final int PAPERDOLL_RFINGER = 13;
- public static final int PAPERDOLL_LFINGER = 14;
- public static final int PAPERDOLL_LBRACELET = 15;
- public static final int PAPERDOLL_RBRACELET = 16;
- public static final int PAPERDOLL_DECO1 = 17;
- public static final int PAPERDOLL_DECO2 = 18;
- public static final int PAPERDOLL_DECO3 = 19;
- public static final int PAPERDOLL_DECO4 = 20;
- public static final int PAPERDOLL_DECO5 = 21;
- public static final int PAPERDOLL_DECO6 = 22;
- public static final int PAPERDOLL_CLOAK = 23;
- public static final int PAPERDOLL_BELT = 24;
- public static final int PAPERDOLL_TOTALSLOTS = 25;
-
- // Speed percentage mods
- public static final double MAX_ARMOR_WEIGHT = 12000;
-
- private final L2ItemInstance[] _paperdoll;
- private final List<PaperdollListener> _paperdollListeners;
-
- // protected to be accessed from child classes only
- protected int _totalWeight;
-
- // used to quickly check for using of items of special type
- private int _wearedMask;
-
- // Recorder of alterations in inventory
- private static final class ChangeRecorder implements PaperdollListener
- {
- private final Inventory _inventory;
- private final List<L2ItemInstance> _changed;
-
- /**
- * Constructor of the ChangeRecorder
- * @param inventory
- */
- ChangeRecorder(Inventory inventory)
- {
- _inventory = inventory;
- _changed = new ArrayList<>();
- _inventory.addPaperdollListener(this);
- }
-
- /**
- * Add alteration in inventory when item equipped
- * @param slot
- * @param item
- * @param inventory
- */
- @Override
- public void notifyEquiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (!_changed.contains(item))
- {
- _changed.add(item);
- }
- }
-
- /**
- * Add alteration in inventory when item unequipped
- * @param slot
- * @param item
- * @param inventory
- */
- @Override
- public void notifyUnequiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (!_changed.contains(item))
- {
- _changed.add(item);
- }
- }
-
- /**
- * Returns alterations in inventory
- * @return L2ItemInstance[] : array of altered items
- */
- public L2ItemInstance[] getChangedItems()
- {
- return _changed.toArray(new L2ItemInstance[_changed.size()]);
- }
- }
-
- private static final class BowCrossRodListener implements PaperdollListener
- {
- private static BowCrossRodListener instance = new BowCrossRodListener();
-
- public static BowCrossRodListener getInstance()
- {
- return instance;
- }
-
- @Override
- public void notifyUnequiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (slot != PAPERDOLL_RHAND)
- {
- return;
- }
-
- if (item.getItemType() == WeaponType.BOW)
- {
- L2ItemInstance arrow = inventory.getPaperdollItem(PAPERDOLL_LHAND);
-
- if (arrow != null)
- {
- inventory.setPaperdollItem(PAPERDOLL_LHAND, null);
- }
- }
- else if (item.getItemType() == WeaponType.CROSSBOW)
- {
- L2ItemInstance bolts = inventory.getPaperdollItem(PAPERDOLL_LHAND);
-
- if (bolts != null)
- {
- inventory.setPaperdollItem(PAPERDOLL_LHAND, null);
- }
- }
- else if (item.getItemType() == WeaponType.FISHINGROD)
- {
- L2ItemInstance lure = inventory.getPaperdollItem(PAPERDOLL_LHAND);
-
- if (lure != null)
- {
- inventory.setPaperdollItem(PAPERDOLL_LHAND, null);
- }
- }
- }
-
- @Override
- public void notifyEquiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (slot != PAPERDOLL_RHAND)
- {
- return;
- }
-
- if (item.getItemType() == WeaponType.BOW)
- {
- L2ItemInstance arrow = inventory.findArrowForBow(item.getItem());
-
- if (arrow != null)
- {
- inventory.setPaperdollItem(PAPERDOLL_LHAND, arrow);
- }
- }
- else if (item.getItemType() == WeaponType.CROSSBOW)
- {
- L2ItemInstance bolts = inventory.findBoltForCrossBow(item.getItem());
-
- if (bolts != null)
- {
- inventory.setPaperdollItem(PAPERDOLL_LHAND, bolts);
- }
- }
- }
- }
-
- private static final class StatsListener implements PaperdollListener
- {
- private static StatsListener instance = new StatsListener();
-
- public static StatsListener getInstance()
- {
- return instance;
- }
-
- @Override
- public void notifyUnequiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- inventory.getOwner().removeStatsOwner(item);
- }
-
- @Override
- public void notifyEquiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- inventory.getOwner().addStatFuncs(item.getStatFuncs(inventory.getOwner()));
- }
- }
-
- private static final class ItemSkillsListener implements PaperdollListener
- {
- private static ItemSkillsListener instance = new ItemSkillsListener();
-
- public static ItemSkillsListener getInstance()
- {
- return instance;
- }
-
- @Override
- public void notifyUnequiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (!(inventory.getOwner() instanceof L2PcInstance))
- {
- return;
- }
- final L2PcInstance player = (L2PcInstance) inventory.getOwner();
-
- Skill enchant4Skill, itemSkill;
- L2Item it = item.getItem();
- boolean update = false;
- boolean updateTimeStamp = false;
-
- // Remove augmentation bonuses on unequip
- if (item.isAugmented())
- {
- item.getAugmentation().removeBonus(player);
- }
-
- item.removeElementAttrBonus(player);
-
- // Remove skills bestowed from +4 armor
- if (item.getEnchantLevel() >= 4)
- {
- enchant4Skill = it.getEnchant4Skill();
-
- if (enchant4Skill != null)
- {
- player.removeSkill(enchant4Skill, false, enchant4Skill.isPassive());
- update = true;
- }
- }
-
- item.clearEnchantStats();
-
- final SkillHolder[] skills = it.getSkills();
-
- if (skills != null)
- {
- for (SkillHolder skillInfo : skills)
- {
- if (skillInfo == null)
- {
- continue;
- }
-
- itemSkill = skillInfo.getSkill();
-
- if (itemSkill != null)
- {
- player.removeSkill(itemSkill, false, itemSkill.isPassive());
- update = true;
- }
- else
- {
- _log.warning("Inventory.ItemSkillsListener.Weapon: Incorrect skill: " + skillInfo + ".");
- }
- }
- }
-
- if (item.isArmor())
- {
- for (L2ItemInstance itm : inventory.getItems())
- {
- if (!itm.isEquipped() || (itm.getItem().getSkills() == null) || itm.equals(item))
- {
- continue;
- }
- for (SkillHolder sk : itm.getItem().getSkills())
- {
- if (player.getSkillLevel(sk.getSkillId()) != -1)
- {
- continue;
- }
-
- itemSkill = sk.getSkill();
-
- if (itemSkill != null)
- {
- player.addSkill(itemSkill, false);
-
- if (itemSkill.isActive())
- {
- if (!player.hasSkillReuse(itemSkill.getReuseHashCode()))
- {
- int equipDelay = item.getEquipReuseDelay();
- if (equipDelay > 0)
- {
- player.addTimeStamp(itemSkill, equipDelay);
- player.disableSkill(itemSkill, equipDelay);
- }
- }
- updateTimeStamp = true;
- }
- update = true;
- }
- }
- }
- }
-
- // Apply skill, if weapon have "skills on unequip"
- Skill unequipSkill = it.getUnequipSkill();
- if (unequipSkill != null)
- {
- unequipSkill.activateSkill(player, player);
- }
-
- if (update)
- {
- player.sendSkillList();
-
- if (updateTimeStamp)
- {
- player.sendPacket(new SkillCoolTime(player));
- }
- }
- }
-
- @Override
- public void notifyEquiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (!(inventory.getOwner() instanceof L2PcInstance))
- {
- return;
- }
-
- final L2PcInstance player = (L2PcInstance) inventory.getOwner();
-
- Skill enchant4Skill, itemSkill;
- L2Item it = item.getItem();
- boolean update = false;
- boolean updateTimeStamp = false;
-
- // Apply augmentation bonuses on equip
- if (item.isAugmented())
- {
- item.getAugmentation().applyBonus(player);
- }
-
- item.updateElementAttrBonus(player);
-
- // Add skills bestowed from +4 armor
- if (item.getEnchantLevel() >= 4)
- {
- enchant4Skill = it.getEnchant4Skill();
-
- if (enchant4Skill != null)
- {
- player.addSkill(enchant4Skill, false);
- update = true;
- }
- }
-
- item.applyEnchantStats();
-
- final SkillHolder[] skills = it.getSkills();
-
- if (skills != null)
- {
- for (SkillHolder skillInfo : skills)
- {
- if (skillInfo == null)
- {
- continue;
- }
-
- itemSkill = skillInfo.getSkill();
-
- if (itemSkill != null)
- {
- itemSkill.setReferenceItemId(item.getId());
- player.addSkill(itemSkill, false);
-
- if (itemSkill.isActive())
- {
- if (!player.hasSkillReuse(itemSkill.getReuseHashCode()))
- {
- int equipDelay = item.getEquipReuseDelay();
- if (equipDelay > 0)
- {
- player.addTimeStamp(itemSkill, equipDelay);
- player.disableSkill(itemSkill, equipDelay);
- }
- }
- updateTimeStamp = true;
- }
- update = true;
- }
- else
- {
- _log.warning("Inventory.ItemSkillsListener.Weapon: Incorrect skill: " + skillInfo + ".");
- }
- }
- }
-
- if (update)
- {
- player.sendSkillList();
-
- if (updateTimeStamp)
- {
- player.sendPacket(new SkillCoolTime(player));
- }
- }
- }
- }
-
- private static final class ArmorSetListener implements PaperdollListener
- {
- private static ArmorSetListener instance = new ArmorSetListener();
-
- public static ArmorSetListener getInstance()
- {
- return instance;
- }
-
- @Override
- public void notifyEquiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (!(inventory.getOwner() instanceof L2PcInstance))
- {
- return;
- }
-
- final L2PcInstance player = (L2PcInstance) inventory.getOwner();
-
- // Checks if player is wearing a chest item
- final L2ItemInstance chestItem = inventory.getPaperdollItem(PAPERDOLL_CHEST);
-
- if (chestItem == null)
- {
- return;
- }
-
- // Checks for armor set for the equipped chest.
- if (!ArmorSetsData.getInstance().isArmorSet(chestItem.getId()))
- {
- return;
- }
- final L2ArmorSet armorSet = ArmorSetsData.getInstance().getSet(chestItem.getId());
- boolean update = false;
- boolean updateTimeStamp = false;
- // Checks if equipped item is part of set
- if (armorSet.containItem(slot, item.getId()))
- {
- if (armorSet.containAll(player))
- {
- Skill itemSkill;
- final List<SkillHolder> skills = armorSet.getSkills();
-
- if (skills != null)
- {
- for (SkillHolder holder : skills)
- {
-
- itemSkill = holder.getSkill();
- if (itemSkill != null)
- {
- player.addSkill(itemSkill, false);
-
- if (itemSkill.isActive())
- {
- if (!player.hasSkillReuse(itemSkill.getReuseHashCode()))
- {
- int equipDelay = item.getEquipReuseDelay();
- if (equipDelay > 0)
- {
- player.addTimeStamp(itemSkill, equipDelay);
- player.disableSkill(itemSkill, equipDelay);
- }
- }
- updateTimeStamp = true;
- }
- update = true;
- }
- else
- {
- _log.warning("Inventory.ArmorSetListener: Incorrect skill: " + holder + ".");
- }
- }
- }
-
- if (armorSet.containShield(player)) // has shield from set
- {
- for (SkillHolder holder : armorSet.getShieldSkillId())
- {
- if (holder.getSkill() != null)
- {
- player.addSkill(holder.getSkill(), false);
- update = true;
- }
- else
- {
- _log.warning("Inventory.ArmorSetListener: Incorrect skill: " + holder + ".");
- }
- }
- }
-
- if (armorSet.isEnchanted6(player)) // has all parts of set enchanted to 6 or more
- {
- for (SkillHolder holder : armorSet.getEnchant6skillId())
- {
- if (holder.getSkill() != null)
- {
- player.addSkill(holder.getSkill(), false);
- update = true;
- }
- else
- {
- _log.warning("Inventory.ArmorSetListener: Incorrect skill: " + holder + ".");
- }
- }
- }
- }
- }
- else if (armorSet.containShield(item.getId()))
- {
- for (SkillHolder holder : armorSet.getShieldSkillId())
- {
- if (holder.getSkill() != null)
- {
- player.addSkill(holder.getSkill(), false);
- update = true;
- }
- else
- {
- _log.warning("Inventory.ArmorSetListener: Incorrect skill: " + holder + ".");
- }
- }
- }
-
- if (update)
- {
- player.sendSkillList();
-
- if (updateTimeStamp)
- {
- player.sendPacket(new SkillCoolTime(player));
- }
- }
- }
-
- @Override
- public void notifyUnequiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (!(inventory.getOwner() instanceof L2PcInstance))
- {
- return;
- }
-
- final L2PcInstance player = (L2PcInstance) inventory.getOwner();
-
- boolean remove = false;
- Skill itemSkill;
- List<SkillHolder> skills = null;
- List<SkillHolder> shieldSkill = null; // shield skill
- List<SkillHolder> skillId6 = null; // enchant +6 skill
-
- if (slot == PAPERDOLL_CHEST)
- {
- if (!ArmorSetsData.getInstance().isArmorSet(item.getId()))
- {
- return;
- }
- final L2ArmorSet armorSet = ArmorSetsData.getInstance().getSet(item.getId());
- remove = true;
- skills = armorSet.getSkills();
- shieldSkill = armorSet.getShieldSkillId();
- skillId6 = armorSet.getEnchant6skillId();
- }
- else
- {
- L2ItemInstance chestItem = inventory.getPaperdollItem(PAPERDOLL_CHEST);
- if (chestItem == null)
- {
- return;
- }
-
- L2ArmorSet armorSet = ArmorSetsData.getInstance().getSet(chestItem.getId());
- if (armorSet == null)
- {
- return;
- }
-
- if (armorSet.containItem(slot, item.getId())) // removed part of set
- {
- remove = true;
- skills = armorSet.getSkills();
- shieldSkill = armorSet.getShieldSkillId();
- skillId6 = armorSet.getEnchant6skillId();
- }
- else if (armorSet.containShield(item.getId())) // removed shield
- {
- remove = true;
- shieldSkill = armorSet.getShieldSkillId();
- }
- }
-
- if (remove)
- {
- if (skills != null)
- {
- for (SkillHolder holder : skills)
- {
- itemSkill = holder.getSkill();
- if (itemSkill != null)
- {
- player.removeSkill(itemSkill, false, itemSkill.isPassive());
- }
- else
- {
- _log.warning("Inventory.ArmorSetListener: Incorrect skill: " + holder + ".");
- }
- }
- }
-
- if (shieldSkill != null)
- {
- for (SkillHolder holder : shieldSkill)
- {
- itemSkill = holder.getSkill();
- if (itemSkill != null)
- {
- player.removeSkill(itemSkill, false, itemSkill.isPassive());
- }
- else
- {
- _log.warning("Inventory.ArmorSetListener: Incorrect skill: " + holder + ".");
- }
- }
- }
-
- if (skillId6 != null)
- {
- for (SkillHolder holder : skillId6)
- {
- itemSkill = holder.getSkill();
- if (itemSkill != null)
- {
- player.removeSkill(itemSkill, false, itemSkill.isPassive());
- }
- else
- {
- _log.warning("Inventory.ArmorSetListener: Incorrect skill: " + holder + ".");
- }
- }
- }
-
- player.checkItemRestriction();
- player.sendSkillList();
- }
- }
- }
-
- private static final class BraceletListener implements PaperdollListener
- {
- private static BraceletListener instance = new BraceletListener();
-
- public static BraceletListener getInstance()
- {
- return instance;
- }
-
- @Override
- public void notifyUnequiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- if (item.getItem().getBodyPart() == L2Item.SLOT_R_BRACELET)
- {
- inventory.unEquipItemInSlot(PAPERDOLL_DECO1);
- inventory.unEquipItemInSlot(PAPERDOLL_DECO2);
- inventory.unEquipItemInSlot(PAPERDOLL_DECO3);
- inventory.unEquipItemInSlot(PAPERDOLL_DECO4);
- inventory.unEquipItemInSlot(PAPERDOLL_DECO5);
- inventory.unEquipItemInSlot(PAPERDOLL_DECO6);
- }
- }
-
- // Note (April 3, 2009): Currently on equip, talismans do not display properly, do we need checks here to fix this?
- @Override
- public void notifyEquiped(int slot, L2ItemInstance item, Inventory inventory)
- {
- }
- }
-
- /**
- * Constructor of the inventory
- */
- protected Inventory()
- {
- _paperdoll = new L2ItemInstance[PAPERDOLL_TOTALSLOTS];
- _paperdollListeners = new ArrayList<>();
-
- if (this instanceof PcInventory)
- {
- addPaperdollListener(ArmorSetListener.getInstance());
- addPaperdollListener(BowCrossRodListener.getInstance());
- addPaperdollListener(ItemSkillsListener.getInstance());
- addPaperdollListener(BraceletListener.getInstance());
- }
-
- // common
- addPaperdollListener(StatsListener.getInstance());
-
- }
-
- protected abstract ItemLocation getEquipLocation();
-
- /**
- * Returns the instance of new ChangeRecorder
- * @return ChangeRecorder
- */
- private ChangeRecorder newRecorder()
- {
- return new ChangeRecorder(this);
- }
-
- /**
- * Drop item from inventory and updates database
- * @param process : String Identifier of process triggering this action
- * @param item : L2ItemInstance to be dropped
- * @param actor : L2PcInstance Player requesting the item drop
- * @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
- * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
- */
- public L2ItemInstance dropItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
- {
- if (item == null)
- {
- return null;
- }
-
- synchronized (item)
- {
- if (!_items.contains(item))
- {
- return null;
- }
-
- removeItem(item);
- item.setOwnerId(process, 0, actor, reference);
- item.setItemLocation(ItemLocation.VOID);
- item.setLastChange(L2ItemInstance.REMOVED);
-
- item.updateDatabase();
- refreshWeight();
- }
- return item;
- }
-
- /**
- * Drop item from inventory by using its <B>objectID</B> and updates database
- * @param process : String Identifier of process triggering this action
- * @param objectId : int Item Instance identifier of the item to be dropped
- * @param count : int Quantity of items to be dropped
- * @param actor : L2PcInstance Player requesting the item drop
- * @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
- * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
- */
- public L2ItemInstance dropItem(String process, int objectId, long count, L2PcInstance actor, Object reference)
- {
- L2ItemInstance item = getItemByObjectId(objectId);
- if (item == null)
- {
- return null;
- }
-
- synchronized (item)
- {
- if (!_items.contains(item))
- {
- return null;
- }
-
- // Adjust item quantity and create new instance to drop
- // Directly drop entire item
- if (item.getCount() > count)
- {
- item.changeCount(process, -count, actor, reference);
- item.setLastChange(L2ItemInstance.MODIFIED);
- item.updateDatabase();
-
- item = ItemTable.getInstance().createItem(process, item.getId(), count, actor, reference);
- item.updateDatabase();
- refreshWeight();
- return item;
- }
- }
- return dropItem(process, item, actor, reference);
- }
-
- /**
- * Adds item to inventory for further adjustments and Equip it if necessary (itemlocation defined)
- * @param item : L2ItemInstance to be added from inventory
- */
- @Override
- protected void addItem(L2ItemInstance item)
- {
- super.addItem(item);
- if (item.isEquipped())
- {
- equipItem(item);
- }
- }
-
- /**
- * Removes item from inventory for further adjustments.
- * @param item : L2ItemInstance to be removed from inventory
- */
- @Override
- protected boolean removeItem(L2ItemInstance item)
- {
- // Unequip item if equiped
- for (int i = 0; i < _paperdoll.length; i++)
- {
- if (_paperdoll[i] == item)
- {
- unEquipItemInSlot(i);
- }
- }
- return super.removeItem(item);
- }
-
- /**
- * @param slot the slot.
- * @return the item in the paperdoll slot
- */
- public L2ItemInstance getPaperdollItem(int slot)
- {
- return _paperdoll[slot];
- }
-
- /**
- * @param slot the slot.
- * @return {@code true} if specified paperdoll slot is empty, {@code false} otherwise
- */
- public boolean isPaperdollSlotEmpty(int slot)
- {
- return _paperdoll[slot] == null;
- }
-
- public static int getPaperdollIndex(int slot)
- {
- switch (slot)
- {
- case L2Item.SLOT_UNDERWEAR:
- return PAPERDOLL_UNDER;
- case L2Item.SLOT_R_EAR:
- return PAPERDOLL_REAR;
- case L2Item.SLOT_LR_EAR:
- case L2Item.SLOT_L_EAR:
- return PAPERDOLL_LEAR;
- case L2Item.SLOT_NECK:
- return PAPERDOLL_NECK;
- case L2Item.SLOT_R_FINGER:
- case L2Item.SLOT_LR_FINGER:
- return PAPERDOLL_RFINGER;
- case L2Item.SLOT_L_FINGER:
- return PAPERDOLL_LFINGER;
- case L2Item.SLOT_HEAD:
- return PAPERDOLL_HEAD;
- case L2Item.SLOT_R_HAND:
- case L2Item.SLOT_LR_HAND:
- return PAPERDOLL_RHAND;
- case L2Item.SLOT_L_HAND:
- return PAPERDOLL_LHAND;
- case L2Item.SLOT_GLOVES:
- return PAPERDOLL_GLOVES;
- case L2Item.SLOT_CHEST:
- case L2Item.SLOT_FULL_ARMOR:
- case L2Item.SLOT_ALLDRESS:
- return PAPERDOLL_CHEST;
- case L2Item.SLOT_LEGS:
- return PAPERDOLL_LEGS;
- case L2Item.SLOT_FEET:
- return PAPERDOLL_FEET;
- case L2Item.SLOT_BACK:
- return PAPERDOLL_CLOAK;
- case L2Item.SLOT_HAIR:
- case L2Item.SLOT_HAIRALL:
- return PAPERDOLL_HAIR;
- case L2Item.SLOT_HAIR2:
- return PAPERDOLL_HAIR2;
- case L2Item.SLOT_R_BRACELET:
- return PAPERDOLL_RBRACELET;
- case L2Item.SLOT_L_BRACELET:
- return PAPERDOLL_LBRACELET;
- case L2Item.SLOT_DECO:
- return PAPERDOLL_DECO1; // return first we deal with it later
- case L2Item.SLOT_BELT:
- return PAPERDOLL_BELT;
- }
- return -1;
- }
-
- /**
- * Returns the item in the paperdoll L2Item slot
- * @param slot identifier
- * @return L2ItemInstance
- */
- public L2ItemInstance getPaperdollItemByL2ItemId(int slot)
- {
- int index = getPaperdollIndex(slot);
- if (index == -1)
- {
- return null;
- }
- return _paperdoll[index];
- }
-
- /**
- * Returns the ID of the item in the paperdoll slot
- * @param slot : int designating the slot
- * @return int designating the ID of the item
- */
- public int getPaperdollItemId(int slot)
- {
- L2ItemInstance item = _paperdoll[slot];
- if (item != null)
- {
- return item.getId();
- }
- return 0;
- }
-
- /**
- * Returns the ID of the item in the paperdoll slot
- * @param slot : int designating the slot
- * @return int designating the ID of the item
- */
- public int getPaperdollItemDisplayId(int slot)
- {
- final L2ItemInstance item = _paperdoll[slot];
- return (item != null) ? item.getDisplayId() : 0;
- }
-
- public int getPaperdollAugmentationId(int slot)
- {
- final L2ItemInstance item = _paperdoll[slot];
- return ((item != null) && (item.getAugmentation() != null)) ? item.getAugmentation().getAugmentationId() : 0;
- }
-
- /**
- * Returns the objectID associated to the item in the paperdoll slot
- * @param slot : int pointing out the slot
- * @return int designating the objectID
- */
- public int getPaperdollObjectId(int slot)
- {
- final L2ItemInstance item = _paperdoll[slot];
- return (item != null) ? item.getObjectId() : 0;
- }
-
- /**
- * Adds new inventory's paperdoll listener.
- * @param listener the new listener
- */
- public synchronized void addPaperdollListener(PaperdollListener listener)
- {
- assert !_paperdollListeners.contains(listener);
- _paperdollListeners.add(listener);
- }
-
- /**
- * Removes a paperdoll listener.
- * @param listener the listener to be deleted
- */
- public synchronized void removePaperdollListener(PaperdollListener listener)
- {
- _paperdollListeners.remove(listener);
- }
-
- /**
- * Equips an item in the given slot of the paperdoll.<br>
- * <U><I>Remark :</I></U> The item <B>must be</B> in the inventory already.
- * @param slot : int pointing out the slot of the paperdoll
- * @param item : L2ItemInstance pointing out the item to add in slot
- * @return L2ItemInstance designating the item placed in the slot before
- */
- public synchronized L2ItemInstance setPaperdollItem(int slot, L2ItemInstance item)
- {
- L2ItemInstance old = _paperdoll[slot];
- if (old != item)
- {
- if (old != null)
- {
- _paperdoll[slot] = null;
- // Put old item from paperdoll slot to base location
- old.setItemLocation(getBaseLocation());
- old.setLastChange(L2ItemInstance.MODIFIED);
- // Get the mask for paperdoll
- int mask = 0;
- for (int i = 0; i < PAPERDOLL_TOTALSLOTS; i++)
- {
- L2ItemInstance pi = _paperdoll[i];
- if (pi != null)
- {
- mask |= pi.getItem().getItemMask();
- }
- }
- _wearedMask = mask;
- // Notify all paperdoll listener in order to unequip old item in slot
- for (PaperdollListener listener : _paperdollListeners)
- {
- if (listener == null)
- {
- continue;
- }
-
- listener.notifyUnequiped(slot, old, this);
- }
- old.updateDatabase();
- }
- // Add new item in slot of paperdoll
- if (item != null)
- {
- _paperdoll[slot] = item;
- item.setItemLocation(getEquipLocation(), slot);
- item.setLastChange(L2ItemInstance.MODIFIED);
- _wearedMask |= item.getItem().getItemMask();
- for (PaperdollListener listener : _paperdollListeners)
- {
- if (listener == null)
- {
- continue;
- }
-
- listener.notifyEquiped(slot, item, this);
- }
- item.updateDatabase();
- }
- }
- return old;
- }
-
- /**
- * @return the mask of wore item
- */
- public int getWearedMask()
- {
- return _wearedMask;
- }
-
- public int getSlotFromItem(L2ItemInstance item)
- {
- int slot = -1;
- final int location = item.getLocationSlot();
- switch (location)
- {
- case PAPERDOLL_UNDER:
- slot = L2Item.SLOT_UNDERWEAR;
- break;
- case PAPERDOLL_LEAR:
- slot = L2Item.SLOT_L_EAR;
- break;
- case PAPERDOLL_REAR:
- slot = L2Item.SLOT_R_EAR;
- break;
- case PAPERDOLL_NECK:
- slot = L2Item.SLOT_NECK;
- break;
- case PAPERDOLL_RFINGER:
- slot = L2Item.SLOT_R_FINGER;
- break;
- case PAPERDOLL_LFINGER:
- slot = L2Item.SLOT_L_FINGER;
- break;
- case PAPERDOLL_HAIR:
- slot = L2Item.SLOT_HAIR;
- break;
- case PAPERDOLL_HAIR2:
- slot = L2Item.SLOT_HAIR2;
- break;
- case PAPERDOLL_HEAD:
- slot = L2Item.SLOT_HEAD;
- break;
- case PAPERDOLL_RHAND:
- slot = L2Item.SLOT_R_HAND;
- break;
- case PAPERDOLL_LHAND:
- slot = L2Item.SLOT_L_HAND;
- break;
- case PAPERDOLL_GLOVES:
- slot = L2Item.SLOT_GLOVES;
- break;
- case PAPERDOLL_CHEST:
- slot = item.getItem().getBodyPart();
- break;
- case PAPERDOLL_LEGS:
- slot = L2Item.SLOT_LEGS;
- break;
- case PAPERDOLL_CLOAK:
- slot = L2Item.SLOT_BACK;
- break;
- case PAPERDOLL_FEET:
- slot = L2Item.SLOT_FEET;
- break;
- case PAPERDOLL_LBRACELET:
- slot = L2Item.SLOT_L_BRACELET;
- break;
- case PAPERDOLL_RBRACELET:
- slot = L2Item.SLOT_R_BRACELET;
- break;
- case PAPERDOLL_DECO1:
- case PAPERDOLL_DECO2:
- case PAPERDOLL_DECO3:
- case PAPERDOLL_DECO4:
- case PAPERDOLL_DECO5:
- case PAPERDOLL_DECO6:
- slot = L2Item.SLOT_DECO;
- break;
- case PAPERDOLL_BELT:
- slot = L2Item.SLOT_BELT;
- break;
- }
- return slot;
- }
-
- /**
- * Unequips item in body slot and returns alterations.<BR>
- * <B>If you dont need return value use {@link Inventory#unEquipItemInBodySlot(int)} instead</B>
- * @param slot : int designating the slot of the paperdoll
- * @return L2ItemInstance[] : list of changes
- */
- public L2ItemInstance[] unEquipItemInBodySlotAndRecord(int slot)
- {
- Inventory.ChangeRecorder recorder = newRecorder();
-
- try
- {
- unEquipItemInBodySlot(slot);
- }
- finally
- {
- removePaperdollListener(recorder);
- }
- return recorder.getChangedItems();
- }
-
- /**
- * Sets item in slot of the paperdoll to null value
- * @param pdollSlot : int designating the slot
- * @return L2ItemInstance designating the item in slot before change
- */
- public L2ItemInstance unEquipItemInSlot(int pdollSlot)
- {
- return setPaperdollItem(pdollSlot, null);
- }
-
- /**
- * Unequips item in slot and returns alterations<BR>
- * <B>If you dont need return value use {@link Inventory#unEquipItemInSlot(int)} instead</B>
- * @param slot : int designating the slot
- * @return L2ItemInstance[] : list of items altered
- */
- public L2ItemInstance[] unEquipItemInSlotAndRecord(int slot)
- {
- Inventory.ChangeRecorder recorder = newRecorder();
-
- try
- {
- unEquipItemInSlot(slot);
- if (getOwner() instanceof L2PcInstance)
- {
- ((L2PcInstance) getOwner()).refreshExpertisePenalty();
- }
- }
- finally
- {
- removePaperdollListener(recorder);
- }
- return recorder.getChangedItems();
- }
-
- /**
- * Unequips item in slot (i.e. equips with default value)
- * @param slot : int designating the slot
- * @return {@link L2ItemInstance} designating the item placed in the slot
- */
- public L2ItemInstance unEquipItemInBodySlot(int slot)
- {
- if (Config.DEBUG)
- {
- _log.info(Inventory.class.getSimpleName() + ": Unequip body slot:" + slot);
- }
-
- int pdollSlot = -1;
-
- switch (slot)
- {
- case L2Item.SLOT_L_EAR:
- pdollSlot = PAPERDOLL_LEAR;
- break;
- case L2Item.SLOT_R_EAR:
- pdollSlot = PAPERDOLL_REAR;
- break;
- case L2Item.SLOT_NECK:
- pdollSlot = PAPERDOLL_NECK;
- break;
- case L2Item.SLOT_R_FINGER:
- pdollSlot = PAPERDOLL_RFINGER;
- break;
- case L2Item.SLOT_L_FINGER:
- pdollSlot = PAPERDOLL_LFINGER;
- break;
- case L2Item.SLOT_HAIR:
- pdollSlot = PAPERDOLL_HAIR;
- break;
- case L2Item.SLOT_HAIR2:
- pdollSlot = PAPERDOLL_HAIR2;
- break;
- case L2Item.SLOT_HAIRALL:
- setPaperdollItem(PAPERDOLL_HAIR, null);
- pdollSlot = PAPERDOLL_HAIR;
- break;
- case L2Item.SLOT_HEAD:
- pdollSlot = PAPERDOLL_HEAD;
- break;
- case L2Item.SLOT_R_HAND:
- case L2Item.SLOT_LR_HAND:
- pdollSlot = PAPERDOLL_RHAND;
- break;
- case L2Item.SLOT_L_HAND:
- pdollSlot = PAPERDOLL_LHAND;
- break;
- case L2Item.SLOT_GLOVES:
- pdollSlot = PAPERDOLL_GLOVES;
- break;
- case L2Item.SLOT_CHEST:
- case L2Item.SLOT_ALLDRESS:
- case L2Item.SLOT_FULL_ARMOR:
- pdollSlot = PAPERDOLL_CHEST;
- break;
- case L2Item.SLOT_LEGS:
- pdollSlot = PAPERDOLL_LEGS;
- break;
- case L2Item.SLOT_BACK:
- pdollSlot = PAPERDOLL_CLOAK;
- break;
- case L2Item.SLOT_FEET:
- pdollSlot = PAPERDOLL_FEET;
- break;
- case L2Item.SLOT_UNDERWEAR:
- pdollSlot = PAPERDOLL_UNDER;
- break;
- case L2Item.SLOT_L_BRACELET:
- pdollSlot = PAPERDOLL_LBRACELET;
- break;
- case L2Item.SLOT_R_BRACELET:
- pdollSlot = PAPERDOLL_RBRACELET;
- break;
- case L2Item.SLOT_DECO:
- pdollSlot = PAPERDOLL_DECO1;
- break;
- case L2Item.SLOT_BELT:
- pdollSlot = PAPERDOLL_BELT;
- break;
- default:
- _log.info("Unhandled slot type: " + slot);
- _log.info(StringUtil.getTraceString(Thread.currentThread().getStackTrace()));
- }
- if (pdollSlot >= 0)
- {
- L2ItemInstance old = setPaperdollItem(pdollSlot, null);
- if (old != null)
- {
- if (getOwner() instanceof L2PcInstance)
- {
- ((L2PcInstance) getOwner()).refreshExpertisePenalty();
- }
- }
- return old;
- }
- return null;
- }
-
- /**
- * Equips item and returns list of alterations<BR>
- * <B>If you don't need return value use {@link Inventory#equipItem(L2ItemInstance)} instead</B>
- * @param item : L2ItemInstance corresponding to the item
- * @return L2ItemInstance[] : list of alterations
- */
- public L2ItemInstance[] equipItemAndRecord(L2ItemInstance item)
- {
- Inventory.ChangeRecorder recorder = newRecorder();
-
- try
- {
- equipItem(item);
- }
- finally
- {
- removePaperdollListener(recorder);
- }
- return recorder.getChangedItems();
- }
-
- /**
- * Equips item in slot of paperdoll.
- * @param item : L2ItemInstance designating the item and slot used.
- */
- public void equipItem(L2ItemInstance item)
- {
- if ((getOwner() instanceof L2PcInstance) && (((L2PcInstance) getOwner()).getPrivateStoreType() != PrivateStoreType.NONE))
- {
- return;
- }
-
- if (getOwner() instanceof L2PcInstance)
- {
- L2PcInstance player = (L2PcInstance) getOwner();
-
- if (!player.canOverrideCond(PcCondOverride.ITEM_CONDITIONS) && !player.isHero() && item.isHeroItem())
- {
- return;
- }
- }
-
- int targetSlot = item.getItem().getBodyPart();
-
- // Check if player is using Formal Wear and item isn't Wedding Bouquet.
- L2ItemInstance formal = getPaperdollItem(PAPERDOLL_CHEST);
- if ((item.getId() != 21163) && (formal != null) && (formal.getItem().getBodyPart() == L2Item.SLOT_ALLDRESS))
- {
- // only chest target can pass this
- switch (targetSlot)
- {
- case L2Item.SLOT_LR_HAND:
- case L2Item.SLOT_L_HAND:
- case L2Item.SLOT_R_HAND:
- case L2Item.SLOT_LEGS:
- case L2Item.SLOT_FEET:
- case L2Item.SLOT_GLOVES:
- case L2Item.SLOT_HEAD:
- return;
- }
- }
-
- switch (targetSlot)
- {
- case L2Item.SLOT_LR_HAND:
- {
- setPaperdollItem(PAPERDOLL_LHAND, null);
- setPaperdollItem(PAPERDOLL_RHAND, item);
- break;
- }
- case L2Item.SLOT_L_HAND:
- {
- L2ItemInstance rh = getPaperdollItem(PAPERDOLL_RHAND);
- if ((rh != null) && (rh.getItem().getBodyPart() == L2Item.SLOT_LR_HAND) && !(((rh.getItemType() == WeaponType.BOW) && (item.getItemType() == EtcItemType.ARROW)) || ((rh.getItemType() == WeaponType.CROSSBOW) && (item.getItemType() == EtcItemType.BOLT)) || ((rh.getItemType() == WeaponType.FISHINGROD) && (item.getItemType() == EtcItemType.LURE))))
- {
- setPaperdollItem(PAPERDOLL_RHAND, null);
- }
-
- setPaperdollItem(PAPERDOLL_LHAND, item);
- break;
- }
- case L2Item.SLOT_R_HAND:
- {
- // don't care about arrows, listener will unequip them (hopefully)
- setPaperdollItem(PAPERDOLL_RHAND, item);
- break;
- }
- case L2Item.SLOT_L_EAR:
- case L2Item.SLOT_R_EAR:
- case L2Item.SLOT_LR_EAR:
- {
- if (_paperdoll[PAPERDOLL_LEAR] == null)
- {
- setPaperdollItem(PAPERDOLL_LEAR, item);
- }
- else if (_paperdoll[PAPERDOLL_REAR] == null)
- {
- setPaperdollItem(PAPERDOLL_REAR, item);
- }
- else
- {
- setPaperdollItem(PAPERDOLL_LEAR, item);
- }
- break;
- }
- case L2Item.SLOT_L_FINGER:
- case L2Item.SLOT_R_FINGER:
- case L2Item.SLOT_LR_FINGER:
- {
- if (_paperdoll[PAPERDOLL_LFINGER] == null)
- {
- setPaperdollItem(PAPERDOLL_LFINGER, item);
- }
- else if (_paperdoll[PAPERDOLL_RFINGER] == null)
- {
- setPaperdollItem(PAPERDOLL_RFINGER, item);
- }
- else
- {
- setPaperdollItem(PAPERDOLL_LFINGER, item);
- }
- break;
- }
- case L2Item.SLOT_NECK:
- setPaperdollItem(PAPERDOLL_NECK, item);
- break;
- case L2Item.SLOT_FULL_ARMOR:
- setPaperdollItem(PAPERDOLL_LEGS, null);
- setPaperdollItem(PAPERDOLL_CHEST, item);
- break;
- case L2Item.SLOT_CHEST:
- setPaperdollItem(PAPERDOLL_CHEST, item);
- break;
- case L2Item.SLOT_LEGS:
- {
- // handle full armor
- L2ItemInstance chest = getPaperdollItem(PAPERDOLL_CHEST);
- if ((chest != null) && (chest.getItem().getBodyPart() == L2Item.SLOT_FULL_ARMOR))
- {
- setPaperdollItem(PAPERDOLL_CHEST, null);
- }
-
- setPaperdollItem(PAPERDOLL_LEGS, item);
- break;
- }
- case L2Item.SLOT_FEET:
- setPaperdollItem(PAPERDOLL_FEET, item);
- break;
- case L2Item.SLOT_GLOVES:
- setPaperdollItem(PAPERDOLL_GLOVES, item);
- break;
- case L2Item.SLOT_HEAD:
- setPaperdollItem(PAPERDOLL_HEAD, item);
- break;
- case L2Item.SLOT_HAIR:
- L2ItemInstance hair = getPaperdollItem(PAPERDOLL_HAIR);
- if ((hair != null) && (hair.getItem().getBodyPart() == L2Item.SLOT_HAIRALL))
- {
- setPaperdollItem(PAPERDOLL_HAIR2, null);
- }
- else
- {
- setPaperdollItem(PAPERDOLL_HAIR, null);
- }
-
- setPaperdollItem(PAPERDOLL_HAIR, item);
- break;
- case L2Item.SLOT_HAIR2:
- L2ItemInstance hair2 = getPaperdollItem(PAPERDOLL_HAIR);
- if ((hair2 != null) && (hair2.getItem().getBodyPart() == L2Item.SLOT_HAIRALL))
- {
- setPaperdollItem(PAPERDOLL_HAIR, null);
- }
- else
- {
- setPaperdollItem(PAPERDOLL_HAIR2, null);
- }
-
- setPaperdollItem(PAPERDOLL_HAIR2, item);
- break;
- case L2Item.SLOT_HAIRALL:
- setPaperdollItem(PAPERDOLL_HAIR2, null);
- setPaperdollItem(PAPERDOLL_HAIR, item);
- break;
- case L2Item.SLOT_UNDERWEAR:
- setPaperdollItem(PAPERDOLL_UNDER, item);
- break;
- case L2Item.SLOT_BACK:
- setPaperdollItem(PAPERDOLL_CLOAK, item);
- break;
- case L2Item.SLOT_L_BRACELET:
- setPaperdollItem(PAPERDOLL_LBRACELET, item);
- break;
- case L2Item.SLOT_R_BRACELET:
- setPaperdollItem(PAPERDOLL_RBRACELET, item);
- break;
- case L2Item.SLOT_DECO:
- equipTalisman(item);
- break;
- case L2Item.SLOT_BELT:
- setPaperdollItem(PAPERDOLL_BELT, item);
- break;
- case L2Item.SLOT_ALLDRESS:
- // formal dress
- setPaperdollItem(PAPERDOLL_LEGS, null);
- setPaperdollItem(PAPERDOLL_LHAND, null);
- setPaperdollItem(PAPERDOLL_RHAND, null);
- setPaperdollItem(PAPERDOLL_RHAND, null);
- setPaperdollItem(PAPERDOLL_LHAND, null);
- setPaperdollItem(PAPERDOLL_HEAD, null);
- setPaperdollItem(PAPERDOLL_FEET, null);
- setPaperdollItem(PAPERDOLL_GLOVES, null);
- setPaperdollItem(PAPERDOLL_CHEST, item);
- break;
- default:
- _log.warning("Unknown body slot " + targetSlot + " for Item ID:" + item.getId());
- }
- }
-
- /**
- * Refresh the weight of equipment loaded
- */
- @Override
- protected void refreshWeight()
- {
- long weight = 0;
-
- for (L2ItemInstance item : _items)
- {
- if ((item != null) && (item.getItem() != null))
- {
- weight += item.getItem().getWeight() * item.getCount();
- }
- }
- _totalWeight = (int) Math.min(weight, Integer.MAX_VALUE);
- }
-
- /**
- * @return the totalWeight.
- */
- public int getTotalWeight()
- {
- return _totalWeight;
- }
-
- /**
- * Return the L2ItemInstance of the arrows needed for this bow.
- * @param bow : L2Item designating the bow
- * @return L2ItemInstance pointing out arrows for bow
- */
- public L2ItemInstance findArrowForBow(L2Item bow)
- {
- if (bow == null)
- {
- return null;
- }
-
- L2ItemInstance arrow = null;
-
- for (L2ItemInstance item : getItems())
- {
- if (item.isEtcItem() && (item.getItem().getItemGradeSPlus() == bow.getItemGradeSPlus()) && (item.getEtcItem().getItemType() == EtcItemType.ARROW))
- {
- arrow = item;
- break;
- }
- }
-
- // Get the L2ItemInstance corresponding to the item identifier and return it
- return arrow;
- }
-
- /**
- * Return the L2ItemInstance of the bolts needed for this crossbow.
- * @param crossbow : L2Item designating the crossbow
- * @return L2ItemInstance pointing out bolts for crossbow
- */
- public L2ItemInstance findBoltForCrossBow(L2Item crossbow)
- {
- L2ItemInstance bolt = null;
-
- for (L2ItemInstance item : getItems())
- {
- if (item.isEtcItem() && (item.getItem().getItemGradeSPlus() == crossbow.getItemGradeSPlus()) && (item.getEtcItem().getItemType() == EtcItemType.BOLT))
- {
- bolt = item;
- break;
- }
- }
-
- // Get the L2ItemInstance corresponding to the item identifier and return it
- return bolt;
- }
-
- /**
- * Get back items in inventory from database
- */
- @Override
- public void restore()
- {
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT object_id, item_id, count, enchant_level, loc, loc_data, custom_type1, custom_type2, mana_left, time FROM items WHERE owner_id=? AND (loc=? OR loc=?) ORDER BY loc_data"))
- {
- ps.setInt(1, getOwnerId());
- ps.setString(2, getBaseLocation().name());
- ps.setString(3, getEquipLocation().name());
- try (ResultSet inv = ps.executeQuery())
- {
- L2ItemInstance item;
- while (inv.next())
- {
- item = L2ItemInstance.restoreFromDb(getOwnerId(), inv);
- if (item == null)
- {
- continue;
- }
-
- if (getOwner() instanceof L2PcInstance)
- {
- L2PcInstance player = (L2PcInstance) getOwner();
-
- if (!player.canOverrideCond(PcCondOverride.ITEM_CONDITIONS) && !player.isHero() && item.isHeroItem())
- {
- item.setItemLocation(ItemLocation.INVENTORY);
- }
- }
-
- L2World.getInstance().storeObject(item);
-
- // If stackable item is found in inventory just add to current quantity
- if (item.isStackable() && (getItemByItemId(item.getId()) != null))
- {
- addItem("Restore", item, getOwner().getActingPlayer(), null);
- }
- else
- {
- addItem(item);
- }
- }
- }
- refreshWeight();
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, "Could not restore inventory: " + e.getMessage(), e);
- }
- }
-
- public int getTalismanSlots()
- {
- return getOwner().getActingPlayer().getStat().getTalismanSlots();
- }
-
- private void equipTalisman(L2ItemInstance item)
- {
- if (getTalismanSlots() == 0)
- {
- return;
- }
-
- // find same (or incompatible) talisman type
- for (int i = PAPERDOLL_DECO1; i < (PAPERDOLL_DECO1 + getTalismanSlots()); i++)
- {
- if (_paperdoll[i] != null)
- {
- if (getPaperdollItemId(i) == item.getId())
- {
- // overwtite
- setPaperdollItem(i, item);
- return;
- }
- }
- }
-
- // no free slot found - put on first free
- for (int i = PAPERDOLL_DECO1; i < (PAPERDOLL_DECO1 + getTalismanSlots()); i++)
- {
- if (_paperdoll[i] == null)
- {
- setPaperdollItem(i, item);
- return;
- }
- }
-
- // no free slots - put on first
- setPaperdollItem(PAPERDOLL_DECO1, item);
- }
-
- public boolean canEquipCloak()
- {
- return getOwner().getActingPlayer().getStat().canEquipCloak();
- }
-
- /**
- * Re-notify to paperdoll listeners every equipped item
- */
- public void reloadEquippedItems()
- {
- int slot;
-
- for (L2ItemInstance item : _paperdoll)
- {
- if (item == null)
- {
- continue;
- }
-
- slot = item.getLocationSlot();
-
- for (PaperdollListener listener : _paperdollListeners)
- {
- if (listener == null)
- {
- continue;
- }
-
- listener.notifyUnequiped(slot, item, this);
- listener.notifyEquiped(slot, item, this);
- }
- }
- }
- }
|