It is currently 29 Apr 2024, 07:41
   
Text Size

Modular

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Modular

Postby zerker2000 » 03 Oct 2009, 06:38

Code: Select all
private final int shouldModular(Card c) {
         ArrayList<String> a = c.getKeyword();
         for (int i = 0; i < a.size(); i++)
         {
            if (a.get(i).toString().startsWith("Modular"))
               return i;
         }
         return -1;
   }
Code: Select all
while (shouldModular(card) != -1)
    {
       int n = shouldModular(card);
       if (n != -1)
       {
          String parse = card.getKeyword().get(n).toString();
            card.removeIntrinsicKeyword(parse);

            final int m = Integer.parseInt(parse.substring(8));
            String t = card.getSpellText();
            if (!t.equals("")) t += "\r\n";
            card.setText(t + parse + " (This enters the battlefield with " + m + " +1/+1 counters on it. When it's put into a graveyard, you may put its +1/+1 counters on target artifact creature.)");//Erm help? Isn't there a normal way to do this?...
            card.setComesIntoPlay(
                  new Command()
                  {
                     public void execute()
                     {
                        card.addCounter(Counters.P1P1, m);
                     }});
          final SpellAbility ability = new Ability(card, "0")
            {
             public void resolve()
             {
                if (card.getController().equals(Constant.Player.Computer))
                {
                   CardList choices = new CardList(AllZone.Computer_Play.getCards()).filter(
                    new CardListFilter(){public boolean addCard(Card c) {return c.isCreature() && c.isArtifact() && CardFactoryUtil.canTarget(ability, c); }});
                   if (choices.size() != 0)
                      CardFactoryUtil.AI_getBestCreature(choices).addCounter(Counters.P1P1, getSourceCard().getCounters(Counters.P1P1));
                }
                final SpellAbility ability=this;
                AllZone.InputControl.setInput(
                   new Input(){
                      public void showMessage()
                      {
                         AllZone.Display.showMessage("Select target artifact creature");
                         ButtonUtil.enableOnlyCancel();
                      }
                      public void selectButtonCancel() {stop();}
                      public void selectCard(Card card2, PlayerZone zone)
                      {
                         if(card2.isCreature() && card2.isArtifact() && zone.is(Constant.Zone.Play) && CardFactoryUtil.canTarget(ability, card2))
                         {
                            card2.addCounter(Counters.P1P1, ability.getSourceCard().getCounters(Counters.P1P1));//combining input and resolve is skirting rules and hacky at best, but non-stackability of destroyCommand Inputs turns into a major problem when the keyword is mainly used during the simultaneous destruction of combat.
                            stop();
                         }
                      }
                   });
             }//resolve()
            };

          card.setDestroy(new Command()
            {
               private static final long serialVersionUID = 304026662487997331L;
               
               public void execute()
               {
                  ability.setStackDescription("Put "+ card.getCounters(Counters.P1P1) +" +1/+1 counter/s from " + card + " on target artifact creature.");
               AllZone.Stack.push(ability);
               }
            });
           
       }
        
    }
And immediate applications:
Code: Select all
Arcbound Bruiser
5
Artifact Creature Golem
no text
0/0
Modular 3

Arcbound Hybrid
4
Artifact Creature Beast
no text
0/0
Haste
Modular 2

Arcbound Lancer
7
Artifact Creature Beast
no text
0/0
First Strike
Modular 4

Arcbound Stinger
2
Artifact Creature Insect
no text
0/0
Flying
Modular 1

Arcbound Worker
1
Artifact Creature Construct
no text
0/0
Modular 1
These have been tested somewhat, after which no immediate bugs remain.

Side notes:
-I found Ashnod's Transmorgant code in my version, I remember the card working nicely, but I don't think I got around to posting it. Should I post the code, or have I already?
-Dennis, is my mpool code still resisting merging attempts? If so, would me merging it to the version you released today be productive?
-Finally, I am now officially over all eclipse problems and on top of schoolwork, and have resumed working on my to-code list. Any suggestions for further actions? Perhaps changing the manaCost code to check lands for basic land types(which should be a quick fix, but would probably interfere to some degree with merging my code), or trying to set up an InputStack/multi-targeting system? Any suggestions welcome :).

EDIT: added CanTarget code for AI and fixed it for human (used to say canTarget(ability, card) instead of canTarget(ability, card2)).
Last edited by zerker2000 on 03 Oct 2009, 21:04, edited 1 time in total.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby Marek14 » 03 Oct 2009, 06:47

As for the rest of modular cards, MTG Forge has Sliths, so Arcbound Slith should be doable. The others are:

Arcbound Fiend - requires moving counters.
Arcbound Overseer - might be doable if modular is true keyword so it's easy to determine which creatures should get the counter.

Arcbound Ravager
Arcbound Reclaimer
Arcbound Wanderer - will require sunburst.
Marek14
Tester
 
Posts: 2762
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 297 times

Re: Modular

Postby silly freak » 03 Oct 2009, 08:19

___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Modular

Postby DennisBergkamp » 03 Oct 2009, 15:06

Awesome, very nice job on the Modular code =D>

Side notes:
-I found Ashnod's Transmorgant code in my version, I remember the card working nicely, but I don't think I got around to posting it. Should I post the code, or have I already?
-Dennis, is my mpool code still resisting merging attempts? If so, would me merging it to the version you released today be productive?
-Finally, I am now officially over all eclipse problems and on top of schoolwork, and have resumed working on my to-code list. Any suggestions for further actions? Perhaps changing the manaCost code to check lands for basic land types(which should be a quick fix, but would probably interfere to some degree with merging my code), or trying to set up an InputStack/multi-targeting system? Any suggestions welcome :).
:oops: Yes, to be honest, I kind of gave up... I tried a bunch of times, but every time something went wrong :(
I've just made a bunch of changes/fixes to the latest version actually, maybe the best way to do this is to wait a day or two and I will submit you the very latest source I have. Then you could merge your manapool changes (during which I won't make any changes - a good thing really, I could use a bit of a break :) ). And at the same time, you could maybe merge whatever cards you've coded (like Ashnod's Transmorgant).
So this weekend, I will fix a few extra bugs that were posted on this latest version, then I'll send you the latest stuff I've got (either tonight or on Sunday). Does that sound good to you?

I'm not sure what you mean about the manaCost code checking lands for basic land types, but that multi-targeting system sure sounds good :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby zerker2000 » 03 Oct 2009, 17:25

I wrote:-Dennis, is my mpool code still resisting merging attempts? If so, would me merging it to the version you released today be productive?
DennisBergkamp wrote: :oops: Yes, to be honest, I kind of gave up... I tried a bunch of times, but every time something went wrong :(
That seems to be a definite yes :). Anyways, not to sound too <insert derogatory term for self-promotion here>, but my pool Is quite an improvement, supporting resonable undo(I think it untaps souce of ability if ability was tap: add <one mana>, and restores mana to pool otherwise), smart split-cost choosing (e.g. won't offer its red mana when you're paying for {GU} {GU}), and automatic payment (So when the pool has a bunch of {G} from Gea's Cradle, and you click on it to pay for {2} {G} {G}, it will pay for all of it... maybe make that a checkbox in menu options?)

I wrote:-I found Ashnod's Transmorgant code in my version, I remember the card working nicely, but I don't think I got around to posting it. Should I post the code, or have I already?
I've just made a bunch of changes/fixes to the latest version actually, maybe the best way to do this is to wait a day or two and I will submit you the very latest source I have. Then you could merge your manapool changes (during which I won't make any changes - a good thing really, I could use a bit of a break :) ). And at the same time, you could maybe merge whatever cards you've coded (like Ashnod's Transmorgant). So this weekend, I will fix a few extra bugs that were posted on this latest version, then I'll send you the latest stuff I've got (either tonight or on Sunday). Does that sound good to you?
Sure, I'm afraid the Transmorgant is the only new card though (so far :P). When I get your code I'll do a diff of cards.txt's to verify that, and add in mana abilities in there for the hard-coded cards while I'm at it.

I wrote:-Finally, I am now officially over all eclipse problems and on top of schoolwork, and have resumed working on my to-code list. Any suggestions for further actions? Perhaps changing the manaCost code to check lands for basic land types(which should be a quick fix, but would probably interfere to some degree with merging my code), or trying to set up an InputStack/multi-targeting system? Any suggestions welcome :).
I'm not sure what you mean about the manaCost code checking lands for basic land types, but that multi-targeting system sure sounds good :)
See my Hardcoding Basic Land types idea, which I'll probably put in during the merge. On behalf of the multi-targeting system, I just had the idea that InputControl could have an invisible Stack of inputs, which would be checked in Input.stop() before the SpellAbility stack. That way, a card would have Input arrays for beforePayMana, afterPayMana, and afterResolve, which would be added on the inputStack at appropriate.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby DennisBergkamp » 03 Oct 2009, 18:15

That seems to be a definite yes :). Anyways, not to sound too <insert derogatory term for self-promotion here>, but my pool Is quite an improvement, supporting resonable undo(I think it untaps souce of ability if ability was tap: add <one mana>, and restores mana to pool otherwise), smart split-cost choosing (e.g. won't offer its red mana when you're paying for {GU} {GU}), and automatic payment (So when the pool has a bunch of {G} from Gea's Cradle, and you click on it to pay for {2} {G} {G}, it will pay for all of it... maybe make that a checkbox in menu options?)
Those do sound like awesome improvements :)
I'm sorry I wasn't able to add your changes in successfully. But having said that, I really did spend a lot of time trying... I'm still not sure what I did wrong exactly.
Anyway, I guess it's easy to make mistakes in a merge like that, especially since it was quite a big update, involving lots of changes in a lot of different files.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby zerker2000 » 03 Oct 2009, 18:30

Any particular examples of what went wrong?
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby DennisBergkamp » 03 Oct 2009, 20:41

There were a few things, but I think the main issue I kept running into was that when I finally got rid of all the compile errors, forge wouldn't start anymore. It didn't give any error messages either, which is the strange thing. Maybe some infinite loop?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby zerker2000 » 03 Oct 2009, 21:00

Tried debugging? If it's an infinite loop, make sure mana pool uses extrinsic keywords and shouldManaAbility uses c.getIntrinsicKeyword, I do remember some infinite loop problems having popped up somewhere around that code. Also, how many / what bugs (ones unrelated to manapool issues) do you have left to fix? A recent bug report mentioned targeting problems with Dragon Blood, I think an &&canTarget(ability, c) needs to be added in the AI targeting system, and to this post's CardListFilter as well.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby DennisBergkamp » 03 Oct 2009, 23:59

Ah, yes I'm pretty sure I tried debugging. I can't remember what happened exactly, but whatever it was, it didn't help much :)

Currently I'm finishing:

- some of the "This card can't be countered" cards.
- making a separate imageName for all of the tokens (I'm done with all the token generators in CardFactory, so basically I'm done with most of it - 90% probably)
- I'll also fix Dragon Blood + Sun Quan, Lord of Wu.

- some more problems with the imageName stuff (big pic doesn't show up on the right panel).
- test AEther Web
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby zerker2000 » 04 Oct 2009, 00:23

DennisBergkamp wrote:Ah, yes I'm pretty sure I tried debugging. I can't remember what happened exactly, but whatever it was, it didn't help much :)
Erm, at least you could find out when the problem happened... if the bug is what I experienced, it would be an infinite loop in CardFactory.shouldManaAbility, with the first card with a mana ability having it copied into its keyword ArrayList an infinite amount of times. I think this is aused by the hack used to keep AI backwards compatibility, and was fixed by having shouldManaAbility check intrinsic keywords instead of all of them. If that's not the problem, it should be easy to breakpoint vital new methods to see where the program isn't getting. Anyways, I'm planning on removing basic mana abilities as keywords altogether, and somehow teaching the AI to use them.
Currently I'm finishing:

- some of the "This card can't be countered" cards.
- making a separate imageName for all of the tokens (I'm done with all the token generators in CardFactory, so basically I'm done with most of it - 90% probably)
- I'll also fix Dragon Blood + Sun Quan, Lord of Wu.

- some more problems with the imageName stuff (big pic doesn't show up on the right panel).
- test AEther Web
Is this topic's code going to make it in? :oops: Or should I add it myself when I get the code?
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby DennisBergkamp » 04 Oct 2009, 01:37

Yikes, yes this is exactly what's happening (I debugged and put a breakpoint in shouldManaAbility - it's stuck on Tranquil Thicket).
But unfortunately, this is obviously on a very old version (a July 25th backup), so either way, merging your stuff into my new version will still be quite a big job. I've made a lot of updates all over the place, fortunately I don't think I changed much in the mana classes though.

I've already put in your Modular code (not tested yet though, but it should work), I will also include a small changelog of all the changes since 10-02. I'm almost ready with everything - some bugs will take much longer to fix, I'll save those for some other time. Anyway, I'll send you a pm with the source sometime this evening.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby DennisBergkamp » 04 Oct 2009, 02:04

Actually, I might as well just post it here.
Feel free to download this everyone... if you know how to compile, this is basically the 10-02 version with some extra cards/fixes/features.
(A lot of things haven't been fixed yet though).

I've added your Energizer card as well as the Modular keyword (+ cards), Zerker.

=============================================================================================================================
- Dosan's Oldest Chant shouldn't have cycling anymore.
- Fixed Think Twice (has Flashback now)
- Fixed a bunch of Auras (AI shouldn't try to cast them on untargetable creatures now).
- Fixed a lot of small errors in cards.txt and CardFactory.
- Fixed Impulse when cast on an empty (or near empty) library.
- Fixed Secluded Steppe/Forgotten Cave.
- Added keyword "This creature can block creatures with shadow as though they didn't have shadow."
- Added Chris' fix on the properties files (how to text).
- Added Zerker's Modular keyword.
- Fixed some bugs in the combat code with shadow:
1. creatures with flying/landwalk/etc. and shadow won't be able to be blocked merely by a creature with shadow.
2. creatures with "This creature can block creatures with shadow as though they didn't have shadow." and shadow won't be able to block anything now.
- Fixed Sun Quan, Lord of Wu.
- Fixed Dragon Blood.
- Added a separate ImageName for tokens, and updated all token generators to provide tokens with correct names.

- Added a few extra cards.
=============================================================================================================================
Attachments
Source1003.rar
(517.86 KiB) Downloaded 240 times
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby zerker2000 » 04 Oct 2009, 07:10

Eclipse seems to not like your code: I extract it, base a new project off of it, and get this when I try to run it:
Code: Select all
java.io.FileNotFoundException: forge.properties (No such file or directory)
   at java.io.FileInputStream.open(Native Method)
   at java.io.FileInputStream.<init>(FileInputStream.java:106)
   at treeProperties.TreeProperties.<init>(TreeProperties.java:158)
   at treeProperties.TreeProperties.<init>(TreeProperties.java:132)
   at forge.properties.ForgeProps.<clinit>(ForgeProps.java:28)
   at Gui_NewGame.<clinit>(Gui_NewGame.java:79)
Exception in thread "main" java.lang.ExceptionInInitializerError
   at Gui_NewGame.<clinit>(Gui_NewGame.java:79)
Caused by: java.lang.NullPointerException
   at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
   at java.util.regex.Matcher.reset(Matcher.java:291)
   at java.util.regex.Matcher.<init>(Matcher.java:211)
   at java.util.regex.Pattern.matcher(Pattern.java:888)
   at java.util.Formatter.parse(Formatter.java:2457)
   at java.util.Formatter.format(Formatter.java:2413)
   at java.io.PrintWriter.format(PrintWriter.java:861)
   at java.io.PrintWriter.printf(PrintWriter.java:760)
   at forge.error.ErrorViewer.printError(ErrorViewer.java:129)
   at forge.error.ErrorViewer.showError(ErrorViewer.java:66)
   at forge.error.ErrorViewer.showError(ErrorViewer.java:47)
   at forge.properties.ForgeProps.<clinit>(ForgeProps.java:31)
   ... 1 more
Could not find the main class: Gui_NewGame.  Program will exit.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Modular

Postby silly freak » 04 Oct 2009, 09:20

obviously, the forge.properties file is missing. maybe your eclipse uses the wrong working directory. look into the launch configuration (in the "arguments" tab) and make sure that the working directory is the one where your forge.properties is located
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 104 guests


Who is online

In total there are 104 users online :: 0 registered, 0 hidden and 104 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 104 guests

Login Form