Test Failed
Push — dev ( 708190...bf98d5 )
by Nico
07:04
created

DamageWrapper::setModificator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
3
/*
4
 *
5
 * Copyright 2010 Daniel Jakob All Rights Reserved
6
 * This software is the proprietary information of Daniel Jakob
7
 * Use is subject to license terms
8
 *
9
 */
10
11
/* $Id:$ */
12
13
namespace Stu\Lib;
14
15
use Stu\Component\Ship\ShipEnum;
16
use Stu\Component\Ship\ShipRoleEnum;
17
use Stu\Orm\Entity\ColonyInterface;
18
use Stu\Orm\Entity\ShipInterface;
19
20
/**
21
 * @author Daniel Jakob <[email protected]>
22
 * @version $Revision: 1.4 $
23
 * @access public
24
 */
25
class DamageWrapper
26
{ #{{{
27
    private $damage = 0;
28
    private $source = false;
29
    private $isCrit = false;
30
    private $modificator = 100;
31
32
    /**
33
     */
34
    public function __construct($damage, $source = false)
35
    { #{{{
36
        $this->damage = $damage;
37
        $this->source = $source;
38
    } # }}}
39
40
    private $hull_damage_factor = 100;
41
42
    /**
43
     */
44
    public function setHullDamageFactor($value)
45
    { #{{{
46
        $this->hull_damage_factor = $value;
47
    } # }}}
48
49
    /**
50
     */
51
    public function getHullDamageFactor()
52
    { #{{{
53
        return $this->hull_damage_factor;
54
    } # }}}
55
56
    public function setCrit(bool $isCrit)
57
    {
58
        $this->isCrit = $isCrit;
59
    }
60
61
    public function isCrit(): bool
62
    {
63
        return $this->isCrit;
64
    }
65
66
    private $shield_damage_factor = 100;
67
68
    /**
69
     */
70
    public function setShieldDamageFactor($value)
71
    { #{{{
72
        $this->shield_damage_factor = $value;
73
    } # }}}
74
75
    /**
76
     */
77
    public function getShieldDamageFactor()
78
    { #{{{
79
        return $this->shield_damage_factor;
80
    } # }}}
81
82
    private $is_phaser_damage = false;
83
84
    /**
85
     */
86
    public function setIsPhaserDamage($value)
87
    { #{{{
88
        $this->is_phaser_damage = $value;
89
    } # }}}
90
91
    /**
92
     */
93
    public function getIsPhaserDamage()
94
    { #{{{
95
        return $this->is_phaser_damage;
96
    } # }}}
97
98
    private $is_torpedo_damage = false;
99
100
    /**
101
     */
102
    public function setIsTorpedoDamage($value)
103
    { #{{{
104
        $this->is_torpedo_damage = $value;
105
    } # }}}
106
107
    /**
108
     */
109
    public function getIsTorpedoDamage()
110
    { #{{{
111
        return $this->is_torpedo_damage;
112
    } # }}}
113
114
    /**
115
     */
116
    public function getSource()
117
    { #{{{
118
        return $this->source;
119
    } # }}}
120
121
    /**
122
     */
123
    public function setDamage($value)
124
    { #{{{
125
        $this->damage = $value;
126
    } # }}}
127
128
    /**
129
     */
130
    public function getDamage()
131
    { #{{{
132
        return $this->damage;
133
    } # }}}
134
135
    public function getModificator()
136
    { #{{{
137
        return $this->modificator;
138
    } # }}}
139
140
    public function setModificator($value)
141
    { #{{{
142
        $this->modificator = $value;
143
    } # }}}
144
145
    /**
146
     */
147
    public function getDamageRelative($target, $mode, $isColony = false)
148
    { #{{{
149
        if ($isColony) {
150
            if ($mode === ShipEnum::DAMAGE_MODE_HULL) {
151
                return $this->calculateDamageBuilding();
152
            }
153
            return $this->calculateDamageColonyShields($target);
154
        }
155
        if ($mode === ShipEnum::DAMAGE_MODE_HULL) {
156
            return $this->calculateDamageHull($target);
157
        }
158
        return $this->calculateDamageShields($target);
159
    } # }}}
160
161
    /**
162
     */
163
    private function calculateDamageShields(ShipInterface $target)
164
    { #{{{
165
        $damage = round($this->getDamage() / 100 * $this->getShieldDamageFactor());
166
        /* paratrinic shields
167
        if ($this->getSource() && $target->getRump()->getRoleId() == ShipRoleEnum::ROLE_TORPEDOSHIP && $this->getSource()->getRump()->getRoleId() != ShipRoleEnum::ROLE_PULSESHIP) {
168
            $damage = round($damage * 0.6);
169
        } */
170
        if ($damage < $target->getShield()) {
171
            $this->setDamage(0);
172
        } else {
173
            $this->setDamage(round($damage - $target->getShield() / $this->getShieldDamageFactor() * 100));
174
        }
175
        return $damage;
176
    } # }}}
177
178
    /**
179
     */
180
    private function calculateDamageColonyShields(ColonyInterface $target)
181
    { #{{{
182
        $damage = round($this->getDamage() / 100 * $this->getShieldDamageFactor());
183
        // paratrinic shields
184
        if ($damage < $target->getShields()) {
185
            $this->setDamage(0);
186
        } else {
187
            $this->setDamage(round($damage - $target->getShields() / $this->getShieldDamageFactor() * 100));
188
        }
189
        return $damage;
190
    } # }}}
191
192
    /**
193
     */
194
    private function calculateDamageHull(ShipInterface $target)
0 ignored issues
show
Unused Code introduced by
The parameter $target is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

194
    private function calculateDamageHull(/** @scrutinizer ignore-unused */ ShipInterface $target)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
195
    { #{{{
196
        $damage = round($this->getDamage() / 100 * $this->getHullDamageFactor());
197
        // ablative huell plating
198
        if ($this->getIsTorpedoDamage() === true) {
199
            $damage = round($damage * ($this->getModificator() / 100));
200
        }
201
        return $damage;
202
    } # }}}
203
204
    /**
205
     */
206
    private function calculateDamageBuilding()
207
    { #{{{
208
        $damage = round($this->getDamage() / 100 * $this->getHullDamageFactor());
209
        return $damage;
210
    } # }}}
211
} #}}}