Pārlūkot izejas kodu

- Mercenary Loyalty Updates.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@13176 54d463be-8e91-2dee-dedb-b68131a5f0ec
zephyrus 16 gadi atpakaļ
vecāks
revīzija
8752909a84
3 mainītis faili ar 54 papildinājumiem un 17 dzēšanām
  1. 43 12
      src/map/mercenary.c
  2. 1 0
      src/map/mercenary.h
  3. 10 5
      src/map/mob.c

+ 43 - 12
src/map/mercenary.c

@@ -117,7 +117,7 @@ int mercenary_get_faith(struct mercenary_data *md)
 int mercenary_set_faith(struct mercenary_data *md, int value)
 {
 	struct map_session_data *sd;
-	int class_;
+	int class_, *faith;
 
 	if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
 		return 0;
@@ -125,11 +125,15 @@ int mercenary_set_faith(struct mercenary_data *md, int value)
 	class_ = md->db->class_;
 
 	if( class_ >= 6017 && class_ <= 6026 )
-		sd->status.arch_faith += value;
+		faith = &sd->status.arch_faith;
 	else if( class_ >= 6027 && class_ <= 6036 )
-		sd->status.spear_faith += value;
+		faith = &sd->status.spear_faith;
 	else if( class_ >= 6037 && class_ <= 6046 )
-		sd->status.sword_faith += value;
+		faith = &sd->status.sword_faith;
+
+	*faith += value;
+	*faith = cap_value(*faith, 0, SHRT_MAX);
+	clif_mercenary_updatestatus(sd, SP_MERCFAITH);
 
 	return 0;
 }
@@ -157,7 +161,7 @@ int mercenary_get_calls(struct mercenary_data *md)
 int mercenary_set_calls(struct mercenary_data *md, int value)
 {
 	struct map_session_data *sd;
-	int class_;
+	int class_, *calls;
 
 	if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
 		return 0;
@@ -165,11 +169,14 @@ int mercenary_set_calls(struct mercenary_data *md, int value)
 	class_ = md->db->class_;
 
 	if( class_ >= 6017 && class_ <= 6026 )
-		sd->status.arch_calls += value;
+		calls = &sd->status.arch_calls;
 	else if( class_ >= 6027 && class_ <= 6036 )
-		sd->status.spear_calls += value;
+		calls = &sd->status.spear_calls;
 	else if( class_ >= 6037 && class_ <= 6046 )
-		sd->status.sword_calls += value;
+		calls = &sd->status.sword_calls;
+
+	*calls += value;
+	*calls = cap_value(*calls, 0, INT_MAX);
 
 	return 0;
 }
@@ -215,8 +222,14 @@ int merc_delete(struct mercenary_data *md, int reply)
 
 	if( !sd )
 		return unit_free(&md->bl, 0);
+
+	switch( reply )
+	{
+		case 0: mercenary_set_faith(md, 1); break; // +1 Loyalty on Contract ends.
+		case 1: mercenary_set_faith(md, -1); break; // -1 Loyalty on Mercenary killed
+	}
+
 	clif_mercenary_message(sd->fd, reply);
-	
 	return unit_remove_map(&md->bl, 0);
 }
 
@@ -251,9 +264,7 @@ int merc_data_received(struct s_mercenary *merc, bool flag)
 		return 0;
 	}
 
-	sd->status.mer_id = merc->mercenary_id;
 	db = &mercenary_db[i];
-
 	if( !sd->md )
 	{
 		sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data));
@@ -281,9 +292,15 @@ int merc_data_received(struct s_mercenary *merc, bool flag)
 		merc_contract_init(md);
 	}
 	else
+	{
 		memcpy(&sd->md->mercenary, merc, sizeof(struct s_mercenary));
+		md = sd->md;
+	}
+
+	if( sd->status.mer_id == 0 )
+		mercenary_set_calls(md, 1);
+	sd->status.mer_id = merc->mercenary_id;
 
-	md = sd->md;
 	if( md && md->bl.prev == NULL && sd->bl.prev != NULL )
 	{
 		map_addblock(&md->bl);
@@ -314,6 +331,20 @@ int mercenary_dead(struct mercenary_data *md, struct block_list *src)
 	return 0;
 }
 
+int mercenary_kills(struct mercenary_data *md)
+{
+	md->mercenary.kill_count++;
+	md->mercenary.kill_count = cap_value(md->mercenary.kill_count, 0, INT_MAX);
+
+	if( (md->mercenary.kill_count % 50) == 0 )
+		mercenary_set_faith(md, 1);
+
+	if( md->master )
+		clif_mercenary_updatestatus(md->master, SP_MERCKILLS);
+
+	return 0;
+}
+
 int read_mercenarydb(void)
 {
 	FILE *fp;

+ 1 - 0
src/map/mercenary.h

@@ -55,6 +55,7 @@ int mercenary_get_faith(struct mercenary_data *md);
 int mercenary_set_faith(struct mercenary_data *md, int value);
 int mercenary_get_calls(struct mercenary_data *md);
 int mercenary_set_calls(struct mercenary_data *md, int value);
+int mercenary_kills(struct mercenary_data *md);
 
 int do_init_mercenary(void);
 

+ 10 - 5
src/map/mob.c

@@ -1921,16 +1921,18 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 	if(src && src->type == BL_MOB)
 		mob_unlocktarget((struct mob_data *)src,tick);
 
-	if(sd) {
+	if( sd )
+	{
 		int sp = 0, hp = 0;
 		sp += sd->sp_gain_value;
 		sp += sd->sp_gain_race[status->race];
 		sp += sd->sp_gain_race[status->mode&MD_BOSS?RC_BOSS:RC_NONBOSS];
 		hp += sd->hp_gain_value;
-		if (hp||sp)
+		if( hp || sp )
 			status_heal(src, hp, sp, battle_config.show_hp_sp_gain?2:0);
-		if (sd->mission_mobid == md->class_) { //TK_MISSION [Skotlex]
-			if (++sd->mission_count >= 100 && (temp = mob_get_random_id(0, 0xE, sd->status.base_level)))
+		if( sd->mission_mobid == md->class_)
+		{ //TK_MISSION [Skotlex]
+			if( ++sd->mission_count >= 100 && (temp = mob_get_random_id(0, 0xE, sd->status.base_level)) )
 			{
 				pc_addfame(sd, 1);
 				sd->mission_mobid = temp;
@@ -1940,6 +1942,8 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 			}
 			pc_setglobalreg(sd,"TK_MISSION_COUNT", sd->mission_count);
 		}
+		if( sd->md && (md->level > sd->status.base_level / 2) )
+			mercenary_kills(sd->md);
 	}
 
 	// filter out entries not eligible for exp distribution
@@ -3501,7 +3505,8 @@ static bool mob_parse_dbrow(char** str)
 		db->dropitem[i].p = mob_drop_adjust(rate, rate_adjust, ratemin, ratemax);
 		
 		//calculate and store Max available drop chance of the item
-		if (db->dropitem[i].p && (class_ < 1324 || class_ > 1363) && (class_ < 1938 || class_ > 1946) { //Skip treasure chests.
+		if( db->dropitem[i].p && (class_ < 1324 || class_ > 1363) && (class_ < 1938 || class_ > 1946) )
+		{ //Skip treasure chests.
 			id = itemdb_search(db->dropitem[i].nameid);
 			if (id->maxchance == 10000 || (id->maxchance < db->dropitem[i].p) ) {
 				id->maxchance = db->dropitem[i].p; //item has bigger drop chance or sold in shops