Code: Select all
struct CharacterStats play {
…
}
class MyRPGPlayerPawn : PlayerPawn abstract {
CharacterStats stats;
…
}
class MyRPGMonster : Actor abstract {
CharacterStats stats;
…
}
Since we're not getting multiple inheritance (even of field declarations), the only way I know of to solve this problem is with this slow, abstraction-breaking pattern:
Code: Select all
struct CharacterStats play {
int Strength, Perception, Endurance, Charisma, Intelligence, Agility, Luck;
void Copy(CharacterStats from) {
Strength = from.Strength;
Perception = from.Perception;
Endurance = from.Endurance;
Charisma = from.Charisma;
Intelligence = from.Intelligence;
Agility = from.Agility;
Luck = from.Luck;
}
static bool Get(Actor actor, in out CharacterStats stats) {
if (actor is "MyRPGPlayerPawn") {
stats.Copy(MyRPGPlayerPawn(actor).stats);
return true;
}
else if (actor is "MyRPGMonster") {
stats.Copy(MyRPGMonster(actor).stats);
return true;
}
else
return false;
}
static bool Set(Actor actor, CharacterStats stats) {
if (actor is "MyRPGPlayerPawn") {
MyRPGPlayerPawn(actor).stats.Copy(stats);
return true;
}
else if (actor is "MyRPGMonster") {
MyRPGMonster(actor).stats.Copy(stats);
return true;
}
else
return false;
}
}