basic stub of encounter human
This commit is contained in:
		@@ -2,12 +2,45 @@ import json
 | 
			
		||||
import random
 | 
			
		||||
import subprocess
 | 
			
		||||
 | 
			
		||||
import flask
 | 
			
		||||
 | 
			
		||||
from . import core
 | 
			
		||||
 | 
			
		||||
def generate_flavor_text():
 | 
			
		||||
    proc_rant = subprocess.run(["rant", "/app/rant/flavor.rant"], capture_output=True)
 | 
			
		||||
    return proc_rant.stdout.decode()
 | 
			
		||||
 | 
			
		||||
class TickEvent(object):
 | 
			
		||||
    def __init__(self, tickno, tickweight, tickcode):
 | 
			
		||||
        self.tickno = tickno
 | 
			
		||||
        self.tickweight = tickweight
 | 
			
		||||
        self.tickcode = tickcode
 | 
			
		||||
 | 
			
		||||
tick_event_list = []
 | 
			
		||||
tick_event_list.append(TickEvent(0, 16, "XYZZY"))       # nothing happens
 | 
			
		||||
tick_event_list.append(TickEvent(1, 1, "FLAVOR"))       # procedurally generated event of no consequence
 | 
			
		||||
tick_event_list.append(TickEvent(10, 2, "ENCHUMAN"))    # encounter: human
 | 
			
		||||
 | 
			
		||||
@core.app.route("/tick")
 | 
			
		||||
def tick():
 | 
			
		||||
    return random.choices([json.dumps({"code": 200, "event_type": 0}), json.dumps({"code": 200, "event_type": 1, "log": generate_flavor_text()})], weights=[16, 1])[0]
 | 
			
		||||
    #return random.choices([json.dumps({"code": 200, "event_type": 0}), json.dumps({"code": 200, "event_type": 1, "log": generate_flavor_text()})], weights=[16, 1])[0]
 | 
			
		||||
    ticktypes = []
 | 
			
		||||
    tickweights = []
 | 
			
		||||
 | 
			
		||||
    for event in tick_event_list:
 | 
			
		||||
        ticktypes.append(event.tickno) # unce unce unce
 | 
			
		||||
        tickweights.append(event.tickweight)
 | 
			
		||||
 | 
			
		||||
    result = {}
 | 
			
		||||
    result["code"] = 200
 | 
			
		||||
    result["event_type"] = random.choices(ticktypes, weights=tickweights)[0]
 | 
			
		||||
 | 
			
		||||
    match result["event_type"]:
 | 
			
		||||
        case 1: # FLAVOR
 | 
			
		||||
            result["log"] = generate_flavor_text()
 | 
			
		||||
        case 10: # ENCHUMAN
 | 
			
		||||
            result["items"] = [] # TODO: implement items
 | 
			
		||||
        case _:
 | 
			
		||||
            print("undefined tick: {0}".format(result["event_type"]))
 | 
			
		||||
 | 
			
		||||
    return flask.Response(json.dumps(result), status=200, content_type="application/json")
 | 
			
		||||
		Reference in New Issue
	
	Block a user