166f4c92 by Barry

Moved the randrange to utils and updated release.py

1 parent acd3caa9
...@@ -5,7 +5,7 @@ def run_mobs(players, mud): ...@@ -5,7 +5,7 @@ def run_mobs(players, mud):
5 if 'd' in d: 5 if 'd' in d:
6 dice = d.split('d') 6 dice = d.split('d')
7 for d in range(int(dice[0])): 7 for d in range(int(dice[0])):
8 att += randrange(int(dice[1])) + 1 8 att += utils.randrange(int(dice[1])) + 1
9 else: 9 else:
10 att = int(d) 10 att = int(d)
11 return att 11 return att
...@@ -17,35 +17,12 @@ def run_mobs(players, mud): ...@@ -17,35 +17,12 @@ def run_mobs(players, mud):
17 v_att.append(attack) 17 v_att.append(attack)
18 # Select a random attack 18 # Select a random attack
19 if len(v_att) > 0: 19 if len(v_att) > 0:
20 attack = v_att[randrange(len(v_att))] 20 attack = v_att[utils.randrange(len(v_att))]
21 att = get_att(attack['dmg']) 21 att = get_att(attack['dmg'])
22 mud.send_message(pid, "%s for %d" % (attack['desc'], att,)) 22 mud.send_message(pid, "%s for %d" % (attack['desc'], att,))
23 bank -= attack['cost'] 23 bank -= attack['cost']
24 return att, bank 24 return att, bank
25 25
26 def randrange(start, stop=None):
27 if 'esp' in sys.platform:
28 if start == 1:
29 return 0
30 if stop is None:
31 stop = start
32 start = 0
33 upper = stop - start
34 bits = 0
35 pwr2 = 1
36 while upper > pwr2:
37 pwr2 <<= 1
38 bits += 1
39 while True:
40 from urandom import getrandbits
41 r = getrandbits(bits)
42 if r < upper:
43 break
44 return r + start
45 else:
46 import random
47 return random.randrange(start)
48
49 for pid, player in players.items(): 26 for pid, player in players.items():
50 if not player['name']: 27 if not player['name']:
51 continue 28 continue
......
...@@ -21,7 +21,8 @@ files = [ ...@@ -21,7 +21,8 @@ files = [
21 "mudserver.py", 21 "mudserver.py",
22 "utils.py", 22 "utils.py",
23 "welcome.txt", 23 "welcome.txt",
24 "wifiweb.py" 24 "wifiweb.py",
25 "defaultplayer.json"
25 ] 26 ]
26 27
27 def run_command(sio, command, expected='>>>'): 28 def run_command(sio, command, expected='>>>'):
......
1 {"cricket": {"max": 1, "active": [{"hp": 100, "mp": 2.0, "sta": 5.550000000000028, "maxhp": 100, "maxmp": 10, "maxsta": 10, "action": "attack", "target": "test"}]}}
...\ No newline at end of file ...\ No newline at end of file
1 {"cricket": {"max": 1, "active": [{"hp": 100, "mp": 4.25, "sta": 3.1500000000000314, "maxhp": 100, "maxmp": 10, "maxsta": 10, "action": "attack", "target": "test"}]}}
...\ No newline at end of file ...\ No newline at end of file
......
1 import json 1 import json
2 import sys
3 if 'esp' in sys.platform:
4 from urandom import getrandbits
5 else:
6 import random
2 7
3 def save_object_to_file(obj, filename): 8 def save_object_to_file(obj, filename):
4 with open(filename, 'w', encoding='utf-8') as f: 9 with open(filename, 'w', encoding='utf-8') as f:
...@@ -12,3 +17,24 @@ def load_object_from_file(filename): ...@@ -12,3 +17,24 @@ def load_object_from_file(filename):
12 print('Error opening file: ' + filename) 17 print('Error opening file: ' + filename)
13 print(e) 18 print(e)
14 return None 19 return None
20
21 def randrange(start, stop=None):
22 if 'esp' in sys.platform:
23 if start == 1:
24 return 0
25 if stop is None:
26 stop = start
27 start = 0
28 upper = stop - start
29 bits = 0
30 pwr2 = 1
31 while upper > pwr2:
32 pwr2 <<= 1
33 bits += 1
34 while True:
35 r = getrandbits(bits)
36 if r < upper:
37 break
38 return r + start
39 else:
40 return random.randrange(start)
...\ No newline at end of file ...\ No newline at end of file
......