[SNV:r3232] NPCTemplate ClassType and GameNPC problem

Discussions on various DOL development features

Moderator: Support Team

[SNV:r3232] NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Wed Jul 31, 2013 6:25 am

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 !
Last edited by Leodagan on Fri Aug 30, 2013 6:57 am, edited 1 time in total.
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Wed Jul 31, 2013 7:58 am

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)
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Wed Jul 31, 2013 8:57 am

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...
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Wed Jul 31, 2013 3:26 pm

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...)
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Graveen » Wed Jul 31, 2013 4:07 pm

Can you post your patch file please ? I should review it and make sure it works.
Interesting bug !!! TY !
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Wed Jul 31, 2013 4:39 pm

here it is !
Attachments
Region.cs.patch
(2.98 KiB) Downloaded 52 times
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Wed Jul 31, 2013 5:23 pm

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
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Argo » Wed Jul 31, 2013 11:12 pm

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
Möge Gott sein zwischen Dir und dem Leid, an allen dunklen und verlassenen Orten, die Du erreichen wirst.
Argo
Server Team
 
Posts: 1760
Joined: Thu Sep 18, 2008 6:21 pm
Location: Berlin, Germany

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Thu Aug 01, 2013 4:54 am

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...
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Thu Aug 01, 2013 8:12 am

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 ;)
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: NPCTemplate ClassType and GameNPC problem

Postby Leodagan » Fri Aug 30, 2013 6:57 am

Added to SVN revision 3232 after re-reading, re-diffing, nothing seems wrong to me...
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

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

Postby Graveen » Fri Aug 30, 2013 7:49 am

yeaahhh ! TY !
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

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

Postby razerwing » Tue May 06, 2014 5:08 pm

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.
razerwing
DOL Guest
 
Posts: 2
Joined: Tue May 06, 2014 5:02 pm

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

Postby razerwing » Tue May 06, 2014 6:05 pm

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!
razerwing
DOL Guest
 
Posts: 2
Joined: Tue May 06, 2014 5:02 pm


Return to “%s” DOL Development Discussion

Who is online

Users browsing this forum: No registered users and 1 guest