Support for no PvP zones.
Contributed by Edoo.
This commit is contained in:
		@@ -153,6 +153,7 @@
 | 
			
		||||
									<xs:enumeration value="NoDropItemZone" />
 | 
			
		||||
									<xs:enumeration value="NoLandingZone" />
 | 
			
		||||
									<xs:enumeration value="NoRestartZone" />
 | 
			
		||||
									<xs:enumeration value="NoPvPZone" />
 | 
			
		||||
									<xs:enumeration value="NoStoreZone" />
 | 
			
		||||
									<xs:enumeration value="NoSummonFriendZone" />
 | 
			
		||||
									<xs:enumeration value="NpcSpawnTerritory" />
 | 
			
		||||
 
 | 
			
		||||
@@ -170,7 +170,7 @@ public class AttackableAI extends CreatureAI
 | 
			
		||||
		{
 | 
			
		||||
			// depending on config, do not allow mobs to attack _new_ players in peacezones,
 | 
			
		||||
			// unless they are already following those players from outside the peacezone.
 | 
			
		||||
			if (!Config.ALT_MOB_AGRO_IN_PEACEZONE && target.isInsideZone(ZoneId.PEACE))
 | 
			
		||||
			if (!Config.ALT_MOB_AGRO_IN_PEACEZONE && target.isInsideZone(ZoneId.PEACE) && target.isInsideZone(ZoneId.NO_PVP))
 | 
			
		||||
			{
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -393,7 +393,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
 | 
			
		||||
				{
 | 
			
		||||
					return true;
 | 
			
		||||
				}
 | 
			
		||||
				return (_zones[ZoneId.PVP.ordinal()] > 0) && (_zones[ZoneId.PEACE.ordinal()] == 0);
 | 
			
		||||
				return (_zones[ZoneId.PVP.ordinal()] > 0) && (_zones[ZoneId.PEACE.ordinal()] == 0) && (_zones[ZoneId.NO_PVP.ordinal()] == 0);
 | 
			
		||||
			}
 | 
			
		||||
			case PEACE:
 | 
			
		||||
			{
 | 
			
		||||
@@ -3955,7 +3955,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return (target.isInsideZone(ZoneId.PEACE) || attacker.isInsideZone(ZoneId.PEACE));
 | 
			
		||||
		return (target.isInsideZone(ZoneId.PEACE) || attacker.isInsideZone(ZoneId.PEACE) || target.isInsideZone(ZoneId.NO_PVP) || attacker.isInsideZone(ZoneId.NO_PVP));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
 
 | 
			
		||||
@@ -636,7 +636,7 @@ public abstract class Summon extends Playable
 | 
			
		||||
			final WorldObject currentTarget = _owner.getTarget();
 | 
			
		||||
			if (currentTarget != null)
 | 
			
		||||
			{
 | 
			
		||||
				target = skill.getTarget(this, forceUse && (!currentTarget.isPlayable() || !currentTarget.isInsideZone(ZoneId.PEACE)), dontMove, false);
 | 
			
		||||
				target = skill.getTarget(this, forceUse && (!currentTarget.isPlayable() || !currentTarget.isInsideZone(ZoneId.PEACE) || !currentTarget.isInsideZone(ZoneId.NO_PVP)), dontMove, false);
 | 
			
		||||
				final PlayerInstance currentTargetPlayer = currentTarget.getActingPlayer();
 | 
			
		||||
				if (!forceUse && (currentTargetPlayer != null) && !currentTargetPlayer.isAutoAttackable(_owner))
 | 
			
		||||
				{
 | 
			
		||||
 
 | 
			
		||||
@@ -1844,6 +1844,15 @@ public class PlayerInstance extends Playable
 | 
			
		||||
			_lastCompassZone = ExSetCompassZoneCode.PEACEZONE;
 | 
			
		||||
			sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.PEACEZONE));
 | 
			
		||||
		}
 | 
			
		||||
		else if (isInsideZone(ZoneId.NO_PVP))
 | 
			
		||||
		{
 | 
			
		||||
			if (_lastCompassZone == ExSetCompassZoneCode.NOPVPZONE)
 | 
			
		||||
			{
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			_lastCompassZone = ExSetCompassZoneCode.NOPVPZONE;
 | 
			
		||||
			sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.NOPVPZONE));
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			if (_lastCompassZone == ExSetCompassZoneCode.GENERALZONE)
 | 
			
		||||
@@ -8222,7 +8231,7 @@ public class PlayerInstance extends Playable
 | 
			
		||||
		// Check if the attacker is a Playable
 | 
			
		||||
		if (attacker.isPlayable())
 | 
			
		||||
		{
 | 
			
		||||
			if (isInsideZone(ZoneId.PEACE))
 | 
			
		||||
			if (isInsideZone(ZoneId.PEACE) || isInsideZone(ZoneId.NO_PVP))
 | 
			
		||||
			{
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
@@ -9420,7 +9429,7 @@ public class PlayerInstance extends Playable
 | 
			
		||||
			_noDuelReason = SystemMessageId.C1_CANNOT_DUEL_BECAUSE_C1_IS_CURRENTLY_FISHING;
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		if (isInsideZone(ZoneId.PVP) || isInsideZone(ZoneId.PEACE) || isInsideZone(ZoneId.SIEGE))
 | 
			
		||||
		if (isInsideZone(ZoneId.PVP) || isInsideZone(ZoneId.PEACE) || isInsideZone(ZoneId.SIEGE) || isInsideZone(ZoneId.NO_PVP))
 | 
			
		||||
		{
 | 
			
		||||
			_noDuelReason = SystemMessageId.C1_CANNOT_MAKE_A_CHALLENGE_TO_A_DUEL_BECAUSE_C1_IS_CURRENTLY_IN_A_DUEL_PROHIBITED_AREA_PEACEFUL_ZONE_BATTLE_ZONE_NEAR_WATER_RESTART_PROHIBITED_AREA;
 | 
			
		||||
			return false;
 | 
			
		||||
 
 | 
			
		||||
@@ -920,7 +920,7 @@ public class Duel
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			// is one of the players in a Siege, Peace or PvP zone?
 | 
			
		||||
			if (_playerA.isInsideZone(ZoneId.PEACE) || _playerB.isInsideZone(ZoneId.PEACE) || _playerA.isInsideZone(ZoneId.SIEGE) || _playerB.isInsideZone(ZoneId.SIEGE) || _playerA.isInsideZone(ZoneId.PVP) || _playerB.isInsideZone(ZoneId.PVP))
 | 
			
		||||
			if (_playerA.isInsideZone(ZoneId.PEACE) || _playerB.isInsideZone(ZoneId.PEACE) ||_playerA.isInsideZone(ZoneId.NO_PVP) || _playerB.isInsideZone(ZoneId.NO_PVP) || _playerA.isInsideZone(ZoneId.SIEGE) || _playerB.isInsideZone(ZoneId.SIEGE) || _playerA.isInsideZone(ZoneId.PVP) || _playerB.isInsideZone(ZoneId.PVP))
 | 
			
		||||
			{
 | 
			
		||||
				return DuelResult.CANCELED;
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -37,6 +37,7 @@ public enum ZoneId
 | 
			
		||||
	NO_SUMMON_FRIEND,
 | 
			
		||||
	FORT,
 | 
			
		||||
	NO_STORE,
 | 
			
		||||
	NO_PVP,
 | 
			
		||||
	SCRIPT,
 | 
			
		||||
	HQ,
 | 
			
		||||
	DANGER_AREA,
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,120 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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 org.l2jmobius.gameserver.model.zone.type;
 | 
			
		||||
 | 
			
		||||
import org.l2jmobius.Config;
 | 
			
		||||
import org.l2jmobius.gameserver.model.World;
 | 
			
		||||
import org.l2jmobius.gameserver.model.actor.Creature;
 | 
			
		||||
import org.l2jmobius.gameserver.model.actor.Summon;
 | 
			
		||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
 | 
			
		||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
 | 
			
		||||
import org.l2jmobius.gameserver.model.zone.ZoneType;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * No PVP Zone
 | 
			
		||||
 * @author Edoo
 | 
			
		||||
 */
 | 
			
		||||
public class NoPvPZone extends ZoneType
 | 
			
		||||
{
 | 
			
		||||
	public NoPvPZone(int id)
 | 
			
		||||
	{
 | 
			
		||||
		super(id);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onEnter(Creature creature)
 | 
			
		||||
	{
 | 
			
		||||
		if (!isEnabled())
 | 
			
		||||
		{
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (creature.isPlayer())
 | 
			
		||||
		{
 | 
			
		||||
			final PlayerInstance player = creature.getActingPlayer();
 | 
			
		||||
			// PVP possible during siege, now for siege participants only
 | 
			
		||||
			// Could also check if this town is in siege, or if any siege is going on
 | 
			
		||||
			if ((player.getSiegeState() != 0) && (Config.PEACE_ZONE_MODE == 1))
 | 
			
		||||
			{
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (Config.PEACE_ZONE_MODE != 2)
 | 
			
		||||
		{
 | 
			
		||||
			creature.setInsideZone(ZoneId.NO_PVP, true);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		// Send player info to nearby players.
 | 
			
		||||
		if (creature.isPlayer())
 | 
			
		||||
		{
 | 
			
		||||
			creature.broadcastInfo();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onExit(Creature creature)
 | 
			
		||||
	{
 | 
			
		||||
		if (Config.PEACE_ZONE_MODE != 2)
 | 
			
		||||
		{
 | 
			
		||||
			creature.setInsideZone(ZoneId.NO_PVP, false);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// Send player info to nearby players.
 | 
			
		||||
		if (creature.isPlayer() && !creature.isTeleporting())
 | 
			
		||||
		{
 | 
			
		||||
			creature.broadcastInfo();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void setEnabled(boolean value)
 | 
			
		||||
	{
 | 
			
		||||
		super.setEnabled(value);
 | 
			
		||||
		if (value)
 | 
			
		||||
		{
 | 
			
		||||
			for (PlayerInstance player : World.getInstance().getPlayers())
 | 
			
		||||
			{
 | 
			
		||||
				if ((player != null) && isInsideZone(player))
 | 
			
		||||
				{
 | 
			
		||||
					revalidateInZone(player);
 | 
			
		||||
					
 | 
			
		||||
					if (player.getPet() != null)
 | 
			
		||||
					{
 | 
			
		||||
						revalidateInZone(player.getPet());
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					for (Summon summon : player.getServitors().values())
 | 
			
		||||
					{
 | 
			
		||||
						revalidateInZone(summon);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			for (Creature creature : getCharactersInside())
 | 
			
		||||
			{
 | 
			
		||||
				if (creature != null)
 | 
			
		||||
				{
 | 
			
		||||
					removeCharacter(creature);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -32,6 +32,8 @@ public class ExSetCompassZoneCode implements IClientOutgoingPacket
 | 
			
		||||
	public static final int SEVENSIGNSZONE = 0x0D;
 | 
			
		||||
	public static final int PVPZONE = 0x0E;
 | 
			
		||||
	public static final int GENERALZONE = 0x0F;
 | 
			
		||||
	// TODO: need to find the desired value
 | 
			
		||||
	public static final int NOPVPZONE = 0x0C;
 | 
			
		||||
	
 | 
			
		||||
	private final int _zoneType;
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user