Change something about aggregate

This commit is contained in:
Lost-MSth
2022-01-24 21:22:38 +08:00
parent 34497d0638
commit 32bcbb0ccd
5 changed files with 138 additions and 131 deletions

View File

@@ -1,5 +1,6 @@
import json
from server.sql import Connect
from .config import Constant
from setting import Config
import server.item
import server.character
@@ -26,14 +27,14 @@ def int2b(x):
def calc_stamina(max_stamina_ts, curr_stamina):
# 计算体力,返回剩余体力数值
stamina = int(Config.MAX_STAMINA - (max_stamina_ts -
int(time.time()*1000)) / Config.STAMINA_RECOVER_TICK)
stamina = int(Constant.MAX_STAMINA - (max_stamina_ts -
int(time.time()*1000)) / Constant.STAMINA_RECOVER_TICK)
if stamina >= Config.MAX_STAMINA:
if curr_stamina >= Config.MAX_STAMINA:
if stamina >= Constant.MAX_STAMINA:
if curr_stamina >= Constant.MAX_STAMINA:
stamina = curr_stamina
else:
stamina = Config.MAX_STAMINA
stamina = Constant.MAX_STAMINA
if stamina < 0:
stamina = 0
@@ -245,8 +246,8 @@ def play_world_song(user_id, args):
return {}
stamina = calc_stamina(max_stamina_ts, stamina) - \
info['stamina_cost'] * stamina_multiply
max_stamina_ts = now + Config.STAMINA_RECOVER_TICK * \
(Config.MAX_STAMINA - stamina)
max_stamina_ts = now + Constant.STAMINA_RECOVER_TICK * \
(Constant.MAX_STAMINA - stamina)
c.execute('''update user set max_stamina_ts=?, stamina=? where user_id=?''',
(max_stamina_ts, stamina, user_id))
r = {
@@ -600,11 +601,11 @@ def add_stamina(c, user_id, add_stamina):
if x and x[0] is not None and x[1] is not None:
stamina = calc_stamina(x[0], x[1]) + add_stamina
max_stamina_ts = now - \
(stamina-Config.MAX_STAMINA) * \
Config.STAMINA_RECOVER_TICK
(stamina-Constant.MAX_STAMINA) * \
Constant.STAMINA_RECOVER_TICK
else:
max_stamina_ts = now
stamina = Config.MAX_STAMINA
stamina = Constant.MAX_STAMINA
c.execute('''update user set max_stamina_ts=?, stamina=? where user_id=?''',
(max_stamina_ts, stamina, user_id))

View File

@@ -0,0 +1,7 @@
class Constant:
MAX_STAMINA = 12
STAMINA_RECOVER_TICK = 1800000
CORE_EXP = 250

View File

@@ -6,7 +6,7 @@ import server.character
import server.item
import time
from setting import Config
from .config import Constant
def int2b(x):
@@ -199,6 +199,38 @@ def get_user_me(c, user_id):
return r
def get_user_me_c(user_id):
# user/me调用上边没开数据库这里开一下
with Connect() as c:
return get_user_me(c, user_id)
def get_purchase_pack(user_id):
# 返回曲包数据
with Connect() as c:
return server.arcpurchase.get_purchase(c, 'pack')
def get_game_info():
# 返回游戏基本信息
r = {
"max_stamina": Constant.MAX_STAMINA,
"stamina_recover_tick": Constant.STAMINA_RECOVER_TICK,
"core_exp": Constant.CORE_EXP,
"curr_ts": int(time.time()*1000),
"level_steps": server.character.get_level_steps(),
"world_ranking_enabled": True,
"is_byd_chapter_unlocked": True
}
return r
def get_user_present(user_id):
# 返回奖励信息
with Connect() as c:
return server.arcpurchase.get_user_present(c, user_id)
def arc_aggregate_small(user_id):
# 返回用户数据
r = {"success": False}
@@ -211,28 +243,6 @@ def arc_aggregate_small(user_id):
return r
def get_purchase_pack(user_id):
# 返回曲包数据
with Connect() as c:
return server.arcpurchase.get_purchase(c, 'pack')
def get_game_info():
# 返回游戏基本信息
r={
"max_stamina": Config.MAX_STAMINA,
"stamina_recover_tick": Config.STAMINA_RECOVER_TICK,
"core_exp": Config.CORE_EXP,
"curr_ts": int(time.time()*1000),
"level_steps": server.character.get_level_steps(),
"world_ranking_enabled": True,
"is_byd_chapter_unlocked": True
}
return r
def get_user_present(user_id):
# 返回礼品信息
with Connect() as c:
return server.arcpurchase.get_user_present(c, user_id)
def arc_aggregate_big(user_id):
# 返回比较全的用户数据
@@ -258,9 +268,9 @@ def arc_aggregate_big(user_id):
}, {
"id": 3,
"value": {
"max_stamina": MAX_STAMINA,
"stamina_recover_tick": STAMINA_RECOVER_TICK,
"core_exp": CORE_EXP,
"max_stamina": Constant.MAX_STAMINA,
"stamina_recover_tick": Constant.STAMINA_RECOVER_TICK,
"core_exp": Constant.CORE_EXP,
"curr_ts": int(time.time()*1000),
"level_steps": server.character.get_level_steps(),
"world_ranking_enabled": True,