Browse Source

Item Restriction patch by mrpoke. Requires [DP5729]

Check http://www.l2jserver.com/forum/thread.php?threadid=32724 for details and to report any issues.
GodKratos 16 năm trước cách đây
mục cha
commit
efb8e41042
32 tập tin đã thay đổi với 750 bổ sung478 xóa
  1. 0 27
      L2_GameServer/java/config/Character.properties
  2. 3 0
      L2_GameServer/java/config/General.properties
  3. 2 18
      L2_GameServer/java/net/sf/l2j/Config.java
  4. 3 4
      L2_GameServer/java/net/sf/l2j/gameserver/Shutdown.java
  5. 0 1
      L2_GameServer/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminMammon.java
  6. 3 31
      L2_GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Potions.java
  7. 14 54
      L2_GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Scrolls.java
  8. 1 0
      L2_GameServer/java/net/sf/l2j/gameserver/model/L2Clan.java
  9. 7 2
      L2_GameServer/java/net/sf/l2j/gameserver/model/L2Skill.java
  10. 28 0
      L2_GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  11. 27 0
      L2_GameServer/java/net/sf/l2j/gameserver/model/base/PlayerState.java
  12. 2 27
      L2_GameServer/java/net/sf/l2j/gameserver/model/olympiad/OlympiadGame.java
  13. 1 1
      L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  14. 7 1
      L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestPetUseItem.java
  15. 7 241
      L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java
  16. 13 13
      L2_GameServer/java/net/sf/l2j/gameserver/network/serverpackets/ExUseSharedGroupItem.java
  17. 3 1
      L2_GameServer/java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java
  18. 72 40
      L2_GameServer/java/net/sf/l2j/gameserver/skills/DocumentBase.java
  19. 22 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/DocumentItem.java
  20. 3 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/DocumentSkill.java
  21. 2 2
      L2_GameServer/java/net/sf/l2j/gameserver/skills/Formulas.java
  22. 7 6
      L2_GameServer/java/net/sf/l2j/gameserver/skills/SkillsEngine.java
  23. 11 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/Condition.java
  24. 61 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerGrade.java
  25. 54 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerHasCastle.java
  26. 56 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerHasClanHall.java
  27. 55 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerHasFort.java
  28. 52 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerPledgeClass.java
  29. 35 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerSex.java
  30. 17 7
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerState.java
  31. 126 0
      L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionSiegeZone.java
  32. 56 2
      L2_GameServer/java/net/sf/l2j/gameserver/templates/item/L2Item.java

+ 0 - 27
L2_GameServer/java/config/Character.properties

@@ -259,33 +259,6 @@ MaximumWarehouseSlotsForNoDwarf = 100
 MaximumWarehouseSlotsForClan = 200
 MaximumFreightSlots = 20
 
-# Alternate Gaming
-# Usage: True  - Restriction enabled
-#        False - Restriction disabled
-# Castle Shield can be equipped by all clan members if they own a castle.
-# Retail: true
-CastleShieldRestriction = True
-
-# ClanHall Shield can be equipped by all clan members if they own a clan hall.
-# Retail: true
-ClanHallShieldRestriction = True
-
-# Apella armors can be equipped only by clan members if their class is Baron or higher.
-# Retail: true
-ApellaArmorsRestriction = True
-
-# Clan Oath Armors can be equipped only by clan members.
-# Retail: true
-OathArmorsRestriction = True
-
-# Castle Crown can be equipped only by castle lord.
-# Retail: true
-CastleLordsCrownRestriction = True
-
-# Castle Circlet can be equipped only by clan members if they own a castle.
-# Retail: true
-CastleCircletsRestriction = True
-
 #============================================================#
 #                  Enchanting & Augmenting                   #
 #============================================================#

+ 3 - 0
L2_GameServer/java/config/General.properties

@@ -65,6 +65,9 @@ GMStartupDietMode = False
 # Retail: modern
 GMAdminMenuStyle = modern
 
+# Item restrictiions apply to GMs aswell?
+GmItemRestriction = False
+
 #============================================================#
 #                      Server Security                       #
 #============================================================#

+ 2 - 18
L2_GameServer/java/net/sf/l2j/Config.java

@@ -144,12 +144,6 @@ public final class Config
     public static int		WAREHOUSE_SLOTS_NO_DWARF;
     public static int		WAREHOUSE_SLOTS_CLAN;
     public static int		FREIGHT_SLOTS;
-    public static boolean	CASTLE_SHIELD;
-    public static boolean	CLANHALL_SHIELD;
-    public static boolean	APELLA_ARMORS;
-    public static boolean	OATH_ARMORS;
-    public static boolean	CASTLE_CROWN;
-    public static boolean	CASTLE_CIRCLETS;
     public static boolean 	ALT_GAME_KARMA_PLAYER_CAN_BE_KILLED_IN_PEACEZONE;
     public static boolean 	ALT_GAME_KARMA_PLAYER_CAN_SHOP;
     public static boolean 	ALT_GAME_KARMA_PLAYER_CAN_TELEPORT;
@@ -350,6 +344,7 @@ public final class Config
     public static boolean	GM_STARTUP_AUTO_LIST;
     public static boolean 	GM_STARTUP_DIET_MODE;
     public static String	GM_ADMIN_MENU_STYLE;
+    public static boolean 	GM_ITEM_RESTRICTION;
     public static boolean	BYPASS_VALIDATION;
     public static boolean	GAMEGUARD_ENFORCE;
     public static boolean	GAMEGUARD_PROHIBITACTION;
@@ -1297,12 +1292,6 @@ public final class Config
 	                WAREHOUSE_SLOTS_NO_DWARF			= Integer.parseInt(Character.getProperty("MaximumWarehouseSlotsForNoDwarf", "100"));
 	                WAREHOUSE_SLOTS_CLAN				= Integer.parseInt(Character.getProperty("MaximumWarehouseSlotsForClan", "150"));
 	                FREIGHT_SLOTS						= Integer.parseInt(Character.getProperty("MaximumFreightSlots", "20"));
-	                CASTLE_SHIELD						= Boolean.parseBoolean(Character.getProperty("CastleShieldRestriction", "True"));
-	                CLANHALL_SHIELD						= Boolean.parseBoolean(Character.getProperty("ClanHallShieldRestriction", "True"));
-	                APELLA_ARMORS						= Boolean.parseBoolean(Character.getProperty("ApellaArmorsRestriction", "True"));
-	                OATH_ARMORS							= Boolean.parseBoolean(Character.getProperty("OathArmorsRestriction", "True"));
-	                CASTLE_CROWN						= Boolean.parseBoolean(Character.getProperty("CastleLordsCrownRestriction", "True"));
-	                CASTLE_CIRCLETS						= Boolean.parseBoolean(Character.getProperty("CastleCircletsRestriction", "True"));
 	                ENCHANT_CHANCE_WEAPON				= Integer.parseInt(Character.getProperty("EnchantChanceWeapon", "68"));
 	                ENCHANT_CHANCE_ARMOR				= Integer.parseInt(Character.getProperty("EnchantChanceArmor", "52"));
 	                ENCHANT_CHANCE_JEWELRY				= Integer.parseInt(Character.getProperty("EnchantChanceJewelry", "54"));
@@ -1468,6 +1457,7 @@ public final class Config
 	                GM_STARTUP_AUTO_LIST						= Boolean.parseBoolean(General.getProperty("GMStartupAutoList", "False"));
 	                GM_STARTUP_DIET_MODE						= Boolean.parseBoolean(General.getProperty("GMStartupDietMode", "False"));
 	                GM_ADMIN_MENU_STYLE							= General.getProperty("GMAdminMenuStyle", "modern");
+	                GM_ITEM_RESTRICTION							= Boolean.parseBoolean(General.getProperty("GmItemRestriction", "False"));
 	                BYPASS_VALIDATION							= Boolean.parseBoolean(General.getProperty("BypassValidation", "True"));
 	                GAMEGUARD_ENFORCE							= Boolean.parseBoolean(General.getProperty("GameGuardEnforce", "False"));
 	                GAMEGUARD_PROHIBITACTION					= Boolean.parseBoolean(General.getProperty("GameGuardProhibitAction", "False"));
@@ -2276,12 +2266,6 @@ public final class Config
         else if (pName.equalsIgnoreCase("AltMembersCanWithdrawFromClanWH")) ALT_MEMBERS_CAN_WITHDRAW_FROM_CLANWH = Boolean.parseBoolean(pValue);
         else if (pName.equalsIgnoreCase("DwarfRecipeLimit")) DWARF_RECIPE_LIMIT = Integer.parseInt(pValue);
         else if (pName.equalsIgnoreCase("CommonRecipeLimit")) COMMON_RECIPE_LIMIT = Integer.parseInt(pValue);
-        else if (pName.equalsIgnoreCase("CastleShieldRestriction")) CASTLE_SHIELD = Boolean.parseBoolean(pValue);
-        else if (pName.equalsIgnoreCase("ClanHallShieldRestriction")) CLANHALL_SHIELD = Boolean.parseBoolean(pValue);
-        else if (pName.equalsIgnoreCase("ApellaArmorsRestriction")) APELLA_ARMORS = Boolean.parseBoolean(pValue);
-        else if (pName.equalsIgnoreCase("OathArmorsRestriction")) OATH_ARMORS = Boolean.parseBoolean(pValue);
-        else if (pName.equalsIgnoreCase("CastleLordsCrownRestriction")) CASTLE_CROWN = Boolean.parseBoolean(pValue);
-        else if (pName.equalsIgnoreCase("CastleCircletsRestriction")) CASTLE_CIRCLETS = Boolean.parseBoolean(pValue);
 
         //ChampionMobs L2JMOD
         else if (pName.equalsIgnoreCase("ChampionEnable")) L2JMOD_CHAMPION_ENABLE =  Boolean.parseBoolean(pValue);

+ 3 - 4
L2_GameServer/java/net/sf/l2j/gameserver/Shutdown.java

@@ -30,6 +30,7 @@ import net.sf.l2j.gameserver.model.L2World;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.olympiad.Olympiad;
 import net.sf.l2j.gameserver.network.L2GameClient;
+import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.network.gameserverpackets.ServerStatus;
 import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
 import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
@@ -66,10 +67,9 @@ public class Shutdown extends Thread
 	 * @param seconds       seconds untill shutdown
 	 * @param restart       true if the server will restart after shutdown
 	 */
-	@SuppressWarnings("deprecation")
 	private void SendServerQuit(int seconds)
 	{
-		SystemMessage sysm = new SystemMessage(1);
+		SystemMessage sysm = new SystemMessage(SystemMessageId.THE_SERVER_WILL_BE_COMING_DOWN_IN_S1_SECONDS);
 		sysm.addNumber(seconds);
 		Broadcast.toAllOnlinePlayers(sysm);
 	}
@@ -539,10 +539,9 @@ public class Shutdown extends Thread
 	 * this disconnects all clients from the server
 	 *
 	 */
-	@SuppressWarnings("deprecation")
 	private void disconnectAllCharacters()
 	{
-		SystemMessage sysm = new SystemMessage(0);
+		SystemMessage sysm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_DISCONNECTED);
 		ServerClose ql = new ServerClose();
 		Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
 		//synchronized (L2World.getInstance().getAllPlayers())

+ 0 - 1
L2_GameServer/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminMammon.java

@@ -45,7 +45,6 @@ public class AdminMammon implements IAdminCommandHandler
 	
 	private boolean _isSealValidation = SevenSigns.getInstance().isSealValidationPeriod();
 	
-	@SuppressWarnings("deprecation")
 	public boolean useAdminCommand(String command, L2PcInstance activeChar)
 	{
 		int npcId = 0;

+ 3 - 31
L2_GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Potions.java

@@ -202,17 +202,7 @@ public class Potions implements IItemHandler
 			{
 				// elixir of Life
 				byte expIndex = (byte) activeChar.getExpertiseIndex();
-				if ((itemId == 8622 && expIndex == 0) || (itemId == 8623 && expIndex == 1) || (itemId == 8624 && expIndex == 2) || (itemId == 8625 && expIndex == 3) || (itemId == 8626 && expIndex == 4)
-						|| (itemId == 8627 && (expIndex == 5 || expIndex == 6)))
-					res = usePotion(activeChar, 2287, (expIndex > 5 ? expIndex : expIndex + 1));
-				else
-				{
-					SystemMessage sm = new SystemMessage(SystemMessageId.INCOMPATIBLE_ITEM_GRADE); // INCOMPATIBLE_ITEM_GRADE
-					sm.addItemName(item);
-					activeChar.sendPacket(sm);
-					return;
-				}
-				break;
+				res = usePotion(activeChar, 2287, (expIndex > 5 ? expIndex : expIndex + 1));
 			}
 			case 8628:
 			case 8629:
@@ -223,16 +213,7 @@ public class Potions implements IItemHandler
 			{
 				byte expIndex = (byte) activeChar.getExpertiseIndex();
 				// elixir of Strength
-				if ((itemId == 8628 && expIndex == 0) || (itemId == 8629 && expIndex == 1) || (itemId == 8630 && expIndex == 2) || (itemId == 8631 && expIndex == 3) || (itemId == 8632 && expIndex == 4)
-						|| (itemId == 8633 && (expIndex == 5 || expIndex == 6)))
-					res = usePotion(activeChar, 2288, (expIndex > 5 ? expIndex : expIndex + 1));
-				else
-				{
-					SystemMessage sm = new SystemMessage(SystemMessageId.INCOMPATIBLE_ITEM_GRADE); // INCOMPATIBLE_ITEM_GRADE
-					sm.addItemName(item);
-					activeChar.sendPacket(sm);
-					return;
-				}
+				res = usePotion(activeChar, 2288, (expIndex > 5 ? expIndex : expIndex + 1));
 				break;
 			}
 			case 8634:
@@ -244,16 +225,7 @@ public class Potions implements IItemHandler
 			{
 				byte expIndex = (byte) activeChar.getExpertiseIndex();
 				// elixir of cp
-				if ((itemId == 8634 && expIndex == 0) || (itemId == 8635 && expIndex == 1) || (itemId == 8636 && expIndex == 2) || (itemId == 8637 && expIndex == 3) || (itemId == 8638 && expIndex == 4)
-						|| (itemId == 8639 && (expIndex == 5 || expIndex == 6)))
-					res = usePotion(activeChar, 2289, (expIndex > 5 ? expIndex : expIndex + 1));
-				else
-				{
-					SystemMessage sm = new SystemMessage(SystemMessageId.INCOMPATIBLE_ITEM_GRADE); // INCOMPATIBLE_ITEM_GRADE
-					sm.addItemName(item);
-					activeChar.sendPacket(sm);
-					return;
-				}
+				res = usePotion(activeChar, 2289, (expIndex > 5 ? expIndex : expIndex + 1));
 				break;
 			}
 				// VALAKAS AMULETS

+ 14 - 54
L2_GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Scrolls.java

@@ -85,67 +85,29 @@ public class Scrolls implements IItemHandler
 		
 		if (itemId >= 8594 && itemId <= 8599) //Scrolls of recovery XML: 2286
 		{
-			if (activeChar.getKarma() > 0)
-				return; // Chaotic can not use it
-				
-			byte expIndex = (byte) activeChar.getExpertiseIndex();
-			
-			if ((itemId == 8594 && expIndex == 0) || // Scroll: Recovery (No Grade)
-					(itemId == 8595 && expIndex == 1) || // Scroll: Recovery (D Grade)
-					(itemId == 8596 && expIndex == 2) || // Scroll: Recovery (C Grade)
-					(itemId == 8597 && expIndex == 3) || // Scroll: Recovery (B Grade)
-					(itemId == 8598 && expIndex == 4) || // Scroll: Recovery (A Grade)
-					(itemId == 8599 && (expIndex == 5 || expIndex == 6))) // Scroll: Recovery (S/80 Grade)
-			{
-				if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
-					return;
-				activeChar.broadcastPacket(new MagicSkillUse(playable, playable, 2286, 1, 1, 0));
-				activeChar.reduceDeathPenaltyBuffLevel();
-				useScroll(activeChar, 2286, itemId - 8593);
-			}
-			else
-				activeChar.sendPacket(new SystemMessage(SystemMessageId.INCOMPATIBLE_ITEM_GRADE));
+			if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
+				return;
+			activeChar.broadcastPacket(new MagicSkillUse(playable, playable, 2286, 1, 1, 0));
+			activeChar.reduceDeathPenaltyBuffLevel();
+			useScroll(activeChar, 2286, itemId - 8593);
 			return;
 		}
 		else if (itemId == 5703 || itemId >= 5803 && itemId <= 5807)
 		{
 			byte expIndex = (byte) activeChar.getExpertiseIndex();
-			
-			if ((itemId == 5703 && expIndex == 0) || // Lucky Charm (No Grade)
-					(itemId == 5803 && expIndex == 1) || // Lucky Charm (D Grade)
-					(itemId == 5804 && expIndex == 2) || // Lucky Charm (C Grade)
-					(itemId == 5805 && expIndex == 3) || // Lucky Charm (B Grade)
-					(itemId == 5806 && expIndex == 4) || // Lucky Charm (A Grade)
-					(itemId == 5807 && (expIndex == 5 || expIndex == 6))) // Lucky Charm (S/80 Grade)
-			{
-				if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
-					return;
-				activeChar.broadcastPacket(new MagicSkillUse(playable, playable, 2168, (expIndex > 5 ? expIndex : expIndex + 1), 1, 0));
-				useScroll(activeChar, 2168, (expIndex > 5 ? expIndex : expIndex + 1));
-				activeChar.setCharmOfLuck(true);
-			}
-			else
-				activeChar.sendPacket(new SystemMessage(SystemMessageId.INCOMPATIBLE_ITEM_GRADE));
+			if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
+				return;
+			activeChar.broadcastPacket(new MagicSkillUse(playable, playable, 2168, (expIndex > 5 ? expIndex : expIndex + 1), 1, 0));
+			useScroll(activeChar, 2168, (expIndex > 5 ? expIndex : expIndex + 1));
+			activeChar.setCharmOfLuck(true);
 			return;
 		}
 		else if (itemId >= 8515 && itemId <= 8520) // Charm of Courage XML: 5041
 		{
-			byte expIndex = (byte) activeChar.getExpertiseIndex();
-			
-			if ((itemId == 8515 && expIndex == 0) || // Charm of Courage (No Grade)
-					(itemId == 8516 && expIndex <= 1) || // Charm of Courage (D Grade)
-					(itemId == 8517 && expIndex <= 2) || // Charm of Courage (C Grade)
-					(itemId == 8518 && expIndex <= 3) || // Charm of Courage (B Grade)
-					(itemId == 8519 && expIndex <= 4) || // Charm of Courage (A Grade)
-					(itemId == 8520 && expIndex <= 6)) // Charm of Courage (S/80 Grade)
-			{
-				if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
-					return;
-				activeChar.broadcastPacket(new MagicSkillUse(playable, playable, 5041, 1, 1, 0));
-				useScroll(activeChar, 5041, 1);
-			}
-			else
-				activeChar.sendPacket(new SystemMessage(SystemMessageId.INCOMPATIBLE_ITEM_GRADE));
+			if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
+				return;
+			activeChar.broadcastPacket(new MagicSkillUse(playable, playable, 5041, 1, 1, 0));
+			useScroll(activeChar, 5041, 1);
 			return;
 		}
 		else if (itemId == 9897 || itemId >= 10131 && itemId <= 10138 || itemId == 10151 || itemId == 10274) //transformation scrolls
@@ -158,8 +120,6 @@ public class Scrolls implements IItemHandler
 		}
 		else if (itemId >= 8954 && itemId <= 8956)
 		{
-			if (activeChar.getLevel() < 76)
-				return;
 			if (!playable.destroyItem("Consume", item.getObjectId(), 1, null, false))
 				return;
 			switch (itemId)

+ 1 - 0
L2_GameServer/java/net/sf/l2j/gameserver/model/L2Clan.java

@@ -247,6 +247,7 @@ public class L2Clan
 
         exLeader.setPledgeClass(exLeader.getClan().getClanMember(exLeader.getObjectId()).calculatePledgeClass(exLeader));
         exLeader.broadcastUserInfo();
+        exLeader.checkItemRestriction();
         L2PcInstance newLeader = member.getPlayerInstance();
         newLeader.setClan(this);
         newLeader.setPledgeClass(member.calculatePledgeClass(newLeader));

+ 7 - 2
L2_GameServer/java/net/sf/l2j/gameserver/model/L2Skill.java

@@ -375,7 +375,7 @@ public abstract class L2Skill
     private final float _flyCourse;
 
     private final boolean _isDebuff;
-
+    
 	private boolean _isAdvancedFlag;
 
     protected L2Skill(StatsSet set)
@@ -1350,7 +1350,12 @@ public abstract class L2Skill
         if (!preCondition.test(env))
         {
             String msg = preCondition.getMessage();
-            if (msg != null)
+            int msgId = preCondition.getMessageId();
+            if (msgId != 0)
+            {
+            	activeChar.sendPacket(new SystemMessage(msgId));
+            }
+            else if (msg != null)
             {
                 activeChar.sendMessage(msg);
             }

+ 28 - 0
L2_GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java

@@ -2430,6 +2430,7 @@ public final class L2PcInstance extends L2PlayableInstance
 		        return;
 			giveAvailableSkills();
 		}
+		checkItemRestriction();
 		sendSkillList(); 
 		// This function gets called on login, so not such a bad place to check weight
 		refreshOverloaded();		// Update the overloaded status of the L2PcInstance
@@ -8980,6 +8981,7 @@ public final class L2PcInstance extends L2PlayableInstance
 	public void setPledgeClass(int classId)
     {
         _pledgeClass = classId;
+		checkItemRestriction();
     }
 
     public int getPledgeClass()
@@ -11943,4 +11945,30 @@ public final class L2PcInstance extends L2PlayableInstance
     	}
     	super.setIsCastingNow(value);
     }
+    public void checkItemRestriction()
+    {
+    	for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++)
+    	{
+    		L2ItemInstance equippedItem = getInventory().getPaperdollItem(i);
+    		if (equippedItem != null && !equippedItem.getItem().checkCondition(this, this))
+    		{
+				getInventory().unEquipItemInSlotAndRecord(i);
+				if (equippedItem.isWear())
+					continue;
+				SystemMessage sm = null;
+				if (equippedItem.getEnchantLevel() > 0)
+				{
+					sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
+					sm.addNumber(equippedItem.getEnchantLevel());
+					sm.addItemName(equippedItem);
+				}
+				else
+				{
+					sm = new SystemMessage(SystemMessageId.S1_DISARMED);
+					sm.addItemName(equippedItem);
+				}
+				sendPacket(sm);
+    		}
+    	}
+    }
 }

+ 27 - 0
L2_GameServer/java/net/sf/l2j/gameserver/model/base/PlayerState.java

@@ -0,0 +1,27 @@
+/*
+ * 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 net.sf.l2j.gameserver.model.base;
+
+public enum PlayerState
+{
+	 RESTING,
+	 MOVING,
+	 RUNNING,
+	 FLYING,
+	 BEHIND,
+	 FRONT,
+	 CHAOTIC,
+	 OLYMPIAD 
+}

+ 2 - 27
L2_GameServer/java/net/sf/l2j/gameserver/model/olympiad/OlympiadGame.java

@@ -30,7 +30,6 @@ import net.sf.l2j.gameserver.model.L2World;
 import net.sf.l2j.gameserver.model.actor.instance.L2CubicInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
-import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
 import net.sf.l2j.gameserver.model.olympiad.Olympiad.COMP_TYPE;
 import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
@@ -257,31 +256,7 @@ class OlympiadGame
 					party.removePartyMember(player);
 				}
 
-				// Remove over enchanted items and hero weapons
-				for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++)
-				{
-					L2ItemInstance equippedItem = player.getInventory().getPaperdollItem(i);
-					
-					if (equippedItem != null && (equippedItem.isHeroItem() || equippedItem.isOlyRestrictedItem()))
-					{
-						player.getInventory().unEquipItemInSlotAndRecord(i);
-						if (equippedItem.isWear())
-							continue;
-						SystemMessage sm = null;
-						if (equippedItem.getEnchantLevel() > 0)
-						{
-							sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
-							sm.addNumber(equippedItem.getEnchantLevel());
-							sm.addItemName(equippedItem);
-						}
-						else
-						{
-							sm = new SystemMessage(SystemMessageId.S1_DISARMED);
-							sm.addItemName(equippedItem);
-						}
-						player.sendPacket(sm);
-					}
-				}
+				player.checkItemRestriction();
 
 				// Remove shot automation
 				Map<Integer, Integer> activeSoulShots = player.getAutoSoulShot();
@@ -1093,8 +1068,8 @@ class OlympiadGameTask implements Runnable
 			return false;
 		}
 		OlympiadManager.STADIUMS[_game._stadiumID].closeDoors();
-		_game.removals();
 		_game.portPlayersToArena();
+		_game.removals();
 		if (Config.ALT_OLY_ANNOUNCE_GAMES)
 			_game.announceGame();
 		try

+ 1 - 1
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java

@@ -589,7 +589,7 @@ public class EnterWorld extends L2GameClientPacket
         if (activeChar.isNoble() && pledgeClass < 5)
                pledgeClass = 5;
 
-        if (activeChar.isHero())
+        if (activeChar.isHero() && pledgeClass < 8)
                pledgeClass = 8;
 
         activeChar.setPledgeClass(pledgeClass);

+ 7 - 1
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestPetUseItem.java

@@ -78,7 +78,13 @@ public final class RequestPetUseItem extends L2GameClientPacket
 
 		if (Config.DEBUG)
             _log.finest(activeChar.getObjectId()+": pet use item " + _objectId);
-
+		
+        if (!item.isEquipped())
+        {
+        	if ( !item.getItem().checkCondition(activeChar, activeChar))
+        		return;
+        }
+        
 		//check if the item matches the pet
 		if (item.isEquipable())
 		{

+ 7 - 241
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java

@@ -21,9 +21,7 @@ import net.sf.l2j.gameserver.GameTimeController;
 import net.sf.l2j.gameserver.ThreadPoolManager;
 import net.sf.l2j.gameserver.handler.IItemHandler;
 import net.sf.l2j.gameserver.handler.ItemHandler;
-import net.sf.l2j.gameserver.instancemanager.CastleManager;
 import net.sf.l2j.gameserver.instancemanager.FortSiegeManager;
-import net.sf.l2j.gameserver.model.L2Clan;
 import net.sf.l2j.gameserver.model.L2ItemInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.base.Race;
@@ -170,76 +168,6 @@ public final class UseItem extends L2GameClientPacket
 				|| itemId == 10129 || itemId == 10130))
 				return;
 
-
-           L2Clan cl = activeChar.getClan();
-            //A shield that can only be used by the members of a clan that owns a castle.
-           if ((cl == null||cl.getHasCastle() == 0) && itemId == 7015 && Config.CASTLE_SHIELD)
-           {
-               SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-               activeChar.sendPacket(sm);
-               sm = null;
-               return;
-           }
-
-           //A shield that can only be used by the members of a clan that owns a clan hall.
-           if ((cl == null|| cl.getHasHideout() == 0) && itemId == 6902 && Config.CLANHALL_SHIELD)
-           {
-               SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-               activeChar.sendPacket(sm);
-               sm = null;
-               return;
-           }
-           
-           //Apella armor used by clan members may be worn by a Baron or a higher level Aristocrat.
-           if ((itemId >=7860 && itemId <=7879) && Config.APELLA_ARMORS && (cl == null||activeChar.getPledgeClass() < 5))
-           {
-               SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-               activeChar.sendPacket(sm);
-               sm = null;
-               return;
-           }
-
-           //Clan Oath armor used by all clan members
-           if ((itemId >=7850 && itemId <=7859) && Config.OATH_ARMORS && (cl == null))
-           {
-               SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-               activeChar.sendPacket(sm);
-               sm = null;
-               return;
-           }
-
-           //The Lord's Crown used by castle lords only
-           if (itemId ==6841 && Config.CASTLE_CROWN && (cl == null||(cl.getHasCastle() == 0||!activeChar.isClanLeader())))
-           {
-               SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-               activeChar.sendPacket(sm);
-               sm = null;
-               return;
-           }
-
-           //Castle circlets used by the members of a clan that owns a castle, academy members are excluded.
-           if (Config.CASTLE_CIRCLETS &&((itemId >= 6834 && itemId <= 6840)||itemId == 8182||itemId == 8183))
-           {
-               if (cl ==null)
-               {
-                   SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-                   activeChar.sendPacket(sm);
-                   sm = null;
-                   return;
-               }
-               else
-               {
-                   int circletId = CastleManager.getInstance().getCircletByCastleId(cl.getHasCastle());
-                   if (activeChar.getPledgeType() == -1||circletId != itemId)
-                   {
-                       SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-                       activeChar.sendPacket(sm);
-                       sm = null;
-                       return;
-                   }
-               }
-           }
-
 			// Items that cannot be used
 			if (itemId == 57)
                 return;
@@ -276,7 +204,13 @@ public final class UseItem extends L2GameClientPacket
 
 			if (Config.DEBUG)
                 _log.finest(activeChar.getObjectId() + ": use item " + _objectId);
-
+			
+			if (!item.isEquipped())
+			{
+				if ( !item.getItem().checkCondition(activeChar, activeChar))
+					return;
+			}
+            
 			if (item.isEquipable())
 			{
 				// No unequipping/equipping while the player is in special conditions
@@ -386,174 +320,6 @@ public final class UseItem extends L2GameClientPacket
                         }
                         break;
                     }
-                    //Race circlets can be used only if your race is matching.
-                    case L2Item.SLOT_HAIRALL:
-                    {
-                    	if (itemId >= 9391 && itemId <= 9396)
-                    	{
-                    		switch (activeChar.getRace())
-                    		{
-                    			case Kamael:
-                    			{
-                    				if (itemId != 9396)
-                    				{
-                    					activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION));
-                    					return;
-                    				}
-                    				break;
-                    			}
-                    			case Human:
-                    			{
-                    				if (itemId != 9391)
-                    				{
-                    					activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION));
-                    					return;
-                    				}
-                    				break;
-                    			}
-                    			case Dwarf:
-                    			{
-                    				if (itemId != 9395)
-                    				{
-                    					activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION));
-                    					return;
-                    				}
-                    				break;
-                    			}
-                    			case Elf:
-                    			{
-                    				if (itemId != 9392)
-                    				{
-                    					activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION));
-                    					return;
-                    				}
-                    				break;
-                    			}
-                    			case DarkElf:
-                    			{
-                    				if (itemId != 9393)
-                    				{
-                    					activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION));
-                    					return;
-                    				}
-                    				break;
-                    			}
-                    			case Orc:
-                    			{
-                    				if (itemId != 9394)
-                    				{
-                    					activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION));
-                    					return;
-                    				}
-                    				break;
-                    			}
-                    		}
-                    	}
-                        break;
-                    }
-                    case L2Item.SLOT_L_BRACELET:
-                    {
-                    	SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
-                    	if ((itemId >= 9605 && itemId <= 9615) || itemId == 10018)
-                    	{
-                    		if (activeChar.getClan()!= null)
-                    		{
-                    			switch (itemId)
-                    			{
-                    				case 9605:
-                    					if (activeChar.getClan().getHasHideout() != 62)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9606:
-                    					if (activeChar.getClan().getHasHideout() != 63)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9607:
-                    					if (activeChar.getClan().getHasCastle() != 1)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9608:
-                    					if (activeChar.getClan().getHasCastle() != 2)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9609:
-                    					if (activeChar.getClan().getHasCastle() != 3)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9610:
-                    					if (activeChar.getClan().getHasCastle() != 4)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9611:
-                    					if (activeChar.getClan().getHasCastle() != 5)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9612:
-                    					if (activeChar.getClan().getHasCastle() != 6)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9613:
-                    					if (activeChar.getClan().getHasCastle() != 7)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9614:
-                    					if (activeChar.getClan().getHasCastle() != 8)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 9615:
-                    					if (activeChar.getClan().getHasCastle() != 9)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    				case 10018:
-                    					if (activeChar.getClan().getHasFort() == 0)
-                    					{
-                                            activeChar.sendPacket(sm);
-                                            return;
-                    					}
-                    					break;
-                    			}
-                    		}
-                    		else
-                    		{
-                                activeChar.sendPacket(sm);
-                                return;
-                    		}
-                    	}
-                    	break;
-                    }
                     case L2Item.SLOT_DECO:
                     {
                         if (!item.isEquipped() && activeChar.getInventory().getMaxTalismanCount() == 0)

+ 13 - 13
L2_GameServer/java/net/sf/l2j/gameserver/network/serverpackets/ExUseSharedGroupItem.java

@@ -20,15 +20,15 @@ package net.sf.l2j.gameserver.network.serverpackets;
  */
 public class ExUseSharedGroupItem extends L2GameServerPacket
 {
-	private static final String _S__FE_49_EXUSESHAREDGROUPITEM = "[S] FE:4a ExUseSharedGroupItem";
-	private int _unk1, _unk2, _unk3, _unk4;
+	private static final String _S__FE_4A_EXUSESHAREDGROUPITEM = "[S] FE:4a ExUseSharedGroupItem";
+	private int _itemId, _grpId, _remainedTime, _totalTime;
 
-	public ExUseSharedGroupItem(int unk1, int unk2, int unk3, int unk4)
+	public ExUseSharedGroupItem(int itemId, int grpId, int remainedTime, int totalTime)
 	{
-		_unk1 = unk1;
-		_unk2 = unk2;
-		_unk3 = unk3;
-		_unk4 = unk4;
+		_itemId = itemId;
+		_grpId = grpId;
+		_remainedTime = remainedTime / 1000;
+		_totalTime = totalTime / 1000;
 	}
 
 	/**
@@ -40,10 +40,10 @@ public class ExUseSharedGroupItem extends L2GameServerPacket
 		writeC(0xfe);
 		writeH(0x4a);
 
-		writeD(_unk1);
-		writeD(_unk2);
-		writeD(_unk3);
-		writeD(_unk4);
+		writeD(_itemId);
+		writeD(_grpId);
+		writeD(_remainedTime);
+		writeD(_totalTime);
 	}
 
 	/**
@@ -52,7 +52,7 @@ public class ExUseSharedGroupItem extends L2GameServerPacket
 	@Override
 	public String getType()
 	{
-		return _S__FE_49_EXUSESHAREDGROUPITEM;
+		return _S__FE_4A_EXUSESHAREDGROUPITEM;
 	}
 
-}
+}

+ 3 - 1
L2_GameServer/java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java

@@ -54,7 +54,9 @@ public final class SystemMessage extends L2GameServerPacket
 		_messageId = messageId.getId();
 	}
 
-	@Deprecated
+	/**
+	 * Use SystemMessage(SystemMessageId messageId) where possible instead
+	 */
 	public SystemMessage(int messageId)
 	{
 		_messageId = messageId;

+ 72 - 40
L2_GameServer/java/net/sf/l2j/gameserver/skills/DocumentBase.java

@@ -31,38 +31,10 @@ import net.sf.l2j.Config;
 import net.sf.l2j.gameserver.datatables.SkillTable;
 import net.sf.l2j.gameserver.model.L2Character;
 import net.sf.l2j.gameserver.model.L2Skill;
+import net.sf.l2j.gameserver.model.base.PlayerState;
 import net.sf.l2j.gameserver.model.base.Race;
-import net.sf.l2j.gameserver.skills.conditions.Condition;
-import net.sf.l2j.gameserver.skills.conditions.ConditionChangeWeapon;
-import net.sf.l2j.gameserver.skills.conditions.ConditionForceBuff;
-import net.sf.l2j.gameserver.skills.conditions.ConditionGameChance;
-import net.sf.l2j.gameserver.skills.conditions.ConditionGameTime;
-import net.sf.l2j.gameserver.skills.conditions.ConditionLogicAnd;
-import net.sf.l2j.gameserver.skills.conditions.ConditionLogicNot;
-import net.sf.l2j.gameserver.skills.conditions.ConditionLogicOr;
-import net.sf.l2j.gameserver.skills.conditions.ConditionMinDistance;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerCp;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerHp;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerHpPercentage;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerLevel;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerMp;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerRace;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerState;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerWeight;
-import net.sf.l2j.gameserver.skills.conditions.ConditionSkillStats;
-import net.sf.l2j.gameserver.skills.conditions.ConditionSlotItemId;
-import net.sf.l2j.gameserver.skills.conditions.ConditionTargetActiveEffectId;
-import net.sf.l2j.gameserver.skills.conditions.ConditionTargetActiveSkillId;
-import net.sf.l2j.gameserver.skills.conditions.ConditionTargetAggro;
-import net.sf.l2j.gameserver.skills.conditions.ConditionTargetClassIdRestriction;
-import net.sf.l2j.gameserver.skills.conditions.ConditionTargetLevel;
-import net.sf.l2j.gameserver.skills.conditions.ConditionTargetRaceId;
-import net.sf.l2j.gameserver.skills.conditions.ConditionTargetUsesWeaponKind;
-import net.sf.l2j.gameserver.skills.conditions.ConditionUsingItemType;
-import net.sf.l2j.gameserver.skills.conditions.ConditionUsingSkill;
-import net.sf.l2j.gameserver.skills.conditions.ConditionWithSkill;
+import net.sf.l2j.gameserver.skills.conditions.*;
 import net.sf.l2j.gameserver.skills.conditions.ConditionGameTime.CheckGameTime;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerState.CheckPlayerState;
 import net.sf.l2j.gameserver.skills.effects.EffectTemplate;
 import net.sf.l2j.gameserver.skills.funcs.FuncTemplate;
 import net.sf.l2j.gameserver.skills.funcs.Lambda;
@@ -151,8 +123,12 @@ abstract class DocumentBase
         if ("cond".equalsIgnoreCase(n.getNodeName()))
         {
             condition = parseCondition(n.getFirstChild(), template);
-            Node msg = n.getAttributes().getNamedItem("msg");
-            if (condition != null && msg != null) condition.setMessage(msg.getNodeValue());
+			Node msg = n.getAttributes().getNamedItem("msg");
+			Node msgId = n.getAttributes().getNamedItem("msgId");
+			if (condition != null && msg != null)
+				condition.setMessage(msg.getNodeValue());
+			else if (condition != null && msgId != null)
+				condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
             n = n.getNextSibling();
         }
         for (; n != null; n = n.getNextSibling())
@@ -314,7 +290,7 @@ abstract class DocumentBase
         if ("and".equalsIgnoreCase(n.getNodeName())) return parseLogicAnd(n, template);
         if ("or".equalsIgnoreCase(n.getNodeName())) return parseLogicOr(n, template);
         if ("not".equalsIgnoreCase(n.getNodeName())) return parseLogicNot(n, template);
-        if ("player".equalsIgnoreCase(n.getNodeName())) return parsePlayerCondition(n);
+        if ("player".equalsIgnoreCase(n.getNodeName())) return parsePlayerCondition(n, template);
         if ("target".equalsIgnoreCase(n.getNodeName())) return parseTargetCondition(n, template);
         if ("skill".equalsIgnoreCase(n.getNodeName())) return parseSkillCondition(n);
         if ("using".equalsIgnoreCase(n.getNodeName())) return parseUsingCondition(n);
@@ -359,7 +335,7 @@ abstract class DocumentBase
         return null;
     }
 
-    protected Condition parsePlayerCondition(Node n)
+    protected Condition parsePlayerCondition(Node n, Object template)
     {
         Condition cond = null;
         byte[] forces = new byte[2];
@@ -380,32 +356,42 @@ abstract class DocumentBase
             else if ("resting".equalsIgnoreCase(a.getNodeName()))
             {
                 boolean val = Boolean.valueOf(a.getNodeValue());
-                cond = joinAnd(cond, new ConditionPlayerState(CheckPlayerState.RESTING, val));
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RESTING, val));
             }
             else if ("flying".equalsIgnoreCase(a.getNodeName()))
             {
                 boolean val = Boolean.valueOf(a.getNodeValue());
-                cond = joinAnd(cond, new ConditionPlayerState(CheckPlayerState.FLYING, val));
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FLYING, val));
             }
             else if ("moving".equalsIgnoreCase(a.getNodeName()))
             {
                 boolean val = Boolean.valueOf(a.getNodeValue());
-                cond = joinAnd(cond, new ConditionPlayerState(CheckPlayerState.MOVING, val));
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.MOVING, val));
             }
             else if ("running".equalsIgnoreCase(a.getNodeName()))
             {
                 boolean val = Boolean.valueOf(a.getNodeValue());
-                cond = joinAnd(cond, new ConditionPlayerState(CheckPlayerState.RUNNING, val));
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RUNNING, val));
             }
             else if ("behind".equalsIgnoreCase(a.getNodeName()))
             {
                 boolean val = Boolean.valueOf(a.getNodeValue());
-                cond = joinAnd(cond, new ConditionPlayerState(CheckPlayerState.BEHIND, val));
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.BEHIND, val));
             }
             else if ("front".equalsIgnoreCase(a.getNodeName()))
             {
                 boolean val = Boolean.valueOf(a.getNodeValue());
-                cond = joinAnd(cond, new ConditionPlayerState(CheckPlayerState.FRONT, val));
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FRONT, val));
+            }
+            else if ("chaotic".equalsIgnoreCase(a.getNodeName()))
+            {
+                boolean val = Boolean.valueOf(a.getNodeValue());
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.CHAOTIC, val));
+            }
+            else if ("olympiad".equalsIgnoreCase(a.getNodeName()))
+            {
+                boolean val = Boolean.valueOf(a.getNodeValue());
+                cond = joinAnd(cond, new ConditionPlayerState(PlayerState.OLYMPIAD, val));
             }
             else if ("hp".equalsIgnoreCase(a.getNodeName()))
             {
@@ -427,6 +413,16 @@ abstract class DocumentBase
             	int cp = Integer.decode(getValue(a.getNodeValue(), null));
             	cond = joinAnd(cond, new ConditionPlayerCp(cp));
             }
+            else if ("grade".equalsIgnoreCase(a.getNodeName()))
+            {
+            	int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
+            	cond = joinAnd(cond, new ConditionPlayerGrade(expIndex));
+            }
+            else if ("siegezone".equalsIgnoreCase(a.getNodeName()))
+            {
+                int value = Integer.decode(getValue(a.getNodeValue(), null));
+                cond = joinAnd(cond, new ConditionSiegeZone(value, true));
+            }
             else if ("battle_force".equalsIgnoreCase(a.getNodeName()))
             {
                 forces[0] = Byte.decode(getValue(a.getNodeValue(), null));
@@ -440,6 +436,37 @@ abstract class DocumentBase
                 int weight = Integer.decode(getValue(a.getNodeValue(), null));
                 cond = joinAnd(cond, new ConditionPlayerWeight(weight));
             }
+            else if ("pledgeClass".equalsIgnoreCase(a.getNodeName()))
+            {
+                int pledgeClass = Integer.decode(getValue(a.getNodeValue(), null));
+                cond = joinAnd(cond, new ConditionPlayerPledgeClass(pledgeClass));
+            }
+            else if ("clanHall".equalsIgnoreCase(a.getNodeName()))
+            {
+            	FastList<Integer> array = new FastList<Integer>();
+            	StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
+            	while (st.hasMoreTokens())
+                {
+                    String item = st.nextToken().trim();
+                    array.add(Integer.decode(getValue(item, null)));
+                }
+                cond = joinAnd(cond, new ConditionPlayerHasClanHall(array));
+            }
+            else if ("fort".equalsIgnoreCase(a.getNodeName()))
+            {
+                int fort = Integer.decode(getValue(a.getNodeValue(), null));
+                cond = joinAnd(cond, new ConditionPlayerHasFort(fort));
+            }
+            else if ("castle".equalsIgnoreCase(a.getNodeName()))
+            {
+                int castle = Integer.decode(getValue(a.getNodeValue(), null));
+                cond = joinAnd(cond, new ConditionPlayerHasCastle(castle));
+            }
+            else if ("sex".equalsIgnoreCase(a.getNodeName()))
+            {
+                int sex = Integer.decode(getValue(a.getNodeValue(), null));
+                cond = joinAnd(cond, new ConditionPlayerSex(sex));
+            }
         }
 
         if(forces[0] + forces[1] > 0)
@@ -463,6 +490,11 @@ abstract class DocumentBase
                 boolean val = Boolean.valueOf(a.getNodeValue());
                 cond = joinAnd(cond, new ConditionTargetAggro(val));
             }
+            else if ("siegezone".equalsIgnoreCase(a.getNodeName()))
+            {
+                int value = Integer.decode(getValue(a.getNodeValue(), null));
+                cond = joinAnd(cond, new ConditionSiegeZone(value, false));
+            }
             else if ("level".equalsIgnoreCase(a.getNodeName()))
             {
                 int lvl = Integer.decode(getValue(a.getNodeValue(), template));

+ 22 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/DocumentItem.java

@@ -21,6 +21,7 @@ import java.util.Map;
 import javolution.util.FastList;
 import javolution.util.FastMap;
 import net.sf.l2j.gameserver.Item;
+import net.sf.l2j.gameserver.skills.conditions.Condition;
 import net.sf.l2j.gameserver.templates.StatsSet;
 import net.sf.l2j.gameserver.templates.item.L2Armor;
 import net.sf.l2j.gameserver.templates.item.L2ArmorType;
@@ -143,6 +144,27 @@ final class DocumentItem extends DocumentBase
                 parseTemplate(n, _currentItem.item);
             }
         }
+        for (n = first; n != null; n = n.getNextSibling())
+        {
+			if ("cond".equalsIgnoreCase(n.getNodeName()))
+			{
+				Condition condition = parseCondition(n.getFirstChild(), _currentItem.item );
+				Node msg = n.getAttributes().getNamedItem("msg");
+				Node msgId = n.getAttributes().getNamedItem("msgId");
+				if (condition != null && msg != null)
+					condition.setMessage(msg.getNodeValue());
+				else if (condition != null && msgId != null)
+					condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
+				_currentItem.item.attach(condition);
+			}
+        }
+        for (n = first; n != null; n = n.getNextSibling())
+        {
+			if ("skill".equalsIgnoreCase(n.getNodeName()))
+			{
+				attachSkill(n, _currentItem.item, null);
+			}
+        }
     }
 
     private void makeItem()

+ 3 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/DocumentSkill.java

@@ -316,8 +316,11 @@ class DocumentSkill extends DocumentBase {
 				{
 					Condition condition = parseCondition(n.getFirstChild(), _currentSkill.currentSkills.get(i));
 					Node msg = n.getAttributes().getNamedItem("msg");
+					Node msgId = n.getAttributes().getNamedItem("msgId");
 					if (condition != null && msg != null)
 						condition.setMessage(msg.getNodeValue());
+					else if (condition != null && msgId != null)
+						condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
                     _currentSkill.currentSkills.get(i).attach(condition, false);
 				}
 				if ("for".equalsIgnoreCase(n.getNodeName()))

+ 2 - 2
L2_GameServer/java/net/sf/l2j/gameserver/skills/Formulas.java

@@ -33,6 +33,7 @@ import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
 import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
+import net.sf.l2j.gameserver.model.base.PlayerState;
 import net.sf.l2j.gameserver.model.entity.Castle;
 import net.sf.l2j.gameserver.model.entity.ClanHall;
 import net.sf.l2j.gameserver.model.entity.Fort;
@@ -42,7 +43,6 @@ import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
 import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerState;
 import net.sf.l2j.gameserver.skills.conditions.ConditionUsingItemType;
-import net.sf.l2j.gameserver.skills.conditions.ConditionPlayerState.CheckPlayerState;
 import net.sf.l2j.gameserver.skills.funcs.Func;
 import net.sf.l2j.gameserver.templates.chars.L2PcTemplate;
 import net.sf.l2j.gameserver.templates.item.L2Armor;
@@ -165,7 +165,7 @@ public final class Formulas
 		private FuncMultRegenResting(Stats pStat)
 		{
 			super(pStat, 0x20, null);
-			setCondition(new ConditionPlayerState(CheckPlayerState.RESTING, true));
+			setCondition(new ConditionPlayerState(PlayerState.RESTING, true));
 		}
 
 		/**

+ 7 - 6
L2_GameServer/java/net/sf/l2j/gameserver/skills/SkillsEngine.java

@@ -54,7 +54,7 @@ public class SkillsEngine {
 
 	private SkillsEngine()
 	{
-		//hashFiles("data/stats/etcitem", _etcitemFiles);
+		hashFiles("data/stats/etcitem", _etcitemFiles);
 		hashFiles("data/stats/armor", _armorFiles);
 		hashFiles("data/stats/weapon", _weaponFiles);
 		hashFiles("data/stats/skills", _skillFiles);
@@ -132,16 +132,17 @@ public class SkillsEngine {
     public List<L2EtcItem> loadItems(Map<Integer, Item> itemData)
     {
         List<L2EtcItem> list  = new FastList<L2EtcItem>();
+        List<Integer> xmlItem  = new FastList<Integer>();
+        
         for (L2Item item : loadData(itemData, _etcitemFiles))
         {
             list.add((L2EtcItem)item);
+            xmlItem.add(item.getItemId());
         }
-        if (list.size() == 0)
+        for (Item item : itemData.values())
         {
-            for (Item item : itemData.values())
-            {
-                list.add(new L2EtcItem((L2EtcItemType)item.type, item.set));
-            }
+        	if (!xmlItem.contains(item.id))
+        		list.add(new L2EtcItem((L2EtcItemType)item.type, item.set));
         }
         return list;
     }

+ 11 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/Condition.java

@@ -29,6 +29,7 @@ public abstract class Condition implements ConditionListener
 	
 	private ConditionListener _listener;
 	private String _msg;
+	private int _msgId;
 	private boolean _result;
 	
 	public final void setMessage(String msg)
@@ -41,6 +42,16 @@ public abstract class Condition implements ConditionListener
 		return _msg;
 	}
 	
+	public final void setMessageId(int msgId)
+	{
+		_msgId = msgId;
+	}
+	
+	public final int getMessageId()
+	{
+		return _msgId;
+	}
+	
 	void setListener(ConditionListener listener)
 	{
 		_listener = listener;

+ 61 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerGrade.java

@@ -0,0 +1,61 @@
+/*
+ * 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 net.sf.l2j.gameserver.skills.conditions;
+
+import java.util.logging.Logger;
+
+import net.sf.l2j.gameserver.skills.Env;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author Gigiikun
+ */
+
+public final class ConditionPlayerGrade extends Condition
+{
+	protected static final Logger _log = Logger.getLogger(ConditionPlayerGrade.class.getName());
+	//	conditional values
+    public final static int COND_NO_GRADE = 0x0001;
+    public final static int COND_D_GRADE = 0x0002;
+    public final static int COND_C_GRADE = 0x0004;
+    public final static int COND_B_GRADE = 0x0008;
+    public final static int COND_A_GRADE = 0x0010;
+    public final static int COND_S_GRADE = 0x0020;
+    public final static int COND_S80_GRADE = 0x0040;
+    
+    private final int _value;
+
+    /**
+     * 
+     */
+
+    public ConditionPlayerGrade(int value)
+    {
+        _value = value;
+    }
+
+    @Override
+    public boolean testImpl(Env env)
+    {
+    	if (env.player instanceof L2PcInstance) 
+    	{
+    		byte expIndex = (byte)((L2PcInstance)env.player).getExpertiseIndex();
+
+    		return _value == expIndex;
+    	}
+    	return false;	
+    }
+    
+}

+ 54 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerHasCastle.java

@@ -0,0 +1,54 @@
+/*
+ * 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 net.sf.l2j.gameserver.skills.conditions;
+
+import net.sf.l2j.gameserver.model.L2Clan;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.skills.Env;
+
+/**
+ * @author MrPoke
+ *
+ */
+public final class ConditionPlayerHasCastle extends Condition
+{
+	
+	private final int _castle;
+	
+	public ConditionPlayerHasCastle(int castle)
+	{
+		_castle = castle;
+	}
+	
+	/**
+	 * 
+	 * @see net.sf.l2j.gameserver.skills.conditions.Condition#testImpl(net.sf.l2j.gameserver.skills.Env)
+	 */
+	@Override
+	public boolean testImpl(Env env)
+	{
+		if (!(env.player instanceof L2PcInstance))
+			return false;
+		
+		L2Clan clan = ((L2PcInstance)env.player).getClan();
+		if (clan == null)
+			return _castle == 0;
+		
+		// Any castle
+		if (_castle == -1) return clan.getHasCastle() > 0;
+		
+		return clan.getHasCastle() == _castle;
+	}
+}

+ 56 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerHasClanHall.java

@@ -0,0 +1,56 @@
+/*
+ * 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 net.sf.l2j.gameserver.skills.conditions;
+
+import javolution.util.FastList;
+import net.sf.l2j.gameserver.model.L2Clan;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.skills.Env;
+
+/**
+ * @author MrPoke
+ *
+ */
+public final class ConditionPlayerHasClanHall extends Condition
+{
+	
+	private final FastList<Integer> _clanHall;
+	
+	public ConditionPlayerHasClanHall(FastList<Integer> clanHall)
+	{
+		_clanHall = clanHall;
+	}
+	
+	/**
+	 * 
+	 * @see net.sf.l2j.gameserver.skills.conditions.Condition#testImpl(net.sf.l2j.gameserver.skills.Env)
+	 */
+	@Override
+	public boolean testImpl(Env env)
+	{
+		if (!(env.player instanceof L2PcInstance))
+			return false;
+		
+		L2Clan clan = ((L2PcInstance)env.player).getClan();
+		if (clan == null)
+			return (_clanHall.size() == 1 && _clanHall.getFirst() == 0);
+		
+		// All Clan Hall
+		if (_clanHall.size() == 1 && _clanHall.getFirst() == -1)
+			return clan.getHasHideout() > 0;
+		
+		return _clanHall.contains(clan.getHasHideout());
+	}
+}

+ 55 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerHasFort.java

@@ -0,0 +1,55 @@
+/*
+ * 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 net.sf.l2j.gameserver.skills.conditions;
+
+import net.sf.l2j.gameserver.model.L2Clan;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.skills.Env;
+
+/**
+ * @author MrPoke
+ *
+ */
+public final class ConditionPlayerHasFort extends Condition
+{
+	
+	private final int _fort;
+	
+	public ConditionPlayerHasFort(int fort)
+	{
+		_fort = fort;
+	}
+	
+	/**
+	 * 
+	 * @see net.sf.l2j.gameserver.skills.conditions.Condition#testImpl(net.sf.l2j.gameserver.skills.Env)
+	 */
+	@Override
+	public boolean testImpl(Env env)
+	{
+		if (!(env.player instanceof L2PcInstance))
+			return false;
+		
+		L2Clan clan = ((L2PcInstance)env.player).getClan();
+		if (clan == null)
+			return _fort == 0;
+		
+		// Any fortress
+		if (_fort == -1)
+			return clan.getHasFort() > 0;
+		
+		return clan.getHasFort() == _fort;
+	}
+}

+ 52 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerPledgeClass.java

@@ -0,0 +1,52 @@
+/*
+ * 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 net.sf.l2j.gameserver.skills.conditions;
+
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.skills.Env;
+
+/**
+ * @author MrPoke
+ *
+ */
+public final class ConditionPlayerPledgeClass extends Condition
+{
+	
+	private final int _pledgeClass;
+	
+	public ConditionPlayerPledgeClass(int pledgeClass)
+	{
+		_pledgeClass = pledgeClass;
+	}
+	
+	/**
+	 * 
+	 * @see net.sf.l2j.gameserver.skills.conditions.Condition#testImpl(net.sf.l2j.gameserver.skills.Env)
+	 */
+	@Override
+	public boolean testImpl(Env env)
+	{
+		if (!(env.player instanceof L2PcInstance))
+			return false;
+		
+		if (((L2PcInstance)env.player).getClan() == null)
+			return false;
+		
+		if (_pledgeClass == -1)
+			return ((L2PcInstance)env.player).isClanLeader();
+		
+		return (((L2PcInstance)env.player).getPledgeClass() >= _pledgeClass);
+	}
+}

+ 35 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerSex.java

@@ -0,0 +1,35 @@
+/*
+ * 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 net.sf.l2j.gameserver.skills.conditions;
+
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.skills.Env;
+
+public class ConditionPlayerSex extends Condition
+{
+	//male 0 fmale 1
+	private final int _sex;
+
+	public ConditionPlayerSex(int sex)
+	{
+		_sex = sex;
+	}
+
+	@Override
+	public boolean testImpl(Env env)
+	{
+		return (((L2PcInstance)env.player).getAppearance().getSex()? 1:0) == _sex;
+	}
+}

+ 17 - 7
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionPlayerState.java

@@ -15,6 +15,7 @@
 package net.sf.l2j.gameserver.skills.conditions;
 
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.model.base.PlayerState;
 import net.sf.l2j.gameserver.skills.Env;
 
 
@@ -24,14 +25,13 @@ import net.sf.l2j.gameserver.skills.Env;
  * TODO To change the template for this generated type comment go to
  * Window - Preferences - Java - Code Style - Code Templates
  */
-public class ConditionPlayerState extends Condition {
+public class ConditionPlayerState extends Condition 
+{
 
-	public enum CheckPlayerState { RESTING, MOVING, RUNNING, FLYING, BEHIND, FRONT }
-
-	private final CheckPlayerState _check;
+	private final PlayerState _check;
 	private final boolean _required;
 
-	public ConditionPlayerState(CheckPlayerState check, boolean required)
+	public ConditionPlayerState(PlayerState check, boolean required)
 	{
 		_check = check;
 		_required = required;
@@ -39,12 +39,12 @@ public class ConditionPlayerState extends Condition {
 
 	@Override
 	public boolean testImpl(Env env) {
+		L2PcInstance player;
 		switch (_check)
 		{
 		case RESTING:
-			if (env.player instanceof L2PcInstance) {
+			if (env.player instanceof L2PcInstance)
 				return ((L2PcInstance)env.player).isSitting() == _required;
-			}
 			return !_required;
 		case MOVING:
 			return env.player.isMoving() == _required;
@@ -56,6 +56,16 @@ public class ConditionPlayerState extends Condition {
             return env.player.isBehindTarget() == _required;
         case FRONT:
             return env.player.isInFrontOfTarget() == _required;
+        case CHAOTIC:
+        	player = env.player.getActingPlayer();
+        	if (player != null) 
+        		return  player.getKarma() > 0 == _required;
+			return !_required;
+        case OLYMPIAD:
+        	player = env.player.getActingPlayer();
+        	if (player != null)
+        		return player.isInOlympiadMode() == _required;
+        	return !_required;
 		}
 		return !_required;
 	}

+ 126 - 0
L2_GameServer/java/net/sf/l2j/gameserver/skills/conditions/ConditionSiegeZone.java

@@ -0,0 +1,126 @@
+/*
+ * 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 net.sf.l2j.gameserver.skills.conditions;
+
+import net.sf.l2j.gameserver.skills.Env;
+import net.sf.l2j.gameserver.instancemanager.CastleManager;
+import net.sf.l2j.gameserver.instancemanager.FortManager;
+import net.sf.l2j.gameserver.model.L2Character;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.model.entity.Castle;
+import net.sf.l2j.gameserver.model.entity.Fort;
+
+/**
+ * @author Gigiikun
+ */
+
+public final class ConditionSiegeZone extends Condition
+{
+	//	conditional values
+    public final static int COND_NOT_ZONE = 0x0001;
+    public final static int COND_CAST_ATTACK = 0x0002;
+    public final static int COND_CAST_DEFEND = 0x0004;
+    public final static int COND_CAST_NEUTRAL = 0x0008;
+    public final static int COND_FORT_ATTACK = 0x0010;
+    public final static int COND_FORT_DEFEND = 0x0020;
+    public final static int COND_FORT_NEUTRAL = 0x0040;
+    
+    private final int _value;
+    private final boolean _self;
+    /**
+     * 
+     */
+
+    public ConditionSiegeZone(int value, boolean self)
+    {
+        _value = value;
+        _self = self;
+    }
+
+    @Override
+    public boolean testImpl(Env env)
+    {
+    	L2Character target = _self ? env.player : env.target;
+        Castle castle = CastleManager.getInstance().getCastle(target);
+        Fort fort = FortManager.getInstance().getFort(target);
+
+        if ((castle == null) && (fort == null))
+        {
+        	if ((_value & COND_NOT_ZONE) != 0)
+        		return true;
+        	else
+        		return false;
+        }
+        if (castle != null)
+            return checkIfOk(target, castle, _value);
+        else
+            return checkIfOk(target, fort, _value);
+    }
+    
+    public static boolean checkIfOk(L2Character activeChar, Castle castle, int value)
+    {
+        if (activeChar == null || !(activeChar instanceof L2PcInstance))
+            return false;
+
+        L2PcInstance player = (L2PcInstance)activeChar;
+
+        if ((castle == null || castle.getCastleId() <= 0))
+        {
+        	if ((value & COND_NOT_ZONE) != 0)
+        		return true;
+        }
+        else if (!castle.getSiege().getIsInProgress())
+        {
+        	if ((value & COND_NOT_ZONE) != 0)
+        		return true;
+        }
+        else if ((castle.getSiege().getAttackerClan(player.getClan()) != null) && (value & COND_CAST_ATTACK) != 0)
+        	return true;
+        else if ((castle.getSiege().getDefenderClan(player.getClan()) != null) && (value & COND_CAST_DEFEND) != 0)
+        	return true;
+        else if ((castle.getSiege().getAttackerClan(player.getClan()) == null) && (castle.getSiege().getDefenderClan(player.getClan()) == null) && (value & COND_CAST_NEUTRAL) != 0)
+        	return true;
+        
+        return false;
+    }
+    
+    public static boolean checkIfOk(L2Character activeChar, Fort fort, int value)
+    {
+        if (activeChar == null || !(activeChar instanceof L2PcInstance))
+            return false;
+
+        L2PcInstance player = (L2PcInstance)activeChar;
+
+        if ((fort == null || fort.getFortId() <= 0))
+        {
+        	if ((value & COND_NOT_ZONE) != 0)
+        		return true;
+        }
+        else if (!fort.getSiege().getIsInProgress())
+        {
+        	if ((value & COND_NOT_ZONE) != 0)
+        		return true;
+        }
+        else if ((fort.getSiege().getAttackerClan(player.getClan()) != null) && (value & COND_FORT_ATTACK) != 0)
+        	return true;
+        else if ((fort.getOwnerClan() == player.getClan()) && (value & COND_FORT_DEFEND) != 0)
+        	return true;
+        else if ((fort.getSiege().getAttackerClan(player.getClan()) == null) && (fort.getOwnerClan() != player.getClan()) && (value & COND_FORT_NEUTRAL) != 0)
+        	return true;
+        
+        return false;
+    }
+    
+}

+ 56 - 2
L2_GameServer/java/net/sf/l2j/gameserver/templates/item/L2Item.java

@@ -21,8 +21,13 @@ import net.sf.l2j.Config;
 import net.sf.l2j.gameserver.model.L2Character;
 import net.sf.l2j.gameserver.model.L2Effect;
 import net.sf.l2j.gameserver.model.L2ItemInstance;
+import net.sf.l2j.gameserver.model.L2Object;
 import net.sf.l2j.gameserver.model.L2Skill;
+import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
+import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
+import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.skills.Env;
+import net.sf.l2j.gameserver.skills.conditions.Condition;
 import net.sf.l2j.gameserver.skills.effects.EffectTemplate;
 import net.sf.l2j.gameserver.skills.funcs.Func;
 import net.sf.l2j.gameserver.skills.funcs.FuncTemplate;
@@ -155,6 +160,7 @@ public abstract class L2Item
 	protected FuncTemplate[] _funcTemplates;
 	protected EffectTemplate[] _effectTemplates;
 	protected L2Skill[] _skills;
+	protected List <Condition> _preConditions = new FastList<Condition>();
 	
 	private static final Func[] _emptyFunctionSet = new Func[0];
 	protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
@@ -532,7 +538,7 @@ public abstract class L2Item
 	 * @param caster : L2Character pointing out the caster
 	 * @param target : L2Character pointing out the target
 	 * @return L2Effect[] : array of effects generated by the skill
-	 */
+	 
 	public L2Effect[] getSkillEffects(L2Character caster, L2Character target)
 	{
 		if (_skills == null)
@@ -553,7 +559,7 @@ public abstract class L2Item
 			return _emptyEffectSet;
 		return effects.toArray(new L2Effect[effects.size()]);
 	}
-	
+	*/
 	/**
 	 * Add the FuncTemplate f to the list of functions used with the item
 	 * @param f : FuncTemplate to add
@@ -630,6 +636,54 @@ public abstract class L2Item
 		}
 	}
 	
+    public final void attach(Condition c)
+    {
+    	if (!_preConditions.contains(c))
+    		_preConditions.add(c);
+    }
+    
+    public final L2Skill[] getItemSkills()
+    {
+    	return _skills;
+    }
+    
+    public boolean checkCondition(L2Character activeChar, L2Object target)
+    {
+    	if (activeChar.isGM() && !Config.GM_ITEM_RESTRICTION)
+    		return true;
+    	for (Condition preCondition : _preConditions)
+    	{
+	        if (preCondition == null) return true;
+	
+	        Env env = new Env();
+	        env.player = activeChar;
+	        if (target instanceof L2Character) // TODO: object or char?
+	        	env.target = (L2Character)target;
+	
+	        if (!preCondition.test(env))
+	        {
+	        	if (activeChar instanceof L2SummonInstance)
+	        	{
+	        		((L2SummonInstance)activeChar).getOwner().sendPacket(new SystemMessage(SystemMessageId.PET_CANNOT_USE_ITEM));
+	        		return false;
+	        	}
+	            String msg = preCondition.getMessage();
+	            int msgId = preCondition.getMessageId();
+	            
+	            if (msg != null)
+	            {
+	                activeChar.sendMessage(msg);
+	            }
+	            else if (msgId !=0)
+	            {
+	            	activeChar.sendPacket(new SystemMessage(msgId));
+	            }
+	            return false;
+	        }
+    	}
+        return true;
+    }
+	
 	/**
 	 * Returns the name of the item
 	 * @return String