Atrinik Server 2.5
skills/inscription.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #include <global.h>
00031 #include <book.h>
00032 
00039 static int inscribe_book(object *op, const char *msg, object *marked)
00040 {
00041     char buf[BOOK_BUF];
00042 
00043     if (!msg || *msg == '\0')
00044     {
00045         new_draw_info(0, COLOR_WHITE, op, "No message to write. Usage:\n/use_skill inscription <message>");
00046         return 0;
00047     }
00048 
00049     /* Prevent cheating. */
00050     if (strcasestr_local(msg, "endmsg"))
00051     {
00052         new_draw_info(0, COLOR_WHITE, op, "Trying to cheat now are we?");
00053         LOG(llevInfo, "%s tried to write a bogus message using inscription skill.\n", op->name);
00054         return 0;
00055     }
00056 
00057     /* Check if we can fit the message into the book. */
00058     if (book_overflow(marked->msg, msg, sizeof(buf)))
00059     {
00060         new_draw_info_format(0, COLOR_WHITE, op, "Your message won't fit in the %s.", query_short_name(marked, op));
00061         return 0;
00062     }
00063 
00064     if (marked->msg)
00065     {
00066         snprintf(buf, sizeof(buf), "%s\n%s\n", marked->msg, msg);
00067     }
00068     else
00069     {
00070         snprintf(buf, sizeof(buf), "%s\n", msg);
00071     }
00072 
00073     FREE_AND_COPY_HASH(marked->msg, buf);
00074     new_draw_info_format(0, COLOR_WHITE, op, "You write in the %s.", query_short_name(marked, op));
00075     CONTR(op)->stat_books_inscribed++;
00076 
00077     return strlen(msg);
00078 }
00079 
00085 int skill_inscription(object *op, const char *params)
00086 {
00087     object *skill_item, *marked;
00088 
00089     /* Can't write anything without being able to read... */
00090     if (!find_skill(op, SK_LITERACY))
00091     {
00092         new_draw_info(0, COLOR_WHITE, op, "You must learn to read before you can write!");
00093         return 0;
00094     }
00095 
00096     skill_item = CONTR(op)->equipment[PLAYER_EQUIP_SKILL_ITEM];
00097 
00098     if (!skill_item)
00099     {
00100         new_draw_info(0, COLOR_WHITE, op, "You need to apply a writing pen to use this skill.");
00101         return 0;
00102     }
00103 
00104     if (skill_item->stats.sp != SK_INSCRIPTION)
00105     {
00106         new_draw_info_format(0, COLOR_WHITE, op, "The %s cannot be used with this skill.", query_short_name(skill_item, NULL));
00107         return 0;
00108     }
00109 
00110     if (QUERY_FLAG(op, FLAG_BLIND) && !QUERY_FLAG(op, FLAG_WIZ))
00111     {
00112         new_draw_info(0, COLOR_WHITE, op, "You are unable to write while blind.");
00113         return 0;
00114     }
00115 
00116     marked = find_marked_object(op);
00117 
00118     if (!marked)
00119     {
00120         new_draw_info(0, COLOR_WHITE, op, "You don't have any marked item to write on.");
00121         return 0;
00122     }
00123 
00124     if (marked->type == BOOK)
00125     {
00126         return inscribe_book(op, params, marked);
00127     }
00128 
00129     new_draw_info_format(0, COLOR_WHITE, op, "You can't write on the %s.", query_short_name(marked, NULL));
00130     return 0;
00131 }