Просмотр исходного кода

Follow up e7b654a. Fixed changes for bugreport:9062 wasn't staged there

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
Cydh Ramdh 11 лет назад
Родитель
Сommit
22dea1f600
4 измененных файлов с 58 добавлено и 56 удалено
  1. 48 45
      src/map/itemdb.c
  2. 7 7
      src/map/itemdb.h
  3. 1 1
      src/map/mob.c
  4. 2 3
      src/map/pc.c

+ 48 - 45
src/map/itemdb.c

@@ -87,12 +87,10 @@ struct item_data* itemdb_searchname(const char *str)
 static int itemdb_searchname_array_sub(DBKey key, DBData data, va_list ap)
 {
 	struct item_data *item = db_data2ptr(&data);
-	char *str;
-	str = va_arg(ap,char *);
+	char *str = va_arg(ap,char *);
 
 	if (item && dummy_item)
 		return 1;
-
 	if (stristr(item->jname,str))
 		return 0;
 	if (stristr(item->name,str))
@@ -378,7 +376,7 @@ static void itemdb_jobid2mapid(unsigned int *bclass, unsigned int jobmask)
 /**
 * Create dummy item data
 */
-static void create_dummy_data(void) {
+static void itemdb_create_dummy(void) {
 	CREATE(dummy_item, struct item_data, 1);
 
 	memset(dummy_item, 0, sizeof(struct item_data));
@@ -392,18 +390,34 @@ static void create_dummy_data(void) {
 	idb_put(itemdb, dummy_item->nameid, dummy_item);
 }
 
+/**
+* Create new item data
+* @param nameid
+*/
+static struct item_data *itemdb_create_item(unsigned short nameid) {
+	struct item_data *id;
+	CREATE(id, struct item_data, 1);
+	memset(id, 0, sizeof(struct item_data));
+	dummy_item->nameid = nameid;
+	dummy_item->type = IT_ETC; //Etc item
+	idb_put(itemdb, nameid, id);
+	return id;
+}
+
 /*==========================================
  * Loads an item from the db. If not found, it will return the dummy item.
  * @param nameid
  * @return *item_data or *dummy_item if item not found
  *------------------------------------------*/
 struct item_data* itemdb_search(unsigned short nameid) {
-	struct item_data* id = (struct item_data*)idb_get(itemdb, nameid);
-	if (id)
-		return id;
-	if (nameid != dummy_item->nameid) // Avoid previous item that assigned with dummy_item to shows this message again
+	struct item_data* id = NULL;
+	if (nameid == dummy_item->nameid)
+		id = dummy_item;
+	else if (!(id = (struct item_data*)idb_get(itemdb, nameid))) {
 		ShowWarning("itemdb_search: Item ID %hu does not exists in the item_db. Using dummy data.\n", nameid);
-	return dummy_item;
+		id = dummy_item;
+	}
+	return id;
 }
 
 /** Checks if item is equip type or not
@@ -565,12 +579,11 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 	while (fgets(line,sizeof(line),fp)) {
 		int group_id = -1;
 		unsigned int j, prob = 1;
-		unsigned short nameid;
-		uint16 amt = 1, dur = 0;
 		uint8 rand_group = 1;
-		char *str[9], *p, announced = 0, named = 0, bound = BOUND_NONE;
+		char *str[9], *p;
 		struct s_item_group_random *random = NULL;
 		struct s_item_group_db *group = NULL;
+		struct s_item_group_entry entry;
 		bool found = false;
 
 		ln++;
@@ -600,6 +613,10 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 			continue;
 		}
 
+		memset(&entry, 0, sizeof(entry));
+		entry.amount = 1;
+		entry.bound = BOUND_NONE;
+
 		// Checking group_id
 		trim(str[0]);
 		if (ISDIGIT(str[0][0]))
@@ -614,7 +631,8 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 
 		// Checking sub group
 		prob = atoi(str[2]);
-		if (str[4] != NULL) rand_group = atoi(str[4]);
+		if (str[4] != NULL)
+			rand_group = atoi(str[4]);
 		if (rand_group < 0 || rand_group > MAX_ITEMGROUP_RANDGROUP) {
 			ShowWarning("itemdb_read_itemgroup: Invalid sub group '%d' for group '%s' in %s:%d\n", rand_group, str[0], filename, ln);
 			continue;
@@ -628,13 +646,13 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 		// Checking item
 		trim(str[1]);
 		if (ISDIGIT(str[1][0])) {
-			if (itemdb_exists((nameid = atoi(str[1]))))
+			if (itemdb_exists((entry.nameid = atoi(str[1]))))
 				found = true;
 		}
 		else {
 			struct item_data *id = itemdb_searchname(str[1]);
 			if (id) {
-				nameid = id->nameid;
+				entry.nameid = id->nameid;
 				found = true;
 			}
 		}
@@ -643,17 +661,16 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 			continue;
 		}
 
-		if (str[3] != NULL) amt = cap_value(atoi(str[3]),1,MAX_AMOUNT);
-		if (str[5] != NULL) announced = atoi(str[5]);
-		if (str[6] != NULL) dur = cap_value(atoi(str[6]),0,UINT16_MAX);
-		if (str[7] != NULL) named = atoi(str[7]);
-		if (str[8] != NULL) bound = cap_value(atoi(str[8]),BOUND_NONE,BOUND_MAX-1);
+		if (str[3] != NULL) entry.amount = cap_value(atoi(str[3]),1,MAX_AMOUNT);
+		if (str[5] != NULL) entry.isAnnounced= atoi(str[5]);
+		if (str[6] != NULL) entry.duration = cap_value(atoi(str[6]),0,UINT16_MAX);
+		if (str[7] != NULL) entry.isNamed = atoi(str[7]);
+		if (str[8] != NULL) entry.bound = cap_value(atoi(str[8]),BOUND_NONE,BOUND_MAX-1);
 
-		found = true;
 		if (!(group = (struct s_item_group_db *) idb_get(itemdb_group, group_id))) {
-			found = false;
 			CREATE(group, struct s_item_group_db, 1);
 			group->id = group_id;
+			idb_put(itemdb_group, group->id, group);
 		}
 
 		// Must item (rand_group == 0), place it here
@@ -664,17 +681,11 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 			else
 				RECREATE(group->must, struct s_item_group_entry, idx+1);
 
-			group->must[idx].nameid = nameid;
-			group->must[idx].amount = amt;
-			group->must[idx].isAnnounced = announced;
-			group->must[idx].duration = dur;
-			group->must[idx].isNamed = named;
-			group->must[idx].bound = bound;
+			group->must[idx] = entry;
 			group->must_qty++;
+
 			// If 'must' item isn't set as random item, skip the next process
 			if (!prob) {
-				if (!found)
-					idb_put(itemdb_group, group->id, group);
 				entries++;
 				continue;
 			}
@@ -693,19 +704,11 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 		else
 			RECREATE(random->data, struct s_item_group_entry, random->data_qty+prob);
 
-		//Now put the entry to its rand_group
-		for (j = random->data_qty; j < random->data_qty+prob; j++) {
-			random->data[j].nameid = nameid;
-			random->data[j].amount = amt;
-			random->data[j].isAnnounced = announced;
-			random->data[j].duration = dur;
-			random->data[j].isNamed = named;
-			random->data[j].bound = bound;
-		}
-		random->data_qty += prob;
+		// Put the entry to its rand_group
+		for (j = random->data_qty; j < random->data_qty+prob; j++)
+			random->data[j] = entry;
 
-		if (!found)
-			idb_put(itemdb_group, group->id, group);
+		random->data_qty += prob;
 		entries++;
 	}
 	fclose(fp);
@@ -1130,7 +1133,7 @@ static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scr
 	unsigned short nameid;
 	struct item_data* id;
 
-	if( atoi(str[0]) <= 0 || atoi(str[0]) >= MAX_ITEMID )
+	if( atoi(str[0]) <= 0 || atoi(str[0]) >= MAX_ITEMID || atoi(str[0]) == dummy_item->nameid )
 	{
 		ShowWarning("itemdb_parse_dbrow: Invalid id %d in line %d of \"%s\", skipping.\n", atoi(str[0]), line, source);
 		return false;
@@ -1139,7 +1142,7 @@ static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scr
 
 	//ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Job Upper,Gender,Loc,wLV,eLV,refineable,View
 	if (!(id = itemdb_exists(nameid)))
-		CREATE(id, struct item_data, 1);
+		id = itemdb_create_item(nameid);
 
 	safestrncpy(id->name, str[1], sizeof(id->name));
 	safestrncpy(id->jname, str[2], sizeof(id->jname));
@@ -1697,6 +1700,6 @@ void do_init_itemdb(void) {
 	itemdb = idb_alloc(DB_OPT_BASE);
 	itemdb_combo = idb_alloc(DB_OPT_BASE);
 	itemdb_group = idb_alloc(DB_OPT_BASE);
-	create_dummy_data(); //Dummy data item.	
+	itemdb_create_dummy(); //Dummy data item.	
 	itemdb_read();
 }

+ 7 - 7
src/map/itemdb.h

@@ -329,8 +329,8 @@ struct item_combo {
 /// Struct of item group entry
 struct s_item_group_entry {
 	unsigned short nameid, /// Item ID
-		duration; /// Duration if item as rental item (in minutes)
-	uint16 amount; /// Amount of item will be obtained
+		duration, /// Duration if item as rental item (in minutes)
+		amount; /// Amount of item will be obtained
 	bool isAnnounced, /// Broadcast if player get this item
 		isNamed; /// Named the item (if possible)
 	char bound; /// Makes the item as bound item (according to bound type)
@@ -338,15 +338,15 @@ struct s_item_group_entry {
 
 /// Struct of random group
 struct s_item_group_random {
-	struct s_item_group_entry *data;
-	uint16 data_qty;
+	struct s_item_group_entry *data; /// Random group entry
+	unsigned short data_qty; /// Number of item in random group
 };
 
 /// Struct of item group that will be used for db
 struct s_item_group_db {
-	uint16 id;
-	struct s_item_group_entry *must;
-	uint16 must_qty;
+	unsigned short id, /// Item Group ID
+		must_qty; /// Number of must item at this group
+	struct s_item_group_entry *must; /// Must item entry
 	struct s_item_group_random random[MAX_ITEMGROUP_RANDGROUP]; //! TODO: Move this fixed array to dynamic size if needed.
 };
 

+ 1 - 1
src/map/mob.c

@@ -2436,7 +2436,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 			for (i = 0; i < ARRAYLENGTH(sd->add_drop); i++) {
 				if (!&sd->add_drop[i] || (!sd->add_drop[i].nameid && !sd->add_drop[i].group))
 					continue;
-				if ((sd->add_drop[i].race < RC_NONE_ && sd->add_drop[i].race == -md->mob_id) || //Race < 0, use mob_id
+				if ((sd->add_drop[i].race < RC_NONE_ && sd->add_drop[i].race == -md->mob_id) || //Race < RC_NONE_, use mob_id
 					(sd->add_drop[i].race == RC_ALL || sd->add_drop[i].race == status->race) || //Matched race
 					(sd->add_drop[i].class_ == CLASS_ALL || sd->add_drop[i].class_ == status->class_)) //Matched class
 				{

+ 2 - 3
src/map/pc.c

@@ -1552,9 +1552,8 @@ void pc_calc_skilltree(struct map_session_data *sd)
 	if ((sd->class_&MAPID_UPPERMASK) != MAPID_TAEKWON) {
 		uint16 c_ = pc_class2idx(JOB_TAEKWON);
 		for (i = 0; i < MAX_SKILL_TREE; i++) {
-			uint16 x = skill_get_index(skill_tree[c_][i].id);
-			uint16 skid;
-			if ((skid = sd->status.skill[x].id)) {
+			uint16 x = skill_get_index(skill_tree[c_][i].id), skid = sd->status.skill[x].id;
+			if (skid && x > 0 && sd->status.skill[x].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[x].flag != SKILL_FLAG_PERM_GRANTED) {
 				if (skid == NV_BASIC || skid == NV_FIRSTAID || skid == WE_CALLBABY)
 					continue;
 				sd->status.skill[x].id = 0;