entities.rb
def strike(target)
    return nil unless target.is_a? Creature
    if rand > target.evasion
      attack = @strength + (@weapon ? $items[@weapon].damage : 0)
      defense = target.agility + (target.armor ? $items[target.armor].defense : 0)
      if rand(32) != 0
        damage_base = (attack - defense / 2.0)
        damage = rand((damage_base / 4)..(damage_base / 2)).to_i
        damage = rand(2) if damage < 1
      else
        damage = rand((attack/2)..(attack))
      end
      target.hp -= damage
      damage
    else
      nil
    end
  end
# Attack the target creature. Returns the damage done, or nil for a miss
Attack the target creature. Returns the damage done, or nil for a miss
Attack the target creature . Returns the damage done or nil for a miss
def strike(target)
    return nil unless target.is_a? Creature
    if rand > target.evasion
      attack = @strength + (@weapon ? $items[@weapon].damage : 0)
      defense = target.agility + (target.armor ? $items[target.armor].defense : 0)
      if rand(32) != 0
        damage_base = (attack - defense / 2.0)
        damage = rand((damage_base / 4)..(damage_base / 2)).to_i
        damage = rand(2) if damage < 1
      else
        damage = rand((attack/2)..(attack))
      end
      target.hp -= damage
      damage
    else
      nil
    end
  end
def strike ( target ) return nil unless target . is_a? Creature if rand > target . evasion attack = @strength + ( @weapon ? $items [ @weapon ] . damage : 0 ) defense = target . agility + ( target . armor ? $items [ target . armor ] . defense : 0 ) if rand ( 32 ) != 0 damage_base = ( attack - defense / 2.0 ) damage = rand ( ( damage_base / 4 ) .. ( damage_base / 2 ) ) . to_i damage = rand ( 2 ) if damage < 1 else damage = rand ( ( attack / 2 ) .. ( attack ) ) end target . hp -= damage damage else nil end end
Attack the target creature.
Attack the target creature .
target