00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #include <global.h>
00027 #include <ob_methods.h>
00028 #include <ob_types.h>
00029 #include <sounds.h>
00030 #include <sproto.h>
00031
00032 static method_ret scroll_type_apply(ob_methods *context, object *op, object *applier, int aflags);
00033
00037 void init_type_scroll(void) {
00038 register_apply(SCROLL, scroll_type_apply);
00039 }
00040
00057 static method_ret scroll_type_apply(ob_methods *context, object *scroll,
00058 object *applier, int aflags) {
00059 object *skapplier;
00060 object *head;
00061 sstring name;
00062
00063 if (applier->head)
00064 head = applier->head;
00065 else
00066 head = applier;
00067
00068 if (QUERY_FLAG(applier, FLAG_BLIND)&&!QUERY_FLAG(applier, FLAG_WIZ)) {
00069 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
00070 "You are unable to read while blind.", NULL);
00071 return METHOD_OK;
00072 }
00073
00074 if (!scroll->inv || scroll->inv->type != SPELL) {
00075 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
00076 "The scroll just doesn't make sense!", NULL);
00077 return METHOD_OK;
00078 }
00079
00080 if (applier->type == PLAYER) {
00081
00082 int exp_gain = 0;
00083
00084
00085
00086
00087 skapplier = find_skill_by_name(applier, skill_names[SK_LITERACY]);
00088
00089 if (!skapplier) {
00090 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE,
00091 "You are unable to decipher the strange symbols.", NULL);
00092 return METHOD_OK;
00093 }
00094
00095 if (!QUERY_FLAG(scroll, FLAG_IDENTIFIED))
00096 identify(scroll);
00097
00098 if (QUERY_FLAG(scroll, FLAG_CURSED) || QUERY_FLAG(scroll, FLAG_DAMNED)) {
00099
00100
00101
00102
00103
00104
00105 int failure = -35;
00106
00107 if (settings.spell_failure_effects == TRUE)
00108 failure = -rndm(35, 100);
00109 scroll_failure(applier, failure, MAX(20, (scroll->level-skapplier->level)*5));
00110 decrease_ob(scroll);
00111 return METHOD_OK;
00112 }
00113
00114 if ((exp_gain = calc_skill_exp(applier, scroll, skapplier)))
00115 change_exp(applier, exp_gain, skapplier->skill, 0);
00116 }
00117
00118
00119 name = scroll->inv->name;
00120 cast_spell(applier, scroll, head->facing, scroll->inv, NULL);
00121
00122 if (QUERY_FLAG(scroll, FLAG_BLESSED) && die_roll(1, 100, applier, 1) < 10) {
00123 draw_ext_info_format(NDI_BLACK, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00124 "Your scroll of %s glows for a second!",
00125 "Your scroll of %s glows for a second!",
00126 name);
00127 } else {
00128 draw_ext_info_format(NDI_BLACK, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00129 "The scroll of %s turns to dust.",
00130 "The scroll of %s turns to dust.",
00131 name);
00132
00133 decrease_ob(scroll);
00134 }
00135 return METHOD_OK;
00136 }