| 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 |
#include <global.h> |
| 27 |
#include <ob_methods.h> |
| 28 |
#include <ob_types.h> |
| 29 |
#include <sounds.h> |
| 30 |
#include <sproto.h> |
| 31 |
|
| 32 |
static method_ret book_type_apply(ob_methods *context, object *op, |
| 33 |
object *applier, int aflags); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
void init_type_book(void) { |
| 39 |
register_apply(BOOK, book_type_apply); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
static method_ret book_type_apply(ob_methods *context, object *op, object *applier, int aflags) { |
| 52 |
int lev_diff; |
| 53 |
object *skill_ob; |
| 54 |
|
| 55 |
if (applier->type != PLAYER) |
| 56 |
return METHOD_UNHANDLED; |
| 57 |
|
| 58 |
if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) { |
| 59 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 60 |
"You are unable to read while blind."); |
| 61 |
return METHOD_OK; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
skill_ob = find_skill_by_name(applier, op->skill); |
| 66 |
if (!skill_ob) { |
| 67 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 68 |
"You are unable to decipher the strange symbols."); |
| 69 |
return METHOD_OK; |
| 70 |
} |
| 71 |
lev_diff = op->level-(skill_ob->level+5); |
| 72 |
if (!QUERY_FLAG(applier, FLAG_WIZ) && lev_diff > 0) { |
| 73 |
if (lev_diff < 2) |
| 74 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 75 |
"This book is just barely beyond your comprehension."); |
| 76 |
else if (lev_diff < 3) |
| 77 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 78 |
"This book is slightly beyond your comprehension."); |
| 79 |
else if (lev_diff < 5) |
| 80 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 81 |
"This book is beyond your comprehension."); |
| 82 |
else if (lev_diff < 8) |
| 83 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 84 |
"This book is quite a bit beyond your comprehension."); |
| 85 |
else if (lev_diff < 15) |
| 86 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 87 |
"This book is way beyond your comprehension."); |
| 88 |
else |
| 89 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 90 |
"This book is totally beyond your comprehension."); |
| 91 |
return METHOD_OK; |
| 92 |
} |
| 93 |
|
| 94 |
if (op->msg == NULL) { |
| 95 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 96 |
"You open the %s and find it empty.", |
| 97 |
op->name); |
| 98 |
} else { |
| 99 |
char desc[MAX_BUF]; |
| 100 |
const readable_message_type *msgType = get_readable_message_type(op); |
| 101 |
|
| 102 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, applier, msgType->message_type, msgType->message_subtype, |
| 103 |
"You open the %s and start reading.\n%s", |
| 104 |
ob_describe(op, applier, 0, desc, sizeof(desc)), op->msg); |
| 105 |
if (applier->contr) |
| 106 |
knowledge_read(applier->contr, op); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
if (!QUERY_FLAG(op, FLAG_NO_SKILL_IDENT)) { |
| 111 |
|
| 112 |
int exp_gain = calc_skill_exp(applier, op, skill_ob); |
| 113 |
|
| 114 |
if (!QUERY_FLAG(op, FLAG_IDENTIFIED)) { |
| 115 |
|
| 116 |
SET_FLAG(op, FLAG_IDENTIFIED); |
| 117 |
|
| 118 |
if (op->env) |
| 119 |
esrv_update_item(UPD_FLAGS|UPD_NAME, applier, op); |
| 120 |
else |
| 121 |
applier->contr->socket.update_look = 1; |
| 122 |
} |
| 123 |
change_exp(applier, exp_gain, skill_ob->skill, 0); |
| 124 |
|
| 125 |
SET_FLAG(op, FLAG_NO_SKILL_IDENT); |
| 126 |
} |
| 127 |
return METHOD_OK; |
| 128 |
} |