Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 CrossFire, A Multiplayer game for X-windows 00003 00004 Copyright (C) 2007 Mark Wedel & Crossfire Development Team 00005 Copyright (C) 1992 Frank Tore Johansen 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 00021 The authors can be reached via e-mail at crossfire-devel@real-time.com 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 book_type_apply(ob_methods *context, object *op, 00033 object *applier, int aflags); 00034 00038 void init_type_book(void) { 00039 register_apply(BOOK, book_type_apply); 00040 } 00041 00051 static method_ret book_type_apply(ob_methods *context, object *op, object *applier, int aflags) { 00052 int lev_diff; 00053 object *skill_ob; 00054 00055 if (applier->type != PLAYER) 00056 return METHOD_UNHANDLED; 00057 00058 if (QUERY_FLAG(applier, FLAG_BLIND)&&!QUERY_FLAG(applier, FLAG_WIZ)) { 00059 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, 00060 "You are unable to read while blind.", NULL); 00061 return METHOD_OK; 00062 } 00063 if (op->msg == NULL) { 00064 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00065 "You open the %s and find it empty.", 00066 "You open the %s and find it empty.", 00067 op->name); 00068 return METHOD_OK; 00069 } 00070 00071 /* need a literacy skill to read stuff! */ 00072 skill_ob = find_skill_by_name(applier, op->skill); 00073 if (!skill_ob) { 00074 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00075 "You are unable to decipher the strange symbols.", NULL); 00076 return METHOD_OK; 00077 } 00078 lev_diff = op->level-(skill_ob->level+5); 00079 if (!QUERY_FLAG(applier, FLAG_WIZ) && lev_diff > 0) { 00080 if (lev_diff < 2) 00081 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00082 "This book is just barely beyond your comprehension.", NULL); 00083 else if (lev_diff < 3) 00084 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00085 "This book is slightly beyond your comprehension.", NULL); 00086 else if (lev_diff < 5) 00087 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00088 "This book is beyond your comprehension.", NULL); 00089 else if (lev_diff < 8) 00090 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00091 "This book is quite a bit beyond your comprehension.", NULL); 00092 else if (lev_diff < 15) 00093 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00094 "This book is way beyond your comprehension.", NULL); 00095 else 00096 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00097 "This book is totally beyond your comprehension.", NULL); 00098 return METHOD_OK; 00099 } 00100 00101 /* Lauwenmark: Handle for plugin book event */ 00102 /*printf("Book apply: %s\n", tmp->name); 00103 execute_event(tmp, EVENT_APPLY, op, NULL, SCRIPT_FIX_ALL); 00104 printf("Book applied: %s\n", tmp->name);*/ 00105 { 00106 char desc[MAX_BUF]; 00107 const readable_message_type *msgType = get_readable_message_type(op); 00108 00109 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, applier, msgType->message_type, msgType->message_subtype, 00110 "You open the %s and start reading.\n%s", 00111 "You open the %s and start reading.\n%s", 00112 ob_describe(op, applier, desc, sizeof(desc)), op->msg); 00113 } 00114 00115 /* gain xp from reading */ 00116 if (!QUERY_FLAG(op, FLAG_NO_SKILL_IDENT)) { 00117 /* only if not read before */ 00118 int exp_gain = calc_skill_exp(applier, op, skill_ob); 00119 00120 if (!QUERY_FLAG(op, FLAG_IDENTIFIED)) { 00121 /*exp_gain *= 2; because they just identified it too */ 00122 SET_FLAG(op, FLAG_IDENTIFIED); 00123 /* If in a container, update how it looks */ 00124 if (op->env) 00125 esrv_update_item(UPD_FLAGS|UPD_NAME, applier, op); 00126 else 00127 applier->contr->socket.update_look = 1; 00128 } 00129 change_exp(applier, exp_gain, skill_ob->skill, 0); 00130 /* so no more xp gained from this book */ 00131 SET_FLAG(op, FLAG_NO_SKILL_IDENT); 00132 } 00133 return METHOD_OK; 00134 }