Class: GamesAndRpgParadise::Mud::Combat

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/mud/combat/combat.rb

Overview

RpgParadise::Mud::Combat

Constant Summary collapse

ARRAY_POSSIBLE_QUALITIES_OF_THE_HIT =
#

ARRAY_POSSIBLE_QUALITIES_OF_THE_HIT

#
%(
  weakly
  quickly
  forcefully
  powerfully
)
ARRAY_POSSIBLE_TARGET_LOCATIONS_ON_A_HUMANOID_TARGET =
#

ARRAY_POSSIBLE_TARGET_LOCATIONS_ON_A_HUMANOID_TARGET

#
%i(
  head
  torso
  left_arm
  left_hand
  right_arm
  right_hand
  left_leg
  right_leg
)

Instance Method Summary collapse

Constructor Details

#initialize(*objects) ⇒ Combat

#

initialize

Please pass the participating combat objects into this method.

Pass only livings to it.

#


44
45
46
47
48
49
50
51
52
53
# File 'lib/games_and_rpg_paradise/mud/combat/combat.rb', line 44

def initialize(
    *objects
  )
  reset
  # ======================================================================= #
  # Designate the participating combat objects next.
  # ======================================================================= #
  @participating_combat_objects = objects # will participate in combat
  run
end

Instance Method Details

#has_hit?Boolean

#

has_hit?

This method determines whether the target was hit.

Or: rand(2) == 0

#

Returns:

  • (Boolean)


68
69
70
# File 'lib/games_and_rpg_paradise/mud/combat/combat.rb', line 68

def has_hit?
  return (rand > 0.5)
end

#resetObject

#

reset

#


58
59
# File 'lib/games_and_rpg_paradise/mud/combat/combat.rb', line 58

def reset
end

#runObject

#

run

#


109
110
111
# File 'lib/games_and_rpg_paradise/mud/combat/combat.rb', line 109

def run
  strike_at_location :random
end

#strike_at_location(this_location = :head) ⇒ Object

#

strike_at_location

#


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/games_and_rpg_paradise/mud/combat/combat.rb', line 75

def strike_at_location(
    this_location = :head
  )
  case this_location
  when :rand
    strike_at_location ARRAY_POSSIBLE_TARGET_LOCATIONS_ON_A_HUMANOID_TARGET.rand
  else
    this_location = this_location.to_s.sub(/_/,' ')
    if has_hit?
      speak 'You '+@quality_of_the_hit+' strike at the '+this_location+' of '+
            'the '+@enemy+' with your '+@weapon
      case @quality_of_the_hit
      # === weakly
      when 'weakly'
        speak 'The hit inflicts a minor scratch at the skin of the '+@enemy
      # === quickly
      when 'quickly'
        speak 'Your quick strike inflicts a rather long wound on the '+@enemy
      when 'forcefully'
        speak 'Blood gushes out from the big wound you inflict on the '+@enemy,2
      when 'powerfully'
        speak 'Your powerful strike impales the '+@enemy+', letting '+
              'blood out of the body'
      end
    else
      speak 'You try to strike at the '+this_location+' of the '+@enemy+' with '+
      'your '+@weapon+' but you miss'
    end
  end
end