Announcement Announcement Module
Collapse
No announcement yet.
I have to define a lot of beans, and it's annoying... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • I have to define a lot of beans, and it's annoying...

    I'm making a game with many abilities and each ability has a status effect. The ability is a singleton, but every time you use it, it puts a new status effect on a character (a lookup method is used for this). I'd like to DI all of this, but it's very verbose and error prone. I'd like to get some advice on a better way of doing things, (if it exists).

    ATM, I have an abstract ability class defined as such:

    Code:
        <bean name="ability" class="com.haverlocke.server.battlecharacter.ability.Ability"
              abstract="true">
            <property name="apCost" value="0"/>
            <property name="minimumLevel" value="1"/>
        </bean>
    Now, in my game each ability is either offensive or defensive and each ability is either physical or magical. As a result, I have these 4 additional definitions:

    Code:
        <bean name="physicalOffense" parent="ability" abstract="true">
            <property name="offensive" value="true"/>
            <property name="reactionType" value="PHYSICAL"/>
        </bean>
    
        <bean name="magicalOffense" parent="ability" abstract="true">
            <property name="offensive" value="true"/>
            <property name="reactionType" value="MAGICAL"/>
        </bean>
    
        <bean name="physicalDefense" parent="ability" abstract="true">
            <property name="offensive" value="false"/>
            <property name="reactionType" value="PHYSICAL"/>
        </bean>
    
        <bean name="magicalDefense" parent="ability" abstract="true">
            <property name="offensive" value="false"/>
            <property name="reactionType" value="MAGICAL"/>
        </bean>
    And now, here's a concrete ability called bash:

    Code:
        <bean name="bash" parent="physicalOffense" scope="prototype">
            <property name="name" value="Bash"/>
            <lookup-method name="copyStatusEffect" bean="bashSe"/>
        </bean>
        <bean name="bashSe" parent="hpDamageSe" scope="prototype">
            <property name="normalDamage" value="20"/>
        </bean>
    Notice that the bash ability takes a bash status effect (bashSe). The bash status effect is itself a child of an abstract bean called hpDamageSe.

    As you can imagine, the number of beans I have to define is going to explode. In my game, I don't think it will be out of the question to have up to 100 abilities so this will quickly get out of hand. Is there a less verbose way of wiring these beans together? I think this would be a lot less verbose if I could define the beans in Java (or another scripting language) but I don't know if that's possible.

    Thanks,
    Dan

  • #2
    You could set it up so that you have a file, maybe as simple as a plain text file, that maps those properties to values and then when the application starts up it can read each file into a new bean.

    The advantage here would be that you could create a new file to create a new skill, rather than having to edit the code directly, but you would have to have it go find those files and parse them everytime the app loads (I imagine this would have some kind, maybe irrelevant, performance impact)

    You could also write out all your properties in another file, but doing something like:
    .appCost,0;
    And when you're done do a find-replace on ., replacing it with <property name=" and replace , with " value=" and ; with "/>
    For a slightly more user friendly typing experience.

    Comment

    Working...
    X