It is currently 20 Apr 2024, 06:08
   
Text Size

Trigger handling for AI

Post MTG Forge Related Programming Questions Here

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

Trigger handling for AI

Postby excessum » 30 Jul 2016, 12:50

What is the exact meaning of "isMandatory" in the various trigger-related methods like doTrigger()? I thought that they meant forced triggers like Necrogen Scudder or Triskaidekaphobia but TriggerHandler.runSingleTrigger() defines all triggers with no cost as mandatory. As an aside, do all non-forced triggers mean that SpellAbility.isOptionalTrigger() returns true?

Both PlayerControllerAi.doTrigger() and confirmTrigger() make calls to AiController.doTrigger() with possibly different arguments and the latter seems to take precedence.
excessum
 
Posts: 177
Joined: 21 Oct 2013, 02:30
Has thanked: 0 time
Been thanked: 19 times

Re: Trigger handling for AI

Postby friarsol » 30 Jul 2016, 13:11

I haven't poked in this part of the code in a while, but here's the general idea.

To be put on the stack they are set as mandatory, since all triggers are added to the stack if able, and targets are required.

During resolution, they should be checking if they are optional ('may') or have a cost, and then running that through for confirmation.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Trigger handling for AI

Postby excessum » 31 Jul 2016, 02:58

Is SpellAbility.isOptionalTrigger() the same as checking "sa.isTrigger && !mandatory"? I was trying to think of a way to consolidate canPlayAi(), chkAIDrawback() and doTriggerAINoCostWithSubs() since they only differ in how "mandatory" they are.
excessum
 
Posts: 177
Joined: 21 Oct 2013, 02:30
Has thanked: 0 time
Been thanked: 19 times

Re: Trigger handling for AI

Postby friarsol » 31 Jul 2016, 11:59

excessum wrote:Is SpellAbility.isOptionalTrigger() the same as checking "sa.isTrigger && !mandatory"? I was trying to think of a way to consolidate canPlayAi(), chkAIDrawback() and doTriggerAINoCostWithSubs() since they only differ in how "mandatory" they are.
Looks like the only thing that sets optionalTrigger is this block in TriggerHandler.runSingleTrigger -

Code: Select all
        if (triggerParams.containsKey("OptionalDecider")) {
            sa.setOptionalTrigger(true);
            decider = AbilityUtils.getDefinedPlayers(host, triggerParams.get("OptionalDecider"), sa).get(0);
        }
        else if (sa instanceof AbilitySub || !sa.hasParam("Cost") || sa.getParam("Cost").equals("0")) {
            mand = true;
        }
        else { // triggers with a cost can't be mandatory
            sa.setOptionalTrigger(true);
            decider = sa.getActivatingPlayer();
        }
So yea, if it has a Cost, or it is explicitly Optional.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 93 guests


Who is online

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

Login Form