/*
* 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 instances.IceQueenCastle2;
import java.util.Calendar;
import java.util.concurrent.ScheduledFuture;
import ai.group_template.L2AttackableAIScript;
import net.l2emuproject.gameserver.ThreadPoolManager;
import net.l2emuproject.gameserver.ai.CtrlIntention;
import net.l2emuproject.gameserver.datatables.NpcTable;
import net.l2emuproject.gameserver.datatables.SkillTable;
import net.l2emuproject.gameserver.instancemanager.InstanceManager;
import net.l2emuproject.gameserver.instancemanager.ZoneManager;
import net.l2emuproject.gameserver.instancemanager.InstanceManager.InstanceWorld;
import net.l2emuproject.gameserver.model.L2Effect;
import net.l2emuproject.gameserver.model.L2Party;
import net.l2emuproject.gameserver.model.L2Skill;
import net.l2emuproject.gameserver.model.L2Spawn;
import net.l2emuproject.gameserver.model.actor.L2Character;
import net.l2emuproject.gameserver.model.actor.L2Npc;
import net.l2emuproject.gameserver.model.actor.instance.L2DoorInstance;
import net.l2emuproject.gameserver.model.actor.instance.L2MonsterInstance;
import net.l2emuproject.gameserver.model.actor.instance.L2PcInstance;
import net.l2emuproject.gameserver.model.entity.Instance;
import net.l2emuproject.gameserver.model.quest.QuestState;
import net.l2emuproject.gameserver.model.quest.State;
import net.l2emuproject.gameserver.model.zone.L2BossZone;
import net.l2emuproject.gameserver.model.zone.L2Zone;
import net.l2emuproject.gameserver.network.SystemMessageId;
import net.l2emuproject.gameserver.network.serverpackets.ExShowScreenMessage;
import net.l2emuproject.gameserver.network.serverpackets.SystemMessage;
import net.l2emuproject.gameserver.skills.Formulas;
import net.l2emuproject.gameserver.templates.chars.L2NpcTemplate;
import net.l2emuproject.geoserver.model.Location;
import net.l2emuproject.tools.random.Rnd;
/**
*
* @author Visor123
* L2Emu Enterprise Server
*
*/
public class IceQueenCastle2 extends L2AttackableAIScript
{
private static final boolean debug = false;
private static final int INSTANCEID = 139;
private static final String qn = "IceQueenCastle2";
private static final String qnPrev = "10286_ReunionWithSirra";
private static final int PLAYERS_MIN = 10;
private static final int PLAYERS_MAX = 27;
private static int _zoneScriptId = 200010; //script zone for start
private static int _zoneBossId = 12015;
private static L2BossZone _Zone;
private static final Location _enterLoc = new Location(114025, -112300, -11200);
private static final Location _centerLoc = new Location(114722, -114797, -11200);
private static final int[][] _iceKnightLoc = {{113845,-116091,-11168,8264}
,{113381,-115622,-11168,8264}
,{113380,-113978,-11168,-8224}
,{113845,-113518,-11168,-8224}
,{115591,-113516,-11168,-24504}
,{116053,-113981,-11168,-24504}
,{116061,-115611,-11168,24804}
,{115597,-116080,-11168,24804}
,{112942,-115480,-10960,52}
,{112940,-115146,-10960,52}
,{112945,-114453,-10960,52}
,{112945,-114123,-10960,52}
,{116497,-114117,-10960,32724}
,{116499,-114454,-10960,32724}
,{116501,-115145,-10960,32724}
,{116502,-115473,-10960,32724}};
private static final int _maxIceKnigth = 20; //OFF 160
private static final int[][] _iceKnightLocThrone = {{114713,-115109,-11202,16456}
,{114008,-115080,-11202,3568}
,{114422,-115508,-11202,12400}
,{115023,-115508,-11202,20016}
,{115459,-115079,-11202,27936}};
private static final int[] _maxIceKnigthThrone = {12,12,30};//first, second, third
private static final int[][] _iceIceBreathLoc = {{114713,-115109,-11202,16456}
,{114008,-115080,-11202,3568}
,{114422,-115508,-11202,12400}
,{115023,-115508,-11202,20016}
,{115459,-115079,-11202,27936}};
private static final int _maxIceBreath = 10;
private static final int _maxIceStone = 6;
private static final int FreyaOnThrone = 29177;
private static final int Freya = 29179;
private static final int[][] Freya_Skills = {{6274,1},{6275,1},{6276,1},{6277,1},{6278,1},{6279,1},{6280,1},{6282,1},{6283,1},{6284,1},{6285,1}};
private static final int Glacier = 18853;
private static final int Glakias = 25699;
private static final int ArcheryKnight = 18855;
private static final int ArchersBreath = 18854;
/*private static final int FreyaController = 18930;
private static final Location FreyaControllerLoc = new Location(114707,-114793,-11199,0);
private static final int IceElementalController = 18931;
private static final Location IceElementalControllerLoc = new Location(114707,-114795,-11199,0);
private static final int IceCastleController = 18932;
private static final Location IceCastleControllerLoc = new Location(114707,-114797,-11199,0);*/
private static final int[] _zoneSkill = {6437,7};
private static final int Kegor = 18851;
private static final int Jinia = 18850;
private static final int JINIA2 = 32781;
static class Timer implements Runnable
{
@Override
public void run()
{
if (time > 10)
{
world.BossZone.broadcastPacket(new ExShowScreenMessage("00 : "+time, 1500), world.instanceId); //need check
ThreadPoolManager.scheduleGeneral(new Timer(time - 1, world), 1000L);
}
}
private int time;
private FreyaWorld world;
public Timer(int _time, FreyaWorld _world)
{
time = _time;
world = _world;
}
}
private static class FreyaWorld extends InstanceWorld
{
L2AttackableAIScript _quest;
L2Npc Npc_Freya;
L2Npc Npc_Kegor;
L2Npc Npc_Jinia;
L2Npc Npc_Glakias;
L2BossZone BossZone;
int stage = 0;
ScheduledFuture<?> knigthController = null;
int countKnigth = 0;
ScheduledFuture<?> knigthThroneController = null;
int countKnigthThrone = 0;
ScheduledFuture<?> breathController = null;
ScheduledFuture<?> stoneController = null;
int countIceBreath = 0;
int countIceStone = 0;
ScheduledFuture<?> zoneSkillController = null;
ScheduledFuture<?> helpMoveController = null;
public FreyaWorld(Instance inst, L2AttackableAIScript quest)
{
super(inst);
_quest = quest;
}
@Override
public void decayMe()
{
stopHelpMoveController();
stopBreathController();
stopKnigthController();
stopKnigthThroneController();
stopStoneController();
stopZoneSkillController();
super.decayMe();
}
synchronized void decCountKnigth()
{ countKnigth --; }
synchronized void decCountKnigthThrone()
{ countKnigthThrone --; }
synchronized void decCountIceBreath()
{ countIceBreath --; }
synchronized void decCountIceStone()
{ countIceStone --; }
synchronized void incCountKnigth()
{ countKnigth ++; }
synchronized void incCountKnigthThrone()
{ countKnigthThrone ++; }
synchronized void incCountIceBreath()
{ countIceBreath ++; }
synchronized void incCountIceStone()
{ countIceStone ++; }
synchronized void startStoneController()
{
if (stoneController != null)
stoneController.cancel(false);
stoneController = ThreadPoolManager.scheduleGeneralAtFixedRate(new iceStoneController(_quest, this, 3), 1000L, 30000L);
}
synchronized void stopStoneController()
{
if (stoneController != null)
stoneController.cancel(false);
stoneController = null;
}
synchronized void startBreathController()
{
if (breathController != null)
breathController.cancel(false);
breathController = ThreadPoolManager.scheduleGeneralAtFixedRate(new breathController(_quest, this, 3), 1000L, 30000L);
}
synchronized void stopBreathController()
{
if (breathController != null)
breathController.cancel(false);
breathController = null;
}
synchronized void startZoneSkillController()
{
if (zoneSkillController != null)
zoneSkillController.cancel(false);
zoneSkillController = ThreadPoolManager.scheduleGeneralAtFixedRate(new zoneSkillController(_quest, this), 1000L, 10000L);
}
synchronized void stopZoneSkillController()
{
if (zoneSkillController != null)
zoneSkillController.cancel(false);
zoneSkillController = null;
for (L2PcInstance player : getPlayers())
{
L2Effect effects[] = player.getAllEffects();
for (int j = 0; j < effects.length; j++)
{
L2Effect e = effects[j];
if (e != null && e.getSkill().getId() == 6437)
e.exit();
}
}
}
synchronized void startKnigthController()
{
if (knigthController != null)
knigthController.cancel(false);
knigthController = ThreadPoolManager.scheduleGeneralAtFixedRate(new knigthController(_quest, this, 12), 1000L, 30000L);
}
synchronized void stopKnigthController()
{
if (knigthController != null)
knigthController.cancel(false);
knigthController = null;
}
synchronized void startKnigthThroneController()
{
if (knigthThroneController != null)
knigthThroneController.cancel(false);
knigthThroneController = ThreadPoolManager.scheduleGeneralAtFixedRate(new knigthThroneController(_quest, this, 5), 1000L, 30000L);
}
synchronized void stopKnigthThroneController()
{
if (knigthThroneController != null)
knigthThroneController.cancel(false);
knigthThroneController = null;
}
synchronized void startHelpMoveController()
{
if (helpMoveController != null)
helpMoveController.cancel(false);
helpMoveController = ThreadPoolManager.scheduleGeneralAtFixedRate(new helpMoveController(_quest, this), 10000L, 5000L);
}
synchronized void stopHelpMoveController()
{
if (helpMoveController != null)
helpMoveController.cancel(false);
helpMoveController = null;
}
}
private static boolean checkConditionsReEnter(L2PcInstance player)
{
if (player.getLevel() < 82)
{
SystemMessage sm = new SystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
sm.addPcName(player);
player.sendPacket(sm);
return false;
}
return true;
}
private static boolean checkConditions(L2PcInstance player)
{
if (debug)
return true;
//custom check
L2Party party = player.getParty();
if (party == null || !party.isInCommandChannel())
{
if (party != null)
party.broadcastToPartyMembers(new SystemMessage(SystemMessageId.NOT_IN_COMMAND_CHANNEL_CANT_ENTER));
else
player.sendPacket(SystemMessageId.NOT_IN_COMMAND_CHANNEL_CANT_ENTER);
return false;
}
if (party.getCommandChannel().getChannelLeader() != player)
{
party.getCommandChannel().broadcastToChannelMembers(new SystemMessage(2765));
return false;
}
int count = 0;
for (int id : InstanceManager.getInstance().getInstances().keySet())
{
InstanceWorld inst = InstanceManager.getInstance().getWorld(id);
if (inst != null && inst.templateId == INSTANCEID)
count++;
if (count >= 3)
{
party.getCommandChannel().broadcastToChannelMembers(new SystemMessage(2104));
return false;
}
}
if (party.getCommandChannel().getMembers().size() < PLAYERS_MIN)
{
party.getCommandChannel().broadcastToChannelMembers(new SystemMessage(2793).addNumber(10));
return false;
}
if (party.getCommandChannel().getMembers().size() > PLAYERS_MAX)
{
party.getCommandChannel().broadcastToChannelMembers(new SystemMessage(2764));
return false;
}
for (L2PcInstance plr : party.getCommandChannel().getMembers())
{
if (InstanceManager.getInstance().getPlayerWorld(plr) != null)
{
party.getCommandChannel().broadcastToChannelMembers(new SystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
return false;
}
if (plr.getLevel() < 82)
{
party.getCommandChannel().broadcastToChannelMembers(new SystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT).addPcName(plr));
return false;
}
if (!plr.isInsideRadius(player, 1000))
{
party.getCommandChannel().broadcastToChannelMembers(new SystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED).addPcName(plr));
return false;
}
Long reentertime = InstanceManager.getInstance().getInstanceTime(plr.getObjectId(), INSTANCEID);
boolean checkTime = true;
/*QuestState qs = player.getQuestState(qnPrev);
if (qs == null || !qs.isCompleted())
checkTime = false;*/
if (checkTime && System.currentTimeMillis() < reentertime)
{
SystemMessage sm = new SystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
sm.addPcName(plr);
party.broadcastToPartyMembers(sm);
return false;
}
}
return true;
}
private synchronized void enterInstance(L2Npc npc, L2PcInstance player)
{
//_log.info("enterInstance:" + player.getName());
InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
if (world != null)
{
if (!(world instanceof FreyaWorld))
player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
else if (checkConditionsReEnter(player))
world.teleportInto(player, _enterLoc);
}
else if (checkConditions(player))
{
int instanceId = InstanceManager.getInstance().createDynamicInstance("IceQueenCastle2.xml");
world = new FreyaWorld(InstanceManager.getInstance().getInstance(instanceId), this);
world.templateId = INSTANCEID;
Instance instance = InstanceManager.getInstance().getInstance(world.instanceId);
int returnLoc[] = { player.getX(), player.getY(), player.getZ() };
instance.setSpawnLoc(returnLoc);
instance.setName("IceQueenCastle2");
world.setStatus(0);
((FreyaWorld)world).BossZone = _Zone;
_log.info("Instance Ice Queen's Castle created with id= "+world.instanceId+" created player "+player.getName());
L2DoorInstance door = InstanceManager.getInstance().getInstance(world.instanceId).getDoor(23140101);
if (door != null)
door.openMe();
L2Party party = player.getParty();
if (party == null)
{
QuestState hostQuest = player.getQuestState(qnPrev);
if (hostQuest != null && hostQuest.getState() == State.STARTED && hostQuest.getInt("progress") == 2 && hostQuest.getInt("cond") == 5)
{
hostQuest.set("cond", "6");
hostQuest.playSound("ItemSound.quest_middle");
}
_Zone.allowPlayerEntry(player, 300);
instance.teleportInto(player, _enterLoc);
}
else
{
if (party.isInCommandChannel())
{
for (L2PcInstance partyMember : party.getCommandChannel().getMembers())
{
QuestState hostQuest = partyMember.getQuestState(qnPrev);
if (hostQuest != null && hostQuest.getState() == State.STARTED && hostQuest.getInt("progress") == 2 && hostQuest.getInt("cond") == 5)
{
hostQuest.set("cond", "6");
hostQuest.playSound("ItemSound.quest_middle");
}
_Zone.allowPlayerEntry(partyMember, 300);
instance.teleportInto(partyMember, _enterLoc);
}
}
else
{
for (L2PcInstance partyMember : party.getPartyMembers())
{
QuestState hostQuest = partyMember.getQuestState(qnPrev);
if (hostQuest != null && hostQuest.getState() == State.STARTED && hostQuest.getInt("progress") == 2 && hostQuest.getInt("cond") == 5)
{
hostQuest.set("cond", "6");
hostQuest.playSound("ItemSound.quest_middle");
}
_Zone.allowPlayerEntry(partyMember, 300);
instance.teleportInto(partyMember, _enterLoc);
}
}
}
}
}
private static L2Npc spawn(int npcId, int X, int Y, int Z, int head, FreyaWorld world)
{
try
{
L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
if (template != null)
{
L2Spawn spawn = new L2Spawn(template);
spawn.setHeading(head);
spawn.setLocx(X);
spawn.setLocy(Y);
spawn.setLocz(Z + 20);
spawn.setInstanceId(world.instanceId);
//spawn.setAmount(spawn.getAmount() + 1);
spawn.setAmount(1);
spawn.stopRespawn();
//spawn.setOnKillDelay(1500);
return spawn.doSpawn();
}
}
catch (Exception e1)
{
_log.info((new StringBuilder()).append("Freya: Could not spawn Npc ").append(npcId).toString());
}
return null;
}
public static void allowBossZone(FreyaWorld world)
{
for (L2PcInstance player : world.getPlayers())
{
world.BossZone.allowPlayerEntry(player, 300);
}
}
public static void startStage(FreyaWorld world)
{
//_log.info("startStage: " + world.stage);
if (InstanceManager.getInstance().getInstance(world.instanceId) == null) return;
final FreyaWorld Wworld = world;
if (world.stage == 1)
{
L2DoorInstance door = world.getSelfInstance().getDoor(23140101);
if (door != null)
door.closeMe();
allowBossZone(world);
world.BossZone.broadcastMovie(15, world.instanceId);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
public void run()
{
Wworld.Npc_Freya = spawn(FreyaOnThrone, 114720, -117068, -11078, 16384, Wworld);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
public void run()
{
Wworld.BossZone.broadcastPacket(new ExShowScreenMessage(1801086, 6000, 1, -1, true), Wworld.instanceId);
Wworld.startStoneController();
Wworld.startKnigthController();
Wworld.startKnigthThroneController();
Wworld.startZoneSkillController();
Wworld.startHelpMoveController();
}
}, 1000);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
public void run()
{
Wworld.startBreathController();
moveTo(Wworld.Npc_Freya, _centerLoc);
}
}, 5000);
}
}, 53500);
}
if (world.stage == 2)
{
allowBossZone(world);
world.BossZone.broadcastMovie(16, world.instanceId);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
public void run()
{
Wworld.Npc_Freya = spawn(FreyaOnThrone, 114719, -117450, -10673, 16384, Wworld);
Wworld.Npc_Freya.setIsOverloaded(true);
Wworld.Npc_Freya.setIsInvul(true);
ThreadPoolManager.scheduleGeneral(new IceQueenCastle2.Timer(60, Wworld), 100);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
public void run()
{
Wworld.BossZone.broadcastPacket(new ExShowScreenMessage(1801087, 6000, 1, -1, true), Wworld.instanceId);
Wworld.startStoneController();
Wworld.startBreathController();
Wworld.startKnigthController();
Wworld.startKnigthThroneController();
Wworld.startZoneSkillController();
Wworld.startHelpMoveController();
}
}, 60100);
}
}, 21100);
}
if (world.stage == 3)
{
allowBossZone(world);
world.BossZone.broadcastMovie(17, world.instanceId);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
public void run()
{
Wworld.setStatus(Wworld.status + 1);
if (Wworld.Npc_Freya != null)
Wworld.Npc_Freya.deleteMe();
Wworld.Npc_Freya = spawn(Freya, 114720, -117068, -11078, 16384, Wworld);
Wworld.BossZone.broadcastPacket(new ExShowScreenMessage(1801088, 6000, 1, -1, true), Wworld.instanceId);
Wworld.startStoneController();
Wworld.startBreathController();
Wworld.startKnigthController();
Wworld.startKnigthThroneController();
Wworld.startZoneSkillController();
Wworld.startHelpMoveController();
moveTo(Wworld.Npc_Freya, _centerLoc);
setInstanceReenterTime(Wworld);
}
}, 21600);
}
}
private void stopAll(FreyaWorld world)
{
world.stopHelpMoveController();
world.stopBreathController();
world.stopKnigthController();
world.stopKnigthThroneController();
world.stopStoneController();
world.stopZoneSkillController();
for (L2PcInstance player : world.getPlayers())
{
player.abortCast();
player.abortAttack();
player.getAI().stopAutoAttack();
player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
player.setIsImmobilized(true);
player.setIsInvul(true);
}
for (L2Npc npc : world.getNpcs())
{
if (npc instanceof L2MonsterInstance)
{
npc.setIsInvul(true);
npc.abortCast();
npc.abortAttack();
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
npc.setIsImmobilized(true);
}
}
if (world.Npc_Freya != null)
{
world.Npc_Freya.abortCast();
world.Npc_Freya.abortAttack();
world.Npc_Freya.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
world.Npc_Freya.setIsImmobilized(true);
world.Npc_Freya.setIsInvul(true);
}
if (world.Npc_Glakias != null)
{
world.Npc_Glakias.abortCast();
world.Npc_Glakias.abortAttack();
world.Npc_Glakias.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
world.Npc_Glakias.setIsImmobilized(true);
world.Npc_Glakias.setIsInvul(true);
}
}
private void startAll(FreyaWorld world)
{
for (L2Npc npc : world.getNpcs())
{
if (npc instanceof L2MonsterInstance)
{
npc.setIsInvul(false);
if (npc.getNpcId() != Glacier)
npc.setIsImmobilized(false);
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
}
}
if (world.Npc_Freya != null)
{
world.Npc_Freya.setIsImmobilized(false);
world.Npc_Freya.setIsInvul(false);
world.Npc_Freya.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
}
if (world.Npc_Glakias != null)
{
world.Npc_Glakias.setIsImmobilized(false);
world.Npc_Glakias.setIsInvul(false);
world.Npc_Glakias.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
}
for (L2PcInstance player : world.getPlayers())
{
player.setIsImmobilized(false);
player.setIsInvul(false);
}
world.startBreathController();
world.startKnigthController();
world.startKnigthThroneController();
world.startStoneController();
world.startZoneSkillController();
world.startHelpMoveController();
}
private static void endStage(FreyaWorld world)
{
world.stopHelpMoveController();
world.stopBreathController();
world.stopKnigthController();
world.stopKnigthThroneController();
world.stopStoneController();
world.stopZoneSkillController();
for (L2PcInstance player : world.getPlayers())
{
player.abortCast();
player.abortAttack();
player.getAI().stopAutoAttack();
player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
}
for (L2Npc npc : world.getNpcs())
{
if (npc instanceof L2MonsterInstance)
npc.deleteMe();
}
synchronized(world)
{
world.countIceBreath = 0;
world.countIceStone = 0;
world.countKnigth = 0;
world.countKnigthThrone = 0;
if (world.Npc_Jinia != null)
{
world.Npc_Jinia.deleteMe();
world.Npc_Jinia = null;
}
if (world.Npc_Kegor != null)
{
world.Npc_Kegor.deleteMe();
world.Npc_Kegor = null;
}
if (world.Npc_Freya != null)
{
world.Npc_Freya.deleteMe();
world.Npc_Freya = null;
}
if (world.Npc_Glakias != null)
{
world.Npc_Glakias.deleteMe();
world.Npc_Glakias = null;
}
}
}
private static long generateUpdateTime()
{
Calendar result = Calendar.getInstance();
result.setTimeInMillis(System.currentTimeMillis());
if (result.get(Calendar.DAY_OF_WEEK) < Calendar.WEDNESDAY)
{
if (result.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
result.add(Calendar.DATE,1);
result.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
}
else if (result.get(Calendar.DAY_OF_WEEK) < Calendar.SATURDAY && result.get(Calendar.DAY_OF_WEEK) > Calendar.WEDNESDAY)
result.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
else
{
if (result.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
{
if (result.get(Calendar.HOUR_OF_DAY) < 6 || result.get(Calendar.HOUR_OF_DAY) == 6 && result.get(Calendar.MINUTE) < 30)
result.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
else
result.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
}
else if (result.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
{
if (result.get(Calendar.HOUR_OF_DAY) < 6 || result.get(Calendar.HOUR_OF_DAY) == 6 && result.get(Calendar.MINUTE) < 30)
result.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
else
{
result.add(Calendar.DATE,2);
result.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
}
}
}
result.set(Calendar.HOUR_OF_DAY,6);
result.set(Calendar.MINUTE,30);
result.set(Calendar.SECOND,0);
return result.getTimeInMillis();
}
@Override
public String onEnterZone(L2Character character, L2Zone zone)
{
if ((character instanceof L2PcInstance) && (character.getInstanceId() > 0))
{
//_log.info("onEnterZone: "+ zone.getId() + " Zone Name: "+ zone.getName());
InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(character.getInstanceId());
//_log.info("freya2 onEnterZone tmpworld="+tmpworld.getClass().getCanonicalName());
if (tmpworld != null && tmpworld.templateId == INSTANCEID)
{
//_log.info("onEnterZone tmpworld.templateId="+tmpworld.templateId+" INSTANCEID="+INSTANCEID);
final FreyaWorld world = (FreyaWorld) tmpworld;
//_log.info("zone.getId(): " + zone.getId() + " world.status: " + world.status);
if (zone.getId() == _zoneScriptId && world.status < 1)
{
world.setStatus(1);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
@Override
public void run()
{
world.stage = 1;
IceQueenCastle2.startStage(world);
}
}, 180000); //3 min
}
}
}
return null;
}
@Override
public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
{
if (npc.getInstanceId() > 0)
{
InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
if (tmpworld instanceof FreyaWorld)
{
final FreyaWorld world = (FreyaWorld) tmpworld;
if (npc.getNpcId() == FreyaOnThrone && world.status == 1)
{
endStage(world);
world.setStatus(2);
world.stage = 2;
startStage(world);
}
else if (npc.getNpcId() == ArcheryKnight)
{
if (npc.getTag() != null && (Integer)npc.getTag() == 1)
world.decCountKnigthThrone();
else
world.decCountKnigth();
if (world.status >= 2 && world.status < 12)
{
world.setStatus(world.status + 1);
if (world.status >= 12)
{
allowBossZone(world);
world.BossZone.broadcastMovie(23, world.instanceId);
stopAll(world);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
@Override
public void run()
{
world.Npc_Glakias = IceQueenCastle2.spawn(Glakias, 114722, -114797, -11200, 16384, world);
startAll(world);
}
}, 7000L);
}
}
}
else if (npc.getNpcId() == ArchersBreath)
{
world.decCountIceBreath();
}
else if (npc.getNpcId() == Glakias && world.status == 12)
{
world.Npc_Glakias = null;
world.setStatus(world.status + 1);
endStage(world);
ThreadPoolManager.scheduleGeneral(new Timer(60, world), 100L);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
@Override
public void run()
{
world.stage = 3;
IceQueenCastle2.startStage(world);
}
}, 60100L);
}
else if (npc.getNpcId() == Freya/* && world.status == 15*/)
{
world.setStatus(16/*world.status + 1*/);
endStage(world);
//complete quest 10286_ReunionWithSirra
for (L2PcInstance player1 : world.getPlayers())
{
if (player1 != null)
{
QuestState qs = player1.getQuestState(qnPrev);
if (qs != null && !qs.isCompleted() && qs.getInt("progress") == 2 && qs.getInt("cond") == 6)
{
qs.set("progress", "3");
qs.set("cond", "7");
qs.playSound("ItemSound.quest_middle");
}
}
}
allowBossZone(world);
world.BossZone.broadcastMovie(19, world.instanceId);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
@Override
public void run()
{
world.setStatus(world.status + 1);
}
}, 16000L);
world.getSelfInstance().setDuration(5); //duration 5 min
}
else if (npc.getNpcId() == Glacier)
{
npc.setDisplayEffect(3);
world.decCountIceStone();
addSpawn(ArchersBreath, npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), true, 0, false, world.instanceId);
world.incCountIceBreath();
}
}
}
return null;
}
private static void setInstanceReenterTime(InstanceWorld world)
{
if (world != null)
{
try
{
long nextUpdate = generateUpdateTime();
// set instance reenter time for all allowed players
for (L2PcInstance player : world.getPlayers())
{
if (player != null)
InstanceManager.getInstance().setInstanceTime(player.getObjectId(), INSTANCEID, nextUpdate);
}
}
catch (Exception e) {
// TODO: handle exception
}
}
}
@Override
public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isPet)
{
if (npc.getInstanceId() > 0)
{
InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
if (tmpworld instanceof FreyaWorld && tmpworld.templateId == INSTANCEID)
{
final FreyaWorld world = (FreyaWorld) tmpworld;
if (npc.getNpcId() == Freya && npc.getCurrentHp() < npc.getMaxHp() * 0.45000000000000001D && world.status == 14)
{
world.setStatus(world.status + 1);
stopAll(world);
allowBossZone(world);
world.BossZone.broadcastMovie(18, world.instanceId);
ThreadPoolManager.scheduleGeneral(new Runnable()
{
@Override
public void run()
{
startAll(world);
world.Npc_Kegor = IceQueenCastle2.spawn(Kegor, 114690, -114700, -11200, -16260, world);
world.Npc_Jinia = IceQueenCastle2.spawn(Jinia, 114727, -114700, -11200, -16260, world);
world.BossZone.broadcastPacket(new ExShowScreenMessage(1801089, 6000, 1, -1, true), world.instanceId);
}
}, 28000L);
}
else if (npc.getNpcId() == ArcheryKnight && npc.isImmobilized())
{
startQuestTimer("startAggro", 200, npc, null);
}
}
}
return super.onAttack(npc, player, damage, isPet);
}
static class breathController implements Runnable
{
private L2AttackableAIScript _quest;
private FreyaWorld ww;
private int count;
public breathController(L2AttackableAIScript quest, FreyaWorld world, int startCount)
{
_quest = quest;
ww = world;
count = startCount;
}
@Override
public void run()
{
if (ww != null && ww.countIceBreath < _maxIceBreath)
{
for (int i = 0; i < count; i++)
{
if (ww.countIceBreath >= _maxIceBreath) return;
int[] loc = _iceIceBreathLoc[Rnd.get(0, _iceIceBreathLoc.length - 1)];
_quest.addSpawn(ArchersBreath, loc[0], loc[1], loc[2], loc[3], true, 0, false, ww.instanceId);
ww.incCountIceBreath();
}
}
}
}
static class iceStoneController implements Runnable
{
private L2AttackableAIScript _quest;
private FreyaWorld ww;
private int count;
public iceStoneController(L2AttackableAIScript quest, FreyaWorld world, int startCount)
{
_quest = quest;
ww = world;
count = startCount;
}
@Override
public void run()
{
if (ww != null && ww.countIceStone < _maxIceStone)
{
for (int i = 0; i < count; i++)
{
if (ww.countIceStone >= _maxIceStone) return;
int[] loc = _iceIceBreathLoc[Rnd.get(0, _iceIceBreathLoc.length - 1)];
_quest.addSpawn(Glacier, loc[0], loc[1], loc[2], loc[3], true, 0, false, ww.instanceId);
ww.incCountIceStone();
}
count = 1;
}
}
}
static class zoneSkillController implements Runnable
{
//private L2AttackableAIScript _quest;
private FreyaWorld ww;
public zoneSkillController(L2AttackableAIScript quest, FreyaWorld world)
{
//_quest = quest;
ww = world;
}
@Override
public void run()
{
if (ww != null && ww.countIceStone > 0)
{
int skillLvl = Rnd.get(1, _zoneSkill[1]);
L2Skill skill = SkillTable.getInstance().getInfo(_zoneSkill[0], skillLvl);
for (L2PcInstance player : ww.getPlayers())
{
if (Formulas.calcSkillSuccess(player, player, skill, (byte)0, false, false, false))
skill.getEffects(player, player);
}
}
}
}
static class knigthController implements Runnable
{
private L2AttackableAIScript _quest;
private FreyaWorld ww;
private int count;
public knigthController(L2AttackableAIScript quest, FreyaWorld world, int startCount)
{
_quest = quest;
ww = world;
count = startCount;
}
@Override
public void run()
{
if (ww != null && ww.countKnigth < _maxIceKnigth)
{
for (int i = 0; i < count; i++)
{
if (ww.countKnigth >= _maxIceKnigth) return;
int[] loc = _iceKnightLoc[Rnd.get(0, _iceKnightLoc.length - 1)];
L2Npc knight = _quest.addSpawn(ArcheryKnight, loc[0], loc[1], loc[2], loc[3], true, 0, false, ww.instanceId);
if (knight != null)
{
ww.incCountKnigth();
knight.setIsImmobilized(true);
knight.setDisplayEffect(1);
_quest.startQuestTimer("startAggro", 20000L, knight, null);
}
}
}
}
}
static class knigthThroneController implements Runnable
{
private L2AttackableAIScript _quest;
private FreyaWorld ww;
private int count;
public knigthThroneController(L2AttackableAIScript quest, FreyaWorld world, int startCount)
{
_quest = quest;
ww = world;
count = startCount;
}
@Override
public void run()
{
if (ww != null && ww.countKnigthThrone < _maxIceKnigthThrone[ww.stage - 1])
{
for (int i = 0; i < count; i++)
{
if (ww.countKnigthThrone >= _maxIceKnigthThrone[ww.stage - 1]) return;
int[] loc = _iceKnightLocThrone[Rnd.get(0, _iceKnightLocThrone.length - 1)];
L2Npc knight = _quest.addSpawn(ArcheryKnight, loc[0], loc[1], loc[2], loc[3], true, 0, false, ww.instanceId);
if (knight != null)
{
knight.setTag((Integer)1);
ww.incCountKnigthThrone();
}
}
}
}
}
static class helpMoveController implements Runnable
{
private L2AttackableAIScript _quest;
private FreyaWorld ww;
public helpMoveController(L2AttackableAIScript quest, FreyaWorld world)
{
_quest = quest;
ww = world;
}
@Override
public void run()
{
if (ww != null)
{
for (L2Npc npc : ww.getNpcs())
{
if (npc != null && npc != ww.Npc_Freya && npc != ww.Npc_Glakias && npc != ww.Npc_Jinia && npc != ww.Npc_Kegor && !npc.isImmobilized() && !npc.isInCombat())
_quest.startQuestTimer("moveTo", Rnd.get(200, 800), npc, null);
}
}
}
}
private static void moveTo(L2Npc npc, Location loc)
{
if (npc != null)
{
npc.setRunning();
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(loc.getX(), loc.getY(), loc.getZ()), true);
if (npc.getSpawn() != null)
{
npc.getSpawn().setLocx(loc.getX());
npc.getSpawn().setLocy(loc.getY());
npc.getSpawn().setLocz(loc.getZ());
}
}
}
@Override
public final String onSpawn(L2Npc npc)
{
if (npc.getNpcId() == Glacier)
{
npc.setDisplayEffect(1);
npc.setIsImmobilized(true);
startQuestTimer("changeEffect", 1900L, npc, null);
}
npc.setIsNoAnimation(true);
return null;
}
@Override
public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
{
if (npc != null && npc.getInstanceId() > 0 && InstanceManager.getInstance().getWorld(npc.getInstanceId()) != null && InstanceManager.getInstance().getWorld(npc.getInstanceId()).templateId == INSTANCEID)
{
FreyaWorld world = (FreyaWorld) InstanceManager.getInstance().getWorld(npc.getInstanceId());
if (event.equalsIgnoreCase("changeEffect"))
{
//npc.setIsImmobilized(false);
npc.setDisplayEffect(2);
npc.broadcastFullInfo();
}
else if (event.equalsIgnoreCase("startAggro"))
{
npc.setIsImmobilized(false);
npc.setDisplayEffect(2);
npc.broadcastFullInfo();
}
else if (event.equalsIgnoreCase("moveTo"))
{
if (!npc.isImmobilized() && !npc.isInCombat())
{
if (Rnd.chance100(50) && !world.getPlayers().isEmpty())
{
try
{
L2PcInstance target = world.getSelfInstance().getRandomPlayer();
if (target != null)
{
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
return null;
}
}
catch (Exception e) {
// TODO: handle exception
startQuestTimer("moveTo", 3000L, npc, null);
}
}
Location toLoc = _centerLoc;
if (world.Npc_Glakias != null)
toLoc = world.Npc_Glakias.getLocation();
else if (world.Npc_Freya != null && world.stage != 2)
toLoc = world.Npc_Freya.getLocation();
if (!npc.isInsideRadius(toLoc.getX(), toLoc.getY(), toLoc.getZ(), 500))
moveTo(npc, toLoc);
}
}
}
return null;
}
@Override
public String onTalk(L2Npc npc, L2PcInstance player)
{
int npcId = npc.getNpcId();
if (npcId == JINIA2)
{
enterInstance(npc, player);
}
return "";
}
public IceQueenCastle2(int id, String name, String descr)
{
super(id, name, descr);
addEnterZoneId(_zoneScriptId);
addStartNpc(JINIA2);
addTalkId(JINIA2);
addKillId(FreyaOnThrone);
addKillId(ArcheryKnight);
addSpawnId(ArcheryKnight);
addKillId(ArchersBreath);
addSpawnId(ArchersBreath);
addKillId(Glakias);
addKillId(Freya);
addKillId(Glacier);
addAttackId(Freya);
addAttackId(ArcheryKnight);
addSpawnId(Glacier);
registerSkillsForNpc(Freya, Freya_Skills);
_Zone = (L2BossZone)ZoneManager.getInstance().getZoneById(_zoneBossId);;
}
public static void main(String args[])
{
new IceQueenCastle2(-1, qn, "instances");
}
}