sort bank contents before sending to client
This commit is contained in:
@@ -43,6 +43,17 @@ bool ItemData::operator!=(const ItemData& other) const {
|
|||||||
return !this->operator==(other);
|
return !this->operator==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemData::operator<(const ItemData& other) const {
|
||||||
|
for (size_t z = 0; z < 3; z++) {
|
||||||
|
if (this->data1db[z] < other.data1db[z]) {
|
||||||
|
return true;
|
||||||
|
} else if (this->data1db[z] > other.data1db[z]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (this->data2db < other.data2db);
|
||||||
|
}
|
||||||
|
|
||||||
void ItemData::clear() {
|
void ItemData::clear() {
|
||||||
this->data1d.clear(0);
|
this->data1d.clear(0);
|
||||||
this->id = 0xFFFFFFFF;
|
this->id = 0xFFFFFFFF;
|
||||||
|
|||||||
@@ -111,13 +111,17 @@ struct ItemData { // 0x14 bytes
|
|||||||
union {
|
union {
|
||||||
parray<uint8_t, 12> data1;
|
parray<uint8_t, 12> data1;
|
||||||
parray<le_uint16_t, 6> data1w;
|
parray<le_uint16_t, 6> data1w;
|
||||||
|
parray<be_uint16_t, 6> data1wb;
|
||||||
parray<le_uint32_t, 3> data1d;
|
parray<le_uint32_t, 3> data1d;
|
||||||
|
parray<be_uint32_t, 3> data1db;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
le_uint32_t id;
|
le_uint32_t id;
|
||||||
union {
|
union {
|
||||||
parray<uint8_t, 4> data2;
|
parray<uint8_t, 4> data2;
|
||||||
parray<le_uint16_t, 2> data2w;
|
parray<le_uint16_t, 2> data2w;
|
||||||
|
parray<be_uint16_t, 2> data2wb;
|
||||||
le_uint32_t data2d;
|
le_uint32_t data2d;
|
||||||
|
be_uint32_t data2db;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
ItemData();
|
ItemData();
|
||||||
@@ -128,6 +132,8 @@ struct ItemData { // 0x14 bytes
|
|||||||
bool operator==(const ItemData& other) const;
|
bool operator==(const ItemData& other) const;
|
||||||
bool operator!=(const ItemData& other) const;
|
bool operator!=(const ItemData& other) const;
|
||||||
|
|
||||||
|
bool operator<(const ItemData& other) const;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
static ItemData from_data(const std::string& data);
|
static ItemData from_data(const std::string& data);
|
||||||
|
|||||||
@@ -683,6 +683,10 @@ size_t PlayerBank::find_item(uint32_t item_id) {
|
|||||||
throw out_of_range("item not present");
|
throw out_of_range("item not present");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerBank::sort() {
|
||||||
|
std::sort(this->items.data(), this->items.data() + this->num_items);
|
||||||
|
}
|
||||||
|
|
||||||
BattleRules::BattleRules(const JSON& json) {
|
BattleRules::BattleRules(const JSON& json) {
|
||||||
static const JSON empty_list = JSON::list();
|
static const JSON empty_list = JSON::list();
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ struct PlayerBankItem {
|
|||||||
/* 14 */ le_uint16_t amount = 0;
|
/* 14 */ le_uint16_t amount = 0;
|
||||||
/* 16 */ le_uint16_t present = 0;
|
/* 16 */ le_uint16_t present = 0;
|
||||||
/* 18 */
|
/* 18 */
|
||||||
|
|
||||||
|
inline bool operator<(const PlayerBankItem& other) const {
|
||||||
|
return this->data < other.data;
|
||||||
|
}
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
struct PlayerInventory {
|
struct PlayerInventory {
|
||||||
@@ -99,6 +103,8 @@ struct PlayerBank {
|
|||||||
void add_item(const ItemData& item);
|
void add_item(const ItemData& item);
|
||||||
ItemData remove_item_by_index(size_t index, uint32_t amount);
|
ItemData remove_item_by_index(size_t index, uint32_t amount);
|
||||||
size_t find_item(uint32_t item_id);
|
size_t find_item(uint32_t item_id);
|
||||||
|
|
||||||
|
void sort();
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
struct PlayerDispDataBB;
|
struct PlayerDispDataBB;
|
||||||
|
|||||||
+2
-1
@@ -2361,7 +2361,8 @@ void send_bank(shared_ptr<Client> c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto p = c->game_data.character();
|
auto p = c->game_data.character();
|
||||||
const auto& bank = c->game_data.current_bank();
|
auto& bank = c->game_data.current_bank();
|
||||||
|
bank.sort();
|
||||||
const auto* items_it = bank.items.data();
|
const auto* items_it = bank.items.data();
|
||||||
vector<PlayerBankItem> items(items_it, items_it + bank.num_items);
|
vector<PlayerBankItem> items(items_it, items_it + bank.num_items);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user