Network Protocol Concepts

From PSwiki
Jump to navigation Jump to search

Any AI system implementer will need to understand what information his creatures will have available to them and when, so he/she can work within that system to determine behavior. This section will not be a detailed explanation of each networking message, but instead an overview of the types of information npcclient gets from the game server and sends to the game server.


Perceptions

The most important thing to understand is the superclient event model. The Game Server notifies all superclients of events relevant to them, and it is up to each superclient to decide when/how/if to react to each event. This constant stream of events, along with periodic updates of entity positions, represents all the info each superclient knows about the world from the game server. (Superclients of course track their own information as well.)

The following is a list of perception events the server sends to superclients such as npcclient, together with their purpose and what a superclient might use them for.

Time of Day The Game Server sends a Time perception once per game hour to all

superclients, with a number from 0 to 23 indicating the hour. If a superclient needs more fine-grained time reactions, the superclient can generate time perceptions of its own in between and react accordingly.

This perception allows npcs to change behaviors or state depending on the time of day. For example, you could have nocturnal hunting creatures who sleep during the day, or npc city merchants who are in their shops during the day and at home at night.

Talking If a player attempts to talk to an NPC, the Game Server handles the dialog

aspect of this event. It was viewed as beneficial to have one central database of dialog for NPCs, and as not beneficial to have multiple implementations of dialog algorithms across superclients, so this is all centralized.

However, NPC behavior surrounding this dialog is entirely determined by the superclient. The Game Server will never move an NPC or make an NPC animate without being told to by the superclient managing that NPC.

This Talk perception message allows the superclient to turn a city merchant to face the speaker, or to make the Orc attack if spoken to, etc. To assist with different reactions depending on the player, the worst mutual faction score between player and NPC is sent with this perception.

Attack If a player attacks an NPC, his superclient is immediately notified even

though it may take 2-5 seconds for the first swing of the weapon to land. This isn’t strictly fair but can help compensate for the lagtime to the superclient and will allow fast-fighting NPCs to hit first even when attacked.

Group Attack If a player is a part of a group, NPC tactics will change slightly. The NPC

may not want to strictly always fight back against the melee fighter, but may decide to pick out the wizard in the group, or the healer or the rogue. This perception sends the list of entities in the attacking group and includes a specifier on each one of what their single highest ranking skill is, to give the NPC some idea of what he is up against.

Damage Whenever the HP of an NPC goes down, whether through melee, fall

damage, spells hitting him or whatever, the superclient managing that NPC gets this perception. The entity is specified (if any) that caused the damage and the amount of HP lost are both sent as part of the perception. NPCs can use this to manage their hate lists or help them decide who to attack and how to fight back, or run to escape, etc.

Spell If a spell is cast by any player, the perception of it is sent to all superclients.

The perception should be broadcast internally in the superclient to any npc that is within 20m of the spell caster. Each perception comes with the category of the spell, as defined in the spells table in the game server database, the severity of the spell (also defined in that table) as a number between 0 and 25, and the caster and target entities.

Each NPC evaluates the caster and target to decide on friend or foe, then decides how to react to that spell type, given its severity. For example, a direct damage spell cast on the NPC himself may not require any further reaction because the NPC will receive a Damage perception covering the same event. If the caster heals her groupmate though, and her groupmate is fighting the NPC, this could make the NPC hate the caster more even though the spell did not directly affect the NPC.

Death If a player or an npc dies, the Game Server notifies all the superclients about

this. The superclient managing the now-dead npc must shut down his AI and stop him from moving. If the dead entity is a player, the npc may want to remove the player from his hate list or stop attacking and so on.

This list is expected to grow somewhat over time, but these are the basics and it probably shouldn’t get too long. NPCClient also makes use of the perception system to generate its own perceptions that do not come from the Game Server. These are primarily things which are CPU-intensive to determine and beyond the budget of the Game Server NPC manager to handle.