Explorar o código

Bug Fixes
* Cleaned up the card fix calculations once more. (bugreport:8848)
* Fixed Kaite pre-renewal effect. (bugreport:6415)
* Fixed a possible crash from Elemental Action.
* Cleaned up the costume atcommand messages.
* Fixed a few issues from the CppCheck report.

aleos89 %!s(int64=11) %!d(string=hai) anos
pai
achega
d876272283
Modificáronse 7 ficheiros con 252 adicións e 260 borrados
  1. 3 3
      conf/msg_conf/map_msg.conf
  2. 3 2
      src/char/char.c
  3. 192 226
      src/map/battle.c
  4. 20 10
      src/map/clif.c
  5. 3 1
      src/map/itemdb.c
  6. 6 3
      src/map/npc.c
  7. 25 15
      src/map/skill.c

+ 3 - 3
conf/msg_conf/map_msg.conf

@@ -1562,11 +1562,11 @@
 1500: Transforming into monster is not allowed in Guild Wars.
 1500: Transforming into monster is not allowed in Guild Wars.
 
 
 // @costume
 // @costume
-1501: '%s' is not a known costume
-1502: You're already with a '%s' costume, type '@costume' to remove it.
+1501: '%s' is an unknown costume
+1502: You're already wearing a(n) '%s' costume, type '@costume' to remove it.
 1503: -- %s
 1503: -- %s
 1504: - Available Costumes
 1504: - Available Costumes
-1505: Costume '%s' removed.
+1505: '%s' Costume removed.
 
 
 //Custom translations
 //Custom translations
 //import: conf/msg_conf/import/map_msg_eng_conf.txt
 //import: conf/msg_conf/import/map_msg_eng_conf.txt

+ 3 - 2
src/char/char.c

@@ -3235,11 +3235,12 @@ int parse_frommap(int fd)
 			char_send_fame_list(fd); //Send fame list.
 			char_send_fame_list(fd); //Send fame list.
 
 
 			{
 			{
-			unsigned char buf[16384];
 			int x;
 			int x;
 			if (j == 0) {
 			if (j == 0) {
 				ShowWarning("Map-server %d has NO maps.\n", id);
 				ShowWarning("Map-server %d has NO maps.\n", id);
 			} else {
 			} else {
+				unsigned char buf[16384];
+
 				// Transmitting maps information to the other map-servers
 				// Transmitting maps information to the other map-servers
 				WBUFW(buf,0) = 0x2b04;
 				WBUFW(buf,0) = 0x2b04;
 				WBUFW(buf,2) = j * 4 + 10;
 				WBUFW(buf,2) = j * 4 + 10;
@@ -3791,7 +3792,7 @@ int parse_frommap(int fd)
 			struct auth_node* node;
 			struct auth_node* node;
 			struct mmo_charstatus* cd;
 			struct mmo_charstatus* cd;
 			struct mmo_charstatus char_dat;
 			struct mmo_charstatus char_dat;
-			bool autotrade = false;
+			bool autotrade;
 
 
 			account_id = RFIFOL(fd,2);
 			account_id = RFIFOL(fd,2);
 			char_id    = RFIFOL(fd,6);
 			char_id    = RFIFOL(fd,6);

+ 192 - 226
src/map/battle.c

@@ -405,25 +405,6 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d
 	return (int64)damage*ratio/100;
 	return (int64)damage*ratio/100;
 }
 }
 
 
-/*==========================================
- * Calculates damage for a specific rate (cardfix) with 100% (precision).
- *------------------------------------------*/
-inline int64 bcc_damage_rate(int64 damage, short rate) {
-	if (rate == 1000)
-		return damage;
-	return ((int64)(damage * rate) / 1000);
-}
-
-/*==========================================
- * Calculates cardfix (damage percentage) after adding a different effect with 100% (effect_precision) by multiplying damage rate.
- * Note: Can be negative for damage reduction.
- *------------------------------------------*/
-inline short bcc_multi_damage_rate(short cardfix, short effect_rate) {
-	if (effect_rate == 100)
-		return cardfix;
-	return ((cardfix * (effect_rate + 100)) / 100);
-}
-
 /*==========================================
 /*==========================================
  * Calculates card bonuses damage adjustments.
  * Calculates card bonuses damage adjustments.
  *------------------------------------------*/
  *------------------------------------------*/
@@ -447,284 +428,270 @@ int battle_calc_cardfix(int attack_type, struct block_list *src, struct block_li
 	tstatus = status_get_status_data(target);
 	tstatus = status_get_status_data(target);
 	s_race2 = status_get_race2(src);
 	s_race2 = status_get_race2(src);
 
 
-	switch(attack_type){
+	switch( attack_type ) {
 		case BF_MAGIC:
 		case BF_MAGIC:
-			if ( sd && !(nk&NK_NO_CARDFIX_ATK) ) {
-				cardfix = bcc_multi_damage_rate(cardfix, sd->magic_addrace[tstatus->race] + sd->magic_addrace[RC_ALL]);
-				if (!(nk&NK_NO_ELEFIX))
-					cardfix = bcc_multi_damage_rate(cardfix, sd->magic_addele[tstatus->def_ele] + sd->magic_addele[ELE_ALL]);
-				cardfix = bcc_multi_damage_rate(cardfix, sd->magic_addsize[tstatus->size] + sd->magic_addsize[SZ_ALL]);
-				cardfix = bcc_multi_damage_rate(cardfix, sd->magic_addclass[tstatus->class_] + sd->magic_addclass[CLASS_ALL]);
-				cardfix = bcc_multi_damage_rate(cardfix, sd->magic_atk_ele[s_ele] + sd->magic_atk_ele[ELE_ALL]);
-				for(i=0; i< ARRAYLENGTH(sd->add_mdmg) && sd->add_mdmg[i].rate;i++) {
-					if(sd->add_mdmg[i].class_ == t_class) {
-						cardfix = bcc_multi_damage_rate(cardfix, sd->add_mdmg[i].rate);
+			if( sd && !(nk&NK_NO_CARDFIX_ATK) ) {
+				cardfix = cardfix * (100 + sd->magic_addrace[tstatus->race] + sd->magic_addrace[RC_ALL]) / 100;
+				if( !(nk&NK_NO_ELEFIX) )
+					cardfix = cardfix * (100 + sd->magic_addele[tstatus->def_ele] + sd->magic_addele[ELE_ALL]) / 100;
+				cardfix = cardfix * (100 + sd->magic_addsize[tstatus->size] + sd->magic_addsize[SZ_ALL]) / 100;
+				cardfix = cardfix * (100 + sd->magic_addclass[tstatus->class_] + sd->magic_addclass[CLASS_ALL]) / 100;
+				cardfix = cardfix * (100 + sd->magic_atk_ele[s_ele] + sd->magic_atk_ele[ELE_ALL]) / 100;
+				for( i = 0; i < ARRAYLENGTH(sd->add_mdmg) && sd->add_mdmg[i].rate; i++ ) {
+					if( sd->add_mdmg[i].class_ == t_class ) {
+						cardfix = cardfix * (100 + sd->add_mdmg[i].rate) / 100;
 						break;
 						break;
 					}
 					}
 				}
 				}
-				damage = bcc_damage_rate(damage, cardfix);
+				if( cardfix != 1000 )
+					damage = damage * cardfix / 1000;
 			}
 			}
+			if( tsd && !(nk&NK_NO_CARDFIX_DEF) ) { // Target cards.
+				cardfix = 1000; // reset var for target
 
 
-			if( tsd && !(nk&NK_NO_CARDFIX_DEF) )
-			{ // Target cards.
-				cardfix = 1000; //reset var for target
-
-				if (!(nk&NK_NO_ELEFIX))
-				{
+				if( !(nk&NK_NO_ELEFIX) ) {
 					int ele_fix = tsd->subele[s_ele] + tsd->subele[ELE_ALL];
 					int ele_fix = tsd->subele[s_ele] + tsd->subele[ELE_ALL];
-					for (i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++)
-					{
-						if(tsd->subele2[i].ele != s_ele) continue;
-						if(!( ((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
-							  ((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
-							  ((tsd->subele2[i].flag)&flag)&BF_SKILLMASK))
+
+					for( i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++ ) {
+						if( tsd->subele2[i].ele != s_ele )
+							continue;
+						if( !(((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
+							((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
+							((tsd->subele2[i].flag)&flag)&BF_SKILLMASK) )
 							continue;
 							continue;
 						ele_fix += tsd->subele2[i].rate;
 						ele_fix += tsd->subele2[i].rate;
 					}
 					}
-					cardfix = bcc_multi_damage_rate(cardfix, -ele_fix);
+					cardfix = cardfix * (100 - ele_fix) / 100;
 				}
 				}
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subsize[sstatus->size] + tsd->subsize[SZ_ALL]));
-				cardfix = bcc_multi_damage_rate(cardfix, -tsd->subrace2[s_race2]);
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subrace[sstatus->race] + tsd->subrace[RC_ALL]));
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subclass[sstatus->class_] + tsd->subclass[CLASS_ALL]));
-
-				for(i=0; i < ARRAYLENGTH(tsd->add_mdef) && tsd->add_mdef[i].rate;i++) {
-					if(tsd->add_mdef[i].class_ == s_class) {
-						cardfix = bcc_multi_damage_rate(cardfix, -tsd->add_mdef[i].rate);
+				cardfix = cardfix * (100 - tsd->subsize[sstatus->size] + tsd->subsize[SZ_ALL]) / 100;
+				cardfix = cardfix * (100 - tsd->subrace2[s_race2]) / 100;
+				cardfix = cardfix * (100 - tsd->subrace[sstatus->race] + tsd->subrace[RC_ALL]) / 100;
+				cardfix = cardfix * (100 - tsd->subclass[sstatus->class_] + tsd->subclass[CLASS_ALL]) / 100;
+
+				for( i = 0; i < ARRAYLENGTH(tsd->add_mdef) && tsd->add_mdef[i].rate; i++ ) {
+					if( tsd->add_mdef[i].class_ == s_class ) {
+						cardfix = cardfix * (100 - tsd->add_mdef[i].rate) / 100;
 						break;
 						break;
 					}
 					}
 				}
 				}
+#ifndef RENEWAL
 				//It was discovered that ranged defense also counts vs magic! [Skotlex]
 				//It was discovered that ranged defense also counts vs magic! [Skotlex]
-				if ( flag&BF_SHORT )
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.near_attack_def_rate);
+				if( flag&BF_SHORT )
+					cardfix = cardfix * (100 - tsd->bonus.near_attack_def_rate) / 100;
 				else
 				else
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.long_attack_def_rate);
-
-				cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.magic_def_rate);
+					cardfix = cardfix * (100 - tsd->bonus.long_attack_def_rate) / 100;
+#endif
+				cardfix = cardfix * (100 - tsd->bonus.magic_def_rate) / 100;
 
 
 				if( tsd->sc.data[SC_MDEF_RATE] )
 				if( tsd->sc.data[SC_MDEF_RATE] )
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->sc.data[SC_MDEF_RATE]->val1);
-
-				damage = bcc_damage_rate(damage, cardfix);
+					cardfix = cardfix * (100 - tsd->sc.data[SC_MDEF_RATE]->val1) / 100;
+				if( cardfix != 1000 )
+					damage = damage * cardfix / 1000;
 			}
 			}
 			break;
 			break;
 		case BF_WEAPON:
 		case BF_WEAPON:
 			t_race2 = status_get_race2(target);
 			t_race2 = status_get_race2(target);
-			if( sd && !(nk&NK_NO_CARDFIX_ATK) && (left&2) ) //Attacker cards should be checked
-			{
-				short cardfix_left = 1000;
-				if(sd->state.arrow_atk)
-				{
-					cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addrace[tstatus->race] + sd->arrow_addrace[tstatus->race]
-															+ sd->right_weapon.addrace[RC_ALL] + sd->arrow_addrace[RC_ALL]);
-					if (!(nk&NK_NO_ELEFIX))
-					{
-						int ele_fix = sd->right_weapon.addele[tstatus->def_ele] + sd->arrow_addele[tstatus->def_ele]
-									+ sd->right_weapon.addele[ELE_ALL] + sd->arrow_addele[ELE_ALL];
-						for (i = 0; ARRAYLENGTH(sd->right_weapon.addele2) > i && sd->right_weapon.addele2[i].rate != 0; i++) {
-							if (sd->right_weapon.addele2[i].ele != tstatus->def_ele) continue;
-							if(!( ((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
-								  ((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
-								  ((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK))
-									continue;
+			if( sd && !(nk&NK_NO_CARDFIX_ATK) && (left&2) ) { //Attacker cards should be checked
+				short cardfix_ = 1000;
+
+				if( sd->state.arrow_atk ) {
+					cardfix = cardfix * (100 + sd->right_weapon.addrace[tstatus->race] + sd->arrow_addrace[tstatus->race] +
+						sd->right_weapon.addrace[RC_ALL] + sd->arrow_addrace[RC_ALL]) / 100;
+					if( !(nk&NK_NO_ELEFIX) ) {
+						int ele_fix = sd->right_weapon.addele[tstatus->def_ele] + sd->arrow_addele[tstatus->def_ele] +
+							sd->right_weapon.addele[ELE_ALL] + sd->arrow_addele[ELE_ALL];
+
+						for( i = 0; ARRAYLENGTH(sd->right_weapon.addele2) > i && sd->right_weapon.addele2[i].rate != 0; i++ ) {
+							if( sd->right_weapon.addele2[i].ele != tstatus->def_ele )
+								continue;
+							if( !(((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
+								((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
+								((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK) )
+								continue;
 							ele_fix += sd->right_weapon.addele2[i].rate;
 							ele_fix += sd->right_weapon.addele2[i].rate;
 						}
 						}
-						cardfix = bcc_multi_damage_rate(cardfix, ele_fix);
+						cardfix = cardfix * (100 + ele_fix) / 100;
 					}
 					}
-					cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addsize[tstatus->size]+sd->arrow_addsize[tstatus->size]
-															+ sd->right_weapon.addsize[SZ_ALL]+sd->arrow_addsize[SZ_ALL]);
-					cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addrace2[t_race2]);
-					cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addclass[tstatus->class_]+sd->arrow_addclass[tstatus->class_]
-															+ sd->right_weapon.addclass[CLASS_ALL]+sd->arrow_addclass[CLASS_ALL]);
-				}
-				else
-				{ // Melee attack
-					int skill_learnlv=0;
-					if( !battle_config.left_cardfix_to_right )
-					{
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addrace[tstatus->race] + sd->right_weapon.addrace[RC_ALL]);
-						if (!(nk&NK_NO_ELEFIX)) {
+					cardfix = cardfix * (100 + sd->right_weapon.addsize[tstatus->size] + sd->arrow_addsize[tstatus->size] +
+						sd->right_weapon.addsize[SZ_ALL] + sd->arrow_addsize[SZ_ALL]) / 100;
+					cardfix = cardfix * (100 + sd->right_weapon.addrace2[t_race2]) / 100;
+					cardfix = cardfix * (100 + sd->right_weapon.addclass[tstatus->class_] + sd->arrow_addclass[tstatus->class_] +
+						sd->right_weapon.addclass[CLASS_ALL] + sd->arrow_addclass[CLASS_ALL]) / 100;
+				} else { // Melee attack
+					int skill = 0;
+
+					if( !battle_config.left_cardfix_to_right ) {
+						cardfix = cardfix * (100 + sd->right_weapon.addrace[tstatus->race] + sd->right_weapon.addrace[RC_ALL]) / 100;
+						if( !(nk&NK_NO_ELEFIX) ) {
 							int ele_fix = sd->right_weapon.addele[tstatus->def_ele] + sd->right_weapon.addele[ELE_ALL];
 							int ele_fix = sd->right_weapon.addele[tstatus->def_ele] + sd->right_weapon.addele[ELE_ALL];
-							for (i = 0; ARRAYLENGTH(sd->right_weapon.addele2) > i && sd->right_weapon.addele2[i].rate != 0; i++) {
-								if (sd->right_weapon.addele2[i].ele != tstatus->def_ele) continue;
-								if(!( ((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
-									  ((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
-									  ((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK))
-										continue;
+
+							for( i = 0; ARRAYLENGTH(sd->right_weapon.addele2) > i && sd->right_weapon.addele2[i].rate != 0; i++ ) {
+								if( sd->right_weapon.addele2[i].ele != tstatus->def_ele )
+									continue;
+								if( !(((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
+									((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
+									((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK) )
+									continue;
 								ele_fix += sd->right_weapon.addele2[i].rate;
 								ele_fix += sd->right_weapon.addele2[i].rate;
 							}
 							}
-							cardfix = bcc_multi_damage_rate(cardfix, ele_fix);
+							cardfix = cardfix * (100 + ele_fix) / 100;
 						}
 						}
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addsize[tstatus->size] + sd->right_weapon.addsize[SZ_ALL]);
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addrace2[t_race2]);
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addclass[tstatus->class_] + sd->right_weapon.addclass[CLASS_ALL]);
+						cardfix = cardfix * (100 + sd->right_weapon.addsize[tstatus->size] + sd->right_weapon.addsize[SZ_ALL]) / 100;
+						cardfix = cardfix * (100 + sd->right_weapon.addrace2[t_race2]) / 100;
+						cardfix = cardfix * (100 + sd->right_weapon.addclass[tstatus->class_] + sd->right_weapon.addclass[CLASS_ALL]) / 100;
 
 
-						if( left&1 )
-						{
-							cardfix_left = bcc_multi_damage_rate(cardfix_left, sd->left_weapon.addrace[tstatus->race] + sd->left_weapon.addrace[RC_ALL]);
-							if (!(nk&NK_NO_ELEFIX))	{
+						if( left&1 ) {
+							cardfix_ = cardfix_ * (100 + sd->left_weapon.addrace[tstatus->race] + sd->left_weapon.addrace[RC_ALL]) / 100;
+							if( !(nk&NK_NO_ELEFIX) ) {
 								int ele_fix_lh = sd->left_weapon.addele[tstatus->def_ele] + sd->left_weapon.addele[ELE_ALL];
 								int ele_fix_lh = sd->left_weapon.addele[tstatus->def_ele] + sd->left_weapon.addele[ELE_ALL];
-								for (i = 0; ARRAYLENGTH(sd->left_weapon.addele2) > i && sd->left_weapon.addele2[i].rate != 0; i++) {
-									if (sd->left_weapon.addele2[i].ele != tstatus->def_ele) continue;
-									if(!( ((sd->left_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
-										  ((sd->left_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
-										  ((sd->left_weapon.addele2[i].flag)&flag)&BF_SKILLMASK))
-											continue;
+
+								for( i = 0; ARRAYLENGTH(sd->left_weapon.addele2) > i && sd->left_weapon.addele2[i].rate != 0; i++ ) {
+									if( sd->left_weapon.addele2[i].ele != tstatus->def_ele )
+										continue;
+									if( !(((sd->left_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
+										((sd->left_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
+										((sd->left_weapon.addele2[i].flag)&flag)&BF_SKILLMASK) )
+										continue;
 									ele_fix_lh += sd->left_weapon.addele2[i].rate;
 									ele_fix_lh += sd->left_weapon.addele2[i].rate;
 								}
 								}
-								cardfix_left = bcc_multi_damage_rate(cardfix_left, ele_fix_lh);
+								cardfix_ = cardfix_ * (100 + ele_fix_lh) / 100;
 							}
 							}
-							cardfix_left = bcc_multi_damage_rate(cardfix_left, sd->left_weapon.addsize[tstatus->size] + sd->left_weapon.addsize[SZ_ALL]);
-							cardfix_left = bcc_multi_damage_rate(cardfix_left, sd->left_weapon.addrace2[t_race2]);
-							cardfix_left = bcc_multi_damage_rate(cardfix_left, sd->left_weapon.addclass[tstatus->class_] + sd->left_weapon.addclass[CLASS_ALL]);
+							cardfix_ = cardfix_ * (100 + sd->left_weapon.addsize[tstatus->size] + sd->left_weapon.addsize[SZ_ALL]) / 100;
+							cardfix_ = cardfix_ * (100 + sd->left_weapon.addrace2[t_race2]) / 100;
+							cardfix_ = cardfix_ * (100 + sd->left_weapon.addclass[tstatus->class_] + sd->left_weapon.addclass[CLASS_ALL]) / 100;
 						}
 						}
-					}
-					else
-					{
+					} else {
 						int ele_fix = sd->right_weapon.addele[tstatus->def_ele] + sd->left_weapon.addele[tstatus->def_ele]
 						int ele_fix = sd->right_weapon.addele[tstatus->def_ele] + sd->left_weapon.addele[tstatus->def_ele]
 									+ sd->right_weapon.addele[ELE_ALL] + sd->left_weapon.addele[ELE_ALL];
 									+ sd->right_weapon.addele[ELE_ALL] + sd->left_weapon.addele[ELE_ALL];
-						for (i = 0; ARRAYLENGTH(sd->right_weapon.addele2) > i && sd->right_weapon.addele2[i].rate != 0; i++) {
-							if (sd->right_weapon.addele2[i].ele != tstatus->def_ele) continue;
-							if(!( ((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
-								  ((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
-								  ((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK))
-									continue;
+
+						for( i = 0; ARRAYLENGTH(sd->right_weapon.addele2) > i && sd->right_weapon.addele2[i].rate != 0; i++ ) {
+							if( sd->right_weapon.addele2[i].ele != tstatus->def_ele )
+								continue;
+							if( !(((sd->right_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
+								((sd->right_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
+								((sd->right_weapon.addele2[i].flag)&flag)&BF_SKILLMASK) )
+								continue;
 							ele_fix += sd->right_weapon.addele2[i].rate;
 							ele_fix += sd->right_weapon.addele2[i].rate;
 						}
 						}
-						for (i = 0; ARRAYLENGTH(sd->left_weapon.addele2) > i && sd->left_weapon.addele2[i].rate != 0; i++) {
-							if (sd->left_weapon.addele2[i].ele != tstatus->def_ele) continue;
-							if(!( ((sd->left_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
-								  ((sd->left_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
-								  ((sd->left_weapon.addele2[i].flag)&flag)&BF_SKILLMASK))
-									continue;
+						for( i = 0; ARRAYLENGTH(sd->left_weapon.addele2) > i && sd->left_weapon.addele2[i].rate != 0; i++ ) {
+							if( sd->left_weapon.addele2[i].ele != tstatus->def_ele )
+								continue;
+							if( !(((sd->left_weapon.addele2[i].flag)&flag)&BF_WEAPONMASK &&
+								((sd->left_weapon.addele2[i].flag)&flag)&BF_RANGEMASK &&
+								((sd->left_weapon.addele2[i].flag)&flag)&BF_SKILLMASK) )
+								continue;
 							ele_fix += sd->left_weapon.addele2[i].rate;
 							ele_fix += sd->left_weapon.addele2[i].rate;
 						}
 						}
-
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addrace[tstatus->race] + sd->left_weapon.addrace[tstatus->race]
-																+ sd->right_weapon.addrace[RC_ALL] + sd->left_weapon.addrace[RC_ALL]);
-						cardfix = bcc_multi_damage_rate(cardfix, ele_fix);
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addsize[tstatus->size] + sd->left_weapon.addsize[tstatus->size]
-																+ sd->right_weapon.addsize[SZ_ALL] + sd->left_weapon.addsize[SZ_ALL]);
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addrace2[t_race2] + sd->left_weapon.addrace2[t_race2]);
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.addclass[tstatus->class_] + sd->left_weapon.addclass[tstatus->class_]
-																+ sd->right_weapon.addclass[CLASS_ALL] + sd->left_weapon.addclass[CLASS_ALL]);
-					}
-					if (sd->status.weapon == W_KATAR && (skill_learnlv=pc_checkskill(sd,ASC_KATAR)) > 0) { // Adv. Katar Mastery functions similar to a +%ATK card on official [helvetica]
-						cardfix = bcc_multi_damage_rate(cardfix, (10 + 2 * skill_learnlv));
+						cardfix = cardfix * (100 + sd->right_weapon.addrace[tstatus->race] + sd->left_weapon.addrace[tstatus->race] +
+							sd->right_weapon.addrace[RC_ALL] + sd->left_weapon.addrace[RC_ALL]) / 100;
+						cardfix = cardfix * (100 + ele_fix) / 100;
+						cardfix = cardfix * (100 + sd->right_weapon.addsize[tstatus->size] + sd->left_weapon.addsize[tstatus->size] +
+							sd->right_weapon.addsize[SZ_ALL] + sd->left_weapon.addsize[SZ_ALL]) / 100;
+						cardfix = cardfix * (100 + sd->right_weapon.addrace2[t_race2] + sd->left_weapon.addrace2[t_race2]) / 100;
+						cardfix = cardfix * (100 + sd->right_weapon.addclass[tstatus->class_] + sd->left_weapon.addclass[tstatus->class_] +
+							sd->right_weapon.addclass[CLASS_ALL] + sd->left_weapon.addclass[CLASS_ALL]) / 100;
 					}
 					}
+					if( sd->status.weapon == W_KATAR && (skill = pc_checkskill(sd,ASC_KATAR)) > 0 ) // Adv. Katar Mastery functions similar to a +%ATK card on official [helvetica]
+						cardfix = cardfix * (100 + (10 + 2 * skill)) / 100;
 				}
 				}
-				for( i = 0; i < ARRAYLENGTH(sd->right_weapon.add_dmg) && sd->right_weapon.add_dmg[i].rate; i++ )
-				{
-					if( sd->right_weapon.add_dmg[i].class_ == t_class )
-					{
-						cardfix = bcc_multi_damage_rate(cardfix, sd->right_weapon.add_dmg[i].rate);
+				for( i = 0; i < ARRAYLENGTH(sd->right_weapon.add_dmg) && sd->right_weapon.add_dmg[i].rate; i++ ) {
+					if( sd->right_weapon.add_dmg[i].class_ == t_class ) {
+						cardfix = cardfix * (100 + sd->right_weapon.add_dmg[i].rate) / 100;
 						break;
 						break;
 					}
 					}
 				}
 				}
-
-				if( left&1 )
-				{
-					for( i = 0; i < ARRAYLENGTH(sd->left_weapon.add_dmg) && sd->left_weapon.add_dmg[i].rate; i++ )
-					{
-						if( sd->left_weapon.add_dmg[i].class_ == t_class )
-						{
-							cardfix_left = bcc_multi_damage_rate(cardfix, sd->left_weapon.add_dmg[i].rate);
+				if( left&1 ) {
+					for( i = 0; i < ARRAYLENGTH(sd->left_weapon.add_dmg) && sd->left_weapon.add_dmg[i].rate; i++ ) {
+						if( sd->left_weapon.add_dmg[i].class_ == t_class ) {
+							cardfix_ = cardfix_ * (100 + sd->left_weapon.add_dmg[i].rate) / 100;
 							break;
 							break;
 						}
 						}
 					}
 					}
 				}
 				}
-
 #ifndef RENEWAL
 #ifndef RENEWAL
 				if( flag&BF_LONG )
 				if( flag&BF_LONG )
-					cardfix = bcc_multi_damage_rate(cardfix, sd->bonus.long_attack_atk_rate);
+					cardfix = cardfix * (100 + sd->bonus.long_attack_atk_rate) / 100;
 #endif
 #endif
-
-				if( (left&1) )
-					damage = bcc_damage_rate(damage, cardfix_left);
-				else
-					damage = bcc_damage_rate(damage, cardfix);
-
-			} else if( tsd && !(nk&NK_NO_CARDFIX_DEF) && !(left&2) ){ //Target cards should be checked
-				if( !(nk&NK_NO_ELEFIX) )
-				{
+				if( (left&1) && cardfix_ != 1000 )
+					damage = damage * cardfix_ / 1000;
+				else if( cardfix != 1000 )
+					damage = damage * cardfix / 1000;
+			} else if( tsd && !(nk&NK_NO_CARDFIX_DEF) && !(left&2) ) { //Target cards should be checked
+				if( !(nk&NK_NO_ELEFIX) ) {
 					int ele_fix = tsd->subele[s_ele] + tsd->subele[ELE_ALL];
 					int ele_fix = tsd->subele[s_ele] + tsd->subele[ELE_ALL];
-					for (i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++)
-					{
-						if(tsd->subele2[i].ele != s_ele) continue;
-						if(!( ((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
-							  ((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
-							  ((tsd->subele2[i].flag)&flag)&BF_SKILLMASK))
+
+					for( i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++ ) {
+						if( tsd->subele2[i].ele != s_ele )
+							continue;
+						if( !(((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
+							((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
+							((tsd->subele2[i].flag)&flag)&BF_SKILLMASK) )
 							continue;
 							continue;
 						ele_fix += tsd->subele2[i].rate;
 						ele_fix += tsd->subele2[i].rate;
 					}
 					}
-					cardfix = bcc_multi_damage_rate(cardfix, -ele_fix);
-					if( left&1 && s_ele_ != s_ele )
-					{
+					cardfix = cardfix * (100 - ele_fix) / 100;
+					if( left&1 && s_ele_ != s_ele ) {
 						int ele_fix_lh = tsd->subele[s_ele_] + tsd->subele[ELE_ALL];
 						int ele_fix_lh = tsd->subele[s_ele_] + tsd->subele[ELE_ALL];
-						for (i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++)
-						{
-							if(tsd->subele2[i].ele != s_ele_) continue;
-							if(!( ((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
-								  ((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
-								  ((tsd->subele2[i].flag)&flag)&BF_SKILLMASK))
+
+						for( i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++ ) {
+							if( tsd->subele2[i].ele != s_ele_ )
+								continue;
+							if( !(((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
+								((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
+								((tsd->subele2[i].flag)&flag)&BF_SKILLMASK) )
 								continue;
 								continue;
 							ele_fix_lh += tsd->subele2[i].rate;
 							ele_fix_lh += tsd->subele2[i].rate;
 						}
 						}
-						cardfix = bcc_multi_damage_rate(cardfix, -ele_fix_lh);
+						cardfix = cardfix * (100 - ele_fix_lh) / 100;
 					}
 					}
 				}
 				}
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subsize[sstatus->size] + tsd->subsize[SZ_ALL]));
-	 			cardfix = bcc_multi_damage_rate(cardfix, -tsd->subrace2[s_race2]);
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subrace[sstatus->race] + tsd->subrace[RC_ALL]));
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subclass[sstatus->class_] + tsd->subclass[CLASS_ALL]));
-
-				for( i = 0; i < ARRAYLENGTH(tsd->add_def) && tsd->add_def[i].rate;i++ ) {
+				cardfix = cardfix * (100 - tsd->subsize[sstatus->size] + tsd->subsize[SZ_ALL]) / 100;
+				cardfix = cardfix * (100 - tsd->subrace2[s_race2]) / 100;
+				cardfix = cardfix * (100 - tsd->subrace[sstatus->race] + tsd->subrace[RC_ALL]) / 100;
+				cardfix = cardfix * (100 - tsd->subclass[sstatus->class_] + tsd->subclass[CLASS_ALL]) / 100;
+				for( i = 0; i < ARRAYLENGTH(tsd->add_def) && tsd->add_def[i].rate; i++ ) {
 					if( tsd->add_def[i].class_ == s_class ) {
 					if( tsd->add_def[i].class_ == s_class ) {
-						cardfix = bcc_multi_damage_rate(cardfix, tsd->add_def[i].rate);
+						cardfix = cardfix * (100 - tsd->add_def[i].rate) / 100;
 						break;
 						break;
 					}
 					}
 				}
 				}
-
 				if( flag&BF_SHORT )
 				if( flag&BF_SHORT )
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.near_attack_def_rate);
+					cardfix = cardfix * (100 - tsd->bonus.near_attack_def_rate) / 100;
 				else	// BF_LONG (there's no other choice)
 				else	// BF_LONG (there's no other choice)
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.long_attack_def_rate);
-
+					cardfix = cardfix * (100 - tsd->bonus.long_attack_def_rate) / 100;
 				if( tsd->sc.data[SC_DEF_RATE] )
 				if( tsd->sc.data[SC_DEF_RATE] )
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->sc.data[SC_DEF_RATE]->val1);
-
-				damage = bcc_damage_rate(damage, cardfix);
+					cardfix = cardfix * (100 - tsd->sc.data[SC_DEF_RATE]->val1) / 100;
+				if( cardfix != 1000 )
+					damage = damage * cardfix / 1000;
 			}
 			}
 			break;
 			break;
 		case BF_MISC:
 		case BF_MISC:
-			if( tsd && !(nk&NK_NO_CARDFIX_DEF) ){
-			// misc damage reduction from equipment
-				if (!(nk&NK_NO_ELEFIX))
-				{
+			if( tsd && !(nk&NK_NO_CARDFIX_DEF) ) { // misc damage reduction from equipment
+				if( !(nk&NK_NO_ELEFIX) ) {
 					int ele_fix = tsd->subele[s_ele] + tsd->subele[ELE_ALL];
 					int ele_fix = tsd->subele[s_ele] + tsd->subele[ELE_ALL];
-					for (i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++)
-					{
-						if(tsd->subele2[i].ele != s_ele) continue;
-						if(!( ((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
-							  ((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
-							  ((tsd->subele2[i].flag)&flag)&BF_SKILLMASK))
+
+					for( i = 0; ARRAYLENGTH(tsd->subele2) > i && tsd->subele2[i].rate != 0; i++ ) {
+						if( tsd->subele2[i].ele != s_ele )
+							continue;
+						if( !(((tsd->subele2[i].flag)&flag)&BF_WEAPONMASK &&
+							((tsd->subele2[i].flag)&flag)&BF_RANGEMASK &&
+							((tsd->subele2[i].flag)&flag)&BF_SKILLMASK))
 							continue;
 							continue;
 						ele_fix += tsd->subele2[i].rate;
 						ele_fix += tsd->subele2[i].rate;
 					}
 					}
-					cardfix = bcc_multi_damage_rate(cardfix, -ele_fix);
+					cardfix = cardfix * (100 - ele_fix) / 100;
 				}
 				}
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subsize[sstatus->size] + tsd->subsize[SZ_ALL]));
-				cardfix = bcc_multi_damage_rate(cardfix, -tsd->subrace2[s_race2]);
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subrace[sstatus->race] + tsd->subrace[RC_ALL]));
-				cardfix = bcc_multi_damage_rate(cardfix, -(tsd->subclass[sstatus->class_] + tsd->subclass[CLASS_ALL]));
-
-				cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.misc_def_rate);
+				cardfix = cardfix * (100 - tsd->subsize[sstatus->size] + tsd->subsize[SZ_ALL]) / 100;
+				cardfix = cardfix * (100 - tsd->subrace2[s_race2]) / 100;
+				cardfix = cardfix * (100 - tsd->subrace[sstatus->race] + tsd->subrace[RC_ALL]) / 100;
+				cardfix = cardfix * (100 - tsd->subclass[sstatus->class_] + tsd->subclass[CLASS_ALL]) / 100;
+				cardfix = cardfix * (100 - tsd->bonus.misc_def_rate) / 100;
 				if( flag&BF_SHORT )
 				if( flag&BF_SHORT )
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.near_attack_def_rate);
+					cardfix = cardfix * (100 - tsd->bonus.near_attack_def_rate) / 100;
 				else	// BF_LONG (there's no other choice)
 				else	// BF_LONG (there's no other choice)
-					cardfix = bcc_multi_damage_rate(cardfix, -tsd->bonus.long_attack_def_rate);
-
-				damage = bcc_damage_rate(damage, cardfix);
+					cardfix = cardfix * (100 - tsd->bonus.long_attack_def_rate) / 100;
+				if( cardfix != 10000 )
+					damage = damage * cardfix / 1000;
 			}
 			}
 			break;
 			break;
 	}
 	}
@@ -733,7 +700,7 @@ int battle_calc_cardfix(int attack_type, struct block_list *src, struct block_li
 }
 }
 
 
 /*==========================================
 /*==========================================
- * Check dammage trough status.
+ * Check damage trough status.
  * ATK may be MISS, BLOCKED FAIL, reduc, increase, end status...
  * ATK may be MISS, BLOCKED FAIL, reduc, increase, end status...
  * After this we apply bg/gvg reduction
  * After this we apply bg/gvg reduction
  *------------------------------------------*/
  *------------------------------------------*/
@@ -5394,16 +5361,15 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
 						else
 						else
 							skillratio += 110 + 20 * skill_lv;
 							skillratio += 110 + 20 * skill_lv;
 						break;
 						break;
-					case KO_KAIHOU: {
+					case KO_KAIHOU:
+						if(sd) {
 							int ttype;
 							int ttype;
 
 
-							if(sd) {
-								ARR_FIND(1, 6, ttype, sd->talisman[ttype] > 0);
-								if(ttype < 5) {
-									skillratio += -100 + 200 * sd->talisman[ttype];
-									RE_LVL_DMOD(100);
-									pc_del_talisman(sd, sd->talisman[ttype], ttype);
-								}
+							ARR_FIND(1, 6, ttype, sd->talisman[ttype] > 0);
+							if(ttype < 5) {
+								skillratio += -100 + 200 * sd->talisman[ttype];
+								RE_LVL_DMOD(100);
+								pc_del_talisman(sd, sd->talisman[ttype], ttype);
 							}
 							}
 						}
 						}
 						break;
 						break;

+ 20 - 10
src/map/clif.c

@@ -8689,7 +8689,7 @@ void clif_refresh(struct map_session_data *sd)
 void clif_charnameack (int fd, struct block_list *bl)
 void clif_charnameack (int fd, struct block_list *bl)
 {
 {
 	unsigned char buf[103];
 	unsigned char buf[103];
-	int cmd = 0x95, i, ps = -1;
+	int cmd = 0x95;
 
 
 	nullpo_retv(bl);
 	nullpo_retv(bl);
 
 
@@ -8703,6 +8703,7 @@ void clif_charnameack (int fd, struct block_list *bl)
 			struct map_session_data *ssd = (struct map_session_data *)bl;
 			struct map_session_data *ssd = (struct map_session_data *)bl;
 			struct party_data *p = NULL;
 			struct party_data *p = NULL;
 			struct guild *g = NULL;
 			struct guild *g = NULL;
+			int ps = -1;
 
 
 			//Requesting your own "shadow" name. [Skotlex]
 			//Requesting your own "shadow" name. [Skotlex]
 			if (ssd->fd == fd && ssd->disguise)
 			if (ssd->fd == fd && ssd->disguise)
@@ -8721,6 +8722,8 @@ void clif_charnameack (int fd, struct block_list *bl)
 			}
 			}
 			if( ssd->status.guild_id ) {
 			if( ssd->status.guild_id ) {
 				if( ( g = ssd->guild ) != NULL ) {
 				if( ( g = ssd->guild ) != NULL ) {
+					int i;
+
 					ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
 					ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
 					if( i < g->max_member ) ps = g->member[i].position;
 					if( i < g->max_member ) ps = g->member[i].position;
 				}
 				}
@@ -10631,7 +10634,7 @@ void clif_parse_UseItem(int fd, struct map_session_data *sd)
 /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
 /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
 void clif_parse_EquipItem(int fd,struct map_session_data *sd)
 void clif_parse_EquipItem(int fd,struct map_session_data *sd)
 {
 {
-	int index, req_pos;
+	int index;
 	struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
 	struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
 
 
 	if(pc_isdead(sd)) {
 	if(pc_isdead(sd)) {
@@ -10666,6 +10669,8 @@ void clif_parse_EquipItem(int fd,struct map_session_data *sd)
 	if(sd->inventory_data[index]->type == IT_AMMO)
 	if(sd->inventory_data[index]->type == IT_AMMO)
 		pc_equipitem(sd,index,EQP_AMMO);
 		pc_equipitem(sd,index,EQP_AMMO);
 	else {
 	else {
+	int req_pos;
+
 #if PACKETVER  >= 20120925
 #if PACKETVER  >= 20120925
 		req_pos = RFIFOL(fd,info->pos[1]);
 		req_pos = RFIFOL(fd,info->pos[1]);
 #else
 #else
@@ -12379,13 +12384,14 @@ void clif_parse_OpenVending(int fd, struct map_session_data* sd){
 	struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
 	struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
 	short len = (short)RFIFOW(fd,info->pos[0]);
 	short len = (short)RFIFOW(fd,info->pos[0]);
 	const char* message = (char*)RFIFOP(fd,info->pos[1]);
 	const char* message = (char*)RFIFOP(fd,info->pos[1]);
-	bool flag;
 	const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
 	const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
 
 
 	if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
 	if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
 		len -= 84;
 		len -= 84;
 	}
 	}
 	else { //(CZ_REQ_OPENSTORE2)
 	else { //(CZ_REQ_OPENSTORE2)
+		bool flag;
+
 		len -= 85;
 		len -= 85;
 		flag = (bool)RFIFOB(fd,info->pos[2]);
 		flag = (bool)RFIFOB(fd,info->pos[2]);
 		if( !flag )
 		if( !flag )
@@ -12527,10 +12533,11 @@ void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
 
 
 
 
 /// Validates data of a guild emblem (compressed bitmap)
 /// Validates data of a guild emblem (compressed bitmap)
-static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len){
+static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
+{
 	uint8 buf[1800];  // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
 	uint8 buf[1800];  // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
 	unsigned long buf_len = sizeof(buf);
 	unsigned long buf_len = sizeof(buf);
-	int i,j, transcount=1, offset=0, tmp[3];
+	int offset = 0;
 
 
 	if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 )  // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
 	if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 )  // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
 		&& RBUFW(buf,0) == 0x4d42   // BITMAPFILEHEADER.bfType (signature)
 		&& RBUFW(buf,0) == 0x4d42   // BITMAPFILEHEADER.bfType (signature)
@@ -12539,11 +12546,12 @@ static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len){
 		))
 		))
 		return -1;
 		return -1;
 
 
-	if(battle_config.emblem_transparency_limit != 100){
-		for(i=offset; i<buf_len-1; i++){
+	if(battle_config.emblem_transparency_limit != 100) {
+		int i, j, transcount = 1, tmp[3];
+		for(i = offset; i < buf_len-1; i++) {
 			j = i%3;
 			j = i%3;
 			tmp[j] = RBUFL(buf,i);
 			tmp[j] = RBUFL(buf,i);
-			if(j==2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
+			if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
 				transcount++;
 				transcount++;
 		}
 		}
 		if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
 		if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
@@ -16937,7 +16945,7 @@ void clif_parse_client_version(int fd,struct map_session_data *sd){
 void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
 void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
 	const char* name;
 	const char* name;
 	struct fame_list* list;
 	struct fame_list* list;
-	int i, skip=0;
+	int skip = 0;
 
 
 	switch(rankingtype+1) //to keep the same case as char.c
 	switch(rankingtype+1) //to keep the same case as char.c
 	{
 	{
@@ -16947,7 +16955,9 @@ void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, i
 	default: skip=1; break;
 	default: skip=1; break;
 	}
 	}
 
 
-	if(!skip){
+	if(!skip) {
+		int i;
+
 		//Packet size limits this list to 10 elements. [Skotlex]
 		//Packet size limits this list to 10 elements. [Skotlex]
 		for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
 		for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
 			if (list[i].id > 0) {
 			if (list[i].id > 0) {

+ 3 - 1
src/map/itemdb.c

@@ -674,7 +674,7 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 	while (fgets(line,sizeof(line),fp)) {
 	while (fgets(line,sizeof(line),fp)) {
 		uint16 nameid;
 		uint16 nameid;
 		int j, group_id, prob = 1, amt = 1, rand_group = 1, announced = 0, dur = 0, named = 0, bound = 0;
 		int j, group_id, prob = 1, amt = 1, rand_group = 1, announced = 0, dur = 0, named = 0, bound = 0;
-		char *str[3], *p, w1[1024], w2[1024];
+		char *str[3], *p;
 		bool found = false;
 		bool found = false;
 		struct s_item_group_random *random;
 		struct s_item_group_random *random;
 
 
@@ -682,6 +682,8 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 		if (line[0] == '/' && line[1] == '/')
 		if (line[0] == '/' && line[1] == '/')
 			continue;
 			continue;
 		if (strstr(line,"import")) {
 		if (strstr(line,"import")) {
+			char w1[1024], w2[1024];
+
 			if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2 &&
 			if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2 &&
 				strcmpi(w1,"import") == 0)
 				strcmpi(w1,"import") == 0)
 			{
 			{

+ 6 - 3
src/map/npc.c

@@ -665,7 +665,6 @@ int npc_timerevent_start(struct npc_data* nd, int rid)
 int npc_timerevent_stop(struct npc_data* nd)
 int npc_timerevent_stop(struct npc_data* nd)
 {
 {
 	struct map_session_data *sd = NULL;
 	struct map_session_data *sd = NULL;
-	const struct TimerData *td = NULL;
 	int *tid;
 	int *tid;
 
 
 	nullpo_ret(nd);
 	nullpo_ret(nd);
@@ -683,6 +682,8 @@ int npc_timerevent_stop(struct npc_data* nd)
 	// Delete timer
 	// Delete timer
 	if ( *tid != INVALID_TIMER )
 	if ( *tid != INVALID_TIMER )
 	{
 	{
+		const struct TimerData *td = NULL;
+
 		td = get_timer(*tid);
 		td = get_timer(*tid);
 		if( td && td->data )
 		if( td && td->data )
 			ers_free(timer_event_ers, (void*)td->data);
 			ers_free(timer_event_ers, (void*)td->data);
@@ -2675,7 +2676,6 @@ static const char* npc_skip_script(const char* start, const char* buffer, const
  */
  */
 static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, bool runOnInit) {
 static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, bool runOnInit) {
 	int x, y, dir = 0, m, xs = 0, ys = 0;	// [Valaris] thanks to fov
 	int x, y, dir = 0, m, xs = 0, ys = 0;	// [Valaris] thanks to fov
-	char mapname[32];
 	struct script_code *script;
 	struct script_code *script;
 	int i;
 	int i;
 	const char* end;
 	const char* end;
@@ -2693,6 +2693,8 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 	}
 	}
 	else
 	else
 	{// npc in a map
 	{// npc in a map
+		char mapname[32];
+
 		if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 )
 		if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 )
 		{
 		{
 			ShowError("npc_parse_script: Invalid placement format for a script in file '%s', line '%d'. Skipping the rest of file...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
 			ShowError("npc_parse_script: Invalid placement format for a script in file '%s', line '%d'. Skipping the rest of file...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
@@ -2814,7 +2816,6 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
 const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
 {
 {
 	int x, y, dir, m, xs = -1, ys = -1;
 	int x, y, dir, m, xs = -1, ys = -1;
-	char mapname[32];
 	char srcname[128];
 	char srcname[128];
 	int i;
 	int i;
 	const char* end;
 	const char* end;
@@ -2849,6 +2850,8 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
 		x = y = dir = 0;
 		x = y = dir = 0;
 		m = -1;
 		m = -1;
 	} else {
 	} else {
+		char mapname[32];
+
 		if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 ) { // <map name>,<x>,<y>,<facing>
 		if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 ) { // <map name>,<x>,<y>,<facing>
 			ShowError("npc_parse_duplicate: Invalid placement format for duplicate in file '%s', line '%d'. Skipping line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
 			ShowError("npc_parse_duplicate: Invalid placement format for duplicate in file '%s', line '%d'. Skipping line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
 			return end;// next line, try to continue
 			return end;// next line, try to continue

+ 25 - 15
src/map/skill.c

@@ -2391,8 +2391,11 @@ int skill_blown(struct block_list* src, struct block_list* target, int count, in
 }
 }
 
 
 
 
-//Checks if 'bl' should reflect back a spell cast by 'src'.
-//type is the type of magic attack: 0: indirect (aoe), 1: direct (targetted)
+// Checks if 'bl' should reflect back a spell cast by 'src'.
+// type is the type of magic attack: 0: indirect (aoe), 1: direct (targetted)
+// In case of success returns type of reflection, otherwise 0
+//		1 - Regular reflection (Maya)
+//		2 - SL_KAITE reflection
 static int skill_magic_reflect(struct block_list* src, struct block_list* bl, int type)
 static int skill_magic_reflect(struct block_list* src, struct block_list* bl, int type)
 {
 {
 	struct status_change *sc = status_get_sc(bl);
 	struct status_change *sc = status_get_sc(bl);
@@ -2766,7 +2769,13 @@ int64 skill_attack (int attack_type, struct block_list* src, struct block_list *
 		 * Official Magic Reflection Behavior : damage reflected depends on gears caster wears, not target
 		 * Official Magic Reflection Behavior : damage reflected depends on gears caster wears, not target
 		 **/
 		 **/
 		#if MAGIC_REFLECTION_TYPE
 		#if MAGIC_REFLECTION_TYPE
-			if( dmg.dmg_lv != ATK_MISS ){//Wiz SL cancelled and consumed fragment
+#ifdef RENEWAL
+			if( dmg.dmg_lv != ATK_MISS ) { //Wiz SL cancelled and consumed fragment
+#else
+			// issue:6415 in pre-renewal Kaite reflected the entire damage received
+			// regardless of caster's equipment (Aegis 11.1)
+			if( dmg.dmg_lv != ATK_MISS && type == 1 ) { //Wiz SL cancelled and consumed fragment
+#endif
 				short s_ele = skill_get_ele(skill_id, skill_lv);
 				short s_ele = skill_get_ele(skill_id, skill_lv);
 
 
 				if (s_ele == -1) // the skill takes the weapon's element
 				if (s_ele == -1) // the skill takes the weapon's element
@@ -9564,21 +9573,22 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 	case SO_EL_ACTION:
 	case SO_EL_ACTION:
 		if( sd ) {
 		if( sd ) {
 				int duration = 3000;
 				int duration = 3000;
-			if( !sd->ed )	break;
+			if( !sd->ed )
+				break;
+			switch(sd->ed->db->class_) {
+				case 2115:case 2124:
+				case 2118:case 2121:
+					duration = 6000;
+					break;
+				case 2116:case 2119:
+				case 2122:case 2125:
+					duration = 9000;
+					break;
+			}
 			sd->skill_id_old = skill_id;
 			sd->skill_id_old = skill_id;
 			elemental_action(sd->ed, bl, tick);
 			elemental_action(sd->ed, bl, tick);
 			clif_skill_nodamage(src,bl,skill_id,skill_lv,1);
 			clif_skill_nodamage(src,bl,skill_id,skill_lv,1);
-				switch(sd->ed->db->class_){
-					case 2115:case 2124:
-					case 2118:case 2121:
-						duration = 6000;
-						break;
-					case 2116:case 2119:
-					case 2122:case 2125:
-						duration = 9000;
-						break;
-				}
-				skill_blockpc_start(sd, skill_id, duration);
+			skill_blockpc_start(sd, skill_id, duration);
 		}
 		}
 		break;
 		break;