public CharacterQuest(CharacterQuestDTO characterQuest) { CharacterId = characterQuest.CharacterId; QuestId = characterQuest.QuestId; FirstObjective = characterQuest.FirstObjective; SecondObjective = characterQuest.SecondObjective; ThirdObjective = characterQuest.ThirdObjective; FourthObjective = characterQuest.FourthObjective; FifthObjective = characterQuest.FifthObjective; IsMainQuest = characterQuest.IsMainQuest; }
private static CharacterQuestDTO Insert(CharacterQuestDTO charQuest, OpenNosContext context) { CharacterQuest entity = new CharacterQuest(); Mapper.Mappers.CharacterQuestMapper.ToCharacterQuest(charQuest, entity); context.CharacterQuest.Add(entity); context.SaveChanges(); if (Mapper.Mappers.CharacterQuestMapper.ToCharacterQuestDTO(entity, charQuest)) { return(charQuest); } return(null); }
protected static CharacterQuestDTO InsertOrUpdate(OpenNosContext context, CharacterQuestDTO dto) { Guid primaryKey = dto.Id; CharacterQuest entity = context.Set <CharacterQuest>().FirstOrDefault(c => c.Id == primaryKey); if (entity == null) { return(Insert(dto, context)); } else { return(Update(entity, dto, context)); } }
public IEnumerable <CharacterQuestDTO> LoadByCharacterId(long characterId) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <CharacterQuestDTO> result = new List <CharacterQuestDTO>(); foreach (CharacterQuest charQuest in context.CharacterQuest.Where(s => s.CharacterId == characterId)) { CharacterQuestDTO dto = new CharacterQuestDTO(); Mapper.Mappers.CharacterQuestMapper.ToCharacterQuestDTO(charQuest, dto); result.Add(dto); } return(result); } }
private static CharacterQuestDTO Update(CharacterQuest entity, CharacterQuestDTO charQuest, OpenNosContext context) { if (entity != null) { Mapper.Mappers.CharacterQuestMapper.ToCharacterQuest(charQuest, entity); context.SaveChanges(); } if (Mapper.Mappers.CharacterQuestMapper.ToCharacterQuestDTO(entity, charQuest)) { return(charQuest); } return(null); }
public CharacterQuestDTO InsertOrUpdate(CharacterQuestDTO charQuest) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { return(InsertOrUpdate(context, charQuest)); } } catch (Exception e) { Logger.Error($"Message: {e.Message}", e); return(null); } }
public static bool ToCharacterQuest(CharacterQuestDTO input, CharacterQuest output) { if (input == null) { return(false); } output.Id = input.Id; output.CharacterId = input.CharacterId; output.QuestId = input.QuestId; output.FirstObjective = input.FirstObjective; output.SecondObjective = input.SecondObjective; output.ThirdObjective = input.ThirdObjective; output.FourthObjective = input.FourthObjective; output.FifthObjective = input.FifthObjective; output.IsMainQuest = input.IsMainQuest; return(true); }
/// <summary> /// Char_NEW character creation character /// </summary> /// <param name="characterCreatePacket"></param> public void CreateCharacter(CharacterCreatePacket characterCreatePacket) { if (Session.HasCurrentMapInstance) { return; } // TODO: Hold Account Information in Authorized object long accountId = Session.Account.AccountId; byte slot = characterCreatePacket.Slot; string characterName = characterCreatePacket.Name; if (slot > 2 || DaoFactory.CharacterDao.LoadBySlot(accountId, slot) != null) { return; } if (characterName.Length <= 3 || characterName.Length >= 15) { return; } Regex rg = new Regex(@"^[\u0021-\u007E\u00A1-\u00AC\u00AE-\u00FF\u4E00-\u9FA5\u0E01-\u0E3A\u0E3F-\u0E5B\u002E]*$"); if (rg.Matches(characterName).Count == 1) { CharacterDTO character = DaoFactory.CharacterDao.LoadByName(characterName); if (character == null || character.State == CharacterState.Inactive) { if (characterCreatePacket.Slot > 2) { return; } CharacterDTO newCharacter = new CharacterDTO { Class = (byte)ClassType.Adventurer, Gender = characterCreatePacket.Gender, HairColor = characterCreatePacket.HairColor, HairStyle = characterCreatePacket.HairStyle, Hp = 221, JobLevel = 20, Level = 15, MapId = 1, MapX = (short)ServerManager.Instance.RandomNumber(78, 81), MapY = (short)ServerManager.Instance.RandomNumber(109, 112), Mp = 221, MaxMateCount = 10, Gold = 15000, SpPoint = 10000, SpAdditionPoint = 0, Name = characterName, Slot = slot, AccountId = accountId, MinilandMessage = "Welcome", State = CharacterState.Active }; SaveResult insertResult = DaoFactory.CharacterDao.InsertOrUpdate(ref newCharacter); CharacterQuestDTO firstQuest = new CharacterQuestDTO { CharacterId = newCharacter.CharacterId, QuestId = 1997, IsMainQuest = true }; CharacterSkillDTO sk1 = new CharacterSkillDTO { CharacterId = newCharacter.CharacterId, SkillVNum = 200 }; CharacterSkillDTO sk2 = new CharacterSkillDTO { CharacterId = newCharacter.CharacterId, SkillVNum = 201 }; CharacterSkillDTO sk3 = new CharacterSkillDTO { CharacterId = newCharacter.CharacterId, SkillVNum = 209 }; QuicklistEntryDTO qlst1 = new QuicklistEntryDTO { CharacterId = newCharacter.CharacterId, Type = 1, Slot = 1, Pos = 1 }; QuicklistEntryDTO qlst2 = new QuicklistEntryDTO { CharacterId = newCharacter.CharacterId, Q2 = 1, Slot = 2 }; QuicklistEntryDTO qlst3 = new QuicklistEntryDTO { CharacterId = newCharacter.CharacterId, Q2 = 8, Type = 1, Slot = 1, Pos = 16 }; QuicklistEntryDTO qlst4 = new QuicklistEntryDTO { CharacterId = newCharacter.CharacterId, Q2 = 9, Type = 1, Slot = 3, Pos = 1 }; DaoFactory.CharacterQuestDao.InsertOrUpdate(firstQuest); DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst1); DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst2); DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst3); DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst4); DaoFactory.CharacterSkillDao.InsertOrUpdate(sk1); DaoFactory.CharacterSkillDao.InsertOrUpdate(sk2); DaoFactory.CharacterSkillDao.InsertOrUpdate(sk3); Inventory startupInventory = new Inventory((Character)newCharacter); startupInventory.AddNewToInventory(2024, 10, InventoryType.Etc); startupInventory.AddNewToInventory(2081, 1, InventoryType.Etc); startupInventory.AddNewToInventory(1907, 1, InventoryType.Main); startupInventory.Select(s => s.Value).ToList().ForEach(i => DaoFactory.IteminstanceDao.InsertOrUpdate(i)); LoadCharacters(characterCreatePacket.OriginalContent); } else { Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("ALREADY_TAKEN")}"); } } else { Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}"); } }
/// <summary> /// select packet /// </summary> /// <param name="selectPacket"></param> public void SelectCharacter(SelectPacket selectPacket) { try { if (Session?.Account == null || Session.HasSelectedCharacter) { return; } if (!(DaoFactory.CharacterDao.LoadBySlot(Session.Account.AccountId, selectPacket.Slot) is Character character)) { return; } character.GeneralLogs = DaoFactory.GeneralLogDao.LoadByAccount(Session.Account.AccountId).Where(s => s.CharacterId == character.CharacterId).ToList(); character.MapInstanceId = ServerManager.Instance.GetBaseMapInstanceIdByMapId(character.MapId); Map currentMap = ServerManager.Instance.GetMapInstance(character.MapInstanceId)?.Map; if (currentMap != null && currentMap.IsBlockedZone(character.MapX, character.MapY)) { MapCell pos = currentMap.GetRandomPosition(); character.PositionX = pos.X; character.PositionY = pos.Y; } else { character.PositionX = character.MapX; character.PositionY = character.MapY; } character.Authority = Session.Account.Authority; Session.SetCharacter(character); if (!Session.Character.GeneralLogs.Any(s => s.Timestamp == DateTime.Now && s.LogData == "World" && s.LogType == "Connection")) { Session.Character.SpAdditionPoint += Session.Character.SpPoint; Session.Character.SpPoint = 10000; } if (Session.Character.Hp > Session.Character.HpLoad()) { Session.Character.Hp = (int)Session.Character.HpLoad(); } if (Session.Character.Mp > Session.Character.MpLoad()) { Session.Character.Mp = (int)Session.Character.MpLoad(); } Session.Character.Respawns = DaoFactory.RespawnDao.LoadByCharacter(Session.Character.CharacterId).ToList(); Session.Character.StaticBonusList = DaoFactory.StaticBonusDao.LoadByCharacterId(Session.Character.CharacterId).ToList(); Session.Character.LoadInventory(); Session.Character.LoadQuicklists(); Session.Character.GenerateMiniland(); if (!DaoFactory.CharacterQuestDao.LoadByCharacterId(Session.Character.CharacterId).Any(s => s.IsMainQuest)) { CharacterQuestDTO firstQuest = new CharacterQuestDTO { CharacterId = Session.Character.CharacterId, QuestId = 1997, IsMainQuest = true }; DaoFactory.CharacterQuestDao.InsertOrUpdate(firstQuest); } DaoFactory.CharacterQuestDao.LoadByCharacterId(Session.Character.CharacterId).ToList().ForEach(q => Session.Character.Quests.Add(q as CharacterQuest)); DaoFactory.MateDao.LoadByCharacterId(Session.Character.CharacterId).ToList().ForEach(s => { Mate mate = (Mate)s; mate.Owner = Session.Character; mate.GenerateMateTransportId(); mate.Monster = ServerManager.Instance.GetNpc(s.NpcMonsterVNum); Session.Character.Mates.Add(mate); if (!mate.IsTeamMember) { mate.MapX = ServerManager.Instance.MinilandRandomPos().X; mate.MapY = ServerManager.Instance.MinilandRandomPos().Y; } }); Session.Character.Life = Observable.Interval(TimeSpan.FromMilliseconds(300)).Subscribe(x => { Session?.Character?.CharacterLife(); }); Session.Character.GeneralLogs.Add(new GeneralLogDTO { AccountId = Session.Account.AccountId, CharacterId = Session.Character.CharacterId, IpAddress = Session.IpAddress, LogData = "World", LogType = "Connection", Timestamp = DateTime.Now }); Session.SendPacket("OK"); // Inform everyone about connected character CommunicationServiceClient.Instance.ConnectCharacter(ServerManager.Instance.WorldId, character.CharacterId); } catch (Exception ex) { Logger.Log.Error("Select character failed.", ex); } }