Pārlūkot izejas kodu

Cleaned up left handed checks (#4358)

* Fixes #4347.
* Cleaned up left handed weapon checks.
* Fixed a potential crash.
Thanks to @laziem!
Aleos 5 gadi atpakaļ
vecāks
revīzija
81c5dc9aaa
1 mainītis faili ar 14 papildinājumiem un 12 dzēšanām
  1. 14 12
      src/map/battle.cpp

+ 14 - 12
src/map/battle.cpp

@@ -2346,18 +2346,20 @@ static bool is_attack_right_handed(struct block_list *src, int skill_id)
 static bool is_attack_left_handed(struct block_list *src, int skill_id)
 {
 	if(src != NULL) {
-		struct status_data *sstatus = status_get_status_data(src);
-		struct map_session_data *sd = BL_CAST(BL_PC, src);
-
 		//Skills ALWAYS use ONLY your right-hand weapon (tested on Aegis 10.2)
 		if(!skill_id) {
-			if (sd && sd->weapontype1 == 0 && sd->weapontype2 > 0)
-				return true;
+			struct map_session_data *sd = BL_CAST(BL_PC, src);
 
-			if (sstatus->lhw.atk)
-				return true;
+			if (sd) {
+				if (sd->weapontype1 == 0 && sd->weapontype2 > 0)
+					return true;
+				if (sd->status.weapon == W_KATAR)
+					return true;
+			}
 
-			if (sd && sd->status.weapon == W_KATAR)
+			struct status_data *sstatus = status_get_status_data(src);
+
+			if (sstatus->lhw.atk)
 				return true;
 		}
 	}
@@ -4865,7 +4867,6 @@ static void battle_calc_attack_post_defense(struct Damage* wd, struct block_list
  */
 static void battle_calc_attack_plant(struct Damage* wd, struct block_list *src,struct block_list *target, uint16 skill_id, uint16 skill_lv)
 {
-	struct map_session_data *sd = BL_CAST(BL_PC, src);
 	struct status_data *tstatus = status_get_status_data(target);
 	bool attack_hits = is_attack_hitting(wd, src, target, skill_id, skill_lv, false);
 	int right_element = battle_get_weapon_element(wd, src, target, skill_id, skill_lv, EQI_HAND_R, false);
@@ -4879,11 +4880,12 @@ static void battle_calc_attack_plant(struct Damage* wd, struct block_list *src,s
 	if( attack_hits || wd->damage > 0 )
 		wd->damage = 1; //In some cases, right hand no need to have a weapon to deal a damage
 	if( is_attack_left_handed(src, skill_id) && (attack_hits || wd->damage2 > 0) ) {
-		if(sd->status.weapon == W_KATAR)
+		struct map_session_data *sd = BL_CAST(BL_PC, src);
+
+		if (sd && sd->status.weapon == W_KATAR)
 			wd->damage2 = 0; //No backhand damage against plants
-		else {
+		else
 			wd->damage2 = 1; //Deal 1 HP damage as long as there is a weapon in the left hand
-		}
 	}
 
 	if (attack_hits && target->type == BL_MOB) {