summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--player.py14
-rw-r--r--protocol.py2
2 files changed, 13 insertions, 3 deletions
diff --git a/player.py b/player.py
index a469158..8e17e86 100644
--- a/player.py
+++ b/player.py
@@ -427,12 +427,13 @@ def get_data(args, token):
# Give you offline AP and refresh to NOW, round down
delta=(now()-Player[token]["aptime"])/AP_REGEN_TIME
+ delta2=(now()-Player[token]["aptime"])%AP_REGEN_TIME
Player[token]["ap"]=min(Player[token]["max_ap"], Player[token]["ap"]+delta)
- Player[token]["aptime"]=now()
+ Player[token]["aptime"]=now()-delta2
# This is only to start the timer if needed
if (Player[token]["ap"] < Player[token]["max_ap"]):
- ApTimer[token]=Timer(AP_REGEN_TIME_F, ap_updater, args=[token])
+ ApTimer[token]=Timer(AP_REGEN_TIME_F-delta2, ap_updater, args=[token])
ApTimer[token].daemon=True
ApTimer[token].start()
@@ -464,11 +465,18 @@ def get_data(args, token):
# {responseCode, token, status, gp, crystals, level, ap, max_ap, aptime }
return sjson
-# TODO: This returns the inventory. Should take a "page" argument
+# This returns the player inventory.
def get_inv(args, token):
sjson=compress(Player[token]["inv"])
return sjson
+# This returns the player AP Data
+def ap_data(args, token):
+ sjson=compress({"ap": Player[token]["ap"],
+ "max_ap": Player[token]["max_ap"],
+ "aptime": Player[token]["aptime"]})
+ return sjson
+
# Sell units. Receives a single JSON array of inventory IDs.
def sellunits(args, token):
try:
diff --git a/protocol.py b/protocol.py
index b3d972b..f7c17e7 100644
--- a/protocol.py
+++ b/protocol.py
@@ -79,6 +79,8 @@ def parse(packet, conn):
r=ERR_DONE
elif data[1] == "get_inv":
r=player.get_inv(data[2], t)
+ elif data[1] == "apdata":
+ r=player.ap_data(data[2], t)
elif data[1] == "battle":
r=battle.battle(data[2], t)
elif data[1] == "reload_battle":