Class Faction
Methods
faction:init (data) | Initiate a faction from its definition. |
faction:get_name () | Returns the faction's name |
faction:get_description () | Returns the faction's description |
faction:is_enemy (creature) | Determine if a creature is an enemy of the faction. |
faction:is_friend (creature) | Determine if the faction considers a creature a friend or not. |
faction:join (creature) | Have a creature become a member of the faction. |
faction:leave (creature) | Have a creature leave as a member of the faction. |
faction:can_join (creature) | Test if a creature can become a member of the faction. |
faction:teach_spell (spellID, creature) | Have a creature learn a spell from a faction. |
faction:teach_skill (skillID, creature) | Have a creature learn a skill from a faction. |
faction:generate_items () | Generates the faction's inventory |
faction:select_missions () | Select missions to offer, if there's a limit |
faction:restock () | Restocks the faction's inventory. |
faction:add_item (item, info) | Adds an item to the faction store. |
faction:get_inventory () | Gets a list of the items the faction is selling |
faction:get_count (item) | Gets the numbers of items this faction has in its current inventory that matches a passed item |
faction:get_buy_list (creat) | Gets a list of the items that a creature can sell to a faction |
faction:get_sell_cost (item) | Determines the cost the faction will sell the item for |
faction:get_buy_cost (item) | Determines if a faction will buy an item, and returns the price if so |
faction:creature_sells_item (item, info, moneyCost, favorCost, reputationCost, amt, creat) | Sell an item to the faction |
faction:creature_buys_item (item, info, moneyCost, favorCost, amt, creat) | Buy an item from the faction |
faction:get_inventory_index (item) | Gets the index within the faction's inventory of the item in question |
faction:get_possible_random_items () | Get all possible random items the faction can stock |
faction:generate_random_item (list, info., artifact_chance, enchantment_chance, noAdd) | Generate a random item from the faction's possible random items list |
faction:generate_gifts (items) | Generates a gift from the faction |
faction:get_possible_gift_items () | Get all possible gift items the faction can offer |
faction:get_cost_modifier (creature) | Gets the modifier for items sold in the faction store |
faction:get_teachable_spells (creature) | Gets the list of spells the faction can teach a given creature |
faction:get_teachable_skills (creature) | Gets the list of skills the faction can teach a given creature |
faction:get_available_services (creature) | Gets the list of services the faction can offer a given creature |
faction:get_available_missions (creature, ignoreCurrent.) | Gets the list of missions the faction can teach a given creature |
faction:get_recruitable_creatures (creature) | Gets the list of creatures the faction offers for recruitment |
faction:recruit (recruitData, creature) | Recruits a creature from a faction |
faction:process_incident (incidentID, actor, target, args) | Registers an incident as having occured, to be processed by all other creatures who observe it |
Methods
- faction:init (data)
-
Initiate a faction from its definition. You shouldn't use this function, the game uses it at loadtime to instantiate the factions.
Parameters:
- data Table. The table of faction data.
Returns:
-
self Faction. The faction itself.
- faction:get_name ()
-
Returns the faction's name
Returns:
-
Text. The name
- faction:get_description ()
-
Returns the faction's description
Returns:
-
Text. The description
- faction:is_enemy (creature)
-
Determine if a creature is an enemy of the faction.
Parameters:
- creature Creature. The creature to test for enmity.
Returns:
-
Boolean. Whether the creature is an enemy or not.
- faction:is_friend (creature)
-
Determine if the faction considers a creature a friend or not.
Parameters:
- creature Creature. The creature to test for friendship.
Returns:
-
Boolean. Whether the creature is a friend or not.
- faction:join (creature)
-
Have a creature become a member of the faction.
Parameters:
- creature Creature. The creature that's joining. (optional, defaults to the player)
- faction:leave (creature)
-
Have a creature leave as a member of the faction.
Parameters:
- creature Creature. The creature that's leaving. (optional, defaults to the player)
- faction:can_join (creature)
-
Test if a creature can become a member of the faction.
Parameters:
- creature Creature. The creature that's a potential applicant. (optional, defaults to the player)
Returns:
- Boolean. Whether the creature can join or not.
- String. Details on why the creature can't join. (nil if they can join)
- faction:teach_spell (spellID, creature)
-
Have a creature learn a spell from a faction.
Parameters:
- spellID String. The ID of the spell they're trying to learn.
- creature Creature. The creature learning the spell. (optional, defaults to the player)
Returns:
-
Boolean. Whether learning the spell was successful or not.
- faction:teach_skill (skillID, creature)
-
Have a creature learn a skill from a faction.
Parameters:
- skillID String. The ID of the skill they're trying to learn.
- creature Creature. The creature learning the skill. (optional, defaults to the player)
Returns:
-
Boolean. Whether learning the skill was successful or not.
- faction:generate_items ()
- Generates the faction's inventory
- faction:select_missions ()
- Select missions to offer, if there's a limit
- faction:restock ()
- Restocks the faction's inventory. Default behavior: Restock all defined items up to their original amount, unless restock_amount or restock_to is set.
- faction:add_item (item, info)
-
Adds an item to the faction store. If the store already has this item, increase the amount
Parameters:
- item Item. The item to add
- info Table. The information to pass
- faction:get_inventory ()
-
Gets a list of the items the faction is selling
Returns:
-
Table. The list of items the faction has in stock
- faction:get_count (item)
-
Gets the numbers of items this faction has in its current inventory that matches a passed item
Parameters:
- item Item. The item to count.
Returns:
-
Number. The number of items
- faction:get_buy_list (creat)
-
Gets a list of the items that a creature can sell to a faction
Parameters:
- creat Creature. The creature selling. Optional, defaults to the player
Returns:
-
Table. The list of items the player can sell, each of which is another table in the format {item=Item,cost=Number}
- faction:get_sell_cost (item)
-
Determines the cost the faction will sell the item for
Parameters:
- item Item. The item to consider
Returns:
-
Table. With moneyCost and favorCost values
- faction:get_buy_cost (item)
-
Determines if a faction will buy an item, and returns the price if so
Parameters:
- item Item. The item to consider
Returns:
-
False or Number. False if the faction won't buy it, the price if it will
- faction:creature_sells_item (item, info, moneyCost, favorCost, reputationCost, amt, creat)
-
Sell an item to the faction
Parameters:
- item Item. The item being sold
- info Table. A table of information passed by the faction screen. Can include the following:
- moneyCost Number. The amount of money the faction will pay per item
- favorCost Number. The amount of favor the faction will pay per item
- reputationCost Number. The amount of reputation the faction will pay per item
- amt Number. The amount of the item being sold. Optional, defaults to 1
- creat Creature. The creature selling. Optional, defaults to the player
- faction:creature_buys_item (item, info, moneyCost, favorCost, amt, creat)
-
Buy an item from the faction
Parameters:
- item Item. The item being sold
- info Table. A table of information passed by the faction screen. Can include the following:
- moneyCost Number. The amount of money the faction is charging per item.
- favorCost Number. The amount of favor the faction is charging per item.
- amt Number. The amount of the item being sold. Optional, defaults to 1.
- creat Creature. The creature selling. Optional, defaults to the player.
Returns:
-
Boolean, Text/nil. True and nil if the buying was successful, False and a string if there's a reason the buying didn't go through.
- faction:get_inventory_index (item)
-
Gets the index within the faction's inventory of the item in question
Parameters:
- item Item. The item to seach for.
Returns:
-
Number. The index ID of the item.
- faction:get_possible_random_items ()
-
Get all possible random items the faction can stock
Returns:
-
Table. A list of the item IDs
- faction:generate_random_item (list, info., artifact_chance, enchantment_chance, noAdd)
-
Generate a random item from the faction's possible random items list
Parameters:
- list Table. A list of item IDs to pull from. Optional, defaults to the list from get_possible_random_items()
- info. Table. A table of potential values including:
- artifact_chance Number.
- enchantment_chance Number.
- noAdd Boolean. If true, don't add the item to inventory
- faction:generate_gifts (items)
-
Generates a gift from the faction
Parameters:
- items Table. The items to give
- faction:get_possible_gift_items ()
-
Get all possible gift items the faction can offer
Returns:
-
Table. A list of the item IDs
- faction:get_cost_modifier (creature)
-
Gets the modifier for items sold in the faction store
Parameters:
- creature
- faction:get_teachable_spells (creature)
-
Gets the list of spells the faction can teach a given creature
Parameters:
- creature Creature. Optional, defaults to player
Returns:
-
Table. A list of possible spells
- faction:get_teachable_skills (creature)
-
Gets the list of skills the faction can teach a given creature
Parameters:
- creature Creature. Optional, defaults to player
Returns:
-
Table. A list of possible skills
- faction:get_available_services (creature)
-
Gets the list of services the faction can offer a given creature
Parameters:
- creature Creature. Optional, defaults to player
Returns:
-
Table. A list of possible services
- faction:get_available_missions (creature, ignoreCurrent.)
-
Gets the list of missions the faction can teach a given creature
Parameters:
- creature Creature. Optional, defaults to player
- ignoreCurrent. Optional, if true ignore the current_missions table
Returns:
-
Table. A list of possible missions
- faction:get_recruitable_creatures (creature)
-
Gets the list of creatures the faction offers for recruitment
Parameters:
- creature Creature. Optional, defaults to player
Returns:
-
Table. A list of possible recruits
- faction:recruit (recruitData, creature)
-
Recruits a creature from a faction
Parameters:
- recruitData Table. The recruitment data
- creature Creature. The creature doing the recruiting
- faction:process_incident (incidentID, actor, target, args)
-
Registers an incident as having occured, to be processed by all other creatures who observe it
Parameters:
- incidentID String. The incident type
- actor Entity. The creature (or other entity) that caused the incident. Optional
- target Entity. The entity (or coordinates), that was the target of the incident. Optional
- args Table. Other information to use when processing this incident