It is currently 20 Apr 2024, 00:05
   
Text Size

java code for Ward Sliver

Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins

java code for Ward Sliver

Postby kdesmond » 20 Sep 2012, 02:36

I'm trying to create java code for the card "Ward Sliver" and I am having some issues. The following is what I have so far:


Code: Select all
public class Ward_Sliver {


      public static final MagicWhenComesIntoPlayTrigger T = new MagicWhenComesIntoPlayTrigger() {
      @Override
      public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final MagicPlayer player) {
         
         return new MagicEvent(
               permanent,
               player,
               new MagicMayChoice(
                     "Choose a color",                           
                     MagicColorChoice.ALL_INSTANCE),
                     new Object[]{player},
                     this,
                     "You may$ Choose a color$." +
               " All Slivers have protection from chosen color.");
      }

      @Override
      public void executeEvent(final MagicGame game,final MagicEvent event,final Object data[],final Object[] choiceResults) {

         //final MagicColor color=(MagicColor)choiceResults[1];
         //MagicAbility ability = color.getProtectionAbility();
         //final long givenAbilityFlags = ability.getMask();
      
      };

      };

   
     /* public static MagicStatic genABStatic(final long givenAbilityFlags) {
     
          return new MagicStatic(MagicLayer.Ability, MagicTargetFilter.TARGET_SLIVER) {
              @Override
              public long getAbilityFlags(
                  final MagicPermanent source,
                  final MagicPermanent permanent,
                  final long flags) {
                  return flags | givenAbilityFlags;
                 //return flags | MagicAbility.ProtectionFromRed.getMask();
              }
             
          };
      }*/
     
   public static final MagicStatic S = new MagicStatic(
         MagicLayer.Ability,
         MagicTargetFilter.TARGET_SLIVER) {
      
      @Override
      public long getAbilityFlags(final MagicPermanent source,final MagicPermanent permanent,final long flags) {
         //return flags | ability.getMask();
         return flags | MagicAbility.ProtectionFromRed.getMask();
         
      }
   };
};
which compiles and runs fine, but doesn't have the desired behaviour; for now it just gives Slivers protection from red because I hard-coded it in. I'm trying to find a way to pass the choice of colour for the protection ability to MagicStatic (as you can see by the parts that I commented out).

If anyone has some suggestions I would be glad to hear. I have been stubbornly trying to resolve this myself but I am not a java programmer and I've reached the limit of what I can figure out quickly by looking at scripts for other cards. Thanks!!
kdesmond
 
Posts: 3
Joined: 20 Sep 2012, 02:21
Has thanked: 1 time
Been thanked: 0 time

Re: java code for Ward Sliver

Postby melvin » 20 Sep 2012, 05:19

Hi kdesmond, welcome to the forum and to Magarena modifications :D

The solution in this case is to create the MagicStatic object and add it to the game as part of the resolution of the trigger. See src/magic/card/Aven_Mimeomancer.java.

The executeEvent for the trigger should look something like the following:
Code: Select all
@Override
public void executeEvent(
    final MagicGame game,
    final MagicEvent event,
    final Object data[],
    final Object[] choiceResults) {

    final MagicColor color=(MagicColor)choiceResults[1];
    MagicAbility protection = color.getProtectionAbility();
    game.doAction(new MagicAddStaticAction((MagicPermanent)event.getSource(), new MagicStatic(
        MagicLayer.Ability,
        MagicTargetFilter.TARGET_SLIVER) {
        @Override
        public long getAbilityFlags(final MagicPermanent source,final MagicPermanent permanent,final long flags) {
            return flags | protection.getMask();
        }
    ));
};
Looking forward to have the first real "Sliver" in the game (besides Venser's Sliver).
User avatar
melvin
AI Programmer
 
Posts: 1062
Joined: 21 Mar 2010, 12:26
Location: Singapore
Has thanked: 36 times
Been thanked: 459 times

Re: java code for Ward Sliver

Postby kdesmond » 21 Sep 2012, 01:09

This worked like a charm, thank you!

Now I just have to remove the "may" part from the colour choice, and it should be ready to submit.
kdesmond
 
Posts: 3
Joined: 20 Sep 2012, 02:21
Has thanked: 1 time
Been thanked: 0 time


Return to Magarena

Who is online

Users browsing this forum: No registered users and 52 guests


Who is online

In total there are 52 users online :: 0 registered, 0 hidden and 52 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 52 guests

Login Form