Page 1 of 1
		
			
				Trigger handling for AI
				
Posted: 
30 Jul 2016, 12:50by excessum
				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.
			 
			
		
			
				Re: Trigger handling for AI
				
Posted: 
30 Jul 2016, 13:11by friarsol
				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.
			 
			
		
			
				Re: Trigger handling for AI
				
Posted: 
31 Jul 2016, 02:58by excessum
				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.
			 
			
		
			
				Re: Trigger handling for AI
				
Posted: 
31 Jul 2016, 11:59by friarsol
				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.