mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Make evadventure get_sides more consistent. Resolve #3199
This commit is contained in:
parent
0d8533e61e
commit
eed5ea78a4
9 changed files with 20 additions and 52 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Main
|
||||
|
||||
- Fix: Clean up `get_sides` function in evadventure tutorial to return also
|
||||
the calling combatant with its `allies` return, to make it easier to reason around.
|
||||
- Feature: Add `SSL_CERTIFICATE_ISSUERS` setting for customizing Telnet+SSL.
|
||||
- Contrib: Refactored `dice.roll` contrib function to use `safe_eval`. Can now
|
||||
optionally be used as `dice.roll("2d10 + 4 > 10")`. Old way works too.
|
||||
|
|
|
|||
|
|
@ -332,8 +332,6 @@ class EvAdventureCombatBaseHandler(DefaultScript):
|
|||
def get_combat_summary(self, combatant):
|
||||
|
||||
allies, enemies = self.get_sides(combatant)
|
||||
# we must include outselves at the top of the list (we are not returned from get_sides)
|
||||
allies.insert(0, combatant)
|
||||
nallies, nenemies = len(allies), len(enemies)
|
||||
|
||||
# prepare colors and hurt-levels
|
||||
|
|
|
|||
|
|
@ -176,11 +176,11 @@ class EvadventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
|||
npcs = [comb for comb in self.combatants if comb not in pcs]
|
||||
if combatant in pcs:
|
||||
# combatant is a PC, so NPCs are all enemies
|
||||
allies = [comb for comb in pcs if comb != combatant]
|
||||
allies = pcs
|
||||
enemies = npcs
|
||||
else:
|
||||
# combatant is an NPC, so PCs are all enemies
|
||||
allies = [comb for comb in npcs if comb != combatant]
|
||||
allies = npcs
|
||||
enemies = pcs
|
||||
return allies, enemies
|
||||
```
|
||||
|
|
@ -897,7 +897,7 @@ def node_choose_allied_recipient(caller, raw_string, **kwargs):
|
|||
- Finally we merge this with the existing `kwargs` dict. The result is a new dict that now has the updated `"action_dict"` key pointing to an action-dict where `target` is set.
|
||||
- **Line 23**: We extend the `options` list with the default wizard options (`back`, `abort`). Since we made a helper function for this, this is only one line.
|
||||
|
||||
Creating the three other needed nodes `node_choose_enemy_recipient`, `node_choose_allied_target` and `node_choose_allied_recipient` are following the same pattern; they just use either the `allies` or `enemies` return from `combathandler.get_sides()` (for the `allies`, don't forget to add `caller` so you can target yourself!). It then sets either the `target` or `recipient` field in the `action_dict`. We leave these up to the reader to implement.
|
||||
Creating the three other needed nodes `node_choose_enemy_recipient`, `node_choose_allied_target` and `node_choose_allied_recipient` are following the same pattern; they just use either the `allies` or `enemies` return from `combathandler.get_sides(). It then sets either the `target` or `recipient` field in the `action_dict`. We leave these up to the reader to implement.
|
||||
|
||||
### Choose an Ability
|
||||
|
||||
|
|
|
|||
|
|
@ -152,11 +152,11 @@ class EvAdventureCombatTwitchHandler(EvAdventureCombatBaseHandler):
|
|||
npcs = [comb for comb in combatants if comb not in pcs]
|
||||
if combatant in pcs:
|
||||
# combatant is a PC, so NPCs are all enemies
|
||||
allies = [comb for comb in pcs if comb != combatant]
|
||||
allies = pcs
|
||||
enemies = npcs
|
||||
else:
|
||||
# combatant is an NPC, so PCs are all enemies
|
||||
allies = [comb for comb in npcs if comb != combatant]
|
||||
allies = npcs
|
||||
enemies = pcs
|
||||
return allies, enemies
|
||||
|
||||
|
|
@ -357,7 +357,6 @@ class EvAdventureCombatTwitchHandler(EvAdventureCombatBaseHandler):
|
|||
"""
|
||||
|
||||
allies, enemies = self.get_sides(self.obj)
|
||||
allies.append(self.obj)
|
||||
|
||||
location = self.obj.location
|
||||
|
||||
|
|
@ -382,7 +381,7 @@ class EvAdventureCombatTwitchHandler(EvAdventureCombatBaseHandler):
|
|||
|
||||
We must make sure to check if combat is over.
|
||||
|
||||
- **Line 12**: With our `.get_sides()` method we can easily get the two sides of the conflict. Note that `combatant` is not included among the allies, so we need to add it back in on the following line.
|
||||
- **Line 12**: With our `.get_sides()` method we can easily get the two sides of the conflict.
|
||||
- **Lines 18, 19**: We get everyone still alive _and still in the same room_. The latter condition is important in case we move away from the battle - you can't hit your enemy from another room.
|
||||
|
||||
In the `stop_method` we'll need to do a bunch of cleanup. We'll hold off on implementing this until we have the Commands written out. Read on.
|
||||
|
|
|
|||
|
|
@ -356,8 +356,6 @@ class EvAdventureCombatBaseHandler(DefaultScript):
|
|||
|
||||
"""
|
||||
allies, enemies = self.get_sides(combatant)
|
||||
# we must include outselves at the top of the list (we are not returned from get_sides)
|
||||
allies.insert(0, combatant)
|
||||
nallies, nenemies = len(allies), len(enemies)
|
||||
|
||||
# prepare colors and hurt-levels
|
||||
|
|
|
|||
|
|
@ -250,11 +250,11 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
|||
npcs = [comb for comb in self.combatants if comb not in pcs]
|
||||
if combatant in pcs:
|
||||
# combatant is a PC, so NPCs are all enemies
|
||||
allies = [comb for comb in pcs if comb != combatant]
|
||||
allies = pcs
|
||||
enemies = npcs
|
||||
else:
|
||||
# combatant is an NPC, so PCs are all enemies
|
||||
allies = [comb for comb in npcs if comb != combatant]
|
||||
allies = npcs
|
||||
enemies = pcs
|
||||
return allies, enemies
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
|||
surviving_combatant = None
|
||||
allies, enemies = (), ()
|
||||
else:
|
||||
# grab a random survivor and check of they have any living enemies.
|
||||
# grab a random survivor and check if they have any living enemies.
|
||||
surviving_combatant = random.choice(list(self.combatants.keys()))
|
||||
allies, enemies = self.get_sides(surviving_combatant)
|
||||
|
||||
|
|
@ -537,19 +537,6 @@ def node_choose_allied_target(caller, raw_string, **kwargs):
|
|||
combathandler = _get_combathandler(caller)
|
||||
allies, _ = combathandler.get_sides(caller)
|
||||
|
||||
# can choose yourself
|
||||
options = [
|
||||
{
|
||||
"desc": "Yourself",
|
||||
"goto": (
|
||||
_step_wizard,
|
||||
{
|
||||
**kwargs,
|
||||
**{"action_dict": {**action_dict, **{"target": caller}}},
|
||||
},
|
||||
),
|
||||
}
|
||||
]
|
||||
options.extend(
|
||||
[
|
||||
{
|
||||
|
|
@ -579,19 +566,6 @@ def node_choose_allied_recipient(caller, raw_string, **kwargs):
|
|||
combathandler = _get_combathandler(caller)
|
||||
allies, _ = combathandler.get_sides(caller)
|
||||
|
||||
# can choose yourself
|
||||
options = [
|
||||
{
|
||||
"desc": "Yourself",
|
||||
"goto": (
|
||||
_step_wizard,
|
||||
{
|
||||
**kwargs,
|
||||
**{"action_dict": {**action_dict, **{"recipient": caller}}},
|
||||
},
|
||||
),
|
||||
}
|
||||
]
|
||||
options.extend(
|
||||
[
|
||||
{
|
||||
|
|
|
|||
|
|
@ -106,11 +106,11 @@ class EvAdventureCombatTwitchHandler(EvAdventureCombatBaseHandler):
|
|||
npcs = [comb for comb in combatants if comb not in pcs]
|
||||
if combatant in pcs:
|
||||
# combatant is a PC, so NPCs are all enemies
|
||||
allies = [comb for comb in pcs if comb != combatant]
|
||||
allies = pcs
|
||||
enemies = npcs
|
||||
else:
|
||||
# combatant is an NPC, so PCs are all enemies
|
||||
allies = [comb for comb in npcs if comb != combatant]
|
||||
allies = npcs
|
||||
enemies = pcs
|
||||
return allies, enemies
|
||||
|
||||
|
|
@ -216,7 +216,6 @@ class EvAdventureCombatTwitchHandler(EvAdventureCombatBaseHandler):
|
|||
"""
|
||||
|
||||
allies, enemies = self.get_sides(self.obj)
|
||||
allies.append(self.obj)
|
||||
|
||||
location = self.obj.location
|
||||
|
||||
|
|
|
|||
|
|
@ -93,9 +93,6 @@ class EquipmentHandler:
|
|||
Args:
|
||||
obj (EvAdventureObject): The object to add.
|
||||
|
||||
Raise:
|
||||
EquipmentError: If there's not enough room.
|
||||
|
||||
"""
|
||||
if not inherits_from(obj, EvAdventureObject):
|
||||
raise EquipmentError(f"{obj.key} is not something that can be equipped.")
|
||||
|
|
@ -103,6 +100,7 @@ class EquipmentHandler:
|
|||
size = obj.size
|
||||
max_slots = self.max_slots
|
||||
current_slot_usage = self.count_slots()
|
||||
|
||||
if current_slot_usage + size > max_slots:
|
||||
slots_left = max_slots - current_slot_usage
|
||||
raise EquipmentError(
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class TestEvAdventureCombatBaseHandler(_CombatTestBase):
|
|||
def test_get_combat_summary(self):
|
||||
"""Test combat summary"""
|
||||
|
||||
self.combathandler.get_sides = Mock(return_value=([], [self.target]))
|
||||
self.combathandler.get_sides = Mock(return_value=([self.combatant], [self.target]))
|
||||
|
||||
# as seen from one side
|
||||
result = str(self.combathandler.get_combat_summary(self.combatant))
|
||||
|
|
@ -92,7 +92,7 @@ class TestEvAdventureCombatBaseHandler(_CombatTestBase):
|
|||
)
|
||||
|
||||
# as seen from other side
|
||||
self.combathandler.get_sides = Mock(return_value=([], [self.combatant]))
|
||||
self.combathandler.get_sides = Mock(return_value=([self.target], [self.combatant]))
|
||||
result = str(self.combathandler.get_combat_summary(self.target))
|
||||
|
||||
self.assertEqual(
|
||||
|
|
@ -383,11 +383,11 @@ class EvAdventureTurnbasedCombatHandlerTest(_CombatTestBase):
|
|||
|
||||
# allies to combatant
|
||||
allies, enemies = self.combathandler.get_sides(self.combatant)
|
||||
self.assertEqual((allies, enemies), ([combatant2], [self.target, target2]))
|
||||
self.assertEqual((allies, enemies), ([self.combatant, combatant2], [self.target, target2]))
|
||||
|
||||
# allies to monster
|
||||
allies, enemies = self.combathandler.get_sides(self.target)
|
||||
self.assertEqual((allies, enemies), ([target2], [self.combatant, combatant2]))
|
||||
self.assertEqual((allies, enemies), ([self.target, target2], [self.combatant, combatant2]))
|
||||
|
||||
def test_queue_and_execute_action(self):
|
||||
"""Queue actions and execute"""
|
||||
|
|
@ -551,7 +551,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
|||
|
||||
def test_get_sides(self):
|
||||
sides = self.combatant_combathandler.get_sides(self.combatant)
|
||||
self.assertEqual(sides, ([], [self.target]))
|
||||
self.assertEqual(sides, ([self.combatant], [self.target]))
|
||||
|
||||
def test_give_advantage(self):
|
||||
self.combatant_combathandler.give_advantage(self.combatant, self.target)
|
||||
|
|
@ -612,7 +612,7 @@ class TestEvAdventureTwitchCombatHandler(EvenniaCommandTestMixin, _CombatTestBas
|
|||
# only one side wiped out
|
||||
self.combatant.hp = 10
|
||||
self.target.hp = -1
|
||||
self.combatant_combathandler.get_sides = Mock(return_value=([], []))
|
||||
self.combatant_combathandler.get_sides = Mock(return_value=([self.combatant], []))
|
||||
self.combatant_combathandler.check_stop_combat()
|
||||
self.combatant.msg.assert_called_with(
|
||||
text=("The combat is over.", {}), from_obj=self.combatant
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue