Prevent flood from using items with skills.

This commit is contained in:
MobiusDevelopment
2022-02-03 22:05:30 +00:00
parent 9ba9ae38af
commit e0dc88e351
84 changed files with 1260 additions and 803 deletions

View File

@@ -584,13 +584,14 @@ public class Player extends Playable
private PlayerRefund _refund;
private PrivateStoreType _privateStoreType = PrivateStoreType.NONE;
private TradeList _activeTradeList;
private boolean _isUsingContainerItem;
private ItemContainer _activeWarehouse;
private Map<Integer, Long> _manufactureItems;
private String _storeName = "";
private TradeList _sellList;
private TradeList _buyList;
private boolean _isUsingSkillItem;
// Multisell
private PreparedMultisellListHolder _currentMultiSell = null;
@@ -4617,6 +4618,23 @@ public class Player extends Playable
}
}
/**
* @return if player is using an item that has skills.
*/
public boolean isUsingSkillItem()
{
return _isUsingSkillItem;
}
/**
* Set value of using an item that has skills.
* @param value : The value to set.
*/
public void setUsingSkillItem(boolean value)
{
_isUsingSkillItem = value;
}
public PreparedMultisellListHolder getMultiSell()
{
return _currentMultiSell;
@@ -5622,16 +5640,6 @@ public class Player extends Playable
return _activeWarehouse;
}
public boolean isUsingContainerItem()
{
return _isUsingContainerItem;
}
public void setUsingContainerItem(boolean value)
{
_isUsingContainerItem = value;
}
/**
* Select the TradeList to be used in next activity.
* @param tradeList

View File

@@ -683,7 +683,7 @@ public class PlayerStat extends PlayableStat
@Override
public void recalculateStats(boolean broadcast)
{
if (!getActiveChar().isChangingClass() && !getActiveChar().isUsingContainerItem())
if (!getActiveChar().isChangingClass() && !getActiveChar().isUsingSkillItem())
{
super.recalculateStats(broadcast);
}

View File

@@ -76,7 +76,7 @@ public abstract class Inventory extends ItemContainer
{
protected static final Logger LOGGER = Logger.getLogger(Inventory.class.getName());
private ScheduledFuture<?> _containerItemTask;
private ScheduledFuture<?> _skillItemTask;
public interface PaperdollListener
{
@@ -1437,12 +1437,19 @@ public abstract class Inventory extends ItemContainer
{
if (old != null)
{
// Prevent flood from using items with skills.
if (old.getItem().hasSkills())
{
checkEquipTask();
}
_paperdoll[slot] = null;
_paperdollCache.getPaperdollItems().remove(old);
// Put old item from paperdoll slot to base location
old.setItemLocation(getBaseLocation());
old.setLastChange(Item.MODIFIED);
// Get the mask for paperdoll
int mask = 0;
for (int i = 0; i < PAPERDOLL_TOTALSLOTS; i++)
@@ -1454,6 +1461,7 @@ public abstract class Inventory extends ItemContainer
}
}
_wearedMask = mask;
// Notify all paperdoll listener in order to unequip old item in slot
for (PaperdollListener listener : _paperdollListeners)
{
@@ -1491,14 +1499,24 @@ public abstract class Inventory extends ItemContainer
}
}
// Add new item in slot of paperdoll
if (item != null)
{
// Prevent flood from using items with skills.
if (item.getItem().hasSkills())
{
checkEquipTask();
}
_paperdoll[slot] = item;
_paperdollCache.getPaperdollItems().add(item);
// Put item to equip location
item.setItemLocation(getEquipLocation(), slot);
item.setLastChange(Item.MODIFIED);
// Notify all paperdoll listener in order to equip item in slot
_wearedMask |= item.getItem().getItemMask();
for (PaperdollListener listener : _paperdollListeners)
{
@@ -1569,6 +1587,25 @@ public abstract class Inventory extends ItemContainer
return old;
}
/**
* Prevent flood from using items with skills.
*/
private void checkEquipTask()
{
if ((_skillItemTask == null) && (getOwner() != null) && getOwner().isPlayer() && (getOwner().getActingPlayer().getUptime() > 5000))
{
getOwner().getActingPlayer().setUsingSkillItem(true);
_skillItemTask = ThreadPool.schedule(() ->
{
getOwner().getActingPlayer().setUsingSkillItem(false);
getOwner().getStat().recalculateStats(true);
getOwner().updateAbnormalVisualEffects();
getOwner().getActingPlayer().sendSkillList();
_skillItemTask = null;
}, 100);
}
}
/**
* @return the mask of wore item
*/
@@ -1875,12 +1912,10 @@ public abstract class Inventory extends ItemContainer
else if (slot == ItemTemplate.SLOT_L_BRACELET)
{
pdollSlot = PAPERDOLL_LBRACELET;
containerItemCheck();
}
else if (slot == ItemTemplate.SLOT_R_BRACELET)
{
pdollSlot = PAPERDOLL_RBRACELET;
containerItemCheck();
}
else if (slot == ItemTemplate.SLOT_DECO)
{
@@ -1893,7 +1928,6 @@ public abstract class Inventory extends ItemContainer
else if (slot == ItemTemplate.SLOT_BROOCH)
{
pdollSlot = PAPERDOLL_BROOCH;
containerItemCheck();
}
else if (slot == ItemTemplate.SLOT_BROOCH_JEWEL)
{
@@ -1906,7 +1940,6 @@ public abstract class Inventory extends ItemContainer
else if (slot == ItemTemplate.SLOT_ARTIFACT_BOOK)
{
pdollSlot = PAPERDOLL_ARTIFACT_BOOK;
containerItemCheck();
}
else if (slot == ItemTemplate.SLOT_ARTIFACT)
{
@@ -1924,26 +1957,6 @@ public abstract class Inventory extends ItemContainer
return null;
}
/**
* Avoid flood from container items.
*/
private void containerItemCheck()
{
final Creature owner = getOwner();
if ((owner != null) && owner.isPlayer() && (_containerItemTask == null))
{
owner.getActingPlayer().setUsingContainerItem(true);
_containerItemTask = ThreadPool.schedule(() ->
{
owner.getActingPlayer().setUsingContainerItem(false);
owner.getStat().recalculateStats(true);
owner.updateAbnormalVisualEffects();
owner.getActingPlayer().sendSkillList();
_containerItemTask = null;
}, 100);
}
}
/**
* Equips item and returns list of alterations<br>
* <b>If you don't need return value use {@link Inventory#equipItem(Item)} instead</b>

View File

@@ -229,8 +229,8 @@ public class GameClient extends ChannelInboundHandler<GameClient>
if (_player != null)
{
// Avoid flood from class change or container items.
if ((_player.isChangingClass() || _player.isUsingContainerItem()) && ((packet instanceof SkillList) || (packet instanceof AcquireSkillList) || (packet instanceof ExUserInfoAbnormalVisualEffect) || (packet instanceof AbnormalStatusUpdate) || (packet instanceof ExAbnormalStatusUpdateFromTarget)))
// Avoid flood from class change or using items with skills.
if ((_player.isChangingClass() || _player.isUsingSkillItem()) && ((packet instanceof SkillList) || (packet instanceof AcquireSkillList) || (packet instanceof ExUserInfoAbnormalVisualEffect) || (packet instanceof AbnormalStatusUpdate) || (packet instanceof ExAbnormalStatusUpdateFromTarget)))
{
return;
}