Pārlūkot izejas kodu

BETA: Unhardcoded and Improved Fishing Monsters by '''nonom'''.

MELERIX 13 gadi atpakaļ
vecāks
revīzija
3328d4698f

+ 2 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/GameServer.java

@@ -49,6 +49,7 @@ import com.l2jserver.gameserver.datatables.EnchantItemData;
 import com.l2jserver.gameserver.datatables.EventDroplist;
 import com.l2jserver.gameserver.datatables.ExperienceTable;
 import com.l2jserver.gameserver.datatables.FishData;
+import com.l2jserver.gameserver.datatables.FishingMonstersData;
 import com.l2jserver.gameserver.datatables.FishingRodsData;
 import com.l2jserver.gameserver.datatables.HelperBuffTable;
 import com.l2jserver.gameserver.datatables.HennaData;
@@ -230,6 +231,7 @@ public class GameServer
 		RecipeData.getInstance();
 		ArmorSetsData.getInstance();
 		FishData.getInstance();
+		FishingMonstersData.getInstance();
 		FishingRodsData.getInstance();
 		HennaData.getInstance();
 		

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/FishData.java

@@ -50,7 +50,7 @@ public final class FishData extends DocumentParser
 		_fishEasy.clear();
 		_fishNormal.clear();
 		_fishHard.clear();
-		parseDatapackFile("data/stats/items/fishing/fishes.xml");
+		parseDatapackFile("data/stats/fishing/fishes.xml");
 		_log.info(getClass().getSimpleName() + ": Loaded " + (_fishEasy.size() + _fishNormal.size() + _fishHard.size()) + " Fishes.");
 	}
 	

+ 113 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/FishingMonstersData.java

@@ -0,0 +1,113 @@
+/*
+ * 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.datatables;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import com.l2jserver.gameserver.engines.DocumentParser;
+import com.l2jserver.gameserver.model.StatsSet;
+import com.l2jserver.gameserver.model.fishing.L2FishingMonster;
+
+/**
+ * This class holds the Fishing Monsters information.
+ * @author nonom
+ */
+public final class FishingMonstersData extends DocumentParser
+{
+	private static final Map<Integer, L2FishingMonster> _FishingMonsterData = new HashMap<>();
+	
+	/**
+	 * Instantiates a new fishing monster data.
+	 */
+	protected FishingMonstersData()
+	{
+		load();
+	}
+	
+	@Override
+	public void load()
+	{
+		_FishingMonsterData.clear();
+		parseDatapackFile("data/stats/fishing/FishingMonsters.xml");
+		_log.info(getClass().getSimpleName() + ": Loaded " + _FishingMonsterData.size() + " Fishing Monsters.");
+	}
+	
+	@Override
+	protected void parseDocument()
+	{
+		NamedNodeMap attrs;
+		Node att;
+		L2FishingMonster fishingMonster;
+		StatsSet set;
+		for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
+		{
+			if ("list".equalsIgnoreCase(n.getNodeName()))
+			{
+				for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
+				{
+					if ("fishingMonster".equalsIgnoreCase(d.getNodeName()))
+					{
+						
+						attrs = d.getAttributes();
+						
+						set = new StatsSet();
+						for (int i = 0; i < attrs.getLength(); i++)
+						{
+							att = attrs.item(i);
+							set.set(att.getNodeName(), att.getNodeValue());
+						}
+						fishingMonster = new L2FishingMonster(set);
+						_FishingMonsterData.put(fishingMonster.getFishingMonsterId(), fishingMonster);
+					}
+				}
+			}
+		}
+	}
+	
+	/**
+	 * Gets the fishing monster.
+	 * @param lvl the fisher lvl
+	 * @return A fishing monster by fisher lvl
+	 */
+	public L2FishingMonster getFishingMonster(int lvl)
+	{
+		for (Map.Entry<Integer, L2FishingMonster> fishingMonster : _FishingMonsterData.entrySet())
+		{
+			if ((lvl >= fishingMonster.getValue().getUserMinLevel()) && (lvl <= fishingMonster.getValue().getUserMaxLevel()))
+			{
+				return fishingMonster.getValue();
+			}
+		}
+		return null;
+	}
+	
+	/**
+	 * Gets the single instance of FishingMonsterData.
+	 * @return single instance of FishingMonsterData
+	 */
+	public static FishingMonstersData getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	private static class SingletonHolder
+	{
+		protected static final FishingMonstersData _instance = new FishingMonstersData();
+	}
+}

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/FishingRodsData.java

@@ -44,7 +44,7 @@ public final class FishingRodsData extends DocumentParser
 	public void load()
 	{
 		_fishingRods.clear();
-		parseDatapackFile("data/stats/items/fishing/fishingRods.xml");
+		parseDatapackFile("data/stats/fishing/fishingRods.xml");
 		_log.info(getClass().getSimpleName() + ": Loaded " + _fishingRods.size() + " Fishing Rods.");
 	}
 	

+ 13 - 46
L2J_Server_BETA/java/com/l2jserver/gameserver/model/fishing/L2Fishing.java

@@ -17,6 +17,7 @@ package com.l2jserver.gameserver.model.fishing;
 import java.util.concurrent.Future;
 
 import com.l2jserver.gameserver.ThreadPoolManager;
+import com.l2jserver.gameserver.datatables.FishingMonstersData;
 import com.l2jserver.gameserver.datatables.NpcTable;
 import com.l2jserver.gameserver.model.L2Spawn;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
@@ -147,10 +148,15 @@ public class L2Fishing implements Runnable
 		
 		if (win)
 		{
-			int check = Rnd.get(100);
-			if (check <= 5)
+			int lvl = _fisher.getLevel();
+			L2NpcTemplate monster;
+			L2FishingMonster fishingMonster = FishingMonstersData.getInstance().getFishingMonster(lvl);
+			
+			if (Rnd.get(100) <= fishingMonster.getProbability())
 			{
-				PenaltyMonster();
+				monster = NpcTable.getInstance().getTemplate(fishingMonster.getFishingMonsterId());
+				_fisher.sendPacket(SystemMessageId.YOU_CAUGHT_SOMETHING_SMELLY_THROW_IT_BACK);
+				spawnMonster(monster);
 			}
 			else
 			{
@@ -364,55 +370,16 @@ public class L2Fishing implements Runnable
 		}
 	}
 	
-	private void PenaltyMonster()
+	private void spawnMonster(L2NpcTemplate monster)
 	{
-		int lvl = (int) Math.round(_fisher.getLevel() * 0.1);
-		
-		int npcid;
-		
-		_fisher.sendPacket(SystemMessageId.YOU_CAUGHT_SOMETHING_SMELLY_THROW_IT_BACK);
-		switch (lvl)
-		{
-			case 0:
-			case 1:
-				npcid = 18319;
-				break;
-			case 2:
-				npcid = 18320;
-				break;
-			case 3:
-				npcid = 18321;
-				break;
-			case 4:
-				npcid = 18322;
-				break;
-			case 5:
-				npcid = 18323;
-				break;
-			case 6:
-				npcid = 18324;
-				break;
-			case 7:
-				npcid = 18325;
-				break;
-			case 8:
-			case 9:
-				npcid = 18326;
-				break;
-			default:
-				npcid = 18319;
-				break;
-		}
-		L2NpcTemplate temp;
-		temp = NpcTable.getInstance().getTemplate(npcid);
-		if (temp != null)
+		if (monster != null)
 		{
 			try
 			{
-				L2Spawn spawn = new L2Spawn(temp);
+				L2Spawn spawn = new L2Spawn(monster);
 				spawn.setLocx(_fisher.getX());
 				spawn.setLocy(_fisher.getY());
-				spawn.setLocz(_fisher.getZ() + 20);
+				spawn.setLocz(_fisher.getZ());
 				spawn.setAmount(1);
 				spawn.setHeading(_fisher.getHeading());
 				spawn.stopRespawn();

+ 69 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/fishing/L2FishingMonster.java

@@ -0,0 +1,69 @@
+/*
+ * 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.fishing;
+
+import com.l2jserver.gameserver.model.StatsSet;
+
+/**
+ * Class for the Fishing Monsters object.
+ * @author nonom
+ */
+public class L2FishingMonster
+{
+	private final int _userMinLevel;
+	private final int _userMaxLevel;
+	private final int _fishingMonsterId;
+	private final int _probability;
+	
+	public L2FishingMonster(StatsSet set)
+	{
+		_userMinLevel = set.getInteger("userMinLevel");
+		_userMaxLevel = set.getInteger("userMaxLevel");
+		_fishingMonsterId = set.getInteger("fishingMonsterId");
+		_probability = set.getInteger("probability");
+	}
+	
+	/**
+	 * @return the minimum user level.
+	 */
+	public int getUserMinLevel()
+	{
+		return _userMinLevel;
+	}
+	
+	/**
+	 * @return the maximum user level.
+	 */
+	public int getUserMaxLevel()
+	{
+		return _userMaxLevel;
+	}
+	
+	/**
+	 * @return the fishing monster Id.
+	 */
+	public int getFishingMonsterId()
+	{
+		return _fishingMonsterId;
+	}
+	
+	/**
+	 * @return the probability.
+	 */
+	public int getProbability()
+	{
+		return _probability;
+	}
+}