1
0
Fork 0

Some updates for enchanting (2)

This commit is contained in:
daniel0916 2014-01-31 19:46:51 +01:00
parent 5609fed360
commit 36120db400
9 changed files with 173 additions and 15 deletions

View File

@ -2453,4 +2453,40 @@ void cClientHandle::SocketClosed(void)
void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment)
{
//Get Item
cItem EnchantItem = m_Player->GetDraggingItem();
cEnchantmentsArray enchantments;
cItem::GetApplicableEnchantmentsForType(EnchantItem.m_ItemType, enchantments);
m_Player->SendMessage(Printf("ItemType: %d", EnchantItem.m_ItemType));
m_Player->SendMessage(enchantments[1].ToString());
//shuffle enchantments (i don't know if this is good)
std::random_shuffle(enchantments.begin(), enchantments.end());
m_Player->SendMessage(enchantments[1].ToString());
//Enchant Item
EnchantItem.m_Enchantments.AddFromString(enchantments[1].ToString());
//Set Enchanted Item to Window Slot
m_Player->GetWindow()->SetSlot(*m_Player, 0, EnchantItem);
LOGWARN("Item enchanted!");
}

View File

@ -214,6 +214,9 @@ public:
/// Handles the block placing packet when it is a real block placement (not block-using, item-using or eating)
void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler);
///Handle item enchanting
void HandleEnchantItem(Byte & WindowID, Byte & Enchantment);
private:

View File

@ -29,6 +29,9 @@ mapping each enchantment's id onto its level. ID may be either a number or the e
Level value of 0 means no such enchantment, and it will not be stored in the m_Enchantments.
Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs.
*/
typedef std::vector<cEnchantments> cEnchantmentsArray;
// tolua_begin
class cEnchantments
{
@ -62,7 +65,7 @@ public:
enchLuckOfTheSea = 61,
enchLure = 62,
} ;
/// Creates an empty enchantments container
cEnchantments(void);

View File

@ -189,6 +189,112 @@ bool cItem::IsEnchantable(short item)
void cItem::GetApplicableEnchantmentsForType(short a_ItemType, cEnchantmentsArray & a_Enchantments)
{
LOGWARN("Get Enchantments");
if (ItemCategory::IsSword(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("Sharpness=4"));
a_Enchantments.push_back(cEnchantments("Smite=5"));
a_Enchantments.push_back(cEnchantments("BaneOfArthropods=5"));
a_Enchantments.push_back(cEnchantments("Knockback=2"));
a_Enchantments.push_back(cEnchantments("FireAspect=2"));
a_Enchantments.push_back(cEnchantments("Looting=3"));
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
}
else if (ItemCategory::IsPickaxe(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("Efficiency=4"));
a_Enchantments.push_back(cEnchantments("SilkTouch=1"));
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
a_Enchantments.push_back(cEnchantments("Fortune=3"));
}
else if (ItemCategory::IsAxe(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("Efficiency=4"));
a_Enchantments.push_back(cEnchantments("SilkTouch=1"));
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
a_Enchantments.push_back(cEnchantments("Fortune=3"));
}
else if (ItemCategory::IsShovel(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("Efficiency=4"));
a_Enchantments.push_back(cEnchantments("SilkTouch=1"));
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
a_Enchantments.push_back(cEnchantments("Fortune=3"));
}
else if (ItemCategory::IsHoe(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
}
else if (ItemCategory::IsArmor(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("Protection=4"));
a_Enchantments.push_back(cEnchantments("FireProtection=4"));
a_Enchantments.push_back(cEnchantments("BlastProtection=4"));
a_Enchantments.push_back(cEnchantments("ProjectileProtection=4"));
a_Enchantments.push_back(cEnchantments("Thorns=3"));
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
if (ItemCategory::IsHelmet(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("Respiration=3"));
a_Enchantments.push_back(cEnchantments("AquaAffinity=1"));
}
else if (ItemCategory::IsBoots(a_ItemType))
{
a_Enchantments.push_back(cEnchantments("FeatherFalling=4"));
}
}
//Bow
else if (a_ItemType == 261)
{
a_Enchantments.push_back(cEnchantments("Power=4"));
a_Enchantments.push_back(cEnchantments("Punch=2"));
a_Enchantments.push_back(cEnchantments("Flame=1"));
a_Enchantments.push_back(cEnchantments("Infinity=1"));
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
}
//Fishing Rod
else if (a_ItemType == 346)
{
a_Enchantments.push_back(cEnchantments("LuckOfTheSea=3"));
a_Enchantments.push_back(cEnchantments("Lure=3"));
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
}
//Shears
else if (a_ItemType == 359)
{
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
}
//Flint and Steel
else if (a_ItemType == 259)
{
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
}
//Carrot on a Stick
else if (a_ItemType == 398)
{
a_Enchantments.push_back(cEnchantments("Unbreaking=3"));
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cItems:

View File

@ -169,6 +169,9 @@ public:
/// Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements)
static bool IsEnchantable(short a_ItemType);
/** Fills a_Enchantments with the list of enchantments applicable to the specified item type */
static void cItem::GetApplicableEnchantmentsForType(short a_ItemType, cEnchantmentsArray & a_Enchantments);
// tolua_begin
short m_ItemType;

View File

@ -1535,6 +1535,21 @@ int cProtocol125::ParseUseEntity(void)
int cProtocol125::ParseEnchantItem(void)
{
HANDLE_PACKET_READ(ReadByte, byte, WindowID);
HANDLE_PACKET_READ(ReadByte, byte, Enchantment);
// TODO: Enchant Handling for older Protocols
return PARSE_OK;
}
int cProtocol125::ParseWindowClick(void)
{
HANDLE_PACKET_READ(ReadChar, char, WindowID);

View File

@ -133,6 +133,7 @@ protected:
virtual int ParseSlotSelected (void);
virtual int ParseUpdateSign (void);
virtual int ParseUseEntity (void);
virtual int ParseEnchantItem (void);
virtual int ParseWindowClick (void);
virtual int ParseWindowClose (void);

View File

@ -1143,7 +1143,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true;
case 0x0f: // Confirm transaction - not used in MCS
case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true;
case 0x11: HandlePacketEnchanting (a_ByteBuffer); return true;
case 0x11: HandlePacketEnchantItem (a_ByteBuffer); return true;
case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true;
case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true;
case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true;
@ -1546,23 +1546,14 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer)
void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID);
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment);
LOGWARN("Enchantment Packet received!");
LOGWARN("Protocol 1.7: Enchantment Packet received!");
//Get Item from Window Slot
cItem EnchantItem = *m_Client->GetPlayer()->GetWindow()->GetSlot(*m_Client->GetPlayer(), 0);
//Enchant item with Sharpness 5
EnchantItem.m_Enchantments.SetLevel(cEnchantments::enchSharpness, 5);
//Set Enchanted Item to Window Slot
m_Client->GetPlayer()->GetWindow()->SetSlot(*m_Client->GetPlayer(), 0, EnchantItem);
LOGWARN("Item enchanted!");
m_Client->HandleEnchantItem(WindowID, Enchantment);
}

View File

@ -258,7 +258,7 @@ protected:
void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer);
void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer);
void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer);
void HandlePacketEnchanting (cByteBuffer & a_ByteBuffer);
void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer);
void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer);
void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer);