- Added functions mobdb_searchname_array and itemdb_searchname_array which return an array of matches.

- Modified @iteminfo and @mobinfo to search and display various matches instead of just one.
- Constant MAX_SEARCH in map.h defines the max size of search results.


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@5512 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
skotlex 2006-03-08 15:16:48 +00:00
parent d4e9bcf863
commit fbda66933a
9 changed files with 168 additions and 81 deletions

View File

@ -4,6 +4,10 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. EVERYTHING ELSE
GOES INTO TRUNK AND WILL BE MERGED INTO STABLE BY VALARIS AND WIZPUTER. -- VALARIS
2006/03/08
* Modified atcommands @mobinfo and @iteminfo to display multiple matches
instead of just one. Max number of matches to display is set in map.h
(MAX_SEARCH) which is currently 5. [Skotlex]
2006/03/07
* Base for ninja/gunslinger is mostly done. need to work on skills now. [Vicious]
- Updated sql-files/ mob_db.sql and item_db.sql to current txt dbs. [Skotlex]

View File

@ -275,7 +275,7 @@
266: Some of your items cannot be vended and were removed from the shop.
267: '%s' designated maps reseted!
268: Reloaded the Message of the Day.
269: Displaying first %d out of %d matches
// Guild Castles Number
// --------------------
299: ?? Castles

View File

@ -5186,7 +5186,7 @@ int atcommand_idsearch(
{
char item_name[100];
unsigned int i, match;
struct item_data *item;
struct item_data *item_array[MAX_SEARCH];
nullpo_retr(-1, sd);
memset(item_name, '\0', sizeof(item_name));
@ -5199,13 +5199,15 @@ int atcommand_idsearch(
sprintf(atcmd_output, msg_table[77], item_name); // The reference result of '%s' (name: id):
clif_displaymessage(fd, atcmd_output);
match = 0;
for(i = 0; i < 20000; i++) {
if ((item = itemdb_exists(i)) != NULL && strstr(item->jname, item_name) != NULL) {
match++;
sprintf(atcmd_output, msg_table[78], item->jname, item->nameid); // %s: %d
match = itemdb_searchname_array(item_array, MAX_SEARCH, item_name);
if (match > MAX_SEARCH) {
sprintf(atcmd_output, msg_table[269], MAX_SEARCH, match);
clif_displaymessage(fd, atcmd_output);
match = MAX_SEARCH;
}
for(i = 0; i < match; i++) {
sprintf(atcmd_output, msg_table[78], item_array[i]->jname, item_array[i]->nameid); // %s: %d
clif_displaymessage(fd, atcmd_output);
}
sprintf(atcmd_output, msg_table[79], match); // It is %d affair above.
clif_displaymessage(fd, atcmd_output);
@ -9251,9 +9253,9 @@ int atcommand_mobinfo(
unsigned char melement[11][8] = {"None", "Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead"};
char atcmd_output2[200];
struct item_data *item_data;
struct mob_db *mob;
int mob_id;
int i, j;
struct mob_db *mob, *mob_array[MAX_SEARCH];
int mob_id, count;
int i, j, k;
memset(atcmd_output, '\0', sizeof(atcmd_output));
memset(atcmd_output2, '\0', sizeof(atcmd_output2));
@ -9264,15 +9266,25 @@ int atcommand_mobinfo(
}
// If monster identifier/name argument is a name
if ((mob_id = mobdb_searchname(message)) == 0) // check name first (to avoid possible name begining by a number)
mob_id = mobdb_checkid(atoi(message));
if ((mob_id = mobdb_checkid(atoi(message))))
{
mob_array[0] = mob_db(mob_id);
count = 1;
} else
count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
if (mob_id == 0) {
if (!count) {
clif_displaymessage(fd, msg_table[40]); // Invalid monster ID or name.
return -1;
}
mob = mob_db(mob_id);
if (count > MAX_SEARCH) {
sprintf(atcmd_output, msg_table[269], MAX_SEARCH, count);
clif_displaymessage(fd, atcmd_output);
count = MAX_SEARCH;
}
for (k = 0; k < count; k++) {
mob = mob_array[k];
// stats
if (mob->mexp)
@ -9337,7 +9349,7 @@ int atcommand_mobinfo(
else
clif_displaymessage(fd, atcmd_output);
}
}
return 0;
}
@ -9353,20 +9365,28 @@ int atcommand_iteminfo(
char *itype[12] = {"Potion/Food", "BUG!", "Usable", "Etc", "Weapon", "Protection", "Card", "Egg", "Pet Acessory", "BUG!", "Arrow"};
//, "Lure/Scroll"}; No need, type 11 items are converted to type 2 upon loading [Skotlex]
struct item_data *item_data;
int item_id=0;
struct item_data *item_data, *item_array[MAX_SEARCH];
int i, item_id=0, count = 1;
if (!message || !*message) {
clif_displaymessage(fd, "Please, enter Item name or its ID (usage: @iteminfo <item_name_or_ID>).");
return -1;
}
if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
if ((item_data = itemdb_searchname(message)) != NULL ||
(item_data = itemdb_exists(atoi(message))) != NULL)
item_id = item_data->nameid;
if (item_id >= 500) {
if (!count) {
clif_displaymessage(fd, "Item not found.");
return -1;
}
if (count > MAX_SEARCH) {
sprintf(atcmd_output, msg_table[269], MAX_SEARCH, count);
clif_displaymessage(fd, atcmd_output);
count = MAX_SEARCH;
}
for (i = 0; i < MAX_SEARCH; i++) {
item_data = item_array[i];
sprintf(atcmd_output, "Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s",
item_data->name,item_data->jname,item_data->slot,item_id,
item_data->type < 12 ? itype[item_data->type] : "BUG!",

View File

@ -61,6 +61,7 @@ int itemdb_searchjname_sub(int key,void *data,va_list ap)
*dst=item;
return 0;
}
/*==========================================
*
*------------------------------------------
@ -72,6 +73,30 @@ struct item_data* itemdb_searchname(const char *str)
return item;
}
static int itemdb_searchname_array_sub(DBKey key,void * data,va_list ap)
{
struct item_data *item=(struct item_data *)data;
char *str;
str=va_arg(ap,char *);
if (item == dummy_item)
return 1; //Invalid item.
if(strstr(item->jname,str))
return 0;
if(strstr(item->name,str))
return 0;
return strcmpi(item->jname,str);
}
/*==========================================
* Founds up to N matches. Returns number of matches [Skotlex]
*------------------------------------------
*/
int itemdb_searchname_array(struct item_data** data, int size, const char *str)
{
return item_db->getall(item_db,(void**)data,size,itemdb_searchname_array_sub,str);
}
/*==========================================
*
*------------------------------------------

View File

@ -56,6 +56,7 @@ struct item_group {
};
struct item_data* itemdb_searchname(const char *name);
int itemdb_searchname_array(struct item_data** data, int size, const char *str);
struct item_data* itemdb_load(int nameid);
struct item_data* itemdb_search(int nameid);
struct item_data* itemdb_exists(int nameid);

View File

@ -51,6 +51,8 @@
#define MOBID_EMPERIUM 1288
#define MAX_PC_BONUS 10
//Designed for search functions, species max number of matches to display.
#define MAX_SEARCH 5
#define MAX_DUEL 1024
//These mark the ID of the jobs, as expected by the client. [Skotlex]

View File

@ -80,6 +80,39 @@ int mobdb_searchname(const char *str)
return 0;
}
static int mobdb_searchname_array_sub(struct mob_db* mob, const char *str)
{
if (mob == mob_dummy)
return 1; //Invalid item.
if(strstr(mob->jname,str))
return 0;
if(strstr(mob->name,str))
return 0;
return strcmpi(mob->jname,str);
}
/*==========================================
* Founds up to N matches. Returns number of matches [Skotlex]
*------------------------------------------
*/
int mobdb_searchname_array(struct mob_db** data, int size, const char *str)
{
int count = 0, i;
struct mob_db* mob;
for(i=0;i<=MAX_MOB_DB;i++){
mob = mob_db(i);
if (mob == mob_dummy)
continue;
if (!mobdb_searchname_array_sub(mob, str)) {
if (count < size)
data[count] = mob;
count++;
}
}
return count;
}
/*==========================================
* Id Mob is checked.

View File

@ -104,6 +104,7 @@ enum {
struct mob_db* mob_db(int class_);
int mobdb_searchname(const char *str);
int mobdb_searchname_array(struct mob_db** data, int size, const char *str);
int mobdb_checkid(const int id);
int mob_once_spawn(struct map_session_data *sd,char *mapname,
int x,int y,const char *mobname,int class_,int amount,const char *event);

View File

@ -5856,11 +5856,12 @@ int pc_heal(struct map_session_data *sd,int hp,int sp)
nullpo_retr(0, sd);
if(hp > 0 && pc_checkoverhp(sd))
hp = 0;
//Uneeded as the hp range adjustment below will auto-adap itself and make hp = max. [Skotlex]
// if(hp > 0 && pc_checkoverhp(sd))
// hp = 0;
if(sp > 0 && pc_checkoversp(sd))
sp = 0;
// if(sp > 0 && pc_checkoversp(sd))
// sp = 0;
if(sd->sc.count && sd->sc.data[SC_BERSERK].timer!=-1) //バ?サ?ク中は回復させないらしい
return 0;