* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand. * WIP - Rewriting packets. * Cleanup and updates README * Converts more packets * Fixes header * Converts Effects packets. * Forgot the send command * Adds the start of containers packets. * Adds message packets with caching * Extends the send methods * Starts to add Acquire methods * Converted the packets * Cleanup * Cleanup * Adds more packets * Adds more packets * Fixes clearing arrays from pool. Adds Mobile Incoming * Converts more packets. * Moves more packets * Moves more packets * Test compression * Merges * Migrating to an idiomatic syntax that also supports compression, and proxying. * Optimize the stack alloc. Changes attributes * Converted container packets * Visual Studio doesn't auto save files. I am still getting used to subpar IDEs. * Adds static packet caching. Will profile later. Converts more packets * Fixes packets and changes how compression is configured * WIP - Adds basics for Gumps. Not finished though. * Fix file * Fixes formatting * Changed SpanWriter to be more idiomatic. * Fixes Span vs RawSpan and missing stackallocs * Converts over some more gumps * WIP - Deletes 32bit support. * Drops RDRand32 support. * Fixes gump compilation * Converting gump components * Removes old huffman compression function * Revert signature for backwards compatibility * WIP - Converting more gump components * Creates ArraySet for the strings. Updates AppendTo to reference that. * Converts the maining gump components * Cleans up gump components * Cleans up directives * Cleans up ArraySet and moves it. Adds null-coalescing-assignment * Cleanup, Target Packets, and C# 8 changes. * Removed OPL Packet * World packets * Fixing packet uses * Cleans up code. Fixes packet uses in various places. * More cleanup for packets * Code cleanup * Converts more packet uses and cleans up more code * More code cleanup * Finishes fixing the packets in Item * Updates secure trade packets * Updates core and gets it to compile. * Moved packets to scripts. Fixed account handler use of packets * Code cleanup * Updates chat packets * Code cleanuo * Adds party packets, but need to implement them. * Party packets WIP * Finishes party packets * Rearrange movement namespaces and classes * Finishes plant packets * Code Formatting * Fixes moving effects * Code cleanup, eliminates equipinfo * Adds more packets. Fixes bugs with various packets. * Finishes mahjon packets * Fixes mahjong packet * Code cleanup * Finishes mahjong packets * Adds Map packets * Add multifacet maps and charts * Cleans up some packets with UTF8 * Optimizes packets * Cleans up more packets. Moves the MessageHelper * Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets. * Updates protocol extensions packet receiver * Fixes a few bugs. Fixes a few more packets. * Code cleanup and fixing more packets * Fixes packet effects * Cleaned up more code * Buff Icon cleanup * Removed unused constructors * Code Cleanup. Adds BoatHS Packets * Moves house files. Updates house foundation packets. * Deployment cleanup * Fixes: * Code cleanup * More code cleanup * More code cleanup * Cleaned up BaseHouse * Enforces styling * Converts foreach to linq where possible. * Dont need that * Goals/Readme updates * Removes 32bit support at the highest level. Turns on HRT by default. * Code cleanup. Fixes extended features packet. * Fixes various bugs * Code cleanup * Code cleanup * Code cleanup. Fixes gump X/Y assignment. * Code cleanup using |= operator * More code cleanup * Cleanup * Fixes spacing issues. Thanks Visual Studio. You suck. * Compiler error * Fixes NPE from RunUO 2.7 * Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README * Fixes more packets. Stupid trailing nulls. * Fixes various bugs. * Fixes for gumps * Fixes more gump stuff. Going to split it out later since it is getting insane * Recoded the gump writing * WIP * *Added output path of scripts project to dev branch *Activated debugging in code
354 lines
9 KiB
C#
354 lines
9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Server.ContextMenus;
|
|
using Server.Engines.Craft;
|
|
using Server.Network;
|
|
|
|
namespace Server.Items
|
|
{
|
|
public class SalvageBag : Bag
|
|
{
|
|
private bool m_Failure;
|
|
|
|
[Constructible]
|
|
public SalvageBag()
|
|
: this(Utility.RandomBlueHue())
|
|
{
|
|
}
|
|
|
|
[Constructible]
|
|
public SalvageBag(int hue)
|
|
{
|
|
Weight = 2.0;
|
|
Hue = hue;
|
|
m_Failure = false;
|
|
}
|
|
|
|
public override int LabelNumber => 1079931; // Salvage Bag
|
|
|
|
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
|
|
{
|
|
base.GetContextMenuEntries(from, list);
|
|
|
|
if (from.Alive)
|
|
{
|
|
list.Add(new SalvageIngotsEntry(this, IsChildOf(from.Backpack) && Resmeltables()));
|
|
list.Add(new SalvageClothEntry(this, IsChildOf(from.Backpack) && Scissorables()));
|
|
list.Add(new SalvageAllEntry(this, IsChildOf(from.Backpack) && Resmeltables() && Scissorables()));
|
|
}
|
|
}
|
|
|
|
#region Resmelt.cs
|
|
|
|
private bool Resmelt(Mobile from, Item item, CraftResource resource)
|
|
{
|
|
try
|
|
{
|
|
if (CraftResources.GetType(resource) != CraftResourceType.Metal)
|
|
return false;
|
|
|
|
CraftResourceInfo info = CraftResources.GetInfo(resource);
|
|
|
|
if (info == null || info.ResourceTypes.Length == 0)
|
|
return false;
|
|
|
|
CraftItem craftItem = DefBlacksmithy.CraftSystem.CraftItems.SearchFor(item.GetType());
|
|
|
|
if (craftItem == null || craftItem.Resources.Count == 0)
|
|
return false;
|
|
|
|
CraftRes craftResource = craftItem.Resources.GetAt(0);
|
|
|
|
if (craftResource.Amount < 2)
|
|
return false; // Not enough metal to resmelt
|
|
|
|
var difficulty = resource switch
|
|
{
|
|
CraftResource.DullCopper => 65.0,
|
|
CraftResource.ShadowIron => 70.0,
|
|
CraftResource.Copper => 75.0,
|
|
CraftResource.Bronze => 80.0,
|
|
CraftResource.Gold => 85.0,
|
|
CraftResource.Agapite => 90.0,
|
|
CraftResource.Verite => 95.0,
|
|
CraftResource.Valorite => 99.0,
|
|
_ => 0.0
|
|
};
|
|
|
|
Type resourceType = info.ResourceTypes[0];
|
|
Item ingot = (Item)Activator.CreateInstance(resourceType);
|
|
|
|
if (item is DragonBardingDeed || item is BaseArmor armor && armor.PlayerConstructed ||
|
|
item is BaseWeapon weapon && weapon.PlayerConstructed ||
|
|
item is BaseClothing clothing && clothing.PlayerConstructed)
|
|
{
|
|
double mining = from.Skills.Mining.Value;
|
|
if (mining > 100.0)
|
|
mining = 100.0;
|
|
double amount = ((4 + mining) * craftResource.Amount - 4) * 0.0068;
|
|
if (amount < 2)
|
|
ingot.Amount = 2;
|
|
else
|
|
ingot.Amount = (int)amount;
|
|
}
|
|
else
|
|
{
|
|
ingot.Amount = 2;
|
|
}
|
|
|
|
if (difficulty > from.Skills.Mining.Value)
|
|
{
|
|
m_Failure = true;
|
|
ingot.Delete();
|
|
}
|
|
else
|
|
{
|
|
item.Delete();
|
|
}
|
|
|
|
from.AddToBackpack(ingot);
|
|
|
|
from.PlaySound(0x2A);
|
|
from.PlaySound(0x240);
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.ToString());
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Checks
|
|
|
|
private bool Resmeltables() => //Where context menu checks for metal items and dragon barding deeds
|
|
Items.Select(i => i?.Deleted == false &&
|
|
(i is BaseWeapon weapon && CraftResources.GetType(weapon.Resource) == CraftResourceType.Metal ||
|
|
i is BaseArmor armor && CraftResources.GetType(armor.Resource) == CraftResourceType.Metal ||
|
|
i is DragonBardingDeed)).FirstOrDefault();
|
|
|
|
private bool Scissorables() //Where context menu checks for Leather items and cloth items
|
|
{
|
|
foreach (Item i in Items)
|
|
{
|
|
if (!(i is IScissorable) || i.Deleted)
|
|
continue;
|
|
|
|
if (i is BaseClothing || i is Cloth || i is BoltOfCloth || i is Hides || i is BonePile ||
|
|
i is BaseArmor armor && CraftResources.GetType(armor.Resource) == CraftResourceType.Leather)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Salvaging
|
|
|
|
private void SalvageIngots(Mobile from)
|
|
{
|
|
if (from.Backpack.FindItemsByType<BaseTool>().All(tool => tool.CraftSystem != DefBlacksmithy.CraftSystem))
|
|
{
|
|
from.SendLocalizedMessage(1079822); // You need a blacksmithing tool in order to salvage ingots.
|
|
return;
|
|
}
|
|
|
|
DefBlacksmithy.CheckAnvilAndForge(from, 2, out _, out bool forge);
|
|
|
|
if (!forge)
|
|
{
|
|
from.SendLocalizedMessage(1044265); // You must be near a forge.
|
|
return;
|
|
}
|
|
|
|
int salvaged = 0;
|
|
int notSalvaged = 0;
|
|
|
|
Container sBag = this;
|
|
|
|
List<Item> smeltables = sBag.FindItemsByType<Item>();
|
|
|
|
foreach (Item item in smeltables)
|
|
{
|
|
if (item?.Deleted != false)
|
|
continue;
|
|
|
|
if (item is BaseArmor armor && Resmelt(from, armor, armor.Resource) ||
|
|
item is BaseWeapon weapon && Resmelt(from, weapon, weapon.Resource) ||
|
|
item is DragonBardingDeed)
|
|
salvaged++;
|
|
else
|
|
notSalvaged++;
|
|
}
|
|
|
|
if (m_Failure)
|
|
{
|
|
from.SendLocalizedMessage(1079975); // You failed to smelt some metal for lack of skill.
|
|
m_Failure = false;
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1079973,
|
|
$"{salvaged}\t{salvaged + notSalvaged}"); // Salvaged: ~1_COUNT~/~2_NUM~ blacksmithed items
|
|
}
|
|
}
|
|
|
|
private void SalvageCloth(Mobile from)
|
|
{
|
|
Scissors scissors = from.Backpack.FindItemByType<Scissors>();
|
|
|
|
if (scissors == null)
|
|
{
|
|
from.SendLocalizedMessage(1079823); // You need scissors in order to salvage cloth.
|
|
return;
|
|
}
|
|
|
|
int salvaged = 0;
|
|
int notSalvaged = 0;
|
|
|
|
Container sBag = this;
|
|
|
|
List<Item> scissorables = sBag.FindItemsByType<Item>();
|
|
|
|
for (int i = scissorables.Count - 1; i >= 0; --i)
|
|
{
|
|
Item item = scissorables[i];
|
|
|
|
if (!(item is IScissorable scissorable))
|
|
continue;
|
|
|
|
if (Scissors.CanScissor(from, scissorable) && scissorable.Scissor(from, scissors))
|
|
++salvaged;
|
|
else
|
|
++notSalvaged;
|
|
}
|
|
|
|
from.SendLocalizedMessage(1079974,
|
|
$"{salvaged}\t{salvaged + notSalvaged}"); // Salvaged: ~1_COUNT~/~2_NUM~ tailored items
|
|
|
|
Item[] items = FindItemsByType(new[]{
|
|
typeof(Leather), typeof(Cloth), typeof(SpinedLeather), typeof(HornedLeather), typeof(BarbedLeather),
|
|
typeof(Bandage), typeof(Bone)
|
|
});
|
|
|
|
for (int i = 0; i < items.Length; i++) from.AddToBackpack(items[i]);
|
|
}
|
|
|
|
private void SalvageAll(Mobile from)
|
|
{
|
|
SalvageIngots(from);
|
|
|
|
SalvageCloth(from);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ContextMenuEntries
|
|
|
|
private class SalvageAllEntry : ContextMenuEntry
|
|
{
|
|
private SalvageBag m_Bag;
|
|
|
|
public SalvageAllEntry(SalvageBag bag, bool enabled)
|
|
: base(6276)
|
|
{
|
|
m_Bag = bag;
|
|
|
|
if (!enabled)
|
|
Flags |= CMEFlags.Disabled;
|
|
}
|
|
|
|
public override void OnClick()
|
|
{
|
|
if (m_Bag.Deleted)
|
|
return;
|
|
|
|
Mobile from = Owner.From;
|
|
|
|
if (from.CheckAlive())
|
|
m_Bag.SalvageAll(from);
|
|
}
|
|
}
|
|
|
|
private class SalvageIngotsEntry : ContextMenuEntry
|
|
{
|
|
private SalvageBag m_Bag;
|
|
|
|
public SalvageIngotsEntry(SalvageBag bag, bool enabled)
|
|
: base(6277)
|
|
{
|
|
m_Bag = bag;
|
|
|
|
if (!enabled)
|
|
Flags |= CMEFlags.Disabled;
|
|
}
|
|
|
|
public override void OnClick()
|
|
{
|
|
if (m_Bag.Deleted)
|
|
return;
|
|
|
|
Mobile from = Owner.From;
|
|
|
|
if (from.CheckAlive())
|
|
m_Bag.SalvageIngots(from);
|
|
}
|
|
}
|
|
|
|
private class SalvageClothEntry : ContextMenuEntry
|
|
{
|
|
private SalvageBag m_Bag;
|
|
|
|
public SalvageClothEntry(SalvageBag bag, bool enabled)
|
|
: base(6278)
|
|
{
|
|
m_Bag = bag;
|
|
|
|
if (!enabled)
|
|
Flags |= CMEFlags.Disabled;
|
|
}
|
|
|
|
public override void OnClick()
|
|
{
|
|
if (m_Bag.Deleted)
|
|
return;
|
|
|
|
Mobile from = Owner.From;
|
|
|
|
if (from.CheckAlive())
|
|
m_Bag.SalvageCloth(from);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Serialization
|
|
|
|
public SalvageBag(Serial serial)
|
|
: base(serial)
|
|
{
|
|
}
|
|
|
|
public override void Serialize(GenericWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
|
|
writer.WriteEncodedInt(0); // version
|
|
}
|
|
|
|
public override void Deserialize(GenericReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
|
|
int version = reader.ReadEncodedInt();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|