Beispiel #1
0
        public MapMonster(MapMonsterDTO monsterdto, Map parent)
        {
            _random = new Random(monsterdto.MapMonsterId);

            // Replace by MAPPING
            MapId        = monsterdto.MapId;
            MapX         = monsterdto.MapX;
            MapMonsterId = monsterdto.MapMonsterId;
            MonsterVNum  = monsterdto.MonsterVNum;
            MapY         = monsterdto.MapY;
            Position     = monsterdto.Position;
            FirstX       = monsterdto.MapX;
            FirstY       = monsterdto.MapY;
            IsMoving     = monsterdto.IsMoving;
            ///////////////////////////////////

            LastEffect = LastMove = DateTime.Now;
            Target     = -1;
            Path       = new List <MapCell>();
            Map        = parent;
            Alive      = true;
            Respawn    = true;
            Monster    = ServerManager.GetNpc(MonsterVNum);
            CurrentHp  = Monster.MaxHP;
            CurrentMp  = Monster.MaxMP;
            Skills     = Monster.Skills.ToList();
            DamageList = new Dictionary <long, long>();
            _movetime  = _random.Next(400, 3200);
        }
Beispiel #2
0
        public void InsertMapMonster(List <string[]> packetList)
        {
            var   monsterCounter   = 0;
            short map              = 0;
            var   mobMvPacketsList = new List <int>();
            var   monsters         = new List <MapMonsterDTO>();

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("mv") && o[1].Equals("3")))
            {
                if (!mobMvPacketsList.Contains(Convert.ToInt32(currentPacket[2])))
                {
                    mobMvPacketsList.Add(Convert.ToInt32(currentPacket[2]));
                }
            }

            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] != "3")
                {
                    continue;
                }

                var monster = new MapMonsterDTO
                {
                    MapId        = map,
                    VNum         = short.Parse(currentPacket[2]),
                    MapMonsterId = int.Parse(currentPacket[3]),
                    MapX         = short.Parse(currentPacket[4]),
                    MapY         = short.Parse(currentPacket[5]),
                    Direction    = (byte)(currentPacket[6] == string.Empty ? 0 : byte.Parse(currentPacket[6])),
                    IsDisabled   = false
                };
                monster.IsMoving = mobMvPacketsList.Contains(monster.MapMonsterId);

                if (DAOFactory.NpcMonsterDAO.FirstOrDefault(s => s.NpcMonsterVNum.Equals(monster.VNum)) == null ||
                    DAOFactory.MapMonsterDAO.FirstOrDefault(s => s.MapMonsterId.Equals(monster.MapMonsterId)) != null ||
                    monsters.Count(i => i.MapMonsterId == monster.MapMonsterId) != 0)
                {
                    continue;
                }

                monsters.Add(monster);
                monsterCounter++;
            }


            IEnumerable <MapMonsterDTO> mapMonsterDtos = monsters;

            DAOFactory.MapMonsterDAO.InsertOrUpdate(mapMonsterDtos);
            Logger.Log.Info(string.Format(LogLanguage.Instance.GetMessageFromKey(LanguageKey.MONSTERS_PARSED),
                                          monsterCounter));
        }
Beispiel #3
0
 public MapMonsterDTO Insert(MapMonsterDTO mapmonster)
 {
     using (var context = DataAccessHelper.CreateContext())
     {
         MapMonster entity = Mapper.Map <MapMonster>(mapmonster);
         context.mapmonster.Add(entity);
         context.SaveChanges();
         return(Mapper.Map <MapMonsterDTO>(entity));
     }
 }
Beispiel #4
0
        public void ImportMonsters()
        {
            int   monsterCounter = 0;
            short map            = 0;
            Dictionary <int, bool> movementlist = new Dictionary <int, bool>();

            foreach (string[] linesave in packetList.Where(o => o[0].Equals("mv") && (o[1].Equals("3"))))
            {
                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("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] == "3")
                {
                    MapMonsterDTO monster = new MapMonsterDTO();

                    monster.MapX         = short.Parse(linesave[4]);
                    monster.MapY         = short.Parse(linesave[5]);
                    monster.MapId        = map;
                    monster.MonsterVNum  = short.Parse(linesave[2]);
                    monster.MapMonsterId = int.Parse(linesave[3]);
                    if (movementlist.ContainsKey(monster.MapMonsterId))
                    {
                        monster.Move = movementlist[monster.MapMonsterId];
                    }
                    else
                    {
                        monster.Move = false;
                    }
                    if (DAOFactory.NpcMonsterDAO.LoadById(monster.MonsterVNum) != null)
                    {
                        if (DAOFactory.MapMonsterDAO.LoadById(monster.MapMonsterId) == null)
                        {
                            DAOFactory.MapMonsterDAO.Insert(monster);
                            monsterCounter++;
                        }
                    }
                }
            }

            Logger.Log.Info(string.Format(Language.Instance.GetMessageFromKey("MONSTERS_PARSED"), monsterCounter));
        }
Beispiel #5
0
 public IEnumerable <MapMonsterDTO> LoadFromMap(short mapId)
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         List <MapMonsterDTO> result = new List <MapMonsterDTO>();
         foreach (MapMonster MapMonsterobject in context.MapMonster.Where(c => c.MapId.Equals(mapId)))
         {
             MapMonsterDTO dto = new MapMonsterDTO();
             Mapper.Mappers.MapMonsterMapper.ToMapMonsterDTO(MapMonsterobject, dto);
             result.Add(dto);
         }
         return(result);
     }
 }
Beispiel #6
0
        private static MapMonsterDTO update(MapMonster entity, MapMonsterDTO mapMonster, OpenNosContext context)
        {
            if (entity != null)
            {
                Mapper.Mappers.MapMonsterMapper.ToMapMonster(mapMonster, entity);
                context.Entry(entity).State = EntityState.Modified;
                context.SaveChanges();
            }
            if (Mapper.Mappers.MapMonsterMapper.ToMapMonsterDTO(entity, mapMonster))
            {
                return(mapMonster);
            }

            return(null);
        }
Beispiel #7
0
 public MapMonster(MapMonsterDTO input)
 {
     Buff           = new ThreadSafeSortedList <short, Buff>();
     HitQueue       = new ConcurrentQueue <HitRequest>();
     OnDeathEvents  = new List <EventContainer>();
     OnNoticeEvents = new List <EventContainer>();
     IsDisabled     = input.IsDisabled;
     IsMoving       = input.IsMoving;
     MapId          = input.MapId;
     MapMonsterId   = input.MapMonsterId;
     MapX           = input.MapX;
     MapY           = input.MapY;
     MonsterVNum    = input.MonsterVNum;
     Position       = input.Position;
 }
        private void ExecuteHandler(ClientSession session)
        {
            if (_isParsed)
            {
                Logger.LogUserEvent("GMCOMMAND", session.GenerateIdentity(),
                                    $"[AddMonster]NpcMonsterVNum: {MonsterVNum} IsMoving: {IsMoving}");

                if (!session.HasCurrentMapInstance)
                {
                    return;
                }

                NpcMonster npcmonster = ServerManager.GetNpcMonster(MonsterVNum);
                if (npcmonster == null)
                {
                    return;
                }

                MapMonsterDTO monst = new MapMonsterDTO
                {
                    MonsterVNum  = MonsterVNum,
                    MapY         = session.Character.PositionY,
                    MapX         = session.Character.PositionX,
                    MapId        = session.Character.MapInstance.Map.MapId,
                    Position     = session.Character.Direction,
                    IsMoving     = IsMoving,
                    MapMonsterId = DAOFactory.MapMonsterDAO.GetNextMapMonsterId()
                };
                if (!DAOFactory.MapMonsterDAO.DoesMonsterExist(monst.MapMonsterId))
                {
                    DAOFactory.MapMonsterDAO.Insert(monst);
                    MapMonsterDTO monster = DAOFactory.MapMonsterDAO.LoadById(monst.MapMonsterId);
                    if (monster != null)
                    {
                        MapMonster mapMonster = new MapMonster(monster);
                        mapMonster.Initialize(session.CurrentMapInstance);
                        session.CurrentMapInstance.AddMonster(mapMonster);
                        session.CurrentMapInstance.Broadcast(mapMonster.GenerateIn());
                    }
                }

                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("DONE"), 10));
            }
            else
            {
                session.SendPacket(session.Character.GenerateSay(ReturnHelp(), 10));
            }
        }
 public static bool ToMapMonsterDTO(MapMonster input, MapMonsterDTO output)
 {
     if (input == null)
     {
         return(false);
     }
     output.IsDisabled   = input.IsDisabled;
     output.IsMoving     = input.IsMoving;
     output.MapId        = input.MapId;
     output.MapMonsterId = input.MapMonsterId;
     output.MapX         = input.MapX;
     output.MapY         = input.MapY;
     output.MonsterVNum  = input.MonsterVNum;
     output.Position     = input.Position;
     return(true);
 }
Beispiel #10
0
 public MapMonsterDTO Insert(MapMonsterDTO mapMonster)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             MapMonster entity = _mapper.Map <MapMonster>(mapMonster);
             context.MapMonster.Add(entity);
             context.SaveChanges();
             return(_mapper.Map <MapMonsterDTO>(entity));
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
         return(null);
     }
 }
Beispiel #11
0
        public SaveResult Update(ref MapMonsterDTO mapMonster)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    int        mapMonsterId = mapMonster.MapMonsterId;
                    MapMonster entity       = context.MapMonster.FirstOrDefault(c => c.MapMonsterId.Equals(mapMonsterId));

                    mapMonster = update(entity, mapMonster, context);
                    return(SaveResult.Updated);
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format(Language.Instance.GetMessageFromKey("UPDATE_MAPMONSTER_ERROR"), mapMonster.MapMonsterId, e.Message), e);
                return(SaveResult.Error);
            }
        }
 public void AddMonster(AddMonsterPacket addMonsterPacket)
 {
     if (addMonsterPacket != null)
     {
         if (!Session.HasCurrentMapInstance)
         {
             return;
         }
         NpcMonster npcmonster = ServerManager.Instance.GetNpc(addMonsterPacket.MonsterVNum);
         if (npcmonster == null)
         {
             return;
         }
         MapMonsterDTO monst = new MapMonsterDTO
         {
             MonsterVNum = addMonsterPacket.MonsterVNum,
             MapY = Session.Character.PositionY,
             MapX = Session.Character.PositionX,
             MapId = Session.Character.MapInstance.Map.MapId,
             Position = (byte)Session.Character.Direction,
             IsMoving = addMonsterPacket.IsMoving,
         };
         MapMonsterDTO monst1 = monst;
         if (DAOFactory.MapMonsterDAO.FirstOrDefault(s => s.MapMonsterId == monst1.MapMonsterId) == null)
         {
             DAOFactory.MapMonsterDAO.InsertOrUpdate(ref monst);
             if (DAOFactory.MapMonsterDAO.FirstOrDefault(s => s.MapMonsterId == monst.MapMonsterId) is MapMonster monster)
             {
                 monster.Initialize(Session.CurrentMapInstance);
                 Session.CurrentMapInstance.AddMonster(monster);
                 Session.CurrentMapInstance?.Broadcast(monster.GenerateIn());
             }
         }
         LogHelper.Instance.InsertCommandLog(Session.Character.CharacterId, addMonsterPacket, Session.IpAddress);
         Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("DONE"), 10));
     }
     else
     {
         Session.SendPacket(Session.Character.GenerateSay(AddMonsterPacket.ReturnHelp(), 10));
     }
 }
Beispiel #13
0
        public MapMonsterDTO LoadById(int mapMonsterId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    MapMonsterDTO dto = new MapMonsterDTO();
                    if (Mapper.Mappers.MapMonsterMapper.ToMapMonsterDTO(context.MapMonster.FirstOrDefault(i => i.MapMonsterId.Equals(mapMonsterId)), dto))
                    {
                        return(dto);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
Beispiel #14
0
        public MapMonsterDTO Insert(MapMonsterDTO mapMonster)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    MapMonster entity = new MapMonster();
                    Mapper.Mappers.MapMonsterMapper.ToMapMonster(mapMonster, entity);
                    context.MapMonster.Add(entity);
                    context.SaveChanges();
                    if (Mapper.Mappers.MapMonsterMapper.ToMapMonsterDTO(entity, mapMonster))
                    {
                        return(mapMonster);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
Beispiel #15
0
 public MapMonsterDTO Insert(MapMonsterDTO mapmonster)
 {
     throw new NotImplementedException();
 }