Fixes mob and item atcommand sorting issues (#7058)
* Fixes #7055. * Fixes several atcommands used for mob and item information were not properly accounting for order. * Resolves an issue where YAML databases were not properly utilizing the cache feature. * Increased MAX_SEARCH to 10 by default as in renewal there are many more items with duplicated names. Thanks to @Playtester! Co-authored-by: Playtester <Kenji.Ito@gmx.de>
This commit is contained in:
parent
563a7012ff
commit
256735a136
@ -166,6 +166,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<datatype>> getCache() {
|
||||
return this->cache;
|
||||
}
|
||||
|
||||
virtual size_t calculateCacheKey( keytype key ){
|
||||
return key;
|
||||
}
|
||||
|
@ -365,6 +365,8 @@ void AchievementDatabase::loadingFinished(){
|
||||
|
||||
ach->dependent_ids.shrink_to_fit();
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
AchievementDatabase achievement_db;
|
||||
|
@ -3912,7 +3912,7 @@ ACMD_FUNC(mapexit)
|
||||
ACMD_FUNC(idsearch)
|
||||
{
|
||||
char item_name[100];
|
||||
unsigned int i, match;
|
||||
uint16 i, match;
|
||||
struct item_data *item_array[MAX_SEARCH];
|
||||
nullpo_retr(-1, sd);
|
||||
|
||||
@ -7613,8 +7613,7 @@ ACMD_FUNC(mobinfo)
|
||||
unsigned char melement[ELE_ALL][8] = { "Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead" };
|
||||
char atcmd_output2[CHAT_SIZE_MAX];
|
||||
struct item_data *item_data;
|
||||
uint16 mob_ids[MAX_SEARCH];
|
||||
int count;
|
||||
uint16 mob_ids[MAX_SEARCH], count;
|
||||
int i, k;
|
||||
|
||||
memset(atcmd_output, '\0', sizeof(atcmd_output));
|
||||
@ -8151,7 +8150,7 @@ ACMD_FUNC(homshuffle)
|
||||
ACMD_FUNC(iteminfo)
|
||||
{
|
||||
struct item_data *item_array[MAX_SEARCH];
|
||||
int i, count = 1;
|
||||
uint16 i, count = 1;
|
||||
|
||||
if (!message || !*message) {
|
||||
clif_displaymessage(fd, msg_txt(sd,1276)); // Please enter an item name/ID (usage: @ii/@iteminfo <item name/ID>).
|
||||
@ -8202,7 +8201,7 @@ ACMD_FUNC(iteminfo)
|
||||
ACMD_FUNC(whodrops)
|
||||
{
|
||||
struct item_data *item_data, *item_array[MAX_SEARCH];
|
||||
int i,j, count = 1;
|
||||
uint16 i, j, count = 1;
|
||||
|
||||
if (!message || !*message) {
|
||||
clif_displaymessage(fd, msg_txt(sd,1284)); // Please enter item name/ID (usage: @whodrops <item name/ID>).
|
||||
@ -8257,8 +8256,7 @@ ACMD_FUNC(whodrops)
|
||||
|
||||
ACMD_FUNC(whereis)
|
||||
{
|
||||
uint16 mob_ids[MAX_SEARCH] = {0};
|
||||
int count = 0;
|
||||
uint16 mob_ids[MAX_SEARCH] = {0}, count;
|
||||
|
||||
if (!message || !*message) {
|
||||
clif_displaymessage(fd, msg_txt(sd,1288)); // Please enter a monster name/ID (usage: @whereis <monster_name_or_monster_ID>).
|
||||
|
@ -1168,6 +1168,8 @@ void ItemDatabase::loadingFinished(){
|
||||
|
||||
item_db.put( ITEMID_DUMMY, dummy_item );
|
||||
}
|
||||
|
||||
TypesafeCachedYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1668,14 +1670,17 @@ LaphineUpgradeDatabase laphine_upgrade_db;
|
||||
* @param str
|
||||
* @return Number of matches item
|
||||
*------------------------------------------*/
|
||||
int itemdb_searchname_array(struct item_data** data, int size, const char *str)
|
||||
uint16 itemdb_searchname_array(struct item_data** data, uint16 size, const char *str)
|
||||
{
|
||||
int count = 0;
|
||||
uint16 count = 0;
|
||||
const auto &item_list = item_db.getCache();
|
||||
|
||||
for (const auto &it : item_db) {
|
||||
for (const auto &item : item_list) {
|
||||
if (item == nullptr)
|
||||
continue;
|
||||
if (count < size) {
|
||||
if (stristr(it.second->name.c_str(), str) != nullptr || stristr(it.second->ename.c_str(), str) != nullptr || strcmpi(it.second->ename.c_str(), str) == 0)
|
||||
data[count++] = it.second.get();
|
||||
if (stristr(item->name.c_str(), str) != nullptr || stristr(item->ename.c_str(), str) != nullptr || strcmpi(item->ename.c_str(), str) == 0)
|
||||
data[count++] = item.get();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
@ -2351,6 +2356,8 @@ void ItemGroupDatabase::loadingFinished() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
/** Read item forbidden by mapflag (can't equip item)
|
||||
@ -2527,6 +2534,8 @@ void ComboDatabase::loadingFinished() {
|
||||
it->combos.push_back(combo.second);
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3115,6 +3124,8 @@ void RandomOptionDatabase::loadingFinished(){
|
||||
|
||||
script_set_constant( name.c_str(), pair.first, false, false );
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
RandomOptionDatabase random_option_db;
|
||||
|
@ -22,7 +22,9 @@ const t_itemid UNKNOWN_ITEM_ID = 512;
|
||||
/// The maximum number of item delays
|
||||
#define MAX_ITEMDELAYS 10
|
||||
///Designed for search functions, species max number of matches to display.
|
||||
#define MAX_SEARCH 5
|
||||
#ifndef MAX_SEARCH
|
||||
#define MAX_SEARCH 10
|
||||
#endif
|
||||
|
||||
#define MAX_ROULETTE_LEVEL 7 /** client-defined value **/
|
||||
#define MAX_ROULETTE_COLUMNS 9 /** client-defined value **/
|
||||
@ -1360,7 +1362,7 @@ public:
|
||||
|
||||
extern LaphineUpgradeDatabase laphine_upgrade_db;
|
||||
|
||||
int itemdb_searchname_array(struct item_data** data, int size, const char *str);
|
||||
uint16 itemdb_searchname_array(struct item_data** data, uint16 size, const char *str);
|
||||
struct item_data* itemdb_search(t_itemid nameid);
|
||||
struct item_data* itemdb_exists(t_itemid nameid);
|
||||
#define itemdb_name(n) itemdb_search(n)->name.c_str()
|
||||
|
@ -315,14 +315,17 @@ std::shared_ptr<s_mob_db> mobdb_search_aegisname( const char* str ){
|
||||
/*==========================================
|
||||
* Founds up to N matches. Returns number of matches [Skotlex]
|
||||
*------------------------------------------*/
|
||||
int mobdb_searchname_array_(const char *str, uint16 * out, int size, bool full_cmp)
|
||||
uint16 mobdb_searchname_array_(const char *str, uint16 * out, uint16 size, bool full_cmp)
|
||||
{
|
||||
unsigned short count = 0;
|
||||
for( auto const &mobdb_pair : mob_db ) {
|
||||
const uint16 mob_id = mobdb_pair.first;
|
||||
if( mobdb_searchname_sub(mob_id, str, full_cmp) ) {
|
||||
uint16 count = 0;
|
||||
const auto &mob_list = mob_db.getCache();
|
||||
|
||||
for( const auto &mob : mob_list ) {
|
||||
if (mob == nullptr)
|
||||
continue;
|
||||
if( mobdb_searchname_sub(mob->id, str, full_cmp) ) {
|
||||
if( count < size )
|
||||
out[count] = mob_id;
|
||||
out[count] = mob->id;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@ -330,7 +333,7 @@ int mobdb_searchname_array_(const char *str, uint16 * out, int size, bool full_c
|
||||
return count;
|
||||
}
|
||||
|
||||
int mobdb_searchname_array(const char *str, uint16 * out, int size)
|
||||
uint16 mobdb_searchname_array(const char *str, uint16 * out, uint16 size)
|
||||
{
|
||||
return mobdb_searchname_array_(str, out, size, false);
|
||||
}
|
||||
@ -4974,6 +4977,8 @@ void MobDatabase::loadingFinished() {
|
||||
mob->status.hp = mob->status.max_hp;
|
||||
mob->status.sp = mob->status.max_sp;
|
||||
}
|
||||
|
||||
TypesafeCachedYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
MobDatabase mob_db;
|
||||
|
@ -447,7 +447,7 @@ struct item_drop_list {
|
||||
|
||||
uint16 mobdb_searchname(const char * const str);
|
||||
std::shared_ptr<s_mob_db> mobdb_search_aegisname( const char* str );
|
||||
int mobdb_searchname_array(const char *str, uint16 * out, int size);
|
||||
uint16 mobdb_searchname_array(const char *str, uint16 * out, uint16 size);
|
||||
int mobdb_checkid(const int id);
|
||||
struct view_data* mob_get_viewdata(int mob_id);
|
||||
void mob_set_dynamic_viewdata( struct mob_data* md );
|
||||
|
@ -833,6 +833,8 @@ void BarterDatabase::loadingFinished(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
BarterDatabase barter_db;
|
||||
|
@ -357,6 +357,8 @@ void PenaltyDatabase::loadingFinished(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
PenaltyDatabase penalty_db;
|
||||
@ -12990,6 +12992,8 @@ void SkillTreeDatabase::loadingFinished() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -13546,6 +13550,8 @@ void JobDatabase::loadingFinished() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeCachedYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -13708,6 +13714,8 @@ void PlayerStatPointDatabase::loadingFinished(){
|
||||
// Store it for next iteration
|
||||
last_level = entry;
|
||||
}
|
||||
|
||||
TypesafeCachedYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
/*==========================================
|
||||
|
@ -304,6 +304,8 @@ void PlayerGroupDatabase::loadingFinished(){
|
||||
|
||||
// Initialize command cache
|
||||
atcommand_db_load_groups();
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
PlayerGroupDatabase player_group_db;
|
||||
|
@ -24022,6 +24022,8 @@ void SkillDatabase::loadingFinished(){
|
||||
if( this->skill_num > MAX_SKILL ){
|
||||
ShowError( "There are more skills defined in the skill database (%d) than the MAX_SKILL (%d) define. Please increase it and recompile.\n", this->skill_num, MAX_SKILL );
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -933,6 +933,8 @@ void EnchantgradeDatabase::loadingFinished(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
EnchantgradeDatabase enchantgrade_db;
|
||||
@ -15542,6 +15544,8 @@ void StatusDatabase::loadingFinished(){
|
||||
this->StatusRelevantBLTypes[status->icon] = BL_PC;
|
||||
}
|
||||
}
|
||||
|
||||
TypesafeYamlDatabase::loadingFinished();
|
||||
}
|
||||
|
||||
StatusDatabase status_db;
|
||||
|
Loading…
x
Reference in New Issue
Block a user