Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #79

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nmmo/systems/combat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def attack(realm, player, target, skill_fn):
equipment_offense = player.equipment.total(offense_fn)
equipment_defense = target.equipment.total(defense_fn)

# after tallying ammo damage, consume ammo (i.e., fire)
# after tallying ammo damage, consume ammo (i.e., fire) when the skill type matches
ammunition = player.equipment.ammunition.item
if ammunition is not None:
if ammunition is not None and getattr(ammunition, skill_name.lower() + '_attack').val > 0:
ammunition.fire(player)

else:
Expand Down
24 changes: 24 additions & 0 deletions tests/action/test_ammo_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ def test_ammo_fire_all(self):

# DONE

def test_use_ammo_only_when_attack_style_match(self):
env = self._setup_env(random_seed=RANDOM_SEED, remove_immunity=True)

# First tick actions: USE (equip) level-0 ammo
env.step({ ent_id: { action.Use:
{ action.InventoryItem: env.obs[ent_id].inventory.sig(ent_ammo, 0) }
} for ent_id, ent_ammo in self.ammo.items() })

# Second tick actions: Melee attack should not consume Arrow
ent_id = 2
env.step({ 2: { action.Attack:
{ action.Style: action.Melee,
action.Target: env.obs[ent_id].entities.index((ent_id+1)%3+1) } }})

ent_ammo = self.ammo[ent_id]
inventory = env.obs[ent_id].inventory
inv_idx = inventory.sig(ent_ammo, 0)
item_info = ItemState.parse_array(inventory.values[inv_idx])

# Did not consume ammo
self.assertEqual(self.ammo_quantity, item_info.quantity)

# DONE

def test_cannot_use_listed_items(self):
env = self._setup_env(random_seed=RANDOM_SEED)

Expand Down