public CharacterData(DbCharactersData dbData) { _dbData = dbData ?? throw new Exception("DB data of new character cannot be NULL!"); GameWorldData gameWorldData = GameWorldData.GetLastInstance(); this.StartingLoc = new Point3 <double>(Convert.ToDouble(_dbData.LocalPosX), Convert.ToDouble(_dbData.LocalPosY), Convert.ToDouble(_dbData.LocalPosZ)); this.DestinationLoc = this.StartingLoc; this.CurrentLoc = this.StartingLoc; this.Angle = Convert.ToDouble(_dbData.LocalAngle); DateTime tNow = DateTime.Now; this.MovingStartTime = tNow; this.MovingEndTime = tNow; this.AccId = _dbData.AccId; this.CharId = _dbData.CharId; this.WmId = _dbData.WmId; this.ParentObjectId = _dbData.TerrainParentId; this.IsOnWorldMap = _dbData.IsOnWorldMap; this.CurrentWorldLoc = gameWorldData.GetWorldCoordsByWmId(_dbData.WmId); if (_dbData.IsOnWorldMap) { this.State = CharacterState.WorldMap; } this.ModelCode = _dbData.ModelCode; this.HairstyleId = _dbData.HairstyleId; this.Name = (_dbData.IsNpc ? _dbData.NpcAltName : _dbData.Name); CalculateMovementAsync(); }
public void AddCommandElements() { if (_isListConfirmation) { _commandDetails.CommandElementList.Add("endlist"); } else { DbCharactersData dbData = _characterData.GetDbData(); LobbyCharDetails charDetails = new LobbyCharDetails() { CharId = dbData.CharId, Name = dbData.Name, ModelCode = dbData.ModelCode, HairstyleId = dbData.HairstyleId }; _commandDetails.CommandElementList.Add("position"); _commandDetails.CommandElementList.Add(JsonConvert.SerializeObject(charDetails)); } }
/// <summary> /// Gets data from table 'characters' /// </summary> public BoxedData GetCharactersData(string sqlFilter = "") { BoxedData data = new BoxedData(); List <DbCharactersData> resultList = new List <DbCharactersData>(); string msg = ""; try { int charId = -1; string name = ""; int accId = -1; bool isNpc = false; string npcAltName = ""; bool isOnWorldMap = false; int wmId = -1; int terrainParentId = -1; decimal localPosX = 0.0000M; decimal localPosY = 0.0000M; decimal localPosZ = 0.0000M; decimal localAngle = 0.0000M; string modelCode = ""; int hairstyleId = 0; string query = @" SELECT `char_id`, `char_name`, `char_acc_id`, `char_is_npc`, `char_npc_alt_name`, `char_is_on_world_map`, `char_wm_id`, `char_terrain_parent_id`, `char_local_pos_x`, `char_local_pos_y`, `char_local_pos_z`, `char_local_angle`, `char_model_code`, `char_hairstyle_id` FROM `characters` "; if (!String.IsNullOrWhiteSpace(sqlFilter)) { query += $" {(!sqlFilter.ToUpper().Contains("WHERE") ? "WHERE" : "")} {sqlFilter}"; } lock (_connectionLock) { using (MySqlCommand command = new MySqlCommand(query, _connection)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { charId = reader.GetInt32("char_id"); name = reader["char_name"].ToString(); accId = reader.GetInt32("char_acc_id"); isNpc = (reader.GetInt32("char_is_npc") == 1); npcAltName = reader["char_npc_alt_name"].ToString(); isOnWorldMap = (reader.GetInt32("char_is_on_world_map") == 1); wmId = reader.GetInt32("char_wm_id"); terrainParentId = reader.GetInt32("char_terrain_parent_id"); localPosX = reader.GetDecimal("char_local_pos_x"); localPosY = reader.GetDecimal("char_local_pos_y"); localPosZ = reader.GetDecimal("char_local_pos_z"); localAngle = reader.GetDecimal("char_local_angle"); modelCode = reader["char_model_code"].ToString(); hairstyleId = reader.GetInt32("char_hairstyle_id"); DbCharactersData result = new DbCharactersData ( charId, name, accId, isNpc, npcAltName, isOnWorldMap, wmId, terrainParentId, localPosX, localPosY, localPosZ, localAngle, modelCode, hairstyleId ); resultList.Add(result); } } } } } catch (Exception exception) { msg = $"Cannot get data from 'characters' table, SQL filter [{sqlFilter}]: {exception.Message}"; } data.Data = resultList; data.Msg = msg; return(data); }
public void Dispose() { _movementCalculationInProgress = false; _dbData = null; }