L2JMobius
Free Users => Shares/Contributions => Committed User Contributions => Topic started by: AnsS on January 03, 2021, 05:15:10 PM
-
Hi all,
Auto functions are auto potion, auto supply and auto skills.
Basic issue: if you disable any auto function, it disables all.
Another issue: automatic potion is registered as auto supply.
Here is my changes - note: im absolute beginner in L2J and Mobius:
From fc6f8962f3bd6b5ba87ed25db2b0cb6641818776 Mon Sep 17 00:00:00 2001
From: AnsS <[email protected]>
Date: Sun, 3 Jan 2021 16:00:50 +0100
Subject: [PATCH] Fix auto functions
---
.../model/holders/AutoUseSettingsHolder.java | 4 ++
.../autoplay/ExRequestActivateAutoShortcut.java | 46 +++++++++++-----------
.../gameserver/taskmanager/AutoUseTaskManager.java | 10 +++--
3 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/java/org/l2jmobius/gameserver/model/holders/AutoUseSettingsHolder.java b/java/org/l2jmobius/gameserver/model/holders/AutoUseSettingsHolder.java
index 2de1989..6d685d0 100644
--- a/java/org/l2jmobius/gameserver/model/holders/AutoUseSettingsHolder.java
+++ b/java/org/l2jmobius/gameserver/model/holders/AutoUseSettingsHolder.java
@@ -31,6 +31,10 @@ public class AutoUseSettingsHolder
public AutoUseSettingsHolder()
{
}
+
+ public boolean allIsEmpty() {
+ return _autoSupplyItems.isEmpty() && _autoPotionItems.isEmpty() && _autoSkills.isEmpty();
+ }
public Collection<Integer> getAutoSupplyItems()
{
diff --git a/java/org/l2jmobius/gameserver/network/clientpackets/autoplay/ExRequestActivateAutoShortcut.java b/java/org/l2jmobius/gameserver/network/clientpackets/autoplay/ExRequestActivateAutoShortcut.java
index 8a8ed87..d5f43ad 100644
--- a/java/org/l2jmobius/gameserver/network/clientpackets/autoplay/ExRequestActivateAutoShortcut.java
+++ b/java/org/l2jmobius/gameserver/network/clientpackets/autoplay/ExRequestActivateAutoShortcut.java
@@ -67,20 +67,18 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
{
skill = player.getKnownSkill(shortcut.getId());
}
-
+
// stop
if (!_activate)
{
if (item != null)
{
- // auto supply
- if (_room > 263)
- {
- AutoUseTaskManager.getInstance().removeAutoSupplyItem(player, item.getId());
- }
- else // auto potion
- {
- AutoUseTaskManager.getInstance().removeAutoPotionItem(player, item.getId());
+ if (_room > 263 && _room < 278) { // auto supply or potion
+ if (_room == 277) { // auto potion
+ AutoUseTaskManager.getInstance().removeAutoPotionItem(player, item.getId());
+ } else {
+ AutoUseTaskManager.getInstance().removeAutoSupplyItem(player, item.getId());
+ }
}
}
// auto skill
@@ -92,25 +90,27 @@ public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
}
// start
- if (_room > 263)
+ if (_room > 263 && _room < 278)
{
- // auto supply
- if (Config.ENABLE_AUTO_ITEM && (item != null))
- {
- AutoUseTaskManager.getInstance().addAutoSupplyItem(player, item.getId());
+ if (_room == 277) {
+ // auto potion
+ if ((page == 23) && (slot == 1))
+ {
+ if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
+ {
+ AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
+ }
+ }
+ } else {
+ // auto supply
+ if (Config.ENABLE_AUTO_ITEM && (item != null))
+ {
+ AutoUseTaskManager.getInstance().addAutoSupplyItem(player, item.getId());
+ }
}
}
else
{
- // auto potion
- if ((page == 23) && (slot == 1))
- {
- if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
- {
- AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
- return;
- }
- }
// auto skill
if (Config.ENABLE_AUTO_BUFF && (skill != null))
{
diff --git a/java/org/l2jmobius/gameserver/taskmanager/AutoUseTaskManager.java b/java/org/l2jmobius/gameserver/taskmanager/AutoUseTaskManager.java
index 03033d8..5dc6001 100644
--- a/java/org/l2jmobius/gameserver/taskmanager/AutoUseTaskManager.java
+++ b/java/org/l2jmobius/gameserver/taskmanager/AutoUseTaskManager.java
@@ -171,7 +171,9 @@ public class AutoUseTaskManager
public void stopAutoUseTask(PlayerInstance player)
{
- PLAYERS.remove(player);
+ if (player.getAutoUseSettings().allIsEmpty()) {
+ PLAYERS.remove(player);
+ }
}
public void addAutoSupplyItem(PlayerInstance player, int itemId)
--
2.10.5
-
If this is tested to work it should be moved to contributions.
Also, use allman coding style. :)
-
Yes, I have tested it. Should I post next time to the contrib board?
I modified Java code style :)
-
Moved.
-
What we use in private version for ExRequestActivateAutoShortcut
/*
* This file is part of the L2J Mobius project.
*
* 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 org.l2jmobius.gameserver.network.clientpackets.autoplay;
import org.l2jmobius.Config;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.Shortcut;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.model.skills.Skill;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.autoplay.ExActivateAutoShortcut;
import org.l2jmobius.gameserver.taskmanager.AutoUseTaskManager;
/**
* @author JoeAlisson, Mobius
*/
public class ExRequestActivateAutoShortcut implements IClientIncomingPacket
{
private boolean _activate;
private int _room;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_room = packet.readH();
_activate = packet.readC() == 1;
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
final int slot = _room % 12;
final int page = _room / 12;
final Shortcut shortcut = player.getShortCut(slot, page);
if (shortcut == null)
{
return;
}
client.sendPacket(new ExActivateAutoShortcut(_room, _activate));
final ItemInstance item = player.getInventory().getItemByObjectId(shortcut.getId());
Skill skill = null;
if (item == null)
{
skill = player.getKnownSkill(shortcut.getId());
}
// stop
if (!_activate)
{
if (item != null)
{
// auto supply
if (!item.isPotion())
{
AutoUseTaskManager.getInstance().removeAutoSupplyItem(player, item.getId());
}
else // auto potion
{
AutoUseTaskManager.getInstance().removeAutoPotionItem(player, item.getId());
}
}
// auto skill
if (skill != null)
{
AutoUseTaskManager.getInstance().removeAutoSkill(player, skill.getId());
}
return;
}
// start
if ((item != null) && !item.isPotion())
{
// auto supply
if (Config.ENABLE_AUTO_ITEM)
{
AutoUseTaskManager.getInstance().addAutoSupplyItem(player, item.getId());
}
}
else
{
// auto potion
if ((page == 23) && (slot == 1))
{
if (Config.ENABLE_AUTO_POTION && (item != null) && item.isPotion())
{
AutoUseTaskManager.getInstance().addAutoPotionItem(player, item.getId());
return;
}
}
// auto skill
if (Config.ENABLE_AUTO_BUFF && (skill != null))
{
AutoUseTaskManager.getInstance().addAutoSkill(player, skill.getId());
return;
}
}
}
}
Also you should remove players when they are offline.
public void stopAutoUseTask(PlayerInstance player)
{
if (!player.isOnline() || player.isInOfflineMode() || player.getAutoUseSettings().allIsEmpty())
{
PLAYERS.remove(player);
}
}
-
Thanks for the offline player mention :)
I have a question, in ExRequestActivateAutoShortcut.java:
// start
if ((item != null) && !item.isPotion())
{
// auto supply
if (Config.ENABLE_AUTO_ITEM)
{
AutoUseTaskManager.getInstance().addAutoSupplyItem(player, item.getId());
}
}
This will prevent using auto reusable potions as a supply item (which I think a problem), am I right?
-
Not really, just not make them potions in datapack.
<set name="etcitem_type" val="POTION" />
can be
<set name="etcitem_type" val="SCROLL" />
Buff scrolls / items exist since ever and potions should be potions. :P
On the private version we have updated many values based on client info.
If anything is not proper, it can easily be changed manually.
-
Committed with https://bitbucket.org/MobiusDev/l2j_mobius/commits/453cff3e26f289eb909f14960fb8b87f5318fa53
Thanks :D