-
Notifications
You must be signed in to change notification settings - Fork 11
/
melee.py
275 lines (209 loc) · 8.92 KB
/
melee.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#NOTE: This was written outside the context of Reactor 3. It might look a bit weird...
from globals import *
import graphics as gfx
import life as lfe
import bad_numbers
import alife
import menus
import random
def get_stance_score(p, stance):
_current_score = p['stances'][p['stance']]
_next_score = p['stances'][stance]
return abs(_current_score-_next_score)
def assume_stance(p, stance, towards=None):
if p['next_stance']['stance'] == stance and p['next_stance']['towards'] == towards:
if 'player' in p:
gfx.message('You continue to %s.' % stance)
return False
if p['next_stance']['forced']:
if not p['next_stance']['delay']:
p['next_stance']['forced'] = False
else:
print p['name'], 'cannot move (forced)'
return False
p['next_stance']['delay'] = get_stance_score(p, stance)
p['next_stance']['stance'] = stance
p['next_stance']['towards'] = towards
p['next_stance']['forced'] = False
if 'player' in p:
gfx.message('You start to %s.' % stance)
elif 'player' in LIFE[towards]:
gfx.message('%s begins to %s.' % (' '.join(p['name']), stance))
print p['name'], 'begins', p['next_stance']['stance'], '(%s' % p['next_stance']['delay']+')'
return True
def force_stance(p, target_id, stance):
if not p['stance'] == stance:
if 'player' in p:
gfx.message('You are thrown by %s.' % ' '.join(LIFE[target_id]['name']), style='player_combat_bad')
elif 'player' in LIFE[target_id]:
gfx.message('You throw %s into %s.' % (' '.join(p['name']), stance), style='player_combat_good')
p['next_stance']['delay'] = get_stance_score(p, stance)
p['stance'] = stance
#TODO: Randomly regain balance or fall over
p['next_stance']['stance'] = 'standing'
p['next_stance']['forced'] = True
print p['name'], 'forced into', p['stance'], '(%s' % p['next_stance']['delay']+')'
def examine_possible_moves(p, targets):
#TODO: Cancel move?
_moves = {}
#if p['next_stance']['stance']:
# return False
for _target in targets:
target = LIFE[_target]
if target == p:
continue
if sum([abs(i) for i in target['velocity']]):
continue
if 'player' in p:
_moves[_target] = {'moves': [], 'counters': []}
_next_stance = p['next_stance']['stance']
_next_target_stance = target['next_stance']['stance']
_incoming_attack = False
#Target is attacking
if target['stance'] in target['moves']:
_incoming_attack = target['stance']
elif _next_target_stance in target['moves']:
_incoming_attack = _next_target_stance
if _incoming_attack:
if not _next_stance in p['moves'][_incoming_attack]['counters']:
if 'player' in p:
_moves[_target]['counters'].extend(p['moves'][_incoming_attack]['counters'])
elif p['moves'][_incoming_attack]['counters']:
assume_stance(p, random.choice(p['moves'][_incoming_attack]['counters']), towards=_target)
return False
elif p['stance'] in p['moves'][_incoming_attack]['counters']:
return True
if 'player' in p:
_moves[_target]['moves'].extend(p['moves'].keys())
else:
assume_stance(p, random.choice(p['moves'].keys()), towards=_target)
return True
#if _next_stance and _next_stance in p['moves'] and not p['stance'] in p['moves'][_next_stance]['counters']:
# assume_stance(p, p['moves'][_next_stance]['counters'][0], towards=_target)
# return False
#elif (not _next_stance or not target['stance'] in p['moves']):
# assume_stance(p, random.choice(p['moves'].keys()), towards=_target)
# return True
if _moves and menus.get_menu_by_name('Advanced Movement')==-1 and not sum([abs(i) for i in p['velocity']]):
_menu = []
for target_id in _moves:
if _moves[target_id]['moves']:
_menu.append(menus.create_item('title', '%s (Attacks)' % ' '.join(LIFE[target_id]['name']), None))
for move in _moves[target_id]['moves']:
_menu.append(menus.create_item('single', move, None, move=move, target=target_id))
if _moves[target_id]['counters']:
_menu.append(menus.create_item('title', '%s (Counters)' % ' '.join(LIFE[target_id]['name']), None))
for move in _moves[target_id]['counters']:
_menu.append(menus.create_item('single', move, None, move=move, target=target_id))
_m = menus.create_menu(menu=_menu,
position=[1, 1],
title='Advanced Movement',
format_str='$k',
on_select=lambda entry: assume_stance(LIFE[SETTINGS['controlling']],
entry['move'],
towards=entry['target']),
close_on_select=True)
menus.activate_menu(_m)
def tick(p):
if p['next_stance']['delay']:
p['next_stance']['delay'] -= 1
if p['next_stance']['delay']:
print p['name'], 'waiting:', p['next_stance']['stance'], '(%s' % p['next_stance']['delay']+')'
return False
if p['next_stance']['stance']:
print p['name'], p['stance'], '->', p['next_stance']['stance']
p['stance'] = p['next_stance']['stance']
p['next_stance']['stance'] = None
return True
def react_to_attack(life, target_id, stance):
_target = LIFE[target_id]
_attack = _target['moves'][stance]
if life['stance'] <= _attack['effective_stance']:
_force = life['stances'][life['stance']]-_attack['effective_stance']
else:
_force = 0
if _force >= life['stances'][life['stance']]:
lfe.push(life, bad_numbers.direction_to(LIFE[target_id]['pos'], life['pos']), _attack['damage']['force'])
force_stance(life, target_id, 'crawling')
elif life['stances'][life['stance']]<=life['stances']['crouching']:
force_stance(life, target_id, 'off-balance')
lfe.add_wound(life, random.choice(life['body'].keys()), pain=_attack['damage']['force'])
def perform_moves(people):
for life_id in people:
_life = LIFE[life_id]
if not _life['stance'] in _life['moves'] or not _life['next_stance']['towards']:
continue
if _life['next_stance']['towards']:
_target = LIFE[_life['next_stance']['towards']]
if _life['stance'] in _life['moves'] and _target['stance'] in _life['moves'][_life['stance']]['counters']:
if 'player' in _target:
gfx.message('You counter %s\'s %s.' % (' '.join(_life['name']), _target['stance']), style='player_combat_good')
elif 'player' in _life:
gfx.message('%s counters your %s.' % (' '.join(_target['name']), _life['stance']), style='player_combat_bad')
print '%s counters %s\'s %s!' % (_target['name'], _life['name'], _life['stance'])
#react_to_attack(_life, _target['id'], _target['stance'])
else:
lfe.memory(_life, 'shot', target=_target['id'])
lfe.memory(_target, 'attacked', target=_life['id'])
alife.judgement.judge_life(_target, _life['id'])
if 'player' in _life:
gfx.message('You %s %s.' % (_life['stance'], ' '.join(_target['name'])), style='player_combat_good')
elif 'player' in _target:
gfx.message('%s lands a %s.' % (' '.join(_life['name']), _life['stance']), style='player_combat_bad')
print '%s\'s %s hits %s!' % (_life['name'], _life['stance'], _target['name'])
react_to_attack(_target, _life['id'], _life['stance'])
_life['next_stance']['towards'] = None
#TODO: Useful, just not here.
#else:
# if 'player' in _life:
# gfx.message('You miss %s.' % ' '.join(_target['name']), style='player_combat_bad')
# elif 'player' in _target:
# gfx.message('%s misses you.' % ' '.join(_life['name']), style='player_combat_bad')
#
# print '%s\'s %s does nothing!' % (_life['name'], _life['stance'])
#TODO: React...
#life['stance'] = 'stand'
def fight(life, target):
examine_possible_moves(life, [target])
def process_fights():
_fighters = []
for life in LIFE.values():
if life['next_stance']['stance']:
if sum([abs(i) for i in life['velocity']]):
continue
if not life['id'] in _fighters:
_fighters.append(life['id'])
if life['next_stance']['towards']:
if sum([abs(i) for i in LIFE[life['next_stance']['towards']]['velocity']]):
life['next_stance']['stance'] = None
life['next_stance']['towards'] = None
continue
if bad_numbers.distance(life['pos'], LIFE[life['next_stance']['towards']]['pos'])>1:
life['next_stance']['stance'] = None
life['next_stance']['towards'] = None
continue
if not life['next_stance']['towards'] in _fighters:
_fighters.append(life['next_stance']['towards'])
if len(_fighters)<=1:
WORLD_INFO['sub_ticks'] = WORLD_INFO['max_sub_ticks']
return False
if WORLD_INFO['sub_ticks']:
WORLD_INFO['sub_ticks'] -= 1
else:
WORLD_INFO['sub_ticks'] = WORLD_INFO['max_sub_ticks']
return False
for _fighter in _fighters:
if lfe.calculate_velocity(LIFE[_fighter]):
continue
examine_possible_moves(LIFE[_fighter], _fighters)
tick(LIFE[_fighter])
perform_moves(_fighters)
_i = 0
for fighter in _fighters:
if sum([abs(i) for i in LIFE[fighter]['velocity']]):
continue
_i += 1
if _i<=1:
if menus.get_menu_by_name('Advanced Movement')>-1:
menus.delete_active_menu()
return _fighters