|
Don't try copying an entire system from another source... especially when they are as intricately tied to the base functionality as the monster system.
Here's the steps for a basic monster system (functions similarly in every source I've seen)
Reference to monster types
-Generally a static collection loaded from database on runtime.
-Contains statistics of each 'type' of monster (health, mesh, name, attack, defense, droprules, etc)
Reference to spawns
-Generally a static collection or by map collection of all spawns of monsters
-Contains statistics concerning location, number and type of monsters, spawn rate, etc
-Some reference to individual monsters
Reference to individual monsters
-Generally inherited from the entity class and referenced in the spawn class so they can be controlled on a 'by spawn basis' (lets to operate only on spawns where players are nearby/on the map, etc)
Now... When you load the server you need to populate the monster types and spawns from database/flatfile. This is quite simple and just a mater of reading the information and creating new objects in memory.
Map system
How you organize this is all up to you honestly. You could have a reference to spawns in your map, or simply insert your monsters into the map objects collection. Personally I would organize it like..
Map>Spawns>Monsters (reference to the same object as is in the objects collection of the map)
Map>ILocatableObjects (anything that can be viewed in game space. Monsters, players, items, npcs, etc)
Now... when a monster is spawned, it is added to the objects collection of the map. This means it is now viewable by players
When a monster is killed, it's still stored in the spawn collection (there are more efficient ways, I'm using a simple example here). When respawned you can heal it up, moved to a random, valid location within the spawn radius and re-added to the visible objects collection of the map.
Displaying the monster to players
Any time your client moves by jumping, walking, teleporting (loging in counts as teleporting) you need to update what is nearby (removing objects no longer on your screen and adding ones that are now visible).
Any time an object is added to this, you need to send a valid spawn packet in order for the client to see it. You need to alter your screen method so that all of these steps also apply to monsters. If not, you will see nothing.
best of luck!
|