|
@@ -12,12 +12,6 @@
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
- * @author FBIagent
|
|
|
- *
|
|
|
- */
|
|
|
package handlers.itemhandlers;
|
|
|
|
|
|
import java.util.logging.Level;
|
|
@@ -42,8 +36,10 @@ import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
|
|
|
import com.l2jserver.gameserver.network.serverpackets.PetItemList;
|
|
|
import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
|
|
|
import com.l2jserver.gameserver.util.Broadcast;
|
|
|
+
|
|
|
/**
|
|
|
* UnAfraid: TODO: Rewrite me :D
|
|
|
+ * @author FBIagent
|
|
|
*/
|
|
|
public class SummonItems implements IItemHandler
|
|
|
{
|
|
@@ -57,12 +53,15 @@ public class SummonItems implements IItemHandler
|
|
|
}
|
|
|
|
|
|
if (!TvTEvent.onItemSummon(playable.getObjectId()))
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
- final L2PcInstance activeChar = (L2PcInstance) playable;
|
|
|
-
|
|
|
+ final L2PcInstance activeChar = playable.getActingPlayer();
|
|
|
if (!activeChar.getFloodProtectors().getItemPetSummon().tryPerformAction("summon items"))
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
if (activeChar.isSitting())
|
|
|
{
|
|
@@ -71,22 +70,28 @@ public class SummonItems implements IItemHandler
|
|
|
}
|
|
|
|
|
|
if (activeChar.getBlockCheckerArena() != -1)
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
if (activeChar.inObserverMode())
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
if (activeChar.isInOlympiadMode())
|
|
|
{
|
|
|
activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
if (activeChar.isAllSkillsDisabled() || activeChar.isCastingNow())
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
final L2SummonItem sitem = SummonItemsData.getInstance().getSummonItem(item.getItemId());
|
|
|
-
|
|
|
- if ((activeChar.getPet() != null || activeChar.isMounted()) && sitem.isPetSummon())
|
|
|
+ if ((activeChar.hasSummon() || activeChar.isMounted()) && sitem.isPetSummon())
|
|
|
{
|
|
|
activeChar.sendPacket(SystemMessageId.YOU_ALREADY_HAVE_A_PET);
|
|
|
return false;
|
|
@@ -100,11 +105,15 @@ public class SummonItems implements IItemHandler
|
|
|
|
|
|
final int npcId = sitem.getNpcId();
|
|
|
if (npcId == 0)
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
final L2NpcTemplate npcTemplate = NpcTable.getInstance().getTemplate(npcId);
|
|
|
if (npcTemplate == null)
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
activeChar.stopMove(null, false);
|
|
|
|
|
@@ -126,7 +135,9 @@ public class SummonItems implements IItemHandler
|
|
|
npc.setTitle(activeChar.getName());
|
|
|
npc.setIsRunning(false); // broadcast info
|
|
|
if (sitem.getDespawnDelay() > 0)
|
|
|
+ {
|
|
|
npc.scheduleDespawn(sitem.getDespawnDelay() * 1000L);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
@@ -155,7 +166,7 @@ public class SummonItems implements IItemHandler
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- static class PetSummonFeedWait implements Runnable
|
|
|
+ private static class PetSummonFeedWait implements Runnable
|
|
|
{
|
|
|
private final L2PcInstance _activeChar;
|
|
|
private final L2PetInstance _petSummon;
|
|
@@ -172,9 +183,13 @@ public class SummonItems implements IItemHandler
|
|
|
try
|
|
|
{
|
|
|
if (_petSummon.getCurrentFed() <= 0)
|
|
|
+ {
|
|
|
_petSummon.unSummon(_activeChar);
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
_petSummon.startFeed();
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -184,13 +199,13 @@ public class SummonItems implements IItemHandler
|
|
|
}
|
|
|
|
|
|
// TODO: this should be inside skill handler
|
|
|
- static class PetSummonFinalizer implements Runnable
|
|
|
+ private static class PetSummonFinalizer implements Runnable
|
|
|
{
|
|
|
private final L2PcInstance _activeChar;
|
|
|
private final L2ItemInstance _item;
|
|
|
private final L2NpcTemplate _npcTemplate;
|
|
|
|
|
|
- PetSummonFinalizer(L2PcInstance activeChar, L2NpcTemplate npcTemplate, L2ItemInstance item)
|
|
|
+ protected PetSummonFinalizer(L2PcInstance activeChar, L2NpcTemplate npcTemplate, L2ItemInstance item)
|
|
|
{
|
|
|
_activeChar = activeChar;
|
|
|
_npcTemplate = npcTemplate;
|
|
@@ -206,46 +221,55 @@ public class SummonItems implements IItemHandler
|
|
|
_activeChar.setIsCastingNow(false);
|
|
|
|
|
|
// check for summon item validity
|
|
|
- if (_item == null || _item.getOwnerId() != _activeChar.getObjectId() || _item.getLocation() != L2ItemInstance.ItemLocation.INVENTORY)
|
|
|
+ if ((_item == null) || (_item.getOwnerId() != _activeChar.getObjectId()) || (_item.getLocation() != L2ItemInstance.ItemLocation.INVENTORY))
|
|
|
+ {
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
- final L2PetInstance petSummon = L2PetInstance.spawnPet(_npcTemplate, _activeChar, _item);
|
|
|
- if (petSummon == null)
|
|
|
+ final L2PetInstance pet = L2PetInstance.spawnPet(_npcTemplate, _activeChar, _item);
|
|
|
+ if (pet == null)
|
|
|
+ {
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
- petSummon.setShowSummonAnimation(true);
|
|
|
- petSummon.setTitle(_activeChar.getName());
|
|
|
+ pet.setShowSummonAnimation(true);
|
|
|
+ pet.setTitle(_activeChar.getName());
|
|
|
|
|
|
- if (!petSummon.isRespawned())
|
|
|
+ if (!pet.isRespawned())
|
|
|
{
|
|
|
- petSummon.setCurrentHp(petSummon.getMaxHp());
|
|
|
- petSummon.setCurrentMp(petSummon.getMaxMp());
|
|
|
- petSummon.getStat().setExp(petSummon.getExpForThisLevel());
|
|
|
- petSummon.setCurrentFed(petSummon.getMaxFed());
|
|
|
+ pet.setCurrentHp(pet.getMaxHp());
|
|
|
+ pet.setCurrentMp(pet.getMaxMp());
|
|
|
+ pet.getStat().setExp(pet.getExpForThisLevel());
|
|
|
+ pet.setCurrentFed(pet.getMaxFed());
|
|
|
}
|
|
|
|
|
|
- petSummon.setRunning();
|
|
|
+ pet.setRunning();
|
|
|
|
|
|
- if (!petSummon.isRespawned())
|
|
|
- petSummon.store();
|
|
|
+ if (!pet.isRespawned())
|
|
|
+ {
|
|
|
+ pet.store();
|
|
|
+ }
|
|
|
|
|
|
- _activeChar.setPet(petSummon);
|
|
|
+ _activeChar.setPet(pet);
|
|
|
|
|
|
// JIV remove - done on spawn
|
|
|
- // L2World.getInstance().storeObject(petSummon);
|
|
|
- petSummon.spawnMe(_activeChar.getX() + 50, _activeChar.getY() + 100, _activeChar.getZ());
|
|
|
- petSummon.startFeed();
|
|
|
- _item.setEnchantLevel(petSummon.getLevel());
|
|
|
+ pet.spawnMe(_activeChar.getX() + 50, _activeChar.getY() + 100, _activeChar.getZ());
|
|
|
+ pet.startFeed();
|
|
|
+ _item.setEnchantLevel(pet.getLevel());
|
|
|
|
|
|
- if (petSummon.getCurrentFed() <= 0)
|
|
|
- ThreadPoolManager.getInstance().scheduleGeneral(new PetSummonFeedWait(_activeChar, petSummon), 60000);
|
|
|
+ if (pet.getCurrentFed() <= 0)
|
|
|
+ {
|
|
|
+ ThreadPoolManager.getInstance().scheduleGeneral(new PetSummonFeedWait(_activeChar, pet), 60000);
|
|
|
+ }
|
|
|
else
|
|
|
- petSummon.startFeed();
|
|
|
+ {
|
|
|
+ pet.startFeed();
|
|
|
+ }
|
|
|
|
|
|
- petSummon.setFollowStatus(true);
|
|
|
+ pet.setFollowStatus(true);
|
|
|
|
|
|
- petSummon.sendPacket(new PetItemList(petSummon));
|
|
|
- petSummon.broadcastStatusUpdate();
|
|
|
+ pet.sendPacket(new PetItemList(pet.getInventory().getItems()));
|
|
|
+ pet.broadcastStatusUpdate();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|