开发者

Dynamic callbacks from dynamic inventory

I am working on a Magic The Gathering game simulator. I haven't found any free systems that allow you to create your own decks which also manage the game (life/toughness, counters, triggered events, etc.).

My problem is that I need to find an efficient way to have triggered events fire for cards which are in play. I am envisioning the card lists being stored in XML format and containing identifiers for the actions they take like follows:

<card>
   <name>Bloodghast</name>
   <cost>BB</cost>
   <type>Creature</type>
   <subtypes>Vampire,Spirit</subtypes>
   <stats>2,1</stats>
   <color>B</color>
   <attributes>
      <attribute>
         <id>C41</id>
         <description>Bloodghast can't block.</description>
      </attribute>
      <attribute>
         <id>C42</id>
         <description>Bloodghast has haste as long as an opponent has 10 or less life/</description>
      </attribute>
      <attribute>
         <id>LF5</id>
         <description>Landfall - Whenever a land enters the battlefield under your control, you may return Bloodghast from your graveyard to the battlefield.</description>
      </attribute>
   </attributes>

Sorry for making that verbose (and probably not understandable for anyone who doesn't really play Magic). So I would read in this tree for each card that is loaded for a deck. I need a way to hook the attributes of the card into the "game engine" so that, for instance, when a player's life total drops below 10 Bloodghast gains haste, or w开发者_高级运维hen a land is played, the engine will allow me to grab him out of my graveyard. For those who have not played Magic, other examples would be that some cards trigger an action when a player discards a card or play a spell of a certain color.

I was thinking I would probably have to have an event handler on the engine for each circumstance which would trigger an event (player plays a spell, player life total changes) and that each card would have to somehow add an element to some list allow it to link itself to that event, but I couldn't even start to think of a good way to do it.

Any help would be greatly appreciated. I'm a pretty decent programmer, but I would rather not have to start this project 5 times and re-write the entire thing.


I would suggest using a proper database such as SQLite or SQLExpress so you can set up relationships and normalize your data (no comma delimited lists, for example).

Coming up with a rules engine is going to be difficult for Magic; Effects can do all sorts of crazy things and your rules engine will have to accommodate all of them. Essentially, you'll be recreating the rules engine from the Magic: The Gathering video games in order to know what is going to happen and when.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜