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

@ -563,13 +563,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, ManufactureItem> _manufactureItems;
private String _storeName = "";
private TradeList _sellList;
private TradeList _buyList;
private boolean _isUsingSkillItem;
// Multisell
private PreparedMultisellListHolder _currentMultiSell = null;
@ -4646,6 +4647,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;
@ -5596,16 +5614,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

@ -662,7 +662,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

@ -75,7 +75,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
{
@ -1330,12 +1330,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++)
@ -1347,6 +1354,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)
{
@ -1359,14 +1367,24 @@ public abstract class Inventory extends ItemContainer
}
old.updateDatabase();
}
// 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)
{
@ -1402,6 +1420,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
*/
@ -1702,7 +1739,6 @@ public abstract class Inventory extends ItemContainer
case ItemTemplate.SLOT_R_BRACELET:
{
pdollSlot = PAPERDOLL_RBRACELET;
containerItemCheck();
break;
}
case ItemTemplate.SLOT_DECO:
@ -1718,7 +1754,6 @@ public abstract class Inventory extends ItemContainer
case ItemTemplate.SLOT_BROOCH:
{
pdollSlot = PAPERDOLL_BROOCH;
containerItemCheck();
break;
}
case ItemTemplate.SLOT_BROOCH_JEWEL:
@ -1744,26 +1779,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;
}