示例#1
0
        protected void Init(FSGameLoop game)
        {
            MapLoader.Instance.OnMapEvent             += OnMapEvent;
            game.PlayerManager.OnPlayerPacketReceived += OnPlayerPacketReceived;
            game.PlayerManager.OnPlayerConnected      += OnPlayerConnected;
            game.PlayerManager.OnPlayerApprovedToJoin += OnPlayerApprovedToJoin;
            game.PlayerManager.OnPlayerDisconnected   += OnPlayerDisconnected;
            game.PlayerManager.OnPlayerIntroduced     += OnPlayerIntroduced;
            game.PlayerManager.OnPlayerChangedTeam    += OnPlayerChangedTeam;
            game.PlayerManager.OnPlayerChangedName    += OnPlayerChangedName;
            game.PlayerManager.OnPlayerLatencyUpdated += OnPlayerLatencyUpdated;
            game.PlayerManager.OnPlayerRunCommand     += OnPlayerRunCommand;
            game.PlayerManager.OnPlayerSpectate       += OnPlayerSpectate;
            game.PlayerManager.OnChatCommand          += OnPlayerChatCommand;
            game.EntityManager.OnEntityAdded          += OnEntityAdded;
            game.EntityManager.OnEntityDestroyed      += OnEntityDestroyed;
            game.EntityManager.OnEntityUpdated        += OnEntityUpdated;
            game.EntityManager.OnHumanTrigger         += OnHumanTrigger;
            game.GameLoader.PreGameLoaded             += OnPreGameLoaded;
            game.GameLoader.GameLoaded      += OnGameLoaded;
            game.GameLoader.PreGameUnloaded += OnPreGameUnloaded;
            game.GameLoader.GameUnloaded    += OnGameUnloaded;

            _game = game;
        }
示例#2
0
        public void Load(FSGameLoop game)
        {
            if (game.IsHost || Server.GameServer.Instance == null)
            {
                ExecuteGameConfig();
            }

            _game = game;
            Directory.CreateDirectory(GetDataDirectory());
            _Load(game);

            InjectComponents();

            foreach (var c in _addedComponents)
            {
                c.OnStart();
            }

            if (!game.IsHost)
            {
                var resource = Resources.Load <GameObject>(Name);
                if (resource != null)
                {
                    _resource = GameObject.Instantiate(resource, game.ObjectContainer.transform);
                }
            }
        }
示例#3
0
        protected override void OnGameLoaded()
        {
            var locked = (FSGameLoop.GetGameInstance(true) == null) || Game.GamemodeLoader.Gamemode.LockVars;

            DevConsole.LockFlags(locked, ConVarFlags.Replicator);
            DevConsole.LockFlags(locked, ConVarFlags.Cheat);
            DevConsole.LockFlags(locked, ConVarFlags.Gamemode);
        }
示例#4
0
        public void Initialize(FSGameLoop game)
        {
            Game = game;

            try
            {
                _Hook();
                _Initialize();

                DevConsole.RegisterObject(this);

                Started = true;
            }
            catch (Exception e)
            {
                Debug.LogError("Failed to register " + GetType().Name + "\n" + e);
                Started = false;
            }
        }
示例#5
0
        protected override void OnPlayerPacketReceived(IPlayer player, IBasePacket packet)
        {
            if (Game.IsHost ||
                FSGameLoop.GetGameInstance(true) != null ||
                !(packet is CustomPacket cp && cp.Label == "Replicate"))
            {
                return;
            }

            var replStr = cp.GetString(0);
            var cmds    = replStr.Split('&');

            if (cmds != null && cmds.Length > 0)
            {
                foreach (var cmd in cmds)
                {
                    DevConsole.ExecuteLine(cmd);
                }
            }
        }
示例#6
0
        public void Unload(FSGameLoop game)
        {
            _Unload(game);

            if (_resource)
            {
                GameObject.Destroy(_resource);
            }

            // unhook then destroy, to make sure we don't lose references
            foreach (var fs in _addedComponents)
            {
                fs.Unhook();
            }

            foreach (var fs in _addedComponents)
            {
                fs.Destroy();
            }

            _addedComponents.Clear();
        }
示例#7
0
 protected abstract void _Unload(FSGameLoop game);