-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge_StreamlabsSystem.py
More file actions
235 lines (218 loc) · 13.1 KB
/
challenge_StreamlabsSystem.py
File metadata and controls
235 lines (218 loc) · 13.1 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
#---------------------------
# Import Libraries
#---------------------------
import os
import sys
libFolder = os.path.join(os.path.dirname(__file__), "lib")
sys.path.append(libFolder)
import Fighter
# chatbot won't load a script that doesn't define these variables
ScriptName = "Challenge"
Website = "https://streamlabs.com"
Description = "Fire Emblem Combat simulator game"
Creator = "StreamMin"
Version = "1.0.0"
# global data used by the script
userLineNumber = 0
recordFile = "challenge_record.txt"
configFile = "config.json"
path = ''
records = []
settings = {}
def writeTextFile(filename,content):
with open(filename,"w") as f:
f.writelines("%s\n" % line for line in content)
f.close()
def readTextFile(filename):
with open(filename,"r") as f:
data = f.readlines()
data = [line.rstrip("\n") for line in data]
f.close()
return data
def openRecordsFile():
location = os.path.join(os.path.dirname(__file__), recordFile)
os.startfile(location)
return
# called when your script starts up
def Init():
global settings, configFile, path
path = os.path.dirname(__file__)
try:
with codecs.open(os.path.join(path, configFile), encoding='utf-8-sig', mode='r') as file:
settings = json.load(file, encoding='utf-8-sig')
except:
settings = {
"liveOnly": True,
"permission": "Everyone",
"minReward": 1,
"maxReward": 10,
"cooldown": 60,
"maxChallenger": 1
}
# called whenever the chatbot has data - chat messages, whispers, etc. - that
# your script might care about
def Execute(data):
global userLineNumber, winLossRecord, scriptDirectory, recordFile, records
if data.IsChatMessage() and data.GetParam(0).lower() == '!challenge' and Parent.HasPermission(data.User, settings["permission"], ""):
try:
cooldownCheck = Parent.IsOnCooldown(ScriptName,'!challenge')
if not cooldownCheck:
Parent.AddCooldown(ScriptName,"!challenge",settings["cooldown"]) # Put the command on cooldown
user = data.UserName
userFound = False
userLineNumber = 0
recordPath = os.path.join(path, recordFile)
records = readTextFile(recordPath)
for line in records:
if line[line.find("name") + 5:line.find("weapon1")-1] == user:
fightState = line[line.find("fight") + 6:line.find("record")-1]
if fightState == "True": # Continue the FIGHT!
userWeapon = line[line.find("weapon1") + 8:line.find("weapon2")-1]
userHitPoints = int(line[line.find("HP1") + 4:line.find("HP2")-1])
challenger = Fighter.fighter(user,weapon = userWeapon, hitPoints = userHitPoints)
challenger.setWeaponStats()
sigrdminWeapon = line[line.find("weapon2") + 8:line.find("HP1")-1]
sigrdminHitPoints = int(line[line.find("HP2") + 4:line.find("fight")-1])
sigrdmin = Fighter.fighter("SIGRDMIN",weapon = sigrdminWeapon, hitPoints = sigrdminHitPoints)
sigrdmin.setWeaponStats()
winLossRecord = line[line.find("record") + 7:len(line)]
userFound = True
break
else: # Start a new FIGHT!
challenger = Fighter.fighter(user)
randomWeapon = Parent.GetRandom(0,3)
userWeapon = challenger.pickWeaponUser(randomWeapon)
challenger.setWeaponStats()
sigrdmin = Fighter.fighter("SIGRDMIN")
randomWeapon = Parent.GetRandom(0,4)
sigrdminWeapon = sigrdmin.pickWeaponSigurd(randomWeapon)
sigrdmin.setWeaponStats()
winLossRecord = line[line.find("record") + 7:len(line)]
userFound = True
break
userLineNumber += 1
if userFound == False:
challenger = Fighter.fighter(user)
randomWeapon = Parent.GetRandom(0,3)
userWeapon = challenger.pickWeaponUser(randomWeapon)
challenger.setWeaponStats()
sigrdmin = Fighter.fighter("SIGRDMIN")
randomWeapon = Parent.GetRandom(0,4)
sigrdminWeapon = sigrdmin.pickWeaponSigurd(randomWeapon)
sigrdmin.setWeaponStats()
winLossRecord = "0-0"
Parent.SendStreamMessage("| " + user + " ( HP : " + str(challenger.returnHP()) + " )" + " vs. " + sigrdmin.returnName() + " ( HP : " + str(sigrdmin.returnHP()) + " )" + " |")
Parent.SendStreamMessage(sigrdmin.returnName() + " unsheathes " + sigrdminWeapon + "! " + user + " unsheathes " + userWeapon + "!")
initiative = Parent.GetRandom(0,2)
if initiative == 0:
initiativeFighter = user
secondFighter = sigrdmin.returnName()
hitRoll = Parent.GetRandom(0,100)
initiativeState = challenger.getAttackState(hitRoll)
quoteLength = len(initiativeState)
if initiativeState[quoteLength - 7: quoteLength] != "misses!":
Parent.SendStreamMessage(str(challenger.returnDamage()))
sigrdmin.takeDamage(challenger.returnDamage())
else:
initiativeFighter = sigrdmin.returnName()
Parent.SendStreamMessage(sigrdmin.pickAttack())
secondFighter = user
hitRoll = Parent.GetRandom(0,100)
initiativeState = sigrdmin.getAttackState(hitRoll)
quoteLength = len(initiativeState)
if initiativeState[quoteLength - 7: quoteLength] != "misses!":
challenger.takeDamage(sigrdmin.returnDamage())
Parent.SendStreamMessage(initiativeFighter + " has the initiative! " + initiativeFighter + initiativeState)
if initiativeFighter == user:
if int(sigrdmin.returnHP()) != int(0):
hitRoll = Parent.GetRandom(0,100)
counterState = sigrdmin.getAttackState(hitRoll)
quoteLength = len(counterState)
if counterState[quoteLength - 7: quoteLength] != "misses!":
challenger.takeDamage(sigrdmin.returnDamage())
Parent.SendStreamMessage(sigrdmin.pickAttack())
Parent.SendStreamMessage(secondFighter + " retaliates! " + secondFighter + counterState)
if int(challenger.returnHP()) != int(0):
if userFound == False:
records.append("name=" + user + " weapon1=" + userWeapon + " weapon2=" + sigrdminWeapon + " HP1=" + str(challenger.returnHP()) + " HP2=" + str(sigrdmin.returnHP()) + " fight=True record=" + winLossRecord)
else:
records[userLineNumber] = "name=" + user + " weapon1=" + userWeapon + " weapon2=" + sigrdminWeapon + " HP1=" + str(challenger.returnHP()) + " HP2=" + str(sigrdmin.returnHP()) + " fight=True record=" + winLossRecord
writeTextFile(recordPath,records)
Parent.SendStreamMessage(sigrdmin.pickSurvive())
Parent.SendStreamMessage(" | CURRENT SITUATION : " + user + " ( HP : " + str(challenger.returnHP()) + " )" + " vs. " + sigrdmin.returnName() + " ( HP : " + str(sigrdmin.returnHP()) + " )" + " |")
else:
sigrdminScore = winLossRecord[winLossRecord.find("-") + 1:]
updatedRecord = winLossRecord[:winLossRecord.find("-") +1] + str(int(sigrdminScore) + 1)
if userFound == False:
records.append("name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord)
else:
records[userLineNumber] = "name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord
writeTextFile(recordPath,records)
Parent.SendStreamMessage(sigrdmin.pickVictory())
Parent.SendStreamMessage(" | CURRENT RECORD: " + user + " " + updatedRecord + " " + sigrdmin.returnName() + " |")
else:
usrScore = winLossRecord[:winLossRecord.find("-")]
updatedRecord = str(int(usrScore) + 1) + winLossRecord[winLossRecord.find("-"):]
if userFound == False:
records.append("name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord)
else:
records[userLineNumber] = "name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord
writeTextFile(recordPath,records)
Parent.SendStreamMessage(sigrdmin.pickDefeat())
Parent.SendStreamMessage(" | CURRENT RECORD: " + user + " " + updatedRecord + " " + sigrdmin.returnName() + " |")
elif initiativeFighter == sigrdmin.returnName():
if int(challenger.returnHP()) != int(0):
hitRoll = Parent.GetRandom(0,100)
counterState = challenger.getAttackState(hitRoll)
quoteLength = len(counterState)
if counterState[quoteLength - 7: quoteLength] != "misses!":
sigrdmin.takeDamage(challenger.returnDamage())
Parent.SendStreamMessage(secondFighter + " retaliates! " + secondFighter + counterState)
if int(sigrdmin.returnHP()) != int(0):
if userFound == False:
records.append("name=" + user + " weapon1=" + userWeapon + " weapon2=" + sigrdminWeapon + " HP1=" + str(challenger.returnHP()) + " HP2=" + str(sigrdmin.returnHP()) + " fight=True record=" + winLossRecord)
else:
records[userLineNumber] = "name=" + user + " weapon1=" + userWeapon + " weapon2=" + sigrdminWeapon + " HP1=" + str(challenger.returnHP()) + " HP2=" + str(sigrdmin.returnHP()) + " fight=True record=" + winLossRecord
writeTextFile(recordPath,records)
Parent.SendStreamMessage(sigrdmin.pickSurvive())
Parent.SendStreamMessage(" | CURRENT SITUATION : " + user + " ( HP : " + str(challenger.returnHP()) + " )" + " vs. " + sigrdmin.returnName() + " ( HP : " + str(sigrdmin.returnHP()) + " )" + " |")
else:
userScore = winLossRecord[:winLossRecord.find("-")]
updatedRecord = str(int(userScore) + 1) + winLossRecord[winLossRecord.find("-"):]
if userFound == False:
records.append("name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord)
else:
records[userLineNumber] = "name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord
writeTextFile(recordPath,records)
Parent.SendStreamMessage(sigrdmin.pickDefeat())
Parent.SendStreamMessage(" | CURRENT RECORD: " + user + " " + updatedRecord + " " + sigrdmin.returnName() + " |")
else:
sigrdminScore = winLossRecord[winLossRecord.find("-") + 1:]
updatedRecord = winLossRecord[:winLossRecord.find("-") +1] + str(int(sigrdminScore) + 1)
if userFound == False:
records.append("name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord)
else:
records[userLineNumber] = "name=" + user + " weapon1= weapon2= HP1= HP2= fight=False record=" + updatedRecord
writeTextFile(recordPath,records)
Parent.SendStreamMessage(sigrdmin.pickVictory())
Parent.SendStreamMessage(" | CURRENT RECORD: " + user + " " + updatedRecord + " " + sigrdmin.returnName() + " |")
except:
pass
# called frequently to mark the passage of time; if there's some condition
# your bot wants to act on *other* than data from the bot, and if you can
# write code that watches for that condition, it can go here; but beware this
# gets run frequently, so if the check is resource-intensive then you don't
# want to run it on *every* tick
def Tick():
return
#---------------------------
# Parse method (Allows you to create your own custom $parameters) TODO: Print leaderboard against Sigrdmin
#---------------------------
"""
def Parse(parseString, userid, username, targetid, targetname, message):
if "$myparameter" in parseString:
return parseString.replace("$myparameter","I am a cat!")
return parseString
"""
def Unload():
return