CRAW now runs on Windows 7 too - the problem was that Windows 7 has moved some functi...
[craw.git] / script / experience.py
blob0b2186ec140a3a81a8b2472cf6fc4154227537b2
1 from experience_table import *
2 import utility, math, craw, packets, configuration
4 class experience_handler_class:
5 def process_bytes(self, bytes):
6 experience_formats = [
7 (0x1a, 1),
8 (0x1b, 2)
11 self.experience = craw.get_experience()
12 if self.experience == None:
13 return
15 elif len(bytes) >= 5 and bytes[0] == 0x1c:
16 new_experience = utility.read_bytes(bytes, 1, 4)
17 self.process_experience(new_experience - self.experience)
19 else:
20 for identifier, size in experience_formats:
21 if len(bytes) >= 1 + size and bytes[0] == identifier:
22 experience_gained = utility.read_bytes(bytes, 1, size)
23 self.process_experience(experience_gained)
24 break
26 def process_experience(self, experience_gained):
27 player = utility.get_my_player()
28 if player == None:
29 return
31 experience_for_this_level = experience_table[player.level - 1]
32 experience_for_next_level = experience_table[player.level]
33 current_experience = self.experience
34 remaining_experience = experience_for_next_level - current_experience
35 kills_required = int(math.ceil(float(remaining_experience) / experience_gained))
36 experience_difference = current_experience - experience_for_this_level
37 experience_in_this_level = experience_for_next_level - experience_for_this_level
38 progress = float(experience_difference) / experience_in_this_level * 100.0
39 self.experience += experience_gained
40 if kills_required > configuration.experience_peanut_limit:
41 return
42 print 'Gained %d experience points, kill %d more of these (%.2f%%)' % (experience_gained, kills_required, progress)