1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # COmbat interactions between characters.
20 # Something that can be used to attack someone and inflict damage.
22 # Damage per second inflicted by this weapon.
23 fun dps
: Float is abstract
26 # Something that can be combatted, it can `attack` and `defend`.
28 # World items can also be `Combatable`.
29 # `defend` method is then used to determines how the object react to an attack
30 # Some magical items can even `attack`.
32 fun hit_points
: Int is abstract
34 # A `Combatable` can attack a `target` that is also a `Combatable`.
36 # Attack the `target` using `wepaon` and returns the number of inflicted hit points.
37 fun attack
(target
: Combatable, weapon
: Weapon): Int is abstract
39 # Like `attack` but cannot be defended.
40 fun direct_attack
(target
: Combatable, weapon
: Weapon): Int is abstract
42 # `Combatable` can defend against attacks.
44 # Defends against a number of received hit points and return the number of pared hit points.
46 # @param hit: damage received.
47 fun defend
(hit
: Int): Int is abstract
49 # Is the character still have hit_points?
50 fun is_dead
: Bool do return hit_points
> 0
53 # Characters are now `Comabatable`
57 # Use character `health` to determines hit_points.
58 redef fun hit_points
do return health
61 # Dwarves can be used as weapons.
65 # Dwarf `dps` are based on the dwarf `base_endurance` (represents weight here)
66 redef fun dps
do return base_endurance
.to_f
/ 10.0