The monsters in our server are kinda stupid.
(Yeah we had an AI in the past but not a lot of thought was put into it, it turned out buggy/laggy and had weird problems).
Most notable all monsters walking towards a point on the map that is way off in the distance.
I aim to fix that sort of problem.
Needed a way to get random numbers within a range but preferring certain ranges over others
Such as walk a distance of between 70 and 120 preferable to a distance of 30-50.
(But still allowing to walk a short distance randomly.)
If anyone is coder/math person what are your thoughts on this, ignoring how bad Math.random is,
( It does not go all the way to 1 so you could never get 100 by doing Math.random() * 100 )
I have not tested if this is correct yet just written it up might do some charts/graphs later to verify.
http://codepen.io/LiamKarlMitchell/pen/QwvyJy
The idea for using this is that monsters that roam around will prefer to wander in the existing direction or turn slightly.
That they will prefer to walk medium to short distances over long.
And then a constraint later to keep them walking around the center of their spawn area/roaming within bounds.
We could configure this to be closer towards where they exited the region, tweaking will be needed.
Areas we spawn monsters in can be considered either points or rectangles.
They are spawned at a point we define (things like guardian stones some boss etc) or within a rectangular region.
If spawned at a defined point we would expect the monster to not roam.
If spawned within a rectangle we would expect the monster to roam within that rectangle, possibly allowed to go slightly outside up to 50 units (could be configurable in config).
The idea is that this kind of movement would let monsters roam around close to their spawned area (you will notice this in real server as a grouped area they spawn in I think this is most noticeable in underground/caves where spawn count is high and re spawn time is low)
When a monster is attacking a target or chasing it will be allowed to roam outside of its area.
If it looses sight of target for more than 10 seconds (should be configurable) it should de spawn and re spawn within its area or chosen point.
You can see example of the monsters moving like this here: http://codepen.io/LiamKarlMitchell/pen/raxRKq
Try adding a small or ranged using the drop down and button.
Middle mouse button down changes the query and spawn circle to the mouse position.
Try different combinations, to see the results of combat press F12 and look in the console.
A blog about TSX a private server/server side emulation project for the game Twelve Sky 1
Sunday, January 18, 2015
Thursday, January 15, 2015
QuadTree improvements.
If you are not a developer this might not make sense to you, just think of it as something important for a good gaming experience and it will keep track of objects in game (monsters, npc, player).
I have been working on improving the QuadTree implementation the server uses so that we can have monsters with AI to fight with.
Quad Tree can be viewed here: http://codepen.io/LiamKarlMitchell/pen/raxRKq
The query region shown in blue now picks up nodes (Game objects) that are just on the edge of the circle as well as outside it but intersecting.
Empty leafs that are no longer fill and have children leafs with nothing in them and so on are removed.
An option enables us to have nodes outside of the created quad tree regions. We were having problems not knowing the full sizes/positions of the maps just yet where players/monsters/npc/item could go outside the area and be removed from the world which caused problems. So that will be fixed soon.
A getByNodeID method allows us to find 1 or more nodes by id.
Improvements that could be made:
A function could be made to query back up the tree from a node, to find Nodes by ID assuming its close first this would speed up trade, duel, attacking etc any interaction that is in close proximity between two game objects.
Adding AI manager, I hope to work on having the monsters attack, walk, agro, die next.
Adding events for on enter/onleave + sensors. (Basically querys that are checked after each node update and could be nodes themselves) although this could be unneeded and would slow down.
Migrate the rest of the functions in the server for object/location lookups to use the quadtree.
For instance we have functions that send an event to all connected clients, that will benefit speed wise from using the tree. Such as updating player action/location, sending a chat message in normal chat, dropping item, monster action/state, npc action/state, duel packets.
Happy New Year btw,
I have been working on improving the QuadTree implementation the server uses so that we can have monsters with AI to fight with.
Quad Tree can be viewed here: http://codepen.io/LiamKarlMitchell/pen/raxRKq
The query region shown in blue now picks up nodes (Game objects) that are just on the edge of the circle as well as outside it but intersecting.
Empty leafs that are no longer fill and have children leafs with nothing in them and so on are removed.
An option enables us to have nodes outside of the created quad tree regions. We were having problems not knowing the full sizes/positions of the maps just yet where players/monsters/npc/item could go outside the area and be removed from the world which caused problems. So that will be fixed soon.
A getByNodeID method allows us to find 1 or more nodes by id.
Improvements that could be made:
A function could be made to query back up the tree from a node, to find Nodes by ID assuming its close first this would speed up trade, duel, attacking etc any interaction that is in close proximity between two game objects.
Adding AI manager, I hope to work on having the monsters attack, walk, agro, die next.
Adding events for on enter/onleave + sensors. (Basically querys that are checked after each node update and could be nodes themselves) although this could be unneeded and would slow down.
Migrate the rest of the functions in the server for object/location lookups to use the quadtree.
For instance we have functions that send an event to all connected clients, that will benefit speed wise from using the tree. Such as updating player action/location, sending a chat message in normal chat, dropping item, monster action/state, npc action/state, duel packets.
Happy New Year btw,
Subscribe to:
Posts (Atom)