From 12d02b95e5dc85688d3fd67d051d1f21ae0e438f Mon Sep 17 00:00:00 2001
From: "(no author)" <(no author)@54d463be-8e91-2dee-dedb-b68131a5f0ec>
Date: Sun, 13 Feb 2005 04:25:58 +0000
Subject: [PATCH] Merged jA's equipment breaking system into the current one

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@1099 54d463be-8e91-2dee-dedb-b68131a5f0ec
---
 Changelog-SVN.txt |  6 ++++
 db/item_db.txt    | 18 +++++------
 src/map/map.h     |  4 +--
 src/map/pc.c      | 77 +++++------------------------------------------
 src/map/pc.h      |  7 +++--
 5 files changed, 29 insertions(+), 83 deletions(-)

diff --git a/Changelog-SVN.txt b/Changelog-SVN.txt
index 884c71ce7c..24a40f96fd 100644
--- a/Changelog-SVN.txt
+++ b/Changelog-SVN.txt
@@ -1,5 +1,11 @@
 Date	Added
 
+02/13
+        * Merged jA's equipment breaking system into the current one, and corrected
+          items with unbreakable effects in the item_db [celest]
+          - "bonus bUnbreakable,[chance];" changed to
+            "bonus bUnbreakable[Weapon/Armor/Helm/Shield],0;"
+
 02/12
         * Merged Dexity's pc_statpointdb into pc_readdb, changed statp's string
           array to short (less memory), and fixed the db not giving status points if
diff --git a/db/item_db.txt b/db/item_db.txt
index 0bcfea23a1..aa3a3f235a 100644
--- a/db/item_db.txt
+++ b/db/item_db.txt
@@ -458,7 +458,7 @@
 1121,Tsurugi__,Tsurugi,4,51000,0,1200,130,,1,0,414946,2,2,3,27,2,{},{}
 1122,Ring_Pommel_Saber,Ring Pommel Saber,4,24000,0,900,100,,1,2,414946,2,2,2,14,2,{},{}
 1123,Haedonggum,Haedonggum,4,50000,0,900,120,,1,1,414946,2,2,3,27,2,{},{ bonus bInt,3; }
-1124,Orcish_Sword,Orcish sword,4,20,0,800,90,,1,0,8803555,2,2,3,5,2,{},{ bonus bUnbreakable,100; }
+1124,Orcish_Sword,Orcish sword,4,20,0,800,90,,1,0,8803555,2,2,3,5,2,{},{ bonus bUnbreakableWeapon,0; }
 1125,Ring_Pommel_Saber_,Ring Pommel Saber,4,24000,0,900,100,,1,3,414946,2,2,2,14,2,{},{}
 1126,Saber,Saber,4,49000,0,1000,115,,1,2,414946,2,2,3,27,2,{},{}
 1127,Saber_,Saber,4,49000,0,1000,115,,1,3,414946,2,2,3,27,2,{},{}
@@ -498,7 +498,7 @@
 1165,Masamune,Masamune,4,20,0,1000,200,,1,0,16514,2,34,4,48,3,{},{ bonus bFlee,30; bonus bStr,-5; bonus bAspd,2; bonus bDefRate,-50; bonus bDef2Rate,-50; },
 1166,Dragon_Slayer,Dragon Slayer,4,20,0,1300,150,,1,0,16514,2,34,4,48,3,{},{ bonus bIgnoreDefRace,9; bonus2 bAddRace,9,15; }
 1167,Schweizersabel,Schweizersabel,4,20,0,1600,160,,1,0,16514,2,34,4,48,3,{},{ bonus bAtkEle,4; skill 20,3; bonus bDef,1; bonus3 bAutoSpell,20,3,25; }
-1168,Zweihander,Zweihander,4,20,0,2200,200,,1,0,16514,2,34,4,48,3,{},{bonus bUnbreakable,100; }
+1168,Zweihander,Zweihander,4,20,0,2200,200,,1,0,16514,2,34,4,48,3,{},{bonus bUnbreakableWeapon,0; }
 1169,Executioner_,Executioner,4,20,0,2200,155,,1,0,16514,2,34,4,48,3,{},{ bonus bIgnoreDefRace,7; bonus2 bAddRace,7,20; bonus2 bSubRace,7,-10; bonus bAtkEle,7; }
 1170,Katzbalger,Katzbalger,4,20,0,2000,175,,1,0,16514,2,34,4,48,3,{},{ bonus bVit,10; bonus bDef,10; }
 // Knifes and Daggers
@@ -537,7 +537,7 @@
 1233,Exercise,Excorcise,4,20,0,700,90,,1,0,2055918,2,2,4,36,1,{},{ bonus bIgnoreDefRace,6; bonus2 bSubRace,6,5; bonus2 bSubRace,7,-10; },
 1234,Moonlight_Sword,Walgwanggum,4,20,0,700,50,,1,0,2055918,2,2,4,36,1,{},{ bonus bMaxSPrate,10; bonus2 bSPDrainRate,100,3; }
 1235,Azoth,Azoth,4,20,0,700,110,,1,0,262144,2,2,4,36,1,{},{ bonus bClassChange,50; }
-1236,Sucsamad,Sucsamad,4,20,0,800,140,,1,0,2055918,2,2,4,36,1,{},{ bonus2 bAddEle,2,10; bonus2 bAddEle,4,10; bonus bUnbreakable,100; }
+1236,Sucsamad,Sucsamad,4,20,0,800,140,,1,0,2055918,2,2,4,36,1,{},{ bonus2 bAddEle,2,10; bonus2 bAddEle,4,10; bonus bUnbreakableWeapon,0; }
 1237,Grimtooth_,Grimtooth,4,20,0,800,180,,1,0,2055918,2,2,4,36,1,{},{ bonus bFlee,10; bonus bFlee2,5; bonus bDefRate,-50; bonus bDef2Rate,-50; }
 1238,Zeny_Knife,Zeny Knife,4,20,0,1200,64,,1,0,2055918,2,2,3,40,1,{},{ bonus bGetZenyNum,100; }
 1239,Poison_Knife,Poison Knife,4,20,0,800,64,,1,0,2055918,2,2,3,65,1,{},{ bonus bAtkEle,5; bonus2 bAddEff,Eff_Poison,3000; }
@@ -650,7 +650,7 @@
 1521,Chain__,Chain,4,23000,0,800,84,,1,3,312754,2,2,2,14,8,{},{}
 1522,Stunner,Stunner,4,60000,0,2000,140,,1,0,33040,2,2,3,27,8,{},{ bonus2 bAddEff,Eff_Stan,1000; }
 1523,Spike,Spike,4,20,0,700,85,,1,0,33040,2,2,4,40,8,{},{ bonus bCritical,40; bonus bDefRate,-67; bonus bDef2Rate,-67; }
-1524,Golden_Mace,Golden Mace,4,20,0,800,110,,1,1,33040,2,2,4,40,8,{},{ bonus2 bAddRace,1,10; bonus bUnbreakable,100; }
+1524,Golden_Mace,Golden Mace,4,20,0,800,110,,1,1,33040,2,2,4,40,8,{},{ bonus2 bAddRace,1,10; bonus bUnbreakableWeapon,0; }
 1525,Long_Mace,Long Mace,4,20,0,800,135,,3,0,33040,2,2,4,40,8,{},{ bonus bLongAtkDef,10; }
 1526,Slash,Slash,4,20,0,1000,145,,1,0,33040,2,2,4,40,8,{},{ bonus2 bAddRace,1,15; bonus2 bWeaponComaRace,1,50; }
 1527,Quadrille,Quadrille,4,20,0,900,165,,1,0,33040,2,2,4,40,8,{},{ bonus2 bAddRace,1,10; bonus2 bAddRace,7,10; bonus2 bAddEle,2,10; }
@@ -792,7 +792,7 @@
 2108,Mirror_Shield_,Mirror Shield,5,60000,0,1000,,4,,1,16514,2,32,,0,4,{},{ bonus bMdef,5; }
 2109,Memorize_Book,Book of Summoning,5,20,0,1000,,3,,0,66052,2,32,,0,,{},{ bonus bInt,1; bonus bMdef,2; },
 2110,Holy_Guard,Holy Guard,5,20,0,1400,,5,,0,16384,2,32,,68,3,{},{ bonus bVit,2; bonus bMdef,2; },
-2111,Evangelist,Evangelist,5,20,0,1400,,5,,0,16384,2,32,,83,3,{},{ bonus bVit,3; bonus bInt,2; bonus bMdef,3; bonus bUnbreakable,100; }
+2111,Evangelist,Evangelist,5,20,0,1400,,5,,0,16384,2,32,,83,3,{},{ bonus bVit,3; bonus bInt,2; bonus bMdef,3; bonus bUnbreakableShield,0; }
 2112,Novice_Guard,Novice Guard,5,20,0,1,,3,,0,8388609,2,32,,0,1,{},{}
 2199,Ahura_Mazda,Ahura Mazda,5,20,0,100,,,,0,10477567,2,32,,,,{},{ bonus bMdef,1; bonus bDef,1; bonus bFlee2,1; bonus2 bSubEle,0,1; }
 
@@ -980,7 +980,7 @@
 2505,Manteau,Manteau,5,32000,0,600,,4,,0,414946,2,4,,0,0,{},{}
 2506,Manteau_,Manteau,5,32000,0,600,,4,,1,414946,2,4,,0,0,{},{}
 2507,Cape_Of_Ancient_Lord,Cape of Old Marquess,5,20,0,600,,2,,0,2088958,2,4,,40,0,{},{ bonus bAgi,1; }
-2508,Ragamuffin_Cape,Ragamuffin Manteau,5,20,0,500,,1,,0,2088958,2,4,,0,0,{},{ bonus bMdef,10; bonus bUnbreakable,100; }
+2508,Ragamuffin_Cape,Ragamuffin Manteau,5,20,0,500,,1,,0,2088958,2,4,,0,0,{},{ bonus bMdef,10; bonus bUnbreakableArmor,0; }
 2509,Manteau_of_Survival,Manteau of Life,5,20,0,550,,0,,0,66052,2,4,,75,0,{},{ bonus bVit,10; }
 2510,Hood_For_Novice,Novice Hood,5,20,0,1,,2,,0,8388609,2,4,,0,0,{},{}
 2511,Skeleton_Manteau,Skeleton's Manteau,5,20,0,700,,1,,,2088958,2,4,,75,,{},{}
@@ -1088,7 +1088,7 @@
 4058,Thara_Frog_Card,Thara Frog Card,6,20,0,10,,,,,,,32,,,,{},{ bonus2 bSubRace,7,30; }
 4059,Soldier_Andre_Card,Soldier Andre Card,6,20,0,10,,,,,,,32,,,,{},{ bonus2 bSubRace,3,30; }
 4060,Goblin_Card,Goblin Card,6,20,0,10,,,,,,,2,,,,{},{ bonus2 bAddRace,2,20; }
-4061,Cornutus_Card,Cornutus Card,6,20,0,10,,,,,,,16,,,,{},{ bonus bDef,1; }
+4061,Cornutus_Card,Cornutus Card,6,20,0,10,,,,,,,16,,,,{},{ bonus bUnbreakableWeapon,0; bonus bDef,1; }
 4062,Anacondaq_Card,Anacondaq Card,6,20,0,10,,,,,,,2,,,,{},{ bonus2 bAddEle,5,20; }
 4063,Caramel_Card,Caramel Card,6,20,0,10,,,,,,,2,,,,{},{ bonus2 bAddRace,4,20; }
 4064,Zerom_Card,Zerom Card,6,20,0,10,,,,,,,136,,,,{},{ bonus bDex,3; }
@@ -1099,7 +1099,7 @@
 4069,Drainliar_Card,Drainliar Card,6,20,0,10,,,,,,,2,,,,{},{ bonus2 bAddEle,1,20; }
 4070,Eggyra_Card,Eggyra Card,6,20,0,10,,,,,,,64,,,,{},{ bonus bSPrecovRate,15; }
 4071,Orc_Zombie_Card,Orc Zombie Card,6,20,0,10,,,,,,,4,,,,{},{ bonus2 bSubEle,9,30; bonus bFlee,5; }
-4072,Golem_Card,Golem Card,6,20,0,10,,,,,,,2,,,,{},{ bonus bBaseAtk,5; }
+4072,Golem_Card,Golem Card,6,20,0,10,,,,,,,2,,,,{},{ bonus bUnbreakableWeapon,0; bonus bBaseAtk,5; }
 4073,Pirate_Skel_Card,Pirate Skel Card,6,20,0,10,,,,,,,136,,,,{},{ skill 37,5; }
 4074,BigFoot_Card,BigFoot Card,6,20,0,10,,,,,,,32,,,,{},{ bonus2 bSubRace,4,30; }
 4075,Argos_Card,Argos Card,6,20,0,10,,,,,,,32,,,,{},{ bonus2 bResEff,Eff_Stone,2000; bonus bDef,1; }
@@ -1379,7 +1379,7 @@
 5006,Machoman_Glasses,Machoman's Glasses,5,36000,0,100,,1,,0,10477567,2,512,,0,92,{},{}
 5007,Grand_Circlet,Grand Circlet,5,20,0,200,,3,,0,10477567,2,256,,55,93,{},{ bonus bMdef,4; bonus bStr,1; bonus bInt,1; bonus bLuk,1; }
 5008,Puppy_Love,Puppy Love,5,20,0,100,,1,,0,10477567,2,256,,0,94,{},{}
-5009,Safety_Helmet,Safety Helmet,5,20,0,500,,3,,0,10477567,2,256,,0,95,{},{ bonus bMdef,3; bonus bUnbreakable,100; }
+5009,Safety_Helmet,Safety Helmet,5,20,0,500,,3,,0,10477567,2,256,,0,95,{},{ bonus bMdef,3; bonus bUnbreakableHelm,0; }
 5010,Indian_Hair_Piece,Indian Fillet,5,20,0,100,,3,,0,10477567,2,256,,0,96,{},{}
 5011,Aerial,Aerial,5,20,0,100,,3,,0,10477567,2,256,,0,97,{},{}
 5012,Ph.D_Hat,Ph.D Hat,5,20,0,200,,3,,0,10477567,2,256,,0,98,{},{ bonus bMdef,3; }
diff --git a/src/map/map.h b/src/map/map.h
index 7238974fd0..91e296f694 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -159,8 +159,6 @@ struct map_session_data {
 		unsigned no_weapon_damage : 1;
 		unsigned no_gemstone : 1;
 		unsigned infinite_endure : 1;
-		unsigned unbreakable_weapon : 1;
-		unsigned unbreakable_armor : 1;
 		unsigned infinite_autospell : 1;
 	} special_state;
 	int char_id, login_id1, login_id2, sex;
@@ -169,6 +167,7 @@ struct map_session_data {
 	struct item_data *inventory_data[MAX_INVENTORY];
 	short equip_index[11];
 	unsigned short unbreakable_equip;
+	unsigned short unbreakable;	// chance to prevent equipment breaking [celest]
 	int weight,max_weight;
 	int cart_weight,cart_max_weight,cart_num,cart_max_num;
 	char mapname[24];
@@ -282,7 +281,6 @@ struct map_session_data {
 	int magic_damage_return; // AppleGirl Was Here
 	int random_attack_increase_add,random_attack_increase_per; // [Valaris]
 	int perfect_hiding; // [Valaris]
-	int unbreakable;
 	int classchange; // [Valaris]
 
 	int die_counter;
diff --git a/src/map/pc.c b/src/map/pc.c
index 9134b40f68..af22970833 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -583,10 +583,11 @@ int pc_break_equip(struct map_session_data *sd, unsigned short where)
 	int sc;
 	char output[255];
 
-	if(sd == NULL)
-		return -1;
+	nullpo_retr(-1, sd);
 	if(sd->unbreakable_equip & where)
 		return 0;
+	if(sd->unbreakable >= rand()%100)
+		return 0;
 	switch (where) {
 		case EQP_WEAPON:
 			sc = SC_CP_WEAPON;
@@ -603,14 +604,15 @@ int pc_break_equip(struct map_session_data *sd, unsigned short where)
 		default:
 			return 0;
 	}
-	if( sd->sc_data && sd->sc_data[sc].timer != -1 )
+	if(sd->sc_count && sd->sc_data[sc].timer != -1)
 		return 0;
 
 	for (i=0;i<MAX_INVENTORY;i++) {
-		if (sd->status.inventory[i].equip & where) {
+		if (sd->status.inventory[i].equip & where &&
+			!sd->status.inventory[i].attribute == 1) {
 			item=sd->inventory_data[i];
 			sd->status.inventory[i].attribute = 1;
-			pc_unequipitem(sd,i,0);
+			pc_unequipitem(sd,i,3);
 			sprintf(output, "%s has broken.",item->jname);
 			clif_emotion(&sd->bl,23);
 			clif_displaymessage(sd->fd, output);
@@ -619,72 +621,9 @@ int pc_break_equip(struct map_session_data *sd, unsigned short where)
 		}
 	}
 
-	return 0;
+	return 1;
 }
 
-/*==========================================
- * Weapon Breaking [Valaris]
- *------------------------------------------
- */
-int pc_breakweapon(struct map_session_data *sd)
-{
-	struct item_data* item;
-	char output[255];
-	int i;
-
-	if(sd==NULL)
-		return -1;
-	if(sd->unbreakable>=rand()%100)
-		return 0;
-	if(sd->sc_count && sd->sc_data[SC_CP_WEAPON].timer != -1)
-		return 0;
-
-	for(i=0;i<MAX_INVENTORY;i++){
-		if(sd->status.inventory[i].equip && sd->status.inventory[i].equip & 0x0002 && !sd->status.inventory[i].attribute==1){
-			item=sd->inventory_data[i];
-			sd->status.inventory[i].attribute=1;
-			pc_unequipitem(sd,i,3);
-			sprintf(output, "%s has broken.",item->jname);
-			clif_emotion(&sd->bl,23);
-			clif_displaymessage(sd->fd, output);
-			clif_equiplist(sd);
-			return 1;
-		}
-	}
-
-	return 0;
-}
-/*==========================================
- * Armor Breaking [Valaris]
- *------------------------------------------
- */
-int pc_breakarmor(struct map_session_data *sd)
-{
-	struct item_data* item;
-	char output[255];
-	int i;
-
-	if(sd==NULL)
-		return -1;
-	if(sd->unbreakable>=rand()%100)
-		return 0;
-	if(sd->sc_count && sd->sc_data[SC_CP_ARMOR].timer != -1)
-		return 0;
-
-	for(i=0;i<MAX_INVENTORY;i++){
-		if(sd->status.inventory[i].equip && sd->status.inventory[i].equip & 0x0010 && !sd->status.inventory[i].attribute==1){
-			item=sd->inventory_data[i];
-			sd->status.inventory[i].attribute=1;
-			pc_unequipitem(sd,i,3);
-			sprintf(output, "%s has broken.",item->jname);
-			clif_emotion(&sd->bl,23);
-			clif_displaymessage(sd->fd, output);
-			clif_equiplist(sd);
-		}
-	}
-
-	return 0;
-}
 /*==========================================
  * session id�ɖ�薳��
  * char�I���瑗���Ă����X�e?�^�X��ݒ�
diff --git a/src/map/pc.h b/src/map/pc.h
index 8c28e299a8..17fea9c13d 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -40,8 +40,11 @@ int pc_authfail(int);
 int pc_isequip(struct map_session_data *sd,int n);
 int pc_equippoint(struct map_session_data *sd,int n);
 
-int pc_breakweapon(struct map_session_data *sd); // weapon breaking [Valaris]
-int pc_breakarmor(struct map_session_data *sd); // armor breaking [Valaris]
+int pc_break_equip(struct map_session_data *, unsigned short);
+#define pc_breakweapon(sd)	(pc_break_equip(sd, EQP_WEAPON))
+#define pc_breakarmor(sd)	(pc_break_equip(sd, EQP_ARMOR))
+#define pc_breakshield(sd)	(pc_break_equip(sd, EQP_SHIELD))
+#define pc_breakhelm(sd)	(pc_break_equip(sd, EQP_HELM))
 
 int pc_checkskill(struct map_session_data *sd,int skill_id);
 int pc_checkallowskill(struct map_session_data *sd);