Options for turn timeout and actions per turn

This commit is contained in:
FlutterSprite 2017-10-23 21:36:42 -07:00
parent f576005772
commit 30eea75ad7
3 changed files with 36 additions and 12 deletions

View file

@ -48,10 +48,18 @@ from evennia.commands.default.help import CmdHelp
""" """
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
COMBAT FUNCTIONS START HERE OPTIONS
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
""" """
TURN_TIMEOUT = 30 # Time before turns automatically end, in seconds
ACTIONS_PER_TURN = 1 # Number of actions allowed per turn
"""
----------------------------------------------------------------------------
COMBAT FUNCTIONS START HERE
----------------------------------------------------------------------------
"""
def roll_init(character): def roll_init(character):
""" """
@ -386,7 +394,7 @@ class TBBasicTurnHandler(DefaultScript):
# Set up the current turn and turn timeout delay. # Set up the current turn and turn timeout delay.
self.db.turn = 0 self.db.turn = 0
self.db.timer = 30 # 30 seconds self.db.timer = TURN_TIMEOUT # Set timer to turn timeout specified in options
def at_stop(self): def at_stop(self):
""" """
@ -440,7 +448,7 @@ class TBBasicTurnHandler(DefaultScript):
separated for movement, by adding "character.db.combat_movesleft = 3" or separated for movement, by adding "character.db.combat_movesleft = 3" or
something similar. something similar.
""" """
character.db.combat_actionsleft = 1 # 1 action per turn. character.db.combat_actionsleft = ACTIONS_PER_TURN # Replenish actions
# 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)
@ -478,7 +486,7 @@ class TBBasicTurnHandler(DefaultScript):
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] # Note the new character newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = 30 + self.time_until_next_repeat() # Reset the timer. self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning. self.db.timeout_warning_given = False # Reset the timeout warning.
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.

View file

@ -60,10 +60,18 @@ from evennia.commands.default.help import CmdHelp
""" """
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
COMBAT FUNCTIONS START HERE OPTIONS
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
""" """
TURN_TIMEOUT = 30 # Time before turns automatically end, in seconds
ACTIONS_PER_TURN = 1 # Number of actions allowed per turn
"""
----------------------------------------------------------------------------
COMBAT FUNCTIONS START HERE
----------------------------------------------------------------------------
"""
def roll_init(character): def roll_init(character):
""" """
@ -377,7 +385,7 @@ class TBEquipTurnHandler(DefaultScript):
# Set up the current turn and turn timeout delay. # Set up the current turn and turn timeout delay.
self.db.turn = 0 self.db.turn = 0
self.db.timer = 30 # 30 seconds self.db.timer = TURN_TIMEOUT # Set timer to turn timeout specified in options
def at_stop(self): def at_stop(self):
""" """
@ -431,7 +439,7 @@ class TBEquipTurnHandler(DefaultScript):
separated for movement, by adding "character.db.combat_movesleft = 3" or separated for movement, by adding "character.db.combat_movesleft = 3" or
something similar. something similar.
""" """
character.db.combat_actionsleft = 1 # 1 action per turn. character.db.combat_actionsleft = ACTIONS_PER_TURN # Replenish actions
# 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)
@ -469,7 +477,7 @@ class TBEquipTurnHandler(DefaultScript):
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] # Note the new character newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = 30 + self.time_until_next_repeat() # Reset the timer. self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning. self.db.timeout_warning_given = False # Reset the timeout warning.
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.

View file

@ -101,10 +101,18 @@ from evennia.commands.default.help import CmdHelp
""" """
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
COMBAT FUNCTIONS START HERE OPTIONS
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
""" """
TURN_TIMEOUT = 30 # Time before turns automatically end, in seconds
ACTIONS_PER_TURN = 1 # Number of actions allowed per turn
"""
----------------------------------------------------------------------------
COMBAT FUNCTIONS START HERE
----------------------------------------------------------------------------
"""
def roll_init(character): def roll_init(character):
""" """
@ -548,7 +556,7 @@ class TBRangeTurnHandler(DefaultScript):
# Set up the current turn and turn timeout delay. # Set up the current turn and turn timeout delay.
self.db.turn = 0 self.db.turn = 0
self.db.timer = 30 # 30 seconds self.db.timer = TURN_TIMEOUT # Set timer to turn timeout specified in options
def at_stop(self): def at_stop(self):
""" """
@ -653,7 +661,7 @@ class TBRangeTurnHandler(DefaultScript):
characters to both move and attack in the same turn (or, alternately, characters to both move and attack in the same turn (or, alternately,
move twice or attack twice). move twice or attack twice).
""" """
character.db.combat_actionsleft = 2 # 2 actions per turn. character.db.combat_actionsleft = ACTIONS_PER_TURN # Replenish actions
# 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!|n") character.msg("|wIt's your turn!|n")
combat_status_message(character) combat_status_message(character)
@ -692,7 +700,7 @@ class TBRangeTurnHandler(DefaultScript):
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] # Note the new character newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = 30 + self.time_until_next_repeat() # Reset the timer. self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning. self.db.timeout_warning_given = False # Reset the timeout warning.
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.