1
|
|
|
/* |
2
|
|
|
* This file is part of Araknemu. |
3
|
|
|
* |
4
|
|
|
* Araknemu is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* Araknemu is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2017-2019 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.game.fight.fighter.player; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.ActiveFighter; |
23
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.BaseFighterLife; |
24
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; |
25
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife; |
26
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter; |
27
|
|
|
import fr.quatrevieux.araknemu.game.world.creature.Life; |
28
|
|
|
import org.checkerframework.checker.index.qual.NonNegative; |
29
|
|
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Handle life points for {@link PlayerFighter} |
33
|
|
|
* |
34
|
|
|
* The life points will be saved when fight started |
35
|
|
|
*/ |
36
|
|
|
public final class PlayerFighterLife implements FighterLife { |
37
|
|
|
private final Life baseLife; |
38
|
|
|
private final Fighter fighter; |
39
|
|
|
|
40
|
|
|
private @MonotonicNonNull BaseFighterLife delegate; |
41
|
|
|
|
42
|
1 |
|
public PlayerFighterLife(Life baseLife, Fighter fighter) { |
43
|
1 |
|
this.baseLife = baseLife; |
44
|
1 |
|
this.fighter = fighter; |
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
|
@Override |
48
|
|
|
public @NonNegative int current() { |
49
|
1 |
|
return delegate != null ? delegate.current() : baseLife.current(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
@Override |
53
|
|
|
public @NonNegative int max() { |
54
|
1 |
|
return delegate != null ? delegate.max() : baseLife.max(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
@Override |
58
|
|
|
public boolean dead() { |
59
|
1 |
|
return delegate != null && delegate.dead(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
@Override |
63
|
|
|
public int alter(PassiveFighter caster, int value) { |
64
|
1 |
|
if (delegate == null) { |
65
|
1 |
|
throw new IllegalStateException("PlayerFighterLife must be initialized"); |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
return delegate.alter(caster, value); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
@Override |
72
|
|
|
public void alterMax(PassiveFighter caster, int value) { |
73
|
1 |
|
if (delegate == null) { |
74
|
1 |
|
throw new IllegalStateException("PlayerFighterLife must be initialized"); |
75
|
|
|
} |
76
|
|
|
|
77
|
1 |
|
delegate.alterMax(caster, value); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
@Override |
81
|
|
|
public void kill(ActiveFighter caster) { |
82
|
1 |
|
if (delegate == null) { |
83
|
1 |
|
throw new IllegalStateException("PlayerFighterLife must be initialized"); |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
delegate.kill(caster); |
87
|
1 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Initialise the fighter life when fight is started |
91
|
|
|
*/ |
92
|
|
|
public void init() { |
93
|
1 |
|
if (delegate != null) { |
94
|
1 |
|
throw new IllegalStateException("Player fighter life is already initialised"); |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
delegate = new BaseFighterLife(fighter, baseLife.current(), baseLife.max()); |
98
|
1 |
|
} |
99
|
|
|
} |
100
|
|
|
|