Four Sepulchers rework.

Thanks to Stayway and gigilo1968.
This commit is contained in:
MobiusDev
2016-08-07 16:38:58 +00:00
parent df9d1379fd
commit 49d0d680a0
85 changed files with 1700 additions and 4845 deletions

View File

@@ -117,7 +117,6 @@ import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FortManager;
import com.l2jmobius.gameserver.instancemanager.FortSiegeManager;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
import com.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
import com.l2jmobius.gameserver.instancemanager.GraciaSeedsManager;
import com.l2jmobius.gameserver.instancemanager.GrandBossManager;
@@ -349,7 +348,6 @@ public class GameServer
SpawnTable.getInstance().load();
SpawnsData.getInstance().init();
FourSepulchersManager.getInstance().init();
DBSpawnManager.getInstance();
printSection("Event Engine");

View File

@@ -54,9 +54,6 @@ public enum InstanceType
FriendlyNpcInstance(L2Attackable),
// FlyMobs
L2FlyTerrainObjectInstance(L2Npc),
// Sepulchers
L2SepulcherNpcInstance(L2NpcInstance),
L2SepulcherMonsterInstance(L2MonsterInstance),
// Vehicles
L2Vehicle(L2Character),
L2BoatInstance(L2Vehicle),

View File

@@ -1,95 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager.tasks;
import java.util.Calendar;
import java.util.concurrent.ScheduledFuture;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
/**
* Four Sepulchers change attack time task.
* @author xban1x
*/
public final class FourSepulchersChangeAttackTimeTask implements Runnable
{
@Override
public void run()
{
final FourSepulchersManager manager = FourSepulchersManager.getInstance();
manager.setIsEntryTime(false);
manager.setIsWarmUpTime(false);
manager.setIsAttackTime(true);
manager.setIsCoolDownTime(false);
manager.locationShadowSpawns();
manager.spawnMysteriousBox(31921);
manager.spawnMysteriousBox(31922);
manager.spawnMysteriousBox(31923);
manager.spawnMysteriousBox(31924);
if (!manager.isFirstTimeRun())
{
manager.setWarmUpTimeEnd(Calendar.getInstance().getTimeInMillis());
}
long interval = 0;
// say task
if (manager.isFirstTimeRun())
{
for (double min = Calendar.getInstance().get(Calendar.MINUTE); min < manager.getCycleMin(); min++)
{
// looking for next shout time....
if ((min % 5) == 0)// check if min can be divided by 5
{
final Calendar inter = Calendar.getInstance();
inter.set(Calendar.MINUTE, (int) min);
ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersManagerSayTask(), inter.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
break;
}
}
}
else
{
ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersManagerSayTask(), 5 * 60400);
}
// searching time when attack time will be ended:
// counting difference between time when attack time ends and
// current time
// and then launching change time task
if (manager.isFirstTimeRun())
{
interval = manager.getAttackTimeEnd() - Calendar.getInstance().getTimeInMillis();
}
else
{
interval = Config.FS_TIME_ATTACK * 60000L;
}
manager.setChangeCoolDownTimeTask(ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeCoolDownTimeTask(), interval));
final ScheduledFuture<?> changeAttackTimeTask = manager.getChangeAttackTimeTask();
if (changeAttackTimeTask != null)
{
changeAttackTimeTask.cancel(true);
manager.setChangeAttackTimeTask(null);
}
}
}

View File

@@ -1,66 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager.tasks;
import java.util.Calendar;
import java.util.concurrent.ScheduledFuture;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
/**
* Four Sepulchers change cool down time task.
* @author xban1x
*/
public final class FourSepulchersChangeCoolDownTimeTask implements Runnable
{
@Override
public void run()
{
final FourSepulchersManager manager = FourSepulchersManager.getInstance();
manager.setIsEntryTime(false);
manager.setIsWarmUpTime(false);
manager.setIsAttackTime(false);
manager.setIsCoolDownTime(true);
manager.clean();
final Calendar time = Calendar.getInstance();
// one hour = 55th min to 55 min of next hour, so we check for this,
// also check for first launch
if (!manager.isFirstTimeRun() && (Calendar.getInstance().get(Calendar.MINUTE) > manager.getCycleMin()))
{
time.set(Calendar.HOUR, Calendar.getInstance().get(Calendar.HOUR) + 1);
}
time.set(Calendar.MINUTE, manager.getCycleMin());
if (manager.isFirstTimeRun())
{
manager.setIsFirstTimeRun(false);
}
final long interval = time.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
manager.setChangeEntryTimeTask(ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeEntryTimeTask(), interval));
final ScheduledFuture<?> changeCoolDownTimeTask = manager.getChangeCoolDownTimeTask();
if (changeCoolDownTimeTask != null)
{
changeCoolDownTimeTask.cancel(true);
manager.setChangeCoolDownTimeTask(null);
}
}
}

View File

@@ -1,68 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager.tasks;
import java.util.Calendar;
import java.util.concurrent.ScheduledFuture;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
/**
* Four Sepulchers change entry time task.
* @author xban1x
*/
public final class FourSepulchersChangeEntryTimeTask implements Runnable
{
@Override
public void run()
{
final FourSepulchersManager manager = FourSepulchersManager.getInstance();
manager.setIsEntryTime(true);
manager.setIsWarmUpTime(false);
manager.setIsAttackTime(false);
manager.setIsCoolDownTime(false);
long interval = 0;
// if this is first launch - search time whFourSepulchersManager_inEntryTime = true;naFourSepulchersManager_inEntryTime = true;maen entry time will be
// ended:
// counting difference between time when entry time ends and current
// time
// and then launching change time task
if (manager.isFirstTimeRun())
{
interval = manager.getEntrytTimeEnd() - Calendar.getInstance().getTimeInMillis();
}
else
{
interval = Config.FS_TIME_ENTRY * 60000L; // else use stupid
// method
}
// launching saying process...
ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersManagerSayTask(), 0);
manager.setChangeWarmUpTimeTask(ThreadPoolManager.getInstance().scheduleEffect(new FourSepulchersChangeWarmUpTimeTask(), interval));
final ScheduledFuture<?> changeEntryTimeTask = manager.getChangeEntryTimeTask();
if (changeEntryTimeTask != null)
{
changeEntryTimeTask.cancel(true);
manager.setChangeEntryTimeTask(null);
}
}
}

View File

@@ -1,64 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager.tasks;
import java.util.Calendar;
import java.util.concurrent.ScheduledFuture;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
/**
* Four Sepulchers change warm up time task.
* @author xban1x
*/
public final class FourSepulchersChangeWarmUpTimeTask implements Runnable
{
@Override
public void run()
{
final FourSepulchersManager manager = FourSepulchersManager.getInstance();
manager.setIsEntryTime(true);
manager.setIsWarmUpTime(false);
manager.setIsAttackTime(false);
manager.setIsCoolDownTime(false);
long interval = 0;
// searching time when warmup time will be ended:
// counting difference between time when warmup time ends and
// current time
// and then launching change time task
if (manager.isFirstTimeRun())
{
interval = manager.getWarmUpTimeEnd() - Calendar.getInstance().getTimeInMillis();
}
else
{
interval = Config.FS_TIME_WARMUP * 60000L;
}
manager.setChangeAttackTimeTask(ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeAttackTimeTask(), interval));
final ScheduledFuture<?> changeWarmUpTimeTask = manager.getChangeWarmUpTimeTask();
if (changeWarmUpTimeTask != null)
{
changeWarmUpTimeTask.cancel(true);
manager.setChangeWarmUpTimeTask(null);
}
}
}

View File

@@ -1,59 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager.tasks;
import java.util.Calendar;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
/**
* Four Sepulchers manager say task.
* @author xban1x
*/
public final class FourSepulchersManagerSayTask implements Runnable
{
@Override
public void run()
{
if (FourSepulchersManager.getInstance().isAttackTime())
{
final Calendar tmp = Calendar.getInstance();
tmp.setTimeInMillis(Calendar.getInstance().getTimeInMillis() - FourSepulchersManager.getInstance().getWarmUpTimeEnd());
if ((tmp.get(Calendar.MINUTE) + 5) < Config.FS_TIME_ATTACK)
{
FourSepulchersManager.getInstance().managerSay((byte) tmp.get(Calendar.MINUTE)); // byte
// because
// minute
// cannot be
// more than
// 59
ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersManagerSayTask(), 5 * 60000);
}
// attack time ending chat
else if ((tmp.get(Calendar.MINUTE) + 5) >= Config.FS_TIME_ATTACK)
{
FourSepulchersManager.getInstance().managerSay((byte) 90); // sending a unique id :D
}
}
else if (FourSepulchersManager.getInstance().isEntryTime())
{
FourSepulchersManager.getInstance().managerSay((byte) 0);
}
}
}

View File

@@ -1,522 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.model.actor.instance;
import java.util.concurrent.Future;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.enums.ChatType;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
import com.l2jmobius.gameserver.model.holders.SkillHolder;
import com.l2jmobius.gameserver.model.quest.QuestState;
/**
* @author sandman
*/
public class L2SepulcherMonsterInstance extends L2MonsterInstance
{
protected static final SkillHolder FAKE_PETRIFICATION = new SkillHolder(4616, 1);
public int mysteriousBoxId = 0;
protected Future<?> _victimSpawnKeyBoxTask = null;
protected Future<?> _victimShout = null;
protected Future<?> _changeImmortalTask = null;
protected Future<?> _onDeadEventTask = null;
public L2SepulcherMonsterInstance(L2NpcTemplate template)
{
super(template);
setInstanceType(InstanceType.L2SepulcherMonsterInstance);
setShowSummonAnimation(true);
switch (template.getId())
{
case 25339:
case 25342:
case 25346:
case 25349:
setIsRaid(true);
}
}
@Override
public void onSpawn()
{
setShowSummonAnimation(false);
switch (getId())
{
case 18150:
case 18151:
case 18152:
case 18153:
case 18154:
case 18155:
case 18156:
case 18157:
if (_victimSpawnKeyBoxTask != null)
{
_victimSpawnKeyBoxTask.cancel(true);
}
_victimSpawnKeyBoxTask = ThreadPoolManager.getInstance().scheduleEffect(new VictimSpawnKeyBox(this), 300000);
if (_victimShout != null)
{
_victimShout.cancel(true);
}
_victimShout = ThreadPoolManager.getInstance().scheduleEffect(new VictimShout(this), 5000);
break;
case 18196:
case 18197:
case 18198:
case 18199:
case 18200:
case 18201:
case 18202:
case 18203:
case 18204:
case 18205:
case 18206:
case 18207:
case 18208:
case 18209:
case 18210:
case 18211:
break;
case 18231:
case 18232:
case 18233:
case 18234:
case 18235:
case 18236:
case 18237:
case 18238:
case 18239:
case 18240:
case 18241:
case 18242:
case 18243:
if (_changeImmortalTask != null)
{
_changeImmortalTask.cancel(true);
}
_changeImmortalTask = ThreadPoolManager.getInstance().scheduleEffect(new ChangeImmortal(this), 1600);
break;
case 18256:
break;
case 25339:
case 25342:
case 25346:
case 25349:
setIsRaid(true);
break;
}
super.onSpawn();
}
@Override
public boolean doDie(L2Character killer)
{
if (!super.doDie(killer))
{
return false;
}
switch (getId())
{
case 18120:
case 18121:
case 18122:
case 18123:
case 18124:
case 18125:
case 18126:
case 18127:
case 18128:
case 18129:
case 18130:
case 18131:
case 18149:
case 18158:
case 18159:
case 18160:
case 18161:
case 18162:
case 18163:
case 18164:
case 18165:
case 18183:
case 18184:
case 18212:
case 18213:
case 18214:
case 18215:
case 18216:
case 18217:
case 18218:
case 18219:
if (_onDeadEventTask != null)
{
_onDeadEventTask.cancel(true);
}
_onDeadEventTask = ThreadPoolManager.getInstance().scheduleEffect(new OnDeadEvent(this), 3500);
break;
case 18150:
case 18151:
case 18152:
case 18153:
case 18154:
case 18155:
case 18156:
case 18157:
if (_victimSpawnKeyBoxTask != null)
{
_victimSpawnKeyBoxTask.cancel(true);
_victimSpawnKeyBoxTask = null;
}
if (_victimShout != null)
{
_victimShout.cancel(true);
_victimShout = null;
}
if (_onDeadEventTask != null)
{
_onDeadEventTask.cancel(true);
}
_onDeadEventTask = ThreadPoolManager.getInstance().scheduleEffect(new OnDeadEvent(this), 3500);
break;
case 18141:
case 18142:
case 18143:
case 18144:
case 18145:
case 18146:
case 18147:
case 18148:
if (FourSepulchersManager.getInstance().isViscountMobsAnnihilated(mysteriousBoxId))
{
if (_onDeadEventTask != null)
{
_onDeadEventTask.cancel(true);
}
_onDeadEventTask = ThreadPoolManager.getInstance().scheduleEffect(new OnDeadEvent(this), 3500);
}
break;
case 18220:
case 18221:
case 18222:
case 18223:
case 18224:
case 18225:
case 18226:
case 18227:
case 18228:
case 18229:
case 18230:
case 18231:
case 18232:
case 18233:
case 18234:
case 18235:
case 18236:
case 18237:
case 18238:
case 18239:
case 18240:
if (FourSepulchersManager.getInstance().isDukeMobsAnnihilated(mysteriousBoxId))
{
if (_onDeadEventTask != null)
{
_onDeadEventTask.cancel(true);
}
_onDeadEventTask = ThreadPoolManager.getInstance().scheduleEffect(new OnDeadEvent(this), 3500);
}
break;
case 25339:
case 25342:
case 25346:
case 25349:
giveCup(killer);
if (_onDeadEventTask != null)
{
_onDeadEventTask.cancel(true);
}
_onDeadEventTask = ThreadPoolManager.getInstance().scheduleEffect(new OnDeadEvent(this), 8500);
break;
}
return true;
}
@Override
public boolean deleteMe()
{
if (_victimSpawnKeyBoxTask != null)
{
_victimSpawnKeyBoxTask.cancel(true);
_victimSpawnKeyBoxTask = null;
}
if (_onDeadEventTask != null)
{
_onDeadEventTask.cancel(true);
_onDeadEventTask = null;
}
return super.deleteMe();
}
private void giveCup(L2Character killer)
{
final String questId = "620_FourGoblets";
int cupId = 0;
final int oldBrooch = 7262;
switch (getId())
{
case 25339:
cupId = 7256;
break;
case 25342:
cupId = 7257;
break;
case 25346:
cupId = 7258;
break;
case 25349:
cupId = 7259;
break;
}
final L2PcInstance player = killer.getActingPlayer();
if (player == null)
{
return;
}
if (player.getParty() != null)
{
for (L2PcInstance mem : player.getParty().getMembers())
{
final QuestState qs = mem.getQuestState(questId);
if ((qs != null) && (qs.isStarted() || qs.isCompleted()) && (mem.getInventory().getItemByItemId(oldBrooch) == null))
{
mem.addItem("Quest", cupId, 1, mem, true);
}
}
}
else
{
final QuestState qs = player.getQuestState(questId);
if ((qs != null) && (qs.isStarted() || qs.isCompleted()) && (player.getInventory().getItemByItemId(oldBrooch) == null))
{
player.addItem("Quest", cupId, 1, player, true);
}
}
}
private class VictimShout implements Runnable
{
private final L2SepulcherMonsterInstance _activeChar;
public VictimShout(L2SepulcherMonsterInstance activeChar)
{
_activeChar = activeChar;
}
@Override
public void run()
{
if (_activeChar.isDead())
{
return;
}
if (!_activeChar.isSpawned())
{
return;
}
broadcastSay(ChatType.NPC_GENERAL, "forgive me!!");
}
}
private class VictimSpawnKeyBox implements Runnable
{
private final L2SepulcherMonsterInstance _activeChar;
public VictimSpawnKeyBox(L2SepulcherMonsterInstance activeChar)
{
_activeChar = activeChar;
}
@Override
public void run()
{
if (_activeChar.isDead())
{
return;
}
if (!_activeChar.isSpawned())
{
return;
}
FourSepulchersManager.getInstance().spawnKeyBox(_activeChar);
broadcastSay(ChatType.NPC_GENERAL, "Many thanks for rescue me.");
if (_victimShout != null)
{
_victimShout.cancel(true);
}
}
}
private static class OnDeadEvent implements Runnable
{
L2SepulcherMonsterInstance _activeChar;
public OnDeadEvent(L2SepulcherMonsterInstance activeChar)
{
_activeChar = activeChar;
}
@Override
public void run()
{
switch (_activeChar.getId())
{
case 18120:
case 18121:
case 18122:
case 18123:
case 18124:
case 18125:
case 18126:
case 18127:
case 18128:
case 18129:
case 18130:
case 18131:
case 18149:
case 18158:
case 18159:
case 18160:
case 18161:
case 18162:
case 18163:
case 18164:
case 18165:
case 18183:
case 18184:
case 18212:
case 18213:
case 18214:
case 18215:
case 18216:
case 18217:
case 18218:
case 18219:
FourSepulchersManager.getInstance().spawnKeyBox(_activeChar);
break;
case 18150:
case 18151:
case 18152:
case 18153:
case 18154:
case 18155:
case 18156:
case 18157:
FourSepulchersManager.getInstance().spawnExecutionerOfHalisha(_activeChar);
break;
case 18141:
case 18142:
case 18143:
case 18144:
case 18145:
case 18146:
case 18147:
case 18148:
FourSepulchersManager.getInstance().spawnMonster(_activeChar.mysteriousBoxId);
break;
case 18220:
case 18221:
case 18222:
case 18223:
case 18224:
case 18225:
case 18226:
case 18227:
case 18228:
case 18229:
case 18230:
case 18231:
case 18232:
case 18233:
case 18234:
case 18235:
case 18236:
case 18237:
case 18238:
case 18239:
case 18240:
FourSepulchersManager.getInstance().spawnArchonOfHalisha(_activeChar.mysteriousBoxId);
break;
case 25339:
case 25342:
case 25346:
case 25349:
FourSepulchersManager.getInstance().spawnEmperorsGraveNpc(_activeChar.mysteriousBoxId);
break;
}
}
}
private static class ChangeImmortal implements Runnable
{
L2SepulcherMonsterInstance activeChar;
public ChangeImmortal(L2SepulcherMonsterInstance mob)
{
activeChar = mob;
}
@Override
public void run()
{
// Invulnerable by petrification
FAKE_PETRIFICATION.getSkill().applyEffects(activeChar, activeChar);
}
}
@Override
public boolean isAutoAttackable(L2Character attacker)
{
return true;
}
}

View File

@@ -1,451 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.model.actor.instance;
import java.util.concurrent.Future;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.Rnd;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.ai.CtrlIntention;
import com.l2jmobius.gameserver.data.xml.impl.DoorData;
import com.l2jmobius.gameserver.enums.ChatType;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.instancemanager.FourSepulchersManager;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.L2Npc;
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
import com.l2jmobius.gameserver.model.events.EventDispatcher;
import com.l2jmobius.gameserver.model.events.EventType;
import com.l2jmobius.gameserver.model.events.impl.character.npc.OnNpcFirstTalk;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.NpcStringId;
import com.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import com.l2jmobius.gameserver.network.serverpackets.CreatureSay;
import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jmobius.gameserver.network.serverpackets.SocialAction;
import com.l2jmobius.gameserver.util.Util;
/**
* @author sandman
*/
public class L2SepulcherNpcInstance extends L2Npc
{
protected Future<?> _closeTask = null;
protected Future<?> _spawnNextMysteriousBoxTask = null;
protected Future<?> _spawnMonsterTask = null;
private static final String HTML_FILE_PATH = "data/html/SepulcherNpc/";
private static final int HALLS_KEY = 7260;
public L2SepulcherNpcInstance(L2NpcTemplate template)
{
super(template);
setInstanceType(InstanceType.L2SepulcherNpcInstance);
setShowSummonAnimation(true);
if (_closeTask != null)
{
_closeTask.cancel(true);
}
if (_spawnNextMysteriousBoxTask != null)
{
_spawnNextMysteriousBoxTask.cancel(true);
}
if (_spawnMonsterTask != null)
{
_spawnMonsterTask.cancel(true);
}
_closeTask = null;
_spawnNextMysteriousBoxTask = null;
_spawnMonsterTask = null;
}
@Override
public void onSpawn()
{
super.onSpawn();
setShowSummonAnimation(false);
}
@Override
public boolean deleteMe()
{
if (_closeTask != null)
{
_closeTask.cancel(true);
_closeTask = null;
}
if (_spawnNextMysteriousBoxTask != null)
{
_spawnNextMysteriousBoxTask.cancel(true);
_spawnNextMysteriousBoxTask = null;
}
if (_spawnMonsterTask != null)
{
_spawnMonsterTask.cancel(true);
_spawnMonsterTask = null;
}
return super.deleteMe();
}
@Override
public void onAction(L2PcInstance player, boolean interact)
{
if (!canTarget(player))
{
return;
}
// Check if the L2PcInstance already target the L2NpcInstance
if (this != player.getTarget())
{
if (Config.DEBUG)
{
_log.info("new target selected:" + getObjectId());
}
// Set the target of the L2PcInstance player
player.setTarget(this);
}
else if (interact)
{
// Check if the player is attackable (without a forced attack) and
// isn't dead
if (isAutoAttackable(player) && !isAlikeDead())
{
// Check the height difference
if (Math.abs(player.getZ() - getZ()) < 400) // this max heigth
// difference might
// need some tweaking
{
// Set the L2PcInstance Intention to AI_INTENTION_ATTACK
player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
}
else
{
// Send a Server->Client packet ActionFailed (target is out
// of attack range) to the L2PcInstance player
player.sendPacket(ActionFailed.STATIC_PACKET);
}
}
if (!isAutoAttackable(player))
{
// Calculate the distance between the L2PcInstance and the
// L2NpcInstance
if (!canInteract(player))
{
// Notify the L2PcInstance AI with AI_INTENTION_INTERACT
player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
}
else
{
// Send a Server->Client packet SocialAction to the all
// L2PcInstance on the _knownPlayer of the L2NpcInstance
// to display a social action of the L2NpcInstance on their
// client
final SocialAction sa = new SocialAction(getObjectId(), Rnd.get(8));
broadcastPacket(sa);
doAction(player);
}
}
// Send a Server->Client ActionFailed to the L2PcInstance in order
// to avoid that the client wait another packet
player.sendPacket(ActionFailed.STATIC_PACKET);
}
}
private void doAction(L2PcInstance player)
{
if (isDead())
{
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
switch (getId())
{
case 31468:
case 31469:
case 31470:
case 31471:
case 31472:
case 31473:
case 31474:
case 31475:
case 31476:
case 31477:
case 31478:
case 31479:
case 31480:
case 31481:
case 31482:
case 31483:
case 31484:
case 31485:
case 31486:
case 31487:
setIsInvul(false);
reduceCurrentHp(getMaxHp() + 1, player, null);
if (_spawnMonsterTask != null)
{
_spawnMonsterTask.cancel(true);
}
_spawnMonsterTask = ThreadPoolManager.getInstance().scheduleEffect(new SpawnMonster(getId()), 3500);
break;
case 31455:
case 31456:
case 31457:
case 31458:
case 31459:
case 31460:
case 31461:
case 31462:
case 31463:
case 31464:
case 31465:
case 31466:
case 31467:
setIsInvul(false);
reduceCurrentHp(getMaxHp() + 1, player, null);
if ((player.getParty() != null) && !player.getParty().isLeader(player))
{
player = player.getParty().getLeader();
}
player.addItem("Quest", HALLS_KEY, 1, player, true);
break;
default:
{
if (hasListener(EventType.ON_NPC_QUEST_START))
{
player.setLastQuestNpcObject(getObjectId());
}
if (hasListener(EventType.ON_NPC_FIRST_TALK))
{
EventDispatcher.getInstance().notifyEventAsync(new OnNpcFirstTalk(this, player), this);
}
else
{
showChatWindow(player, 0);
}
}
}
player.sendPacket(ActionFailed.STATIC_PACKET);
}
@Override
public String getHtmlPath(int npcId, int val)
{
String pom = "";
if (val == 0)
{
pom = "" + npcId;
}
else
{
pom = npcId + "-" + val;
}
return HTML_FILE_PATH + pom + ".htm";
}
@Override
public void showChatWindow(L2PcInstance player, int val)
{
final String filename = getHtmlPath(getId(), val);
final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
html.setFile(player.getHtmlPrefix(), filename);
html.replace("%objectId%", String.valueOf(getObjectId()));
player.sendPacket(html);
player.sendPacket(ActionFailed.STATIC_PACKET);
}
@Override
public void onBypassFeedback(L2PcInstance player, String command)
{
if (isBusy())
{
final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
html.setFile(player.getHtmlPrefix(), "data/html/npcbusy.htm");
html.replace("%busymessage%", ""); // busy message was never used.
html.replace("%npcname%", getName());
html.replace("%playername%", player.getName());
player.sendPacket(html);
}
else if (command.startsWith("Chat"))
{
int val = 0;
try
{
val = Integer.parseInt(command.substring(5));
}
catch (IndexOutOfBoundsException ioobe)
{
}
catch (NumberFormatException nfe)
{
}
showChatWindow(player, val);
}
else if (command.startsWith("open_gate"))
{
final L2ItemInstance hallsKey = player.getInventory().getItemByItemId(HALLS_KEY);
if (hallsKey == null)
{
showHtmlFile(player, "Gatekeeper-no.htm");
}
else if (FourSepulchersManager.getInstance().isAttackTime())
{
switch (getId())
{
case 31929:
case 31934:
case 31939:
case 31944:
FourSepulchersManager.getInstance().spawnShadow(getId());
default:
{
openNextDoor(getId());
if (player.getParty() != null)
{
for (L2PcInstance mem : player.getParty().getMembers())
{
if ((mem != null) && (mem.getInventory().getItemByItemId(HALLS_KEY) != null))
{
mem.destroyItemByItemId("Quest", HALLS_KEY, mem.getInventory().getItemByItemId(HALLS_KEY).getCount(), mem, true);
}
}
}
else
{
player.destroyItemByItemId("Quest", HALLS_KEY, hallsKey.getCount(), player, true);
}
}
}
}
}
else
{
super.onBypassFeedback(player, command);
}
}
public void openNextDoor(int npcId)
{
final int doorId = FourSepulchersManager.getInstance().getHallGateKeepers().get(npcId);
final DoorData _doorTable = DoorData.getInstance();
_doorTable.getDoor(doorId).openMe();
if (_closeTask != null)
{
_closeTask.cancel(true);
}
_closeTask = ThreadPoolManager.getInstance().scheduleEffect(new CloseNextDoor(doorId), 10000);
if (_spawnNextMysteriousBoxTask != null)
{
_spawnNextMysteriousBoxTask.cancel(true);
}
_spawnNextMysteriousBoxTask = ThreadPoolManager.getInstance().scheduleEffect(new SpawnNextMysteriousBox(npcId), 0);
}
private static class CloseNextDoor implements Runnable
{
final DoorData _DoorTable = DoorData.getInstance();
private final int _DoorId;
public CloseNextDoor(int doorId)
{
_DoorId = doorId;
}
@Override
public void run()
{
try
{
_DoorTable.getDoor(_DoorId).closeMe();
}
catch (Exception e)
{
_log.warning(e.getMessage());
}
}
}
private static class SpawnNextMysteriousBox implements Runnable
{
private final int _NpcId;
public SpawnNextMysteriousBox(int npcId)
{
_NpcId = npcId;
}
@Override
public void run()
{
FourSepulchersManager.getInstance().spawnMysteriousBox(_NpcId);
}
}
private static class SpawnMonster implements Runnable
{
private final int _NpcId;
public SpawnMonster(int npcId)
{
_NpcId = npcId;
}
@Override
public void run()
{
FourSepulchersManager.getInstance().spawnMonster(_NpcId);
}
}
public void sayInShout(NpcStringId msg)
{
if (msg == null)
{
return; // wrong usage
}
final CreatureSay creatureSay = new CreatureSay(0, ChatType.NPC_SHOUT, getName(), msg);
for (L2PcInstance player : L2World.getInstance().getPlayers())
{
if (Util.checkIfInRange(15000, player, this, true))
{
player.sendPacket(creatureSay);
}
}
}
public void showHtmlFile(L2PcInstance player, String file)
{
final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
html.setFile(player.getHtmlPrefix(), "data/html/SepulcherNpc/" + file);
html.replace("%npcname%", getName());
player.sendPacket(html);
}
}