CRAW now runs on Windows 7 too - the problem was that Windows 7 has moved some functi...
[craw.git] / script / summoner.py
blobdeb6e76b41cb9a5c79c6194b80138f20b969f72c
1 import packets, nil.thread, time, random, utility, configuration, craw
3 raise_skeleton_skill = 0x46
4 raise_skeletal_mage_skill = 0x50
5 revive_skill = 0x5f
7 skills = [
8 ('Raising a skeleton', raise_skeleton_skill),
9 ('Raising a skeletal mage', raise_skeletal_mage_skill),
10 ('Reviving a monster', revive_skill)
13 class summoner_handler_class:
14 def __init__(self):
15 pass
17 def initialise(self):
18 self.skeletons = 0
19 self.skeleton_mages = 0
20 self.revives = 0
21 self.monsters = []
22 nil.thread.create_thread(self.summoner_thread)
24 def process_bytes(self, bytes):
25 if packets.entering_game(bytes):
26 self.initialise()
28 add_unit = packets.parse_add_unit(bytes)
29 if add_unit != None:
30 unit_type, unit_id = add_unit
31 #print 'Added unit of type %d: %08x' % (unit_type, unit_id)
32 if unit_type == 1:
33 self.monsters.append(unit_id)
35 object_removal = packets.object_removal(bytes)
36 if object_removal != None:
37 type, id = object_removal
38 try:
39 self.monsters.remove(id)
40 except ValueError:
41 pass
43 def get_targets(self):
44 targets = []
45 for unit_id in self.monsters:
46 monster = craw.get_unit(unit_id, 1)
47 if monster == None:
48 print 'Failed to retrieve the unit of monster %08x' % unit_id
49 continue
50 if monster.mode in [0, 12]:
51 targets.append(unit_id)
53 return targets
55 def summoner_thread(self):
56 while True:
57 player = utility.get_my_player()
58 if player == None:
59 #print 'No summoner unit'
60 time.sleep(configuration.summoner_check_delay)
61 continue
62 break
64 if player.name not in configuration.summoners:
65 #print 'This is not a summoner'
66 return
68 while True:
69 my_unit = utility.get_my_unit()
70 if my_unit == None:
71 print 'Unable to retrieve summoner unit'
72 return
74 standing_still = my_unit.mode == 1
75 if standing_still and not utility.town_check():
76 targets = self.get_targets()
77 if len(targets) == 0:
78 craw.print_text('There are no nearby corpses')
79 else:
80 target = random.choice(targets)
81 description, skill = random.choice(skills)
82 craw.print_text('%s: %08x' % (description, target))
83 packets.set_right_skill(skill)
84 time.sleep(configuration.summoner_switch_delay)
85 packets.cast_right_skill_at_target(1, target)
86 time.sleep(configuration.summoner_cast_delay)
87 continue
89 time.sleep(configuration.summoner_check_delay)