Crea uses an event system to allow for actions to be listened to and provide custom logic.
All events use the GameEvent
interface which we will go over some below.
While all events share the same interface, they are used in many places.
Global game events are used with game.events which is technically an EventComponent
.
This allows for new events to be added easily and listened to by name.
game.events['player_respawn'].invoke(player)
# elsewhere...
game.events['player_respawn'].listen(player)
The EventComponent is an actual component that can be added to any Entity
and consequently any entity can invoke and listen to events on itself.
This is used for many things such as when an entity is interacted with it uses the event ‘interact’.
entity.event['interact'].listen(self.interact)
Sometimes a GameEvent
is used directly. This is typically for when a system or component has a specific event it wants to invoke.
Such as in the ResearchComponent at mods/core/component/research.py we use a GameEvent for when a new item is discovered.
self.onDiscovered = GameEvent()
# Elsewhere in ResearchComponent
self.onDiscovered.invoke(content.id)
# Somewhere completely different we can listen to this.
entity.research.onDiscovered.listen(self.handleDiscovered)
The GameEvent
interface is fairly straight-forward with GameEvent.listen()
and GameEvent.invoke()
being the two most important functions.
When listening to an event it is important to ensure the event handler signature properly matches the arguments that are provided to the event’s invoke.
Note
The return value from an event handler tells the GameEvent if it should remove the handler or not. Return True to remove the handler or return nothing to keep it.
def playerCreated(player):
player.entity.inventory.addBag(0, PlayerTuning.STARTING_BAG_SIZE)
def register():
game.events["player_created"].listen(playerCreated)
def unregister():
game.events["player_created"].remove(playerCreated)
You’ll see we also need to call GameEvent.remove()
when we are done with it. This is especially important with global events when Game.onUnregistration()
is invoked.
Note
Always be sure to remove an event when it is no longer needed!
auri_tree_grown
(entity)¶Called when an Auri tree becomes fully grown.
Parameters: | entity (Entity) – The Auri tree entity. |
---|
backup_saves
(*paths)¶Called when saved file(s) need to be backed up. This only happens once per session when the game is exiting.
Parameters: | paths – An arbitrary argument list of paths. |
---|
character_saved
(player)¶Called when a player character has been saved to disk.
Parameters: | player (Player) – The player that was just saved. |
---|
client_input_ready
(client)¶Called when a player’s input has been initialized. This can be used to manipulate the input such as adding new core.system.input.InputStateHandler.
Parameters: | client (core.system.input.ClientInput) – The client input that is now ready. |
---|
control_change
(controllerType, name, controlCode)¶Called when a control input value is changed.
Parameters: |
|
---|
create_realm
(realm)¶Called when a realm has been created. This includes realms created during load.
Parameters: | realm (Realm) – The newly created realm. |
---|
create_talent
(talent)¶Called when a talent is being created for a player.
Parameters: | talent (Talent) – The newly created talent. |
---|
crystal_activated
(player, travelPlayer, self.crystals[uid])¶Called when a Way Crystal has been activated by a player.
Parameters: |
|
---|
damage_item
(entity, isDestroyed)¶Called when a placed item has been damaged (being collected).
Parameters: |
|
---|
dropped_collected
(entity, item)¶Called when a player collects a dropped item.
Parameters: | entity (Entity) – The Player entity that collected the dropped item. |
---|---|
Para InventoryItem item: | |
The dropped item that was collected. |
dropped_expired
(realm, entity)¶Called when a dropped item has expired and will be removed.
Parameters: |
---|
exit_game
()¶Called when the game is being exited by the window being closed.
gather_tile
(player, tileComponent, entity, tilePosition)¶Called when a tile is being gathered by a player.
Parameters: |
|
---|
hit_tile
(entity, realm, tileComponent, tileLayer.type, tilePosition, brokeTile)¶Called when an entity hits a tile to harvest it.
Parameters: |
|
---|
load_biomes
(biomes)¶Called when requesting all possible biomes to use during world generation. Append new biomes to the provided list.
Parameters: | biomes (list) – Empty list for which Biome instances should be added. |
---|
merchant_wares
(wares, daily)¶Called when the merchant wares have been setup. These lists may be modified but cannot exceed core.tuning.NpcTuning.MERCHANT.MAX_WARES and core.tuning.NpcTuning.MERCHANT.MAX_DAILY.
Parameters: |
|
---|
npc_price_notice
()¶Called when the NPC prices should be recalculated. NPC prices are calculated in mods.core.npc.getNpcPrice().
obsidian_created
(realm, tilePosition, waterAmount, lavaAmount)¶Called when obsidian is created by having water and lava mix.
Parameters: |
|
---|
pause_change
(isPaused)¶Called when the game’s paused state changes.
Parameters: | isPaused (bool) – If the game is paused now or not. |
---|
perform_physics
(entities, timestepTime)¶Called when a physics step is about to be performed on a set of entities.
Parameters: |
|
---|
placed_entity
(entity)¶Called when an entity is placed down with PlacementHandler.createPlacement()
.
Parameters: | entity (Entity) – The entity that was just placed. |
---|
player_created
(player)¶Called when a new character has been created through character creation.
Parameters: | player (Player) – The newly created player. |
---|
player_joined
(player)¶Called immediately when a player joins the world before the player has fully loaded.
Parameters: | player (Player) – The player who just joined. |
---|
player_left
(player)¶Called when a player leaves the world.
Parameters: | player (Player) – The player who just left. |
---|
player_ready
(player)¶Called on the server when it has been notified that the client has received all data for their character. This should be used when needing to send data to client’s that is dependent on the player data.
Parameters: | player (Player) – The player that has just joined and is ready. |
---|
player_respawn
(player)¶Called when a player has finished respawning at their attuned crystal.
Parameters: | player (Player) – The player that has finished respawning. |
---|
player_revive
(player)¶Called when a player is revived at their fallen position.
Parameters: | player (Player) – The player that was just revived. |
---|
player_spawn
(player)¶Called when a player has finished joining the game and has spawned in the world.
Parameters: | player (Player) – The player that just joined. |
---|
populate_treasure
(player, chest, groups)¶Called when a treasure chest is about to be populated with loot.
Parameters: |
|
---|
registration_finished
()¶Called after game registration has completely finished. This means all mods have registered and should be initialized.
setup_body
(template, identifier)¶Called when a body content is nearly finished being setup. This allows for manipulation on the body content before it is finalized.
Parameters: |
|
---|
tick
()¶Called when the game ticks is triggered. This occurs every 3 seconds.
tile_changed
(tileLayer, position, previousId, tileId)¶Called when a tile has changed.
Parameters: |
|
---|
world_created
(world)¶Called when the world has been created. This includes when a world is being loaded or connected to.
Parameters: | world (World) – The created world. |
---|
world_loaded
(world)¶Called when the world has finished loading and all systems are ready.
Parameters: | world (World) – The loaded world. |
---|
Some events are invoked to support handlers changing the state of things. This is achieved with core.helper.callEvent() which provides a special interface for this.
callEvent
(eventName, player, *args, **kwargs)¶Invokes the named event for both the player entity (player.entity.events[eventName]) as well as a global event (game.event[eventName]). Any provided keyword arguments are automatically packed up into a core.helper.AttrDict (results) which is passed to the event handlers and returned. Values in results can be modified by other handlers so prefer it over the the provided argument unless you want to use the original value.
The event handlers resulting signature is: handler(player, results, *args, **kwargs)
Parameters: |
|
---|---|
Returns: | The results that was passed to the event handlers containing the keyword arguments. |
Return type: | core.helper.AttrDict |
Note
Remember that all handlers need to include results in the signature!
accuracy_check
(player, attacker, target, accuracy=accuracy, evasion=evasion)¶Called to support accuracy and evasion being manipulated before the accuracy is fully calculated.
Parameters: |
---|
apply_damage
(player, target, origin, damage=damage, isCritical=isCritical, knockback=knockback)¶Called when damage is about to be applied to an entity.
Parameters: |
|
---|---|
Param int knockback: | |
The amount of knockback the attack has. |
can_hit_tile
(player, tileComponent, tilePosition, canHit=canHit)¶Called when checking to see if a player can hit a tile.
Parameters: |
|
---|
completed_dungeon
(player, dungeon)¶Called when a player has completed exploring through an entire dungeon.
Parameters: |
|
---|
craft_adjust_catalyst
(player, chaosCraft, amount=amount)¶Called when the catalyst amount is being modified during chaos crafting.
Parameters: |
|
---|
craft_adjust_chaos
(player, chaosCraft, amount=amount)¶Called when the chaos amount is being modified during chaos crafting.
Parameters: |
|
---|
craft_adjust_quality
(player, chaosCraft, amount=amount)¶Called when the quality amount is being modified during chaos crafting.
Parameters: |
|
---|
craft_finish
(player, craft, quantity, result, item, remainder)¶Called when a player finishes crafting an item.
Parameters: |
|
---|
craft_quality
(player, craft, quality=quality, maxQuality=maxQuality)¶Called to support quality and max quality of crafting items to be manipulated.
Parameters: |
|
---|
craft_start
(player, craft, quantity, materials)¶Called when starting to craft an item.
Parameters: |
|
---|
deal_critical_damage
(player, attacker, target, data, isCritical=isCritical, criticalFactor=criticalFactor)¶Called when calculating if an attack should be critical or not.
Parameters: |
|
---|
deal_damage_end
(player, attacker, target, data, isCritical, damage)¶Called at the end of calculations when the attacker about to deal damage to the target.
Parameters: |
|
---|
deal_damage_start
(player, attacker, target, data)¶Called at the start of calculations when the attacker about to deal damage to the target.
Parameters: |
---|
deal_damage
(player, attacker, target, data, isCritical, damage=damage)¶Called towards the end of calculations when the attacker about to deal damage to the target. This supports the amount of damage being changed.
Parameters: |
|
---|
descent_damage
(player, damage=damage)¶Called when a player will take fall damage.
Parameters: |
|
---|
done_casting
(player, talent, skillTuning, cost=cost)¶Called when a player finishes casting a skill.
Parameters: |
---|
drop_rate_modifier
(player, entity, modifier=modifier)¶Called when calculating the drop rate modifier for a defeated enemy.
Parameters: |
|
---|
enter_dungeon
(player, dungeon)¶Called when a player has entered a dungeon.
Parameters: |
|
---|
exit_dungeon
(player, dungeon)¶Called when a dungeon is exited regardless of how.
Parameters: |
|
---|
gain_tp
(player, talent, amount=amount)¶Called when a player will gain talent points.
Parameters: |
---|
gain_xp
(player, amount=amount)¶Called when a player will gain experience points.
Parameters: |
|
---|
get_research_level
(player, craftLevel, bonus=bonus)¶Called when calculating the player’s current research level.
Parameters: |
---|
harvest_power
(player, toolComponent, power=power)¶Called when calculating the player’s harvest power.
Parameters: |
|
---|
heal_entity
(player, user, target, amount=amount)¶Called when an entity is about to be healed.
Parameters: |
---|
get_hunter_level
(player, skillTuning, level=level)¶Called to support changing the hunter skill level (Ore Hunter or Treasure Hunter).
Parameters: |
|
---|
kill_entity
(player, attacker, target, data, damage, isCritical)¶Called when an entity is killed by an attack.
Parameters: |
|
---|
npc_price
(player, npc, price=price)¶Called when calculating the price of an item an npc is selling.
Parameters: |
|
---|
on_block
(player, attacker, target, shieldProficiency, reduction=reduction, threshold=threshold, staminaCost=staminaCost)¶Called when an entity blocks an attack.
Parameters: |
|
---|
on_jump
(player, jumpSpeed=jumpSpeed)¶Called when a player jumps.
Parameters: |
|
---|
on_land
(player)¶Called when the player lands on the ground.
Parameters: | player (Player) – The player landing on the ground. |
---|
on_roll
(player, cost=cost)¶Called when a player performs a dodge roll.
Parameters: |
|
---|
on_sp_recovery
(player, time=time)¶Called when a player stamina recovery timer will be reset. Upon expiration the player will begin recovering stamina.
Parameters: |
|
---|
ore_drop
(player, droppedPosition=droppedPosition, scavengeLevel=scavengeLevel)¶Called when a player has destroyed an ore tile using a tool.
Parameters: |
---|
player_death
(player, damageSource, message=message)¶Called when a player is killed.
Parameters: |
|
---|
research_item_scraps
(player, content, scrapAmount=scrapAmount)¶Called when the player researches an item using scraps.
Parameters: |
---|
research_recipe
(player, content)¶Called when a new recipe has been learned through researching.
Parameters: |
---|
skill_interrupt
(player, skillTuning, interrupt=interrupt)¶Called when the player skill casting will be interrupted.
Parameters: |
|
---|
start_chaos_craft
(player, item, maxCatalysts=maxCatalysts, skills=skills, passives=passives)¶Called when a player starts chaos crafting.
Parameters: |
|
---|
tool_power
(player, toolComponent, power=power)¶Called when calculating a tool’s power.
Parameters: |
|
---|
translate_scroll
(player, content)¶Called when the player translates a recipe scroll.
Parameters: |
---|
travel_cost
(player, travelPlayer, travelCrystal, cost=cost)¶Called when calculating the Way Shard cost to travel to a Way Crystal.
Parameters: |
|
---|
Below is a list of entity events that are triggered if supported.
can_collect
(player, canCollect)¶When provided this will allow a placed item to provide logic on when it can or cannot be collected.
Parameters: |
|
---|
can_place_item
(player, entity, item, canPerform)¶When provided this checks to see if an item can be place in or on an entity.
Parameters: |
|
---|
can_remove_support
(entity, realm, tileLayer, tilePosition, shouldCancel)¶When provided this will be called when an attempt to remove a tile is made nearby the entity.
Parameters: |
|
---|
close
(player, entity)¶Called when an entity with inventory is closed such as a player closing a treasure chest.
Parameters: |
---|
clothe
(player, entity, position)¶Called when an NPC outfit is being placed onto a mannequin.
Parameters: |
---|
collect
(player, entity, position)¶Called when a player attempts to collect an item. This is for special cases such as removing individual crafting station attachments.
Parameters: |
---|
interact
(player, entity, position)¶Called when a player interacts with an entity.
Parameters: |
---|
place_item
(player, entity, position)¶Called when a player places an item in or on an entity. Use player.grabbed.item (ToolItem
) for the item being placed.
Parameters: |
---|
remove_support
(entity, realm, tileLayer, tilePosition, forced, shouldCancel)¶Called when the player is about to remove a tile that the entity is using as support.
Parameters: |
|
---|
use_gadget
(player, realm, entity, position)¶Called when a player uses a gadget.
Parameters: |
---|
Below is a list of events that are directly called on the player’s EventComponent
.
cast_spell
(spellTuning)¶Called when the player casts a spell.
Parameters: | spellTuning (core.helper.AttrDict) – The tuning data for the spell (See core.tuning.skill). |
---|
claim_imbue_output
(item)¶Called when the player claims the output item from an imbuing chamber.
Parameters: | item (InventoryItem) – The output item. |
---|
completed_horde_realm
(realm)¶Called when the player completes a horde realm.
Parameters: | realm (Realm) – The horde realm that the player completed. |
---|
deal_damage_invisible
(target, data, isCritical, damage)¶Called when the player deals damage to a target while invisible.
Parameters: |
|
---|
equip_craft_station
(entity, unequippedItem, item)¶Called when the player equip an item on a crafting station.
Parameters: |
|
---|
expertise_level
(level)¶Called when the player’s Expertise skill level is changed.
:param int level The current Expertise level.
grabbed_enemy
(player, hook, grapplerData, enemies)¶Called when the player grabs an entity with a grappling hook.
Parameters: |
|
---|
realm_change
(player, previousRealm, realm)¶Called when the player traveling to another realm.
Parameters: |
---|
use_delay
(itemEntity, delay)¶Called when the player uses an item and the player’s use delay timer is about to be set.
Parameters: |
---|
Below is a list of events that are called on pieces of equipment. All equipment attributes can be found in core.item.armor.attribute module.
charged
(player, itemEntity, equipmentSlot, clientInput, inputType, position)¶Called on the item with a ChargedAttackAttribute when it is being charged.
Parameters: |
|
---|
final_combo
(player, itemEntity)¶Called on the item when it performs the last attack in its attack combo.
Parameters: |
---|
hit_ally
(player, target, itemEntity, entity)¶Called when a wand projectile hits an ally.
Parameters: |
---|
post_weapon_use
(player, itemEntity)¶Called after a weapon is used.
Parameters: |
---|