-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
spl-monench.cc
167 lines (135 loc) · 4.21 KB
/
spl-monench.cc
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
/**
* @file
* @brief Monster-affecting enchantment spells.
* Other targeted enchantments are handled in spl-zap.cc.
**/
#include "AppHdr.h"
#include "spl-monench.h"
#include "env.h"
#include "message.h"
#include "spl-util.h"
#include "terrain.h"
int englaciate(coord_def where, int pow, actor *agent)
{
actor *victim = actor_at(where);
if (!victim || victim == agent)
return 0;
if (agent->is_monster() && mons_aligned(agent, victim))
return 0; // don't let monsters hit friendlies
monster* mons = victim->as_monster();
if (victim->res_cold() > 0
|| victim->is_stationary())
{
if (!mons)
canned_msg(MSG_YOU_UNAFFECTED);
else if (!mons_is_firewood(*mons))
simple_monster_message(*mons, " is unaffected.");
return 0;
}
int duration = roll_dice(3, pow) / 6 - victim->get_hit_dice() / 2;
if (duration <= 0)
{
if (!mons)
canned_msg(MSG_YOU_RESIST);
else
simple_monster_message(*mons, " resists.");
return 0;
}
if ((!mons && you.get_mutation_level(MUT_COLD_BLOODED))
|| (mons && mons_class_flag(mons->type, M_COLD_BLOOD)))
{
duration *= 2;
}
// Guarantee a minimum duration if not fully resisted.
duration = max(duration, 2 + random2(4));
if (!mons)
return slow_player(duration);
return do_slow_monster(*mons, agent, duration * BASELINE_DELAY);
}
spret cast_englaciation(int pow, bool fail)
{
fail_check();
mpr("You radiate an aura of cold.");
apply_area_visible([pow] (coord_def where) {
return englaciate(where, pow, &you);
}, you.pos());
return spret::success;
}
/** Corona a monster.
*
* @param mons the monster to get a backlight.
* @returns true if it got backlit (even if it was already).
*/
bool backlight_monster(monster* mons)
{
const mon_enchant bklt = mons->get_ench(ENCH_CORONA);
const mon_enchant zin_bklt = mons->get_ench(ENCH_SILVER_CORONA);
const int lvl = bklt.degree + zin_bklt.degree;
mons->add_ench(mon_enchant(ENCH_CORONA, 1));
if (lvl == 0)
simple_monster_message(*mons, " is outlined in light.");
else if (lvl == 4)
simple_monster_message(*mons, " glows brighter for a moment.");
else
simple_monster_message(*mons, " glows brighter.");
return true;
}
bool do_slow_monster(monster& mon, const actor* agent, int dur)
{
if (mon.stasis())
return true;
if (!mon.is_stationary()
&& mon.add_ench(mon_enchant(ENCH_SLOW, 0, agent, dur)))
{
if (!mon.paralysed() && !mon.petrified()
&& simple_monster_message(mon, " seems to slow down."))
{
return true;
}
}
return false;
}
bool enfeeble_monster(monster &mon, int pow)
{
const int res_margin = mon.check_willpower(&you, pow);
vector<enchant_type> hexes;
if (mons_has_attacks(mon))
hexes.push_back(ENCH_WEAK);
if (mon.antimagic_susceptible())
hexes.push_back(ENCH_ANTIMAGIC);
if (res_margin <= 0)
{
if (mons_can_be_blinded(mon.type))
hexes.push_back(ENCH_BLIND);
hexes.push_back(ENCH_DAZED);
}
// Resisted the upgraded effects, and immune to the irresistible effects.
if (hexes.empty())
{
return simple_monster_message(mon,
mon.resist_margin_phrase(res_margin).c_str());
}
const int max_extra_dur = div_rand_round(pow, 40);
const int dur = 5 + random2avg(max_extra_dur, 3);
for (auto hex : hexes)
{
if (mon.has_ench(hex))
{
mon_enchant ench = mon.get_ench(hex);
ench.duration = max(dur * BASELINE_DELAY, ench.duration);
mon.update_ench(ench);
}
else
mon.add_ench(mon_enchant(hex, 0, &you, dur * BASELINE_DELAY));
}
if (res_margin > 0)
simple_monster_message(mon, " partially resists.");
return simple_monster_message(mon, " is enfeebled!");
}
spret cast_vile_clutch(int pow, bolt &beam, bool fail)
{
spret result = zapping(ZAP_VILE_CLUTCH, pow, beam, true, nullptr, fail);
if (result == spret::success)
you.props[VILE_CLUTCH_POWER_KEY].get_int() = pow;
return result;
}