MobArena icon indicating copy to clipboard operation
MobArena copied to clipboard

Only spawn mobs in line of sight

Open hades200082 opened this issue 6 years ago • 1 comments

Summary

  • This issue is a…
    • [ ] Bug report
    • [X] Feature request
    • [ ] Documentation request
    • [ ] Other issue
    • [ ] Question
  • Describe the issue / feature in 1-2 sentences:

I built a castle and set it up as a mob arena with this plugin. I quickly found that players were having to hunt for mobs because they would spawn in rooms up to 15 blocks away even if there were other blocks also within 15 blocks in line of sight.

Background

Feature request

  • Feature type:
    • [ ] Arena configuration
    • [ ] Classes
    • [ ] Documentation
    • [ ] Economy integration
    • [ ] Leaderboards
    • [ ] New config settings
    • [X] Other (please explain)
    • [ ] Rewards
    • [ ] Third-party plugin support

What does it do?:

spawns mobs up to 15 blocks with no regard for line of sight.

Does it need new or changed commands? What are they?:

No

Does this feature affect other parts of MobArena?:

Yes - spawning of mobs.

Details

Make the mob spawn point selector when spawning mobs favour spawn points that are within 15 blocks AND in line of sight of a player over those that are not in line of sight.

hades200082 avatar Mar 03 '18 00:03 hades200082

Thanks for this feature request :)

The way MobArena finds spawnpoints is by looping through all spawnpoints and players, breaking the inner loop only if a player is in range of the spawnpoint. This results in an inefficient O(n*m) algorithm. It grows very quickly in time complexity if the number of spawnpoints and/or players is large and the statistical chance of a player being in range of a spawnpoint is low. Adding a line of sight check to the inner loop would result in a palpable performance drop.

Optimizing the current spawnpoint algorithm is probably an important first step. The O(n*m) algorithm could be replaced with a better, less naïve, algorithm that actually uses some sort of spatial indexing. kd-trees and octrees come to mind.

garbagemule avatar Mar 04 '18 19:03 garbagemule