Pārlūkot izejas kodu

Adding new config min_npc_vending_distance which simulates the official 'no vending near npcs' feature. super mega credits to masao

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@16227 54d463be-8e91-2dee-dedb-b68131a5f0ec
shennetsind 13 gadi atpakaļ
vecāks
revīzija
049b2552cd
6 mainītis faili ar 42 papildinājumiem un 2 dzēšanām
  1. 4 0
      conf/battle/player.conf
  2. 1 0
      src/map/battle.c
  3. 1 0
      src/map/battle.h
  4. 9 0
      src/map/clif.c
  5. 26 2
      src/map/vending.c
  6. 1 0
      src/map/vending.h

+ 4 - 0
conf/battle/player.conf

@@ -135,3 +135,7 @@ character_size: 0
 // Set to the time in seconds where an idle character will stop receiving
 // items from Autoloot (0: disabled).
 idle_no_autoloot: 0
+
+// Minimum distance a vending must be from a NPC in order to be placed
+// Default: 3 (0: disabled).
+min_npc_vending_distance: 3

+ 1 - 0
src/map/battle.c

@@ -5329,6 +5329,7 @@ static const struct _battle_data {
 	{ "skill_amotion_leniency",             &battle_config.skill_amotion_leniency,          90,     0,      100				},
 	{ "mvp_tomb_enabled",					&battle_config.mvp_tomb_enabled,				1,      0,      1				},
 	{ "feature.atcommand_suggestions",		&battle_config.atcommand_suggestions_enabled,	0,      0,      1				},
+    { "min_npc_vending_distance",           &battle_config.min_npc_vending_distance,	0,      0,      100				},
 };
 
 

+ 1 - 0
src/map/battle.h

@@ -473,6 +473,7 @@ extern struct Battle_Config
 	int mvp_tomb_enabled;
 	
 	int atcommand_suggestions_enabled;
+    int min_npc_vending_distance;
 } battle_config;
 
 void do_init_battle(void);

+ 9 - 0
src/map/clif.c

@@ -11734,6 +11734,15 @@ void clif_parse_OpenVending(int fd, struct map_session_data* sd)
 		clif_displaymessage (sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
 		return;
 	}
+    
+    if( vending_checknearnpc(&sd->bl) ) {
+        char output[50];
+        sprintf(output,"You're too close to a NPC, you must be at least %d cells away from any NPC.",battle_config.min_npc_vending_distance);
+        clif_displaymessage(sd->fd, output);
+        clif_skill_fail(sd, MC_VENDING, USESKILL_FAIL_LEVEL, 0);
+        return;
+    }
+
 	if( message[0] == '\0' ) // invalid input
 		return;
 

+ 26 - 2
src/map/vending.c

@@ -12,6 +12,7 @@
 #include "chrif.h"
 #include "vending.h"
 #include "pc.h"
+#include "npc.h"
 #include "skill.h"
 #include "battle.h"
 #include "log.h"
@@ -233,13 +234,27 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
 		}
 	}
 }
+static int vending_checknearnpc_sub(struct block_list* bl, va_list args) {
+    struct npc_data *nd = (struct npc_data*)bl;
+    
+    if( nd->sc.option & (OPTION_HIDE|OPTION_INVISIBLE) )
+        return 1;
 
+    return 1;
+}
+bool vending_checknearnpc(struct block_list * bl) {
+    
+    if( battle_config.min_npc_vending_distance > 0 &&
+            map_foreachinrange(vending_checknearnpc_sub,bl, battle_config.min_npc_vending_distance, BL_NPC) )
+        return true;
+        
+    return false;
+}
 /*==========================================
  * Open shop
  * data := {<index>.w <amount>.w <value>.l}[count]
  *------------------------------------------*/
-void vending_openvending(struct map_session_data* sd, const char* message, bool flag, const uint8* data, int count)
-{
+void vending_openvending(struct map_session_data* sd, const char* message, bool flag, const uint8* data, int count) {
 	int i, j;
 	int vending_skill_lvl;
 	nullpo_retv(sd);
@@ -265,6 +280,15 @@ void vending_openvending(struct map_session_data* sd, const char* message, bool
 		return;
 	}
 
+    if( vending_checknearnpc(&sd->bl) ) {
+        char output[50];
+        sprintf(output,"You're too close to a NPC, you must be at least %d cells away from any NPC.",battle_config.min_npc_vending_distance);
+        clif_displaymessage(sd->fd, output);
+        clif_skill_fail(sd, MC_VENDING, USESKILL_FAIL_LEVEL, 0);
+        return;
+    }
+        
+    
 	// filter out invalid items
 	i = 0;
 	for( j = 0; j < count; j++ )

+ 1 - 0
src/map/vending.h

@@ -21,5 +21,6 @@ void vending_vendinglistreq(struct map_session_data* sd, int id);
 void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const uint8* data, int count);
 bool vending_search(struct map_session_data* sd, unsigned short nameid);
 bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s);
+bool vending_checknearnpc(struct block_list * bl);
 
 #endif /* _VENDING_H_ */