From 344f312ab8e38921bcc0bf51e9c68af5f97ba42c Mon Sep 17 00:00:00 2001 From: Daniele Pantaleone Date: Mon, 6 Jul 2015 00:00:22 +0200 Subject: [PATCH] [TK] added interface with spawnkill plugin --- b3/conf/plugin_tk.ini | 3 +++ b3/plugins/tk/CHANGELOG | 1 + b3/plugins/tk/__init__.py | 40 +++++++++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/b3/conf/plugin_tk.ini b/b3/conf/plugin_tk.ini index b1902d057..132cba12b 100644 --- a/b3/conf/plugin_tk.ini +++ b/b3/conf/plugin_tk.ini @@ -32,6 +32,9 @@ halflife: 0 ## warn_duration: how long should tk warnings remain active. 30m = thirty minutes, 1h = one hour, 2d = two days warn_duration: 1h +## extra TK points to be given when team spawnkilling is detected (requires Spawnkill Plugin enabled). (0 = disabled) +team_spawnkill_extra_points: 100 + [messages] ## ban: message given to banned players as a reason ban: ^7team damage over limit diff --git a/b3/plugins/tk/CHANGELOG b/b3/plugins/tk/CHANGELOG index cc8177419..eb1492170 100644 --- a/b3/plugins/tk/CHANGELOG +++ b/b3/plugins/tk/CHANGELOG @@ -1,4 +1,5 @@ 07/05/2015 - 1.4 - Fenix - make use of Plugin.getSettings to retrieve configuration file values + - interface with spawnkill plugin 06/30/2015 - 1.3.5 - Fenix - fixed grudge_level retrieval from configuration file 08/30/2014 - 1.3.4 - Fenix - syntax cleanup - highly improved plugin configuration file loading diff --git a/b3/plugins/tk/__init__.py b/b3/plugins/tk/__init__.py index 495eb70ce..be266953c 100644 --- a/b3/plugins/tk/__init__.py +++ b/b3/plugins/tk/__init__.py @@ -134,6 +134,8 @@ def _get_points(self): class TkPlugin(b3.plugin.Plugin): + loadAfterPlugins = ['spawnkill'] + #################################################################################################################### # # # STARTUP # @@ -147,7 +149,8 @@ def __init__(self, console, config=None): :param config: The plugin configuration """ b3.plugin.Plugin.__init__(self, console, config) - self._adminPlugin = None + self._adminPlugin = self.console.getPlugin('admin') + self._spawnkillPlugin = self.console.getPlugin('spawnkill') # game types that have no team based game play and for which there should be no tk detected self._ffa = ['dm', 'ffa', 'syc-ffa', 'lms'] @@ -162,8 +165,7 @@ def __init__(self, console, config=None): 'forgive': '^7$vname^7 has forgiven $aname [^3$points^7]', 'grudged': '^7$vname^7 has a ^1grudge ^7against $aname [^3$points^7]', 'forgive_many': '^7$vname^7 has forgiven $attackers', - 'forgive_warning': '^1ALERT^7: $name^7 auto-kick if not forgiven. Type ^3!forgive $cid ^7to forgive. ' - '[^3damage: $points^7]', + 'forgive_warning': '^1ALERT^7: $name^7 auto-kick if not forgiven. Type ^3!forgive $cid ^7to forgive. [^3damage: $points^7]', 'no_forgive': '^7no one to forgive', 'players': '^7Forgive who? %s', 'forgive_info': '^7$name^7 has ^3$points^7 TK points', @@ -193,6 +195,7 @@ def __init__(self, console, config=None): self._tkpointsHalflife = 0 self._cronTab_tkhalflife = None self._tk_warn_duration = '1h' + self._team_spawnkill_extra_points = 100 def onLoadConfig(self): """ @@ -208,6 +211,9 @@ def onLoadConfig(self): self._tkpointsHalflife = self.getSetting('settings', 'halflife', b3.INT, self._tkpointsHalflife) self._grudge_enable = self.getSetting('settings', 'grudge_enable', b3.BOOL, self._grudge_enable) self._grudge_level = self.getSetting('settings', 'grudge_level', b3.INT, self._grudge_level) + if self._spawnkillPlugin: + self._team_spawnkill_extra_points = self.getSetting('settings', 'team_spawnkill_extra_points', b3.INT, + self._team_spawnkill_extra_points, lambda x: int(max(x, 0))) try: self._levels = self.load_config_for_levels() @@ -297,6 +303,7 @@ def onStartup(self): """ Plugin startup """ + # register events needed self.registerEvent('EVT_CLIENT_DAMAGE_TEAM') self.registerEvent('EVT_CLIENT_KILL_TEAM') self.registerEvent('EVT_CLIENT_DISCONNECT') @@ -304,11 +311,10 @@ def onStartup(self): self.registerEvent('EVT_GAME_ROUND_END') self.registerEvent('EVT_GAME_ROUND_START') - self._adminPlugin = self.console.getPlugin('admin') + if self._spawnkillPlugin: + self.registerEvent('EVT_CLIENT_SPAWNKILL_TEAM') self._adminPlugin.registerCommand(self, 'forgive', 0, self.cmd_forgive, 'f') - # this command will forgive the person about to be kicked - # self._adminPlugin.registerCommand('forgivenow', 0, self.cmd_forgivenow) self._adminPlugin.registerCommand(self, 'forgivelist', 0, self.cmd_forgivelist, 'fl') self._adminPlugin.registerCommand(self, 'forgiveall', 0, self.cmd_forgiveall, 'fa') self._adminPlugin.registerCommand(self, 'forgiveinfo', 20, self.cmd_forgiveinfo, 'fi') @@ -341,6 +347,13 @@ def onEvent(self, event): if event.client.maxLevel <= self._maxLevel: self.clientDamage(event.client, event.target, int(event.data[0])) + elif event.type == self.console.getEventID('EVT_CLIENT_SPAWNKILL_TEAM'): + # this event is fired after EVT_CLIENT_KILL_TEAM, so the client already got some TK points: + # we'll give him some more TK points since if he did it on spawnpoint he probably did that + # on purpose and not by mistake + if event.client.maxLevel <= self._maxLevel and self._team_spawnkill_extra_points > 0: + self.clientSpawnkillTeam(event.client, event.target) + elif event.type == self.console.getEventID('EVT_CLIENT_KILL_TEAM'): if event.client.maxLevel <= self._maxLevel: self.clientDamage(event.client, event.target, int(event.data[0]), True) @@ -482,9 +495,20 @@ def getMultipliers(self, client): return level + def clientSpawnkillTeam(self, attacker, victim): + """ + Executed when EVT_CLIENT_SPAWNKILL_TEAM is received after EVT_CLIENT_TEAM. + """ + points = int(min(100, self._team_spawnkill_extra_points)) + a = self.getClientTkInfo(attacker) + v = self.getClientTkInfo(victim) + a.damage(v.cid, points) + v.damaged(a.cid, points) + self.debug('team spawnkill detected: giving %s %s extra TK points', attacker.name, points) + attacker.message('^7You have been punished with ^1%s ^7 extra TK points for spawnkilling', points) + def clientDamage(self, attacker, victim, points, killed=False): - if points > 100: - points = 100 + points = int(min(100, points)) a = self.getClientTkInfo(attacker) v = self.getClientTkInfo(victim)