public TestSocketedWeapon() { Name = "Test socketed weapon"; switch(Utility.Random(4)) { case 0: // make the weapon socketable up to 4 sockets using the default blacksmithing requirements // and add 2 sockets to start XmlAttach.AttachTo(this, new XmlSocketable(4)); XmlAttach.AttachTo(this, new XmlSockets(2)); break; case 1: // make the weapon socketable up to 4 sockets, and set specific socketing requirements // minimum of 100 skill in Tinkering required to socket it, and it uses 50 Agapipe ingots XmlAttach.AttachTo(this, new XmlSocketable(4, SkillName.Tinkering, 100.0, typeof(AgapiteIngot), 50)); break; case 2: // give it 2 sockets and dont allow it to be further socketed XmlAttach.AttachTo(this, new XmlSocketable(0)); XmlAttach.AttachTo(this, new XmlSockets(2)); break; case 3: // give it 2 sockets, fill one of them with an augment, nd dont allow it to be further socketed // create 2 sockets XmlSockets s = new XmlSockets(2); // fill the sockets (starting at 0) with an ancient diamond augment (which only takes up 1 slot) // the augment call has this form: public static bool Augment( Mobile from, object parent, XmlSockets sock, int socketnum, IXmlSocketAugmentation a) // Note that the new augment will be automatically deleted after augmenting XmlSockets.Augment(null, this, s, 0, new AncientDiamond()); // and put the sockets onto the katana XmlAttach.AttachTo(this, s); // and dont allow it to be further socketed XmlAttach.AttachTo(this, new XmlSocketable(0)); break; } }
public AddAugmentationToSocket(object parent, XmlSockets s, int socketnum) : base ( 30, false, TargetFlags.None ) { m_parent = parent; m_socketnum = socketnum; m_s = s; }
public static bool AddSocket(Mobile from, object target, int maxSockets, double difficulty, SkillName requiredSkill, double difficulty2, SkillName requiredSkill2, Type resource, int quantity) { if(maxSockets == 0 || target == null || from == null) return false; // is it in the pack if ( target is Item && !((Item)target).IsChildOf( from.Backpack )) { from.SendMessage("Must be in your backpack."); return false; } else if ( target is BaseCreature && ((BaseCreature)target).ControlMaster != from) { from.SendMessage("Must be under your control."); return false; } // check the target range if ( target is Mobile && !Utility.InRange( ((Mobile)target).Location, from.Location, MaxSocketDistance )) { from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that. return false; } int nSockets = 0; // first see if the target has any existing sockets XmlSockets s = XmlAttach.FindAttachment(target,typeof(XmlSockets)) as XmlSockets; if(s != null) { // find out how many sockets it has nSockets = s.NSockets; } // already full, no more sockets allowed if(nSockets >= maxSockets && maxSockets >= 0) { from.SendMessage("This cannot be socketed any further."); return false; } // try to add a socket to the target // determine the difficulty based upon the required skill and the current number of sockets int successchance = ComputeSuccessChance( from, nSockets, difficulty, requiredSkill, difficulty2, requiredSkill2); if(successchance <= 0) { from.SendMessage("You have no chance of socketing this."); return false; } // consume the resources if(from.Backpack != null && resource != null && quantity > 0) { if(!from.Backpack.ConsumeTotal( resource, quantity, true)) { from.SendMessage("Socketing this requires {0} {1}",quantity, resource.Name); return false; } } from.PlaySound( 0x2A ); // play anvil sound if(Utility.Random(1000) < successchance*10) { from.SendMessage("You have successfully added a socket the target!"); if(s != null) { // add an empty socket s.SocketOccupants.Add(null ); } else { // add an xmlsockets attachment with the new socket s = new XmlSockets(1); XmlAttach.AttachTo(target, s); } if(s != null) s.InvalidateParentProperties(); from.SendGump(new SocketsGump(from, s)); } else { from.SendMessage("Your attempt to add a socket to the target was unsuccessful."); // if it fails then there is also a chance of destroying it if(DefaultDestructionProbability > 0 && Utility.RandomDouble() < DefaultDestructionProbability) { from.SendMessage("You destroy the target while attempting to add a socket to it."); if(target is Item) { ((Item)target).Delete(); } else if(target is BaseCreature) { ((BaseCreature)target).Delete(); } from.CloseGump(typeof(SocketsGump)); return false; } } return true; }
public static bool Augment( Mobile from, object parent, XmlSockets sock, int socketnum, IXmlSocketAugmentation a) { if(parent == null || a == null || sock == null || socketnum < 0) { if(a != null && from == null) a.Delete(); return false; } if(sock.SocketOccupants != null && sock.NFree >= a.SocketsRequired && sock.SocketOccupants.Count > socketnum && a.OnAugment(from, parent)) { SocketOccupant occ = new SocketOccupant(a.GetType(), a.Version, a.Icon, a.IconXOffset, a.IconYOffset, a.IconHue, a.UseGumpArt, String.Format("{0}\n{1}\n{2} Socket(s)",a.Name,a.OnIdentify(null),a.SocketsRequired)); int remaining = a.SocketsRequired; // make sure the requested socket is unoccupied if(sock.SocketOccupants[socketnum] == null) { sock.SocketOccupants[socketnum] = occ; remaining--; } // if this augmentation requires more than 1 socket, then fill the rest if(remaining > 0) { // find a free socket for(int i = 0;i<sock.SocketOccupants.Count;i++) { if(sock.SocketOccupants[i] == null) { sock.SocketOccupants[i] = occ; remaining--; } // filled all of the required sockets if(remaining == 0) break; } } // destroy after augmenting if needed if(a.DestroyAfterUse || from == null) a.Delete(); return true; } else { if(from == null) a.Delete(); return false; } }
public SocketsGump( Mobile from, XmlSockets a) : base( 0,0) { if(a == null) { return; } if(from != null) from.CloseGump(typeof( SocketsGump)); m_attachment = a; int socketcount = 0; if(a.SocketOccupants != null) { socketcount = a.SocketOccupants.Count; } // prepare the page AddPage( 0 ); AddBackground( 0, 0, 185, 137 + socketcount*vertspacing, 5054 ); AddImage( 2 , 2 , 0x28d4); // garg top center AddImageTiled( 2 , 52 , 30, 50 + socketcount*vertspacing, 0x28e0); // left edge AddImageTiled( 151 , 52 , 30, 50 + socketcount*vertspacing, 0x28e0); // right edge AddImageTiled( 40 , 104 + socketcount*vertspacing , 121, 30, 0x28de); // bottom edge AddImage( 143 , 84 + socketcount*vertspacing , 0x28d2); // garg bottom right AddImage( 2 , 84 + socketcount*vertspacing , 0x28d2); // garg bottom left string label = null; if(m_attachment.AttachedTo is Item) { Item item = m_attachment.AttachedTo as Item; label = item.Name; if(item.Name == null) { label = item.ItemData.Name; } } else if(m_attachment.AttachedTo is Mobile) { Mobile m = m_attachment.AttachedTo as Mobile; label = m.Name; } int xadjust = 50; if(label != null) xadjust -= label.Length*5/2; if(xadjust < 0) xadjust = 0; AddLabelCropped( 34 + xadjust, 60, 110-xadjust, 20, 55, label ); // go through the list of sockets and add buttons for them int xoffset = 62; int y = 98; for(int i = 0;i<socketcount;i++) { SocketOccupant s = (SocketOccupant)m_attachment.SocketOccupants[i]; // add the socket icon if(s != null && s.OccupantID != 0) { // add the describe socket button AddButton( xoffset, y, 0x00ea, 0x00ea, 2000+i, GumpButtonType.Reply, 0 ); // put in the filled socket background AddImageTiled( xoffset , y+1 , 57, 59, 0x1404); // dark AddImageTiled( xoffset+2 , y , 56, 58, 0xbbc); // light AddImageTiled( xoffset+2, y+2 , 54, 56, 0x13f0); // neutral if(s.UseGumpArt) { AddImage( xoffset + s.IconXOffset, y + s.IconYOffset, s.OccupantID, s.IconHue ); } else { AddItem( xoffset + s.IconXOffset, y + s.IconYOffset, s.OccupantID, s.IconHue ); } } else { // display the empty socket button AddButton( xoffset+2, y, 0x00ea, 0x00ea, 1000+i, GumpButtonType.Reply, 0 ); } y += vertspacing; } }