forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweakpoint.h
181 lines (158 loc) · 6.45 KB
/
weakpoint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#pragma once
#ifndef CATA_SRC_WEAKPOINT_H
#define CATA_SRC_WEAKPOINT_H
#include <array>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "damage.h"
#include "optional.h"
#include "type_id.h"
class Character;
class Creature;
class JsonArray;
class JsonObject;
class JsonValue;
// Information about an attack on a weak point.
struct weakpoint_attack {
enum class attack_type : int {
NONE, // Unusual damage instances, such as falls, spells, and effects.
MELEE_BASH, // Melee bludgeoning attacks
MELEE_CUT, // Melee slashing attacks
MELEE_STAB, // Melee piercing attacks
PROJECTILE, // Ranged projectile attacks, including throwing weapons and guns
NUM,
};
// The source of the attack.
const Creature *source;
// The target of the attack.
const Creature *target;
// The weapon used to make the attack.
const item *weapon;
// The type of the attack.
attack_type type;
// Whether the attack from a thrown object.
bool is_thrown;
// Whether the attack a critical hit.
bool is_crit;
// The Creature's skill in hitting weak points.
float wp_skill;
weakpoint_attack();
// Returns the attack type of a melee attack.
static attack_type type_of_melee_attack( const damage_instance &damage );
// Compute and set the value of `wp_skill`.
void compute_wp_skill();
};
// An effect that a weakpoint can cause.
struct weakpoint_effect {
// The type of the effect.
efftype_id effect;
// The percent chance of causing the effect.
float chance;
// Whether the effect is permanent.
bool permanent;
// The range of the durations (in turns) of the effect.
std::pair<int, int> duration;
// The range of the intensities of the effect.
std::pair<int, int> intensity;
// The range of damage, as a percentage of max health, required to the effect.
std::pair<float, float> damage_required;
// The message to print, if the player causes the effect.
std::string message;
weakpoint_effect();
// Maybe apply an effect to the target.
void apply_to( Creature &target, int total_damage, const weakpoint_attack &attack ) const;
void load( const JsonObject &jo );
};
struct weakpoint_difficulty {
std::array<float, static_cast<int>( weakpoint_attack::attack_type::NUM )> difficulty;
explicit weakpoint_difficulty( float default_value );
float of( const weakpoint_attack &attack ) const;
void load( const JsonObject &jo );
};
struct weakpoint_family {
// ID of the family. Equal to the proficiency, if not provided.
std::string id;
// Name of proficiency corresponding to the family.
proficiency_id proficiency;
// The skill bonus for having the proficiency.
cata::optional<float> bonus;
// The skill penalty for not having the proficiency.
cata::optional<float> penalty;
float modifier( const Character &attacker ) const;
void load( const JsonValue &jsin );
};
struct weakpoint_families {
// List of weakpoint families
std::vector<weakpoint_family> families;
// Practice all weak point families for the given duration. Returns true if a proficiency was practiced.
bool practice( Character &learner, const time_duration &amount ) const;
bool practice_hit( Character &learner ) const;
bool practice_kill( Character &learner ) const;
bool practice_dissect( Character &learner ) const;
float modifier( const Character &attacker ) const;
void clear();
void load( const JsonArray &ja );
void remove( const JsonArray &ja );
};
struct weakpoint {
// ID of the weakpoint. Equal to the name, if not provided.
std::string id;
// Name of the weakpoint. Can be empty.
std::string name;
// Percent chance of hitting the weakpoint. Can be increased by skill.
float coverage = 100.0f;
// Multiplier for existing armor values. Defaults to 1.
std::array<float, static_cast<int>( damage_type::NUM )> armor_mult;
// Flat penalty to armor values. Applied after the multiplier.
std::array<float, static_cast<int>( damage_type::NUM )> armor_penalty;
// Damage multipliers. Applied after armor.
std::array<float, static_cast<int>( damage_type::NUM )> damage_mult;
// Critical damage multiplers. Applied after armor instead of damage_mult, if the attack is a crit.
std::array<float, static_cast<int>( damage_type::NUM )>crit_mult;
// A list of required effects.
std::vector<efftype_id> required_effects;
// A list of effects that may trigger by hitting this weak point.
std::vector<weakpoint_effect> effects;
// Constant coverage multipliers, depending on the attack type.
weakpoint_difficulty coverage_mult;
// Difficulty gates, varying by the attack type.
weakpoint_difficulty difficulty;
weakpoint();
// Apply the armor multipliers and offsets to a set of resistances.
void apply_to( resistances &resistances ) const;
// Apply the damage multiplers to a set of damage values.
void apply_to( damage_instance &damage, bool is_crit ) const;
void apply_effects( Creature &target, int total_damage, const weakpoint_attack &attack ) const;
// Return the change of the creature hitting the weakpoint.
float hit_chance( const weakpoint_attack &attack ) const;
void load( const JsonObject &jo );
};
struct weakpoints {
// id of this set of weakpoints (inline weakpoints have a null id)
weakpoints_id id;
// List of weakpoints. Each weakpoint should have a unique id.
std::vector<weakpoint> weakpoint_list;
// Default weakpoint to return.
weakpoint default_weakpoint;
// TODO: make private
bool was_loaded = false;
// Selects a weakpoint to hit.
const weakpoint *select_weakpoint( const weakpoint_attack &attack ) const;
void clear();
// load inline definition
void load( const JsonArray &ja );
void remove( const JsonArray &ja );
/********************* weakpoint_set handling ****************************/
// load standalone JSON type
void load( const JsonObject &jo, const std::string &src );
void add_from_set( const weakpoints_id &set_id, bool replace_id );
void add_from_set( const weakpoints &set, bool replace_id );
void del_from_set( const weakpoints_id &set_id );
void del_from_set( const weakpoints &set );
static void load_weakpoint_sets( const JsonObject &jo, const std::string &src );
static void reset();
static const std::vector<weakpoints> &get_all();
};
#endif // CATA_SRC_WEAKPOINT_H