Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Barry
/
esp8266-Mud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
166f4c92
authored
2018-05-06 23:15:47 -0700
by
Barry
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Moved the randrange to utils and updated release.py
1 parent
acd3caa9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
27 deletions
mobs.txt
release.py
rooms/tavern_monsters.json
utils.py
mobs.txt
View file @
166f4c9
...
...
@@ -5,7 +5,7 @@ def run_mobs(players, mud):
if 'd' in d:
dice = d.split('d')
for d in range(int(dice[0])):
att += randrange(int(dice[1])) + 1
att +=
utils.
randrange(int(dice[1])) + 1
else:
att = int(d)
return att
...
...
@@ -17,35 +17,12 @@ def run_mobs(players, mud):
v_att.append(attack)
# Select a random attack
if len(v_att) > 0:
attack = v_att[randrange(len(v_att))]
attack = v_att[
utils.
randrange(len(v_att))]
att = get_att(attack['dmg'])
mud.send_message(pid, "%s for %d" % (attack['desc'], att,))
bank -= attack['cost']
return att, bank
def randrange(start, stop=None):
if 'esp' in sys.platform:
if start == 1:
return 0
if stop is None:
stop = start
start = 0
upper = stop - start
bits = 0
pwr2 = 1
while upper > pwr2:
pwr2 <<= 1
bits += 1
while True:
from urandom import getrandbits
r = getrandbits(bits)
if r < upper:
break
return r + start
else:
import random
return random.randrange(start)
for pid, player in players.items():
if not player['name']:
continue
...
...
release.py
View file @
166f4c9
...
...
@@ -21,7 +21,8 @@ files = [
"mudserver.py"
,
"utils.py"
,
"welcome.txt"
,
"wifiweb.py"
"wifiweb.py"
,
"defaultplayer.json"
]
def
run_command
(
sio
,
command
,
expected
=
'>>>'
):
...
...
rooms/tavern_monsters.json
View file @
166f4c9
{
"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
{
"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
...
...
utils.py
View file @
166f4c9
import
json
import
sys
if
'esp'
in
sys
.
platform
:
from
urandom
import
getrandbits
else
:
import
random
def
save_object_to_file
(
obj
,
filename
):
with
open
(
filename
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
...
...
@@ -12,3 +17,24 @@ def load_object_from_file(filename):
print
(
'Error opening file: '
+
filename
)
print
(
e
)
return
None
def
randrange
(
start
,
stop
=
None
):
if
'esp'
in
sys
.
platform
:
if
start
==
1
:
return
0
if
stop
is
None
:
stop
=
start
start
=
0
upper
=
stop
-
start
bits
=
0
pwr2
=
1
while
upper
>
pwr2
:
pwr2
<<=
1
bits
+=
1
while
True
:
r
=
getrandbits
(
bits
)
if
r
<
upper
:
break
return
r
+
start
else
:
return
random
.
randrange
(
start
)
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment