-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
1891 lines (1860 loc) · 89.7 KB
/
Copy pathapp.py
File metadata and controls
1891 lines (1860 loc) · 89.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import random
from time import sleep, time
from flask import Flask, request, abort
from flask import render_template
from dotenv import load_dotenv
import lineMessagePacker
import lineMessagePackerRpg
import math
from DataBase import DataBase
from RedisTool import RedisTool
from Games import diceGame, jpGame,rpgGame, wordBossFlexPacker, wordGuideFlexPacker
from datetime import datetime, timedelta
load_dotenv()
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import (
MessageEvent, TextMessage, TextSendMessage,TemplateSendMessage,PostbackEvent,ImageSendMessage,
ButtonsTemplate,
MessageTemplateAction,FlexSendMessage
)
import os
app = Flask(__name__)
environment = os.getenv("ENVIRONMENT")
print("environment: "+environment)
local_storage={}
limite_user={}
if environment =="DEV":
print("本地開發 使用本地開發版本機器人")
line_bot_api = LineBotApi(os.getenv("LINE_BOT_API_DEV"))
handler = WebhookHandler(os.getenv("LINE_BOT_SECRET_DEV"))
else:
print("線上heroku環境 預設線上版機器人")
line_bot_api = LineBotApi(os.getenv("LINE_BOT_API"))
handler = WebhookHandler(os.getenv("LINE_BOT_SECRET"))
database = DataBase()
redistool = RedisTool()
@app.route("/callback", methods=['POST'])
def callback():
# get X-Line-Signature header value
signature = request.headers['X-Line-Signature']
# get request body as text
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)
# handle webhook body
try:
handler.handle(body, signature)
except InvalidSignatureError:
print("Invalid signature. Please check your channel access token/channel secret.")
abort(400)
return 'OK'
#訪問網站
@app.route("/")
def home():
return render_template("home.html")
@app.route("/gm",methods=['post','get'])
def gm():
if request.method == 'POST':
account = request.form.get("account")
password = request.form.get("password")
if account == "123" and password == "123":
return render_template("gmaddweapon.html")
user = database.getUserById(0)
return render_template("gm.html")
@app.route("/addweapon",methods=['post'])
def addweapon():
if request.method == 'POST':
try:
_weaponname = request.form.get("weapon_name")
_stradd = int(request.form.get("str_add"))
_int_add = int(request.form.get("int_add"))
_dex_add = int(request.form.get("dex_add"))
_atk_add = int(request.form.get("atk_add"))
_rare = int(request.form.get("rare"))
if _rare > 5:
_rare = 5
_imagetype = request.form.get("imagetype")
description = request.form.get("otherdescript")
descriptionvalue = request.form.get("otherdescription")
if description =="credit_add" or description =="hp_add":
descriptionvalue = str(descriptionvalue)+"%"
description = '{%s:%s}'%(description,descriptionvalue)
result = database.createNewWeapon(_stradd,_int_add,_dex_add,_atk_add,_rare,_weaponname,_imagetype,description,10)
if result == True:
return render_template("weaponAddSuccess.html")
else:
return render_template("weaponAddfailed.html")
except:
return render_template("weaponAddfailed.html")
return render_template("gm.html")
#用戶post訊息
@handler.add(PostbackEvent)
def handle_postback(event):
data = event.postback.data
if data.startswith("@auctionAddequipment"):
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=data))
return
#用戶文字訊息
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
print(event)
#檢查是否是鎖定玩家
if redistool.getValue(event.source.user_id) is not None:
_usersend = event.message.text
_answerright = redistool.getValue(event.source.user_id).decode()
if _usersend == _answerright:
print("用戶測謊成功")
redistool.removeKey(event.source.user_id)
database.addExpForPlayer(event.source.user_id,4000)
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="成功驗證 可進續進行遊戲 獎勵經驗值: 4000"))
return
else:
print("玩家測謊失敗")
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage("內測期間防止流量問題 請輸入以下文字驗證後再繼續進行 輸入正確會給予獎勵經驗值\n因快取問題如果驗證碼有問題請重新點選圖片即可獲得最新驗證碼\n 驗證文字:\n"),
ImageSendMessage("https://mumu.tw/images/questions/"+event.source.user_id+".png","https://mumu.tw/images/questions/qlittle.png")
])
return
user_send =event.message.text
if user_send =="test":
flex = lineMessagePacker.getPostButtonTest(event.source.user_id)
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("post 測試",contents=flex))
if user_send.strip().startswith("!"):
_command_check = "!"+user_send.strip().split("!")[1].strip().lower()
else:
_command_check = user_send
if _command_check.startswith("!") and _command_check != "!info" and database.checkUser(event.source.user_id) == False:
print("此玩家沒加入好友 傳送提示訊息")
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="看來你還沒有加我好友或是創建個人資料呢!\n請先加我好友 然後使用 !info 指令"))
return
group_id =" "
try:
group_id =event.source.group_id
except:
group_id =" "
print("no group")
print(user_send)
if _command_check =="!respawn":
print("測試期間復活 $10000")
_money = database.getUserMoney(event.source.user_id)
print(_money)
_money = int(_money)
if _money > 0:
_reply = "妳的餘額還沒有歸0 不能浴火重生喔!"
elif database.GetUserLockedMoneyLineId(event.source.user_id) > 0:
_reply ="請先把正在進行的遊戲結算"
else:
database.SetUserMoneyByLineId(event.source.user_id,10000)
_reply = "已幫您復活 充值 $10000"
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=_reply))
if user_send =="@gmaddweapon":
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="gm新增表單:"),
TextSendMessage(text="https://lineherorpg.herokuapp.com/gm")])
if user_send =="@bugreport":
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("BUG回報",contents=lineMessagePacker.getBugReport()))
return
if user_send =="!ranking":
top5 = database.getTop5Ranking()
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("財力排行",contents=lineMessagePacker.getRanking(top5[0],top5[1],top5[2],top5[3],top5[4])))
return
if user_send =="@ranking":
top5 = database.getTop5RpgRanking()
print(top5)
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("LV排行",contents=lineMessagePackerRpg.getRpgTop5Rank(top5)))
return
elif user_send =="!dailyrequest":
if database.checkUserDaily(event.source.user_id) == True:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage("你已領取過每日獎賞囉"))
return
else:
_dailybroadcast = database.checkDailyBroadcast()
_broadcast_str = "伺服器公告:\n"+_dailybroadcast
_nowmoney = int(database.getUserMoney(event.source.user_id))
_nowmoney+=100000
database.SetUserMoneyByLineId(event.source.user_id,_nowmoney)
database.setUserDaily(event.source.user_id,True)
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage("每日獎賞已到帳!"),
TextSendMessage(_broadcast_str)])
return
elif _command_check.startswith("!initjob"):
try:
_job = user_send.split(" ")[1]
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料格式錯誤"))
return
if database.checkUserHasJob(event.source.user_id) == True:
_userjson = database.getUser(event.source.user_id)
_jobjson = database.getUserJob(event.source.user_id)
_flex = lineMessagePackerRpg.getCheckJobButton()
_reply = "你已經有職業囉"
print("已經有職業!")
print(_flex)
line_bot_api.reply_message(
event.reply_token,
[TextSendMessage(text="你已經有職業囉"),
FlexSendMessage("確認職業",_flex)]
)
return
else:
if rpgGame.checkstrjobLegal(_job) == True:
_reply = rpgGame.createrJob(event.source.user_id,_job)
_userjson = database.getUser(event.source.user_id)
_jobjson = database.getUserJob(event.source.user_id)
_imglink = _userjson["user_img_link"]
_rank = database.getUserRpgRank(event.source.user_id)
_weapon = database.getUserEquipmentWeapon(event.source.user_id)
_flex = lineMessagePackerRpg.getJobInfo(_imglink,_jobjson,_rank,_weapon)
_flex_sub_menu = lineMessagePackerRpg.getJobInfoSubMenu()
line_bot_api.reply_message(
event.reply_token,
[TextSendMessage(text=_reply),
FlexSendMessage("職業資訊",contents=_flex),
FlexSendMessage("職業資訊",contents=_flex_sub_menu),
])
else:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料格式錯誤"))
return
elif user_send =="@pet":
user_id = event.source.user_id
try:
profile = line_bot_api.get_profile(user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="看來你沒有加我好友! 請先加我好友喔"))
_player_jobinfo = database.getUserJob(user_id)
_pet_info = database.getPetInfo(_player_jobinfo["pet"])
_flex_pet = lineMessagePackerRpg.getEquipmentPet(_pet_info)
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("寵物資訊",contents=_flex_pet)
)
elif user_send =="@pet_adventure":
user_id = event.source.user_id
try:
profile = line_bot_api.get_profile(user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="看來你沒有加我好友! 請先加我好友喔"))
return
#已經在掛機了 進入結算畫面
if database.UserIsInAdventure(event.source.user_id) == True:
_nowstatus = database.getUserAdventureStatus(event.source.user_id)
_adventure_result = rpgGame.checkAdventureResult(_nowstatus)
_pet_info = database.getPetInfo(_nowstatus["pet_id"])
_flex_adventure_result = lineMessagePackerRpg.getAdventureNowStatus(_pet_info,_adventure_result)
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("目前遠征資訊",contents=_flex_adventure_result)
)
return
_flex_adventure = lineMessagePackerRpg.getAdventureMap()
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("遠征團地圖資訊",contents=_flex_adventure)
)
elif user_send == "@petadventureback":
if database.UserIsInAdventure(event.source.user_id) == False:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="沒有派處遠征軍喔!"))
return
_nowstatus = database.getUserAdventureStatus(event.source.user_id)
_adventure_result = rpgGame.checkAdventureResult(_nowstatus)
_user_job_json = database.getUserJob(event.source.user_id)
_user_job_json = rpgGame.addPlayerExp(_user_job_json,_adventure_result["total_exp"])
database.setUserJobStatus(event.source.user_id,_user_job_json)
database.AddUserMoneyByLineId(event.source.user_id,_adventure_result["total_money"])
database.ClearUserAdventureStatus(event.source.user_id)
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="已招回遠征軍隊!!\n獲得EXP : "+str(_adventure_result["total_exp"])+"\n獲得金錢 : "+str(_adventure_result["total_money"])))
elif user_send.startswith("@petadventureGoto"):
if database.UserIsInAdventure(event.source.user_id) == True:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="遠征隊已經出發了喔 要查看詳請可以進入寵物資訊頁面"))
return
try:
_map = user_send.split(" ")[1]
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage("指令格式有問題"))
return
_map_info = database.getAdventureMapInfo(_map)
database.setUserAdventureStatus(event.source.user_id,_map_info["map_id"])
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="掛機成功 記得要按時來領取冒險隊獎勵,最多累積24HR"))
elif user_send =="@showAuctionNpc":
_flex = lineMessagePackerRpg.getAuctionNpc()
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("世界拍賣",contents=_flex)
)
return
elif user_send =="@auctionlistWeapon":
_auction_list_info = database.getAuctionList("weapon")
if _auction_list_info is None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="目前拍賣場沒有人上架物品"))
return
_flex = lineMessagePackerRpg.getAuctionWeaponList(_auction_list_info)
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("拍賣裝備列表",contents=_flex)
)
return
elif user_send.startswith("@auctionbuyweapon"):
try:
_auction_id = int(user_send.split("@auctionbuyweapon")[1])
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="格式好像有問題ㄛ"))
return
#確認玩家是否達到武器上線
if database.getUserBackItemNum(event.source.user_id,"weapon") >= 60:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="裝備欄好像滿了喔 請確認或是清理"))
return
#獲取訂單資料
try:
auction = database.getAuction(_auction_id)
auction_info = auction["auction_info"]
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="該商品似乎不存在了 請再刷新一次試試看"))
return
#獲取使用者金錢資料
user_money = int(database.getUserMoney(event.source.user_id))
#可以購買 -> 新增該加成武器去買家 -> 移除拍賣場該筆訂單 -> 給予賣家金錢
if user_money >= int(auction_info["list_price"]):
#新增該武器去買家 並且扣款
user_money -= int(auction_info["list_price"])
database.SetUserMoneyByLineId(event.source.user_id,user_money)
_weapon_info = auction["weapon_json"]
hassame,loc = database.checkUserPackMaxLoc(event.source.user_id,"weapon",_weapon_info["weapon_id"])
database.addToUserBackPack(event.source.user_id,"weapon",_weapon_info["weapon_id"],1,hassame,loc)
database.addToUserWeaponWithEnhanced(event.source.user_id,_weapon_info["weapon_id"],loc,auction_info["str_add"],auction_info["int_add"],
auction_info["dex_add"],auction_info["atk_add"],auction_info["uses_reel"],auction_info["available_reeltime"],auction_info["description"],auction_info["success_time"])
#移除拍賣場訂單
database.removeAuction(_auction_id,auction_info["auction_line_id"])
#給予賣家金錢
seller_money = int(database.getUserMoney(auction_info["auction_line_id"]))
seller_money+= int(auction_info["list_price"])
database.SetUserMoneyByLineId(auction_info["auction_line_id"],seller_money)
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="購買成功! 已撥款給賣家 $"+str(auction_info["list_price"])))
return
#購買人同上架人 不給錢不扣錢
elif event.source.user_id == auction_info["auction_line_id"]:
_weapon_info = auction["weapon_json"]
hassame,loc = database.checkUserPackMaxLoc(event.source.user_id,"weapon",_weapon_info["weapon_id"])
database.addToUserBackPack(event.source.user_id,"weapon",_weapon_info["weapon_id"],1,hassame,loc)
database.addToUserWeaponWithEnhanced(event.source.user_id,_weapon_info["weapon_id"],loc,auction_info["str_add"],auction_info["int_add"],
auction_info["dex_add"],auction_info["atk_add"],auction_info["uses_reel"],auction_info["available_reeltime"],auction_info["description"],auction_info["success_time"])
#移除拍賣場訂單
database.removeAuction(_auction_id,auction_info["auction_line_id"])
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="購買人為上架者 成功下架商品"))
return
else:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="哦... 妳的錢好像不夠喔"))
return
elif user_send =="@auctionaddWeapon":
_nowlist = database.getAuctionList("weapon")
if _nowlist is not None:
if len(_nowlist) > 59:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="抱歉我的拍賣場最多只能販賣60把武器,請等武器下架或是被買走"))
return
_weapon_json_list = database.getUserEquipmentList(event.source.user_id)
_sendlist = []
_first = True
if len(_weapon_json_list)>12:
_temp = []
for _weapon in _weapon_json_list:
_temp.append(_weapon)
if len(_temp) == 12:
print(_temp)
_flex = lineMessagePackerRpg.getUserWeaponToAuctionList(_temp,_first)
_first = False
_sendlist.append(FlexSendMessage("裝備列表",contents=_flex))
_temp = []
_lastflex = lineMessagePackerRpg.getUserWeaponToAuctionList(_temp,_first)
_sendlist.append(FlexSendMessage("裝備列表",contents=_lastflex))
else:
_flex_equipment = lineMessagePackerRpg.getUserWeaponToAuctionList(_weapon_json_list,_first)
_sendlist.append(FlexSendMessage("裝備列表",contents=_flex_equipment))
line_bot_api.reply_message(
event.reply_token,_sendlist)
return
elif user_send.startswith("@auctionAddequipment"):
try:
_loc = int(user_send.split(" ")[1])
_price = int(user_send.split(" ")[2])
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage("資料格式好像有問題 請使用按鈕給的指令(@)開頭 -> 格式為: @auctionAddequipment ID 價格"))
return
if _price > 2000000000:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage("最大價格不可超過 20E"))
return
if _price < 0:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage("最小價格不可低於 0"))
return
#上架流程 -> 檢查該格是否真的有武器 -> 新增至拍賣系統 -> 移除使用者該武器 -> 扣除手續費用
_checkitem = database.getItemFromUserBackPack(event.source.user_id,_loc)
if _checkitem == None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="您並沒有這個裝備喔"))
return
#新增至拍賣系統
user_weapon = database.getValueFromUserWeapon(event.source.user_id,_loc)
database.addAuction(event.source.user_id,"weapon",user_weapon["weapon_id"],_price,user_weapon)
#移除使用者該武器
database.removeUserBackPack(event.source.user_id,_loc)
#扣除手續費用
_money = int(database.getUserMoney(event.source.user_id))
_money-= 5000
database.SetUserMoneyByLineId(event.source.user_id,_money)
_flex = lineMessagePackerRpg.getAuctionNpc()
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="上架成功! 酌收手續費用 $5000 請注意24小時以後會自動下架退回物品喔"),
FlexSendMessage("世界拍賣",contents=_flex)
])
return
elif user_send =="@wordboss":
# line_bot_api.reply_message(
# event.reply_token,
# TextSendMessage(text="世界王已消滅 獎勵已全數發放 敬請期待下一隻BOSS"),
# )
# return
#check word boss status
_wordboss_status = database.getWordBossStatus()
if _wordboss_status is None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="目前沒有世界王喔"),
)
return
_boss_basic_info = database.getWordBossInfo(_wordboss_status["boss_id"])
_user_word_boss_status = database.getWordBossUserList()
flex = wordBossFlexPacker.getWordBossInfo(_wordboss_status,_user_word_boss_status,_boss_basic_info)
_activeskills = database.getUserActiveSkillList(event.source.user_id)
if _activeskills != [] and len(_activeskills) > 0:
_skillflex = lineMessagePackerRpg.getUserActiveSkillsBoss(_activeskills)
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="Boss"),
FlexSendMessage("Boss",contents=flex),
FlexSendMessage("Boss!",contents=_skillflex)
])
else:
#無技能
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="Boss"),
FlexSendMessage("Boss",contents=flex)
])
return
elif user_send =="@attackWordBoss":
#check word boss status
_wordboss_status = database.getWordBossStatus()
# line_bot_api.reply_message(
# event.reply_token,
# TextSendMessage(text="世界王已消滅 獎勵已全數發放 敬請期待下一隻BOSS"),
# )
# return
if _wordboss_status is None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="目前沒有世界王喔"),
)
return
#測謊確認
try:
_userjobinfo = database.getUserJob(event.source.user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料有問題 請確認有加我好友 並且使用!info 建檔 接著透過@jobinfo進行創角"))
return
if _userjobinfo["word"] is None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="請先加入陣營在攻打世界王 => 冒險之旅 => 陣營系統"))
return
try:
if redistool.getValue(event.source.user_id) is None:
_random = random.randrange(1,100)
if _random <=5:
print("玩家 進入測謊")
from Games import questions
_question = questions.getRandomQuestionImage(event.source.user_id)
redistool.setKey(event.source.user_id,_question)
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage("內測期間防止流量問題 請輸入以下文字驗證後再繼續進行\n因快取問題如果驗證碼有問題請重新點選圖片即可獲得最新驗證碼\n 輸入正確會給予獎勵經驗值 驗證文字:\n"),
ImageSendMessage("https://mumu.tw/images/questions/"+event.source.user_id+".png","https://mumu.tw/images/questions/qlittle.png")
])
return
except:
print("測謊好像有問題")
_userstatus = database.getUserWordBossStatus(event.source.user_id)
if _userstatus is not None:
_time = _userstatus["last_atack_time"]
if _time is not None:
current = datetime.now()
_lasttime = datetime.strptime(_time,"%m/%d/%Y %H:%M:%S")
time_elapsed = (current-_lasttime) #經過的掛機時間
time_elapsed = math.floor(time_elapsed.total_seconds())
print("經過秒數:"+str(time_elapsed))
if time_elapsed < 10 and time_elapsed > 0: #超過10秒才能攻擊
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="屈服於Boss的強大的威脅,玩家只能10秒攻擊他一次"))
return
_userjob = database.getUserJob(event.source.user_id)
attackresult = rpgGame.attackBoss(event.source.user_id,_userjob)
database.addUserWordBossDamage(event.source.user_id,attackresult)
_boss_basic_info = database.getWordBossInfo(_wordboss_status["boss_id"])
_user_word_boss_status = database.getWordBossUserList()
_getreel = random.randrange(1,100)
_specialstr = ""
if _getreel <= 10:
_reellist = [2,6,9]
_reelchoose = random.choices(_reellist,weights=[100,10,5])[0]
database.givePlayerItem(event.source.user_id,"reel",_reelchoose,1)
_reelname = database.getUserUsingReel(_reelchoose)["reel_name"]
_specialstr = "恭喜獲得掉落物 "+_reelname
_money = random.randrange(100,4500)
_exp = random.randrange(2100,10000)
user_jobafterexp = rpgGame.addPlayerExp(_userjob,_exp)
database.AddUserMoneyByLineId(event.source.user_id,_money)
database.setUserJobStatus(event.source.user_id,user_jobafterexp)
database.addUserWordStatus(event.source.user_id,_userjob["word"],int(_money*0.5),int(_exp*0.5))
_specialstr+="\n金幣:"+str(_money)+" EXP:"+str(_exp)
flex = wordBossFlexPacker.getWordBossInfo(_wordboss_status,_user_word_boss_status,_boss_basic_info)
_activeskills = database.getUserActiveSkillList(event.source.user_id)
if _activeskills != [] and len(_activeskills) > 0:
_skillflex = lineMessagePackerRpg.getUserActiveSkillsBoss(_activeskills)
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="對boss造成傷害:"+str(attackresult)+_specialstr+"\n世界BOSS傷害與血量更新頻率為每分鐘更新一次"),
FlexSendMessage("Boss",contents=flex),
FlexSendMessage("Boss!",contents=_skillflex)
])
else:
#無技能
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="對boss造成傷害:"+str(attackresult)+_specialstr+"\n世界BOSS傷害與血量更新頻率為每分鐘更新一次"),
FlexSendMessage("Boss",contents=flex)])
return
elif user_send.startswith("@wordbossuseskill"):
# line_bot_api.reply_message(
# event.reply_token,
# TextSendMessage(text="世界王已消滅 獎勵已全數發放 敬請期待下一隻BOSS"),
# )
# return
try:
_skilljob = user_send.split(" ")[1]
_skillid = user_send.split(" ")[2]
_test = int(_skillid)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="指令好像有問題ㄛ 請盡量用按鈕謝謝"))
return
if _skilljob != 'rog' and _skilljob !='warrior' and _skilljob !='majic':
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="指令好像有問題ㄛ 請盡量用按鈕謝謝"))
return
try:
_userjobinfo = database.getUserJob(event.source.user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料有問題 請確認有加我好友 並且使用!info 建檔 接著透過@jobinfo進行創角"))
return
if _userjobinfo["word"] is None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="請先加入陣營在攻打世界王 => 冒險之旅 => 陣營系統"))
return
if database.checkUserHasSkill(event.source.user_id,_skillid,_skilljob) == True:
_skillinfo = database.getSkillFromUser(event.source.user_id,_skillid,_skilljob)
else:
_skillinfo = None
#check word boss status
_wordboss_status = database.getWordBossStatus()
if _wordboss_status is None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="目前沒有世界王喔"),
)
return
#測謊確認
try:
if redistool.getValue(event.source.user_id) is None:
_random = random.randrange(1,100)
if _random <=5:
print("玩家 進入測謊")
from Games import questions
_question = questions.getRandomQuestionImage(event.source.user_id)
redistool.setKey(event.source.user_id,_question)
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage("內測期間防止流量問題 請輸入以下文字驗證後再繼續進行\n因快取問題如果驗證碼有問題請重新點選圖片即可獲得最新驗證碼\n 輸入正確會給予獎勵經驗值 驗證文字:\n"),
ImageSendMessage("https://mumu.tw/images/questions/"+event.source.user_id+".png","https://mumu.tw/images/questions/qlittle.png")
])
return
except:
print("測謊好像有問題")
_userstatus = database.getUserWordBossStatus(event.source.user_id)
if _userstatus is not None:
_time = _userstatus["last_atack_time"]
if _time is not None:
current = datetime.now()
_lasttime = datetime.strptime(_time,"%m/%d/%Y %H:%M:%S")
time_elapsed = (current-_lasttime) #經過的掛機時間
time_elapsed = math.floor(time_elapsed.total_seconds())
print("經過秒數:"+str(time_elapsed))
if time_elapsed < 30 and time_elapsed > 0: #技能要超過30秒才能攻擊
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="屈服於Boss的強大的威脅,玩家技能只能30秒攻擊他一次"))
return
_userjob = database.getUserJob(event.source.user_id)
attackresult = rpgGame.attackBoss(event.source.user_id,_userjob,_skillinfo)
database.addUserWordBossDamage(event.source.user_id,attackresult)
_boss_basic_info = database.getWordBossInfo(_wordboss_status["boss_id"])
_user_word_boss_status = database.getWordBossUserList()
_getreel = random.randrange(1,100)
_specialstr = ""
if _getreel <= 10:
_reellist = [2,6,9]
_reelchoose = random.choices(_reellist,weights=[100,10,5])[0]
database.givePlayerItem(event.source.user_id,"reel",_reelchoose,1)
_reelname = database.getUserUsingReel(_reelchoose)["reel_name"]
_specialstr = "恭喜獲得掉落物 "+_reelname
_money = random.randrange(100,4500)
_exp = random.randrange(2100,10000)
user_jobafterexp = rpgGame.addPlayerExp(_userjob,_exp)
database.AddUserMoneyByLineId(event.source.user_id,_money)
database.setUserJobStatus(event.source.user_id,user_jobafterexp)
database.addUserWordStatus(event.source.user_id,_userjob["word"],int(_money*0.5),int(_exp*0.5))
_specialstr+="\n金幣:"+str(_money)+" EXP:"+str(_exp)
flex = wordBossFlexPacker.getWordBossInfo(_wordboss_status,_user_word_boss_status,_boss_basic_info)
_activeskills = database.getUserActiveSkillList(event.source.user_id)
if _activeskills != [] and len(_activeskills) > 0:
_skillflex = lineMessagePackerRpg.getUserActiveSkillsBoss(_activeskills)
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="使用技能對boss造成傷害:"+str(attackresult)+"\n"+_specialstr+"\n世界BOSS傷害與血量更新頻率為每分鐘更新一次"),
FlexSendMessage("Boss",contents=flex),
FlexSendMessage("Boss!",contents=_skillflex)
])
else:
#無技能
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="對boss造成傷害:"+str(attackresult)+"\n"+_specialstr+"\n世界BOSS傷害與血量更新頻率為每分鐘更新一次"),
FlexSendMessage("Boss",contents=flex)])
return
elif user_send =="@wordranklist":
try:
_userjobinfo = database.getUserJob(event.source.user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料有問題 請確認有加我好友 並且使用!info 建檔 接著透過@jobinfo進行創角"))
return
_word1 = database.getWordStatus(1)
_word2 = database.getWordStatus(2)
_word3 = database.getWordStatus(3)
_wordlist =[_word1,_word2,_word3]
_wordlist.sort(key=lambda word:(word["word_level"],word["word_money"]),reverse=True)
print(_wordlist)
_w1top1 = database.getWordRank1(_wordlist[0]["word_id"])
_w1top1 = database.getUserName(_w1top1)
_w2top1 = database.getWordRank1(_wordlist[1]["word_id"])
_w2top1 = database.getUserName(_w2top1)
_w3top1 = database.getWordRank1(_wordlist[2]["word_id"])
_w3top1 = database.getUserName(_w3top1)
_top5list = [_w1top1,_w2top1,_w3top1]
_levellist = []
_levellist.append(database.getWordlevelList(_wordlist[0]["word_level"]))
_levellist.append(database.getWordlevelList(_wordlist[1]["word_level"]))
_levellist.append(database.getWordlevelList(_wordlist[2]["word_level"]))
flex = wordGuideFlexPacker.getWordGuideStatusList(_wordlist,_top5list,_levellist)
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="陣營狀態"),
FlexSendMessage("陣營",contents=flex)
])
return
elif user_send =="@wordguidemenu":
try:
_userjobinfo = database.getUserJob(event.source.user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料有問題 請確認有加我好友 並且使用!info 建檔 接著透過@jobinfo進行創角"))
return
if _userjobinfo["word"] is None:
flex = lineMessagePackerRpg.getWordJoinMenu()
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="看來你還沒有陣營呢 這是勢力地圖,是否要加入勢力呢?"),
ImageSendMessage(original_content_url="https://mumu.tw/images/game_ui/wordmap.png",preview_image_url="https://mumu.tw/images/game_ui/wordmap.png"),
FlexSendMessage("勢力選擇",contents=flex)
])
else:
menu = lineMessagePackerRpg.getGuideMenu()
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("陣營選單",contents=menu)
)
return
elif user_send =="@wordguide":
try:
_userjobinfo = database.getUserJob(event.source.user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料有問題 請確認有加我好友 並且使用!info 建檔 接著透過@jobinfo進行創角"))
return
if _userjobinfo["word"] is None:
flex = lineMessagePackerRpg.getWordJoinMenu()
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="看來你還沒有陣營呢 這是勢力地圖,是否要加入勢力呢?"),
ImageSendMessage(original_content_url="https://mumu.tw/images/game_ui/wordmap.png",preview_image_url="https://mumu.tw/images/game_ui/wordmap.png"),
FlexSendMessage("勢力選擇",contents=flex)
])
else:
_userword = _userjobinfo["word"]
_wordinfo = database.getWordStatus(_userword)
_wordlevelinfo = database.getWordlevelList(_wordinfo["word_level"])
_top1 = database.getWordRank1(_userword)
if _top1 is None:
_top1 = "從缺"
else:
top1name = database.getUser(_top1)["user_line_name"]
_userwordinfo = database.getUserWordStatus(event.source.user_id,_userword)
flex = lineMessagePackerRpg.getWordGuideStatus(_wordinfo,_userwordinfo,top1name,_wordlevelinfo)
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("勢力狀態",contents=flex)
)
elif user_send == "@worduplevel":
try:
_userjobinfo = database.getUserJob(event.source.user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料有問題 請確認有加我好友 並且使用!info 建檔 接著透過@jobinfo進行創角"))
return
_userword = _userjobinfo["word"]
_top1 = database.getWordRank1(_userword)
if event.source.user_id != _top1:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="只有陣營國王有權力進行陣營等級提升"))
return
_wordinfo = database.getWordStatus(_userword)
_wordlevelinfo = database.getWordlevelList(_wordinfo["word_level"])
if _wordinfo["word_money"] >= _wordlevelinfo["next_level_money"] and _wordinfo["word_exp"] >= _wordlevelinfo["next_level_exp"]:
_wordinfo["word_level"] += 1
_wordinfo["word_money"] -= _wordlevelinfo["next_level_money"]
_wordinfo["word_exp"] -= _wordlevelinfo["next_level_exp"]
database.updateWordStatus(_wordinfo["word_id"],_wordinfo["word_level"],_wordinfo["word_exp"],_wordinfo["word_money"])
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="陣營已成功升等至:"+str(_wordinfo["word_level"])))
return
else:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="陣營似乎不滿足升等條件呢"))
return
elif user_send.startswith("@joinword"):
try:
word = user_send.split("@joinword")[1]
word = int(word)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="資料有問題 請使用按鈕加入"))
return
try:
_userjobinfo = database.getUserJob(event.source.user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="沒有冒險家資料 請確認已經加我好友 並且透過!info 與 @jobinfo 建檔"))
return
if _userjobinfo["word"] is None:
_userjobinfo["word"] = word
database.setUserJobStatus(event.source.user_id,_userjobinfo)
database.joinUserWord(event.source.user_id,word)
database.addWordMoneyExp(word,1000,1000)
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="加入陣營成功 可透過陣營頁面瀏覽詳細資料"))
return
else:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="你已經有加入陣營囉..."))
return
elif user_send == "@jobinfo":
user_id = event.source.user_id
try:
profile = line_bot_api.get_profile(user_id)
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="看來你沒有加我好友! 請先加我好友喔"))
if database.checkUserHasJob(event.source.user_id) == False:
_replyflex = lineMessagePackerRpg.getCreaterJobList()
line_bot_api.reply_message(
event.reply_token,[
TextSendMessage(text="看來你好像還沒成為冒險家呢 請選擇職業吧!"),
FlexSendMessage("職業資料",contents=_replyflex)])
return
_jobjson = database.getUserJob(event.source.user_id)
profile = line_bot_api.get_profile(event.source.user_id)
user_line_img = str(profile.picture_url)
if user_line_img.startswith("https") is False:
user_line_img = 'https://mumu.tw/images/game_ui/job_bkg.jpg'
_rank = database.getUserRpgRank(event.source.user_id)
_weapon = database.getUserEquipmentWeapon(event.source.user_id)
_packagejson = lineMessagePackerRpg.getJobInfo(user_line_img,_jobjson,_rank,_weapon)
_flex_sub_menu = lineMessagePackerRpg.getJobInfoSubMenu()
line_bot_api.reply_message(
event.reply_token,[
FlexSendMessage("職業資料",contents=_packagejson),
FlexSendMessage("職業資料",contents=_flex_sub_menu)
])
elif user_send =="@exper":
if database.checkUserHasJob(event.source.user_id) == False:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage("你還沒有創建冒險者喔\n請先使用 !info 裡面的冒險者之旅按鈕開始旅程"))
return
if database.getUserJob(event.source.user_id)["hp"] <= 0:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage("你沒有錢了... 想辦法賺錢復活吧 復活指令: @health"))
return
_reply = lineMessagePackerRpg.getExperList()
line_bot_api.reply_message(
event.reply_token,
FlexSendMessage("冒險列表",contents=_reply))
elif user_send == "@equipment":
_weapon_json_list = database.getUserEquipmentList(event.source.user_id)
_sendlist = []
_first = True
if len(_weapon_json_list)>12:
_temp = []
for _weapon in _weapon_json_list:
_temp.append(_weapon)
if len(_temp) == 12:
print("超過12把 送一次")
print(_temp)
_flex = lineMessagePackerRpg.getEquipmentList(_temp,_first)
_first = False
_sendlist.append(FlexSendMessage("裝備列表",contents=_flex))
_temp = []
_lastflex = lineMessagePackerRpg.getEquipmentList(_temp,_first)
_sendlist.append(FlexSendMessage("裝備列表",contents=_lastflex))
else:
_flex_equipment = lineMessagePackerRpg.getEquipmentList(_weapon_json_list,_first)
_sendlist.append(FlexSendMessage("裝備列表",contents=_flex_equipment))
line_bot_api.reply_message(
event.reply_token,_sendlist)
return
elif user_send.startswith("@changeequipment"):
try:
loc = int(user_send.split(" ")[1])
except:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="裝備編號好像有問題呢.."))
return
_checkitem = database.getItemFromUserBackPack(event.source.user_id,loc)
if _checkitem == None:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="您並沒有這個裝備喔"))
return
elif _checkitem["item_type"] != "weapon":
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="這個編號不是可裝備武器 請在確認!"))
return
database.changeEquipmentWeapon(event.source.user_id,loc)
_user_job = database.getUserJob(event.source.user_id)
_noweapon = database.getUserEquipmentWeapon(event.source.user_id)
_maxhp = rpgGame.getMaxHp(_user_job["job"],_user_job["level"])
#確認武器加乘血量
try:
hp_add = _noweapon["other_effect"]["hp_add"]
if "%" in hp_add:
hp_add = int(hp_add.split("%")[0])
hp_add/=100
hp_add = _maxhp*hp_add
else:
hp_add = int(hp_add)
hp_add = hp_add
except:
hp_add = 0
_maxhp+=hp_add
if _user_job["hp"] >= _maxhp:
_user_job["hp"] = _maxhp
database.setUserJobStatus(event.source.user_id,_user_job)
_weapon_json_list = database.getUserEquipmentList(event.source.user_id)
_sendlist = []
_first = True
_sendlist.append(TextSendMessage(text="切換裝備成功"))
if len(_weapon_json_list)>12:
_temp = []
for _weapon in _weapon_json_list:
_temp.append(_weapon)