/*
 * 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.edelvez.gameserver.model.actor.instance;

import com.edelvez.gameserver.instancemanager.RaidBossPointsManager;
import com.edelvez.gameserver.model.L2Character;
import com.edelvez.gameserver.model.L2Skill;
import com.edelvez.gameserver.model.L2Summon;
import com.edelvez.gameserver.network.SystemMessageId;
import com.edelvez.gameserver.network.serverpackets.SystemMessage;
import com.edelvez.gameserver.templates.L2NpcTemplate;
import com.edelvez.util.Rnd;

/**
 * This class manages all Grand Bosses.
 *
 * @version $Revision: 1.0.0.0 $ $Date: 2006/06/16 $
 */
public final class L2GrandBossInstance extends L2MonsterInstance
{
	private static final int BOSS_MAINTENANCE_INTERVAL = 10000;
	protected boolean _isInSocialAction = false;

	public boolean IsInSocialAction()
	{
		return _isInSocialAction;
	}

	public void setIsInSocialAction(boolean value)
	{
		_isInSocialAction = value;
	}

	/**
	 * Constructor for L2GrandBossInstance. This represent all grandbosses.
	 *
	 * @param objectId
	 *            ID of the instance
	 * @param template
	 *            L2NpcTemplate of the instance
	 */
	public L2GrandBossInstance(int objectId, L2NpcTemplate template)
	{
		super(objectId, template);
	}

	@Override
	protected int getMaintenanceInterval()
	{
		return BOSS_MAINTENANCE_INTERVAL;
	}

	@Override
	public void onSpawn()
	{
		setIsRaid(true);
		if (getNpcId() == 29020 || getNpcId() == 29028) {
			super.disableCoreAI(true);
		}
		super.onSpawn();
	}

	/**
	 * Reduce the current HP of the L2Attackable, update its _aggroList and launch the doDie Task if necessary.<BR>
	 * <BR>
	 */
	@Override
	public void reduceCurrentHp(double damage, L2Character attacker, boolean awake)
	{
		super.reduceCurrentHp(damage, attacker, awake);
	}

	/**
	 * @see com.edelvez.gameserver.model.actor.instance.L2MonsterInstance#doDie(com.edelvez.gameserver.model.L2Character)
	 */
	@Override
	public boolean doDie(L2Character killer)
	{
		if (!super.doDie(killer)) {
			return false;
		}
		L2PcInstance player = null;
		if (killer instanceof L2PcInstance) {
			player = (L2PcInstance) killer;
		} else if (killer instanceof L2Summon) {
			player = ((L2Summon) killer).getOwner();
		}
		if (player != null)
		{
			broadcastPacket(new SystemMessage(SystemMessageId.RAID_WAS_SUCCESSFUL));
			if (player.getParty() != null)
			{
				for (L2PcInstance member : player.getParty().getPartyMembers())
				{
					RaidBossPointsManager.addPoints(member, getNpcId(), getLevel() / 2 + Rnd.get(-5, 5));
				}
			} else {
				RaidBossPointsManager.addPoints(player, getNpcId(), getLevel() / 2 + Rnd.get(-5, 5));
			}
		}
		return true;
	}

	@Override
	public void doAttack(L2Character target)
	{
		if (_isInSocialAction) {
			return;
		} else {
			super.doAttack(target);
		}
	}

	@Override
	public void doCast(L2Skill skill)
	{
		if (_isInSocialAction) {
			return;
		} else {
			super.doCast(skill);
		}
	}
}
