Difference between revisions of "Extending the editor"

From CCG Kit
Jump to: navigation, search
Line 18: Line 18:
 
* Move card effect: It moves the target card to another game zone.
 
* Move card effect: It moves the target card to another game zone.
  
It is possible to create your own custom effects in a very convenient way. The editor will pick them up automatically without you having to write any additional code to do so. If you want to create a new effect, you will first need to decide if it is a player effect (i.e., it targets a player or group of players) or a card effect (i.e., it targets a card or group of cards).
+
It is possible to create your own custom effects in a very convenient way and the editor will pick them up automatically without you having to write any additional code to do so. If you want to create a new effect, you will first need to decide if it is a player effect (i.e., it targets a player or group of players) or a card effect (i.e., it targets a card or group of cards).
 +
 
 +
Let's take the ''increase player stat'' effect as a reference on player effects:
 +
 
 +
<nowiki>
 +
[PlayerTarget]
 +
public class IncreasePlayerStatEffect : PlayerEffect
 +
{
 +
    [PlayerStatField("Player stat")]
 +
    [Order(1)]
 +
    public int statId;
 +
 
 +
    [ValueField("Value")]
 +
    [Order(2)]
 +
    public Value value;
 +
 
 +
    [IntField("Duration")]
 +
    [Order(3)]
 +
    public int duration;
 +
 
 +
    public override void Resolve(GameState state, PlayerInfo player)
 +
    {
 +
        var modifier = new Modifier(value.GetValue(state, player), duration);
 +
        player.stats[statId].AddModifier(modifier);
 +
    }
 +
}
 +
</nowiki>
 +
 
 +
And the ''decrease card effect'' as a reference on card effects:
 +
 
 +
<nowiki>
 +
[CardTarget]
 +
public class DecreaseCardStatEffect : CardStatEffect
 +
{
 +
    [ValueField("Value")]
 +
    [Order(4)]
 +
    public Value value;
 +
 
 +
    [IntField("Duration")]
 +
    [Order(5)]
 +
    public int duration;
 +
 
 +
    public override void Resolve(GameState state, RuntimeCard card)
 +
    {
 +
        var modifier = new Modifier(-value.GetValue(state, card.ownerPlayer), duration);
 +
        card.stats[statId].AddModifier(modifier);
 +
    }
 +
}
 +
</nowiki>
 +
 
 +
As you can see, there are several useful base classes for effects:
 +
 
 +
* PlayerEffect: The base class for player effects.
 +
* CardEffect: The base class for card effects.
 +
* CardStatEffect: The utility base class for card stat effects.
 +
 
 +
And several useful attributes for effect fields:
 +
 
 +
* Order: It allows you to determine the rendering order of the field in the visual editor.
 +
* IntField: Used for integer fields.
 +
* EnumField: Used for enum fields.
 +
* ValueField: Used for value fields.
 +
* PlayerStatField: Used for player stat fields.
 +
* CardTypeField: Used for card type fields.
 +
* CardStatField: Used for card stat fields.
 +
* KeywordTypeField: Used for keyword type fields.
 +
* KeywordValueField: Used for keyword value fields.
 +
* GameZoneField: Used for game zone fields.
  
 
|}
 
|}

Revision as of 03:45, 21 July 2017

Creating new card effects

The kit includes a collection of default card effects:

  • Increase player stat: It increases the stat of the target player by a given amount and for a given duration.
  • Decrease player stat: It decreases the stat of the target player by a given amount and for a given duration.
  • Set player stat: It sets the stat of the target player to a given value.
  • Reset player stat: It resets the stat of the target player to its original value.
  • Increase card stat: It increases the stat of the target card by a given amount and for a given duration.
  • Decrease card stat: It decreases the stat of the target card by a given amount and for a given duration.
  • Set card stat: It sets the stat of the target card to a given value.
  • Reset card stat: It resets the stat of the target card to its original value.
  • Add keyword: It adds a given keyword to the target card.
  • Remove keyword: It removes a given keyword from the target card.
  • Move card effect: It moves the target card to another game zone.

It is possible to create your own custom effects in a very convenient way and the editor will pick them up automatically without you having to write any additional code to do so. If you want to create a new effect, you will first need to decide if it is a player effect (i.e., it targets a player or group of players) or a card effect (i.e., it targets a card or group of cards).

Let's take the increase player stat effect as a reference on player effects:

[PlayerTarget]
public class IncreasePlayerStatEffect : PlayerEffect
{
    [PlayerStatField("Player stat")]
    [Order(1)]
    public int statId;

    [ValueField("Value")]
    [Order(2)]
    public Value value;

    [IntField("Duration")]
    [Order(3)]
    public int duration;

    public override void Resolve(GameState state, PlayerInfo player)
    {
        var modifier = new Modifier(value.GetValue(state, player), duration);
        player.stats[statId].AddModifier(modifier);
    }
}

And the decrease card effect as a reference on card effects:

[CardTarget]
public class DecreaseCardStatEffect : CardStatEffect
{
    [ValueField("Value")]
    [Order(4)]
    public Value value;

    [IntField("Duration")]
    [Order(5)]
    public int duration;

    public override void Resolve(GameState state, RuntimeCard card)
    {
        var modifier = new Modifier(-value.GetValue(state, card.ownerPlayer), duration);
        card.stats[statId].AddModifier(modifier);
    }
}

As you can see, there are several useful base classes for effects:

  • PlayerEffect: The base class for player effects.
  • CardEffect: The base class for card effects.
  • CardStatEffect: The utility base class for card stat effects.

And several useful attributes for effect fields:

  • Order: It allows you to determine the rendering order of the field in the visual editor.
  • IntField: Used for integer fields.
  • EnumField: Used for enum fields.
  • ValueField: Used for value fields.
  • PlayerStatField: Used for player stat fields.
  • CardTypeField: Used for card type fields.
  • CardStatField: Used for card stat fields.
  • KeywordTypeField: Used for keyword type fields.
  • KeywordValueField: Used for keyword value fields.
  • GameZoneField: Used for game zone fields.