Reorganizes Project (#41)
This commit is contained in:
parent
08bf44af9a
commit
3614a66aee
3499 changed files with 79 additions and 55 deletions
55
Projects/Scripts/Engines/Craft/Core/CraftContext.cs
Normal file
55
Projects/Scripts/Engines/Craft/Core/CraftContext.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public enum CraftMarkOption
|
||||
{
|
||||
MarkItem,
|
||||
DoNotMark,
|
||||
PromptForMark
|
||||
}
|
||||
|
||||
public class CraftContext
|
||||
{
|
||||
public CraftContext()
|
||||
{
|
||||
Items = new List<CraftItem>();
|
||||
LastResourceIndex = -1;
|
||||
LastResourceIndex2 = -1;
|
||||
LastGroupIndex = -1;
|
||||
}
|
||||
|
||||
public List<CraftItem> Items{ get; }
|
||||
|
||||
public int LastResourceIndex{ get; set; }
|
||||
|
||||
public int LastResourceIndex2{ get; set; }
|
||||
|
||||
public int LastGroupIndex{ get; set; }
|
||||
|
||||
public bool DoNotColor{ get; set; }
|
||||
|
||||
public CraftMarkOption MarkOption{ get; set; }
|
||||
|
||||
public CraftItem LastMade
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Items.Count > 0)
|
||||
return Items[0];
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMade(CraftItem item)
|
||||
{
|
||||
Items.Remove(item);
|
||||
|
||||
if (Items.Count == 10)
|
||||
Items.RemoveAt(9);
|
||||
|
||||
Items.Insert(0, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Projects/Scripts/Engines/Craft/Core/CraftGroup.cs
Normal file
23
Projects/Scripts/Engines/Craft/Core/CraftGroup.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftGroup
|
||||
{
|
||||
public CraftGroup(TextDefinition groupName)
|
||||
{
|
||||
NameNumber = groupName;
|
||||
NameString = groupName;
|
||||
CraftItems = new CraftItemCol();
|
||||
}
|
||||
|
||||
public CraftItemCol CraftItems{ get; }
|
||||
|
||||
public string NameString{ get; }
|
||||
|
||||
public int NameNumber{ get; }
|
||||
|
||||
public void AddCraftItem(CraftItem craftItem)
|
||||
{
|
||||
CraftItems.Add(craftItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Projects/Scripts/Engines/Craft/Core/CraftGroupCol.cs
Normal file
45
Projects/Scripts/Engines/Craft/Core/CraftGroupCol.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftGroupCol : CollectionBase
|
||||
{
|
||||
public int Add(CraftGroup craftGroup)
|
||||
{
|
||||
return List.Add(craftGroup);
|
||||
}
|
||||
|
||||
public void Remove(int index)
|
||||
{
|
||||
if (index > Count - 1 || index < 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
List.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public CraftGroup GetAt(int index)
|
||||
{
|
||||
return (CraftGroup)List[index];
|
||||
}
|
||||
|
||||
public int SearchFor(TextDefinition groupName)
|
||||
{
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
{
|
||||
CraftGroup craftGroup = (CraftGroup)List[i];
|
||||
|
||||
int nameNumber = craftGroup.NameNumber;
|
||||
string nameString = craftGroup.NameString;
|
||||
|
||||
if (nameNumber != 0 && nameNumber == groupName.Number ||
|
||||
nameString != null && nameString == groupName.String)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
608
Projects/Scripts/Engines/Craft/Core/CraftGump.cs
Normal file
608
Projects/Scripts/Engines/Craft/Core/CraftGump.cs
Normal file
|
|
@ -0,0 +1,608 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftGump : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480;
|
||||
private const int LabelColor = 0x7FFF;
|
||||
private const int FontColor = 0xFFFFFF;
|
||||
private CraftSystem m_CraftSystem;
|
||||
private Mobile m_From;
|
||||
|
||||
private CraftPage m_Page;
|
||||
private BaseTool m_Tool;
|
||||
|
||||
public CraftGump(Mobile from, CraftSystem craftSystem, BaseTool tool, object notice, CraftPage page = CraftPage.None) : base(40, 40)
|
||||
{
|
||||
m_From = from;
|
||||
m_CraftSystem = craftSystem;
|
||||
m_Tool = tool;
|
||||
m_Page = page;
|
||||
|
||||
CraftContext context = craftSystem.GetContext(from);
|
||||
|
||||
from.CloseGump<CraftGump>();
|
||||
from.CloseGump<CraftGumpItem>();
|
||||
|
||||
AddPage(0);
|
||||
|
||||
AddBackground(0, 0, 530, 437, 5054);
|
||||
AddImageTiled(10, 10, 510, 22, 2624);
|
||||
AddImageTiled(10, 292, 150, 45, 2624);
|
||||
AddImageTiled(165, 292, 355, 45, 2624);
|
||||
AddImageTiled(10, 342, 510, 85, 2624);
|
||||
AddImageTiled(10, 37, 200, 250, 2624);
|
||||
AddImageTiled(215, 37, 305, 250, 2624);
|
||||
AddAlphaRegion(10, 10, 510, 417);
|
||||
|
||||
if (craftSystem.GumpTitleNumber > 0)
|
||||
AddHtmlLocalized(10, 12, 510, 20, craftSystem.GumpTitleNumber, LabelColor);
|
||||
else
|
||||
AddHtml(10, 12, 510, 20, craftSystem.GumpTitleString);
|
||||
|
||||
AddHtmlLocalized(10, 37, 200, 22, 1044010, LabelColor); // <CENTER>CATEGORIES</CENTER>
|
||||
AddHtmlLocalized(215, 37, 305, 22, 1044011, LabelColor); // <CENTER>SELECTIONS</CENTER>
|
||||
AddHtmlLocalized(10, 302, 150, 25, 1044012, LabelColor); // <CENTER>NOTICES</CENTER>
|
||||
|
||||
AddButton(15, 402, 4017, 4019, 0);
|
||||
AddHtmlLocalized(50, 405, 150, 18, 1011441, LabelColor); // EXIT
|
||||
|
||||
AddButton(270, 402, 4005, 4007, GetButtonID(6, 2));
|
||||
AddHtmlLocalized(305, 405, 150, 18, 1044013, LabelColor); // MAKE LAST
|
||||
|
||||
// Mark option
|
||||
if (craftSystem.MarkOption)
|
||||
{
|
||||
AddButton(270, 362, 4005, 4007, GetButtonID(6, 6));
|
||||
AddHtmlLocalized(305, 365, 150, 18, 1044017 + (context == null ? 0 : (int)context.MarkOption), LabelColor); // MARK ITEM
|
||||
}
|
||||
// ****************************************
|
||||
|
||||
// Resmelt option
|
||||
if (craftSystem.Resmelt)
|
||||
{
|
||||
AddButton(15, 342, 4005, 4007, GetButtonID(6, 1));
|
||||
AddHtmlLocalized(50, 345, 150, 18, 1044259, LabelColor); // SMELT ITEM
|
||||
}
|
||||
// ****************************************
|
||||
|
||||
// Repair option
|
||||
if (craftSystem.Repair)
|
||||
{
|
||||
AddButton(270, 342, 4005, 4007, GetButtonID(6, 5));
|
||||
AddHtmlLocalized(305, 345, 150, 18, 1044260, LabelColor); // REPAIR ITEM
|
||||
}
|
||||
// ****************************************
|
||||
|
||||
// Enhance option
|
||||
if (craftSystem.CanEnhance)
|
||||
{
|
||||
AddButton(270, 382, 4005, 4007, GetButtonID(6, 8));
|
||||
AddHtmlLocalized(305, 385, 150, 18, 1061001, LabelColor); // ENHANCE ITEM
|
||||
}
|
||||
// ****************************************
|
||||
|
||||
if (notice is int noticeInt && noticeInt > 0)
|
||||
AddHtmlLocalized(170, 295, 350, 40, noticeInt, LabelColor);
|
||||
else if (notice is string)
|
||||
AddHtml(170, 295, 350, 40, $"<BASEFONT COLOR=#{FontColor:X6}>{notice}</BASEFONT>");
|
||||
|
||||
// If the system has more than one resource
|
||||
if (craftSystem.CraftSubRes.Init)
|
||||
{
|
||||
string nameString = craftSystem.CraftSubRes.NameString;
|
||||
int nameNumber = craftSystem.CraftSubRes.NameNumber;
|
||||
|
||||
int resIndex = context?.LastResourceIndex ?? -1;
|
||||
|
||||
Type resourceType = craftSystem.CraftSubRes.ResType;
|
||||
|
||||
if (resIndex > -1)
|
||||
{
|
||||
CraftSubRes subResource = craftSystem.CraftSubRes.GetAt(resIndex);
|
||||
|
||||
nameString = subResource.NameString;
|
||||
nameNumber = subResource.NameNumber;
|
||||
resourceType = subResource.ItemType;
|
||||
}
|
||||
|
||||
int resourceCount = 0;
|
||||
|
||||
if (from.Backpack != null)
|
||||
{
|
||||
Item[] items = from.Backpack.FindItemsByType(resourceType);
|
||||
|
||||
for (int i = 0; i < items.Length; ++i)
|
||||
resourceCount += items[i].Amount;
|
||||
}
|
||||
|
||||
AddButton(15, 362, 4005, 4007, GetButtonID(6, 0));
|
||||
|
||||
if (nameNumber > 0)
|
||||
AddHtmlLocalized(50, 365, 250, 18, nameNumber, resourceCount.ToString(), LabelColor);
|
||||
else
|
||||
AddLabel(50, 362, LabelHue, $"{nameString} ({resourceCount} Available)");
|
||||
}
|
||||
// ****************************************
|
||||
|
||||
// For dragon scales
|
||||
if (craftSystem.CraftSubRes2.Init)
|
||||
{
|
||||
string nameString = craftSystem.CraftSubRes2.NameString;
|
||||
int nameNumber = craftSystem.CraftSubRes2.NameNumber;
|
||||
|
||||
int resIndex = context?.LastResourceIndex2 ?? -1;
|
||||
|
||||
Type resourceType = craftSystem.CraftSubRes2.ResType;
|
||||
|
||||
if (resIndex > -1)
|
||||
{
|
||||
CraftSubRes subResource = craftSystem.CraftSubRes2.GetAt(resIndex);
|
||||
|
||||
nameString = subResource.NameString;
|
||||
nameNumber = subResource.NameNumber;
|
||||
resourceType = subResource.ItemType;
|
||||
}
|
||||
|
||||
int resourceCount = 0;
|
||||
|
||||
if (from.Backpack != null)
|
||||
{
|
||||
Item[] items = from.Backpack.FindItemsByType(resourceType);
|
||||
|
||||
for (int i = 0; i < items.Length; ++i)
|
||||
resourceCount += items[i].Amount;
|
||||
}
|
||||
|
||||
AddButton(15, 382, 4005, 4007, GetButtonID(6, 7));
|
||||
|
||||
if (nameNumber > 0)
|
||||
AddHtmlLocalized(50, 385, 250, 18, nameNumber, resourceCount.ToString(), LabelColor);
|
||||
else
|
||||
AddLabel(50, 385, LabelHue, $"{nameString} ({resourceCount} Available)");
|
||||
}
|
||||
// ****************************************
|
||||
|
||||
CreateGroupList();
|
||||
|
||||
if (page == CraftPage.PickResource)
|
||||
CreateResList(false, from);
|
||||
else if (page == CraftPage.PickResource2)
|
||||
CreateResList(true, from);
|
||||
else if (context?.LastGroupIndex > -1)
|
||||
CreateItemList(context.LastGroupIndex);
|
||||
}
|
||||
|
||||
public void CreateResList(bool opt, Mobile from)
|
||||
{
|
||||
CraftSubResCol res = opt ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes;
|
||||
|
||||
for (int i = 0; i < res.Count; ++i)
|
||||
{
|
||||
int index = i % 10;
|
||||
|
||||
CraftSubRes subResource = res.GetAt(i);
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
if (i > 0)
|
||||
AddButton(485, 260, 4005, 4007, 0, GumpButtonType.Page, i / 10 + 1);
|
||||
|
||||
AddPage(i / 10 + 1);
|
||||
|
||||
if (i > 0)
|
||||
AddButton(455, 260, 4014, 4015, 0, GumpButtonType.Page, i / 10);
|
||||
|
||||
CraftContext context = m_CraftSystem.GetContext(m_From);
|
||||
|
||||
AddButton(220, 260, 4005, 4007, GetButtonID(6, 4));
|
||||
AddHtmlLocalized(255, 263, 200, 18, context == null || !context.DoNotColor ? 1061591 : 1061590,
|
||||
LabelColor);
|
||||
}
|
||||
|
||||
int resourceCount = 0;
|
||||
|
||||
if (from.Backpack != null)
|
||||
{
|
||||
Item[] items = from.Backpack.FindItemsByType(subResource.ItemType);
|
||||
|
||||
for (int j = 0; j < items.Length; ++j)
|
||||
resourceCount += items[j].Amount;
|
||||
}
|
||||
|
||||
AddButton(220, 60 + index * 20, 4005, 4007, GetButtonID(5, i));
|
||||
|
||||
if (subResource.NameNumber > 0)
|
||||
AddHtmlLocalized(255, 63 + index * 20, 250, 18, subResource.NameNumber, resourceCount.ToString(),
|
||||
LabelColor);
|
||||
else
|
||||
AddLabel(255, 60 + index * 20, LabelHue, $"{subResource.NameString} ({resourceCount})");
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateMakeLastList()
|
||||
{
|
||||
CraftContext context = m_CraftSystem.GetContext(m_From);
|
||||
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
List<CraftItem> items = context.Items;
|
||||
|
||||
if (items.Count > 0)
|
||||
for (int i = 0; i < items.Count; ++i)
|
||||
{
|
||||
int index = i % 10;
|
||||
|
||||
CraftItem craftItem = items[i];
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
AddButton(370, 260, 4005, 4007, 0, GumpButtonType.Page, i / 10 + 1);
|
||||
AddHtmlLocalized(405, 263, 100, 18, 1044045, LabelColor); // NEXT PAGE
|
||||
}
|
||||
|
||||
AddPage(i / 10 + 1);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
AddButton(220, 260, 4014, 4015, 0, GumpButtonType.Page, i / 10);
|
||||
AddHtmlLocalized(255, 263, 100, 18, 1044044, LabelColor); // PREV PAGE
|
||||
}
|
||||
}
|
||||
|
||||
AddButton(220, 60 + index * 20, 4005, 4007, GetButtonID(3, i));
|
||||
|
||||
if (craftItem.NameNumber > 0)
|
||||
AddHtmlLocalized(255, 63 + index * 20, 220, 18, craftItem.NameNumber, LabelColor);
|
||||
else
|
||||
AddLabel(255, 60 + index * 20, LabelHue, craftItem.NameString);
|
||||
|
||||
AddButton(480, 60 + index * 20, 4011, 4012, GetButtonID(4, i));
|
||||
}
|
||||
else
|
||||
AddHtmlLocalized(230, 62, 200, 22, 1044165, LabelColor); // You haven't made anything yet.
|
||||
}
|
||||
|
||||
public void CreateItemList(int selectedGroup)
|
||||
{
|
||||
if (selectedGroup == 501) // 501 : Last 10
|
||||
{
|
||||
CreateMakeLastList();
|
||||
return;
|
||||
}
|
||||
|
||||
CraftGroupCol craftGroupCol = m_CraftSystem.CraftGroups;
|
||||
CraftGroup craftGroup = craftGroupCol.GetAt(selectedGroup);
|
||||
CraftItemCol craftItemCol = craftGroup.CraftItems;
|
||||
|
||||
for (int i = 0; i < craftItemCol.Count; ++i)
|
||||
{
|
||||
int index = i % 10;
|
||||
|
||||
CraftItem craftItem = craftItemCol.GetAt(i);
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
AddButton(370, 260, 4005, 4007, 0, GumpButtonType.Page, i / 10 + 1);
|
||||
AddHtmlLocalized(405, 263, 100, 18, 1044045, LabelColor); // NEXT PAGE
|
||||
}
|
||||
|
||||
AddPage(i / 10 + 1);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
AddButton(220, 260, 4014, 4015, 0, GumpButtonType.Page, i / 10);
|
||||
AddHtmlLocalized(255, 263, 100, 18, 1044044, LabelColor); // PREV PAGE
|
||||
}
|
||||
}
|
||||
|
||||
AddButton(220, 60 + index * 20, 4005, 4007, GetButtonID(1, i));
|
||||
|
||||
if (craftItem.NameNumber > 0)
|
||||
AddHtmlLocalized(255, 63 + index * 20, 220, 18, craftItem.NameNumber, LabelColor);
|
||||
else
|
||||
AddLabel(255, 60 + index * 20, LabelHue, craftItem.NameString);
|
||||
|
||||
AddButton(480, 60 + index * 20, 4011, 4012, GetButtonID(2, i));
|
||||
}
|
||||
}
|
||||
|
||||
public int CreateGroupList()
|
||||
{
|
||||
CraftGroupCol craftGroupCol = m_CraftSystem.CraftGroups;
|
||||
|
||||
AddButton(15, 60, 4005, 4007, GetButtonID(6, 3));
|
||||
AddHtmlLocalized(50, 63, 150, 18, 1044014, LabelColor); // LAST TEN
|
||||
|
||||
for (int i = 0; i < craftGroupCol.Count; i++)
|
||||
{
|
||||
CraftGroup craftGroup = craftGroupCol.GetAt(i);
|
||||
|
||||
AddButton(15, 80 + i * 20, 4005, 4007, GetButtonID(0, i));
|
||||
|
||||
if (craftGroup.NameNumber > 0)
|
||||
AddHtmlLocalized(50, 83 + i * 20, 150, 18, craftGroup.NameNumber, LabelColor);
|
||||
else
|
||||
AddLabel(50, 80 + i * 20, LabelHue, craftGroup.NameString);
|
||||
}
|
||||
|
||||
return craftGroupCol.Count;
|
||||
}
|
||||
|
||||
public static int GetButtonID(int type, int index)
|
||||
{
|
||||
return 1 + type + index * 7;
|
||||
}
|
||||
|
||||
public void CraftItem(CraftItem item)
|
||||
{
|
||||
int num = m_CraftSystem.CanCraft(m_From, m_Tool, item.ItemType);
|
||||
|
||||
if (num > 0)
|
||||
{
|
||||
m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num));
|
||||
}
|
||||
else
|
||||
{
|
||||
Type type = null;
|
||||
|
||||
CraftContext context = m_CraftSystem.GetContext(m_From);
|
||||
|
||||
if (context != null)
|
||||
{
|
||||
CraftSubResCol res = item.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes;
|
||||
int resIndex = item.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex;
|
||||
|
||||
if (resIndex >= 0 && resIndex < res.Count)
|
||||
type = res.GetAt(resIndex).ItemType;
|
||||
}
|
||||
|
||||
m_CraftSystem.CreateItem(m_From, item.ItemType, type, m_Tool, item);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, RelayInfo info)
|
||||
{
|
||||
if (info.ButtonID <= 0)
|
||||
return; // Canceled
|
||||
|
||||
int buttonID = info.ButtonID - 1;
|
||||
int type = buttonID % 7;
|
||||
int index = buttonID / 7;
|
||||
|
||||
CraftSystem system = m_CraftSystem;
|
||||
CraftGroupCol groups = system.CraftGroups;
|
||||
CraftContext context = system.GetContext(m_From);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0: // Show group
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
if (index >= 0 && index < groups.Count)
|
||||
{
|
||||
context.LastGroupIndex = index;
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, null));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: // Create item
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
int groupIndex = context.LastGroupIndex;
|
||||
|
||||
if (groupIndex >= 0 && groupIndex < groups.Count)
|
||||
{
|
||||
CraftGroup group = groups.GetAt(groupIndex);
|
||||
|
||||
if (index >= 0 && index < group.CraftItems.Count)
|
||||
CraftItem(group.CraftItems.GetAt(index));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2: // Item details
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
int groupIndex = context.LastGroupIndex;
|
||||
|
||||
if (groupIndex >= 0 && groupIndex < groups.Count)
|
||||
{
|
||||
CraftGroup group = groups.GetAt(groupIndex);
|
||||
|
||||
if (index >= 0 && index < group.CraftItems.Count)
|
||||
m_From.SendGump(new CraftGumpItem(m_From, system, group.CraftItems.GetAt(index), m_Tool));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 3: // Create item (last 10)
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
List<CraftItem> lastTen = context.Items;
|
||||
|
||||
if (index >= 0 && index < lastTen.Count)
|
||||
CraftItem(lastTen[index]);
|
||||
|
||||
break;
|
||||
}
|
||||
case 4: // Item details (last 10)
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
List<CraftItem> lastTen = context.Items;
|
||||
|
||||
if (index >= 0 && index < lastTen.Count)
|
||||
m_From.SendGump(new CraftGumpItem(m_From, system, lastTen[index], m_Tool));
|
||||
|
||||
break;
|
||||
}
|
||||
case 5: // Resource selected
|
||||
{
|
||||
if (m_Page == CraftPage.PickResource && index >= 0 && index < system.CraftSubRes.Count)
|
||||
{
|
||||
CraftSubRes res = system.CraftSubRes.GetAt(index);
|
||||
|
||||
if (m_From.Skills[system.MainSkill].Base < res.RequiredSkill)
|
||||
{
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, res.Message));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (context != null)
|
||||
context.LastResourceIndex = index;
|
||||
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, null));
|
||||
}
|
||||
}
|
||||
else if (m_Page == CraftPage.PickResource2 && index >= 0 && index < system.CraftSubRes2.Count)
|
||||
{
|
||||
CraftSubRes res = system.CraftSubRes2.GetAt(index);
|
||||
|
||||
if (m_From.Skills[system.MainSkill].Base < res.RequiredSkill)
|
||||
{
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, res.Message));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (context != null)
|
||||
context.LastResourceIndex2 = index;
|
||||
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, null));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 6: // Misc. buttons
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0: // Resource selection
|
||||
{
|
||||
if (system.CraftSubRes.Init)
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, null, CraftPage.PickResource));
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: // Smelt item
|
||||
{
|
||||
if (system.Resmelt)
|
||||
Resmelt.Do(m_From, system, m_Tool);
|
||||
|
||||
break;
|
||||
}
|
||||
case 2: // Make last
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
CraftItem item = context.LastMade;
|
||||
|
||||
if (item != null)
|
||||
CraftItem(item);
|
||||
else
|
||||
m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, 1044165,
|
||||
m_Page)); // You haven't made anything yet.
|
||||
|
||||
break;
|
||||
}
|
||||
case 3: // Last 10
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
context.LastGroupIndex = 501;
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, null));
|
||||
|
||||
break;
|
||||
}
|
||||
case 4: // Toggle use resource hue
|
||||
{
|
||||
if (context == null)
|
||||
break;
|
||||
|
||||
context.DoNotColor = !context.DoNotColor;
|
||||
|
||||
m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, null, m_Page));
|
||||
|
||||
break;
|
||||
}
|
||||
case 5: // Repair item
|
||||
{
|
||||
if (system.Repair)
|
||||
Repair.Do(m_From, system, m_Tool);
|
||||
|
||||
break;
|
||||
}
|
||||
case 6: // Toggle mark option
|
||||
{
|
||||
if (context == null || !system.MarkOption)
|
||||
break;
|
||||
|
||||
switch (context.MarkOption)
|
||||
{
|
||||
case CraftMarkOption.MarkItem:
|
||||
context.MarkOption = CraftMarkOption.DoNotMark;
|
||||
break;
|
||||
case CraftMarkOption.DoNotMark:
|
||||
context.MarkOption = CraftMarkOption.PromptForMark;
|
||||
break;
|
||||
case CraftMarkOption.PromptForMark:
|
||||
context.MarkOption = CraftMarkOption.MarkItem;
|
||||
break;
|
||||
}
|
||||
|
||||
m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, null, m_Page));
|
||||
|
||||
break;
|
||||
}
|
||||
case 7: // Resource selection 2
|
||||
{
|
||||
if (system.CraftSubRes2.Init)
|
||||
m_From.SendGump(new CraftGump(m_From, system, m_Tool, null, CraftPage.PickResource2));
|
||||
|
||||
break;
|
||||
}
|
||||
case 8: // Enhance item
|
||||
{
|
||||
if (system.CanEnhance)
|
||||
Enhance.BeginTarget(m_From, system, m_Tool);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum CraftPage
|
||||
{
|
||||
None,
|
||||
PickResource,
|
||||
PickResource2
|
||||
}
|
||||
}
|
||||
}
|
||||
289
Projects/Scripts/Engines/Craft/Core/CraftGumpItem.cs
Normal file
289
Projects/Scripts/Engines/Craft/Core/CraftGumpItem.cs
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
using System;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftGumpItem : Gump
|
||||
{
|
||||
private const int LabelHue = 0x480; // 0x384
|
||||
private const int RedLabelHue = 0x20;
|
||||
|
||||
private const int LabelColor = 0x7FFF;
|
||||
private const int RedLabelColor = 0x6400;
|
||||
|
||||
private const int GreyLabelColor = 0x3DEF;
|
||||
|
||||
private static Type typeofBlankScroll = typeof(BlankScroll);
|
||||
private static Type typeofSpellScroll = typeof(SpellScroll);
|
||||
private CraftItem m_CraftItem;
|
||||
private CraftSystem m_CraftSystem;
|
||||
private Mobile m_From;
|
||||
|
||||
private int m_OtherCount;
|
||||
|
||||
private bool m_ShowExceptionalChance;
|
||||
private BaseTool m_Tool;
|
||||
|
||||
public CraftGumpItem(Mobile from, CraftSystem craftSystem, CraftItem craftItem, BaseTool tool) : base(40, 40)
|
||||
{
|
||||
m_From = from;
|
||||
m_CraftSystem = craftSystem;
|
||||
m_CraftItem = craftItem;
|
||||
m_Tool = tool;
|
||||
|
||||
from.CloseGump<CraftGump>();
|
||||
from.CloseGump<CraftGumpItem>();
|
||||
|
||||
AddPage(0);
|
||||
AddBackground(0, 0, 530, 417, 5054);
|
||||
AddImageTiled(10, 10, 510, 22, 2624);
|
||||
AddImageTiled(10, 37, 150, 148, 2624);
|
||||
AddImageTiled(165, 37, 355, 90, 2624);
|
||||
AddImageTiled(10, 190, 155, 22, 2624);
|
||||
AddImageTiled(10, 217, 150, 53, 2624);
|
||||
AddImageTiled(165, 132, 355, 80, 2624);
|
||||
AddImageTiled(10, 275, 155, 22, 2624);
|
||||
AddImageTiled(10, 302, 150, 53, 2624);
|
||||
AddImageTiled(165, 217, 355, 80, 2624);
|
||||
AddImageTiled(10, 360, 155, 22, 2624);
|
||||
AddImageTiled(165, 302, 355, 80, 2624);
|
||||
AddImageTiled(10, 387, 510, 22, 2624);
|
||||
AddAlphaRegion(10, 10, 510, 399);
|
||||
|
||||
AddHtmlLocalized(170, 40, 150, 20, 1044053, LabelColor); // ITEM
|
||||
AddHtmlLocalized(10, 192, 150, 22, 1044054, LabelColor); // <CENTER>SKILLS</CENTER>
|
||||
AddHtmlLocalized(10, 277, 150, 22, 1044055, LabelColor); // <CENTER>MATERIALS</CENTER>
|
||||
AddHtmlLocalized(10, 362, 150, 22, 1044056, LabelColor); // <CENTER>OTHER</CENTER>
|
||||
|
||||
if (craftSystem.GumpTitleNumber > 0)
|
||||
AddHtmlLocalized(10, 12, 510, 20, craftSystem.GumpTitleNumber, LabelColor);
|
||||
else
|
||||
AddHtml(10, 12, 510, 20, craftSystem.GumpTitleString);
|
||||
|
||||
AddButton(15, 387, 4014, 4016, 0);
|
||||
AddHtmlLocalized(50, 390, 150, 18, 1044150, LabelColor); // BACK
|
||||
|
||||
bool needsRecipe = craftItem.Recipe != null && from is PlayerMobile mobile &&
|
||||
!mobile.HasRecipe(craftItem.Recipe);
|
||||
|
||||
if (needsRecipe)
|
||||
{
|
||||
AddButton(270, 387, 4005, 4007, 0, GumpButtonType.Page);
|
||||
AddHtmlLocalized(305, 390, 150, 18, 1044151, GreyLabelColor); // MAKE NOW
|
||||
}
|
||||
else
|
||||
{
|
||||
AddButton(270, 387, 4005, 4007, 1);
|
||||
AddHtmlLocalized(305, 390, 150, 18, 1044151, LabelColor); // MAKE NOW
|
||||
}
|
||||
|
||||
if (craftItem.NameNumber > 0)
|
||||
AddHtmlLocalized(330, 40, 180, 18, craftItem.NameNumber, LabelColor);
|
||||
else
|
||||
AddLabel(330, 40, LabelHue, craftItem.NameString);
|
||||
|
||||
if (craftItem.UseAllRes)
|
||||
AddHtmlLocalized(170, 302 + m_OtherCount++ * 20, 310, 18, 1048176, LabelColor); // Makes as many as possible at once
|
||||
|
||||
DrawItem();
|
||||
DrawSkill();
|
||||
DrawResource();
|
||||
|
||||
/*
|
||||
if ( craftItem.RequiresSE )
|
||||
AddHtmlLocalized( 170, 302 + (m_OtherCount++ * 20), 310, 18, 1063363, LabelColor, false, false ); //* Requires the "Samurai Empire" expansion
|
||||
* */
|
||||
|
||||
if (craftItem.RequiredExpansion != Expansion.None)
|
||||
{
|
||||
bool supportsEx = from.NetState?.SupportsExpansion(craftItem.RequiredExpansion) == true;
|
||||
TextDefinition.AddHtmlText(this, 170, 302 + m_OtherCount++ * 20, 310, 18,
|
||||
RequiredExpansionMessage(craftItem.RequiredExpansion), false, false,
|
||||
supportsEx ? LabelColor : RedLabelColor, supportsEx ? LabelHue : RedLabelHue);
|
||||
}
|
||||
|
||||
if (needsRecipe)
|
||||
AddHtmlLocalized(170, 302 + m_OtherCount++ * 20, 310, 18, 1073620, RedLabelColor); // You have not learned this recipe.
|
||||
}
|
||||
|
||||
private TextDefinition RequiredExpansionMessage(Expansion expansion)
|
||||
{
|
||||
switch (expansion)
|
||||
{
|
||||
case Expansion.SE:
|
||||
return 1063363; // * Requires the "Samurai Empire" expansion
|
||||
case Expansion.ML:
|
||||
return 1072651; // * Requires the "Mondain's Legacy" expansion
|
||||
default:
|
||||
return $"* Requires the \"{ExpansionInfo.GetInfo(expansion).Name}\" expansion";
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawItem()
|
||||
{
|
||||
Type type = m_CraftItem.ItemType;
|
||||
|
||||
AddItem(20, 50, CraftItem.ItemIDOf(type), m_CraftItem.ItemHue);
|
||||
|
||||
if (m_CraftItem.IsMarkable(type))
|
||||
{
|
||||
AddHtmlLocalized(170, 302 + m_OtherCount++ * 20, 310, 18, 1044059, LabelColor); // This item may hold its maker's mark
|
||||
m_ShowExceptionalChance = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawSkill()
|
||||
{
|
||||
for (int i = 0; i < m_CraftItem.Skills.Count; i++)
|
||||
{
|
||||
CraftSkill skill = m_CraftItem.Skills.GetAt(i);
|
||||
double minSkill = skill.MinSkill;
|
||||
|
||||
if (minSkill < 0)
|
||||
minSkill = 0;
|
||||
|
||||
AddHtmlLocalized(170, 132 + i * 20, 200, 18, AosSkillBonuses.GetLabel(skill.SkillToMake), LabelColor);
|
||||
AddLabel(430, 132 + i * 20, LabelHue, $"{minSkill:F1}");
|
||||
}
|
||||
|
||||
CraftSubResCol res = m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes;
|
||||
int resIndex = -1;
|
||||
|
||||
CraftContext context = m_CraftSystem.GetContext(m_From);
|
||||
|
||||
if (context != null)
|
||||
resIndex = m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex;
|
||||
|
||||
bool allRequiredSkills = true;
|
||||
double chance = m_CraftItem.GetSuccessChance(m_From, resIndex > -1 ? res.GetAt(resIndex).ItemType : null,
|
||||
m_CraftSystem, false, ref allRequiredSkills);
|
||||
double excepChance = m_CraftItem.GetExceptionalChance(m_CraftSystem, chance, m_From);
|
||||
|
||||
if (chance < 0.0)
|
||||
chance = 0.0;
|
||||
else if (chance > 1.0)
|
||||
chance = 1.0;
|
||||
|
||||
AddHtmlLocalized(170, 80, 250, 18, 1044057, LabelColor); // Success Chance:
|
||||
AddLabel(430, 80, LabelHue, $"{chance * 100:F1}%");
|
||||
|
||||
if (m_ShowExceptionalChance)
|
||||
{
|
||||
if (excepChance < 0.0)
|
||||
excepChance = 0.0;
|
||||
else if (excepChance > 1.0)
|
||||
excepChance = 1.0;
|
||||
|
||||
AddHtmlLocalized(170, 100, 250, 18, 1044058, 32767); // Exceptional Chance:
|
||||
AddLabel(430, 100, LabelHue, $"{excepChance * 100:F1}%");
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawResource()
|
||||
{
|
||||
bool retainedColor = false;
|
||||
|
||||
CraftContext context = m_CraftSystem.GetContext(m_From);
|
||||
|
||||
CraftSubResCol res = m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes;
|
||||
int resIndex = -1;
|
||||
|
||||
if (context != null)
|
||||
resIndex = m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex;
|
||||
|
||||
bool cropScroll = m_CraftItem.Resources.Count > 1
|
||||
&& m_CraftItem.Resources.GetAt(m_CraftItem.Resources.Count - 1).ItemType == typeofBlankScroll
|
||||
&& typeofSpellScroll.IsAssignableFrom(m_CraftItem.ItemType);
|
||||
|
||||
for (int i = 0; i < m_CraftItem.Resources.Count - (cropScroll ? 1 : 0) && i < 4; i++)
|
||||
{
|
||||
Type type;
|
||||
string nameString;
|
||||
int nameNumber;
|
||||
|
||||
CraftRes craftResource = m_CraftItem.Resources.GetAt(i);
|
||||
|
||||
type = craftResource.ItemType;
|
||||
nameString = craftResource.NameString;
|
||||
nameNumber = craftResource.NameNumber;
|
||||
|
||||
// Resource Mutation
|
||||
if (type == res.ResType && resIndex > -1)
|
||||
{
|
||||
CraftSubRes subResource = res.GetAt(resIndex);
|
||||
|
||||
type = subResource.ItemType;
|
||||
|
||||
nameString = subResource.NameString;
|
||||
nameNumber = subResource.GenericNameNumber;
|
||||
|
||||
if (nameNumber <= 0)
|
||||
nameNumber = subResource.NameNumber;
|
||||
}
|
||||
// ******************
|
||||
|
||||
if (!retainedColor && m_CraftItem.RetainsColorFrom(m_CraftSystem, type))
|
||||
{
|
||||
retainedColor = true;
|
||||
AddHtmlLocalized(170, 302 + m_OtherCount++ * 20, 310, 18, 1044152, LabelColor); // * The item retains the color of this material
|
||||
AddLabel(500, 219 + i * 20, LabelHue, "*");
|
||||
}
|
||||
|
||||
if (nameNumber > 0)
|
||||
AddHtmlLocalized(170, 219 + i * 20, 310, 18, nameNumber, LabelColor);
|
||||
else
|
||||
AddLabel(170, 219 + i * 20, LabelHue, nameString);
|
||||
|
||||
AddLabel(430, 219 + i * 20, LabelHue, craftResource.Amount.ToString());
|
||||
}
|
||||
|
||||
if (m_CraftItem.NameNumber == 1041267) // runebook
|
||||
{
|
||||
AddHtmlLocalized(170, 219 + m_CraftItem.Resources.Count * 20, 310, 18, 1044447, LabelColor);
|
||||
AddLabel(430, 219 + m_CraftItem.Resources.Count * 20, LabelHue, "1");
|
||||
}
|
||||
|
||||
if (cropScroll)
|
||||
AddHtmlLocalized(170, 302 + m_OtherCount++ * 20, 360, 18, 1044379, LabelColor); // Inscribing scrolls also requires a blank scroll and mana.
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, RelayInfo info)
|
||||
{
|
||||
// Back Button
|
||||
if (info.ButtonID == 0)
|
||||
{
|
||||
CraftGump craftGump = new CraftGump(m_From, m_CraftSystem, m_Tool, null);
|
||||
m_From.SendGump(craftGump);
|
||||
}
|
||||
else // Make Button
|
||||
{
|
||||
int num = m_CraftSystem.CanCraft(m_From, m_Tool, m_CraftItem.ItemType);
|
||||
|
||||
if (num > 0)
|
||||
{
|
||||
m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num));
|
||||
}
|
||||
else
|
||||
{
|
||||
Type type = null;
|
||||
|
||||
CraftContext context = m_CraftSystem.GetContext(m_From);
|
||||
|
||||
if (context != null)
|
||||
{
|
||||
CraftSubResCol res = m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes;
|
||||
int resIndex = m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex;
|
||||
|
||||
if (resIndex > -1)
|
||||
type = res.GetAt(resIndex).ItemType;
|
||||
}
|
||||
|
||||
m_CraftSystem.CreateItem(m_From, m_CraftItem.ItemType, type, m_Tool, m_CraftItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1248
Projects/Scripts/Engines/Craft/Core/CraftItem.cs
Normal file
1248
Projects/Scripts/Engines/Craft/Core/CraftItem.cs
Normal file
File diff suppressed because it is too large
Load diff
53
Projects/Scripts/Engines/Craft/Core/CraftItemCol.cs
Normal file
53
Projects/Scripts/Engines/Craft/Core/CraftItemCol.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftItemCol : CollectionBase
|
||||
{
|
||||
public int Add(CraftItem craftItem)
|
||||
{
|
||||
return List.Add(craftItem);
|
||||
}
|
||||
|
||||
public void Remove(int index)
|
||||
{
|
||||
if (index > Count - 1 || index < 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
List.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public CraftItem GetAt(int index)
|
||||
{
|
||||
return (CraftItem)List[index];
|
||||
}
|
||||
|
||||
public CraftItem SearchForSubclass(Type type)
|
||||
{
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
{
|
||||
CraftItem craftItem = (CraftItem)List[i];
|
||||
|
||||
if (craftItem.ItemType == type || type.IsSubclassOf(craftItem.ItemType))
|
||||
return craftItem;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CraftItem SearchFor(Type type)
|
||||
{
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
{
|
||||
CraftItem craftItem = (CraftItem)List[i];
|
||||
if (craftItem.ItemType == type) return craftItem;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Projects/Scripts/Engines/Craft/Core/CraftItemIDAttribute.cs
Normal file
15
Projects/Scripts/Engines/Craft/Core/CraftItemIDAttribute.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class CraftItemIDAttribute : Attribute
|
||||
{
|
||||
public CraftItemIDAttribute(int itemID)
|
||||
{
|
||||
ItemID = itemID;
|
||||
}
|
||||
|
||||
public int ItemID{ get; }
|
||||
}
|
||||
}
|
||||
41
Projects/Scripts/Engines/Craft/Core/CraftRes.cs
Normal file
41
Projects/Scripts/Engines/Craft/Core/CraftRes.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftRes
|
||||
{
|
||||
public CraftRes(Type type, TextDefinition name, int amount, TextDefinition message = null)
|
||||
{
|
||||
ItemType = type;
|
||||
Amount = amount;
|
||||
|
||||
NameNumber = name;
|
||||
MessageNumber = message;
|
||||
|
||||
NameString = name;
|
||||
MessageString = message;
|
||||
}
|
||||
|
||||
public Type ItemType{ get; }
|
||||
|
||||
public string MessageString{ get; }
|
||||
|
||||
public int MessageNumber{ get; }
|
||||
|
||||
public string NameString{ get; }
|
||||
|
||||
public int NameNumber{ get; }
|
||||
|
||||
public int Amount{ get; }
|
||||
|
||||
public void SendMessage(Mobile from)
|
||||
{
|
||||
if (MessageNumber > 0)
|
||||
from.SendLocalizedMessage(MessageNumber);
|
||||
else if (!string.IsNullOrEmpty(MessageString))
|
||||
from.SendMessage(MessageString);
|
||||
else
|
||||
from.SendLocalizedMessage(502925); // You don't have the resources required to make that item.
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Projects/Scripts/Engines/Craft/Core/CraftResCol.cs
Normal file
28
Projects/Scripts/Engines/Craft/Core/CraftResCol.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftResCol : CollectionBase
|
||||
{
|
||||
public void Add(CraftRes craftRes)
|
||||
{
|
||||
List.Add(craftRes);
|
||||
}
|
||||
|
||||
public void Remove(int index)
|
||||
{
|
||||
if (index > Count - 1 || index < 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
List.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public CraftRes GetAt(int index)
|
||||
{
|
||||
return (CraftRes)List[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Projects/Scripts/Engines/Craft/Core/CraftSkill.cs
Normal file
18
Projects/Scripts/Engines/Craft/Core/CraftSkill.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftSkill
|
||||
{
|
||||
public CraftSkill(SkillName skillToMake, double minSkill, double maxSkill)
|
||||
{
|
||||
SkillToMake = skillToMake;
|
||||
MinSkill = minSkill;
|
||||
MaxSkill = maxSkill;
|
||||
}
|
||||
|
||||
public SkillName SkillToMake{ get; }
|
||||
|
||||
public double MinSkill{ get; }
|
||||
|
||||
public double MaxSkill{ get; }
|
||||
}
|
||||
}
|
||||
28
Projects/Scripts/Engines/Craft/Core/CraftSkillCol.cs
Normal file
28
Projects/Scripts/Engines/Craft/Core/CraftSkillCol.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftSkillCol : CollectionBase
|
||||
{
|
||||
public void Add(CraftSkill craftSkill)
|
||||
{
|
||||
List.Add(craftSkill);
|
||||
}
|
||||
|
||||
public void Remove(int index)
|
||||
{
|
||||
if (index > Count - 1 || index < 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
List.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public CraftSkill GetAt(int index)
|
||||
{
|
||||
return (CraftSkill)List[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Projects/Scripts/Engines/Craft/Core/CraftSubRes.cs
Normal file
34
Projects/Scripts/Engines/Craft/Core/CraftSubRes.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftSubRes
|
||||
{
|
||||
public CraftSubRes(Type type, TextDefinition name, double reqSkill, object message) : this(type, name, reqSkill, 0,
|
||||
message)
|
||||
{
|
||||
}
|
||||
|
||||
public CraftSubRes(Type type, TextDefinition name, double reqSkill, int genericNameNumber, object message)
|
||||
{
|
||||
ItemType = type;
|
||||
NameNumber = name;
|
||||
NameString = name;
|
||||
RequiredSkill = reqSkill;
|
||||
GenericNameNumber = genericNameNumber;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public Type ItemType{ get; }
|
||||
|
||||
public string NameString{ get; }
|
||||
|
||||
public int NameNumber{ get; }
|
||||
|
||||
public int GenericNameNumber{ get; }
|
||||
|
||||
public object Message{ get; }
|
||||
|
||||
public double RequiredSkill{ get; }
|
||||
}
|
||||
}
|
||||
53
Projects/Scripts/Engines/Craft/Core/CraftSubResCol.cs
Normal file
53
Projects/Scripts/Engines/Craft/Core/CraftSubResCol.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class CraftSubResCol : CollectionBase
|
||||
{
|
||||
public CraftSubResCol()
|
||||
{
|
||||
Init = false;
|
||||
}
|
||||
|
||||
public bool Init{ get; set; }
|
||||
|
||||
public Type ResType{ get; set; }
|
||||
|
||||
public string NameString{ get; set; }
|
||||
|
||||
public int NameNumber{ get; set; }
|
||||
|
||||
public void Add(CraftSubRes craftSubRes)
|
||||
{
|
||||
List.Add(craftSubRes);
|
||||
}
|
||||
|
||||
public void Remove(int index)
|
||||
{
|
||||
if (index > Count - 1 || index < 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
List.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public CraftSubRes GetAt(int index)
|
||||
{
|
||||
return (CraftSubRes)List[index];
|
||||
}
|
||||
|
||||
public CraftSubRes SearchFor(Type type)
|
||||
{
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
{
|
||||
CraftSubRes craftSubRes = (CraftSubRes)List[i];
|
||||
if (craftSubRes.ItemType == type) return craftSubRes;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
358
Projects/Scripts/Engines/Craft/Core/CraftSystem.cs
Normal file
358
Projects/Scripts/Engines/Craft/Core/CraftSystem.cs
Normal file
|
|
@ -0,0 +1,358 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public enum CraftECA
|
||||
{
|
||||
ChanceMinusSixty,
|
||||
FiftyPercentChanceMinusTenPercent,
|
||||
ChanceMinusSixtyToFourtyFive
|
||||
}
|
||||
|
||||
public abstract class CraftSystem
|
||||
{
|
||||
private Dictionary<Mobile, CraftContext> m_ContextTable = new Dictionary<Mobile, CraftContext>();
|
||||
private List<int> m_RareRecipes;
|
||||
private List<int> m_Recipes;
|
||||
|
||||
public CraftSystem(int minCraftEffect, int maxCraftEffect, double delay)
|
||||
{
|
||||
MinCraftEffect = minCraftEffect;
|
||||
MaxCraftEffect = maxCraftEffect;
|
||||
Delay = delay;
|
||||
|
||||
CraftItems = new CraftItemCol();
|
||||
CraftGroups = new CraftGroupCol();
|
||||
CraftSubRes = new CraftSubResCol();
|
||||
CraftSubRes2 = new CraftSubResCol();
|
||||
|
||||
m_Recipes = new List<int>();
|
||||
m_RareRecipes = new List<int>();
|
||||
|
||||
InitCraftList();
|
||||
}
|
||||
|
||||
public int MinCraftEffect{ get; }
|
||||
|
||||
public int MaxCraftEffect{ get; }
|
||||
|
||||
public double Delay{ get; }
|
||||
|
||||
public CraftItemCol CraftItems{ get; }
|
||||
|
||||
public CraftGroupCol CraftGroups{ get; }
|
||||
|
||||
public CraftSubResCol CraftSubRes{ get; }
|
||||
|
||||
public CraftSubResCol CraftSubRes2{ get; }
|
||||
|
||||
public abstract SkillName MainSkill{ get; }
|
||||
|
||||
public virtual int GumpTitleNumber => 0;
|
||||
public virtual string GumpTitleString => "";
|
||||
|
||||
public virtual CraftECA ECA => CraftECA.ChanceMinusSixty;
|
||||
|
||||
public bool Resmelt{ get; set; }
|
||||
|
||||
public bool Repair{ get; set; }
|
||||
|
||||
public bool MarkOption{ get; set; }
|
||||
|
||||
public bool CanEnhance{ get; set; }
|
||||
|
||||
public abstract double GetChanceAtMin(CraftItem item);
|
||||
|
||||
public virtual bool RetainsColorFrom(CraftItem item, Type type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public CraftContext GetContext(Mobile m)
|
||||
{
|
||||
if (m == null)
|
||||
return null;
|
||||
|
||||
if (m.Deleted)
|
||||
{
|
||||
m_ContextTable.Remove(m);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!m_ContextTable.TryGetValue(m, out CraftContext c))
|
||||
m_ContextTable[m] = c = new CraftContext();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public void OnMade(Mobile m, CraftItem item)
|
||||
{
|
||||
GetContext(m)?.OnMade(item);
|
||||
}
|
||||
|
||||
public virtual bool ConsumeOnFailure(Mobile from, Type resourceType, CraftItem craftItem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CreateItem(Mobile from, Type type, Type typeRes, BaseTool tool, CraftItem realCraftItem)
|
||||
{
|
||||
// Verify if the type is in the list of the craftable item
|
||||
if (CraftItems.SearchFor(type) != null)
|
||||
realCraftItem.Craft(from, this, typeRes, tool);
|
||||
}
|
||||
|
||||
public int RandomRecipe()
|
||||
{
|
||||
if (m_Recipes.Count == 0)
|
||||
return -1;
|
||||
|
||||
return m_Recipes[Utility.Random(m_Recipes.Count)];
|
||||
}
|
||||
|
||||
public int RandomRareRecipe()
|
||||
{
|
||||
if (m_RareRecipes.Count == 0)
|
||||
return -1;
|
||||
|
||||
return m_RareRecipes[Utility.Random(m_RareRecipes.Count)];
|
||||
}
|
||||
|
||||
|
||||
public int AddCraft(Type typeItem, TextDefinition group, TextDefinition name, double minSkill, double maxSkill,
|
||||
Type typeRes, TextDefinition nameRes, int amount)
|
||||
{
|
||||
return AddCraft(typeItem, group, name, MainSkill, minSkill, maxSkill, typeRes, nameRes, amount, "");
|
||||
}
|
||||
|
||||
public int AddCraft(Type typeItem, TextDefinition group, TextDefinition name, double minSkill, double maxSkill,
|
||||
Type typeRes, TextDefinition nameRes, int amount, TextDefinition message)
|
||||
{
|
||||
return AddCraft(typeItem, group, name, MainSkill, minSkill, maxSkill, typeRes, nameRes, amount, message);
|
||||
}
|
||||
|
||||
public int AddCraft(Type typeItem, TextDefinition group, TextDefinition name, SkillName skillToMake, double minSkill,
|
||||
double maxSkill, Type typeRes, TextDefinition nameRes, int amount)
|
||||
{
|
||||
return AddCraft(typeItem, group, name, skillToMake, minSkill, maxSkill, typeRes, nameRes, amount, "");
|
||||
}
|
||||
|
||||
public int AddCraft(Type typeItem, TextDefinition group, TextDefinition name, SkillName skillToMake, double minSkill,
|
||||
double maxSkill, Type typeRes, TextDefinition nameRes, int amount, TextDefinition message)
|
||||
{
|
||||
CraftItem craftItem = new CraftItem(typeItem, group, name);
|
||||
craftItem.AddRes(typeRes, nameRes, amount, message);
|
||||
craftItem.AddSkill(skillToMake, minSkill, maxSkill);
|
||||
|
||||
DoGroup(group, craftItem);
|
||||
return CraftItems.Add(craftItem);
|
||||
}
|
||||
|
||||
|
||||
private void DoGroup(TextDefinition groupName, CraftItem craftItem)
|
||||
{
|
||||
int index = CraftGroups.SearchFor(groupName);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
CraftGroup craftGroup = new CraftGroup(groupName);
|
||||
craftGroup.AddCraftItem(craftItem);
|
||||
CraftGroups.Add(craftGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
CraftGroups.GetAt(index).AddCraftItem(craftItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetItemHue(int index, int hue)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.ItemHue = hue;
|
||||
}
|
||||
|
||||
public void SetManaReq(int index, int mana)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.Mana = mana;
|
||||
}
|
||||
|
||||
public void SetStamReq(int index, int stam)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.Stam = stam;
|
||||
}
|
||||
|
||||
public void SetHitsReq(int index, int hits)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.Hits = hits;
|
||||
}
|
||||
|
||||
public void SetUseAllRes(int index, bool useAll)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.UseAllRes = useAll;
|
||||
}
|
||||
|
||||
public void SetNeedHeat(int index, bool needHeat)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.NeedHeat = needHeat;
|
||||
}
|
||||
|
||||
public void SetNeedOven(int index, bool needOven)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.NeedOven = needOven;
|
||||
}
|
||||
|
||||
public void SetBeverageType(int index, BeverageType requiredBeverage)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.RequiredBeverage = requiredBeverage;
|
||||
}
|
||||
|
||||
public void SetNeedMill(int index, bool needMill)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.NeedMill = needMill;
|
||||
}
|
||||
|
||||
public void SetNeededExpansion(int index, Expansion expansion)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.RequiredExpansion = expansion;
|
||||
}
|
||||
|
||||
public void AddRes(int index, Type type, TextDefinition name, int amount)
|
||||
{
|
||||
AddRes(index, type, name, amount, "");
|
||||
}
|
||||
|
||||
public void AddRes(int index, Type type, TextDefinition name, int amount, TextDefinition message)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.AddRes(type, name, amount, message);
|
||||
}
|
||||
|
||||
public void AddSkill(int index, SkillName skillToMake, double minSkill, double maxSkill)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.AddSkill(skillToMake, minSkill, maxSkill);
|
||||
}
|
||||
|
||||
public void SetUseSubRes2(int index, bool val)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.UseSubRes2 = val;
|
||||
}
|
||||
|
||||
private void AddRecipeBase(int index, int id)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.AddRecipe(id, this);
|
||||
}
|
||||
|
||||
public void AddRecipe(int index, int id)
|
||||
{
|
||||
AddRecipeBase(index, id);
|
||||
m_Recipes.Add(id);
|
||||
}
|
||||
|
||||
public void AddRareRecipe(int index, int id)
|
||||
{
|
||||
AddRecipeBase(index, id);
|
||||
m_RareRecipes.Add(id);
|
||||
}
|
||||
|
||||
public void AddQuestRecipe(int index, int id)
|
||||
{
|
||||
AddRecipeBase(index, id);
|
||||
}
|
||||
|
||||
public void ForceNonExceptional(int index)
|
||||
{
|
||||
CraftItem craftItem = CraftItems.GetAt(index);
|
||||
craftItem.ForceNonExceptional = true;
|
||||
}
|
||||
|
||||
|
||||
public void SetSubRes(Type type, string name)
|
||||
{
|
||||
CraftSubRes.ResType = type;
|
||||
CraftSubRes.NameString = name;
|
||||
CraftSubRes.Init = true;
|
||||
}
|
||||
|
||||
public void SetSubRes(Type type, int name)
|
||||
{
|
||||
CraftSubRes.ResType = type;
|
||||
CraftSubRes.NameNumber = name;
|
||||
CraftSubRes.Init = true;
|
||||
}
|
||||
|
||||
public void AddSubRes(Type type, int name, double reqSkill, object message)
|
||||
{
|
||||
CraftSubRes craftSubRes = new CraftSubRes(type, name, reqSkill, message);
|
||||
CraftSubRes.Add(craftSubRes);
|
||||
}
|
||||
|
||||
public void AddSubRes(Type type, int name, double reqSkill, int genericName, object message)
|
||||
{
|
||||
CraftSubRes craftSubRes = new CraftSubRes(type, name, reqSkill, genericName, message);
|
||||
CraftSubRes.Add(craftSubRes);
|
||||
}
|
||||
|
||||
public void AddSubRes(Type type, string name, double reqSkill, object message)
|
||||
{
|
||||
CraftSubRes craftSubRes = new CraftSubRes(type, name, reqSkill, message);
|
||||
CraftSubRes.Add(craftSubRes);
|
||||
}
|
||||
|
||||
|
||||
public void SetSubRes2(Type type, string name)
|
||||
{
|
||||
CraftSubRes2.ResType = type;
|
||||
CraftSubRes2.NameString = name;
|
||||
CraftSubRes2.Init = true;
|
||||
}
|
||||
|
||||
public void SetSubRes2(Type type, int name)
|
||||
{
|
||||
CraftSubRes2.ResType = type;
|
||||
CraftSubRes2.NameNumber = name;
|
||||
CraftSubRes2.Init = true;
|
||||
}
|
||||
|
||||
public void AddSubRes2(Type type, int name, double reqSkill, object message)
|
||||
{
|
||||
CraftSubRes craftSubRes = new CraftSubRes(type, name, reqSkill, message);
|
||||
CraftSubRes2.Add(craftSubRes);
|
||||
}
|
||||
|
||||
public void AddSubRes2(Type type, int name, double reqSkill, int genericName, object message)
|
||||
{
|
||||
CraftSubRes craftSubRes = new CraftSubRes(type, name, reqSkill, genericName, message);
|
||||
CraftSubRes2.Add(craftSubRes);
|
||||
}
|
||||
|
||||
public void AddSubRes2(Type type, string name, double reqSkill, object message)
|
||||
{
|
||||
CraftSubRes craftSubRes = new CraftSubRes(type, name, reqSkill, message);
|
||||
CraftSubRes2.Add(craftSubRes);
|
||||
}
|
||||
|
||||
public abstract void InitCraftList();
|
||||
|
||||
public abstract void PlayCraftEffect(Mobile from);
|
||||
|
||||
public abstract int PlayEndingEffect(Mobile from, bool failed, bool lostMaterial, bool toolBroken, int quality,
|
||||
bool makersMark, CraftItem item);
|
||||
|
||||
public abstract int CanCraft(Mobile from, BaseTool tool, Type itemType);
|
||||
}
|
||||
}
|
||||
34
Projects/Scripts/Engines/Craft/Core/CustomCraft.cs
Normal file
34
Projects/Scripts/Engines/Craft/Core/CustomCraft.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public abstract class CustomCraft
|
||||
{
|
||||
public CustomCraft(Mobile from, CraftItem craftItem, CraftSystem craftSystem, Type typeRes, BaseTool tool,
|
||||
int quality)
|
||||
{
|
||||
From = from;
|
||||
CraftItem = craftItem;
|
||||
CraftSystem = craftSystem;
|
||||
TypeRes = typeRes;
|
||||
Tool = tool;
|
||||
Quality = quality;
|
||||
}
|
||||
|
||||
public Mobile From{ get; }
|
||||
|
||||
public CraftItem CraftItem{ get; }
|
||||
|
||||
public CraftSystem CraftSystem{ get; }
|
||||
|
||||
public Type TypeRes{ get; }
|
||||
|
||||
public BaseTool Tool{ get; }
|
||||
|
||||
public int Quality{ get; }
|
||||
|
||||
public abstract void EndCraftAction();
|
||||
public abstract Item CompleteCraft(out int message);
|
||||
}
|
||||
}
|
||||
340
Projects/Scripts/Engines/Craft/Core/Enhance.cs
Normal file
340
Projects/Scripts/Engines/Craft/Core/Enhance.cs
Normal file
|
|
@ -0,0 +1,340 @@
|
|||
using System;
|
||||
using Server.Items;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public enum EnhanceResult
|
||||
{
|
||||
None,
|
||||
NotInBackpack,
|
||||
BadItem,
|
||||
BadResource,
|
||||
AlreadyEnhanced,
|
||||
Success,
|
||||
Failure,
|
||||
Broken,
|
||||
NoResources,
|
||||
NoSkill
|
||||
}
|
||||
|
||||
public class Enhance
|
||||
{
|
||||
public static EnhanceResult Invoke(Mobile from, CraftSystem craftSystem, BaseTool tool, Item item,
|
||||
CraftResource resource, Type resType, ref object resMessage)
|
||||
{
|
||||
if (item == null)
|
||||
return EnhanceResult.BadItem;
|
||||
|
||||
if (!item.IsChildOf(from.Backpack))
|
||||
return EnhanceResult.NotInBackpack;
|
||||
|
||||
if (!(item is BaseArmor) && !(item is BaseWeapon))
|
||||
return EnhanceResult.BadItem;
|
||||
|
||||
if (item is IArcaneEquip eq && eq.IsArcane)
|
||||
return EnhanceResult.BadItem;
|
||||
|
||||
if (CraftResources.IsStandard(resource))
|
||||
return EnhanceResult.BadResource;
|
||||
|
||||
int num = craftSystem.CanCraft(from, tool, item.GetType());
|
||||
|
||||
if (num > 0)
|
||||
{
|
||||
resMessage = num;
|
||||
return EnhanceResult.None;
|
||||
}
|
||||
|
||||
CraftItem craftItem = craftSystem.CraftItems.SearchFor(item.GetType());
|
||||
|
||||
if (craftItem == null || craftItem.Resources.Count == 0)
|
||||
return EnhanceResult.BadItem;
|
||||
|
||||
bool allRequiredSkills = false;
|
||||
if (craftItem.GetSuccessChance(from, resType, craftSystem, false, ref allRequiredSkills) <= 0.0)
|
||||
return EnhanceResult.NoSkill;
|
||||
|
||||
CraftResourceInfo info = CraftResources.GetInfo(resource);
|
||||
|
||||
if (info == null || info.ResourceTypes.Length == 0)
|
||||
return EnhanceResult.BadResource;
|
||||
|
||||
CraftAttributeInfo attributes = info.AttributeInfo;
|
||||
|
||||
if (attributes == null)
|
||||
return EnhanceResult.BadResource;
|
||||
|
||||
int resHue = 0, maxAmount = 0;
|
||||
|
||||
if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None,
|
||||
ref resMessage))
|
||||
return EnhanceResult.NoResources;
|
||||
|
||||
if (craftSystem is DefBlacksmithy)
|
||||
if (from.FindItemOnLayer(Layer.OneHanded) is AncientSmithyHammer hammer)
|
||||
{
|
||||
hammer.UsesRemaining--;
|
||||
if (hammer.UsesRemaining < 1)
|
||||
hammer.Delete();
|
||||
}
|
||||
|
||||
int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
|
||||
int dura, luck, lreq, dinc = 0;
|
||||
int baseChance;
|
||||
|
||||
bool physBonus = false;
|
||||
bool fireBonus;
|
||||
bool coldBonus;
|
||||
bool nrgyBonus;
|
||||
bool poisBonus;
|
||||
bool duraBonus;
|
||||
bool luckBonus;
|
||||
bool lreqBonus;
|
||||
bool dincBonus;
|
||||
|
||||
if (item is BaseWeapon weapon)
|
||||
{
|
||||
if (!CraftResources.IsStandard(weapon.Resource))
|
||||
return EnhanceResult.AlreadyEnhanced;
|
||||
|
||||
baseChance = 20;
|
||||
|
||||
dura = weapon.MaxHitPoints;
|
||||
luck = weapon.Attributes.Luck;
|
||||
lreq = weapon.WeaponAttributes.LowerStatReq;
|
||||
dinc = weapon.Attributes.WeaponDamage;
|
||||
|
||||
fireBonus = attributes.WeaponFireDamage > 0;
|
||||
coldBonus = attributes.WeaponColdDamage > 0;
|
||||
nrgyBonus = attributes.WeaponEnergyDamage > 0;
|
||||
poisBonus = attributes.WeaponPoisonDamage > 0;
|
||||
|
||||
duraBonus = attributes.WeaponDurability > 0;
|
||||
luckBonus = attributes.WeaponLuck > 0;
|
||||
lreqBonus = attributes.WeaponLowerRequirements > 0;
|
||||
dincBonus = dinc > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseArmor armor = (BaseArmor)item;
|
||||
|
||||
if (!CraftResources.IsStandard(armor.Resource))
|
||||
return EnhanceResult.AlreadyEnhanced;
|
||||
|
||||
baseChance = 20;
|
||||
|
||||
phys = armor.PhysicalResistance;
|
||||
fire = armor.FireResistance;
|
||||
cold = armor.ColdResistance;
|
||||
pois = armor.PoisonResistance;
|
||||
nrgy = armor.EnergyResistance;
|
||||
|
||||
dura = armor.MaxHitPoints;
|
||||
luck = armor.Attributes.Luck;
|
||||
lreq = armor.ArmorAttributes.LowerStatReq;
|
||||
|
||||
physBonus = attributes.ArmorPhysicalResist > 0;
|
||||
fireBonus = attributes.ArmorFireResist > 0;
|
||||
coldBonus = attributes.ArmorColdResist > 0;
|
||||
nrgyBonus = attributes.ArmorEnergyResist > 0;
|
||||
poisBonus = attributes.ArmorPoisonResist > 0;
|
||||
|
||||
duraBonus = attributes.ArmorDurability > 0;
|
||||
luckBonus = attributes.ArmorLuck > 0;
|
||||
lreqBonus = attributes.ArmorLowerRequirements > 0;
|
||||
dincBonus = false;
|
||||
}
|
||||
|
||||
int skill = from.Skills[craftSystem.MainSkill].Fixed / 10;
|
||||
|
||||
if (skill >= 100)
|
||||
baseChance -= (skill - 90) / 10;
|
||||
|
||||
EnhanceResult res = EnhanceResult.Success;
|
||||
|
||||
if (physBonus)
|
||||
CheckResult(ref res, baseChance + phys);
|
||||
|
||||
if (fireBonus)
|
||||
CheckResult(ref res, baseChance + fire);
|
||||
|
||||
if (coldBonus)
|
||||
CheckResult(ref res, baseChance + cold);
|
||||
|
||||
if (nrgyBonus)
|
||||
CheckResult(ref res, baseChance + nrgy);
|
||||
|
||||
if (poisBonus)
|
||||
CheckResult(ref res, baseChance + pois);
|
||||
|
||||
if (duraBonus)
|
||||
CheckResult(ref res, baseChance + dura / 40);
|
||||
|
||||
if (luckBonus)
|
||||
CheckResult(ref res, baseChance + 10 + luck / 2);
|
||||
|
||||
if (lreqBonus)
|
||||
CheckResult(ref res, baseChance + lreq / 4);
|
||||
|
||||
if (dincBonus)
|
||||
CheckResult(ref res, baseChance + dinc / 4);
|
||||
|
||||
switch (res)
|
||||
{
|
||||
case EnhanceResult.Broken:
|
||||
{
|
||||
if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half,
|
||||
ref resMessage))
|
||||
return EnhanceResult.NoResources;
|
||||
|
||||
item.Delete();
|
||||
break;
|
||||
}
|
||||
case EnhanceResult.Success:
|
||||
{
|
||||
if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All,
|
||||
ref resMessage))
|
||||
return EnhanceResult.NoResources;
|
||||
|
||||
if (item is BaseWeapon w)
|
||||
{
|
||||
w.Resource = resource;
|
||||
|
||||
int hue = w.GetElementalDamageHue();
|
||||
if (hue > 0)
|
||||
w.Hue = hue;
|
||||
}
|
||||
else
|
||||
{
|
||||
((BaseArmor)item).Resource = resource;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case EnhanceResult.Failure:
|
||||
{
|
||||
if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half,
|
||||
ref resMessage))
|
||||
return EnhanceResult.NoResources;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void CheckResult(ref EnhanceResult res, int chance)
|
||||
{
|
||||
if (res != EnhanceResult.Success)
|
||||
return; // we've already failed..
|
||||
|
||||
int random = Utility.Random(100);
|
||||
|
||||
if (10 > random)
|
||||
res = EnhanceResult.Failure;
|
||||
else if (chance > random)
|
||||
res = EnhanceResult.Broken;
|
||||
}
|
||||
|
||||
public static void BeginTarget(Mobile from, CraftSystem craftSystem, BaseTool tool)
|
||||
{
|
||||
CraftContext context = craftSystem.GetContext(from);
|
||||
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
int lastRes = context.LastResourceIndex;
|
||||
CraftSubResCol subRes = craftSystem.CraftSubRes;
|
||||
|
||||
if (lastRes >= 0 && lastRes < subRes.Count)
|
||||
{
|
||||
CraftSubRes res = subRes.GetAt(lastRes);
|
||||
|
||||
if (from.Skills[craftSystem.MainSkill].Value < res.RequiredSkill)
|
||||
{
|
||||
from.SendGump(new CraftGump(from, craftSystem, tool, res.Message));
|
||||
}
|
||||
else
|
||||
{
|
||||
CraftResource resource = CraftResources.GetFromType(res.ItemType);
|
||||
|
||||
if (resource != CraftResource.None)
|
||||
{
|
||||
from.Target = new InternalTarget(craftSystem, tool, res.ItemType, resource);
|
||||
from.SendLocalizedMessage(
|
||||
1061004); // Target an item to enhance with the properties of your selected material.
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendGump(new CraftGump(from, craftSystem, tool,
|
||||
1061010)); // You must select a special material in order to enhance an item with its properties.
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendGump(new CraftGump(from, craftSystem, tool,
|
||||
1061010)); // You must select a special material in order to enhance an item with its properties.
|
||||
}
|
||||
}
|
||||
|
||||
private class InternalTarget : Target
|
||||
{
|
||||
private CraftSystem m_CraftSystem;
|
||||
private CraftResource m_Resource;
|
||||
private Type m_ResourceType;
|
||||
private BaseTool m_Tool;
|
||||
|
||||
public InternalTarget(CraftSystem craftSystem, BaseTool tool, Type resourceType, CraftResource resource) : base(
|
||||
2, false, TargetFlags.None)
|
||||
{
|
||||
m_CraftSystem = craftSystem;
|
||||
m_Tool = tool;
|
||||
m_ResourceType = resourceType;
|
||||
m_Resource = resource;
|
||||
}
|
||||
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
if (targeted is Item item)
|
||||
{
|
||||
object message = null;
|
||||
EnhanceResult res = Enhance.Invoke(from, m_CraftSystem, m_Tool, item, m_Resource, m_ResourceType,
|
||||
ref message);
|
||||
|
||||
switch (res)
|
||||
{
|
||||
case EnhanceResult.NotInBackpack:
|
||||
message = 1061005;
|
||||
break; // The item must be in your backpack to enhance it.
|
||||
case EnhanceResult.AlreadyEnhanced:
|
||||
message = 1061012;
|
||||
break; // This item is already enhanced with the properties of a special material.
|
||||
case EnhanceResult.BadItem:
|
||||
message = 1061011;
|
||||
break; // You cannot enhance this type of item with the properties of the selected special material.
|
||||
case EnhanceResult.BadResource:
|
||||
message = 1061010;
|
||||
break; // You must select a special material in order to enhance an item with its properties.
|
||||
case EnhanceResult.Broken:
|
||||
message = 1061080;
|
||||
break; // You attempt to enhance the item, but fail catastrophically. The item is lost.
|
||||
case EnhanceResult.Failure:
|
||||
message = 1061082;
|
||||
break; // You attempt to enhance the item, but fail. Some material is lost in the process.
|
||||
case EnhanceResult.Success:
|
||||
message = 1061008;
|
||||
break; // You enhance the item with the properties of the special material.
|
||||
case EnhanceResult.NoSkill:
|
||||
message = 1044153;
|
||||
break; // You don't have the required skills to attempt this item.
|
||||
}
|
||||
|
||||
from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Projects/Scripts/Engines/Craft/Core/QueryMakersMarkGump.cs
Normal file
55
Projects/Scripts/Engines/Craft/Core/QueryMakersMarkGump.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class QueryMakersMarkGump : Gump
|
||||
{
|
||||
private CraftItem m_CraftItem;
|
||||
private CraftSystem m_CraftSystem;
|
||||
private Mobile m_From;
|
||||
private int m_Quality;
|
||||
private BaseTool m_Tool;
|
||||
private Type m_TypeRes;
|
||||
|
||||
public QueryMakersMarkGump(int quality, Mobile from, CraftItem craftItem, CraftSystem craftSystem, Type typeRes,
|
||||
BaseTool tool) : base(100, 200)
|
||||
{
|
||||
from.CloseGump<QueryMakersMarkGump>();
|
||||
|
||||
m_Quality = quality;
|
||||
m_From = from;
|
||||
m_CraftItem = craftItem;
|
||||
m_CraftSystem = craftSystem;
|
||||
m_TypeRes = typeRes;
|
||||
m_Tool = tool;
|
||||
|
||||
AddPage(0);
|
||||
|
||||
AddBackground(0, 0, 220, 170, 5054);
|
||||
AddBackground(10, 10, 200, 150, 3000);
|
||||
|
||||
AddHtmlLocalized(20, 20, 180, 80, 1018317); // Do you wish to place your maker's mark on this item?
|
||||
|
||||
AddHtmlLocalized(55, 100, 140, 25, 1011011); // CONTINUE
|
||||
AddButton(20, 100, 4005, 4007, 1);
|
||||
|
||||
AddHtmlLocalized(55, 125, 140, 25, 1011012); // CANCEL
|
||||
AddButton(20, 125, 4005, 4007, 0);
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, RelayInfo info)
|
||||
{
|
||||
bool makersMark = info.ButtonID == 1;
|
||||
|
||||
if (makersMark)
|
||||
m_From.SendLocalizedMessage(501808); // You mark the item.
|
||||
else
|
||||
m_From.SendLocalizedMessage(501809); // Cancelled mark.
|
||||
|
||||
m_CraftItem.CompleteCraft(m_Quality, makersMark, m_From, m_CraftSystem, m_TypeRes, m_Tool, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
90
Projects/Scripts/Engines/Craft/Core/Recipes.cs
Normal file
90
Projects/Scripts/Engines/Craft/Core/Recipes.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Commands;
|
||||
using Server.Mobiles;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class Recipe
|
||||
{
|
||||
private TextDefinition m_TD;
|
||||
|
||||
public Recipe(int id, CraftSystem system, CraftItem item)
|
||||
{
|
||||
ID = id;
|
||||
CraftSystem = system;
|
||||
CraftItem = item;
|
||||
|
||||
if (Recipes.ContainsKey(id))
|
||||
throw new Exception("Attempting to create recipe with preexisting ID.");
|
||||
|
||||
Recipes.Add(id, this);
|
||||
LargestRecipeID = Math.Max(id, LargestRecipeID);
|
||||
}
|
||||
|
||||
|
||||
public static Dictionary<int, Recipe> Recipes{ get; } = new Dictionary<int, Recipe>();
|
||||
|
||||
public static int LargestRecipeID{ get; private set; }
|
||||
|
||||
public CraftSystem CraftSystem{ get; set; }
|
||||
|
||||
public CraftItem CraftItem{ get; set; }
|
||||
|
||||
public int ID{ get; }
|
||||
|
||||
public TextDefinition TextDefinition => m_TD ?? (m_TD = new TextDefinition(CraftItem.NameNumber, CraftItem.NameString));
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("LearnAllRecipes", AccessLevel.GameMaster, LearnAllRecipes_OnCommand);
|
||||
CommandSystem.Register("ForgetAllRecipes", AccessLevel.GameMaster, ForgetAllRecipes_OnCommand);
|
||||
}
|
||||
|
||||
[Usage("LearnAllRecipes")]
|
||||
[Description("Teaches a player all available recipes.")]
|
||||
private static void LearnAllRecipes_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile m = e.Mobile;
|
||||
m.SendMessage("Target a player to teach them all of the recipes.");
|
||||
|
||||
m.BeginTarget(-1, false, TargetFlags.None, delegate(Mobile from, object targeted)
|
||||
{
|
||||
if (targeted is PlayerMobile mobile)
|
||||
{
|
||||
foreach (KeyValuePair<int, Recipe> kvp in Recipes)
|
||||
mobile.AcquireRecipe(kvp.Key);
|
||||
|
||||
m.SendMessage("You teach them all of the recipes.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m.SendMessage("That is not a player!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Usage("ForgetAllRecipes")]
|
||||
[Description("Makes a player forget all the recipes they've learned.")]
|
||||
private static void ForgetAllRecipes_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile m = e.Mobile;
|
||||
m.SendMessage("Target a player to have them forget all of the recipes they've learned.");
|
||||
|
||||
m.BeginTarget(-1, false, TargetFlags.None, delegate(Mobile from, object targeted)
|
||||
{
|
||||
if (targeted is PlayerMobile mobile)
|
||||
{
|
||||
mobile.ResetRecipes();
|
||||
|
||||
m.SendMessage("They forget all their recipes.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m.SendMessage("That is not a player!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
517
Projects/Scripts/Engines/Craft/Core/Repair.cs
Normal file
517
Projects/Scripts/Engines/Craft/Core/Repair.cs
Normal file
|
|
@ -0,0 +1,517 @@
|
|||
using System;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public class Repair
|
||||
{
|
||||
public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
|
||||
{
|
||||
from.Target = new InternalTarget(craftSystem, tool);
|
||||
from.SendLocalizedMessage(1044276); // Target an item to repair.
|
||||
}
|
||||
|
||||
public static void Do(Mobile from, CraftSystem craftSystem, RepairDeed deed)
|
||||
{
|
||||
from.Target = new InternalTarget(craftSystem, deed);
|
||||
from.SendLocalizedMessage(1044276); // Target an item to repair.
|
||||
}
|
||||
|
||||
private class InternalTarget : Target
|
||||
{
|
||||
private CraftSystem m_CraftSystem;
|
||||
private RepairDeed m_Deed;
|
||||
private BaseTool m_Tool;
|
||||
|
||||
public InternalTarget(CraftSystem craftSystem, BaseTool tool) : base(2, false, TargetFlags.None)
|
||||
{
|
||||
m_CraftSystem = craftSystem;
|
||||
m_Tool = tool;
|
||||
}
|
||||
|
||||
public InternalTarget(CraftSystem craftSystem, RepairDeed deed) : base(2, false, TargetFlags.None)
|
||||
{
|
||||
m_CraftSystem = craftSystem;
|
||||
m_Deed = deed;
|
||||
}
|
||||
|
||||
private int GetWeakenChance(Mobile mob, SkillName skill, int curHits, int maxHits)
|
||||
{
|
||||
// 40% - (1% per hp lost) - (1% per 10 craft skill)
|
||||
return 40 + (maxHits - curHits) - (int)((m_Deed?.SkillLevel ?? mob.Skills[skill].Value) / 10);
|
||||
}
|
||||
|
||||
private bool CheckWeaken(Mobile mob, SkillName skill, int curHits, int maxHits)
|
||||
{
|
||||
return GetWeakenChance(mob, skill, curHits, maxHits) > Utility.Random(100);
|
||||
}
|
||||
|
||||
private int GetRepairDifficulty(int curHits, int maxHits)
|
||||
{
|
||||
return (maxHits - curHits) * 1250 / Math.Max(maxHits, 1) - 250;
|
||||
}
|
||||
|
||||
private bool CheckRepairDifficulty(Mobile mob, SkillName skill, int curHits, int maxHits)
|
||||
{
|
||||
double difficulty = GetRepairDifficulty(curHits, maxHits) * 0.1;
|
||||
|
||||
|
||||
if (m_Deed != null)
|
||||
{
|
||||
double value = m_Deed.SkillLevel;
|
||||
double minSkill = difficulty - 25.0;
|
||||
double maxSkill = difficulty + 25;
|
||||
|
||||
if (value < minSkill)
|
||||
return false; // Too difficult
|
||||
if (value >= maxSkill)
|
||||
return true; // No challenge
|
||||
|
||||
double chance = (value - minSkill) / (maxSkill - minSkill);
|
||||
|
||||
return chance >= Utility.RandomDouble();
|
||||
}
|
||||
|
||||
return mob.CheckSkill(skill, difficulty - 25.0, difficulty + 25.0);
|
||||
}
|
||||
|
||||
private bool CheckDeed(Mobile from)
|
||||
{
|
||||
if (m_Deed != null) return m_Deed.Check(from);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsSpecialClothing(BaseClothing clothing)
|
||||
{
|
||||
// Clothing repairable but not craftable
|
||||
|
||||
if (m_CraftSystem is DefTailoring)
|
||||
return clothing is BearMask
|
||||
|| clothing is DeerMask
|
||||
|| clothing is TheMostKnowledgePerson
|
||||
|| clothing is TheRobeOfBritanniaAri
|
||||
|| clothing is EmbroideredOakLeafCloak;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsSpecialWeapon(BaseWeapon weapon)
|
||||
{
|
||||
// Weapons repairable but not craftable
|
||||
|
||||
if (m_CraftSystem is DefTinkering)
|
||||
return weapon is Cleaver
|
||||
|| weapon is Hatchet
|
||||
|| weapon is Pickaxe
|
||||
|| weapon is ButcherKnife
|
||||
|| weapon is SkinningKnife;
|
||||
|
||||
if (m_CraftSystem is DefCarpentry)
|
||||
{
|
||||
return weapon is Club
|
||||
|| weapon is BlackStaff
|
||||
|| weapon is MagicWand
|
||||
|
||||
#region Temporary
|
||||
|
||||
// TODO: Make these items craftable
|
||||
|| weapon is WildStaff;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (m_CraftSystem is DefBlacksmithy)
|
||||
{
|
||||
return weapon is Pitchfork
|
||||
|
||||
#region Temporary
|
||||
|
||||
// TODO: Make these items craftable
|
||||
|| weapon is RadiantScimitar
|
||||
|| weapon is WarCleaver
|
||||
|| weapon is ElvenSpellblade
|
||||
|| weapon is AssassinSpike
|
||||
|| weapon is Leafblade
|
||||
|| weapon is RuneBlade
|
||||
|| weapon is ElvenMachete
|
||||
|| weapon is OrnateAxe
|
||||
|| weapon is DiamondMace;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Temporary
|
||||
|
||||
// TODO: Make these items craftable
|
||||
if (m_CraftSystem is DefBowFletching)
|
||||
return weapon is ElvenCompositeLongbow
|
||||
|| weapon is MagicalShortbow;
|
||||
|
||||
#endregion
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsSpecialArmor(BaseArmor armor)
|
||||
{
|
||||
// Armor repairable but not craftable
|
||||
|
||||
#region Temporary
|
||||
|
||||
// TODO: Make these items craftable
|
||||
if (m_CraftSystem is DefTailoring)
|
||||
return armor is LeafTonlet
|
||||
|| armor is LeafArms
|
||||
|| armor is LeafChest
|
||||
|| armor is LeafGloves
|
||||
|| armor is LeafGorget
|
||||
|| armor is LeafLegs
|
||||
|| armor is HideChest
|
||||
|| armor is HideGloves
|
||||
|| armor is HideGorget
|
||||
|| armor is HidePants
|
||||
|| armor is HidePauldrons;
|
||||
|
||||
if (m_CraftSystem is DefCarpentry)
|
||||
return armor is WingedHelm
|
||||
|| armor is RavenHelm
|
||||
|| armor is VultureHelm
|
||||
|| armor is WoodlandArms
|
||||
|| armor is WoodlandChest
|
||||
|| armor is WoodlandGloves
|
||||
|| armor is WoodlandGorget
|
||||
|| armor is WoodlandLegs;
|
||||
if (m_CraftSystem is DefBlacksmithy)
|
||||
return armor is Circlet
|
||||
|| armor is RoyalCirclet
|
||||
|| armor is GemmedCirclet;
|
||||
|
||||
#endregion
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
int number;
|
||||
|
||||
if (!CheckDeed(from))
|
||||
return;
|
||||
|
||||
bool usingDeed = m_Deed != null;
|
||||
bool toDelete = false;
|
||||
|
||||
// TODO: Make an IRepairable
|
||||
|
||||
if (m_CraftSystem.CanCraft(from, m_Tool, targeted.GetType()) == 1044267)
|
||||
{
|
||||
number = 1044282; // You must be near a forge and and anvil to repair items. * Yes, there are two and's *
|
||||
}
|
||||
else if (m_CraftSystem is DefTinkering && targeted is Golem g)
|
||||
{
|
||||
int damage = g.HitsMax - g.Hits;
|
||||
|
||||
if (g.IsDeadBondedPet)
|
||||
{
|
||||
number = 500426; // You can't repair that.
|
||||
}
|
||||
else if (damage <= 0)
|
||||
{
|
||||
number = 500423; // That is already in full repair.
|
||||
}
|
||||
else
|
||||
{
|
||||
double skillValue = usingDeed ? m_Deed.SkillLevel : from.Skills.Tinkering.Value;
|
||||
|
||||
if (skillValue < 60.0)
|
||||
{
|
||||
number =
|
||||
1044153; // You don't have the required skills to attempt this item. //TODO: How does OSI handle this with deeds with golems?
|
||||
}
|
||||
else if (!from.CanBeginAction<Golem>())
|
||||
{
|
||||
number = 501789; // You must wait before trying again.
|
||||
}
|
||||
else
|
||||
{
|
||||
if (damage > (int)(skillValue * 0.3))
|
||||
damage = (int)(skillValue * 0.3);
|
||||
|
||||
damage += 30;
|
||||
|
||||
if (!from.CheckSkill(SkillName.Tinkering, 0.0, 100.0))
|
||||
damage /= 2;
|
||||
|
||||
Container pack = from.Backpack;
|
||||
|
||||
if (pack != null)
|
||||
{
|
||||
int v = pack.ConsumeUpTo(typeof(IronIngot), (damage + 4) / 5);
|
||||
|
||||
if (v > 0)
|
||||
{
|
||||
g.Hits += v * 5;
|
||||
|
||||
number = 1044279; // You repair the item.
|
||||
toDelete = true;
|
||||
|
||||
from.BeginAction<Golem>();
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(12.0), from.EndAction<Golem>);
|
||||
}
|
||||
else
|
||||
{
|
||||
number = 1044037; // You do not have sufficient metal to make that.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
number = 1044037; // You do not have sufficient metal to make that.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (targeted is BaseWeapon weapon)
|
||||
{
|
||||
SkillName skill = m_CraftSystem.MainSkill;
|
||||
int toWeaken = 0;
|
||||
|
||||
if (Core.AOS)
|
||||
{
|
||||
toWeaken = 1;
|
||||
}
|
||||
else if (skill != SkillName.Tailoring)
|
||||
{
|
||||
double skillLevel = usingDeed ? m_Deed.SkillLevel : from.Skills[skill].Base;
|
||||
|
||||
if (skillLevel >= 90.0)
|
||||
toWeaken = 1;
|
||||
else if (skillLevel >= 70.0)
|
||||
toWeaken = 2;
|
||||
else
|
||||
toWeaken = 3;
|
||||
}
|
||||
|
||||
if (m_CraftSystem.CraftItems.SearchForSubclass(weapon.GetType()) == null && !IsSpecialWeapon(weapon))
|
||||
{
|
||||
number = usingDeed
|
||||
? 1061136
|
||||
: 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
|
||||
}
|
||||
else if (!weapon.IsChildOf(from.Backpack) && (!Core.ML || weapon.Parent != from))
|
||||
{
|
||||
number = 1044275; // The item must be in your backpack to repair it.
|
||||
}
|
||||
else if (!Core.AOS && weapon.PoisonCharges != 0)
|
||||
{
|
||||
number = 1005012; // You cannot repair an item while a caustic substance is on it.
|
||||
}
|
||||
else if (weapon.MaxHitPoints <= 0 || weapon.HitPoints == weapon.MaxHitPoints)
|
||||
{
|
||||
number = 1044281; // That item is in full repair
|
||||
}
|
||||
else if (weapon.MaxHitPoints <= toWeaken)
|
||||
{
|
||||
number = 1044278; // That item has been repaired many times, and will break if repairs are attempted again.
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CheckWeaken(from, skill, weapon.HitPoints, weapon.MaxHitPoints))
|
||||
{
|
||||
weapon.MaxHitPoints -= toWeaken;
|
||||
weapon.HitPoints = Math.Max(0, weapon.HitPoints - toWeaken);
|
||||
}
|
||||
|
||||
if (CheckRepairDifficulty(from, skill, weapon.HitPoints, weapon.MaxHitPoints))
|
||||
{
|
||||
number = 1044279; // You repair the item.
|
||||
m_CraftSystem.PlayCraftEffect(from);
|
||||
weapon.HitPoints = weapon.MaxHitPoints;
|
||||
}
|
||||
else
|
||||
{
|
||||
number = usingDeed
|
||||
? 1061137
|
||||
: 1044280; // You fail to repair the item. [And the contract is destroyed]
|
||||
m_CraftSystem.PlayCraftEffect(from);
|
||||
}
|
||||
|
||||
toDelete = true;
|
||||
}
|
||||
}
|
||||
else if (targeted is BaseArmor armor)
|
||||
{
|
||||
SkillName skill = m_CraftSystem.MainSkill;
|
||||
int toWeaken = 0;
|
||||
|
||||
if (Core.AOS)
|
||||
{
|
||||
toWeaken = 1;
|
||||
}
|
||||
else if (skill != SkillName.Tailoring)
|
||||
{
|
||||
double skillLevel = usingDeed ? m_Deed.SkillLevel : from.Skills[skill].Base;
|
||||
|
||||
if (skillLevel >= 90.0)
|
||||
toWeaken = 1;
|
||||
else if (skillLevel >= 70.0)
|
||||
toWeaken = 2;
|
||||
else
|
||||
toWeaken = 3;
|
||||
}
|
||||
|
||||
if (m_CraftSystem.CraftItems.SearchForSubclass(armor.GetType()) == null && !IsSpecialArmor(armor))
|
||||
{
|
||||
number = usingDeed
|
||||
? 1061136
|
||||
: 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
|
||||
}
|
||||
else if (!armor.IsChildOf(from.Backpack) && (!Core.ML || armor.Parent != from))
|
||||
{
|
||||
number = 1044275; // The item must be in your backpack to repair it.
|
||||
}
|
||||
else if (armor.MaxHitPoints <= 0 || armor.HitPoints == armor.MaxHitPoints)
|
||||
{
|
||||
number = 1044281; // That item is in full repair
|
||||
}
|
||||
else if (armor.MaxHitPoints <= toWeaken)
|
||||
{
|
||||
number = 1044278; // That item has been repaired many times, and will break if repairs are attempted again.
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CheckWeaken(from, skill, armor.HitPoints, armor.MaxHitPoints))
|
||||
{
|
||||
armor.MaxHitPoints -= toWeaken;
|
||||
armor.HitPoints = Math.Max(0, armor.HitPoints - toWeaken);
|
||||
}
|
||||
|
||||
if (CheckRepairDifficulty(from, skill, armor.HitPoints, armor.MaxHitPoints))
|
||||
{
|
||||
number = 1044279; // You repair the item.
|
||||
m_CraftSystem.PlayCraftEffect(from);
|
||||
armor.HitPoints = armor.MaxHitPoints;
|
||||
}
|
||||
else
|
||||
{
|
||||
number = usingDeed
|
||||
? 1061137
|
||||
: 1044280; // You fail to repair the item. [And the contract is destroyed]
|
||||
m_CraftSystem.PlayCraftEffect(from);
|
||||
}
|
||||
|
||||
toDelete = true;
|
||||
}
|
||||
}
|
||||
else if (targeted is BaseClothing clothing)
|
||||
{
|
||||
SkillName skill = m_CraftSystem.MainSkill;
|
||||
int toWeaken = 0;
|
||||
|
||||
if (Core.AOS)
|
||||
{
|
||||
toWeaken = 1;
|
||||
}
|
||||
else if (skill != SkillName.Tailoring)
|
||||
{
|
||||
double skillLevel = usingDeed ? m_Deed.SkillLevel : from.Skills[skill].Base;
|
||||
|
||||
if (skillLevel >= 90.0)
|
||||
toWeaken = 1;
|
||||
else if (skillLevel >= 70.0)
|
||||
toWeaken = 2;
|
||||
else
|
||||
toWeaken = 3;
|
||||
}
|
||||
|
||||
if (m_CraftSystem.CraftItems.SearchForSubclass(clothing.GetType()) == null &&
|
||||
!IsSpecialClothing(clothing) && !(clothing is TribalMask || clothing is HornedTribalMask))
|
||||
{
|
||||
number = usingDeed
|
||||
? 1061136
|
||||
: 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
|
||||
}
|
||||
else if (!clothing.IsChildOf(from.Backpack) && (!Core.ML || clothing.Parent != from))
|
||||
{
|
||||
number = 1044275; // The item must be in your backpack to repair it.
|
||||
}
|
||||
else if (clothing.MaxHitPoints <= 0 || clothing.HitPoints == clothing.MaxHitPoints)
|
||||
{
|
||||
number = 1044281; // That item is in full repair
|
||||
}
|
||||
else if (clothing.MaxHitPoints <= toWeaken)
|
||||
{
|
||||
number = 1044278; // That item has been repaired many times, and will break if repairs are attempted again.
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CheckWeaken(from, skill, clothing.HitPoints, clothing.MaxHitPoints))
|
||||
{
|
||||
clothing.MaxHitPoints -= toWeaken;
|
||||
clothing.HitPoints = Math.Max(0, clothing.HitPoints - toWeaken);
|
||||
}
|
||||
|
||||
if (CheckRepairDifficulty(from, skill, clothing.HitPoints, clothing.MaxHitPoints))
|
||||
{
|
||||
number = 1044279; // You repair the item.
|
||||
m_CraftSystem.PlayCraftEffect(from);
|
||||
clothing.HitPoints = clothing.MaxHitPoints;
|
||||
}
|
||||
else
|
||||
{
|
||||
number = usingDeed
|
||||
? 1061137
|
||||
: 1044280; // You fail to repair the item. [And the contract is destroyed]
|
||||
m_CraftSystem.PlayCraftEffect(from);
|
||||
}
|
||||
|
||||
toDelete = true;
|
||||
}
|
||||
}
|
||||
else if (!usingDeed && targeted is BlankScroll scroll)
|
||||
{
|
||||
SkillName skill = m_CraftSystem.MainSkill;
|
||||
|
||||
if (from.Skills[skill].Value >= 50.0)
|
||||
{
|
||||
scroll.Consume(1);
|
||||
RepairDeed deed = new RepairDeed(RepairDeed.GetTypeFor(m_CraftSystem), from.Skills[skill].Value,
|
||||
from);
|
||||
from.AddToBackpack(deed);
|
||||
|
||||
number = 500442; // You create the item and put it in your backpack.
|
||||
}
|
||||
else
|
||||
{
|
||||
number = 1047005; // You must be at least apprentice level to create a repair service contract.
|
||||
}
|
||||
}
|
||||
else if (targeted is Item)
|
||||
{
|
||||
number = usingDeed
|
||||
? 1061136
|
||||
: 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
|
||||
}
|
||||
else
|
||||
{
|
||||
number = 500426; // You can't repair that.
|
||||
}
|
||||
|
||||
if (!usingDeed)
|
||||
{
|
||||
CraftContext context = m_CraftSystem.GetContext(from);
|
||||
from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, number));
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(number);
|
||||
|
||||
if (toDelete)
|
||||
m_Deed.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
185
Projects/Scripts/Engines/Craft/Core/Resmelt.cs
Normal file
185
Projects/Scripts/Engines/Craft/Core/Resmelt.cs
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
using System;
|
||||
using Server.Ethics;
|
||||
using Server.Items;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Engines.Craft
|
||||
{
|
||||
public enum SmeltResult
|
||||
{
|
||||
Success,
|
||||
Invalid,
|
||||
NoSkill
|
||||
}
|
||||
|
||||
public class Resmelt
|
||||
{
|
||||
public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
|
||||
{
|
||||
int num = craftSystem.CanCraft(from, tool, null);
|
||||
|
||||
if (num > 0 && num != 1044267)
|
||||
{
|
||||
from.SendGump(new CraftGump(from, craftSystem, tool, num));
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Target = new InternalTarget(craftSystem, tool);
|
||||
from.SendLocalizedMessage(1044273); // Target an item to recycle.
|
||||
}
|
||||
}
|
||||
|
||||
private class InternalTarget : Target
|
||||
{
|
||||
private CraftSystem m_CraftSystem;
|
||||
private BaseTool m_Tool;
|
||||
|
||||
public InternalTarget(CraftSystem craftSystem, BaseTool tool) : base(2, false, TargetFlags.None)
|
||||
{
|
||||
m_CraftSystem = craftSystem;
|
||||
m_Tool = tool;
|
||||
}
|
||||
|
||||
private SmeltResult Resmelt(Mobile from, Item item, CraftResource resource)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Ethic.IsImbued(item))
|
||||
return SmeltResult.Invalid;
|
||||
|
||||
if (CraftResources.GetType(resource) != CraftResourceType.Metal)
|
||||
return SmeltResult.Invalid;
|
||||
|
||||
CraftResourceInfo info = CraftResources.GetInfo(resource);
|
||||
|
||||
if (info == null || info.ResourceTypes.Length == 0)
|
||||
return SmeltResult.Invalid;
|
||||
|
||||
CraftItem craftItem = m_CraftSystem.CraftItems.SearchFor(item.GetType());
|
||||
|
||||
if (craftItem == null || craftItem.Resources.Count == 0)
|
||||
return SmeltResult.Invalid;
|
||||
|
||||
CraftRes craftResource = craftItem.Resources.GetAt(0);
|
||||
|
||||
if (craftResource.Amount < 2)
|
||||
return SmeltResult.Invalid; // Not enough metal to resmelt
|
||||
|
||||
double difficulty = 0.0;
|
||||
|
||||
switch (resource)
|
||||
{
|
||||
case CraftResource.DullCopper:
|
||||
difficulty = 65.0;
|
||||
break;
|
||||
case CraftResource.ShadowIron:
|
||||
difficulty = 70.0;
|
||||
break;
|
||||
case CraftResource.Copper:
|
||||
difficulty = 75.0;
|
||||
break;
|
||||
case CraftResource.Bronze:
|
||||
difficulty = 80.0;
|
||||
break;
|
||||
case CraftResource.Gold:
|
||||
difficulty = 85.0;
|
||||
break;
|
||||
case CraftResource.Agapite:
|
||||
difficulty = 90.0;
|
||||
break;
|
||||
case CraftResource.Verite:
|
||||
difficulty = 95.0;
|
||||
break;
|
||||
case CraftResource.Valorite:
|
||||
difficulty = 99.0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (difficulty > from.Skills.Mining.Value)
|
||||
return SmeltResult.NoSkill;
|
||||
|
||||
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)
|
||||
ingot.Amount = craftResource.Amount / 2;
|
||||
else
|
||||
ingot.Amount = 1;
|
||||
|
||||
item.Delete();
|
||||
from.AddToBackpack(ingot);
|
||||
|
||||
from.PlaySound(0x2A);
|
||||
from.PlaySound(0x240);
|
||||
return SmeltResult.Success;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
return SmeltResult.Invalid;
|
||||
}
|
||||
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
int num = m_CraftSystem.CanCraft(from, m_Tool, null);
|
||||
|
||||
if (num > 0)
|
||||
{
|
||||
if (num == 1044267)
|
||||
{
|
||||
DefBlacksmithy.CheckAnvilAndForge(from, 2, out bool anvil, out bool forge);
|
||||
|
||||
if (!anvil)
|
||||
num = 1044266; // You must be near an anvil
|
||||
else if (!forge)
|
||||
num = 1044265; // You must be near a forge.
|
||||
}
|
||||
|
||||
from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
|
||||
}
|
||||
else
|
||||
{
|
||||
SmeltResult result = SmeltResult.Invalid;
|
||||
bool isStoreBought = false;
|
||||
int message;
|
||||
|
||||
if (targeted is BaseArmor armor)
|
||||
{
|
||||
result = Resmelt(from, armor, armor.Resource);
|
||||
isStoreBought = !armor.PlayerConstructed;
|
||||
}
|
||||
else if (targeted is BaseWeapon weapon)
|
||||
{
|
||||
result = Resmelt(from, weapon, weapon.Resource);
|
||||
isStoreBought = !weapon.PlayerConstructed;
|
||||
}
|
||||
else if (targeted is DragonBardingDeed deed)
|
||||
{
|
||||
result = Resmelt(from, deed, deed.Resource);
|
||||
isStoreBought = false;
|
||||
}
|
||||
|
||||
switch (result)
|
||||
{
|
||||
default:
|
||||
case SmeltResult.Invalid:
|
||||
message = 1044272;
|
||||
break; // You can't melt that down into ingots.
|
||||
case SmeltResult.NoSkill:
|
||||
message = 1044269;
|
||||
break; // You have no idea how to work this metal.
|
||||
case SmeltResult.Success:
|
||||
message = isStoreBought ? 500418 : 1044270;
|
||||
break; // You melt the item down into ingots.
|
||||
}
|
||||
|
||||
from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue