[Release] command $AddMonster debug

07/06/2019 23:00 redbull2905#1
In a lot of servers, you'll have a lot of monsters to add on your server. especially those who use open source ciapa know what i'm talking about
when I say it's really shit to add monsters on the db with the command. Reboot mandatory, command bug.... Here is the code that will change your life the monster will appear without restarting your server and the command is absolutely not bug

ps: This code does not come from me but from the source I used.
so you may have to adapt the codes to your source to repair the errors.




Code:
////<auto-generated <- Codemaid exclusion for now (PacketIndex Order is important for maintenance)

using OpenNos.Core;
using OpenNos.Domain;

namespace OpenNos.GameObject.CommandPackets
{
    [PacketHeader("$AddMonster", PassNonParseablePacket = true, Authority = AuthorityType.GameMaster)]
    public class AddMonsterPacket : PacketDefinition
    {
        #region Properties

        [PacketIndex(0)]
        public short MonsterVNum { get; set; }

        [PacketIndex(1)]
        public bool IsMoving { get; set; }

        public static string ReturnHelp()
        {
            return "$AddMonster VNUM MOVE";
        }

        #endregion
    }
}
Code:
        /// <summary>
        /// $AddMonster Command
        /// </summary>
        /// <param name="addMonsterPacket"></param>
        public void AddMonster(AddMonsterPacket addMonsterPacket)
        {
            if (addMonsterPacket != null)
            {
                Logger.LogUserEvent("GMCOMMAND", Session.GenerateIdentity(),
                    $"[AddMonster]NpcMonsterVNum: {addMonsterPacket.MonsterVNum} IsMoving: {addMonsterPacket.IsMoving}");

                if (ServerManager.Instance.Configuration.UseLogService)
                {
                    LogServiceClient.Instance.LogPacket(new PacketLogEntry()
                    {
                        Sender = Session.Character.Name,
                        SenderId = Session.Character.CharacterId,
                        PacketType = LogType.GMCommand,
                        Packet = $"[AddMonster]NpcMonsterVNum: {addMonsterPacket.MonsterVNum} IsMoving: {addMonsterPacket.IsMoving}"
                    });
                }

                if (!Session.HasCurrentMapInstance)
                {
                    return;
                }

                NpcMonster npcmonster = ServerManager.GetNpcMonster(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 = Session.Character.Direction,
                    IsMoving = addMonsterPacket.IsMoving,
                    MapMonsterId = ServerManager.Instance.GetNextMobId()
                };
                if (!DAOFactory.MapMonsterDAO.DoesMonsterExist(monst.MapMonsterId))
                {
                    DAOFactory.MapMonsterDAO.Insert(monst);
                    if (DAOFactory.MapMonsterDAO.LoadById(monst.MapMonsterId) is MapMonsterDTO monsterDTO)
                    {
                        MapMonster monster = new MapMonster(monsterDTO);
                        monster.Initialize(Session.CurrentMapInstance);
                        Session.CurrentMapInstance.AddMonster(monster);
                        Session.CurrentMapInstance?.Broadcast(monster.GenerateIn());
                    }
                }

                Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("DONE"), 10));
            }
            else
            {
                Session.SendPacket(Session.Character.GenerateSay(AddMonsterPacket.ReturnHelp(), 10));
            }
        }
07/07/2019 16:18 Cryless~#2
It totally changed my life ~ another dream become reality. Thank you.
07/08/2019 05:39 0Lucifer0#3
That’s an awesome release :kappa: are you gonna do a thread for all commands of [Only registered and activated users can see links. Click Here To Register...] ?

Seriously except increasing the amount of dumb thread what are you trying to get by releasing already existing code from official opennos repo ?
07/08/2019 06:25 redbull2905#4
[Only registered and activated users can see links. Click Here To Register...]

this code I did not take it at all on your opennos
07/08/2019 08:10 0Lucifer0#5
Quote:
Originally Posted by redbull2905 View Post
[Only registered and activated users can see links. Click Here To Register...]

this code I did not take it at all on your opennos
Yes but this code is log... you don’t even understand what the code does... this is just printing info inside the log the function is already on opennos

You could also do Console.Writeline(123); everywhere and said this code is not a copy... if you copy an exam on someone else and replace your name by your actual name it’s still a copy pasta. This here is the same. Or you could edit your title to this one which would match what you are releasing:
[release] add logs to a command