Unfortunately, I don't have any of the code left from when I was re-writing the combat system for a mud that never got off the ground.
I'd suggest trying to get as much experience writing muds in existing mudlibs first, so you can decide what features you'd like, and which one's aren't as important for what you're trying to prove.
I doubt I'd ever write a mud from scratch -- there are too many generic things that every mud has, that isn't of interest tome to program -- I'd want to focus on the sections that I could improve. Look at PerlMUD, or some of the LP mudlibs,
That being said -- here's how we structured the object inheritance on the most recent mud I coded on: (working from many years old memory ... it was probably not this linear)
ability / property objects
inherited by -> generic creature / generic player objects
inherited by -> generic race objects
inherited by -> creature library objects
inherited by -> specific creature objects
So, in your case, we'd have 'attackable' as a property, which includes HP as a property, and ways to damage the object. 'can attack' is an ability, which would have ways for the object to deal damange. Most coders wouldn't reference these directly, but would inherit from the generic creature object, which contained those and other properties necessary.
(come to think of it ... I think we had a 'set_race' function in the generic creature, which would dynamically inherit from the appropriate race object -- rases set up intrensic abilities and body structure (eg, which / how many of each armour type it could wear, how many weapons it could wield, base attack speed / strength, damage type resistance / weaknesses (eg, a fire elemental is hurt more by cold, but healed by fire attacks)))
There were then a generic set of creatures that people could inherit, so that we'd make sure that a creatures were consistent between areas coded by different people. (similar hp, xp, damage, item drops, etc.)
And, for those special creatures, area designers could inherit a library monster / object, and give it some tweaks
...
There's way too much info about coding muds than I can easily post in this forum, and there are plenty of other people out there with more skills than I have. I'd suggest that you try lurking in a mud-specific forum. (it may be that you have to specifically wiz on a mud to get to some forums, but there used to be some good usenet newsgroups for this sort of discussion) |