XZZ/worker/pcr.py

277 lines
10 KiB
Python
Raw Normal View History

2020-04-30 16:32:45 +08:00
import json
from zzcore import StdAns
2020-05-07 19:59:46 +08:00
AllowCMD = ['登记','申请出刀','报刀','挂树','查树','进度','查刀','新的一天','血量','初始化','求助','迁移','踢人']
2020-04-30 16:32:45 +08:00
status = {
'all_player':{
'1318000868': {
'id':'十六夜咲夜',
'余刀': 3,
'加时刀': 0,
# 'SL':1
},
},
'boss_num': 0,
'boss_hp': 0,
'dao':{
'qq':1318000868,
'类型':'普通刀',
},
'tree':[]
}
class Ans(StdAns):
2020-05-07 20:25:32 +08:00
AllowGroup = [125733077,1084566280]
2020-04-30 16:32:45 +08:00
def GETMSG(self):
if len(self.parms) < 2:
return '不加参数是坏文明!'
cmd = self.parms[1]
if cmd not in AllowCMD:
return '没有 ' + cmd + ' 这个命令,请检查。'
2020-05-07 17:42:46 +08:00
if cmd == '迁移':
if self.uid != 1318000868:
return '迁移数据请联系SiHuan'
try:
nowdata = json.loads(self.DATAGET()[self.parms[2]])
except:
return '获取原始数据出错!'
2020-05-07 17:44:04 +08:00
self.DATASET({self.parms[3]:json.dumps(nowdata)})
return '数据迁移完成! ' + self.parms[2] + '现在迁移到' + self.parms[3]
2020-05-07 17:42:46 +08:00
gid = str(self.gid)
2020-04-30 16:32:45 +08:00
try:
2020-05-07 17:42:46 +08:00
nowdata = json.loads(self.DATAGET()[gid])
2020-04-30 16:32:45 +08:00
except:
2020-04-30 16:38:05 +08:00
if cmd == '初始化':
nowdata = {}
else:
return '请管理员先初始化,初始化会将进度设置为第一周目第一个Boss,成员数据不会丢失。'
2020-04-30 16:32:45 +08:00
if cmd == '初始化':
if self.role not in ['owner','admin'] and self.uid != 1318000868:
return '你没有权限执行初始化。'
else:
try:
all_player = nowdata['all_player']
except:
all_player = {}
nowdata = {}
nowdata['all_player'] = all_player
nowdata['boss_num'] = 1
nowdata['boss_hp'] = -1
nowdata['dao'] = {
'qq':0,
'类型':'普通刀',
}
nowdata['tree'] = []
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
return '初始化完成!请使用\n /pcr 血量 xxxx \n 来设置第一周目第一个Boss的总血量。'
if cmd == '登记':
nickname = self.raw_msg['message'][8:]
if nickname:
player = {
'id':nickname,
'余刀': 3,
'加时刀': 0,
# 'SL':1
}
2020-04-30 16:45:30 +08:00
nowdata['all_player'][str(self.uid)] = player
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
return '[CQ:at,qq=' + str(self.uid) + ']' + '游戏id设置为 ' + nickname
else:
return '登记失败请使用合法的游戏id。'
2020-05-07 19:59:46 +08:00
if cmd == '踢人':
if self.role not in ['owner','admin'] and self.uid != 1318000868:
return '你没有权限踢人。'
else:
tiqq = self.parms[2]
try:
nowplayer = nowdata['all_player'][tiqq]
except:
return '此人未登记!!!。'
if tiqq in nowdata['tree']:
nowdata['tree'].remove(tiqq)
if str(nowdata['dao']['qq']) == tiqq:
nowdata['dao']['qq'] = 0
del nowdata['all_player'][tiqq]
self.DATASET({gid: json.dumps(nowdata)})
return nowplayer['id'] + '已被踢除。'
2020-04-30 16:32:45 +08:00
if cmd == '血量':
if self.role not in ['owner','admin'] and self.uid != 1318000868:
return '你没有权限设置血量。'
else:
try:
hp = int(self.parms[2])
except:
return '血量应该是整数!'
nowdata['boss_hp'] = hp
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
return '现在' + bossname(int(nowdata['boss_num'])) +'的血量被设置为' + str(hp)
if cmd == '新的一天':
if self.role not in ['owner','admin'] and self.uid != 1318000868:
return '你没有权限新的一天。'
else:
2020-04-30 16:41:53 +08:00
for value in nowdata['all_player'].values():
2020-04-30 16:39:54 +08:00
value['余刀'] = 3
value['加时刀'] = 0
2020-04-30 16:32:45 +08:00
# value['SL'] == 1
2020-04-30 16:53:26 +08:00
nowdata['tree'] = []
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
return '新的一天已经开始大家各有3刀剩余了。'
if cmd == '进度':
return bossname(int(nowdata['boss_num'])) + '\n剩余血量:' + str(nowdata['boss_hp'])
if cmd == '申请出刀':
try:
nowplayer = nowdata['all_player'][str(self.uid)]
except:
return '您未登记。'
2020-04-30 18:09:37 +08:00
if self.uid in nowdata['tree']:
return '您在树上了。'
2020-04-30 16:32:45 +08:00
daoqq = nowdata['dao']['qq']
if daoqq != 0 and daoqq not in nowdata['tree']:
return nowdata['all_player'][str(daoqq)]['id'] + '正在出刀,请等待他结算或挂树.'
2020-04-30 16:49:23 +08:00
elif nowplayer['余刀'] + nowplayer['加时刀'] < 1:
2020-04-30 16:32:45 +08:00
return '您已无刀可出。'
else:
nowdata['dao']['qq'] = self.uid
if nowplayer['加时刀'] > 0:
nowdata['dao']['类型'] = '加时刀'
else:
nowdata['dao']['类型'] = '普通刀'
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
return nowplayer['id'] + '' + nowdata['dao']['类型'] + '讨伐' + bossname(int(nowdata['boss_num'])) + '\n剩余血量:' + str(nowdata['boss_hp'])
if cmd == '报刀':
try:
nowplayer = nowdata['all_player'][str(self.uid)]
except:
return '您未登记。'
2020-04-30 18:09:37 +08:00
if nowdata['dao']['qq'] != self.uid and self.uid not in nowdata['tree']:
2020-04-30 17:50:23 +08:00
return '您未出刀,报个毛刀'
2020-04-30 16:32:45 +08:00
try:
jianhp = int(self.parms[2])
except:
return '打掉的血量应该是整数!'
newhp = nowdata['boss_hp'] - jianhp
# BOSS 没死
if newhp > 0:
nowdata['boss_hp'] = newhp
nowdata['dao']['qq'] = 0
if nowdata['dao']['类型'] == '加时刀':
nowplayer['加时刀'] = 0
else:
nowplayer['余刀'] = nowplayer['余刀'] - 1
nowdata['all_player'][str(self.uid)] = nowplayer
2020-04-30 18:09:37 +08:00
if self.uid in nowdata['tree']:
2020-04-30 18:14:43 +08:00
nowdata['tree'].remove(self.uid)
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
2020-04-30 18:09:37 +08:00
msg = nowplayer['id'] + '打了' + bossname(int(nowdata['boss_num'])) + str(jianhp) + '\n剩余血量:' + str(nowdata['boss_hp'])
if self.uid in nowdata['tree']:
msg = msg + '\n' + nowplayer['id'] + '自行下树'
2020-04-30 18:17:04 +08:00
return msg
2020-04-30 16:32:45 +08:00
#BOSS 死了
else:
nowdata['boss_hp'] = 0
nowdata['boss_num'] = nowdata['boss_num'] + 1
nowdata['dao']['qq'] = 0
nowdata['tree'] = []
if nowdata['dao']['类型'] == '加时刀':
nowplayer['加时刀'] = 0
else:
nowplayer['余刀'] = nowplayer['余刀'] - 1
nowplayer['加时刀'] = 1
nowdata['all_player'][str(self.uid)] = nowplayer
2020-04-30 18:09:37 +08:00
if self.uid in nowdata['tree']:
2020-04-30 18:14:43 +08:00
nowdata['tree'].remove(self.uid)
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
2020-04-30 17:08:54 +08:00
return nowplayer['id'] + '击杀了' + bossname(int(nowdata['boss_num'])-1) + '\n现在进入' + bossname(int(nowdata['boss_num'])) + '\n挂树的同学已经全部下树\n请使用\n /pcr 血量 xxxx \n 来设置新Boss的总血量'
2020-04-30 16:32:45 +08:00
if cmd == '挂树':
try:
nowplayer = nowdata['all_player'][str(self.uid)]
except:
return '您未登记。'
2020-04-30 17:30:08 +08:00
if self.uid in nowdata['tree']:
return '您已经在树上了。'
2020-04-30 16:32:45 +08:00
# elif nowplayer['SL'] == 1:
2020-04-30 17:30:08 +08:00
elif nowdata['dao']['qq'] != self.uid:
return '您未出刀,挂个毛树'
2020-04-30 16:32:45 +08:00
else:
nowdata['dao']['qq'] = 0
2020-04-30 17:27:59 +08:00
# print(nowdata['tree'])
# print(type(nowdata['tree']))
nowdata['tree'].append(self.uid)
# print(nowdata['tree'])
# print(type(nowdata['tree']))
2020-05-07 17:42:46 +08:00
self.DATASET({gid:json.dumps(nowdata)})
2020-04-30 16:32:45 +08:00
return '已挂树'
if cmd == '查树':
on_tree_players = ''
for p in nowdata['tree']:
on_tree_players = on_tree_players + nowdata['all_player'][str(p)]['id'] + '\n'
return '树上的有\n' + on_tree_players
if cmd == '查刀':
alldao = ''
2020-05-06 16:05:27 +08:00
index = 1
2020-04-30 17:34:00 +08:00
for key, value in nowdata['all_player'].items():
2020-05-06 16:05:27 +08:00
alldao = alldao + str(index) + '. ' + value['id'] + ' ' + '🔪'*value['余刀'] + '🍴'*value['加时刀']
2020-04-30 17:34:00 +08:00
if int(key) in nowdata['tree']:
alldao = alldao + ' 在🌳上\n'
else:
alldao = alldao + '\n'
2020-05-06 16:05:27 +08:00
index = index + 1
2020-04-30 16:32:45 +08:00
return alldao
2020-04-30 17:50:23 +08:00
if cmd == '求助':
on_tree_players = ''
for p in nowdata['tree']:
on_tree_players = on_tree_players + nowdata['all_player'][str(p)]['id'] + '\n'
return '救命[CQ:at,qq=3178302597][CQ:at,qq=3430357110]\n' + on_tree_players + '都在🌳上'
2020-04-30 16:32:45 +08:00
def bossname(num):
zm = int(num/5)+1
z = num%5
if z == 0:
z = 5
zm = zm - 1
return ''+ str(zm) + '周目第' + str(z) + 'Boss'