Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: save stateful items in houses #1539

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions data-otservbr-global/scripts/actions/other/transform_to.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ local transformItems = {
[2663] = 2662, -- cuckoo clock
[2772] = 2773,
[2773] = 2772, -- lever
[2907] = 2908,
[2908] = 2907, -- wall lamp
[2909] = 2910,
[2910] = 2909, -- wall lamp
[2911] = 2912,
[2912] = 2911, -- candelabrum
[2914] = 2915,
Expand All @@ -54,12 +50,6 @@ local transformItems = {
[2931] = 2930, -- torch bearer
[2934] = 2935,
[2935] = 2934, -- table lamp
[2936] = 2937,
[2937] = 2936, -- wall lamp
[2938] = 2939,
[2939] = 2938, -- wall lamp
[2944] = 2945,
[2945] = 2944, -- wall lamp
[2977] = 2978,
[2978] = 2977, -- pumpkinhead
[3046] = 3047,
Expand Down Expand Up @@ -403,18 +393,6 @@ local transformItems = {
[38525] = 38523, -- naga lamp
[38526] = 38528,
[38528] = 38526, -- basin with a glowing flower
[38529] = 38530,
[38530] = 38529, -- wall lamp
[38531] = 38532,
[38532] = 38531, -- wall lamp
[38533] = 38534,
[38534] = 38533, -- wall lamp
[38535] = 38536,
[38536] = 38535, -- wall lamp
[38623] = 38624,
[38624] = 38623, -- wall lamp
[38625] = 38626,
[38626] = 38625, -- wall lamp
[38677] = 38680,
[38704] = 38705, -- beaver of wisdom
[38827] = 38828,
Expand All @@ -428,10 +406,6 @@ local transformItems = {
[39443] = 39444,
[39444] = 39445, -- knightly fire bowl
[39445] = 39443, -- knightly fire bowl
[39446] = 39447,
[39447] = 39446, -- knightly wall lamp
[39496] = 39497,
[39497] = 39496, -- knightly sword lamp
[39498] = 39499,
[39499] = 39498, -- knightly candelabra
[39500] = 39501,
Expand Down
100 changes: 76 additions & 24 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5532,10 +5532,18 @@
<attribute key="primarytype" value="tools"/>
<attribute key="weight" value="50"/>
</item>
<item id="2907" article="a" name="wall lamp"/>
<item id="2908" article="a" name="lit wall lamp"/>
<item id="2909" article="a" name="wall lamp"/>
<item id="2910" article="a" name="lit wall lamp"/>
<item id="2907" article="a" name="wall lamp">
<attribute key="transformOnUse" value="2908"/>
</item>
<item id="2908" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="2907"/>
</item>
<item id="2909" article="a" name="wall lamp">
<attribute key="transformOnUse" value="2910"/>
</item>
<item id="2910" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="2909"/>
</item>
<item id="2911" article="a" name="candelabrum">
<attribute key="primarytype" value="light sources"/>
<attribute key="stopduration" value="1"/>
Expand Down Expand Up @@ -5647,10 +5655,18 @@
<attribute key="primarytype" value="decoration"/>
</item>
<item id="2935" article="a" name="lit table lamp"/>
<item id="2936" article="a" name="wall lamp"/>
<item id="2937" article="a" name="lit wall lamp"/>
<item id="2938" article="a" name="wall lamp"/>
<item id="2939" article="a" name="lit wall lamp"/>
<item id="2936" article="a" name="wall lamp">
<attribute key="transformOnUse" value="2937"/>
</item>
<item id="2937" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="2936"/>
</item>
<item id="2938" article="a" name="wall lamp">
<attribute key="transformOnUse" value="2939"/>
</item>
<item id="2939" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="2938"/>
</item>
<item id="2940" article="a" name="torch bearer">
<attribute key="primarytype" value="wall hangings"/>
</item>
Expand All @@ -5663,10 +5679,18 @@
<item id="2943" article="a" name="lit torch bearer">
<attribute key="primarytype" value="wall hangings"/>
</item>
<item id="2944" article="a" name="wall lamp"/>
<item id="2945" article="a" name="lit wall lamp"/>
<item id="2946" article="a" name="wall lamp"/>
<item id="2947" article="a" name="lit wall lamp"/>
<item id="2944" article="a" name="wall lamp">
<attribute key="transformOnUse" value="2945"/>
</item>
<item id="2945" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="2944"/>
</item>
<item id="2946" article="a" name="wall lamp">
<attribute key="transformOnUse" value="2947"/>
</item>
<item id="2947" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="2946"/>
</item>
<item id="2948" article="a" name="wooden flute">
<attribute key="primarytype" value="musical instruments"/>
<attribute key="weight" value="200"/>
Expand Down Expand Up @@ -64974,20 +64998,44 @@
<item fromid="38522" toid="38525" article="a" name="naga lamp"/>
<item id="38526" article="a" name="basin with a glowing flower"/>
<item id="38528" article="a" name="basin with flower"/>
<item id="38529" article="a" name="wall lamp"/>
<item id="38530" article="a" name="lit wall lamp"/>
<item id="38531" article="a" name="wall lamp"/>
<item id="38532" article="a" name="lit wall lamp"/>
<item id="38533" article="a" name="wall lamp"/>
<item id="38534" article="a" name="lit wall lamp"/>
<item id="38535" article="a" name="wall lamp"/>
<item id="38536" article="a" name="lit wall lamp"/>
<item id="38529" article="a" name="wall lamp">
<attribute key="transformOnUse" value="38530"/>
</item>
<item id="38530" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="38529"/>
</item>
<item id="38531" article="a" name="wall lamp">
<attribute key="transformOnUse" value="38532"/>
</item>
<item id="38532" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="38531"/>
</item>
<item id="38533" article="a" name="wall lamp">
<attribute key="transformOnUse" value="38534"/>
</item>
<item id="38534" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="38533"/>
</item>
<item id="38535" article="a" name="wall lamp">
<attribute key="transformOnUse" value="38536"/>
</item>
<item id="38536" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="38535"/>
</item>
<item fromid="38537" toid="38613" article="a" name="big naga statue"/>
<item fromid="38614" toid="38622" name="mangrove branches"/>
<item id="38623" article="a" name="wall lamp"/>
<item id="38624" article="a" name="lit wall lamp"/>
<item id="38625" article="a" name="wall lamp"/>
<item id="38626" article="a" name="lit wall lamp"/>
<item id="38623" article="a" name="wall lamp">
<attribute key="transformOnUse" value="38624"/>
</item>
<item id="38624" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="38623"/>
</item>
<item id="38625" article="a" name="wall lamp">
<attribute key="transformOnUse" value="38626"/>
</item>
<item id="38626" article="a" name="lit wall lamp">
<attribute key="transformOnUse" value="38625"/>
</item>
<item id="38633" name="peacock feather">
<attribute key="primarytype" value="quest items"/>
<attribute key="weight" value="20"/>
Expand Down Expand Up @@ -66632,19 +66680,23 @@
</item>
<item id="39446" article="a" name="knightly wall lamp">
<attribute key="primarytype" value="furniture"/>
<attribute key="transformOnUse" value="39447"/>
<attribute key="wrapableto" value="23398"/>
</item>
<item id="39447" article="a" name="knightly wall lamp">
<attribute key="primarytype" value="furniture"/>
<attribute key="transformOnUse" value="39446"/>
<attribute key="wrapableto" value="23398"/>
</item>
<item fromid="39484" toid="39495" name="some crystals"/>
<item id="39496" article="a" name="knightly sword lamp">
<attribute key="primarytype" value="furniture"/>
<attribute key="transformOnUse" value="39497"/>
<attribute key="wrapableto" value="23398"/>
</item>
<item id="39497" article="a" name="knightly sword lamp">
<attribute key="primarytype" value="furniture"/>
<attribute key="transformOnUse" value="39496"/>
<attribute key="wrapableto" value="23398"/>
</item>
<item id="39498" article="a" name="knightly candelabra">
Expand Down
8 changes: 4 additions & 4 deletions src/io/iomapserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ bool IOMapSerialize::loadItem(PropStream &propStream, Cylinder* parent, bool isH
if (findItem->getID() == id) {
item = findItem;
break;
} else if (iType.m_transformOnUse && findItem->getID() == iType.m_transformOnUse) {
item = findItem;
break;
} else if (iType.isDoor() && findItem->getDoor()) {
item = findItem;
break;
Expand Down Expand Up @@ -232,10 +235,7 @@ void IOMapSerialize::saveTile(PropWriteStream &stream, const Tile* tile) {
std::forward_list<Item*> items;
uint16_t count = 0;
for (Item* item : *tileItems) {
const ItemType &it = Item::items[item->getID()];

// Note that these are NEGATED, ie. these are the items that will be saved.
if (!(it.moveable || it.isCarpet() || item->getDoor() || (item->getContainer() && !item->getContainer()->empty()) || it.canWriteText || item->getBed())) {
if (!item->isSavedToHouses()) {
continue;
}

Expand Down
5 changes: 5 additions & 0 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,11 @@ std::string Item::parseImbuementDescription(const Item* item) {
return s.str();
}

bool Item::isSavedToHouses() const {
const auto &it = items[id];
return it.moveable || it.isWrappable() || it.isCarpet() || getDoor() || (getContainer() && !getContainer()->empty()) || it.canWriteText || getBed() || it.m_transformOnUse;
}

SoundEffect_t Item::getMovementSound(Cylinder* toCylinder) const {
if (!toCylinder) {
return SoundEffect_t::ITEM_MOVE_DEFAULT;
Expand Down
2 changes: 2 additions & 0 deletions src/items/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ class Item : virtual public Thing, public ItemProperties {
return nullptr;
}

bool isSavedToHouses() const;

SoundEffect_t getMovementSound(Cylinder* toCylinder) const;

void setIsLootTrackeable(bool value) {
Expand Down