Package pajammin :: Package entity :: Package agent :: Module agent :: Class Agent
[show private | hide private]
[frames | no frames]

Type Agent

object --+    
         |    
    Entity --+
             |
            Agent

Known Subclasses:
Avatar, Flyer, Walker

A 'character' in the world. The Agent class defines the basic attributes and properties that all agents share. Subclasses of Agent, such as walker.Walker and flyer.Flyer, are used to add support for performing different sets of actions. These are subclassed further to define specific agent types, such as walker.GreenTurtle or flyer.RedBird.

Each agent is characterized by a basic set of attributes which describe the agent's current state:

In addition, each agent has a number of "fixed" properties affect the agent and its behavior. Normally, the values for these properties are taken from class variables defined by Agent subclasses. However, the class defaults can be temporarilly overridden by instance variables when the agent is affected by an Effect, such as a buff or a magical spell.

By default, an agent will be represented on the display with a single sprite, whose category is defined by the class variable sprite_category. Subclasses must define the method current_animation(), which is used to determine which of the sprite's animations to display.

However, subclasses of Agent may choose to handle their own sprite display; to do so, they should set sprite_category to None, and override the methods update_animation(), play_animation(), and icon().
Method Summary
  __init__(self, x, y)
Create a new agent at the given position.
  add_effect(self, effect)
Apply a temporary change to the "fixed" properties of this agent.
  attack(self, attack_type, **attack_args)
  current_animation(self)
Return a tuple (basename, speed), indicating the animation name and the animation speed that should be used by this agent's sprite, based on the agent's current state.
  icon(cls)
(Class method)
  is_hostile(self, agent)
Return true if this agent is hostile to the given agent.
  play_animation(self, basename, speed)
Change the agent's sprite to display the animation with the given basename, for the duration of the animation (just one time through, if the animation normally loops).
  register(cls)
(Class method)
  remove_effect(self, *effects_to_remove)
Cancel one or more temporary changes to the "fixed" properties of this agent.
  say(self, text, duration)
Say something...
  update(self, duration)
Update the current state of this agent.
  update_animation(self)
Update the animation mode and speed of this agent's sprite(s), based on the agent's state.
    Actions
  heal(self, health)
Increase the health of this agent by the given amount.
  hurt(self, damage, damage_type)
Cause the given amount of damage to this agent.
  die(self)
Cause the agent to die.
    Inherited from Entity
  __repr__(self)
  add_body(self, body)
  add_sprite(self, sprite)
  after(self, duration, callback, *params, **kwparams)
After the given duration has elapsed, call the given callback function.
  handle_collision(self, obstacle, side)
Called when one of the entity's bodies collides with another body.
  handle_lose_support(self, old_support)
Called when one of the entity's bodies becomes unsupported.
  handle_movement(self, dx, dy)
Called when one of the entity's bodies moves.
  remove_body(self, body)
  remove_sprite(self, sprite)
  use(self)
Define this method for entities that the avatar can 'use'.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
Return hash(x)...
  __new__(T, S, ...)
Return a new object with type S, a subtype of T...
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
Return str(x)...

Property Summary
  bottom: The y coordinate of the bottom side of the agent's body.
  center: The (x,y) position of the center of the agent's body.
  left: The x coordinate of the left side of the agent's body.
  right: The x coordinate of the right side of the agent's body.
  top: The y coordinate of the top side of the agent's body.
  x: The x coordinate of the center of the agent's body.
  y: The y coordinate of the center of the agent's body.
    Inherited from Entity
  bodies
  sprites

Instance Variable Summary
int mana_regen: The rate at which this agent regains its mana, in MP/sec.
    State Attributes
  health: The number of health points this agent currently has.
  mana: The number of mana points this agent currently has.
  body: The agent's body.
  facing: The direction that the agent is currently facing.
  effects: A list of the Effects (temporary changes to fixed properties) that are currently affecting this agent.
  attack_cooldown_timer: ...
    Fixed Properties
int health_max: The maximum number of health points this agent can have.
int health_regen: The rate at which this agent regains its health, in HP/sec.
int mana_max: The maximum number of mana points this agent can have.
dict resists: A dictionary describing the base amount that this agent resists each damage type.
bool is_mortal: Determines whether this agent dies when its health reaches zero.
int attack_speed: A modifier for the rate at which this agent can attack.
str faction: The name of the faction that this agent belongs to.
    Inherited from Entity
bool alive: A flag indicating whether the entity is alive or not.
  bodies = pajammin.entity.entity.Entity.bodies
NoneType level: A pointer to the level that contains this entity (if any).
  sprites = pajammin.entity.entity.Entity.sprites
NoneType update_delay: The amount of time that has elapsed since the last time update was called for this entity.

Class Variable Summary
dict attack_types: A dictionary describing the types of attack that agents in this class can make.
NoneType bbox_size: The default size of the bounding box for agents in this class.
list classes = [<class 'pajammin.entity.agent.flyer.WhiteBird...
int solid_sides: The sides of the agent's body which should be solid for agents in this class.
NoneType sprite_category: The sprite category that should be used to create this agent's sprite.
int update_interval: The interval at which entities in a given class should have its update function called.
    Inherited from Entity
bool autouse = False
bool is_usable = False

Instance Method Details

heal(self, health)

Increase the health of this agent by the given amount. The agent's health will be capped at its health_max.

Requires: health must be non-negative.

hurt(self, damage, damage_type=1)

Cause the given amount of damage to this agent. The damage amount will be modified based on the agent's resistances to the given damage type(s). If the agent's health goes below zero, and the agent is mortal, then the agent will die.

die(self)

Cause the agent to die. This can be overridden if an agent class needs to perform any special actions when it dies.

__init__(self, x, y)
(Constructor)

Create a new agent at the given position. The new agent's health and mana will be set to their maximum; and the direction it is facing will be randomly chosen between LEFT and RIGHT.
Overrides:
__builtin__.object.__init__

add_effect(self, effect)

Apply a temporary change to the "fixed" properties of this agent. If multiple effects change the same property, then they will be cascaded (in arbitrary order).

Any sprite associated with the new effect will be added to this agent's sprite list. When the effect expires or is explicitly removed, its change will be undone, and any sprite associated with it will be removed.
Parameters:
effect - An Effect object specifying what change should be applied to the agent.

attack(self, attack_type, **attack_args)

current_animation(self)

Returns:

A tuple (basename, speed), indicating the animation name and the animation speed that should be used by this agent's sprite, based on the agent's current state. The actual animation name will be formed by combining basename with a suffix indicating which direction the agent is facing, such as '_left' or '_down'.

This method must be defined by any subclass that does not handle its own sprite display.

is_hostile(self, agent)

Return true if this agent is hostile to the given agent. This is decided based on the two agent's factions: if one agent has the faction 'goodguy' and the other has the faction 'badguy,' then they are hostile to each other.

play_animation(self, basename, speed=1)

Change the agent's sprite to display the animation with the given basename, for the duration of the animation (just one time through, if the animation normally loops). The actual animation name will be formed by combining basename with a suffix indicating which direction the agent is facing, such as '_left' or '_down'. Once the specified animation is complete, the agent will resume using current_animation() to decide which animation to display.

remove_effect(self, *effects_to_remove)

Cancel one or more temporary changes to the "fixed" properties of this agent. Any sprites associated with the cancelled effects will be removed.

Cancelling an effect that does not currently apply to the agent has no effect. (In particular, it does not generate an error.)
Parameters:
effects_to_remove - A list of Effect object specifying what changes should be cancelled.

say(self, text, duration=None)

Say something...

update(self, duration)

Update the current state of this agent. This update function applies health & mana regeneration, and checks whether the agent's health or mana is at or below zero (taking appropriate actions if either is).
Overrides:
pajammin.entity.entity.Entity.update

update_animation(self)

Update the animation mode and speed of this agent's sprite(s), based on the agent's state. This method should be called any time the agent is modified in such a way that its animation mode or speed might need to change.

update_animation() uses current_animation() to decide which of the sprite's animations to display. The method play_animation() can also be used to temporarily override which animation is displayed.

Class Method Details

icon(cls)

Overrides:
__builtin__.type.icon

register(cls)


Property Details

bottom

The y coordinate of the bottom side of the agent's body.

center

The (x,y) position of the center of the agent's body.

left

The x coordinate of the left side of the agent's body.

right

The x coordinate of the right side of the agent's body.

top

The y coordinate of the top side of the agent's body.

x

The x coordinate of the center of the agent's body.

y

The y coordinate of the center of the agent's body.

Instance Variable Details

health

The number of health points this agent currently has. If this reaches zero, then the agent dies.

mana

The number of mana points this agent currently has.

body

The agent's body.

facing

The direction that the agent is currently facing. This is used to decide which direction attacks will go in. It is also used by subclasses to decide which sprite to use. It can be LEFT, RIGHT, TOP, or BOTTOM, or None. (Its initial value will be randomly chosen from LEFT and RIGHT.)

effects

A list of the Effects (temporary changes to fixed properties) that are currently affecting this agent.

attack_cooldown_timer

...

health_max

The maximum number of health points this agent can have.
Type:
int
Value:
100                                                                   

health_regen

The rate at which this agent regains its health, in HP/sec. This rate may be negative, to indicate a health drain.
Type:
int
Value:
0                                                                     

mana_max

The maximum number of mana points this agent can have.
Type:
int
Value:
0                                                                     

resists

A dictionary describing the base amount that this agent resists each damage type. In particular, any damage with type T will be multiplied by (100-resists.get(T,0))/100. Note that resist values may be negative, indicating that the agent is more succeptible to that type of damage. Warning: class variables are used to define default resistances; so if you want to modify an instance's resist values, be sure to make a new copy of the dictionary first!
Type:
dict
Value:
{}                                                                     

is_mortal

Determines whether this agent dies when its health reaches zero. If is_mortal is false, then the agent's health will be increased to 1 whenever it reaches 0.
Type:
bool
Value:
True                                                                   

attack_speed

A modifier for the rate at which this agent can attack. This modifier is multiplied by the agent's base attack speed values to decide how fast it actually attacks. If this is set to zero, then the agent is prevented from attacking.
Type:
int
Value:
1                                                                     

faction

The name of the faction that this agent belongs to. Can be 'goodguy', 'badguy', or 'neutral'.
Type:
str
Value:
'neutral'                                                              

mana_regen

The rate at which this agent regains its mana, in MP/sec. This rate may be negative, to indicate a mana drain.
Type:
int
Value:
0                                                                     

Class Variable Details

attack_types

A dictionary describing the types of attack that agents in this class can make. It maps from attack names to AttackType objects. [xx] should this be considered a fixed property? if so, then a spell or other effect could grant a new attack type to an agent; but it would have to be pretty specific... the agent's sprite would have to have the appropriate animations.
Type:
dict
Value:
{}                                                                     

bbox_size

The default size of the bounding box for agents in this class.
Type:
NoneType
Value:
None                                                                  

classes

Type:
list
Value:
[<class 'pajammin.entity.agent.flyer.WhiteBird'>,
 <class 'pajammin.entity.agent.flyer.BrownBird'>,
 <class 'pajammin.entity.agent.flyer.BlueBird'>,
 <class 'pajammin.entity.agent.flyer.RedBird'>,
 <class 'pajammin.entity.agent.flyer.Farie'>,
 <class 'pajammin.entity.agent.walker.RedBall'>,
 <class 'pajammin.entity.agent.walker.RedMoop'>,
 <class 'pajammin.entity.agent.walker.GreenMoop'>,
...                                                                    

solid_sides

The sides of the agent's body which should be solid for agents in this class.
Type:
int
Value:
0                                                                     

sprite_category

The sprite category that should be used to create this agent's sprite. This must be defined by each subclass, unless that subclass is handling its own sprite creation & display.
Type:
NoneType
Value:
None                                                                  

update_interval

The interval at which entities in a given class should have its update function called.
Type:
int
Value:
200