Jump to content
  • 0

Having more than 1 Masterwork option on 1 item


Question

Posted (edited)

Hello, I want to add an option to have the chance of 2 different masterwork items when crafting something (for example when crafting Vesper Helmet having the chance of getting the normal item, the masterwork item and the chance of getting a custom masterwork one)

Something like this:

 

Spoiler
<item id="954" recipeId="15792" name="mk_sealed_vesper_helmet" craftLevel="10" type="dwarven" successRate="60">
        <ingredient id="15792" count="1" />
        <production id="Vesper Helmet" count="1" />
        <productionRare id="Vesper Helmet Foundation" count="1" rarity="8" />
  		<productionRare2 id="Custom Vesper Helmet Foundation" count="1" rarity="4" />
        <statUse name="MP" value="252" />
    </item>

 

 

I don't know much about java but I've made things by looking at others stuff that works similar and copying/adapting, this is what my RecipeData.java looks like:

 

Spoiler
@Override
	public void parseDocument(Document doc)
	{
		// TODO: Cleanup checks enforced by XSD.
		final List<L2RecipeInstance> recipePartList = new ArrayList<>();
		final List<L2RecipeStatInstance> recipeStatUseList = new ArrayList<>();
		final List<L2RecipeStatInstance> recipeAltStatChangeList = new ArrayList<>();
		for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
		{
			if ("list".equalsIgnoreCase(n.getNodeName()))
			{
				RECIPES_FILE:
				for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
				{
					if ("item".equalsIgnoreCase(d.getNodeName()))
					{
						recipePartList.clear();
						recipeStatUseList.clear();
						recipeAltStatChangeList.clear();
						NamedNodeMap attrs = d.getAttributes();
						Node att;
						int id = -1;
						boolean haveRare = false;
						boolean haveRare2 = false;
						boolean haveRare3 = false;
						StatsSet set = new StatsSet();
						
						att = attrs.getNamedItem("id");
						if (att == null)
						{
							LOG.error("{}: Missing id for recipe item, skipping!", getClass().getSimpleName());
							continue;
						}
						id = Integer.parseInt(att.getNodeValue());
						set.set("id", id);
						
						att = attrs.getNamedItem("recipeId");
						if (att == null)
						{
							LOG.error("{}: Missing recipeId for recipe item ID: {}, skipping!", getClass().getSimpleName(), id);
							continue;
						}
						set.set("recipeId", Integer.parseInt(att.getNodeValue()));
						
						att = attrs.getNamedItem("name");
						if (att == null)
						{
							LOG.error("{}: Missing name for recipe item ID: {}, skipping!", getClass().getSimpleName(), id);
							continue;
						}
						set.set("recipeName", att.getNodeValue());
						
						att = attrs.getNamedItem("craftLevel");
						if (att == null)
						{
							LOG.error("{}: Missing level for recipe item ID: {}, skipping!", getClass().getSimpleName(), id);
							continue;
						}
						set.set("craftLevel", Integer.parseInt(att.getNodeValue()));
						
						att = attrs.getNamedItem("type");
						if (att == null)
						{
							LOG.error("{}: Missing type for recipe item ID: {}, skipping!", getClass().getSimpleName(), id);
							continue;
						}
						set.set("isDwarvenRecipe", att.getNodeValue().equalsIgnoreCase("dwarven"));
						
						att = attrs.getNamedItem("successRate");
						if (att == null)
						{
							LOG.error("{}: Missing successRate for recipe item ID: {}, skipping!", getClass().getSimpleName(), id);
							continue;
						}
						set.set("successRate", Integer.parseInt(att.getNodeValue()));
						
						for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
						{
							if ("statUse".equalsIgnoreCase(c.getNodeName()))
							{
								String statName = c.getAttributes().getNamedItem("name").getNodeValue();
								int value = Integer.parseInt(c.getAttributes().getNamedItem("value").getNodeValue());
								try
								{
									recipeStatUseList.add(new L2RecipeStatInstance(statName, value));
								}
								catch (Exception e)
								{
									LOG.error("{}: Error in StatUse parameter for recipe item ID: {}, skipping!", getClass().getSimpleName(), id);
									continue RECIPES_FILE;
								}
							}
							else if ("altStatChange".equalsIgnoreCase(c.getNodeName()))
							{
								String statName = c.getAttributes().getNamedItem("name").getNodeValue();
								int value = Integer.parseInt(c.getAttributes().getNamedItem("value").getNodeValue());
								try
								{
									recipeAltStatChangeList.add(new L2RecipeStatInstance(statName, value));
								}
								catch (Exception e)
								{
									LOG.error("{}: Error in AltStatChange parameter for recipe item ID: {}, skipping!", getClass().getSimpleName(), id);
									continue RECIPES_FILE;
								}
							}
							else if ("ingredient".equalsIgnoreCase(c.getNodeName()))
							{
								int ingId = Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue());
								int ingCount = Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue());
								recipePartList.add(new L2RecipeInstance(ingId, ingCount));
							}
							else if ("production".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("itemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
								set.set("count", Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue()));
							}
							else if ("productionRare".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("rareItemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
								set.set("rareCount", Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue()));
								set.set("rarity", Integer.parseInt(c.getAttributes().getNamedItem("rarity").getNodeValue()));
								haveRare = true;
							}
							else if ("productionRare2".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("rareItemId2", Integer.parseInt(c.getAttributes().getNamedItem("id2").getNodeValue()));
								set.set("rareCount", Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue()));
								set.set("rarity2", Integer.parseInt(c.getAttributes().getNamedItem("rarity2").getNodeValue()));
								haveRare = true;
							}
						}
						
						L2RecipeList recipeList = new L2RecipeList(set, haveRare);
						for (L2RecipeInstance recipePart : recipePartList)
						{
							recipeList.addRecipe(recipePart);
						}
						for (L2RecipeStatInstance recipeStatUse : recipeStatUseList)
						{
							recipeList.addStatUse(recipeStatUse);
						}
						for (L2RecipeStatInstance recipeAltStatChange : recipeAltStatChangeList)
						{
							recipeList.addAltStatChange(recipeAltStatChange);
						}
						
						_recipes.put(id, recipeList);
					}
				}
			}
		}
	}

 


But when I start the server I get the error on the pic


Any ideas of what is wrong?


 

image.png

Edited by Kyboi

8 answers to this question

Recommended Posts

  • 0
Posted

To fix your error, edit your xml as such:

<item id="954" recipeId="15792" name="mk_sealed_vesper_helmet" craftLevel="10" type="dwarven" successRate="60">
        <ingredient id="15792" count="1" />
        <production id="Vesper Helmet" count="1" />
        <productionRare id="Vesper Helmet Foundation" count="1" rarity="8" />
  		<productionRare2 id2="Custom Vesper Helmet Foundation" count="1" rarity2="4" />
        <statUse name="MP" value="252" />
    </item>

 

However, this code you posted is incomplete and it will just read the data but never use it. You need to modify the logic when the player presses 'Buy' to calculate which item will be given to the player based on rarity.

  • 0
Posted
1 hour ago, An4rchy said:

To fix your error, edit your xml as such:

<item id="954" recipeId="15792" name="mk_sealed_vesper_helmet" craftLevel="10" type="dwarven" successRate="60">
        <ingredient id="15792" count="1" />
        <production id="Vesper Helmet" count="1" />
        <productionRare id="Vesper Helmet Foundation" count="1" rarity="8" />
  		<productionRare2 id2="Custom Vesper Helmet Foundation" count="1" rarity2="4" />
        <statUse name="MP" value="252" />
    </item>

 

However, this code you posted is incomplete and it will just read the data but never use it. You need to modify the logic when the player presses 'Buy' to calculate which item will be given to the player based on rarity.


The error on the console is definitely coming from the core, I tried running the server with no modifications on the xml and xsd and still get the error, and running the xml and xsd modificated but with no modification in the core results in no error but ofc the crafting works like vanilla

The only different scenario is when I modify the xml and xsd to:

 

Spoiler
<productionRare id="135" count="2" rarity="30" />
<productionRare id2="204" count="1" rarity2="30" />
(just for testing)

 

and

Spoiler
<xs:element name="productionRare" minOccurs="0" maxOccurs="1">
	<xs:complexType>
			<xs:attribute name="count" type="xs:positiveInteger" use="required" />
			<xs:attribute name="id" type="xs:positiveInteger" use="required" />
			<xs:attribute name="rarity" type="xs:positiveInteger" use="required" />
	</xs:complexType>
</xs:element>
<xs:element name="productionRare" minOccurs="0" maxOccurs="1">
	<xs:complexType>
		<xs:attribute name="count" type="xs:positiveInteger" use="required" />
		<xs:attribute name="id2" type="xs:positiveInteger" use="required" />
		<xs:attribute name="rarity2" type="xs:positiveInteger" use="required" />
	</xs:complexType>
</xs:element>

 


In which case I get the error for not being able to load the file:

 

[17/05 08:31:24] RecipeData: Could not parse file recipes.xml
java.lang.NullPointerException
        at com.l2jserver.gameserver.data.xml.impl.RecipeData.parseDocument(RecipeData.java:178)
        at com.l2jserver.util.data.xml.IXmlReader.parseDocument(IXmlReader.java:185)
        at com.l2jserver.util.data.xml.IXmlReader.parseFile(IXmlReader.java:89)
        at com.l2jserver.util.data.xml.IXmlReader.parseDatapackFile(IXmlReader.java:63)
        at com.l2jserver.gameserver.data.xml.impl.RecipeData.load(RecipeData.java:57)
        at com.l2jserver.gameserver.data.xml.impl.RecipeData.<init>(RecipeData.java:50)
        at com.l2jserver.gameserver.data.xml.impl.RecipeData$SingletonHolder.<clinit>(RecipeData.java:280)
        at com.l2jserver.gameserver.data.xml.impl.RecipeData.getInstance(RecipeData.java:272)
        at com.l2jserver.gameserver.GameServer.<init>(GameServer.java:228)
        at com.l2jserver.gameserver.GameServer.main(GameServer.java:617)


Which is kinda obvious since "rarity2" and "id2" are not in the core part.

I've been trying duplicating and moving things around in the core but the most I've achieved is that I can get the "second" rare to work, something like if I have recipe for item A, productionRare is B and productionRare2 is C, then A and C work, I haven't been able to make both rares to work at the same time

The problem is that I don't quite understand how the whole system works, and since I don't know much java I'm trying to figure things out by logic but this case isn't as obvious as some other stuff

 

  • 0
Posted (edited)
<productionRare2 id="Custom Vesper Helmet Foundation" count="1" rarity="4" />

 

try like this 

<productionRare2 id2="Custom Vesper Helmet Foundation" count="1" rarity2="4" />

how i know should be like this you ask ? 

 

did you do the java work yourself ?

 

				else if ("productionRare2".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("rareItemId2", Integer.parseInt(c.getAttributes().getNamedItem("id2").getNodeValue()));
								set.set("rareCount", Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue()));
								set.set("rarity2", Integer.parseInt(c.getAttributes().getNamedItem("rarity2").getNodeValue()));
Edited by LoVe+
  • 0
Posted

As An4rchy said, its not enough the 'read' part. You need to edit some other parts too.

Also, i'm wondering....

these lines (the set part):

else if ("production".equalsIgnoreCase(c.getNodeName()))
{
	set.set("itemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
	....
}
else if ("productionRare".equalsIgnoreCase(c.getNodeName()))
{
	set.set("rareItemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
	...
}
else if ("productionRare2".equalsIgnoreCase(c.getNodeName()))
{
	set.set("rareItemId2", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
	...
}

 

They are all parsing a number (Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()))

While they are reading the "id" node value which in your case (even the retail one) are not numeric values

 

id="Vesper Helmet"
id="Vesper Helmet Foundation"
id="Custom Vesper Helmet Foundation"

 

So, either i really can't understand the way the parsing works, or even your retail code is broken.

  • Sad 1
  • 0
Posted

yep .. now wonder how it worked before adding rarity2 even on production there is not int value ..

 

<production id="Vesper Helmet" count="1" />

and it parse int 

 

else if ("production".equalsIgnoreCase(c.getNodeName()))
{
	set.set("itemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
	....
}

this is broken in all possible corner

  • 0
Posted
8 hours ago, LoVe+ said:
<productionRare2 id="Custom Vesper Helmet Foundation" count="1" rarity="4" />

 

try like this 

<productionRare2 id2="Custom Vesper Helmet Foundation" count="1" rarity2="4" />

how i know should be like this you ask ? 

 

did you do the java work yourself ?

 

				else if ("productionRare2".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("rareItemId2", Integer.parseInt(c.getAttributes().getNamedItem("id2").getNodeValue()));
								set.set("rareCount", Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue()));
								set.set("rarity2", Integer.parseInt(c.getAttributes().getNamedItem("rarity2").getNodeValue()));


If I try with that only (only by adding that to RecipeData.java and not modifying L2RecipeController.java and L2RecipeList.java) then I don't get an error but the masterwork system stops working entirely (only base item ID results from the production)

 

 

8 hours ago, melron said:

As An4rchy said, its not enough the 'read' part. You need to edit some other parts too.

Also, i'm wondering....

these lines (the set part):

else if ("production".equalsIgnoreCase(c.getNodeName()))
{
	set.set("itemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
	....
}
else if ("productionRare".equalsIgnoreCase(c.getNodeName()))
{
	set.set("rareItemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
	...
}
else if ("productionRare2".equalsIgnoreCase(c.getNodeName()))
{
	set.set("rareItemId2", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
	...
}

 

They are all parsing a number (Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()))

While they are reading the "id" node value which in your case (even the retail one) are not numeric values

 

id="Vesper Helmet"
id="Vesper Helmet Foundation"
id="Custom Vesper Helmet Foundation"

 

So, either i really can't understand the way the parsing works, or even your retail code is broken.

 

 

Ah that was only for example purposes, I have the proper item IDs on the recipes.xml file (currently using samurai longsword to test):

 

<item id="246" recipeId="2353" name="mk_samurai_longsword" craftLevel="6" type="dwarven" successRate="100">
		<ingredient id="2115" count="11" />
		<ingredient id="1891" count="3" />
		<ingredient id="1890" count="82" />
		<ingredient id="1888" count="41" />
		<ingredient id="5220" count="164" />
		<ingredient id="1459" count="410" />
		<ingredient id="2131" count="248" />
		<production id="135" count="1" />
		<productionRare id="135" count="2" rarity="30" />
		<productionRare2 id2="204" count="1" rarity2="30" />
		<statUse name="MP" value="165" />
	</item>




Maybe the problem is not on RecipeData.java but in one of the other 2 files:

L2RecipeList.java:
 

Spoiler
/**
	 * Constructor of L2RecipeList (create a new Recipe).
	 * @param set
	 * @param haveRare
	 */
	public L2RecipeList(StatsSet set, boolean haveRare)
	{
		_recipes = new L2RecipeInstance[0];
		_statUse = new L2RecipeStatInstance[0];
		_altStatChange = new L2RecipeStatInstance[0];
		_id = set.getInt("id");
		_level = set.getInt("craftLevel");
		_recipeId = set.getInt("recipeId");
		_recipeName = set.getString("recipeName");
		_successRate = set.getInt("successRate");
		_itemId = set.getInt("itemId");
		_count = set.getInt("count");
		if (haveRare)
		{
			_rareItemId = set.getInt("rareItemId");
			_rareCount = set.getInt("rareCount");
			_rarity = set.getInt("rarity");
		}
		_isDwarvenRecipe = set.getBoolean("isDwarvenRecipe");
	}

 


I tried adding it like this:
 

if (haveRare)
		{
			_rareItemId = set.getInt("rareItemId");
			_rareItemId2 = set.getInt("rareItemId2");
			_rareCount = set.getInt("rareCount");
			_rarity = set.getInt("rarity");
			_rarity2 = set.getInt("rarity2");
		}

 

And with that I get the error on the console, I think here is where the problem is (because it points to this line in the console)

 

RecipeController.java:

 

Spoiler
private void rewardPlayer()
		{
			int rareProdId = _recipeList.getRareItemId();
			int itemId = _recipeList.getItemId();
			int itemCount = _recipeList.getCount();
			L2Item template = ItemTable.getInstance().getTemplate(itemId);
			
			// check that the current recipe has a rare production or not
			if ((rareProdId != -1) && ((rareProdId == itemId) || Config.CRAFT_MASTERWORK))
			{
				if (Rnd.get(100) < _recipeList.getRarity())
				{
					itemId = rareProdId;
					itemCount = _recipeList.getRareCount();
				}
			}
			

 

 

I tried by adding stuff here too with no luck, my guess based on the error given by the console is that I have to preperly add the stuff to L2RecipeList so it doesn't return an error and start working from there

  • 0
Posted (edited)
 

 

 

give this one a try  maybe that stands for chance ? 

rarity = 80 chance to get rare

and rarity2 = 40 chance to get masteerwork

 

also you will have to change  Vesper Helmet Vesper Helmet Foundation and Custom Vesper Helmet Foundation to itemId that stands for this names.

<item id="954" recipeId="15792" name="mk_sealed_vesper_helmet" craftLevel="10" type="dwarven" successRate="60">
        <ingredient id="15792" count="1" />
        <production id="== PUT ITEM ID HERE ==" count="1" />
        <productionRare id="== PUT ITEM ID HERE ==" count="1" rarity="80" />
  		<productionRare2 id2="== PUT ITEM ID HERE ==" count="1" rarity2="40" />
        <statUse name="MP" value="252" />
    </item>

 

Edited by LoVe+
  • 0
Posted

I made it, the error was being caused by the way the L2RecipeList parsed the xml, I fixed it by making a dupe of the boolean for the "productionRare2" function, the final result is:

L2RecipeList.java:
 

Spoiler
/**
	 * Constructor of L2RecipeList (create a new Recipe).
	 * @param set
	 * @param haveRare
	 * @param haveRare2
	 */
	public L2RecipeList(StatsSet set, boolean haveRare, boolean haveRare2)
	{
		_recipes = new L2RecipeInstance[0];
		_statUse = new L2RecipeStatInstance[0];
		_altStatChange = new L2RecipeStatInstance[0];
		_id = set.getInt("id");
		_level = set.getInt("craftLevel");
		_recipeId = set.getInt("recipeId");
		_recipeName = set.getString("recipeName");
		_successRate = set.getInt("successRate");
		_itemId = set.getInt("itemId");
		_count = set.getInt("count");
		if (haveRare)
		{
			_rareItemId = set.getInt("rareItemId");
			_rareCount = set.getInt("rareCount");
			_rarity = set.getInt("rarity");
		}
		if (haveRare2)
		{
			_rareItemId2 = set.getInt("rareItemId2");
			_rareCount2 = set.getInt("rareCount2");
			_rarity2 = set.getInt("rarity2");
		}
		_isDwarvenRecipe = set.getBoolean("isDwarvenRecipe");
	}

 


RecipeData.java:
 

Spoiler
else if ("production".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("itemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
								set.set("count", Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue()));
							}
							else if ("productionRare".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("rareItemId", Integer.parseInt(c.getAttributes().getNamedItem("id").getNodeValue()));
								set.set("rareCount", Integer.parseInt(c.getAttributes().getNamedItem("count").getNodeValue()));
								set.set("rarity", Integer.parseInt(c.getAttributes().getNamedItem("rarity").getNodeValue()));
								haveRare = true;
							}
							else if ("productionRare2".equalsIgnoreCase(c.getNodeName()))
							{
								set.set("rareItemId2", Integer.parseInt(c.getAttributes().getNamedItem("id2").getNodeValue()));
								set.set("rareCount2", Integer.parseInt(c.getAttributes().getNamedItem("count2").getNodeValue()));
								set.set("rarity2", Integer.parseInt(c.getAttributes().getNamedItem("rarity2").getNodeValue()));
								haveRare2 = true;
							}
						}
						
						L2RecipeList recipeList = new L2RecipeList(set, haveRare, haveRare2);

 


RecipeController.java:
 

Spoiler
private void rewardPlayer()
		{
			int rareProdId = _recipeList.getRareItemId();
			int rareProdId2 = _recipeList.getRareItemId2();
			int itemId = _recipeList.getItemId();
			int itemCount = _recipeList.getCount();
			L2Item template = ItemTable.getInstance().getTemplate(itemId);
			
			// check that the current recipe has a rare production or not
			if ((rareProdId != -1) && ((rareProdId == itemId) || Config.CRAFT_MASTERWORK))
			{
				if (Rnd.get(100) < _recipeList.getRarity())
				{
					itemId = rareProdId;
					itemCount = _recipeList.getRareCount();
				}
			}
			if ((rareProdId2 != -1) && ((rareProdId2 == itemId) || Config.CRAFT_MASTERWORK))
			{
				if (Rnd.get(100) < _recipeList.getRarity2())
				{
					itemId = rareProdId2;
					itemCount = _recipeList.getRareCount2();
				}
			}

 


Of course I had te declare the boolean on the RecipeData.java:

 

Spoiler
Node att;
						int id = -1;
						boolean haveRare = false;
						boolean haveRare2 = false;
						StatsSet set = new StatsSet();

 



I tested it and its working

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...