Browse Source

- Changed function itemdb_group to itemdb_group_bonus, it now calculates the total group bonuses of a player for a given item.
- Changed itemhealrate to itemgrouphealrate, added a structure itemhealrate to allow storing item-healing bonuses per item.
- Modified bAddItemHealRate so it can receive both item-id and item-group values (since the first item-id is +500, there's no risk of mixing them up).


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@8136 54d463be-8e91-2dee-dedb-b68131a5f0ec

skotlex 19 năm trước cách đây
mục cha
commit
04edacd3d9
7 tập tin đã thay đổi với 48 bổ sung33 xóa
  1. 3 0
      Changelog-Trunk.txt
  2. 3 1
      doc/item_bonus.txt
  3. 11 22
      src/map/itemdb.c
  4. 1 1
      src/map/itemdb.h
  5. 5 1
      src/map/map.h
  6. 23 7
      src/map/pc.c
  7. 2 1
      src/map/status.c

+ 3 - 0
Changelog-Trunk.txt

@@ -3,6 +3,9 @@ Date	Added
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 2006/08/04
+	* Modified bAddItemHealRate so it can receive both item-id and item-group
+	  values (since the first item-id is +500, there's no risk of mixing them
+	  up). [Skotlex]
 	* Removed settings enemy_critical_rate, homun_critical_rate. Added settings
 	  enable_critical (defaults to specify only players), mob_critical_rate and
 	  critical_rate. The last applies to all non-mobs and non-players

+ 3 - 1
doc/item_bonus.txt

@@ -183,7 +183,9 @@ bonus4 bAutoSpellWhenHit,x,y,n,i;	n/10% chance to cast skill x of level y when
 
 //---- 2/22 new card effects ----
 
-bonus2 bAddItemHealRate,n,x;		Increases HP recovered by n type items by x%
+bonus2 bAddItemHealRate,n,x;		Increases HP recovered by n type items by x%,
+                                        you can also use direct item IDs instead
+                                        of group values.
                                         (Check db/item_group_db.txt)
 
 //---- 3/15 new card effects ----

+ 11 - 22
src/map/itemdb.c

@@ -111,36 +111,25 @@ int itemdb_searchrandomid(int group)
 		ShowError("itemdb_searchrandomid: No item entries for group id %d\n", group);
 	return UNKNOWN_ITEM_ID;
 }
-
 /*==========================================
- * Returns the group this item belongs to.
- * Skips general random item givers (gift/blue/violet box)
+ * Calculates total item-group related bonuses for the given item. [Skotlex]
  *------------------------------------------
  */
-int itemdb_group (int nameid)
+int itemdb_group_bonus(struct map_session_data *sd, int itemid)
 {
-	int i, j;
+	int bonus = 0, i, j;
 	for (i=0; i < MAX_ITEMGROUP; i++) {
-		switch (i) {
-			case IG_BLUEBOX:
-			case IG_VIOLETBOX:
-			case IG_CARDALBUM:
-			case IG_GIFTBOX:
-			case IG_COOKIEBAG:
-			case IG_GIFTBOX_1:
-			case IG_GIFTBOX_2:
-			case IG_GIFTBOX_3:
-			case IG_GIFTBOX_4:
-			case IG_GIFTBOXCHINA:
-				continue;
-		}
-
+		if (!sd->itemgrouphealrate[i])
+			continue;
 		for (j=0; j < itemgroup_db[i].qty; j++) {
-			if (itemgroup_db[i].id[j] == nameid)
-				return i;
+			if (itemgroup_db[i].id[j] == itemid)
+		 	{
+				bonus += sd->itemgrouphealrate[i];
+				continue;
+			}
 		}
 	}
-	return -1;
+	return bonus;
 }
 
 /*==========================================

+ 1 - 1
src/map/itemdb.h

@@ -104,7 +104,7 @@ struct item_data* itemdb_exists(int nameid);
 #define itemdb_available(n) (itemdb_exists(n) && itemdb_search(n)->flag.available)
 #define itemdb_viewid(n) (itemdb_search(n)->view_id)
 #define itemdb_autoequip(n) (itemdb_search(n)->flag.autoequip)
-int itemdb_group(int nameid);
+int itemdb_group_bonus(struct map_session_data *sd, int itemid);
 
 int itemdb_searchrandomid(int flags);
 

+ 5 - 1
src/map/map.h

@@ -629,7 +629,7 @@ struct map_session_data {
 	int magic_addsize[3];
 	int critaddrace[RC_MAX];
 	int expaddrace[RC_MAX];
-	int itemhealrate[MAX_ITEMGROUP];
+	int itemgrouphealrate[MAX_ITEMGROUP];
 	short sp_gain_race[RC_MAX];
 	// zeroed arrays end here.
 	// zeroed structures start here
@@ -651,6 +651,10 @@ struct map_session_data {
 		short id, group;
 		int race, rate;
 	} add_drop[MAX_PC_BONUS];
+	struct {
+		int nameid;
+		int rate;
+	} itemhealrate[MAX_PC_BONUS];
 	// zeroed structures end here
 	// zeroed vars start here.
 	int arrow_atk,arrow_ele,arrow_cri,arrow_hit;

+ 23 - 7
src/map/pc.c

@@ -2167,10 +2167,18 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
 	case SP_ADD_ITEM_HEAL_RATE:
 		if(sd->state.lr_flag == 2)
 			break;
-		if (type2 < MAX_ITEMGROUP)
-			sd->itemhealrate[type2] += val;
-		else
-			ShowWarning("pc_bonus2: AddItemHealRate: Group %d is beyond limit (%d).\n", type2, MAX_ITEMGROUP);
+		if (type2 < MAX_ITEMGROUP) {	//Group bonus
+			sd->itemgrouphealrate[type2] += val;
+			break;
+		}
+		//Standard item bonus.
+		for(i=0; i < MAX_PC_BONUS && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++);
+		if(i == MAX_PC_BONUS) {
+			ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", MAX_PC_BONUS);
+			break;
+		}
+		sd->itemhealrate[i].nameid = type2;
+		sd->itemhealrate[i].rate += val;
 		break;
 	case SP_EXP_ADDRACE:
 		if(sd->state.lr_flag != 2)
@@ -5329,7 +5337,7 @@ void pc_heal(struct map_session_data *sd,unsigned int hp,unsigned int sp, int ty
  */
 int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
 {
-	int bonus, type;
+	int i, bonus;
 
 	if(hp) {
 		bonus = 100 + (sd->battle_status.vit<<1)
@@ -5337,8 +5345,16 @@ int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
 			+ pc_checkskill(sd,AM_LEARNINGPOTION)*5;
 		// A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
 		bonus += (potion_flag==2)?50:(potion_flag==3?100:0);
-		if ((type = itemdb_group(itemid)) > 0 && type < MAX_ITEMGROUP && sd->itemhealrate[type])
-			bonus += bonus * sd->itemhealrate[type] / 100;
+		//Item Group bonuses
+		bonus += bonus*itemdb_group_bonus(sd, itemid)/100;
+		//Individual item bonuses.
+		for(i = 0; i < MAX_PC_BONUS && sd->itemhealrate[i].nameid; i++)
+		{
+			if (sd->itemhealrate[i].nameid == itemid) {
+				bonus += bonus*sd->itemhealrate[i].rate/100;
+				break;
+			}
+		}
 		if(bonus!=100)
 			hp = hp * bonus / 100;
 	}

+ 2 - 1
src/map/status.c

@@ -1539,7 +1539,7 @@ int status_calc_pc(struct map_session_data* sd,int first)
 		+ sizeof(sd->magic_addsize)
 		+ sizeof(sd->critaddrace)
 		+ sizeof(sd->expaddrace)
-		+ sizeof(sd->itemhealrate)
+		+ sizeof(sd->itemgrouphealrate)
 		+ sizeof(sd->sp_gain_race)
 		);
 
@@ -1578,6 +1578,7 @@ int status_calc_pc(struct map_session_data* sd,int first)
 		+ sizeof(sd->add_dmg)
 		+ sizeof(sd->add_mdmg)
 		+ sizeof(sd->add_drop)
+		+ sizeof(sd->itemhealrate)
 	);
 	
 	// vars zeroing. ints, shorts, chars. in that order.