| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "global.h" |
| 25 |
|
| 26 |
#include <errno.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include "output_file.h" |
| 31 |
#include "sproto.h" |
| 32 |
#include "spells.h" |
| 33 |
|
| 34 |
static int resurrection_fails(int levelcaster, int leveldead); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
static int resurrect_player(object *op, char *playername, object *spell, char *accountname) { |
| 53 |
FILE *deadplayer, *liveplayer; |
| 54 |
OutputFile of; |
| 55 |
char oldname[MAX_BUF]; |
| 56 |
char newname[MAX_BUF]; |
| 57 |
char path[MAX_BUF]; |
| 58 |
char buf[MAX_BUF]; |
| 59 |
char buf2[MAX_BUF]; |
| 60 |
const char *race = NULL; |
| 61 |
int64_t exp; |
| 62 |
int Con; |
| 63 |
|
| 64 |
|
| 65 |
if (spell->race) { |
| 66 |
treasurelist *tl = find_treasurelist(spell->race); |
| 67 |
treasure *t; |
| 68 |
int value; |
| 69 |
|
| 70 |
if (!tl) { |
| 71 |
LOG(llevError, "resurrect_player: race set to %s, but no treasurelist of that name!\n", spell->race); |
| 72 |
return 0; |
| 73 |
} |
| 74 |
value = RANDOM()%tl->total_chance; |
| 75 |
for (t = tl->items; t; t = t->next) { |
| 76 |
value -= t->chance; |
| 77 |
if (value < 0) |
| 78 |
break; |
| 79 |
} |
| 80 |
if (!t) { |
| 81 |
LOG(llevError, "resurrect_player: got null treasure from treasurelist %s!\n", spell->race); |
| 82 |
return 0; |
| 83 |
} |
| 84 |
race = t->item->name; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
snprintf(path, sizeof(path), "%s/%s/%s/%s", settings.localdir, settings.playerdir, playername, playername); |
| 89 |
|
| 90 |
strcpy(newname, path); |
| 91 |
strcat(newname, ".pl"); |
| 92 |
|
| 93 |
strcpy(oldname, newname); |
| 94 |
strcat(oldname, ".dead"); |
| 95 |
|
| 96 |
if (!(deadplayer = fopen(oldname, "r"))) { |
| 97 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 98 |
"The soul of %s cannot be reached.", |
| 99 |
playername); |
| 100 |
return 0; |
| 101 |
} |
| 102 |
|
| 103 |
if (!access(newname, 0)) { |
| 104 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 105 |
"The soul of %s has already been reborn!", |
| 106 |
playername); |
| 107 |
fclose(deadplayer); |
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
liveplayer = of_open(&of, newname); |
| 112 |
if (liveplayer == NULL) { |
| 113 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 114 |
"The soul of %s cannot be re-embodied at the moment.", |
| 115 |
playername); |
| 116 |
fclose(deadplayer); |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
while (!feof(deadplayer)) { |
| 121 |
if ( fgets(buf, 255, deadplayer) == NULL ) break; |
| 122 |
sscanf(buf, "%s", buf2); |
| 123 |
if (!(strcmp(buf2, "exp"))) { |
| 124 |
sscanf(buf, "%s %"FMT64, buf2, &exp); |
| 125 |
if (spell->stats.exp) { |
| 126 |
exp -= exp/spell->stats.exp; |
| 127 |
snprintf(buf, sizeof(buf), "exp %"FMT64"\n", exp); |
| 128 |
} |
| 129 |
} |
| 130 |
if (!(strcmp(buf2, "Con"))) { |
| 131 |
sscanf(buf, "%s %d", buf2, &Con); |
| 132 |
Con -= spell->stats.Con; |
| 133 |
if (Con < 1) |
| 134 |
Con = 1; |
| 135 |
snprintf(buf, sizeof(buf), "Con %d\n", Con); |
| 136 |
} |
| 137 |
if (race && !strcmp(buf2, "race")) { |
| 138 |
snprintf(buf, sizeof(buf), "race %s\n", race); |
| 139 |
} |
| 140 |
fputs(buf, liveplayer); |
| 141 |
} |
| 142 |
if (!of_close(&of)) { |
| 143 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 144 |
"The soul of %s cannot be re-embodied at the moment.", |
| 145 |
playername); |
| 146 |
fclose(deadplayer); |
| 147 |
return 0; |
| 148 |
} |
| 149 |
fclose(deadplayer); |
| 150 |
unlink(oldname); |
| 151 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 152 |
"%s lives again!", |
| 153 |
playername); |
| 154 |
|
| 155 |
|
| 156 |
if (accountname) |
| 157 |
unmake_perma_dead(accountname, playername); |
| 158 |
return 1; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg) { |
| 182 |
object *temp, *newob; |
| 183 |
char name_to_resurrect[MAX_BUF]; |
| 184 |
char *corpse_account = NULL; |
| 185 |
int leveldead = 25, mflags, clevel; |
| 186 |
int16_t sx, sy; |
| 187 |
mapstruct *m; |
| 188 |
int spell_success = 0; |
| 189 |
|
| 190 |
clevel = caster_level(caster, spell); |
| 191 |
|
| 192 |
if (spell->last_heal) { |
| 193 |
if (!arg) { |
| 194 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 195 |
"Cast %s on who?", |
| 196 |
spell->name); |
| 197 |
return 0; |
| 198 |
} |
| 199 |
safe_strncpy(name_to_resurrect, arg, sizeof(name_to_resurrect)); |
| 200 |
temp = NULL; |
| 201 |
} else { |
| 202 |
sx = op->x+freearr_x[dir]; |
| 203 |
sy = op->y+freearr_y[dir]; |
| 204 |
m = op->map; |
| 205 |
mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); |
| 206 |
if (mflags&P_OUT_OF_MAP) |
| 207 |
temp = NULL; |
| 208 |
else { |
| 209 |
|
| 210 |
|
| 211 |
temp = NULL; |
| 212 |
FOR_MAP_PREPARE(m, sx, sy, tmp) |
| 213 |
|
| 214 |
if (tmp->type == CORPSE) { |
| 215 |
temp = tmp; |
| 216 |
break; |
| 217 |
} |
| 218 |
FOR_MAP_FINISH(); |
| 219 |
} |
| 220 |
|
| 221 |
if (temp == NULL) { |
| 222 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 223 |
"You need a body for this spell."); |
| 224 |
return 0; |
| 225 |
} |
| 226 |
safe_strncpy(name_to_resurrect, temp->name, sizeof(name_to_resurrect)); |
| 227 |
|
| 228 |
if (temp->slaying){ |
| 229 |
corpse_account = (char *)CALLOC(sizeof(char), MAX_BUF); |
| 230 |
|
| 231 |
if (corpse_account) strcpy(corpse_account, temp->slaying); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
if (temp && temp->map) { |
| 236 |
|
| 237 |
archetype *arch = find_archetype("burnout"); |
| 238 |
if (arch != NULL) { |
| 239 |
newob = arch_to_object(arch); |
| 240 |
if (newob != NULL) |
| 241 |
object_insert_in_map_at(newob, temp->map, op, 0, temp->x, temp->y); |
| 242 |
} |
| 243 |
leveldead = temp->level; |
| 244 |
object_remove(temp); |
| 245 |
object_free_drop_inventory(temp); |
| 246 |
} |
| 247 |
|
| 248 |
if (resurrection_fails(clevel, leveldead)) { |
| 249 |
if (spell->randomitems) { |
| 250 |
treasure *t; |
| 251 |
|
| 252 |
for (t = spell->randomitems->items; t; t = t->next) { |
| 253 |
summon_hostile_monsters(op, t->nrof, t->item->name); |
| 254 |
} |
| 255 |
} |
| 256 |
spell_success = 1; |
| 257 |
} else { |
| 258 |
spell_success = resurrect_player(op, name_to_resurrect, spell, corpse_account); |
| 259 |
} |
| 260 |
|
| 261 |
free(corpse_account); |
| 262 |
return spell_success; |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
static int resurrection_fails(int levelcaster, int leveldead) { |
| 281 |
int chance = 9; |
| 282 |
|
| 283 |
chance += levelcaster-leveldead; |
| 284 |
if (chance < 4) |
| 285 |
chance = 4; |
| 286 |
if (chance > rndm(0, 19)) |
| 287 |
return 0; |
| 288 |
return 1; |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
void dead_player(object *op) { |
| 298 |
char filename[MAX_BUF]; |
| 299 |
char newname[MAX_BUF]; |
| 300 |
char path[MAX_BUF]; |
| 301 |
|
| 302 |
|
| 303 |
snprintf(path, sizeof(path), "%s/%s/%s/%s", settings.localdir, settings.playerdir, op->name, op->name); |
| 304 |
|
| 305 |
strcpy(filename, path); |
| 306 |
strcat(filename, ".pl"); |
| 307 |
strcpy(newname, filename); |
| 308 |
strcat(newname, ".dead"); |
| 309 |
|
| 310 |
if (rename(filename, newname) != 0) { |
| 311 |
LOG(llevError, "Cannot rename dead player's file %s into %s: %s\n", filename, newname, strerror(errno)); |
| 312 |
} |
| 313 |
|
| 314 |
if (make_perma_dead(op)){ |
| 315 |
|
| 316 |
LOG(llevError, "Could not edit the account to indicate permanent death for %s!\n", op->name); |
| 317 |
} |
| 318 |
} |