intficpy.actor module

class intficpy.actor.Actor(game, name)

Bases: intficpy.thing_base.Thing

Actors are Things that are capable of conversations.

Topics can be added using the addTopic method. SpecialTopics are added using the addSpecialTopic method.

Actors track their available topics in dictionaries, depending on topic type. Each Actor has a dicitonary for ask_topics, tell_topics, give_topics, and show_topics, to which Topic objects can be added, as well as a special_topics dictionary for SpecialTopics.

All topics that are currently in these dictionaries are considered to be active, and will be available in converstions.

Actors can also buy and sell items. This can be enabled by adding an item using the addSelling or addWillBuy methods.

Items the Actor is willing to sell or buy are stored in the for_sale and will_buy dictionaries on the Actor object. More specifically, objects of the SaleItem class are stored here, serving as records of what is for sale/what is wanted, and templates for the transactions.

If you need to access a SaleItem created by addSelling/addWillBuy, you can look it up in the Actor’s for_sale or will_buy dictionary. The key is the IFPObject index of the relevant Thing, which can be found in the Thing’s ix attribute. For example, if an Actor person sells a Thing called item, we can look up the SaleItem with person.for_sale[item.ix].

Parameters
  • game (IFPGame) – the current game

  • name (str) – a single noun to use as the Actor’s initial name (synonyms/adjectives/ full_name can be customized after initialization)

addSelling(item, currency, price, stock)

Add an item that the Actor sells.

Parameters
  • item (Thing) – the Thing for sale (by the unit)

  • currency (Thing) – Thing to offer in exchange (use currency.copyThing() for duplicates)

  • price (int) – the number of the currency Things required

  • stock (int or True) – the number of a given Thing the Actor has to sell (set to True for infinite)

addSpecialTopic(topic)

Add a SpecialTopic for this Actor. This will immediately add it to the available suggestions for the Actor.

Parameters

topic (SpecialTopic) – the SpecialTopic to add

addTopic(ask_tell_give_show, topic, thing)

Adds a conversation topic (ask/tell/give/show) to the Actor.

Parameters
  • ask_tell_give_show (str) – specifies one or more conversation verbs (ask, tell, give, and/or show) to which the actor should respond with the specified topic, when the direct object is the specified thing. For every substring “ask”, “tell”, “give” and “show” present in this string, the Topic will be registered under the corresponding topic category for the given Thing. For instance, passing in “ask show” for this parameter will cause the Topic to be saved as both an ask topic, (“ask selena about rice”) and a show topic (“show selena rice”) Ordering of ask/tell/give/show in the string does not matter.

  • topic (Topic) – the Topic you want to add to the Actor

  • thing (Thing) – the Thing you want to associate the Topic to, ie. what you want to ask about, tell about, or give, or show to the Actor

addWillBuy(item, currency, price, max_wanted)

Add an item that the Actor is willing to buy.

Parameters
  • item (Thing) – the Thing the Actor wishes to purchase (by the unit)

  • currency (Thing) – the Thing the Actor will offer in exchange (by the unit)

  • price (int) – the number of the currency Things the Actor will give for a single unit of the item

  • max_wanted (int or True) – the number of a given Thing the Actor is willing to buy (set to True for infinite)

defaultTopic(game)

Called when the Actor’s default topic is triggered. Prints the default_topic text, and the current SpecialTopic suggestions.

Parameters

game (IFPGame) – the current game

makeLying()

Set the Actor’s position to lying

makeProper(proper_name)

Give this character a proper name. Updates has_proper_name as well as name, full_name, synonyms, and adjectives for this Actor based on the new name given. The intended use is to facilitate having the player character “learn” the initially unknown name of another character.

Parameters

proper_name (str) – the name of this character

makeSitting()

Set the Actor’s position to sitting

makeStanding()

Set the Actor’s position to standing

printSuggestions(game)

Print the suggestions for this all of this Actor’s current SpecialTopics in the format, “(You could {suggestion)”.

Parameters

game (IFPGame) – the current game

removeAllSpecialTopics()

Clear all SpecialTopics from this Actor. This removes all conversation suggestions. The SpecialTopic objects will remain unchanged, and can be added back later.

removeAllTopics()

Clear all ask/tell/give/show Topics from this Actor. The Actor will no longer have responses to being asked or told about anything, or to being given or shown anything. The Topic objects will remain unchanged, and can be added back later.

removeHermitTopic()

Remove the Actor’s hermit topic, if there is one. Equivalent to setting some_actor.hermit_topic = None

removeSpecialTopic(topic)

Remove the specified SpecialTopic from this Actor. The SpecialTopic will no longer appear in the Actor’s conversation suggestions.

Parameters

topic (SpecialTopic) – the SpecialTopic to remove

setHermitTopic(hermit_topic)

Set a hermit topic for this Actor. While the hermit topic is set, it will be the only response the Actor gives to any conversation.

Parameters

hermit_topic (Topic) – the topic to set as the Actor’s hermit topic

setHiTopics(hi_topic, return_hi_topic)

Set the hi topics for this Actor. Sets both the initial greeting, and the greeting to show at the start of subsequent interactions. To make both greetings the same, pass in the same Topic for both.

Parameters
  • hi_topic (Topic, None) – the Topic to open when the player first talks to this Actor None skips directly to the topic at hand.

  • return_hi_topic (Topic, None) – the Topic to open when the the player uses “hi” or “talk to” after having previously interacted with the Actor. None skips directly to the topic at hand.

POSITION_STATE_DESC_KEY = 'position_state_desc'
property contains_desc

Return an empty string. We do not want to describe an actor’s inventory on room/examine desc.

property is_current_player

Is this Actor the current player character?

Return type

bool

property position_state_desc

A description of an Actor’s position (standing, lying, etc.), to be appended to that Actor’s description in the room. Standing is assumed to be default, and is not specially described.

Return type

str

property verb_to_be

Get the simple present tense of the verb “to be” for this Actor. Returns “is” unless the Actor is the current player (i.e. “you”), in which case it returns “are”.

Return type

str

property verbose_name

The name the game will use to describe this Actor to the player. Returns “you” if this Actor is currently the player character, otherwise defaults to the logic from the superclass.

Return type

str

class intficpy.actor.Player(game)

Bases: intficpy.actor.Actor

A playable Actor.

Currently, the game only supports a single player character.

Parameters

game (IFPGame) – the current game

setPlayer()

Add some default synomyms for this Player object that players are likely to try to use to refer to their character

property default_desc

Describe this Player in the room. By default, the Player is not described in the room description.

Return type

str

property default_xdesc

The base description of the Player, if a description has not been specified.

Return type

str

class intficpy.actor.SaleItem(game, item, currency, price, number)

Bases: intficpy.ifp_object.IFPObject

Stores information about an Actor’s ability to sell a particular item to the player, or buy a particular item from the player. SaleItems are created automatically by the Actor methods addSelling and addWillBuy, and game creators should not generally need to create them manually.

Once created, SaleItems can be accessed in the Actor’s for_sale and will_buy dictionaries by looking up the ix of the Thing in question.

Parameters
  • game (IFPGame) – the current game

  • item (Thing) – the item the Actor sells

  • currency (Thing) – the item the Actor expects to receive in return, as currency

  • price (int) – the number of the currency item required to purchase 1 of the item for sale

  • number (int or True) – the number of the item the Actor has in stock (True for infinite)

afterBuy(game)

Override this to trigger behaviour after a unit of the item is bought.

Parameters

game (IFPGame) – the current game

afterSell(game)

Override this to trigger behaviour after the player sells a unit of the item.

Parameters

game (IFPGame) – the current game

beforeBuy(game)

Override this to trigger behaviour before a unit of the item is bought.

Parameters

game (IFPGame) – the current game

beforeSell(game)

Override this to trigger behaviour before the player sells a unit of the item.

Parameters

game (IFPGame) – the current game

boughtAll(game)

Override this to trigger behaviour when the Actor has bought all of the item that they are willing to buy.

Parameters

game (IFPGame) – the current game

buyUnit(game)

Buy one unit of the item for sale.

Removes the needed amount of currency from the player’s inventory, adds the purchased item, and prints the interaction messages to the turn.

Parameters

game (IFPGame) – the current game

sellUnit(game)

Sell one unit of the item for sale.

Removes the item from the player’s inventory, adds the needed amount of currency, and prints the interaction messages to the turn.

Parameters

game (IFPGame) – the current game

soldOut(game)

Override this to trigger behaviour when the item sells out.

Parameters

game (IFPGame) – the current game

class intficpy.actor.SpecialTopic(game, suggestion, topic_text)

Bases: intficpy.actor.Topic

A SpecialTopic is is a Topic accessed by responding to a printed suggestion during conversation, instead of through the use of the ask/tell/give/show verbs.

A SpecialTopic can be added to an Actor using Actor.addSpecialTopic

Parameters
  • game (IFPGame) – the current game

  • suggestion (str) – the prompt or suggestion that will lead the player to this SpecialTopic

  • topic_text (str) – the text that should print when this Topic is opened

addAlternatePhrasing(phrasing)

Add a possible alternate phrasing for this suggestion. Alternate phrasings will not be printed to the user.

Parameters

phrasing (str) – the alternate phrasing to add

class intficpy.actor.Topic(game, topic_text)

Bases: intficpy.ifp_object.IFPObject

Topic represents a topic in conversation.

Topic (base) is meant to be added to an Actor as an ask/tell/give/show topic - a conversation topic that is triggered when a player asks about, tells about, shows, or gives a Thing or Abstract.

As well as printing text, a Topic can add and remove SpecialTopics from its Actor when it is triggered. Set SpecialTopics to add to the Actor by adding the SpecialTopic objects to the Topic’s new_suggestions. Add them to expire_suggestions to remove them.

The Topic itself contains no reference to any Thing or Abstract to which a given Actor will associate it. This connection is created when the Topic is added to the Actor with addTopic, and then, exists only on the Actor object. This means that the same Topic can be added as a response to multiple things.

A single Topic should not be added to multiple Actors at the same time, as this will break suggestion functionality.

Parameters
  • game (IFPGame) – the current game

  • topic_text (str) – the text that should print when this Topic is opened

func(game, suggest=True)

What happens when this Topic is opened. Prints the topic text and suggestions to the turn.

Parameters
  • game (IFPGame) – the current game

  • suggest (bool, optional) – should we print the current suggested SpecialTopics?

on_trigger(game)

Override this to add custom behaviour when the Topic function runs

Parameters

game (IFPGame) – the current game

update_suggestions()

Read this Topic’s new_suggestions and expire_suggestions, and add/remove SpecialTopic suggestions from the Actor as needed.