Skip to content

Commit

Permalink
Better Item Craft Button Enable Code (#254)
Browse files Browse the repository at this point in the history
* Added GetCraftingSkill() Method

Added GetCraftingSkill() Method, which returns the crafting skill that created a given item.

* Improved Code to Enable Craft Button

Old code enabled the craft button for items if the player's primary crafting skill was alchemy or spellcrafting.  This means that the craft button could be enabled for items that weren't player crafted, and that servers which give access to all crafting skills never enable the crafting button.

New code checks if the item is player crafted, is from one of the crafting skills which can be imbued or tinctured, and the player has either alchemy or spellcrafting skills.
  • Loading branch information
tegstewart authored Sep 21, 2020
1 parent 1e477cb commit 930446f
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 20 deletions.
71 changes: 71 additions & 0 deletions GameServer/craft/CraftingMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,77 @@ public static bool Init()

#region Global craft functions

/// <summary>
/// Return the crafting skill which created the item
/// </summary>
public static eCraftingSkill GetCraftingSkill(InventoryItem item)
{
if (!item.IsCrafted)
return eCraftingSkill.NoCrafting;

switch (item.Object_Type)
{
case (int)eObjectType.Cloth:
case (int)eObjectType.Leather:
return eCraftingSkill.Tailoring;

case (int)eObjectType.Studded:
case (int)eObjectType.Reinforced:
case (int)eObjectType.Chain:
case (int)eObjectType.Scale:
case (int)eObjectType.Plate:
return eCraftingSkill.ArmorCrafting;

// all weapon
case (int)eObjectType.Axe:
case (int)eObjectType.Blades:
case (int)eObjectType.Blunt:
case (int)eObjectType.CelticSpear:
case (int)eObjectType.CrushingWeapon:
case (int)eObjectType.Flexible:
case (int)eObjectType.Hammer:
case (int)eObjectType.HandToHand:
case (int)eObjectType.LargeWeapons:
case (int)eObjectType.LeftAxe:
case (int)eObjectType.Piercing:
case (int)eObjectType.PolearmWeapon:
case (int)eObjectType.Scythe:
case (int)eObjectType.Shield:
case (int)eObjectType.SlashingWeapon:
case (int)eObjectType.Spear:
case (int)eObjectType.Sword:
case (int)eObjectType.ThrustWeapon:
case (int)eObjectType.TwoHandedWeapon:
return eCraftingSkill.WeaponCrafting;

case (int)eObjectType.CompositeBow:
case (int)eObjectType.Crossbow:
case (int)eObjectType.Fired:
case (int)eObjectType.Instrument:
case (int)eObjectType.Longbow:
case (int)eObjectType.RecurvedBow:
case (int)eObjectType.Staff:
return eCraftingSkill.Fletching;

case (int)eObjectType.AlchemyTincture:
case (int)eObjectType.Poison:
return eCraftingSkill.Alchemy;

case (int)eObjectType.SpellcraftGem:
return eCraftingSkill.SpellCrafting;

case (int)eObjectType.SiegeBalista:
case (int)eObjectType.SiegeCatapult:
case (int)eObjectType.SiegeCauldron:
case (int)eObjectType.SiegeRam:
case (int)eObjectType.SiegeTrebuchet:
return eCraftingSkill.SiegeCrafting;

default:
return eCraftingSkill.NoCrafting;
}
}

/// <summary>
/// Return the crafting skill needed to work on the item
/// </summary>
Expand Down
21 changes: 18 additions & 3 deletions GameServer/packets/Server/PacketLib1109.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,24 @@ protected override void WriteItemData(GSTCPPacketOut pak, InventoryItem item)
pak.WriteShort((ushort)item.Color);
// flag |= 0x01; // newGuildEmblem
flag |= 0x02; // enable salvage button
AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(m_gameClient.Player.CraftingPrimarySkill);
if (skill != null && skill is AdvancedCraftingSkill/* && ((AdvancedCraftingSkill)skill).IsAllowedToCombine(m_gameClient.Player, item)*/)
flag |= 0x04; // enable craft button

// Enable craft button if the item can be modified and the player has alchemy or spellcrafting
eCraftingSkill skill = CraftingMgr.GetCraftingSkill(item);
switch (skill)
{
case eCraftingSkill.ArmorCrafting:
case eCraftingSkill.Fletching:
case eCraftingSkill.Tailoring:
case eCraftingSkill.WeaponCrafting:
if (m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.Alchemy)
|| m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.SpellCrafting))
flag |= 0x04; // enable craft button
break;

default:
break;
}

ushort icon1 = 0;
ushort icon2 = 0;
string spell_name1 = "";
Expand Down
22 changes: 18 additions & 4 deletions GameServer/packets/Server/PacketLib1112.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,24 @@ protected override void WriteItemData(GSTCPPacketOut pak, InventoryItem item)
pak.WriteShort((ushort)color);
}
// flag |= 0x01; // newGuildEmblem
flag |= 0x02; // enable salvage button
AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(m_gameClient.Player.CraftingPrimarySkill);
if (skill != null && skill is AdvancedCraftingSkill/* && ((AdvancedCraftingSkill)skill).IsAllowedToCombine(m_gameClient.Player, item)*/)
flag |= 0x04; // enable craft button

// Enable craft button if the item can be modified and the player has alchemy or spellcrafting
eCraftingSkill skill = CraftingMgr.GetCraftingSkill(item);
switch (skill)
{
case eCraftingSkill.ArmorCrafting:
case eCraftingSkill.Fletching:
case eCraftingSkill.Tailoring:
case eCraftingSkill.WeaponCrafting:
if (m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.Alchemy)
|| m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.SpellCrafting))
flag |= 0x04; // enable craft button
break;

default:
break;
}

ushort icon1 = 0;
ushort icon2 = 0;
string spell_name1 = "";
Expand Down
21 changes: 18 additions & 3 deletions GameServer/packets/Server/PacketLib1119.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,24 @@ protected override void WriteItemData(GSTCPPacketOut pak, InventoryItem item)
}
// flag |= 0x01; // newGuildEmblem
flag |= 0x02; // enable salvage button
AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(m_gameClient.Player.CraftingPrimarySkill);
if (skill != null && skill is AdvancedCraftingSkill/* && ((AdvancedCraftingSkill)skill).IsAllowedToCombine(m_gameClient.Player, item)*/)
flag |= 0x04; // enable craft button

// Enable craft button if the item can be modified and the player has alchemy or spellcrafting
eCraftingSkill skill = CraftingMgr.GetCraftingSkill(item);
switch (skill)
{
case eCraftingSkill.ArmorCrafting:
case eCraftingSkill.Fletching:
case eCraftingSkill.Tailoring:
case eCraftingSkill.WeaponCrafting:
if (m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.Alchemy)
|| m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.SpellCrafting))
flag |= 0x04; // enable craft button
break;

default:
break;
}

ushort icon1 = 0;
ushort icon2 = 0;
string spell_name1 = "";
Expand Down
21 changes: 18 additions & 3 deletions GameServer/packets/Server/PacketLib1124.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5109,9 +5109,24 @@ protected virtual void WriteItemData(GSTCPPacketOut pak, InventoryItem item, int
}
//flag |= 0x01; // newGuildEmblem
flag |= 0x02; // enable salvage button
AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(m_gameClient.Player.CraftingPrimarySkill);
if (skill != null && skill is AdvancedCraftingSkill/* && ((AdvancedCraftingSkill)skill).IsAllowedToCombine(_gameClient.Player, item)*/)
flag |= 0x04; // enable craft button

// Enable craft button if the item can be modified and the player has alchemy or spellcrafting
eCraftingSkill skill = CraftingMgr.GetCraftingSkill(item);
switch (skill)
{
case eCraftingSkill.ArmorCrafting:
case eCraftingSkill.Fletching:
case eCraftingSkill.Tailoring:
case eCraftingSkill.WeaponCrafting:
if (m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.Alchemy)
|| m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.SpellCrafting))
flag |= 0x04; // enable craft button
break;

default:
break;
}

ushort icon1 = 0;
ushort icon2 = 0;
string spell_name1 = "";
Expand Down
23 changes: 19 additions & 4 deletions GameServer/packets/Server/PacketLib182.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,25 @@ protected override void SendInventorySlotsUpdateRange(ICollection<int> slots, eI
else
pak.WriteShort((ushort)item.Color);
// flag |= 0x01; // newGuildEmblem
flag |= 0x02; // enable salvage button
AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(m_gameClient.Player.CraftingPrimarySkill);
if (skill != null && skill is AdvancedCraftingSkill/* && ((AdvancedCraftingSkill)skill).IsAllowedToCombine(m_gameClient.Player, item)*/)
flag |= 0x04; // enable craft button
flag |= 0x02; // enable salvage button

// Enable craft button if the item can be modified and the player has alchemy or spellcrafting
eCraftingSkill skill = CraftingMgr.GetCraftingSkill(item);
switch (skill)
{
case eCraftingSkill.ArmorCrafting:
case eCraftingSkill.Fletching:
case eCraftingSkill.Tailoring:
case eCraftingSkill.WeaponCrafting:
if (m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.Alchemy)
|| m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.SpellCrafting))
flag |= 0x04; // enable craft button
break;

default:
break;
}

ushort icon1 = 0;
ushort icon2 = 0;
string spell_name1 = "";
Expand Down
17 changes: 14 additions & 3 deletions GameServer/packets/Server/PacketLib189.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,21 @@ protected virtual void WriteItemData(GSTCPPacketOut pak, InventoryItem item)

flag |= 0x02; // enable salvage button

AbstractCraftingSkill skill = CraftingMgr.getSkillbyEnum(m_gameClient.Player.CraftingPrimarySkill);
if (skill != null && skill is AdvancedCraftingSkill/* && ((AdvancedCraftingSkill)skill).IsAllowedToCombine(m_gameClient.Player, item)*/)
// Enable craft button if the item can be modified and the player has alchemy or spellcrafting
eCraftingSkill skill = CraftingMgr.GetCraftingSkill(item);
switch (skill)
{
flag |= 0x04; // enable craft button
case eCraftingSkill.ArmorCrafting:
case eCraftingSkill.Fletching:
case eCraftingSkill.Tailoring:
case eCraftingSkill.WeaponCrafting:
if (m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.Alchemy)
|| m_gameClient.Player.CraftingSkills.ContainsKey(eCraftingSkill.SpellCrafting))
flag |= 0x04; // enable craft button
break;

default:
break;
}

ushort icon1 = 0;
Expand Down

0 comments on commit 930446f

Please sign in to comment.