ItemGradeSPlus Custom Tweak Help

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Meydex
Posts: 25
Joined: Wed Aug 17, 2016 10:19 pm

ItemGradeSPlus Custom Tweak Help

Post by Meydex »

Revision: Master Branch High 5

Hey everyone,
Since I am experimenting a lot with java these days, I decided to customize the way ItemGradeSPlus method works in L2Item.java. This is how the original works:

Code: Select all

public final CrystalType getItemGradeSPlus()
	{
		switch (getItemGrade())
		{
			case S80:
			case S84:
				return CrystalType.S;
			default:
				return getItemGrade();
		}
	}
And this is what I did:

Code: Select all

public final CrystalType getItemGradeSPlus()
	{		
		
		int enchantLevel = 0;		
		switch (getItemGrade())	
		   {		   
			  case S80:
			    if (enchantLevel > 12)	        	
		        {
				 return CrystalType.A;
				}
				else if (enchantLevel < 12)
				{
				return CrystalType.S; 
			    } 
			  case S84:
				if (enchantLevel > 10)	        	
		        {
				 return CrystalType.B;
				}
				else if (enchantLevel < 10)
				{
				return CrystalType.S; 
			    } 
			  default:
				  return getItemGrade();
		   }  
	}
In other words what I am trying to achieve is when an item that is S80/S84 and is enchanted over a certain value, it should return a different grade than the one assigned to it.
The build executed fine without errors, however it doesn't seem to be working at all. When I entered the game I started hitting with an S84 grade weapon without enchant value in it and I could see from the soulshots that it was S grade. When I enchanted it to +11 the crystal type did not change (tested with Soulshots and Enchant scrolls which were both S grade at the testing phase)
I might have done stupid things but that's why I am here asking for your help afterall guys :D .
I would really appreciate any help.
Cheers

EDIT: Even after correcting this huge integer mistake I still don't get it to work (No compilation errors though).

Code: Select all

public final CrystalType getItemGradeSPlus()
	   {      	           
		_enchant = _defaultEnchantLevel;
		  switch (getItemGrade())   
	         {         
	           case S80:
	             if (_enchant > 12)              
	              {
	             return CrystalType.A;
	            }
	            else if (_enchant < 12)
	            {
	            return CrystalType.S; 
	             } 
	           case S84:
	            if (_enchant > 10)              
	              {
	             return CrystalType.B;
	            }
	            else if (_enchant < 10)
	            {
	            return CrystalType.S; 
	             } 
	           default:
	              return getItemGrade();
	         }  
	   }
Last edited by Meydex on Sat Oct 01, 2016 5:13 pm, edited 1 time in total.
User avatar
Avanael92
Advanced User
Advanced User
Posts: 189
Joined: Thu Aug 07, 2014 5:26 pm
Location: Germany

Re: ItemGradeSPlus Custom Tweak Help

Post by Avanael92 »

What do you expect when your new variable will always be 0? You are doing nothing with it :kappa:
Meydex
Posts: 25
Joined: Wed Aug 17, 2016 10:19 pm

Re: ItemGradeSPlus Custom Tweak Help

Post by Meydex »

Lol, you've got a point. Any suggestions on what to put in the enchantLevel integer? xD
Menoh
Posts: 19
Joined: Wed Oct 12, 2016 10:35 pm

Re: ItemGradeSPlus Custom Tweak Help

Post by Menoh »

Hello,

I don't know yet how exactly you get the current lvl of enchantment of the weapon because I haven't read all the classes yet, but did you try searching in com\l2jserver\gameserver\model\items\L2Weapon.java or in com/l2jserver/gameserver/model/items/enchant package ? Names sounds good. I suppose that the method looks like public int getEnchantLvl(L2Weapon weapon) or something like that...

By the way, what happens in your script if the S80 item is exactly +12, or your S84 item is exactly +10 ? Don't forget to use >= or <= somewhere.

Edit : in com/l2jserver/gameserver/model/items/L2Item.java I've found this that may help you :
private final int _defaultEnchantLevel; (line 144)
public final int getCrystalCount(int enchantLevel) (line 443)
Meydex
Posts: 25
Joined: Wed Aug 17, 2016 10:19 pm

Re: ItemGradeSPlus Custom Tweak Help

Post by Meydex »

Hi thanks for replying.
I did try using defaultEnchantLevel but it is another integer which is stored as the item's default enchant value. In other words whenever you buy, spawn or get the item by drop it will have that specific enchant level in it by default, hence the name. What I was trying to do was to check on the getItemGradeSPlus function, if the Item class is an instance of an item that is weapon and after a certain enchant level, its crystal type would change. It seemed complicated when I first thought the idea but now it seems even more complicated than before xD. To be honest I decided to give up on it and try again later when I gain more knowledge on Java :angel: .
HorridoJoho
L2j Senior Developer
L2j Senior Developer
Posts: 795
Joined: Sun Aug 14, 2005 11:27 am

Re: ItemGradeSPlus Custom Tweak Help

Post by HorridoJoho »

The first problem you got is that you can't change the grade of an item. The item grade is hardcoded in the client. When you change the grade server side, the client still shows the same item grade.
Meydex
Posts: 25
Joined: Wed Aug 17, 2016 10:19 pm

Re: ItemGradeSPlus Custom Tweak Help

Post by Meydex »

Yes I understand that and its ok since I don't care about the visual part but only for the item to have its server side grade changed at a certain enchant level. :)
HorridoJoho
L2j Senior Developer
L2j Senior Developer
Posts: 795
Joined: Sun Aug 14, 2005 11:27 am

Re: ItemGradeSPlus Custom Tweak Help

Post by HorridoJoho »

What you want to do does not work because L2Item is not an existing item that was created but the template which describes an item. This principle is used for npc and skills too.

L2Item describes an item with it's fundamental properties, the properties which are the same for each created item. This is good because for each player having that item, you don't need to define the same properties again and again, but the created item just refererences the describing L2Item, which saves memory.

L2ItemInstance is a created item. One L2ItemInstance is one slot in your inventory/warehouse or an item on the floor. As mentioned before, it references the L2Item to know about it's basic properties. Enchants and stack count and stuff is saved here(the dynamic data which can varry from created item to created item).

The problem is that you change code in L2Item, which is not a created item, hence it does not have an enchant level. L2ItemInstance has an enchant level, however it does not have a grade method you could change, and all the code which works with CrystalType rely on the grade methods in L2Item. It is very difficult to archive what you want to do. You would need to create CrystalType methods in L2ItemInstance and then change all the code which works with the CrystalType methods in L2Item.
Meydex
Posts: 25
Joined: Wed Aug 17, 2016 10:19 pm

Re: ItemGradeSPlus Custom Tweak Help

Post by Meydex »

Yes, it started becoming clearer as I was working on it that it is very difficult to achieve.
Anyway, you have been very informative regarding those two classes (which I was pretty confused the whole time) and I thank you a lot for that.
Cheers :+1:
Post Reply