diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-05-12 11:30:59 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-08-26 22:56:47 +0200 |
commit | e3a1e9c89e102dbf961c624435c495c759776312 (patch) | |
tree | c76e09b7661a61eebd042b8d49502fcbcb6d0066 /example/scripts/damage.lua | |
parent | 4d46079cd147e05513473860cb2e92fec0c31b8f (diff) | |
download | manaserv-e3a1e9c89e102dbf961c624435c495c759776312.tar.gz manaserv-e3a1e9c89e102dbf961c624435c495c759776312.tar.bz2 manaserv-e3a1e9c89e102dbf961c624435c495c759776312.tar.xz manaserv-e3a1e9c89e102dbf961c624435c495c759776312.zip |
Readded Entity:damage as lua function
Diffstat (limited to 'example/scripts/damage.lua')
-rw-r--r-- | example/scripts/damage.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/example/scripts/damage.lua b/example/scripts/damage.lua new file mode 100644 index 00000000..d031deee --- /dev/null +++ b/example/scripts/damage.lua @@ -0,0 +1,31 @@ +--[[ + + Offers damage functions + +--]] + + +-- damage is a table with these keys: +-- base, delta, chance_to_hit +function Entity:damage(source, damage) + local hp_loss = math.random(damage.base, damage.base + damage.delta) + local dodge = self:modified_attribute(ATTR_DODGE) + + if math.random(dodge) > math.random(damage.chance_to_hit) then + hp_loss = 0 -- attack missed + else + local defense = self:modified_attribute(ATTR_DEFENSE) + local randomness = hp_loss > 16 and math.random(hp_loss / 16) or 0 + hp_loss = hp_loss * (1 - (0.0159375 * defense) / (1 + 0.017 * defense)) + + randomness + end + + if hp_loss > 0 then + local hp = self:modified_attribute(ATTR_HP) + hp_loss = math.min(hp, hp_loss) + self:add_hit_taken(hp_loss) + self:set_base_attribute(ATTR_HP, hp - hp_loss) + else + hp_loss = 0 + end +end |