-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: Player module named BioCreature. BioCreature is an Endurance c…
…haracter.
- Loading branch information
1 parent
b6804ff
commit 35c5b33
Showing
3 changed files
with
141 additions
and
15 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 @@ | ||
2.1.0 |
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
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,126 @@ | ||
module BioCreature | ||
|
||
def to_s | ||
"BioCreature" | ||
end | ||
|
||
def self.extended(base) | ||
base.instance_variable_set :@round, 0 | ||
end | ||
|
||
def move | ||
@round += 1 | ||
|
||
if should_fight? | ||
fight | ||
else | ||
recover | ||
end | ||
|
||
end | ||
|
||
private | ||
|
||
def kill | ||
if @round > 80 | ||
leader | ||
else | ||
easy_players = opponents.select{|p| p!=self}.select{|p| easyKill? p} | ||
medium_players = opponents.select{|p| p!=self}.select{|p| killable? p} | ||
|
||
if easy_players.count > 0 | ||
return easy_players[rand(easy_players.count - 1)] | ||
elsif medium_players.count > 0 | ||
return medium_players[rand(medium_players.count - 1)] | ||
end | ||
end | ||
|
||
end | ||
|
||
# player: the player that you want to know if is killable | ||
def killable? player | ||
opponentDamage = calcDamage(fromPlayer: player, toPlayer: self) | ||
selfDamage = calcDamage(fromPlayer: self, toPlayer: player) | ||
|
||
# if the TTK for myself is equal to my opponent then return true | ||
timeToKill(player: self, damage: opponentDamage) == timeToKill(player: player, damage: selfDamage) | ||
# note: if you are wondering why only equals, then look at easyKill | ||
end | ||
|
||
# player: the player that you want to know if is an easy kill | ||
def easyKill? player | ||
opponentDamage = calcDamage(fromPlayer: player, toPlayer: self) | ||
selfDamage = calcDamage(fromPlayer: self, toPlayer: player) | ||
|
||
# if the TTK for myself is longer than my opponent (not equal) then return true | ||
timeToKill(player: self, damage: opponentDamage) > timeToKill(player: player, damage: selfDamage) | ||
end | ||
|
||
# fromPlayer: the player that you want to know the damage for | ||
# toPlayer: the player that you want to possibly attack | ||
def calcDamage (fromPlayer: self, toPlayer: self) | ||
# Damage = Strength - Defense/2 | ||
if self == fromPlayer | ||
self.stats[:strength] - toPlayer.stats[:defense]/2 | ||
else | ||
fromPlayer.stats[:strength] - self.stats[:defense]/2 | ||
end | ||
end | ||
|
||
# player: the player that you want to know the TTK for | ||
# damage: the damage of the player other than the :player | ||
def timeToKill (player: self, damage: 10) | ||
# Time-To-Kill = Health / Damage | ||
if player != self | ||
player.stats[:health]/damage | ||
else | ||
self.stats[:health]/damage | ||
end | ||
end | ||
|
||
def opponents | ||
Game.world[:players].select{|p| p!=self} | ||
end | ||
|
||
def recover | ||
[:rest] | ||
end | ||
|
||
def leader | ||
opponents.max_by { |p| xp(p) } | ||
end | ||
|
||
def middle_of_pack | ||
opponents.sort_by! { |p| xp(p) } | ||
opponents[opponents.count/2] | ||
end | ||
|
||
def should_fight? | ||
if health >= 100 && @round < 10 | ||
true | ||
elsif @round >= 80 | ||
true | ||
elsif xp > xp(middle_of_pack) | ||
false | ||
else | ||
true | ||
end | ||
end | ||
|
||
def xp(p = self) | ||
p.stats[:experience] | ||
end | ||
|
||
def level(p = self) | ||
p.stats[:level] | ||
end | ||
|
||
def health(p = self) | ||
p.stats[:health] | ||
end | ||
|
||
def fight | ||
[:attack, kill] unless kill.nil? | ||
end | ||
|
||
end |