[Release]Namechange Item

06/18/2019 20:51 AfterLife-#1
Add this to OpenNos.Handler.FamilyPacketHandler -> CreateFamily


Code:
else if (createFamilyPacket.CharacterName != null && Session.Character.Group == null && Session.Character.Inventory.Any(x => x.Item.VNum == 1638)) // Enter Item VNum
    if (createFamilyPacket.CharacterName.Length< 4 || createFamilyPacket.CharacterName.Length> 14)
    {
        Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}");
    }
    else
    {
        private Regex rg = new Regex(@"^[A-Za-z0-9_äÄöÖüÜß~*<>°+-.!_-Й¤£±†‡×ßø^\S]+$");
        if (rg.Matches(createFamilyPacket.CharacterName).Count == 1)
        {
            if (DAOFactory.CharacterDAO.LoadByName(createFamilyPacket.CharacterName) == null)
            {
                Session.Character.Name = createFamilyPacket.CharacterName;

                if (Session.Character.Miniland == Session.Character.MapInstance)
                {
                    ServerManager.Instance.JoinMiniland(Session, Session);
                }
                else
                {
                    ServerManager.Instance.ChangeMapInstance(Session.Character.CharacterId, Session.Character.MapInstanceId, Session.Character.PositionX, Session.Character.PositionY, true);
                    Session.SendPacket(StaticPacketHelper.Cancel(2));
                }

                Session.Character.Inventory.RemoveItemFromInventory(Session.Character.Inventory.LoadByVNum<ItemInstance>(1638).Id);
                Session.Character.Save();
            }
            else
            {
                Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("ALREADY_TAKEN")}");
            }
        }
        else
        {
            Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}");
        }
    }
}
Then create a new Item-Case (i've used OpenNos.GameObject.SpecialItem)

Code:
//Namechange
case 1638:
    if (session.Character.Group != null && session.Character.Inventory.Any(x => x.Item.VNum == 1638)) // Enter VNum
    {
        session.SendPacket(UserInterfaceHelper.GenerateMsg("Leave your group to change your name", 0));
    }
    else
    {
        session.SendPacket(UserInterfaceHelper.GenerateInbox($"#glmk^ 14 1 Charactername Charactername"));
    }
    break;
06/18/2019 21:12 Blowa#2
Thanks for your release anyway :

This should not be implemented inside the "CreateFamily" method, as its name tells, it's designed to handle family creation.
Create a designed method for the character name changements (which is already done through commands, just refactor both and merge the code properly, enjoy, you got a maintainable feature that you can plug to more things without having to again write the code somewhere else)

And stop using hardcoded values inside predicate lambdas, use configurations (struct/class configuration or App's settings through ConfigurationManager) or at least, const value with a real name so you get the compile time advantages and more maintainability...

Hope you get it right,
Blowa.
06/18/2019 21:36 AfterLife-#3
Quote:
Originally Posted by val77 View Post
Thanks for your release anyway :

This should not be implemented inside the "CreateFamily" method, as its name tells, it's designed to handle family creation.
Create a designed method for the character name changements (which is already done through commands, just refactor both and merge the code properly, enjoy, you got a maintainable feature that you can plug to more things without having to again write the code somewhere else)

And stop using hardcoded values inside predicate lambdas, use configurations (struct/class configuration or App's settings through ConfigurationManager) or at least, const value with a real name so you get the compile time advantages and more maintainability...

Hope you get it right,
Blowa.

I totally agree that this implementation is poor structured and definitly not well done.
I was rather depressed about the fact that people try selling such poor implementations of this feature and decided to post it for good.

Will definitly look into re-doing some of my older releases "the right way" as soon as i get enough freetime to do so. Am currently not capable of spending more then 5-10 Minutes on such things.
06/19/2019 19:49 Prophecy_#4
In my opinion the BasicPacketHandler could be a good spot to handle this.

But it is very usefull, thanks for sharing! :)
06/19/2019 23:38 AfterLife-#5
Quote:
Originally Posted by Prophecy_ View Post
In my opinion the BasicPacketHandler could be a good spot to handle this.

But it is very usefull, thanks for sharing! :)
First of all thank you for your comment.

This was done in a rush.
I've located it in the FamilyCreate Method because i wanted the InGame Pop-Up to be present. Could've used the Speaker packet as well thou. I don't know how to trigger a packet-response from the client similar to this with another packet then those two to be honest, so i've done my 5 minute job and put it in there.

Might be possible to trigger the In-Game Pop-up with another recieve packet that allows me to send an unused Packet back to the Server.
06/20/2019 09:52 GGGGame#6
Quote:
Originally Posted by AfterLife- View Post
Might be possible to trigger the In-Game Pop-up with another recieve packet that allows me to send an unused Packet back to the Server.
on SpecialItem.cs

Code:
                case 261:
                    if (!session.Character.IsVehicled && Option == 0)
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateGuri(10, 5, session.Character.CharacterId, 1));
                    }
                    break;
BasicPacketHandler.cs

Code:
if (guriPacket.Argument == 5)
                    {
                     // Your code for change name
                    }
06/01/2020 14:08 zazouzo#7
Hi i have a small question can you contact me on discord ?
Kintsugi #3701