MUD (game) design concept question about time related events

I'm trying my best when creating a MUD (multiplayer interactive game)

I am in the design / conceptualization phase and I have a problem that makes me unable to find a solution. I hope some more experienced programmers get some tips.

Here is the problem, as far as I can explain it. When a player decides to perform an action, he sends a command to the server. the server then processes the command, determines whether the action can be performed, and either it does or answers the reason why this is not possible. One of the reasons that an action may fail is because the player is busy with something else. For example, if a player is in the middle of a battle and has just deployed a massive wide sword, it may take 3 seconds before he can repeat this action. If the player starts to swing again, the game will respond, indicating that he must wait x seconds before doing this. Now, I can perhaps develop without much trouble. The problem I am facing is how can I reproduce this behavior in AI creatures. All events,which are executed by the ON ITS OWN server, and not as an immediate reaction to what the player has done, should be time sensitive. Some evil monster cast a spell on you, but must wait 30 seconds before doing it again ... I think that I will probably add all these events to some kind of event queue, but how can I make this queue time in queues?

+3
source share
7 answers

MUD actions are usually performed on ticks, and not immediately - this allows you to limit the effect of the delay, and the commands of the monsters will be inserted into the queue and processed enough.

Personally, I don't like this approach, but almost 99% of MUDs use it. You need to create a reliable command queue and an event queue that can process both AI and user commands. Then you can add a “virtual delay” to the AI ​​commands, which can be predefined or for all users, the average delay or whatever.

+3
source

, , AI, " ?" , ? " , , ", .

.

class ToughGuy(AI):
   Action_Idle, Action_BroadswordSwing, Action_CastingMagic = range(3)

   MagicRange = 10
   MagicTime = 8
   MeleeRange = 4
   MeleeTime = 2

   def __init__(self):
      self.action = ToughGuy.Action_Idle
      self.actiontimer = 0

   def Update(self, timestep):
      if self.actiontimer <= 0:
         self.action = ToughGuy.ActionIdle
      else
         self.actiontimer -= timestep

      if self.action == ToughGuy.Action_Idle:
         global player # don't do this
         if self.AmIFacing(player):
            distance = DistanceBetween(self, player)
            if distance < ToughGuy.MeleeRange:
               self.action = ToughGuy.Action_BroadswordSwing
               self.actiontimer = ToughGuy.MeleeTime
            elif distance < ToughGuy.MagicRange:
               self.action = ToughGuy.Action_CastingMagic
               self.actiontimer = ToughGuy.MagicTime

... ...;)

+2

Mobs - . , . DelayTimeStart Delay Mob, , Mob, , .

+2

AI - .

" " . . .

AI , -.

+1

, , , . , ( , - ); , . , , , , .

0

LPMud/LDMud.

MUD player.c. Player.c living.c. , , . heartbeat 2 ( , heartbeat()). , , .

, , , living.c. , , , .

0

Source: https://habr.com/ru/post/1743583/


All Articles