-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcontexts.py
62 lines (47 loc) · 1.88 KB
/
contexts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from globals import SETTINGS, LIFE
import life as lfe
import encounters
import graphics
import dialog
import alife
import logic
import logging
def _create_context_from_phrase(life, phrase):
_reactions = []
if phrase['gist'] == 'comply':
_reactions.append({'type': 'say','text': 'I give up!',
'communicate': 'surrender'})
if lfe.get_held_items(life, matches=[{'type': 'gun'}]):
_reactions.append({'action': 'action',
'text': '<Shoot %s>' % ' '.join(phrase['from']['name'])})
elif phrase['gist'] == 'demand_drop_item':
_reactions.append({'type': 'action','text': 'Drop the item.',
'action': {'action': 'dropitem','item': phrase['item']},
'score': 900,
'delay': lfe.get_item_access_time(life,phrase['item']),
'communicate': 'dropped_demanded_item'})
elif phrase['gist'] == 'dialog':
if not phrase['dialog_id'] in LIFE[SETTINGS['controlling']]['dialogs']:
life['dialogs'].append(phrase['dialog_id'])
if dialog.get_last_message(phrase['dialog_id'])['text']:
logic.show_event(dialog.get_last_message(phrase['dialog_id'])['text'], life=phrase['from'])
if dialog.is_turn_to_talk(LIFE[SETTINGS['controlling']], phrase['dialog_id']):
dialog.process(LIFE[SETTINGS['controlling']], phrase['dialog_id'])
elif phrase['gist'] == 'looks_hostile':
#encounters.create_encounter(life, phrase['from'])
#logic.show_event(
alife.speech.start_dialog(phrase['from'], life['id'], 'encounter')
#else:
# logging.warning('Unhandled player context: %s' % phrase['gist'])
return _reactions
def create_context(life, action, timeout_callback=None):
#logging.debug('** Created new context %s **' % action['gist'])
if 'gist' in action:
_reactions = _create_context_from_phrase(life, action)
return {'action': 'None',
'text': 'Nothing here!',
'items': [],
'reactions': _reactions,
'from': action['from'],
'timeout_callback': timeout_callback,
'time': 150}