Advertisement
Asyncron

Untitled

Jul 3rd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.71 KB | None | 0 0
  1.         private static void AddDamageProtection(WorldSession client, uint mainGuid, IReadOnlyList<uint> minorGuids)
  2.         {
  3.             Item mainItem;
  4.             if (client.Character.GetItem(mainGuid, out mainItem) && mainItem.Protection < 7)
  5.             {
  6.                 if (!mainItem.IsBlessEnable)
  7.                     throw new SevereViolation($"Attempted to add protection to {mainItem}");
  8.  
  9.                 var remove = 0;
  10.                 while (remove < minorGuids.Count)
  11.                 {
  12.                     Item minorItem;
  13.                     if (!client.Character.TryRemoveItem(minorGuids[remove], out minorItem))
  14.                         break;
  15.  
  16.                     if (minorItem.Base.Sort != ItemSort.Gem ||
  17.                         minorItem.Base.Class != ItemClass.SuperTortoiseGem)
  18.                         throw new SevereViolation($"Attempted add protection to {mainItem} using {minorItem}");
  19.  
  20.                     remove++;
  21.                 }
  22.  
  23.                 switch (mainItem.Protection)
  24.                 {
  25.                     case 0:
  26.                         if (remove == 5)
  27.                             mainItem.Protection = 1;
  28.                         break;
  29.                     case 1:
  30.                         if (remove == 1)
  31.                             mainItem.Protection = 3;
  32.                         break;
  33.                     case 3:
  34.                         if (remove == 3)
  35.                             mainItem.Protection = 5;
  36.                         break;
  37.                     case 5:
  38.                         if (remove == 5)
  39.                             mainItem.Protection = 7;
  40.                         break;
  41.                 }
  42.             }
  43.  
  44.             client.Send(new ItemInformation(mainItem, ItemInformation.Mode.Update));
  45.         }
  46.  
  47.         private static void CreateEquipmentSocket(WorldSession client, uint mainGuid, IReadOnlyList<uint> minorGuids)
  48.         {
  49.             if (minorGuids.Count < 1)
  50.                 throw new SevereViolation("Attempt to create item socket with no minor items.");
  51.  
  52.             Item mainItem;
  53.             if (!client.Character.GetItem(mainGuid, out mainItem))
  54.                 throw new MildViolation($"Expected to find the main item on {client.Character.Name}, but did not.");
  55.  
  56.             if (!mainItem.IsSocketEnable)
  57.                 // should never reach this case if the item is socketless.
  58.                 throw new SevereViolation($"Opening sockets in a socketless item. {mainItem}");
  59.  
  60.             if (mainItem.Base.Sort == ItemSort.Artifact)
  61.                 // the main item should never be an artifact in this case.
  62.                 throw new SevereViolation($"Attempt to socket an artifact using the equipment socket method. {mainItem}");
  63.  
  64.             if (mainItem.SecondSocket == SocketIdentifier.None)
  65.             {
  66.                 var remove = 0;
  67.                 while (remove < minorGuids.Count)
  68.                 {
  69.                     Item minorItem;
  70.                     if (!client.Character.TryRemoveItem(minorGuids[remove], out minorItem))
  71.                         continue;
  72.  
  73.                     remove++;
  74.  
  75.                     if (mainItem.IsArmor || mainItem.IsShield)
  76.                     {
  77.                         if (mainItem.FirstSocket == SocketIdentifier.None)
  78.                         {
  79.                             if (minorGuids.Count != 12)
  80.                                 throw new SevereViolation(
  81.                                     $"The requirement to open the first armor socket was not met. {minorItem} was lost.");
  82.  
  83.                             if (minorItem.Base.Id != 1088000)
  84.                                 throw new ModerateViolation(
  85.                                     $"{minorItem} was lost while using it to open the first armor socket.");
  86.  
  87.                             if (remove < 12)
  88.                                 continue;
  89.  
  90.                             mainItem.FirstSocket = SocketIdentifier.EmptySocket;
  91.                             break;
  92.                         }
  93.  
  94.                         if (minorItem.Base.Sort != ItemSort.PremiumExpendable)
  95.                             throw new ModerateViolation(
  96.                                 $"{minorItem} was lost while using it to open the second armor socket.");
  97.  
  98.                         if (minorItem.Base.Class == ItemClass.ToughDrill)
  99.                             if (!RNGProvider.Chance(WorldServer.Configuration.World.ArmorSecondSocketRate))
  100.                             {
  101.                                 client.Character.Inventory.Add(ItemManager.Instance.CreateItem(client.Character, 1200006));
  102.                                 break;
  103.                             }
  104.                         if (minorItem.Base.Class == ItemClass.StarDrill)
  105.                             if (remove < 7)
  106.                                 continue;
  107.  
  108.                         mainItem.SecondSocket = SocketIdentifier.EmptySocket;
  109.                         break;
  110.                     }
  111.  
  112.                     if (mainItem.IsWeapon)
  113.                     {
  114.                         if (minorItem.Base.Id != 1088000)
  115.                             throw new ModerateViolation(
  116.                                 $"{minorItem} was lost while using it to open a weapon socket.");
  117.  
  118.                         if (mainItem.FirstSocket == SocketIdentifier.None)
  119.                         {
  120.                             mainItem.FirstSocket = SocketIdentifier.EmptySocket;
  121.                             break;
  122.                         }
  123.  
  124.                         if (remove < 5)
  125.                             continue;
  126.  
  127.                         mainItem.SecondSocket = SocketIdentifier.EmptySocket;
  128.                         break;
  129.                     }
  130.                 }
  131.             }
  132.  
  133.             client.Send(new ItemInformation(mainItem, ItemInformation.Mode.Update));
  134.         }
  135.  
  136.         private static void CreateTalismanSocket(WorldSession client, uint mainGuid, IReadOnlyList<uint> minorGuids)
  137.         {
  138.             Item mainItem;
  139.             if (!client.Character.GetItem(mainGuid, out mainItem))
  140.                 throw new MildViolation(
  141.                     $"Expected to find the main item on {client.Character.Name}, but did not.");
  142.  
  143.             if (!mainItem.IsSocketEnable || mainItem.Base.Sort != ItemSort.Artifact)
  144.                 throw new SevereViolation(
  145.                     $"Invalid item received when using talisman socket function. {mainItem}");
  146.  
  147.             if (mainItem.SecondSocket == SocketIdentifier.None)
  148.             {
  149.                 var remove = 0;
  150.                 while (remove < minorGuids.Count)
  151.                 {
  152.                     Item minorItem;
  153.                     if (!client.Character.TryRemoveItem(minorGuids[remove], out minorItem))
  154.                         // more than one or two of these and it *could be* an attempt to cheat the system.
  155.                         // a few scenarios would make this an acceptable occurrence
  156.                         throw new MildViolation("A minor item was expected to be removable, but was not.");
  157.                     remove++;
  158.  
  159.                     //initialize progress value based on how many points are added by a minor's craft level.
  160.                     var progressAdded =
  161.                         ItemManager.ArtifactSocketPoints[minorItem.CraftLevel > 9 ? 9 : minorItem.CraftLevel];
  162.  
  163.                     //increase progress per minor quality.
  164.                     switch (minorItem.Quality)
  165.                     {
  166.                         case ItemQuality.Refined:
  167.                             progressAdded += 5;
  168.                             break;
  169.                         case ItemQuality.Unique:
  170.                             progressAdded += 10;
  171.                             break;
  172.                         case ItemQuality.Elite:
  173.                             progressAdded += 40;
  174.                             break;
  175.                         case ItemQuality.Super:
  176.                             progressAdded += 1000;
  177.                             break;
  178.                     }
  179.  
  180.                     if (minorItem.IsArmor || minorItem.IsShield)
  181.                     {
  182.                         if (minorItem.FirstSocket != SocketIdentifier.None)
  183.                             progressAdded += 2000;
  184.                         if (minorItem.SecondSocket != SocketIdentifier.None)
  185.                             progressAdded += 6000;
  186.                     }
  187.                     else if (minorItem.IsWeapon)
  188.                     {
  189.                         if (minorItem.FirstSocket != SocketIdentifier.None)
  190.                             progressAdded += 160;
  191.                         if (minorItem.SecondSocket != SocketIdentifier.None)
  192.                             progressAdded += 800;
  193.                     }
  194.  
  195.                     mainItem.SocketProgress += progressAdded;
  196.                 }
  197.  
  198.                 if (mainItem.FirstSocket == SocketIdentifier.None && mainItem.SocketProgress >= 8000)
  199.                 {
  200.                     mainItem.SocketProgress -= 8000;
  201.                     mainItem.FirstSocket = SocketIdentifier.EmptySocket;
  202.                 }
  203.  
  204.                 if (mainItem.SocketProgress >= 20000)
  205.                 {
  206.                     mainItem.SocketProgress = 0;
  207.                     mainItem.SecondSocket = SocketIdentifier.EmptySocket;
  208.                 }
  209.             }
  210.             client.Send(new ItemInformation(mainItem, ItemInformation.Mode.Update));
  211.         }
  212.  
  213.         private static void PurchaseTalismanSocket(WorldSession client, uint itemGuid)
  214.         {
  215.             Item item;
  216.             if (!client.Character.GetItem(itemGuid, out item))
  217.                 throw new MildViolation(
  218.                     $"Expected to find the main item on {client.Character.Name}, but did not.");
  219.  
  220.             if (item.SecondSocket != SocketIdentifier.None)
  221.                 return;
  222.  
  223.             var progressRequired = item.FirstSocket == SocketIdentifier.None ? 8000 : 20000;
  224.             var socketProgressPercentage = MathUtils.Percentage(item.SocketProgress, progressRequired);
  225.             if (socketProgressPercentage < 30)
  226.                 throw new SevereViolation(
  227.                     $"Attempt to buy talisman socket below 30% progress. {item} available progress: {socketProgressPercentage}");
  228.  
  229.             var eMoneyPrice = (int) ((progressRequired - item.SocketProgress)*0.7);
  230.  
  231.             if (client.Character.EMoney >= eMoneyPrice)
  232.             {
  233.                 client.Character.EMoney -= eMoneyPrice;
  234.                 if (progressRequired == 8000)
  235.                     item.FirstSocket = SocketIdentifier.EmptySocket;
  236.                 if (progressRequired == 20000)
  237.                     item.SecondSocket = SocketIdentifier.EmptySocket;
  238.                 item.SocketProgress = 0;
  239.             }
  240.             client.Send(new ItemInformation(item, ItemInformation.Mode.Update));
  241.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement