5812e177 by Barry

Updated readme and release. Removed unused files.

1 parent bb26558b
......@@ -59,3 +59,125 @@ All damage rolls are described in the number of times to roll and the random amo
* cost - The cost in stamina of the attack
* dmg - the amount of damage caused by this attack
* desc - the description to display when the attack is performed
### Where to buy your ESP8266
https://www.amazon.com/gp/product/B01IK9GEQG/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1
I like the NodeMcu devices. They have 4mb flash and work well and are fairly robust and compact.
### How to Load on a New ESP8266
Use python 3.6+
Create a virtual environment to save your brainspace.
```
virtualenv venv
```
Use your virtual env:
Mac / Linux:
```
source venv/bin/activate
```
Windows:
```
venv\Scripts\activate
```
Install esptool and the other required pip modules which will let you install the micropython firmware.
```
pip install -r requirements.txt
```
After the modules are installed you will need to use esptool to erase the flash.
if things go wrong... https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
Find the com port, you should look in your devices, plug / unplug until you figure it out.
```
esptool --port COM1 erase_flash
```
This will remove all data from the device.
Download a version of micropython for your device:
http://micropython.org/resources/firmware/esp8266-20171101-v1.9.3.bin
The mud is written based on 1.9.3 and I suspect it will be very version sensitive.
After the file has been downloaded (use wget? browser? curl? whatever makes you happy)
```
esptool --port COM1 --baud 460800 write_flash --flash_size=detect 0 esp8266-20171101-v1.9.3.bin
```
This will write the binary micropython os to the device. After this you will want to validate the write was successful.
We will use the miniterm included with pyserial to connect to the device.
```
python -m serial.tools.miniterm COM1 115200
```
After you get in you will have access to the micropython terminal which will let you run python.
Enter the following to check the firmware to be sure everything went well.
```
import esp
esp.check_fw()
```
This should return a "True" at the end along with the checksum if things went well.
Next the WebREPL server needs to be setup to ease file transfer.
```
import webrepl_setup
```
This script will ask you for a password and a few other odds and ends.
After a reboot you will need to configure your wifi.
```
import network
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)
# activate the station interface
sta_if.active(True)
sta_if.connect('<your ESSID>', '<your password>')
# Run this again and again until you get an IP Address. If this fails your connect is likely wrong.
sta_if.ifconfig()
```
Note your IP Address from the sta_if.ifconfig()
Disconnect from the serial miniterm with a ctrl+]
After exiting the miniterm edit the release.py and change the IP Address and port:
```
PORT = 'COM1'
IPADDRESS = '192.168.1.122'
```
Run the release script:
```
python release.py
```
Reboot your device and the mud will be running at the IP Address on port 1234. To connect:
```
telnet 192.168.1.122 1234
```
......
import utils
class InventoryHandler(object):
def __init__(self, directory):
self.directory = directory
def _get_inventory_file(self, item_name):
filename = self.directory + '/' + item_name + ".txt"
item_data = utils.load_object_from_file(filename)
if item_data is None:
print("Error opening inventory file: {}".format(item_name))
return {}
return item_data
def get_title(self, item_name):
return self._get_inventory_file(item_name)['title']
def get_description(self, item_name):
return self._get_inventory_file(item_name)['description']
def get_type(self, item_name):
return self._get_inventory_file(item_name)['type']
def get_power(self, item_name):
return self._get_inventory_file(item_name)['power']
def get_damage(self, item_name):
return self._get_inventory_file(item_name)['damage']
def get_weight(self, item_name):
return self._get_inventory_file(item_name)['weight']
......@@ -3,20 +3,22 @@ import io
import os
import sys
######################################
# EDIT THIS TO MATCH YOUR SETTINGS
PORT = 'COM17'
IPADDRESS = '192.168.1.122'
######################################
BAUDRATE = 115200
IPADDRESS = ' 192.168.1.122'
folders = ['help', 'rooms', 'inventory', 'commands', 'mobs']
files = [
"commandhandler.py",
"inventoryhandler.py",
"main.py",
"mobs.txt",
"spawner.txt",
"mudserver.py",
"roomloader.py",
"utils.py",
"welcome.txt",
"wifiweb.py"
......
import json
import utils
class RoomLoader(object):
def __init__(self, directory):
self.directory = directory
def _get_room_file(self, room_name):
filename = self.directory + '/' + room_name + ".txt"
room_data = utils.load_object_from_file(filename)
if room_data is None:
print("Error opening room file: {}".format(room_name))
return {}
return room_data
def _save_room_file(self, room_name, room_data):
filename = self.directory + '/' + room_name + ".txt"
utils.save_object_to_file(room_data, filename)
def get_title(self, room_name):
return self._get_room_file(room_name).get('title', None)
def get_description(self, room_name):
return self._get_room_file(room_name).get('description', None)
def get_exits(self, room_name):
return self._get_room_file(room_name).get('exits', None)
def get_look_items(self, room_name):
return self._get_room_file(room_name).get('look_items', None)
def get_inventory(self, room_name):
return self._get_room_file(room_name).get('inventory', None)
def add_to_inventory(self, room_name, item_name, quantity):
room_data = self._get_room_file(room_name)
if item_name in room_data['inventory']:
room_data['inventory'][item_name] += quantity
else:
room_data['inventory'][item_name] = 1
self._save_room_file(room_name, room_data)
return True
def remove_from_inventory(self, room_name, item_name, quantity):
room_data = self._get_room_file(room_name)
if item_name in room_data['inventory']:
room_data['inventory'][item_name] -= quantity
if room_data['inventory'][item_name] <= 0:
del room_data['inventory'][item_name]
self._save_room_file(room_name, room_data)
return True
\ No newline at end of file