mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-13 09:17:59 +00:00
Compare commits
2 Commits
reduce-bit
...
forge-2.0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a29da54b2e | ||
|
|
ec63b230c8 |
139
.github/workflows/maven-publish.yml
vendored
139
.github/workflows/maven-publish.yml
vendored
@@ -2,21 +2,10 @@ name: Publish Desktop Forge
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
|
||||||
debug_enabled:
|
|
||||||
type: boolean
|
|
||||||
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
|
|
||||||
required: false
|
|
||||||
default: false
|
|
||||||
release_android:
|
|
||||||
type: boolean
|
|
||||||
description: 'Also try to release android build'
|
|
||||||
required: false
|
|
||||||
default: false
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: github.repository_owner == 'Card-Forge'
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -43,132 +32,10 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
git config user.email "actions@github.com"
|
git config user.email "actions@github.com"
|
||||||
git config user.name "GitHub Actions"
|
git config user.name "GitHub Actions"
|
||||||
|
- name: Build/Install/Publish to GitHub Packages Apache Maven
|
||||||
- name: Install old maven (3.8.1)
|
|
||||||
run: |
|
|
||||||
curl -o apache-maven-3.8.1-bin.tar.gz https://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
|
|
||||||
tar xf apache-maven-3.8.1-bin.tar.gz
|
|
||||||
export PATH=$PWD/apache-maven-3.8.1/bin:$PATH
|
|
||||||
export MAVEN_HOME=$PWD/apache-maven-3.8.1
|
|
||||||
mvn --version
|
|
||||||
|
|
||||||
- name: Setup tmate session
|
|
||||||
uses: mxschmitt/action-tmate@v3
|
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
|
|
||||||
|
|
||||||
- name: Setup android requirements
|
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.release_android }}
|
|
||||||
run: |
|
|
||||||
JAVA_HOME=${JAVA_HOME_17_X64} ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT --install "build-tools;35.0.0" "platform-tools" "platforms;android-35"
|
|
||||||
cd forge-gui-android
|
|
||||||
echo "${{ secrets.FORGE_KEYSTORE }}" > forge.keystore.asc
|
|
||||||
gpg -d --passphrase "${{ secrets.FORGE_KEYSTORE_PASSPHRASE }}" --batch forge.keystore.asc > forge.keystore
|
|
||||||
cd -
|
|
||||||
mkdir -p ~/.m2/repository/com/simpligility/maven/plugins/android-maven-plugin/4.6.2
|
|
||||||
cd ~/.m2/repository/com/simpligility/maven/plugins/android-maven-plugin/4.6.2
|
|
||||||
curl -L -o android-maven-plugin-4.6.2.jar https://github.com/Card-Forge/android-maven-plugin/releases/download/4.6.2/android-maven-plugin-4.6.2.jar
|
|
||||||
curl -L -o android-maven-plugin-4.6.2.pom https://github.com/Card-Forge/android-maven-plugin/releases/download/4.6.2/android-maven-plugin-4.6.2.pom
|
|
||||||
cd -
|
|
||||||
mvn install -Dmaven.test.skip=true
|
|
||||||
mvn dependency:tree
|
|
||||||
|
|
||||||
|
|
||||||
- name: Build/Install/Publish Desktop to GitHub Packages Apache Maven
|
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' && !inputs.release_android }}
|
|
||||||
run: |
|
run: |
|
||||||
export DISPLAY=":1"
|
export DISPLAY=":1"
|
||||||
Xvfb :1 -screen 0 800x600x8 &
|
Xvfb :1 -screen 0 800x600x8 &
|
||||||
export _JAVA_OPTIONS="-Xmx2g"
|
mvn -U -B clean -P windows-linux install release:clean release:prepare release:perform -T 1C -Dcardforge-repo.username=${{ secrets.FTP_USERNAME }} -Dcardforge-repo.password=${{ secrets.FTP_PASSWORD }}
|
||||||
d=$(date +%m.%d)
|
|
||||||
# build only desktop and only try to move desktop files
|
|
||||||
mvn -U -B clean -P windows-linux install -DskipTests -Dskip.flatten=true -e -T 1C release:clean release:prepare release:perform
|
|
||||||
mkdir izpack
|
|
||||||
# move bz2 and jar from work dir to izpack dir
|
|
||||||
mv /home/runner/work/forge/forge/forge-installer/*/*.{bz2,jar} izpack/
|
|
||||||
# move desktop build.txt and version.txt to izpack
|
|
||||||
mv /home/runner/work/forge/forge/forge-gui-desktop/target/classes/*.txt izpack/
|
|
||||||
cd izpack
|
|
||||||
ls
|
|
||||||
echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
|
|
||||||
- name: Build/Install/Publish Desktop+Android to GitHub Packages Apache Maven
|
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.release_android }}
|
|
||||||
run: |
|
|
||||||
export DISPLAY=":1"
|
|
||||||
Xvfb :1 -screen 0 800x600x8 &
|
|
||||||
export _JAVA_OPTIONS="-Xmx2g"
|
|
||||||
d=$(date +%m.%d)
|
|
||||||
# build both desktop and android
|
|
||||||
mvn -U -B clean -P windows-linux,android-release-build install -e -Dcardforge-repo.username=${{ secrets.FTP_USERNAME }} -Dcardforge-repo.password=${{ secrets.FTP_PASSWORD }} -Dandroid.sdk.path=/usr/local/lib/android/sdk -Dandroid.buildToolsVersion=35.0.0
|
|
||||||
mkdir izpack
|
|
||||||
# move bz2 and jar from work dir to izpack dir
|
|
||||||
mv /home/runner/work/forge/forge/forge-installer/*/*.{bz2,jar} izpack/
|
|
||||||
# move desktop build.txt and version.txt to izpack
|
|
||||||
mv /home/runner/work/forge/forge/forge-gui-desktop/target/classes/*.txt izpack/
|
|
||||||
# move android apk and assets.zip
|
|
||||||
mv /home/runner/work/forge/forge/forge-gui-android/target/*-signed-aligned.apk izpack/
|
|
||||||
mv /home/runner/work/forge/forge/forge-gui-android/target/assets.zip izpack/
|
|
||||||
cd izpack
|
|
||||||
ls
|
|
||||||
echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
|
||||||
|
|
||||||
- name: Upload snapshot to GitHub Prerelease
|
|
||||||
uses: ncipollo/release-action@v1
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
name: Release ${{ env.GIT_TAG }}
|
|
||||||
tag: ${{ env.GIT_TAG }}
|
|
||||||
artifacts: izpack/*
|
|
||||||
allowUpdates: true
|
|
||||||
removeArtifacts: true
|
|
||||||
makeLatest: true
|
|
||||||
|
|
||||||
- name: 🔧 Install XML tools
|
|
||||||
run: sudo apt-get install -y libxml2-utils
|
|
||||||
|
|
||||||
- name: 🔼 Bump versionCode in root POM
|
|
||||||
id: bump_version
|
|
||||||
run: |
|
|
||||||
cd /home/runner/work/forge/forge/
|
|
||||||
|
|
||||||
current_version=$(xmllint --xpath "//*[local-name()='versionCode']/text()" pom.xml)
|
|
||||||
echo "Current versionCode: $current_version"
|
|
||||||
|
|
||||||
IFS='.' read -r major minor patch <<< "${current_version}"
|
|
||||||
new_patch=$(printf "%02d" $((10#$patch + 1)))
|
|
||||||
new_version="${major}.${minor}.${new_patch}"
|
|
||||||
|
|
||||||
sed -i -E "s|<versionCode>.*</versionCode>|<versionCode>${new_version}</versionCode>|" pom.xml
|
|
||||||
|
|
||||||
echo "version_code=${new_version}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: ♻️ Restore {revision} in child POMs
|
|
||||||
run: |
|
|
||||||
find . -name pom.xml ! -path "./pom.xml" | while read -r pom; do
|
|
||||||
sed -i -E 's|<version>2\.0+\.[0-9]+(-SNAPSHOT)?</version>|<version>${revision}</version>|' "$pom"
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: 💾 Commit restored {revision}
|
|
||||||
run: |
|
|
||||||
# Add only pom.xml files
|
|
||||||
find . -name pom.xml -exec git add {} \;
|
|
||||||
|
|
||||||
# Commit if there are changes
|
|
||||||
if git diff --cached --quiet; then
|
|
||||||
echo "No pom.xml changes to commit."
|
|
||||||
else
|
|
||||||
git commit -m "Restore POM files for preparation of next release" || echo "No changes to commit"
|
|
||||||
git push
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Send failure notification to Discord
|
|
||||||
if: failure() # This step runs only if the job fails
|
|
||||||
run: |
|
|
||||||
curl -X POST -H "Content-Type: application/json" \
|
|
||||||
-d "{\"content\": \"🔴 Release Build Failed in branch: \`${{ github.ref_name }}\` by \`${{ github.actor }}\`.\nCheck logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
|
|
||||||
${{ secrets.DISCORD_AUTOMATION_WEBHOOK }}
|
|
||||||
|
|||||||
32
.github/workflows/snapshot-both-pc-android.yml
vendored
32
.github/workflows/snapshot-both-pc-android.yml
vendored
@@ -8,9 +8,6 @@ on:
|
|||||||
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
|
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
schedule:
|
|
||||||
# * is a special character in YAML so you have to quote this string
|
|
||||||
- cron: '00 18 * * *'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -112,21 +109,16 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
|
|
||||||
- name: Upload snapshot to GitHub Prerelease
|
- name: 📂 Sync files
|
||||||
uses: ncipollo/release-action@v1
|
uses: SamKirkland/FTP-Deploy-Action@v4.3.4
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
with:
|
||||||
name: Daily Snapshot
|
server: ftp.cardforge.org
|
||||||
tag: daily-snapshots
|
username: ${{ secrets.FTP_USERNAME }}
|
||||||
prerelease: true
|
password: ${{ secrets.FTP_PASSWORD }}
|
||||||
artifacts: izpack/*
|
local-dir: izpack/
|
||||||
allowUpdates: true
|
server-dir: downloads/dailysnapshots/
|
||||||
removeArtifacts: true
|
state-name: .ftp-deploy-both-sync-state.json
|
||||||
|
exclude: |
|
||||||
- name: Send failure notification to Discord
|
*.pom
|
||||||
if: failure() # This step runs only if the job fails
|
*.repositories
|
||||||
run: |
|
*.xml
|
||||||
curl -X POST -H "Content-Type: application/json" \
|
|
||||||
-d "{\"content\": \"🔴 Snapshot Build Failed in branch: \`${{ github.ref_name }}\` by \`${{ github.actor }}\`.\nCheck logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
|
|
||||||
${{ secrets.DISCORD_AUTOMATION_WEBHOOK }}
|
|
||||||
|
|||||||
4
.github/workflows/snapshots-android.yml
vendored
4
.github/workflows/snapshots-android.yml
vendored
@@ -13,6 +13,10 @@ on:
|
|||||||
# description: 'Upload the completed Android package'
|
# description: 'Upload the completed Android package'
|
||||||
# required: false
|
# required: false
|
||||||
# default: true
|
# default: true
|
||||||
|
schedule:
|
||||||
|
# * is a special character in YAML so you have to quote this string
|
||||||
|
- cron: '00 19 * * *'
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
3
.github/workflows/snapshots-pc.yml
vendored
3
.github/workflows/snapshots-pc.yml
vendored
@@ -8,6 +8,9 @@ on:
|
|||||||
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
|
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
|
schedule:
|
||||||
|
# * is a special character in YAML so you have to quote this string
|
||||||
|
- cron: '30 18 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Dev instructions here: [Getting Started](https://github.com/Card-Forge/forge/wik
|
|||||||
|
|
||||||
## Requirements / Tools
|
## Requirements / Tools
|
||||||
|
|
||||||
- your favourite Java IDE (IntelliJ, Eclipse, VSCodium, Emacs, Vi...)
|
- you favourite Java IDE (IntelliJ, Eclipse, VSCodium, Emacs, Vi...)
|
||||||
- Java JDK 17 or later
|
- Java JDK 17 or later
|
||||||
- Git
|
- Git
|
||||||
- Git client (optional)
|
- Git client (optional)
|
||||||
@@ -22,41 +22,42 @@ Dev instructions here: [Getting Started](https://github.com/Card-Forge/forge/wik
|
|||||||
|
|
||||||
- Clone your forked project to your local machine
|
- 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`
|
- 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`
|
||||||
|
|
||||||
## IntelliJ
|
## IntelliJ
|
||||||
|
|
||||||
IntelliJ is the recommended IDE for Forge development. Quick start guide for [setting up the Forge project within IntelliJ](https://github.com/Card-Forge/forge/wiki/IntelliJ-setup).
|
IntelliJ is the recommended IDE for Forge development. Quick start guide for [setting up the Forge project within IntelliJ](https://github.com/Card-Forge/forge/wiki/IntelliJ-setup).
|
||||||
|
|
||||||
|
|
||||||
## Eclipse
|
## Eclipse
|
||||||
|
|
||||||
Eclipse includes Maven integration so a separate install is not necessary. For other IDEs, your mileage may vary.
|
Eclipse includes Maven integration so a separate install is not necessary. For other IDEs, your mileage may vary.
|
||||||
At this time, Eclipse is not the recommended IDE for Forge development.
|
At this time, Eclipse is not the recommended IDE for Forge development.
|
||||||
|
|
||||||
### Project Setup
|
### Project Setup
|
||||||
|
|
||||||
- Follow the instructions for cloning from GitHub. You'll need to setup an account and your SSH key.
|
- Follow the instructions for cloning from GitHub. You'll need to setup an account and your SSH key.
|
||||||
|
|
||||||
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
|
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 GitHub profile under
|
the OpenSSH public key. If you just leave the dialog open, you can copy and paste the key from it to your GitHub profile under
|
||||||
"SSH keys". Run pageant.exe and add the private key generated earlier. TortoiseGit will use this for accessing GitHub.
|
"SSH keys". Run pageant.exe and add the private key generated earlier. TortoiseGit will use this for accessing GitHub.
|
||||||
|
|
||||||
- Fork the Forge git repo to your GitHub account.
|
- Fork the Forge git repo to your GitHub account.
|
||||||
|
|
||||||
- Clone your forked repo to your local machine.
|
- Clone your forked repo to your local machine.
|
||||||
|
|
||||||
- Make sure the Java SDK is installed -- not just the JRE. Java 17 or newer required. If you execute `java -version` at the shell or command prompt, it should report version 17 or later.
|
- Make sure the Java SDK is installed -- not just the JRE. Java 17 or newer required. If you execute `java -version` at the shell or command prompt, it should report version 17 or later.
|
||||||
|
|
||||||
- Install Eclipse 2021-12 or later for Java. Launch it.
|
- Install Eclipse 2021-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
|
- 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.
|
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
|
- 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
|
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.
|
for this first time through.
|
||||||
|
|
||||||
- Once everything builds, all errors should disappear. You can now advance to Project launch.
|
- Once everything builds, all errors should disappear. You can now advance to Project launch.
|
||||||
|
|
||||||
### Project Launch
|
### Project Launch
|
||||||
|
|
||||||
@@ -66,15 +67,15 @@ 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
|
- Right-click on forge-gui-desktop > Run As... > Java Application > "Main - forge.view" > Ok
|
||||||
|
|
||||||
- The familiar Forge splash screen, etc. should appear. Enjoy!
|
- The familiar Forge splash screen, etc. should appear. Enjoy!
|
||||||
|
|
||||||
#### Mobile (Desktop dev)
|
#### 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.
|
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.
|
- 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!
|
- A view similar to a mobile phone should appear. Enjoy!
|
||||||
|
|
||||||
### Eclipse / Android SDK Integration
|
### Eclipse / Android SDK Integration
|
||||||
|
|
||||||
@@ -98,7 +99,7 @@ TBD
|
|||||||
|
|
||||||
#### Android Platform
|
#### Android Platform
|
||||||
|
|
||||||
In Intellij, if the SDK Manager is not already running, go to Tools > Android > Android SDK Manager. Install the following options / versions:
|
In Intellij, if the SDK Manager is not already running, go to Tools > Android > Android SDK Manager. Install the following options / versions:
|
||||||
|
|
||||||
- Android SDK Build-tools 35.0.0
|
- Android SDK Build-tools 35.0.0
|
||||||
- Android 15 (API 35) SDK Platform
|
- Android 15 (API 35) SDK Platform
|
||||||
@@ -123,11 +124,10 @@ TBD
|
|||||||
|
|
||||||
SNAPSHOT builds can be built via the Maven integration in Eclipse.
|
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...
|
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
|
- 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.
|
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-[version]-SNAPSHOT
|
The resulting snapshot will be found at: forge-gui-desktop/target/forge-gui-desktop-[version]-SNAPSHOT
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ Card scripting resources are found in the forge-gui/res/ path.
|
|||||||
|
|
||||||
### Project Hierarchy
|
### Project Hierarchy
|
||||||
|
|
||||||
Forge is divided into 4 primary projects with additional projects that target specific platform releases. The primary projects are:
|
Forge is divided into 4 primary projects with additional projects that target specific platform releases. The primary projects are:
|
||||||
|
|
||||||
- forge-ai
|
- forge-ai
|
||||||
- forge-core
|
- forge-core
|
||||||
@@ -158,38 +158,32 @@ The platform-specific projects are:
|
|||||||
|
|
||||||
#### forge-ai
|
#### forge-ai
|
||||||
|
|
||||||
The forge-ai project contains the computer opponent logic for gameplay. It includes decision-making algorithms for specific abilities, cards and turn phases.
|
|
||||||
|
|
||||||
#### forge-core
|
#### forge-core
|
||||||
|
|
||||||
The forge-core project contains the core game engine, card mechanics, rules engine, and fundamental game logic. It includes the implementation of Magic: The Gathering rules, card interactions, and the game state management system.
|
|
||||||
|
|
||||||
#### forge-game
|
#### forge-game
|
||||||
|
|
||||||
The forge-game project handles the game session management, player interactions, and game flow control. It includes implementations for multiplayer support, game modes, matchmaking, and game state persistence. This module bridges the core game engine with the user interface and networking components.
|
|
||||||
|
|
||||||
#### forge-gui
|
#### forge-gui
|
||||||
|
|
||||||
The forge-gui project contains the user interface components and rendering logic for the game. It includes the main game window, card displays, player interactions, and the scripting resource definitions in the res/ path.
|
The forge-gui project includes the scripting resource definitions in the res/ path.
|
||||||
|
|
||||||
#### forge-gui-android
|
#### forge-gui-android
|
||||||
|
|
||||||
Libgdx-based backend targeting Android. Requires Android SDK and relies on forge-gui-mobile for GUI logic.
|
Libgdx-based backend targeting Android. Requires Android SDK and relies on forge-gui-mobile for GUI logic.
|
||||||
|
|
||||||
#### forge-gui-desktop
|
#### forge-gui-desktop
|
||||||
|
|
||||||
Java Swing based GUI targeting desktop machines.
|
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.
|
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
|
#### forge-gui-ios
|
||||||
|
|
||||||
Libgdx-based backend targeting iOS. Relies on forge-gui-mobile for GUI logic.
|
Libgdx-based backend targeting iOS. Relies on forge-gui-mobile for GUI logic.
|
||||||
|
|
||||||
#### forge-gui-mobile
|
#### 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.
|
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
|
#### forge-gui-mobile-dev
|
||||||
|
|
||||||
Libgdx backend for desktop development for mobile backends. Utilizes LWJGL. Relies on forge-gui-mobile for GUI logic.
|
Libgdx backend for desktop development for mobile backends. Utilizes LWJGL. Relies on forge-gui-mobile for GUI logic.
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -1,4 +1,4 @@
|
|||||||
# ⚔️ Forge: The Magic: The Gathering Rules Engine
|
# ⚔️ Forge: The Magic: The Gathering Rules Engine
|
||||||
|
|
||||||
Join the **Forge community** on [Discord](https://discord.gg/HcPJNyD66a)!
|
Join the **Forge community** on [Discord](https://discord.gg/HcPJNyD66a)!
|
||||||
|
|
||||||
@@ -26,14 +26,13 @@ Join the **Forge community** on [Discord](https://discord.gg/HcPJNyD66a)!
|
|||||||
|
|
||||||
### 📥 Desktop Installation
|
### 📥 Desktop Installation
|
||||||
1. **Latest Releases:** Download the latest version [here](https://github.com/Card-Forge/forge/releases/latest).
|
1. **Latest Releases:** Download the latest version [here](https://github.com/Card-Forge/forge/releases/latest).
|
||||||
2. **Snapshot Build:** For the latest development version, grab the `forge-gui-desktop` tarball from our [Snapshot Build](https://github.com/Card-Forge/forge/releases/tag/daily-snapshots).
|
2. **Snapshot Build:** For the latest development version, grab the `forge-gui-desktop` tarball from our [Snapshot Build](https://downloads.cardforge.org/dailysnapshots/).
|
||||||
- **Tip:** Extract to a new folder to prevent version conflicts.
|
- **Tip:** Extract to a new folder to prevent version conflicts.
|
||||||
3. **User Data Management:** Previous players’ data is preserved during upgrades.
|
3. **User Data Management:** Previous players’ data is preserved during upgrades.
|
||||||
4. **Java Requirement:** Ensure you have **Java 17 or later** installed.
|
4. **Java Requirement:** Ensure you have **Java 17 or later** installed.
|
||||||
|
|
||||||
### 📱 Android Installation
|
### 📱 Android Installation
|
||||||
- _(Note: **Android 11** is the minimum requirements with at least **6GB RAM** to run smoothly. You need to enable **"Install unknown apps"** for Forge to initialize and update itself)_
|
- Download the **APK** from the [Snapshot Build](https://downloads.cardforge.org/dailysnapshots/). On the first launch, Forge will automatically download all necessary assets.
|
||||||
- Download the **APK** from the [Snapshot Build](https://github.com/Card-Forge/forge/releases/tag/daily-snapshots). On the first launch, Forge will automatically download all necessary assets.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -47,13 +46,11 @@ Embark on a thrilling single-player journey where you can:
|
|||||||
- Challenge diverse AI opponents.
|
- Challenge diverse AI opponents.
|
||||||
- Collect cards and items to boost your abilities.
|
- Collect cards and items to boost your abilities.
|
||||||
|
|
||||||
<img width="1282" height="752" alt="Shandalar World" src="https://github.com/user-attachments/assets/9af31471-d688-442f-9418-9807d8635b72" />
|

|
||||||
|
|
||||||
### 🔍 Quest Modes
|
### 🔍 Quest Modes
|
||||||
Engage in focused gameplay without the overworld exploration—perfect for quick sessions!
|
Engage in focused gameplay without the overworld exploration—perfect for quick sessions!
|
||||||
|
|
||||||
<img width="1282" height="752" alt="Quest Duels" src="https://github.com/user-attachments/assets/b9613b1c-e8c3-4320-8044-6922c519aad4" />
|
|
||||||
|
|
||||||
### 🤖 AI Formats
|
### 🤖 AI Formats
|
||||||
Test your skills against AI in multiple formats:
|
Test your skills against AI in multiple formats:
|
||||||
- **Sealed**
|
- **Sealed**
|
||||||
@@ -63,8 +60,6 @@ Test your skills against AI in multiple formats:
|
|||||||
|
|
||||||
For comprehensive gameplay instructions, visit our [Gameplay Guide](https://github.com/Card-Forge/forge/wiki/Gameplay-Guide).
|
For comprehensive gameplay instructions, visit our [Gameplay Guide](https://github.com/Card-Forge/forge/wiki/Gameplay-Guide).
|
||||||
|
|
||||||
<img width="1282" height="752" alt="Sealed" src="https://github.com/user-attachments/assets/ae603dbd-4421-4753-a333-87cb0a28d772" />
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 💬 Support & Community
|
## 💬 Support & Community
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>forge</artifactId>
|
<artifactId>forge</artifactId>
|
||||||
<groupId>forge</groupId>
|
<groupId>forge</groupId>
|
||||||
<version>${revision}</version>
|
<version>2.0.02</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>forge</artifactId>
|
<artifactId>forge</artifactId>
|
||||||
<groupId>forge</groupId>
|
<groupId>forge</groupId>
|
||||||
<version>${revision}</version>
|
<version>2.0.02</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>forge-ai</artifactId>
|
<artifactId>forge-ai</artifactId>
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package forge.ai;
|
|
||||||
|
|
||||||
public record AiAbilityDecision(int rating, AiPlayDecision decision) {
|
|
||||||
private static int MIN_RATING = 30;
|
|
||||||
|
|
||||||
public boolean willingToPlay() {
|
|
||||||
return rating > MIN_RATING && decision.willingToPlay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -37,7 +37,6 @@ import forge.game.spellability.SpellAbility;
|
|||||||
import forge.game.spellability.SpellAbilityPredicates;
|
import forge.game.spellability.SpellAbilityPredicates;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
import forge.game.staticability.StaticAbilityAssignCombatDamageAsUnblocked;
|
import forge.game.staticability.StaticAbilityAssignCombatDamageAsUnblocked;
|
||||||
import forge.game.staticability.StaticAbilityMode;
|
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
@@ -145,15 +144,13 @@ public class AiAttackController {
|
|||||||
sa.setActivatingPlayer(defender);
|
sa.setActivatingPlayer(defender);
|
||||||
if (sa.isCrew() && !ComputerUtilCost.checkTapTypeCost(defender, sa.getPayCosts(), c, sa, tappedDefenders)) {
|
if (sa.isCrew() && !ComputerUtilCost.checkTapTypeCost(defender, sa.getPayCosts(), c, sa, tappedDefenders)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if (!ComputerUtilCost.canPayCost(sa, defender, false) || !sa.getRestrictions().checkOtherRestrictions(c, sa, defender)) {
|
||||||
if (!ComputerUtilCost.canPayCost(sa, defender, false) || !sa.getRestrictions().checkOtherRestrictions(c, sa, defender)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Card animatedCopy = AnimateAi.becomeAnimated(c, sa);
|
Card animatedCopy = AnimateAi.becomeAnimated(c, sa);
|
||||||
if (animatedCopy.isCreature()) {
|
if (animatedCopy.isCreature()) {
|
||||||
// TODO imprecise, only works 100% for colorless mana
|
|
||||||
int saCMC = sa.getPayCosts() != null && sa.getPayCosts().hasManaCost() ?
|
int saCMC = sa.getPayCosts() != null && sa.getPayCosts().hasManaCost() ?
|
||||||
sa.getPayCosts().getTotalMana().getCMC() : 0;
|
sa.getPayCosts().getTotalMana().getCMC() : 0; // FIXME: imprecise, only works 100% for colorless mana
|
||||||
if (totalMana - manaReserved >= saCMC) {
|
if (totalMana - manaReserved >= saCMC) {
|
||||||
manaReserved += saCMC;
|
manaReserved += saCMC;
|
||||||
defenders.add(animatedCopy);
|
defenders.add(animatedCopy);
|
||||||
@@ -1590,7 +1587,7 @@ public class AiAttackController {
|
|||||||
// but there are no creatures it can target, no need to exert with it
|
// but there are no creatures it can target, no need to exert with it
|
||||||
boolean missTarget = false;
|
boolean missTarget = false;
|
||||||
for (StaticAbility st : c.getStaticAbilities()) {
|
for (StaticAbility st : c.getStaticAbilities()) {
|
||||||
if (!st.checkMode(StaticAbilityMode.OptionalAttackCost)) {
|
if (!"OptionalAttackCost".equals(st.getParam("Mode"))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SpellAbility sa = st.getPayingTrigSA();
|
SpellAbility sa = st.getPayingTrigSA();
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public class AiCardMemory {
|
|||||||
ATTACHED_THIS_TURN, // These equipments were attached to something already this turn
|
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
|
ANIMATED_THIS_TURN, // These cards had their AF Animate effect activated this turn
|
||||||
BOUNCED_THIS_TURN, // These cards were bounced 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
|
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
|
MARKED_TO_AVOID_REENTRY, // These cards may cause a stack smash when processed recursively, and are thus marked to avoid a crash
|
||||||
PAYS_TAP_COST, // These cards will be tapped as part of a cost and cannot be chosen in another part
|
PAYS_TAP_COST, // These cards will be tapped as part of a cost and cannot be chosen in another part
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import forge.game.replacement.ReplacementType;
|
|||||||
import forge.game.spellability.*;
|
import forge.game.spellability.*;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
import forge.game.staticability.StaticAbilityDisableTriggers;
|
import forge.game.staticability.StaticAbilityDisableTriggers;
|
||||||
import forge.game.staticability.StaticAbilityMode;
|
|
||||||
import forge.game.staticability.StaticAbilityMustTarget;
|
import forge.game.staticability.StaticAbilityMustTarget;
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
@@ -66,10 +65,10 @@ import io.sentry.Breadcrumb;
|
|||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.FutureTask;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
@@ -293,7 +292,7 @@ public class AiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// can't fetch partner isn't problematic
|
// can't fetch partner isn't problematic
|
||||||
if (tr.isKeyword(Keyword.PARTNER)) {
|
if (tr.getKeyword() != null && tr.getKeyword().getOriginal().startsWith("Partner")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +480,7 @@ public class AiController {
|
|||||||
|
|
||||||
if (lands.size() >= Math.max(maxCmcInHand, 6)) {
|
if (lands.size() >= Math.max(maxCmcInHand, 6)) {
|
||||||
// don't play MDFC land if other side is spell and enough lands are available
|
// don't play MDFC land if other side is spell and enough lands are available
|
||||||
if (!c.isLand() || (c.isModal() && !c.getState(CardStateName.Backside).getType().isLand())) {
|
if (!c.isLand() || (c.isModal() && !c.getState(CardStateName.Modal).getType().isLand())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -690,6 +689,7 @@ public class AiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO handle fetchlands and what they can fetch for
|
// TODO handle fetchlands and what they can fetch for
|
||||||
// determine new color pips
|
// determine new color pips
|
||||||
int[] card_counts = new int[6]; // in WUBRGC order
|
int[] card_counts = new int[6]; // in WUBRGC order
|
||||||
@@ -909,14 +909,56 @@ public class AiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the "heaviest" check, which also sets up targets, defines X, etc.
|
int oldCMC = -1;
|
||||||
AiPlayDecision canPlay = canPlaySa(sa);
|
boolean xCost = sa.costHasX() || host.hasKeyword(Keyword.STRIVE) || sa.getApi() == ApiType.Charm;
|
||||||
|
if (!xCost) {
|
||||||
|
if (!ComputerUtilCost.canPayCost(sa, player, sa.isTrigger())) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
// TODO check for Reduce too, e.g. Battlefield Thaumaturge could make it castable
|
||||||
|
if (!sa.getAllTargetChoices().isEmpty()) {
|
||||||
|
oldCMC = CostAdjustment.adjust(sa.getPayCosts(), sa, false).getTotalMana().getCMC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AiPlayDecision canPlay = canPlaySa(sa); // this is the "heaviest" check, which also sets up targets, defines X, etc.
|
||||||
|
|
||||||
if (canPlay != AiPlayDecision.WillPlay) {
|
if (canPlay != AiPlayDecision.WillPlay) {
|
||||||
return canPlay;
|
return canPlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComputerUtilCost.canPayCost(sa, player, sa.isTrigger())) {
|
// Account for possible Ward after the spell is fully targeted
|
||||||
|
// TODO: ideally, this should be done while targeting, so that a different target can be preferred if the best
|
||||||
|
// one is warded and can't be paid for. (currently it will be stuck with the target until it could pay)
|
||||||
|
if (!sa.isSpell() || sa.isCounterableBy(null)) {
|
||||||
|
for (TargetChoices tc : sa.getAllTargetChoices()) {
|
||||||
|
for (Card tgt : tc.getTargetCards()) {
|
||||||
|
// TODO some older cards don't use the keyword, so check for trigger instead
|
||||||
|
if (tgt.hasKeyword(Keyword.WARD) && tgt.isInPlay() && tgt.getController().isOpponentOf(host.getController())) {
|
||||||
|
Cost wardCost = ComputerUtilCard.getTotalWardCost(tgt);
|
||||||
|
if (wardCost.hasManaCost()) {
|
||||||
|
xCost |= wardCost.getTotalMana().getCMC() > 0;
|
||||||
|
}
|
||||||
|
SpellAbilityAi topAI = new SpellAbilityAi() {};
|
||||||
|
if (!topAI.willPayCosts(player, sa, wardCost, host)) {
|
||||||
|
return AiPlayDecision.CostNotAcceptable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if some target raised cost
|
||||||
|
if (!xCost && oldCMC > -1) {
|
||||||
|
int finalCMC = CostAdjustment.adjust(sa.getPayCosts(), sa, false).getTotalMana().getCMC();
|
||||||
|
if (finalCMC > oldCMC) {
|
||||||
|
xCost = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xCost && !ComputerUtilCost.canPayCost(sa, player, sa.isTrigger())) {
|
||||||
// for dependent costs with X, e.g. Repeal, which require a valid target to be specified before a decision can be made
|
// 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)
|
// 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;
|
return AiPlayDecision.CantAfford;
|
||||||
@@ -929,6 +971,8 @@ public class AiController {
|
|||||||
return AiPlayDecision.CantAfford;
|
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;
|
return AiPlayDecision.WillPlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,7 +1015,7 @@ public class AiController {
|
|||||||
Sentry.setExtra("Card", card.getName());
|
Sentry.setExtra("Card", card.getName());
|
||||||
Sentry.setExtra("SA", sa.toString());
|
Sentry.setExtra("SA", sa.toString());
|
||||||
|
|
||||||
boolean canPlay = SpellApiToAi.Converter.get(sa).canPlayWithSubs(player, sa).willingToPlay();
|
boolean canPlay = SpellApiToAi.Converter.get(sa).canPlayAIWithSubs(player, sa);
|
||||||
|
|
||||||
// remove added extra
|
// remove added extra
|
||||||
Sentry.removeExtra("Card");
|
Sentry.removeExtra("Card");
|
||||||
@@ -1084,7 +1128,7 @@ public class AiController {
|
|||||||
// Memory Crystal-like effects need special handling
|
// Memory Crystal-like effects need special handling
|
||||||
for (Card c : game.getCardsIn(ZoneType.Battlefield)) {
|
for (Card c : game.getCardsIn(ZoneType.Battlefield)) {
|
||||||
for (StaticAbility s : c.getStaticAbilities()) {
|
for (StaticAbility s : c.getStaticAbilities()) {
|
||||||
if (s.checkMode(StaticAbilityMode.ReduceCost)
|
if ("ReduceCost".equals(s.getParam("Mode"))
|
||||||
&& "Spell.Buyback".equals(s.getParam("ValidSpell"))) {
|
&& "Spell.Buyback".equals(s.getParam("ValidSpell"))) {
|
||||||
neededMana -= AbilityUtils.calculateAmount(c, s.getParam("Amount"), s);
|
neededMana -= AbilityUtils.calculateAmount(c, s.getParam("Amount"), s);
|
||||||
}
|
}
|
||||||
@@ -1349,9 +1393,9 @@ public class AiController {
|
|||||||
if (spell instanceof SpellApiBased) {
|
if (spell instanceof SpellApiBased) {
|
||||||
boolean chance = false;
|
boolean chance = false;
|
||||||
if (withoutPayingManaCost) {
|
if (withoutPayingManaCost) {
|
||||||
chance = SpellApiToAi.Converter.get(spell).doTriggerNoCostWithSubs(player, spell, mandatory).willingToPlay();
|
chance = SpellApiToAi.Converter.get(spell).doTriggerNoCostWithSubs(player, spell, mandatory);
|
||||||
} else {
|
} else {
|
||||||
chance = SpellApiToAi.Converter.get(spell).doTrigger(player, spell, mandatory);
|
chance = SpellApiToAi.Converter.get(spell).doTriggerAI(player, spell, mandatory);
|
||||||
}
|
}
|
||||||
if (!chance) {
|
if (!chance) {
|
||||||
return AiPlayDecision.TargetingFailed;
|
return AiPlayDecision.TargetingFailed;
|
||||||
@@ -1664,7 +1708,7 @@ public class AiController {
|
|||||||
Sentry.captureMessage(ex.getMessage() + "\nAssertionError [verifyTransitivity]: " + assertex);
|
Sentry.captureMessage(ex.getMessage() + "\nAssertionError [verifyTransitivity]: " + assertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureTask<SpellAbility> future = new FutureTask<>(() -> {
|
CompletableFuture<SpellAbility> future = CompletableFuture.supplyAsync(() -> {
|
||||||
//avoid ComputerUtil.aiLifeInDanger in loops as it slows down a lot.. call this outside loops will generally be fast...
|
//avoid ComputerUtil.aiLifeInDanger in loops as it slows down a lot.. call this outside loops will generally be fast...
|
||||||
boolean isLifeInDanger = useLivingEnd && ComputerUtil.aiLifeInDanger(player, true, 0);
|
boolean isLifeInDanger = useLivingEnd && ComputerUtil.aiLifeInDanger(player, true, 0);
|
||||||
for (final SpellAbility sa : ComputerUtilAbility.getOriginalAndAltCostAbilities(all, player)) {
|
for (final SpellAbility sa : ComputerUtilAbility.getOriginalAndAltCostAbilities(all, player)) {
|
||||||
@@ -1742,18 +1786,13 @@ public class AiController {
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
Thread t = new Thread(future);
|
// instead of computing all available concurrently just add a simple timeout depending on the user prefs
|
||||||
t.start();
|
|
||||||
try {
|
try {
|
||||||
// instead of computing all available concurrently just add a simple timeout depending on the user prefs
|
if (game.AI_CAN_USE_TIMEOUT)
|
||||||
return future.get(game.getAITimeout(), TimeUnit.SECONDS);
|
return future.completeOnTimeout(null, game.getAITimeout(), TimeUnit.SECONDS).get();
|
||||||
|
else
|
||||||
|
return future.get(game.getAITimeout(), TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||||
try {
|
|
||||||
t.stop();
|
|
||||||
} catch (UnsupportedOperationException ex) {
|
|
||||||
// Android and Java 20 dropped support to stop so sadly thread will keep running
|
|
||||||
future.cancel(true);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1764,9 +1803,9 @@ public class AiController {
|
|||||||
|
|
||||||
for (int i = 0; i < numToExile; i++) {
|
for (int i = 0; i < numToExile; i++) {
|
||||||
Card chosen = null;
|
Card chosen = null;
|
||||||
for (final Card c : grave) {
|
for (final Card c : grave) { // Exile noncreatures first in
|
||||||
// Exile noncreatures first in case we can revive
|
// case we can revive. Might wanna do some additional
|
||||||
// Might wanna do some additional checking here for Flashback and the like
|
// checking here for Flashback and the like.
|
||||||
if (!c.isCreature()) {
|
if (!c.isCreature()) {
|
||||||
chosen = c;
|
chosen = c;
|
||||||
break;
|
break;
|
||||||
@@ -1787,12 +1826,12 @@ public class AiController {
|
|||||||
return toExile;
|
return toExile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doTrigger(SpellAbility sa, boolean mandatory) {
|
public boolean doTrigger(SpellAbility spell, boolean mandatory) {
|
||||||
if (sa instanceof WrappedAbility)
|
if (spell instanceof WrappedAbility)
|
||||||
return doTrigger(((WrappedAbility) sa).getWrappedAbility(), mandatory);
|
return doTrigger(((WrappedAbility) spell).getWrappedAbility(), mandatory);
|
||||||
if (sa.getApi() != null)
|
if (spell.getApi() != null)
|
||||||
return SpellApiToAi.Converter.get(sa).doTrigger(player, sa, mandatory);
|
return SpellApiToAi.Converter.get(spell).doTriggerAI(player, spell, mandatory);
|
||||||
if (sa.getPayCosts() == Cost.Zero && !sa.usesTargeting()) {
|
if (spell.getPayCosts() == Cost.Zero && !spell.usesTargeting()) {
|
||||||
// For non-converted triggers (such as Cumulative Upkeep) that don't have costs or targets to worry about
|
// For non-converted triggers (such as Cumulative Upkeep) that don't have costs or targets to worry about
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2329,7 +2368,7 @@ public class AiController {
|
|||||||
|
|
||||||
// TODO move to more common place
|
// TODO move to more common place
|
||||||
public static <T extends TriggerReplacementBase> List<T> filterList(List<T> input, Function<SpellAbility, Object> pred, Object value) {
|
public static <T extends TriggerReplacementBase> List<T> filterList(List<T> input, Function<SpellAbility, Object> pred, Object value) {
|
||||||
return filterList(input, trb -> trb.ensureAbility() != null && pred.apply(trb.ensureAbility()) == value);
|
return filterList(input, trb -> pred.apply(trb.ensureAbility()) == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SpellAbility> filterListByApi(List<SpellAbility> input, ApiType type) {
|
public static List<SpellAbility> filterListByApi(List<SpellAbility> input, ApiType type) {
|
||||||
|
|||||||
@@ -46,14 +46,6 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
|||||||
return PaymentDecision.number(c);
|
return PaymentDecision.number(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PaymentDecision visit(CostBehold cost) {
|
|
||||||
final String type = cost.getType();
|
|
||||||
CardCollectionView hand = player.getCardsIn(cost.getRevealFrom());
|
|
||||||
hand = CardLists.getValidCards(hand, type.split(";"), player, source, ability);
|
|
||||||
return hand.isEmpty() ? null : PaymentDecision.card(getBestCreatureAI(hand));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaymentDecision visit(CostChooseColor cost) {
|
public PaymentDecision visit(CostChooseColor cost) {
|
||||||
int c = cost.getAbilityAmount(ability);
|
int c = cost.getAbilityAmount(ability);
|
||||||
@@ -767,12 +759,6 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
|||||||
public PaymentDecision visit(CostRemoveCounter cost) {
|
public PaymentDecision visit(CostRemoveCounter cost) {
|
||||||
final String amount = cost.getAmount();
|
final String amount = cost.getAmount();
|
||||||
final String type = cost.getType();
|
final String type = cost.getType();
|
||||||
final GameEntityCounterTable counterTable = new GameEntityCounterTable();
|
|
||||||
|
|
||||||
// TODO Help AI filter card with most useless counters and put those counters in countertable for things like
|
|
||||||
// Moxite Refinery, similar to CostRemoveAnyCounter
|
|
||||||
// Probably a lot of that decision making can be re-used or pulled out for both PaymentDecisions to use
|
|
||||||
if (cost.counter == null) return null;
|
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -801,8 +787,7 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
|||||||
}
|
}
|
||||||
for (Card card : typeList) {
|
for (Card card : typeList) {
|
||||||
if (card.getCounters(cost.counter) >= c) {
|
if (card.getCounters(cost.counter) >= c) {
|
||||||
counterTable.put(null, card, cost.counter, c);
|
return PaymentDecision.card(card, c);
|
||||||
return PaymentDecision.counters(counterTable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -813,8 +798,7 @@ public class AiCostDecision extends CostDecisionMakerBase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
counterTable.put(null, source, cost.counter, c);
|
return PaymentDecision.card(source, c);
|
||||||
return PaymentDecision.counters(counterTable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,52 +1,21 @@
|
|||||||
package forge.ai;
|
package forge.ai;
|
||||||
|
|
||||||
public enum AiPlayDecision {
|
public enum AiPlayDecision {
|
||||||
// Play decision reasons
|
|
||||||
WillPlay,
|
WillPlay,
|
||||||
MandatoryPlay,
|
|
||||||
PlayToEmptyHand,
|
|
||||||
ImpactCombat,
|
|
||||||
ResponseToStackResolve,
|
|
||||||
AddBoardPresence,
|
|
||||||
Removal,
|
|
||||||
Tempo,
|
|
||||||
CardAdvantage,
|
|
||||||
|
|
||||||
// Play later decisions
|
|
||||||
WaitForCombat,
|
|
||||||
WaitForMain2,
|
|
||||||
WaitForEndOfTurn,
|
|
||||||
StackNotEmpty,
|
|
||||||
AnotherTime,
|
|
||||||
|
|
||||||
// Don't play decision reasons
|
|
||||||
CantPlaySa,
|
CantPlaySa,
|
||||||
CantPlayAi,
|
CantPlayAi,
|
||||||
CantAfford,
|
CantAfford,
|
||||||
CantAffordX,
|
CantAffordX,
|
||||||
DoesntImpactCombat,
|
WaitForMain2,
|
||||||
DoesntImpactGame,
|
AnotherTime,
|
||||||
MissingLogic,
|
|
||||||
MissingNeededCards,
|
MissingNeededCards,
|
||||||
TimingRestrictions,
|
|
||||||
MissingPhaseRestrictions,
|
|
||||||
ConditionsNotMet,
|
|
||||||
NeedsToPlayCriteriaNotMet,
|
NeedsToPlayCriteriaNotMet,
|
||||||
StopRunawayActivations,
|
|
||||||
TargetingFailed,
|
TargetingFailed,
|
||||||
CostNotAcceptable,
|
CostNotAcceptable,
|
||||||
LifeInDanger,
|
|
||||||
WouldDestroyLegend,
|
WouldDestroyLegend,
|
||||||
WouldDestroyOtherPlaneswalker,
|
WouldDestroyOtherPlaneswalker,
|
||||||
WouldBecomeZeroToughnessCreature,
|
WouldBecomeZeroToughnessCreature,
|
||||||
WouldDestroyWorldEnchantment,
|
WouldDestroyWorldEnchantment,
|
||||||
BadEtbEffects,
|
BadEtbEffects,
|
||||||
CurseEffects;
|
CurseEffects
|
||||||
|
|
||||||
public boolean willingToPlay() {
|
|
||||||
return switch (this) {
|
|
||||||
case WillPlay, MandatoryPlay, PlayToEmptyHand, AddBoardPresence, ImpactCombat, ResponseToStackResolve, Removal, Tempo, CardAdvantage -> true;
|
|
||||||
default -> false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,6 @@ import forge.game.spellability.SpellAbility;
|
|||||||
import forge.game.spellability.SpellAbilityStackInstance;
|
import forge.game.spellability.SpellAbilityStackInstance;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
import forge.game.staticability.StaticAbilityMode;
|
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
import forge.game.trigger.WrappedAbility;
|
import forge.game.trigger.WrappedAbility;
|
||||||
@@ -864,7 +863,7 @@ public class ComputerUtil {
|
|||||||
|
|
||||||
// Run non-mandatory trigger.
|
// Run non-mandatory trigger.
|
||||||
// These checks only work if the Executing SpellAbility is an Ability_Sub.
|
// These checks only work if the Executing SpellAbility is an Ability_Sub.
|
||||||
if ((exSA instanceof AbilitySub) && !SpellApiToAi.Converter.get(exSA).doTrigger(ai, exSA, false)) {
|
if ((exSA instanceof AbilitySub) && !SpellApiToAi.Converter.get(exSA).doTriggerAI(ai, exSA, false)) {
|
||||||
// AI would not run this trigger if given the chance
|
// AI would not run this trigger if given the chance
|
||||||
return sacrificed;
|
return sacrificed;
|
||||||
}
|
}
|
||||||
@@ -1074,80 +1073,6 @@ public class ComputerUtil {
|
|||||||
return prevented;
|
return prevented;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Is it OK to cast this for less than the Max Targets?
|
|
||||||
* @param source the source Card
|
|
||||||
* @return true if it's OK to cast this Card for less than the max targets
|
|
||||||
*/
|
|
||||||
public static boolean shouldCastLessThanMax(final Player ai, final Card source) {
|
|
||||||
if (source.getXManaCostPaid() > 0) {
|
|
||||||
// If TargetMax is MaxTgts (i.e., an "X" cost), this is fine because AI is limited by payment resources available.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (aiLifeInDanger(ai, false, 0)) {
|
|
||||||
// Otherwise, if life is possibly in danger, then this is fine.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// do not play now.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this discard probably worse than a random draw?
|
|
||||||
* @param discard Card to discard
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public static boolean isWorseThanDraw(final Player ai, Card discard) {
|
|
||||||
if (discard.hasSVar("DiscardMe")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Game game = ai.getGame();
|
|
||||||
final CardCollection landsInPlay = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.LANDS_PRODUCING_MANA);
|
|
||||||
final CardCollection landsInHand = CardLists.filter(ai.getCardsIn(ZoneType.Hand), CardPredicates.LANDS);
|
|
||||||
final CardCollection nonLandsInHand = CardLists.getNotType(ai.getCardsIn(ZoneType.Hand), "Land");
|
|
||||||
final int highestCMC = Math.max(6, Aggregates.max(nonLandsInHand, Card::getCMC));
|
|
||||||
final int discardCMC = discard.getCMC();
|
|
||||||
if (discard.isLand()) {
|
|
||||||
if (landsInPlay.size() >= highestCMC
|
|
||||||
|| (landsInPlay.size() + landsInHand.size() > 6 && landsInHand.size() > 1)
|
|
||||||
|| (landsInPlay.size() > 3 && nonLandsInHand.size() == 0)) {
|
|
||||||
// Don't need more land.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else { //non-land
|
|
||||||
if (discardCMC > landsInPlay.size() + landsInHand.size() + 2) {
|
|
||||||
// not castable for some time.
|
|
||||||
return true;
|
|
||||||
} else if (!game.getPhaseHandler().isPlayerTurn(ai)
|
|
||||||
&& game.getPhaseHandler().getPhase().isAfter(PhaseType.MAIN2)
|
|
||||||
&& discardCMC > landsInPlay.size() + landsInHand.size()
|
|
||||||
&& discardCMC > landsInPlay.size() + 1
|
|
||||||
&& nonLandsInHand.size() > 1) {
|
|
||||||
// not castable for at least one other turn.
|
|
||||||
return true;
|
|
||||||
} else if (landsInPlay.size() > 5 && discard.getCMC() <= 1
|
|
||||||
&& !discard.hasProperty("hasXCost", ai, null, null)) {
|
|
||||||
// Probably don't need small stuff now.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns true if it's better to wait until blockers are declared
|
|
||||||
public static boolean waitForBlocking(final SpellAbility sa) {
|
|
||||||
final Game game = sa.getActivatingPlayer().getGame();
|
|
||||||
final PhaseHandler ph = game.getPhaseHandler();
|
|
||||||
|
|
||||||
return sa.getHostCard().isCreature()
|
|
||||||
&& sa.getPayCosts().hasTapCost()
|
|
||||||
&& (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
|
||||||
&& !ph.getNextTurn().equals(sa.getActivatingPlayer()))
|
|
||||||
&& !sa.getHostCard().hasSVar("EndOfTurnLeavePlay")
|
|
||||||
&& !sa.hasParam("ActivationPhases");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean castPermanentInMain1(final Player ai, final SpellAbility sa) {
|
public static boolean castPermanentInMain1(final Player ai, final SpellAbility sa) {
|
||||||
final Card card = sa.getHostCard();
|
final Card card = sa.getHostCard();
|
||||||
final CardState cardState = card.isFaceDown() ? card.getState(CardStateName.Original) : card.getCurrentState();
|
final CardState cardState = card.isFaceDown() ? card.getState(CardStateName.Original) : card.getCurrentState();
|
||||||
@@ -1174,11 +1099,6 @@ public class ComputerUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if AI has no speed, play start your engines on Main1
|
|
||||||
if (ai.noSpeed() && cardState.hasKeyword(Keyword.START_YOUR_ENGINES)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cast Blitz in main 1 if the creature attacks
|
// cast Blitz in main 1 if the creature attacks
|
||||||
if (sa.isBlitz() && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, card)) {
|
if (sa.isBlitz() && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, card)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1319,6 +1239,80 @@ public class ComputerUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is it OK to cast this for less than the Max Targets?
|
||||||
|
* @param source the source Card
|
||||||
|
* @return true if it's OK to cast this Card for less than the max targets
|
||||||
|
*/
|
||||||
|
public static boolean shouldCastLessThanMax(final Player ai, final Card source) {
|
||||||
|
if (source.getXManaCostPaid() > 0) {
|
||||||
|
// If TargetMax is MaxTgts (i.e., an "X" cost), this is fine because AI is limited by payment resources available.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (aiLifeInDanger(ai, false, 0)) {
|
||||||
|
// Otherwise, if life is possibly in danger, then this is fine.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// do not play now.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this discard probably worse than a random draw?
|
||||||
|
* @param discard Card to discard
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static boolean isWorseThanDraw(final Player ai, Card discard) {
|
||||||
|
if (discard.hasSVar("DiscardMe")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Game game = ai.getGame();
|
||||||
|
final CardCollection landsInPlay = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.LANDS_PRODUCING_MANA);
|
||||||
|
final CardCollection landsInHand = CardLists.filter(ai.getCardsIn(ZoneType.Hand), CardPredicates.LANDS);
|
||||||
|
final CardCollection nonLandsInHand = CardLists.getNotType(ai.getCardsIn(ZoneType.Hand), "Land");
|
||||||
|
final int highestCMC = Math.max(6, Aggregates.max(nonLandsInHand, Card::getCMC));
|
||||||
|
final int discardCMC = discard.getCMC();
|
||||||
|
if (discard.isLand()) {
|
||||||
|
if (landsInPlay.size() >= highestCMC
|
||||||
|
|| (landsInPlay.size() + landsInHand.size() > 6 && landsInHand.size() > 1)
|
||||||
|
|| (landsInPlay.size() > 3 && nonLandsInHand.size() == 0)) {
|
||||||
|
// Don't need more land.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else { //non-land
|
||||||
|
if (discardCMC > landsInPlay.size() + landsInHand.size() + 2) {
|
||||||
|
// not castable for some time.
|
||||||
|
return true;
|
||||||
|
} else if (!game.getPhaseHandler().isPlayerTurn(ai)
|
||||||
|
&& game.getPhaseHandler().getPhase().isAfter(PhaseType.MAIN2)
|
||||||
|
&& discardCMC > landsInPlay.size() + landsInHand.size()
|
||||||
|
&& discardCMC > landsInPlay.size() + 1
|
||||||
|
&& nonLandsInHand.size() > 1) {
|
||||||
|
// not castable for at least one other turn.
|
||||||
|
return true;
|
||||||
|
} else if (landsInPlay.size() > 5 && discard.getCMC() <= 1
|
||||||
|
&& !discard.hasProperty("hasXCost", ai, null, null)) {
|
||||||
|
// Probably don't need small stuff now.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if it's better to wait until blockers are declared
|
||||||
|
public static boolean waitForBlocking(final SpellAbility sa) {
|
||||||
|
final Game game = sa.getActivatingPlayer().getGame();
|
||||||
|
final PhaseHandler ph = game.getPhaseHandler();
|
||||||
|
|
||||||
|
return sa.getHostCard().isCreature()
|
||||||
|
&& sa.getPayCosts().hasTapCost()
|
||||||
|
&& (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
||||||
|
&& !ph.getNextTurn().equals(sa.getActivatingPlayer()))
|
||||||
|
&& !sa.getHostCard().hasSVar("EndOfTurnLeavePlay")
|
||||||
|
&& !sa.hasParam("ActivationPhases");
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean castSpellInMain1(final Player ai, final SpellAbility sa) {
|
public static boolean castSpellInMain1(final Player ai, final SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final SpellAbility sub = sa.getSubAbility();
|
final SpellAbility sub = sa.getSubAbility();
|
||||||
@@ -1327,6 +1321,7 @@ public class ComputerUtil {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cipher spells
|
||||||
if (sub != null) {
|
if (sub != null) {
|
||||||
final ApiType api = sub.getApi();
|
final ApiType api = sub.getApi();
|
||||||
if (ApiType.Encode == api && !ai.getCreaturesInPlay().isEmpty()) {
|
if (ApiType.Encode == api && !ai.getCreaturesInPlay().isEmpty()) {
|
||||||
@@ -1384,14 +1379,13 @@ public class ComputerUtil {
|
|||||||
|
|
||||||
// returns true if the AI should stop using the ability
|
// returns true if the AI should stop using the ability
|
||||||
public static boolean preventRunAwayActivations(final SpellAbility sa) {
|
public static boolean preventRunAwayActivations(final SpellAbility sa) {
|
||||||
if (!sa.isActivatedAbility()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int activations = sa.getActivationsThisTurn();
|
int activations = sa.getActivationsThisTurn();
|
||||||
|
|
||||||
//10 activations should still be acceptable
|
if (!sa.isIntrinsic()) {
|
||||||
if (activations < 10) {
|
return MyRandom.getRandom().nextFloat() >= .95; // Abilities created by static abilities have no memory
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activations < 10) { //10 activations per turn should still be acceptable
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1459,14 +1453,15 @@ public class ComputerUtil {
|
|||||||
// check for Continuous abilities that grant Haste
|
// check for Continuous abilities that grant Haste
|
||||||
for (final Card c : all) {
|
for (final Card c : all) {
|
||||||
for (StaticAbility stAb : c.getStaticAbilities()) {
|
for (StaticAbility stAb : c.getStaticAbilities()) {
|
||||||
if (stAb.checkMode(StaticAbilityMode.Continuous) && stAb.hasParam("AddKeyword")
|
Map<String, String> params = stAb.getMapParams();
|
||||||
&& stAb.getParam("AddKeyword").contains("Haste")) {
|
if ("Continuous".equals(params.get("Mode")) && params.containsKey("AddKeyword")
|
||||||
|
&& params.get("AddKeyword").contains("Haste")) {
|
||||||
|
|
||||||
if (c.isEquipment() && c.getEquipping() == null) {
|
if (c.isEquipment() && c.getEquipping() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String affected = stAb.getParam("Affected");
|
final String affected = params.get("Affected");
|
||||||
if (affected.contains("Creature.YouCtrl")
|
if (affected.contains("Creature.YouCtrl")
|
||||||
|| affected.contains("Other+YouCtrl")) {
|
|| affected.contains("Other+YouCtrl")) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1519,10 +1514,11 @@ public class ComputerUtil {
|
|||||||
|
|
||||||
for (final Card c : opp) {
|
for (final Card c : opp) {
|
||||||
for (StaticAbility stAb : c.getStaticAbilities()) {
|
for (StaticAbility stAb : c.getStaticAbilities()) {
|
||||||
if (stAb.checkMode(StaticAbilityMode.Continuous) && stAb.hasParam("AddKeyword")
|
Map<String, String> params = stAb.getMapParams();
|
||||||
&& stAb.getParam("AddKeyword").contains("Haste")) {
|
if ("Continuous".equals(params.get("Mode")) && params.containsKey("AddKeyword")
|
||||||
|
&& params.get("AddKeyword").contains("Haste")) {
|
||||||
|
|
||||||
final ArrayList<String> affected = Lists.newArrayList(stAb.getParam("Affected").split(","));
|
final ArrayList<String> affected = Lists.newArrayList(params.get("Affected").split(","));
|
||||||
if (affected.contains("Creature")) {
|
if (affected.contains("Creature")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1621,6 +1617,7 @@ public class ComputerUtil {
|
|||||||
damage = dmg;
|
damage = dmg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Triggered abilities
|
||||||
if (c.isCreature() && c.isInPlay() && CombatUtil.canAttack(c)) {
|
if (c.isCreature() && c.isInPlay() && CombatUtil.canAttack(c)) {
|
||||||
for (final Trigger t : c.getTriggers()) {
|
for (final Trigger t : c.getTriggers()) {
|
||||||
if (TriggerType.Attacks.equals(t.getMode())) {
|
if (TriggerType.Attacks.equals(t.getMode())) {
|
||||||
@@ -2427,7 +2424,7 @@ public class ComputerUtil {
|
|||||||
// Are we picking a type to reduce costs for that type?
|
// Are we picking a type to reduce costs for that type?
|
||||||
boolean reducingCost = false;
|
boolean reducingCost = false;
|
||||||
for (StaticAbility s : sa.getHostCard().getStaticAbilities()) {
|
for (StaticAbility s : sa.getHostCard().getStaticAbilities()) {
|
||||||
if (s.checkMode(StaticAbilityMode.ReduceCost) && "Card.ChosenType".equals(s.getParam("ValidCard"))) {
|
if ("ReduceCost".equals(s.getParam("Mode")) && "Card.ChosenType".equals(s.getParam("ValidCard"))) {
|
||||||
reducingCost = true;
|
reducingCost = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2551,7 +2548,7 @@ public class ComputerUtil {
|
|||||||
String logic = sa.getParam("AILogic");
|
String logic = sa.getParam("AILogic");
|
||||||
switch (logic) {
|
switch (logic) {
|
||||||
case "Torture":
|
case "Torture":
|
||||||
return options.get(1);
|
return "Torture";
|
||||||
case "GraceOrCondemnation":
|
case "GraceOrCondemnation":
|
||||||
List<ZoneType> graceZones = new ArrayList<ZoneType>();
|
List<ZoneType> graceZones = new ArrayList<ZoneType>();
|
||||||
graceZones.add(ZoneType.Battlefield);
|
graceZones.add(ZoneType.Battlefield);
|
||||||
@@ -2559,12 +2556,12 @@ public class ComputerUtil {
|
|||||||
CardCollection graceCreatures = CardLists.getType(game.getCardsIn(graceZones), "Creature");
|
CardCollection graceCreatures = CardLists.getType(game.getCardsIn(graceZones), "Creature");
|
||||||
int humanGrace = CardLists.filterControlledBy(graceCreatures, ai.getOpponents()).size();
|
int humanGrace = CardLists.filterControlledBy(graceCreatures, ai.getOpponents()).size();
|
||||||
int aiGrace = CardLists.filterControlledBy(graceCreatures, ai).size();
|
int aiGrace = CardLists.filterControlledBy(graceCreatures, ai).size();
|
||||||
return options.get(aiGrace > humanGrace ? 0 : 1);
|
return aiGrace > humanGrace ? "Grace" : "Condemnation";
|
||||||
case "CarnageOrHomage":
|
case "CarnageOrHomage":
|
||||||
CardCollection cardsInPlay = CardLists.getNotType(game.getCardsIn(ZoneType.Battlefield), "Land");
|
CardCollection cardsInPlay = CardLists.getNotType(game.getCardsIn(ZoneType.Battlefield), "Land");
|
||||||
CardCollection humanlist = CardLists.filterControlledBy(cardsInPlay, ai.getOpponents());
|
CardCollection humanlist = CardLists.filterControlledBy(cardsInPlay, ai.getOpponents());
|
||||||
CardCollection computerlist = ai.getCreaturesInPlay();
|
CardCollection computerlist = ai.getCreaturesInPlay();
|
||||||
return options.get(ComputerUtilCard.evaluatePermanentList(computerlist) + 3 < ComputerUtilCard.evaluatePermanentList(humanlist) ? 0 : 1);
|
return ComputerUtilCard.evaluatePermanentList(computerlist) + 3 < ComputerUtilCard.evaluatePermanentList(humanlist) ? "Carnage" : "Homage";
|
||||||
case "Judgment":
|
case "Judgment":
|
||||||
if (votes.isEmpty()) {
|
if (votes.isEmpty()) {
|
||||||
CardCollection list = new CardCollection();
|
CardCollection list = new CardCollection();
|
||||||
@@ -2578,71 +2575,68 @@ public class ComputerUtil {
|
|||||||
return Iterables.getFirst(votes.keySet(), null);
|
return Iterables.getFirst(votes.keySet(), null);
|
||||||
case "Protection":
|
case "Protection":
|
||||||
if (votes.isEmpty()) {
|
if (votes.isEmpty()) {
|
||||||
Map<String, SpellAbility> restrictedToColors = Maps.newHashMap();
|
List<String> restrictedToColors = Lists.newArrayList();
|
||||||
for (Object o : options) {
|
for (Object o : options) {
|
||||||
if (o instanceof SpellAbility sp) { // TODO check for Color Word Changes
|
if (o instanceof String) {
|
||||||
restrictedToColors.put(sp.getOriginalDescription(), sp);
|
restrictedToColors.add((String) o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
CardCollection lists = CardLists.filterControlledBy(game.getCardsInGame(), ai.getOpponents());
|
CardCollection lists = CardLists.filterControlledBy(game.getCardsInGame(), ai.getOpponents());
|
||||||
return restrictedToColors.get(StringUtils.capitalize(ComputerUtilCard.getMostProminentColor(lists, restrictedToColors.keySet())));
|
return StringUtils.capitalize(ComputerUtilCard.getMostProminentColor(lists, restrictedToColors));
|
||||||
}
|
}
|
||||||
return Iterables.getFirst(votes.keySet(), null);
|
return Iterables.getFirst(votes.keySet(), null);
|
||||||
case "FeatherOrQuill":
|
case "FeatherOrQuill":
|
||||||
SpellAbility feather = (SpellAbility)options.get(0);
|
|
||||||
SpellAbility quill = (SpellAbility)options.get(1);
|
|
||||||
// try to mill opponent with Quill vote
|
// try to mill opponent with Quill vote
|
||||||
if (opponent && !controller.cantLoseCheck(GameLossReason.Milled)) {
|
if (opponent && !controller.cantLoseCheck(GameLossReason.Milled)) {
|
||||||
int numQuill = votes.get(quill).size();
|
int numQuill = votes.get("Quill").size();
|
||||||
if (numQuill + 1 >= controller.getCardsIn(ZoneType.Library).size()) {
|
if (numQuill + 1 >= controller.getCardsIn(ZoneType.Library).size()) {
|
||||||
return controller.isCardInPlay("Laboratory Maniac") ? feather : quill;
|
return controller.isCardInPlay("Laboratory Maniac") ? "Feather" : "Quill";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// is it can't receive counters, choose +1/+1 ones
|
// is it can't receive counters, choose +1/+1 ones
|
||||||
if (!source.canReceiveCounters(p1p1Type)) {
|
if (!source.canReceiveCounters(p1p1Type)) {
|
||||||
return opponent ? feather : quill;
|
return opponent ? "Feather" : "Quill";
|
||||||
}
|
}
|
||||||
// if source is not on the battlefield anymore, choose +1/+1 ones
|
// if source is not on the battlefield anymore, choose +1/+1 ones
|
||||||
if (!game.getCardState(source).isInPlay()) {
|
if (!game.getCardState(source).isInPlay()) {
|
||||||
return opponent ? feather : quill;
|
return opponent ? "Feather" : "Quill";
|
||||||
}
|
}
|
||||||
// if no hand cards, try to mill opponent
|
// if no hand cards, try to mill opponent
|
||||||
if (controller.getCardsIn(ZoneType.Hand).isEmpty()) {
|
if (controller.getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||||
return opponent ? quill : feather;
|
return opponent ? "Quill" : "Feather";
|
||||||
}
|
}
|
||||||
|
|
||||||
// AI has something to discard
|
// AI has something to discard
|
||||||
if (ai.equals(controller)) {
|
if (ai.equals(controller)) {
|
||||||
CardCollectionView aiCardsInHand = ai.getCardsIn(ZoneType.Hand);
|
CardCollectionView aiCardsInHand = ai.getCardsIn(ZoneType.Hand);
|
||||||
if (CardLists.count(aiCardsInHand, CardPredicates.hasSVar("DiscardMe")) >= 1) {
|
if (CardLists.count(aiCardsInHand, CardPredicates.hasSVar("DiscardMe")) >= 1) {
|
||||||
return quill;
|
return "Quill";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// default card draw and discard are better than +1/+1 counter
|
// default card draw and discard are better than +1/+1 counter
|
||||||
return opponent ? feather : quill;
|
return opponent ? "Feather" : "Quill";
|
||||||
case "StrengthOrNumbers":
|
case "StrengthOrNumbers":
|
||||||
SpellAbility strength = (SpellAbility)options.get(0);
|
|
||||||
SpellAbility numbers = (SpellAbility)options.get(1);
|
|
||||||
// similar to fabricate choose +1/+1 or Token
|
// similar to fabricate choose +1/+1 or Token
|
||||||
int numStrength = votes.get(strength).size();
|
final SpellAbility saToken = sa.findSubAbilityByType(ApiType.Token);
|
||||||
int numNumbers = votes.get(numbers).size();
|
int numStrength = votes.get("Strength").size();
|
||||||
|
int numNumbers = votes.get("Numbers").size();
|
||||||
|
|
||||||
Card token = TokenAi.spawnToken(controller, numbers);
|
Card token = TokenAi.spawnToken(controller, saToken);
|
||||||
|
|
||||||
// is it can't receive counters, choose +1/+1 ones
|
// is it can't receive counters, choose +1/+1 ones
|
||||||
if (!source.canReceiveCounters(p1p1Type)) {
|
if (!source.canReceiveCounters(p1p1Type)) {
|
||||||
return opponent ? strength : numbers;
|
return opponent ? "Strength" : "Numbers";
|
||||||
}
|
}
|
||||||
|
|
||||||
// if source is not on the battlefield anymore
|
// if source is not on the battlefield anymore
|
||||||
if (!game.getCardState(source).isInPlay()) {
|
if (!game.getCardState(source).isInPlay()) {
|
||||||
return opponent ? strength : numbers;
|
return opponent ? "Strength" : "Numbers";
|
||||||
}
|
}
|
||||||
|
|
||||||
// token would not survive
|
// token would not survive
|
||||||
if (token == null || !token.isCreature() || token.getNetToughness() < 1) {
|
if (token == null || !token.isCreature() || token.getNetToughness() < 1) {
|
||||||
return opponent ? numbers : strength;
|
return opponent ? "Numbers" : "Strength";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check for ETB to +1/+1 counters or over another trigger like lifegain
|
// TODO check for ETB to +1/+1 counters or over another trigger like lifegain
|
||||||
@@ -2663,40 +2657,35 @@ public class ComputerUtil {
|
|||||||
int scoreStrength = ComputerUtilCard.evaluateCreature(sourceStrength) + tokenScore * numNumbers;
|
int scoreStrength = ComputerUtilCard.evaluateCreature(sourceStrength) + tokenScore * numNumbers;
|
||||||
int scoreNumbers = ComputerUtilCard.evaluateCreature(sourceNumbers) + tokenScore * (numNumbers + 1);
|
int scoreNumbers = ComputerUtilCard.evaluateCreature(sourceNumbers) + tokenScore * (numNumbers + 1);
|
||||||
|
|
||||||
return (scoreNumbers >= scoreStrength) != opponent ? numbers : strength;
|
return (scoreNumbers >= scoreStrength) != opponent ? "Numbers" : "Strength";
|
||||||
case "SproutOrHarvest":
|
case "SproutOrHarvest":
|
||||||
SpellAbility sprout = (SpellAbility)options.get(0);
|
|
||||||
SpellAbility harvest = (SpellAbility)options.get(1);
|
|
||||||
// lifegain would hurt or has no effect
|
// lifegain would hurt or has no effect
|
||||||
if (opponent) {
|
if (opponent) {
|
||||||
if (lifegainNegative(controller, source)) {
|
if (lifegainNegative(controller, source)) {
|
||||||
return harvest;
|
return "Harvest";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (lifegainNegative(controller, source)) {
|
if (lifegainNegative(controller, source)) {
|
||||||
return sprout;
|
return "Sprout";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// is it can't receive counters, choose +1/+1 ones
|
// is it can't receive counters, choose +1/+1 ones
|
||||||
if (!source.canReceiveCounters(p1p1Type)) {
|
if (!source.canReceiveCounters(p1p1Type)) {
|
||||||
return opponent ? sprout : harvest;
|
return opponent ? "Sprout" : "Harvest";
|
||||||
}
|
}
|
||||||
|
|
||||||
// if source is not on the battlefield anymore
|
// if source is not on the battlefield anymore
|
||||||
if (!game.getCardState(source).isInPlay()) {
|
if (!game.getCardState(source).isInPlay()) {
|
||||||
return opponent ? sprout : harvest;
|
return opponent ? "Sprout" : "Harvest";
|
||||||
}
|
}
|
||||||
// TODO add Lifegain to +1/+1 counters trigger
|
// TODO add Lifegain to +1/+1 counters trigger
|
||||||
|
|
||||||
// for now +1/+1 counters are better
|
// for now +1/+1 counters are better
|
||||||
return opponent ? harvest : sprout;
|
return opponent ? "Harvest" : "Sprout";
|
||||||
case "DeathOrTaxes":
|
case "DeathOrTaxes":
|
||||||
SpellAbility death = (SpellAbility)options.get(0);
|
int numDeath = votes.get("Death").size();
|
||||||
SpellAbility taxes = (SpellAbility)options.get(1);
|
int numTaxes = votes.get("Taxes").size();
|
||||||
|
|
||||||
int numDeath = votes.get(death).size();
|
|
||||||
int numTaxes = votes.get(taxes).size();
|
|
||||||
|
|
||||||
if (opponent) {
|
if (opponent) {
|
||||||
CardCollection aiCreatures = ai.getCreaturesInPlay();
|
CardCollection aiCreatures = ai.getCreaturesInPlay();
|
||||||
@@ -2704,29 +2693,29 @@ public class ComputerUtil {
|
|||||||
// would need to sacrifice more creatures than AI has
|
// would need to sacrifice more creatures than AI has
|
||||||
// sacrifice even more
|
// sacrifice even more
|
||||||
if (aiCreatures.size() <= numDeath) {
|
if (aiCreatures.size() <= numDeath) {
|
||||||
return death;
|
return "Death";
|
||||||
}
|
}
|
||||||
// would need to discard more cards than it has
|
// would need to discard more cards than it has
|
||||||
if (aiCardsInHand.size() <= numTaxes) {
|
if (aiCardsInHand.size() <= numTaxes) {
|
||||||
return taxes;
|
return "Taxes";
|
||||||
}
|
}
|
||||||
|
|
||||||
// has cards with SacMe or Token
|
// has cards with SacMe or Token
|
||||||
if (CardLists.count(aiCreatures, CardPredicates.hasSVar("SacMe").or(CardPredicates.TOKEN)) >= numDeath) {
|
if (CardLists.count(aiCreatures, CardPredicates.hasSVar("SacMe").or(CardPredicates.TOKEN)) >= numDeath) {
|
||||||
return death;
|
return "Death";
|
||||||
}
|
}
|
||||||
|
|
||||||
// has cards with DiscardMe
|
// has cards with DiscardMe
|
||||||
if (CardLists.count(aiCardsInHand, CardPredicates.hasSVar("DiscardMe")) >= numTaxes) {
|
if (CardLists.count(aiCardsInHand, CardPredicates.hasSVar("DiscardMe")) >= numTaxes) {
|
||||||
return taxes;
|
return "Taxes";
|
||||||
}
|
}
|
||||||
|
|
||||||
// discard is probably less worse than sacrifice
|
// discard is probably less worse than sacrifice
|
||||||
return taxes;
|
return "Taxes";
|
||||||
} else {
|
} else {
|
||||||
// ai is first voter or ally of controller
|
// ai is first voter or ally of controller
|
||||||
// both are not affected, but if opponents control creatures, sacrifice is worse
|
// both are not affected, but if opponents control creatures, sacrifice is worse
|
||||||
return controller.getOpponents().getCreaturesInPlay().isEmpty() ? taxes : death;
|
return controller.getOpponents().getCreaturesInPlay().isEmpty() ? "Taxes" : "Death";
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return Iterables.getFirst(options, null);
|
return Iterables.getFirst(options, null);
|
||||||
@@ -2897,7 +2886,7 @@ public class ComputerUtil {
|
|||||||
// Iceberg does use Ice as Storage
|
// Iceberg does use Ice as Storage
|
||||||
|| (type.is(CounterEnumType.ICE) && !"Iceberg".equals(c.getName()))
|
|| (type.is(CounterEnumType.ICE) && !"Iceberg".equals(c.getName()))
|
||||||
// some lands does use Depletion as Storage Counter
|
// some lands does use Depletion as Storage Counter
|
||||||
|| (type.is(CounterEnumType.DEPLETION) && c.getReplacementEffects().anyMatch(r -> r.getMode().equals(ReplacementType.Untap) && r.getLayer().equals(ReplacementLayer.CantHappen)))
|
|| (type.is(CounterEnumType.DEPLETION) && c.hasKeyword("CARDNAME doesn't untap during your untap step."))
|
||||||
// treat Time Counters on suspended Cards as Bad,
|
// treat Time Counters on suspended Cards as Bad,
|
||||||
// and also on Chronozoa
|
// and also on Chronozoa
|
||||||
|| (type.is(CounterEnumType.TIME) && (!c.isInPlay() || "Chronozoa".equals(c.getName())))
|
|| (type.is(CounterEnumType.TIME) && (!c.isInPlay() || "Chronozoa".equals(c.getName())))
|
||||||
|
|||||||
@@ -345,10 +345,6 @@ public class ComputerUtilAbility {
|
|||||||
if (source.hasSVar("AIPriorityModifier")) {
|
if (source.hasSVar("AIPriorityModifier")) {
|
||||||
p += Integer.parseInt(source.getSVar("AIPriorityModifier"));
|
p += Integer.parseInt(source.getSVar("AIPriorityModifier"));
|
||||||
}
|
}
|
||||||
// try to use it before it's gone
|
|
||||||
if (source.isInPlay() && source.hasSVar("EndOfTurnLeavePlay")) {
|
|
||||||
p += 1;
|
|
||||||
}
|
|
||||||
if (ComputerUtilCard.isCardRemAIDeck(sa.getOriginalHost() != null ? sa.getOriginalHost() : source)) {
|
if (ComputerUtilCard.isCardRemAIDeck(sa.getOriginalHost() != null ? sa.getOriginalHost() : source)) {
|
||||||
p -= 10;
|
p -= 10;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import forge.game.replacement.ReplacementEffect;
|
|||||||
import forge.game.replacement.ReplacementLayer;
|
import forge.game.replacement.ReplacementLayer;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
import forge.game.staticability.StaticAbilityMode;
|
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.zone.MagicStack;
|
import forge.game.zone.MagicStack;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
@@ -692,8 +691,6 @@ public class ComputerUtilCard {
|
|||||||
public static boolean canBeBlockedProfitably(final Player ai, Card attacker, boolean checkingOther) {
|
public static boolean canBeBlockedProfitably(final Player ai, Card attacker, boolean checkingOther) {
|
||||||
AiBlockController aiBlk = new AiBlockController(ai, checkingOther);
|
AiBlockController aiBlk = new AiBlockController(ai, checkingOther);
|
||||||
Combat combat = new Combat(ai);
|
Combat combat = new Combat(ai);
|
||||||
// avoid removing original attacker
|
|
||||||
attacker.setCombatLKI(null);
|
|
||||||
combat.addAttacker(attacker, ai);
|
combat.addAttacker(attacker, ai);
|
||||||
final List<Card> attackers = Lists.newArrayList(attacker);
|
final List<Card> attackers = Lists.newArrayList(attacker);
|
||||||
aiBlk.assignBlockersGivenAttackers(combat, attackers);
|
aiBlk.assignBlockersGivenAttackers(combat, attackers);
|
||||||
@@ -919,14 +916,14 @@ public class ComputerUtilCard {
|
|||||||
return MagicColor.Constant.WHITE; // no difference, there was no prominent color
|
return MagicColor.Constant.WHITE; // no difference, there was no prominent color
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMostProminentColor(final CardCollectionView list, final Iterable<String> restrictedToColors) {
|
public static String getMostProminentColor(final CardCollectionView list, final List<String> restrictedToColors) {
|
||||||
byte colors = CardFactoryUtil.getMostProminentColorsFromList(list, restrictedToColors);
|
byte colors = CardFactoryUtil.getMostProminentColorsFromList(list, restrictedToColors);
|
||||||
for (byte c : MagicColor.WUBRG) {
|
for (byte c : MagicColor.WUBRG) {
|
||||||
if ((colors & c) != 0) {
|
if ((colors & c) != 0) {
|
||||||
return MagicColor.toLongString(c);
|
return MagicColor.toLongString(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Iterables.get(restrictedToColors, 0); // no difference, there was no prominent color
|
return restrictedToColors.get(0); // no difference, there was no prominent color
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getColorByProminence(final List<Card> list) {
|
public static List<String> getColorByProminence(final List<Card> list) {
|
||||||
@@ -1214,7 +1211,8 @@ public class ComputerUtilCard {
|
|||||||
// if this thing is both owned and controlled by an opponent and it has a continuous ability,
|
// if this thing is both owned and controlled by an opponent and it has a continuous ability,
|
||||||
// assume it either benefits the player or disrupts the opponent
|
// assume it either benefits the player or disrupts the opponent
|
||||||
for (final StaticAbility stAb : c.getStaticAbilities()) {
|
for (final StaticAbility stAb : c.getStaticAbilities()) {
|
||||||
if (stAb.checkMode(StaticAbilityMode.Continuous) && stAb.isIntrinsic()) {
|
final Map<String, String> params = stAb.getMapParams();
|
||||||
|
if (params.get("Mode").equals("Continuous") && stAb.isIntrinsic()) {
|
||||||
priority = true;
|
priority = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1245,16 +1243,17 @@ public class ComputerUtilCard {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (final StaticAbility stAb : c.getStaticAbilities()) {
|
for (final StaticAbility stAb : c.getStaticAbilities()) {
|
||||||
|
final Map<String, String> params = stAb.getMapParams();
|
||||||
//continuous buffs
|
//continuous buffs
|
||||||
if (stAb.checkMode(StaticAbilityMode.Continuous) && "Creature.YouCtrl".equals(stAb.getParam("Affected"))) {
|
if (params.get("Mode").equals("Continuous") && "Creature.YouCtrl".equals(params.get("Affected"))) {
|
||||||
int bonusPT = 0;
|
int bonusPT = 0;
|
||||||
if (stAb.hasParam("AddPower")) {
|
if (params.containsKey("AddPower")) {
|
||||||
bonusPT += AbilityUtils.calculateAmount(c, stAb.getParam("AddPower"), stAb);
|
bonusPT += AbilityUtils.calculateAmount(c, params.get("AddPower"), stAb);
|
||||||
}
|
}
|
||||||
if (stAb.hasParam("AddToughness")) {
|
if (params.containsKey("AddToughness")) {
|
||||||
bonusPT += AbilityUtils.calculateAmount(c, stAb.getParam("AddPower"), stAb);
|
bonusPT += AbilityUtils.calculateAmount(c, params.get("AddPower"), stAb);
|
||||||
}
|
}
|
||||||
String kws = stAb.getParam("AddKeyword");
|
String kws = params.get("AddKeyword");
|
||||||
if (kws != null) {
|
if (kws != null) {
|
||||||
bonusPT += 4 * (1 + StringUtils.countMatches(kws, "&")); //treat each added keyword as a +2/+2 for now
|
bonusPT += 4 * (1 + StringUtils.countMatches(kws, "&")); //treat each added keyword as a +2/+2 for now
|
||||||
}
|
}
|
||||||
@@ -1785,7 +1784,7 @@ public class ComputerUtilCard {
|
|||||||
// remove old boost that might be copied
|
// remove old boost that might be copied
|
||||||
for (final StaticAbility stAb : c.getStaticAbilities()) {
|
for (final StaticAbility stAb : c.getStaticAbilities()) {
|
||||||
vCard.removePTBoost(c.getLayerTimestamp(), stAb.getId());
|
vCard.removePTBoost(c.getLayerTimestamp(), stAb.getId());
|
||||||
if (!stAb.checkMode(StaticAbilityMode.Continuous)) {
|
if (!stAb.checkMode("Continuous")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!stAb.hasParam("Affected")) {
|
if (!stAb.hasParam("Affected")) {
|
||||||
@@ -1819,18 +1818,18 @@ public class ComputerUtilCard {
|
|||||||
* @param sa Pump* or CounterPut*
|
* @param sa Pump* or CounterPut*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static AiAbilityDecision canPumpAgainstRemoval(Player ai, SpellAbility sa) {
|
public static boolean canPumpAgainstRemoval(Player ai, SpellAbility sa) {
|
||||||
final List<GameObject> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa, true);
|
final List<GameObject> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa, true);
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
final List<Card> cards = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa);
|
final List<Card> cards = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa);
|
||||||
for (final Card card : cards) {
|
for (final Card card : cards) {
|
||||||
if (objects.contains(card)) {
|
if (objects.contains(card)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ResponseToStackResolve);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For pumps without targeting restrictions, just return immediately until this is fleshed out.
|
// For pumps without targeting restrictions, just return immediately until this is fleshed out.
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection threatenedTargets = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
CardCollection threatenedTargets = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
@@ -1849,11 +1848,11 @@ public class ComputerUtilCard {
|
|||||||
}
|
}
|
||||||
if (!sa.isTargetNumberValid()) {
|
if (!sa.isTargetNumberValid()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ResponseToStackResolve);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUselessCreature(Player ai, Card c) {
|
public static boolean isUselessCreature(Player ai, Card c) {
|
||||||
@@ -1863,7 +1862,7 @@ public class ComputerUtilCard {
|
|||||||
if (!c.isCreature()) {
|
if (!c.isCreature()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (c.hasKeyword("CARDNAME can't attack or block.") || (c.isTapped() && !c.canUntap(ai, true)) || (c.getOwner() == ai && ai.getOpponents().contains(c.getController()))) {
|
if (c.hasKeyword("CARDNAME can't attack or block.") || (c.hasKeyword("CARDNAME doesn't untap during your untap step.") && c.isTapped()) || (c.getOwner() == ai && ai.getOpponents().contains(c.getController()))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import forge.game.combat.Combat;
|
|||||||
import forge.game.combat.CombatUtil;
|
import forge.game.combat.CombatUtil;
|
||||||
import forge.game.cost.CostPayment;
|
import forge.game.cost.CostPayment;
|
||||||
import forge.game.keyword.Keyword;
|
import forge.game.keyword.Keyword;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.Untap;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.replacement.ReplacementEffect;
|
import forge.game.replacement.ReplacementEffect;
|
||||||
import forge.game.replacement.ReplacementLayer;
|
import forge.game.replacement.ReplacementLayer;
|
||||||
@@ -39,7 +39,6 @@ import forge.game.replacement.ReplacementType;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
import forge.game.staticability.StaticAbilityAssignCombatDamageAsUnblocked;
|
import forge.game.staticability.StaticAbilityAssignCombatDamageAsUnblocked;
|
||||||
import forge.game.staticability.StaticAbilityMode;
|
|
||||||
import forge.game.staticability.StaticAbilityMustAttack;
|
import forge.game.staticability.StaticAbilityMustAttack;
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
@@ -102,7 +101,7 @@ public class ComputerUtilCombat {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attacker.getGame().getReplacementHandler().wouldPhaseBeSkipped(attacker.getController(), PhaseType.COMBAT_BEGIN)) {
|
if (attacker.getGame().getReplacementHandler().wouldPhaseBeSkipped(attacker.getController(), "BeginCombat")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +118,7 @@ public class ComputerUtilCombat {
|
|||||||
// || (attacker.hasKeyword(Keyword.FADING) && attacker.getCounters(CounterEnumType.FADE) == 0)
|
// || (attacker.hasKeyword(Keyword.FADING) && attacker.getCounters(CounterEnumType.FADE) == 0)
|
||||||
// || attacker.hasSVar("EndOfTurnLeavePlay"));
|
// || attacker.hasSVar("EndOfTurnLeavePlay"));
|
||||||
// The creature won't untap next turn
|
// The creature won't untap next turn
|
||||||
return !attacker.isTapped() || (attacker.getCounters(CounterEnumType.STUN) == 0 && attacker.canUntap(attacker.getController(), true));
|
return !attacker.isTapped() || (attacker.getCounters(CounterEnumType.STUN) == 0 && Untap.canUntap(attacker));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,7 +214,7 @@ public class ComputerUtilCombat {
|
|||||||
int damage = attacker.getNetCombatDamage();
|
int damage = attacker.getNetCombatDamage();
|
||||||
int poison = 0;
|
int poison = 0;
|
||||||
damage += predictPowerBonusOfAttacker(attacker, null, null, false);
|
damage += predictPowerBonusOfAttacker(attacker, null, null, false);
|
||||||
if (attacker.isInfectDamage(attacked)) {
|
if (attacker.hasKeyword(Keyword.INFECT)) {
|
||||||
int pd = predictDamageTo(attacked, damage, attacker, true);
|
int pd = predictDamageTo(attacked, damage, attacker, true);
|
||||||
// opponent can always order it so that he gets 0
|
// opponent can always order it so that he gets 0
|
||||||
if (pd == 1 && attacker.getController().getOpponents().getCardsIn(ZoneType.Battlefield).anyMatch(CardPredicates.nameEquals("Vorinclex, Monstrous Raider"))) {
|
if (pd == 1 && attacker.getController().getOpponents().getCardsIn(ZoneType.Battlefield).anyMatch(CardPredicates.nameEquals("Vorinclex, Monstrous Raider"))) {
|
||||||
@@ -358,7 +357,7 @@ public class ComputerUtilCombat {
|
|||||||
} else if (attacker.hasKeyword(Keyword.TRAMPLE)) {
|
} else if (attacker.hasKeyword(Keyword.TRAMPLE)) {
|
||||||
int trampleDamage = getAttack(attacker) - totalShieldDamage(attacker, blockers);
|
int trampleDamage = getAttack(attacker) - totalShieldDamage(attacker, blockers);
|
||||||
if (trampleDamage > 0) {
|
if (trampleDamage > 0) {
|
||||||
if (attacker.isInfectDamage(ai)) {
|
if (attacker.hasKeyword(Keyword.INFECT)) {
|
||||||
poison += trampleDamage;
|
poison += trampleDamage;
|
||||||
}
|
}
|
||||||
poison += predictExtraPoisonWithDamage(attacker, ai, trampleDamage);
|
poison += predictExtraPoisonWithDamage(attacker, ai, trampleDamage);
|
||||||
@@ -901,7 +900,7 @@ public class ComputerUtilCombat {
|
|||||||
final CardCollectionView cardList = CardCollection.combine(game.getCardsIn(ZoneType.Battlefield), game.getCardsIn(ZoneType.Command));
|
final CardCollectionView cardList = CardCollection.combine(game.getCardsIn(ZoneType.Battlefield), game.getCardsIn(ZoneType.Command));
|
||||||
for (final Card card : cardList) {
|
for (final Card card : cardList) {
|
||||||
for (final StaticAbility stAb : card.getStaticAbilities()) {
|
for (final StaticAbility stAb : card.getStaticAbilities()) {
|
||||||
if (!stAb.checkMode(StaticAbilityMode.Continuous)) {
|
if (!stAb.checkMode("Continuous")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!stAb.hasParam("Affected") || !stAb.getParam("Affected").contains("blocking")) {
|
if (!stAb.hasParam("Affected") || !stAb.getParam("Affected").contains("blocking")) {
|
||||||
@@ -1197,7 +1196,7 @@ public class ComputerUtilCombat {
|
|||||||
final CardCollectionView cardList = CardCollection.combine(game.getCardsIn(ZoneType.Battlefield), game.getCardsIn(ZoneType.Command));
|
final CardCollectionView cardList = CardCollection.combine(game.getCardsIn(ZoneType.Battlefield), game.getCardsIn(ZoneType.Command));
|
||||||
for (final Card card : cardList) {
|
for (final Card card : cardList) {
|
||||||
for (final StaticAbility stAb : card.getStaticAbilities()) {
|
for (final StaticAbility stAb : card.getStaticAbilities()) {
|
||||||
if (!stAb.checkMode(StaticAbilityMode.Continuous)) {
|
if (!stAb.checkMode("Continuous")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!stAb.hasParam("Affected") || !stAb.getParam("Affected").contains("attacking")) {
|
if (!stAb.hasParam("Affected") || !stAb.getParam("Affected").contains("attacking")) {
|
||||||
@@ -1388,7 +1387,7 @@ public class ComputerUtilCombat {
|
|||||||
final CardCollectionView cardList = game.getCardsIn(ZoneType.Battlefield);
|
final CardCollectionView cardList = game.getCardsIn(ZoneType.Battlefield);
|
||||||
for (final Card card : cardList) {
|
for (final Card card : cardList) {
|
||||||
for (final StaticAbility stAb : card.getStaticAbilities()) {
|
for (final StaticAbility stAb : card.getStaticAbilities()) {
|
||||||
if (!stAb.checkMode(StaticAbilityMode.Continuous)) {
|
if (!"Continuous".equals(stAb.getParam("Mode"))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!stAb.hasParam("Affected")) {
|
if (!stAb.hasParam("Affected")) {
|
||||||
@@ -1735,7 +1734,6 @@ public class ComputerUtilCombat {
|
|||||||
final int attackerLife = getDamageToKill(attacker, false)
|
final int attackerLife = getDamageToKill(attacker, false)
|
||||||
+ predictToughnessBonusOfAttacker(attacker, blocker, combat, withoutAbilities, withoutAttackerStaticAbilities);
|
+ predictToughnessBonusOfAttacker(attacker, blocker, combat, withoutAbilities, withoutAttackerStaticAbilities);
|
||||||
|
|
||||||
// AI should be less worried about Deathtouch
|
|
||||||
if (blocker.hasDoubleStrike()) {
|
if (blocker.hasDoubleStrike()) {
|
||||||
if (defenderDamage > 0 && (hasKeyword(blocker, "Deathtouch", withoutAbilities, combat) || attacker.hasSVar("DestroyWhenDamaged"))) {
|
if (defenderDamage > 0 && (hasKeyword(blocker, "Deathtouch", withoutAbilities, combat) || attacker.hasSVar("DestroyWhenDamaged"))) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1965,7 +1963,6 @@ public class ComputerUtilCombat {
|
|||||||
final int attackerLife = getDamageToKill(attacker, false)
|
final int attackerLife = getDamageToKill(attacker, false)
|
||||||
+ predictToughnessBonusOfAttacker(attacker, blocker, combat, withoutAbilities, withoutAttackerStaticAbilities);
|
+ predictToughnessBonusOfAttacker(attacker, blocker, combat, withoutAbilities, withoutAttackerStaticAbilities);
|
||||||
|
|
||||||
// AI should be less worried about deathtouch
|
|
||||||
if (attacker.hasDoubleStrike()) {
|
if (attacker.hasDoubleStrike()) {
|
||||||
if (attackerDamage >= defenderLife) {
|
if (attackerDamage >= defenderLife) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import forge.game.GameObject;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -140,13 +139,11 @@ public class ComputerUtilCost {
|
|||||||
if (type.equals("CARDNAME")) {
|
if (type.equals("CARDNAME")) {
|
||||||
if (source.getAbilityText().contains("Bloodrush")) {
|
if (source.getAbilityText().contains("Bloodrush")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if (ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN, ai)
|
||||||
if (ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN, ai)
|
|
||||||
&& !ai.isUnlimitedHandSize() && ai.getCardsIn(ZoneType.Hand).size() > ai.getMaxHandSize()) {
|
&& !ai.isUnlimitedHandSize() && ai.getCardsIn(ZoneType.Hand).size() > ai.getMaxHandSize()) {
|
||||||
// Better do something than just discard stuff
|
// Better do something than just discard stuff
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
typeList = CardLists.getValidCards(hand, type, source.getController(), source, sa);
|
typeList = CardLists.getValidCards(hand, type, source.getController(), source, sa);
|
||||||
if (typeList.size() > ai.getMaxHandSize()) {
|
if (typeList.size() > ai.getMaxHandSize()) {
|
||||||
@@ -251,7 +248,11 @@ public class ComputerUtilCost {
|
|||||||
// Does the AI want to use Sacrifice All?
|
// Does the AI want to use Sacrifice All?
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
int c = part.getAbilityAmount(sourceAbility);
|
Integer c = part.convertAmount();
|
||||||
|
|
||||||
|
if (c == null) {
|
||||||
|
c = part.getAbilityAmount(sourceAbility);
|
||||||
|
}
|
||||||
final AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
final AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||||
CardCollectionView choices = aic.chooseSacrificeType(part.getType(), sourceAbility, effect, c, exclude);
|
CardCollectionView choices = aic.chooseSacrificeType(part.getType(), sourceAbility, effect, c, exclude);
|
||||||
if (choices != null) {
|
if (choices != null) {
|
||||||
@@ -521,12 +522,13 @@ public class ComputerUtilCost {
|
|||||||
sa.setActivatingPlayer(player); // complaints on NPE had came before this line was added.
|
sa.setActivatingPlayer(player); // complaints on NPE had came before this line was added.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean cannotBeCountered = false;
|
||||||
|
|
||||||
// Check for stuff like Nether Void
|
// Check for stuff like Nether Void
|
||||||
int extraManaNeeded = 0;
|
int extraManaNeeded = 0;
|
||||||
if (!effect) {
|
if (!effect) {
|
||||||
boolean cannotBeCountered = !sa.isCounterableBy(null);
|
|
||||||
|
|
||||||
if (sa instanceof Spell) {
|
if (sa instanceof Spell) {
|
||||||
|
cannotBeCountered = !sa.isCounterableBy(null);
|
||||||
for (Card c : player.getGame().getCardsIn(ZoneType.Battlefield)) {
|
for (Card c : player.getGame().getCardsIn(ZoneType.Battlefield)) {
|
||||||
final String snem = c.getSVar("AI_SpellsNeedExtraMana");
|
final String snem = c.getSVar("AI_SpellsNeedExtraMana");
|
||||||
if (!StringUtils.isBlank(snem)) {
|
if (!StringUtils.isBlank(snem)) {
|
||||||
@@ -576,24 +578,12 @@ public class ComputerUtilCost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Account for possible Ward after the spell is fully targeted
|
// Ward - will be accounted for when rechecking a targeted ability
|
||||||
// TODO: ideally, this should be done while targeting, so that a different target can be preferred if the best
|
if (!sa.isTrigger() && (!sa.isSpell() || !cannotBeCountered)) {
|
||||||
// one is warded and can't be paid for. (currently it will be stuck with the target until it could pay)
|
|
||||||
if (!sa.isTrigger() && !cannotBeCountered) {
|
|
||||||
Set<GameObject> distinctObjects = Sets.newHashSet();
|
|
||||||
for (TargetChoices tc : sa.getAllTargetChoices()) {
|
for (TargetChoices tc : sa.getAllTargetChoices()) {
|
||||||
for (Card tgt : tc.getTargetCards()) {
|
for (Card tgt : tc.getTargetCards()) {
|
||||||
if (!distinctObjects.add(tgt)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// TODO some older cards don't use the keyword, so check for trigger instead
|
|
||||||
if (tgt.hasKeyword(Keyword.WARD) && tgt.isInPlay() && tgt.getController().isOpponentOf(sa.getHostCard().getController())) {
|
if (tgt.hasKeyword(Keyword.WARD) && tgt.isInPlay() && tgt.getController().isOpponentOf(sa.getHostCard().getController())) {
|
||||||
Cost wardCost = ComputerUtilCard.getTotalWardCost(tgt);
|
Cost wardCost = ComputerUtilCard.getTotalWardCost(tgt);
|
||||||
// don't use API converter since it might have special part logic not meant for Ward cost
|
|
||||||
SpellAbilityAi topAI = new SpellAbilityAi() {};
|
|
||||||
if (!topAI.willPayCosts(player, sa, wardCost, sa.getHostCard())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (wardCost.hasManaCost()) {
|
if (wardCost.hasManaCost()) {
|
||||||
extraManaNeeded += wardCost.getTotalMana().getCMC();
|
extraManaNeeded += wardCost.getTotalMana().getCMC();
|
||||||
}
|
}
|
||||||
@@ -617,9 +607,8 @@ public class ComputerUtilCost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO both of these call CostAdjustment.adjust, try to reuse instead
|
|
||||||
return ComputerUtilMana.canPayManaCost(cost, sa, player, extraManaNeeded, effect)
|
return ComputerUtilMana.canPayManaCost(cost, sa, player, extraManaNeeded, effect)
|
||||||
&& CostPayment.canPayAdditionalCosts(cost, sa, effect, player);
|
&& CostPayment.canPayAdditionalCosts(cost, sa, effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getAvailableManaColors(Player ai, Card additionalLand) {
|
public static Set<String> getAvailableManaColors(Player ai, Card additionalLand) {
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ public class ComputerUtilMana {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mana abilities on the same card
|
// Mana abilities on the same card
|
||||||
String shardMana = shard.toShortString();
|
String shardMana = shard.toString().replaceAll("\\{", "").replaceAll("\\}", "");
|
||||||
|
|
||||||
boolean payWithAb1 = ability1.getManaPart().mana(ability1).contains(shardMana);
|
boolean payWithAb1 = ability1.getManaPart().mana(ability1).contains(shardMana);
|
||||||
boolean payWithAb2 = ability2.getManaPart().mana(ability2).contains(shardMana);
|
boolean payWithAb2 = ability2.getManaPart().mana(ability2).contains(shardMana);
|
||||||
@@ -226,7 +226,7 @@ public class ComputerUtilMana {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SpellAbility chooseManaAbility(ManaCostBeingPaid cost, SpellAbility sa, Player ai, ManaCostShard toPay,
|
public static SpellAbility chooseManaAbility(ManaCostBeingPaid cost, SpellAbility sa, Player ai, ManaCostShard toPay,
|
||||||
Collection<SpellAbility> maList, boolean checkCosts) {
|
Collection<SpellAbility> saList, boolean checkCosts) {
|
||||||
Card saHost = sa.getHostCard();
|
Card saHost = sa.getHostCard();
|
||||||
|
|
||||||
// CastTotalManaSpent (AIPreference:ManaFrom$Type or AIManaPref$ Type)
|
// CastTotalManaSpent (AIPreference:ManaFrom$Type or AIManaPref$ Type)
|
||||||
@@ -240,12 +240,12 @@ public class ComputerUtilMana {
|
|||||||
manaSourceType = sa.getParam("AIManaPref");
|
manaSourceType = sa.getParam("AIManaPref");
|
||||||
}
|
}
|
||||||
if (manaSourceType != "") {
|
if (manaSourceType != "") {
|
||||||
List<SpellAbility> filteredList = Lists.newArrayList(maList);
|
List<SpellAbility> filteredList = Lists.newArrayList(saList);
|
||||||
switch (manaSourceType) {
|
switch (manaSourceType) {
|
||||||
case "Snow":
|
case "Snow":
|
||||||
filteredList.sort((ab1, ab2) -> ab1.getHostCard() != null && ab1.getHostCard().isSnow()
|
filteredList.sort((ab1, ab2) -> ab1.getHostCard() != null && ab1.getHostCard().isSnow()
|
||||||
&& ab2.getHostCard() != null && !ab2.getHostCard().isSnow() ? -1 : 1);
|
&& ab2.getHostCard() != null && !ab2.getHostCard().isSnow() ? -1 : 1);
|
||||||
maList = filteredList;
|
saList = filteredList;
|
||||||
break;
|
break;
|
||||||
case "Treasure":
|
case "Treasure":
|
||||||
// Try to spend only one Treasure if possible
|
// Try to spend only one Treasure if possible
|
||||||
@@ -253,22 +253,22 @@ public class ComputerUtilMana {
|
|||||||
&& ab2.getHostCard() != null && !ab2.getHostCard().getType().hasSubtype("Treasure") ? -1 : 1);
|
&& ab2.getHostCard() != null && !ab2.getHostCard().getType().hasSubtype("Treasure") ? -1 : 1);
|
||||||
SpellAbility first = filteredList.get(0);
|
SpellAbility first = filteredList.get(0);
|
||||||
if (first.getHostCard() != null && first.getHostCard().getType().hasSubtype("Treasure")) {
|
if (first.getHostCard() != null && first.getHostCard().getType().hasSubtype("Treasure")) {
|
||||||
maList.remove(first);
|
saList.remove(first);
|
||||||
List<SpellAbility> updatedList = Lists.newArrayList();
|
List<SpellAbility> updatedList = Lists.newArrayList();
|
||||||
updatedList.add(first);
|
updatedList.add(first);
|
||||||
updatedList.addAll(maList);
|
updatedList.addAll(saList);
|
||||||
maList = updatedList;
|
saList = updatedList;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "TreasureMax":
|
case "TreasureMax":
|
||||||
// Ok to spend as many Treasures as possible
|
// Ok to spend as many Treasures as possible
|
||||||
filteredList.sort((ab1, ab2) -> ab1.getHostCard() != null && ab1.getHostCard().getType().hasSubtype("Treasure")
|
filteredList.sort((ab1, ab2) -> ab1.getHostCard() != null && ab1.getHostCard().getType().hasSubtype("Treasure")
|
||||||
&& ab2.getHostCard() != null && !ab2.getHostCard().getType().hasSubtype("Treasure") ? -1 : 1);
|
&& ab2.getHostCard() != null && !ab2.getHostCard().getType().hasSubtype("Treasure") ? -1 : 1);
|
||||||
maList = filteredList;
|
saList = filteredList;
|
||||||
break;
|
break;
|
||||||
case "NotSameCard":
|
case "NotSameCard":
|
||||||
String hostName = sa.getHostCard().getName();
|
String hostName = sa.getHostCard().getName();
|
||||||
maList = filteredList.stream()
|
saList = filteredList.stream()
|
||||||
.filter(saPay -> !saPay.getHostCard().getName().equals(hostName))
|
.filter(saPay -> !saPay.getHostCard().getName().equals(hostName))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
break;
|
break;
|
||||||
@@ -277,7 +277,7 @@ public class ComputerUtilMana {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final SpellAbility ma : maList) {
|
for (final SpellAbility ma : saList) {
|
||||||
// this rarely seems like a good idea
|
// this rarely seems like a good idea
|
||||||
if (ma.getHostCard() == saHost) {
|
if (ma.getHostCard() == saHost) {
|
||||||
continue;
|
continue;
|
||||||
@@ -336,7 +336,7 @@ public class ComputerUtilMana {
|
|||||||
// Deprioritize Cavern of Souls, try to pay generic mana with it instead to use the NoCounter ability
|
// Deprioritize Cavern of Souls, try to pay generic mana with it instead to use the NoCounter ability
|
||||||
continue;
|
continue;
|
||||||
} else if (toPay == ManaCostShard.GENERIC || toPay == ManaCostShard.X) {
|
} else if (toPay == ManaCostShard.GENERIC || toPay == ManaCostShard.X) {
|
||||||
for (SpellAbility ab : maList) {
|
for (SpellAbility ab : saList) {
|
||||||
if (ab.isManaAbility() && ab.getManaPart().isAnyMana() && ab.hasParam("AddsNoCounter")) {
|
if (ab.isManaAbility() && ab.getManaPart().isAnyMana() && ab.hasParam("AddsNoCounter")) {
|
||||||
if (!ab.getHostCard().isTapped()) {
|
if (!ab.getHostCard().isTapped()) {
|
||||||
paymentChoice = ab;
|
paymentChoice = ab;
|
||||||
@@ -590,12 +590,12 @@ public class ComputerUtilMana {
|
|||||||
while (!cost.isPaid()) {
|
while (!cost.isPaid()) {
|
||||||
toPay = getNextShardToPay(cost, sourcesForShards);
|
toPay = getNextShardToPay(cost, sourcesForShards);
|
||||||
|
|
||||||
Collection<SpellAbility> maList = sourcesForShards.get(toPay);
|
Collection<SpellAbility> saList = sourcesForShards.get(toPay);
|
||||||
if (maList == null) {
|
if (saList == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpellAbility saPayment = chooseManaAbility(cost, sa, ai, toPay, maList, true);
|
SpellAbility saPayment = chooseManaAbility(cost, sa, ai, toPay, saList, true);
|
||||||
if (saPayment == null) {
|
if (saPayment == null) {
|
||||||
boolean lifeInsteadOfBlack = toPay.isBlack() && ai.hasKeyword("PayLifeInsteadOf:B");
|
boolean lifeInsteadOfBlack = toPay.isBlack() && ai.hasKeyword("PayLifeInsteadOf:B");
|
||||||
if ((!toPay.isPhyrexian() && !lifeInsteadOfBlack) || !ai.canPayLife(2, false, sa)) {
|
if ((!toPay.isPhyrexian() && !lifeInsteadOfBlack) || !ai.canPayLife(2, false, sa)) {
|
||||||
@@ -642,31 +642,26 @@ public class ComputerUtilMana {
|
|||||||
List<SpellAbility> paymentList = Lists.newArrayList();
|
List<SpellAbility> paymentList = Lists.newArrayList();
|
||||||
final ManaPool manapool = ai.getManaPool();
|
final ManaPool manapool = ai.getManaPool();
|
||||||
|
|
||||||
// Apply color/type conversion matrix if necessary (already done via autopay)
|
// Apply the color/type conversion matrix if necessary
|
||||||
if (ai.getControllingPlayer() == null) {
|
manapool.restoreColorReplacements();
|
||||||
manapool.restoreColorReplacements();
|
CardPlayOption mayPlay = sa.getMayPlayOption();
|
||||||
CardPlayOption mayPlay = sa.getMayPlayOption();
|
if (!effect) {
|
||||||
if (!effect) {
|
if (sa.isSpell() && mayPlay != null) {
|
||||||
if (sa.isSpell() && mayPlay != null) {
|
mayPlay.applyManaConvert(manapool);
|
||||||
mayPlay.applyManaConvert(manapool);
|
} else if (sa.isActivatedAbility() && sa.getGrantorStatic() != null && sa.getGrantorStatic().hasParam("ManaConversion")) {
|
||||||
} else if (sa.isActivatedAbility() && sa.getGrantorStatic() != null && sa.getGrantorStatic().hasParam("ManaConversion")) {
|
AbilityUtils.applyManaColorConversion(manapool, sa.getGrantorStatic().getParam("ManaConversion"));
|
||||||
AbilityUtils.applyManaColorConversion(manapool, sa.getGrantorStatic().getParam("ManaConversion"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (sa.hasParam("ManaConversion")) {
|
|
||||||
AbilityUtils.applyManaColorConversion(manapool, sa.getParam("ManaConversion"));
|
|
||||||
}
|
|
||||||
StaticAbilityManaConvert.manaConvert(manapool, ai, sa.getHostCard(), effect && !sa.isCastFromPlayEffect() ? null : sa);
|
|
||||||
}
|
}
|
||||||
|
if (sa.hasParam("ManaConversion")) {
|
||||||
|
AbilityUtils.applyManaColorConversion(manapool, sa.getParam("ManaConversion"));
|
||||||
|
}
|
||||||
|
StaticAbilityManaConvert.manaConvert(manapool, ai, sa.getHostCard(), effect && !sa.isCastFromPlayEffect() ? null : sa);
|
||||||
|
|
||||||
// not worth checking if it makes sense to not spend floating first
|
|
||||||
if (manapool.payManaCostFromPool(cost, sa, test, manaSpentToPay)) {
|
if (manapool.payManaCostFromPool(cost, sa, test, manaSpentToPay)) {
|
||||||
CostPayment.handleOfferings(sa, test, cost.isPaid());
|
CostPayment.handleOfferings(sa, test, cost.isPaid());
|
||||||
// paid all from floating mana
|
return true; // paid all from floating mana
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int phyLifeToPay = 2;
|
|
||||||
boolean purePhyrexian = cost.containsOnlyPhyrexianMana();
|
boolean purePhyrexian = cost.containsOnlyPhyrexianMana();
|
||||||
boolean hasConverge = sa.getHostCard().hasConverge();
|
boolean hasConverge = sa.getHostCard().hasConverge();
|
||||||
ListMultimap<ManaCostShard, SpellAbility> sourcesForShards = getSourcesForShards(cost, sa, ai, test, checkPlayable, hasConverge);
|
ListMultimap<ManaCostShard, SpellAbility> sourcesForShards = getSourcesForShards(cost, sa, ai, test, checkPlayable, hasConverge);
|
||||||
@@ -694,12 +689,13 @@ public class ComputerUtilMana {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sourcesForShards == null && !purePhyrexian) {
|
if (sourcesForShards == null && !purePhyrexian) {
|
||||||
// no mana abilities to use for paying
|
break; // no mana abilities to use for paying
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toPay = getNextShardToPay(cost, sourcesForShards);
|
toPay = getNextShardToPay(cost, sourcesForShards);
|
||||||
|
|
||||||
|
boolean lifeInsteadOfBlack = toPay.isBlack() && ai.hasKeyword("PayLifeInsteadOf:B");
|
||||||
|
|
||||||
Collection<SpellAbility> saList = null;
|
Collection<SpellAbility> saList = null;
|
||||||
if (hasConverge &&
|
if (hasConverge &&
|
||||||
(toPay == ManaCostShard.GENERIC || toPay == ManaCostShard.X)) {
|
(toPay == ManaCostShard.GENERIC || toPay == ManaCostShard.X)) {
|
||||||
@@ -752,14 +748,9 @@ public class ComputerUtilMana {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (saPayment == null) {
|
if (saPayment == null) {
|
||||||
boolean lifeInsteadOfBlack = toPay.isBlack() && ai.hasKeyword("PayLifeInsteadOf:B");
|
if ((!toPay.isPhyrexian() && !lifeInsteadOfBlack) || !ai.canPayLife(2, false, sa)
|
||||||
if ((!toPay.isPhyrexian() && !lifeInsteadOfBlack) || !ai.canPayLife(phyLifeToPay, false, sa)
|
|| (ai.getLife() <= 2 && !ai.cantLoseForZeroOrLessLife())) {
|
||||||
|| (ai.getLife() <= phyLifeToPay && !ai.cantLoseForZeroOrLessLife())) {
|
break; // cannot pay
|
||||||
// cannot pay
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (test) {
|
|
||||||
phyLifeToPay += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("AIPhyrexianPayment")) {
|
if (sa.hasParam("AIPhyrexianPayment")) {
|
||||||
@@ -963,6 +954,7 @@ public class ComputerUtilMana {
|
|||||||
if (checkCosts) {
|
if (checkCosts) {
|
||||||
// Check if AI can still play this mana ability
|
// Check if AI can still play this mana ability
|
||||||
ma.setActivatingPlayer(ai);
|
ma.setActivatingPlayer(ai);
|
||||||
|
// if the AI can't pay the additional costs skip the mana ability
|
||||||
if (!CostPayment.canPayAdditionalCosts(ma.getPayCosts(), ma, false)) {
|
if (!CostPayment.canPayAdditionalCosts(ma.getPayCosts(), ma, false)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (ma.getRestrictions() != null && ma.getRestrictions().isInstantSpeed()) {
|
} else if (ma.getRestrictions() != null && ma.getRestrictions().isInstantSpeed()) {
|
||||||
@@ -980,9 +972,8 @@ public class ComputerUtilMana {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Any".equals(s) || ai.getManaPool().canPayForShardWithColor(toPay, ManaAtom.fromName(s))){
|
if ("Any".equals(s) || ai.getManaPool().canPayForShardWithColor(toPay, ManaAtom.fromName(s)))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1508,7 +1499,7 @@ public class ComputerUtilMana {
|
|||||||
AbilitySub sub = m.getSubAbility();
|
AbilitySub sub = m.getSubAbility();
|
||||||
// We really shouldn't be hardcoding names here. ChkDrawback should just return true for them
|
// We really shouldn't be hardcoding names here. ChkDrawback should just return true for them
|
||||||
if (sub != null && !card.getName().equals("Pristine Talisman") && !card.getName().equals("Zhur-Taa Druid")) {
|
if (sub != null && !card.getName().equals("Pristine Talisman") && !card.getName().equals("Zhur-Taa Druid")) {
|
||||||
if (!SpellApiToAi.Converter.get(sub).chkDrawbackWithSubs(ai, sub).willingToPlay()) {
|
if (!SpellApiToAi.Converter.get(sub).chkDrawbackWithSubs(ai, sub)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
needsLimitedResources = true; // TODO: check for good drawbacks (gainLife)
|
needsLimitedResources = true; // TODO: check for good drawbacks (gainLife)
|
||||||
@@ -1588,7 +1579,7 @@ public class ComputerUtilMana {
|
|||||||
// don't use abilities with dangerous drawbacks
|
// don't use abilities with dangerous drawbacks
|
||||||
AbilitySub sub = m.getSubAbility();
|
AbilitySub sub = m.getSubAbility();
|
||||||
if (sub != null) {
|
if (sub != null) {
|
||||||
if (!SpellApiToAi.Converter.get(sub).chkDrawbackWithSubs(ai, sub).willingToPlay()) {
|
if (!SpellApiToAi.Converter.get(sub).chkDrawbackWithSubs(ai, sub)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,12 @@ public class CreatureEvaluator implements Function<Card, Integer> {
|
|||||||
value += addValue(20, "protection");
|
value += addValue(20, "protection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (final SpellAbility sa : c.getSpellAbilities()) {
|
||||||
|
if (sa.isAbility()) {
|
||||||
|
value += addValue(evaluateSpellAbility(sa), "sa: " + sa);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// paired creatures are more valuable because they grant a bonus to the other creature
|
// paired creatures are more valuable because they grant a bonus to the other creature
|
||||||
if (c.isPaired()) {
|
if (c.isPaired()) {
|
||||||
value += addValue(14, "paired");
|
value += addValue(14, "paired");
|
||||||
@@ -207,7 +213,11 @@ public class CreatureEvaluator implements Function<Card, Integer> {
|
|||||||
value += addValue(1, "untapped");
|
value += addValue(1, "untapped");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!c.canUntap(c.getController(), true)) {
|
if (!c.getManaAbilities().isEmpty()) {
|
||||||
|
value += addValue(10, "manadork");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.hasKeyword("CARDNAME doesn't untap during your untap step.")) {
|
||||||
if (c.isTapped()) {
|
if (c.isTapped()) {
|
||||||
value = addValue(50 + (c.getCMC() * 5), "tapped-useless"); // reset everything - useless
|
value = addValue(50 + (c.getCMC() * 5), "tapped-useless"); // reset everything - useless
|
||||||
} else {
|
} else {
|
||||||
@@ -216,17 +226,6 @@ public class CreatureEvaluator implements Function<Card, Integer> {
|
|||||||
} else {
|
} else {
|
||||||
value -= subValue(10 * c.getCounters(CounterEnumType.STUN), "stunned");
|
value -= subValue(10 * c.getCounters(CounterEnumType.STUN), "stunned");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final SpellAbility sa : c.getSpellAbilities()) {
|
|
||||||
if (sa.isAbility()) {
|
|
||||||
value += addValue(evaluateSpellAbility(sa), "sa: " + sa);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!c.getManaAbilities().isEmpty()) {
|
|
||||||
value += addValue(10, "manadork");
|
|
||||||
}
|
|
||||||
|
|
||||||
// use scaling because the creature is only available halfway
|
// use scaling because the creature is only available halfway
|
||||||
if (c.hasKeyword(Keyword.PHASING)) {
|
if (c.hasKeyword(Keyword.PHASING)) {
|
||||||
value -= subValue(Math.max(20, value / 2), "phasing");
|
value -= subValue(Math.max(20, value / 2), "phasing");
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import forge.card.mana.ManaAtom;
|
|||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.GameEntity;
|
import forge.game.GameEntity;
|
||||||
import forge.game.ability.AbilityFactory;
|
import forge.game.ability.AbilityFactory;
|
||||||
import forge.game.ability.ApiType;
|
|
||||||
import forge.game.ability.effects.DetachedCardEffect;
|
import forge.game.ability.effects.DetachedCardEffect;
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
import forge.game.card.token.TokenInfo;
|
import forge.game.card.token.TokenInfo;
|
||||||
@@ -264,14 +263,12 @@ public abstract class GameState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (c.hasMergedCard()) {
|
if (c.hasMergedCard()) {
|
||||||
String suffix = c.getTopMergedCard().hasPaperFoil() ? "+" : "";
|
|
||||||
// we have to go by the current top card name here
|
// we have to go by the current top card name here
|
||||||
newText.append(c.getTopMergedCard().getPaperCard().getName()).append(suffix).append("|Set:")
|
newText.append(c.getTopMergedCard().getPaperCard().getName()).append("|Set:")
|
||||||
.append(c.getTopMergedCard().getPaperCard().getEdition()).append("|Art:")
|
.append(c.getTopMergedCard().getPaperCard().getEdition()).append("|Art:")
|
||||||
.append(c.getTopMergedCard().getPaperCard().getArtIndex());
|
.append(c.getTopMergedCard().getPaperCard().getArtIndex());
|
||||||
} else {
|
} else {
|
||||||
String suffix = c.hasPaperFoil() ? "+" : "";
|
newText.append(c.getPaperCard().getName()).append("|Set:").append(c.getPaperCard().getEdition())
|
||||||
newText.append(c.getPaperCard().getName()).append(suffix).append("|Set:").append(c.getPaperCard().getEdition())
|
|
||||||
.append("|Art:").append(c.getPaperCard().getArtIndex());
|
.append("|Art:").append(c.getPaperCard().getArtIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,21 +318,18 @@ public abstract class GameState {
|
|||||||
newText.append(":Cloaked");
|
newText.append(":Cloaked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c.getCurrentStateName().equals(CardStateName.Flipped)) {
|
if (c.getCurrentStateName().equals(CardStateName.Transformed)) {
|
||||||
|
newText.append("|Transformed");
|
||||||
|
} else if (c.getCurrentStateName().equals(CardStateName.Flipped)) {
|
||||||
newText.append("|Flipped");
|
newText.append("|Flipped");
|
||||||
} else if (c.getCurrentStateName().equals(CardStateName.Meld)) {
|
} else if (c.getCurrentStateName().equals(CardStateName.Meld)) {
|
||||||
newText.append("|Meld");
|
newText.append("|Meld");
|
||||||
if (c.getMeldedWith() != null) {
|
if (c.getMeldedWith() != null) {
|
||||||
String suffix = c.getMeldedWith().hasPaperFoil() ? "+" : "";
|
|
||||||
newText.append(":");
|
newText.append(":");
|
||||||
newText.append(c.getMeldedWith().getName()).append(suffix);
|
newText.append(c.getMeldedWith().getName());
|
||||||
}
|
|
||||||
} else if (c.getCurrentStateName().equals(CardStateName.Backside)) {
|
|
||||||
if (c.isModal()) {
|
|
||||||
newText.append("|Modal");
|
|
||||||
} else {
|
|
||||||
newText.append("|Transformed");
|
|
||||||
}
|
}
|
||||||
|
} else if (c.getCurrentStateName().equals(CardStateName.Modal)) {
|
||||||
|
newText.append("|Modal");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.getPlayerAttachedTo() != null) {
|
if (c.getPlayerAttachedTo() != null) {
|
||||||
@@ -1268,7 +1262,7 @@ public abstract class GameState {
|
|||||||
} else if (cardinfo[0].startsWith("T:")) {
|
} else if (cardinfo[0].startsWith("T:")) {
|
||||||
String tokenStr = cardinfo[0].substring(2);
|
String tokenStr = cardinfo[0].substring(2);
|
||||||
PaperToken token = StaticData.instance().getAllTokens().getToken(tokenStr,
|
PaperToken token = StaticData.instance().getAllTokens().getToken(tokenStr,
|
||||||
setCode != null ? setCode : CardEdition.UNKNOWN_CODE);
|
setCode != null ? setCode : CardEdition.UNKNOWN.getName());
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
System.err.println("ERROR: Tried to create a non-existent token named " + cardinfo[0] + " when loading game state!");
|
System.err.println("ERROR: Tried to create a non-existent token named " + cardinfo[0] + " when loading game state!");
|
||||||
continue;
|
continue;
|
||||||
@@ -1311,13 +1305,13 @@ public abstract class GameState {
|
|||||||
} else if (info.startsWith("FaceDown")) {
|
} else if (info.startsWith("FaceDown")) {
|
||||||
c.turnFaceDown(true);
|
c.turnFaceDown(true);
|
||||||
if (info.endsWith("Manifested")) {
|
if (info.endsWith("Manifested")) {
|
||||||
c.setManifested(new SpellAbility.EmptySa(ApiType.Manifest, c));
|
c.setManifested(true);
|
||||||
}
|
}
|
||||||
if (info.endsWith("Cloaked")) {
|
if (info.endsWith("Cloaked")) {
|
||||||
c.setCloaked(new SpellAbility.EmptySa(ApiType.Cloak, c));
|
c.setCloaked(true);
|
||||||
}
|
}
|
||||||
} else if (info.startsWith("Transformed") || info.startsWith("Modal")) {
|
} else if (info.startsWith("Transformed")) {
|
||||||
c.setState(CardStateName.Backside, true);
|
c.setState(CardStateName.Transformed, true);
|
||||||
c.setBackSide(true);
|
c.setBackSide(true);
|
||||||
} else if (info.startsWith("Flipped")) {
|
} else if (info.startsWith("Flipped")) {
|
||||||
c.setState(CardStateName.Flipped, true);
|
c.setState(CardStateName.Flipped, true);
|
||||||
@@ -1335,6 +1329,9 @@ public abstract class GameState {
|
|||||||
}
|
}
|
||||||
c.setState(CardStateName.Meld, true);
|
c.setState(CardStateName.Meld, true);
|
||||||
c.setBackSide(true);
|
c.setBackSide(true);
|
||||||
|
} else if (info.startsWith("Modal")) {
|
||||||
|
c.setState(CardStateName.Modal, true);
|
||||||
|
c.setBackSide(true);
|
||||||
}
|
}
|
||||||
else if (info.startsWith("OnAdventure")) {
|
else if (info.startsWith("OnAdventure")) {
|
||||||
String abAdventure = "DB$ Effect | RememberObjects$ Self | StaticAbilities$ Play | ForgetOnMoved$ Exile | Duration$ Permanent | ConditionDefined$ Self | ConditionPresent$ Card.!copiedSpell";
|
String abAdventure = "DB$ Effect | RememberObjects$ Self | StaticAbilities$ Play | ForgetOnMoved$ Exile | Duration$ Permanent | ConditionDefined$ Self | ConditionPresent$ Card.!copiedSpell";
|
||||||
@@ -1411,7 +1408,7 @@ public abstract class GameState {
|
|||||||
} else if (info.equals("Foretold")) {
|
} else if (info.equals("Foretold")) {
|
||||||
c.setForetold(true);
|
c.setForetold(true);
|
||||||
c.turnFaceDown(true);
|
c.turnFaceDown(true);
|
||||||
c.addMayLookFaceDownExile(c.getOwner());
|
c.addMayLookTemp(c.getOwner());
|
||||||
} else if (info.equals("ForetoldThisTurn")) {
|
} else if (info.equals("ForetoldThisTurn")) {
|
||||||
c.setTurnInZone(turn);
|
c.setTurnInZone(turn);
|
||||||
} else if (info.equals("IsToken")) {
|
} else if (info.equals("IsToken")) {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import forge.game.*;
|
|||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.ability.ApiType;
|
import forge.game.ability.ApiType;
|
||||||
import forge.game.ability.effects.CharmEffect;
|
import forge.game.ability.effects.CharmEffect;
|
||||||
import forge.game.ability.effects.RollDiceEffect;
|
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
import forge.game.cost.Cost;
|
import forge.game.cost.Cost;
|
||||||
@@ -746,30 +745,6 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
return Aggregates.random(rolls);
|
return Aggregates.random(rolls);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Integer> chooseDiceToReroll(List<Integer> rolls) {
|
|
||||||
//TODO create AI logic for this
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer chooseRollToModify(List<Integer> rolls) {
|
|
||||||
//TODO create AI logic for this
|
|
||||||
return Aggregates.random(rolls);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RollDiceEffect.DieRollResult chooseRollToSwap(List<RollDiceEffect.DieRollResult> rolls) {
|
|
||||||
//TODO create AI logic for this
|
|
||||||
return Aggregates.random(rolls);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String chooseRollSwapValue(List<String> swapChoices, Integer currentResult, int power, int toughness) {
|
|
||||||
//TODO create AI logic for this
|
|
||||||
return Aggregates.random(swapChoices);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mulliganKeepHand(Player firstPlayer, int cardsToReturn) {
|
public boolean mulliganKeepHand(Player firstPlayer, int cardsToReturn) {
|
||||||
return !ComputerUtil.wantMulligan(player, cardsToReturn);
|
return !ComputerUtil.wantMulligan(player, cardsToReturn);
|
||||||
@@ -1232,11 +1207,6 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean payCostDuringRoll(final Cost cost, final SpellAbility sa, final FCollectionView<Player> allPayers) {
|
|
||||||
// TODO logic for AI to pay rerolls and modification costs
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void orderAndPlaySimultaneousSa(List<SpellAbility> activePlayerSAs) {
|
public void orderAndPlaySimultaneousSa(List<SpellAbility> activePlayerSAs) {
|
||||||
for (final SpellAbility sa : getAi().orderPlaySa(activePlayerSAs)) {
|
for (final SpellAbility sa : getAi().orderPlaySa(activePlayerSAs)) {
|
||||||
@@ -1419,11 +1389,11 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
oppLibrary = CardLists.getValidCards(oppLibrary, valid, source.getController(), source, sa);
|
oppLibrary = CardLists.getValidCards(oppLibrary, valid, source.getController(), source, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source != null && source.getState(CardStateName.Original).hasKeyword(Keyword.HIDDEN_AGENDA)) {
|
if (source != null && source.getState(CardStateName.Original).hasIntrinsicKeyword("Hidden agenda")) {
|
||||||
// If any Conspiracies are present, try not to choose the same name twice
|
// If any Conspiracies are present, try not to choose the same name twice
|
||||||
// (otherwise the AI will spam the same name)
|
// (otherwise the AI will spam the same name)
|
||||||
for (Card consp : player.getCardsIn(ZoneType.Command)) {
|
for (Card consp : player.getCardsIn(ZoneType.Command)) {
|
||||||
if (consp.getState(CardStateName.Original).hasKeyword(Keyword.HIDDEN_AGENDA)) {
|
if (consp.getState(CardStateName.Original).hasIntrinsicKeyword("Hidden agenda")) {
|
||||||
String chosenName = consp.getNamedCard();
|
String chosenName = consp.getNamedCard();
|
||||||
if (!chosenName.isEmpty()) {
|
if (!chosenName.isEmpty()) {
|
||||||
aiLibrary = CardLists.filter(aiLibrary, CardPredicates.nameNotEquals(chosenName));
|
aiLibrary = CardLists.filter(aiLibrary, CardPredicates.nameNotEquals(chosenName));
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ public class SpecialAiLogic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A logic for cards that say "Sacrifice a creature: put X +1/+1 counters on CARDNAME" (e.g. Falkenrath Aristocrat)
|
// A logic for cards that say "Sacrifice a creature: put X +1/+1 counters on CARDNAME" (e.g. Falkenrath Aristocrat)
|
||||||
public static AiAbilityDecision doAristocratWithCountersLogic(final Player ai, final SpellAbility sa) {
|
public static boolean doAristocratWithCountersLogic(final Player ai, final SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String logic = sa.getParam("AILogic"); // should not even get here unless there's an Aristocrats logic applied
|
final String logic = sa.getParam("AILogic"); // should not even get here unless there's an Aristocrats logic applied
|
||||||
final boolean isDeclareBlockers = ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS);
|
final boolean isDeclareBlockers = ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS);
|
||||||
@@ -222,14 +222,14 @@ public class SpecialAiLogic {
|
|||||||
final int numOtherCreats = Math.max(0, ai.getCreaturesInPlay().size() - 1);
|
final int numOtherCreats = Math.max(0, ai.getCreaturesInPlay().size() - 1);
|
||||||
if (numOtherCreats == 0) {
|
if (numOtherCreats == 0) {
|
||||||
// Cut short if there's nothing to sac at all
|
// Cut short if there's nothing to sac at all
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the standard Aristocrats logic applies first (if in the right conditions for it)
|
// Check if the standard Aristocrats logic applies first (if in the right conditions for it)
|
||||||
final boolean isThreatened = ComputerUtil.predictThreatenedObjects(ai, null, true).contains(source);
|
final boolean isThreatened = ComputerUtil.predictThreatenedObjects(ai, null, true).contains(source);
|
||||||
if (isDeclareBlockers || isThreatened) {
|
if (isDeclareBlockers || isThreatened) {
|
||||||
if (doAristocratLogic(ai, sa)) {
|
if (doAristocratLogic(ai, sa)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ public class SpecialAiLogic {
|
|||||||
if (countersSa == null) {
|
if (countersSa == null) {
|
||||||
// Shouldn't get here if there is no PutCounter subability (wrong AI logic specified?)
|
// Shouldn't get here if there is no PutCounter subability (wrong AI logic specified?)
|
||||||
System.err.println("Warning: AILogic AristocratCounters was specified on " + source + ", but there was no PutCounter SA in chain!");
|
System.err.println("Warning: AILogic AristocratCounters was specified on " + source + ", but there was no PutCounter SA in chain!");
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
@@ -263,7 +263,7 @@ public class SpecialAiLogic {
|
|||||||
relevantCreats.remove(source);
|
relevantCreats.remove(source);
|
||||||
if (relevantCreats.isEmpty()) {
|
if (relevantCreats.isEmpty()) {
|
||||||
// No relevant creatures to sac
|
// No relevant creatures to sac
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numCtrs = AbilityUtils.calculateAmount(source, countersSa.getParam("CounterNum"), countersSa);
|
int numCtrs = AbilityUtils.calculateAmount(source, countersSa.getParam("CounterNum"), countersSa);
|
||||||
@@ -287,20 +287,16 @@ public class SpecialAiLogic {
|
|||||||
|| (combat.isAttacking(card) && combat.isBlocked(card) && ComputerUtilCombat.combatantWouldBeDestroyed(ai, card, combat))
|
|| (combat.isAttacking(card) && combat.isBlocked(card) && ComputerUtilCombat.combatantWouldBeDestroyed(ai, card, combat))
|
||||||
);
|
);
|
||||||
if (!forcedSacTgts.isEmpty()) {
|
if (!forcedSacTgts.isEmpty()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int numCreatsToSac = Math.max(0, (lethalDmg - source.getNetCombatDamage()) / numCtrs);
|
final int numCreatsToSac = Math.max(0, (lethalDmg - source.getNetCombatDamage()) / numCtrs);
|
||||||
|
|
||||||
if (defTappedOut || numCreatsToSac < relevantCreats.size() / 2) {
|
if (defTappedOut || numCreatsToSac < relevantCreats.size() / 2) {
|
||||||
if (source.getNetCombatDamage() < lethalDmg
|
return source.getNetCombatDamage() < lethalDmg
|
||||||
&& source.getNetCombatDamage() + relevantCreats.size() * numCtrs >= lethalDmg) {
|
&& source.getNetCombatDamage() + relevantCreats.size() * numCtrs >= lethalDmg;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// We have already attacked. Thus, see if we have a creature to sac that is worse to lose
|
// We have already attacked. Thus, see if we have a creature to sac that is worse to lose
|
||||||
@@ -313,7 +309,7 @@ public class SpecialAiLogic {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (sacTgts.isEmpty()) {
|
if (sacTgts.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean sourceCantDie = ComputerUtilCombat.combatantCantBeDestroyed(ai, source);
|
final boolean sourceCantDie = ComputerUtilCombat.combatantCantBeDestroyed(ai, source);
|
||||||
@@ -321,10 +317,7 @@ public class SpecialAiLogic {
|
|||||||
final int DefP = sourceCantDie ? 0 : Aggregates.sum(combat.getBlockers(source), Card::getNetPower);
|
final int DefP = sourceCantDie ? 0 : Aggregates.sum(combat.getBlockers(source), Card::getNetPower);
|
||||||
|
|
||||||
// Make sure we don't over-sacrifice, only sac until we can survive and kill a creature
|
// Make sure we don't over-sacrifice, only sac until we can survive and kill a creature
|
||||||
if (source.getNetToughness() - source.getDamage() <= DefP || source.getNetCombatDamage() < minDefT) {
|
return source.getNetToughness() - source.getDamage() <= DefP || source.getNetCombatDamage() < minDefT;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// We can't deal lethal, check if there's any sac fodder than can be used for other circumstances
|
// We can't deal lethal, check if there's any sac fodder than can be used for other circumstances
|
||||||
@@ -336,11 +329,7 @@ public class SpecialAiLogic {
|
|||||||
|| ComputerUtil.predictThreatenedObjects(ai, null, true).contains(card)
|
|| ComputerUtil.predictThreatenedObjects(ai, null, true).contains(card)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (sacFodder.isEmpty()) {
|
return !sacFodder.isEmpty();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,10 +360,10 @@ public class SpecialAiLogic {
|
|||||||
// FIXME: We're emulating the UnlessCost on the SA to run the proper checks.
|
// FIXME: We're emulating the UnlessCost on the SA to run the proper checks.
|
||||||
// This is hacky, but it works. Perhaps a cleaner way exists?
|
// This is hacky, but it works. Perhaps a cleaner way exists?
|
||||||
sa.getMapParams().put("UnlessCost", falseSub.getParam("UnlessCost"));
|
sa.getMapParams().put("UnlessCost", falseSub.getParam("UnlessCost"));
|
||||||
willPlay = SpellApiToAi.Converter.get(ApiType.Counter).canPlayWithSubs(ai, sa).willingToPlay();
|
willPlay = SpellApiToAi.Converter.get(ApiType.Counter).canPlayAIWithSubs(ai, sa);
|
||||||
sa.getMapParams().remove("UnlessCost");
|
sa.getMapParams().remove("UnlessCost");
|
||||||
} else {
|
} else {
|
||||||
willPlay = SpellApiToAi.Converter.get(ApiType.Counter).canPlayWithSubs(ai, sa).willingToPlay();
|
willPlay = SpellApiToAi.Converter.get(ApiType.Counter).canPlayAIWithSubs(ai, sa);
|
||||||
}
|
}
|
||||||
return willPlay;
|
return willPlay;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,17 +78,16 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Arena and Magus of the Arena
|
// Arena and Magus of the Arena
|
||||||
public static class Arena {
|
public static class Arena {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
|
|
||||||
// TODO This is basically removal, so we may want to play this at other times
|
|
||||||
if (!game.getPhaseHandler().is(PhaseType.END_OF_TURN) || game.getPhaseHandler().getNextTurn() != ai) {
|
if (!game.getPhaseHandler().is(PhaseType.END_OF_TURN) || game.getPhaseHandler().getNextTurn() != ai) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForEndOfTurn);
|
return false; // at opponent's EOT only, to conserve mana
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection aiCreatures = ai.getCreaturesInPlay();
|
CardCollection aiCreatures = ai.getCreaturesInPlay();
|
||||||
if (aiCreatures.isEmpty()) {
|
if (aiCreatures.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Player opp : ai.getOpponents()) {
|
for (Player opp : ai.getOpponents()) {
|
||||||
@@ -112,11 +111,11 @@ public class SpecialCardAi {
|
|||||||
if (canKillAll) {
|
if (canKillAll) {
|
||||||
sa.getTargets().clear();
|
sa.getTargets().clear();
|
||||||
sa.getTargets().add(aiCreature);
|
sa.getTargets().add(aiCreature);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.Removal);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return sa.isTargetNumberValid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +203,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Chain of Acid
|
// Chain of Acid
|
||||||
public static class ChainOfAcid {
|
public static class ChainOfAcid {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
List<Card> AiLandsOnly = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
List<Card> AiLandsOnly = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
||||||
CardPredicates.LANDS);
|
CardPredicates.LANDS);
|
||||||
List<Card> OppPerms = CardLists.filter(ai.getOpponents().getCardsIn(ZoneType.Battlefield),
|
List<Card> OppPerms = CardLists.filter(ai.getOpponents().getCardsIn(ZoneType.Battlefield),
|
||||||
@@ -214,22 +213,13 @@ public class SpecialCardAi {
|
|||||||
// which it can only distinguish by their CMC, considering >CMC higher value).
|
// which it can only distinguish by their CMC, considering >CMC higher value).
|
||||||
// Currently ensures that the AI will still have lands provided that the human player goes to
|
// Currently ensures that the AI will still have lands provided that the human player goes to
|
||||||
// destroy all the AI's lands in order (to avoid manalock).
|
// destroy all the AI's lands in order (to avoid manalock).
|
||||||
if (!OppPerms.isEmpty() && AiLandsOnly.size() > OppPerms.size() + 2) {
|
return !OppPerms.isEmpty() && AiLandsOnly.size() > OppPerms.size() + 2;
|
||||||
// If there are enough lands, target the worst non-creature permanent of the opponent
|
|
||||||
Card worstOppPerm = ComputerUtilCard.getWorstAI(OppPerms);
|
|
||||||
if (worstOppPerm != null) {
|
|
||||||
sa.resetTargets();
|
|
||||||
sa.getTargets().add(worstOppPerm);
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chain of Smog
|
// Chain of Smog
|
||||||
public static class ChainOfSmog {
|
public static class ChainOfSmog {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
if (ai.getCardsIn(ZoneType.Hand).isEmpty()) {
|
if (ai.getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||||
// to avoid failure to add to stack, provide a legal target opponent first (choosing random at this point)
|
// to avoid failure to add to stack, provide a legal target opponent first (choosing random at this point)
|
||||||
// TODO: this makes the AI target opponents with 0 cards in hand, but bailing from here causes a
|
// TODO: this makes the AI target opponents with 0 cards in hand, but bailing from here causes a
|
||||||
@@ -245,10 +235,10 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
sa.getParent().resetTargets();
|
sa.getParent().resetTargets();
|
||||||
sa.getParent().getTargets().add(targOpp);
|
sa.getParent().getTargets().add(targOpp);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,28 +359,18 @@ public class SpecialCardAi {
|
|||||||
private static final int demonSacThreshold = Integer.MAX_VALUE; // if we're in dire conditions, sac everything from worst to best hoping to find an answer
|
private static final int demonSacThreshold = Integer.MAX_VALUE; // if we're in dire conditions, sac everything from worst to best hoping to find an answer
|
||||||
|
|
||||||
public static boolean considerSacrificingCreature(final Player ai, final SpellAbility sa) {
|
public static boolean considerSacrificingCreature(final Player ai, final SpellAbility sa) {
|
||||||
Card c = sa.getHostCard();
|
|
||||||
|
|
||||||
// Only check for sacrifice if it's the owner's turn, and it can attack.
|
|
||||||
// TODO: Maybe check if sacrificing a creature allows AI to kill the opponent with the rest on their turn?
|
|
||||||
if (!CombatUtil.canAttack(c) ||
|
|
||||||
!ai.getGame().getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CardCollection flyingCreatures = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
CardCollection flyingCreatures = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
||||||
CardPredicates.UNTAPPED.and(
|
CardPredicates.UNTAPPED.and(
|
||||||
CardPredicates.hasKeyword(Keyword.FLYING).or(CardPredicates.hasKeyword(Keyword.REACH))));
|
CardPredicates.hasKeyword(Keyword.FLYING).or(CardPredicates.hasKeyword(Keyword.REACH))));
|
||||||
boolean hasUsefulBlocker = false;
|
boolean hasUsefulBlocker = false;
|
||||||
|
|
||||||
for (Card fc : flyingCreatures) {
|
for (Card c : flyingCreatures) {
|
||||||
if (!ComputerUtilCard.isUselessCreature(ai, fc)) {
|
if (!ComputerUtilCard.isUselessCreature(ai, c)) {
|
||||||
hasUsefulBlocker = true;
|
hasUsefulBlocker = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ai.getLife() <= c.getNetPower() && !hasUsefulBlocker;
|
return ai.getLife() <= sa.getHostCard().getNetPower() && !hasUsefulBlocker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSacThreshold() {
|
public static int getSacThreshold() {
|
||||||
@@ -400,7 +380,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Donate
|
// Donate
|
||||||
public static class Donate {
|
public static class Donate {
|
||||||
public static AiAbilityDecision considerTargetingOpponent(final Player ai, final SpellAbility sa) {
|
public static boolean considerTargetingOpponent(final Player ai, final SpellAbility sa) {
|
||||||
final Card donateTarget = ComputerUtil.getCardPreference(ai, sa.getHostCard(), "DonateMe", CardLists.filter(
|
final Card donateTarget = ComputerUtil.getCardPreference(ai, sa.getHostCard(), "DonateMe", CardLists.filter(
|
||||||
ai.getCardsIn(ZoneType.Battlefield).threadSafeIterable(), CardPredicates.hasSVar("DonateMe")));
|
ai.getCardsIn(ZoneType.Battlefield).threadSafeIterable(), CardPredicates.hasSVar("DonateMe")));
|
||||||
if (donateTarget != null) {
|
if (donateTarget != null) {
|
||||||
@@ -410,7 +390,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// All opponents have hexproof or something like that
|
// All opponents have hexproof or something like that
|
||||||
if (Iterables.isEmpty(oppList)) {
|
if (Iterables.isEmpty(oppList)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter for player who does not have donate target already
|
// filter for player who does not have donate target already
|
||||||
@@ -428,30 +408,31 @@ public class SpecialCardAi {
|
|||||||
if (opp != null) {
|
if (opp != null) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
// No targets found to donate, so do nothing.
|
// No targets found to donate, so do nothing.
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AiAbilityDecision considerDonatingPermanent(final Player ai, final SpellAbility sa) {
|
public static boolean considerDonatingPermanent(final Player ai, final SpellAbility sa) {
|
||||||
Card donateTarget = ComputerUtil.getCardPreference(ai, sa.getHostCard(), "DonateMe", CardLists.filter(ai.getCardsIn(ZoneType.Battlefield).threadSafeIterable(), CardPredicates.hasSVar("DonateMe")));
|
Card donateTarget = ComputerUtil.getCardPreference(ai, sa.getHostCard(), "DonateMe", CardLists.filter(ai.getCardsIn(ZoneType.Battlefield).threadSafeIterable(), CardPredicates.hasSVar("DonateMe")));
|
||||||
if (donateTarget != null) {
|
if (donateTarget != null) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(donateTarget);
|
sa.getTargets().add(donateTarget);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should never get here because targetOpponent, called before targetPermanentToDonate, should already have made the AI bail
|
// Should never get here because targetOpponent, called before targetPermanentToDonate, should already have made the AI bail
|
||||||
System.err.println("Warning: Donate AI failed at SpecialCardAi.Donate#targetPermanentToDonate despite successfully targeting an opponent first.");
|
System.err.println("Warning: Donate AI failed at SpecialCardAi.Donate#targetPermanentToDonate despite successfully targeting an opponent first.");
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Electrostatic Pummeler
|
// Electrostatic Pummeler
|
||||||
public static class ElectrostaticPummeler {
|
public static class ElectrostaticPummeler {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
Game game = ai.getGame();
|
Game game = ai.getGame();
|
||||||
Combat combat = game.getCombat();
|
Combat combat = game.getCombat();
|
||||||
@@ -464,13 +445,13 @@ public class SpecialCardAi {
|
|||||||
if (saTop.getApi() == ApiType.DealDamage || saTop.getApi() == ApiType.DamageAll) {
|
if (saTop.getApi() == ApiType.DealDamage || saTop.getApi() == ApiType.DamageAll) {
|
||||||
int dmg = AbilityUtils.calculateAmount(saTop.getHostCard(), saTop.getParam("NumDmg"), saTop);
|
int dmg = AbilityUtils.calculateAmount(saTop.getHostCard(), saTop.getParam("NumDmg"), saTop);
|
||||||
if (source.getNetToughness() - source.getDamage() <= dmg && predictedPT.getRight() - source.getDamage() > dmg)
|
if (source.getNetToughness() - source.getDamage() <= dmg && predictedPT.getRight() - source.getDamage() > dmg)
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not activate if damage will be prevented
|
// Do not activate if damage will be prevented
|
||||||
if (source.staticDamagePrevention(predictedPT.getLeft(), 0, source, true) == 0) {
|
if (source.staticDamagePrevention(predictedPT.getLeft(), 0, source, true) == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactGame);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate Electrostatic Pummeler's pump only as a combat trick
|
// Activate Electrostatic Pummeler's pump only as a combat trick
|
||||||
@@ -479,14 +460,14 @@ public class SpecialCardAi {
|
|||||||
// We'll try to deal lethal trample/unblocked damage, so remember the card for attack
|
// We'll try to deal lethal trample/unblocked damage, so remember the card for attack
|
||||||
// and wait until declare blockers step.
|
// and wait until declare blockers step.
|
||||||
AiCardMemory.rememberCard(ai, source, AiCardMemory.MemorySet.MANDATORY_ATTACKERS);
|
AiCardMemory.rememberCard(ai, source, AiCardMemory.MemorySet.MANDATORY_ATTACKERS);
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
} else if (!game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (combat == null || !(combat.isAttacking(source) || combat.isBlocking(source))) {
|
if (combat == null || !(combat.isAttacking(source) || combat.isBlocking(source))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isBlocking = combat.isBlocking(source);
|
boolean isBlocking = combat.isBlocking(source);
|
||||||
@@ -511,11 +492,11 @@ public class SpecialCardAi {
|
|||||||
}
|
}
|
||||||
if (totalDamageToPW >= oppT + loyalty) {
|
if (totalDamageToPW >= oppT + loyalty) {
|
||||||
// Already enough damage to take care of the planeswalker
|
// Already enough damage to take care of the planeswalker
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
return false;
|
||||||
}
|
}
|
||||||
if ((unblocked || canTrample) && predictedPT.getLeft() >= oppT + loyalty) {
|
if ((unblocked || canTrample) && predictedPT.getLeft() >= oppT + loyalty) {
|
||||||
// Can pump to kill the planeswalker, go for it
|
// Can pump to kill the planeswalker, go for it
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -536,31 +517,31 @@ public class SpecialCardAi {
|
|||||||
// We can deal a lot of damage (either a lot of damage directly to the opponent,
|
// We can deal a lot of damage (either a lot of damage directly to the opponent,
|
||||||
// or kill the blocker(s) and damage the opponent at the same time, so go for it
|
// or kill the blocker(s) and damage the opponent at the same time, so go for it
|
||||||
AiCardMemory.rememberCard(ai, source, AiCardMemory.MemorySet.MANDATORY_ATTACKERS);
|
AiCardMemory.rememberCard(ai, source, AiCardMemory.MemorySet.MANDATORY_ATTACKERS);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (predictedPT.getRight() - source.getDamage() <= oppP && oppHasFirstStrike && !cantDie) {
|
if (predictedPT.getRight() - source.getDamage() <= oppP && oppHasFirstStrike && !cantDie) {
|
||||||
// Can't survive first strike or double strike, don't pump
|
// Can't survive first strike or double strike, don't pump
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
return false;
|
||||||
}
|
}
|
||||||
if (predictedPT.getLeft() < oppT && (!cantDie || predictedPT.getRight() - source.getDamage() <= oppP)) {
|
if (predictedPT.getLeft() < oppT && (!cantDie || predictedPT.getRight() - source.getDamage() <= oppP)) {
|
||||||
// Can't pump enough to kill the blockers and survive, don't pump
|
// Can't pump enough to kill the blockers and survive, don't pump
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
return false;
|
||||||
}
|
}
|
||||||
if (source.getNetCombatDamage() > oppT && source.getNetToughness() > oppP) {
|
if (source.getNetCombatDamage() > oppT && source.getNetToughness() > oppP) {
|
||||||
// Already enough to kill the blockers and survive, don't overpump
|
// Already enough to kill the blockers and survive, don't overpump
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
return false;
|
||||||
}
|
}
|
||||||
if (oppCantDie && !source.hasKeyword(Keyword.TRAMPLE) && !source.isWitherDamage()
|
if (oppCantDie && !source.hasKeyword(Keyword.TRAMPLE) && !source.isWitherDamage()
|
||||||
&& predictedPT.getLeft() <= oppT) {
|
&& predictedPT.getLeft() <= oppT) {
|
||||||
// Can't kill or cripple anyone, as well as can't Trample over, so don't pump
|
// Can't kill or cripple anyone, as well as can't Trample over, so don't pump
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we got here, it should be a favorable combat pump, resulting in at least one
|
// If we got here, it should be a favorable combat pump, resulting in at least one
|
||||||
// opposing creature dying, and hopefully with the Pummeler surviving combat.
|
// opposing creature dying, and hopefully with the Pummeler surviving combat.
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean predictOverwhelmingDamage(final Player ai, final SpellAbility sa) {
|
public static boolean predictOverwhelmingDamage(final Player ai, final SpellAbility sa) {
|
||||||
@@ -637,15 +618,15 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Fell the Mighty
|
// Fell the Mighty
|
||||||
public static class FellTheMighty {
|
public static class FellTheMighty {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
CardCollection aiList = ai.getCreaturesInPlay();
|
CardCollection aiList = ai.getCreaturesInPlay();
|
||||||
if (aiList.isEmpty()) {
|
if (aiList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
CardLists.sortByPowerAsc(aiList);
|
CardLists.sortByPowerAsc(aiList);
|
||||||
Card lowest = aiList.get(0);
|
Card lowest = aiList.get(0);
|
||||||
if (!sa.canTarget(lowest)) {
|
if (!sa.canTarget(lowest)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection oppList = CardLists.filter(ai.getGame().getCardsIn(ZoneType.Battlefield),
|
CardCollection oppList = CardLists.filter(ai.getGame().getCardsIn(ZoneType.Battlefield),
|
||||||
@@ -655,9 +636,9 @@ public class SpecialCardAi {
|
|||||||
if (ComputerUtilCard.evaluateCreatureList(oppList) > 200) {
|
if (ComputerUtilCard.evaluateCreatureList(oppList) > 200) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(lowest);
|
sa.getTargets().add(lowest);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,25 +673,25 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Gideon Blackblade
|
// Gideon Blackblade
|
||||||
public static class GideonBlackblade {
|
public static class GideonBlackblade {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
CardCollectionView otb = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.isTargetableBy(sa));
|
CardCollectionView otb = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.isTargetableBy(sa));
|
||||||
if (!otb.isEmpty()) {
|
if (!otb.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestAI(otb));
|
sa.getTargets().add(ComputerUtilCard.getBestAI(otb));
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Goblin Polka Band
|
// Goblin Polka Band
|
||||||
public static class GoblinPolkaBand {
|
public static class GoblinPolkaBand {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
int maxPotentialTgts = ai.getOpponents().getCreaturesInPlay().filter(CardPredicates.UNTAPPED).size();
|
int maxPotentialTgts = ai.getOpponents().getCreaturesInPlay().filter(CardPredicates.UNTAPPED).size();
|
||||||
int maxPotentialPayment = ComputerUtilMana.determineLeftoverMana(sa, ai, "R", false);
|
int maxPotentialPayment = ComputerUtilMana.determineLeftoverMana(sa, ai, "R", false);
|
||||||
|
|
||||||
int numTgts = Math.min(maxPotentialPayment, maxPotentialTgts);
|
int numTgts = Math.min(maxPotentialPayment, maxPotentialTgts);
|
||||||
if (numTgts == 0) {
|
if (numTgts == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Announce
|
// Set Announce
|
||||||
@@ -720,7 +701,7 @@ public class SpecialCardAi {
|
|||||||
List<GameEntity> validTgts = sa.getTargetRestrictions().getAllCandidates(sa, true);
|
List<GameEntity> validTgts = sa.getTargetRestrictions().getAllCandidates(sa, true);
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().addAll(Aggregates.random(validTgts, numTgts));
|
sa.getTargets().addAll(Aggregates.random(validTgts, numTgts));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -929,12 +910,12 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Living Death (and other similar cards using AILogic LivingDeath or AILogic ReanimateAll)
|
// Living Death (and other similar cards using AILogic LivingDeath or AILogic ReanimateAll)
|
||||||
public static class LivingDeath {
|
public static class LivingDeath {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
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
|
// 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)
|
// one resolves, otherwise the reanimation attempt will be ruined (e.g. Living End)
|
||||||
for (Card ex : ai.getCardsIn(ZoneType.Exile)) {
|
for (Card ex : ai.getCardsIn(ZoneType.Exile)) {
|
||||||
if (ex.hasSVar("IsReanimatorCard") && ex.getCounters(CounterEnumType.TIME) > 0) {
|
if (ex.hasSVar("IsReanimatorCard") && ex.getCounters(CounterEnumType.TIME) > 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -945,7 +926,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
if (aiCreaturesInGY.isEmpty()) {
|
if (aiCreaturesInGY.isEmpty()) {
|
||||||
// nothing in graveyard, so cut short
|
// nothing in graveyard, so cut short
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Card c : ai.getCreaturesInPlay()) {
|
for (Card c : ai.getCreaturesInPlay()) {
|
||||||
@@ -977,30 +958,17 @@ public class SpecialCardAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we get more value out of this than our opponent does (hopefully), go for it
|
// if we get more value out of this than our opponent does (hopefully), go for it
|
||||||
if ((aiGraveyardPower - aiBattlefieldPower) > (oppGraveyardPower - oppBattlefieldPower + threshold)) {
|
return (aiGraveyardPower - aiBattlefieldPower) > (oppGraveyardPower - oppBattlefieldPower + threshold);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maze's End
|
// Maze's End
|
||||||
public static class MazesEnd {
|
public static class MazesEnd {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||||
CardCollection availableGates = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.isType("Gate"));
|
CardCollection availableGates = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.isType("Gate"));
|
||||||
|
|
||||||
if (ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == ai && !availableGates.isEmpty()) {
|
return ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == ai && !availableGates.isEmpty();
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (availableGates.isEmpty()) {
|
|
||||||
// No gates available, so don't activate Maze's End
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Card considerCardToGet(final Player ai, final SpellAbility sa)
|
public static Card considerCardToGet(final Player ai, final SpellAbility sa)
|
||||||
@@ -1064,33 +1032,29 @@ public class SpecialCardAi {
|
|||||||
return exiledWith == null || (tgt != null && ComputerUtilCard.evaluateCreature(tgt) > ComputerUtilCard.evaluateCreature(exiledWith));
|
return exiledWith == null || (tgt != null && ComputerUtilCard.evaluateCreature(tgt) > ComputerUtilCard.evaluateCreature(exiledWith));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AiAbilityDecision considerCopy(final Player ai, final SpellAbility sa) {
|
public static boolean considerCopy(final Player ai, final SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Card exiledWith = source.getImprintedCards().isEmpty() ? null : source.getImprintedCards().getFirst();
|
final Card exiledWith = source.getImprintedCards().isEmpty() ? null : source.getImprintedCards().getFirst();
|
||||||
|
|
||||||
if (exiledWith == null) {
|
if (exiledWith == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to either be able to attack with the creature, or keep it until our opponent's end of turn as a
|
// We want to either be able to attack with the creature, or keep it until our opponent's end of turn as a
|
||||||
// potential blocker
|
// potential blocker
|
||||||
if (ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, exiledWith)
|
return ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, exiledWith)
|
||||||
|| (ai.getGame().getPhaseHandler().getPlayerTurn().isOpponentOf(ai) && ai.getGame().getCombat() != null
|
|| (ai.getGame().getPhaseHandler().getPlayerTurn().isOpponentOf(ai) && ai.getGame().getCombat() != null
|
||||||
&& !ai.getGame().getCombat().getAttackers().isEmpty())) {
|
&& !ai.getGame().getCombat().getAttackers().isEmpty());
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Momir Vig, Simic Visionary Avatar
|
// Momir Vig, Simic Visionary Avatar
|
||||||
public static class MomirVigAvatar {
|
public static class MomirVigAvatar {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
|
|
||||||
if (source.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN1)) {
|
if (source.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN1)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In MoJhoSto, prefer Jhoira sorcery ability from time to time
|
// In MoJhoSto, prefer Jhoira sorcery ability from time to time
|
||||||
@@ -1101,7 +1065,7 @@ public class SpecialCardAi {
|
|||||||
int numLandsForJhoira = aic.getIntProperty(AiProps.MOJHOSTO_NUM_LANDS_TO_ACTIVATE_JHOIRA);
|
int numLandsForJhoira = aic.getIntProperty(AiProps.MOJHOSTO_NUM_LANDS_TO_ACTIVATE_JHOIRA);
|
||||||
|
|
||||||
if (ai.getLandsInPlay().size() >= numLandsForJhoira && MyRandom.percentTrue(chanceToPrefJhoira)) {
|
if (ai.getLandsInPlay().size() >= numLandsForJhoira && MyRandom.percentTrue(chanceToPrefJhoira)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1110,7 +1074,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Some basic strategy for Momir
|
// Some basic strategy for Momir
|
||||||
if (tokenSize < 2) {
|
if (tokenSize < 2) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenSize > 11) {
|
if (tokenSize > 11) {
|
||||||
@@ -1119,7 +1083,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
sa.setXManaCostPaid(tokenSize);
|
sa.setXManaCostPaid(tokenSize);
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1158,13 +1122,13 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Necropotence
|
// Necropotence
|
||||||
public static class Necropotence {
|
public static class Necropotence {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
Game game = ai.getGame();
|
Game game = ai.getGame();
|
||||||
int computerHandSize = ai.getZone(ZoneType.Hand).size();
|
int computerHandSize = ai.getZone(ZoneType.Hand).size();
|
||||||
int maxHandSize = ai.getMaxHandSize();
|
int maxHandSize = ai.getMaxHandSize();
|
||||||
|
|
||||||
if (ai.getCardsIn(ZoneType.Library).isEmpty()) {
|
if (ai.getCardsIn(ZoneType.Library).isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false; // nothing to draw from the library
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ai.getCardsIn(ZoneType.Battlefield).anyMatch(CardPredicates.nameEquals("Yawgmoth's Bargain"))) {
|
if (ai.getCardsIn(ZoneType.Battlefield).anyMatch(CardPredicates.nameEquals("Yawgmoth's Bargain"))) {
|
||||||
@@ -1172,7 +1136,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// TODO: in presence of bad effects which deal damage when a card is drawn, probably better to prefer Necropotence instead?
|
// TODO: in presence of bad effects which deal damage when a card is drawn, probably better to prefer Necropotence instead?
|
||||||
// (not sure how to detect the presence of such effects yet)
|
// (not sure how to detect the presence of such effects yet)
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhaseHandler ph = game.getPhaseHandler();
|
PhaseHandler ph = game.getPhaseHandler();
|
||||||
@@ -1194,33 +1158,23 @@ public class SpecialCardAi {
|
|||||||
// We're in a situation when we have nothing castable in hand, something needs to be done
|
// We're in a situation when we have nothing castable in hand, something needs to be done
|
||||||
if (!blackViseOTB) {
|
if (!blackViseOTB) {
|
||||||
// exile-loot +1 card when at max hand size, hoping to get a workable spell or land
|
// exile-loot +1 card when at max hand size, hoping to get a workable spell or land
|
||||||
if (computerHandSize + exiledWithNecro - 1 == maxHandSize) {
|
return computerHandSize + exiledWithNecro - 1 == maxHandSize;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Loot to 7 in presence of Black Vise, hoping to find what to do
|
// Loot to 7 in presence of Black Vise, hoping to find what to do
|
||||||
// NOTE: can still currently get theoretically locked with 7 uncastable spells. Loot to 8 instead?
|
// NOTE: can still currently get theoretically locked with 7 uncastable spells. Loot to 8 instead?
|
||||||
if (computerHandSize + exiledWithNecro <= maxHandSize) {
|
return computerHandSize + exiledWithNecro <= maxHandSize;
|
||||||
// Loot to 7, hoping to find something playable
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// Loot to 8, hoping to find something playable
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (blackViseOTB && computerHandSize + exiledWithNecro - 1 >= 4) {
|
} else if (blackViseOTB && computerHandSize + exiledWithNecro - 1 >= 4) {
|
||||||
// try not to overdraw in presence of Black Vise
|
// try not to overdraw in presence of Black Vise
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (computerHandSize + exiledWithNecro - 1 >= maxHandSize) {
|
} else if (computerHandSize + exiledWithNecro - 1 >= maxHandSize) {
|
||||||
// Only draw until we reach max hand size
|
// Only draw until we reach max hand size
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (!ph.isPlayerTurn(ai) || !ph.is(PhaseType.MAIN2)) {
|
} else if (!ph.isPlayerTurn(ai) || !ph.is(PhaseType.MAIN2)) {
|
||||||
// Only activate in AI's own turn (sans the exception above)
|
// Only activate in AI's own turn (sans the exception above)
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForMain2);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1340,7 +1294,7 @@ public class SpecialCardAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AiAbilityDecision considerSecondTarget(final Player ai, final SpellAbility sa) {
|
public static boolean considerSecondTarget(final Player ai, final SpellAbility sa) {
|
||||||
Card firstTgt = sa.getParent().getTargetCard();
|
Card firstTgt = sa.getParent().getTargetCard();
|
||||||
CardCollection candidates = ai.getOpponents().getCardsIn(ZoneType.Battlefield).filter(
|
CardCollection candidates = ai.getOpponents().getCardsIn(ZoneType.Battlefield).filter(
|
||||||
CardPredicates.sharesCardTypeWith(firstTgt).and(CardPredicates.isTargetableBy(sa)));
|
CardPredicates.sharesCardTypeWith(firstTgt).and(CardPredicates.isTargetableBy(sa)));
|
||||||
@@ -1348,105 +1302,89 @@ public class SpecialCardAi {
|
|||||||
if (secondTgt != null) {
|
if (secondTgt != null) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(secondTgt);
|
sa.getTargets().add(secondTgt);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Price of Progress
|
// Price of Progress
|
||||||
public static class PriceOfProgress {
|
public static class PriceOfProgress {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
// Don't play in early game - opponent likely still has lands to play
|
// Don't play in early game - opponent likely still has lands to play
|
||||||
if (ai.getGame().getPhaseHandler().getTurn() < 10) {
|
if (ai.getGame().getPhaseHandler().getTurn() < 10) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int aiLands = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.NONBASIC_LANDS).size();
|
int aiLands = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.NONBASIC_LANDS).size();
|
||||||
// TODO Better if we actually calculate the true damage
|
|
||||||
boolean willDieToPCasting = (ai.getLife() <= aiLands * 2);
|
|
||||||
if (!willDieToPCasting) {
|
|
||||||
boolean hasBridge = false;
|
|
||||||
for (Card c : ai.getCardsIn(ZoneType.Battlefield)) {
|
|
||||||
// Do we have a card in play that makes us want to empty out hand?
|
|
||||||
if (c.hasSVar("PreferredHandSize") && ai.getCardsIn(ZoneType.Hand).size() > Integer.parseInt(c.getSVar("PreferredHandSize"))) {
|
|
||||||
hasBridge = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do if we need to lose cards to activate Ensnaring Bridge or Cursed Scroll
|
boolean hasBridge = false;
|
||||||
// even if suboptimal play, but don't waste the card too early even then!
|
for (Card c : ai.getCardsIn(ZoneType.Battlefield)) {
|
||||||
if (hasBridge) {
|
// Do we have a card in play that makes us want to empty out hand?
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.PlayToEmptyHand);
|
if (c.hasSVar("PreferredHandSize") && ai.getCardsIn(ZoneType.Hand).size() > Integer.parseInt(c.getSVar("PreferredHandSize"))) {
|
||||||
|
hasBridge = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean willPlay = true;
|
// Do if we need to lose cards to activate Ensnaring Bridge or Cursed Scroll
|
||||||
|
// even if suboptimal play, but don't waste the card too early even then!
|
||||||
|
if ((hasBridge) && (ai.getGame().getPhaseHandler().getTurn() >= 10)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (Player opp : ai.getOpponents()) {
|
for (Player opp : ai.getOpponents()) {
|
||||||
int oppLands = CardLists.filter(opp.getCardsIn(ZoneType.Battlefield), CardPredicates.NONBASIC_LANDS).size();
|
int oppLands = CardLists.filter(opp.getCardsIn(ZoneType.Battlefield), CardPredicates.NONBASIC_LANDS).size();
|
||||||
// Don't if no enemy nonbasic lands
|
|
||||||
if (oppLands == 0) {
|
|
||||||
willPlay = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always if enemy would die and we don't!
|
// Always if enemy would die and we don't!
|
||||||
// TODO : predict actual damage instead of assuming it'll be 2*lands
|
// TODO : predict actual damage instead of assuming it'll be 2*lands
|
||||||
// Don't if we lose, unless we lose anyway to unblocked creatures next turn
|
// Don't if we lose, unless we lose anyway to unblocked creatures next turn
|
||||||
if (willDieToPCasting &&
|
if ((ai.getLife() <= aiLands * 2) &&
|
||||||
(!(ComputerUtil.aiLifeInDanger(ai, true, 0)) && ((ai.getOpponentsSmallestLifeTotal()) <= oppLands * 2))) {
|
(!(ComputerUtil.aiLifeInDanger(ai, true, 0)) && ((ai.getOpponentsSmallestLifeTotal()) <= oppLands * 2))) {
|
||||||
willPlay = false;
|
return false;
|
||||||
}
|
}
|
||||||
// Do if we can win
|
// Do if we can win
|
||||||
if (opp.getLife() <= oppLands * 2) {
|
if ((ai.getOpponentsSmallestLifeTotal()) <= oppLands * 2) {
|
||||||
return new AiAbilityDecision(1000, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
// Don't if we'd lose a larger percentage of our remaining life than enemy
|
// Don't if we'd lose a larger percentage of our remaining life than enemy
|
||||||
if ((aiLands / ((double) ai.getLife())) >
|
if ((aiLands / ((double) ai.getLife())) >
|
||||||
(oppLands / ((double) ai.getOpponentsSmallestLifeTotal()))) {
|
(oppLands / ((double) ai.getOpponentsSmallestLifeTotal()))) {
|
||||||
willPlay = false;
|
return false;
|
||||||
|
}
|
||||||
|
// Don't if no enemy nonbasic lands
|
||||||
|
if (oppLands == 0) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't if loss is equal in percentage but we lose more points
|
// Don't if loss is equal in percentage but we lose more points
|
||||||
if (((aiLands / ((double) ai.getLife())) == (oppLands / ((double) ai.getOpponentsSmallestLifeTotal())))
|
if (((aiLands / ((double) ai.getLife())) == (oppLands / ((double) ai.getOpponentsSmallestLifeTotal())))
|
||||||
&& (aiLands > oppLands)) {
|
&& (aiLands > oppLands)) {
|
||||||
willPlay = false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (willPlay) {
|
return true;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sarkhan the Mad
|
// Sarkhan the Mad
|
||||||
public static class SarkhanTheMad {
|
public static class SarkhanTheMad {
|
||||||
public static AiAbilityDecision considerDig(final Player ai, final SpellAbility sa) {
|
public static boolean considerDig(final Player ai, final SpellAbility sa) {
|
||||||
if (sa.getHostCard().getCounters(CounterEnumType.LOYALTY) == 1) {
|
return sa.getHostCard().getCounters(CounterEnumType.LOYALTY) == 1;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AiAbilityDecision considerMakeDragon(final Player ai, final SpellAbility sa) {
|
public static boolean considerMakeDragon(final Player ai, final SpellAbility sa) {
|
||||||
// TODO: expand this logic to make the AI force the opponent to sacrifice a big threat bigger than a 5/5 flier?
|
// TODO: expand this logic to make the AI force the opponent to sacrifice a big threat bigger than a 5/5 flier?
|
||||||
CardCollection creatures = ai.getCreaturesInPlay();
|
CardCollection creatures = ai.getCreaturesInPlay();
|
||||||
boolean hasValidTgt = !CardLists.filter(creatures, t -> t.getNetPower() < 5 && t.getNetToughness() < 5).isEmpty();
|
boolean hasValidTgt = !CardLists.filter(creatures, t -> t.getNetPower() < 5 && t.getNetToughness() < 5).isEmpty();
|
||||||
if (hasValidTgt) {
|
if (hasValidTgt) {
|
||||||
Card worstCreature = ComputerUtilCard.getWorstCreatureAI(creatures);
|
Card worstCreature = ComputerUtilCard.getWorstCreatureAI(creatures);
|
||||||
sa.getTargets().add(worstCreature);
|
sa.getTargets().add(worstCreature);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.AddBoardPresence);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean considerUltimate(final Player ai, final SpellAbility sa, final Player weakestOpp) {
|
public static boolean considerUltimate(final Player ai, final SpellAbility sa, final Player weakestOpp) {
|
||||||
int minLife = weakestOpp.getLife();
|
int minLife = weakestOpp.getLife();
|
||||||
|
|
||||||
@@ -1502,7 +1440,7 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Sorin, Vengeful Bloodlord
|
// Sorin, Vengeful Bloodlord
|
||||||
public static class SorinVengefulBloodlord {
|
public static class SorinVengefulBloodlord {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
int loyalty = sa.getHostCard().getCounters(CounterEnumType.LOYALTY);
|
int loyalty = sa.getHostCard().getCounters(CounterEnumType.LOYALTY);
|
||||||
CardCollection creaturesToGet = CardLists.filter(ai.getCardsIn(ZoneType.Graveyard),
|
CardCollection creaturesToGet = CardLists.filter(ai.getCardsIn(ZoneType.Graveyard),
|
||||||
CardPredicates.CREATURES
|
CardPredicates.CREATURES
|
||||||
@@ -1516,7 +1454,7 @@ public class SpecialCardAi {
|
|||||||
CardLists.sortByCmcDesc(creaturesToGet);
|
CardLists.sortByCmcDesc(creaturesToGet);
|
||||||
|
|
||||||
if (creaturesToGet.isEmpty()) {
|
if (creaturesToGet.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pick the best creature that will stay on the battlefield
|
// pick the best creature that will stay on the battlefield
|
||||||
@@ -1531,11 +1469,10 @@ public class SpecialCardAi {
|
|||||||
if (best != null) {
|
if (best != null) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(best);
|
sa.getTargets().add(best);
|
||||||
sa.setXManaCostPaid(best.getCMC());
|
return true;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1649,27 +1586,23 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// The One Ring
|
// The One Ring
|
||||||
public static class TheOneRing {
|
public static class TheOneRing {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
if (!ai.canLoseLife() || ai.cantLoseForZeroOrLessLife()) {
|
if (!ai.canLoseLife() || ai.cantLoseForZeroOrLessLife()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AiController aic = ((PlayerControllerAi) ai.getController()).getAi();
|
AiController aic = ((PlayerControllerAi) ai.getController()).getAi();
|
||||||
int lifeInDanger = aic.getIntProperty(AiProps.AI_IN_DANGER_THRESHOLD);
|
int lifeInDanger = aic.getIntProperty(AiProps.AI_IN_DANGER_THRESHOLD);
|
||||||
int numCtrs = sa.getHostCard().getCounters(CounterEnumType.BURDEN);
|
int numCtrs = sa.getHostCard().getCounters(CounterEnumType.BURDEN);
|
||||||
|
|
||||||
if (ai.getLife() > numCtrs + 1 && ai.getLife() > lifeInDanger
|
return ai.getLife() > numCtrs + 1 && ai.getLife() > lifeInDanger
|
||||||
&& ai.getMaxHandSize() >= ai.getCardsIn(ZoneType.Hand).size() + numCtrs + 1) {
|
&& ai.getMaxHandSize() >= ai.getCardsIn(ZoneType.Hand).size() + numCtrs + 1;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.LifeInDanger);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Scarab God
|
// The Scarab God
|
||||||
public static class TheScarabGod {
|
public static class TheScarabGod {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
Card bestOppCreat = ComputerUtilCard.getBestAI(CardLists.filter(ai.getOpponents().getCardsIn(ZoneType.Graveyard), CardPredicates.CREATURES));
|
Card bestOppCreat = ComputerUtilCard.getBestAI(CardLists.filter(ai.getOpponents().getCardsIn(ZoneType.Graveyard), CardPredicates.CREATURES));
|
||||||
Card worstOwnCreat = ComputerUtilCard.getWorstAI(CardLists.filter(ai.getCardsIn(ZoneType.Graveyard), CardPredicates.CREATURES));
|
Card worstOwnCreat = ComputerUtilCard.getWorstAI(CardLists.filter(ai.getCardsIn(ZoneType.Graveyard), CardPredicates.CREATURES));
|
||||||
|
|
||||||
@@ -1680,19 +1613,13 @@ public class SpecialCardAi {
|
|||||||
sa.getTargets().add(worstOwnCreat);
|
sa.getTargets().add(worstOwnCreat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sa.getTargets().isEmpty()) {
|
return sa.getTargets().size() > 0;
|
||||||
// If we have a target, we can play this ability
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// No valid targets, can't play this ability
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timetwister
|
// Timetwister
|
||||||
public static class Timetwister {
|
public static class Timetwister {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
final int aiHandSize = ai.getCardsIn(ZoneType.Hand).size();
|
final int aiHandSize = ai.getCardsIn(ZoneType.Hand).size();
|
||||||
int maxOppHandSize = 0;
|
int maxOppHandSize = 0;
|
||||||
|
|
||||||
@@ -1706,14 +1633,7 @@ public class SpecialCardAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use in case we're getting low on cards or if we're significantly behind our opponent in cards in hand
|
// use in case we're getting low on cards or if we're significantly behind our opponent in cards in hand
|
||||||
if (aiHandSize < HAND_SIZE_THRESHOLD || maxOppHandSize - aiHandSize > HAND_SIZE_THRESHOLD) {
|
return aiHandSize < HAND_SIZE_THRESHOLD || maxOppHandSize - aiHandSize > HAND_SIZE_THRESHOLD;
|
||||||
// if the AI has less than 3 cards in hand or the opponent has more than 3 cards in hand than the AI
|
|
||||||
// then the AI is willing to play this ability
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// otherwise, don't play this ability
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1774,12 +1694,12 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
// Volrath's Shapeshifter
|
// Volrath's Shapeshifter
|
||||||
public static class VolrathsShapeshifter {
|
public static class VolrathsShapeshifter {
|
||||||
public static AiAbilityDecision consider(final Player ai, final SpellAbility sa) {
|
public static boolean consider(final Player ai, final SpellAbility sa) {
|
||||||
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||||
if (ph.getPhase().isBefore(PhaseType.COMBAT_BEGIN)) {
|
if (ph.getPhase().isBefore(PhaseType.COMBAT_BEGIN)) {
|
||||||
// try not to do this too early to at least attempt to avoid situations where the AI
|
// try not to do this too early to at least attempt to avoid situations where the AI
|
||||||
// would cast a spell which would ruin the shapeshifting
|
// would cast a spell which would ruin the shapeshifting
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForMain2);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollectionView aiGY = ai.getCardsIn(ZoneType.Graveyard);
|
CardCollectionView aiGY = ai.getCardsIn(ZoneType.Graveyard);
|
||||||
@@ -1795,15 +1715,11 @@ public class SpecialCardAi {
|
|||||||
if (topGY == null
|
if (topGY == null
|
||||||
|| !topGY.isCreature()
|
|| !topGY.isCreature()
|
||||||
|| ComputerUtilCard.evaluateCreature(creatHand) > ComputerUtilCard.evaluateCreature(topGY) + 80) {
|
|| ComputerUtilCard.evaluateCreature(creatHand) > ComputerUtilCard.evaluateCreature(topGY) + 80) {
|
||||||
if ( numCreatsInHand > 1 || !ComputerUtilMana.canPayManaCost(creatHand.getSpellPermanent(), ai, 0, false)) {
|
return numCreatsInHand > 1 || !ComputerUtilMana.canPayManaCost(creatHand.getSpellPermanent(), ai, 0, false);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CardCollection targetBestCreature(final Player ai, final SpellAbility sa) {
|
public static CardCollection targetBestCreature(final Player ai, final SpellAbility sa) {
|
||||||
|
|||||||
@@ -39,75 +39,70 @@ import forge.util.collect.FCollectionView;
|
|||||||
*/
|
*/
|
||||||
public abstract class SpellAbilityAi {
|
public abstract class SpellAbilityAi {
|
||||||
|
|
||||||
public final AiAbilityDecision canPlayWithSubs(final Player aiPlayer, final SpellAbility sa) {
|
public final boolean canPlayAIWithSubs(final Player aiPlayer, final SpellAbility sa) {
|
||||||
AiAbilityDecision decision = canPlay(aiPlayer, sa);
|
if (!canPlayAI(aiPlayer, sa)) {
|
||||||
if (!decision.willingToPlay() && !"PlayForSub".equals(sa.getParam("AILogic"))) {
|
return false;
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
final AbilitySub subAb = sa.getSubAbility();
|
final AbilitySub subAb = sa.getSubAbility();
|
||||||
if (subAb == null) {
|
return subAb == null || chkDrawbackWithSubs(aiPlayer, subAb);
|
||||||
return decision;
|
|
||||||
}
|
|
||||||
|
|
||||||
return chkDrawbackWithSubs(aiPlayer, subAb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the AI decision to play a "main" SpellAbility
|
* Handles the AI decision to play a "main" SpellAbility
|
||||||
*/
|
*/
|
||||||
protected AiAbilityDecision canPlay(final Player ai, final SpellAbility sa) {
|
protected boolean canPlayAI(final Player ai, final SpellAbility sa) {
|
||||||
if (sa.getRestrictions() != null && !sa.getRestrictions().canPlay(sa.getHostCard(), sa)) {
|
final Card source = sa.getHostCard();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
|
||||||
|
if (sa.getRestrictions() != null && !sa.getRestrictions().canPlay(source, sa)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return canPlayWithoutRestrict(ai, sa);
|
return canPlayWithoutRestrict(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AiAbilityDecision canPlayWithoutRestrict(final Player ai, final SpellAbility sa) {
|
protected boolean canPlayWithoutRestrict(final Player ai, final SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Cost cost = sa.getPayCosts();
|
final Cost cost = sa.getPayCosts();
|
||||||
|
|
||||||
|
if (sa.hasParam("AICheckCanPlayWithDefinedX")) {
|
||||||
|
// FIXME: can this somehow be simplified without the need for an extra AI hint?
|
||||||
|
sa.setXManaCostPaid(ComputerUtilCost.getMaxXValue(sa, ai, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkConditions(ai, sa, sa.getConditions())) {
|
||||||
|
SpellAbility sub = sa.getSubAbility();
|
||||||
|
if (sub != null && !checkConditions(ai, sub, sub.getConditions())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sa.hasParam("AILogic")) {
|
if (sa.hasParam("AILogic")) {
|
||||||
final String logic = sa.getParam("AILogic");
|
final String logic = sa.getParam("AILogic");
|
||||||
final boolean alwaysOnDiscard = "AlwaysOnDiscard".equals(logic) && ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN, ai)
|
final boolean alwaysOnDiscard = "AlwaysOnDiscard".equals(logic) && ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN, ai)
|
||||||
&& !ai.isUnlimitedHandSize() && ai.getCardsIn(ZoneType.Hand).size() > ai.getMaxHandSize();
|
&& !ai.isUnlimitedHandSize() && ai.getCardsIn(ZoneType.Hand).size() > ai.getMaxHandSize();
|
||||||
if (!checkAiLogic(ai, sa, logic)) {
|
if (!checkAiLogic(ai, sa, logic)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if (!alwaysOnDiscard && !checkPhaseRestrictions(ai, sa, ai.getGame().getPhaseHandler(), logic)) {
|
if (!alwaysOnDiscard && !checkPhaseRestrictions(ai, sa, ai.getGame().getPhaseHandler(), logic)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingPhaseRestrictions);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!checkPhaseRestrictions(ai, sa, ai.getGame().getPhaseHandler())) {
|
} else if (!checkPhaseRestrictions(ai, sa, ai.getGame().getPhaseHandler())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingPhaseRestrictions);
|
return false;
|
||||||
} else if (ComputerUtil.preventRunAwayActivations(sa)) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.StopRunawayActivations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AiAbilityDecision decision = checkApiLogic(ai, sa);
|
if (!checkApiLogic(ai, sa)) {
|
||||||
if (!decision.willingToPlay()) {
|
return false;
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
|
// needs to be after API logic because needs to check possible X Cost?
|
||||||
// needs to be after API logic because needs to check possible X Cost
|
|
||||||
if (cost != null && !willPayCosts(ai, sa, cost, source)) {
|
if (cost != null && !willPayCosts(ai, sa, cost, source)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CostNotAcceptable);
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
// for cards like Figure of Destiny
|
|
||||||
// (it's unlikely many valid effect would work like this -
|
|
||||||
// and while in theory AI could turn some conditions true in response that's far too advanced as default)
|
|
||||||
if (!checkConditions(ai, sa)) {
|
|
||||||
SpellAbility sub = sa.getSubAbility();
|
|
||||||
if (sub == null || !checkConditions(ai, sub)) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.NeedsToPlayCriteriaNotMet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkConditions(final Player ai, final SpellAbility sa) {
|
protected boolean checkConditions(final Player ai, final SpellAbility sa, SpellAbilityCondition con) {
|
||||||
// copy it to disable some checks that the AI need to check extra
|
// copy it to disable some checks that the AI need to check extra
|
||||||
SpellAbilityCondition con = (SpellAbilityCondition) sa.getConditions().copy();
|
con = (SpellAbilityCondition) con.copy();
|
||||||
|
|
||||||
// if manaspent, check if AI can pay the colored mana as cost
|
// if manaspent, check if AI can pay the colored mana as cost
|
||||||
if (!con.getManaSpent().isEmpty()) {
|
if (!con.getManaSpent().isEmpty()) {
|
||||||
@@ -121,6 +116,40 @@ public abstract class SpellAbilityAi {
|
|||||||
return con.areMet(sa);
|
return con.areMet(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the AI will play a SpellAbility with the specified AiLogic
|
||||||
|
*/
|
||||||
|
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
|
||||||
|
if (aiLogic.equals("CheckCondition")) {
|
||||||
|
SpellAbility saCopy = sa.copy();
|
||||||
|
saCopy.setActivatingPlayer(ai);
|
||||||
|
return saCopy.metConditions();
|
||||||
|
}
|
||||||
|
|
||||||
|
return !("Never".equals(aiLogic));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the AI is willing to pay for additional costs
|
||||||
|
* <p>
|
||||||
|
* Evaluated costs are: life, discard, sacrifice and counter-removal
|
||||||
|
*/
|
||||||
|
protected boolean willPayCosts(final Player ai, final SpellAbility sa, final Cost cost, final Card source) {
|
||||||
|
if (!ComputerUtilCost.checkLifeCost(ai, cost, source, 4, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!ComputerUtilCost.checkDiscardCost(ai, cost, source, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!ComputerUtilCost.checkSacrificeCost(ai, cost, source, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!ComputerUtilCost.checkRemoveCounterCost(cost, source, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the AI will play a SpellAbility based on its phase restrictions
|
* Checks if the AI will play a SpellAbility based on its phase restrictions
|
||||||
*/
|
*/
|
||||||
@@ -130,38 +159,19 @@ public abstract class SpellAbilityAi {
|
|||||||
|
|
||||||
protected boolean checkPhaseRestrictions(final Player ai, final SpellAbility sa, final PhaseHandler ph,
|
protected boolean checkPhaseRestrictions(final Player ai, final SpellAbility sa, final PhaseHandler ph,
|
||||||
final String logic) {
|
final String logic) {
|
||||||
if (logic.equals("AtOppEOT")) {
|
|
||||||
return ph.getNextTurn() == ai && ph.is(PhaseType.END_OF_TURN);
|
|
||||||
}
|
|
||||||
return checkPhaseRestrictions(ai, sa, ph);
|
return checkPhaseRestrictions(ai, sa, ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the AI will play a SpellAbility with the specified AiLogic
|
|
||||||
*/
|
|
||||||
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
|
|
||||||
if ("Never".equals(aiLogic)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!"Once".equals(aiLogic)) {
|
|
||||||
return !sa.getHostCard().getAbilityActivatedThisTurn().getActivators(sa).contains(ai);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rest of the logic not covered by the canPlayAI template is defined here
|
* The rest of the logic not covered by the canPlayAI template is defined here
|
||||||
*/
|
*/
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
if (sa.getActivationsThisTurn() == 0 || MyRandom.getRandom().nextFloat() < .8f) {
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
// 80% chance to play the ability
|
return false; // prevent infinite loop
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
}
|
||||||
|
return MyRandom.getRandom().nextFloat() < .8f; // random success
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean doTrigger(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
public final boolean doTriggerAI(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
||||||
// this evaluation order is currently intentional as it does more stuff that helps avoiding some crashes
|
// this evaluation order is currently intentional as it does more stuff that helps avoiding some crashes
|
||||||
if (!ComputerUtilCost.canPayCost(sa, aiPlayer, true) && !mandatory) {
|
if (!ComputerUtilCost.canPayCost(sa, aiPlayer, true) && !mandatory) {
|
||||||
return false;
|
return false;
|
||||||
@@ -173,48 +183,28 @@ public abstract class SpellAbilityAi {
|
|||||||
return sa.isTargetNumberValid();
|
return sa.isTargetNumberValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
return doTriggerNoCostWithSubs(aiPlayer, sa, mandatory).willingToPlay();
|
return doTriggerNoCostWithSubs(aiPlayer, sa, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final AiAbilityDecision doTriggerNoCostWithSubs(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
public final boolean doTriggerNoCostWithSubs(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
||||||
AiAbilityDecision decision = doTriggerNoCost(aiPlayer, sa, mandatory);
|
if (!doTriggerAINoCost(aiPlayer, sa, mandatory) && !"Always".equals(sa.getParam("AILogic"))) {
|
||||||
if (!decision.willingToPlay() && !"Always".equals(sa.getParam("AILogic"))) {
|
return false;
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
final AbilitySub subAb = sa.getSubAbility();
|
final AbilitySub subAb = sa.getSubAbility();
|
||||||
if (subAb == null) {
|
return subAb == null || chkDrawbackWithSubs(aiPlayer, subAb) || mandatory;
|
||||||
if (decision.willingToPlay()) {
|
}
|
||||||
return decision;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
decision = chkDrawbackWithSubs(aiPlayer, subAb);
|
|
||||||
if (decision.willingToPlay()) {
|
|
||||||
return decision;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mandatory) {
|
|
||||||
return new AiAbilityDecision(50, AiPlayDecision.MandatoryPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the AI decision to play a triggered SpellAbility
|
* Handles the AI decision to play a triggered SpellAbility
|
||||||
*/
|
*/
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
||||||
AiAbilityDecision decision = canPlayWithoutRestrict(aiPlayer, sa);
|
if (canPlayWithoutRestrict(aiPlayer, sa) && (!mandatory || sa.isTargetNumberValid())) {
|
||||||
if (decision.willingToPlay() && (!mandatory || sa.isTargetNumberValid())) {
|
return true;
|
||||||
// This is a weird check. Why do we care if its not mandatory if we WANT to do it?
|
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// not mandatory, short way out
|
// not mandatory, short way out
|
||||||
if (!mandatory) {
|
if (!mandatory) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalid target might prevent it
|
// invalid target might prevent it
|
||||||
@@ -230,13 +220,82 @@ public abstract class SpellAbilityAi {
|
|||||||
if (sa.canTarget(p)) {
|
if (sa.canTarget(p)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(p);
|
sa.getTargets().add(p);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the AI decision to play a sub-SpellAbility
|
||||||
|
*/
|
||||||
|
public boolean chkAIDrawback(final SpellAbility sa, final Player aiPlayer) {
|
||||||
|
// sub-SpellAbility might use targets too
|
||||||
|
if (sa.usesTargeting()) {
|
||||||
|
// no Candidates, no adding to Stack
|
||||||
|
if (!sa.getTargetRestrictions().hasCandidates(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// but if it does, it should override this function
|
||||||
|
System.err.println("Warning: default (ie. inherited from base class) implementation of chkAIDrawback is used by " + sa.getHostCard().getName() + " for " + this.getClass().getName() + ". Consider declaring an overloaded method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* isSorcerySpeed.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param sa
|
||||||
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
|
* @return a boolean.
|
||||||
|
*/
|
||||||
|
protected static boolean isSorcerySpeed(final SpellAbility sa, Player ai) {
|
||||||
|
return (sa.getRootAbility().isSpell() && sa.getHostCard().isSorcery())
|
||||||
|
|| (sa.getRootAbility().isActivatedAbility() && sa.getRootAbility().getRestrictions().isSorcerySpeed())
|
||||||
|
|| (sa.getRootAbility().isAdventure() && sa.getHostCard().getState(CardStateName.Adventure).getType().isSorcery())
|
||||||
|
|| (sa.isPwAbility() && !sa.withFlash(sa.getHostCard(), ai));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* playReusable.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param sa
|
||||||
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
|
* @return a boolean.
|
||||||
|
*/
|
||||||
|
protected static boolean playReusable(final Player ai, final SpellAbility sa) {
|
||||||
|
PhaseHandler phase = ai.getGame().getPhaseHandler();
|
||||||
|
|
||||||
|
// TODO probably also consider if winter orb or similar are out
|
||||||
|
|
||||||
|
if (sa instanceof AbilitySub) {
|
||||||
|
return true; // This is only true for Drawbacks and triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sa.getPayCosts().isReusuableResource()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ComputerUtil.playImmediately(ai, sa)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sa.isPwAbility() && phase.is(PhaseType.MAIN2)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (sa.isSpell() && !sa.isBuyback()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return phase.is(PhaseType.END_OF_TURN) && phase.getNextTurn().equals(ai);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,35 +304,9 @@ public abstract class SpellAbilityAi {
|
|||||||
* @param ab
|
* @param ab
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public AiAbilityDecision chkDrawbackWithSubs(Player aiPlayer, AbilitySub ab) {
|
public boolean chkDrawbackWithSubs(Player aiPlayer, AbilitySub ab) {
|
||||||
final AbilitySub subAb = ab.getSubAbility();
|
final AbilitySub subAb = ab.getSubAbility();
|
||||||
AiAbilityDecision decision = SpellApiToAi.Converter.get(ab).chkDrawback(ab, aiPlayer);
|
return SpellApiToAi.Converter.get(ab).chkAIDrawback(ab, aiPlayer) && (subAb == null || chkDrawbackWithSubs(aiPlayer, subAb));
|
||||||
if (!decision.willingToPlay()) {
|
|
||||||
return decision;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subAb == null) {
|
|
||||||
return decision;
|
|
||||||
}
|
|
||||||
|
|
||||||
return chkDrawbackWithSubs(aiPlayer, subAb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the AI decision to play a sub-SpellAbility
|
|
||||||
*/
|
|
||||||
public AiAbilityDecision chkDrawback(final SpellAbility sa, final Player aiPlayer) {
|
|
||||||
// sub-SpellAbility might use targets too
|
|
||||||
if (sa.usesTargeting()) {
|
|
||||||
// no Candidates, no adding to Stack
|
|
||||||
if (!sa.getTargetRestrictions().hasCandidates(sa)) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
// but if it does, it should override this function
|
|
||||||
System.err.println("Warning: default (ie. inherited from base class) implementation of chkAIDrawback is used by " + sa.getHostCard().getName() + " for " + this.getClass().getName() + ". Consider declaring an overloaded method");
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
||||||
@@ -281,6 +314,25 @@ public abstract class SpellAbilityAi {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean willPayUnlessCost(SpellAbility sa, Player payer, Cost cost, boolean alreadyPaid, FCollectionView<Player> payers) {
|
||||||
|
final Card source = sa.getHostCard();
|
||||||
|
final String aiLogic = sa.getParam("UnlessAI");
|
||||||
|
boolean payNever = "Never".equals(aiLogic);
|
||||||
|
boolean isMine = sa.getActivatingPlayer().equals(payer);
|
||||||
|
|
||||||
|
if (payNever) { return false; }
|
||||||
|
|
||||||
|
// AI will only pay when it's not already payed and only opponents abilities
|
||||||
|
if (alreadyPaid || (payers.size() > 1 && isMine)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ComputerUtilCost.checkLifeCost(payer, cost, source, 4, sa)
|
||||||
|
&& ComputerUtilCost.checkDamageCost(payer, cost, source, 4, sa)
|
||||||
|
&& (isMine || ComputerUtilCost.checkSacrificeCost(payer, cost, source, sa))
|
||||||
|
&& (isMine || ComputerUtilCost.checkDiscardCost(payer, cost, source, sa));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends GameEntity> T chooseSingleEntity(Player ai, SpellAbility sa, Collection<T> options, boolean isOptional, Player targetedPlayer, Map<String, Object> params) {
|
public <T extends GameEntity> T chooseSingleEntity(Player ai, SpellAbility sa, Collection<T> options, boolean isOptional, Player targetedPlayer, Map<String, Object> params) {
|
||||||
boolean hasPlayer = false;
|
boolean hasPlayer = false;
|
||||||
@@ -360,46 +412,6 @@ public abstract class SpellAbilityAi {
|
|||||||
return MyRandom.getRandom().nextBoolean();
|
return MyRandom.getRandom().nextBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the AI is willing to pay for additional costs
|
|
||||||
* <p>
|
|
||||||
* Evaluated costs are: life, discard, sacrifice and counter-removal
|
|
||||||
*/
|
|
||||||
protected boolean willPayCosts(final Player ai, final SpellAbility sa, final Cost cost, final Card source) {
|
|
||||||
if (!ComputerUtilCost.checkLifeCost(ai, cost, source, 4, sa)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!ComputerUtilCost.checkDiscardCost(ai, cost, source, sa)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!ComputerUtilCost.checkSacrificeCost(ai, cost, source, sa)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!ComputerUtilCost.checkRemoveCounterCost(cost, source, sa)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean willPayUnlessCost(SpellAbility sa, Player payer, Cost cost, boolean alreadyPaid, FCollectionView<Player> payers) {
|
|
||||||
final Card source = sa.getHostCard();
|
|
||||||
final String aiLogic = sa.getParam("UnlessAI");
|
|
||||||
boolean payNever = "Never".equals(aiLogic);
|
|
||||||
boolean isMine = sa.getActivatingPlayer().equals(payer);
|
|
||||||
|
|
||||||
if (payNever) { return false; }
|
|
||||||
|
|
||||||
// AI will only pay when it's not already payed and only opponents abilities
|
|
||||||
if (alreadyPaid || (payers.size() > 1 && isMine)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ComputerUtilCost.checkLifeCost(payer, cost, source, 4, sa)
|
|
||||||
&& ComputerUtilCost.checkDamageCost(payer, cost, source, 4, sa)
|
|
||||||
&& (isMine || ComputerUtilCost.checkSacrificeCost(payer, cost, source, sa))
|
|
||||||
&& (isMine || ComputerUtilCost.checkDiscardCost(payer, cost, source, sa));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OptionalCostValue> chooseOptionalCosts(SpellAbility chosen, Player player, List<OptionalCostValue> optionalCostValues) {
|
public List<OptionalCostValue> chooseOptionalCosts(SpellAbility chosen, Player player, List<OptionalCostValue> optionalCostValues) {
|
||||||
List<OptionalCostValue> chosenOptCosts = Lists.newArrayList();
|
List<OptionalCostValue> chosenOptCosts = Lists.newArrayList();
|
||||||
Cost costSoFar = chosen.getPayCosts().copy();
|
Cost costSoFar = chosen.getPayCosts().copy();
|
||||||
@@ -409,14 +421,14 @@ public abstract class SpellAbilityAi {
|
|||||||
Cost fullCost = opt.getCost().copy().add(costSoFar);
|
Cost fullCost = opt.getCost().copy().add(costSoFar);
|
||||||
SpellAbility fullCostSa = chosen.copyWithDefinedCost(fullCost);
|
SpellAbility fullCostSa = chosen.copyWithDefinedCost(fullCost);
|
||||||
|
|
||||||
|
// Playability check for Kicker
|
||||||
if (opt.getType() == OptionalCost.Kicker1 || opt.getType() == OptionalCost.Kicker2) {
|
if (opt.getType() == OptionalCost.Kicker1 || opt.getType() == OptionalCost.Kicker2) {
|
||||||
SpellAbility kickedSaCopy = fullCostSa.copy();
|
SpellAbility kickedSaCopy = fullCostSa.copy();
|
||||||
kickedSaCopy.addOptionalCost(opt.getType());
|
kickedSaCopy.addOptionalCost(opt.getType());
|
||||||
Card copy = CardCopyService.getLKICopy(chosen.getHostCard());
|
Card copy = CardCopyService.getLKICopy(chosen.getHostCard());
|
||||||
copy.setCastSA(kickedSaCopy);
|
copy.setCastSA(kickedSaCopy);
|
||||||
if (ComputerUtilCard.checkNeedsToPlayReqs(copy, kickedSaCopy) != AiPlayDecision.WillPlay) {
|
if (ComputerUtilCard.checkNeedsToPlayReqs(copy, kickedSaCopy) != AiPlayDecision.WillPlay) {
|
||||||
// don't choose kickers we don't want to play
|
continue; // don't choose kickers we don't want to play
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,56 +440,4 @@ public abstract class SpellAbilityAi {
|
|||||||
|
|
||||||
return chosenOptCosts;
|
return chosenOptCosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* isSorcerySpeed.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param sa
|
|
||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
|
||||||
* @return a boolean.
|
|
||||||
*/
|
|
||||||
protected static boolean isSorcerySpeed(final SpellAbility sa, Player ai) {
|
|
||||||
return (sa.getRootAbility().isSpell() && sa.getHostCard().isSorcery())
|
|
||||||
|| (sa.getRootAbility().isActivatedAbility() && sa.getRootAbility().getRestrictions().isSorcerySpeed())
|
|
||||||
|| (sa.getRootAbility().isAdventure() && sa.getHostCard().getState(CardStateName.Secondary).getType().isSorcery())
|
|
||||||
|| (sa.isPwAbility() && !sa.withFlash(sa.getHostCard(), ai));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* playReusable.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param sa
|
|
||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
|
||||||
* @return a boolean.
|
|
||||||
*/
|
|
||||||
protected static boolean playReusable(final Player ai, final SpellAbility sa) {
|
|
||||||
PhaseHandler phase = ai.getGame().getPhaseHandler();
|
|
||||||
|
|
||||||
// TODO probably also consider if winter orb or similar are out
|
|
||||||
|
|
||||||
if (sa instanceof AbilitySub) {
|
|
||||||
return true; // This is only true for Drawbacks and triggers
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sa.getPayCosts().isReusuableResource()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ComputerUtil.playImmediately(ai, sa)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sa.isPwAbility() && phase.is(PhaseType.MAIN2)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (sa.isSpell() && !sa.isBuyback()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return phase.is(PhaseType.END_OF_TURN) && phase.getNextTurn().equals(ai);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ public enum SpellApiToAi {
|
|||||||
.put(ApiType.EachDamage, DamageEachAi.class)
|
.put(ApiType.EachDamage, DamageEachAi.class)
|
||||||
.put(ApiType.Effect, EffectAi.class)
|
.put(ApiType.Effect, EffectAi.class)
|
||||||
.put(ApiType.Encode, EncodeAi.class)
|
.put(ApiType.Encode, EncodeAi.class)
|
||||||
.put(ApiType.Endure, EndureAi.class)
|
|
||||||
.put(ApiType.EndCombatPhase, EndTurnAi.class)
|
.put(ApiType.EndCombatPhase, EndTurnAi.class)
|
||||||
.put(ApiType.EndTurn, EndTurnAi.class)
|
.put(ApiType.EndTurn, EndTurnAi.class)
|
||||||
.put(ApiType.ExchangeLife, LifeExchangeAi.class)
|
.put(ApiType.ExchangeLife, LifeExchangeAi.class)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -10,6 +8,7 @@ import forge.game.player.Player;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -17,69 +16,78 @@ import java.util.Map;
|
|||||||
public class ActivateAbilityAi extends SpellAbilityAi {
|
public class ActivateAbilityAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
|
// AI cannot use this properly until he can use SAs during Humans turn
|
||||||
|
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Player opp = ai.getStrongestOpponent();
|
final Player opp = ai.getStrongestOpponent();
|
||||||
|
|
||||||
List<Card> list = CardLists.getType(opp.getCardsIn(ZoneType.Battlefield), sa.getParamOrDefault("Type", "Card"));
|
List<Card> list = CardLists.getType(opp.getCardsIn(ZoneType.Battlefield), sa.getParamOrDefault("Type", "Card"));
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
||||||
|
|
||||||
if (!defined.contains(opp)) {
|
if (!defined.contains(opp)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (sa.canTarget(opp)) {
|
if (sa.canTarget(opp)) {
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.checkApiLogic(ai, sa);
|
boolean randomReturn = MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
|
return randomReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Player opp = ai.getStrongestOpponent();
|
final Player opp = ai.getStrongestOpponent();
|
||||||
|
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
if (null == tgt) {
|
if (null == tgt) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
||||||
if (defined.contains(opp)) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return defined.contains(opp);
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
|
// AI cannot use this properly until he can use SAs during Humans turn
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
|
boolean randomReturn = true;
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
||||||
|
|
||||||
if (defined.contains(ai)) {
|
if (defined.contains(ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(ai.getWeakestOpponent());
|
sa.getTargets().add(ai.getWeakestOpponent());
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
|
return randomReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
@@ -13,8 +11,8 @@ import forge.game.spellability.SpellAbility;
|
|||||||
public class AddPhaseAi extends SpellAbilityAi {
|
public class AddPhaseAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -40,7 +38,7 @@ import java.util.List;
|
|||||||
public class AddTurnAi extends SpellAbilityAi {
|
public class AddTurnAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
Player opp = targetableOpps.min(PlayerPredicates.compareByLife());
|
Player opp = targetableOpps.min(PlayerPredicates.compareByLife());
|
||||||
|
|
||||||
@@ -49,41 +47,41 @@ public class AddTurnAi extends SpellAbilityAi {
|
|||||||
if (sa.canTarget(ai) && (mandatory || !ai.getGame().getReplacementHandler().wouldExtraTurnBeSkipped(ai))) {
|
if (sa.canTarget(ai) && (mandatory || !ai.getGame().getReplacementHandler().wouldExtraTurnBeSkipped(ai))) {
|
||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
} else if (mandatory) {
|
} else if (mandatory) {
|
||||||
for (final Player ally : ai.getAllies()) {
|
for (final Player ally : ai.getAllies()) {
|
||||||
if (sa.canTarget(ally)) {
|
if (sa.canTarget(ally)) {
|
||||||
sa.getTargets().add(ally);
|
sa.getTargets().add(ally);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sa.getTargetRestrictions().isMinTargetsChosen(sa.getHostCard(), sa) && opp != null) {
|
if (!sa.getTargetRestrictions().isMinTargetsChosen(sa.getHostCard(), sa) && opp != null) {
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final List<Player> tgtPlayers = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa);
|
final List<Player> tgtPlayers = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa);
|
||||||
for (final Player p : tgtPlayers) {
|
for (final Player p : tgtPlayers) {
|
||||||
if (p.isOpponentOf(ai) && !mandatory) {
|
if (p.isOpponentOf(ai) && !mandatory) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: improve ai for Sage of Hours
|
// TODO: improve ai for Sage of Hours
|
||||||
if (!StringUtils.isNumeric(sa.getParam("NumTurns"))) {
|
return StringUtils.isNumeric(sa.getParam("NumTurns"));
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
// not sure if the AI should be playing with cards that give the
|
||||||
}
|
// Human more turns.
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
return doTriggerNoCost(aiPlayer, sa, false);
|
return doTriggerAINoCost(aiPlayer, sa, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,30 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
import forge.game.card.CardPredicates;
|
import forge.game.card.CardPredicates;
|
||||||
|
import forge.game.phase.PhaseHandler;
|
||||||
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
|
||||||
public class AdvanceCrankAi extends SpellAbilityAi {
|
public class AdvanceCrankAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
int nextSprocket = (ai.getCrankCounter() % 3) + 1;
|
int nextSprocket = (ai.getCrankCounter() % 3) + 1;
|
||||||
int crankCount = CardLists.count(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.isContraptionOnSprocket(nextSprocket));
|
int crankCount = CardLists.count(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.isContraptionOnSprocket(nextSprocket));
|
||||||
if (crankCount < 2) {
|
//Could evaluate whether we actually want to crank those, but this is probably fine for now.
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
if(crankCount < 2)
|
||||||
}
|
return false;
|
||||||
return super.canPlay(ai, sa);
|
return super.canPlayAI(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph, String logic) {
|
||||||
|
if(logic.equals("AtOppEOT"))
|
||||||
|
return ph.getNextTurn() == ai && ph.is(PhaseType.END_OF_TURN);
|
||||||
|
|
||||||
|
return super.checkPhaseRestrictions(ai, sa, ph, logic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -18,7 +16,7 @@ import java.util.Map;
|
|||||||
public class AlterAttributeAi extends SpellAbilityAi {
|
public class AlterAttributeAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
boolean activate = Boolean.parseBoolean(sa.getParamOrDefault("Activate", "true"));
|
boolean activate = Boolean.parseBoolean(sa.getParamOrDefault("Activate", "true"));
|
||||||
String[] attributes = sa.getParam("Attributes").split(",");
|
String[] attributes = sa.getParam("Attributes").split(",");
|
||||||
@@ -26,7 +24,7 @@ public class AlterAttributeAi extends SpellAbilityAi {
|
|||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
// TODO add targeting logic
|
// TODO add targeting logic
|
||||||
// needed for Suspected
|
// needed for Suspected
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Card> defined = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
final List<Card> defined = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
||||||
@@ -38,7 +36,7 @@ public class AlterAttributeAi extends SpellAbilityAi {
|
|||||||
case "Solved":
|
case "Solved":
|
||||||
// there is currently no effect that would un-solve something
|
// there is currently no effect that would un-solve something
|
||||||
if (!c.isSolved() && activate) {
|
if (!c.isSolved() && activate) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Suspect":
|
case "Suspect":
|
||||||
@@ -46,21 +44,21 @@ public class AlterAttributeAi extends SpellAbilityAi {
|
|||||||
// is Suspected good or bad?
|
// is Suspected good or bad?
|
||||||
// currently Suspected is better
|
// currently Suspected is better
|
||||||
if (!activate) {
|
if (!activate) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
case "Saddle":
|
case "Saddle":
|
||||||
case "Saddled":
|
case "Saddled":
|
||||||
// AI should not try to Saddle again?
|
// AI should not try to Saddle again?
|
||||||
if (c.isSaddled()) {
|
if (c.isSaddled()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerActionConfirmMode;
|
import forge.game.player.PlayerActionConfirmMode;
|
||||||
@@ -14,8 +13,8 @@ public class AlwaysPlayAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package forge.ai.ability;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -21,28 +19,24 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class AmassAi extends SpellAbilityAi {
|
public class AmassAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, final SpellAbility sa) {
|
||||||
CardCollection aiArmies = CardLists.getType(ai.getCardsIn(ZoneType.Battlefield), "Army");
|
CardCollection aiArmies = CardLists.getType(ai.getCardsIn(ZoneType.Battlefield), "Army");
|
||||||
Card host = sa.getHostCard();
|
Card host = sa.getHostCard();
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
|
|
||||||
if (!aiArmies.isEmpty()) {
|
if (!aiArmies.isEmpty()) {
|
||||||
if (aiArmies.anyMatch(CardPredicates.canReceiveCounters(CounterEnumType.P1P1))) {
|
return aiArmies.anyMatch(CardPredicates.canReceiveCounters(CounterEnumType.P1P1));
|
||||||
// If AI has an Army that can receive counters, play the ability
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// AI has Armies but none can receive counters, so don't play
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactGame);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final String type = sa.getParam("Type");
|
final String type = sa.getParam("Type");
|
||||||
final String tokenScript = "b_0_0_" + sa.getOriginalParam("Type").toLowerCase() + "_army";
|
StringBuilder sb = new StringBuilder("b_0_0_");
|
||||||
|
sb.append(sa.getOriginalParam("Type").toLowerCase()).append("_army");
|
||||||
|
final String tokenScript = sb.toString();
|
||||||
final int amount = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("Num", "1"), sa);
|
final int amount = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("Num", "1"), sa);
|
||||||
|
|
||||||
Card token = TokenInfo.getProtoType(tokenScript, sa, ai, false);
|
Card token = TokenInfo.getProtoType(tokenScript, sa, ai, false);
|
||||||
|
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
token.setController(ai, 0);
|
token.setController(ai, 0);
|
||||||
@@ -69,11 +63,7 @@ public class AmassAi extends SpellAbilityAi {
|
|||||||
//reset static abilities
|
//reset static abilities
|
||||||
game.getAction().checkStaticAbilities(false);
|
game.getAction().checkStaticAbilities(false);
|
||||||
|
|
||||||
if (result) {
|
return result;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,12 +82,8 @@ public class AmassAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || checkApiLogic(ai, sa);
|
||||||
return new AiAbilityDecision(50, AiPlayDecision.MandatoryPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return checkApiLogic(ai, sa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import forge.game.spellability.SpellAbility;
|
|||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
import forge.game.staticability.StaticAbilityContinuous;
|
import forge.game.staticability.StaticAbilityContinuous;
|
||||||
import forge.game.staticability.StaticAbilityLayer;
|
import forge.game.staticability.StaticAbilityLayer;
|
||||||
import forge.game.staticability.StaticAbilityMode;
|
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.FileSection;
|
import forge.util.FileSection;
|
||||||
import forge.util.collect.FCollectionView;
|
import forge.util.collect.FCollectionView;
|
||||||
@@ -142,129 +141,130 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Game game = aiPlayer.getGame();
|
final Game game = aiPlayer.getGame();
|
||||||
final PhaseHandler ph = game.getPhaseHandler();
|
final PhaseHandler ph = game.getPhaseHandler();
|
||||||
|
if (!sa.metConditions() && sa.getSubAbility() == null) {
|
||||||
|
return false; // what is this for?
|
||||||
|
}
|
||||||
if (!game.getStack().isEmpty() && game.getStack().peekAbility().getApi() == ApiType.Sacrifice) {
|
if (!game.getStack().isEmpty() && game.getStack().peekAbility().getApi() == ApiType.Sacrifice) {
|
||||||
// Should I animate a card before i have to sacrifice something better?
|
|
||||||
if (!isAnimatedThisTurn(aiPlayer, source)) {
|
if (!isAnimatedThisTurn(aiPlayer, source)) {
|
||||||
rememberAnimatedThisTurn(aiPlayer, source);
|
rememberAnimatedThisTurn(aiPlayer, source);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ResponseToStackResolve);
|
return true; // interrupt sacrifice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ComputerUtilCost.checkTapTypeCost(aiPlayer, sa.getPayCosts(), source, sa, new CardCollection())) {
|
if (!ComputerUtilCost.checkTapTypeCost(aiPlayer, sa.getPayCosts(), source, sa, new CardCollection())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CostNotAcceptable);
|
return false; // prevent crewing with equal or better creatures
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.costHasManaX() && sa.getSVar("X").equals("Count$xPaid")) {
|
if (sa.costHasManaX() && sa.getSVar("X").equals("Count$xPaid")) {
|
||||||
|
// Set PayX here to maximum value.
|
||||||
final int xPay = ComputerUtilCost.getMaxXValue(sa, aiPlayer, sa.isTrigger());
|
final int xPay = ComputerUtilCost.getMaxXValue(sa, aiPlayer, sa.isTrigger());
|
||||||
|
|
||||||
sa.setXManaCostPaid(xPay);
|
sa.setXManaCostPaid(xPay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
final List<Card> defined = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
||||||
return animateTgtAI(sa);
|
boolean bFlag = false;
|
||||||
}
|
boolean givesHaste = sa.hasParam("Keywords") && sa.getParam("Keywords").contains("Haste");
|
||||||
|
for (final Card c : defined) {
|
||||||
|
bFlag |= !c.isCreature() && !c.isTapped()
|
||||||
|
&& (!c.hasSickness() || givesHaste || !ph.isPlayerTurn(aiPlayer))
|
||||||
|
&& !c.isEquipping();
|
||||||
|
|
||||||
final List<Card> defined = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
// for creatures that could be improved (like Figure of Destiny)
|
||||||
boolean bFlag = false;
|
if (!bFlag && c.isCreature() && ("Permanent".equals(sa.getParam("Duration")) || (!c.isTapped() && !c.isSick()))) {
|
||||||
boolean givesHaste = sa.hasParam("Keywords") && sa.getParam("Keywords").contains("Haste");
|
int power = -5;
|
||||||
for (final Card c : defined) {
|
if (sa.hasParam("Power")) {
|
||||||
bFlag |= !c.isCreature() && !c.isTapped()
|
power = AbilityUtils.calculateAmount(c, sa.getParam("Power"), sa);
|
||||||
&& (!c.hasSickness() || givesHaste || !ph.isPlayerTurn(aiPlayer))
|
}
|
||||||
&& !c.isEquipping();
|
int toughness = -5;
|
||||||
|
if (sa.hasParam("Toughness")) {
|
||||||
// for creatures that could be improved (like Figure of Destiny)
|
toughness = AbilityUtils.calculateAmount(c, sa.getParam("Toughness"), sa);
|
||||||
if (!bFlag && c.isCreature() && ("Permanent".equals(sa.getParam("Duration")) || (!c.isTapped() && !c.isSick()))) {
|
}
|
||||||
int power = -5;
|
if (sa.hasParam("Keywords")) {
|
||||||
if (sa.hasParam("Power")) {
|
for (String keyword : sa.getParam("Keywords").split(" & ")) {
|
||||||
power = AbilityUtils.calculateAmount(c, sa.getParam("Power"), sa);
|
if (!c.hasKeyword(keyword)) {
|
||||||
}
|
bFlag = true;
|
||||||
int toughness = -5;
|
}
|
||||||
if (sa.hasParam("Toughness")) {
|
|
||||||
toughness = AbilityUtils.calculateAmount(c, sa.getParam("Toughness"), sa);
|
|
||||||
}
|
|
||||||
if (sa.hasParam("Keywords")) {
|
|
||||||
for (String keyword : sa.getParam("Keywords").split(" & ")) {
|
|
||||||
if (!c.hasKeyword(keyword)) {
|
|
||||||
bFlag = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (power + toughness > c.getCurrentPower() + c.getCurrentToughness()) {
|
||||||
if (power + toughness > c.getCurrentPower() + c.getCurrentToughness()) {
|
|
||||||
if (!c.isTapped() || (ph.inCombat() && game.getCombat().isAttacking(c))) {
|
|
||||||
bFlag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isSorcerySpeed(sa, aiPlayer) && !"Permanent".equals(sa.getParam("Duration"))) {
|
|
||||||
if (sa.isCrew() && c.isCreature()) {
|
|
||||||
// Do not try to crew a vehicle which is already a creature
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
Card animatedCopy = becomeAnimated(c, sa);
|
|
||||||
if (ph.isPlayerTurn(aiPlayer)
|
|
||||||
&& !ComputerUtilCard.doesSpecifiedCreatureAttackAI(aiPlayer, animatedCopy)) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
|
||||||
}
|
|
||||||
if (ph.getPlayerTurn().isOpponentOf(aiPlayer)
|
|
||||||
&& !ComputerUtilCard.doesSpecifiedCreatureBlock(aiPlayer, animatedCopy)) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.DoesntImpactCombat);
|
|
||||||
}
|
|
||||||
// also check if maybe there are static effects applied to the animated copy that would matter
|
|
||||||
// (e.g. Myth Realized)
|
|
||||||
if (animatedCopy.getCurrentPower() + animatedCopy.getCurrentToughness() >
|
|
||||||
c.getCurrentPower() + c.getCurrentToughness()) {
|
|
||||||
if (!isAnimatedThisTurn(aiPlayer, source)) {
|
|
||||||
if (!c.isTapped() || (ph.inCombat() && game.getCombat().isAttacking(c))) {
|
if (!c.isTapped() || (ph.inCombat() && game.getCombat().isAttacking(c))) {
|
||||||
bFlag = true;
|
bFlag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isSorcerySpeed(sa, aiPlayer) && !"Permanent".equals(sa.getParam("Duration"))) {
|
||||||
|
if (sa.isCrew() && c.isCreature()) {
|
||||||
|
// Do not try to crew a vehicle which is already a creature
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Card animatedCopy = becomeAnimated(c, sa);
|
||||||
|
if (ph.isPlayerTurn(aiPlayer)
|
||||||
|
&& !ComputerUtilCard.doesSpecifiedCreatureAttackAI(aiPlayer, animatedCopy)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ph.getPlayerTurn().isOpponentOf(aiPlayer)
|
||||||
|
&& !ComputerUtilCard.doesSpecifiedCreatureBlock(aiPlayer, animatedCopy)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// also check if maybe there are static effects applied to the animated copy that would matter
|
||||||
|
// (e.g. Myth Realized)
|
||||||
|
if (animatedCopy.getCurrentPower() + animatedCopy.getCurrentToughness() >
|
||||||
|
c.getCurrentPower() + c.getCurrentToughness()) {
|
||||||
|
if (!isAnimatedThisTurn(aiPlayer, sa.getHostCard())) {
|
||||||
|
if (!c.isTapped() || (ph.inCombat() && game.getCombat().isAttacking(c))) {
|
||||||
|
bFlag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (bFlag) {
|
||||||
|
rememberAnimatedThisTurn(aiPlayer, sa.getHostCard());
|
||||||
|
}
|
||||||
|
return bFlag; // All of the defined stuff is animated, not very useful
|
||||||
|
} else {
|
||||||
|
sa.resetTargets();
|
||||||
|
return animateTgtAI(sa);
|
||||||
}
|
}
|
||||||
if (bFlag) {
|
|
||||||
rememberAnimatedThisTurn(aiPlayer, source);
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return animateTgtAI(sa);
|
return animateTgtAI(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
AiAbilityDecision decision;
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
decision = animateTgtAI(sa);
|
if(animateTgtAI(sa))
|
||||||
if (decision.willingToPlay()) {
|
return true;
|
||||||
return decision;
|
else if (!mandatory)
|
||||||
} else if (!mandatory) {
|
return false;
|
||||||
return decision;
|
else {
|
||||||
} else {
|
|
||||||
// fallback if animate is mandatory
|
// fallback if animate is mandatory
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
List<Card> list = CardUtil.getValidCardsToTarget(sa);
|
List<Card> list = CardUtil.getValidCardsToTarget(sa);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return decision;
|
return false;
|
||||||
}
|
}
|
||||||
Card toAnimate = ComputerUtilCard.getWorstAI(list);
|
Card toAnimate = ComputerUtilCard.getWorstAI(list);
|
||||||
rememberAnimatedThisTurn(aiPlayer, toAnimate);
|
rememberAnimatedThisTurn(aiPlayer, toAnimate);
|
||||||
sa.getTargets().add(toAnimate);
|
sa.getTargets().add(toAnimate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -272,14 +272,9 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
return player.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2);
|
return player.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision animateTgtAI(final SpellAbility sa) {
|
private boolean animateTgtAI(final SpellAbility sa) {
|
||||||
if (sa.getMaxTargets() == 0) {
|
|
||||||
// this happens if an optional cost is skipped, e.g. Brave the Wilds
|
|
||||||
return new AiAbilityDecision(80, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
final Player ai = sa.getActivatingPlayer();
|
final Player ai = sa.getActivatingPlayer();
|
||||||
final Game game = ai.getGame();
|
final PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||||
final PhaseHandler ph = game.getPhaseHandler();
|
|
||||||
final String logic = sa.getParamOrDefault("AILogic", "");
|
final String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
final boolean alwaysActivatePWAbility = sa.isPwAbility()
|
final boolean alwaysActivatePWAbility = sa.isPwAbility()
|
||||||
&& sa.getPayCosts().hasSpecificCostType(CostPutCounter.class)
|
&& sa.getPayCosts().hasSpecificCostType(CostPutCounter.class)
|
||||||
@@ -291,13 +286,15 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
types.addAll(Arrays.asList(sa.getParam("Types").split(",")));
|
types.addAll(Arrays.asList(sa.getParam("Types").split(",")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Game game = ai.getGame();
|
||||||
CardCollection list = CardLists.getTargetableCards(game.getCardsIn(ZoneType.Battlefield), sa);
|
CardCollection list = CardLists.getTargetableCards(game.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
|
|
||||||
|
// Filter AI-specific targets if provided
|
||||||
list = ComputerUtil.filterAITgts(sa, ai, list, false);
|
list = ComputerUtil.filterAITgts(sa, ai, list, false);
|
||||||
|
|
||||||
// list is empty, no possible targets
|
// list is empty, no possible targets
|
||||||
if (list.isEmpty() && !alwaysActivatePWAbility) {
|
if (list.isEmpty() && !alwaysActivatePWAbility) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// something is used for animate into creature
|
// something is used for animate into creature
|
||||||
@@ -364,7 +361,7 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// data is empty, no good targets
|
// data is empty, no good targets
|
||||||
if (data.isEmpty() && !alwaysActivatePWAbility) {
|
if (data.isEmpty() && !alwaysActivatePWAbility) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the best creature to be animated
|
// get the best creature to be animated
|
||||||
@@ -387,18 +384,17 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
holdAnimatedTillMain2(ai, worst);
|
holdAnimatedTillMain2(ai, worst);
|
||||||
if (!ComputerUtilMana.canPayManaCost(sa, ai, 0, sa.isTrigger())) {
|
if (!ComputerUtilMana.canPayManaCost(sa, ai, 0, sa.isTrigger())) {
|
||||||
releaseHeldTillMain2(ai, worst);
|
releaseHeldTillMain2(ai, worst);
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rememberAnimatedThisTurn(ai, worst);
|
rememberAnimatedThisTurn(ai, worst);
|
||||||
sa.getTargets().add(worst);
|
sa.getTargets().add(worst);
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logic.equals("SetPT")) {
|
if (logic.equals("SetPT")) {
|
||||||
// TODO: 1. Teach the AI to use this to save the creature from direct damage;
|
// TODO: 1. Teach the AI to use this to save the creature from direct damage; 2. Determine the best target in a smarter way?
|
||||||
// 2. Determine the best target in a smarter way?
|
|
||||||
Card worst = ComputerUtilCard.getWorstCreatureAI(ai.getCreaturesInPlay());
|
Card worst = ComputerUtilCard.getWorstCreatureAI(ai.getCreaturesInPlay());
|
||||||
Card buffed = becomeAnimated(worst, sa);
|
Card buffed = becomeAnimated(worst, sa);
|
||||||
|
|
||||||
@@ -406,7 +402,7 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
&& (buffed.getNetPower() - worst.getNetPower() >= 3 || !ComputerUtilCard.doesCreatureAttackAI(ai, worst))) {
|
&& (buffed.getNetPower() - worst.getNetPower() >= 3 || !ComputerUtilCard.doesCreatureAttackAI(ai, worst))) {
|
||||||
sa.getTargets().add(worst);
|
sa.getTargets().add(worst);
|
||||||
rememberAnimatedThisTurn(ai, worst);
|
rememberAnimatedThisTurn(ai, worst);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,7 +414,7 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
boolean isValuableAttacker = ph.is(PhaseType.MAIN1, ai) && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, animated);
|
boolean isValuableAttacker = ph.is(PhaseType.MAIN1, ai) && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, animated);
|
||||||
boolean isValuableBlocker = combat != null && combat.getDefendingPlayers().contains(ai) && ComputerUtilCard.doesSpecifiedCreatureBlock(ai, animated);
|
boolean isValuableBlocker = combat != null && combat.getDefendingPlayers().contains(ai) && ComputerUtilCard.doesSpecifiedCreatureBlock(ai, animated);
|
||||||
if (isValuableAttacker || isValuableBlocker)
|
if (isValuableAttacker || isValuableBlocker)
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,23 +424,25 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
if(worst != null) {
|
if(worst != null) {
|
||||||
sa.getTargets().add(worst);
|
sa.getTargets().add(worst);
|
||||||
rememberAnimatedThisTurn(ai, worst);
|
rememberAnimatedThisTurn(ai, worst);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("AITgts") && !list.isEmpty()) {
|
if (sa.hasParam("AITgts") && !list.isEmpty()) {
|
||||||
//No logic, but we do have preferences. Pick the best among those?
|
//No logic, but we do have preferences. Pick the best among those?
|
||||||
Card best = ComputerUtilCard.getBestAI(list);
|
Card best = ComputerUtilCard.getBestAI(list);
|
||||||
sa.getTargets().add(best);
|
if(best != null) {
|
||||||
rememberAnimatedThisTurn(ai, best);
|
sa.getTargets().add(best);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
rememberAnimatedThisTurn(ai, best);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is reasonable for now. Kamahl, Fist of Krosa and a sorcery or
|
// This is reasonable for now. Kamahl, Fist of Krosa and a sorcery or
|
||||||
// two are the only things
|
// two are the only things
|
||||||
// that animate a target. Those can just use AI:RemoveDeck:All 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
|
// this can do a reasonably good job of picking a good target
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Card becomeAnimated(final Card card, final SpellAbility sa) {
|
public static Card becomeAnimated(final Card card, final SpellAbility sa) {
|
||||||
@@ -564,7 +562,7 @@ public class AnimateAi extends SpellAbilityAi {
|
|||||||
CardTraitChanges traits = card.getChangedCardTraits().get(timestamp, 0);
|
CardTraitChanges traits = card.getChangedCardTraits().get(timestamp, 0);
|
||||||
if (traits != null) {
|
if (traits != null) {
|
||||||
for (StaticAbility stAb : traits.getStaticAbilities()) {
|
for (StaticAbility stAb : traits.getStaticAbilities()) {
|
||||||
if (stAb.checkMode(StaticAbilityMode.Continuous)) {
|
if ("Continuous".equals(stAb.getParam("Mode"))) {
|
||||||
for (final StaticAbilityLayer layer : stAb.getLayers()) {
|
for (final StaticAbilityLayer layer : stAb.getLayers()) {
|
||||||
StaticAbilityContinuous.applyContinuousAbility(stAb, new CardCollection(card), layer);
|
StaticAbilityContinuous.applyContinuousAbility(stAb, new CardCollection(card), layer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -11,30 +9,24 @@ import forge.game.spellability.SpellAbility;
|
|||||||
public class AnimateAllAi extends SpellAbilityAi {
|
public class AnimateAllAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
String logic = sa.getParamOrDefault("AILogic", "");
|
String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if ("CreatureAdvantage".equals(logic) && !aiPlayer.getCreaturesInPlay().isEmpty()) {
|
if ("CreatureAdvantage".equals(logic) && !aiPlayer.getCreaturesInPlay().isEmpty()) {
|
||||||
// TODO: improve this or implement a better logic for abilities like Oko, the Trickster ultimate
|
// TODO: improve this or implement a better logic for abilities like Oko, the Trickster ultimate
|
||||||
for (Card c : aiPlayer.getCreaturesInPlay()) {
|
for (Card c : aiPlayer.getCreaturesInPlay()) {
|
||||||
if (ComputerUtilCard.doesCreatureAttackAI(aiPlayer, c)) {
|
if (ComputerUtilCard.doesCreatureAttackAI(aiPlayer, c)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Always".equals(logic)) {
|
return "Always".equals(logic);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
} // end animateAllCanPlayAI()
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(aiPlayer, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return canPlay(aiPlayer, sa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCost;
|
import forge.ai.ComputerUtilCost;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.GameEntity;
|
import forge.game.GameEntity;
|
||||||
import forge.game.ability.ApiType;
|
import forge.game.ability.ApiType;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardCollectionView;
|
import forge.game.card.CardCollectionView;
|
||||||
|
import forge.game.phase.PhaseHandler;
|
||||||
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
@@ -16,32 +16,30 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AssembleContraptionAi extends SpellAbilityAi {
|
public class AssembleContraptionAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
|
//Pulls double duty as the OpenAttraction API. Same logic; usually good to do as long as we have the appropriate cards.
|
||||||
CardCollectionView deck = getDeck(ai, sa);
|
CardCollectionView deck = getDeck(ai, sa);
|
||||||
|
|
||||||
if(deck.isEmpty())
|
if(deck.isEmpty())
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
|
|
||||||
AiAbilityDecision superDecision = super.canPlay(ai, sa);
|
if(!super.canPlayAI(ai, sa))
|
||||||
if (!superDecision.willingToPlay())
|
return false;
|
||||||
return superDecision;
|
|
||||||
|
|
||||||
if ("X".equals(sa.getParam("Amount")) && sa.getSVar("X").equals("Count$xPaid")) {
|
if ("X".equals(sa.getParam("Amount")) && sa.getSVar("X").equals("Count$xPaid")) {
|
||||||
int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
xPay = Math.max(xPay, deck.size());
|
xPay = Math.max(xPay, deck.size());
|
||||||
if (xPay == 0) {
|
if (xPay == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getRootAbility().setXManaCostPaid(xPay);
|
sa.getRootAbility().setXManaCostPaid(xPay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sa.hasParam("DefinedContraption") && sa.usesTargeting()) {
|
if(sa.hasParam("DefinedContraption") && sa.usesTargeting()) {
|
||||||
if (getGoodReassembleTarget(ai, sa) == null) {
|
return getGoodReassembleTarget(ai, sa) != null;
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CardCollectionView getDeck(Player ai, SpellAbility sa) {
|
private static CardCollectionView getDeck(Player ai, SpellAbility sa) {
|
||||||
@@ -50,11 +48,11 @@ public class AssembleContraptionAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
if ("X".equals(sa.getParam("Amount")) && sa.getSVar("X").equals("Count$xPaid")) {
|
if ("X".equals(sa.getParam("Amount")) && sa.getSVar("X").equals("Count$xPaid")) {
|
||||||
int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
if (xPay == 0) {
|
if (xPay == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getRootAbility().setXManaCostPaid(xPay);
|
sa.getRootAbility().setXManaCostPaid(xPay);
|
||||||
}
|
}
|
||||||
@@ -64,7 +62,7 @@ public class AssembleContraptionAi extends SpellAbilityAi {
|
|||||||
if(target != null)
|
if(target != null)
|
||||||
sa.getTargets().add(target);
|
sa.getTargets().add(target);
|
||||||
else
|
else
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.checkApiLogic(ai, sa);
|
return super.checkApiLogic(ai, sa);
|
||||||
@@ -86,16 +84,26 @@ public class AssembleContraptionAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph, String logic) {
|
||||||
if(!mandatory && getDeck(aiPlayer, sa).isEmpty())
|
if(logic.equals("AtOppEOT"))
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return ph.getNextTurn() == ai && ph.is(PhaseType.END_OF_TURN);
|
||||||
return super.doTriggerNoCost(aiPlayer, sa, mandatory);
|
|
||||||
|
return super.checkPhaseRestrictions(ai, sa, ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
if(getDeck(aiPlayer, sa).isEmpty())
|
if(getDeck(aiPlayer, sa).isEmpty())
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
return super.chkDrawback(sa, aiPlayer);
|
|
||||||
|
return super.chkAIDrawback(sa, aiPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
|
if(!mandatory && getDeck(aiPlayer, sa).isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return super.doTriggerAINoCost(aiPlayer, sa, mandatory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
@@ -12,11 +10,11 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class AssignGroupAi extends SpellAbilityAi {
|
public class AssignGroupAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
|
||||||
// TODO: Currently this AI relies on the card-specific limiting hints (NeedsToPlay / NeedsToPlayVar),
|
// TODO: Currently this AI relies on the card-specific limiting hints (NeedsToPlay / NeedsToPlayVar),
|
||||||
// otherwise the AI considers the card playable.
|
// otherwise the AI considers the card playable.
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellAbility chooseSingleSpellAbility(Player player, SpellAbility sa, List<SpellAbility> spells, Map<String, Object> params) {
|
public SpellAbility chooseSingleSpellAbility(Player player, SpellAbility sa, List<SpellAbility> spells, Map<String, Object> params) {
|
||||||
|
|||||||
@@ -15,23 +15,20 @@ import forge.game.cost.Cost;
|
|||||||
import forge.game.cost.CostPart;
|
import forge.game.cost.CostPart;
|
||||||
import forge.game.cost.CostSacrifice;
|
import forge.game.cost.CostSacrifice;
|
||||||
import forge.game.keyword.Keyword;
|
import forge.game.keyword.Keyword;
|
||||||
import forge.game.keyword.KeywordInterface;
|
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerActionConfirmMode;
|
import forge.game.player.PlayerActionConfirmMode;
|
||||||
import forge.game.replacement.ReplacementLayer;
|
|
||||||
import forge.game.replacement.ReplacementType;
|
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
import forge.game.staticability.StaticAbilityCantAttackBlock;
|
import forge.game.staticability.StaticAbilityCantAttackBlock;
|
||||||
import forge.game.staticability.StaticAbilityMode;
|
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -45,14 +42,24 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Cost abCost = sa.getPayCosts();
|
final Cost abCost = sa.getPayCosts();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
// TODO: improve this so that the AI can use a flash aura buff as a means of killing opposing creatures
|
// TODO: improve this so that the AI can use a flash aura buff as a means of killing opposing creatures
|
||||||
// and gaining card advantage
|
// and gaining card advantage
|
||||||
if (source.hasKeyword("MayFlashSac") && !ai.canCastSorcery()) {
|
if (source.hasKeyword("MayFlashSac") && !ai.canCastSorcery()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TimingRestrictions);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (abCost != null) {
|
||||||
|
// AI currently disabled for these costs
|
||||||
|
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source.isAura() && sa.isSpell() && !source.ignoreLegendRule() && ai.isCardInPlay(source.getName())) {
|
if (source.isAura() && sa.isSpell() && !source.ignoreLegendRule() && ai.isCardInPlay(source.getName())) {
|
||||||
@@ -60,16 +67,20 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// TODO: Add some extra checks for where the AI may want to cast a replacement aura
|
// 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
|
// on another creature and keep it when the original enchanted creature is useless
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WouldDestroyLegend);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent run-away activations - first time will always return true
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach spells always have a target
|
// Attach spells always have a target
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
if (tgt != null) {
|
if (tgt != null) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
AiAbilityDecision attachDecision = attachPreference(sa, tgt, false);
|
if (!attachPreference(sa, tgt, false)) {
|
||||||
if (!attachDecision.willingToPlay()) {
|
return false;
|
||||||
return attachDecision;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +91,7 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
if ((source.hasKeyword(Keyword.FLASH) || (!ai.canCastSorcery() && sa.canCastTiming(ai)))
|
if ((source.hasKeyword(Keyword.FLASH) || (!ai.canCastSorcery() && sa.canCastTiming(ai)))
|
||||||
&& source.isAura() && advancedFlash && !doAdvancedFlashAuraLogic(ai, sa, sa.getTargetCard())) {
|
&& source.isAura() && advancedFlash && !doAdvancedFlashAuraLogic(ai, sa, sa.getTargetCard())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abCost.getTotalMana().countX() > 0 && sa.getSVar("X").equals("Count$xPaid")) {
|
if (abCost.getTotalMana().countX() > 0 && sa.getSVar("X").equals("Count$xPaid")) {
|
||||||
@@ -88,7 +99,7 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
final int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
final int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
|
|
||||||
if (xPay == 0) {
|
if (xPay == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.setXManaCostPaid(xPay);
|
sa.setXManaCostPaid(xPay);
|
||||||
@@ -98,10 +109,10 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
final SpellAbility effectExile = AbilityFactory.getAbility(source.getSVar("TrigExile"), source);
|
final SpellAbility effectExile = AbilityFactory.getAbility(source.getSVar("TrigExile"), source);
|
||||||
effectExile.setActivatingPlayer(ai);
|
effectExile.setActivatingPlayer(ai);
|
||||||
final List<Card> targets = CardUtil.getValidCardsToTarget(effectExile);
|
final List<Card> targets = CardUtil.getValidCardsToTarget(effectExile);
|
||||||
return !targets.isEmpty() ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return !targets.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doAdvancedFlashAuraLogic(Player ai, SpellAbility sa, Card attachTarget) {
|
private boolean doAdvancedFlashAuraLogic(Player ai, SpellAbility sa, Card attachTarget) {
|
||||||
@@ -119,7 +130,7 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
int power = 0, toughness = 0;
|
int power = 0, toughness = 0;
|
||||||
List<String> keywords = Lists.newArrayList();
|
List<String> keywords = Lists.newArrayList();
|
||||||
for (StaticAbility stAb : source.getStaticAbilities()) {
|
for (StaticAbility stAb : source.getStaticAbilities()) {
|
||||||
if (stAb.checkMode(StaticAbilityMode.Continuous)) {
|
if ("Continuous".equals(stAb.getParam("Mode"))) {
|
||||||
if (stAb.hasParam("AddPower")) {
|
if (stAb.hasParam("AddPower")) {
|
||||||
power += AbilityUtils.calculateAmount(source, stAb.getParam("AddPower"), stAb);
|
power += AbilityUtils.calculateAmount(source, stAb.getParam("AddPower"), stAb);
|
||||||
}
|
}
|
||||||
@@ -296,8 +307,9 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
String type = "";
|
String type = "";
|
||||||
|
|
||||||
for (final StaticAbility stAb : attachSource.getStaticAbilities()) {
|
for (final StaticAbility stAb : attachSource.getStaticAbilities()) {
|
||||||
if (stAb.checkMode(StaticAbilityMode.Continuous) && stAb.hasParam("AddType")) {
|
final Map<String, String> stab = stAb.getMapParams();
|
||||||
type = stAb.getParam("AddType");
|
if (stab.get("Mode").equals("Continuous") && stab.containsKey("AddType")) {
|
||||||
|
type = stab.get("AddType");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,39 +371,9 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
*/
|
*/
|
||||||
private static Card attachAIKeepTappedPreference(final SpellAbility sa, final List<Card> list, final boolean mandatory, final Card attachSource) {
|
private static Card attachAIKeepTappedPreference(final SpellAbility sa, final List<Card> list, final boolean mandatory, final Card attachSource) {
|
||||||
// AI For Cards like Paralyzing Grasp and Glimmerdust Nap
|
// AI For Cards like Paralyzing Grasp and Glimmerdust Nap
|
||||||
|
|
||||||
// check for ETB Trigger
|
|
||||||
boolean tapETB = isAuraSpell(sa) && attachSource.getTriggers().anyMatch(t -> {
|
|
||||||
if (t.getMode() != TriggerType.ChangesZone) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ZoneType.Battlefield.toString().equals(t.getParam("Destination"))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.hasParam("ValidCard") && !t.getParam("ValidCard").contains("Self")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpellAbility tSa = t.ensureAbility();
|
|
||||||
if (tSa == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ApiType.Tap.equals(tSa.getApi())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!"Enchanted".equals(tSa.getParam("Defined"))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
final List<Card> prefList = CardLists.filter(list, c -> {
|
final List<Card> prefList = CardLists.filter(list, c -> {
|
||||||
// Don't do Untapped Vigilance cards
|
// Don't do Untapped Vigilance cards
|
||||||
if (!tapETB && c.isCreature() && c.hasKeyword(Keyword.VIGILANCE) && c.isUntapped()) {
|
if (c.isCreature() && c.hasKeyword(Keyword.VIGILANCE) && c.isUntapped()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,9 +388,20 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// already affected
|
|
||||||
if (!c.canUntap(c.getController(), true)) {
|
if (!c.isEnchanted()) {
|
||||||
return false;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Iterable<Card> auras = c.getEnchantedBy();
|
||||||
|
for (Card aura : auras) {
|
||||||
|
SpellAbility auraSA = aura.getSpells().get(0);
|
||||||
|
if (auraSA.getApi() == ApiType.Attach) {
|
||||||
|
if ("KeepTapped".equals(auraSA.getParam("AILogic"))) {
|
||||||
|
// Don't attach multiple KeepTapped Auras to one card
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -493,29 +486,29 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
*/
|
*/
|
||||||
private static Card attachAIAnimatePreference(final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
private static Card attachAIAnimatePreference(final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
||||||
final Card attachSource) {
|
final Card attachSource) {
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Card card = null;
|
Card card = null;
|
||||||
// AI For choosing a Card to Animate.
|
// AI For choosing a Card to Animate.
|
||||||
List<Card> betterList = CardLists.getNotType(list, "Creature");
|
List<Card> betterList = CardLists.getNotType(list, "Creature");
|
||||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Animate Artifact")) {
|
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Animate Artifact")) {
|
||||||
betterList = CardLists.filter(betterList, c -> c.getCMC() > 0);
|
betterList = CardLists.filter(betterList, c -> c.getCMC() > 0);
|
||||||
card = ComputerUtilCard.getMostExpensivePermanentAI(betterList);
|
card = ComputerUtilCard.getMostExpensivePermanentAI(betterList);
|
||||||
} else {
|
} else {
|
||||||
List<Card> evenBetterList = CardLists.filter(betterList, c -> c.hasKeyword(Keyword.INDESTRUCTIBLE) || c.hasKeyword(Keyword.HEXPROOF));
|
List<Card> evenBetterList = CardLists.filter(betterList, c -> c.hasKeyword(Keyword.INDESTRUCTIBLE) || c.hasKeyword(Keyword.HEXPROOF));
|
||||||
if (!evenBetterList.isEmpty()) {
|
if (!evenBetterList.isEmpty()) {
|
||||||
betterList = evenBetterList;
|
betterList = evenBetterList;
|
||||||
}
|
}
|
||||||
evenBetterList = CardLists.filter(betterList, CardPredicates.UNTAPPED);
|
evenBetterList = CardLists.filter(betterList, CardPredicates.UNTAPPED);
|
||||||
if (!evenBetterList.isEmpty()) {
|
if (!evenBetterList.isEmpty()) {
|
||||||
betterList = evenBetterList;
|
betterList = evenBetterList;
|
||||||
}
|
}
|
||||||
evenBetterList = CardLists.filter(betterList, c -> c.getTurnInZone() != c.getGame().getPhaseHandler().getTurn());
|
evenBetterList = CardLists.filter(betterList, c -> c.getTurnInZone() != c.getGame().getPhaseHandler().getTurn());
|
||||||
if (!evenBetterList.isEmpty()) {
|
if (!evenBetterList.isEmpty()) {
|
||||||
betterList = evenBetterList;
|
betterList = evenBetterList;
|
||||||
}
|
}
|
||||||
evenBetterList = CardLists.filter(betterList, c -> {
|
evenBetterList = CardLists.filter(betterList, c -> {
|
||||||
for (final SpellAbility sa1 : c.getSpellAbilities()) {
|
for (final SpellAbility sa1 : c.getSpellAbilities()) {
|
||||||
if (sa1.isAbility() && sa1.getPayCosts().hasTapCost()) {
|
if (sa1.isAbility() && sa1.getPayCosts().hasTapCost()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -523,10 +516,10 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
if (!evenBetterList.isEmpty()) {
|
if (!evenBetterList.isEmpty()) {
|
||||||
betterList = evenBetterList;
|
betterList = evenBetterList;
|
||||||
}
|
}
|
||||||
card = ComputerUtilCard.getWorstAI(betterList);
|
card = ComputerUtilCard.getWorstAI(betterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -556,46 +549,28 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
final Card attachSource) {
|
final Card attachSource) {
|
||||||
// AI For choosing a Card to Animate.
|
// AI For choosing a Card to Animate.
|
||||||
final Player ai = sa.getActivatingPlayer();
|
final Player ai = sa.getActivatingPlayer();
|
||||||
Card attachSourceLki = null;
|
final Card attachSourceLki = CardCopyService.getLKICopy(attachSource);
|
||||||
for (Trigger t : attachSource.getTriggers()) {
|
|
||||||
if (!t.getMode().equals(TriggerType.ChangesZone)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!"Battlefield".equals(t.getParam("Destination"))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!"Card.Self".equals(t.getParam("ValidCard"))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
SpellAbility trigSa = t.ensureAbility();
|
|
||||||
SpellAbility animateSa = trigSa.findSubAbilityByType(ApiType.Animate);
|
|
||||||
if (animateSa == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
animateSa.setActivatingPlayer(sa.getActivatingPlayer());
|
|
||||||
attachSourceLki = AnimateAi.becomeAnimated(attachSource, animateSa);
|
|
||||||
}
|
|
||||||
if (attachSourceLki == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
attachSourceLki.setLastKnownZone(ai.getZone(ZoneType.Battlefield));
|
attachSourceLki.setLastKnownZone(ai.getZone(ZoneType.Battlefield));
|
||||||
final Card finalAttachSourceLki = attachSourceLki;
|
// 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, c -> {
|
List<Card> betterList = CardLists.filter(list, c -> {
|
||||||
final Card lki = CardCopyService.getLKICopy(c);
|
final Card lki = CardCopyService.getLKICopy(c);
|
||||||
// need to fake it as if lki would be on the battlefield
|
// need to fake it as if lki would be on the battlefield
|
||||||
lki.setLastKnownZone(ai.getZone(ZoneType.Battlefield));
|
lki.setLastKnownZone(ai.getZone(ZoneType.Battlefield));
|
||||||
|
|
||||||
// Reanimate Auras use "Enchant creature put onto the battlefield with CARDNAME" with Remembered
|
// Reanimate Auras use "Enchant creature put onto the battlefield with CARDNAME" with Remembered
|
||||||
finalAttachSourceLki.clearRemembered();
|
attachSourceLki.clearRemembered();
|
||||||
finalAttachSourceLki.addRemembered(lki);
|
attachSourceLki.addRemembered(lki);
|
||||||
|
|
||||||
// need to check what the cards would be on the battlefield
|
// need to check what the cards would be on the battlefield
|
||||||
// do not attach yet, that would cause Events
|
// do not attach yet, that would cause Events
|
||||||
CardCollection preList = new CardCollection(lki);
|
CardCollection preList = new CardCollection(lki);
|
||||||
preList.add(finalAttachSourceLki);
|
preList.add(attachSourceLki);
|
||||||
c.getGame().getAction().checkStaticAbilities(false, Sets.newHashSet(preList), preList);
|
c.getGame().getAction().checkStaticAbilities(false, Sets.newHashSet(preList), preList);
|
||||||
boolean result = lki.canBeAttached(finalAttachSourceLki, null);
|
boolean result = lki.canBeAttached(attachSourceLki, null);
|
||||||
|
|
||||||
//reset static abilities
|
//reset static abilities
|
||||||
c.getGame().getAction().checkStaticAbilities(false);
|
c.getGame().getAction().checkStaticAbilities(false);
|
||||||
@@ -820,45 +795,27 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
int totPower = 0;
|
int totPower = 0;
|
||||||
final List<String> keywords = new ArrayList<>();
|
final List<String> keywords = new ArrayList<>();
|
||||||
|
|
||||||
boolean cantAttack = false;
|
|
||||||
boolean cantBlock = false;
|
|
||||||
|
|
||||||
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
||||||
if (stAbility.checkMode(StaticAbilityMode.CantAttack)) {
|
final Map<String, String> stabMap = stAbility.getMapParams();
|
||||||
String valid = stAbility.getParam("ValidCard");
|
|
||||||
if (valid.contains(stCheck) || valid.contains("AttachedBy")) {
|
|
||||||
cantAttack = true;
|
|
||||||
}
|
|
||||||
} else if (stAbility.checkMode(StaticAbilityMode.CantBlock)) {
|
|
||||||
String valid = stAbility.getParam("ValidCard");
|
|
||||||
if (valid.contains(stCheck) || valid.contains("AttachedBy")) {
|
|
||||||
cantBlock = true;
|
|
||||||
}
|
|
||||||
} else if (stAbility.checkMode(StaticAbilityMode.CantBlockBy)) {
|
|
||||||
String valid = stAbility.getParam("ValidBlocker");
|
|
||||||
if (valid.contains(stCheck) || valid.contains("AttachedBy")) {
|
|
||||||
cantBlock = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stAbility.checkMode(StaticAbilityMode.Continuous)) {
|
if (!stabMap.get("Mode").equals("Continuous")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String affected = stAbility.getParam("Affected");
|
final String affected = stabMap.get("Affected");
|
||||||
|
|
||||||
if (affected == null) {
|
if (affected == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((affected.contains(stCheck) || affected.contains("AttachedBy"))) {
|
if ((affected.contains(stCheck) || affected.contains("AttachedBy"))) {
|
||||||
totToughness += AbilityUtils.calculateAmount(attachSource, stAbility.getParam("AddToughness"), sa);
|
totToughness += AbilityUtils.calculateAmount(attachSource, stabMap.get("AddToughness"), sa);
|
||||||
totPower += AbilityUtils.calculateAmount(attachSource, stAbility.getParam("AddPower"), sa);
|
totPower += AbilityUtils.calculateAmount(attachSource, stabMap.get("AddPower"), sa);
|
||||||
|
|
||||||
String kws = stAbility.getParam("AddKeyword");
|
String kws = stabMap.get("AddKeyword");
|
||||||
if (kws != null) {
|
if (kws != null) {
|
||||||
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
||||||
}
|
}
|
||||||
kws = stAbility.getParam("AddHiddenKeyword");
|
kws = stabMap.get("AddHiddenKeyword");
|
||||||
if (kws != null) {
|
if (kws != null) {
|
||||||
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
||||||
}
|
}
|
||||||
@@ -894,12 +851,6 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
prefList = CardLists.filter(prefList, c -> c.getNetPower() > 0 && ComputerUtilCombat.canAttackNextTurn(c));
|
prefList = CardLists.filter(prefList, c -> c.getNetPower() > 0 && ComputerUtilCombat.canAttackNextTurn(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cantAttack) {
|
|
||||||
prefList = CardLists.filter(prefList, c -> c.isCreature() && ComputerUtilCombat.canAttackNextTurn(c));
|
|
||||||
} else if (cantBlock) { // TODO better can block filter?
|
|
||||||
prefList = CardLists.filter(prefList, c -> c.isCreature() && !ComputerUtilCard.isUselessCreature(ai, c));
|
|
||||||
}
|
|
||||||
|
|
||||||
//some auras aren't useful in multiples
|
//some auras aren't useful in multiples
|
||||||
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
||||||
prefList = CardLists.filter(prefList,
|
prefList = CardLists.filter(prefList,
|
||||||
@@ -941,8 +892,9 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
||||||
final Card card = sa.getHostCard();
|
final Card card = sa.getHostCard();
|
||||||
|
// Check if there are any valid targets
|
||||||
List<GameObject> targets = new ArrayList<>();
|
List<GameObject> targets = new ArrayList<>();
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
if (tgt == null) {
|
if (tgt == null) {
|
||||||
@@ -954,48 +906,23 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!mandatory && card.isEquipment() && !targets.isEmpty()) {
|
if (!mandatory && card.isEquipment() && !targets.isEmpty()) {
|
||||||
Card newTarget = (Card) targets.get(0);
|
Card newTarget = (Card) targets.get(0);
|
||||||
|
//don't equip human creatures
|
||||||
if (newTarget.getController().isOpponentOf(ai)) {
|
if (newTarget.getController().isOpponentOf(ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//don't equip a worse creature
|
||||||
if (card.isEquipping()) {
|
if (card.isEquipping()) {
|
||||||
Card oldTarget = card.getEquipping();
|
Card oldTarget = card.getEquipping();
|
||||||
if (ComputerUtilCard.evaluateCreature(oldTarget) > ComputerUtilCard.evaluateCreature(newTarget)) {
|
if (ComputerUtilCard.evaluateCreature(oldTarget) > ComputerUtilCard.evaluateCreature(newTarget)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
|
||||||
boolean stacking = !card.hasSVar("NonStackingAttachEffect") || !newTarget.isEquippedBy(card.getName());
|
|
||||||
if (!stacking) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
// don't equip creatures that don't gain anything
|
||||||
|
return !card.hasSVar("NonStackingAttachEffect") || !newTarget.isEquippedBy(card.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return true;
|
||||||
public AiAbilityDecision chkDrawback(final SpellAbility sa, final Player ai) {
|
|
||||||
if (sa.isTrigger() && sa.usesTargeting()) {
|
|
||||||
CardCollection targetables = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
|
||||||
CardCollection source = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Object"), sa);
|
|
||||||
Card tgt = attachGeneralAI(ai, sa, targetables, !sa.getRootAbility().isOptionalTrigger(), source.getFirst(), null);
|
|
||||||
if (tgt != null) {
|
|
||||||
sa.resetTargets();
|
|
||||||
sa.getTargets().add(tgt);
|
|
||||||
}
|
|
||||||
if (sa.isTargetNumberValid()) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
} else if ("Remembered".equals(sa.getParam("Defined")) && sa.getParent() != null
|
|
||||||
&& sa.getParent().getApi() == ApiType.Token && sa.getParent().hasParam("RememberTokens")) {
|
|
||||||
// Living Weapon or similar
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isAuraSpell(final SpellAbility sa) {
|
|
||||||
return sa.isSpell() && sa.getHostCard().isAura();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1011,25 +938,9 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
* the mandatory
|
* the mandatory
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
private static AiAbilityDecision attachPreference(final SpellAbility sa, final TargetRestrictions tgt, final boolean mandatory) {
|
private static boolean attachPreference(final SpellAbility sa, final TargetRestrictions tgt, final boolean mandatory) {
|
||||||
GameObject o;
|
GameObject o;
|
||||||
boolean spellCanTargetPlayer = false;
|
if (tgt.canTgtPlayer()) {
|
||||||
if (isAuraSpell(sa)) {
|
|
||||||
Card source = sa.getHostCard();
|
|
||||||
if (!source.hasKeyword(Keyword.ENCHANT)) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
for (KeywordInterface ki : source.getKeywords(Keyword.ENCHANT)) {
|
|
||||||
String ko = ki.getOriginal();
|
|
||||||
String m[] = ko.split(":");
|
|
||||||
String v = m[1];
|
|
||||||
if (v.contains("Player") || v.contains("Opponent")) {
|
|
||||||
spellCanTargetPlayer = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tgt.canTgtPlayer() && (!isAuraSpell(sa) || spellCanTargetPlayer)) {
|
|
||||||
List<Player> targetable = new ArrayList<>();
|
List<Player> targetable = new ArrayList<>();
|
||||||
for (final Player player : sa.getHostCard().getGame().getPlayers()) {
|
for (final Player player : sa.getHostCard().getGame().getPlayers()) {
|
||||||
if (sa.canTarget(player)) {
|
if (sa.canTarget(player)) {
|
||||||
@@ -1042,11 +953,11 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.getTargets().add(o);
|
sa.getTargets().add(o);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1094,8 +1005,9 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
CardCollection toRemove = new CardCollection();
|
CardCollection toRemove = new CardCollection();
|
||||||
for (Trigger t : attachSource.getTriggers()) {
|
for (Trigger t : attachSource.getTriggers()) {
|
||||||
if (t.getMode() == TriggerType.ChangesZone) {
|
if (t.getMode() == TriggerType.ChangesZone) {
|
||||||
if ("Card.Self".equals(t.getParam("ValidCard"))
|
final Map<String, String> params = t.getMapParams();
|
||||||
&& "Battlefield".equals(t.getParam("Destination"))) {
|
if ("Card.Self".equals(params.get("ValidCard"))
|
||||||
|
&& "Battlefield".equals(params.get("Destination"))) {
|
||||||
SpellAbility trigSa = t.ensureAbility();
|
SpellAbility trigSa = t.ensureAbility();
|
||||||
if (trigSa != null && trigSa.getApi() == ApiType.DealDamage && "Enchanted".equals(trigSa.getParam("Defined"))) {
|
if (trigSa != null && trigSa.getApi() == ApiType.DealDamage && "Enchanted".equals(trigSa.getParam("Defined"))) {
|
||||||
for (Card target : list) {
|
for (Card target : list) {
|
||||||
@@ -1132,17 +1044,17 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
// Probably want to "weight" the list by amount of Enchantments and
|
// Probably want to "weight" the list by amount of Enchantments and
|
||||||
// choose the "lightest"
|
// choose the "lightest"
|
||||||
|
|
||||||
List<Card> betterList = CardLists.filter(magnetList, c -> CombatUtil.canAttack(c, ai.getWeakestOpponent()));
|
List<Card> betterList = CardLists.filter(magnetList, c -> CombatUtil.canAttack(c, ai.getWeakestOpponent()));
|
||||||
if (!betterList.isEmpty()) {
|
if (!betterList.isEmpty()) {
|
||||||
return ComputerUtilCard.getBestAI(betterList);
|
return ComputerUtilCard.getBestAI(betterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magnet List should not be attached when they are useless
|
// Magnet List should not be attached when they are useless
|
||||||
betterList = CardLists.filter(magnetList, c -> !ComputerUtilCard.isUselessCreature(ai, c));
|
betterList = CardLists.filter(magnetList, c -> !ComputerUtilCard.isUselessCreature(ai, c));
|
||||||
|
|
||||||
if (!betterList.isEmpty()) {
|
if (!betterList.isEmpty()) {
|
||||||
return ComputerUtilCard.getBestAI(betterList);
|
return ComputerUtilCard.getBestAI(betterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
//return ComputerUtilCard.getBestAI(magnetList);
|
//return ComputerUtilCard.getBestAI(magnetList);
|
||||||
}
|
}
|
||||||
@@ -1155,27 +1067,29 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
boolean grantingExtraBlock = false;
|
boolean grantingExtraBlock = false;
|
||||||
|
|
||||||
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
||||||
if (!stAbility.checkMode(StaticAbilityMode.Continuous)) {
|
final Map<String, String> stabMap = stAbility.getMapParams();
|
||||||
|
|
||||||
|
if (!"Continuous".equals(stabMap.get("Mode"))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String affected = stAbility.getParam("Affected");
|
final String affected = stabMap.get("Affected");
|
||||||
|
|
||||||
if (affected == null) {
|
if (affected == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (affected.contains(stCheck) || affected.contains("AttachedBy")) {
|
if (affected.contains(stCheck) || affected.contains("AttachedBy")) {
|
||||||
totToughness += AbilityUtils.calculateAmount(attachSource, stAbility.getParam("AddToughness"), stAbility);
|
totToughness += AbilityUtils.calculateAmount(attachSource, stabMap.get("AddToughness"), stAbility);
|
||||||
totPower += AbilityUtils.calculateAmount(attachSource, stAbility.getParam("AddPower"), stAbility);
|
totPower += AbilityUtils.calculateAmount(attachSource, stabMap.get("AddPower"), stAbility);
|
||||||
|
|
||||||
grantingAbilities |= stAbility.hasParam("AddAbility");
|
grantingAbilities |= stabMap.containsKey("AddAbility");
|
||||||
grantingExtraBlock |= stAbility.hasParam("CanBlockAmount") || stAbility.hasParam("CanBlockAny");
|
grantingExtraBlock |= stabMap.containsKey("CanBlockAmount") || stabMap.containsKey("CanBlockAny");
|
||||||
|
|
||||||
String kws = stAbility.getParam("AddKeyword");
|
String kws = stabMap.get("AddKeyword");
|
||||||
if (kws != null) {
|
if (kws != null) {
|
||||||
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
||||||
}
|
}
|
||||||
kws = stAbility.getParam("AddHiddenKeyword");
|
kws = stabMap.get("AddHiddenKeyword");
|
||||||
if (kws != null) {
|
if (kws != null) {
|
||||||
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
keywords.addAll(Arrays.asList(kws.split(" & ")));
|
||||||
}
|
}
|
||||||
@@ -1229,13 +1143,13 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
prefList = ComputerUtil.getSafeTargets(ai, sa, prefList);
|
prefList = ComputerUtil.getSafeTargets(ai, sa, prefList);
|
||||||
|
|
||||||
if (attachSource.isAura()) {
|
if (attachSource.isAura()) {
|
||||||
if (!attachSource.getName().equals("Daybreak Coronet")) {
|
if (!attachSource.getName().equals("Daybreak Coronet")) {
|
||||||
// TODO For Auras like Rancor, that aren't as likely to lead to
|
// TODO For Auras like Rancor, that aren't as likely to lead to
|
||||||
// card disadvantage, this check should be skipped
|
// card disadvantage, this check should be skipped
|
||||||
prefList = CardLists.filter(prefList, c -> !c.isEnchanted() || c.hasKeyword(Keyword.HEXPROOF));
|
prefList = CardLists.filter(prefList, c -> !c.isEnchanted() || c.hasKeyword(Keyword.HEXPROOF));
|
||||||
}
|
}
|
||||||
|
|
||||||
// should not attach Auras to creatures that does leave the play
|
// should not attach Auras to creatures that does leave the play
|
||||||
prefList = CardLists.filter(prefList, c -> !c.hasSVar("EndOfTurnLeavePlay"));
|
prefList = CardLists.filter(prefList, c -> !c.hasSVar("EndOfTurnLeavePlay"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1244,15 +1158,10 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
// TODO Somehow test for definitive advantage (e.g. opponent low on health, AI is attacking)
|
// TODO Somehow test for definitive advantage (e.g. opponent low on health, AI is attacking)
|
||||||
// to be able to deal the final blow with an enchanted vehicle like that
|
// to be able to deal the final blow with an enchanted vehicle like that
|
||||||
boolean canOnlyTargetCreatures = true;
|
boolean canOnlyTargetCreatures = true;
|
||||||
if (attachSource.isAura()) {
|
for (String valid : ObjectUtils.firstNonNull(attachSource.getFirstAttachSpell(), sa).getTargetRestrictions().getValidTgts()) {
|
||||||
for (KeywordInterface ki : attachSource.getKeywords(Keyword.ENCHANT)) {
|
if (!valid.startsWith("Creature")) {
|
||||||
String o = ki.getOriginal();
|
canOnlyTargetCreatures = false;
|
||||||
String m[] = o.split(":");
|
break;
|
||||||
String v = m[1];
|
|
||||||
if (!v.startsWith("Creature")) {
|
|
||||||
canOnlyTargetCreatures = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canOnlyTargetCreatures && (attachSource.isAura() || attachSource.isEquipment())) {
|
if (canOnlyTargetCreatures && (attachSource.isAura() || attachSource.isEquipment())) {
|
||||||
@@ -1263,7 +1172,7 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
// Probably prefer to Enchant Creatures that Can Attack
|
// Probably prefer to Enchant Creatures that Can Attack
|
||||||
// Filter out creatures that can't Attack or have Defender
|
// Filter out creatures that can't Attack or have Defender
|
||||||
if (keywords.isEmpty()) {
|
if (keywords.isEmpty()) {
|
||||||
final int powerBonus = totPower;
|
final int powerBonus = totPower;
|
||||||
prefList = CardLists.filter(prefList, c -> {
|
prefList = CardLists.filter(prefList, c -> {
|
||||||
if (!c.isCreature()) {
|
if (!c.isCreature()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1478,6 +1387,8 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
c = attachAICuriosityPreference(sa, prefList, mandatory, attachSource);
|
c = attachAICuriosityPreference(sa, prefList, mandatory, attachSource);
|
||||||
} else if ("ChangeType".equals(logic)) {
|
} else if ("ChangeType".equals(logic)) {
|
||||||
c = attachAIChangeTypePreference(sa, prefList, mandatory, attachSource);
|
c = attachAIChangeTypePreference(sa, prefList, mandatory, attachSource);
|
||||||
|
} else if ("KeepTapped".equals(logic)) {
|
||||||
|
c = attachAIKeepTappedPreference(sa, prefList, mandatory, attachSource);
|
||||||
} else if ("Animate".equals(logic)) {
|
} else if ("Animate".equals(logic)) {
|
||||||
c = attachAIAnimatePreference(sa, prefList, mandatory, attachSource);
|
c = attachAIAnimatePreference(sa, prefList, mandatory, attachSource);
|
||||||
} else if ("Reanimate".equals(logic)) {
|
} else if ("Reanimate".equals(logic)) {
|
||||||
@@ -1488,12 +1399,6 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
c = attachAIHighestEvaluationPreference(prefList);
|
c = attachAIHighestEvaluationPreference(prefList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAuraSpell(sa)) {
|
|
||||||
if (attachSource.getReplacementEffects().anyMatch(re -> re.getMode().equals(ReplacementType.Untap) && re.getLayer().equals(ReplacementLayer.CantHappen))) {
|
|
||||||
c = attachAIKeepTappedPreference(sa, prefList, mandatory, attachSource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consider exceptional cases which break the normal evaluation rules
|
// Consider exceptional cases which break the normal evaluation rules
|
||||||
if (!isUsefulAttachAction(ai, c, sa)) {
|
if (!isUsefulAttachAction(ai, c, sa)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -1646,6 +1551,8 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
} else if (keyword.endsWith("Prevent all combat damage that would be dealt to and dealt by CARDNAME.")
|
} else if (keyword.endsWith("Prevent all combat damage that would be dealt to and dealt by CARDNAME.")
|
||||||
|| keyword.endsWith("Prevent all damage that would be dealt to and dealt by CARDNAME.")) {
|
|| keyword.endsWith("Prevent all damage that would be dealt to and dealt by CARDNAME.")) {
|
||||||
return card.getNetCombatDamage() >= 2 && ComputerUtilCombat.canAttackNextTurn(card);
|
return card.getNetCombatDamage() >= 2 && ComputerUtilCombat.canAttackNextTurn(card);
|
||||||
|
} else if (keyword.endsWith("CARDNAME doesn't untap during your untap step.")) {
|
||||||
|
return !card.isUntapped();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1698,6 +1605,25 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
return chosen;
|
return chosen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean chkAIDrawback(final SpellAbility sa, final Player ai) {
|
||||||
|
// TODO for targeting optional Halvar trigger, needs to be coordinated with PumpAi to make it playable
|
||||||
|
if (sa.isTrigger() && sa.usesTargeting()) {
|
||||||
|
CardCollection targetables = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
|
CardCollection source = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Object"), sa);
|
||||||
|
Card tgt = attachGeneralAI(ai, sa, targetables, !sa.getRootAbility().isOptionalTrigger(), source.getFirst(), null);
|
||||||
|
if (tgt != null) {
|
||||||
|
sa.resetTargets();
|
||||||
|
sa.getTargets().add(tgt);
|
||||||
|
}
|
||||||
|
return sa.isTargetNumberValid();
|
||||||
|
} else if ("Remembered".equals(sa.getParam("Defined")) && sa.getParent() != null
|
||||||
|
&& sa.getParent().getApi() == ApiType.Token && sa.getParent().hasParam("RememberTokens")) {
|
||||||
|
// Living Weapon or similar
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.CardCollectionView;
|
import forge.game.card.CardCollectionView;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
@@ -13,7 +11,7 @@ import forge.util.MyRandom;
|
|||||||
|
|
||||||
public class BalanceAi extends SpellAbilityAi {
|
public class BalanceAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
String logic = sa.getParam("AILogic");
|
String logic = sa.getParam("AILogic");
|
||||||
int diff = 0;
|
int diff = 0;
|
||||||
Player opp = aiPlayer.getWeakestOpponent();
|
Player opp = aiPlayer.getWeakestOpponent();
|
||||||
@@ -39,7 +37,7 @@ public class BalanceAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
// Don't sacrifice permanents even if opponent has a ton of cards in hand
|
// Don't sacrifice permanents even if opponent has a ton of cards in hand
|
||||||
return new AiAbilityDecision(0, forge.ai.AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CardCollectionView humHand = opp.getCardsIn(ZoneType.Hand);
|
final CardCollectionView humHand = opp.getCardsIn(ZoneType.Hand);
|
||||||
@@ -47,7 +45,6 @@ public class BalanceAi extends SpellAbilityAi {
|
|||||||
diff += 0.5 * (humHand.size() - compHand.size());
|
diff += 0.5 * (humHand.size() - compHand.size());
|
||||||
|
|
||||||
// Larger differential == more chance to actually cast this spell
|
// Larger differential == more chance to actually cast this spell
|
||||||
boolean willPlay = diff > 2 && MyRandom.getRandom().nextInt(100) < diff*10;
|
return diff > 2 && MyRandom.getRandom().nextInt(100) < diff*10;
|
||||||
return new AiAbilityDecision(willPlay ? 100 : 0, willPlay ? forge.ai.AiPlayDecision.WillPlay : AiPlayDecision.StopRunawayActivations);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -17,51 +16,55 @@ import forge.game.zone.ZoneType;
|
|||||||
|
|
||||||
public class BecomesBlockedAi extends SpellAbilityAi {
|
public class BecomesBlockedAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
final Game game = aiPlayer.getGame();
|
final Game game = aiPlayer.getGame();
|
||||||
|
|
||||||
if (!game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
if (!game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
||||||
|| !game.getPhaseHandler().getPlayerTurn().isOpponentOf(aiPlayer)) {
|
|| !game.getPhaseHandler().getPlayerTurn().isOpponentOf(aiPlayer)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tgt != null) {
|
if (tgt != null) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
CardCollection list = CardLists.filterControlledBy(game.getCardsIn(ZoneType.Battlefield), aiPlayer.getOpponents());
|
CardCollection list = CardLists.filterControlledBy(game.getCardsIn(ZoneType.Battlefield), aiPlayer.getOpponents());
|
||||||
list = CardLists.getTargetableCards(list, sa);
|
list = CardLists.getTargetableCards(list, sa);
|
||||||
list = CardLists.getNotKeyword(list, Keyword.TRAMPLE);
|
list = CardLists.getNotKeyword(list, Keyword.TRAMPLE);
|
||||||
|
|
||||||
while (sa.canAddMoreTarget()) {
|
while (sa.canAddMoreTarget()) {
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
choice = ComputerUtilCard.getBestCreatureAI(list);
|
choice = ComputerUtilCard.getBestCreatureAI(list);
|
||||||
|
|
||||||
if (choice == null) { // can't find anything left
|
if (choice == null) { // can't find anything left
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
list.remove(choice);
|
list.remove(choice);
|
||||||
sa.getTargets().add(choice);
|
sa.getTargets().add(choice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
// TODO - implement AI
|
// TODO - implement AI
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
|
boolean chance;
|
||||||
|
|
||||||
// TODO - implement AI
|
// TODO - implement AI
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
chance = false;
|
||||||
|
|
||||||
|
return chance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiAttackController;
|
import forge.ai.AiAttackController;
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -12,13 +10,14 @@ import forge.game.player.Player;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BidLifeAi extends SpellAbilityAi {
|
public class BidLifeAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Game game = source.getGame();
|
final Game game = source.getGame();
|
||||||
TargetRestrictions tgt = sa.getTargetRestrictions();
|
TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
@@ -27,31 +26,31 @@ public class BidLifeAi extends SpellAbilityAi {
|
|||||||
if (tgt.canTgtCreature()) {
|
if (tgt.canTgtCreature()) {
|
||||||
List<Card> list = CardLists.getTargetableCards(AiAttackController.choosePreferredDefenderPlayer(aiPlayer).getCardsIn(ZoneType.Battlefield), sa);
|
List<Card> list = CardLists.getTargetableCards(AiAttackController.choosePreferredDefenderPlayer(aiPlayer).getCardsIn(ZoneType.Battlefield), sa);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
Card c = ComputerUtilCard.getBestCreatureAI(list);
|
Card c = ComputerUtilCard.getBestCreatureAI(list);
|
||||||
if (sa.canTarget(c)) {
|
if (sa.canTarget(c)) {
|
||||||
sa.getTargets().add(c);
|
sa.getTargets().add(c);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (tgt.getZone().contains(ZoneType.Stack)) {
|
} else if (tgt.getZone().contains(ZoneType.Stack)) {
|
||||||
if (game.getStack().isEmpty()) {
|
if (game.getStack().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
final SpellAbility topSA = game.getStack().peekAbility();
|
final SpellAbility topSA = game.getStack().peekAbility();
|
||||||
if (!topSA.isCounterableBy(sa) || aiPlayer.equals(topSA.getActivatingPlayer())) {
|
if (!topSA.isCounterableBy(sa) || aiPlayer.equals(topSA.getActivatingPlayer())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if (sa.canTargetSpellAbility(topSA)) {
|
if (sa.canTargetSpellAbility(topSA)) {
|
||||||
sa.getTargets().add(topSA);
|
sa.getTargets().add(topSA);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
boolean chance = MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -48,9 +46,9 @@ public final class BondAi extends SpellAbilityAi {
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
} // end bondCanPlayAI()
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Card chooseSingleCard(Player ai, SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer, Map<String, Object> params) {
|
protected Card chooseSingleCard(Player ai, SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer, Map<String, Object> params) {
|
||||||
@@ -58,7 +56,7 @@ public final class BondAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpecialAiLogic;
|
import forge.ai.SpecialAiLogic;
|
||||||
import forge.ai.SpecialCardAi;
|
import forge.ai.SpecialCardAi;
|
||||||
@@ -23,18 +21,16 @@ public class BranchAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
if ("GrislySigil".equals(aiLogic)) {
|
if ("GrislySigil".equals(aiLogic)) {
|
||||||
boolean result = SpecialCardAi.GrislySigil.consider(aiPlayer, sa);
|
return SpecialCardAi.GrislySigil.consider(aiPlayer, sa);
|
||||||
return new AiAbilityDecision(result ? 100 : 0, result ? AiPlayDecision.WillPlay : AiPlayDecision.CantPlayAi);
|
|
||||||
} else if ("BranchCounter".equals(aiLogic)) {
|
} else if ("BranchCounter".equals(aiLogic)) {
|
||||||
boolean result = SpecialAiLogic.doBranchCounterspellLogic(aiPlayer, sa);
|
return SpecialAiLogic.doBranchCounterspellLogic(aiPlayer, sa); // Bring the Ending, Anticognition (hacky implementation)
|
||||||
return new AiAbilityDecision(result ? 100 : 0, result ? AiPlayDecision.WillPlay : AiPlayDecision.CantPlayAi);
|
|
||||||
} else if ("TgtAttacker".equals(aiLogic)) {
|
} else if ("TgtAttacker".equals(aiLogic)) {
|
||||||
final Combat combat = aiPlayer.getGame().getCombat();
|
final Combat combat = aiPlayer.getGame().getCombat();
|
||||||
if (combat == null || combat.getAttackingPlayer() != aiPlayer) {
|
if (combat == null || combat.getAttackingPlayer() != aiPlayer) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CardCollection attackers = combat.getAttackers();
|
final CardCollection attackers = combat.getAttackers();
|
||||||
@@ -49,20 +45,16 @@ public class BranchAi extends SpellAbilityAi {
|
|||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(attackers));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(attackers));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(sa.isTargetNumberValid() ? 100 : 0, sa.isTargetNumberValid() ? AiPlayDecision.WillPlay : AiPlayDecision.CantPlayAi);
|
return sa.isTargetNumberValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: expand for other cases where the AI is needed to make a decision on a branch
|
// TODO: expand for other cases where the AI is needed to make a decision on a branch
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
AiAbilityDecision decision = canPlay(aiPlayer, sa);
|
return canPlayAI(aiPlayer, sa) || mandatory;
|
||||||
if (decision.willingToPlay() || mandatory) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
@@ -12,15 +10,15 @@ public class CannotPlayAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return canPlayAI(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.GameEntity;
|
import forge.game.GameEntity;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -17,36 +15,34 @@ public class ChangeCombatantsAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
// TODO: Extend this if possible for cards that have this as an activated ability
|
// TODO: Extend this if possible for cards that have this as an activated ability
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(aiPlayer, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
final String logic = sa.getParamOrDefault("AILogic", "");
|
final String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if (logic.equals("WeakestOppExceptCtrl")) {
|
if (logic.equals("WeakestOppExceptCtrl")) {
|
||||||
PlayerCollection targetableOpps = aiPlayer.getOpponents();
|
PlayerCollection targetableOpps = aiPlayer.getOpponents();
|
||||||
targetableOpps.remove(sa.getHostCard().getController());
|
targetableOpps.remove(sa.getHostCard().getController());
|
||||||
if (targetableOpps.isEmpty()) {
|
if (targetableOpps.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,3 +63,4 @@ public class ChangeCombatantsAi extends SpellAbilityAi {
|
|||||||
return (T)weakestTargetableOpp;
|
return (T)weakestTargetableOpp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtil;
|
||||||
|
import forge.ai.ComputerUtilAbility;
|
||||||
|
import forge.ai.ComputerUtilMana;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -18,7 +21,7 @@ public class ChangeTargetsAi extends SpellAbilityAi {
|
|||||||
* forge.game.spellability.SpellAbility)
|
* forge.game.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
final Game game = sa.getHostCard().getGame();
|
final Game game = sa.getHostCard().getGame();
|
||||||
final SpellAbility topSa = game.getStack().isEmpty() ? null
|
final SpellAbility topSa = game.getStack().isEmpty() ? null
|
||||||
: ComputerUtilAbility.getTopSpellAbilityOnStack(game, sa);
|
: ComputerUtilAbility.getTopSpellAbilityOnStack(game, sa);
|
||||||
@@ -29,50 +32,47 @@ public class ChangeTargetsAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// The AI can't otherwise play this ability, but should at least not
|
// The AI can't otherwise play this ability, but should at least not
|
||||||
// miss mandatory activations (e.g. triggers).
|
// miss mandatory activations (e.g. triggers).
|
||||||
if (sa.isMandatory()) {
|
return sa.isMandatory();
|
||||||
return new AiAbilityDecision(50, AiPlayDecision.MandatoryPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doSpellMagnet(SpellAbility sa, SpellAbility topSa, Player aiPlayer) {
|
private boolean doSpellMagnet(SpellAbility sa, SpellAbility topSa, Player aiPlayer) {
|
||||||
// For cards like Spellskite that retarget spells to itself
|
// For cards like Spellskite that retarget spells to itself
|
||||||
if (topSa == null) {
|
if (topSa == null) {
|
||||||
// nothing on stack, so nothing to target
|
// nothing on stack, so nothing to target
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
final TargetChoices topTargets = topSa.getTargets();
|
final TargetChoices topTargets = topSa.getTargets();
|
||||||
final Card topHost = topSa.getHostCard();
|
final Card topHost = topSa.getHostCard();
|
||||||
|
|
||||||
if (!sa.getTargets().isEmpty() && sa.isTrigger()) {
|
if (sa.getTargets().size() != 0 && sa.isTrigger()) {
|
||||||
// something was already chosen before (e.g. in response to a trigger - Mizzium Meddler), so just proceed
|
// something was already chosen before (e.g. in response to a trigger - Mizzium Meddler), so just proceed
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!topSa.usesTargeting() || topTargets.getTargetCards().contains(sa.getHostCard())) {
|
if (!topSa.usesTargeting() || topTargets.getTargetCards().contains(sa.getHostCard())) {
|
||||||
// if this does not target at all or already targets host, no need to redirect it again
|
// if this does not target at all or already targets host, no need to redirect it again
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Card tgt : topTargets.getTargetCards()) {
|
for (Card tgt : topTargets.getTargetCards()) {
|
||||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals(tgt.getName()) && tgt.getController().equals(aiPlayer)) {
|
if (ComputerUtilAbility.getAbilitySourceName(sa).equals(tgt.getName()) && tgt.getController().equals(aiPlayer)) {
|
||||||
// We are already targeting at least one card with the same name (e.g. in presence of 2+ Spellskites),
|
// We are already targeting at least one card with the same name (e.g. in presence of 2+ Spellskites),
|
||||||
// no need to retarget again to another one
|
// no need to retarget again to another one
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topHost != null && !topHost.getController().isOpponentOf(aiPlayer)) {
|
if (topHost != null && !topHost.getController().isOpponentOf(aiPlayer)) {
|
||||||
// make sure not to redirect our own abilities
|
// make sure not to redirect our own abilities
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if (!topSa.canTarget(sa.getHostCard())) {
|
if (!topSa.canTarget(sa.getHostCard())) {
|
||||||
// don't try targeting it if we can't legally target the host card with it in the first place
|
// don't try targeting it if we can't legally target the host card with it in the first place
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if (!sa.canTarget(topSa)) {
|
if (!sa.canTarget(topSa)) {
|
||||||
// don't try retargeting a spell that the current card can't legally retarget (e.g. Muck Drubb + Lightning Bolt to the face)
|
// don't try retargeting a spell that the current card can't legally retarget (e.g. Muck Drubb + Lightning Bolt to the face)
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.getPayCosts().getCostMana() != null && sa.getPayCosts().getCostMana().getMana().hasPhyrexian()) {
|
if (sa.getPayCosts().getCostMana() != null && sa.getPayCosts().getCostMana().getMana().hasPhyrexian()) {
|
||||||
@@ -85,22 +85,22 @@ public class ChangeTargetsAi extends SpellAbilityAi {
|
|||||||
if (potentialDmg != -1 && potentialDmg <= payDamage && !canPay
|
if (potentialDmg != -1 && potentialDmg <= payDamage && !canPay
|
||||||
&& topTargets.contains(aiPlayer)) {
|
&& topTargets.contains(aiPlayer)) {
|
||||||
// do not pay Phyrexian mana if the spell is a damaging one but it deals less damage or the same damage as we'll pay life
|
// do not pay Phyrexian mana if the spell is a damaging one but it deals less damage or the same damage as we'll pay life
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Card firstCard = topTargets.getFirstTargetedCard();
|
Card firstCard = topTargets.getFirstTargetedCard();
|
||||||
// if we're not the target don't intervene unless we can steal a buff
|
// if we're not the target don't intervene unless we can steal a buff
|
||||||
if (firstCard != null && !aiPlayer.equals(firstCard.getController()) && !topHost.getController().equals(firstCard.getController()) && !topHost.getController().getAllies().contains(firstCard.getController())) {
|
if (firstCard != null && !aiPlayer.equals(firstCard.getController()) && !topHost.getController().equals(firstCard.getController()) && !topHost.getController().getAllies().contains(firstCard.getController())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
Player firstPlayer = topTargets.getFirstTargetedPlayer();
|
Player firstPlayer = topTargets.getFirstTargetedPlayer();
|
||||||
if (firstPlayer != null && !aiPlayer.equals(firstPlayer)) {
|
if (firstPlayer != null && !aiPlayer.equals(firstPlayer)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(topSa);
|
sa.getTargets().add(topSa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,30 +46,6 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
private static CardCollection multipleCardsToChoose = new CardCollection();
|
private static CardCollection multipleCardsToChoose = new CardCollection();
|
||||||
|
|
||||||
protected boolean willPayCosts(Player ai, SpellAbility sa, Cost cost, Card source) {
|
protected boolean willPayCosts(Player ai, SpellAbility sa, Cost cost, Card source) {
|
||||||
if (sa.isHidden()) {
|
|
||||||
if (!ComputerUtilCost.checkSacrificeCost(ai, cost, source, sa)
|
|
||||||
&& !"Battlefield".equals(sa.getParam("Destination")) && !source.isLand()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkLifeCost(ai, cost, source, 4, sa)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkDiscardCost(ai, cost, source, sa)) {
|
|
||||||
for (final CostPart part : cost.getCostParts()) {
|
|
||||||
if (part instanceof CostDiscard) {
|
|
||||||
CostDiscard cd = (CostDiscard) part;
|
|
||||||
// this is mainly for typecycling
|
|
||||||
if (!cd.payCostFromSource() || !ComputerUtil.isWorseThanDraw(ai, source)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sa.isCraft()) {
|
if (sa.isCraft()) {
|
||||||
CardCollection payingCards = new CardCollection();
|
CardCollection payingCards = new CardCollection();
|
||||||
int needed = 0;
|
int needed = 0;
|
||||||
@@ -153,12 +129,14 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
||||||
|
// Checks for "return true" unlike checkAiLogic()
|
||||||
|
|
||||||
multipleCardsToChoose.clear();
|
multipleCardsToChoose.clear();
|
||||||
String aiLogic = sa.getParam("AILogic");
|
String aiLogic = sa.getParam("AILogic");
|
||||||
if (aiLogic != null) {
|
if (aiLogic != null) {
|
||||||
if (aiLogic.equals("Always")) {
|
if (aiLogic.equals("Always")) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if (aiLogic.startsWith("SacAndUpgrade")) { // Birthing Pod, Natural Order, etc.
|
} else if (aiLogic.startsWith("SacAndUpgrade")) { // Birthing Pod, Natural Order, etc.
|
||||||
return doSacAndUpgradeLogic(aiPlayer, sa);
|
return doSacAndUpgradeLogic(aiPlayer, sa);
|
||||||
} else if (aiLogic.startsWith("SacAndRetFromGrave")) { // Recurring Nightmare, etc.
|
} else if (aiLogic.startsWith("SacAndRetFromGrave")) { // Recurring Nightmare, etc.
|
||||||
@@ -178,18 +156,10 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
} else if (aiLogic.equals("MazesEnd")) {
|
} else if (aiLogic.equals("MazesEnd")) {
|
||||||
return SpecialCardAi.MazesEnd.consider(aiPlayer, sa);
|
return SpecialCardAi.MazesEnd.consider(aiPlayer, sa);
|
||||||
} else if (aiLogic.equals("Pongify")) {
|
} else if (aiLogic.equals("Pongify")) {
|
||||||
if (sa.isTargetNumberValid()) {
|
return sa.isTargetNumberValid(); // Pre-targeted in checkAiLogic
|
||||||
// Pre-targeted in checkAiLogic
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else if (aiLogic.equals("ReturnCastable")) {
|
} else if (aiLogic.equals("ReturnCastable")) {
|
||||||
if (!sa.getHostCard().getExiledCards().isEmpty()
|
return !sa.getHostCard().getExiledCards().isEmpty()
|
||||||
&& ComputerUtilMana.canPayManaCost(sa.getHostCard().getExiledCards().getFirst().getFirstSpellAbility(), aiPlayer, 0, false)) {
|
&& ComputerUtilMana.canPayManaCost(sa.getHostCard().getExiledCards().getFirst().getFirstSpellAbility(), aiPlayer, 0, false);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sa.isHidden()) {
|
if (sa.isHidden()) {
|
||||||
@@ -208,7 +178,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
if (sa.isHidden()) {
|
if (sa.isHidden()) {
|
||||||
return hiddenOriginPlayDrawbackAI(aiPlayer, sa);
|
return hiddenOriginPlayDrawbackAI(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
@@ -227,7 +197,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if (sa.isReplacementAbility() && "Command".equals(sa.getParam("Destination")) && "ReplacedCard".equals(sa.getParam("Defined"))) {
|
if (sa.isReplacementAbility() && "Command".equals(sa.getParam("Destination")) && "ReplacedCard".equals(sa.getParam("Defined"))) {
|
||||||
@@ -236,10 +206,10 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("Always".equals(aiLogic)) {
|
if ("Always".equals(aiLogic)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if ("IfNotBuffed".equals(aiLogic)) {
|
} else if ("IfNotBuffed".equals(aiLogic)) {
|
||||||
if (ComputerUtilCard.isUselessCreature(aiPlayer, sa.getHostCard())) {
|
if (ComputerUtilCard.isUselessCreature(aiPlayer, sa.getHostCard())) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true; // debuffed by opponent's auras to the level that it becomes useless
|
||||||
}
|
}
|
||||||
int delta = 0;
|
int delta = 0;
|
||||||
for (Card enc : sa.getHostCard().getEnchantedBy()) {
|
for (Card enc : sa.getHostCard().getEnchantedBy()) {
|
||||||
@@ -249,17 +219,9 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
delta++;
|
delta++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (delta <= 0) {
|
return delta <= 0;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else if ("SaviorOfOllenbock".equals(aiLogic)) {
|
} else if ("SaviorOfOllenbock".equals(aiLogic)) {
|
||||||
if (SpecialCardAi.SaviorOfOllenbock.consider(aiPlayer, sa)) {
|
return SpecialCardAi.SaviorOfOllenbock.consider(aiPlayer, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.isHidden()) {
|
if (sa.isHidden()) {
|
||||||
@@ -288,8 +250,10 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
private static AiAbilityDecision hiddenOriginCanPlayAI(final Player ai, final SpellAbility sa) {
|
private static boolean hiddenOriginCanPlayAI(final Player ai, final SpellAbility sa) {
|
||||||
// Fetching should occur fairly often as it helps cast more spells, and have access to more mana
|
// Fetching should occur fairly often as it helps cast more spells, and
|
||||||
|
// have access to more mana
|
||||||
|
final Cost abCost = sa.getPayCosts();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
||||||
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
@@ -303,35 +267,75 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
// This happens when Origin is something like
|
// This happens when Origin is something like
|
||||||
// "Graveyard,Library" (Doomsday)
|
// "Graveyard,Library" (Doomsday)
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String destination = sa.getParam("Destination");
|
final String destination = sa.getParam("Destination");
|
||||||
|
|
||||||
if (sa.isNinjutsu()) {
|
if (abCost != null) {
|
||||||
if (!source.ignoreLegendRule() && ai.isCardInPlay(source.getName())) {
|
// AI currently disabled for these costs
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WouldDestroyLegend);
|
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa)
|
||||||
}
|
&& !(destination.equals("Battlefield") && !source.isLand())) {
|
||||||
if (ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DAMAGE)) {
|
return false;
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ai.getGame().getCombat() == null) {
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
|
return false;
|
||||||
}
|
}
|
||||||
List<Card> attackers = ai.getGame().getCombat().getUnblockedAttackers();
|
|
||||||
boolean lowerCMC = false;
|
if (!ComputerUtilCost.checkDiscardCost(ai, abCost, source, sa)) {
|
||||||
for (Card attacker : attackers) {
|
for (final CostPart part : abCost.getCostParts()) {
|
||||||
if (attacker.getCMC() < source.getCMC()) {
|
if (part instanceof CostDiscard) {
|
||||||
lowerCMC = true;
|
CostDiscard cd = (CostDiscard) part;
|
||||||
break;
|
// this is mainly for typecycling
|
||||||
|
if (!cd.payCostFromSource() || !ComputerUtil.isWorseThanDraw(ai, source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!lowerCMC) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
if (sa.isNinjutsu()) {
|
||||||
|
if (!source.ignoreLegendRule() && ai.isCardInPlay(source.getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
if (attacker.getCMC() < source.getCMC()) {
|
||||||
|
lowerCMC = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!lowerCMC) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't play if the conditions aren't met, unless it would trigger a beneficial sub-condition
|
||||||
|
if (!activateForCost && !sa.metConditions()) {
|
||||||
|
final AbilitySub abSub = sa.getSubAbility();
|
||||||
|
if (abSub != null && !sa.isWrapper() && "True".equals(source.getSVar("AIPlayForSub"))) {
|
||||||
|
if (!abSub.metConditions()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// prevent run-away activations - first time will always return true
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Iterable<Player> pDefined = Lists.newArrayList(source.getController());
|
Iterable<Player> pDefined = Lists.newArrayList(source.getController());
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
if (tgt != null && tgt.canTgtPlayer()) {
|
if (tgt != null && tgt.canTgtPlayer()) {
|
||||||
@@ -343,7 +347,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
}
|
}
|
||||||
if (!sa.isTargetNumberValid()) {
|
if (!sa.isTargetNumberValid()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
pDefined = sa.getTargets().getTargetPlayers();
|
pDefined = sa.getTargets().getTargetPlayers();
|
||||||
} else {
|
} else {
|
||||||
@@ -387,12 +391,12 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!activateForCost && list.isEmpty()) {
|
if (!activateForCost && list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if ("Atarka's Command".equals(sourceName)
|
if ("Atarka's Command".equals(sourceName)
|
||||||
&& (list.size() < 2 || ai.getLandsPlayedThisTurn() < 1)) {
|
&& (list.size() < 2 || ai.getLandsPlayedThisTurn() < 1)) {
|
||||||
// be strict on playing lands off charms
|
// be strict on playing lands off charms
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String num = sa.getParamOrDefault("ChangeNum", "1");
|
String num = sa.getParamOrDefault("ChangeNum", "1");
|
||||||
@@ -400,60 +404,55 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
if (sa.getSVar("X").equals("Count$xPaid")) {
|
if (sa.getSVar("X").equals("Count$xPaid")) {
|
||||||
// Set PayX here to maximum value.
|
// Set PayX here to maximum value.
|
||||||
int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
if (xPay == 0) {
|
if (xPay == 0) return false;
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
|
||||||
}
|
|
||||||
xPay = Math.min(xPay, list.size());
|
xPay = Math.min(xPay, list.size());
|
||||||
sa.setXManaCostPaid(xPay);
|
sa.setXManaCostPaid(xPay);
|
||||||
} else {
|
} else {
|
||||||
// Figure out the X amount, bail if it's zero (nothing will change zone).
|
// Figure out the X amount, bail if it's zero (nothing will change zone).
|
||||||
int xValue = AbilityUtils.calculateAmount(source, "X", sa);
|
int xValue = AbilityUtils.calculateAmount(source, "X", sa);
|
||||||
if (xValue == 0) {
|
if (xValue == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceName.equals("Temur Sabertooth")) {
|
if (sourceName.equals("Temur Sabertooth")) {
|
||||||
// activated bounce + pump
|
// activated bounce + pump
|
||||||
boolean pumpDecision = ComputerUtilCard.shouldPumpCard(ai, sa.getSubAbility(), source, 0, 0, Arrays.asList("Indestructible"));
|
if (ComputerUtilCard.shouldPumpCard(ai, sa.getSubAbility(), source, 0, 0, Arrays.asList("Indestructible")) ||
|
||||||
AiAbilityDecision saveDecision = ComputerUtilCard.canPumpAgainstRemoval(ai, sa.getSubAbility());
|
ComputerUtilCard.canPumpAgainstRemoval(ai, sa.getSubAbility())) {
|
||||||
if (pumpDecision || saveDecision.willingToPlay()) {
|
|
||||||
for (Card c : list) {
|
for (Card c : list) {
|
||||||
if (ComputerUtilCard.evaluateCreature(c) < ComputerUtilCard.evaluateCreature(source)) {
|
if (ComputerUtilCard.evaluateCreature(c) < ComputerUtilCard.evaluateCreature(source)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ResponseToStackResolve);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canBouncePermanent(ai, sa, list) != null) {
|
return canBouncePermanent(ai, sa, list) != null;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ComputerUtil.playImmediately(ai, sa)) {
|
if (ComputerUtil.playImmediately(ai, sa)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't use fetching to top of library/graveyard before main2
|
// don't use fetching to top of library/graveyard before main2
|
||||||
if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
|
if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
|
||||||
&& !sa.hasParam("ActivationPhases")) {
|
&& !sa.hasParam("ActivationPhases")) {
|
||||||
if (!destination.equals("Battlefield") && !destination.equals("Hand")) {
|
if (!destination.equals("Battlefield") && !destination.equals("Hand")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
// Only tutor something in main1 if hand is almost empty
|
// Only tutor something in main1 if hand is almost empty
|
||||||
if (ai.getCardsIn(ZoneType.Hand).size() > 1 && destination.equals("Hand")
|
if (ai.getCardsIn(ZoneType.Hand).size() > 1 && destination.equals("Hand")
|
||||||
&& !aiLogic.equals("AnyMainPhase")) {
|
&& !aiLogic.equals("AnyMainPhase")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ComputerUtil.waitForBlocking(sa)) {
|
if (ComputerUtil.waitForBlocking(sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
final AbilitySub subAb = sa.getSubAbility();
|
||||||
|
return subAb == null || SpellApiToAi.Converter.get(subAb).chkDrawbackWithSubs(ai, subAb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -465,7 +464,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
private static AiAbilityDecision hiddenOriginPlayDrawbackAI(final Player aiPlayer, final SpellAbility sa) {
|
private static boolean hiddenOriginPlayDrawbackAI(final Player aiPlayer, final SpellAbility sa) {
|
||||||
// if putting cards from hand to library and parent is drawing cards
|
// if putting cards from hand to library and parent is drawing cards
|
||||||
// make sure this will actually do something:
|
// make sure this will actually do something:
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
@@ -477,11 +476,11 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
} else if (!isCurse && sa.canTarget(aiPlayer)) {
|
} else if (!isCurse && sa.canTarget(aiPlayer)) {
|
||||||
sa.getTargets().add(aiPlayer);
|
sa.getTargets().add(aiPlayer);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -495,7 +494,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* a boolean.
|
* a boolean.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
private static AiAbilityDecision hiddenTriggerAI(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
private static boolean hiddenTriggerAI(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
||||||
// Fetching should occur fairly often as it helps cast more spells, and
|
// Fetching should occur fairly often as it helps cast more spells, and
|
||||||
// have access to more mana
|
// have access to more mana
|
||||||
|
|
||||||
@@ -508,7 +507,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* to make sub-optimal choices (waste bounce) than to make obvious mistakes
|
* to make sub-optimal choices (waste bounce) than to make obvious mistakes
|
||||||
* (bounce useful permanent).
|
* (bounce useful permanent).
|
||||||
*/
|
*/
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,15 +545,15 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
pDefined = sa.getTargets().getTargetPlayers();
|
pDefined = sa.getTargets().getTargetPlayers();
|
||||||
|
|
||||||
if (Iterables.isEmpty(pDefined)) {
|
if (Iterables.isEmpty(pDefined)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
pDefined = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa);
|
pDefined = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa);
|
||||||
}
|
}
|
||||||
@@ -568,10 +567,10 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *********** Utility functions for Hidden ********************
|
// *********** Utility functions for Hidden ********************
|
||||||
@@ -674,7 +673,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
private static AiAbilityDecision knownOriginCanPlayAI(final Player ai, final SpellAbility sa) {
|
private static boolean knownOriginCanPlayAI(final Player ai, final SpellAbility sa) {
|
||||||
// Retrieve either this card, or target Cards in Graveyard
|
// Retrieve either this card, or target Cards in Graveyard
|
||||||
|
|
||||||
final List<ZoneType> origin = Lists.newArrayList();
|
final List<ZoneType> origin = Lists.newArrayList();
|
||||||
@@ -686,16 +685,20 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
final ZoneType destination = ZoneType.smartValueOf(sa.getParam("Destination"));
|
final ZoneType destination = ZoneType.smartValueOf(sa.getParam("Destination"));
|
||||||
|
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
if (!isPreferredTarget(ai, sa, false, false)) {
|
if (!isPreferredTarget(ai, sa, false, false)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// non-targeted retrieval
|
// non-targeted retrieval
|
||||||
final List<Card> retrieval = sa.knownDetermineDefined(sa.getParam("Defined"));
|
final List<Card> retrieval = sa.knownDetermineDefined(sa.getParam("Defined"));
|
||||||
|
|
||||||
if (retrieval == null || retrieval.isEmpty()) {
|
if (retrieval == null || retrieval.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return this card from graveyard: cards like Hammer of Bogardan
|
// return this card from graveyard: cards like Hammer of Bogardan
|
||||||
@@ -706,7 +709,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
// (dying or losing control of)
|
// (dying or losing control of)
|
||||||
if (origin.contains(ZoneType.Battlefield)) {
|
if (origin.contains(ZoneType.Battlefield)) {
|
||||||
if (ai.getGame().getStack().isEmpty()) {
|
if (ai.getGame().getStack().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final AbilitySub abSub = sa.getSubAbility();
|
final AbilitySub abSub = sa.getSubAbility();
|
||||||
@@ -719,7 +722,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
if (!(destination.equals(ZoneType.Exile)
|
if (!(destination.equals(ZoneType.Exile)
|
||||||
&& (subApi == ApiType.DelayedTrigger || subApi == ApiType.ChangeZone || "DelayedBlink".equals(sa.getParam("AILogic"))))
|
&& (subApi == ApiType.DelayedTrigger || subApi == ApiType.ChangeZone || "DelayedBlink".equals(sa.getParam("AILogic"))))
|
||||||
&& !destination.equals(ZoneType.Hand)) {
|
&& !destination.equals(ZoneType.Hand)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<GameObject> objects = ComputerUtil.predictThreatenedObjects(ai, sa);
|
final List<GameObject> objects = ComputerUtil.predictThreatenedObjects(ai, sa);
|
||||||
@@ -731,13 +734,13 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!contains) {
|
if (!contains) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destination == ZoneType.Battlefield) {
|
if (destination == ZoneType.Battlefield) {
|
||||||
if (ComputerUtil.isETBprevented(retrieval.get(0))) {
|
if (ComputerUtil.isETBprevented(retrieval.get(0))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// predict whether something may put a ETBing creature below zero toughness
|
// predict whether something may put a ETBing creature below zero toughness
|
||||||
@@ -747,7 +750,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
final Card copy = CardCopyService.getLKICopy(c);
|
final Card copy = CardCopyService.getLKICopy(c);
|
||||||
ComputerUtilCard.applyStaticContPT(c.getGame(), copy, null);
|
ComputerUtilCard.applyStaticContPT(c.getGame(), copy, null);
|
||||||
if (copy.getNetToughness() <= 0) {
|
if (copy.getNetToughness() <= 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -761,12 +764,13 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nothingWillReturn) {
|
if (nothingWillReturn) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
final AbilitySub subAb = sa.getSubAbility();
|
||||||
|
return subAb == null || SpellApiToAi.Converter.get(subAb).chkDrawbackWithSubs(ai, subAb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -780,7 +784,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph) {
|
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph) {
|
||||||
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if (aiLogic.equals("SurvivalOfTheFittest")) {
|
if (aiLogic.equals("SurvivalOfTheFittest") || aiLogic.equals("AtOppEOT")) {
|
||||||
return ph.getNextTurn().equals(ai) && ph.is(PhaseType.END_OF_TURN);
|
return ph.getNextTurn().equals(ai) && ph.is(PhaseType.END_OF_TURN);
|
||||||
} else if (aiLogic.equals("Main1") && ph.is(PhaseType.MAIN1, ai)) {
|
} else if (aiLogic.equals("Main1") && ph.is(PhaseType.MAIN1, ai)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -839,26 +843,16 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
private static AiAbilityDecision knownOriginPlayDrawbackAI(final Player aiPlayer, final SpellAbility sa) {
|
private static boolean knownOriginPlayDrawbackAI(final Player aiPlayer, final SpellAbility sa) {
|
||||||
if ("MimicVat".equals(sa.getParam("AILogic"))) {
|
if ("MimicVat".equals(sa.getParam("AILogic"))) {
|
||||||
if (SpecialCardAi.MimicVat.considerExile(aiPlayer, sa)) {
|
return SpecialCardAi.MimicVat.considerExile(aiPlayer, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPreferredTarget(aiPlayer, sa, false, true)) {
|
return isPreferredTarget(aiPlayer, sa, false, true);
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
} else {
|
|
||||||
// if we are here, we have a target
|
|
||||||
// so we can play the ability
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -920,9 +914,6 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
if (sa.isSpell()) {
|
if (sa.isSpell()) {
|
||||||
list.remove(source); // spells can't target their own source, because it's actually in the stack zone
|
list.remove(source); // spells can't target their own source, because it's actually in the stack zone
|
||||||
}
|
}
|
||||||
|
|
||||||
// list = CardLists.canSubsequentlyTarget(list, sa);
|
|
||||||
|
|
||||||
if (sa.hasParam("AttachedTo")) {
|
if (sa.hasParam("AttachedTo")) {
|
||||||
list = CardLists.filter(list, c -> {
|
list = CardLists.filter(list, c -> {
|
||||||
for (Card card : game.getCardsIn(ZoneType.Battlefield)) {
|
for (Card card : game.getCardsIn(ZoneType.Battlefield)) {
|
||||||
@@ -1291,9 +1282,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list.remove(choice);
|
list.remove(choice);
|
||||||
if (sa.canTarget(choice)) {
|
sa.getTargets().add(choice);
|
||||||
sa.getTargets().add(choice);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Honor the Single Zone restriction. For now, simply remove targets that do not belong to the same zone as the first targeted card.
|
// Honor the Single Zone restriction. For now, simply remove targets that do not belong to the same zone as the first targeted card.
|
||||||
@@ -1459,9 +1448,6 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
// AI Targeting
|
// AI Targeting
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
|
|
||||||
// Filter out cards TargetsForEachPlayer
|
|
||||||
list = CardLists.canSubsequentlyTarget(list, sa);
|
|
||||||
|
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
Card mostExpensivePermanent = ComputerUtilCard.getMostExpensivePermanentAI(list);
|
Card mostExpensivePermanent = ComputerUtilCard.getMostExpensivePermanentAI(list);
|
||||||
if (mostExpensivePermanent.isCreature()
|
if (mostExpensivePermanent.isCreature()
|
||||||
@@ -1499,7 +1485,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (choice == null) { // can't find anything left
|
if (choice == null) { // can't find anything left
|
||||||
if (sa.getTargets().isEmpty() || sa.getTargets().size() < tgt.getMinTargets(sa.getHostCard(), sa)) {
|
if (sa.getTargets().size() == 0 || sa.getTargets().size() < tgt.getMinTargets(sa.getHostCard(), sa)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1527,21 +1513,13 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
* a boolean.
|
* a boolean.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
private static AiAbilityDecision knownOriginTriggerAI(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
private static boolean knownOriginTriggerAI(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
||||||
final String logic = sa.getParamOrDefault("AILogic", "");
|
final String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if ("DeathgorgeScavenger".equals(logic)) {
|
if ("DeathgorgeScavenger".equals(logic)) {
|
||||||
if (SpecialCardAi.DeathgorgeScavenger.consider(ai, sa)) {
|
return SpecialCardAi.DeathgorgeScavenger.consider(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else if ("ExtraplanarLens".equals(logic)) {
|
} else if ("ExtraplanarLens".equals(logic)) {
|
||||||
if (SpecialCardAi.ExtraplanarLens.consider(ai, sa)) {
|
return SpecialCardAi.ExtraplanarLens.consider(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else if ("ExileCombatThreat".equals(logic)) {
|
} else if ("ExileCombatThreat".equals(logic)) {
|
||||||
return doExileCombatThreatLogic(ai, sa);
|
return doExileCombatThreatLogic(ai, sa);
|
||||||
}
|
}
|
||||||
@@ -1553,27 +1531,14 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
final Card attachedTo = list.get(0);
|
final Card attachedTo = list.get(0);
|
||||||
// This code is for the Dragon auras
|
// This code is for the Dragon auras
|
||||||
if (!attachedTo.getController().isOpponentOf(ai)) {
|
return !attachedTo.getController().isOpponentOf(ai);
|
||||||
// If the AI is not the controller of the attachedTo card, then it is not a valid target.
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// If the AI is the controller of the attachedTo card, then it is a valid target.
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (isPreferredTarget(ai, sa, mandatory, true)) {
|
} else if (isPreferredTarget(ai, sa, mandatory, true)) {
|
||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else return isUnpreferredTarget(ai, sa, mandatory);
|
||||||
if (isUnpreferredTarget(ai, sa, mandatory)) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// If the AI is not the controller of the attachedTo card, then it is not a valid target.
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Card chooseCardToHiddenOriginChangeZone(ZoneType destination, List<ZoneType> origin, SpellAbility sa, CardCollection fetchList, Player player, final Player decider) {
|
public static Card chooseCardToHiddenOriginChangeZone(ZoneType destination, List<ZoneType> origin, SpellAbility sa, CardCollection fetchList, Player player, final Player decider) {
|
||||||
@@ -1804,7 +1769,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
return super.chooseSingleAttackableEntity(ai, sa, options, params);
|
return super.chooseSingleAttackableEntity(ai, sa, options, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doSacAndReturnFromGraveLogic(final Player ai, final SpellAbility sa) {
|
private boolean doSacAndReturnFromGraveLogic(final Player ai, final SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
String definedSac = StringUtils.split(source.getSVar("AIPreference"), "$")[1];
|
String definedSac = StringUtils.split(source.getSVar("AIPreference"), "$")[1];
|
||||||
|
|
||||||
@@ -1823,14 +1788,14 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(bestRet);
|
sa.getTargets().add(bestRet);
|
||||||
source.setSVar("AIPreferenceOverride", "Creature.cmcEQ" + worstSac.getCMC());
|
source.setSVar("AIPreferenceOverride", "Creature.cmcEQ" + worstSac.getCMC());
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doSacAndUpgradeLogic(final Player ai, final SpellAbility sa) {
|
private boolean doSacAndUpgradeLogic(final Player ai, final SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||||
String logic = sa.getParam("AILogic");
|
String logic = sa.getParam("AILogic");
|
||||||
@@ -1838,7 +1803,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!ph.is(PhaseType.MAIN2)) {
|
if (!ph.is(PhaseType.MAIN2)) {
|
||||||
// Should be given a chance to cast other spells as well as to use a previously upgraded creature
|
// Should be given a chance to cast other spells as well as to use a previously upgraded creature
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForMain2);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String definedSac = StringUtils.split(source.getSVar("AIPreference"), "$")[1];
|
String definedSac = StringUtils.split(source.getSVar("AIPreference"), "$")[1];
|
||||||
@@ -1877,14 +1842,15 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
if (!listGoal.isEmpty()) {
|
if (!listGoal.isEmpty()) {
|
||||||
// make sure we're upgrading sacCMC->goalCMC
|
// make sure we're upgrading sacCMC->goalCMC
|
||||||
source.setSVar("AIPreferenceOverride", "Creature.cmcEQ" + sacCMC);
|
source.setSVar("AIPreferenceOverride", "Creature.cmcEQ" + sacCMC);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
// no candidates to upgrade
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AiAbilityDecision doReturnCommanderLogic(SpellAbility sa, Player aiPlayer) {
|
public boolean doReturnCommanderLogic(SpellAbility sa, Player aiPlayer) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<AbilityKey, Object> originalParams = (Map<AbilityKey, Object>)sa.getReplacingObject(AbilityKey.OriginalParams);
|
Map<AbilityKey, Object> originalParams = (Map<AbilityKey, Object>)sa.getReplacingObject(AbilityKey.OriginalParams);
|
||||||
SpellAbility causeSa = (SpellAbility)originalParams.get(AbilityKey.Cause);
|
SpellAbility causeSa = (SpellAbility)originalParams.get(AbilityKey.Cause);
|
||||||
@@ -1893,13 +1859,13 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (Objects.equals(ZoneType.Hand, destination)) {
|
if (Objects.equals(ZoneType.Hand, destination)) {
|
||||||
// If the commander is being moved to your hand, don't replace since its easier to cast it again
|
// If the commander is being moved to your hand, don't replace since its easier to cast it again
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Squee, the Immortal: easier to recast it (the call below has to be "contains" since SA is an intrinsic effect)
|
// 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") &&
|
if (sa.getHostCard().getName().contains("Squee, the Immortal") &&
|
||||||
(destination == ZoneType.Graveyard || destination == ZoneType.Exile)) {
|
(destination == ZoneType.Graveyard || destination == ZoneType.Exile)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (causeSa != null && (causeSub = causeSa.getSubAbility()) != null) {
|
if (causeSa != null && (causeSub = causeSa.getSubAbility()) != null) {
|
||||||
@@ -1908,38 +1874,28 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
if (subApi == ApiType.ChangeZone && "Exile".equals(causeSub.getParam("Origin"))
|
if (subApi == ApiType.ChangeZone && "Exile".equals(causeSub.getParam("Origin"))
|
||||||
&& "Battlefield".equals(causeSub.getParam("Destination"))) {
|
&& "Battlefield".equals(causeSub.getParam("Destination"))) {
|
||||||
// A blink effect implemented using ChangeZone API
|
// A blink effect implemented using ChangeZone API
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else // This is an intrinsic effect that blinks the card (e.g. Obzedat, Ghost Council), no need to
|
} else // This is an intrinsic effect that blinks the card (e.g. Obzedat, Ghost Council), no need to
|
||||||
// return the commander to the Command zone.
|
// return the commander to the Command zone.
|
||||||
if (subApi == ApiType.DelayedTrigger) {
|
if (subApi == ApiType.DelayedTrigger) {
|
||||||
SpellAbility exec = causeSub.getAdditionalAbility("Execute");
|
SpellAbility exec = causeSub.getAdditionalAbility("Execute");
|
||||||
if (exec != null && exec.getApi() == ApiType.ChangeZone) {
|
if (exec != null && exec.getApi() == ApiType.ChangeZone) {
|
||||||
// A blink effect implemented using a delayed trigger
|
// A blink effect implemented using a delayed trigger
|
||||||
if (!"Exile".equals(exec.getParam("Origin")) || !"Battlefield".equals(exec.getParam("Destination"))) {
|
return !"Exile".equals(exec.getParam("Origin")) || !"Battlefield".equals(exec.getParam("Destination"));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (causeSa.getHostCard() == null || !causeSa.getHostCard().equals(sa.getReplacingObject(AbilityKey.Card))
|
|
||||||
|| !causeSa.getActivatingPlayer().equals(aiPlayer)) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else return causeSa.getHostCard() == null || !causeSa.getHostCard().equals(sa.getReplacingObject(AbilityKey.Card))
|
||||||
|
|| !causeSa.getActivatingPlayer().equals(aiPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normally we want the commander back in Command zone to recast it later
|
// Normally we want the commander back in Command zone to recast him later
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AiAbilityDecision doExileCombatThreatLogic(final Player aiPlayer, final SpellAbility sa) {
|
public static boolean doExileCombatThreatLogic(final Player aiPlayer, final SpellAbility sa) {
|
||||||
final Combat combat = aiPlayer.getGame().getCombat();
|
final Combat combat = aiPlayer.getGame().getCombat();
|
||||||
|
|
||||||
if (combat == null) {
|
if (combat == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
@@ -1974,9 +1930,9 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (choice != null) {
|
if (choice != null) {
|
||||||
sa.getTargets().add(choice);
|
sa.getTargets().add(choice);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Card doExilePreferenceLogic(final Player aiPlayer, final SpellAbility sa, CardCollection fetchList) {
|
public static Card doExilePreferenceLogic(final Player aiPlayer, final SpellAbility sa, CardCollection fetchList) {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.*;
|
import forge.ai.*;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
@@ -21,7 +19,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class ChangeZoneAllAi extends SpellAbilityAi {
|
public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
// Change Zone All, can be any type moving from one zone to another
|
// Change Zone All, can be any type moving from one zone to another
|
||||||
final Cost abCost = sa.getPayCosts();
|
final Cost abCost = sa.getPayCosts();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
@@ -34,14 +32,14 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
|||||||
if (abCost != null) {
|
if (abCost != null) {
|
||||||
// AI currently disabled for these costs
|
// AI currently disabled for these costs
|
||||||
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CostNotAcceptable);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkDiscardCost(ai, abCost, source, sa)) {
|
if (!ComputerUtilCost.checkDiscardCost(ai, abCost, source, sa)) {
|
||||||
boolean aiLogicAllowsDiscard = aiLogic.startsWith("DiscardAll");
|
boolean aiLogicAllowsDiscard = aiLogic.startsWith("DiscardAll");
|
||||||
|
|
||||||
if (!aiLogicAllowsDiscard) {
|
if (!aiLogicAllowsDiscard) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CostNotAcceptable);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,29 +59,31 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// Ugin AI: always try to sweep before considering +1
|
// Ugin AI: always try to sweep before considering +1
|
||||||
if (sourceName.equals("Ugin, the Spirit Dragon")) {
|
if (sourceName.equals("Ugin, the Spirit Dragon")) {
|
||||||
boolean result = SpecialCardAi.UginTheSpiritDragon.considerPWAbilityPriority(ai, sa, origin, oppType, computerType);
|
return SpecialCardAi.UginTheSpiritDragon.considerPWAbilityPriority(ai, sa, origin, oppType, computerType);
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oppType = AbilityUtils.filterListByType(oppType, sa.getParam("ChangeType"), sa);
|
oppType = AbilityUtils.filterListByType(oppType, sa.getParam("ChangeType"), sa);
|
||||||
computerType = AbilityUtils.filterListByType(computerType, sa.getParam("ChangeType"), sa);
|
computerType = AbilityUtils.filterListByType(computerType, sa.getParam("ChangeType"), sa);
|
||||||
|
|
||||||
if ("LivingDeath".equals(aiLogic)) {
|
if ("LivingDeath".equals(aiLogic)) {
|
||||||
|
// Living Death AI
|
||||||
return SpecialCardAi.LivingDeath.consider(ai, sa);
|
return SpecialCardAi.LivingDeath.consider(ai, sa);
|
||||||
} else if ("Timetwister".equals(aiLogic)) {
|
} else if ("Timetwister".equals(aiLogic)) {
|
||||||
|
// Timetwister AI
|
||||||
return SpecialCardAi.Timetwister.consider(ai, sa);
|
return SpecialCardAi.Timetwister.consider(ai, sa);
|
||||||
} else if ("RetDiscardedThisTurn".equals(aiLogic)) {
|
} else if ("RetDiscardedThisTurn".equals(aiLogic)) {
|
||||||
boolean result = !ai.getDiscardedThisTurn().isEmpty() && ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN);
|
// e.g. Shadow of the Grave
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return ai.getDiscardedThisTurn().size() > 0 && ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN);
|
||||||
} else if ("ExileGraveyards".equals(aiLogic)) {
|
} else if ("ExileGraveyards".equals(aiLogic)) {
|
||||||
for (Player opp : ai.getOpponents()) {
|
for (Player opp : ai.getOpponents()) {
|
||||||
CardCollectionView cardsGY = opp.getCardsIn(ZoneType.Graveyard);
|
CardCollectionView cardsGY = opp.getCardsIn(ZoneType.Graveyard);
|
||||||
CardCollection creats = CardLists.filter(cardsGY, CardPredicates.CREATURES);
|
CardCollection creats = CardLists.filter(cardsGY, CardPredicates.CREATURES);
|
||||||
|
|
||||||
if (opp.hasDelirium() || opp.hasThreshold() || creats.size() >= 5) {
|
if (opp.hasDelirium() || opp.hasThreshold() || creats.size() >= 5) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if ("ManifestCreatsFromGraveyard".equals(aiLogic)) {
|
} else if ("ManifestCreatsFromGraveyard".equals(aiLogic)) {
|
||||||
PlayerCollection players = ai.getOpponents();
|
PlayerCollection players = ai.getOpponents();
|
||||||
players.add(ai);
|
players.add(ai);
|
||||||
@@ -98,48 +98,68 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
|||||||
bestTgt = player;
|
bestTgt = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestTgt != null) {
|
if (bestTgt != null) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(bestTgt);
|
sa.getTargets().add(bestTgt);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO improve restrictions on when the AI would want to use this
|
// TODO improve restrictions on when the AI would want to use this
|
||||||
// spBounceAll has some AI we can compare to.
|
// spBounceAll has some AI we can compare to.
|
||||||
if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) {
|
if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) {
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
// TODO: improve logic for non-targeted SAs of this type (most are currently AI:RemoveDeck:All, e.g. Memory Jar)
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
// search targetable Opponents
|
||||||
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
|
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the one with the most handsize
|
||||||
Player oppTarget = oppList.max(PlayerPredicates.compareByZoneSize(origin));
|
Player oppTarget = oppList.max(PlayerPredicates.compareByZoneSize(origin));
|
||||||
|
|
||||||
|
// set the target
|
||||||
if (!oppTarget.getCardsIn(ZoneType.Hand).isEmpty()) {
|
if (!oppTarget.getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(oppTarget);
|
sa.getTargets().add(oppTarget);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (origin.equals(ZoneType.Battlefield)) {
|
} else if (origin.equals(ZoneType.Battlefield)) {
|
||||||
|
// this statement is assuming the AI is trying to use this spell offensively
|
||||||
|
// if the AI is using it defensively, then something else needs to occur
|
||||||
|
// if only creatures are affected evaluate both lists and pass only
|
||||||
|
// if human creatures are more valuable
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
|
// search targetable Opponents
|
||||||
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
|
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the one with the most in graveyard
|
||||||
|
// zone is visible so evaluate which would be hurt the most
|
||||||
Player oppTarget = oppList.max(PlayerPredicates.compareByZoneSize(origin));
|
Player oppTarget = oppList.max(PlayerPredicates.compareByZoneSize(origin));
|
||||||
|
|
||||||
|
// set the target
|
||||||
if (oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
if (oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(oppTarget);
|
sa.getTargets().add(oppTarget);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
computerType = new CardCollection();
|
computerType = new CardCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
int creatureEvalThreshold = 200; // value difference (in evaluateCreatureList units)
|
int creatureEvalThreshold = 200; // value difference (in evaluateCreatureList units)
|
||||||
int nonCreatureEvalThreshold = 3; // CMC difference
|
int nonCreatureEvalThreshold = 3; // CMC difference
|
||||||
if (ai.getController().isAI()) {
|
if (ai.getController().isAI()) {
|
||||||
@@ -161,80 +181,103 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
|||||||
&& game.getPhaseHandler().getPlayerTurn().isOpponentOf(ai)) {
|
&& game.getPhaseHandler().getPlayerTurn().isOpponentOf(ai)) {
|
||||||
// Life is in serious danger, return all creatures from the battlefield to wherever
|
// Life is in serious danger, return all creatures from the battlefield to wherever
|
||||||
// so they don't deal lethal damage
|
// so they don't deal lethal damage
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((ComputerUtilCard.evaluateCreatureList(computerType) + creatureEvalThreshold) >= ComputerUtilCard
|
if ((ComputerUtilCard.evaluateCreatureList(computerType) + creatureEvalThreshold) >= ComputerUtilCard
|
||||||
.evaluateCreatureList(oppType)) {
|
.evaluateCreatureList(oppType)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if ((ComputerUtilCard.evaluatePermanentList(computerType) + nonCreatureEvalThreshold) >= ComputerUtilCard
|
} // mass zone change for non-creatures: evaluate both lists by CMC and pass only if human
|
||||||
|
// permanents are more valuable
|
||||||
|
else if ((ComputerUtilCard.evaluatePermanentList(computerType) + nonCreatureEvalThreshold) >= ComputerUtilCard
|
||||||
.evaluatePermanentList(oppType)) {
|
.evaluatePermanentList(oppType)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't cast during main1?
|
||||||
if (game.getPhaseHandler().is(PhaseType.MAIN1, ai) && !aiLogic.equals("Main1")) {
|
if (game.getPhaseHandler().is(PhaseType.MAIN1, ai) && !aiLogic.equals("Main1")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TimingRestrictions);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (origin.equals(ZoneType.Graveyard)) {
|
} else if (origin.equals(ZoneType.Graveyard)) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
|
// search targetable Opponents
|
||||||
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
|
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the one with the most in graveyard
|
||||||
|
// zone is visible so evaluate which would be hurt the most
|
||||||
Player oppTarget = Collections.max(oppList, AiPlayerPredicates.compareByZoneValue(sa.getParam("ChangeType"), origin, sa));
|
Player oppTarget = Collections.max(oppList, AiPlayerPredicates.compareByZoneValue(sa.getParam("ChangeType"), origin, sa));
|
||||||
|
|
||||||
|
// set the target
|
||||||
if (!oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
if (!oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(oppTarget);
|
sa.getTargets().add(oppTarget);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (destination.equals(ZoneType.Library) && "Card.YouOwn".equals(sa.getParam("ChangeType"))) {
|
} else if (destination.equals(ZoneType.Library) && "Card.YouOwn".equals(sa.getParam("ChangeType"))) {
|
||||||
boolean result = (ai.getCardsIn(ZoneType.Graveyard).size() > ai.getCardsIn(ZoneType.Library).size())
|
return (ai.getCardsIn(ZoneType.Graveyard).size() > ai.getCardsIn(ZoneType.Library).size())
|
||||||
&& !ComputerUtil.isPlayingReanimator(ai);
|
&& !ComputerUtil.isPlayingReanimator(ai);
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
} else if (origin.equals(ZoneType.Exile)) {
|
} else if (origin.equals(ZoneType.Exile)) {
|
||||||
if (aiLogic.startsWith("DiscardAllAndRetExiled")) {
|
if (aiLogic.startsWith("DiscardAllAndRetExiled")) {
|
||||||
int numExiledWithSrc = CardLists.filter(ai.getCardsIn(ZoneType.Exile), CardPredicates.isExiledWith(source)).size();
|
int numExiledWithSrc = CardLists.filter(ai.getCardsIn(ZoneType.Exile), CardPredicates.isExiledWith(source)).size();
|
||||||
int curHandSize = ai.getCardsIn(ZoneType.Hand).size();
|
int curHandSize = ai.getCardsIn(ZoneType.Hand).size();
|
||||||
|
|
||||||
|
// minimum card advantage unless the hand will be fully reloaded
|
||||||
int minAdv = aiLogic.contains(".minAdv") ? Integer.parseInt(aiLogic.substring(aiLogic.indexOf(".minAdv") + 7)) : 0;
|
int minAdv = aiLogic.contains(".minAdv") ? Integer.parseInt(aiLogic.substring(aiLogic.indexOf(".minAdv") + 7)) : 0;
|
||||||
boolean noDiscard = aiLogic.contains(".noDiscard");
|
boolean noDiscard = aiLogic.contains(".noDiscard");
|
||||||
|
|
||||||
if (numExiledWithSrc > curHandSize || (noDiscard && numExiledWithSrc > 0)) {
|
if (numExiledWithSrc > curHandSize || (noDiscard && numExiledWithSrc > 0)) {
|
||||||
if (ComputerUtil.predictThreatenedObjects(ai, sa, true).contains(source)) {
|
if (ComputerUtil.predictThreatenedObjects(ai, sa, true).contains(source)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
// Try to gain some card advantage if the card will die anyway
|
||||||
|
// TODO: ideally, should evaluate the hand value and not discard good hands to it
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean result = (curHandSize + minAdv - 1 < numExiledWithSrc) || (!noDiscard && numExiledWithSrc >= ai.getMaxHandSize());
|
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return (curHandSize + minAdv - 1 < numExiledWithSrc) || (!noDiscard && numExiledWithSrc >= ai.getMaxHandSize());
|
||||||
}
|
}
|
||||||
} else if (origin.equals(ZoneType.Stack)) {
|
} else if (origin.equals(ZoneType.Stack)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
// TODO
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destination.equals(ZoneType.Battlefield)) {
|
if (destination.equals(ZoneType.Battlefield)) {
|
||||||
if (sa.hasParam("GainControl")) {
|
if (sa.hasParam("GainControl")) {
|
||||||
|
// Check if the cards are valuable enough
|
||||||
if (CardLists.getNotType(oppType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
if (CardLists.getNotType(oppType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
||||||
if ((ComputerUtilCard.evaluateCreatureList(computerType) + ComputerUtilCard
|
if ((ComputerUtilCard.evaluateCreatureList(computerType) + ComputerUtilCard
|
||||||
.evaluateCreatureList(oppType)) < 400) {
|
.evaluateCreatureList(oppType)) < 400) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if ((ComputerUtilCard.evaluatePermanentList(computerType) + ComputerUtilCard
|
} // otherwise evaluate both lists by CMC and pass only if human
|
||||||
|
// permanents are less valuable
|
||||||
|
else if ((ComputerUtilCard.evaluatePermanentList(computerType) + ComputerUtilCard
|
||||||
.evaluatePermanentList(oppType)) < 6) {
|
.evaluatePermanentList(oppType)) < 6) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// don't activate if human gets more back than AI does
|
||||||
if (CardLists.getNotType(oppType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
if (CardLists.getNotType(oppType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
||||||
if (ComputerUtilCard.evaluateCreatureList(computerType) <= (ComputerUtilCard
|
if (ComputerUtilCard.evaluateCreatureList(computerType) <= (ComputerUtilCard
|
||||||
.evaluateCreatureList(oppType) + 100)) {
|
.evaluateCreatureList(oppType) + 100)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (ComputerUtilCard.evaluatePermanentList(computerType) <= (ComputerUtilCard
|
} // otherwise evaluate both lists by CMC and pass only if human
|
||||||
|
// permanents are less valuable
|
||||||
|
else if (ComputerUtilCard.evaluatePermanentList(computerType) <= (ComputerUtilCard
|
||||||
.evaluatePermanentList(oppType) + 2)) {
|
.evaluatePermanentList(oppType) + 2)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean result = ((MyRandom.getRandom().nextFloat() < .8) || sa.isTrigger()) && chance;
|
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return (((MyRandom.getRandom().nextFloat() < .8) || sa.isTrigger()) && chance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,11 +292,11 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
// if putting cards from hand to library and parent is drawing cards
|
// if putting cards from hand to library and parent is drawing cards
|
||||||
// make sure this will actually do something:
|
// make sure this will actually do something:
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -285,90 +328,127 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, final SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, final SpellAbility sa, boolean mandatory) {
|
||||||
|
// Change Zone All, can be any type moving from one zone to another
|
||||||
|
|
||||||
final ZoneType destination = ZoneType.smartValueOf(sa.getParam("Destination"));
|
final ZoneType destination = ZoneType.smartValueOf(sa.getParam("Destination"));
|
||||||
final ZoneType origin = ZoneType.listValueOf(sa.getParam("Origin")).get(0);
|
final ZoneType origin = ZoneType.listValueOf(sa.getParam("Origin")).get(0);
|
||||||
|
|
||||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Profaner of the Dead")) {
|
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Profaner of the Dead")) {
|
||||||
boolean result = ai.getOpponents().getCardsIn(origin).anyMatch(CardPredicates.CREATURES);
|
// TODO: this is a stub to prevent the AI from crashing the game when, for instance, playing the opponent's
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
// 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 ai.getOpponents().getCardsIn(origin).anyMatch(CardPredicates.CREATURES);
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollectionView humanType = ai.getOpponents().getCardsIn(origin);
|
CardCollectionView humanType = ai.getOpponents().getCardsIn(origin);
|
||||||
humanType = AbilityUtils.filterListByType(humanType, sa.getParam("ChangeType"), sa);
|
humanType = AbilityUtils.filterListByType(humanType, sa.getParam("ChangeType"), sa);
|
||||||
|
|
||||||
CardCollectionView computerType = ai.getCardsIn(origin);
|
CardCollectionView computerType = ai.getCardsIn(origin);
|
||||||
computerType = AbilityUtils.filterListByType(computerType, sa.getParam("ChangeType"), sa);
|
computerType = AbilityUtils.filterListByType(computerType, sa.getParam("ChangeType"), sa);
|
||||||
|
|
||||||
|
// TODO improve restrictions on when the AI would want to use this
|
||||||
|
// spBounceAll has some AI we can compare to.
|
||||||
if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) {
|
if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
|
// search targetable Opponents
|
||||||
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
|
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) {
|
if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the one with the most handsize
|
||||||
Player oppTarget = oppList.max(PlayerPredicates.compareByZoneSize(origin));
|
Player oppTarget = oppList.max(PlayerPredicates.compareByZoneSize(origin));
|
||||||
|
|
||||||
|
// set the target
|
||||||
if (!oppTarget.getCardsIn(ZoneType.Hand).isEmpty() || mandatory) {
|
if (!oppTarget.getCardsIn(ZoneType.Hand).isEmpty() || mandatory) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(oppTarget);
|
sa.getTargets().add(oppTarget);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (origin.equals(ZoneType.Battlefield)) {
|
} else if (origin.equals(ZoneType.Battlefield)) {
|
||||||
|
// if mandatory, no need to evaluate
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
// this statement is assuming the AI is trying to use this spell offensively
|
||||||
|
// if the AI is using it defensively, then something else needs to occur
|
||||||
|
// if only creatures are affected evaluate both lists and pass only
|
||||||
|
// if human creatures are more valuable
|
||||||
if (CardLists.getNotType(humanType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
if (CardLists.getNotType(humanType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
||||||
if (ComputerUtilCard.evaluateCreatureList(computerType) >= ComputerUtilCard.evaluateCreatureList(humanType)) {
|
if (ComputerUtilCard.evaluateCreatureList(computerType) >= ComputerUtilCard.evaluateCreatureList(humanType)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (ComputerUtilCard.evaluatePermanentList(computerType) >= ComputerUtilCard.evaluatePermanentList(humanType)) {
|
} // otherwise evaluate both lists by CMC and pass only if human
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
// permanents are more valuable
|
||||||
|
else if (ComputerUtilCard.evaluatePermanentList(computerType) >= ComputerUtilCard.evaluatePermanentList(humanType)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else if (origin.equals(ZoneType.Graveyard)) {
|
} else if (origin.equals(ZoneType.Graveyard)) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
|
// search targetable Opponents
|
||||||
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
|
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) {
|
if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return sa.isTargetNumberValid() ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return sa.isTargetNumberValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the one with the most in graveyard
|
||||||
|
// zone is visible so evaluate which would be hurt the most
|
||||||
Player oppTarget = oppList.max(
|
Player oppTarget = oppList.max(
|
||||||
AiPlayerPredicates.compareByZoneValue(sa.getParam("ChangeType"), origin, sa));
|
AiPlayerPredicates.compareByZoneValue(sa.getParam("ChangeType"), origin, sa));
|
||||||
|
|
||||||
|
// set the target
|
||||||
if (!oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty() || mandatory) {
|
if (!oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty() || mandatory) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(oppTarget);
|
sa.getTargets().add(oppTarget);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (origin.equals(ZoneType.Exile)) {
|
||||||
|
|
||||||
|
} else if (origin.equals(ZoneType.Stack)) {
|
||||||
|
// currently only exists indirectly (e.g. Summary Dismissal via PlayAi)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destination.equals(ZoneType.Battlefield)) {
|
if (destination.equals(ZoneType.Battlefield)) {
|
||||||
|
// if mandatory, no need to evaluate
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
if (sa.hasParam("GainControl")) {
|
if (sa.hasParam("GainControl")) {
|
||||||
|
// Check if the cards are valuable enough
|
||||||
if (CardLists.getNotType(humanType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
if (CardLists.getNotType(humanType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
||||||
boolean result = (ComputerUtilCard.evaluateCreatureList(computerType) + ComputerUtilCard.evaluateCreatureList(humanType)) >= 1;
|
return (ComputerUtilCard.evaluateCreatureList(computerType) + ComputerUtilCard.evaluateCreatureList(humanType)) >= 1;
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
} // otherwise evaluate both lists by CMC and pass only if human
|
||||||
}
|
// permanents are less valuable
|
||||||
boolean result = (ComputerUtilCard.evaluatePermanentList(computerType) + ComputerUtilCard
|
return (ComputerUtilCard.evaluatePermanentList(computerType) + ComputerUtilCard
|
||||||
.evaluatePermanentList(humanType)) >= 1;
|
.evaluatePermanentList(humanType)) >= 1;
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't activate if human gets more back than AI does
|
||||||
if (CardLists.getNotType(humanType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
if (CardLists.getNotType(humanType, "Creature").isEmpty() && CardLists.getNotType(computerType, "Creature").isEmpty()) {
|
||||||
boolean result = ComputerUtilCard.evaluateCreatureList(computerType) > ComputerUtilCard.evaluateCreatureList(humanType);
|
return ComputerUtilCard.evaluateCreatureList(computerType) > ComputerUtilCard.evaluateCreatureList(humanType);
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
} // otherwise evaluate both lists by CMC and pass only if human
|
||||||
}
|
// permanents are less valuable
|
||||||
boolean result = ComputerUtilCard.evaluatePermanentList(computerType) > ComputerUtilCard.evaluatePermanentList(humanType);
|
return ComputerUtilCard.evaluatePermanentList(computerType) > ComputerUtilCard.evaluatePermanentList(humanType);
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import forge.game.player.Player;
|
|||||||
import forge.game.spellability.AbilitySub;
|
import forge.game.spellability.AbilitySub;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
|
import forge.util.MyRandom;
|
||||||
import forge.util.collect.FCollection;
|
import forge.util.collect.FCollection;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -17,7 +18,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class CharmAi extends SpellAbilityAi {
|
public class CharmAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
List<AbilitySub> choices = CharmEffect.makePossibleOptions(sa);
|
List<AbilitySub> choices = CharmEffect.makePossibleOptions(sa);
|
||||||
|
|
||||||
@@ -69,10 +70,10 @@ public class CharmAi extends SpellAbilityAi {
|
|||||||
// Set minimum choices for triggers where chooseMultipleOptionsAi() returns null
|
// Set minimum choices for triggers where chooseMultipleOptionsAi() returns null
|
||||||
chosenList = chooseOptionsAi(sa, choices, ai, true, num, min);
|
chosenList = chooseOptionsAi(sa, choices, ai, true, num, min);
|
||||||
if (chosenList.isEmpty() && min != 0) {
|
if (chosenList.isEmpty() && min != 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ public class CharmAi extends SpellAbilityAi {
|
|||||||
sa.setChosenList(chosenList);
|
sa.setChosenList(chosenList);
|
||||||
|
|
||||||
if (choiceForOpp) {
|
if (choiceForOpp) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.isSpell()) {
|
if (sa.isSpell()) {
|
||||||
@@ -88,7 +89,8 @@ public class CharmAi extends SpellAbilityAi {
|
|||||||
CharmEffect.chainAbilities(sa, chosenList);
|
CharmEffect.chainAbilities(sa, chosenList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.checkApiLogic(ai, sa);
|
// prevent run-away activations - first time will always return true
|
||||||
|
return MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<AbilitySub> chooseOptionsAi(SpellAbility sa, List<AbilitySub> choices, final Player ai, boolean isTrigger, int num, int min) {
|
private List<AbilitySub> chooseOptionsAi(SpellAbility sa, List<AbilitySub> choices, final Player ai, boolean isTrigger, int num, int min) {
|
||||||
@@ -274,10 +276,10 @@ public class CharmAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawbackWithSubs(Player aiPlayer, AbilitySub ab) {
|
public boolean chkDrawbackWithSubs(Player aiPlayer, AbilitySub ab) {
|
||||||
// choices were already targeted
|
// choices were already targeted
|
||||||
if (ab.getRootAbility().getChosenList() != null) {
|
if (ab.getRootAbility().getChosenList() != null) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return super.chkDrawbackWithSubs(aiPlayer, ab);
|
return super.chkDrawbackWithSubs(aiPlayer, ab);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import forge.game.Game;
|
|||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
import forge.game.keyword.Keyword;
|
import forge.game.keyword.Keyword;
|
||||||
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerPredicates;
|
import forge.game.player.PlayerPredicates;
|
||||||
@@ -25,19 +26,19 @@ public class ChooseCardAi extends SpellAbilityAi {
|
|||||||
* The rest of the logic not covered by the canPlayAI template is defined here
|
* The rest of the logic not covered by the canPlayAI template is defined here
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
// search targetable Opponents
|
// search targetable Opponents
|
||||||
final List<Player> oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
final List<Player> oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
|
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.getTargets().add(Iterables.getFirst(oppList, null));
|
sa.getTargets().add(Iterables.getFirst(oppList, null));
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,12 +135,21 @@ public class ChooseCardAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
if (sa.hasParam("AILogic") && !checkAiLogic(ai, sa, sa.getParam("AILogic"))) {
|
if (sa.hasParam("AILogic") && !checkAiLogic(ai, sa, sa.getParam("AILogic"))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
|
}
|
||||||
|
return checkApiLogic(ai, sa);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph) {
|
||||||
|
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
|
if (aiLogic.equals("AtOppEOT")) {
|
||||||
|
return ph.getNextTurn().equals(ai) && ph.is(PhaseType.END_OF_TURN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkApiLogic(ai, sa);
|
return super.checkPhaseRestrictions(ai, sa, ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -22,20 +22,16 @@ import java.util.Map;
|
|||||||
public class ChooseCardNameAi extends SpellAbilityAi {
|
public class ChooseCardNameAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
if (sa.hasParam("AILogic")) {
|
if (sa.hasParam("AILogic")) {
|
||||||
// Don't tap creatures that may be able to block
|
// Don't tap creatures that may be able to block
|
||||||
if (ComputerUtil.waitForBlocking(sa)) {
|
if (ComputerUtil.waitForBlocking(sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String logic = sa.getParam("AILogic");
|
String logic = sa.getParam("AILogic");
|
||||||
if (logic.equals("CursedScroll")) {
|
if (logic.equals("CursedScroll")) {
|
||||||
if (SpecialCardAi.CursedScroll.consider(ai, sa)) {
|
return SpecialCardAi.CursedScroll.consider(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
@@ -47,13 +43,13 @@ public class ChooseCardNameAi extends SpellAbilityAi {
|
|||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
if ("PithingNeedle".equals(aiLogic)) {
|
if ("PithingNeedle".equals(aiLogic)) {
|
||||||
// Make sure theres something in play worth Needlings.
|
// Make sure theres something in play worth Needlings.
|
||||||
@@ -61,27 +57,18 @@ public class ChooseCardNameAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
CardCollection oppPerms = CardLists.getValidCards(ai.getOpponents().getCardsIn(ZoneType.Battlefield), "Card.OppCtrl+hasNonManaActivatedAbility", ai, sa.getHostCard(), sa);
|
CardCollection oppPerms = CardLists.getValidCards(ai.getOpponents().getCardsIn(ZoneType.Battlefield), "Card.OppCtrl+hasNonManaActivatedAbility", ai, sa.getHostCard(), sa);
|
||||||
if (oppPerms.isEmpty()) {
|
if (oppPerms.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Card card = ComputerUtilCard.getBestPlaneswalkerAI(oppPerms);
|
Card card = ComputerUtilCard.getBestPlaneswalkerAI(oppPerms);
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5 percent chance to cast per opposing card with a non mana ability
|
// 5 percent chance to cast per opposing card with a non mana ability
|
||||||
if (MyRandom.getRandom().nextFloat() <= .05 * oppPerms.size()) {
|
return MyRandom.getRandom().nextFloat() <= .05 * oppPerms.size();
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mandatory) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
return mandatory;
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.ability.SpellAbilityAi#chooseSingleCard(forge.card.spellability.SpellAbility, java.util.List, boolean)
|
* @see forge.card.ability.SpellAbilityAi#chooseSingleCard(forge.card.spellability.SpellAbility, java.util.List, boolean)
|
||||||
|
|||||||
@@ -11,45 +11,40 @@ import forge.game.phase.PhaseType;
|
|||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
public class ChooseColorAi extends SpellAbilityAi {
|
public class ChooseColorAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
||||||
final PhaseHandler ph = game.getPhaseHandler();
|
final PhaseHandler ph = game.getPhaseHandler();
|
||||||
|
|
||||||
if (!sa.hasParam("AILogic")) {
|
if (!sa.hasParam("AILogic")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingLogic);
|
return false;
|
||||||
}
|
}
|
||||||
final String logic = sa.getParam("AILogic");
|
final String logic = sa.getParam("AILogic");
|
||||||
|
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ("Nykthos, Shrine to Nyx".equals(sourceName)) {
|
if ("Nykthos, Shrine to Nyx".equals(sourceName)) {
|
||||||
if (SpecialCardAi.NykthosShrineToNyx.consider(ai, sa)) {
|
return SpecialCardAi.NykthosShrineToNyx.consider(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Oona, Queen of the Fae".equals(sourceName)) {
|
if ("Oona, Queen of the Fae".equals(sourceName)) {
|
||||||
if (ph.isPlayerTurn(ai) || ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
if (ph.isPlayerTurn(ai) || ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
// Set PayX here to maximum value.
|
// Set PayX here to maximum value.
|
||||||
sa.setXManaCostPaid(ComputerUtilCost.getMaxXValue(sa, ai, false));
|
sa.setXManaCostPaid(ComputerUtilCost.getMaxXValue(sa, ai, false));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Addle".equals(sourceName)) {
|
if ("Addle".equals(sourceName)) {
|
||||||
// TODO Why is this not in the AI logic?
|
return !ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) && !ai.getWeakestOpponent().getCardsIn(ZoneType.Hand).isEmpty();
|
||||||
// Why are we specifying the weakest opponent?
|
|
||||||
if (!ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) && !ai.getWeakestOpponent().getCardsIn(ZoneType.Hand).isEmpty()) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logic.equals("MostExcessOpponentControls")) {
|
if (logic.equals("MostExcessOpponentControls")) {
|
||||||
@@ -59,10 +54,10 @@ public class ChooseColorAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
int excess = ComputerUtilCard.evaluatePermanentList(opplist) - ComputerUtilCard.evaluatePermanentList(ailist);
|
int excess = ComputerUtilCard.evaluatePermanentList(opplist) - ComputerUtilCard.evaluatePermanentList(ailist);
|
||||||
if (excess > 4) {
|
if (excess > 4) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (logic.equals("MostProminentInComputerDeck")) {
|
} else if (logic.equals("MostProminentInComputerDeck")) {
|
||||||
if ("Astral Cornucopia".equals(sourceName)) {
|
if ("Astral Cornucopia".equals(sourceName)) {
|
||||||
// activate in Main 2 hoping that the extra mana surplus will make a difference
|
// activate in Main 2 hoping that the extra mana surplus will make a difference
|
||||||
@@ -70,28 +65,22 @@ public class ChooseColorAi extends SpellAbilityAi {
|
|||||||
CardCollectionView permanents = CardLists.filter(ai.getCardsIn(ZoneType.Hand),
|
CardCollectionView permanents = CardLists.filter(ai.getCardsIn(ZoneType.Hand),
|
||||||
CardPredicates.NONLAND_PERMANENTS);
|
CardPredicates.NONLAND_PERMANENTS);
|
||||||
|
|
||||||
if (!permanents.isEmpty() && ph.is(PhaseType.MAIN2, ai)) {
|
return permanents.size() > 0 && ph.is(PhaseType.MAIN2, ai);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForMain2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (logic.equals("HighestDevotionToColor")) {
|
} else if (logic.equals("HighestDevotionToColor")) {
|
||||||
// currently only works more or less reliably in Main2 to cast own spells
|
// currently only works more or less reliably in Main2 to cast own spells
|
||||||
if (!ph.is(PhaseType.MAIN2, ai)) {
|
if (!ph.is(PhaseType.MAIN2, ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForMain2);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
boolean chance = MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return canPlay(ai, sa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Direction;
|
import forge.game.Direction;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -20,11 +18,11 @@ public class ChooseDirectionAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final String logic = sa.getParam("AILogic");
|
final String logic = sa.getParam("AILogic");
|
||||||
final Game game = sa.getActivatingPlayer().getGame();
|
final Game game = sa.getActivatingPlayer().getGame();
|
||||||
if (logic == null) {
|
if (logic == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingLogic);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if ("Aminatou".equals(logic)) {
|
if ("Aminatou".equals(logic)) {
|
||||||
CardCollection all = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.NONLAND_PERMANENTS);
|
CardCollection all = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.NONLAND_PERMANENTS);
|
||||||
@@ -35,24 +33,19 @@ public class ChooseDirectionAi extends SpellAbilityAi {
|
|||||||
CardCollection right = CardLists.filterControlledBy(all, game.getNextPlayerAfter(ai, Direction.Right));
|
CardCollection right = CardLists.filterControlledBy(all, game.getNextPlayerAfter(ai, Direction.Right));
|
||||||
int leftValue = Aggregates.sum(left, Card::getCMC);
|
int leftValue = Aggregates.sum(left, Card::getCMC);
|
||||||
int rightValue = Aggregates.sum(right, Card::getCMC);
|
int rightValue = Aggregates.sum(right, Card::getCMC);
|
||||||
if (aiValue <= leftValue && aiValue <= rightValue) {
|
return aiValue <= leftValue && aiValue <= rightValue;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
return canPlay(ai, sa);
|
return canPlayAI(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return canPlay(ai, sa);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiAttackController;
|
import forge.ai.AiAttackController;
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
public class ChooseEvenOddAi extends SpellAbilityAi {
|
public class ChooseEvenOddAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
if (!sa.hasParam("AILogic")) {
|
if (!sa.hasParam("AILogic")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingLogic);
|
return false;
|
||||||
}
|
}
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
@@ -20,17 +19,16 @@ public class ChooseEvenOddAi extends SpellAbilityAi {
|
|||||||
if (sa.canTarget(opp)) {
|
if (sa.canTarget(opp)) {
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
boolean chance = MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return canPlay(ai, sa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import forge.game.Game;
|
|||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardCollectionView;
|
import forge.game.card.CardCollectionView;
|
||||||
import forge.game.cost.Cost;
|
import forge.game.cost.Cost;
|
||||||
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.AbilitySub;
|
import forge.game.spellability.AbilitySub;
|
||||||
@@ -19,6 +20,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
public class ChooseGenericAi extends SpellAbilityAi {
|
public class ChooseGenericAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,10 +29,13 @@ public class ChooseGenericAi extends SpellAbilityAi {
|
|||||||
return true;
|
return true;
|
||||||
} else if ("Pump".equals(aiLogic) || "BestOption".equals(aiLogic)) {
|
} else if ("Pump".equals(aiLogic) || "BestOption".equals(aiLogic)) {
|
||||||
for (AbilitySub sb : sa.getAdditionalAbilityList("Choices")) {
|
for (AbilitySub sb : sa.getAdditionalAbilityList("Choices")) {
|
||||||
if (SpellApiToAi.Converter.get(sb).canPlayWithSubs(ai, sb).willingToPlay()) {
|
if (SpellApiToAi.Converter.get(sb).canPlayAIWithSubs(ai, sb)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if ("AtOppEOT".equals(aiLogic)) {
|
||||||
|
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||||
|
return ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == ai;
|
||||||
} else if ("Always".equals(aiLogic)) {
|
} else if ("Always".equals(aiLogic)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -38,46 +43,35 @@ public class ChooseGenericAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
if (sa.hasParam("AILogic")) {
|
return sa.hasParam("AILogic");
|
||||||
// This is equivilant to what was here before but feels bad
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
AiAbilityDecision decision;
|
return sa.isTrigger() ? doTriggerAINoCost(aiPlayer, sa, sa.isMandatory()) : checkApiLogic(aiPlayer, sa);
|
||||||
if (sa.isTrigger()) {
|
|
||||||
decision = doTriggerNoCost(aiPlayer, sa, sa.isMandatory());
|
|
||||||
} else {
|
|
||||||
decision = checkApiLogic(aiPlayer, sa);
|
|
||||||
}
|
|
||||||
|
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
||||||
if ("CombustibleGearhulk".equals(sa.getParam("AILogic")) || "SoulEcho".equals(sa.getParam("AILogic"))) {
|
if ("CombustibleGearhulk".equals(sa.getParam("AILogic")) || "SoulEcho".equals(sa.getParam("AILogic"))) {
|
||||||
for (final Player p : aiPlayer.getOpponents()) {
|
for (final Player p : aiPlayer.getOpponents()) {
|
||||||
if (p.canBeTargetedBy(sa)) {
|
if (p.canBeTargetedBy(sa)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(p);
|
sa.getTargets().add(p);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay); // perhaps the opponent(s) had Sigarda, Heron's Grace or another effect giving hexproof in play, still play the creature as 6/6
|
return true; // perhaps the opponent(s) had Sigarda, Heron's Grace or another effect giving hexproof in play, still play the creature as 6/6
|
||||||
}
|
}
|
||||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Deathmist Raptor")) {
|
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Deathmist Raptor")) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return super.doTriggerNoCost(aiPlayer, sa, mandatory);
|
|
||||||
|
return super.doTriggerAINoCost(aiPlayer, sa, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -167,10 +161,10 @@ public class ChooseGenericAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FatespinnerSkipDraw,FatespinnerSkipMain,FatespinnerSkipCombat
|
// FatespinnerSkipDraw,FatespinnerSkipMain,FatespinnerSkipCombat
|
||||||
if (game.getReplacementHandler().wouldPhaseBeSkipped(player, PhaseType.DRAW)) {
|
if (game.getReplacementHandler().wouldPhaseBeSkipped(player, "Draw")) {
|
||||||
return skipDraw;
|
return skipDraw;
|
||||||
}
|
}
|
||||||
if (game.getReplacementHandler().wouldPhaseBeSkipped(player, PhaseType.COMBAT_BEGIN)) {
|
if (game.getReplacementHandler().wouldPhaseBeSkipped(player, "BeginCombat")) {
|
||||||
return skipCombat;
|
return skipCombat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +262,7 @@ public class ChooseGenericAi extends SpellAbilityAi {
|
|||||||
List<SpellAbility> filtered = Lists.newArrayList();
|
List<SpellAbility> filtered = Lists.newArrayList();
|
||||||
// filter first for the spells which can be done
|
// filter first for the spells which can be done
|
||||||
for (SpellAbility sp : spells) {
|
for (SpellAbility sp : spells) {
|
||||||
if (SpellApiToAi.Converter.get(sp).canPlayWithSubs(player, sp).willingToPlay()) {
|
if (SpellApiToAi.Converter.get(sp).canPlayAIWithSubs(player, sp)) {
|
||||||
filtered.add(sp);
|
filtered.add(sp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.AiAttackController;
|
||||||
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
public class ChooseNumberAi extends SpellAbilityAi {
|
public class ChooseNumberAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if (aiLogic.isEmpty()) {
|
if (aiLogic.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingLogic);
|
return false;
|
||||||
} else if (aiLogic.equals("SweepCreatures")) {
|
} else if (aiLogic.equals("SweepCreatures")) {
|
||||||
int maxChoiceLimit = AbilityUtils.calculateAmount(sa.getHostCard(), sa.getParam("Max"), sa);
|
int maxChoiceLimit = AbilityUtils.calculateAmount(sa.getHostCard(), sa.getParam("Max"), sa);
|
||||||
int ownCreatureCount = aiPlayer.getCreaturesInPlay().size();
|
int ownCreatureCount = aiPlayer.getCreaturesInPlay().size();
|
||||||
@@ -27,24 +30,17 @@ public class ChooseNumberAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (refOpp == null) {
|
if (refOpp == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false; // no opponent has any creatures
|
||||||
}
|
}
|
||||||
|
|
||||||
int evalAI = ComputerUtilCard.evaluateCreatureList(aiPlayer.getCreaturesInPlay());
|
int evalAI = ComputerUtilCard.evaluateCreatureList(aiPlayer.getCreaturesInPlay());
|
||||||
int evalOpp = ComputerUtilCard.evaluateCreatureList(refOpp.getCreaturesInPlay());
|
int evalOpp = ComputerUtilCard.evaluateCreatureList(refOpp.getCreaturesInPlay());
|
||||||
|
|
||||||
if (aiPlayer.getLifeLostLastTurn() + aiPlayer.getLifeLostThisTurn() == 0 && evalAI > evalOpp) {
|
if (aiPlayer.getLifeLostLastTurn() + aiPlayer.getLifeLostThisTurn() == 0 && evalAI > evalOpp) {
|
||||||
// we're not pressured and our stuff seems better, don't do it yet
|
return false; // we're not pressured and our stuff seems better, don't do it yet
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ownCreatureCount > oppMaxCreatureCount + 2 || ownCreatureCount < Math.min(oppMaxCreatureCount, maxChoiceLimit)) {
|
return ownCreatureCount > oppMaxCreatureCount + 2 || ownCreatureCount < Math.min(oppMaxCreatureCount, maxChoiceLimit);
|
||||||
// we have more creatures than the opponent, or we have less than the opponent but more than the max choice limit
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// we have less creatures than the opponent and less than the max choice limit
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
@@ -53,17 +49,16 @@ public class ChooseNumberAi extends SpellAbilityAi {
|
|||||||
if (sa.canTarget(opp)) {
|
if (sa.canTarget(opp)) {
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
boolean chance = MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
return canPlay(ai, sa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package forge.ai.ability;
|
|||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtil;
|
import forge.ai.ComputerUtil;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -17,18 +15,18 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class ChoosePlayerAi extends SpellAbilityAi {
|
public class ChoosePlayerAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
return canPlay(ai, sa);
|
return canPlayAI(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
return canPlay(ai, sa);
|
return canPlayAI(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.*;
|
import forge.ai.AiAttackController;
|
||||||
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.ComputerUtilCombat;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.GameObject;
|
import forge.game.GameObject;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
@@ -11,6 +14,7 @@ import forge.game.card.CardCollectionView;
|
|||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
import forge.game.card.CardPredicates;
|
import forge.game.card.CardPredicates;
|
||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
|
import forge.game.cost.Cost;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
@@ -28,13 +32,21 @@ public class ChooseSourceAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(final Player ai, SpellAbility sa) {
|
||||||
// TODO: AI Support! Currently this is copied from AF ChooseCard.
|
// TODO: AI Support! Currently this is copied from AF ChooseCard.
|
||||||
// When implementing AI, I believe AI also needs to be made aware of the damage sources chosen
|
// When implementing AI, I believe AI also needs to be made aware of the damage sources chosen
|
||||||
// to be prevented (e.g. so the AI doesn't attack with a creature that will not deal any damage
|
// to be prevented (e.g. so the AI doesn't attack with a creature that will not deal any damage
|
||||||
// to the player because a CoP was pre-activated on it - unless, of course, there's another
|
// to the player because a CoP was pre-activated on it - unless, of course, there's another
|
||||||
// possible reason to attack with that creature).
|
// possible reason to attack with that creature).
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
|
final Cost abCost = sa.getPayCosts();
|
||||||
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
|
if (abCost != null) {
|
||||||
|
if (!willPayCosts(ai, sa, abCost, source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
@@ -42,7 +54,7 @@ public class ChooseSourceAi extends SpellAbilityAi {
|
|||||||
if (sa.canTarget(opp)) {
|
if (sa.canTarget(opp)) {
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sa.hasParam("AILogic")) {
|
if (sa.hasParam("AILogic")) {
|
||||||
@@ -51,11 +63,11 @@ public class ChooseSourceAi extends SpellAbilityAi {
|
|||||||
if (!game.getStack().isEmpty()) {
|
if (!game.getStack().isEmpty()) {
|
||||||
final SpellAbility topStack = game.getStack().peekAbility();
|
final SpellAbility topStack = game.getStack().peekAbility();
|
||||||
if (sa.hasParam("Choices") && !topStack.matchesValid(topStack.getHostCard(), sa.getParam("Choices").split(","))) {
|
if (sa.hasParam("Choices") && !topStack.matchesValid(topStack.getHostCard(), sa.getParam("Choices").split(","))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
final ApiType threatApi = topStack.getApi();
|
final ApiType threatApi = topStack.getApi();
|
||||||
if (threatApi != ApiType.DealDamage && threatApi != ApiType.DamageAll) {
|
if (threatApi != ApiType.DealDamage && threatApi != ApiType.DamageAll) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card threatSource = topStack.getHostCard();
|
final Card threatSource = topStack.getHostCard();
|
||||||
@@ -67,17 +79,13 @@ public class ChooseSourceAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!objects.contains(ai) || topStack.hasParam("NoPrevention")) {
|
if (!objects.contains(ai) || topStack.hasParam("NoPrevention")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
int dmg = AbilityUtils.calculateAmount(threatSource, topStack.getParam("NumDmg"), topStack);
|
int dmg = AbilityUtils.calculateAmount(threatSource, topStack.getParam("NumDmg"), topStack);
|
||||||
if (ComputerUtilCombat.predictDamageTo(ai, dmg, threatSource, false) > 0) {
|
return ComputerUtilCombat.predictDamageTo(ai, dmg, threatSource, false) > 0;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (game.getPhaseHandler().getPhase() != PhaseType.COMBAT_DECLARE_BLOCKERS) {
|
if (game.getPhaseHandler().getPhase() != PhaseType.COMBAT_DECLARE_BLOCKERS) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
CardCollectionView choices = game.getCardsIn(ZoneType.Battlefield);
|
CardCollectionView choices = game.getCardsIn(ZoneType.Battlefield);
|
||||||
if (sa.hasParam("Choices")) {
|
if (sa.hasParam("Choices")) {
|
||||||
@@ -90,13 +98,11 @@ public class ChooseSourceAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
return ComputerUtilCombat.damageIfUnblocked(c, ai, combat, true) > 0;
|
return ComputerUtilCombat.damageIfUnblocked(c, ai, combat, true) > 0;
|
||||||
});
|
});
|
||||||
if (choices.isEmpty()) {
|
return !choices.isEmpty();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,37 +21,23 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class ChooseTypeAi extends SpellAbilityAi {
|
public class ChooseTypeAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if (aiLogic.isEmpty()) {
|
if (aiLogic.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingLogic);
|
return false;
|
||||||
} else if ("MostProminentComputerControls".equals(aiLogic)) {
|
} else if ("MostProminentComputerControls".equals(aiLogic)) {
|
||||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Mirror Entity Avatar")) {
|
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Mirror Entity Avatar")) {
|
||||||
if (doMirrorEntityLogic(aiPlayer, sa)) {
|
return doMirrorEntityLogic(aiPlayer, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!chooseType(sa, aiPlayer.getCardsIn(ZoneType.Battlefield)).isEmpty()) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
return !chooseType(sa, aiPlayer.getCardsIn(ZoneType.Battlefield)).isEmpty();
|
||||||
} else if ("MostProminentComputerControlsOrOwns".equals(aiLogic)) {
|
} else if ("MostProminentComputerControlsOrOwns".equals(aiLogic)) {
|
||||||
return !chooseType(sa, aiPlayer.getCardsIn(Arrays.asList(ZoneType.Hand, ZoneType.Battlefield))).isEmpty()
|
return !chooseType(sa, aiPlayer.getCardsIn(Arrays.asList(ZoneType.Hand, ZoneType.Battlefield))).isEmpty();
|
||||||
? new AiAbilityDecision(100, AiPlayDecision.WillPlay)
|
|
||||||
: new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
} else if ("MostProminentOppControls".equals(aiLogic)) {
|
} else if ("MostProminentOppControls".equals(aiLogic)) {
|
||||||
return !chooseType(sa, aiPlayer.getOpponents().getCardsIn(ZoneType.Battlefield)).isEmpty()
|
return !chooseType(sa, aiPlayer.getOpponents().getCardsIn(ZoneType.Battlefield)).isEmpty();
|
||||||
? new AiAbilityDecision(100, AiPlayDecision.WillPlay)
|
|
||||||
: new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return doTriggerNoCost(aiPlayer, sa, false);
|
return doTriggerAINoCost(aiPlayer, sa, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doMirrorEntityLogic(Player aiPlayer, SpellAbility sa) {
|
private boolean doMirrorEntityLogic(Player aiPlayer, SpellAbility sa) {
|
||||||
@@ -115,7 +101,7 @@ public class ChooseTypeAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
boolean isCurse = sa.isCurse();
|
boolean isCurse = sa.isCurse();
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
@@ -147,16 +133,16 @@ public class ChooseTypeAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sa.isTargetNumberValid()) {
|
if (!sa.isTargetNumberValid()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false; // nothing to target?
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (final Player p : AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa)) {
|
for (final Player p : AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa)) {
|
||||||
if (p.isOpponentOf(ai) && !mandatory && !isCurse) {
|
if (p.isOpponentOf(ai) && !mandatory && !isCurse) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String chooseType(SpellAbility sa, CardCollectionView cards) {
|
private String chooseType(SpellAbility sa, CardCollectionView cards) {
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package forge.ai.ability;
|
|||||||
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -24,15 +22,14 @@ public class ClashAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
boolean legalAction = true;
|
boolean legalAction = true;
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
legalAction = selectTarget(aiPlayer, sa);
|
legalAction = selectTarget(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
return legalAction ? new AiAbilityDecision(100, AiPlayDecision.WillPlay)
|
return legalAction;
|
||||||
: new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -42,17 +39,14 @@ public class ClashAi extends SpellAbilityAi {
|
|||||||
* forge.game.spellability.SpellAbility)
|
* forge.game.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
boolean legalAction = true;
|
boolean legalAction = true;
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
legalAction = selectTarget(ai, sa);
|
legalAction = selectTarget(ai, sa);
|
||||||
if (!legalAction) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return legalAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -110,6 +104,7 @@ public class ClashAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !sa.getTargets().isEmpty();
|
return sa.getTargets().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.ai.SpellApiToAi;
|
import forge.ai.SpellApiToAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
@@ -14,8 +12,7 @@ import forge.game.trigger.TriggerType;
|
|||||||
|
|
||||||
public class ClassLevelUpAi extends SpellAbilityAi {
|
public class ClassLevelUpAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
// TODO does leveling up affect combat? Otherwise wait for Main2
|
|
||||||
Card host = sa.getHostCard();
|
Card host = sa.getHostCard();
|
||||||
final int level = host.getClassLevel() + 1;
|
final int level = host.getClassLevel() + 1;
|
||||||
for (StaticAbility stAb : host.getStaticAbilities()) {
|
for (StaticAbility stAb : host.getStaticAbilities()) {
|
||||||
@@ -28,12 +25,12 @@ public class ClassLevelUpAi extends SpellAbilityAi {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SpellAbility effect = t.ensureAbility();
|
SpellAbility effect = t.ensureAbility();
|
||||||
if (!SpellApiToAi.Converter.get(effect).doTrigger(aiPlayer, effect, false)) {
|
if (!SpellApiToAi.Converter.get(effect).doTriggerAI(aiPlayer, effect, false)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class CloakAi extends ManifestBaseAi {
|
|||||||
// (e.g. Grafdigger's Cage)
|
// (e.g. Grafdigger's Cage)
|
||||||
Card topCopy = CardCopyService.getLKICopy(card);
|
Card topCopy = CardCopyService.getLKICopy(card);
|
||||||
topCopy.turnFaceDownNoUpdate();
|
topCopy.turnFaceDownNoUpdate();
|
||||||
topCopy.setCloaked(sa);
|
topCopy.setCloaked(true);
|
||||||
|
|
||||||
if (ComputerUtil.isETBprevented(topCopy)) {
|
if (ComputerUtil.isETBprevented(topCopy)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -20,7 +18,7 @@ import java.util.Map;
|
|||||||
public class CloneAi extends SpellAbilityAi {
|
public class CloneAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Game game = source.getGame();
|
final Game game = source.getGame();
|
||||||
|
|
||||||
@@ -38,6 +36,10 @@ public class CloneAi extends SpellAbilityAi {
|
|||||||
// TODO - add some kind of check for during human turn to answer
|
// TODO - add some kind of check for during human turn to answer
|
||||||
// "Can I use this to block something?"
|
// "Can I use this to block something?"
|
||||||
|
|
||||||
|
if (!checkPhaseRestrictions(ai, sa, game.getPhaseHandler())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
PhaseHandler phase = game.getPhaseHandler();
|
PhaseHandler phase = game.getPhaseHandler();
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
@@ -64,19 +66,18 @@ public class CloneAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!bFlag) { // All of the defined stuff is cloned, not very useful
|
if (!bFlag) { // All of the defined stuff is cloned, not very useful
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
useAbility &= cloneTgtAI(sa);
|
useAbility &= cloneTgtAI(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
return useAbility ? new AiAbilityDecision(100, AiPlayDecision.WillPlay)
|
return useAbility;
|
||||||
: new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
} // end cloneCanPlayAI()
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
// AI should only activate this during Human's turn
|
// AI should only activate this during Human's turn
|
||||||
boolean chance = true;
|
boolean chance = true;
|
||||||
|
|
||||||
@@ -84,12 +85,11 @@ public class CloneAi extends SpellAbilityAi {
|
|||||||
chance = cloneTgtAI(sa);
|
chance = cloneTgtAI(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
return chance ? new AiAbilityDecision(100, AiPlayDecision.WillPlay)
|
return chance;
|
||||||
: new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
Card host = sa.getHostCard();
|
Card host = sa.getHostCard();
|
||||||
boolean chance = true;
|
boolean chance = true;
|
||||||
|
|
||||||
@@ -111,11 +111,7 @@ public class CloneAi extends SpellAbilityAi {
|
|||||||
// Eventually, we can call the trigger of ETB abilities with
|
// Eventually, we can call the trigger of ETB abilities with
|
||||||
// not mandatory as part of the checks to cast something
|
// not mandatory as part of the checks to cast something
|
||||||
|
|
||||||
if (mandatory || chance) {
|
return chance || mandatory;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtil;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.ComputerUtilMana;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardCollection;
|
import forge.game.card.CardCollection;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
@@ -11,16 +13,9 @@ import forge.game.zone.ZoneType;
|
|||||||
|
|
||||||
public class ConniveAi extends SpellAbilityAi {
|
public class ConniveAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
if (!ai.canDraw()) {
|
if (!ai.canDraw()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false; // can't draw anything
|
||||||
}
|
|
||||||
|
|
||||||
Card host = sa.getHostCard();
|
|
||||||
|
|
||||||
final int num = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("ConniveNum", "1"), sa);
|
|
||||||
if (num == 0) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection list = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
CardCollection list = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
@@ -38,7 +33,7 @@ public class ConniveAi extends SpellAbilityAi {
|
|||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
while (sa.canAddMoreTarget()) {
|
while (sa.canAddMoreTarget()) {
|
||||||
if ((list.isEmpty() && sa.isTargetNumberValid() && !sa.getTargets().isEmpty())) {
|
if ((list.isEmpty() && sa.isTargetNumberValid() && !sa.getTargets().isEmpty())) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
@@ -50,7 +45,7 @@ public class ConniveAi extends SpellAbilityAi {
|
|||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
// Not mandatory, or the the list was regenerated and is still empty,
|
// Not mandatory, or the the list was regenerated and is still empty,
|
||||||
// so return whether or not we found enough targets
|
// so return whether or not we found enough targets
|
||||||
return new AiAbilityDecision(sa.isTargetNumberValid() ? 100 : 0, sa.isTargetNumberValid() ? AiPlayDecision.WillPlay : AiPlayDecision.CantPlayAi);
|
return sa.isTargetNumberValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Card choice = ComputerUtilCard.getBestCreatureAI(list);
|
Card choice = ComputerUtilCard.getBestCreatureAI(list);
|
||||||
@@ -63,17 +58,13 @@ public class ConniveAi extends SpellAbilityAi {
|
|||||||
list.clear();
|
list.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sa.getTargets().isEmpty() && sa.isTargetNumberValid()) {
|
return !sa.getTargets().isEmpty() && sa.isTargetNumberValid();
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (!ai.canDraw() && !mandatory) {
|
if (!ai.canDraw() && !mandatory) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false; // can't draw anything
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean preferred = true;
|
boolean preferred = true;
|
||||||
@@ -86,7 +77,7 @@ public class ConniveAi extends SpellAbilityAi {
|
|||||||
while (sa.canAddMoreTarget()) {
|
while (sa.canAddMoreTarget()) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
if ((list.isEmpty() || !preferred) && sa.isTargetNumberValid()) {
|
if ((list.isEmpty() || !preferred) && sa.isTargetNumberValid()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.isEmpty() && preferred) {
|
if (list.isEmpty() && preferred) {
|
||||||
@@ -99,13 +90,14 @@ public class ConniveAi extends SpellAbilityAi {
|
|||||||
// Still an empty list, but we have to choose something (mandatory); expand targeting to
|
// Still an empty list, but we have to choose something (mandatory); expand targeting to
|
||||||
// include AI's own cards to see if there's anything targetable (e.g. Plague Belcher).
|
// include AI's own cards to see if there's anything targetable (e.g. Plague Belcher).
|
||||||
list = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
list = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
|
preferred = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
// Not mandatory, or the the list was regenerated and is still empty,
|
// Not mandatory, or the the list was regenerated and is still empty,
|
||||||
// so return whether or not we found enough targets
|
// so return whether or not we found enough targets
|
||||||
return new AiAbilityDecision(sa.isTargetNumberValid() ? 100 : 0, sa.isTargetNumberValid() ? AiPlayDecision.WillPlay : AiPlayDecision.CantPlayAi);
|
return sa.isTargetNumberValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Card choice = ComputerUtilCard.getBestCreatureAI(list);
|
Card choice = ComputerUtilCard.getBestCreatureAI(list);
|
||||||
@@ -118,10 +110,7 @@ public class ConniveAi extends SpellAbilityAi {
|
|||||||
list.clear();
|
list.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(
|
return true;
|
||||||
sa.isTargetNumberValid() && !sa.getTargets().isEmpty() ? 100 : 0,
|
|
||||||
sa.isTargetNumberValid() ? AiPlayDecision.WillPlay : AiPlayDecision.TargetingFailed
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.SpecialCardAi;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardCollection;
|
import forge.game.card.CardCollection;
|
||||||
@@ -11,6 +13,7 @@ import forge.game.player.Player;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
public class ControlExchangeAi extends SpellAbilityAi {
|
public class ControlExchangeAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@@ -18,7 +21,7 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, final SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, final SpellAbility sa) {
|
||||||
Card object1 = null;
|
Card object1 = null;
|
||||||
Card object2 = null;
|
Card object2 = null;
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
@@ -38,40 +41,35 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
sa.getTargets().add(object2);
|
sa.getTargets().add(object2);
|
||||||
}
|
}
|
||||||
if (object1 == null || object2 == null) {
|
if (object1 == null || object2 == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
if (ComputerUtilCard.evaluateCreature(object1) > ComputerUtilCard.evaluateCreature(object2) + 40) {
|
if (ComputerUtilCard.evaluateCreature(object1) > ComputerUtilCard.evaluateCreature(object2) + 40) {
|
||||||
sa.getTargets().add(object1);
|
sa.getTargets().add(object1);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
AiAbilityDecision decision = chkDrawback(sa, aiPlayer);
|
return chkAIDrawback(sa, aiPlayer) || sa.isTargetNumberValid();
|
||||||
if (sa.isTargetNumberValid()) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return decision;
|
|
||||||
} else {
|
} else {
|
||||||
return canPlay(aiPlayer, sa);
|
return canPlayAI(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
@@ -92,7 +90,7 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
list = CardLists.getTargetableCards(list, sa);
|
list = CardLists.getTargetableCards(list, sa);
|
||||||
|
|
||||||
if (list.isEmpty())
|
if (list.isEmpty())
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
|
|
||||||
Card best = ComputerUtilCard.getBestAI(list);
|
Card best = ComputerUtilCard.getBestAI(list);
|
||||||
|
|
||||||
@@ -108,7 +106,7 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// Defined card is better than this one, try to avoid trade
|
// Defined card is better than this one, try to avoid trade
|
||||||
if (!best.equals(realBest)) {
|
if (!best.equals(realBest)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,10 +115,10 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
return doTrigTwoTargetsLogic(aiPlayer, sa, best);
|
return doTrigTwoTargetsLogic(aiPlayer, sa, best);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doTrigTwoTargetsLogic(Player ai, SpellAbility sa, Card bestFirstTgt) {
|
private boolean doTrigTwoTargetsLogic(Player ai, SpellAbility sa, Card bestFirstTgt) {
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
final int creatureThreshold = 100; // TODO: make this configurable from the AI profile
|
final int creatureThreshold = 100; // TODO: make this configurable from the AI profile
|
||||||
final int nonCreatureThreshold = 2;
|
final int nonCreatureThreshold = 2;
|
||||||
@@ -132,30 +130,30 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
list = CardLists.getTargetableCards(list, sa);
|
list = CardLists.getTargetableCards(list, sa);
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Card aiWorst = ComputerUtilCard.getWorstAI(list);
|
Card aiWorst = ComputerUtilCard.getWorstAI(list);
|
||||||
if (aiWorst == null) {
|
if (aiWorst == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aiWorst != bestFirstTgt) {
|
if (aiWorst != bestFirstTgt) {
|
||||||
if (bestFirstTgt.isCreature() && aiWorst.isCreature()) {
|
if (bestFirstTgt.isCreature() && aiWorst.isCreature()) {
|
||||||
if ((ComputerUtilCard.evaluateCreature(bestFirstTgt) > ComputerUtilCard.evaluateCreature(aiWorst) + creatureThreshold) || sa.isMandatory()) {
|
if ((ComputerUtilCard.evaluateCreature(bestFirstTgt) > ComputerUtilCard.evaluateCreature(aiWorst) + creatureThreshold) || sa.isMandatory()) {
|
||||||
sa.getTargets().add(aiWorst);
|
sa.getTargets().add(aiWorst);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: compare non-creatures by CMC - can be improved, at least shouldn't give control of things like the Power Nine
|
// TODO: compare non-creatures by CMC - can be improved, at least shouldn't give control of things like the Power Nine
|
||||||
if ((bestFirstTgt.getCMC() > aiWorst.getCMC() + nonCreatureThreshold) || sa.isMandatory()) {
|
if ((bestFirstTgt.getCMC() > aiWorst.getCMC() + nonCreatureThreshold) || sa.isMandatory()) {
|
||||||
sa.getTargets().add(aiWorst);
|
sa.getTargets().add(aiWorst);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.clearTargets();
|
sa.clearTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class ControlGainAi extends SpellAbilityAi {
|
public class ControlGainAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(final Player ai, final SpellAbility sa) {
|
protected boolean canPlayAI(final Player ai, final SpellAbility sa) {
|
||||||
final List<String> lose = Lists.newArrayList();
|
final List<String> lose = Lists.newArrayList();
|
||||||
|
|
||||||
if (sa.hasParam("LoseControl")) {
|
if (sa.hasParam("LoseControl")) {
|
||||||
@@ -81,30 +81,22 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
if (sa.hasParam("AllValid")) {
|
if (sa.hasParam("AllValid")) {
|
||||||
CardCollectionView tgtCards = opponents.getCardsIn(ZoneType.Battlefield);
|
CardCollectionView tgtCards = opponents.getCardsIn(ZoneType.Battlefield);
|
||||||
tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa);
|
tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa);
|
||||||
|
return !tgtCards.isEmpty();
|
||||||
if (tgtCards.isEmpty()) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (sa.hasParam("TargetingPlayer")) {
|
if (sa.hasParam("TargetingPlayer")) {
|
||||||
Player targetingPlayer = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("TargetingPlayer"), sa).get(0);
|
Player targetingPlayer = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("TargetingPlayer"), sa).get(0);
|
||||||
sa.setTargetingPlayer(targetingPlayer);
|
sa.setTargetingPlayer(targetingPlayer);
|
||||||
if (targetingPlayer.getController().chooseTargetsFor(sa)) {
|
return targetingPlayer.getController().chooseTargetsFor(sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tgt.canOnlyTgtOpponent()) {
|
if (tgt.canOnlyTgtOpponent()) {
|
||||||
List<Player> oppList = opponents.filter(PlayerPredicates.isTargetableBy(sa));
|
List<Player> oppList = opponents.filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
|
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tgt.isRandomTarget()) {
|
if (tgt.isRandomTarget()) {
|
||||||
@@ -119,12 +111,12 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
if (lose.contains("EOT")
|
if (lose.contains("EOT")
|
||||||
&& game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|
&& game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|
||||||
&& !sa.isTrigger()) {
|
&& !sa.isTrigger()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("Defined")) {
|
if (sa.hasParam("Defined")) {
|
||||||
// no need to target, we'll pick up the target from Defined
|
// no need to target, we'll pick up the target from Defined
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection list = opponents.getCardsIn(ZoneType.Battlefield);
|
CardCollection list = opponents.getCardsIn(ZoneType.Battlefield);
|
||||||
@@ -173,7 +165,7 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int creatures = 0, artifacts = 0, planeswalkers = 0, lands = 0, enchantments = 0;
|
int creatures = 0, artifacts = 0, planeswalkers = 0, lands = 0, enchantments = 0;
|
||||||
@@ -202,7 +194,7 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
if ((sa.getTargets().size() < tgt.getMinTargets(sa.getHostCard(), sa)) || (sa.getTargets().size() == 0)) {
|
if ((sa.getTargets().size() < tgt.getMinTargets(sa.getHostCard(), sa)) || (sa.getTargets().size() == 0)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -213,9 +205,6 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
while (t == null) {
|
while (t == null) {
|
||||||
// filter by MustTarget requirement
|
// filter by MustTarget requirement
|
||||||
CardCollection originalList = new CardCollection(list);
|
CardCollection originalList = new CardCollection(list);
|
||||||
|
|
||||||
list = CardLists.canSubsequentlyTarget(list, sa);
|
|
||||||
|
|
||||||
boolean mustTargetFiltered = StaticAbilityMustTarget.filterMustTargetCards(ai, list, sa);
|
boolean mustTargetFiltered = StaticAbilityMustTarget.filterMustTargetCards(ai, list, sa);
|
||||||
|
|
||||||
if (planeswalkers > 0) {
|
if (planeswalkers > 0) {
|
||||||
@@ -265,41 +254,39 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(
|
return true;
|
||||||
sa.isTargetNumberValid() ? 100 : 0,
|
|
||||||
sa.isTargetNumberValid() ? AiPlayDecision.WillPlay : AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sa.hasParam("TargetingPlayer") || (mandatory && !this.canPlay(ai, sa).willingToPlay())) {
|
if (sa.hasParam("TargetingPlayer") || (!this.canPlayAI(ai, sa) && mandatory)) {
|
||||||
if (sa.getTargetRestrictions().canOnlyTgtOpponent()) {
|
if (sa.getTargetRestrictions().canOnlyTgtOpponent()) {
|
||||||
List<Player> oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
List<Player> oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
if (oppList.isEmpty()) {
|
if (oppList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getTargets().add(Aggregates.random(oppList));
|
sa.getTargets().add(Aggregates.random(oppList));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> list = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
List<Card> list = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(list));
|
sa.getTargets().add(ComputerUtilCard.getWorstAI(list));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, final Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, final Player ai) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
|
|
||||||
// Special card logic that is processed elsewhere
|
// Special card logic that is processed elsewhere
|
||||||
@@ -315,7 +302,7 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
CardCollectionView tgtCards = ai.getOpponents().getCardsIn(ZoneType.Battlefield);
|
CardCollectionView tgtCards = ai.getOpponents().getCardsIn(ZoneType.Battlefield);
|
||||||
tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa);
|
tgtCards = AbilityUtils.filterListByType(tgtCards, sa.getParam("AllValid"), sa);
|
||||||
if (tgtCards.isEmpty()) {
|
if (tgtCards.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final List<String> lose = Lists.newArrayList();
|
final List<String> lose = Lists.newArrayList();
|
||||||
@@ -324,14 +311,10 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
lose.addAll(Lists.newArrayList(sa.getParam("LoseControl").split(",")));
|
lose.addAll(Lists.newArrayList(sa.getParam("LoseControl").split(",")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lose.contains("EOT")
|
return !lose.contains("EOT")
|
||||||
&& game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
|| !game.getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS);
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return this.canPlay(ai, sa);
|
return this.canPlayAI(ai, sa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -43,22 +41,24 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class ControlGainVariantAi extends SpellAbilityAi {
|
public class ControlGainVariantAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(final Player ai, final SpellAbility sa) {
|
protected boolean canPlayAI(final Player ai, final SpellAbility sa) {
|
||||||
|
|
||||||
String logic = sa.getParam("AILogic");
|
String logic = sa.getParam("AILogic");
|
||||||
|
|
||||||
if ("GainControlOwns".equals(logic)) {
|
if ("GainControlOwns".equals(logic)) {
|
||||||
List<Card> list = CardLists.filter(ai.getGame().getCardsIn(ZoneType.Battlefield), crd -> crd.isCreature() && !crd.getController().equals(crd.getOwner()));
|
List<Card> list = CardLists.filter(ai.getGame().getCardsIn(ZoneType.Battlefield), crd -> crd.isCreature() && !crd.getController().equals(crd.getOwner()));
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
for (final Card c : list) {
|
for (final Card c : list) {
|
||||||
if (ai.equals(c.getController())) {
|
if (ai.equals(c.getController())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,52 +22,45 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
public class CopyPermanentAi extends SpellAbilityAi {
|
public class CopyPermanentAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
PhaseHandler ph = aiPlayer.getGame().getPhaseHandler();
|
PhaseHandler ph = aiPlayer.getGame().getPhaseHandler();
|
||||||
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ("MomirAvatar".equals(aiLogic)) {
|
if ("MomirAvatar".equals(aiLogic)) {
|
||||||
return SpecialCardAi.MomirVigAvatar.consider(aiPlayer, sa);
|
return SpecialCardAi.MomirVigAvatar.consider(aiPlayer, sa);
|
||||||
} else if ("MimicVat".equals(aiLogic)) {
|
} else if ("MimicVat".equals(aiLogic)) {
|
||||||
return SpecialCardAi.MimicVat.considerCopy(aiPlayer, sa);
|
return SpecialCardAi.MimicVat.considerCopy(aiPlayer, sa);
|
||||||
} else if ("AtEOT".equals(aiLogic)) {
|
} else if ("AtEOT".equals(aiLogic)) {
|
||||||
if (ph.is(PhaseType.END_OF_TURN)) {
|
return ph.is(PhaseType.END_OF_TURN);
|
||||||
if (ph.getPlayerTurn() == aiPlayer) {
|
} else if ("AtOppEOT".equals(aiLogic)) {
|
||||||
// If it's the AI's turn, it can activate at EOT
|
return ph.is(PhaseType.END_OF_TURN) && ph.getPlayerTurn() != aiPlayer;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
} else if ("DuplicatePerms".equals(aiLogic)) {
|
||||||
} else {
|
|
||||||
// If it's not the AI's turn, it can't activate at EOT
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Not at EOT phase
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForEndOfTurn);
|
|
||||||
}
|
|
||||||
} if ("DuplicatePerms".equals(aiLogic)) {
|
|
||||||
final List<Card> valid = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
final List<Card> valid = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
||||||
if (valid.size() < 2) {
|
if (valid.size() < 2) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("AtEOT") && !ph.is(PhaseType.MAIN1)) {
|
if (sa.hasParam("AtEOT") && !ph.is(PhaseType.MAIN1)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("Defined")) {
|
if (sa.hasParam("Defined")) {
|
||||||
// If there needs to be an imprinted card, don't activate the ability if nothing was imprinted yet (e.g. Mimic Vat)
|
// If there needs to be an imprinted card, don't activate the ability if nothing was imprinted yet (e.g. Mimic Vat)
|
||||||
if (sa.getParam("Defined").equals("Imprinted.ExiledWithSource") && source.getImprintedCards().isEmpty()) {
|
if (sa.getParam("Defined").equals("Imprinted.ExiledWithSource") && source.getImprintedCards().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.isEmbalm() || sa.isEternalize()) {
|
if (sa.isEmbalm() || sa.isEternalize()) {
|
||||||
// E.g. Vizier of Many Faces: check to make sure it makes sense to make the token now
|
// E.g. Vizier of Many Faces: check to make sure it makes sense to make the token now
|
||||||
AiPlayDecision decision = ComputerUtilCard.checkNeedsToPlayReqs(sa.getHostCard(), sa);
|
if (ComputerUtilCard.checkNeedsToPlayReqs(sa.getHostCard(), sa) != AiPlayDecision.WillPlay) {
|
||||||
|
return false;
|
||||||
if (decision != AiPlayDecision.WillPlay) {
|
|
||||||
return new AiAbilityDecision(0, decision);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,45 +75,37 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
|||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
Player targetingPlayer = AbilityUtils.getDefinedPlayers(source, sa.getParam("TargetingPlayer"), sa).get(0);
|
Player targetingPlayer = AbilityUtils.getDefinedPlayers(source, sa.getParam("TargetingPlayer"), sa).get(0);
|
||||||
sa.setTargetingPlayer(targetingPlayer);
|
sa.setTargetingPlayer(targetingPlayer);
|
||||||
if (targetingPlayer.getController().chooseTargetsFor(sa)) {
|
return targetingPlayer.getController().chooseTargetsFor(sa);
|
||||||
if (sa.isTargetNumberValid()) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else if (sa.usesTargeting() && sa.getTargetRestrictions().canTgtPlayer()) {
|
} else if (sa.usesTargeting() && sa.getTargetRestrictions().canTgtPlayer()) {
|
||||||
if (!sa.isCurse()) {
|
if (!sa.isCurse()) {
|
||||||
if (sa.canTarget(aiPlayer)) {
|
if (sa.canTarget(aiPlayer)) {
|
||||||
sa.getTargets().add(aiPlayer);
|
sa.getTargets().add(aiPlayer);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (Player p : aiPlayer.getYourTeam()) {
|
for (Player p : aiPlayer.getYourTeam()) {
|
||||||
if (sa.canTarget(p)) {
|
if (sa.canTarget(p)) {
|
||||||
sa.getTargets().add(p);
|
sa.getTargets().add(p);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Player p : aiPlayer.getOpponents()) {
|
for (Player p : aiPlayer.getOpponents()) {
|
||||||
if (sa.canTarget(p)) {
|
if (sa.canTarget(p)) {
|
||||||
sa.getTargets().add(p);
|
sa.getTargets().add(p);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return doTriggerNoCost(aiPlayer, sa, false);
|
return doTriggerAINoCost(aiPlayer, sa, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
final Player activator = sa.getActivatingPlayer();
|
final Player activator = sa.getActivatingPlayer();
|
||||||
final Game game = host.getGame();
|
final Game game = host.getGame();
|
||||||
@@ -143,13 +128,13 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
//Nothing to target
|
//Nothing to target
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection betterList = CardLists.filter(list, CardPredicates.isRemAIDeck().negate());
|
CardCollection betterList = CardLists.filter(list, CardPredicates.isRemAIDeck().negate());
|
||||||
if (betterList.isEmpty()) {
|
if (betterList.isEmpty()) {
|
||||||
if (!mandatory) {
|
if (!mandatory) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list = betterList;
|
list = betterList;
|
||||||
@@ -161,18 +146,16 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
|||||||
if (felidarGuardian.size() > 0) {
|
if (felidarGuardian.size() > 0) {
|
||||||
// can copy a Felidar Guardian and combo off, so let's do it
|
// can copy a Felidar Guardian and combo off, so let's do it
|
||||||
sa.getTargets().add(felidarGuardian.get(0));
|
sa.getTargets().add(felidarGuardian.get(0));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// target loop
|
// target loop
|
||||||
while (sa.canAddMoreTarget()) {
|
while (sa.canAddMoreTarget()) {
|
||||||
list = CardLists.canSubsequentlyTarget(list, sa);
|
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
if (!sa.isTargetNumberValid() || sa.getTargets().isEmpty()) {
|
if (!sa.isTargetNumberValid() || sa.getTargets().size() == 0) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -192,9 +175,9 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (choice == null) { // can't find anything left
|
if (choice == null) { // can't find anything left
|
||||||
if (!sa.isTargetNumberValid() || sa.getTargets().isEmpty()) {
|
if (!sa.isTargetNumberValid() || sa.getTargets().size() == 0) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -209,22 +192,20 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
|||||||
choices = CardLists.getValidCards(choices, sa.getParam("Choices"), activator, host, sa);
|
choices = CardLists.getValidCards(choices, sa.getParam("Choices"), activator, host, sa);
|
||||||
Collection<Card> betterChoices = getBetterOptions(aiPlayer, sa, choices, !mandatory);
|
Collection<Card> betterChoices = getBetterOptions(aiPlayer, sa, choices, !mandatory);
|
||||||
if (betterChoices.isEmpty()) {
|
if (betterChoices.isEmpty()) {
|
||||||
if (mandatory) {
|
return mandatory;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// if no targeting, it should always be ok
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("TriggeredCardController".equals(sa.getParam("Controller"))) {
|
if ("TriggeredCardController".equals(sa.getParam("Controller"))) {
|
||||||
Card trigCard = (Card)sa.getTriggeringObject(AbilityKey.Card);
|
Card trigCard = (Card)sa.getTriggeringObject(AbilityKey.Card);
|
||||||
if (!mandatory && trigCard != null && trigCard.getController().isOpponentOf(aiPlayer)) {
|
if (!mandatory && trigCard != null && trigCard.getController().isOpponentOf(aiPlayer)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -17,15 +17,14 @@ import java.util.Map;
|
|||||||
public class CopySpellAbilityAi extends SpellAbilityAi {
|
public class CopySpellAbilityAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
Game game = aiPlayer.getGame();
|
Game game = aiPlayer.getGame();
|
||||||
int chance = ((PlayerControllerAi)aiPlayer.getController()).getAi().getIntProperty(AiProps.CHANCE_TO_COPY_OWN_SPELL_WHILE_ON_STACK);
|
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);
|
int diff = ((PlayerControllerAi)aiPlayer.getController()).getAi().getIntProperty(AiProps.ALWAYS_COPY_SPELL_IF_CMC_DIFF);
|
||||||
String logic = sa.getParamOrDefault("AILogic", "");
|
String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if (game.getStack().isEmpty()) {
|
if (game.getStack().isEmpty()) {
|
||||||
boolean result = sa.isMandatory() || "Always".equals(logic);
|
return sa.isMandatory() || "Always".equals(logic);
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final SpellAbility top = game.getStack().peekAbility();
|
final SpellAbility top = game.getStack().peekAbility();
|
||||||
@@ -42,40 +41,47 @@ public class CopySpellAbilityAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!MyRandom.percentTrue(chance)
|
if (!MyRandom.percentTrue(chance)
|
||||||
&& !"Always".equals(logic)
|
&& !"AlwaysIfViable".equals(logic)
|
||||||
|
&& !"OnceIfViable".equals(logic)
|
||||||
&& !"AlwaysCopyActivatedAbilities".equals(logic)) {
|
&& !"AlwaysCopyActivatedAbilities".equals(logic)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("OnceIfViable".equals(logic)) {
|
||||||
|
if (AiCardMemory.isRememberedCard(aiPlayer, sa.getHostCard(), AiCardMemory.MemorySet.ACTIVATED_THIS_TURN)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
// Filter AI-specific targets if provided
|
// Filter AI-specific targets if provided
|
||||||
if ("OnlyOwned".equals(sa.getParam("AITgts"))) {
|
if ("OnlyOwned".equals(sa.getParam("AITgts"))) {
|
||||||
if (!top.getActivatingPlayer().equals(aiPlayer)) {
|
if (!top.getActivatingPlayer().equals(aiPlayer)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (top.isWrapper() || top.isActivatedAbility()) {
|
if (top.isWrapper() || top.isActivatedAbility()) {
|
||||||
// Shouldn't even try with triggered or wrapped abilities at this time, will crash
|
// Shouldn't even try with triggered or wrapped abilities at this time, will crash
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (top.getApi() == ApiType.CopySpellAbility) {
|
} else if (top.getApi() == ApiType.CopySpellAbility) {
|
||||||
// Don't try to copy a copy ability, too complex for the AI to handle
|
// Don't try to copy a copy ability, too complex for the AI to handle
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (top.getApi() == ApiType.Mana) {
|
} else if (top.getApi() == ApiType.Mana) {
|
||||||
// would lead to Stack Overflow by trying to play this again
|
// would lead to Stack Overflow by trying to play this again
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (top.getApi() == ApiType.DestroyAll || top.getApi() == ApiType.SacrificeAll || top.getApi() == ApiType.ChangeZoneAll || top.getApi() == ApiType.TapAll || top.getApi() == ApiType.UnattachAll) {
|
} 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 (!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
|
// 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
|
// 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 new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (top.hasParam("ConditionManaSpent") || top.getHostCard().hasSVar("AINoCopy")) {
|
} else if (top.hasParam("ConditionManaSpent") || top.getHostCard().hasSVar("AINoCopy")) {
|
||||||
// Mana spent is not copied, so these spells generally do nothing when copied.
|
// Mana spent is not copied, so these spells generally do nothing when copied.
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (ComputerUtilCard.isCardRemAIDeck(top.getHostCard())) {
|
} else if (ComputerUtilCard.isCardRemAIDeck(top.getHostCard())) {
|
||||||
// Don't try to copy anything you can't understand how to handle
|
// Don't try to copy anything you can't understand how to handle
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A copy is necessary to properly test the SA before targeting the copied spell, otherwise the copy SA will fizzle.
|
// A copy is necessary to properly test the SA before targeting the copied spell, otherwise the copy SA will fizzle.
|
||||||
@@ -93,49 +99,32 @@ public class CopySpellAbilityAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
if (decision == AiPlayDecision.WillPlay) {
|
if (decision == AiPlayDecision.WillPlay) {
|
||||||
sa.getTargets().add(top);
|
sa.getTargets().add(top);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
AiCardMemory.rememberCard(aiPlayer, sa.getHostCard(), AiCardMemory.MemorySet.ACTIVATED_THIS_TURN);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, decision);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the AI should not miss mandatory activations
|
// the AI should not miss mandatory activations
|
||||||
boolean result = sa.isMandatory() || "Always".equals(logic);
|
return sa.isMandatory() || "Always".equals(logic);
|
||||||
return result ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
// the AI should not miss mandatory activations (e.g. Precursor Golem trigger)
|
// the AI should not miss mandatory activations (e.g. Precursor Golem trigger)
|
||||||
String logic = sa.getParamOrDefault("AILogic", "");
|
String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
return mandatory || logic.contains("Always"); // this includes logic like AlwaysIfViable
|
||||||
if (mandatory) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logic.contains("Always")) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(final SpellAbility sa, final Player aiPlayer) {
|
public boolean chkAIDrawback(final SpellAbility sa, final Player aiPlayer) {
|
||||||
if ("ChainOfSmog".equals(sa.getParam("AILogic"))) {
|
if ("ChainOfSmog".equals(sa.getParam("AILogic"))) {
|
||||||
return SpecialCardAi.ChainOfSmog.consider(aiPlayer, sa);
|
return SpecialCardAi.ChainOfSmog.consider(aiPlayer, sa);
|
||||||
}
|
} else if ("ChainOfAcid".equals(sa.getParam("AILogic"))) {
|
||||||
if ("ChainOfAcid".equals(sa.getParam("AILogic"))) {
|
|
||||||
return SpecialCardAi.ChainOfAcid.consider(aiPlayer, sa);
|
return SpecialCardAi.ChainOfAcid.consider(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
AiAbilityDecision decision = canPlay(aiPlayer, sa);
|
return canPlayAI(aiPlayer, sa) || (sa.isMandatory() && super.chkAIDrawback(sa, aiPlayer));
|
||||||
if (!decision.willingToPlay()) {
|
|
||||||
if (sa.isMandatory()) {
|
|
||||||
return super.chkDrawback(sa, aiPlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -149,7 +138,7 @@ public class CopySpellAbilityAi extends SpellAbilityAi {
|
|||||||
// Chain of Acid requires special attention here since otherwise the AI will confirm the copy and then
|
// Chain of Acid requires special attention here since otherwise the AI will confirm the copy and then
|
||||||
// run into the necessity of confirming a mandatory Destroy, thus destroying all of its own permanents.
|
// run into the necessity of confirming a mandatory Destroy, thus destroying all of its own permanents.
|
||||||
if ("ChainOfAcid".equals(sa.getParam("AILogic"))) {
|
if ("ChainOfAcid".equals(sa.getParam("AILogic"))) {
|
||||||
return SpecialCardAi.ChainOfAcid.consider(player, sa).willingToPlay();
|
return SpecialCardAi.ChainOfAcid.consider(player, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ import forge.game.zone.ZoneType;
|
|||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
import forge.util.collect.FCollectionView;
|
import forge.util.collect.FCollectionView;
|
||||||
|
|
||||||
|
|
||||||
public class CounterAi extends SpellAbilityAi {
|
public class CounterAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
boolean toReturn = true;
|
boolean toReturn = true;
|
||||||
|
final Cost abCost = sa.getPayCosts();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
@@ -38,12 +40,22 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
SpellAbility tgtSA = null;
|
SpellAbility tgtSA = null;
|
||||||
|
|
||||||
if (game.getStack().isEmpty()) {
|
if (game.getStack().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (abCost != null) {
|
||||||
|
// AI currently disabled for these costs
|
||||||
|
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Force of Will".equals(sourceName)) {
|
if ("Force of Will".equals(sourceName)) {
|
||||||
if (!SpecialCardAi.ForceOfWill.consider(ai, sa)) {
|
if (!SpecialCardAi.ForceOfWill.consider(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,19 +63,19 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
final SpellAbility topSA = ComputerUtilAbility.getTopSpellAbilityOnStack(game, sa);
|
final SpellAbility topSA = ComputerUtilAbility.getTopSpellAbilityOnStack(game, sa);
|
||||||
if ((topSA.isSpell() && !topSA.isCounterableBy(sa)) || ai.getYourTeam().contains(topSA.getActivatingPlayer())) {
|
if ((topSA.isSpell() && !topSA.isCounterableBy(sa)) || ai.getYourTeam().contains(topSA.getActivatingPlayer())) {
|
||||||
// might as well check for player's friendliness
|
// might as well check for player's friendliness
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (sa.hasParam("ConditionWouldDestroy") && !CounterEffect.checkForConditionWouldDestroy(sa, topSA)) {
|
} else if (sa.hasParam("ConditionWouldDestroy") && !CounterEffect.checkForConditionWouldDestroy(sa, topSA)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the top ability on the stack corresponds to the AI-specific targeting declaration, if provided
|
// check if the top ability on the stack corresponds to the AI-specific targeting declaration, if provided
|
||||||
if (sa.hasParam("AITgts") && (topSA.getHostCard() == null
|
if (sa.hasParam("AITgts") && (topSA.getHostCard() == null
|
||||||
|| !topSA.getHostCard().isValid(sa.getParam("AITgts"), sa.getActivatingPlayer(), source, sa))) {
|
|| !topSA.getHostCard().isValid(sa.getParam("AITgts"), sa.getActivatingPlayer(), source, sa))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("CounterNoManaSpell") && topSA.getTotalManaSpent() > 0) {
|
if (sa.hasParam("CounterNoManaSpell") && topSA.getTotalManaSpent() > 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("UnlessCost") && "TargetedController".equals(sa.getParamOrDefault("UnlessPayer", "TargetedController"))) {
|
if (sa.hasParam("UnlessCost") && "TargetedController".equals(sa.getParamOrDefault("UnlessPayer", "TargetedController"))) {
|
||||||
@@ -72,7 +84,7 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
CostDiscard discardCost = unlessCost.getCostPartByType(CostDiscard.class);
|
CostDiscard discardCost = unlessCost.getCostPartByType(CostDiscard.class);
|
||||||
if ("Hand".equals(discardCost.getType())) {
|
if ("Hand".equals(discardCost.getType())) {
|
||||||
if (topSA.getActivatingPlayer().getCardsIn(ZoneType.Hand).size() < 2) {
|
if (topSA.getActivatingPlayer().getCardsIn(ZoneType.Hand).size() < 2) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,11 +100,10 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
tgtCMC += topSA.getPayCosts().getTotalMana().countX() > 0 ? 3 : 0; // TODO: somehow determine the value of X paid and account for it?
|
tgtCMC += topSA.getPayCosts().getTotalMana().countX() > 0 ? 3 : 0; // TODO: somehow determine the value of X paid and account for it?
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This spell doesn't target. Must be a "Coutner All" or "Counter trigger" type of ability.
|
return false;
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String unlessCost = sa.hasParam("UnlessCost") ? sa.getParam("UnlessCost").trim() : null;
|
String unlessCost = sa.hasParam("UnlessCost") ? sa.getParam("UnlessCost").trim() : null;
|
||||||
@@ -111,13 +122,13 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (toPay == 0) {
|
if (toPay == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toPay <= usableManaSources) {
|
if (toPay <= usableManaSources) {
|
||||||
// If this is a reusable Resource, feel free to play it most of the time
|
// If this is a reusable Resource, feel free to play it most of the time
|
||||||
if (!playReusable(ai, sa)) {
|
if (!playReusable(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,15 +147,15 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
if (sa.hasParam("AILogic")) {
|
if (sa.hasParam("AILogic")) {
|
||||||
String logic = sa.getParam("AILogic");
|
String logic = sa.getParam("AILogic");
|
||||||
if ("Never".equals(logic)) {
|
if ("Never".equals(logic)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (logic.startsWith("MinCMC.")) { // TODO fix Daze and fold into AITgts
|
} else if (logic.startsWith("MinCMC.")) { // TODO fix Daze and fold into AITgts
|
||||||
int minCMC = Integer.parseInt(logic.substring(7));
|
int minCMC = Integer.parseInt(logic.substring(7));
|
||||||
if (tgtCMC < minCMC) {
|
if (tgtCMC < minCMC) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if ("NullBrooch".equals(logic)) {
|
} else if ("NullBrooch".equals(logic)) {
|
||||||
if (!SpecialCardAi.NullBrooch.consider(ai, sa)) {
|
if (!SpecialCardAi.NullBrooch.consider(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,40 +234,40 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dontCounter) {
|
if (dontCounter) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
return doTriggerNoCost(aiPlayer, sa, true);
|
return doTriggerAINoCost(aiPlayer, sa, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
if (game.getStack().isEmpty()) {
|
if (game.getStack().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (mandatory && !sa.canAddMoreTarget()) {
|
if (mandatory && !sa.canAddMoreTarget()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
Pair<SpellAbility, Boolean> pair = chooseTargetSpellAbility(game, sa, ai, mandatory);
|
Pair<SpellAbility, Boolean> pair = chooseTargetSpellAbility(game, sa, ai, mandatory);
|
||||||
SpellAbility tgtSA = pair.getLeft();
|
SpellAbility tgtSA = pair.getLeft();
|
||||||
|
|
||||||
if (tgtSA == null) {
|
if (tgtSA == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getTargets().add(tgtSA);
|
sa.getTargets().add(tgtSA);
|
||||||
if (!mandatory && !pair.getRight()) {
|
if (!mandatory && !pair.getRight()) {
|
||||||
// If not mandatory and not preferred, bail out after setting target
|
// If not mandatory and not preferred, bail out after setting target
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String unlessCost = sa.hasParam("UnlessCost") ? sa.getParam("UnlessCost").trim() : null;
|
String unlessCost = sa.hasParam("UnlessCost") ? sa.getParam("UnlessCost").trim() : null;
|
||||||
@@ -277,13 +288,14 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!mandatory) {
|
if (!mandatory) {
|
||||||
if (toPay == 0) {
|
if (toPay == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toPay <= usableManaSources) {
|
if (toPay <= usableManaSources) {
|
||||||
// If this is a reusable Resource, feel free to play it most of the time
|
// If this is a reusable Resource, feel free to play it most
|
||||||
|
// of the time
|
||||||
if (!playReusable(ai,sa) || (MyRandom.getRandom().nextFloat() < .4)) {
|
if (!playReusable(ai,sa) || (MyRandom.getRandom().nextFloat() < .4)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,7 +312,7 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
// force the Human into making decisions)
|
// force the Human into making decisions)
|
||||||
|
|
||||||
// But really it should be more picky about how it counters things
|
// But really it should be more picky about how it counters things
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<SpellAbility, Boolean> chooseTargetSpellAbility(Game game, SpellAbility sa, Player ai, boolean mandatory) {
|
public Pair<SpellAbility, Boolean> chooseTargetSpellAbility(Game game, SpellAbility sa, Player ai, boolean mandatory) {
|
||||||
@@ -350,11 +362,11 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willPayUnlessCost(SpellAbility sa, Player payer, Cost cost, boolean alreadyPaid, FCollectionView<Player> payers) {
|
public boolean willPayUnlessCost(SpellAbility sa, Player payer, Cost cost, boolean alreadyPaid, FCollectionView<Player> payers) {
|
||||||
|
// ward or human misplay
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Game game = source.getGame();
|
final Game game = source.getGame();
|
||||||
List<SpellAbility> spells = AbilityUtils.getDefinedSpellAbilities(source, sa.getParamOrDefault("Defined", "Targeted"), sa);
|
List<SpellAbility> spells = AbilityUtils.getDefinedSpellAbilities(source, sa.getParamOrDefault("Defined", "Targeted"), sa);
|
||||||
for (SpellAbility toBeCountered : spells) {
|
for (SpellAbility toBeCountered : spells) {
|
||||||
// ward or human misplay
|
|
||||||
if (!toBeCountered.isCounterableBy(sa)) {
|
if (!toBeCountered.isCounterableBy(sa)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -369,7 +381,7 @@ public class CounterAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no reason to pay if we don't plan to confirm
|
// no reason to pay if we don't plan to confirm
|
||||||
if (toBeCountered.isOptionalTrigger() && !SpellApiToAi.Converter.get(toBeCountered).doTriggerNoCostWithSubs(payer, toBeCountered, false).willingToPlay()) {
|
if (toBeCountered.isOptionalTrigger() && !SpellApiToAi.Converter.get(toBeCountered).doTriggerNoCostWithSubs(payer, toBeCountered, false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO check hasFizzled
|
// TODO check hasFizzled
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ public abstract class CountersAi extends SpellAbilityAi {
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param list
|
* @param list
|
||||||
* a {@link CardCollectionView} object.
|
* a {@link forge.CardList} object.
|
||||||
* @param type
|
* @param type
|
||||||
* a {@link String} object.
|
* a {@link java.lang.String} object.
|
||||||
* @param amount
|
* @param amount
|
||||||
* a int.
|
* a int.
|
||||||
* @param ai a {@link Player} object.
|
* @param newParam TODO
|
||||||
* @return a {@link Card} object.
|
* @return a {@link forge.game.card.Card} object.
|
||||||
*/
|
*/
|
||||||
public static Card chooseCursedTarget(final CardCollectionView list, final String type, final int amount, final Player ai) {
|
public static Card chooseCursedTarget(final CardCollectionView list, final String type, final int amount, final Player ai) {
|
||||||
Card choice;
|
Card choice;
|
||||||
@@ -65,7 +65,7 @@ public abstract class CountersAi extends SpellAbilityAi {
|
|||||||
// try to kill the best killable creature, or reduce the best one
|
// try to kill the best killable creature, or reduce the best one
|
||||||
// but try not to target a Undying Creature
|
// but try not to target a Undying Creature
|
||||||
final List<Card> killable = CardLists.getNotKeyword(CardLists.filterToughness(list, amount), Keyword.UNDYING);
|
final List<Card> killable = CardLists.getNotKeyword(CardLists.filterToughness(list, amount), Keyword.UNDYING);
|
||||||
if (!killable.isEmpty()) {
|
if (killable.size() > 0) {
|
||||||
choice = ComputerUtilCard.getBestCreatureAI(killable);
|
choice = ComputerUtilCard.getBestCreatureAI(killable);
|
||||||
} else {
|
} else {
|
||||||
choice = ComputerUtilCard.getBestCreatureAI(list);
|
choice = ComputerUtilCard.getBestCreatureAI(list);
|
||||||
@@ -83,10 +83,10 @@ public abstract class CountersAi extends SpellAbilityAi {
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param list
|
* @param list
|
||||||
* a {@link CardCollectionView} object.
|
* a {@link forge.CardList} object.
|
||||||
* @param type
|
* @param type
|
||||||
* a {@link String} object.
|
* a {@link java.lang.String} object.
|
||||||
* @return a {@link Card} object.
|
* @return a {@link forge.game.card.Card} object.
|
||||||
*/
|
*/
|
||||||
public static Card chooseBoonTarget(final CardCollectionView list, final String type) {
|
public static Card chooseBoonTarget(final CardCollectionView list, final String type) {
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtil;
|
||||||
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
@@ -19,25 +21,19 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class CountersMoveAi extends SpellAbilityAi {
|
public class CountersMoveAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
AiAbilityDecision decision = new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
decision = moveTgtAI(ai, sa);
|
if (!moveTgtAI(ai, sa)) {
|
||||||
if (!decision.willingToPlay()) {
|
return false;
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!playReusable(ai, sa)) {
|
if (!playReusable(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MyRandom.getRandom().nextFloat() < .8f) {
|
return MyRandom.getRandom().nextFloat() < .8f; // random success
|
||||||
return decision;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,13 +109,12 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
|
|
||||||
AiAbilityDecision decision = moveTgtAI(ai, sa);
|
if (!moveTgtAI(ai, sa) && !mandatory) {
|
||||||
if (!decision.willingToPlay() && !mandatory) {
|
return false;
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sa.isTargetNumberValid() && mandatory) {
|
if (!sa.isTargetNumberValid() && mandatory) {
|
||||||
@@ -127,18 +122,18 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
List<Card> tgtCards = CardLists.getTargetableCards(game.getCardsIn(ZoneType.Battlefield), sa);
|
List<Card> tgtCards = CardLists.getTargetableCards(game.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
|
|
||||||
if (tgtCards.isEmpty()) {
|
if (tgtCards.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card card = ComputerUtilCard.getWorstAI(tgtCards);
|
final Card card = ComputerUtilCard.getWorstAI(tgtCards);
|
||||||
sa.getTargets().add(card);
|
sa.getTargets().add(card);
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// no target Probably something like Graft
|
// no target Probably something like Graft
|
||||||
|
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
@@ -150,7 +145,7 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
final List<Card> destCards = AbilityUtils.getDefinedCards(host, sa.getParam("Defined"), sa);
|
final List<Card> destCards = AbilityUtils.getDefinedCards(host, sa.getParam("Defined"), sa);
|
||||||
|
|
||||||
if (srcCards.isEmpty() || destCards.isEmpty()) {
|
if (srcCards.isEmpty() || destCards.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card src = srcCards.get(0);
|
final Card src = srcCards.get(0);
|
||||||
@@ -158,21 +153,21 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// for such Trigger, do not move counter to another players creature
|
// for such Trigger, do not move counter to another players creature
|
||||||
if (!dest.getController().equals(ai)) {
|
if (!dest.getController().equals(ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (ComputerUtilCard.isUselessCreature(ai, dest)) {
|
} else if (ComputerUtilCard.isUselessCreature(ai, dest)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (dest.hasSVar("EndOfTurnLeavePlay")) {
|
} else if (dest.hasSVar("EndOfTurnLeavePlay")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cType != null) {
|
if (cType != null) {
|
||||||
if (!dest.canReceiveCounters(cType)) {
|
if (!dest.canReceiveCounters(cType)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
final int amount = calcAmount(sa, cType);
|
final int amount = calcAmount(sa, cType);
|
||||||
int a = src.getCounters(cType);
|
int a = src.getCounters(cType);
|
||||||
if (a < amount) {
|
if (a < amount) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card srcCopy = CardCopyService.getLKICopy(src);
|
final Card srcCopy = CardCopyService.getLKICopy(src);
|
||||||
@@ -186,31 +181,27 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
int newEval = ComputerUtilCard.evaluateCreature(srcCopy) + ComputerUtilCard.evaluateCreature(destCopy);
|
int newEval = ComputerUtilCard.evaluateCreature(srcCopy) + ComputerUtilCard.evaluateCreature(destCopy);
|
||||||
|
|
||||||
if (newEval < oldEval) {
|
if (newEval < oldEval) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for some specific AI preferences
|
// check for some specific AI preferences
|
||||||
if ("DontMoveCounterIfLethal".equals(sa.getParam("AILogic"))) {
|
if ("DontMoveCounterIfLethal".equals(sa.getParam("AILogic"))) {
|
||||||
if (!cType.is(CounterEnumType.P1P1) || src.getNetToughness() - src.getTempToughnessBoost() - 1 > 0) {
|
return !cType.is(CounterEnumType.P1P1) || src.getNetToughness() - src.getTempToughnessBoost() - 1 > 0;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no target
|
// no target
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return moveTgtAI(ai, sa);
|
return moveTgtAI(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int calcAmount(final SpellAbility sa, final CounterType cType) {
|
private static int calcAmount(final SpellAbility sa, final CounterType cType) {
|
||||||
@@ -235,7 +226,7 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision moveTgtAI(final Player ai, final SpellAbility sa) {
|
private boolean moveTgtAI(final Player ai, final SpellAbility sa) {
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
final String type = sa.getParam("CounterType");
|
final String type = sa.getParam("CounterType");
|
||||||
@@ -253,7 +244,7 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (destCards.isEmpty()) {
|
if (destCards.isEmpty()) {
|
||||||
// something went wrong
|
// something went wrong
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card dest = destCards.get(0);
|
final Card dest = destCards.get(0);
|
||||||
@@ -262,7 +253,7 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
tgtCards.remove(dest);
|
tgtCards.remove(dest);
|
||||||
|
|
||||||
if (cType != null && !dest.canReceiveCounters(cType)) {
|
if (cType != null && !dest.canReceiveCounters(cType)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prefered logic for this: try to steal counter
|
// prefered logic for this: try to steal counter
|
||||||
@@ -294,7 +285,7 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
sa.getTargets().add(card);
|
sa.getTargets().add(card);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -338,14 +329,14 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
sa.getTargets().add(card);
|
sa.getTargets().add(card);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else if (sa.getMaxTargets() == 2) {
|
} else if (sa.getMaxTargets() == 2) {
|
||||||
// TODO
|
// TODO
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// SA uses target for Defined
|
// SA uses target for Defined
|
||||||
// Source => Targeted
|
// Source => Targeted
|
||||||
@@ -353,12 +344,12 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (srcCards.isEmpty()) {
|
if (srcCards.isEmpty()) {
|
||||||
// something went wrong
|
// something went wrong
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card src = srcCards.get(0);
|
final Card src = srcCards.get(0);
|
||||||
if (cType != null && src.getCounters(cType) <= 0) {
|
if (cType != null && src.getCounters(cType) <= 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Card lkiWithCounters = CardCopyService.getLKICopy(src);
|
Card lkiWithCounters = CardCopyService.getLKICopy(src);
|
||||||
@@ -411,14 +402,14 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
sa.getTargets().add(card);
|
sa.getTargets().add(card);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final boolean isMandatoryTrigger = (sa.isTrigger() && !sa.isOptionalTrigger())
|
final boolean isMandatoryTrigger = (sa.isTrigger() && !sa.isOptionalTrigger())
|
||||||
|| (sa.getRootAbility().isTrigger() && !sa.getRootAbility().isOptionalTrigger());
|
|| (sa.getRootAbility().isTrigger() && !sa.getRootAbility().isOptionalTrigger());
|
||||||
if (!isMandatoryTrigger) {
|
if (!isMandatoryTrigger) {
|
||||||
// no good target
|
// no good target
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,10 +439,10 @@ public class CountersMoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
sa.getTargets().add(card);
|
sa.getTargets().add(card);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtil;
|
||||||
|
import forge.ai.ComputerUtilCost;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
@@ -19,41 +21,42 @@ import java.util.Map;
|
|||||||
public class CountersMultiplyAi extends SpellAbilityAi {
|
public class CountersMultiplyAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
if (sa.usesTargeting()) {
|
|
||||||
return setTargets(ai, sa);
|
|
||||||
}
|
|
||||||
|
|
||||||
final CounterType counterType = getCounterType(sa);
|
final CounterType counterType = getCounterType(sa);
|
||||||
// defined are mostly Self or Creatures you control
|
|
||||||
CardCollection list = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa);
|
|
||||||
|
|
||||||
list = CardLists.filter(list, c -> {
|
if (!sa.usesTargeting()) {
|
||||||
if (!c.hasCounters()) {
|
// defined are mostly Self or Creatures you control
|
||||||
return false;
|
CardCollection list = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa);
|
||||||
}
|
|
||||||
|
|
||||||
if (counterType != null) {
|
list = CardLists.filter(list, c -> {
|
||||||
if (c.getCounters(counterType) <= 0) {
|
if (!c.hasCounters()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!c.canReceiveCounters(counterType)) {
|
|
||||||
return false;
|
if (counterType != null) {
|
||||||
}
|
if (c.getCounters(counterType) <= 0) {
|
||||||
} else {
|
|
||||||
for (Map.Entry<CounterType, Integer> e : c.getCounters().entrySet()) {
|
|
||||||
// has negative counter it would double
|
|
||||||
if (ComputerUtil.isNegativeCounter(e.getKey(), c)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!c.canReceiveCounters(counterType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (Map.Entry<CounterType, Integer> e : c.getCounters().entrySet()) {
|
||||||
|
// has negative counter it would double
|
||||||
|
if (ComputerUtil.isNegativeCounter(e.getKey(), c)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
return true;
|
return setTargets(ai, sa);
|
||||||
});
|
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.checkApiLogic(ai, sa);
|
return super.checkApiLogic(ai, sa);
|
||||||
@@ -82,27 +85,24 @@ public class CountersMultiplyAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
if (setTargets(ai, sa)) {
|
||||||
AiAbilityDecision decision = setTargets(ai, sa);
|
return true;
|
||||||
if (decision.willingToPlay()) {
|
|
||||||
return decision;
|
|
||||||
} else if (mandatory) {
|
} else if (mandatory) {
|
||||||
CardCollection list = CardLists.getTargetableCards(ai.getGame().getCardsIn(ZoneType.Battlefield), sa);
|
CardCollection list = CardLists.getTargetableCards(ai.getGame().getCardsIn(ZoneType.Battlefield), sa);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
Card safeMatch = list.stream()
|
Card safeMatch = list.stream()
|
||||||
.filter(CardPredicates.hasCounters().negate())
|
.filter(CardPredicates.hasCounters().negate())
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
sa.getTargets().add(safeMatch == null ? list.getFirst() : safeMatch);
|
sa.getTargets().add(safeMatch == null ? list.getFirst() : safeMatch);
|
||||||
return new AiAbilityDecision(50, AiPlayDecision.MandatoryPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
return mandatory;
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CounterType getCounterType(SpellAbility sa) {
|
private CounterType getCounterType(SpellAbility sa) {
|
||||||
@@ -117,7 +117,7 @@ public class CountersMultiplyAi extends SpellAbilityAi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision setTargets(Player ai, SpellAbility sa) {
|
private boolean setTargets(Player ai, SpellAbility sa) {
|
||||||
final CounterType counterType = getCounterType(sa);
|
final CounterType counterType = getCounterType(sa);
|
||||||
|
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
@@ -173,10 +173,10 @@ public class CountersMultiplyAi extends SpellAbilityAi {
|
|||||||
// targeting does failed
|
// targeting does failed
|
||||||
if (!sa.isTargetNumberValid() || sa.getTargets().size() == 0) {
|
if (!sa.isTargetNumberValid() || sa.getTargets().size() == 0) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addTargetsByCounterType(final Player ai, final SpellAbility sa, final CardCollection list,
|
private void addTargetsByCounterType(final Player ai, final SpellAbility sa, final CardCollection list,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.util.Map;
|
|||||||
public class CountersProliferateAi extends SpellAbilityAi {
|
public class CountersProliferateAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
final List<Card> cperms = Lists.newArrayList();
|
final List<Card> cperms = Lists.newArrayList();
|
||||||
boolean allyExpOrEnergy = false;
|
boolean allyExpOrEnergy = false;
|
||||||
|
|
||||||
@@ -68,34 +68,25 @@ public class CountersProliferateAi extends SpellAbilityAi {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cperms.isEmpty() || !hperms.isEmpty() || opponentPoison || allyExpOrEnergy) {
|
return !cperms.isEmpty() || !hperms.isEmpty() || opponentPoison || allyExpOrEnergy;
|
||||||
// AI will play it if there are any counters to proliferate
|
|
||||||
// or if there are no counters, but AI has experience or energy counters
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
boolean chance = true;
|
boolean chance = true;
|
||||||
|
|
||||||
// TODO Make sure Human has poison counters or there are some counters
|
// TODO Make sure Human has poison counters or there are some counters
|
||||||
// we want to proliferate
|
// we want to proliferate
|
||||||
return new AiAbilityDecision(
|
return chance;
|
||||||
chance ? 100 : 0,
|
|
||||||
chance ? AiPlayDecision.WillPlay : AiPlayDecision.CantPlayAi
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
* @see forge.card.abilityfactory.SpellAiLogic#chkAIDrawback(java.util.Map, forge.card.spellability.SpellAbility, forge.game.player.Player)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
if ("Always".equals(sa.getParam("AILogic"))) {
|
if ("Always".equals(sa.getParam("AILogic"))) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkApiLogic(ai, sa);
|
return checkApiLogic(ai, sa);
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ public class CountersPutAi extends CountersAi {
|
|||||||
|
|
||||||
// disable moving counters (unless a specialized AI logic supports it)
|
// disable moving counters (unless a specialized AI logic supports it)
|
||||||
for (final CostPart part : cost.getCostParts()) {
|
for (final CostPart part : cost.getCostParts()) {
|
||||||
if (part instanceof CostRemoveCounter remCounter) {
|
if (part instanceof CostRemoveCounter) {
|
||||||
|
final CostRemoveCounter remCounter = (CostRemoveCounter) part;
|
||||||
final CounterType counterType = remCounter.counter;
|
final CounterType counterType = remCounter.counter;
|
||||||
if (counterType.getName().equals(type) && !aiLogic.startsWith("MoveCounter")) {
|
if (counterType.getName().equals(type) && !aiLogic.startsWith("MoveCounter")) {
|
||||||
return false;
|
return false;
|
||||||
@@ -97,7 +98,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.isKeyword(Keyword.LEVEL_UP)) {
|
if (sa.hasParam("LevelUp")) {
|
||||||
// creatures enchanted by curse auras have low priority
|
// creatures enchanted by curse auras have low priority
|
||||||
if (ph.getPhase().isBefore(PhaseType.MAIN2)) {
|
if (ph.getPhase().isBefore(PhaseType.MAIN2)) {
|
||||||
for (Card aura : source.getEnchantedBy()) {
|
for (Card aura : source.getEnchantedBy()) {
|
||||||
@@ -118,7 +119,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, final SpellAbility sa) {
|
||||||
// AI needs to be expanded, since this function can be pretty complex
|
// AI needs to be expanded, since this function can be pretty complex
|
||||||
// based on what the expected targets could be
|
// based on what the expected targets could be
|
||||||
final Cost abCost = sa.getPayCosts();
|
final Cost abCost = sa.getPayCosts();
|
||||||
@@ -159,7 +160,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
PlayerCollection poisonList = oppList.filter(PlayerPredicates.hasCounter(CounterEnumType.POISON, 9));
|
PlayerCollection poisonList = oppList.filter(PlayerPredicates.hasCounter(CounterEnumType.POISON, 9));
|
||||||
if (!poisonList.isEmpty()) {
|
if (!poisonList.isEmpty()) {
|
||||||
sa.getTargets().add(poisonList.max(PlayerPredicates.compareByLife()));
|
sa.getTargets().add(poisonList.max(PlayerPredicates.compareByLife()));
|
||||||
return new AiAbilityDecision(1000, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +176,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
Card best = ComputerUtilCard.getBestAI(oppCreatM1);
|
Card best = ComputerUtilCard.getBestAI(oppCreatM1);
|
||||||
if (best != null) {
|
if (best != null) {
|
||||||
sa.getTargets().add(best);
|
sa.getTargets().add(best);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection aiCreat = CardLists.getTargetableCards(ai.getCreaturesInPlay(), sa);
|
CardCollection aiCreat = CardLists.getTargetableCards(ai.getCreaturesInPlay(), sa);
|
||||||
@@ -195,7 +196,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
best = ComputerUtilCard.getBestAI(aiCreat);
|
best = ComputerUtilCard.getBestAI(aiCreat);
|
||||||
if (best != null) {
|
if (best != null) {
|
||||||
sa.getTargets().add(best);
|
sa.getTargets().add(best);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,22 +205,28 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (!ai.getCounters().isEmpty()) {
|
if (!ai.getCounters().isEmpty()) {
|
||||||
if (!eachExisting || ai.getPoisonCounters() < 5) {
|
if (!eachExisting || ai.getPoisonCounters() < 5) {
|
||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("AlwaysWithNoTgt".equals(logic)) {
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("Never".equals(logic)) {
|
||||||
|
return false;
|
||||||
|
} else if ("AlwaysWithNoTgt".equals(logic)) {
|
||||||
|
return true;
|
||||||
} else if ("AristocratCounters".equals(logic)) {
|
} else if ("AristocratCounters".equals(logic)) {
|
||||||
return SpecialAiLogic.doAristocratWithCountersLogic(ai, sa);
|
return SpecialAiLogic.doAristocratWithCountersLogic(ai, sa);
|
||||||
} else if ("PayEnergy".equals(logic)) {
|
} else if ("PayEnergy".equals(logic)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if ("PayEnergyConservatively".equals(logic)) {
|
} else if ("PayEnergyConservatively".equals(logic)) {
|
||||||
boolean onlyInCombat = ai.getController().isAI()
|
boolean onlyInCombat = ai.getController().isAI()
|
||||||
&& ((PlayerControllerAi) ai.getController()).getAi().getBooleanProperty(AiProps.CONSERVATIVE_ENERGY_PAYMENT_ONLY_IN_COMBAT);
|
&& ((PlayerControllerAi) ai.getController()).getAi().getBooleanProperty(AiProps.CONSERVATIVE_ENERGY_PAYMENT_ONLY_IN_COMBAT);
|
||||||
@@ -228,10 +235,10 @@ public class CountersPutAi extends CountersAi {
|
|||||||
|
|
||||||
if (playAggro) {
|
if (playAggro) {
|
||||||
// aggro profiles ignore conservative play for this AI logic
|
// aggro profiles ignore conservative play for this AI logic
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if (ph.inCombat() && source != null) {
|
} else if (ph.inCombat() && source != null) {
|
||||||
if (ai.getGame().getCombat().isAttacking(source) && !onlyDefensive) {
|
if (ai.getGame().getCombat().isAttacking(source) && !onlyDefensive) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
} else if (ai.getGame().getCombat().isBlocking(source)) {
|
} else if (ai.getGame().getCombat().isBlocking(source)) {
|
||||||
// when blocking, consider this if it's possible to save the blocker and/or kill at least one attacker
|
// when blocking, consider this if it's possible to save the blocker and/or kill at least one attacker
|
||||||
CardCollection blocked = ai.getGame().getCombat().getAttackersBlockedBy(source);
|
CardCollection blocked = ai.getGame().getCombat().getAttackersBlockedBy(source);
|
||||||
@@ -241,27 +248,28 @@ public class CountersPutAi extends CountersAi {
|
|||||||
int numActivations = ai.getCounters(CounterEnumType.ENERGY) / sa.getPayCosts().getCostEnergy().convertAmount();
|
int numActivations = ai.getCounters(CounterEnumType.ENERGY) / sa.getPayCosts().getCostEnergy().convertAmount();
|
||||||
if (source.getNetToughness() + numActivations > totBlkPower
|
if (source.getNetToughness() + numActivations > totBlkPower
|
||||||
|| source.getNetPower() + numActivations >= totBlkToughness) {
|
|| source.getNetPower() + numActivations >= totBlkToughness) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (sa.getSubAbility() != null
|
} else if (sa.getSubAbility() != null
|
||||||
&& "Self".equals(sa.getSubAbility().getParam("Defined"))
|
&& "Self".equals(sa.getSubAbility().getParam("Defined"))
|
||||||
&& sa.getSubAbility().getParamOrDefault("KW", "").contains("Hexproof")
|
&& sa.getSubAbility().getParamOrDefault("KW", "").contains("Hexproof")
|
||||||
&& !source.getAbilityActivatedThisTurn().getActivators(sa).contains(ai)) {
|
&& !AiCardMemory.isRememberedCard(ai, source, AiCardMemory.MemorySet.ANIMATED_THIS_TURN)) {
|
||||||
// Bristling Hydra: save from death using a ping activation
|
// Bristling Hydra: save from death using a ping activation
|
||||||
if (ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa).contains(source)) {
|
if (ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa).contains(source)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
AiCardMemory.rememberCard(ai, source, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else if (ai.getCounters(CounterEnumType.ENERGY) > ComputerUtilCard.getMaxSAEnergyCostOnBattlefield(ai) + sa.getPayCosts().getCostEnergy().convertAmount()) {
|
} else if (ai.getCounters(CounterEnumType.ENERGY) > ComputerUtilCard.getMaxSAEnergyCostOnBattlefield(ai) + sa.getPayCosts().getCostEnergy().convertAmount()) {
|
||||||
// outside of combat, this logic only works if the relevant AI profile option is enabled
|
// outside of combat, this logic only works if the relevant AI profile option is enabled
|
||||||
// and if there is enough energy saved
|
// and if there is enough energy saved
|
||||||
if (!onlyInCombat) {
|
if (!onlyInCombat) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (logic.equals("MarkOppCreature")) {
|
} else if (logic.equals("MarkOppCreature")) {
|
||||||
if (!ph.is(PhaseType.END_OF_TURN)) {
|
if (!ph.is(PhaseType.END_OF_TURN)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForEndOfTurn);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Predicate<Card> predicate = CardPredicates.hasCounter(CounterType.getType(type));
|
Predicate<Card> predicate = CardPredicates.hasCounter(CounterType.getType(type));
|
||||||
@@ -273,12 +281,12 @@ public class CountersPutAi extends CountersAi {
|
|||||||
Card bestCreat = ComputerUtilCard.getBestCreatureAI(oppCreats);
|
Card bestCreat = ComputerUtilCard.getBestCreatureAI(oppCreats);
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(bestCreat);
|
sa.getTargets().add(bestCreat);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else if (logic.equals("CheckDFC")) {
|
} else if (logic.equals("CheckDFC")) {
|
||||||
// for cards like Ludevic's Test Subject
|
// for cards like Ludevic's Test Subject
|
||||||
if (!source.canTransform(null)) {
|
if (!source.canTransform(null)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (logic.startsWith("MoveCounter")) {
|
} else if (logic.startsWith("MoveCounter")) {
|
||||||
return doMoveCounterLogic(ai, sa, ph);
|
return doMoveCounterLogic(ai, sa, ph);
|
||||||
@@ -287,15 +295,8 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (willActivate && ph.getPhase().isBefore(PhaseType.MAIN2)) {
|
if (willActivate && ph.getPhase().isBefore(PhaseType.MAIN2)) {
|
||||||
// don't use this for mana until after combat
|
// don't use this for mana until after combat
|
||||||
AiCardMemory.rememberCard(ai, source, AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2);
|
AiCardMemory.rememberCard(ai, source, AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2);
|
||||||
return new AiAbilityDecision(25, AiPlayDecision.WaitForMain2);
|
|
||||||
}
|
}
|
||||||
|
return willActivate;
|
||||||
if (willActivate) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (logic.equals("ChargeToBestCMC")) {
|
} else if (logic.equals("ChargeToBestCMC")) {
|
||||||
return doChargeToCMCLogic(ai, sa);
|
return doChargeToCMCLogic(ai, sa);
|
||||||
} else if (logic.equals("ChargeToBestOppControlledCMC")) {
|
} else if (logic.equals("ChargeToBestOppControlledCMC")) {
|
||||||
@@ -304,11 +305,15 @@ public class CountersPutAi extends CountersAi {
|
|||||||
return SpecialCardAi.TheOneRing.consider(ai, sa);
|
return SpecialCardAi.TheOneRing.consider(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!sa.metConditions() && sa.getSubAbility() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (sourceName.equals("Feat of Resistance")) { // sub-ability should take precedence
|
if (sourceName.equals("Feat of Resistance")) { // sub-ability should take precedence
|
||||||
CardCollection prot = ProtectAi.getProtectCreatures(ai, sa.getSubAbility());
|
CardCollection prot = ProtectAi.getProtectCreatures(ai, sa.getSubAbility());
|
||||||
if (!prot.isEmpty()) {
|
if (!prot.isEmpty()) {
|
||||||
sa.getTargets().add(prot.get(0));
|
sa.getTargets().add(prot.get(0));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,13 +321,13 @@ public class CountersPutAi extends CountersAi {
|
|||||||
CardCollection creatsYouCtrl = ai.getCreaturesInPlay();
|
CardCollection creatsYouCtrl = ai.getCreaturesInPlay();
|
||||||
List<Card> leastToughness = Aggregates.listWithMin(creatsYouCtrl, Card::getNetToughness);
|
List<Card> leastToughness = Aggregates.listWithMin(creatsYouCtrl, Card::getNetToughness);
|
||||||
if (leastToughness.isEmpty()) {
|
if (leastToughness.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
// TODO If Creature that would be Bolstered for some reason is useless, also return False
|
// TODO If Creature that would be Bolstered for some reason is useless, also return False
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("Monstrosity") && source.isMonstrous()) {
|
if (sa.hasParam("Monstrosity") && source.isMonstrous()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO handle proper calculation of X values based on Cost
|
// TODO handle proper calculation of X values based on Cost
|
||||||
@@ -337,7 +342,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
Combat combat = game.getCombat();
|
Combat combat = game.getCombat();
|
||||||
|
|
||||||
if (!source.canReceiveCounters(CounterType.get(CounterEnumType.P1P1)) || source.getCounters(CounterEnumType.P1P1) > 0) {
|
if (!source.canReceiveCounters(CounterType.get(CounterEnumType.P1P1)) || source.getCounters(CounterEnumType.P1P1) > 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (combat != null && ph.is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
} else if (combat != null && ph.is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||||
return doCombatAdaptLogic(source, amount, combat);
|
return doCombatAdaptLogic(source, amount, combat);
|
||||||
}
|
}
|
||||||
@@ -364,12 +369,12 @@ public class CountersPutAi extends CountersAi {
|
|||||||
|
|
||||||
// This will "rewind" clockwork cards when they fall to 50% power or below, consider improving
|
// This will "rewind" clockwork cards when they fall to 50% power or below, consider improving
|
||||||
if (curCtrs > Math.ceil(maxCtrs / 2.0)) {
|
if (curCtrs > Math.ceil(maxCtrs / 2.0)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
amount = Math.min(amount, maxCtrs - curCtrs);
|
amount = Math.min(amount, maxCtrs - curCtrs);
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,14 +386,14 @@ public class CountersPutAi extends CountersAi {
|
|||||||
.mapToInt(Card::getCMC)
|
.mapToInt(Card::getCMC)
|
||||||
.max().orElse(0);
|
.max().orElse(0);
|
||||||
if (amount > 0 && ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN)) {
|
if (amount > 0 && ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't use it if no counters to add
|
// don't use it if no counters to add
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Polukranos".equals(logic)) {
|
if ("Polukranos".equals(logic)) {
|
||||||
@@ -415,14 +420,20 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!canSurvive) {
|
if (!canSurvive) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("AtOppEOT".equals(logic)) {
|
||||||
|
if (ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn().equals(ai)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,19 +444,17 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (!ai.getGame().getStack().isEmpty() && !isSorcerySpeed(sa, ai)) {
|
if (!ai.getGame().getStack().isEmpty() && !isSorcerySpeed(sa, ai)) {
|
||||||
// only evaluates case where all tokens are placed on a single target
|
// only evaluates case where all tokens are placed on a single target
|
||||||
if (sa.getMinTargets() < 2) {
|
if (sa.getMinTargets() < 2) {
|
||||||
AiAbilityDecision decision = ComputerUtilCard.canPumpAgainstRemoval(ai, sa);
|
if (ComputerUtilCard.canPumpAgainstRemoval(ai, sa)) {
|
||||||
if (decision.willingToPlay()) {
|
|
||||||
Card c = sa.getTargetCard();
|
Card c = sa.getTargetCard();
|
||||||
if (sa.getTargets().size() > 1) {
|
if (sa.getTargets().size() > 1) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(c);
|
sa.getTargets().add(c);
|
||||||
}
|
}
|
||||||
sa.addDividedAllocation(c, amount);
|
sa.addDividedAllocation(c, amount);
|
||||||
return decision;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (!hasSacCost) {
|
if (!hasSacCost) { // for Sacrifice costs, evaluate further to see if it's worth using the ability before the card dies
|
||||||
// for Sacrifice costs, evaluate further to see if it's worth using the ability before the card dies
|
return false;
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,7 +498,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (list.size() < sa.getTargetRestrictions().getMinTargets(source, sa)) {
|
if (list.size() < sa.getTargetRestrictions().getMinTargets(source, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate +Loyalty planeswalker abilities even if they have no target (e.g. Vivien of the Arkbow),
|
// Activate +Loyalty planeswalker abilities even if they have no target (e.g. Vivien of the Arkbow),
|
||||||
@@ -498,9 +507,9 @@ public class CountersPutAi extends CountersAi {
|
|||||||
&& sa.isPwAbility()
|
&& sa.isPwAbility()
|
||||||
&& sa.getPayCosts().hasOnlySpecificCostType(CostPutCounter.class)
|
&& sa.getPayCosts().hasOnlySpecificCostType(CostPutCounter.class)
|
||||||
&& sa.isTargetNumberValid()
|
&& sa.isTargetNumberValid()
|
||||||
&& sa.getTargets().isEmpty()
|
&& sa.getTargets().size() == 0
|
||||||
&& ai.getGame().getPhaseHandler().is(PhaseType.MAIN2, ai)) {
|
&& ai.getGame().getPhaseHandler().is(PhaseType.MAIN2, ai)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceName.equals("Abzan Charm")) {
|
if (sourceName.equals("Abzan Charm")) {
|
||||||
@@ -522,11 +531,11 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (left == 0) {
|
if (left == 0) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// target loop
|
// target loop
|
||||||
@@ -534,7 +543,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
if (!sa.isTargetNumberValid() || sa.getTargets().isEmpty()) {
|
if (!sa.isTargetNumberValid() || sa.getTargets().isEmpty()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -566,9 +575,10 @@ public class CountersPutAi extends CountersAi {
|
|||||||
// check if other choice will already be played
|
// check if other choice will already be played
|
||||||
increasesCharmOutcome = !choices.get(0).getTargets().isEmpty();
|
increasesCharmOutcome = !choices.get(0).getTargets().isEmpty();
|
||||||
}
|
}
|
||||||
if (source != null && !source.isSpell() || increasesCharmOutcome // does not cost a card or can buff charm for no expense
|
if (!source.isSpell() || increasesCharmOutcome // does not cost a card or can buff charm for no expense
|
||||||
|| ph.getTurn() - source.getTurnInZone() >= source.getGame().getPlayers().size() * 2) {
|
|| ph.getTurn() - source.getTurnInZone() >= source.getGame().getPlayers().size() * 2) {
|
||||||
if (abCost == Cost.Zero || ph.is(PhaseType.END_OF_TURN) && ph.getPlayerTurn().isOpponentOf(ai)) {
|
if (abCost == null || abCost == Cost.Zero
|
||||||
|
|| (ph.is(PhaseType.END_OF_TURN) && ph.getPlayerTurn().isOpponentOf(ai))) {
|
||||||
// only use at opponent EOT unless it is free
|
// only use at opponent EOT unless it is free
|
||||||
choice = chooseBoonTarget(list, type);
|
choice = chooseBoonTarget(list, type);
|
||||||
}
|
}
|
||||||
@@ -582,7 +592,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (choice == null) { // can't find anything left
|
if (choice == null) { // can't find anything left
|
||||||
if (!sa.isTargetNumberValid() || sa.getTargets().isEmpty()) {
|
if (!sa.isTargetNumberValid() || sa.getTargets().isEmpty()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -598,14 +608,14 @@ public class CountersPutAi extends CountersAi {
|
|||||||
choice = null;
|
choice = null;
|
||||||
}
|
}
|
||||||
if (sa.getTargets().isEmpty()) {
|
if (sa.getTargets().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final List<Card> cards = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
final List<Card> cards = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
||||||
// Don't activate Curse abilities on my cards and non-curse abilities
|
// Don't activate Curse abilities on my cards and non-curse abilities
|
||||||
// on my opponents
|
// on my opponents
|
||||||
if (cards.isEmpty() || (cards.get(0).getController().isOpponentOf(ai) && !sa.isCurse())) {
|
if (cards.isEmpty() || (cards.get(0).getController().isOpponentOf(ai) && !sa.isCurse())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.MissingNeededCards);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int currCounters = cards.get(0).getCounters(CounterType.get(type));
|
final int currCounters = cards.get(0).getCounters(CounterType.get(type));
|
||||||
@@ -613,50 +623,51 @@ public class CountersPutAi extends CountersAi {
|
|||||||
// activating this ability.
|
// activating this ability.
|
||||||
|
|
||||||
if (!(type.equals("P1P1") || type.equals("M1M1") || type.equals("ICE")) && (MyRandom.getRandom().nextFloat() < (.1 * currCounters))) {
|
if (!(type.equals("P1P1") || type.equals("M1M1") || type.equals("ICE")) && (MyRandom.getRandom().nextFloat() < (.1 * currCounters))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
// Instant +1/+1
|
// Instant +1/+1
|
||||||
if (type.equals("P1P1") && !isSorcerySpeed(sa, ai)) {
|
if (type.equals("P1P1") && !isSorcerySpeed(sa, ai)) {
|
||||||
if (!hasSacCost && !(ph.getNextTurn() == ai && ph.is(PhaseType.END_OF_TURN) && abCost.isReusuableResource())) {
|
if (!hasSacCost && !(ph.getNextTurn() == ai && ph.is(PhaseType.END_OF_TURN) && abCost.isReusuableResource())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false; // only if next turn and cost is reusable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Useless since the card already has the keyword (or for another reason)
|
// Useless since the card already has the keyword (or for another reason)
|
||||||
if (ComputerUtil.isUselessCounter(CounterType.get(type), cards.get(0))) {
|
if (ComputerUtil.isUselessCounter(CounterType.get(type), cards.get(0))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean immediately = ComputerUtil.playImmediately(ai, sa);
|
boolean immediately = ComputerUtil.playImmediately(ai, sa);
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa, immediately)) {
|
if (abCost != null && !ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa, immediately)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (immediately) {
|
if (immediately) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!type.equals("P1P1") && !type.equals("M1M1") && !sa.hasParam("ActivationPhases")) {
|
if (!type.equals("P1P1") && !type.equals("M1M1") && !sa.hasParam("ActivationPhases")) {
|
||||||
// Don't use non P1P1/M1M1 counters before main 2 if possible
|
// Don't use non P1P1/M1M1 counters before main 2 if possible
|
||||||
if (ph.getPhase().isBefore(PhaseType.MAIN2) && !ComputerUtil.castSpellInMain1(ai, sa)) {
|
if (ph.getPhase().isBefore(PhaseType.MAIN2) && !ComputerUtil.castSpellInMain1(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForMain2);
|
return false;
|
||||||
}
|
}
|
||||||
if (ph.isPlayerTurn(ai) && !isSorcerySpeed(sa, ai)) {
|
if (ph.isPlayerTurn(ai) && !isSorcerySpeed(sa, ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ComputerUtil.waitForBlocking(sa)) {
|
if (ComputerUtil.waitForBlocking(sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(final SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(final SpellAbility sa, Player ai) {
|
||||||
|
boolean chance = true;
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
final String type = sa.getParam("CounterType");
|
final String type = sa.getParam("CounterType");
|
||||||
@@ -690,9 +701,9 @@ public class CountersPutAi extends CountersAi {
|
|||||||
while (sa.canAddMoreTarget()) {
|
while (sa.canAddMoreTarget()) {
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
if (!sa.isTargetNumberValid()
|
if (!sa.isTargetNumberValid()
|
||||||
|| sa.getTargets().isEmpty()) {
|
|| sa.getTargets().size() == 0) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -713,9 +724,9 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (choice == null) { // can't find anything left
|
if (choice == null) { // can't find anything left
|
||||||
if ((!sa.isTargetNumberValid()) || (sa.getTargets().isEmpty())) {
|
if ((!sa.isTargetNumberValid()) || (sa.getTargets().size() == 0)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -730,14 +741,15 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final SpellAbility root = sa.getRootAbility();
|
final SpellAbility root = sa.getRootAbility();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
// boolean chance = true;
|
||||||
boolean preferred = true;
|
boolean preferred = true;
|
||||||
CardCollection list;
|
CardCollection list;
|
||||||
final String amountStr = sa.getParamOrDefault("CounterNum", "1");
|
final String amountStr = sa.getParamOrDefault("CounterNum", "1");
|
||||||
@@ -758,14 +770,9 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("ChargeToBestCMC".equals(aiLogic)) {
|
if ("ChargeToBestCMC".equals(aiLogic)) {
|
||||||
AiAbilityDecision decision = doChargeToCMCLogic(ai, sa);
|
return doChargeToCMCLogic(ai, sa) || mandatory;
|
||||||
if (decision.willingToPlay()) {
|
} else if ("ChargeToBestOppControlledCMC".equals(aiLogic)) {
|
||||||
return decision;
|
return doChargeToOppCtrlCMCLogic(ai, sa) || mandatory;
|
||||||
} else if (mandatory) {
|
|
||||||
return new AiAbilityDecision(50, AiPlayDecision.MandatoryPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
@@ -794,7 +801,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
sa.getTargetRestrictions().getAllCandidates(sa, true, true), Player.class));
|
sa.getTargetRestrictions().getAllCandidates(sa, true, true), Player.class));
|
||||||
|
|
||||||
if (playerList.isEmpty()) {
|
if (playerList.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to choose player with less creatures
|
// try to choose player with less creatures
|
||||||
@@ -810,9 +817,8 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (type.equals("P1P1")) {
|
if (type.equals("P1P1")) {
|
||||||
nPump = amount;
|
nPump = amount;
|
||||||
}
|
}
|
||||||
AiAbilityDecision decision = FightAi.canFightAi(ai, sa, nPump, nPump);
|
if (FightAi.canFightAi(ai, sa, nPump, nPump)) {
|
||||||
if (decision.willingToPlay()) {
|
return true;
|
||||||
return decision;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -833,7 +839,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
// When things are mandatory, gotta handle a little differently
|
// When things are mandatory, gotta handle a little differently
|
||||||
if ((list.isEmpty() || !preferred) && sa.isTargetNumberValid()) {
|
if ((list.isEmpty() || !preferred) && sa.isTargetNumberValid()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.isEmpty() && preferred) {
|
if (list.isEmpty() && preferred) {
|
||||||
@@ -853,7 +859,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
// Not mandatory, or the the list was regenerated and is still empty,
|
// Not mandatory, or the the list was regenerated and is still empty,
|
||||||
// so return whether or not we found enough targets
|
// so return whether or not we found enough targets
|
||||||
return new AiAbilityDecision(sa.isTargetNumberValid() ? 100 : 0, sa.isTargetNumberValid() ? AiPlayDecision.WillPlay : AiPlayDecision.CantPlayAi);
|
return sa.isTargetNumberValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
@@ -906,7 +912,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1114,7 +1120,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
return Iterables.getFirst(options, null);
|
return Iterables.getFirst(options, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doMoveCounterLogic(final Player ai, SpellAbility sa, PhaseHandler ph) {
|
private boolean doMoveCounterLogic(final Player ai, SpellAbility sa, PhaseHandler ph) {
|
||||||
// Spikes (Tempest)
|
// Spikes (Tempest)
|
||||||
|
|
||||||
// Try not to do it unless at the end of opponent's turn or the creature is threatened
|
// Try not to do it unless at the end of opponent's turn or the creature is threatened
|
||||||
@@ -1127,7 +1133,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
|| (combat.isBlocking(source) && ComputerUtilCombat.blockerWouldBeDestroyed(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))) {
|
if (!(threatened || (ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == ai))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection targets = CardLists.getTargetableCards(ai.getCreaturesInPlay(), sa);
|
CardCollection targets = CardLists.getTargetableCards(ai.getCreaturesInPlay(), sa);
|
||||||
@@ -1145,45 +1151,45 @@ public class CountersPutAi extends CountersAi {
|
|||||||
|
|
||||||
if (bestTgt != null) {
|
if (bestTgt != null) {
|
||||||
sa.getTargets().add(bestTgt);
|
sa.getTargets().add(bestTgt);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doCombatAdaptLogic(Card source, int amount, Combat combat) {
|
private boolean doCombatAdaptLogic(Card source, int amount, Combat combat) {
|
||||||
if (combat.isAttacking(source)) {
|
if (combat.isAttacking(source)) {
|
||||||
if (!combat.isBlocked(source)) {
|
if (!combat.isBlocked(source)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (Card blockedBy : combat.getBlockers(source)) {
|
for (Card blockedBy : combat.getBlockers(source)) {
|
||||||
if (blockedBy.getNetToughness() > source.getNetPower()
|
if (blockedBy.getNetToughness() > source.getNetPower()
|
||||||
&& blockedBy.getNetToughness() <= source.getNetPower() + amount) {
|
&& blockedBy.getNetToughness() <= source.getNetPower() + amount) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int totBlkPower = Aggregates.sum(combat.getBlockers(source), Card::getNetPower);
|
int totBlkPower = Aggregates.sum(combat.getBlockers(source), Card::getNetPower);
|
||||||
if (source.getNetToughness() <= totBlkPower
|
if (source.getNetToughness() <= totBlkPower
|
||||||
&& source.getNetToughness() + amount > totBlkPower) {
|
&& source.getNetToughness() + amount > totBlkPower) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (combat.isBlocking(source)) {
|
} else if (combat.isBlocking(source)) {
|
||||||
for (Card blocked : combat.getAttackersBlockedBy(source)) {
|
for (Card blocked : combat.getAttackersBlockedBy(source)) {
|
||||||
if (blocked.getNetToughness() > source.getNetPower()
|
if (blocked.getNetToughness() > source.getNetPower()
|
||||||
&& blocked.getNetToughness() <= source.getNetPower() + amount) {
|
&& blocked.getNetToughness() <= source.getNetPower() + amount) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.ImpactCombat);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int totAtkPower = Aggregates.sum(combat.getAttackersBlockedBy(source), Card::getNetPower);
|
int totAtkPower = Aggregates.sum(combat.getAttackersBlockedBy(source), Card::getNetPower);
|
||||||
if (source.getNetToughness() <= totAtkPower
|
if (source.getNetToughness() <= totAtkPower
|
||||||
&& source.getNetToughness() + amount > totAtkPower) {
|
&& source.getNetToughness() + amount > totAtkPower) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1194,7 +1200,7 @@ public class CountersPutAi extends CountersAi {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doChargeToCMCLogic(Player ai, SpellAbility sa) {
|
private boolean doChargeToCMCLogic(Player ai, SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
CardCollectionView ownLib = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.CREATURES);
|
CardCollectionView ownLib = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.CREATURES);
|
||||||
int numCtrs = source.getCounters(CounterEnumType.CHARGE);
|
int numCtrs = source.getCounters(CounterEnumType.CHARGE);
|
||||||
@@ -1209,14 +1215,10 @@ public class CountersPutAi extends CountersAi {
|
|||||||
optimalCMC = cmc;
|
optimalCMC = cmc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numCtrs < optimalCMC) {
|
return numCtrs < optimalCMC;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doChargeToOppCtrlCMCLogic(Player ai, SpellAbility sa) {
|
private boolean doChargeToOppCtrlCMCLogic(Player ai, SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
CardCollectionView oppInPlay = CardLists.filter(ai.getOpponents().getCardsIn(ZoneType.Battlefield), CardPredicates.NONLAND_PERMANENTS);
|
CardCollectionView oppInPlay = CardLists.filter(ai.getOpponents().getCardsIn(ZoneType.Battlefield), CardPredicates.NONLAND_PERMANENTS);
|
||||||
int numCtrs = source.getCounters(CounterEnumType.CHARGE);
|
int numCtrs = source.getCounters(CounterEnumType.CHARGE);
|
||||||
@@ -1230,12 +1232,6 @@ public class CountersPutAi extends CountersAi {
|
|||||||
optimalCMC = cmc;
|
optimalCMC = cmc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numCtrs < optimalCMC) {
|
return numCtrs < optimalCMC;
|
||||||
// If the AI has less counters than the optimal CMC, it should play the ability.
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// If the AI has enough counters or more than the optimal CMC, it should not play the ability.
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCost;
|
import forge.ai.ComputerUtilCost;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
|
import forge.game.cost.Cost;
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -16,15 +15,17 @@ import forge.game.spellability.AbilitySub;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class CountersPutAllAi extends SpellAbilityAi {
|
public class CountersPutAllAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
// AI needs to be expanded, since this function can be pretty complex
|
// AI needs to be expanded, since this function can be pretty complex
|
||||||
// based on what the expected targets could be
|
// based on what the expected targets could be
|
||||||
|
final Cost abCost = sa.getPayCosts();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
List<Card> hList;
|
List<Card> hList;
|
||||||
List<Card> cList;
|
List<Card> cList;
|
||||||
@@ -43,9 +44,28 @@ public class CountersPutAllAi extends SpellAbilityAi {
|
|||||||
cList = CardLists.getValidCards(ai.getCardsIn(ZoneType.Battlefield), valid, source.getController(), source, sa);
|
cList = CardLists.getValidCards(ai.getCardsIn(ZoneType.Battlefield), valid, source.getController(), source, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (abCost != null) {
|
||||||
|
// AI currently disabled for these costs
|
||||||
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 8, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ComputerUtilCost.checkDiscardCost(ai, abCost, source, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (logic.equals("AtEOTOrBlock")) {
|
if (logic.equals("AtEOTOrBlock")) {
|
||||||
if (!ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN) && !ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
if (!ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN) && !ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
|
}
|
||||||
|
} else if (logic.equals("AtOppEOT")) {
|
||||||
|
if (!(ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN) && ai.getGame().getPhaseHandler().getNextTurn() == ai)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,23 +88,26 @@ public class CountersPutAllAi extends SpellAbilityAi {
|
|||||||
amount = AbilityUtils.calculateAmount(source, amountStr, sa);
|
amount = AbilityUtils.calculateAmount(source, amountStr, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent run-away activations - first time will always return true
|
||||||
|
boolean chance = MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
|
|
||||||
if (curse) {
|
if (curse) {
|
||||||
if (type.equals("M1M1")) {
|
if (type.equals("M1M1")) {
|
||||||
final List<Card> killable = CardLists.filter(hList, c -> c.getNetToughness() <= amount);
|
final List<Card> killable = CardLists.filter(hList, c -> c.getNetToughness() <= amount);
|
||||||
if (killable.size() <= 2) {
|
if (!(killable.size() > 2)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// make sure compy doesn't harm his stuff more than human's
|
// make sure compy doesn't harm his stuff more than human's
|
||||||
// stuff
|
// stuff
|
||||||
if (cList.size() > hList.size()) {
|
if (cList.size() > hList.size()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// human has more things that will benefit, don't play
|
// human has more things that will benefit, don't play
|
||||||
if (hList.size() >= cList.size()) {
|
if (hList.size() >= cList.size()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for cards that could profit from the ability
|
//Check for cards that could profit from the ability
|
||||||
@@ -102,21 +125,21 @@ public class CountersPutAllAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!combatants) {
|
if (!combatants) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playReusable(ai, sa)) {
|
if (playReusable(ai, sa)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.checkApiLogic(ai, sa);
|
return ((MyRandom.getRandom().nextFloat() < .6667) && chance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
return canPlay(ai, sa);
|
return canPlayAI(ai, sa);
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.ability.SpellAbilityAi#confirmAction(forge.game.player.Player, forge.card.spellability.SpellAbility, forge.game.player.PlayerActionConfirmMode, java.lang.String)
|
* @see forge.card.ability.SpellAbilityAi#confirmAction(forge.game.player.Player, forge.card.spellability.SpellAbility, forge.game.player.PlayerActionConfirmMode, java.lang.String)
|
||||||
@@ -127,7 +150,7 @@ public class CountersPutAllAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
List<Player> players = Lists.newArrayList();
|
List<Player> players = Lists.newArrayList();
|
||||||
if (!sa.isCurse()) {
|
if (!sa.isCurse()) {
|
||||||
@@ -145,23 +168,11 @@ public class CountersPutAllAi extends SpellAbilityAi {
|
|||||||
preferred = (sa.isCurse() && p.isOpponentOf(aiPlayer)) || (!sa.isCurse() && p == aiPlayer);
|
preferred = (sa.isCurse() && p.isOpponentOf(aiPlayer)) || (!sa.isCurse() && p == aiPlayer);
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(p);
|
sa.getTargets().add(p);
|
||||||
if (preferred) {
|
return preferred || mandatory;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mandatory) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(aiPlayer, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return canPlay(aiPlayer, sa);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtil;
|
||||||
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
@@ -50,13 +52,9 @@ public class CountersPutOrRemoveAi extends SpellAbilityAi {
|
|||||||
* forge.game.spellability.SpellAbility)
|
* forge.game.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
if (doTgt(ai, sa, false)) {
|
return doTgt(ai, sa, false);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return super.checkApiLogic(ai, sa);
|
return super.checkApiLogic(ai, sa);
|
||||||
}
|
}
|
||||||
@@ -182,27 +180,11 @@ public class CountersPutOrRemoveAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
if (doTgt(ai, sa, mandatory)) {
|
return doTgt(ai, sa, mandatory);
|
||||||
// if we can target, then we can play it
|
|
||||||
if (sa.isTargetNumberValid()) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// if we can't target, then we can't play it
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mandatory) {
|
|
||||||
// if mandatory, just play it
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
// if not mandatory, check if we can play it
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
return mandatory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtil;
|
import forge.ai.ComputerUtil;
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.ComputerUtilCost;
|
import forge.ai.ComputerUtilCost;
|
||||||
@@ -25,6 +23,14 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
public class CountersRemoveAi extends SpellAbilityAi {
|
public class CountersRemoveAi extends SpellAbilityAi {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean canPlayWithoutRestrict(final Player ai, final SpellAbility sa) {
|
||||||
|
if ("Always".equals(sa.getParam("AILogic"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.canPlayWithoutRestrict(ai, sa);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
@@ -42,6 +48,24 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
return super.checkPhaseRestrictions(ai, sa, ph);
|
return super.checkPhaseRestrictions(ai, sa, ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* forge.ai.SpellAbilityAi#checkPhaseRestrictions(forge.game.player.Player,
|
||||||
|
* forge.game.spellability.SpellAbility, forge.game.phase.PhaseHandler,
|
||||||
|
* java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph, String logic) {
|
||||||
|
if ("EndOfOpponentsTurn".equals(logic)) {
|
||||||
|
if (!ph.is(PhaseType.END_OF_TURN) || !ph.getNextTurn().equals(ai)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.checkPhaseRestrictions(ai, sa, ph, logic);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
@@ -49,7 +73,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
* forge.game.spellability.SpellAbility)
|
* forge.game.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
final String type = sa.getParam("CounterType");
|
final String type = sa.getParam("CounterType");
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
@@ -59,14 +83,14 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
if (!type.matches("Any") && !type.matches("All")) {
|
if (!type.matches("Any") && !type.matches("All")) {
|
||||||
final int currCounters = sa.getHostCard().getCounters(CounterType.getType(type));
|
final int currCounters = sa.getHostCard().getCounters(CounterType.getType(type));
|
||||||
if (currCounters < 1) {
|
if (currCounters < 1) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.checkApiLogic(ai, sa);
|
return super.checkApiLogic(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AiAbilityDecision doTgt(Player ai, SpellAbility sa, boolean mandatory) {
|
private boolean doTgt(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
|
|
||||||
@@ -79,7 +103,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
CardCollection list = CardLists.getTargetableCards(game.getCardsIn(tgt.getZone()), sa);
|
CardCollection list = CardLists.getTargetableCards(game.getCardsIn(tgt.getZone()), sa);
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter AI-specific targets if provided
|
// Filter AI-specific targets if provided
|
||||||
@@ -97,7 +121,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
CardPredicates.hasCounter(CounterEnumType.ICE, 3));
|
CardPredicates.hasCounter(CounterEnumType.ICE, 3));
|
||||||
if (!depthsList.isEmpty()) {
|
if (!depthsList.isEmpty()) {
|
||||||
sa.getTargets().add(depthsList.getFirst());
|
sa.getTargets().add(depthsList.getFirst());
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +134,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!planeswalkerList.isEmpty()) {
|
if (!planeswalkerList.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestPlaneswalkerAI(planeswalkerList));
|
sa.getTargets().add(ComputerUtilCard.getBestPlaneswalkerAI(planeswalkerList));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else if (type.matches("Any")) {
|
} else if (type.matches("Any")) {
|
||||||
// variable amount for Hex Parasite
|
// variable amount for Hex Parasite
|
||||||
@@ -120,7 +144,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
final int manaLeft = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
final int manaLeft = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
|
|
||||||
if (manaLeft == 0) {
|
if (manaLeft == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
amount = manaLeft;
|
amount = manaLeft;
|
||||||
xPay = true;
|
xPay = true;
|
||||||
@@ -142,7 +166,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
if (xPay) {
|
if (xPay) {
|
||||||
sa.setXManaCostPaid(ice);
|
sa.setXManaCostPaid(ice);
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,7 +185,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
if (xPay) {
|
if (xPay) {
|
||||||
sa.setXManaCostPaid(best.getCurrentLoyalty());
|
sa.setXManaCostPaid(best.getCurrentLoyalty());
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// some rules only for amount = 1
|
// some rules only for amount = 1
|
||||||
@@ -178,7 +202,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!aiM1M1List.isEmpty()) {
|
if (!aiM1M1List.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiM1M1List));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiM1M1List));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do as P1P1 part
|
// do as P1P1 part
|
||||||
@@ -187,7 +211,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!aiUndyingList.isEmpty()) {
|
if (!aiUndyingList.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiUndyingList));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiUndyingList));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO stun counters with canRemoveCounters check
|
// TODO stun counters with canRemoveCounters check
|
||||||
@@ -198,7 +222,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
CardPredicates.hasCounter(CounterEnumType.P1P1));
|
CardPredicates.hasCounter(CounterEnumType.P1P1));
|
||||||
if (!oppP1P1List.isEmpty()) {
|
if (!oppP1P1List.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(oppP1P1List));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(oppP1P1List));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback to remove any counter from opponent
|
// fallback to remove any counter from opponent
|
||||||
@@ -210,7 +234,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
for (final CounterType aType : best.getCounters().keySet()) {
|
for (final CounterType aType : best.getCounters().keySet()) {
|
||||||
if (!ComputerUtil.isNegativeCounter(aType, best)) {
|
if (!ComputerUtil.isNegativeCounter(aType, best)) {
|
||||||
sa.getTargets().add(best);
|
sa.getTargets().add(best);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,7 +255,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!aiList.isEmpty()) {
|
if (!aiList.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiList));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiList));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else if (type.equals("P1P1")) {
|
} else if (type.equals("P1P1")) {
|
||||||
// no special amount for that one yet
|
// no special amount for that one yet
|
||||||
@@ -249,7 +273,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
if (!aiList.isEmpty()) {
|
if (!aiList.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiList));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(aiList));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +287,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!oppList.isEmpty()) {
|
if (!oppList.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getWorstCreatureAI(oppList));
|
sa.getTargets().add(ComputerUtilCard.getWorstCreatureAI(oppList));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type.equals("TIME")) {
|
} else if (type.equals("TIME")) {
|
||||||
@@ -274,7 +298,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
final int manaLeft = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
final int manaLeft = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
|
|
||||||
if (manaLeft == 0) {
|
if (manaLeft == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
amount = manaLeft;
|
amount = manaLeft;
|
||||||
xPay = true;
|
xPay = true;
|
||||||
@@ -292,7 +316,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
if (xPay) {
|
if (xPay) {
|
||||||
sa.setXManaCostPaid(timeCount);
|
sa.setXManaCostPaid(timeCount);
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
@@ -301,7 +325,7 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
CardCollection adaptCreats = CardLists.filter(list, CardPredicates.hasKeyword(Keyword.ADAPT));
|
CardCollection adaptCreats = CardLists.filter(list, CardPredicates.hasKeyword(Keyword.ADAPT));
|
||||||
if (!adaptCreats.isEmpty()) {
|
if (!adaptCreats.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(adaptCreats));
|
sa.getTargets().add(ComputerUtilCard.getWorstAI(adaptCreats));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outlast nice target
|
// Outlast nice target
|
||||||
@@ -312,27 +336,26 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!betterTargets.isEmpty()) {
|
if (!betterTargets.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(betterTargets));
|
sa.getTargets().add(ComputerUtilCard.getWorstAI(betterTargets));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(outlastCreats));
|
sa.getTargets().add(ComputerUtilCard.getWorstAI(outlastCreats));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(list));
|
sa.getTargets().add(ComputerUtilCard.getWorstAI(list));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
return doTgt(aiPlayer, sa, mandatory);
|
return doTgt(aiPlayer, sa, mandatory);
|
||||||
}
|
}
|
||||||
return mandatory ? new AiAbilityDecision(100, AiPlayDecision.MandatoryPlay)
|
return mandatory;
|
||||||
: new AiAbilityDecision(0, AiPlayDecision.CantPlaySa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -346,7 +369,8 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
GameEntity target = (GameEntity) params.get("Target");
|
GameEntity target = (GameEntity) params.get("Target");
|
||||||
CounterType type = (CounterType) params.get("CounterType");
|
CounterType type = (CounterType) params.get("CounterType");
|
||||||
|
|
||||||
if (target instanceof Card targetCard) {
|
if (target instanceof Card) {
|
||||||
|
Card targetCard = (Card) target;
|
||||||
if (targetCard.getController().isOpponentOf(player)) {
|
if (targetCard.getController().isOpponentOf(player)) {
|
||||||
return !ComputerUtil.isNegativeCounter(type, targetCard) ? max : min;
|
return !ComputerUtil.isNegativeCounter(type, targetCard) ? max : min;
|
||||||
} else {
|
} else {
|
||||||
@@ -357,7 +381,8 @@ public class CountersRemoveAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
return ComputerUtil.isNegativeCounter(type, targetCard) ? max : min;
|
return ComputerUtil.isNegativeCounter(type, targetCard) ? max : min;
|
||||||
}
|
}
|
||||||
} else if (target instanceof Player targetPlayer) {
|
} else if (target instanceof Player) {
|
||||||
|
Player targetPlayer = (Player) target;
|
||||||
if (targetPlayer.isOpponentOf(player)) {
|
if (targetPlayer.isOpponentOf(player)) {
|
||||||
return !type.is(CounterEnumType.POISON) ? max : min;
|
return !type.is(CounterEnumType.POISON) ? max : min;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,24 +5,38 @@ import forge.game.ability.AbilityUtils;
|
|||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardCollection;
|
import forge.game.card.CardCollection;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
|
import forge.game.cost.Cost;
|
||||||
import forge.game.keyword.Keyword;
|
import forge.game.keyword.Keyword;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class DamageAllAi extends SpellAbilityAi {
|
public class DamageAllAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
// AI needs to be expanded, since this function can be pretty complex
|
// AI needs to be expanded, since this function can be pretty complex
|
||||||
// based on what the expected targets could be
|
// based on what the expected targets could be
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
|
// prevent run-away activations - first time will always return true
|
||||||
|
if (MyRandom.getRandom().nextFloat() > Math.pow(.9, sa.getActivationsThisTurn())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// abCost stuff that should probably be centralized...
|
||||||
|
final Cost abCost = sa.getPayCosts();
|
||||||
|
if (abCost != null) {
|
||||||
|
// AI currently disabled for some costs
|
||||||
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
// wait until stack is empty (prevents duplicate kills)
|
// wait until stack is empty (prevents duplicate kills)
|
||||||
if (!ai.getGame().getStack().isEmpty()) {
|
if (!ai.getGame().getStack().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.StackNotEmpty);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = -1;
|
int x = -1;
|
||||||
@@ -37,15 +51,11 @@ public class DamageAllAi extends SpellAbilityAi {
|
|||||||
if (x == -1) {
|
if (x == -1) {
|
||||||
if (determineOppToKill(ai, sa, source, dmg) != null) {
|
if (determineOppToKill(ai, sa, source, dmg) != null) {
|
||||||
// we already know we can kill a player, so go for it
|
// we already know we can kill a player, so go for it
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
// look for other value in this (damaging creatures or
|
// look for other value in this (damaging creatures or
|
||||||
// creatures + player, e.g. Pestilence, etc.)
|
// creatures + player, e.g. Pestilence, etc.)
|
||||||
if (evaluateDamageAll(ai, sa, source, dmg) > 0) {
|
return evaluateDamageAll(ai, sa, source, dmg) > 0;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int best = -1, best_x = -1;
|
int best = -1, best_x = -1;
|
||||||
Player bestOpp = determineOppToKill(ai, sa, source, x);
|
Player bestOpp = determineOppToKill(ai, sa, source, x);
|
||||||
@@ -71,9 +81,9 @@ public class DamageAllAi extends SpellAbilityAi {
|
|||||||
if (sa.getSVar(damage).equals("Count$xPaid")) {
|
if (sa.getSVar(damage).equals("Count$xPaid")) {
|
||||||
sa.setXManaCostPaid(best_x);
|
sa.setXManaCostPaid(best_x);
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +185,7 @@ public class DamageAllAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String validP = sa.getParamOrDefault("ValidPlayers", "");
|
final String validP = sa.getParamOrDefault("ValidPlayers", "");
|
||||||
|
|
||||||
@@ -201,21 +211,21 @@ public class DamageAllAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
// Don't get yourself killed
|
// Don't get yourself killed
|
||||||
if (validP.equals("Player") && (ai.getLife() <= ComputerUtilCombat.predictDamageTo(ai, dmg, source, false))) {
|
if (validP.equals("Player") && (ai.getLife() <= ComputerUtilCombat.predictDamageTo(ai, dmg, source, false))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we can kill human, do it
|
// if we can kill human, do it
|
||||||
if ((validP.equals("Player") || validP.equals("Opponent") || validP.contains("Targeted"))
|
if ((validP.equals("Player") || validP.equals("Opponent") || validP.contains("Targeted"))
|
||||||
&& (enemy.getLife() <= ComputerUtilCombat.predictDamageTo(enemy, dmg, source, false))) {
|
&& (enemy.getLife() <= ComputerUtilCombat.predictDamageTo(enemy, dmg, source, false))) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!computerList.isEmpty() && ComputerUtilCard.evaluateCreatureList(computerList) > ComputerUtilCard
|
if (!computerList.isEmpty() && ComputerUtilCard.evaluateCreatureList(computerList) > ComputerUtilCard
|
||||||
.evaluateCreatureList(humanList)) {
|
.evaluateCreatureList(humanList)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -248,7 +258,7 @@ public class DamageAllAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String validP = sa.getParamOrDefault("ValidPlayers", "");
|
final String validP = sa.getParamOrDefault("ValidPlayers", "");
|
||||||
|
|
||||||
@@ -277,24 +287,24 @@ public class DamageAllAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// If it's not mandatory check a few things
|
// If it's not mandatory check a few things
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
// Don't get yourself killed
|
// Don't get yourself killed
|
||||||
if (validP.equals("Player") && (ai.getLife() <= ComputerUtilCombat.predictDamageTo(ai, dmg, source, false))) {
|
if (validP.equals("Player") && (ai.getLife() <= ComputerUtilCombat.predictDamageTo(ai, dmg, source, false))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we can kill human, do it
|
// if we can kill human, do it
|
||||||
if ((validP.equals("Player") || validP.contains("Opponent") || validP.contains("Targeted"))
|
if ((validP.equals("Player") || validP.contains("Opponent") || validP.contains("Targeted"))
|
||||||
&& (enemy.getLife() <= ComputerUtilCombat.predictDamageTo(enemy, dmg, source, false))) {
|
&& (enemy.getLife() <= ComputerUtilCombat.predictDamageTo(enemy, dmg, source, false))) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!computerList.isEmpty() && ComputerUtilCard.evaluateCreatureList(computerList) + 50 >= ComputerUtilCard
|
if (!computerList.isEmpty() && ComputerUtilCard.evaluateCreatureList(computerList) + 50 >= ComputerUtilCard
|
||||||
.evaluateCreatureList(humanList)) {
|
.evaluateCreatureList(humanList)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DamageDealAi extends DamageAiBase {
|
public class DamageDealAi extends DamageAiBase {
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
final SpellAbility root = sa.getRootAbility();
|
final SpellAbility root = sa.getRootAbility();
|
||||||
final String damage = sa.getParam("NumDmg");
|
final String damage = sa.getParam("NumDmg");
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
@@ -65,19 +65,15 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
continue; // in case the calculation gets messed up somewhere
|
continue; // in case the calculation gets messed up somewhere
|
||||||
}
|
}
|
||||||
root.setSVar("EnergyToPay", "Number$" + dmg);
|
root.setSVar("EnergyToPay", "Number$" + dmg);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if (sa.getSVar(damage).equals("Count$xPaid")) {
|
if (sa.getSVar(damage).equals("Count$xPaid")) {
|
||||||
// Life Drain
|
// Life Drain
|
||||||
if ("XLifeDrain".equals(logic)) {
|
if ("XLifeDrain".equals(logic)) {
|
||||||
if (doXLifeDrainLogic(ai, sa)) {
|
return doXLifeDrainLogic(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set PayX here to maximum value.
|
// Set PayX here to maximum value.
|
||||||
@@ -87,15 +83,11 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
dmg--; // the card will be spent casting the spell, so actual damage is 1 less
|
dmg--; // the card will be spent casting the spell, so actual damage is 1 less
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (damageTargetAI(ai, sa, dmg, true)) {
|
return damageTargetAI(ai, sa, dmg, true);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Cost abCost = sa.getPayCosts();
|
final Cost abCost = sa.getPayCosts();
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
||||||
@@ -103,7 +95,7 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
final String damage = sa.getParam("NumDmg");
|
final String damage = sa.getParam("NumDmg");
|
||||||
int dmg = calculateDamageAmount(sa, source, damage);
|
int dmg = calculateDamageAmount(sa, source, damage);
|
||||||
|
|
||||||
if (damage.equals("X") || (dmg == 0 && source.getSVar("X").equals("Count$xPaid"))) {
|
if (damage.equals("X") || source.getSVar("X").equals("Count$xPaid")) {
|
||||||
if (sa.getSVar("X").equals("Count$xPaid") || sa.getSVar(damage).equals("Count$xPaid")) {
|
if (sa.getSVar("X").equals("Count$xPaid") || sa.getSVar(damage).equals("Count$xPaid")) {
|
||||||
dmg = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
dmg = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
|
|
||||||
@@ -116,7 +108,7 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
boolean inDanger = ComputerUtil.aiLifeInDanger(ai, false, 0);
|
boolean inDanger = ComputerUtil.aiLifeInDanger(ai, false, 0);
|
||||||
boolean isLethal = sa.usesTargeting() && sa.getTargetRestrictions().canTgtPlayer() && dmg >= ai.getWeakestOpponent().getLife() && !ai.getWeakestOpponent().cantLoseForZeroOrLessLife();
|
boolean isLethal = sa.usesTargeting() && sa.getTargetRestrictions().canTgtPlayer() && dmg >= ai.getWeakestOpponent().getLife() && !ai.getWeakestOpponent().cantLoseForZeroOrLessLife();
|
||||||
if (dmg < threshold && ai.getGame().getPhaseHandler().getTurn() / 2 < threshold && !inDanger && !isLethal) {
|
if (dmg < threshold && ai.getGame().getPhaseHandler().getTurn() / 2 < threshold && !inDanger && !isLethal) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,10 +134,10 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
if (shouldTgtP(ai, sa, maxDmg, false)) {
|
if (shouldTgtP(ai, sa, maxDmg, false)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(maxDamaged);
|
sa.getTargets().add(maxDamaged);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +154,7 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
if (ai.getGame().getPhaseHandler().isPlayerTurn(ai) && ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
if (ai.getGame().getPhaseHandler().isPlayerTurn(ai) && ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||||
for (Card potentialAtkr : ai.getCreaturesInPlay()) {
|
for (Card potentialAtkr : ai.getCreaturesInPlay()) {
|
||||||
if (ComputerUtilCard.doesCreatureAttackAI(ai, potentialAtkr)) {
|
if (ComputerUtilCard.doesCreatureAttackAI(ai, potentialAtkr)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,24 +175,16 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
* Mostly used to ping the player with remaining counters. The issue with
|
* Mostly used to ping the player with remaining counters. The issue with
|
||||||
* stacked effects might appear here.
|
* stacked effects might appear here.
|
||||||
*/
|
*/
|
||||||
if (damageTargetAI(ai, sa, n, true)) {
|
return damageTargetAI(ai, sa, n, true);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Only ping when stack is clear to avoid hassle of evaluating stacked effects
|
* Only ping when stack is clear to avoid hassle of evaluating stacked effects
|
||||||
* like protection/pumps or over-killing target.
|
* like protection/pumps or over-killing target.
|
||||||
*/
|
*/
|
||||||
if (ai.getGame().getStack().isEmpty() && damageTargetAI(ai, sa, n, false)) {
|
return ai.getGame().getStack().isEmpty() && damageTargetAI(ai, sa, n, false);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.StackNotEmpty);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if ("NinThePainArtist".equals(logic)) {
|
} else if ("NinThePainArtist".equals(logic)) {
|
||||||
// Make sure not to mana lock ourselves + make the opponent draw cards into an immediate discard
|
// Make sure not to mana lock ourselves + make the opponent draw cards into an immediate discard
|
||||||
@@ -209,15 +193,11 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
if (doTarget) {
|
if (doTarget) {
|
||||||
Card tgt = sa.getTargetCard();
|
Card tgt = sa.getTargetCard();
|
||||||
if (tgt != null) {
|
if (tgt != null) {
|
||||||
if (ai.getGame().getPhaseHandler().getPlayerTurn() == tgt.getController()) {
|
return ai.getGame().getPhaseHandler().getPlayerTurn() == tgt.getController();
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForEndOfTurn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForEndOfTurn);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceName.equals("Sorin, Grim Nemesis")) {
|
if (sourceName.equals("Sorin, Grim Nemesis")) {
|
||||||
@@ -229,35 +209,35 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
continue; // in case the calculation gets messed up somewhere
|
continue; // in case the calculation gets messed up somewhere
|
||||||
}
|
}
|
||||||
sa.setXManaCostPaid(dmg);
|
sa.setXManaCostPaid(dmg);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmg <= 0) {
|
if (dmg <= 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// temporarily disabled until better AI
|
// temporarily disabled until better AI
|
||||||
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa)) {
|
if (!ComputerUtilCost.checkSacrificeCost(ai, abCost, source, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkRemoveCounterCost(abCost, source, sa)) {
|
if (!ComputerUtilCost.checkRemoveCounterCost(abCost, source, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("DiscardLands".equals(sa.getParam("AILogic")) && !ComputerUtilCost.checkDiscardCost(ai, abCost, source, sa)) {
|
if ("DiscardLands".equals(sa.getParam("AILogic")) && !ComputerUtilCost.checkDiscardCost(ai, abCost, source, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to chain damage/debuff effects
|
// Try to chain damage/debuff effects
|
||||||
@@ -268,13 +248,13 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
int extraDmg = chainDmg.getValue();
|
int extraDmg = chainDmg.getValue();
|
||||||
boolean willTargetIfChained = damageTargetAI(ai, sa, dmg + extraDmg, false);
|
boolean willTargetIfChained = damageTargetAI(ai, sa, dmg + extraDmg, false);
|
||||||
if (!willTargetIfChained) {
|
if (!willTargetIfChained) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed); // won't play it even in chain
|
return false; // won't play it even in chain
|
||||||
} else if (willTargetIfChained && chainDmg.getKey().getApi() == ApiType.Pump && sa.getTargets().isTargetingAnyPlayer()) {
|
} 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
|
// 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
|
// so run an additional check to ensure that we want to cast the current spell separately
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (!damageTargetAI(ai, sa, dmg, false)) {
|
if (!damageTargetAI(ai, sa, dmg, false)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// we are about to decide to play this damage spell; if there's something chained to it, reserve mana for
|
// we are about to decide to play this damage spell; if there's something chained to it, reserve mana for
|
||||||
@@ -284,7 +264,7 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
}
|
}
|
||||||
} else if (!damageTargetAI(ai, sa, dmg, false)) {
|
} else if (!damageTargetAI(ai, sa, dmg, false)) {
|
||||||
// simple targeting when there is no spell chaining plan
|
// simple targeting when there is no spell chaining plan
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid")) ||
|
if ((damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid")) ||
|
||||||
@@ -308,12 +288,10 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
|
|
||||||
if ("DiscardCMCX".equals(sa.getParam("AILogic"))) {
|
if ("DiscardCMCX".equals(sa.getParam("AILogic"))) {
|
||||||
final int cmc = sa.getXManaCostPaid();
|
final int cmc = sa.getXManaCostPaid();
|
||||||
if (!ai.getZone(ZoneType.Hand).contains(CardPredicates.hasCMC(cmc))) {
|
return ai.getZone(ZoneType.Hand).contains(CardPredicates.hasCMC(cmc));
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -954,14 +932,14 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String damage = sa.getParam("NumDmg");
|
final String damage = sa.getParam("NumDmg");
|
||||||
int dmg = calculateDamageAmount(sa, source, damage);
|
int dmg = calculateDamageAmount(sa, source, damage);
|
||||||
|
|
||||||
// Remove all damage
|
// Remove all damage
|
||||||
if (sa.hasParam("Remove")) {
|
if (sa.hasParam("Remove")) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid")) {
|
if (damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid")) {
|
||||||
@@ -972,18 +950,10 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
// If it's not mandatory check a few things
|
// If it's not mandatory check a few things
|
||||||
if (mandatory) {
|
return mandatory || damageChooseNontargeted(ai, sa, dmg);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (damageChooseNontargeted(ai, sa, dmg)) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!damageChoosingTargets(ai, sa, sa.getTargetRestrictions(), dmg, mandatory, true) && !mandatory) {
|
if (!damageChoosingTargets(ai, sa, sa.getTargetRestrictions(), dmg, mandatory, true) && !mandatory) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid") && !sa.isDividedAsYouChoose()) {
|
if (damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid") && !sa.isDividedAsYouChoose()) {
|
||||||
@@ -1006,7 +976,7 @@ public class DamageDealAi extends DamageAiBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int calculateDamageAmount(SpellAbility sa, Card source, String damage) {
|
private static int calculateDamageAmount(SpellAbility sa, Card source, String damage) {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpecialCardAi;
|
import forge.ai.SpecialCardAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -16,7 +14,7 @@ public class DamageEachAi extends DamageAiBase {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final String logic = sa.getParam("AILogic");
|
final String logic = sa.getParam("AILogic");
|
||||||
|
|
||||||
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
@@ -24,41 +22,30 @@ public class DamageEachAi extends DamageAiBase {
|
|||||||
|
|
||||||
if (sa.usesTargeting() && weakestOpp != null) {
|
if (sa.usesTargeting() && weakestOpp != null) {
|
||||||
if ("MadSarkhanUltimate".equals(logic) && !SpecialCardAi.SarkhanTheMad.considerUltimate(ai, sa, weakestOpp)) {
|
if ("MadSarkhanUltimate".equals(logic) && !SpecialCardAi.SarkhanTheMad.considerUltimate(ai, sa, weakestOpp)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (weakestOpp.canLoseLife() && !weakestOpp.cantLoseForZeroOrLessLife()) {
|
sa.getTargets().add(weakestOpp);
|
||||||
sa.getTargets().add(weakestOpp);
|
return weakestOpp.canLoseLife() && !weakestOpp.cantLoseForZeroOrLessLife();
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String damage = sa.getParam("NumDmg");
|
final String damage = sa.getParam("NumDmg");
|
||||||
final int iDmg = AbilityUtils.calculateAmount(sa.getHostCard(), damage, sa);
|
final int iDmg = AbilityUtils.calculateAmount(sa.getHostCard(), damage, sa);
|
||||||
|
return shouldTgtP(ai, sa, iDmg, false);
|
||||||
if (shouldTgtP(ai, sa, iDmg, false)) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
// check AI life before playing this drawback?
|
// check AI life before playing this drawback?
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || canPlayAI(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return canPlay(ai, sa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtil;
|
||||||
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.ComputerUtilCombat;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.GameObject;
|
import forge.game.GameObject;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
|
import forge.game.cost.Cost;
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -20,12 +24,18 @@ import java.util.List;
|
|||||||
public class DamagePreventAi extends SpellAbilityAi {
|
public class DamagePreventAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Card hostCard = sa.getHostCard();
|
final Card hostCard = sa.getHostCard();
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
final Combat combat = game.getCombat();
|
final Combat combat = game.getCombat();
|
||||||
boolean chance = false;
|
boolean chance = false;
|
||||||
|
|
||||||
|
final Cost cost = sa.getPayCosts();
|
||||||
|
|
||||||
|
if (!willPayCosts(ai, sa, cost, hostCard)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
if (tgt == null) {
|
if (tgt == null) {
|
||||||
// As far as I can tell these Defined Cards will only have one of them
|
// As far as I can tell these Defined Cards will only have one of them
|
||||||
@@ -60,7 +70,7 @@ public class DamagePreventAi extends SpellAbilityAi {
|
|||||||
chance = flag;
|
chance = flag;
|
||||||
} else { // if nothing on the stack, and it's not declare
|
} else { // if nothing on the stack, and it's not declare
|
||||||
// blockers. no need to prevent
|
// blockers. no need to prevent
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // non-targeted
|
} // non-targeted
|
||||||
@@ -110,7 +120,7 @@ public class DamagePreventAi extends SpellAbilityAi {
|
|||||||
targetables = CardLists.getTargetableCards(targetables, sa);
|
targetables = CardLists.getTargetableCards(targetables, sa);
|
||||||
|
|
||||||
if (targetables.isEmpty()) {
|
if (targetables.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
final CardCollection combatants = CardLists.filter(targetables, CardPredicates.CREATURES);
|
final CardCollection combatants = CardLists.filter(targetables, CardPredicates.CREATURES);
|
||||||
ComputerUtilCard.sortByEvaluateCreature(combatants);
|
ComputerUtilCard.sortByEvaluateCreature(combatants);
|
||||||
@@ -127,15 +137,11 @@ public class DamagePreventAi extends SpellAbilityAi {
|
|||||||
sa.addDividedAllocation(sa.getTargets().get(0), AbilityUtils.calculateAmount(hostCard, sa.getParam("Amount"), sa));
|
sa.addDividedAllocation(sa.getTargets().get(0), AbilityUtils.calculateAmount(hostCard, sa.getParam("Amount"), sa));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chance) {
|
return chance;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
boolean chance = false;
|
boolean chance = false;
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
if (tgt == null) {
|
if (tgt == null) {
|
||||||
@@ -145,11 +151,7 @@ public class DamagePreventAi extends SpellAbilityAi {
|
|||||||
chance = preventDamageMandatoryTarget(ai, sa, mandatory);
|
chance = preventDamageMandatoryTarget(ai, sa, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chance) {
|
return chance;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.StopRunawayActivations);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
@@ -13,34 +11,24 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DayTimeAi extends SpellAbilityAi {
|
public class DayTimeAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
PhaseHandler ph = aiPlayer.getGame().getPhaseHandler();
|
PhaseHandler ph = aiPlayer.getGame().getPhaseHandler();
|
||||||
|
|
||||||
if ((sa.getHostCard().isCreature() && sa.getPayCosts().hasTapCost()) || sa.getPayCosts().hasManaCost()) {
|
if ((sa.getHostCard().isCreature() && sa.getPayCosts().hasTapCost()) || sa.getPayCosts().hasManaCost()) {
|
||||||
// If it involves a cost that may put us at a disadvantage, better activate before own turn if possible
|
// If it involves a cost that may put us at a disadvantage, better activate before own turn if possible
|
||||||
if (!isSorcerySpeed(sa, aiPlayer)) {
|
if (!isSorcerySpeed(sa, aiPlayer)) {
|
||||||
if (ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == aiPlayer) {
|
return ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == aiPlayer;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (ph.is(PhaseType.MAIN2, aiPlayer)) {
|
return ph.is(PhaseType.MAIN2, aiPlayer); // Give other things a chance to be cast (e.g. Celestus)
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true; // TODO: more logic if it's ever a bad idea to trigger this (when non-mandatory)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import forge.ai.*;
|
import forge.ai.AiAttackController;
|
||||||
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.ComputerUtilCost;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -23,27 +26,27 @@ import java.util.List;
|
|||||||
public class DebuffAi extends SpellAbilityAi {
|
public class DebuffAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(final Player ai, final SpellAbility sa) {
|
protected boolean canPlayAI(final Player ai, final SpellAbility sa) {
|
||||||
// if there is no target and host card isn't in play, don't activate
|
// if there is no target and host card isn't in play, don't activate
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
if (!sa.usesTargeting() && !source.isInPlay()) {
|
if (!sa.usesTargeting() && !source.isInPlay()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Cost cost = sa.getPayCosts();
|
final Cost cost = sa.getPayCosts();
|
||||||
|
|
||||||
// temporarily disabled until AI is improved
|
// temporarily disabled until AI is improved
|
||||||
if (!ComputerUtilCost.checkCreatureSacrificeCost(ai, cost, source, sa)) {
|
if (!ComputerUtilCost.checkCreatureSacrificeCost(ai, cost, source, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkLifeCost(ai, cost, source, 40, sa)) {
|
if (!ComputerUtilCost.checkLifeCost(ai, cost, source, 40, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkRemoveCounterCost(cost, source, sa)) {
|
if (!ComputerUtilCost.checkRemoveCounterCost(cost, source, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAfford);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PhaseHandler ph = game.getPhaseHandler();
|
final PhaseHandler ph = game.getPhaseHandler();
|
||||||
@@ -55,7 +58,7 @@ public class DebuffAi extends SpellAbilityAi {
|
|||||||
// Instant-speed pumps should not be cast outside of combat when the
|
// Instant-speed pumps should not be cast outside of combat when the
|
||||||
// stack is empty, unless there are specific activation phase requirements
|
// stack is empty, unless there are specific activation phase requirements
|
||||||
if (!isSorcerySpeed(sa, ai) && !sa.hasParam("ActivationPhases")) {
|
if (!isSorcerySpeed(sa, ai) && !sa.hasParam("ActivationPhases")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.AnotherTime);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +66,7 @@ public class DebuffAi extends SpellAbilityAi {
|
|||||||
List<Card> cards = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
List<Card> cards = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
||||||
|
|
||||||
final Combat combat = game.getCombat();
|
final Combat combat = game.getCombat();
|
||||||
if (cards.stream().anyMatch(c -> {
|
return cards.stream().anyMatch(c -> {
|
||||||
if (c.getController().equals(sa.getActivatingPlayer()) || combat == null)
|
if (c.getController().equals(sa.getActivatingPlayer()) || combat == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -72,34 +75,21 @@ public class DebuffAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
// don't add duplicate negative keywords
|
// don't add duplicate negative keywords
|
||||||
return sa.hasParam("Keywords") && c.hasAnyKeyword(Arrays.asList(sa.getParam("Keywords").split(" & ")));
|
return sa.hasParam("Keywords") && c.hasAnyKeyword(Arrays.asList(sa.getParam("Keywords").split(" & ")));
|
||||||
})) {
|
});
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (debuffTgtAI(ai, sa, sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : null, false)) {
|
return debuffTgtAI(ai, sa, sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : null, false);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
// TODO - copied from AF_Pump.pumpDrawbackAI() - what should be here?
|
// TODO - copied from AF_Pump.pumpDrawbackAI() - what should be here?
|
||||||
} else {
|
} else {
|
||||||
if (debuffTgtAI(ai, sa, sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : null, false)) {
|
return debuffTgtAI(ai, sa, sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : null, false);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
} // debuffDrawbackAI()
|
} // debuffDrawbackAI()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,24 +234,18 @@ public class DebuffAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final List<String> kws = sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : new ArrayList<>();
|
final List<String> kws = sa.hasParam("Keywords") ? Arrays.asList(sa.getParam("Keywords").split(" & ")) : new ArrayList<>();
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (debuffTgtAI(ai, sa, kws, mandatory)) {
|
return debuffTgtAI(ai, sa, kws, mandatory);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,56 +15,43 @@ import forge.game.zone.ZoneType;
|
|||||||
public class DelayedTriggerAi extends SpellAbilityAi {
|
public class DelayedTriggerAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
if ("Always".equals(sa.getParam("AILogic"))) {
|
if ("Always".equals(sa.getParam("AILogic"))) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
// TODO: improve ai
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
SpellAbility trigsa = sa.getAdditionalAbility("Execute");
|
SpellAbility trigsa = sa.getAdditionalAbility("Execute");
|
||||||
if (trigsa == null) {
|
if (trigsa == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
trigsa.setActivatingPlayer(ai);
|
trigsa.setActivatingPlayer(ai);
|
||||||
|
|
||||||
if (trigsa instanceof AbilitySub) {
|
if (trigsa instanceof AbilitySub) {
|
||||||
return SpellApiToAi.Converter.get(trigsa).chkDrawbackWithSubs(ai, (AbilitySub)trigsa);
|
return SpellApiToAi.Converter.get(trigsa).chkDrawbackWithSubs(ai, (AbilitySub)trigsa);
|
||||||
} else {
|
} else {
|
||||||
AiPlayDecision decision = ((PlayerControllerAi)ai.getController()).getAi().canPlaySa(trigsa);
|
return AiPlayDecision.WillPlay == ((PlayerControllerAi)ai.getController()).getAi().canPlaySa(trigsa);
|
||||||
if (decision == AiPlayDecision.WillPlay) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
SpellAbility trigsa = sa.getAdditionalAbility("Execute");
|
SpellAbility trigsa = sa.getAdditionalAbility("Execute");
|
||||||
if (trigsa == null) {
|
if (trigsa == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
|
||||||
trigsa.setActivatingPlayer(ai);
|
trigsa.setActivatingPlayer(ai);
|
||||||
|
|
||||||
if (!sa.hasParam("OptionalDecider")) {
|
if (!sa.hasParam("OptionalDecider")) {
|
||||||
if (aic.doTrigger(trigsa, true)) {
|
return aic.doTrigger(trigsa, true);
|
||||||
// If the trigger is mandatory, we can play it
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (aic.doTrigger(trigsa, !sa.getParam("OptionalDecider").equals("You"))) {
|
return aic.doTrigger(trigsa, !sa.getParam("OptionalDecider").equals("You"));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
// Card-specific logic
|
// Card-specific logic
|
||||||
String logic = sa.getParamOrDefault("AILogic", "");
|
String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
if (logic.equals("SpellCopy")) {
|
if (logic.equals("SpellCopy")) {
|
||||||
@@ -103,9 +90,9 @@ public class DelayedTriggerAi extends SpellAbilityAi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if (logic.equals("NarsetRebound")) {
|
} else if (logic.equals("NarsetRebound")) {
|
||||||
// should be done in Main2, but it might broke for other cards
|
// should be done in Main2, but it might broke for other cards
|
||||||
//if (phase.getPhase().isBefore(PhaseType.MAIN2)) {
|
//if (phase.getPhase().isBefore(PhaseType.MAIN2)) {
|
||||||
@@ -138,10 +125,10 @@ public class DelayedTriggerAi extends SpellAbilityAi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if (logic.equals("SaveCreature")) {
|
} else if (logic.equals("SaveCreature")) {
|
||||||
CardCollection ownCreatures = ai.getCreaturesInPlay();
|
CardCollection ownCreatures = ai.getCreaturesInPlay();
|
||||||
|
|
||||||
@@ -155,25 +142,19 @@ public class DelayedTriggerAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (!ownCreatures.isEmpty()) {
|
if (!ownCreatures.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestAI(ownCreatures));
|
sa.getTargets().add(ComputerUtilCard.getBestAI(ownCreatures));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic logic
|
// Generic logic
|
||||||
SpellAbility trigsa = sa.getAdditionalAbility("Execute");
|
SpellAbility trigsa = sa.getAdditionalAbility("Execute");
|
||||||
if (trigsa == null) {
|
if (trigsa == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
trigsa.setActivatingPlayer(ai);
|
trigsa.setActivatingPlayer(ai);
|
||||||
|
return AiPlayDecision.WillPlay == ((PlayerControllerAi)ai.getController()).getAi().canPlaySa(trigsa);
|
||||||
AiPlayDecision decision = ((PlayerControllerAi)ai.getController()).getAi().canPlaySa(trigsa);
|
|
||||||
if (decision == AiPlayDecision.WillPlay) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import forge.util.collect.FCollectionView;
|
|||||||
|
|
||||||
public class DestroyAi extends SpellAbilityAi {
|
public class DestroyAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
return checkApiLogic(ai, sa);
|
return checkApiLogic(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,27 +103,36 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final boolean noRegen = sa.hasParam("NoRegen");
|
final boolean noRegen = sa.hasParam("NoRegen");
|
||||||
final String logic = sa.getParam("AILogic");
|
final String logic = sa.getParam("AILogic");
|
||||||
|
|
||||||
CardCollection list;
|
CardCollection list;
|
||||||
|
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Targeting
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
|
// If there's X in payment costs and it's tied to targeting, make sure we set the XManaCostPaid first
|
||||||
|
// (e.g. Heliod's Intervention)
|
||||||
|
if ("X".equals(sa.getTargetRestrictions().getMinTargets()) && sa.getSVar("X").equals("Count$xPaid")) {
|
||||||
|
int xPay = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
|
sa.getRootAbility().setXManaCostPaid(xPay);
|
||||||
|
}
|
||||||
|
|
||||||
// Assume there where already enough targets chosen by AI Logic Above
|
// Assume there where already enough targets chosen by AI Logic Above
|
||||||
if (sa.hasParam("AILogic") && !sa.canAddMoreTarget() && sa.isTargetNumberValid()) {
|
if (sa.hasParam("AILogic") && !sa.canAddMoreTarget() && sa.isTargetNumberValid()) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset targets before AI Logic part
|
// reset targets before AI Logic part
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
int maxTargets;
|
int maxTargets;
|
||||||
|
|
||||||
// If there's X in payment costs and it's tied to targeting, make sure we set the XManaCostPaid first
|
if (sa.getRootAbility().costHasManaX()) {
|
||||||
// (e.g. Heliod's Intervention)
|
|
||||||
if (sa.getRootAbility().costHasManaX() ||
|
|
||||||
("X".equals(sa.getTargetRestrictions().getMinTargets()) && sa.getSVar("X").equals("Count$xPaid"))) {
|
|
||||||
// TODO: currently the AI will maximize mana spent on X, trying to maximize damage. This may need improvement.
|
// TODO: currently the AI will maximize mana spent on X, trying to maximize damage. This may need improvement.
|
||||||
maxTargets = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
maxTargets = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
// need to set XPaid to get the right number for
|
// need to set XPaid to get the right number for
|
||||||
@@ -136,22 +145,23 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
if (maxTargets == 0) {
|
if (maxTargets == 0) {
|
||||||
// can't afford X or otherwise target anything
|
// can't afford X or otherwise target anything
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantAffordX);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("TargetingPlayer")) {
|
if (sa.hasParam("TargetingPlayer")) {
|
||||||
Player targetingPlayer = AbilityUtils.getDefinedPlayers(source, sa.getParam("TargetingPlayer"), sa).get(0);
|
Player targetingPlayer = AbilityUtils.getDefinedPlayers(source, sa.getParam("TargetingPlayer"), sa).get(0);
|
||||||
sa.setTargetingPlayer(targetingPlayer);
|
sa.setTargetingPlayer(targetingPlayer);
|
||||||
if (targetingPlayer.getController().chooseTargetsFor(sa)) {
|
return targetingPlayer.getController().chooseTargetsFor(sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AI doesn't destroy own cards if it isn't defined in AI logic
|
// AI doesn't destroy own cards if it isn't defined in AI logic
|
||||||
list = CardLists.getTargetableCards(ai.getOpponents().getCardsIn(ZoneType.Battlefield), sa);
|
list = CardLists.getTargetableCards(ai.getOpponents().getCardsIn(ZoneType.Battlefield), sa);
|
||||||
|
if ("FatalPush".equals(logic)) {
|
||||||
|
final int cmcMax = ai.hasRevolt() ? 4 : 2;
|
||||||
|
list = CardLists.filter(list, CardPredicates.lessCMC(cmcMax));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter AI-specific targets if provided
|
||||||
list = ComputerUtil.filterAITgts(sa, ai, list, true);
|
list = ComputerUtil.filterAITgts(sa, ai, list, true);
|
||||||
|
|
||||||
list = CardLists.getNotKeyword(list, Keyword.INDESTRUCTIBLE);
|
list = CardLists.getNotKeyword(list, Keyword.INDESTRUCTIBLE);
|
||||||
@@ -196,7 +206,7 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
// Try to avoid targeting creatures that are dead on board
|
// Try to avoid targeting creatures that are dead on board
|
||||||
list = ComputerUtil.filterCreaturesThatWillDieThisTurn(ai, list, sa);
|
list = ComputerUtil.filterCreaturesThatWillDieThisTurn(ai, list, sa);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// target loop
|
// target loop
|
||||||
@@ -206,12 +216,10 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
CardCollection originalList = new CardCollection(list);
|
CardCollection originalList = new CardCollection(list);
|
||||||
boolean mustTargetFiltered = StaticAbilityMustTarget.filterMustTargetCards(ai, list, sa);
|
boolean mustTargetFiltered = StaticAbilityMustTarget.filterMustTargetCards(ai, list, sa);
|
||||||
|
|
||||||
list = CardLists.canSubsequentlyTarget(list, sa);
|
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
if (!sa.isMinTargetChosen() || sa.isZeroTargets()) {
|
if (!sa.isMinTargetChosen() || sa.isZeroTargets()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -225,7 +233,7 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
if ("OppDestroyYours".equals(logic)) {
|
if ("OppDestroyYours".equals(logic)) {
|
||||||
Card aiBest = ComputerUtilCard.getBestCreatureAI(ai.getCreaturesInPlay());
|
Card aiBest = ComputerUtilCard.getBestCreatureAI(ai.getCreaturesInPlay());
|
||||||
if (ComputerUtilCard.evaluateCreature(aiBest) > ComputerUtilCard.evaluateCreature(choice) - 40) {
|
if (ComputerUtilCard.evaluateCreature(aiBest) > ComputerUtilCard.evaluateCreature(choice) - 40) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (CardLists.getNotType(list, "Land").isEmpty()) {
|
} else if (CardLists.getNotType(list, "Land").isEmpty()) {
|
||||||
@@ -234,7 +242,7 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
if ("LandForLand".equals(logic) || "GhostQuarter".equals(logic)) {
|
if ("LandForLand".equals(logic) || "GhostQuarter".equals(logic)) {
|
||||||
// Strip Mine, Wasteland - cut short if the relevant logic fails
|
// Strip Mine, Wasteland - cut short if the relevant logic fails
|
||||||
if (!doLandForLandRemovalLogic(sa, ai, choice, logic)) {
|
if (!doLandForLandRemovalLogic(sa, ai, choice, logic)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -244,14 +252,14 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
//option to hold removal instead only applies for single targeted removal
|
//option to hold removal instead only applies for single targeted removal
|
||||||
if (!sa.isTrigger() && sa.getMaxTargets() == 1) {
|
if (!sa.isTrigger() && sa.getMaxTargets() == 1) {
|
||||||
if (choice == null || !ComputerUtilCard.useRemovalNow(sa, choice, 0, ZoneType.Graveyard)) {
|
if (choice == null || !ComputerUtilCard.useRemovalNow(sa, choice, 0, ZoneType.Graveyard)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choice == null) { // can't find anything left
|
if (choice == null) { // can't find anything left
|
||||||
if (!sa.isMinTargetChosen() || sa.isZeroTargets()) {
|
if (!sa.isMinTargetChosen() || sa.isZeroTargets()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO is this good enough? for up to amounts?
|
// TODO is this good enough? for up to amounts?
|
||||||
break;
|
break;
|
||||||
@@ -267,7 +275,6 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
choice = aura;
|
choice = aura;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO What about stolen permanents we're getting back at the end of the turn?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,9 +284,7 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list.remove(choice);
|
list.remove(choice);
|
||||||
if (sa.canTarget(choice)) {
|
sa.getTargets().add(choice);
|
||||||
sa.getTargets().add(choice);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (sa.hasParam("Defined")) {
|
} else if (sa.hasParam("Defined")) {
|
||||||
list = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
list = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
|
||||||
@@ -288,22 +293,22 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
|| !source.getGame().getPhaseHandler().isPlayerTurn(ai)
|
|| !source.getGame().getPhaseHandler().isPlayerTurn(ai)
|
||||||
|| ai.getLife() <= 5)) {
|
|| ai.getLife() <= 5)) {
|
||||||
// Basic ai logic for Lethal Vapors
|
// Basic ai logic for Lethal Vapors
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if ("Always".equals(logic)) {
|
} else if ("Always".equals(logic)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.isEmpty()
|
if (list.isEmpty()
|
||||||
|| !CardLists.filterControlledBy(list, ai).isEmpty()
|
|| !CardLists.filterControlledBy(list, ai).isEmpty()
|
||||||
|| CardLists.getNotKeyword(list, Keyword.INDESTRUCTIBLE).isEmpty()) {
|
|| CardLists.getNotKeyword(list, Keyword.INDESTRUCTIBLE).isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final boolean noRegen = sa.hasParam("NoRegen");
|
final boolean noRegen = sa.hasParam("NoRegen");
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
@@ -311,7 +316,7 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
CardCollection list = CardLists.getTargetableCards(ai.getGame().getCardsIn(ZoneType.Battlefield), sa);
|
CardCollection list = CardLists.getTargetableCards(ai.getGame().getCardsIn(ZoneType.Battlefield), sa);
|
||||||
|
|
||||||
if (list.isEmpty() || list.size() < sa.getMinTargets()) {
|
if (list.isEmpty() || list.size() < sa.getMinTargets()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to avoid targeting creatures that are dead on board
|
// Try to avoid targeting creatures that are dead on board
|
||||||
@@ -339,7 +344,7 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
list.removeAll(preferred);
|
list.removeAll(preferred);
|
||||||
|
|
||||||
if (preferred.isEmpty() && !mandatory) {
|
if (preferred.isEmpty() && !mandatory) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (sa.canAddMoreTarget()) {
|
while (sa.canAddMoreTarget()) {
|
||||||
@@ -347,19 +352,16 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
if (!sa.isMinTargetChosen()) {
|
if (!sa.isMinTargetChosen()) {
|
||||||
if (!mandatory) {
|
if (!mandatory) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Card c = ComputerUtilCard.getBestAI(preferred);
|
Card c = ComputerUtilCard.getBestAI(preferred);
|
||||||
|
sa.getTargets().add(c);
|
||||||
if (sa.canTarget(c)) {
|
|
||||||
sa.getTargets().add(c);
|
|
||||||
}
|
|
||||||
preferred.remove(c);
|
preferred.remove(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,25 +382,14 @@ public class DestroyAi extends SpellAbilityAi {
|
|||||||
} else {
|
} else {
|
||||||
c = ComputerUtilCard.getCheapestPermanentAI(list, sa, false);
|
c = ComputerUtilCard.getCheapestPermanentAI(list, sa, false);
|
||||||
}
|
}
|
||||||
if (sa.canTarget(c)) {
|
sa.getTargets().add(c);
|
||||||
sa.getTargets().add(c);
|
|
||||||
}
|
|
||||||
list.remove(c);
|
list.remove(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.isTargetNumberValid()) {
|
return sa.isTargetNumberValid();
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
sa.resetTargets();
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (mandatory) {
|
return mandatory;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,23 +23,38 @@ public class DestroyAllAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
* @see forge.card.abilityfactory.SpellAiLogic#doTriggerAINoCost(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility, boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return doMassRemovalLogic(ai, sa);
|
return doMassRemovalLogic(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
return doMassRemovalLogic(aiPlayer, sa);
|
return doMassRemovalLogic(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(final Player ai, SpellAbility sa) {
|
||||||
// AI needs to be expanded, since this function can be pretty complex
|
// AI needs to be expanded, since this function can be pretty complex
|
||||||
// based on what the expected targets could be
|
// based on what the expected targets could be
|
||||||
|
final Cost abCost = sa.getPayCosts();
|
||||||
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
|
if (abCost != null) {
|
||||||
|
// AI currently disabled for some costs
|
||||||
|
if (!ComputerUtilCost.checkLifeCost(ai, abCost, source, 4, sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent run-away activations - first time will always return true
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
if ("FellTheMighty".equals(aiLogic)) {
|
if ("FellTheMighty".equals(aiLogic)) {
|
||||||
@@ -49,7 +64,7 @@ public class DestroyAllAi extends SpellAbilityAi {
|
|||||||
return doMassRemovalLogic(ai, sa);
|
return doMassRemovalLogic(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AiAbilityDecision doMassRemovalLogic(Player ai, SpellAbility sa) {
|
public static boolean doMassRemovalLogic(Player ai, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String logic = sa.getParamOrDefault("AILogic", "");
|
final String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
@@ -57,7 +72,7 @@ public class DestroyAllAi extends SpellAbilityAi {
|
|||||||
final int CREATURE_EVAL_THRESHOLD = 200 / (!sa.usesTargeting() ? ai.getOpponents().size() : 1);
|
final int CREATURE_EVAL_THRESHOLD = 200 / (!sa.usesTargeting() ? ai.getOpponents().size() : 1);
|
||||||
|
|
||||||
if (logic.equals("Always")) {
|
if (logic.equals("Always")) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true; // e.g. Tetzimoc, Primal Death, where we want to cast the permanent even if the removal trigger does nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
String valid = sa.getParamOrDefault("ValidCards", "");
|
String valid = sa.getParamOrDefault("ValidCards", "");
|
||||||
@@ -77,7 +92,7 @@ public class DestroyAllAi extends SpellAbilityAi {
|
|||||||
opplist = CardLists.filter(opplist, predicate);
|
opplist = CardLists.filter(opplist, predicate);
|
||||||
ailist = CardLists.filter(ailist, predicate);
|
ailist = CardLists.filter(ailist, predicate);
|
||||||
if (opplist.isEmpty()) {
|
if (opplist.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
@@ -86,7 +101,7 @@ public class DestroyAllAi extends SpellAbilityAi {
|
|||||||
sa.getTargets().add(opponent);
|
sa.getTargets().add(opponent);
|
||||||
ailist.clear();
|
ailist.clear();
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,35 +110,30 @@ public class DestroyAllAi extends SpellAbilityAi {
|
|||||||
int numAiCanSave = Math.min(CardLists.count(ai.getCreaturesInPlay(), CardPredicates.isColor(MagicColor.WHITE).and(CardPredicates.UNTAPPED)) * 2, ailist.size());
|
int numAiCanSave = Math.min(CardLists.count(ai.getCreaturesInPlay(), CardPredicates.isColor(MagicColor.WHITE).and(CardPredicates.UNTAPPED)) * 2, ailist.size());
|
||||||
int numOppsCanSave = Math.min(CardLists.count(ai.getOpponents().getCreaturesInPlay(), CardPredicates.isColor(MagicColor.WHITE).and(CardPredicates.UNTAPPED)) * 2, opplist.size());
|
int numOppsCanSave = Math.min(CardLists.count(ai.getOpponents().getCreaturesInPlay(), CardPredicates.isColor(MagicColor.WHITE).and(CardPredicates.UNTAPPED)) * 2, opplist.size());
|
||||||
|
|
||||||
if (numOppsCanSave < opplist.size() && (ailist.size() - numAiCanSave < opplist.size() - numOppsCanSave)) {
|
return numOppsCanSave < opplist.size() && (ailist.size() - numAiCanSave < opplist.size() - numOppsCanSave);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else if (numAiCanSave < ailist.size() && (opplist.size() - numOppsCanSave < ailist.size() - numAiCanSave)) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If effect is destroying creatures and AI is about to lose, activate effect anyway no matter what!
|
// If effect is destroying creatures and AI is about to lose, activate effect anyway no matter what!
|
||||||
if ((!CardLists.getType(opplist, "Creature").isEmpty()) && (ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS))
|
if ((!CardLists.getType(opplist, "Creature").isEmpty()) && (ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS))
|
||||||
&& (ai.getGame().getCombat() != null && ComputerUtilCombat.lifeInSeriousDanger(ai, ai.getGame().getCombat()))) {
|
&& (ai.getGame().getCombat() != null && ComputerUtilCombat.lifeInSeriousDanger(ai, ai.getGame().getCombat()))) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If effect is destroying creatures and AI is about to get low on life, activate effect anyway if difference in lost permanents not very much
|
// If effect is destroying creatures and AI is about to get low on life, activate effect anyway if difference in lost permanents not very much
|
||||||
if ((!CardLists.getType(opplist, "Creature").isEmpty()) && (ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS))
|
if ((!CardLists.getType(opplist, "Creature").isEmpty()) && (ai.getGame().getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS))
|
||||||
&& (ai.getGame().getCombat() != null && ComputerUtilCombat.lifeInDanger(ai, ai.getGame().getCombat()))
|
&& (ai.getGame().getCombat() != null && ComputerUtilCombat.lifeInDanger(ai, ai.getGame().getCombat()))
|
||||||
&& ((ComputerUtilCard.evaluatePermanentList(ailist) - 6) >= ComputerUtilCard.evaluatePermanentList(opplist))) {
|
&& ((ComputerUtilCard.evaluatePermanentList(ailist) - 6) >= ComputerUtilCard.evaluatePermanentList(opplist))) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if only creatures are affected evaluate both lists and pass only if human creatures are more valuable
|
// if only creatures are affected evaluate both lists and pass only if human creatures are more valuable
|
||||||
if (CardLists.getNotType(opplist, "Creature").isEmpty() && CardLists.getNotType(ailist, "Creature").isEmpty()) {
|
if (CardLists.getNotType(opplist, "Creature").isEmpty() && CardLists.getNotType(ailist, "Creature").isEmpty()) {
|
||||||
if (ComputerUtilCard.evaluateCreatureList(ailist) + CREATURE_EVAL_THRESHOLD < ComputerUtilCard.evaluateCreatureList(opplist)) {
|
if (ComputerUtilCard.evaluateCreatureList(ailist) + CREATURE_EVAL_THRESHOLD < ComputerUtilCard.evaluateCreatureList(opplist)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)) {
|
if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForMain2);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// test whether the human can kill the ai next turn
|
// test whether the human can kill the ai next turn
|
||||||
@@ -136,42 +146,39 @@ public class DestroyAllAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!containsAttacker) {
|
if (!containsAttacker) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
AiBlockController block = new AiBlockController(ai, false);
|
AiBlockController block = new AiBlockController(ai, false);
|
||||||
block.assignBlockersForCombat(combat);
|
block.assignBlockersForCombat(combat);
|
||||||
|
|
||||||
if (ComputerUtilCombat.lifeInSeriousDanger(ai, combat)) {
|
if (ComputerUtilCombat.lifeInSeriousDanger(ai, combat)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} // only lands involved
|
} // only lands involved
|
||||||
else if (CardLists.getNotType(opplist, "Land").isEmpty() && CardLists.getNotType(ailist, "Land").isEmpty()) {
|
else if (CardLists.getNotType(opplist, "Land").isEmpty() && CardLists.getNotType(ailist, "Land").isEmpty()) {
|
||||||
if (ai.isCardInPlay("Crucible of Worlds") && !opponent.isCardInPlay("Crucible of Worlds")) {
|
if (ai.isCardInPlay("Crucible of Worlds") && !opponent.isCardInPlay("Crucible of Worlds")) {
|
||||||
// TODO Should care about any land recursion, not just Crucible of Worlds
|
return true;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// evaluate the situation with creatures on the battlefield separately, as that's where the AI typically makes mistakes
|
// evaluate the situation with creatures on the battlefield separately, as that's where the AI typically makes mistakes
|
||||||
CardCollection aiCreatures = ai.getCreaturesInPlay();
|
CardCollection aiCreatures = ai.getCreaturesInPlay();
|
||||||
CardCollection oppCreatures = opponent.getCreaturesInPlay();
|
CardCollection oppCreatures = opponent.getCreaturesInPlay();
|
||||||
if (!oppCreatures.isEmpty()) {
|
if (!oppCreatures.isEmpty()) {
|
||||||
if (ComputerUtilCard.evaluateCreatureList(aiCreatures) < ComputerUtilCard.evaluateCreatureList(oppCreatures) + CREATURE_EVAL_THRESHOLD) {
|
if (ComputerUtilCard.evaluateCreatureList(aiCreatures) < ComputerUtilCard.evaluateCreatureList(oppCreatures) + CREATURE_EVAL_THRESHOLD) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if the AI would lose more lands than the opponent would
|
// check if the AI would lose more lands than the opponent would
|
||||||
if (ComputerUtilCard.evaluatePermanentList(ailist) > ComputerUtilCard.evaluatePermanentList(opplist) + 1) {
|
if (ComputerUtilCard.evaluatePermanentList(ailist) > ComputerUtilCard.evaluatePermanentList(opplist) + 1) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} // otherwise evaluate both lists by CMC and pass only if human permanents are more valuable
|
} // otherwise evaluate both lists by CMC and pass only if human permanents are more valuable
|
||||||
else if ((ComputerUtilCard.evaluatePermanentList(ailist) + 3) >= ComputerUtilCard.evaluatePermanentList(opplist)) {
|
else if ((ComputerUtilCard.evaluatePermanentList(ailist) + 3) >= ComputerUtilCard.evaluatePermanentList(opplist)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,21 +20,26 @@ import forge.util.TextUtil;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class DigAi extends SpellAbilityAi {
|
public class DigAi extends SpellAbilityAi {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
Player opp = AiAttackController.choosePreferredDefenderPlayer(ai);
|
Player opp = AiAttackController.choosePreferredDefenderPlayer(ai);
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
Player libraryOwner = ai;
|
Player libraryOwner = ai;
|
||||||
|
|
||||||
|
if (!willPayCosts(ai, sa, sa.getPayCosts(), host)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (!sa.canTarget(opp)) {
|
if (!sa.canTarget(opp)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
libraryOwner = opp;
|
libraryOwner = opp;
|
||||||
@@ -42,21 +47,29 @@ public class DigAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// return false if nothing to dig into
|
// return false if nothing to dig into
|
||||||
if (libraryOwner.getCardsIn(ZoneType.Library).isEmpty()) {
|
if (libraryOwner.getCardsIn(ZoneType.Library).isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("Never".equals(sa.getParam("AILogic"))) {
|
||||||
|
return false;
|
||||||
|
} else if ("AtOppEOT".equals(sa.getParam("AILogic"))) {
|
||||||
|
if (!(game.getPhaseHandler().getNextTurn() == ai && game.getPhaseHandler().is(PhaseType.END_OF_TURN))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't deck yourself
|
// don't deck yourself
|
||||||
if (sa.hasParam("DestinationZone2") && !"Library".equals(sa.getParam("DestinationZone2"))) {
|
if (sa.hasParam("DestinationZone2") && !"Library".equals(sa.getParam("DestinationZone2"))) {
|
||||||
int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);
|
int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);
|
||||||
if (libraryOwner == ai && ai.getCardsIn(ZoneType.Library).size() <= numToDig + 2) {
|
if (libraryOwner == ai && ai.getCardsIn(ZoneType.Library).size() <= numToDig + 2) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use draw abilities before main 2 if possible
|
// Don't use draw abilities before main 2 if possible
|
||||||
if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")
|
if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")
|
||||||
&& !sa.hasParam("DestinationZone") && !ComputerUtil.castSpellInMain1(ai, sa)) {
|
&& !sa.hasParam("DestinationZone") && !ComputerUtil.castSpellInMain1(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String num = sa.getParam("DigNum");
|
final String num = sa.getParam("DigNum");
|
||||||
@@ -74,14 +87,14 @@ public class DigAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
int numCards = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger()) - manaToSave;
|
int numCards = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger()) - manaToSave;
|
||||||
if (numCards <= 0) {
|
if (numCards <= 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
root.setXManaCostPaid(numCards);
|
root.setXManaCostPaid(numCards);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playReusable(ai, sa)) {
|
if (playReusable(ai, sa)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!game.getPhaseHandler().getNextTurn().equals(ai)
|
if ((!game.getPhaseHandler().getNextTurn().equals(ai)
|
||||||
@@ -89,24 +102,24 @@ public class DigAi extends SpellAbilityAi {
|
|||||||
&& !sa.hasParam("PlayerTurn") && !isSorcerySpeed(sa, ai)
|
&& !sa.hasParam("PlayerTurn") && !isSorcerySpeed(sa, ai)
|
||||||
&& (ai.getCardsIn(ZoneType.Hand).size() > 1 || game.getPhaseHandler().getPhase().isBefore(PhaseType.DRAW))
|
&& (ai.getCardsIn(ZoneType.Hand).size() > 1 || game.getPhaseHandler().getPhase().isBefore(PhaseType.DRAW))
|
||||||
&& !ComputerUtil.activateForCost(sa, ai)) {
|
&& !ComputerUtil.activateForCost(sa, ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("MadSarkhanDigDmg".equals(sa.getParam("AILogic"))) {
|
if ("MadSarkhanDigDmg".equals(sa.getParam("AILogic"))) {
|
||||||
return SpecialCardAi.SarkhanTheMad.considerDig(ai, sa);
|
return SpecialCardAi.SarkhanTheMad.considerDig(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return !ComputerUtil.preventRunAwayActivations(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) {
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
// TODO: improve this check in ways that may be specific to a subability
|
// TODO: improve this check in ways that may be specific to a subability
|
||||||
return canPlay(aiPlayer, sa);
|
return canPlayAI(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final SpellAbility root = sa.getRootAbility();
|
final SpellAbility root = sa.getRootAbility();
|
||||||
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
Player opp = targetableOpps.min(PlayerPredicates.compareByLife());
|
Player opp = targetableOpps.min(PlayerPredicates.compareByLife());
|
||||||
@@ -124,16 +137,12 @@ public class DigAi extends SpellAbilityAi {
|
|||||||
int manaToSave = Integer.parseInt(TextUtil.split(sa.getParam("AILogic"), '.')[1]);
|
int manaToSave = Integer.parseInt(TextUtil.split(sa.getParam("AILogic"), '.')[1]);
|
||||||
int numCards = ComputerUtilCost.getMaxXValue(sa, ai, true) - manaToSave;
|
int numCards = ComputerUtilCost.getMaxXValue(sa, ai, true) - manaToSave;
|
||||||
if (numCards <= 0) {
|
if (numCards <= 0) {
|
||||||
if (mandatory) {
|
return mandatory;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
root.setXManaCostPaid(numCards);
|
root.setXManaCostPaid(numCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -194,12 +203,15 @@ public class DigAi extends SpellAbilityAi {
|
|||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
||||||
Card topc = player.getZone(ZoneType.Library).get(0);
|
Card topc = player.getZone(ZoneType.Library).get(0);
|
||||||
|
|
||||||
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Explorer's Scope")) {
|
// AI actions for individual cards (until this AI can be generalized)
|
||||||
// for Explorer's Scope, always put a land on the battlefield tapped
|
if (sa.getHostCard() != null) {
|
||||||
// (TODO: might not always be a good idea, e.g. when a land ETBing can have detrimental effects)
|
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Explorer's Scope")) {
|
||||||
return true;
|
// for Explorer's Scope, always put a land on the battlefield tapped
|
||||||
} else if ("AlwaysConfirm".equals(sa.getParam("AILogic"))) {
|
// (TODO: might not always be a good idea, e.g. when a land ETBing can have detrimental effects)
|
||||||
return true;
|
return true;
|
||||||
|
} else if ("AlwaysConfirm".equals(sa.getParam("AILogic"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// looks like perfect code for Delver of Secrets, but what about other cards?
|
// looks like perfect code for Delver of Secrets, but what about other cards?
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.AiAttackController;
|
||||||
|
import forge.ai.ComputerUtil;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -12,12 +14,13 @@ import forge.game.zone.ZoneType;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class DigMultipleAi extends SpellAbilityAi {
|
public class DigMultipleAi extends SpellAbilityAi {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
Player opp = AiAttackController.choosePreferredDefenderPlayer(ai);
|
Player opp = AiAttackController.choosePreferredDefenderPlayer(ai);
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
@@ -26,7 +29,7 @@ public class DigMultipleAi extends SpellAbilityAi {
|
|||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (!opp.canBeTargetedBy(sa)) {
|
if (!opp.canBeTargetedBy(sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
libraryOwner = opp;
|
libraryOwner = opp;
|
||||||
@@ -34,29 +37,33 @@ public class DigMultipleAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// return false if nothing to dig into
|
// return false if nothing to dig into
|
||||||
if (libraryOwner.getCardsIn(ZoneType.Library).isEmpty()) {
|
if (libraryOwner.getCardsIn(ZoneType.Library).isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Never".equals(sa.getParam("AILogic"))) {
|
if ("Never".equals(sa.getParam("AILogic"))) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
|
} else if ("AtOppEOT".equals(sa.getParam("AILogic"))) {
|
||||||
|
if (!(game.getPhaseHandler().getNextTurn() == ai && game.getPhaseHandler().is(PhaseType.END_OF_TURN))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't deck yourself
|
// don't deck yourself
|
||||||
if (sa.hasParam("DestinationZone2") && !"Library".equals(sa.getParam("DestinationZone2"))) {
|
if (sa.hasParam("DestinationZone2") && !"Library".equals(sa.getParam("DestinationZone2"))) {
|
||||||
int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);
|
int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);
|
||||||
if (libraryOwner == ai && ai.getCardsIn(ZoneType.Library).size() <= numToDig + 2) {
|
if (libraryOwner == ai && ai.getCardsIn(ZoneType.Library).size() <= numToDig + 2) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use draw abilities before main 2 if possible
|
// Don't use draw abilities before main 2 if possible
|
||||||
if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")
|
if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")
|
||||||
&& !sa.hasParam("DestinationZone") && !ComputerUtil.castSpellInMain1(ai, sa)) {
|
&& !sa.hasParam("DestinationZone") && !ComputerUtil.castSpellInMain1(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playReusable(ai, sa)) {
|
if (playReusable(ai, sa)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!game.getPhaseHandler().getNextTurn().equals(ai)
|
if ((!game.getPhaseHandler().getNextTurn().equals(ai)
|
||||||
@@ -64,14 +71,14 @@ public class DigMultipleAi extends SpellAbilityAi {
|
|||||||
&& !sa.hasParam("PlayerTurn") && !isSorcerySpeed(sa, ai)
|
&& !sa.hasParam("PlayerTurn") && !isSorcerySpeed(sa, ai)
|
||||||
&& (ai.getCardsIn(ZoneType.Hand).size() > 1 || game.getPhaseHandler().getPhase().isBefore(PhaseType.DRAW))
|
&& (ai.getCardsIn(ZoneType.Hand).size() > 1 || game.getPhaseHandler().getPhase().isBefore(PhaseType.DRAW))
|
||||||
&& !ComputerUtil.activateForCost(sa, ai)) {
|
&& !ComputerUtil.activateForCost(sa, ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return !ComputerUtil.preventRunAwayActivations(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Player opp = AiAttackController.choosePreferredDefenderPlayer(ai);
|
final Player opp = AiAttackController.choosePreferredDefenderPlayer(ai);
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
@@ -82,7 +89,7 @@ public class DigMultipleAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.AiAttackController;
|
||||||
|
import forge.ai.ComputerUtilCost;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
import forge.game.card.CardPredicates;
|
import forge.game.card.CardPredicates;
|
||||||
@@ -9,6 +11,7 @@ import forge.game.player.Player;
|
|||||||
import forge.game.player.PlayerActionConfirmMode;
|
import forge.game.player.PlayerActionConfirmMode;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -16,7 +19,7 @@ import java.util.Map;
|
|||||||
public class DigUntilAi extends SpellAbilityAi {
|
public class DigUntilAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
final String logic = sa.getParamOrDefault("AILogic", "");
|
final String logic = sa.getParamOrDefault("AILogic", "");
|
||||||
double chance = .4; // 40 percent chance with instant speed stuff
|
double chance = .4; // 40 percent chance with instant speed stuff
|
||||||
@@ -39,7 +42,7 @@ public class DigUntilAi extends SpellAbilityAi {
|
|||||||
// material in the library after using it several times.
|
// material in the library after using it several times.
|
||||||
// TODO: maybe this should happen for any DigUntil SA with RevealedDestination$ Graveyard?
|
// TODO: maybe this should happen for any DigUntil SA with RevealedDestination$ Graveyard?
|
||||||
if (ai.getCardsIn(ZoneType.Library).size() < 20) {
|
if (ai.getCardsIn(ZoneType.Library).size() < 20) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if ("Land.Basic".equals(sa.getParam("Valid"))
|
if ("Land.Basic".equals(sa.getParam("Valid"))
|
||||||
&& ai.getZone(ZoneType.Hand).contains(CardPredicates.LANDS_PRODUCING_MANA)) {
|
&& ai.getZone(ZoneType.Hand).contains(CardPredicates.LANDS_PRODUCING_MANA)) {
|
||||||
@@ -49,7 +52,7 @@ public class DigUntilAi extends SpellAbilityAi {
|
|||||||
// This is important for Replenish/Living Death type decks
|
// This is important for Replenish/Living Death type decks
|
||||||
if (!ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN)
|
if (!ai.getGame().getPhaseHandler().is(PhaseType.END_OF_TURN)
|
||||||
&& !ai.getGame().getPhaseHandler().isPlayerTurn(ai)) {
|
&& !ai.getGame().getPhaseHandler().isPlayerTurn(ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +60,7 @@ public class DigUntilAi extends SpellAbilityAi {
|
|||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (!sa.canTarget(opp)) {
|
if (!sa.canTarget(opp)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
libraryOwner = opp;
|
libraryOwner = opp;
|
||||||
@@ -65,7 +68,7 @@ public class DigUntilAi extends SpellAbilityAi {
|
|||||||
if (sa.hasParam("Valid")) {
|
if (sa.hasParam("Valid")) {
|
||||||
final String valid = sa.getParam("Valid");
|
final String valid = sa.getParam("Valid");
|
||||||
if (CardLists.getValidCards(ai.getCardsIn(ZoneType.Library), valid, source.getController(), source, sa).isEmpty()) {
|
if (CardLists.getValidCards(ai.getCardsIn(ZoneType.Library), valid, source.getController(), source, sa).isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +80,7 @@ public class DigUntilAi extends SpellAbilityAi {
|
|||||||
if (root.getXManaCostPaid() == null) {
|
if (root.getXManaCostPaid() == null) {
|
||||||
int numCards = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
int numCards = ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger());
|
||||||
if (numCards <= 0) {
|
if (numCards <= 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
root.setXManaCostPaid(numCards);
|
root.setXManaCostPaid(numCards);
|
||||||
}
|
}
|
||||||
@@ -85,14 +88,15 @@ public class DigUntilAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// return false if nothing to dig into
|
// return false if nothing to dig into
|
||||||
if (libraryOwner.getCardsIn(ZoneType.Library).isEmpty()) {
|
if (libraryOwner.getCardsIn(ZoneType.Library).isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
final boolean randomReturn = MyRandom.getRandom().nextFloat() <= Math.pow(chance, sa.getActivationsThisTurn() + 1);
|
||||||
|
return randomReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
if (sa.isCurse()) {
|
if (sa.isCurse()) {
|
||||||
@@ -112,7 +116,7 @@ public class DigUntilAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -26,29 +26,31 @@ import forge.util.collect.FCollectionView;
|
|||||||
public class DiscardAi extends SpellAbilityAi {
|
public class DiscardAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
||||||
|
final Cost abCost = sa.getPayCosts();
|
||||||
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
final String aiLogic = sa.getParamOrDefault("AILogic", "");
|
||||||
|
|
||||||
|
// temporarily disabled until better AI
|
||||||
|
if (!willPayCosts(ai, sa, abCost, source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ("Chandra, Flamecaller".equals(sourceName)) {
|
if ("Chandra, Flamecaller".equals(sourceName)) {
|
||||||
final int hand = ai.getCardsIn(ZoneType.Hand).size();
|
final int hand = ai.getCardsIn(ZoneType.Hand).size();
|
||||||
if (MyRandom.getRandom().nextFloat() < (1.0 / (1 + hand))) {
|
return MyRandom.getRandom().nextFloat() < (1.0 / (1 + hand));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aiLogic.equals("VolrathsShapeshifter")) {
|
if (aiLogic.equals("VolrathsShapeshifter")) {
|
||||||
return SpecialCardAi.VolrathsShapeshifter.consider(ai, sa);
|
return SpecialCardAi.VolrathsShapeshifter.consider(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean humanHasHand = !ai.getWeakestOpponent().getCardsIn(ZoneType.Hand).isEmpty();
|
final boolean humanHasHand = ai.getWeakestOpponent().getCardsIn(ZoneType.Hand).size() > 0;
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
if (!discardTargetAI(ai, sa)) {
|
if (!discardTargetAI(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: Add appropriate restrictions
|
// TODO: Add appropriate restrictions
|
||||||
@@ -62,7 +64,7 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
} else {
|
} else {
|
||||||
// defined to the human, so that's fine as long the human has cards
|
// defined to the human, so that's fine as long the human has cards
|
||||||
if (!humanHasHand) {
|
if (!humanHasHand) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -76,12 +78,12 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
final int cardsToDiscard = Math.min(ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger()), ai.getWeakestOpponent()
|
final int cardsToDiscard = Math.min(ComputerUtilCost.getMaxXValue(sa, ai, sa.isTrigger()), ai.getWeakestOpponent()
|
||||||
.getCardsIn(ZoneType.Hand).size());
|
.getCardsIn(ZoneType.Hand).size());
|
||||||
if (cardsToDiscard < 1) {
|
if (cardsToDiscard < 1) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
sa.setXManaCostPaid(cardsToDiscard);
|
sa.setXManaCostPaid(cardsToDiscard);
|
||||||
} else {
|
} else {
|
||||||
if (AbilityUtils.calculateAmount(source, sa.getParam("NumCards"), sa) < 1) {
|
if (AbilityUtils.calculateAmount(source, sa.getParam("NumCards"), sa) < 1) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +113,7 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numDiscard == 0) {
|
if (numDiscard == 0) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,25 +121,27 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
// Don't use discard abilities before main 2 if possible
|
// Don't use discard abilities before main 2 if possible
|
||||||
if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
|
if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
|
||||||
&& !sa.hasParam("ActivationPhases") && !aiLogic.startsWith("AnyPhase")) {
|
&& !sa.hasParam("ActivationPhases") && !aiLogic.startsWith("AnyPhase")) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aiLogic.equals("AnyPhaseIfFavored")) {
|
if (aiLogic.equals("AnyPhaseIfFavored")) {
|
||||||
if (ai.getGame().getCombat() != null) {
|
if (ai.getGame().getCombat() != null) {
|
||||||
if (ai.getCardsIn(ZoneType.Hand).size() < ai.getGame().getCombat().getDefenderPlayerByAttacker(source).getCardsIn(ZoneType.Hand).size()) {
|
if (ai.getCardsIn(ZoneType.Hand).size() < ai.getGame().getCombat().getDefenderPlayerByAttacker(source).getCardsIn(ZoneType.Hand).size()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't tap creatures that may be able to block
|
// Don't tap creatures that may be able to block
|
||||||
if (ComputerUtil.waitForBlocking(sa)) {
|
if (ComputerUtil.waitForBlocking(sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean randomReturn = MyRandom.getRandom().nextFloat() <= Math.pow(0.9, sa.getActivationsThisTurn());
|
||||||
|
|
||||||
// some other variables here, like handsize vs. maxHandSize
|
// some other variables here, like handsize vs. maxHandSize
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return randomReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean discardTargetAI(final Player ai, final SpellAbility sa) {
|
private boolean discardTargetAI(final Player ai, final SpellAbility sa) {
|
||||||
@@ -162,7 +166,7 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
|
||||||
Player opp = targetableOpps.min(PlayerPredicates.compareByLife());
|
Player opp = targetableOpps.min(PlayerPredicates.compareByLife());
|
||||||
@@ -172,7 +176,7 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
} else if (mandatory && sa.canTarget(ai)) {
|
} else if (mandatory && sa.canTarget(ai)) {
|
||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
} else {
|
} else {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -180,7 +184,7 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
if ("AtLeast2".equals(sa.getParam("AILogic"))) {
|
if ("AtLeast2".equals(sa.getParam("AILogic"))) {
|
||||||
final List<Player> players = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa);
|
final List<Player> players = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("Defined"), sa);
|
||||||
if (players.isEmpty() || players.get(0).getCardsIn(ZoneType.Hand).size() < 2) {
|
if (players.isEmpty() || players.get(0).getCardsIn(ZoneType.Hand).size() < 2) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,22 +196,18 @@ public class DiscardAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
// Drawback AI improvements
|
// Drawback AI improvements
|
||||||
// if parent draws cards, make sure cards in hand + cards drawn > 0
|
// if parent draws cards, make sure cards in hand + cards drawn > 0
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
if (discardTargetAI(ai, sa)) {
|
return discardTargetAI(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO: check for some extra things
|
// TODO: check for some extra things
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.AiPlayDecision;
|
||||||
|
import forge.ai.ComputerUtil;
|
||||||
|
import forge.ai.PlayerControllerAi;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -13,8 +16,12 @@ import java.util.Map;
|
|||||||
public class DiscoverAi extends SpellAbilityAi {
|
public class DiscoverAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false; // prevent infinite loop
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,12 +36,8 @@ public class DiscoverAi extends SpellAbilityAi {
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player ai, final SpellAbility sa, final boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory || checkApiLogic(ai, sa);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return checkApiLogic(ai, sa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DrainManaAi extends SpellAbilityAi {
|
public class DrainManaAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
||||||
// AI cannot use this properly until he can use SAs during Humans turn
|
// AI cannot use this properly until he can use SAs during Humans turn
|
||||||
|
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
final Player opp = ai.getWeakestOpponent();
|
final Player opp = ai.getWeakestOpponent();
|
||||||
|
boolean randomReturn = MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
// assume we are looking to tap human's stuff
|
// assume we are looking to tap human's stuff
|
||||||
@@ -25,58 +25,56 @@ public class DrainManaAi extends SpellAbilityAi {
|
|||||||
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
||||||
|
|
||||||
if (!defined.contains(opp)) {
|
if (!defined.contains(opp)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return randomReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Player opp = ai.getWeakestOpponent();
|
final Player opp = ai.getWeakestOpponent();
|
||||||
|
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
||||||
|
|
||||||
if (defined.contains(opp)) {
|
return defined.contains(opp);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
// AI cannot use this properly until he can use SAs during Humans turn
|
// AI cannot use this properly until he can use SAs during Humans turn
|
||||||
final Card source = sa.getHostCard();
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
|
boolean randomReturn = true;
|
||||||
|
|
||||||
if (!sa.usesTargeting()) {
|
if (!sa.usesTargeting()) {
|
||||||
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
final List<Player> defined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
|
||||||
|
|
||||||
if (defined.contains(ai)) {
|
if (defined.contains(ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(ai.getWeakestOpponent());
|
sa.getTargets().add(ai.getWeakestOpponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return randomReturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,41 +42,43 @@ public class DrawAi extends SpellAbilityAi {
|
|||||||
* @see forge.ai.SpellAbilityAi#checkApiLogic(forge.game.player.Player, forge.game.spellability.SpellAbility)
|
* @see forge.ai.SpellAbilityAi#checkApiLogic(forge.game.player.Player, forge.game.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
if (!targetAI(ai, sa, false)) {
|
if (!targetAI(ai, sa, false)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
final Player player = sa.getTargets().getFirstTargetedPlayer();
|
final Player player = sa.getTargets().getFirstTargetedPlayer();
|
||||||
if (player != null && player.isOpponentOf(ai)) {
|
if (player != null && player.isOpponentOf(ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent run-away activations - first time will always return true
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (ComputerUtil.playImmediately(ai, sa)) {
|
if (ComputerUtil.playImmediately(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't tap creatures that may be able to block
|
// Don't tap creatures that may be able to block
|
||||||
if (ComputerUtil.waitForBlocking(sa)) {
|
if (ComputerUtil.waitForBlocking(sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canLoot(ai, sa)) {
|
if (!canLoot(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ComputerUtilCost.isSacrificeSelfCost(sa.getPayCosts())) {
|
if (ComputerUtilCost.isSacrificeSelfCost(sa.getPayCosts())) {
|
||||||
// Canopy lands and other cards that sacrifice themselves to draw cards
|
// Canopy lands and other cards that sacrifice themselves to draw cards
|
||||||
if (ai.getCardsIn(ZoneType.Hand).isEmpty()
|
return ai.getCardsIn(ZoneType.Hand).isEmpty()
|
||||||
|| (sa.getHostCard().isLand() && ai.getLandsInPlay().size() >= 5)) {
|
|| (sa.getHostCard().isLand() && ai.getLandsInPlay().size() >= 5); // TODO: make this configurable in the AI profile
|
||||||
// TODO: make this configurable in the AI profile
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -159,6 +161,8 @@ public class DrawAi extends SpellAbilityAi {
|
|||||||
// LifeLessThan logic presupposes activation as soon as possible in an
|
// LifeLessThan logic presupposes activation as soon as possible in an
|
||||||
// attempt to save the AI from dying
|
// attempt to save the AI from dying
|
||||||
return true;
|
return true;
|
||||||
|
} else if (logic.equals("AtOppEOT")) {
|
||||||
|
return ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn().equals(ai);
|
||||||
} else if (logic.equals("RespondToOwnActivation")) {
|
} else if (logic.equals("RespondToOwnActivation")) {
|
||||||
return !ai.getGame().getStack().isEmpty() && ai.getGame().getStack().peekAbility().getHostCard().equals(sa.getHostCard());
|
return !ai.getGame().getStack().isEmpty() && ai.getGame().getStack().peekAbility().getHostCard().equals(sa.getHostCard());
|
||||||
} else if ((!ph.getNextTurn().equals(ai) || ph.getPhase().isBefore(PhaseType.END_OF_TURN))
|
} else if ((!ph.getNextTurn().equals(ai) || ph.getPhase().isBefore(PhaseType.END_OF_TURN))
|
||||||
@@ -171,12 +175,8 @@ public class DrawAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
if (targetAI(ai, sa, sa.isTrigger() && sa.getHostCard().isInPlay())) {
|
return targetAI(ai, sa, sa.isTrigger() && sa.getHostCard().isInPlay());
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -515,17 +515,12 @@ public class DrawAi extends SpellAbilityAi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((computerHandSize + numCards > computerMaxHandSize)) {
|
if ((computerHandSize + numCards > computerMaxHandSize)
|
||||||
|
&& game.getPhaseHandler().isPlayerTurn(ai)
|
||||||
|
&& !sa.isTrigger()
|
||||||
|
&& !assumeSafeX) {
|
||||||
// Don't draw too many cards and then risk discarding cards at EOT
|
// Don't draw too many cards and then risk discarding cards at EOT
|
||||||
if (game.getPhaseHandler().isPlayerTurn(ai)
|
if (!drawback) {
|
||||||
&& !sa.isTrigger()
|
|
||||||
&& !assumeSafeX
|
|
||||||
&& !drawback) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (computerHandSize > computerMaxHandSize) {
|
|
||||||
// Don't make my hand size get too big if already at max
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -534,16 +529,12 @@ public class DrawAi extends SpellAbilityAi {
|
|||||||
} // drawTargetAI()
|
} // drawTargetAI()
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
if (!mandatory && !willPayCosts(ai, sa, sa.getPayCosts(), sa.getHostCard())) {
|
if (!mandatory && !willPayCosts(ai, sa, sa.getPayCosts(), sa.getHostCard())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetAI(ai, sa, mandatory)) {
|
return targetAI(ai, sa, mandatory);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class EffectAi extends SpellAbilityAi {
|
public class EffectAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
|
protected boolean canPlayAI(final Player ai,final SpellAbility sa) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
boolean randomReturn = MyRandom.getRandom().nextFloat() <= .6667;
|
boolean randomReturn = MyRandom.getRandom().nextFloat() <= .6667;
|
||||||
String logic = "";
|
String logic = "";
|
||||||
@@ -45,7 +45,12 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
final PhaseHandler phase = game.getPhaseHandler();
|
final PhaseHandler phase = game.getPhaseHandler();
|
||||||
if (logic.equals("BeginningOfOppTurn")) {
|
if (logic.equals("BeginningOfOppTurn")) {
|
||||||
if (!phase.getPlayerTurn().isOpponentOf(ai) || phase.getPhase().isAfter(PhaseType.DRAW)) {
|
if (!phase.getPlayerTurn().isOpponentOf(ai) || phase.getPhase().isAfter(PhaseType.DRAW)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
|
}
|
||||||
|
randomReturn = true;
|
||||||
|
} else if (logic.equals("EndOfOppTurn")) {
|
||||||
|
if (!phase.getPlayerTurn().isOpponentOf(ai) || phase.getPhase().isBefore(PhaseType.END_OF_TURN)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
randomReturn = true;
|
randomReturn = true;
|
||||||
} else if (logic.equals("KeepOppCreatsLandsTapped")) {
|
} else if (logic.equals("KeepOppCreatsLandsTapped")) {
|
||||||
@@ -59,20 +64,20 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
worthHolding = true;
|
worthHolding = true;
|
||||||
}
|
}
|
||||||
if (!worthHolding) {
|
if (!worthHolding) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
randomReturn = true;
|
randomReturn = true;
|
||||||
}
|
}
|
||||||
} else if (logic.equals("RestrictBlocking")) {
|
} else if (logic.equals("RestrictBlocking")) {
|
||||||
if (!phase.isPlayerTurn(ai) || phase.getPhase().isBefore(PhaseType.COMBAT_BEGIN)
|
if (!phase.isPlayerTurn(ai) || phase.getPhase().isBefore(PhaseType.COMBAT_BEGIN)
|
||||||
|| phase.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
|| phase.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.getPayCosts().getTotalMana().countX() > 0 && sa.getHostCard().getSVar("X").equals("Count$xPaid")) {
|
if (sa.getPayCosts().getTotalMana().countX() > 0 && sa.getHostCard().getSVar("X").equals("Count$xPaid")) {
|
||||||
// Set PayX here to half the remaining mana to allow for Main 2 and other combat shenanigans.
|
// Set PayX here to half the remaining mana to allow for Main 2 and other combat shenanigans.
|
||||||
final int xPay = ComputerUtilMana.determineLeftoverMana(sa, ai, sa.isTrigger()) / 2;
|
final int xPay = ComputerUtilMana.determineLeftoverMana(sa, ai, sa.isTrigger()) / 2;
|
||||||
if (xPay == 0) { return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi); }
|
if (xPay == 0) { return false; }
|
||||||
sa.setXManaCostPaid(xPay);
|
sa.setXManaCostPaid(xPay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,27 +90,23 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
int potentialDmg = 0;
|
int potentialDmg = 0;
|
||||||
List<Card> currentAttackers = new ArrayList<>();
|
List<Card> currentAttackers = new ArrayList<>();
|
||||||
|
|
||||||
if (possibleBlockers.isEmpty()) { return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi); }
|
if (possibleBlockers.isEmpty()) { return false; }
|
||||||
|
|
||||||
for (final Card creat : possibleAttackers) {
|
for (final Card creat : possibleAttackers) {
|
||||||
if (CombatUtil.canAttack(creat, opp) && possibleBlockers.size() > 1) {
|
if (CombatUtil.canAttack(creat, opp) && possibleBlockers.size() > 1) {
|
||||||
potentialDmg += creat.getCurrentPower();
|
potentialDmg += creat.getCurrentPower();
|
||||||
if (potentialDmg >= oppLife) { return new AiAbilityDecision(100, AiPlayDecision.WillPlay); }
|
if (potentialDmg >= oppLife) { return true; }
|
||||||
}
|
}
|
||||||
if (combat != null && combat.isAttacking(creat)) {
|
if (combat != null && combat.isAttacking(creat)) {
|
||||||
currentAttackers.add(creat);
|
currentAttackers.add(creat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentAttackers.size() > possibleBlockers.size()) {
|
return currentAttackers.size() > possibleBlockers.size();
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
} else if (logic.equals("Fog")) {
|
} else if (logic.equals("Fog")) {
|
||||||
FogAi fogAi = new FogAi();
|
FogAi fogAi = new FogAi();
|
||||||
if (!fogAi.canPlay(ai, sa).willingToPlay()) {
|
if (!fogAi.canPlayAI(ai, sa)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
@@ -123,14 +124,14 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!canTgt) {
|
if (!canTgt) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<Card> list = game.getCombat().getAttackers();
|
List<Card> list = game.getCombat().getAttackers();
|
||||||
list = CardLists.getTargetableCards(list, sa);
|
list = CardLists.getTargetableCards(list, sa);
|
||||||
Card target = ComputerUtilCard.getBestCreatureAI(list);
|
Card target = ComputerUtilCard.getBestCreatureAI(list);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
sa.getTargets().add(target);
|
sa.getTargets().add(target);
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,7 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
randomReturn = true;
|
randomReturn = true;
|
||||||
} else if (logic.equals("ChainVeil")) {
|
} else if (logic.equals("ChainVeil")) {
|
||||||
if (!phase.isPlayerTurn(ai) || !phase.getPhase().equals(PhaseType.MAIN2) || ai.getPlaneswalkersInPlay().isEmpty()) {
|
if (!phase.isPlayerTurn(ai) || !phase.getPhase().equals(PhaseType.MAIN2) || ai.getPlaneswalkersInPlay().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
randomReturn = true;
|
randomReturn = true;
|
||||||
} else if (logic.equals("WillCastCreature") && ai.isAI()) {
|
} else if (logic.equals("WillCastCreature") && ai.isAI()) {
|
||||||
@@ -149,17 +150,17 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
randomReturn = true;
|
randomReturn = true;
|
||||||
} else if (logic.equals("Main1")) {
|
} else if (logic.equals("Main1")) {
|
||||||
if (phase.getPhase().isBefore(PhaseType.MAIN1)) {
|
if (phase.getPhase().isBefore(PhaseType.MAIN1)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
randomReturn = true;
|
randomReturn = true;
|
||||||
} else if (logic.equals("Main2")) {
|
} else if (logic.equals("Main2")) {
|
||||||
if (phase.getPhase().isBefore(PhaseType.MAIN2)) {
|
if (phase.getPhase().isBefore(PhaseType.MAIN2)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
randomReturn = true;
|
randomReturn = true;
|
||||||
} else if (logic.equals("Evasion")) {
|
} else if (logic.equals("Evasion")) {
|
||||||
if (!phase.isPlayerTurn(ai)) {
|
if (!phase.isPlayerTurn(ai)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean shouldPlay = false;
|
boolean shouldPlay = false;
|
||||||
@@ -184,10 +185,10 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shouldPlay ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return shouldPlay;
|
||||||
} else if (logic.equals("RedirectSpellDamageFromPlayer")) {
|
} else if (logic.equals("RedirectSpellDamageFromPlayer")) {
|
||||||
if (game.getStack().isEmpty()) {
|
if (game.getStack().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
boolean threatened = false;
|
boolean threatened = false;
|
||||||
for (final SpellAbilityStackInstance stackInst : game.getStack()) {
|
for (final SpellAbilityStackInstance stackInst : game.getStack()) {
|
||||||
@@ -203,7 +204,7 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
randomReturn = threatened;
|
randomReturn = threatened;
|
||||||
} else if (logic.equals("Prevent")) { // prevent burn spell from opponent
|
} else if (logic.equals("Prevent")) { // prevent burn spell from opponent
|
||||||
if (game.getStack().isEmpty()) {
|
if (game.getStack().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
final SpellAbility saTop = game.getStack().peekAbility();
|
final SpellAbility saTop = game.getStack().peekAbility();
|
||||||
final Card host = saTop.getHostCard();
|
final Card host = saTop.getHostCard();
|
||||||
@@ -214,10 +215,10 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
final ApiType type = saTop.getApi();
|
final ApiType type = saTop.getApi();
|
||||||
if (type == ApiType.DealDamage || type == ApiType.DamageAll) { // burn spell
|
if (type == ApiType.DealDamage || type == ApiType.DamageAll) { // burn spell
|
||||||
sa.getTargets().add(saTop);
|
sa.getTargets().add(saTop);
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (logic.equals("NoGain")) {
|
} else if (logic.equals("NoGain")) {
|
||||||
// basic logic to cancel GainLife on stack
|
// basic logic to cancel GainLife on stack
|
||||||
if (!game.getStack().isEmpty()) {
|
if (!game.getStack().isEmpty()) {
|
||||||
@@ -227,14 +228,14 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
while (topStack != null) {
|
while (topStack != null) {
|
||||||
if (topStack.getApi() == ApiType.GainLife) {
|
if (topStack.getApi() == ApiType.GainLife) {
|
||||||
if ("You".equals(topStack.getParam("Defined")) || topStack.isTargeting(activator) || (!topStack.usesTargeting() && !topStack.hasParam("Defined"))) {
|
if ("You".equals(topStack.getParam("Defined")) || topStack.isTargeting(activator) || (!topStack.usesTargeting() && !topStack.hasParam("Defined"))) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
} else if (topStack.getApi() == ApiType.DealDamage && topStack.getHostCard().hasKeyword(Keyword.LIFELINK)) {
|
} else if (topStack.getApi() == ApiType.DealDamage && topStack.getHostCard().hasKeyword(Keyword.LIFELINK)) {
|
||||||
Card host = topStack.getHostCard();
|
Card host = topStack.getHostCard();
|
||||||
for (GameEntity target : topStack.getTargets().getTargetEntities()) {
|
for (GameEntity target : topStack.getTargets().getTargetEntities()) {
|
||||||
if (ComputerUtilCombat.predictDamageTo(target,
|
if (ComputerUtilCombat.predictDamageTo(target,
|
||||||
AbilityUtils.calculateAmount(host, topStack.getParam("NumDmg"), topStack), host, false) > 0) {
|
AbilityUtils.calculateAmount(host, topStack.getParam("NumDmg"), topStack), host, false) > 0) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,11 +249,11 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
final Player attackingPlayer = combat.getAttackingPlayer();
|
final Player attackingPlayer = combat.getAttackingPlayer();
|
||||||
if (attackingPlayer.isOpponentOf(ai) && attackingPlayer.canGainLife()) {
|
if (attackingPlayer.isOpponentOf(ai) && attackingPlayer.canGainLife()) {
|
||||||
if (ComputerUtilCombat.checkAttackerLifelinkDamage(combat) > 0) {
|
if (ComputerUtilCombat.checkAttackerLifelinkDamage(combat) > 0) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (logic.equals("NonCastCreature")) {
|
} else if (logic.equals("NonCastCreature")) {
|
||||||
// TODO: add support for more cases with more convoluted API setups
|
// TODO: add support for more cases with more convoluted API setups
|
||||||
if (!game.getStack().isEmpty()) {
|
if (!game.getStack().isEmpty()) {
|
||||||
@@ -264,13 +265,13 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
boolean reanimator = "true".equalsIgnoreCase(topStack.getSVar("IsReanimatorCard"));
|
boolean reanimator = "true".equalsIgnoreCase(topStack.getSVar("IsReanimatorCard"));
|
||||||
if (changeZone && (toBattlefield || reanimator)) {
|
if (changeZone && (toBattlefield || reanimator)) {
|
||||||
if ("Creature".equals(topStack.getParam("ChangeType")) || topStack.getParamOrDefault("Defined", "").contains("Creature"))
|
if ("Creature".equals(topStack.getParam("ChangeType")) || topStack.getParamOrDefault("Defined", "").contains("Creature"))
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (logic.equals("Fight")) {
|
} else if (logic.equals("Fight")) {
|
||||||
return FightAi.canFightAi(ai, sa, 0,0);
|
return FightAi.canFightAi(ai, sa, 0, 0);
|
||||||
} else if (logic.equals("Pump")) {
|
} else if (logic.equals("Pump")) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
List<Card> options = CardUtil.getValidCardsToTarget(sa);
|
List<Card> options = CardUtil.getValidCardsToTarget(sa);
|
||||||
@@ -280,55 +281,55 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
if (!options.isEmpty() && phase.isPlayerTurn(ai) && phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
if (!options.isEmpty() && phase.isPlayerTurn(ai) && phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(options));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(options));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (logic.equals("Burn")) {
|
} else if (logic.equals("Burn")) {
|
||||||
|
// for DamageDeal sub-abilities (eg. Wild Slash, Skullcrack)
|
||||||
SpellAbility burn = sa.getSubAbility();
|
SpellAbility burn = sa.getSubAbility();
|
||||||
return SpellApiToAi.Converter.get(burn).canPlayWithSubs(ai, burn).willingToPlay() ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return SpellApiToAi.Converter.get(burn).canPlayAIWithSubs(ai, burn);
|
||||||
} else if (logic.equals("YawgmothsWill")) {
|
} else if (logic.equals("YawgmothsWill")) {
|
||||||
return SpecialCardAi.YawgmothsWill.consider(ai, sa) ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return SpecialCardAi.YawgmothsWill.consider(ai, sa);
|
||||||
} else if (logic.startsWith("NeedCreatures")) {
|
} else if (logic.startsWith("NeedCreatures")) {
|
||||||
// TODO convert to AiCheckSVar
|
|
||||||
if (ai.getCreaturesInPlay().isEmpty()) {
|
if (ai.getCreaturesInPlay().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
if (logic.contains(":")) {
|
if (logic.contains(":")) {
|
||||||
String[] k = logic.split(":");
|
String[] k = logic.split(":");
|
||||||
int i = Integer.parseInt(k[1]);
|
int i = Integer.parseInt(k[1]);
|
||||||
return ai.getCreaturesInPlay().size() >= i ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return ai.getCreaturesInPlay().size() >= i;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if (logic.equals("ReplaySpell")) {
|
} else if (logic.equals("ReplaySpell")) {
|
||||||
CardCollection list = CardLists.getValidCards(game.getCardsIn(ZoneType.Graveyard), sa.getTargetRestrictions().getValidTgts(), ai, sa.getHostCard(), sa);
|
CardCollection list = CardLists.getValidCards(game.getCardsIn(ZoneType.Graveyard), sa.getTargetRestrictions().getValidTgts(), ai, sa.getHostCard(), sa);
|
||||||
if (!ComputerUtil.targetPlayableSpellCard(ai, list, sa, false, false)) {
|
if (!ComputerUtil.targetPlayableSpellCard(ai, list, sa, false, false)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
} else if (logic.equals("PeaceTalks")) {
|
} else if (logic.equals("PeaceTalks")) {
|
||||||
Player nextPlayer = game.getNextPlayerAfter(ai);
|
Player nextPlayer = game.getNextPlayerAfter(ai);
|
||||||
|
|
||||||
// If opponent doesn't have creatures, preventing attacks don't mean as much
|
// If opponent doesn't have creatures, preventing attacks don't mean as much
|
||||||
if (nextPlayer.getCreaturesInPlay().isEmpty()) {
|
if (nextPlayer.getCreaturesInPlay().isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only cast Peace Talks after you attack just in case you have creatures
|
// Only cast Peace Talks after you attack just in case you have creatures
|
||||||
if (!phase.is(PhaseType.MAIN2)) {
|
if (!phase.is(PhaseType.MAIN2)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a pseudo combat and see if my life is in danger
|
// Create a pseudo combat and see if my life is in danger
|
||||||
return randomReturn ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return randomReturn;
|
||||||
} else if (logic.equals("Bribe")) {
|
} else if (logic.equals("Bribe")) {
|
||||||
Card host = sa.getHostCard();
|
Card host = sa.getHostCard();
|
||||||
Combat combat = game.getCombat();
|
Combat combat = game.getCombat();
|
||||||
if (combat != null && combat.isAttacking(host, ai) && !combat.isBlocked(host)
|
if (combat != null && combat.isAttacking(host, ai) && !combat.isBlocked(host)
|
||||||
&& phase.is(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
&& phase.is(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
||||||
&& !host.getAbilityActivatedThisTurn().getActivators(sa).contains(ai)) {
|
&& !AiCardMemory.isRememberedCard(ai, host, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN)) {
|
||||||
// ideally needs once per combat or something
|
AiCardMemory.rememberCard(ai, host, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN); // ideally needs once per combat or something
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
} else if (logic.equals("CantRegenerate")) {
|
} else if (logic.equals("CantRegenerate")) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
CardCollection list = CardLists.getTargetableCards(ai.getOpponents().getCardsIn(ZoneType.Battlefield), sa);
|
CardCollection list = CardLists.getTargetableCards(ai.getOpponents().getCardsIn(ZoneType.Battlefield), sa);
|
||||||
@@ -349,19 +350,19 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
// TODO check Stack for Effects that would destroy the selected card?
|
// TODO check Stack for Effects that would destroy the selected card?
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestAI(list));
|
sa.getTargets().add(ComputerUtilCard.getBestAI(list));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if (sa.getParent() != null) {
|
} else if (sa.getParent() != null) {
|
||||||
// sub ability should be okay
|
// sub ability should be okay
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
} else if ("Self".equals(sa.getParam("RememberObjects"))) {
|
} else if ("Self".equals(sa.getParam("RememberObjects"))) {
|
||||||
// the ones affecting itself are Nimbus cards, were opponent can activate this effect
|
// the ones affecting itself are Nimbus cards, were opponent can activate this effect
|
||||||
Card host = sa.getHostCard();
|
Card host = sa.getHostCard();
|
||||||
if (!host.canBeDestroyed()) {
|
if (!host.canBeDestroyed()) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<AbilityKey, Object> runParams = AbilityKey.mapFromAffected(sa.getHostCard());
|
Map<AbilityKey, Object> runParams = AbilityKey.mapFromAffected(sa.getHostCard());
|
||||||
@@ -369,18 +370,18 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
List<ReplacementEffect> repDestroyList = game.getReplacementHandler().getReplacementList(ReplacementType.Destroy, runParams, ReplacementLayer.Other);
|
List<ReplacementEffect> repDestroyList = game.getReplacementHandler().getReplacementList(ReplacementType.Destroy, runParams, ReplacementLayer.Other);
|
||||||
// no Destroy Replacement, or one non-Regeneration one like Totem-Armor
|
// no Destroy Replacement, or one non-Regeneration one like Totem-Armor
|
||||||
if (repDestroyList.isEmpty() || repDestroyList.stream().anyMatch(CardTraitPredicates.hasParam("Regeneration").negate())) {
|
if (repDestroyList.isEmpty() || repDestroyList.stream().anyMatch(CardTraitPredicates.hasParam("Regeneration").negate())) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cantRegenerateCheckCombat(host) || cantRegenerateCheckStack(host)) {
|
if (cantRegenerateCheckCombat(host) || cantRegenerateCheckStack(host)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { //no AILogic
|
} else { //no AILogic
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("False".equals(sa.getParam("Stackable"))) {
|
if ("False".equals(sa.getParam("Stackable"))) {
|
||||||
@@ -389,7 +390,7 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
name = sa.getHostCard().getName() + "'s Effect";
|
name = sa.getHostCard().getName() + "'s Effect";
|
||||||
}
|
}
|
||||||
if (sa.getActivatingPlayer().isCardInCommand(name)) {
|
if (sa.getActivatingPlayer().isCardInCommand(name)) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,20 +406,20 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return canTgt ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return canTgt;
|
||||||
} else {
|
} else {
|
||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return randomReturn ? new AiAbilityDecision(100, AiPlayDecision.WillPlay) : new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return randomReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
protected boolean doTriggerAINoCost(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
|
||||||
if (sa.hasParam("AILogic")) {
|
if (sa.hasParam("AILogic")) {
|
||||||
if (canPlay(aiPlayer, sa).willingToPlay()) {
|
if (canPlayAI(aiPlayer, sa)) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true; // if false, fall through further to do the mandatory stuff
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,7 +431,7 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
if (!oppPerms.isEmpty()) {
|
if (!oppPerms.isEmpty()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestAI(oppPerms));
|
sa.getTargets().add(ComputerUtilCard.getBestAI(oppPerms));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
@@ -440,14 +441,14 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
if (!aiPerms.isEmpty()) {
|
if (!aiPerms.isEmpty()) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(ComputerUtilCard.getWorstAI(aiPerms));
|
sa.getTargets().add(ComputerUtilCard.getWorstAI(aiPerms));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.doTriggerNoCost(aiPlayer, sa, mandatory);
|
return super.doTriggerAINoCost(aiPlayer, sa, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean cantRegenerateCheckCombat(Card host) {
|
protected boolean cantRegenerateCheckCombat(Card host) {
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import forge.ai.*;
|
import forge.ai.ComputerUtilCard;
|
||||||
|
import forge.ai.ComputerUtilCombat;
|
||||||
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
import forge.game.combat.CombatUtil;
|
import forge.game.combat.CombatUtil;
|
||||||
@@ -43,17 +45,19 @@ public final class EncodeAi extends SpellAbilityAi {
|
|||||||
* </p>
|
* </p>
|
||||||
* @param sa
|
* @param sa
|
||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.game.ability.AbilityFactory} object.
|
||||||
*
|
*
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
@@ -14,22 +12,18 @@ import forge.game.spellability.SpellAbility;
|
|||||||
public class EndTurnAi extends SpellAbilityAi {
|
public class EndTurnAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
if (mandatory) {
|
return mandatory;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
} else {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiAbilityDecision chkDrawback(SpellAbility sa, Player aiPlayer) { return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi); }
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) { return false; }
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,146 +0,0 @@
|
|||||||
package forge.ai.ability;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
import forge.ai.AiAbilityDecision;
|
|
||||||
import forge.ai.AiPlayDecision;
|
|
||||||
import forge.ai.ComputerUtilCard;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
|
||||||
import forge.game.ability.AbilityUtils;
|
|
||||||
import forge.game.Game;
|
|
||||||
import forge.game.card.*;
|
|
||||||
import forge.game.card.token.TokenInfo;
|
|
||||||
import forge.game.combat.Combat;
|
|
||||||
import forge.game.combat.CombatUtil;
|
|
||||||
import forge.game.player.Player;
|
|
||||||
import forge.game.player.PlayerActionConfirmMode;
|
|
||||||
import forge.game.spellability.SpellAbility;
|
|
||||||
import forge.game.zone.ZoneType;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class EndureAi extends SpellAbilityAi {
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
|
||||||
// Support for possible targeted Endure (e.g. target creature endures X)
|
|
||||||
if (sa.usesTargeting()) {
|
|
||||||
Card bestCreature = ComputerUtilCard.getBestCreatureAI(aiPlayer.getCardsIn(ZoneType.Battlefield));
|
|
||||||
if (bestCreature == null) {
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
|
|
||||||
sa.resetTargets();
|
|
||||||
sa.getTargets().add(bestCreature);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean shouldPutCounters(Player ai, SpellAbility sa) {
|
|
||||||
// TODO: adapted from Fabricate AI in TokenAi, maybe can be refactored to a single method
|
|
||||||
final Card source = sa.getHostCard();
|
|
||||||
final Game game = source.getGame();
|
|
||||||
final String num = sa.getParamOrDefault("Num", "1");
|
|
||||||
final int amount = AbilityUtils.calculateAmount(source, num, sa);
|
|
||||||
|
|
||||||
// if host would leave the play or if host is useless, create the token
|
|
||||||
if (source.hasSVar("EndOfTurnLeavePlay") || ComputerUtilCard.isUselessCreature(ai, source)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// need a copy for one with extra +1/+1 counter boost,
|
|
||||||
// without causing triggers to run
|
|
||||||
final Card copy = CardCopyService.getLKICopy(source);
|
|
||||||
copy.setCounters(CounterEnumType.P1P1, copy.getCounters(CounterEnumType.P1P1) + amount);
|
|
||||||
copy.setZone(source.getZone());
|
|
||||||
|
|
||||||
// if host would put into the battlefield attacking
|
|
||||||
Combat combat = source.getGame().getCombat();
|
|
||||||
if (combat != null && combat.isAttacking(source)) {
|
|
||||||
final Player defender = combat.getDefenderPlayerByAttacker(source);
|
|
||||||
return defender.canLoseLife() && !ComputerUtilCard.canBeBlockedProfitably(defender, copy, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the host has haste and can attack
|
|
||||||
if (CombatUtil.canAttack(copy)) {
|
|
||||||
for (final Player opp : ai.getOpponents()) {
|
|
||||||
if (CombatUtil.canAttack(copy, opp) &&
|
|
||||||
opp.canLoseLife() &&
|
|
||||||
!ComputerUtilCard.canBeBlockedProfitably(opp, copy, true))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO check for trigger to turn token ETB into +1/+1 counter for host
|
|
||||||
// TODO check for trigger to turn token ETB into damage or life loss for opponent
|
|
||||||
// in these cases token might be preferred even if they would not survive
|
|
||||||
|
|
||||||
// evaluate creature with counters
|
|
||||||
int evalCounter = ComputerUtilCard.evaluateCreature(copy);
|
|
||||||
|
|
||||||
// spawn the token so it's possible to evaluate it
|
|
||||||
final Card token = TokenInfo.getProtoType("w_x_x_spirit", sa, ai, false);
|
|
||||||
|
|
||||||
token.setController(ai, 0);
|
|
||||||
token.setLastKnownZone(ai.getZone(ZoneType.Battlefield));
|
|
||||||
token.setTokenSpawningAbility(sa);
|
|
||||||
|
|
||||||
// evaluate the generated token
|
|
||||||
token.setBasePowerString(num);
|
|
||||||
token.setBasePower(amount);
|
|
||||||
token.setBaseToughnessString(num);
|
|
||||||
token.setBaseToughness(amount);
|
|
||||||
|
|
||||||
boolean result = true;
|
|
||||||
|
|
||||||
// need to check what the cards would be on the battlefield
|
|
||||||
// do not attach yet, that would cause Events
|
|
||||||
CardCollection preList = new CardCollection(token);
|
|
||||||
game.getAction().checkStaticAbilities(false, Sets.newHashSet(token), preList);
|
|
||||||
|
|
||||||
// token would not survive
|
|
||||||
if (!token.isCreature() || token.getNetToughness() < 1) {
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
int evalToken = ComputerUtilCard.evaluateCreature(token);
|
|
||||||
result = evalToken < evalCounter;
|
|
||||||
}
|
|
||||||
|
|
||||||
//reset static abilities
|
|
||||||
game.getAction().checkStaticAbilities(false);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message, Map<String, Object> params) {
|
|
||||||
return shouldPutCounters(player, sa);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
|
||||||
// Support for possible targeted Endure (e.g. target creature endures X)
|
|
||||||
if (sa.usesTargeting()) {
|
|
||||||
CardCollection list = CardLists.getValidCards(aiPlayer.getGame().getCardsIn(ZoneType.Battlefield),
|
|
||||||
sa.getTargetRestrictions().getValidTgts(), aiPlayer, sa.getHostCard(), sa);
|
|
||||||
|
|
||||||
if (!list.isEmpty()) {
|
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(list));
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mandatory) {
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return canPlay(aiPlayer, sa);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,19 +15,19 @@ public class ExploreAi extends SpellAbilityAi {
|
|||||||
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision canPlay(Player aiPlayer, SpellAbility sa) {
|
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
|
||||||
// Explore with a target (e.g. Enter the Unknown)
|
// Explore with a target (e.g. Enter the Unknown)
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
Card bestCreature = ComputerUtilCard.getBestCreatureAI(aiPlayer.getCardsIn(ZoneType.Battlefield));
|
Card bestCreature = ComputerUtilCard.getBestCreatureAI(aiPlayer.getCardsIn(ZoneType.Battlefield));
|
||||||
if (bestCreature == null) {
|
if (bestCreature == null) {
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
sa.getTargets().add(bestCreature);
|
sa.getTargets().add(bestCreature);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldPutInGraveyard(Card topCard, Player ai) {
|
public static boolean shouldPutInGraveyard(Card topCard, Player ai) {
|
||||||
@@ -64,23 +64,19 @@ public class ExploreAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AiAbilityDecision doTriggerNoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
if (sa.usesTargeting()) {
|
if (sa.usesTargeting()) {
|
||||||
CardCollection list = CardLists.getValidCards(aiPlayer.getGame().getCardsIn(ZoneType.Battlefield),
|
CardCollection list = CardLists.getValidCards(aiPlayer.getGame().getCardsIn(ZoneType.Battlefield),
|
||||||
sa.getTargetRestrictions().getValidTgts(), aiPlayer, sa.getHostCard(), sa);
|
sa.getTargetRestrictions().getValidTgts(), aiPlayer, sa.getHostCard(), sa);
|
||||||
|
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(list));
|
sa.getTargets().add(ComputerUtilCard.getBestCreatureAI(list));
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mandatory) {
|
return canPlayAI(aiPlayer, sa) || mandatory;
|
||||||
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
return canPlay(aiPlayer, sa);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user