Page 1 of 1

[SNV:r3232] NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 6:25 am
by Leodagan
I noticed that Templated Mob will always be of GameNPC class...

ClassType work in the Mob Table, but once it's templated it default to GameNPC, I think this comes from the GameNPC(INPCTemplate template) constructor, which calls GameNPC default constructor, the Templated Constuctor isn't overriden in the subclass code of GameNPC so it defaults to GameNPC constructor ?

I'm looking more into that matter !

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 7:58 am
by Leodagan
I think the trouble is around : DOL.GS.Region.LoadFromDatabase()

It's only taking Template into account when there is a GuildScript, and even then, if there is a template it will go to "Constructor(npctemplate)"
Code: Select all
if (mob.NPCTemplateID != -1) { constructorParams = new Type[] { typeof(INpcTemplate) }; ConstructorInfo handlerConstructor = typeof(GameNPC).GetConstructor(constructorParams); INpcTemplate template = NpcTemplateMgr.GetTemplate(mob.NPCTemplateID); myMob = (GameNPC)handlerConstructor.Invoke(new object[] { template }); }
There are really almost no Derived Class of GameNPC that override "base(npctemplate)" or even implement it

I'm thinking it'll need two patch...

Tell the region mob load to check for Template.Classtype if any and if it's a replacing template...

Tells the GameNPC(template) Constructor to check for classtype and instantiate the subclass instead of main class (not really sure how C# work for this kind of stuff)

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 8:57 am
by Leodagan
Ok I've documented on C# there is no elegant Way to obtain Derived Constructor with parameters (the one used by GameNPC(template) won't be inherited from derived class)

So I changed Region Loader to only call parameterless Constructor from Derived GameNPC then if there is a template I can call LoadTemplate that is inherited from derived classes...

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 3:26 pm
by Leodagan
I made a patch...
Code: Select all
Index: world/Region.cs =================================================================== --- world/Region.cs (revision 3226) +++ world/Region.cs (working copy) @@ -798,6 +798,17 @@ { GameNPC myMob = null; string error = string.Empty; + + // Default Classtype + string classtype = ServerProperties.Properties.GAMENPC_DEFAULT_CLASSTYPE; + + // load template if any + INpcTemplate template = null; + if(mob.NPCTemplateID != -1) + { + template = NpcTemplateMgr.GetTemplate(mob.NPCTemplateID); + } + if (mob.Guild.Length > 0 && mob.Realm >= 0 && mob.Realm <= (int)eRealm._Last) { @@ -806,18 +817,9 @@ { try { - Type[] constructorParams; - if (mob.NPCTemplateID != -1) - { - constructorParams = new Type[] { typeof(INpcTemplate) }; - ConstructorInfo handlerConstructor = typeof(GameNPC).GetConstructor(constructorParams); - INpcTemplate template = NpcTemplateMgr.GetTemplate(mob.NPCTemplateID); - myMob = (GameNPC)handlerConstructor.Invoke(new object[] { template }); - } - else - { - myMob = (GameNPC)type.Assembly.CreateInstance(type.FullName); - } + + myMob = (GameNPC)type.Assembly.CreateInstance(type.FullName); + } catch (Exception e) { @@ -827,12 +829,14 @@ } } - + if (myMob == null) { - string classtype = ServerProperties.Properties.GAMENPC_DEFAULT_CLASSTYPE; - - if (mob.ClassType != null && mob.ClassType.Length > 0 && mob.ClassType != Mob.DEFAULT_NPC_CLASSTYPE) + if(template != null && template.ClassType != null && template.ClassType.Length > 0 && template.ClassType != Mob.DEFAULT_NPC_CLASSTYPE && template.ReplaceMobValues) + { + classtype = template.ClassType; + } + else if (mob.ClassType != null && mob.ClassType.Length > 0 && mob.ClassType != Mob.DEFAULT_NPC_CLASSTYPE) { classtype = mob.ClassType; }
I removed all code from templated GuildScript NPC loading, as I have no use to it, I want to call the default constructor anyway ! (it still do what is expected from it ! no worries...)

I put template lookup at begining of foreach and use it only to replace mob.classtype in case it's not default...

The rest of the code do what I want, as there is a GameNPC.loadFromDatabase() which is called at the end, this method is derived to child class so it will use GameNPC one or a another implementation that should take template into account (anyway I don't matter my NPC is already instatiated as subclass that's what I really need to make it behave like hoped...)

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 4:07 pm
by Graveen
Can you post your patch file please ? I should review it and make sure it works.
Interesting bug !!! TY !

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 4:39 pm
by Leodagan
here it is !

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 5:23 pm
by Leodagan
I think there is a BodyType bug too with NPCTemplate...

All my templated mob have bodytype = 1 !

but it's nowhere related to this patch

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Wed Jul 31, 2013 11:12 pm
by Argo
I think there is a BodyType bug too with NPCTemplate...

All my templated mob have bodytype = 1 !

but it's nowhere related to this patch
i can't confirm that bug. all my templated mobs have the bodytype that's defined in NPCT.

regards

Argo

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Thu Aug 01, 2013 4:54 am
by Leodagan
I think there is a BodyType bug too with NPCTemplate...

All my templated mob have bodytype = 1 !

but it's nowhere related to this patch
i can't confirm that bug. all my templated mobs have the bodytype that's defined in NPCT.

regards

Argo
Thanks, that'll help me to look somewhere else ! ;)

In fact I checked most references of Bodytype in the Core Code, nothing looks wrong, I should check my DB, maybe something is wrong with datatype...

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Thu Aug 01, 2013 8:12 am
by Leodagan
You're right... It'll look stupid but the problem came from my multiple Databases instances (I'm working with more than 20 databases...)

I updated the wrong one with body types... so I couldn't notice the change ;)

Re: NPCTemplate ClassType and GameNPC problem

PostPosted: Fri Aug 30, 2013 6:57 am
by Leodagan
Added to SVN revision 3232 after re-reading, re-diffing, nothing seems wrong to me...

Re: [SNV:r3232] NPCTemplate ClassType and GameNPC problem

PostPosted: Fri Aug 30, 2013 7:49 am
by Graveen
yeaahhh ! TY !

Re: [SNV:r3232] NPCTemplate ClassType and GameNPC problem

PostPosted: Tue May 06, 2014 5:08 pm
by razerwing
Sorry in advance for my simple questions, but I wanted to clarify a couple things.

This patch resolves the issue with NPCs being unresponsive?

How do I go about applying this patch?

Thank you.

Re: [SNV:r3232] NPCTemplate ClassType and GameNPC problem

PostPosted: Tue May 06, 2014 6:05 pm
by razerwing
Please forgive my noob questions, but does this patch resolve the unresponsive NPCs in Alpha 3.1?

Also how do I go about applying this patch?

Thank you!