private async void ExecuteAsync(PlayerDetails playerDetails) { await Task.Factory.StartNew ( () => { lock (_dataLock) { try { if (_cmdElements.Length < 1 || !_cmdElements[0].Equals(_keyWord, GlobalData.InputDataStringComparison)) { throw new Exception($"command replacement error [{_cmdInfo.CommandTxt}]"); } else { CharacterData mainCharacter = _characterInfo.GetCharacterById(playerDetails.CharId); if (mainCharacter == null) { throw new Exception($"cannot get main character with char_id [{playerDetails.CharId}]"); } int wmId = mainCharacter.WmId; int parentObjectId = mainCharacter.ParentObjectId; bool isOnWorldMap = mainCharacter.IsOnWorldMap; int charIdFilter = -1; if (_cmdElements.Length == 2 && !String.IsNullOrWhiteSpace(_cmdElements[1])) { Int32.TryParse(_cmdElements[1], out charIdFilter); } List <CharacterData> charsList = _characterInfo.GetCharactersByWorldLocation(wmId, isOnWorldMap, parentObjectId); if (charIdFilter < 0) { foreach (CharacterData character in charsList) { CommandHandler.Send(new LocalCharacterDetailsCmdBuilder(false, character), playerDetails); } CommandHandler.Send(new LocalCharacterDetailsCmdBuilder(true), playerDetails); } else { foreach (CharacterData character in charsList) { if (character.CharId == charIdFilter) { CommandHandler.Send ( new LocalCharacterDetailsCmdBuilder(false, character, LocalCharacterDetailsCmdBuilder.Action.OnRequestSpawn), playerDetails ); break; } } } } } catch (Exception exception) { CommandHandler.Send(new InfoCmdBuilder("Internal server error (cannot get local characters)!"), playerDetails); _logger.UpdateLog($"Location characters getting error for TCP client ID [{playerDetails.TcpClientId}]: {exception.Message}"); } } } ); }
public bool Execute(PlayerDetails playerDetails) { bool executed = false; try { double newPosX = 0.00; double newPosY = 0.00; double newPosZ = 0.00; int timeArrivalMs = 0; if (_cmdElements.Length != 5) { throw new Exception($"wrong count of command elements [{_cmdElements.Length}]"); } if ( !Double.TryParse(_cmdElements[1], out newPosX) || !Double.TryParse(_cmdElements[2], out newPosY) || !Double.TryParse(_cmdElements[3], out newPosZ) || !Int32.TryParse(_cmdElements[4], out timeArrivalMs) ) { throw new Exception($"cannot convert parameters from command [{_cmdInfo.CommandTxt}]"); } int charId = _playerHandler.GetPlayerCharacterId(playerDetails.TcpClientId); if (charId < 0) { throw new Exception("cannot find active character!"); } CharacterData charData = _charInfo.GetCharacterById(charId); if (charData == null) { throw new Exception($"cannot get character data of char. ID [{charId}]"); } if (charData.IsOnWorldMap) { _charActionManager.MoveCharacterWorld ( charId, charData.CurrentWorldLoc, new Point2 <int> ( Convert.ToInt32(Math.Round(newPosX)), Convert.ToInt32(Math.Round(newPosY)) ) ); } else { _charActionManager.MoveCharacterLocal ( charId, charData.CurrentLoc, new Point3 <double> ( newPosX, newPosY, newPosZ ), timeArrivalMs ); } executed = true; } catch (Exception exception) { _logger.UpdateLog($"Character movement request command execution error: {exception.Message}"); } return(executed); }