# Path: cuwo/script.py
# class ServerScript(BaseScript):
#     connection_class = ConnectionScript
#     commands = None
#     aliases = None
# 
#     def __init__(self, server):
#         self.script_name = self.__module__.split('.')[1]
# 
#         self.server = server
#         self.world = server.world
#         self.loop = server.loop
#         server.scripts.add(self)
#         self.children = []
#         self.on_load()
#         for connection in server.connections:
#             self.call('on_existing_connection', connection=connection)
# 
#     def on_new_connection(self, event):
#         if self.connection_class is None:
#             return
#         script = self.connection_class(self, event.connection)
#         script.call('on_connect')
# 
#     def on_existing_connection(self, event):
#         if self.connection_class is None:
#             return
#         self.connection_class(self, event.connection)
# 
#     def on_command(self, event):
#         return self.call_command(event.user, event.command, event.args)
# 
#     def unload(self):
#         if self.server is None:
#             return
#         self.on_unload()
#         self.server.scripts.remove(self)
#         for script in self.children[:]:
#             script.unload()
#         self.children = None
#         self.server = None
#         self.world = None
# 
#     def call_command(self, user, command, args):
#         if self.commands is None:
#             return
#         command = command.lower()
#         command = self.aliases.get(command, command)
#         command = self.commands.get(command, None)
#         if not command:
#             return
#         user.parent = self  # for ScriptInterface
# 
#         if len(args) < command.min_args:
#             return command.get_syntax()
#         if command.max_args is not None and len(args) > command.max_args:
#             return command.get_syntax()
# 
#         try:
#             ret = command(user, *args) or ''
#         except InvalidPlayer:
#             ret = 'Invalid player specified'
#         except InsufficientRights:
#             ret = 'Insufficient rights'
#         except Exception:
#             import traceback
#             traceback.print_exc()
#             ret = ''
#         return ret
# 
# class ConnectionScript(BaseScript):
#     def __init__(self, parent, connection):
#         self.script_name = parent.script_name
# 
#         self.parent = parent
#         self.server = parent.server
#         self.world = parent.world
#         self.loop = connection.loop
#         self.connection = connection
#         connection.scripts.add(self)
#         parent.children.append(self)
#         self.on_load()
# 
#     def on_disconnect(self, event):
#         self.unload()
# 
#     def on_command(self, event):
#         ret = self.parent.call_command(self, event.command, event.args)
#         if ret is None:
#             return
#         if ret:
#             self.connection.send_chat(ret)
#         return False
# 
#     def get_player(self, name=None):
#         if name is None:
#             return self.connection
#         return get_player(self.server, name)
# 
#     def get_commands(self):
#         rights = self.connection.rights
#         for command in self.server.get_commands():
#             if command.is_compatible(rights):
#                 yield command
# 
#     def get_command(self, name):
#         command = self.server.get_command(name)
#         if not command:
#             return
#         if not command.is_compatible(self.connection.rights):
#             return
#         return command
# 
#     def unload(self):
#         if self.parent is None:
#             return
#         self.connection.scripts.remove(self)
#         self.parent.children.remove(self)
#         self.on_unload()
#         self.parent = None
#         self.connection = None
#         self.server = None
#         self.world = None
# 
#     @property
#     def entity(self):
#         return self.connection.entity
# 
# Path: cuwo/constants.py
# HOSTILE_FLAG = 1 << 5


from cuwo.script import ServerScript, ConnectionScript
from cuwo.constants import HOSTILE_FLAG
# Copyright (c) Mathias Kaerlev 2013-2017.
#
# This file is part of cuwo.
#
# cuwo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cuwo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cuwo.  If not, see <http://www.gnu.org/licenses/>.

"""
Player versus player mode!
"""



class VersusConnection(ConnectionScript):
    def on_join(self, event):
        self.entity.flags |= HOSTILE_FLAG

    def on_flags_update(self, event):

# Path: cuwo/script.py
# class ServerScript(BaseScript):
#     connection_class = ConnectionScript
#     commands = None
#     aliases = None
# 
#     def __init__(self, server):
#         self.script_name = self.__module__.split('.')[1]
# 
#         self.server = server
#         self.world = server.world
#         self.loop = server.loop
#         server.scripts.add(self)
#         self.children = []
#         self.on_load()
#         for connection in server.connections:
#             self.call('on_existing_connection', connection=connection)
# 
#     def on_new_connection(self, event):
#         if self.connection_class is None:
#             return
#         script = self.connection_class(self, event.connection)
#         script.call('on_connect')
# 
#     def on_existing_connection(self, event):
#         if self.connection_class is None:
#             return
#         self.connection_class(self, event.connection)
# 
#     def on_command(self, event):
#         return self.call_command(event.user, event.command, event.args)
# 
#     def unload(self):
#         if self.server is None:
#             return
#         self.on_unload()
#         self.server.scripts.remove(self)
#         for script in self.children[:]:
#             script.unload()
#         self.children = None
#         self.server = None
#         self.world = None
# 
#     def call_command(self, user, command, args):
#         if self.commands is None:
#             return
#         command = command.lower()
#         command = self.aliases.get(command, command)
#         command = self.commands.get(command, None)
#         if not command:
#             return
#         user.parent = self  # for ScriptInterface
# 
#         if len(args) < command.min_args:
#             return command.get_syntax()
#         if command.max_args is not None and len(args) > command.max_args:
#             return command.get_syntax()
# 
#         try:
#             ret = command(user, *args) or ''
#         except InvalidPlayer:
#             ret = 'Invalid player specified'
#         except InsufficientRights:
#             ret = 'Insufficient rights'
#         except Exception:
#             import traceback
#             traceback.print_exc()
#             ret = ''
#         return ret
# 
# class ConnectionScript(BaseScript):
#     def __init__(self, parent, connection):
#         self.script_name = parent.script_name
# 
#         self.parent = parent
#         self.server = parent.server
#         self.world = parent.world
#         self.loop = connection.loop
#         self.connection = connection
#         connection.scripts.add(self)
#         parent.children.append(self)
#         self.on_load()
# 
#     def on_disconnect(self, event):
#         self.unload()
# 
#     def on_command(self, event):
#         ret = self.parent.call_command(self, event.command, event.args)
#         if ret is None:
#             return
#         if ret:
#             self.connection.send_chat(ret)
#         return False
# 
#     def get_player(self, name=None):
#         if name is None:
#             return self.connection
#         return get_player(self.server, name)
# 
#     def get_commands(self):
#         rights = self.connection.rights
#         for command in self.server.get_commands():
#             if command.is_compatible(rights):
#                 yield command
# 
#     def get_command(self, name):
#         command = self.server.get_command(name)
#         if not command:
#             return
#         if not command.is_compatible(self.connection.rights):
#             return
#         return command
# 
#     def unload(self):
#         if self.parent is None:
#             return
#         self.connection.scripts.remove(self)
#         self.parent.children.remove(self)
#         self.on_unload()
#         self.parent = None
#         self.connection = None
#         self.server = None
#         self.world = None
# 
#     @property
#     def entity(self):
#         return self.connection.entity
# 
# Path: cuwo/constants.py
# HOSTILE_FLAG = 1 << 5


# Path: scripts/pvp.py
from cuwo.script import ServerScript, ConnectionScript
from cuwo.constants import HOSTILE_FLAG

# Copyright (c) Mathias Kaerlev 2013-2017.
#
# This file is part of cuwo.
#
# cuwo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cuwo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cuwo.  If not, see <http://www.gnu.org/licenses/>.

"""
Player versus player mode!
"""



class VersusConnection(ConnectionScript):
    def on_join(self, event):
        self.entity.flags |= HOSTILE_FLAG

    def on_flags_update(self, event):

        self.entity.flags |= HOSTILE_FLAG