distance_inc & distance_dec changed to helper funcs

This commit is contained in:
FlutterSprite 2017-10-23 21:51:03 -07:00
parent 30eea75ad7
commit b2ec29db81

View file

@ -79,6 +79,11 @@ instead of the default:
class Character(TBRangeCharacter): class Character(TBRangeCharacter):
Do the same thing in your game's objects.py module for TBRangeObject:
from evennia.contrib.turnbattle.tb_range import TBRangeObject
class Object(TBRangeObject):
Next, import this module into your default_cmdsets.py module: Next, import this module into your default_cmdsets.py module:
from evennia.contrib.turnbattle import tb_range from evennia.contrib.turnbattle import tb_range
@ -106,7 +111,7 @@ OPTIONS
""" """
TURN_TIMEOUT = 30 # Time before turns automatically end, in seconds TURN_TIMEOUT = 30 # Time before turns automatically end, in seconds
ACTIONS_PER_TURN = 1 # Number of actions allowed per turn ACTIONS_PER_TURN = 2 # Number of actions allowed per turn
""" """
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
@ -283,9 +288,22 @@ def resolve_attack(attacker, defender, attack_type, attack_value=None, defense_v
if defender.db.hp <= 0: if defender.db.hp <= 0:
at_defeat(defender) at_defeat(defender)
def approach(mover, target):
"""
Manages a character's whole approach, including changes in ranges to other characters.
Args:
mover (obj): The object moving
target (obj): The object to be moved toward
Notes:
The mover will also automatically move toward any objects that are closer to the
target than the mover is. The mover will also move away from anything they started
out close to.
"""
def distance_dec(mover, target): def distance_dec(mover, target):
""" """
Decreases distance in range field between mover and target. Helper function that decreases distance in range field between mover and target.
Args: Args:
mover (obj): The object moving mover (obj): The object moving
@ -303,34 +321,6 @@ def distance_dec(mover, target):
if object != mover and object != target: if object != mover and object != target:
object.db.combat_range[mover] = object.db.combat_range[target] object.db.combat_range[mover] = object.db.combat_range[target]
def distance_inc(mover, target):
"""
Increases distance in range field between mover and target.
Args:
mover (obj): The object moving
target (obj): The object to be moved away from
"""
mover.db.combat_range[target] += 1
target.db.combat_range[mover] = mover.db.combat_range[target]
# Set a cap of 2:
if mover.db.combat_range[target] > 2:
target.db.combat_range[mover] = 2
mover.db.combat_range[target] = 2
def approach(mover, target):
"""
Manages a character's whole approach, including changes in ranges to other characters.
Args:
mover (obj): The object moving
target (obj): The object to be moved toward
Notes:
The mover will also automatically move toward any objects that are closer to the
target than the mover is. The mover will also move away from anything they started
out close to.
"""
objects = mover.location.contents objects = mover.location.contents
for thing in objects: for thing in objects:
@ -358,7 +348,23 @@ def withdraw(mover, target):
of their withdrawl. The mover will never inadvertently move toward anything else while of their withdrawl. The mover will never inadvertently move toward anything else while
withdrawing - they can be considered to be moving to open space. withdrawing - they can be considered to be moving to open space.
""" """
def distance_inc(mover, target):
"""
Helper function that increases distance in range field between mover and target.
Args:
mover (obj): The object moving
target (obj): The object to be moved away from
"""
mover.db.combat_range[target] += 1
target.db.combat_range[mover] = mover.db.combat_range[target]
# Set a cap of 2:
if mover.db.combat_range[target] > 2:
target.db.combat_range[mover] = 2
mover.db.combat_range[target] = 2
objects = mover.location.contents objects = mover.location.contents
for thing in objects: for thing in objects:
if thing != mover and thing != target: if thing != mover and thing != target:
# Move away from each object closer to the target than you, if it's also closer to you than you are to the target. # Move away from each object closer to the target than you, if it's also closer to you than you are to the target.