Skip to content

Commit

Permalink
Merge pull request #79 from CarperAI/2.0
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
jsuarez5341 committed Sep 15, 2023
2 parents 2cdf0f2 + ee671c9 commit cdf959a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nmmo/systems/combat.py
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
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

0 comments on commit cdf959a

Please sign in to comment.