2 7ea8226e 2021-09-06 xhr * Copyright (c) 2021 Matthias Schmidt <xhr@giessen.ccc.de>
4 7ea8226e 2021-09-06 xhr * Permission to use, copy, modify, and distribute this software for any
5 7ea8226e 2021-09-06 xhr * purpose with or without fee is hereby granted, provided that the above
6 7ea8226e 2021-09-06 xhr * copyright notice and this permission notice appear in all copies.
8 7ea8226e 2021-09-06 xhr * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7ea8226e 2021-09-06 xhr * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7ea8226e 2021-09-06 xhr * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7ea8226e 2021-09-06 xhr * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7ea8226e 2021-09-06 xhr * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7ea8226e 2021-09-06 xhr * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7ea8226e 2021-09-06 xhr * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ffb14e6a 2021-09-02 xhr #include <errno.h>
18 ffb14e6a 2021-09-02 xhr #include <limits.h>
19 63354cc5 2021-09-01 xhr #include <stdio.h>
20 63354cc5 2021-09-01 xhr #include <stdlib.h>
21 63354cc5 2021-09-01 xhr #include <string.h>
22 ffb14e6a 2021-09-02 xhr #include <stdlib.h>
24 63354cc5 2021-09-01 xhr #include "isscrolls.h"
26 d548c131 2021-09-02 xhr #define MAXTOKENS 3
28 1e9e9b0b 2021-09-01 xhr static const char *odds[] = {
29 1e9e9b0b 2021-09-01 xhr "Almost certain",
33 1e9e9b0b 2021-09-01 xhr "Small chance",
38 f267c8e7 2021-09-08 xhr cmd_gather_information(char *cmd)
40 f267c8e7 2021-09-08 xhr struct character *curchar = get_current_character();
41 f267c8e7 2021-09-08 xhr int ival[2] = { -1, -1 };
44 f267c8e7 2021-09-08 xhr if (curchar == NULL) {
45 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
49 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
50 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
52 f267c8e7 2021-09-08 xhr ret = action_roll(ival);
53 f267c8e7 2021-09-08 xhr if (ret == 8) { /* strong hit */
54 f267c8e7 2021-09-08 xhr change_char_value("momentum", INCREASE, 2);
55 f267c8e7 2021-09-08 xhr } else if (ret == 4) { /* weak hit */
56 f267c8e7 2021-09-08 xhr change_char_value("momentum", INCREASE, 1);
58 704a3bbf 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
62 80379fca 2021-09-09 xhr cmd_sojourn(char *cmd)
64 704a3bbf 2021-09-09 xhr struct character *curchar = get_current_character();
65 704a3bbf 2021-09-09 xhr int ival[2] = { -1, -1 };
68 704a3bbf 2021-09-09 xhr if (curchar == NULL) {
69 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
73 704a3bbf 2021-09-09 xhr ival[0] = curchar->heart;
74 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
76 704a3bbf 2021-09-09 xhr ret = action_roll(ival);
77 704a3bbf 2021-09-09 xhr if (ret == 8) { /* strong hit */
78 3501467d 2021-09-09 xhr printf("You may choose two optionsresults -> Rulebook\n");
79 704a3bbf 2021-09-09 xhr } else if (ret == 4) { /* weak hit */
80 704a3bbf 2021-09-09 xhr printf("You may choose one result -> Rulebook\n");
82 2231141b 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
86 9c58a078 2021-09-09 xhr cmd_draw_the_circle(char *cmd)
88 9c58a078 2021-09-09 xhr struct character *curchar = get_current_character();
89 9c58a078 2021-09-09 xhr int ival[2] = { -1, -1 };
92 9c58a078 2021-09-09 xhr if (curchar == NULL) {
93 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
97 9c58a078 2021-09-09 xhr ival[0] = curchar->heart;
98 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
100 9c58a078 2021-09-09 xhr ret = action_roll(ival);
101 9c58a078 2021-09-09 xhr if (ret == 8) {
102 9c58a078 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
103 9c58a078 2021-09-09 xhr printf("You may choose even more boasts -> Rulebook\n");
104 9c58a078 2021-09-09 xhr } else if (ret == 4) {
105 9c58a078 2021-09-09 xhr printf("You may choose one boasts -> Rulebook\n");
107 9c58a078 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
111 8cc30b28 2021-09-09 xhr cmd_swear_an_iron_vow(char *cmd)
113 8cc30b28 2021-09-09 xhr struct character *curchar = get_current_character();
114 8cc30b28 2021-09-09 xhr int ival[2] = { -1, -1 };
117 8cc30b28 2021-09-09 xhr if (curchar == NULL) {
118 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
122 8cc30b28 2021-09-09 xhr ival[0] = curchar->heart;
123 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
125 8cc30b28 2021-09-09 xhr ret = action_roll(ival);
126 8cc30b28 2021-09-09 xhr if (ret == 8) {
127 8cc30b28 2021-09-09 xhr change_char_value("momentum", INCREASE, 2);
128 8cc30b28 2021-09-09 xhr printf("You are emboldened and know what you must do next\n");
129 8cc30b28 2021-09-09 xhr } else if (ret == 4) {
130 8cc30b28 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
131 8cc30b28 2021-09-09 xhr printf("You are determined but begin your quest with questions\n");
133 8cc30b28 2021-09-09 xhr printf("You face a significant obstacle -> Rulebook\n");
137 319d4050 2021-09-16 xhr cmd_forge_a_bond(char *cmd)
139 86c8a615 2021-09-09 xhr struct character *curchar = get_current_character();
140 86c8a615 2021-09-09 xhr int ival[2] = { -1, -1 };
143 86c8a615 2021-09-09 xhr if (curchar == NULL) {
144 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
148 86c8a615 2021-09-09 xhr ival[0] = curchar->heart;
149 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
151 86c8a615 2021-09-09 xhr ret = action_roll(ival);
152 86c8a615 2021-09-09 xhr if (ret == 8) {
153 be9e9b67 2021-09-13 xhr printf("You forge a bind and choose one option -> Rulebook\n");
154 be9e9b67 2021-09-13 xhr curchar->bonds += 0.25;
155 86c8a615 2021-09-09 xhr } else if (ret == 4) {
156 86c8a615 2021-09-09 xhr printf("They ask something from you first -> Rulebook\n");
158 be9e9b67 2021-09-13 xhr printf("You are refused. Pay the price -> Rulebook\n");
162 319d4050 2021-09-16 xhr cmd_test_your_bond(char *cmd)
164 34ed03e1 2021-09-09 xhr struct character *curchar = get_current_character();
165 34ed03e1 2021-09-09 xhr int ival[2] = { -1, -1 };
168 34ed03e1 2021-09-09 xhr if (curchar == NULL) {
169 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
173 cc1c1bd6 2021-09-13 xhr if (curchar->bonds == 0) {
174 cc1c1bd6 2021-09-13 xhr printf("You have no bonds forged. Please do so first\n");
178 34ed03e1 2021-09-09 xhr ival[0] = curchar->heart;
179 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
181 34ed03e1 2021-09-09 xhr ret = action_roll(ival);
182 34ed03e1 2021-09-09 xhr if (ret == 8) {
183 34ed03e1 2021-09-09 xhr printf("You may choose one boost -> Rulebook\n");
184 34ed03e1 2021-09-09 xhr } else if (ret == 4) {
185 34ed03e1 2021-09-09 xhr printf("Your bond is fragile -> Rulebook\n");
187 cc1c1bd6 2021-09-13 xhr printf("Your bond is cleared. Pay the price -> Rulebook\n");
188 cc1c1bd6 2021-09-13 xhr curchar->bonds -= 0.25;
193 80a35657 2021-09-13 xhr cmd_endure_stress(char *cmd)
195 80a35657 2021-09-13 xhr struct character *curchar = get_current_character();
196 80a35657 2021-09-13 xhr int ival[2] = { -1, -1 };
197 80a35657 2021-09-13 xhr int ret, hr;
199 80a35657 2021-09-13 xhr if (curchar == NULL) {
200 80a35657 2021-09-13 xhr printf("No character loaded. Use 'cd' to load a character\n");
204 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
205 319d4050 2021-09-16 xhr if (ival[1] == -1) {
206 80a35657 2021-09-13 xhr printf("Please provide a number as argument\n\n");
207 80a35657 2021-09-13 xhr printf("The number is the amount of stress you suffer\n");
208 80a35657 2021-09-13 xhr printf("Example: endurestress 2\n");
212 80a35657 2021-09-13 xhr hr = curchar->spirit - ival[1];
213 80a35657 2021-09-13 xhr if (hr >= 0) {
214 80a35657 2021-09-13 xhr curchar->spirit -= ival[1];
215 80a35657 2021-09-13 xhr printf("You suffer -%d spirit and it is down to %d\n",
216 80a35657 2021-09-13 xhr ival[1], curchar->spirit);
217 80a35657 2021-09-13 xhr } else if (hr < 0) {
218 80a35657 2021-09-13 xhr /* Spirit is 0, so suffer -momentum equal to remaining health */
219 80a35657 2021-09-13 xhr log_debug("hr < 0: %d\n", hr);
220 80a35657 2021-09-13 xhr curchar->spirit = 0;
221 80a35657 2021-09-13 xhr curchar->momentum -= (hr * (-1));
222 80a35657 2021-09-13 xhr printf("You suffer -%d spirt and since your spirit is 0, your "\
223 80a35657 2021-09-13 xhr "momentum is down to %d\n", ival[1], curchar->momentum);
226 80a35657 2021-09-13 xhr /* Reset ival[1] since we need no bonus for the roll */
227 80a35657 2021-09-13 xhr ival[1] = -1;
228 80a35657 2021-09-13 xhr ival[0] = curchar->heart;
229 80a35657 2021-09-13 xhr if (curchar->spirit > curchar->heart) {
230 80a35657 2021-09-13 xhr ival[0] = curchar->spirit;
233 80a35657 2021-09-13 xhr ret = action_roll(ival);
234 80a35657 2021-09-13 xhr if (ret == 8) {
235 80a35657 2021-09-13 xhr printf("You need to choose one option -> Rulebook\n");
236 80a35657 2021-09-13 xhr } else if (ret == 4) {
237 80a35657 2021-09-13 xhr printf("You press on\n");
239 80a35657 2021-09-13 xhr change_char_value("momentum", DECREASE, 1);
240 80a35657 2021-09-13 xhr if (curchar->health == 0)
241 80a35657 2021-09-13 xhr printf("Mark either shaken or corrupted or roll on the oracle table -> Rulebook\n");
246 319d4050 2021-09-16 xhr cmd_face_death(char *cmd)
248 d2b9d86f 2021-09-13 xhr struct character *curchar = get_current_character();
249 d2b9d86f 2021-09-13 xhr int ival[2] = { -1, -1 };
252 d2b9d86f 2021-09-13 xhr if (curchar == NULL) {
253 d2b9d86f 2021-09-13 xhr printf("No character loaded. Use 'cd' to load a character\n");
257 d2b9d86f 2021-09-13 xhr ival[0] = curchar->heart;
258 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
260 d2b9d86f 2021-09-13 xhr ret = action_roll(ival);
261 d2b9d86f 2021-09-13 xhr if (ret == 8) {
262 d2b9d86f 2021-09-13 xhr printf("Death rejects you.\n");
263 d2b9d86f 2021-09-13 xhr } else if (ret == 4) {
264 d2b9d86f 2021-09-13 xhr printf("Your must choose one option -> Rulebook\n");
266 d2b9d86f 2021-09-13 xhr printf("You are dead\n");
267 d2b9d86f 2021-09-13 xhr curchar->dead = 1;
272 f267c8e7 2021-09-08 xhr cmd_heal(char *who)
274 f267c8e7 2021-09-08 xhr struct character *curchar = get_current_character();
275 f267c8e7 2021-09-08 xhr int ival[2] = { -1, -1 };
278 f267c8e7 2021-09-08 xhr if (curchar == NULL) {
279 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
283 f267c8e7 2021-09-08 xhr if (strlen(who) == 0) {
285 f267c8e7 2021-09-08 xhr printf("Please specify who to heal\n\n");
286 f267c8e7 2021-09-08 xhr printf("me\t- heal yourself (roll against Iron or Wits (whatever is lower))\n");
287 f267c8e7 2021-09-08 xhr printf("others\t- heal others (roll against Wits)\n\n");
288 f267c8e7 2021-09-08 xhr printf("Example: heal me\n");
292 a14b5708 2021-09-16 xhr if (strcasecmp(who, "me") == 0) {
293 f267c8e7 2021-09-08 xhr if (curchar->iron < curchar->wits)
294 f267c8e7 2021-09-08 xhr ival[0] = curchar->iron;
295 f267c8e7 2021-09-08 xhr else if (curchar->iron > curchar->wits)
296 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
298 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
299 a14b5708 2021-09-16 xhr } else if (strcasecmp(who, "others") == 0) {
300 f267c8e7 2021-09-08 xhr ival[0] = curchar->wits;
304 f267c8e7 2021-09-08 xhr ret = action_roll(ival);
305 f267c8e7 2021-09-08 xhr if (ret == 8) { /* strong hit */
306 f267c8e7 2021-09-08 xhr change_char_value("health", INCREASE, 2);
307 f267c8e7 2021-09-08 xhr } else if (ret == 4) { /* weak hit */
308 f267c8e7 2021-09-08 xhr change_char_value("health", INCREASE, 1);
309 f267c8e7 2021-09-08 xhr change_char_value("momentum", DECREASE, 1);
311 2231141b 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
315 63354cc5 2021-09-01 xhr cmd_roll_action_dice(char *cmd)
318 d548c131 2021-09-02 xhr char *tokens[MAXTOKENS];
319 d548c131 2021-09-02 xhr char *p, *last;
321 d548c131 2021-09-02 xhr long lval[2];
322 d548c131 2021-09-02 xhr int ival[2] = { -1, -1 };
324 ffb14e6a 2021-09-02 xhr if (cmd == NULL || strlen(cmd) == 0) {
325 d548c131 2021-09-02 xhr printf("Please provide at least one attribute value\n\n");
326 d548c131 2021-09-02 xhr printf("> action <attribute value> [bonus value]\n\n");
327 d548c131 2021-09-02 xhr printf("Examples:\n");
328 8f2dede1 2021-09-02 xhr printf("> action 3\t- Add 3 to the D6 die\n");
329 295637c6 2021-09-09 xhr printf("> action 4 1\t- Add 4 and additionally 1 to the D6 die\n\n");
334 d548c131 2021-09-02 xhr log_debug("cmd: %s\n", cmd);
336 d548c131 2021-09-02 xhr /* Parse the argument line into 2 tokens, separated by space */
337 d548c131 2021-09-02 xhr for ((p = strtok_r(cmd, " ", &last)); p;
338 d548c131 2021-09-02 xhr (p = strtok_r(NULL, " ", &last))) {
339 d548c131 2021-09-02 xhr if (i < MAXTOKENS - 1)
340 d548c131 2021-09-02 xhr tokens[i++] = p;
342 d548c131 2021-09-02 xhr tokens[i] = NULL;
344 d548c131 2021-09-02 xhr for (i=0; tokens[i] != NULL; i++) {
345 d548c131 2021-09-02 xhr log_debug("token %d: %s\n", i, tokens[i]);
348 d548c131 2021-09-02 xhr lval[i] = strtol(tokens[i], &ep, 10);
349 d548c131 2021-09-02 xhr if (cmd[0] == '\0' || *ep != '\0') {
350 d548c131 2021-09-02 xhr printf("Please provide a number as argument\n");
353 d548c131 2021-09-02 xhr if ((errno == ERANGE || lval[i] <= 0 || lval[i] > 10)) {
354 d548c131 2021-09-02 xhr printf("Please provide a number between 1 and 10\n");
357 d548c131 2021-09-02 xhr ival[i] = lval[i];
360 ffb14e6a 2021-09-02 xhr action_roll(ival);
364 319d4050 2021-09-16 xhr cmd_resupply(char *cmd)
366 a5abbb50 2021-09-09 xhr struct character *curchar = get_current_character();
367 a5abbb50 2021-09-09 xhr int ival[2] = { -1, -1 };
370 a5abbb50 2021-09-09 xhr if (curchar == NULL) {
371 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
375 a5abbb50 2021-09-09 xhr ival[0] = curchar->wits;
376 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
378 a5abbb50 2021-09-09 xhr ret = action_roll(ival);
379 a5abbb50 2021-09-09 xhr if (ret == 8) { /* strong hit */
380 a5abbb50 2021-09-09 xhr change_char_value("momentum", INCREASE, 2);
381 a5abbb50 2021-09-09 xhr } else if (ret == 4) { /* weak hit */
382 a5abbb50 2021-09-09 xhr printf("Take up to +2 supply, but suffer -1 momentum for each\n");
384 60bf4095 2021-09-11 xhr printf("Pay the price -> Rulebook\n");
389 319d4050 2021-09-16 xhr cmd_make_camp(char *cmd)
391 7317e41e 2021-09-09 xhr struct character *curchar = get_current_character();
392 7317e41e 2021-09-09 xhr int ival[2] = { -1, -1 };
395 7317e41e 2021-09-09 xhr if (curchar == NULL) {
396 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
400 7317e41e 2021-09-09 xhr ival[0] = curchar->supply;
401 319d4050 2021-09-16 xhr ival[1] = get_int_from_cmd(cmd);
403 7317e41e 2021-09-09 xhr ret = action_roll(ival);
404 7317e41e 2021-09-09 xhr if (ret == 8)
405 3501467d 2021-09-09 xhr printf("Choose two options-> Rulebook\n");
406 7317e41e 2021-09-09 xhr else if (ret == 4)
407 3501467d 2021-09-09 xhr printf("Choose one option-> Rulebook\n");
409 7317e41e 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
413 1c9cf51f 2021-09-09 xhr cmd_face_danger(char *stat)
415 1c9cf51f 2021-09-09 xhr struct character *curchar = get_current_character();
416 1c9cf51f 2021-09-09 xhr int ival[2] = { -1, -1 };
419 1c9cf51f 2021-09-09 xhr if (curchar == NULL) {
420 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
424 1c9cf51f 2021-09-09 xhr if (strlen(stat) == 0) {
426 1c9cf51f 2021-09-09 xhr printf("Please specify the stat you'd like to use in this move\n\n");
427 1c9cf51f 2021-09-09 xhr printf("edge\t- Act with speed, agility, or precision\n");
428 1c9cf51f 2021-09-09 xhr printf("heart\t- Act with charm, loyalty, or courage\n");
429 1c9cf51f 2021-09-09 xhr printf("iron\t- Act with aggressive action, forceful defense, strength\n");
430 1c9cf51f 2021-09-09 xhr printf("shadow\t- Act with deception, stealth, or trickery\n");
431 1c9cf51f 2021-09-09 xhr printf("wits\t- Act with expertise, insight, or observation\n\n");
432 1c9cf51f 2021-09-09 xhr printf("Example: facedanger iron\n");
436 a14b5708 2021-09-16 xhr if (strcasecmp(stat, "iron") == 0) {
437 1c9cf51f 2021-09-09 xhr ival[0] = curchar->iron;
438 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "wits") == 0) {
439 1c9cf51f 2021-09-09 xhr ival[0] = curchar->wits;
440 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "edge") == 0) {
441 1c9cf51f 2021-09-09 xhr ival[0] = curchar->edge;
442 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "shadow") == 0) {
443 1c9cf51f 2021-09-09 xhr ival[0] = curchar->shadow;
444 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "heart") == 0) {
445 1c9cf51f 2021-09-09 xhr ival[0] = curchar->heart;
449 1c9cf51f 2021-09-09 xhr ret = action_roll(ival);
450 1c9cf51f 2021-09-09 xhr if (ret == 8) /* strong hit */
451 1c9cf51f 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
452 1c9cf51f 2021-09-09 xhr else if (ret == 4) /* weak hit */
453 1c9cf51f 2021-09-09 xhr printf("Face a troublesome cost -> Rulebook\n");
455 dab8f6b9 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
459 ad0031e7 2021-09-16 xhr cmd_compel(char *cmd)
461 dab8f6b9 2021-09-09 xhr struct character *curchar = get_current_character();
462 ad0031e7 2021-09-16 xhr char stat[MAX_STAT_LEN];
463 dab8f6b9 2021-09-09 xhr int ival[2] = { -1, -1 };
466 dab8f6b9 2021-09-09 xhr if (curchar == NULL) {
467 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
471 ad0031e7 2021-09-16 xhr ret = get_args_from_cmd(cmd, stat, &ival[1]);
472 219a93cc 2021-09-16 xhr if (ret >= 10) {
474 dab8f6b9 2021-09-09 xhr printf("Please specify the stat you'd like to use in this move\n\n");
475 dab8f6b9 2021-09-09 xhr printf("heart\t- You charm, pacify, barter, or convince\n");
476 dab8f6b9 2021-09-09 xhr printf("iron\t- You threaten or incite\n");
477 dab8f6b9 2021-09-09 xhr printf("shadow\t- You lie or swindle\n");
478 dab8f6b9 2021-09-09 xhr printf("Example: compel iron\n");
480 ad0031e7 2021-09-16 xhr } else if (ret <= -20)
483 a14b5708 2021-09-16 xhr if (strcasecmp(stat, "iron") == 0) {
484 dab8f6b9 2021-09-09 xhr ival[0] = curchar->iron;
485 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "shadow") == 0) {
486 dab8f6b9 2021-09-09 xhr ival[0] = curchar->shadow;
487 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "heart") == 0) {
488 dab8f6b9 2021-09-09 xhr ival[0] = curchar->heart;
492 dab8f6b9 2021-09-09 xhr ret = action_roll(ival);
493 dab8f6b9 2021-09-09 xhr if (ret == 8) {
494 dab8f6b9 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
495 dab8f6b9 2021-09-09 xhr printf("You might get +1 for your next move -> Rulebook\n");
496 dab8f6b9 2021-09-09 xhr } else if (ret == 4) {
497 dab8f6b9 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
498 dab8f6b9 2021-09-09 xhr printf("You might be asked for something in return -> Rulebook\n");
500 1edc302f 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
504 ad0031e7 2021-09-16 xhr cmd_secure_an_advantage(char *cmd)
506 5f0cab5f 2021-09-09 xhr struct character *curchar = get_current_character();
507 ad0031e7 2021-09-16 xhr char stat[MAX_STAT_LEN];
508 5f0cab5f 2021-09-09 xhr int ival[2] = { -1, -1 };
511 5f0cab5f 2021-09-09 xhr if (curchar == NULL) {
512 7c1e70f0 2021-09-09 xhr printf("No character loaded. Use 'cd' to load a character\n");
516 ad0031e7 2021-09-16 xhr ret = get_args_from_cmd(cmd, stat, &ival[1]);
517 219a93cc 2021-09-16 xhr if (ret >= 10) {
519 5f0cab5f 2021-09-09 xhr printf("Please specify the stat you'd like to use in this move\n\n");
520 5f0cab5f 2021-09-09 xhr printf("edge\t- Act with speed, agility, or precision\n");
521 5f0cab5f 2021-09-09 xhr printf("heart\t- Act with charm, loyalty, or courage\n");
522 5f0cab5f 2021-09-09 xhr printf("iron\t- Act with aggressive action, forceful defense, strength\n");
523 5f0cab5f 2021-09-09 xhr printf("shadow\t- Act with deception, stealth, or trickery\n");
524 5f0cab5f 2021-09-09 xhr printf("wits\t- Act with expertise, insight, or observation\n\n");
525 5f0cab5f 2021-09-09 xhr printf("Example: secureanadvantage iron\n");
527 ad0031e7 2021-09-16 xhr } else if (ret <= -20)
530 a14b5708 2021-09-16 xhr if (strcasecmp(stat, "iron") == 0) {
531 5f0cab5f 2021-09-09 xhr ival[0] = curchar->iron;
532 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "wits") == 0) {
533 5f0cab5f 2021-09-09 xhr ival[0] = curchar->wits;
534 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "edge") == 0) {
535 5f0cab5f 2021-09-09 xhr ival[0] = curchar->edge;
536 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "shadow") == 0) {
537 5f0cab5f 2021-09-09 xhr ival[0] = curchar->shadow;
538 a14b5708 2021-09-16 xhr } else if (strcasecmp(stat, "heart") == 0) {
539 5f0cab5f 2021-09-09 xhr ival[0] = curchar->heart;
543 5f0cab5f 2021-09-09 xhr ret = action_roll(ival);
544 5f0cab5f 2021-09-09 xhr if (ret == 8)
545 5f0cab5f 2021-09-09 xhr printf("Gain an advantage -> Rulebook\n");
546 5f0cab5f 2021-09-09 xhr else if (ret == 4)
547 5f0cab5f 2021-09-09 xhr change_char_value("momentum", INCREASE, 1);
549 2231141b 2021-09-09 xhr printf("Pay the price -> Rulebook\n");
553 a844ca20 2021-09-05 xhr cmd_roll_challenge_die(__attribute__((unused)) char *unused)
555 8f2dede1 2021-09-02 xhr printf("%ld\n", roll_challenge_die());
559 a844ca20 2021-09-05 xhr cmd_roll_oracle_die(__attribute__((unused)) char *unused)
561 8f2dede1 2021-09-02 xhr printf("%ld\n", roll_oracle_die());
565 8f2dede1 2021-09-02 xhr roll_action_die()
567 63354cc5 2021-09-01 xhr long ret = random() % 6;
569 63354cc5 2021-09-01 xhr return ret == 0 ? 6 : ret;
573 8f2dede1 2021-09-02 xhr roll_challenge_die()
575 63354cc5 2021-09-01 xhr return random() % 10;
579 8f2dede1 2021-09-02 xhr roll_oracle_die()
581 63354cc5 2021-09-01 xhr return random() % 100;
585 63354cc5 2021-09-01 xhr cmd_yes_or_no(char *args)
587 63354cc5 2021-09-01 xhr int num = atoi(args);
590 1e9e9b0b 2021-09-01 xhr log_debug("Argument %d\n", num);
591 63354cc5 2021-09-01 xhr if (num <= 0 || num > 5) {
592 1e9e9b0b 2021-09-01 xhr printf("Provide a number between 1-5 as argument, i.e. yesorno 2\n\n");
593 1e9e9b0b 2021-09-01 xhr for (i=0; odds[i] != NULL; i++)
594 1e9e9b0b 2021-09-01 xhr printf("%d - %s\n", i+1, odds[i]);
599 63354cc5 2021-09-01 xhr yes_or_no(num);
603 63354cc5 2021-09-01 xhr yes_or_no(int num)
605 63354cc5 2021-09-01 xhr long a1, c1, c2;
607 8f2dede1 2021-09-02 xhr a1 = roll_challenge_die();
608 8f2dede1 2021-09-02 xhr c2 = roll_challenge_die();
609 63354cc5 2021-09-01 xhr c1 = (a1 * 10) + c2;
611 63354cc5 2021-09-01 xhr if (a1 == c2)
612 d12dcdd5 2021-09-05 xhr printf("W10: match %ld -> ", a1);
614 d12dcdd5 2021-09-05 xhr printf("W10: %ld, %ld -> ", a1, c2);
617 63354cc5 2021-09-01 xhr if (num == 1 && c1 >= 11)
618 63354cc5 2021-09-01 xhr printf("yes\n");
619 63354cc5 2021-09-01 xhr else if (num == 2 && c1 >= 26)
620 63354cc5 2021-09-01 xhr printf("yes\n");
621 63354cc5 2021-09-01 xhr else if (num == 3 && c1 >= 51)
622 63354cc5 2021-09-01 xhr printf("yes\n");
623 63354cc5 2021-09-01 xhr else if (num == 4 && c1 >= 76)
624 63354cc5 2021-09-01 xhr printf("yes\n");
625 63354cc5 2021-09-01 xhr else if (num == 5 && c1 >= 91)
626 63354cc5 2021-09-01 xhr printf("yes\n");
628 63354cc5 2021-09-01 xhr printf("no\n");
632 d548c131 2021-09-02 xhr action_roll(int args[2])
634 d548c131 2021-09-02 xhr long c1, c2, a1, b;
635 04d8c7d3 2021-09-08 xhr int ret = 0;
637 d548c131 2021-09-02 xhr log_debug("Action args: %d, %d\n", args[0], args[1]);
639 64d52bc9 2021-09-16 xhr if (args[0] == -1) {
640 d548c131 2021-09-02 xhr log_errx(1, "No attribute value provided. This should not happen!");
643 8f2dede1 2021-09-02 xhr a1 = b = roll_action_die();
644 d548c131 2021-09-02 xhr /* Add attribute and maybe a bonus value */
645 d548c131 2021-09-02 xhr b += args[0];
646 d548c131 2021-09-02 xhr if (args[1] != -1)
647 d548c131 2021-09-02 xhr b += args[1];
649 d548c131 2021-09-02 xhr if (args[1] == -1)
650 d12dcdd5 2021-09-05 xhr printf("D6: %ld+%d=%ld ", a1, args[0], b);
652 d12dcdd5 2021-09-05 xhr printf("D6: %ld+%d+%d=%ld ", a1, args[0], args[1], b);
654 8f2dede1 2021-09-02 xhr c1 = roll_challenge_die();
655 8f2dede1 2021-09-02 xhr c2 = roll_challenge_die();
656 d548c131 2021-09-02 xhr c1 = (c1 == 0 ? 10 : c1);
657 d548c131 2021-09-02 xhr c2 = (c2 == 0 ? 10 : c2);
659 63354cc5 2021-09-01 xhr if (c1 == c2) {
660 d12dcdd5 2021-09-05 xhr printf("D10: %ld match -> ", c1);
662 d12dcdd5 2021-09-05 xhr printf("D10: %ld, %ld -> ", c1, c2);
665 04d8c7d3 2021-09-08 xhr if (b <= c1 && b <= c2) {
666 af92ffb1 2021-09-15 xhr pm(RED, "miss\n");
668 04d8c7d3 2021-09-08 xhr } else if (b <= c1 || b <= c2) {
669 af92ffb1 2021-09-15 xhr pm(YELLOW, "weak hit\n");
671 04d8c7d3 2021-09-08 xhr } else if (b > c1 && b > c2) {
672 af92ffb1 2021-09-15 xhr pm(GREEN, "strong hit\n");
680 319d4050 2021-09-16 xhr progress_roll(double args[2])
683 60bf4095 2021-09-11 xhr long c1, c2;
684 60bf4095 2021-09-11 xhr int ret = 0;
686 319d4050 2021-09-16 xhr if (args[0] == -1) {
687 319d4050 2021-09-16 xhr log_errx(1, "No attribute value provided. This should not happen!");
690 60bf4095 2021-09-11 xhr c1 = roll_challenge_die();
691 60bf4095 2021-09-11 xhr c2 = roll_challenge_die();
692 60bf4095 2021-09-11 xhr c1 = (c1 == 0 ? 10 : c1);
693 60bf4095 2021-09-11 xhr c2 = (c2 == 0 ? 10 : c2);
695 319d4050 2021-09-16 xhr log_debug("args[0] %.2lf args[1] %.2lf\n", args[0], args[1]);
697 319d4050 2021-09-16 xhr b = args[0];
698 319d4050 2021-09-16 xhr if (args[1] != -1)
699 319d4050 2021-09-16 xhr b += args[1];
701 319d4050 2021-09-16 xhr if (c1 == c2) {
702 319d4050 2021-09-16 xhr printf("D10: %ld match vs ", c1);
704 319d4050 2021-09-16 xhr printf("D10: %ld, %ld vs ", c1, c2);
707 319d4050 2021-09-16 xhr printf("Progress: %.2lf -> ", b);
709 60bf4095 2021-09-11 xhr if (b <= c1 && b <= c2) {
710 af92ffb1 2021-09-15 xhr pm(RED, "miss\n");
712 60bf4095 2021-09-11 xhr } else if (b <= c1 || b <= c2) {
713 af92ffb1 2021-09-15 xhr pm(YELLOW, "weak hit\n");
715 60bf4095 2021-09-11 xhr } else if (b > c1 && b > c2) {
716 af92ffb1 2021-09-15 xhr pm(GREEN, "strong hit\n");
724 319d4050 2021-09-16 xhr get_int_from_cmd(const char *cmd)
728 319d4050 2021-09-16 xhr int ival = -1;
730 319d4050 2021-09-16 xhr if (strlen(cmd) > 0) {
732 319d4050 2021-09-16 xhr lval = strtol(cmd, &ep, 10);
733 319d4050 2021-09-16 xhr if (cmd[0] == '\0' || *ep != '\0') {
734 319d4050 2021-09-16 xhr printf("Please provide a number as argument\n");
735 319d4050 2021-09-16 xhr return ival;
737 319d4050 2021-09-16 xhr if ((errno == ERANGE || lval <= 0 || lval > 10)) {
738 319d4050 2021-09-16 xhr printf("Please provide a number between 1 and 10\n");
739 319d4050 2021-09-16 xhr return ival;
742 319d4050 2021-09-16 xhr ival = lval;
743 319d4050 2021-09-16 xhr log_debug("Arg provided %d\n", ival);
746 319d4050 2021-09-16 xhr return ival;
750 c0c6ae4a 2021-09-16 xhr get_args_from_cmd(char *cmd, char *stat, int *ival)
752 c0c6ae4a 2021-09-16 xhr char *tokens[MAXTOKENS];
754 c0c6ae4a 2021-09-16 xhr char *p, *last;
756 c0c6ae4a 2021-09-16 xhr long lval = -1;
758 c0c6ae4a 2021-09-16 xhr /* Parse the argument line into max tokens, separated by space */
759 c0c6ae4a 2021-09-16 xhr for ((p = strtok_r(cmd, " ", &last)); p;
760 c0c6ae4a 2021-09-16 xhr (p = strtok_r(NULL, " ", &last))) {
761 c0c6ae4a 2021-09-16 xhr if (i < MAXTOKENS - 1)
762 c0c6ae4a 2021-09-16 xhr tokens[i++] = p;
764 c0c6ae4a 2021-09-16 xhr tokens[i] = NULL;
766 c0c6ae4a 2021-09-16 xhr /* First token is a stat */
768 c0c6ae4a 2021-09-16 xhr if (tokens[i] == NULL)
770 c0c6ae4a 2021-09-16 xhr else if (strlen(tokens[i]) == 0)
773 c0c6ae4a 2021-09-16 xhr log_debug("stat token: %s\n", tokens[i]);
774 c0c6ae4a 2021-09-16 xhr snprintf(stat, MAX_STAT_LEN, "%s", tokens[i]);
776 c0c6ae4a 2021-09-16 xhr /* Second token is a bonus value*/
779 c0c6ae4a 2021-09-16 xhr /* It's OK to have no bonus, so the token can be NULL and we can return */
780 c0c6ae4a 2021-09-16 xhr if (tokens[i] == NULL)
783 c0c6ae4a 2021-09-16 xhr log_debug("bonus token: %s\n", tokens[i]);
785 c0c6ae4a 2021-09-16 xhr lval = strtol(tokens[i], &ep, 10);
786 c0c6ae4a 2021-09-16 xhr if (cmd[0] == '\0' || *ep != '\0') {
787 c0c6ae4a 2021-09-16 xhr printf("Please provide a number as argument\n");
790 c0c6ae4a 2021-09-16 xhr if ((errno == ERANGE || lval <= 0 || lval > 10)) {
791 c0c6ae4a 2021-09-16 xhr printf("Please provide a number between 1 and 10\n");
794 c0c6ae4a 2021-09-16 xhr *ival = lval;