Fixed log error + bug with timeout
Reworked the way the turn timeout countdown works - it's now less precise but also no longer gives errors. There may be a problem in the Evennia codebase with the default script object's force_repeat() method, but I was unable to figure out what.
This commit is contained in:
parent
de21883717
commit
9073b688a6
1 changed files with 19 additions and 18 deletions
|
|
@ -517,7 +517,7 @@ class TurnHandler(DefaultScript):
|
||||||
Called once, when the script is created.
|
Called once, when the script is created.
|
||||||
"""
|
"""
|
||||||
self.key = "Combat Turn Handler"
|
self.key = "Combat Turn Handler"
|
||||||
self.interval = 10 # Once every 10 seconds
|
self.interval = 5 # Once every 5 seconds
|
||||||
self.persistent = True
|
self.persistent = True
|
||||||
self.db.fighters = []
|
self.db.fighters = []
|
||||||
|
|
||||||
|
|
@ -556,14 +556,15 @@ class TurnHandler(DefaultScript):
|
||||||
currentchar = self.db.fighters[self.db.turn] # Note the current character in the turn order.
|
currentchar = self.db.fighters[self.db.turn] # Note the current character in the turn order.
|
||||||
self.db.timer -= self.interval # Count down the timer.
|
self.db.timer -= self.interval # Count down the timer.
|
||||||
|
|
||||||
# Warn the current character if they're about to time out.
|
|
||||||
if self.db.timer == 10: # 10 seconds left
|
|
||||||
currentchar.msg("WARNING: About to time out!")
|
|
||||||
|
|
||||||
# Force current character to disengage if timer runs out.
|
|
||||||
if self.db.timer <= 0:
|
if self.db.timer <= 0:
|
||||||
|
# Force current character to disengage if timer runs out.
|
||||||
self.obj.msg_contents("%s's turn timed out!" % currentchar)
|
self.obj.msg_contents("%s's turn timed out!" % currentchar)
|
||||||
spend_action(currentchar, 'all', action_name="disengage") # Spend all remaining actions.
|
spend_action(currentchar, 'all', action_name="disengage") # Spend all remaining actions.
|
||||||
|
return
|
||||||
|
elif self.db.timer <= 10 and not self.db.timeout_warning_given: # 10 seconds left
|
||||||
|
# Warn the current character if they're about to time out.
|
||||||
|
currentchar.msg("WARNING: About to time out!")
|
||||||
|
self.db.timeout_warning_given = True
|
||||||
|
|
||||||
|
|
||||||
def initialize_for_combat(self, character):
|
def initialize_for_combat(self, character):
|
||||||
|
|
@ -584,16 +585,16 @@ class TurnHandler(DefaultScript):
|
||||||
available actions and notifying them that their turn has come up.
|
available actions and notifying them that their turn has come up.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
character (obj): Character to be readied.
|
character (obj): Character to be readied.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
Here, you only get one action per turn, but you might want to allow more than
|
||||||
|
one per turn, or even grant a number of actions based on a character's
|
||||||
|
attributes. You can even add multiple different kinds of actions, I.E. actions
|
||||||
|
separated for movement, by adding "character.db.Combat_MovesLeft = 3" or
|
||||||
|
something similar.
|
||||||
"""
|
"""
|
||||||
character.db.Combat_ActionsLeft = 1 # 1 action per turn.
|
character.db.Combat_ActionsLeft = 1 # 1 action per turn.
|
||||||
"""
|
|
||||||
Here, you only get one action per turn, but you might want to allow more than
|
|
||||||
one per turn, or even grant a number of actions based on a character's
|
|
||||||
attributes. You can even add multiple different kinds of actions, I.E. actions
|
|
||||||
separated for movement, by adding "character.db.Combat_MovesLeft = 3" or
|
|
||||||
something similar.
|
|
||||||
"""
|
|
||||||
# Prompt the character for their turn and give some information.
|
# Prompt the character for their turn and give some information.
|
||||||
character.msg("|wIt's your turn! You have %i HP remaining.|n" % character.db.hp)
|
character.msg("|wIt's your turn! You have %i HP remaining.|n" % character.db.hp)
|
||||||
|
|
||||||
|
|
@ -630,13 +631,13 @@ class TurnHandler(DefaultScript):
|
||||||
self.db.turn += 1 # Go to the next in the turn order.
|
self.db.turn += 1 # Go to the next in the turn order.
|
||||||
if self.db.turn > len(self.db.fighters) - 1:
|
if self.db.turn > len(self.db.fighters) - 1:
|
||||||
self.db.turn = 0 # Go back to the first in the turn order once you reach the end.
|
self.db.turn = 0 # Go back to the first in the turn order once you reach the end.
|
||||||
newchar = self.db.fighters[self.db.turn]
|
newchar = self.db.fighters[self.db.turn] # Note the new character
|
||||||
# Reset the timer.
|
self.db.timer = 30 + self.time_until_next_repeat() # Reset the timer.
|
||||||
self.db.timer = 30 + self.interval
|
self.db.timeout_warning_given = False # Reset the timeout warning.
|
||||||
self.force_repeat()
|
|
||||||
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
|
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
|
||||||
self.start_turn(newchar) # Start the new character's turn.
|
self.start_turn(newchar) # Start the new character's turn.
|
||||||
|
|
||||||
|
|
||||||
def turn_end_check(self, character):
|
def turn_end_check(self, character):
|
||||||
"""
|
"""
|
||||||
Tests to see if a character's turn is over, and cycles to the next turn if it is.
|
Tests to see if a character's turn is over, and cycles to the next turn if it is.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue