Skip to content

Commit b9a99db

Browse files
authored
Added headshake and hurricane (#58)
1 parent 11ce1b4 commit b9a99db

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "simonsays_drgreengiant"
7-
version = "2.0.3"
7+
version = "2.0.4"
88
authors = [{ name = "Simon Howroyd", email = "[email protected]" }]
99
description = "A Twitch Plays style programme to allow users in Twitch chats to control the broadcasters mouse and keyboard"
1010
keywords = ["twitch", "chat", "twitchplays", "troll"]

src/simonsays_drgreengiant/phasmoactions.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,60 @@ def distance(self) -> int:
791791
#####################################################################
792792

793793

794+
@dataclasses.dataclass(slots=True)
795+
class Headshake(GenericActionBase):
796+
"""Look left and right repeatedly"""
797+
name: str = "headshake"
798+
chained: bool = True
799+
800+
def run(self, *, force: bool = False) -> errorcodes.ErrorSet:
801+
"""Run the action"""
802+
actionconfig: HeadshakeConfig = self.config
803+
repeats = actionconfig.repeats
804+
pause = actionconfig.pause
805+
806+
if DEBUG:
807+
print(f"Headshake: repeats={repeats}, pause={pause}")
808+
809+
distance = actionconfig.distance or DEFAULTS.PEEK_DISTANCE
810+
811+
lookleft = hidactions.MoveMouseRelativeDirectionSmooth(hidactions.MouseMoveDirectionSmoothActionConfig(distance, hidactions.MouseMoveDirection.LEFT))
812+
lookright = hidactions.MoveMouseRelativeDirectionSmooth(hidactions.MouseMoveDirectionSmoothActionConfig(distance, hidactions.MouseMoveDirection.RIGHT))
813+
814+
once = actions.ActionSequence([lookleft, actions.Wait(pause), lookright])
815+
return actions.ActionRepeatWithWait(once, repeats, actions.Wait(pause)).run(force=force)
816+
817+
818+
@dataclasses.dataclass(slots=True)
819+
class HeadshakeConfig:
820+
"""Look left and right repeatedly config"""
821+
hidconfig: hidactions.Config = None
822+
_pause: float = 0.33
823+
_repeats: tuple[int] = dataclasses.field(default_factory=lambda: (5, 10))
824+
_distance: int = DEFAULTS.PEEK_DISTANCE
825+
826+
def __post_init__(self) -> None:
827+
if not isinstance(self._repeats, tuple):
828+
self._repeats = tuple(self._repeats)
829+
830+
@property
831+
def pause(self) -> float:
832+
"""Get the pause"""
833+
return self._pause
834+
835+
@property
836+
def repeats(self) -> int:
837+
"""Get the repeats"""
838+
return random.randint(*self._repeats)
839+
840+
@property
841+
def distance(self) -> int:
842+
"""Get the distance"""
843+
return self._distance
844+
845+
#####################################################################
846+
847+
794848
@dataclasses.dataclass(slots=True)
795849
class Yoga(GenericAction):
796850
"""Look up to the sky"""
@@ -913,6 +967,64 @@ class TornadoConfig:
913967
_mousemovedirection: hidactions.MouseMoveDirection = None
914968
_distance: int = DEFAULTS.LOOK_DISTANCE
915969

970+
@property
971+
def pause(self) -> float:
972+
"""Get the pause"""
973+
return self._pause
974+
975+
@property
976+
def repeats(self) -> int:
977+
"""Get the repeats"""
978+
return self._repeats
979+
980+
@property
981+
def mousemovedirection(self) -> hidactions.MouseMoveDirection:
982+
"""Get the mouse move direction"""
983+
return self._mousemovedirection or random.choice(list([hidactions.MouseMoveDirection.RIGHT, hidactions.MouseMoveDirection.LEFT]))
984+
985+
@property
986+
def distance(self) -> int:
987+
"""Get the distance"""
988+
return self._distance
989+
#####################################################################
990+
991+
992+
@dataclasses.dataclass(slots=True)
993+
class Hurricane(GenericActionBase):
994+
"""Spin on the spot whilst using items"""
995+
name: str = "hurricane"
996+
chained: bool = True
997+
998+
def run(self, *, force: bool = False) -> errorcodes.ErrorSet:
999+
"""Run the action"""
1000+
actionconfig: TornadoConfig = self.config
1001+
1002+
cfg = hidactions.MouseMoveDirectionSmoothActionConfig(actionconfig.distance,
1003+
actionconfig.mousemovedirection,
1004+
pause=actionconfig.pause)
1005+
1006+
look = hidactions.MoveMouseRelativeDirectionSmooth(cfg)
1007+
lookfar = actions.ActionRepeat(look, actionconfig.repeats)
1008+
useconfig = Use(self.config_fn).config.hidconfig
1009+
useaction = hidactions.PressReleaseKeyOrButton(useconfig, delay=0.01)
1010+
dropconfig = Drop(self.config_fn).config.hidconfig
1011+
dropaction = hidactions.PressReleaseKeyOrButton(dropconfig, delay=0.01)
1012+
switchaction = Switch(self.config_fn)
1013+
1014+
lookanduse = actions.ActionSequence([lookfar, useaction, dropaction, switchaction])
1015+
1016+
return actions.ActionRepeat(lookanduse, 4).run(force=force)
1017+
1018+
1019+
@dataclasses.dataclass(slots=True)
1020+
class HurricaneConfig:
1021+
"""Spin on the spot whilst using items config"""
1022+
hidconfig: hidactions.Config = None
1023+
_pause: float = 0.005
1024+
_repeats: int = 4
1025+
_mousemovedirection: hidactions.MouseMoveDirection = None
1026+
_distance: int = DEFAULTS.LOOK_DISTANCE
1027+
9161028
@property
9171029
def pause(self) -> float:
9181030
"""Get the pause"""
@@ -999,10 +1111,12 @@ def _get_all(config_fn: gameactions.ConfigFn) -> gameactions.ActionAndConfigDict
9991111
DropAllItems(None).name: gameactions.ActionAndConfig(DropAllItems, DropAllItemsConfig()),
10001112
Spin(None).name: gameactions.ActionAndConfig(Spin, SpinConfig()),
10011113
Headbang(None).name: gameactions.ActionAndConfig(Headbang, HeadbangConfig()),
1114+
Headshake(None).name: gameactions.ActionAndConfig(Headshake, HeadshakeConfig()),
10021115
Yoga(None).name: gameactions.ActionAndConfig(Yoga, YogaConfig()),
10031116
Feet(None).name: gameactions.ActionAndConfig(Feet, FeetConfig()),
10041117
Freeze(None).name: gameactions.ActionAndConfig(Freeze, FreezeConfig()),
10051118
Tornado(None).name: gameactions.ActionAndConfig(Tornado, TornadoConfig()),
1119+
Hurricane(None).name: gameactions.ActionAndConfig(Hurricane, HurricaneConfig()),
10061120
}
10071121

10081122

@@ -1070,10 +1184,12 @@ def all_actions(config_fn: gameactions.ConfigFn) -> list[gameactions.Action]:
10701184
DropAllItems(config_fn),
10711185
Spin(config_fn),
10721186
Headbang(config_fn),
1187+
Headshake(config_fn),
10731188
Yoga(config_fn),
10741189
Feet(config_fn),
10751190
Freeze(config_fn),
10761191
Tornado(config_fn),
1192+
Hurricane(config_fn),
10771193
]
10781194

10791195

@@ -1119,8 +1235,10 @@ def default_config() -> gameactions.Config:
11191235
DropAllItems(None).name: DropAllItemsConfig(),
11201236
Spin(None).name: SpinConfig(),
11211237
Headbang(None).name: HeadbangConfig(),
1238+
Headshake(None).name: HeadshakeConfig(),
11221239
Yoga(None).name: YogaConfig(),
11231240
Feet(None).name: FeetConfig(),
11241241
Freeze(None).name: FreezeConfig(),
11251242
Tornado(None).name: TornadoConfig(),
1243+
Hurricane(None).name: HurricaneConfig(),
11261244
})

0 commit comments

Comments
 (0)