I have a hard task here. I'm thinking of building a simple game, and in this game I'm going to apply a buff system (read here for more information).
So, let's say I want to create a buff:
<buff name="Life Steal">
<afterAttack>
<heal target="attacker">$damage$ * 0.2</heal>`
</afterAttack>
</buff>
This, in thesis, would generate the following output:
public class Life_Steal extends Buff {
@Override
public void afterAttack(Object attacker, Object defender, int damageDone) {
heal(attacker, damageDone * 0.2);
}
}
Is this possible? If so, is there any tool out there that enables me to do something like that?
EDIT
I found out that mixing Javascript and XML would be a good way to go for it.
<buff name="Life Steal>
<onattach>
<javascript>
attacker.hp += damage * 0.2;
</javascript>
</onattach>
</buff>
That's the best solution I could think of. Anyone have a better one?
I don't condone this project, but it is along the lines of what you are doing. Jelly - Executable XML. The most painless way to load XML is JAXB.
That said, a real scripting language would be a much better choice.
In any case read Scripting for the Java Platform and Java Scripting Programmers Guide before you go any further.
If you just have to use XML for some bizarre reason, a mixture of JAXB with scripting imbedded in the XML might be another way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With