瀏覽代碼

Fixed card removal script functions' 'extra card' bug (bugreport:786)

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@12075 54d463be-8e91-2dee-dedb-b68131a5f0ec
ultramage 17 年之前
父節點
當前提交
88cfb8ff5a
共有 3 個文件被更改,包括 62 次插入259 次删除
  1. 2 1
      Changelog-Trunk.txt
  2. 0 197
      npc/sample/npc_card_remover.txt
  3. 60 61
      src/map/script.c

+ 2 - 1
Changelog-Trunk.txt

@@ -5,13 +5,14 @@ IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 
 2008/01/14
+	* Fixed card removal script functions' 'extra card' bug (bugreport:786)
 	* Removed the hardcoded limit for numeric npc input boxes (bugreport:811)
 	* Applied a temp patch to make some npc-executed atcommands work again
 	* Added support for right-click-gm-menu kicking NPC objects [ultramage]
 	* Fixed dangling pointer crashes when bleeding or Deadly poison kills a
 	  spawn-once monster.
 	* Fixed a possible ERS entry corruption when Deadly Poison kills a target
-	  that has kaziel active.
+	  that has kaizel active.
 2008/01/13
 	* Fixed a possible ers_entry corruption if you die from bleeding while
 	  under the effects of kaizel.

+ 0 - 197
npc/sample/npc_card_remover.txt

@@ -1,197 +0,0 @@
-// Card removal NPC by TyrNemesis^ 日本語訳:胡蝶蘭
-prt_in,28,73,4	script	賢い老女	78,{
-
-UPGRADEROOT:
-//	mes "[Wise Old Woman]";
-//	mes "Good day, young one. I have the power to remove cards that you have compounded onto your equipment. Does this idea please you?";
-	mes "[賢い老女]";
-	mes "いい天気だね、若いの。";
-	mes "ところで、アタシは武具に装着している";
-	mes "カードを取り外す力を持っているけど、";
-	mes "力を貸そうかね?";
-	next;
-//	menu "Yes, it does.",REMOVEMENU,
-//	     "What do you charge?",REMOVEPRICE,
-//	     "No thanks.",CLOSEOUT;
-	menu "お願いします。",REMOVEMENU,
-	     "いくらかかるんですか?",REMOVEPRICE,
-	     "必要ないです。",CLOSEOUT;
-
-REMOVEPRICE:
-//	mes "[Wise Old Woman]";
-//	mes "I charge a flat fee of 200000 zeny, plus 25000 zeny for each card I remove from the item. In addition, I need a star crumb and a yellow gemstone to work my magic.";
-	mes "[賢い老女]";
-	mes "そうだね、";
-	mes "まず基本料金として^4040FF200000z^000000。";
-	mes "そしてカード1枚につき^4040FF25000z^000000貰うよ。";
-	mes "あとは、魔法を使うために^4040FF星のかけら^000000と";
-	mes "^4040FFイエロージェムストーン^000000が1つずつ必要だよ。";
-	next;
-//	menu "Very well. Let's do it.",REMOVEMENU,
-//	     "No thanks.",CLOSEOUT;
-	menu "お願いします。",REMOVEMENU,
-	     "必要ないです。",CLOSEOUT;
-
-REMOVEMENU:
-//	mes "[Wise Old Woman]";
-//	mes "Very well. Which item shall I examine for you?";
-	mes "[賢い老女]";
-	mes "よしよし。";
-	mes "どの武具のカードを取り外すんだね?";
-	next;
-//	menu "I changed my mind.",CLOSEOUT,
-	menu "やっぱりやめます。",CLOSEOUT,
-	     getequipname(1),-,
-	     getequipname(2),-,
-	     getequipname(3),-,
-	     getequipname(4),-,
-	     getequipname(5),-,
-	     getequipname(6),-,
-	     getequipname(7),-,
-	     getequipname(8),-,
-	     getequipname(9),-,
-	     getequipname(10),-;
-	set @part,@menu-1;
-	if(getequipcardcnt(@part) == 0) goto DENYCARDCOUNT;
-	set @cardcount,getequipcardcnt(@part);
-//	if(@cardcount > 1) goto CARDNUMMULTIMSG;
-//	mes "[Wise Old Woman]";
-//	mes "This item has " + @cardcount + " card compounded on it. To perform my magic, I will need 225000 zeny, a ^0000FFStar Crumb^000000, and a ^0000FFYellow Gemstone^000000.";
-//	goto CARDNUMPOSTMSG;
-//CARDNUMMULTIMSG:
-//	mes "[Wise Old Woman]";
-//	mes "This item has " + @cardcount + " cards compounded on it. To perform my magic, I will need " + (200000+(@cardcount * 25000)) + " zeny, a ^0000FFStar Crumb^000000, and a ^0000FFYellow Gemstone^000000.";
-	mes "[賢い老女]";
-	mes "この武具には" + @cardcount + "つカードがついてるね。";
-	mes "^0000FF" + (200000+(@cardcount * 25000)) + "z^000000と^0000FF星のかけら^000000と^0000FFイエロージェムストーン^000000が必要だよ。";
-//CARDNUMPOSTMSG:
-	next;
-//	menu "Very well. Do it.",REMOVECARDWARNING,
-//	     "Never mind.",CLOSEOUT;
-	menu "わかりました、お願いします。",REMOVECARDWARNING,
-	     "やっぱりやめます。",CLOSEOUT;
-
-REMOVECARDWARNING:
-//	mes "[Wise Old Woman]";
-//	mes "Before I begin, I must warn you--I may fail. If I do, I may destroy the cards, the item, or both. I do not give refunds. That being said, which is more important to you: The cards, or the item?";
-	mes "[賢い老女]";
-	mes "おっと言い忘れるところだったね。";
-	mes "この魔法はとても難しいから、";
-	mes "^FF4040失敗するかもしれない^000000のさ。";
-	mes "失敗したらカードか武具、あるいは";
-	mes "その両方が^FF4040破壊されてしまう^000000かも";
-	mes "しれないんだよ。";
-	next;
-	mes "[賢い老女]";
-	mes "失敗しても^FF4040返金はしない^000000から、";
-	mes "一応聞いて置くけど、比べるなら";
-	mes "カードと武具のどっちが大切だい?";
-	next;
-//	menu "I changed my mind about this.",CLOSEOUT,
-//	     "The item.",PRIORITYITEM,
-//	     "The cards.",PRIORITYCARD;
-	menu "それならやめます。",CLOSEOUT,
-	     "武具の方が大切です。",PRIORITYITEM,
-	     "カードの方が大切です",PRIORITYCARD;
-
-PRIORITYITEM:
-	set @failtype,1;
-	goto REMOVECARD;
-
-PRIORITYCARD:
-	set @failtype,2;
-	goto REMOVECARD;
-
-REMOVECARD:
-//	mes "[Wise Old Woman]";
-//	mes "Very well. I shall begin.";
-	mes "[賢い老女]";
-	mes "よし、始めるよ。";
-	next;
-	if((zeny < (200000+(@cardcount * 25000))) || (countitem(1000) < 1) || (countitem(715) < 1)) goto DENYMATERIAL;
-	set zeny,zeny - (200000+(@cardcount * 25000));
-	delitem 1000,1;
-	delitem 715,1;
-
-// Replace the constants in the next 3 lines with failure chance values defined in refine_db.txt
-// First value = Total failure chance (item and cards destroyed)
-// Second value = Partial failure chance (one or the other is destroyed, player decides which one is safe)
-// Third value = Harmless failure chance (all that's lost is your investment)
-
-	set @failchance,rand(100);
-	if(@failchance < 2) goto FAILREMOVECARD0;
-	if((@failchance < 6) && (@failtype == 1)) goto FAILREMOVECARD1;
-	if((@failchance < 6) && (@failtype == 2)) goto FAILREMOVECARD2;
-	if(@failchance < 10) goto FAILREMOVECARD3;
-	successremovecards @part;
-//	mes "[Wise Old Woman]";
-//	mes "The process was a success. Here are your cards and your item. Farewell.";
-	mes "[賢い老女]";
-	mes "うまくいったよ。";
-	mes "これらが武具とアイテムさ。じゃあね。";
-	close;
-
-FAILREMOVECARD0:
-//	mes "[Wise Old Woman]";
-//	mes "The process was a total failure. I am afraid the item and the cards were destroyed.";
-	mes "[賢い老女]";
-	mes "残念だけど完全に失敗したよ。";
-	mes "武具もカードも壊れてしまった。";
-	failedremovecards @part,0;
-	close;
-
-FAILREMOVECARD1:
-//	mes "[Wise Old Woman]";
-//	mes "While I have managed to remove the cards from the item, they were destroyed in the process. The item, however, is okay.";
-	mes "[賢い老女]";
-	mes "頑張ったけどね、";
-	mes "カードのほうは全部壊れてしまったよ。";
-	mes "でも武具の方は無事だったよ。";
-	failedremovecards @part,1;
-	close;
-
-FAILREMOVECARD2:
-//	mes "[Wise Old Woman]";
-//	mes "Most unfortunate. I succeeded at removing the cards, but the item itself was destroyed in the process.";
-	mes "[賢い老女]";
-	mes "不運だったね。";
-	mes "カードを取り外すのはうまくいったけど";
-	mes "武具が壊れてしまったよ。";
-	failedremovecards @part,2;
-	close;
-
-FAILREMOVECARD3:
-//	mes "[Wise Old Woman]";
-//	mes "I have failed to remove the cards. Luckily, however, both the item and the cards are still okay.";
-	mes "[賢い老女]";
-	mes "カードを取り外すのに失敗したよ。";
-	mes "でも、不幸中の幸いさ。";
-	mes "武具もカードも無事だよ。";
-	failedremovecards @part,3;
-	close;
-
-DENYCARDCOUNT:
-//	mes "[Wise Old Woman]";
-//	mes "Young one... There are no cards compounded on this item. I can do nothing with it, I'm afraid.";
-	mes "[賢い老女]";
-	mes "若いの、カードがついてないよ。";
-	mes "それじゃアタシの出番はないさ。";
-	close;
-
-DENYMATERIAL:
-//	mes "[Wise Old Woman]";
-//	mes "You do not have all the items I require to work my magic, child. Come again when you do.";
-	mes "[賢い老女]";
-	mes "必要なアイテムが足りないようだね。";
-	mes "アイテムを揃えてもう一度来な。";
-	close;
-
-CLOSEOUT:
-//	mes "[Wise Old Woman]";
-//	mes "Very well. Return at once if you seek my services.";
-	mes "[賢い老女]";
-	mes "わかったよ。";
-	mes "アタシの力が必要ならいつでも来な。";
-	close;
-
-}

+ 60 - 61
src/map/script.c

@@ -9261,14 +9261,13 @@ BUILDIN_FUNC(requestguildinfo)
 	return 0;
 }
 
-/* =====================================================================
- * カードの数を得る
- * ---------------------------------------------------------------------*/
+/// Returns the number of cards that have been compounded onto the specified equipped item.
+/// getequipcardcnt(<equipment slot>);
 BUILDIN_FUNC(getequipcardcnt)
 {
-	int i=-1,num;
+	int i=-1,j,num;
 	TBL_PC *sd;
-	int c=MAX_SLOTS;
+	int count;
 
 	num=script_getnum(st,2);
 	sd=script_rid2sd(st);
@@ -9285,46 +9284,44 @@ BUILDIN_FUNC(getequipcardcnt)
 		script_pushint(st,0);
 		return 0;
 	}
-	do{
-		if(sd->status.inventory[i].card[c-1] &&
-			itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){	// [Celest]
-			script_pushint(st,(c));
-			return 0;
-		}
-	}while(c--);
-	script_pushint(st,0);
+
+	count = 0;
+	for( j = 0; j < MAX_SLOTS; j++ )
+		if( sd->status.inventory[i].card[j] && itemdb_type(sd->status.inventory[i].card[j]) == IT_CARD )
+			count++;
+
+	script_pushint(st,count);
 	return 0;
 }
 
-/* ================================================================
- * カード取り外し成功
- * ----------------------------------------------------------------*/
+/// Removes all cards from the item found in the specified equipment slot of the invoking character,
+/// and give them to the character. If any cards were removed in this manner, it will also show a success effect.
+/// successremovecards <slot>;
 BUILDIN_FUNC(successremovecards)
 {
-	int i=-1,j,num,cardflag=0,flag;
-	TBL_PC *sd;
-	struct item item_tmp;
-	int c=MAX_SLOTS;
+	int i=-1,j,c,cardflag=0;
+
+	TBL_PC* sd = script_rid2sd(st);
+	int num = script_getnum(st,2);
 
-	num=script_getnum(st,2);
-	sd=script_rid2sd(st);
 	if (num > 0 && num <= ARRAYLENGTH(equip))
 		i=pc_checkequip(sd,equip[num-1]);
 
 	if (i < 0) {
-		script_pushint(st,0);
 		return 0;
 	}
 
 	if(itemdb_isspecial(sd->status.inventory[i].card[0])) 
 		return 0;
 
-	do{
-		if(sd->status.inventory[i].card[c-1] &&
-			itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){	// [Celest]
-
+	for( c = MAX_SLOTS - 1; c >= 0; --c )
+	{
+		if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD )
+		{// extract this card from the item
+			int flag;
+			struct item item_tmp;
 			cardflag = 1;
-			item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
+			item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c];
 			item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
 			item_tmp.attribute=0;
 			for (j = 0; j < MAX_SLOTS; j++)
@@ -9339,20 +9336,22 @@ BUILDIN_FUNC(successremovecards)
 				map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
 			}
 		}
-	}while(c--);
+	}
 
-	if(cardflag == 1){	// カードを取り除いたアイテム所得
-		flag=0;
+	if(cardflag == 1)
+	{	// カードを取り除いたアイテム所得
+		int flag;
+		struct item item_tmp;
 		item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
 		item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
 		item_tmp.attribute=sd->status.inventory[i].attribute;
+		for (j = 0; j < MAX_SLOTS; j++)
+			item_tmp.card[j]=0;
 
 		//Logs items, got from (N)PC scripts [Lupus]
 		if(log_config.enable_logs&0x40)
 			log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
 
-		for (j = 0; j < MAX_SLOTS; j++)
-			item_tmp.card[j]=0;
 		pc_delitem(sd,i,1,0);
 
 		//Logs items, got from (N)PC scripts [Lupus]
@@ -9363,45 +9362,46 @@ BUILDIN_FUNC(successremovecards)
 			clif_additem(sd,0,0,flag);
 			map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
 		}
+
 		clif_misceffect(&sd->bl,3);
-		return 0;
 	}
 	return 0;
 }
 
-/* ================================================================
- * カード取り外し失敗 slot,type
- * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
- * ----------------------------------------------------------------*/
+/// Removes all cards from the item found in the specified equipment slot of the invoking character.
+/// failedremovecards <slot>, <type>;
+/// <type>=0 : will destroy both the item and the cards.
+/// <type>=1 : will keep the item, but destroy the cards.
+/// <type>=2 : will keep the cards, but destroy the item.
+/// <type>=? : will just display the failure effect.
 BUILDIN_FUNC(failedremovecards)
 {
-	int i=-1,j,num,cardflag=0,flag,typefail;
-	TBL_PC *sd;
-	struct item item_tmp;
-	int c=MAX_SLOTS;
+	int i=-1,j,c,cardflag=0;
+
+	TBL_PC* sd = script_rid2sd(st);
+	int num = script_getnum(st,2);
+	int typefail = script_getnum(st,3);
 
-	num=script_getnum(st,2);
-	typefail=script_getnum(st,3);
-	sd=script_rid2sd(st);
 	if (num > 0 && num <= ARRAYLENGTH(equip))
 		i=pc_checkequip(sd,equip[num-1]);
 
-	if (i < 0) {
-		script_pushint(st,0);
+	if (i < 0)
 		return 0;
-	}
 
 	if(itemdb_isspecial(sd->status.inventory[i].card[0]))
 		return 0;
 
-	do{
-		if(sd->status.inventory[i].card[c-1] &&
-			itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){	// [Celest]
-
+	for( c = MAX_SLOTS - 1; c >= 0; --c )
+	{
+		if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD )
+		{
 			cardflag = 1;
 
-			if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
-				item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
+			if(typefail == 2)
+			{// add cards to inventory, clear 
+				int flag;
+				struct item item_tmp;
+				item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c];
 				item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
 				item_tmp.attribute=0;
 				for (j = 0; j < MAX_SLOTS; j++)
@@ -9417,21 +9417,20 @@ BUILDIN_FUNC(failedremovecards)
 				}
 			}
 		}
-	}while(c--);
-
-	if(cardflag == 1){
+	}
 
+	if(cardflag == 1)
+	{
 		if(typefail == 0 || typefail == 2){	// 武具損失
 			//Logs items, got from (N)PC scripts [Lupus]
 			if(log_config.enable_logs&0x40)
 				log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
 
 			pc_delitem(sd,i,1,0);
-			clif_misceffect(&sd->bl,2);
-			return 0;
 		}
 		if(typefail == 1){	// カードのみ損失(武具を返す)
-			flag=0;
+			int flag;
+			struct item item_tmp;
 			item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
 			item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
 			item_tmp.attribute=sd->status.inventory[i].attribute;
@@ -9454,8 +9453,8 @@ BUILDIN_FUNC(failedremovecards)
 			}
 		}
 		clif_misceffect(&sd->bl,2);
-		return 0;
 	}
+
 	return 0;
 }