fr.arakne.swflangloader.lang.classes.CharacteristicBoostCosts   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 92.59%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 87
ccs 25
cts 27
cp 0.9259
rs 10
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A costs() 0 2 1
A Cost.Cost(int,int) 0 3 1
A Cost.boost() 0 2 1
A at(int) 0 12 5
A Cost.cost() 0 2 1
A total(int) 0 21 4
A CharacteristicBoostCosts(int[[]]) 0 2 1
1
/*
2
 * This file is part of ArakneLangLoader.
3
 *
4
 * ArakneLangLoader 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
 * ArakneLangLoader 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 ArakneLangLoader.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2020 Vincent Quatrevieux
18
 */
19
20
package fr.arakne.swflangloader.lang.classes;
21
22
/**
23
 * Handle boosts intervals and costs
24
 */
25
final public class CharacteristicBoostCosts {
26
    final static public class Cost {
27
        final private int cost;
28
        final private int boost;
29
30 1
        public Cost(int cost, int boost) {
31 1
            this.cost = cost;
32 1
            this.boost = boost;
33 1
        }
34
35
        /**
36
         * @return The characteristic boost points cost
37
         */
38
        public int cost() {
39 1
            return cost;
40
        }
41
42
        /**
43
         * @return The boosted characteristics value
44
         */
45
        public int boost() {
46 1
            return boost;
47
        }
48
    }
49
50
    final private int[][] costs;
51
52 1
    public CharacteristicBoostCosts(int[][] costs) {
53 1
        this.costs = costs;
54 1
    }
55
56
    /**
57
     * Get the characteristic boost cost for the current characteristic value
58
     *
59
     * @param current The current characteristic value
60
     *
61
     * @return The cost
62
     */
63
    public Cost at(int current) {
64 1
        if (current < 0) {
65 1
            throw new IllegalArgumentException("Current characteristic value cannot be less than zero");
66
        }
67
68 1
        for (int i = costs.length - 1; i >= 0; --i) {
69 1
            if (costs[i][0] <= current) {
70 1
                return new Cost(costs[i][1], costs[i].length == 3 ? costs[i][2] : 1);
71
            }
72
        }
73
74
        throw new IllegalArgumentException("Cannot found any valid boost cost");
75
    }
76
77
    /**
78
     * Get the total points cost needed to reach the current value
79
     *
80
     * @param current The current value
81
     *
82
     * @return The spent points
83
     */
84
    public int total(int current) {
85 1
        int total = 0;
86
87 1
        for (int i = costs.length - 1; i >= 0; --i) {
88 1
            int[] cost = costs[i];
89
90 1
            if (cost[0] > current) {
91 1
                continue;
92
            }
93
94 1
            int value = current - cost[0];
95
96 1
            if (cost.length == 3) {
97 1
                value /= cost[2];
98
            }
99
100 1
            total += value * cost[1];
101 1
            current = cost[0];
102
        }
103
104 1
        return total;
105
    }
106
107
    /**
108
     * @return Raw costs
109
     */
110
    public int[][] costs() {
111
        return costs;
112
    }
113
}
114