From 0c2b307eab67b7f37d82a7862a6acbcd96b45adb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 20 Jan 2014 18:22:08 +0100 Subject: first changes for enchanting (not finished) - added enchanting table block handler and added it to the blockhandler - added enchanting window - drop item in the slot 0 when the player close the window - added enchanting packet (1.7 only) - some more... --- src/Blocks/BlockEnchantmentTable.h | 37 ++++++++++++++++ src/Blocks/BlockHandler.cpp | 2 + src/Protocol/Protocol17x.cpp | 17 ++++++++ src/Protocol/Protocol17x.h | 1 + src/UI/SlotArea.cpp | 86 ++++++++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 28 +++++++++++++ src/UI/Window.cpp | 15 +++++++ src/UI/Window.h | 12 ++++++ 8 files changed, 198 insertions(+) create mode 100644 src/Blocks/BlockEnchantmentTable.h (limited to 'src') diff --git a/src/Blocks/BlockEnchantmentTable.h b/src/Blocks/BlockEnchantmentTable.h new file mode 100644 index 000000000..e8a87179b --- /dev/null +++ b/src/Blocks/BlockEnchantmentTable.h @@ -0,0 +1,37 @@ + +#pragma once + +#include "BlockHandler.h" +#include "../UI/Window.h" +#include "../Entities/Player.h" + + + + + +class cBlockEnchantmentTableHandler : + public cBlockHandler +{ +public: + cBlockEnchantmentTableHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + + virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + { + cWindow * Window = new cEnchantingWindow(a_BlockX, a_BlockY, a_BlockZ); + a_Player->OpenWindow(Window); + } + + + virtual bool IsUseable(void) override + { + return true; + } +}; + + + + diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index b9c0887ce..8d09b5559 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -21,6 +21,7 @@ #include "BlockDirt.h" #include "BlockDoor.h" #include "BlockDropSpenser.h" +#include "BlockEnchantmentTable.h" #include "BlockEnderchest.h" #include "BlockEntity.h" #include "BlockFarmland.h" @@ -132,6 +133,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_DOUBLE_WOODEN_SLAB: return new cBlockDoubleSlabHandler (a_BlockType); case E_BLOCK_DROPPER: return new cBlockDropSpenserHandler (a_BlockType); case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType); + case E_BLOCK_ENCHANTMENT_TABLE: return new cBlockEnchantmentTableHandler(a_BlockType); case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType); case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler ( ); case E_BLOCK_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType); diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e5a380f8a..d120d8d91 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1143,6 +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 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true; case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true; case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true; @@ -1545,6 +1546,22 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) +void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer) +{ + HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); + HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); + + //TODO: EnchantItem (getWindow, getItem, Enchant) + + + + LOG("Enchantment Paket empfangen!"); +} + + + + + void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID); diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 3ae774c18..04d65910c 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -258,6 +258,7 @@ protected: void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer); void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer); void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer); + void HandlePacketEnchanting (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index bfcad3d92..ae6bfccb5 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -562,6 +562,92 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaEnchanting: + +cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : +cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +{ +} + + + + + +void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +{ + LOG("Clicked"); + // Check if Slot is in the Enchantment Table + if (a_SlotNum == 0) + { + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + ShiftClickedResult(a_Player); + } + else + { + ClickedResult(a_Player); + } + return; + } + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); +} + + + + + +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 0); + // Player not found - that is acceptable +} + + + + + +void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) +{ + LOG("Click!"); + + if (a_Player.GetDraggingItem().IsEmpty()) + { + LOG("EMPTY"); + this->m_ParentWindow.SetProperty(0, NULL); + this->m_ParentWindow.SetProperty(1, NULL); + this->m_ParentWindow.SetProperty(2, NULL); + } + else if (a_Player.GetDraggingItem().IsEnchantable) + { + LOG("Enchantable"); + this->m_ParentWindow.SetProperty(0, 30); + this->m_ParentWindow.SetProperty(1, 20); + this->m_ParentWindow.SetProperty(2, 10); + } + else + { + LOG("Not Enchantable"); + this->m_ParentWindow.SetProperty(0, NULL); + this->m_ParentWindow.SetProperty(1, NULL); + this->m_ParentWindow.SetProperty(2, NULL); + } +} + + + + + +void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) +{ + LOG("Shift Click!"); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnderChest: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index d31c87e0c..bd5c66c77 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -252,6 +252,34 @@ protected: +class cSlotAreaEnchanting : + public cSlotAreaTemporary +{ + typedef cSlotAreaTemporary super; + +public: + /// a_GridSize is allowed to be only 2 or 3 + cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow); + + // cSlotAreaTemporary overrides: + virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void OnPlayerRemoved(cPlayer & a_Player) override; + + // Distributing items into this area is completely disabled + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {} + +protected: + /// Handles a click in the result slot. Crafts using the current recipe, if possible + void ClickedResult(cPlayer & a_Player); + + /// Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result. + void ShiftClickedResult(cPlayer & a_Player); +}; + + + + + class cSlotAreaChest : public cSlotArea { diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 3ffeff7a0..fcfe6faf3 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -781,6 +781,21 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cEnchantingWindow: + +cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : +cWindow(wtEnchantment, "Enchantment Table") +{ + m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cChestWindow: diff --git a/src/UI/Window.h b/src/UI/Window.h index 030182888..cdaec5aaa 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -231,6 +231,18 @@ public: +class cEnchantingWindow : + public cWindow +{ + typedef cWindow super; +public: + cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); +}; + + + + + class cFurnaceWindow : public cWindow { -- cgit v1.2.3 From bfac00f2807a6740e876adebd689cc3ae6e075ed Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 24 Jan 2014 20:01:21 +0100 Subject: Some updates for enchanting --- src/Entities/Player.cpp | 4 ++++ src/Protocol/Protocol17x.cpp | 14 +++++++++++--- src/Protocol/Protocol17x.h | 2 +- src/UI/SlotArea.cpp | 24 ++++++++++++------------ src/UI/Window.cpp | 2 +- 5 files changed, 29 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c1f2456eb..abdd792e0 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -120,6 +120,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cPlayer::~cPlayer(void) { + cRoot::Get()->GetPluginManager()->CallHookPlayerDestroying(*this); + LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); // Notify the server that the player is being destroyed @@ -134,6 +136,8 @@ cPlayer::~cPlayer(void) delete m_InventoryWindow; LOGD("Player %p deleted", this); + + cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this); } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index d120d8d91..f302da2ad 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -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: HandlePacketEnchanting (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; @@ -1551,11 +1551,19 @@ void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); - //TODO: EnchantItem (getWindow, getItem, Enchant) + LOGWARN("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); - LOG("Enchantment Paket empfangen!"); + //Set Enchanted Item to Window Slot + m_Client->GetPlayer()->GetWindow()->SetSlot(*m_Client->GetPlayer(), 0, EnchantItem); + + LOGWARN("Item enchanted!"); + } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 04d65910c..7877e783a 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -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 HandlePacketEnchanting (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index ae6bfccb5..a226d027b 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -576,7 +576,7 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - LOG("Clicked"); + LOGWARN("Clicked"); // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -610,28 +610,28 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - LOG("Click!"); + LOGWARN("Click!"); if (a_Player.GetDraggingItem().IsEmpty()) { - LOG("EMPTY"); - this->m_ParentWindow.SetProperty(0, NULL); - this->m_ParentWindow.SetProperty(1, NULL); - this->m_ParentWindow.SetProperty(2, NULL); + LOGWARN("EMPTY"); + this->m_ParentWindow.SetProperty(0, 0); + this->m_ParentWindow.SetProperty(1, 0); + this->m_ParentWindow.SetProperty(2, 0); } else if (a_Player.GetDraggingItem().IsEnchantable) { - LOG("Enchantable"); + LOGWARN("Enchantable"); this->m_ParentWindow.SetProperty(0, 30); this->m_ParentWindow.SetProperty(1, 20); this->m_ParentWindow.SetProperty(2, 10); } else { - LOG("Not Enchantable"); - this->m_ParentWindow.SetProperty(0, NULL); - this->m_ParentWindow.SetProperty(1, NULL); - this->m_ParentWindow.SetProperty(2, NULL); + LOGWARN("Not Enchantable"); + this->m_ParentWindow.SetProperty(0, 0); + this->m_ParentWindow.SetProperty(1, 0); + this->m_ParentWindow.SetProperty(2, 0); } } @@ -641,7 +641,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) { - LOG("Shift Click!"); + LOGWARN("Shift Click!"); } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index fcfe6faf3..9188b47a7 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -785,7 +785,7 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : // cEnchantingWindow: cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : -cWindow(wtEnchantment, "Enchantment Table") +cWindow(wtEnchantment, "Enchant") { m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); -- cgit v1.2.3 From 5609fed3602b4da3c22ca042819561c2b9b21715 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 24 Jan 2014 21:53:27 +0100 Subject: removed hook from enchanting commit --- src/Entities/Player.cpp | 4 ---- src/Protocol/Protocol17x.cpp | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index abdd792e0..c1f2456eb 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -120,8 +120,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cPlayer::~cPlayer(void) { - cRoot::Get()->GetPluginManager()->CallHookPlayerDestroying(*this); - LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); // Notify the server that the player is being destroyed @@ -136,8 +134,6 @@ cPlayer::~cPlayer(void) delete m_InventoryWindow; LOGD("Player %p deleted", this); - - cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this); } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index f302da2ad..949498734 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1563,7 +1563,7 @@ void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer) m_Client->GetPlayer()->GetWindow()->SetSlot(*m_Client->GetPlayer(), 0, EnchantItem); LOGWARN("Item enchanted!"); - + } -- cgit v1.2.3 From 36120db400691be75199ff404e35f5c289b8818f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 31 Jan 2014 19:46:51 +0100 Subject: Some updates for enchanting (2) --- src/ClientHandle.cpp | 36 +++++++++++++++ src/ClientHandle.h | 3 ++ src/Enchantments.h | 5 +- src/Item.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++ src/Item.h | 3 ++ src/Protocol/Protocol125.cpp | 15 ++++++ src/Protocol/Protocol125.h | 1 + src/Protocol/Protocol17x.cpp | 17 ++----- src/Protocol/Protocol17x.h | 2 +- 9 files changed, 173 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 74d192129..979298c59 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -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!"); +} + + + + + diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 4add022a6..1a1e22a19 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -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: diff --git a/src/Enchantments.h b/src/Enchantments.h index e984df92e..e0861aa1e 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -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 cEnchantmentsArray; + // tolua_begin class cEnchantments { @@ -62,7 +65,7 @@ public: enchLuckOfTheSea = 61, enchLure = 62, } ; - + /// Creates an empty enchantments container cEnchantments(void); diff --git a/src/Item.cpp b/src/Item.cpp index 9170006b6..fb561d7b2 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -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: diff --git a/src/Item.h b/src/Item.h index 727965112..1a070eafd 100644 --- a/src/Item.h +++ b/src/Item.h @@ -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; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 323a13992..b2b61acc9 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -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); diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 310f9dd78..e3c8765b1 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -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); diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 949498734..05b7ebd45 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -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); } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 7877e783a..1f3039edb 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -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); -- cgit v1.2.3 From 7735a1104ff4861fd02609aefaa63ea4587c3649 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 1 Feb 2014 13:09:28 +0100 Subject: added EnchantItemPacket to older Protocols --- src/Protocol/Protocol125.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index b2b61acc9..2df2a695b 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -94,6 +94,7 @@ enum PACKET_INVENTORY_WHOLE = 0x68, PACKET_WINDOW_PROPERTY = 0x69, PACKET_CREATIVE_INVENTORY_ACTION = 0x6B, + PACKET_ENCHANT_ITEM = 0x6C, PACKET_UPDATE_SIGN = 0x82, PACKET_PLAYER_LIST_ITEM = 0xC9, PACKET_PLAYER_ABILITIES = 0xca, @@ -1170,6 +1171,7 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType) case PACKET_SLOT_SELECTED: return ParseSlotSelected(); case PACKET_UPDATE_SIGN: return ParseUpdateSign(); case PACKET_USE_ENTITY: return ParseUseEntity(); + case PACKET_ENCHANT_ITEM: return ParseEnchantItem(); case PACKET_WINDOW_CLICK: return ParseWindowClick(); case PACKET_WINDOW_CLOSE: return ParseWindowClose(); } @@ -1540,8 +1542,9 @@ int cProtocol125::ParseEnchantItem(void) HANDLE_PACKET_READ(ReadByte, byte, WindowID); HANDLE_PACKET_READ(ReadByte, byte, Enchantment); - // TODO: Enchant Handling for older Protocols + LOGWARN("Older Protocol: Enchantment Packet received!"); + m_Client->HandleEnchantItem(WindowID, Enchantment); return PARSE_OK; } -- cgit v1.2.3 From af566d5a79134842854bea78de577676d507949f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 19:52:35 +0200 Subject: Added Enchantment-Slot-Level generating --- src/FastRandom.cpp | 10 ++++++++++ src/FastRandom.h | 3 +++ src/UI/SlotArea.cpp | 28 +++++++++++++++++++--------- 3 files changed, 32 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp index e6634bb0d..c45261947 100644 --- a/src/FastRandom.cpp +++ b/src/FastRandom.cpp @@ -172,3 +172,13 @@ float cFastRandom::NextFloat(float a_Range, int a_Salt) + +int cFastRandom::GenerateRandomInteger(int a_Begin, int a_End) +{ + cFastRandom Random; + return Random.NextInt(a_End - a_Begin + 1) + a_Begin; +} + + + + diff --git a/src/FastRandom.h b/src/FastRandom.h index bf70822cf..1c20fa39f 100644 --- a/src/FastRandom.h +++ b/src/FastRandom.h @@ -43,6 +43,9 @@ public: /// Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M; a_Salt is additional source of randomness float NextFloat(float a_Range, int a_Salt); + + /// Returns a random int in the range [a_Begin .. a_End] + int GenerateRandomInteger(int a_Begin, int a_End); protected: int m_Seed; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index a226d027b..03bfd275a 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -13,6 +13,8 @@ #include "Window.h" #include "../CraftingRecipes.h" #include "../Root.h" +#include "../FastRandom.h" +#include "../BlockArea.h" @@ -615,23 +617,31 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) if (a_Player.GetDraggingItem().IsEmpty()) { LOGWARN("EMPTY"); - this->m_ParentWindow.SetProperty(0, 0); - this->m_ParentWindow.SetProperty(1, 0); - this->m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0); + m_ParentWindow.SetProperty(1, 0); + m_ParentWindow.SetProperty(2, 0); } else if (a_Player.GetDraggingItem().IsEnchantable) { + int bookshelves = 15; // TODO: Check Bookshelves + + cFastRandom Random; + int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); + int topSlot = std::max(base / 3, 1); + int middleSlot = (base * 2) / 3 + 1; + int bottomSlot = std::max(base, bookshelves * 2); + LOGWARN("Enchantable"); - this->m_ParentWindow.SetProperty(0, 30); - this->m_ParentWindow.SetProperty(1, 20); - this->m_ParentWindow.SetProperty(2, 10); + m_ParentWindow.SetProperty(0, topSlot); + m_ParentWindow.SetProperty(1, middleSlot); + m_ParentWindow.SetProperty(2, bottomSlot); } else { LOGWARN("Not Enchantable"); - this->m_ParentWindow.SetProperty(0, 0); - this->m_ParentWindow.SetProperty(1, 0); - this->m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0); + m_ParentWindow.SetProperty(1, 0); + m_ParentWindow.SetProperty(2, 0); } } -- cgit v1.2.3 From 93a7494e4b32777c38bae863aaa9ac0a39a770eb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 20:11:43 +0200 Subject: Fixed merge conflict --- src/ClientHandle.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 1a1e22a19..4add022a6 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -214,9 +214,6 @@ 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: -- cgit v1.2.3 From 296d0acbffc053b4edc4c4b02503603081180ecf Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 20:13:45 +0200 Subject: Added deleted things for merging --- src/ClientHandle.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 0c367ec7d..01765cc85 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -230,6 +230,9 @@ public: /** Called when the player moves into a different world; queues sreaming the new chunks */ void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); + ///Handle item enchanting + void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); + private: /** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */ -- cgit v1.2.3 From 1dfd2b1c5fe125757aeb084c163aec5b25a55fc2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 20:25:30 +0200 Subject: Fixed Errors --- src/Blocks/BlockEnchantmentTable.h | 2 +- src/Protocol/Protocol125.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockEnchantmentTable.h b/src/Blocks/BlockEnchantmentTable.h index e8a87179b..81d2cb9a0 100644 --- a/src/Blocks/BlockEnchantmentTable.h +++ b/src/Blocks/BlockEnchantmentTable.h @@ -19,7 +19,7 @@ public: } - virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { cWindow * Window = new cEnchantingWindow(a_BlockX, a_BlockY, a_BlockZ); a_Player->OpenWindow(Window); diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 867cf3ef3..26f109918 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1601,8 +1601,8 @@ int cProtocol125::ParseUseEntity(void) int cProtocol125::ParseEnchantItem(void) { - HANDLE_PACKET_READ(ReadByte, byte, WindowID); - HANDLE_PACKET_READ(ReadByte, byte, Enchantment); + HANDLE_PACKET_READ(ReadByte, Byte, WindowID); + HANDLE_PACKET_READ(ReadByte, Byte, Enchantment); LOGWARN("Older Protocol: Enchantment Packet received!"); -- cgit v1.2.3 From 427924fbb0dd4d6bae909095d0c3ae7dac0da36b Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 20:41:47 +0200 Subject: Modified comment --- src/FastRandom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/FastRandom.h b/src/FastRandom.h index 1c20fa39f..567198a31 100644 --- a/src/FastRandom.h +++ b/src/FastRandom.h @@ -44,7 +44,7 @@ public: /// Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M; a_Salt is additional source of randomness float NextFloat(float a_Range, int a_Salt); - /// Returns a random int in the range [a_Begin .. a_End] + /** Returns a random int in the range [a_Begin .. a_End] */ int GenerateRandomInteger(int a_Begin, int a_End); protected: -- cgit v1.2.3 From e6e702e7fdbc8b7475d3dbecc0f81a08304997ae Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Apr 2014 14:58:46 +0200 Subject: Added complete Enchanting System http://minecraft.gamepedia.com/Enchantment_mechanics --- src/ClientHandle.cpp | 677 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/ClientHandle.h | 5 +- src/Enchantments.h | 4 +- src/Item.cpp | 106 -------- src/Item.h | 3 - src/UI/SlotArea.cpp | 49 ++-- src/UI/Window.cpp | 86 ++++++- src/UI/Window.h | 20 +- 8 files changed, 803 insertions(+), 147 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 73a275ab1..90165b432 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -31,6 +31,8 @@ #include "CompositeChat.h" #include "Items/ItemSword.h" +#include "FastRandom.h" + /** Maximum number of explosions to send this tick, server will start dropping if exceeded */ @@ -2687,34 +2689,679 @@ 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); + cItem Item = m_Player->GetDraggingItem(); + cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); + int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); + + // Step 1 from Enchanting + int Enchantability = 1; + + if (Item.m_ItemType == E_ITEM_WOODEN_SWORD || Item.m_ItemType == E_ITEM_WOODEN_PICKAXE || Item.m_ItemType == E_ITEM_WOODEN_SHOVEL || Item.m_ItemType == E_ITEM_WOODEN_AXE || Item.m_ItemType == E_ITEM_WOODEN_HOE) + { + Enchantability = 15; + } + else if (Item.m_ItemType == E_ITEM_LEATHER_CAP || Item.m_ItemType == E_ITEM_LEATHER_TUNIC || Item.m_ItemType == E_ITEM_LEATHER_PANTS || Item.m_ItemType == E_ITEM_LEATHER_BOOTS) + { + Enchantability = 15; + } + else if (Item.m_ItemType == E_ITEM_STONE_SWORD || Item.m_ItemType == E_ITEM_STONE_PICKAXE || Item.m_ItemType == E_ITEM_STONE_SHOVEL || Item.m_ItemType == E_ITEM_STONE_AXE || Item.m_ItemType == E_ITEM_STONE_HOE) + { + Enchantability = 5; + } + else if (Item.m_ItemType == E_ITEM_IRON_HELMET || Item.m_ItemType == E_ITEM_IRON_CHESTPLATE || Item.m_ItemType == E_ITEM_IRON_LEGGINGS || Item.m_ItemType == E_ITEM_IRON_BOOTS) + { + Enchantability = 9; + } + else if (Item.m_ItemType == E_ITEM_IRON_SWORD || Item.m_ItemType == E_ITEM_IRON_PICKAXE || Item.m_ItemType == E_ITEM_IRON_SHOVEL || Item.m_ItemType == E_ITEM_IRON_AXE || Item.m_ItemType == E_ITEM_IRON_HOE) + { + Enchantability = 14; + } + else if (Item.m_ItemType == E_ITEM_CHAIN_HELMET || Item.m_ItemType == E_ITEM_CHAIN_CHESTPLATE || Item.m_ItemType == E_ITEM_CHAIN_LEGGINGS || Item.m_ItemType == E_ITEM_CHAIN_BOOTS) + { + Enchantability = 12; + } + else if (Item.m_ItemType == E_ITEM_DIAMOND_HELMET || Item.m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || Item.m_ItemType == E_ITEM_DIAMOND_LEGGINGS || Item.m_ItemType == E_ITEM_DIAMOND_BOOTS) + { + Enchantability = 10; + } + else if (Item.m_ItemType == E_ITEM_DIAMOND_SWORD || Item.m_ItemType == E_ITEM_DIAMOND_PICKAXE || Item.m_ItemType == E_ITEM_DIAMOND_SHOVEL || Item.m_ItemType == E_ITEM_DIAMOND_AXE || Item.m_ItemType == E_ITEM_DIAMOND_HOE) + { + Enchantability = 10; + } + else if (Item.m_ItemType == E_ITEM_GOLD_HELMET || Item.m_ItemType == E_ITEM_GOLD_CHESTPLATE || Item.m_ItemType == E_ITEM_GOLD_LEGGINGS || Item.m_ItemType == E_ITEM_GOLD_BOOTS) + { + Enchantability = 25; + } + else if (Item.m_ItemType == E_ITEM_GOLD_SWORD || Item.m_ItemType == E_ITEM_GOLD_PICKAXE || Item.m_ItemType == E_ITEM_GOLD_SHOVEL || Item.m_ItemType == E_ITEM_GOLD_AXE || Item.m_ItemType == E_ITEM_GOLD_HOE) + { + Enchantability = 22; + } + + cFastRandom Random; + int ModifiedEnchantmentLevel = BaseEnchantmentLevel + Random.NextInt(Enchantability / 4) + Random.NextInt(Enchantability / 4) + 1; + float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; + + int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); + + // Step 2 and 3 from Enchanting + cEnchantmentsVector enchantments; + + if (ItemCategory::IsSword(Item.m_ItemType)) + { + // Sharpness + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); + } + + // Smite + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); + } + + // Bane of Arthropods + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); + } + + // Knockback + if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); + } + + // Fire Aspect + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); + } + + // Looting + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); + } + } + + else if (ItemCategory::IsTool(Item.m_ItemType)) + { + // Efficiency + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); + } + + // Silk Touch + if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); + } + + // Fortune + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); + } + } + + else if (ItemCategory::IsArmor(Item.m_ItemType)) + { + // Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); + } + + // Fire Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); + } + else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); + } + else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); + } + + // Blast Protection + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); + } + + // Projectile Protection + if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); + } + else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); + } + else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); + } + + // Thorns + if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); + } + else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); + } + + + if (ItemCategory::IsHelmet(Item.m_ItemType)) + { + // Respiration + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); + } + else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); + } + + // Aqua Affinity + if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); + } + } + + else if (ItemCategory::IsBoots(Item.m_ItemType)) + { + // Feather Fall + if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); + } + else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); + } + } + } + + else if (Item.m_ItemType == E_ITEM_BOW) + { + // Power + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); + } + + // Punch + if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); + } + + // Flame and Infinity + if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); + } + } + + else if (Item.m_ItemType == E_ITEM_FISHING_ROD) + { + // Luck of the Sea and Lure + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); + } + } + + // Unbreaking + if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 63) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1")); + } + + int RandomEnchantment1 = floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment1 = enchantments[RandomEnchantment1]; + Item.m_Enchantments.AddFromString(Enchantment1.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); + + // TODO: Don't add every time so much enchantments + + // Checking for conflicting enchantments + enchantments = CheckEnchantmentConflicts(enchantments, Enchantment1); + + int RandomEnchantment2 = floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment2 = enchantments[RandomEnchantment2]; + Item.m_Enchantments.AddFromString(Enchantment2.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); + + // Checking for conflicting enchantments + enchantments = CheckEnchantmentConflicts(enchantments, Enchantment2); + + int RandomEnchantment3 = floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment3 = enchantments[RandomEnchantment3]; + Item.m_Enchantments.AddFromString(Enchantment3.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); + + m_Player->GetWindow()->SetSlot(*m_Player, 0, Item); +} + + - m_Player->SendMessage(Printf("ItemType: %d", EnchantItem.m_ItemType)); - m_Player->SendMessage(enchantments[1].ToString()); +cEnchantmentsVector cClientHandle::AddEnchantmentWeight(cEnchantmentsVector a_Map, int a_Weight, cEnchantments a_Enchantment) +{ + for (int i = 0; i < a_Weight; i++) + { + a_Map.push_back(a_Enchantment); + } + + return a_Map; +} + + + + + +cEnchantmentsVector cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector a_Map, cEnchantments a_FirstEnchantment) +{ + int FirstEnchantmentID = std::stoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0]); - //shuffle enchantments (i don't know if this is good) - std::random_shuffle(enchantments.begin(), enchantments.end()); + if (FirstEnchantmentID == cEnchantments::enchProtection) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); - m_Player->SendMessage(enchantments[1].ToString()); + if (EnchantmentID == cEnchantments::enchFireProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + if (EnchantmentID == cEnchantments::enchBlastProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + if (EnchantmentID == cEnchantments::enchProjectileProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + else if (FirstEnchantmentID == cEnchantments::enchFireProtection) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + if (EnchantmentID == cEnchantments::enchProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + if (EnchantmentID == cEnchantments::enchBlastProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + if (EnchantmentID == cEnchantments::enchProjectileProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); - //Enchant Item - EnchantItem.m_Enchantments.AddFromString(enchantments[1].ToString()); + if (EnchantmentID == cEnchantments::enchProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); - //Set Enchanted Item to Window Slot - m_Player->GetWindow()->SetSlot(*m_Player, 0, EnchantItem); + if (EnchantmentID == cEnchantments::enchFireProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchProjectileProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchFireProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchBlastProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + + else if (FirstEnchantmentID == cEnchantments::enchSharpness) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchSmite) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchBaneOfArthropods) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + else if (FirstEnchantmentID == cEnchantments::enchSmite) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchSharpness) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchBaneOfArthropods) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchSharpness) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchSmite) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchFortune) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } + else if (FirstEnchantmentID == cEnchantments::enchFortune) + { + for (cEnchantments enchantment : a_Map) + { + int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + + if (EnchantmentID == cEnchantments::enchSilkTouch) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + break; + } + } + } - LOGWARN("Item enchanted!"); + return a_Map; } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 01765cc85..4c88d79e2 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -18,6 +18,7 @@ #include "ByteBuffer.h" #include "Scoreboard.h" #include "Map.h" +#include "Enchantments.h" @@ -230,8 +231,10 @@ public: /** Called when the player moves into a different world; queues sreaming the new chunks */ void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); - ///Handle item enchanting + /** Called when the player will enchant a Item */ void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); + cEnchantmentsVector AddEnchantmentWeight(cEnchantmentsVector a_Map, int a_Weight, cEnchantments a_Enchantment); + cEnchantmentsVector CheckEnchantmentConflicts(cEnchantmentsVector a_Map, cEnchantments a_FirstEnchantment); private: diff --git a/src/Enchantments.h b/src/Enchantments.h index 2af772928..70d6b6613 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -29,7 +29,7 @@ Level value of 0 means no such enchantment, and it will not be stored in the m_E Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs. */ -typedef std::vector cEnchantmentsArray; +typedef std::vector cEnchantmentsVector; // tolua_begin class cEnchantments @@ -105,7 +105,7 @@ public: /// Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments) friend void EnchantmentSerializer::ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx); - + protected: /// Maps enchantment ID -> enchantment level typedef std::map cMap; diff --git a/src/Item.cpp b/src/Item.cpp index 093147b54..856b68be6 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -209,112 +209,6 @@ 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: diff --git a/src/Item.h b/src/Item.h index 620c77b29..910ecb382 100644 --- a/src/Item.h +++ b/src/Item.h @@ -175,9 +175,6 @@ public: /** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */ static bool IsEnchantable(short a_ItemType); // tolua_export - /** 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; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 9463bc593..f76b11380 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -608,7 +608,6 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - LOGWARN("Clicked"); // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -642,17 +641,39 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - LOGWARN("Click!"); - if (a_Player.GetDraggingItem().IsEmpty()) { - LOGWARN("EMPTY"); - m_ParentWindow.SetProperty(0, 0); - m_ParentWindow.SetProperty(1, 0); - m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } else if (a_Player.GetDraggingItem().IsEnchantable) { + int PosX = 0; + int PosY = 0; + int PosZ = 0; + cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; + Window->GetBlockPos(PosX, PosY, PosZ); + + cBlockArea Area; + Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); + + for (int x = 0; x < 7; x++) + { + for (int y = 0; y < 2; y++) + { + for (int z = 0; z < 7; z++) + { + LOG(Printf("%i", Area.GetBlockType(x, y, z)).c_str()); + + if (Area.GetBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + LOG("BookShelf"); + } + } + } + } + int bookshelves = 15; // TODO: Check Bookshelves cFastRandom Random; @@ -661,17 +682,15 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) int middleSlot = (base * 2) / 3 + 1; int bottomSlot = std::max(base, bookshelves * 2); - LOGWARN("Enchantable"); - m_ParentWindow.SetProperty(0, topSlot); - m_ParentWindow.SetProperty(1, middleSlot); - m_ParentWindow.SetProperty(2, bottomSlot); + m_ParentWindow.SetProperty(0, topSlot, a_Player); + m_ParentWindow.SetProperty(1, middleSlot, a_Player); + m_ParentWindow.SetProperty(2, bottomSlot, a_Player); } else { - LOGWARN("Not Enchantable"); - m_ParentWindow.SetProperty(0, 0); - m_ParentWindow.SetProperty(1, 0); - m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 5d89534dd..c514e76e7 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -808,7 +808,10 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : // cEnchantingWindow: cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : -cWindow(wtEnchantment, "Enchant") + cWindow(wtEnchantment, "Enchant"), + m_BlockX(a_BlockX), + m_BlockY(a_BlockY), + m_BlockZ(a_BlockZ) { m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); @@ -819,6 +822,87 @@ cWindow(wtEnchantment, "Enchant") +void cEnchantingWindow::SetProperty(int a_Property, int a_Value) +{ + if (a_Property == 0) + { + m_PropertyValue0 = a_Value; + } + else if (a_Property == 1) + { + m_PropertyValue1 = a_Value; + } + else if (a_Property == 2) + { + m_PropertyValue2 = a_Value; + } + + cCSLock Lock(m_CS); + for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) + { + (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); + } // for itr - m_OpenedBy[] +} + + + + + +void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) +{ + if (a_Property == 0) + { + m_PropertyValue0 = a_Value; + } + else if (a_Property == 1) + { + m_PropertyValue1 = a_Value; + } + else if (a_Property == 2) + { + m_PropertyValue2 = a_Value; + } + + a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); +} + + + + + +int cEnchantingWindow::GetPropertyValue(int a_Property) +{ + if (a_Property == 0) + { + return m_PropertyValue0; + } + else if (a_Property == 1) + { + return m_PropertyValue1; + } + else if (a_Property == 2) + { + return m_PropertyValue2; + } + + return -1; +} + + + + + +void cEnchantingWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ) +{ + a_PosX = m_BlockX; + a_PosY = m_BlockY; + a_PosZ = m_BlockZ; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cChestWindow: diff --git a/src/UI/Window.h b/src/UI/Window.h index cdaec5aaa..52ab6c3ae 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -136,11 +136,11 @@ public: void SetWindowTitle(const AString & a_WindowTitle ) { m_WindowTitle = a_WindowTitle; } /// Sends the UpdateWindowProperty (0x69) packet to all clients of the window - void SetProperty(int a_Property, int a_Value); + virtual void SetProperty(int a_Property, int a_Value); /// Sends the UpdateWindowPropert(0x69) packet to the specified player - void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); - + virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); + // tolua_end void OwnerDestroyed(void); @@ -165,7 +165,7 @@ public: /// Used by cSlotAreas to send individual slots to clients, a_RelativeSlotNum is the slot number relative to a_SlotArea void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum); - + protected: cSlotAreas m_SlotAreas; @@ -237,6 +237,18 @@ class cEnchantingWindow : typedef cWindow super; public: cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player) override; + virtual void SetProperty(int a_Property, int a_Value) override; + + /** Return the Value of a Property */ + int GetPropertyValue(int a_Property); + + /** Set the Position Values to the Position of the Enchantment Table */ + void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); + +protected: + int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2; + int m_BlockX, m_BlockY, m_BlockZ; }; -- cgit v1.2.3 From dd1f8fb1f5640d9f9d58098c8aefbc1c1ad308ab Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Apr 2014 18:52:17 +0200 Subject: Fixed Bookshelves Checking (not completly) --- src/UI/SlotArea.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index f76b11380..d43b91700 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -658,17 +658,20 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) cBlockArea Area; Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int x = 0; x < 7; x++) + for (int x = 0; x < 6; x++) { - for (int y = 0; y < 2; y++) + for (int y = 0; y < 3; y++) { - for (int z = 0; z < 7; z++) + for (int z = 0; z < 6; z++) { - LOG(Printf("%i", Area.GetBlockType(x, y, z)).c_str()); - - if (Area.GetBlockType(x, y, z) == E_BLOCK_BOOKCASE) + if ((((x == 0) || (x == 5)) || ((z == 0) || (z == 5))) && ((y == 0) || y == 1)) { - LOG("BookShelf"); + LOG("%i", Area.GetRelBlockType(x, y, z)); + + if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + LOG("BookShelf"); + } } } } -- cgit v1.2.3 From 1429d2f1b1802e1be5f5551df890562b4a014342 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 13:33:47 +0200 Subject: Some Fixes --- src/ClientHandle.cpp | 9 ++++++++- src/UI/SlotArea.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 90165b432..2d068ea07 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -3107,7 +3107,14 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) Item.m_Enchantments.AddFromString(Enchantment3.ToString()); enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); - m_Player->GetWindow()->SetSlot(*m_Player, 0, Item); + if (m_Player->DeltaExperience(Window->GetPropertyValue(Enchantment)) >= 0 || m_Player->IsGameModeCreative()) + { + m_Player->GetWindow()->SetSlot(*m_Player, 0, Item); + + Window->SetProperty(0, 0, *m_Player); + Window->SetProperty(1, 0, *m_Player); + Window->SetProperty(2, 0, *m_Player); + } } diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index d43b91700..352558d9e 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -647,7 +647,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (a_Player.GetDraggingItem().IsEnchantable) + else if (cItem::IsEnchantable(a_Player.GetDraggingItem().m_ItemType)) { int PosX = 0; int PosY = 0; -- cgit v1.2.3 From c88464e62aefb104f59391162b8e39da6041d37a Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 13:36:03 +0200 Subject: Fixed Server Crash --- src/ClientHandle.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 2d068ea07..a5ce510a3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2690,6 +2690,12 @@ void cClientHandle::SocketClosed(void) void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) { cItem Item = m_Player->GetDraggingItem(); + + if (!cItem::IsEnchantable(Item.m_ItemType)) + { + return; + } + cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); -- cgit v1.2.3 From 9dc4617e8d6ad6d3fa874e67dff2f79f4d1a651e Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 13:53:10 +0200 Subject: Fixed mistake --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a5ce510a3..96afff5bc 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -3113,7 +3113,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) Item.m_Enchantments.AddFromString(Enchantment3.ToString()); enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); - if (m_Player->DeltaExperience(Window->GetPropertyValue(Enchantment)) >= 0 || m_Player->IsGameModeCreative()) + if (m_Player->DeltaExperience(-m_Player->XpForLevel(Window->GetPropertyValue(Enchantment))) >= 0 || m_Player->IsGameModeCreative()) { m_Player->GetWindow()->SetSlot(*m_Player, 0, Item); -- cgit v1.2.3 From fce9ea65c35ab7f94c23bb361386b5ce223279eb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 22:15:10 +0200 Subject: Fixed invisibility enchantments --- src/ClientHandle.cpp | 4 +++- src/ClientHandle.h | 1 + src/UI/SlotArea.cpp | 2 ++ src/UI/Window.h | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 96afff5bc..2dd9cb91e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -3115,7 +3115,9 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) if (m_Player->DeltaExperience(-m_Player->XpForLevel(Window->GetPropertyValue(Enchantment))) >= 0 || m_Player->IsGameModeCreative()) { - m_Player->GetWindow()->SetSlot(*m_Player, 0, Item); + Window->m_SlotArea->SetSlot(0, *m_Player, Item); + Window->SendSlot(*m_Player, Window->m_SlotArea, 0); + Window->BroadcastWholeWindow(); Window->SetProperty(0, 0, *m_Player); Window->SetProperty(1, 0, *m_Player); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 4c88d79e2..b4b1d0da3 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -19,6 +19,7 @@ #include "Scoreboard.h" #include "Map.h" #include "Enchantments.h" +#include "UI/SlotArea.h" diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 352558d9e..35230cffb 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -600,6 +600,8 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : cSlotAreaTemporary(a_NumSlots, a_ParentWindow) { + cEnchantingWindow * Window = (cEnchantingWindow *)&m_ParentWindow; + Window->m_SlotArea = this; } diff --git a/src/UI/Window.h b/src/UI/Window.h index 52ab6c3ae..5e799248c 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -246,6 +246,8 @@ public: /** Set the Position Values to the Position of the Enchantment Table */ void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); + cSlotArea * m_SlotArea; + protected: int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2; int m_BlockX, m_BlockY, m_BlockZ; -- cgit v1.2.3 From 856e900bf8e74cb478904d6322dcb6310ff7a3b2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 11:48:12 +0200 Subject: Bug fixes --- src/ClientHandle.cpp | 4 ++-- src/Protocol/Protocol17x.cpp | 3 --- src/UI/SlotArea.cpp | 32 +++++++++++++++++--------------- src/UI/SlotArea.h | 8 ++------ 4 files changed, 21 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 2dd9cb91e..fc4db1d10 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2689,14 +2689,14 @@ void cClientHandle::SocketClosed(void) void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) { - cItem Item = m_Player->GetDraggingItem(); + cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); + cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); if (!cItem::IsEnchantable(Item.m_ItemType)) { return; } - cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); // Step 1 from Enchanting diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 785dbf935..a31643ccf 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1918,10 +1918,7 @@ void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); - LOGWARN("Protocol 1.7: Enchantment Packet received!"); - m_Client->HandleEnchantItem(WindowID, Enchantment); - } diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 35230cffb..673c036b6 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -608,8 +608,21 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 1); + // Player not found - that is acceptable +} + + + + + void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -621,20 +634,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio { ClickedResult(a_Player); } - return; } - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); -} - - - - - -void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) -{ - // Toss the item in the enchanting slot - TossItems(a_Player, 0, 0); - // Player not found - that is acceptable } @@ -643,13 +643,15 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - if (a_Player.GetDraggingItem().IsEmpty()) + cItem Item = *GetSlot(0, a_Player); + + if (Item.IsEmpty()) { m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(a_Player.GetDraggingItem().m_ItemType)) + else if (cItem::IsEnchantable(Item.m_ItemType)) { int PosX = 0; int PosY = 0; diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 82360ffbe..7feb74aa1 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -258,21 +258,17 @@ class cSlotAreaEnchanting : typedef cSlotAreaTemporary super; public: - /// a_GridSize is allowed to be only 2 or 3 cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow); // cSlotAreaTemporary overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; - // Distributing items into this area is completely disabled - virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {} - protected: - /// Handles a click in the result slot. Crafts using the current recipe, if possible + /// Handles a click in the item slot. void ClickedResult(cPlayer & a_Player); - /// Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result. + /// Handles a shift-click in the item slot. void ShiftClickedResult(cPlayer & a_Player); }; -- cgit v1.2.3 From fb26d2ba870f63deb5515521ecf5ce0c35780a2b Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 11:56:50 +0200 Subject: Fixed Bookshelf Checking Code by LO1ZB --- src/UI/SlotArea.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 673c036b6..23108c256 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -659,29 +659,31 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; Window->GetBlockPos(PosX, PosY, PosZ); + int bookshelves = 0; cBlockArea Area; Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int x = 0; x < 6; x++) + for (int y = 0; y <= 2; y++) { - for (int y = 0; y < 3; y++) + for (int x = 0; x <= 4; x++) { - for (int z = 0; z < 6; z++) + for (int z = 0; z <= 4; z++) { - if ((((x == 0) || (x == 5)) || ((z == 0) || (z == 5))) && ((y == 0) || y == 1)) + if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) { - LOG("%i", Area.GetRelBlockType(x, y, z)); - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) { - LOG("BookShelf"); + bookshelves++; } } } } } - int bookshelves = 15; // TODO: Check Bookshelves + if (bookshelves > 15) + { + bookshelves = 15; + } cFastRandom Random; int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); -- cgit v1.2.3 From a51a099c81f34f875c76d560e6729889b2fdd4fa Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 13:39:44 +0200 Subject: Blocked enchanting a item twice --- src/UI/SlotArea.cpp | 14 ++++++++------ src/UI/SlotArea.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 23108c256..eb528d7ca 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -628,11 +628,11 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio { if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) { - ShiftClickedResult(a_Player); + ShiftClickedSlot(a_Player); } else { - ClickedResult(a_Player); + ClickedSlot(a_Player); } } } @@ -641,7 +641,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio -void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) +void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); @@ -651,7 +651,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType)) + else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) { int PosX = 0; int PosY = 0; @@ -707,9 +707,11 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) -void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) +void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) { - LOGWARN("Shift Click!"); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 7feb74aa1..a6af72273 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -266,10 +266,10 @@ public: protected: /// Handles a click in the item slot. - void ClickedResult(cPlayer & a_Player); + void ClickedSlot(cPlayer & a_Player); /// Handles a shift-click in the item slot. - void ShiftClickedResult(cPlayer & a_Player); + void ShiftClickedSlot(cPlayer & a_Player); }; -- cgit v1.2.3 From 0ba0e39db4a3fae9139c5b875462fcd81faec3fc Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 16:46:59 +0200 Subject: Added/Modified last things for Enchanting System --- src/ClientHandle.cpp | 68 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index fc4db1d10..c00047ecd 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2699,6 +2699,8 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); + LOG("499"); + // Step 1 from Enchanting int Enchantability = 1; @@ -2744,7 +2746,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) } cFastRandom Random; - int ModifiedEnchantmentLevel = BaseEnchantmentLevel + Random.NextInt(Enchantability / 4) + Random.NextInt(Enchantability / 4) + 1; + int ModifiedEnchantmentLevel = BaseEnchantmentLevel + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1; float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); @@ -3090,28 +3092,64 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1")); } - int RandomEnchantment1 = floor(Random.NextFloat(1) * enchantments.size()); + int RandomEnchantment1 = (int) floor(Random.NextFloat(1) * enchantments.size()); cEnchantments Enchantment1 = enchantments[RandomEnchantment1]; Item.m_Enchantments.AddFromString(Enchantment1.ToString()); enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); - // TODO: Don't add every time so much enchantments + float NewEnchantmentLevel = (float) BaseEnchantmentLevel; + + // Next Enchantment (Second) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= SecondEnchantmentChance) + { + // Checking for conflicting enchantments + enchantments = CheckEnchantmentConflicts(enchantments, Enchantment1); + + if (enchantments.size() > 0) + { + int RandomEnchantment2 = (int) floor(Random.NextFloat(1) * enchantments.size()); + + cEnchantments Enchantment2 = enchantments[RandomEnchantment2]; + Item.m_Enchantments.AddFromString(Enchantment2.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); - // Checking for conflicting enchantments - enchantments = CheckEnchantmentConflicts(enchantments, Enchantment1); + // Checking for conflicting enchantments + enchantments = CheckEnchantmentConflicts(enchantments, Enchantment2); + } + } - int RandomEnchantment2 = floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment2 = enchantments[RandomEnchantment2]; - Item.m_Enchantments.AddFromString(Enchantment2.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); + // Next Enchantment (Third) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= ThirdEnchantmentChance) + { + if (enchantments.size() > 0) + { + int RandomEnchantment3 = (int) floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment3 = enchantments[RandomEnchantment3]; + Item.m_Enchantments.AddFromString(Enchantment3.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); - // Checking for conflicting enchantments - enchantments = CheckEnchantmentConflicts(enchantments, Enchantment2); + // Checking for conflicting enchantments + enchantments = CheckEnchantmentConflicts(enchantments, Enchantment3); + } + } - int RandomEnchantment3 = floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment3 = enchantments[RandomEnchantment3]; - Item.m_Enchantments.AddFromString(Enchantment3.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); + // Next Enchantment (Fourth) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= FourthEnchantmentChance) + { + if (enchantments.size() > 0) + { + int RandomEnchantment4 = (int) floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment4 = enchantments[RandomEnchantment4]; + Item.m_Enchantments.AddFromString(Enchantment4.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); + } + } if (m_Player->DeltaExperience(-m_Player->XpForLevel(Window->GetPropertyValue(Enchantment))) >= 0 || m_Player->IsGameModeCreative()) { -- cgit v1.2.3 From 55224d25ef67e69ead2d54885a5a1f12c3e7990e Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 16:48:14 +0200 Subject: Removed Debug Message --- src/ClientHandle.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c00047ecd..9605aa004 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2699,8 +2699,6 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); - LOG("499"); - // Step 1 from Enchanting int Enchantability = 1; -- cgit v1.2.3 From b5401ec03ad74782129e6a68eac3e9c0ccb573e2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 22:05:04 +0200 Subject: Added ItemPlaceCount in SlotArea Thanks to Howaner for helping --- src/UI/SlotArea.cpp | 32 ++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 3 +++ 2 files changed, 35 insertions(+) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index eb528d7ca..9ea2e0021 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -135,6 +135,12 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA cItem tmp(DraggingItem); DraggingItem = Slot; Slot = tmp; + int ItemPlaceCount = GetItemPlaceCount(Slot); + if (Slot.m_ItemCount > ItemPlaceCount) + { + DraggingItem.m_ItemCount += Slot.m_ItemCount - ItemPlaceCount; + Slot.m_ItemCount = ItemPlaceCount; + } } else { @@ -147,6 +153,13 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA FreeSlots = 0; } int Filling = (FreeSlots > DraggingItem.m_ItemCount) ? DraggingItem.m_ItemCount : FreeSlots; + + int ItemPlaceCount = GetItemPlaceCount(DraggingItem); + if (Filling > ItemPlaceCount) + { + Filling = ItemPlaceCount; + } + Slot.m_ItemCount += (char)Filling; DraggingItem.m_ItemCount -= (char)Filling; if (DraggingItem.m_ItemCount <= 0) @@ -315,6 +328,16 @@ bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool +int cSlotArea::GetItemPlaceCount(cItem & a_Item) +{ + cItemHandler * Handler = ItemHandler(a_Item.m_ItemType); + return Handler->GetMaxStackSize(); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaChest: @@ -718,6 +741,15 @@ void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) +int cSlotAreaEnchanting::GetItemPlaceCount(cItem & a_Item) +{ + return 1; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnderChest: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index a6af72273..431ad753c 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -66,6 +66,8 @@ public: /// If a_CollectFullStacks is false, slots with full stacks are skipped while collecting. /// Returns true if full stack has been collected in a_Dragging, false if there's space remaining to fill. virtual bool CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks); + + virtual int GetItemPlaceCount(cItem & a_Item); protected: int m_NumSlots; @@ -263,6 +265,7 @@ public: // cSlotAreaTemporary overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; + virtual int GetItemPlaceCount(cItem & a_Item) override; protected: /// Handles a click in the item slot. -- cgit v1.2.3 From 8df922e3e0f94dca067926db3cb1229956df96db Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 14 Apr 2014 23:10:13 +0200 Subject: Add linux compatibility --- src/ClientHandle.cpp | 132 +++++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9605aa004..bcec20973 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -3181,136 +3181,146 @@ cEnchantmentsVector cClientHandle::AddEnchantmentWeight(cEnchantmentsVector a_Ma cEnchantmentsVector cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector a_Map, cEnchantments a_FirstEnchantment) { - int FirstEnchantmentID = std::stoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0]); + int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); if (FirstEnchantmentID == cEnchantments::enchProtection) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFireProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); + + if (EnchantmentID == cEnchantments::enchFireProtection) + { + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + break; + } + } + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + { + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBlastProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProjectileProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchFireProtection) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBlastProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProjectileProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFireProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProjectileProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFireProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBlastProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } @@ -3318,95 +3328,95 @@ cEnchantmentsVector cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector else if (FirstEnchantmentID == cEnchantments::enchSharpness) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSmite) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBaneOfArthropods) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchSmite) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSharpness) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBaneOfArthropods) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSharpness) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSmite) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFortune) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchFortune) { - for (cEnchantments enchantment : a_Map) + for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) { - int EnchantmentID = std::stoi(StringSplit(enchantment.ToString(), "=")[0]); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSilkTouch) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), enchantment), a_Map.end()); + a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); break; } } -- cgit v1.2.3 From fb3c755c0a6d1ccaae8e990375229afee4827e0c Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Tue, 15 Apr 2014 20:55:37 +0200 Subject: Modified names --- src/ClientHandle.cpp | 94 ++++++++++++++++++++++++++-------------------------- src/ClientHandle.h | 4 +-- 2 files changed, 49 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index bcec20973..ee94cd08d 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -3165,162 +3165,162 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) -cEnchantmentsVector cClientHandle::AddEnchantmentWeight(cEnchantmentsVector a_Map, int a_Weight, cEnchantments a_Enchantment) +cEnchantmentsVector cClientHandle::AddEnchantmentWeight(cEnchantmentsVector a_Enchantments, int a_Weight, cEnchantments a_Enchantment) { for (int i = 0; i < a_Weight; i++) { - a_Map.push_back(a_Enchantment); + a_Enchantments.push_back(a_Enchantment); } - return a_Map; + return a_Enchantments; } -cEnchantmentsVector cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector a_Map, cEnchantments a_FirstEnchantment) +cEnchantmentsVector cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector a_Enchantments, cEnchantments a_FirstEnchantment) { int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); if (FirstEnchantmentID == cEnchantments::enchProtection) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFireProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFireProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBlastProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProjectileProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchFireProtection) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBlastProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProjectileProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFireProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProjectileProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFireProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBlastProtection) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } @@ -3328,101 +3328,101 @@ cEnchantmentsVector cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector else if (FirstEnchantmentID == cEnchantments::enchSharpness) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSmite) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBaneOfArthropods) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchSmite) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSharpness) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchBaneOfArthropods) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSharpness) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSmite) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchFortune) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } else if (FirstEnchantmentID == cEnchantments::enchFortune) { - for (cEnchantmentsVector::iterator it = a_Map.begin(); it != a_Map.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == cEnchantments::enchSilkTouch) { - a_Map.erase(std::remove(a_Map.begin(), a_Map.end(), *it), a_Map.end()); + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); break; } } } - return a_Map; + return a_Enchantments; } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index b4b1d0da3..b9e470653 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -234,8 +234,8 @@ public: /** Called when the player will enchant a Item */ void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); - cEnchantmentsVector AddEnchantmentWeight(cEnchantmentsVector a_Map, int a_Weight, cEnchantments a_Enchantment); - cEnchantmentsVector CheckEnchantmentConflicts(cEnchantmentsVector a_Map, cEnchantments a_FirstEnchantment); + cEnchantmentsVector AddEnchantmentWeight(cEnchantmentsVector a_Enchantments, int a_Weight, cEnchantments a_Enchantment); + cEnchantmentsVector CheckEnchantmentConflicts(cEnchantmentsVector a_Enchantments, cEnchantments a_FirstEnchantment); private: -- cgit v1.2.3 From e81fc2779e4b9a8ce847d63864537259033c9cb9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 15 Apr 2014 21:10:44 +0200 Subject: Add more checks to cSlotAreaEnchanting --- src/UI/SlotArea.cpp | 286 ++++++++++++++++++++++++++++++++++++---------------- src/UI/SlotArea.h | 23 +++-- src/UI/Window.cpp | 2 +- 3 files changed, 212 insertions(+), 99 deletions(-) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 9ea2e0021..46ed493d8 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -135,12 +135,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA cItem tmp(DraggingItem); DraggingItem = Slot; Slot = tmp; - int ItemPlaceCount = GetItemPlaceCount(Slot); - if (Slot.m_ItemCount > ItemPlaceCount) - { - DraggingItem.m_ItemCount += Slot.m_ItemCount - ItemPlaceCount; - Slot.m_ItemCount = ItemPlaceCount; - } } else { @@ -154,12 +148,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA } int Filling = (FreeSlots > DraggingItem.m_ItemCount) ? DraggingItem.m_ItemCount : FreeSlots; - int ItemPlaceCount = GetItemPlaceCount(DraggingItem); - if (Filling > ItemPlaceCount) - { - Filling = ItemPlaceCount; - } - Slot.m_ItemCount += (char)Filling; DraggingItem.m_ItemCount -= (char)Filling; if (DraggingItem.m_ItemCount <= 0) @@ -182,7 +170,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA { m_ParentWindow.BroadcastWholeWindow(); } - } @@ -328,16 +315,6 @@ bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool -int cSlotArea::GetItemPlaceCount(cItem & a_Item) -{ - cItemHandler * Handler = ItemHandler(a_Item.m_ItemType); - return Handler->GetMaxStackSize(); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaChest: @@ -620,51 +597,200 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnchanting: -cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : -cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) : + cSlotAreaTemporary(1, a_ParentWindow) { - cEnchantingWindow * Window = (cEnchantingWindow *)&m_ParentWindow; - Window->m_SlotArea = this; + a_ParentWindow.m_SlotArea = this; } -void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - // Toss the item in the enchanting slot - TossItems(a_Player, 0, 1); - // Player not found - that is acceptable + ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); + + bool bAsync = false; + if (GetSlot(a_SlotNum, a_Player) == NULL) + { + LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + return; + } + + switch (a_ClickAction) + { + case caShiftLeftClick: + case caShiftRightClick: + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + return; + } + + case caDblClick: + { + DblClicked(a_Player, a_SlotNum); + return; + } + default: + { + break; + } + } + + cItem Slot(*GetSlot(a_SlotNum, a_Player)); + if (!Slot.IsSameType(a_ClickedItem)) + { + LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots); + LOGWARNING("My item: %s", ItemToFullString(Slot).c_str()); + LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str()); + bAsync = true; + } + cItem & DraggingItem = a_Player.GetDraggingItem(); + switch (a_ClickAction) + { + case caRightClick: + { + // Right-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (Slot.IsEmpty()) + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + else if ((!DraggingItem.IsEqual(Slot)) && (DraggingItem.m_ItemCount == 1)) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + break; + } + + case caLeftClick: + { + // Left-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (DraggingItem.IsEqual(Slot)) + { + // Do nothing + break; + } + + if (!Slot.IsEmpty()) + { + if (DraggingItem.m_ItemCount == 1) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + } + else + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + break; + } + default: + { + LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction)); + m_ParentWindow.BroadcastWholeWindow(); + return; + } + } // switch (a_ClickAction + + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } + UpdateResult(a_Player); } -void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +void cSlotAreaEnchanting::DblClicked(cPlayer & a_Player, int a_SlotNum) { - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + cItem & Dragging = a_Player.GetDraggingItem(); + if ((!Dragging.IsEmpty()) || (a_SlotNum != 0)) + { + return; + } + + cItem Item = *GetSlot(0, a_Player); + if (!m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, false)) + { + m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, true); + } +} - // Check if Slot is in the Enchantment Table - if (a_SlotNum == 0) + + + + +void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) +{ + const cItem * Slot = GetSlot(0, a_Player); + if (!Slot->IsEmpty()) { - if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) - { - ShiftClickedSlot(a_Player); - } - else - { - ClickedSlot(a_Player); - } + return; } + + if (a_Apply) + { + SetSlot(0, a_Player, a_ItemStack.CopyOne()); + } + a_ItemStack.m_ItemCount -= 1; + if (a_ItemStack.m_ItemCount <= 0) + { + a_ItemStack.Empty(); + } + + UpdateResult(a_Player); +} + + + + + +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 1); + // Player not found - that is acceptable } -void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) +void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); @@ -676,43 +802,13 @@ void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) } else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) { - int PosX = 0; - int PosY = 0; - int PosZ = 0; - cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; - Window->GetBlockPos(PosX, PosY, PosZ); - - int bookshelves = 0; - cBlockArea Area; - Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - - for (int y = 0; y <= 2; y++) - { - for (int x = 0; x <= 4; x++) - { - for (int z = 0; z <= 4; z++) - { - if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) - { - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) - { - bookshelves++; - } - } - } - } - } - - if (bookshelves > 15) - { - bookshelves = 15; - } + int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); cFastRandom Random; - int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); + int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); int topSlot = std::max(base / 3, 1); int middleSlot = (base * 2) / 3 + 1; - int bottomSlot = std::max(base, bookshelves * 2); + int bottomSlot = std::max(base, Bookshelves * 2); m_ParentWindow.SetProperty(0, topSlot, a_Player); m_ParentWindow.SetProperty(1, middleSlot, a_Player); @@ -730,20 +826,34 @@ void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) -void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) +int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) { - m_ParentWindow.SetProperty(0, 0, a_Player); - m_ParentWindow.SetProperty(1, 0, a_Player); - m_ParentWindow.SetProperty(2, 0, a_Player); -} - - + int PosX, PosY, PosZ; + ((cEnchantingWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); + int Bookshelves = 0; + cBlockArea Area; + Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - -int cSlotAreaEnchanting::GetItemPlaceCount(cItem & a_Item) -{ - return 1; + for (int y = 0; y <= 2; y++) + { + for (int x = 0; x <= 4; x++) + { + for (int z = 0; z <= 4; z++) + { + if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) + { + if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + Bookshelves++; + } + } + } + } + } + + Bookshelves = std::min(Bookshelves, 15); + return Bookshelves; } diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 431ad753c..bab1098bb 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -19,6 +19,8 @@ class cDropSpenserEntity; class cEnderChestEntity; class cFurnaceEntity; class cCraftingRecipe; +class cEnchantingWindow; +class cWorld; @@ -67,8 +69,6 @@ public: /// Returns true if full stack has been collected in a_Dragging, false if there's space remaining to fill. virtual bool CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks); - virtual int GetItemPlaceCount(cItem & a_Item); - protected: int m_NumSlots; cWindow & m_ParentWindow; @@ -260,19 +260,22 @@ class cSlotAreaEnchanting : typedef cSlotAreaTemporary super; public: - cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow); + cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow); - // cSlotAreaTemporary overrides: + // cSlotArea overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void DblClicked(cPlayer & a_Player, int a_SlotNum) override; + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; + + // cSlotAreaTemporary overrides: virtual void OnPlayerRemoved(cPlayer & a_Player) override; - virtual int GetItemPlaceCount(cItem & a_Item) override; -protected: - /// Handles a click in the item slot. - void ClickedSlot(cPlayer & a_Player); + /* Get the count of bookshelves who stand in the near of the enchanting table */ + int GetBookshelvesCount(cWorld * a_World); - /// Handles a shift-click in the item slot. - void ShiftClickedSlot(cPlayer & a_Player); +protected: + /** Handles a click in the item slot. */ + void UpdateResult(cPlayer & a_Player); }; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index c514e76e7..c7b9b6aaf 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -813,7 +813,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : m_BlockY(a_BlockY), m_BlockZ(a_BlockZ) { - m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); + m_SlotAreas.push_back(new cSlotAreaEnchanting(*this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); } -- cgit v1.2.3 From 36f747d6746b32c4352354933b25ae7ead6f1b7f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Tue, 15 Apr 2014 21:43:52 +0200 Subject: Added Book Enchanting --- src/ClientHandle.cpp | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/UI/SlotArea.cpp | 2 +- 2 files changed, 311 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index ee94cd08d..905be5438 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2692,7 +2692,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); - if (!cItem::IsEnchantable(Item.m_ItemType)) + if (!cItem::IsEnchantable(Item.m_ItemType) && Item.m_ItemType != E_ITEM_BOOK) { return; } @@ -3076,6 +3076,315 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) } } + else if (Item.m_ItemType == E_ITEM_BOOK) + { + // All enchantments + + // Sharpness + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); + } + + // Smite + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); + } + + // Bane of Arthropods + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); + } + + // Knockback + if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); + } + + // Fire Aspect + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); + } + + // Looting + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); + } + + // Efficiency + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); + } + + // Silk Touch + if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); + } + + // Fortune + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); + } + + // Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); + } + + // Fire Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); + } + else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); + } + else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); + } + + // Blast Protection + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); + } + + // Projectile Protection + if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); + } + else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); + } + else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); + } + + // Thorns + if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); + } + else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); + } + + // Respiration + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); + } + else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); + } + + // Aqua Affinity + if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); + } + + // Feather Fall + if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); + } + else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) + { + enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); + } + + // Power + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) + { + enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); + } + + // Punch + if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); + } + + // Flame and Infinity + if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); + } + + // Luck of the Sea and Lure + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); + enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); + } + + Item.m_ItemType = E_ITEM_ENCHANTED_BOOK; + } + // Unbreaking if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) { diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 46ed493d8..d8d02f458 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -800,7 +800,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) + else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK && Item.m_Enchantments.IsEmpty()) { int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); -- cgit v1.2.3 From 2cb8538e2e60309bc9d1f13dc90dd5cbface8967 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Tue, 15 Apr 2014 22:03:15 +0200 Subject: Code Optimization --- src/ClientHandle.cpp | 536 +++++++++++++++++---------------------------------- src/ClientHandle.h | 5 +- 2 files changed, 183 insertions(+), 358 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 905be5438..406ca6e19 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2757,89 +2757,89 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Sharpness if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); } else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); } else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); } // Smite if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); } else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); } // Bane of Arthropods if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); } else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); } // Knockback if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); } // Fire Aspect if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); } // Looting if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); } else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); } } @@ -2848,39 +2848,39 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Efficiency if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); } else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); } // Silk Touch if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); } // Fortune if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); } else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); } } @@ -2889,87 +2889,87 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Protection if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); } else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); } else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); } // Fire Protection if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); } else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); } else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); } // Blast Protection if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); } else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); } // Projectile Protection if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); } else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); } else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); } // Thorns if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); } else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); } @@ -2978,21 +2978,21 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Respiration if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); } else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); } // Aqua Affinity if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); } } @@ -3001,19 +3001,19 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Feather Fall if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); } else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); } else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); } } } @@ -3023,36 +3023,36 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Power if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); } else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); } // Punch if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); } else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); } // Flame and Infinity if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); } } @@ -3061,18 +3061,18 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Luck of the Sea and Lure if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); } else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); } } @@ -3083,303 +3083,303 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Sharpness if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); } else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); } else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); } // Smite if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); } else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); } // Bane of Arthropods if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); } else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); } // Knockback if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); } // Fire Aspect if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); } // Looting if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); } else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); } // Efficiency if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); } else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); } // Silk Touch if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); } // Fortune if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); } else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); } // Protection if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); } else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); } else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); } // Fire Protection if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); } else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); } else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); } // Blast Protection if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); } else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); } // Projectile Protection if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); } else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); } else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); } // Thorns if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); } else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); } // Respiration if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); } else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); } else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); } // Aqua Affinity if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); } // Feather Fall if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); } else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); } else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); } // Power if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); } else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); } else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); } else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) { - enchantments = AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); } // Punch if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); } else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); } // Flame and Infinity if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) { - enchantments = AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); + AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); } // Luck of the Sea and Lure if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); } else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); } else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) { - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); - enchantments = AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); } Item.m_ItemType = E_ITEM_ENCHANTED_BOOK; @@ -3388,15 +3388,15 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) // Unbreaking if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=3")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=3")); } else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 63) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=2")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=2")); } else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) { - enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1")); + AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1")); } int RandomEnchantment1 = (int) floor(Random.NextFloat(1) * enchantments.size()); @@ -3412,7 +3412,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) if (Random.NextFloat(100) <= SecondEnchantmentChance) { // Checking for conflicting enchantments - enchantments = CheckEnchantmentConflicts(enchantments, Enchantment1); + CheckEnchantmentConflicts(enchantments, Enchantment1); if (enchantments.size() > 0) { @@ -3423,7 +3423,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); // Checking for conflicting enchantments - enchantments = CheckEnchantmentConflicts(enchantments, Enchantment2); + CheckEnchantmentConflicts(enchantments, Enchantment2); } } @@ -3440,7 +3440,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); // Checking for conflicting enchantments - enchantments = CheckEnchantmentConflicts(enchantments, Enchantment3); + CheckEnchantmentConflicts(enchantments, Enchantment3); } } @@ -3474,264 +3474,88 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) -cEnchantmentsVector cClientHandle::AddEnchantmentWeight(cEnchantmentsVector a_Enchantments, int a_Weight, cEnchantments a_Enchantment) +void cClientHandle::AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment) { for (int i = 0; i < a_Weight; i++) { a_Enchantments.push_back(a_Enchantment); } - - return a_Enchantments; } -cEnchantmentsVector cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector a_Enchantments, cEnchantments a_FirstEnchantment) +void cClientHandle::RemoveEnchantmentFromVector(cEnchantmentsVector & a_Enchantments, int a_EnchantmentID) { - int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); - - if (FirstEnchantmentID == cEnchantments::enchProtection) + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - if (EnchantmentID == cEnchantments::enchFireProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + if (EnchantmentID == a_EnchantmentID) { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchFireProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); + break; } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); + } +} - if (EnchantmentID == cEnchantments::enchBlastProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - if (EnchantmentID == cEnchantments::enchProjectileProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - } - else if (FirstEnchantmentID == cEnchantments::enchFireProtection) - { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - if (EnchantmentID == cEnchantments::enchProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - if (EnchantmentID == cEnchantments::enchBlastProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - if (EnchantmentID == cEnchantments::enchProjectileProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } +void cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment) +{ + int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); + + if (FirstEnchantmentID == cEnchantments::enchProtection) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (FirstEnchantmentID == cEnchantments::enchFireProtection) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); } else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchFireProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchProjectileProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); } else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchFireProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchBlastProtection) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); } else if (FirstEnchantmentID == cEnchantments::enchSharpness) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchSmite) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchBaneOfArthropods) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); } else if (FirstEnchantmentID == cEnchantments::enchSmite) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchSharpness) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchBaneOfArthropods) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); } else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchSharpness) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchSmite) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); } else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchFortune) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFortune); } else if (FirstEnchantmentID == cEnchantments::enchFortune) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == cEnchantments::enchSilkTouch) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSilkTouch); } - - return a_Enchantments; } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index b9e470653..f6d0af3b4 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -234,8 +234,9 @@ public: /** Called when the player will enchant a Item */ void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); - cEnchantmentsVector AddEnchantmentWeight(cEnchantmentsVector a_Enchantments, int a_Weight, cEnchantments a_Enchantment); - cEnchantmentsVector CheckEnchantmentConflicts(cEnchantmentsVector a_Enchantments, cEnchantments a_FirstEnchantment); + void AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment); + void RemoveEnchantmentFromVector(cEnchantmentsVector & a_Enchantments, int a_EnchantmentID); + void CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment); private: -- cgit v1.2.3 From 8c33b3c4155b030e2174a453ca067be969473736 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Wed, 16 Apr 2014 13:31:37 +0200 Subject: Fixed double enchanting items --- src/UI/SlotArea.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index d8d02f458..621854518 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -794,13 +794,13 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); - if (Item.IsEmpty()) + if (Item.IsEmpty() || !Item.m_Enchantments.IsEmpty()) { m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK && Item.m_Enchantments.IsEmpty()) + else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) { int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); -- cgit v1.2.3 From 8d67562238b1772b763766b85779c1afd211d3f5 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Wed, 16 Apr 2014 14:30:55 +0200 Subject: Fixed merge conflict --- src/ClientHandle.cpp | 877 --------------------------------------------------- 1 file changed, 877 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 406ca6e19..5876e55c7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -31,8 +31,6 @@ #include "CompositeChat.h" #include "Items/ItemSword.h" -#include "FastRandom.h" - /** Maximum number of explosions to send this tick, server will start dropping if exceeded */ @@ -2687,879 +2685,4 @@ void cClientHandle::SocketClosed(void) -void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) -{ - cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); - cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); - - if (!cItem::IsEnchantable(Item.m_ItemType) && Item.m_ItemType != E_ITEM_BOOK) - { - return; - } - - int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); - - // Step 1 from Enchanting - int Enchantability = 1; - - if (Item.m_ItemType == E_ITEM_WOODEN_SWORD || Item.m_ItemType == E_ITEM_WOODEN_PICKAXE || Item.m_ItemType == E_ITEM_WOODEN_SHOVEL || Item.m_ItemType == E_ITEM_WOODEN_AXE || Item.m_ItemType == E_ITEM_WOODEN_HOE) - { - Enchantability = 15; - } - else if (Item.m_ItemType == E_ITEM_LEATHER_CAP || Item.m_ItemType == E_ITEM_LEATHER_TUNIC || Item.m_ItemType == E_ITEM_LEATHER_PANTS || Item.m_ItemType == E_ITEM_LEATHER_BOOTS) - { - Enchantability = 15; - } - else if (Item.m_ItemType == E_ITEM_STONE_SWORD || Item.m_ItemType == E_ITEM_STONE_PICKAXE || Item.m_ItemType == E_ITEM_STONE_SHOVEL || Item.m_ItemType == E_ITEM_STONE_AXE || Item.m_ItemType == E_ITEM_STONE_HOE) - { - Enchantability = 5; - } - else if (Item.m_ItemType == E_ITEM_IRON_HELMET || Item.m_ItemType == E_ITEM_IRON_CHESTPLATE || Item.m_ItemType == E_ITEM_IRON_LEGGINGS || Item.m_ItemType == E_ITEM_IRON_BOOTS) - { - Enchantability = 9; - } - else if (Item.m_ItemType == E_ITEM_IRON_SWORD || Item.m_ItemType == E_ITEM_IRON_PICKAXE || Item.m_ItemType == E_ITEM_IRON_SHOVEL || Item.m_ItemType == E_ITEM_IRON_AXE || Item.m_ItemType == E_ITEM_IRON_HOE) - { - Enchantability = 14; - } - else if (Item.m_ItemType == E_ITEM_CHAIN_HELMET || Item.m_ItemType == E_ITEM_CHAIN_CHESTPLATE || Item.m_ItemType == E_ITEM_CHAIN_LEGGINGS || Item.m_ItemType == E_ITEM_CHAIN_BOOTS) - { - Enchantability = 12; - } - else if (Item.m_ItemType == E_ITEM_DIAMOND_HELMET || Item.m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || Item.m_ItemType == E_ITEM_DIAMOND_LEGGINGS || Item.m_ItemType == E_ITEM_DIAMOND_BOOTS) - { - Enchantability = 10; - } - else if (Item.m_ItemType == E_ITEM_DIAMOND_SWORD || Item.m_ItemType == E_ITEM_DIAMOND_PICKAXE || Item.m_ItemType == E_ITEM_DIAMOND_SHOVEL || Item.m_ItemType == E_ITEM_DIAMOND_AXE || Item.m_ItemType == E_ITEM_DIAMOND_HOE) - { - Enchantability = 10; - } - else if (Item.m_ItemType == E_ITEM_GOLD_HELMET || Item.m_ItemType == E_ITEM_GOLD_CHESTPLATE || Item.m_ItemType == E_ITEM_GOLD_LEGGINGS || Item.m_ItemType == E_ITEM_GOLD_BOOTS) - { - Enchantability = 25; - } - else if (Item.m_ItemType == E_ITEM_GOLD_SWORD || Item.m_ItemType == E_ITEM_GOLD_PICKAXE || Item.m_ItemType == E_ITEM_GOLD_SHOVEL || Item.m_ItemType == E_ITEM_GOLD_AXE || Item.m_ItemType == E_ITEM_GOLD_HOE) - { - Enchantability = 22; - } - - cFastRandom Random; - int ModifiedEnchantmentLevel = BaseEnchantmentLevel + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1; - float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; - - int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); - - // Step 2 and 3 from Enchanting - cEnchantmentsVector enchantments; - - if (ItemCategory::IsSword(Item.m_ItemType)) - { - // Sharpness - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); - } - - // Smite - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); - } - - // Bane of Arthropods - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); - } - - // Knockback - if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); - } - - // Fire Aspect - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); - } - - // Looting - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); - } - } - - else if (ItemCategory::IsTool(Item.m_ItemType)) - { - // Efficiency - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); - } - - // Silk Touch - if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); - } - - // Fortune - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); - } - } - - else if (ItemCategory::IsArmor(Item.m_ItemType)) - { - // Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); - } - - // Fire Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); - } - else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); - } - else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); - } - - // Blast Protection - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); - } - - // Projectile Protection - if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); - } - else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); - } - else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); - } - - // Thorns - if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); - } - else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); - } - - - if (ItemCategory::IsHelmet(Item.m_ItemType)) - { - // Respiration - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); - } - else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); - } - - // Aqua Affinity - if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); - } - } - - else if (ItemCategory::IsBoots(Item.m_ItemType)) - { - // Feather Fall - if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); - } - else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); - } - } - } - - else if (Item.m_ItemType == E_ITEM_BOW) - { - // Power - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); - } - - // Punch - if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); - } - - // Flame and Infinity - if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); - } - } - - else if (Item.m_ItemType == E_ITEM_FISHING_ROD) - { - // Luck of the Sea and Lure - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); - } - } - - else if (Item.m_ItemType == E_ITEM_BOOK) - { - // All enchantments - - // Sharpness - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); - } - - // Smite - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); - } - - // Bane of Arthropods - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); - } - - // Knockback - if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); - } - - // Fire Aspect - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); - } - - // Looting - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); - } - - // Efficiency - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); - } - - // Silk Touch - if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); - } - - // Fortune - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); - } - - // Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); - } - - // Fire Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); - } - else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); - } - else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); - } - - // Blast Protection - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); - } - - // Projectile Protection - if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); - } - else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); - } - else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); - } - - // Thorns - if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); - } - else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); - } - - // Respiration - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); - } - else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); - } - - // Aqua Affinity - if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); - } - - // Feather Fall - if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); - } - else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); - } - - // Power - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); - } - - // Punch - if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); - } - - // Flame and Infinity - if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); - } - - // Luck of the Sea and Lure - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); - } - - Item.m_ItemType = E_ITEM_ENCHANTED_BOOK; - } - - // Unbreaking - if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 63) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1")); - } - - int RandomEnchantment1 = (int) floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment1 = enchantments[RandomEnchantment1]; - Item.m_Enchantments.AddFromString(Enchantment1.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); - - float NewEnchantmentLevel = (float) BaseEnchantmentLevel; - - // Next Enchantment (Second) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= SecondEnchantmentChance) - { - // Checking for conflicting enchantments - CheckEnchantmentConflicts(enchantments, Enchantment1); - - if (enchantments.size() > 0) - { - int RandomEnchantment2 = (int) floor(Random.NextFloat(1) * enchantments.size()); - - cEnchantments Enchantment2 = enchantments[RandomEnchantment2]; - Item.m_Enchantments.AddFromString(Enchantment2.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); - - // Checking for conflicting enchantments - CheckEnchantmentConflicts(enchantments, Enchantment2); - } - } - - // Next Enchantment (Third) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= ThirdEnchantmentChance) - { - if (enchantments.size() > 0) - { - int RandomEnchantment3 = (int) floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment3 = enchantments[RandomEnchantment3]; - Item.m_Enchantments.AddFromString(Enchantment3.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); - - // Checking for conflicting enchantments - CheckEnchantmentConflicts(enchantments, Enchantment3); - } - } - - // Next Enchantment (Fourth) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= FourthEnchantmentChance) - { - if (enchantments.size() > 0) - { - int RandomEnchantment4 = (int) floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment4 = enchantments[RandomEnchantment4]; - Item.m_Enchantments.AddFromString(Enchantment4.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); - } - } - - if (m_Player->DeltaExperience(-m_Player->XpForLevel(Window->GetPropertyValue(Enchantment))) >= 0 || m_Player->IsGameModeCreative()) - { - Window->m_SlotArea->SetSlot(0, *m_Player, Item); - Window->SendSlot(*m_Player, Window->m_SlotArea, 0); - Window->BroadcastWholeWindow(); - - Window->SetProperty(0, 0, *m_Player); - Window->SetProperty(1, 0, *m_Player); - Window->SetProperty(2, 0, *m_Player); - } -} - - - - - -void cClientHandle::AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment) -{ - for (int i = 0; i < a_Weight; i++) - { - a_Enchantments.push_back(a_Enchantment); - } -} - - - - - -void cClientHandle::RemoveEnchantmentFromVector(cEnchantmentsVector & a_Enchantments, int a_EnchantmentID) -{ - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == a_EnchantmentID) - { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); - break; - } - } -} - - - - - -void cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment) -{ - int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); - - if (FirstEnchantmentID == cEnchantments::enchProtection) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); - } - else if (FirstEnchantmentID == cEnchantments::enchFireProtection) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); - } - else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); - } - else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); - } - - else if (FirstEnchantmentID == cEnchantments::enchSharpness) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); - } - else if (FirstEnchantmentID == cEnchantments::enchSmite) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); - } - else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); - } - else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFortune); - } - else if (FirstEnchantmentID == cEnchantments::enchFortune) - { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSilkTouch); - } -} - - - - - -- cgit v1.2.3 From a12a9117c2cfe2339a633c678e86597bed876f4a Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Wed, 16 Apr 2014 14:33:03 +0200 Subject: Added deletions from merge conflict --- src/ClientHandle.cpp | 875 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 875 insertions(+) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9ab32d6ec..319af9ed3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -31,6 +31,8 @@ #include "CompositeChat.h" #include "Items/ItemSword.h" +#include "FastRandom.h" + #include "md5/md5.h" @@ -2729,4 +2731,877 @@ void cClientHandle::SocketClosed(void) +void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) +{ + cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); + cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); + + if (!cItem::IsEnchantable(Item.m_ItemType) && Item.m_ItemType != E_ITEM_BOOK) + { + return; + } + + int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); + + // Step 1 from Enchanting + int Enchantability = 1; + + if (Item.m_ItemType == E_ITEM_WOODEN_SWORD || Item.m_ItemType == E_ITEM_WOODEN_PICKAXE || Item.m_ItemType == E_ITEM_WOODEN_SHOVEL || Item.m_ItemType == E_ITEM_WOODEN_AXE || Item.m_ItemType == E_ITEM_WOODEN_HOE) + { + Enchantability = 15; + } + else if (Item.m_ItemType == E_ITEM_LEATHER_CAP || Item.m_ItemType == E_ITEM_LEATHER_TUNIC || Item.m_ItemType == E_ITEM_LEATHER_PANTS || Item.m_ItemType == E_ITEM_LEATHER_BOOTS) + { + Enchantability = 15; + } + else if (Item.m_ItemType == E_ITEM_STONE_SWORD || Item.m_ItemType == E_ITEM_STONE_PICKAXE || Item.m_ItemType == E_ITEM_STONE_SHOVEL || Item.m_ItemType == E_ITEM_STONE_AXE || Item.m_ItemType == E_ITEM_STONE_HOE) + { + Enchantability = 5; + } + else if (Item.m_ItemType == E_ITEM_IRON_HELMET || Item.m_ItemType == E_ITEM_IRON_CHESTPLATE || Item.m_ItemType == E_ITEM_IRON_LEGGINGS || Item.m_ItemType == E_ITEM_IRON_BOOTS) + { + Enchantability = 9; + } + else if (Item.m_ItemType == E_ITEM_IRON_SWORD || Item.m_ItemType == E_ITEM_IRON_PICKAXE || Item.m_ItemType == E_ITEM_IRON_SHOVEL || Item.m_ItemType == E_ITEM_IRON_AXE || Item.m_ItemType == E_ITEM_IRON_HOE) + { + Enchantability = 14; + } + else if (Item.m_ItemType == E_ITEM_CHAIN_HELMET || Item.m_ItemType == E_ITEM_CHAIN_CHESTPLATE || Item.m_ItemType == E_ITEM_CHAIN_LEGGINGS || Item.m_ItemType == E_ITEM_CHAIN_BOOTS) + { + Enchantability = 12; + } + else if (Item.m_ItemType == E_ITEM_DIAMOND_HELMET || Item.m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || Item.m_ItemType == E_ITEM_DIAMOND_LEGGINGS || Item.m_ItemType == E_ITEM_DIAMOND_BOOTS) + { + Enchantability = 10; + } + else if (Item.m_ItemType == E_ITEM_DIAMOND_SWORD || Item.m_ItemType == E_ITEM_DIAMOND_PICKAXE || Item.m_ItemType == E_ITEM_DIAMOND_SHOVEL || Item.m_ItemType == E_ITEM_DIAMOND_AXE || Item.m_ItemType == E_ITEM_DIAMOND_HOE) + { + Enchantability = 10; + } + else if (Item.m_ItemType == E_ITEM_GOLD_HELMET || Item.m_ItemType == E_ITEM_GOLD_CHESTPLATE || Item.m_ItemType == E_ITEM_GOLD_LEGGINGS || Item.m_ItemType == E_ITEM_GOLD_BOOTS) + { + Enchantability = 25; + } + else if (Item.m_ItemType == E_ITEM_GOLD_SWORD || Item.m_ItemType == E_ITEM_GOLD_PICKAXE || Item.m_ItemType == E_ITEM_GOLD_SHOVEL || Item.m_ItemType == E_ITEM_GOLD_AXE || Item.m_ItemType == E_ITEM_GOLD_HOE) + { + Enchantability = 22; + } + + cFastRandom Random; + int ModifiedEnchantmentLevel = BaseEnchantmentLevel + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1; + float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; + + int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); + + // Step 2 and 3 from Enchanting + cEnchantmentsVector enchantments; + + if (ItemCategory::IsSword(Item.m_ItemType)) + { + // Sharpness + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); + } + + // Smite + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); + } + + // Bane of Arthropods + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); + } + + // Knockback + if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); + } + + // Fire Aspect + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); + } + + // Looting + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); + } + } + + else if (ItemCategory::IsTool(Item.m_ItemType)) + { + // Efficiency + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); + } + + // Silk Touch + if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); + } + + // Fortune + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); + } + } + + else if (ItemCategory::IsArmor(Item.m_ItemType)) + { + // Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); + } + + // Fire Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); + } + else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); + } + else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); + } + + // Blast Protection + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); + } + + // Projectile Protection + if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); + } + else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); + } + else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); + } + + // Thorns + if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); + } + else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); + } + + + if (ItemCategory::IsHelmet(Item.m_ItemType)) + { + // Respiration + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); + } + else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); + } + + // Aqua Affinity + if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); + } + } + + else if (ItemCategory::IsBoots(Item.m_ItemType)) + { + // Feather Fall + if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); + } + else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); + } + } + } + + else if (Item.m_ItemType == E_ITEM_BOW) + { + // Power + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); + } + + // Punch + if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); + } + + // Flame and Infinity + if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); + } + } + + else if (Item.m_ItemType == E_ITEM_FISHING_ROD) + { + // Luck of the Sea and Lure + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); + } + } + + else if (Item.m_ItemType == E_ITEM_BOOK) + { + // All enchantments + + // Sharpness + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); + } + + // Smite + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); + } + + // Bane of Arthropods + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); + } + + // Knockback + if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); + } + + // Fire Aspect + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); + } + + // Looting + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); + } + + // Efficiency + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); + } + + // Silk Touch + if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); + } + + // Fortune + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); + } + + // Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); + } + else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); + } + + // Fire Protection + if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); + } + else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); + } + else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); + } + + // Blast Protection + if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); + } + + // Projectile Protection + if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); + } + else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); + } + else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); + } + + // Thorns + if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); + } + else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); + } + + // Respiration + if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); + } + else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); + } + else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); + } + + // Aqua Affinity + if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); + } + + // Feather Fall + if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); + } + else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); + } + + // Power + if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); + } + else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); + } + else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); + } + else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) + { + AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); + } + + // Punch + if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); + } + else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); + } + + // Flame and Infinity + if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) + { + AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); + } + + // Luck of the Sea and Lure + if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); + } + else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); + } + else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) + { + AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); + AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); + } + + Item.m_ItemType = E_ITEM_ENCHANTED_BOOK; + } + + // Unbreaking + if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=3")); + } + else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 63) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=2")); + } + else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) + { + AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1")); + } + + int RandomEnchantment1 = (int)floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment1 = enchantments[RandomEnchantment1]; + Item.m_Enchantments.AddFromString(Enchantment1.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); + + float NewEnchantmentLevel = (float)BaseEnchantmentLevel; + + // Next Enchantment (Second) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= SecondEnchantmentChance) + { + // Checking for conflicting enchantments + CheckEnchantmentConflicts(enchantments, Enchantment1); + + if (enchantments.size() > 0) + { + int RandomEnchantment2 = (int)floor(Random.NextFloat(1) * enchantments.size()); + + cEnchantments Enchantment2 = enchantments[RandomEnchantment2]; + Item.m_Enchantments.AddFromString(Enchantment2.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); + + // Checking for conflicting enchantments + CheckEnchantmentConflicts(enchantments, Enchantment2); + } + } + + // Next Enchantment (Third) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= ThirdEnchantmentChance) + { + if (enchantments.size() > 0) + { + int RandomEnchantment3 = (int)floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment3 = enchantments[RandomEnchantment3]; + Item.m_Enchantments.AddFromString(Enchantment3.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); + + // Checking for conflicting enchantments + CheckEnchantmentConflicts(enchantments, Enchantment3); + } + } + + // Next Enchantment (Fourth) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= FourthEnchantmentChance) + { + if (enchantments.size() > 0) + { + int RandomEnchantment4 = (int)floor(Random.NextFloat(1) * enchantments.size()); + cEnchantments Enchantment4 = enchantments[RandomEnchantment4]; + Item.m_Enchantments.AddFromString(Enchantment4.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); + } + } + + if (m_Player->DeltaExperience(-m_Player->XpForLevel(Window->GetPropertyValue(Enchantment))) >= 0 || m_Player->IsGameModeCreative()) + { + Window->m_SlotArea->SetSlot(0, *m_Player, Item); + Window->SendSlot(*m_Player, Window->m_SlotArea, 0); + Window->BroadcastWholeWindow(); + + Window->SetProperty(0, 0, *m_Player); + Window->SetProperty(1, 0, *m_Player); + Window->SetProperty(2, 0, *m_Player); + } +} + + + + + +void cClientHandle::AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment) +{ + for (int i = 0; i < a_Weight; i++) + { + a_Enchantments.push_back(a_Enchantment); + } +} + + + + + +void cClientHandle::RemoveEnchantmentFromVector(cEnchantmentsVector & a_Enchantments, int a_EnchantmentID) +{ + for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); + + if (EnchantmentID == a_EnchantmentID) + { + a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); + break; + } + } +} + + + + + +void cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment) +{ + int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); + + if (FirstEnchantmentID == cEnchantments::enchProtection) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (FirstEnchantmentID == cEnchantments::enchFireProtection) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + } + + else if (FirstEnchantmentID == cEnchantments::enchSharpness) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (FirstEnchantmentID == cEnchantments::enchSmite) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); + } + else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFortune); + } + else if (FirstEnchantmentID == cEnchantments::enchFortune) + { + RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSilkTouch); + } +} + + + -- cgit v1.2.3 From a0725747af9581744577be7ed06c07ec9c9fe3f2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Wed, 16 Apr 2014 14:52:09 +0200 Subject: Fixed conflicting enchantments checking --- src/ClientHandle.cpp | 46 +++++++++++++++++++++++----------------------- src/ClientHandle.h | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 319af9ed3..688441d39 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -3530,15 +3530,15 @@ void cClientHandle::AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, i -void cClientHandle::RemoveEnchantmentFromVector(cEnchantmentsVector & a_Enchantments, int a_EnchantmentID) +void cClientHandle::RemoveEnchantmentFromVector(cEnchantmentsVector * a_Enchantments, int a_EnchantmentID) { - for (cEnchantmentsVector::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + for (cEnchantmentsVector::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it) { int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); if (EnchantmentID == a_EnchantmentID) { - a_Enchantments.erase(std::remove(a_Enchantments.begin(), a_Enchantments.end(), *it), a_Enchantments.end()); + a_Enchantments->erase(std::remove(a_Enchantments->begin(), a_Enchantments->end(), *it), a_Enchantments->end()); break; } } @@ -3554,51 +3554,51 @@ void cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantmen if (FirstEnchantmentID == cEnchantments::enchProtection) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); } else if (FirstEnchantmentID == cEnchantments::enchFireProtection) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); } else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); } else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); } else if (FirstEnchantmentID == cEnchantments::enchSharpness) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); } else if (FirstEnchantmentID == cEnchantments::enchSmite) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); } else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSmite); } else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchFortune); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFortune); } else if (FirstEnchantmentID == cEnchantments::enchFortune) { - RemoveEnchantmentFromVector(a_Enchantments, cEnchantments::enchSilkTouch); + RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSilkTouch); } } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 8bba0d27c..1829e3b4d 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -249,7 +249,7 @@ public: /** Called when the player will enchant a Item */ void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); void AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment); - void RemoveEnchantmentFromVector(cEnchantmentsVector & a_Enchantments, int a_EnchantmentID); + void RemoveEnchantmentFromVector(cEnchantmentsVector * a_Enchantments, int a_EnchantmentID); void CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment); private: -- cgit v1.2.3 From f9343a8490b50cb28a62c7327c0013da48ca2745 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 17 Apr 2014 13:15:35 +0200 Subject: Modified many things --- src/ClientHandle.cpp | 857 +------------------------------------------ src/ClientHandle.h | 3 - src/Enchantments.cpp | 769 ++++++++++++++++++++++++++++++++++++++ src/Enchantments.h | 30 +- src/Item.cpp | 141 +++++++ src/Item.h | 7 + src/Protocol/Protocol125.cpp | 2 - src/UI/SlotArea.cpp | 66 +++- src/UI/Window.cpp | 41 +-- src/UI/Window.h | 2 +- 10 files changed, 1000 insertions(+), 918 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 688441d39..a3d0501c3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -31,8 +31,6 @@ #include "CompositeChat.h" #include "Items/ItemSword.h" -#include "FastRandom.h" - #include "md5/md5.h" @@ -2735,774 +2733,9 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) { cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); - - if (!cItem::IsEnchantable(Item.m_ItemType) && Item.m_ItemType != E_ITEM_BOOK) - { - return; - } - int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); - // Step 1 from Enchanting - int Enchantability = 1; - - if (Item.m_ItemType == E_ITEM_WOODEN_SWORD || Item.m_ItemType == E_ITEM_WOODEN_PICKAXE || Item.m_ItemType == E_ITEM_WOODEN_SHOVEL || Item.m_ItemType == E_ITEM_WOODEN_AXE || Item.m_ItemType == E_ITEM_WOODEN_HOE) - { - Enchantability = 15; - } - else if (Item.m_ItemType == E_ITEM_LEATHER_CAP || Item.m_ItemType == E_ITEM_LEATHER_TUNIC || Item.m_ItemType == E_ITEM_LEATHER_PANTS || Item.m_ItemType == E_ITEM_LEATHER_BOOTS) - { - Enchantability = 15; - } - else if (Item.m_ItemType == E_ITEM_STONE_SWORD || Item.m_ItemType == E_ITEM_STONE_PICKAXE || Item.m_ItemType == E_ITEM_STONE_SHOVEL || Item.m_ItemType == E_ITEM_STONE_AXE || Item.m_ItemType == E_ITEM_STONE_HOE) - { - Enchantability = 5; - } - else if (Item.m_ItemType == E_ITEM_IRON_HELMET || Item.m_ItemType == E_ITEM_IRON_CHESTPLATE || Item.m_ItemType == E_ITEM_IRON_LEGGINGS || Item.m_ItemType == E_ITEM_IRON_BOOTS) - { - Enchantability = 9; - } - else if (Item.m_ItemType == E_ITEM_IRON_SWORD || Item.m_ItemType == E_ITEM_IRON_PICKAXE || Item.m_ItemType == E_ITEM_IRON_SHOVEL || Item.m_ItemType == E_ITEM_IRON_AXE || Item.m_ItemType == E_ITEM_IRON_HOE) - { - Enchantability = 14; - } - else if (Item.m_ItemType == E_ITEM_CHAIN_HELMET || Item.m_ItemType == E_ITEM_CHAIN_CHESTPLATE || Item.m_ItemType == E_ITEM_CHAIN_LEGGINGS || Item.m_ItemType == E_ITEM_CHAIN_BOOTS) - { - Enchantability = 12; - } - else if (Item.m_ItemType == E_ITEM_DIAMOND_HELMET || Item.m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || Item.m_ItemType == E_ITEM_DIAMOND_LEGGINGS || Item.m_ItemType == E_ITEM_DIAMOND_BOOTS) - { - Enchantability = 10; - } - else if (Item.m_ItemType == E_ITEM_DIAMOND_SWORD || Item.m_ItemType == E_ITEM_DIAMOND_PICKAXE || Item.m_ItemType == E_ITEM_DIAMOND_SHOVEL || Item.m_ItemType == E_ITEM_DIAMOND_AXE || Item.m_ItemType == E_ITEM_DIAMOND_HOE) - { - Enchantability = 10; - } - else if (Item.m_ItemType == E_ITEM_GOLD_HELMET || Item.m_ItemType == E_ITEM_GOLD_CHESTPLATE || Item.m_ItemType == E_ITEM_GOLD_LEGGINGS || Item.m_ItemType == E_ITEM_GOLD_BOOTS) - { - Enchantability = 25; - } - else if (Item.m_ItemType == E_ITEM_GOLD_SWORD || Item.m_ItemType == E_ITEM_GOLD_PICKAXE || Item.m_ItemType == E_ITEM_GOLD_SHOVEL || Item.m_ItemType == E_ITEM_GOLD_AXE || Item.m_ItemType == E_ITEM_GOLD_HOE) - { - Enchantability = 22; - } - - cFastRandom Random; - int ModifiedEnchantmentLevel = BaseEnchantmentLevel + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1; - float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; - - int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); - - // Step 2 and 3 from Enchanting - cEnchantmentsVector enchantments; - - if (ItemCategory::IsSword(Item.m_ItemType)) - { - // Sharpness - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); - } - - // Smite - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); - } - - // Bane of Arthropods - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); - } - - // Knockback - if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); - } - - // Fire Aspect - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); - } - - // Looting - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); - } - } - - else if (ItemCategory::IsTool(Item.m_ItemType)) - { - // Efficiency - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); - } - - // Silk Touch - if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); - } - - // Fortune - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); - } - } - - else if (ItemCategory::IsArmor(Item.m_ItemType)) - { - // Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); - } - - // Fire Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); - } - else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); - } - else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); - } - - // Blast Protection - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); - } - - // Projectile Protection - if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); - } - else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); - } - else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); - } - - // Thorns - if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); - } - else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); - } - - - if (ItemCategory::IsHelmet(Item.m_ItemType)) - { - // Respiration - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); - } - else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); - } - - // Aqua Affinity - if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); - } - } - - else if (ItemCategory::IsBoots(Item.m_ItemType)) - { - // Feather Fall - if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); - } - else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); - } - } - } - - else if (Item.m_ItemType == E_ITEM_BOW) - { - // Power - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); - } - - // Punch - if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); - } - - // Flame and Infinity - if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); - } - } - - else if (Item.m_ItemType == E_ITEM_FISHING_ROD) - { - // Luck of the Sea and Lure - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); - } - } - - else if (Item.m_ItemType == E_ITEM_BOOK) - { - // All enchantments - - // Sharpness - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1")); - } - - // Smite - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1")); - } - - // Bane of Arthropods - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1")); - } - - // Knockback - if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1")); - } - - // Fire Aspect - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1")); - } - - // Looting - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1")); - } - - // Efficiency - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1")); - } - - // Silk Touch - if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1")); - } - - // Fortune - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1")); - } - - // Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4")); - } - else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1")); - } - - // Fire Protection - if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4")); - } - else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3")); - } - else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1")); - } - - // Blast Protection - if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1")); - } - - // Projectile Protection - if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3")); - } - else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2")); - } - else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1")); - } - - // Thorns - if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3")); - } - else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1")); - } - - // Respiration - if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3")); - } - else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2")); - } - else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1")); - } - - // Aqua Affinity - if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1")); - } - - // Feather Fall - if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4")); - } - else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1")); - } - - // Power - if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4")); - } - else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3")); - } - else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2")); - } - else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16) - { - AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1")); - } - - // Punch - if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2")); - } - else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1")); - } - - // Flame and Infinity - if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50) - { - AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1")); - } - - // Luck of the Sea and Lure - if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3")); - } - else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2")); - } - else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65) - { - AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1")); - AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1")); - } - - Item.m_ItemType = E_ITEM_ENCHANTED_BOOK; - } - - // Unbreaking - if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=3")); - } - else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 63) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=2")); - } - else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55) - { - AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1")); - } - - int RandomEnchantment1 = (int)floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment1 = enchantments[RandomEnchantment1]; - Item.m_Enchantments.AddFromString(Enchantment1.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); - - float NewEnchantmentLevel = (float)BaseEnchantmentLevel; - - // Next Enchantment (Second) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= SecondEnchantmentChance) - { - // Checking for conflicting enchantments - CheckEnchantmentConflicts(enchantments, Enchantment1); - - if (enchantments.size() > 0) - { - int RandomEnchantment2 = (int)floor(Random.NextFloat(1) * enchantments.size()); - - cEnchantments Enchantment2 = enchantments[RandomEnchantment2]; - Item.m_Enchantments.AddFromString(Enchantment2.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); - - // Checking for conflicting enchantments - CheckEnchantmentConflicts(enchantments, Enchantment2); - } - } - - // Next Enchantment (Third) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= ThirdEnchantmentChance) - { - if (enchantments.size() > 0) - { - int RandomEnchantment3 = (int)floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment3 = enchantments[RandomEnchantment3]; - Item.m_Enchantments.AddFromString(Enchantment3.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); - - // Checking for conflicting enchantments - CheckEnchantmentConflicts(enchantments, Enchantment3); - } - } - - // Next Enchantment (Fourth) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= FourthEnchantmentChance) - { - if (enchantments.size() > 0) - { - int RandomEnchantment4 = (int)floor(Random.NextFloat(1) * enchantments.size()); - cEnchantments Enchantment4 = enchantments[RandomEnchantment4]; - Item.m_Enchantments.AddFromString(Enchantment4.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); - } - } - - if (m_Player->DeltaExperience(-m_Player->XpForLevel(Window->GetPropertyValue(Enchantment))) >= 0 || m_Player->IsGameModeCreative()) + if (Item.EnchantByXPLevels(BaseEnchantmentLevel, *m_Player, true, true)) { Window->m_SlotArea->SetSlot(0, *m_Player, Item); Window->SendSlot(*m_Player, Window->m_SlotArea, 0); @@ -3517,91 +2750,3 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) - -void cClientHandle::AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment) -{ - for (int i = 0; i < a_Weight; i++) - { - a_Enchantments.push_back(a_Enchantment); - } -} - - - - - -void cClientHandle::RemoveEnchantmentFromVector(cEnchantmentsVector * a_Enchantments, int a_EnchantmentID) -{ - for (cEnchantmentsVector::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it) - { - int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str()); - - if (EnchantmentID == a_EnchantmentID) - { - a_Enchantments->erase(std::remove(a_Enchantments->begin(), a_Enchantments->end(), *it), a_Enchantments->end()); - break; - } - } -} - - - - - -void cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment) -{ - int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); - - if (FirstEnchantmentID == cEnchantments::enchProtection) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); - } - else if (FirstEnchantmentID == cEnchantments::enchFireProtection) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); - } - else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); - } - else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); - } - - else if (FirstEnchantmentID == cEnchantments::enchSharpness) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSmite); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); - } - else if (FirstEnchantmentID == cEnchantments::enchSmite) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); - } - else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSmite); - } - else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFortune); - } - else if (FirstEnchantmentID == cEnchantments::enchFortune) - { - RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSilkTouch); - } -} - - - - diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 1829e3b4d..3d01d8034 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -248,9 +248,6 @@ public: /** Called when the player will enchant a Item */ void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); - void AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment); - void RemoveEnchantmentFromVector(cEnchantmentsVector * a_Enchantments, int a_EnchantmentID); - void CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment); private: diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 9d4e23e0a..3caebdff5 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "Enchantments.h" #include "WorldStorage/FastNBT.h" +#include "FastRandom.h" @@ -218,6 +219,774 @@ bool cEnchantments::operator !=(const cEnchantments & a_Other) const +void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short & a_ItemType, int a_EnchantmentLevel) +{ + if (ItemCategory::IsSword(a_ItemType)) + { + // Sharpness + if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=4")); + } + else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=3")); + } + else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=1")); + } + + // Smite + if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=3")); + } + else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=1")); + } + + // Bane of Arthropods + if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=3")); + } + else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=1")); + } + + // Knockback + if (a_EnchantmentLevel >= 25 && a_EnchantmentLevel <= 75) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=1")); + } + + // Fire Aspect + if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=1")); + } + + // Looting + if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=3")); + } + else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=2")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=1")); + } + } + + else if (ItemCategory::IsTool(a_ItemType)) + { + // Efficiency + if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 81) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=3")); + } + else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 61) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 51) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=1")); + } + + // Silk Touch + if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("SilkTouch=1")); + } + + // Fortune + if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=3")); + } + else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=2")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=1")); + } + } + + else if (ItemCategory::IsArmor(a_ItemType)) + { + // Protection + if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=4")); + } + else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=3")); + } + else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=1")); + } + + // Fire Protection + if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 46) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=4")); + } + else if (a_EnchantmentLevel >= 26 && a_EnchantmentLevel <= 38) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=3")); + } + else if (a_EnchantmentLevel >= 18 && a_EnchantmentLevel <= 30) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 22) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=1")); + } + + // Blast Protection + if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=3")); + } + else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 25) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 17) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=1")); + } + + // Projectile Protection + if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=4")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 30) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=3")); + } + else if (a_EnchantmentLevel >= 9 && a_EnchantmentLevel <= 24) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=2")); + } + else if (a_EnchantmentLevel >= 3 && a_EnchantmentLevel <= 18) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=1")); + } + + // Thorns + if (a_EnchantmentLevel >= 50 && a_EnchantmentLevel <= 100) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=3")); + } + else if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=1")); + } + + + if (ItemCategory::IsHelmet(a_ItemType)) + { + // Respiration + if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 60) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=3")); + } + else if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 40) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=1")); + } + + // Aqua Affinity + if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("AquaAffinity=1")); + } + } + + else if (ItemCategory::IsBoots(a_ItemType)) + { + // Feather Fall + if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=4")); + } + else if (a_EnchantmentLevel >= 17 && a_EnchantmentLevel <= 27) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=3")); + } + else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 21) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 15) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=1")); + } + } + } + + else if (a_ItemType == E_ITEM_BOW) + { + // Power + if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 46) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=3")); + } + else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 26) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 16) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=1")); + } + + // Punch + if (a_EnchantmentLevel >= 32 && a_EnchantmentLevel <= 57) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=2")); + } + else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 37) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=1")); + } + + // Flame and Infinity + if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Flame=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Infinity=1")); + } + } + + else if (a_ItemType == E_ITEM_FISHING_ROD) + { + // Luck of the Sea and Lure + if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=3")); + } + else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=2")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=1")); + } + } + + else if (a_ItemType == E_ITEM_BOOK) + { + // All &a_Enchantments + + // Sharpness + if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=4")); + } + else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=3")); + } + else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=1")); + } + + // Smite + if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=3")); + } + else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=1")); + } + + // Bane of Arthropods + if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=3")); + } + else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=1")); + } + + // Knockback + if (a_EnchantmentLevel >= 25 && a_EnchantmentLevel <= 75) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=1")); + } + + // Fire Aspect + if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=1")); + } + + // Looting + if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=3")); + } + else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=2")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=1")); + } + + // Efficiency + if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 81) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=3")); + } + else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 61) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 51) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=1")); + } + + // Silk Touch + if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("SilkTouch=1")); + } + + // Fortune + if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=3")); + } + else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=2")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=1")); + } + + // Protection + if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=4")); + } + else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=3")); + } + else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=1")); + } + + // Fire Protection + if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 46) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=4")); + } + else if (a_EnchantmentLevel >= 26 && a_EnchantmentLevel <= 38) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=3")); + } + else if (a_EnchantmentLevel >= 18 && a_EnchantmentLevel <= 30) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 22) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=1")); + } + + // Blast Protection + if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=3")); + } + else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 25) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 17) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=1")); + } + + // Projectile Protection + if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=4")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 30) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=3")); + } + else if (a_EnchantmentLevel >= 9 && a_EnchantmentLevel <= 24) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=2")); + } + else if (a_EnchantmentLevel >= 3 && a_EnchantmentLevel <= 18) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=1")); + } + + // Thorns + if (a_EnchantmentLevel >= 50 && a_EnchantmentLevel <= 100) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=3")); + } + else if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=1")); + } + + // Respiration + if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 60) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=3")); + } + else if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=2")); + } + else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 40) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=1")); + } + + // Aqua Affinity + if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 41) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("AquaAffinity=1")); + } + + // Feather Fall + if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 33) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=4")); + } + else if (a_EnchantmentLevel >= 17 && a_EnchantmentLevel <= 27) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=3")); + } + else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 21) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 15) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=1")); + } + + // Power + if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 46) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=4")); + } + else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=3")); + } + else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 26) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=2")); + } + else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 16) + { + AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=1")); + } + + // Punch + if (a_EnchantmentLevel >= 32 && a_EnchantmentLevel <= 57) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=2")); + } + else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 37) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=1")); + } + + // Flame and Infinity + if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + { + AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Flame=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Infinity=1")); + } + + // Luck of the Sea and Lure + if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=3")); + } + else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=2")); + } + else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + { + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=1")); + } + + a_ItemType = E_ITEM_ENCHANTED_BOOK; + } + + // Unbreaking + if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=3")); + } + else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 63) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=2")); + } + else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55) + { + AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=1")); + } +} + + + + + +void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment) +{ + cWeightedEnchantment enchantment; + enchantment.m_Weight = a_Weight; + enchantment.m_Enchantments = a_Enchantment; + a_Enchantments->push_back(enchantment); +} + + + + + +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID) +{ + for (cWeightedEnchantments::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it) + { + int EnchantmentID = atoi(StringSplit((*it).m_Enchantments.ToString(), "=")[0].c_str()); + + if (EnchantmentID == a_EnchantmentID) + { + a_Enchantments->erase(std::remove(a_Enchantments->begin(), a_Enchantments->end(), *it), a_Enchantments->end()); + break; + } + } +} + + + + + +void cEnchantments::CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment) +{ + int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); + + if (FirstEnchantmentID == cEnchantments::enchProtection) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (FirstEnchantmentID == cEnchantments::enchFireProtection) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); + } + + else if (FirstEnchantmentID == cEnchantments::enchSharpness) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (FirstEnchantmentID == cEnchantments::enchSmite) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSmite); + } + else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFortune); + } + else if (FirstEnchantmentID == cEnchantments::enchFortune) + { + RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSilkTouch); + } +} + + + + + +cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments) +{ + cFastRandom Random; + + int AllWeights = 0; + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + AllWeights += (*it).m_Weight; + } + int RandomNumber = Random.GenerateRandomInteger(0, AllWeights - 1); + cEnchantments enchantment; + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + RandomNumber -= (*it).m_Weight; + if (RandomNumber < 0) + { + return (*it).m_Enchantments; + } + } +} + + + + + + diff --git a/src/Enchantments.h b/src/Enchantments.h index 70d6b6613..1d226330a 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -8,7 +8,9 @@ #pragma once +#include "Defines.h" #include "WorldStorage/EnchantmentSerializer.h" +#include "Entities/Player.h" @@ -29,7 +31,6 @@ Level value of 0 means no such enchantment, and it will not be stored in the m_E Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs. */ -typedef std::vector cEnchantmentsVector; // tolua_begin class cEnchantments @@ -94,9 +95,24 @@ public: /// Returns true if a_Other contains exactly the same enchantments and levels bool operator ==(const cEnchantments & a_Other) const; - + // tolua_end + + /** Add enchantment weights from item to the vector */ + static void AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short & a_ItemType, int a_EnchantmentLevel); + + /** Add a enchantment weight to the vector */ + static void AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment); + /** Remove a enchantment weight from the vector */ + static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID); + + /** Check enchantment conflicts from enchantments from the vector */ + static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment); + + /** Gets random enchantment from Vector and returns it */ + static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments); + /// Returns true if a_Other doesn't contain exactly the same enchantments and levels bool operator !=(const cEnchantments & a_Other) const; @@ -115,5 +131,15 @@ protected: } ; // tolua_export +/** Things below for the Enchanting System */ +struct cWeightedEnchantment +{ + int m_Weight; + cEnchantments m_Enchantments; +}; + +typedef std::vector cWeightedEnchantments; + + diff --git a/src/Item.cpp b/src/Item.cpp index 856b68be6..8bc25d242 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -5,6 +5,8 @@ #include "json/json.h" #include "Items/ItemHandler.h" +#include "FastRandom.h" + @@ -209,6 +211,145 @@ bool cItem::IsEnchantable(short item) +int cItem::GetEnchantability() +{ + int Enchantability = 0; + + if (m_ItemType == E_ITEM_WOODEN_SWORD || m_ItemType == E_ITEM_WOODEN_PICKAXE || m_ItemType == E_ITEM_WOODEN_SHOVEL || m_ItemType == E_ITEM_WOODEN_AXE || m_ItemType == E_ITEM_WOODEN_HOE) + { + Enchantability = 15; + } + else if (m_ItemType == E_ITEM_LEATHER_CAP || m_ItemType == E_ITEM_LEATHER_TUNIC || m_ItemType == E_ITEM_LEATHER_PANTS || m_ItemType == E_ITEM_LEATHER_BOOTS) + { + Enchantability = 15; + } + else if (m_ItemType == E_ITEM_STONE_SWORD || m_ItemType == E_ITEM_STONE_PICKAXE || m_ItemType == E_ITEM_STONE_SHOVEL || m_ItemType == E_ITEM_STONE_AXE || m_ItemType == E_ITEM_STONE_HOE) + { + Enchantability = 5; + } + else if (m_ItemType == E_ITEM_IRON_HELMET || m_ItemType == E_ITEM_IRON_CHESTPLATE || m_ItemType == E_ITEM_IRON_LEGGINGS || m_ItemType == E_ITEM_IRON_BOOTS) + { + Enchantability = 9; + } + else if (m_ItemType == E_ITEM_IRON_SWORD || m_ItemType == E_ITEM_IRON_PICKAXE || m_ItemType == E_ITEM_IRON_SHOVEL || m_ItemType == E_ITEM_IRON_AXE || m_ItemType == E_ITEM_IRON_HOE) + { + Enchantability = 14; + } + else if (m_ItemType == E_ITEM_CHAIN_HELMET || m_ItemType == E_ITEM_CHAIN_CHESTPLATE || m_ItemType == E_ITEM_CHAIN_LEGGINGS || m_ItemType == E_ITEM_CHAIN_BOOTS) + { + Enchantability = 12; + } + else if (m_ItemType == E_ITEM_DIAMOND_HELMET || m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || m_ItemType == E_ITEM_DIAMOND_LEGGINGS || m_ItemType == E_ITEM_DIAMOND_BOOTS) + { + Enchantability = 10; + } + else if (m_ItemType == E_ITEM_DIAMOND_SWORD || m_ItemType == E_ITEM_DIAMOND_PICKAXE || m_ItemType == E_ITEM_DIAMOND_SHOVEL || m_ItemType == E_ITEM_DIAMOND_AXE || m_ItemType == E_ITEM_DIAMOND_HOE) + { + Enchantability = 10; + } + else if (m_ItemType == E_ITEM_GOLD_HELMET || m_ItemType == E_ITEM_GOLD_CHESTPLATE || m_ItemType == E_ITEM_GOLD_LEGGINGS || m_ItemType == E_ITEM_GOLD_BOOTS) + { + Enchantability = 25; + } + else if (m_ItemType == E_ITEM_GOLD_SWORD || m_ItemType == E_ITEM_GOLD_PICKAXE || m_ItemType == E_ITEM_GOLD_SHOVEL || m_ItemType == E_ITEM_GOLD_AXE || m_ItemType == E_ITEM_GOLD_HOE) + { + Enchantability = 22; + } + else if (m_ItemType == E_ITEM_FISHING_ROD || m_ItemType == E_ITEM_BOW || m_ItemType == E_ITEM_BOOK) + { + Enchantability = 1; + } + + return Enchantability; +} + + + + + +bool cItem::EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_BlockConflictingEnchantments, bool a_DeleteLevelFromPlayer) +{ + if (!cItem::IsEnchantable(m_ItemType) && m_ItemType != E_ITEM_BOOK) + { + return false; + } + + int Enchantability = GetEnchantability(); + + cFastRandom Random; + int ModifiedEnchantmentLevel = a_NumXPLevels + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1; + float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; + int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); + + cWeightedEnchantments enchantments; + cEnchantments::AddItemEnchantmentWeights(enchantments, m_ItemType, FinalEnchantmentLevel); + + cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment1.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1); + + float NewEnchantmentLevel = (float)a_NumXPLevels; + + // Next Enchantment (Second) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= SecondEnchantmentChance) + { + if (enchantments.size() > 0) + { + cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment2.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); + } + } + + // Next Enchantment (Third) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= ThirdEnchantmentChance) + { + if (enchantments.size() > 0) + { + cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment3.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); + } + } + + // Next Enchantment (Fourth) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= FourthEnchantmentChance) + { + if (enchantments.size() > 0) + { + cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment4.ToString()); + enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); + } + } + + if (a_Player.DeltaExperience(-a_Player.XpForLevel(a_NumXPLevels)) >= 0 || a_Player.IsGameModeCreative()) + { + return true; + } + + return false; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cItems: diff --git a/src/Item.h b/src/Item.h index 910ecb382..987dea2a9 100644 --- a/src/Item.h +++ b/src/Item.h @@ -175,6 +175,13 @@ public: /** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */ static bool IsEnchantable(short a_ItemType); // tolua_export + /** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */ + int GetEnchantability(); // tolua_export + + /** Enchants the item using the specified number of XP levels. + Returns true if item enchanted, false if not. */ + bool EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_BlockConflictingEnchantments, bool a_DeleteLevelFromPlayer); // tolua_export + // tolua_begin short m_ItemType; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 6cf611d90..9b8db0b7b 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1646,8 +1646,6 @@ int cProtocol125::ParseEnchantItem(void) HANDLE_PACKET_READ(ReadByte, Byte, WindowID); HANDLE_PACKET_READ(ReadByte, Byte, Enchantment); - LOGWARN("Older Protocol: Enchantment Packet received!"); - m_Client->HandleEnchantItem(WindowID, Enchantment); return PARSE_OK; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 621854518..26fdfe928 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -802,7 +802,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) } else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) { - int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); + int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15); cFastRandom Random; int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); @@ -835,24 +835,58 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) cBlockArea Area; Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int y = 0; y <= 2; y++) + static const struct { - for (int x = 0; x <= 4; x++) + int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases + int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won\'t be counted + } CheckCoords[] = + { + { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1} + { 0, 0, 1, 1, 0, 1 }, // Bookcase at {0, 0, 1}, air at {1, 0, 1} + { 0, 0, 2, 1, 0, 2 }, // Bookcase at {0, 0, 2}, air at {1, 0, 2} + { 0, 0, 3, 1, 0, 3 }, // Bookcase at {0, 0, 3}, air at {1, 0, 3} + { 0, 0, 4, 1, 0, 3 }, // Bookcase at {0, 0, 4}, air at {1, 0, 3} + { 1, 0, 4, 1, 0, 3 }, // Bookcase at {1, 0, 4}, air at {1, 0, 3} + { 2, 0, 4, 2, 0, 3 }, // Bookcase at {2, 0, 4}, air at {2, 0, 3} + { 3, 0, 4, 3, 0, 3 }, // Bookcase at {3, 0, 4}, air at {3, 0, 3} + { 4, 0, 4, 3, 0, 3 }, // Bookcase at {4, 0, 4}, air at {3, 0, 3} + { 4, 0, 3, 3, 0, 3 }, // Bookcase at {4, 0, 3}, air at {3, 0, 3} + { 4, 0, 2, 3, 0, 2 }, // Bookcase at {4, 0, 2}, air at {3, 0, 2} + { 4, 0, 1, 3, 0, 1 }, // Bookcase at {4, 0, 1}, air at {3, 0, 1} + { 4, 0, 0, 3, 0, 1 }, // Bookcase at {4, 0, 0}, air at {3, 0, 1} + { 3, 0, 0, 3, 0, 1 }, // Bookcase at {3, 0, 0}, air at {3, 0, 1} + { 2, 0, 0, 2, 0, 1 }, // Bookcase at {2, 0, 0}, air at {2, 0, 1} + { 1, 0, 0, 1, 0, 1 }, // Bookcase at {1, 0, 0}, air at {1, 0, 1} + + { 0, 1, 0, 1, 1, 1 }, // Bookcase at {0, 1, 0}, air at {1, 1, 1} + { 0, 1, 1, 1, 1, 1 }, // Bookcase at {0, 1, 1}, air at {1, 1, 1} + { 0, 1, 2, 1, 1, 2 }, // Bookcase at {0, 1, 2}, air at {1, 1, 2} + { 0, 1, 3, 1, 1, 3 }, // Bookcase at {0, 1, 3}, air at {1, 1, 3} + { 0, 1, 4, 1, 1, 3 }, // Bookcase at {0, 1, 4}, air at {1, 1, 3} + { 1, 1, 4, 1, 1, 3 }, // Bookcase at {1, 1, 4}, air at {1, 1, 3} + { 2, 1, 4, 2, 1, 3 }, // Bookcase at {2, 1, 4}, air at {2, 1, 3} + { 3, 1, 4, 3, 1, 3 }, // Bookcase at {3, 1, 4}, air at {3, 1, 3} + { 4, 1, 4, 3, 1, 3 }, // Bookcase at {4, 1, 4}, air at {3, 1, 3} + { 4, 1, 3, 3, 1, 3 }, // Bookcase at {4, 1, 3}, air at {3, 1, 3} + { 4, 1, 2, 3, 1, 2 }, // Bookcase at {4, 1, 2}, air at {3, 1, 2} + { 4, 1, 1, 3, 1, 1 }, // Bookcase at {4, 1, 1}, air at {3, 1, 1} + { 4, 1, 0, 3, 1, 1 }, // Bookcase at {4, 1, 0}, air at {3, 1, 1} + { 3, 1, 0, 3, 1, 1 }, // Bookcase at {3, 1, 0}, air at {3, 1, 1} + { 2, 1, 0, 2, 1, 1 }, // Bookcase at {2, 1, 0}, air at {2, 1, 1} + { 1, 1, 0, 1, 1, 1 }, // Bookcase at {1, 1, 0}, air at {1, 1, 1} + }; + + for (size_t i = 0; i < ARRAYCOUNT(CheckCoords); i++) + { + if ( + (Area.GetRelBlockType(CheckCoords[i].m_AirX, CheckCoords[i].m_AirY, CheckCoords[i].m_AirZ) == E_BLOCK_AIR) && // There's air in the checkspot + (Area.GetRelBlockType(CheckCoords[i].m_BookX, CheckCoords[i].m_BookY, CheckCoords[i].m_BookZ) == E_BLOCK_BOOKCASE) // There's bookcase in the wanted place + ) { - for (int z = 0; z <= 4; z++) - { - if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) - { - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) - { - Bookshelves++; - } - } - } + Bookshelves++; } - } - - Bookshelves = std::min(Bookshelves, 15); + } // for i - CheckCoords + return Bookshelves; } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index c7b9b6aaf..fffe0e3fd 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -824,18 +824,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : void cEnchantingWindow::SetProperty(int a_Property, int a_Value) { - if (a_Property == 0) - { - m_PropertyValue0 = a_Value; - } - else if (a_Property == 1) - { - m_PropertyValue1 = a_Value; - } - else if (a_Property == 2) - { - m_PropertyValue2 = a_Value; - } + m_PropertyValue[a_Property] = a_Value; cCSLock Lock(m_CS); for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) @@ -850,18 +839,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value) void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) { - if (a_Property == 0) - { - m_PropertyValue0 = a_Value; - } - else if (a_Property == 1) - { - m_PropertyValue1 = a_Value; - } - else if (a_Property == 2) - { - m_PropertyValue2 = a_Value; - } + m_PropertyValue[a_Property] = a_Value; a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); } @@ -872,20 +850,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla int cEnchantingWindow::GetPropertyValue(int a_Property) { - if (a_Property == 0) - { - return m_PropertyValue0; - } - else if (a_Property == 1) - { - return m_PropertyValue1; - } - else if (a_Property == 2) - { - return m_PropertyValue2; - } - - return -1; + return m_PropertyValue[a_Property]; } diff --git a/src/UI/Window.h b/src/UI/Window.h index 5e799248c..1ca67bfd8 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -249,7 +249,7 @@ public: cSlotArea * m_SlotArea; protected: - int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2; + int m_PropertyValue[3]; int m_BlockX, m_BlockY, m_BlockZ; }; -- cgit v1.2.3 From 0086fcfef18db58f3a4509853399c0a9b610e950 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 17 Apr 2014 19:31:43 +0200 Subject: Fixed some Errors (not all) --- src/ClientHandle.cpp | 17 ++++++++++------- src/Enchantments.h | 13 ++++++++----- src/Item.cpp | 9 ++------- src/Item.h | 2 +- 4 files changed, 21 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a3d0501c3..eab306a0c 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2735,15 +2735,18 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); - if (Item.EnchantByXPLevels(BaseEnchantmentLevel, *m_Player, true, true)) + if (Item.EnchantByXPLevels(BaseEnchantmentLevel)) { - Window->m_SlotArea->SetSlot(0, *m_Player, Item); - Window->SendSlot(*m_Player, Window->m_SlotArea, 0); - Window->BroadcastWholeWindow(); + if (m_Player->IsGameModeCreative() | m_Player->DeltaExperience(-m_Player->XpForLevel(BaseEnchantmentLevel)) >= 0) + { + Window->m_SlotArea->SetSlot(0, *m_Player, Item); + Window->SendSlot(*m_Player, Window->m_SlotArea, 0); + Window->BroadcastWholeWindow(); - Window->SetProperty(0, 0, *m_Player); - Window->SetProperty(1, 0, *m_Player); - Window->SetProperty(2, 0, *m_Player); + Window->SetProperty(0, 0, *m_Player); + Window->SetProperty(1, 0, *m_Player); + Window->SetProperty(2, 0, *m_Player); + } } } diff --git a/src/Enchantments.h b/src/Enchantments.h index 1d226330a..fa07dc2d4 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -20,6 +20,11 @@ class cFastNBTWriter; class cParsedNBT; +// fwd: +struct cWeightedEnchantment; + +typedef std::vector cWeightedEnchantments; + @@ -111,7 +116,6 @@ public: /** Gets random enchantment from Vector and returns it */ static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments); - /// Returns true if a_Other doesn't contain exactly the same enchantments and levels bool operator !=(const cEnchantments & a_Other) const; @@ -131,15 +135,14 @@ protected: } ; // tolua_export -/** Things below for the Enchanting System */ + + +// Define the cWeightedEnchantment struct: struct cWeightedEnchantment { int m_Weight; cEnchantments m_Enchantments; }; -typedef std::vector cWeightedEnchantments; - - diff --git a/src/Item.cpp b/src/Item.cpp index 8bc25d242..540725492 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -267,7 +267,7 @@ int cItem::GetEnchantability() -bool cItem::EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_BlockConflictingEnchantments, bool a_DeleteLevelFromPlayer) +bool cItem::EnchantByXPLevels(int a_NumXPLevels) { if (!cItem::IsEnchantable(m_ItemType) && m_ItemType != E_ITEM_BOOK) { @@ -338,12 +338,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_Bloc } } - if (a_Player.DeltaExperience(-a_Player.XpForLevel(a_NumXPLevels)) >= 0 || a_Player.IsGameModeCreative()) - { - return true; - } - - return false; + return true; } diff --git a/src/Item.h b/src/Item.h index 987dea2a9..00316c188 100644 --- a/src/Item.h +++ b/src/Item.h @@ -180,7 +180,7 @@ public: /** Enchants the item using the specified number of XP levels. Returns true if item enchanted, false if not. */ - bool EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_BlockConflictingEnchantments, bool a_DeleteLevelFromPlayer); // tolua_export + bool EnchantByXPLevels(int a_NumXPLevels); // tolua_export // tolua_begin -- cgit v1.2.3 From 3efd232829aaa15193550a300d3385f59316b4a8 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 18 Apr 2014 14:10:31 +0200 Subject: Removed old include --- src/ClientHandle.cpp | 2 +- src/Enchantments.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index eab306a0c..bc1926976 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2737,7 +2737,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) if (Item.EnchantByXPLevels(BaseEnchantmentLevel)) { - if (m_Player->IsGameModeCreative() | m_Player->DeltaExperience(-m_Player->XpForLevel(BaseEnchantmentLevel)) >= 0) + if (m_Player->IsGameModeCreative() || m_Player->DeltaExperience(-m_Player->XpForLevel(BaseEnchantmentLevel)) >= 0) { Window->m_SlotArea->SetSlot(0, *m_Player, Item); Window->SendSlot(*m_Player, Window->m_SlotArea, 0); diff --git a/src/Enchantments.h b/src/Enchantments.h index fa07dc2d4..1b3561faf 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -10,7 +10,6 @@ #include "Defines.h" #include "WorldStorage/EnchantmentSerializer.h" -#include "Entities/Player.h" -- cgit v1.2.3 From 56613d2b22c82f301eb651d1f24a0c2155917d24 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 18 Apr 2014 14:34:29 +0200 Subject: Fixed Errors --- src/Enchantments.cpp | 20 +++++++++++++++++++- src/Enchantments.h | 1 + src/Item.cpp | 7 +++---- 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 3caebdff5..ca72065ff 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -893,7 +893,23 @@ void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_ if (EnchantmentID == a_EnchantmentID) { - a_Enchantments->erase(std::remove(a_Enchantments->begin(), a_Enchantments->end(), *it), a_Enchantments->end()); + a_Enchantments->erase(it); + break; + } + } +} + + + + + +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, cEnchantments a_Enchantment) +{ + for (cWeightedEnchantments::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it) + { + if ((*it).m_Enchantments == a_Enchantment) + { + a_Enchantments->erase(it); break; } } @@ -980,6 +996,8 @@ cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantment return (*it).m_Enchantments; } } + + return cEnchantments(); } diff --git a/src/Enchantments.h b/src/Enchantments.h index 1b3561faf..3cb979042 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -109,6 +109,7 @@ public: static void AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment); /** Remove a enchantment weight from the vector */ static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID); + static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, cEnchantments a_Enchantment); /** Check enchantment conflicts from enchantments from the vector */ static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment); diff --git a/src/Item.cpp b/src/Item.cpp index 540725492..1941a6693 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -286,7 +286,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment1.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment1); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1); @@ -302,7 +302,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment2.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment2); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); @@ -318,7 +318,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment3.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment3); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); @@ -334,7 +334,6 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment4.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); } } -- cgit v1.2.3 From a6de7bf1cd80847abed22e3b962a5b8650b2911c Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 19 Apr 2014 15:10:50 +0200 Subject: Fixed Code --- src/Enchantments.cpp | 642 +++++++++++++++++++++++++-------------------------- src/Enchantments.h | 8 +- src/Item.cpp | 166 +++++++------ src/UI/SlotArea.cpp | 5 +- src/UI/Window.cpp | 8 +- 5 files changed, 418 insertions(+), 411 deletions(-) (limited to 'src') diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index ca72065ff..3a65b7284 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -219,270 +219,270 @@ bool cEnchantments::operator !=(const cEnchantments & a_Other) const -void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short & a_ItemType, int a_EnchantmentLevel) +void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short a_ItemType, int a_EnchantmentLevel) { if (ItemCategory::IsSword(a_ItemType)) { // Sharpness - if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 4); } - else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 3); } - else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 1); } // Smite - if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 3); } - else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 1); } // Bane of Arthropods - if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 3); } - else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 1); } // Knockback - if (a_EnchantmentLevel >= 25 && a_EnchantmentLevel <= 75) + if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 1); } // Fire Aspect - if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 1); } // Looting - if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 3); } - else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 2); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 1); } } else if (ItemCategory::IsTool(a_ItemType)) { // Efficiency - if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 81) + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 3); } - else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 61) + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 51) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 1); } // Silk Touch - if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("SilkTouch=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchSilkTouch, 1); } // Fortune - if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 3); } - else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 2); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 1); } } else if (ItemCategory::IsArmor(a_ItemType)) { // Protection - if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 4); } - else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 3); } - else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 1); } // Fire Protection - if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 46) + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 4); } - else if (a_EnchantmentLevel >= 26 && a_EnchantmentLevel <= 38) + else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 3); } - else if (a_EnchantmentLevel >= 18 && a_EnchantmentLevel <= 30) + else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 22) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 1); } // Blast Protection - if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 41) + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 33) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 3); } - else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 25) + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 17) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 1); } // Projectile Protection - if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 4); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 30) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 3); } - else if (a_EnchantmentLevel >= 9 && a_EnchantmentLevel <= 24) + else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 2); } - else if (a_EnchantmentLevel >= 3 && a_EnchantmentLevel <= 18) + else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 1); } // Thorns - if (a_EnchantmentLevel >= 50 && a_EnchantmentLevel <= 100) + if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 3); } - else if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 1); } if (ItemCategory::IsHelmet(a_ItemType)) { // Respiration - if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 60) + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 3); } - else if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 40) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 1); } // Aqua Affinity - if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 41) + if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("AquaAffinity=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchAquaAffinity, 1); } } else if (ItemCategory::IsBoots(a_ItemType)) { // Feather Fall - if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 33) + if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 4); } - else if (a_EnchantmentLevel >= 17 && a_EnchantmentLevel <= 27) + else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 3); } - else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 21) + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 15) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 1); } } } @@ -490,382 +490,380 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm else if (a_ItemType == E_ITEM_BOW) { // Power - if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 46) + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 3); } - else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 26) + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 16) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 1); } // Punch - if (a_EnchantmentLevel >= 32 && a_EnchantmentLevel <= 57) + if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 2); } - else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 37) + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 1); } // Flame and Infinity - if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Flame=1")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Infinity=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchInfinity, 1); } } else if (a_ItemType == E_ITEM_FISHING_ROD) { // Luck of the Sea and Lure - if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=3")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 3); } - else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=2")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 2); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=1")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 1); } } else if (a_ItemType == E_ITEM_BOOK) { - // All &a_Enchantments + // All Enchantments // Sharpness - if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 4); } - else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 3); } - else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 1); } // Smite - if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 3); } - else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 1); } // Bane of Arthropods - if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49) + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 3); } - else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33) + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 1); } // Knockback - if (a_EnchantmentLevel >= 25 && a_EnchantmentLevel <= 75) + if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 1); } // Fire Aspect - if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 1); } // Looting - if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 3); } - else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 2); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 1); } // Efficiency - if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 81) + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 3); } - else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 61) + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 51) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 1); } // Silk Touch - if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("SilkTouch=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchSilkTouch, 1); } // Fortune - if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 3); } - else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 2); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 1); } // Protection - if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54) + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 4); } - else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43) + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 3); } - else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32) + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 1); } // Fire Protection - if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 46) + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 4); } - else if (a_EnchantmentLevel >= 26 && a_EnchantmentLevel <= 38) + else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 3); } - else if (a_EnchantmentLevel >= 18 && a_EnchantmentLevel <= 30) + else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 22) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 1); } // Blast Protection - if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 41) + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 33) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 3); } - else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 25) + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 17) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 1); } // Projectile Protection - if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 4); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 30) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 3); } - else if (a_EnchantmentLevel >= 9 && a_EnchantmentLevel <= 24) + else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 2); } - else if (a_EnchantmentLevel >= 3 && a_EnchantmentLevel <= 18) + else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 1); } // Thorns - if (a_EnchantmentLevel >= 50 && a_EnchantmentLevel <= 100) + if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 3); } - else if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80) + else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 1); } // Respiration - if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 60) + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 3); } - else if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 2); } - else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 40) + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 1); } // Aqua Affinity - if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 41) + if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("AquaAffinity=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchAquaAffinity, 1); } // Feather Fall - if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 33) + if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 4); } - else if (a_EnchantmentLevel >= 17 && a_EnchantmentLevel <= 27) + else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 3); } - else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 21) + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 15) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 1); } // Power - if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 46) + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=4")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 4); } - else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36) + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 3); } - else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 26) + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 2); } - else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 16) + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 1); } // Punch - if (a_EnchantmentLevel >= 32 && a_EnchantmentLevel <= 57) + if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 2); } - else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 37) + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 1); } // Flame and Infinity - if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50) + if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Flame=1")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Infinity=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchInfinity, 1); } // Luck of the Sea and Lure - if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83) + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=3")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 3); } - else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74) + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=2")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 2); } - else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65) + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=1")); - AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 1); } - - a_ItemType = E_ITEM_ENCHANTED_BOOK; } // Unbreaking - if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71) + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=3")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchUnbreaking, 3); } - else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 63) + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 63)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=2")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchUnbreaking, 2); } - else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55) + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=1")); + AddEnchantmentWeightToVector(&a_Enchantments, 5, enchUnbreaking, 1); } } @@ -873,27 +871,27 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm -void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment) +void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel) { - cWeightedEnchantment enchantment; - enchantment.m_Weight = a_Weight; - enchantment.m_Enchantments = a_Enchantment; - a_Enchantments->push_back(enchantment); + cWeightedEnchantment weightedenchantment; + weightedenchantment.m_Weight = a_Weight; + cEnchantments enchantment; + enchantment.SetLevel(a_EnchantmentID, a_EnchantmentLevel); + weightedenchantment.m_Enchantments = enchantment; + a_Enchantments->push_back(weightedenchantment); } -void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID) +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, int a_EnchantmentID) { - for (cWeightedEnchantments::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it) + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { - int EnchantmentID = atoi(StringSplit((*it).m_Enchantments.ToString(), "=")[0].c_str()); - - if (EnchantmentID == a_EnchantmentID) + if ((*it).m_Enchantments.GetLevel(a_EnchantmentID) > 0) { - a_Enchantments->erase(it); + a_Enchantments.erase(it); break; } } @@ -903,13 +901,13 @@ void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_ -void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, cEnchantments a_Enchantment) +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, const cEnchantments & a_Enchantment) { - for (cWeightedEnchantments::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it) + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { if ((*it).m_Enchantments == a_Enchantment) { - a_Enchantments->erase(it); + a_Enchantments.erase(it); break; } } @@ -921,55 +919,53 @@ void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_ void cEnchantments::CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment) { - int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str()); - - if (FirstEnchantmentID == cEnchantments::enchProtection) + if (a_FirstEnchantment.GetLevel(cEnchantments::enchProtection) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); } - else if (FirstEnchantmentID == cEnchantments::enchFireProtection) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchFireProtection) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); } - else if (FirstEnchantmentID == cEnchantments::enchBlastProtection) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchBlastProtection) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); } - else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchProjectileProtection) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); } - else if (FirstEnchantmentID == cEnchantments::enchSharpness) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSharpness) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSmite); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); } - else if (FirstEnchantmentID == cEnchantments::enchSmite) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSmite) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); } - else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchBaneOfArthropods) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSharpness); - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSmite); } - else if (FirstEnchantmentID == cEnchantments::enchSilkTouch) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSilkTouch) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFortune); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFortune); } - else if (FirstEnchantmentID == cEnchantments::enchFortune) + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchFortune) > 0) { - RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSilkTouch); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSilkTouch); } } @@ -987,7 +983,6 @@ cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantment AllWeights += (*it).m_Weight; } int RandomNumber = Random.GenerateRandomInteger(0, AllWeights - 1); - cEnchantments enchantment; for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) { RandomNumber -= (*it).m_Weight; @@ -1003,10 +998,3 @@ cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantment - - - - - - - diff --git a/src/Enchantments.h b/src/Enchantments.h index 3cb979042..fc848ebec 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -103,13 +103,13 @@ public: // tolua_end /** Add enchantment weights from item to the vector */ - static void AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short & a_ItemType, int a_EnchantmentLevel); + static void AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short a_ItemType, int a_EnchantmentLevel); /** Add a enchantment weight to the vector */ - static void AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment); + static void AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel); /** Remove a enchantment weight from the vector */ - static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID); - static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, cEnchantments a_Enchantment); + static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, int a_EnchantmentID); + static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, const cEnchantments & a_Enchantment); /** Check enchantment conflicts from enchantments from the vector */ static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment); diff --git a/src/Item.cpp b/src/Item.cpp index 1941a6693..9899d7f32 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -215,49 +215,66 @@ int cItem::GetEnchantability() { int Enchantability = 0; - if (m_ItemType == E_ITEM_WOODEN_SWORD || m_ItemType == E_ITEM_WOODEN_PICKAXE || m_ItemType == E_ITEM_WOODEN_SHOVEL || m_ItemType == E_ITEM_WOODEN_AXE || m_ItemType == E_ITEM_WOODEN_HOE) - { - Enchantability = 15; - } - else if (m_ItemType == E_ITEM_LEATHER_CAP || m_ItemType == E_ITEM_LEATHER_TUNIC || m_ItemType == E_ITEM_LEATHER_PANTS || m_ItemType == E_ITEM_LEATHER_BOOTS) - { - Enchantability = 15; - } - else if (m_ItemType == E_ITEM_STONE_SWORD || m_ItemType == E_ITEM_STONE_PICKAXE || m_ItemType == E_ITEM_STONE_SHOVEL || m_ItemType == E_ITEM_STONE_AXE || m_ItemType == E_ITEM_STONE_HOE) - { - Enchantability = 5; - } - else if (m_ItemType == E_ITEM_IRON_HELMET || m_ItemType == E_ITEM_IRON_CHESTPLATE || m_ItemType == E_ITEM_IRON_LEGGINGS || m_ItemType == E_ITEM_IRON_BOOTS) - { - Enchantability = 9; - } - else if (m_ItemType == E_ITEM_IRON_SWORD || m_ItemType == E_ITEM_IRON_PICKAXE || m_ItemType == E_ITEM_IRON_SHOVEL || m_ItemType == E_ITEM_IRON_AXE || m_ItemType == E_ITEM_IRON_HOE) - { - Enchantability = 14; - } - else if (m_ItemType == E_ITEM_CHAIN_HELMET || m_ItemType == E_ITEM_CHAIN_CHESTPLATE || m_ItemType == E_ITEM_CHAIN_LEGGINGS || m_ItemType == E_ITEM_CHAIN_BOOTS) - { - Enchantability = 12; - } - else if (m_ItemType == E_ITEM_DIAMOND_HELMET || m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || m_ItemType == E_ITEM_DIAMOND_LEGGINGS || m_ItemType == E_ITEM_DIAMOND_BOOTS) - { - Enchantability = 10; - } - else if (m_ItemType == E_ITEM_DIAMOND_SWORD || m_ItemType == E_ITEM_DIAMOND_PICKAXE || m_ItemType == E_ITEM_DIAMOND_SHOVEL || m_ItemType == E_ITEM_DIAMOND_AXE || m_ItemType == E_ITEM_DIAMOND_HOE) - { - Enchantability = 10; - } - else if (m_ItemType == E_ITEM_GOLD_HELMET || m_ItemType == E_ITEM_GOLD_CHESTPLATE || m_ItemType == E_ITEM_GOLD_LEGGINGS || m_ItemType == E_ITEM_GOLD_BOOTS) - { - Enchantability = 25; - } - else if (m_ItemType == E_ITEM_GOLD_SWORD || m_ItemType == E_ITEM_GOLD_PICKAXE || m_ItemType == E_ITEM_GOLD_SHOVEL || m_ItemType == E_ITEM_GOLD_AXE || m_ItemType == E_ITEM_GOLD_HOE) - { - Enchantability = 22; - } - else if (m_ItemType == E_ITEM_FISHING_ROD || m_ItemType == E_ITEM_BOW || m_ItemType == E_ITEM_BOOK) + switch (m_ItemType) { - Enchantability = 1; + case E_ITEM_WOODEN_SWORD: Enchantability = 15; + case E_ITEM_WOODEN_PICKAXE: Enchantability = 15; + case E_ITEM_WOODEN_SHOVEL: Enchantability = 15; + case E_ITEM_WOODEN_AXE: Enchantability = 15; + case E_ITEM_WOODEN_HOE: Enchantability = 15; + + case E_ITEM_LEATHER_CAP: Enchantability = 15; + case E_ITEM_LEATHER_TUNIC: Enchantability = 15; + case E_ITEM_LEATHER_PANTS: Enchantability = 15; + case E_ITEM_LEATHER_BOOTS: Enchantability = 15; + + case E_ITEM_STONE_SWORD: Enchantability = 5; + case E_ITEM_STONE_PICKAXE: Enchantability = 5; + case E_ITEM_STONE_SHOVEL: Enchantability = 5; + case E_ITEM_STONE_AXE: Enchantability = 5; + case E_ITEM_STONE_HOE: Enchantability = 5; + + case E_ITEM_IRON_HELMET: Enchantability = 9; + case E_ITEM_IRON_CHESTPLATE: Enchantability = 9; + case E_ITEM_IRON_LEGGINGS: Enchantability = 9; + case E_ITEM_IRON_BOOTS: Enchantability = 9; + + case E_ITEM_IRON_SWORD: Enchantability = 14; + case E_ITEM_IRON_PICKAXE: Enchantability = 14; + case E_ITEM_IRON_SHOVEL: Enchantability = 14; + case E_ITEM_IRON_AXE: Enchantability = 14; + case E_ITEM_IRON_HOE: Enchantability = 14; + + case E_ITEM_CHAIN_HELMET: Enchantability = 12; + case E_ITEM_CHAIN_CHESTPLATE: Enchantability = 12; + case E_ITEM_CHAIN_LEGGINGS: Enchantability = 12; + case E_ITEM_CHAIN_BOOTS: Enchantability = 12; + + case E_ITEM_DIAMOND_HELMET: Enchantability = 10; + case E_ITEM_DIAMOND_CHESTPLATE: Enchantability = 10; + case E_ITEM_DIAMOND_LEGGINGS: Enchantability = 10; + case E_ITEM_DIAMOND_BOOTS: Enchantability = 10; + + case E_ITEM_DIAMOND_SWORD: Enchantability = 10; + case E_ITEM_DIAMOND_PICKAXE: Enchantability = 10; + case E_ITEM_DIAMOND_SHOVEL: Enchantability = 10; + case E_ITEM_DIAMOND_AXE: Enchantability = 10; + case E_ITEM_DIAMOND_HOE: Enchantability = 10; + + case E_ITEM_GOLD_HELMET: Enchantability = 25; + case E_ITEM_GOLD_CHESTPLATE: Enchantability = 25; + case E_ITEM_GOLD_LEGGINGS: Enchantability = 25; + case E_ITEM_GOLD_BOOTS: Enchantability = 25; + + case E_ITEM_GOLD_SWORD: Enchantability = 22; + case E_ITEM_GOLD_PICKAXE: Enchantability = 22; + case E_ITEM_GOLD_SHOVEL: Enchantability = 22; + case E_ITEM_GOLD_AXE: Enchantability = 22; + case E_ITEM_GOLD_HOE: Enchantability = 22; + + case E_ITEM_FISHING_ROD: Enchantability = 1; + case E_ITEM_BOW: Enchantability = 1; + case E_ITEM_BOOK: Enchantability = 1; } return Enchantability; @@ -269,7 +286,7 @@ int cItem::GetEnchantability() bool cItem::EnchantByXPLevels(int a_NumXPLevels) { - if (!cItem::IsEnchantable(m_ItemType) && m_ItemType != E_ITEM_BOOK) + if ((!cItem::IsEnchantable(m_ItemType)) && (m_ItemType != E_ITEM_BOOK)) { return false; } @@ -284,9 +301,14 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) cWeightedEnchantments enchantments; cEnchantments::AddItemEnchantmentWeights(enchantments, m_ItemType, FinalEnchantmentLevel); + if (m_ItemType == E_ITEM_BOOK) + { + m_ItemType = E_ITEM_ENCHANTED_BOOK; + } + cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment1.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment1); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment1); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1); @@ -302,38 +324,38 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment2.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment2); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment2); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); - } - } - // Next Enchantment (Third) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= ThirdEnchantmentChance) - { - if (enchantments.size() > 0) - { - cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); - m_Enchantments.AddFromString(Enchantment3.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment3); - - // Checking for conflicting enchantments - cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); - } - } - - // Next Enchantment (Fourth) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= FourthEnchantmentChance) - { - if (enchantments.size() > 0) - { - cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); - m_Enchantments.AddFromString(Enchantment4.ToString()); + // Next Enchantment (Third) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= ThirdEnchantmentChance) + { + if (enchantments.size() > 0) + { + cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment3.ToString()); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment3); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); + + // Next Enchantment (Fourth) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (Random.NextFloat(100) <= FourthEnchantmentChance) + { + if (enchantments.size() > 0) + { + cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment4.ToString()); + } + } + } + } } } diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 26fdfe928..5f74b4fa3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -783,7 +783,8 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) { // Toss the item in the enchanting slot TossItems(a_Player, 0, 1); - // Player not found - that is acceptable + + super::OnPlayerRemoved(a_Player); } @@ -838,7 +839,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) static const struct { int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases - int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won\'t be counted + int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won't be counted } CheckCoords[] = { { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1} diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index fffe0e3fd..0a78578fc 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -826,11 +826,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value) { m_PropertyValue[a_Property] = a_Value; - cCSLock Lock(m_CS); - for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) - { - (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); - } // for itr - m_OpenedBy[] + super::SetProperty(a_Property, a_Value); } @@ -841,7 +837,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla { m_PropertyValue[a_Property] = a_Value; - a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); + super::SetProperty(a_Property, a_Value, a_Player); } -- cgit v1.2.3 From 11ff36c683975b69ed10bca31f01cdb2269bc4b6 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 19 Apr 2014 16:10:05 +0200 Subject: Fixed Code (2) --- src/Item.cpp | 190 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 93 insertions(+), 97 deletions(-) (limited to 'src') diff --git a/src/Item.cpp b/src/Item.cpp index 9899d7f32..f92efcb39 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -217,64 +217,64 @@ int cItem::GetEnchantability() switch (m_ItemType) { - case E_ITEM_WOODEN_SWORD: Enchantability = 15; - case E_ITEM_WOODEN_PICKAXE: Enchantability = 15; - case E_ITEM_WOODEN_SHOVEL: Enchantability = 15; - case E_ITEM_WOODEN_AXE: Enchantability = 15; - case E_ITEM_WOODEN_HOE: Enchantability = 15; - - case E_ITEM_LEATHER_CAP: Enchantability = 15; - case E_ITEM_LEATHER_TUNIC: Enchantability = 15; - case E_ITEM_LEATHER_PANTS: Enchantability = 15; - case E_ITEM_LEATHER_BOOTS: Enchantability = 15; - - case E_ITEM_STONE_SWORD: Enchantability = 5; - case E_ITEM_STONE_PICKAXE: Enchantability = 5; - case E_ITEM_STONE_SHOVEL: Enchantability = 5; - case E_ITEM_STONE_AXE: Enchantability = 5; - case E_ITEM_STONE_HOE: Enchantability = 5; - - case E_ITEM_IRON_HELMET: Enchantability = 9; - case E_ITEM_IRON_CHESTPLATE: Enchantability = 9; - case E_ITEM_IRON_LEGGINGS: Enchantability = 9; - case E_ITEM_IRON_BOOTS: Enchantability = 9; - - case E_ITEM_IRON_SWORD: Enchantability = 14; - case E_ITEM_IRON_PICKAXE: Enchantability = 14; - case E_ITEM_IRON_SHOVEL: Enchantability = 14; - case E_ITEM_IRON_AXE: Enchantability = 14; - case E_ITEM_IRON_HOE: Enchantability = 14; - - case E_ITEM_CHAIN_HELMET: Enchantability = 12; - case E_ITEM_CHAIN_CHESTPLATE: Enchantability = 12; - case E_ITEM_CHAIN_LEGGINGS: Enchantability = 12; - case E_ITEM_CHAIN_BOOTS: Enchantability = 12; - - case E_ITEM_DIAMOND_HELMET: Enchantability = 10; - case E_ITEM_DIAMOND_CHESTPLATE: Enchantability = 10; - case E_ITEM_DIAMOND_LEGGINGS: Enchantability = 10; - case E_ITEM_DIAMOND_BOOTS: Enchantability = 10; - - case E_ITEM_DIAMOND_SWORD: Enchantability = 10; - case E_ITEM_DIAMOND_PICKAXE: Enchantability = 10; - case E_ITEM_DIAMOND_SHOVEL: Enchantability = 10; - case E_ITEM_DIAMOND_AXE: Enchantability = 10; - case E_ITEM_DIAMOND_HOE: Enchantability = 10; - - case E_ITEM_GOLD_HELMET: Enchantability = 25; - case E_ITEM_GOLD_CHESTPLATE: Enchantability = 25; - case E_ITEM_GOLD_LEGGINGS: Enchantability = 25; - case E_ITEM_GOLD_BOOTS: Enchantability = 25; - - case E_ITEM_GOLD_SWORD: Enchantability = 22; - case E_ITEM_GOLD_PICKAXE: Enchantability = 22; - case E_ITEM_GOLD_SHOVEL: Enchantability = 22; - case E_ITEM_GOLD_AXE: Enchantability = 22; - case E_ITEM_GOLD_HOE: Enchantability = 22; - - case E_ITEM_FISHING_ROD: Enchantability = 1; - case E_ITEM_BOW: Enchantability = 1; - case E_ITEM_BOOK: Enchantability = 1; + case E_ITEM_WOODEN_SWORD: Enchantability = 15; break; + case E_ITEM_WOODEN_PICKAXE: Enchantability = 15; break; + case E_ITEM_WOODEN_SHOVEL: Enchantability = 15; break; + case E_ITEM_WOODEN_AXE: Enchantability = 15; break; + case E_ITEM_WOODEN_HOE: Enchantability = 15; break; + + case E_ITEM_LEATHER_CAP: Enchantability = 15; break; + case E_ITEM_LEATHER_TUNIC: Enchantability = 15; break; + case E_ITEM_LEATHER_PANTS: Enchantability = 15; break; + case E_ITEM_LEATHER_BOOTS: Enchantability = 15; break; + + case E_ITEM_STONE_SWORD: Enchantability = 5; break; + case E_ITEM_STONE_PICKAXE: Enchantability = 5; break; + case E_ITEM_STONE_SHOVEL: Enchantability = 5; break; + case E_ITEM_STONE_AXE: Enchantability = 5; break; + case E_ITEM_STONE_HOE: Enchantability = 5; break; + + case E_ITEM_IRON_HELMET: Enchantability = 9; break; + case E_ITEM_IRON_CHESTPLATE: Enchantability = 9; break; + case E_ITEM_IRON_LEGGINGS: Enchantability = 9; break; + case E_ITEM_IRON_BOOTS: Enchantability = 9; break; + + case E_ITEM_IRON_SWORD: Enchantability = 14; break; + case E_ITEM_IRON_PICKAXE: Enchantability = 14; break; + case E_ITEM_IRON_SHOVEL: Enchantability = 14; break; + case E_ITEM_IRON_AXE: Enchantability = 14; break; + case E_ITEM_IRON_HOE: Enchantability = 14; break; + + case E_ITEM_CHAIN_HELMET: Enchantability = 12; break; + case E_ITEM_CHAIN_CHESTPLATE: Enchantability = 12; break; + case E_ITEM_CHAIN_LEGGINGS: Enchantability = 12; break; + case E_ITEM_CHAIN_BOOTS: Enchantability = 12; break; + + case E_ITEM_DIAMOND_HELMET: Enchantability = 10; break; + case E_ITEM_DIAMOND_CHESTPLATE: Enchantability = 10; break; + case E_ITEM_DIAMOND_LEGGINGS: Enchantability = 10; break; + case E_ITEM_DIAMOND_BOOTS: Enchantability = 10; break; + + case E_ITEM_DIAMOND_SWORD: Enchantability = 10; break; + case E_ITEM_DIAMOND_PICKAXE: Enchantability = 10; break; + case E_ITEM_DIAMOND_SHOVEL: Enchantability = 10; break; + case E_ITEM_DIAMOND_AXE: Enchantability = 10; break; + case E_ITEM_DIAMOND_HOE: Enchantability = 10; break; + + case E_ITEM_GOLD_HELMET: Enchantability = 25; break; + case E_ITEM_GOLD_CHESTPLATE: Enchantability = 25; break; + case E_ITEM_GOLD_LEGGINGS: Enchantability = 25; break; + case E_ITEM_GOLD_BOOTS: Enchantability = 25; break; + + case E_ITEM_GOLD_SWORD: Enchantability = 22; break; + case E_ITEM_GOLD_PICKAXE: Enchantability = 22; break; + case E_ITEM_GOLD_SHOVEL: Enchantability = 22; break; + case E_ITEM_GOLD_AXE: Enchantability = 22; break; + case E_ITEM_GOLD_HOE: Enchantability = 22; break; + + case E_ITEM_FISHING_ROD: Enchantability = 1; break; + case E_ITEM_BOW: Enchantability = 1; break; + case E_ITEM_BOOK: Enchantability = 1; break; } return Enchantability; @@ -286,7 +286,7 @@ int cItem::GetEnchantability() bool cItem::EnchantByXPLevels(int a_NumXPLevels) { - if ((!cItem::IsEnchantable(m_ItemType)) && (m_ItemType != E_ITEM_BOOK)) + if (!cItem::IsEnchantable(m_ItemType) && (m_ItemType != E_ITEM_BOOK)) { return false; } @@ -318,46 +318,42 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) // Next Enchantment (Second) NewEnchantmentLevel = NewEnchantmentLevel / 2; float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= SecondEnchantmentChance) + if ((Random.NextFloat(100) > SecondEnchantmentChance) || (enchantments.size() == 0)) { - if (enchantments.size() > 0) - { - cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); - m_Enchantments.AddFromString(Enchantment2.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment2); - - // Checking for conflicting enchantments - cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); - - // Next Enchantment (Third) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= ThirdEnchantmentChance) - { - if (enchantments.size() > 0) - { - cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); - m_Enchantments.AddFromString(Enchantment3.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment3); - - // Checking for conflicting enchantments - cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); - - // Next Enchantment (Fourth) - NewEnchantmentLevel = NewEnchantmentLevel / 2; - float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= FourthEnchantmentChance) - { - if (enchantments.size() > 0) - { - cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); - m_Enchantments.AddFromString(Enchantment4.ToString()); - } - } - } - } - } + return false; + } + + cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment2.ToString()); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment2); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); + + // Next Enchantment (Third) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if ((Random.NextFloat(100) > ThirdEnchantmentChance) || (enchantments.size() == 0)) + { + return false; + } + + cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment3.ToString()); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment3); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); + + // Next Enchantment (Fourth) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if ((Random.NextFloat(100) > FourthEnchantmentChance) || (enchantments.size() == 0)) + { + return false; } + cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment4.ToString()); return true; } -- cgit v1.2.3 From 098be1c7fc0d2e0309bc2a649d21090265535a3e Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 19 Apr 2014 22:37:29 +0200 Subject: Fixed Code --- src/Enchantments.cpp | 282 +++++++++++++++++++++++++-------------------------- src/Enchantments.h | 11 +- 2 files changed, 148 insertions(+), 145 deletions(-) (limited to 'src') diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 3a65b7284..dad92dc91 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -226,89 +226,89 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Sharpness if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 4); } else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 3); } else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 1); } // Smite if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 3); } else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 1); } // Bane of Arthropods if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 3); } else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 1); } // Knockback if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 1); } // Fire Aspect if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 1); } // Looting if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 3); } else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 2); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 1); } } @@ -317,39 +317,39 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Efficiency if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 3); } else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 1); } // Silk Touch if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchSilkTouch, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchSilkTouch, 1); } // Fortune if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 3); } else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 2); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 1); } } @@ -358,87 +358,87 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Protection if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 4); } else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 3); } else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 1); } // Fire Protection if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 4); } else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 3); } else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 1); } // Blast Protection if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 3); } else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 1); } // Projectile Protection if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 4); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 3); } else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 2); } else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 1); } // Thorns if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 3); } else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 1); } @@ -447,21 +447,21 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Respiration if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 3); } else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 1); } // Aqua Affinity if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchAquaAffinity, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchAquaAffinity, 1); } } @@ -470,19 +470,19 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Feather Fall if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 4); } else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 3); } else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 1); } } } @@ -492,36 +492,36 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Power if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 3); } else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 1); } // Punch if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 2); } else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 1); } // Flame and Infinity if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFlame, 1); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchInfinity, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchInfinity, 1); } } @@ -530,18 +530,18 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Luck of the Sea and Lure if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 3); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 3); } else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 2); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 2); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 1); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 1); } } @@ -552,318 +552,318 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm // Sharpness if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 4); } else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 3); } else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchSharpness, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 1); } // Smite if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 3); } else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchSmite, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 1); } // Bane of Arthropods if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 3); } else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchBaneOfArthropods, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 1); } // Knockback if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchKnockback, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 1); } // Fire Aspect if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFireAspect, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 1); } // Looting if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 3); } else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 2); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchLooting, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 1); } // Efficiency if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 3); } else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchEfficiency, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 1); } // Silk Touch if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchSilkTouch, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchSilkTouch, 1); } // Fortune if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 3); } else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 2); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFortune, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 1); } // Protection if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 4); } else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 3); } else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 1); } // Fire Protection if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 4); } else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 3); } else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFireProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 1); } // Blast Protection if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 3); } else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchBlastProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 1); } // Projectile Protection if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 4); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 3); } else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 2); } else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchProjectileProtection, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 1); } // Thorns if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 3); } else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchThorns, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 1); } // Respiration if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 3); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 3); } else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 2); } else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchRespiration, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 1); } // Aqua Affinity if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchAquaAffinity, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchAquaAffinity, 1); } // Feather Fall if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 4); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 4); } else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 3); } else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchFeatherFalling, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 1); } // Power if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 4); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 4); } else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 3); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 3); } else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 2); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 2); } else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) { - AddEnchantmentWeightToVector(&a_Enchantments, 10, enchPower, 1); + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 1); } // Punch if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 2); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 2); } else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchPunch, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 1); } // Flame and Infinity if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) { - AddEnchantmentWeightToVector(&a_Enchantments, 2, enchFlame, 1); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchInfinity, 1); + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchInfinity, 1); } // Luck of the Sea and Lure if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 3); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 3); } else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 2); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 2); } else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) { - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLuckOfTheSea, 1); - AddEnchantmentWeightToVector(&a_Enchantments, 1, enchLure, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 1); } } // Unbreaking if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchUnbreaking, 3); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 3); } else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 63)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchUnbreaking, 2); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 2); } else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) { - AddEnchantmentWeightToVector(&a_Enchantments, 5, enchUnbreaking, 1); + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 1); } } @@ -871,14 +871,14 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm -void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel) +void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel) { cWeightedEnchantment weightedenchantment; weightedenchantment.m_Weight = a_Weight; cEnchantments enchantment; enchantment.SetLevel(a_EnchantmentID, a_EnchantmentLevel); weightedenchantment.m_Enchantments = enchantment; - a_Enchantments->push_back(weightedenchantment); + a_Enchantments.push_back(weightedenchantment); } diff --git a/src/Enchantments.h b/src/Enchantments.h index fc848ebec..a376d27cf 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -105,10 +105,13 @@ public: /** Add enchantment weights from item to the vector */ static void AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short a_ItemType, int a_EnchantmentLevel); - /** Add a enchantment weight to the vector */ - static void AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel); - /** Remove a enchantment weight from the vector */ + /** Add a enchantment with weight to the vector */ + static void AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel); + + /** Remove the entire enchantment (with weight) from the vector */ static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, int a_EnchantmentID); + + /** Remove the entire enchantment (with weight) from the vector */ static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, const cEnchantments & a_Enchantment); /** Check enchantment conflicts from enchantments from the vector */ @@ -137,7 +140,7 @@ protected: -// Define the cWeightedEnchantment struct: +// Define the cWeightedEnchantment struct for the Enchanting System to store the EnchantmentWeights: struct cWeightedEnchantment { int m_Weight; -- cgit v1.2.3