Module gameactor
[hide private]
[frames] | no frames]

Source Code for Module gameactor

 1  #!/usr/bin/python3 
 2  """ This module implements the GameActor class """ 
 3  from random import randint 
 4  from gameobject import GameObject 
 5  from gameaction import GameAction 
 6  from gamecontext import GameContext 
 7   
 8   
9 -class GameActor(GameObject):
10 """ 11 A GameActor (typically a PC or NPC) is an agent that has a 12 context and is capable of initiating and receiving actions. 13 """ 14
15 - def __init__(self, name="actor", descr=None):
16 """ 17 create a new GameActor 18 @param name: display name of this actor 19 @param descr: human description of this actor 20 """
21
22 - def _accept_attack(self, action, actor, context):
23 """ 24 Accept an attack, figure out if it hits, and how bad 25 @param action: (GameAction) being performed 26 @param actor: (GameActor) initiating the action 27 @param context: (GameContext) in which action is being taken 28 @return: (boolean, string) succewss and description of the effect 29 30 """
31 # get the victim's base and sub-type EVASION 32 # see if EVASION+D100 can beat the incoming TO_HIT 33 # get the recipient's base and sub-class PROTECTION 34 # see if PROTECTION can absorb all the incoming HIT_POINTS 35 # subtract received HIT_POINTS from our LIFE 36 # if LIFE<=0 we are incapacitated, and no longer alive 37
38 - def accept_action(self, action, actor, context):
39 """ 40 receive and process the effects of an ATTACK 41 (other actions are passed to our super-class) 42 43 A standard attack comes with at-least two standard attributes: 44 - TO_HIT ... the (pre defense) to-hit probability 45 - HIT_POINTS ... the (pre-armor) damage being delivered 46 47 1. use D100+EVASION to determine if attack hits 48 2. use PROTECTION to see how much damage gets through 49 3. update LIFE_POINTS 50 51 @param action: (GameAction) being performed 52 @param actor: (GameActor) initiating the action 53 @param context: (GameContext) in which action is being taken 54 @return: (boolean, string) description of the effect 55 """
56 # get the base action verb 57 # we handle ATTACK (based on HIT/DAMAGE vs EVASION/PROTECTION) 58 # otherwise let our (GameObject) super-class handle it 59
60 - def interact(self, actor):
61 """ 62 return a list of possible interactions (w/this GameActor) 63 64 @param actor: (GameActor) initiating the interactions 65 @return: Interaction object 66 67 GameObjects have a (ACTIONS) list of verbs that can be turned into 68 a list of the GameActions that they enable. 69 GameActors have a (INTERACTIONS) list of verbs that a requesting 70 GameActor can turn into interaction GameActions that can be 71 exchanged with that character. 72 73 The interaction object will have an ACTIONS attribute, 74 containing a comma-separated list of the supported interaction verbs 75 (which can be used to instantiate and deliver GameActions). 76 """
77
78 - def set_context(self, context):
79 """ 80 establish the local context 81 """
82
83 - def take_action(self, action, target):
84 """ 85 Initiate an action against a target 86 @param action: (GameAction) to be initiated 87 @param target: (GameObject) target of the action 88 @return: (boolean, string) result of the action 89 """
90 # call C{action.act()} with me as initiator, in my context 91
92 - def take_turn(self):
93 """ 94 called once per round in initiative order 95 (must be implemented in sub-classes) 96 """
97