| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#include "ob_methods.h" |
| 24 |
#include "ob_types.h" |
| 25 |
#include "sounds.h" |
| 26 |
#include "sproto.h" |
| 27 |
|
| 28 |
static method_ret potion_type_apply(ob_methods *context, object *potion, |
| 29 |
object *applier, int aflags); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
void init_type_potion(void) { |
| 35 |
register_apply(POTION, potion_type_apply); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static method_ret potion_type_apply(ob_methods *context, object *potion, |
| 47 |
object *applier, int aflags) { |
| 48 |
int got_one = 0, i; |
| 49 |
object *force; |
| 50 |
|
| 51 |
if (applier->type == PLAYER) { |
| 52 |
if (!QUERY_FLAG(potion, FLAG_IDENTIFIED)) |
| 53 |
potion = identify(potion); |
| 54 |
} |
| 55 |
|
| 56 |
play_sound_map(SOUND_TYPE_ITEM, applier, 0, "drink"); |
| 57 |
apply_handle_yield(potion); |
| 58 |
|
| 59 |
|
| 60 |
if (applier->type == PLAYER && (potion->attacktype&AT_DEPLETE)) { |
| 61 |
if (QUERY_FLAG(potion, FLAG_CURSED) || QUERY_FLAG(potion, FLAG_DAMNED)) { |
| 62 |
drain_stat(applier); |
| 63 |
fix_object(applier); |
| 64 |
object_decrease_nrof_by_one(potion); |
| 65 |
return METHOD_OK; |
| 66 |
} |
| 67 |
|
| 68 |
if (remove_depletion(applier, potion->level) == 0) |
| 69 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 70 |
"Your potion had no effect."); |
| 71 |
|
| 72 |
object_decrease_nrof_by_one(potion); |
| 73 |
return METHOD_OK; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
if (applier->type == PLAYER && potion->attacktype&AT_GODPOWER) { |
| 78 |
for (i = 1; i < MIN(11, applier->level); i++) { |
| 79 |
if (QUERY_FLAG(potion, FLAG_CURSED) || QUERY_FLAG(potion, FLAG_DAMNED)) { |
| 80 |
if (applier->contr->levhp[i] != 1) { |
| 81 |
applier->contr->levhp[i] = 1; |
| 82 |
break; |
| 83 |
} |
| 84 |
if (applier->contr->levsp[i] != 1) { |
| 85 |
applier->contr->levsp[i] = 1; |
| 86 |
break; |
| 87 |
} |
| 88 |
if (applier->contr->levgrace[i] != 1) { |
| 89 |
applier->contr->levgrace[i] = 1; |
| 90 |
break; |
| 91 |
} |
| 92 |
} else { |
| 93 |
if (applier->contr->levhp[i] < 9) { |
| 94 |
applier->contr->levhp[i] = 9; |
| 95 |
break; |
| 96 |
} |
| 97 |
if (applier->contr->levsp[i] < 6) { |
| 98 |
applier->contr->levsp[i] = 6; |
| 99 |
break; |
| 100 |
} |
| 101 |
if (applier->contr->levgrace[i] < 3) { |
| 102 |
applier->contr->levgrace[i] = 3; |
| 103 |
break; |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
if (i < MIN(11, applier->level)) |
| 109 |
got_one = 1; |
| 110 |
if (!QUERY_FLAG(potion, FLAG_CURSED) && !QUERY_FLAG(potion, FLAG_DAMNED)) { |
| 111 |
if (got_one) { |
| 112 |
fix_object(applier); |
| 113 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 114 |
"The Gods smile upon you and remake you a little more in their image. " |
| 115 |
"You feel a little more perfect."); |
| 116 |
} else |
| 117 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 118 |
"The potion had no effect - you are already perfect"); |
| 119 |
} else { |
| 120 |
if (got_one) { |
| 121 |
fix_object(applier); |
| 122 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 123 |
"The Gods are angry and punish you."); |
| 124 |
} else |
| 125 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 126 |
"You are fortunate that you are so pathetic."); |
| 127 |
} |
| 128 |
object_decrease_nrof_by_one(potion); |
| 129 |
return METHOD_OK; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
if (potion->inv) { |
| 139 |
if (QUERY_FLAG(potion, FLAG_CURSED) || QUERY_FLAG(potion, FLAG_DAMNED)) { |
| 140 |
object *fball; |
| 141 |
|
| 142 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 143 |
"Yech! Your lungs are on fire!"); |
| 144 |
|
| 145 |
fball = create_archetype(EXPLODING_FIREBALL); |
| 146 |
fball->dam_modifier = random_roll(1, applier->level, applier, PREFER_LOW)/5+1; |
| 147 |
fball->stats.maxhp = random_roll(1, applier->level, applier, PREFER_LOW)/10+2; |
| 148 |
object_insert_in_map_at(fball, applier->map, NULL, 0, applier->x, applier->y); |
| 149 |
} else |
| 150 |
cast_spell(applier, potion, applier->facing, potion->inv, NULL); |
| 151 |
|
| 152 |
object_decrease_nrof_by_one(potion); |
| 153 |
|
| 154 |
if (!QUERY_FLAG(applier, FLAG_REMOVED)) |
| 155 |
fix_object(applier); |
| 156 |
return METHOD_OK; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
force = NULL; |
| 161 |
for (i = 0; i < NROFATTACKS; i++) { |
| 162 |
if (potion->resist[i]) { |
| 163 |
if (!force) |
| 164 |
force = create_archetype(FORCE_NAME); |
| 165 |
memcpy(force->resist, potion->resist, sizeof(potion->resist)); |
| 166 |
force->type = POTION_RESIST_EFFECT; |
| 167 |
force->speed = MOVE_PER_SECOND; |
| 168 |
force->duration = 60; |
| 169 |
break; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
if (force) { |
| 174 |
char name[MAX_BUF]; |
| 175 |
int resist = i; |
| 176 |
|
| 177 |
|
| 178 |
if (QUERY_FLAG(potion, FLAG_CURSED) || QUERY_FLAG(potion, FLAG_DAMNED)) { |
| 179 |
draw_ext_info_format(NDI_RED|NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, "The %s was cursed!", potion->name); |
| 180 |
force->duration *= 10; |
| 181 |
for (i = 0; i < NROFATTACKS; i++) |
| 182 |
if (force->resist[i] > 0) |
| 183 |
force->resist[i] = -force->resist[i]; |
| 184 |
} |
| 185 |
force->speed_left = -1; |
| 186 |
|
| 187 |
snprintf(name, MAX_BUF, "resistance to %s", change_resist_msg[resist]); |
| 188 |
free_string(force->name); |
| 189 |
force->name = add_string(name); |
| 190 |
store_spell_expiry(force); |
| 191 |
force = object_insert_in_ob(force, applier); |
| 192 |
CLEAR_FLAG(potion, FLAG_APPLIED); |
| 193 |
SET_FLAG(force, FLAG_APPLIED); |
| 194 |
change_abil(applier, force); |
| 195 |
object_decrease_nrof_by_one(potion); |
| 196 |
|
| 197 |
if (potion->other_arch != NULL && applier->map != NULL) { |
| 198 |
object_insert_in_map_at(arch_to_object(potion->other_arch), applier->map, NULL, INS_ON_TOP, applier->x, applier->y); |
| 199 |
} |
| 200 |
|
| 201 |
return METHOD_OK; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
if (applier->type == PLAYER) { |
| 206 |
if ((QUERY_FLAG(potion, FLAG_CURSED) || QUERY_FLAG(potion, FLAG_DAMNED)) |
| 207 |
&& potion->value != 0) |
| 208 |
CLEAR_FLAG(potion, FLAG_APPLIED); |
| 209 |
else |
| 210 |
SET_FLAG(potion, FLAG_APPLIED); |
| 211 |
if (!change_abil(applier, potion)) |
| 212 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 213 |
"Nothing happened."); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
CLEAR_FLAG(potion, FLAG_APPLIED); |
| 222 |
fix_object(applier); |
| 223 |
object_decrease_nrof_by_one(potion); |
| 224 |
return METHOD_OK; |
| 225 |
} |