I have adapter the XML sockets into my level system, at X level a socket is applied to a weapon. Getting the first initial socket is no problem, and replacing it with other socket variables is also not a problem. The issue is, lets say a player levels a katana up and obtains 2 sockets. Then they level it up again and obtain 2 more sockets for a total of 4. That works great, but the problem is, instead of incriminating the amount of sockets the weapon has on the xml attachment it replaces it entirely and removes any existing augments. Any one have any suggestions to make that work? here is a snippit of the code I'm using to make all this happen?

I just need each following level up to add sockets, not remove the existing ones. I tried referencing the sockets attachment but i'm not sure what i'm doing wrong.


Code:
                Item bww = from.FindItemOnLayer(Layer.TwoHanded);
                if ( bww != null )
                {
                    if (bww is BaseWeapon)
                    {
                        XmlLevelItem weapon1levelitem = (XmlLevelItem)XmlAttach.FindAttachment(bww, typeof(XmlLevelItem));
                        if (weapon1levelitem != null )
                        {
                            if ( weapon1levelitem.Level == 2)
                            {
                                XmlSockets twohandsocket1 = (XmlSockets)XmlAttach.FindAttachment(bww, typeof(XmlSockets));
                                if ( twohandsocket1 != null )
                                    return;
                                else
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Your weapon is glowing with potential. ");
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Weapon can be further Enhanced!. ");
    //                                XmlAttach.AttachTo(bww, new XmlSocketable(4)); //max sockets available
                                    XmlAttach.AttachTo(bww, new XmlSockets(2));  
                            }
                            else if ( weapon1levelitem.Level == 4)
                            {
                                XmlSockets twohandsocket2 = (XmlSockets)XmlAttach.FindAttachment(bww, typeof(XmlSockets));
                                int nSockets = 0;
                                nSockets = twohandsocket2.NSockets;
                                if(nSockets >= 4)
                                    return;
                                else
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Your weapon is glowing with potential. ");
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Weapon can be further Enhanced!. ");
                                    twohandsocket2 = new XmlSockets(4);
                                    XmlAttach.AttachTo(bww,twohandsocket2);
                            }
                            else
                                return;
                        }
                    }
                }
 
I believe your problem is right here:
Code:
twohandsocket2 =new XmlSockets(4);
I think it should be:
Code:
twohandsocket2 +=new XmlSockets(2);
That would add two new sockets.
 
I gave the adjustment a try and it provided me an error during compile.

Here is the Error
Code:
Errors:
+ Mobiles/BaseCreature.cs:
    CS0019: Line 2013: Operator '+=' cannot be applied to operands of type 'Server.Engines.XmlSpawner2.XmlSockets' and 'Server.Engines.XmlSpawner2.XmlSockets'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

Here is the script with the adjustment
Code:
                Item bww = from.FindItemOnLayer(Layer.TwoHanded);
                if ( bww != null )
                {
                    if (bww is BaseWeapon)
                    {
                        XmlLevelItem weapon1levelitem = (XmlLevelItem)XmlAttach.FindAttachment(bww, typeof(XmlLevelItem));
                        if (weapon1levelitem != null )
                        {
                            if ( weapon1levelitem.Level == 2)
                            {
                                XmlSockets twohandsocket1 = (XmlSockets)XmlAttach.FindAttachment(bww, typeof(XmlSockets));
                                if ( twohandsocket1 != null )
                                    return;
                                else
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Your weapon is glowing with potential. ");
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Weapon can be further Enhanced!. ");
    //                                XmlAttach.AttachTo(bww, new XmlSocketable(4)); //max sockets available
                                    XmlAttach.AttachTo(bww, new XmlSockets(2));   
                            }
                            else if ( weapon1levelitem.Level == 4)
                            {
                                XmlSockets twohandsocket2 = (XmlSockets)XmlAttach.FindAttachment(bww, typeof(XmlSockets));
                                int nSockets = 0;
                                nSockets = twohandsocket2.NSockets;
                                if(nSockets >= 4)
                                    return;
                                else
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Your weapon is glowing with potential. ");
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Weapon can be further Enhanced!. ");
                                    twohandsocket2 += new XmlSockets(2); //adjustment to try to fix the issue
                                    XmlAttach.AttachTo(bww,twohandsocket2);
                            }
                            else
                                return;
                        }
                    }
                }
 
Sorry, I meant this, but my fingers said differently lol
Code:
twohandsocket2 +=2;
If you could post the entire script, I might have better luck, because the code is out of context.
 
Still same error as before. Here is my full basecreature.cs (the reason its in base creature is so on kill it checks the equipment and attachment for the sockets n levels), if you think it would be easier to mod the atlevelup entry in xml sockets i would like to know how lol. I tried a few things but i gave up on that possibility.

Line 1985 is where the modifications start for XML sockets
 

Attachments

  • BaseCreature.cs
    189.7 KB · Views: 1
So in looking at the way sockets are added by default...the command AddSocket is used and an object is targeted, resources are consumed if successful. I think what you need to do is simple "call" the command there.
So something like this perhaps?
Code:
            #region XmlSpawner
            if (!Summoned && willKill && from != null)
            {
                LevelItemManager.CheckItems(from, this);
				
				Item bww = from.FindItemOnLayer(Layer.TwoHanded);
				if ( bww != null )
				{
					if (bww is BaseWeapon)
					{
						XmlLevelItem weapon1levelitem = (XmlLevelItem)XmlAttach.FindAttachment(bww, typeof(XmlLevelItem));
						if (weapon1levelitem != null )
						{
							if ( weapon1levelitem.Level == 2)
							{
								XmlSockets twohandsocket1 = (XmlSockets)XmlAttach.FindAttachment(bww, typeof(XmlSockets));
								if ( twohandsocket1 != null )
									return;
								else 
									from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Your weapon is glowing with potential. ");
									from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Weapon can be further Enhanced!. ");
									XmlAttach.AttachTo(bww, new XmlSocketable(4)); //max sockets available
									XmlAttach.AttachTo(bww, new XmlSockets(2));	
							}
							else if ( weapon1levelitem.Level == 4)
							{
								XmlSockets twohandsocket2 = (XmlSockets)XmlAttach.FindAttachment(bww, typeof(XmlSockets));
								int nSockets = 0;
								nSockets = twohandsocket2.NSockets;
								if(nSockets >= 4)
									return;
								else 
									from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Your weapon is glowing with potential. ");
									from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Weapon can be further Enhanced!. ");
									from.bww = new XmlSockets.AddSocketTobww();
									from.bww = new XmlSockets.AddSocketTobww();
									//twohandsocket2 += 2;
									//XmlAttach.AttachTo(bww,twohandsocket2);
							}
							else
								return;
						}
					}
				}
            }
            #endregion
Notice I removed the comment for XmlAttach.AttachTo(bww, new XmlSocketable(4)); //max sockets available that is correct (you're max is 4 sockets, you're adding 2 when it hits Level 2).
 
So it failed differently this time, I suspect refencing mobile as from was the issue , so i removed from. and used jsut bww, it still failed for the addsocketbww portion.


This is the error from the 'from' being there

Code:
Errors:
+ Mobiles/BaseCreature.cs:
    CS1061: Line 2013: 'Server.Mobile' does not contain a definition for 'bww' and no extension method 'bww' accepting a first argument of type 'Server.Mobile' could be found (are you missing a using directive or an assembly reference?)
    CS0426: Line 2013: The type name 'AddSocketTobww' does not exist in the type 'Server.Engines.XmlSpawner2.XmlSockets'
    CS1061: Line 2014: 'Server.Mobile' does not contain a definition for 'bww' and no extension method 'bww' accepting a first argument of type 'Server.Mobile' could be found (are you missing a using directive or an assembly reference?)
    CS0426: Line 2014: The type name 'AddSocketTobww' does not exist in the type 'Server.Engines.XmlSpawner2.XmlSockets'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.


I looked further into xmlsockets on addsocket,
This snippit adds an empty socket to the existing weapon when successful.
Code:
                from.SendMessage("You have successfully added a socket the target!");
                if(s != null)
                {
                    // add an empty socket
                    s.SocketOccupants.Add(null );

                }

Looks like SocketOccupants plays a big part in the xmlsocket addsocket section.
I tried referencing it in the add socket code

Code:
                            else if ( weapon1levelitem.Level == 4)
                            {
                                XmlSockets twohandsocket2 = (XmlSockets)XmlAttach.FindAttachment(bww, typeof(XmlSockets));
                                int nSockets = 0;
                                nSockets = twohandsocket2.NSockets;
                                if(nSockets >= 4)
                                    return;
                                else
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Your weapon is glowing with potential. ");
                                    from.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Weapon can be further Enhanced!. ");
                                    twohandsocket2.SocketOccupants.Add(2);
//                                  from.bww = new XmlSockets.AddSocketTobww();
//                                    twohandsocket2 = new XmlSockets(4);
//                                    XmlAttach.AttachTo(bww,twohandsocket2);
                            }

Which actually compiles Fine (not sure if this would work or not) so I went ahead and went into game and tested it, at Level 4 on the weapon.
did add the socket however something different happened.

So after level up, it worked, but checking the attachment.
NFree = 2 (still equaled 2, did not increase)
and NSockets = 4 , so that did increase like it was supposed to.

When I used Item Identification on the weapon to add jewels to the socket, the server then crashed.
Here is the crash log. So it seems we are almost there.

Code:
Server Crash Report
===================

RunUO Version 0.5, Build 6225.40023
Operating System: Microsoft Windows NT 6.2.9200.0
.NET Framework: 4.0.30319.42000
Time: 1/21/2017 5:10:21 PM
Mobiles: 3999
Items: 117593
Exception:
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'SocketOccupant'.
   at Server.Engines.XmlSpawner2.XmlSockets.SocketsGump..ctor(Mobile from, XmlSockets a)
   at Server.Engines.XmlSpawner2.XmlSockets.OnIdentify(Mobile from)
   at Server.Engines.XmlSpawner2.XmlAttach.RevealAttachments(Mobile from, Object o)
   at Server.Targeting.Target.Invoke(Mobile from, Object targeted) in k:\AlfheimRebornServer\Ultima Server\Server\Targeting\Target.cs:line 273
   at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc) in k:\AlfheimRebornServer\Ultima Server\Server\Network\PacketHandlers.cs:line 1323
   at Server.Network.MessagePump.HandleReceive(NetState ns) in k:\AlfheimRebornServer\Ultima Server\Server\Network\MessagePump.cs:line 187
   at Server.Network.MessagePump.Slice() in k:\AlfheimRebornServer\Ultima Server\Server\Network\MessagePump.cs:line 115
   at Server.Core.Main(String[] args) in k:\AlfheimRebornServer\Ultima Server\Server\Main.cs:line 579

Clients:
- Count: 1
+ 192.168.1.212: (account = romeov007) (mobile = 0x34B 'Asuna')
 
And with that, you just stepped beyond my knowledge as far as errors goes. My guess is that some packets don't add up with when the Identify skill is used. Which ones, I'm not sure.
I suppose you could remove the need to Identify it, in this case and see if that works.
 
bummer. then im back to square 1.. lol. so i will need to then figure out how to make Nfree public and not read only, so that way i can just submit the code to actively change it. As of right now any attempt to change NFree results in compile error that its read only.
 
bummer. then im back to square 1.. lol. so i will need to then figure out how to make Nfree public and not read only, so that way i can just submit the code to actively change it. As of right now any attempt to change NFree results in compile error that its read only.
It's already Public in XmlSockets.cs, at least it is for me :|

Also, this is what my OnIdentify looks like in XmlSockets.cs:
Code:
public override string OnIdentify(Mobile from)
		{

			// open up the socket gump
			if(from != null)
			{
				from.SendGump(new SocketsGump(from, this));
			} 
			else
			{
				return String.Format("{0} Sockets. {1} available.",NSockets, NFree);
			}

			return null;
		}
 
Back