public item_selector_type(Command_Code a, string b, string c, Misc.item_tester_hook_func d, int e) { command = a; prompt = b; noop = c; filter = d; mode = e; }
/* * Quit the game. */ //ARGS was cmd_arg public static void quit(Command_Code code, object[] args) { throw new NotImplementedException(); ///* Stop playing */ //p_ptr.playing = false; ///* Leaving */ //p_ptr.leaving = true; }
public Game_Command(Command_Code cmd, cmd_arg_type[] args, cmd_handler_fn func, bool r, int ar) { this.command = cmd; for (int i = 0; args != null && i < args.Length; i++) { this.arg_type[i] = args[i]; } this.fn = func; this.repeat_allowed = r; this.nrepeats = ar; }
/* Return the index of the given command in the command array. */ static int cmd_idx(Command_Code code) { for (int i = 0; i < game_cmds.Length; i++) { if (game_cmds[i].command == code) { return(i); } } return(-1); }
/* * Inserts a command in the queue to be carried out, with the given * number of repeats. */ public static int insert_repeated(Command_Code c, int nrepeats) { Game_Command cmd = new Game_Command(); if (cmd_idx(c) == -1) { return(1); } cmd.command = c; cmd.nrepeats = nrepeats; return(cmd_insert_s(ref cmd)); }
public Command_Info(string desc, char key, Command_Code cmd, hook_func hook = null, prereq_func prereq = null) { this.desc = desc; this.key = key; this.cmd = cmd; if (hook != null) { this.hook = hook; } if (prereq != null) { this.prereq = prereq; } }
public static char lookup_key(Command_Code lookup_cmd) { for (int i = 0; i < converted_list.Length; i++) { Command_Info cmd = converted_list[i]; if (cmd != null && cmd.cmd == lookup_cmd) { return(cmd.key); } } return('\0'); }
/* * Go down one level */ public static void go_down(Command_Code code, cmd_arg[] args) { /* Verify stairs */ if (Cave.cave.feat[Misc.p_ptr.py][Misc.p_ptr.px] != Cave.FEAT_MORE) { Utilities.msg("I see no down staircase here."); return; } /* Hack -- take a turn */ Misc.p_ptr.energy_use = 100; /* Success */ Utilities.msgt(Message_Type.MSG_STAIRS_DOWN, "You enter a maze of down staircases."); /* Create a way back */ Misc.p_ptr.create_up_stair = true; Misc.p_ptr.create_down_stair = false; /* Change level */ Dungeon.dungeon_change_level(Misc.p_ptr.depth + 1); }
/* * Inserts a command in the queue to be carried out, with the given * number of repeats. */ public static int insert_repeated(Command_Code c, int nrepeats) { Game_Command cmd = new Game_Command(); if (cmd_idx(c) == -1) return 1; cmd.command = c; cmd.nrepeats = nrepeats; return cmd_insert_s(ref cmd); }
public Game_Command() { this.command = Command_Code.NULL; this.arg_type = new cmd_arg_type[]{cmd_arg_type.arg_NONE, cmd_arg_type.arg_NONE}; this.fn = null; this.repeat_allowed = false; this.nrepeats = 0; }
/* Allow the user to select from the current menu, and return the * corresponding command to the game. Some actions are handled entirely * by the UI (displaying help text, for instance). */ static birth_stage menu_question(birth_stage current, Menu_Type current_menu, Command_Code choice_command) { birthmenu_data menu_data = current_menu.menu_data as birthmenu_data; birth_stage next = birth_stage.BIRTH_RESET; /* Print the question currently being asked. */ clear_question(); Term.putstr(QUESTION_COL, QUESTION_ROW, -1, ConsoleColor.Yellow, menu_data.hint); current_menu.cmd_keys = "?=*\x18"; /* ?, =, *, <ctl-X> */ while (next == birth_stage.BIRTH_RESET) { /* Display the menu, wait for a selection of some sort to be made. */ ui_event cx = current_menu.select(ui_event_type.EVT_KBRD, false); /* As all the menus are displayed in "hierarchical" style, we allow * use of "back" (left arrow key or equivalent) to step back in * the proces as well as "escape". */ if (cx.type == ui_event_type.EVT_ESCAPE) { next = birth_stage.BIRTH_BACK; } else if (cx.type == ui_event_type.EVT_SELECT) { if (current == birth_stage.BIRTH_ROLLER_CHOICE) { Game_Command.insert(Command_Code.FINALIZE_OPTIONS); if (current_menu.cursor != 0) { /* Do a first roll of the stats */ Game_Command.insert(Command_Code.ROLL_STATS); next = current + 2; } else { /* * Make sure we've got a point-based char to play with. * We call point_based_start here to make sure we get * an update on the points totals before trying to * display the screen. The call to CMD_RESET_STATS * forces a rebuying of the stats to give us up-to-date * totals. This is, it should go without saying, a hack. */ point_based_start(); Game_Command.insert(Command_Code.RESET_STATS); Game_Command.get_top().set_arg_choice(0, 1); next = current + 1; } } else { Game_Command.insert(choice_command); Game_Command.get_top().set_arg_choice(0, current_menu.cursor); next = current + 1; } } else if (cx.type == ui_event_type.EVT_KBRD) { /* '*' chooses an option at random from those the game's provided. */ if (cx.key.code == (keycode_t)'*' && menu_data.allow_random) { current_menu.cursor = Random.randint0(current_menu.count); Game_Command.insert(choice_command); Game_Command.get_top().set_arg_choice(0, current_menu.cursor); current_menu.refresh(false); next = current + 1; } else if (cx.key.code == (keycode_t)'=') { Do_Command.options_birth(); next = current; } else if (cx.key.code == (keycode_t)UIEvent.KTRL('X')) { Game_Command.insert(Command_Code.QUIT); next = birth_stage.BIRTH_COMPLETE; } else if (cx.key.code == (keycode_t)'?') { Do_Command.help(); } } } return(next); }
/* * Stay still. Search. Enter stores. * Pick up treasure if "pickup" is true. */ public static void hold(Command_Code code, cmd_arg[] args) { /* Take a turn */ Misc.p_ptr.energy_use = 100; /* Spontaneous Searching */ if ((Misc.p_ptr.state.skills[(int)Skill.SEARCH_FREQUENCY] >= 50) || Random.one_in_(50 - Misc.p_ptr.state.skills[(int)Skill.SEARCH_FREQUENCY])) { Command.search(false); } /* Continuous Searching */ if (Misc.p_ptr.searching != 0) { Command.search(false); } /* Pick things up, not using extra energy */ Command.do_autopickup(); /* Hack -- enter a store if we are on one */ if ((Cave.cave.feat[Misc.p_ptr.py][Misc.p_ptr.px] >= Cave.FEAT_SHOP_HEAD) && (Cave.cave.feat[Misc.p_ptr.py][Misc.p_ptr.px] <= Cave.FEAT_SHOP_TAIL)) { /* Disturb */ Cave.disturb(Misc.p_ptr, 0, 0); Game_Command.insert(Command_Code.ENTER_STORE); /* Free turn XXX XXX XXX */ Misc.p_ptr.energy_use = 0; } else { Game_Event.signal(Game_Event.Event_Type.SEEFLOOR); } }
/* * Pick up objects on the floor beneath you. -LM- */ public static void autopickup(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //p_ptr.energy_use = do_autopickup() * 10; }
/* * Rest (restores hit points and mana and such) */ public static void rest(Command_Code code, cmd_arg[] args) { /* * A little sanity checking on the input - only the specified negative * values are valid. */ if ((args[0].value < 0) && ((args[0].value != (int)Misc.REST.COMPLETE) && (args[0].value != (int)Misc.REST.ALL_POINTS) && (args[0].value != (int)Misc.REST.SOME_POINTS))) { return; } /* Save the rest code */ Misc.p_ptr.resting = (short)args[0].value; /* Truncate overlarge values */ if (Misc.p_ptr.resting > 9999) Misc.p_ptr.resting = 9999; /* Take a turn XXX XXX XXX (?) */ Misc.p_ptr.energy_use = 100; /* Cancel searching */ Misc.p_ptr.searching = 0; //false /* Recalculate bonuses */ Misc.p_ptr.update |= (Misc.PU_BONUS); /* Redraw the state */ Misc.p_ptr.redraw |= (Misc.PR_STATE); /* Handle stuff */ Misc.p_ptr.handle_stuff(); /* Refresh XXX XXX XXX */ Term.fresh(); }
public static void refill(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //object_type *j_ptr = &p_ptr.inventory[INVEN_LIGHT]; //bitflag f[OF_SIZE]; //int item = args[0].item; //object_type *o_ptr = object_from_item_idx(item); //if (!item_is_available(item, null, USE_INVEN | USE_FLOOR)) //{ // msg("You do not have that item to refill with it."); // return; //} ///* Check what we're wielding. */ //object_flags(j_ptr, f); //if (j_ptr.tval != TV_LIGHT) //{ // msg("You are not wielding a light."); // return; //} //else if (of_has(f, OF_NO_FUEL)) //{ // msg("Your light cannot be refilled."); // return; //} ///* It's a lamp */ //if (j_ptr.sval == SV_LIGHT_LANTERN) // refill_lamp(j_ptr, o_ptr, item); ///* It's a torch */ //else if (j_ptr.sval == SV_LIGHT_TORCH) // refuel_torch(j_ptr, o_ptr, item); //p_ptr.energy_use = 50; }
/* * Pick up objects on the floor beneath you. -LM- */ public static void pickup(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //int energy_cost; ///* Pick up floor objects, forcing a menu for multiple objects. */ //energy_cost = py_pickup(1) * 10; ///* Charge this amount of energy. */ //p_ptr.energy_use = energy_cost; }
/* * Start running with pathfinder. * * Note that running while confused is not allowed. */ public static void pathfind(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); ///* Hack XXX XXX XXX */ //int dir = 5; //if (player_confuse_dir(p_ptr, &dir, true)) //{ // return; //} //if (findpath(args[0].point.x, args[0].point.y)) //{ // p_ptr.running = 1000; // /* Calculate torch radius */ // p_ptr.update |= (PU_TORCH); // p_ptr.running_withpathfind = true; // run_step(0); //} }
/* * Open a closed/locked/jammed door or a closed/locked chest. * * Unlocking a locked door/chest is worth one experience point. */ public static void open(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //int y, x, dir; //s16b o_idx; //bool more = false; //dir = args[0].direction; ///* Get location */ //y = p_ptr.py + ddy[dir]; //x = p_ptr.px + ddx[dir]; ///* Check for chests */ //o_idx = chest_check(y, x); ///* Verify legality */ //if (!o_idx && !do_cmd_open_test(y, x)) //{ // /* Cancel repeat */ // disturb(p_ptr, 0, 0); // return; //} ///* Take a turn */ //p_ptr.energy_use = 100; ///* Apply confusion */ //if (player_confuse_dir(p_ptr, &dir, false)) //{ // /* Get location */ // y = p_ptr.py + ddy[dir]; // x = p_ptr.px + ddx[dir]; // /* Check for chest */ // o_idx = chest_check(y, x); //} ///* Monster */ //if (cave.m_idx[y][x] > 0) //{ // int m_idx = cave.m_idx[y][x]; // /* Mimics surprise the player */ // if (is_mimicking(m_idx)) { // become_aware(m_idx); // /* Mimic wakes up */ // mon_clear_timed(m_idx, MON_TMD_SLEEP, MON_TMD_FLG_NOMESSAGE, false); // } else { // /* Message */ // msg("There is a monster in the way!"); // /* Attack */ // py_attack(y, x); // } //} ///* Chest */ //else if (o_idx) //{ // /* Open the chest */ // more = do_cmd_open_chest(y, x, o_idx); //} ///* Door */ //else //{ // /* Open the door */ // more = do_cmd_open_aux(y, x); //} ///* Cancel repeat unless we may continue */ //if (!more) disturb(p_ptr, 0, 0); }
/* * Walk into a trap. */ public static void jump(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //int x, y; //int dir = args[0].direction; ///* Apply confusion if necessary */ //player_confuse_dir(p_ptr, &dir, false); ///* Verify walkability */ //y = p_ptr.py + ddy[dir]; //x = p_ptr.px + ddx[dir]; //if (!do_cmd_walk_test(y, x)) // return; //p_ptr.energy_use = 100; //move_player(dir, false); }
/* * Retrieve the item with the given index from the home's inventory. */ public static void retrieve(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //int item = args[0].item; //int amt = args[1].number; //object_type *o_ptr; //object_type picked_item; //char o_name[80]; //int item_new; //struct store *store = current_store(); //if (store.sidx != STORE_HOME) { // msg("You are not currently at home."); // return; //} ///* Get the actual object */ //o_ptr = &store.stock[item]; ///* Get desired object */ //object_copy_amt(&picked_item, o_ptr, amt); ///* Ensure we have room */ //if (!inven_carry_okay(&picked_item)) //{ // msg("You cannot carry that many items."); // return; //} ///* Distribute charges of wands, staves, or rods */ //distribute_charges(o_ptr, &picked_item, amt); ///* Give it to the player */ //item_new = inven_carry(p_ptr, &picked_item); ///* Describe just the result */ //object_desc(o_name, sizeof(o_name), &p_ptr.inventory[item_new], // ODESC_PREFIX | ODESC_FULL); ///* Message */ //msg("You have %s (%c).", o_name, index_to_label(item_new)); ///* Handle stuff */ //handle_stuff(p_ptr); ///* Remove the items from the home */ //store_item_increase(store, item, -amt); //store_item_optimize(store, item); //event_signal(EVENT_INVENTORY); //event_signal(EVENT_EQUIPMENT); }
public static int get_birth_command(bool wait) { birth_stage next = current_stage; switch (current_stage) { case birth_stage.BIRTH_RESET: { Game_Command.insert(Command_Code.BIRTH_RESET); roller = birth_stage.BIRTH_RESET; if (quickstart_allowed) { next = birth_stage.BIRTH_QUICKSTART; } else { next = birth_stage.BIRTH_SEX_CHOICE; } break; } case birth_stage.BIRTH_QUICKSTART: { Files.display_player(0); next = get_quickstart_command(); break; } case birth_stage.BIRTH_SEX_CHOICE: case birth_stage.BIRTH_CLASS_CHOICE: case birth_stage.BIRTH_RACE_CHOICE: case birth_stage.BIRTH_ROLLER_CHOICE: { Menu_Type menu = sex_menu; Command_Code command = Command_Code.CHOOSE_SEX; Term.clear(); print_menu_instructions(); if (current_stage > birth_stage.BIRTH_SEX_CHOICE) { sex_menu.refresh(false); menu = race_menu; command = Command_Code.CHOOSE_RACE; } if (current_stage > birth_stage.BIRTH_RACE_CHOICE) { race_menu.refresh(false); menu = class_menu; command = Command_Code.CHOOSE_CLASS; } if (current_stage > birth_stage.BIRTH_CLASS_CHOICE) { class_menu.refresh(false); menu = roller_menu; command = Command_Code.NULL; } next = menu_question(current_stage, menu, command); if (next == birth_stage.BIRTH_BACK) { next = current_stage - 1; } /* Make sure that the character gets reset before quickstarting */ if (next == birth_stage.BIRTH_QUICKSTART) { next = birth_stage.BIRTH_RESET; } break; } case birth_stage.BIRTH_POINTBASED: { roller = birth_stage.BIRTH_POINTBASED; if (prev > birth_stage.BIRTH_POINTBASED) { point_based_start(); } next = point_based_command(); if (next == birth_stage.BIRTH_BACK) { next = birth_stage.BIRTH_ROLLER_CHOICE; } if (next != birth_stage.BIRTH_POINTBASED) { point_based_stop(); } break; } case birth_stage.BIRTH_ROLLER: { roller = birth_stage.BIRTH_ROLLER; next = roller_command(prev < birth_stage.BIRTH_ROLLER); if (next == birth_stage.BIRTH_BACK) { next = birth_stage.BIRTH_ROLLER_CHOICE; } break; } case birth_stage.BIRTH_NAME_CHOICE: { if (prev < birth_stage.BIRTH_NAME_CHOICE) { Files.display_player(0); } next = get_name_command(); if (next == birth_stage.BIRTH_BACK) { next = roller; } break; } case birth_stage.BIRTH_FINAL_CONFIRM: { if (prev < birth_stage.BIRTH_FINAL_CONFIRM) { Files.display_player(0); } next = get_confirm_command(); if (next == birth_stage.BIRTH_BACK) { next = birth_stage.BIRTH_NAME_CHOICE; } break; } } prev = current_stage; current_stage = next; return(0); }
/* * Start running. * * Note that running while confused is not allowed. */ public static void run(Command_Code code, cmd_arg[] args) { int x, y; int dir = args[0].value; if (Misc.p_ptr.confuse_dir(ref dir, true)) { return; } /* Get location */ y = Misc.p_ptr.py + Misc.ddy[dir]; x = Misc.p_ptr.px + Misc.ddx[dir]; if (!Do_Command.walk_test(y, x)) return; /* Start run */ Pathfind.run_step(dir); }
public static char lookup_key(Command_Code lookup_cmd) { for (int i = 0; i < converted_list.Length; i++) { Command_Info cmd = converted_list[i]; if (cmd != null && cmd.cmd == lookup_cmd) return cmd.key; } return '\0'; }
public static void save_game(Command_Code code, cmd_arg[] args) { Files.save_game(); }
public Game_Command(Command_Code cmd, cmd_arg_type[] args, cmd_handler_fn func, bool r, int ar) { this.command = cmd; for(int i = 0; args != null && i < args.Length; i++) { this.arg_type[i] = args[i]; } this.fn = func; this.repeat_allowed = r; this.nrepeats = ar; }
/* * Simple command to "search" for one turn */ public static void search(Command_Code code, cmd_arg[] args) { /* Only take a turn if attempted */ if (Command.search(true)) Misc.p_ptr.energy_use = 100; }
/* * Inserts a command in the queue to be carried out. */ public static int insert(Command_Code c) { return insert_repeated(c, 0); }
/* * Sell an item to the current store. */ public static void sell(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); // int item = args[0].item; // int amt = args[1].number; // object_type sold_item; // struct store *store = current_store(); // int price, dummy, value; // char o_name[120]; // /* Get the item */ // object_type *o_ptr = object_from_item_idx(item); // /* Cannot remove cursed objects */ // if ((item >= INVEN_WIELD) && cursed_p(o_ptr.flags)) { // msg("Hmmm, it seems to be cursed."); // return; // } // /* Check we are somewhere we can sell the items. */ // if (!store) { // msg("You cannot sell items when not in a store."); // return; // } // /* Check the store wants the items being sold */ // if (!store_will_buy(store, o_ptr)) { // msg("I do not wish to purchase this item."); // return; // } // /* Get a copy of the object representing the number being sold */ // object_copy_amt(&sold_item, o_ptr, amt); // /* Check if the store has space for the items */ // if (!store_check_num(store, &sold_item)) // { // msg("I have not the room in my store to keep it."); // return; // } // price = price_item(&sold_item, true, amt); // /* Get some money */ // p_ptr.au += price; // /* Update the display */ // store_flags |= STORE_GOLD_CHANGE; // /* Update the auto-history if selling an artifact that was previously un-IDed. (Ouch!) */ // if (o_ptr.artifact) // history_add_artifact(o_ptr.artifact, true, true); // /* Combine / Reorder the pack (later) */ // p_ptr.notice |= (PN_COMBINE | PN_REORDER | PN_SORT_QUIVER); // /* Redraw stuff */ // p_ptr.redraw |= (PR_INVEN | PR_EQUIP); // /* Get the "apparent" value */ // dummy = object_value(&sold_item, amt, false); ///* msg("Dummy is %d", dummy); */ // /* Identify original object */ // object_notice_everything(o_ptr); // /* Take a new copy of the now known-about object. */ // object_copy_amt(&sold_item, o_ptr, amt); // /* The item belongs to the store now */ // sold_item.ident |= IDENT_STORE; // /* // * Hack -- Allocate charges between those wands, staves, or rods // * sold and retained, unless all are being sold. // */ // distribute_charges(o_ptr, &sold_item, amt); // /* Get the "actual" value */ // value = object_value(&sold_item, amt, false); ///* msg("Value is %d", value); */ // /* Get the description all over again */ // object_desc(o_name, sizeof(o_name), &sold_item, ODESC_PREFIX | ODESC_FULL); // /* Describe the result (in message buffer) */ // msg("You sold %s (%c) for %ld gold.", // o_name, index_to_label(item), (long)price); // /* Analyze the prices (and comment verbally) */ // purchase_analyze(price, value, dummy); // /* Set squelch flag */ // p_ptr.notice |= PN_SQUELCH; // /* Take the object from the player */ // inven_item_increase(item, -amt); // inven_item_optimize(item); // /* Handle stuff */ // handle_stuff(p_ptr); // /* The store gets that (known) object */ // store_carry(store, &sold_item); // event_signal(EVENT_INVENTORY); // event_signal(EVENT_EQUIPMENT); }
/* Return the index of the given command in the command array. */ static int cmd_idx(Command_Code code) { for (int i = 0; i < game_cmds.Length; i++) { if (game_cmds[i].command == code) return i; } return -1; }
/* * Find the "first" inventory object with the given "tag". * * A "tag" is a char "n" appearing as "@n" anywhere in the * inscription of an object. * * Also, the tag "@xn" will work as well, where "n" is a tag-char, * and "x" is the action that tag will work for. */ static bool get_tag(ref int cp, char tag, Command_Code cmd, bool quiver_tags) { int i; /* (f)ire is handled differently from all others, due to the quiver */ if (quiver_tags) { i = Misc.QUIVER_START + tag - '0'; if (Misc.p_ptr.inventory[i].kind != null) { cp = i; return(true); } return(false); } /* Check every object */ for (i = 0; i < Misc.ALL_INVEN_TOTAL; ++i) { Object o_ptr = Misc.p_ptr.inventory[i]; /* Skip non-objects */ if (o_ptr.kind == null) { continue; } /* Skip empty inscriptions */ if (o_ptr.note == null) { continue; } /* Find a '@' */ string[] tags = o_ptr.note.ToString().Split('@'); int tagat = 0; //strchr(quark_str(o_ptr.note), '@'); /* Process all tags */ while (tagat < tags.Length) { string s = tags[tagat++]; /* Check the normal tags */ if (s[0] == tag) { /* Save the actual inventory ID */ cp = i; /* Success */ return(true); } /* Check the special tags */ if ((Command.lookup(s[1]) == cmd) && (s[2] == tag)) { /* Save the actual inventory ID */ cp = i; /* Success */ return(true); } /* Find another '@' */ //s = strchr(s + 1, '@'); } } /* No such tag */ return(false); }
/* * Go up one level */ public static void go_up(Command_Code code, cmd_arg[] args) { /* Verify stairs */ if (Cave.cave.feat[Misc.p_ptr.py][Misc.p_ptr.px] != Cave.FEAT_LESS) { Utilities.msg("I see no up staircase here."); return; } /* Ironman */ if (Option.birth_ironman.value) { Utilities.msg("Nothing happens!"); return; } /* Hack -- take a turn */ Misc.p_ptr.energy_use = 100; /* Success */ Utilities.msgt(Message_Type.MSG_STAIRS_UP, "You enter a maze of up staircases."); /* Create a way back */ Misc.p_ptr.create_up_stair = false; Misc.p_ptr.create_down_stair = true; /* Change level */ Dungeon.dungeon_change_level(Misc.p_ptr.depth - 1); }
/* * Let the user select an item, save its "index" * * Return true only if an acceptable item was chosen by the user. * * The selected item must satisfy the "item_tester_hook()" function, * if that hook is set, and the "item_tester_tval", if that value is set. * * All "item_tester" restrictions are cleared before this function returns. * * The user is allowed to choose acceptable items from the equipment, * inventory, or floor, respectively, if the proper flag was given, * and there are any acceptable items in that location. * * The equipment or inventory are displayed (even if no acceptable * items are in that location) if the proper flag was given. * * If there are no acceptable items available anywhere, and "str" is * not null, then it will be used as the text of a warning message * before the function returns. * * Note that the user must press "-" to specify the item on the floor, * and there is no way to "examine" the item on the floor, while the * use of "capital" letters will "examine" an inventory/equipment item, * and prompt for its use. * * If a legal item is selected from the inventory, we save it in "cp" * directly (0 to 35), and return true. * * If a legal item is selected from the floor, we save it in "cp" as * a negative (-1 to -511), and return true. * * If no item is available, we do nothing to "cp", and we display a * warning message, using "str" if available, and return false. * * If no item is selected, we do nothing to "cp", and return false. * * Global "p_ptr.command_wrk" is used to choose between equip/inven/floor * listings. It is equal to USE_INVEN or USE_EQUIP or USE_FLOOR, except * when this function is first called, when it is equal to zero, which will * cause it to be set to USE_INVEN. * * We always erase the prompt when we are done, leaving a blank line, * or a warning message, if appropriate, if no items are available. * * Note that only "acceptable" floor objects get indexes, so between two * commands, the indexes of floor objects may change. XXX XXX XXX */ public static bool get_item(ref int cp, string pmt, string str, Command_Code cmd, int mode) { int py = Misc.p_ptr.py; int px = Misc.p_ptr.px; char cmdkey = Command.lookup_key(cmd); keypress which; int j, k = 0; int i1, i2; int e1, e2; int f1, f2; bool done, item; bool oops = false; bool use_inven = ((mode & Misc.USE_INVEN) != 0 ? true : false); bool use_equip = ((mode & Misc.USE_EQUIP) != 0 ? true : false); bool use_floor = ((mode & Misc.USE_FLOOR) != 0 ? true : false); bool use_quiver = ((mode & Misc.QUIVER_TAGS) != 0 ? true : false); bool is_harmless = ((mode & Misc.IS_HARMLESS) != 0 ? true : false); bool quiver_tags = ((mode & Misc.QUIVER_TAGS) != 0 ? true : false); olist_detail_t olist_mode = 0; bool allow_inven = false; bool allow_equip = false; bool allow_floor = false; bool toggle = false; string tmp_val;//[160]; string out_val;//[160]; int[] floor_list = new int[Misc.MAX_FLOOR_STACK]; int floor_num; bool show_list = true; /* Object list display modes */ if ((mode & Misc.SHOW_FAIL) != 0) olist_mode |= (olist_detail_t.OLIST_FAIL); else olist_mode |= (olist_detail_t.OLIST_WEIGHT); if ((mode & Misc.SHOW_PRICES) != 0) olist_mode |= (olist_detail_t.OLIST_PRICE); /* Paranoia XXX XXX XXX */ Utilities.message_flush(); /* Not done */ done = false; /* No item selected */ item = false; /* Full inventory */ i1 = 0; i2 = Misc.INVEN_PACK - 1; /* Forbid inventory */ if (!use_inven) i2 = -1; /* Restrict inventory indexes */ while ((i1 <= i2) && (!Object.get_item_okay(i1))) i1++; while ((i1 <= i2) && (!get_item_okay(i2))) i2--; /* Accept inventory */ if (i1 <= i2) allow_inven = true; /* Full equipment */ e1 = Misc.INVEN_WIELD; e2 = Misc.ALL_INVEN_TOTAL - 1; /* Forbid equipment */ if (!use_equip) e2 = -1; /* Restrict equipment indexes */ while ((e1 <= e2) && (!get_item_okay(e1))) e1++; while ((e1 <= e2) && (!get_item_okay(e2))) e2--; /* Accept equipment */ if (e1 <= e2) allow_equip = true; /* Scan all non-gold objects in the grid */ floor_num = scan_floor(floor_list, floor_list.Length, py, px, 0x03); /* Full floor */ f1 = 0; f2 = floor_num - 1; /* Forbid floor */ if (!use_floor) f2 = -1; /* Restrict floor indexes */ while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f1]))) f1++; while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f2]))) f2--; /* Accept floor */ if (f1 <= f2) allow_floor = true; /* Require at least one legal choice */ if (!allow_inven && !allow_equip && !allow_floor) { /* Oops */ oops = true; done = true; } /* Analyze choices */ else { /* Hack -- Start on equipment if requested */ if ((Misc.p_ptr.command_wrk == Misc.USE_EQUIP) && use_equip) Misc.p_ptr.command_wrk = Misc.USE_EQUIP; /* If we are using the quiver then start on equipment */ else if (use_quiver) Misc.p_ptr.command_wrk = Misc.USE_EQUIP; /* Use inventory if allowed */ else if (use_inven) Misc.p_ptr.command_wrk = Misc.USE_INVEN; /* Use equipment if allowed */ else if (use_equip) Misc.p_ptr.command_wrk = Misc.USE_EQUIP; /* Use floor if allowed */ else if (use_floor) Misc.p_ptr.command_wrk = Misc.USE_FLOOR; /* Hack -- Use (empty) inventory */ else Misc.p_ptr.command_wrk = Misc.USE_INVEN; } /* Start out in "display" mode */ if (show_list) { /* Save screen */ Utilities.screen_save(); } /* Repeat until done */ while (!done) { int ni = 0; int ne = 0; /* Scan windows */ for (j = 0; j < Misc.ANGBAND_TERM_MAX; j++) { /* Unused */ if (Misc.angband_term[j] == null) continue; /* Count windows displaying inven */ if ((Player.Player_Other.instance.window_flag[j] & (Misc.PW_INVEN)) != 0) ni++; /* Count windows displaying equip */ if ((Player.Player_Other.instance.window_flag[j] & (Misc.PW_EQUIP)) != 0) ne++; } /* Toggle if needed */ if (((Misc.p_ptr.command_wrk == Misc.USE_EQUIP) && ni != 0 && ne == 0) || ((Misc.p_ptr.command_wrk == Misc.USE_INVEN) && ni == 0 && ne != 0)) { /* Toggle */ Command_Info.toggle_inven_equip(); /* Track toggles */ toggle = !toggle; } /* Redraw */ Misc.p_ptr.redraw |= (Misc.PR_INVEN | Misc.PR_EQUIP); /* Redraw windows */ Misc.p_ptr.redraw_stuff(); /* Viewing inventory */ if (Misc.p_ptr.command_wrk == Misc.USE_INVEN) { /* Redraw if needed */ if (show_list) show_inven(olist_mode); /* Begin the prompt */ out_val = "Inven:"; /* List choices */ if (i1 <= i2) { /* Build the prompt */ tmp_val = String.Format(" {0}-{1},", index_to_label(i1), index_to_label(i2)); /* Append */ out_val += tmp_val; } /* Indicate ability to "view" */ if (!show_list) { out_val += " * to see,"; Button.button_add("[*]", '*'); } /* Indicate legality of "toggle" */ if (use_equip) { out_val += " / for Equip,"; Button.button_add("[/]", '/'); } /* Indicate legality of the "floor" */ if (allow_floor) { out_val += " - for floor,"; Button.button_add("[-]", '-'); } } /* Viewing equipment */ else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP) { /* Redraw if needed */ if (show_list) show_equip(olist_mode); /* Begin the prompt */ out_val = "Equip:"; /* List choices */ if (e1 <= e2) { /* Build the prompt */ tmp_val = String.Format(" {0}-{1},", index_to_label(e1), index_to_label(e2)); /* Append */ out_val += tmp_val; } /* Indicate ability to "view" */ if (!show_list) { out_val += " * to see,"; Button.button_add("[*]", '*'); } /* Indicate legality of "toggle" */ if (use_inven) { out_val += " / for Inven,"; Button.button_add("[/]", '/'); } /* Indicate legality of the "floor" */ if (allow_floor) { out_val += " - for floor,"; Button.button_add("[!]", '!'); } } /* Viewing floor */ else { /* Redraw if needed */ if (show_list) show_floor(floor_list, floor_num, olist_mode); /* Begin the prompt */ out_val = "Floor:"; /* List choices */ if (f1 <= f2) { /* Build the prompt */ tmp_val = String.Format(" {0}-{1}", Basic.I2A(f1), Basic.I2A(f2)); /* Append */ out_val += tmp_val; } /* Indicate ability to "view" */ if (!show_list) { out_val += " * to see,"; Button.button_add("[*]", '*'); } /* Append */ if (use_inven) { out_val += " / for Inven,"; Button.button_add("[/]", '/'); } /* Append */ else if (use_equip) { out_val += " / for Equip,"; Button.button_add("[/]", '/'); } } Misc.p_ptr.redraw_stuff(); /* Finish the prompt */ out_val += " ESC"; /* Build the prompt */ tmp_val = String.Format("({0}) {1}", out_val, pmt); /* Show the prompt */ Utilities.prt(tmp_val, 0, 0); /* Get a key */ which = Utilities.inkey(); /* Parse it */ switch (which.code) { case keycode_t.ESCAPE: { done = true; break; } case (keycode_t)'/': { /* Toggle to inventory */ if (use_inven && (Misc.p_ptr.command_wrk != Misc.USE_INVEN)) { Misc.p_ptr.command_wrk = Misc.USE_INVEN; } /* Toggle to equipment */ else if (use_equip && (Misc.p_ptr.command_wrk != Misc.USE_EQUIP)) { Misc.p_ptr.command_wrk = Misc.USE_EQUIP; } /* No toggle allowed */ else { Utilities.bell("Cannot switch item selector!"); break; } /* Hack -- Fix screen */ if (show_list) { /* Load screen */ Utilities.screen_load(); /* Save screen */ Utilities.screen_save(); } /* Need to redraw */ break; } case (keycode_t)'-': { /* Paranoia */ if (!allow_floor) { Utilities.bell("Cannot select floor!"); break; } /* There is only one item */ if (floor_num == 1) { /* Auto-select */ if (Misc.p_ptr.command_wrk == (Misc.USE_FLOOR)) { /* Special index */ k = 0 - floor_list[0]; /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } } /* Hack -- Fix screen */ if (show_list) { /* Load screen */ Utilities.screen_load(); /* Save screen */ Utilities.screen_save(); } Misc.p_ptr.command_wrk = (Misc.USE_FLOOR); //#if 0 // /* Check each legal object */ // for (i = 0; i < floor_num; ++i) // { // /* Special index */ // k = 0 - floor_list[i]; // /* Skip non-okay objects */ // if (!get_item_okay(k)) continue; // /* Allow player to "refuse" certain actions */ // if (!get_item_allow(k, cmdkey, is_harmless)) continue; // /* Accept that choice */ // (*cp) = k; // item = true; // done = true; // break; // } //#endif break; } case (keycode_t)'0': case (keycode_t)'1': case (keycode_t)'2': case (keycode_t)'3': case (keycode_t)'4': case (keycode_t)'5': case (keycode_t)'6': case (keycode_t)'7': case (keycode_t)'8': case (keycode_t)'9': { /* Look up the tag */ if (!get_tag(ref k, (char)which.code, cmd, quiver_tags)) { Utilities.bell("Illegal object choice (tag)!"); break; } /* Hack -- Validate the item */ if ((k < Misc.INVEN_WIELD) ? !allow_inven : !allow_equip) { Utilities.bell("Illegal object choice (tag)!"); break; } /* Validate the item */ if (!get_item_okay(k)) { Utilities.bell("Illegal object choice (tag)!"); break; } /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } case (keycode_t)'\n': case (keycode_t)'\r': { /* Choose "default" inventory item */ if (Misc.p_ptr.command_wrk == Misc.USE_INVEN) { if (i1 != i2) { Utilities.bell("Illegal object choice (default)!"); break; } k = i1; } /* Choose the "default" slot (0) of the quiver */ else if (quiver_tags) k = e1; /* Choose "default" equipment item */ else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP) { if (e1 != e2) { Utilities.bell("Illegal object choice (default)!"); break; } k = e1; } /* Choose "default" floor item */ else { if (f1 != f2) { Utilities.bell("Illegal object choice (default)!"); break; } k = 0 - floor_list[f1]; } /* Validate the item */ if (!get_item_okay(k)) { Utilities.bell("Illegal object choice (default)!"); break; } /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } default: { bool verify; /* Note verify */ verify = (Char.IsUpper((char)which.code) ? true : false); /* Lowercase */ which.code = (keycode_t)Char.ToLower((char)which.code); /* Convert letter to inventory index */ if (Misc.p_ptr.command_wrk == Misc.USE_INVEN) { k = label_to_inven((char)which.code); if (k < 0) { Utilities.bell("Illegal object choice (inven)!"); break; } } /* Convert letter to equipment index */ else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP) { k = label_to_equip((char)which.code); if (k < 0) { Utilities.bell("Illegal object choice (equip)!"); break; } } /* Convert letter to floor index */ else { k = (Char.IsLower((char)which.code) ? Basic.A2I((char)which.code) : -1); if (k < 0 || k >= floor_num) { Utilities.bell("Illegal object choice (floor)!"); break; } /* Special index */ k = 0 - floor_list[k]; } /* Validate the item */ if (!get_item_okay(k)) { Utilities.bell("Illegal object choice (normal)!"); break; } /* Verify the item */ if (verify && !verify_item("Try", k)) { done = true; break; } /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } } } /* Fix the screen if necessary */ if (show_list) { /* Load screen */ Utilities.screen_load(); /* Hack -- Cancel "display" */ show_list = false; } /* Kill buttons */ Button.button_kill('*'); Button.button_kill('/'); Button.button_kill('-'); Button.button_kill('!'); Misc.p_ptr.redraw_stuff(); /* Forget the item_tester_tval restriction */ Misc.item_tester_tval = 0; /* Forget the item_tester_hook restriction */ Misc.item_tester_hook = null; /* Toggle again if needed */ if (toggle) Command_Info.toggle_inven_equip(); /* Update */ Misc.p_ptr.redraw |= (Misc.PR_INVEN | Misc.PR_EQUIP); Misc.p_ptr.redraw_stuff(); /* Clear the prompt line */ Utilities.prt("", 0, 0); /* Warning if needed */ if (oops && str != null) Utilities.msg("{0}", str); /* Result */ return (item); }
/* * Inserts a command in the queue to be carried out. */ public static int insert(Command_Code c) { return(insert_repeated(c, 0)); }
/** * Fire an object from the quiver, pack or floor at a target. */ public static void fire(Command_Code code, cmd_arg[] args) { int item = args[0].value; int dir = args[1].value; int range = 6 + 2 * Misc.p_ptr.state.ammo_mult; int shots = Misc.p_ptr.state.num_shots; Attack.ranged_attack attack = Attack.make_ranged_shot; Object.Object j_ptr = Misc.p_ptr.inventory[Misc.INVEN_BOW]; Object.Object o_ptr = Object.Object.object_from_item_idx(item); /* Require a usable launcher */ if (j_ptr.tval == 0 || Misc.p_ptr.state.ammo_tval == 0) { Utilities.msg("You have nothing to fire with."); return; } /* Check the item being fired is usable by the player. */ if (!Object.Object.item_is_available(item, null, Misc.USE_EQUIP | Misc.USE_INVEN | Misc.USE_FLOOR)) { Utilities.msg("That item is not within your reach."); return; } /* Check the ammo can be used with the launcher */ if (o_ptr.tval != Misc.p_ptr.state.ammo_tval) { Utilities.msg("That ammo cannot be fired by your current weapon."); return; } Attack.ranged_helper(item, dir, range, shots, attack); }
/* * Let the user select an item, save its "index" * * Return true only if an acceptable item was chosen by the user. * * The selected item must satisfy the "item_tester_hook()" function, * if that hook is set, and the "item_tester_tval", if that value is set. * * All "item_tester" restrictions are cleared before this function returns. * * The user is allowed to choose acceptable items from the equipment, * inventory, or floor, respectively, if the proper flag was given, * and there are any acceptable items in that location. * * The equipment or inventory are displayed (even if no acceptable * items are in that location) if the proper flag was given. * * If there are no acceptable items available anywhere, and "str" is * not null, then it will be used as the text of a warning message * before the function returns. * * Note that the user must press "-" to specify the item on the floor, * and there is no way to "examine" the item on the floor, while the * use of "capital" letters will "examine" an inventory/equipment item, * and prompt for its use. * * If a legal item is selected from the inventory, we save it in "cp" * directly (0 to 35), and return true. * * If a legal item is selected from the floor, we save it in "cp" as * a negative (-1 to -511), and return true. * * If no item is available, we do nothing to "cp", and we display a * warning message, using "str" if available, and return false. * * If no item is selected, we do nothing to "cp", and return false. * * Global "p_ptr.command_wrk" is used to choose between equip/inven/floor * listings. It is equal to USE_INVEN or USE_EQUIP or USE_FLOOR, except * when this function is first called, when it is equal to zero, which will * cause it to be set to USE_INVEN. * * We always erase the prompt when we are done, leaving a blank line, * or a warning message, if appropriate, if no items are available. * * Note that only "acceptable" floor objects get indexes, so between two * commands, the indexes of floor objects may change. XXX XXX XXX */ public static bool get_item(ref int cp, string pmt, string str, Command_Code cmd, int mode) { int py = Misc.p_ptr.py; int px = Misc.p_ptr.px; char cmdkey = Command.lookup_key(cmd); keypress which; int j, k = 0; int i1, i2; int e1, e2; int f1, f2; bool done, item; bool oops = false; bool use_inven = ((mode & Misc.USE_INVEN) != 0 ? true : false); bool use_equip = ((mode & Misc.USE_EQUIP) != 0 ? true : false); bool use_floor = ((mode & Misc.USE_FLOOR) != 0 ? true : false); bool use_quiver = ((mode & Misc.QUIVER_TAGS) != 0 ? true : false); bool is_harmless = ((mode & Misc.IS_HARMLESS) != 0 ? true : false); bool quiver_tags = ((mode & Misc.QUIVER_TAGS) != 0 ? true : false); olist_detail_t olist_mode = 0; bool allow_inven = false; bool allow_equip = false; bool allow_floor = false; bool toggle = false; string tmp_val; //[160]; string out_val; //[160]; int[] floor_list = new int[Misc.MAX_FLOOR_STACK]; int floor_num; bool show_list = true; /* Object list display modes */ if ((mode & Misc.SHOW_FAIL) != 0) { olist_mode |= (olist_detail_t.OLIST_FAIL); } else { olist_mode |= (olist_detail_t.OLIST_WEIGHT); } if ((mode & Misc.SHOW_PRICES) != 0) { olist_mode |= (olist_detail_t.OLIST_PRICE); } /* Paranoia XXX XXX XXX */ Utilities.message_flush(); /* Not done */ done = false; /* No item selected */ item = false; /* Full inventory */ i1 = 0; i2 = Misc.INVEN_PACK - 1; /* Forbid inventory */ if (!use_inven) { i2 = -1; } /* Restrict inventory indexes */ while ((i1 <= i2) && (!Object.get_item_okay(i1))) { i1++; } while ((i1 <= i2) && (!get_item_okay(i2))) { i2--; } /* Accept inventory */ if (i1 <= i2) { allow_inven = true; } /* Full equipment */ e1 = Misc.INVEN_WIELD; e2 = Misc.ALL_INVEN_TOTAL - 1; /* Forbid equipment */ if (!use_equip) { e2 = -1; } /* Restrict equipment indexes */ while ((e1 <= e2) && (!get_item_okay(e1))) { e1++; } while ((e1 <= e2) && (!get_item_okay(e2))) { e2--; } /* Accept equipment */ if (e1 <= e2) { allow_equip = true; } /* Scan all non-gold objects in the grid */ floor_num = scan_floor(floor_list, floor_list.Length, py, px, 0x03); /* Full floor */ f1 = 0; f2 = floor_num - 1; /* Forbid floor */ if (!use_floor) { f2 = -1; } /* Restrict floor indexes */ while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f1]))) { f1++; } while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f2]))) { f2--; } /* Accept floor */ if (f1 <= f2) { allow_floor = true; } /* Require at least one legal choice */ if (!allow_inven && !allow_equip && !allow_floor) { /* Oops */ oops = true; done = true; } /* Analyze choices */ else { /* Hack -- Start on equipment if requested */ if ((Misc.p_ptr.command_wrk == Misc.USE_EQUIP) && use_equip) { Misc.p_ptr.command_wrk = Misc.USE_EQUIP; } /* If we are using the quiver then start on equipment */ else if (use_quiver) { Misc.p_ptr.command_wrk = Misc.USE_EQUIP; } /* Use inventory if allowed */ else if (use_inven) { Misc.p_ptr.command_wrk = Misc.USE_INVEN; } /* Use equipment if allowed */ else if (use_equip) { Misc.p_ptr.command_wrk = Misc.USE_EQUIP; } /* Use floor if allowed */ else if (use_floor) { Misc.p_ptr.command_wrk = Misc.USE_FLOOR; } /* Hack -- Use (empty) inventory */ else { Misc.p_ptr.command_wrk = Misc.USE_INVEN; } } /* Start out in "display" mode */ if (show_list) { /* Save screen */ Utilities.screen_save(); } /* Repeat until done */ while (!done) { int ni = 0; int ne = 0; /* Scan windows */ for (j = 0; j < Misc.ANGBAND_TERM_MAX; j++) { /* Unused */ if (Misc.angband_term[j] == null) { continue; } /* Count windows displaying inven */ if ((Player.Player_Other.instance.window_flag[j] & (Misc.PW_INVEN)) != 0) { ni++; } /* Count windows displaying equip */ if ((Player.Player_Other.instance.window_flag[j] & (Misc.PW_EQUIP)) != 0) { ne++; } } /* Toggle if needed */ if (((Misc.p_ptr.command_wrk == Misc.USE_EQUIP) && ni != 0 && ne == 0) || ((Misc.p_ptr.command_wrk == Misc.USE_INVEN) && ni == 0 && ne != 0)) { /* Toggle */ Command_Info.toggle_inven_equip(); /* Track toggles */ toggle = !toggle; } /* Redraw */ Misc.p_ptr.redraw |= (Misc.PR_INVEN | Misc.PR_EQUIP); /* Redraw windows */ Misc.p_ptr.redraw_stuff(); /* Viewing inventory */ if (Misc.p_ptr.command_wrk == Misc.USE_INVEN) { /* Redraw if needed */ if (show_list) { show_inven(olist_mode); } /* Begin the prompt */ out_val = "Inven:"; /* List choices */ if (i1 <= i2) { /* Build the prompt */ tmp_val = String.Format(" {0}-{1},", index_to_label(i1), index_to_label(i2)); /* Append */ out_val += tmp_val; } /* Indicate ability to "view" */ if (!show_list) { out_val += " * to see,"; Button.button_add("[*]", '*'); } /* Indicate legality of "toggle" */ if (use_equip) { out_val += " / for Equip,"; Button.button_add("[/]", '/'); } /* Indicate legality of the "floor" */ if (allow_floor) { out_val += " - for floor,"; Button.button_add("[-]", '-'); } } /* Viewing equipment */ else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP) { /* Redraw if needed */ if (show_list) { show_equip(olist_mode); } /* Begin the prompt */ out_val = "Equip:"; /* List choices */ if (e1 <= e2) { /* Build the prompt */ tmp_val = String.Format(" {0}-{1},", index_to_label(e1), index_to_label(e2)); /* Append */ out_val += tmp_val; } /* Indicate ability to "view" */ if (!show_list) { out_val += " * to see,"; Button.button_add("[*]", '*'); } /* Indicate legality of "toggle" */ if (use_inven) { out_val += " / for Inven,"; Button.button_add("[/]", '/'); } /* Indicate legality of the "floor" */ if (allow_floor) { out_val += " - for floor,"; Button.button_add("[!]", '!'); } } /* Viewing floor */ else { /* Redraw if needed */ if (show_list) { show_floor(floor_list, floor_num, olist_mode); } /* Begin the prompt */ out_val = "Floor:"; /* List choices */ if (f1 <= f2) { /* Build the prompt */ tmp_val = String.Format(" {0}-{1}", Basic.I2A(f1), Basic.I2A(f2)); /* Append */ out_val += tmp_val; } /* Indicate ability to "view" */ if (!show_list) { out_val += " * to see,"; Button.button_add("[*]", '*'); } /* Append */ if (use_inven) { out_val += " / for Inven,"; Button.button_add("[/]", '/'); } /* Append */ else if (use_equip) { out_val += " / for Equip,"; Button.button_add("[/]", '/'); } } Misc.p_ptr.redraw_stuff(); /* Finish the prompt */ out_val += " ESC"; /* Build the prompt */ tmp_val = String.Format("({0}) {1}", out_val, pmt); /* Show the prompt */ Utilities.prt(tmp_val, 0, 0); /* Get a key */ which = Utilities.inkey(); /* Parse it */ switch (which.code) { case keycode_t.ESCAPE: { done = true; break; } case (keycode_t)'/': { /* Toggle to inventory */ if (use_inven && (Misc.p_ptr.command_wrk != Misc.USE_INVEN)) { Misc.p_ptr.command_wrk = Misc.USE_INVEN; } /* Toggle to equipment */ else if (use_equip && (Misc.p_ptr.command_wrk != Misc.USE_EQUIP)) { Misc.p_ptr.command_wrk = Misc.USE_EQUIP; } /* No toggle allowed */ else { Utilities.bell("Cannot switch item selector!"); break; } /* Hack -- Fix screen */ if (show_list) { /* Load screen */ Utilities.screen_load(); /* Save screen */ Utilities.screen_save(); } /* Need to redraw */ break; } case (keycode_t)'-': { /* Paranoia */ if (!allow_floor) { Utilities.bell("Cannot select floor!"); break; } /* There is only one item */ if (floor_num == 1) { /* Auto-select */ if (Misc.p_ptr.command_wrk == (Misc.USE_FLOOR)) { /* Special index */ k = 0 - floor_list[0]; /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } } /* Hack -- Fix screen */ if (show_list) { /* Load screen */ Utilities.screen_load(); /* Save screen */ Utilities.screen_save(); } Misc.p_ptr.command_wrk = (Misc.USE_FLOOR); //#if 0 // /* Check each legal object */ // for (i = 0; i < floor_num; ++i) // { // /* Special index */ // k = 0 - floor_list[i]; // /* Skip non-okay objects */ // if (!get_item_okay(k)) continue; // /* Allow player to "refuse" certain actions */ // if (!get_item_allow(k, cmdkey, is_harmless)) continue; // /* Accept that choice */ // (*cp) = k; // item = true; // done = true; // break; // } //#endif break; } case (keycode_t)'0': case (keycode_t)'1': case (keycode_t)'2': case (keycode_t)'3': case (keycode_t)'4': case (keycode_t)'5': case (keycode_t)'6': case (keycode_t)'7': case (keycode_t)'8': case (keycode_t)'9': { /* Look up the tag */ if (!get_tag(ref k, (char)which.code, cmd, quiver_tags)) { Utilities.bell("Illegal object choice (tag)!"); break; } /* Hack -- Validate the item */ if ((k < Misc.INVEN_WIELD) ? !allow_inven : !allow_equip) { Utilities.bell("Illegal object choice (tag)!"); break; } /* Validate the item */ if (!get_item_okay(k)) { Utilities.bell("Illegal object choice (tag)!"); break; } /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } case (keycode_t)'\n': case (keycode_t)'\r': { /* Choose "default" inventory item */ if (Misc.p_ptr.command_wrk == Misc.USE_INVEN) { if (i1 != i2) { Utilities.bell("Illegal object choice (default)!"); break; } k = i1; } /* Choose the "default" slot (0) of the quiver */ else if (quiver_tags) { k = e1; } /* Choose "default" equipment item */ else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP) { if (e1 != e2) { Utilities.bell("Illegal object choice (default)!"); break; } k = e1; } /* Choose "default" floor item */ else { if (f1 != f2) { Utilities.bell("Illegal object choice (default)!"); break; } k = 0 - floor_list[f1]; } /* Validate the item */ if (!get_item_okay(k)) { Utilities.bell("Illegal object choice (default)!"); break; } /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } default: { bool verify; /* Note verify */ verify = (Char.IsUpper((char)which.code) ? true : false); /* Lowercase */ which.code = (keycode_t)Char.ToLower((char)which.code); /* Convert letter to inventory index */ if (Misc.p_ptr.command_wrk == Misc.USE_INVEN) { k = label_to_inven((char)which.code); if (k < 0) { Utilities.bell("Illegal object choice (inven)!"); break; } } /* Convert letter to equipment index */ else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP) { k = label_to_equip((char)which.code); if (k < 0) { Utilities.bell("Illegal object choice (equip)!"); break; } } /* Convert letter to floor index */ else { k = (Char.IsLower((char)which.code) ? Basic.A2I((char)which.code) : -1); if (k < 0 || k >= floor_num) { Utilities.bell("Illegal object choice (floor)!"); break; } /* Special index */ k = 0 - floor_list[k]; } /* Validate the item */ if (!get_item_okay(k)) { Utilities.bell("Illegal object choice (normal)!"); break; } /* Verify the item */ if (verify && !verify_item("Try", k)) { done = true; break; } /* Allow player to "refuse" certain actions */ if (!get_item_allow(k, cmdkey, is_harmless)) { done = true; break; } /* Accept that choice */ cp = k; item = true; done = true; break; } } } /* Fix the screen if necessary */ if (show_list) { /* Load screen */ Utilities.screen_load(); /* Hack -- Cancel "display" */ show_list = false; } /* Kill buttons */ Button.button_kill('*'); Button.button_kill('/'); Button.button_kill('-'); Button.button_kill('!'); Misc.p_ptr.redraw_stuff(); /* Forget the item_tester_tval restriction */ Misc.item_tester_tval = 0; /* Forget the item_tester_hook restriction */ Misc.item_tester_hook = null; /* Toggle again if needed */ if (toggle) { Command_Info.toggle_inven_equip(); } /* Update */ Misc.p_ptr.redraw |= (Misc.PR_INVEN | Misc.PR_EQUIP); Misc.p_ptr.redraw_stuff(); /* Clear the prompt line */ Utilities.prt("", 0, 0); /* Warning if needed */ if (oops && str != null) { Utilities.msg("{0}", str); } /* Result */ return(item); }
/* Add inscription */ public static void inscribe(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //object_type *o_ptr = object_from_item_idx(args[0].item); //o_ptr.note = quark_add(args[1].string); //p_ptr.notice |= (PN_COMBINE | PN_SQUELCH | PN_SORT_QUIVER); //p_ptr.redraw |= (PR_INVEN | PR_EQUIP); }
/* * Find the "first" inventory object with the given "tag". * * A "tag" is a char "n" appearing as "@n" anywhere in the * inscription of an object. * * Also, the tag "@xn" will work as well, where "n" is a tag-char, * and "x" is the action that tag will work for. */ static bool get_tag(ref int cp, char tag, Command_Code cmd, bool quiver_tags) { int i; /* (f)ire is handled differently from all others, due to the quiver */ if (quiver_tags) { i = Misc.QUIVER_START + tag - '0'; if (Misc.p_ptr.inventory[i].kind != null) { cp = i; return (true); } return (false); } /* Check every object */ for (i = 0; i < Misc.ALL_INVEN_TOTAL; ++i) { Object o_ptr = Misc.p_ptr.inventory[i]; /* Skip non-objects */ if (o_ptr.kind == null) continue; /* Skip empty inscriptions */ if (o_ptr.note == null) continue; /* Find a '@' */ string[] tags = o_ptr.note.ToString().Split('@'); int tagat = 0; //strchr(quark_str(o_ptr.note), '@'); /* Process all tags */ while (tagat < tags.Length) { string s = tags[tagat++]; /* Check the normal tags */ if (s[0] == tag) { /* Save the actual inventory ID */ cp = i; /* Success */ return (true); } /* Check the special tags */ if ((Command.lookup(s[1]) == cmd) && (s[2] == tag)) { /* Save the actual inventory ID */ cp = i; /* Success */ return (true); } /* Find another '@' */ //s = strchr(s + 1, '@'); } } /* No such tag */ return (false); }
/* * Holds a generic command - if cmd is set to other than CMD_null * it simply pushes that command to the game, otherwise the hook * function will be called. */ public Command_Info() { desc = ""; key = '\0'; cmd = Command_Code.NULL; }
public Command_Info(string desc, char key, Command_Code cmd, hook_func hook = null, prereq_func prereq = null) { this.desc = desc; this.key = key; this.cmd = cmd; if(hook != null) { this.hook = hook; } if(prereq != null) { this.prereq = prereq; } }
/* Drop an item */ public static void drop(Command_Code code, cmd_arg[] args) { throw new NotImplementedException(); //int item = args[0].item; //object_type* o_ptr = object_from_item_idx(item); //int amt = args[1].number; //if(!item_is_available(item, null, USE_INVEN | USE_EQUIP)) { // msg("You do not have that item to drop it."); // return; //} ///* Hack -- Cannot remove cursed items */ //if((item >= INVEN_WIELD) && cursed_p(o_ptr.flags)) { // msg("Hmmm, it seems to be cursed."); // return; //} //inven_drop(item, amt); //p_ptr.energy_use = 50; }