浏览代码

Loot Closest Item Feature Improvement (#9168)

- When setting monster_loot_search_type to 0, monsters will now reliably switch to the closest item target
  * This works now even when a new item appears that is closer while the monster is already chasing an item
  * Does not apply when the monster already has a target that is not an item
- Removed previous code that shortened the walkpath but only worked in a few edge cases
  * Now uses the normal process of stopping when target is gone
Playtester 2 月之前
父节点
当前提交
fdef3d02ed
共有 1 个文件被更改,包括 14 次插入7 次删除
  1. 14 7
      src/map/mob.cpp

+ 14 - 7
src/map/mob.cpp

@@ -1404,10 +1404,6 @@ static int32 mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
 		(*target) = bl;
 		(*target) = bl;
 		md->target_id = bl->id;
 		md->target_id = bl->id;
 	}
 	}
-	else if( !battle_config.monster_loot_search_type ){
-		// Stop walking after 0.5-1.5 cells if item is no longer on the ground.
-		unit_stop_walking_soon(md->bl, gettick());
-	}
 
 
 	return 0;
 	return 0;
 }
 }
@@ -1993,10 +1989,21 @@ static bool mob_ai_sub_hard(struct mob_data *md, t_tick tick)
 	}
 	}
 
 
 	// Scan area for targets
 	// Scan area for targets
-	if (!tbl && can_move && mode&MD_LOOTER && md->lootitems && DIFF_TICK(tick, md->ud.canact_tick) > 0 &&
+
+	// Scan area for items to loot, avoid trying to loot if the mob is full and can't consume the items.
+	if (can_move && mode&MD_LOOTER && md->lootitems && DIFF_TICK(tick, md->ud.canact_tick) > 0 &&
 		(md->lootitem_count < LOOTITEM_SIZE || battle_config.monster_loot_type != 1))
 		(md->lootitem_count < LOOTITEM_SIZE || battle_config.monster_loot_type != 1))
-	{	// Scan area for items to loot, avoid trying to loot if the mob is full and can't consume the items.
-		map_foreachinshootrange (mob_ai_sub_hard_lootsearch, &md->bl, battle_config.loot_range, BL_ITEM, md, &tbl);
+	{
+		if (tbl == nullptr) {
+			// Search for items in loot range
+			map_foreachinshootrange(mob_ai_sub_hard_lootsearch, &md->bl, battle_config.loot_range, BL_ITEM, md, &tbl);
+		}
+		else if (tbl->type == BL_ITEM && battle_config.monster_loot_search_type == 0) {
+			// Looter already has a target item, but we want to check if there is an item that's closer
+			int16 dist = distance_bl(&md->bl, tbl) - 1;
+			if (dist > 0)
+				map_foreachinshootrange(mob_ai_sub_hard_lootsearch, &md->bl, dist, BL_ITEM, md, &tbl);
+		}
 	}
 	}
 
 
 	if ((mode&MD_AGGRESSIVE && (!tbl || slave_lost_target)) || md->state.skillstate == MSS_FOLLOW)
 	if ((mode&MD_AGGRESSIVE && (!tbl || slave_lost_target)) || md->state.skillstate == MSS_FOLLOW)