From 5f579e1a60dfcdfe0b6667c918df34e0773107f7 Mon Sep 17 00:00:00 2001 From: "Way, No" Date: Sat, 27 Apr 2013 00:31:41 +1200 Subject: [PATCH 1/2] Create protect.py Protects areas against block destroying/building. --- protect.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 protect.py diff --git a/protect.py b/protect.py new file mode 100644 index 0000000..64b53de --- /dev/null +++ b/protect.py @@ -0,0 +1,70 @@ +""" +Protects areas against block destroying/building. + +Maintainer: hompy +""" + +from commands import add, admin +from pyspades.common import coordinates + + +@admin +def protect(connection, value=None): + protocol = connection.protocol + if value is None: + protocol.protected = None + protocol.send_chat('All areas unprotected', irc=True) + else: + if protocol.protected is None: + protocol.protected = set() + pos = coordinates(value) + protocol.protected.symmetric_difference_update([pos]) + message = 'The area at %s is now %s' % (value.upper(), 'protected' + if pos in protocol.protected + else 'unprotected') + protocol.send_chat(message, irc=True) + +add(protect) + + +def apply_script(protocol, connection, config): + class ProtectConnection(connection): + def _block_available(self, x, y, z): + if (not (self.god or self.admin) + and self.protocol.is_protected(x, y, z)): + return False + + def on_block_build_attempt(self, x, y, z): + if (not (self.god or self.admin) + and self.protocol.is_protected(x, y, z)): + return False + return connection.on_block_build_attempt(self, x, y, z) + + def on_line_build_attempt(self, points): + if not (self.god or self.admin): + for point in points: + if self.protocol.is_protected(*point): + return False + return connection.on_line_build_attempt(self, points) + + class ProtectProtocol(protocol): + protected = None + + def on_map_change(self, map): + self.protected = set(coordinates(s) for s in + getattr(self.map_info.info, 'protected', [])) + protocol.on_map_change(self, map) + + def is_indestructable(self, x, y, z): + if self.is_protected(x, y, z): + return True + return protocol.is_indestructable(self, x, y, z) + + def is_protected(self, x, y, z): + if self.protected: + for sx, sy in self.protected: + if x >= sx and y >= sy and x < sx + 64 and y < sy + 64: + return True + return False + + return ProtectProtocol, ProtectConnection From 9b0454feeb7099d7370cc4749af3c2b3445b373c Mon Sep 17 00:00:00 2001 From: "Way, No" Date: Sat, 27 Apr 2013 00:33:13 +1200 Subject: [PATCH 2/2] Create unbreak.py Set landshaft in some areas unbreakable --- unbreak.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 unbreak.py diff --git a/unbreak.py b/unbreak.py new file mode 100644 index 0000000..2c8abf6 --- /dev/null +++ b/unbreak.py @@ -0,0 +1,92 @@ +""" +Set landshaft in some areas unbreakable + +* Only users blocks can be breaked + +You can configure locations for unbreaking in map file. Example: + +unbreak = ['B6','B7','B8','C8','D8','E6','E7','E8'] # this squares unbreakable + +or + +unbreak = True # unbreakable whole map + +or + +unbreak = False # disable unbreakable + +Maintainer: noway421 +""" + +from collections import namedtuple +from pyspades.color import rgb_distance +from pyspades.constants import * +from pyspades.common import coordinates + +DIRT_COLOR = (71, 48, 35) +ALWAYS_ENABLED = False # Ignore map overrides? + + +def apply_script(protocol, connection, config): + class UnbreakConnection(connection): + def on_disconnect(self): + if bool(self.protocol.unbreak): + player_blocks = self.protocol.player_blocks + for xyz, player_block in player_blocks.iteritems(): + if player_block[0] is self: + # mojno zagadit' mapu i uiti, nichego ne budet + player_blocks[xyz] = (None, ) + return connection.on_disconnect(self) + + def on_block_build(self, x, y, z): + if bool(self.protocol.unbreak): + if self.protocol.is_unbreak_area(x, y, z): + player_block = (self, ) + self.protocol.player_blocks[(x, y, z)] = player_block + return connection.on_block_build(self, x, y, z) + + def on_line_build(self, points): + if bool(self.protocol.unbreak): + player_block = (self, ) + for xyz in points: + if self.protocol.is_unbreak_area(xyz[0], xyz[1], xyz[2]): + self.protocol.player_blocks[xyz] = player_block + return connection.on_line_build(self, points) + + def on_block_destroy(self, x, y, z, value): + can_destroy = connection.on_block_destroy(self, x, y, z, value) + if bool(self.protocol.unbreak): + if self.protocol.is_unbreak_area(x, y, z): + if can_destroy is not False: + player_block = self.protocol.player_blocks.pop( + (x, y, z), None) + if player_block is None: + return False + return can_destroy + + class UnbreakProtocol(protocol): + player_blocks = None + unbreak = False + + def on_map_change(self, map): + info = self.map_info.info + if ALWAYS_ENABLED: + self.unbreak = True + else: + ubrk = getattr(info, 'unbreak', True) + if ubrk is True or ubrk is False: + self.unbreak = ubrk + else: + self.unbreak = set(coordinates(s) for s in ubrk) + self.player_blocks = {} + return protocol.on_map_change(self, map) + + def is_unbreak_area(self, x, y, z): + if self.unbreak is True: + return True + if bool(self.unbreak): + for sx, sy in self.unbreak: + if x >= sx and y >= sy and x < sx + 64 and y < sy + 64: + return True + return False + return UnbreakProtocol, UnbreakConnection