From 1e2032cc218ea9adc09046928d8dbbfc38e02dec Mon Sep 17 00:00:00 2001
From: Daegaladh <Daegaladh@users.noreply.github.com>
Date: Thu, 22 Feb 2018 22:23:11 +0100
Subject: [PATCH] Fixed Endow skills to match official behavior. (#2918)

* Endows are now interchangeable.
* No longer break the weapon on failure and now unequips instead.
Thanks to @Daegaladh!
---
 conf/msg_conf/map_msg.conf     |  2 +-
 conf/msg_conf/map_msg_chn.conf |  2 +-
 conf/msg_conf/map_msg_frn.conf |  2 +-
 conf/msg_conf/map_msg_idn.conf |  2 +-
 conf/msg_conf/map_msg_por.conf |  2 +-
 conf/msg_conf/map_msg_rus.conf |  2 +-
 conf/msg_conf/map_msg_spn.conf |  2 +-
 conf/msg_conf/map_msg_tha.conf |  2 +-
 src/map/skill.cpp              | 29 ++++++++++-------------------
 9 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/conf/msg_conf/map_msg.conf b/conf/msg_conf/map_msg.conf
index f95c7905a6..817250c868 100644
--- a/conf/msg_conf/map_msg.conf
+++ b/conf/msg_conf/map_msg.conf
@@ -690,7 +690,7 @@
 666: Pets are not allowed in Guild Wars.
 667: You're not dead.
 668: Your actual memo positions are:
-669: You broke the target's weapon.
+//669 free
 670: You can't leave battleground guilds.
 671: Friend already exists.
 672: Name not found in list.
diff --git a/conf/msg_conf/map_msg_chn.conf b/conf/msg_conf/map_msg_chn.conf
index 3c41d9ebaa..db259dd8b3 100644
--- a/conf/msg_conf/map_msg_chn.conf
+++ b/conf/msg_conf/map_msg_chn.conf
@@ -643,7 +643,7 @@
 666: 公會戰不允許有寵物
 667: 你沒死亡
 668: 你實際儲存點是:
-669: 你破壞目標的武器
+//669 free
 670: 你無法離開戰場公會
 671: 這朋友已存在
 672: 該名稱不在清單內
diff --git a/conf/msg_conf/map_msg_frn.conf b/conf/msg_conf/map_msg_frn.conf
index b840ada28b..4279933589 100644
--- a/conf/msg_conf/map_msg_frn.conf
+++ b/conf/msg_conf/map_msg_frn.conf
@@ -655,7 +655,7 @@
 666: Pets non-autoris�s lors d'une guerre entre guilde.
 667: Vous n'�tes pas mort(e).
 668: Votre position memo actuelle est:
-669: Vous brisez l'arme de la cible.
+//669 free
 670: Vous ne pouvez pas quitter votre guilde.
 671: Cette personne est d�j� dans votre liste d'ami.
 672: Nom introuvable dans la liste.
diff --git a/conf/msg_conf/map_msg_idn.conf b/conf/msg_conf/map_msg_idn.conf
index 56f4be3de8..79bc84e611 100644
--- a/conf/msg_conf/map_msg_idn.conf
+++ b/conf/msg_conf/map_msg_idn.conf
@@ -689,7 +689,7 @@
 666: Peliharaan tidak diperbolehkan di Guild Wars.
 667: Kamu tidak mati.
 668: Posisi memomu saat ini adalah:
-669: Kamu menghancurkan senajta lawan.
+//669 kosong
 670: Kamu tidak dapat meninggalkan guild battleground.
 671: Teman sudah ada.
 672: Nama tidak ditemukan di daftar.
diff --git a/conf/msg_conf/map_msg_por.conf b/conf/msg_conf/map_msg_por.conf
index 4c50bc8952..dddb8543fe 100644
--- a/conf/msg_conf/map_msg_por.conf
+++ b/conf/msg_conf/map_msg_por.conf
@@ -635,7 +635,7 @@
 666: Bichinhos de estima��o n�o s�o permitidos na Guerra de Cl�s.
 667: Voc� n�o est� morto.
 668: Seu ponto de retorno atual �:
-669: Voc� quebrou a arma de seu oponente.
+//669 livre
 670: Voc� n�o pode deixar os campos de batalha em uma guerra.
 671: Amigo j� existente.
 672: Nome n�o encontrado na lista.
diff --git a/conf/msg_conf/map_msg_rus.conf b/conf/msg_conf/map_msg_rus.conf
index 7db5bf6ee0..45e85f3189 100644
--- a/conf/msg_conf/map_msg_rus.conf
+++ b/conf/msg_conf/map_msg_rus.conf
@@ -655,7 +655,7 @@
 666: ������� ��������� �� ����� ����� �� ��������.
 667: �� �� ������.
 668: ���� ������� ����� ����������:
-669: �� ������� ������ ����.
+//669 �� ������������
 670: �� �� ������ �������� ��.
 671: ���� ��� ��������.
 672: ��� �� ������� � ������.
diff --git a/conf/msg_conf/map_msg_spn.conf b/conf/msg_conf/map_msg_spn.conf
index 68649dfe1d..14b7341dcc 100644
--- a/conf/msg_conf/map_msg_spn.conf
+++ b/conf/msg_conf/map_msg_spn.conf
@@ -690,7 +690,7 @@
 666: Las mascotas est�n prohibidas en la guerra de clanes.
 667: No est�s muerto.
 668: Tus puntos de memorizaci�n actuales son los siguientes:
-669: Has roto el arma de tu enemigo.
+//669 vac�o
 670: No puedes abandonar un clan especial de battleground.
 671: Ese jugador ya es amigo tuyo.
 672: No se ha encontrado el nombre que has introducido.
diff --git a/conf/msg_conf/map_msg_tha.conf b/conf/msg_conf/map_msg_tha.conf
index 023d73fe0c..758f03f575 100644
--- a/conf/msg_conf/map_msg_tha.conf
+++ b/conf/msg_conf/map_msg_tha.conf
@@ -649,7 +649,7 @@
 666: �ѵ������§�����١�Ѻ͹حҵ�������㹾�鹷�� Guild Wars.
 667: �س�������.
 668: ���˹觷��س��ѹ�֡����մѧ���:
-669: �س���������ظ�ͧ�������.
+//669 free
 670: �س�������ö�͡�ҡ Guild ��㹢������� battleground.
 671: ���͹�������������.
 672: ��辺�������¡��.
diff --git a/src/map/skill.cpp b/src/map/skill.cpp
index 28b5d290d3..ee2d11b0ed 100755
--- a/src/map/skill.cpp
+++ b/src/map/skill.cpp
@@ -6509,30 +6509,21 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 	case SA_FROSTWEAPON:
 	case SA_LIGHTNINGLOADER:
 	case SA_SEISMICWEAPON:
-		if (dstsd) {
-			if(dstsd->status.weapon == W_FIST ||
-				(dstsd->sc.count && !dstsd->sc.data[type] &&
-				(	//Allow re-enchanting to lenghten time. [Skotlex]
-					dstsd->sc.data[SC_FIREWEAPON] ||
-					dstsd->sc.data[SC_WATERWEAPON] ||
-					dstsd->sc.data[SC_WINDWEAPON] ||
-					dstsd->sc.data[SC_EARTHWEAPON] ||
-					dstsd->sc.data[SC_SHADOWWEAPON] ||
-					dstsd->sc.data[SC_GHOSTWEAPON] ||
-					dstsd->sc.data[SC_ENCPOISON]
-				))
-				) {
-				if (sd) clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
-				clif_skill_nodamage(src,bl,skill_id,skill_lv,0);
-				break;
-			}
+		if (dstsd && dstsd->status.weapon == W_FIST) {
+			if (sd)
+				clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
+			clif_skill_nodamage(src,bl,skill_id,skill_lv,0);
+			break;
 		}
 		// 100% success rate at lv4 & 5, but lasts longer at lv5
 		if(!clif_skill_nodamage(src,bl,skill_id,skill_lv, sc_start(src,bl,type,(60+skill_lv*10),skill_lv, skill_get_time(skill_id,skill_lv)))) {
+			if (dstsd){
+				short index = dstsd->equip_index[EQI_HAND_R];
+				if (index&EQP_WEAPON && dstsd->inventory_data[index]->type == IT_WEAPON)
+					pc_unequipitem(dstsd, index, 3); //Must unequip the weapon instead of breaking it [Daegaladh]
+			}
 			if (sd)
 				clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
-			if (skill_break_equip(src,bl, EQP_WEAPON, 10000, BCT_PARTY) && sd && sd != dstsd)
-				clif_displaymessage(sd->fd, msg_txt(sd,669));
 		}
 		break;