示例#1
0
const char *nhnet_root_plselection_prompt(char *buf, int buflen, int rolenum,
        int racenum, int gendnum, int alignnum)
{
    json_t *jmsg;
    char *str, *ret;

    if (!nhnet_active())
        return nh_root_plselection_prompt(buf, buflen, rolenum,
                                          racenum, gendnum, alignnum);

    if (!api_entry())
        return NULL;

    jmsg = json_pack("{si,si,si,si}", "role", rolenum, "race", racenum,
                     "gend", gendnum, "align", alignnum);
    jmsg = send_receive_msg("get_root_pl_prompt", jmsg);
    if (json_unpack(jmsg, "{ss!}", "prompt", &str) == -1) {
        print_error("Incorrect return object in nhnet_root_plselection_prompt");
        ret = NULL;
    } else {
        strncpy(buf, str, buflen-1);
        buf[buflen-1] = '\0';
        ret = buf;
    }
    json_decref(jmsg);

    api_exit();
    return ret;
}
示例#2
0
char *nh_build_plselection_prompt(char *buf, int buflen, int rolenum, int racenum,
			       int gendnum, int alignnum)
{
	const char *defprompt = "需要我帮你选一个角色吗?";
	int num_post_attribs = 0;
	char tmpbuf[BUFSZ];
	
	if (buflen < QBUFSZ)
		return (char *)defprompt;

	strcpy(tmpbuf, "需要我选择");
	if (racenum != ROLE_NONE || validrole(rolenum))
		strcat(tmpbuf, "你的");
	else {
		strcat(tmpbuf, "一个");
	}
	/* <your> */

	nh_root_plselection_prompt(eos(tmpbuf), buflen - strlen(tmpbuf),
					rolenum, racenum, gendnum, alignnum);
	sprintf(buf, "%s", s_suffix(tmpbuf));

	/* buf should now be:
	 * < your lawful female gnomish cavewoman's> || <your lawful female gnome's>
	 *    || <your lawful female character's>
	 *
         * Now append the post attributes to it
	 */

	num_post_attribs = post_attribs;
	if (post_attribs) {
		if (pa[BP_RACE]) {
			promptsep(eos(buf), num_post_attribs);
			strcat(buf, "种族");
		}
		if (pa[BP_ROLE]) {
			promptsep(eos(buf), num_post_attribs);
			strcat(buf, "角色");
		}
		if (pa[BP_GEND]) {
			promptsep(eos(buf), num_post_attribs);
			strcat(buf, "性别");
		}
		if (pa[BP_ALIGN]) {
			promptsep(eos(buf), num_post_attribs);
			strcat(buf, "阵营");
		}
	}
	strcat(buf, "吗?");
	return buf;
}
示例#3
0
static void
ccmd_get_root_pl_prompt(json_t * params)
{
    int rolenum, racenum, gendnum, alignnum;
    char buf[1024];
    const char *bp;

    if (json_unpack
        (params, "{si,si,si,si*}", "role", &rolenum, "race", &racenum, "gend",
         &gendnum, "align", &alignnum) == -1)
        exit_client("Bad parameters for get_root_pl_prompt");

    bp = nh_root_plselection_prompt(buf, 1024, rolenum, racenum, gendnum,
                                    alignnum);
    client_msg("get_root_pl_prompt", json_pack("{ss}", "prompt", bp));
}
示例#4
0
nh_bool player_selection(int *out_role, int *out_race, int *out_gend,
			 int *out_align, int randomall, nh_bool tutorial)
{
    struct nh_menuitem *items;
    int icount, size;
    int i, k, n, listlen, id;
    char pick4u = 'n', thisch, lastch = 0;
    char pbuf[QBUFSZ], plbuf[QBUFSZ];
    struct nh_listitem list[LISTSZ]; /* need enough space for lists of roles or races */
    char listbuffers[LISTSZ][256];
    int pick_list[2];
    int initrole, initrace, initgend, initalign;
    const struct nh_roles_info *ri = nh_get_roles();
    
    if (tutorial)
	return tutorial_player_selection(out_role, out_race, out_gend, out_align);
    
    initrole = *out_role; initrace = *out_race;
    initalign = *out_align; initgend = *out_gend;
    if (initrole == ROLE_NONE) initrole = ri->def_role;
    if (initrace == ROLE_NONE) initrace = ri->def_race;
    if (initgend == ROLE_NONE) initgend = ri->def_gend;
    if (initalign == ROLE_NONE) initalign = ri->def_align;
    
    validate_character_presets(ri, &initrole, &initrace, &initgend, &initalign);
    
    for (i = 0; i < LISTSZ; i++) {
	listbuffers[i][0] = '\0';
	list[i].caption = listbuffers[i];
    }
    
    srandom(time(NULL));
    
    /* Should we randomly pick for the player? */
    if (!randomall &&
	(initrole == ROLE_NONE || initrace == ROLE_NONE ||
	    initgend == ROLE_NONE || initalign == ROLE_NONE)) {
	char *prompt = nh_build_plselection_prompt(pbuf, QBUFSZ, initrole,
			    initrace, initgend, initalign);

	pick4u = curses_yn_function(prompt, "ynq", 'y');	
	if (pick4u != 'y' && pick4u != 'n')
	    return FALSE;
    }

    nh_root_plselection_prompt(plbuf, QBUFSZ - 1,
		    initrole, initrace, initgend, initalign);
    icount = 0; size = 10;
    items = malloc(sizeof(struct nh_menuitem) * size);

    /* Select a role, if necessary */
    /* if pre-selected race/gender/alignment are still set after
     * validate_character_presets we know they're OK */
    if (initrole < 0) {
	listlen = get_valid_roles(ri, initrace, initgend, initalign, list, LISTSZ);
	
	/* Process the choice */
	if (pick4u == 'y' || initrole == ROLE_RANDOM || randomall) {
	    /* Pick a random role */
	    initrole = list[random() % listlen].id;
	} else {
	    /* Prompt for a role */
	    for (i = 0; i < listlen; i++) {
		id = list[i].id + 1; /* list[i].id starts at 0 */
		thisch = tolower((unsigned char)*list[i].caption);
		if (thisch == lastch)
		    thisch = toupper((unsigned char)thisch);
		add_menu_item(items, size, icount, id, list[i].caption + 2, thisch, 0);
		lastch = thisch;
	    }
	    pick_list[0] = id = list[random() % listlen].id+1;
	    add_menu_item(items, size, icount, id, "随机", '*', 0);
	    add_menu_item(items, size, icount, -1, "退出", 'q', 0);
	    
	    sprintf(pbuf, "为你的%s选择一个角色", plbuf);
	    n = curses_display_menu(items, icount, pbuf, PICK_ONE, pick_list);

	    /* Process the choice */
	    if (n == -1 || pick_list[0] == -1)
		goto give_up;		/* Selected quit */

	    initrole = pick_list[0] - 1;
	    icount = 0;
	}
	nh_root_plselection_prompt(plbuf, QBUFSZ - 1,
		    initrole, initrace, initgend, initalign);
    }
    
    /* Select a race, if necessary */
    if (initrace < 0) {
	listlen = get_valid_races(ri, initrole, initgend, initalign, list, LISTSZ);
	
	if (pick4u == 'y' || initrace == ROLE_RANDOM || randomall) {
	    initrace = list[random() % listlen].id;
	} else {	/* pick4u == 'n' */
	    /* Count the number of valid races */
	    k = list[0].id;	/* valid race */

	    /* Permit the user to pick, if there is more than one */
	    if (listlen > 1) {
		for (i = 0; i < listlen; i++) {
		    id = list[i].id + 1;
		    add_menu_item(items, size, icount, id, list[i].caption + 2,
				  list[i].caption[0], 0);
		}
		pick_list[0] = id = list[random() % listlen].id+1;
		add_menu_item(items, size, icount, id, "随机", '*', 0);
		add_menu_item(items, size, icount, -1, "退出", 'q', 0);

		sprintf(pbuf, "为你的%s选择一个种族", plbuf);
		n = curses_display_menu(items, icount, pbuf, PICK_ONE, pick_list);
		
		if (n == -1 || pick_list[0] == -1)
		    goto give_up;		/* Selected quit */

		k = pick_list[0] - 1;
		icount = 0;
	    }
	    initrace = k;
	}
	nh_root_plselection_prompt(plbuf, QBUFSZ - 1,
		    initrole, initrace, initgend, initalign);
    }

    /* Select a gender, if necessary */
    if (initgend < 0) {
	listlen = get_valid_genders(ri, initrole, initrace, initalign, list, LISTSZ);

	if (pick4u == 'y' || initgend == ROLE_RANDOM || randomall) {
	    initgend = list[random() % listlen].id;
	} else {	/* pick4u == 'n' */
	    /* Count the number of valid genders */
	    k = list[0].id;	/* valid gender */

	    /* Permit the user to pick, if there is more than one */
	    if (listlen > 1) {
		for (i = 0; i < listlen; i++) {
		    id = list[i].id + 1;
		    add_menu_item(items, size, icount, id, list[i].caption + 2,
				  list[i].caption[0], 0);
		}
		pick_list[0] = id = list[random() % listlen].id+1;
		add_menu_item(items, size, icount, id, "随机", '*', 0);
		add_menu_item(items, size, icount, -1, "退出", 'q', 0);

		sprintf(pbuf, "为你的%s选择一个性别", plbuf);
		n = curses_display_menu(items, icount, pbuf, PICK_ONE, pick_list);
		
		if (n == -1 || pick_list[0] == -1)
		    goto give_up;		/* Selected quit */

		k = pick_list[0] - 1;
		icount = 0;
	    }
	    initgend = k;
	}
	nh_root_plselection_prompt(plbuf, QBUFSZ - 1,
		    initrole, initrace, initgend, initalign);
    }

    /* Select an alignment, if necessary */
    if (initalign < 0) {
	listlen = get_valid_aligns(ri, initrole, initrace, initgend, list, LISTSZ);
	
	if (pick4u == 'y' || initalign == ROLE_RANDOM || randomall) {
	    initalign = list[random() % listlen].id;
	} else {	/* pick4u == 'n' */
	    /* Count the number of valid alignments */
	    k = list[0].id;	/* valid alignment */

	    /* Permit the user to pick, if there is more than one */
	    if (listlen > 1) {
		for (i = 0; i < listlen; i++) {
		    id = list[i].id + 1;
		    add_menu_item(items, size, icount, id, list[i].caption + 2,
				  list[i].caption[0], 0);
		}
		pick_list[0] = id = list[random() % listlen].id+1;
		add_menu_item(items, size, icount, id, "随机", '*', 0);
		add_menu_item(items, size, icount, -1, "退出", 'q', 0);
		
		sprintf(pbuf, "为你的%s选择一个阵营", plbuf);
		n = curses_display_menu(items, icount, pbuf, PICK_ONE, pick_list);
		
		if (n == -1 || pick_list[0] == -1)
		    goto give_up;		/* Selected quit */

		k = pick_list[0] - 1;
	    }
	    initalign = k;
	}
    }
    
    *out_role = initrole;
    *out_race = initrace;
    *out_gend = initgend;
    *out_align = initalign;
    
    free(items);
    return TRUE;
    
give_up:
    free(items);
    return FALSE;
}