Ejemplo n.º 1
0
        private void HandleSelectCharacterRequest(string username, PacketBase p)
        {
            CharacterSelectedPacket packet = (CharacterSelectedPacket)p;

            // If player is already added to the game world, we don't want to add another. Ignore this request.
            if (_pcs.ContainsKey(username))
            {
                _logger.Info($"Player {username} is already added to the game world. Ignoring request.");
                return;
            }

            string path = _pathService.ServerVaultDirectory + username + "/" + packet.PCGlobalID + ".pcf";

            if (!File.Exists(path))
            {
                _logger.Error($"PC file '{packet.PCGlobalID}.pcf' does not exist for username {username}. Cannot select character. Ignoring request.");
                return;
            }

            PCData pcData = _dataService.Load <PCData>(path);
            Entity player = _entityFactory.Create <Player, PCData>(pcData);

            _pcs.Add(username, player);

            ScriptGroup scripts = _gameModule.GetComponent <ScriptGroup>();
            string      script  = scripts[ScriptEvent.OnModulePlayerEnter];

            _scriptService.QueueScript(script, _gameModule);

            CharacterAddedToWorldPacket response = new CharacterAddedToWorldPacket();

            _networkService.SendMessage(PacketDeliveryMethod.ReliableUnordered, response, username);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public override void Process(Entity entity)
        {
            ScriptGroup scripts = entity.GetComponent <ScriptGroup>();

            if (!scripts.ContainsKey(ScriptEvent.OnHeartbeat) ||
                string.IsNullOrWhiteSpace(scripts[ScriptEvent.OnHeartbeat]))
            {
                return;
            }

            Heartbeat hb = entity.GetComponent <Heartbeat>();

            if (hb.Interval <= 0.0f)
            {
                return;
            }
            hb.CurrentTimer += _world.DeltaSeconds();
            if (hb.CurrentTimer < hb.Interval)
            {
                return;
            }

            _scriptService.QueueScript(scripts[ScriptEvent.OnHeartbeat], entity);
            hb.CurrentTimer = 0.0f;
        }