Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPCs keep track of total sales #51388

Merged
merged 1 commit into from
Sep 5, 2021
Merged

Conversation

eltank
Copy link
Contributor

@eltank eltank commented Sep 5, 2021

Summary

Infrastructure "NPCs keep track of total sales"

Purpose of change

This change makes trading NPCs keep track of the total value of everything you ever sold to them.
This sales value can be used in dialogue scripts for dynamic lines and conditional dialogue. It can also be modified via dialogue.
Primarily intended for the new merchant Rubik, but can probably be used to unlock some new options with the Free Merchants as well (#51320).

Describe the solution

Add sold to npc_opinion, stored in npc::op_of_u.
Modify the "Edit NPC" debug menu to show this value and allow changing it.
Update op_of_u.sold in trading_window::update_npc_owed using trading_window::your_sale_value (also introduced in this PR; computed in trading_window::perform_trade).
Add talker::sold() and talker::add_sold() and implement them in talker_npc similar to debt() and add_debt().
Add code to handle "sold" in the "u_val" handler in condition.cpp.
And some code cleanup related to npc_opinion.

Describe alternatives you've considered

Implementing u_have_sold as a special condition similar to u_are_owed. However, that's much less flexible in terms of possible comparison operations and doesn't allow modification. [Edit: I just realized that I'm using features that were recently added in #50305. This would not have been possible more than 2 weeks ago. Thanks, @Light-Wave!]

Testing

Modified the Refugee Center merchant json:

    "responses": [
      { 
        "text": "Can I get a discount?",
        "topic": "TALK_DONE",
        "condition": { "compare_int": [ { "u_val": "sold" }, { "const": 1000 } ], "op": ">=" }
      },
      { 
        "text": "Forget I ever sold you anything!",
        "topic": "TALK_NONE",
        "effect": { "arithmetic": [ { "u_val": "sold" }, { "const": 0 } ], "op": "=" },
        "condition": { "compare_int": [ { "u_val": "sold" }, { "const": 0 } ], "op": ">" }
      },
...
  {
    "id": "TALK_EVAC_MERCHANT",
    "type": "talk_topic",
    "dynamic_line": { "compare_int": [ { "u_val": "sold" }, { "const": 1000 } ], "op": ">=", "yes": "Welcome, big spender…", "no": "Welcome…" }
  },

patch.txt

Teleported to the Refugee Center. Traded 1 Hub01 coin for 1 pipe bomb.
Debug menu for the merchant shows:
image

The conversation changes to:
image

After selecting the option to forget the sale:
image

Additional context

Add `sold` to NPC `op_of_u`
Add dialog support for reading/writing this value through `"u_val":
"sold"`
@eltank eltank changed the title NPCs keep track of sales value NPCs keep track of total sales Sep 5, 2021
@BrettDong BrettDong added the NPC / Factions NPCs, AI, Speech, Factions, Ownership label Sep 5, 2021
@eltank
Copy link
Contributor Author

eltank commented Sep 5, 2021

Tagging in @I-am-Erk

@kevingranade kevingranade merged commit aae81f0 into CleverRaven:master Sep 5, 2021
@Theawesomeboophis
Copy link
Contributor

Awesome addition, although I usually just steal everything they have and kill them anyways. Great work.

@eltank eltank deleted the npc_sold_var branch September 8, 2021 06:01
Venera3 pushed a commit to Venera3/Cataclysm-DDA that referenced this pull request Sep 21, 2021
Add `sold` to NPC `op_of_u`
Add dialog support for reading/writing this value through `"u_val":
"sold"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants