L2JMobius

Free Users => Work in Progress => Topic started by: gigilo1968 on November 14, 2022, 09:05:52 PM

Title: Implemented Daily Mission quests (Item Use handler)
Post by: gigilo1968 on November 14, 2022, 09:05:52 PM
1.  When item use player at works fine
2.  When item autouse or use in UI window, not work

Code: [Select]
### Eclipse Workspace Patch 1.0
#P L2J_Mobius_10.1_MasterClass
diff --git .gitignore .gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ .gitignore
@@ -0,0 +1 @@
+/bin/
diff --git dist/game/data/DailyMission.xml dist/game/data/DailyMission.xml
index 0bf8ede..3532179 100644
--- dist/game/data/DailyMission.xml
+++ dist/game/data/DailyMission.xml
@@ -1232,17 +1232,6 @@
  <item id="-300" count="10000" /> Fame
  </items>
  </reward>
- <reward id="4101" name="Power of Freya's Scroll" requiredCompletion="24" isOneTime="false">
- Use any of the following scrolls 24 times: Freya's Frozen Scroll Freya's Frozen Scroll (Event) Freya's Scroll of Storm Freya's Scroll of Storm (Event) PA Scroll of Storm
- <handler name="useitem">
- <param name="minLevel">85</param>
- <param name="maxLevel">255</param>
- </handler>
- <items>
- <item id="-200" count="25" /> Clan Reputation
- <item id="-300" count="250" /> Fame
- </items>
- </reward>
  <reward id="4103" name="Power of Freya's Ice Rose" requiredCompletion="8" isOneTime="false">
  Use any of the following items 8 times: Freya's Ice Rose Freya's Ice Rose (Event) PA Ice Rose
  <handler name="useitem">
@@ -1385,10 +1374,22 @@
  </items>
  </reward>
  -->
- <reward id="4103" name="Power of Freya's Ice Rose" requiredCompletion="8" isOneTime="false" dailyReset="true">
+ <reward id="4101" name="Power of Freya's Scroll" requiredCompletion="24" isOneTime="false">
+ <!-- Use any of the following scrolls 24 times: Freya's Frozen Scroll Freya's Frozen Scroll (Event) Freya's Scroll of Storm Freya's Scroll of Storm (Event) PA Scroll of Storm -->
  <handler name="useitem">
+ <param name="itemId">40227,40231,47382,80746,27673,47428,81054</param>
  <param name="minLevel">85</param>
- <param name="maxLevel">255</param>
+ </handler>
+ <items>
+ <item id="-200" count="25" />
+ <item id="-300" count="250" />
+ </items>
+ </reward>
+ <reward id="4103" name="Power of Freya's Ice Rose" requiredCompletion="8" isOneTime="false">
+ <!-- Use any of the following items 8 times: Freya's Ice Rose Freya's Ice Rose (Event) PA Ice Rose -->
+ <handler name="useitem">
+ <param name="itemId">29789,48830,48848,48848,80441,80442,80612,80745</param>
+ <param name="minLevel">85</param>
  </handler>
  <items>
  <item id="-200" count="25" />
diff --git dist/game/data/scripts/handlers/DailyMissionMasterHandler.java dist/game/data/scripts/handlers/DailyMissionMasterHandler.java
index d6889f4..660af7d 100644
--- dist/game/data/scripts/handlers/DailyMissionMasterHandler.java
+++ dist/game/data/scripts/handlers/DailyMissionMasterHandler.java
@@ -23,6 +23,7 @@
 import handlers.dailymissionhandlers.BossDailyMissionHandler;
 import handlers.dailymissionhandlers.CeremonyOfChaosDailyMissionHandler;
 import handlers.dailymissionhandlers.FishingDailyMissionHandler;
+import handlers.dailymissionhandlers.ItemDailyMissionHandler;
 import handlers.dailymissionhandlers.LevelDailyMissionHandler;
 import handlers.dailymissionhandlers.LoginMonthDailyMissionHandler;
 import handlers.dailymissionhandlers.LoginWeekendDailyMissionHandler;
@@ -50,6 +51,7 @@
  DailyMissionHandler.getInstance().registerHandler("boss", BossDailyMissionHandler::new);
  DailyMissionHandler.getInstance().registerHandler("monster", MonsterDailyMissionHandler::new);
  DailyMissionHandler.getInstance().registerHandler("fishing", FishingDailyMissionHandler::new);
+ DailyMissionHandler.getInstance().registerHandler("useitem", ItemDailyMissionHandler::new);
  LOGGER.info(DailyMissionMasterHandler.class.getSimpleName() + ":  Loaded " + DailyMissionHandler.getInstance().size() + " handlers.");
  }
 }
diff --git dist/game/data/scripts/handlers/dailymissionhandlers/ItemDailyMissionHandler.java dist/game/data/scripts/handlers/dailymissionhandlers/ItemDailyMissionHandler.java
new file mode 100644
index 0000000..1738af9
--- /dev/null
+++ dist/game/data/scripts/handlers/dailymissionhandlers/ItemDailyMissionHandler.java
@@ -0,0 +1,114 @@
+/*
+ * 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 handlers.dailymissionhandlers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.l2jmobius.gameserver.enums.DailyMissionStatus;
+import org.l2jmobius.gameserver.handler.AbstractDailyMissionHandler;
+import org.l2jmobius.gameserver.model.DailyMissionDataHolder;
+import org.l2jmobius.gameserver.model.DailyMissionPlayerEntry;
+import org.l2jmobius.gameserver.model.actor.Player;
+import org.l2jmobius.gameserver.model.events.Containers;
+import org.l2jmobius.gameserver.model.events.EventType;
+import org.l2jmobius.gameserver.model.events.impl.item.OnItemUse;
+import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
+import org.l2jmobius.gameserver.model.item.instance.Item;
+
+/**
+ * @author Gigi
+ */
+public class ItemDailyMissionHandler extends AbstractDailyMissionHandler
+{
+ private final int _amount;
+ private final int _minLevel;
+ private final Set<Integer> _itemList = new HashSet<>();
+
+ public ItemDailyMissionHandler(DailyMissionDataHolder holder)
+ {
+ super(holder);
+ _amount = holder.getRequiredCompletions();
+ _minLevel = holder.getParams().getInt("minLevel", 0);
+ final String items = holder.getParams().getString("itemId", "");
+ if (!items.isEmpty())
+ {
+ for (String s : items.split(","))
+ {
+ final int ids = Integer.parseInt(s);
+ if (!_itemList.contains(ids))
+ {
+ _itemList.add(ids);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void init()
+ {
+ Containers.Global().addListener(new ConsumerEventListener(this, EventType.ON_ITEM_USE, (OnItemUse event) -> OnItemUse(event), this));
+ }
+
+ @Override
+ public boolean isAvailable(Player player)
+ {
+ final DailyMissionPlayerEntry entry = getPlayerEntry(player.getObjectId(), false);
+ if (entry != null)
+ {
+ switch (entry.getStatus())
+ {
+ case NOT_AVAILABLE: // Initial state
+ {
+ if (entry.getProgress() >= _amount)
+ {
+ entry.setStatus(DailyMissionStatus.AVAILABLE);
+ storePlayerEntry(entry);
+ }
+ break;
+ }
+ case AVAILABLE:
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void OnItemUse(OnItemUse event)
+ {
+ final Item item = event.getItem();
+ final Player player = event.getPlayer();
+ if (!_itemList.isEmpty() && !_itemList.contains(item.getId()))
+ {
+ return;
+ }
+ if (player.getLevel() > _minLevel)
+ {
+ final DailyMissionPlayerEntry entry = getPlayerEntry(player.getObjectId(), true);
+ if (entry.getStatus() == DailyMissionStatus.NOT_AVAILABLE)
+ {
+ if (entry.increaseProgress() >= _amount)
+ {
+ entry.setStatus(DailyMissionStatus.AVAILABLE);
+ }
+ }
+ storePlayerEntry(entry);
+ }
+ }
+}
diff --git java/org/l2jmobius/gameserver/model/events/EventType.java java/org/l2jmobius/gameserver/model/events/EventType.java
index 1537518..d3ae1d5 100644
--- java/org/l2jmobius/gameserver/model/events/EventType.java
+++ java/org/l2jmobius/gameserver/model/events/EventType.java
@@ -127,6 +127,7 @@
 import org.l2jmobius.gameserver.model.events.impl.item.OnItemEnchantAdd;
 import org.l2jmobius.gameserver.model.events.impl.item.OnItemSoulCrystalAdd;
 import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
+import org.l2jmobius.gameserver.model.events.impl.item.OnItemUse;
 import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
 import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
 import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
@@ -182,6 +183,7 @@
  // Item events
  ON_ITEM_BYPASS_EVENT(OnItemBypassEvent.class, void.class),
  ON_ITEM_CREATE(OnItemCreate.class, void.class),
+ ON_ITEM_USE(OnItemUse.class, void.class),
  ON_ITEM_TALK(OnItemTalk.class, void.class),
  ON_ITEM_ATTRIBUTE_ADD(OnItemAttributeAdd.class, void.class),
  ON_ITEM_SOUL_CRYSTAL_ADD(OnItemSoulCrystalAdd.class, void.class),
diff --git java/org/l2jmobius/gameserver/model/events/impl/item/OnItemUse.java java/org/l2jmobius/gameserver/model/events/impl/item/OnItemUse.java
new file mode 100644
index 0000000..e7e07b7
--- /dev/null
+++ java/org/l2jmobius/gameserver/model/events/impl/item/OnItemUse.java
@@ -0,0 +1,53 @@
+/*
+ * 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.model.events.impl.item;
+
+import org.l2jmobius.gameserver.model.actor.Player;
+import org.l2jmobius.gameserver.model.events.EventType;
+import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
+import org.l2jmobius.gameserver.model.item.instance.Item;
+
+/**
+ * @author Gigi
+ */
+public class OnItemUse implements IBaseEvent
+{
+ private final Player _player;
+ private final Item _item;
+
+ public OnItemUse(Player player, Item item)
+ {
+ _player = player;
+ _item = item;
+ }
+
+ public Player getPlayer()
+ {
+ return _player;
+ }
+
+ public Item getItem()
+ {
+ return _item;
+ }
+
+ @Override
+ public EventType getType()
+ {
+ return EventType.ON_ITEM_USE;
+ }
+}
\ No newline at end of file

Any idea how to fix it
Title: Re: Implemented Daily Mission quests (Item Use handler)
Post by: Mobius on November 15, 2022, 03:33:59 PM
Already fixed on subscriber version.
Will not reach xmas free version tho.
Title: Re: Implemented Daily Mission quests (Item Use handler)
Post by: gigilo1968 on November 16, 2022, 09:56:13 AM
Already fixed on subscriber version.
Will not reach xmas free version tho.

I never use other people's files, I don't need it
Title: Re: Implemented Daily Mission quests (Item Use handler)
Post by: Mobius on November 17, 2022, 05:25:50 AM
I never use other people's files, I don't need it

Definitely not.
You just want to take a peek.
(https://i.ibb.co/x5bQq1s/image.png) (https://ibb.co/bdVn5s3)
:D
Title: Re: Implemented Daily Mission quests (Item Use handler)
Post by: gigilo1968 on November 17, 2022, 08:46:22 AM
Only for open hide content ..
I use Fafurion chronicle
Title: Re: Implemented Daily Mission quests (Item Use handler)
Post by: nasseka on November 17, 2022, 08:58:04 AM
The tag says Master Class.... :D
Only for open hide content ..
I use Fafurion chronicle
Title: Re: Implemented Daily Mission quests (Item Use handler)
Post by: gigilo1968 on November 17, 2022, 10:51:15 AM
Yes I added last public chronicle, in Fafurion the same problem for auto use item.
Also not show completed mission alert, I don't understand why deleted getablereward packet. I rewerted this class for clan mission, and all work fine