Voxpire

Vita-Nex
Administrator
Voxpire submitted a new resource:

Sandboxed System Serialization - How to avoid editing PlayerMobile when possible

This short tutorial describes how to avoid editing PlayerMobile when introducing new features to your server.

A basic "talent" system will be used as the means to add context to the way persistent data can be handled without the need to update PlayerMobile's Serialize or Deserialize methods.

Why is this beneficial?
Decoupling the data from the owner allows you to maintain synchronicity when updating to the latest ServUO repository; if ServUO is updated and requires a version change in...

Read more about this resource...
 
I assume this method can also be used to avoid editing any object directly!? Like Mobile.. or Item..
 
@Korasek Yes, they are called "Extension Methods". Here's a quote from Microsoft's page:
Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.

I have 2 questions:
  1. Is there a way to mimic polymorphism with this code architecture?
  2. Is there a way to extend the class' property with our added features when using [props?

1. Polymorphism / overriding a static method.
I searched and couldn't find a way to override or redefine, in the Script section of the code, an existing Extension Method. In my specific case, I have methods extending the Mobile class. My "master factory class" has to be defined in the Server project has I need some of its methods in the server code.

I also want to have different behavior for this method depending on if said mobile is PlayerMobile or BaseCreature. The Server code has no awareness, as far as I know, of those classes. In my previous version, I had the method defined directly in the Mobile class and it was overridden by PlayerMobile and BaseCreature.

Is there a way to achieve the same functionalities with the "sandbox" approach?

2. Extend the class' property list for [props.
I extended the PlayerMobile class with information I want the GMs to view and modify from a [props command. Right now, what I did is create a "[customprops" command that asks for a target and retrieves the custom class for said target. The custom class is marker with the attribute [PropertyObject] and each property of said class that need to be accessible are marked with [CommandProperty(...)]. The command then sends a PropertiesGump with the custom class as argument.

This is acceptable and working fine. I am just wondering if it could somehow be hooked into the existing player's property without modifications of ServUO files. My understanding is that this is not possible.
 

Active Shards

Donations

Total amount
$80.00
Goal
$1,000.00
Back