Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile XML into Java

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?

like image 431
SHiRKiT Avatar asked Mar 18 '26 19:03

SHiRKiT


1 Answers

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.

  1. Javascript is included as a scripting engine language by default ( Rhino )
  2. Lua is a good choice as a dedicated embedded scripting language
  3. Jython is very popular
  4. JRuby is available as well

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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!