This repository has been archived by the owner on Jul 31, 2021. It is now read-only.
forked from roguelike2d/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 4
/
_TekkenBotLauncher.py
72 lines (57 loc) · 2.54 KB
/
_TekkenBotLauncher.py
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
import math
import random
import time
from TekkenEncyclopedia import TekkenEncyclopedia
from ArtificialKeyboard import ArtificalKeyboard
import GameInputter
import TekkenGameState
import BasicCommands
from BotFrameTrap import BotFrameTrap
from BotPunisher import BotPunisher
from BotRecorder import BotRecorder
#print("ADMIN STATUS: " + str(c.windll.shell32.IsUserAnAdmin()))
class TekkenBotLauncher:
def __init__(self, botClass, isPlayerOne):
self.gameState = TekkenGameState.TekkenGameState()
self.gameController = GameInputter.GameControllerInputter()
self.botCommands = BasicCommands.BotCommands(self.gameController)
self.botBrain = botClass(self.botCommands)
self.benchmarkTime = time.time()
self.frameRateCounter = 0
self.frameRate = 0
self.isPlayerOne = isPlayerOne
self.doMashAccept = False #before turning this on, make sure that your 'accept' key and your '3' key are different in GameControllerInputter.
def Update(self):
successfulUpdate = self.gameState.Update()
if self.gameState.IsGameHappening() and successfulUpdate:
self.frameRateCounter += 1
if not self.isPlayerOne:
self.gameState.FlipMirror()
self.gameController.Update(self.gameState.IsForegroundPID(), self.gameState.IsBotOnLeft())
self.botCommands.Update(self.gameState)
self.botBrain.Update(self.gameState)
if not self.isPlayerOne:
self.gameState.FlipMirror()
if self.doMashAccept:
self.MashAccept()
elapsedTime = time.time() - self.benchmarkTime
if elapsedTime >= 1:
self.frameRate = self.frameRateCounter / elapsedTime
self.frameRateCounter = 0
self.benchmarkTime = time.time()
if self.frameRate < 31:
pass
#print("WARNING! FRAME RATE IS LESS THAN 30 FPS (" + str(int(self.frameRate)) + "). TEKKEN BOT MAY BEHAVE ERRATICALLY.")
def GetBot(self):
return self.botBrain
def MashAccept(self): #Useful for Treasure Mode
if self.gameState.IsForegroundPID():
if (random.randint(0, 1) == 0):
ArtificalKeyboard.PressKey(GameInputter.Keys_P2.A)
else:
ArtificalKeyboard.ReleaseKey(GameInputter.Keys_P2.A)
if __name__ == "__main__":
launcher = TekkenBotLauncher(BotRecorder, True)
while(True):
launcher.Update()
time.sleep(.005)