Skip to content

Commit

Permalink
feat: filter store inbox items
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Aug 29, 2023
1 parent 9cc674d commit 13db09a
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 22 deletions.
24 changes: 24 additions & 0 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37971,18 +37971,21 @@
<item id="25879" article="a" name="health cask">
<attribute key="description" value="This cask can be used to refill health potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item id="25880" article="a" name="strong health cask">
<attribute key="description" value="This cask can be used to refill strong health potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item id="25881" article="a" name="great health cask">
<attribute key="description" value="This cask can be used to refill great health potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
Expand All @@ -37995,19 +37998,22 @@
<item id="25883" article="a" name="supreme health cask">
<attribute key="description" value="This cask can be used to refill supreme health potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item fromid="25884" toid="25888" name="RESERVED SPRITE"/>
<item id="25889" article="a" name="mana cask">
<attribute key="description" value="This cask can be used to refill mana potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item id="25890" article="a" name="strong mana cask">
<attribute key="description" value="This cask can be used to refill strong mana potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
Expand All @@ -38020,96 +38026,112 @@
<item id="25892" article="an" name="ultimate mana cask">
<attribute key="description" value="This cask can be used to refill ultimate mana potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item id="25893" article="a" name="supreme mana cask">
<attribute key="description" value="This cask can be used to refill supreme mana potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item id="25899" article="a" name="great spirit cask">
<attribute key="description" value="This cask can be used to refill great spirit potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item id="25900" article="a" name="ultimate spirit cask">
<attribute key="description" value="This cask can be used to refill ultimate spirit potions"/>
<attribute key="charges" value="1000"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="200000"/>
</item>
<item id="25903" article="a" name="health keg">
<attribute key="description" value="This keg can be used to refill health potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="67500"/>
</item>
<item id="25904" article="a" name="strong health keg">
<attribute key="description" value="This keg can be used to refill strong health potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="72500"/>
</item>
<item id="25905" article="a" name="great health keg">
<attribute key="description" value="This keg can be used to refill great health potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="77500"/>
</item>
<item id="25906" article="an" name="ultimate health keg">
<attribute key="description" value="This keg can be used to refill ultimate health potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="77500"/>
</item>
<item id="25907" article="a" name="supreme health keg">
<attribute key="description" value="This keg can be used to refill supreme health potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="87500"/>
</item>
<item id="25908" article="a" name="mana keg">
<attribute key="description" value="This keg can be used to refill mana potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="67500"/>
</item>
<item id="25909" article="a" name="strong mana keg">
<attribute key="description" value="This keg can be used to refill strong mana potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="72500"/>
</item>
<item id="25910" article="a" name="great mana keg">
<attribute key="description" value="This keg can be used to refill great mana potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="77500"/>
</item>
<item id="25911" article="an" name="ultimate mana keg">
<attribute key="description" value="This keg can be used to refill ultimate mana potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="77500"/>
</item>
<item id="25912" article="a" name="supreme mana keg">
<attribute key="description" value="This keg can be used to refill supreme mana potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="12500"/>
</item>
<item id="25913" article="a" name="great spririt keg">
<attribute key="description" value="This keg can be used to refill great spririt potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="12500"/>
</item>
<item id="25914" article="an" name="ultimate spirit keg">
<attribute key="description" value="This keg can be used to refill ultimate spririt potions"/>
<attribute key="charges" value="500"/>
<attribute key="primarytype" value="consumable"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="77500"/>
</item>
Expand Down Expand Up @@ -40302,10 +40324,12 @@
<item id="27661" article="an" name="alchemistic chair">
<attribute key="wrapableto" value="23398"/>
<attribute key="rotateto" value="27662"/>
<attribute key="primarytype" value="furniture"/>
</item>
<item id="27662" article="an" name="alchemistic chair">
<attribute key="wrapableto" value="23398"/>
<attribute key="rotateto" value="27661"/>
<attribute key="primarytype" value="furniture"/>
</item>
<item id="27663" article="an" name="alchemistic cabinet">
<attribute key="containersize" value="8"/>
Expand Down
9 changes: 5 additions & 4 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ function GameStore.processItemPurchase(player, offerId, offerCount, moveable)
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox and inbox:getEmptySlots() > offerCount then
if inbox then
for t = 1, offerCount do
local inboxItem = inbox:addItem(offerId, offerCount or 1)
if moveable ~= true and inboxItem then
Expand All @@ -1509,7 +1509,7 @@ function GameStore.processChargesPurchase(player, itemtype, name, charges, movea
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox and inbox:getEmptySlots() > 1 then
if inbox then
local inboxItem = inbox:addItem(itemtype, charges)

if moveable ~= true and inboxItem then
Expand Down Expand Up @@ -1570,7 +1570,7 @@ function GameStore.processStackablePurchase(player, offerId, offerCount, offerNa
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox and inbox:getEmptySlots() > 0 then
if inbox then
if (isKeg and offerCount > 500) or offerCount > 100 then
local parcel = inbox:addItem(PARCEL_ID, 1)
parcel:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime());
Expand Down Expand Up @@ -1627,7 +1627,7 @@ function GameStore.processHouseRelatedPurchase(player, offer)
if type(itemIds) ~= "table" then
itemIds = { itemIds }
end
if inbox and inbox:getEmptySlots() >= #itemIds then
if inbox then
for _, itemId in ipairs(itemIds) do
local decoKit = inbox:addItem(23398, 1)
if decoKit then
Expand All @@ -1642,6 +1642,7 @@ function GameStore.processHouseRelatedPurchase(player, offer)
end
end
end
player:sendUpdateContainer(inbox)
else
return error({ code = 0, message = "Please make sure you have free slots in your store inbox." })
end
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ enum integerConfig_t {
STATUS_PORT,
STAIRHOP_DELAY,
MAX_CONTAINER,
MAX_ITEM,
MAX_CONTAINER_ITEM,
MARKET_OFFER_DURATION,
DEPOT_BOXES,
FREE_DEPOT_LIMIT,
Expand Down
2 changes: 1 addition & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ bool ConfigManager::load() {
integer[WHITE_SKULL_TIME] = getGlobalNumber(L, "whiteSkullTime", 15 * 60 * 1000);
integer[STAIRHOP_DELAY] = getGlobalNumber(L, "stairJumpExhaustion", 2000);
integer[MAX_CONTAINER] = getGlobalNumber(L, "maxContainer", 500);
integer[MAX_ITEM] = getGlobalNumber(L, "maxItem", 10000);
integer[MAX_CONTAINER_ITEM] = getGlobalNumber(L, "maxItem", 5000);
integer[EXP_FROM_PLAYERS_LEVEL_RANGE] = getGlobalNumber(L, "expFromPlayersLevelRange", 75);
integer[CHECK_EXPIRED_MARKET_OFFERS_EACH_MINUTES] = getGlobalNumber(L, "checkExpiredMarketOffersEachMinutes", 60);
integer[MAX_MARKET_OFFERS_AT_A_TIME_PER_PLAYER] = getGlobalNumber(L, "maxMarketOffersAtATimePerPlayer", 100);
Expand Down
1 change: 1 addition & 0 deletions src/enums/item_attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum ItemAttribute_t : uint64_t {
STORE = 31,
CUSTOM = 32,
LOOTMESSAGE_SUFFIX = 33,
STORE_INBOX_CATEGORY = 34,
};

enum ItemDecayState_t : uint8_t {
Expand Down
8 changes: 7 additions & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4108,7 +4108,7 @@ void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t coun
}
}

void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index) {
void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index, uint8_t containerCategory) {
Player* player = getPlayerByID(playerId);
if (!player) {
return;
Expand All @@ -4119,6 +4119,12 @@ void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_
return;
}

if (container->getID() == ITEM_STORE_INBOX) {
auto enumName = magic_enum::enum_name(static_cast<StoreInboxCategory_t>(containerCategory)).data();
container->setAttribute(ItemAttribute_t::STORE_INBOX_CATEGORY, enumName);
g_logger().debug("Setting new container with store inbox category name {}", enumName);
}

if ((index % container->capacity()) != 0 || index >= container->size()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class Game {
void playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId);
void playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std::string &text);
void playerBrowseField(uint32_t playerId, const Position &pos);
void playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index);
void playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index, uint8_t containerCategory);
void playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t windowTextId, const std::string &text);
void playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t stackPos, uint32_t tradePlayerId, uint16_t itemId);
void playerAcceptTrade(uint32_t playerId);
Expand Down
16 changes: 9 additions & 7 deletions src/items/containers/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

Container::Container(uint16_t type) :
Container(type, items[type].maxItems) {
if (getID() == ITEM_GOLD_POUCH) {
m_maxItems = static_cast<uint32_t>(g_configManager().getNumber(MAX_CONTAINER_ITEM));
if (getID() == ITEM_GOLD_POUCH || getID() == ITEM_STORE_INBOX) {
pagination = true;
m_maxItems = 2000;
maxSize = 32;
}
}

Expand Down Expand Up @@ -371,22 +374,21 @@ ReturnValue Container::queryAdd(int32_t addIndex, const Thing &addThing, uint32_
}

if (const Container* topParentContainer = getTopParentContainer()) {
uint32_t maxItem = static_cast<uint32_t>(g_configManager().getNumber(MAX_ITEM));
if (const Container* addContainer = item->getContainer()) {
uint32_t addContainerCount = addContainer->getContainerHoldingCount() + 1;
uint32_t maxContainer = static_cast<uint32_t>(g_configManager().getNumber(MAX_CONTAINER));
if (addContainerCount + topParentContainer->getContainerHoldingCount() > maxContainer) {
return RETURNVALUE_NOTPOSSIBLE;
return RETURNVALUE_CONTAINERISFULL;
}

uint32_t addItemCount = addContainer->getItemHoldingCount() + 1;
if (addItemCount + topParentContainer->getItemHoldingCount() > maxItem) {
return RETURNVALUE_NOTPOSSIBLE;
if (addItemCount + topParentContainer->getItemHoldingCount() > m_maxItems) {
return RETURNVALUE_CONTAINERISFULL;
}
}

if (topParentContainer->getItemHoldingCount() + 1 > maxItem) {
return RETURNVALUE_NOTPOSSIBLE;
if (topParentContainer->getItemHoldingCount() + 1 > m_maxItems) {
return RETURNVALUE_CONTAINERISFULL;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/items/containers/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class Container : public Item, public Cylinder {
protected:
std::ostringstream &getContentDescription(std::ostringstream &os, bool oldProtocol) const;

uint32_t m_maxItems;
uint32_t maxSize;
uint32_t totalWeight = 0;
ItemDeque itemlist;
Expand Down
1 change: 1 addition & 0 deletions src/items/functions/item/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ItemAttributeHelper {
case ItemAttribute_t::PLURALNAME:
case ItemAttribute_t::SPECIAL:
case ItemAttribute_t::LOOTMESSAGE_SUFFIX:
case ItemAttribute_t::STORE_INBOX_CATEGORY:
return true;
default:
return false;
Expand Down
8 changes: 7 additions & 1 deletion src/items/functions/item/item_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void ItemParse::initParse(const std::string &tmpStrValue, pugi::xml_node attribu
ItemParse::parseMagicLevelPoint(tmpStrValue, valueAttribute, itemType);
ItemParse::parseFieldAbsorbPercent(tmpStrValue, valueAttribute, itemType);
ItemParse::parseAbsorbPercent(tmpStrValue, valueAttribute, itemType);

ItemParse::parseSupressDrunk(tmpStrValue, valueAttribute, itemType);
ItemParse::parseField(tmpStrValue, attributeNode, valueAttribute, itemType);
ItemParse::parseReplaceable(tmpStrValue, valueAttribute, itemType);
Expand All @@ -73,6 +72,7 @@ void ItemParse::initParse(const std::string &tmpStrValue, pugi::xml_node attribu
ItemParse::parseCleavePercent(tmpStrValue, valueAttribute, itemType);
ItemParse::parseReflectDamage(tmpStrValue, valueAttribute, itemType);
ItemParse::parseTransformOnUse(tmpStrValue, valueAttribute, itemType);
ItemParse::parsePrimaryType(tmpStrValue, valueAttribute, itemType);
}

void ItemParse::parseDummyRate(pugi::xml_node attributeNode, ItemType &itemType) {
Expand Down Expand Up @@ -940,3 +940,9 @@ void ItemParse::parseTransformOnUse(const std::string_view &tmpStrValue, pugi::x
itemType.m_transformOnUse = pugi::cast<uint16_t>(valueAttribute.value());
}
}

void ItemParse::parsePrimaryType(const std::string_view &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType) {
if (tmpStrValue == "primarytype") {
itemType.m_primaryType = asLowerCaseString(valueAttribute.as_string());
}
}
2 changes: 2 additions & 0 deletions src/items/functions/item/item_parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const phmap::flat_hash_map<std::string, ItemParseAttributes_t> ItemParseAttribut
{ "cleavepercent", ITEM_PARSE_CLEAVEPERCENT },
{ "reflectdamage", ITEM_PARSE_REFLECTDAMAGE },
{ "reflectpercentall", ITEM_PARSE_REFLECTPERCENTALL },
{ "primarytype", ITEM_PARSE_PRIMARYTYPE },
};

const phmap::flat_hash_map<std::string, ItemTypes_t> ItemTypesMap = {
Expand Down Expand Up @@ -308,6 +309,7 @@ class ItemParse : public Items {
static void parseCleavePercent(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType);
static void parseReflectDamage(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType);
static void parseTransformOnUse(const std::string_view &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType);
static void parsePrimaryType(const std::string_view &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType);

private:
// Parent of the function: static void parseField
Expand Down
15 changes: 15 additions & 0 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,17 @@ Attr_ReadValue Item::readAttr(AttrTypes_t attr, PropStream &propStream) {
break;
}

case ATTR_STORE_INBOX_CATEGORY: {
std::string category;
if (!propStream.readString(category)) {
g_logger().error("[{}] failed to read store inbox category from item {}", __FUNCTION__, getName());
return ATTR_READ_ERROR;
}

setAttribute(ItemAttribute_t::STORE_INBOX_CATEGORY, category);
break;
}

default:
return ATTR_READ_ERROR;
}
Expand Down Expand Up @@ -954,6 +965,10 @@ void Item::serializeAttr(PropWriteStream &propWriteStream) const {
propWriteStream.write<uint8_t>(ATTR_AMOUNT);
propWriteStream.write<uint16_t>(getAttribute<uint16_t>(AMOUNT));
}
if (hasAttribute(STORE_INBOX_CATEGORY)) {
propWriteStream.write<uint8_t>(ATTR_STORE_INBOX_CATEGORY);
propWriteStream.writeString(getString(ItemAttribute_t::STORE_INBOX_CATEGORY));
}

// Serialize custom attributes, only serialize if the map not is empty
if (hasCustomAttribute()) {
Expand Down
Loading

0 comments on commit 13db09a

Please sign in to comment.