Ver código fonte

BETA: Support for Totem items
- Also added new player condition called: insideZoneId="id, id, id" params are zone ids returns true if the caster is on at least 1 of specified ids

Rumen Nikiforov 13 anos atrás
pai
commit
b56dd0e188

+ 1 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Object.java

@@ -165,6 +165,7 @@ public abstract class L2Object
 		L2RaceManagerInstance(L2Npc),
 		L2SymbolMakerInstance(L2Npc),
 		L2TeleporterInstance(L2Npc),
+		L2TotemInstance(L2NpcInstance),
 		L2TownPetInstance(L2Npc),
 		L2TrainerInstance(L2NpcInstance),
 		L2TrainerHealersInstance(L2TrainerInstance),

+ 101 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2TotemInstance.java

@@ -0,0 +1,101 @@
+/*
+ * 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.l2jserver.gameserver.model.actor.instance;
+
+import java.util.Collection;
+import java.util.concurrent.ScheduledFuture;
+
+import com.l2jserver.gameserver.ThreadPoolManager;
+import com.l2jserver.gameserver.datatables.SkillTable;
+import com.l2jserver.gameserver.model.L2Object;
+import com.l2jserver.gameserver.model.L2Skill;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.L2Npc;
+import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
+import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
+
+/**
+ * @author UnAfraid
+ *
+ */
+public class L2TotemInstance extends L2Npc
+{
+	private ScheduledFuture<?> _aiTask;
+	private final L2Skill _skill;
+	
+	private class TotemAI implements Runnable
+	{
+		private final L2TotemInstance _caster;
+		
+		protected TotemAI(L2TotemInstance caster)
+		{
+			_caster = caster;
+		}
+		
+		@Override
+		public void run()
+		{
+			if (_skill == null)
+			{
+				_caster._aiTask.cancel(false);
+				_caster._aiTask = null;
+				return;
+			}
+			
+			Collection<L2PcInstance> plrs = getKnownList().getKnownPlayersInRadius(_skill.getSkillRadius());
+			for (L2PcInstance player : plrs)
+			{
+				if (player.getFirstEffect(_skill.getId()) == null)
+				{
+					_skill.getEffects(player, player);
+				}
+			}
+		}
+	}
+	
+	public L2TotemInstance(int objectId, L2NpcTemplate template, int skillId)
+	{
+		super(objectId, template);
+		setInstanceType(InstanceType.L2TotemInstance);
+		_skill = SkillTable.getInstance().getInfo(skillId, 1);
+		_aiTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new TotemAI(this), 3000, 3000);
+	}
+	
+	@Override
+	public void deleteMe()
+	{
+		if (_aiTask != null)
+			_aiTask.cancel(true);
+		super.deleteMe();
+	}
+	
+	@Override
+	public int getDistanceToWatchObject(L2Object object)
+	{
+		return 900;
+	}
+	
+	@Override
+	public boolean isAutoAttackable(L2Character attacker)
+	{
+		return false;
+	}
+	
+	@Override
+	public void onAction(L2PcInstance player, boolean interact)
+	{
+		player.sendPacket(ActionFailed.STATIC_PACKET);
+	}
+}

+ 10 - 10
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2XmassTreeInstance.java

@@ -35,10 +35,10 @@ public class L2XmassTreeInstance extends L2Npc
 	public static final int SPECIAL_TREE_ID = 13007;
 	private ScheduledFuture<?> _aiTask;
 	
-	class XmassAI implements Runnable
+	private final class XmassAI implements Runnable
 	{
-		private L2XmassTreeInstance _caster;
-		private L2Skill _skill;
+		private final L2XmassTreeInstance _caster;
+		private final L2Skill _skill;
 		
 		protected XmassAI(L2XmassTreeInstance caster, L2Skill skill)
 		{
@@ -46,6 +46,7 @@ public class L2XmassTreeInstance extends L2Npc
 			_skill = skill;
 		}
 		
+		@Override
 		public void run()
 		{
 			if (_skill == null || _caster.isInsideZone(ZONE_PEACE))
@@ -54,10 +55,15 @@ public class L2XmassTreeInstance extends L2Npc
 				_caster._aiTask = null;
 				return;
 			}
-			Collection<L2PcInstance> plrs = getKnownList().getKnownPlayersInRadius(200);
+			
+			Collection<L2PcInstance> plrs = getKnownList().getKnownPlayersInRadius(_skill.getSkillRadius());
 			for (L2PcInstance player : plrs)
+			{
 				if (player.getFirstEffect(_skill.getId()) == null)
+				{
 					_skill.getEffects(player, player);
+				}
+			}
 		}
 	}
 	
@@ -83,18 +89,12 @@ public class L2XmassTreeInstance extends L2Npc
 		return 900;
 	}
 	
-	/* (non-Javadoc)
-	 * @see com.l2jserver.gameserver.model.L2Object#isAttackable()
-	 */
 	@Override
 	public boolean isAutoAttackable(L2Character attacker)
 	{
 		return false;
 	}
 	
-	/**
-	 * @see com.l2jserver.gameserver.model.actor.L2Npc#onAction(com.l2jserver.gameserver.model.actor.instance.L2PcInstance, boolean)
-	 */
 	@Override
 	public void onAction(L2PcInstance player, boolean interact)
 	{

+ 13 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/skills/DocumentBase.java

@@ -63,6 +63,7 @@ import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHasClanHall;
 import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHasFort;
 import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHasPet;
 import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHp;
+import com.l2jserver.gameserver.skills.conditions.ConditionPlayerInsideZoneId;
 import com.l2jserver.gameserver.skills.conditions.ConditionPlayerInstanceId;
 import com.l2jserver.gameserver.skills.conditions.ConditionPlayerInvSize;
 import com.l2jserver.gameserver.skills.conditions.ConditionPlayerIsClanLeader;
@@ -123,7 +124,7 @@ abstract class DocumentBase
 {
 	static Logger _log = Logger.getLogger(DocumentBase.class.getName());
 	
-	private File _file;
+	private final File _file;
 	protected Map<String, String[]> _tables;
 	
 	DocumentBase(File pFile)
@@ -769,6 +770,17 @@ abstract class DocumentBase
 			{
 				cond = joinAnd(cond, new ConditionPlayerCanSweep(Boolean.valueOf(a.getNodeValue())));
 			}
+			else if ("insideZoneId".equalsIgnoreCase(a.getNodeName()))
+			{
+				StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
+				ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
+				while (st.hasMoreTokens())
+				{
+					String item = st.nextToken().trim();
+					array.add(Integer.decode(getValue(item, null)));
+				}
+				cond = joinAnd(cond, new ConditionPlayerInsideZoneId(array));
+			}
 		}
 		
 		if (forces[0] + forces[1] > 0)

+ 50 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/skills/conditions/ConditionPlayerInsideZoneId.java

@@ -0,0 +1,50 @@
+/*
+ * 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.l2jserver.gameserver.skills.conditions;
+
+import java.util.ArrayList;
+
+import com.l2jserver.gameserver.instancemanager.ZoneManager;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.model.zone.L2ZoneType;
+import com.l2jserver.gameserver.skills.Env;
+
+/**
+ * @author UnAfraid
+ *
+ */
+public class ConditionPlayerInsideZoneId extends Condition
+{
+	private final ArrayList<Integer> _zones;
+	
+	public ConditionPlayerInsideZoneId(ArrayList<Integer> zones)
+	{
+		_zones = zones;
+	}
+	
+	@Override
+	public boolean testImpl(Env env)
+	{
+		if (!(env.player instanceof L2PcInstance))
+			return false;
+		
+		for (L2ZoneType zone : ZoneManager.getInstance().getZones(env.player))
+		{
+			if (_zones.contains(zone.getId()))
+				return true;
+		}
+		return false;
+	}
+}

+ 14 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/skills/l2skills/L2SkillSpawn.java

@@ -22,6 +22,7 @@ import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.L2Npc;
 import com.l2jserver.gameserver.model.actor.instance.L2BirthdayCakeInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
+import com.l2jserver.gameserver.model.actor.instance.L2TotemInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2XmassTreeInstance;
 import com.l2jserver.gameserver.templates.StatsSet;
 import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
@@ -33,6 +34,7 @@ public class L2SkillSpawn extends L2Skill
 	private final int _despawnDelay;
 	private final boolean _summonSpawn;
 	private final boolean _randomOffset;
+	private final int _skillToCast;
 	
 	public L2SkillSpawn(StatsSet set)
 	{
@@ -41,6 +43,7 @@ public class L2SkillSpawn extends L2Skill
 		_despawnDelay = set.getInteger("despawnDelay", 0);
 		_summonSpawn = set.getBool("isSummonSpawn", false);
 		_randomOffset = set.getBool("randomOffset", true);
+		_skillToCast = set.getInteger("skillToCast", 0);
 	}
 	
 	@Override
@@ -53,7 +56,7 @@ public class L2SkillSpawn extends L2Skill
 		
 		if (_npcId == 0)
 		{
-			_log.warning("NPC ID not defined for skill ID:"+this.getId());
+			_log.warning("NPC ID not defined for skill ID:" + getId());
 			return;
 		}
 		
@@ -61,7 +64,7 @@ public class L2SkillSpawn extends L2Skill
 		final L2NpcTemplate template = NpcTable.getInstance().getTemplate(_npcId);
 		if (template == null)
 		{
-			_log.warning("Spawn of the nonexisting NPC ID:"+_npcId+", skill ID:"+this.getId());
+			_log.warning("Spawn of the nonexisting NPC ID:" + _npcId + ", skill ID:" + getId());
 			return;
 		}
 		
@@ -69,9 +72,13 @@ public class L2SkillSpawn extends L2Skill
 			npc = new L2XmassTreeInstance(IdFactory.getInstance().getNextId(), template);
 		else if (template.type.equalsIgnoreCase("L2BirthdayCake"))
 			npc = new L2BirthdayCakeInstance(IdFactory.getInstance().getNextId(), template, caster.getObjectId());
-		/* TODO
-		else if (template.type.equalsIgnoreCase("L2WeddingCake"))
-			npc = new L2WeddingCakeInstance(IdFactory.getInstance().getNextId(), template);*/
+		else if (template.type.equalsIgnoreCase("L2Totem"))
+			npc = new L2TotemInstance(IdFactory.getInstance().getNextId(), template, _skillToCast);
+		/*
+		 * TODO
+		 * else if (template.type.equalsIgnoreCase("L2WeddingCake"))
+		 * npc = new L2WeddingCakeInstance(IdFactory.getInstance().getNextId(), template);
+		 */
 		else
 			npc = new L2NpcInstance(IdFactory.getInstance().getNextId(), template);
 		
@@ -90,9 +97,9 @@ public class L2SkillSpawn extends L2Skill
 			x = caster.getX();
 			y = caster.getY();
 		}
-
+		
 		npc.spawnMe(x, y, caster.getZ() + 20);
 		if (_despawnDelay > 0)
 			npc.scheduleDespawn(_despawnDelay);
 	}
-}
+}