ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/skills.C
(Generate patch)

Comparing deliantra/server/server/skills.C (file contents):
Revision 1.39 by root, Tue Jul 3 06:07:07 2007 UTC vs.
Revision 1.40 by root, Sun Aug 12 05:59:25 2007 UTC

1120 success += calc_skill_exp (op, tmp, skill); 1120 success += calc_skill_exp (op, tmp, skill);
1121 } 1121 }
1122 } 1122 }
1123 } 1123 }
1124 } 1124 }
1125
1125 return success; 1126 return success;
1126} 1127}
1127
1128 1128
1129/* pray() - when this skill is called from do_skill(), it allows 1129/* pray() - when this skill is called from do_skill(), it allows
1130 * the player to regain lost grace points at a faster rate. -b.t. 1130 * the player to regain lost grace points at a faster rate. -b.t.
1131 * This always returns 0 - return value is used by calling function 1131 * This always returns 0 - return value is used by calling function
1132 * such that if it returns true, player gets exp in that skill. This 1132 * such that if it returns true, player gets exp in that skill. This
1133 * the effect here can be done on demand, we probably don't want to 1133 * the effect here can be done on demand, we probably don't want to
1134 * give infinite exp by returning true in any cases. 1134 * give infinite exp by returning true in any cases.
1135 */ 1135 */
1136
1137int 1136int
1138pray (object *pl, object *skill) 1137pray (object *pl, object *skill)
1139{ 1138{
1140 char buf[MAX_BUF]; 1139 char buf[MAX_BUF];
1141 object *tmp; 1140 object *tmp;
1166 if (pl->stats.grace < pl->stats.maxgrace) 1165 if (pl->stats.grace < pl->stats.maxgrace)
1167 { 1166 {
1168 pl->stats.grace++; 1167 pl->stats.grace++;
1169 pl->last_grace = -1; 1168 pl->last_grace = -1;
1170 } 1169 }
1170
1171 return 0; 1171 return 0;
1172} 1172}
1173 1173
1174/* This skill allows the player to regain a few sp or hp for a 1174/* This skill allows the player to regain a few sp or hp for a
1175 * brief period of concentration. No armour or weapons may be 1175 * brief period of concentration. No armour or weapons may be
1176 * wielded/applied for this to work. The amount of time needed 1176 * wielded/applied for this to work. The amount of time needed
1177 * to concentrate and the # of points regained is dependant on 1177 * to concentrate and the # of points regained is dependant on
1178 * the level of the user. - b.t. thomas@astro.psu.edu 1178 * the level of the user. - b.t. thomas@astro.psu.edu
1179 */ 1179 */
1180
1181void 1180void
1182meditate (object *pl, object *skill) 1181meditate (object *pl, object *skill)
1183{ 1182{
1184 object *tmp; 1183 object *tmp;
1185 1184
1228 pl->last_heal = -1; 1227 pl->last_heal = -1;
1229 } 1228 }
1230} 1229}
1231 1230
1232/* write_note() - this routine allows players to inscribe messages in 1231/* write_note() - this routine allows players to inscribe messages in
1233 * ordinary 'books' (anything that is type BOOK). b.t. 1232 * ordinary inscribable 'books' (anything that is not a SPELL). b.t.
1234 */ 1233 */
1235static int 1234static int
1236write_note (object *pl, object *item, const char *msg, object *skill) 1235write_note (object *pl, object *item, const char *msg, object *skill)
1237{ 1236{
1237
1238 if (strstr (msg, "\nendmsg"))
1239 {
1240 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?");
1241 return 0;
1242 }
1243
1244 int len = strlen (msg);
1245
1246 if (!is_utf8_string ((U8 *)msg, len))
1247 {
1248 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message is garbled (text must be UTF-8, client-bug)!");
1249 return 0;
1250 }
1251
1252 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1253 return RESULT_INT (0);
1254
1238 char buf[1024]; 1255 char buf[1024];
1239 object *newBook = NULL;
1240 1256
1241 /* a pair of sanity checks */ 1257 if (len < sizeof (buf) - 2)
1242 if (!item || item->type != BOOK)
1243 return 0;
1244
1245 if (!msg)
1246 {
1247 new_draw_info (NDI_UNIQUE, 0, pl, "No message to write!");
1248 new_draw_info_format (NDI_UNIQUE, 0, pl, "Usage: use_skill %s <message>", &skill->skill);
1249 return 0;
1250 } 1258 {
1259 snprintf (buf, sizeof (buf), "%s\n", msg);
1251 1260
1252 if (strcasestr_local (msg, "endmsg")) 1261 object *newbook = arch_to_object (item->other_arch);
1253 {
1254 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?");
1255 return 0;
1256 }
1257
1258 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1259 return strlen (msg);
1260
1261 buf[0] = 0;
1262 if (!book_overflow (item->msg, msg, sizeof (buf)))
1263 { /* add msg string to book */
1264 if (item->msg)
1265 strcpy (buf, item->msg);
1266
1267 strcat (buf, msg);
1268 strcat (buf, "\n"); /* new msg needs a LF */
1269 if (item->nrof > 1)
1270 {
1271 newBook = item->clone ();
1272 decrease_ob (item); 1262 decrease_ob (item);
1273 esrv_send_item (pl, item); 1263 esrv_send_item (pl, item);
1274 newBook->nrof = 1; 1264 newbook->nrof = 1;
1275 newBook->msg = buf; 1265 newbook->msg = buf;
1266 newbook->flag [FLAG_IDENTIFIED] = true;
1267
1268 if (item->subtype == 1) // mailscrolls
1269 {
1270 newbook->name = item->name;
1271 newbook->name_pl = item->name_pl;
1272 }
1273
1276 newBook = insert_ob_in_ob (newBook, pl); 1274 newbook = insert_ob_in_ob (newbook, pl);
1277 esrv_send_item (pl, newBook); 1275 esrv_send_item (pl, newbook);
1278 }
1279 else
1280 {
1281 item->msg = buf;
1282 /* This shouldn't be necessary - the object hasn't changed in any
1283 * visible way
1284 */
1285 /* esrv_send_item(pl, item); */
1286 }
1287 1276
1277 pl->contr->play_sound (sound_find ("inscribe_success"));
1288 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", query_short_name (item)); 1278 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", &item->name);
1289 return strlen (msg); 1279 return strlen (msg);
1290 } 1280 }
1291 else 1281 else
1292 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", query_short_name (item)); 1282 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", &item->name);
1293 1283
1294 return 0; 1284 return 0;
1295} 1285}
1296 1286
1297/* write_scroll() - this routine allows players to inscribe spell scrolls 1287/* write_scroll() - this routine allows players to inscribe spell scrolls
1298 * of spells which they know. Backfire effects are possible with the 1288 * of spells which they know. Backfire effects are possible with the
1299 * severity of the backlash correlated with the difficulty of the scroll 1289 * severity of the backlash correlated with the difficulty of the scroll
1300 * that is attempted. -b.t. thomas@astro.psu.edu 1290 * that is attempted. -b.t. thomas@astro.psu.edu
1301 */ 1291 */
1302
1303static int 1292static int
1304write_scroll (object *pl, object *scroll, object *skill) 1293write_scroll (object *pl, object *scroll, object *skill)
1305{ 1294{
1306 int success = 0, confused = 0; 1295 int success = 0, confused = 0;
1307 object *newscroll, *chosen_spell, *tmp;
1308
1309 /* this is a sanity check */
1310 if (scroll->type != SCROLL)
1311 {
1312 new_draw_info (NDI_UNIQUE, 0, pl, "A spell can only be inscribed into a scroll!");
1313 return 0;
1314 }
1315 1296
1316 /* Check if we are ready to attempt inscription */ 1297 /* Check if we are ready to attempt inscription */
1317 chosen_spell = pl->contr->ranged_ob; 1298 object *chosen_spell = pl->contr->ranged_ob;
1299
1318 if (!chosen_spell || chosen_spell->type != SPELL) 1300 if (!chosen_spell || chosen_spell->type != SPELL)
1319 { 1301 {
1320 new_draw_info (NDI_UNIQUE, 0, pl, "You need a spell readied in order to inscribe!"); 1302 new_draw_info (NDI_UNIQUE, 0, pl, "You need a spell readied in order to inscribe!");
1321 return 0; 1303 return 0;
1322 } 1304 }
1328 } 1310 }
1329 1311
1330 if (SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA) > pl->stats.sp) 1312 if (SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA) > pl->stats.sp)
1331 { 1313 {
1332 new_draw_info_format (NDI_UNIQUE, 0, pl, "You don't have enough mana to write a scroll of %s.", &chosen_spell->name); 1314 new_draw_info_format (NDI_UNIQUE, 0, pl, "You don't have enough mana to write a scroll of %s.", &chosen_spell->name);
1333 return 0;
1334 }
1335
1336 /* if there is a spell already on the scroll then player could easily
1337 * accidently read it while trying to write the new one. give player
1338 * a 50% chance to overwrite spell at their own level
1339 */
1340 if ((scroll->stats.sp || scroll->inv) && random_roll (0, scroll->level * 2, pl, PREFER_LOW) > skill->level)
1341 {
1342 new_draw_info_format (NDI_UNIQUE, 0, pl, "Oops! You accidently read it while trying to write on it.");
1343 manual_apply (pl, scroll, 0);
1344 return 0; 1315 return 0;
1345 } 1316 }
1346 1317
1347 /* ok, we are ready to try inscription */ 1318 /* ok, we are ready to try inscription */
1348 if (QUERY_FLAG (pl, FLAG_CONFUSED)) 1319 if (QUERY_FLAG (pl, FLAG_CONFUSED))
1352 pl->stats.grace -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_GRACE); 1323 pl->stats.grace -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_GRACE);
1353 pl->stats.sp -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA); 1324 pl->stats.sp -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA);
1354 1325
1355 if (random_roll (0, chosen_spell->level * 4 - 1, pl, PREFER_LOW) < skill->level) 1326 if (random_roll (0, chosen_spell->level * 4 - 1, pl, PREFER_LOW) < skill->level)
1356 { 1327 {
1357 if (scroll->nrof > 1) 1328 object *newscroll = arch_to_object (scroll->other_arch);
1358 {
1359 newscroll = scroll->clone ();
1360 decrease_ob (scroll); 1329 decrease_ob (scroll);
1361 newscroll->nrof = 1; 1330 newscroll->nrof = 1;
1362 } 1331
1363 else 1332 pl->contr->play_sound (sound_find ("inscribe_success"));
1364 newscroll = scroll;
1365 1333
1366 if (!confused) 1334 if (!confused)
1367 { 1335 {
1368 newscroll->level = MAX (skill->level, chosen_spell->level); 1336 newscroll->level = MAX (skill->level, chosen_spell->level);
1337 newscroll->flag [FLAG_IDENTIFIED] = true;
1369 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing a new scroll."); 1338 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing the spell.");
1370 } 1339 }
1371 else 1340 else
1372 { 1341 {
1373 chosen_spell = find_random_spell_in_ob (pl, NULL); 1342 chosen_spell = find_random_spell_in_ob (pl, NULL);
1374 if (!chosen_spell) 1343 if (!chosen_spell)
1376 1345
1377 newscroll->level = MAX (skill->level, chosen_spell->level); 1346 newscroll->level = MAX (skill->level, chosen_spell->level);
1378 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell."); 1347 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell.");
1379 } 1348 }
1380 1349
1381 if (newscroll->inv)
1382 newscroll->inv->destroy ();
1383
1384 tmp = chosen_spell->clone (); 1350 object *tmp = chosen_spell->clone ();
1385 insert_ob_in_ob (tmp, newscroll); 1351 insert_ob_in_ob (tmp, newscroll);
1386 1352
1387 /* Same code as from treasure.c - so they can better merge. 1353 /* Same code as from treasure.C - so they can better merge.
1388 * if players want to sell them, so be it. 1354 * if players want to sell them, so be it.
1389 */ 1355 */
1390 newscroll->value = newscroll->arch->value * newscroll->inv->value * (newscroll->level + 50) / (newscroll->inv->level + 50); 1356 newscroll->value = newscroll->arch->value * newscroll->inv->value * (newscroll->level + 50) / (newscroll->inv->level + 50);
1391 newscroll->stats.exp = newscroll->value / 5; 1357 newscroll->stats.exp = newscroll->value / 5;
1392 1358
1393 /* wait until finished manipulating the scroll before inserting it */
1394 if (newscroll == scroll)
1395 {
1396 /* Remove to correctly merge with other items which may exist in inventory */
1397 newscroll->remove ();
1398 esrv_del_item (pl->contr, newscroll->count);
1399 }
1400
1401 newscroll = insert_ob_in_ob (newscroll, pl); 1359 newscroll = insert_ob_in_ob (newscroll, pl);
1402 esrv_send_item (pl, newscroll); 1360 esrv_send_item (pl, newscroll);
1361
1403 success = calc_skill_exp (pl, newscroll, skill); 1362 success = calc_skill_exp (pl, newscroll, skill);
1404 if (!confused) 1363 if (!confused)
1405 success *= 2; 1364 success *= 2;
1365
1406 success = success * skill->level; 1366 success = success * skill->level;
1407 return success; 1367 return success;
1408
1409 } 1368 }
1410 else 1369 else
1411 { /* Inscription has failed */ 1370 { /* Inscription has failed */
1371 pl->contr->play_sound (sound_find ("inscribe_fail"));
1412 1372
1413 if (chosen_spell->level > skill->level || confused) 1373 if (chosen_spell->level > skill->level || confused)
1414 { /*backfire! */ 1374 { /*backfire! */
1415 new_draw_info (NDI_UNIQUE, 0, pl, "Ouch! Your attempt to write a new scroll strains your mind!"); 1375 new_draw_info (NDI_UNIQUE, 0, pl, "Ouch! Your attempt to write a new scroll strains your mind!");
1376
1416 if (random_roll (0, 1, pl, PREFER_LOW) == 1) 1377 if (random_roll (0, 1, pl, PREFER_LOW) == 1)
1417 pl->drain_specific_stat (4); 1378 pl->drain_specific_stat (4);
1418 else 1379 else
1419 { 1380 {
1420 confuse_player (pl, pl, 99); 1381 confuse_player (pl, pl, 99);
1421 return (-30 * chosen_spell->level); 1382 return -30 * chosen_spell->level;
1422 } 1383 }
1423 } 1384 }
1424 else if (random_roll (0, pl->stats.Int - 1, pl, PREFER_HIGH) < 15) 1385 else if (random_roll (0, pl->stats.Int - 1, pl, PREFER_HIGH) < 15)
1425 { 1386 {
1426 new_draw_info (NDI_UNIQUE, 0, pl, "Your attempt to write a new scroll rattles your mind!"); 1387 new_draw_info (NDI_UNIQUE, 0, pl, "Your attempt to write a new scroll rattles your mind! H<Frankly spoken, you were too dumb and unlucky.>");
1427 confuse_player (pl, pl, 99); 1388 confuse_player (pl, pl, 99);
1428 } 1389 }
1429 else 1390 else
1430 new_draw_info (NDI_UNIQUE, 0, pl, "You fail to write a new scroll."); 1391 new_draw_info (NDI_UNIQUE, 0, pl, "You fail to write a new scroll. H<Try a lower-level spell, if possible at all.>");
1431 } 1392 }
1432 1393
1433 return 0; 1394 return 0;
1434} 1395}
1435 1396
1436/* write_on_item() - wrapper for write_note and write_scroll */ 1397/* write_on_item() - wrapper for write_note and write_scroll */
1437int 1398int
1438write_on_item (object *pl, const char *params, object *skill) 1399write_on_item (object *pl, const char *params, object *skill)
1439{ 1400{
1440 object *item;
1441 const char *string = params;
1442 int msgtype;
1443 archetype *skat; 1401 archetype *skat;
1444 1402
1445 if (pl->type != PLAYER) 1403 if (pl->type != PLAYER)
1446 return 0; 1404 return 0;
1447 1405
1448 if (!params) 1406 if (!params)
1449 {
1450 params = ""; 1407 params = "";
1451 string = params;
1452 }
1453 1408
1454 skat = get_archetype_by_type_subtype (SKILL, SK_LITERACY); 1409 skat = get_archetype_by_type_subtype (SKILL, SK_LITERACY);
1455 1410
1456 /* Need to be able to read before we can write! */ 1411 /* Need to be able to read before we can write! */
1457 if (!find_skill_by_name (pl, skat->skill)) 1412 if (!find_skill_by_name (pl, skat->skill))
1458 { 1413 {
1459 new_draw_info (NDI_UNIQUE, 0, pl, "You must learn to read before you can write!"); 1414 new_draw_info (NDI_UNIQUE, 0, pl, "You must learn to read before you can write! H<You lack the literacy skill.>");
1460 return 0; 1415 return 0;
1461 } 1416 }
1462 1417
1463 /* if there is a message then it goes in a book and no message means 1418 object *item = find_marked_object (pl);
1464 * write active spell into the scroll
1465 */
1466 msgtype = (string[0] != '\0') ? BOOK : SCROLL;
1467 1419
1468 /* find an item of correct type to write on */ 1420 /* find an item of correct type to write on */
1469 if (!(item = find_marked_object (pl))) 1421 if (!item)
1422 {
1423 new_draw_info (NDI_UNIQUE, 0, pl, "You don't have any marked item to write on. H<Use the mark command or the popup menu to makr an item.>");
1424 return 0;
1470 { 1425 }
1471 new_draw_info (NDI_UNIQUE, 0, pl, "You don't have any marked item to write on."); 1426
1427 if (item->type != INSCRIBABLE)
1428 {
1429 new_draw_info_format (NDI_UNIQUE, 0, pl, "You cannot inscribe this! H<You can only inscribe empty scrolls and books.>");
1472 return 0; 1430 return 0;
1473 } 1431 }
1474 1432
1475 if (QUERY_FLAG (item, FLAG_UNPAID)) 1433 if (QUERY_FLAG (item, FLAG_UNPAID))
1476 { 1434 {
1477 new_draw_info (NDI_UNIQUE, 0, pl, "You had better pay for that before you write on it."); 1435 new_draw_info (NDI_UNIQUE, 0, pl, "You had better pay for that before you write on it.");
1478 return 0; 1436 return 0;
1479 } 1437 }
1480 if (msgtype != item->type) 1438
1439 if (item->other_arch->type == SCROLL)
1481 { 1440 {
1482 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no %s to write on", msgtype == BOOK ? "book" : "scroll"); 1441 if (*params)
1442 {
1443 // check readied scroll
1444 new_draw_info_format (NDI_UNIQUE, 0, pl,
1445 "When inscribing spells you need to ready a spell and do not specify a string argument.\n"
1446 "Usage: cast [spell name]; use_skill %s", &skill->skill);
1483 return 0; 1447 return 0;
1484 } 1448 }
1485 1449
1486 if (msgtype == SCROLL)
1487 return write_scroll (pl, item, skill); 1450 return write_scroll (pl, item, skill);
1488 else if (msgtype == BOOK) 1451 }
1452 else
1453 {
1454 if (!*params)
1455 {
1456 new_draw_info_format (NDI_UNIQUE, 0, pl,
1457 "When inscribing books you need to specify the words you want to inscribe as command argument.\n"
1458 "Usage: use_skill %s <message>", &skill->skill);
1459 return 0;
1460 }
1461
1489 return write_note (pl, item, string, skill); 1462 return write_note (pl, item, params, skill);
1463 }
1490 1464
1491 return 0; 1465 return 0;
1492} 1466}
1493 1467
1494/* find_throw_ob() - if we request an object, then 1468/* find_throw_ob() - if we request an object, then

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines