forked from reedlaw/ruby-mmo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request reedlaw#20 from southpolesteve/master
Adding my character
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module SouthPoleSteve | ||
def to_s | ||
"South Pole Steve" | ||
end | ||
|
||
def move | ||
return [:attack, killable_opponents.select{ |p| p.stats[:health] < 30 }.pop] unless killable_opponents.empty? | ||
|
||
return [:attack, opponents.first] if opponents.size == 1 || stats[:health] >= 100 | ||
|
||
[:rest] | ||
end | ||
|
||
private | ||
|
||
def opponents | ||
Game.world[:players].select{ |p| p != self } | ||
end | ||
|
||
def killable_opponents | ||
opponents.select { |o| can_kill?(o) } | ||
end | ||
|
||
def can_kill?(player) | ||
points = stats[:strength] - (player.stats[:defense] / 2) | ||
player.stats[:health] <= points | ||
end | ||
end |