public static bool ToMapNpc(MapNpcDTO input, MapNpc output) { if (input == null) { return(false); } output.Dialog = input.Dialog; output.Effect = input.Effect; output.EffectDelay = input.EffectDelay; output.IsDisabled = input.IsDisabled; output.IsMoving = input.IsMoving; output.IsSitting = input.IsSitting; output.MapId = input.MapId; output.MapNpcId = input.MapNpcId; output.MapX = input.MapX; output.MapY = input.MapY; output.Name = input.Name; output.NpcVNum = input.NpcVNum; output.Position = input.Position; output.Say = input.Say; output.Delay = input.Delay; return(true); }
public MapNpcDTO Insert(MapNpcDTO npc) { using (var context = DataAccessHelper.CreateContext()) { MapNpc entity = _mapper.Map <MapNpc>(npc); context.MapNpc.Add(entity); context.SaveChanges(); return(_mapper.Map <MapNpcDTO>(entity)); } }
public IEnumerable <MapNpcDTO> LoadAll() { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <MapNpcDTO> result = new List <MapNpcDTO>(); foreach (MapNpc entity in context.MapNpc) { MapNpcDTO dto = new MapNpcDTO(); Mapper.Mappers.MapNpcMapper.ToMapNpcDTO(entity, dto); result.Add(dto); } return(result); } }
public IEnumerable <MapNpcDTO> LoadFromMap(short mapId) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <MapNpcDTO> result = new List <MapNpcDTO>(); foreach (MapNpc npcobject in context.MapNpc.Where(c => c.MapId.Equals(mapId))) { MapNpcDTO dto = new MapNpcDTO(); Mapper.Mappers.MapNpcMapper.ToMapNpcDTO(npcobject, dto); result.Add(dto); } return(result); } }
public MapNpc(MapNpcDTO input) { Dialog = input.Dialog; Effect = input.Effect; EffectDelay = input.EffectDelay; IsDisabled = input.IsDisabled; IsMoving = input.IsMoving; IsSitting = input.IsSitting; MapId = input.MapId; MapNpcId = input.MapNpcId; MapX = input.MapX; MapY = input.MapY; NpcVNum = input.NpcVNum; Position = input.Position; }
private static MapNpcDTO update(MapNpc entity, MapNpcDTO mapNpc, OpenNosContext context) { if (entity != null) { Mapper.Mappers.MapNpcMapper.ToMapNpc(mapNpc, entity); context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); } if (Mapper.Mappers.MapNpcMapper.ToMapNpcDTO(entity, mapNpc)) { return(mapNpc); } return(null); }
public MapNpcDTO Insert(MapNpcDTO npc) { try { using (var context = DataAccessHelper.CreateContext()) { MapNpc entity = _mapper.Map <MapNpc>(npc); context.MapNpc.Add(entity); context.SaveChanges(); return(_mapper.Map <MapNpcDTO>(entity)); } } catch (Exception e) { Logger.Error(e); return(null); } }
public SaveResult Update(ref MapNpcDTO mapNpc) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { int mapNpcId = mapNpc.MapNpcId; MapNpc entity = context.MapNpc.FirstOrDefault(c => c.MapNpcId.Equals(mapNpcId)); mapNpc = update(entity, mapNpc, context); return(SaveResult.Updated); } } catch (Exception e) { Logger.Error(string.Format(Language.Instance.GetMessageFromKey("UPDATE_MAPNPC_ERROR"), mapNpc.MapNpcId, e.Message), e); return(SaveResult.Error); } }
public bool ToMapNPCDTO(MapNpc input, MapNpcDTO output) { if (input == null) { output = null; return(false); } output.Dialog = input.Dialog; output.Effect = input.Effect; output.EffectDelay = input.EffectDelay; output.IsDisabled = input.IsDisabled; output.IsMoving = input.IsMoving; output.IsSitting = input.IsSitting; output.MapId = input.MapId; output.MapNpcId = input.MapNpcId; output.MapX = input.MapX; output.MapY = input.MapY; output.NpcVNum = input.NpcVNum; output.Position = input.Position; return(true); }
public MapNpcDTO LoadById(int mapNpcId) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { MapNpcDTO dto = new MapNpcDTO(); if (Mapper.Mappers.MapNpcMapper.ToMapNpcDTO(context.MapNpc.FirstOrDefault(i => i.MapNpcId.Equals(mapNpcId)), dto)) { return(dto); } return(null); } } catch (Exception e) { Logger.Error(e); return(null); } }
public void ImportShops() { int shopCounter = 0; foreach (string[] linesave in packetList.Where(o => o[0].Equals("shop"))) { if (linesave.Length > 6 && linesave[0] == "shop" && linesave[1] == "2") { MapNpcDTO npc = DAOFactory.MapNpcDAO.LoadById(short.Parse(linesave[2])); if (npc == null) { continue; } string named = ""; for (int j = 6; j < linesave.Length; j++) { named += $"{linesave[j]} "; } named = named.Trim(); ShopDTO shop = new ShopDTO { Name = named, MapNpcId = npc.MapNpcId, MenuType = short.Parse(linesave[4]), ShopType = short.Parse(linesave[5]) }; if (DAOFactory.ShopDAO.LoadByNpc(shop.MapNpcId) == null) { DAOFactory.ShopDAO.Insert(shop); shopCounter++; } } } Logger.Log.Info(string.Format(Language.Instance.GetMessageFromKey("SHOPS_PARSED"), shopCounter)); }
public MapNpcDTO Insert(MapNpcDTO npc) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { MapNpc entity = new MapNpc(); Mapper.Mappers.MapNpcMapper.ToMapNpc(npc, entity); context.MapNpc.Add(entity); context.SaveChanges(); if (Mapper.Mappers.MapNpcMapper.ToMapNpcDTO(entity, npc)) { return(npc); } return(null); } } catch (Exception e) { Logger.Error(e); return(null); } }
public MapNpc(MapNpcDTO npc, Map parent) { //Replace by MAPPING MapId = npc.MapId; MapX = npc.MapX; MapY = npc.MapY; Position = npc.Position; NpcVNum = npc.NpcVNum; IsSitting = npc.IsSitting; IsMoving = npc.IsMoving; Effect = npc.Effect; EffectDelay = npc.EffectDelay; Dialog = npc.Dialog; FirstX = npc.MapX; FirstY = npc.MapY; MapNpcId = npc.MapNpcId; //////////////////////// Npc = ServerManager.GetNpc(this.NpcVNum); LastEffect = LastMove = DateTime.Now; Map = parent; IEnumerable <RecipeDTO> recipe = DAOFactory.RecipeDAO.LoadByNpc(MapNpcId); if (recipe != null) { Recipes = new List <Recipe>(); foreach (RecipeDTO rec in recipe) { //Replace by MAPPING Recipes.Add(new Recipe(rec.RecipeId) { ItemVNum = rec.ItemVNum, MapNpcId = rec.MapNpcId, RecipeId = rec.RecipeId, Amount = rec.Amount }); /////////////////// } } IEnumerable <TeleporterDTO> teleporters = DAOFactory.TeleporterDAO.LoadFromNpc(MapNpcId); if (teleporters != null) { Teleporters = new List <Teleporter>(); foreach (TeleporterDTO teleporter in teleporters) { //Replace by MAPPING Teleporters.Add(new Teleporter() { MapId = teleporter.MapId, Index = teleporter.Index, MapNpcId = teleporter.MapNpcId, MapX = teleporter.MapX, MapY = teleporter.MapY, TeleporterId = teleporter.TeleporterId }); /////////////////// } } ShopDTO shop = DAOFactory.ShopDAO.LoadByNpc(MapNpcId); if (shop != null) { //Replace by MAPPING Shop = new Shop(shop.ShopId) { Name = shop.Name, MapNpcId = MapNpcId, MenuType = shop.MenuType, ShopType = shop.ShopType }; /////////////////// } }
public void InsertMapNpcs(List <string[]> packetList) { var npcCounter = 0; short map = 0; var npcs = new List <MapNpcDTO>(); var npcMvPacketsList = new List <int>(); var effPacketsDictionary = new Dictionary <int, short>(); foreach (var currentPacket in packetList.Where(o => o[0].Equals("mv") && o[1].Equals("2"))) { if (long.Parse(currentPacket[2]) >= 20000) { continue; } if (!npcMvPacketsList.Contains(Convert.ToInt32(currentPacket[2]))) { npcMvPacketsList.Add(Convert.ToInt32(currentPacket[2])); } } foreach (var currentPacket in packetList.Where(o => o[0].Equals("eff") && o[1].Equals("2"))) { if (long.Parse(currentPacket[2]) >= 20000) { continue; } if (!effPacketsDictionary.ContainsKey(Convert.ToInt32(currentPacket[2]))) { effPacketsDictionary.Add(Convert.ToInt32(currentPacket[2]), Convert.ToInt16(currentPacket[3])); } } foreach (var currentPacket in packetList.Where(o => o[0].Equals("in") || o[0].Equals("at"))) { if (currentPacket.Length > 5 && currentPacket[0] == "at") { map = short.Parse(currentPacket[2]); continue; } if (currentPacket.Length <= 7 || currentPacket[0] != "in" || currentPacket[1] != "2") { continue; } var npctest = new MapNpcDTO { MapX = short.Parse(currentPacket[4]), MapY = short.Parse(currentPacket[5]), MapId = map, VNum = short.Parse(currentPacket[2]) }; if (long.Parse(currentPacket[3]) > 20000) { continue; } npctest.MapNpcId = short.Parse(currentPacket[3]); if (effPacketsDictionary.ContainsKey(npctest.MapNpcId)) { npctest.Effect = effPacketsDictionary[npctest.MapNpcId]; } npctest.EffectDelay = 4750; npctest.IsMoving = npcMvPacketsList.Contains(npctest.MapNpcId); npctest.Direction = byte.Parse(currentPacket[6]); npctest.Dialog = short.Parse(currentPacket[9]); npctest.IsSitting = currentPacket[13] != "1"; npctest.IsDisabled = false; if (DAOFactory.NpcMonsterDAO.FirstOrDefault(s => s.NpcMonsterVNum.Equals(npctest.VNum)) == null || DAOFactory.MapNpcDAO.FirstOrDefault(s => s.MapNpcId.Equals(npctest.MapNpcId)) != null || npcs.Count(i => i.MapNpcId == npctest.MapNpcId) != 0) { continue; } npcs.Add(npctest); npcCounter++; } IEnumerable <MapNpcDTO> npcDtos = npcs; DAOFactory.MapNpcDAO.InsertOrUpdate(npcDtos); Logger.Log.Info(string.Format(LogLanguage.Instance.GetMessageFromKey(LanguageKey.NPCS_PARSED), npcCounter)); }
public MapNpcDTO Insert(MapNpcDTO npc) { throw new NotImplementedException(); }
public void ImportMapNpcs() { int npcCounter = 0; short map = 0; Dictionary <int, bool> movementlist = new Dictionary <int, bool>(); Dictionary <int, short> effectlist = new Dictionary <int, short>(); foreach (string[] linesave in packetList.Where(o => o[0].Equals("mv") && (o[1].Equals("2")))) { if (!(long.Parse(linesave[2]) >= 20000)) { if (!movementlist.ContainsKey(Convert.ToInt32(linesave[2]))) { movementlist[Convert.ToInt32(linesave[2])] = true; } } } foreach (string[] linesave in packetList.Where(o => o[0].Equals("eff") && o[1].Equals("2"))) { if (!(long.Parse(linesave[2]) >= 20000)) { if (!effectlist.ContainsKey(Convert.ToInt32(linesave[2]))) { effectlist[Convert.ToInt32(linesave[2])] = Convert.ToInt16(linesave[3]); } } } foreach (string[] linesave in packetList.Where(o => o[0].Equals("in") || o[0].Equals("at"))) { if (linesave.Length > 5 && linesave[0] == "at") { map = short.Parse(linesave[2]); } else if (linesave.Length > 7 && linesave[0] == "in" && linesave[1] == "2") { MapNpcDTO npctest = new MapNpcDTO(); npctest.MapX = short.Parse(linesave[4]); npctest.MapY = short.Parse(linesave[5]); npctest.MapId = map; npctest.NpcVNum = short.Parse(linesave[2]); if (long.Parse(linesave[3]) > 20000) { continue; } npctest.MapNpcId = short.Parse(linesave[3]); if (effectlist.ContainsKey(npctest.MapNpcId)) { npctest.Effect = effectlist[npctest.MapNpcId]; } npctest.EffectDelay = 5000; if (movementlist.ContainsKey(npctest.MapNpcId)) { npctest.Move = movementlist[npctest.MapNpcId]; } else { npctest.Move = false; } npctest.Position = short.Parse(linesave[6]); npctest.Dialog = short.Parse(linesave[9]); npctest.IsSitting = linesave[13] == "1" ? false : true; if (DAOFactory.NpcMonsterDAO.LoadById(npctest.NpcVNum) != null) { if (DAOFactory.MapNpcDAO.LoadById(npctest.MapNpcId) == null) { DAOFactory.MapNpcDAO.Insert(npctest); npcCounter++; } } } } Logger.Log.Info(string.Format(Language.Instance.GetMessageFromKey("NPCS_PARSED"), npcCounter)); }