From 0e58c2daf34b3368d1720c722a1ccc78fbf80076 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 17:16:54 -0500 Subject: [PATCH 01/65] + Added ItemModifyingGUI class which handles all GUI's for Item modifying Spells/Scrolls --- src/interface/ItemModifyingGUI.cpp | 1959 ++++++++++++++++++++++++++++ src/interface/ItemModifyingGUI.hpp | 68 + 2 files changed, 2027 insertions(+) create mode 100644 src/interface/ItemModifyingGUI.cpp create mode 100644 src/interface/ItemModifyingGUI.hpp diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp new file mode 100644 index 000000000..1541dd0cb --- /dev/null +++ b/src/interface/ItemModifyingGUI.cpp @@ -0,0 +1,1959 @@ +#include "ItemModifyingGUI.hpp" +#include "../player.hpp" +#include "../stat.hpp" +#include "../net.hpp" +#include "../items.hpp" + +namespace GUI +{ + +ItemModifyingGUI::ItemModifyingGUI() : + bIsActive(false), + bIsCursed(false), + bIsItemModifyingGUI_Dragging(false), + itemModifyingGUI_ScrollBeatitude(0), + itemModifyingGUI_Type(0), + itemModifyingGUI_InventoryScrollOffset(0), + itemModifyingGUI_InventorySelectedSlot(-1), + itemModifyingGUI_OffsetX(0), + itemModifyingGUI_OffsetY(0) +{ + itemModifyingGUI_IMG = loadImage("images/system/identifyGUI.png"); +} // ItemModifyingGUI() + +ItemModifyingGUI::~ItemModifyingGUI() +{ + closeItemModifyingGUI(); + itemModifyingGUI_IMG = nullptr; + itemModifyingGUI_ScrollUsed = nullptr; + for ( int i = 0; i < NUM_ITEM_MODIFYING_GUI_ITEMS; i++ ) + { + itemModifyingGUI_Inventory[i] = nullptr; + } +} // ~ItemModifyingGUI() + +/* ItemModifyingGUI.cpp + * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + * @param scrollUsed - A pointer to the Item being used to open the GUI. The Item will be deleted if processing completes successfully. Use nullptr if a Spell is used to open the GUI + * Initializes the GUI, sets 'shootmode' to false, and 'gui_mode' to 'GUI_MODE_INVENTORY'. The GUI Inventory will be built using 'buildItemModifyingGUIInventory()' + * In the case of a Spell, itemModifyingGUI_ScrollBeatitude will be 0, as Spells do not give any extra or negative effects + * If a ItemModifyingGUI is already opened, it will be closed before opening the new one + * If a Unidentified Scroll is used, it will be Identified here and message the Player accordingly + */ +void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scrollUsed) +{ + // If a GUI is already opened, close the GUI before opening the new one + if ( bIsActive == true ) + { + closeItemModifyingGUI(); + } + + // Initialize the values for the GUI + bIsActive = true; + + itemModifyingGUI_Type = GUIType; + itemModifyingGUI_ScrollUsed = scrollUsed; + + // Check to see if a Scroll is being used to open the GUI + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + itemModifyingGUI_ScrollBeatitude = itemModifyingGUI_ScrollUsed->beatitude; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + bIsCursed = true; + } + + // If the Scroll is Unidentified, Identify it and message the Player what type of Scroll it is + if ( itemModifyingGUI_ScrollUsed->identified == false ) + { + itemModifyingGUI_ScrollUsed->identified = true; + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + messagePlayer(clientnum, language[849]); // "This is a scroll of identify!" + break; + case 1: // Remove Curse + messagePlayer(clientnum, language[2501]); // "This is a scroll of remove curse!" + break; + case 2: // Repair + messagePlayer(clientnum, language[2502]); // "This is a scroll of repair!" + break; + case 3: // Enchant Weapon + messagePlayer(clientnum, language[2503]); // "This is a scroll of enchant weapon!" + break; + case 4: // Enchant Armor + messagePlayer(clientnum, language[2504]); // "This is a scroll of enchant armor!" + break; + default: printlog("ERROR: updateItemModifyingGUI() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } + } + } + + // Open the Inventory, this is for Spells, as they can open the GUI without having the Inventory open + shootmode = false; + gui_mode = GUI_MODE_INVENTORY; + + // Build the GUI's Inventory for an initial check + rebuildItemModifyingGUIInventory(); + + // If the Inventory is empty, there is nothing to process. The GUI will not open and nothing will be processed + if ( itemModifyingGUI_Inventory[0] == nullptr ) + { + messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" + closeItemModifyingGUI(); + return; + } + else + { + // The actual logic is handled by updateItemModifyingGUI() + itemModifyingGUI_InventorySelectedSlot = 0; + warpMouseToSelectedGUISlot(); + } +} // openItemModifyingGUI() + +/* ItemModifyingGUI.cpp + * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls + * Handles the GUI Inventory slot bounds and Mouse input to call processGUIEffectOnItem() + */ +void ItemModifyingGUI::updateItemModifyingGUI() +{ + // Cursed Scrolls do not use the GUI, their processing is determined at random + if ( bIsActive == true && bIsCursed != true ) + { + // If the Player's Inventory cannot be accessed, nothing will work, therefore this is a check to prevent needless processing + list_t* playerInventoryList = &stats[clientnum]->inventory; + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: updateItemModifyingGUI() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // playerInventoryList is no longer used, nullify it + playerInventoryList = nullptr; + + SDL_Rect GUIRect; // The location of the GUI window + + // Draw the GUI Background at the center off the Game Window + GUIRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + GUIRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + drawImage(itemModifyingGUI_IMG, nullptr, &GUIRect); + + // Setup the collision bounds for the GUI buttons + itemModifyingGUI_HandleButtons(); + + // Setup the collision bounds for the Mouse Wheel + itemModifyingGUI_HandleMouseWheel(); + + // Setup the collision bounds for the GUI Dragging Bar + itemModifyingGUI_HandleDraggingBar(); + + // Print the Window Label signifying this GUI + char* windowName; + windowName = language[2499]; // "Repair an Item" + + Sint32 windowLabelX = ((((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 2 + ((identifyGUI_img->w / 2) - ((TTF8_WIDTH * longestline(windowName)) / 2))); + Sint32 windowLabelY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 4; + + // Print the Window Label + ttfPrintText(ttf8, windowLabelX, windowLabelY, windowName); + + // The GUI Window's position after being offset + Sint32 GUIOffsetPosX = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + Sint32 GUIOffsetPosY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + + // Draw the Images for the GUI buttons when they are being clicked + itemModifyingGUI_HandleButtonImages(GUIOffsetPosX, GUIOffsetPosY); + + SDL_Rect inventorySlotRect; // The position of all the Inventory Slots combined + inventorySlotRect.x = GUIOffsetPosX; + inventorySlotRect.w = inventoryoptionChest_bmp->w; + inventorySlotRect.y = GUIOffsetPosY + 16; + inventorySlotRect.h = inventoryoptionChest_bmp->h; + + SDL_Rect currentInventorySlotRect; // The current Inventory Slot Image to be drawn + + bool bIsMouseHoveringOverSlot = false; // True if the User's Mouse is currently over an Inventory Slot + + // Draw every Inventory Slot and check for Mouse clicks on those Inventory Slots + for ( Uint8 iSlotIndex = 0; iSlotIndex < NUM_ITEM_MODIFYING_GUI_ITEMS; ++iSlotIndex, inventorySlotRect.y += inventorySlotRect.h ) + { + // Update the position of the currentInventorySlotRect + currentInventorySlotRect.x = inventorySlotRect.x + 12; + currentInventorySlotRect.w = 0; + currentInventorySlotRect.h = 0; + + // If the mouse is currently hovering over an Inventory Slot, and there's an Item there, check for Mouse input + if ( omousey >= inventorySlotRect.y && omousey < inventorySlotRect.y + inventorySlotRect.h && itemModifyingGUI_Inventory[iSlotIndex] ) + { + // Update the Y position of the currentInventorySlotRect before drawing + currentInventorySlotRect.y = inventorySlotRect.y; + drawImage(inventoryoptionChest_bmp, nullptr, ¤tInventorySlotRect); + + itemModifyingGUI_InventorySelectedSlot = iSlotIndex; + bIsMouseHoveringOverSlot = true; + + // If the User clicks on the current Inventory Slot, process the Item + if ( mousestatus[SDL_BUTTON_LEFT] || *inputPressed(joyimpulses[INJOY_MENU_USE]) ) + { + *inputPressed(joyimpulses[INJOY_MENU_USE]) = 0; + mousestatus[SDL_BUTTON_LEFT] = 0; + + processGUIEffectOnItem(itemModifyingGUI_Inventory[iSlotIndex]); + } + } + } + + // Only have a slot selected if hovering over a slot + if ( !bIsMouseHoveringOverSlot ) + { + itemModifyingGUI_InventorySelectedSlot = -1; + } + + // Draw the Images for each Item in the GUI Inventory + // This is done at the end to prevent the Inventory Slot highlight from being drawn on top of the Item information + itemModifyingGUI_HandleItemImages(); + } + else if ( bIsActive == true && bIsCursed == true ) + { + if ( itemModifyingGUI_ScrollUsed == nullptr ) + { + // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed + printlog("ERROR: updateItemModifyingGUI() - A Cursed Spell has opened the GUI. This should never happen."); + return; + } + + messagePlayer(clientnum, language[2505]); // "Oh no! The scroll was cursed!" + + itemModifyingGUIProcessRandomItem(); + + consumeItem(itemModifyingGUI_ScrollUsed); + closeItemModifyingGUI(); + } +} // updateItemModifyingGUI() + +/* ItemModifyingGUI.cpp + * Resets all relevant variables back to their base states + */ +void ItemModifyingGUI::closeItemModifyingGUI() +{ + bIsActive = false; + bIsCursed = false; + bIsItemModifyingGUI_Dragging = false; + itemModifyingGUI_ScrollBeatitude = 0; + itemModifyingGUI_Type = 0; + itemModifyingGUI_InventoryScrollOffset = 0; + itemModifyingGUI_InventorySelectedSlot = -1; +} // closeItemModifyingGUI() + +/* ItemModifyingGUI.cpp +* Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] +* @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] +* @returns The Item* from itemModifyingGUI_Inventory[slot] +* @returns nullptr if slot >= 4 (Out of bounds) +*/ +inline Item* ItemModifyingGUI::getItemInfoFromGUI(Uint8 slot) +{ + if ( slot >= 4 ) + { + return nullptr; // Out of bounds + } + + return itemModifyingGUI_Inventory[slot]; +} // getItemInfoFromGUI() + +// ITEM MODIFYING GUI LOGIC HANDLERS + +/* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Selects the correct function to process the Item according to 'itemModifyingGUI_Type' + */ +void ItemModifyingGUI::processGUIEffectOnItem(Item* const selectedItem) +{ + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + processIdentifyGUIEffectOnItem(selectedItem); + break; + case 1: // Remove Curse + processRemoveCurseGUIEffectOnItem(selectedItem); + break; + case 2: // Repair + processRepairGUIEffectOnItem(selectedItem); + break; + case 3: // Enchant Weapon + break; + case 4: // Enchant Armor + break; + default: printlog("ERROR: processGUIEffectOnItem() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } +} // processGUIEffectOnItem() + +/* ItemModifyingGUI.cpp + * Used for Cursed Scrolls. Selects the correct function to randomly process the Item(s) according to 'itemModifyingGUI_Type' + */ +void ItemModifyingGUI::itemModifyingGUIProcessRandomItem() +{ + Uint8 numberOfItemsToProcess = 0; + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + numberOfItemsToProcess = 2; + break; + case -1: + numberOfItemsToProcess = 1; + break; + default: printlog("ERROR: itemModifyingGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%s) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + identifyGUIProcessRandomItem(numberOfItemsToProcess); + break; + case 1: // Remove Curse + removeCurseGUIProcessRandomItem(numberOfItemsToProcess); + break; + case 2: // Repair + repairGUIProcessRandomItem(numberOfItemsToProcess); + break; + case 3: // Enchant Weapon + break; + case 4: // Enchant Armor + break; + default: printlog("ERROR: itemModifyingGUIProcessRandomItem() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } +} + +/* ItemModifyingGUI.cpp + * Selects the correct function to rebuild the GUI Inventory according to 'itemModifyingGUI_Type' + */ +void ItemModifyingGUI::rebuildItemModifyingGUIInventory() +{ + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + rebuildIdentifyGUIInventory(); + break; + case 1: // Remove Curse + rebuildRemoveCurseGUIInventory(); + break; + case 2: // Repair + rebuildRepairGUIInventory(); + break; + case 3: // Enchant Weapon + break; + case 4: // Enchant Armor + break; + default: printlog("ERROR: rebuildItemModifyingGUIInventory() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } +} // rebuildItemModifyingGUIInventory() + +/* ItemModifyingGUI.cpp + * Calls SDL_WarpMouseInWindow() to move the Mouse cursor to the currently selected GUI slot for controllers + */ +void ItemModifyingGUI::warpMouseToSelectedGUISlot() +{ + SDL_Rect slotPos; + slotPos.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + slotPos.w = inventoryoptionChest_bmp->w; + slotPos.h = inventoryoptionChest_bmp->h; + slotPos.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16 + (slotPos.h * itemModifyingGUI_InventorySelectedSlot); + + SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); +} // warpMouseToSelectedGUISlot() + +// ITEM MODIFYING GUI DISPLAY HANDLERS + +/* ItemModifyingGUI.cpp + * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for each of the GUI's buttons + * The Top Bar of the GUI used for dragging is considered a button + */ +void ItemModifyingGUI::itemModifyingGUI_HandleButtons() +{ + // GUI Button Collision Bounds TODOR: I may have these swapped, the lower bound may be the upper bound + // Scroll Up Button Y + Sint32 scrollUpButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; + Sint32 scrollUpButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; + // Scroll Up Button X + Sint32 scrollUpButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + Sint32 scrollUpButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + // Scroll Down Button Y + Sint32 scrollDownButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; + Sint32 scrollDownButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 88; + // Scroll Down Button X + Sint32 scrollDownButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + Sint32 scrollDownButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + // Close Button Y + Sint32 closeButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + Sint32 closeButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; + // Close Button X + Sint32 closeButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 393; + Sint32 closeButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 407; + // Dragging Bar Y + Sint32 draggingBarY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + Sint32 draggingBarY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; + // Dragging Bar X + Sint32 draggingBarX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + Sint32 draggingBarX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 377; + + // Buttons + if ( mousestatus[SDL_BUTTON_LEFT] ) + { + // GUI Scroll Up Button + if ( omousey >= scrollUpButtonY_LowerBound && omousey < scrollUpButtonY_UpperBound ) + { + if ( omousex >= scrollUpButtonX_LowerBound && omousex < scrollUpButtonX_UpperBound ) + { + buttonclick = 7; + if ( itemModifyingGUI_InventoryScrollOffset != 0 ) + { + itemModifyingGUI_InventoryScrollOffset--; + } + mousestatus[SDL_BUTTON_LEFT] = 0; + } + } + + // GUI Scroll Down Button + else if ( omousey >= scrollDownButtonY_LowerBound && omousey < scrollDownButtonY_UpperBound ) + { + if ( omousex >= scrollDownButtonX_LowerBound && omousex < scrollDownButtonX_UpperBound ) + { + buttonclick = 8; + itemModifyingGUI_InventoryScrollOffset++; + mousestatus[SDL_BUTTON_LEFT] = 0; + } + } + + // Top Bar of GUI + else if ( omousey >= closeButtonY_LowerBound && omousey < closeButtonY_UpperBound ) + { + // GUI Close Button + if ( omousex >= closeButtonX_LowerBound && omousex < closeButtonX_UpperBound ) + { + buttonclick = 9; + mousestatus[SDL_BUTTON_LEFT] = 0; + } + + // GUI Dragging Top Bar + if ( omousex >= draggingBarX_LowerBound && omousex < draggingBarX_UpperBound && omousey >= draggingBarY_LowerBound && omousey < draggingBarY_UpperBound ) + { + gui_clickdrag = true; + bIsItemModifyingGUI_Dragging = true; + dragoffset_x = omousex - (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + dragoffset_y = omousey - (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + mousestatus[SDL_BUTTON_LEFT] = 0; + } + } + } +} + +/* ItemModifyingGUI.cpp + * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for Mouse scroll wheel input + */ +void ItemModifyingGUI::itemModifyingGUI_HandleMouseWheel() +{ + // GUI Mouse Wheel Collision Bounds + // Mouse Wheel Y + Sint32 mouseWheelY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; + Sint32 mouseWheelY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + (identifyGUI_img->h - 8); + // Mouse Wheel X + Sint32 mouseWheelX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 12; + Sint32 mouseWheelX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (identifyGUI_img->w - 28); + + // Mouse wheel + if ( omousex >= mouseWheelX_LowerBound && omousex < mouseWheelX_UpperBound ) + { + if ( omousey >= mouseWheelY_LowerBound && omousey < mouseWheelY_UpperBound ) + { + if ( mousestatus[SDL_BUTTON_WHEELDOWN] ) + { + mousestatus[SDL_BUTTON_WHEELDOWN] = 0; + itemModifyingGUI_InventoryScrollOffset++; + } + else if ( mousestatus[SDL_BUTTON_WHEELUP] ) + { + mousestatus[SDL_BUTTON_WHEELUP] = 0; + if ( itemModifyingGUI_InventoryScrollOffset != 0 ) + { + itemModifyingGUI_InventoryScrollOffset--; + } + } + } + } +} + +/* ItemModifyingGUI.cpp + * Handles the actual movement of the GUI Window by modifying 'itemModifyingGUI_OffsetX/Y' when 'bIsItemModifyingGUI_Dragging' == true + */ +void ItemModifyingGUI::itemModifyingGUI_HandleDraggingBar() +{ + // GUI Dragging + // The GUI Window's centered position in the Game Window + Sint32 GUICenterPosY = ((yres / 2) - (inventoryChest_bmp->h / 2)); + Sint32 GUICenterPosX = ((xres / 2) - (inventoryChest_bmp->w / 2)); + // The GUI Window's position after being offset + Sint32 GUIOffsetPosY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + Sint32 GUIOffsetPosX = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + + // Dragging the Window + if ( bIsItemModifyingGUI_Dragging == true) + { + if ( gui_clickdrag == true ) // If the User is dragging, process the movement + { + itemModifyingGUI_OffsetX = (omousex - dragoffset_x) - GUICenterPosX; + itemModifyingGUI_OffsetY = (omousey - dragoffset_y) - GUICenterPosY; + if ( GUIOffsetPosX <= camera.winx ) + { + itemModifyingGUI_OffsetX = camera.winx - GUICenterPosX; + } + if ( GUIOffsetPosX > camera.winx + camera.winw - identifyGUI_img->w ) + { + itemModifyingGUI_OffsetX = (camera.winx + camera.winw - identifyGUI_img->w) - GUICenterPosX; + } + if ( GUIOffsetPosY <= camera.winy ) + { + itemModifyingGUI_OffsetY = camera.winy - GUICenterPosY; + } + if ( GUIOffsetPosY > camera.winy + camera.winh - identifyGUI_img->h ) + { + itemModifyingGUI_OffsetY = (camera.winy + camera.winh - identifyGUI_img->h) - GUICenterPosY; + } + } + else // Else, reset the flag + { + bIsItemModifyingGUI_Dragging = false; + } + } +} + +/* ItemModifyingGUI.cpp + * @param GUIPosX - The GUI position in the center of the screen + itemModifyingGUI_OffsetX + * @param GUIPosY - The GUI position in the center of the screen + itemModifyingGUI_OffsetY + * Handles drawing the actual GUI button Images when they are being clicked. The unclicked versions are part of the original Image + */ +void ItemModifyingGUI::itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY) +{ + // GUI Scroll Up Button + if ( buttonclick == 7 ) + { + SDL_Rect GUIInventoryUpButtonRect; + GUIInventoryUpButtonRect.x = GUIPosX + (identifyGUI_img->w - 28); + GUIInventoryUpButtonRect.y = GUIPosY + 16; + GUIInventoryUpButtonRect.w = 0; + GUIInventoryUpButtonRect.h = 0; + drawImage(invup_bmp, nullptr, &GUIInventoryUpButtonRect); + } + + // GUI Scroll Down Button + if ( buttonclick == 8 ) + { + SDL_Rect GUIInventoryDownButtonRect; + GUIInventoryDownButtonRect.x = GUIPosX + (identifyGUI_img->w - 28); + GUIInventoryDownButtonRect.y = GUIPosY + 52; + GUIInventoryDownButtonRect.w = 0; + GUIInventoryDownButtonRect.h = 0; + drawImage(invdown_bmp, nullptr, &GUIInventoryDownButtonRect); + } + + // GUI Close Button + if ( buttonclick == 9 ) + { + SDL_Rect GUICloseButtonRect; + GUICloseButtonRect.x = GUIPosX + 393; + GUICloseButtonRect.y = GUIPosY; + GUICloseButtonRect.w = 0; + GUICloseButtonRect.h = 0; + drawImage(invclose_bmp, nullptr, &GUICloseButtonRect); + closeItemModifyingGUI(); + } +} + +/* ItemModifyingGUI.cpp + * Rebuilds the GUI Inventory before selecting the correct function to render the Images for each Item according to 'itemModifyingGUI_Type' + */ +void ItemModifyingGUI::itemModifyingGUI_HandleItemImages() +{ + // Rebuild the GUI Inventory to prevent scrolling infinitely + rebuildItemModifyingGUIInventory(); + + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + identifyGUI_HandleItemImages(); + break; + case 1: // Remove Curse + removeCurseGUI_HandleItemImages(); + break; + case 2: // Repair + repairGUI_HandleItemImages(); + break; + case 3: // Enchant Weapon + break; + case 4: // Enchant Armor + break; + default: printlog("ERROR: itemModifyingGUI_HandleItemImages() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } +} + +// IDENTIFY GUI + +/* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ +void ItemModifyingGUI::processIdentifyGUIEffectOnItem(Item* const selectedItem) +{ + if ( selectedItem == nullptr ) + { + printlog("ERROR: processIdentifyGUIEffectOnItem() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Identify the selected Item + selectedItem->identified = true; + messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." + break; + case 1: + // Identify the selected Item and 1 random Unidentified Item in their Inventory + selectedItem->identified = true; + messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." + identifyGUIProcessRandomItem(1); + break; + case 2: + // Identify the selected Item and 2 random Unidentified Items in their Inventory + selectedItem->identified = true; + messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." + identifyGUIProcessRandomItem(2); + break; + default: printlog("ERROR: processIdentifyGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + closeItemModifyingGUI(); +} + +/* ItemModifyingGUI.cpp + * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' + * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used + */ +void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) +{ + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: identifyGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->identified == true ) // Skip over all Unidentified Items + { + totalAmountOfItems++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( item->identified != true ) // Skip over all Identified Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: identifyGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid items to be processed + if ( totalAmountOfItems == 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iIdentifyGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iIdentifyGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->identified == true ) // Skip over all Unidentified Items + { + if ( iIdentifyGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 ) + { + messagePlayer(clientnum, language[2514], itemToProcess->description()); // "Oh no! Your %s was unidentified too!" + } + else + { + messagePlayer(clientnum, language[2506], itemToProcess->description()); // "Your %s was unidentified!" + } + + itemToProcess->identified = false; + amountOfItemsLeftToProcess--; + + iPreviousItemProcessedIndex = iIdentifyGUIInventoryIndex; + } + iIdentifyGUIInventoryIndex++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( itemToProcess->identified != true ) // Skip over all Identified Items + { + if ( iIdentifyGUIInventoryIndex == iItemToProcessIndex ) + { + itemToProcess->identified = true; + amountOfItemsLeftToProcess--; + messagePlayer(clientnum, language[2511], itemToProcess->description()); // "Wow! Your %s was identified too!" + iPreviousItemProcessedIndex = iIdentifyGUIInventoryIndex; + } + iIdentifyGUIInventoryIndex++; + } + break; + default: printlog("ERROR: identifyGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + } +} + +/* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ +void ItemModifyingGUI::rebuildIdentifyGUIInventory() +{ + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iIdentifyGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: rebuildIdentifyGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of items in the GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->identified == true ) // Skip over all Unidentified Items + { + ++iIdentifyGUIInventoryIndex; + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified != true ) // Skip over all Identified Items + { + ++iIdentifyGUIInventoryIndex; + } + break; + default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iIdentifyGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iIdentifyGUIInventoryIndex = 0; iIdentifyGUIInventoryIndex < 4; ++iIdentifyGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex] = nullptr; + } + + iIdentifyGUIInventoryIndex = 0; + + // Assign the visible items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->identified == true ) // Skip over all Unidentified Items + { + ++iIdentifyGUIInventoryIndex; + + if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified != true ) // Skip over all Identified Items + { + ++iIdentifyGUIInventoryIndex; + + if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: rebuildIdentifyGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } +} + +/* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ +void ItemModifyingGUI::identifyGUI_HandleItemImages() +{ + Uint8 iIdentifyGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iIdentifyGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + if ( item->identified != true ) // Skip over all Identified Items + { + iIdentifyGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iIdentifyGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iIdentifyGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + break; + } + } + } + } +} + +// REMOVE CURSE GUI + +/* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ +void ItemModifyingGUI::processRemoveCurseGUIEffectOnItem(Item* const selectedItem) +{ + if ( selectedItem == nullptr ) + { + printlog("ERROR: processRemoveCurseGUIEffectOnItem() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Uncurse the selected Item + messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." + selectedItem->beatitude = 0; + break; + case 1: + // Uncurse the selected Item and 1 random Cursed Item in their Inventory + messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." + selectedItem->beatitude = 0; + removeCurseGUIProcessRandomItem(1); + break; + case 2: + // Uncurse the selected Item and 2 random Cursed Items in their Inventory + messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." + selectedItem->beatitude = 0; + removeCurseGUIProcessRandomItem(2); + break; + default: printlog("ERROR: processRemoveCurseGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + closeItemModifyingGUI(); + + // TODOR: Why does the Client need to be told, this doesn't need to be networked likely + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + // The Client needs to inform the Server that their equipment was Uncursed + + // Convert the Item type to an int for the packet + Uint8 itemType = 0; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->weapon ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 8; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 9; + } + + strcpy((char*)net_packet->data, "RCUR"); + net_packet->data[4] = clientnum; + net_packet->data[5] = itemType; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 6; + sendPacketSafe(net_sock, -1, net_packet, 0); + } +} + +/* ItemModifyingGUI.cpp + * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' + * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used + */ +void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) +{ + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: removeCurseGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude >= 0 ) // Skip over all Cursed Items + { + totalAmountOfItems++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( item->beatitude < 0 ) // Skip over all Uncursed Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: removeCurseGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid items to be processed + if ( totalAmountOfItems == 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iRemoveCurseGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iRemoveCurseGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->beatitude >= 0 ) // Skip over all Cursed Items + { + if ( iRemoveCurseGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 ) + { + messagePlayer(clientnum, language[2515], itemToProcess->description()); // "Oh no! Your %s was cursed too!" + } + else + { + messagePlayer(clientnum, language[2507], itemToProcess->description()); // "Your %s was cursed!" + } + + itemToProcess->beatitude = -1; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; + } + iRemoveCurseGUIInventoryIndex++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( itemToProcess->beatitude < 0 ) // Skip over all Uncursed Items + { + if ( iRemoveCurseGUIInventoryIndex == iItemToProcessIndex ) + { + messagePlayer(clientnum, language[2512], itemToProcess->description()); // "Wow! Your %s was uncursed too!" + itemToProcess->beatitude = 0; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; + } + iRemoveCurseGUIInventoryIndex++; + } + break; + default: printlog("ERROR: removeCurseGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + } +} + +/* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ +void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() +{ + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iRemoveCurseGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: rebuildRemoveCurseGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of items in the GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude >= 0 ) // Skip over all Cursed Items + { + ++iRemoveCurseGUIInventoryIndex; + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified == true && item->beatitude < 0 ) // Skip over all Unidentified and Uncursed Items + { + ++iRemoveCurseGUIInventoryIndex; + } + break; + default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iRemoveCurseGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iRemoveCurseGUIInventoryIndex = 0; iRemoveCurseGUIInventoryIndex < 4; ++iRemoveCurseGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex] = nullptr; + } + + iRemoveCurseGUIInventoryIndex = 0; + + // Assign the visible items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude >= 0 ) // Skip over all Cursed Items + { + ++iRemoveCurseGUIInventoryIndex; + + if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified == true && item->beatitude < 0 ) // Skip over all Unidentified and Uncursed Items + { + ++iRemoveCurseGUIInventoryIndex; + + if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: rebuildRemoveCurseGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } +} + +/* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ +void ItemModifyingGUI::removeCurseGUI_HandleItemImages() +{ + Uint8 iRemoveCurseGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iRemoveCurseGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + if ( item->identified == true && item->beatitude < 0 ) + { + iRemoveCurseGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRemoveCurseGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRemoveCurseGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + break; + } + } + } + } +} + +// REPAIR GUI + +/* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Repairs the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls cannot repair Broken or Serviceable Items. +0 can repair Decrepit and Worn up to Serviceable + * +1 Scrolls cannot repair Serviceable Items. +1 can repair Broken, Decrepit, and Worn up to Serviceable + * +2 Scrolls can repair all Items up to Excellent + * Messages the Player that their Item has been Repaired, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ +void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) +{ + if ( selectedItem == nullptr ) + { + printlog("ERROR: processRepairGUIEffectOnItem() - selectedItem is null."); + return; + } + + Uint8 itemNewStatus = -1; + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Intentional fall-through + case 1: + // Repair the Item if it is Broken (+1 only), Decrepit, or Worn up to Serviceable + selectedItem->status = SERVICABLE; + messagePlayer(clientnum, language[872], selectedItem->description()); // "Your %s looks better!" + break; + case 2: + // Repair the Item if it is Broken, Decrepit, Worn, or Serviceable up to Excellent + selectedItem->status = EXCELLENT; + messagePlayer(clientnum, language[2517], selectedItem->description()); // "Your %s looks perfect now!" + break; + default: printlog("ERROR: processRepairGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it. Currently there is no Spell of Repair + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + closeItemModifyingGUI(); + + // TODOR: Why does the Client need to be told, this doesn't need to be networked likely + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + // The Client needs to inform the Server that their equipment was repaired + + // Convert the Item type to an int for the packet + Uint8 itemType = 0; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->weapon ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 8; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 9; + } + + strcpy((char*)net_packet->data, "ARMR"); + net_packet->data[4] = itemType; + net_packet->data[5] = itemNewStatus; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 6; + sendPacketSafe(net_sock, -1, net_packet, 0); + } +} + +/* ItemModifyingGUI.cpp + * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random items to Broken + * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used + */ +void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) +{ + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: repairGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->status != BROKEN ) // Skip over all Broken Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: repairGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid items to be processed + if ( totalAmountOfItems == 0 ) + { + messagePlayer(clientnum, language[2513]); // "You have no remaining items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iRepairGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iRepairGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(itemToProcess) == POTION || itemCategory(itemToProcess) == SCROLL || itemCategory(itemToProcess) == SPELLBOOK || itemCategory(itemToProcess) == GEM || itemCategory(itemToProcess) == THROWN || itemCategory(itemToProcess) == FOOD || itemCategory(itemToProcess) == BOOK || itemCategory(itemToProcess) == SPELL_CAT ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->status != BROKEN ) // Skip over all Cursed Items + { + if ( iRepairGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 ) + { + messagePlayer(clientnum, language[2516], itemToProcess->description()); // "Oh no! Your %s was broken too!" + } + else + { + messagePlayer(clientnum, language[2508], itemToProcess->description()); // "Your %s is now broken!" + } + + itemToProcess->status = BROKEN; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iRepairGUIInventoryIndex; + } + iRepairGUIInventoryIndex++; + } + break; + default: printlog("ERROR: repairGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + } +} + +/* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ +void ItemModifyingGUI::rebuildRepairGUIInventory() +{ + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iRepairGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: rebuildRepairGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of items in the Repair GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->status != BROKEN ) // Skip over all Broken Items + { + ++iRepairGUIInventoryIndex; + } + break; + case 0: + if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items + { + ++iRepairGUIInventoryIndex; + } + break; + case 1: + if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable and Excellent Items + { + ++iRepairGUIInventoryIndex; + } + break; + case 2: + if ( item->status != EXCELLENT ) // Skip over all Excellent Items + { + ++iRepairGUIInventoryIndex; + } + break; + default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iRepairGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iRepairGUIInventoryIndex = 0; iRepairGUIInventoryIndex < 4; ++iRepairGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex] = nullptr; + } + + iRepairGUIInventoryIndex = 0; + + // Assign the visible items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->status != BROKEN ) // Skip over all Broken Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable, and Excellent Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( item->status != EXCELLENT ) // Skip over all Excellent Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } +} + +/* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ +void ItemModifyingGUI::repairGUI_HandleItemImages() +{ + bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) + Uint8 iRepairGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iRepairGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items + { + iRepairGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRepairGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable, and Excellent Items + { + iRepairGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRepairGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( item->status != EXCELLENT ) // Skip over all Excellent Items + { + iRepairGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRepairGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: repairGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } + } +} + +// ENCHANT WEAPON GUI + +// ENCHANT ARMOR GUI + +} // namespace GUI diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp new file mode 100644 index 000000000..9d6912b04 --- /dev/null +++ b/src/interface/ItemModifyingGUI.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include "interface.hpp" + +namespace GUI +{ +class ItemModifyingGUI +{ +public: + ItemModifyingGUI(); + ~ItemModifyingGUI(); + + void openItemModifyingGUI(const Uint8 GUIType, Item* const scrollUsed); + void updateItemModifyingGUI(); + +private: + // ItemModifying GUI + static const Uint8 NUM_ITEM_MODIFYING_GUI_ITEMS = 4; // The maximum number of Items that can be displayed in the window + + bool bIsActive; // Flag for whether or not the ItemModifyingGUI is currently displayed + bool bIsCursed; // Flag for whether or not the Scroll used is Cursed. If it is, bypasses the GUI and skips to processing + bool bIsItemModifyingGUI_Dragging; // Flag for whether or not the GUI Window is being dragged around the Screen + Sint8 itemModifyingGUI_ScrollBeatitude; // The Beatitude value of the Scroll being used + Uint8 itemModifyingGUI_Type; // Which type of GUI is being displayed? 0, 1, 2, 3, 4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + Uint8 itemModifyingGUI_InventoryScrollOffset; // The amount Items existing past the limit of visible Items #TODOR: I actually am not 100% certain what this is + Uint8 itemModifyingGUI_InventorySelectedSlot; // The GUI Inventory Slot that has been selected by the Player for processing + Sint32 itemModifyingGUI_OffsetX; // The GUI Window's X offset, to allow the Window to be moved around the screen. Offset is remembered for future use + Sint32 itemModifyingGUI_OffsetY; // The GUI Window's Y offset, to allow the Window to be moved around the screen. Offset is remembered for future use + + SDL_Surface* itemModifyingGUI_IMG = nullptr; // The background image for Identify, Remove Curse, and Repair GUIs + Item* itemModifyingGUI_Inventory[NUM_ITEM_MODIFYING_GUI_ITEMS] = {nullptr}; // The GUI Inventory which holds all of the Player's Inventory Items that match the given GUIType + Item* itemModifyingGUI_ScrollUsed = nullptr; // A pointer to the Item of the Scroll being used to open the GUI. If the Scroll finishes it's processing, the Item will be deleted + + void closeItemModifyingGUI(); + + Item* getItemInfoFromGUI(Uint8 slot); + + void processGUIEffectOnItem(Item* const selectedItem); + void itemModifyingGUIProcessRandomItem(); + void rebuildItemModifyingGUIInventory(); + void warpMouseToSelectedGUISlot(); + + // Display Update Handlers + void itemModifyingGUI_HandleButtons(); + void itemModifyingGUI_HandleMouseWheel(); + void itemModifyingGUI_HandleDraggingBar(); + void itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY); + void itemModifyingGUI_HandleItemImages(); + + // Identify GUI + void processIdentifyGUIEffectOnItem(Item* const selectedItem); + void identifyGUIProcessRandomItem(const Uint8 numItems); + void rebuildIdentifyGUIInventory(); + void identifyGUI_HandleItemImages(); + + // Remove Curse GUI + void processRemoveCurseGUIEffectOnItem(Item* const selectedItem); + void removeCurseGUIProcessRandomItem(const Uint8 numItems); + void rebuildRemoveCurseGUIInventory(); + void removeCurseGUI_HandleItemImages(); + + // Repair GUI + void processRepairGUIEffectOnItem(Item* const selectedItem); + void repairGUIProcessRandomItem(const Uint8 numItems); + void rebuildRepairGUIInventory(); + void repairGUI_HandleItemImages(); +}; +} \ No newline at end of file From f17c926f031ca1f4246274fda5b20b0a26eaacca Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 18:08:38 -0500 Subject: [PATCH 02/65] * Rearranged code so that inventory doesn't open if Spell is cast but no valid items --- src/interface/ItemModifyingGUI.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index 1541dd0cb..ef3b5e50d 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -89,10 +89,6 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr } } - // Open the Inventory, this is for Spells, as they can open the GUI without having the Inventory open - shootmode = false; - gui_mode = GUI_MODE_INVENTORY; - // Build the GUI's Inventory for an initial check rebuildItemModifyingGUIInventory(); @@ -105,6 +101,10 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr } else { + // Open the Inventory, this is for Spells, as they can open the GUI without having the Inventory open + shootmode = false; + gui_mode = GUI_MODE_INVENTORY; + // The actual logic is handled by updateItemModifyingGUI() itemModifyingGUI_InventorySelectedSlot = 0; warpMouseToSelectedGUISlot(); From 55eb0f0dcd93cd589f07a5acbd9196c4e79ad12d Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 18:09:29 -0500 Subject: [PATCH 03/65] * Replaced old implementation of item modifying spells with new --- src/magic/castSpell.cpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index 301aa48e2..d55302bc9 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -524,22 +524,7 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool else { //Identify an item. - shootmode = false; - gui_mode = GUI_MODE_INVENTORY; //Reset the GUI to the inventory. - identifygui_active = true; - identifygui_appraising = false; - if ( removecursegui_active ) - { - closeRemoveCurseGUI(); - } - if ( openedChest[i] ) - { - openedChest[i]->closeChest(); - } - //identifygui_mode = true; - - //Initialize Identify GUI game controller code here. - initIdentifyGUIControllerCode(); + itemModifyingGUI->openItemModifyingGUI(0, nullptr); } } } @@ -565,16 +550,7 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool else { //Uncurse an item - shootmode = false; - gui_mode = GUI_MODE_INVENTORY; //Reset the GUI to the inventory. - removecursegui_active = true; - identifygui_active = false; - if ( openedChest[i] ) - { - openedChest[i]->closeChest(); - } - - initRemoveCurseGUIControllerCode(); + itemModifyingGUI->openItemModifyingGUI(1, nullptr); } } } From 2b4a80d909c5e072d125b54855c84edc1430addb Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 18:21:22 -0500 Subject: [PATCH 04/65] + Added 'areThereValidItems()' to check for valid items before casting a spell --- src/interface/ItemModifyingGUI.cpp | 28 ++++++++++++++++++++++++++++ src/interface/ItemModifyingGUI.hpp | 1 + 2 files changed, 29 insertions(+) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index ef3b5e50d..8a0111650 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -246,6 +246,34 @@ void ItemModifyingGUI::closeItemModifyingGUI() itemModifyingGUI_InventorySelectedSlot = -1; } // closeItemModifyingGUI() +/* ItemModifyingGUI.cpp + * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + * @returns true - If the Player's Inventory has valid Items for processing + * @returns false - If the Player's Inventory has no valid Items for processing + * The main usage of this function is to prevent a Spell from being cast needlessly + * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via closeItemModifyingGUI() + */ +bool ItemModifyingGUI::areThereValidItems(const Uint8 GUIType) +{ + itemModifyingGUI_Type = GUIType; + + // Build the GUI's Inventory for an initial check + rebuildItemModifyingGUIInventory(); + + // If the Inventory is empty, there is nothing to process + if ( itemModifyingGUI_Inventory[0] == nullptr ) + { + messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" + closeItemModifyingGUI(); // Reset all values to prevent any crossover + return false; + } + else + { + closeItemModifyingGUI(); // Reset all values to prevent any crossover + return true; + } +} + /* ItemModifyingGUI.cpp * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] * @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 9d6912b04..786e01af4 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -32,6 +32,7 @@ class ItemModifyingGUI Item* itemModifyingGUI_ScrollUsed = nullptr; // A pointer to the Item of the Scroll being used to open the GUI. If the Scroll finishes it's processing, the Item will be deleted void closeItemModifyingGUI(); + bool areThereValidItems(const Uint8 GUIType); Item* getItemInfoFromGUI(Uint8 slot); From 18f531677ab0667fa54448a35c94210cb32a6b31 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 18:22:00 -0500 Subject: [PATCH 05/65] * Fixed 'areThereValidItems()' being private --- src/interface/ItemModifyingGUI.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 786e01af4..71e374f30 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -12,6 +12,7 @@ class ItemModifyingGUI void openItemModifyingGUI(const Uint8 GUIType, Item* const scrollUsed); void updateItemModifyingGUI(); + bool areThereValidItems(const Uint8 GUIType); private: // ItemModifying GUI @@ -32,7 +33,6 @@ class ItemModifyingGUI Item* itemModifyingGUI_ScrollUsed = nullptr; // A pointer to the Item of the Scroll being used to open the GUI. If the Scroll finishes it's processing, the Item will be deleted void closeItemModifyingGUI(); - bool areThereValidItems(const Uint8 GUIType); Item* getItemInfoFromGUI(Uint8 slot); From 50b20328790790fd0c34516ce9d930ee6451afff Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 18:24:28 -0500 Subject: [PATCH 06/65] + Added checks to prevent spellcast if there are no valid items to be processed --- src/magic/castSpell.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index d55302bc9..c5a9c35e6 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -115,6 +115,24 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) return; } + // Check to prevent Mana loss if there are no valid Items to be processed by Identify Spell + if ( spell->ID == SPELL_IDENTIFY ) + { + if ( itemModifyingGUI->areThereValidItems(0) != true ) + { + return; + } + } + + // Check to prevent Mana loss if there are no valid Items to be processed by Remove Curse Spell + if ( spell->ID == SPELL_REMOVECURSE ) + { + if ( itemModifyingGUI->areThereValidItems(1) != true ) + { + return; + } + } + if ( spell->ID == SPELL_MAGICMISSILE && skillCapstoneUnlocked(player, PRO_SPELLCASTING) ) { //Spellcasting capstone. From 4863aabd9c6112ba78512ce0aa1c0b69ccb3602e Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 18:24:54 -0500 Subject: [PATCH 07/65] + Added several lines pertaining to the new GUI's and their various functions --- lang/en.txt | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lang/en.txt b/lang/en.txt index ce927d844..41606d1b8 100644 --- a/lang/en.txt +++ b/lang/en.txt @@ -2899,16 +2899,6 @@ client (player %d) (direct ip)# 2271 spellbook# 2272 spellbook of reflect magic# 2273 spellbook# -2274 blank spellbook 1# -2275 spellbook# -2276 blank spellbook 2# -2277 spellbook# -2278 blank spellbook 3# -2279 spellbook# -2280 blank spellbook 4# -2281 spellbook# -2282 blank spellbook 5# -2283 spellbook# #Additional ingame text. 2350 A fragment breaks away from your %s.# @@ -2976,5 +2966,24 @@ dominate the %s into your service!# 2476 You feel the reflect magic spell fail as the last of your magic is drained!# - -2499 end# +2499 Repair an Item# +2500 There are no valid items to use this on!# +2501 This is a scroll of remove curse!# +2502 This is a scroll of repair!# +2503 This is a scroll of enchant weapon!# +2504 This is a scroll of enchant armor!# +2505 Oh no! The scroll was cursed!# +2506 Your %s was unidentified!# +2507 Your %s was cursed!# +2508 Your %s is now broken!# +2509 Your %s was unenchanted!# +2510 You have no remaining items for the scroll's blessing...# +2511 Wow! Your %s was identified too!# +2512 Wow! Your %s was uncursed too!# +2513 You have no remaining items for the scroll's curse...# +2514 Oh no! Your %s was unidentified too!# +2515 Oh no! Your %s was cursed too!# +2516 Oh no! Your %s was broken too!# +2517 Your %s looks perfect now!# + +2518 end# From 84afe3d43ba8103dd9afd8ac15cec7f982edcb23 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 22:12:34 -0500 Subject: [PATCH 08/65] - Removed the deprecated GUI controller init code --- src/player.cpp | 27 --------------------------- src/player.hpp | 3 --- 2 files changed, 30 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 01d7bf77e..341da8f8c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -820,30 +820,3 @@ Player::~Player() delete entity; } } - -void initIdentifyGUIControllerCode() -{ - if ( identify_items[0] ) - { - selectedIdentifySlot = 0; - warpMouseToSelectedIdentifySlot(); - } - else - { - selectedIdentifySlot = -1; - } -} - -void initRemoveCurseGUIControllerCode() -{ - if ( removecurse_items[0] ) - { - selectedRemoveCurseSlot = 0; - warpMouseToSelectedRemoveCurseSlot(); - } - else - { - selectedRemoveCurseSlot = -1; - } -} - diff --git a/src/player.hpp b/src/player.hpp index f7ec808d7..cbcd7214f 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -179,9 +179,6 @@ class Player ~Player(); }; -void initIdentifyGUIControllerCode(); -void initRemoveCurseGUIControllerCode(); - extern Player** players; //In the process of switching from the old entity player array, all of the old uses of player need to be hunted down and then corrected to account for the new array. //So, search for the comment: From a4790e747bb2f6e6bff1baf405f7511ae9d81b98 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 22:13:27 -0500 Subject: [PATCH 09/65] * Updated NUMLANGENTRIES to correct amount --- src/main.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.hpp b/src/main.hpp index 1a78206f5..01fdbb985 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -450,7 +450,7 @@ extern int minotaurlevel; #define DIRECTCLIENT 4 // language stuff -#define NUMLANGENTRIES 2500 +#define NUMLANGENTRIES 2519 extern char languageCode[32]; extern char** language; From 525203db130f5fe8d9d4afd5e92c66c2240859bc Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 22:22:06 -0500 Subject: [PATCH 10/65] - Removed deprecated item_Scroll functions for item modifying GUI scrolls --- src/item_usage_funcs.cpp | 245 --------------------------------------- src/items.hpp | 3 - 2 files changed, 248 deletions(-) diff --git a/src/item_usage_funcs.cpp b/src/item_usage_funcs.cpp index f15a446c5..7dc3dda9a 100644 --- a/src/item_usage_funcs.cpp +++ b/src/item_usage_funcs.cpp @@ -1047,81 +1047,6 @@ void item_ScrollMail(Item* item, int player) } } -void item_ScrollIdentify(Item* item, int player) -{ - node_t* node; - Item* target; - int c, items, itemToIdentify, numIdentified = 0; - - if (players[player] == nullptr || players[player]->entity == nullptr) - { - return; - } - - if (player != clientnum) - { - return; - } - - if (players[player]->entity->isBlind()) - { - messagePlayer(player, language[775]); - return; - } - - if ( player == clientnum ) - { - conductIlliterate = false; - } - item->identified = 1; - messagePlayer(player, language[848]); - messagePlayer(player, language[849]); - - // identify algorithm: locate unidentified inventory items and randomly choose - // one of them to be identified. Each item has equal chance of being identified. - // cursed = 1 item identified - // uncursed = 1 item identified - // blessed = 1+ items identified - - for ( c = 0; c < std::max(item->beatitude + 1, 1); c++ ) - { - items = 0; - for ( node = stats[player]->inventory.first; node != NULL; node = node->next ) - { - target = (Item*)node->element; - if ( target && target->identified == false ) - { - items++; - } - } - if ( items == 0 ) - { - if ( numIdentified == 0 ) - { - messagePlayer(player, language[850]); - } - break; - } - itemToIdentify = rand() % items; - items = 0; - for ( node = stats[player]->inventory.first; node != NULL; node = node->next ) - { - target = (Item*)node->element; - if ( target && target->identified == false ) - { - if ( items == itemToIdentify ) - { - target->identified = true; - numIdentified++; - messagePlayer(player, " * %s.", target->description()); - break; - } - items++; - } - } - } -} - void item_ScrollLight(Item* item, int player) { int c; @@ -1352,95 +1277,6 @@ void item_ScrollEnchantArmor(Item* item, int player) } } -void item_ScrollRemoveCurse(Item* item, int player) -{ - Item* target; - node_t* node; - if (players[player] == nullptr || players[player]->entity == nullptr) - { - return; - } - - if (players[player]->entity->isBlind()) - { - if (player == clientnum) - { - messagePlayer(player, language[775]); - } - return; - } - - if (player == clientnum) - { - conductIlliterate = false; - } - item->identified = 1; - if (player == clientnum) - { - messagePlayer(player, language[848]); - } - if (item->beatitude >= 0) - { - if (player == clientnum) - { - messagePlayer(player, language[861]); - } - if (stats[player]->helmet != nullptr) - { - stats[player]->helmet->beatitude = std::max(0, stats[player]->helmet->beatitude); - } - if (stats[player]->breastplate != nullptr) - { - stats[player]->breastplate->beatitude = std::max(0, stats[player]->breastplate->beatitude); - } - if (stats[player]->gloves != nullptr) - { - stats[player]->gloves->beatitude = std::max(0, stats[player]->gloves->beatitude); - } - if (stats[player]->shoes != nullptr) - { - stats[player]->shoes->beatitude = std::max(0, stats[player]->shoes->beatitude); - } - if (stats[player]->shield != nullptr) - { - stats[player]->shield->beatitude = std::max(0, stats[player]->shield->beatitude); - } - if (stats[player]->weapon != nullptr) - { - stats[player]->weapon->beatitude = std::max(0, stats[player]->weapon->beatitude); - } - if (stats[player]->cloak != nullptr) - { - stats[player]->cloak->beatitude = std::max(0, stats[player]->cloak->beatitude); - } - if (stats[player]->amulet != nullptr) - { - stats[player]->amulet->beatitude = std::max(0, stats[player]->amulet->beatitude); - } - if (stats[player]->ring != nullptr) - { - stats[player]->ring->beatitude = std::max(0, stats[player]->ring->beatitude); - } - if (stats[player]->mask != nullptr) - { - stats[player]->mask->beatitude = std::max(0, stats[player]->mask->beatitude); - } - if (item->beatitude > 0 && player == clientnum ) - for (node = stats[player]->inventory.first; node != nullptr; node = node->next) - { - target = (Item*)node->element; - target->beatitude = std::max(0, target->beatitude); - } - } - else - { - if (player == clientnum) - { - messagePlayer(player, language[862]); - } - } -} - void item_ScrollFire(Item* item, int player) { if (multiplayer == CLIENT) @@ -1601,87 +1437,6 @@ void item_ScrollMagicMapping(Item* item, int player) } } -void item_ScrollRepair(Item* item, int player) -{ - Item* armor; - if (players[player] == nullptr || players[player]->entity == nullptr) - { - return; - } - - if (players[player]->entity->isBlind()) - { - if (player == clientnum) - { - messagePlayer(player, language[775]); - } - return; - } - - if ( player == clientnum ) - { - conductIlliterate = false; - } - item->identified = 1; - if ( player == clientnum ) - { - messagePlayer(player, language[848]); - } - - if ( stats[player]->weapon != NULL ) - { - armor = stats[player]->weapon; - } - else if ( stats[player]->helmet != NULL ) - { - armor = stats[player]->helmet; - } - else if ( stats[player]->breastplate != NULL ) - { - armor = stats[player]->breastplate; - } - else if ( stats[player]->gloves != NULL ) - { - armor = stats[player]->gloves; - } - else if ( stats[player]->shoes != NULL ) - { - armor = stats[player]->shoes; - } - else if ( stats[player]->shield != NULL ) - { - armor = stats[player]->shield; - } - else if ( stats[player]->cloak != NULL ) - { - armor = stats[player]->cloak; - } - else - { - armor = NULL; - } - - if ( armor == NULL && player == clientnum ) - { - messagePlayer(player, language[870]); - } - else - { - if ( item->beatitude < 0 && player == clientnum ) - { - messagePlayer(player, language[871], armor->getName()); - } - else - { - if ( player == clientnum ) - { - messagePlayer(player, language[872], armor->getName()); - } - armor->status = static_cast(std::min(armor->status + 1 + item->beatitude, 4)); - } - } -} - void item_ScrollDestroyArmor(Item* item, int player) { Item* armor; diff --git a/src/items.hpp b/src/items.hpp index 1c60e3992..9e0633a98 100644 --- a/src/items.hpp +++ b/src/items.hpp @@ -379,16 +379,13 @@ void item_PotionSpeed(Item* item, Entity* entity); void item_PotionAcid(Item* item, Entity* entity); void item_PotionParalysis(Item* item, Entity* entity); void item_ScrollMail(Item* item, int player); -void item_ScrollIdentify(Item* item, int player); void item_ScrollLight(Item* item, int player); void item_ScrollBlank(Item* item, int player); void item_ScrollEnchantWeapon(Item* item, int player); void item_ScrollEnchantArmor(Item* item, int player); -void item_ScrollRemoveCurse(Item* item, int player); void item_ScrollFire(Item* item, int player); void item_ScrollFood(Item* item, int player); void item_ScrollMagicMapping(Item* item, int player); -void item_ScrollRepair(Item* item, int player); void item_ScrollDestroyArmor(Item* item, int player); void item_ScrollTeleportation(Item* item, int player); void item_ScrollSummon(Item* item, int player); From 9075084f64acdd589901874958e4965aec921f67 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 22:22:54 -0500 Subject: [PATCH 11/65] * Replaced deprecated code with new itemModifyingGUI implementation --- src/items.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/items.cpp b/src/items.cpp index 0dda5e755..54c958c74 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -1443,11 +1443,7 @@ void useItem(Item* item, int player) item_ScrollMail(item, player); break; case SCROLL_IDENTIFY: - item_ScrollIdentify(item, player); - if ( !players[player]->entity->isBlind() ) - { - consumeItem(item); - } + itemModifyingGUI->openItemModifyingGUI(0, item); break; case SCROLL_LIGHT: item_ScrollLight(item, player); @@ -1474,11 +1470,7 @@ void useItem(Item* item, int player) } break; case SCROLL_REMOVECURSE: - item_ScrollRemoveCurse(item, player); - if ( !players[player]->entity->isBlind() ) - { - consumeItem(item); - } + itemModifyingGUI->openItemModifyingGUI(1, item); break; case SCROLL_FIRE: item_ScrollFire(item, player); @@ -1502,11 +1494,7 @@ void useItem(Item* item, int player) } break; case SCROLL_REPAIR: - item_ScrollRepair(item, player); - if ( !players[player]->entity->isBlind() ) - { - consumeItem(item); - } + itemModifyingGUI->openItemModifyingGUI(2, item); break; case SCROLL_DESTROYARMOR: item_ScrollDestroyArmor(item, player); From 551056846b185d936c8bb4dff6807302029fc47e Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 22:24:05 -0500 Subject: [PATCH 12/65] + Added initial setup and final cleanup of itemModifyingGUI --- src/init_game.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/init_game.cpp b/src/init_game.cpp index 002c70e10..6c43420df 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -493,6 +493,8 @@ int fmod_result; return -1; } + itemModifyingGUI = new GUI::ItemModifyingGUI; + return 0; } @@ -830,4 +832,8 @@ void deinitGame() delete players[i]; } delete[] players; + + // 9-5-2017 - Lutz - ItemModifyingGUI Refactor + delete itemModifyingGUI; + itemModifyingGUI = nullptr; } From 426c58c461e1caf39f945e0a8b5b831dff959081 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 23:44:09 -0500 Subject: [PATCH 13/65] + Added various documentation comments --- src/interface/ItemModifyingGUI.cpp | 51 +++++++++++++++++++----------- src/interface/ItemModifyingGUI.hpp | 13 ++++++++ 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index 8a0111650..c4d657a15 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -1,3 +1,16 @@ +/*------------------------------------------------------------------------------- + +BARONY +File: ItemModifyingGUI.cpp +Desc: ItemModifyingGUI class implementation + +Copyright 2013-2017 (c) Turning Wheel LLC, all rights reserved. +See LICENSE for details. + +Additional Author(s): Lutz Kellen + +-------------------------------------------------------------------------------*/ + #include "ItemModifyingGUI.hpp" #include "../player.hpp" #include "../stat.hpp" @@ -272,7 +285,7 @@ bool ItemModifyingGUI::areThereValidItems(const Uint8 GUIType) closeItemModifyingGUI(); // Reset all values to prevent any crossover return true; } -} +} // areThereValidItems() /* ItemModifyingGUI.cpp * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] @@ -351,7 +364,7 @@ void ItemModifyingGUI::itemModifyingGUIProcessRandomItem() break; default: printlog("ERROR: itemModifyingGUIProcessRandomItem() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } -} +} // itemModifyingGUIProcessRandomItem() /* ItemModifyingGUI.cpp * Selects the correct function to rebuild the GUI Inventory according to 'itemModifyingGUI_Type' @@ -474,7 +487,7 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtons() } } } -} +} // itemModifyingGUI_HandleButtons() /* ItemModifyingGUI.cpp * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for Mouse scroll wheel input @@ -509,7 +522,7 @@ void ItemModifyingGUI::itemModifyingGUI_HandleMouseWheel() } } } -} +} // itemModifyingGUI_HandleMouseWheel() /* ItemModifyingGUI.cpp * Handles the actual movement of the GUI Window by modifying 'itemModifyingGUI_OffsetX/Y' when 'bIsItemModifyingGUI_Dragging' == true @@ -553,7 +566,7 @@ void ItemModifyingGUI::itemModifyingGUI_HandleDraggingBar() bIsItemModifyingGUI_Dragging = false; } } -} +} // itemModifyingGUI_HandleDraggingBar() /* ItemModifyingGUI.cpp * @param GUIPosX - The GUI position in the center of the screen + itemModifyingGUI_OffsetX @@ -595,7 +608,7 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, drawImage(invclose_bmp, nullptr, &GUICloseButtonRect); closeItemModifyingGUI(); } -} +} // itemModifyingGUI_HandleButtonImages() /* ItemModifyingGUI.cpp * Rebuilds the GUI Inventory before selecting the correct function to render the Images for each Item according to 'itemModifyingGUI_Type' @@ -622,7 +635,7 @@ void ItemModifyingGUI::itemModifyingGUI_HandleItemImages() break; default: printlog("ERROR: itemModifyingGUI_HandleItemImages() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } -} +} // itemModifyingGUI_HandleItemImages() // IDENTIFY GUI @@ -670,7 +683,7 @@ void ItemModifyingGUI::processIdentifyGUIEffectOnItem(Item* const selectedItem) } closeItemModifyingGUI(); -} +} // processIdentifyGUIEffectOnItem() /* ItemModifyingGUI.cpp * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 @@ -797,7 +810,7 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) } } } -} +} // identifyGUIProcessRandomItem() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' @@ -923,7 +936,7 @@ void ItemModifyingGUI::rebuildIdentifyGUIInventory() break; } } -} +} // rebuildIdentifyGUIInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots @@ -991,7 +1004,7 @@ void ItemModifyingGUI::identifyGUI_HandleItemImages() } } } -} +} // identifyGUI_HandleItemImages() // REMOVE CURSE GUI @@ -1096,7 +1109,7 @@ void ItemModifyingGUI::processRemoveCurseGUIEffectOnItem(Item* const selectedIte net_packet->len = 6; sendPacketSafe(net_sock, -1, net_packet, 0); } -} +} // processRemoveCurseGUIEffectOnItem() /* ItemModifyingGUI.cpp * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 @@ -1222,7 +1235,7 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) } } } -} +} // removeCurseGUIProcessRandomItem() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' @@ -1348,7 +1361,7 @@ void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() break; } } -} +} // rebuildRemoveCurseGUIInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots @@ -1416,7 +1429,7 @@ void ItemModifyingGUI::removeCurseGUI_HandleItemImages() } } } -} +} // removeCurseGUI_HandleItemImages() // REPAIR GUI @@ -1519,7 +1532,7 @@ void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) net_packet->len = 6; sendPacketSafe(net_sock, -1, net_packet, 0); } -} +} // processRepairGUIEffectOnItem() /* ItemModifyingGUI.cpp * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 @@ -1634,7 +1647,7 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) } } } -} +} // repairGUIProcessRandomItem() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' @@ -1812,7 +1825,7 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() break; } } -} +} // rebuildRepairGUIInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots @@ -1978,7 +1991,7 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() } } } -} +} // repairGUI_HandleItemImages() // ENCHANT WEAPON GUI diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 71e374f30..888372fbf 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -1,3 +1,16 @@ +/*------------------------------------------------------------------------------- + +BARONY +File: ItemModifyingGUI.hpp +Desc: ItemModifyingGUI class definition + +Copyright 2013-2017 (c) Turning Wheel LLC, all rights reserved. +See LICENSE for details. + +Additional Author(s): Lutz Kellen + +-------------------------------------------------------------------------------*/ + #pragma once #include "interface.hpp" From 6bf4d3ce9e7c9d7a0db9033ecd8d59b2637f80f6 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 8 Sep 2017 23:46:23 -0500 Subject: [PATCH 14/65] + Added a check to prevent any further progression if bIsActive == false --- src/interface/ItemModifyingGUI.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index c4d657a15..a80c1dbd8 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -130,6 +130,12 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr */ void ItemModifyingGUI::updateItemModifyingGUI() { + // If the GUI is not active, there is no reason to go further + if ( bIsActive != true ) + { + return; + } + // Cursed Scrolls do not use the GUI, their processing is determined at random if ( bIsActive == true && bIsCursed != true ) { From 7bf01e379106fc4b80cf0ef8c36feee373fb1191 Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 13 Sep 2017 14:09:16 -0500 Subject: [PATCH 15/65] * Tweaked several small things and added gamepadMoveCursor() and more documentation --- src/interface/ItemModifyingGUI.cpp | 179 ++++++++++++++++++++++------- src/interface/ItemModifyingGUI.hpp | 141 ++++++++++++++++++++++- 2 files changed, 275 insertions(+), 45 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index a80c1dbd8..a17c979a8 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -31,18 +31,13 @@ ItemModifyingGUI::ItemModifyingGUI() : itemModifyingGUI_OffsetX(0), itemModifyingGUI_OffsetY(0) { - itemModifyingGUI_IMG = loadImage("images/system/identifyGUI.png"); + itemModifyingGUI_IMG = loadImage("images/system/itemModifyingGUI.png"); } // ItemModifyingGUI() ItemModifyingGUI::~ItemModifyingGUI() { closeItemModifyingGUI(); itemModifyingGUI_IMG = nullptr; - itemModifyingGUI_ScrollUsed = nullptr; - for ( int i = 0; i < NUM_ITEM_MODIFYING_GUI_ITEMS; i++ ) - { - itemModifyingGUI_Inventory[i] = nullptr; - } } // ~ItemModifyingGUI() /* ItemModifyingGUI.cpp @@ -137,7 +132,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() } // Cursed Scrolls do not use the GUI, their processing is determined at random - if ( bIsActive == true && bIsCursed != true ) + if ( bIsCursed != true ) { // If the Player's Inventory cannot be accessed, nothing will work, therefore this is a check to prevent needless processing list_t* playerInventoryList = &stats[clientnum]->inventory; @@ -171,15 +166,15 @@ void ItemModifyingGUI::updateItemModifyingGUI() char* windowName; windowName = language[2499]; // "Repair an Item" - Sint32 windowLabelX = ((((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 2 + ((identifyGUI_img->w / 2) - ((TTF8_WIDTH * longestline(windowName)) / 2))); - Sint32 windowLabelY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 4; + const Sint32 windowLabelX = ((((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 2 + ((itemModifyingGUI_IMG->w / 2) - ((TTF8_WIDTH * longestline(windowName)) / 2))); + const Sint32 windowLabelY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 4; // Print the Window Label ttfPrintText(ttf8, windowLabelX, windowLabelY, windowName); // The GUI Window's position after being offset - Sint32 GUIOffsetPosX = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); - Sint32 GUIOffsetPosY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 GUIOffsetPosX = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 GUIOffsetPosY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); // Draw the Images for the GUI buttons when they are being clicked itemModifyingGUI_HandleButtonImages(GUIOffsetPosX, GUIOffsetPosY); @@ -233,7 +228,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() // This is done at the end to prevent the Inventory Slot highlight from being drawn on top of the Item information itemModifyingGUI_HandleItemImages(); } - else if ( bIsActive == true && bIsCursed == true ) + else { if ( itemModifyingGUI_ScrollUsed == nullptr ) { @@ -252,7 +247,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() } // updateItemModifyingGUI() /* ItemModifyingGUI.cpp - * Resets all relevant variables back to their base states + * Resets all member variables back to their base states */ void ItemModifyingGUI::closeItemModifyingGUI() { @@ -263,8 +258,104 @@ void ItemModifyingGUI::closeItemModifyingGUI() itemModifyingGUI_Type = 0; itemModifyingGUI_InventoryScrollOffset = 0; itemModifyingGUI_InventorySelectedSlot = -1; + + itemModifyingGUI_ScrollUsed = nullptr; + for ( int i = 0; i < NUM_ITEM_MODIFYING_GUI_ITEMS; i++ ) + { + itemModifyingGUI_Inventory[i] = nullptr; + } } // closeItemModifyingGUI() +/* ItemModifyingGUI.cpp + * @param direction - Will either be -1 for Up or 1 for Down. The direction in which the User wants to move the cursor + * Called by GameController::handleItemModifyingGUIMovement(). Evaluates the requested movement, updating 'itemModifyingGUI_InventorySelectedSlot' as needed + */ +void ItemModifyingGUI::gamepadMoveCursor(Sint8 direction) +{ + // Up will be -1, Down will be 1 + Sint8 newSlot = itemModifyingGUI_InventorySelectedSlot + direction; + + // D-Pad Up was pressed + if ( newSlot < itemModifyingGUI_InventorySelectedSlot ) + { + // Possible cases: + // * 1) Move cursor up the GUI through different itemModifyingGUI_InventorySelectedSlot + // * * 2) Page up through itemModifyingGUI_InventoryScrollOffset-- + // * * 3) Scrolling up past top of the GUI's Inventory, no itemModifyingGUI_InventoryScrollOffset (move back to Player Inventory) + + if ( itemModifyingGUI_InventorySelectedSlot <= 0 ) + { + // Covers cases 2 & 3 + // Possible cases: + // * A) Hit very top of the GUI's Inventory, can't go any further. Return to Player Inventory + // * * B) Page up, scrolling through itemModifyingGUI_InventoryScrollOffset-- + + if ( itemModifyingGUI_InventoryScrollOffset <= 0 ) + { + // Case 3/A: Return to Player Inventory + // A check will happen in playerinventory.cpp immediately after this which will call warpMouseToSelectedInventorySlot() + itemModifyingGUI_InventorySelectedSlot = -1; + } + else + { + // Case 2/B: Page up through GUI's Inventory + itemModifyingGUI_InventoryScrollOffset--; + } + } + else + { + // Covers case 1 + // Move cursor up the GUI through different itemModifyingGUI_InventorySelectedSlot (itemModifyingGUI_InventorySelectedSlot--) + itemModifyingGUI_InventorySelectedSlot--; + warpMouseToSelectedGUISlot(); + } + } + else if ( newSlot > itemModifyingGUI_InventorySelectedSlot ) // D-Pad Down was pressed + { + // Possible cases: + // * 1) Moving cursor down through GUI through different itemModifyingGUI_InventorySelectedSlot + // * * 2) Scrolling down past bottom of GUI's Inventory through itemModifyingGUI_InventoryScrollOffset++ + // * * 3) Scrolling down past bottom of GUI's Inventory, past maximum GUI Inventory size (Undo move -- can't go beyond limit of the GUI's Inventory) + + if ( itemModifyingGUI_InventorySelectedSlot >= NUM_ITEM_MODIFYING_GUI_ITEMS - 1 ) + { + // Covers cases 2 & 3 + itemModifyingGUI_InventoryScrollOffset++; // itemModifyingGUI_InventoryScrollOffset is automatically sanitized in updateItemModifyingGUI() + } + else + { + // Covers case 1 + // Move cursor down through the GUI through different itemModifyingGUI_InventorySelectedSlot (itemModifyingGUI_InventorySelectedSlot++) + // This is a little bit trickier since must undo movement if there is no Item in the next slot + // Two possible cases: + // * A) There are Items below this. Advance itemModifyingGUI_InventorySelectedSlot to them + // * * B) On last Item already. Do nothing (undo movement) + + Item* item = getItemInfoFromGUI(itemModifyingGUI_InventorySelectedSlot + 1); + + if ( item != nullptr ) + { + // Case 1/A + itemModifyingGUI_InventorySelectedSlot++; + warpMouseToSelectedGUISlot(); + } + else + { + // Case 1/B + //No more Items. Prevent movement (undo movement) + } + } + } +} + +/* ItemModifyingGUI.cpp + * @returns 'bIsActive' + */ +bool ItemModifyingGUI::isActive() const +{ + return bIsActive; +} + /* ItemModifyingGUI.cpp * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor * @returns true - If the Player's Inventory has valid Items for processing @@ -293,6 +384,16 @@ bool ItemModifyingGUI::areThereValidItems(const Uint8 GUIType) } } // areThereValidItems() +/* ItemModifyingGUI.cpp + * @returns true - If 'itemModifyingGUI_InventorySelectedSlot' is < 0 + * @returns false - If 'itemModifyingGUI_InventorySelectedSlot' is 0 or greater + * Returns whether or not the mouse is currently hovering over a GUI Inventory Slot + */ +bool ItemModifyingGUI::isSelectedSlotInvalid() const +{ + return (itemModifyingGUI_InventorySelectedSlot < 0); +} + /* ItemModifyingGUI.cpp * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] * @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] @@ -420,29 +521,29 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtons() { // GUI Button Collision Bounds TODOR: I may have these swapped, the lower bound may be the upper bound // Scroll Up Button Y - Sint32 scrollUpButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; - Sint32 scrollUpButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; + const Sint32 scrollUpButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; + const Sint32 scrollUpButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; // Scroll Up Button X - Sint32 scrollUpButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); - Sint32 scrollUpButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + const Sint32 scrollUpButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + const Sint32 scrollUpButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); // Scroll Down Button Y - Sint32 scrollDownButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; - Sint32 scrollDownButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 88; + const Sint32 scrollDownButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; + const Sint32 scrollDownButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 88; // Scroll Down Button X - Sint32 scrollDownButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); - Sint32 scrollDownButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + const Sint32 scrollDownButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + const Sint32 scrollDownButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); // Close Button Y - Sint32 closeButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); - Sint32 closeButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; + const Sint32 closeButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 closeButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; // Close Button X - Sint32 closeButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 393; - Sint32 closeButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 407; + const Sint32 closeButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 393; + const Sint32 closeButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 407; // Dragging Bar Y - Sint32 draggingBarY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); - Sint32 draggingBarY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; + const Sint32 draggingBarY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 draggingBarY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; // Dragging Bar X - Sint32 draggingBarX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); - Sint32 draggingBarX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 377; + const Sint32 draggingBarX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 draggingBarX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 377; // Buttons if ( mousestatus[SDL_BUTTON_LEFT] ) @@ -502,11 +603,11 @@ void ItemModifyingGUI::itemModifyingGUI_HandleMouseWheel() { // GUI Mouse Wheel Collision Bounds // Mouse Wheel Y - Sint32 mouseWheelY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; - Sint32 mouseWheelY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + (identifyGUI_img->h - 8); + const Sint32 mouseWheelY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; + const Sint32 mouseWheelY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + (itemModifyingGUI_IMG->h - 8); // Mouse Wheel X - Sint32 mouseWheelX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 12; - Sint32 mouseWheelX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (identifyGUI_img->w - 28); + const Sint32 mouseWheelX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 12; + const Sint32 mouseWheelX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); // Mouse wheel if ( omousex >= mouseWheelX_LowerBound && omousex < mouseWheelX_UpperBound ) @@ -554,17 +655,17 @@ void ItemModifyingGUI::itemModifyingGUI_HandleDraggingBar() { itemModifyingGUI_OffsetX = camera.winx - GUICenterPosX; } - if ( GUIOffsetPosX > camera.winx + camera.winw - identifyGUI_img->w ) + if ( GUIOffsetPosX > camera.winx + camera.winw - itemModifyingGUI_IMG->w ) { - itemModifyingGUI_OffsetX = (camera.winx + camera.winw - identifyGUI_img->w) - GUICenterPosX; + itemModifyingGUI_OffsetX = (camera.winx + camera.winw - itemModifyingGUI_IMG->w) - GUICenterPosX; } if ( GUIOffsetPosY <= camera.winy ) { itemModifyingGUI_OffsetY = camera.winy - GUICenterPosY; } - if ( GUIOffsetPosY > camera.winy + camera.winh - identifyGUI_img->h ) + if ( GUIOffsetPosY > camera.winy + camera.winh - itemModifyingGUI_IMG->h ) { - itemModifyingGUI_OffsetY = (camera.winy + camera.winh - identifyGUI_img->h) - GUICenterPosY; + itemModifyingGUI_OffsetY = (camera.winy + camera.winh - itemModifyingGUI_IMG->h) - GUICenterPosY; } } else // Else, reset the flag @@ -585,7 +686,7 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, if ( buttonclick == 7 ) { SDL_Rect GUIInventoryUpButtonRect; - GUIInventoryUpButtonRect.x = GUIPosX + (identifyGUI_img->w - 28); + GUIInventoryUpButtonRect.x = GUIPosX + (itemModifyingGUI_IMG->w - 28); GUIInventoryUpButtonRect.y = GUIPosY + 16; GUIInventoryUpButtonRect.w = 0; GUIInventoryUpButtonRect.h = 0; @@ -596,7 +697,7 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, if ( buttonclick == 8 ) { SDL_Rect GUIInventoryDownButtonRect; - GUIInventoryDownButtonRect.x = GUIPosX + (identifyGUI_img->w - 28); + GUIInventoryDownButtonRect.x = GUIPosX + (itemModifyingGUI_IMG->w - 28); GUIInventoryDownButtonRect.y = GUIPosY + 52; GUIInventoryDownButtonRect.w = 0; GUIInventoryDownButtonRect.h = 0; diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 888372fbf..9a4079bfe 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -17,15 +17,54 @@ Additional Author(s): Lutz Kellen namespace GUI { + class ItemModifyingGUI { public: ItemModifyingGUI(); ~ItemModifyingGUI(); + /* ItemModifyingGUI.cpp + * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + * @param scrollUsed - A pointer to the Item being used to open the GUI. The Item will be deleted if processing completes successfully. Use nullptr if a Spell is used to open the GUI + * Initializes the GUI, sets 'shootmode' to false, and 'gui_mode' to 'GUI_MODE_INVENTORY'. The GUI Inventory will be built using 'buildItemModifyingGUIInventory()' + * In the case of a Spell, itemModifyingGUI_ScrollBeatitude will be 0, as Spells do not give any extra or negative effects + * If a ItemModifyingGUI is already opened, it will be closed before opening the new one + * If a Unidentified Scroll is used, it will be Identified here and message the Player accordingly + */ void openItemModifyingGUI(const Uint8 GUIType, Item* const scrollUsed); + /* ItemModifyingGUI.cpp + * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls + * Handles the GUI Inventory slot bounds and Mouse input to call processGUIEffectOnItem() + */ void updateItemModifyingGUI(); + /* ItemModifyingGUI.cpp + * Resets all member variables back to their base states + */ + void closeItemModifyingGUI(); + /* ItemModifyingGUI.cpp + * @param direction - Will either be -1 for Up or 1 for Down. The direction in which the User wants to move the cursor + * Called by GameController::handleItemModifyingGUIMovement(). Evaluates the requested movement, updating 'itemModifyingGUI_InventorySelectedSlot' as needed + */ + void gamepadMoveCursor(Sint8 direction); + /* ItemModifyingGUI.cpp + * @returns 'bIsActive' + */ + bool isActive() const; + /* ItemModifyingGUI.cpp + * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + * @returns true - If the Player's Inventory has valid Items for processing + * @returns false - If the Player's Inventory has no valid Items for processing + * The main usage of this function is to prevent a Spell from being cast needlessly + * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via closeItemModifyingGUI() + */ bool areThereValidItems(const Uint8 GUIType); + /* ItemModifyingGUI.cpp + * @returns true - If 'itemModifyingGUI_InventorySelectedSlot' is < 0 + * @returns false - If 'itemModifyingGUI_InventorySelectedSlot' is 0 or greater + * Returns whether or not the mouse is currently hovering over a GUI Inventory Slot + */ + bool isSelectedSlotInvalid() const; private: // ItemModifying GUI @@ -34,10 +73,10 @@ class ItemModifyingGUI bool bIsActive; // Flag for whether or not the ItemModifyingGUI is currently displayed bool bIsCursed; // Flag for whether or not the Scroll used is Cursed. If it is, bypasses the GUI and skips to processing bool bIsItemModifyingGUI_Dragging; // Flag for whether or not the GUI Window is being dragged around the Screen - Sint8 itemModifyingGUI_ScrollBeatitude; // The Beatitude value of the Scroll being used + Sint16 itemModifyingGUI_ScrollBeatitude; // The Beatitude value of the Scroll being used Uint8 itemModifyingGUI_Type; // Which type of GUI is being displayed? 0, 1, 2, 3, 4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor Uint8 itemModifyingGUI_InventoryScrollOffset; // The amount Items existing past the limit of visible Items #TODOR: I actually am not 100% certain what this is - Uint8 itemModifyingGUI_InventorySelectedSlot; // The GUI Inventory Slot that has been selected by the Player for processing + Sint8 itemModifyingGUI_InventorySelectedSlot; // The GUI Inventory Slot that has been selected by the Player for processing Sint32 itemModifyingGUI_OffsetX; // The GUI Window's X offset, to allow the Window to be moved around the screen. Offset is remembered for future use Sint32 itemModifyingGUI_OffsetY; // The GUI Window's Y offset, to allow the Window to be moved around the screen. Offset is remembered for future use @@ -45,38 +84,128 @@ class ItemModifyingGUI Item* itemModifyingGUI_Inventory[NUM_ITEM_MODIFYING_GUI_ITEMS] = {nullptr}; // The GUI Inventory which holds all of the Player's Inventory Items that match the given GUIType Item* itemModifyingGUI_ScrollUsed = nullptr; // A pointer to the Item of the Scroll being used to open the GUI. If the Scroll finishes it's processing, the Item will be deleted - void closeItemModifyingGUI(); - + /* ItemModifyingGUI.cpp + * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] + * @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] + * @returns The Item* from itemModifyingGUI_Inventory[slot] + * @returns nullptr if slot >= 4 (Out of bounds) + */ Item* getItemInfoFromGUI(Uint8 slot); + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Selects the correct function to process the Item according to 'itemModifyingGUI_Type' + */ void processGUIEffectOnItem(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * Used for Cursed Scrolls. Selects the correct function to randomly process the Item(s) according to 'itemModifyingGUI_Type' + */ void itemModifyingGUIProcessRandomItem(); + /* ItemModifyingGUI.cpp + * Selects the correct function to rebuild the GUI Inventory according to 'itemModifyingGUI_Type' + */ void rebuildItemModifyingGUIInventory(); + /* ItemModifyingGUI.cpp + * Calls SDL_WarpMouseInWindow() to move the Mouse cursor to the currently selected GUI slot for controllers + */ void warpMouseToSelectedGUISlot(); // Display Update Handlers + /* ItemModifyingGUI.cpp + * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for each of the GUI's buttons + * The Top Bar of the GUI used for dragging is considered a button + */ void itemModifyingGUI_HandleButtons(); + /* ItemModifyingGUI.cpp + * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for Mouse scroll wheel input + */ void itemModifyingGUI_HandleMouseWheel(); + /* ItemModifyingGUI.cpp + * Handles the actual movement of the GUI Window by modifying 'itemModifyingGUI_OffsetX/Y' when 'bIsItemModifyingGUI_Dragging' == true + */ void itemModifyingGUI_HandleDraggingBar(); + /* ItemModifyingGUI.cpp + * @param GUIPosX - The GUI position in the center of the screen + itemModifyingGUI_OffsetX + * @param GUIPosY - The GUI position in the center of the screen + itemModifyingGUI_OffsetY + * Handles drawing the actual GUI button Images when they are being clicked. The unclicked versions are part of the original Image + */ void itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY); + /* ItemModifyingGUI.cpp + * Rebuilds the GUI Inventory before selecting the correct function to render the Images for each Item according to 'itemModifyingGUI_Type' + */ void itemModifyingGUI_HandleItemImages(); // Identify GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ void processIdentifyGUIEffectOnItem(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' + * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used + */ void identifyGUIProcessRandomItem(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ void rebuildIdentifyGUIInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ void identifyGUI_HandleItemImages(); // Remove Curse GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ void processRemoveCurseGUIEffectOnItem(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' + * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used + */ void removeCurseGUIProcessRandomItem(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ void rebuildRemoveCurseGUIInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ void removeCurseGUI_HandleItemImages(); // Repair GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Repairs the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls cannot repair Broken or Serviceable Items. +0 can repair Decrepit and Worn up to Serviceable + * +1 Scrolls cannot repair Serviceable Items. +1 can repair Broken, Decrepit, and Worn up to Serviceable + * +2 Scrolls can repair all Items up to Excellent + * Messages the Player that their Item has been Repaired, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ void processRepairGUIEffectOnItem(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random items to Broken + * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used + */ void repairGUIProcessRandomItem(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ void rebuildRepairGUIInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ void repairGUI_HandleItemImages(); -}; -} \ No newline at end of file +}; // class ItemModifyingGUI + +} // namespace GUI \ No newline at end of file From a846892188f0e608b8d34d401b4ed1da1daa53fd Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 12:56:43 -0500 Subject: [PATCH 16/65] + Added Enchant Scrolls functionality and other various tweaks/fixes --- src/interface/ItemModifyingGUI.cpp | 1442 +++++++++++++++++++++++++++- src/interface/ItemModifyingGUI.hpp | 60 +- 2 files changed, 1463 insertions(+), 39 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index a17c979a8..fc0770a63 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -87,10 +87,10 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr messagePlayer(clientnum, language[2502]); // "This is a scroll of repair!" break; case 3: // Enchant Weapon - messagePlayer(clientnum, language[2503]); // "This is a scroll of enchant weapon!" + messagePlayer(clientnum, language[2503]); // "This is a scroll of Enchant weapon!" break; case 4: // Enchant Armor - messagePlayer(clientnum, language[2504]); // "This is a scroll of enchant armor!" + messagePlayer(clientnum, language[2504]); // "This is a scroll of Enchant armor!" break; default: printlog("ERROR: updateItemModifyingGUI() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } @@ -103,6 +103,22 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr // If the Inventory is empty, there is nothing to process. The GUI will not open and nothing will be processed if ( itemModifyingGUI_Inventory[0] == nullptr ) { + // If it is a Cursed Scroll and there are no valid Items, still use up the Scroll + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[863]); // "The scroll smokes and crumbles to ash!" + + // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed + if ( itemModifyingGUI_ScrollUsed == nullptr ) + { + printlog("ERROR: updateItemModifyingGUI() - A Cursed Spell has opened the GUI. This should never happen."); + return; + } + + consumeItem(itemModifyingGUI_ScrollUsed); + closeItemModifyingGUI(); + return; + } messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" closeItemModifyingGUI(); return; @@ -113,9 +129,13 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr shootmode = false; gui_mode = GUI_MODE_INVENTORY; - // The actual logic is handled by updateItemModifyingGUI() - itemModifyingGUI_InventorySelectedSlot = 0; - warpMouseToSelectedGUISlot(); + // If the Scroll is Cursed, don't warp the Mouse + if ( itemModifyingGUI_ScrollBeatitude >= 0 ) + { + // The actual logic is handled by updateItemModifyingGUI() + itemModifyingGUI_InventorySelectedSlot = 0; + warpMouseToSelectedGUISlot(); + } } } // openItemModifyingGUI() @@ -430,8 +450,10 @@ void ItemModifyingGUI::processGUIEffectOnItem(Item* const selectedItem) processRepairGUIEffectOnItem(selectedItem); break; case 3: // Enchant Weapon + processEnchantWeaponGUIEffectOnItem(selectedItem); break; case 4: // Enchant Armor + processEnchantArmorGUIEffectOnItem(selectedItem); break; default: printlog("ERROR: processGUIEffectOnItem() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } @@ -466,8 +488,10 @@ void ItemModifyingGUI::itemModifyingGUIProcessRandomItem() repairGUIProcessRandomItem(numberOfItemsToProcess); break; case 3: // Enchant Weapon + enchantWeaponGUIProcessRandomItem(numberOfItemsToProcess); break; case 4: // Enchant Armor + enchantArmorGUIProcessRandomItem(numberOfItemsToProcess); break; default: printlog("ERROR: itemModifyingGUIProcessRandomItem() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } @@ -490,8 +514,10 @@ void ItemModifyingGUI::rebuildItemModifyingGUIInventory() rebuildRepairGUIInventory(); break; case 3: // Enchant Weapon + rebuildEnchantWeaponGUIInventory(); break; case 4: // Enchant Armor + rebuildEnchantArmorGUIInventory(); break; default: printlog("ERROR: rebuildItemModifyingGUIInventory() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } @@ -737,8 +763,10 @@ void ItemModifyingGUI::itemModifyingGUI_HandleItemImages() repairGUI_HandleItemImages(); break; case 3: // Enchant Weapon + enchantWeaponGUI_HandleItemImages(); break; case 4: // Enchant Armor + enchantArmorGUI_HandleItemImages(); break; default: printlog("ERROR: itemModifyingGUI_HandleItemImages() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } @@ -793,7 +821,7 @@ void ItemModifyingGUI::processIdentifyGUIEffectOnItem(Item* const selectedItem) } // processIdentifyGUIEffectOnItem() /* ItemModifyingGUI.cpp - * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used */ @@ -809,7 +837,7 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) return; } - // Count the number of items in the GUI Inventory + // Count the number of Items in the GUI Inventory Uint8 totalAmountOfItems = 0; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { @@ -842,14 +870,33 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) } } - // There are no valid items to be processed - if ( totalAmountOfItems == 0 ) + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) { messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." return; } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + Sint8 iPreviousItemProcessedIndex = -1; Sint8 iItemToProcessIndex = -1; Uint8 iIdentifyGUIInventoryIndex = 0; @@ -881,7 +928,7 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) { if ( iIdentifyGUIInventoryIndex == iItemToProcessIndex ) { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 ) + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) { messagePlayer(clientnum, language[2514], itemToProcess->description()); // "Oh no! Your %s was unidentified too!" } @@ -915,8 +962,30 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) break; default: printlog("ERROR: identifyGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; } } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } } // identifyGUIProcessRandomItem() /* ItemModifyingGUI.cpp @@ -936,7 +1005,7 @@ void ItemModifyingGUI::rebuildIdentifyGUIInventory() return; } - // Count the number of items in the GUI Inventory + // Count the number of Items in the GUI Inventory for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { Item* item = static_cast(iInventoryNode->element); @@ -980,7 +1049,7 @@ void ItemModifyingGUI::rebuildIdentifyGUIInventory() iIdentifyGUIInventoryIndex = 0; - // Assign the visible items to the GUI slots + // Assign the visible Items to the GUI slots bool bBreakFromLoop = false; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { @@ -1219,7 +1288,7 @@ void ItemModifyingGUI::processRemoveCurseGUIEffectOnItem(Item* const selectedIte } // processRemoveCurseGUIEffectOnItem() /* ItemModifyingGUI.cpp - * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used */ @@ -1235,7 +1304,7 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) return; } - // Count the number of items in the GUI Inventory + // Count the number of Items in the GUI Inventory Uint8 totalAmountOfItems = 0; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { @@ -1268,14 +1337,33 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) } } - // There are no valid items to be processed - if ( totalAmountOfItems == 0 ) + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) { messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." return; } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + Sint8 iPreviousItemProcessedIndex = -1; Sint8 iItemToProcessIndex = -1; Uint8 iRemoveCurseGUIInventoryIndex = 0; @@ -1307,7 +1395,7 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) { if ( iRemoveCurseGUIInventoryIndex == iItemToProcessIndex ) { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 ) + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) { messagePlayer(clientnum, language[2515], itemToProcess->description()); // "Oh no! Your %s was cursed too!" } @@ -1340,7 +1428,29 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) break; default: printlog("ERROR: removeCurseGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." } } // removeCurseGUIProcessRandomItem() @@ -1361,7 +1471,7 @@ void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() return; } - // Count the number of items in the GUI Inventory + // Count the number of Items in the GUI Inventory for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { Item* item = static_cast(iInventoryNode->element); @@ -1405,7 +1515,7 @@ void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() iRemoveCurseGUIInventoryIndex = 0; - // Assign the visible items to the GUI slots + // Assign the visible Items to the GUI slots bool bBreakFromLoop = false; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { @@ -1556,7 +1666,7 @@ void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) return; } - Uint8 itemNewStatus = -1; + // Cursed Scrolls don't use the GUI so they will never call this function switch ( itemModifyingGUI_ScrollBeatitude ) { case 0: @@ -1633,7 +1743,7 @@ void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) strcpy((char*)net_packet->data, "ARMR"); net_packet->data[4] = itemType; - net_packet->data[5] = itemNewStatus; + net_packet->data[5] = selectedItem->status; net_packet->address.host = net_server.host; net_packet->address.port = net_server.port; net_packet->len = 6; @@ -1642,8 +1752,8 @@ void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) } // processRepairGUIEffectOnItem() /* ItemModifyingGUI.cpp - * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 - * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random items to Broken + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to Broken * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used */ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) @@ -1658,7 +1768,7 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) return; } - // Count the number of items in the GUI Inventory + // Count the number of Items in the GUI Inventory Uint8 totalAmountOfItems = 0; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { @@ -1670,7 +1780,7 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) } // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) { continue; } @@ -1689,14 +1799,33 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) } } - // There are no valid items to be processed - if ( totalAmountOfItems == 0 ) + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) { - messagePlayer(clientnum, language[2513]); // "You have no remaining items for the scroll's curse..." + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." return; } Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + Sint8 iPreviousItemProcessedIndex = -1; Sint8 iItemToProcessIndex = -1; Uint8 iRepairGUIInventoryIndex = 0; @@ -1734,7 +1863,7 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) { if ( iRepairGUIInventoryIndex == iItemToProcessIndex ) { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 ) + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) { messagePlayer(clientnum, language[2516], itemToProcess->description()); // "Oh no! Your %s was broken too!" } @@ -1752,8 +1881,30 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) break; default: printlog("ERROR: repairGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; } } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } } // repairGUIProcessRandomItem() /* ItemModifyingGUI.cpp @@ -1773,7 +1924,7 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() return; } - // Count the number of items in the Repair GUI Inventory + // Count the number of Items in the Repair GUI Inventory for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { Item* item = static_cast(iInventoryNode->element); @@ -1784,7 +1935,7 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() } // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) { continue; } @@ -1831,7 +1982,7 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() iRepairGUIInventoryIndex = 0; - // Assign the visible items to the GUI slots + // Assign the visible Items to the GUI slots bool bBreakFromLoop = false; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) { @@ -1843,7 +1994,7 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() } // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) { continue; } @@ -1961,7 +2112,7 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() } // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) == POTION || itemCategory(item) == SCROLL || itemCategory(item) == SPELLBOOK || itemCategory(item) == GEM || itemCategory(item) == THROWN || itemCategory(item) == FOOD || itemCategory(item) == BOOK || itemCategory(item) == SPELL_CAT ) + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) { continue; } @@ -2102,6 +2253,1227 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() // ENCHANT WEAPON GUI -// ENCHANT ARMOR GUI +/* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls can raise a +0 or +1 weapon up to +2. Cannot Enchant Artifacts + * +1 Scrolls can raise a +0, +1, or +2 weapon up to +3. Cannot Enchant Artifacts + * +2 Scrolls can raise a +0, +1, +2, +3, or +4 weapon up to +5. Raises any Artifact Weapon by one level + * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ +void ItemModifyingGUI::processEnchantWeaponGUIEffectOnItem(Item* const selectedItem) +{ + if ( selectedItem == nullptr ) + { + printlog("ERROR: processEnchantWeaponGUIEffectOnItem() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + ItemType itemType = WOODEN_SHIELD; + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Enchant the Item if it is a weapon +0 or +1 up to +2. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2520], selectedItem->description()); // "Your %s glows blue!" + selectedItem->beatitude = 2; + break; + case 1: + // Enchant the Item if it is a weapon +0, +1, or +2 up to +3. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2521], selectedItem->description()); // "Your %s violently glows blue!" + selectedItem->beatitude = 3; + break; + case 2: + // Enchant the Item if it is a weapon +0, +1, +2, +3, or +4 up to +5. Raises any Artifact Weapon by one level + messagePlayer(clientnum, language[2522], selectedItem->description()); // "Your %s radiates power!" + itemType = selectedItem->type; + if ( itemType == ARTIFACT_SWORD || itemType == ARTIFACT_MACE || itemType == ARTIFACT_SPEAR || itemType == ARTIFACT_AXE || itemType == ARTIFACT_BOW ) + { + selectedItem->beatitude++; + } + else + { + selectedItem->beatitude = 5; + } + break; + default: printlog("ERROR: processEnchantWeaponGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + closeItemModifyingGUI(); +} // processEnchantWeaponGUIEffectOnItem() + +/* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 + * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used + */ +void ItemModifyingGUI::enchantWeaponGUIProcessRandomItem(const Uint8 numItems) +{ + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: enchantWeaponGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0) // Skip over all Cursed and Unenchanted Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: enchantWeaponGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iEnchantWeaponGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iEnchantWeaponGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(itemToProcess) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + if ( iEnchantWeaponGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) + { + messagePlayer(clientnum, language[2523], itemToProcess->description()); // "Oh no! Your %s was disenchanted too!" + } + else + { + messagePlayer(clientnum, language[2509], itemToProcess->description()); // "Your %s was disenchanted!" + } + + itemToProcess->beatitude = 0; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iEnchantWeaponGUIInventoryIndex; + } + iEnchantWeaponGUIInventoryIndex++; + } + break; + default: printlog("ERROR: enchantWeaponGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } +} // enchantWeaponGUIProcessRandomItem() + +/* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ +void ItemModifyingGUI::rebuildEnchantWeaponGUIInventory() +{ + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iEnchantWeaponGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: rebuildEnchantWeaponGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the Repair GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantWeaponGUIInventoryIndex; + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + ++iEnchantWeaponGUIInventoryIndex; + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + ++iEnchantWeaponGUIInventoryIndex; + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon + { + ++iEnchantWeaponGUIInventoryIndex; + } + break; + default: printlog("ERROR: rebuildEnchantWeaponGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iEnchantWeaponGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iEnchantWeaponGUIInventoryIndex = 0; iEnchantWeaponGUIInventoryIndex < 4; ++iEnchantWeaponGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex] = nullptr; + } + + iEnchantWeaponGUIInventoryIndex = 0; + + // Assign the visible Items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon + { + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: rebuildEnchantWeaponGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } +} // rebuildEnchantWeaponGUIInventory() + +/* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ +void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() +{ + bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) + Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon + { + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: enchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } + } +} // enchantWeaponGUI_HandleItemImages() + +// ENCHANT ARMOR GUI + +/* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls can raise a +0 or +1 Shield, Breastpiece, or Helm up to +2. Cannot Enchant Artifacts + * +1 Scrolls can raise a +0, +1, or +2 Shield, Breastpiece, Helm, Boots, or Gloves up to +3. Cannot Enchant Artifacts + * +2 Scrolls can raise a +0, +1, +2, +3, or +4 Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks up to +5. Raises any Artifact Armor by one level + * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ +void ItemModifyingGUI::processEnchantArmorGUIEffectOnItem(Item* const selectedItem) +{ + if ( selectedItem == nullptr ) + { + printlog("ERROR: processEnchantArmorGUIEffectOnItem() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + ItemType itemType = WOODEN_SHIELD; + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Enchant the Item if it is a Shield, Breastpiece, or Helm +0 or +1 up to +2. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2520], selectedItem->description()); // "Your %s glows blue!" + selectedItem->beatitude = 2; + break; + case 1: + // Enchant the Item if it is a Shield, Breastpiece, Helm, Boots, or Gloves +0, +1, or +2 up to +3. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2521], selectedItem->description()); // "Your %s violently glows blue!" + selectedItem->beatitude = 3; + break; + case 2: + // Enchant the Item if it is a Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks +0, +1, +2, +3, or +4 up to +5. Raises any Artifact Armor by one level + messagePlayer(clientnum, language[2522], selectedItem->description()); // "Your %s radiates power!" + itemType = selectedItem->type; + if ( itemType == ARTIFACT_BREASTPIECE || itemType == ARTIFACT_HELM || itemType == ARTIFACT_BOOTS || itemType == ARTIFACT_CLOAK || itemType == ARTIFACT_GLOVES ) + { + selectedItem->beatitude++; + } + else + { + selectedItem->beatitude = 5; + } + break; + default: printlog("ERROR: processEnchantArmorGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + closeItemModifyingGUI(); +} // processEnchantArmorGUIEffectOnItem() + +/* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 + * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used + */ +void ItemModifyingGUI::enchantArmorGUIProcessRandomItem(const Uint8 numItems) +{ + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: enchantArmorGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: enchantArmorGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iEnchantArmorGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iEnchantArmorGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(itemToProcess->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + if ( iEnchantArmorGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) + { + messagePlayer(clientnum, language[2523], itemToProcess->description()); // "Oh no! Your %s was disenchanted too!" + } + else + { + messagePlayer(clientnum, language[2509], itemToProcess->description()); // "Your %s was disenchanted!" + } + + itemToProcess->beatitude = 0; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iEnchantArmorGUIInventoryIndex; + } + iEnchantArmorGUIInventoryIndex++; + } + break; + default: printlog("ERROR: enchantArmorGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } +} // enchantArmorGUIProcessRandomItem() + +/* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ +void ItemModifyingGUI::rebuildEnchantArmorGUIInventory() +{ + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iEnchantArmorGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: rebuildEnchantArmorGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the Repair GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantArmorGUIInventoryIndex; + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + // +0 can enchant Shields, Breastpiece, Masks, and Helms + if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + // +0 cannot enchant Artifacts + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves + if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + // +1 cannot enchant Artifacts + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor + { + // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks + ++iEnchantArmorGUIInventoryIndex; + } + break; + default: printlog("ERROR: rebuildEnchantArmorGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iEnchantArmorGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iEnchantArmorGUIInventoryIndex = 0; iEnchantArmorGUIInventoryIndex < 4; ++iEnchantArmorGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex] = nullptr; + } + + iEnchantArmorGUIInventoryIndex = 0; + + // Assign the visible Items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + // +0 can enchant Shields, Breastpiece, Masks, and Helms + if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves + if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor + { + // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: rebuildEnchantArmorGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } +} // rebuildEnchantArmorGUIInventory() + +/* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ +void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() +{ + bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) + Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + // +0 can enchant Shields, Breastpiece, Masks, and Helms + if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves + if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor + { + // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: enchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } + } +} // enchantArmorGUI_HandleItemImages() } // namespace GUI diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 9a4079bfe..26f61358b 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -143,7 +143,7 @@ class ItemModifyingGUI */ void processIdentifyGUIEffectOnItem(Item* const selectedItem); /* ItemModifyingGUI.cpp - * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used */ @@ -166,7 +166,7 @@ class ItemModifyingGUI */ void processRemoveCurseGUIEffectOnItem(Item* const selectedItem); /* ItemModifyingGUI.cpp - * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used */ @@ -192,8 +192,8 @@ class ItemModifyingGUI */ void processRepairGUIEffectOnItem(Item* const selectedItem); /* ItemModifyingGUI.cpp - * @param numItems - The number of random items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 - * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random items to Broken + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to Broken * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used */ void repairGUIProcessRandomItem(const Uint8 numItems); @@ -206,6 +206,58 @@ class ItemModifyingGUI * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ void repairGUI_HandleItemImages(); + + // Enchant Weapon GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls can raise a +0 or +1 weapon up to +2. Cannot Enchant Artifacts + * +1 Scrolls can raise a +0, +1, or +2 weapon up to +3. Cannot Enchant Artifacts + * +2 Scrolls can raise a +0, +1, +2, +3, or +4 weapon up to +5. Raises any Artifact Weapon by one level + * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ + void processEnchantWeaponGUIEffectOnItem(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 + * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used + */ + void enchantWeaponGUIProcessRandomItem(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ + void rebuildEnchantWeaponGUIInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ + void enchantWeaponGUI_HandleItemImages(); + + // Enchant Armor GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls can raise a +0 or +1 Shield, Breastpiece, or Helm up to +2. Cannot enchant Artifacts + * +1 Scrolls can raise a +0, +1, or +2 Shield, Breastpiece, Helm, Boots, or Gloves up to +3. Cannot enchant Artifacts + * +2 Scrolls can raise a +0, +1, +2, +3, or +4 Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks up to +5. Raises any Artifact Armor by one level + * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ + void processEnchantArmorGUIEffectOnItem(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 + * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used + */ + void enchantArmorGUIProcessRandomItem(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ + void rebuildEnchantArmorGUIInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ + void enchantArmorGUI_HandleItemImages(); }; // class ItemModifyingGUI } // namespace GUI \ No newline at end of file From 9fcb493b611a20ecf56d83369c4c05773386a92d Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 12:58:51 -0500 Subject: [PATCH 17/65] + Added the new lang entries for Enchant Scrolls --- lang/en.txt | 15 +++++++++++---- src/main.hpp | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lang/en.txt b/lang/en.txt index 41606d1b8..5470aef93 100644 --- a/lang/en.txt +++ b/lang/en.txt @@ -2976,14 +2976,21 @@ last of your magic is drained!# 2506 Your %s was unidentified!# 2507 Your %s was cursed!# 2508 Your %s is now broken!# -2509 Your %s was unenchanted!# +2509 Your %s was disenchanted!# 2510 You have no remaining items for the scroll's blessing...# 2511 Wow! Your %s was identified too!# 2512 Wow! Your %s was uncursed too!# -2513 You have no remaining items for the scroll's curse...# +2513 You have no items for the scroll's curse...# 2514 Oh no! Your %s was unidentified too!# 2515 Oh no! Your %s was cursed too!# 2516 Oh no! Your %s was broken too!# 2517 Your %s looks perfect now!# - -2518 end# +2518 Enchant a Weapon# +2519 Enchant an Armor Piece# +2520 Your %s glows blue!# +2521 Your %s glows violently blue!# +2522 Your %s radiates power!# +2523 Oh no! Your %s was disenchanted too!# +2524 You have no remaining items for the scroll's curse...# + +2525 end# diff --git a/src/main.hpp b/src/main.hpp index 01fdbb985..e90a8fa74 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -450,7 +450,7 @@ extern int minotaurlevel; #define DIRECTCLIENT 4 // language stuff -#define NUMLANGENTRIES 2519 +#define NUMLANGENTRIES 2526 extern char languageCode[32]; extern char** language; From 7f95817e468cdc4a061ea26c19b968a1b9349026 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:17:54 -0500 Subject: [PATCH 18/65] + Added checks for is player is blind, they cannot read scrolls --- src/items.cpp | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/items.cpp b/src/items.cpp index 54c958c74..c28e67b60 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -1443,7 +1443,14 @@ void useItem(Item* item, int player) item_ScrollMail(item, player); break; case SCROLL_IDENTIFY: - itemModifyingGUI->openItemModifyingGUI(0, item); + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(0, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } break; case SCROLL_LIGHT: item_ScrollLight(item, player); @@ -1456,21 +1463,34 @@ void useItem(Item* item, int player) item_ScrollBlank(item, player); break; case SCROLL_ENCHANTWEAPON: - item_ScrollEnchantWeapon(item, player); if ( !players[player]->entity->isBlind() ) { - consumeItem(item); + itemModifyingGUI->openItemModifyingGUI(3, item); } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } break; case SCROLL_ENCHANTARMOR: - item_ScrollEnchantArmor(item, player); if ( !players[player]->entity->isBlind() ) { - consumeItem(item); - } + itemModifyingGUI->openItemModifyingGUI(4, item); + } + else if(player == clientnum) + { + messagePlayer(player, language[775]); + } break; case SCROLL_REMOVECURSE: - itemModifyingGUI->openItemModifyingGUI(1, item); + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(1, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } break; case SCROLL_FIRE: item_ScrollFire(item, player); @@ -1494,7 +1514,14 @@ void useItem(Item* item, int player) } break; case SCROLL_REPAIR: - itemModifyingGUI->openItemModifyingGUI(2, item); + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(2, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } break; case SCROLL_DESTROYARMOR: item_ScrollDestroyArmor(item, player); @@ -1732,10 +1759,10 @@ Item* itemPickup(int player, Item* item) for ( node = stats[player]->inventory.first; node != NULL; node = node->next ) { item2 = (Item*) node->element; - if ( stats[player]->PROFICIENCIES[PRO_APPRAISAL] >= CAPSTONE_UNLOCK_LEVEL[PRO_APPRAISAL] ) - { - item->identified = true; - } + if ( stats[player]->PROFICIENCIES[PRO_APPRAISAL] >= CAPSTONE_UNLOCK_LEVEL[PRO_APPRAISAL] ) + { + item->identified = true; + } if (!itemCompare(item, item2)) { item2->count += item->count; From 40e3f2e549ecf31a75f426aa09102fb3205e29c8 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:18:32 -0500 Subject: [PATCH 19/65] - Removed a check for instant appraisal on item pickup, it is now handled by AppraisalGUI --- src/items.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/items.cpp b/src/items.cpp index c28e67b60..0b9bace2d 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -1759,10 +1759,6 @@ Item* itemPickup(int player, Item* item) for ( node = stats[player]->inventory.first; node != NULL; node = node->next ) { item2 = (Item*) node->element; - if ( stats[player]->PROFICIENCIES[PRO_APPRAISAL] >= CAPSTONE_UNLOCK_LEVEL[PRO_APPRAISAL] ) - { - item->identified = true; - } if (!itemCompare(item, item2)) { item2->count += item->count; From cc3759a6cee0d9bfaf7090ec0c4d6e5c8ed46a31 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:20:21 -0500 Subject: [PATCH 20/65] + Added enum 'ItemArmorType' and its getter function --- src/items.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/items.hpp | 18 ++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/items.cpp b/src/items.cpp index 0b9bace2d..204170f7f 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -543,6 +543,58 @@ Category itemCategory(const Item* item) return items[item->type].category; } +/* items.cpp + * @param itemType - A reference to the ItemType being evaluated + * @returns ItemArmorType - The specific ItemArmorType that the Item falls under + * @returns ItemArmorType::NOT_ARMOR - If the Item is not a type of Armor + * Used to return the type of Armor, for networked updates and Enchant Armor Scrolls + */ +ItemArmorType getItemArmorType(const ItemType& itemType) +{ + // TODOR: This is a fix until Entities get refactored and Items become a separate thing. Then it'll be easy to just tag it as armor or not + + if ( itemType == WOODEN_SHIELD || itemType == IRON_SHIELD || itemType == STEEL_SHIELD || itemType == STEEL_SHIELD_RESISTANCE || itemType == CRYSTAL_SHIELD || itemType == MIRROR_SHIELD ) + { // Shields + return ItemArmorType::SHIELD; + } + else if ( itemType == HEALER_DOUBLET || itemType == WIZARD_DOUBLET || itemType == VAMPIRE_DOUBLET || itemType == LEATHER_BREASTPIECE || itemType == IRON_BREASTPIECE || itemType == STEEL_BREASTPIECE || itemType == CRYSTAL_BREASTPIECE || itemType == ARTIFACT_BREASTPIECE ) + { // Breastpieces + return ItemArmorType::BREASTPIECE; + } + else if ( itemType == TOOL_GLASSES || itemType == TOOL_BLINDFOLD || itemType == TOOL_BLINDFOLD_FOCUS || itemType == TOOL_BLINDFOLD_TELEPATHY ) + { // Masks + return ItemArmorType::MASK; + } + else if ( itemType == HAT_PHRYGIAN || itemType == HAT_HOOD || itemType == HAT_WIZARD || itemType == HAT_JESTER || itemType == LEATHER_HELM || itemType == STEEL_HELM || itemType == CRYSTAL_HELM || itemType == ARTIFACT_HELM ) + { // Helms + return ItemArmorType::HELM; + } + else if ( itemType == LEATHER_BOOTS || itemType == LEATHER_BOOTS_SPEED || itemType == IRON_BOOTS || itemType == IRON_BOOTS_WATERWALKING || itemType == STEEL_BOOTS || itemType == STEEL_BOOTS_FEATHER || itemType == STEEL_BOOTS_LEVITATION || itemType == CRYSTAL_BOOTS || itemType == ARTIFACT_BOOTS ) + { // Boots + return ItemArmorType::BOOTS; + } + else if ( itemType == GLOVES || itemType == GLOVES_DEXTERITY || itemType == BRASS_KNUCKLES || itemType == BRACERS || itemType == BRACERS_CONSTITUTION || itemType == IRON_KNUCKLES || itemType == GAUNTLETS || itemType == GAUNTLETS_STRENGTH || itemType == SPIKED_GAUNTLETS || itemType == CRYSTAL_GLOVES || itemType == ARTIFACT_GLOVES ) + { // Gloves + return ItemArmorType::GLOVES; + } + else if ( itemType == RING_ADORNMENT || itemType == RING_SLOWDIGESTION || itemType == RING_PROTECTION || itemType == RING_WARNING || itemType == RING_STRENGTH || itemType == RING_CONSTITUTION || itemType == RING_INVISIBILITY || itemType == RING_MAGICRESISTANCE || itemType == RING_CONFLICT || itemType == RING_LEVITATION || itemType == RING_REGENERATION || itemType == RING_TELEPORTATION ) + { // Rings + return ItemArmorType::RING; + } + else if ( itemType == AMULET_SEXCHANGE || itemType == AMULET_LIFESAVING || itemType == AMULET_WATERBREATHING || itemType == AMULET_MAGICREFLECTION || itemType == AMULET_STRANGULATION || itemType == AMULET_WATERBREATHING ) + { // Amulets + return ItemArmorType::AMULET; + } + else if ( itemType == CLOAK || itemType == CLOAK_BLACK || itemType == CLOAK_MAGICREFLECTION || itemType == CLOAK_INVISIBILITY || itemType == CLOAK_PROTECTION || itemType == ARTIFACT_CLOAK ) + { // Cloaks + return ItemArmorType::CLOAK; + } + else + { + return ItemArmorType::NOT_ARMOR; + } +} + /*------------------------------------------------------------------------------- Item::getName diff --git a/src/items.hpp b/src/items.hpp index 9e0633a98..397dc1373 100644 --- a/src/items.hpp +++ b/src/items.hpp @@ -253,6 +253,23 @@ typedef enum Category SPELL_CAT } Category; +/* items.hpp + * The type of Armor that the Item is. Returned by getItemArmorType() + */ +typedef enum class ItemArmorType +{ + NOT_ARMOR, + SHIELD, + BREASTPIECE, + MASK, + HELM, + BOOTS, + GLOVES, + RING, + AMULET, + CLOAK +} ItemArmorType; + typedef enum Status { BROKEN, @@ -408,6 +425,7 @@ Entity* dropItemMonster(Item* item, Entity* monster, Stat* monsterStats); Item** itemSlot(Stat* myStats, Item* item); enum Category itemCategory(const Item* item); +ItemArmorType getItemArmorType(const ItemType& itemType); Sint32 itemModel(Item* item); Sint32 itemModelFirstperson(Item* item); SDL_Surface* itemSprite(Item* item); From 7e439ce491094fe79e9172772074f14a47bda57b Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:22:49 -0500 Subject: [PATCH 21/65] - Removed the now deprecated Enchant Weapon and Armor Scrolls functions --- src/item_usage_funcs.cpp | 152 --------------------------------------- 1 file changed, 152 deletions(-) diff --git a/src/item_usage_funcs.cpp b/src/item_usage_funcs.cpp index 7dc3dda9a..beb2a0dff 100644 --- a/src/item_usage_funcs.cpp +++ b/src/item_usage_funcs.cpp @@ -1125,158 +1125,6 @@ void item_ScrollBlank(Item* item, int player) messagePlayer(player, language[852]); } -void item_ScrollEnchantWeapon(Item* item, int player) -{ - if (players[player] == nullptr || players[player]->entity == nullptr) - { - return; - } - - if (players[player]->entity->isBlind()) - { - if (player == clientnum) - { - messagePlayer(player, language[775]); - } - return; - } - - if (player == clientnum) - { - conductIlliterate = false; - } - item->identified = 1; - if (player == clientnum) - { - messagePlayer(player, language[848]); - } - - if (stats[player]->weapon == nullptr) - { - if (player == clientnum) - { - messagePlayer(player, language[853]); - } - } - else - { - if (item->beatitude < 0) - { - if (player == clientnum) - { - messagePlayer(player, language[854]); - } - stats[player]->weapon->beatitude -= 1; - } - else - { - if (player == clientnum) - { - if (item->beatitude == 0) - { - messagePlayer(player, language[855]); - } - else - { - messagePlayer(player, language[856]); - } - } - stats[player]->weapon->beatitude += 1 + item->beatitude; - } - } -} - -void item_ScrollEnchantArmor(Item* item, int player) -{ - Item* armor; - if (players[player] == nullptr || players[player]->entity == nullptr) - { - return; - } - - if (players[player]->entity->isBlind()) - { - if (player == clientnum) - { - messagePlayer(player, language[775]); - } - return; - } - - if (player == clientnum) - { - conductIlliterate = false; - } - item->identified = 1; - if (player == clientnum) - { - messagePlayer(player, language[848]); - } - - if (stats[player]->helmet != nullptr) - { - armor = stats[player]->helmet; - } - else if (stats[player]->breastplate != nullptr) - { - armor = stats[player]->breastplate; - } - else if (stats[player]->gloves != nullptr) - { - armor = stats[player]->gloves; - } - else if (stats[player]->shoes != nullptr) - { - armor = stats[player]->shoes; - } - else if (stats[player]->shield != nullptr) - { - armor = stats[player]->shield; - } - else if (stats[player]->cloak != nullptr) - { - armor = stats[player]->cloak; - } - else - { - armor = nullptr; - } - - if (armor == nullptr) - { - if (player == clientnum) - { - messagePlayer(player, language[857]); - } - } - else - { - if (item->beatitude < 0) - { - if (player == clientnum) - { - messagePlayer(player, language[858], armor->getName()); - } - armor->beatitude -= 1; - } - else - { - if (player == clientnum) - { - if (item->beatitude == 0) - { - messagePlayer(player, language[859], armor->getName()); - } - else - { - messagePlayer(player, language[860], armor->getName()); - } - } - armor->beatitude += 1 + item->beatitude; - } - } -} - void item_ScrollFire(Item* item, int player) { if (multiplayer == CLIENT) From 2264446b1f4c52b76012e662e894c3825774bc86 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:25:49 -0500 Subject: [PATCH 22/65] + Added braces to if statements --- src/interface/clickdescription.cpp | 48 +++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/interface/clickdescription.cpp b/src/interface/clickdescription.cpp index 6cb18ec5a..e903aeb9c 100644 --- a/src/interface/clickdescription.cpp +++ b/src/interface/clickdescription.cpp @@ -44,28 +44,36 @@ void clickDescription(int player, Entity* entity) { return; } - if (openedChest[clientnum]) - if (omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h) - { - return; //Click falls inside the chest inventory GUI. - } - if (identifygui_active) - if (omousex > IDENTIFY_GUI_X && omousex < IDENTIFY_GUI_X + identifyGUI_img->w && omousey > IDENTIFY_GUI_Y && omousey < IDENTIFY_GUI_Y + identifyGUI_img->h) - { - return; //Click falls inside the identify item gui. - } - if (book_open) - if (mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h)) - { - return; //Click falls inside the book GUI. - } + if ( openedChest[clientnum] ) + { + if ( omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h ) + { + return; //Click falls inside the chest inventory GUI. + } + } + if ( identifygui_active ) + { + if ( omousex > IDENTIFY_GUI_X && omousex < IDENTIFY_GUI_X + identifyGUI_img->w && omousey > IDENTIFY_GUI_Y && omousey < IDENTIFY_GUI_Y + identifyGUI_img->h ) + { + return; //Click falls inside the identify item gui. + } + } + if ( book_open ) + { + if ( mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h) ) + { + return; //Click falls inside the book GUI. + } + } if (gui_mode == GUI_MODE_INVENTORY || gui_mode == GUI_MODE_SHOP) { - if ( gui_mode == GUI_MODE_INVENTORY ) - if (mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height)) - { - return; //Click falls inside the right sidebar. - } + if ( gui_mode == GUI_MODE_INVENTORY ) + { + if ( mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height) ) + { + return; //Click falls inside the right sidebar. + } + } //int x = std::max(character_bmp->w, xres/2-inventory_bmp->w/2); //if (mouseInBounds(x,x+inventory_bmp->w,0,inventory_bmp->h)) //return NULL; From f3586bda695b0944b2f50d19bbf9858e73141f1d Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:34:05 -0500 Subject: [PATCH 23/65] * Replaced any instance of 'inventoryChest_bmp' with 'itemModifyingGUI_IMG' --- src/interface/ItemModifyingGUI.cpp | 144 ++++++++++++++--------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index fc0770a63..032ab956c 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -169,8 +169,8 @@ void ItemModifyingGUI::updateItemModifyingGUI() SDL_Rect GUIRect; // The location of the GUI window // Draw the GUI Background at the center off the Game Window - GUIRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); - GUIRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + GUIRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + GUIRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); drawImage(itemModifyingGUI_IMG, nullptr, &GUIRect); // Setup the collision bounds for the GUI buttons @@ -186,15 +186,15 @@ void ItemModifyingGUI::updateItemModifyingGUI() char* windowName; windowName = language[2499]; // "Repair an Item" - const Sint32 windowLabelX = ((((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 2 + ((itemModifyingGUI_IMG->w / 2) - ((TTF8_WIDTH * longestline(windowName)) / 2))); - const Sint32 windowLabelY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 4; + const Sint32 windowLabelX = ((((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 2 + ((itemModifyingGUI_IMG->w / 2) - ((TTF8_WIDTH * longestline(windowName)) / 2))); + const Sint32 windowLabelY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 4; // Print the Window Label ttfPrintText(ttf8, windowLabelX, windowLabelY, windowName); // The GUI Window's position after being offset - const Sint32 GUIOffsetPosX = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); - const Sint32 GUIOffsetPosY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 GUIOffsetPosX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 GUIOffsetPosY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); // Draw the Images for the GUI buttons when they are being clicked itemModifyingGUI_HandleButtonImages(GUIOffsetPosX, GUIOffsetPosY); @@ -529,10 +529,10 @@ void ItemModifyingGUI::rebuildItemModifyingGUIInventory() void ItemModifyingGUI::warpMouseToSelectedGUISlot() { SDL_Rect slotPos; - slotPos.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + slotPos.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); slotPos.w = inventoryoptionChest_bmp->w; slotPos.h = inventoryoptionChest_bmp->h; - slotPos.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16 + (slotPos.h * itemModifyingGUI_InventorySelectedSlot); + slotPos.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16 + (slotPos.h * itemModifyingGUI_InventorySelectedSlot); SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); } // warpMouseToSelectedGUISlot() @@ -547,29 +547,29 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtons() { // GUI Button Collision Bounds TODOR: I may have these swapped, the lower bound may be the upper bound // Scroll Up Button Y - const Sint32 scrollUpButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; - const Sint32 scrollUpButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; + const Sint32 scrollUpButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16; + const Sint32 scrollUpButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 52; // Scroll Up Button X - const Sint32 scrollUpButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); - const Sint32 scrollUpButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + const Sint32 scrollUpButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + const Sint32 scrollUpButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); // Scroll Down Button Y - const Sint32 scrollDownButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 52; - const Sint32 scrollDownButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 88; + const Sint32 scrollDownButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 52; + const Sint32 scrollDownButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 88; // Scroll Down Button X - const Sint32 scrollDownButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); - const Sint32 scrollDownButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + const Sint32 scrollDownButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + const Sint32 scrollDownButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); // Close Button Y - const Sint32 closeButtonY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); - const Sint32 closeButtonY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; + const Sint32 closeButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 closeButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 15; // Close Button X - const Sint32 closeButtonX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 393; - const Sint32 closeButtonX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 407; + const Sint32 closeButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 393; + const Sint32 closeButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 407; // Dragging Bar Y - const Sint32 draggingBarY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); - const Sint32 draggingBarY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 15; + const Sint32 draggingBarY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 draggingBarY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 15; // Dragging Bar X - const Sint32 draggingBarX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); - const Sint32 draggingBarX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 377; + const Sint32 draggingBarX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 draggingBarX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 377; // Buttons if ( mousestatus[SDL_BUTTON_LEFT] ) @@ -614,8 +614,8 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtons() { gui_clickdrag = true; bIsItemModifyingGUI_Dragging = true; - dragoffset_x = omousex - (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); - dragoffset_y = omousey - (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); + dragoffset_x = omousex - (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + dragoffset_y = omousey - (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); mousestatus[SDL_BUTTON_LEFT] = 0; } } @@ -629,11 +629,11 @@ void ItemModifyingGUI::itemModifyingGUI_HandleMouseWheel() { // GUI Mouse Wheel Collision Bounds // Mouse Wheel Y - const Sint32 mouseWheelY_LowerBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 16; - const Sint32 mouseWheelY_UpperBound = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + (itemModifyingGUI_IMG->h - 8); + const Sint32 mouseWheelY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16; + const Sint32 mouseWheelY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + (itemModifyingGUI_IMG->h - 8); // Mouse Wheel X - const Sint32 mouseWheelX_LowerBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 12; - const Sint32 mouseWheelX_UpperBound = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + const Sint32 mouseWheelX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 12; + const Sint32 mouseWheelX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); // Mouse wheel if ( omousex >= mouseWheelX_LowerBound && omousex < mouseWheelX_UpperBound ) @@ -664,11 +664,11 @@ void ItemModifyingGUI::itemModifyingGUI_HandleDraggingBar() { // GUI Dragging // The GUI Window's centered position in the Game Window - Sint32 GUICenterPosY = ((yres / 2) - (inventoryChest_bmp->h / 2)); - Sint32 GUICenterPosX = ((xres / 2) - (inventoryChest_bmp->w / 2)); + Sint32 GUICenterPosY = ((yres / 2) - (itemModifyingGUI_IMG->h / 2)); + Sint32 GUICenterPosX = ((xres / 2) - (itemModifyingGUI_IMG->w / 2)); // The GUI Window's position after being offset - Sint32 GUIOffsetPosY = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY); - Sint32 GUIOffsetPosX = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX); + Sint32 GUIOffsetPosY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + Sint32 GUIOffsetPosX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); // Dragging the Window if ( bIsItemModifyingGUI_Dragging == true) @@ -1120,7 +1120,7 @@ void ItemModifyingGUI::rebuildIdentifyGUIInventory() void ItemModifyingGUI::identifyGUI_HandleItemImages() { Uint8 iIdentifyGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iIdentifyGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + Sint32 iIdentifyGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory @@ -1161,11 +1161,11 @@ void ItemModifyingGUI::identifyGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iIdentifyGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iIdentifyGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -1586,7 +1586,7 @@ void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() void ItemModifyingGUI::removeCurseGUI_HandleItemImages() { Uint8 iRemoveCurseGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iRemoveCurseGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + Sint32 iRemoveCurseGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory @@ -1627,11 +1627,11 @@ void ItemModifyingGUI::removeCurseGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRemoveCurseGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRemoveCurseGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -2092,7 +2092,7 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() { bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) Uint8 iRepairGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iRepairGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + Sint32 iRepairGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory @@ -2142,11 +2142,11 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -2182,11 +2182,11 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -2222,11 +2222,11 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -2668,7 +2668,7 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() { bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory @@ -2723,11 +2723,11 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -2768,11 +2768,11 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -2808,11 +2808,11 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -3292,7 +3292,7 @@ void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() { bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory @@ -3355,11 +3355,11 @@ void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -3406,11 +3406,11 @@ void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); @@ -3447,11 +3447,11 @@ void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() } // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (inventoryChest_bmp->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (inventoryChest_bmp->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); itemImageRect.w = 16; itemImageRect.h = 16; drawImageScaled(itemSprite(item), nullptr, &itemImageRect); From 9a6dafea0c018ac0c4b90e35466fe7bd4e3e23d4 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:43:51 -0500 Subject: [PATCH 24/65] + Added function isMouseWithinGUIBounds() --- src/interface/ItemModifyingGUI.cpp | 21 ++++++++++++++++++++- src/interface/ItemModifyingGUI.hpp | 6 ++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index 032ab956c..9b6b74552 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -168,7 +168,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() SDL_Rect GUIRect; // The location of the GUI window - // Draw the GUI Background at the center off the Game Window + // Draw the GUI Background at the center of the Game Window + it's offset GUIRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); GUIRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); drawImage(itemModifyingGUI_IMG, nullptr, &GUIRect); @@ -414,6 +414,25 @@ bool ItemModifyingGUI::isSelectedSlotInvalid() const return (itemModifyingGUI_InventorySelectedSlot < 0); } +/* ItemModifyingGUI.cpp + * @returns true - If the Mouse is currently within the bounds of the GUI + * @returns false - If the Mouse is not within the bounds of the GUI + * Returns whether or not the Mouse is currently within the bounds of the ItemModifyingGUI + */ +bool ItemModifyingGUI::isMouseWithinGUIBounds() const +{ + // Draw the GUI Background at the center of the Game Window + it's offset + const Sint32 GUIX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 GUIY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + + if ( ((omousex > GUIX) && (omousex < GUIX + itemModifyingGUI_IMG->w)) && ((omousey > GUIY) && (omousey < GUIY + itemModifyingGUI_IMG->h))) + { + return true; + } + + return false; +} // isMouseWithinGUIBounds() + /* ItemModifyingGUI.cpp * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] * @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 26f61358b..f99f4bac7 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -65,6 +65,12 @@ class ItemModifyingGUI * Returns whether or not the mouse is currently hovering over a GUI Inventory Slot */ bool isSelectedSlotInvalid() const; + /* ItemModifyingGUI.cpp + * @returns true - If the Mouse is currently within the bounds of the GUI + * @returns false - If the Mouse is not within the bounds of the GUI + * Returns whether or not the Mouse is currently within the bounds of the ItemModifyingGUI + */ + bool isMouseWithinGUIBounds() const; private: // ItemModifying GUI From 2f4d43fa261bc24aa877ff702df1b3d0a6fecfbb Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:45:37 -0500 Subject: [PATCH 25/65] * Changed click check to handle itemModifyingGUI --- src/interface/clickdescription.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interface/clickdescription.cpp b/src/interface/clickdescription.cpp index e903aeb9c..7490a99bf 100644 --- a/src/interface/clickdescription.cpp +++ b/src/interface/clickdescription.cpp @@ -51,11 +51,11 @@ void clickDescription(int player, Entity* entity) return; //Click falls inside the chest inventory GUI. } } - if ( identifygui_active ) + if ( itemModifyingGUI->isActive() == true ) { - if ( omousex > IDENTIFY_GUI_X && omousex < IDENTIFY_GUI_X + identifyGUI_img->w && omousey > IDENTIFY_GUI_Y && omousey < IDENTIFY_GUI_Y + identifyGUI_img->h ) + if ( itemModifyingGUI->isMouseWithinGUIBounds() == true ) { - return; //Click falls inside the identify item gui. + return; // Click falls within the itemModifyingGUI's bounds } } if ( book_open ) From 317e8b0fe9d700787fb0e6339f7f6c899f326c63 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:48:26 -0500 Subject: [PATCH 26/65] * Refactored opening of chest to handle ItemModifyingGUI --- src/actchest.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/actchest.cpp b/src/actchest.cpp index ab2d53b98..32712d376 100644 --- a/src/actchest.cpp +++ b/src/actchest.cpp @@ -494,11 +494,13 @@ void Entity::actChest() messagePlayer(chestclicked, language[459]); chestOpener = chestclicked; openedChest[chestclicked] = this; - if ( removecursegui_active ) - { - closeRemoveCurseGUI(); - } - identifygui_active = false; + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->isActive() == true ) + { + itemModifyingGUI->closeItemModifyingGUI(); + } + if (chestclicked != 0 && multiplayer == SERVER) { //Send all of the items to the client. From 5ef0fba2170078941d9763f53de1368b454fa834 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:50:41 -0500 Subject: [PATCH 27/65] * Refactored entityClicked() to handle ItemModifyingGUI --- src/collision.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/collision.cpp b/src/collision.cpp index fd6eb0db8..095306250 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -74,11 +74,13 @@ Entity* entityClicked() { return NULL; //Click falls inside the chest inventory GUI. } - if (identifygui_active) - if (omousex > IDENTIFY_GUI_X && omousex < IDENTIFY_GUI_X + identifyGUI_img->w && omousey > IDENTIFY_GUI_Y && omousey < IDENTIFY_GUI_Y + identifyGUI_img->h) - { - return NULL; //Click falls inside the identify item gui. - } + if ( itemModifyingGUI->isActive() == true ) + { + if ( itemModifyingGUI->isMouseWithinGUIBounds() == true ) + { + return nullptr; // Click falls within the itemModifyingGUI's bounds + } + } if (book_open) if (mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h)) { From f697335b61eb8ecff3d82d75788b33fb455d853c Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:52:39 -0500 Subject: [PATCH 28/65] * Style Guidelines cleanup --- src/collision.cpp | 56 ++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/collision.cpp b/src/collision.cpp index 095306250..826005ca8 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -57,23 +57,25 @@ Entity* entityClicked() if ( !(*inputPressed(impulses[IN_USE])) && !(*inputPressed(joyimpulses[INJOY_GAME_USE])) ) { - return NULL; + return nullptr; } if ( !shootmode ) { if ( itemMenuOpen ) { - return NULL; + return nullptr; } if ( omousex < camera.winx || omousex >= camera.winx + camera.winw || omousey < camera.winy || omousey >= camera.winy + camera.winh ) { - return NULL; + return nullptr; } - if (openedChest[clientnum]) - if (omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h) - { - return NULL; //Click falls inside the chest inventory GUI. - } + if ( openedChest[clientnum] ) + { + if ( omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h ) + { + return nullptr; //Click falls inside the chest inventory GUI. + } + } if ( itemModifyingGUI->isActive() == true ) { if ( itemModifyingGUI->isMouseWithinGUIBounds() == true ) @@ -81,25 +83,29 @@ Entity* entityClicked() return nullptr; // Click falls within the itemModifyingGUI's bounds } } - if (book_open) - if (mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h)) - { - return NULL; //Click falls inside the book GUI. - } + if ( book_open ) + { + if ( mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h) ) + { + return nullptr; //Click falls inside the book GUI. + } + } if (gui_mode == GUI_MODE_INVENTORY || gui_mode == GUI_MODE_SHOP) { - if ( gui_mode == GUI_MODE_INVENTORY ) - if (mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height)) - { - return NULL; //Click falls inside the right sidebar. - } + if ( gui_mode == GUI_MODE_INVENTORY ) + { + if ( mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height) ) + { + return nullptr; //Click falls inside the right sidebar. + } + } //int x = std::max(character_bmp->w, xres/2-inventory_bmp->w/2); //if (mouseInBounds(x,x+inventory_bmp->w,0,inventory_bmp->h)) //return NULL; if ( mouseInBounds(INVENTORY_STARTX, INVENTORY_STARTX + INVENTORY_SIZEX * INVENTORY_SLOTSIZE, INVENTORY_STARTY, INVENTORY_STARTY + INVENTORY_SIZEY * INVENTORY_SLOTSIZE) ) { // clicked in inventory - return NULL; + return nullptr; } if ( gui_mode == GUI_MODE_SHOP ) { @@ -107,7 +113,7 @@ Entity* entityClicked() int y1 = yres / 2 - SHOPWINDOW_SIZEY / 2, y2 = yres / 2 + SHOPWINDOW_SIZEY / 2; if (mouseInBounds(x1, x2, y1, y2)) { - return NULL; + return nullptr; } } } @@ -119,7 +125,7 @@ Entity* entityClicked() int height = spell_list_titlebar_bmp->h; int numspells = 0; node_t* node; - for (node = spellList.first; node != NULL; node = node->next) + for (node = spellList.first; node != nullptr; node = node->next) { numspells++; } @@ -130,18 +136,18 @@ Entity* entityClicked() if (mouseInBounds(MAGICSPELL_LIST_X, MAGICSPELL_LIST_X + spell_list_titlebar_bmp->w, spelllist_y, spelllist_y + height)) { - return NULL; + return nullptr; } } } if (mouseInBounds(0, 224, 0, 420)) // character sheet { - return NULL; + return nullptr; } int x = xres / 2 - (status_bmp->w / 2); if (mouseInBounds(x, x + status_bmp->w, yres - status_bmp->h, yres)) { - return NULL; + return nullptr; } *inputPressed(impulses[IN_USE]) = 0; *inputPressed(joyimpulses[INJOY_GAME_USE]) = 0; @@ -175,7 +181,7 @@ Entity* entityClicked() } else { - return NULL; + return nullptr; } } From 0318ad45d248a6dc9a04bb9ba28da6371f8c8904 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:54:45 -0500 Subject: [PATCH 29/65] * Refactored open shop menu to handle itemModifyingGUI --- src/shops.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/shops.cpp b/src/shops.cpp index d4dd86339..85007713e 100644 --- a/src/shops.cpp +++ b/src/shops.cpp @@ -76,8 +76,12 @@ void startTradingServer(Entity* entity, int player) shopkeepertype = entity->skill[18]; shopkeepername = stats->name; shopitemscroll = 0; - identifygui_active = false; - closeRemoveCurseGUI(); + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->isActive() == true ) + { + itemModifyingGUI->closeItemModifyingGUI(); + } //Initialize shop gamepad code here. if ( shopinvitems[0] != nullptr ) From d51ace174ede31113861be33a89fd60701c69bf7 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:58:13 -0500 Subject: [PATCH 30/65] - Removed deprecated handleIdentifyMovement() and handleRemoveCurseMovement() --- src/player.cpp | 72 -------------------------------------------------- src/player.hpp | 12 --------- 2 files changed, 84 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 341da8f8c..72a3e16b7 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -666,78 +666,6 @@ bool GameController::handleShopMovement() return false; } -bool GameController::handleIdentifyMovement() -{ - bool dpad_moved = false; - - if ( itemMenuOpen ) - { - return false; - } - - if (*inputPressed(joyimpulses[INJOY_DPAD_UP])) - { - selectIdentifySlot(selectedIdentifySlot - 1); - *inputPressed(joyimpulses[INJOY_DPAD_UP]) = 0; - - dpad_moved = true; - } - - if (*inputPressed(joyimpulses[INJOY_DPAD_DOWN])) - { - selectIdentifySlot(selectedIdentifySlot + 1); - *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) = 0; - - dpad_moved = true; - } - - if (dpad_moved) - { - dpad_moved = false; - draw_cursor = false; - - return true; - } - - return false; -} - -bool GameController::handleRemoveCurseMovement() -{ - bool dpad_moved = false; - - if ( itemMenuOpen ) - { - return false; - } - - if (*inputPressed(joyimpulses[INJOY_DPAD_UP])) - { - selectRemoveCurseSlot(selectedRemoveCurseSlot - 1); - *inputPressed(joyimpulses[INJOY_DPAD_UP]) = 0; - - dpad_moved = true; - } - - if (*inputPressed(joyimpulses[INJOY_DPAD_DOWN])) - { - selectRemoveCurseSlot(selectedRemoveCurseSlot + 1); - *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) = 0; - - dpad_moved = true; - } - - if (dpad_moved) - { - dpad_moved = false; - draw_cursor = false; - - return true; - } - - return false; -} - bool GameController::handleItemContextMenu(const Item& item) { bool dpad_moved = false; diff --git a/src/player.hpp b/src/player.hpp index cbcd7214f..9a5057166 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -138,18 +138,6 @@ class GameController */ bool handleShopMovement(); - /* - * Uses dpad to move the cursor around Identify GUI's inventory and select items. - * Returns true if moved. - */ - bool handleIdentifyMovement(); - - /* - * Uses dpad to move the cursor around Remove Curse GUI's inventory and select items. - * Returns true if moved. - */ - bool handleRemoveCurseMovement(); - /* * Uses dpad to move the cursor through the item context menu and select entries. * Returns true if moved. From b63b2459753609a29a81f2fbe224efa4d8e5d051 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 13:59:50 -0500 Subject: [PATCH 31/65] + Added handleItemModifyingGUIMovement() --- src/player.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/player.hpp | 8 ++++++++ 2 files changed, 51 insertions(+) diff --git a/src/player.cpp b/src/player.cpp index 72a3e16b7..65e0d3893 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -666,6 +666,49 @@ bool GameController::handleShopMovement() return false; } +/* player.cpp + * @returns true - If the cursor has been moved using the D-Pad + * @returns false - If the cursor has not been moved or 'itemMenuOpen' == true + * The cursor has been moved if '*joyimpulses[INJOY_DPAD_UP]' or '*joyimpulses[INJOY_DPAD_DOWN]' is true + * If the cursor has been moved, itemModifyingGUI->gamepadMoveCursor() will be called. 'draw_cursor' will be set to false as well + */ +bool GameController::handleItemModifyingGUIMovement() +{ + if ( itemMenuOpen == true ) + { + return false; + } + + bool wasDPadPressed = false; + Sint8 direction = 0; + + // If the User has pressed Up or Down on the D-Pad, move the mouse to the new slot + if ( *inputPressed(joyimpulses[INJOY_DPAD_UP]) ) + { + *inputPressed(joyimpulses[INJOY_DPAD_UP]) = 0; + direction = -1; + wasDPadPressed = true; + } + else if ( *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) ) + { + *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) = 0; + direction = 1; + wasDPadPressed = true; + } + + if ( wasDPadPressed == true ) + { + // Move the cursor to the new slot position + itemModifyingGUI->gamepadMoveCursor(direction); + + //draw_cursor = false; TODOR: Ask why this matters + + return true; + } + + return false; +} + bool GameController::handleItemContextMenu(const Item& item) { bool dpad_moved = false; diff --git a/src/player.hpp b/src/player.hpp index 9a5057166..f0e94e702 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -138,6 +138,14 @@ class GameController */ bool handleShopMovement(); + /* player.cpp + * @returns true - If the cursor has been moved using the D-Pad + * @returns false - If the cursor has not been moved or 'itemMenuOpen' == true + * The cursor has been moved if '*joyimpulses[INJOY_DPAD_UP]' or '*joyimpulses[INJOY_DPAD_DOWN]' is true + * If the cursor has been moved, itemModifyingGUI->gamepadMoveCursor() will be called. 'dpad_moved' and 'draw_cursor' will both be set to false as well + */ + bool handleItemModifyingGUIMovement(); + /* * Uses dpad to move the cursor through the item context menu and select entries. * Returns true if moved. From 2f7e0dfdb49fbc6fb8c16783f04adb8cc0ce9c6b Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 14:00:47 -0500 Subject: [PATCH 32/65] + Added initialization and cleanup of AppraisalGUI object --- src/init_game.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/init_game.cpp b/src/init_game.cpp index 6c43420df..72e15b15d 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -494,6 +494,7 @@ int fmod_result; } itemModifyingGUI = new GUI::ItemModifyingGUI; + appraisalGUI = new GUI::AppraisalGUI; return 0; } @@ -836,4 +837,7 @@ void deinitGame() // 9-5-2017 - Lutz - ItemModifyingGUI Refactor delete itemModifyingGUI; itemModifyingGUI = nullptr; + + delete appraisalGUI; + appraisalGUI = nullptr; } From fa88a8df2e73d900317a094f3639026c038c0ce3 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 14:04:04 -0500 Subject: [PATCH 33/65] * Refactored client opening chest and shop to handle ItemModifyingGUI --- src/net.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 9ff24af91..a3271b153 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1519,8 +1519,12 @@ void clientHandlePacket() shopinventorycategory = 7; sellitem = NULL; shopitemscroll = 0; - identifygui_active = false; //Really need a centralized function to open up whatever screen/inventory. - closeRemoveCurseGUI(); + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->isActive() == true ) + { + itemModifyingGUI->closeItemModifyingGUI(); + } //Initialize shop gamepad code here. if ( shopinvitems[0] != nullptr ) @@ -2336,11 +2340,13 @@ void clientHandlePacket() if (entity2->getUID() == i) { openedChest[clientnum] = entity2; //Set the opened chest to this. - if ( removecursegui_active ) - { - closeRemoveCurseGUI(); - } - identifygui_active = false; + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->isActive() == true ) + { + itemModifyingGUI->closeItemModifyingGUI(); + } + list_FreeAll(&chestInv); chestInv.first = nullptr; chestInv.last = nullptr; @@ -2403,8 +2409,8 @@ void clientHandlePacket() openedChest[clientnum]->closeChest(); } - //Initialize Identify GUI game controller code here. - initIdentifyGUIControllerCode(); + //Initialize Identify GUI game controller code here. + initIdentifyGUIControllerCode(); return; } From 2eccaeecdcbc01d2d9c1a2ea6423115781d3dfac Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 14:34:37 -0500 Subject: [PATCH 34/65] * Refactored drawStatus() to handle ItemModifyingGUI and AppraisalGUI --- src/interface/drawstatus.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/interface/drawstatus.cpp b/src/interface/drawstatus.cpp index f20d5b088..34928ebd3 100644 --- a/src/interface/drawstatus.cpp +++ b/src/interface/drawstatus.cpp @@ -538,7 +538,7 @@ void drawStatus() { if ( !shootmode && mouseInBounds(pos.x, pos.x + hotbar_img->w, pos.y, pos.y + hotbar_img->h) ) { - if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !identifygui_active && !removecursegui_active)) && !selectedItem ) + if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->isActive() == false)) && !selectedItem) ) { toggleclick = false; if ( keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT] ) @@ -555,7 +555,7 @@ void drawStatus() } hotbar[num].item = 0; - if ( *inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !identifygui_active ) + if ( *inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->isActive() == false) ) { *inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) = 0; //itemSelectBehavior = BEHAVIOR_GAMEPAD; @@ -565,7 +565,7 @@ void drawStatus() } } } - if ( mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !identifygui_active && !removecursegui_active) ) + if ( mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->isActive() == false)) ) { //Use the item if right clicked. mousestatus[SDL_BUTTON_RIGHT] = 0; @@ -578,15 +578,11 @@ void drawStatus() badpotion = true; } } + + // Shift + Right click on Item in Player Inventory will starting Appraising if ( keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT] ) { - identifygui_active = false; - identifygui_appraising = true; - - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; - - identifyGUIIdentify(item); + appraisalGUI->openAppraisalGUI(item, players[clientnum]->entity); } else { @@ -841,27 +837,27 @@ void drawStatus() bool bumper_moved = false; //Gamepad change hotbar selection. - if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_NEXT]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && !identifygui_active && !removecursegui_active ) + if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_NEXT]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) { *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_NEXT]) = 0; selectHotbarSlot(current_hotbar + 1); bumper_moved = true; } - if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_PREV]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && !identifygui_active && !removecursegui_active ) + if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_PREV]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) { *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_PREV]) = 0; selectHotbarSlot(current_hotbar - 1); bumper_moved = true; } - if ( bumper_moved && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && !identifygui_active && !removecursegui_active ) + if ( bumper_moved && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) { warpMouseToSelectedHotbarSlot(); } if ( !itemMenuOpen && !selectedItem && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) ) { - if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_ACTIVATE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && !identifygui_active && !removecursegui_active ) + if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_ACTIVATE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) { //Activate a hotbar slot if in-game. *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_ACTIVATE]) = 0; From 6a11798c30ca36b654ca9aa22095ba63d5bd6249 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 14:41:36 -0500 Subject: [PATCH 35/65] - Commented out all deprecated code relating to 'updateRightSidebar()' --- src/interface/updaterightsidebar.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/interface/updaterightsidebar.cpp b/src/interface/updaterightsidebar.cpp index 6ca511cdd..4f3c0cf42 100644 --- a/src/interface/updaterightsidebar.cpp +++ b/src/interface/updaterightsidebar.cpp @@ -10,7 +10,7 @@ -------------------------------------------------------------------------------*/ // note: as of some prealpha version I've since forgotten, this module is totally deprecated - +/* #include "../main.hpp" #include "../game.hpp" #include "../stat.hpp" @@ -61,20 +61,8 @@ void updateRightSidebar() if (mousestatus[SDL_BUTTON_LEFT]) { mousestatus[SDL_BUTTON_LEFT] = 0; - identifygui_active = true; - identifygui_appraising = true; - gui_mode = GUI_MODE_INVENTORY; - if ( removecursegui_active ) - { - closeRemoveCurseGUI(); - } - if ( openedChest[clientnum] ) - { - openedChest[clientnum]->closeChest(); - } - - //Initialize Identify GUI game controller code here. - initIdentifyGUIControllerCode(); + + // AppraisalGUI->openAppraisalGUI() would go here, but this is a deprecated function } } else @@ -121,3 +109,4 @@ void updateRightSidebar() //Advance the position. pos.y += rightsidebar_slot_img->h; } +*/ \ No newline at end of file From 34fbdfd819eb5e2fe2a1569105e450083bde9961 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 15:01:16 -0500 Subject: [PATCH 36/65] * Refactored gameLogic() and main() to handle ItemModifyingGUI --- src/game.cpp | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 030e321a9..e074c06af 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -77,6 +77,9 @@ int game = 1; Uint32 uniqueGameKey = 0; list_t steamAchievements; +GUI::ItemModifyingGUI* itemModifyingGUI; +GUI::AppraisalGUI* appraisalGUI; + /*------------------------------------------------------------------------------- gameLogic @@ -1442,7 +1445,7 @@ void gameLogic(void) } else { - if ( auto_appraise_new_items && appraisal_timer == 0 && !(item->identified) ) + if ( auto_appraise_new_items && appraisal_timer == 0 && !(item->identified) ) { int appraisal_time = getAppraisalTime(item); if (appraisal_time < auto_appraise_lowest_time) @@ -2695,9 +2698,13 @@ int main(int argc, char** argv) { shootmode = true; gui_mode = GUI_MODE_INVENTORY; - identifygui_active = false; - selectedIdentifySlot = -1; - closeRemoveCurseGUI(); + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->isActive() == true ) + { + itemModifyingGUI->closeItemModifyingGUI(); + } + if ( shopkeeper != 0 ) { if ( multiplayer != CLIENT ) @@ -2799,10 +2806,13 @@ int main(int argc, char** argv) } else { - shootmode = true; - identifygui_active = false; - selectedIdentifySlot = -1; - closeRemoveCurseGUI(); + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->isActive() == true ) + { + itemModifyingGUI->closeItemModifyingGUI(); + } + + shootmode = true; } //What even is this code? When should it be run? @@ -3023,22 +3033,14 @@ int main(int argc, char** argv) } else { - //Do these get called every frame? Might be better to move this stuff into an if (went_back_into_shootmode) { ... } thing. - //2-3 years later...yes, it is run every frame. - if (identifygui_appraising) - { - //Close the identify GUI if appraising. - identifygui_active = false; - identifygui_appraising = false; - - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; - } + //Do these get called every frame? Might be better to move this stuff into an if (went_back_into_shootmode) { ... } thing. + //2-3 years later...yes, it is run every frame. - if ( removecursegui_active ) - { - closeRemoveCurseGUI(); - } + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->isActive() == true ) + { + itemModifyingGUI->closeItemModifyingGUI(); + } if ( book_open ) { @@ -3068,8 +3070,7 @@ int main(int argc, char** argv) updateCharacterSheet(); updatePlayerInventory(); updateChestInventory(); - updateIdentifyGUI(); - updateRemoveCurseGUI(); + itemModifyingGUI->updateItemModifyingGUI(); updateBookGUI(); //updateRightSidebar(); From e3465c3a678e862abba06d1429debeabefa6ce8d Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 15:17:42 -0500 Subject: [PATCH 37/65] * Updated VS Barony Solution to be accurate and added ItemModifyingGUI/AppraisalGUI --- VS.2015/Barony/Barony.vcxproj.filters | 41 ++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/VS.2015/Barony/Barony.vcxproj.filters b/VS.2015/Barony/Barony.vcxproj.filters index 611d2dd39..0a9b1a477 100644 --- a/VS.2015/Barony/Barony.vcxproj.filters +++ b/VS.2015/Barony/Barony.vcxproj.filters @@ -294,9 +294,6 @@ Source Files - - Source Files - Source Files @@ -369,6 +366,12 @@ Source Files\magic + + Source Files\interface + + + Source Files\interface + @@ -443,26 +446,32 @@ Header Files - - Source Files + + Header Files\interface - - Source Files + + Header Files\magic + + + Header Files\interface + + + Header Files\interface - Source Files + Header Files - - Source Files + + Header Files - - Source Files + + Header Files - - Header Files\interface + + Header Files - - Header Files\magic + + Header Files From 3b2ef2523e1b35c89f4936e811f0bb12ac12f9bf Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 16:06:46 -0500 Subject: [PATCH 38/65] * Refactored player inventory to handle ItemModifyingGUI --- src/interface/playerinventory.cpp | 68 +++++++++++-------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/src/interface/playerinventory.cpp b/src/interface/playerinventory.cpp index 82359d503..3b7c68e0d 100644 --- a/src/interface/playerinventory.cpp +++ b/src/interface/playerinventory.cpp @@ -32,7 +32,7 @@ SDL_Surface* inventory_mode_spell_img = NULL; SDL_Surface* inventory_mode_spell_highlighted_img = NULL; int inventory_mode = INVENTORY_MODE_ITEM; -selectBehavior_t itemSelectBehavior = BEHAVIOR_MOUSE; +//selectBehavior_t itemSelectBehavior = BEHAVIOR_MOUSE; void warpMouseToSelectedInventorySlot() { @@ -349,30 +349,15 @@ void select_inventory_slot(int x, int y) warpMouseToSelectedShopSlot(); } } - else if ( identifygui_active ) - { - warpInv = false; - y = INVENTORY_SIZEY - 1; + else if ( itemModifyingGUI->isActive() == true ) + { + warpInv = false; + y = INVENTORY_SIZEY - 1; - //Warp into identify GUI "inventory"...if there is anything there. - if ( identify_items[0] ) - { - selectedIdentifySlot = 0; - warpMouseToSelectedIdentifySlot(); - } - } - else if ( removecursegui_active ) - { - warpInv = false; - y = INVENTORY_SIZEY - 1; - - //Warp into Remove Curse GUI "inventory"...if there is anything there. - if ( removecurse_items[0] ) - { - selectedRemoveCurseSlot = 0; - warpMouseToSelectedRemoveCurseSlot(); - } - } + // Warp Cursor into itemModifyingGUI's Inventory + Sint8 direction = 1; // itemModifyingGUI_InventorySelectedSlot will be -1. +1 will place it at 0 + itemModifyingGUI->gamepadMoveCursor(direction); + } if ( warpInv ) //Wrap around to top. { @@ -702,9 +687,9 @@ void updatePlayerInventory() } } - if ( selectedChestSlot < 0 && selectedShopSlot < 0 && selectedIdentifySlot < 0 && selectedRemoveCurseSlot < 0 && !itemMenuOpen && game_controller->handleInventoryMovement() ) + if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() && !itemMenuOpen && game_controller->handleInventoryMovement() ) { - if ( selectedChestSlot < 0 && selectedShopSlot < 0 && selectedIdentifySlot < 0 && selectedRemoveCurseSlot < 0 ) //This second check prevents the extra mouse warp. + if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() ) //This second check prevents the extra mouse warp. { if ( !hotbarHasFocus ) { @@ -731,20 +716,15 @@ void updatePlayerInventory() warpMouseToSelectedInventorySlot(); } } - else if ( selectedIdentifySlot >= 0 && !itemMenuOpen && game_controller->handleIdentifyMovement() ) - { - if ( selectedIdentifySlot < 0 ) - { - warpMouseToSelectedInventorySlot(); - } - } - else if ( selectedRemoveCurseSlot >= 0 && !itemMenuOpen && game_controller->handleRemoveCurseMovement() ) - { - if ( selectedRemoveCurseSlot < 0 ) - { - warpMouseToSelectedInventorySlot(); - } - } + else if ( itemModifyingGUI->isSelectedSlotInvalid() == false && itemMenuOpen != true && game_controller->handleItemModifyingGUIMovement() ) + { + // If, after game_controller->handleItemModifyingGUIMovement() calls itemModifyingGUI->gamepadMoveCursor(), 'itemModifyingGUI_InventorySelectedSlot' is -1 + if ( itemModifyingGUI->isSelectedSlotInvalid() == true ) + { + // Then warp the cursor to the Player's Inventory instead + warpMouseToSelectedInventorySlot(); + } + } if ( *inputPressed(joyimpulses[INJOY_MENU_INVENTORY_TAB]) ) { @@ -780,7 +760,7 @@ void updatePlayerInventory() drawLine(pos.x, pos.y + y * INVENTORY_SLOTSIZE, pos.x + pos.w, pos.y + y * INVENTORY_SLOTSIZE, SDL_MapRGB(mainsurface->format, 150, 150, 150), 255); } - if ( !itemMenuOpen && selectedChestSlot < 0 && selectedShopSlot < 0 && selectedIdentifySlot < 0 && selectedRemoveCurseSlot < 0 ) + if ( !itemMenuOpen && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() ) { //Highlight (draw a gold border) currently selected inventory slot (for gamepad). //Only if item menu is not open, no chest slot is selected, no shop slot is selected, no Identify GUI slot is selected, and no Remove Curse GUI slot is selected. @@ -1113,14 +1093,14 @@ void updatePlayerInventory() break; } - if ( *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) && !itemMenuOpen && !selectedItem && selectedChestSlot < 0 && selectedShopSlot < 0 && selectedIdentifySlot < 0 && selectedRemoveCurseSlot < 0 ) + if ( *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) && !itemMenuOpen && !selectedItem && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() ) { *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) = 0; dropItem(item, clientnum); } // handle clicking - if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && selectedChestSlot < 0 && selectedShopSlot < 0 && selectedIdentifySlot < 0 && selectedRemoveCurseSlot < 0)) && !selectedItem && !itemMenuOpen ) + if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() )) && !selectedItem && !itemMenuOpen ) { if ( !(*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK])) && (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) ) { @@ -1144,7 +1124,7 @@ void updatePlayerInventory() } } } - else if ( (mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0 && selectedShopSlot < 0 && selectedIdentifySlot < 0 && selectedRemoveCurseSlot < 0)) && !itemMenuOpen && !selectedItem ) + else if ( (mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() )) && !itemMenuOpen && !selectedItem ) { if ( (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) && !(*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0) ) //TODO: selected shop slot, identify, remove curse? { From 945cf0679f103fab87ec43f87adb3b835c75a65b Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 16:15:59 -0500 Subject: [PATCH 39/65] * Refactored interface.cpp to handle ItemModifyingGUI --- src/interface/interface.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/interface/interface.cpp b/src/interface/interface.cpp index cc1e0ad00..32bb87ff5 100644 --- a/src/interface/interface.cpp +++ b/src/interface/interface.cpp @@ -192,9 +192,6 @@ bool loadInterfaceResources() invclose_bmp = loadImage("images/system/InventoryCloseHighlighted.png"); invgraball_bmp = loadImage("images/system/InventoryChestGraballHighlighted.png"); - //Identify GUI images... - identifyGUI_img = loadImage("images/system/identifyGUI.png"); - /*rightsidebar_titlebar_img = loadImage("images/system/rightSidebarTitlebar.png"); if (!rightsidebar_titlebar_img) { printlog( "Failed to load \"images/system/rightSidebarTitlebar.png\"."); @@ -389,10 +386,7 @@ void freeInterfaceResources() //for( c=0; cfreeGUIImage(); /*if (rightsidebar_titlebar_img) SDL_FreeSurface(rightsidebar_titlebar_img); if (rightsidebar_slot_img) From 94b761e921cade85f2be66d6049a3c86079551b5 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 16:16:50 -0500 Subject: [PATCH 40/65] + Added freeGUIImage() to handle unloading of image resource --- src/interface/ItemModifyingGUI.cpp | 14 +++++++++++++- src/interface/ItemModifyingGUI.hpp | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index 9b6b74552..e8c95778c 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -37,7 +37,7 @@ ItemModifyingGUI::ItemModifyingGUI() : ItemModifyingGUI::~ItemModifyingGUI() { closeItemModifyingGUI(); - itemModifyingGUI_IMG = nullptr; + freeGUIImage(); } // ~ItemModifyingGUI() /* ItemModifyingGUI.cpp @@ -433,6 +433,18 @@ bool ItemModifyingGUI::isMouseWithinGUIBounds() const return false; } // isMouseWithinGUIBounds() +/* ItemModifyingGUI.cpp + * Called by freeInterfaceResources(). Frees 'itemModifyingGUI_IMG' using SDL_FreeSurface() + */ +void ItemModifyingGUI::freeGUIImage() +{ + if ( itemModifyingGUI_IMG != nullptr ) + { + SDL_FreeSurface(itemModifyingGUI_IMG); + itemModifyingGUI_IMG = nullptr; + } +} + /* ItemModifyingGUI.cpp * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] * @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index f99f4bac7..a708d7671 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -71,6 +71,10 @@ class ItemModifyingGUI * Returns whether or not the Mouse is currently within the bounds of the ItemModifyingGUI */ bool isMouseWithinGUIBounds() const; + /* ItemModifyingGUI.cpp + * Called by freeInterfaceResources(). Frees 'itemModifyingGUI_IMG' using SDL_FreeSurface() + */ + void freeGUIImage(); private: // ItemModifying GUI From f87e921860a832be1f19828753abd6e85143c6de Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 17:12:30 -0500 Subject: [PATCH 41/65] * Refactored interface.hpp to handle ItemModifyingGUI/AppraisalGUI and deprecate old versions --- src/interface/interface.hpp | 65 ++++++++++--------------------------- 1 file changed, 17 insertions(+), 48 deletions(-) diff --git a/src/interface/interface.hpp b/src/interface/interface.hpp index de2366536..0a7113401 100644 --- a/src/interface/interface.hpp +++ b/src/interface/interface.hpp @@ -13,6 +13,8 @@ #include "../main.hpp" #include "../game.hpp" +#include "ItemModifyingGUI.hpp" +#include "AppraisalGUI.hpp" class Item; @@ -142,12 +144,14 @@ extern int inventory_mode; * BEHAVIOR_MOUSE = press left button to pick up, release left button to drop, * BEHAVIOR_GAMEPAD = press mapped button (x by default) to select/"grab" item, press again to drop. */ +/* enum selectBehavior_t { BEHAVIOR_MOUSE = 0, BEHAVIOR_GAMEPAD = 1, ENUM_LEN = 2 } extern itemSelectBehavior; +*/ //Chest GUI definitions. #define CHEST_INVENTORY_X (((xres / 2) - (inventoryChest_bmp->w / 2)) + chestgui_offset_x) @@ -198,52 +202,6 @@ void updateMagicGUI(); #define SUST_SPELLS_RIGHT_ALIGN true //If true, overrides settings and makes the sustained spells draw alongside the right edge of the screen, vertically. void drawSustainedSpells(); //Draws an icon for every sustained spell. -//Identify GUI definitions. -//NOTE: Make sure to always reset identifygui_appraising back to false. -#define IDENTIFY_GUI_X (((xres / 2) - (inventoryChest_bmp->w / 2)) + identifygui_offset_x) -#define IDENTIFY_GUI_Y (((yres / 2) - (inventoryChest_bmp->h / 2)) + identifygui_offset_y) -extern bool identifygui_active; -extern bool identifygui_appraising; //If this is true, the appraisal skill is controlling the identify GUI. If this is false, it originated from an identify spell. -extern int identifygui_offset_x; -extern int identifygui_offset_y; -extern bool dragging_identifyGUI; //The identify GUI is being dragged. -extern int identifyscroll; -static const int NUM_IDENTIFY_GUI_ITEMS = 4; -extern Item* identify_items[NUM_IDENTIFY_GUI_ITEMS]; -extern SDL_Surface* identifyGUI_img; - -extern int selectedIdentifySlot; - -void selectIdentifySlot(int slot); -void warpMouseToSelectedIdentifySlot(); - -void updateIdentifyGUI(); //Updates the identify item GUI. -void identifyGUIIdentify(Item* item); //Identify the given item. -int getAppraisalTime(Item* item); // Return time in ticks needed to appraise an item -void drawSustainedSpells(); //Draws an icon for every sustained spell. - -//Remove curse GUI definitions. -#define REMOVECURSE_GUI_X (((xres / 2) - (inventoryChest_bmp->w / 2)) + removecursegui_offset_x) -#define REMOVECURSE_GUI_Y (((yres / 2) - (inventoryChest_bmp->h / 2)) + removecursegui_offset_y) -extern bool removecursegui_active; -extern int removecursegui_offset_x; -extern int removecursegui_offset_y; -extern bool dragging_removecurseGUI; //The remove curse GUI is being dragged. -extern int removecursescroll; -static const int NUM_REMOVE_CURSE_GUI_ITEMS = 4; -extern Item* removecurse_items[NUM_REMOVE_CURSE_GUI_ITEMS]; -//extern SDL_Surface *removecurseGUI_img; //Nah, just use the identify GUI's image. It works well enough. No need to double the resources. - -void closeRemoveCurseGUI(); -void updateRemoveCurseGUI(); //Updates the remove curse GUI. -void removecurseGUIRemoveCurse(Item* item); //Uncurse the given item. - -//Gamepad-support related stuff. -extern int selectedRemoveCurseSlot; -void selectRemoveCurseSlot(int slot); -void warpMouseToSelectedRemoveCurseSlot(); - - /* * Returns true if the mouse is in the specified bounds, with x1 and y1 specifying the top left corner, and x2 and y2 specifying the bottom right corner. */ @@ -264,7 +222,7 @@ extern int appraisal_timer; //There is a delay after the appraisal skill is acti extern int appraisal_timermax; extern Uint32 appraisal_item; //The item being appraised (or rather its uid) -void updateRightSidebar(); //Updates the sidebar on the right side of the screen, the one containing spells, skills, etc. +//void updateRightSidebar(); //Updates the sidebar on the right side of the screen, the one containing spells, skills, etc. DEPRECATED: See updaterightsidebar.cpp //------book_t Defines----- extern SDL_Surface* bookgui_img; @@ -362,9 +320,10 @@ void openStatusScreen(int whichGUIMode, int whichInventoryMode); //TODO: Make al static const int SCANCODE_UNASSIGNED_BINDING = 399; +// TODOR: I'm not sure why this is the intended behavior. I believe this should be reworked to be more user friendly inline bool hotbarGamepadControlEnabled() { - return ( !openedChest[clientnum] && gui_mode != GUI_MODE_SHOP && !identifygui_active && !removecursegui_active ); + return (!openedChest[clientnum] && gui_mode != GUI_MODE_SHOP); // && itemModifyingGUI->isActive() == false); // TODOR: This cannot be done as the function is inline } extern SDL_Surface *str_bmp64u; @@ -382,3 +341,13 @@ extern SDL_Surface *chr_bmp64; void printStatBonus(TTF_Font* outputFont, Sint32 stat, Sint32 statWithModifiers, int x, int y); +// 9-5-2017 - Lutz - ItemModifyingGUI Refactor +// Forward Declaration +namespace GUI +{ +class ItemModifyingGUI; +class AppraisalGUI; +} + +extern GUI::ItemModifyingGUI* itemModifyingGUI; +extern GUI::AppraisalGUI* appraisalGUI; From 1d85c0bbd4e237ab178c9ec4e67385aafbb82755 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 15 Sep 2017 17:13:10 -0500 Subject: [PATCH 42/65] - Commented out deprecated versions of ItemModifyingGUI pending removal --- src/interface/identify_and_appraise.cpp | 23 ++++++++++++++--------- src/interface/removecurse.cpp | 20 ++++++++++---------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/interface/identify_and_appraise.cpp b/src/interface/identify_and_appraise.cpp index b7c8f6160..4337608fc 100644 --- a/src/interface/identify_and_appraise.cpp +++ b/src/interface/identify_and_appraise.cpp @@ -8,7 +8,7 @@ See LICENSE for details. -------------------------------------------------------------------------------*/ - +/* #include "../main.hpp" #include "../game.hpp" #include "../stat.hpp" @@ -17,6 +17,10 @@ #include "../player.hpp" #include "interface.hpp" +#define IDENTIFY_GUI_X 1 +#define IDENTIFY_GUI_Y 1 +#define NUM_IDENTIFY_GUI_ITEMS 4 + //Identify GUI definitions. bool identifygui_active = false; bool identifygui_appraising = false; @@ -423,22 +427,22 @@ void selectIdentifySlot(int slot) { //Moving up. - /* + * Possible cases: * * 1) Move cursor up the GUI through different selectedIdentifySlot. * * 2) Page up through identifyscroll-- * * 3) Scrolling up past top of Identify GUI, no identifyscroll (move back to inventory) - */ + if ( selectedIdentifySlot <= 0 ) { //Covers cases 2 & 3. - /* + * Possible cases: * * A) Hit very top of Identify "inventory", can't go any further. Return to inventory. * * B) Page up, scrolling through identifyscroll. - */ + if ( identifyscroll <= 0 ) { @@ -464,12 +468,12 @@ void selectIdentifySlot(int slot) { //Moving down. - /* + * Possible cases: * * 1) Moving cursor down through GUI through different selectedIdentifySlot. * * 2) Scrolling down past bottom of Identify GUI through identifyscroll++ * * 3) Scrolling down past bottom of Identify GUI, max Identify scroll (revoke move -- can't go beyond limit of Identify GUI). - */ + if ( selectedIdentifySlot >= NUM_IDENTIFY_GUI_ITEMS - 1 ) { @@ -482,11 +486,11 @@ void selectIdentifySlot(int slot) //Move cursor down through the GUi through different selectedIdentifySlot (++selectedIdentifySlot). //This is a little bit trickier since must revoke movement if there is no item in the next slot! - /* + * Two possible cases: * * A) Items below this. Advance selectedIdentifySlot to them. * * B) On last item already. Do nothing (revoke movement). - */ + Item* item = getItemInfoFromIdentifyGUI(selectedIdentifySlot + 1); @@ -513,3 +517,4 @@ void warpMouseToSelectedIdentifySlot() SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); } +*/ \ No newline at end of file diff --git a/src/interface/removecurse.cpp b/src/interface/removecurse.cpp index 3351d0000..f96e8b21c 100644 --- a/src/interface/removecurse.cpp +++ b/src/interface/removecurse.cpp @@ -8,7 +8,7 @@ See LICENSE for details. -------------------------------------------------------------------------------*/ - +/* #include "../main.hpp" #include "../game.hpp" #include "../stat.hpp" @@ -17,7 +17,6 @@ #include "../player.hpp" #include "interface.hpp" - //Remove curse GUI definitions. bool removecursegui_active = false; bool removecursegui_appraising = false; @@ -415,22 +414,22 @@ void selectRemoveCurseSlot(int slot) { //Moving up. - /* + * Possible cases: * * 1) Move cursor up the GUI through different selectedRemoveCurseSlot. * * 2) Page up through removecursescroll-- * * 3) Scrolling up past top of Remove Curse GUI, no removecursescroll (move back to inventory) - */ + if ( selectedRemoveCurseSlot <= 0 ) { //Covers cases 2 & 3. - /* + * Possible cases: * * A) Hit very top of Remove Curse "inventory", can't go any further. Return to inventory. * * B) Page up, scrolling through removecursescroll. - */ + if ( removecursescroll <= 0 ) { @@ -456,12 +455,12 @@ void selectRemoveCurseSlot(int slot) { //Moving down. - /* + * Possible cases: * * 1) Moving cursor down through GUI through different selectedRemoveCurseSlot. * * 2) Scrolling down past bottom of Remove Curse GUI through removecursescroll++ * * 3) Scrolling down past bottom of Remove Curse GUI, max Remove Curse scroll (revoke move -- can't go beyond limit of Remove Curse GUI). - */ + if ( selectedRemoveCurseSlot >= NUM_REMOVE_CURSE_GUI_ITEMS - 1 ) { @@ -474,11 +473,11 @@ void selectRemoveCurseSlot(int slot) //Move cursor down through the GUI through different selectedRemoveCurseSlot (++selectedRemoveCurseSlot). //This is a little bit trickier since must revoke movement if there is no item in the next slot! - /* + * Two possible cases: * * A) Items below this. Advance selectedRemoveCurseSlot to them. * * B) On last item already. Do nothing (revoke movement). - */ + Item* item = getItemInfoFromRemoveCurseGUI(selectedRemoveCurseSlot + 1); @@ -505,3 +504,4 @@ void warpMouseToSelectedRemoveCurseSlot() SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); } +*/ \ No newline at end of file From 653c1bcc84c24a394215493ad5c4e1153434b3aa Mon Sep 17 00:00:00 2001 From: Lutz Date: Mon, 18 Sep 2017 23:30:43 -0500 Subject: [PATCH 43/65] * Renamed functions for much more clarity --- src/interface/ItemModifyingGUI.cpp | 373 ++++++++++++----------------- src/interface/ItemModifyingGUI.hpp | 64 ++--- 2 files changed, 190 insertions(+), 247 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index e8c95778c..93751b97b 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -98,7 +98,7 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr } // Build the GUI's Inventory for an initial check - rebuildItemModifyingGUIInventory(); + ItemModifyingGUI_RebuildInventory(); // If the Inventory is empty, there is nothing to process. The GUI will not open and nothing will be processed if ( itemModifyingGUI_Inventory[0] == nullptr ) @@ -134,14 +134,14 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr { // The actual logic is handled by updateItemModifyingGUI() itemModifyingGUI_InventorySelectedSlot = 0; - warpMouseToSelectedGUISlot(); + WarpMouseToSelectedGUISlot(); } } } // openItemModifyingGUI() /* ItemModifyingGUI.cpp * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls - * Handles the GUI Inventory slot bounds and Mouse input to call processGUIEffectOnItem() + * Handles the GUI Inventory slot bounds and Mouse input to call ItemModifyingGUI_Process() */ void ItemModifyingGUI::updateItemModifyingGUI() { @@ -174,13 +174,13 @@ void ItemModifyingGUI::updateItemModifyingGUI() drawImage(itemModifyingGUI_IMG, nullptr, &GUIRect); // Setup the collision bounds for the GUI buttons - itemModifyingGUI_HandleButtons(); + ItemModifyingGUI_HandleButtons(); // Setup the collision bounds for the Mouse Wheel - itemModifyingGUI_HandleMouseWheel(); + ItemModifyingGUI_HandleMouseWheel(); // Setup the collision bounds for the GUI Dragging Bar - itemModifyingGUI_HandleDraggingBar(); + ItemModifyingGUI_HandleDraggingBar(); // Print the Window Label signifying this GUI char* windowName; @@ -197,7 +197,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() const Sint32 GUIOffsetPosY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); // Draw the Images for the GUI buttons when they are being clicked - itemModifyingGUI_HandleButtonImages(GUIOffsetPosX, GUIOffsetPosY); + ItemModifyingGUI_HandleButtonImages(GUIOffsetPosX, GUIOffsetPosY); SDL_Rect inventorySlotRect; // The position of all the Inventory Slots combined inventorySlotRect.x = GUIOffsetPosX; @@ -233,7 +233,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() *inputPressed(joyimpulses[INJOY_MENU_USE]) = 0; mousestatus[SDL_BUTTON_LEFT] = 0; - processGUIEffectOnItem(itemModifyingGUI_Inventory[iSlotIndex]); + ItemModifyingGUI_Process(itemModifyingGUI_Inventory[iSlotIndex]); } } } @@ -246,7 +246,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() // Draw the Images for each Item in the GUI Inventory // This is done at the end to prevent the Inventory Slot highlight from being drawn on top of the Item information - itemModifyingGUI_HandleItemImages(); + ItemModifyingGUI_HandleItemImages(); } else { @@ -259,7 +259,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() messagePlayer(clientnum, language[2505]); // "Oh no! The scroll was cursed!" - itemModifyingGUIProcessRandomItem(); + ItemModifyingGUI_ProcessRandom(); consumeItem(itemModifyingGUI_ScrollUsed); closeItemModifyingGUI(); @@ -327,7 +327,7 @@ void ItemModifyingGUI::gamepadMoveCursor(Sint8 direction) // Covers case 1 // Move cursor up the GUI through different itemModifyingGUI_InventorySelectedSlot (itemModifyingGUI_InventorySelectedSlot--) itemModifyingGUI_InventorySelectedSlot--; - warpMouseToSelectedGUISlot(); + WarpMouseToSelectedGUISlot(); } } else if ( newSlot > itemModifyingGUI_InventorySelectedSlot ) // D-Pad Down was pressed @@ -357,7 +357,7 @@ void ItemModifyingGUI::gamepadMoveCursor(Sint8 direction) { // Case 1/A itemModifyingGUI_InventorySelectedSlot++; - warpMouseToSelectedGUISlot(); + WarpMouseToSelectedGUISlot(); } else { @@ -388,7 +388,7 @@ bool ItemModifyingGUI::areThereValidItems(const Uint8 GUIType) itemModifyingGUI_Type = GUIType; // Build the GUI's Inventory for an initial check - rebuildItemModifyingGUIInventory(); + ItemModifyingGUI_RebuildInventory(); // If the Inventory is empty, there is nothing to process if ( itemModifyingGUI_Inventory[0] == nullptr ) @@ -467,33 +467,33 @@ inline Item* ItemModifyingGUI::getItemInfoFromGUI(Uint8 slot) * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Selects the correct function to process the Item according to 'itemModifyingGUI_Type' */ -void ItemModifyingGUI::processGUIEffectOnItem(Item* const selectedItem) +void ItemModifyingGUI::ItemModifyingGUI_Process(Item* const selectedItem) { switch ( itemModifyingGUI_Type ) { case 0: // Identify - processIdentifyGUIEffectOnItem(selectedItem); + IdentifyGUI_Process(selectedItem); break; case 1: // Remove Curse - processRemoveCurseGUIEffectOnItem(selectedItem); + RemoveCurseGUI_Process(selectedItem); break; case 2: // Repair - processRepairGUIEffectOnItem(selectedItem); + RepairGUI_Process(selectedItem); break; case 3: // Enchant Weapon - processEnchantWeaponGUIEffectOnItem(selectedItem); + EnchantWeaponGUI_Process(selectedItem); break; case 4: // Enchant Armor - processEnchantArmorGUIEffectOnItem(selectedItem); + EnchantArmorGUI_Process(selectedItem); break; - default: printlog("ERROR: processGUIEffectOnItem() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + default: printlog("ERROR: ItemModifyingGUI_Process() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } -} // processGUIEffectOnItem() +} // ItemModifyingGUI_Process() /* ItemModifyingGUI.cpp * Used for Cursed Scrolls. Selects the correct function to randomly process the Item(s) according to 'itemModifyingGUI_Type' */ -void ItemModifyingGUI::itemModifyingGUIProcessRandomItem() +void ItemModifyingGUI::ItemModifyingGUI_ProcessRandom() { Uint8 numberOfItemsToProcess = 0; switch ( itemModifyingGUI_ScrollBeatitude ) @@ -504,60 +504,60 @@ void ItemModifyingGUI::itemModifyingGUIProcessRandomItem() case -1: numberOfItemsToProcess = 1; break; - default: printlog("ERROR: itemModifyingGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%s) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: ItemModifyingGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%s) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; } switch ( itemModifyingGUI_Type ) { case 0: // Identify - identifyGUIProcessRandomItem(numberOfItemsToProcess); + IdentifyGUI_ProcessRandom(numberOfItemsToProcess); break; case 1: // Remove Curse - removeCurseGUIProcessRandomItem(numberOfItemsToProcess); + RemoveCurseGUI_ProcessRandom(numberOfItemsToProcess); break; case 2: // Repair - repairGUIProcessRandomItem(numberOfItemsToProcess); + RepairGUI_ProcessRandom(numberOfItemsToProcess); break; case 3: // Enchant Weapon - enchantWeaponGUIProcessRandomItem(numberOfItemsToProcess); + EnchantWeaponGUI_ProcessRandom(numberOfItemsToProcess); break; case 4: // Enchant Armor - enchantArmorGUIProcessRandomItem(numberOfItemsToProcess); + EnchantArmorGUI_ProcessRandom(numberOfItemsToProcess); break; - default: printlog("ERROR: itemModifyingGUIProcessRandomItem() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + default: printlog("ERROR: ItemModifyingGUI_ProcessRandom() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } -} // itemModifyingGUIProcessRandomItem() +} // ItemModifyingGUI_ProcessRandom() /* ItemModifyingGUI.cpp * Selects the correct function to rebuild the GUI Inventory according to 'itemModifyingGUI_Type' */ -void ItemModifyingGUI::rebuildItemModifyingGUIInventory() +void ItemModifyingGUI::ItemModifyingGUI_RebuildInventory() { switch ( itemModifyingGUI_Type ) { case 0: // Identify - rebuildIdentifyGUIInventory(); + IdentifyGUI_RebuildInventory(); break; case 1: // Remove Curse - rebuildRemoveCurseGUIInventory(); + RemoveCurseGUI_RebuildInventory(); break; case 2: // Repair - rebuildRepairGUIInventory(); + RepairGUI_RebuildInventory(); break; case 3: // Enchant Weapon - rebuildEnchantWeaponGUIInventory(); + EnchantWeaponGUI_RebuildInventory(); break; case 4: // Enchant Armor - rebuildEnchantArmorGUIInventory(); + EnchantArmorGUI_RebuildInventory(); break; - default: printlog("ERROR: rebuildItemModifyingGUIInventory() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + default: printlog("ERROR: ItemModifyingGUI_RebuildInventory() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } -} // rebuildItemModifyingGUIInventory() +} // ItemModifyingGUI_RebuildInventory() /* ItemModifyingGUI.cpp * Calls SDL_WarpMouseInWindow() to move the Mouse cursor to the currently selected GUI slot for controllers */ -void ItemModifyingGUI::warpMouseToSelectedGUISlot() +void ItemModifyingGUI::WarpMouseToSelectedGUISlot() { SDL_Rect slotPos; slotPos.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); @@ -566,7 +566,7 @@ void ItemModifyingGUI::warpMouseToSelectedGUISlot() slotPos.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16 + (slotPos.h * itemModifyingGUI_InventorySelectedSlot); SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); -} // warpMouseToSelectedGUISlot() +} // WarpMouseToSelectedGUISlot() // ITEM MODIFYING GUI DISPLAY HANDLERS @@ -574,7 +574,7 @@ void ItemModifyingGUI::warpMouseToSelectedGUISlot() * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for each of the GUI's buttons * The Top Bar of the GUI used for dragging is considered a button */ -void ItemModifyingGUI::itemModifyingGUI_HandleButtons() +void ItemModifyingGUI::ItemModifyingGUI_HandleButtons() { // GUI Button Collision Bounds TODOR: I may have these swapped, the lower bound may be the upper bound // Scroll Up Button Y @@ -651,12 +651,12 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtons() } } } -} // itemModifyingGUI_HandleButtons() +} // ItemModifyingGUI_HandleButtons() /* ItemModifyingGUI.cpp * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for Mouse scroll wheel input */ -void ItemModifyingGUI::itemModifyingGUI_HandleMouseWheel() +void ItemModifyingGUI::ItemModifyingGUI_HandleMouseWheel() { // GUI Mouse Wheel Collision Bounds // Mouse Wheel Y @@ -686,12 +686,12 @@ void ItemModifyingGUI::itemModifyingGUI_HandleMouseWheel() } } } -} // itemModifyingGUI_HandleMouseWheel() +} // ItemModifyingGUI_HandleMouseWheel() /* ItemModifyingGUI.cpp * Handles the actual movement of the GUI Window by modifying 'itemModifyingGUI_OffsetX/Y' when 'bIsItemModifyingGUI_Dragging' == true */ -void ItemModifyingGUI::itemModifyingGUI_HandleDraggingBar() +void ItemModifyingGUI::ItemModifyingGUI_HandleDraggingBar() { // GUI Dragging // The GUI Window's centered position in the Game Window @@ -730,14 +730,14 @@ void ItemModifyingGUI::itemModifyingGUI_HandleDraggingBar() bIsItemModifyingGUI_Dragging = false; } } -} // itemModifyingGUI_HandleDraggingBar() +} // ItemModifyingGUI_HandleDraggingBar() /* ItemModifyingGUI.cpp * @param GUIPosX - The GUI position in the center of the screen + itemModifyingGUI_OffsetX * @param GUIPosY - The GUI position in the center of the screen + itemModifyingGUI_OffsetY * Handles drawing the actual GUI button Images when they are being clicked. The unclicked versions are part of the original Image */ -void ItemModifyingGUI::itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY) +void ItemModifyingGUI::ItemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY) { // GUI Scroll Up Button if ( buttonclick == 7 ) @@ -772,49 +772,49 @@ void ItemModifyingGUI::itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, drawImage(invclose_bmp, nullptr, &GUICloseButtonRect); closeItemModifyingGUI(); } -} // itemModifyingGUI_HandleButtonImages() +} // ItemModifyingGUI_HandleButtonImages() /* ItemModifyingGUI.cpp * Rebuilds the GUI Inventory before selecting the correct function to render the Images for each Item according to 'itemModifyingGUI_Type' */ -void ItemModifyingGUI::itemModifyingGUI_HandleItemImages() +void ItemModifyingGUI::ItemModifyingGUI_HandleItemImages() { // Rebuild the GUI Inventory to prevent scrolling infinitely - rebuildItemModifyingGUIInventory(); + ItemModifyingGUI_RebuildInventory(); switch ( itemModifyingGUI_Type ) { case 0: // Identify - identifyGUI_HandleItemImages(); + IdentifyGUI_HandleItemImages(); break; case 1: // Remove Curse - removeCurseGUI_HandleItemImages(); + RemoveCurseGUI_HandleItemImages(); break; case 2: // Repair - repairGUI_HandleItemImages(); + RepairGUI_HandleItemImages(); break; case 3: // Enchant Weapon - enchantWeaponGUI_HandleItemImages(); + EnchantWeaponGUI_HandleItemImages(); break; case 4: // Enchant Armor - enchantArmorGUI_HandleItemImages(); + EnchantArmorGUI_HandleItemImages(); break; - default: printlog("ERROR: itemModifyingGUI_HandleItemImages() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + default: printlog("ERROR: ItemModifyingGUI_HandleItemImages() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } -} // itemModifyingGUI_HandleItemImages() +} // ItemModifyingGUI_HandleItemImages() // IDENTIFY GUI /* ItemModifyingGUI.cpp * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then IdentifyGUI_ProcessRandom() will be called * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ -void ItemModifyingGUI::processIdentifyGUIEffectOnItem(Item* const selectedItem) +void ItemModifyingGUI::IdentifyGUI_Process(Item* const selectedItem) { if ( selectedItem == nullptr ) { - printlog("ERROR: processIdentifyGUIEffectOnItem() - selectedItem is null."); + printlog("ERROR: IdentifyGUI_Process() - selectedItem is null."); return; } @@ -830,15 +830,15 @@ void ItemModifyingGUI::processIdentifyGUIEffectOnItem(Item* const selectedItem) // Identify the selected Item and 1 random Unidentified Item in their Inventory selectedItem->identified = true; messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." - identifyGUIProcessRandomItem(1); + IdentifyGUI_ProcessRandom(1); break; case 2: // Identify the selected Item and 2 random Unidentified Items in their Inventory selectedItem->identified = true; messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." - identifyGUIProcessRandomItem(2); + IdentifyGUI_ProcessRandom(2); break; - default: printlog("ERROR: processIdentifyGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: IdentifyGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; } // If the Player used a Scroll, consume it @@ -849,14 +849,14 @@ void ItemModifyingGUI::processIdentifyGUIEffectOnItem(Item* const selectedItem) } closeItemModifyingGUI(); -} // processIdentifyGUIEffectOnItem() +} // IdentifyGUI_Process() /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used */ -void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) +void ItemModifyingGUI::IdentifyGUI_ProcessRandom(const Uint8 numItems) { // Grab the Player's Inventory again, as it may have been modified prior to this list_t* playerInventoryList = &stats[clientnum]->inventory; @@ -864,7 +864,7 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: identifyGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: IdentifyGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -897,7 +897,7 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) totalAmountOfItems++; } break; - default: printlog("ERROR: identifyGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: IdentifyGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -991,7 +991,7 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) iIdentifyGUIInventoryIndex++; } break; - default: printlog("ERROR: identifyGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: IdentifyGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } // If processing is done, stop searching the Inventory @@ -1017,22 +1017,22 @@ void ItemModifyingGUI::identifyGUIProcessRandomItem(const Uint8 numItems) { messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." } -} // identifyGUIProcessRandomItem() +} // IdentifyGUI_ProcessRandom() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ -void ItemModifyingGUI::rebuildIdentifyGUIInventory() +void ItemModifyingGUI::IdentifyGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; Uint8 iIdentifyGUIInventoryIndex = 0; if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: rebuildIdentifyGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: IdentifyGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -1066,7 +1066,7 @@ void ItemModifyingGUI::rebuildIdentifyGUIInventory() ++iIdentifyGUIInventoryIndex; } break; - default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -1135,7 +1135,7 @@ void ItemModifyingGUI::rebuildIdentifyGUIInventory() } } break; - default: printlog("ERROR: rebuildIdentifyGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: IdentifyGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -1143,12 +1143,12 @@ void ItemModifyingGUI::rebuildIdentifyGUIInventory() break; } } -} // rebuildIdentifyGUIInventory() +} // IdentifyGUI_RebuildInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ -void ItemModifyingGUI::identifyGUI_HandleItemImages() +void ItemModifyingGUI::IdentifyGUI_HandleItemImages() { Uint8 iIdentifyGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item Sint32 iIdentifyGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other @@ -1156,7 +1156,7 @@ void ItemModifyingGUI::identifyGUI_HandleItemImages() Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) @@ -1211,20 +1211,20 @@ void ItemModifyingGUI::identifyGUI_HandleItemImages() } } } -} // identifyGUI_HandleItemImages() +} // IdentifyGUI_HandleItemImages() // REMOVE CURSE GUI /* ItemModifyingGUI.cpp * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then IdentifyGUI_ProcessRandom() will be called * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ -void ItemModifyingGUI::processRemoveCurseGUIEffectOnItem(Item* const selectedItem) +void ItemModifyingGUI::RemoveCurseGUI_Process(Item* const selectedItem) { if ( selectedItem == nullptr ) { - printlog("ERROR: processRemoveCurseGUIEffectOnItem() - selectedItem is null."); + printlog("ERROR: RemoveCurseGUI_Process() - selectedItem is null."); return; } @@ -1240,15 +1240,15 @@ void ItemModifyingGUI::processRemoveCurseGUIEffectOnItem(Item* const selectedIte // Uncurse the selected Item and 1 random Cursed Item in their Inventory messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." selectedItem->beatitude = 0; - removeCurseGUIProcessRandomItem(1); + RemoveCurseGUI_ProcessRandom(1); break; case 2: // Uncurse the selected Item and 2 random Cursed Items in their Inventory messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." selectedItem->beatitude = 0; - removeCurseGUIProcessRandomItem(2); + RemoveCurseGUI_ProcessRandom(2); break; - default: printlog("ERROR: processRemoveCurseGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RemoveCurseGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; } // If the Player used a Scroll, consume it @@ -1260,70 +1260,15 @@ void ItemModifyingGUI::processRemoveCurseGUIEffectOnItem(Item* const selectedIte closeItemModifyingGUI(); - // TODOR: Why does the Client need to be told, this doesn't need to be networked likely - if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) - { - // The Client needs to inform the Server that their equipment was Uncursed - - // Convert the Item type to an int for the packet - Uint8 itemType = 0; - if ( selectedItem == stats[clientnum]->helmet ) - { - itemType = 0; - } - else if ( selectedItem == stats[clientnum]->breastplate ) - { - itemType = 1; - } - else if ( selectedItem == stats[clientnum]->gloves ) - { - itemType = 2; - } - else if ( selectedItem == stats[clientnum]->shoes ) - { - itemType = 3; - } - else if ( selectedItem == stats[clientnum]->shield ) - { - itemType = 4; - } - else if ( selectedItem == stats[clientnum]->weapon ) - { - itemType = 5; - } - else if ( selectedItem == stats[clientnum]->cloak ) - { - itemType = 6; - } - else if ( selectedItem == stats[clientnum]->amulet ) - { - itemType = 7; - } - else if ( selectedItem == stats[clientnum]->ring ) - { - itemType = 8; - } - else if ( selectedItem == stats[clientnum]->mask ) - { - itemType = 9; - } - - strcpy((char*)net_packet->data, "RCUR"); - net_packet->data[4] = clientnum; - net_packet->data[5] = itemType; - net_packet->address.host = net_server.host; - net_packet->address.port = net_server.port; - net_packet->len = 6; - sendPacketSafe(net_sock, -1, net_packet, 0); - } -} // processRemoveCurseGUIEffectOnItem() + // The Client needs to inform the Server that their equipment was Uncursed only if they are wearing it +} // RemoveCurseGUI_Process() /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used */ -void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) +void ItemModifyingGUI::RemoveCurseGUI_ProcessRandom(const Uint8 numItems) { // Grab the Player's Inventory again, as it may have been modified prior to this list_t* playerInventoryList = &stats[clientnum]->inventory; @@ -1331,7 +1276,7 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: removeCurseGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: RemoveCurseGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -1364,7 +1309,7 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) totalAmountOfItems++; } break; - default: printlog("ERROR: removeCurseGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RemoveCurseGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -1457,7 +1402,7 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) iRemoveCurseGUIInventoryIndex++; } break; - default: printlog("ERROR: removeCurseGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RemoveCurseGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } // If processing is done, stop searching the Inventory @@ -1483,22 +1428,22 @@ void ItemModifyingGUI::removeCurseGUIProcessRandomItem(const Uint8 numItems) { messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." } -} // removeCurseGUIProcessRandomItem() +} // RemoveCurseGUI_ProcessRandom() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ -void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() +void ItemModifyingGUI::RemoveCurseGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; Uint8 iRemoveCurseGUIInventoryIndex = 0; if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: rebuildRemoveCurseGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: RemoveCurseGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -1532,7 +1477,7 @@ void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() ++iRemoveCurseGUIInventoryIndex; } break; - default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -1601,7 +1546,7 @@ void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() } } break; - default: printlog("ERROR: rebuildRemoveCurseGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RemoveCurseGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -1609,12 +1554,12 @@ void ItemModifyingGUI::rebuildRemoveCurseGUIInventory() break; } } -} // rebuildRemoveCurseGUIInventory() +} // RemoveCurseGUI_RebuildInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ -void ItemModifyingGUI::removeCurseGUI_HandleItemImages() +void ItemModifyingGUI::RemoveCurseGUI_HandleItemImages() { Uint8 iRemoveCurseGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item Sint32 iRemoveCurseGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other @@ -1622,7 +1567,7 @@ void ItemModifyingGUI::removeCurseGUI_HandleItemImages() Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) @@ -1677,7 +1622,7 @@ void ItemModifyingGUI::removeCurseGUI_HandleItemImages() } } } -} // removeCurseGUI_HandleItemImages() +} // RemoveCurseGUI_HandleItemImages() // REPAIR GUI @@ -1689,11 +1634,11 @@ void ItemModifyingGUI::removeCurseGUI_HandleItemImages() * +2 Scrolls can repair all Items up to Excellent * Messages the Player that their Item has been Repaired, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ -void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) +void ItemModifyingGUI::RepairGUI_Process(Item* const selectedItem) { if ( selectedItem == nullptr ) { - printlog("ERROR: processRepairGUIEffectOnItem() - selectedItem is null."); + printlog("ERROR: RepairGUI_Process() - selectedItem is null."); return; } @@ -1712,7 +1657,7 @@ void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) selectedItem->status = EXCELLENT; messagePlayer(clientnum, language[2517], selectedItem->description()); // "Your %s looks perfect now!" break; - default: printlog("ERROR: processRepairGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; } // If the Player used a Scroll, consume it. Currently there is no Spell of Repair @@ -1724,11 +1669,9 @@ void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) closeItemModifyingGUI(); - // TODOR: Why does the Client need to be told, this doesn't need to be networked likely + // The Client needs to inform the Server that their equipment was Repaired only if they are wearing it if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) { - // The Client needs to inform the Server that their equipment was repaired - // Convert the Item type to an int for the packet Uint8 itemType = 0; if ( selectedItem == stats[clientnum]->helmet ) @@ -1780,14 +1723,14 @@ void ItemModifyingGUI::processRepairGUIEffectOnItem(Item* const selectedItem) net_packet->len = 6; sendPacketSafe(net_sock, -1, net_packet, 0); } -} // processRepairGUIEffectOnItem() +} // RepairGUI_Process() /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to Broken * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used */ -void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) +void ItemModifyingGUI::RepairGUI_ProcessRandom(const Uint8 numItems) { // Grab the Player's Inventory again, as it may have been modified prior to this list_t* playerInventoryList = &stats[clientnum]->inventory; @@ -1795,7 +1738,7 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: repairGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: RepairGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -1826,7 +1769,7 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) totalAmountOfItems++; } break; - default: printlog("ERROR: repairGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -1910,7 +1853,7 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) iRepairGUIInventoryIndex++; } break; - default: printlog("ERROR: repairGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } // If processing is done, stop searching the Inventory @@ -1936,22 +1879,22 @@ void ItemModifyingGUI::repairGUIProcessRandomItem(const Uint8 numItems) { messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." } -} // repairGUIProcessRandomItem() +} // RepairGUI_ProcessRandom() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ -void ItemModifyingGUI::rebuildRepairGUIInventory() +void ItemModifyingGUI::RepairGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; Uint8 iRepairGUIInventoryIndex = 0; if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: rebuildRepairGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: RepairGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -1999,7 +1942,7 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() ++iRepairGUIInventoryIndex; } break; - default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -2106,7 +2049,7 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() } } break; - default: printlog("ERROR: rebuildRepairGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -2114,12 +2057,12 @@ void ItemModifyingGUI::rebuildRepairGUIInventory() break; } } -} // rebuildRepairGUIInventory() +} // RepairGUI_RebuildInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ -void ItemModifyingGUI::repairGUI_HandleItemImages() +void ItemModifyingGUI::RepairGUI_HandleItemImages() { bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) Uint8 iRepairGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item @@ -2128,7 +2071,7 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) @@ -2271,7 +2214,7 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() } } break; - default: printlog("ERROR: repairGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: RepairGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -2280,7 +2223,7 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() } } } -} // repairGUI_HandleItemImages() +} // RepairGUI_HandleItemImages() // ENCHANT WEAPON GUI @@ -2292,11 +2235,11 @@ void ItemModifyingGUI::repairGUI_HandleItemImages() * +2 Scrolls can raise a +0, +1, +2, +3, or +4 weapon up to +5. Raises any Artifact Weapon by one level * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ -void ItemModifyingGUI::processEnchantWeaponGUIEffectOnItem(Item* const selectedItem) +void ItemModifyingGUI::EnchantWeaponGUI_Process(Item* const selectedItem) { if ( selectedItem == nullptr ) { - printlog("ERROR: processEnchantWeaponGUIEffectOnItem() - selectedItem is null."); + printlog("ERROR: EnchantWeaponGUI_Process() - selectedItem is null."); return; } @@ -2327,7 +2270,7 @@ void ItemModifyingGUI::processEnchantWeaponGUIEffectOnItem(Item* const selectedI selectedItem->beatitude = 5; } break; - default: printlog("ERROR: processEnchantWeaponGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantWeaponGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; } // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon @@ -2338,14 +2281,14 @@ void ItemModifyingGUI::processEnchantWeaponGUIEffectOnItem(Item* const selectedI } closeItemModifyingGUI(); -} // processEnchantWeaponGUIEffectOnItem() +} // EnchantWeaponGUI_Process() /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used */ -void ItemModifyingGUI::enchantWeaponGUIProcessRandomItem(const Uint8 numItems) +void ItemModifyingGUI::EnchantWeaponGUI_ProcessRandom(const Uint8 numItems) { // Grab the Player's Inventory again, as it may have been modified prior to this list_t* playerInventoryList = &stats[clientnum]->inventory; @@ -2353,7 +2296,7 @@ void ItemModifyingGUI::enchantWeaponGUIProcessRandomItem(const Uint8 numItems) if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: enchantWeaponGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -2384,7 +2327,7 @@ void ItemModifyingGUI::enchantWeaponGUIProcessRandomItem(const Uint8 numItems) totalAmountOfItems++; } break; - default: printlog("ERROR: enchantWeaponGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -2468,7 +2411,7 @@ void ItemModifyingGUI::enchantWeaponGUIProcessRandomItem(const Uint8 numItems) iEnchantWeaponGUIInventoryIndex++; } break; - default: printlog("ERROR: enchantWeaponGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } // If processing is done, stop searching the Inventory @@ -2494,22 +2437,22 @@ void ItemModifyingGUI::enchantWeaponGUIProcessRandomItem(const Uint8 numItems) { messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." } -} // enchantWeaponGUIProcessRandomItem() +} // EnchantWeaponGUI_ProcessRandom() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ -void ItemModifyingGUI::rebuildEnchantWeaponGUIInventory() +void ItemModifyingGUI::EnchantWeaponGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; Uint8 iEnchantWeaponGUIInventoryIndex = 0; if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: rebuildEnchantWeaponGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -2565,7 +2508,7 @@ void ItemModifyingGUI::rebuildEnchantWeaponGUIInventory() ++iEnchantWeaponGUIInventoryIndex; } break; - default: printlog("ERROR: rebuildEnchantWeaponGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -2682,7 +2625,7 @@ void ItemModifyingGUI::rebuildEnchantWeaponGUIInventory() } } break; - default: printlog("ERROR: rebuildEnchantWeaponGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -2690,12 +2633,12 @@ void ItemModifyingGUI::rebuildEnchantWeaponGUIInventory() break; } } -} // rebuildEnchantWeaponGUIInventory() +} // EnchantWeaponGUI_RebuildInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ -void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() +void ItemModifyingGUI::EnchantWeaponGUI_HandleItemImages() { bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item @@ -2704,7 +2647,7 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) @@ -2857,7 +2800,7 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() } } break; - default: printlog("ERROR: enchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -2866,7 +2809,7 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() } } } -} // enchantWeaponGUI_HandleItemImages() +} // EnchantWeaponGUI_HandleItemImages() // ENCHANT ARMOR GUI @@ -2878,11 +2821,11 @@ void ItemModifyingGUI::enchantWeaponGUI_HandleItemImages() * +2 Scrolls can raise a +0, +1, +2, +3, or +4 Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks up to +5. Raises any Artifact Armor by one level * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ -void ItemModifyingGUI::processEnchantArmorGUIEffectOnItem(Item* const selectedItem) +void ItemModifyingGUI::EnchantArmorGUI_Process(Item* const selectedItem) { if ( selectedItem == nullptr ) { - printlog("ERROR: processEnchantArmorGUIEffectOnItem() - selectedItem is null."); + printlog("ERROR: EnchantArmorGUI_Process() - selectedItem is null."); return; } @@ -2913,7 +2856,7 @@ void ItemModifyingGUI::processEnchantArmorGUIEffectOnItem(Item* const selectedIt selectedItem->beatitude = 5; } break; - default: printlog("ERROR: processEnchantArmorGUIEffectOnItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantArmorGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; } // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon @@ -2924,14 +2867,14 @@ void ItemModifyingGUI::processEnchantArmorGUIEffectOnItem(Item* const selectedIt } closeItemModifyingGUI(); -} // processEnchantArmorGUIEffectOnItem() +} // EnchantArmorGUI_Process() /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used */ -void ItemModifyingGUI::enchantArmorGUIProcessRandomItem(const Uint8 numItems) +void ItemModifyingGUI::EnchantArmorGUI_ProcessRandom(const Uint8 numItems) { // Grab the Player's Inventory again, as it may have been modified prior to this list_t* playerInventoryList = &stats[clientnum]->inventory; @@ -2939,7 +2882,7 @@ void ItemModifyingGUI::enchantArmorGUIProcessRandomItem(const Uint8 numItems) if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: enchantArmorGUIProcessRandomItem() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: EnchantArmorGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -2972,7 +2915,7 @@ void ItemModifyingGUI::enchantArmorGUIProcessRandomItem(const Uint8 numItems) totalAmountOfItems++; } break; - default: printlog("ERROR: enchantArmorGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantArmorGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -3058,7 +3001,7 @@ void ItemModifyingGUI::enchantArmorGUIProcessRandomItem(const Uint8 numItems) iEnchantArmorGUIInventoryIndex++; } break; - default: printlog("ERROR: enchantArmorGUIProcessRandomItem() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantArmorGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } // If processing is done, stop searching the Inventory @@ -3084,22 +3027,22 @@ void ItemModifyingGUI::enchantArmorGUIProcessRandomItem(const Uint8 numItems) { messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." } -} // enchantArmorGUIProcessRandomItem() +} // EnchantArmorGUI_ProcessRandom() /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ -void ItemModifyingGUI::rebuildEnchantArmorGUIInventory() +void ItemModifyingGUI::EnchantArmorGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; Uint8 iEnchantArmorGUIInventoryIndex = 0; if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: rebuildEnchantArmorGUIInventory() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: EnchantArmorGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -3174,7 +3117,7 @@ void ItemModifyingGUI::rebuildEnchantArmorGUIInventory() ++iEnchantArmorGUIInventoryIndex; } break; - default: printlog("ERROR: rebuildEnchantArmorGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantArmorGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } } @@ -3306,7 +3249,7 @@ void ItemModifyingGUI::rebuildEnchantArmorGUIInventory() } } break; - default: printlog("ERROR: rebuildEnchantArmorGUIInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantArmorGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -3314,12 +3257,12 @@ void ItemModifyingGUI::rebuildEnchantArmorGUIInventory() break; } } -} // rebuildEnchantArmorGUIInventory() +} // EnchantArmorGUI_RebuildInventory() /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ -void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() +void ItemModifyingGUI::EnchantArmorGUI_HandleItemImages() { bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item @@ -3328,7 +3271,7 @@ void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() Item* item = nullptr; // The given Item being drawn from the GUI Inventory SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - // Grab the Player's Inventory again, as it may have been modified by processGUIEffectOnItem() + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() list_t* playerInventoryList = &stats[clientnum]->inventory; for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) @@ -3496,7 +3439,7 @@ void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() } } break; - default: printlog("ERROR: enchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + default: printlog("ERROR: EnchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; } if ( bBreakFromLoop == true ) @@ -3505,6 +3448,6 @@ void ItemModifyingGUI::enchantArmorGUI_HandleItemImages() } } } -} // enchantArmorGUI_HandleItemImages() +} // EnchantArmorGUI_HandleItemImages() } // namespace GUI diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index a708d7671..6046c55a9 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -35,7 +35,7 @@ class ItemModifyingGUI void openItemModifyingGUI(const Uint8 GUIType, Item* const scrollUsed); /* ItemModifyingGUI.cpp * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls - * Handles the GUI Inventory slot bounds and Mouse input to call processGUIEffectOnItem() + * Handles the GUI Inventory slot bounds and Mouse input to call ItemModifyingGUI_Process() */ void updateItemModifyingGUI(); /* ItemModifyingGUI.cpp @@ -106,90 +106,90 @@ class ItemModifyingGUI * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Selects the correct function to process the Item according to 'itemModifyingGUI_Type' */ - void processGUIEffectOnItem(Item* const selectedItem); + void ItemModifyingGUI_Process(Item* const selectedItem); /* ItemModifyingGUI.cpp * Used for Cursed Scrolls. Selects the correct function to randomly process the Item(s) according to 'itemModifyingGUI_Type' */ - void itemModifyingGUIProcessRandomItem(); + void ItemModifyingGUI_ProcessRandom(); /* ItemModifyingGUI.cpp * Selects the correct function to rebuild the GUI Inventory according to 'itemModifyingGUI_Type' */ - void rebuildItemModifyingGUIInventory(); + void ItemModifyingGUI_RebuildInventory(); /* ItemModifyingGUI.cpp * Calls SDL_WarpMouseInWindow() to move the Mouse cursor to the currently selected GUI slot for controllers */ - void warpMouseToSelectedGUISlot(); + void WarpMouseToSelectedGUISlot(); // Display Update Handlers /* ItemModifyingGUI.cpp * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for each of the GUI's buttons * The Top Bar of the GUI used for dragging is considered a button */ - void itemModifyingGUI_HandleButtons(); + void ItemModifyingGUI_HandleButtons(); /* ItemModifyingGUI.cpp * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for Mouse scroll wheel input */ - void itemModifyingGUI_HandleMouseWheel(); + void ItemModifyingGUI_HandleMouseWheel(); /* ItemModifyingGUI.cpp * Handles the actual movement of the GUI Window by modifying 'itemModifyingGUI_OffsetX/Y' when 'bIsItemModifyingGUI_Dragging' == true */ - void itemModifyingGUI_HandleDraggingBar(); + void ItemModifyingGUI_HandleDraggingBar(); /* ItemModifyingGUI.cpp * @param GUIPosX - The GUI position in the center of the screen + itemModifyingGUI_OffsetX * @param GUIPosY - The GUI position in the center of the screen + itemModifyingGUI_OffsetY * Handles drawing the actual GUI button Images when they are being clicked. The unclicked versions are part of the original Image */ - void itemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY); + void ItemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY); /* ItemModifyingGUI.cpp * Rebuilds the GUI Inventory before selecting the correct function to render the Images for each Item according to 'itemModifyingGUI_Type' */ - void itemModifyingGUI_HandleItemImages(); + void ItemModifyingGUI_HandleItemImages(); // Identify GUI /* ItemModifyingGUI.cpp * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then IdentifyGUI_ProcessRandom() will be called * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ - void processIdentifyGUIEffectOnItem(Item* const selectedItem); + void IdentifyGUI_Process(Item* const selectedItem); /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used */ - void identifyGUIProcessRandomItem(const Uint8 numItems); + void IdentifyGUI_ProcessRandom(const Uint8 numItems); /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ - void rebuildIdentifyGUIInventory(); + void IdentifyGUI_RebuildInventory(); /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ - void identifyGUI_HandleItemImages(); + void IdentifyGUI_HandleItemImages(); // Remove Curse GUI /* ItemModifyingGUI.cpp * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then identifyGUIProcessRandomItem() will be called + * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > or < 0 then RemoveCurseGUI_ProcessRandom() will be called * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ - void processRemoveCurseGUIEffectOnItem(Item* const selectedItem); + void RemoveCurseGUI_Process(Item* const selectedItem); /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used */ - void removeCurseGUIProcessRandomItem(const Uint8 numItems); + void RemoveCurseGUI_ProcessRandom(const Uint8 numItems); /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ - void rebuildRemoveCurseGUIInventory(); + void RemoveCurseGUI_RebuildInventory(); /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ - void removeCurseGUI_HandleItemImages(); + void RemoveCurseGUI_HandleItemImages(); // Repair GUI /* ItemModifyingGUI.cpp @@ -200,22 +200,22 @@ class ItemModifyingGUI * +2 Scrolls can repair all Items up to Excellent * Messages the Player that their Item has been Repaired, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ - void processRepairGUIEffectOnItem(Item* const selectedItem); + void RepairGUI_Process(Item* const selectedItem); /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to Broken * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used */ - void repairGUIProcessRandomItem(const Uint8 numItems); + void RepairGUI_ProcessRandom(const Uint8 numItems); /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ - void rebuildRepairGUIInventory(); + void RepairGUI_RebuildInventory(); /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ - void repairGUI_HandleItemImages(); + void RepairGUI_HandleItemImages(); // Enchant Weapon GUI /* ItemModifyingGUI.cpp @@ -226,22 +226,22 @@ class ItemModifyingGUI * +2 Scrolls can raise a +0, +1, +2, +3, or +4 weapon up to +5. Raises any Artifact Weapon by one level * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ - void processEnchantWeaponGUIEffectOnItem(Item* const selectedItem); + void EnchantWeaponGUI_Process(Item* const selectedItem); /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used */ - void enchantWeaponGUIProcessRandomItem(const Uint8 numItems); + void EnchantWeaponGUI_ProcessRandom(const Uint8 numItems); /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ - void rebuildEnchantWeaponGUIInventory(); + void EnchantWeaponGUI_RebuildInventory(); /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ - void enchantWeaponGUI_HandleItemImages(); + void EnchantWeaponGUI_HandleItemImages(); // Enchant Armor GUI /* ItemModifyingGUI.cpp @@ -252,22 +252,22 @@ class ItemModifyingGUI * +2 Scrolls can raise a +0, +1, +2, +3, or +4 Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks up to +5. Raises any Artifact Armor by one level * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI */ - void processEnchantArmorGUIEffectOnItem(Item* const selectedItem); + void EnchantArmorGUI_Process(Item* const selectedItem); /* ItemModifyingGUI.cpp * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used */ - void enchantArmorGUIProcessRandomItem(const Uint8 numItems); + void EnchantArmorGUI_ProcessRandom(const Uint8 numItems); /* ItemModifyingGUI.cpp * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' */ - void rebuildEnchantArmorGUIInventory(); + void EnchantArmorGUI_RebuildInventory(); /* ItemModifyingGUI.cpp * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ - void enchantArmorGUI_HandleItemImages(); + void EnchantArmorGUI_HandleItemImages(); }; // class ItemModifyingGUI } // namespace GUI \ No newline at end of file From c60154960fd76c00d30ba6e54db87ca809c52751 Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 11:59:43 -0500 Subject: [PATCH 44/65] + Added the functions for GUI_UpdateServer() for client-sided changes to be reflected on the server --- src/interface/ItemModifyingGUI.cpp | 349 ++++++++++++++++++++++++----- src/interface/ItemModifyingGUI.hpp | 20 ++ 2 files changed, 315 insertions(+), 54 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index 93751b97b..1d2f9394c 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -1260,7 +1260,11 @@ void ItemModifyingGUI::RemoveCurseGUI_Process(Item* const selectedItem) closeItemModifyingGUI(); - // The Client needs to inform the Server that their equipment was Uncursed only if they are wearing it + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + RemoveCurseGUI_UpdateServer(selectedItem); + } } // RemoveCurseGUI_Process() /* ItemModifyingGUI.cpp @@ -1383,6 +1387,12 @@ void ItemModifyingGUI::RemoveCurseGUI_ProcessRandom(const Uint8 numItems) itemToProcess->beatitude = -1; amountOfItemsLeftToProcess--; iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + RemoveCurseGUI_UpdateServer(itemToProcess); + } } iRemoveCurseGUIInventoryIndex++; } @@ -1398,6 +1408,12 @@ void ItemModifyingGUI::RemoveCurseGUI_ProcessRandom(const Uint8 numItems) itemToProcess->beatitude = 0; amountOfItemsLeftToProcess--; iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + RemoveCurseGUI_UpdateServer(itemToProcess); + } } iRemoveCurseGUIInventoryIndex++; } @@ -1624,6 +1640,81 @@ void ItemModifyingGUI::RemoveCurseGUI_HandleItemImages() } } // RemoveCurseGUI_HandleItemImages() +/* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ +void ItemModifyingGUI::RemoveCurseGUI_UpdateServer(Item* const selectedItem) +{ + // Convert the Item type to an int for the packet + Uint8 itemType = 10; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->weapon ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 8; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 9; + } + + // If none of the above is true, then this shouldn't have happened in the first place + if ( itemType == 10 ) + { + printlog("ERROR: RemoveCurseGUI_UpdateServer() - itemType is out of bounds."); + return; + } + + Uint8 isScrollCursed = 0; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + isScrollCursed = 1; + } + + // data[4] = The type of Item as a Uint8 + // data[5] = 0 if the Scroll was Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Uncursed or Cursed + // data[6] = The Player that is sending the message + strcpy((char*)net_packet->data, "CRCU"); + net_packet->data[4] = itemType; + net_packet->data[5] = isScrollCursed; + net_packet->data[6] = clientnum; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 7; + sendPacketSafe(net_sock, -1, net_packet, 0); +} + // REPAIR GUI /* ItemModifyingGUI.cpp @@ -1649,13 +1740,13 @@ void ItemModifyingGUI::RepairGUI_Process(Item* const selectedItem) // Intentional fall-through case 1: // Repair the Item if it is Broken (+1 only), Decrepit, or Worn up to Serviceable - selectedItem->status = SERVICABLE; messagePlayer(clientnum, language[872], selectedItem->description()); // "Your %s looks better!" + selectedItem->status = SERVICABLE; break; case 2: // Repair the Item if it is Broken, Decrepit, Worn, or Serviceable up to Excellent - selectedItem->status = EXCELLENT; messagePlayer(clientnum, language[2517], selectedItem->description()); // "Your %s looks perfect now!" + selectedItem->status = EXCELLENT; break; default: printlog("ERROR: RepairGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; } @@ -1669,59 +1760,10 @@ void ItemModifyingGUI::RepairGUI_Process(Item* const selectedItem) closeItemModifyingGUI(); - // The Client needs to inform the Server that their equipment was Repaired only if they are wearing it + // The Client needs to inform the Server that their equipment was changed only if they have it equipped if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) { - // Convert the Item type to an int for the packet - Uint8 itemType = 0; - if ( selectedItem == stats[clientnum]->helmet ) - { - itemType = 0; - } - else if ( selectedItem == stats[clientnum]->breastplate ) - { - itemType = 1; - } - else if ( selectedItem == stats[clientnum]->gloves ) - { - itemType = 2; - } - else if ( selectedItem == stats[clientnum]->shoes ) - { - itemType = 3; - } - else if ( selectedItem == stats[clientnum]->shield ) - { - itemType = 4; - } - else if ( selectedItem == stats[clientnum]->weapon ) - { - itemType = 5; - } - else if ( selectedItem == stats[clientnum]->cloak ) - { - itemType = 6; - } - else if ( selectedItem == stats[clientnum]->amulet ) - { - itemType = 7; - } - else if ( selectedItem == stats[clientnum]->ring ) - { - itemType = 8; - } - else if ( selectedItem == stats[clientnum]->mask ) - { - itemType = 9; - } - - strcpy((char*)net_packet->data, "ARMR"); - net_packet->data[4] = itemType; - net_packet->data[5] = selectedItem->status; - net_packet->address.host = net_server.host; - net_packet->address.port = net_server.port; - net_packet->len = 6; - sendPacketSafe(net_sock, -1, net_packet, 0); + RepairGUI_UpdateServer(selectedItem); } } // RepairGUI_Process() @@ -1849,6 +1891,12 @@ void ItemModifyingGUI::RepairGUI_ProcessRandom(const Uint8 numItems) itemToProcess->status = BROKEN; amountOfItemsLeftToProcess--; iPreviousItemProcessedIndex = iRepairGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + RepairGUI_UpdateServer(itemToProcess); + } } iRepairGUIInventoryIndex++; } @@ -2225,6 +2273,75 @@ void ItemModifyingGUI::RepairGUI_HandleItemImages() } } // RepairGUI_HandleItemImages() +/* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ +void ItemModifyingGUI::RepairGUI_UpdateServer(Item* const selectedItem) +{ + // Convert the Item type to an int for the packet + Uint8 itemType = 10; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->weapon ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 8; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 9; + } + + // If none of the above is true, then this shouldn't have happened in the first place + if ( itemType == 10 ) + { + printlog("ERROR: RepairGUI_UpdateServer() - itemType is out of bounds."); + return; + } + + // data[4] = The type of Item as a Uint8 + // data[5] = The updated ItemStatus of the Armor as a Uint8 + // data[6] = The Player that is sending the message + strcpy((char*)net_packet->data, "CREP"); + net_packet->data[4] = itemType; + net_packet->data[5] = static_cast(selectedItem->status); + net_packet->data[6] = static_cast(clientnum); + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 7; + sendPacketSafe(net_sock, -1, net_packet, 0); +} + // ENCHANT WEAPON GUI /* ItemModifyingGUI.cpp @@ -2281,6 +2398,15 @@ void ItemModifyingGUI::EnchantWeaponGUI_Process(Item* const selectedItem) } closeItemModifyingGUI(); + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + if ( selectedItem == stats[clientnum]->weapon ) + { + EnchantWeaponGUI_UpdateServer(); + } + } } // EnchantWeaponGUI_Process() /* ItemModifyingGUI.cpp @@ -2407,6 +2533,15 @@ void ItemModifyingGUI::EnchantWeaponGUI_ProcessRandom(const Uint8 numItems) itemToProcess->beatitude = 0; amountOfItemsLeftToProcess--; iPreviousItemProcessedIndex = iEnchantWeaponGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + if ( itemToProcess == stats[clientnum]->weapon ) + { + EnchantWeaponGUI_UpdateServer(); + } + } } iEnchantWeaponGUIInventoryIndex++; } @@ -2811,6 +2946,29 @@ void ItemModifyingGUI::EnchantWeaponGUI_HandleItemImages() } } // EnchantWeaponGUI_HandleItemImages() +/* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ +void ItemModifyingGUI::EnchantWeaponGUI_UpdateServer() +{ + Uint8 isScrollCursed = 0; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + isScrollCursed = 1; + } + + // data[4] = The Player that is sending the message + // data[5] = 0 if the Scroll was Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Enchanted or Disenchanted + strcpy((char*)net_packet->data, "CENW"); + net_packet->data[4] = clientnum; + net_packet->data[5] = isScrollCursed; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 6; + sendPacketSafe(net_sock, -1, net_packet, 0); +} + // ENCHANT ARMOR GUI /* ItemModifyingGUI.cpp @@ -2867,6 +3025,12 @@ void ItemModifyingGUI::EnchantArmorGUI_Process(Item* const selectedItem) } closeItemModifyingGUI(); + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + EnchantArmorGUI_UpdateServer(selectedItem); + } } // EnchantArmorGUI_Process() /* ItemModifyingGUI.cpp @@ -2997,6 +3161,12 @@ void ItemModifyingGUI::EnchantArmorGUI_ProcessRandom(const Uint8 numItems) itemToProcess->beatitude = 0; amountOfItemsLeftToProcess--; iPreviousItemProcessedIndex = iEnchantArmorGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + EnchantArmorGUI_UpdateServer(itemToProcess); + } } iEnchantArmorGUIInventoryIndex++; } @@ -3450,4 +3620,75 @@ void ItemModifyingGUI::EnchantArmorGUI_HandleItemImages() } } // EnchantArmorGUI_HandleItemImages() +/* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ +void ItemModifyingGUI::EnchantArmorGUI_UpdateServer(Item* const selectedItem) +{ + // Convert the Item type to an int for the packet + Uint8 itemType = 9; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 8; + } + + // If none of the above is true, then this shouldn't have happened in the first place + if ( itemType == 9 ) + { + printlog("ERROR: EnchantArmorGUI_UpdateServer() - itemType is out of bounds."); + return; + } + + Uint8 isScrollCursed = 0; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + isScrollCursed = 1; + } + + // data[4] = The type of Armor as a Uint8 + // data[5] = 0 if the Scroll is Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Enchanted or Disenchanted + // data[6] = The Player that is sending the message + strcpy((char*)net_packet->data, "CENA"); + net_packet->data[4] = itemType; + net_packet->data[5] = isScrollCursed; + net_packet->data[6] = clientnum; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 7; + sendPacketSafe(net_sock, -1, net_packet, 0); +} + } // namespace GUI diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 6046c55a9..ea4ae97be 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -190,6 +190,11 @@ class ItemModifyingGUI * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ void RemoveCurseGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void RemoveCurseGUI_UpdateServer(Item* const selectedItem); // Repair GUI /* ItemModifyingGUI.cpp @@ -216,6 +221,11 @@ class ItemModifyingGUI * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ void RepairGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void RepairGUI_UpdateServer(Item* const selectedItem); // Enchant Weapon GUI /* ItemModifyingGUI.cpp @@ -242,6 +252,11 @@ class ItemModifyingGUI * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ void EnchantWeaponGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void EnchantWeaponGUI_UpdateServer(); // Enchant Armor GUI /* ItemModifyingGUI.cpp @@ -268,6 +283,11 @@ class ItemModifyingGUI * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots */ void EnchantArmorGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void EnchantArmorGUI_UpdateServer(Item* const selectedItem); }; // class ItemModifyingGUI } // namespace GUI \ No newline at end of file From 1016c3c8154c04c90dc868f1660b51353d0e0d4f Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 12:00:46 -0500 Subject: [PATCH 45/65] * Modified the packets sent for Identify and Remove Curse spells --- src/magic/castSpell.cpp | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index c5a9c35e6..e4a99edb5 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -525,23 +525,27 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool } else if (!strcmp(element->name, spellElement_identify.name)) { - for (i = 0; i < numplayers; ++i) + // Find the Client that is casting the Spell + for ( Uint8 iClientPlayerIndex = 0; iClientPlayerIndex < numplayers; ++iClientPlayerIndex ) { - if (caster == players[i]->entity) + if ( caster == players[iClientPlayerIndex]->entity ) { spawnMagicEffectParticles(caster->x, caster->y, caster->z, 171); - if (i != 0) + + // If the Client is not the Host, send a packet to tell open the ItemModifyingGUI + if ( iClientPlayerIndex != 0 ) { - //Tell the client to identify an item. - strcpy((char*)net_packet->data, "IDEN"); - net_packet->address.host = net_clients[i - 1].host; - net_packet->address.port = net_clients[i - 1].port; - net_packet->len = 4; - sendPacketSafe(net_sock, -1, net_packet, i - 1); + // data[4] = The type of ItemModifyingGUI to open. 0 is Identify GUI + strcpy((char*)net_packet->data, "CIMG"); + net_packet->data[4] = 0; + net_packet->address.host = net_clients[iClientPlayerIndex - 1].host; + net_packet->address.port = net_clients[iClientPlayerIndex - 1].port; + net_packet->len = 5; + sendPacketSafe(net_sock, -1, net_packet, iClientPlayerIndex - 1); } else { - //Identify an item. + // Open ItemModifyingGUI as Identify GUI itemModifyingGUI->openItemModifyingGUI(0, nullptr); } } @@ -551,23 +555,27 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool } else if (!strcmp(element->name, spellElement_removecurse.name)) { - for (i = 0; i < numplayers; ++i) + // Find the Client that is casting the Spell + for ( Uint8 iClientPlayerIndex = 0; iClientPlayerIndex < numplayers; ++iClientPlayerIndex ) { - if (caster == players[i]->entity) + if ( caster == players[iClientPlayerIndex]->entity ) { spawnMagicEffectParticles(caster->x, caster->y, caster->z, 169); - if (i != 0) + + // If the Client is not the Host, send a packet to tell open the ItemModifyingGUI + if ( iClientPlayerIndex != 0 ) { - //Tell the client to uncurse an item. - strcpy((char*)net_packet->data, "RCUR"); //TODO: Send a different packet, to pop open the remove curse GUI. - net_packet->address.host = net_clients[i - 1].host; - net_packet->address.port = net_clients[i - 1].port; - net_packet->len = 4; - sendPacketSafe(net_sock, -1, net_packet, i - 1); + // data[4] = The type of ItemModifyingGUI to open. 1 is Remove Curse GUI + strcpy((char*)net_packet->data, "CIMG"); + net_packet->data[4] = 1; + net_packet->address.host = net_clients[iClientPlayerIndex - 1].host; + net_packet->address.port = net_clients[iClientPlayerIndex - 1].port; + net_packet->len = 5; + sendPacketSafe(net_sock, -1, net_packet, iClientPlayerIndex - 1); } else { - //Uncurse an item + // Open ItemModifyingGUI as Remove Curse GUI itemModifyingGUI->openItemModifyingGUI(1, nullptr); } } From 9fd5f6cf93c93116c14b97787f52fb5a44205be9 Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 12:06:33 -0500 Subject: [PATCH 46/65] + Refactored IDEN/RCUR into appropriate handlers for ItemModifyingGUI (CRCU, CREP, CENW, CENA) --- src/net.cpp | 452 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 332 insertions(+), 120 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index a3271b153..fbcfefe56 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1234,56 +1234,67 @@ void clientHandlePacket() return; } - // update armor quality - else if (!strncmp((char*)net_packet->data, "ARMR", 4)) - { - switch ( net_packet->data[4] ) - { - case 0: - item = stats[clientnum]->helmet; - break; - case 1: - item = stats[clientnum]->breastplate; - break; - case 2: - item = stats[clientnum]->gloves; - break; - case 3: - item = stats[clientnum]->shoes; - break; - case 4: - item = stats[clientnum]->shield; - break; - case 5: - item = stats[clientnum]->weapon; - break; - case 6: - item = stats[clientnum]->cloak; - break; - case 7: - item = stats[clientnum]->amulet; - break; - case 8: - item = stats[clientnum]->ring; - break; - case 9: - item = stats[clientnum]->mask; - break; - default: - item = NULL; - break; - } - if ( item != NULL ) - { - if ( item->count > 1 ) - { - newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientnum]->inventory); - item->count = 1; - } - item->status = static_cast(net_packet->data[5]); - } - return; - } + // Client Update Equipped Status - Called whenever the Client's equipped Item's ItemStatus has changed, except for Repair GUI + else if ( !strncmp((char*)net_packet->data, "ARMR", 4) ) + { + // data[4] = The type of Armor as a Uint8 + // data[5] = The updated ItemStatus of the Armor as a Uint8 + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientnum]->helmet; + break; + case 1: + item = stats[clientnum]->breastplate; + break; + case 2: + item = stats[clientnum]->gloves; + break; + case 3: + item = stats[clientnum]->shoes; + break; + case 4: + item = stats[clientnum]->shield; + break; + case 5: + item = stats[clientnum]->weapon; + break; + case 6: + item = stats[clientnum]->cloak; + break; + case 7: + item = stats[clientnum]->amulet; + break; + case 8: + item = stats[clientnum]->ring; + break; + case 9: + item = stats[clientnum]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientnum]->inventory); + item->count = 1; + } + + item->status = static_cast(net_packet->data[5]); + return; + } + else + { + printlog("ERROR: clientHandlePacket() (ARMR) - item is null."); + } + + return; + } // "ARMR" - Client Update Equipped Status // steal armor (destroy it) else if (!strncmp((char*)net_packet->data, "STLA", 4)) @@ -2392,29 +2403,6 @@ void clientHandlePacket() return; } - //Open up the GUI to identify an item. - else if (!strncmp((char*)net_packet->data, "IDEN", 4)) - { - //identifygui_mode = true; - identifygui_active = true; - identifygui_appraising = false; - shootmode = false; - gui_mode = GUI_MODE_INVENTORY; //Reset the GUI to the inventory. - if ( removecursegui_active ) - { - closeRemoveCurseGUI(); - } - if ( openedChest[clientnum] ) - { - openedChest[clientnum]->closeChest(); - } - - //Initialize Identify GUI game controller code here. - initIdentifyGUIControllerCode(); - - return; - } - //Add a spell to the channeled spells list. else if (!strncmp((char*)net_packet->data, "CHAN", 4)) { @@ -2608,6 +2596,15 @@ void clientHandlePacket() return; } + // Client open ItemModifyingGUI - Called by castSpell() on Server. Client is told to open GUI locally + else if ( !strncmp((char*)net_packet->data, "CIMG", 4) ) + { + // data[4] = The type of ItemModifyingGUI to open + // 0 is Identify GUI, 1 is Remove Curse GUI + itemModifyingGUI->openItemModifyingGUI(net_packet->data[4], nullptr); + return; + } // "CIMG" - Client Open ItemModifyingGUI + // game restart if (!strncmp((char*)net_packet->data, "BARONY_GAME_START", 17)) { @@ -3274,53 +3271,268 @@ void serverHandlePacket() return; } - // the client removed a curse on his equipment - else if (!strncmp((char*)net_packet->data, "RCUR", 4)) - { - int player = net_packet->data[4]; - switch ( net_packet->data[5] ) - { - case 0: - item = stats[player]->helmet; - break; - case 1: - item = stats[player]->breastplate; - break; - case 2: - item = stats[player]->gloves; - break; - case 3: - item = stats[player]->shoes; - break; - case 4: - item = stats[player]->shield; - break; - case 5: - item = stats[player]->weapon; - break; - case 6: - item = stats[player]->cloak; - break; - case 7: - item = stats[player]->amulet; - break; - case 8: - item = stats[player]->ring; - break; - case 9: - item = stats[player]->mask; - break; - default: - item = NULL; - break; - } - if ( item != NULL ) - { - item->beatitude = 0; - } - return; - } -} + // Client Remove Curse - Called by ItemModifyingGUI to update Server when Client removes Curse on equipped Item(s) + else if ( !strncmp((char*)net_packet->data, "CRCU", 4) ) + { + // data[4] = The type of Item as a Uint8 + // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Cursed or Uncursed + // data[6] = The Player that is sending the message + + Uint8 clientToUpdate = net_packet->data[6]; + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientToUpdate]->helmet; + break; + case 1: + item = stats[clientToUpdate]->breastplate; + break; + case 2: + item = stats[clientToUpdate]->gloves; + break; + case 3: + item = stats[clientToUpdate]->shoes; + break; + case 4: + item = stats[clientToUpdate]->shield; + break; + case 5: + item = stats[clientToUpdate]->weapon; + break; + case 6: + item = stats[clientToUpdate]->cloak; + break; + case 7: + item = stats[clientToUpdate]->amulet; + break; + case 8: + item = stats[clientToUpdate]->ring; + break; + case 9: + item = stats[clientToUpdate]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + bool bWasScrollCursed = false; + if ( net_packet->data[5] == 1 ) + { + bWasScrollCursed = true; + } + + if ( bWasScrollCursed == true ) + { + item->beatitude = -1; + return; + } + else + { + item->beatitude = 0; + return; + } + } + else + { + printlog("ERROR: clientHandlePacket() (CRCU) - item is null."); + } + + return; + } // "CRCU" - Client Remove Curse + + // Client Repair - Called by ItemModifyingGUI to update Server when Client Repairs an equipped Item + else if ( !strncmp((char*)net_packet->data, "CREP", 4) ) + { + // data[4] = The type of Item as a Uint8 + // data[5] = The updated ItemStatus of the Armor as a Uint8 + // data[6] = The Player that is sending the message + + Uint8 clientToUpdate = net_packet->data[6]; + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientToUpdate]->helmet; + break; + case 1: + item = stats[clientToUpdate]->breastplate; + break; + case 2: + item = stats[clientToUpdate]->gloves; + break; + case 3: + item = stats[clientToUpdate]->shoes; + break; + case 4: + item = stats[clientToUpdate]->shield; + break; + case 5: + item = stats[clientToUpdate]->weapon; + break; + case 6: + item = stats[clientToUpdate]->cloak; + break; + case 7: + item = stats[clientToUpdate]->amulet; + break; + case 8: + item = stats[clientToUpdate]->ring; + break; + case 9: + item = stats[clientToUpdate]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + item->status = static_cast(net_packet->data[5]); + return; + } + else + { + printlog("ERROR: clientHandlePacket() (CREP) - item is null."); + } + + return; + } // "CREP" - Client Repair + + // Client Enchant Weapon - Called by ItemModifyingGUI to update Server when Client Enchants equipped Weapon + else if ( !strncmp((char*)net_packet->data, "CENW", 4) ) + { + // data[4] = The Player that is sending the message + // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Disenchanted or Enchanted + + Uint8 clientToUpdate = net_packet->data[4]; + item = stats[clientToUpdate]->weapon; + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + bool bWasScrollCursed = false; + if ( net_packet->data[5] == 1 ) + { + bWasScrollCursed = true; + } + + if ( bWasScrollCursed == true ) + { + item->beatitude = 0; + return; + } + else + { + item->beatitude++; + return; + } + } + else + { + printlog("ERROR: clientHandlePacket() (CENW) - item is null."); + } + + return; + } // "CENW" - Client Enchant Weapon + + // Client Enchant Armor - Called by ItemModifyingGUI to update Server when Client Enchants equipped Armor + else if ( !strncmp((char*)net_packet->data, "CENA", 4) ) + { + // data[4] = The type of Armor as a Uint8 + // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Disenchanted or Enchanted + // data[6] = The Player that is sending the message + + Uint8 clientToUpdate = net_packet->data[6]; + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientToUpdate]->helmet; + break; + case 1: + item = stats[clientToUpdate]->breastplate; + break; + case 2: + item = stats[clientToUpdate]->gloves; + break; + case 3: + item = stats[clientToUpdate]->shoes; + break; + case 4: + item = stats[clientToUpdate]->shield; + break; + case 5: + item = stats[clientToUpdate]->cloak; + break; + case 6: + item = stats[clientToUpdate]->amulet; + break; + case 7: + item = stats[clientToUpdate]->ring; + break; + case 8: + item = stats[clientToUpdate]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + bool bWasScrollCursed = false; + if ( net_packet->data[5] == 1 ) + { + bWasScrollCursed = true; + } + + if ( bWasScrollCursed == true ) + { + item->beatitude = 0; + return; + } + else + { + item->beatitude++; + return; + } + } + else + { + printlog("ERROR: clientHandlePacket() (CENA) - item is null."); + } + + return; + } // "CENA" - Client Enchant Armor +} // serverHandlePacket() /*------------------------------------------------------------------------------- From 794ad8c7923429b6b76bfb10f193bb01cc94444e Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 12:07:22 -0500 Subject: [PATCH 47/65] + Added a small hack to get ItemModifyingGUI working locally, rather than through network (pending useItem refactor) --- src/items.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/items.cpp b/src/items.cpp index 204170f7f..ea3c1c2e9 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -1309,6 +1309,61 @@ void useItem(Item* item, int player) } } + // 9-15-2017 - Lutz GUI Refactor - This is a quick hack to make itemModifyingGUI's work, it will need to be replaced with a refactor of net code/useItem later + switch ( item->type ) + { + case SCROLL_IDENTIFY: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(0, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_ENCHANTWEAPON: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(3, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_ENCHANTARMOR: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(4, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_REMOVECURSE: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(1, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_REPAIR: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->openItemModifyingGUI(2, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + } + if ( multiplayer == CLIENT && !intro ) { strcpy((char*)net_packet->data, "USEI"); From 985bb361deebc0adc3825704ccf294263ea28a2f Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 14:46:37 -0500 Subject: [PATCH 48/65] * Renamed public functions to be more clear and concise --- src/interface/ItemModifyingGUI.cpp | 70 +++++++++++++++--------------- src/interface/ItemModifyingGUI.hpp | 20 ++++----- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index 1d2f9394c..17ee3ed60 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -36,8 +36,8 @@ ItemModifyingGUI::ItemModifyingGUI() : ItemModifyingGUI::~ItemModifyingGUI() { - closeItemModifyingGUI(); - freeGUIImage(); + CloseGUI(); + FreeImage(); } // ~ItemModifyingGUI() /* ItemModifyingGUI.cpp @@ -48,12 +48,12 @@ ItemModifyingGUI::~ItemModifyingGUI() * If a ItemModifyingGUI is already opened, it will be closed before opening the new one * If a Unidentified Scroll is used, it will be Identified here and message the Player accordingly */ -void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scrollUsed) +void ItemModifyingGUI::OpenGUI(const Uint8 GUIType, Item* const scrollUsed) { // If a GUI is already opened, close the GUI before opening the new one if ( bIsActive == true ) { - closeItemModifyingGUI(); + CloseGUI(); } // Initialize the values for the GUI @@ -92,7 +92,7 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr case 4: // Enchant Armor messagePlayer(clientnum, language[2504]); // "This is a scroll of Enchant armor!" break; - default: printlog("ERROR: updateItemModifyingGUI() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + default: printlog("ERROR: UpdateGUI() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; } } } @@ -111,16 +111,16 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed if ( itemModifyingGUI_ScrollUsed == nullptr ) { - printlog("ERROR: updateItemModifyingGUI() - A Cursed Spell has opened the GUI. This should never happen."); + printlog("ERROR: UpdateGUI() - A Cursed Spell has opened the GUI. This should never happen."); return; } consumeItem(itemModifyingGUI_ScrollUsed); - closeItemModifyingGUI(); + CloseGUI(); return; } messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" - closeItemModifyingGUI(); + CloseGUI(); return; } else @@ -132,18 +132,18 @@ void ItemModifyingGUI::openItemModifyingGUI(const Uint8 GUIType, Item* const scr // If the Scroll is Cursed, don't warp the Mouse if ( itemModifyingGUI_ScrollBeatitude >= 0 ) { - // The actual logic is handled by updateItemModifyingGUI() + // The actual logic is handled by UpdateGUI() itemModifyingGUI_InventorySelectedSlot = 0; WarpMouseToSelectedGUISlot(); } } -} // openItemModifyingGUI() +} // OpenGUI() /* ItemModifyingGUI.cpp * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls * Handles the GUI Inventory slot bounds and Mouse input to call ItemModifyingGUI_Process() */ -void ItemModifyingGUI::updateItemModifyingGUI() +void ItemModifyingGUI::UpdateGUI() { // If the GUI is not active, there is no reason to go further if ( bIsActive != true ) @@ -159,7 +159,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() if ( playerInventoryList == nullptr ) { messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: updateItemModifyingGUI() - stats[%d]->inventory is not a valid list.", clientnum); + printlog("ERROR: UpdateGUI() - stats[%d]->inventory is not a valid list.", clientnum); return; } @@ -253,7 +253,7 @@ void ItemModifyingGUI::updateItemModifyingGUI() if ( itemModifyingGUI_ScrollUsed == nullptr ) { // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed - printlog("ERROR: updateItemModifyingGUI() - A Cursed Spell has opened the GUI. This should never happen."); + printlog("ERROR: UpdateGUI() - A Cursed Spell has opened the GUI. This should never happen."); return; } @@ -262,14 +262,14 @@ void ItemModifyingGUI::updateItemModifyingGUI() ItemModifyingGUI_ProcessRandom(); consumeItem(itemModifyingGUI_ScrollUsed); - closeItemModifyingGUI(); + CloseGUI(); } -} // updateItemModifyingGUI() +} // UpdateGUI() /* ItemModifyingGUI.cpp * Resets all member variables back to their base states */ -void ItemModifyingGUI::closeItemModifyingGUI() +void ItemModifyingGUI::CloseGUI() { bIsActive = false; bIsCursed = false; @@ -284,13 +284,13 @@ void ItemModifyingGUI::closeItemModifyingGUI() { itemModifyingGUI_Inventory[i] = nullptr; } -} // closeItemModifyingGUI() +} // CloseGUI() /* ItemModifyingGUI.cpp * @param direction - Will either be -1 for Up or 1 for Down. The direction in which the User wants to move the cursor * Called by GameController::handleItemModifyingGUIMovement(). Evaluates the requested movement, updating 'itemModifyingGUI_InventorySelectedSlot' as needed */ -void ItemModifyingGUI::gamepadMoveCursor(Sint8 direction) +void ItemModifyingGUI::Gamepad_MoveCursor(Sint8 direction) { // Up will be -1, Down will be 1 Sint8 newSlot = itemModifyingGUI_InventorySelectedSlot + direction; @@ -340,7 +340,7 @@ void ItemModifyingGUI::gamepadMoveCursor(Sint8 direction) if ( itemModifyingGUI_InventorySelectedSlot >= NUM_ITEM_MODIFYING_GUI_ITEMS - 1 ) { // Covers cases 2 & 3 - itemModifyingGUI_InventoryScrollOffset++; // itemModifyingGUI_InventoryScrollOffset is automatically sanitized in updateItemModifyingGUI() + itemModifyingGUI_InventoryScrollOffset++; // itemModifyingGUI_InventoryScrollOffset is automatically sanitized in UpdateGUI() } else { @@ -371,7 +371,7 @@ void ItemModifyingGUI::gamepadMoveCursor(Sint8 direction) /* ItemModifyingGUI.cpp * @returns 'bIsActive' */ -bool ItemModifyingGUI::isActive() const +bool ItemModifyingGUI::IsGUIOpen() const { return bIsActive; } @@ -381,9 +381,9 @@ bool ItemModifyingGUI::isActive() const * @returns true - If the Player's Inventory has valid Items for processing * @returns false - If the Player's Inventory has no valid Items for processing * The main usage of this function is to prevent a Spell from being cast needlessly - * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via closeItemModifyingGUI() + * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via CloseGUI() */ -bool ItemModifyingGUI::areThereValidItems(const Uint8 GUIType) +bool ItemModifyingGUI::AreThereValidItems(const Uint8 GUIType) { itemModifyingGUI_Type = GUIType; @@ -394,22 +394,22 @@ bool ItemModifyingGUI::areThereValidItems(const Uint8 GUIType) if ( itemModifyingGUI_Inventory[0] == nullptr ) { messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" - closeItemModifyingGUI(); // Reset all values to prevent any crossover + CloseGUI(); // Reset all values to prevent any crossover return false; } else { - closeItemModifyingGUI(); // Reset all values to prevent any crossover + CloseGUI(); // Reset all values to prevent any crossover return true; } -} // areThereValidItems() +} // AreThereValidItems() /* ItemModifyingGUI.cpp * @returns true - If 'itemModifyingGUI_InventorySelectedSlot' is < 0 * @returns false - If 'itemModifyingGUI_InventorySelectedSlot' is 0 or greater * Returns whether or not the mouse is currently hovering over a GUI Inventory Slot */ -bool ItemModifyingGUI::isSelectedSlotInvalid() const +bool ItemModifyingGUI::IsSelectedSlotInvalid() const { return (itemModifyingGUI_InventorySelectedSlot < 0); } @@ -419,7 +419,7 @@ bool ItemModifyingGUI::isSelectedSlotInvalid() const * @returns false - If the Mouse is not within the bounds of the GUI * Returns whether or not the Mouse is currently within the bounds of the ItemModifyingGUI */ -bool ItemModifyingGUI::isMouseWithinGUIBounds() const +bool ItemModifyingGUI::IsMouseWithinGUIBounds() const { // Draw the GUI Background at the center of the Game Window + it's offset const Sint32 GUIX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); @@ -431,12 +431,12 @@ bool ItemModifyingGUI::isMouseWithinGUIBounds() const } return false; -} // isMouseWithinGUIBounds() +} // IsMouseWithinGUIBounds() /* ItemModifyingGUI.cpp * Called by freeInterfaceResources(). Frees 'itemModifyingGUI_IMG' using SDL_FreeSurface() */ -void ItemModifyingGUI::freeGUIImage() +void ItemModifyingGUI::FreeImage() { if ( itemModifyingGUI_IMG != nullptr ) { @@ -770,7 +770,7 @@ void ItemModifyingGUI::ItemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, GUICloseButtonRect.w = 0; GUICloseButtonRect.h = 0; drawImage(invclose_bmp, nullptr, &GUICloseButtonRect); - closeItemModifyingGUI(); + CloseGUI(); } } // ItemModifyingGUI_HandleButtonImages() @@ -848,7 +848,7 @@ void ItemModifyingGUI::IdentifyGUI_Process(Item* const selectedItem) itemModifyingGUI_ScrollUsed = nullptr; } - closeItemModifyingGUI(); + CloseGUI(); } // IdentifyGUI_Process() /* ItemModifyingGUI.cpp @@ -1258,7 +1258,7 @@ void ItemModifyingGUI::RemoveCurseGUI_Process(Item* const selectedItem) itemModifyingGUI_ScrollUsed = nullptr; } - closeItemModifyingGUI(); + CloseGUI(); // The Client needs to inform the Server that their equipment was changed only if they have it equipped if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) @@ -1758,7 +1758,7 @@ void ItemModifyingGUI::RepairGUI_Process(Item* const selectedItem) itemModifyingGUI_ScrollUsed = nullptr; } - closeItemModifyingGUI(); + CloseGUI(); // The Client needs to inform the Server that their equipment was changed only if they have it equipped if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) @@ -2397,7 +2397,7 @@ void ItemModifyingGUI::EnchantWeaponGUI_Process(Item* const selectedItem) itemModifyingGUI_ScrollUsed = nullptr; } - closeItemModifyingGUI(); + CloseGUI(); // The Client needs to inform the Server that their equipment was changed only if they have it equipped if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) @@ -3024,7 +3024,7 @@ void ItemModifyingGUI::EnchantArmorGUI_Process(Item* const selectedItem) itemModifyingGUI_ScrollUsed = nullptr; } - closeItemModifyingGUI(); + CloseGUI(); // The Client needs to inform the Server that their equipment was changed only if they have it equipped if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index ea4ae97be..36fbb6401 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -32,49 +32,49 @@ class ItemModifyingGUI * If a ItemModifyingGUI is already opened, it will be closed before opening the new one * If a Unidentified Scroll is used, it will be Identified here and message the Player accordingly */ - void openItemModifyingGUI(const Uint8 GUIType, Item* const scrollUsed); + void OpenGUI(const Uint8 GUIType, Item* const scrollUsed); /* ItemModifyingGUI.cpp * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls * Handles the GUI Inventory slot bounds and Mouse input to call ItemModifyingGUI_Process() */ - void updateItemModifyingGUI(); + void UpdateGUI(); /* ItemModifyingGUI.cpp * Resets all member variables back to their base states */ - void closeItemModifyingGUI(); + void CloseGUI(); /* ItemModifyingGUI.cpp * @param direction - Will either be -1 for Up or 1 for Down. The direction in which the User wants to move the cursor * Called by GameController::handleItemModifyingGUIMovement(). Evaluates the requested movement, updating 'itemModifyingGUI_InventorySelectedSlot' as needed */ - void gamepadMoveCursor(Sint8 direction); + void Gamepad_MoveCursor(Sint8 direction); /* ItemModifyingGUI.cpp * @returns 'bIsActive' */ - bool isActive() const; + bool IsGUIOpen() const; /* ItemModifyingGUI.cpp * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor * @returns true - If the Player's Inventory has valid Items for processing * @returns false - If the Player's Inventory has no valid Items for processing * The main usage of this function is to prevent a Spell from being cast needlessly - * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via closeItemModifyingGUI() + * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via CloseGUI() */ - bool areThereValidItems(const Uint8 GUIType); + bool AreThereValidItems(const Uint8 GUIType); /* ItemModifyingGUI.cpp * @returns true - If 'itemModifyingGUI_InventorySelectedSlot' is < 0 * @returns false - If 'itemModifyingGUI_InventorySelectedSlot' is 0 or greater * Returns whether or not the mouse is currently hovering over a GUI Inventory Slot */ - bool isSelectedSlotInvalid() const; + bool IsSelectedSlotInvalid() const; /* ItemModifyingGUI.cpp * @returns true - If the Mouse is currently within the bounds of the GUI * @returns false - If the Mouse is not within the bounds of the GUI * Returns whether or not the Mouse is currently within the bounds of the ItemModifyingGUI */ - bool isMouseWithinGUIBounds() const; + bool IsMouseWithinGUIBounds() const; /* ItemModifyingGUI.cpp * Called by freeInterfaceResources(). Frees 'itemModifyingGUI_IMG' using SDL_FreeSurface() */ - void freeGUIImage(); + void FreeImage(); private: // ItemModifying GUI From 8eb03c7ff10b543967e36cf72eb7266904757384 Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 14:59:46 -0500 Subject: [PATCH 49/65] * Updated all the new ItemModifyingGUI function names to be correct --- src/actchest.cpp | 4 ++-- src/collision.cpp | 4 ++-- src/game.cpp | 14 +++++++------- src/interface/clickdescription.cpp | 4 ++-- src/interface/drawstatus.cpp | 14 +++++++------- src/interface/interface.cpp | 2 +- src/interface/interface.hpp | 2 +- src/interface/playerinventory.cpp | 22 +++++++++++----------- src/items.cpp | 20 ++++++++++---------- src/magic/castSpell.cpp | 8 ++++---- src/net.cpp | 10 +++++----- src/player.cpp | 4 ++-- src/player.hpp | 2 +- src/shops.cpp | 4 ++-- 14 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/actchest.cpp b/src/actchest.cpp index 32712d376..a17b02ec5 100644 --- a/src/actchest.cpp +++ b/src/actchest.cpp @@ -496,9 +496,9 @@ void Entity::actChest() openedChest[chestclicked] = this; // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - itemModifyingGUI->closeItemModifyingGUI(); + itemModifyingGUI->CloseGUI(); } if (chestclicked != 0 && multiplayer == SERVER) diff --git a/src/collision.cpp b/src/collision.cpp index 826005ca8..968ed29be 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -76,9 +76,9 @@ Entity* entityClicked() return nullptr; //Click falls inside the chest inventory GUI. } } - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - if ( itemModifyingGUI->isMouseWithinGUIBounds() == true ) + if ( itemModifyingGUI->IsMouseWithinGUIBounds() == true ) { return nullptr; // Click falls within the itemModifyingGUI's bounds } diff --git a/src/game.cpp b/src/game.cpp index e074c06af..eea123721 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2700,9 +2700,9 @@ int main(int argc, char** argv) gui_mode = GUI_MODE_INVENTORY; // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - itemModifyingGUI->closeItemModifyingGUI(); + itemModifyingGUI->CloseGUI(); } if ( shopkeeper != 0 ) @@ -2807,9 +2807,9 @@ int main(int argc, char** argv) else { // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - itemModifyingGUI->closeItemModifyingGUI(); + itemModifyingGUI->CloseGUI(); } shootmode = true; @@ -3037,9 +3037,9 @@ int main(int argc, char** argv) //2-3 years later...yes, it is run every frame. // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - itemModifyingGUI->closeItemModifyingGUI(); + itemModifyingGUI->CloseGUI(); } if ( book_open ) @@ -3070,7 +3070,7 @@ int main(int argc, char** argv) updateCharacterSheet(); updatePlayerInventory(); updateChestInventory(); - itemModifyingGUI->updateItemModifyingGUI(); + itemModifyingGUI->UpdateGUI(); updateBookGUI(); //updateRightSidebar(); diff --git a/src/interface/clickdescription.cpp b/src/interface/clickdescription.cpp index 7490a99bf..1f81baed7 100644 --- a/src/interface/clickdescription.cpp +++ b/src/interface/clickdescription.cpp @@ -51,9 +51,9 @@ void clickDescription(int player, Entity* entity) return; //Click falls inside the chest inventory GUI. } } - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - if ( itemModifyingGUI->isMouseWithinGUIBounds() == true ) + if ( itemModifyingGUI->IsMouseWithinGUIBounds() == true ) { return; // Click falls within the itemModifyingGUI's bounds } diff --git a/src/interface/drawstatus.cpp b/src/interface/drawstatus.cpp index 34928ebd3..64caefcfc 100644 --- a/src/interface/drawstatus.cpp +++ b/src/interface/drawstatus.cpp @@ -538,7 +538,7 @@ void drawStatus() { if ( !shootmode && mouseInBounds(pos.x, pos.x + hotbar_img->w, pos.y, pos.y + hotbar_img->h) ) { - if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->isActive() == false)) && !selectedItem) ) + if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->IsGUIOpen() == false)) && !selectedItem) ) { toggleclick = false; if ( keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT] ) @@ -555,7 +555,7 @@ void drawStatus() } hotbar[num].item = 0; - if ( *inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->isActive() == false) ) + if ( *inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->IsGUIOpen() == false) ) { *inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) = 0; //itemSelectBehavior = BEHAVIOR_GAMEPAD; @@ -565,7 +565,7 @@ void drawStatus() } } } - if ( mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->isActive() == false)) ) + if ( mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && (itemModifyingGUI->IsGUIOpen() == false)) ) { //Use the item if right clicked. mousestatus[SDL_BUTTON_RIGHT] = 0; @@ -837,27 +837,27 @@ void drawStatus() bool bumper_moved = false; //Gamepad change hotbar selection. - if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_NEXT]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) + if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_NEXT]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->IsGUIOpen() == false) ) { *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_NEXT]) = 0; selectHotbarSlot(current_hotbar + 1); bumper_moved = true; } - if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_PREV]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) + if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_PREV]) && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->IsGUIOpen() == false) ) { *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_PREV]) = 0; selectHotbarSlot(current_hotbar - 1); bumper_moved = true; } - if ( bumper_moved && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) + if ( bumper_moved && !itemMenuOpen && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->IsGUIOpen() == false) ) { warpMouseToSelectedHotbarSlot(); } if ( !itemMenuOpen && !selectedItem && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) ) { - if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_ACTIVATE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->isActive() == false) ) + if ( shootmode && *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_ACTIVATE]) && !openedChest[clientnum] && gui_mode != (GUI_MODE_SHOP) && !book_open && (itemModifyingGUI->IsGUIOpen() == false) ) { //Activate a hotbar slot if in-game. *inputPressed(joyimpulses[INJOY_GAME_HOTBAR_ACTIVATE]) = 0; diff --git a/src/interface/interface.cpp b/src/interface/interface.cpp index 32bb87ff5..9e4af0d2f 100644 --- a/src/interface/interface.cpp +++ b/src/interface/interface.cpp @@ -386,7 +386,7 @@ void freeInterfaceResources() //for( c=0; cfreeGUIImage(); + itemModifyingGUI->FreeImage(); /*if (rightsidebar_titlebar_img) SDL_FreeSurface(rightsidebar_titlebar_img); if (rightsidebar_slot_img) diff --git a/src/interface/interface.hpp b/src/interface/interface.hpp index 0a7113401..74c31d459 100644 --- a/src/interface/interface.hpp +++ b/src/interface/interface.hpp @@ -323,7 +323,7 @@ static const int SCANCODE_UNASSIGNED_BINDING = 399; // TODOR: I'm not sure why this is the intended behavior. I believe this should be reworked to be more user friendly inline bool hotbarGamepadControlEnabled() { - return (!openedChest[clientnum] && gui_mode != GUI_MODE_SHOP); // && itemModifyingGUI->isActive() == false); // TODOR: This cannot be done as the function is inline + return (!openedChest[clientnum] && gui_mode != GUI_MODE_SHOP); // && itemModifyingGUI->IsGUIOpen() == false); // TODOR: This cannot be done as the function is inline } extern SDL_Surface *str_bmp64u; diff --git a/src/interface/playerinventory.cpp b/src/interface/playerinventory.cpp index 3b7c68e0d..4fe31be7f 100644 --- a/src/interface/playerinventory.cpp +++ b/src/interface/playerinventory.cpp @@ -349,14 +349,14 @@ void select_inventory_slot(int x, int y) warpMouseToSelectedShopSlot(); } } - else if ( itemModifyingGUI->isActive() == true ) + else if ( itemModifyingGUI->IsGUIOpen() == true ) { warpInv = false; y = INVENTORY_SIZEY - 1; // Warp Cursor into itemModifyingGUI's Inventory Sint8 direction = 1; // itemModifyingGUI_InventorySelectedSlot will be -1. +1 will place it at 0 - itemModifyingGUI->gamepadMoveCursor(direction); + itemModifyingGUI->Gamepad_MoveCursor(direction); } if ( warpInv ) //Wrap around to top. @@ -687,9 +687,9 @@ void updatePlayerInventory() } } - if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() && !itemMenuOpen && game_controller->handleInventoryMovement() ) + if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() && !itemMenuOpen && game_controller->handleInventoryMovement() ) { - if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() ) //This second check prevents the extra mouse warp. + if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() ) //This second check prevents the extra mouse warp. { if ( !hotbarHasFocus ) { @@ -716,10 +716,10 @@ void updatePlayerInventory() warpMouseToSelectedInventorySlot(); } } - else if ( itemModifyingGUI->isSelectedSlotInvalid() == false && itemMenuOpen != true && game_controller->handleItemModifyingGUIMovement() ) + else if ( itemModifyingGUI->IsSelectedSlotInvalid() == false && itemMenuOpen != true && game_controller->handleItemModifyingGUIMovement() ) { - // If, after game_controller->handleItemModifyingGUIMovement() calls itemModifyingGUI->gamepadMoveCursor(), 'itemModifyingGUI_InventorySelectedSlot' is -1 - if ( itemModifyingGUI->isSelectedSlotInvalid() == true ) + // If, after game_controller->handleItemModifyingGUIMovement() calls itemModifyingGUI->Gamepad_MoveCursor(), 'itemModifyingGUI_InventorySelectedSlot' is -1 + if ( itemModifyingGUI->IsSelectedSlotInvalid() == true ) { // Then warp the cursor to the Player's Inventory instead warpMouseToSelectedInventorySlot(); @@ -760,7 +760,7 @@ void updatePlayerInventory() drawLine(pos.x, pos.y + y * INVENTORY_SLOTSIZE, pos.x + pos.w, pos.y + y * INVENTORY_SLOTSIZE, SDL_MapRGB(mainsurface->format, 150, 150, 150), 255); } - if ( !itemMenuOpen && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() ) + if ( !itemMenuOpen && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() ) { //Highlight (draw a gold border) currently selected inventory slot (for gamepad). //Only if item menu is not open, no chest slot is selected, no shop slot is selected, no Identify GUI slot is selected, and no Remove Curse GUI slot is selected. @@ -1093,14 +1093,14 @@ void updatePlayerInventory() break; } - if ( *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) && !itemMenuOpen && !selectedItem && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() ) + if ( *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) && !itemMenuOpen && !selectedItem && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() ) { *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) = 0; dropItem(item, clientnum); } // handle clicking - if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() )) && !selectedItem && !itemMenuOpen ) + if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() )) && !selectedItem && !itemMenuOpen ) { if ( !(*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK])) && (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) ) { @@ -1124,7 +1124,7 @@ void updatePlayerInventory() } } } - else if ( (mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->isSelectedSlotInvalid() )) && !itemMenuOpen && !selectedItem ) + else if ( (mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() )) && !itemMenuOpen && !selectedItem ) { if ( (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) && !(*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0) ) //TODO: selected shop slot, identify, remove curse? { diff --git a/src/items.cpp b/src/items.cpp index ea3c1c2e9..a32c552e9 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -1315,7 +1315,7 @@ void useItem(Item* item, int player) case SCROLL_IDENTIFY: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(0, item); + itemModifyingGUI->OpenGUI(0, item); } else if ( player == clientnum ) { @@ -1325,7 +1325,7 @@ void useItem(Item* item, int player) case SCROLL_ENCHANTWEAPON: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(3, item); + itemModifyingGUI->OpenGUI(3, item); } else if ( player == clientnum ) { @@ -1335,7 +1335,7 @@ void useItem(Item* item, int player) case SCROLL_ENCHANTARMOR: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(4, item); + itemModifyingGUI->OpenGUI(4, item); } else if ( player == clientnum ) { @@ -1345,7 +1345,7 @@ void useItem(Item* item, int player) case SCROLL_REMOVECURSE: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(1, item); + itemModifyingGUI->OpenGUI(1, item); } else if ( player == clientnum ) { @@ -1355,7 +1355,7 @@ void useItem(Item* item, int player) case SCROLL_REPAIR: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(2, item); + itemModifyingGUI->OpenGUI(2, item); } else if ( player == clientnum ) { @@ -1552,7 +1552,7 @@ void useItem(Item* item, int player) case SCROLL_IDENTIFY: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(0, item); + itemModifyingGUI->OpenGUI(0, item); } else if ( player == clientnum ) { @@ -1572,7 +1572,7 @@ void useItem(Item* item, int player) case SCROLL_ENCHANTWEAPON: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(3, item); + itemModifyingGUI->OpenGUI(3, item); } else if ( player == clientnum ) { @@ -1582,7 +1582,7 @@ void useItem(Item* item, int player) case SCROLL_ENCHANTARMOR: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(4, item); + itemModifyingGUI->OpenGUI(4, item); } else if(player == clientnum) { @@ -1592,7 +1592,7 @@ void useItem(Item* item, int player) case SCROLL_REMOVECURSE: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(1, item); + itemModifyingGUI->OpenGUI(1, item); } else if ( player == clientnum ) { @@ -1623,7 +1623,7 @@ void useItem(Item* item, int player) case SCROLL_REPAIR: if ( !players[player]->entity->isBlind() ) { - itemModifyingGUI->openItemModifyingGUI(2, item); + itemModifyingGUI->OpenGUI(2, item); } else if ( player == clientnum ) { diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index e4a99edb5..ee4d793c7 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -118,7 +118,7 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) // Check to prevent Mana loss if there are no valid Items to be processed by Identify Spell if ( spell->ID == SPELL_IDENTIFY ) { - if ( itemModifyingGUI->areThereValidItems(0) != true ) + if ( itemModifyingGUI->AreThereValidItems(0) != true ) { return; } @@ -127,7 +127,7 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) // Check to prevent Mana loss if there are no valid Items to be processed by Remove Curse Spell if ( spell->ID == SPELL_REMOVECURSE ) { - if ( itemModifyingGUI->areThereValidItems(1) != true ) + if ( itemModifyingGUI->AreThereValidItems(1) != true ) { return; } @@ -546,7 +546,7 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool else { // Open ItemModifyingGUI as Identify GUI - itemModifyingGUI->openItemModifyingGUI(0, nullptr); + itemModifyingGUI->OpenGUI(0, nullptr); } } } @@ -576,7 +576,7 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool else { // Open ItemModifyingGUI as Remove Curse GUI - itemModifyingGUI->openItemModifyingGUI(1, nullptr); + itemModifyingGUI->OpenGUI(1, nullptr); } } } diff --git a/src/net.cpp b/src/net.cpp index fbcfefe56..a93f064eb 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1532,9 +1532,9 @@ void clientHandlePacket() shopitemscroll = 0; // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - itemModifyingGUI->closeItemModifyingGUI(); + itemModifyingGUI->CloseGUI(); } //Initialize shop gamepad code here. @@ -2353,9 +2353,9 @@ void clientHandlePacket() openedChest[clientnum] = entity2; //Set the opened chest to this. // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - itemModifyingGUI->closeItemModifyingGUI(); + itemModifyingGUI->CloseGUI(); } list_FreeAll(&chestInv); @@ -2601,7 +2601,7 @@ void clientHandlePacket() { // data[4] = The type of ItemModifyingGUI to open // 0 is Identify GUI, 1 is Remove Curse GUI - itemModifyingGUI->openItemModifyingGUI(net_packet->data[4], nullptr); + itemModifyingGUI->OpenGUI(net_packet->data[4], nullptr); return; } // "CIMG" - Client Open ItemModifyingGUI diff --git a/src/player.cpp b/src/player.cpp index 65e0d3893..3166b4446 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -670,7 +670,7 @@ bool GameController::handleShopMovement() * @returns true - If the cursor has been moved using the D-Pad * @returns false - If the cursor has not been moved or 'itemMenuOpen' == true * The cursor has been moved if '*joyimpulses[INJOY_DPAD_UP]' or '*joyimpulses[INJOY_DPAD_DOWN]' is true - * If the cursor has been moved, itemModifyingGUI->gamepadMoveCursor() will be called. 'draw_cursor' will be set to false as well + * If the cursor has been moved, itemModifyingGUI->Gamepad_MoveCursor() will be called. 'draw_cursor' will be set to false as well */ bool GameController::handleItemModifyingGUIMovement() { @@ -699,7 +699,7 @@ bool GameController::handleItemModifyingGUIMovement() if ( wasDPadPressed == true ) { // Move the cursor to the new slot position - itemModifyingGUI->gamepadMoveCursor(direction); + itemModifyingGUI->Gamepad_MoveCursor(direction); //draw_cursor = false; TODOR: Ask why this matters diff --git a/src/player.hpp b/src/player.hpp index f0e94e702..1aaee1b14 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -142,7 +142,7 @@ class GameController * @returns true - If the cursor has been moved using the D-Pad * @returns false - If the cursor has not been moved or 'itemMenuOpen' == true * The cursor has been moved if '*joyimpulses[INJOY_DPAD_UP]' or '*joyimpulses[INJOY_DPAD_DOWN]' is true - * If the cursor has been moved, itemModifyingGUI->gamepadMoveCursor() will be called. 'dpad_moved' and 'draw_cursor' will both be set to false as well + * If the cursor has been moved, itemModifyingGUI->Gamepad_MoveCursor() will be called. 'dpad_moved' and 'draw_cursor' will both be set to false as well */ bool handleItemModifyingGUIMovement(); diff --git a/src/shops.cpp b/src/shops.cpp index 85007713e..036f1427b 100644 --- a/src/shops.cpp +++ b/src/shops.cpp @@ -78,9 +78,9 @@ void startTradingServer(Entity* entity, int player) shopitemscroll = 0; // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->isActive() == true ) + if ( itemModifyingGUI->IsGUIOpen() == true ) { - itemModifyingGUI->closeItemModifyingGUI(); + itemModifyingGUI->CloseGUI(); } //Initialize shop gamepad code here. From f392cb19500740ecae79e8dcbb4140dc9f9ca8ee Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 17:03:17 -0500 Subject: [PATCH 50/65] * Changed name to be updated (accidentally commited earlier) --- src/interface/drawstatus.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/drawstatus.cpp b/src/interface/drawstatus.cpp index 64caefcfc..824b41f08 100644 --- a/src/interface/drawstatus.cpp +++ b/src/interface/drawstatus.cpp @@ -582,7 +582,7 @@ void drawStatus() // Shift + Right click on Item in Player Inventory will starting Appraising if ( keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT] ) { - appraisalGUI->openAppraisalGUI(item, players[clientnum]->entity); + appraisalGUI->OpenGUI(item, players[clientnum]->entity); } else { From bc66c6798e6268f41af2e8254fb27ef6483fad39 Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 17:28:51 -0500 Subject: [PATCH 51/65] * Refactored playerinventory.cpp to handle AppraisalGUI --- src/interface/playerinventory.cpp | 94 ++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/src/interface/playerinventory.cpp b/src/interface/playerinventory.cpp index 4fe31be7f..3acbf5015 100644 --- a/src/interface/playerinventory.cpp +++ b/src/interface/playerinventory.cpp @@ -588,13 +588,30 @@ void releaseItem(int x, int y) //TODO: This function uses toggleclick. Conflict } else { + // Let go of Item outside of the Inventory if (selectedItem->count > 1) { + // Item being held is a stack of Items, drop one at a time + + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(selectedItem) == true ) + { + appraisalGUI->CloseGUI(); + } + dropItem(selectedItem, clientnum); toggleclick = true; } else { + // Item being held is a single Item, drop it + + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(selectedItem) == true ) + { + appraisalGUI->CloseGUI(); + } + dropItem(selectedItem, clientnum); selectedItem = NULL; toggleclick = false; @@ -1096,15 +1113,31 @@ void updatePlayerInventory() if ( *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) && !itemMenuOpen && !selectedItem && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() ) { *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) = 0; + + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } + dropItem(item, clientnum); } // handle clicking if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() )) && !selectedItem && !itemMenuOpen ) { + // If the User presses Shift + Left Click, drop the Item they have selected if ( !(*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK])) && (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) ) { - dropItem(item, clientnum); // Quick item drop + mousestatus[SDL_BUTTON_LEFT] = 0; + + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } + + dropItem(item, clientnum); // Drop the Item } else { @@ -1126,16 +1159,16 @@ void updatePlayerInventory() } else if ( (mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() )) && !itemMenuOpen && !selectedItem ) { + // If the User presses Shift + Right Click, start appraising the Item they have selected if ( (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) && !(*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0) ) //TODO: selected shop slot, identify, remove curse? { - // auto-appraise the item - identifygui_active = false; - identifygui_appraising = true; - identifyGUIIdentify(item); - mousestatus[SDL_BUTTON_RIGHT] = 0; - - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; + mousestatus[SDL_BUTTON_RIGHT] = 0; + + // Don't starting appraising if the Item is already being appraised + if ( appraisalGUI->IsItemBeingAppraised(item) == false ) + { + appraisalGUI->OpenGUI(item, players[clientnum]->entity); + } } else { @@ -1490,16 +1523,14 @@ inline void executeItemMenuOption1(Item* item, bool is_potion_bad = false) return; } + // If the Item is not a Potion, the second Tooltip Option is "Appraise" if (itemCategory(item) != POTION) { - //Option 1 = appraise. - identifygui_active = false; - identifygui_appraising = true; - - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; - - identifyGUIIdentify(item); + // Don't starting appraising if the Item is already being appraised + if ( appraisalGUI->IsItemBeingAppraised(item) == false ) + { + appraisalGUI->OpenGUI(item, players[clientnum]->entity); + } } else { @@ -1538,32 +1569,41 @@ inline void executeItemMenuOption2(Item* item) return; } + // If the Item is not a Potion, the third Tooltip Option is "Drop" if (itemCategory(item) != POTION) { - //Option 2 = drop. + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } + dropItem(item, clientnum); } else { - //Option 2 = appraise. - identifygui_active = false; - identifygui_appraising = true; - - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; - - identifyGUIIdentify(item); + // Don't starting appraising if the Item is already being appraised + if ( appraisalGUI->IsItemBeingAppraised(item) == false ) + { + appraisalGUI->OpenGUI(item, players[clientnum]->entity); + } } } inline void executeItemMenuOption3(Item* item) { + // Only Potions have four Tooltip Options, the fourth being "Drop" if (!item || itemCategory(item) != POTION) { return; } - //Option 3 = drop (only potions have option 3). + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } + dropItem(item, clientnum); } From 84623b4325921a3e541798c5050e438582aac6ad Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 18:28:41 -0500 Subject: [PATCH 52/65] * Refactored gameLogic() to handle AppraisalGUI --- src/game.cpp | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index eea123721..ff05806a0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -98,8 +98,8 @@ void gameLogic(void) FILE* fp; deleteent_t* deleteent; bool entitydeletedself; - int auto_appraise_lowest_time = std::numeric_limits::max(); - Item* auto_appraise_target = NULL; + + Item* autoAppraiseTarget = nullptr; // The Item that has been selected to be auto-appraised if ( creditstage > 0 ) { @@ -1019,14 +1019,14 @@ void gameLogic(void) } else { - if ( auto_appraise_new_items && appraisal_timer == 0 && !(item->identified) ) + // Items don't have to be dropped, auto-appraise a new Item if valid + if( auto_appraise_new_items && item->identified == false && appraisalGUI->IsGUIOpen() == false ) { - int appraisal_time = getAppraisalTime(item); - if (appraisal_time < auto_appraise_lowest_time) - { - auto_appraise_target = item; - auto_appraise_lowest_time = appraisal_time; - } + // Check if the current Item has the lowest appraisal time, if it does, set appraisalGUI->lowestAppraisalTime = item's appraisal time + if ( appraisalGUI->IsItemAppraisalTimeShortest(item) == true ) + { + autoAppraiseTarget = item; + } } } } @@ -1445,15 +1445,15 @@ void gameLogic(void) } else { - if ( auto_appraise_new_items && appraisal_timer == 0 && !(item->identified) ) - { - int appraisal_time = getAppraisalTime(item); - if (appraisal_time < auto_appraise_lowest_time) - { - auto_appraise_target = item; - auto_appraise_lowest_time = appraisal_time; - } - } + // Items don't have to be dropped, auto-appraise a new Item if valid + if ( auto_appraise_new_items && item->identified == false && appraisalGUI->IsGUIOpen() == false ) + { + // Check if the current Item has the lowest appraisal time, if it does, set appraisalGUI->lowestAppraisalTime = item's appraisal time + if ( appraisalGUI->IsItemAppraisalTimeShortest(item) == true ) + { + autoAppraiseTarget = item; + } + } } } @@ -1467,15 +1467,10 @@ void gameLogic(void) } } - // Automatically identify items, shortest time required first - if ( auto_appraise_target != NULL ) + // If an Item was selected for auto-appraisal, open the AppraisalGUI + if ( autoAppraiseTarget != nullptr ) { - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; - - identifygui_active = false; - identifygui_appraising = true; - identifyGUIIdentify(auto_appraise_target); + appraisalGUI->OpenGUI(autoAppraiseTarget, players[clientnum]->entity); } } } From 1d4b8ee5540eabd4ae110b1f1b1ff308712831a8 Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 20 Sep 2017 19:15:01 -0500 Subject: [PATCH 53/65] * Updated some comments --- src/interface/ItemModifyingGUI.cpp | 25 ++++++++++++++----------- src/interface/ItemModifyingGUI.hpp | 5 ++++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index 17ee3ed60..a09fa4b7d 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -351,7 +351,7 @@ void ItemModifyingGUI::Gamepad_MoveCursor(Sint8 direction) // * A) There are Items below this. Advance itemModifyingGUI_InventorySelectedSlot to them // * * B) On last Item already. Do nothing (undo movement) - Item* item = getItemInfoFromGUI(itemModifyingGUI_InventorySelectedSlot + 1); + Item* item = GetItemInfoFromGUI(itemModifyingGUI_InventorySelectedSlot + 1); if ( item != nullptr ) { @@ -366,7 +366,7 @@ void ItemModifyingGUI::Gamepad_MoveCursor(Sint8 direction) } } } -} +} // Gamepad_MoveCursor() /* ItemModifyingGUI.cpp * @returns 'bIsActive' @@ -374,7 +374,7 @@ void ItemModifyingGUI::Gamepad_MoveCursor(Sint8 direction) bool ItemModifyingGUI::IsGUIOpen() const { return bIsActive; -} +} // IsGUIOpen() /* ItemModifyingGUI.cpp * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor @@ -412,7 +412,7 @@ bool ItemModifyingGUI::AreThereValidItems(const Uint8 GUIType) bool ItemModifyingGUI::IsSelectedSlotInvalid() const { return (itemModifyingGUI_InventorySelectedSlot < 0); -} +} // IsSelectedSlotInvalid() /* ItemModifyingGUI.cpp * @returns true - If the Mouse is currently within the bounds of the GUI @@ -443,7 +443,7 @@ void ItemModifyingGUI::FreeImage() SDL_FreeSurface(itemModifyingGUI_IMG); itemModifyingGUI_IMG = nullptr; } -} +} // FreeImage() /* ItemModifyingGUI.cpp * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] @@ -451,7 +451,7 @@ void ItemModifyingGUI::FreeImage() * @returns The Item* from itemModifyingGUI_Inventory[slot] * @returns nullptr if slot >= 4 (Out of bounds) */ -inline Item* ItemModifyingGUI::getItemInfoFromGUI(Uint8 slot) +inline Item* ItemModifyingGUI::GetItemInfoFromGUI(Uint8 slot) { if ( slot >= 4 ) { @@ -459,7 +459,7 @@ inline Item* ItemModifyingGUI::getItemInfoFromGUI(Uint8 slot) } return itemModifyingGUI_Inventory[slot]; -} // getItemInfoFromGUI() +} // GetItemInfoFromGUI() // ITEM MODIFYING GUI LOGIC HANDLERS @@ -1641,6 +1641,7 @@ void ItemModifyingGUI::RemoveCurseGUI_HandleItemImages() } // RemoveCurseGUI_HandleItemImages() /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them */ @@ -1713,7 +1714,7 @@ void ItemModifyingGUI::RemoveCurseGUI_UpdateServer(Item* const selectedItem) net_packet->address.port = net_server.port; net_packet->len = 7; sendPacketSafe(net_sock, -1, net_packet, 0); -} +} // RemoveCurseGUI_UpdateServer() // REPAIR GUI @@ -2274,6 +2275,7 @@ void ItemModifyingGUI::RepairGUI_HandleItemImages() } // RepairGUI_HandleItemImages() /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them */ @@ -2340,7 +2342,7 @@ void ItemModifyingGUI::RepairGUI_UpdateServer(Item* const selectedItem) net_packet->address.port = net_server.port; net_packet->len = 7; sendPacketSafe(net_sock, -1, net_packet, 0); -} +} // RepairGUI_UpdateServer() // ENCHANT WEAPON GUI @@ -2967,7 +2969,7 @@ void ItemModifyingGUI::EnchantWeaponGUI_UpdateServer() net_packet->address.port = net_server.port; net_packet->len = 6; sendPacketSafe(net_sock, -1, net_packet, 0); -} +} // EnchantWeaponGUI_UpdateServer() // ENCHANT ARMOR GUI @@ -3621,6 +3623,7 @@ void ItemModifyingGUI::EnchantArmorGUI_HandleItemImages() } // EnchantArmorGUI_HandleItemImages() /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them */ @@ -3689,6 +3692,6 @@ void ItemModifyingGUI::EnchantArmorGUI_UpdateServer(Item* const selectedItem) net_packet->address.port = net_server.port; net_packet->len = 7; sendPacketSafe(net_sock, -1, net_packet, 0); -} +} // EnchantArmorGUI_UpdateServer() } // namespace GUI diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index 36fbb6401..f023c52d2 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -100,7 +100,7 @@ class ItemModifyingGUI * @returns The Item* from itemModifyingGUI_Inventory[slot] * @returns nullptr if slot >= 4 (Out of bounds) */ - Item* getItemInfoFromGUI(Uint8 slot); + Item* GetItemInfoFromGUI(Uint8 slot); /* ItemModifyingGUI.cpp * @param selectedItem - The Item that is being processed, selected from the GUI Inventory @@ -191,6 +191,7 @@ class ItemModifyingGUI */ void RemoveCurseGUI_HandleItemImages(); /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them */ @@ -222,6 +223,7 @@ class ItemModifyingGUI */ void RepairGUI_HandleItemImages(); /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them */ @@ -284,6 +286,7 @@ class ItemModifyingGUI */ void EnchantArmorGUI_HandleItemImages(); /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them */ From cb26e9ae52b7ca6eb67c65cd150142b6ad4437a2 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:20:33 -0500 Subject: [PATCH 54/65] - Removed unused global variables that are replaced by AppraisalGUI --- src/init_game.cpp | 3 +-- src/interface/interface.hpp | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/init_game.cpp b/src/init_game.cpp index 72e15b15d..3bca7773b 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -623,8 +623,7 @@ void deinitGame() } free( books ); } - appraisal_timer = 0; - appraisal_item = 0; + for (c = 0; c < MAXPLAYERS; c++) { list_FreeAll(&stats[c]->inventory); diff --git a/src/interface/interface.hpp b/src/interface/interface.hpp index 74c31d459..48c3991f2 100644 --- a/src/interface/interface.hpp +++ b/src/interface/interface.hpp @@ -218,9 +218,9 @@ extern SDL_Surface* rightsidebar_slot_img; extern SDL_Surface* rightsidebar_slot_highlighted_img; extern SDL_Surface* rightsidebar_slot_grayedout_img; extern int rightsidebar_height; -extern int appraisal_timer; //There is a delay after the appraisal skill is activated before the item is identified. -extern int appraisal_timermax; -extern Uint32 appraisal_item; //The item being appraised (or rather its uid) +//extern int appraisal_timer; //There is a delay after the appraisal skill is activated before the item is identified. +//extern int appraisal_timermax; +//extern Uint32 appraisal_item; //The item being appraised (or rather its uid) //void updateRightSidebar(); //Updates the sidebar on the right side of the screen, the one containing spells, skills, etc. DEPRECATED: See updaterightsidebar.cpp From 4f55e66d7d6888982b8272c158f2e2b92aad1fd9 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:23:10 -0500 Subject: [PATCH 55/65] * Replaced deprecated variables with AppraisalGUI --- src/menu.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index e41947a0f..cae964d01 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -4187,8 +4187,9 @@ void handleMainMenu(bool mode) // reset game darkmap = false; - appraisal_timer = 0; - appraisal_item = 0; + + appraisalGUI->CloseGUI(); // Close the Appraisal GUI + multiplayer = 0; shootmode = true; currentlevel = 0; From 75ab86bcae6fde4dccc85aaab6f33345ebb8adda Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:23:57 -0500 Subject: [PATCH 56/65] * Refactored consumeItem to handle AppraisalGUI --- src/items.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/items.cpp b/src/items.cpp index a32c552e9..98d558055 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -997,11 +997,13 @@ void consumeItem(Item* item) { return; } - if ( appraisal_item == item->uid && item->count == 1 ) - { - appraisal_item = 0; - appraisal_timer = 0; - } + + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } + item->count--; if ( item->count <= 0 ) { From ff822c98626f574f9f74a2bf2450ce286c857866 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:30:19 -0500 Subject: [PATCH 57/65] - Commented out deprecated AppraisalGUI drawing function --- src/interface/interface.hpp | 2 +- src/interface/playerinventory.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/interface/interface.hpp b/src/interface/interface.hpp index 48c3991f2..998cc22bc 100644 --- a/src/interface/interface.hpp +++ b/src/interface/interface.hpp @@ -111,7 +111,7 @@ int loadConfig(char* filename); int saveConfig(char* filename); void defaultConfig(); void updateChestInventory(); -void updateAppraisalItemBox(); +//void updateAppraisalItemBox(); void updatePlayerInventory(); void updateShopWindow(); void updateEnemyBar(Entity* source, Entity* target, char* name, Sint32 hp, Sint32 maxhp); diff --git a/src/interface/playerinventory.cpp b/src/interface/playerinventory.cpp index 3acbf5015..a25c9d2a9 100644 --- a/src/interface/playerinventory.cpp +++ b/src/interface/playerinventory.cpp @@ -245,7 +245,7 @@ char* itemUseString(const Item* item) draws the current item being appraised -------------------------------------------------------------------------------*/ - +/* void updateAppraisalItemBox() { SDL_Rect pos; @@ -295,6 +295,7 @@ void updateAppraisalItemBox() drawImageScaled(itemSprite(item), NULL, &pos); } } +*/ void select_inventory_slot(int x, int y) { From c9ac248632f7a13ed924d840cc667eea2f7d7048 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:31:11 -0500 Subject: [PATCH 58/65] * Refactored actPlayer() to handle AppraisalGUI --- src/actplayer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/actplayer.cpp b/src/actplayer.cpp index 8606786cc..2752a1a08 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -618,6 +618,15 @@ void actPlayer(Entity* my) } } + if ( PLAYER_NUM == clientnum ) + { + if ( appraisalGUI->IsGUIOpen() == true ) + { + appraisalGUI->UpdateGUI(); + } + } + + /* if (PLAYER_NUM == clientnum && appraisal_timer > 0) { Item* tempItem = uidToItem(appraisal_item); @@ -692,7 +701,7 @@ void actPlayer(Entity* my) appraisal_timer = 0; appraisal_item = 0; } - } + }*/ // remove broken equipment if ( stats[PLAYER_NUM]->helmet != NULL ) From 9cc6213e5cd9a2ec89a22040b04fe6ee5a645b39 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:31:34 -0500 Subject: [PATCH 59/65] + Created the new AppraisalGUI class --- src/interface/AppraisalGUI.cpp | 351 +++++++++++++++++++++++++++++++++ src/interface/AppraisalGUI.hpp | 103 ++++++++++ 2 files changed, 454 insertions(+) create mode 100644 src/interface/AppraisalGUI.cpp create mode 100644 src/interface/AppraisalGUI.hpp diff --git a/src/interface/AppraisalGUI.cpp b/src/interface/AppraisalGUI.cpp new file mode 100644 index 000000000..188f1cafc --- /dev/null +++ b/src/interface/AppraisalGUI.cpp @@ -0,0 +1,351 @@ +/*------------------------------------------------------------------------------- + +BARONY +File: AppraisalGUI.cpp +Desc: AppraisalGUI class implementation + +Copyright 2013-2017 (c) Turning Wheel LLC, all rights reserved. +See LICENSE for details. + +Additional Author(s): Lutz Kellen + +-------------------------------------------------------------------------------*/ + +#include "AppraisalGUI.hpp" +#include "../items.hpp" +#include "../net.hpp" + +namespace GUI +{ + +AppraisalGUI::AppraisalGUI() : + bIsActive(false), + initialAppraisalTime(0), + remainingAppraisalTime(0) +{ + std::numeric_limits::max(); +} // AppraisalGUI() + +AppraisalGUI::~AppraisalGUI() +{ + CloseGUI(); + itemToAppraise = nullptr; + localPlayerEntity = nullptr; +} // ~AppraisalGUI() + +/* AppraisalGUI.cpp + * @param appraisalItem - A pointer to the Item that is going to be appraised + * @param localPlayer - A pointer to the Entity of the Player who is appraising (Local Player only), used for accessing their skill and PER Stats + * Initializes the GUI, with two initial checks for instantaneous appraisal. If the Player's appraisal skill is >= 100 or the Item is a GEM_ROCK + * In the case of a non-instant appraisal, 'initialAppraisalTime' is calculated and 'remainingAppraisalTime' is set to 'initialAppraisalTime' + */ +void AppraisalGUI::OpenGUI(Item* const appraisalItem, Entity* const localPlayer) +{ + // If a GUI is already opened, close the GUI before opening the new one + if ( bIsActive == true ) + { + CloseGUI(); + } + + // Update the Appraisal GUI + bIsActive = true; + itemToAppraise = appraisalItem; + localPlayerEntity = localPlayer; + + // If the Player has is Legendary in Appraisal then complete the action immediately + if ( stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] >= CAPSTONE_UNLOCK_LEVEL[PRO_APPRAISAL] ) + { + itemToAppraise->identified = true; + messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." + AttemptSkillUp(); + CloseGUI(); + return; + } + else if ( itemToAppraise->type == GEM_ROCK ) // Rocks are appraised instantly + { + itemToAppraise->identified = true; + messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." + AttemptSkillUp(); + CloseGUI(); + return; + } + + // Since it wasn't autocompleted, initialize the appraisal timer + initialAppraisalTime = GetGUIItemAppraisalTime(); + remainingAppraisalTime = initialAppraisalTime; + + messagePlayer(clientnum, language[321], appraisalItem->description()); // "Appraising "%s"..." +} // OpenGUI() + +/* AppraisalGUI.cpp + * Handles the updating of the appraisal timer by decreasing 'remainingAppraisalTime' by 1 every call (every tick) + * Once 'remainingAppraisalTime' == 0, IsAppraisalSuccessful() will be called. On success, the Item is Identified + * In both success and failure cases, the Player is messaged on the result, and AttemptSkillUp() is called before closing the GUI + */ +void AppraisalGUI::UpdateGUI() +{ + // If the GUI is not active, there is no reason to go further + if ( bIsActive != true ) + { + return; + } + + // The GUI should never be active with the itemToAppraise being null + if ( itemToAppraise == nullptr ) + { + printlog("ERROR: updateAppraisalGUI() - itemToAppraise is null."); + CloseGUI(); + return; + } + + remainingAppraisalTime--; // Tick downward while appraising + + if ( remainingAppraisalTime == 0 ) + { + if ( IsAppraisalSuccessful() == true ) + { + itemToAppraise->identified = true; + messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." + AttemptSkillUp(); + CloseGUI(); + } + else + { + messagePlayer(clientnum, language[571], itemToAppraise->description()); // "Failed to identify "%s"." + AttemptSkillUp(); + CloseGUI(); + } + } +} // UpdateGUI() + +/* AppraisalGUI.cpp + * Resets all member variables back to their base states + */ +void AppraisalGUI::CloseGUI() +{ + bIsActive = false; + initialAppraisalTime = 0; + remainingAppraisalTime = 0; + lowestAppraisalTime = std::numeric_limits::max(); + + itemToAppraise = nullptr; + localPlayerEntity = nullptr; +} // CloseGUI() + +/* AppraisalGUI.cpp + * @returns bIsActive + * Returns the status of whether or not the AppraisalGUI is currently active + */ +bool AppraisalGUI::IsGUIOpen() const +{ + return bIsActive; +} // IsGUIOpen() + +/* AppraisalGUI.cpp + * @param item - The Item being compared to 'itemToAppraise' + * @returns true - If the AppraisalGUI's currently appraising Item is the same as @item + * @returns false - If they are not the same + */ +bool AppraisalGUI::IsItemBeingAppraised(const Item* const item) const +{ + return (itemToAppraise == item); +} // IsItemBeingAppraised() + +/* AppraisalGUI.cpp + * @param item - A pointer to the Item having it's appraisal time evaluated + * @returns true - If @item's appraisal time is lower than 'lowestAppraisalTime' + * @returns false - Default case + * Evaluates and compares @item's appraisal time to 'lowestAppraisalTime'. In the event that it is shorter, 'lowestAppraisalTime' is set to @item's appraisal time + * Used for finding the next target for auto-appraisal + */ +bool AppraisalGUI::IsItemAppraisalTimeShortest(const Item* const item) +{ + Uint32 itemAppraisalTime = GetExternalItemAppraisalTime(item); + + // Check if the Item's appraisal time is lower than the previous lowest time + if ( itemAppraisalTime < lowestAppraisalTime ) + { + lowestAppraisalTime = itemAppraisalTime; + return true; + } + + return false; +} // IsItemAppraisalTimeShortest() + +// PRIVATE FUNCTIONS + +/* AppraisalGUI.cpp + * Draws the AppraisalGUI box, along with the text and Item icon. The GUI's position is shifted if the Player's Inventory is open + */ +void AppraisalGUI::DrawGUI() +{ + if ( bIsActive == false ) + { + return; + } + + if ( itemToAppraise == nullptr ) + { + CloseGUI(); + return; + } + + // The offset of the Appraisal GUI when the Inventory is open + const Sint32 appraisalBox_OffsetX = ((xres) / 2 - (INVENTORY_SIZEX)*(INVENTORY_SLOTSIZE) / 2 - inventory_mode_item_img->w / 2); + const Sint32 appraisalBox_OffsetY = 10; + + // Draw the Appraisal GUI Box + SDL_Rect appraisalBoxRect; + + // If the Player is in an Inventory, offset so it isn't in the way + if ( shootmode == false ) + { + appraisalBoxRect.x = appraisalBox_OffsetX + 16; + appraisalBoxRect.y = appraisalBox_OffsetY + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16; + } + else + { + appraisalBoxRect.x = 16; + appraisalBoxRect.y = 16; + } + + int appraisingTextWidth = 0; // The width of the text "Appraising: " + int itemNameTextWidth = 0; // The width of the text of the name of the Item being appraised + + // Get the size of the text within the Appraisal GUI Box + TTF_SizeUTF8(ttf12, language[340], &appraisingTextWidth, nullptr); + TTF_SizeUTF8(ttf12, itemToAppraise->getName(), &itemNameTextWidth, nullptr); + + // Resize the Appraisal GUI Box based on the text within it + itemNameTextWidth += 48; + appraisalBoxRect.w = std::max(appraisingTextWidth, itemNameTextWidth) + 8; + appraisalBoxRect.h = 68; + + // Draw the actual Appraisal GUI Box + drawTooltip(&appraisalBoxRect); + + // Draw the appraising timer % in the Appraisal GUI Box + char appraisalBoxFormattedText[64] = {0}; + snprintf(appraisalBoxFormattedText, 63, language[341], ((static_cast((initialAppraisalTime - remainingAppraisalTime))) / (static_cast(initialAppraisalTime))) * 100); // "Appraising:%3.0f%%" + ttfPrintText(ttf12, appraisalBoxRect.x + 8, appraisalBoxRect.y + 8, appraisalBoxFormattedText); + + // Draw the Item's Sprite and name + //SDL_Rect itemSpriteRect; + + // If the Player is in an Inventory, offset so it isn't in the way + if ( shootmode == false ) + { + appraisalBoxRect.x = appraisalBox_OffsetX + 24; + appraisalBoxRect.y = appraisalBox_OffsetY + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16 + 24; + } + else + { + appraisalBoxRect.x = 24; + appraisalBoxRect.y = 16 + 24; + } + + // Draw the name of the Item being appraised + ttfPrintText(ttf12, appraisalBoxRect.x + 40, appraisalBoxRect.y + 8, itemToAppraise->getName()); + appraisalBoxRect.w = 32; + appraisalBoxRect.h = 32; + + // Draw the Sprite of the Item being appraised + drawImageScaled(itemSprite(itemToAppraise), nullptr, &appraisalBoxRect); +} // DrawGUI() + +/* AppraisalGUI.cpp + * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks + * Calculates the appraisal time of the selected appraisal target, 'itemToAppraise'. Value is used internally only + */ +Uint32 AppraisalGUI::GetGUIItemAppraisalTime() const +{ + Uint32 calculatedTime = 0; // The time calculated based on the type and value of the Item and Proficiency of the Player + + if ( itemToAppraise->type != GEM_GLASS ) + { + // All Items other than Worthless glass have an appraisal time based on their value, reduced by the Player's proficiency + calculatedTime = (items[itemToAppraise->type].value * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + else + { + // Worthless glass has a flat time of 60,000 ticks, reduced by the Player's proficiency + calculatedTime = (1000 * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + + // Appraisal time has a minimum of 1 tick and a maximum of 36,000 ticks + calculatedTime = std::min(std::max(1, static_cast(calculatedTime)), 36000); + + return calculatedTime; +} // GetGUIItemAppraisalTime() + +/* AppraisalGUI.cpp + * @param item - A pointer to the Item that is having the appraisal time calculated + * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks + * Calculates the appraisal time of the given Item, @item. Value is used for IsItemAppraisalTimeShortest() for finding the next auto-appraise target + */ +Uint32 AppraisalGUI::GetExternalItemAppraisalTime(const Item* const item) +{ + Uint32 calculatedTime = 0; // The time calculated based on the type and value of the Item and Proficiency of the Player + + if ( item->type != GEM_GLASS ) + { + // All Items other than Worthless glass have an appraisal time based on their value, reduced by the Player's proficiency + calculatedTime = (items[item->type].value * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + else + { + // Worthless glass has a flat time of 60,000 ticks, reduced by the Player's proficiency + calculatedTime = (1000 * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + + // Appraisal time has a minimum of 1 tick and a maximum of 36,000 ticks + calculatedTime = std::min(std::max(1, static_cast(calculatedTime)), 36000); + + return calculatedTime; +} // GetExternalItemAppraisalTime() + +/* AppraisalGUI.cpp + * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 'itemToAppraise' value / 10 WHEN itemToAppraise->type != GEM_GLASS + * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 100 WHEN itemToAppraise->type == GEM_GLASS + * @returns false - Default case + * Calculates whether or not the appraisal is successful, based off the Player's appraisal skill and PER + */ +bool AppraisalGUI::IsAppraisalSuccessful() +{ + bool bIsAppraisalSuccessful = false; + + if ( itemToAppraise->type != GEM_GLASS ) + { + // For Items other than Worthless glass, (Prof + (PER * 5)) must be >= to (ItemValue / 10) + bIsAppraisalSuccessful = ((stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + (localPlayerEntity->getPER() * 5)) >= (items[itemToAppraise->type].value / 10)); + } + else + { + // For Worthless glass, (Prof + (PER * 5)) must be >= to 100 + bIsAppraisalSuccessful = ((stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + (localPlayerEntity->getPER() * 5)) >= 100); + } + + return bIsAppraisalSuccessful; +} // IsAppraisalSuccessful() + +/* AppraisalGUI.cpp + * Checks to see if the Player's appraisal skill should be increased. Only Items with a value above 0 will be considered + * If the Item was successfully appraised, then the Player's skill will be increased. Else, 1 in 5 chance of increasing their skill + */ +void AppraisalGUI::AttemptSkillUp() +{ + if ( items[itemToAppraise->type].value > 0 ) + { + // If the Player succeeded in appraising the Item, increase their skill + if ( itemToAppraise->identified ) + { + localPlayerEntity->increaseSkill(PRO_APPRAISAL); + } + else if ( rand() % 5 == 0 ) // Else random chance for an increase + { + localPlayerEntity->increaseSkill(PRO_APPRAISAL); + } + } +} // AttemptSkillUp() + +} // namespace GUI \ No newline at end of file diff --git a/src/interface/AppraisalGUI.hpp b/src/interface/AppraisalGUI.hpp new file mode 100644 index 000000000..0a9da6711 --- /dev/null +++ b/src/interface/AppraisalGUI.hpp @@ -0,0 +1,103 @@ +/*------------------------------------------------------------------------------- + +BARONY +File: AppraisalGUI.hpp +Desc: AppraisalGUI class definition + +Copyright 2013-2017 (c) Turning Wheel LLC, all rights reserved. +See LICENSE for details. + +Additional Author(s): Lutz Kellen + +-------------------------------------------------------------------------------*/ + +#pragma once + +#include "interface.hpp" + +namespace GUI +{ + +class AppraisalGUI +{ + +public: + AppraisalGUI(); + ~AppraisalGUI(); + + /* AppraisalGUI.cpp + * @param appraisalItem - A pointer to the Item that is going to be appraised + * @param localPlayer - A pointer to the Entity of the Player who is appraising (Local Player only), used for accessing their skill and PER Stats + * Initializes the GUI, with two initial checks for instantaneous appraisal. If the Player's appraisal skill is >= 100 or the Item is a GEM_ROCK + * In the case of a non-instant appraisal, 'initialAppraisalTime' is calculated and 'remainingAppraisalTime' is set to 'initialAppraisalTime' + */ + void OpenGUI(Item* const apprisalItem, Entity* const localPlayer); + /* AppraisalGUI.cpp + * Handles the updating of the appraisal timer by decreasing 'remainingAppraisalTime' by 1 every call (every tick) + * Once 'remainingAppraisalTime' == 0, IsAppraisalSuccessful() will be called. On success, the Item is Identified + * In both success and failure cases, the Player is messaged on the result, and AttemptSkillUp() is called before closing the GUI + */ + void UpdateGUI(); + /* AppraisalGUI.cpp + * Resets all member variables back to their base states + */ + void CloseGUI(); + /* AppraisalGUI.cpp + * @returns bIsActive + * Returns the status of whether or not the AppraisalGUI is currently active + */ + bool IsGUIOpen() const; + /* AppraisalGUI.cpp + * @param item - The Item being compared to 'itemToAppraise' + * @returns true - If the AppraisalGUI's currently appraising Item is the same as @item + * @returns false - If they are not the same + */ + bool IsItemBeingAppraised(const Item* const item) const; + /* AppraisalGUI.cpp + * @param item - A pointer to the Item having it's appraisal time evaluated + * @returns true - If @item's appraisal time is lower than 'lowestAppraisalTime' + * @returns false - Default case + * Evaluates and compares @item's appraisal time to 'lowestAppraisalTime'. In the event that it is shorter, 'lowestAppraisalTime' is set to @item's appraisal time + * Used for finding the next target for auto-appraisal + */ + bool IsItemAppraisalTimeShortest(const Item* const item); + +private: + bool bIsActive; // Flag for whether or not the AppraisalGUI is currently displayed + Uint32 initialAppraisalTime; // The initial appraisal time, calculated by GetGUIItemAppraisalTime() + Uint32 remainingAppraisalTime; // The remaining time before the appraisal is finished, originally set to initialAppraisalTime + Uint32 lowestAppraisalTime; // The lowest appraisal time out of all Items in the Player's Inventory that can be auto-appraised + + Item* itemToAppraise = nullptr; // A pointer to the Item being appraised + Entity* localPlayerEntity = nullptr; // A pointer to the Player who is preforming the appraisal, used for getting the PER of the Player, and for increasing their skill + + /* AppraisalGUI.cpp + * Draws the AppraisalGUI box, along with the text and Item icon. The GUI's position is shifted if the Player's Inventory is open + */ + void DrawGUI(); + /* AppraisalGUI.cpp + * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks + * Calculates the appraisal time of the selected appraisal target, 'itemToAppraise'. Value is used internally only + */ + Uint32 GetGUIItemAppraisalTime() const; + /* AppraisalGUI.cpp + * @param item - A pointer to the Item that is having the appraisal time calculated + * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks + * Calculates the appraisal time of the given Item, @item. Value is used for IsItemAppraisalTimeShortest() for finding the next auto-appraise target + */ + Uint32 GetExternalItemAppraisalTime(const Item* const item); + /* AppraisalGUI.cpp + * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 'itemToAppraise' value / 10 WHEN itemToAppraise->type != GEM_GLASS + * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 100 WHEN itemToAppraise->type == GEM_GLASS + * @returns false - Default case + * Calculates whether or not the appraisal is successful, based off the Player's appraisal skill and PER + */ + bool IsAppraisalSuccessful(); + /* AppraisalGUI.cpp + * Checks to see if the Player's appraisal skill should be increased. Only Items with a value above 0 will be considered + * If the Item was successfully appraised, then the Player's skill will be increased. Else, 1 in 5 chance of increasing their skill + */ + void AttemptSkillUp(); +}; // class AppraisalGUI + +} // namespace GUI \ No newline at end of file From 956ec85e19c5015315d2a0ed0e28823dec76c20e Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:36:38 -0500 Subject: [PATCH 60/65] * Changed DrawGUI() to be public --- src/interface/AppraisalGUI.cpp | 85 +++++++++++++++++----------------- src/interface/AppraisalGUI.hpp | 8 ++-- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/interface/AppraisalGUI.cpp b/src/interface/AppraisalGUI.cpp index 188f1cafc..dc0ac685c 100644 --- a/src/interface/AppraisalGUI.cpp +++ b/src/interface/AppraisalGUI.cpp @@ -132,50 +132,9 @@ void AppraisalGUI::CloseGUI() localPlayerEntity = nullptr; } // CloseGUI() -/* AppraisalGUI.cpp - * @returns bIsActive - * Returns the status of whether or not the AppraisalGUI is currently active - */ -bool AppraisalGUI::IsGUIOpen() const -{ - return bIsActive; -} // IsGUIOpen() - -/* AppraisalGUI.cpp - * @param item - The Item being compared to 'itemToAppraise' - * @returns true - If the AppraisalGUI's currently appraising Item is the same as @item - * @returns false - If they are not the same - */ -bool AppraisalGUI::IsItemBeingAppraised(const Item* const item) const -{ - return (itemToAppraise == item); -} // IsItemBeingAppraised() - -/* AppraisalGUI.cpp - * @param item - A pointer to the Item having it's appraisal time evaluated - * @returns true - If @item's appraisal time is lower than 'lowestAppraisalTime' - * @returns false - Default case - * Evaluates and compares @item's appraisal time to 'lowestAppraisalTime'. In the event that it is shorter, 'lowestAppraisalTime' is set to @item's appraisal time - * Used for finding the next target for auto-appraisal - */ -bool AppraisalGUI::IsItemAppraisalTimeShortest(const Item* const item) -{ - Uint32 itemAppraisalTime = GetExternalItemAppraisalTime(item); - - // Check if the Item's appraisal time is lower than the previous lowest time - if ( itemAppraisalTime < lowestAppraisalTime ) - { - lowestAppraisalTime = itemAppraisalTime; - return true; - } - - return false; -} // IsItemAppraisalTimeShortest() - -// PRIVATE FUNCTIONS - /* AppraisalGUI.cpp * Draws the AppraisalGUI box, along with the text and Item icon. The GUI's position is shifted if the Player's Inventory is open + * Will not draw anything if AppraisalGUI is not active */ void AppraisalGUI::DrawGUI() { @@ -253,6 +212,48 @@ void AppraisalGUI::DrawGUI() drawImageScaled(itemSprite(itemToAppraise), nullptr, &appraisalBoxRect); } // DrawGUI() +/* AppraisalGUI.cpp + * @returns bIsActive + * Returns the status of whether or not the AppraisalGUI is currently active + */ +bool AppraisalGUI::IsGUIOpen() const +{ + return bIsActive; +} // IsGUIOpen() + +/* AppraisalGUI.cpp + * @param item - The Item being compared to 'itemToAppraise' + * @returns true - If the AppraisalGUI's currently appraising Item is the same as @item + * @returns false - If they are not the same + */ +bool AppraisalGUI::IsItemBeingAppraised(const Item* const item) const +{ + return (itemToAppraise == item); +} // IsItemBeingAppraised() + +/* AppraisalGUI.cpp + * @param item - A pointer to the Item having it's appraisal time evaluated + * @returns true - If @item's appraisal time is lower than 'lowestAppraisalTime' + * @returns false - Default case + * Evaluates and compares @item's appraisal time to 'lowestAppraisalTime'. In the event that it is shorter, 'lowestAppraisalTime' is set to @item's appraisal time + * Used for finding the next target for auto-appraisal + */ +bool AppraisalGUI::IsItemAppraisalTimeShortest(const Item* const item) +{ + Uint32 itemAppraisalTime = GetExternalItemAppraisalTime(item); + + // Check if the Item's appraisal time is lower than the previous lowest time + if ( itemAppraisalTime < lowestAppraisalTime ) + { + lowestAppraisalTime = itemAppraisalTime; + return true; + } + + return false; +} // IsItemAppraisalTimeShortest() + +// PRIVATE FUNCTIONS + /* AppraisalGUI.cpp * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks * Calculates the appraisal time of the selected appraisal target, 'itemToAppraise'. Value is used internally only diff --git a/src/interface/AppraisalGUI.hpp b/src/interface/AppraisalGUI.hpp index 0a9da6711..210946c99 100644 --- a/src/interface/AppraisalGUI.hpp +++ b/src/interface/AppraisalGUI.hpp @@ -42,6 +42,10 @@ class AppraisalGUI * Resets all member variables back to their base states */ void CloseGUI(); + /* AppraisalGUI.cpp + * Draws the AppraisalGUI box, along with the text and Item icon. The GUI's position is shifted if the Player's Inventory is open + */ + void DrawGUI(); /* AppraisalGUI.cpp * @returns bIsActive * Returns the status of whether or not the AppraisalGUI is currently active @@ -71,10 +75,6 @@ class AppraisalGUI Item* itemToAppraise = nullptr; // A pointer to the Item being appraised Entity* localPlayerEntity = nullptr; // A pointer to the Player who is preforming the appraisal, used for getting the PER of the Player, and for increasing their skill - /* AppraisalGUI.cpp - * Draws the AppraisalGUI box, along with the text and Item icon. The GUI's position is shifted if the Player's Inventory is open - */ - void DrawGUI(); /* AppraisalGUI.cpp * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks * Calculates the appraisal time of the selected appraisal target, 'itemToAppraise'. Value is used internally only From 855137b557482a2597abbdcb62230a65bca42b8e Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:37:10 -0500 Subject: [PATCH 61/65] * Replaced updateAppraisalItemBox() with AppraisalGUI->DrawGUI() --- src/game.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/game.cpp b/src/game.cpp index ff05806a0..e7525d1fc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3055,7 +3055,8 @@ int main(int argc, char** argv) } drawSustainedSpells(); - updateAppraisalItemBox(); + appraisalGUI->DrawGUI(); + //updateAppraisalItemBox(); // inventory and stats if ( shootmode == false ) From 9f08c2ebec7549ad3a253503fbc23c6af9933241 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 14:55:51 -0500 Subject: [PATCH 62/65] * Added the actual initialization statement that was forgotten --- src/interface/AppraisalGUI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/AppraisalGUI.cpp b/src/interface/AppraisalGUI.cpp index dc0ac685c..ce1a54472 100644 --- a/src/interface/AppraisalGUI.cpp +++ b/src/interface/AppraisalGUI.cpp @@ -23,7 +23,7 @@ AppraisalGUI::AppraisalGUI() : initialAppraisalTime(0), remainingAppraisalTime(0) { - std::numeric_limits::max(); + lowestAppraisalTime = std::numeric_limits::max(); } // AppraisalGUI() AppraisalGUI::~AppraisalGUI() From 29f4d75808168194f37891b78438bd154c447e69 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 21 Sep 2017 15:05:19 -0500 Subject: [PATCH 63/65] + Resolved merge conflict - Added missing lines --- lang/en.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lang/en.txt b/lang/en.txt index 5470aef93..2658e11e5 100644 --- a/lang/en.txt +++ b/lang/en.txt @@ -2899,6 +2899,18 @@ client (player %d) (direct ip)# 2271 spellbook# 2272 spellbook of reflect magic# 2273 spellbook# +2274 blank spellbook 1# +2275 spellbook# +2276 blank spellbook 2# +2277 spellbook# +2278 blank spellbook 3# +2279 spellbook# +2280 blank spellbook 4# +2281 spellbook# +2282 blank spellbook 5# +2283 spellbook# +2284 empty bottle# +2285 empty bottle# #Additional ingame text. 2350 A fragment breaks away from your %s.# From abb2b6d3f121957524dc9c83efba5f0480547d61 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 26 Sep 2017 16:37:04 -0500 Subject: [PATCH 64/65] * Fixed formatting (spaces -> tabs) --- src/actchest.cpp | 12 +- src/actplayer.cpp | 85 +- src/collision.cpp | 58 +- src/game.cpp | 75 +- src/init_game.cpp | 14 +- src/interface/AppraisalGUI.cpp | 446 +- src/interface/AppraisalGUI.hpp | 142 +- src/interface/ItemModifyingGUI.cpp | 6568 ++++++++++++++-------------- src/interface/ItemModifyingGUI.hpp | 514 +-- src/interface/clickdescription.cpp | 58 +- src/interface/drawstatus.cpp | 4 +- src/interface/interface.cpp | 2 +- src/interface/playerinventory.cpp | 168 +- src/items.cpp | 248 +- src/items.hpp | 20 +- src/magic/castSpell.cpp | 62 +- src/menu.cpp | 4 +- src/net.cpp | 684 +-- src/player.cpp | 66 +- src/player.hpp | 14 +- src/shops.cpp | 10 +- 21 files changed, 4571 insertions(+), 4683 deletions(-) diff --git a/src/actchest.cpp b/src/actchest.cpp index a17b02ec5..24cf4a448 100644 --- a/src/actchest.cpp +++ b/src/actchest.cpp @@ -494,12 +494,12 @@ void Entity::actChest() messagePlayer(chestclicked, language[459]); chestOpener = chestclicked; openedChest[chestclicked] = this; - - // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - itemModifyingGUI->CloseGUI(); - } + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + itemModifyingGUI->CloseGUI(); + } if (chestclicked != 0 && multiplayer == SERVER) { diff --git a/src/actplayer.cpp b/src/actplayer.cpp index 2752a1a08..64d6c7f0e 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -618,90 +618,13 @@ void actPlayer(Entity* my) } } - if ( PLAYER_NUM == clientnum ) - { - if ( appraisalGUI->IsGUIOpen() == true ) - { - appraisalGUI->UpdateGUI(); - } - } - - /* - if (PLAYER_NUM == clientnum && appraisal_timer > 0) + if ( PLAYER_NUM == clientnum ) { - Item* tempItem = uidToItem(appraisal_item); - if ( tempItem ) + if ( appraisalGUI->IsGUIOpen() == true ) { - if ( tempItem->identified ) - { - appraisal_timer = 0; - appraisal_item = 0; - } - else if ( tempItem->type == GEM_ROCK ) - { - //Auto-succeed on rocks. - tempItem->identified = true; - messagePlayer(clientnum, language[570], tempItem->description()); - appraisal_item = 0; - appraisal_timer = 0; - } - else - { - appraisal_timer -= 1; //De-increment appraisal timer. - if (appraisal_timer <= 0) - { - appraisal_timer = 0; - - //Cool. Time to identify the item. - bool success = false; - if ( stats[PLAYER_NUM]->PROFICIENCIES[PRO_APPRAISAL] < 100 ) - { - if ( tempItem->type != GEM_GLASS ) - { - success = (stats[PLAYER_NUM]->PROFICIENCIES[PRO_APPRAISAL] + my->getPER() * 5 >= items[tempItem->type].value / 10); - } - else - { - success = (stats[PLAYER_NUM]->PROFICIENCIES[PRO_APPRAISAL] + my->getPER() * 5 >= 100); - } - } - else - { - success = true; // always succeed when appraisal is maxed out - } - if ( success ) - { - tempItem->identified = true; - messagePlayer(clientnum, language[570], tempItem->description()); - } - else - { - messagePlayer(clientnum, language[571], tempItem->description()); - } - - //Attempt a level up. - if ( items[tempItem->type].value > 0 ) - { - if ( tempItem->identified ) - { - my->increaseSkill(PRO_APPRAISAL); - } - else if ( rand() % 5 == 0 ) - { - my->increaseSkill(PRO_APPRAISAL); - } - } - - appraisal_item = 0; - } - } + appraisalGUI->UpdateGUI(); } - else - { - appraisal_timer = 0; - appraisal_item = 0; - } - }*/ + } // remove broken equipment if ( stats[PLAYER_NUM]->helmet != NULL ) diff --git a/src/collision.cpp b/src/collision.cpp index 968ed29be..07dde5fc0 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -69,36 +69,36 @@ Entity* entityClicked() { return nullptr; } - if ( openedChest[clientnum] ) - { - if ( omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h ) - { - return nullptr; //Click falls inside the chest inventory GUI. - } - } - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - if ( itemModifyingGUI->IsMouseWithinGUIBounds() == true ) - { - return nullptr; // Click falls within the itemModifyingGUI's bounds - } - } - if ( book_open ) - { - if ( mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h) ) - { - return nullptr; //Click falls inside the book GUI. - } - } - if (gui_mode == GUI_MODE_INVENTORY || gui_mode == GUI_MODE_SHOP) + if ( openedChest[clientnum] ) { - if ( gui_mode == GUI_MODE_INVENTORY ) - { - if ( mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height) ) - { - return nullptr; //Click falls inside the right sidebar. - } - } + if ( omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h ) + { + return nullptr; //Click falls inside the chest inventory GUI. + } + } + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + if ( itemModifyingGUI->IsMouseWithinGUIBounds() == true ) + { + return nullptr; // Click falls within the itemModifyingGUI's bounds + } + } + if ( book_open ) + { + if ( mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h) ) + { + return nullptr; //Click falls inside the book GUI. + } + } + if ( gui_mode == GUI_MODE_INVENTORY || gui_mode == GUI_MODE_SHOP ) + { + if ( gui_mode == GUI_MODE_INVENTORY ) + { + if ( mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height) ) + { + return nullptr; //Click falls inside the right sidebar. + } + } //int x = std::max(character_bmp->w, xres/2-inventory_bmp->w/2); //if (mouseInBounds(x,x+inventory_bmp->w,0,inventory_bmp->h)) //return NULL; diff --git a/src/game.cpp b/src/game.cpp index e7525d1fc..5718c21c2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1019,14 +1019,14 @@ void gameLogic(void) } else { - // Items don't have to be dropped, auto-appraise a new Item if valid - if( auto_appraise_new_items && item->identified == false && appraisalGUI->IsGUIOpen() == false ) + // Items don't have to be dropped, auto-appraise a new Item if valid + if ( auto_appraise_new_items && item->identified == false && appraisalGUI->IsGUIOpen() == false ) { - // Check if the current Item has the lowest appraisal time, if it does, set appraisalGUI->lowestAppraisalTime = item's appraisal time - if ( appraisalGUI->IsItemAppraisalTimeShortest(item) == true ) - { - autoAppraiseTarget = item; - } + // Check if the current Item has the lowest appraisal time, if it does, set appraisalGUI->lowestAppraisalTime = item's appraisal time + if ( appraisalGUI->IsItemAppraisalTimeShortest(item) == true ) + { + autoAppraiseTarget = item; + } } } } @@ -1445,15 +1445,15 @@ void gameLogic(void) } else { - // Items don't have to be dropped, auto-appraise a new Item if valid - if ( auto_appraise_new_items && item->identified == false && appraisalGUI->IsGUIOpen() == false ) - { - // Check if the current Item has the lowest appraisal time, if it does, set appraisalGUI->lowestAppraisalTime = item's appraisal time - if ( appraisalGUI->IsItemAppraisalTimeShortest(item) == true ) - { - autoAppraiseTarget = item; - } - } + // Items don't have to be dropped, auto-appraise a new Item if valid + if ( auto_appraise_new_items && item->identified == false && appraisalGUI->IsGUIOpen() == false ) + { + // Check if the current Item has the lowest appraisal time, if it does, set appraisalGUI->lowestAppraisalTime = item's appraisal time + if ( appraisalGUI->IsItemAppraisalTimeShortest(item) == true ) + { + autoAppraiseTarget = item; + } + } } } @@ -1470,7 +1470,7 @@ void gameLogic(void) // If an Item was selected for auto-appraisal, open the AppraisalGUI if ( autoAppraiseTarget != nullptr ) { - appraisalGUI->OpenGUI(autoAppraiseTarget, players[clientnum]->entity); + appraisalGUI->OpenGUI(autoAppraiseTarget, players[clientnum]->entity); } } } @@ -2694,11 +2694,11 @@ int main(int argc, char** argv) shootmode = true; gui_mode = GUI_MODE_INVENTORY; - // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - itemModifyingGUI->CloseGUI(); - } + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + itemModifyingGUI->CloseGUI(); + } if ( shopkeeper != 0 ) { @@ -2801,13 +2801,13 @@ int main(int argc, char** argv) } else { - // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - itemModifyingGUI->CloseGUI(); - } + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + itemModifyingGUI->CloseGUI(); + } - shootmode = true; + shootmode = true; } //What even is this code? When should it be run? @@ -3028,14 +3028,14 @@ int main(int argc, char** argv) } else { - //Do these get called every frame? Might be better to move this stuff into an if (went_back_into_shootmode) { ... } thing. - //2-3 years later...yes, it is run every frame. + //Do these get called every frame? Might be better to move this stuff into an if (went_back_into_shootmode) { ... } thing. + //2-3 years later...yes, it is run every frame. - // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - itemModifyingGUI->CloseGUI(); - } + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + itemModifyingGUI->CloseGUI(); + } if ( book_open ) { @@ -3055,8 +3055,7 @@ int main(int argc, char** argv) } drawSustainedSpells(); - appraisalGUI->DrawGUI(); - //updateAppraisalItemBox(); + appraisalGUI->DrawGUI(); // inventory and stats if ( shootmode == false ) @@ -3066,7 +3065,7 @@ int main(int argc, char** argv) updateCharacterSheet(); updatePlayerInventory(); updateChestInventory(); - itemModifyingGUI->UpdateGUI(); + itemModifyingGUI->UpdateGUI(); updateBookGUI(); //updateRightSidebar(); diff --git a/src/init_game.cpp b/src/init_game.cpp index 3bca7773b..da1af42d9 100644 --- a/src/init_game.cpp +++ b/src/init_game.cpp @@ -493,8 +493,8 @@ int fmod_result; return -1; } - itemModifyingGUI = new GUI::ItemModifyingGUI; - appraisalGUI = new GUI::AppraisalGUI; + itemModifyingGUI = new GUI::ItemModifyingGUI; + appraisalGUI = new GUI::AppraisalGUI; return 0; } @@ -833,10 +833,10 @@ void deinitGame() } delete[] players; - // 9-5-2017 - Lutz - ItemModifyingGUI Refactor - delete itemModifyingGUI; - itemModifyingGUI = nullptr; + // 9-5-2017 - Lutz - ItemModifyingGUI Refactor + delete itemModifyingGUI; + itemModifyingGUI = nullptr; - delete appraisalGUI; - appraisalGUI = nullptr; + delete appraisalGUI; + appraisalGUI = nullptr; } diff --git a/src/interface/AppraisalGUI.cpp b/src/interface/AppraisalGUI.cpp index ce1a54472..170e9d25d 100644 --- a/src/interface/AppraisalGUI.cpp +++ b/src/interface/AppraisalGUI.cpp @@ -19,18 +19,18 @@ namespace GUI { AppraisalGUI::AppraisalGUI() : - bIsActive(false), - initialAppraisalTime(0), - remainingAppraisalTime(0) + bIsActive(false), + initialAppraisalTime(0), + remainingAppraisalTime(0) { - lowestAppraisalTime = std::numeric_limits::max(); + lowestAppraisalTime = std::numeric_limits::max(); } // AppraisalGUI() AppraisalGUI::~AppraisalGUI() { - CloseGUI(); - itemToAppraise = nullptr; - localPlayerEntity = nullptr; + CloseGUI(); + itemToAppraise = nullptr; + localPlayerEntity = nullptr; } // ~AppraisalGUI() /* AppraisalGUI.cpp @@ -41,40 +41,40 @@ AppraisalGUI::~AppraisalGUI() */ void AppraisalGUI::OpenGUI(Item* const appraisalItem, Entity* const localPlayer) { - // If a GUI is already opened, close the GUI before opening the new one - if ( bIsActive == true ) - { - CloseGUI(); - } - - // Update the Appraisal GUI - bIsActive = true; - itemToAppraise = appraisalItem; - localPlayerEntity = localPlayer; - - // If the Player has is Legendary in Appraisal then complete the action immediately - if ( stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] >= CAPSTONE_UNLOCK_LEVEL[PRO_APPRAISAL] ) - { - itemToAppraise->identified = true; - messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." - AttemptSkillUp(); - CloseGUI(); - return; - } - else if ( itemToAppraise->type == GEM_ROCK ) // Rocks are appraised instantly - { - itemToAppraise->identified = true; - messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." - AttemptSkillUp(); - CloseGUI(); - return; - } - - // Since it wasn't autocompleted, initialize the appraisal timer - initialAppraisalTime = GetGUIItemAppraisalTime(); - remainingAppraisalTime = initialAppraisalTime; - - messagePlayer(clientnum, language[321], appraisalItem->description()); // "Appraising "%s"..." + // If a GUI is already opened, close the GUI before opening the new one + if ( bIsActive == true ) + { + CloseGUI(); + } + + // Update the Appraisal GUI + bIsActive = true; + itemToAppraise = appraisalItem; + localPlayerEntity = localPlayer; + + // If the Player has is Legendary in Appraisal then complete the action immediately + if ( stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] >= CAPSTONE_UNLOCK_LEVEL[PRO_APPRAISAL] ) + { + itemToAppraise->identified = true; + messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." + AttemptSkillUp(); + CloseGUI(); + return; + } + else if ( itemToAppraise->type == GEM_ROCK ) // Rocks are appraised instantly + { + itemToAppraise->identified = true; + messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." + AttemptSkillUp(); + CloseGUI(); + return; + } + + // Since it wasn't autocompleted, initialize the appraisal timer + initialAppraisalTime = GetGUIItemAppraisalTime(); + remainingAppraisalTime = initialAppraisalTime; + + messagePlayer(clientnum, language[321], appraisalItem->description()); // "Appraising "%s"..." } // OpenGUI() /* AppraisalGUI.cpp @@ -84,38 +84,38 @@ void AppraisalGUI::OpenGUI(Item* const appraisalItem, Entity* const localPlayer) */ void AppraisalGUI::UpdateGUI() { - // If the GUI is not active, there is no reason to go further - if ( bIsActive != true ) - { - return; - } - - // The GUI should never be active with the itemToAppraise being null - if ( itemToAppraise == nullptr ) - { - printlog("ERROR: updateAppraisalGUI() - itemToAppraise is null."); - CloseGUI(); - return; - } - - remainingAppraisalTime--; // Tick downward while appraising - - if ( remainingAppraisalTime == 0 ) - { - if ( IsAppraisalSuccessful() == true ) - { - itemToAppraise->identified = true; - messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." - AttemptSkillUp(); - CloseGUI(); - } - else - { - messagePlayer(clientnum, language[571], itemToAppraise->description()); // "Failed to identify "%s"." - AttemptSkillUp(); - CloseGUI(); - } - } + // If the GUI is not active, there is no reason to go further + if ( bIsActive != true ) + { + return; + } + + // The GUI should never be active with the itemToAppraise being null + if ( itemToAppraise == nullptr ) + { + printlog("ERROR: updateAppraisalGUI() - itemToAppraise is null."); + CloseGUI(); + return; + } + + remainingAppraisalTime--; // Tick downward while appraising + + if ( remainingAppraisalTime == 0 ) + { + if ( IsAppraisalSuccessful() == true ) + { + itemToAppraise->identified = true; + messagePlayer(clientnum, language[320], itemToAppraise->description()); // "Identified "%s"." + AttemptSkillUp(); + CloseGUI(); + } + else + { + messagePlayer(clientnum, language[571], itemToAppraise->description()); // "Failed to identify "%s"." + AttemptSkillUp(); + CloseGUI(); + } + } } // UpdateGUI() /* AppraisalGUI.cpp @@ -123,13 +123,13 @@ void AppraisalGUI::UpdateGUI() */ void AppraisalGUI::CloseGUI() { - bIsActive = false; - initialAppraisalTime = 0; - remainingAppraisalTime = 0; - lowestAppraisalTime = std::numeric_limits::max(); + bIsActive = false; + initialAppraisalTime = 0; + remainingAppraisalTime = 0; + lowestAppraisalTime = std::numeric_limits::max(); - itemToAppraise = nullptr; - localPlayerEntity = nullptr; + itemToAppraise = nullptr; + localPlayerEntity = nullptr; } // CloseGUI() /* AppraisalGUI.cpp @@ -138,78 +138,78 @@ void AppraisalGUI::CloseGUI() */ void AppraisalGUI::DrawGUI() { - if ( bIsActive == false ) - { - return; - } - - if ( itemToAppraise == nullptr ) - { - CloseGUI(); - return; - } - - // The offset of the Appraisal GUI when the Inventory is open - const Sint32 appraisalBox_OffsetX = ((xres) / 2 - (INVENTORY_SIZEX)*(INVENTORY_SLOTSIZE) / 2 - inventory_mode_item_img->w / 2); - const Sint32 appraisalBox_OffsetY = 10; - - // Draw the Appraisal GUI Box - SDL_Rect appraisalBoxRect; - - // If the Player is in an Inventory, offset so it isn't in the way - if ( shootmode == false ) - { - appraisalBoxRect.x = appraisalBox_OffsetX + 16; - appraisalBoxRect.y = appraisalBox_OffsetY + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16; - } - else - { - appraisalBoxRect.x = 16; - appraisalBoxRect.y = 16; - } - - int appraisingTextWidth = 0; // The width of the text "Appraising: " - int itemNameTextWidth = 0; // The width of the text of the name of the Item being appraised - - // Get the size of the text within the Appraisal GUI Box - TTF_SizeUTF8(ttf12, language[340], &appraisingTextWidth, nullptr); - TTF_SizeUTF8(ttf12, itemToAppraise->getName(), &itemNameTextWidth, nullptr); - - // Resize the Appraisal GUI Box based on the text within it - itemNameTextWidth += 48; - appraisalBoxRect.w = std::max(appraisingTextWidth, itemNameTextWidth) + 8; - appraisalBoxRect.h = 68; - - // Draw the actual Appraisal GUI Box - drawTooltip(&appraisalBoxRect); - - // Draw the appraising timer % in the Appraisal GUI Box - char appraisalBoxFormattedText[64] = {0}; - snprintf(appraisalBoxFormattedText, 63, language[341], ((static_cast((initialAppraisalTime - remainingAppraisalTime))) / (static_cast(initialAppraisalTime))) * 100); // "Appraising:%3.0f%%" - ttfPrintText(ttf12, appraisalBoxRect.x + 8, appraisalBoxRect.y + 8, appraisalBoxFormattedText); - - // Draw the Item's Sprite and name - //SDL_Rect itemSpriteRect; - - // If the Player is in an Inventory, offset so it isn't in the way - if ( shootmode == false ) - { - appraisalBoxRect.x = appraisalBox_OffsetX + 24; - appraisalBoxRect.y = appraisalBox_OffsetY + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16 + 24; - } - else - { - appraisalBoxRect.x = 24; - appraisalBoxRect.y = 16 + 24; - } - - // Draw the name of the Item being appraised - ttfPrintText(ttf12, appraisalBoxRect.x + 40, appraisalBoxRect.y + 8, itemToAppraise->getName()); - appraisalBoxRect.w = 32; - appraisalBoxRect.h = 32; - - // Draw the Sprite of the Item being appraised - drawImageScaled(itemSprite(itemToAppraise), nullptr, &appraisalBoxRect); + if ( bIsActive == false ) + { + return; + } + + if ( itemToAppraise == nullptr ) + { + CloseGUI(); + return; + } + + // The offset of the Appraisal GUI when the Inventory is open + const Sint32 appraisalBox_OffsetX = ((xres) / 2 - (INVENTORY_SIZEX)*(INVENTORY_SLOTSIZE) / 2 - inventory_mode_item_img->w / 2); + const Sint32 appraisalBox_OffsetY = 10; + + // Draw the Appraisal GUI Box + SDL_Rect appraisalBoxRect; + + // If the Player is in an Inventory, offset so it isn't in the way + if ( shootmode == false ) + { + appraisalBoxRect.x = appraisalBox_OffsetX + 16; + appraisalBoxRect.y = appraisalBox_OffsetY + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16; + } + else + { + appraisalBoxRect.x = 16; + appraisalBoxRect.y = 16; + } + + int appraisingTextWidth = 0; // The width of the text "Appraising: " + int itemNameTextWidth = 0; // The width of the text of the name of the Item being appraised + + // Get the size of the text within the Appraisal GUI Box + TTF_SizeUTF8(ttf12, language[340], &appraisingTextWidth, nullptr); + TTF_SizeUTF8(ttf12, itemToAppraise->getName(), &itemNameTextWidth, nullptr); + + // Resize the Appraisal GUI Box based on the text within it + itemNameTextWidth += 48; + appraisalBoxRect.w = std::max(appraisingTextWidth, itemNameTextWidth) + 8; + appraisalBoxRect.h = 68; + + // Draw the actual Appraisal GUI Box + drawTooltip(&appraisalBoxRect); + + // Draw the appraising timer % in the Appraisal GUI Box + char appraisalBoxFormattedText[64] = {0}; + snprintf(appraisalBoxFormattedText, 63, language[341], ((static_cast((initialAppraisalTime - remainingAppraisalTime))) / (static_cast(initialAppraisalTime))) * 100); // "Appraising:%3.0f%%" + ttfPrintText(ttf12, appraisalBoxRect.x + 8, appraisalBoxRect.y + 8, appraisalBoxFormattedText); + + // Draw the Item's Sprite and name + //SDL_Rect itemSpriteRect; + + // If the Player is in an Inventory, offset so it isn't in the way + if ( shootmode == false ) + { + appraisalBoxRect.x = appraisalBox_OffsetX + 24; + appraisalBoxRect.y = appraisalBox_OffsetY + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16 + 24; + } + else + { + appraisalBoxRect.x = 24; + appraisalBoxRect.y = 16 + 24; + } + + // Draw the name of the Item being appraised + ttfPrintText(ttf12, appraisalBoxRect.x + 40, appraisalBoxRect.y + 8, itemToAppraise->getName()); + appraisalBoxRect.w = 32; + appraisalBoxRect.h = 32; + + // Draw the Sprite of the Item being appraised + drawImageScaled(itemSprite(itemToAppraise), nullptr, &appraisalBoxRect); } // DrawGUI() /* AppraisalGUI.cpp @@ -218,7 +218,7 @@ void AppraisalGUI::DrawGUI() */ bool AppraisalGUI::IsGUIOpen() const { - return bIsActive; + return bIsActive; } // IsGUIOpen() /* AppraisalGUI.cpp @@ -228,7 +228,7 @@ bool AppraisalGUI::IsGUIOpen() const */ bool AppraisalGUI::IsItemBeingAppraised(const Item* const item) const { - return (itemToAppraise == item); + return (itemToAppraise == item); } // IsItemBeingAppraised() /* AppraisalGUI.cpp @@ -238,18 +238,18 @@ bool AppraisalGUI::IsItemBeingAppraised(const Item* const item) const * Evaluates and compares @item's appraisal time to 'lowestAppraisalTime'. In the event that it is shorter, 'lowestAppraisalTime' is set to @item's appraisal time * Used for finding the next target for auto-appraisal */ -bool AppraisalGUI::IsItemAppraisalTimeShortest(const Item* const item) +bool AppraisalGUI::IsItemAppraisalTimeShortest(const Item* const item) { - Uint32 itemAppraisalTime = GetExternalItemAppraisalTime(item); + Uint32 itemAppraisalTime = GetExternalItemAppraisalTime(item); - // Check if the Item's appraisal time is lower than the previous lowest time - if ( itemAppraisalTime < lowestAppraisalTime ) - { - lowestAppraisalTime = itemAppraisalTime; - return true; - } + // Check if the Item's appraisal time is lower than the previous lowest time + if ( itemAppraisalTime < lowestAppraisalTime ) + { + lowestAppraisalTime = itemAppraisalTime; + return true; + } - return false; + return false; } // IsItemAppraisalTimeShortest() // PRIVATE FUNCTIONS @@ -260,23 +260,23 @@ bool AppraisalGUI::IsItemAppraisalTimeShortest(const Item* const item) */ Uint32 AppraisalGUI::GetGUIItemAppraisalTime() const { - Uint32 calculatedTime = 0; // The time calculated based on the type and value of the Item and Proficiency of the Player - - if ( itemToAppraise->type != GEM_GLASS ) - { - // All Items other than Worthless glass have an appraisal time based on their value, reduced by the Player's proficiency - calculatedTime = (items[itemToAppraise->type].value * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); - } - else - { - // Worthless glass has a flat time of 60,000 ticks, reduced by the Player's proficiency - calculatedTime = (1000 * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); - } - - // Appraisal time has a minimum of 1 tick and a maximum of 36,000 ticks - calculatedTime = std::min(std::max(1, static_cast(calculatedTime)), 36000); - - return calculatedTime; + Uint32 calculatedTime = 0; // The time calculated based on the type and value of the Item and Proficiency of the Player + + if ( itemToAppraise->type != GEM_GLASS ) + { + // All Items other than Worthless glass have an appraisal time based on their value, reduced by the Player's proficiency + calculatedTime = (items[itemToAppraise->type].value * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + else + { + // Worthless glass has a flat time of 60,000 ticks, reduced by the Player's proficiency + calculatedTime = (1000 * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + + // Appraisal time has a minimum of 1 tick and a maximum of 36,000 ticks + calculatedTime = std::min(std::max(1, static_cast(calculatedTime)), 36000); + + return calculatedTime; } // GetGUIItemAppraisalTime() /* AppraisalGUI.cpp @@ -284,25 +284,25 @@ Uint32 AppraisalGUI::GetGUIItemAppraisalTime() const * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks * Calculates the appraisal time of the given Item, @item. Value is used for IsItemAppraisalTimeShortest() for finding the next auto-appraise target */ -Uint32 AppraisalGUI::GetExternalItemAppraisalTime(const Item* const item) +Uint32 AppraisalGUI::GetExternalItemAppraisalTime(const Item* const item) { - Uint32 calculatedTime = 0; // The time calculated based on the type and value of the Item and Proficiency of the Player - - if ( item->type != GEM_GLASS ) - { - // All Items other than Worthless glass have an appraisal time based on their value, reduced by the Player's proficiency - calculatedTime = (items[item->type].value * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); - } - else - { - // Worthless glass has a flat time of 60,000 ticks, reduced by the Player's proficiency - calculatedTime = (1000 * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); - } - - // Appraisal time has a minimum of 1 tick and a maximum of 36,000 ticks - calculatedTime = std::min(std::max(1, static_cast(calculatedTime)), 36000); - - return calculatedTime; + Uint32 calculatedTime = 0; // The time calculated based on the type and value of the Item and Proficiency of the Player + + if ( item->type != GEM_GLASS ) + { + // All Items other than Worthless glass have an appraisal time based on their value, reduced by the Player's proficiency + calculatedTime = (items[item->type].value * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + else + { + // Worthless glass has a flat time of 60,000 ticks, reduced by the Player's proficiency + calculatedTime = (1000 * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); + } + + // Appraisal time has a minimum of 1 tick and a maximum of 36,000 ticks + calculatedTime = std::min(std::max(1, static_cast(calculatedTime)), 36000); + + return calculatedTime; } // GetExternalItemAppraisalTime() /* AppraisalGUI.cpp @@ -313,20 +313,20 @@ Uint32 AppraisalGUI::GetExternalItemAppraisalTime(const Item* const item) */ bool AppraisalGUI::IsAppraisalSuccessful() { - bool bIsAppraisalSuccessful = false; - - if ( itemToAppraise->type != GEM_GLASS ) - { - // For Items other than Worthless glass, (Prof + (PER * 5)) must be >= to (ItemValue / 10) - bIsAppraisalSuccessful = ((stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + (localPlayerEntity->getPER() * 5)) >= (items[itemToAppraise->type].value / 10)); - } - else - { - // For Worthless glass, (Prof + (PER * 5)) must be >= to 100 - bIsAppraisalSuccessful = ((stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + (localPlayerEntity->getPER() * 5)) >= 100); - } - - return bIsAppraisalSuccessful; + bool bIsAppraisalSuccessful = false; + + if ( itemToAppraise->type != GEM_GLASS ) + { + // For Items other than Worthless glass, (Prof + (PER * 5)) must be >= to (ItemValue / 10) + bIsAppraisalSuccessful = ((stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + (localPlayerEntity->getPER() * 5)) >= (items[itemToAppraise->type].value / 10)); + } + else + { + // For Worthless glass, (Prof + (PER * 5)) must be >= to 100 + bIsAppraisalSuccessful = ((stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + (localPlayerEntity->getPER() * 5)) >= 100); + } + + return bIsAppraisalSuccessful; } // IsAppraisalSuccessful() /* AppraisalGUI.cpp @@ -335,18 +335,18 @@ bool AppraisalGUI::IsAppraisalSuccessful() */ void AppraisalGUI::AttemptSkillUp() { - if ( items[itemToAppraise->type].value > 0 ) - { - // If the Player succeeded in appraising the Item, increase their skill - if ( itemToAppraise->identified ) - { - localPlayerEntity->increaseSkill(PRO_APPRAISAL); - } - else if ( rand() % 5 == 0 ) // Else random chance for an increase - { - localPlayerEntity->increaseSkill(PRO_APPRAISAL); - } - } + if ( items[itemToAppraise->type].value > 0 ) + { + // If the Player succeeded in appraising the Item, increase their skill + if ( itemToAppraise->identified ) + { + localPlayerEntity->increaseSkill(PRO_APPRAISAL); + } + else if ( rand() % 5 == 0 ) // Else random chance for an increase + { + localPlayerEntity->increaseSkill(PRO_APPRAISAL); + } + } } // AttemptSkillUp() } // namespace GUI \ No newline at end of file diff --git a/src/interface/AppraisalGUI.hpp b/src/interface/AppraisalGUI.hpp index 210946c99..81930d83d 100644 --- a/src/interface/AppraisalGUI.hpp +++ b/src/interface/AppraisalGUI.hpp @@ -22,82 +22,82 @@ class AppraisalGUI { public: - AppraisalGUI(); - ~AppraisalGUI(); + AppraisalGUI(); + ~AppraisalGUI(); - /* AppraisalGUI.cpp - * @param appraisalItem - A pointer to the Item that is going to be appraised - * @param localPlayer - A pointer to the Entity of the Player who is appraising (Local Player only), used for accessing their skill and PER Stats - * Initializes the GUI, with two initial checks for instantaneous appraisal. If the Player's appraisal skill is >= 100 or the Item is a GEM_ROCK - * In the case of a non-instant appraisal, 'initialAppraisalTime' is calculated and 'remainingAppraisalTime' is set to 'initialAppraisalTime' - */ - void OpenGUI(Item* const apprisalItem, Entity* const localPlayer); - /* AppraisalGUI.cpp - * Handles the updating of the appraisal timer by decreasing 'remainingAppraisalTime' by 1 every call (every tick) - * Once 'remainingAppraisalTime' == 0, IsAppraisalSuccessful() will be called. On success, the Item is Identified - * In both success and failure cases, the Player is messaged on the result, and AttemptSkillUp() is called before closing the GUI - */ - void UpdateGUI(); - /* AppraisalGUI.cpp - * Resets all member variables back to their base states - */ - void CloseGUI(); - /* AppraisalGUI.cpp - * Draws the AppraisalGUI box, along with the text and Item icon. The GUI's position is shifted if the Player's Inventory is open - */ - void DrawGUI(); - /* AppraisalGUI.cpp - * @returns bIsActive - * Returns the status of whether or not the AppraisalGUI is currently active - */ - bool IsGUIOpen() const; - /* AppraisalGUI.cpp - * @param item - The Item being compared to 'itemToAppraise' - * @returns true - If the AppraisalGUI's currently appraising Item is the same as @item - * @returns false - If they are not the same - */ - bool IsItemBeingAppraised(const Item* const item) const; - /* AppraisalGUI.cpp - * @param item - A pointer to the Item having it's appraisal time evaluated - * @returns true - If @item's appraisal time is lower than 'lowestAppraisalTime' - * @returns false - Default case - * Evaluates and compares @item's appraisal time to 'lowestAppraisalTime'. In the event that it is shorter, 'lowestAppraisalTime' is set to @item's appraisal time - * Used for finding the next target for auto-appraisal - */ - bool IsItemAppraisalTimeShortest(const Item* const item); + /* AppraisalGUI.cpp + * @param appraisalItem - A pointer to the Item that is going to be appraised + * @param localPlayer - A pointer to the Entity of the Player who is appraising (Local Player only), used for accessing their skill and PER Stats + * Initializes the GUI, with two initial checks for instantaneous appraisal. If the Player's appraisal skill is >= 100 or the Item is a GEM_ROCK + * In the case of a non-instant appraisal, 'initialAppraisalTime' is calculated and 'remainingAppraisalTime' is set to 'initialAppraisalTime' + */ + void OpenGUI(Item* const apprisalItem, Entity* const localPlayer); + /* AppraisalGUI.cpp + * Handles the updating of the appraisal timer by decreasing 'remainingAppraisalTime' by 1 every call (every tick) + * Once 'remainingAppraisalTime' == 0, IsAppraisalSuccessful() will be called. On success, the Item is Identified + * In both success and failure cases, the Player is messaged on the result, and AttemptSkillUp() is called before closing the GUI + */ + void UpdateGUI(); + /* AppraisalGUI.cpp + * Resets all member variables back to their base states + */ + void CloseGUI(); + /* AppraisalGUI.cpp + * Draws the AppraisalGUI box, along with the text and Item icon. The GUI's position is shifted if the Player's Inventory is open + */ + void DrawGUI(); + /* AppraisalGUI.cpp + * @returns bIsActive + * Returns the status of whether or not the AppraisalGUI is currently active + */ + bool IsGUIOpen() const; + /* AppraisalGUI.cpp + * @param item - The Item being compared to 'itemToAppraise' + * @returns true - If the AppraisalGUI's currently appraising Item is the same as @item + * @returns false - If they are not the same + */ + bool IsItemBeingAppraised(const Item* const item) const; + /* AppraisalGUI.cpp + * @param item - A pointer to the Item having it's appraisal time evaluated + * @returns true - If @item's appraisal time is lower than 'lowestAppraisalTime' + * @returns false - Default case + * Evaluates and compares @item's appraisal time to 'lowestAppraisalTime'. In the event that it is shorter, 'lowestAppraisalTime' is set to @item's appraisal time + * Used for finding the next target for auto-appraisal + */ + bool IsItemAppraisalTimeShortest(const Item* const item); private: - bool bIsActive; // Flag for whether or not the AppraisalGUI is currently displayed - Uint32 initialAppraisalTime; // The initial appraisal time, calculated by GetGUIItemAppraisalTime() - Uint32 remainingAppraisalTime; // The remaining time before the appraisal is finished, originally set to initialAppraisalTime - Uint32 lowestAppraisalTime; // The lowest appraisal time out of all Items in the Player's Inventory that can be auto-appraised + bool bIsActive; // Flag for whether or not the AppraisalGUI is currently displayed + Uint32 initialAppraisalTime; // The initial appraisal time, calculated by GetGUIItemAppraisalTime() + Uint32 remainingAppraisalTime; // The remaining time before the appraisal is finished, originally set to initialAppraisalTime + Uint32 lowestAppraisalTime; // The lowest appraisal time out of all Items in the Player's Inventory that can be auto-appraised - Item* itemToAppraise = nullptr; // A pointer to the Item being appraised - Entity* localPlayerEntity = nullptr; // A pointer to the Player who is preforming the appraisal, used for getting the PER of the Player, and for increasing their skill + Item* itemToAppraise = nullptr; // A pointer to the Item being appraised + Entity* localPlayerEntity = nullptr; // A pointer to the Player who is preforming the appraisal, used for getting the PER of the Player, and for increasing their skill - /* AppraisalGUI.cpp - * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks - * Calculates the appraisal time of the selected appraisal target, 'itemToAppraise'. Value is used internally only - */ - Uint32 GetGUIItemAppraisalTime() const; - /* AppraisalGUI.cpp - * @param item - A pointer to the Item that is having the appraisal time calculated - * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks - * Calculates the appraisal time of the given Item, @item. Value is used for IsItemAppraisalTimeShortest() for finding the next auto-appraise target - */ - Uint32 GetExternalItemAppraisalTime(const Item* const item); - /* AppraisalGUI.cpp - * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 'itemToAppraise' value / 10 WHEN itemToAppraise->type != GEM_GLASS - * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 100 WHEN itemToAppraise->type == GEM_GLASS - * @returns false - Default case - * Calculates whether or not the appraisal is successful, based off the Player's appraisal skill and PER - */ - bool IsAppraisalSuccessful(); - /* AppraisalGUI.cpp - * Checks to see if the Player's appraisal skill should be increased. Only Items with a value above 0 will be considered - * If the Item was successfully appraised, then the Player's skill will be increased. Else, 1 in 5 chance of increasing their skill - */ - void AttemptSkillUp(); + /* AppraisalGUI.cpp + * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks + * Calculates the appraisal time of the selected appraisal target, 'itemToAppraise'. Value is used internally only + */ + Uint32 GetGUIItemAppraisalTime() const; + /* AppraisalGUI.cpp + * @param item - A pointer to the Item that is having the appraisal time calculated + * @returns - The calcuated appraisal time based off of (value * 60) / (PRO_APPRAISAL + 1). Minimum of 1, maximum of 36,000 ticks + * Calculates the appraisal time of the given Item, @item. Value is used for IsItemAppraisalTimeShortest() for finding the next auto-appraise target + */ + Uint32 GetExternalItemAppraisalTime(const Item* const item); + /* AppraisalGUI.cpp + * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 'itemToAppraise' value / 10 WHEN itemToAppraise->type != GEM_GLASS + * @returns true - If the Player's Appraisal Skill + (PER * 5) is >= 100 WHEN itemToAppraise->type == GEM_GLASS + * @returns false - Default case + * Calculates whether or not the appraisal is successful, based off the Player's appraisal skill and PER + */ + bool IsAppraisalSuccessful(); + /* AppraisalGUI.cpp + * Checks to see if the Player's appraisal skill should be increased. Only Items with a value above 0 will be considered + * If the Item was successfully appraised, then the Player's skill will be increased. Else, 1 in 5 chance of increasing their skill + */ + void AttemptSkillUp(); }; // class AppraisalGUI } // namespace GUI \ No newline at end of file diff --git a/src/interface/ItemModifyingGUI.cpp b/src/interface/ItemModifyingGUI.cpp index a09fa4b7d..ef87cc165 100644 --- a/src/interface/ItemModifyingGUI.cpp +++ b/src/interface/ItemModifyingGUI.cpp @@ -21,23 +21,23 @@ namespace GUI { ItemModifyingGUI::ItemModifyingGUI() : - bIsActive(false), - bIsCursed(false), - bIsItemModifyingGUI_Dragging(false), - itemModifyingGUI_ScrollBeatitude(0), - itemModifyingGUI_Type(0), - itemModifyingGUI_InventoryScrollOffset(0), - itemModifyingGUI_InventorySelectedSlot(-1), - itemModifyingGUI_OffsetX(0), - itemModifyingGUI_OffsetY(0) + bIsActive(false), + bIsCursed(false), + bIsItemModifyingGUI_Dragging(false), + itemModifyingGUI_ScrollBeatitude(0), + itemModifyingGUI_Type(0), + itemModifyingGUI_InventoryScrollOffset(0), + itemModifyingGUI_InventorySelectedSlot(-1), + itemModifyingGUI_OffsetX(0), + itemModifyingGUI_OffsetY(0) { - itemModifyingGUI_IMG = loadImage("images/system/itemModifyingGUI.png"); + itemModifyingGUI_IMG = loadImage("images/system/itemModifyingGUI.png"); } // ItemModifyingGUI() ItemModifyingGUI::~ItemModifyingGUI() { - CloseGUI(); - FreeImage(); + CloseGUI(); + FreeImage(); } // ~ItemModifyingGUI() /* ItemModifyingGUI.cpp @@ -50,93 +50,93 @@ ItemModifyingGUI::~ItemModifyingGUI() */ void ItemModifyingGUI::OpenGUI(const Uint8 GUIType, Item* const scrollUsed) { - // If a GUI is already opened, close the GUI before opening the new one - if ( bIsActive == true ) - { - CloseGUI(); - } - - // Initialize the values for the GUI - bIsActive = true; - - itemModifyingGUI_Type = GUIType; - itemModifyingGUI_ScrollUsed = scrollUsed; - - // Check to see if a Scroll is being used to open the GUI - if ( itemModifyingGUI_ScrollUsed != nullptr ) - { - itemModifyingGUI_ScrollBeatitude = itemModifyingGUI_ScrollUsed->beatitude; - if ( itemModifyingGUI_ScrollBeatitude < 0 ) - { - bIsCursed = true; - } - - // If the Scroll is Unidentified, Identify it and message the Player what type of Scroll it is - if ( itemModifyingGUI_ScrollUsed->identified == false ) - { - itemModifyingGUI_ScrollUsed->identified = true; - switch ( itemModifyingGUI_Type ) - { - case 0: // Identify - messagePlayer(clientnum, language[849]); // "This is a scroll of identify!" - break; - case 1: // Remove Curse - messagePlayer(clientnum, language[2501]); // "This is a scroll of remove curse!" - break; - case 2: // Repair - messagePlayer(clientnum, language[2502]); // "This is a scroll of repair!" - break; - case 3: // Enchant Weapon - messagePlayer(clientnum, language[2503]); // "This is a scroll of Enchant weapon!" - break; - case 4: // Enchant Armor - messagePlayer(clientnum, language[2504]); // "This is a scroll of Enchant armor!" - break; - default: printlog("ERROR: UpdateGUI() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; - } - } - } - - // Build the GUI's Inventory for an initial check - ItemModifyingGUI_RebuildInventory(); - - // If the Inventory is empty, there is nothing to process. The GUI will not open and nothing will be processed - if ( itemModifyingGUI_Inventory[0] == nullptr ) - { - // If it is a Cursed Scroll and there are no valid Items, still use up the Scroll - if ( itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[863]); // "The scroll smokes and crumbles to ash!" - - // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed - if ( itemModifyingGUI_ScrollUsed == nullptr ) - { - printlog("ERROR: UpdateGUI() - A Cursed Spell has opened the GUI. This should never happen."); - return; - } - - consumeItem(itemModifyingGUI_ScrollUsed); - CloseGUI(); - return; - } - messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" - CloseGUI(); - return; - } - else - { - // Open the Inventory, this is for Spells, as they can open the GUI without having the Inventory open - shootmode = false; - gui_mode = GUI_MODE_INVENTORY; - - // If the Scroll is Cursed, don't warp the Mouse - if ( itemModifyingGUI_ScrollBeatitude >= 0 ) - { - // The actual logic is handled by UpdateGUI() - itemModifyingGUI_InventorySelectedSlot = 0; - WarpMouseToSelectedGUISlot(); - } - } + // If a GUI is already opened, close the GUI before opening the new one + if ( bIsActive == true ) + { + CloseGUI(); + } + + // Initialize the values for the GUI + bIsActive = true; + + itemModifyingGUI_Type = GUIType; + itemModifyingGUI_ScrollUsed = scrollUsed; + + // Check to see if a Scroll is being used to open the GUI + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + itemModifyingGUI_ScrollBeatitude = itemModifyingGUI_ScrollUsed->beatitude; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + bIsCursed = true; + } + + // If the Scroll is Unidentified, Identify it and message the Player what type of Scroll it is + if ( itemModifyingGUI_ScrollUsed->identified == false ) + { + itemModifyingGUI_ScrollUsed->identified = true; + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + messagePlayer(clientnum, language[849]); // "This is a scroll of identify!" + break; + case 1: // Remove Curse + messagePlayer(clientnum, language[2501]); // "This is a scroll of remove curse!" + break; + case 2: // Repair + messagePlayer(clientnum, language[2502]); // "This is a scroll of repair!" + break; + case 3: // Enchant Weapon + messagePlayer(clientnum, language[2503]); // "This is a scroll of Enchant weapon!" + break; + case 4: // Enchant Armor + messagePlayer(clientnum, language[2504]); // "This is a scroll of Enchant armor!" + break; + default: printlog("ERROR: UpdateGUI() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } + } + } + + // Build the GUI's Inventory for an initial check + ItemModifyingGUI_RebuildInventory(); + + // If the Inventory is empty, there is nothing to process. The GUI will not open and nothing will be processed + if ( itemModifyingGUI_Inventory[0] == nullptr ) + { + // If it is a Cursed Scroll and there are no valid Items, still use up the Scroll + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[863]); // "The scroll smokes and crumbles to ash!" + + // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed + if ( itemModifyingGUI_ScrollUsed == nullptr ) + { + printlog("ERROR: UpdateGUI() - A Cursed Spell has opened the GUI. This should never happen."); + return; + } + + consumeItem(itemModifyingGUI_ScrollUsed); + CloseGUI(); + return; + } + messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" + CloseGUI(); + return; + } + else + { + // Open the Inventory, this is for Spells, as they can open the GUI without having the Inventory open + shootmode = false; + gui_mode = GUI_MODE_INVENTORY; + + // If the Scroll is Cursed, don't warp the Mouse + if ( itemModifyingGUI_ScrollBeatitude >= 0 ) + { + // The actual logic is handled by UpdateGUI() + itemModifyingGUI_InventorySelectedSlot = 0; + WarpMouseToSelectedGUISlot(); + } + } } // OpenGUI() /* ItemModifyingGUI.cpp @@ -145,125 +145,125 @@ void ItemModifyingGUI::OpenGUI(const Uint8 GUIType, Item* const scrollUsed) */ void ItemModifyingGUI::UpdateGUI() { - // If the GUI is not active, there is no reason to go further - if ( bIsActive != true ) - { - return; - } - - // Cursed Scrolls do not use the GUI, their processing is determined at random - if ( bIsCursed != true ) - { - // If the Player's Inventory cannot be accessed, nothing will work, therefore this is a check to prevent needless processing - list_t* playerInventoryList = &stats[clientnum]->inventory; - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: UpdateGUI() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // playerInventoryList is no longer used, nullify it - playerInventoryList = nullptr; - - SDL_Rect GUIRect; // The location of the GUI window - - // Draw the GUI Background at the center of the Game Window + it's offset - GUIRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); - GUIRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); - drawImage(itemModifyingGUI_IMG, nullptr, &GUIRect); - - // Setup the collision bounds for the GUI buttons - ItemModifyingGUI_HandleButtons(); - - // Setup the collision bounds for the Mouse Wheel - ItemModifyingGUI_HandleMouseWheel(); - - // Setup the collision bounds for the GUI Dragging Bar - ItemModifyingGUI_HandleDraggingBar(); - - // Print the Window Label signifying this GUI - char* windowName; - windowName = language[2499]; // "Repair an Item" - - const Sint32 windowLabelX = ((((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 2 + ((itemModifyingGUI_IMG->w / 2) - ((TTF8_WIDTH * longestline(windowName)) / 2))); - const Sint32 windowLabelY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 4; - - // Print the Window Label - ttfPrintText(ttf8, windowLabelX, windowLabelY, windowName); - - // The GUI Window's position after being offset - const Sint32 GUIOffsetPosX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); - const Sint32 GUIOffsetPosY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); - - // Draw the Images for the GUI buttons when they are being clicked - ItemModifyingGUI_HandleButtonImages(GUIOffsetPosX, GUIOffsetPosY); - - SDL_Rect inventorySlotRect; // The position of all the Inventory Slots combined - inventorySlotRect.x = GUIOffsetPosX; - inventorySlotRect.w = inventoryoptionChest_bmp->w; - inventorySlotRect.y = GUIOffsetPosY + 16; - inventorySlotRect.h = inventoryoptionChest_bmp->h; - - SDL_Rect currentInventorySlotRect; // The current Inventory Slot Image to be drawn - - bool bIsMouseHoveringOverSlot = false; // True if the User's Mouse is currently over an Inventory Slot - - // Draw every Inventory Slot and check for Mouse clicks on those Inventory Slots - for ( Uint8 iSlotIndex = 0; iSlotIndex < NUM_ITEM_MODIFYING_GUI_ITEMS; ++iSlotIndex, inventorySlotRect.y += inventorySlotRect.h ) - { - // Update the position of the currentInventorySlotRect - currentInventorySlotRect.x = inventorySlotRect.x + 12; - currentInventorySlotRect.w = 0; - currentInventorySlotRect.h = 0; - - // If the mouse is currently hovering over an Inventory Slot, and there's an Item there, check for Mouse input - if ( omousey >= inventorySlotRect.y && omousey < inventorySlotRect.y + inventorySlotRect.h && itemModifyingGUI_Inventory[iSlotIndex] ) - { - // Update the Y position of the currentInventorySlotRect before drawing - currentInventorySlotRect.y = inventorySlotRect.y; - drawImage(inventoryoptionChest_bmp, nullptr, ¤tInventorySlotRect); - - itemModifyingGUI_InventorySelectedSlot = iSlotIndex; - bIsMouseHoveringOverSlot = true; - - // If the User clicks on the current Inventory Slot, process the Item - if ( mousestatus[SDL_BUTTON_LEFT] || *inputPressed(joyimpulses[INJOY_MENU_USE]) ) - { - *inputPressed(joyimpulses[INJOY_MENU_USE]) = 0; - mousestatus[SDL_BUTTON_LEFT] = 0; - - ItemModifyingGUI_Process(itemModifyingGUI_Inventory[iSlotIndex]); - } - } - } - - // Only have a slot selected if hovering over a slot - if ( !bIsMouseHoveringOverSlot ) - { - itemModifyingGUI_InventorySelectedSlot = -1; - } - - // Draw the Images for each Item in the GUI Inventory - // This is done at the end to prevent the Inventory Slot highlight from being drawn on top of the Item information - ItemModifyingGUI_HandleItemImages(); - } - else - { - if ( itemModifyingGUI_ScrollUsed == nullptr ) - { - // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed - printlog("ERROR: UpdateGUI() - A Cursed Spell has opened the GUI. This should never happen."); - return; - } - - messagePlayer(clientnum, language[2505]); // "Oh no! The scroll was cursed!" - - ItemModifyingGUI_ProcessRandom(); - - consumeItem(itemModifyingGUI_ScrollUsed); - CloseGUI(); - } + // If the GUI is not active, there is no reason to go further + if ( bIsActive != true ) + { + return; + } + + // Cursed Scrolls do not use the GUI, their processing is determined at random + if ( bIsCursed != true ) + { + // If the Player's Inventory cannot be accessed, nothing will work, therefore this is a check to prevent needless processing + list_t* playerInventoryList = &stats[clientnum]->inventory; + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: UpdateGUI() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // playerInventoryList is no longer used, nullify it + playerInventoryList = nullptr; + + SDL_Rect GUIRect; // The location of the GUI window + + // Draw the GUI Background at the center of the Game Window + it's offset + GUIRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + GUIRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + drawImage(itemModifyingGUI_IMG, nullptr, &GUIRect); + + // Setup the collision bounds for the GUI buttons + ItemModifyingGUI_HandleButtons(); + + // Setup the collision bounds for the Mouse Wheel + ItemModifyingGUI_HandleMouseWheel(); + + // Setup the collision bounds for the GUI Dragging Bar + ItemModifyingGUI_HandleDraggingBar(); + + // Print the Window Label signifying this GUI + char* windowName; + windowName = language[2499]; // "Repair an Item" + + const Sint32 windowLabelX = ((((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 2 + ((itemModifyingGUI_IMG->w / 2) - ((TTF8_WIDTH * longestline(windowName)) / 2))); + const Sint32 windowLabelY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 4; + + // Print the Window Label + ttfPrintText(ttf8, windowLabelX, windowLabelY, windowName); + + // The GUI Window's position after being offset + const Sint32 GUIOffsetPosX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 GUIOffsetPosY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + + // Draw the Images for the GUI buttons when they are being clicked + ItemModifyingGUI_HandleButtonImages(GUIOffsetPosX, GUIOffsetPosY); + + SDL_Rect inventorySlotRect; // The position of all the Inventory Slots combined + inventorySlotRect.x = GUIOffsetPosX; + inventorySlotRect.w = inventoryoptionChest_bmp->w; + inventorySlotRect.y = GUIOffsetPosY + 16; + inventorySlotRect.h = inventoryoptionChest_bmp->h; + + SDL_Rect currentInventorySlotRect; // The current Inventory Slot Image to be drawn + + bool bIsMouseHoveringOverSlot = false; // True if the User's Mouse is currently over an Inventory Slot + + // Draw every Inventory Slot and check for Mouse clicks on those Inventory Slots + for ( Uint8 iSlotIndex = 0; iSlotIndex < NUM_ITEM_MODIFYING_GUI_ITEMS; ++iSlotIndex, inventorySlotRect.y += inventorySlotRect.h ) + { + // Update the position of the currentInventorySlotRect + currentInventorySlotRect.x = inventorySlotRect.x + 12; + currentInventorySlotRect.w = 0; + currentInventorySlotRect.h = 0; + + // If the mouse is currently hovering over an Inventory Slot, and there's an Item there, check for Mouse input + if ( omousey >= inventorySlotRect.y && omousey < inventorySlotRect.y + inventorySlotRect.h && itemModifyingGUI_Inventory[iSlotIndex] ) + { + // Update the Y position of the currentInventorySlotRect before drawing + currentInventorySlotRect.y = inventorySlotRect.y; + drawImage(inventoryoptionChest_bmp, nullptr, ¤tInventorySlotRect); + + itemModifyingGUI_InventorySelectedSlot = iSlotIndex; + bIsMouseHoveringOverSlot = true; + + // If the User clicks on the current Inventory Slot, process the Item + if ( mousestatus[SDL_BUTTON_LEFT] || *inputPressed(joyimpulses[INJOY_MENU_USE]) ) + { + *inputPressed(joyimpulses[INJOY_MENU_USE]) = 0; + mousestatus[SDL_BUTTON_LEFT] = 0; + + ItemModifyingGUI_Process(itemModifyingGUI_Inventory[iSlotIndex]); + } + } + } + + // Only have a slot selected if hovering over a slot + if ( !bIsMouseHoveringOverSlot ) + { + itemModifyingGUI_InventorySelectedSlot = -1; + } + + // Draw the Images for each Item in the GUI Inventory + // This is done at the end to prevent the Inventory Slot highlight from being drawn on top of the Item information + ItemModifyingGUI_HandleItemImages(); + } + else + { + if ( itemModifyingGUI_ScrollUsed == nullptr ) + { + // Somehow, a Spell has been used to open the GUI, but was also Cursed, this should never happen, because Spells cannot be Cursed + printlog("ERROR: UpdateGUI() - A Cursed Spell has opened the GUI. This should never happen."); + return; + } + + messagePlayer(clientnum, language[2505]); // "Oh no! The scroll was cursed!" + + ItemModifyingGUI_ProcessRandom(); + + consumeItem(itemModifyingGUI_ScrollUsed); + CloseGUI(); + } } // UpdateGUI() /* ItemModifyingGUI.cpp @@ -271,19 +271,19 @@ void ItemModifyingGUI::UpdateGUI() */ void ItemModifyingGUI::CloseGUI() { - bIsActive = false; - bIsCursed = false; - bIsItemModifyingGUI_Dragging = false; - itemModifyingGUI_ScrollBeatitude = 0; - itemModifyingGUI_Type = 0; - itemModifyingGUI_InventoryScrollOffset = 0; - itemModifyingGUI_InventorySelectedSlot = -1; - - itemModifyingGUI_ScrollUsed = nullptr; - for ( int i = 0; i < NUM_ITEM_MODIFYING_GUI_ITEMS; i++ ) - { - itemModifyingGUI_Inventory[i] = nullptr; - } + bIsActive = false; + bIsCursed = false; + bIsItemModifyingGUI_Dragging = false; + itemModifyingGUI_ScrollBeatitude = 0; + itemModifyingGUI_Type = 0; + itemModifyingGUI_InventoryScrollOffset = 0; + itemModifyingGUI_InventorySelectedSlot = -1; + + itemModifyingGUI_ScrollUsed = nullptr; + for ( int i = 0; i < NUM_ITEM_MODIFYING_GUI_ITEMS; i++ ) + { + itemModifyingGUI_Inventory[i] = nullptr; + } } // CloseGUI() /* ItemModifyingGUI.cpp @@ -292,80 +292,80 @@ void ItemModifyingGUI::CloseGUI() */ void ItemModifyingGUI::Gamepad_MoveCursor(Sint8 direction) { - // Up will be -1, Down will be 1 - Sint8 newSlot = itemModifyingGUI_InventorySelectedSlot + direction; - - // D-Pad Up was pressed - if ( newSlot < itemModifyingGUI_InventorySelectedSlot ) - { - // Possible cases: - // * 1) Move cursor up the GUI through different itemModifyingGUI_InventorySelectedSlot - // * * 2) Page up through itemModifyingGUI_InventoryScrollOffset-- - // * * 3) Scrolling up past top of the GUI's Inventory, no itemModifyingGUI_InventoryScrollOffset (move back to Player Inventory) - - if ( itemModifyingGUI_InventorySelectedSlot <= 0 ) - { - // Covers cases 2 & 3 - // Possible cases: - // * A) Hit very top of the GUI's Inventory, can't go any further. Return to Player Inventory - // * * B) Page up, scrolling through itemModifyingGUI_InventoryScrollOffset-- - - if ( itemModifyingGUI_InventoryScrollOffset <= 0 ) - { - // Case 3/A: Return to Player Inventory - // A check will happen in playerinventory.cpp immediately after this which will call warpMouseToSelectedInventorySlot() - itemModifyingGUI_InventorySelectedSlot = -1; - } - else - { - // Case 2/B: Page up through GUI's Inventory - itemModifyingGUI_InventoryScrollOffset--; - } - } - else - { - // Covers case 1 - // Move cursor up the GUI through different itemModifyingGUI_InventorySelectedSlot (itemModifyingGUI_InventorySelectedSlot--) - itemModifyingGUI_InventorySelectedSlot--; - WarpMouseToSelectedGUISlot(); - } - } - else if ( newSlot > itemModifyingGUI_InventorySelectedSlot ) // D-Pad Down was pressed - { - // Possible cases: - // * 1) Moving cursor down through GUI through different itemModifyingGUI_InventorySelectedSlot - // * * 2) Scrolling down past bottom of GUI's Inventory through itemModifyingGUI_InventoryScrollOffset++ - // * * 3) Scrolling down past bottom of GUI's Inventory, past maximum GUI Inventory size (Undo move -- can't go beyond limit of the GUI's Inventory) - - if ( itemModifyingGUI_InventorySelectedSlot >= NUM_ITEM_MODIFYING_GUI_ITEMS - 1 ) - { - // Covers cases 2 & 3 - itemModifyingGUI_InventoryScrollOffset++; // itemModifyingGUI_InventoryScrollOffset is automatically sanitized in UpdateGUI() - } - else - { - // Covers case 1 - // Move cursor down through the GUI through different itemModifyingGUI_InventorySelectedSlot (itemModifyingGUI_InventorySelectedSlot++) - // This is a little bit trickier since must undo movement if there is no Item in the next slot - // Two possible cases: - // * A) There are Items below this. Advance itemModifyingGUI_InventorySelectedSlot to them - // * * B) On last Item already. Do nothing (undo movement) - - Item* item = GetItemInfoFromGUI(itemModifyingGUI_InventorySelectedSlot + 1); - - if ( item != nullptr ) - { - // Case 1/A - itemModifyingGUI_InventorySelectedSlot++; - WarpMouseToSelectedGUISlot(); - } - else - { - // Case 1/B - //No more Items. Prevent movement (undo movement) - } - } - } + // Up will be -1, Down will be 1 + Sint8 newSlot = itemModifyingGUI_InventorySelectedSlot + direction; + + // D-Pad Up was pressed + if ( newSlot < itemModifyingGUI_InventorySelectedSlot ) + { + // Possible cases: + // * 1) Move cursor up the GUI through different itemModifyingGUI_InventorySelectedSlot + // * * 2) Page up through itemModifyingGUI_InventoryScrollOffset-- + // * * 3) Scrolling up past top of the GUI's Inventory, no itemModifyingGUI_InventoryScrollOffset (move back to Player Inventory) + + if ( itemModifyingGUI_InventorySelectedSlot <= 0 ) + { + // Covers cases 2 & 3 + // Possible cases: + // * A) Hit very top of the GUI's Inventory, can't go any further. Return to Player Inventory + // * * B) Page up, scrolling through itemModifyingGUI_InventoryScrollOffset-- + + if ( itemModifyingGUI_InventoryScrollOffset <= 0 ) + { + // Case 3/A: Return to Player Inventory + // A check will happen in playerinventory.cpp immediately after this which will call warpMouseToSelectedInventorySlot() + itemModifyingGUI_InventorySelectedSlot = -1; + } + else + { + // Case 2/B: Page up through GUI's Inventory + itemModifyingGUI_InventoryScrollOffset--; + } + } + else + { + // Covers case 1 + // Move cursor up the GUI through different itemModifyingGUI_InventorySelectedSlot (itemModifyingGUI_InventorySelectedSlot--) + itemModifyingGUI_InventorySelectedSlot--; + WarpMouseToSelectedGUISlot(); + } + } + else if ( newSlot > itemModifyingGUI_InventorySelectedSlot ) // D-Pad Down was pressed + { + // Possible cases: + // * 1) Moving cursor down through GUI through different itemModifyingGUI_InventorySelectedSlot + // * * 2) Scrolling down past bottom of GUI's Inventory through itemModifyingGUI_InventoryScrollOffset++ + // * * 3) Scrolling down past bottom of GUI's Inventory, past maximum GUI Inventory size (Undo move -- can't go beyond limit of the GUI's Inventory) + + if ( itemModifyingGUI_InventorySelectedSlot >= NUM_ITEM_MODIFYING_GUI_ITEMS - 1 ) + { + // Covers cases 2 & 3 + itemModifyingGUI_InventoryScrollOffset++; // itemModifyingGUI_InventoryScrollOffset is automatically sanitized in UpdateGUI() + } + else + { + // Covers case 1 + // Move cursor down through the GUI through different itemModifyingGUI_InventorySelectedSlot (itemModifyingGUI_InventorySelectedSlot++) + // This is a little bit trickier since must undo movement if there is no Item in the next slot + // Two possible cases: + // * A) There are Items below this. Advance itemModifyingGUI_InventorySelectedSlot to them + // * * B) On last Item already. Do nothing (undo movement) + + Item* item = GetItemInfoFromGUI(itemModifyingGUI_InventorySelectedSlot + 1); + + if ( item != nullptr ) + { + // Case 1/A + itemModifyingGUI_InventorySelectedSlot++; + WarpMouseToSelectedGUISlot(); + } + else + { + // Case 1/B + //No more Items. Prevent movement (undo movement) + } + } + } } // Gamepad_MoveCursor() /* ItemModifyingGUI.cpp @@ -373,7 +373,7 @@ void ItemModifyingGUI::Gamepad_MoveCursor(Sint8 direction) */ bool ItemModifyingGUI::IsGUIOpen() const { - return bIsActive; + return bIsActive; } // IsGUIOpen() /* ItemModifyingGUI.cpp @@ -385,23 +385,23 @@ bool ItemModifyingGUI::IsGUIOpen() const */ bool ItemModifyingGUI::AreThereValidItems(const Uint8 GUIType) { - itemModifyingGUI_Type = GUIType; - - // Build the GUI's Inventory for an initial check - ItemModifyingGUI_RebuildInventory(); - - // If the Inventory is empty, there is nothing to process - if ( itemModifyingGUI_Inventory[0] == nullptr ) - { - messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" - CloseGUI(); // Reset all values to prevent any crossover - return false; - } - else - { - CloseGUI(); // Reset all values to prevent any crossover - return true; - } + itemModifyingGUI_Type = GUIType; + + // Build the GUI's Inventory for an initial check + ItemModifyingGUI_RebuildInventory(); + + // If the Inventory is empty, there is nothing to process + if ( itemModifyingGUI_Inventory[0] == nullptr ) + { + messagePlayer(clientnum, language[2500]); // "There are no valid items to use this on!" + CloseGUI(); // Reset all values to prevent any crossover + return false; + } + else + { + CloseGUI(); // Reset all values to prevent any crossover + return true; + } } // AreThereValidItems() /* ItemModifyingGUI.cpp @@ -411,7 +411,7 @@ bool ItemModifyingGUI::AreThereValidItems(const Uint8 GUIType) */ bool ItemModifyingGUI::IsSelectedSlotInvalid() const { - return (itemModifyingGUI_InventorySelectedSlot < 0); + return (itemModifyingGUI_InventorySelectedSlot < 0); } // IsSelectedSlotInvalid() /* ItemModifyingGUI.cpp @@ -421,16 +421,16 @@ bool ItemModifyingGUI::IsSelectedSlotInvalid() const */ bool ItemModifyingGUI::IsMouseWithinGUIBounds() const { - // Draw the GUI Background at the center of the Game Window + it's offset - const Sint32 GUIX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); - const Sint32 GUIY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + // Draw the GUI Background at the center of the Game Window + it's offset + const Sint32 GUIX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 GUIY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); - if ( ((omousex > GUIX) && (omousex < GUIX + itemModifyingGUI_IMG->w)) && ((omousey > GUIY) && (omousey < GUIY + itemModifyingGUI_IMG->h))) - { - return true; - } + if ( ((omousex > GUIX) && (omousex < GUIX + itemModifyingGUI_IMG->w)) && ((omousey > GUIY) && (omousey < GUIY + itemModifyingGUI_IMG->h)) ) + { + return true; + } - return false; + return false; } // IsMouseWithinGUIBounds() /* ItemModifyingGUI.cpp @@ -438,11 +438,11 @@ bool ItemModifyingGUI::IsMouseWithinGUIBounds() const */ void ItemModifyingGUI::FreeImage() { - if ( itemModifyingGUI_IMG != nullptr ) - { - SDL_FreeSurface(itemModifyingGUI_IMG); - itemModifyingGUI_IMG = nullptr; - } + if ( itemModifyingGUI_IMG != nullptr ) + { + SDL_FreeSurface(itemModifyingGUI_IMG); + itemModifyingGUI_IMG = nullptr; + } } // FreeImage() /* ItemModifyingGUI.cpp @@ -453,12 +453,12 @@ void ItemModifyingGUI::FreeImage() */ inline Item* ItemModifyingGUI::GetItemInfoFromGUI(Uint8 slot) { - if ( slot >= 4 ) - { - return nullptr; // Out of bounds - } + if ( slot >= 4 ) + { + return nullptr; // Out of bounds + } - return itemModifyingGUI_Inventory[slot]; + return itemModifyingGUI_Inventory[slot]; } // GetItemInfoFromGUI() // ITEM MODIFYING GUI LOGIC HANDLERS @@ -469,25 +469,25 @@ inline Item* ItemModifyingGUI::GetItemInfoFromGUI(Uint8 slot) */ void ItemModifyingGUI::ItemModifyingGUI_Process(Item* const selectedItem) { - switch ( itemModifyingGUI_Type ) - { - case 0: // Identify - IdentifyGUI_Process(selectedItem); - break; - case 1: // Remove Curse - RemoveCurseGUI_Process(selectedItem); - break; - case 2: // Repair - RepairGUI_Process(selectedItem); - break; - case 3: // Enchant Weapon - EnchantWeaponGUI_Process(selectedItem); - break; - case 4: // Enchant Armor - EnchantArmorGUI_Process(selectedItem); - break; - default: printlog("ERROR: ItemModifyingGUI_Process() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; - } + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + IdentifyGUI_Process(selectedItem); + break; + case 1: // Remove Curse + RemoveCurseGUI_Process(selectedItem); + break; + case 2: // Repair + RepairGUI_Process(selectedItem); + break; + case 3: // Enchant Weapon + EnchantWeaponGUI_Process(selectedItem); + break; + case 4: // Enchant Armor + EnchantArmorGUI_Process(selectedItem); + break; + default: printlog("ERROR: ItemModifyingGUI_Process() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } } // ItemModifyingGUI_Process() /* ItemModifyingGUI.cpp @@ -495,37 +495,37 @@ void ItemModifyingGUI::ItemModifyingGUI_Process(Item* const selectedItem) */ void ItemModifyingGUI::ItemModifyingGUI_ProcessRandom() { - Uint8 numberOfItemsToProcess = 0; - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - numberOfItemsToProcess = 2; - break; - case -1: - numberOfItemsToProcess = 1; - break; - default: printlog("ERROR: ItemModifyingGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%s) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; - } - - switch ( itemModifyingGUI_Type ) - { - case 0: // Identify - IdentifyGUI_ProcessRandom(numberOfItemsToProcess); - break; - case 1: // Remove Curse - RemoveCurseGUI_ProcessRandom(numberOfItemsToProcess); - break; - case 2: // Repair - RepairGUI_ProcessRandom(numberOfItemsToProcess); - break; - case 3: // Enchant Weapon - EnchantWeaponGUI_ProcessRandom(numberOfItemsToProcess); - break; - case 4: // Enchant Armor - EnchantArmorGUI_ProcessRandom(numberOfItemsToProcess); - break; - default: printlog("ERROR: ItemModifyingGUI_ProcessRandom() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; - } + Uint8 numberOfItemsToProcess = 0; + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + numberOfItemsToProcess = 2; + break; + case -1: + numberOfItemsToProcess = 1; + break; + default: printlog("ERROR: ItemModifyingGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%s) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + IdentifyGUI_ProcessRandom(numberOfItemsToProcess); + break; + case 1: // Remove Curse + RemoveCurseGUI_ProcessRandom(numberOfItemsToProcess); + break; + case 2: // Repair + RepairGUI_ProcessRandom(numberOfItemsToProcess); + break; + case 3: // Enchant Weapon + EnchantWeaponGUI_ProcessRandom(numberOfItemsToProcess); + break; + case 4: // Enchant Armor + EnchantArmorGUI_ProcessRandom(numberOfItemsToProcess); + break; + default: printlog("ERROR: ItemModifyingGUI_ProcessRandom() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } } // ItemModifyingGUI_ProcessRandom() /* ItemModifyingGUI.cpp @@ -533,25 +533,25 @@ void ItemModifyingGUI::ItemModifyingGUI_ProcessRandom() */ void ItemModifyingGUI::ItemModifyingGUI_RebuildInventory() { - switch ( itemModifyingGUI_Type ) - { - case 0: // Identify - IdentifyGUI_RebuildInventory(); - break; - case 1: // Remove Curse - RemoveCurseGUI_RebuildInventory(); - break; - case 2: // Repair - RepairGUI_RebuildInventory(); - break; - case 3: // Enchant Weapon - EnchantWeaponGUI_RebuildInventory(); - break; - case 4: // Enchant Armor - EnchantArmorGUI_RebuildInventory(); - break; - default: printlog("ERROR: ItemModifyingGUI_RebuildInventory() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; - } + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + IdentifyGUI_RebuildInventory(); + break; + case 1: // Remove Curse + RemoveCurseGUI_RebuildInventory(); + break; + case 2: // Repair + RepairGUI_RebuildInventory(); + break; + case 3: // Enchant Weapon + EnchantWeaponGUI_RebuildInventory(); + break; + case 4: // Enchant Armor + EnchantArmorGUI_RebuildInventory(); + break; + default: printlog("ERROR: ItemModifyingGUI_RebuildInventory() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } } // ItemModifyingGUI_RebuildInventory() /* ItemModifyingGUI.cpp @@ -559,13 +559,13 @@ void ItemModifyingGUI::ItemModifyingGUI_RebuildInventory() */ void ItemModifyingGUI::WarpMouseToSelectedGUISlot() { - SDL_Rect slotPos; - slotPos.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); - slotPos.w = inventoryoptionChest_bmp->w; - slotPos.h = inventoryoptionChest_bmp->h; - slotPos.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16 + (slotPos.h * itemModifyingGUI_InventorySelectedSlot); + SDL_Rect slotPos; + slotPos.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + slotPos.w = inventoryoptionChest_bmp->w; + slotPos.h = inventoryoptionChest_bmp->h; + slotPos.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16 + (slotPos.h * itemModifyingGUI_InventorySelectedSlot); - SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); + SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); } // WarpMouseToSelectedGUISlot() // ITEM MODIFYING GUI DISPLAY HANDLERS @@ -576,81 +576,81 @@ void ItemModifyingGUI::WarpMouseToSelectedGUISlot() */ void ItemModifyingGUI::ItemModifyingGUI_HandleButtons() { - // GUI Button Collision Bounds TODOR: I may have these swapped, the lower bound may be the upper bound - // Scroll Up Button Y - const Sint32 scrollUpButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16; - const Sint32 scrollUpButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 52; - // Scroll Up Button X - const Sint32 scrollUpButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); - const Sint32 scrollUpButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); - // Scroll Down Button Y - const Sint32 scrollDownButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 52; - const Sint32 scrollDownButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 88; - // Scroll Down Button X - const Sint32 scrollDownButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); - const Sint32 scrollDownButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); - // Close Button Y - const Sint32 closeButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); - const Sint32 closeButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 15; - // Close Button X - const Sint32 closeButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 393; - const Sint32 closeButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 407; - // Dragging Bar Y - const Sint32 draggingBarY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); - const Sint32 draggingBarY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 15; - // Dragging Bar X - const Sint32 draggingBarX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); - const Sint32 draggingBarX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 377; - - // Buttons - if ( mousestatus[SDL_BUTTON_LEFT] ) - { - // GUI Scroll Up Button - if ( omousey >= scrollUpButtonY_LowerBound && omousey < scrollUpButtonY_UpperBound ) - { - if ( omousex >= scrollUpButtonX_LowerBound && omousex < scrollUpButtonX_UpperBound ) - { - buttonclick = 7; - if ( itemModifyingGUI_InventoryScrollOffset != 0 ) - { - itemModifyingGUI_InventoryScrollOffset--; - } - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - - // GUI Scroll Down Button - else if ( omousey >= scrollDownButtonY_LowerBound && omousey < scrollDownButtonY_UpperBound ) - { - if ( omousex >= scrollDownButtonX_LowerBound && omousex < scrollDownButtonX_UpperBound ) - { - buttonclick = 8; - itemModifyingGUI_InventoryScrollOffset++; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - - // Top Bar of GUI - else if ( omousey >= closeButtonY_LowerBound && omousey < closeButtonY_UpperBound ) - { - // GUI Close Button - if ( omousex >= closeButtonX_LowerBound && omousex < closeButtonX_UpperBound ) - { - buttonclick = 9; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - - // GUI Dragging Top Bar - if ( omousex >= draggingBarX_LowerBound && omousex < draggingBarX_UpperBound && omousey >= draggingBarY_LowerBound && omousey < draggingBarY_UpperBound ) - { - gui_clickdrag = true; - bIsItemModifyingGUI_Dragging = true; - dragoffset_x = omousex - (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); - dragoffset_y = omousey - (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - } + // GUI Button Collision Bounds TODOR: I may have these swapped, the lower bound may be the upper bound + // Scroll Up Button Y + const Sint32 scrollUpButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16; + const Sint32 scrollUpButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 52; + // Scroll Up Button X + const Sint32 scrollUpButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + const Sint32 scrollUpButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + // Scroll Down Button Y + const Sint32 scrollDownButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 52; + const Sint32 scrollDownButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 88; + // Scroll Down Button X + const Sint32 scrollDownButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + const Sint32 scrollDownButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 12); + // Close Button Y + const Sint32 closeButtonY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 closeButtonY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 15; + // Close Button X + const Sint32 closeButtonX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 393; + const Sint32 closeButtonX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 407; + // Dragging Bar Y + const Sint32 draggingBarY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + const Sint32 draggingBarY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 15; + // Dragging Bar X + const Sint32 draggingBarX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + const Sint32 draggingBarX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 377; + + // Buttons + if ( mousestatus[SDL_BUTTON_LEFT] ) + { + // GUI Scroll Up Button + if ( omousey >= scrollUpButtonY_LowerBound && omousey < scrollUpButtonY_UpperBound ) + { + if ( omousex >= scrollUpButtonX_LowerBound && omousex < scrollUpButtonX_UpperBound ) + { + buttonclick = 7; + if ( itemModifyingGUI_InventoryScrollOffset != 0 ) + { + itemModifyingGUI_InventoryScrollOffset--; + } + mousestatus[SDL_BUTTON_LEFT] = 0; + } + } + + // GUI Scroll Down Button + else if ( omousey >= scrollDownButtonY_LowerBound && omousey < scrollDownButtonY_UpperBound ) + { + if ( omousex >= scrollDownButtonX_LowerBound && omousex < scrollDownButtonX_UpperBound ) + { + buttonclick = 8; + itemModifyingGUI_InventoryScrollOffset++; + mousestatus[SDL_BUTTON_LEFT] = 0; + } + } + + // Top Bar of GUI + else if ( omousey >= closeButtonY_LowerBound && omousey < closeButtonY_UpperBound ) + { + // GUI Close Button + if ( omousex >= closeButtonX_LowerBound && omousex < closeButtonX_UpperBound ) + { + buttonclick = 9; + mousestatus[SDL_BUTTON_LEFT] = 0; + } + + // GUI Dragging Top Bar + if ( omousex >= draggingBarX_LowerBound && omousex < draggingBarX_UpperBound && omousey >= draggingBarY_LowerBound && omousey < draggingBarY_UpperBound ) + { + gui_clickdrag = true; + bIsItemModifyingGUI_Dragging = true; + dragoffset_x = omousex - (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + dragoffset_y = omousey - (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + mousestatus[SDL_BUTTON_LEFT] = 0; + } + } + } } // ItemModifyingGUI_HandleButtons() /* ItemModifyingGUI.cpp @@ -658,34 +658,34 @@ void ItemModifyingGUI::ItemModifyingGUI_HandleButtons() */ void ItemModifyingGUI::ItemModifyingGUI_HandleMouseWheel() { - // GUI Mouse Wheel Collision Bounds - // Mouse Wheel Y - const Sint32 mouseWheelY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16; - const Sint32 mouseWheelY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + (itemModifyingGUI_IMG->h - 8); - // Mouse Wheel X - const Sint32 mouseWheelX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 12; - const Sint32 mouseWheelX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); - - // Mouse wheel - if ( omousex >= mouseWheelX_LowerBound && omousex < mouseWheelX_UpperBound ) - { - if ( omousey >= mouseWheelY_LowerBound && omousey < mouseWheelY_UpperBound ) - { - if ( mousestatus[SDL_BUTTON_WHEELDOWN] ) - { - mousestatus[SDL_BUTTON_WHEELDOWN] = 0; - itemModifyingGUI_InventoryScrollOffset++; - } - else if ( mousestatus[SDL_BUTTON_WHEELUP] ) - { - mousestatus[SDL_BUTTON_WHEELUP] = 0; - if ( itemModifyingGUI_InventoryScrollOffset != 0 ) - { - itemModifyingGUI_InventoryScrollOffset--; - } - } - } - } + // GUI Mouse Wheel Collision Bounds + // Mouse Wheel Y + const Sint32 mouseWheelY_LowerBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 16; + const Sint32 mouseWheelY_UpperBound = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + (itemModifyingGUI_IMG->h - 8); + // Mouse Wheel X + const Sint32 mouseWheelX_LowerBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 12; + const Sint32 mouseWheelX_UpperBound = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + (itemModifyingGUI_IMG->w - 28); + + // Mouse wheel + if ( omousex >= mouseWheelX_LowerBound && omousex < mouseWheelX_UpperBound ) + { + if ( omousey >= mouseWheelY_LowerBound && omousey < mouseWheelY_UpperBound ) + { + if ( mousestatus[SDL_BUTTON_WHEELDOWN] ) + { + mousestatus[SDL_BUTTON_WHEELDOWN] = 0; + itemModifyingGUI_InventoryScrollOffset++; + } + else if ( mousestatus[SDL_BUTTON_WHEELUP] ) + { + mousestatus[SDL_BUTTON_WHEELUP] = 0; + if ( itemModifyingGUI_InventoryScrollOffset != 0 ) + { + itemModifyingGUI_InventoryScrollOffset--; + } + } + } + } } // ItemModifyingGUI_HandleMouseWheel() /* ItemModifyingGUI.cpp @@ -693,43 +693,43 @@ void ItemModifyingGUI::ItemModifyingGUI_HandleMouseWheel() */ void ItemModifyingGUI::ItemModifyingGUI_HandleDraggingBar() { - // GUI Dragging - // The GUI Window's centered position in the Game Window - Sint32 GUICenterPosY = ((yres / 2) - (itemModifyingGUI_IMG->h / 2)); - Sint32 GUICenterPosX = ((xres / 2) - (itemModifyingGUI_IMG->w / 2)); - // The GUI Window's position after being offset - Sint32 GUIOffsetPosY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); - Sint32 GUIOffsetPosX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); - - // Dragging the Window - if ( bIsItemModifyingGUI_Dragging == true) - { - if ( gui_clickdrag == true ) // If the User is dragging, process the movement - { - itemModifyingGUI_OffsetX = (omousex - dragoffset_x) - GUICenterPosX; - itemModifyingGUI_OffsetY = (omousey - dragoffset_y) - GUICenterPosY; - if ( GUIOffsetPosX <= camera.winx ) - { - itemModifyingGUI_OffsetX = camera.winx - GUICenterPosX; - } - if ( GUIOffsetPosX > camera.winx + camera.winw - itemModifyingGUI_IMG->w ) - { - itemModifyingGUI_OffsetX = (camera.winx + camera.winw - itemModifyingGUI_IMG->w) - GUICenterPosX; - } - if ( GUIOffsetPosY <= camera.winy ) - { - itemModifyingGUI_OffsetY = camera.winy - GUICenterPosY; - } - if ( GUIOffsetPosY > camera.winy + camera.winh - itemModifyingGUI_IMG->h ) - { - itemModifyingGUI_OffsetY = (camera.winy + camera.winh - itemModifyingGUI_IMG->h) - GUICenterPosY; - } - } - else // Else, reset the flag - { - bIsItemModifyingGUI_Dragging = false; - } - } + // GUI Dragging + // The GUI Window's centered position in the Game Window + Sint32 GUICenterPosY = ((yres / 2) - (itemModifyingGUI_IMG->h / 2)); + Sint32 GUICenterPosX = ((xres / 2) - (itemModifyingGUI_IMG->w / 2)); + // The GUI Window's position after being offset + Sint32 GUIOffsetPosY = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY); + Sint32 GUIOffsetPosX = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX); + + // Dragging the Window + if ( bIsItemModifyingGUI_Dragging == true ) + { + if ( gui_clickdrag == true ) // If the User is dragging, process the movement + { + itemModifyingGUI_OffsetX = (omousex - dragoffset_x) - GUICenterPosX; + itemModifyingGUI_OffsetY = (omousey - dragoffset_y) - GUICenterPosY; + if ( GUIOffsetPosX <= camera.winx ) + { + itemModifyingGUI_OffsetX = camera.winx - GUICenterPosX; + } + if ( GUIOffsetPosX > camera.winx + camera.winw - itemModifyingGUI_IMG->w ) + { + itemModifyingGUI_OffsetX = (camera.winx + camera.winw - itemModifyingGUI_IMG->w) - GUICenterPosX; + } + if ( GUIOffsetPosY <= camera.winy ) + { + itemModifyingGUI_OffsetY = camera.winy - GUICenterPosY; + } + if ( GUIOffsetPosY > camera.winy + camera.winh - itemModifyingGUI_IMG->h ) + { + itemModifyingGUI_OffsetY = (camera.winy + camera.winh - itemModifyingGUI_IMG->h) - GUICenterPosY; + } + } + else // Else, reset the flag + { + bIsItemModifyingGUI_Dragging = false; + } + } } // ItemModifyingGUI_HandleDraggingBar() /* ItemModifyingGUI.cpp @@ -739,39 +739,39 @@ void ItemModifyingGUI::ItemModifyingGUI_HandleDraggingBar() */ void ItemModifyingGUI::ItemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY) { - // GUI Scroll Up Button - if ( buttonclick == 7 ) - { - SDL_Rect GUIInventoryUpButtonRect; - GUIInventoryUpButtonRect.x = GUIPosX + (itemModifyingGUI_IMG->w - 28); - GUIInventoryUpButtonRect.y = GUIPosY + 16; - GUIInventoryUpButtonRect.w = 0; - GUIInventoryUpButtonRect.h = 0; - drawImage(invup_bmp, nullptr, &GUIInventoryUpButtonRect); - } - - // GUI Scroll Down Button - if ( buttonclick == 8 ) - { - SDL_Rect GUIInventoryDownButtonRect; - GUIInventoryDownButtonRect.x = GUIPosX + (itemModifyingGUI_IMG->w - 28); - GUIInventoryDownButtonRect.y = GUIPosY + 52; - GUIInventoryDownButtonRect.w = 0; - GUIInventoryDownButtonRect.h = 0; - drawImage(invdown_bmp, nullptr, &GUIInventoryDownButtonRect); - } - - // GUI Close Button - if ( buttonclick == 9 ) - { - SDL_Rect GUICloseButtonRect; - GUICloseButtonRect.x = GUIPosX + 393; - GUICloseButtonRect.y = GUIPosY; - GUICloseButtonRect.w = 0; - GUICloseButtonRect.h = 0; - drawImage(invclose_bmp, nullptr, &GUICloseButtonRect); - CloseGUI(); - } + // GUI Scroll Up Button + if ( buttonclick == 7 ) + { + SDL_Rect GUIInventoryUpButtonRect; + GUIInventoryUpButtonRect.x = GUIPosX + (itemModifyingGUI_IMG->w - 28); + GUIInventoryUpButtonRect.y = GUIPosY + 16; + GUIInventoryUpButtonRect.w = 0; + GUIInventoryUpButtonRect.h = 0; + drawImage(invup_bmp, nullptr, &GUIInventoryUpButtonRect); + } + + // GUI Scroll Down Button + if ( buttonclick == 8 ) + { + SDL_Rect GUIInventoryDownButtonRect; + GUIInventoryDownButtonRect.x = GUIPosX + (itemModifyingGUI_IMG->w - 28); + GUIInventoryDownButtonRect.y = GUIPosY + 52; + GUIInventoryDownButtonRect.w = 0; + GUIInventoryDownButtonRect.h = 0; + drawImage(invdown_bmp, nullptr, &GUIInventoryDownButtonRect); + } + + // GUI Close Button + if ( buttonclick == 9 ) + { + SDL_Rect GUICloseButtonRect; + GUICloseButtonRect.x = GUIPosX + 393; + GUICloseButtonRect.y = GUIPosY; + GUICloseButtonRect.w = 0; + GUICloseButtonRect.h = 0; + drawImage(invclose_bmp, nullptr, &GUICloseButtonRect); + CloseGUI(); + } } // ItemModifyingGUI_HandleButtonImages() /* ItemModifyingGUI.cpp @@ -779,28 +779,28 @@ void ItemModifyingGUI::ItemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, */ void ItemModifyingGUI::ItemModifyingGUI_HandleItemImages() { - // Rebuild the GUI Inventory to prevent scrolling infinitely - ItemModifyingGUI_RebuildInventory(); - - switch ( itemModifyingGUI_Type ) - { - case 0: // Identify - IdentifyGUI_HandleItemImages(); - break; - case 1: // Remove Curse - RemoveCurseGUI_HandleItemImages(); - break; - case 2: // Repair - RepairGUI_HandleItemImages(); - break; - case 3: // Enchant Weapon - EnchantWeaponGUI_HandleItemImages(); - break; - case 4: // Enchant Armor - EnchantArmorGUI_HandleItemImages(); - break; - default: printlog("ERROR: ItemModifyingGUI_HandleItemImages() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; - } + // Rebuild the GUI Inventory to prevent scrolling infinitely + ItemModifyingGUI_RebuildInventory(); + + switch ( itemModifyingGUI_Type ) + { + case 0: // Identify + IdentifyGUI_HandleItemImages(); + break; + case 1: // Remove Curse + RemoveCurseGUI_HandleItemImages(); + break; + case 2: // Repair + RepairGUI_HandleItemImages(); + break; + case 3: // Enchant Weapon + EnchantWeaponGUI_HandleItemImages(); + break; + case 4: // Enchant Armor + EnchantArmorGUI_HandleItemImages(); + break; + default: printlog("ERROR: ItemModifyingGUI_HandleItemImages() - itemModifyingGUI_Type (%s) out of bounds.", itemModifyingGUI_Type); return; + } } // ItemModifyingGUI_HandleItemImages() // IDENTIFY GUI @@ -812,43 +812,43 @@ void ItemModifyingGUI::ItemModifyingGUI_HandleItemImages() */ void ItemModifyingGUI::IdentifyGUI_Process(Item* const selectedItem) { - if ( selectedItem == nullptr ) - { - printlog("ERROR: IdentifyGUI_Process() - selectedItem is null."); - return; - } - - // Cursed Scrolls don't use the GUI so they will never call this function - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - // Identify the selected Item - selectedItem->identified = true; - messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." - break; - case 1: - // Identify the selected Item and 1 random Unidentified Item in their Inventory - selectedItem->identified = true; - messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." - IdentifyGUI_ProcessRandom(1); - break; - case 2: - // Identify the selected Item and 2 random Unidentified Items in their Inventory - selectedItem->identified = true; - messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." - IdentifyGUI_ProcessRandom(2); - break; - default: printlog("ERROR: IdentifyGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; - } - - // If the Player used a Scroll, consume it - if ( itemModifyingGUI_ScrollUsed != nullptr ) - { - consumeItem(itemModifyingGUI_ScrollUsed); - itemModifyingGUI_ScrollUsed = nullptr; - } - - CloseGUI(); + if ( selectedItem == nullptr ) + { + printlog("ERROR: IdentifyGUI_Process() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Identify the selected Item + selectedItem->identified = true; + messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." + break; + case 1: + // Identify the selected Item and 1 random Unidentified Item in their Inventory + selectedItem->identified = true; + messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." + IdentifyGUI_ProcessRandom(1); + break; + case 2: + // Identify the selected Item and 2 random Unidentified Items in their Inventory + selectedItem->identified = true; + messagePlayer(clientnum, language[320], selectedItem->description()); // "Identified "%s"." + IdentifyGUI_ProcessRandom(2); + break; + default: printlog("ERROR: IdentifyGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + CloseGUI(); } // IdentifyGUI_Process() /* ItemModifyingGUI.cpp @@ -858,165 +858,165 @@ void ItemModifyingGUI::IdentifyGUI_Process(Item* const selectedItem) */ void ItemModifyingGUI::IdentifyGUI_ProcessRandom(const Uint8 numItems) { - // Grab the Player's Inventory again, as it may have been modified prior to this - list_t* playerInventoryList = &stats[clientnum]->inventory; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: IdentifyGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the GUI Inventory - Uint8 totalAmountOfItems = 0; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->identified == true ) // Skip over all Unidentified Items - { - totalAmountOfItems++; - } - break; - case 1: - // Intentional fall-through - case 2: - if ( item->identified != true ) // Skip over all Identified Items - { - totalAmountOfItems++; - } - break; - default: printlog("ERROR: IdentifyGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - // There are no valid Items to be processed - if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - return; - } - else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." - return; - } - - Uint8 amountOfItemsLeftToProcess = numItems; - bool isThereASingleItem = false; - - // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop - if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - - Sint8 iPreviousItemProcessedIndex = -1; - Sint8 iItemToProcessIndex = -1; - Uint8 iIdentifyGUIInventoryIndex = 0; - - for ( Uint8 i = 0; i < numItems; i++ ) - { - while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) - { - iItemToProcessIndex = rand() % totalAmountOfItems; - } - - iIdentifyGUIInventoryIndex = 0; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* itemToProcess = static_cast(iInventoryNode->element); - - if ( itemToProcess == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( itemToProcess->identified == true ) // Skip over all Unidentified Items - { - if ( iIdentifyGUIInventoryIndex == iItemToProcessIndex ) - { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) - { - messagePlayer(clientnum, language[2514], itemToProcess->description()); // "Oh no! Your %s was unidentified too!" - } - else - { - messagePlayer(clientnum, language[2506], itemToProcess->description()); // "Your %s was unidentified!" - } - - itemToProcess->identified = false; - amountOfItemsLeftToProcess--; - - iPreviousItemProcessedIndex = iIdentifyGUIInventoryIndex; - } - iIdentifyGUIInventoryIndex++; - } - break; - case 1: - // Intentional fall-through - case 2: - if ( itemToProcess->identified != true ) // Skip over all Identified Items - { - if ( iIdentifyGUIInventoryIndex == iItemToProcessIndex ) - { - itemToProcess->identified = true; - amountOfItemsLeftToProcess--; - messagePlayer(clientnum, language[2511], itemToProcess->description()); // "Wow! Your %s was identified too!" - iPreviousItemProcessedIndex = iIdentifyGUIInventoryIndex; - } - iIdentifyGUIInventoryIndex++; - } - break; - default: printlog("ERROR: IdentifyGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - // If processing is done, stop searching the Inventory - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // If there's only a single valid Item, but it's a +-2 scroll, this will happen - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // Tell the Player they were an Item short of the full effect - if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - } - else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." - } + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: IdentifyGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->identified == true ) // Skip over all Unidentified Items + { + totalAmountOfItems++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( item->identified != true ) // Skip over all Identified Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: IdentifyGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iIdentifyGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iIdentifyGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->identified == true ) // Skip over all Unidentified Items + { + if ( iIdentifyGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) + { + messagePlayer(clientnum, language[2514], itemToProcess->description()); // "Oh no! Your %s was unidentified too!" + } + else + { + messagePlayer(clientnum, language[2506], itemToProcess->description()); // "Your %s was unidentified!" + } + + itemToProcess->identified = false; + amountOfItemsLeftToProcess--; + + iPreviousItemProcessedIndex = iIdentifyGUIInventoryIndex; + } + iIdentifyGUIInventoryIndex++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( itemToProcess->identified != true ) // Skip over all Identified Items + { + if ( iIdentifyGUIInventoryIndex == iItemToProcessIndex ) + { + itemToProcess->identified = true; + amountOfItemsLeftToProcess--; + messagePlayer(clientnum, language[2511], itemToProcess->description()); // "Wow! Your %s was identified too!" + iPreviousItemProcessedIndex = iIdentifyGUIInventoryIndex; + } + iIdentifyGUIInventoryIndex++; + } + break; + default: printlog("ERROR: IdentifyGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } } // IdentifyGUI_ProcessRandom() /* ItemModifyingGUI.cpp @@ -1025,124 +1025,124 @@ void ItemModifyingGUI::IdentifyGUI_ProcessRandom(const Uint8 numItems) */ void ItemModifyingGUI::IdentifyGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - Uint8 iIdentifyGUIInventoryIndex = 0; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: IdentifyGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the GUI Inventory - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->identified == true ) // Skip over all Unidentified Items - { - ++iIdentifyGUIInventoryIndex; - } - break; - case 0: - // Intentional fall-through - case 1: - // Intentional fall-through - case 2: - if ( item->identified != true ) // Skip over all Identified Items - { - ++iIdentifyGUIInventoryIndex; - } - break; - default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iIdentifyGUIInventoryIndex - 4)); - - // Reset the current Inventory - for ( iIdentifyGUIInventoryIndex = 0; iIdentifyGUIInventoryIndex < 4; ++iIdentifyGUIInventoryIndex ) - { - itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex] = nullptr; - } - - iIdentifyGUIInventoryIndex = 0; - - // Assign the visible Items to the GUI slots - bool bBreakFromLoop = false; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->identified == true ) // Skip over all Unidentified Items - { - ++iIdentifyGUIInventoryIndex; - - if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 0: - // Intentional fall-through - case 1: - // Intentional fall-through - case 2: - if ( item->identified != true ) // Skip over all Identified Items - { - ++iIdentifyGUIInventoryIndex; - - if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: IdentifyGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iIdentifyGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: IdentifyGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->identified == true ) // Skip over all Unidentified Items + { + ++iIdentifyGUIInventoryIndex; + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified != true ) // Skip over all Identified Items + { + ++iIdentifyGUIInventoryIndex; + } + break; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iIdentifyGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iIdentifyGUIInventoryIndex = 0; iIdentifyGUIInventoryIndex < 4; ++iIdentifyGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex] = nullptr; + } + + iIdentifyGUIInventoryIndex = 0; + + // Assign the visible Items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->identified == true ) // Skip over all Unidentified Items + { + ++iIdentifyGUIInventoryIndex; + + if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified != true ) // Skip over all Identified Items + { + ++iIdentifyGUIInventoryIndex; + + if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: IdentifyGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } } // IdentifyGUI_RebuildInventory() /* ItemModifyingGUI.cpp @@ -1150,67 +1150,67 @@ void ItemModifyingGUI::IdentifyGUI_RebuildInventory() */ void ItemModifyingGUI::IdentifyGUI_HandleItemImages() { - Uint8 iIdentifyGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iIdentifyGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other - - Item* item = nullptr; // The given Item being drawn from the GUI Inventory - SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - if ( iInventoryNode->element != nullptr ) - { - item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Cursed Scrolls don't need to be shown, as they wont have a GUI - if ( item->identified != true ) // Skip over all Identified Items - { - iIdentifyGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iIdentifyGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iIdentifyGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - break; - } - } - } - } + Uint8 iIdentifyGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iIdentifyGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + if ( item->identified != true ) // Skip over all Identified Items + { + iIdentifyGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iIdentifyGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iIdentifyGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iIdentifyGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iIdentifyGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iIdentifyGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + break; + } + } + } + } } // IdentifyGUI_HandleItemImages() // REMOVE CURSE GUI @@ -1222,49 +1222,49 @@ void ItemModifyingGUI::IdentifyGUI_HandleItemImages() */ void ItemModifyingGUI::RemoveCurseGUI_Process(Item* const selectedItem) { - if ( selectedItem == nullptr ) - { - printlog("ERROR: RemoveCurseGUI_Process() - selectedItem is null."); - return; - } - - // Cursed Scrolls don't use the GUI so they will never call this function - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - // Uncurse the selected Item - messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." - selectedItem->beatitude = 0; - break; - case 1: - // Uncurse the selected Item and 1 random Cursed Item in their Inventory - messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." - selectedItem->beatitude = 0; - RemoveCurseGUI_ProcessRandom(1); - break; - case 2: - // Uncurse the selected Item and 2 random Cursed Items in their Inventory - messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." - selectedItem->beatitude = 0; - RemoveCurseGUI_ProcessRandom(2); - break; - default: printlog("ERROR: RemoveCurseGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; - } - - // If the Player used a Scroll, consume it - if ( itemModifyingGUI_ScrollUsed != nullptr ) - { - consumeItem(itemModifyingGUI_ScrollUsed); - itemModifyingGUI_ScrollUsed = nullptr; - } - - CloseGUI(); - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) - { - RemoveCurseGUI_UpdateServer(selectedItem); - } + if ( selectedItem == nullptr ) + { + printlog("ERROR: RemoveCurseGUI_Process() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Uncurse the selected Item + messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." + selectedItem->beatitude = 0; + break; + case 1: + // Uncurse the selected Item and 1 random Cursed Item in their Inventory + messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." + selectedItem->beatitude = 0; + RemoveCurseGUI_ProcessRandom(1); + break; + case 2: + // Uncurse the selected Item and 2 random Cursed Items in their Inventory + messagePlayer(clientnum, language[348], selectedItem->description()); // "Uncursed "%s"." + selectedItem->beatitude = 0; + RemoveCurseGUI_ProcessRandom(2); + break; + default: printlog("ERROR: RemoveCurseGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + CloseGUI(); + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + RemoveCurseGUI_UpdateServer(selectedItem); + } } // RemoveCurseGUI_Process() /* ItemModifyingGUI.cpp @@ -1274,176 +1274,176 @@ void ItemModifyingGUI::RemoveCurseGUI_Process(Item* const selectedItem) */ void ItemModifyingGUI::RemoveCurseGUI_ProcessRandom(const Uint8 numItems) { - // Grab the Player's Inventory again, as it may have been modified prior to this - list_t* playerInventoryList = &stats[clientnum]->inventory; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: RemoveCurseGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the GUI Inventory - Uint8 totalAmountOfItems = 0; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude >= 0 ) // Skip over all Cursed Items - { - totalAmountOfItems++; - } - break; - case 1: - // Intentional fall-through - case 2: - if ( item->beatitude < 0 ) // Skip over all Uncursed Items - { - totalAmountOfItems++; - } - break; - default: printlog("ERROR: RemoveCurseGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - // There are no valid Items to be processed - if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - return; - } - else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." - return; - } - - Uint8 amountOfItemsLeftToProcess = numItems; - bool isThereASingleItem = false; - - // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop - if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - - Sint8 iPreviousItemProcessedIndex = -1; - Sint8 iItemToProcessIndex = -1; - Uint8 iRemoveCurseGUIInventoryIndex = 0; - - for ( Uint8 i = 0; i < numItems; i++ ) - { - while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) - { - iItemToProcessIndex = rand() % totalAmountOfItems; - } - - iRemoveCurseGUIInventoryIndex = 0; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* itemToProcess = static_cast(iInventoryNode->element); - - if ( itemToProcess == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( itemToProcess->beatitude >= 0 ) // Skip over all Cursed Items - { - if ( iRemoveCurseGUIInventoryIndex == iItemToProcessIndex ) - { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) - { - messagePlayer(clientnum, language[2515], itemToProcess->description()); // "Oh no! Your %s was cursed too!" - } - else - { - messagePlayer(clientnum, language[2507], itemToProcess->description()); // "Your %s was cursed!" - } - - itemToProcess->beatitude = -1; - amountOfItemsLeftToProcess--; - iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) - { - RemoveCurseGUI_UpdateServer(itemToProcess); - } - } - iRemoveCurseGUIInventoryIndex++; - } - break; - case 1: - // Intentional fall-through - case 2: - if ( itemToProcess->beatitude < 0 ) // Skip over all Uncursed Items - { - if ( iRemoveCurseGUIInventoryIndex == iItemToProcessIndex ) - { - messagePlayer(clientnum, language[2512], itemToProcess->description()); // "Wow! Your %s was uncursed too!" - itemToProcess->beatitude = 0; - amountOfItemsLeftToProcess--; - iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) - { - RemoveCurseGUI_UpdateServer(itemToProcess); - } - } - iRemoveCurseGUIInventoryIndex++; - } - break; - default: printlog("ERROR: RemoveCurseGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - // If processing is done, stop searching the Inventory - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // If there's only a single valid Item, but it's a +-2 scroll, this will happen - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // Tell the Player they were an Item short of the full effect - if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - } - else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." - } + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: RemoveCurseGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude >= 0 ) // Skip over all Cursed Items + { + totalAmountOfItems++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( item->beatitude < 0 ) // Skip over all Uncursed Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: RemoveCurseGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iRemoveCurseGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iRemoveCurseGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->beatitude >= 0 ) // Skip over all Cursed Items + { + if ( iRemoveCurseGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) + { + messagePlayer(clientnum, language[2515], itemToProcess->description()); // "Oh no! Your %s was cursed too!" + } + else + { + messagePlayer(clientnum, language[2507], itemToProcess->description()); // "Your %s was cursed!" + } + + itemToProcess->beatitude = -1; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + RemoveCurseGUI_UpdateServer(itemToProcess); + } + } + iRemoveCurseGUIInventoryIndex++; + } + break; + case 1: + // Intentional fall-through + case 2: + if ( itemToProcess->beatitude < 0 ) // Skip over all Uncursed Items + { + if ( iRemoveCurseGUIInventoryIndex == iItemToProcessIndex ) + { + messagePlayer(clientnum, language[2512], itemToProcess->description()); // "Wow! Your %s was uncursed too!" + itemToProcess->beatitude = 0; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iRemoveCurseGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + RemoveCurseGUI_UpdateServer(itemToProcess); + } + } + iRemoveCurseGUIInventoryIndex++; + } + break; + default: printlog("ERROR: RemoveCurseGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } } // RemoveCurseGUI_ProcessRandom() /* ItemModifyingGUI.cpp @@ -1452,124 +1452,124 @@ void ItemModifyingGUI::RemoveCurseGUI_ProcessRandom(const Uint8 numItems) */ void ItemModifyingGUI::RemoveCurseGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - Uint8 iRemoveCurseGUIInventoryIndex = 0; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: RemoveCurseGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the GUI Inventory - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude >= 0 ) // Skip over all Cursed Items - { - ++iRemoveCurseGUIInventoryIndex; - } - break; - case 0: - // Intentional fall-through - case 1: - // Intentional fall-through - case 2: - if ( item->identified == true && item->beatitude < 0 ) // Skip over all Unidentified and Uncursed Items - { - ++iRemoveCurseGUIInventoryIndex; - } - break; - default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iRemoveCurseGUIInventoryIndex - 4)); - - // Reset the current Inventory - for ( iRemoveCurseGUIInventoryIndex = 0; iRemoveCurseGUIInventoryIndex < 4; ++iRemoveCurseGUIInventoryIndex ) - { - itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex] = nullptr; - } - - iRemoveCurseGUIInventoryIndex = 0; - - // Assign the visible Items to the GUI slots - bool bBreakFromLoop = false; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude >= 0 ) // Skip over all Cursed Items - { - ++iRemoveCurseGUIInventoryIndex; - - if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 0: - // Intentional fall-through - case 1: - // Intentional fall-through - case 2: - if ( item->identified == true && item->beatitude < 0 ) // Skip over all Unidentified and Uncursed Items - { - ++iRemoveCurseGUIInventoryIndex; - - if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: RemoveCurseGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iRemoveCurseGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: RemoveCurseGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude >= 0 ) // Skip over all Cursed Items + { + ++iRemoveCurseGUIInventoryIndex; + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified == true && item->beatitude < 0 ) // Skip over all Unidentified and Uncursed Items + { + ++iRemoveCurseGUIInventoryIndex; + } + break; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iRemoveCurseGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iRemoveCurseGUIInventoryIndex = 0; iRemoveCurseGUIInventoryIndex < 4; ++iRemoveCurseGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex] = nullptr; + } + + iRemoveCurseGUIInventoryIndex = 0; + + // Assign the visible Items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude >= 0 ) // Skip over all Cursed Items + { + ++iRemoveCurseGUIInventoryIndex; + + if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + // Intentional fall-through + case 1: + // Intentional fall-through + case 2: + if ( item->identified == true && item->beatitude < 0 ) // Skip over all Unidentified and Uncursed Items + { + ++iRemoveCurseGUIInventoryIndex; + + if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: RemoveCurseGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } } // RemoveCurseGUI_RebuildInventory() /* ItemModifyingGUI.cpp @@ -1577,67 +1577,67 @@ void ItemModifyingGUI::RemoveCurseGUI_RebuildInventory() */ void ItemModifyingGUI::RemoveCurseGUI_HandleItemImages() { - Uint8 iRemoveCurseGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iRemoveCurseGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other - - Item* item = nullptr; // The given Item being drawn from the GUI Inventory - SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - if ( iInventoryNode->element != nullptr ) - { - item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Cursed Scrolls don't need to be shown, as they wont have a GUI - if ( item->identified == true && item->beatitude < 0 ) - { - iRemoveCurseGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRemoveCurseGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iRemoveCurseGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - break; - } - } - } - } + Uint8 iRemoveCurseGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iRemoveCurseGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + if ( item->identified == true && item->beatitude < 0 ) + { + iRemoveCurseGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRemoveCurseGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRemoveCurseGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRemoveCurseGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRemoveCurseGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRemoveCurseGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + break; + } + } + } + } } // RemoveCurseGUI_HandleItemImages() /* ItemModifyingGUI.cpp @@ -1647,73 +1647,73 @@ void ItemModifyingGUI::RemoveCurseGUI_HandleItemImages() */ void ItemModifyingGUI::RemoveCurseGUI_UpdateServer(Item* const selectedItem) { - // Convert the Item type to an int for the packet - Uint8 itemType = 10; - if ( selectedItem == stats[clientnum]->helmet ) - { - itemType = 0; - } - else if ( selectedItem == stats[clientnum]->breastplate ) - { - itemType = 1; - } - else if ( selectedItem == stats[clientnum]->gloves ) - { - itemType = 2; - } - else if ( selectedItem == stats[clientnum]->shoes ) - { - itemType = 3; - } - else if ( selectedItem == stats[clientnum]->shield ) - { - itemType = 4; - } - else if ( selectedItem == stats[clientnum]->weapon ) - { - itemType = 5; - } - else if ( selectedItem == stats[clientnum]->cloak ) - { - itemType = 6; - } - else if ( selectedItem == stats[clientnum]->amulet ) - { - itemType = 7; - } - else if ( selectedItem == stats[clientnum]->ring ) - { - itemType = 8; - } - else if ( selectedItem == stats[clientnum]->mask ) - { - itemType = 9; - } - - // If none of the above is true, then this shouldn't have happened in the first place - if ( itemType == 10 ) - { - printlog("ERROR: RemoveCurseGUI_UpdateServer() - itemType is out of bounds."); - return; - } - - Uint8 isScrollCursed = 0; - if ( itemModifyingGUI_ScrollBeatitude < 0 ) - { - isScrollCursed = 1; - } - - // data[4] = The type of Item as a Uint8 - // data[5] = 0 if the Scroll was Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Uncursed or Cursed - // data[6] = The Player that is sending the message - strcpy((char*)net_packet->data, "CRCU"); - net_packet->data[4] = itemType; - net_packet->data[5] = isScrollCursed; - net_packet->data[6] = clientnum; - net_packet->address.host = net_server.host; - net_packet->address.port = net_server.port; - net_packet->len = 7; - sendPacketSafe(net_sock, -1, net_packet, 0); + // Convert the Item type to an int for the packet + Uint8 itemType = 10; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->weapon ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 8; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 9; + } + + // If none of the above is true, then this shouldn't have happened in the first place + if ( itemType == 10 ) + { + printlog("ERROR: RemoveCurseGUI_UpdateServer() - itemType is out of bounds."); + return; + } + + Uint8 isScrollCursed = 0; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + isScrollCursed = 1; + } + + // data[4] = The type of Item as a Uint8 + // data[5] = 0 if the Scroll was Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Uncursed or Cursed + // data[6] = The Player that is sending the message + strcpy((char*)net_packet->data, "CRCU"); + net_packet->data[4] = itemType; + net_packet->data[5] = isScrollCursed; + net_packet->data[6] = clientnum; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 7; + sendPacketSafe(net_sock, -1, net_packet, 0); } // RemoveCurseGUI_UpdateServer() // REPAIR GUI @@ -1728,44 +1728,44 @@ void ItemModifyingGUI::RemoveCurseGUI_UpdateServer(Item* const selectedItem) */ void ItemModifyingGUI::RepairGUI_Process(Item* const selectedItem) { - if ( selectedItem == nullptr ) - { - printlog("ERROR: RepairGUI_Process() - selectedItem is null."); - return; - } - - // Cursed Scrolls don't use the GUI so they will never call this function - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - // Intentional fall-through - case 1: - // Repair the Item if it is Broken (+1 only), Decrepit, or Worn up to Serviceable - messagePlayer(clientnum, language[872], selectedItem->description()); // "Your %s looks better!" - selectedItem->status = SERVICABLE; - break; - case 2: - // Repair the Item if it is Broken, Decrepit, Worn, or Serviceable up to Excellent - messagePlayer(clientnum, language[2517], selectedItem->description()); // "Your %s looks perfect now!" - selectedItem->status = EXCELLENT; - break; - default: printlog("ERROR: RepairGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; - } - - // If the Player used a Scroll, consume it. Currently there is no Spell of Repair - if ( itemModifyingGUI_ScrollUsed != nullptr ) - { - consumeItem(itemModifyingGUI_ScrollUsed); - itemModifyingGUI_ScrollUsed = nullptr; - } - - CloseGUI(); - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) - { - RepairGUI_UpdateServer(selectedItem); - } + if ( selectedItem == nullptr ) + { + printlog("ERROR: RepairGUI_Process() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Intentional fall-through + case 1: + // Repair the Item if it is Broken (+1 only), Decrepit, or Worn up to Serviceable + messagePlayer(clientnum, language[872], selectedItem->description()); // "Your %s looks better!" + selectedItem->status = SERVICABLE; + break; + case 2: + // Repair the Item if it is Broken, Decrepit, Worn, or Serviceable up to Excellent + messagePlayer(clientnum, language[2517], selectedItem->description()); // "Your %s looks perfect now!" + selectedItem->status = EXCELLENT; + break; + default: printlog("ERROR: RepairGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it. Currently there is no Spell of Repair + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + CloseGUI(); + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + RepairGUI_UpdateServer(selectedItem); + } } // RepairGUI_Process() /* ItemModifyingGUI.cpp @@ -1775,159 +1775,159 @@ void ItemModifyingGUI::RepairGUI_Process(Item* const selectedItem) */ void ItemModifyingGUI::RepairGUI_ProcessRandom(const Uint8 numItems) { - // Grab the Player's Inventory again, as it may have been modified prior to this - list_t* playerInventoryList = &stats[clientnum]->inventory; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: RepairGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the GUI Inventory - Uint8 totalAmountOfItems = 0; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->status != BROKEN ) // Skip over all Broken Items - { - totalAmountOfItems++; - } - break; - default: printlog("ERROR: RepairGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - // There are no valid Items to be processed - if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - return; - } - else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." - return; - } - - Uint8 amountOfItemsLeftToProcess = numItems; - bool isThereASingleItem = false; - - // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop - if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - - Sint8 iPreviousItemProcessedIndex = -1; - Sint8 iItemToProcessIndex = -1; - Uint8 iRepairGUIInventoryIndex = 0; - - for ( Uint8 i = 0; i < numItems; i++ ) - { - while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) - { - iItemToProcessIndex = rand() % totalAmountOfItems; - } - - iRepairGUIInventoryIndex = 0; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* itemToProcess = static_cast(iInventoryNode->element); - - if ( itemToProcess == nullptr ) - { - continue; - } - - // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(itemToProcess) == POTION || itemCategory(itemToProcess) == SCROLL || itemCategory(itemToProcess) == SPELLBOOK || itemCategory(itemToProcess) == GEM || itemCategory(itemToProcess) == THROWN || itemCategory(itemToProcess) == FOOD || itemCategory(itemToProcess) == BOOK || itemCategory(itemToProcess) == SPELL_CAT ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( itemToProcess->status != BROKEN ) // Skip over all Cursed Items - { - if ( iRepairGUIInventoryIndex == iItemToProcessIndex ) - { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) - { - messagePlayer(clientnum, language[2516], itemToProcess->description()); // "Oh no! Your %s was broken too!" - } - else - { - messagePlayer(clientnum, language[2508], itemToProcess->description()); // "Your %s is now broken!" - } - - itemToProcess->status = BROKEN; - amountOfItemsLeftToProcess--; - iPreviousItemProcessedIndex = iRepairGUIInventoryIndex; - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) - { - RepairGUI_UpdateServer(itemToProcess); - } - } - iRepairGUIInventoryIndex++; - } - break; - default: printlog("ERROR: RepairGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - // If processing is done, stop searching the Inventory - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // If there's only a single valid Item, but it's a +-2 scroll, this will happen - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // Tell the Player they were an Item short of the full effect - if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - } - else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." - } + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: RepairGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->status != BROKEN ) // Skip over all Broken Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: RepairGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iRepairGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iRepairGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(itemToProcess) == POTION || itemCategory(itemToProcess) == SCROLL || itemCategory(itemToProcess) == SPELLBOOK || itemCategory(itemToProcess) == GEM || itemCategory(itemToProcess) == THROWN || itemCategory(itemToProcess) == FOOD || itemCategory(itemToProcess) == BOOK || itemCategory(itemToProcess) == SPELL_CAT ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->status != BROKEN ) // Skip over all Cursed Items + { + if ( iRepairGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) + { + messagePlayer(clientnum, language[2516], itemToProcess->description()); // "Oh no! Your %s was broken too!" + } + else + { + messagePlayer(clientnum, language[2508], itemToProcess->description()); // "Your %s is now broken!" + } + + itemToProcess->status = BROKEN; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iRepairGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + RepairGUI_UpdateServer(itemToProcess); + } + } + iRepairGUIInventoryIndex++; + } + break; + default: printlog("ERROR: RepairGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } } // RepairGUI_ProcessRandom() /* ItemModifyingGUI.cpp @@ -1936,176 +1936,176 @@ void ItemModifyingGUI::RepairGUI_ProcessRandom(const Uint8 numItems) */ void ItemModifyingGUI::RepairGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - Uint8 iRepairGUIInventoryIndex = 0; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: RepairGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the Repair GUI Inventory - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->status != BROKEN ) // Skip over all Broken Items - { - ++iRepairGUIInventoryIndex; - } - break; - case 0: - if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items - { - ++iRepairGUIInventoryIndex; - } - break; - case 1: - if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable and Excellent Items - { - ++iRepairGUIInventoryIndex; - } - break; - case 2: - if ( item->status != EXCELLENT ) // Skip over all Excellent Items - { - ++iRepairGUIInventoryIndex; - } - break; - default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iRepairGUIInventoryIndex - 4)); - - // Reset the current Inventory - for ( iRepairGUIInventoryIndex = 0; iRepairGUIInventoryIndex < 4; ++iRepairGUIInventoryIndex ) - { - itemModifyingGUI_Inventory[iRepairGUIInventoryIndex] = nullptr; - } - - iRepairGUIInventoryIndex = 0; - - // Assign the visible Items to the GUI slots - bool bBreakFromLoop = false; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->status != BROKEN ) // Skip over all Broken Items - { - ++iRepairGUIInventoryIndex; - - if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 0: - if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items - { - ++iRepairGUIInventoryIndex; - - if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 1: - if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable, and Excellent Items - { - ++iRepairGUIInventoryIndex; - - if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 2: - if ( item->status != EXCELLENT ) // Skip over all Excellent Items - { - ++iRepairGUIInventoryIndex; - - if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iRepairGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: RepairGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the Repair GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->status != BROKEN ) // Skip over all Broken Items + { + ++iRepairGUIInventoryIndex; + } + break; + case 0: + if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items + { + ++iRepairGUIInventoryIndex; + } + break; + case 1: + if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable and Excellent Items + { + ++iRepairGUIInventoryIndex; + } + break; + case 2: + if ( item->status != EXCELLENT ) // Skip over all Excellent Items + { + ++iRepairGUIInventoryIndex; + } + break; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iRepairGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iRepairGUIInventoryIndex = 0; iRepairGUIInventoryIndex < 4; ++iRepairGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex] = nullptr; + } + + iRepairGUIInventoryIndex = 0; + + // Assign the visible Items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->status != BROKEN ) // Skip over all Broken Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable, and Excellent Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( item->status != EXCELLENT ) // Skip over all Excellent Items + { + ++iRepairGUIInventoryIndex; + + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: RepairGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } } // RepairGUI_RebuildInventory() /* ItemModifyingGUI.cpp @@ -2113,165 +2113,165 @@ void ItemModifyingGUI::RepairGUI_RebuildInventory() */ void ItemModifyingGUI::RepairGUI_HandleItemImages() { - bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) - Uint8 iRepairGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iRepairGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other - - Item* item = nullptr; // The given Item being drawn from the GUI Inventory - SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - if ( iInventoryNode->element != nullptr ) - { - item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component - if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) - { - continue; - } - - // Cursed Scrolls don't need to be shown, as they wont have a GUI - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items - { - iRepairGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iRepairGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 1: - if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable, and Excellent Items - { - iRepairGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iRepairGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 2: - if ( item->status != EXCELLENT ) // Skip over all Excellent Items - { - iRepairGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iRepairGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: RepairGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } - } + bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) + Uint8 iRepairGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iRepairGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that don't need to be repaired TODOR: Item's should have a "repairable" component + if ( itemCategory(item) != WEAPON && itemCategory(item) != ARMOR && item->type != AMULET_LIFESAVING && item->type != AMULET_MAGICREFLECTION && itemCategory(item) != MAGICSTAFF && item->type != TOOL_PICKAXE ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + if ( item->status != BROKEN && item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Broken, Serviceable, and Excellent Items + { + iRepairGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRepairGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->status != SERVICABLE && item->status != EXCELLENT ) // Skip over all Serviceable, and Excellent Items + { + iRepairGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRepairGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( item->status != EXCELLENT ) // Skip over all Excellent Items + { + iRepairGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iRepairGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iRepairGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iRepairGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iRepairGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iRepairGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: RepairGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } + } } // RepairGUI_HandleItemImages() /* ItemModifyingGUI.cpp @@ -2281,67 +2281,67 @@ void ItemModifyingGUI::RepairGUI_HandleItemImages() */ void ItemModifyingGUI::RepairGUI_UpdateServer(Item* const selectedItem) { - // Convert the Item type to an int for the packet - Uint8 itemType = 10; - if ( selectedItem == stats[clientnum]->helmet ) - { - itemType = 0; - } - else if ( selectedItem == stats[clientnum]->breastplate ) - { - itemType = 1; - } - else if ( selectedItem == stats[clientnum]->gloves ) - { - itemType = 2; - } - else if ( selectedItem == stats[clientnum]->shoes ) - { - itemType = 3; - } - else if ( selectedItem == stats[clientnum]->shield ) - { - itemType = 4; - } - else if ( selectedItem == stats[clientnum]->weapon ) - { - itemType = 5; - } - else if ( selectedItem == stats[clientnum]->cloak ) - { - itemType = 6; - } - else if ( selectedItem == stats[clientnum]->amulet ) - { - itemType = 7; - } - else if ( selectedItem == stats[clientnum]->ring ) - { - itemType = 8; - } - else if ( selectedItem == stats[clientnum]->mask ) - { - itemType = 9; - } - - // If none of the above is true, then this shouldn't have happened in the first place - if ( itemType == 10 ) - { - printlog("ERROR: RepairGUI_UpdateServer() - itemType is out of bounds."); - return; - } - - // data[4] = The type of Item as a Uint8 - // data[5] = The updated ItemStatus of the Armor as a Uint8 - // data[6] = The Player that is sending the message - strcpy((char*)net_packet->data, "CREP"); - net_packet->data[4] = itemType; - net_packet->data[5] = static_cast(selectedItem->status); - net_packet->data[6] = static_cast(clientnum); - net_packet->address.host = net_server.host; - net_packet->address.port = net_server.port; - net_packet->len = 7; - sendPacketSafe(net_sock, -1, net_packet, 0); + // Convert the Item type to an int for the packet + Uint8 itemType = 10; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->weapon ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 8; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 9; + } + + // If none of the above is true, then this shouldn't have happened in the first place + if ( itemType == 10 ) + { + printlog("ERROR: RepairGUI_UpdateServer() - itemType is out of bounds."); + return; + } + + // data[4] = The type of Item as a Uint8 + // data[5] = The updated ItemStatus of the Armor as a Uint8 + // data[6] = The Player that is sending the message + strcpy((char*)net_packet->data, "CREP"); + net_packet->data[4] = itemType; + net_packet->data[5] = static_cast(selectedItem->status); + net_packet->data[6] = static_cast(clientnum); + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 7; + sendPacketSafe(net_sock, -1, net_packet, 0); } // RepairGUI_UpdateServer() // ENCHANT WEAPON GUI @@ -2356,59 +2356,59 @@ void ItemModifyingGUI::RepairGUI_UpdateServer(Item* const selectedItem) */ void ItemModifyingGUI::EnchantWeaponGUI_Process(Item* const selectedItem) { - if ( selectedItem == nullptr ) - { - printlog("ERROR: EnchantWeaponGUI_Process() - selectedItem is null."); - return; - } - - // Cursed Scrolls don't use the GUI so they will never call this function - ItemType itemType = WOODEN_SHIELD; - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - // Enchant the Item if it is a weapon +0 or +1 up to +2. Cannot Enchant Artifacts - messagePlayer(clientnum, language[2520], selectedItem->description()); // "Your %s glows blue!" - selectedItem->beatitude = 2; - break; - case 1: - // Enchant the Item if it is a weapon +0, +1, or +2 up to +3. Cannot Enchant Artifacts - messagePlayer(clientnum, language[2521], selectedItem->description()); // "Your %s violently glows blue!" - selectedItem->beatitude = 3; - break; - case 2: - // Enchant the Item if it is a weapon +0, +1, +2, +3, or +4 up to +5. Raises any Artifact Weapon by one level - messagePlayer(clientnum, language[2522], selectedItem->description()); // "Your %s radiates power!" - itemType = selectedItem->type; - if ( itemType == ARTIFACT_SWORD || itemType == ARTIFACT_MACE || itemType == ARTIFACT_SPEAR || itemType == ARTIFACT_AXE || itemType == ARTIFACT_BOW ) - { - selectedItem->beatitude++; - } - else - { - selectedItem->beatitude = 5; - } - break; - default: printlog("ERROR: EnchantWeaponGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; - } - - // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon - if ( itemModifyingGUI_ScrollUsed != nullptr ) - { - consumeItem(itemModifyingGUI_ScrollUsed); - itemModifyingGUI_ScrollUsed = nullptr; - } - - CloseGUI(); - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) - { - if ( selectedItem == stats[clientnum]->weapon ) - { - EnchantWeaponGUI_UpdateServer(); - } - } + if ( selectedItem == nullptr ) + { + printlog("ERROR: EnchantWeaponGUI_Process() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + ItemType itemType = WOODEN_SHIELD; + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Enchant the Item if it is a weapon +0 or +1 up to +2. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2520], selectedItem->description()); // "Your %s glows blue!" + selectedItem->beatitude = 2; + break; + case 1: + // Enchant the Item if it is a weapon +0, +1, or +2 up to +3. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2521], selectedItem->description()); // "Your %s violently glows blue!" + selectedItem->beatitude = 3; + break; + case 2: + // Enchant the Item if it is a weapon +0, +1, +2, +3, or +4 up to +5. Raises any Artifact Weapon by one level + messagePlayer(clientnum, language[2522], selectedItem->description()); // "Your %s radiates power!" + itemType = selectedItem->type; + if ( itemType == ARTIFACT_SWORD || itemType == ARTIFACT_MACE || itemType == ARTIFACT_SPEAR || itemType == ARTIFACT_AXE || itemType == ARTIFACT_BOW ) + { + selectedItem->beatitude++; + } + else + { + selectedItem->beatitude = 5; + } + break; + default: printlog("ERROR: EnchantWeaponGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + CloseGUI(); + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + if ( selectedItem == stats[clientnum]->weapon ) + { + EnchantWeaponGUI_UpdateServer(); + } + } } // EnchantWeaponGUI_Process() /* ItemModifyingGUI.cpp @@ -2418,162 +2418,162 @@ void ItemModifyingGUI::EnchantWeaponGUI_Process(Item* const selectedItem) */ void ItemModifyingGUI::EnchantWeaponGUI_ProcessRandom(const Uint8 numItems) { - // Grab the Player's Inventory again, as it may have been modified prior to this - list_t* playerInventoryList = &stats[clientnum]->inventory; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the GUI Inventory - Uint8 totalAmountOfItems = 0; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that aren't Weapons - if ( itemCategory(item) != WEAPON ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude > 0) // Skip over all Cursed and Unenchanted Items - { - totalAmountOfItems++; - } - break; - default: printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - // There are no valid Items to be processed - if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - return; - } - else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." - return; - } - - Uint8 amountOfItemsLeftToProcess = numItems; - bool isThereASingleItem = false; - - // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop - if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - - Sint8 iPreviousItemProcessedIndex = -1; - Sint8 iItemToProcessIndex = -1; - Uint8 iEnchantWeaponGUIInventoryIndex = 0; - - for ( Uint8 i = 0; i < numItems; i++ ) - { - while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) - { - iItemToProcessIndex = rand() % totalAmountOfItems; - } - - iEnchantWeaponGUIInventoryIndex = 0; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* itemToProcess = static_cast(iInventoryNode->element); - - if ( itemToProcess == nullptr ) - { - continue; - } - - // Skip all Items that aren't Weapons - if ( itemCategory(itemToProcess) != WEAPON ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( itemToProcess->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items - { - if ( iEnchantWeaponGUIInventoryIndex == iItemToProcessIndex ) - { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) - { - messagePlayer(clientnum, language[2523], itemToProcess->description()); // "Oh no! Your %s was disenchanted too!" - } - else - { - messagePlayer(clientnum, language[2509], itemToProcess->description()); // "Your %s was disenchanted!" - } - - itemToProcess->beatitude = 0; - amountOfItemsLeftToProcess--; - iPreviousItemProcessedIndex = iEnchantWeaponGUIInventoryIndex; - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) - { - if ( itemToProcess == stats[clientnum]->weapon ) - { - EnchantWeaponGUI_UpdateServer(); - } - } - } - iEnchantWeaponGUIInventoryIndex++; - } - break; - default: printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - // If processing is done, stop searching the Inventory - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // If there's only a single valid Item, but it's a +-2 scroll, this will happen - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // Tell the Player they were an Item short of the full effect - if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - } - else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." - } + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iEnchantWeaponGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iEnchantWeaponGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(itemToProcess) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + if ( iEnchantWeaponGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) + { + messagePlayer(clientnum, language[2523], itemToProcess->description()); // "Oh no! Your %s was disenchanted too!" + } + else + { + messagePlayer(clientnum, language[2509], itemToProcess->description()); // "Your %s was disenchanted!" + } + + itemToProcess->beatitude = 0; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iEnchantWeaponGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + if ( itemToProcess == stats[clientnum]->weapon ) + { + EnchantWeaponGUI_UpdateServer(); + } + } + } + iEnchantWeaponGUIInventoryIndex++; + } + break; + default: printlog("ERROR: EnchantWeaponGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } } // EnchantWeaponGUI_ProcessRandom() /* ItemModifyingGUI.cpp @@ -2582,194 +2582,194 @@ void ItemModifyingGUI::EnchantWeaponGUI_ProcessRandom(const Uint8 numItems) */ void ItemModifyingGUI::EnchantWeaponGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - Uint8 iEnchantWeaponGUIInventoryIndex = 0; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the Repair GUI Inventory - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that aren't Weapons - if ( itemCategory(item) != WEAPON ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items - { - ++iEnchantWeaponGUIInventoryIndex; - } - break; - case 0: - if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts - { - if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) - { - continue; - } - ++iEnchantWeaponGUIInventoryIndex; - } - break; - case 1: - if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts - { - if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) - { - continue; - } - ++iEnchantWeaponGUIInventoryIndex; - } - break; - case 2: - if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon - { - ++iEnchantWeaponGUIInventoryIndex; - } - break; - default: printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iEnchantWeaponGUIInventoryIndex - 4)); - - // Reset the current Inventory - for ( iEnchantWeaponGUIInventoryIndex = 0; iEnchantWeaponGUIInventoryIndex < 4; ++iEnchantWeaponGUIInventoryIndex ) - { - itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex] = nullptr; - } - - iEnchantWeaponGUIInventoryIndex = 0; - - // Assign the visible Items to the GUI slots - bool bBreakFromLoop = false; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that aren't Weapons - if ( itemCategory(item) != WEAPON ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items - { - ++iEnchantWeaponGUIInventoryIndex; - - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 0: - if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts - { - if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) - { - continue; - } - - ++iEnchantWeaponGUIInventoryIndex; - - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 1: - if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts - { - if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) - { - continue; - } - - ++iEnchantWeaponGUIInventoryIndex; - - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 2: - if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon - { - ++iEnchantWeaponGUIInventoryIndex; - - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iEnchantWeaponGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the Repair GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantWeaponGUIInventoryIndex; + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + ++iEnchantWeaponGUIInventoryIndex; + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + ++iEnchantWeaponGUIInventoryIndex; + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon + { + ++iEnchantWeaponGUIInventoryIndex; + } + break; + default: printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iEnchantWeaponGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iEnchantWeaponGUIInventoryIndex = 0; iEnchantWeaponGUIInventoryIndex < 4; ++iEnchantWeaponGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex] = nullptr; + } + + iEnchantWeaponGUIInventoryIndex = 0; + + // Assign the visible Items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon + { + ++iEnchantWeaponGUIInventoryIndex; + + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: EnchantWeaponGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } } // EnchantWeaponGUI_RebuildInventory() /* ItemModifyingGUI.cpp @@ -2777,175 +2777,175 @@ void ItemModifyingGUI::EnchantWeaponGUI_RebuildInventory() */ void ItemModifyingGUI::EnchantWeaponGUI_HandleItemImages() { - bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) - Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other - - Item* item = nullptr; // The given Item being drawn from the GUI Inventory - SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - if ( iInventoryNode->element != nullptr ) - { - item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - // Skip all Items that aren't Weapons - if ( itemCategory(item) != WEAPON ) - { - continue; - } - - // Cursed Scrolls don't need to be shown, as they wont have a GUI - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts - { - if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) - { - continue; - } - - iEnchantWeaponGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iEnchantWeaponGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 1: - if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts - { - if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) - { - continue; - } - - iEnchantWeaponGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iEnchantWeaponGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 2: - if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon - { - iEnchantWeaponGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iEnchantWeaponGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: EnchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } - } + bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) + Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + // Skip all Items that aren't Weapons + if ( itemCategory(item) != WEAPON ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + if ( item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_SWORD || item->type == ARTIFACT_MACE || item->type == ARTIFACT_SPEAR || item->type == ARTIFACT_AXE || item->type == ARTIFACT_BOW)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Weapon + { + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: EnchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } + } } // EnchantWeaponGUI_HandleItemImages() /* ItemModifyingGUI.cpp @@ -2954,21 +2954,21 @@ void ItemModifyingGUI::EnchantWeaponGUI_HandleItemImages() */ void ItemModifyingGUI::EnchantWeaponGUI_UpdateServer() { - Uint8 isScrollCursed = 0; - if ( itemModifyingGUI_ScrollBeatitude < 0 ) - { - isScrollCursed = 1; - } - - // data[4] = The Player that is sending the message - // data[5] = 0 if the Scroll was Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Enchanted or Disenchanted - strcpy((char*)net_packet->data, "CENW"); - net_packet->data[4] = clientnum; - net_packet->data[5] = isScrollCursed; - net_packet->address.host = net_server.host; - net_packet->address.port = net_server.port; - net_packet->len = 6; - sendPacketSafe(net_sock, -1, net_packet, 0); + Uint8 isScrollCursed = 0; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + isScrollCursed = 1; + } + + // data[4] = The Player that is sending the message + // data[5] = 0 if the Scroll was Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Enchanted or Disenchanted + strcpy((char*)net_packet->data, "CENW"); + net_packet->data[4] = clientnum; + net_packet->data[5] = isScrollCursed; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 6; + sendPacketSafe(net_sock, -1, net_packet, 0); } // EnchantWeaponGUI_UpdateServer() // ENCHANT ARMOR GUI @@ -2983,56 +2983,56 @@ void ItemModifyingGUI::EnchantWeaponGUI_UpdateServer() */ void ItemModifyingGUI::EnchantArmorGUI_Process(Item* const selectedItem) { - if ( selectedItem == nullptr ) - { - printlog("ERROR: EnchantArmorGUI_Process() - selectedItem is null."); - return; - } - - // Cursed Scrolls don't use the GUI so they will never call this function - ItemType itemType = WOODEN_SHIELD; - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - // Enchant the Item if it is a Shield, Breastpiece, or Helm +0 or +1 up to +2. Cannot Enchant Artifacts - messagePlayer(clientnum, language[2520], selectedItem->description()); // "Your %s glows blue!" - selectedItem->beatitude = 2; - break; - case 1: - // Enchant the Item if it is a Shield, Breastpiece, Helm, Boots, or Gloves +0, +1, or +2 up to +3. Cannot Enchant Artifacts - messagePlayer(clientnum, language[2521], selectedItem->description()); // "Your %s violently glows blue!" - selectedItem->beatitude = 3; - break; - case 2: - // Enchant the Item if it is a Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks +0, +1, +2, +3, or +4 up to +5. Raises any Artifact Armor by one level - messagePlayer(clientnum, language[2522], selectedItem->description()); // "Your %s radiates power!" - itemType = selectedItem->type; - if ( itemType == ARTIFACT_BREASTPIECE || itemType == ARTIFACT_HELM || itemType == ARTIFACT_BOOTS || itemType == ARTIFACT_CLOAK || itemType == ARTIFACT_GLOVES ) - { - selectedItem->beatitude++; - } - else - { - selectedItem->beatitude = 5; - } - break; - default: printlog("ERROR: EnchantArmorGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; - } - - // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon - if ( itemModifyingGUI_ScrollUsed != nullptr ) - { - consumeItem(itemModifyingGUI_ScrollUsed); - itemModifyingGUI_ScrollUsed = nullptr; - } - - CloseGUI(); - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) - { - EnchantArmorGUI_UpdateServer(selectedItem); - } + if ( selectedItem == nullptr ) + { + printlog("ERROR: EnchantArmorGUI_Process() - selectedItem is null."); + return; + } + + // Cursed Scrolls don't use the GUI so they will never call this function + ItemType itemType = WOODEN_SHIELD; + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + // Enchant the Item if it is a Shield, Breastpiece, or Helm +0 or +1 up to +2. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2520], selectedItem->description()); // "Your %s glows blue!" + selectedItem->beatitude = 2; + break; + case 1: + // Enchant the Item if it is a Shield, Breastpiece, Helm, Boots, or Gloves +0, +1, or +2 up to +3. Cannot Enchant Artifacts + messagePlayer(clientnum, language[2521], selectedItem->description()); // "Your %s violently glows blue!" + selectedItem->beatitude = 3; + break; + case 2: + // Enchant the Item if it is a Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks +0, +1, +2, +3, or +4 up to +5. Raises any Artifact Armor by one level + messagePlayer(clientnum, language[2522], selectedItem->description()); // "Your %s radiates power!" + itemType = selectedItem->type; + if ( itemType == ARTIFACT_BREASTPIECE || itemType == ARTIFACT_HELM || itemType == ARTIFACT_BOOTS || itemType == ARTIFACT_CLOAK || itemType == ARTIFACT_GLOVES ) + { + selectedItem->beatitude++; + } + else + { + selectedItem->beatitude = 5; + } + break; + default: printlog("ERROR: EnchantArmorGUI_Process() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds.", itemModifyingGUI_ScrollBeatitude); return; + } + + // If the Player used a Scroll, consume it. Currently there is no Spell of Enchant Weapon + if ( itemModifyingGUI_ScrollUsed != nullptr ) + { + consumeItem(itemModifyingGUI_ScrollUsed); + itemModifyingGUI_ScrollUsed = nullptr; + } + + CloseGUI(); + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(selectedItem, clientnum) ) + { + EnchantArmorGUI_UpdateServer(selectedItem); + } } // EnchantArmorGUI_Process() /* ItemModifyingGUI.cpp @@ -3042,163 +3042,163 @@ void ItemModifyingGUI::EnchantArmorGUI_Process(Item* const selectedItem) */ void ItemModifyingGUI::EnchantArmorGUI_ProcessRandom(const Uint8 numItems) { - // Grab the Player's Inventory again, as it may have been modified prior to this - list_t* playerInventoryList = &stats[clientnum]->inventory; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: EnchantArmorGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the GUI Inventory - Uint8 totalAmountOfItems = 0; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - ItemArmorType itemArmorType = getItemArmorType(item->type); - - // Skip all Items that aren't Armor - if ( itemArmorType == ItemArmorType::NOT_ARMOR ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items - { - totalAmountOfItems++; - } - break; - default: printlog("ERROR: EnchantArmorGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - // There are no valid Items to be processed - if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - return; - } - else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." - return; - } - - Uint8 amountOfItemsLeftToProcess = numItems; - bool isThereASingleItem = false; - - // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop - if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) - { - isThereASingleItem = true; - amountOfItemsLeftToProcess--; - } - - Sint8 iPreviousItemProcessedIndex = -1; - Sint8 iItemToProcessIndex = -1; - Uint8 iEnchantArmorGUIInventoryIndex = 0; - - for ( Uint8 i = 0; i < numItems; i++ ) - { - while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) - { - iItemToProcessIndex = rand() % totalAmountOfItems; - } - - iEnchantArmorGUIInventoryIndex = 0; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* itemToProcess = static_cast(iInventoryNode->element); - - if ( itemToProcess == nullptr ) - { - continue; - } - - ItemArmorType itemArmorType = getItemArmorType(itemToProcess->type); - - // Skip all Items that aren't Armor - if ( itemArmorType == ItemArmorType::NOT_ARMOR ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( itemToProcess->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items - { - if ( iEnchantArmorGUIInventoryIndex == iItemToProcessIndex ) - { - if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) - { - messagePlayer(clientnum, language[2523], itemToProcess->description()); // "Oh no! Your %s was disenchanted too!" - } - else - { - messagePlayer(clientnum, language[2509], itemToProcess->description()); // "Your %s was disenchanted!" - } - - itemToProcess->beatitude = 0; - amountOfItemsLeftToProcess--; - iPreviousItemProcessedIndex = iEnchantArmorGUIInventoryIndex; - - // The Client needs to inform the Server that their equipment was changed only if they have it equipped - if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) - { - EnchantArmorGUI_UpdateServer(itemToProcess); - } - } - iEnchantArmorGUIInventoryIndex++; - } - break; - default: printlog("ERROR: EnchantArmorGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - // If processing is done, stop searching the Inventory - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // If there's only a single valid Item, but it's a +-2 scroll, this will happen - if ( amountOfItemsLeftToProcess == 0 ) - { - break; - } - } - - // Tell the Player they were an Item short of the full effect - if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) - { - messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." - } - else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) - { - messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." - } + // Grab the Player's Inventory again, as it may have been modified prior to this + list_t* playerInventoryList = &stats[clientnum]->inventory; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: EnchantArmorGUI_ProcessRandom() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the GUI Inventory + Uint8 totalAmountOfItems = 0; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + totalAmountOfItems++; + } + break; + default: printlog("ERROR: EnchantArmorGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + // There are no valid Items to be processed + if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + return; + } + else if ( totalAmountOfItems == 0 && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no items for the scroll's curse..." + return; + } + + Uint8 amountOfItemsLeftToProcess = numItems; + bool isThereASingleItem = false; + + // If there is only a single Item that can be processed, but it's a +-2 Scroll, adjust the loop + if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude >= 2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + else if ( totalAmountOfItems == 1 && itemModifyingGUI_ScrollBeatitude <= -2 ) + { + isThereASingleItem = true; + amountOfItemsLeftToProcess--; + } + + Sint8 iPreviousItemProcessedIndex = -1; + Sint8 iItemToProcessIndex = -1; + Uint8 iEnchantArmorGUIInventoryIndex = 0; + + for ( Uint8 i = 0; i < numItems; i++ ) + { + while ( iItemToProcessIndex == iPreviousItemProcessedIndex ) + { + iItemToProcessIndex = rand() % totalAmountOfItems; + } + + iEnchantArmorGUIInventoryIndex = 0; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* itemToProcess = static_cast(iInventoryNode->element); + + if ( itemToProcess == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(itemToProcess->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( itemToProcess->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + if ( iEnchantArmorGUIInventoryIndex == iItemToProcessIndex ) + { + if ( numItems == 2 && amountOfItemsLeftToProcess == 1 && isThereASingleItem != true ) + { + messagePlayer(clientnum, language[2523], itemToProcess->description()); // "Oh no! Your %s was disenchanted too!" + } + else + { + messagePlayer(clientnum, language[2509], itemToProcess->description()); // "Your %s was disenchanted!" + } + + itemToProcess->beatitude = 0; + amountOfItemsLeftToProcess--; + iPreviousItemProcessedIndex = iEnchantArmorGUIInventoryIndex; + + // The Client needs to inform the Server that their equipment was changed only if they have it equipped + if ( multiplayer == CLIENT && itemIsEquipped(itemToProcess, clientnum) ) + { + EnchantArmorGUI_UpdateServer(itemToProcess); + } + } + iEnchantArmorGUIInventoryIndex++; + } + break; + default: printlog("ERROR: EnchantArmorGUI_ProcessRandom() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + // If processing is done, stop searching the Inventory + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // If there's only a single valid Item, but it's a +-2 scroll, this will happen + if ( amountOfItemsLeftToProcess == 0 ) + { + break; + } + } + + // Tell the Player they were an Item short of the full effect + if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude > 0 ) + { + messagePlayer(clientnum, language[2510]); // "You have no remaining items for the scroll's blessing..." + } + else if ( isThereASingleItem == true && itemModifyingGUI_ScrollBeatitude < 0 ) + { + messagePlayer(clientnum, language[2524]); // "You have no remaining items for the scroll's curse..." + } } // EnchantArmorGUI_ProcessRandom() /* ItemModifyingGUI.cpp @@ -3207,228 +3207,228 @@ void ItemModifyingGUI::EnchantArmorGUI_ProcessRandom(const Uint8 numItems) */ void ItemModifyingGUI::EnchantArmorGUI_RebuildInventory() { - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - Uint8 iEnchantArmorGUIInventoryIndex = 0; - - if ( playerInventoryList == nullptr ) - { - messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); - printlog("ERROR: EnchantArmorGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); - return; - } - - // Count the number of Items in the Repair GUI Inventory - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - ItemArmorType itemArmorType = getItemArmorType(item->type); - - // Skip all Items that aren't Armor - if ( itemArmorType == ItemArmorType::NOT_ARMOR ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items - { - ++iEnchantArmorGUIInventoryIndex; - } - break; - case 0: - if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts - { - // +0 can enchant Shields, Breastpiece, Masks, and Helms - if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) - { - continue; - } - - // +0 cannot enchant Artifacts - if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) - { - continue; - } - - ++iEnchantArmorGUIInventoryIndex; - } - break; - case 1: - if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts - { - // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves - if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) - { - continue; - } - - // +1 cannot enchant Artifacts - if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) - { - continue; - } - - ++iEnchantArmorGUIInventoryIndex; - } - break; - case 2: - if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor - { - // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks - ++iEnchantArmorGUIInventoryIndex; - } - break; - default: printlog("ERROR: EnchantArmorGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - } - - itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iEnchantArmorGUIInventoryIndex - 4)); - - // Reset the current Inventory - for ( iEnchantArmorGUIInventoryIndex = 0; iEnchantArmorGUIInventoryIndex < 4; ++iEnchantArmorGUIInventoryIndex ) - { - itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex] = nullptr; - } - - iEnchantArmorGUIInventoryIndex = 0; - - // Assign the visible Items to the GUI slots - bool bBreakFromLoop = false; - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - Item* item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - ItemArmorType itemArmorType = getItemArmorType(item->type); - - // Skip all Items that aren't Armor - if ( itemArmorType == ItemArmorType::NOT_ARMOR ) - { - continue; - } - - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case -2: - // Intentional fall-through - case -1: - if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items - { - ++iEnchantArmorGUIInventoryIndex; - - if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 0: - if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts - { - // +0 can enchant Shields, Breastpiece, Masks, and Helms - if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) - { - continue; - } - - if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) - { - continue; - } - - ++iEnchantArmorGUIInventoryIndex; - - if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 1: - if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts - { - // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves - if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) - { - continue; - } - - if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) - { - continue; - } - - ++iEnchantArmorGUIInventoryIndex; - - if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 2: - if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor - { - // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks - ++iEnchantArmorGUIInventoryIndex; - - if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; - - if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: EnchantArmorGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + Uint8 iEnchantArmorGUIInventoryIndex = 0; + + if ( playerInventoryList == nullptr ) + { + messagePlayer(0, "Warning: stats[%d]->inventory is not a valid list. This should not happen.", clientnum); + printlog("ERROR: EnchantArmorGUI_RebuildInventory() - stats[%d]->inventory is not a valid list.", clientnum); + return; + } + + // Count the number of Items in the Repair GUI Inventory + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantArmorGUIInventoryIndex; + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + // +0 can enchant Shields, Breastpiece, Masks, and Helms + if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + // +0 cannot enchant Artifacts + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves + if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + // +1 cannot enchant Artifacts + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor + { + // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks + ++iEnchantArmorGUIInventoryIndex; + } + break; + default: printlog("ERROR: EnchantArmorGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + } + + itemModifyingGUI_InventoryScrollOffset = std::max(0, std::min(static_cast(itemModifyingGUI_InventoryScrollOffset), iEnchantArmorGUIInventoryIndex - 4)); + + // Reset the current Inventory + for ( iEnchantArmorGUIInventoryIndex = 0; iEnchantArmorGUIInventoryIndex < 4; ++iEnchantArmorGUIInventoryIndex ) + { + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex] = nullptr; + } + + iEnchantArmorGUIInventoryIndex = 0; + + // Assign the visible Items to the GUI slots + bool bBreakFromLoop = false; + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + Item* item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case -2: + // Intentional fall-through + case -1: + if ( item->beatitude > 0 ) // Skip over all Cursed and Unenchanted Items + { + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + // +0 can enchant Shields, Breastpiece, Masks, and Helms + if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves + if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor + { + // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks + ++iEnchantArmorGUIInventoryIndex; + + if ( iEnchantArmorGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + itemModifyingGUI_Inventory[iEnchantArmorGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1] = item; + + if ( iEnchantArmorGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: EnchantArmorGUI_RebuildInventory() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } } // EnchantArmorGUI_RebuildInventory() /* ItemModifyingGUI.cpp @@ -3436,190 +3436,190 @@ void ItemModifyingGUI::EnchantArmorGUI_RebuildInventory() */ void ItemModifyingGUI::EnchantArmorGUI_HandleItemImages() { - bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) - Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item - Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other - - Item* item = nullptr; // The given Item being drawn from the GUI Inventory - SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory - - // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() - list_t* playerInventoryList = &stats[clientnum]->inventory; - - for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) - { - if ( iInventoryNode->element != nullptr ) - { - item = static_cast(iInventoryNode->element); - - if ( item == nullptr ) - { - continue; - } - - ItemArmorType itemArmorType = getItemArmorType(item->type); - - // Skip all Items that aren't Armor - if ( itemArmorType == ItemArmorType::NOT_ARMOR ) - { - continue; - } - - // Cursed Scrolls don't need to be shown, as they wont have a GUI - switch ( itemModifyingGUI_ScrollBeatitude ) - { - case 0: - if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts - { - // +0 can enchant Shields, Breastpiece, Masks, and Helms - if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) - { - continue; - } - - if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) - { - continue; - } - - iEnchantWeaponGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iEnchantWeaponGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 1: - if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts - { - // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves - if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) - { - continue; - } - - if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) - { - continue; - } - - iEnchantWeaponGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iEnchantWeaponGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - case 2: - if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor - { - // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks - iEnchantWeaponGUIInventoryIndex++; - - // If the Item is not visible (within 0 - 3 in Inventory), skip over it - if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) - { - continue; - } - - // The name and description of the Item in the GUI Inventory - char itemDescription[64] = {0}; - strncpy(itemDescription, item->description(), 46); - - // Check to make sure the text doesn't go out of bounds - if ( strlen(itemDescription) == 46 ) - { - strcat(itemDescription, " ..."); - } - - // Print the name and description of the Item - ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); - - // Draw the Image of the Item - itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; - itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); - itemImageRect.w = 16; - itemImageRect.h = 16; - drawImageScaled(itemSprite(item), nullptr, &itemImageRect); - - iEnchantWeaponGUIInventoryItemOffset += 18; - - // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing - if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) - { - bBreakFromLoop = true; - } - } - break; - default: printlog("ERROR: EnchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; - } - - if ( bBreakFromLoop == true ) - { - break; - } - } - } + bool bBreakFromLoop = false; // True if evaluation of drawing Images has ended (all viable Images have been processed) + Uint8 iEnchantWeaponGUIInventoryIndex = 0; // The position in the GUI Inventory array of the given Item + Sint32 iEnchantWeaponGUIInventoryItemOffset = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 22; // The amount that each Item is offset vertically from each other + + Item* item = nullptr; // The given Item being drawn from the GUI Inventory + SDL_Rect itemImageRect; // The position of the Image of the Item in the GUI Inventory + + // Grab the Player's Inventory again, as it may have been modified by ItemModifyingGUI_Process() + list_t* playerInventoryList = &stats[clientnum]->inventory; + + for ( node_t* iInventoryNode = playerInventoryList->first; iInventoryNode != nullptr; iInventoryNode = iInventoryNode->next ) + { + if ( iInventoryNode->element != nullptr ) + { + item = static_cast(iInventoryNode->element); + + if ( item == nullptr ) + { + continue; + } + + ItemArmorType itemArmorType = getItemArmorType(item->type); + + // Skip all Items that aren't Armor + if ( itemArmorType == ItemArmorType::NOT_ARMOR ) + { + continue; + } + + // Cursed Scrolls don't need to be shown, as they wont have a GUI + switch ( itemModifyingGUI_ScrollBeatitude ) + { + case 0: + if ( item->beatitude >= 0 && item->beatitude < 2 ) // Skip over all Cursed Items and Items +2 and greater. Skip Artifacts + { + // +0 can enchant Shields, Breastpiece, Masks, and Helms + if ( itemArmorType == ItemArmorType::BOOTS || itemArmorType == ItemArmorType::GLOVES || itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 1: + if ( item->beatitude >= 0 && item->beatitude < 3 ) // Skip over all Cursed Items and Items +3 and greater. Skip Artifacts + { + // +1 can enchant Shields, Breastpiece, Masks, Helms, Boots, and Gloves + if ( itemArmorType == ItemArmorType::RING || itemArmorType == ItemArmorType::AMULET || itemArmorType == ItemArmorType::CLOAK ) + { + continue; + } + + if ( item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES ) + { + continue; + } + + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + case 2: + if ( (item->beatitude >= 0 && item->beatitude < 5) || (item->beatitude >= 5 && (item->type == ARTIFACT_BREASTPIECE || item->type == ARTIFACT_HELM || item->type == ARTIFACT_BOOTS || item->type == ARTIFACT_CLOAK || item->type == ARTIFACT_GLOVES)) ) // Skip over all Cursed Items and Items +5 and greater, unless it's an Artifact Armor + { + // +2 can enchant Shields, Breastpiece, Masks, Helms, Boots, Gloves, Rings, Amulets, and Cloaks + iEnchantWeaponGUIInventoryIndex++; + + // If the Item is not visible (within 0 - 3 in Inventory), skip over it + if ( iEnchantWeaponGUIInventoryIndex <= itemModifyingGUI_InventoryScrollOffset ) + { + continue; + } + + // The name and description of the Item in the GUI Inventory + char itemDescription[64] = {0}; + strncpy(itemDescription, item->description(), 46); + + // Check to make sure the text doesn't go out of bounds + if ( strlen(itemDescription) == 46 ) + { + strcat(itemDescription, " ..."); + } + + // Print the name and description of the Item + ttfPrintText(ttf8, (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 36, iEnchantWeaponGUIInventoryItemOffset, itemDescription); + + // Draw the Image of the Item + itemImageRect.x = (((xres / 2) - (itemModifyingGUI_IMG->w / 2)) + itemModifyingGUI_OffsetX) + 16; + itemImageRect.y = (((yres / 2) - (itemModifyingGUI_IMG->h / 2)) + itemModifyingGUI_OffsetY) + 17 + 18 * (iEnchantWeaponGUIInventoryIndex - itemModifyingGUI_InventoryScrollOffset - 1); + itemImageRect.w = 16; + itemImageRect.h = 16; + drawImageScaled(itemSprite(item), nullptr, &itemImageRect); + + iEnchantWeaponGUIInventoryItemOffset += 18; + + // If the Item's index is out of bounds (above the amount of Items in the Inventory), stop drawing + if ( iEnchantWeaponGUIInventoryIndex > 3 + itemModifyingGUI_InventoryScrollOffset ) + { + bBreakFromLoop = true; + } + } + break; + default: printlog("ERROR: EnchantWeaponGUI_HandleItemImages() - itemModifyingGUI_ScrollBeatitude (%d) out of bounds", itemModifyingGUI_ScrollBeatitude); return; + } + + if ( bBreakFromLoop == true ) + { + break; + } + } + } } // EnchantArmorGUI_HandleItemImages() /* ItemModifyingGUI.cpp @@ -3629,69 +3629,69 @@ void ItemModifyingGUI::EnchantArmorGUI_HandleItemImages() */ void ItemModifyingGUI::EnchantArmorGUI_UpdateServer(Item* const selectedItem) { - // Convert the Item type to an int for the packet - Uint8 itemType = 9; - if ( selectedItem == stats[clientnum]->helmet ) - { - itemType = 0; - } - else if ( selectedItem == stats[clientnum]->breastplate ) - { - itemType = 1; - } - else if ( selectedItem == stats[clientnum]->gloves ) - { - itemType = 2; - } - else if ( selectedItem == stats[clientnum]->shoes ) - { - itemType = 3; - } - else if ( selectedItem == stats[clientnum]->shield ) - { - itemType = 4; - } - else if ( selectedItem == stats[clientnum]->cloak ) - { - itemType = 5; - } - else if ( selectedItem == stats[clientnum]->amulet ) - { - itemType = 6; - } - else if ( selectedItem == stats[clientnum]->ring ) - { - itemType = 7; - } - else if ( selectedItem == stats[clientnum]->mask ) - { - itemType = 8; - } - - // If none of the above is true, then this shouldn't have happened in the first place - if ( itemType == 9 ) - { - printlog("ERROR: EnchantArmorGUI_UpdateServer() - itemType is out of bounds."); - return; - } - - Uint8 isScrollCursed = 0; - if ( itemModifyingGUI_ScrollBeatitude < 0 ) - { - isScrollCursed = 1; - } - - // data[4] = The type of Armor as a Uint8 - // data[5] = 0 if the Scroll is Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Enchanted or Disenchanted - // data[6] = The Player that is sending the message - strcpy((char*)net_packet->data, "CENA"); - net_packet->data[4] = itemType; - net_packet->data[5] = isScrollCursed; - net_packet->data[6] = clientnum; - net_packet->address.host = net_server.host; - net_packet->address.port = net_server.port; - net_packet->len = 7; - sendPacketSafe(net_sock, -1, net_packet, 0); + // Convert the Item type to an int for the packet + Uint8 itemType = 9; + if ( selectedItem == stats[clientnum]->helmet ) + { + itemType = 0; + } + else if ( selectedItem == stats[clientnum]->breastplate ) + { + itemType = 1; + } + else if ( selectedItem == stats[clientnum]->gloves ) + { + itemType = 2; + } + else if ( selectedItem == stats[clientnum]->shoes ) + { + itemType = 3; + } + else if ( selectedItem == stats[clientnum]->shield ) + { + itemType = 4; + } + else if ( selectedItem == stats[clientnum]->cloak ) + { + itemType = 5; + } + else if ( selectedItem == stats[clientnum]->amulet ) + { + itemType = 6; + } + else if ( selectedItem == stats[clientnum]->ring ) + { + itemType = 7; + } + else if ( selectedItem == stats[clientnum]->mask ) + { + itemType = 8; + } + + // If none of the above is true, then this shouldn't have happened in the first place + if ( itemType == 9 ) + { + printlog("ERROR: EnchantArmorGUI_UpdateServer() - itemType is out of bounds."); + return; + } + + Uint8 isScrollCursed = 0; + if ( itemModifyingGUI_ScrollBeatitude < 0 ) + { + isScrollCursed = 1; + } + + // data[4] = The type of Armor as a Uint8 + // data[5] = 0 if the Scroll is Uncursed, 1 if the Scroll is Cursed. Determines if the Item is Enchanted or Disenchanted + // data[6] = The Player that is sending the message + strcpy((char*)net_packet->data, "CENA"); + net_packet->data[4] = itemType; + net_packet->data[5] = isScrollCursed; + net_packet->data[6] = clientnum; + net_packet->address.host = net_server.host; + net_packet->address.port = net_server.port; + net_packet->len = 7; + sendPacketSafe(net_sock, -1, net_packet, 0); } // EnchantArmorGUI_UpdateServer() } // namespace GUI diff --git a/src/interface/ItemModifyingGUI.hpp b/src/interface/ItemModifyingGUI.hpp index f023c52d2..65e8ca735 100644 --- a/src/interface/ItemModifyingGUI.hpp +++ b/src/interface/ItemModifyingGUI.hpp @@ -21,276 +21,276 @@ namespace GUI class ItemModifyingGUI { public: - ItemModifyingGUI(); - ~ItemModifyingGUI(); + ItemModifyingGUI(); + ~ItemModifyingGUI(); - /* ItemModifyingGUI.cpp - * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor - * @param scrollUsed - A pointer to the Item being used to open the GUI. The Item will be deleted if processing completes successfully. Use nullptr if a Spell is used to open the GUI - * Initializes the GUI, sets 'shootmode' to false, and 'gui_mode' to 'GUI_MODE_INVENTORY'. The GUI Inventory will be built using 'buildItemModifyingGUIInventory()' - * In the case of a Spell, itemModifyingGUI_ScrollBeatitude will be 0, as Spells do not give any extra or negative effects - * If a ItemModifyingGUI is already opened, it will be closed before opening the new one - * If a Unidentified Scroll is used, it will be Identified here and message the Player accordingly - */ - void OpenGUI(const Uint8 GUIType, Item* const scrollUsed); - /* ItemModifyingGUI.cpp - * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls - * Handles the GUI Inventory slot bounds and Mouse input to call ItemModifyingGUI_Process() - */ - void UpdateGUI(); - /* ItemModifyingGUI.cpp - * Resets all member variables back to their base states - */ - void CloseGUI(); - /* ItemModifyingGUI.cpp - * @param direction - Will either be -1 for Up or 1 for Down. The direction in which the User wants to move the cursor - * Called by GameController::handleItemModifyingGUIMovement(). Evaluates the requested movement, updating 'itemModifyingGUI_InventorySelectedSlot' as needed - */ - void Gamepad_MoveCursor(Sint8 direction); - /* ItemModifyingGUI.cpp - * @returns 'bIsActive' - */ - bool IsGUIOpen() const; - /* ItemModifyingGUI.cpp - * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor - * @returns true - If the Player's Inventory has valid Items for processing - * @returns false - If the Player's Inventory has no valid Items for processing - * The main usage of this function is to prevent a Spell from being cast needlessly - * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via CloseGUI() - */ - bool AreThereValidItems(const Uint8 GUIType); - /* ItemModifyingGUI.cpp - * @returns true - If 'itemModifyingGUI_InventorySelectedSlot' is < 0 - * @returns false - If 'itemModifyingGUI_InventorySelectedSlot' is 0 or greater - * Returns whether or not the mouse is currently hovering over a GUI Inventory Slot - */ - bool IsSelectedSlotInvalid() const; - /* ItemModifyingGUI.cpp - * @returns true - If the Mouse is currently within the bounds of the GUI - * @returns false - If the Mouse is not within the bounds of the GUI - * Returns whether or not the Mouse is currently within the bounds of the ItemModifyingGUI - */ - bool IsMouseWithinGUIBounds() const; - /* ItemModifyingGUI.cpp - * Called by freeInterfaceResources(). Frees 'itemModifyingGUI_IMG' using SDL_FreeSurface() - */ - void FreeImage(); + /* ItemModifyingGUI.cpp + * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + * @param scrollUsed - A pointer to the Item being used to open the GUI. The Item will be deleted if processing completes successfully. Use nullptr if a Spell is used to open the GUI + * Initializes the GUI, sets 'shootmode' to false, and 'gui_mode' to 'GUI_MODE_INVENTORY'. The GUI Inventory will be built using 'buildItemModifyingGUIInventory()' + * In the case of a Spell, itemModifyingGUI_ScrollBeatitude will be 0, as Spells do not give any extra or negative effects + * If a ItemModifyingGUI is already opened, it will be closed before opening the new one + * If a Unidentified Scroll is used, it will be Identified here and message the Player accordingly + */ + void OpenGUI(const Uint8 GUIType, Item* const scrollUsed); + /* ItemModifyingGUI.cpp + * Handles the Drawing of the GUI, along with setting up and processing the Mouse input collision bounds through their various function calls + * Handles the GUI Inventory slot bounds and Mouse input to call ItemModifyingGUI_Process() + */ + void UpdateGUI(); + /* ItemModifyingGUI.cpp + * Resets all member variables back to their base states + */ + void CloseGUI(); + /* ItemModifyingGUI.cpp + * @param direction - Will either be -1 for Up or 1 for Down. The direction in which the User wants to move the cursor + * Called by GameController::handleItemModifyingGUIMovement(). Evaluates the requested movement, updating 'itemModifyingGUI_InventorySelectedSlot' as needed + */ + void Gamepad_MoveCursor(Sint8 direction); + /* ItemModifyingGUI.cpp + * @returns 'bIsActive' + */ + bool IsGUIOpen() const; + /* ItemModifyingGUI.cpp + * @param GUIType - The type of GUI to be opened: 0,1,2,3,4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + * @returns true - If the Player's Inventory has valid Items for processing + * @returns false - If the Player's Inventory has no valid Items for processing + * The main usage of this function is to prevent a Spell from being cast needlessly + * Sets 'itemModifyingGUI_Type' = @GUIType. 'itemModifyingGUI_Type' is set back to default value before returning via CloseGUI() + */ + bool AreThereValidItems(const Uint8 GUIType); + /* ItemModifyingGUI.cpp + * @returns true - If 'itemModifyingGUI_InventorySelectedSlot' is < 0 + * @returns false - If 'itemModifyingGUI_InventorySelectedSlot' is 0 or greater + * Returns whether or not the mouse is currently hovering over a GUI Inventory Slot + */ + bool IsSelectedSlotInvalid() const; + /* ItemModifyingGUI.cpp + * @returns true - If the Mouse is currently within the bounds of the GUI + * @returns false - If the Mouse is not within the bounds of the GUI + * Returns whether or not the Mouse is currently within the bounds of the ItemModifyingGUI + */ + bool IsMouseWithinGUIBounds() const; + /* ItemModifyingGUI.cpp + * Called by freeInterfaceResources(). Frees 'itemModifyingGUI_IMG' using SDL_FreeSurface() + */ + void FreeImage(); private: - // ItemModifying GUI - static const Uint8 NUM_ITEM_MODIFYING_GUI_ITEMS = 4; // The maximum number of Items that can be displayed in the window + // ItemModifying GUI + static const Uint8 NUM_ITEM_MODIFYING_GUI_ITEMS = 4; // The maximum number of Items that can be displayed in the window - bool bIsActive; // Flag for whether or not the ItemModifyingGUI is currently displayed - bool bIsCursed; // Flag for whether or not the Scroll used is Cursed. If it is, bypasses the GUI and skips to processing - bool bIsItemModifyingGUI_Dragging; // Flag for whether or not the GUI Window is being dragged around the Screen - Sint16 itemModifyingGUI_ScrollBeatitude; // The Beatitude value of the Scroll being used - Uint8 itemModifyingGUI_Type; // Which type of GUI is being displayed? 0, 1, 2, 3, 4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor - Uint8 itemModifyingGUI_InventoryScrollOffset; // The amount Items existing past the limit of visible Items #TODOR: I actually am not 100% certain what this is - Sint8 itemModifyingGUI_InventorySelectedSlot; // The GUI Inventory Slot that has been selected by the Player for processing - Sint32 itemModifyingGUI_OffsetX; // The GUI Window's X offset, to allow the Window to be moved around the screen. Offset is remembered for future use - Sint32 itemModifyingGUI_OffsetY; // The GUI Window's Y offset, to allow the Window to be moved around the screen. Offset is remembered for future use + bool bIsActive; // Flag for whether or not the ItemModifyingGUI is currently displayed + bool bIsCursed; // Flag for whether or not the Scroll used is Cursed. If it is, bypasses the GUI and skips to processing + bool bIsItemModifyingGUI_Dragging; // Flag for whether or not the GUI Window is being dragged around the Screen + Sint16 itemModifyingGUI_ScrollBeatitude; // The Beatitude value of the Scroll being used + Uint8 itemModifyingGUI_Type; // Which type of GUI is being displayed? 0, 1, 2, 3, 4 - Identify, Remove Curse, Repair, Enchant Weapon, Enchant Armor + Uint8 itemModifyingGUI_InventoryScrollOffset; // The amount Items existing past the limit of visible Items #TODOR: I actually am not 100% certain what this is + Sint8 itemModifyingGUI_InventorySelectedSlot; // The GUI Inventory Slot that has been selected by the Player for processing + Sint32 itemModifyingGUI_OffsetX; // The GUI Window's X offset, to allow the Window to be moved around the screen. Offset is remembered for future use + Sint32 itemModifyingGUI_OffsetY; // The GUI Window's Y offset, to allow the Window to be moved around the screen. Offset is remembered for future use - SDL_Surface* itemModifyingGUI_IMG = nullptr; // The background image for Identify, Remove Curse, and Repair GUIs - Item* itemModifyingGUI_Inventory[NUM_ITEM_MODIFYING_GUI_ITEMS] = {nullptr}; // The GUI Inventory which holds all of the Player's Inventory Items that match the given GUIType - Item* itemModifyingGUI_ScrollUsed = nullptr; // A pointer to the Item of the Scroll being used to open the GUI. If the Scroll finishes it's processing, the Item will be deleted + SDL_Surface* itemModifyingGUI_IMG = nullptr; // The background image for Identify, Remove Curse, and Repair GUIs + Item* itemModifyingGUI_Inventory[NUM_ITEM_MODIFYING_GUI_ITEMS] = {nullptr}; // The GUI Inventory which holds all of the Player's Inventory Items that match the given GUIType + Item* itemModifyingGUI_ScrollUsed = nullptr; // A pointer to the Item of the Scroll being used to open the GUI. If the Scroll finishes it's processing, the Item will be deleted - /* ItemModifyingGUI.cpp - * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] - * @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] - * @returns The Item* from itemModifyingGUI_Inventory[slot] - * @returns nullptr if slot >= 4 (Out of bounds) - */ - Item* GetItemInfoFromGUI(Uint8 slot); + /* ItemModifyingGUI.cpp + * Used to get the reference to the Item in the given slot in itemModifyingGUI_Inventory[] + * @param int slot - The slot to be accessed in itemModifyingGUI_Inventory[] + * @returns The Item* from itemModifyingGUI_Inventory[slot] + * @returns nullptr if slot >= 4 (Out of bounds) + */ + Item* GetItemInfoFromGUI(Uint8 slot); - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Selects the correct function to process the Item according to 'itemModifyingGUI_Type' - */ - void ItemModifyingGUI_Process(Item* const selectedItem); - /* ItemModifyingGUI.cpp - * Used for Cursed Scrolls. Selects the correct function to randomly process the Item(s) according to 'itemModifyingGUI_Type' - */ - void ItemModifyingGUI_ProcessRandom(); - /* ItemModifyingGUI.cpp - * Selects the correct function to rebuild the GUI Inventory according to 'itemModifyingGUI_Type' - */ - void ItemModifyingGUI_RebuildInventory(); - /* ItemModifyingGUI.cpp - * Calls SDL_WarpMouseInWindow() to move the Mouse cursor to the currently selected GUI slot for controllers - */ - void WarpMouseToSelectedGUISlot(); + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Selects the correct function to process the Item according to 'itemModifyingGUI_Type' + */ + void ItemModifyingGUI_Process(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * Used for Cursed Scrolls. Selects the correct function to randomly process the Item(s) according to 'itemModifyingGUI_Type' + */ + void ItemModifyingGUI_ProcessRandom(); + /* ItemModifyingGUI.cpp + * Selects the correct function to rebuild the GUI Inventory according to 'itemModifyingGUI_Type' + */ + void ItemModifyingGUI_RebuildInventory(); + /* ItemModifyingGUI.cpp + * Calls SDL_WarpMouseInWindow() to move the Mouse cursor to the currently selected GUI slot for controllers + */ + void WarpMouseToSelectedGUISlot(); - // Display Update Handlers - /* ItemModifyingGUI.cpp - * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for each of the GUI's buttons - * The Top Bar of the GUI used for dragging is considered a button - */ - void ItemModifyingGUI_HandleButtons(); - /* ItemModifyingGUI.cpp - * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for Mouse scroll wheel input - */ - void ItemModifyingGUI_HandleMouseWheel(); - /* ItemModifyingGUI.cpp - * Handles the actual movement of the GUI Window by modifying 'itemModifyingGUI_OffsetX/Y' when 'bIsItemModifyingGUI_Dragging' == true - */ - void ItemModifyingGUI_HandleDraggingBar(); - /* ItemModifyingGUI.cpp - * @param GUIPosX - The GUI position in the center of the screen + itemModifyingGUI_OffsetX - * @param GUIPosY - The GUI position in the center of the screen + itemModifyingGUI_OffsetY - * Handles drawing the actual GUI button Images when they are being clicked. The unclicked versions are part of the original Image - */ - void ItemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY); - /* ItemModifyingGUI.cpp - * Rebuilds the GUI Inventory before selecting the correct function to render the Images for each Item according to 'itemModifyingGUI_Type' - */ - void ItemModifyingGUI_HandleItemImages(); + // Display Update Handlers + /* ItemModifyingGUI.cpp + * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for each of the GUI's buttons + * The Top Bar of the GUI used for dragging is considered a button + */ + void ItemModifyingGUI_HandleButtons(); + /* ItemModifyingGUI.cpp + * Handles setting up the collision bounds and checking for Mouse input on those collision bounds for Mouse scroll wheel input + */ + void ItemModifyingGUI_HandleMouseWheel(); + /* ItemModifyingGUI.cpp + * Handles the actual movement of the GUI Window by modifying 'itemModifyingGUI_OffsetX/Y' when 'bIsItemModifyingGUI_Dragging' == true + */ + void ItemModifyingGUI_HandleDraggingBar(); + /* ItemModifyingGUI.cpp + * @param GUIPosX - The GUI position in the center of the screen + itemModifyingGUI_OffsetX + * @param GUIPosY - The GUI position in the center of the screen + itemModifyingGUI_OffsetY + * Handles drawing the actual GUI button Images when they are being clicked. The unclicked versions are part of the original Image + */ + void ItemModifyingGUI_HandleButtonImages(const Sint32 GUIPosX, const Sint32 GUIPosY); + /* ItemModifyingGUI.cpp + * Rebuilds the GUI Inventory before selecting the correct function to render the Images for each Item according to 'itemModifyingGUI_Type' + */ + void ItemModifyingGUI_HandleItemImages(); - // Identify GUI - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then IdentifyGUI_ProcessRandom() will be called - * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI - */ - void IdentifyGUI_Process(Item* const selectedItem); - /* ItemModifyingGUI.cpp - * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 - * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' - * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used - */ - void IdentifyGUI_ProcessRandom(const Uint8 numItems); - /* ItemModifyingGUI.cpp - * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' - * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' - */ - void IdentifyGUI_RebuildInventory(); - /* ItemModifyingGUI.cpp - * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots - */ - void IdentifyGUI_HandleItemImages(); + // Identify GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Identifies the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > 0 then IdentifyGUI_ProcessRandom() will be called + * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ + void IdentifyGUI_Process(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will either Identify or Unidentify the random Items according to 'itemModifyingGUI_ScrollBeatitude' + * Messages the Player that their Item has been Identified or Unidentified because of the beatitude of the Scroll used + */ + void IdentifyGUI_ProcessRandom(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ + void IdentifyGUI_RebuildInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ + void IdentifyGUI_HandleItemImages(); - // Remove Curse GUI - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > or < 0 then RemoveCurseGUI_ProcessRandom() will be called - * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI - */ - void RemoveCurseGUI_Process(Item* const selectedItem); - /* ItemModifyingGUI.cpp - * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 - * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' - * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used - */ - void RemoveCurseGUI_ProcessRandom(const Uint8 numItems); - /* ItemModifyingGUI.cpp - * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' - * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' - */ - void RemoveCurseGUI_RebuildInventory(); - /* ItemModifyingGUI.cpp - * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots - */ - void RemoveCurseGUI_HandleItemImages(); - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn - * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them - */ - void RemoveCurseGUI_UpdateServer(Item* const selectedItem); + // Remove Curse GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Uncurses the selected Item based on 'itemModifyingGUI_ScrollBeatitude'. If 'itemModifyingGUI_ScrollBeatitude' is > or < 0 then RemoveCurseGUI_ProcessRandom() will be called + * Messages the Player that their Item has been Identified, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ + void RemoveCurseGUI_Process(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will either Uncurse or Curse the random Items according to 'itemModifyingGUI_ScrollBeatitude' + * Messages the Player that their Item has been Uncursed or Cursed because of the beatitude of the Scroll used + */ + void RemoveCurseGUI_ProcessRandom(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ + void RemoveCurseGUI_RebuildInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ + void RemoveCurseGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void RemoveCurseGUI_UpdateServer(Item* const selectedItem); - // Repair GUI - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Repairs the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' - * +0 Scrolls cannot repair Broken or Serviceable Items. +0 can repair Decrepit and Worn up to Serviceable - * +1 Scrolls cannot repair Serviceable Items. +1 can repair Broken, Decrepit, and Worn up to Serviceable - * +2 Scrolls can repair all Items up to Excellent - * Messages the Player that their Item has been Repaired, then if the GUI was opened with a Scroll, it is consumed before closing the GUI - */ - void RepairGUI_Process(Item* const selectedItem); - /* ItemModifyingGUI.cpp - * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 - * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to Broken - * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used - */ - void RepairGUI_ProcessRandom(const Uint8 numItems); - /* ItemModifyingGUI.cpp - * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' - * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' - */ - void RepairGUI_RebuildInventory(); - /* ItemModifyingGUI.cpp - * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots - */ - void RepairGUI_HandleItemImages(); - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn - * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them - */ - void RepairGUI_UpdateServer(Item* const selectedItem); + // Repair GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Repairs the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls cannot repair Broken or Serviceable Items. +0 can repair Decrepit and Worn up to Serviceable + * +1 Scrolls cannot repair Serviceable Items. +1 can repair Broken, Decrepit, and Worn up to Serviceable + * +2 Scrolls can repair all Items up to Excellent + * Messages the Player that their Item has been Repaired, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ + void RepairGUI_Process(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to Broken + * Messages the Player that their Item has been Broken because of the beatitude of the Scroll used + */ + void RepairGUI_ProcessRandom(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ + void RepairGUI_RebuildInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ + void RepairGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void RepairGUI_UpdateServer(Item* const selectedItem); - // Enchant Weapon GUI - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' - * +0 Scrolls can raise a +0 or +1 weapon up to +2. Cannot Enchant Artifacts - * +1 Scrolls can raise a +0, +1, or +2 weapon up to +3. Cannot Enchant Artifacts - * +2 Scrolls can raise a +0, +1, +2, +3, or +4 weapon up to +5. Raises any Artifact Weapon by one level - * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI - */ - void EnchantWeaponGUI_Process(Item* const selectedItem); - /* ItemModifyingGUI.cpp - * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 - * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 - * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used - */ - void EnchantWeaponGUI_ProcessRandom(const Uint8 numItems); - /* ItemModifyingGUI.cpp - * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' - * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' - */ - void EnchantWeaponGUI_RebuildInventory(); - /* ItemModifyingGUI.cpp - * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots - */ - void EnchantWeaponGUI_HandleItemImages(); - /* ItemModifyingGUI.cpp - * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn - * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them - */ - void EnchantWeaponGUI_UpdateServer(); + // Enchant Weapon GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls can raise a +0 or +1 weapon up to +2. Cannot Enchant Artifacts + * +1 Scrolls can raise a +0, +1, or +2 weapon up to +3. Cannot Enchant Artifacts + * +2 Scrolls can raise a +0, +1, +2, +3, or +4 weapon up to +5. Raises any Artifact Weapon by one level + * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ + void EnchantWeaponGUI_Process(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 + * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used + */ + void EnchantWeaponGUI_ProcessRandom(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ + void EnchantWeaponGUI_RebuildInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ + void EnchantWeaponGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void EnchantWeaponGUI_UpdateServer(); - // Enchant Armor GUI - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' - * +0 Scrolls can raise a +0 or +1 Shield, Breastpiece, or Helm up to +2. Cannot enchant Artifacts - * +1 Scrolls can raise a +0, +1, or +2 Shield, Breastpiece, Helm, Boots, or Gloves up to +3. Cannot enchant Artifacts - * +2 Scrolls can raise a +0, +1, +2, +3, or +4 Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks up to +5. Raises any Artifact Armor by one level - * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI - */ - void EnchantArmorGUI_Process(Item* const selectedItem); - /* ItemModifyingGUI.cpp - * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 - * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 - * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used - */ - void EnchantArmorGUI_ProcessRandom(const Uint8 numItems); - /* ItemModifyingGUI.cpp - * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' - * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' - */ - void EnchantArmorGUI_RebuildInventory(); - /* ItemModifyingGUI.cpp - * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots - */ - void EnchantArmorGUI_HandleItemImages(); - /* ItemModifyingGUI.cpp - * @param selectedItem - The Item that is being processed, selected from the GUI Inventory - * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn - * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them - */ - void EnchantArmorGUI_UpdateServer(Item* const selectedItem); + // Enchant Armor GUI + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Enchants the selected Item based on 'itemModifyingGUI_ScrollBeatitude' and 'itemModifyingGUI_ScrollBeatitude' + * +0 Scrolls can raise a +0 or +1 Shield, Breastpiece, or Helm up to +2. Cannot enchant Artifacts + * +1 Scrolls can raise a +0, +1, or +2 Shield, Breastpiece, Helm, Boots, or Gloves up to +3. Cannot enchant Artifacts + * +2 Scrolls can raise a +0, +1, +2, +3, or +4 Shield, Breastpiece, Helm, Boots, Gloves, Rings, or Cloaks up to +5. Raises any Artifact Armor by one level + * Messages the Player that their Item has been Enchanted, then if the GUI was opened with a Scroll, it is consumed before closing the GUI + */ + void EnchantArmorGUI_Process(Item* const selectedItem); + /* ItemModifyingGUI.cpp + * @param numItems - The number of random Items to be processed. Currently this number should never exceed 2, as the highest naturally spawning Scrolls are +-2 + * Processes a random amount of valid Items equal to 'numItems'. Processing will reduce the random Items to +0 + * Messages the Player that their Item has been Disenchanted because of the beatitude of the Scroll used + */ + void EnchantArmorGUI_ProcessRandom(const Uint8 numItems); + /* ItemModifyingGUI.cpp + * Builds the GUI's Inventory based off of 'itemModifyingGUI_Type' and 'itemModifyingGUI_ScrollBeatitude' + * Counts the number of Items to add to the GUI's Inventory, then assigns the visible ones to their position in 'itemModifyingGUI_Inventory[]' + */ + void EnchantArmorGUI_RebuildInventory(); + /* ItemModifyingGUI.cpp + * Draws the Sprite Image and description for the given Item in each of the visible GUI Inventory slots + */ + void EnchantArmorGUI_HandleItemImages(); + /* ItemModifyingGUI.cpp + * @param selectedItem - The Item that is being processed, selected from the GUI Inventory + * Updates the Server with the updated stats of the Client's equipment. Only needs to update the equipment that is being worn + * Equipment that is worn affects the stats of the Player, and is only updated in certain cases, this being one of them + */ + void EnchantArmorGUI_UpdateServer(Item* const selectedItem); }; // class ItemModifyingGUI } // namespace GUI \ No newline at end of file diff --git a/src/interface/clickdescription.cpp b/src/interface/clickdescription.cpp index 1f81baed7..11e234b7c 100644 --- a/src/interface/clickdescription.cpp +++ b/src/interface/clickdescription.cpp @@ -44,36 +44,36 @@ void clickDescription(int player, Entity* entity) { return; } - if ( openedChest[clientnum] ) - { - if ( omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h ) - { - return; //Click falls inside the chest inventory GUI. - } - } - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - if ( itemModifyingGUI->IsMouseWithinGUIBounds() == true ) - { - return; // Click falls within the itemModifyingGUI's bounds - } - } - if ( book_open ) - { - if ( mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h) ) - { - return; //Click falls inside the book GUI. - } - } - if (gui_mode == GUI_MODE_INVENTORY || gui_mode == GUI_MODE_SHOP) + if ( openedChest[clientnum] ) { - if ( gui_mode == GUI_MODE_INVENTORY ) - { - if ( mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height) ) - { - return; //Click falls inside the right sidebar. - } - } + if ( omousex > CHEST_INVENTORY_X && omousex < CHEST_INVENTORY_X + inventoryChest_bmp->w && omousey > CHEST_INVENTORY_Y && omousey < CHEST_INVENTORY_Y + inventoryChest_bmp->h ) + { + return; //Click falls inside the chest inventory GUI. + } + } + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + if ( itemModifyingGUI->IsMouseWithinGUIBounds() == true ) + { + return; // Click falls within the itemModifyingGUI's bounds + } + } + if ( book_open ) + { + if ( mouseInBounds(BOOK_GUI_X, BOOK_GUI_X + bookgui_img->w, BOOK_GUI_Y, BOOK_GUI_Y + bookgui_img->h) ) + { + return; //Click falls inside the book GUI. + } + } + if ( gui_mode == GUI_MODE_INVENTORY || gui_mode == GUI_MODE_SHOP ) + { + if ( gui_mode == GUI_MODE_INVENTORY ) + { + if ( mouseInBounds(RIGHTSIDEBAR_X, RIGHTSIDEBAR_X + rightsidebar_titlebar_img->w, RIGHTSIDEBAR_Y, RIGHTSIDEBAR_Y + rightsidebar_height) ) + { + return; //Click falls inside the right sidebar. + } + } //int x = std::max(character_bmp->w, xres/2-inventory_bmp->w/2); //if (mouseInBounds(x,x+inventory_bmp->w,0,inventory_bmp->h)) //return NULL; diff --git a/src/interface/drawstatus.cpp b/src/interface/drawstatus.cpp index 824b41f08..41c757074 100644 --- a/src/interface/drawstatus.cpp +++ b/src/interface/drawstatus.cpp @@ -579,10 +579,10 @@ void drawStatus() } } - // Shift + Right click on Item in Player Inventory will starting Appraising + // Shift + Right click on Item in Player Inventory will starting Appraising if ( keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT] ) { - appraisalGUI->OpenGUI(item, players[clientnum]->entity); + appraisalGUI->OpenGUI(item, players[clientnum]->entity); } else { diff --git a/src/interface/interface.cpp b/src/interface/interface.cpp index 9e4af0d2f..b2a3e16e6 100644 --- a/src/interface/interface.cpp +++ b/src/interface/interface.cpp @@ -386,7 +386,7 @@ void freeInterfaceResources() //for( c=0; cFreeImage(); + itemModifyingGUI->FreeImage(); /*if (rightsidebar_titlebar_img) SDL_FreeSurface(rightsidebar_titlebar_img); if (rightsidebar_slot_img) diff --git a/src/interface/playerinventory.cpp b/src/interface/playerinventory.cpp index a25c9d2a9..ffd2412db 100644 --- a/src/interface/playerinventory.cpp +++ b/src/interface/playerinventory.cpp @@ -350,15 +350,15 @@ void select_inventory_slot(int x, int y) warpMouseToSelectedShopSlot(); } } - else if ( itemModifyingGUI->IsGUIOpen() == true ) - { - warpInv = false; - y = INVENTORY_SIZEY - 1; + else if ( itemModifyingGUI->IsGUIOpen() == true ) + { + warpInv = false; + y = INVENTORY_SIZEY - 1; - // Warp Cursor into itemModifyingGUI's Inventory - Sint8 direction = 1; // itemModifyingGUI_InventorySelectedSlot will be -1. +1 will place it at 0 - itemModifyingGUI->Gamepad_MoveCursor(direction); - } + // Warp Cursor into itemModifyingGUI's Inventory + Sint8 direction = 1; // itemModifyingGUI_InventorySelectedSlot will be -1. +1 will place it at 0 + itemModifyingGUI->Gamepad_MoveCursor(direction); + } if ( warpInv ) //Wrap around to top. { @@ -589,29 +589,29 @@ void releaseItem(int x, int y) //TODO: This function uses toggleclick. Conflict } else { - // Let go of Item outside of the Inventory - if (selectedItem->count > 1) + // Let go of Item outside of the Inventory + if ( selectedItem->count > 1 ) { - // Item being held is a stack of Items, drop one at a time + // Item being held is a stack of Items, drop one at a time - // If the Item is currently being Appraised, stop the appraisal - if ( appraisalGUI->IsItemBeingAppraised(selectedItem) == true ) - { - appraisalGUI->CloseGUI(); - } + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(selectedItem) == true ) + { + appraisalGUI->CloseGUI(); + } dropItem(selectedItem, clientnum); toggleclick = true; } else { - // Item being held is a single Item, drop it + // Item being held is a single Item, drop it - // If the Item is currently being Appraised, stop the appraisal - if ( appraisalGUI->IsItemBeingAppraised(selectedItem) == true ) - { - appraisalGUI->CloseGUI(); - } + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(selectedItem) == true ) + { + appraisalGUI->CloseGUI(); + } dropItem(selectedItem, clientnum); selectedItem = NULL; @@ -707,7 +707,7 @@ void updatePlayerInventory() if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() && !itemMenuOpen && game_controller->handleInventoryMovement() ) { - if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() ) //This second check prevents the extra mouse warp. + if ( selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() ) // This second check prevents the extra mouse warp { if ( !hotbarHasFocus ) { @@ -734,15 +734,15 @@ void updatePlayerInventory() warpMouseToSelectedInventorySlot(); } } - else if ( itemModifyingGUI->IsSelectedSlotInvalid() == false && itemMenuOpen != true && game_controller->handleItemModifyingGUIMovement() ) - { - // If, after game_controller->handleItemModifyingGUIMovement() calls itemModifyingGUI->Gamepad_MoveCursor(), 'itemModifyingGUI_InventorySelectedSlot' is -1 - if ( itemModifyingGUI->IsSelectedSlotInvalid() == true ) - { - // Then warp the cursor to the Player's Inventory instead - warpMouseToSelectedInventorySlot(); - } - } + else if ( itemModifyingGUI->IsSelectedSlotInvalid() == false && itemMenuOpen != true && game_controller->handleItemModifyingGUIMovement() ) + { + // If, after game_controller->handleItemModifyingGUIMovement() calls itemModifyingGUI->Gamepad_MoveCursor(), 'itemModifyingGUI_InventorySelectedSlot' is -1 + if ( itemModifyingGUI->IsSelectedSlotInvalid() == true ) + { + // Then warp the cursor to the Player's Inventory instead + warpMouseToSelectedInventorySlot(); + } + } if ( *inputPressed(joyimpulses[INJOY_MENU_INVENTORY_TAB]) ) { @@ -1115,28 +1115,28 @@ void updatePlayerInventory() { *inputPressed(joyimpulses[INJOY_MENU_DROP_ITEM]) = 0; - // If the Item is currently being Appraised, stop the appraisal - if ( appraisalGUI->IsItemBeingAppraised(item) == true ) - { - appraisalGUI->CloseGUI(); - } + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } dropItem(item, clientnum); } // handle clicking - if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() )) && !selectedItem && !itemMenuOpen ) + if ( (mousestatus[SDL_BUTTON_LEFT] || (*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid())) && !selectedItem && !itemMenuOpen ) { - // If the User presses Shift + Left Click, drop the Item they have selected + // If the User presses Shift + Left Click, drop the Item they have selected if ( !(*inputPressed(joyimpulses[INJOY_MENU_LEFT_CLICK])) && (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) ) { - mousestatus[SDL_BUTTON_LEFT] = 0; + mousestatus[SDL_BUTTON_LEFT] = 0; - // If the Item is currently being Appraised, stop the appraisal - if ( appraisalGUI->IsItemBeingAppraised(item) == true ) - { - appraisalGUI->CloseGUI(); - } + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } dropItem(item, clientnum); // Drop the Item } @@ -1158,18 +1158,18 @@ void updatePlayerInventory() } } } - else if ( (mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid() )) && !itemMenuOpen && !selectedItem ) + else if ( (mousestatus[SDL_BUTTON_RIGHT] || (*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0 && selectedShopSlot < 0 && itemModifyingGUI->IsSelectedSlotInvalid())) && !itemMenuOpen && !selectedItem ) { - // If the User presses Shift + Right Click, start appraising the Item they have selected + // If the User presses Shift + Right Click, start appraising the Item they have selected if ( (keystatus[SDL_SCANCODE_LSHIFT] || keystatus[SDL_SCANCODE_RSHIFT]) && !(*inputPressed(joyimpulses[INJOY_MENU_USE]) && selectedChestSlot < 0) ) //TODO: selected shop slot, identify, remove curse? { - mousestatus[SDL_BUTTON_RIGHT] = 0; + mousestatus[SDL_BUTTON_RIGHT] = 0; - // Don't starting appraising if the Item is already being appraised - if ( appraisalGUI->IsItemBeingAppraised(item) == false ) - { - appraisalGUI->OpenGUI(item, players[clientnum]->entity); - } + // Don't starting appraising if the Item is already being appraised + if ( appraisalGUI->IsItemBeingAppraised(item) == false ) + { + appraisalGUI->OpenGUI(item, players[clientnum]->entity); + } } else { @@ -1519,26 +1519,26 @@ inline void executeItemMenuOption0(Item* item, bool is_potion_bad = false) inline void executeItemMenuOption1(Item* item, bool is_potion_bad = false) { - if (!item || itemCategory(item) == SPELL_CAT) + if ( !item || itemCategory(item) == SPELL_CAT ) { return; } - // If the Item is not a Potion, the second Tooltip Option is "Appraise" - if (itemCategory(item) != POTION) + // If the Item is not a Potion, the second Tooltip Option is "Appraise" + if ( itemCategory(item) != POTION ) { - // Don't starting appraising if the Item is already being appraised - if ( appraisalGUI->IsItemBeingAppraised(item) == false ) - { - appraisalGUI->OpenGUI(item, players[clientnum]->entity); - } + // Don't starting appraising if the Item is already being appraised + if ( appraisalGUI->IsItemBeingAppraised(item) == false ) + { + appraisalGUI->OpenGUI(item, players[clientnum]->entity); + } } else { - if (!is_potion_bad) + if ( !is_potion_bad ) { - //Option 1 = equip. - if (multiplayer == CLIENT) + // Option 1 = "Equip" + if ( multiplayer == CLIENT ) { strcpy((char*)net_packet->data, "EQUI"); SDLNet_Write32((Uint32)item->type, &net_packet->data[4]); @@ -1565,45 +1565,45 @@ inline void executeItemMenuOption1(Item* item, bool is_potion_bad = false) inline void executeItemMenuOption2(Item* item) { - if (!item || itemCategory(item) == SPELL_CAT) + if ( !item || itemCategory(item) == SPELL_CAT ) { return; } - // If the Item is not a Potion, the third Tooltip Option is "Drop" - if (itemCategory(item) != POTION) + // If the Item is not a Potion, the third Tooltip Option is "Drop" + if ( itemCategory(item) != POTION ) { - // If the Item is currently being Appraised, stop the appraisal - if ( appraisalGUI->IsItemBeingAppraised(item) == true ) - { - appraisalGUI->CloseGUI(); - } + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } dropItem(item, clientnum); } else { - // Don't starting appraising if the Item is already being appraised - if ( appraisalGUI->IsItemBeingAppraised(item) == false ) - { - appraisalGUI->OpenGUI(item, players[clientnum]->entity); - } + // Don't starting appraising if the Item is already being appraised + if ( appraisalGUI->IsItemBeingAppraised(item) == false ) + { + appraisalGUI->OpenGUI(item, players[clientnum]->entity); + } } } inline void executeItemMenuOption3(Item* item) { - // Only Potions have four Tooltip Options, the fourth being "Drop" - if (!item || itemCategory(item) != POTION) + // Only Potions have four Tooltip Options, the fourth being "Drop" + if ( !item || itemCategory(item) != POTION ) { return; } - // If the Item is currently being Appraised, stop the appraisal - if ( appraisalGUI->IsItemBeingAppraised(item) == true ) - { - appraisalGUI->CloseGUI(); - } + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } dropItem(item, clientnum); } diff --git a/src/items.cpp b/src/items.cpp index 98d558055..c59fa3975 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -551,48 +551,48 @@ Category itemCategory(const Item* item) */ ItemArmorType getItemArmorType(const ItemType& itemType) { - // TODOR: This is a fix until Entities get refactored and Items become a separate thing. Then it'll be easy to just tag it as armor or not - - if ( itemType == WOODEN_SHIELD || itemType == IRON_SHIELD || itemType == STEEL_SHIELD || itemType == STEEL_SHIELD_RESISTANCE || itemType == CRYSTAL_SHIELD || itemType == MIRROR_SHIELD ) - { // Shields - return ItemArmorType::SHIELD; - } - else if ( itemType == HEALER_DOUBLET || itemType == WIZARD_DOUBLET || itemType == VAMPIRE_DOUBLET || itemType == LEATHER_BREASTPIECE || itemType == IRON_BREASTPIECE || itemType == STEEL_BREASTPIECE || itemType == CRYSTAL_BREASTPIECE || itemType == ARTIFACT_BREASTPIECE ) - { // Breastpieces - return ItemArmorType::BREASTPIECE; - } - else if ( itemType == TOOL_GLASSES || itemType == TOOL_BLINDFOLD || itemType == TOOL_BLINDFOLD_FOCUS || itemType == TOOL_BLINDFOLD_TELEPATHY ) - { // Masks - return ItemArmorType::MASK; - } - else if ( itemType == HAT_PHRYGIAN || itemType == HAT_HOOD || itemType == HAT_WIZARD || itemType == HAT_JESTER || itemType == LEATHER_HELM || itemType == STEEL_HELM || itemType == CRYSTAL_HELM || itemType == ARTIFACT_HELM ) - { // Helms - return ItemArmorType::HELM; - } - else if ( itemType == LEATHER_BOOTS || itemType == LEATHER_BOOTS_SPEED || itemType == IRON_BOOTS || itemType == IRON_BOOTS_WATERWALKING || itemType == STEEL_BOOTS || itemType == STEEL_BOOTS_FEATHER || itemType == STEEL_BOOTS_LEVITATION || itemType == CRYSTAL_BOOTS || itemType == ARTIFACT_BOOTS ) - { // Boots - return ItemArmorType::BOOTS; - } - else if ( itemType == GLOVES || itemType == GLOVES_DEXTERITY || itemType == BRASS_KNUCKLES || itemType == BRACERS || itemType == BRACERS_CONSTITUTION || itemType == IRON_KNUCKLES || itemType == GAUNTLETS || itemType == GAUNTLETS_STRENGTH || itemType == SPIKED_GAUNTLETS || itemType == CRYSTAL_GLOVES || itemType == ARTIFACT_GLOVES ) - { // Gloves - return ItemArmorType::GLOVES; - } - else if ( itemType == RING_ADORNMENT || itemType == RING_SLOWDIGESTION || itemType == RING_PROTECTION || itemType == RING_WARNING || itemType == RING_STRENGTH || itemType == RING_CONSTITUTION || itemType == RING_INVISIBILITY || itemType == RING_MAGICRESISTANCE || itemType == RING_CONFLICT || itemType == RING_LEVITATION || itemType == RING_REGENERATION || itemType == RING_TELEPORTATION ) - { // Rings - return ItemArmorType::RING; - } - else if ( itemType == AMULET_SEXCHANGE || itemType == AMULET_LIFESAVING || itemType == AMULET_WATERBREATHING || itemType == AMULET_MAGICREFLECTION || itemType == AMULET_STRANGULATION || itemType == AMULET_WATERBREATHING ) - { // Amulets - return ItemArmorType::AMULET; - } - else if ( itemType == CLOAK || itemType == CLOAK_BLACK || itemType == CLOAK_MAGICREFLECTION || itemType == CLOAK_INVISIBILITY || itemType == CLOAK_PROTECTION || itemType == ARTIFACT_CLOAK ) - { // Cloaks - return ItemArmorType::CLOAK; - } - else - { - return ItemArmorType::NOT_ARMOR; - } + // TODOR: This is a fix until Entities get refactored and Items become a separate thing. Then it'll be easy to just tag it as armor or not + + if ( itemType == WOODEN_SHIELD || itemType == IRON_SHIELD || itemType == STEEL_SHIELD || itemType == STEEL_SHIELD_RESISTANCE || itemType == CRYSTAL_SHIELD || itemType == MIRROR_SHIELD ) + { // Shields + return ItemArmorType::SHIELD; + } + else if ( itemType == HEALER_DOUBLET || itemType == WIZARD_DOUBLET || itemType == VAMPIRE_DOUBLET || itemType == LEATHER_BREASTPIECE || itemType == IRON_BREASTPIECE || itemType == STEEL_BREASTPIECE || itemType == CRYSTAL_BREASTPIECE || itemType == ARTIFACT_BREASTPIECE ) + { // Breastpieces + return ItemArmorType::BREASTPIECE; + } + else if ( itemType == TOOL_GLASSES || itemType == TOOL_BLINDFOLD || itemType == TOOL_BLINDFOLD_FOCUS || itemType == TOOL_BLINDFOLD_TELEPATHY ) + { // Masks + return ItemArmorType::MASK; + } + else if ( itemType == HAT_PHRYGIAN || itemType == HAT_HOOD || itemType == HAT_WIZARD || itemType == HAT_JESTER || itemType == LEATHER_HELM || itemType == STEEL_HELM || itemType == CRYSTAL_HELM || itemType == ARTIFACT_HELM ) + { // Helms + return ItemArmorType::HELM; + } + else if ( itemType == LEATHER_BOOTS || itemType == LEATHER_BOOTS_SPEED || itemType == IRON_BOOTS || itemType == IRON_BOOTS_WATERWALKING || itemType == STEEL_BOOTS || itemType == STEEL_BOOTS_FEATHER || itemType == STEEL_BOOTS_LEVITATION || itemType == CRYSTAL_BOOTS || itemType == ARTIFACT_BOOTS ) + { // Boots + return ItemArmorType::BOOTS; + } + else if ( itemType == GLOVES || itemType == GLOVES_DEXTERITY || itemType == BRASS_KNUCKLES || itemType == BRACERS || itemType == BRACERS_CONSTITUTION || itemType == IRON_KNUCKLES || itemType == GAUNTLETS || itemType == GAUNTLETS_STRENGTH || itemType == SPIKED_GAUNTLETS || itemType == CRYSTAL_GLOVES || itemType == ARTIFACT_GLOVES ) + { // Gloves + return ItemArmorType::GLOVES; + } + else if ( itemType == RING_ADORNMENT || itemType == RING_SLOWDIGESTION || itemType == RING_PROTECTION || itemType == RING_WARNING || itemType == RING_STRENGTH || itemType == RING_CONSTITUTION || itemType == RING_INVISIBILITY || itemType == RING_MAGICRESISTANCE || itemType == RING_CONFLICT || itemType == RING_LEVITATION || itemType == RING_REGENERATION || itemType == RING_TELEPORTATION ) + { // Rings + return ItemArmorType::RING; + } + else if ( itemType == AMULET_SEXCHANGE || itemType == AMULET_LIFESAVING || itemType == AMULET_WATERBREATHING || itemType == AMULET_MAGICREFLECTION || itemType == AMULET_STRANGULATION || itemType == AMULET_WATERBREATHING ) + { // Amulets + return ItemArmorType::AMULET; + } + else if ( itemType == CLOAK || itemType == CLOAK_BLACK || itemType == CLOAK_MAGICREFLECTION || itemType == CLOAK_INVISIBILITY || itemType == CLOAK_PROTECTION || itemType == ARTIFACT_CLOAK ) + { // Cloaks + return ItemArmorType::CLOAK; + } + else + { + return ItemArmorType::NOT_ARMOR; + } } /*------------------------------------------------------------------------------- @@ -998,11 +998,11 @@ void consumeItem(Item* item) return; } - // If the Item is currently being Appraised, stop the appraisal - if ( appraisalGUI->IsItemBeingAppraised(item) == true ) - { - appraisalGUI->CloseGUI(); - } + // If the Item is currently being Appraised, stop the appraisal + if ( appraisalGUI->IsItemBeingAppraised(item) == true ) + { + appraisalGUI->CloseGUI(); + } item->count--; if ( item->count <= 0 ) @@ -1311,60 +1311,61 @@ void useItem(Item* item, int player) } } - // 9-15-2017 - Lutz GUI Refactor - This is a quick hack to make itemModifyingGUI's work, it will need to be replaced with a refactor of net code/useItem later - switch ( item->type ) - { - case SCROLL_IDENTIFY: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(0, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } - return; - case SCROLL_ENCHANTWEAPON: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(3, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } - return; - case SCROLL_ENCHANTARMOR: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(4, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } - return; - case SCROLL_REMOVECURSE: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(1, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } - return; - case SCROLL_REPAIR: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(2, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } - return; - } + // 9-15-2017 - Lutz GUI Refactor - This is a quick hack to make itemModifyingGUI's work, it will need to be replaced with a refactor of net code/useItem later + switch ( item->type ) + { + case SCROLL_IDENTIFY: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->OpenGUI(0, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_ENCHANTWEAPON: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->OpenGUI(3, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_ENCHANTARMOR: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->OpenGUI(4, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_REMOVECURSE: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->OpenGUI(1, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + case SCROLL_REPAIR: + if ( !players[player]->entity->isBlind() ) + { + itemModifyingGUI->OpenGUI(2, item); + } + else if ( player == clientnum ) + { + messagePlayer(player, language[775]); + } + return; + default: break; + } if ( multiplayer == CLIENT && !intro ) { @@ -1552,14 +1553,7 @@ void useItem(Item* item, int player) item_ScrollMail(item, player); break; case SCROLL_IDENTIFY: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(0, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } + // Replaced by hack up above break; case SCROLL_LIGHT: item_ScrollLight(item, player); @@ -1572,34 +1566,13 @@ void useItem(Item* item, int player) item_ScrollBlank(item, player); break; case SCROLL_ENCHANTWEAPON: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(3, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } + // Replaced by hack up above break; case SCROLL_ENCHANTARMOR: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(4, item); - } - else if(player == clientnum) - { - messagePlayer(player, language[775]); - } + // Replaced by hack up above break; case SCROLL_REMOVECURSE: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(1, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } + // Replaced by hack up above break; case SCROLL_FIRE: item_ScrollFire(item, player); @@ -1623,14 +1596,7 @@ void useItem(Item* item, int player) } break; case SCROLL_REPAIR: - if ( !players[player]->entity->isBlind() ) - { - itemModifyingGUI->OpenGUI(2, item); - } - else if ( player == clientnum ) - { - messagePlayer(player, language[775]); - } + // Replaced by hack up above break; case SCROLL_DESTROYARMOR: item_ScrollDestroyArmor(item, player); diff --git a/src/items.hpp b/src/items.hpp index 397dc1373..b6d48222a 100644 --- a/src/items.hpp +++ b/src/items.hpp @@ -258,16 +258,16 @@ typedef enum Category */ typedef enum class ItemArmorType { - NOT_ARMOR, - SHIELD, - BREASTPIECE, - MASK, - HELM, - BOOTS, - GLOVES, - RING, - AMULET, - CLOAK + NOT_ARMOR, + SHIELD, + BREASTPIECE, + MASK, + HELM, + BOOTS, + GLOVES, + RING, + AMULET, + CLOAK } ItemArmorType; typedef enum Status diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index ee4d793c7..3c27e7552 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -115,23 +115,23 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) return; } - // Check to prevent Mana loss if there are no valid Items to be processed by Identify Spell - if ( spell->ID == SPELL_IDENTIFY ) - { - if ( itemModifyingGUI->AreThereValidItems(0) != true ) - { - return; - } - } - - // Check to prevent Mana loss if there are no valid Items to be processed by Remove Curse Spell - if ( spell->ID == SPELL_REMOVECURSE ) - { - if ( itemModifyingGUI->AreThereValidItems(1) != true ) - { - return; - } - } + // Check to prevent Mana loss if there are no valid Items to be processed by Identify Spell + if ( spell->ID == SPELL_IDENTIFY ) + { + if ( itemModifyingGUI->AreThereValidItems(0) != true ) + { + return; + } + } + + // Check to prevent Mana loss if there are no valid Items to be processed by Remove Curse Spell + if ( spell->ID == SPELL_REMOVECURSE ) + { + if ( itemModifyingGUI->AreThereValidItems(1) != true ) + { + return; + } + } if ( spell->ID == SPELL_MAGICMISSILE && skillCapstoneUnlocked(player, PRO_SPELLCASTING) ) { @@ -523,21 +523,21 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool { caster->teleportRandom(); } - else if (!strcmp(element->name, spellElement_identify.name)) + else if ( !strcmp(element->name, spellElement_identify.name) ) { - // Find the Client that is casting the Spell + // Find the Client that is casting the Spell for ( Uint8 iClientPlayerIndex = 0; iClientPlayerIndex < numplayers; ++iClientPlayerIndex ) { if ( caster == players[iClientPlayerIndex]->entity ) { spawnMagicEffectParticles(caster->x, caster->y, caster->z, 171); - // If the Client is not the Host, send a packet to tell open the ItemModifyingGUI + // If the Client is not the Host, send a packet to tell open the ItemModifyingGUI if ( iClientPlayerIndex != 0 ) { // data[4] = The type of ItemModifyingGUI to open. 0 is Identify GUI strcpy((char*)net_packet->data, "CIMG"); - net_packet->data[4] = 0; + net_packet->data[4] = 0; net_packet->address.host = net_clients[iClientPlayerIndex - 1].host; net_packet->address.port = net_clients[iClientPlayerIndex - 1].port; net_packet->len = 5; @@ -546,28 +546,28 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool else { // Open ItemModifyingGUI as Identify GUI - itemModifyingGUI->OpenGUI(0, nullptr); + itemModifyingGUI->OpenGUI(0, nullptr); } } } - playSoundEntity(caster, 167, 128 ); + playSoundEntity(caster, 167, 128); } - else if (!strcmp(element->name, spellElement_removecurse.name)) + else if ( !strcmp(element->name, spellElement_removecurse.name) ) { - // Find the Client that is casting the Spell + // Find the Client that is casting the Spell for ( Uint8 iClientPlayerIndex = 0; iClientPlayerIndex < numplayers; ++iClientPlayerIndex ) { if ( caster == players[iClientPlayerIndex]->entity ) { spawnMagicEffectParticles(caster->x, caster->y, caster->z, 169); - // If the Client is not the Host, send a packet to tell open the ItemModifyingGUI + // If the Client is not the Host, send a packet to tell open the ItemModifyingGUI if ( iClientPlayerIndex != 0 ) { - // data[4] = The type of ItemModifyingGUI to open. 1 is Remove Curse GUI + // data[4] = The type of ItemModifyingGUI to open. 1 is Remove Curse GUI strcpy((char*)net_packet->data, "CIMG"); - net_packet->data[4] = 1; + net_packet->data[4] = 1; net_packet->address.host = net_clients[iClientPlayerIndex - 1].host; net_packet->address.port = net_clients[iClientPlayerIndex - 1].port; net_packet->len = 5; @@ -575,13 +575,13 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool } else { - // Open ItemModifyingGUI as Remove Curse GUI - itemModifyingGUI->OpenGUI(1, nullptr); + // Open ItemModifyingGUI as Remove Curse GUI + itemModifyingGUI->OpenGUI(1, nullptr); } } } - playSoundEntity(caster, 167, 128 ); + playSoundEntity(caster, 167, 128); } else if (!strcmp(element->name, spellElement_magicmapping.name)) { diff --git a/src/menu.cpp b/src/menu.cpp index cae964d01..4421a50ad 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -4187,8 +4187,8 @@ void handleMainMenu(bool mode) // reset game darkmap = false; - - appraisalGUI->CloseGUI(); // Close the Appraisal GUI + + appraisalGUI->CloseGUI(); // Close the Appraisal GUI multiplayer = 0; shootmode = true; diff --git a/src/net.cpp b/src/net.cpp index a93f064eb..a2fdc2204 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1234,67 +1234,67 @@ void clientHandlePacket() return; } - // Client Update Equipped Status - Called whenever the Client's equipped Item's ItemStatus has changed, except for Repair GUI - else if ( !strncmp((char*)net_packet->data, "ARMR", 4) ) - { - // data[4] = The type of Armor as a Uint8 - // data[5] = The updated ItemStatus of the Armor as a Uint8 - - switch ( net_packet->data[4] ) - { - case 0: - item = stats[clientnum]->helmet; - break; - case 1: - item = stats[clientnum]->breastplate; - break; - case 2: - item = stats[clientnum]->gloves; - break; - case 3: - item = stats[clientnum]->shoes; - break; - case 4: - item = stats[clientnum]->shield; - break; - case 5: - item = stats[clientnum]->weapon; - break; - case 6: - item = stats[clientnum]->cloak; - break; - case 7: - item = stats[clientnum]->amulet; - break; - case 8: - item = stats[clientnum]->ring; - break; - case 9: - item = stats[clientnum]->mask; - break; - default: - item = nullptr; - break; - } - - if ( item != nullptr ) - { - if ( item->count > 1 ) - { - newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientnum]->inventory); - item->count = 1; - } - - item->status = static_cast(net_packet->data[5]); - return; - } - else - { - printlog("ERROR: clientHandlePacket() (ARMR) - item is null."); - } - - return; - } // "ARMR" - Client Update Equipped Status + // Client Update Equipped Status - Called whenever the Client's equipped Item's ItemStatus has changed, except for Repair GUI + else if ( !strncmp((char*)net_packet->data, "ARMR", 4) ) + { + // data[4] = The type of Armor as a Uint8 + // data[5] = The updated ItemStatus of the Armor as a Uint8 + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientnum]->helmet; + break; + case 1: + item = stats[clientnum]->breastplate; + break; + case 2: + item = stats[clientnum]->gloves; + break; + case 3: + item = stats[clientnum]->shoes; + break; + case 4: + item = stats[clientnum]->shield; + break; + case 5: + item = stats[clientnum]->weapon; + break; + case 6: + item = stats[clientnum]->cloak; + break; + case 7: + item = stats[clientnum]->amulet; + break; + case 8: + item = stats[clientnum]->ring; + break; + case 9: + item = stats[clientnum]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientnum]->inventory); + item->count = 1; + } + + item->status = static_cast(net_packet->data[5]); + return; + } + else + { + printlog("ERROR: clientHandlePacket() (ARMR) - item is null."); + } + + return; + } // "ARMR" - Client Update Equipped Status // steal armor (destroy it) else if (!strncmp((char*)net_packet->data, "STLA", 4)) @@ -1530,12 +1530,12 @@ void clientHandlePacket() shopinventorycategory = 7; sellitem = NULL; shopitemscroll = 0; - - // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - itemModifyingGUI->CloseGUI(); - } + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + itemModifyingGUI->CloseGUI(); + } //Initialize shop gamepad code here. if ( shopinvitems[0] != nullptr ) @@ -2351,12 +2351,12 @@ void clientHandlePacket() if (entity2->getUID() == i) { openedChest[clientnum] = entity2; //Set the opened chest to this. - - // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - itemModifyingGUI->CloseGUI(); - } + + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + itemModifyingGUI->CloseGUI(); + } list_FreeAll(&chestInv); chestInv.first = nullptr; @@ -2596,14 +2596,14 @@ void clientHandlePacket() return; } - // Client open ItemModifyingGUI - Called by castSpell() on Server. Client is told to open GUI locally - else if ( !strncmp((char*)net_packet->data, "CIMG", 4) ) - { - // data[4] = The type of ItemModifyingGUI to open - // 0 is Identify GUI, 1 is Remove Curse GUI - itemModifyingGUI->OpenGUI(net_packet->data[4], nullptr); - return; - } // "CIMG" - Client Open ItemModifyingGUI + // Client open ItemModifyingGUI - Called by castSpell() on Server. Client is told to open GUI locally + else if ( !strncmp((char*)net_packet->data, "CIMG", 4) ) + { + // data[4] = The type of ItemModifyingGUI to open + // 0 is Identify GUI, 1 is Remove Curse GUI + itemModifyingGUI->OpenGUI(net_packet->data[4], nullptr); + return; + } // "CIMG" - Client Open ItemModifyingGUI // game restart if (!strncmp((char*)net_packet->data, "BARONY_GAME_START", 17)) @@ -3271,267 +3271,267 @@ void serverHandlePacket() return; } - // Client Remove Curse - Called by ItemModifyingGUI to update Server when Client removes Curse on equipped Item(s) - else if ( !strncmp((char*)net_packet->data, "CRCU", 4) ) - { - // data[4] = The type of Item as a Uint8 - // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Cursed or Uncursed - // data[6] = The Player that is sending the message - - Uint8 clientToUpdate = net_packet->data[6]; - - switch ( net_packet->data[4] ) - { - case 0: - item = stats[clientToUpdate]->helmet; - break; - case 1: - item = stats[clientToUpdate]->breastplate; - break; - case 2: - item = stats[clientToUpdate]->gloves; - break; - case 3: - item = stats[clientToUpdate]->shoes; - break; - case 4: - item = stats[clientToUpdate]->shield; - break; - case 5: - item = stats[clientToUpdate]->weapon; - break; - case 6: - item = stats[clientToUpdate]->cloak; - break; - case 7: - item = stats[clientToUpdate]->amulet; - break; - case 8: - item = stats[clientToUpdate]->ring; - break; - case 9: - item = stats[clientToUpdate]->mask; - break; - default: - item = nullptr; - break; - } - - if ( item != nullptr ) - { - if ( item->count > 1 ) - { - newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); - item->count = 1; - } - - bool bWasScrollCursed = false; - if ( net_packet->data[5] == 1 ) - { - bWasScrollCursed = true; - } - - if ( bWasScrollCursed == true ) - { - item->beatitude = -1; - return; - } - else - { - item->beatitude = 0; - return; - } - } - else - { - printlog("ERROR: clientHandlePacket() (CRCU) - item is null."); - } - - return; - } // "CRCU" - Client Remove Curse - - // Client Repair - Called by ItemModifyingGUI to update Server when Client Repairs an equipped Item - else if ( !strncmp((char*)net_packet->data, "CREP", 4) ) - { - // data[4] = The type of Item as a Uint8 - // data[5] = The updated ItemStatus of the Armor as a Uint8 - // data[6] = The Player that is sending the message - - Uint8 clientToUpdate = net_packet->data[6]; - - switch ( net_packet->data[4] ) - { - case 0: - item = stats[clientToUpdate]->helmet; - break; - case 1: - item = stats[clientToUpdate]->breastplate; - break; - case 2: - item = stats[clientToUpdate]->gloves; - break; - case 3: - item = stats[clientToUpdate]->shoes; - break; - case 4: - item = stats[clientToUpdate]->shield; - break; - case 5: - item = stats[clientToUpdate]->weapon; - break; - case 6: - item = stats[clientToUpdate]->cloak; - break; - case 7: - item = stats[clientToUpdate]->amulet; - break; - case 8: - item = stats[clientToUpdate]->ring; - break; - case 9: - item = stats[clientToUpdate]->mask; - break; - default: - item = nullptr; - break; - } - - if ( item != nullptr ) - { - if ( item->count > 1 ) - { - newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); - item->count = 1; - } - - item->status = static_cast(net_packet->data[5]); - return; - } - else - { - printlog("ERROR: clientHandlePacket() (CREP) - item is null."); - } - - return; - } // "CREP" - Client Repair - - // Client Enchant Weapon - Called by ItemModifyingGUI to update Server when Client Enchants equipped Weapon - else if ( !strncmp((char*)net_packet->data, "CENW", 4) ) - { - // data[4] = The Player that is sending the message - // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Disenchanted or Enchanted - - Uint8 clientToUpdate = net_packet->data[4]; - item = stats[clientToUpdate]->weapon; - - if ( item != nullptr ) - { - if ( item->count > 1 ) - { - newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); - item->count = 1; - } - - bool bWasScrollCursed = false; - if ( net_packet->data[5] == 1 ) - { - bWasScrollCursed = true; - } - - if ( bWasScrollCursed == true ) - { - item->beatitude = 0; - return; - } - else - { - item->beatitude++; - return; - } - } - else - { - printlog("ERROR: clientHandlePacket() (CENW) - item is null."); - } - - return; - } // "CENW" - Client Enchant Weapon - - // Client Enchant Armor - Called by ItemModifyingGUI to update Server when Client Enchants equipped Armor - else if ( !strncmp((char*)net_packet->data, "CENA", 4) ) - { - // data[4] = The type of Armor as a Uint8 - // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Disenchanted or Enchanted - // data[6] = The Player that is sending the message - - Uint8 clientToUpdate = net_packet->data[6]; - - switch ( net_packet->data[4] ) - { - case 0: - item = stats[clientToUpdate]->helmet; - break; - case 1: - item = stats[clientToUpdate]->breastplate; - break; - case 2: - item = stats[clientToUpdate]->gloves; - break; - case 3: - item = stats[clientToUpdate]->shoes; - break; - case 4: - item = stats[clientToUpdate]->shield; - break; - case 5: - item = stats[clientToUpdate]->cloak; - break; - case 6: - item = stats[clientToUpdate]->amulet; - break; - case 7: - item = stats[clientToUpdate]->ring; - break; - case 8: - item = stats[clientToUpdate]->mask; - break; - default: - item = nullptr; - break; - } - - if ( item != nullptr ) - { - if ( item->count > 1 ) - { - newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); - item->count = 1; - } - - bool bWasScrollCursed = false; - if ( net_packet->data[5] == 1 ) - { - bWasScrollCursed = true; - } - - if ( bWasScrollCursed == true ) - { - item->beatitude = 0; - return; - } - else - { - item->beatitude++; - return; - } - } - else - { - printlog("ERROR: clientHandlePacket() (CENA) - item is null."); - } - - return; - } // "CENA" - Client Enchant Armor + // Client Remove Curse - Called by ItemModifyingGUI to update Server when Client removes Curse on equipped Item(s) + else if ( !strncmp((char*)net_packet->data, "CRCU", 4) ) + { + // data[4] = The type of Item as a Uint8 + // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Cursed or Uncursed + // data[6] = The Player that is sending the message + + Uint8 clientToUpdate = net_packet->data[6]; + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientToUpdate]->helmet; + break; + case 1: + item = stats[clientToUpdate]->breastplate; + break; + case 2: + item = stats[clientToUpdate]->gloves; + break; + case 3: + item = stats[clientToUpdate]->shoes; + break; + case 4: + item = stats[clientToUpdate]->shield; + break; + case 5: + item = stats[clientToUpdate]->weapon; + break; + case 6: + item = stats[clientToUpdate]->cloak; + break; + case 7: + item = stats[clientToUpdate]->amulet; + break; + case 8: + item = stats[clientToUpdate]->ring; + break; + case 9: + item = stats[clientToUpdate]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + bool bWasScrollCursed = false; + if ( net_packet->data[5] == 1 ) + { + bWasScrollCursed = true; + } + + if ( bWasScrollCursed == true ) + { + item->beatitude = -1; + return; + } + else + { + item->beatitude = 0; + return; + } + } + else + { + printlog("ERROR: clientHandlePacket() (CRCU) - item is null."); + } + + return; + } // "CRCU" - Client Remove Curse + + // Client Repair - Called by ItemModifyingGUI to update Server when Client Repairs an equipped Item + else if ( !strncmp((char*)net_packet->data, "CREP", 4) ) + { + // data[4] = The type of Item as a Uint8 + // data[5] = The updated ItemStatus of the Armor as a Uint8 + // data[6] = The Player that is sending the message + + Uint8 clientToUpdate = net_packet->data[6]; + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientToUpdate]->helmet; + break; + case 1: + item = stats[clientToUpdate]->breastplate; + break; + case 2: + item = stats[clientToUpdate]->gloves; + break; + case 3: + item = stats[clientToUpdate]->shoes; + break; + case 4: + item = stats[clientToUpdate]->shield; + break; + case 5: + item = stats[clientToUpdate]->weapon; + break; + case 6: + item = stats[clientToUpdate]->cloak; + break; + case 7: + item = stats[clientToUpdate]->amulet; + break; + case 8: + item = stats[clientToUpdate]->ring; + break; + case 9: + item = stats[clientToUpdate]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + item->status = static_cast(net_packet->data[5]); + return; + } + else + { + printlog("ERROR: clientHandlePacket() (CREP) - item is null."); + } + + return; + } // "CREP" - Client Repair + + // Client Enchant Weapon - Called by ItemModifyingGUI to update Server when Client Enchants equipped Weapon + else if ( !strncmp((char*)net_packet->data, "CENW", 4) ) + { + // data[4] = The Player that is sending the message + // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Disenchanted or Enchanted + + Uint8 clientToUpdate = net_packet->data[4]; + item = stats[clientToUpdate]->weapon; + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + bool bWasScrollCursed = false; + if ( net_packet->data[5] == 1 ) + { + bWasScrollCursed = true; + } + + if ( bWasScrollCursed == true ) + { + item->beatitude = 0; + return; + } + else + { + item->beatitude++; + return; + } + } + else + { + printlog("ERROR: clientHandlePacket() (CENW) - item is null."); + } + + return; + } // "CENW" - Client Enchant Weapon + + // Client Enchant Armor - Called by ItemModifyingGUI to update Server when Client Enchants equipped Armor + else if ( !strncmp((char*)net_packet->data, "CENA", 4) ) + { + // data[4] = The type of Armor as a Uint8 + // data[5] = 0 if the Scroll was Cursed, 1 if the Scroll is Uncursed. Determines if the Item is Disenchanted or Enchanted + // data[6] = The Player that is sending the message + + Uint8 clientToUpdate = net_packet->data[6]; + + switch ( net_packet->data[4] ) + { + case 0: + item = stats[clientToUpdate]->helmet; + break; + case 1: + item = stats[clientToUpdate]->breastplate; + break; + case 2: + item = stats[clientToUpdate]->gloves; + break; + case 3: + item = stats[clientToUpdate]->shoes; + break; + case 4: + item = stats[clientToUpdate]->shield; + break; + case 5: + item = stats[clientToUpdate]->cloak; + break; + case 6: + item = stats[clientToUpdate]->amulet; + break; + case 7: + item = stats[clientToUpdate]->ring; + break; + case 8: + item = stats[clientToUpdate]->mask; + break; + default: + item = nullptr; + break; + } + + if ( item != nullptr ) + { + if ( item->count > 1 ) + { + newItem(item->type, item->status, item->beatitude, item->count - 1, item->appearance, item->identified, &stats[clientToUpdate]->inventory); + item->count = 1; + } + + bool bWasScrollCursed = false; + if ( net_packet->data[5] == 1 ) + { + bWasScrollCursed = true; + } + + if ( bWasScrollCursed == true ) + { + item->beatitude = 0; + return; + } + else + { + item->beatitude++; + return; + } + } + else + { + printlog("ERROR: clientHandlePacket() (CENA) - item is null."); + } + + return; + } // "CENA" - Client Enchant Armor } // serverHandlePacket() /*------------------------------------------------------------------------------- diff --git a/src/player.cpp b/src/player.cpp index 3166b4446..67689962a 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -674,39 +674,39 @@ bool GameController::handleShopMovement() */ bool GameController::handleItemModifyingGUIMovement() { - if ( itemMenuOpen == true ) - { - return false; - } - - bool wasDPadPressed = false; - Sint8 direction = 0; - - // If the User has pressed Up or Down on the D-Pad, move the mouse to the new slot - if ( *inputPressed(joyimpulses[INJOY_DPAD_UP]) ) - { - *inputPressed(joyimpulses[INJOY_DPAD_UP]) = 0; - direction = -1; - wasDPadPressed = true; - } - else if ( *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) ) - { - *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) = 0; - direction = 1; - wasDPadPressed = true; - } - - if ( wasDPadPressed == true ) - { - // Move the cursor to the new slot position - itemModifyingGUI->Gamepad_MoveCursor(direction); - - //draw_cursor = false; TODOR: Ask why this matters - - return true; - } - - return false; + if ( itemMenuOpen == true ) + { + return false; + } + + bool wasDPadPressed = false; + Sint8 direction = 0; + + // If the User has pressed Up or Down on the D-Pad, move the mouse to the new slot + if ( *inputPressed(joyimpulses[INJOY_DPAD_UP]) ) + { + *inputPressed(joyimpulses[INJOY_DPAD_UP]) = 0; + direction = -1; + wasDPadPressed = true; + } + else if ( *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) ) + { + *inputPressed(joyimpulses[INJOY_DPAD_DOWN]) = 0; + direction = 1; + wasDPadPressed = true; + } + + if ( wasDPadPressed == true ) + { + // Move the cursor to the new slot position + itemModifyingGUI->Gamepad_MoveCursor(direction); + + //draw_cursor = false; TODOR: Ask why this matters + + return true; + } + + return false; } bool GameController::handleItemContextMenu(const Item& item) diff --git a/src/player.hpp b/src/player.hpp index 1aaee1b14..1bf7a6fc0 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -138,13 +138,13 @@ class GameController */ bool handleShopMovement(); - /* player.cpp - * @returns true - If the cursor has been moved using the D-Pad - * @returns false - If the cursor has not been moved or 'itemMenuOpen' == true - * The cursor has been moved if '*joyimpulses[INJOY_DPAD_UP]' or '*joyimpulses[INJOY_DPAD_DOWN]' is true - * If the cursor has been moved, itemModifyingGUI->Gamepad_MoveCursor() will be called. 'dpad_moved' and 'draw_cursor' will both be set to false as well - */ - bool handleItemModifyingGUIMovement(); + /* player.cpp + * @returns true - If the cursor has been moved using the D-Pad + * @returns false - If the cursor has not been moved or 'itemMenuOpen' == true + * The cursor has been moved if '*joyimpulses[INJOY_DPAD_UP]' or '*joyimpulses[INJOY_DPAD_DOWN]' is true + * If the cursor has been moved, itemModifyingGUI->Gamepad_MoveCursor() will be called. 'dpad_moved' and 'draw_cursor' will both be set to false as well + */ + bool handleItemModifyingGUIMovement(); /* * Uses dpad to move the cursor through the item context menu and select entries. diff --git a/src/shops.cpp b/src/shops.cpp index 036f1427b..fafcb98e5 100644 --- a/src/shops.cpp +++ b/src/shops.cpp @@ -77,11 +77,11 @@ void startTradingServer(Entity* entity, int player) shopkeepername = stats->name; shopitemscroll = 0; - // If the ItemModifyingGUI is open, close it - if ( itemModifyingGUI->IsGUIOpen() == true ) - { - itemModifyingGUI->CloseGUI(); - } + // If the ItemModifyingGUI is open, close it + if ( itemModifyingGUI->IsGUIOpen() == true ) + { + itemModifyingGUI->CloseGUI(); + } //Initialize shop gamepad code here. if ( shopinvitems[0] != nullptr ) From 3b3c4998e0b0c25f6a13ad9b8889cdf860f08734 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 26 Sep 2017 17:14:13 -0500 Subject: [PATCH 65/65] - Remove the deprecated code entirely --- VS.2015/Barony/Barony.vcxproj.filters | 20 +- src/interface/identify_and_appraise.cpp | 520 ------------------------ src/interface/interface.hpp | 4 - src/interface/playerinventory.cpp | 59 --- src/interface/removecurse.cpp | 507 ----------------------- 5 files changed, 7 insertions(+), 1103 deletions(-) delete mode 100644 src/interface/identify_and_appraise.cpp delete mode 100644 src/interface/removecurse.cpp diff --git a/VS.2015/Barony/Barony.vcxproj.filters b/VS.2015/Barony/Barony.vcxproj.filters index 0a9b1a477..6e8fa23e0 100644 --- a/VS.2015/Barony/Barony.vcxproj.filters +++ b/VS.2015/Barony/Barony.vcxproj.filters @@ -321,9 +321,6 @@ Source Files\interface - - Source Files\interface - Source Files\interface @@ -333,9 +330,6 @@ Source Files\interface - - Source Files\interface - Source Files\interface @@ -366,10 +360,10 @@ Source Files\magic - + Source Files\interface - + Source Files\interface @@ -452,13 +446,13 @@ Header Files\magic - + Header Files\interface - + Header Files\interface - + Header Files @@ -467,10 +461,10 @@ Header Files - + Header Files - + Header Files diff --git a/src/interface/identify_and_appraise.cpp b/src/interface/identify_and_appraise.cpp deleted file mode 100644 index 4337608fc..000000000 --- a/src/interface/identify_and_appraise.cpp +++ /dev/null @@ -1,520 +0,0 @@ -/*------------------------------------------------------------------------------- - - BARONY - File: identify_and_appraise.cpp - Desc: contains identify and appraisal related (GUI) code. - - Copyright 2013-2016 (c) Turning Wheel LLC, all rights reserved. - See LICENSE for details. - --------------------------------------------------------------------------------*/ -/* -#include "../main.hpp" -#include "../game.hpp" -#include "../stat.hpp" -#include "../items.hpp" -#include "../net.hpp" -#include "../player.hpp" -#include "interface.hpp" - -#define IDENTIFY_GUI_X 1 -#define IDENTIFY_GUI_Y 1 -#define NUM_IDENTIFY_GUI_ITEMS 4 - -//Identify GUI definitions. -bool identifygui_active = false; -bool identifygui_appraising = false; -int identifygui_offset_x = 0; -int identifygui_offset_y = 0; -bool dragging_identifyGUI = false; -int identifyscroll = 0; -Item* identify_items[NUM_IDENTIFY_GUI_ITEMS]; -SDL_Surface* identifyGUI_img; - -int selectedIdentifySlot = -1; - -void rebuildIdentifyGUIInventory() -{ - list_t* identify_inventory = &stats[clientnum]->inventory; - node_t* node = nullptr; - Item* item = nullptr; - int c = 0; - - if (identify_inventory) - { - //Count the number of items in the identify GUI "inventory". - for (node = identify_inventory->first; node != NULL; node = node->next) - { - item = (Item*) node->element; - if (item && !item->identified) - { - c++; - } - } - identifyscroll = std::max(0, std::min(identifyscroll, c - 4)); - for (c = 0; c < 4; ++c) - { - identify_items[c] = NULL; - } - c = 0; - - //Assign the visible items to the GUI slots. - for (node = identify_inventory->first; node != NULL; node = node->next) - { - if (node->element) - { - item = (Item*) node->element; - if (item && !item->identified) //Skip over all identified items. - { - c++; - if (c <= identifyscroll) - { - continue; - } - identify_items[c - identifyscroll - 1] = item; - if (c > 3 + identifyscroll) - { - break; - } - } - } - } - } -} - -void updateIdentifyGUI() -{ - //if (openedChest[clientnum]) - // return; //Cannot have the identify and chest GUIs open at the same time. - - SDL_Rect pos; - node_t* node; - int y, c; - - //Identify GUI. - if (identifygui_active) - { - //Center the identify GUI. - pos.x = IDENTIFY_GUI_X; - pos.y = IDENTIFY_GUI_Y; - drawImage(identifyGUI_img, NULL, &pos); - - //Buttons - if ( mousestatus[SDL_BUTTON_LEFT] ) - { - //Identify GUI scroll up button. - if (omousey >= IDENTIFY_GUI_Y + 16 && omousey < IDENTIFY_GUI_Y + 52) - { - if (omousex >= IDENTIFY_GUI_X + (identifyGUI_img->w - 28) && omousex < IDENTIFY_GUI_X + (identifyGUI_img->w - 12)) - { - buttonclick = 7; - identifyscroll--; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - //Identify GUI scroll down button. - else if (omousey >= IDENTIFY_GUI_Y + 52 && omousey < IDENTIFY_GUI_Y + 88) - { - if (omousex >= IDENTIFY_GUI_X + (identifyGUI_img->w - 28) && omousex < IDENTIFY_GUI_X + (identifyGUI_img->w - 12)) - { - buttonclick = 8; - identifyscroll++; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - else if (omousey >= IDENTIFY_GUI_Y && omousey < IDENTIFY_GUI_Y + 15) - { - //Identify GUI close button. - if (omousex >= IDENTIFY_GUI_X + 393 && omousex < IDENTIFY_GUI_X + 407) - { - buttonclick = 9; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - if (omousex >= IDENTIFY_GUI_X && omousex < IDENTIFY_GUI_X + 377 && omousey >= IDENTIFY_GUI_Y && omousey < IDENTIFY_GUI_Y + 15) - { - gui_clickdrag = true; - dragging_identifyGUI = true; - dragoffset_x = omousex - IDENTIFY_GUI_X; - dragoffset_y = omousey - IDENTIFY_GUI_Y; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - } - - // mousewheel - if ( omousex >= IDENTIFY_GUI_X + 12 && omousex < IDENTIFY_GUI_X + (identifyGUI_img->w - 28) ) - { - if ( omousey >= IDENTIFY_GUI_Y + 16 && omousey < IDENTIFY_GUI_Y + (identifyGUI_img->h - 8) ) - { - if ( mousestatus[SDL_BUTTON_WHEELDOWN] ) - { - mousestatus[SDL_BUTTON_WHEELDOWN] = 0; - identifyscroll++; - } - else if ( mousestatus[SDL_BUTTON_WHEELUP] ) - { - mousestatus[SDL_BUTTON_WHEELUP] = 0; - identifyscroll--; - } - } - } - - if (dragging_identifyGUI) - { - if (gui_clickdrag) - { - identifygui_offset_x = (omousex - dragoffset_x) - (IDENTIFY_GUI_X - identifygui_offset_x); - identifygui_offset_y = (omousey - dragoffset_y) - (IDENTIFY_GUI_Y - identifygui_offset_y); - if (IDENTIFY_GUI_X <= camera.winx) - { - identifygui_offset_x = camera.winx - (IDENTIFY_GUI_X - identifygui_offset_x); - } - if (IDENTIFY_GUI_X > camera.winx + camera.winw - identifyGUI_img->w) - { - identifygui_offset_x = (camera.winx + camera.winw - identifyGUI_img->w) - (IDENTIFY_GUI_X - identifygui_offset_x); - } - if (IDENTIFY_GUI_Y <= camera.winy) - { - identifygui_offset_y = camera.winy - (IDENTIFY_GUI_Y - identifygui_offset_y); - } - if (IDENTIFY_GUI_Y > camera.winy + camera.winh - identifyGUI_img->h) - { - identifygui_offset_y = (camera.winy + camera.winh - identifyGUI_img->h) - (IDENTIFY_GUI_Y - identifygui_offset_y); - } - } - else - { - dragging_identifyGUI = false; - } - } - - list_t* identify_inventory = &stats[clientnum]->inventory; - - if (!identify_inventory) - { - messagePlayer(0, "Warning: stats[%d].inventory is not a valid list. This should not happen.", clientnum); - } - else - { - //Print the window label signifying this as the identify GUI. - char* window_name; - if (identifygui_appraising) - { - window_name = language[317]; - } - else - { - window_name = language[318]; - } - ttfPrintText(ttf8, (IDENTIFY_GUI_X + 2 + ((identifyGUI_img->w / 2) - ((TTF8_WIDTH * longestline(window_name)) / 2))), IDENTIFY_GUI_Y + 4, window_name); - - //Identify GUI up button. - if (buttonclick == 7) - { - pos.x = IDENTIFY_GUI_X + (identifyGUI_img->w - 28); - pos.y = IDENTIFY_GUI_Y + 16; - pos.w = 0; - pos.h = 0; - drawImage(invup_bmp, NULL, &pos); - } - //Identify GUI down button. - if (buttonclick == 8) - { - pos.x = IDENTIFY_GUI_X + (identifyGUI_img->w - 28); - pos.y = IDENTIFY_GUI_Y + 52; - pos.w = 0; - pos.h = 0; - drawImage(invdown_bmp, NULL, &pos); - } - //Identify GUI close button. - if (buttonclick == 9) - { - pos.x = IDENTIFY_GUI_X + 393; - pos.y = IDENTIFY_GUI_Y; - pos.w = 0; - pos.h = 0; - drawImage(invclose_bmp, NULL, &pos); - identifygui_active = false; - identifygui_appraising = false; - - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; - //TODO: closeIdentifyGUI() instead. - } - - Item* item = NULL; - - bool selectingSlot = false; - SDL_Rect slotPos; - slotPos.x = IDENTIFY_GUI_X; - slotPos.w = inventoryoptionChest_bmp->w; - slotPos.y = IDENTIFY_GUI_Y + 16; - slotPos.h = inventoryoptionChest_bmp->h; - for ( int i = 0; i < NUM_IDENTIFY_GUI_ITEMS; ++i, slotPos.y += slotPos.h ) - { - pos.x = slotPos.x + 12; - pos.w = 0; - pos.h = 0; - - if ( omousey >= slotPos.y && omousey < slotPos.y + slotPos.h && identify_items[i] ) - { - pos.y = slotPos.y; - drawImage(inventoryoptionChest_bmp, nullptr, &pos); - selectedIdentifySlot = i; - selectingSlot = true; - if ( mousestatus[SDL_BUTTON_LEFT] || *inputPressed(joyimpulses[INJOY_MENU_USE]) ) - { - *inputPressed(joyimpulses[INJOY_MENU_USE]) = 0; - mousestatus[SDL_BUTTON_LEFT] = 0; - identifyGUIIdentify(identify_items[i]); - - rebuildIdentifyGUIInventory(); - if ( identify_items[i] == nullptr ) - { - if ( identify_items[0] == nullptr ) - { - //Go back to inventory. - selectedIdentifySlot = -1; - warpMouseToSelectedInventorySlot(); - } - else - { - //Move up one slot. - --selectedIdentifySlot; - warpMouseToSelectedIdentifySlot(); - } - } - } - } - } - - if ( !selectingSlot ) - { - selectedIdentifySlot = -1; - } - - //Okay, now prepare to render all the items. - y = IDENTIFY_GUI_Y + 22; - c = 0; - if (identify_inventory) - { - rebuildIdentifyGUIInventory(); - - //Actually render the items. - c = 0; - for (node = identify_inventory->first; node != NULL; node = node->next) - { - if (node->element) - { - item = (Item*) node->element; - if (item && !item->identified) //Skip over all identified items. - { - c++; - if (c <= identifyscroll) - { - continue; - } - char tempstr[64] = { 0 }; - strncpy(tempstr, item->description(), 46); - if ( strlen(tempstr) == 46 ) - { - strcat(tempstr, " ..."); - } - ttfPrintText(ttf8, IDENTIFY_GUI_X + 36, y, tempstr); - pos.x = IDENTIFY_GUI_X + 16; - pos.y = IDENTIFY_GUI_Y + 17 + 18 * (c - identifyscroll - 1); - pos.w = 16; - pos.h = 16; - drawImageScaled(itemSprite(item), NULL, &pos); - y += 18; - if (c > 3 + identifyscroll) - { - break; - } - } - } - } - } - } - } -} //updateIdentifyGUI() - -void identifyGUIIdentify(Item* item) -{ - if (!item) - { - return; - } - if (item->identified) - { - messagePlayer(clientnum, language[319], item->getName()); - return; - } - - if (!identifygui_appraising) - { - item->identified = true; - messagePlayer(clientnum, language[320], item->description()); - if (appraisal_timer > 0 && appraisal_item && appraisal_item == item->uid) - { - appraisal_timer = 0; - appraisal_item = 0; - } - } - else - { - //Appraising. - - //If appraisal skill >= LEGENDARY, then auto-complete appraisal. Else, do the normal routine. - if ( stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] >= CAPSTONE_UNLOCK_LEVEL[PRO_APPRAISAL] ) - { - item->identified = true; - messagePlayer(clientnum, language[320], item->description()); - if (appraisal_timer > 0 && appraisal_item && appraisal_item == item->uid) - { - appraisal_timer = 0; - appraisal_item = 0; - } - } - else - { - messagePlayer(clientnum, language[321], item->description()); - - //Tick the timer in act player. - //Once the timer hits zero, roll to see if the item is identified. - //If it is identified, identify it and print out a message for the player. - - identifygui_appraising = false; - appraisal_timer = getAppraisalTime(item); - appraisal_timermax = appraisal_timer; - appraisal_item = item->uid; - } - } - identifygui_active = false; - - //Cleanup identify GUI gamecontroller code here. - selectedIdentifySlot = -1; -} - -int getAppraisalTime(Item* item) -{ - int appraisal_time; - if ( item->type != GEM_GLASS ) - { - appraisal_time = (items[item->type].value * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); // time in ticks until item is appraised - } - else - { - appraisal_time = (1000 * 60) / (stats[clientnum]->PROFICIENCIES[PRO_APPRAISAL] + 1); // time in ticks until item is appraised+- - } - appraisal_time = std::min(std::max(1, appraisal_time), 36000); - return appraisal_time; -} - -inline Item* getItemInfoFromIdentifyGUI(int slot) -{ - if ( slot >= 4 ) - { - return nullptr; //Out of bounds, - } - - return identify_items[slot]; -} - -void selectIdentifySlot(int slot) -{ - if ( slot < selectedIdentifySlot ) - { - //Moving up. - - - * Possible cases: - * * 1) Move cursor up the GUI through different selectedIdentifySlot. - * * 2) Page up through identifyscroll-- - * * 3) Scrolling up past top of Identify GUI, no identifyscroll (move back to inventory) - - - if ( selectedIdentifySlot <= 0 ) - { - //Covers cases 2 & 3. - - - * Possible cases: - * * A) Hit very top of Identify "inventory", can't go any further. Return to inventory. - * * B) Page up, scrolling through identifyscroll. - - - if ( identifyscroll <= 0 ) - { - //Case 3/A: Return to inventory. - selectedIdentifySlot = -1; - } - else - { - //Case 2/B: Page up through Identify "inventory". - --identifyscroll; - } - } - else - { - //Covers case 1. - - //Move cursor up the GUI through different selectedIdentifySlot (--selectedIdentifySlot). - --selectedIdentifySlot; - warpMouseToSelectedIdentifySlot(); - } - } - else if ( slot > selectedIdentifySlot ) - { - //Moving down. - - - * Possible cases: - * * 1) Moving cursor down through GUI through different selectedIdentifySlot. - * * 2) Scrolling down past bottom of Identify GUI through identifyscroll++ - * * 3) Scrolling down past bottom of Identify GUI, max Identify scroll (revoke move -- can't go beyond limit of Identify GUI). - - - if ( selectedIdentifySlot >= NUM_IDENTIFY_GUI_ITEMS - 1 ) - { - //Covers cases 2 & 3. - ++identifyscroll; //identifyscroll is automatically sanitized in updateIdentifyGUI(). - } - else - { - //Covers case 1. - //Move cursor down through the GUi through different selectedIdentifySlot (++selectedIdentifySlot). - //This is a little bit trickier since must revoke movement if there is no item in the next slot! - - - * Two possible cases: - * * A) Items below this. Advance selectedIdentifySlot to them. - * * B) On last item already. Do nothing (revoke movement). - - - Item* item = getItemInfoFromIdentifyGUI(selectedIdentifySlot + 1); - - if ( item ) - { - ++selectedIdentifySlot; - warpMouseToSelectedIdentifySlot(); - } - else - { - //No more items. Stop. - } - } - } -} - -void warpMouseToSelectedIdentifySlot() -{ - SDL_Rect slotPos; - slotPos.x = IDENTIFY_GUI_X; - slotPos.w = inventoryoptionChest_bmp->w; - slotPos.h = inventoryoptionChest_bmp->h; - slotPos.y = IDENTIFY_GUI_Y + 16 + (slotPos.h * selectedIdentifySlot); - - SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); -} -*/ \ No newline at end of file diff --git a/src/interface/interface.hpp b/src/interface/interface.hpp index 998cc22bc..b76c34477 100644 --- a/src/interface/interface.hpp +++ b/src/interface/interface.hpp @@ -111,7 +111,6 @@ int loadConfig(char* filename); int saveConfig(char* filename); void defaultConfig(); void updateChestInventory(); -//void updateAppraisalItemBox(); void updatePlayerInventory(); void updateShopWindow(); void updateEnemyBar(Entity* source, Entity* target, char* name, Sint32 hp, Sint32 maxhp); @@ -218,9 +217,6 @@ extern SDL_Surface* rightsidebar_slot_img; extern SDL_Surface* rightsidebar_slot_highlighted_img; extern SDL_Surface* rightsidebar_slot_grayedout_img; extern int rightsidebar_height; -//extern int appraisal_timer; //There is a delay after the appraisal skill is activated before the item is identified. -//extern int appraisal_timermax; -//extern Uint32 appraisal_item; //The item being appraised (or rather its uid) //void updateRightSidebar(); //Updates the sidebar on the right side of the screen, the one containing spells, skills, etc. DEPRECATED: See updaterightsidebar.cpp diff --git a/src/interface/playerinventory.cpp b/src/interface/playerinventory.cpp index ffd2412db..58b242964 100644 --- a/src/interface/playerinventory.cpp +++ b/src/interface/playerinventory.cpp @@ -238,65 +238,6 @@ char* itemUseString(const Item* item) return language[332]; } -/*------------------------------------------------------------------------------- - - updateAppraisalItemBox - - draws the current item being appraised - --------------------------------------------------------------------------------*/ -/* -void updateAppraisalItemBox() -{ - SDL_Rect pos; - Item* item; - int x, y; - - x = INVENTORY_STARTX; - y = INVENTORY_STARTY; - - // appraisal item box - if ( (item = uidToItem(appraisal_item)) != NULL && appraisal_timer > 0 ) - { - if ( !shootmode ) - { - pos.x = x + 16; - pos.y = y + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16; - } - else - { - pos.x = 16; - pos.y = 16; - } - int w1, w2; - TTF_SizeUTF8(ttf12, language[340], &w1, NULL); - TTF_SizeUTF8(ttf12, item->getName(), &w2, NULL); - w2 += 48; - pos.w = std::max(w1, w2) + 8; - pos.h = 68; - drawTooltip(&pos); - - char tempstr[64] = { 0 }; - snprintf(tempstr, 63, language[341], (((double)(appraisal_timermax - appraisal_timer)) / ((double)appraisal_timermax)) * 100); - ttfPrintText( ttf12, pos.x + 8, pos.y + 8, tempstr ); - if ( !shootmode ) - { - pos.x = x + 24; - pos.y = y + INVENTORY_SIZEY * INVENTORY_SLOTSIZE + 16 + 24; - } - else - { - pos.x = 24; - pos.y = 16 + 24; - } - ttfPrintText( ttf12, pos.x + 40, pos.y + 8, item->getName() ); - pos.w = 32; - pos.h = 32; - drawImageScaled(itemSprite(item), NULL, &pos); - } -} -*/ - void select_inventory_slot(int x, int y) { if ( x < 0 ) //Wrap around left boundary. diff --git a/src/interface/removecurse.cpp b/src/interface/removecurse.cpp deleted file mode 100644 index f96e8b21c..000000000 --- a/src/interface/removecurse.cpp +++ /dev/null @@ -1,507 +0,0 @@ -/*------------------------------------------------------------------------------- - - BARONY - File: removecurse.cpp - Desc: GUI code for the remove curse spell. - - Copyright 2013-2016 (c) Turning Wheel LLC, all rights reserved. - See LICENSE for details. - --------------------------------------------------------------------------------*/ -/* -#include "../main.hpp" -#include "../game.hpp" -#include "../stat.hpp" -#include "../items.hpp" -#include "../net.hpp" -#include "../player.hpp" -#include "interface.hpp" - -//Remove curse GUI definitions. -bool removecursegui_active = false; -bool removecursegui_appraising = false; -int removecursegui_offset_x = 0; -int removecursegui_offset_y = 0; -bool dragging_removecurseGUI = false; -int removecursescroll = 0; -Item* removecurse_items[NUM_REMOVE_CURSE_GUI_ITEMS]; -SDL_Surface* removecurseGUI_img; - -int selectedRemoveCurseSlot = -1; - -void rebuildRemoveCurseGUIInventory() -{ - list_t* removecurse_inventory = &stats[clientnum]->inventory; - node_t* node = nullptr; - Item* item = nullptr; - int c = 0; - - if ( removecurse_inventory ) - { - //Count the number of items in the Remove Curse GUI "inventory". - for ( node = removecurse_inventory->first; node != nullptr; node = node->next ) - { - item = (Item*) node->element; - if ( item && item->identified && item->beatitude < 0 ) - { - ++c; - } - } - removecursescroll = std::max(0, std::min(removecursescroll, c - 4)); - for ( c = 0; c < 4; ++c ) - { - removecurse_items[c] = nullptr; - } - c = 0; - - //Assign the visible items to the GUI slots. - for ( node = removecurse_inventory->first; node != nullptr; node = node->next ) - { - if ( node->element ) - { - item = (Item*) node->element; - if ( item && item->identified && item->beatitude < 0 ) //Skip over all unidentified or uncursed items. - { - ++c; - if ( c <= removecursescroll ) - { - continue; - } - removecurse_items[c - removecursescroll - 1] = item; - if ( c > 3 + removecursescroll ) - { - break; - } - } - } - } - } -} - - -void updateRemoveCurseGUI() -{ - SDL_Rect pos; - node_t* node; - int y, c; - - //Remove Curse GUI. - if (removecursegui_active) - { - //Center the remove curse GUI. - pos.x = REMOVECURSE_GUI_X; - pos.y = REMOVECURSE_GUI_Y; - drawImage(identifyGUI_img, NULL, &pos); - - //Buttons - if ( mousestatus[SDL_BUTTON_LEFT] ) - { - //Remove Curse GUI scroll up button. - if (omousey >= REMOVECURSE_GUI_Y + 16 && omousey < REMOVECURSE_GUI_Y + 52) - { - if (omousex >= REMOVECURSE_GUI_X + (identifyGUI_img->w - 28) && omousex < REMOVECURSE_GUI_X + (identifyGUI_img->w - 12)) - { - buttonclick = 7; - removecursescroll--; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - //Remove Curse GUI scroll down button. - else if (omousey >= REMOVECURSE_GUI_Y + 52 && omousey < REMOVECURSE_GUI_Y + 88) - { - if (omousex >= REMOVECURSE_GUI_X + (identifyGUI_img->w - 28) && omousex < REMOVECURSE_GUI_X + (identifyGUI_img->w - 12)) - { - buttonclick = 8; - removecursescroll++; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - else if (omousey >= REMOVECURSE_GUI_Y && omousey < REMOVECURSE_GUI_Y + 15) - { - //Remove Curse GUI close button. - if (omousex >= REMOVECURSE_GUI_X + 393 && omousex < REMOVECURSE_GUI_X + 407) - { - buttonclick = 9; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - if (omousex >= REMOVECURSE_GUI_X && omousex < REMOVECURSE_GUI_X + 377 && omousey >= REMOVECURSE_GUI_Y && omousey < REMOVECURSE_GUI_Y + 15) - { - gui_clickdrag = true; - dragging_removecurseGUI = true; - dragoffset_x = omousex - REMOVECURSE_GUI_X; - dragoffset_y = omousey - REMOVECURSE_GUI_Y; - mousestatus[SDL_BUTTON_LEFT] = 0; - } - } - } - - // mousewheel - if ( omousex >= REMOVECURSE_GUI_X + 12 && omousex < REMOVECURSE_GUI_X + (identifyGUI_img->w - 28) ) - { - if ( omousey >= REMOVECURSE_GUI_Y + 16 && omousey < REMOVECURSE_GUI_Y + (identifyGUI_img->h - 8) ) - { - if ( mousestatus[SDL_BUTTON_WHEELDOWN] ) - { - mousestatus[SDL_BUTTON_WHEELDOWN] = 0; - removecursescroll++; - } - else if ( mousestatus[SDL_BUTTON_WHEELUP] ) - { - mousestatus[SDL_BUTTON_WHEELUP] = 0; - removecursescroll--; - } - } - } - - if (dragging_removecurseGUI) - { - if (gui_clickdrag) - { - removecursegui_offset_x = (omousex - dragoffset_x) - (REMOVECURSE_GUI_X - removecursegui_offset_x); - removecursegui_offset_y = (omousey - dragoffset_y) - (REMOVECURSE_GUI_Y - removecursegui_offset_y); - if (REMOVECURSE_GUI_X <= camera.winx) - { - removecursegui_offset_x = camera.winx - (REMOVECURSE_GUI_X - removecursegui_offset_x); - } - if (REMOVECURSE_GUI_X > camera.winx + camera.winw - identifyGUI_img->w) - { - removecursegui_offset_x = (camera.winx + camera.winw - identifyGUI_img->w) - (REMOVECURSE_GUI_X - removecursegui_offset_x); - } - if (REMOVECURSE_GUI_Y <= camera.winy) - { - removecursegui_offset_y = camera.winy - (REMOVECURSE_GUI_Y - removecursegui_offset_y); - } - if (REMOVECURSE_GUI_Y > camera.winy + camera.winh - identifyGUI_img->h) - { - removecursegui_offset_y = (camera.winy + camera.winh - identifyGUI_img->h) - (REMOVECURSE_GUI_Y - removecursegui_offset_y); - } - } - else - { - dragging_removecurseGUI = false; - } - } - - list_t* removecurse_inventory = &stats[clientnum]->inventory; - - if (!removecurse_inventory) - { - messagePlayer(0, "Warning: stats[%d].inventory is not a valid list. This should not happen.", clientnum); - } - else - { - //Print the window label signifying this as the remove curse GUI. - char* window_name; - window_name = language[346]; - ttfPrintText(ttf8, (REMOVECURSE_GUI_X + 2 + ((identifyGUI_img->w / 2) - ((TTF8_WIDTH * longestline(window_name)) / 2))), REMOVECURSE_GUI_Y + 4, window_name); - - //Remove Curse GUI up button. - if (buttonclick == 7) - { - pos.x = REMOVECURSE_GUI_X + (identifyGUI_img->w - 28); - pos.y = REMOVECURSE_GUI_Y + 16; - pos.w = 0; - pos.h = 0; - drawImage(invup_bmp, NULL, &pos); - } - //Remove Curse GUI down button. - if (buttonclick == 8) - { - pos.x = REMOVECURSE_GUI_X + (identifyGUI_img->w - 28); - pos.y = REMOVECURSE_GUI_Y + 52; - pos.w = 0; - pos.h = 0; - drawImage(invdown_bmp, NULL, &pos); - } - //Remove Curse GUI close button. - if (buttonclick == 9) - { - pos.x = REMOVECURSE_GUI_X + 393; - pos.y = REMOVECURSE_GUI_Y; - pos.w = 0; - pos.h = 0; - drawImage(invclose_bmp, NULL, &pos); - closeRemoveCurseGUI(); - } - - Item *item = nullptr; - - bool selectingSlot = false; - SDL_Rect slotPos; - slotPos.x = REMOVECURSE_GUI_X; - slotPos.w = inventoryoptionChest_bmp->w; - slotPos.y = REMOVECURSE_GUI_Y + 16; - slotPos.h = inventoryoptionChest_bmp->h; - - for ( int i = 0; i < NUM_REMOVE_CURSE_GUI_ITEMS; ++i, slotPos.y += slotPos.h ) - { - pos.x = slotPos.x + 12; - pos.w = 0; - pos.h = 0; - - if ( omousey >= slotPos.y && omousey < slotPos.y + slotPos.h && removecurse_items[i] ) - { - pos.y = slotPos.y; - drawImage(inventoryoptionChest_bmp, nullptr, &pos); - selectedRemoveCurseSlot = i; - selectingSlot = true; - if ( mousestatus[SDL_BUTTON_LEFT] || *inputPressed(joyimpulses[INJOY_MENU_USE]) ) - { - *inputPressed(joyimpulses[INJOY_MENU_USE]) = 0; - mousestatus[SDL_BUTTON_LEFT] = 0; - removecurseGUIRemoveCurse(removecurse_items[i]); - - rebuildRemoveCurseGUIInventory(); - if ( removecurse_items[i] == nullptr ) - { - if ( removecurse_items[0] == nullptr ) - { - //Go back to inventory. - selectedRemoveCurseSlot = -1; - warpMouseToSelectedInventorySlot(); - } - else - { - //Move up one slot. - --selectedRemoveCurseSlot; - warpMouseToSelectedRemoveCurseSlot(); - } - } - } - } - } - - if ( !selectingSlot ) - { - selectedRemoveCurseSlot = -1; - } - - //Okay, now prepare to render all the items. - y = REMOVECURSE_GUI_Y + 22; - c = 0; - if (removecurse_inventory) - { - rebuildRemoveCurseGUIInventory(); - - //Actually render the items. - c = 0; - for (node = removecurse_inventory->first; node != NULL; node = node->next) - { - if (node->element) - { - item = (Item*) node->element; - if (item && item->identified && item->beatitude < 0) //Skip over all unidentified or uncursed items. - { - c++; - if (c <= removecursescroll) - { - continue; - } - char tempstr[64] = { 0 }; - strncpy(tempstr, item->description(), 46); - if ( strlen(tempstr) == 46 ) - { - strcat(tempstr, " ..."); - } - ttfPrintText(ttf8, REMOVECURSE_GUI_X + 36, y, tempstr); - pos.x = REMOVECURSE_GUI_X + 16; - pos.y = REMOVECURSE_GUI_Y + 17 + 18 * (c - removecursescroll - 1); - pos.w = 16; - pos.h = 16; - drawImageScaled(itemSprite(item), NULL, &pos); - y += 18; - if (c > 3 + removecursescroll) - { - break; - } - } - } - } - } - } - } -} //updateRemoveCurseGUI() - -void removecurseGUIRemoveCurse(Item* item) -{ - if (!item) - { - return; - } - if (item->beatitude >= 0) - { - messagePlayer(clientnum, language[347], item->getName()); - return; - } - - item->beatitude = 0; //0 = uncursed. > 0 = blessed. - messagePlayer(clientnum, language[348], item->description()); - closeRemoveCurseGUI(); - if ( multiplayer == CLIENT && itemIsEquipped(item, clientnum) ) - { - // the client needs to inform the server that their equipment was uncursed. - int armornum = 0; - if ( item == stats[clientnum]->helmet ) - { - armornum = 0; - } - else if ( item == stats[clientnum]->breastplate ) - { - armornum = 1; - } - else if ( item == stats[clientnum]->gloves ) - { - armornum = 2; - } - else if ( item == stats[clientnum]->shoes ) - { - armornum = 3; - } - else if ( item == stats[clientnum]->shield ) - { - armornum = 4; - } - else if ( item == stats[clientnum]->weapon ) - { - armornum = 5; - } - else if ( item == stats[clientnum]->cloak ) - { - armornum = 6; - } - else if ( item == stats[clientnum]->amulet ) - { - armornum = 7; - } - else if ( item == stats[clientnum]->ring ) - { - armornum = 8; - } - else if ( item == stats[clientnum]->mask ) - { - armornum = 9; - } - strcpy((char*)net_packet->data, "RCUR"); - net_packet->data[4] = clientnum; - net_packet->data[5] = armornum; - net_packet->address.host = net_server.host; - net_packet->address.port = net_server.port; - net_packet->len = 6; - sendPacketSafe(net_sock, -1, net_packet, 0); - } -} - -void closeRemoveCurseGUI() -{ - removecursegui_active = false; - - selectedRemoveCurseSlot = -1; -} - -inline Item* getItemInfoFromRemoveCurseGUI(int slot) -{ - if ( slot >= 4 ) - { - return nullptr; //Out of bounds, - } - - return removecurse_items[slot]; -} - -void selectRemoveCurseSlot(int slot) -{ - if ( slot < selectedRemoveCurseSlot ) - { - //Moving up. - - - * Possible cases: - * * 1) Move cursor up the GUI through different selectedRemoveCurseSlot. - * * 2) Page up through removecursescroll-- - * * 3) Scrolling up past top of Remove Curse GUI, no removecursescroll (move back to inventory) - - - if ( selectedRemoveCurseSlot <= 0 ) - { - //Covers cases 2 & 3. - - - * Possible cases: - * * A) Hit very top of Remove Curse "inventory", can't go any further. Return to inventory. - * * B) Page up, scrolling through removecursescroll. - - - if ( removecursescroll <= 0 ) - { - //Case 3/A: Return to inventory. - selectedRemoveCurseSlot = -1; - } - else - { - //Case 2/B: Page up through Remove Curse "inventory". - --removecursescroll; - } - } - else - { - //Covers case 1. - - //Move cursor up the GUI through different selectedRemoveCurseSlot (--selectedRemoveCurseSlot). - --selectedRemoveCurseSlot; - warpMouseToSelectedRemoveCurseSlot(); - } - } - else if ( slot > selectedRemoveCurseSlot ) - { - //Moving down. - - - * Possible cases: - * * 1) Moving cursor down through GUI through different selectedRemoveCurseSlot. - * * 2) Scrolling down past bottom of Remove Curse GUI through removecursescroll++ - * * 3) Scrolling down past bottom of Remove Curse GUI, max Remove Curse scroll (revoke move -- can't go beyond limit of Remove Curse GUI). - - - if ( selectedRemoveCurseSlot >= NUM_REMOVE_CURSE_GUI_ITEMS - 1 ) - { - //Covers cases 2 & 3. - ++removecursescroll; //removecursescroll is automatically sanitized in updateRemoveCurseGUI(). - } - else - { - //Covers case 1. - //Move cursor down through the GUI through different selectedRemoveCurseSlot (++selectedRemoveCurseSlot). - //This is a little bit trickier since must revoke movement if there is no item in the next slot! - - - * Two possible cases: - * * A) Items below this. Advance selectedRemoveCurseSlot to them. - * * B) On last item already. Do nothing (revoke movement). - - - Item* item = getItemInfoFromRemoveCurseGUI(selectedRemoveCurseSlot + 1); - - if ( item ) - { - ++selectedRemoveCurseSlot; - warpMouseToSelectedRemoveCurseSlot(); - } - else - { - //No more items. Stop. - } - } - } -} - -void warpMouseToSelectedRemoveCurseSlot() -{ - SDL_Rect slotPos; - slotPos.x = REMOVECURSE_GUI_X; - slotPos.w = inventoryoptionChest_bmp->w; - slotPos.h = inventoryoptionChest_bmp->h; - slotPos.y = REMOVECURSE_GUI_Y + 16 + (slotPos.h * selectedRemoveCurseSlot); - - SDL_WarpMouseInWindow(screen, slotPos.x + (slotPos.w / 2), slotPos.y + (slotPos.h / 2)); -} -*/ \ No newline at end of file