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
|
#include "StarDamageTypes.hpp"
namespace Star {
EnumMap<DamageType> const DamageTypeNames{{DamageType::NoDamage, "NoDamage"},
{DamageType::Damage, "Damage"},
{DamageType::IgnoresDef, "IgnoresDef"},
{DamageType::Knockback, "Knockback"},
{DamageType::Environment, "Environment"},
{DamageType::Status, "Status"}};
EnumMap<HitType> const HitTypeNames{
{HitType::Hit, "Hit"},
{HitType::StrongHit, "StrongHit"},
{HitType::WeakHit, "WeakHit"},
{HitType::ShieldHit, "ShieldHit"},
{HitType::Kill, "Kill"}};
EnumMap<TeamType> const TeamTypeNames{{TeamType::Null, "null"},
{TeamType::Friendly, "friendly"},
{TeamType::Enemy, "enemy"},
{TeamType::PVP, "pvp"},
{TeamType::Passive, "passive"},
{TeamType::Ghostly, "ghostly"},
{TeamType::Environment, "environment"},
{TeamType::Indiscriminate, "indiscriminate"},
{TeamType::Assistant, "assistant"}};
EntityDamageTeam::EntityDamageTeam() : type(TeamType::Null), team(0) {}
EntityDamageTeam::EntityDamageTeam(TeamType type, TeamNumber team) : type(type), team(team) {}
EntityDamageTeam::EntityDamageTeam(Json const& json) {
type = TeamTypeNames.getLeft(json.getString("type"));
team = json.getUInt("team", 0);
}
Json EntityDamageTeam::toJson() const {
return JsonObject{{"type", TeamTypeNames.getRight(type)}, {"team", team}};
}
bool EntityDamageTeam::canDamage(EntityDamageTeam victim, bool victimIsSelf) const {
if (victimIsSelf) {
if (type == TeamType::Indiscriminate)
return true;
} else if (type == TeamType::Friendly) {
if (victim.type == TeamType::Enemy || victim.type == TeamType::Passive || victim.type == TeamType::Environment || victim.type == TeamType::Indiscriminate)
return true;
} else if (type == TeamType::Enemy) {
if (victim.type == TeamType::Friendly || victim.type == TeamType::PVP || victim.type == TeamType::Indiscriminate)
return true;
else if (victim.type == TeamType::Enemy && team != victim.team)
return true;
} else if (type == TeamType::PVP) {
if (victim.type == TeamType::Enemy || victim.type == TeamType::Passive || victim.type == TeamType::Environment || victim.type == TeamType::Indiscriminate)
return true;
else if (victim.type == TeamType::PVP && (team == 0 || team != victim.team))
return true;
} else if (type == TeamType::Passive) {
// never deal damage
} else if (type == TeamType::Ghostly) {
// never deal damage
} else if (type == TeamType::Environment) {
if (victim.type == TeamType::Friendly || victim.type == TeamType::PVP || victim.type == TeamType::Indiscriminate)
return true;
} else if (type == TeamType::Indiscriminate) {
if (victim.type == TeamType::Friendly || victim.type == TeamType::Enemy || victim.type == TeamType::PVP
|| victim.type == TeamType::Passive
|| victim.type == TeamType::Environment
|| victim.type == TeamType::Indiscriminate)
return true;
} else if (type == TeamType::Assistant) {
if (victim.type == TeamType::Enemy || victim.type == TeamType::Passive || victim.type == TeamType::Environment || victim.type == TeamType::Indiscriminate)
return true;
}
return false;
}
bool EntityDamageTeam::operator==(EntityDamageTeam const& rhs) const {
return tie(type, team) == tie(rhs.type, rhs.team);
}
DataStream& operator<<(DataStream& ds, EntityDamageTeam const& team) {
ds.write(team.type);
ds.write(team.team);
return ds;
}
DataStream& operator>>(DataStream& ds, EntityDamageTeam& team) {
ds.read(team.type);
ds.read(team.team);
return ds;
}
TeamNumber soloPvpTeam(ConnectionId clientId) {
return (TeamNumber)clientId;
}
}
|