Browse Source

- Added some braces to clear up the code in pc_additem, even though I doubt it'll fix the problem :X
- Modified mobskill_use behaviour to pick a random starting point and check skills from that, rather than always checking from first to last. Fixes skills with high priority blocking skills lower down in the list from triggering.


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@6657 54d463be-8e91-2dee-dedb-b68131a5f0ec

skotlex 19 years ago
parent
commit
1b2a882dc3
3 changed files with 20 additions and 7 deletions
  1. 4 0
      Changelog-Trunk.txt
  2. 12 6
      src/map/mob.c
  3. 4 1
      src/map/pc.c

+ 4 - 0
Changelog-Trunk.txt

@@ -4,6 +4,10 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2006/05/19
+	* Modified mobskill_use behaviour to pick a random starting point and check
+	  skills from that, rather than always checking from first to last. Fixes
+	  skills with high priority blocking skills lower down in the list from
+	  triggering. [Skotlex]
 	* Updated mob ai behaviour so that mobs use IDLE state skills when their
 	  current target cannot be reached for melee fighting. [Skotlex]
 2006/05/18

+ 12 - 6
src/map/mob.c

@@ -2570,24 +2570,30 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
 	struct mob_skill *ms;
 	struct block_list *fbl = NULL; //Friend bl, which can either be a BL_PC or BL_MOB depending on the situation. [Skotlex]
 	struct mob_data *fmd = NULL;
-	int i;
+	int i,j;
 
 	nullpo_retr (0, md);
 	nullpo_retr (0, ms = md->db->skill);
 
-	if (battle_config.mob_skill_rate == 0 || md->ud.skilltimer != -1)
+	if (!battle_config.mob_skill_rate || md->ud.skilltimer != -1 || !md->db->maxskill)
 		return 0;
 
 	if (event < 0 && DIFF_TICK(md->ud.canact_tick, tick) > 0)
 		return 0; //Skill act delay only affects non-event skills.
-	
-	for (i = 0; i < md->db->maxskill; i++) {
-		int c2 = ms[i].cond2, flag = 0;		
 
-		// ƒfƒBƒŒƒC’†
+	//Pick a random starting position and loop from that.
+	j = rand()%md->db->maxskill;
+	for (i = j+1; i != j; i++) {
+		int c2, flag = 0;		
+
+		if (i == md->db->maxskill)
+			i = 0;
+
 		if (DIFF_TICK(tick, md->skilldelay[i]) < ms[i].delay)
 			continue;
 
+		c2 = ms[i].cond2;
+		
 		if (ms[i].state != md->state.skillstate && md->state.skillstate != MSS_DEAD) {
 			if (ms[i].state == MSS_ANY || (ms[i].state == MSS_ANYTARGET && md->target_id))
 				; //ANYTARGET works with any state as long as there's a target. [Skotlex]

+ 4 - 1
src/map/pc.c

@@ -2401,8 +2401,10 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount)
 
 	i = MAX_INVENTORY;
 
-	if (!itemdb_isequip2(data)){ //Stackable
+	if (!itemdb_isequip2(data))
+	{ //Stackable
 		for (i = 0; i < MAX_INVENTORY; i++)
+		{
 			if(sd->status.inventory[i].nameid == item_data->nameid &&
 				memcmp(&sd->status.inventory[i].card,&item_data->card,
 					sizeof(item_data->card))==0)
@@ -2413,6 +2415,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount)
 				clif_additem(sd,i,amount,0);
 				break;
 			}
+		}
 	}
 	if (i >= MAX_INVENTORY){
 		i = pc_search_inventory(sd,0);