Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_gameserver
- Index: java/net/sf/l2j/gameserver/taskmanager/HeroTaskManager.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/taskmanager/HeroTaskManager.java (nonexistent)
- +++ java/net/sf/l2j/gameserver/taskmanager/HeroTaskManager.java (working copy)
- @@ -0,0 +1,86 @@
- +/*
- + * 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 net.sf.l2j.gameserver.taskmanager;
- +
- +import java.util.Map;
- +import java.util.concurrent.ConcurrentHashMap;
- +
- +import net.sf.l2j.commons.concurrent.ThreadPool;
- +
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +import net.sf.l2j.gameserver.network.clientpackets.Say2;
- +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
- +
- +public final class HeroTaskManager implements Runnable
- +{
- + private final Map<L2PcInstance, Long> _players = new ConcurrentHashMap<>();
- +
- + protected HeroTaskManager()
- + {
- + ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
- + }
- +
- + /**
- + * Adds {@link L2PcInstance} to the HeroTask.
- + * @param player : L2PcInstance to be added and checked.
- + */
- + public final void add(L2PcInstance player)
- + {
- + _players.put(player, System.currentTimeMillis());
- + }
- +
- + /**
- + * Removes {@link L2PcInstance} from the HeroTask.
- + * @param player : {@link L2PcInstance} to be removed.
- + */
- + public final void remove(L2PcInstance player)
- + {
- + _players.remove(player);
- + }
- +
- + @Override
- + public final void run()
- + {
- + // List is empty, skip.
- + if (_players.isEmpty())
- + return;
- +
- + // Loop all players.
- + for (Map.Entry<L2PcInstance, Long> entry : _players.entrySet())
- + {
- + // Get player.
- + final L2PcInstance player = entry.getKey();
- +
- + if (player.getMemos().getLong("heroTime") < System.currentTimeMillis())
- + {
- + player.setHero(false);
- + player.broadcastUserInfo();
- + player.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "System", "Dear player, your hero period is over."));
- + player.getMemos().set("heroTime", 0);
- + remove(player);
- + }
- + }
- + }
- +
- + public static final HeroTaskManager getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final HeroTaskManager _instance = new HeroTaskManager();
- + }
- +}
- \ No newline at end of file
- Index: java/net/sf/l2j/gameserver/handler/ItemHandler.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/ItemHandler.java (revision 590)
- +++ java/net/sf/l2j/gameserver/handler/ItemHandler.java (working copy)
- @@ -27,6 +27,7 @@
- import net.sf.l2j.gameserver.handler.itemhandlers.EnchantScrolls;
- import net.sf.l2j.gameserver.handler.itemhandlers.FishShots;
- import net.sf.l2j.gameserver.handler.itemhandlers.Harvester;
- +import net.sf.l2j.gameserver.handler.itemhandlers.HeroItem;
- import net.sf.l2j.gameserver.handler.itemhandlers.ItemSkills;
- import net.sf.l2j.gameserver.handler.itemhandlers.Keys;
- import net.sf.l2j.gameserver.handler.itemhandlers.Maps;
- @@ -66,6 +67,7 @@
- registerItemHandler(new EnchantScrolls());
- registerItemHandler(new FishShots());
- registerItemHandler(new Harvester());
- + registerItemHandler(new HeroItem());
- registerItemHandler(new ItemSkills());
- registerItemHandler(new Keys());
- registerItemHandler(new Maps());
- Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 590)
- +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
- @@ -241,6 +241,7 @@
- import net.sf.l2j.gameserver.skills.l2skills.L2SkillSummon;
- import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
- import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
- +import net.sf.l2j.gameserver.taskmanager.HeroTaskManager;
- import net.sf.l2j.gameserver.taskmanager.ItemsOnGroundTaskManager;
- import net.sf.l2j.gameserver.taskmanager.PvpFlagTaskManager;
- import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
- @@ -4267,6 +4268,7 @@
- PvpFlagTaskManager.getInstance().remove(this);
- GameTimeTaskManager.getInstance().remove(this);
- ShadowItemTaskManager.getInstance().remove(this);
- + HeroTaskManager.getInstance().remove(this);
- }
- /**
- @@ -8366,6 +8368,12 @@
- if (isCursedWeaponEquipped())
- CursedWeaponsManager.getInstance().getCursedWeapon(getCursedWeaponEquippedId()).cursedOnLogin();
- + if (getMemos().getLong("heroTime", 0) > 0)
- + {
- + setHero(true);
- + HeroTaskManager.getInstance().add(this);
- + }
- +
- // Add to the GameTimeTask to keep inform about activity time.
- GameTimeTaskManager.getInstance().add(this);
- Index: java/net/sf/l2j/gameserver/handler/itemhandlers/HeroItem.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/itemhandlers/HeroItem.java (nonexistent)
- +++ java/net/sf/l2j/gameserver/handler/itemhandlers/HeroItem.java (working copy)
- @@ -0,0 +1,61 @@
- +/*
- + * 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 net.sf.l2j.gameserver.handler.itemhandlers;
- +
- +import java.util.concurrent.TimeUnit;
- +
- +import net.sf.l2j.gameserver.handler.IItemHandler;
- +import net.sf.l2j.gameserver.model.actor.L2Playable;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
- +import net.sf.l2j.gameserver.network.clientpackets.Say2;
- +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
- +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
- +import net.sf.l2j.gameserver.taskmanager.HeroTaskManager;
- +
- +public class HeroItem implements IItemHandler
- +{
- + @Override
- + public void useItem(L2Playable playable, ItemInstance item, boolean forceUse)
- + {
- + if (!(playable instanceof L2PcInstance))
- + return;
- +
- + L2PcInstance activeChar = (L2PcInstance) playable;
- +
- + long remainingTime = activeChar.getMemos().getLong("heroTime", 0);
- + int days = 7;
- +
- + if (remainingTime > 0)
- + {
- + activeChar.getMemos().set("heroTime", remainingTime + TimeUnit.DAYS.toMillis(days));
- + activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "System", "Dear player, your hero status has been extended by " + days + " day(s)."));
- + }
- + else
- + {
- + activeChar.setHero(true);
- + if (activeChar.getInventory().getItemByItemId(6842) == null)
- + activeChar.addItem("circlet", 6842, 1, activeChar, true);
- +
- + activeChar.getMemos().set("heroTime", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(days));
- + activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "System", "Dear player, you are now a hero, congratulations."));
- + activeChar.broadcastUserInfo();
- + }
- +
- + activeChar.destroyItem("Consume", item.getObjectId(), 1, null, true);
- + activeChar.broadcastPacket(new SocialAction(activeChar, 16));
- + HeroTaskManager.getInstance().add(activeChar);
- + }
- +}
- \ No newline at end of file
- #P aCis_datapack
- Index: data/xml/items/9200-9299.xml
- ===================================================================
- --- data/xml/items/9200-9299.xml (revision 590)
- +++ data/xml/items/9200-9299.xml (working copy)
- @@ -102,4 +102,12 @@
- <set name="is_dropable" val="false" />
- <set name="is_sellable" val="false" />
- </item>
- + <item id="9209" type="EtcItem" name="Hero Item">
- + <set name="material" val="PAPER" />
- + <set name="is_tradable" val="true" />
- + <set name="is_dropable" val="false" />
- + <set name="is_sellable" val="false" />
- + <set name="is_depositable" val="false" />
- + <set name="handler" val="HeroItem" />
- + </item>
- </list>
- \ No newline at end of file
Add Comment
Please, Sign In to add comment