mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Merge branch 'master' of git.cardforge.org:core-developers/forge into custom-pool-options
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -231,3 +231,6 @@ forge-gui/tools/oracleScript.log
|
||||
/release.properties
|
||||
/target
|
||||
/test-output
|
||||
.settings
|
||||
.classpath
|
||||
.project
|
||||
12
.project
12
.project
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>forge</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,7 +0,0 @@
|
||||
add_header=true
|
||||
add_todo=false
|
||||
eclipse.preferences.version=1
|
||||
header_text=/*\n * Forge\: Play Magic\: the Gathering.\n * Copyright (C) 2011 Forge Team\n *\n * This program is free software\: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http\://www.gnu.org/licenses/>.\n */
|
||||
project_specific_settings=true
|
||||
replacements=<?xml version\="1.0" standalone\="yes"?>\n\n<replacements>\n<replacement key\="get" scope\="1" mode\="0">Gets the</replacement>\n<replacement key\="set" scope\="1" mode\="0">Sets the</replacement>\n<replacement key\="add" scope\="1" mode\="0">Adds the</replacement>\n<replacement key\="edit" scope\="1" mode\="0">Edits the</replacement>\n<replacement key\="remove" scope\="1" mode\="0">Removes the</replacement>\n<replacement key\="init" scope\="1" mode\="0">Inits the</replacement>\n<replacement key\="parse" scope\="1" mode\="0">Parses the</replacement>\n<replacement key\="create" scope\="1" mode\="0">Creates the</replacement>\n<replacement key\="build" scope\="1" mode\="0">Builds the</replacement>\n<replacement key\="is" scope\="1" mode\="0">Checks if is</replacement>\n<replacement key\="print" scope\="1" mode\="0">Prints the</replacement>\n<replacement key\="has" scope\="1" mode\="0">Checks for</replacement>\n</replacements>\n\n
|
||||
visibility_private=false
|
||||
@@ -1,2 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -1,284 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
|
||||
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_method=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_header=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_html=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_source_code=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.comment.line_length=80
|
||||
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
|
||||
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
|
||||
org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false
|
||||
org.eclipse.jdt.core.formatter.compact_else_if=true
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation=2
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
|
||||
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
|
||||
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
|
||||
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_empty_lines=false
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
|
||||
org.eclipse.jdt.core.formatter.indentation.size=4
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
|
||||
org.eclipse.jdt.core.formatter.join_wrapped_lines=true
|
||||
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.lineSplit=120
|
||||
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
|
||||
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
|
||||
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
|
||||
org.eclipse.jdt.core.formatter.tabulation.char=space
|
||||
org.eclipse.jdt.core.formatter.tabulation.size=4
|
||||
org.eclipse.jdt.core.formatter.use_on_off_tags=false
|
||||
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +0,0 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
230
README.md
Normal file
230
README.md
Normal file
@@ -0,0 +1,230 @@
|
||||
# Forge
|
||||
|
||||
Gitlab repo is found [here](https://git.cardforge.org/core-developers/forge).
|
||||
|
||||
Dev instructions here: [Getting Started](https://www.slightlymagic.net/wiki/Forge:How_to_Get_Started_Developing_Forge) (Somewhat outdated)
|
||||
|
||||
Discord channel [here](https://discordapp.com/channels/267367946135928833/267742313390931968)
|
||||
|
||||
# Requirements / Tools
|
||||
|
||||
- Java IDE such as IntelliJ or Eclipse
|
||||
- Java JDK 8 or later
|
||||
- Git
|
||||
- Git client (optional)
|
||||
- Maven
|
||||
- Gitlab account
|
||||
- Libgdx (optional: familiarity with this library is helpful for mobile platform development)
|
||||
- Android SDK (optional: for Android releases)
|
||||
- RoboVM (optional: for iOS releases) (TBD: Current status of support by libgdx)
|
||||
|
||||
# Project Quick Setup
|
||||
|
||||
- Log in to gitlab with your user account and fork the project.
|
||||
|
||||
- Clone your forked project to your local machine
|
||||
|
||||
- Go to the project location on your machine. Run Maven to download all dependencies and build a snapshot. Example for Windows & Linux: `mvn -U -B clean -P windows-linux install`
|
||||
|
||||
# Eclipse
|
||||
|
||||
Eclipse includes Maven integration so a separate install is not necessary. For other IDEs, your mileage may vary.
|
||||
|
||||
## Project Setup
|
||||
|
||||
- Follow the instructions for cloning from Gitlab. You'll need a Gitlab account setup and an SSH key defined.
|
||||
|
||||
If you are on a Windows machine you can use Putty with TortoiseGit for SSH keys. Run puttygen.exe to generate the key -- save the private key and export
|
||||
the OpenSSH public key. If you just leave the dialog open, you can copy and paste the key from it to your Gitlab profile under
|
||||
"SSH keys". Run pageant.exe and add the private key generated earlier. TortoiseGit will use this for accessing Gitlab.
|
||||
|
||||
- Fork the Forge git repo to your Gitlab account.
|
||||
|
||||
- Clone your forked repo to your local machine.
|
||||
|
||||
- Make sure the Java SDK is installed -- not just the JRE. Java 8 or newer required. If you execute `java -version` at the shell or command prompt, it should report version 1.8 or later.
|
||||
|
||||
- Install Eclipse 2018-12 or later for Java. Launch it.
|
||||
|
||||
- Create a workspace. Go to the workbench. Right-click inside of Package Explorer > Import... > Maven > Existing Maven Projects > Navigate to root path of the local forge repo and
|
||||
ensure everything is checked > Finish.
|
||||
|
||||
- Let Eclipse run through building the project. You may be prompted for resolving any missing Maven plugins -- accept the ones offered. You may see errors appear in the "Problems" tab. These should
|
||||
be automatically resolved as plug-ins are installed and Eclipse continues the build process. If this is the first time for some plug-in installs, Eclipse may prompt you to restart. Do so. Be patient
|
||||
for this first time through.
|
||||
|
||||
- Once everything builds, all errors should disappear. You can now advance to Project launch.
|
||||
|
||||
## Project Launch
|
||||
|
||||
### Desktop
|
||||
|
||||
This is the standard configuration used for releasing to Windows / Linux / MacOS.
|
||||
|
||||
- Right-click on forge-gui-desktop > Run As... > Java Application > "Main - forge.view" > Ok
|
||||
|
||||
- The familiar Forge splash screen, etc. should appear. Enjoy!
|
||||
|
||||
### Mobile (Desktop dev)
|
||||
|
||||
This is the configuration used for doing mobile development using the Windows / Linux / MacOS front-end. Knowledge of libgdx is helpful here.
|
||||
|
||||
- Right-click on forge-gui-mobile-dev > Run As... > Java Application > "Main - forge.app" > Ok.
|
||||
|
||||
- A view similar to a mobile phone should appear. Enjoy!
|
||||
|
||||
## Eclipse / Android SDK Integration
|
||||
|
||||
Google no longer supports Android SDK releases for Eclipse. That said, it is still possible to build and debug Android platforms.
|
||||
|
||||
### Android SDK
|
||||
|
||||
Reference SO for obtaining a specific release: https://stackoverflow.com/questions/27043522/where-can-i-download-an-older-version-of-the-android-sdk
|
||||
|
||||
#### Windows
|
||||
|
||||
Download the following archived version of the Android SDK: http://dl-ssl.google.com/android/repository/tools_r25.2.3-windows.zip. Install it somewhere on your machine. This is referenced
|
||||
in the following instructions as your 'Android SDK Install' path.
|
||||
|
||||
#### Linux / Mac OSX
|
||||
|
||||
TBD
|
||||
|
||||
### Android Plugin for Eclipse
|
||||
|
||||
Google's last plugin release does not work completely with target's running Android 7.0 or later. Download the ADT-24.2.0-20160729.zip plugin
|
||||
from: https://github.com/khaledev/ADT/releases
|
||||
|
||||
In Eclipse go to: Help > Install New Software... > Add > Name: ADT Update, Click on the "Archive:" button and navigate to the downloaded ADT-24.2.0-20160729.zip file > Add. Install all "Developer Tools". Eclipse
|
||||
should restart and prompt you to run the SDK Manager. Launch it and continue to the next steps below.
|
||||
|
||||
### Android Platform
|
||||
|
||||
In Eclipse, if the SDK Manager is not already running, go to Window > Android SDK Manager. Install the following options / versions:
|
||||
|
||||
- Android SDK Build-tools 26.0.1
|
||||
- Android 7.1.1 (API 25) SDK Platform
|
||||
- Google USB Driver 11
|
||||
|
||||
Note that this will populate additional tools in the Android SDK install path extracted above.
|
||||
|
||||
### Proguard update
|
||||
|
||||
The Proguard included with the Android SDK Build-tools is outdated and does not work with Java 1.8. Download Proguard 6.0.3 from https://sourceforge.net/projects/proguard/files/proguard/6.0/.
|
||||
|
||||
- Go to the Android SDK install path. Rename the tools/proguard/ path to tools/proguard4.7/.
|
||||
|
||||
- Extract Proguard 6.0.3 to the Android SDK install path under tools/. You will need to rename the dir proguard6.0.3/ to proguard/.
|
||||
|
||||
### Android Build
|
||||
|
||||
The Eclipse plug-ins do NOT support building things for Android. They do however allow you to use the debugger so you can still set breakpoints and trace
|
||||
things out. The steps below show how to generate a debug Android build.
|
||||
|
||||
1) Create a Maven build for the forge top-level project. Right-click on the forge project. Run as.. > Maven build...
|
||||
- On the Main tab, set Goals: clean install
|
||||
|
||||
2) Run forge Maven build. If everything built, you should see "BUILD SUCCESS" in the Console View.
|
||||
|
||||
3) Right-click on the forge-gui-android project. Run as.. > Maven build...
|
||||
|
||||
- On the Main tab, set Goals: install, Profiles: android-debug
|
||||
- On the Environment tab, you may need to define the variable ANDROID_HOME with the value containing the path to your Android SDK installation. For example, Variable: ANDROID_HOME, Value: Your Android SDK install path here.
|
||||
|
||||
4) Run the forge-gui-android Maven build. This may take a few minutes. If everything worked, you should see "BUILD SUCCESS" in the Console View.
|
||||
|
||||
Assuming you got this far, you should have an Android forge-android-[version].apk in the forge-gui-android/target path.
|
||||
|
||||
### Android Deploy
|
||||
|
||||
You'll need to have the Android SDK install path platform-tools/ path in your command search path to easily deploy builds.
|
||||
|
||||
- Open a command prompt. Navigate to the forge-gui-android/target/ path.
|
||||
|
||||
- Connect your Android device to your dev machine.
|
||||
|
||||
- Ensure the device is visible using `adb devices`
|
||||
|
||||
- Remove the old Forge install if present: `adb uninstall forge.app`
|
||||
|
||||
- Install the new apk: `adb install forge-android-[version].apk`
|
||||
|
||||
### Android Debugging
|
||||
|
||||
Assuming the apk is installed, launch it from the device.
|
||||
|
||||
In Eclipse, launch the DDMS. Window > Perspective > Open Perspective > Other... > DDMS. You should see the forge app in the list. Highlight the app, click on the green debug button and a
|
||||
green debug button should appear next to the app's name. You can now set breakpoints and step through the source code.
|
||||
|
||||
## Windows / Linux SNAPSHOT build
|
||||
|
||||
SNAPSHOT builds can be built via the Maven integration in Eclipse.
|
||||
|
||||
1) Create a Maven build for the forge top-level project. Right-click on the forge project. Run as.. > Maven build...
|
||||
- On the Main tab, set Goals: clean install, set Profiles: windows-linux
|
||||
|
||||
2) Run forge Maven build. If everything built, you should see "BUILD SUCCESS" in the Console View.
|
||||
|
||||
The resulting snapshot will be found at: forge-gui-desktop/target/forge-gui-desktop-1.6.22-SNAPSHOT
|
||||
|
||||
# IntelliJ
|
||||
|
||||
TBD
|
||||
|
||||
# Card Scripting
|
||||
|
||||
Visit [this page](https://www.slightlymagic.net/wiki/Forge_API) for information on scripting.
|
||||
|
||||
Card scripting resources are found in the forge-gui/res/ path.
|
||||
|
||||
# General Notes
|
||||
|
||||
## Project Hierarchy
|
||||
|
||||
Forge is divided into 4 primary projects with additional projects that target specific platform releases. The primary projects are:
|
||||
|
||||
- forge-ai
|
||||
- forge-core
|
||||
- forge-game
|
||||
- forge-gui
|
||||
|
||||
The platform-specific projects are:
|
||||
|
||||
- forge-gui-android
|
||||
- forge-gui-desktop
|
||||
- forge-gui-ios
|
||||
- forge-gui-mobile
|
||||
- forge-gui-mobile-dev
|
||||
|
||||
### forge-ai
|
||||
|
||||
### forge-core
|
||||
|
||||
### forge-game
|
||||
|
||||
### forge-gui
|
||||
|
||||
The forge-gui project includes the scripting resource definitions in the res/ path.
|
||||
|
||||
### forge-gui-android
|
||||
|
||||
Libgdx-based backend targeting Android. Requires Android SDK and relies on forge-gui-mobile for GUI logic.
|
||||
|
||||
### forge-gui-desktop
|
||||
|
||||
Java Swing based GUI targeting desktop machines.
|
||||
|
||||
Screen layout and game logic revolving around the GUI is found here. For example, the overlay arrows (when enabled) that indicate attackers and blockers, or the targets of the stack are defined and drawn by this.
|
||||
|
||||
### forge-gui-ios
|
||||
|
||||
Libgdx-based backend targeting iOS. Relies on forge-gui-mobile for GUI logic.
|
||||
|
||||
### forge-gui-mobile
|
||||
|
||||
Mobile GUI game logic utilizing [libgdx](https://libgdx.badlogicgames.com/) library. Screen layout and game logic revolving around the GUI for the mobile platforms is found here.
|
||||
|
||||
### forge-gui-mobile-dev
|
||||
|
||||
Libgdx backend for desktop development for mobile backends. Utilizes LWJGL. Relies on forge-gui-mobile for GUI logic.
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/forge-core"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>forge-ai</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>forge-game</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,3 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=ISO-8859-1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -1,5 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -1,4 +0,0 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>forge</artifactId>
|
||||
<groupId>forge</groupId>
|
||||
<version>1.6.18-SNAPSHOT</version>
|
||||
<version>1.6.22-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>forge-ai</artifactId>
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.common.base.Predicates;
|
||||
import forge.card.CardStateName;
|
||||
import forge.game.CardTraitBase;
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.GlobalRuleChange;
|
||||
import forge.game.card.*;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
@@ -771,6 +772,16 @@ public class AiBlockController {
|
||||
blockers = getPossibleBlockers(combat, attacker, blockersLeft, false);
|
||||
blockers.removeAll(combat.getBlockers(attacker));
|
||||
|
||||
// Don't add any blockers that won't kill the attacker because the damage would be prevented by a static effect
|
||||
if (!ai.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) {
|
||||
blockers = CardLists.filter(blockers, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card blocker) {
|
||||
return !ComputerUtilCombat.isCombatDamagePrevented(blocker, attacker, blocker.getNetCombatDamage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Try to use safe blockers first
|
||||
if (blockers.size() > 0) {
|
||||
safeBlockers = getSafeBlockers(combat, attacker, blockers);
|
||||
|
||||
@@ -40,16 +40,39 @@ import java.util.Set;
|
||||
*/
|
||||
public class AiCardMemory {
|
||||
|
||||
/**
|
||||
* Defines the memory set in which the card is remembered
|
||||
* (which, in its turn, defines how the AI utilizes the information
|
||||
* about remembered cards).
|
||||
*/
|
||||
public enum MemorySet {
|
||||
MANDATORY_ATTACKERS, // These creatures must attack this turn
|
||||
TRICK_ATTACKERS, // These creatures will attack to try to provoke the opponent to block them into a combat trick
|
||||
HELD_MANA_SOURCES_FOR_MAIN2, // These mana sources will not be used before Main 2
|
||||
HELD_MANA_SOURCES_FOR_DECLBLK, // These mana sources will not be used before Combat - Declare Blockers
|
||||
HELD_MANA_SOURCES_FOR_ENEMY_DECLBLK, // These mana sources will not be used before the opponent's Combat - Declare Blockers
|
||||
HELD_MANA_SOURCES_FOR_NEXT_SPELL, // These mana sources will not be used until the next time the AI chooses a spell to cast
|
||||
ATTACHED_THIS_TURN, // These equipments were attached to something already this turn
|
||||
ANIMATED_THIS_TURN, // These cards had their AF Animate effect activated this turn
|
||||
BOUNCED_THIS_TURN, // These cards were bounced this turn
|
||||
ACTIVATED_THIS_TURN, // These cards had their ability activated this turn
|
||||
CHOSEN_FOG_EFFECT, // These cards are marked as the Fog-like effect the AI is planning to cast this turn
|
||||
MARKED_TO_AVOID_REENTRY // These cards may cause a stack smash when processed recursively, and are thus marked to avoid a crash
|
||||
//REVEALED_CARDS // stub, not linked to AI code yet
|
||||
}
|
||||
|
||||
private final Set<Card> memMandatoryAttackers;
|
||||
private final Set<Card> memTrickAttackers;
|
||||
private final Set<Card> memHeldManaSources;
|
||||
private final Set<Card> memHeldManaSourcesForCombat;
|
||||
private final Set<Card> memHeldManaSourcesForEnemyCombat;
|
||||
private final Set<Card> memHeldManaSourcesForNextSpell;
|
||||
private final Set<Card> memAttachedThisTurn;
|
||||
private final Set<Card> memAnimatedThisTurn;
|
||||
private final Set<Card> memBouncedThisTurn;
|
||||
private final Set<Card> memActivatedThisTurn;
|
||||
private final Set<Card> memChosenFogEffect;
|
||||
private final Set<Card> memMarkedToAvoidReentry;
|
||||
|
||||
public AiCardMemory() {
|
||||
this.memMandatoryAttackers = new HashSet<>();
|
||||
@@ -62,25 +85,8 @@ public class AiCardMemory {
|
||||
this.memActivatedThisTurn = new HashSet<>();
|
||||
this.memTrickAttackers = new HashSet<>();
|
||||
this.memChosenFogEffect = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the memory set in which the card is remembered
|
||||
* (which, in its turn, defines how the AI utilizes the information
|
||||
* about remembered cards).
|
||||
*/
|
||||
public enum MemorySet {
|
||||
MANDATORY_ATTACKERS,
|
||||
TRICK_ATTACKERS,
|
||||
HELD_MANA_SOURCES_FOR_MAIN2,
|
||||
HELD_MANA_SOURCES_FOR_DECLBLK,
|
||||
HELD_MANA_SOURCES_FOR_ENEMY_DECLBLK,
|
||||
ATTACHED_THIS_TURN,
|
||||
ANIMATED_THIS_TURN,
|
||||
BOUNCED_THIS_TURN,
|
||||
ACTIVATED_THIS_TURN,
|
||||
CHOSEN_FOG_EFFECT,
|
||||
//REVEALED_CARDS // stub, not linked to AI code yet
|
||||
this.memMarkedToAvoidReentry = new HashSet<>();
|
||||
this.memHeldManaSourcesForNextSpell = new HashSet<>();
|
||||
}
|
||||
|
||||
private Set<Card> getMemorySet(MemorySet set) {
|
||||
@@ -95,6 +101,8 @@ public class AiCardMemory {
|
||||
return memHeldManaSourcesForCombat;
|
||||
case HELD_MANA_SOURCES_FOR_ENEMY_DECLBLK:
|
||||
return memHeldManaSourcesForEnemyCombat;
|
||||
case HELD_MANA_SOURCES_FOR_NEXT_SPELL:
|
||||
return memHeldManaSourcesForNextSpell;
|
||||
case ATTACHED_THIS_TURN:
|
||||
return memAttachedThisTurn;
|
||||
case ANIMATED_THIS_TURN:
|
||||
@@ -105,6 +113,8 @@ public class AiCardMemory {
|
||||
return memActivatedThisTurn;
|
||||
case CHOSEN_FOG_EFFECT:
|
||||
return memChosenFogEffect;
|
||||
case MARKED_TO_AVOID_REENTRY:
|
||||
return memMarkedToAvoidReentry;
|
||||
//case REVEALED_CARDS:
|
||||
// return memRevealedCards;
|
||||
default:
|
||||
@@ -273,35 +283,66 @@ public class AiCardMemory {
|
||||
* Clears all memory sets stored in this card memory for the given player.
|
||||
*/
|
||||
public void clearAllRemembered() {
|
||||
clearMemorySet(MemorySet.MANDATORY_ATTACKERS);
|
||||
clearMemorySet(MemorySet.TRICK_ATTACKERS);
|
||||
clearMemorySet(MemorySet.HELD_MANA_SOURCES_FOR_MAIN2);
|
||||
clearMemorySet(MemorySet.HELD_MANA_SOURCES_FOR_DECLBLK);
|
||||
clearMemorySet(MemorySet.HELD_MANA_SOURCES_FOR_ENEMY_DECLBLK);
|
||||
clearMemorySet(MemorySet.ATTACHED_THIS_TURN);
|
||||
clearMemorySet(MemorySet.ANIMATED_THIS_TURN);
|
||||
clearMemorySet(MemorySet.BOUNCED_THIS_TURN);
|
||||
clearMemorySet(MemorySet.ACTIVATED_THIS_TURN);
|
||||
clearMemorySet(MemorySet.CHOSEN_FOG_EFFECT);
|
||||
for (MemorySet memSet : MemorySet.values()) {
|
||||
clearMemorySet(memSet);
|
||||
}
|
||||
}
|
||||
|
||||
// Static functions to simplify access to AI card memory of a given AI player.
|
||||
public static void rememberCard(Player ai, Card c, MemorySet set) {
|
||||
if (!ai.getController().isAI()) {
|
||||
return;
|
||||
}
|
||||
((PlayerControllerAi)ai.getController()).getAi().getCardMemory().rememberCard(c, set);
|
||||
}
|
||||
public static void rememberCard(AiController aic, Card c, MemorySet set) {
|
||||
aic.getCardMemory().rememberCard(c, set);
|
||||
}
|
||||
public static void forgetCard(Player ai, Card c, MemorySet set) {
|
||||
if (!ai.getController().isAI()) {
|
||||
return;
|
||||
}
|
||||
((PlayerControllerAi)ai.getController()).getAi().getCardMemory().forgetCard(c, set);
|
||||
}
|
||||
public static void forgetCard(AiController aic, Card c, MemorySet set) {
|
||||
aic.getCardMemory().forgetCard(c, set);
|
||||
}
|
||||
public static boolean isRememberedCard(Player ai, Card c, MemorySet set) {
|
||||
if (!ai.getController().isAI()) {
|
||||
return false;
|
||||
}
|
||||
return ((PlayerControllerAi)ai.getController()).getAi().getCardMemory().isRememberedCard(c, set);
|
||||
}
|
||||
public static boolean isRememberedCard(AiController aic, Card c, MemorySet set) {
|
||||
return aic.getCardMemory().isRememberedCard(c, set);
|
||||
}
|
||||
public static boolean isRememberedCardByName(Player ai, String name, MemorySet set) {
|
||||
if (!ai.getController().isAI()) {
|
||||
return false;
|
||||
}
|
||||
return ((PlayerControllerAi)ai.getController()).getAi().getCardMemory().isRememberedCardByName(name, set);
|
||||
}
|
||||
public static boolean isRememberedCardByName(AiController aic, String name, MemorySet set) {
|
||||
return aic.getCardMemory().isRememberedCardByName(name, set);
|
||||
}
|
||||
public static void clearMemorySet(Player ai, MemorySet set) {
|
||||
if (!ai.getController().isAI()) {
|
||||
return;
|
||||
}
|
||||
((PlayerControllerAi)ai.getController()).getAi().getCardMemory().clearMemorySet(set);
|
||||
}
|
||||
public static void clearMemorySet(AiController aic, MemorySet set) {
|
||||
if (!isMemorySetEmpty(aic, set)) {
|
||||
aic.getCardMemory().clearMemorySet(set);
|
||||
}
|
||||
}
|
||||
public static boolean isMemorySetEmpty(Player ai, MemorySet set) {
|
||||
if (!ai.getController().isAI()) {
|
||||
return false;
|
||||
}
|
||||
return ((PlayerControllerAi)ai.getController()).getAi().getCardMemory().isMemorySetEmpty(set);
|
||||
}
|
||||
public static boolean isMemorySetEmpty(AiController aic, MemorySet set) {
|
||||
return aic.getCardMemory().isMemorySetEmpty(set);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.replacement.ReplaceMoved;
|
||||
import forge.game.replacement.ReplacementEffect;
|
||||
import forge.game.spellability.*;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.trigger.WrappedAbility;
|
||||
@@ -60,6 +61,8 @@ import forge.util.Aggregates;
|
||||
import forge.util.Expressions;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.collect.FCollectionView;
|
||||
import io.sentry.Sentry;
|
||||
import io.sentry.event.BreadcrumbBuilder;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.*;
|
||||
@@ -90,6 +93,9 @@ public class AiController {
|
||||
this.cheatShuffle = canCheatShuffle;
|
||||
}
|
||||
|
||||
public boolean usesSimulation() {
|
||||
return this.useSimulation;
|
||||
}
|
||||
public void setUseSimulation(boolean value) {
|
||||
this.useSimulation = value;
|
||||
}
|
||||
@@ -434,6 +440,38 @@ public class AiController {
|
||||
if (landList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CardCollection nonLandsInHand = CardLists.filter(player.getCardsIn(ZoneType.Hand), Predicates.not(CardPredicates.Presets.LANDS));
|
||||
|
||||
// Some considerations for Momir/MoJhoSto
|
||||
boolean hasMomir = !CardLists.filter(player.getCardsIn(ZoneType.Command),
|
||||
CardPredicates.nameEquals("Momir Vig, Simic Visionary Avatar")).isEmpty();
|
||||
if (hasMomir && nonLandsInHand.isEmpty()) {
|
||||
// Only do this if we have an all-basic land hand, which covers both stock Momir and MoJhoSto modes
|
||||
// and also a custom Vanguard setup with a customized basic land deck and Momir as the avatar.
|
||||
String landStrategy = getProperty(AiProps.MOMIR_BASIC_LAND_STRATEGY);
|
||||
if (landStrategy.equalsIgnoreCase("random")) {
|
||||
// Pick a completely random basic land
|
||||
return Aggregates.random(landList);
|
||||
} else if (landStrategy.toLowerCase().startsWith("preforder:")) {
|
||||
// Pick a basic land in order of preference, or play a random one if nothing is preferred
|
||||
String order = landStrategy.substring(10);
|
||||
for (char c : order.toCharArray()) {
|
||||
byte color = MagicColor.fromName(c);
|
||||
for (Card land : landList) {
|
||||
for (final SpellAbility m : ComputerUtilMana.getAIPlayableMana(land)) {
|
||||
AbilityManaPart mp = m.getManaPart();
|
||||
if (mp.canProduce(MagicColor.toShortString(color), m)) {
|
||||
return land;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Aggregates.random(landList);
|
||||
}
|
||||
// If nothing is done here, proceeds to the default land picking strategy
|
||||
}
|
||||
|
||||
//Skip reflected lands.
|
||||
CardCollection unreflectedLands = new CardCollection(landList);
|
||||
for (Card l : landList) {
|
||||
@@ -445,7 +483,6 @@ public class AiController {
|
||||
landList = unreflectedLands;
|
||||
}
|
||||
|
||||
CardCollection nonLandsInHand = CardLists.filter(player.getCardsIn(ZoneType.Hand), Predicates.not(CardPredicates.Presets.LANDS));
|
||||
|
||||
//try to skip lands that enter the battlefield tapped
|
||||
if (!nonLandsInHand.isEmpty()) {
|
||||
@@ -595,34 +632,61 @@ public class AiController {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void reserveManaSources(SpellAbility sa) {
|
||||
reserveManaSources(sa, PhaseType.MAIN2, false);
|
||||
public boolean reserveManaSources(SpellAbility sa) {
|
||||
return reserveManaSources(sa, PhaseType.MAIN2, false, false, null);
|
||||
}
|
||||
|
||||
public void reserveManaSources(SpellAbility sa, PhaseType phaseType, boolean enemy) {
|
||||
public boolean reserveManaSourcesForNextSpell(SpellAbility sa, SpellAbility exceptForSa) {
|
||||
return reserveManaSources(sa, null, false, true, exceptForSa);
|
||||
}
|
||||
|
||||
public boolean reserveManaSources(SpellAbility sa, PhaseType phaseType, boolean enemy) {
|
||||
return reserveManaSources(sa, phaseType, enemy, true, null);
|
||||
}
|
||||
|
||||
public boolean reserveManaSources(SpellAbility sa, PhaseType phaseType, boolean enemy, boolean forNextSpell, SpellAbility exceptForThisSa) {
|
||||
ManaCostBeingPaid cost = ComputerUtilMana.calculateManaCost(sa, true, 0);
|
||||
CardCollection manaSources = ComputerUtilMana.getManaSourcesToPayCost(cost, sa, player);
|
||||
|
||||
// used for chained spells where two spells need to be cast in succession
|
||||
if (exceptForThisSa != null) {
|
||||
manaSources.removeAll(ComputerUtilMana.getManaSourcesToPayCost(ComputerUtilMana.calculateManaCost(exceptForThisSa, true, 0), exceptForThisSa, player));
|
||||
}
|
||||
|
||||
if (manaSources.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AiCardMemory.MemorySet memSet;
|
||||
|
||||
switch (phaseType) {
|
||||
case MAIN2:
|
||||
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2;
|
||||
break;
|
||||
case COMBAT_DECLARE_BLOCKERS:
|
||||
memSet = enemy ? AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_ENEMY_DECLBLK
|
||||
: AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_DECLBLK;
|
||||
break;
|
||||
default:
|
||||
System.out.println("Warning: unsupported mana reservation phase specified for reserveManaSources: "
|
||||
+ phaseType.name() + ", reserving until Main 2 instead. Consider adding support for the phase if needed.");
|
||||
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2;
|
||||
break;
|
||||
if (phaseType == null && forNextSpell) {
|
||||
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_NEXT_SPELL;
|
||||
} else {
|
||||
switch (phaseType) {
|
||||
case MAIN2:
|
||||
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2;
|
||||
break;
|
||||
case COMBAT_DECLARE_BLOCKERS:
|
||||
memSet = enemy ? AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_ENEMY_DECLBLK
|
||||
: AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_DECLBLK;
|
||||
break;
|
||||
default:
|
||||
System.out.println("Warning: unsupported mana reservation phase specified for reserveManaSources: "
|
||||
+ phaseType.name() + ", reserving until Main 2 instead. Consider adding support for the phase if needed.");
|
||||
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (Card c : manaSources) {
|
||||
AiCardMemory.rememberCard(player, c, memSet);
|
||||
// This is a simplification, since one mana source can produce more than one mana,
|
||||
// but should work in most circumstances to ensure safety in whatever the AI is using this for.
|
||||
if (manaSources.size() >= cost.getConvertedManaCost()) {
|
||||
for (Card c : manaSources) {
|
||||
AiCardMemory.rememberCard(player, c, memSet);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is for playing spells regularly (no Cascade/Ripple etc.)
|
||||
@@ -631,11 +695,27 @@ public class AiController {
|
||||
return AiPlayDecision.CantPlaySa;
|
||||
}
|
||||
|
||||
AiPlayDecision op = canPlaySa(sa);
|
||||
if (op != AiPlayDecision.WillPlay) {
|
||||
return op;
|
||||
boolean xCost = sa.getPayCosts().hasXInAnyCostPart();
|
||||
if (!xCost && !ComputerUtilCost.canPayCost(sa, player)) {
|
||||
// for most costs, it's OK to check if they can be paid early in order to avoid running a heavy API check
|
||||
// when the AI won't even be able to play the spell in the first place (even if it could afford it)
|
||||
return AiPlayDecision.CantAfford;
|
||||
}
|
||||
return ComputerUtilCost.canPayCost(sa, player) ? AiPlayDecision.WillPlay : AiPlayDecision.CantAfford;
|
||||
|
||||
AiPlayDecision canPlay = canPlaySa(sa); // this is the "heaviest" check, which also sets up targets, defines X, etc.
|
||||
if (canPlay != AiPlayDecision.WillPlay) {
|
||||
return canPlay;
|
||||
}
|
||||
|
||||
if (xCost && !ComputerUtilCost.canPayCost(sa, player)) {
|
||||
// for dependent costs with X, e.g. Repeal, which require a valid target to be specified before a decision can be made
|
||||
// on whether the cost can be paid, this can only be checked late after canPlaySa has been run (or the AI will misplay)
|
||||
return AiPlayDecision.CantAfford;
|
||||
}
|
||||
|
||||
// if we got here, looks like we can play the final cost and we could properly set up and target the API and
|
||||
// are willing to play the SA
|
||||
return AiPlayDecision.WillPlay;
|
||||
}
|
||||
|
||||
public AiPlayDecision canPlaySa(SpellAbility sa) {
|
||||
@@ -646,8 +726,37 @@ public class AiController {
|
||||
if (sa instanceof WrappedAbility) {
|
||||
return canPlaySa(((WrappedAbility) sa).getWrappedAbility());
|
||||
}
|
||||
|
||||
// Trying to play a card that has Buyback without a Buyback cost, look for possible additional considerations
|
||||
if (getBooleanProperty(AiProps.TRY_TO_PRESERVE_BUYBACK_SPELLS)) {
|
||||
if (card.hasKeyword(Keyword.BUYBACK) && !sa.isBuyBackAbility() && !canPlaySpellWithoutBuyback(card, sa)) {
|
||||
return AiPlayDecision.NeedsToPlayCriteriaNotMet;
|
||||
}
|
||||
}
|
||||
|
||||
// When processing a new SA, clear the previously remembered cards that have been marked to avoid re-entry
|
||||
// which might potentially cause a stack overflow.
|
||||
AiCardMemory.clearMemorySet(this, AiCardMemory.MemorySet.MARKED_TO_AVOID_REENTRY);
|
||||
|
||||
if (sa.getApi() != null) {
|
||||
|
||||
String msg = "AiController:canPlaySa: AI checks for if can PlaySa";
|
||||
Sentry.getContext().recordBreadcrumb(
|
||||
new BreadcrumbBuilder().setMessage(msg)
|
||||
.withData("Api", sa.getApi().toString())
|
||||
.withData("Card", card.getName()).withData("SA", sa.toString()).build()
|
||||
);
|
||||
|
||||
// add Extra for debugging
|
||||
Sentry.getContext().addExtra("Card", card);
|
||||
Sentry.getContext().addExtra("SA", sa.toString());
|
||||
|
||||
boolean canPlay = SpellApiToAi.Converter.get(sa.getApi()).canPlayAIWithSubs(player, sa);
|
||||
|
||||
// remove added extra
|
||||
Sentry.getContext().removeExtra("Card");
|
||||
Sentry.getContext().removeExtra("SA");
|
||||
|
||||
if (!canPlay) {
|
||||
return AiPlayDecision.CantPlayAi;
|
||||
}
|
||||
@@ -702,7 +811,7 @@ public class AiController {
|
||||
// will need actual logic that determines if the enchantment is able
|
||||
// to disable the permanent or it's still functional and a duplicate is unneeded.
|
||||
boolean disabledByEnemy = false;
|
||||
for (Card card2 : card.getEnchantedBy(false)) {
|
||||
for (Card card2 : card.getEnchantedBy()) {
|
||||
if (card2.getOwner() != player) {
|
||||
disabledByEnemy = true;
|
||||
}
|
||||
@@ -719,10 +828,71 @@ public class AiController {
|
||||
if ("True".equals(card.getSVar("NonStackingEffect")) && isNonDisabledCardInPlay(card.getName())) {
|
||||
return AiPlayDecision.NeedsToPlayCriteriaNotMet;
|
||||
}
|
||||
|
||||
// add any other necessary logic to play a basic spell here
|
||||
return ComputerUtilCard.checkNeedsToPlayReqs(card, sa);
|
||||
}
|
||||
|
||||
private boolean canPlaySpellWithoutBuyback(Card card, SpellAbility sa) {
|
||||
boolean wasteBuybackAllowed = false;
|
||||
|
||||
// About to lose game : allow
|
||||
if (ComputerUtil.aiLifeInDanger(player, true, 0)) {
|
||||
wasteBuybackAllowed = true;
|
||||
}
|
||||
|
||||
int copies = CardLists.filter(player.getCardsIn(ZoneType.Hand), CardPredicates.nameEquals(card.getName())).size();
|
||||
// Have two copies : allow
|
||||
if (copies >= 2) {
|
||||
wasteBuybackAllowed = true;
|
||||
}
|
||||
|
||||
int neededMana = 0;
|
||||
boolean dangerousRecurringCost = false;
|
||||
|
||||
Cost costWithBuyback = sa.getPayCosts() != null ? sa.getPayCosts().copy() : Cost.Zero;
|
||||
for (OptionalCostValue opt : GameActionUtil.getOptionalCostValues(sa)) {
|
||||
if (opt.getType() == OptionalCost.Buyback) {
|
||||
costWithBuyback.add(opt.getCost());
|
||||
}
|
||||
}
|
||||
CostAdjustment.adjust(costWithBuyback, sa);
|
||||
if (costWithBuyback.getCostMana() != null) {
|
||||
neededMana = costWithBuyback.getCostMana().getMana().getCMC();
|
||||
}
|
||||
if (costWithBuyback.hasSpecificCostType(CostPayLife.class)
|
||||
|| costWithBuyback.hasSpecificCostType(CostDiscard.class)
|
||||
|| costWithBuyback.hasSpecificCostType(CostSacrifice.class)) {
|
||||
dangerousRecurringCost = true;
|
||||
}
|
||||
|
||||
// won't be able to afford buyback any time soon
|
||||
// if Buyback cost includes sacrifice, life, discard
|
||||
if (dangerousRecurringCost) {
|
||||
wasteBuybackAllowed = true;
|
||||
}
|
||||
|
||||
// Memory Crystal-like effects need special handling
|
||||
for (Card c : game.getCardsIn(ZoneType.Battlefield)) {
|
||||
for (StaticAbility s : c.getStaticAbilities()) {
|
||||
if ("ReduceCost".equals(s.getParam("Mode"))
|
||||
&& "Spell.Buyback".equals(s.getParam("ValidSpell"))) {
|
||||
neededMana -= AbilityUtils.calculateAmount(c, s.getParam("Amount"), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (neededMana < 0) {
|
||||
neededMana = 0;
|
||||
}
|
||||
|
||||
int hasMana = ComputerUtilMana.getAvailableManaEstimate(player, false);
|
||||
if (hasMana < neededMana - 1) {
|
||||
wasteBuybackAllowed = true;
|
||||
}
|
||||
|
||||
return wasteBuybackAllowed;
|
||||
}
|
||||
|
||||
// not sure "playing biggest spell" matters?
|
||||
private final static Comparator<SpellAbility> saComparator = new Comparator<SpellAbility>() {
|
||||
@Override
|
||||
@@ -732,6 +902,13 @@ public class AiController {
|
||||
int a1 = a.getPayCosts() == null ? 0 : a.getPayCosts().getTotalMana().getCMC();
|
||||
int b1 = b.getPayCosts() == null ? 0 : b.getPayCosts().getTotalMana().getCMC();
|
||||
|
||||
// deprioritize SAs explicitly marked as preferred to be activated last compared to all other SAs
|
||||
if (a.hasParam("AIActivateLast") && !b.hasParam("AIActivateLast")) {
|
||||
return 1;
|
||||
} else if (b.hasParam("AIActivateLast") && !a.hasParam("AIActivateLast")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// deprioritize planar die roll marked with AIRollPlanarDieParams:LowPriority$ True
|
||||
if (ApiType.RollPlanarDice == a.getApi() && a.getHostCard() != null && a.getHostCard().hasSVar("AIRollPlanarDieParams") && a.getHostCard().getSVar("AIRollPlanarDieParams").toLowerCase().matches(".*lowpriority\\$\\s*true.*")) {
|
||||
return 1;
|
||||
@@ -771,6 +948,20 @@ public class AiController {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a.getHostCard().equals(b.getHostCard()) && a.getApi() == b.getApi()
|
||||
&& a.getPayCosts() != null && b.getPayCosts() != null) {
|
||||
// Cheaper Spectacle costs should be preferred
|
||||
// FIXME: Any better way to identify that these are the same ability, one with Spectacle and one not?
|
||||
// (looks like it's not a full-fledged alternative cost as such, and is not processed with other alt costs)
|
||||
if (a.isSpectacle() && !b.isSpectacle()
|
||||
&& a.getPayCosts().getTotalMana().getCMC() < b.getPayCosts().getTotalMana().getCMC()) {
|
||||
return 1;
|
||||
} else if (b.isSpectacle() && !a.isSpectacle()
|
||||
&& b.getPayCosts().getTotalMana().getCMC() < a.getPayCosts().getTotalMana().getCMC()) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
a1 += getSpellAbilityPriority(a);
|
||||
b1 += getSpellAbilityPriority(b);
|
||||
|
||||
@@ -792,6 +983,9 @@ public class AiController {
|
||||
if (source.isCreature()) {
|
||||
p += 1;
|
||||
}
|
||||
if (source.hasSVar("AIPriorityModifier")) {
|
||||
p += Integer.parseInt(source.getSVar("AIPriorityModifier"));
|
||||
}
|
||||
// don't play equipments before having any creatures
|
||||
if (source.isEquipment() && noCreatures) {
|
||||
p -= 9;
|
||||
@@ -957,10 +1151,14 @@ public class AiController {
|
||||
numLandsAvailable++;
|
||||
}
|
||||
|
||||
//Discard unplayable card
|
||||
// Discard unplayable card (checks by CMC)
|
||||
// But check if there is a card in play that allows casting spells for free!
|
||||
// if yes, nothing is unplayable based on CMC alone
|
||||
boolean discardedUnplayable = false;
|
||||
boolean freeCastAllowed = ComputerUtilCost.isFreeCastAllowedByPermanent(player, null);
|
||||
|
||||
for (int j = 0; j < validCards.size(); j++) {
|
||||
if (validCards.get(j).getCMC() > numLandsAvailable && !validCards.get(j).hasSVar("DoNotDiscardIfAble")) {
|
||||
if ((validCards.get(j).getCMC() > numLandsAvailable || freeCastAllowed) && !validCards.get(j).hasSVar("DoNotDiscardIfAble")) {
|
||||
discardList.add(validCards.get(j));
|
||||
validCards.remove(validCards.get(j));
|
||||
discardedUnplayable = true;
|
||||
@@ -1013,7 +1211,7 @@ public class AiController {
|
||||
public boolean confirmAction(SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||
ApiType api = sa.getApi();
|
||||
|
||||
// Abilities without api may also use this routine, However they should provide a unique mode value
|
||||
// Abilities without api may also use this routine, However they should provide a unique mode value ?? How could this work?
|
||||
if (api == null) {
|
||||
String exMsg = String.format("AI confirmAction does not know what to decide about %s mode (api is null).",
|
||||
mode);
|
||||
@@ -1155,6 +1353,9 @@ public class AiController {
|
||||
// re-created if needed and used for any AI logic that needs it.
|
||||
predictedCombat = null;
|
||||
|
||||
// Reset priority mana reservation that's meant to work for one spell only
|
||||
AiCardMemory.clearMemorySet(player, AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_NEXT_SPELL);
|
||||
|
||||
if (useSimulation) {
|
||||
return singleSpellAbilityList(simPicker.chooseSpellAbilityToPlay(null));
|
||||
}
|
||||
@@ -1318,12 +1519,28 @@ public class AiController {
|
||||
}
|
||||
|
||||
private final SpellAbility getSpellAbilityToPlay() {
|
||||
// if top of stack is owned by me
|
||||
if (!game.getStack().isEmpty() && game.getStack().peekAbility().getActivatingPlayer().equals(player)) {
|
||||
// probably should let my stuff resolve
|
||||
return null;
|
||||
}
|
||||
final CardCollection cards = ComputerUtilAbility.getAvailableCards(game, player);
|
||||
List<SpellAbility> saList = Lists.newArrayList();
|
||||
|
||||
SpellAbility top = null;
|
||||
if (!game.getStack().isEmpty()) {
|
||||
top = game.getStack().peekAbility();
|
||||
}
|
||||
final boolean topOwnedByAI = top != null && top.getActivatingPlayer().equals(player);
|
||||
|
||||
if (topOwnedByAI) {
|
||||
// AI's own spell: should probably let my stuff resolve first, but may want to copy the SA or respond to it
|
||||
// in a scripted timed fashion.
|
||||
final boolean mustRespond = top.hasParam("AIRespondsToOwnAbility");
|
||||
|
||||
if (!mustRespond) {
|
||||
saList = ComputerUtilAbility.getSpellAbilities(cards, player); // get the SA list early to check for copy SAs
|
||||
if (ComputerUtilAbility.getFirstCopySASpell(saList) == null) {
|
||||
// Nothing to copy the spell with, so do nothing.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!game.getStack().isEmpty()) {
|
||||
SpellAbility counter = chooseCounterSpell(getPlayableCounters(cards));
|
||||
@@ -1334,7 +1551,13 @@ public class AiController {
|
||||
return counterETB;
|
||||
}
|
||||
|
||||
return chooseSpellAbilityToPlayFromList(ComputerUtilAbility.getSpellAbilities(cards, player), true);
|
||||
if (saList.isEmpty()) {
|
||||
saList = ComputerUtilAbility.getSpellAbilities(cards, player);
|
||||
}
|
||||
|
||||
SpellAbility chosenSa = chooseSpellAbilityToPlayFromList(saList, true);
|
||||
|
||||
return chosenSa;
|
||||
}
|
||||
|
||||
private SpellAbility chooseSpellAbilityToPlayFromList(final List<SpellAbility> all, boolean skipCounter) {
|
||||
@@ -1361,7 +1584,7 @@ public class AiController {
|
||||
sa.setActivatingPlayer(player);
|
||||
sa.setLastStateBattlefield(game.getLastStateBattlefield());
|
||||
sa.setLastStateGraveyard(game.getLastStateGraveyard());
|
||||
|
||||
|
||||
AiPlayDecision opinion = canPlayAndPayFor(sa);
|
||||
// PhaseHandler ph = game.getPhaseHandler();
|
||||
// System.out.printf("Ai thinks '%s' of %s -> %s @ %s %s >>> \n", opinion, sa.getHostCard(), sa, Lang.getPossesive(ph.getPlayerTurn().getName()), ph.getPhase());
|
||||
@@ -1705,7 +1928,7 @@ public class AiController {
|
||||
if (!useSimulation) {
|
||||
for (Entry<DeckSection, CardPool> ds : myDeck) {
|
||||
for (Entry<PaperCard, Integer> cp : ds.getValue()) {
|
||||
if (cp.getKey().getRules().getAiHints().getRemAIDecks())
|
||||
if (cp.getKey().getRules().getAiHints().getRemAIDecks())
|
||||
result.add(cp.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,6 +459,10 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
||||
Integer c = cost.convertAmount();
|
||||
String type = cost.getType();
|
||||
boolean isVehicle = type.contains("+withTotalPowerGE");
|
||||
|
||||
CardCollection exclude = new CardCollection();
|
||||
exclude.addAll(tapped);
|
||||
|
||||
if (c == null) {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
if (sVar.equals("XChoice")) {
|
||||
@@ -482,18 +486,36 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ("DontPayTapCostWithManaSources".equals(source.getSVar("AIPaymentPreference"))) {
|
||||
CardCollectionView toExclude =
|
||||
CardLists.getValidCards(player.getCardsIn(ZoneType.Battlefield), type.split(";"),
|
||||
ability.getActivatingPlayer(), ability.getHostCard(), ability);
|
||||
toExclude = CardLists.filter(toExclude, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card card) {
|
||||
for (final SpellAbility sa : card.getSpellAbilities()) {
|
||||
if (sa.isManaAbility() && sa.getPayCosts() != null && sa.getPayCosts().hasTapCost()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
exclude.addAll(toExclude);
|
||||
}
|
||||
|
||||
String totalP = "";
|
||||
CardCollectionView totap;
|
||||
if (isVehicle) {
|
||||
totalP = type.split("withTotalPowerGE")[1];
|
||||
type = TextUtil.fastReplace(type, "+withTotalPowerGE", "");
|
||||
totap = ComputerUtil.chooseTapTypeAccumulatePower(player, type, ability, !cost.canTapSource, Integer.parseInt(totalP), tapped);
|
||||
totap = ComputerUtil.chooseTapTypeAccumulatePower(player, type, ability, !cost.canTapSource, Integer.parseInt(totalP), exclude);
|
||||
} else {
|
||||
totap = ComputerUtil.chooseTapType(player, type, source, !cost.canTapSource, c, tapped);
|
||||
totap = ComputerUtil.chooseTapType(player, type, source, !cost.canTapSource, c, exclude);
|
||||
}
|
||||
|
||||
if (totap == null) {
|
||||
// System.out.println("Couldn't find a valid card(s) to tap for: " + source.getName());
|
||||
//System.out.println("Couldn't find a valid card(s) to tap for: " + source.getName());
|
||||
return null;
|
||||
}
|
||||
tapped.addAll(totap);
|
||||
@@ -528,7 +550,7 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
||||
// are currently conventionally flagged with AILogic$ DoSacrifice.
|
||||
c = AbilityUtils.calculateAmount(source, source.getSVar("ChosenX"), null);
|
||||
} else {
|
||||
// Other cards are assumed to be flagged RemAIDeck for now
|
||||
// Other cards are assumed to be flagged AI:RemoveDeck:All for now
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
@@ -787,8 +809,20 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = AbilityUtils.calculateAmount(source, "ChosenX", ability);
|
||||
source.setSVar("ChosenX", "Number$" + String.valueOf(c));
|
||||
} else if (amount.equals("All")) {
|
||||
c = source.getCounters(cost.counter);
|
||||
} else if (sVar.equals("Targeted$CardManaCost")) {
|
||||
c = 0;
|
||||
if (ability.getTargets().getNumTargeted() > 0) {
|
||||
for (Card tgt : ability.getTargets().getTargetCards()) {
|
||||
if (tgt.getManaCost() != null) {
|
||||
c += tgt.getManaCost().getCMC();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (sVar.equals("Count$xPaid")) {
|
||||
c = AbilityUtils.calculateAmount(source, "PayX", null);
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public enum AiProps { /** */
|
||||
THRESHOLD_TOKEN_CHUMP_TO_SAVE_PLANESWALKER ("135"), /** */
|
||||
THRESHOLD_NONTOKEN_CHUMP_TO_SAVE_PLANESWALKER ("110"), /** */
|
||||
CHUMP_TO_SAVE_PLANESWALKER_ONLY_ON_LETHAL ("true"), /** */
|
||||
TRY_TO_PRESERVE_BUYBACK_SPELLS ("true"), /** */
|
||||
MIN_SPELL_CMC_TO_COUNTER ("0"), /** */
|
||||
CHANCE_TO_COUNTER_CMC_1 ("50"), /** */
|
||||
CHANCE_TO_COUNTER_CMC_2 ("75"), /** */
|
||||
@@ -69,11 +70,18 @@ public enum AiProps { /** */
|
||||
ALWAYS_COUNTER_PUMP_SPELLS ("true"), /** */
|
||||
ALWAYS_COUNTER_AURAS ("true"), /** */
|
||||
ALWAYS_COUNTER_SPELLS_FROM_NAMED_CARDS (""), /** */
|
||||
CHANCE_TO_COPY_OWN_SPELL_WHILE_ON_STACK ("30"), /** */
|
||||
ALWAYS_COPY_SPELL_IF_CMC_DIFF ("2"), /** */
|
||||
ACTIVELY_DESTROY_ARTS_AND_NONAURA_ENCHS ("true"), /** */
|
||||
ACTIVELY_DESTROY_IMMEDIATELY_UNBLOCKABLE ("false"), /** */
|
||||
DESTROY_IMMEDIATELY_UNBLOCKABLE_THRESHOLD ("2"), /** */
|
||||
DESTROY_IMMEDIATELY_UNBLOCKABLE_ONLY_IN_DNGR ("true"), /** */
|
||||
DESTROY_IMMEDIATELY_UNBLOCKABLE_LIFE_IN_DNGR ("5"), /** */
|
||||
AVOID_TARGETING_CREATS_THAT_WILL_DIE ("true"), /** */
|
||||
DONT_EVAL_KILLSPELLS_ON_STACK_WITH_PERMISSION ("true"), /** */
|
||||
CHANCE_TO_CHAIN_TWO_DAMAGE_SPELLS("50"), /** */
|
||||
HOLD_X_DAMAGE_SPELLS_FOR_MORE_DAMAGE_CHANCE("100"),
|
||||
HOLD_X_DAMAGE_SPELLS_THRESHOLD("5"), /** */
|
||||
PRIORITY_REDUCTION_FOR_STORM_SPELLS ("0"), /** */
|
||||
USE_BERSERK_AGGRESSIVELY ("false"), /** */
|
||||
MIN_COUNT_FOR_STORM_SPELLS ("0"), /** */
|
||||
@@ -94,6 +102,7 @@ public enum AiProps { /** */
|
||||
SCRY_IMMEDIATELY_UNCASTABLE_TO_BOTTOM ("false"), /** */
|
||||
SCRY_IMMEDIATELY_UNCASTABLE_CMC_DIFF ("1"), /** */
|
||||
SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL ("10"), /** */
|
||||
SURVEIL_LIFEPERC_AFTER_PAYING_LIFE ("75"), /** */
|
||||
COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION ("true"), /** */
|
||||
COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION ("true"), /** */
|
||||
CONSERVATIVE_ENERGY_PAYMENT_ONLY_IN_COMBAT ("true"), /** */
|
||||
@@ -105,13 +114,24 @@ public enum AiProps { /** */
|
||||
INTUITION_ALTERNATIVE_LOGIC ("false"), /** */
|
||||
EXPLORE_MAX_CMC_DIFF_TO_PUT_IN_GRAVEYARD ("2"),
|
||||
EXPLORE_NUM_LANDS_TO_STILL_NEED_MORE("2"), /** */
|
||||
MOMIR_BASIC_LAND_STRATEGY("default"), /** */
|
||||
MOJHOSTO_NUM_LANDS_TO_ACTIVATE_JHOIRA("5"), /** */
|
||||
MOJHOSTO_CHANCE_TO_PREFER_JHOIRA_OVER_MOMIR ("50"), /** */
|
||||
MOJHOSTO_CHANCE_TO_USE_JHOIRA_COPY_INSTANT ("20"), /** */
|
||||
// Experimental features, must be removed after extensive testing and, ideally, defaulting
|
||||
AI_IN_DANGER_THRESHOLD("4"), /** */
|
||||
AI_IN_DANGER_MAX_THRESHOLD("4"), /** */
|
||||
FLASH_ENABLE_ADVANCED_LOGIC("true"), /** */
|
||||
FLASH_CHANCE_TO_OBEY_AMBUSHAI("100"), /** */
|
||||
FLASH_CHANCE_TO_CAST_DUE_TO_ETB_EFFECTS("100"), /** */
|
||||
FLASH_CHANCE_TO_CAST_FOR_ETB_BEFORE_MAIN1("10"), /** */
|
||||
FLASH_CHANCE_TO_RESPOND_TO_STACK_WITH_ETB("0"), /** */
|
||||
FLASH_CHANCE_TO_CAST_AS_VALUABLE_BLOCKER("100"),
|
||||
FLASH_USE_BUFF_AURAS_AS_COMBAT_TRICKS("true"),
|
||||
FLASH_BUFF_AURA_CHANCE_TO_CAST_EARLY("1"),
|
||||
FLASH_BUFF_AURA_CHANCE_CAST_AT_EOT("5"),
|
||||
FLASH_BUFF_AURA_CHANCE_TO_RESPOND_TO_STACK("100"); /** */
|
||||
// Experimental features, must be promoted or removed after extensive testing and, ideally, defaulting
|
||||
// <-- There are no experimental options here -->
|
||||
AI_IN_DANGER_THRESHOLD("4"),
|
||||
AI_IN_DANGER_MAX_THRESHOLD("4");
|
||||
|
||||
|
||||
private final String strDefaultVal;
|
||||
|
||||
@@ -20,14 +20,14 @@ package forge.ai;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.*;
|
||||
import forge.ai.ability.ChooseGenericEffectAi;
|
||||
import forge.ai.ability.ProtectAi;
|
||||
import forge.ai.ability.TokenAi;
|
||||
import forge.card.CardType;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.game.CardTraitPredicates;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.*;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
@@ -73,6 +73,7 @@ public class ComputerUtil {
|
||||
public static boolean handlePlayingSpellAbility(final Player ai, SpellAbility sa, final Game game, Runnable chooseTargets) {
|
||||
game.getStack().freezeStack();
|
||||
final Card source = sa.getHostCard();
|
||||
source.setSplitStateToPlayAbility(sa);
|
||||
|
||||
if (sa.isSpell() && !source.isCopiedSpell()) {
|
||||
if (source.getType().hasStringType("Arcane")) {
|
||||
@@ -408,6 +409,35 @@ public class ComputerUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (ComputerUtilCost.isFreeCastAllowedByPermanent(ai, "Discard")) {
|
||||
// Dream Halls allows to discard 1 worthless card to cast 1 expensive for free
|
||||
// Do it even if nothing marked for discard in hand, if it's worth doing!
|
||||
int mana = ComputerUtilMana.getAvailableManaEstimate(ai, false);
|
||||
|
||||
boolean cantAffordSoon = activate.getCMC() > mana + 1;
|
||||
boolean wrongColor = !activate.determineColor().hasNoColorsExcept(ColorSet.fromNames(ComputerUtilCost.getAvailableManaColors(ai, ImmutableList.<Card>of())).getColor());
|
||||
|
||||
// Only do this for spells, not activated abilities
|
||||
// We can't pay for this spell even if we play another land, or have wrong colors
|
||||
if (!activate.isInPlay() && (cantAffordSoon || wrongColor)) {
|
||||
CardCollection options = new CardCollection();
|
||||
for (Card c : typeList) {
|
||||
// Try to avoid stupidity by playing cheap spells and paying for them with expensive spells
|
||||
// while the intention was to do things the other way around
|
||||
if (c.isCreature() && activate.isCreature()) {
|
||||
if (ComputerUtilCard.evaluateCreature(c) < ComputerUtilCard.evaluateCreature(activate)) {
|
||||
options.add(c);
|
||||
}
|
||||
} else if (c.getCMC() <= activate.getCMC()) {
|
||||
options.add(c);
|
||||
}
|
||||
}
|
||||
if (!options.isEmpty()) {
|
||||
return ComputerUtilCard.getWorstAI(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Survival of the Fittest logic
|
||||
if (prefDef.contains("DiscardCost$Special:SurvivalOfTheFittest")) {
|
||||
return SpecialCardAi.SurvivalOfTheFittest.considerDiscardTarget(ai);
|
||||
@@ -823,7 +853,7 @@ public class ComputerUtil {
|
||||
|
||||
if (c != null && c.isEnchanted()) {
|
||||
// TODO: choose "worst" controlled enchanting Aura
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
for (Card aura : c.getEnchantedBy()) {
|
||||
if (aura.getController().equals(c.getController()) && remaining.contains(aura)) {
|
||||
return aura;
|
||||
}
|
||||
@@ -958,6 +988,27 @@ public class ComputerUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (card.hasKeyword(Keyword.RIOT) && ChooseGenericEffectAi.preferHasteForRiot(sa, ai)) {
|
||||
// Planning to choose Haste for Riot, so do this in Main 1
|
||||
return true;
|
||||
}
|
||||
|
||||
// if we have non-persistent mana in our pool, would be good to try to use it and not waste it
|
||||
if (ai.getManaPool().willManaBeLostAtEndOfPhase()) {
|
||||
boolean canUseToPayCost = false;
|
||||
for (byte color : MagicColor.WUBRGC) {
|
||||
if (ai.getManaPool().getAmountOfColor(color) > 0
|
||||
&& ((card.getManaCost().getColorProfile() & color) == color)) {
|
||||
canUseToPayCost = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (canUseToPayCost) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (card.isCreature() && !card.hasKeyword(Keyword.DEFENDER)
|
||||
&& (card.hasKeyword(Keyword.HASTE) || ComputerUtil.hasACardGivingHaste(ai, true) || sa.isDash())) {
|
||||
return true;
|
||||
@@ -975,7 +1026,7 @@ public class ComputerUtil {
|
||||
playNow = false;
|
||||
break;
|
||||
}
|
||||
if (!playNow && c.isCreature() && ComputerUtilCombat.canAttackNextTurn(c) && c.canBeEquippedBy(card)) {
|
||||
if (!playNow && c.isCreature() && ComputerUtilCombat.canAttackNextTurn(c) && c.canBeAttached(card)) {
|
||||
playNow = true;
|
||||
}
|
||||
}
|
||||
@@ -1025,6 +1076,20 @@ public class ComputerUtil {
|
||||
}
|
||||
} // AntiBuffedBy
|
||||
|
||||
// Plane cards that give Haste (e.g. Sokenzan)
|
||||
if (ai.getGame().getRules().hasAppliedVariant(GameType.Planechase)) {
|
||||
for (Card c : ai.getGame().getActivePlanes()) {
|
||||
for (StaticAbility s : c.getStaticAbilities()) {
|
||||
if (s.hasParam("AddKeyword")
|
||||
&& s.getParam("AddKeyword").contains("Haste")
|
||||
&& "Creature".equals(s.getParam("Affected"))
|
||||
&& card.isCreature()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final CardCollectionView vengevines = ai.getCardsIn(ZoneType.Graveyard, "Vengevine");
|
||||
if (!vengevines.isEmpty()) {
|
||||
final CardCollectionView creatures = ai.getCardsIn(ZoneType.Hand);
|
||||
@@ -1347,6 +1412,16 @@ public class ComputerUtil {
|
||||
if (sa.getApi() != ApiType.Fog) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Avoid re-entry for cards already being considered (e.g. in case the AI is considering
|
||||
// Convoke or Improvise for a Fog-like effect)
|
||||
if (c.hasKeyword("Convoke") || c.hasKeyword("Improvise")) {
|
||||
if (AiCardMemory.isRememberedCard(ai, c, AiCardMemory.MemorySet.MARKED_TO_AVOID_REENTRY)) {
|
||||
continue;
|
||||
}
|
||||
AiCardMemory.rememberCard(ai, c, AiCardMemory.MemorySet.MARKED_TO_AVOID_REENTRY);
|
||||
}
|
||||
|
||||
if (!ComputerUtilCost.canPayCost(sa, ai)) {
|
||||
continue;
|
||||
}
|
||||
@@ -1383,6 +1458,9 @@ public class ComputerUtil {
|
||||
if (!ComputerUtilCost.canPayCost(sa, ai)) {
|
||||
continue;
|
||||
}
|
||||
if (!GameActionUtil.getOptionalCostValues(sa).isEmpty()) {
|
||||
continue; // we can't rely on the AI being always willing and able to pay the optional cost to deal extra damage
|
||||
}
|
||||
damage = dmg;
|
||||
}
|
||||
|
||||
@@ -1760,7 +1838,69 @@ public class ComputerUtil {
|
||||
Iterables.addAll(threatened, ComputerUtil.predictThreatenedObjects(aiPlayer, saviour, topStack.getSubAbility()));
|
||||
return threatened;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the specified creature will die this turn either from lethal damage in combat
|
||||
* or from a killing spell on stack.
|
||||
* TODO: This currently does not account for the fact that spells on stack can be countered, can be improved.
|
||||
*
|
||||
* @param creature
|
||||
* A creature to check
|
||||
* @return true if the creature dies according to current board position.
|
||||
*/
|
||||
public static boolean predictCreatureWillDieThisTurn(final Player ai, final Card creature, final SpellAbility excludeSa) {
|
||||
final Game game = creature.getGame();
|
||||
|
||||
// a creature will die as a result of combat
|
||||
boolean willDieInCombat = game.getPhaseHandler().inCombat()
|
||||
&& ComputerUtilCombat.combatantWouldBeDestroyed(creature.getController(), creature, game.getCombat());
|
||||
|
||||
// a creature will [hopefully] die from a spell on stack
|
||||
boolean willDieFromSpell = false;
|
||||
boolean noStackCheck = false;
|
||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||
if (aic.getBooleanProperty(AiProps.DONT_EVAL_KILLSPELLS_ON_STACK_WITH_PERMISSION)) {
|
||||
// See if permission is on stack and ignore this check if there is and the relevant AI flag is set
|
||||
// TODO: improve this so that this flag is not needed and the AI can properly evaluate spells in presence of counterspells.
|
||||
for (SpellAbilityStackInstance si : game.getStack()) {
|
||||
SpellAbility sa = si.getSpellAbility(false);
|
||||
if (sa.getApi() == ApiType.Counter) {
|
||||
noStackCheck = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
willDieFromSpell = !noStackCheck && ComputerUtil.predictThreatenedObjects(creature.getController(), excludeSa).contains(creature);
|
||||
|
||||
return willDieInCombat || willDieFromSpell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of cards excluding any creatures that will die in active combat or from a spell on stack.
|
||||
* Works only on AI profiles which have AVOID_TARGETING_CREATS_THAT_WILL_DIE enabled, otherwise returns
|
||||
* the original list.
|
||||
*
|
||||
* @param ai
|
||||
* The AI player performing this evaluation
|
||||
* @param list
|
||||
* The list of cards to work with
|
||||
* @return a filtered list with no dying creatures in it
|
||||
*/
|
||||
public static CardCollection filterCreaturesThatWillDieThisTurn(final Player ai, final CardCollection list, final SpellAbility excludeSa) {
|
||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||
if (aic.getBooleanProperty(AiProps.AVOID_TARGETING_CREATS_THAT_WILL_DIE)) {
|
||||
// Try to avoid targeting creatures that are dead on board
|
||||
List<Card> willBeKilled = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card card) {
|
||||
return card.isCreature() && ComputerUtil.predictCreatureWillDieThisTurn(ai, card, excludeSa);
|
||||
}
|
||||
});
|
||||
list.removeAll(willBeKilled);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean playImmediately(Player ai, SpellAbility sa) {
|
||||
final Card source = sa.getHostCard();
|
||||
final Zone zone = source.getZone();
|
||||
@@ -2708,7 +2848,7 @@ public class ComputerUtil {
|
||||
repParams.put("Source", source);
|
||||
|
||||
List<ReplacementEffect> list = player.getGame().getReplacementHandler().getReplacementList(repParams,
|
||||
ReplacementLayer.None);
|
||||
ReplacementLayer.Other);
|
||||
|
||||
if (Iterables.any(list, CardTraitPredicates.hasParam("AiLogic", "NoLife"))) {
|
||||
return false;
|
||||
@@ -2739,7 +2879,7 @@ public class ComputerUtil {
|
||||
repParams.put("Source", source);
|
||||
|
||||
List<ReplacementEffect> list = player.getGame().getReplacementHandler().getReplacementList(repParams,
|
||||
ReplacementLayer.None);
|
||||
ReplacementLayer.Other);
|
||||
|
||||
if (Iterables.any(list, CardTraitPredicates.hasParam("AiLogic", "NoLife"))) {
|
||||
// no life gain is not negative
|
||||
@@ -2769,6 +2909,10 @@ public class ComputerUtil {
|
||||
if (ab.getApi() == null) {
|
||||
// only API-based SAs are supported, other things may lead to a NPE (e.g. Ancestral Vision Suspend SA)
|
||||
continue;
|
||||
} else if (ab.getApi() == ApiType.Mana && "ManaRitual".equals(ab.getParam("AILogic"))) {
|
||||
// Mana Ritual cards are too complex for the AI to consider casting through a spell effect and will
|
||||
// lead to a stack overflow. Consider improving.
|
||||
continue;
|
||||
}
|
||||
SpellAbility abTest = withoutPayingManaCost ? ab.copyWithNoManaCost() : ab.copy();
|
||||
// at this point, we're assuming that card will be castable from whichever zone it's in by the AI player.
|
||||
@@ -2848,7 +2992,7 @@ public class ComputerUtil {
|
||||
if (sa.getParam("AITgts").equals("BetterThanSource")) {
|
||||
int value = ComputerUtilCard.evaluateCreature(source);
|
||||
if (source.isEnchanted()) {
|
||||
for (Card enc : source.getEnchantedBy(false)) {
|
||||
for (Card enc : source.getEnchantedBy()) {
|
||||
if (enc.getController().equals(ai)) {
|
||||
value += 100; // is 100 per AI's own aura enough?
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package forge.ai;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.card.CardStateName;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameActionUtil;
|
||||
@@ -16,10 +12,14 @@ import forge.game.card.CardCollectionView;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates.Presets;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.OptionalCostValue;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ComputerUtilAbility {
|
||||
public static CardCollection getAvailableLandsToPlay(final Game game, final Player player) {
|
||||
if (!game.getStack().isEmpty() || !game.getPhaseHandler().getPhase().isMain()) {
|
||||
@@ -95,18 +95,58 @@ public class ComputerUtilAbility {
|
||||
|
||||
public static List<SpellAbility> getOriginalAndAltCostAbilities(final List<SpellAbility> originList, final Player player) {
|
||||
final List<SpellAbility> newAbilities = Lists.newArrayList();
|
||||
|
||||
List<SpellAbility> originListWithAddCosts = Lists.newArrayList();
|
||||
for (SpellAbility sa : originList) {
|
||||
// If this spell has alternative additional costs, add them instead of the unmodified SA itself
|
||||
sa.setActivatingPlayer(player);
|
||||
//add alternative costs as additional spell abilities
|
||||
originListWithAddCosts.addAll(GameActionUtil.getAdditionalCostSpell(sa));
|
||||
}
|
||||
|
||||
for (SpellAbility sa : originListWithAddCosts) {
|
||||
// determine which alternative costs are cheaper than the original and prioritize them
|
||||
List<SpellAbility> saAltCosts = GameActionUtil.getAlternativeCosts(sa, player);
|
||||
List<SpellAbility> priorityAltSa = Lists.newArrayList();
|
||||
List<SpellAbility> otherAltSa = Lists.newArrayList();
|
||||
for (SpellAbility altSa : saAltCosts) {
|
||||
if (altSa.getPayCosts() == null || sa.getPayCosts() == null) {
|
||||
otherAltSa.add(altSa);
|
||||
} else if (sa.getPayCosts().isOnlyManaCost()
|
||||
&& altSa.getPayCosts().isOnlyManaCost() && sa.getPayCosts().getTotalMana().compareTo(altSa.getPayCosts().getTotalMana()) == 1) {
|
||||
// the alternative cost is strictly cheaper, so why not? (e.g. Omniscience etc.)
|
||||
priorityAltSa.add(altSa);
|
||||
} else {
|
||||
otherAltSa.add(altSa);
|
||||
}
|
||||
}
|
||||
|
||||
// add alternative costs as additional spell abilities
|
||||
newAbilities.addAll(priorityAltSa);
|
||||
newAbilities.add(sa);
|
||||
newAbilities.addAll(GameActionUtil.getAlternativeCosts(sa, player));
|
||||
newAbilities.addAll(otherAltSa);
|
||||
}
|
||||
|
||||
final List<SpellAbility> result = Lists.newArrayList();
|
||||
for (SpellAbility sa : newAbilities) {
|
||||
sa.setActivatingPlayer(player);
|
||||
result.addAll(GameActionUtil.getOptionalCosts(sa));
|
||||
|
||||
// Optional cost selection through the AI controller
|
||||
boolean choseOptCost = false;
|
||||
List<OptionalCostValue> list = GameActionUtil.getOptionalCostValues(sa);
|
||||
if (!list.isEmpty()) {
|
||||
list = player.getController().chooseOptionalCosts(sa, list);
|
||||
if (!list.isEmpty()) {
|
||||
choseOptCost = true;
|
||||
result.add(GameActionUtil.addOptionalCosts(sa, list));
|
||||
}
|
||||
}
|
||||
|
||||
// Add only one ability: either the one with preferred optional costs, or the original one if there are none
|
||||
if (!choseOptCost) {
|
||||
result.add(sa);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -128,6 +168,17 @@ public class ComputerUtilAbility {
|
||||
return tgtSA;
|
||||
}
|
||||
|
||||
public static SpellAbility getFirstCopySASpell(List<SpellAbility> spells) {
|
||||
SpellAbility sa = null;
|
||||
for (SpellAbility spell : spells) {
|
||||
if (spell.getApi() == ApiType.CopySpellAbility) {
|
||||
sa = spell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
|
||||
public static Card getAbilitySource(SpellAbility sa) {
|
||||
return sa.getOriginalHost() != null ? sa.getOriginalHost() : sa.getHostCard();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import forge.game.ability.ApiType;
|
||||
import forge.game.card.*;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.cost.CostPayEnergy;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.keyword.KeywordCollection;
|
||||
@@ -585,7 +586,7 @@ public class ComputerUtilCard {
|
||||
|
||||
// Add all cost of all auras with the same controller
|
||||
if (card.isEnchanted()) {
|
||||
final List<Card> auras = CardLists.filterControlledBy(card.getEnchantedBy(false), card.getController());
|
||||
final List<Card> auras = CardLists.filterControlledBy(card.getEnchantedBy(), card.getController());
|
||||
curCMC += Aggregates.sum(auras, CardPredicates.Accessors.fnGetCmc) + auras.size();
|
||||
}
|
||||
|
||||
@@ -833,7 +834,7 @@ public class ComputerUtilCard {
|
||||
int score = tmp.isTapped() ? 2 : 0;
|
||||
score += tmp.isBasicLand() ? 1 : 0;
|
||||
score -= tmp.isCreature() ? 4 : 0;
|
||||
for (Card aura : tmp.getEnchantedBy(false)) {
|
||||
for (Card aura : tmp.getEnchantedBy()) {
|
||||
if (aura.getController().isOpponentOf(tmp.getController())) {
|
||||
score += 5;
|
||||
} else {
|
||||
@@ -857,7 +858,7 @@ public class ComputerUtilCard {
|
||||
int score = tmp.isTapped() ? 0 : 2;
|
||||
score += tmp.isBasicLand() ? 2 : 0;
|
||||
score -= tmp.isCreature() ? 4 : 0;
|
||||
score -= 5 * tmp.getEnchantedBy(false).size();
|
||||
score -= 5 * tmp.getEnchantedBy().size();
|
||||
|
||||
if (score >= maxScore) {
|
||||
land = tmp;
|
||||
@@ -1033,7 +1034,7 @@ public class ComputerUtilCard {
|
||||
// interrupt 3: two for one = good
|
||||
if (c.isEnchanted()) {
|
||||
boolean myEnchants = false;
|
||||
for (Card enc : c.getEnchantedBy(false)) {
|
||||
for (Card enc : c.getEnchantedBy()) {
|
||||
if (enc.getOwner().equals(ai)) {
|
||||
myEnchants = true;
|
||||
break;
|
||||
@@ -1311,10 +1312,22 @@ public class ComputerUtilCard {
|
||||
|
||||
//2. grant haste
|
||||
if (keywords.contains("Haste") && c.hasSickness() && !c.isTapped()) {
|
||||
chance += 0.5f;
|
||||
if (ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, pumped)) {
|
||||
chance += 0.5f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat, true) / opp.getLife();
|
||||
double nonCombatChance = 0.0f;
|
||||
double combatChance = 0.0f;
|
||||
// non-combat Haste: has an activated ability with tap cost
|
||||
for (SpellAbility ab : c.getSpellAbilities()) {
|
||||
Cost abCost = ab.getPayCosts();
|
||||
if (abCost != null && abCost.hasTapCost()
|
||||
&& (!abCost.hasManaCost() || ComputerUtilMana.canPayManaCost(ab, ai, 0))) {
|
||||
nonCombatChance += 0.5f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// combat Haste: only grant it if the creature will attack
|
||||
if (ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, pumped)) {
|
||||
combatChance += 0.5f + (0.5f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat, true) / opp.getLife());
|
||||
}
|
||||
chance += nonCombatChance + combatChance;
|
||||
}
|
||||
|
||||
//3. grant evasive
|
||||
@@ -1479,7 +1492,15 @@ public class ComputerUtilCard {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ("UntapCombatTrick".equals(sa.getParam("AILogic")) && c.isTapped()) {
|
||||
if (phase.is(PhaseType.COMBAT_DECLARE_ATTACKERS) && phase.getPlayerTurn().isOpponentOf(ai)) {
|
||||
chance += 0.5f; // this creature will untap to become a potential blocker
|
||||
} else if (phase.is(PhaseType.COMBAT_DECLARE_BLOCKERS, ai)) {
|
||||
chance += 1.0f; // untap after tapping for attack
|
||||
}
|
||||
}
|
||||
|
||||
if (isBerserk) {
|
||||
// if we got here, Berserk will result in the pumped creature dying at EOT and the opponent will not lose
|
||||
// (other similar cards with AILogic$ Berserk that do not die only when attacking are excluded from consideration)
|
||||
@@ -1492,7 +1513,7 @@ public class ComputerUtilCard {
|
||||
}
|
||||
}
|
||||
|
||||
boolean wantToHoldTrick = holdCombatTricks;
|
||||
boolean wantToHoldTrick = holdCombatTricks && !ai.getCardsIn(ZoneType.Hand).isEmpty();
|
||||
if (chanceToHoldCombatTricks >= 0) {
|
||||
// Obey the chance specified in the AI profile for holding combat tricks
|
||||
wantToHoldTrick &= MyRandom.percentTrue(chanceToHoldCombatTricks);
|
||||
@@ -1508,14 +1529,18 @@ public class ComputerUtilCard {
|
||||
// Attempt to hold combat tricks until blockers are declared, and try to lure the opponent into blocking
|
||||
// (The AI will only do it for one attacker at the moment, otherwise it risks running his attackers into
|
||||
// an army of opposing blockers with only one combat trick in hand)
|
||||
AiCardMemory.rememberCard(ai, c, AiCardMemory.MemorySet.MANDATORY_ATTACKERS);
|
||||
AiCardMemory.rememberCard(ai, c, AiCardMemory.MemorySet.TRICK_ATTACKERS);
|
||||
// Reserve the mana until Declare Blockers such that the AI doesn't tap out before having a chance to use
|
||||
// the combat trick
|
||||
boolean reserved = false;
|
||||
if (ai.getController().isAI()) {
|
||||
((PlayerControllerAi) ai.getController()).getAi().reserveManaSources(sa, PhaseType.COMBAT_DECLARE_BLOCKERS, false);
|
||||
reserved = ((PlayerControllerAi) ai.getController()).getAi().reserveManaSources(sa, PhaseType.COMBAT_DECLARE_BLOCKERS, false);
|
||||
// Only proceed with this if we could actually reserve mana
|
||||
if (reserved) {
|
||||
AiCardMemory.rememberCard(ai, c, AiCardMemory.MemorySet.MANDATORY_ATTACKERS);
|
||||
AiCardMemory.rememberCard(ai, c, AiCardMemory.MemorySet.TRICK_ATTACKERS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
// Don't try to mix "lure" and "precast" paradigms for combat tricks, since that creates issues with
|
||||
// the AI overextending the attack
|
||||
@@ -1616,6 +1641,7 @@ public class ComputerUtilCard {
|
||||
if (exclude != null) {
|
||||
list.removeAll(exclude);
|
||||
}
|
||||
list.add(vCard); // account for the static abilities that may be present on the card itself
|
||||
for (final Card c : list) {
|
||||
for (final StaticAbility stAb : c.getStaticAbilities()) {
|
||||
final Map<String, String> params = stAb.getMapParams();
|
||||
@@ -1785,15 +1811,20 @@ public class ComputerUtilCard {
|
||||
|
||||
CardCollection priorityCards = new CardCollection();
|
||||
for (Card atk : oppCards) {
|
||||
boolean canBeBlocked = false;
|
||||
if (isUselessCreature(atk.getController(), atk)) {
|
||||
continue;
|
||||
}
|
||||
for (Card blk : aiCreats) {
|
||||
if (!CombatUtil.canBlock(atk, blk, true)) {
|
||||
boolean threat = atk.getNetCombatDamage() >= ai.getLife() - lifeInDanger;
|
||||
if (!priorityRemovalOnlyInDanger || threat) {
|
||||
priorityCards.add(atk);
|
||||
}
|
||||
if (CombatUtil.canBlock(atk, blk, true)) {
|
||||
canBeBlocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!canBeBlocked) {
|
||||
boolean threat = atk.getNetCombatDamage() >= ai.getLife() - lifeInDanger;
|
||||
if (!priorityRemovalOnlyInDanger || threat) {
|
||||
priorityCards.add(atk);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1844,4 +1875,13 @@ public class ComputerUtilCard {
|
||||
|
||||
return AiPlayDecision.WillPlay;
|
||||
}
|
||||
|
||||
// Determine if the AI has an AI:RemoveDeck:All or an AI:RemoveDeck:Random hint specified.
|
||||
// Includes a NPE guard on getRules() which might otherwise be tripped on some cards (e.g. tokens).
|
||||
public static boolean isCardRemAIDeck(final Card card) {
|
||||
return card.getRules() != null && card.getRules().getAiHints().getRemAIDecks();
|
||||
}
|
||||
public static boolean isCardRemRandomDeck(final Card card) {
|
||||
return card.getRules() != null && card.getRules().getAiHints().getRemRandomDecks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1052,11 +1052,15 @@ public class ComputerUtilCombat {
|
||||
if (!ability.hasParam("CounterType") || !ability.getParam("CounterType").equals("P1P1")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Monstrosity") && blocker.isMonstrous()) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Adapt") && blocker.getCounters(CounterType.P1P1) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ComputerUtilCost.canPayCost(ability, blocker.getController())) {
|
||||
int pBonus = AbilityUtils.calculateAmount(ability.getHostCard(), ability.getParam("CounterNum"), ability);
|
||||
if (pBonus > 0) {
|
||||
@@ -1224,11 +1228,15 @@ public class ComputerUtilCombat {
|
||||
if (!ability.hasParam("CounterType") || !ability.getParam("CounterType").equals("P1P1")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Monstrosity") && blocker.isMonstrous()) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Adapt") && blocker.getCounters(CounterType.P1P1) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ComputerUtilCost.canPayCost(ability, blocker.getController())) {
|
||||
int tBonus = AbilityUtils.calculateAmount(ability.getHostCard(), ability.getParam("CounterNum"), ability);
|
||||
if (tBonus > 0) {
|
||||
@@ -1442,11 +1450,15 @@ public class ComputerUtilCombat {
|
||||
if (!ability.hasParam("CounterType") || !ability.getParam("CounterType").equals("P1P1")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Monstrosity") && attacker.isMonstrous()) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Adapt") && blocker != null && blocker.getCounters(CounterType.P1P1) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ability.getPayCosts().hasTapCost() && ComputerUtilCost.canPayCost(ability, attacker.getController())) {
|
||||
int pBonus = AbilityUtils.calculateAmount(ability.getHostCard(), ability.getParam("CounterNum"), ability);
|
||||
if (pBonus > 0) {
|
||||
@@ -1675,11 +1687,15 @@ public class ComputerUtilCombat {
|
||||
if (!ability.hasParam("CounterType") || !ability.getParam("CounterType").equals("P1P1")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Monstrosity") && attacker.isMonstrous()) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ability.hasParam("Adapt") && blocker.getCounters(CounterType.P1P1) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ability.getPayCosts().hasTapCost() && ComputerUtilCost.canPayCost(ability, attacker.getController())) {
|
||||
int tBonus = AbilityUtils.calculateAmount(ability.getHostCard(), ability.getParam("CounterNum"), ability);
|
||||
if (tBonus > 0) {
|
||||
@@ -2104,6 +2120,16 @@ public class ComputerUtilCombat {
|
||||
defenderDamage = predictDamageTo(attacker, defenderDamage, possibleAttackerPrevention, blocker, true);
|
||||
attackerDamage = predictDamageTo(blocker, attackerDamage, possibleDefenderPrevention, attacker, true);
|
||||
|
||||
// Damage prevention might come from a static effect
|
||||
if (!ai.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) {
|
||||
if (isCombatDamagePrevented(attacker, blocker, attackerDamage)) {
|
||||
attackerDamage = 0;
|
||||
}
|
||||
if (isCombatDamagePrevented(blocker, attacker, defenderDamage)) {
|
||||
defenderDamage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (combat != null) {
|
||||
for (Card atkr : combat.getAttackersBlockedBy(blocker)) {
|
||||
if (!atkr.equals(attacker)) {
|
||||
@@ -2550,7 +2576,7 @@ public class ComputerUtilCombat {
|
||||
return original;
|
||||
}
|
||||
|
||||
private static boolean isCombatDamagePrevented(final Card attacker, final GameEntity target, final int damage) {
|
||||
public static boolean isCombatDamagePrevented(final Card attacker, final GameEntity target, final int damage) {
|
||||
final Game game = attacker.getGame();
|
||||
|
||||
// first try to replace the damage
|
||||
@@ -2564,7 +2590,7 @@ public class ComputerUtilCombat {
|
||||
// repParams.put("PreventMap", preventMap);
|
||||
|
||||
List<ReplacementEffect> list = game.getReplacementHandler().getReplacementList(repParams,
|
||||
ReplacementLayer.None);
|
||||
ReplacementLayer.Other);
|
||||
|
||||
return !list.isEmpty();
|
||||
}
|
||||
@@ -2655,6 +2681,30 @@ public class ComputerUtilCombat {
|
||||
|
||||
return attackerAfterTrigs;
|
||||
}
|
||||
|
||||
public static boolean willKillAtLeastOne(final Player ai, final Card c, final Combat combat) {
|
||||
// This method detects if the attacking or blocking group the card "c" belongs to will kill
|
||||
// at least one creature it's in combat with (either profitably or as a trade),
|
||||
if (combat == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (combat.isBlocked(c)) {
|
||||
for (Card blk : combat.getBlockers(c)) {
|
||||
if (ComputerUtilCombat.blockerWouldBeDestroyed(ai, blk, combat)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (combat.isBlocking(c)) {
|
||||
for (Card atk : combat.getAttackersBlockedBy(c)) {
|
||||
if (ComputerUtilCombat.attackerWouldBeDestroyed(ai, atk, combat)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,15 +5,13 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import forge.ai.ability.AnimateAi;
|
||||
import forge.card.ColorSet;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.card.CardFactoryUtil;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.*;
|
||||
import forge.game.card.CardPredicates.Presets;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.cost.*;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.Spell;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
@@ -31,7 +29,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check add m1 m1 counter cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -46,7 +44,7 @@ public class ComputerUtilCost {
|
||||
if (part instanceof CostPutCounter) {
|
||||
final CostPutCounter addCounter = (CostPutCounter) part;
|
||||
final CounterType type = addCounter.getCounter();
|
||||
|
||||
|
||||
if (type.equals(CounterType.M1M1)) {
|
||||
return false;
|
||||
}
|
||||
@@ -60,7 +58,7 @@ public class ComputerUtilCost {
|
||||
}
|
||||
/**
|
||||
* Check remove counter cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -74,10 +72,10 @@ public class ComputerUtilCost {
|
||||
for (final CostPart part : cost.getCostParts()) {
|
||||
if (part instanceof CostRemoveCounter) {
|
||||
final CostRemoveCounter remCounter = (CostRemoveCounter) part;
|
||||
|
||||
|
||||
final CounterType type = remCounter.counter;
|
||||
if (!part.payCostFromSource()) {
|
||||
if (type.name().equals("P1P1")) {
|
||||
if (CounterType.P1P1.equals(type)) {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
@@ -92,7 +90,7 @@ public class ComputerUtilCost {
|
||||
// value later as the AI decides what to do (in checkApiLogic / checkAiLogic)
|
||||
if (sa != null && sa.hasSVar(remCounter.getAmount())) {
|
||||
final String sVar = sa.getSVar(remCounter.getAmount());
|
||||
if (sVar.equals("XChoice")) {
|
||||
if (sVar.equals("XChoice") && !sa.hasSVar("ChosenX")) {
|
||||
sa.setSVar("ChosenX", String.valueOf(source.getCounters(type)));
|
||||
}
|
||||
}
|
||||
@@ -108,7 +106,8 @@ public class ComputerUtilCost {
|
||||
}
|
||||
|
||||
//don't kill the creature
|
||||
if (type.name().equals("P1P1") && source.getLethalDamage() <= 1) {
|
||||
if (CounterType.P1P1.equals(type) && source.getLethalDamage() <= 1
|
||||
&& !source.hasKeyword(Keyword.UNDYING)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +117,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check discard cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -135,7 +134,7 @@ public class ComputerUtilCost {
|
||||
for (final CostPart part : cost.getCostParts()) {
|
||||
if (part instanceof CostDiscard) {
|
||||
final CostDiscard disc = (CostDiscard) part;
|
||||
|
||||
|
||||
final String type = disc.getType();
|
||||
if (type.equals("CARDNAME") && source.getAbilityText().contains("Bloodrush")) {
|
||||
continue;
|
||||
@@ -145,6 +144,7 @@ public class ComputerUtilCost {
|
||||
continue;
|
||||
}
|
||||
int num = AbilityUtils.calculateAmount(source, disc.getAmount(), null);
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
Card pref = ComputerUtil.getCardPreference(ai, source, "DiscardCost", typeList);
|
||||
if (pref == null) {
|
||||
@@ -161,7 +161,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check life cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -193,7 +193,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check life cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -210,12 +210,12 @@ public class ComputerUtilCost {
|
||||
for (final CostPart part : cost.getCostParts()) {
|
||||
if (part instanceof CostPayLife) {
|
||||
final CostPayLife payLife = (CostPayLife) part;
|
||||
|
||||
|
||||
Integer amount = payLife.convertAmount();
|
||||
if (amount == null) {
|
||||
amount = AbilityUtils.calculateAmount(source, payLife.getAmount(), sourceAbility);
|
||||
}
|
||||
|
||||
|
||||
// check if there's override for the remainingLife threshold
|
||||
if (sourceAbility != null && sourceAbility.hasParam("AILifeThreshold")) {
|
||||
remainingLife = Integer.parseInt(sourceAbility.getParam("AILifeThreshold"));
|
||||
@@ -231,7 +231,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check creature sacrifice cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -251,7 +251,7 @@ public class ComputerUtilCost {
|
||||
return false;
|
||||
}
|
||||
final String type = sac.getType();
|
||||
|
||||
|
||||
if (type.equals("CARDNAME")) {
|
||||
continue;
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check sacrifice cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -300,7 +300,7 @@ public class ComputerUtilCost {
|
||||
if (!important) {
|
||||
return false;
|
||||
}
|
||||
if (!CardLists.filterControlledBy(source.getEnchantedBy(false), source.getController()).isEmpty()) {
|
||||
if (!CardLists.filterControlledBy(source.getEnchantedBy(), source.getController()).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
@@ -323,7 +323,7 @@ public class ComputerUtilCost {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSacrificeSelfCost(final Cost cost) {
|
||||
if (cost == null) {
|
||||
return false;
|
||||
@@ -340,7 +340,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check creature sacrifice cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -386,7 +386,7 @@ public class ComputerUtilCost {
|
||||
|
||||
/**
|
||||
* Check sacrifice cost.
|
||||
*
|
||||
*
|
||||
* @param cost
|
||||
* the cost
|
||||
* @param source
|
||||
@@ -401,14 +401,14 @@ public class ComputerUtilCost {
|
||||
* <p>
|
||||
* shouldPayCost.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param hostCard
|
||||
* a {@link forge.game.card.Card} object.
|
||||
* @param cost
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean shouldPayCost(final Player ai, final Card hostCard, final Cost cost) {
|
||||
|
||||
|
||||
for (final CostPart part : cost.getCostParts()) {
|
||||
if (part instanceof CostPayLife) {
|
||||
if (!ai.cantLoseForZeroOrLessLife()) {
|
||||
@@ -423,7 +423,7 @@ public class ComputerUtilCost {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
} // shouldPayCost()
|
||||
|
||||
@@ -431,7 +431,7 @@ public class ComputerUtilCost {
|
||||
* <p>
|
||||
* canPayCost.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* a {@link forge.game.spellability.SpellAbility} object.
|
||||
* @param player
|
||||
@@ -479,7 +479,7 @@ public class ComputerUtilCost {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Try not to lose Planeswalker if not threatened
|
||||
if (sa.getRestrictions().isPwAbility()) {
|
||||
for (final CostPart part : sa.getPayCosts().getCostParts()) {
|
||||
@@ -495,6 +495,7 @@ public class ComputerUtilCost {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KLD vehicle
|
||||
if (sa.hasParam("Crew")) { // put under checkTapTypeCost?
|
||||
for (final CostPart part : sa.getPayCosts().getCostParts()) {
|
||||
@@ -504,7 +505,37 @@ public class ComputerUtilCost {
|
||||
}
|
||||
}
|
||||
|
||||
return ComputerUtilMana.canPayManaCost(sa, player, extraManaNeeded)
|
||||
// TODO: Alternate costs which involve both paying mana and tapping a card, e.g. Zahid, Djinn of the Lamp
|
||||
// Current AI decides on each part separately, thus making it possible for the AI to cheat by
|
||||
// tapping a mana source for mana and for the tap cost at the same time. Until this is improved, AI
|
||||
// will not consider mana sources valid for paying the tap cost to avoid this exact situation.
|
||||
if ("DontPayTapCostWithManaSources".equals(sa.getHostCard().getSVar("AIPaymentPreference"))) {
|
||||
for (final CostPart part : sa.getPayCosts().getCostParts()) {
|
||||
if (part instanceof CostTapType) {
|
||||
CardCollectionView nonManaSources =
|
||||
CardLists.getValidCards(player.getCardsIn(ZoneType.Battlefield), part.getType().split(";"),
|
||||
sa.getActivatingPlayer(), sa.getHostCard(), sa);
|
||||
nonManaSources = CardLists.filter(nonManaSources, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card card) {
|
||||
boolean hasManaSa = false;
|
||||
for (final SpellAbility sa : card.getSpellAbilities()) {
|
||||
if (sa.isManaAbility() && sa.getPayCosts() != null && sa.getPayCosts().hasTapCost()) {
|
||||
hasManaSa = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return !hasManaSa;
|
||||
}
|
||||
});
|
||||
if (nonManaSources.size() < part.convertAmount()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ComputerUtilMana.canPayManaCost(sa, player, extraManaNeeded)
|
||||
&& CostPayment.canPayAdditionalCosts(sa.getPayCosts(), sa);
|
||||
} // canPayCost()
|
||||
|
||||
@@ -516,7 +547,7 @@ public class ComputerUtilCost {
|
||||
boolean payNever = "Never".equals(aiLogic);
|
||||
boolean shockland = "Shockland".equals(aiLogic);
|
||||
boolean isMine = sa.getActivatingPlayer().equals(payer);
|
||||
|
||||
|
||||
if (payNever) { return false; }
|
||||
if (payForOwnOnly && !isMine) { return false; }
|
||||
if (payOwner) {
|
||||
@@ -536,7 +567,7 @@ public class ComputerUtilCost {
|
||||
// if the new land size would equal the CMC of a card in AIs hand, consider playing it untapped,
|
||||
// otherwise don't bother running other checks
|
||||
if (landsize != c.getCMC()) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
// try to determine in the AI is actually planning to play a spell ability from the card
|
||||
boolean willPlay = ComputerUtil.hasReasonToPlayCardThisTurn(payer, c);
|
||||
@@ -620,4 +651,15 @@ public class ComputerUtilCost {
|
||||
|
||||
return colorsAvailable;
|
||||
}
|
||||
|
||||
public static boolean isFreeCastAllowedByPermanent(Player player, String altCost) {
|
||||
Game game = player.getGame();
|
||||
for (Card cardInPlay : game.getCardsIn(ZoneType.Battlefield)) {
|
||||
if (cardInPlay.hasSVar("AllowFreeCast")) {
|
||||
return altCost == null ? "Always".equals(cardInPlay.getSVar("AllowFreeCast"))
|
||||
: altCost.equals(cardInPlay.getSVar("AllowFreeCast"));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,7 @@ import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.*;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.cost.CostAdjustment;
|
||||
import forge.game.cost.CostPartMana;
|
||||
import forge.game.cost.CostPayEnergy;
|
||||
import forge.game.cost.CostPayment;
|
||||
import forge.game.cost.*;
|
||||
import forge.game.mana.Mana;
|
||||
import forge.game.mana.ManaCostBeingPaid;
|
||||
import forge.game.mana.ManaPool;
|
||||
@@ -860,6 +856,11 @@ public class ComputerUtilMana {
|
||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||
int chanceToReserve = aic.getIntProperty(AiProps.RESERVE_MANA_FOR_MAIN2_CHANCE);
|
||||
|
||||
// Mana reserved for spell synchronization
|
||||
if (AiCardMemory.isRememberedCard(ai, sourceCard, AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_NEXT_SPELL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PhaseType curPhase = ai.getGame().getPhaseHandler().getPhase();
|
||||
|
||||
// For combat tricks, always obey mana reservation
|
||||
@@ -1513,7 +1514,7 @@ public class ComputerUtilMana {
|
||||
final Card offering = sa.getSacrificedAsOffering();
|
||||
offering.setUsedToPay(false);
|
||||
if (costIsPaid && !test) {
|
||||
sa.getHostCard().getController().getGame().getAction().sacrifice(offering, sa);
|
||||
sa.getHostCard().getGame().getAction().sacrifice(offering, sa, null);
|
||||
}
|
||||
sa.resetSacrificedAsOffering();
|
||||
}
|
||||
@@ -1521,7 +1522,7 @@ public class ComputerUtilMana {
|
||||
final Card emerge = sa.getSacrificedAsEmerge();
|
||||
emerge.setUsedToPay(false);
|
||||
if (costIsPaid && !test) {
|
||||
sa.getHostCard().getController().getGame().getAction().sacrifice(emerge, sa);
|
||||
sa.getHostCard().getGame().getAction().sacrifice(emerge, sa, null);
|
||||
}
|
||||
sa.resetSacrificedAsEmerge();
|
||||
}
|
||||
|
||||
@@ -196,9 +196,7 @@ public abstract class GameState {
|
||||
cardsReferencedByID.add(card.getExiledWith());
|
||||
}
|
||||
if (zone == ZoneType.Battlefield) {
|
||||
if (!card.getEnchantedBy(false).isEmpty()
|
||||
|| !card.getEquippedBy(false).isEmpty()
|
||||
|| !card.getFortifiedBy(false).isEmpty()) {
|
||||
if (!card.getAttachedCards().isEmpty()) {
|
||||
// Remember the ID of cards that have attachments
|
||||
cardsReferencedByID.add(card);
|
||||
}
|
||||
@@ -290,17 +288,13 @@ public abstract class GameState {
|
||||
} else if (c.getCurrentStateName().equals(CardStateName.Meld)) {
|
||||
newText.append("|Meld");
|
||||
}
|
||||
if (c.getEquipping() != null) {
|
||||
newText.append("|Attaching:").append(c.getEquipping().getId());
|
||||
} else if (c.getFortifying() != null) {
|
||||
newText.append("|Attaching:").append(c.getFortifying().getId());
|
||||
} else if (c.getEnchantingCard() != null) {
|
||||
newText.append("|Attaching:").append(c.getEnchantingCard().getId());
|
||||
if (c.isAttachedToEntity()) {
|
||||
newText.append("|AttachedTo:").append(c.getEntityAttachedTo().getId());
|
||||
}
|
||||
if (c.getEnchantingPlayer() != null) {
|
||||
if (c.getPlayerAttachedTo() != null) {
|
||||
// TODO: improve this for game states with more than two players
|
||||
newText.append("|EnchantingPlayer:");
|
||||
Player p = c.getEnchantingPlayer();
|
||||
Player p = c.getPlayerAttachedTo();
|
||||
newText.append(p.getController().isAI() ? "AI" : "HUMAN");
|
||||
}
|
||||
|
||||
@@ -959,25 +953,15 @@ public abstract class GameState {
|
||||
// Unattach all permanents first
|
||||
for(Entry<Card, Integer> entry : cardToAttachId.entrySet()) {
|
||||
Card attachedTo = idToCard.get(entry.getValue());
|
||||
|
||||
attachedTo.unEnchantAllCards();
|
||||
attachedTo.unEquipAllCards();
|
||||
for (Card c : attachedTo.getFortifiedBy(true)) {
|
||||
attachedTo.unFortifyCard(c);
|
||||
}
|
||||
attachedTo.unAttachAllCards();
|
||||
}
|
||||
|
||||
// Attach permanents by ID
|
||||
for(Entry<Card, Integer> entry : cardToAttachId.entrySet()) {
|
||||
Card attachedTo = idToCard.get(entry.getValue());
|
||||
Card attacher = entry.getKey();
|
||||
|
||||
if (attacher.isEquipment()) {
|
||||
attacher.equipCard(attachedTo);
|
||||
} else if (attacher.isAura()) {
|
||||
attacher.enchantEntity(attachedTo);
|
||||
} else if (attacher.isFortified()) {
|
||||
attacher.fortifyCard(attachedTo);
|
||||
if (attacher.isAttachment()) {
|
||||
attacher.attachToEntity(attachedTo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -988,7 +972,7 @@ public abstract class GameState {
|
||||
Game game = attacher.getGame();
|
||||
Player attachedTo = entry.getValue() == TARGET_AI ? game.getPlayers().get(1) : game.getPlayers().get(0);
|
||||
|
||||
attacher.enchantEntity(attachedTo);
|
||||
attacher.attachToEntity(attachedTo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1004,6 +988,12 @@ public abstract class GameState {
|
||||
private void setupPlayerState(int life, Map<ZoneType, String> cardTexts, final Player p, final int landsPlayed, final int landsPlayedLastTurn) {
|
||||
// Lock check static as we setup player state
|
||||
|
||||
// Clear all zones first, this ensures that any lingering cards and effects (e.g. in command zone) get cleared up
|
||||
// before setting up a new state
|
||||
for (ZoneType zt : ZONES.keySet()) {
|
||||
p.getZone(zt).removeAllCards(true);
|
||||
}
|
||||
|
||||
Map<ZoneType, CardCollectionView> playerCards = new EnumMap<ZoneType, CardCollectionView>(ZoneType.class);
|
||||
for (Entry<ZoneType, String> kv : cardTexts.entrySet()) {
|
||||
String value = kv.getValue();
|
||||
@@ -1037,7 +1027,9 @@ public abstract class GameState {
|
||||
if (c.isAura()) {
|
||||
// dummy "enchanting" to indicate that the card will be force-attached elsewhere
|
||||
// (will be overridden later, so the actual value shouldn't matter)
|
||||
c.setEnchanting(c);
|
||||
|
||||
//FIXME it shouldn't be able to attach itself
|
||||
c.setEntityAttachedTo(c);
|
||||
}
|
||||
|
||||
if (cardsWithoutETBTrigs.contains(c)) {
|
||||
@@ -1134,7 +1126,7 @@ public abstract class GameState {
|
||||
} else if (info.startsWith("Id:")) {
|
||||
int id = Integer.parseInt(info.substring(3));
|
||||
idToCard.put(id, c);
|
||||
} else if (info.startsWith("Attaching:")) {
|
||||
} else if (info.startsWith("Attaching:") /*deprecated*/ || info.startsWith("AttachedTo:")) {
|
||||
int id = Integer.parseInt(info.substring(info.indexOf(':') + 1));
|
||||
cardToAttachId.put(c, id);
|
||||
} else if (info.startsWith("EnchantingPlayer:")) {
|
||||
|
||||
@@ -162,10 +162,36 @@ public class PlayerControllerAi extends PlayerController {
|
||||
|
||||
@Override
|
||||
public <T extends GameEntity> List<T> chooseEntitiesForEffect(
|
||||
FCollectionView<T> optionList, DelayedReveal delayedReveal, SpellAbility sa, String title,
|
||||
FCollectionView<T> optionList, int min, int max, DelayedReveal delayedReveal, SpellAbility sa, String title,
|
||||
Player targetedPlayer) {
|
||||
// this isn't used
|
||||
return null;
|
||||
if (delayedReveal != null) {
|
||||
reveal(delayedReveal.getCards(), delayedReveal.getZone(), delayedReveal.getOwner(), delayedReveal.getMessagePrefix());
|
||||
}
|
||||
FCollection<T> remaining = new FCollection<T>(optionList);
|
||||
List<T> selecteds = new ArrayList<T>();
|
||||
T selected;
|
||||
do {
|
||||
selected = chooseSingleEntityForEffect(remaining, null, sa, title, selecteds.size()>=min, targetedPlayer);
|
||||
if ( selected != null ) {
|
||||
remaining.remove(selected);
|
||||
selecteds.add(selected);
|
||||
}
|
||||
} while ( (selected != null ) && (selecteds.size() < max) );
|
||||
return selecteds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends GameEntity> List<T> chooseFromTwoListsForEffect(FCollectionView<T> optionList1, FCollectionView<T> optionList2,
|
||||
boolean optional, DelayedReveal delayedReveal, SpellAbility sa, String title, Player targetedPlayer) {
|
||||
if (delayedReveal != null) {
|
||||
reveal(delayedReveal.getCards(), delayedReveal.getZone(), delayedReveal.getOwner(), delayedReveal.getMessagePrefix());
|
||||
}
|
||||
T selected1 = chooseSingleEntityForEffect(optionList1, null, sa, title, optional, targetedPlayer);
|
||||
T selected2 = chooseSingleEntityForEffect(optionList2, null, sa, title, optional || selected1!=null, targetedPlayer);
|
||||
List<T> selecteds = new ArrayList<T>();
|
||||
if ( selected1 != null ) { selecteds.add(selected1); }
|
||||
if ( selected2 != null ) { selecteds.add(selected2); }
|
||||
return selecteds;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -303,7 +329,7 @@ public class PlayerControllerAi extends PlayerController {
|
||||
|
||||
// TODO: Currently this logic uses the same routine as Scry. Possibly differentiate this and implement
|
||||
// a specific logic for Surveil (e.g. maybe to interact better with Reanimator strategies etc.).
|
||||
if (getPlayer().getCardsIn(ZoneType.Hand).size() <= getAi().getIntProperty(AiProps.SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL)) {
|
||||
if (getPlayer().getCardsIn(ZoneType.Library).size() <= getAi().getIntProperty(AiProps.SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL)) {
|
||||
toTop.addAll(topN);
|
||||
} else {
|
||||
for (Card c : topN) {
|
||||
@@ -331,8 +357,12 @@ public class PlayerControllerAi extends PlayerController {
|
||||
public CardCollectionView orderMoveToZoneList(CardCollectionView cards, ZoneType destinationZone, SpellAbility source) {
|
||||
//TODO Add more logic for AI ordering here
|
||||
|
||||
// In presence of Volrath's Shapeshifter in deck, try to place the best creature on top of the graveyard
|
||||
if (cards.isEmpty()) {
|
||||
return cards;
|
||||
}
|
||||
|
||||
if (destinationZone == ZoneType.Graveyard) {
|
||||
// In presence of Volrath's Shapeshifter in deck, try to place the best creature on top of the graveyard
|
||||
if (!CardLists.filter(game.getCardsInGame(), new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card card) {
|
||||
@@ -362,6 +392,61 @@ public class PlayerControllerAi extends PlayerController {
|
||||
return reordered;
|
||||
}
|
||||
}
|
||||
} else if (destinationZone == ZoneType.Library) {
|
||||
// Ponder and similar cards
|
||||
Player p = cards.getFirst().getController(); // whose library are we reordering?
|
||||
CardCollection reordered = new CardCollection();
|
||||
|
||||
// Try to use the Scry logic to figure out what should be closer to the top and what should be closer to the bottom
|
||||
CardCollection topLands = new CardCollection(), topNonLands = new CardCollection(), bottom = new CardCollection();
|
||||
for (Card c : cards) {
|
||||
if (ComputerUtil.scryWillMoveCardToBottomOfLibrary(p, c)) {
|
||||
bottom.add(c);
|
||||
} else {
|
||||
if (c.isLand()) {
|
||||
topLands.add(c);
|
||||
} else {
|
||||
topNonLands.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int landsOTB = CardLists.filter(p.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.LANDS_PRODUCING_MANA).size();
|
||||
|
||||
if (!p.isOpponentOf(player)) {
|
||||
if (landsOTB <= 2) {
|
||||
// too few lands, add all the lands from the "top" category first
|
||||
reordered.addAll(topLands);
|
||||
topLands.clear();
|
||||
} else {
|
||||
// we would have scried a land to top, so add one land from the "top" category if it's available there, but not more
|
||||
if (!topLands.isEmpty()) {
|
||||
Card first = topLands.getFirst();
|
||||
reordered.add(first);
|
||||
topLands.remove(first);
|
||||
}
|
||||
}
|
||||
// add everything that was deemed playable
|
||||
reordered.addAll(topNonLands);
|
||||
// then all the land extras that may be there
|
||||
reordered.addAll(topLands);
|
||||
// and then everything else that was deemed unplayable and thus scriable to the bottom
|
||||
reordered.addAll(bottom);
|
||||
} else {
|
||||
// try to screw the opponent up as much as possible by placing the uncastables first
|
||||
reordered.addAll(bottom);
|
||||
if (landsOTB <= 5) {
|
||||
reordered.addAll(topNonLands);
|
||||
reordered.addAll(topLands);
|
||||
} else {
|
||||
reordered.addAll(topLands);
|
||||
reordered.addAll(topNonLands);
|
||||
}
|
||||
}
|
||||
|
||||
assert(reordered.size() == cards.size());
|
||||
|
||||
return reordered;
|
||||
}
|
||||
|
||||
// Default: return with the same order as was passed into this method
|
||||
@@ -1031,7 +1116,7 @@ public class PlayerControllerAi extends PlayerController {
|
||||
|
||||
@Override
|
||||
public List<Card> chooseCardsForZoneChange(
|
||||
ZoneType destination, List<ZoneType> origin, SpellAbility sa, CardCollection fetchList,
|
||||
ZoneType destination, List<ZoneType> origin, SpellAbility sa, CardCollection fetchList, int min, int max,
|
||||
DelayedReveal delayedReveal, String selectPrompt, Player decider) {
|
||||
// this isn't used
|
||||
return null;
|
||||
@@ -1088,9 +1173,27 @@ public class PlayerControllerAi extends PlayerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OptionalCostValue> chooseOptionalCosts(SpellAbility choosen,
|
||||
public List<OptionalCostValue> chooseOptionalCosts(SpellAbility chosen,
|
||||
List<OptionalCostValue> optionalCostValues) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
List<OptionalCostValue> chosenOptCosts = Lists.newArrayList();
|
||||
Cost costSoFar = chosen.getPayCosts() != null ? chosen.getPayCosts().copy() : Cost.Zero;
|
||||
|
||||
for (OptionalCostValue opt : optionalCostValues) {
|
||||
// Choose the optional cost if it can be paid (to be improved later, check for playability and other conditions perhaps)
|
||||
Cost fullCost = opt.getCost().copy().add(costSoFar);
|
||||
SpellAbility fullCostSa = chosen.copyWithDefinedCost(fullCost);
|
||||
if (ComputerUtilCost.canPayCost(fullCostSa, player)) {
|
||||
chosenOptCosts.add(opt);
|
||||
costSoFar.add(opt.getCost());
|
||||
}
|
||||
}
|
||||
|
||||
return chosenOptCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean confirmMulliganScry(Player p) {
|
||||
// Always true?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -677,6 +677,14 @@ public class SpecialCardAi {
|
||||
// Living Death (and other similar cards using AILogic LivingDeath or AILogic ReanimateAll)
|
||||
public static class LivingDeath {
|
||||
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||
// if there's another reanimator card currently suspended, don't cast a new one until the previous
|
||||
// one resolves, otherwise the reanimation attempt will be ruined (e.g. Living End)
|
||||
for (Card ex : ai.getCardsIn(ZoneType.Exile)) {
|
||||
if (ex.hasSVar("IsReanimatorCard") && ex.getCounters(CounterType.TIME) > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int aiBattlefieldPower = 0, aiGraveyardPower = 0;
|
||||
int threshold = 320; // approximately a 4/4 Flying creature worth of extra value
|
||||
|
||||
@@ -821,6 +829,10 @@ public class SpecialCardAi {
|
||||
int computerHandSize = ai.getZone(ZoneType.Hand).size();
|
||||
int maxHandSize = ai.getMaxHandSize();
|
||||
|
||||
if (ai.getCardsIn(ZoneType.Library).isEmpty()) {
|
||||
return false; // nothing to draw from the library
|
||||
}
|
||||
|
||||
if (!CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Yawgmoth's Bargain")).isEmpty()) {
|
||||
// Prefer Yawgmoth's Bargain because AI is generally better with it
|
||||
|
||||
@@ -1337,6 +1349,10 @@ public class SpecialCardAi {
|
||||
Game game = ai.getGame();
|
||||
PhaseHandler ph = game.getPhaseHandler();
|
||||
|
||||
if (ai.getCardsIn(ZoneType.Library).isEmpty()) {
|
||||
return false; // nothing to draw from the library
|
||||
}
|
||||
|
||||
int computerHandSize = ai.getZone(ZoneType.Hand).size();
|
||||
int maxHandSize = ai.getMaxHandSize();
|
||||
|
||||
|
||||
@@ -76,6 +76,13 @@ public abstract class SpellAbilityAi {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (sa.hasParam("AITgtBeforeCostEval")) {
|
||||
// Cost payment requires a valid target to be specified, e.g. Quillmane Baku, so run the API logic first
|
||||
// to set the target, then decide on paying costs (slower, so only use for cards where it matters)
|
||||
return checkApiLogic(ai, sa) && (cost == null || willPayCosts(ai, sa, cost, source));
|
||||
}
|
||||
|
||||
if (cost != null && !willPayCosts(ai, sa, cost, source)) {
|
||||
return false;
|
||||
}
|
||||
@@ -169,7 +176,7 @@ public abstract class SpellAbilityAi {
|
||||
|
||||
public final boolean doTriggerNoCostWithSubs(final Player aiPlayer, final SpellAbility sa, final boolean mandatory)
|
||||
{
|
||||
if (!doTriggerAINoCost(aiPlayer, sa, mandatory)) {
|
||||
if (!doTriggerAINoCost(aiPlayer, sa, mandatory) && !"Always".equals(sa.getParam("AILogic"))) {
|
||||
return false;
|
||||
}
|
||||
final AbilitySub subAb = sa.getSubAbility();
|
||||
@@ -238,8 +245,8 @@ public abstract class SpellAbilityAi {
|
||||
* @return a boolean.
|
||||
*/
|
||||
protected static boolean isSorcerySpeed(final SpellAbility sa) {
|
||||
return (sa.isSpell() && sa.getHostCard().isSorcery())
|
||||
|| (sa.isAbility() && sa.getRestrictions().isSorcerySpeed())
|
||||
return (sa.getRootAbility().isSpell() && sa.getHostCard().isSorcery())
|
||||
|| (sa.getRootAbility().isAbility() && sa.getRestrictions().isSorcerySpeed())
|
||||
|| (sa.getRestrictions().isPwAbility() && !sa.getHostCard().hasKeyword("CARDNAME's loyalty abilities can be activated at instant speed."));
|
||||
}
|
||||
|
||||
|
||||
@@ -149,15 +149,15 @@ public class AnimateAi extends SpellAbilityAi {
|
||||
if (!bFlag && c.isCreature() && (sa.hasParam("Permanent") || (!c.isTapped() && !c.isSick()))) {
|
||||
int power = -5;
|
||||
if (sa.hasParam("Power")) {
|
||||
power = AbilityUtils.calculateAmount(source, sa.getParam("Power"), sa);
|
||||
power = AbilityUtils.calculateAmount(c, sa.getParam("Power"), sa);
|
||||
}
|
||||
int toughness = -5;
|
||||
if (sa.hasParam("Toughness")) {
|
||||
toughness = AbilityUtils.calculateAmount(source, sa.getParam("Toughness"), sa);
|
||||
toughness = AbilityUtils.calculateAmount(c, sa.getParam("Toughness"), sa);
|
||||
}
|
||||
if (sa.hasParam("Keywords")) {
|
||||
for (String keyword : sa.getParam("Keywords").split(" & ")) {
|
||||
if (!source.hasKeyword(keyword)) {
|
||||
if (!c.hasKeyword(keyword)) {
|
||||
bFlag = true;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ public class AnimateAi extends SpellAbilityAi {
|
||||
if (animatedCopy.getCurrentPower() + animatedCopy.getCurrentToughness() >
|
||||
c.getCurrentPower() + c.getCurrentToughness()) {
|
||||
if (!isAnimatedThisTurn(aiPlayer, sa.getHostCard())) {
|
||||
if (!sa.getHostCard().isTapped() || (game.getCombat() != null && game.getCombat().isAttacking(sa.getHostCard()))) {
|
||||
if (!c.isTapped() || (game.getCombat() != null && game.getCombat().isAttacking(c))) {
|
||||
bFlag = true;
|
||||
}
|
||||
}
|
||||
@@ -342,7 +342,7 @@ public class AnimateAi extends SpellAbilityAi {
|
||||
|
||||
// This is reasonable for now. Kamahl, Fist of Krosa and a sorcery or
|
||||
// two are the only things
|
||||
// that animate a target. Those can just use SVar:RemAIDeck:True until
|
||||
// that animate a target. Those can just use AI:RemoveDeck:All until
|
||||
// this can do a reasonably
|
||||
// good job of picking a good target
|
||||
return false;
|
||||
|
||||
@@ -2,8 +2,12 @@ package forge.ai.ability;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import forge.ai.*;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.GlobalRuleChange;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
@@ -19,11 +23,13 @@ import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellPermanent;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -56,6 +62,16 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
|
||||
if (!ai.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)
|
||||
&& source.getType().isLegendary() && sa instanceof SpellPermanent
|
||||
&& ai.isCardInPlay(source.getName())) {
|
||||
// Don't play the second copy of a legendary enchantment already in play
|
||||
|
||||
// TODO: Add some extra checks for where the AI may want to cast a replacement aura
|
||||
// on another creature and keep it when the original enchanted creature is useless
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
||||
&& !"Curse".equals(sa.getParam("AILogic"))) {
|
||||
return false;
|
||||
@@ -75,6 +91,15 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
|
||||
// Flash logic
|
||||
boolean advancedFlash = false;
|
||||
if (ai.getController().isAI()) {
|
||||
advancedFlash = ((PlayerControllerAi)ai.getController()).getAi().getBooleanProperty(AiProps.FLASH_ENABLE_ADVANCED_LOGIC);
|
||||
}
|
||||
if (source.withFlash(ai) && source.isAura() && advancedFlash && !doAdvancedFlashAuraLogic(ai, sa, sa.getTargetCard())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (abCost.getTotalMana().countX() > 0 && source.getSVar("X").equals("Count$xPaid")) {
|
||||
// Set PayX here to maximum value. (Endless Scream and Venarian
|
||||
// Gold)
|
||||
@@ -102,13 +127,129 @@ public class AttachAi extends SpellAbilityAi {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean doAdvancedFlashAuraLogic(Player ai, SpellAbility sa, Card attachTarget) {
|
||||
Card source = sa.getHostCard();
|
||||
Game game = ai.getGame();
|
||||
Combat combat = game.getCombat();
|
||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||
|
||||
if (!aic.getBooleanProperty(AiProps.FLASH_USE_BUFF_AURAS_AS_COMBAT_TRICKS)) {
|
||||
// Currently this only works with buff auras, so if the relevant toggle is disabled, just return true
|
||||
// for instant speed use. To be improved later.
|
||||
return true;
|
||||
}
|
||||
|
||||
int power = 0, toughness = 0;
|
||||
List<String> keywords = Lists.newArrayList();
|
||||
for (StaticAbility stAb : source.getStaticAbilities()) {
|
||||
if ("Continuous".equals(stAb.getParam("Mode"))) {
|
||||
if (stAb.hasParam("AddPower")) {
|
||||
power += AbilityUtils.calculateAmount(source, stAb.getParam("AddPower"), stAb);
|
||||
}
|
||||
if (stAb.hasParam("AddToughness")) {
|
||||
toughness += AbilityUtils.calculateAmount(source, stAb.getParam("AddToughness"), stAb);
|
||||
}
|
||||
if (stAb.hasParam("AddKeyword")) {
|
||||
keywords.addAll(Lists.newArrayList(stAb.getParam("AddKeyword").split(" & ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean isBuffAura = !sa.isCurse() && (power > 0 || toughness > 0 || !keywords.isEmpty());
|
||||
if (!isBuffAura) {
|
||||
// Currently only works with buff auras, otherwise returns true for instant speed use. To be improved later.
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean canRespondToStack = false;
|
||||
if (!game.getStack().isEmpty()) {
|
||||
SpellAbility peekSa = game.getStack().peekAbility();
|
||||
Player activator = peekSa.getActivatingPlayer();
|
||||
if (activator != null && activator.isOpponentOf(ai)
|
||||
&& (!peekSa.usesTargeting() || peekSa.getTargets().getTargetCards().contains(attachTarget))) {
|
||||
if (peekSa.getApi() == ApiType.DealDamage || peekSa.getApi() == ApiType.DamageAll) {
|
||||
int dmg = AbilityUtils.calculateAmount(peekSa.getHostCard(), peekSa.getParam("NumDmg"), peekSa);
|
||||
if (dmg < toughness + attachTarget.getNetToughness()) {
|
||||
canRespondToStack = true;
|
||||
}
|
||||
} else if (peekSa.getApi() == ApiType.Destroy || peekSa.getApi() == ApiType.DestroyAll) {
|
||||
if (!attachTarget.hasKeyword(Keyword.INDESTRUCTIBLE) && !ComputerUtil.canRegenerate(ai, attachTarget)
|
||||
&& keywords.contains("Indestructible")) {
|
||||
canRespondToStack = true;
|
||||
}
|
||||
} else if (peekSa.getApi() == ApiType.Pump || peekSa.getApi() == ApiType.PumpAll) {
|
||||
int p = AbilityUtils.calculateAmount(peekSa.getHostCard(), peekSa.getParam("NumAtt"), peekSa);
|
||||
int t = AbilityUtils.calculateAmount(peekSa.getHostCard(), peekSa.getParam("NumDef"), peekSa);
|
||||
if (t < 0 && toughness > 0 && attachTarget.getNetToughness() + t + toughness > 0) {
|
||||
canRespondToStack = true;
|
||||
} else if (p < 0 && power > 0 && attachTarget.getNetPower() + p + power > 0
|
||||
&& attachTarget.getNetToughness() + t + toughness > 0) {
|
||||
// Yep, still need to ensure that the net toughness will be positive here even if buffing for power
|
||||
canRespondToStack = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean canSurviveCombat = true;
|
||||
if (combat != null && combat.isBlocked(attachTarget)) {
|
||||
if (!attachTarget.hasKeyword(Keyword.INDESTRUCTIBLE) && !ComputerUtil.canRegenerate(ai, attachTarget)) {
|
||||
boolean dangerous = false;
|
||||
int totalAtkPower = 0;
|
||||
for (Card attacker : combat.getBlockers(attachTarget)) {
|
||||
if (attacker.hasKeyword(Keyword.DEATHTOUCH) || attacker.hasKeyword(Keyword.INFECT)
|
||||
|| attacker.hasKeyword(Keyword.WITHER)) {
|
||||
dangerous = true;
|
||||
}
|
||||
totalAtkPower += attacker.getNetPower();
|
||||
}
|
||||
if (totalAtkPower > attachTarget.getNetToughness() + toughness || dangerous) {
|
||||
canSurviveCombat = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!canSurviveCombat || (attachTarget.isCreature() && ComputerUtilCard.isUselessCreature(ai, attachTarget))) {
|
||||
// don't buff anything that will die or get seriously crippled in combat, it's pointless anyway
|
||||
return false;
|
||||
}
|
||||
|
||||
int chanceToCastAtEOT = aic.getIntProperty(AiProps.FLASH_BUFF_AURA_CHANCE_CAST_AT_EOT);
|
||||
int chanceToCastEarly = aic.getIntProperty(AiProps.FLASH_BUFF_AURA_CHANCE_TO_CAST_EARLY);
|
||||
int chanceToRespondToStack = aic.getIntProperty(AiProps.FLASH_BUFF_AURA_CHANCE_TO_RESPOND_TO_STACK);
|
||||
|
||||
boolean hasFloatMana = ai.getManaPool().totalMana() > 0;
|
||||
boolean willDiscardNow = game.getPhaseHandler().is(PhaseType.END_OF_TURN, ai)
|
||||
&& ai.getCardsIn(ZoneType.Hand).size() > ai.getMaxHandSize();
|
||||
boolean willDieNow = combat != null && ComputerUtilCombat.lifeInSeriousDanger(ai, combat);
|
||||
boolean willRespondToStack = canRespondToStack && MyRandom.percentTrue(chanceToRespondToStack);
|
||||
boolean willCastEarly = MyRandom.percentTrue(chanceToCastEarly);
|
||||
boolean willCastAtEOT = game.getPhaseHandler().is(PhaseType.END_OF_TURN)
|
||||
&& game.getPhaseHandler().getNextTurn().equals(ai) && MyRandom.percentTrue(chanceToCastAtEOT);
|
||||
|
||||
boolean alternativeConsiderations = hasFloatMana || willDiscardNow || willDieNow || willRespondToStack || willCastAtEOT || willCastEarly;
|
||||
|
||||
if (!alternativeConsiderations) {
|
||||
if (combat == null ||
|
||||
game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(combat.isAttacking(attachTarget) || combat.isBlocking(attachTarget))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acceptable choice.
|
||||
*
|
||||
*
|
||||
* @param c
|
||||
* the c
|
||||
* @param mandatory
|
||||
@@ -133,7 +274,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Choose unpreferred.
|
||||
*
|
||||
*
|
||||
* @param mandatory
|
||||
* the mandatory
|
||||
* @param list
|
||||
@@ -150,7 +291,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Choose less preferred.
|
||||
*
|
||||
*
|
||||
* @param mandatory
|
||||
* the mandatory
|
||||
* @param list
|
||||
@@ -167,7 +308,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach ai change type preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -198,7 +339,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
list = CardLists.getNotType(list, type); // Filter out Basic Lands that have the same type as the changing type
|
||||
|
||||
|
||||
// Don't target fetchlands
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
@@ -239,7 +380,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach ai keep tapped preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -276,7 +417,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Iterable<Card> auras = c.getEnchantedBy(false);
|
||||
final Iterable<Card> auras = c.getEnchantedBy();
|
||||
final Iterator<Card> itr = auras.iterator();
|
||||
while (itr.hasNext()) {
|
||||
final Card aura = itr.next();
|
||||
@@ -367,7 +508,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach ai control preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -438,7 +579,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
c = ComputerUtilCard.getWorstAI(betterList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If Mandatory (brought directly into play without casting) gotta
|
||||
// choose something
|
||||
@@ -451,7 +592,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach ai reanimate preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -465,8 +606,40 @@ public class AttachAi extends SpellAbilityAi {
|
||||
private static Card attachAIReanimatePreference(final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
||||
final Card attachSource) {
|
||||
// AI For choosing a Card to Animate.
|
||||
// TODO Add some more restrictions for Reanimation Auras
|
||||
final Card c = ComputerUtilCard.getBestCreatureAI(list);
|
||||
final Player ai = sa.getActivatingPlayer();
|
||||
final Card attachSourceLki = CardUtil.getLKICopy(attachSource);
|
||||
attachSourceLki.setLastKnownZone(ai.getZone(ZoneType.Battlefield));
|
||||
// Suppress original attach Spell to replace it with another
|
||||
attachSourceLki.getFirstAttachSpell().setSuppressed(true);
|
||||
|
||||
//TODO for Reanimate Auras i need the new Attach Spell, in later versions it might be part of the Enchant Keyword
|
||||
attachSourceLki.addSpellAbility(AbilityFactory.getAbility(attachSourceLki, "NewAttach"));
|
||||
List<Card> betterList = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
final Card lki = CardUtil.getLKICopy(c);
|
||||
// need to fake it as if lki would be on the battlefield
|
||||
lki.setLastKnownZone(ai.getZone(ZoneType.Battlefield));
|
||||
|
||||
// Reanimate Auras use "Enchant creature put onto the battlefield with CARDNAME" with Remembered
|
||||
attachSourceLki.clearRemembered();
|
||||
attachSourceLki.addRemembered(lki);
|
||||
|
||||
// need to check what the cards would be on the battlefield
|
||||
// do not attach yet, that would cause Events
|
||||
CardCollection preList = new CardCollection(lki);
|
||||
preList.add(attachSourceLki);
|
||||
c.getGame().getAction().checkStaticAbilities(false, Sets.newHashSet(preList), preList);
|
||||
boolean result = lki.canBeAttached(attachSourceLki);
|
||||
|
||||
//reset static abilities
|
||||
c.getGame().getAction().checkStaticAbilities(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
final Card c = ComputerUtilCard.getBestCreatureAI(betterList);
|
||||
|
||||
// If Mandatory (brought directly into play without casting) gotta
|
||||
// choose something
|
||||
@@ -538,7 +711,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
/**
|
||||
* Attach ai specific card preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -555,7 +728,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
final Player ai = sa.getActivatingPlayer();
|
||||
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
||||
Card chosen = null;
|
||||
|
||||
|
||||
if ("Guilty Conscience".equals(sourceName)) {
|
||||
chosen = SpecialCardAi.GuiltyConscience.getBestAttachTarget(ai, sa, list);
|
||||
} else if ("Bonds of Faith".equals(sourceName)) {
|
||||
@@ -614,7 +787,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
// Should generalize this code a bit since they all have similar structures
|
||||
/**
|
||||
* Attach ai control preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -650,7 +823,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach ai highest evaluated preference.
|
||||
*
|
||||
*
|
||||
* @param list the initial valid list
|
||||
* @return the card
|
||||
*/
|
||||
@@ -660,7 +833,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach ai curse preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -784,7 +957,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
* the sa
|
||||
* @param mandatory
|
||||
* the mandatory
|
||||
*
|
||||
*
|
||||
* @return true, if successful
|
||||
*/
|
||||
@Override
|
||||
@@ -854,7 +1027,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach ai pump preference.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -905,8 +1078,36 @@ public class AttachAi extends SpellAbilityAi {
|
||||
});
|
||||
}
|
||||
|
||||
// Look for triggers that will damage the creature and remove AI-owned creatures that will die
|
||||
CardCollection toRemove = new CardCollection();
|
||||
for (Trigger t : attachSource.getTriggers()) {
|
||||
if (t.getMode() == TriggerType.ChangesZone) {
|
||||
final Map<String, String> params = t.getMapParams();
|
||||
if ("Card.Self".equals(params.get("ValidCard"))
|
||||
&& "Battlefield".equals(params.get("Destination"))) {
|
||||
SpellAbility trigSa = null;
|
||||
if (t.hasParam("Execute") && attachSource.hasSVar(t.getParam("Execute"))) {
|
||||
trigSa = AbilityFactory.getAbility(attachSource.getSVar(params.get("Execute")), attachSource);
|
||||
} else if (t.getOverridingAbility() != null) {
|
||||
trigSa = t.getOverridingAbility();
|
||||
}
|
||||
if (trigSa != null && trigSa.getApi() == ApiType.DealDamage && "Enchanted".equals(trigSa.getParam("Defined"))) {
|
||||
for (Card target : list) {
|
||||
if (!target.getController().isOpponentOf(ai)) {
|
||||
int numDmg = AbilityUtils.calculateAmount(target, trigSa.getParam("NumDmg"), trigSa);
|
||||
if (target.getNetToughness() - target.getDamage() <= numDmg && !target.hasKeyword(Keyword.INDESTRUCTIBLE)) {
|
||||
toRemove.add(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
list.removeAll(toRemove);
|
||||
|
||||
if (magnetList != null) {
|
||||
|
||||
|
||||
// Look for Heroic triggers
|
||||
if (magnetList.isEmpty() && sa.isSpell()) {
|
||||
for (Card target : list) {
|
||||
@@ -921,7 +1122,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!magnetList.isEmpty()) {
|
||||
// Always choose something from the Magnet List.
|
||||
// Probably want to "weight" the list by amount of Enchantments and
|
||||
@@ -992,6 +1193,10 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
CardCollection prefList = new CardCollection(list);
|
||||
|
||||
// Filter AI-specific targets if provided
|
||||
prefList = ComputerUtil.filterAITgts(sa, ai, (CardCollection)list, false);
|
||||
|
||||
if (totToughness < 0) {
|
||||
// Don't kill my own stuff with Negative toughness Auras
|
||||
final int tgh = totToughness;
|
||||
@@ -1092,7 +1297,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach to card ai preferences.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param sa
|
||||
@@ -1111,8 +1316,15 @@ public class AttachAi extends SpellAbilityAi {
|
||||
if (attachSource.hasSVar("DontEquip")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// is no attachment so no using attach
|
||||
if (!attachSource.isAttachment()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't fortify if already fortifying
|
||||
if (attachSource.getFortifying() != null && attachSource.getFortifying().getController() == aiPlayer) {
|
||||
if (attachSource.isFortification() && attachSource.getAttachedTo() != null
|
||||
&& attachSource.getAttachedTo().getController() == aiPlayer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1122,11 +1334,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
} else {
|
||||
list = CardLists.getValidCards(aiPlayer.getGame().getCardsIn(tgt.getZone()), tgt.getValidTgts(), sa.getActivatingPlayer(), attachSource, sa);
|
||||
|
||||
if (attachSource.isAura()) {
|
||||
list = CardLists.filter(list, CardPredicates.canBeEnchantedBy(attachSource));
|
||||
} else if (attachSource.isEquipment()) {
|
||||
list = CardLists.filter(list, CardPredicates.canBeEquippedBy(attachSource));
|
||||
}
|
||||
list = CardLists.filter(list, CardPredicates.canBeAttached(attachSource));
|
||||
|
||||
// TODO If Attaching without casting, don't need to actually target.
|
||||
// I believe this is the only case where mandatory will be true, so just
|
||||
@@ -1150,7 +1358,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
Card c = attachGeneralAI(aiPlayer, sa, prefList, mandatory, attachSource, sa.getParam("AILogic"));
|
||||
|
||||
AiController aic = ((PlayerControllerAi)aiPlayer.getController()).getAi();
|
||||
if (c != null && attachSource.isEquipment()
|
||||
if (c != null && attachSource.isEquipment()
|
||||
&& attachSource.isEquipping()
|
||||
&& attachSource.getEquipping().getController() == aiPlayer) {
|
||||
if (c.equals(attachSource.getEquipping())) {
|
||||
@@ -1174,7 +1382,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// make sure to prioritize casting spells in main 2 (creatures, other equipment, etc.) rather than moving equipment around
|
||||
boolean decideMoveFromUseless = uselessCreature && aic.getBooleanProperty(AiProps.PRIORITIZE_MOVE_EQUIPMENT_IF_USELESS);
|
||||
|
||||
@@ -1188,7 +1396,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
// avoid randomly moving the equipment back and forth between several creatures in one turn
|
||||
if (AiCardMemory.isRememberedCard(aiPlayer, sa.getHostCard(), AiCardMemory.MemorySet.ATTACHED_THIS_TURN)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// do not equip if the new creature is not significantly better than the previous one (evaluates at least better by evalT)
|
||||
int evalT = aic.getIntProperty(AiProps.MOVE_EQUIPMENT_CREATURE_EVAL_THRESHOLD);
|
||||
@@ -1196,7 +1404,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AiCardMemory.rememberCard(aiPlayer, sa.getHostCard(), AiCardMemory.MemorySet.ATTACHED_THIS_TURN);
|
||||
|
||||
if (c == null && mandatory) {
|
||||
@@ -1208,7 +1416,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Attach general ai.
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* the sa
|
||||
* @param list
|
||||
@@ -1284,7 +1492,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Contains useful curse keyword.
|
||||
*
|
||||
*
|
||||
* @param keywords
|
||||
* the keywords
|
||||
* @param card
|
||||
@@ -1303,7 +1511,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Checks if is useful keyword.
|
||||
*
|
||||
*
|
||||
* @param keyword
|
||||
* the keyword
|
||||
* @param card
|
||||
@@ -1314,7 +1522,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
private static boolean isUsefulAttachKeyword(final String keyword, final Card card, final SpellAbility sa, final int powerBonus) {
|
||||
final Player ai = sa.getActivatingPlayer();
|
||||
final PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||
|
||||
|
||||
if (!CardUtil.isStackingKeyword(keyword) && card.hasKeyword(keyword)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1327,7 +1535,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
return false;
|
||||
}
|
||||
// Also don't play if it would destroy own Aura
|
||||
for (Card c : card.getEnchantedBy(false)) {
|
||||
for (Card c : card.getEnchantedBy()) {
|
||||
if ((c.getController().equals(ai)) && (c.isOfColor(cc))) {
|
||||
return false;
|
||||
}
|
||||
@@ -1433,7 +1641,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Checks if is useful curse keyword.
|
||||
*
|
||||
*
|
||||
* @param keyword
|
||||
* the keyword
|
||||
* @param card
|
||||
@@ -1486,15 +1694,15 @@ public class AttachAi extends SpellAbilityAi {
|
||||
|
||||
/**
|
||||
* Checks if it is useful to execute the attach action given the current context.
|
||||
*
|
||||
*
|
||||
* @param c
|
||||
* the card
|
||||
* @param sa SpellAbility
|
||||
* @return true, if the action is useful (beneficial) in the current minimal context (Card vs. Attach SpellAbility)
|
||||
* @return true, if the action is useful (beneficial) in the current minimal context (Card vs. Attach SpellAbility)
|
||||
*/
|
||||
private static boolean isUsefulAttachAction(Player ai, Card c, SpellAbility sa) {
|
||||
if (c == null) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (sa.getHostCard() == null) {
|
||||
// FIXME: Not sure what should the resolution be if a SpellAbility has no host card. This should
|
||||
@@ -1552,12 +1760,12 @@ public class AttachAi extends SpellAbilityAi {
|
||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Card chooseSingleCard(Player ai, SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer) {
|
||||
return attachToCardAIPreferences(ai, sa, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Player chooseSinglePlayer(Player ai, SpellAbility sa, Iterable<Player> options) {
|
||||
return attachToPlayerAIPreferences(ai, sa, true);
|
||||
|
||||
@@ -159,7 +159,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
return true; // debuffed by opponent's auras to the level that it becomes useless
|
||||
}
|
||||
int delta = 0;
|
||||
for (Card enc : sa.getHostCard().getEnchantedBy(false)) {
|
||||
for (Card enc : sa.getHostCard().getEnchantedBy()) {
|
||||
if (enc.getController().isOpponentOf(aiPlayer)) {
|
||||
delta--;
|
||||
} else {
|
||||
@@ -251,6 +251,10 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
if (ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DAMAGE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ai.getGame().getCombat() == null) {
|
||||
return false;
|
||||
}
|
||||
List<Card> attackers = ai.getGame().getCombat().getUnblockedAttackers();
|
||||
boolean lowerCMC = false;
|
||||
for (Card attacker : attackers) {
|
||||
@@ -957,7 +961,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
for (Card aura : c.getEnchantedBy()) {
|
||||
if (aura.getController().isOpponentOf(ai)) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -1050,7 +1054,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
for (Card aura : c.getEnchantedBy()) {
|
||||
if (c.getOwner().isOpponentOf(ai) && aura.getController().equals(ai)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1459,7 +1463,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
fetchList = CardLists.filter(fetchList, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
if (c.hasSVar("RemAIDeck") || c.hasSVar("RemRandomDeck")) {
|
||||
if (ComputerUtilCard.isCardRemAIDeck(c) || ComputerUtilCard.isCardRemRandomDeck(c)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1729,7 +1733,12 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
Map<String, Object> originalParams = (Map<String, Object>)sa.getReplacingObject("OriginalParams");
|
||||
SpellAbility causeSa = (SpellAbility)originalParams.get("Cause");
|
||||
SpellAbility causeSub = null;
|
||||
|
||||
|
||||
// Squee, the Immortal: easier to recast it (the call below has to be "contains" since SA is an intrinsic effect)
|
||||
if (sa.getHostCard().getName().contains("Squee, the Immortal")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (causeSa != null && (causeSub = causeSa.getSubAbility()) != null) {
|
||||
ApiType subApi = causeSub.getApi();
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
// spBounceAll has some AI we can compare to.
|
||||
if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) {
|
||||
if (!sa.usesTargeting()) {
|
||||
// TODO: improve logic for non-targeted SAs of this type (most are currently RemAIDeck, e.g. Memory Jar)
|
||||
// TODO: improve logic for non-targeted SAs of this type (most are currently AI:RemoveDeck:All, e.g. Memory Jar)
|
||||
return true;
|
||||
} else {
|
||||
// search targetable Opponents
|
||||
@@ -220,6 +220,9 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (destination.equals(ZoneType.Library) && "Card.YouOwn".equals(sa.getParam("ChangeType"))) {
|
||||
return (ai.getCardsIn(ZoneType.Graveyard).size() > ai.getCardsIn(ZoneType.Library).size())
|
||||
&& !ComputerUtil.isPlayingReanimator(ai);
|
||||
}
|
||||
} else if (origin.equals(ZoneType.Exile)) {
|
||||
String logic = sa.getParam("AILogic");
|
||||
@@ -344,8 +347,8 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
|
||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Profaner of the Dead")) {
|
||||
// TODO: this is a stub to prevent the AI from crashing the game when, for instance, playing the opponent's
|
||||
// Profaner from exile without paying its mana cost. Otherwise the card is marked RemAIDeck and there is no
|
||||
// specific AI to support playing it in a smarter way. Feel free to expand.
|
||||
// Profaner from exile without paying its mana cost. Otherwise the card is marked AI:RemoveDeck:All and
|
||||
// there is no specific AI to support playing it in a smarter way. Feel free to expand.
|
||||
return !CardLists.filter(ai.getOpponents().getCardsIn(origin), CardPredicates.Presets.CREATURES).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -274,6 +275,22 @@ public class ChooseCardAi extends SpellAbilityAi {
|
||||
if (ai.equals(sa.getActivatingPlayer())) {
|
||||
choice = ComputerUtilCard.getBestAI(options);
|
||||
} // TODO: improve ai
|
||||
} else if (logic.equals("Phylactery")) {
|
||||
CardCollection aiArtifacts = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), Presets.ARTIFACTS);
|
||||
CardCollection indestructibles = CardLists.filter(aiArtifacts, CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE));
|
||||
CardCollection nonCreatures = CardLists.filter(aiArtifacts, Predicates.not(Presets.CREATURES));
|
||||
CardCollection creatures = CardLists.filter(aiArtifacts, Presets.CREATURES);
|
||||
if (!indestructibles.isEmpty()) {
|
||||
// Choose the worst (smallest) indestructible artifact so that the opponent would have to waste
|
||||
// removal on something unpreferred
|
||||
choice = ComputerUtilCard.getWorstAI(indestructibles);
|
||||
} else if (!nonCreatures.isEmpty()) {
|
||||
// The same as above, but for non-indestructible non-creature artifacts (they can't die in combat)
|
||||
choice = ComputerUtilCard.getWorstAI(nonCreatures);
|
||||
} else if (!creatures.isEmpty()) {
|
||||
// Choose the best (hopefully the fattest, whatever) creature so that hopefully it won't die too easily
|
||||
choice = ComputerUtilCard.getBestAI(creatures);
|
||||
}
|
||||
} else {
|
||||
choice = ComputerUtilCard.getBestAI(options);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.util.Map;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import forge.ai.ComputerUtilAbility;
|
||||
|
||||
import forge.ai.ComputerUtilCard;
|
||||
@@ -24,6 +26,8 @@ import forge.game.card.CounterType;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.AbilitySub;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
@@ -38,7 +42,7 @@ public class ChooseGenericEffectAi extends SpellAbilityAi {
|
||||
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
|
||||
if ("Khans".equals(aiLogic) || "Dragons".equals(aiLogic)) {
|
||||
return true;
|
||||
} else if (aiLogic.startsWith("Fabricate")) {
|
||||
} else if (aiLogic.startsWith("Fabricate") || "Riot".equals(aiLogic)) {
|
||||
return true;
|
||||
} else if ("Pump".equals(aiLogic) || "BestOption".equals(aiLogic)) {
|
||||
for (AbilitySub sb : sa.getAdditionalAbilityList("Choices")) {
|
||||
@@ -344,7 +348,56 @@ public class ChooseGenericEffectAi extends SpellAbilityAi {
|
||||
if (!filtered.isEmpty()) {
|
||||
return filtered.get(0);
|
||||
}
|
||||
} else if ("Riot".equals(logic)) {
|
||||
SpellAbility counterSA = spells.get(0), hasteSA = spells.get(1);
|
||||
return preferHasteForRiot(sa, player) ? hasteSA : counterSA;
|
||||
}
|
||||
return spells.get(0); // return first choice if no logic found
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean preferHasteForRiot(SpellAbility sa, Player player) {
|
||||
// returning true means preferring Haste, returning false means preferring a +1/+1 counter
|
||||
final Card host = sa.getHostCard();
|
||||
final Game game = host.getGame();
|
||||
final Card copy = CardUtil.getLKICopy(host);
|
||||
copy.setLastKnownZone(player.getZone(ZoneType.Battlefield));
|
||||
|
||||
// check state it would have on the battlefield
|
||||
CardCollection preList = new CardCollection(copy);
|
||||
game.getAction().checkStaticAbilities(false, Sets.newHashSet(copy), preList);
|
||||
// reset again?
|
||||
game.getAction().checkStaticAbilities(false);
|
||||
|
||||
// can't gain counters, use Haste
|
||||
if (!copy.canReceiveCounters(CounterType.P1P1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// already has Haste, use counter
|
||||
if (copy.hasKeyword(Keyword.HASTE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// not AI turn
|
||||
if (!game.getPhaseHandler().isPlayerTurn(player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// not before Combat
|
||||
if (!game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO check other opponents too if able
|
||||
final Player opp = player.getWeakestOpponent();
|
||||
if (opp != null) {
|
||||
// TODO add predict Combat Damage?
|
||||
if (opp.getLife() < copy.getNetPower()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// haste might not be good enough?
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,14 +142,17 @@ public class CloneAi extends SpellAbilityAi {
|
||||
CardCollection valid = CardLists.getValidCards(sa.getHostCard().getController().getCardsIn(ZoneType.Battlefield), sa.getParam("ValidTgts"), sa.getHostCard().getController(), sa.getHostCard());
|
||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(valid));
|
||||
return true;
|
||||
} else if ("CloneBestCreature".equals(sa.getParam("AILogic"))) {
|
||||
CardCollection valid = CardLists.getValidCards(sa.getHostCard().getController().getGame().getCardsIn(ZoneType.Battlefield), sa.getParam("ValidTgts"), sa.getHostCard().getController(), sa.getHostCard());
|
||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(valid));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Default:
|
||||
// This is reasonable for now. Kamahl, Fist of Krosa and a sorcery or
|
||||
// two are the only things
|
||||
// that clone a target. Those can just use SVar:RemAIDeck:True until
|
||||
// this can do a reasonably
|
||||
// good job of picking a good target
|
||||
// two are the only things that clone a target. Those can just use
|
||||
// AI:RemoveDeck:All until this can do a reasonably good job of picking
|
||||
// a good target
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -158,7 +161,18 @@ public class CloneAi extends SpellAbilityAi {
|
||||
*/
|
||||
@Override
|
||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||
// Didn't confirm in the original code
|
||||
if (sa.hasParam("AILogic") && (!sa.usesTargeting() || sa.isTargetNumberValid())) {
|
||||
// Had a special logic for it and managed to target, so confirm if viable
|
||||
if ("CloneBestCreature".equals(sa.getParam("AILogic"))) {
|
||||
return ComputerUtilCard.evaluateCreature(sa.getTargets().getFirstTargetedCard()) > ComputerUtilCard.evaluateCreature(sa.getHostCard());
|
||||
} else if ("IfDefinedCreatureIsBetter".equals(sa.getParam("AILogic"))) {
|
||||
List<Card> defined = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa);
|
||||
Card bestDefined = ComputerUtilCard.getBestCreatureAI(defined);
|
||||
return ComputerUtilCard.evaluateCreature(bestDefined) > ComputerUtilCard.evaluateCreature(sa.getHostCard());
|
||||
}
|
||||
}
|
||||
|
||||
// Currently doesn't confirm anything that's not defined by AI logic
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
return !c.hasSVar("RemAIDeck") && c.canBeTargetedBy(sa);
|
||||
return !ComputerUtilCard.isCardRemAIDeck(c) && c.canBeTargetedBy(sa);
|
||||
}
|
||||
});
|
||||
object1 = ComputerUtilCard.getBestAI(list);
|
||||
|
||||
@@ -171,7 +171,7 @@ public class ControlGainAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
// do not take control on something it doesn't know how to use
|
||||
return !c.hasSVar("RemAIDeck");
|
||||
return !ComputerUtilCard.isCardRemAIDeck(c);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
||||
|
||||
CardCollection list = new CardCollection(CardUtil.getValidCardsToTarget(sa.getTargetRestrictions(), sa));
|
||||
|
||||
list = CardLists.filter(list, Predicates.not(CardPredicates.hasSVar("RemAIDeck")));
|
||||
list = CardLists.filter(list, Predicates.not(CardPredicates.isRemAIDeck()));
|
||||
//Nothing to target
|
||||
if (list.isEmpty()) {
|
||||
return false;
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package forge.ai.ability;
|
||||
|
||||
import forge.ai.SpecialCardAi;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.ai.*;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.spellability.AbilityActivated;
|
||||
import forge.game.spellability.Spell;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -13,27 +18,111 @@ public class CopySpellAbilityAi extends SpellAbilityAi {
|
||||
|
||||
@Override
|
||||
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||
// the AI should not miss mandatory activations (e.g. Precursor Golem trigger)
|
||||
return sa.isMandatory() || "Always".equals(sa.getParam("AILogic"));
|
||||
Game game = aiPlayer.getGame();
|
||||
int chance = ((PlayerControllerAi)aiPlayer.getController()).getAi().getIntProperty(AiProps.CHANCE_TO_COPY_OWN_SPELL_WHILE_ON_STACK);
|
||||
int diff = ((PlayerControllerAi)aiPlayer.getController()).getAi().getIntProperty(AiProps.ALWAYS_COPY_SPELL_IF_CMC_DIFF);
|
||||
String logic = sa.getParamOrDefault("AILogic", "");
|
||||
|
||||
if (game.getStack().isEmpty()) {
|
||||
return sa.isMandatory();
|
||||
}
|
||||
|
||||
final SpellAbility top = game.getStack().peekAbility();
|
||||
if (top != null
|
||||
&& top.getPayCosts() != null && top.getPayCosts().getCostMana() != null
|
||||
&& sa.getPayCosts() != null && sa.getPayCosts().getCostMana() != null
|
||||
&& top.getPayCosts().getCostMana().getMana().getCMC() >= sa.getPayCosts().getCostMana().getMana().getCMC() + diff) {
|
||||
// The copied spell has a significantly higher CMC than the copy spell, consider copying
|
||||
chance = 100;
|
||||
}
|
||||
|
||||
if (top.getActivatingPlayer().isOpponentOf(aiPlayer)) {
|
||||
chance = 100; // currently the AI will always copy the opponent's spell if viable
|
||||
}
|
||||
|
||||
if (!MyRandom.percentTrue(chance)
|
||||
&& !"AlwaysIfViable".equals(logic)
|
||||
&& !"OnceIfViable".equals(logic)
|
||||
&& !"AlwaysCopyActivatedAbilities".equals(logic)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("OnceIfViable".equals(logic)) {
|
||||
if (AiCardMemory.isRememberedCard(aiPlayer, sa.getHostCard(), AiCardMemory.MemorySet.ACTIVATED_THIS_TURN)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||
if (tgt != null) {
|
||||
|
||||
// Filter AI-specific targets if provided
|
||||
if ("OnlyOwned".equals(sa.getParam("AITgts"))) {
|
||||
if (!top.getActivatingPlayer().equals(aiPlayer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (top.isWrapper() || !(top instanceof SpellAbility || top instanceof AbilityActivated)) {
|
||||
// Shouldn't even try with triggered or wrapped abilities at this time, will crash
|
||||
return false;
|
||||
} else if (top.getApi() == ApiType.CopySpellAbility) {
|
||||
// Don't try to copy a copy ability, too complex for the AI to handle
|
||||
return false;
|
||||
} else if (top.getApi() == ApiType.DestroyAll || top.getApi() == ApiType.SacrificeAll || top.getApi() == ApiType.ChangeZoneAll || top.getApi() == ApiType.TapAll || top.getApi() == ApiType.UnattachAll) {
|
||||
if (!top.usesTargeting() || top.getActivatingPlayer().equals(aiPlayer)) {
|
||||
// If we activated a mass removal / mass tap / mass bounce / etc. spell, or if the opponent activated it but
|
||||
// it can't be retargeted, no reason to copy this spell since it'll probably do the same thing and is useless as a copy
|
||||
return false;
|
||||
}
|
||||
} else if (top.hasParam("ConditionManaSpent")) {
|
||||
// Mana spent is not copied, so these spells generally do nothing when copied.
|
||||
return false;
|
||||
} else if (ComputerUtilCard.isCardRemAIDeck(top.getHostCard())) {
|
||||
// Don't try to copy anything you can't understand how to handle
|
||||
return false;
|
||||
}
|
||||
|
||||
// A copy is necessary to properly test the SA before targeting the copied spell, otherwise the copy SA will fizzle.
|
||||
final SpellAbility topCopy = top.copy(aiPlayer);
|
||||
topCopy.resetTargets();
|
||||
|
||||
if (top.canBeTargetedBy(sa)) {
|
||||
AiPlayDecision decision = AiPlayDecision.CantPlaySa;
|
||||
if (top instanceof Spell) {
|
||||
decision = ((PlayerControllerAi) aiPlayer.getController()).getAi().canPlayFromEffectAI((Spell) topCopy, true, true);
|
||||
} else if (top instanceof AbilityActivated && top.getActivatingPlayer().equals(aiPlayer)
|
||||
&& logic.contains("CopyActivatedAbilities")) {
|
||||
decision = AiPlayDecision.WillPlay; // FIXME: we activated it once, why not again? Or bad idea?
|
||||
}
|
||||
if (decision == AiPlayDecision.WillPlay) {
|
||||
sa.getTargets().add(top);
|
||||
AiCardMemory.rememberCard(aiPlayer, sa.getHostCard(), AiCardMemory.MemorySet.ACTIVATED_THIS_TURN);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the AI should not miss mandatory activations
|
||||
return sa.isMandatory() || "Always".equals(logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||
// the AI should not miss mandatory activations (e.g. Precursor Golem trigger)
|
||||
return mandatory || "Always".equals(sa.getParam("AILogic"));
|
||||
String logic = sa.getParamOrDefault("AILogic", "");
|
||||
return mandatory || logic.contains("Always"); // this includes logic like AlwaysIfViable
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean chkAIDrawback(final SpellAbility sa, final Player aiPlayer) {
|
||||
// NOTE: Other SAs that use CopySpellAbilityAi (e.g. Chain Lightning) are currently routed through
|
||||
// generic method SpellAbilityAi#chkDrawbackWithSubs and are handled there.
|
||||
if ("ChainOfSmog".equals(sa.getParam("AILogic"))) {
|
||||
return SpecialCardAi.ChainOfSmog.consider(aiPlayer, sa);
|
||||
} else if ("ChainOfAcid".equals(sa.getParam("AILogic"))) {
|
||||
return SpecialCardAi.ChainOfAcid.consider(aiPlayer, sa);
|
||||
}
|
||||
|
||||
return super.chkAIDrawback(sa, aiPlayer);
|
||||
return canPlayAI(aiPlayer, sa) || (sa.isMandatory() && super.chkAIDrawback(sa, aiPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -105,7 +105,7 @@ public class CounterAi extends SpellAbilityAi {
|
||||
boolean setPayX = false;
|
||||
if (unlessCost.equals("X") && source.getSVar(unlessCost).equals("Count$xPaid")) {
|
||||
setPayX = true;
|
||||
toPay = ComputerUtilMana.determineLeftoverMana(sa, ai);
|
||||
toPay = Math.min(ComputerUtilMana.determineLeftoverMana(sa, ai), usableManaSources + 1);
|
||||
} else {
|
||||
toPay = AbilityUtils.calculateAmount(source, unlessCost, sa);
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public class CountersMoveAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
// check for some specific AI preferences
|
||||
if (src.hasStartOfKeyword("Graft") && "DontMoveCounterIfLethal".equals(src.getSVar("AIGraftPreference"))) {
|
||||
if ("DontMoveCounterIfLethal".equals(sa.getParam("AILogic"))) {
|
||||
if (cType == CounterType.P1P1 && src.getNetToughness() - src.getTempToughnessBoost() - 1 <= 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -333,11 +333,12 @@ public class CountersMoveAi extends SpellAbilityAi {
|
||||
|
||||
// try to remove P1P1 from undying or evolve
|
||||
if (CounterType.P1P1.equals(cType)) {
|
||||
if (card.hasKeyword("Undying") || card.hasKeyword("Evolve")) {
|
||||
if (card.hasKeyword(Keyword.UNDYING) || card.hasKeyword(Keyword.EVOLVE)
|
||||
|| card.hasKeyword(Keyword.ADAPT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (CounterType.M1M1.equals(cType) && card.hasKeyword("Persist")) {
|
||||
if (CounterType.M1M1.equals(cType) && card.hasKeyword(Keyword.PERSIST)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -392,10 +393,10 @@ public class CountersMoveAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
if (cType != null) {
|
||||
if (CounterType.P1P1.equals(cType) && card.hasKeyword("Undying")) {
|
||||
if (CounterType.P1P1.equals(cType) && card.hasKeyword(Keyword.UNDYING)) {
|
||||
return false;
|
||||
}
|
||||
if (CounterType.M1M1.equals(cType) && card.hasKeyword("Persist")) {
|
||||
if (CounterType.M1M1.equals(cType) && card.hasKeyword(Keyword.PERSIST)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,9 @@ import forge.game.GameEntity;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.*;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.cost.CostPart;
|
||||
import forge.game.cost.CostRemoveCounter;
|
||||
import forge.game.cost.CostSacrifice;
|
||||
import forge.game.cost.*;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
@@ -46,17 +44,19 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
protected boolean willPayCosts(Player ai, SpellAbility sa, Cost cost, Card source) {
|
||||
|
||||
final String type = sa.getParam("CounterType");
|
||||
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
if (!super.willPayCosts(ai, sa, cost, source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// disable moving counters
|
||||
// disable moving counters (unless a specialized AI logic supports it)
|
||||
for (final CostPart part : cost.getCostParts()) {
|
||||
if (part instanceof CostRemoveCounter) {
|
||||
final CostRemoveCounter remCounter = (CostRemoveCounter) part;
|
||||
final CounterType counterType = remCounter.counter;
|
||||
if (counterType.name().equals(type)) {
|
||||
if (counterType.name().equals(type) && !aiLogic.startsWith("MoveCounter")) {
|
||||
return false;
|
||||
}
|
||||
if (!part.payCostFromSource()) {
|
||||
@@ -102,7 +102,7 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
if (sa.hasParam("LevelUp")) {
|
||||
// creatures enchanted by curse auras have low priority
|
||||
if (ph.getPhase().isBefore(PhaseType.MAIN2)) {
|
||||
for (Card aura : source.getEnchantedBy(false)) {
|
||||
for (Card aura : source.getEnchantedBy()) {
|
||||
if (aura.getController().isOpponentOf(ai)) {
|
||||
return false;
|
||||
}
|
||||
@@ -282,6 +282,8 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
if (!source.canTransform()) {
|
||||
return false;
|
||||
}
|
||||
} else if (logic.startsWith("MoveCounter")) {
|
||||
return doMoveCounterLogic(ai, sa, ph);
|
||||
}
|
||||
|
||||
if (sa.getConditions() != null && !sa.getConditions().areMet(sa) && sa.getSubAbility() == null) {
|
||||
@@ -312,6 +314,17 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
// TODO handle proper calculation of X values based on Cost
|
||||
int amount = AbilityUtils.calculateAmount(source, amountStr, sa);
|
||||
|
||||
if (sa.hasParam("Adapt")) {
|
||||
Game game = ai.getGame();
|
||||
Combat combat = game.getCombat();
|
||||
|
||||
if (!source.canReceiveCounters(CounterType.P1P1) || source.getCounters(CounterType.P1P1) > 0) {
|
||||
return false;
|
||||
} else if (combat != null && ph.is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||
return doCombatAdaptLogic(source, amount, combat);
|
||||
}
|
||||
}
|
||||
|
||||
if ("Fight".equals(logic)) {
|
||||
int nPump = 0;
|
||||
if (type.equals("P1P1")) {
|
||||
@@ -433,6 +446,18 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Activate +Loyalty planeswalker abilities even if they have no target (e.g. Vivien of the Arkbow),
|
||||
// but try to do it in Main 2 then so that the AI has a chance to play creatures first.
|
||||
if (list.isEmpty()
|
||||
&& sa.hasParam("Planeswalker")
|
||||
&& sa.getPayCosts() != null
|
||||
&& sa.getPayCosts().hasOnlySpecificCostType(CostPutCounter.class)
|
||||
&& sa.isTargetNumberValid()
|
||||
&& sa.getTargets().getNumTargeted() == 0
|
||||
&& ai.getGame().getPhaseHandler().is(PhaseType.MAIN2, ai)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sourceName.equals("Abzan Charm")) {
|
||||
final TargetRestrictions abTgt = sa.getTargetRestrictions();
|
||||
// specific AI for instant with distribute two +1/+1 counters
|
||||
@@ -715,6 +740,7 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
|
||||
int totalTargets = list.size();
|
||||
|
||||
sa.resetTargets();
|
||||
while (sa.canAddMoreTarget()) {
|
||||
if (mandatory) {
|
||||
// When things are mandatory, gotta handle a little differently
|
||||
@@ -989,4 +1015,80 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
}
|
||||
return Iterables.getFirst(options, null);
|
||||
}
|
||||
|
||||
private boolean doMoveCounterLogic(final Player ai, SpellAbility sa, PhaseHandler ph) {
|
||||
// Spikes (Tempest)
|
||||
|
||||
// Try not to do it unless at the end of opponent's turn or the creature is threatened
|
||||
final int creatDiff = sa.getParam("AILogic").contains("IsCounterUser") ? 450 : 1;
|
||||
final Combat combat = ai.getGame().getCombat();
|
||||
final Card source = sa.getHostCard();
|
||||
|
||||
final boolean threatened = ComputerUtil.predictThreatenedObjects(ai, null, true).contains(source)
|
||||
|| (combat != null && (((combat.isBlocked(source) && ComputerUtilCombat.attackerWouldBeDestroyed(ai, source, combat)) && !ComputerUtilCombat.willKillAtLeastOne(ai, source, combat))
|
||||
|| (combat.isBlocking(source) && ComputerUtilCombat.blockerWouldBeDestroyed(ai, source, combat) && !ComputerUtilCombat.willKillAtLeastOne(ai, source, combat))));
|
||||
|
||||
if (!(threatened || (ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == ai))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CardCollection targets = CardLists.getTargetableCards(ai.getCreaturesInPlay(), sa);
|
||||
targets.remove(source);
|
||||
|
||||
targets = CardLists.filter(targets, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card card) {
|
||||
boolean tgtThreatened = ComputerUtil.predictThreatenedObjects(ai, null, true).contains(card)
|
||||
|| (combat != null && ((combat.isBlocked(card) && ComputerUtilCombat.attackerWouldBeDestroyed(ai, card, combat))
|
||||
|| (combat.isBlocking(card) && ComputerUtilCombat.blockerWouldBeDestroyed(ai, card, combat))));
|
||||
// when threatened, any non-threatened target is good to preserve the counter
|
||||
return !tgtThreatened && (threatened || ComputerUtilCard.evaluateCreature(card, false, false) > ComputerUtilCard.evaluateCreature(source, false, false) + creatDiff);
|
||||
}
|
||||
});
|
||||
|
||||
Card bestTgt = ComputerUtilCard.getBestCreatureAI(targets);
|
||||
|
||||
if (bestTgt != null) {
|
||||
sa.getTargets().add(bestTgt);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean doCombatAdaptLogic(Card source, int amount, Combat combat) {
|
||||
if (combat.isAttacking(source)) {
|
||||
if (!combat.isBlocked(source)) {
|
||||
return true;
|
||||
} else {
|
||||
for (Card blockedBy : combat.getBlockers(source)) {
|
||||
if (blockedBy.getNetToughness() > source.getNetPower()
|
||||
&& blockedBy.getNetToughness() <= source.getNetPower() + amount) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int totBlkPower = Aggregates.sum(combat.getBlockers(source), CardPredicates.Accessors.fnGetNetPower);
|
||||
if (source.getNetToughness() <= totBlkPower
|
||||
&& source.getNetToughness() + amount > totBlkPower) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (combat.isBlocking(source)) {
|
||||
for (Card blocked : combat.getAttackersBlockedBy(source)) {
|
||||
if (blocked.getNetToughness() > source.getNetPower()
|
||||
&& blocked.getNetToughness() <= source.getNetPower() + amount) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int totAtkPower = Aggregates.sum(combat.getAttackersBlockedBy(source), CardPredicates.Accessors.fnGetNetPower);
|
||||
if (source.getNetToughness() <= totAtkPower
|
||||
&& source.getNetToughness() + amount > totAtkPower) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -308,6 +308,30 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
if (mandatory) {
|
||||
if (type.equals("P1P1")) {
|
||||
// Try to target creatures with Adapt or similar
|
||||
CardCollection adaptCreats = CardLists.filter(list, CardPredicates.hasKeyword(Keyword.ADAPT));
|
||||
if (!adaptCreats.isEmpty()) {
|
||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(adaptCreats));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Outlast nice target
|
||||
CardCollection outlastCreats = CardLists.filter(list, CardPredicates.hasKeyword(Keyword.OUTLAST));
|
||||
if (!outlastCreats.isEmpty()) {
|
||||
// outlast cards often benefit from having +1/+1 counters, try not to remove last one
|
||||
CardCollection betterTargets = CardLists.filter(outlastCreats, CardPredicates.hasCounter(CounterType.P1P1, 2));
|
||||
|
||||
if (!betterTargets.isEmpty()) {
|
||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(betterTargets));
|
||||
return true;
|
||||
}
|
||||
|
||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(outlastCreats));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(list));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class DamageAiBase extends SpellAbilityAi {
|
||||
Card hostcard = sa.getHostCard();
|
||||
boolean lifelink = hostcard.hasKeyword(Keyword.LIFELINK);
|
||||
if (!lifelink) {
|
||||
for (Card ench : hostcard.getEnchantedBy(false)) {
|
||||
for (Card ench : hostcard.getEnchantedBy()) {
|
||||
// Treat cards enchanted by older cards with "when enchanted creature deals damage, gain life" as if they had lifelink.
|
||||
if (ench.hasSVar("LikeLifeLink")) {
|
||||
if ("True".equals(ench.getSVar("LikeLifeLink"))) {
|
||||
|
||||
@@ -4,11 +4,15 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import forge.ai.*;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.*;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.cost.CostPart;
|
||||
import forge.game.cost.CostPartMana;
|
||||
import forge.game.cost.CostRemoveCounter;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
@@ -21,7 +25,11 @@ import forge.game.spellability.TargetChoices;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -90,11 +98,26 @@ public class DamageDealAi extends DamageAiBase {
|
||||
|
||||
if (damage.equals("X")) {
|
||||
if (sa.getSVar(damage).equals("Count$xPaid") || sourceName.equals("Crater's Claws")) {
|
||||
// Set PayX here to maximum value.
|
||||
dmg = ComputerUtilMana.determineLeftoverMana(sa, ai);
|
||||
|
||||
// Try not to waste spells like Blaze or Fireball on early targets, try to do more damage with them if possible
|
||||
if (ai.getController().isAI()) {
|
||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||
int holdChance = aic.getIntProperty(AiProps.HOLD_X_DAMAGE_SPELLS_FOR_MORE_DAMAGE_CHANCE);
|
||||
if (MyRandom.percentTrue(holdChance)) {
|
||||
int threshold = aic.getIntProperty(AiProps.HOLD_X_DAMAGE_SPELLS_THRESHOLD);
|
||||
boolean inDanger = ComputerUtil.aiLifeInDanger(ai, false, 0);
|
||||
boolean isLethal = sa.getTargetRestrictions().canTgtPlayer() && dmg >= ai.getWeakestOpponent().getLife() && !ai.getWeakestOpponent().cantLoseForZeroOrLessLife();
|
||||
if (dmg < threshold && ai.getGame().getPhaseHandler().getTurn() / 2 < threshold && !inDanger && !isLethal) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set PayX here to maximum value. It will be adjusted later depending on the target.
|
||||
source.setSVar("PayX", Integer.toString(dmg));
|
||||
} else if (sa.getSVar(damage).equals("Count$CardsInYourHand") && source.getZone().is(ZoneType.Hand)) {
|
||||
dmg--; // the card will be spent casting the spell, so actual damage is 1 less
|
||||
} else if (sa.getSVar(damage).contains("InYourHand") && source.getZone().is(ZoneType.Hand)) {
|
||||
dmg = CardFactoryUtil.xCount(source, sa.getSVar(damage)) - 1; // the card will be spent casting the spell, so actual damage is 1 less
|
||||
} else if (sa.getSVar(damage).equals("TargetedPlayer$CardsInHand")) {
|
||||
// cards that deal damage by the number of cards in target player's hand, e.g. Sudden Impact
|
||||
if (sa.getTargetRestrictions().canTgtPlayer()) {
|
||||
@@ -216,8 +239,33 @@ public class DamageDealAi extends DamageAiBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.damageTargetAI(ai, sa, dmg, false)) {
|
||||
return false;
|
||||
// Try to chain damage/debuff effects
|
||||
Pair<SpellAbility, Integer> chainDmg = getDamagingSAToChain(ai, sa, damage);
|
||||
|
||||
// test what happens if we chain this to another damaging spell
|
||||
if (chainDmg != null) {
|
||||
int extraDmg = chainDmg.getValue();
|
||||
boolean willTargetIfChained = this.damageTargetAI(ai, sa, dmg + extraDmg, false);
|
||||
if (!willTargetIfChained) {
|
||||
return false; // won't play it even in chain
|
||||
} else if (willTargetIfChained && chainDmg.getKey().getApi() == ApiType.Pump && sa.getTargets().isTargetingAnyPlayer()) {
|
||||
// we're trying to chain a pump spell to a damage spell targeting a player, that won't work
|
||||
// so run an additional check to ensure that we want to cast the current spell separately
|
||||
sa.resetTargets();
|
||||
if (!this.damageTargetAI(ai, sa, dmg, false)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// we are about to decide to play this damage spell; if there's something chained to it, reserve mana for
|
||||
// the second spell so we don't misplay
|
||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||
aic.reserveManaSourcesForNextSpell(chainDmg.getKey(), sa);
|
||||
}
|
||||
} else {
|
||||
// simple targeting when there is no spell chaining plan
|
||||
if (!this.damageTargetAI(ai, sa, dmg, false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((damage.equals("X") && source.getSVar(damage).equals("Count$xPaid")) ||
|
||||
@@ -238,6 +286,19 @@ public class DamageDealAi extends DamageAiBase {
|
||||
source.setSVar("PayX", Integer.toString(actualPay));
|
||||
}
|
||||
}
|
||||
|
||||
if ("XCountersDamage".equals(logic) && sa.getPayCosts() != null) {
|
||||
// Check to ensure that we have enough counters to remove per the defined PayX
|
||||
for (CostPart part : sa.getPayCosts().getCostParts()) {
|
||||
if (part instanceof CostRemoveCounter) {
|
||||
if (source.getCounters(((CostRemoveCounter) part).counter) < Integer.valueOf(source.getSVar("PayX"))) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -275,7 +336,7 @@ public class DamageDealAi extends DamageAiBase {
|
||||
final Game game = source.getGame();
|
||||
List<Card> hPlay = getTargetableCards(ai, sa, pl, tgt, activator, source, game);
|
||||
|
||||
List<Card> killables = CardLists.filter(hPlay, new Predicate<Card>() {
|
||||
CardCollection killables = CardLists.filter(hPlay, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
return c.getSVar("Targeting").equals("Dies")
|
||||
@@ -286,7 +347,10 @@ public class DamageDealAi extends DamageAiBase {
|
||||
});
|
||||
|
||||
// Filter AI-specific targets if provided
|
||||
killables = ComputerUtil.filterAITgts(sa, ai, new CardCollection(killables), true);
|
||||
killables = ComputerUtil.filterAITgts(sa, ai, killables, true);
|
||||
|
||||
// Try not to target anything which will already be dead by the time the spell resolves
|
||||
killables = ComputerUtil.filterCreaturesThatWillDieThisTurn(ai, killables, sa);
|
||||
|
||||
Card targetCard = null;
|
||||
if (pl.isOpponentOf(ai) && activator.equals(ai) && !killables.isEmpty()) {
|
||||
@@ -494,7 +558,9 @@ public class DamageDealAi extends DamageAiBase {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tgt.getMaxTargets(source, sa) <= 0) {
|
||||
// AssumeAtLeastOneTarget is used for cards with funky targeting implementation like Fight with Fire which would
|
||||
// otherwise confuse the AI by returning 0 unexpectedly during SA "AI can play" tests.
|
||||
if (tgt.getMaxTargets(source, sa) <= 0 && !logic.equals("AssumeAtLeastOneTarget")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -560,7 +626,15 @@ public class DamageDealAi extends DamageAiBase {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int totalTargetedSoFar = -1;
|
||||
while (tcs.getNumTargeted() < tgt.getMaxTargets(source, sa)) {
|
||||
if (totalTargetedSoFar == tcs.getNumTargeted()) {
|
||||
// Avoid looping endlessly when choosing targets for cards with variable target number and type
|
||||
// like Jaya's Immolating Inferno
|
||||
break;
|
||||
}
|
||||
totalTargetedSoFar = tcs.getNumTargeted();
|
||||
if (oppTargetsChoice && sa.getActivatingPlayer().equals(ai) && !sa.isTrigger()) {
|
||||
// canPlayAI (sa activated by ai)
|
||||
Player targetingPlayer = AbilityUtils.getDefinedPlayers(source, sa.getParam("TargetingPlayer"), sa).get(0);
|
||||
@@ -962,4 +1036,90 @@ public class DamageDealAi extends DamageAiBase {
|
||||
source.setSVar("PayX", Integer.toString(dmg));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns a pair of a SpellAbility (APIType DealDamage or Pump) and damage/debuff amount
|
||||
// The returned spell ability can be chained to "sa" to deal more damage (enough mana is available to cast both
|
||||
// and can be properly reserved).
|
||||
public static Pair<SpellAbility, Integer> getDamagingSAToChain(Player ai, SpellAbility sa, String damage) {
|
||||
if (!ai.getController().isAI()) {
|
||||
return null; // should only work for the actual AI player
|
||||
} else if (((PlayerControllerAi)ai.getController()).getAi().usesSimulation()) {
|
||||
// simulated AI shouldn't use paired decisions, it tries to find complex decisions on its own
|
||||
return null;
|
||||
}
|
||||
|
||||
Game game = ai.getGame();
|
||||
int chance = ((PlayerControllerAi)ai.getController()).getAi().getIntProperty(AiProps.CHANCE_TO_CHAIN_TWO_DAMAGE_SPELLS);
|
||||
|
||||
if (chance > 0 && (ComputerUtilCombat.lifeInDanger(ai, game.getCombat()) || ComputerUtil.aiLifeInDanger(ai, true, 0))) {
|
||||
chance = 100; // in danger, do it even if normally the chance is low (unless chaining is completely disabled)
|
||||
}
|
||||
|
||||
if (!MyRandom.percentTrue(chance)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (sa.getSubAbility() != null || sa.getParent() != null) {
|
||||
// Doesn't work yet for complex decisions where damage is only a part of the decision process
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try to chain damage/debuff effects
|
||||
if (StringUtils.isNumeric(damage) || (damage.startsWith("-") && StringUtils.isNumeric(damage.substring(1)))) {
|
||||
// currently only works for predictable numeric damage
|
||||
CardCollection cards = new CardCollection();
|
||||
cards.addAll(ai.getCardsIn(ZoneType.Hand));
|
||||
cards.addAll(ai.getCardsIn(ZoneType.Battlefield));
|
||||
cards.addAll(ai.getCardsActivableInExternalZones(true));
|
||||
for (Card c : cards) {
|
||||
for (SpellAbility ab : c.getSpellAbilities()) {
|
||||
if (ab.equals(sa) || ab.getSubAbility() != null) { // decisions for complex SAs with subs are not supported yet
|
||||
continue;
|
||||
}
|
||||
if (!ab.canPlay()) {
|
||||
continue;
|
||||
}
|
||||
// currently works only with cards that don't have additional costs (only mana is supported)
|
||||
if (ab.getPayCosts() != null
|
||||
&& (ab.getPayCosts().hasNoManaCost() || ab.getPayCosts().hasOnlySpecificCostType(CostPartMana.class))) {
|
||||
String dmgDef = "0";
|
||||
if (ab.getApi() == ApiType.DealDamage) {
|
||||
dmgDef = ab.getParamOrDefault("NumDmg", "0");
|
||||
} else if (ab.getApi() == ApiType.Pump) {
|
||||
dmgDef = ab.getParamOrDefault("NumDef", "0");
|
||||
if (dmgDef.startsWith("-")) {
|
||||
dmgDef = dmgDef.substring(1);
|
||||
} else {
|
||||
continue; // not a toughness debuff
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNumeric(dmgDef)) { // currently doesn't work for X and other dependent costs
|
||||
if (sa.usesTargeting() && ab.usesTargeting()) {
|
||||
// Ensure that the chained spell can target at least the same things (or more) as the current one
|
||||
TargetRestrictions tgtSa = sa.getTargetRestrictions();
|
||||
TargetRestrictions tgtAb = sa.getTargetRestrictions();
|
||||
String[] validTgtsSa = tgtSa.getValidTgts();
|
||||
String[] validTgtsAb = tgtAb.getValidTgts();
|
||||
if (!Arrays.asList(validTgtsSa).containsAll(Arrays.asList(validTgtsAb))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// FIXME: should it also check restrictions for targeting players?
|
||||
ManaCost costSa = sa.getPayCosts() != null ? sa.getPayCosts().getTotalMana() : ManaCost.NO_COST;
|
||||
ManaCost costAb = ab.getPayCosts().getTotalMana(); // checked for null above
|
||||
ManaCost total = ManaCost.combine(costSa, costAb);
|
||||
SpellAbility combinedAb = ab.copyWithDefinedCost(new Cost(total, false));
|
||||
// can we pay both costs?
|
||||
if (ComputerUtilMana.canPayManaCost(combinedAb, ai, 0)) {
|
||||
return Pair.of(ab, Integer.parseInt(dmgDef));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +178,8 @@ public class DestroyAi extends SpellAbilityAi {
|
||||
});
|
||||
}
|
||||
|
||||
// Try to avoid targeting creatures that are dead on board
|
||||
list = ComputerUtil.filterCreaturesThatWillDieThisTurn(ai, list, sa);
|
||||
if (list.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -271,7 +273,7 @@ public class DestroyAi extends SpellAbilityAi {
|
||||
} else {
|
||||
// Don't destroy stolen permanents when the stealing aura can be destroyed
|
||||
if (choice.getOwner() == ai) {
|
||||
for (Card aura : choice.getEnchantedBy(false)) {
|
||||
for (Card aura : choice.getEnchantedBy()) {
|
||||
SpellAbility sp = aura.getFirstSpellAbility();
|
||||
if (sp != null && "GainControl".equals(sp.getParam("AILogic"))
|
||||
&& aura.getController() != ai && sa.canTarget(aura)) {
|
||||
@@ -313,6 +315,9 @@ public class DestroyAi extends SpellAbilityAi {
|
||||
CardCollection list = CardLists.getTargetableCards(ai.getGame().getCardsIn(ZoneType.Battlefield), sa);
|
||||
list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source, sa);
|
||||
|
||||
// Try to avoid targeting creatures that are dead on board
|
||||
list = ComputerUtil.filterCreaturesThatWillDieThisTurn(ai, list, sa);
|
||||
|
||||
if (list.isEmpty() || list.size() < tgt.getMinTargets(sa.getHostCard(), sa)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -131,6 +131,8 @@ public class DrawAi extends SpellAbilityAi {
|
||||
return true;
|
||||
} else if (logic.equals("AlwaysAtOppEOT")) {
|
||||
return ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn().equals(ai);
|
||||
} else if (logic.equals("RespondToOwnActivation")) {
|
||||
return !ai.getGame().getStack().isEmpty() && ai.getGame().getStack().peekAbility().getHostCard().equals(sa.getHostCard());
|
||||
}
|
||||
|
||||
// Don't use draw abilities before main 2 if possible
|
||||
@@ -363,6 +365,10 @@ public class DrawAi extends SpellAbilityAi {
|
||||
if (numCards >= computerLibrarySize) {
|
||||
if (xPaid) {
|
||||
numCards = computerLibrarySize - 1;
|
||||
if (numCards <= 0 && !mandatory) {
|
||||
// not drawing anything, so don't do it
|
||||
return false;
|
||||
}
|
||||
} else if (!ai.isCardInPlay("Laboratory Maniac")) {
|
||||
aiTarget = false;
|
||||
}
|
||||
@@ -396,6 +402,9 @@ public class DrawAi extends SpellAbilityAi {
|
||||
if (computerHandSize + numCards > computerMaxHandSize && game.getPhaseHandler().isPlayerTurn(ai)) {
|
||||
if (xPaid) {
|
||||
numCards = computerMaxHandSize - computerHandSize;
|
||||
if (sa.getHostCard().getZone().is(ZoneType.Hand)) {
|
||||
numCards++; // the card will be spent
|
||||
}
|
||||
source.setSVar("PayX", Integer.toString(numCards));
|
||||
} else {
|
||||
// Don't draw too many cards and then risk discarding
|
||||
|
||||
@@ -6,17 +6,14 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.ai.ComputerUtil;
|
||||
import forge.ai.ComputerUtilCard;
|
||||
import forge.ai.ComputerUtilCombat;
|
||||
import forge.ai.SpecialCardAi;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.ai.SpellApiToAi;
|
||||
import forge.ai.*;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.Game;
|
||||
import forge.game.GlobalRuleChange;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.*;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
@@ -116,10 +113,39 @@ public class EffectAi extends SpellAbilityAi {
|
||||
} else if (logic.equals("SpellCopy")) {
|
||||
// fetch Instant or Sorcery and AI has reason to play this turn
|
||||
// does not try to get itself
|
||||
final ManaCost costSa = sa.getPayCosts() != null ? sa.getPayCosts().getTotalMana() : ManaCost.NO_COST;
|
||||
final int count = CardLists.count(ai.getCardsIn(ZoneType.Hand), new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
return (c.isInstant() || c.isSorcery()) && c != sa.getHostCard() && ComputerUtil.hasReasonToPlayCardThisTurn(ai, c);
|
||||
if (!(c.isInstant() || c.isSorcery()) || c.equals(sa.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
for (SpellAbility ab : c.getSpellAbilities()) {
|
||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals(ComputerUtilAbility.getAbilitySourceName(ab))
|
||||
|| ab.hasParam("AINoRecursiveCheck")) {
|
||||
// prevent infinitely recursing mana ritual and other abilities with reentry
|
||||
continue;
|
||||
} else if ("SpellCopy".equals(ab.getParam("AILogic")) && ab.getApi() == ApiType.Effect) {
|
||||
// don't copy another copy spell, too complex for the AI
|
||||
continue;
|
||||
}
|
||||
if (!ab.canPlay()) {
|
||||
continue;
|
||||
}
|
||||
AiPlayDecision decision = ((PlayerControllerAi)ai.getController()).getAi().canPlaySa(ab);
|
||||
// see if we can pay both for this spell and for the Effect spell we're considering
|
||||
if (decision == AiPlayDecision.WillPlay || decision == AiPlayDecision.WaitForMain2) {
|
||||
ManaCost costAb = ab.getPayCosts() != null ? ab.getPayCosts().getTotalMana() : ManaCost.NO_COST;
|
||||
ManaCost total = ManaCost.combine(costSa, costAb);
|
||||
SpellAbility combinedAb = ab.copyWithDefinedCost(new Cost(total, false));
|
||||
// can we pay both costs?
|
||||
if (ComputerUtilMana.canPayManaCost(combinedAb, ai, 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -139,8 +165,26 @@ public class EffectAi extends SpellAbilityAi {
|
||||
final int count = CardLists.count(ai.getCardsIn(ZoneType.Hand), new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
return (c.isInstant() || c.isSorcery()) && !c.hasKeyword(Keyword.REBOUND)
|
||||
&& ComputerUtil.hasReasonToPlayCardThisTurn(ai, c);
|
||||
if (!(c.isInstant() || c.isSorcery()) || c.hasKeyword(Keyword.REBOUND)) {
|
||||
return false;
|
||||
}
|
||||
for (SpellAbility ab : c.getSpellAbilities()) {
|
||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals(ComputerUtilAbility.getAbilitySourceName(ab))
|
||||
|| ab.hasParam("AINoRecursiveCheck")) {
|
||||
// prevent infinitely recursing mana ritual and other abilities with reentry
|
||||
continue;
|
||||
}
|
||||
if (!ab.canPlay()) {
|
||||
continue;
|
||||
}
|
||||
AiPlayDecision decision = ((PlayerControllerAi)ai.getController()).getAi().canPlaySa(ab);
|
||||
if (decision == AiPlayDecision.WillPlay || decision == AiPlayDecision.WaitForMain2) {
|
||||
if (ComputerUtilMana.canPayManaCost(ab, ai, 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -45,8 +45,10 @@ public class FogAi extends SpellAbilityAi {
|
||||
|| (game.getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)))
|
||||
&& (AiCardMemory.isMemorySetEmpty(ai, AiCardMemory.MemorySet.CHOSEN_FOG_EFFECT))
|
||||
&& (ComputerUtil.aiLifeInDanger(ai, false, 0))) {
|
||||
((PlayerControllerAi) ai.getController()).getAi().reserveManaSources(sa, PhaseType.COMBAT_DECLARE_BLOCKERS, true);
|
||||
AiCardMemory.rememberCard(ai, hostCard, AiCardMemory.MemorySet.CHOSEN_FOG_EFFECT);
|
||||
boolean reserved = ((PlayerControllerAi) ai.getController()).getAi().reserveManaSources(sa, PhaseType.COMBAT_DECLARE_BLOCKERS, true);
|
||||
if (reserved) {
|
||||
AiCardMemory.rememberCard(ai, hostCard, AiCardMemory.MemorySet.CHOSEN_FOG_EFFECT);
|
||||
}
|
||||
}
|
||||
|
||||
// AI should only activate this during Human's Declare Blockers phase
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package forge.ai.ability;
|
||||
|
||||
import forge.ai.ComputerUtil;
|
||||
import forge.ai.ComputerUtilAbility;
|
||||
import forge.ai.ComputerUtilCombat;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.ai.*;
|
||||
import forge.game.Game;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.MagicStack;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
public class LifeExchangeVariantAi extends SpellAbilityAi {
|
||||
|
||||
@@ -84,18 +84,40 @@ public class LifeExchangeVariantAi extends SpellAbilityAi {
|
||||
return shouldDo;
|
||||
}
|
||||
else if ("Evra, Halcyon Witness".equals(sourceName)) {
|
||||
if (!ai.canGainLife())
|
||||
return false;
|
||||
|
||||
int aiLife = ai.getLife();
|
||||
|
||||
// Offensive use of Evra, try to kill the opponent or deal a lot of damage, and hopefully gain a lot of life too
|
||||
if (game.getCombat() != null && game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
||||
&& game.getCombat().isAttacking(source) && source.getNetPower() > 0
|
||||
&& source.getNetPower() < aiLife) {
|
||||
Player def = game.getCombat().getDefenderPlayerByAttacker(source);
|
||||
if (game.getCombat().isUnblocked(source) && def.canLoseLife() && aiLife >= def.getLife() && source.getNetPower() < def.getLife()) {
|
||||
// Unblocked Evra which can deal lethal damage
|
||||
return true;
|
||||
} else if (ai.getController().isAI() && aiLife > source.getNetPower() && source.hasKeyword(Keyword.LIFELINK)) {
|
||||
int dangerMin = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_THRESHOLD));
|
||||
int dangerMax = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_MAX_THRESHOLD));
|
||||
int dangerDiff = dangerMax - dangerMin;
|
||||
int lifeInDanger = dangerDiff <= 0 ? dangerMin : MyRandom.getRandom().nextInt(dangerDiff) + dangerMin;
|
||||
if (source.getNetPower() >= lifeInDanger && ai.canGainLife() && ComputerUtil.lifegainPositive(ai, source)) {
|
||||
// Blocked or unblocked Evra which will get bigger *and* we're getting our life back through Lifelink
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Defensive use of Evra, try to debuff Evra to try to gain some life
|
||||
if (source.getNetPower() > aiLife) {
|
||||
if (ComputerUtilCombat.lifeInSeriousDanger(ai, ai.getGame().getCombat())) {
|
||||
// Only makes sense if the AI can actually gain life from this
|
||||
if (!ai.canGainLife())
|
||||
return false;
|
||||
|
||||
if (ComputerUtilCombat.lifeInSeriousDanger(ai, game.getCombat())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// check the top of stack
|
||||
MagicStack stack = ai.getGame().getStack();
|
||||
MagicStack stack = game.getStack();
|
||||
if (!stack.isEmpty()) {
|
||||
SpellAbility saTop = stack.peekAbility();
|
||||
if (ComputerUtil.predictDamageFromSpell(saTop, ai) >= aiLife) {
|
||||
@@ -103,6 +125,7 @@ public class LifeExchangeVariantAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -29,8 +30,10 @@ public class ManaEffectAi extends SpellAbilityAi {
|
||||
*/
|
||||
@Override
|
||||
protected boolean checkAiLogic(Player ai, SpellAbility sa, String aiLogic) {
|
||||
if ("ManaRitual".equals(aiLogic)) {
|
||||
if (aiLogic.startsWith("ManaRitual")) {
|
||||
return doManaRitualLogic(ai, sa);
|
||||
} else if ("Always".equals(aiLogic)) {
|
||||
return true;
|
||||
}
|
||||
return super.checkAiLogic(ai, sa, aiLogic);
|
||||
}
|
||||
@@ -104,6 +107,7 @@ public class ManaEffectAi extends SpellAbilityAi {
|
||||
// Dark Ritual and other similar instants/sorceries that add mana to mana pool
|
||||
private boolean doManaRitualLogic(Player ai, SpellAbility sa) {
|
||||
final Card host = sa.getHostCard();
|
||||
final String logic = sa.getParamOrDefault("AILogic", "");
|
||||
|
||||
CardCollection manaSources = ComputerUtilMana.getAvailableManaSources(ai, true);
|
||||
int numManaSrcs = manaSources.size();
|
||||
@@ -115,7 +119,9 @@ public class ManaEffectAi extends SpellAbilityAi {
|
||||
String produced = sa.getParam("Produced");
|
||||
byte producedColor = produced.equals("Any") ? MagicColor.ALL_COLORS : MagicColor.fromName(produced);
|
||||
|
||||
if ("ChosenX".equals(sa.getParam("Amount"))
|
||||
int numCounters = 0;
|
||||
int manaSurplus = 0;
|
||||
if ("XChoice".equals(host.getSVar("X"))
|
||||
&& sa.getPayCosts() != null && sa.getPayCosts().hasSpecificCostType(CostRemoveCounter.class)) {
|
||||
CounterType ctrType = CounterType.KI; // Petalmane Baku
|
||||
for (CostPart part : sa.getPayCosts().getCostParts()) {
|
||||
@@ -124,7 +130,12 @@ public class ManaEffectAi extends SpellAbilityAi {
|
||||
break;
|
||||
}
|
||||
}
|
||||
manaReceived = host.getCounters(ctrType);
|
||||
numCounters = host.getCounters(ctrType);
|
||||
manaReceived = numCounters;
|
||||
if (logic.startsWith("ManaRitualBattery.")) {
|
||||
manaSurplus = Integer.valueOf(logic.substring(18)); // adds an extra mana even if no counters removed
|
||||
manaReceived += manaSurplus;
|
||||
}
|
||||
}
|
||||
|
||||
int searchCMC = numManaSrcs - selfCost + manaReceived;
|
||||
@@ -194,6 +205,13 @@ public class ManaEffectAi extends SpellAbilityAi {
|
||||
CardPredicates.lessCMC(searchCMC),
|
||||
Predicates.or(CardPredicates.isColorless(), CardPredicates.isColor(producedColor))));
|
||||
|
||||
if (logic.startsWith("ManaRitualBattery")) {
|
||||
// Don't remove more counters than would be needed to cast the more expensive thing we want to cast,
|
||||
// otherwise the AI grabs too many counters at once.
|
||||
int maxCtrs = Aggregates.max(castableSpells, CardPredicates.Accessors.fnGetCmc) - manaSurplus;
|
||||
sa.setSVar("ChosenX", "Number$" + Math.min(numCounters, maxCtrs));
|
||||
}
|
||||
|
||||
// TODO: this will probably still waste the card from time to time. Somehow improve detection of castable material.
|
||||
return castableSpells.size() > 0;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ManifestAi extends SpellAbilityAi {
|
||||
repParams.put("Origin", ZoneType.Library);
|
||||
repParams.put("Destination", ZoneType.Battlefield);
|
||||
repParams.put("Source", sa.getHostCard());
|
||||
List<ReplacementEffect> list = game.getReplacementHandler().getReplacementList(repParams, ReplacementLayer.None);
|
||||
List<ReplacementEffect> list = game.getReplacementHandler().getReplacementList(repParams, ReplacementLayer.Other);
|
||||
if (!list.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,9 +55,11 @@ public class MillAi extends SpellAbilityAi {
|
||||
} else if ("ExileAndPlayOrDealDamage".equals(sa.getParam("AILogic"))) {
|
||||
return (ph.is(PhaseType.MAIN1) || ph.is(PhaseType.MAIN2)) && ph.isPlayerTurn(ai); // Chandra, Torch of Defiance and similar
|
||||
}
|
||||
if ("You".equals(sa.getParam("Defined")) && !(!SpellAbilityAi.isSorcerySpeed(sa) && ph.is(PhaseType.END_OF_TURN)
|
||||
&& ph.getNextTurn().equals(ai))) {
|
||||
return false; // only self-mill at opponent EOT
|
||||
if (!sa.hasParam("Planeswalker")) { // Planeswalker abilities are only activated at sorcery speed
|
||||
if ("You".equals(sa.getParam("Defined")) && !(!SpellAbilityAi.isSorcerySpeed(sa) && ph.is(PhaseType.END_OF_TURN)
|
||||
&& ph.getNextTurn().equals(ai))) {
|
||||
return false; // only self-mill at opponent EOT
|
||||
}
|
||||
}
|
||||
if (sa.getHostCard().isCreature() && sa.getPayCosts().hasTapCost()) {
|
||||
if (!(ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn().equals(ai))) {
|
||||
|
||||
@@ -2,15 +2,17 @@ package forge.ai.ability;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.ai.ComputerUtil;
|
||||
import forge.ai.ComputerUtilCard;
|
||||
import forge.ai.ComputerUtilCombat;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import com.google.common.collect.Lists;
|
||||
import forge.ai.*;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
@@ -23,14 +25,45 @@ public class MustBlockAi extends SpellAbilityAi {
|
||||
|
||||
@Override
|
||||
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||
// disabled for the AI until he/she can make decisions about who to make
|
||||
// block
|
||||
final Card source = sa.getHostCard();
|
||||
final Game game = aiPlayer.getGame();
|
||||
final Combat combat = game.getCombat();
|
||||
final PhaseHandler ph = game.getPhaseHandler();
|
||||
final boolean onlyLethal = !"AllowNonLethal".equals(sa.getParam("AILogic"));
|
||||
|
||||
if (combat == null || !combat.isAttacking(source)) {
|
||||
return false;
|
||||
} else if (AiCardMemory.isRememberedCard(aiPlayer, source, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN)) {
|
||||
// The AI can meaningfully do it only to one creature per card yet, trying to do it to multiple cards
|
||||
// may result in overextending and losing the attacker
|
||||
return false;
|
||||
}
|
||||
|
||||
final TargetRestrictions abTgt = sa.getTargetRestrictions();
|
||||
final List<Card> list = determineGoodBlockers(source, aiPlayer, combat.getDefenderPlayerByAttacker(source), sa, onlyLethal,false);
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
final Card blocker = ComputerUtilCard.getBestCreatureAI(list);
|
||||
if (blocker == null) {
|
||||
return false;
|
||||
}
|
||||
sa.getTargets().add(blocker);
|
||||
AiCardMemory.rememberCard(aiPlayer, source, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||
return false;
|
||||
if (sa.hasParam("DefinedAttacker")) {
|
||||
// The AI can't handle "target creature blocks another target creature" abilities yet
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise it's a standard targeted "target creature blocks CARDNAME" ability, so use the main canPlayAI code path
|
||||
return canPlayAI(aiPlayer, sa);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,27 +95,7 @@ public class MustBlockAi extends SpellAbilityAi {
|
||||
boolean chance = false;
|
||||
|
||||
if (abTgt != null) {
|
||||
List<Card> list = CardLists.filter(ComputerUtil.getOpponentFor(ai).getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES);
|
||||
list = CardLists.getTargetableCards(list, sa);
|
||||
list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source, sa);
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
boolean tapped = c.isTapped();
|
||||
c.setTapped(false);
|
||||
if (!CombatUtil.canBlock(definedAttacker, c)) {
|
||||
return false;
|
||||
}
|
||||
if (ComputerUtilCombat.canDestroyAttacker(ai, definedAttacker, c, null, false)) {
|
||||
return false;
|
||||
}
|
||||
if (!ComputerUtilCombat.canDestroyBlocker(ai, c, definedAttacker, null, false)) {
|
||||
return false;
|
||||
}
|
||||
c.setTapped(tapped);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
final List<Card> list = determineGoodBlockers(definedAttacker, ai, ComputerUtil.getOpponentFor(ai), sa, true,true);
|
||||
if (list.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -90,6 +103,20 @@ public class MustBlockAi extends SpellAbilityAi {
|
||||
if (blocker == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source.hasKeyword(Keyword.PROVOKE) && blocker.isTapped()) {
|
||||
// Don't provoke if the attack is potentially lethal
|
||||
Combat combat = ai.getGame().getCombat();
|
||||
if (combat != null) {
|
||||
Player defender = combat.getDefenderPlayerByAttacker(source);
|
||||
if (defender != null && combat.getAttackingPlayer().equals(ai)
|
||||
&& defender.canLoseLife() && !defender.cantLoseForZeroOrLessLife()
|
||||
&& ComputerUtilCombat.lifeThatWouldRemain(defender, combat) <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sa.getTargets().add(blocker);
|
||||
chance = true;
|
||||
} else {
|
||||
@@ -98,4 +125,40 @@ public class MustBlockAi extends SpellAbilityAi {
|
||||
|
||||
return chance;
|
||||
}
|
||||
|
||||
private List<Card> determineGoodBlockers(final Card attacker, final Player ai, Player defender, SpellAbility sa,
|
||||
final boolean onlyLethal, final boolean testTapped) {
|
||||
final Card source = sa.getHostCard();
|
||||
final TargetRestrictions abTgt = sa.getTargetRestrictions();
|
||||
|
||||
List<Card> list = Lists.newArrayList();
|
||||
list = CardLists.filter(defender.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES);
|
||||
list = CardLists.getTargetableCards(list, sa);
|
||||
list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source, sa);
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
boolean tapped = c.isTapped();
|
||||
if (testTapped) {
|
||||
c.setTapped(false);
|
||||
}
|
||||
if (!CombatUtil.canBlock(attacker, c)) {
|
||||
return false;
|
||||
}
|
||||
if (ComputerUtilCombat.canDestroyAttacker(ai, attacker, c, null, false)) {
|
||||
return false;
|
||||
}
|
||||
if (onlyLethal && !ComputerUtilCombat.canDestroyBlocker(ai, c, attacker, null, false)) {
|
||||
return false;
|
||||
}
|
||||
if (testTapped) {
|
||||
c.setTapped(tapped);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +61,23 @@ public class PermanentAi extends SpellAbilityAi {
|
||||
if (card.getType().isLegendary()
|
||||
&& !game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)) {
|
||||
if (ai.isCardInPlay(card.getName())) {
|
||||
// AiPlayDecision.WouldDestroyLegend
|
||||
return false;
|
||||
if (!card.hasSVar("AILegendaryException")) {
|
||||
// AiPlayDecision.WouldDestroyLegend
|
||||
return false;
|
||||
} else {
|
||||
String specialRule = card.getSVar("AILegendaryException");
|
||||
if ("TwoCopiesAllowed".equals(specialRule)) {
|
||||
// One extra copy allowed on the battlefield, e.g. Brothers Yamazaki
|
||||
if (CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals(card.getName())).size() > 1) {
|
||||
return false;
|
||||
}
|
||||
} else if ("AlwaysAllowed".equals(specialRule)) {
|
||||
// Nothing to do here, check for Legendary is disabled
|
||||
} else {
|
||||
// Unknown hint, assume two copies not allowed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,10 +207,10 @@ public class PermanentAi extends SpellAbilityAi {
|
||||
// be better to have a pristine copy of the card - might not always be a correct assumption, but sounds
|
||||
// like a reasonable default for some cards).
|
||||
for (Card c : ctrld) {
|
||||
if (c.getEnchantedBy(false).isEmpty()) {
|
||||
if (c.getEnchantedBy().isEmpty()) {
|
||||
numControlled++;
|
||||
} else {
|
||||
for (Card att : c.getEnchantedBy(false)) {
|
||||
for (Card att : c.getEnchantedBy()) {
|
||||
if (!att.getController().isOpponentOf(ai)) {
|
||||
numControlled++;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package forge.ai.ability;
|
||||
|
||||
import forge.ai.ComputerUtil;
|
||||
import forge.ai.ComputerUtilCard;
|
||||
import forge.ai.ComputerUtilCost;
|
||||
import com.google.common.base.Predicate;
|
||||
import forge.ai.*;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardUtil;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
/**
|
||||
* AbilityFactory for Creature Spells.
|
||||
*
|
||||
*/
|
||||
@@ -79,21 +83,122 @@ public class PermanentCreatureAi extends PermanentAi {
|
||||
return false;
|
||||
}
|
||||
|
||||
// save cards with flash for surprise blocking
|
||||
if (card.withFlash(ai)
|
||||
&& (ai.isUnlimitedHandSize() || ai.getCardsIn(ZoneType.Hand).size() <= ai.getMaxHandSize()
|
||||
// Flash logic
|
||||
boolean advancedFlash = false;
|
||||
if (ai.getController().isAI()) {
|
||||
advancedFlash = ((PlayerControllerAi)ai.getController()).getAi().getBooleanProperty(AiProps.FLASH_ENABLE_ADVANCED_LOGIC);
|
||||
}
|
||||
if (card.withFlash(ai)) {
|
||||
if (advancedFlash) {
|
||||
return doAdvancedFlashLogic(card, ai, sa);
|
||||
} else {
|
||||
// save cards with flash for surprise blocking
|
||||
if ((ai.isUnlimitedHandSize() || ai.getCardsIn(ZoneType.Hand).size() <= ai.getMaxHandSize()
|
||||
|| ph.getPhase().isBefore(PhaseType.END_OF_TURN))
|
||||
&& ai.getManaPool().totalMana() <= 0
|
||||
&& (ph.isPlayerTurn(ai) || ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS))
|
||||
&& (!card.hasETBTrigger(true) || card.hasSVar("AmbushAI")) && game.getStack().isEmpty()
|
||||
&& !ComputerUtil.castPermanentInMain1(ai, sa)) {
|
||||
// AiPlayDecision.AnotherTime;
|
||||
return false;
|
||||
&& ai.getManaPool().totalMana() <= 0
|
||||
&& (ph.isPlayerTurn(ai) || ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS))
|
||||
&& (!card.hasETBTrigger(true) && !card.hasSVar("AmbushAI"))
|
||||
&& game.getStack().isEmpty()
|
||||
&& !ComputerUtil.castPermanentInMain1(ai, sa)) {
|
||||
// AiPlayDecision.AnotherTime;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.checkPhaseRestrictions(ai, sa, ph);
|
||||
}
|
||||
|
||||
private boolean doAdvancedFlashLogic(Card card, final Player ai, SpellAbility sa) {
|
||||
Game game = ai.getGame();
|
||||
PhaseHandler ph = game.getPhaseHandler();
|
||||
Combat combat = game.getCombat();
|
||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||
|
||||
boolean isOppTurn = ph.getPlayerTurn().isOpponentOf(ai);
|
||||
boolean isOwnEOT = ph.is(PhaseType.END_OF_TURN, ai);
|
||||
boolean isEOTBeforeMyTurn = ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn().equals(ai);
|
||||
boolean isMyDeclareBlockers = ph.is(PhaseType.COMBAT_DECLARE_BLOCKERS, ai) && ai.getGame().getCombat() != null;
|
||||
boolean isOppDeclareAttackers = ph.is(PhaseType.COMBAT_DECLARE_ATTACKERS) && isOppTurn && ai.getGame().getCombat() != null;
|
||||
boolean isMyMain1OrLater = ph.is(PhaseType.MAIN1, ai) || (ph.getPhase().isAfter(PhaseType.MAIN1) && ph.getPlayerTurn().equals(ai));
|
||||
boolean canRespondToStack = false;
|
||||
if (!game.getStack().isEmpty()) {
|
||||
SpellAbility peekSa = game.getStack().peekAbility();
|
||||
Player activator = peekSa.getActivatingPlayer();
|
||||
if (activator != null && activator.isOpponentOf(ai) && peekSa.getApi() != ApiType.DestroyAll
|
||||
&& peekSa.getApi() != ApiType.DamageAll) {
|
||||
canRespondToStack = true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasETBTrigger = card.hasETBTrigger(true);
|
||||
boolean hasAmbushAI = card.hasSVar("AmbushAI");
|
||||
boolean defOnlyAmbushAI = hasAmbushAI && "BlockOnly".equals(card.getSVar("AmbushAI"));
|
||||
boolean hasFloatMana = ai.getManaPool().totalMana() > 0;
|
||||
boolean willDiscardNow = isOwnEOT && ai.getCardsIn(ZoneType.Hand).size() > ai.getMaxHandSize();
|
||||
boolean willDieNow = combat != null && ComputerUtilCombat.lifeInSeriousDanger(ai, combat);
|
||||
boolean wantToCastInMain1 = ph.is(PhaseType.MAIN1, ai) && ComputerUtil.castPermanentInMain1(ai, sa);
|
||||
|
||||
// figure out if the card might be a valuable blocker
|
||||
boolean valuableBlocker = false;
|
||||
if (combat != null && combat.getDefendingPlayers().contains(ai)) {
|
||||
// Currently we use a rather simplistic assumption that if we're behind on creature count on board,
|
||||
// a flashed in creature might prove to be good as an additional defender
|
||||
int numUntappedPotentialBlockers = CardLists.filter(ai.getCreaturesInPlay(), new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card card) {
|
||||
return card.isUntapped() && !ComputerUtilCard.isUselessCreature(ai, card);
|
||||
}
|
||||
}).size();
|
||||
|
||||
if (combat.getAttackersOf(ai).size() > numUntappedPotentialBlockers) {
|
||||
valuableBlocker = true;
|
||||
}
|
||||
}
|
||||
|
||||
int chanceToObeyAmbushAI = aic.getIntProperty(AiProps.FLASH_CHANCE_TO_OBEY_AMBUSHAI);
|
||||
int chanceToAddBlocker = aic.getIntProperty(AiProps.FLASH_CHANCE_TO_CAST_AS_VALUABLE_BLOCKER);
|
||||
int chanceToCastForETB = aic.getIntProperty(AiProps.FLASH_CHANCE_TO_CAST_DUE_TO_ETB_EFFECTS);
|
||||
int chanceToRespondToStack = aic.getIntProperty(AiProps.FLASH_CHANCE_TO_RESPOND_TO_STACK_WITH_ETB);
|
||||
int chanceToProcETBBeforeMain1 = aic.getIntProperty(AiProps.FLASH_CHANCE_TO_CAST_FOR_ETB_BEFORE_MAIN1);
|
||||
boolean canCastAtOppTurn = true;
|
||||
for (Card c : ai.getGame().getCardsIn(ZoneType.Battlefield)) {
|
||||
for (StaticAbility s : c.getStaticAbilities()) {
|
||||
if ("CantBeCast".equals(s.getParam("Mode")) && "True".equals(s.getParam("NonCasterTurn"))) {
|
||||
canCastAtOppTurn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (hasFloatMana || willDiscardNow || willDieNow) {
|
||||
// Will lose mana in pool or about to discard a card in cleanup or about to die in combat, so use this opportunity
|
||||
return true;
|
||||
} else if (wantToCastInMain1) {
|
||||
// Would rather cast it in Main 1 or as soon as possible anyway, so go for it
|
||||
return isMyMain1OrLater;
|
||||
} else if (hasAmbushAI && MyRandom.percentTrue(chanceToObeyAmbushAI)) {
|
||||
// Is an ambusher, so try to hold for declare blockers in combat where the AI defends, if possible
|
||||
return defOnlyAmbushAI && canCastAtOppTurn ? isOppDeclareAttackers : (isOppDeclareAttackers || isMyDeclareBlockers);
|
||||
} else if (valuableBlocker && isOppDeclareAttackers && MyRandom.percentTrue(chanceToAddBlocker)) {
|
||||
// Might serve as a valuable blocker in a combat where we are behind on untapped blockers
|
||||
return true;
|
||||
} else if (hasETBTrigger && MyRandom.percentTrue(chanceToCastForETB)) {
|
||||
// Instant speed is good when a card has an ETB trigger, but prolly don't cast in own turn before Main 1 not
|
||||
// to mana lock the AI or lose the chance to consider other options. Try to utilize it as a response to stack
|
||||
// if possible.
|
||||
return isMyMain1OrLater || isOppTurn || MyRandom.percentTrue(chanceToProcETBBeforeMain1);
|
||||
} else if (hasETBTrigger && canRespondToStack && MyRandom.percentTrue(chanceToRespondToStack)) {
|
||||
// Try to do something meaningful in response to an opposing effect on stack. Note that this is currently
|
||||
// too random to likely be meaningful, serious improvement might be needed.
|
||||
return canCastAtOppTurn || ph.getPlayerTurn().equals(ai);
|
||||
} else {
|
||||
// Doesn't have a ETB trigger and doesn't seem to be good as an ambusher, try to surprise the opp before my turn
|
||||
// TODO: maybe implement a way to reserve mana for this
|
||||
return canCastAtOppTurn ? isEOTBeforeMyTurn : isOwnEOT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||
|
||||
|
||||
@@ -7,15 +7,14 @@ import forge.card.CardTypeView;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameType;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.*;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.spellability.Spell;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellPermanent;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.MyRandom;
|
||||
@@ -71,8 +70,25 @@ public class PlayAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that if a ValidZone is specified, there's at least something to choose from in that zone.
|
||||
CardCollectionView validOpts = new CardCollection();
|
||||
if (sa.hasParam("ValidZone")) {
|
||||
validOpts = AbilityUtils.filterListByType(game.getCardsIn(ZoneType.valueOf(sa.getParam("ValidZone"))),
|
||||
sa.getParam("Valid"), sa);
|
||||
if (validOpts.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ("ReplaySpell".equals(logic)) {
|
||||
return ComputerUtil.targetPlayableSpellCard(ai, cards, sa, sa.hasParam("WithoutManaCost"));
|
||||
} else if (logic.startsWith("NeedsChosenCard")) {
|
||||
int minCMC = 0;
|
||||
if (sa.getPayCosts() != null && sa.getPayCosts().getCostMana() != null) {
|
||||
minCMC = sa.getPayCosts().getCostMana().getMana().getCMC();
|
||||
}
|
||||
validOpts = CardLists.filter(validOpts, CardPredicates.greaterCMC(minCMC));
|
||||
return chooseSingleCard(ai, sa, validOpts, sa.hasParam("Optional"), null) != null;
|
||||
}
|
||||
|
||||
if (source != null && source.hasKeyword(Keyword.HIDEAWAY) && source.hasRemembered()) {
|
||||
@@ -138,6 +154,15 @@ public class PlayAi extends SpellAbilityAi {
|
||||
if (!s.getRestrictions().checkTimingRestrictions(c, s))
|
||||
continue;
|
||||
if (sa.hasParam("WithoutManaCost")) {
|
||||
// Try to avoid casting instants and sorceries with X in their cost, since X will be assumed to be 0.
|
||||
if (!(spell instanceof SpellPermanent)) {
|
||||
if (spell.getPayCosts() != null
|
||||
&& spell.getPayCosts().getCostMana() != null
|
||||
&& spell.getPayCosts().getCostMana().getMana().countX() > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
spell = (Spell) spell.copyWithNoManaCost();
|
||||
} else if (sa.hasParam("PlayCost")) {
|
||||
Cost abCost;
|
||||
@@ -150,6 +175,13 @@ public class PlayAi extends SpellAbilityAi {
|
||||
spell = (Spell) spell.copyWithDefinedCost(abCost);
|
||||
}
|
||||
if( AiPlayDecision.WillPlay == ((PlayerControllerAi)ai.getController()).getAi().canPlayFromEffectAI(spell, !isOptional, true)) {
|
||||
// Before accepting, see if the spell has a valid number of targets (it should at this point).
|
||||
// Proceeding past this point if the spell is not correctly targeted will result
|
||||
// in "Failed to add to stack" error and the card disappearing from the game completely.
|
||||
if (!spell.isTargetNumberValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import forge.util.MyRandom;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PowerExchangeAi extends SpellAbilityAi {
|
||||
|
||||
@@ -38,8 +37,7 @@ public class PowerExchangeAi extends SpellAbilityAi {
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
final Map<String, String> vars = c.getSVars();
|
||||
return !vars.containsKey("RemAIDeck") && c.canBeTargetedBy(sa);
|
||||
return !ComputerUtilCard.isCardRemAIDeck(c) && c.canBeTargetedBy(sa);
|
||||
}
|
||||
});
|
||||
CardLists.sortByPowerAsc(list);
|
||||
|
||||
@@ -316,6 +316,9 @@ public class PumpAi extends PumpAiBase {
|
||||
}
|
||||
} else {
|
||||
defense = AbilityUtils.calculateAmount(sa.getHostCard(), numDefense, sa);
|
||||
if (numDefense.contains("X") && sa.getSVar("X").equals("Count$CardsInYourHand") && source.getZone().is(ZoneType.Hand)) {
|
||||
defense--; // the card will be spent casting the spell, so actual toughness is 1 less
|
||||
}
|
||||
}
|
||||
|
||||
int attack;
|
||||
@@ -332,6 +335,9 @@ public class PumpAi extends PumpAiBase {
|
||||
}
|
||||
} else {
|
||||
attack = AbilityUtils.calculateAmount(sa.getHostCard(), numAttack, sa);
|
||||
if (numAttack.contains("X") && sa.getSVar("X").equals("Count$CardsInYourHand") && source.getZone().is(ZoneType.Hand)) {
|
||||
attack--; // the card will be spent casting the spell, so actual power is 1 less
|
||||
}
|
||||
}
|
||||
|
||||
if ("ContinuousBonus".equals(aiLogic)) {
|
||||
@@ -481,6 +487,10 @@ public class PumpAi extends PumpAiBase {
|
||||
} else if (sa.getParam("AILogic").equals("DonateTargetPerm")) {
|
||||
// Donate step 2 - target a donatable permanent.
|
||||
return SpecialCardAi.Donate.considerDonatingPermanent(ai, sa);
|
||||
} else if (sa.getParam("AILogic").equals("SacOneEach")) {
|
||||
// each player sacrifices one permanent, e.g. Vaevictis, Asmadi the Dire - grab the worst for allied and
|
||||
// the best for opponents
|
||||
return SacrificeAi.doSacOneEachLogic(ai, sa);
|
||||
}
|
||||
if (isFight) {
|
||||
return FightAi.canFightAi(ai, sa, attack, defense);
|
||||
|
||||
@@ -15,6 +15,7 @@ import forge.game.card.CardLists;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
@@ -37,6 +38,15 @@ public class PumpAllAi extends PumpAiBase {
|
||||
final Game game = ai.getGame();
|
||||
final Combat combat = game.getCombat();
|
||||
final Cost abCost = sa.getPayCosts();
|
||||
final String logic = sa.getParamOrDefault("AILogic", "");
|
||||
|
||||
if (logic.equals("UntapCombatTrick")) {
|
||||
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||
if (!(ph.is(PhaseType.COMBAT_DECLARE_BLOCKERS, ai)
|
||||
|| (!ph.getPlayerTurn().equals(ai) && ph.is(PhaseType.COMBAT_DECLARE_ATTACKERS)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final int power = AbilityUtils.calculateAmount(sa.getHostCard(), sa.getParam("NumAtt"), sa);
|
||||
final int defense = AbilityUtils.calculateAmount(sa.getHostCard(), sa.getParam("NumDef"), sa);
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
package forge.ai.ability;
|
||||
|
||||
|
||||
import forge.ai.ComputerUtil;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.ai.*;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.player.PlayerCollection;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
public class RearrangeTopOfLibraryAi extends SpellAbilityAi {
|
||||
/* (non-Javadoc)
|
||||
@@ -13,14 +22,22 @@ public class RearrangeTopOfLibraryAi extends SpellAbilityAi {
|
||||
*/
|
||||
@Override
|
||||
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||
return sa.isMandatory(); // AI doesn't do anything with this SA yet, but at least it shouldn't miss mandatory triggers
|
||||
}
|
||||
// Specific details of ordering cards are handled by PlayerControllerAi#orderMoveToZoneList
|
||||
final PhaseHandler ph = aiPlayer.getGame().getPhaseHandler();
|
||||
final Card source = sa.getHostCard();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
||||
*/
|
||||
@Override
|
||||
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||
if (source.isPermanent() && sa.getPayCosts() != null
|
||||
&& (sa.getPayCosts().hasTapCost() || sa.getPayCosts().hasManaCost())) {
|
||||
// If it has an associated cost, try to only do this before own turn
|
||||
if (!(ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == aiPlayer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Do it once per turn, generally (may be improved later)
|
||||
if (AiCardMemory.isRememberedCardByName(aiPlayer, source.getName(), AiCardMemory.MemorySet.ACTIVATED_THIS_TURN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||
|
||||
@@ -28,21 +45,78 @@ public class RearrangeTopOfLibraryAi extends SpellAbilityAi {
|
||||
// ability is targeted
|
||||
sa.resetTargets();
|
||||
|
||||
Player opp = ComputerUtil.getOpponentFor(ai);
|
||||
Player opp = ComputerUtil.getOpponentFor(aiPlayer);
|
||||
final boolean canTgtAI = aiPlayer.canBeTargetedBy(sa);
|
||||
final boolean canTgtHuman = opp.canBeTargetedBy(sa);
|
||||
|
||||
if (!canTgtHuman) {
|
||||
return false;
|
||||
} else {
|
||||
if (canTgtHuman && canTgtAI) {
|
||||
// TODO: maybe some other consideration rather than random?
|
||||
Player preferredTarget = MyRandom.percentTrue(50) ? aiPlayer : opp;
|
||||
sa.getTargets().add(preferredTarget);
|
||||
} else if (canTgtAI) {
|
||||
sa.getTargets().add(aiPlayer);
|
||||
} else if (canTgtHuman) {
|
||||
sa.getTargets().add(opp);
|
||||
} else {
|
||||
return false; // could not find a valid target
|
||||
}
|
||||
|
||||
if (!canTgtHuman || !canTgtAI) {
|
||||
// can't target another player anyway, remember for no second activation this turn
|
||||
AiCardMemory.rememberCard(aiPlayer, source, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN);
|
||||
}
|
||||
} else {
|
||||
// if it's just defined, no big deal
|
||||
AiCardMemory.rememberCard(aiPlayer, source, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN);
|
||||
}
|
||||
|
||||
// TODO: the AI currently doesn't do anything with this ability, consider improving.
|
||||
// For now, "true" is returned (without any action) if the SA is mandatory in order
|
||||
// not to miss triggers.
|
||||
return sa.isMandatory();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
||||
*/
|
||||
@Override
|
||||
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||
// Specific details of ordering cards are handled by PlayerControllerAi#orderMoveToZoneList
|
||||
return mandatory || canPlayAI(ai, sa);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.ability.SpellAbilityAi#confirmAction(forge.game.player.Player, forge.card.spellability.SpellAbility, forge.game.player.PlayerActionConfirmMode, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||
// Confirming this action means shuffling the library if asked.
|
||||
|
||||
// First, let's check if we can play the top card of the library
|
||||
PlayerCollection pc = sa.usesTargeting() ? new PlayerCollection(sa.getTargets().getTargetPlayers())
|
||||
: AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa);
|
||||
|
||||
int uncastableCMCThreshold = 2;
|
||||
int minLandsToScryLandsAway = 4;
|
||||
if (player.getController().isAI()) {
|
||||
AiController aic = ((PlayerControllerAi)player.getController()).getAi();
|
||||
minLandsToScryLandsAway = aic.getIntProperty(AiProps.SCRY_NUM_LANDS_TO_NOT_NEED_MORE);
|
||||
uncastableCMCThreshold = aic.getIntProperty(AiProps.SCRY_IMMEDIATELY_UNCASTABLE_CMC_DIFF);
|
||||
}
|
||||
|
||||
Player p = pc.getFirst(); // FIXME: is this always a single target spell?
|
||||
Card top = p.getCardsIn(ZoneType.Library).getFirst();
|
||||
int landsOTB = CardLists.filter(p.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.LANDS_PRODUCING_MANA).size();
|
||||
int cmc = top.isSplitCard() ? Math.min(top.getCMC(Card.SplitCMCMode.LeftSplitCMC), top.getCMC(Card.SplitCMCMode.RightSplitCMC))
|
||||
: top.getCMC();
|
||||
int maxCastable = ComputerUtilMana.getAvailableManaEstimate(p, false);
|
||||
|
||||
if (!top.isLand() && cmc - maxCastable >= uncastableCMCThreshold) {
|
||||
// Can't cast in the foreseeable future. Shuffle if doing it to ourselves or an ally, otherwise keep it
|
||||
return !p.isOpponentOf(player);
|
||||
} else if (top.isLand() && landsOTB <= minLandsToScryLandsAway){
|
||||
// We don't want to give the opponent a free land if his land count is low
|
||||
return p.isOpponentOf(player);
|
||||
}
|
||||
|
||||
// Usually we don't want to shuffle if we arranged things carefully
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import forge.ai.ComputerUtil;
|
||||
import forge.ai.ComputerUtilCard;
|
||||
import forge.ai.ComputerUtilMana;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates;
|
||||
import forge.game.keyword.Keyword;
|
||||
@@ -133,7 +135,7 @@ public class SacrificeAi extends SpellAbilityAi {
|
||||
List<Card> humanList =
|
||||
CardLists.getValidCards(opp.getCardsIn(ZoneType.Battlefield), valid.split(","), sa.getActivatingPlayer(), sa.getHostCard(), sa);
|
||||
|
||||
// Since all of the cards have remAIDeck:True, I enabled 1 for 1
|
||||
// Since all of the cards have AI:RemoveDeck:All, I enabled 1 for 1
|
||||
// (or X for X) trades for special decks
|
||||
if (humanList.size() < amount) {
|
||||
return false;
|
||||
@@ -157,4 +159,41 @@ public class SacrificeAi extends SpellAbilityAi {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean doSacOneEachLogic(Player ai, SpellAbility sa) {
|
||||
Game game = ai.getGame();
|
||||
|
||||
sa.resetTargets();
|
||||
for (Player p : game.getPlayers()) {
|
||||
CardCollection targetable = CardLists.filter(p.getCardsIn(ZoneType.Battlefield), CardPredicates.isTargetableBy(sa));
|
||||
if (!targetable.isEmpty()) {
|
||||
CardCollection priorityTgts = new CardCollection();
|
||||
if (p.isOpponentOf(ai)) {
|
||||
priorityTgts.addAll(CardLists.filter(targetable, CardPredicates.canBeSacrificedBy(sa)));
|
||||
if (!priorityTgts.isEmpty()) {
|
||||
sa.getTargets().add(ComputerUtilCard.getBestAI(priorityTgts));
|
||||
} else {
|
||||
sa.getTargets().add(ComputerUtilCard.getBestAI(targetable));
|
||||
}
|
||||
} else {
|
||||
for (Card c : targetable) {
|
||||
if (c.canBeSacrificedBy(sa) && (c.hasSVar("SacMe") || (c.isCreature() && ComputerUtilCard.evaluateCreature(c) <= 135)) && !c.equals(sa.getHostCard())) {
|
||||
priorityTgts.add(c);
|
||||
}
|
||||
}
|
||||
if (!priorityTgts.isEmpty()) {
|
||||
sa.getTargets().add(ComputerUtilCard.getWorstPermanentAI(priorityTgts, false, false, false, false));
|
||||
} else {
|
||||
targetable.remove(sa.getHostCard());
|
||||
if (!targetable.isEmpty()) {
|
||||
sa.getTargets().add(ComputerUtilCard.getWorstPermanentAI(targetable, true, true, true, false));
|
||||
} else {
|
||||
sa.getTargets().add(sa.getHostCard()); // sac self only as a last resort
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,31 +29,8 @@ public class SetStateAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
// Prevent transform into legendary creature if copy already exists
|
||||
// Check first if Legend Rule does still apply
|
||||
if (!aiPlayer.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)) {
|
||||
if (!source.hasAlternateState()) {
|
||||
System.err.println("Warning: SetState without ALTERNATE on " + source.getName() + ".");
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if the other side is legendary and if such Card already is in Play
|
||||
final CardState other = source.getAlternateState();
|
||||
|
||||
if (other != null && other.getType().isLegendary() && aiPlayer.isCardInPlay(other.getName())) {
|
||||
if (!other.getType().isCreature()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Card othercard = aiPlayer.getCardsIn(ZoneType.Battlefield, other.getName()).getFirst();
|
||||
|
||||
// for legendary KI counter creatures
|
||||
if (othercard.getCounters(CounterType.KI) >= source.getCounters(CounterType.KI)) {
|
||||
// if the other legendary is useless try to replace it
|
||||
if (!ComputerUtilCard.isUselessCreature(aiPlayer, othercard)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isSafeToTransformIntoLegendary(aiPlayer, source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if("Transform".equals(mode) || "Flip".equals(mode)) {
|
||||
@@ -255,8 +232,44 @@ public class SetStateAi extends SpellAbilityAi {
|
||||
return valueCard <= valueTransformed;
|
||||
}
|
||||
|
||||
private boolean isSafeToTransformIntoLegendary(Player aiPlayer, Card source) {
|
||||
// Prevent transform into legendary creature if copy already exists
|
||||
// Check first if Legend Rule does still apply
|
||||
if (!aiPlayer.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)) {
|
||||
if (!source.hasAlternateState()) {
|
||||
System.err.println("Warning: SetState without ALTERNATE on " + source.getName() + ".");
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if the other side is legendary and if such Card already is in Play
|
||||
final CardState other = source.getAlternateState();
|
||||
|
||||
if (other != null && other.getType().isLegendary() && aiPlayer.isCardInPlay(other.getName())) {
|
||||
if (!other.getType().isCreature()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Card othercard = aiPlayer.getCardsIn(ZoneType.Battlefield, other.getName()).getFirst();
|
||||
|
||||
// for legendary KI counter creatures
|
||||
if (othercard.getCounters(CounterType.KI) >= source.getCounters(CounterType.KI)) {
|
||||
// if the other legendary is useless try to replace it
|
||||
if (!ComputerUtilCard.isUselessCreature(aiPlayer, othercard)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||
// TODO: improve the AI for when it may want to transform something that's optional to transform
|
||||
if (!isSafeToTransformIntoLegendary(player, sa.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ import forge.game.spellability.SpellAbility;
|
||||
public class ShuffleAi extends SpellAbilityAi {
|
||||
@Override
|
||||
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||
String logic = sa.getParamOrDefault("AILogic", "");
|
||||
if (logic.equals("Always")) {
|
||||
// We may want to play this for the subability, e.g. Mind's Desire
|
||||
return true;
|
||||
}
|
||||
|
||||
// not really sure when the compy would use this; maybe only after a
|
||||
// human
|
||||
// deliberately put a card on top of their library
|
||||
@@ -47,7 +53,7 @@ public class ShuffleAi extends SpellAbilityAi {
|
||||
|
||||
@Override
|
||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||
// ai could analyze parameter denoting the player to shuffle
|
||||
// ai could analyze parameter denoting the player to shuffle
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package forge.ai.ability;
|
||||
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.ai.*;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.cost.CostPayLife;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
@@ -68,8 +71,14 @@ public class SurveilAi extends SpellAbilityAi {
|
||||
*/
|
||||
@Override
|
||||
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
|
||||
final Card source = sa.getHostCard();
|
||||
|
||||
if ("Never".equals(aiLogic)) {
|
||||
return false;
|
||||
} else if ("Once".equals(aiLogic)) {
|
||||
if (AiCardMemory.isRememberedCard(ai, source, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add card-specific Surveil AI logic here when/if necessary
|
||||
@@ -84,6 +93,15 @@ public class SurveilAi extends SpellAbilityAi {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only Surveil for life when at decent amount of life remaining
|
||||
final Cost cost = sa.getPayCosts();
|
||||
if (cost != null && cost.hasSpecificCostType(CostPayLife.class)) {
|
||||
final int maxLife = ((PlayerControllerAi)ai.getController()).getAi().getIntProperty(AiProps.SURVEIL_LIFEPERC_AFTER_PAYING_LIFE);
|
||||
if (!ComputerUtilCost.checkLifeCost(ai, cost, sa.getHostCard(), ai.getStartingLife() * maxLife / 100, sa)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
double chance = .4; // 40 percent chance for instant speed
|
||||
if (SpellAbilityAi.isSorcerySpeed(sa)) {
|
||||
chance = .667; // 66.7% chance for sorcery speed (since it will never activate EOT)
|
||||
@@ -94,6 +112,10 @@ public class SurveilAi extends SpellAbilityAi {
|
||||
randomReturn = true;
|
||||
}
|
||||
|
||||
if (randomReturn) {
|
||||
AiCardMemory.rememberCard(ai, sa.getHostCard(), AiCardMemory.MemorySet.ACTIVATED_THIS_TURN);
|
||||
}
|
||||
|
||||
return randomReturn;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ import forge.game.GameEntity;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.ability.effects.TokenEffect;
|
||||
import forge.game.card.*;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates;
|
||||
import forge.game.card.token.TokenInfo;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.cost.CostPart;
|
||||
@@ -58,20 +60,9 @@ public class TokenAi extends SpellAbilityAi {
|
||||
private void readParameters(final SpellAbility mapParams) {
|
||||
this.tokenAmount = mapParams.getParamOrDefault("TokenAmount", "1");
|
||||
|
||||
TokenEffect effect = new TokenEffect();
|
||||
|
||||
this.actualToken = effect.loadTokenPrototype(mapParams);
|
||||
this.actualToken = TokenInfo.getProtoType(mapParams.getParam("TokenScript"), mapParams);
|
||||
|
||||
if (actualToken == null) {
|
||||
String[] keywords;
|
||||
|
||||
if (mapParams.hasParam("TokenKeywords")) {
|
||||
// TODO: Change this Split to a semicolon or something else
|
||||
keywords = mapParams.getParam("TokenKeywords").split("<>");
|
||||
} else {
|
||||
keywords = new String[0];
|
||||
}
|
||||
|
||||
this.tokenPower = mapParams.getParam("TokenPower");
|
||||
this.tokenToughness = mapParams.getParam("TokenToughness");
|
||||
} else {
|
||||
@@ -340,6 +331,7 @@ public class TokenAi extends SpellAbilityAi {
|
||||
@Override
|
||||
protected Player chooseSinglePlayer(Player ai, SpellAbility sa, Iterable<Player> options) {
|
||||
// TODO: AILogic
|
||||
readParameters(sa); // remember to call this somewhere!
|
||||
Combat combat = ai.getGame().getCombat();
|
||||
// TokenAttacking
|
||||
if (combat != null && sa.hasParam("TokenAttacking")) {
|
||||
@@ -359,6 +351,7 @@ public class TokenAi extends SpellAbilityAi {
|
||||
@Override
|
||||
protected GameEntity chooseSinglePlayerOrPlaneswalker(Player ai, SpellAbility sa, Iterable<GameEntity> options) {
|
||||
// TODO: AILogic
|
||||
readParameters(sa); // remember to call this somewhere!
|
||||
Combat combat = ai.getGame().getCombat();
|
||||
// TokenAttacking
|
||||
if (combat != null && sa.hasParam("TokenAttacking")) {
|
||||
@@ -389,6 +382,7 @@ public class TokenAi extends SpellAbilityAi {
|
||||
* @param sa Token SpellAbility
|
||||
* @return token creature created by ability
|
||||
*/
|
||||
@Deprecated
|
||||
public static Card spawnToken(Player ai, SpellAbility sa) {
|
||||
return spawnToken(ai, sa, false);
|
||||
}
|
||||
@@ -401,9 +395,17 @@ public class TokenAi extends SpellAbilityAi {
|
||||
* @return token creature created by ability
|
||||
*/
|
||||
// TODO Is this just completely copied from TokenEffect? Let's just call that thing
|
||||
@Deprecated
|
||||
public static Card spawnToken(Player ai, SpellAbility sa, boolean notNull) {
|
||||
final Card host = sa.getHostCard();
|
||||
|
||||
Card result = TokenInfo.getProtoType(sa.getParam("TokenScript"), sa);
|
||||
|
||||
if (result != null) {
|
||||
result.setController(ai, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
String[] tokenKeywords = sa.hasParam("TokenKeywords") ? sa.getParam("TokenKeywords").split("<>") : new String[0];
|
||||
String tokenPower = sa.getParam("TokenPower");
|
||||
String tokenToughness = sa.getParam("TokenToughness");
|
||||
|
||||
@@ -5,6 +5,7 @@ import forge.game.ability.ApiType;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollectionView;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.AbilitySub;
|
||||
@@ -23,7 +24,7 @@ public class UntapAllAi extends SpellAbilityAi {
|
||||
return false;
|
||||
}
|
||||
String valid = "";
|
||||
CardCollectionView list = aiPlayer.getGame().getCardsIn(ZoneType.Battlefield);
|
||||
CardCollectionView list = CardLists.filter(aiPlayer.getGame().getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.TAPPED);
|
||||
if (sa.hasParam("ValidCards")) {
|
||||
valid = sa.getParam("ValidCards");
|
||||
}
|
||||
@@ -35,6 +36,15 @@ public class UntapAllAi extends SpellAbilityAi {
|
||||
|
||||
@Override
|
||||
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||
Card source = sa.getHostCard();
|
||||
|
||||
if (sa.hasParam("ValidCards")) {
|
||||
String valid = sa.getParam("ValidCards");
|
||||
CardCollectionView list = CardLists.filter(aiPlayer.getGame().getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.TAPPED);
|
||||
list = CardLists.getValidCards(list, valid.split(","), source.getController(), source, sa);
|
||||
return mandatory || !list.isEmpty();
|
||||
}
|
||||
|
||||
return mandatory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ZoneExchangeAi extends SpellAbilityAi {
|
||||
}
|
||||
if (type.equals("Aura")) {
|
||||
Card c = object1.getEnchantingCard();
|
||||
if (!c.canBeEnchantedBy(object2)) {
|
||||
if (!c.canBeAttached(object2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import forge.LobbyPlayer;
|
||||
import forge.ai.LobbyPlayerAi;
|
||||
import forge.card.CardStateName;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.GameObjectMap;
|
||||
import forge.game.GameRules;
|
||||
@@ -204,19 +205,16 @@ public class GameCopier {
|
||||
}
|
||||
}
|
||||
gameObjectMap = new CopiedGameObjectMap(newGame);
|
||||
|
||||
for (Card card : origGame.getCardsIn(ZoneType.Battlefield)) {
|
||||
Card otherCard = cardMap.get(card);
|
||||
otherCard.setTimestamp(card.getTimestamp());
|
||||
otherCard.setSickness(card.hasSickness());
|
||||
otherCard.setState(card.getCurrentStateName(), false);
|
||||
if (card.isEnchanting()) {
|
||||
otherCard.setEnchanting(gameObjectMap.map(card.getEnchanting()));
|
||||
}
|
||||
if (card.isEquipping()) {
|
||||
otherCard.equipCard(cardMap.get(card.getEquipping()));
|
||||
}
|
||||
if (card.isFortifying()) {
|
||||
otherCard.setFortifying(cardMap.get(card.getFortifying()));
|
||||
if (card.isAttachedToEntity()) {
|
||||
GameEntity ge = gameObjectMap.map(card.getEntityAttachedTo());
|
||||
otherCard.setEntityAttachedTo(ge);
|
||||
ge.addAttachedCard(otherCard);
|
||||
}
|
||||
if (card.getCloneOrigin() != null) {
|
||||
otherCard.setCloneOrigin(cardMap.get(card.getCloneOrigin()));
|
||||
@@ -312,7 +310,8 @@ public class GameCopier {
|
||||
newCard.setManifested(true);
|
||||
// TODO: Should be able to copy other abilities...
|
||||
if (isCreature && hasManaCost) {
|
||||
newCard.addSpellAbility(CardFactoryUtil.abilityManifestFaceUp(newCard, newCard.getManaCost()));
|
||||
newCard.getState(CardStateName.Original).addSpellAbility(
|
||||
CardFactoryUtil.abilityManifestFaceUp(newCard, newCard.getManaCost()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>forge-core</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,4 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=ISO-8859-1
|
||||
encoding//src/test/java=ISO-8859-1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -1,5 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -1,4 +0,0 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>forge</artifactId>
|
||||
<groupId>forge</groupId>
|
||||
<version>1.6.18-SNAPSHOT</version>
|
||||
<version>1.6.22-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>forge-core</artifactId>
|
||||
|
||||
@@ -352,9 +352,18 @@ public final class CardRules implements ICardCharacteristics {
|
||||
|
||||
switch(key.charAt(0)) {
|
||||
case 'A':
|
||||
if ("A".equals(key))
|
||||
if ("A".equals(key)) {
|
||||
this.faces[curFace].addAbility(value);
|
||||
else if ("AlternateMode".equals(key)) {
|
||||
} else if ("AI".equals(key)) {
|
||||
colonPos = value.indexOf(':');
|
||||
String variable = colonPos > 0 ? value.substring(0, colonPos) : value;
|
||||
value = colonPos > 0 ? value.substring(1+colonPos) : null;
|
||||
|
||||
if ( "RemoveDeck".equals(variable) ) {
|
||||
this.removedFromAIDecks = "All".equalsIgnoreCase(value);
|
||||
this.removedFromRandomDecks = "Random".equalsIgnoreCase(value);
|
||||
}
|
||||
} else if ("AlternateMode".equals(key)) {
|
||||
//System.out.println(faces[curFace].getName());
|
||||
this.altMode = CardSplitType.smartValueOf(value);
|
||||
} else if ("ALTERNATE".equals(key)) {
|
||||
@@ -447,11 +456,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
String variable = colonPos > 0 ? value.substring(0, colonPos) : value;
|
||||
value = colonPos > 0 ? value.substring(1+colonPos) : null;
|
||||
|
||||
if ( "RemAIDeck".equals(variable) ) {
|
||||
this.removedFromAIDecks = "True".equalsIgnoreCase(value);
|
||||
} else if ( "RemRandomDeck".equals(variable) ) {
|
||||
this.removedFromRandomDecks = "True".equalsIgnoreCase(value);
|
||||
} else if ( "Picture".equals(variable) ) {
|
||||
if ( "Picture".equals(variable) ) {
|
||||
this.pictureUrl[this.curFace] = value;
|
||||
} else
|
||||
this.faces[curFace].addSVar(variable, value);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import forge.StaticData;
|
||||
import forge.card.CardDb;
|
||||
@@ -216,4 +217,17 @@ public class CardPool extends ItemPool<PaperCard> {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a predicate to this CardPool's cards.
|
||||
* @param predicate the Predicate to apply to this CardPool
|
||||
* @return a new CardPool made from this CardPool with only the cards that agree with the provided Predicate
|
||||
*/
|
||||
public CardPool getFilteredPool(Predicate<PaperCard> predicate){
|
||||
CardPool filteredPool = new CardPool();
|
||||
for(PaperCard pc : this.items.keySet()){
|
||||
if(predicate.apply(pc)) filteredPool.add(pc);
|
||||
}
|
||||
return filteredPool;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ package forge.deck;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.StaticData;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
@@ -47,7 +49,7 @@ public enum DeckFormat {
|
||||
QuestDeck ( Range.between(40, Integer.MAX_VALUE), Range.between(0, 15), 4),
|
||||
Limited ( Range.between(40, Integer.MAX_VALUE), null, Integer.MAX_VALUE),
|
||||
Commander ( Range.is(99), Range.between(0, 10), 1, new Predicate<CardRules>() {
|
||||
private final Set<String> bannedCards = new HashSet<String>(Arrays.asList(
|
||||
private final Set<String> bannedCards = ImmutableSet.of(
|
||||
"Adriana's Valor", "Advantageous Proclamation", "Amulet of Quoz", "Ancestral Recall", "Assemble the Rank and Vile",
|
||||
"Backup Plan", "Balance", "Biorhythm", "Black Lotus", "Brago's Favor", "Braids, Cabal Minion", "Bronze Tablet",
|
||||
"Channel", "Chaos Orb", "Coalition Victory", "Contract from Below", "Darkpact", "Demonic Attorney", "Double Stroke",
|
||||
@@ -59,7 +61,7 @@ public enum DeckFormat {
|
||||
"Rebirth", "Recurring Nightmare", "Rofellos, Llanowar Emissary", "Secret Summoning", "Secrets of Paradise",
|
||||
"Sentinel Dispatch", "Shahrazad", "Sovereign's Realm", "Summoner's Bond", "Sundering Titan", "Sway of the Stars",
|
||||
"Sylvan Primordial", "Tempest Efreet", "Time Vault", "Time Walk", "Timmerian Fiends", "Tinker", "Tolarian Academy",
|
||||
"Trade Secrets", "Unexpected Potential", "Upheaval", "Weight Advantage", "Worldfire", "Worldknit", "Yawgmoth's Bargain"));
|
||||
"Trade Secrets", "Unexpected Potential", "Upheaval", "Weight Advantage", "Worldfire", "Worldknit", "Yawgmoth's Bargain");
|
||||
@Override
|
||||
public boolean apply(CardRules rules) {
|
||||
if (bannedCards.contains(rules.getName())) {
|
||||
@@ -70,8 +72,8 @@ public enum DeckFormat {
|
||||
}),
|
||||
Pauper ( Range.is(60), Range.between(0, 10), 1),
|
||||
Brawl ( Range.is(59), Range.between(0, 15), 1, null, new Predicate<PaperCard>() {
|
||||
private final Set<String> bannedCards = new HashSet<String>(Arrays.asList(
|
||||
"Baral, Chief of Compliance","Smuggler's Copter","Sorcerous Spyglass"));
|
||||
private final Set<String> bannedCards = ImmutableSet.of(
|
||||
"Baral, Chief of Compliance","Smuggler's Copter","Sorcerous Spyglass");
|
||||
@Override
|
||||
public boolean apply(PaperCard card) {
|
||||
//why do we need to hard code the bannings here - they are defined in the GameFormat predicate used below
|
||||
@@ -81,7 +83,7 @@ public enum DeckFormat {
|
||||
return StaticData.instance() == null ? false : StaticData.instance().getBrawlPredicate().apply(card);
|
||||
}
|
||||
}) {
|
||||
private final ImmutableSet<String> bannedCommanders = ImmutableSet.of("Baral, Chief of Compliance");
|
||||
private final Set<String> bannedCommanders = ImmutableSet.of("Baral, Chief of Compliance");
|
||||
|
||||
@Override
|
||||
public boolean isLegalCommander(CardRules rules) {
|
||||
@@ -89,11 +91,11 @@ public enum DeckFormat {
|
||||
}
|
||||
},
|
||||
TinyLeaders ( Range.is(49), Range.between(0, 10), 1, new Predicate<CardRules>() {
|
||||
private final Set<String> bannedCards = new HashSet<String>(Arrays.asList(
|
||||
private final Set<String> bannedCards = ImmutableSet.of(
|
||||
"Ancestral Recall", "Balance", "Black Lotus", "Black Vise", "Channel", "Chaos Orb", "Contract From Below", "Counterbalance", "Darkpact", "Demonic Attorney", "Demonic Tutor", "Earthcraft", "Edric, Spymaster of Trest", "Falling Star",
|
||||
"Fastbond", "Flash", "Goblin Recruiter", "Grindstone", "Hermit Druid", "Imperial Seal", "Jeweled Bird", "Karakas", "Library of Alexandria", "Mana Crypt", "Mana Drain", "Mana Vault", "Metalworker", "Mind Twist", "Mishra's Workshop",
|
||||
"Mox Emerald", "Mox Jet", "Mox Pearl", "Mox Ruby", "Mox Sapphire", "Necropotence", "Shahrazad", "Skullclamp", "Sol Ring", "Strip Mine", "Survival of the Fittest", "Sword of Body and Mind", "Time Vault", "Time Walk", "Timetwister",
|
||||
"Timmerian Fiends", "Tolarian Academy", "Umezawa's Jitte", "Vampiric Tutor", "Wheel of Fortune", "Yawgmoth's Will"));
|
||||
"Timmerian Fiends", "Tolarian Academy", "Umezawa's Jitte", "Vampiric Tutor", "Wheel of Fortune", "Yawgmoth's Will");
|
||||
|
||||
@Override
|
||||
public boolean apply(CardRules rules) {
|
||||
@@ -112,7 +114,7 @@ public enum DeckFormat {
|
||||
return true;
|
||||
}
|
||||
}) {
|
||||
private final ImmutableSet<String> bannedCommanders = ImmutableSet.of("Derevi, Empyrial Tactician", "Erayo, Soratami Ascendant", "Rofellos, Llanowar Emissary");
|
||||
private final Set<String> bannedCommanders = ImmutableSet.of("Derevi, Empyrial Tactician", "Erayo, Soratami Ascendant", "Rofellos, Llanowar Emissary");
|
||||
|
||||
@Override
|
||||
public boolean isLegalCommander(CardRules rules) {
|
||||
@@ -141,13 +143,6 @@ public enum DeckFormat {
|
||||
private final static String ADVPROCLAMATION = "Advantageous Proclamation";
|
||||
private final static String SOVREALM = "Sovereign's Realm";
|
||||
|
||||
private static final List<String> limitExceptions = Arrays.asList(
|
||||
new String[]{"Relentless Rats", "Shadowborn Apostle", "Rat Colony"});
|
||||
|
||||
public static List<String> getLimitExceptions(){
|
||||
return limitExceptions;
|
||||
}
|
||||
|
||||
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0, Predicate<PaperCard> paperCardPoolFilter0) {
|
||||
mainRange = mainRange0;
|
||||
sideRange = sideRange0;
|
||||
@@ -342,7 +337,6 @@ public enum DeckFormat {
|
||||
//basic lands, Shadowborn Apostle, Relentless Rats and Rat Colony
|
||||
|
||||
final CardPool allCards = deck.getAllCardsInASinglePool(hasCommander());
|
||||
final ImmutableSet<String> limitExceptions = ImmutableSet.of("Relentless Rats", "Shadowborn Apostle", "Rat Colony");
|
||||
|
||||
// should group all cards by name, so that different editions of same card are really counted as the same card
|
||||
for (final Entry<String, Integer> cp : Aggregates.groupSumBy(allCards, PaperCard.FN_GET_NAME)) {
|
||||
@@ -351,8 +345,7 @@ public enum DeckFormat {
|
||||
return TextUtil.concatWithSpace("contains the nonexisting card", cp.getKey());
|
||||
}
|
||||
|
||||
final boolean canHaveMultiple = simpleCard.getRules().getType().isBasicLand() || limitExceptions.contains(cp.getKey());
|
||||
if (!canHaveMultiple && cp.getValue() > maxCopies) {
|
||||
if (!canHaveAnyNumberOf(simpleCard) && cp.getValue() > maxCopies) {
|
||||
return TextUtil.concatWithSpace("must not contain more than", String.valueOf(maxCopies), "copies of the card", cp.getKey());
|
||||
}
|
||||
}
|
||||
@@ -370,6 +363,12 @@ public enum DeckFormat {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean canHaveAnyNumberOf(final IPaperCard icard) {
|
||||
return icard.getRules().getType().isBasicLand()
|
||||
|| Iterables.contains(icard.getRules().getMainPart().getKeywords(),
|
||||
"A deck can have any number of cards named CARDNAME.");
|
||||
}
|
||||
|
||||
public static String getPlaneSectionConformanceProblem(final CardPool planes) {
|
||||
//Must contain at least 10 planes/phenomenons, but max 2 phenomenons. Singleton.
|
||||
if (planes == null || planes.countAll() < 10) {
|
||||
|
||||
@@ -102,6 +102,7 @@ public class DeckRecognizer {
|
||||
// Pattern.compile("(.*)[^A-Za-wyz]*\\s+([\\d]{1,2})");
|
||||
private static final Pattern SEARCH_NUMBERS_IN_FRONT = Pattern.compile("([\\d]{1,2})[^A-Za-wyz]*\\s+(.*)");
|
||||
//private static final Pattern READ_SEPARATED_EDITION = Pattern.compile("[[\\(\\{]([a-zA-Z0-9]){1,3})[]*\\s+(.*)");
|
||||
private static final Pattern SEARCH_SINGLE_SLASH = Pattern.compile("(?<=[^/])\\s*/\\s*(?=[^/])");
|
||||
|
||||
private final SetPreference useLastSet;
|
||||
private final ICardDatabase db;
|
||||
@@ -125,7 +126,10 @@ public class DeckRecognizer {
|
||||
return new Token(TokenType.Comment, 0, rawLine);
|
||||
}
|
||||
final char smartQuote = (char) 8217;
|
||||
final String line = rawLine.trim().replace(smartQuote, '\'');
|
||||
String line = rawLine.trim().replace(smartQuote, '\'');
|
||||
|
||||
// Some websites export split card names with a single slash. Replace with double slash.
|
||||
line = SEARCH_SINGLE_SLASH.matcher(line).replaceFirst(" // ");
|
||||
|
||||
Token result = null;
|
||||
final Matcher foundNumbersInFront = DeckRecognizer.SEARCH_NUMBERS_IN_FRONT.matcher(line);
|
||||
|
||||
@@ -96,32 +96,31 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
build.add(keyword);
|
||||
}
|
||||
|
||||
build.add(edition.getCode());
|
||||
if (edition != null) {
|
||||
build.add(edition.getCode());
|
||||
}
|
||||
|
||||
// Should future image file names be all lower case? Instead of Up case sets?
|
||||
return StringUtils.join(build, "_").toLowerCase();
|
||||
return StringUtils.join(build, "_").replace('*', 'x').toLowerCase();
|
||||
}
|
||||
|
||||
public PaperToken(final CardRules c) { this(c, null, null); }
|
||||
public PaperToken(final CardRules c, final String fileName) { this(c, null, fileName); }
|
||||
public PaperToken(final CardRules c, CardEdition edition) { this(c, edition, null); }
|
||||
public PaperToken(final CardRules c, CardEdition edition0, String imageFileName) {
|
||||
this.card = c;
|
||||
this.name = c.getName();
|
||||
this.edition = edition0;
|
||||
|
||||
if (imageFileName == null) {
|
||||
// This shouldn't really happen. We can just use the normalized name again for the base image name
|
||||
this.imageFileName = makeTokenFileName(c, edition0);
|
||||
} else {
|
||||
String formatEdition = null == edition || CardEdition.UNKNOWN == edition ? "" : edition.getCode();
|
||||
this.imageFileName = String.format("%s%s", formatEdition, imageFileName);
|
||||
String formatEdition = null == edition || CardEdition.UNKNOWN == edition ? "" : "_" + edition.getCode().toLowerCase();
|
||||
this.imageFileName = String.format("%s%s", imageFileName, formatEdition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String getName() { return name; }
|
||||
|
||||
@Override public String toString() { return name; }
|
||||
@Override public String getEdition() { return edition.getCode(); }
|
||||
@Override public String getEdition() { return edition != null ? edition.getCode() : "???"; }
|
||||
@Override public int getArtIndex() { return 0; } // This might change however
|
||||
@Override public boolean isFoil() { return false; }
|
||||
@Override public CardRules getRules() { return card; }
|
||||
|
||||
@@ -2,7 +2,9 @@ package forge.token;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Maps;
|
||||
import forge.card.*;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
import forge.item.PaperToken;
|
||||
|
||||
import java.util.*;
|
||||
@@ -43,11 +45,11 @@ public class TokenDb implements ITokenDatabase {
|
||||
|
||||
if (!tokensByName.containsKey(fullName)) {
|
||||
try {
|
||||
PaperToken pt = new PaperToken(rulesByName.get(tokenName), editions.get(edition));
|
||||
PaperToken pt = new PaperToken(rulesByName.get(tokenName), editions.get(edition), tokenName);
|
||||
tokensByName.put(fullName, pt);
|
||||
return pt;
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ public class Localizer {
|
||||
MessageFormat formatter = null;
|
||||
|
||||
try {
|
||||
formatter = new MessageFormat(resourceBundle.getString(key.toLowerCase()), locale);
|
||||
//formatter = new MessageFormat(resourceBundle.getString(key.toLowerCase()), locale);
|
||||
formatter = new MessageFormat(resourceBundle.getString(key.toString()), locale);
|
||||
} catch (final IllegalArgumentException | MissingResourceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -86,7 +87,7 @@ public class Localizer {
|
||||
resourceBundle = ResourceBundle.getBundle(languageRegionID, new Locale(splitLocale[0], splitLocale[1]), loader);
|
||||
} catch (NullPointerException | MissingResourceException e) {
|
||||
//If the language can't be loaded, default to US English
|
||||
resourceBundle = ResourceBundle.getBundle("en-GB", new Locale("en", "GB"), loader);
|
||||
resourceBundle = ResourceBundle.getBundle("en-US", new Locale("en", "US"), loader);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/forge-core"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>forge-game</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,4 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=ISO-8859-1
|
||||
encoding//src/test/java=ISO-8859-1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -1,5 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -1,4 +0,0 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>forge</artifactId>
|
||||
<groupId>forge</groupId>
|
||||
<version>1.6.18-SNAPSHOT</version>
|
||||
<version>1.6.22-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>forge-game</artifactId>
|
||||
|
||||
@@ -152,7 +152,15 @@ public class ForgeScript {
|
||||
|
||||
public static boolean spellAbilityHasProperty(SpellAbility sa, String property, Player sourceController,
|
||||
Card source, SpellAbility spellAbility) {
|
||||
if (property.equals("Buyback")) {
|
||||
if (property.equals("ManaAbility")) {
|
||||
if (!sa.isManaAbility()) {
|
||||
return false;
|
||||
}
|
||||
} else if (property.equals("nonManaAbility")) {
|
||||
if (sa.isManaAbility()) {
|
||||
return false;
|
||||
}
|
||||
} else if (property.equals("Buyback")) {
|
||||
if (!sa.isBuyBackAbility()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ public class Game {
|
||||
* Gets the players who participated in match (regardless of outcome).
|
||||
* <i>Use this in UI and after match calculations</i>
|
||||
*/
|
||||
public final List<Player> getRegisteredPlayers() {
|
||||
public final PlayerCollection getRegisteredPlayers() {
|
||||
return allPlayers;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import forge.game.ability.effects.AttachEffect;
|
||||
import forge.game.card.*;
|
||||
import forge.game.event.*;
|
||||
import forge.game.keyword.KeywordInterface;
|
||||
import forge.game.keyword.KeywordsChange;
|
||||
import forge.game.player.GameLossReason;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.replacement.ReplacementEffect;
|
||||
@@ -36,7 +37,6 @@ import forge.game.replacement.ReplacementResult;
|
||||
import forge.game.spellability.AbilitySub;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityPredicates;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.staticability.StaticAbilityLayer;
|
||||
import forge.game.trigger.Trigger;
|
||||
@@ -51,9 +51,9 @@ import forge.util.collect.FCollection;
|
||||
import forge.util.collect.FCollectionView;
|
||||
import forge.util.maps.HashMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Methods for common actions performed during a game.
|
||||
@@ -71,10 +71,8 @@ public class GameAction {
|
||||
}
|
||||
|
||||
public final void resetActivationsPerTurn() {
|
||||
final CardCollectionView all = game.getCardsInGame();
|
||||
|
||||
// Reset Activations per Turn
|
||||
for (final Card card : all) {
|
||||
for (final Card card : game.getCardsInGame()) {
|
||||
for (final SpellAbility sa : card.getAllSpellAbilities()) {
|
||||
sa.getRestrictions().resetTurnActivations();
|
||||
}
|
||||
@@ -105,6 +103,7 @@ public class GameAction {
|
||||
boolean toBattlefield = zoneTo.is(ZoneType.Battlefield);
|
||||
boolean fromBattlefield = zoneFrom != null && zoneFrom.is(ZoneType.Battlefield);
|
||||
boolean toHand = zoneTo.is(ZoneType.Hand);
|
||||
boolean wasFacedown = c.isFaceDown();
|
||||
|
||||
//Rule 110.5g: A token that has left the battlefield can't move to another zone
|
||||
if (c.isToken() && zoneFrom != null && !fromBattlefield && !zoneFrom.is(ZoneType.Command)) {
|
||||
@@ -148,16 +147,11 @@ public class GameAction {
|
||||
}
|
||||
}
|
||||
|
||||
// Cards returned from exile face-down must be reset to their original state, otherwise
|
||||
// all sort of funky shenanigans may happen later (e.g. their ETB replacement effects are set
|
||||
// up on the wrong card state etc.).
|
||||
if (c.isFaceDown() && (fromBattlefield || (toHand && zoneFrom.is(ZoneType.Exile)))) {
|
||||
c.setState(CardStateName.Original, true);
|
||||
c.runFaceupCommands();
|
||||
}
|
||||
|
||||
// Clean up the temporary Dash SVar when the Dashed card leaves the battlefield
|
||||
if (fromBattlefield && c.getSVar("EndOfTurnLeavePlay").equals("Dash")) {
|
||||
// Clean up the temporary AtEOT SVar
|
||||
String endofTurn = c.getSVar("EndOfTurnLeavePlay");
|
||||
if (fromBattlefield && (endofTurn.equals("Dash") || endofTurn.equals("AtEOT"))) {
|
||||
c.removeSVar("EndOfTurnLeavePlay");
|
||||
}
|
||||
|
||||
@@ -190,6 +184,14 @@ public class GameAction {
|
||||
lastKnownInfo = CardUtil.getLKICopy(c);
|
||||
}
|
||||
|
||||
// Cards returned from exile face-down must be reset to their original state, otherwise
|
||||
// all sort of funky shenanigans may happen later (e.g. their ETB replacement effects are set
|
||||
// up on the wrong card state etc.).
|
||||
if (wasFacedown && (fromBattlefield || (toHand && zoneFrom.is(ZoneType.Exile)))) {
|
||||
c.setState(CardStateName.Original, true);
|
||||
c.runFaceupCommands();
|
||||
}
|
||||
|
||||
if (!c.isToken()) {
|
||||
if (c.isCloned()) {
|
||||
c.switchStates(CardStateName.Original, CardStateName.Cloner, false);
|
||||
@@ -216,12 +218,16 @@ public class GameAction {
|
||||
|
||||
copied = CardFactory.copyCard(c, false);
|
||||
|
||||
copied.setUnearthed(c.isUnearthed());
|
||||
copied.setTapped(false);
|
||||
if (fromBattlefield) {
|
||||
if (fromBattlefield && copied.getCurrentStateName() != CardStateName.Original) {
|
||||
// when a card leaves the battlefield, ensure it's in its original state
|
||||
// (we need to do this on the object before copying it, or it won't work correctly e.g.
|
||||
// on Transformed objects)
|
||||
copied.setState(CardStateName.Original, false);
|
||||
}
|
||||
|
||||
copied.setUnearthed(c.isUnearthed());
|
||||
copied.setTapped(false);
|
||||
|
||||
for (final Trigger trigger : copied.getTriggers()) {
|
||||
trigger.setHostCard(copied);
|
||||
}
|
||||
@@ -245,26 +251,25 @@ public class GameAction {
|
||||
// special rule for Worms of the Earth
|
||||
if (toBattlefield && game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLandBattlefield)) {
|
||||
// something that is already a Land cant enter the battlefield
|
||||
if (c.isLand()) {
|
||||
return c;
|
||||
}
|
||||
// check if something would be a land
|
||||
Card noLandLKI = CardUtil.getLKICopy(c);
|
||||
// this check needs to check if this card would be on the battlefield
|
||||
noLandLKI.setLastKnownZone(zoneTo);
|
||||
Card noLandLKI = c;
|
||||
if (!c.isLand()) {
|
||||
// check if something would be a land
|
||||
noLandLKI = CardUtil.getLKICopy(c);
|
||||
// this check needs to check if this card would be on the battlefield
|
||||
noLandLKI.setLastKnownZone(zoneTo);
|
||||
|
||||
CardCollection preList = new CardCollection(noLandLKI);
|
||||
checkStaticAbilities(false, Sets.newHashSet(noLandLKI), preList);
|
||||
CardCollection preList = new CardCollection(noLandLKI);
|
||||
checkStaticAbilities(false, Sets.newHashSet(noLandLKI), preList);
|
||||
|
||||
// fake etb counters thing, then if something changed,
|
||||
// need to apply checkStaticAbilities again
|
||||
if(!noLandLKI.isLand()) {
|
||||
if (noLandLKI.putEtbCounters()) {
|
||||
// counters are added need to check again
|
||||
checkStaticAbilities(false, Sets.newHashSet(noLandLKI), preList);
|
||||
// fake etb counters thing, then if something changed,
|
||||
// need to apply checkStaticAbilities again
|
||||
if(!noLandLKI.isLand()) {
|
||||
if (noLandLKI.putEtbCounters()) {
|
||||
// counters are added need to check again
|
||||
checkStaticAbilities(false, Sets.newHashSet(noLandLKI), preList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(noLandLKI.isLand()) {
|
||||
// if it isn't on the Stack, it stays in that Zone
|
||||
if (!c.getZone().is(ZoneType.Stack)) {
|
||||
@@ -273,6 +278,7 @@ public class GameAction {
|
||||
// if something would only be a land when entering the battlefield and not before
|
||||
// put it into the graveyard instead
|
||||
zoneTo = c.getOwner().getZone(ZoneType.Graveyard);
|
||||
|
||||
// reset facedown
|
||||
copied.setState(CardStateName.Original, false);
|
||||
copied.setManifested(false);
|
||||
@@ -280,6 +286,26 @@ public class GameAction {
|
||||
|
||||
// not to battlefield anymore!
|
||||
toBattlefield = false;
|
||||
|
||||
if (copied.isCloned()) {
|
||||
copied.switchStates(CardStateName.Original, CardStateName.Cloner, false);
|
||||
copied.setState(CardStateName.Original, false);
|
||||
copied.clearStates(CardStateName.Cloner, false);
|
||||
if (copied.isFlipCard()) {
|
||||
copied.clearStates(CardStateName.Flipped, false);
|
||||
}
|
||||
if (copied.getStates().contains(CardStateName.OriginalText)) {
|
||||
copied.clearStates(CardStateName.OriginalText, false);
|
||||
copied.removeSVar("GainingTextFrom");
|
||||
copied.removeSVar("GainingTextFromTimestamp");
|
||||
}
|
||||
}
|
||||
|
||||
if (copied.getCurrentStateName() != CardStateName.Original) {
|
||||
copied.setState(CardStateName.Original, false);
|
||||
}
|
||||
|
||||
copied.updateStateForView();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,6 +314,33 @@ public class GameAction {
|
||||
copied.getOwner().addInboundToken(copied);
|
||||
}
|
||||
|
||||
if (toBattlefield) {
|
||||
// HACK for making the RIOT enchantment look into the Future
|
||||
// need to check the Keywords what it would have on the Battlefield
|
||||
Card riotLKI = CardUtil.getLKICopy(copied);
|
||||
riotLKI.setLastKnownZone(zoneTo);
|
||||
CardCollection preList = new CardCollection(riotLKI);
|
||||
checkStaticAbilities(false, Sets.newHashSet(riotLKI), preList);
|
||||
|
||||
List<Long> changedTimeStamps = Lists.newArrayList();
|
||||
for(Map.Entry<Long, KeywordsChange> e : riotLKI.getChangedCardKeywords().entrySet()) {
|
||||
if (!copied.hasChangedCardKeywords(e.getKey())) {
|
||||
KeywordsChange o = e.getValue();
|
||||
o.setHostCard(copied);
|
||||
for (KeywordInterface k : o.getKeywords()) {
|
||||
for (ReplacementEffect re : k.getReplacements()) {
|
||||
// this param need to be set, otherwise in ReplaceMoved it fails
|
||||
re.getMapParams().put("BypassEtbCheck", "True");
|
||||
}
|
||||
}
|
||||
copied.addChangedCardKeywordsInternal(o, e.getKey());
|
||||
changedTimeStamps.add(e.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
checkStaticAbilities(false);
|
||||
}
|
||||
|
||||
Map<String, Object> repParams = Maps.newHashMap();
|
||||
repParams.put("Event", "Moved");
|
||||
repParams.put("Affected", copied);
|
||||
@@ -432,10 +485,14 @@ public class GameAction {
|
||||
}
|
||||
|
||||
// rule 504.6: reveal a face-down card leaving the stack
|
||||
if (zoneFrom != null && zoneTo != null && zoneFrom.is(ZoneType.Stack) && !zoneTo.is(ZoneType.Battlefield) && c.isFaceDown()) {
|
||||
if (zoneFrom != null && zoneTo != null && zoneFrom.is(ZoneType.Stack) && !zoneTo.is(ZoneType.Battlefield) && wasFacedown) {
|
||||
// FIXME: tracker freeze-unfreeze is needed here to avoid a bug with the card staying face down in the View for the reveal
|
||||
boolean trackerFrozen = game.getTracker().isFrozen();
|
||||
game.getTracker().unfreeze();
|
||||
c.setState(CardStateName.Original, true);
|
||||
reveal(new CardCollection(c), c.getOwner(), true, "Face-down card moves from the stack: ");
|
||||
c.setState(CardStateName.FaceDown, true);
|
||||
if (trackerFrozen) { game.getTracker().freeze(); }
|
||||
}
|
||||
|
||||
if (fromBattlefield) {
|
||||
@@ -463,19 +520,19 @@ public class GameAction {
|
||||
changeZone(null, zoneTo, unmeld, position, cause, params);
|
||||
}
|
||||
// Reveal if face-down
|
||||
if (c.isFaceDown()) {
|
||||
if (wasFacedown) {
|
||||
// FIXME: tracker freeze-unfreeze is needed here to avoid a bug with the card staying face down in the View for the reveal
|
||||
boolean trackerFrozen = game.getTracker().isFrozen();
|
||||
game.getTracker().unfreeze();
|
||||
c.setState(CardStateName.Original, true);
|
||||
reveal(new CardCollection(c), c.getOwner(), true, "Face-down card leaves the battlefield: ");
|
||||
c.setState(CardStateName.FaceDown, true);
|
||||
if (trackerFrozen) { game.getTracker().freeze(); }
|
||||
copied.setState(CardStateName.Original, true);
|
||||
}
|
||||
unattachCardLeavingBattlefield(copied);
|
||||
// Remove all changed keywords
|
||||
copied.removeAllChangedText(game.getNextTimestamp());
|
||||
// reset activations
|
||||
for (SpellAbility ab : copied.getSpellAbilities()) {
|
||||
ab.getRestrictions().resetTurnActivations();
|
||||
}
|
||||
} else if (toBattlefield) {
|
||||
// reset timestamp in changezone effects so they have same timestamp if ETB simutaneously
|
||||
copied.setTimestamp(game.getNextTimestamp());
|
||||
@@ -504,45 +561,12 @@ public class GameAction {
|
||||
}
|
||||
|
||||
private static void unattachCardLeavingBattlefield(final Card copied) {
|
||||
// Handle unequipping creatures
|
||||
if (copied.isEquipped()) {
|
||||
for (final Card equipment : copied.getEquippedBy(true)) {
|
||||
if (equipment.isInPlay()) {
|
||||
equipment.unEquipCard(copied);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Handle unfortifying lands
|
||||
if (copied.isFortified()) {
|
||||
for (final Card f : copied.getFortifiedBy(true)) {
|
||||
if (f.isInPlay()) {
|
||||
f.unFortifyCard(copied);
|
||||
}
|
||||
}
|
||||
}
|
||||
// equipment moving off battlefield
|
||||
if (copied.isEquipping()) {
|
||||
final Card equippedCreature = copied.getEquipping();
|
||||
if (equippedCreature.isInPlay()) {
|
||||
copied.unEquipCard(equippedCreature);
|
||||
}
|
||||
}
|
||||
// fortifications moving off battlefield
|
||||
if (copied.isFortifying()) {
|
||||
final Card fortifiedLand = copied.getFortifying();
|
||||
if (fortifiedLand.isInPlay()) {
|
||||
copied.unFortifyCard(fortifiedLand);
|
||||
}
|
||||
}
|
||||
// remove enchantments from creatures
|
||||
if (copied.isEnchanted()) {
|
||||
for (final Card aura : copied.getEnchantedBy(true)) {
|
||||
aura.unEnchantEntity(copied);
|
||||
}
|
||||
}
|
||||
// remove attachments from creatures
|
||||
copied.unAttachAllCards();
|
||||
|
||||
// unenchant creature if moving aura
|
||||
if (copied.isEnchanting()) {
|
||||
copied.unEnchantEntity(copied.getEnchanting());
|
||||
if (copied.isAttachedToEntity()) {
|
||||
copied.unattachFromEntity(copied.getEntityAttachedTo());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -872,9 +896,7 @@ public class GameAction {
|
||||
affectedCards.add(c);
|
||||
}
|
||||
}
|
||||
for (Object[] staticCheck : c.getStaticCommandList()) {
|
||||
c.getStaticCommandList().remove(staticCheck);
|
||||
}
|
||||
c.getStaticCommandList().removeAll(toRemove);
|
||||
}
|
||||
// Exclude cards in hidden zones from update
|
||||
Iterator<Card> it = affectedCards.iterator();
|
||||
@@ -958,6 +980,8 @@ public class GameAction {
|
||||
checkStaticAbilities(false, affectedCards, CardCollection.EMPTY);
|
||||
boolean checkAgain = false;
|
||||
|
||||
CardZoneTable table = new CardZoneTable();
|
||||
|
||||
for (final Player p : game.getPlayers()) {
|
||||
for (final ZoneType zt : ZoneType.values()) {
|
||||
if (zt == ZoneType.Battlefield) {
|
||||
@@ -1005,12 +1029,11 @@ public class GameAction {
|
||||
}
|
||||
}
|
||||
|
||||
checkAgain |= stateBasedAction_Saga(c);
|
||||
checkAgain |= stateBasedAction704_5n(c); // Auras attached to illegal or not attached go to graveyard
|
||||
checkAgain |= stateBasedAction704_5p(c); // Equipment and Fortifications
|
||||
checkAgain |= stateBasedAction_Saga(c, table);
|
||||
checkAgain |= stateBasedAction704_attach(c, table); // Attachment
|
||||
|
||||
if (c.isCreature() && c.isEnchanting()) { // Rule 704.5q - Creature attached to an object or player, becomes unattached
|
||||
c.unEnchantEntity(c.getEnchanting());
|
||||
if (c.isCreature() && c.isAttachedToEntity()) { // Rule 704.5q - Creature attached to an object or player, becomes unattached
|
||||
c.unattachFromEntity(c.getEntityAttachedTo());
|
||||
checkAgain = true;
|
||||
}
|
||||
|
||||
@@ -1032,24 +1055,19 @@ public class GameAction {
|
||||
orderedNoRegCreats = true;
|
||||
}
|
||||
for (Card c : noRegCreats) {
|
||||
sacrificeDestroy(c, null);
|
||||
sacrificeDestroy(c, null, table);
|
||||
}
|
||||
}
|
||||
if (desCreats != null) {
|
||||
if (desCreats.size() > 1 && !orderedDesCreats) {
|
||||
desCreats = CardLists.filter(desCreats, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card card) {
|
||||
return card.canBeDestroyed();
|
||||
}
|
||||
});
|
||||
desCreats = CardLists.filter(desCreats, CardPredicates.Presets.CAN_BE_DESTROYED);
|
||||
if (!desCreats.isEmpty()) {
|
||||
desCreats = (CardCollection) GameActionUtil.orderCardsByTheirOwners(game, desCreats, ZoneType.Graveyard);
|
||||
}
|
||||
orderedDesCreats = true;
|
||||
}
|
||||
for (Card c : desCreats) {
|
||||
destroy(c, null);
|
||||
destroy(c, null, true, table);
|
||||
}
|
||||
}
|
||||
setHoldCheckingStaticAbilities(false);
|
||||
@@ -1059,20 +1077,21 @@ public class GameAction {
|
||||
}
|
||||
|
||||
for (Player p : game.getPlayers()) {
|
||||
if (handleLegendRule(p)) {
|
||||
if (handleLegendRule(p, table)) {
|
||||
checkAgain = true;
|
||||
}
|
||||
|
||||
if (handlePlaneswalkerRule(p)) {
|
||||
if (handlePlaneswalkerRule(p, table)) {
|
||||
checkAgain = true;
|
||||
}
|
||||
}
|
||||
// 704.5m World rule
|
||||
checkAgain |= handleWorldRule();
|
||||
checkAgain |= handleWorldRule(table);
|
||||
|
||||
if (game.getCombat() != null) {
|
||||
game.getCombat().removeAbsentCombatants();
|
||||
}
|
||||
table.triggerChangesZoneAll(game);
|
||||
if (!checkAgain) {
|
||||
break; // do not continue the loop
|
||||
}
|
||||
@@ -1105,7 +1124,7 @@ public class GameAction {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stateBasedAction_Saga(Card c) {
|
||||
private boolean stateBasedAction_Saga(Card c, CardZoneTable table) {
|
||||
boolean checkAgain = false;
|
||||
if (!c.getType().hasSubtype("Saga")) {
|
||||
return false;
|
||||
@@ -1118,116 +1137,40 @@ public class GameAction {
|
||||
}
|
||||
if (!game.getStack().hasSimultaneousStackEntries() &&
|
||||
!game.getStack().hasSourceOnStack(c, SpellAbilityPredicates.isChapter())) {
|
||||
sacrifice(c, null);
|
||||
sacrifice(c, null, table);
|
||||
checkAgain = true;
|
||||
}
|
||||
return checkAgain;
|
||||
}
|
||||
|
||||
private boolean stateBasedAction704_5n(Card c) {
|
||||
private boolean stateBasedAction704_attach(Card c, CardZoneTable table) {
|
||||
boolean checkAgain = false;
|
||||
if (!c.isAura()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if Card Aura is attached to is a legal target
|
||||
final GameEntity entity = c.getEnchanting();
|
||||
SpellAbility sa = c.getFirstAttachSpell();
|
||||
|
||||
TargetRestrictions tgt = null;
|
||||
if (sa != null) {
|
||||
tgt = sa.getTargetRestrictions();
|
||||
}
|
||||
|
||||
if (entity instanceof Card) {
|
||||
final Card perm = (Card) entity;
|
||||
final ZoneType tgtZone = tgt.getZone().get(0);
|
||||
|
||||
if (!perm.isInZone(tgtZone) || !perm.canBeEnchantedBy(c, true) || (perm.isPhasedOut() && !c.isPhasedOut())) {
|
||||
c.unEnchantEntity(perm);
|
||||
moveToGraveyard(c, null, null);
|
||||
checkAgain = true;
|
||||
}
|
||||
} else if (entity instanceof Player) {
|
||||
final Player pl = (Player) entity;
|
||||
boolean invalid = false;
|
||||
|
||||
if (!game.getPlayers().contains(pl)) {
|
||||
// lost player can't have Aura on it
|
||||
invalid = true;
|
||||
} else if (tgt.canOnlyTgtOpponent() && !c.getController().isOpponentOf(pl)) {
|
||||
invalid = true;
|
||||
}
|
||||
else if (pl.hasProtectionFrom(c)) {
|
||||
invalid = true;
|
||||
}
|
||||
if (invalid) {
|
||||
c.unEnchantEntity(pl);
|
||||
moveToGraveyard(c, null, null);
|
||||
if (c.isAttachedToEntity()) {
|
||||
final GameEntity ge = c.getEntityAttachedTo();
|
||||
if (!ge.canBeAttached(c, true)) {
|
||||
c.unattachFromEntity(ge);
|
||||
checkAgain = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (c.isInPlay() && !c.isEnchanting()) {
|
||||
moveToGraveyard(c, null, null);
|
||||
if (c.hasCardAttachments()) {
|
||||
for (final Card attach : Lists.newArrayList(c.getAttachedCards())) {
|
||||
if (!attach.isInPlay()) {
|
||||
attach.unattachFromEntity(c);
|
||||
checkAgain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup aura
|
||||
if (c.isAura() && c.isInPlay() && !c.isEnchanting()) {
|
||||
sacrificeDestroy(c, null, table);
|
||||
checkAgain = true;
|
||||
}
|
||||
return checkAgain;
|
||||
}
|
||||
|
||||
private boolean stateBasedAction704_5p(Card c) {
|
||||
boolean checkAgain = false;
|
||||
if (c.isEquipped()) {
|
||||
for (final Card equipment : c.getEquippedBy(true)) {
|
||||
if (!equipment.isInPlay()) {
|
||||
equipment.unEquipCard(c);
|
||||
checkAgain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c.isFortified()) {
|
||||
for (final Card f : c.getFortifiedBy(true)) {
|
||||
if (!f.isInPlay()) {
|
||||
f.unFortifyCard(c);
|
||||
checkAgain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c.isEquipping()) {
|
||||
final Card equippedCreature = c.getEquipping();
|
||||
if (!equippedCreature.isCreature() || !equippedCreature.isInPlay()
|
||||
|| !equippedCreature.canBeEquippedBy(c)
|
||||
|| (equippedCreature.isPhasedOut() && !c.isPhasedOut())
|
||||
|| !c.isEquipment()) {
|
||||
c.unEquipCard(equippedCreature);
|
||||
checkAgain = true;
|
||||
}
|
||||
// make sure any equipment that has become a creature stops equipping
|
||||
if (c.isCreature()) {
|
||||
c.unEquipCard(equippedCreature);
|
||||
checkAgain = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (c.isFortifying()) {
|
||||
final Card fortifiedLand = c.getFortifying();
|
||||
if (!fortifiedLand.isLand() || !fortifiedLand.isInPlay()
|
||||
|| (fortifiedLand.isPhasedOut() && !c.isPhasedOut())
|
||||
|| !c.isFortification()) {
|
||||
c.unFortifyCard(fortifiedLand);
|
||||
checkAgain = true;
|
||||
}
|
||||
// make sure any fortification that has become a creature stops fortifying
|
||||
if (c.isCreature()) {
|
||||
c.unFortifyCard(fortifiedLand);
|
||||
checkAgain = true;
|
||||
}
|
||||
}
|
||||
return checkAgain;
|
||||
}
|
||||
|
||||
private boolean stateBasedAction704_5r(Card c) {
|
||||
boolean checkAgain = false;
|
||||
int plusOneCounters = c.getCounters(CounterType.P1P1);
|
||||
@@ -1352,7 +1295,7 @@ public class GameAction {
|
||||
game.getStack().clearSimultaneousStack();
|
||||
}
|
||||
|
||||
private boolean handlePlaneswalkerRule(Player p) {
|
||||
private boolean handlePlaneswalkerRule(Player p, CardZoneTable table) {
|
||||
// get all Planeswalkers
|
||||
final List<Card> list = CardLists.filter(p.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.PLANESWALKERS);
|
||||
boolean recheck = false;
|
||||
@@ -1361,7 +1304,7 @@ public class GameAction {
|
||||
|
||||
for (Card c : list) {
|
||||
if (c.getCounters(CounterType.LOYALTY) <= 0) {
|
||||
moveToGraveyard(c, null, null);
|
||||
sacrificeDestroy(c, null, table);
|
||||
// Play the Destroy sound
|
||||
game.fireEvent(new GameEventCardDestroyed());
|
||||
recheck = true;
|
||||
@@ -1395,7 +1338,7 @@ public class GameAction {
|
||||
return recheck;
|
||||
}
|
||||
|
||||
private boolean handleLegendRule(Player p) {
|
||||
private boolean handleLegendRule(Player p, CardZoneTable table) {
|
||||
final List<Card> a = CardLists.getType(p.getCardsIn(ZoneType.Battlefield), "Legendary");
|
||||
if (a.isEmpty() || game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)) {
|
||||
return false;
|
||||
@@ -1423,7 +1366,7 @@ public class GameAction {
|
||||
Card toKeep = p.getController().chooseSingleEntityForEffect(new CardCollection(cc), new AbilitySub(ApiType.InternalLegendaryRule, null, null, null), "You have multiple legendary permanents named \""+name+"\" in play.\n\nChoose the one to stay on battlefield (the rest will be moved to graveyard)");
|
||||
for (Card c: cc) {
|
||||
if (c != toKeep) {
|
||||
sacrificeDestroy(c, null);
|
||||
sacrificeDestroy(c, null, table);
|
||||
}
|
||||
}
|
||||
game.fireEvent(new GameEventCardDestroyed());
|
||||
@@ -1432,7 +1375,7 @@ public class GameAction {
|
||||
return recheck;
|
||||
}
|
||||
|
||||
private boolean handleWorldRule() {
|
||||
private boolean handleWorldRule(CardZoneTable table) {
|
||||
final List<Card> worlds = CardLists.getType(game.getCardsIn(ZoneType.Battlefield), "World");
|
||||
if (worlds.size() <= 1) {
|
||||
return false;
|
||||
@@ -1457,35 +1400,28 @@ public class GameAction {
|
||||
}
|
||||
|
||||
for (Card c : worlds) {
|
||||
sacrificeDestroy(c, null);
|
||||
sacrificeDestroy(c, null, table);
|
||||
game.fireEvent(new GameEventCardDestroyed());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public final Card sacrifice(final Card c, final SpellAbility source) {
|
||||
return sacrifice(c, source, null);
|
||||
}
|
||||
public final Card sacrifice(final Card c, final SpellAbility source, CardZoneTable table) {
|
||||
if (!c.canBeSacrificedBy(source)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
c.getController().addSacrificedThisTurn(c, source);
|
||||
|
||||
return sacrificeDestroy(c, source);
|
||||
return sacrificeDestroy(c, source, table);
|
||||
}
|
||||
|
||||
public final boolean destroy(final Card c, final SpellAbility sa) {
|
||||
if (!c.canBeDestroyed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return destroy(c, sa, true);
|
||||
}
|
||||
public final boolean destroyNoRegeneration(final Card c, final SpellAbility sa) {
|
||||
return destroy(c, sa, false);
|
||||
}
|
||||
|
||||
public final boolean destroy(final Card c, final SpellAbility sa, final boolean regenerate) {
|
||||
public final boolean destroy(final Card c, final SpellAbility sa, final boolean regenerate, CardZoneTable table) {
|
||||
Player activator = null;
|
||||
if (!c.canBeDestroyed()) {
|
||||
return false;
|
||||
@@ -1517,7 +1453,7 @@ public class GameAction {
|
||||
runParams.put("Causer", activator);
|
||||
game.getTriggerHandler().runTrigger(TriggerType.Destroyed, runParams, false);
|
||||
|
||||
final Card sacrificed = sacrificeDestroy(c, sa);
|
||||
final Card sacrificed = sacrificeDestroy(c, sa, table);
|
||||
return sacrificed != null;
|
||||
}
|
||||
|
||||
@@ -1525,12 +1461,15 @@ public class GameAction {
|
||||
* @return the sacrificed Card in its new location, or {@code null} if the
|
||||
* sacrifice wasn't successful.
|
||||
*/
|
||||
public final Card sacrificeDestroy(final Card c, SpellAbility cause) {
|
||||
protected final Card sacrificeDestroy(final Card c, SpellAbility cause, CardZoneTable table) {
|
||||
if (!c.isInPlay()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Card newCard = moveToGraveyard(c, cause, null);
|
||||
if (table != null) {
|
||||
table.put(ZoneType.Battlefield, newCard.getZone().getZoneType(), newCard);
|
||||
}
|
||||
|
||||
return newCard;
|
||||
}
|
||||
@@ -1784,12 +1723,8 @@ public class GameAction {
|
||||
|
||||
// rule 103.4b
|
||||
boolean isMultiPlayer = game.getPlayers().size() > 2;
|
||||
int mulliganDelta = isMultiPlayer ? 0 : 1;
|
||||
|
||||
// https://magic.wizards.com/en/articles/archive/feature/checking-brawl-2018-07-09
|
||||
if (game.getRules().hasAppliedVariant(GameType.Brawl) && !isMultiPlayer){
|
||||
mulliganDelta = 0;
|
||||
}
|
||||
int mulliganDelta = isMultiPlayer || game.getRules().hasAppliedVariant(GameType.Brawl) ? 0 : 1;
|
||||
|
||||
boolean allKept;
|
||||
do {
|
||||
@@ -1805,32 +1740,17 @@ public class GameAction {
|
||||
}
|
||||
|
||||
if (toMulligan != null && !toMulligan.isEmpty()) {
|
||||
if (!isCommander) {
|
||||
toMulligan = new CardCollection(p.getCardsIn(ZoneType.Hand));
|
||||
for (final Card c : toMulligan) {
|
||||
moveToLibrary(c, null, null);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100); //delay for a tiny bit to give UI a chance catch up
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.shuffle(null);
|
||||
p.drawCards(handSize[i] - mulliganDelta);
|
||||
} else {
|
||||
List<Card> toExile = Lists.newArrayList(toMulligan);
|
||||
for (Card c : toExile) {
|
||||
exile(c, null, null);
|
||||
}
|
||||
exiledDuringMulligans.addAll(p, toExile);
|
||||
try {
|
||||
Thread.sleep(100); //delay for a tiny bit to give UI a chance catch up
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.drawCards(toExile.size() - 1);
|
||||
toMulligan = new CardCollection(p.getCardsIn(ZoneType.Hand));
|
||||
for (final Card c : toMulligan) {
|
||||
moveToLibrary(c, null, null);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(100); //delay for a tiny bit to give UI a chance catch up
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.shuffle(null);
|
||||
p.drawCards(handSize[i] - mulliganDelta);
|
||||
p.onMulliganned();
|
||||
allKept = false;
|
||||
} else {
|
||||
@@ -1841,21 +1761,17 @@ public class GameAction {
|
||||
mulliganDelta++;
|
||||
} while (!allKept);
|
||||
|
||||
if (isCommander) {
|
||||
for (Entry<Player, Collection<Card>> kv : exiledDuringMulligans.entrySet()) {
|
||||
Player p = kv.getKey();
|
||||
Collection<Card> cc = kv.getValue();
|
||||
for (Card c : cc) {
|
||||
moveToLibrary(c, null, null);
|
||||
}
|
||||
p.shuffle(null);
|
||||
//Vancouver Mulligan as a scry with the decisions inside
|
||||
List<Player> scryers = Lists.newArrayList();
|
||||
for(Player p : whoCanMulligan) {
|
||||
if (p.getStartingHandSize() > p.getZone(ZoneType.Hand).size()) {
|
||||
scryers.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
//Vancouver Mulligan
|
||||
for(Player p : whoCanMulligan) {
|
||||
if (p.getStartingHandSize() > p.getZone(ZoneType.Hand).size()) {
|
||||
p.scry(1, null);
|
||||
for(Player p : scryers) {
|
||||
if (p.getController().confirmMulliganScry(p)) {
|
||||
scry(ImmutableList.of(p), 1, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1953,4 +1869,68 @@ public class GameAction {
|
||||
runParams.put("Player", p);
|
||||
game.getTriggerHandler().runTrigger(TriggerType.BecomeMonarch, runParams, false);
|
||||
}
|
||||
|
||||
// Make scry an action function so that it can be used for mulligans (with a null cause)
|
||||
// Assumes that the list of players is in APNAP order, which should be the case
|
||||
// Optional here as well to handle the way that mulligans do the choice
|
||||
// 701.17. Scry
|
||||
// 701.17a To "scry N" means to look at the top N cards of your library, then put any number of them
|
||||
// on the bottom of your library in any order and the rest on top of your library in any order.
|
||||
// 701.17b If a player is instructed to scry 0, no scry event occurs. Abilities that trigger whenever a
|
||||
// player scries won’t trigger.
|
||||
// 701.17c If multiple players scry at once, each of those players looks at the top cards of their library
|
||||
// at the same time. Those players decide in APNAP order (see rule 101.4) where to put those
|
||||
// cards, then those cards move at the same time.
|
||||
public void scry(List<Player> players, int numScry, SpellAbility cause) {
|
||||
if (numScry == 0) {
|
||||
return;
|
||||
}
|
||||
// reveal the top N library cards to the player (only)
|
||||
// no real need to separate out the look if
|
||||
// there is only one player scrying
|
||||
if (players.size() > 1) {
|
||||
for (final Player p : players) {
|
||||
final CardCollection topN = new CardCollection(p.getCardsIn(ZoneType.Library, numScry));
|
||||
revealTo(topN, p);
|
||||
}
|
||||
}
|
||||
// make the decisions
|
||||
List<ImmutablePair<CardCollection, CardCollection>> decisions = Lists.newArrayList();
|
||||
for (final Player p : players) {
|
||||
final CardCollection topN = new CardCollection(p.getCardsIn(ZoneType.Library, numScry));
|
||||
ImmutablePair<CardCollection, CardCollection> decision = p.getController().arrangeForScry(topN);
|
||||
decisions.add(decision);
|
||||
int numToTop = decision.getLeft() == null ? 0 : decision.getLeft().size();
|
||||
int numToBottom = decision.getRight() == null ? 0 : decision.getRight().size();
|
||||
|
||||
// publicize the decision
|
||||
game.fireEvent(new GameEventScry(p, numToTop, numToBottom));
|
||||
}
|
||||
// do the moves after all the decisions (maybe not necesssary, but let's
|
||||
// do it the official way)
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
// no good iterate simultaneously in Java
|
||||
final Player p = players.get(i);
|
||||
final CardCollection toTop = decisions.get(i).getLeft();
|
||||
final CardCollection toBottom = decisions.get(i).getRight();
|
||||
if (toTop != null) {
|
||||
Collections.reverse(toTop); // reverse to get the correct order
|
||||
for (Card c : toTop) {
|
||||
moveToLibrary(c, cause, null);
|
||||
}
|
||||
}
|
||||
if (toBottom != null) {
|
||||
for (Card c : toBottom) {
|
||||
moveToBottomOfLibrary(c, cause, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (cause != null) {
|
||||
// set up triggers (but not actually do them until later)
|
||||
final Map<String, Object> runParams = Maps.newHashMap();
|
||||
runParams.put("Player", p);
|
||||
game.getTriggerHandler().runTrigger(TriggerType.Scry, runParams, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,12 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import forge.card.mana.ManaCostParser;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.*;
|
||||
import forge.game.card.CardPlayOption.PayManaCost;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.keyword.KeywordInterface;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.*;
|
||||
@@ -345,121 +343,6 @@ public final class GameActionUtil {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get optional additional costs.
|
||||
*
|
||||
* @param original
|
||||
* the original sa
|
||||
* @return an ArrayList<SpellAbility>.
|
||||
*
|
||||
* @deprecated only used by AI, replace it with new functions in AI
|
||||
*/
|
||||
@Deprecated public static List<SpellAbility> getOptionalCosts(final SpellAbility original) {
|
||||
final List<SpellAbility> abilities = getAdditionalCostSpell(original);
|
||||
|
||||
final Card source = original.getHostCard();
|
||||
|
||||
if (!original.isSpell()) {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
// Buyback, Kicker
|
||||
for (KeywordInterface inst : source.getKeywords()) {
|
||||
final String keyword = inst.getOriginal();
|
||||
if (keyword.startsWith("Buyback")) {
|
||||
for (int i = 0; i < abilities.size(); i++) {
|
||||
final SpellAbility newSA = abilities.get(i).copy();
|
||||
newSA.setBasicSpell(false);
|
||||
newSA.setPayCosts(new Cost(keyword.substring(8), false).add(newSA.getPayCosts()));
|
||||
newSA.setDescription(newSA.getDescription() + " (with Buyback)");
|
||||
newSA.addOptionalCost(OptionalCost.Buyback);
|
||||
if (newSA.canPlay()) {
|
||||
abilities.add(i, newSA);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else if (keyword.startsWith("MayFlashCost")) {
|
||||
// this is there for the AI
|
||||
if ( source.getGame().getPhaseHandler().isPlayerTurn(source.getController())) {
|
||||
continue; // don't cast it with additional flash cost during AI's own turn, commonly a waste of mana
|
||||
}
|
||||
final String[] k = keyword.split(":");
|
||||
for (int i = 0; i < abilities.size(); i++) {
|
||||
final SpellAbility newSA = abilities.get(i).copy();
|
||||
newSA.setBasicSpell(false);
|
||||
newSA.setPayCosts(new Cost(k[1], false).add(newSA.getPayCosts()));
|
||||
newSA.setDescription(newSA.getDescription() + " (as though it had flash)");
|
||||
newSA.getRestrictions().setInstantSpeed(true);
|
||||
if (newSA.canPlay()) {
|
||||
abilities.add(i, newSA);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else if (keyword.startsWith("Kicker")) {
|
||||
String[] sCosts = TextUtil.split(keyword.substring(6), ':');
|
||||
boolean generic = "Generic".equals(sCosts[sCosts.length - 1]);
|
||||
// If this is a "generic kicker" (Undergrowth), ignore value for kicker creations
|
||||
int numKickers = sCosts.length - (generic ? 1 : 0);
|
||||
for (int i = 0; i < abilities.size(); i++) {
|
||||
int iUnKicked = i;
|
||||
for (int j = 0; j < numKickers; j++) {
|
||||
final SpellAbility newSA = abilities.get(iUnKicked).copy();
|
||||
newSA.setBasicSpell(false);
|
||||
final Cost cost = new Cost(sCosts[j], false);
|
||||
newSA.setPayCosts(cost.add(newSA.getPayCosts()));
|
||||
if (!generic) {
|
||||
newSA.setDescription(newSA.getDescription() + " (Kicker " + cost.toSimpleString() + ")");
|
||||
newSA.addOptionalCost(j == 0 ? OptionalCost.Kicker1 : OptionalCost.Kicker2);
|
||||
} else {
|
||||
newSA.setDescription(newSA.getDescription() + " (Optional " + cost.toSimpleString() + ")");
|
||||
newSA.addOptionalCost(OptionalCost.Generic);
|
||||
}
|
||||
if (newSA.canPlay()) {
|
||||
abilities.add(i, newSA);
|
||||
i++;
|
||||
iUnKicked++;
|
||||
}
|
||||
}
|
||||
if (numKickers == 2) { // case for both kickers - it's hardcoded since they never have more than 2 kickers
|
||||
final SpellAbility newSA = abilities.get(iUnKicked).copy();
|
||||
newSA.setBasicSpell(false);
|
||||
final Cost cost1 = new Cost(sCosts[0], false);
|
||||
final Cost cost2 = new Cost(sCosts[1], false);
|
||||
newSA.setDescription(TextUtil.addSuffix(newSA.getDescription(), TextUtil.concatWithSpace(" (Both kickers:", cost1.toSimpleString(),"and",TextUtil.addSuffix(cost2.toSimpleString(),")"))));
|
||||
newSA.setPayCosts(cost2.add(cost1.add(newSA.getPayCosts())));
|
||||
newSA.addOptionalCost(OptionalCost.Kicker1);
|
||||
newSA.addOptionalCost(OptionalCost.Kicker2);
|
||||
if (newSA.canPlay()) {
|
||||
abilities.add(i, newSA);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (source.hasKeyword(Keyword.CONSPIRE)) {
|
||||
int amount = source.getAmountOfKeyword(Keyword.CONSPIRE);
|
||||
for (int kwInstance = 1; kwInstance <= amount; kwInstance++) {
|
||||
for (int i = 0; i < abilities.size(); i++) {
|
||||
final SpellAbility newSA = abilities.get(i).copy();
|
||||
newSA.setBasicSpell(false);
|
||||
final String conspireCost = "tapXType<2/Creature.SharesColorWith/untapped creature you control that shares a color with " + source.getName() + ">";
|
||||
newSA.setPayCosts(new Cost(conspireCost, false).add(newSA.getPayCosts()));
|
||||
final String tag = kwInstance > 1 ? " (Conspire " + kwInstance + ")" : " (Conspire)";
|
||||
newSA.setDescription(newSA.getDescription() + tag);
|
||||
newSA.addOptionalCost(OptionalCost.Conspire);
|
||||
newSA.addConspireInstance();
|
||||
if (newSA.canPlay()) {
|
||||
abilities.add(++i, newSA);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return abilities;
|
||||
}
|
||||
|
||||
private static boolean hasUrzaLands(final Player p) {
|
||||
final CardCollectionView landsControlled = p.getCardsIn(ZoneType.Battlefield);
|
||||
return Iterables.any(landsControlled, Predicates.and(CardPredicates.isType("Urza's"), CardPredicates.isType("Mine")))
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -21,18 +21,22 @@ import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.card.CardCollectionView;
|
||||
import forge.game.card.CardDamageMap;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.event.GameEventCardAttachment;
|
||||
import forge.game.event.GameEventCardAttachment.AttachMethod;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.collect.FCollection;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
||||
@@ -40,7 +44,7 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
|
||||
protected final int id;
|
||||
private String name = "";
|
||||
private int preventNextDamage = 0;
|
||||
private CardCollection enchantedBy;
|
||||
protected CardCollection attachedCards;
|
||||
private Map<Card, Map<String, String>> preventionShieldsWithEffects = Maps.newTreeMap();
|
||||
protected Map<CounterType, Integer> counters = Maps.newEnumMap(CounterType.class);
|
||||
|
||||
@@ -93,7 +97,7 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
|
||||
source.getDamageHistory().registerCombatDamage(this);
|
||||
}
|
||||
// damage prevention is already checked
|
||||
return addCombatDamageBase(damageToDo, source, damageMap);
|
||||
return addCombatDamageBase(damageToDo, source, damageMap);
|
||||
}
|
||||
|
||||
protected int addCombatDamageBase(final int damage, final Card source, CardDamageMap damageMap) {
|
||||
@@ -204,17 +208,17 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
|
||||
restDamage = 0;
|
||||
}
|
||||
|
||||
// if damage is greater than restDamage, damage was prevented
|
||||
// if damage is greater than restDamage, damage was prevented
|
||||
if (damage > restDamage) {
|
||||
int prevent = damage - restDamage;
|
||||
preventMap.put(source, this, damage - restDamage);
|
||||
|
||||
|
||||
final Map<String, Object> runParams = Maps.newHashMap();
|
||||
runParams.put("DamageTarget", this);
|
||||
runParams.put("DamageAmount", prevent);
|
||||
runParams.put("DamageSource", source);
|
||||
runParams.put("IsCombatDamage", isCombat);
|
||||
|
||||
|
||||
getGame().getTriggerHandler().runTrigger(TriggerType.DamagePrevented, runParams, false);
|
||||
}
|
||||
|
||||
@@ -280,77 +284,165 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
|
||||
public abstract boolean hasKeyword(final String keyword);
|
||||
public abstract boolean hasKeyword(final Keyword keyword);
|
||||
|
||||
// GameEntities can now be Enchanted
|
||||
public final CardCollectionView getEnchantedBy(boolean allowModify) {
|
||||
return CardCollection.getView(enchantedBy, allowModify);
|
||||
public final CardCollectionView getEnchantedBy() {
|
||||
if (attachedCards == null) {
|
||||
return CardCollection.EMPTY;
|
||||
}
|
||||
// enchanted means attached by Aura
|
||||
return CardLists.filter(attachedCards, CardPredicates.Presets.AURA);
|
||||
}
|
||||
public final void setEnchantedBy(final CardCollection cards) {
|
||||
enchantedBy = cards;
|
||||
getView().updateEnchantedBy(this);
|
||||
|
||||
public final CardCollectionView getAttachedCards() {
|
||||
return CardCollection.getView(attachedCards);
|
||||
}
|
||||
public final void setEnchantedBy(final Iterable<Card> cards) {
|
||||
|
||||
public final void setAttachedCards(final Iterable<Card> cards) {
|
||||
if (cards == null) {
|
||||
enchantedBy = null;
|
||||
attachedCards = null;
|
||||
}
|
||||
else {
|
||||
enchantedBy = new CardCollection(cards);
|
||||
attachedCards = new CardCollection(cards);
|
||||
}
|
||||
getView().updateEnchantedBy(this);
|
||||
|
||||
getView().updateAttachedCards(this);
|
||||
}
|
||||
|
||||
public final boolean hasCardAttachments() {
|
||||
return FCollection.hasElements(attachedCards);
|
||||
}
|
||||
|
||||
public final boolean isEnchanted() {
|
||||
return FCollection.hasElements(enchantedBy);
|
||||
if (attachedCards == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// enchanted means attached by Aura
|
||||
return CardLists.count(attachedCards, CardPredicates.Presets.AURA) > 0;
|
||||
}
|
||||
|
||||
public final boolean hasCardAttachment(Card c) {
|
||||
return FCollection.hasElement(attachedCards, c);
|
||||
}
|
||||
public final boolean isEnchantedBy(Card c) {
|
||||
return FCollection.hasElement(enchantedBy, c);
|
||||
// Rule 303.4k Even if c is no Aura it still counts
|
||||
return hasCardAttachment(c);
|
||||
}
|
||||
|
||||
public final boolean hasCardAttachment(final String cardName) {
|
||||
if (attachedCards == null) {
|
||||
return false;
|
||||
}
|
||||
return CardLists.count(getAttachedCards(), CardPredicates.nameEquals(cardName)) > 0;
|
||||
}
|
||||
public final boolean isEnchantedBy(final String cardName) {
|
||||
for (final Card aura : getEnchantedBy(false)) {
|
||||
if (aura.getName().equals(cardName)) {
|
||||
return true;
|
||||
// Rule 303.4k Even if c is no Aura it still counts
|
||||
return hasCardAttachment(cardName);
|
||||
}
|
||||
|
||||
/**
|
||||
* internal method
|
||||
* @param Card c
|
||||
*/
|
||||
public final void addAttachedCard(final Card c) {
|
||||
if (attachedCards == null) {
|
||||
attachedCards = new CardCollection();
|
||||
}
|
||||
|
||||
if (attachedCards.add(c)) {
|
||||
getView().updateAttachedCards(this);
|
||||
getGame().fireEvent(new GameEventCardAttachment(c, null, this));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* internal method
|
||||
* @param Card c
|
||||
*/
|
||||
public final void removeAttachedCard(final Card c) {
|
||||
if (attachedCards == null) { return; }
|
||||
|
||||
if (attachedCards.remove(c)) {
|
||||
if (attachedCards.isEmpty()) {
|
||||
attachedCards = null;
|
||||
}
|
||||
getView().updateAttachedCards(this);
|
||||
getGame().fireEvent(new GameEventCardAttachment(c, this, null));
|
||||
}
|
||||
}
|
||||
|
||||
public final void unAttachAllCards() {
|
||||
for (Card c : Lists.newArrayList(getAttachedCards())) {
|
||||
c.unattachFromEntity(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canBeAttached(final Card attach) {
|
||||
return canBeAttached(attach, false);
|
||||
}
|
||||
|
||||
public boolean canBeAttached(final Card attach, boolean checkSBA) {
|
||||
// master mode
|
||||
if (!attach.isAttachment() || attach.isCreature() || equals(attach)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// CantTarget static abilities
|
||||
for (final Card ca : getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) {
|
||||
for (final StaticAbility stAb : ca.getStaticAbilities()) {
|
||||
if (stAb.applyAbility("CantAttach", attach, this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attach.isAura() && !canBeEnchantedBy(attach)) {
|
||||
return false;
|
||||
}
|
||||
if (attach.isEquipment() && !canBeEquippedBy(attach)) {
|
||||
return false;
|
||||
}
|
||||
if (attach.isFortification() && !canBeFortifiedBy(attach)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// true for all
|
||||
if (hasProtectionFrom(attach, checkSBA)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean canBeEquippedBy(final Card aura) {
|
||||
/**
|
||||
* Equip only to Creatures which are cards
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
public final void addEnchantedBy(final Card c) {
|
||||
if (enchantedBy == null) {
|
||||
enchantedBy = new CardCollection();
|
||||
}
|
||||
if (enchantedBy.add(c)) {
|
||||
getView().updateEnchantedBy(this);
|
||||
getGame().fireEvent(new GameEventCardAttachment(c, null, this, AttachMethod.Enchant));
|
||||
}
|
||||
}
|
||||
public final void removeEnchantedBy(final Card c) {
|
||||
if (enchantedBy == null) { return; }
|
||||
|
||||
if (enchantedBy.remove(c)) {
|
||||
if (enchantedBy.isEmpty()) {
|
||||
enchantedBy = null;
|
||||
}
|
||||
getView().updateEnchantedBy(this);
|
||||
getGame().fireEvent(new GameEventCardAttachment(c, this, null, AttachMethod.Enchant));
|
||||
}
|
||||
}
|
||||
public final void unEnchantAllCards() {
|
||||
if (isEnchanted()) {
|
||||
for (Card c : getEnchantedBy(true)) {
|
||||
c.unEnchantEntity(this);
|
||||
}
|
||||
}
|
||||
protected boolean canBeFortifiedBy(final Card aura) {
|
||||
/**
|
||||
* Equip only to Lands which are cards
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canBeEnchantedBy(final Card aura) {
|
||||
protected boolean canBeEnchantedBy(final Card aura) {
|
||||
|
||||
SpellAbility sa = aura.getFirstAttachSpell();
|
||||
TargetRestrictions tgt = null;
|
||||
if (sa != null) {
|
||||
tgt = sa.getTargetRestrictions();
|
||||
}
|
||||
|
||||
return !(hasProtectionFrom(aura)
|
||||
|| ((tgt != null) && !isValid(tgt.getValidTgts(), aura.getController(), aura, sa)));
|
||||
return !((tgt != null) && !isValid(tgt.getValidTgts(), aura.getController(), aura, sa));
|
||||
}
|
||||
|
||||
public abstract boolean hasProtectionFrom(final Card source);
|
||||
public boolean hasProtectionFrom(final Card source) {
|
||||
return hasProtectionFrom(source, false);
|
||||
}
|
||||
|
||||
public abstract boolean hasProtectionFrom(final Card source, final boolean checkSBA);
|
||||
|
||||
// Counters!
|
||||
public boolean hasCounters() {
|
||||
|
||||
@@ -42,18 +42,19 @@ public abstract class GameEntityView extends TrackableObject {
|
||||
set(TrackableProperty.PreventNextDamage, e.getPreventNextDamageTotalShields());
|
||||
}
|
||||
|
||||
public Iterable<CardView> getEnchantedBy() {
|
||||
return get(TrackableProperty.EnchantedBy);
|
||||
public Iterable<CardView> getAttachedCards() {
|
||||
return get(TrackableProperty.AttachedCards);
|
||||
}
|
||||
protected void updateEnchantedBy(GameEntity e) {
|
||||
if (e.isEnchanted()) {
|
||||
set(TrackableProperty.EnchantedBy, CardView.getCollection(e.getEnchantedBy(false)));
|
||||
public boolean hasCardAttachments() {
|
||||
return getAttachedCards() != null;
|
||||
}
|
||||
|
||||
protected void updateAttachedCards(GameEntity e) {
|
||||
if (e.hasCardAttachments()) {
|
||||
set(TrackableProperty.AttachedCards, CardView.getCollection(e.getAttachedCards()));
|
||||
}
|
||||
else {
|
||||
set(TrackableProperty.EnchantedBy, null);
|
||||
set(TrackableProperty.AttachedCards, null);
|
||||
}
|
||||
}
|
||||
public boolean isEnchanted() {
|
||||
return getEnchantedBy() != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ public class GameRules {
|
||||
}
|
||||
|
||||
public boolean hasCommander() {
|
||||
return appliedVariants.contains(GameType.Commander) || appliedVariants.contains(GameType.TinyLeaders)
|
||||
return appliedVariants.contains(GameType.Commander)
|
||||
|| appliedVariants.contains(GameType.TinyLeaders)
|
||||
|| appliedVariants.contains(GameType.Brawl);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package forge.game;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.LobbyPlayer;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameOutcome.AnteResult;
|
||||
@@ -22,6 +19,8 @@ import forge.trackable.TrackableObject;
|
||||
import forge.trackable.TrackableProperty;
|
||||
import forge.util.collect.FCollectionView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GameView extends TrackableObject {
|
||||
private static final long serialVersionUID = 8522884512960961528L;
|
||||
|
||||
@@ -127,7 +126,9 @@ public class GameView extends TrackableObject {
|
||||
void updateGameOver(final Game game) {
|
||||
set(TrackableProperty.GameOver, game.isGameOver());
|
||||
set(TrackableProperty.MatchOver, game.getMatch().isMatchOver());
|
||||
set(TrackableProperty.WinningPlayerName, game.getOutcome().getWinningLobbyPlayer().getName());
|
||||
if (game.getOutcome() != null && game.getOutcome().getWinningLobbyPlayer() != null) {
|
||||
set(TrackableProperty.WinningPlayerName, game.getOutcome().getWinningLobbyPlayer().getName());
|
||||
}
|
||||
set(TrackableProperty.WinningTeam, game.getOutcome() == null ? -1 : game.getOutcome().getWinningTeam());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import forge.game.cost.Cost;
|
||||
import forge.game.spellability.*;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.FileSection;
|
||||
import io.sentry.Sentry;
|
||||
import io.sentry.event.BreadcrumbBuilder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -130,7 +132,16 @@ public final class AbilityFactory {
|
||||
String source = state.getName().isEmpty() ? abString : state.getName();
|
||||
throw new RuntimeException("AbilityFactory : getAbility -- no API in " + source + ": " + abString);
|
||||
}
|
||||
return getAbility(mapParams, type, state, parent);
|
||||
try {
|
||||
return getAbility(mapParams, type, state, parent);
|
||||
} catch (Error | Exception ex) {
|
||||
String msg = "AbilityFactory:getAbility: crash when trying to create ability ";
|
||||
Sentry.getContext().recordBreadcrumb(
|
||||
new BreadcrumbBuilder().setMessage(msg)
|
||||
.withData("Card", state.getName()).withData("Ability", abString).build()
|
||||
);
|
||||
throw new RuntimeException(msg + " of card: " + state.getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static final SpellAbility getAbility(final Card hostCard, final String svar) {
|
||||
|
||||
@@ -29,6 +29,9 @@ import forge.util.Expressions;
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.collect.FCollection;
|
||||
import forge.util.collect.FCollectionView;
|
||||
import io.sentry.Sentry;
|
||||
import io.sentry.event.BreadcrumbBuilder;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
@@ -222,10 +225,6 @@ public class AbilityUtils {
|
||||
if (o != null && o instanceof Card) {
|
||||
cards.add(game.getCardState((Card) o));
|
||||
}
|
||||
} else if (defined.equals("Clones")) {
|
||||
for (final Card clone : hostCard.getClones()) {
|
||||
cards.add(game.getCardState(clone));
|
||||
}
|
||||
} else if (defined.equals("Imprinted")) {
|
||||
for (final Card imprint : hostCard.getImprintedCards()) {
|
||||
cards.add(game.getCardState(imprint));
|
||||
@@ -469,10 +468,18 @@ public class AbilityUtils {
|
||||
players.remove(game.getPhaseHandler().getPlayerTurn());
|
||||
val = CardFactoryUtil.playerXCount(players, calcX[1], card);
|
||||
}
|
||||
else if (hType.startsWith("PropertyYou") && !(ability instanceof SpellAbility)) {
|
||||
// Related to the controller of the card with ability when the ability is static (or otherwise not a SpellAbility)
|
||||
// TODO: This doesn't work in situations when the controller of the card is different from the spell caster
|
||||
// (e.g. opponent's Hollow One exiled by Hostage Taker - cost reduction will not work in this scenario, requires
|
||||
// a more significant rework).
|
||||
players.add(card.getController());
|
||||
val = CardFactoryUtil.playerXCount(players, calcX[1], card);
|
||||
}
|
||||
else if (hType.startsWith("Property") && ability instanceof SpellAbility) {
|
||||
String defined = hType.split("Property")[1];
|
||||
for (Player p : game.getPlayersInTurnOrder()) {
|
||||
if (p.hasProperty(defined, ((SpellAbility)ability).getActivatingPlayer(), ability.getHostCard(), (SpellAbility)ability)) {
|
||||
if (p.hasProperty(defined, ((SpellAbility) ability).getActivatingPlayer(), ability.getHostCard(), (SpellAbility) ability)) {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
@@ -542,7 +549,7 @@ public class AbilityUtils {
|
||||
// Add whole Enchanted list to handlePaid
|
||||
final CardCollection list = new CardCollection();
|
||||
if (card.isEnchanting()) {
|
||||
Object o = card.getEnchanting();
|
||||
Object o = card.getEntityAttachedTo();
|
||||
if (o instanceof Card) {
|
||||
list.add(game.getCardState((Card) o));
|
||||
}
|
||||
@@ -1111,7 +1118,7 @@ public class AbilityUtils {
|
||||
}
|
||||
}
|
||||
else if (defined.equals("EnchantedPlayer")) {
|
||||
final Object o = sa.getHostCard().getEnchanting();
|
||||
final Object o = sa.getHostCard().getEntityAttachedTo();
|
||||
if (o instanceof Player) {
|
||||
if (!players.contains(o)) {
|
||||
players.add((Player) o);
|
||||
@@ -1345,6 +1352,15 @@ public class AbilityUtils {
|
||||
}
|
||||
|
||||
private static void resolveApiAbility(final SpellAbility sa, final Game game) {
|
||||
final Card card = sa.getHostCard();
|
||||
|
||||
String msg = "AbilityUtils:resolveApiAbility: try to resolve API ability";
|
||||
Sentry.getContext().recordBreadcrumb(
|
||||
new BreadcrumbBuilder().setMessage(msg)
|
||||
.withData("Api", sa.getApi().toString())
|
||||
.withData("Card", card.getName()).withData("SA", sa.toString()).build()
|
||||
);
|
||||
|
||||
// check conditions
|
||||
if (sa.getConditions().areMet(sa)) {
|
||||
if (sa.isWrapper() || StringUtils.isBlank(sa.getParam("UnlessCost"))) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user