forked from bombsquad-community/plugin-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable_friendly_fire.py
112 lines (83 loc) · 4.11 KB
/
disable_friendly_fire.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
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
# Ported to api 8 by brostos using baport.(https://github.com/bombsquad-community/baport)
# ba_meta require api 8
from __future__ import annotations
from typing import TYPE_CHECKING
import babase
import bauiv1 as bui
import bascenev1 as bs
import bascenev1lib
from bascenev1lib.gameutils import SharedObjects
if TYPE_CHECKING:
pass
class BombPickupMessage:
""" message says that someone pick up the dropped bomb """
# for bs.FreezeMessage
freeze: bool = True
# ba_meta export plugin
class Plugin(babase.Plugin):
# there are two ways to ignore our team player hits
# either change playerspaz handlemessage or change spaz handlemessage
def playerspaz_new_handlemessage(func: fuction) -> fuction:
def wrapper(*args, **kwargs):
global freeze
# only run if session is dual team
if isinstance(args[0].activity.session, bs.DualTeamSession):
# when spaz got hurt by any reason this statement is runs.
if isinstance(args[1], bs.HitMessage):
our_team_players: list[type(args[0]._player)]
# source_player
attacker = args[1].get_source_player(type(args[0]._player))
# our team payers
our_team_players = args[0]._player.team.players.copy()
if len(our_team_players) > 0:
# removing our self
our_team_players.remove(args[0]._player)
# if we honding teammate or if we have a shield, do hit.
for player in our_team_players:
if player.actor.exists() and args[0]._player.actor.exists():
if args[0]._player.actor.node.hold_node == player.actor.node or args[0]._player.actor.shield:
our_team_players.remove(player)
break
if attacker in our_team_players:
freeze = False
return None
else:
freeze = True
# if ice_bomb blast hits any spaz this statement runs.
elif isinstance(args[1], bs.FreezeMessage):
if not freeze:
freeze = True # use it and reset it
return None
# orignal unchanged code goes here
func(*args, **kwargs)
return wrapper
# replace original fuction to modified function
bascenev1lib.actor.playerspaz.PlayerSpaz.handlemessage = playerspaz_new_handlemessage(
bascenev1lib.actor.playerspaz.PlayerSpaz.handlemessage)
# let's add a message when bomb is pick by player
def bombfact_new_init(func: function) -> function:
def wrapper(*args):
func(*args) # original code
args[0].bomb_material.add_actions(
conditions=('they_have_material', SharedObjects.get().pickup_material),
actions=('message', 'our_node', 'at_connect', BombPickupMessage()),
)
return wrapper
# you get the idea
bascenev1lib.actor.bomb.BombFactory.__init__ = bombfact_new_init(
bascenev1lib.actor.bomb.BombFactory.__init__)
def bomb_new_handlemessage(func: function) -> function:
def wrapper(*args, **kwargs):
# only run if session is dual team
if isinstance(args[0].activity.session, bs.DualTeamSession):
if isinstance(args[1], BombPickupMessage):
# get the pickuper and assign the pickuper to the source_player(attacker) of bomb blast
for player in args[0].activity.players:
if player.actor.exists():
if player.actor.node.hold_node == args[0].node:
args[0]._source_player = player
break
func(*args, **kwargs) # original
return wrapper
bascenev1lib.actor.bomb.Bomb.handlemessage = bomb_new_handlemessage(
bascenev1lib.actor.bomb.Bomb.handlemessage)