XZZ/worker/pcr.py

439 lines
17 KiB
Python
Raw Permalink Normal View History

2020-04-30 16:32:45 +08:00
import json
from zzcore import StdAns
2020-08-15 23:18:30 +08:00
from random import randint, choice
2020-04-30 16:32:45 +08:00
AllowCMD = ['登记','申请出刀','报刀','挂树','查树','进度','查刀','新的一天','血量','boss','初始化','求助','迁移','踢人','单抽','十连','查看卡池','查看池子','新增角色','删除角色','设置up']
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-08 18:08:37 +08:00
AllowGroup = [125733077,1084566280,920863253]
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 == '登记':
2021-01-27 11:33:32 +08:00
nickname = self.raw_msg['raw_message'][8:]
2020-04-30 16:32:45 +08:00
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)
2020-05-10 18:58:05 +08:00
if cmd == 'boss':
if self.role not in ['owner','admin'] and self.uid != 1318000868:
return '你没有权限设置boss。'
else:
try:
boss = int(self.parms[2])
except:
return 'boss序号应该是整数'
nowdata['boss_num'] = boss
self.DATASET({gid:json.dumps(nowdata)})
return '现在boss被设置为' + bossname(int(nowdata['boss_num']))
2020-04-30 16:32:45 +08:00
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
2020-08-19 14:47:49 +08:00
path = './data/pcr/char.list'
try:
with open(path, 'r+', encoding='utf-8') as f:
characters = f.readlines()
except:
return '好像角色名单没有加载呢。。。'
star3 = characters[1].replace('\n','').split(' ')
star3 = [each for each in star3 if each]
star2 = characters[3].replace('\n', '').split(' ')
star2 = [each for each in star2 if each]
star1 = characters[5].replace('\n', '').split(' ')
star1 = [each for each in star1 if each]
up = characters[7].replace('\n', '').split(' ')
up = [each for each in up if each]
2020-08-16 08:27:08 +08:00
2020-08-15 23:18:30 +08:00
if cmd == '单抽' or cmd == '十连':
times = 1 if cmd == '单抽' else 9
resultStar = []
resultName = []
for each in range(times):
2020-08-16 08:27:08 +08:00
code = randint(1,1000)
if code <= 18:
2020-08-15 23:18:30 +08:00
resultStar.append(3)
resultName.append(choice(star3))
2020-08-16 08:27:08 +08:00
elif code <= 25:
resultStar.append(3)
resultName.append(choice(up))
elif code <= 205:
2020-08-15 23:18:30 +08:00
resultStar.append(2)
resultName.append(choice(star2))
else:
resultStar.append(1)
resultName.append(choice(star1))
if times == 9:
2020-08-16 08:27:08 +08:00
code = randint(1, 1000)
if code <= 18:
2020-08-15 23:18:30 +08:00
resultStar.append(3)
resultName.append(choice(star3))
2020-08-16 08:27:08 +08:00
elif code <= 25:
resultStar.append(3)
resultName.append(choice(up))
2020-08-15 23:18:30 +08:00
else:
resultStar.append(2)
resultName.append(choice(star2))
stones = 0
2020-08-16 20:13:41 +08:00
colors = '[CQ:at,qq={}]\n'.format(self.uid)
2020-08-15 23:18:30 +08:00
for each in range(len(resultStar)):
if resultStar[each] == 3:
stones = stones + 50
color = ''
elif resultStar[each] == 2:
stones = stones + 10
color = ''
else:
stones = stones + 1
color = ''
if each == 4:colors = colors + color + '\n'
else:colors = colors + color + ' '
name = ''
for each in range(len(resultName)):
2020-08-16 20:16:35 +08:00
if each == 4: name = name + resultName[each] + '\n'
2020-08-15 23:18:30 +08:00
else:name = name + resultName[each] + ' '
2020-08-16 20:20:09 +08:00
name = name + '\n母猪石 +{} [CQ:face,id=108]'.format(stones)
2020-08-15 23:18:30 +08:00
self.sendmsg(colors)
self.sendmsg(name)
2020-08-16 08:00:04 +08:00
if stones == 19:return '非酋在上,请受我一拜[CQ:face,id=0][CQ:face,id=118]'
elif stones > 157:return '欧皇![CQ:face,id=23]啊我酸了'
2020-08-15 23:18:30 +08:00
if cmd == '查看卡池' or cmd == '查看池子':
return '3★\n' + ''.join(star3) + '\n2★\n' + ''.join(star2) + '\n1★\n' + ''.join(
star1) + '\n★UP★\n' + ''.join(up)
if cmd == '新增角色':
2020-08-19 15:03:04 +08:00
if self.role in ['owner','admin']:
if len(self.parms) != 4:
return '请使用句式:/pcr 新增角色 3 镜华'
try:
star = int(self.parms[2])
except:
return '请使用句式:/pcr 新增角色 3 镜华'
name = self.parms[3]
if star == 3:
star3.append(name)
elif star == 2:
star2.append(name)
elif star == 1:
star1.append(name)
else:
return '请输入正确的星级'
char = '3* 2.5%\n{}\n2* 18%\n{}\n1* 79.5%\n{}\nup 0.7%\n{}'.format(' '.join(star3), ' '.join(star2),
' '.join(star1), ' '.join(up))
try:
with open(path, 'w+', encoding='utf-8') as f:
f.write(char)
except:
return '好像角色名单没有加载呢。。。'
return '添加新角色{}{} 成功[CQ:face,id=144][CQ:face,id=144]'.format(star, name)
else:
return '抱歉,您没有使用这条命令的权柄'
if cmd == '删除角色':
2020-08-19 15:03:04 +08:00
if self.role in ['owner','admin']:
if len(self.parms) != 4:
return '请使用句式:/pcr 删除角色 3 镜华'
try:
star = int(self.parms[2])
except:
return '请使用句式:/pcr 删除角色 3 镜华'
name = self.parms[3]
try:
if star == 3:
star3.remove(name)
elif star == 2:
star2.remove(name)
elif star == 1:
star1.remove(name)
else:
return '请输入正确的星级'
except:
return '没有找到对应的角色'
char = '3* 2.5%\n{}\n2* 18%\n{}\n1* 79.5%\n{}\nup 0.7%\n{}'.format(' '.join(star3), ' '.join(star2),
' '.join(star1), ' '.join(up))
try:
with open(path, 'w+', encoding='utf-8') as f:
f.write(char)
except:
return '好像角色名单没有加载呢。。。'
return '删除角色{}{} 成功'.format(star, name)
else:
return '抱歉,您没有使用这条命令的权柄'
if cmd == '设置up':
2020-08-19 15:03:04 +08:00
if self.role in ['owner','admin']:
if len(self.parms) != 3:
return '请使用句式:/pcr 设置up 镜华(多位角色请用中文逗号隔开)'
name = self.parms[2]
up = [each for each in name.split('') if each]
char = '3* 2.5%\n{}\n2* 18%\n{}\n1* 79.5%\n{}\nup 0.7%\n{}'.format(' '.join(star3), ' '.join(star2),
' '.join(star1), ' '.join(up))
try:
with open(path, 'w+', encoding='utf-8') as f:
f.write(char)
except:
return '好像角色名单没有加载呢。。。'
return '已成功将{}设为★UP★角色'.format(name)
else:
return '抱歉,您没有使用这条命令的权柄'
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'