Skip to content

Instantly share code, notes, and snippets.

@Ruin0x11
Created July 12, 2020 03:03
Show Gist options
  • Save Ruin0x11/7690069d967be8221c230b3d53f69e62 to your computer and use it in GitHub Desktop.
Save Ruin0x11/7690069d967be8221c230b3d53f69e62 to your computer and use it in GitHub Desktop.
invctrl ops

invctrl ops

NOTE: on_item_selected and on_filter must be extracted as separate components. This is to allow shortcuts.

1 - general inventory (“X”)

properties

  • Supports tagging as no-drop.

on_filter

  • Include items on chara.
  • Include items on the ground.
  • Include equipped items.
  • Permit own_state 5.
  • Permit harvest items.

when item is chosen after filter

  • Sort equipped items first, but after items on ground.

on_item_selected

  • Display item description. Jump back to start.
    • vanilla re-runs filtering after this, but it may not be necessary now.

keybinds

  • x: mark no-drop

2 - dropping

properties

  • If multidrop disabled, supports enabling multidrop.

on_filter

  • Include items on chara.
  • Permit harvest items.

on_item_selected

  • Fail if item is no-drop.
  • Fail if map is full (technical limitation).
  • Fail if map is full (declared item limit on map) and category != 60000 (furniture).
  • If number of items > 1, ask how many items to drop. If canceled, fail.
  • Drop the item.
  • If multi-drop is on, don’t exit the menu. Else, exit the menu as turn_end.

keybinds

  • x: turn on multidrop

on_menu_exit

  • If multidrop enabled, return turn_end.

3 - picking up multiple

on_draw

  • Do not distinguish items on ground.

on_filter

  • Include items on the ground.
  • Reject items on chara.

after sorting

  • Return turn_end if no items.

on_item_selected

  • Permit if item is no-drop.
  • Fail if item not owned/harvested.
  • Query amount if mode is 6 and number > 1. If canceled, fail.
  • Try to move the item to the player/chara’s inventory.
    • NOTE: This needs to stop the inventory menu and return turn_end if harvesting and picking up succeeded.
  • Try to move the item to the player/chara’s inventory.

5 - eating

properties

  • Supports shortcuts.

on_filter

  • Include items on chara.
  • Include items on the ground.
  • Include equipped items.
  • Remove if item type != 57000 (food) and type != 91000 (traveler’s food) and item material is not raw.

on_item_selected

  • Fail if item is no-drop.
  • Fail if nutrition > 10000.
  • Try to eat the item. Return the result.

6 - equipping

on_filter

  • Include items on chara.
  • Remove if item is equipped.

on_item_selected

  • Fail if player has the fairy trait and the item is too heavy.
  • Equip the item. (always succeeds)
  • Control jumps back to calling equipment menu.

before_menu_exit

  • Control jumps back to equipment menu. (no-op)

7 - reading

properties

  • Supports shortcuts.

on filter

  • Include items on chara.
  • Include items on the ground.
  • Remove if item is not readable.
  • If map is a world map:
    • Remove if subcategory != 53100 (deed) and item is not treasure map.

on_item_selected

  • Try to read the item. Return the result.

8 - drinking

properties

  • Supports shortcuts.

on filter

  • Include items on chara.
  • Include items on the ground.
  • Remove if item is not drinkable.

on_item_selected

  • Try to drink the item. Return the result.

9 - zapping

properties

  • Supports shortcuts.

on filter

  • Include items on chara.
  • Include items on the ground.
  • Remove if item is not zappable.

on shortcut

  • Fails if in world map.

on_item_selected

  • Try to zap the item. Return the result.

10 - giving/taking ally items (invally = 1)

on_filter

  • Include items on chara.

on_item_selected

  • Fail if item is no-drop.
  • Fail if target is sleeping.
  • Fail if target’s inventory is full.
  • Run the ally item giving logic. Depending on the result, continue the menu or return turn_end (or similar).

11 - shop buying (uses tc?, invfile = cdata[tc].shop_store_id)

on_draw

  • Subtext is price.
  • Do not distinguish items on ground. (temporary inventory)

on filter

  • Include items on the ground. (actually the temp inventory loaded in)
  • Reject items on chara. (inventory is not on chara, it is in tempinv)
  • Show money.
  • Everything from shop selling.
  • Remove if item is gold piece or platinum coin.
  • If item is on ground:
    • Permit if item position differs from character position.

on_item_selected

  • Fail if item is no-drop.
  • Fail if item not owned/harvested.
  • Query amount if mode is 6 and number > 1. If canceled, fail.
    • Also print buying amount message.
  • Prompt if mode == 6 and is configured. If no, fail.
    • Also print buying prompt.
    • Fail if player/chara doesn’t have enough money.
  • Try to move the item to the player/chara’s inventory.
    • If failed, print player’s inventory is full. (usual case)
    • Update some expiration if food. (on_sell_to_shop)
if (inv[ti].param3 != 0 && inv[ti].material == 35)
{
    inv[ti].param3 = game_data.date.hours() +
        the_item_db[inv[ti].id]->expiration_date;
    if (inv[ti].param2 != 0)
    {
        inv[ti].param3 += 72;
    }
}
  • On success, print message/play sound/modify gold.
    • If item is cargo, calc value.
if (the_item_db[inv[ti].id]->category == 92000)
{
    inv[ti].param2 = calcitemvalue(ti, 0);
}
  • Gain negotiation experience.

before_menu_exit

  • Load shoptemp.

12 - shop selling (uses tc?)

on_draw

  • Subtext is price.

on filter

  • Include items on chara.
  • Show money.
  • If user is trading cargo:
    • Remove if item weight >= 0 (not-cargo indication).
    • Remove if type is not 92000 (cargo).
  • Else:
    • Remove if item weight < 0 (cargo indication) and item type is 92000 (cargo).
  • Remove if item value <= 1.
  • Remove if item is precious.
  • Remove if item.param3 < 0.
  • Remove if item quality is special.

on_item_selected

  • Character using becomes -1.
  • Fail if item is no-drop.
  • Fail if item not owned/harvested.
  • Query amount if mode is 6 and number > 1. If canceled, fail.
    • Also print selling amount message.
  • Prompt if mode == 6 and is configured. If no, fail.
    • Also print selling prompt.
    • Fail if shopkeeper doesn’t have enough money and shopkeeper role is not cargo trader.
  • Try to move the item to the player/chara’s inventory.
    • If failed, print shopkeeper’s inventory is full.
    • On success, print message/play sound/modify gold.
      • Logic differs if item is stolen.
    • Gain negotiation experience.
if (!inv[ti].is_stolen())
{
    txt(i18n::s.get(
        "core.locale.action.pick_up.you_sell", itemname(ti, in)));
}
else
{
    inv[ti].is_stolen() = false;
    txt(i18n::s.get(
        "core.locale.action.pick_up.you_sell_stolen",
        itemname(ti, in)));
    if (game_data.guild.thieves_guild_quota > 0)
    {
        game_data.guild.thieves_guild_quota -= sellgold;
        if (game_data.guild.thieves_guild_quota < 0)
        {
            game_data.guild.thieves_guild_quota = 0;
        }
        txt(i18n::s.get(
            "core.locale.action.pick_up.thieves_guild_quota",
            game_data.guild.thieves_guild_quota));
    }
}

before_menu_exit

  • Load shoptemp.

13 - identifying

on filter

  • Include items on chara.
  • Include items on the ground.
  • Include equipped items.
  • Remove if item is completely identified.

when item is chosen after filter

  • Sort equipped items first, but after items on ground.

on_item_selected

  • Try to identify. Print a message depending on the result.
  • Stack the item.
  • Return success.

14 - using

properties

  • Supports shortcuts.

on filter

  • Include items on chara.
  • Include items on the ground.
  • Include equipped items.
  • Permit own_state 5.
  • Remove if item is not usable and item is not alive.

on_item_selected

  • Try to use the item. Return the result.

15 - opening

properties

  • Supports shortcuts.

on filter

  • Include items on chara.
  • Include items on the ground.
  • Remove if type is not 72000 (container) or is not one of the following.
    • deck

on shortcut

  • Fails if in world map.

on_item_selected

  • Try to open the item. Return the result.

16 - cooking

on filter

  • Include items on chara.
  • Remove if type is not 57000 (food).
  • Remove if item is already cooked (item.param2 != 0).

on_item_selected

  • Return success. (?)

17 - dipping

on filter

  • Include items on chara.
  • Include items on the ground.
  • Remove if type is not 52000 (bottle of liquid) or is not one of the following.
    • bait

on_item_selected

  • Save selected item.
  • Push inventory context 18 (dipping target).

18 - dipping target

chained from 17

on filter

  • Include items on chara.
  • Include items on the ground.
  • Include equipped items.
  • If dipping item is bait:
    • Remove if target is not fishing pole.
  • Remove if target is the same as the current dipping item.
  • Remove if the target is bottle of water.

on menu enter

  • Print I18N formatted message with dipping item name.

on_item_selected

  • Try to dip dipping target into item. Return result.

19 - offering

on filter

  • Include items on chara.
  • Include items on the ground.
  • Remove if item cannot be offered to god.

after filter

  • Fail if no altar in player inventory or on ground.

on_item_selected

  • Fail if item is no-drop.
  • Try to offer item. Return result.

20 - trading

on filter

  • Set inventory to target chara.
  • Include equipped items.
  • Remove if item is gold piece or platinum coin.

on_item_selected

  • Save selected item.
  • Push inventory context 21 (trading target).

21 - trading target

chained from 20

on filter

  • Include items on chara.
  • Remove if item isn’t valuable enough for trading.
    • (item.value * item.number < trade.value * trade.number / 2 * 3)
  • Remove if item is stolen.

when no items

  • Display message and fail.

on menu enter

  • Print I18N formatted message with trading item name.

on_item_selected

  • Fail if item is no-drop.
  • Clear target character’s continuous action.
  • Run trading logic. Return success.

22 - take from container

on_draw

  • Do not distinguish items on ground. (temp inventory)

on_filter

  • Include items on the ground. (temp inventory)
  • Reject items on chara. (temp inventory)
  • If item is on ground:
    • Permit if item position differs from character position.

on_item_selected

  • Permit if item is no-drop.
  • Fail if item not owned/harvested.
  • Do not query amount. Amount becomes equal to item.number.
  • Try to move the item to the player/chara’s inventory.
    • Update some expiration if food. (on_sell_to_shop).
      • Same as shop selling.
      • However, logic is different in sub 3.
    • Play sound/print message.

before_menu_exit

  • Load shoptemp.

sub 0 - boxes/casino (invfile = inv[ci].param1)

  • invsubroutine 1: casino

before_menu_exit

  • If item count > 0, prompt leaving leftover items.

sub 1 - inheritance chest

on_filter

  • Delete cards and figures from the container.

on_item_selected

  • Fail if no inheritance claim.
  • On success, decrement rights to succeed to and print message.

sub 2 - general container? (invsubroutine = 1)

sub 3 - cooler box/general container (inv[ci].param1 == 6)

  • When successfully moved item:
    • Update some expiration if food. (on_take_from_container)
if (inv[ti].param3 > 0)
{
    inv[ti].param3 += game_data.date.hours();
}

sub 4 - strange scientist rewards

on_item_selected

  • On success, increment gift count of little sister quest and return success.

sub 5 - four dimensional pocket

on_item_selected

  • Fail if player does not have at least 10 SP.

23 - equipment

on_filter

  • Include items on chara.
  • Include equipped items.

sub 0 - general

(scroll of name, scroll of change material)

on filter

  • Remove if type >= 50000 (non-equipment) and type != 60000 (furniture).

sub 1 - weapons

(scroll of enchant weapon)

on filter

  • Remove if type != 10000 (melee weapon) and type != 24000 (ranged weapon)

sub 2 - armor

(scroll of enchant armor)

on filter

  • Remove if (type < 12000 (helm) or type >= 24000 (ranged)) and (type < 30000 (ring) or type >= 50000 (non-equipment))

sub 3 - fill charge

on filter

  • Remove if item does not have charge.

sub 4 - alchemy

on filter

  • Remove if item is equipped.

on_item_selected

  • Fail if item is no-drop.
  • Separate one item off stack.
  • Return success.

sub 5 - draw charge

on filter

  • Remove if type != 56000 (wands).

sub 6 - flying

on filter

  • Remove if item weight <= 0.
  • Remove if item is cooler box.

sub 7 - garok’s hammer

on filter

  • Remove if item quality is miracle or greater.
  • Remove if type >= 50000 (non-equip).

24 - put into container

on filtering

  • Include items on chara.
  • Remove if type is 72000 (containers).

on_item_selected

  • Move item into item’s inventory.
  • Play sound/print message.

sub 0 - master’s delivery chest

on filtering

  • If current map is Lumiest:
    • (Guild logic) Update quota.
  • Else:
    • (Harvest quest) Update quest data.
  • Remove item. Continue menu.

after filtering

  • If current map is Lumiest:
    • (Guild logic) Fail if no quota.

on_menu_open

  • Print current guild quota. (was checked for >= 0 earlier)

on_item_selected

  • If current map is Lumiest:
    • (Guild logic) Remove if item is not ancient book or it is not decoded.
  • Else:
    • (Harvest quest) Remove if item is not harvested.

sub 2 - tax master’s tax box

on filtering

  • Remove if item is not bill.
  • Remove if own state is 4 (being harvested). [unnecessary]

on_item_selected

  • Character using becomes -1.
  • Fail if not enough money as listed on selected bill.
  • Fail if no bills are outsanding.
  • Decrement gold and left bills.
  • Decrement item count.
  • Continue menu.

sub 3 - cooler box/general container

on filtering

  • Remove if type is not 57000 (seed/herb).

on_item_selected

  • Character using becomes -1.
  • Fail if item is no-drop.
  • Fail if container is full.
  • Fail if item not owned/harvested.
  • Query amount if mode is 6 and number > 1. If canceled, fail.
  • Try to move the item to the item’s inventory.
    • On success, update expiration.
if (inv[ti].param3 > 0)
{
    inv[ti].param3 = inv[ti].param3 - game_data.date.hours();
}

sub 5 - four dimensional pocket

on_item_selected

  • Fail if item is no-drop.
  • Fail if container is full.
  • Fail if container is too heavy (based on efp).
  • Fail if item is cargo.
  • Fail if player does not have at least 10 SP.
  • Fail if item not owned/harvested.
  • Query amount if mode is 6 and number > 1. If canceled, fail.
  • Try to move the item to the item’s inventory.

sub 8 - deck

on filtering

  • Remove if item is not card.
  • Remove if item is not owned.
  • Remove if item doesn’t have a character (subname).
  • Remove if card is already collected in global collection.

on_item_selected

  • Character using becomes -1.
  • Put card in deck.
  • Decrement item number.
  • Continue menu.

25 - take from ally inventory

on_draw

  • Hides player’s total weight note.
  • Draws ally body parts.

on_filter

  • Set inventory to target chara.
  • Show money.
  • Include equipped items (on target chara).

on_item_selected

  • Fail if player’s inventory is full.
  • Fail with refusal if category is 77000 (ore).
  • Fail if item is cursed and equipped.
  • If wedding ring/band, decrement and continue menu.
  • If gold piece, set number to item number. Else, set number to 1.
  • Copy and transfer item to player. Stack item. Convert artifact.
  • Make ally wear most valuable equipment.
  • Refresh chara.
  • Refresh PCC.
  • Continue menu.

26 - throwing

properties

  • Supports shortcuts.

on filtering

  • Include items on chara.
  • Include items on the ground.
  • Remove if type is not 52000 or is not one of the following items.
    • kitty bank
    • monster ball
    • little ball
    • tomato
  • Remove if item is monster ball and it is not empty (subname != 0)

on shortcut

  • Fails if in world map.

on_item_selected

  • Fail if target cannot be seen/route cannot be calculated.
  • Fail if target location is blocked. (FOV usually counts the target cell as unblocked even if solid)
  • Try to throw item. Return result.

27 - stealing (uses tc)

on_draw

  • Do not distinguish items on ground. (either from chara or ground but not both)

on filtering

  • Add items from inventory of chara standing on target position.
  • Skip entirely if target chara is player or nonexistent.
  • Include items on the ground.
  • Include equipped items.
  • Show money.
  • Remove if on ground and own state is not 1.
  • When item is on ground:
    • Remove if item position is not the same as targeting position.

when no items

  • Display message and fail.
    • If there is a target selected.
    • If there is no target selected (items on square).

after filtering

  • Fail if target is selected and target is ally.

on_item_selected

  • Start stealing continuous action.
  • Return success.

(skill_shortcut / 10000): run skill shortcut (invsc = skill_shortcut % 10000)

28 - buying with small medals

on_draw

  • Subtext is medal cost.
  • Do not distinguish items on ground. (temp inv)

on_filter

  • Reject items on chara. (temp inv)
  • If item is on ground: (temp inv)
    • Permit if item position differs from character position.

when item is chosen after filter

  • Set sort value to the item’s value in medals

on_menu_open

  • Print message with number of small medals in player inventory (or 0)

on_item_selected

  • Fail if player’s inventory is full.
  • Fail if not enough medals.
  • Subtact medals. Copy item. Convert artifact.
  • Continue menu.

before_menu_exit

  • Load shoptemp.

The Law of (Inventory) Cycles

The available actions in the inventory menu are dynamic depending on the context. This gets hard to support. There may be a need to pass the target of an action like stealing/chest opening to more than one menu context. Also the “drop” action is not mutually exclusive with the ones requiring a container and the ones that don’t, due to the temporary inventory system.

0 - General

1 (general) 2 (drop) 5 (eat) 7 (read) 8 (drink) 9 (zap) 14 (use) 15 (open) 17 (dip) 26 (throw)

1 - World map

1 (general) 5 (eat) 7 (read) 8 (drink) 14 (use)

2 - Ally

10 (give/take ally items) 25 (ally body parts)

3 - invcontainer > 0

22 (take from chest) 24 (put into chest)

4 - Multidrop

2 (drop) 2

Special item handling

when item is chosen after filter

  • music disc: sort by BGM number in addition to type/ID

Shortcuts

  • Item to use is applied AFTER filtering. If it can be found in the player’s inventory but was filtered out, the game assumes it was an item that couldn’t be used in the global map (scrolls).
    • To support, probably best to give a filtering API to get the list of items an inventory filter would apply if the screen were opened. Currently shortcuts are tied to the massive ctrl_inventory function.
    • Shortcuts have to save the inventory context used to reapply the filter when the shortcut is ran. The shortcuts are tied to the invctrl they were set in.

invfile

3: inheritance chest 4: income box 6: cooler box/container 8: four dimensional pocket (other): shop id/shopkeeper’s trunk/inv[ci].count

invcontainer

maximum items that can be stored

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment