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:

 

  Reveal hidden contents

 

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:

 

  Reveal hidden contents


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
  On 5/17/2023 at 11:22 AM, 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.

Expand  


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:

 

  Reveal hidden contents

and

  Reveal hidden contents


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
  On 5/17/2023 at 3:42 PM, 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()));
Expand  


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)

 

 

  On 5/17/2023 at 4:21 PM, 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.

Expand  

 

 

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:
 

  Reveal hidden contents


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:

 

  Reveal hidden contents

 

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)
  On 5/17/2023 at 3:42 PM, LoVe+ said:
 

 

 

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:
 

  Reveal hidden contents


RecipeData.java:
 

  Reveal hidden contents


RecipeController.java:
 

  Reveal hidden contents


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

 

  Reveal hidden contents



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...