Przeglądaj źródła

Updated RecipeController handling by Benurb and some cleanup.

GodKratos 16 lat temu
rodzic
commit
e4287079e4

+ 15 - 82
L2_GameServer/java/net/sf/l2j/gameserver/RecipeController.java

@@ -98,33 +98,28 @@ public class RecipeController
 	{
 		return _lists.get(listId);
 	}
-
+	
 	public L2RecipeList getRecipeByItemId(int itemId)
 	{
-		for (int i = 0; i < _lists.size(); i++)
+		for (L2RecipeList find : _lists.values())
 		{
-			L2RecipeList find = _lists.get(new Integer(i));
 			if (find.getRecipeId() == itemId)
-			{
 				return find;
-			}
 		}
 		return null;
 	}
-	
-    public L2RecipeList getRecipeById(int recId)
-    {
-        for (int i = 0; i < _lists.size(); i++)
-        {
-            L2RecipeList find = _lists.get(new Integer(i));
-            if (find.getId() == recId)
-            {
-                return find;
-            }
-        }
-        return null;
-    }
 
+	public int[] getAllItemIds()
+	{
+		int[] idList = new int[_lists.size()];
+		int i = 0;
+		for (L2RecipeList rec: _lists.values())
+		{
+			idList[i++] = rec.getRecipeId();
+		}
+		return idList;
+	}
+	
 	public synchronized void requestBookOpen(L2PcInstance player, boolean isDwarvenCraft)
 	{
 		RecipeItemMaker maker = null;
@@ -231,68 +226,6 @@ public class RecipeController
 		}
 	}
 
-	//TODO XMLize the recipe list
-	/*private void parseList(String line)
-	{
-		try
-		{
-			StringTokenizer st = new StringTokenizer(line, ";");
-			List<L2RecipeInstance> recipePartList = new FastList<L2RecipeInstance>();
-
-			//we use common/dwarf for easy reading of the recipes.csv file
-			String recipeTypeString = st.nextToken();
-
-			// now parse the string into a boolean
-			boolean isDwarvenRecipe;
-
-			if (recipeTypeString.equalsIgnoreCase("dwarven")) isDwarvenRecipe = true;
-			else if (recipeTypeString.equalsIgnoreCase("common")) isDwarvenRecipe = false;
-			else
-			{ //prints a helpfull message
-				_log.warning("Error parsing recipes.csv, unknown recipe type " + recipeTypeString);
-				return;
-			}
-
-			String recipeName = st.nextToken();
-			int id = Integer.parseInt(st.nextToken());
-			int recipeId = Integer.parseInt(st.nextToken());
-			int level = Integer.parseInt(st.nextToken());
-
-			//material
-			StringTokenizer st2 = new StringTokenizer(st.nextToken(), "[],");
-			while (st2.hasMoreTokens())
-			{
-				StringTokenizer st3 = new StringTokenizer(st2.nextToken(), "()");
-				int rpItemId = Integer.parseInt(st3.nextToken());
-				int quantity = Integer.parseInt(st3.nextToken());
-				L2RecipeInstance rp = new L2RecipeInstance(rpItemId, quantity);
-				recipePartList.add(rp);
-			}
-
-			int itemId = Integer.parseInt(st.nextToken());
-			int count = Integer.parseInt(st.nextToken());
-
-			//npc fee
-			//String notdoneyet = 
-            st.nextToken();
-
-			int mpCost = Integer.parseInt(st.nextToken());
-			int successRate = Integer.parseInt(st.nextToken());
-
-			L2RecipeList recipeList = new L2RecipeList(id, level, recipeId, recipeName, successRate,
-			                                           mpCost, itemId, count, isDwarvenRecipe);
-			for (L2RecipeInstance recipePart : recipePartList)
-			{
-				recipeList.addRecipe(recipePart);
-			}
-			_lists.put(new Integer(_lists.size()), recipeList);
-		}
-		catch (Exception e)
-		{
-			_log.severe("Exception in RecipeController.parseList() - " + e);
-		}
-	}*/
-    
     private void loadFromXML() throws SAXException, IOException, ParserConfigurationException
     {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -455,7 +388,7 @@ public class RecipeController
                                 recipeList.addAltStatChange(recipeAltStatChange);
                             }
 
-                            _lists.put(_lists.size(), recipeList);
+                            _lists.put(id, recipeList);
                         }
                     }
                 }
@@ -1072,7 +1005,7 @@ public class RecipeController
 
 	private L2RecipeList getValidRecipeList(L2PcInstance player, int id)
 	{
-		L2RecipeList recipeList = getRecipeList(id - 1);
+		L2RecipeList recipeList = getRecipeList(id);
 
 		if ((recipeList == null) || (recipeList.getRecipes().length == 0))
 		{

+ 1 - 6
L2_GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Recipes.java

@@ -35,12 +35,7 @@ public class Recipes implements IItemHandler
 	
 	public Recipes()
 	{
-		RecipeController rc = RecipeController.getInstance();
-		ITEM_IDS = new int[rc.getRecipesCount()];
-		for (int i = 0; i < rc.getRecipesCount(); i++)
-		{
-			ITEM_IDS[i] = rc.getRecipeList(i).getRecipeId();
-		}
+		ITEM_IDS = RecipeController.getInstance().getAllItemIds();
 	}
 	
 	/**

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

@@ -33,7 +33,7 @@ public class L2ManufactureItem
         _recipeId = recipeId;
         _cost = cost;
 
-        _isDwarven = RecipeController.getInstance().getRecipeById(_recipeId).isDwarvenRecipe();
+        _isDwarven = RecipeController.getInstance().getRecipeList(_recipeId).isDwarvenRecipe();
     }
 
     public int getRecipeId()

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

@@ -6928,7 +6928,7 @@ public final class L2PcInstance extends L2PlayableInstance
 
 			L2RecipeList recipe;
 			while (rset.next()) {
-				recipe = RecipeController.getInstance().getRecipeList(rset.getInt("id") - 1);
+				recipe = RecipeController.getInstance().getRecipeList(rset.getInt("id"));
 
 				if (rset.getInt("type") == 1)
 					registerDwarvenRecipeList(recipe);

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

@@ -42,7 +42,7 @@ public final class RequestRecipeBookDestroy extends L2GameClientPacket
         L2PcInstance activeChar = getClient().getActiveChar();
         if (activeChar != null)
         {
-        	L2RecipeList rp = RecipeController.getInstance().getRecipeList(_recipeID-1);
+        	L2RecipeList rp = RecipeController.getInstance().getRecipeList(_recipeID);
          	if (rp == null)
          		return;
             activeChar.unregisterRecipeList(_recipeID);

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

@@ -55,7 +55,7 @@ public class RecipeItemMakeInfo extends L2GameServerPacket
     @Override
 	protected final void writeImpl()
     {
-        L2RecipeList recipe = RecipeController.getInstance().getRecipeById(_id);
+        L2RecipeList recipe = RecipeController.getInstance().getRecipeList(_id);
 
         if (recipe != null)
         {