core: import the rules core (ygopro-core 973672dc + fork patches)
The vendored ocgcore from the Unity repo (Tools/YGOLegacy/ocgcore at dev HEAD). Upstream is nanahira/ygopro-core at 973672dc9ce7cb49f47173277ab1ad0e318b7593; the seven files that differ from it carry the fork's core patches, already applied: 0001 face-down Token setcode, 0004 effect damage step outside a chain, 0008 Sandbox god mode, 0015 tag first seat holds the hand, 0022 attack preview, 0024 attack preview legality. Generated build/ output is left out. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
26f9baf9b4
47 files changed
+40899
No files matched your search
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
name: Automated Test Build
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
runs-on: windows-2022
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Download lua
|
||||
id: lua
|
||||
uses: mercury233/action-cache-download-file@0e2b8bab566270adae95bd3cd298744402b667eb # v1.1.0
|
||||
with:
|
||||
url: https://www.lua.org/ftp/lua-5.4.8.tar.gz
|
||||
|
||||
- name: Lua
|
||||
run: |
|
||||
tar -xzf ${{ steps.lua.outputs.filepath }}
|
||||
move lua-5.4.8 lua
|
||||
|
||||
- name: Download premake
|
||||
id: premake
|
||||
uses: mercury233/action-cache-download-file@0e2b8bab566270adae95bd3cd298744402b667eb
|
||||
with:
|
||||
url: https://github.com/premake/premake-core/releases/download/v5.0.0-beta7/premake-5.0.0-beta7-windows.zip
|
||||
|
||||
- name: Premake
|
||||
run: |
|
||||
mkdir premake-5
|
||||
tar -C premake-5 -xzf ${{ steps.premake.outputs.filepath }}
|
||||
copy premake\lua.lua lua\premake5.lua
|
||||
copy premake\dll.lua dll.lua
|
||||
.\premake-5\premake5.exe vs2022 --file=dll.lua
|
||||
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
|
||||
- name: Build x32
|
||||
run: |
|
||||
msbuild build\ocgcoredll.sln /m /t:Build /p:"Configuration=Release;Platform=Win32"
|
||||
|
||||
- name: Build x64
|
||||
run: |
|
||||
msbuild build\ocgcoredll.sln /m /t:Build /p:"Configuration=Release;Platform=x64"
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: ocgcore-windows
|
||||
path: |
|
||||
build/bin/x32/Release/ocgcore.dll
|
||||
build/bin/x64/Release/ocgcore.dll
|
||||
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y gcc-multilib g++-multilib
|
||||
|
||||
- name: Download lua
|
||||
id: lua
|
||||
uses: mercury233/action-cache-download-file@0e2b8bab566270adae95bd3cd298744402b667eb
|
||||
with:
|
||||
url: https://www.lua.org/ftp/lua-5.4.8.tar.gz
|
||||
|
||||
- name: Lua
|
||||
run: |
|
||||
tar -xzf ${{ steps.lua.outputs.filepath }}
|
||||
mv lua-5.4.8 lua
|
||||
|
||||
- name: Download premake
|
||||
id: premake
|
||||
uses: mercury233/action-cache-download-file@0e2b8bab566270adae95bd3cd298744402b667eb
|
||||
with:
|
||||
url: https://github.com/premake/premake-core/releases/download/v5.0.0-beta7/premake-5.0.0-beta7-linux.tar.gz
|
||||
|
||||
- name: Premake
|
||||
run: |
|
||||
mkdir premake-5
|
||||
tar -C premake-5 -xzf ${{ steps.premake.outputs.filepath }}
|
||||
cp premake/lua.lua lua/premake5.lua
|
||||
cp premake/dll.lua dll.lua
|
||||
chmod +x premake-5/premake5
|
||||
./premake-5/premake5 gmake --file=dll.lua
|
||||
|
||||
- name: Build x32
|
||||
run: |
|
||||
cd build
|
||||
make -j $(nproc) config=release_x32
|
||||
cd ..
|
||||
|
||||
- name: Build x64
|
||||
run: |
|
||||
cd build
|
||||
make -j $(nproc) config=release_x64
|
||||
cd ..
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: ocgcore-linux
|
||||
path: |
|
||||
build/bin/x32/Release/libocgcore.so
|
||||
build/bin/x64/Release/libocgcore.so
|
||||
@@ -0,0 +1,15 @@
|
||||
/.vscode/
|
||||
/build/
|
||||
/lua
|
||||
/temp/
|
||||
/.emsdk/
|
||||
/premake-5/
|
||||
/premake5.exe
|
||||
/premake5
|
||||
|
||||
/dll.lua
|
||||
/*.sh
|
||||
/test-wasm
|
||||
/wasm
|
||||
/dist
|
||||
/research
|
||||
@@ -0,0 +1,269 @@
|
||||
stages:
|
||||
- prepare
|
||||
- build
|
||||
- combine
|
||||
- deploy
|
||||
|
||||
variables:
|
||||
GIT_DEPTH: "1"
|
||||
|
||||
.no_888:
|
||||
except:
|
||||
- '888'
|
||||
|
||||
mat_common:
|
||||
stage: prepare
|
||||
tags:
|
||||
- linux
|
||||
script:
|
||||
# lua
|
||||
- wget -O - https://mat-cacher.moenext.com/https://www.lua.org/ftp/lua-5.4.8.tar.gz | tar zfx -
|
||||
- mv lua-5.4.8 lua
|
||||
- cp premake/lua.lua lua/premake5.lua
|
||||
- wget -O - https://mat-cacher.moenext.com/https://www.sqlite.org/2026/sqlite-autoconf-3510300.tar.gz | tar zfx -
|
||||
- mv sqlite-autoconf-3510300 sqlite3
|
||||
artifacts:
|
||||
paths:
|
||||
- lua
|
||||
- sqlite3
|
||||
|
||||
mat_windows:
|
||||
extends: .no_888
|
||||
stage: prepare
|
||||
tags:
|
||||
- linux
|
||||
script:
|
||||
# premake5.exe
|
||||
- wget https://cdn02.moecube.com:444/premake5-built/premake-5.0.0-beta8-windows.zip
|
||||
- 7z x -y premake-5.0.0-beta8-windows.zip
|
||||
artifacts:
|
||||
paths:
|
||||
- premake5.exe
|
||||
|
||||
mat_macos:
|
||||
extends: .no_888
|
||||
stage: prepare
|
||||
tags:
|
||||
- linux
|
||||
script:
|
||||
- wget -O - https://cdn02.moecube.com:444/premake5-built/premake-5.0.0-beta8-macosx.tar.gz | tar zfx -
|
||||
- chmod +x premake5
|
||||
artifacts:
|
||||
paths:
|
||||
- premake5
|
||||
|
||||
.build:
|
||||
extends: .no_888
|
||||
stage: build
|
||||
dependencies:
|
||||
- mat_common
|
||||
artifacts:
|
||||
paths:
|
||||
- dist
|
||||
|
||||
.build_unix:
|
||||
extends: .build
|
||||
tags:
|
||||
- noavx2
|
||||
image: git-registry.moenext.com/mycard/docker-ygopro-builder:debian11
|
||||
variables:
|
||||
PREMAKE_OS: linux
|
||||
BUILD_TYPE: x64
|
||||
PREMAKE5_PATH: premake5
|
||||
script:
|
||||
- ln -sf premake/dll.lua .
|
||||
- $PREMAKE5_PATH gmake --file=dll.lua --os=$PREMAKE_OS --sqlite3-dir=sqlite3
|
||||
- cd build
|
||||
- make config=release_${BUILD_TYPE} -j$(nproc)
|
||||
- cd ..
|
||||
- mkdir -p dist/$BUILD_TYPE
|
||||
- cp build/bin/$BUILD_TYPE/Release/libocgcore.* dist/$BUILD_TYPE/
|
||||
- cp build/bin/$BUILD_TYPE/Release/libsqlite3.* dist/$BUILD_TYPE/ || true
|
||||
|
||||
build_linux_x64:
|
||||
extends: .build_unix
|
||||
|
||||
build_android:
|
||||
extends: .build_unix
|
||||
variables:
|
||||
BUILD_TYPE: android_arm64
|
||||
NDK_DIR: android-ndk-r23b
|
||||
ANDROID_API_LEVEL: '26'
|
||||
before_script:
|
||||
- wget -O android-ndk-r23b-linux.zip https://mat-cacher.moenext.com/https://dl.google.com/android/repository/android-ndk-r23b-linux.zip
|
||||
- 7z x -y android-ndk-r23b-linux.zip
|
||||
|
||||
build_linux_x64_no_longjmp:
|
||||
extends: .build_unix
|
||||
except: []
|
||||
only:
|
||||
- '888'
|
||||
variables:
|
||||
NO_LONGJMP: '1'
|
||||
|
||||
build_linux_x32:
|
||||
extends: .build_unix
|
||||
variables:
|
||||
BUILD_TYPE: x32
|
||||
before_script:
|
||||
- apt update; apt -y install gcc-multilib g++-multilib
|
||||
|
||||
build_wasm_cjs:
|
||||
extends: .build_unix
|
||||
except: []
|
||||
variables:
|
||||
PREMAKE_OS: emscripten
|
||||
BUILD_TYPE: wasm_cjs
|
||||
image: git-registry.moenext.com/mycard/docker-ygopro-builder:debian12
|
||||
|
||||
build_wasm_esm:
|
||||
extends: .build_unix
|
||||
variables:
|
||||
PREMAKE_OS: emscripten
|
||||
BUILD_TYPE: wasm_esm
|
||||
image: git-registry.moenext.com/mycard/docker-ygopro-builder:debian12
|
||||
|
||||
.build_windows:
|
||||
extends: .build
|
||||
dependencies:
|
||||
- mat_common
|
||||
- mat_windows
|
||||
tags:
|
||||
- vs
|
||||
before_script:
|
||||
- copy premake\dll.lua dll.lua
|
||||
- '.\premake5.exe vs2026 --file=dll.lua --sqlite3-dir=sqlite3'
|
||||
- mkdir dist
|
||||
|
||||
build_windows_x32:
|
||||
extends: .build_windows
|
||||
script:
|
||||
- cmd /c '"C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Current\Bin\msbuild.exe" build\ocgcoredll.slnx /t:Build /p:Configuration=Release /p:Platform=Win32'
|
||||
- mkdir dist\x32
|
||||
- copy build\bin\x32\Release\ocgcore.dll dist\x32\ocgcore.dll
|
||||
- copy build\bin\x32\Release\sqlite3.dll dist\x32\sqlite3.dll
|
||||
|
||||
build_windows_x64:
|
||||
extends: .build_windows
|
||||
script:
|
||||
- cmd /c '"C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Current\Bin\msbuild.exe" build\ocgcoredll.slnx /t:Build /p:Configuration=Release /p:Platform=x64'
|
||||
- mkdir dist\x64
|
||||
- copy build\bin\x64\Release\ocgcore.dll dist\x64\ocgcore.dll
|
||||
- copy build\bin\x64\Release\sqlite3.dll dist\x64\sqlite3.dll
|
||||
|
||||
.build_macos_arch:
|
||||
extends: .build_unix
|
||||
tags:
|
||||
- macos
|
||||
dependencies:
|
||||
- mat_common
|
||||
- mat_macos
|
||||
variables:
|
||||
PREMAKE_OS: macosx
|
||||
PREMAKE5_PATH: ./premake5
|
||||
before_script:
|
||||
- rm -rf sqlite3/VERSION sqlite3/version
|
||||
|
||||
build_macos_x64:
|
||||
extends: .build_macos_arch
|
||||
variables:
|
||||
BUILD_TYPE: x64
|
||||
|
||||
build_macos_m1:
|
||||
extends: .build_macos_arch
|
||||
tags:
|
||||
- macos-m1
|
||||
variables:
|
||||
BUILD_TYPE: arm64
|
||||
|
||||
build_macos:
|
||||
extends: .no_888
|
||||
stage: combine
|
||||
dependencies:
|
||||
- build_macos_x64
|
||||
- build_macos_m1
|
||||
tags:
|
||||
- macos
|
||||
script:
|
||||
- mkdir -p dist/macos
|
||||
- lipo -create -output dist/macos/libocgcore.dylib dist/x64/libocgcore.dylib dist/arm64/libocgcore.dylib
|
||||
- lipo -create -output dist/macos/libsqlite3.dylib dist/x64/libsqlite3.dylib dist/arm64/libsqlite3.dylib
|
||||
- rm -rf dist/x64 dist/arm64
|
||||
artifacts:
|
||||
paths:
|
||||
- dist
|
||||
|
||||
upload_to_minio:
|
||||
stage: deploy
|
||||
dependencies:
|
||||
- build_android
|
||||
- build_linux_x32
|
||||
- build_linux_x64
|
||||
- build_windows_x32
|
||||
- build_windows_x64
|
||||
- build_macos
|
||||
- build_wasm_cjs
|
||||
- build_wasm_esm
|
||||
tags:
|
||||
- linux
|
||||
variables:
|
||||
MINIO_DIR: 'libocgcore-koishi'
|
||||
script:
|
||||
- aws s3 --endpoint=https://minio.moenext.com:9000 sync --delete dist/ s3://mycard/$MINIO_DIR
|
||||
only:
|
||||
- master
|
||||
|
||||
upload_to_minio_develop:
|
||||
extends: upload_to_minio
|
||||
variables:
|
||||
MINIO_DIR: 'libocgcore-koishi-develop'
|
||||
only:
|
||||
- develop
|
||||
|
||||
.deploy_to_server:
|
||||
stage: deploy
|
||||
tags:
|
||||
- linux
|
||||
variables:
|
||||
SERVER_USER: nanahira
|
||||
SERVER_HOST: koishi.momobako.com
|
||||
FROM_PATH: ''
|
||||
SERVER_PATH: ''
|
||||
script:
|
||||
- apt update && apt -y install openssh-client rsync coreutils
|
||||
- mkdir -p ~/.ssh
|
||||
- chmod 700 ~/.ssh
|
||||
- ssh-keyscan $SERVER_HOST >> ~/.ssh/known_hosts
|
||||
- echo $NANAHIRA_SSH_KEY | base64 --decode > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/*
|
||||
- rsync -4cavzP $FROM_PATH $SERVER_USER@$SERVER_HOST:$SERVER_PATH
|
||||
|
||||
deploy_888_so:
|
||||
extends: .deploy_to_server
|
||||
dependencies:
|
||||
- build_linux_x64_no_longjmp
|
||||
variables:
|
||||
FROM_PATH: 'dist/x64/libocgcore.so'
|
||||
SERVER_PATH: '~/ygopro-super-pre/bin/release/'
|
||||
only:
|
||||
- '888'
|
||||
|
||||
deploy_888_wasm:
|
||||
extends: .deploy_to_server
|
||||
dependencies:
|
||||
- build_wasm_cjs
|
||||
variables:
|
||||
FROM_PATH: 'dist/wasm_cjs/'
|
||||
SERVER_PATH: '~/srvpro2/888/wasm/'
|
||||
only:
|
||||
- '888'
|
||||
|
||||
deploy_8888_wasm:
|
||||
extends: .deploy_to_server
|
||||
dependencies:
|
||||
- build_wasm_cjs
|
||||
variables:
|
||||
FROM_PATH: 'dist/wasm_cjs/'
|
||||
SERVER_PATH: '~/srvpro2/8888/wasm/'
|
||||
only:
|
||||
- 'develop'
|
||||
@@ -0,0 +1,18 @@
|
||||
project (ocgcore)
|
||||
|
||||
set (AUTO_FILES_RESULT)
|
||||
AutoFiles("." "src" "\\.(cpp|c|h)$")
|
||||
|
||||
if (MSVC)
|
||||
include_directories ( ../lua )
|
||||
else ()
|
||||
include_directories ( ${LUA_INCLUDE_DIR} )
|
||||
endif ()
|
||||
|
||||
add_library (ocgcore STATIC ${AUTO_FILES_RESULT})
|
||||
|
||||
if (MSVC)
|
||||
target_link_libraries (ocgcore lua)
|
||||
else ()
|
||||
target_link_libraries (ocgcore ${LUA_LIBRARIES})
|
||||
endif ()
|
||||
+339
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -0,0 +1,120 @@
|
||||
#include "LuaMemTracker.h"
|
||||
#include <lauxlib.h>
|
||||
|
||||
LuaMemTracker::LuaMemTracker(size_t mem_limit)
|
||||
: limit(mem_limit) {
|
||||
lua_State* tmp_L = luaL_newstate(); // get default alloc
|
||||
real_alloc = lua_getallocf(tmp_L, &real_ud);
|
||||
lua_close(tmp_L);
|
||||
|
||||
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
|
||||
time_t now = time(nullptr);
|
||||
char filename[64];
|
||||
std::snprintf(filename, sizeof(filename), "memtrace-%ld.log", static_cast<long>(now));
|
||||
|
||||
log_file = std::fopen(filename, "a");
|
||||
if (log_file) {
|
||||
std::fprintf(log_file, "---- Lua memory tracking started ----\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
LuaMemTracker::~LuaMemTracker() {
|
||||
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
|
||||
if (log_file) {
|
||||
std::fprintf(log_file, "---- Lua memory tracking ended ----\n");
|
||||
std::fclose(log_file);
|
||||
log_file = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void* LuaMemTracker::AllocThunk(void* ud, void* ptr, size_t osize, size_t nsize) {
|
||||
return static_cast<LuaMemTracker*>(ud)->Alloc(ptr, osize, nsize);
|
||||
}
|
||||
|
||||
void* LuaMemTracker::Alloc(void* ptr, size_t osize, size_t nsize) {
|
||||
auto shrink = [&](size_t dec) {
|
||||
// Clamp subtraction to avoid size_t underflow.
|
||||
if (dec > total_allocated) {
|
||||
total_allocated = 0;
|
||||
} else {
|
||||
total_allocated -= dec;
|
||||
}
|
||||
};
|
||||
|
||||
if (nsize == 0) { // free
|
||||
if (ptr) {
|
||||
shrink(osize);
|
||||
}
|
||||
return real_alloc(real_ud, ptr, osize, nsize);
|
||||
}
|
||||
|
||||
// Unified path:
|
||||
// - grow > 0: check limit using safe inequality, then alloc; on success add 'grow'
|
||||
// - grow = 0: just alloc; accounting unchanged
|
||||
// - shrink > 0: shrink first, alloc; on failure, rollback the shrink
|
||||
auto do_alloc = [&](size_t grow_amount, size_t shrink_amount) -> void* {
|
||||
if (grow_amount > 0 && limit) {
|
||||
if (total_allocated >= limit || grow_amount > (limit - total_allocated)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto result = real_alloc(real_ud, ptr, osize, nsize);
|
||||
if (result) {
|
||||
if (shrink_amount > 0)
|
||||
shrink(shrink_amount);
|
||||
if (grow_amount > 0)
|
||||
total_allocated += grow_amount;
|
||||
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
|
||||
write_log();
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
if (ptr) {
|
||||
// realloc path: osize is the real old size
|
||||
if (nsize > osize) {
|
||||
// growth
|
||||
size_t grow = nsize - osize;
|
||||
return do_alloc(grow, 0);
|
||||
} else if (nsize < osize) {
|
||||
// shrink
|
||||
size_t dec = osize - nsize;
|
||||
return do_alloc(0, dec);
|
||||
} else {
|
||||
// no net change
|
||||
return do_alloc(0, 0);
|
||||
}
|
||||
} else {
|
||||
// malloc path: osize is a type tag; only count nsize
|
||||
return do_alloc(nsize, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
|
||||
void LuaMemTracker::write_log() {
|
||||
if (!log_file) return;
|
||||
|
||||
time_t now = time(nullptr);
|
||||
struct tm* tm_info = localtime(&now);
|
||||
|
||||
char time_buf[32];
|
||||
std::strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", tm_info);
|
||||
|
||||
if (total_allocated > max_used)
|
||||
max_used = total_allocated;
|
||||
|
||||
if (limit)
|
||||
std::fprintf(log_file, "%s | used = %zu bytes | max_used = %zu bytes | limit = %zu\n",
|
||||
time_buf, total_allocated, max_used, limit);
|
||||
else
|
||||
std::fprintf(log_file, "%s | used = %zu bytes | max_used = %zu bytes | limit = unlimited\n",
|
||||
time_buf, total_allocated, max_used);
|
||||
|
||||
std::fflush(log_file); // make it write instantly
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef LUA_MEM_TRACKER_H
|
||||
#define LUA_MEM_TRACKER_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <lua.h>
|
||||
|
||||
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
|
||||
#include <ctime> // time_t
|
||||
#include <cstdio> // FILE*, fopen, fprintf
|
||||
#endif
|
||||
|
||||
class LuaMemTracker {
|
||||
public:
|
||||
LuaMemTracker(size_t mem_limit = 0);
|
||||
~LuaMemTracker();
|
||||
static void* AllocThunk(void* ud, void* ptr, size_t osize, size_t nsize);
|
||||
void* Alloc(void* ptr, size_t osize, size_t nsize);
|
||||
|
||||
size_t get_total() const { return total_allocated; }
|
||||
size_t get_limit() const { return limit; }
|
||||
|
||||
private:
|
||||
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
|
||||
FILE* log_file = nullptr;
|
||||
void write_log();
|
||||
#endif
|
||||
|
||||
lua_Alloc real_alloc;
|
||||
void* real_ud;
|
||||
size_t total_allocated = 0;
|
||||
size_t limit = 0;
|
||||
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
|
||||
size_t max_used = 0; // for logging purposes, to track peak memory usage
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // LUA_MEM_TRACKER_H
|
||||
@@ -0,0 +1,79 @@
|
||||
# YGOPro script engine
|
||||
|
||||
## Introduction
|
||||
The core logic and lua script processor of YGOPro. This library can be made external of the project and used to power server technologies. It maintains a state engine that is manipulated by Lua scripts using manipulation functions it exposes.
|
||||
|
||||
## Compiling
|
||||
In most cases, what you want to compile is the main program of YGOPro. You should refer to the main YGOPro project's [wiki](https://github.com/Fluorohydride/ygopro/wiki).
|
||||
If you want to compile the dynamic link library of this repository (ocgcore.dll), you can refer to [this script](https://github.com/Fluorohydride/ygopro-core/blob/master/.github/workflows/build.yml).
|
||||
|
||||
For WebAssembly builds, use Emscripten 3.1.1 through 3.1.7.
|
||||
|
||||
## Exposed Functions
|
||||
|
||||
The 3 functions need to be provided to the core so it can get card and database information.
|
||||
- `void set_script_reader(script_reader f);`
|
||||
Interface provided returns scripts based on number that corresponds to a lua file, send in a string.
|
||||
|
||||
- `void set_card_reader(card_reader f);`
|
||||
Interface provided function that provides database information from the `datas` table of `cards.cdb`.
|
||||
|
||||
- `void set_message_handler(message_handler f);`
|
||||
Interface provided function that handles error messages.
|
||||
|
||||
These functions create the game itself and then manipulate it.
|
||||
- `intptr_t create_duel(uint_fast32_t seed);`
|
||||
(Deprecated) Create an instance of `duel` with 1 uint32 PRNG seed.
|
||||
This function is reserved for replay mode only.
|
||||
|
||||
- `intptr_t create_duel_v2(uint32_t seed_sequence[]);`
|
||||
Create an instance of `duel` with PRNG seed `seed_sequence[]` of length `SEED_COUNT`.
|
||||
|
||||
- `void start_duel(intptr_t pduel, uint32_t options);`
|
||||
Start the duel.
|
||||
|
||||
- `void end_duel(intptr_t pduel);`
|
||||
End the duel.
|
||||
|
||||
- `void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount);`
|
||||
Set up the duel information.
|
||||
|
||||
- `void get_log_message(intptr_t pduel, char* buf);`
|
||||
|
||||
- `int32_t get_message(intptr_t pduel, byte* buf);`
|
||||
|
||||
- `int32_t process(intptr_t pduel);`
|
||||
Do a game tick.
|
||||
|
||||
- `void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);`
|
||||
Add a card to the duel state.
|
||||
|
||||
- `void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location);`
|
||||
Add a new card to the tag pool.
|
||||
|
||||
- `int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint32_t query_flag, byte* buf, int32_t use_cache);`
|
||||
Get a card in a specific location.
|
||||
|
||||
- `int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location);`
|
||||
Get the number of cards in a specific location.
|
||||
|
||||
- `int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);`
|
||||
Get all cards in some location.
|
||||
|
||||
- `int32_t query_field_info(intptr_t pduel, byte* buf);`
|
||||
|
||||
- `void set_responsei(intptr_t pduel, int32_t value);`
|
||||
|
||||
- `void set_responseb(intptr_t pduel, byte* buf);`
|
||||
|
||||
- `int32_t preload_script(intptr_t pduel, const char* script_name);`
|
||||
|
||||
- `byte* default_script_reader(const char* script_name, int* len);`
|
||||
The default script reader using `fread`.
|
||||
|
||||
# Lua functions
|
||||
- `libcard.cpp`
|
||||
- `libdebug.cpp`
|
||||
- `libduel.cpp`
|
||||
- `libeffect.cpp`
|
||||
- `libgroup.cpp`
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef CORE_BUFFER_H
|
||||
#define CORE_BUFFER_H
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
inline void buffer_read_block(unsigned char*& p, void* dest, size_t size) {
|
||||
std::memcpy(dest, p, size);
|
||||
p += size;
|
||||
}
|
||||
template<typename T>
|
||||
inline T buffer_read(unsigned char*& p) {
|
||||
T ret{};
|
||||
std::memcpy(&ret, p, sizeof(T));
|
||||
p += sizeof(T);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline void buffer_write_block(unsigned char*& p, const void* src, size_t size) {
|
||||
std::memcpy(p, src, size);
|
||||
p += size;
|
||||
}
|
||||
template<typename T>
|
||||
inline void buffer_write(unsigned char*& p, const T& value) {
|
||||
std::memcpy(p, &value, sizeof(T));
|
||||
p += sizeof(T);
|
||||
}
|
||||
|
||||
inline void vector_write_block(std::vector<unsigned char>& buffer, const void* src, size_t size) {
|
||||
auto* bytes = static_cast<const unsigned char*>(src);
|
||||
buffer.insert(buffer.end(), bytes, bytes + size);
|
||||
}
|
||||
template<typename T>
|
||||
inline void vector_write(std::vector<unsigned char>& buffer, const T& value) {
|
||||
vector_write_block(buffer, &value, sizeof(T));
|
||||
}
|
||||
|
||||
inline void vector_fread(std::vector<unsigned char>& buffer, FILE* fp) {
|
||||
unsigned char temp[4096]{};
|
||||
while (size_t len = std::fread(temp, 1, sizeof temp, fp))
|
||||
vector_write_block(buffer, temp, len);
|
||||
std::fclose(fp);
|
||||
}
|
||||
|
||||
#endif // !CORE_BUFFER_H
|
||||
+4302
File diff suppressed because it is too large.
Load diff
+473
@@ -0,0 +1,473 @@
|
||||
/*
|
||||
* card.h
|
||||
*
|
||||
* Created on: 2010-4-8
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef CARD_H_
|
||||
#define CARD_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "effectset.h"
|
||||
#include "card_data.h"
|
||||
#include "sort.h"
|
||||
#include "metadata.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <tuple>
|
||||
|
||||
class card;
|
||||
class duel;
|
||||
class effect;
|
||||
class group;
|
||||
struct chain;
|
||||
|
||||
using card_set = std::set<card*, card_sort>;
|
||||
using card_vector = std::vector<card*>;
|
||||
using effect_container = std::multimap<uint32_t, effect*>;
|
||||
using effect_indexer = std::unordered_map<effect*, effect_container::iterator>;
|
||||
using effect_collection = std::unordered_set<effect*>;
|
||||
|
||||
using effect_filter = bool(*)(card* self, effect* peffect);
|
||||
using effect_filter_target = bool(*)(card* self, effect* peffect, card* target);
|
||||
|
||||
struct card_state {
|
||||
uint32_t code{ 0 };
|
||||
uint32_t code2{ 0 };
|
||||
std::vector<uint16_t> setcode;
|
||||
uint32_t type{ 0 };
|
||||
uint32_t level{ 0 };
|
||||
uint32_t rank{ 0 };
|
||||
uint32_t link{ 0 };
|
||||
uint32_t lscale{ 0 };
|
||||
uint32_t rscale{ 0 };
|
||||
uint32_t attribute{ 0 };
|
||||
uint32_t race{ 0 };
|
||||
int32_t attack{ 0 };
|
||||
int32_t defense{ 0 };
|
||||
int32_t base_attack{ 0 };
|
||||
int32_t base_defense{ 0 };
|
||||
uint8_t controler{ PLAYER_NONE };
|
||||
uint8_t location{ 0 };
|
||||
uint8_t sequence{ 0 };
|
||||
uint8_t position{ 0 };
|
||||
uint32_t reason{ 0 };
|
||||
card* reason_card{ nullptr };
|
||||
effect* reason_effect{ nullptr };
|
||||
uint8_t reason_player{ PLAYER_NONE };
|
||||
bool pzone{ false };
|
||||
|
||||
bool is_location(uint32_t loc) const;
|
||||
bool is_main_mzone() const {
|
||||
return location == LOCATION_MZONE && sequence >= 0 && sequence <= 4;
|
||||
}
|
||||
bool is_stzone() const {
|
||||
return location == LOCATION_SZONE && sequence >= 0 && sequence <= 4;
|
||||
}
|
||||
void init_state();
|
||||
};
|
||||
|
||||
struct query_cache {
|
||||
uint32_t info_location{ UINT32_MAX };
|
||||
uint32_t current_code{ UINT32_MAX };
|
||||
uint32_t type{ UINT32_MAX };
|
||||
uint32_t level{ UINT32_MAX };
|
||||
uint32_t rank{ UINT32_MAX };
|
||||
uint32_t link{ UINT32_MAX };
|
||||
uint32_t attribute{ UINT32_MAX };
|
||||
uint32_t race{ UINT32_MAX };
|
||||
int32_t attack{ -1 };
|
||||
int32_t defense{ -1 };
|
||||
int32_t base_attack{ -1 };
|
||||
int32_t base_defense{ -1 };
|
||||
uint32_t reason{ UINT32_MAX };
|
||||
uint32_t status{ UINT32_MAX };
|
||||
uint32_t lscale{ UINT32_MAX };
|
||||
uint32_t rscale{ UINT32_MAX };
|
||||
uint32_t link_marker{ UINT32_MAX };
|
||||
|
||||
void clear_cache();
|
||||
};
|
||||
|
||||
struct material_info {
|
||||
// Synchron
|
||||
card* limit_tuner{ nullptr };
|
||||
group* limit_syn{ nullptr };
|
||||
int32_t limit_syn_minc{ 0 };
|
||||
int32_t limit_syn_maxc{ 0 };
|
||||
// Xyz
|
||||
group* limit_xyz{ nullptr };
|
||||
int32_t limit_xyz_minc{ 0 };
|
||||
int32_t limit_xyz_maxc{ 0 };
|
||||
// Link
|
||||
group* limit_link{ nullptr };
|
||||
card* limit_link_card{ nullptr };
|
||||
int32_t limit_link_minc{ 0 };
|
||||
int32_t limit_link_maxc{ 0 };
|
||||
};
|
||||
const material_info null_info;
|
||||
|
||||
class card {
|
||||
public:
|
||||
struct effect_relation_hash {
|
||||
std::size_t operator()(const std::pair<effect*, uint16_t>& v) const {
|
||||
std::size_t h1 = std::hash<effect*>()(v.first);
|
||||
std::size_t h2 = std::hash<uint16_t>()(v.second);
|
||||
return h1 ^ (h2 << 1);
|
||||
}
|
||||
};
|
||||
using effect_relation = std::unordered_set<std::pair<effect*, uint16_t>, effect_relation_hash>;
|
||||
using relation_map = std::unordered_map<card*, uint32_t>;
|
||||
using counter_map = std::map<uint16_t, uint16_t>;
|
||||
using effect_count = std::map<uint32_t, int32_t>;
|
||||
class attacker_map : public std::unordered_map<uint32_t, std::pair<card*, uint32_t>> {
|
||||
public:
|
||||
void addcard(card* pcard);
|
||||
uint32_t findcard(card* pcard);
|
||||
};
|
||||
|
||||
//millux
|
||||
|
||||
uint32_t get_ritual_type();
|
||||
uint32_t set_entity_code(uint32_t entity_code, bool remove_alias = false);
|
||||
uint32_t get_summon_info();
|
||||
|
||||
struct sendto_param_t {
|
||||
void set(uint8_t p, uint8_t pos, uint8_t loc, uint8_t seq = 0) {
|
||||
playerid = p;
|
||||
position = pos;
|
||||
location = loc;
|
||||
sequence = seq;
|
||||
}
|
||||
void clear() {
|
||||
playerid = 0;
|
||||
position = 0;
|
||||
location = 0;
|
||||
sequence = 0;
|
||||
}
|
||||
uint8_t playerid{ 0 };
|
||||
uint8_t position{ 0 };
|
||||
uint8_t location{ 0 };
|
||||
uint8_t sequence{ 0 };
|
||||
};
|
||||
|
||||
int32_t ref_handle{};
|
||||
duel* pduel{};
|
||||
metadata meta;
|
||||
card_data data;
|
||||
card_state previous;
|
||||
card_state temp;
|
||||
card_state current;
|
||||
card_state spsummon;
|
||||
query_cache q_cache;
|
||||
uint8_t owner{ PLAYER_NONE };
|
||||
uint8_t summon_player{ PLAYER_NONE };
|
||||
uint32_t summon_info{};
|
||||
uint32_t status{};
|
||||
sendto_param_t sendto_param;
|
||||
uint32_t release_param{};
|
||||
uint32_t sum_param{};
|
||||
uint32_t position_param{};
|
||||
uint32_t spsummon_param{};
|
||||
uint32_t to_field_param{};
|
||||
uint8_t attack_announce_count{};
|
||||
uint8_t direct_attackable{};
|
||||
uint8_t announce_count{};
|
||||
uint8_t attacked_count{};
|
||||
uint8_t removed_overlay_count{};
|
||||
uint8_t attack_all_target{};
|
||||
uint8_t attack_controler{};
|
||||
uint64_t cardid{};
|
||||
uint32_t fieldid{};
|
||||
uint32_t fieldid_r{}; //real field id, updated when moving to new location
|
||||
uint32_t activate_count_id{}; //updated when moving to new location or flipping
|
||||
uint16_t turnid{};
|
||||
uint16_t turn_counter{};
|
||||
uint8_t unique_pos[2]{};
|
||||
uint32_t unique_fieldid{};
|
||||
uint32_t unique_code{};
|
||||
uint32_t unique_location{};
|
||||
int32_t unique_function{};
|
||||
effect* unique_effect{};
|
||||
uint32_t spsummon_code{};
|
||||
uint16_t spsummon_counter[2]{};
|
||||
uint8_t assume_type{};
|
||||
uint32_t assume_value{};
|
||||
card* equiping_target{};
|
||||
card* pre_equip_target{};
|
||||
card* overlay_target{};
|
||||
relation_map relations;
|
||||
counter_map counters;
|
||||
effect_count indestructable_effects;
|
||||
attacker_map announced_cards;
|
||||
attacker_map attacked_cards;
|
||||
attacker_map battled_cards;
|
||||
card_set equiping_cards;
|
||||
card_set material_cards;
|
||||
card_set effect_target_owner;
|
||||
card_set effect_target_cards;
|
||||
card_vector xyz_materials;
|
||||
int32_t xyz_materials_previous_count_onfield{};
|
||||
effect_container single_effect;
|
||||
effect_container field_effect;
|
||||
effect_container equip_effect;
|
||||
effect_container target_effect;
|
||||
effect_container xmaterial_effect;
|
||||
effect_indexer indexer;
|
||||
effect_relation relate_effect;
|
||||
effect_set_v immune_effect;
|
||||
effect_collection initial_effect;
|
||||
effect_collection owning_effect;
|
||||
|
||||
uint8_t to_leave_fromex;
|
||||
|
||||
explicit card(duel* pd);
|
||||
~card() = default;
|
||||
static bool card_operation_sort(card* c1, card* c2);
|
||||
static bool check_card_setcode(uint32_t code, uint32_t value);
|
||||
bool is_extra_deck_monster() const { return !!(data.type & TYPES_EXTRA_DECK); }
|
||||
|
||||
int32_t get_infos(byte* buf, uint32_t query_flag, int32_t use_cache = TRUE);
|
||||
uint32_t get_info_location() const;
|
||||
uint32_t get_public_info_location();
|
||||
uint32_t get_original_code() const;
|
||||
std::tuple<uint32_t, uint32_t> get_original_code_rule() const;
|
||||
uint32_t get_code();
|
||||
uint32_t get_another_code();
|
||||
int32_t is_set_card(uint32_t set_code);
|
||||
int32_t is_origin_set_card(uint32_t set_code);
|
||||
int32_t is_pre_set_card(uint32_t set_code);
|
||||
int32_t is_fusion_set_card(uint32_t set_code);
|
||||
int32_t is_link_set_card(uint32_t set_code);
|
||||
int32_t is_special_summon_set_card(uint32_t set_code);
|
||||
uint32_t get_type();
|
||||
uint32_t get_fusion_type();
|
||||
uint32_t get_synchro_type();
|
||||
uint32_t get_xyz_type();
|
||||
uint32_t get_link_type();
|
||||
std::pair<int32_t, int32_t> get_base_atk_def();
|
||||
std::pair<int32_t, int32_t> get_atk_def();
|
||||
int32_t get_base_attack();
|
||||
int32_t get_attack();
|
||||
int32_t get_base_defense();
|
||||
int32_t get_defense();
|
||||
int32_t get_battle_attack();
|
||||
int32_t get_battle_defense();
|
||||
uint32_t get_level();
|
||||
uint32_t get_rank();
|
||||
uint32_t get_link();
|
||||
uint32_t get_mat_level_from_effect(card* pcard, uint32_t effect_code);
|
||||
uint32_t get_mat_level(card* pcard, uint32_t level_effect_code, uint32_t allow_effect_code = 0);
|
||||
uint32_t get_synchro_level(card* pcard);
|
||||
uint32_t get_ritual_level(card* pcard);
|
||||
uint32_t check_xyz_level(card* pcard, uint32_t lv);
|
||||
uint32_t get_attribute();
|
||||
uint32_t get_fusion_attribute(uint8_t playerid);
|
||||
uint32_t get_link_attribute(uint8_t playerid);
|
||||
uint32_t get_grave_attribute(uint8_t playerid);
|
||||
uint32_t get_race();
|
||||
uint32_t get_link_race(uint8_t playerid);
|
||||
uint32_t get_grave_race(uint8_t playerid);
|
||||
uint32_t get_lscale();
|
||||
uint32_t get_rscale();
|
||||
uint32_t get_link_marker();
|
||||
uint32_t is_link_marker(uint32_t dir);
|
||||
uint32_t get_linked_zone();
|
||||
void get_linked_cards(card_set* cset);
|
||||
uint32_t get_mutual_linked_zone();
|
||||
void get_mutual_linked_cards(card_set * cset);
|
||||
int32_t is_link_state();
|
||||
int32_t is_extra_link_state();
|
||||
int32_t is_position(uint32_t pos) const;
|
||||
void set_status(uint32_t x, int32_t enabled);
|
||||
int32_t get_status(uint32_t x) const;
|
||||
int32_t is_status(uint32_t x) const;
|
||||
uint32_t get_column_zone(int32_t location);
|
||||
void get_column_cards(card_set* cset);
|
||||
int32_t is_all_column();
|
||||
uint8_t get_select_sequence(uint8_t *deck_seq_pointer);
|
||||
uint32_t get_select_info_location(uint8_t *deck_seq_pointer);
|
||||
int32_t is_treated_as_not_on_field() const;
|
||||
|
||||
void equip(card* target, uint32_t send_msg = TRUE);
|
||||
void unequip();
|
||||
int32_t get_union_count();
|
||||
int32_t get_old_union_count();
|
||||
void xyz_overlay(const card_set& materials);
|
||||
void xyz_add(card* mat);
|
||||
void xyz_remove(card* mat);
|
||||
void apply_field_effect();
|
||||
void cancel_field_effect();
|
||||
void enable_field_effect(bool enabled);
|
||||
int32_t add_effect(effect* peffect);
|
||||
effect_indexer::iterator remove_effect(effect* peffect);
|
||||
int32_t copy_effect(uint32_t code, uint32_t reset, int32_t count);
|
||||
int32_t replace_effect(uint32_t code, uint32_t reset, int32_t count);
|
||||
void reset(uint32_t id, uint32_t reset_type);
|
||||
void reset_effect_count();
|
||||
void refresh_disable_status();
|
||||
std::tuple<uint8_t, effect*> refresh_control_status();
|
||||
|
||||
void count_turn(uint16_t ct);
|
||||
void create_relation(card* target, uint32_t reset);
|
||||
int32_t is_has_relation(card* target);
|
||||
void release_relation(card* target);
|
||||
void create_relation(const chain& ch);
|
||||
int32_t is_has_relation(const chain& ch);
|
||||
void release_relation(const chain& ch);
|
||||
void clear_relate_effect();
|
||||
void create_relation(effect* peffect);
|
||||
int32_t is_has_relation(effect* peffect);
|
||||
void release_relation(effect* peffect);
|
||||
int32_t leave_field_redirect(uint32_t reason);
|
||||
int32_t destination_redirect(uint8_t destination, uint32_t reason);
|
||||
int32_t add_counter(uint8_t playerid, uint16_t countertype, uint16_t count, uint8_t singly);
|
||||
int32_t remove_counter(uint16_t countertype, uint16_t count);
|
||||
int32_t is_can_add_counter(uint8_t playerid, uint16_t countertype, uint16_t count, uint8_t singly, uint32_t loc);
|
||||
int32_t is_can_have_counter(uint16_t countertype);
|
||||
int32_t get_counter(uint16_t countertype);
|
||||
void set_material(card_set* materials);
|
||||
void add_card_target(card* pcard);
|
||||
void cancel_card_target(card* pcard);
|
||||
void delete_card_target(uint32_t send_msg);
|
||||
void clear_card_target();
|
||||
void set_special_summon_status(effect* peffect);
|
||||
|
||||
template<typename T>
|
||||
void filter_effect_container(const effect_container& container, uint32_t code, effect_filter f, T& eset);
|
||||
void filter_effect_container(const effect_container& container, uint32_t code, effect_filter f, effect_collection& eset);
|
||||
void filter_effect(uint32_t code, effect_set* eset, uint8_t sort = TRUE);
|
||||
void filter_single_continuous_effect(uint32_t code, effect_set* eset, uint8_t sort = TRUE);
|
||||
void filter_self_effect(uint32_t code, effect_set* eset, uint8_t sort = TRUE);
|
||||
void filter_immune_effect();
|
||||
void filter_disable_related_cards();
|
||||
int32_t filter_summon_procedure(uint8_t playerid, effect_set* eset, uint8_t ignore_count, uint8_t min_tribute, uint32_t zone);
|
||||
int32_t check_summon_procedure(effect* proc, uint8_t playerid, uint8_t ignore_count, uint8_t min_tribute, uint32_t zone);
|
||||
int32_t filter_set_procedure(uint8_t playerid, effect_set* eset, uint8_t ignore_count, uint8_t min_tribute, uint32_t zone);
|
||||
int32_t check_set_procedure(effect* proc, uint8_t playerid, uint8_t ignore_count, uint8_t min_tribute, uint32_t zone);
|
||||
void filter_spsummon_procedure(uint8_t playerid, effect_set* eset, uint32_t summon_type, material_info info = null_info);
|
||||
void filter_spsummon_procedure_g(uint8_t playerid, effect_set* eset);
|
||||
effect* find_effect(const effect_container& container, uint32_t code, effect_filter f);
|
||||
effect* find_effect_with_target(const effect_container& container, uint32_t code, effect_filter_target f, card* target);
|
||||
effect* is_affected_by_effect(uint32_t code);
|
||||
effect* is_affected_by_effect(int32_t code, card* target);
|
||||
int32_t fusion_check(group* fusion_m, card* cg, uint32_t chkf, uint8_t not_material);
|
||||
void fusion_select(uint8_t playerid, group* fusion_m, card* cg, uint32_t chkf, uint8_t not_material);
|
||||
int32_t check_fusion_substitute(card* fcard);
|
||||
int32_t is_not_tuner(card* scard);
|
||||
int32_t is_tuner(card* scard);
|
||||
|
||||
int32_t check_unique_code(card* pcard);
|
||||
void get_unique_target(card_set* cset, int32_t controler, card* icard = nullptr);
|
||||
int32_t check_cost_condition(int32_t ecode, int32_t playerid);
|
||||
int32_t check_cost_condition(int32_t ecode, int32_t playerid, int32_t sumtype);
|
||||
int32_t is_summonable_card() const;
|
||||
int32_t is_spsummonable_card();
|
||||
int32_t is_fusion_summonable_card(uint32_t summon_type);
|
||||
int32_t is_spsummonable(effect* proc, material_info info = null_info);
|
||||
int32_t is_summonable(effect* proc, uint8_t min_tribute, uint32_t zone = 0x1f, uint32_t releasable = 0xff00ff);
|
||||
int32_t is_can_be_summoned(uint8_t playerid, uint8_t ingore_count, effect* peffect, uint8_t min_tribute, uint32_t zone = 0x1f);
|
||||
int32_t is_summon_negatable(uint32_t sumtype, effect* reason_effect);
|
||||
int32_t get_summon_tribute_count();
|
||||
int32_t get_set_tribute_count();
|
||||
int32_t is_can_be_flip_summoned(uint8_t playerid);
|
||||
int32_t is_special_summonable(uint8_t playerid, uint32_t summon_type, material_info info = null_info);
|
||||
int32_t is_can_be_special_summoned(effect* reason_effect, uint32_t sumtype, uint8_t sumpos, uint8_t sumplayer, uint8_t toplayer, uint8_t nocheck, uint8_t nolimit, uint32_t zone);
|
||||
uint8_t get_spsummonable_position(effect* reason_effect, uint32_t sumtype, uint8_t sumpos, uint8_t sumplayer, uint8_t toplayer);
|
||||
int32_t is_setable_mzone(uint8_t playerid, uint8_t ignore_count, effect* peffect, uint8_t min_tribute, uint32_t zone = 0x1f);
|
||||
int32_t is_setable_szone(uint8_t playerid, uint8_t ignore_fd = 0, uint8_t toplayer = 2, uint32_t zone = 0xff);
|
||||
int32_t is_affect_by_effect(effect* reason_effect);
|
||||
int32_t is_can_be_disabled_by_effect(effect* reason_effect, bool is_monster_effect);
|
||||
int32_t is_destructable();
|
||||
int32_t is_destructable_by_battle(card* pcard);
|
||||
effect* check_indestructable_by_effect(effect* reason_effect, uint8_t playerid);
|
||||
int32_t is_destructable_by_effect(effect* reason_effect, uint8_t playerid);
|
||||
int32_t is_removeable(uint8_t playerid, uint8_t pos, uint32_t reason);
|
||||
int32_t is_removeable_as_cost(uint8_t playerid, uint8_t pos);
|
||||
int32_t is_attack_decreasable_as_cost(uint8_t playerid, int32_t val);
|
||||
int32_t is_defense_decreasable_as_cost(uint8_t playerid, int32_t val);
|
||||
int32_t is_releasable_by_summon(uint8_t playerid, card* pcard);
|
||||
int32_t is_releasable_by_nonsummon(uint8_t playerid, uint32_t reason);
|
||||
int32_t is_releasable_by_effect(uint8_t playerid, effect* reason_effect);
|
||||
int32_t is_capable_send_to_grave(uint8_t playerid);
|
||||
int32_t is_capable_send_to_hand(uint8_t playerid);
|
||||
int32_t is_capable_send_to_deck(uint8_t playerid, uint8_t send_activating = FALSE);
|
||||
int32_t is_capable_send_to_extra(uint8_t playerid);
|
||||
int32_t is_capable_cost_to_grave(uint8_t playerid);
|
||||
int32_t is_capable_cost_to_hand(uint8_t playerid);
|
||||
int32_t is_capable_cost_to_deck(uint8_t playerid);
|
||||
int32_t is_capable_cost_to_extra(uint8_t playerid);
|
||||
int32_t is_capable_attack();
|
||||
int32_t is_capable_attack_announce(uint8_t playerid);
|
||||
int32_t is_capable_change_position(uint8_t playerid);
|
||||
int32_t is_capable_change_position_by_effect(uint8_t playerid);
|
||||
int32_t is_capable_turn_set(uint8_t playerid);
|
||||
int32_t is_capable_change_control();
|
||||
int32_t is_control_can_be_changed(int32_t ignore_mzone, uint32_t zone);
|
||||
int32_t is_capable_be_battle_target(card* pcard);
|
||||
int32_t is_capable_be_effect_target(effect* reason_effect, uint8_t playerid);
|
||||
int32_t is_capable_overlay(uint8_t playerid);
|
||||
int32_t is_can_be_fusion_material(card* fcard, uint32_t summon_type);
|
||||
int32_t is_can_be_synchro_material(card* scard, card* tuner = nullptr);
|
||||
int32_t is_can_be_ritual_material(card* scard);
|
||||
int32_t is_can_be_xyz_material(card* scard);
|
||||
int32_t is_can_be_link_material(card* scard);
|
||||
int32_t is_original_effect_property(int32_t filter);
|
||||
int32_t is_effect_property(int32_t filter);
|
||||
};
|
||||
|
||||
//Summon Type in summon_info
|
||||
#define SUMMON_TYPE_NORMAL 0x10000000U
|
||||
#define SUMMON_TYPE_ADVANCE 0x11000000U
|
||||
#define SUMMON_TYPE_FLIP 0x20000000U
|
||||
#define SUMMON_TYPE_SPECIAL 0x40000000U
|
||||
#define SUMMON_TYPE_FUSION 0x43000000U
|
||||
#define SUMMON_TYPE_RITUAL 0x45000000U
|
||||
#define SUMMON_TYPE_SYNCHRO 0x46000000U
|
||||
#define SUMMON_TYPE_XYZ 0x49000000U
|
||||
#define SUMMON_TYPE_PENDULUM 0x4a000000U
|
||||
#define SUMMON_TYPE_LINK 0x4c000000U
|
||||
|
||||
//Gemini Summon
|
||||
#define SUMMON_TYPE_DUAL 0x12000000U
|
||||
|
||||
//bitfield blocks
|
||||
#define SUMMON_VALUE_MAIN_TYPE 0xf0000000U
|
||||
#define SUMMON_VALUE_SUB_TYPE 0x0f000000U
|
||||
#define SUMMON_VALUE_LOCATION 0x00ff0000U
|
||||
#define SUMMON_VALUE_CUSTOM_TYPE 0x0000ffffU
|
||||
constexpr uint32_t DEFAULT_SUMMON_TYPE = SUMMON_VALUE_MAIN_TYPE | SUMMON_VALUE_SUB_TYPE | SUMMON_VALUE_CUSTOM_TYPE;
|
||||
|
||||
#define SUMMON_VALUE_FUTURE_FUSION 0x18
|
||||
|
||||
//Counter
|
||||
#define COUNTER_WITHOUT_PERMIT 0x1000U
|
||||
//#define COUNTER_NEED_ENABLE 0x2000
|
||||
|
||||
//Assume
|
||||
#define ASSUME_CODE 1
|
||||
#define ASSUME_TYPE 2
|
||||
#define ASSUME_LEVEL 3
|
||||
#define ASSUME_RANK 4
|
||||
#define ASSUME_ATTRIBUTE 5
|
||||
#define ASSUME_RACE 6
|
||||
#define ASSUME_ATTACK 7
|
||||
#define ASSUME_DEFENSE 8
|
||||
|
||||
//Special Summon effect info
|
||||
#define SUMMON_INFO_CODE 0x01
|
||||
#define SUMMON_INFO_CODE2 0x02
|
||||
#define SUMMON_INFO_TYPE 0x04
|
||||
#define SUMMON_INFO_LEVEL 0x08
|
||||
#define SUMMON_INFO_RANK 0x10
|
||||
#define SUMMON_INFO_ATTRIBUTE 0x20
|
||||
#define SUMMON_INFO_RACE 0x40
|
||||
#define SUMMON_INFO_ATTACK 0x80
|
||||
#define SUMMON_INFO_DEFENSE 0x100
|
||||
#define SUMMON_INFO_REASON_EFFECT 0x200
|
||||
#define SUMMON_INFO_REASON_PLAYER 0x400
|
||||
|
||||
#endif /* CARD_H_ */
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifndef CARD_DATA_H_
|
||||
#define CARD_DATA_H_
|
||||
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include "common.h"
|
||||
|
||||
constexpr int SIZE_SETCODE = 16;
|
||||
|
||||
//double name
|
||||
constexpr uint32_t CARD_MARINE_DOLPHIN = 78734254;
|
||||
constexpr uint32_t CARD_TWINKLE_MOSS = 13857930;
|
||||
constexpr uint32_t CARD_TIMAEUS = 1784686;
|
||||
constexpr uint32_t CARD_CRITIAS = 11082056;
|
||||
constexpr uint32_t CARD_HERMOS = 46232525;
|
||||
|
||||
const std::unordered_map<uint32_t, uint32_t> second_code = {
|
||||
{CARD_MARINE_DOLPHIN, 17955766u},
|
||||
{CARD_TWINKLE_MOSS, 17732278u},
|
||||
{CARD_TIMAEUS, 10000050u},
|
||||
{CARD_CRITIAS, 10000060u},
|
||||
{CARD_HERMOS, 10000070u},
|
||||
};
|
||||
|
||||
inline bool check_setcode(uint16_t setcode, uint32_t value) {
|
||||
const uint32_t settype = value & 0x0fffU;
|
||||
const uint32_t setsubtype = value & 0xf000U;
|
||||
return setcode && (setcode & 0x0fffU) == settype && (setcode & setsubtype) == setsubtype;
|
||||
}
|
||||
|
||||
inline void write_setcode(uint16_t list[], uint64_t value) {
|
||||
if (!list)
|
||||
return;
|
||||
int len = 0;
|
||||
while (value) {
|
||||
if (value & 0xffff) {
|
||||
list[len] = value & 0xffff;
|
||||
++len;
|
||||
}
|
||||
value >>= 16;
|
||||
}
|
||||
if (len < SIZE_SETCODE)
|
||||
std::memset(list + len, 0, (SIZE_SETCODE - len) * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
struct card_data {
|
||||
uint32_t code{};
|
||||
uint32_t alias{};
|
||||
uint16_t setcode[SIZE_SETCODE]{};
|
||||
uint32_t type{};
|
||||
uint32_t level{};
|
||||
uint32_t attribute{};
|
||||
uint32_t race{};
|
||||
int32_t attack{};
|
||||
int32_t defense{};
|
||||
uint32_t lscale{};
|
||||
uint32_t rscale{};
|
||||
uint32_t link_marker{};
|
||||
uint32_t rule_code{};
|
||||
|
||||
void clear() {
|
||||
std::memset(this, 0, sizeof(card_data));
|
||||
}
|
||||
|
||||
bool is_setcode(uint32_t value) const {
|
||||
for (auto& x : setcode) {
|
||||
if (!x)
|
||||
return false;
|
||||
if (check_setcode(x, value))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the printed code on card
|
||||
uint32_t get_original_code() const {
|
||||
return alias ? alias : code;
|
||||
}
|
||||
|
||||
// get the code used in duel
|
||||
uint32_t get_duel_code() const {
|
||||
return rule_code ? rule_code : get_original_code();
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(card_data) == 80, "card_data size error");
|
||||
#endif /* CARD_DATA_H_ */
|
||||
+485
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* common.h
|
||||
*
|
||||
* Created on: 2009-1-7
|
||||
* Author: Argon.Sun
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H_
|
||||
#define COMMON_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
typedef unsigned char byte;
|
||||
|
||||
inline bool check_playerid(int32_t playerid) {
|
||||
return playerid >= 0 && playerid <= 1;
|
||||
}
|
||||
|
||||
enum LuaParamType : int32_t {
|
||||
PARAM_TYPE_INT = 0x01,
|
||||
PARAM_TYPE_STRING = 0x02,
|
||||
PARAM_TYPE_CARD = 0x04,
|
||||
PARAM_TYPE_GROUP = 0x08,
|
||||
PARAM_TYPE_EFFECT = 0x10,
|
||||
PARAM_TYPE_FUNCTION = 0x20,
|
||||
PARAM_TYPE_BOOLEAN = 0x40,
|
||||
PARAM_TYPE_INDEX = 0x80,
|
||||
};
|
||||
|
||||
#define MATCH_ALL(x,y) (((x)&(y))==(y))
|
||||
#define MATCH_ANY(x,y) ((x)&(y))
|
||||
#define ADD_BIT(x,y) ((x)|=(y))
|
||||
#define REMOVE_BIT(x,y) ((x)&=~(y))
|
||||
|
||||
#define OPERATION_SUCCESS 1
|
||||
#define OPERATION_FAIL 0
|
||||
#define OPERATION_CANCELED -1
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define SIZE_MESSAGE_BUFFER 0x2000u
|
||||
#define SIZE_RETURN_VALUE 256u
|
||||
#define SIZE_AI_NAME 128u
|
||||
#define SIZE_HINT_MSG 1024u
|
||||
|
||||
#define PROCESSOR_BUFFER_LEN 0x0fffffff
|
||||
#define PROCESSOR_FLAG 0xf0000000
|
||||
#define PROCESSOR_NONE 0
|
||||
#define PROCESSOR_WAITING 0x10000000
|
||||
#define PROCESSOR_END 0x20000000
|
||||
|
||||
#define MASTER_RULE3 3 //Master Rule 3 (2014)
|
||||
#define NEW_MASTER_RULE 4 //New Master Rule (2017)
|
||||
#define MASTER_RULE_2020 5 //Master Rule 2020
|
||||
#define CURRENT_RULE 5
|
||||
|
||||
// Duel creation flags
|
||||
#define OCGCORE_CREATE_ENABLE_LUA_COVERAGE 0x00000001u
|
||||
|
||||
//Locations
|
||||
#define LOCATION_DECK 0x01U
|
||||
#define LOCATION_HAND 0x02U
|
||||
#define LOCATION_MZONE 0x04U
|
||||
#define LOCATION_SZONE 0x08U
|
||||
#define LOCATION_GRAVE 0x10U
|
||||
#define LOCATION_REMOVED 0x20U
|
||||
#define LOCATION_EXTRA 0x40U
|
||||
#define LOCATION_OVERLAY 0x80U
|
||||
#define LOCATION_ONFIELD (LOCATION_MZONE | LOCATION_SZONE)
|
||||
#define LOCATION_FZONE 0x100U
|
||||
#define LOCATION_PZONE 0x200U
|
||||
//For redirect
|
||||
#define LOCATION_DECKBOT 0x10001 //Return to deck bottom
|
||||
#define LOCATION_DECKSHF 0x20001 //Return to deck and shuffle
|
||||
//For Duel.SendtoDeck
|
||||
#define SEQ_DECKTOP 0 //Return to deck top
|
||||
#define SEQ_DECKBOTTOM 1 //Return to deck bottom
|
||||
#define SEQ_DECKSHUFFLE 2 //Return to deck and shuffle
|
||||
|
||||
//Positions
|
||||
#define POS_FACEUP_ATTACK 0x1
|
||||
#define POS_FACEDOWN_ATTACK 0x2
|
||||
#define POS_FACEUP_DEFENSE 0x4
|
||||
#define POS_FACEDOWN_DEFENSE 0x8
|
||||
#define POS_FACEUP 0x5
|
||||
#define POS_FACEDOWN 0xa
|
||||
#define POS_ATTACK 0x3
|
||||
#define POS_DEFENSE 0xc
|
||||
#define POS_REVEAL 0x80
|
||||
//Flip effect flags
|
||||
#define NO_FLIP_EFFECT 0x10000
|
||||
|
||||
//Move to field flags
|
||||
#define RETURN_TEMP_REMOVE_TO_FIELD 1
|
||||
#define RETURN_TRAP_MONSTER_TO_SZONE 2
|
||||
|
||||
//Types
|
||||
#define TYPE_MONSTER 0x1 //
|
||||
#define TYPE_SPELL 0x2 //
|
||||
#define TYPE_TRAP 0x4 //
|
||||
#define TYPE_NORMAL 0x10 //
|
||||
#define TYPE_EFFECT 0x20 //
|
||||
#define TYPE_FUSION 0x40 //
|
||||
#define TYPE_RITUAL 0x80 //
|
||||
#define TYPE_TRAPMONSTER 0x100 //
|
||||
#define TYPE_SPIRIT 0x200 //
|
||||
#define TYPE_UNION 0x400 //
|
||||
#define TYPE_DUAL 0x800 //
|
||||
#define TYPE_TUNER 0x1000 //
|
||||
#define TYPE_SYNCHRO 0x2000 //
|
||||
#define TYPE_TOKEN 0x4000 //
|
||||
#define TYPE_QUICKPLAY 0x10000 //
|
||||
#define TYPE_CONTINUOUS 0x20000 //
|
||||
#define TYPE_EQUIP 0x40000 //
|
||||
#define TYPE_FIELD 0x80000 //
|
||||
#define TYPE_COUNTER 0x100000 //
|
||||
#define TYPE_FLIP 0x200000 //
|
||||
#define TYPE_TOON 0x400000 //
|
||||
#define TYPE_XYZ 0x800000 //
|
||||
#define TYPE_PENDULUM 0x1000000 //
|
||||
#define TYPE_SPSUMMON 0x2000000 //
|
||||
#define TYPE_LINK 0x4000000 //
|
||||
|
||||
//[YGOL] Reserved setcode: "this Token is allowed to exist face-down".
|
||||
// The OCG rule is that a Token is never face-down; the core hard-codes that in
|
||||
// card::get_spsummonable_position and card::is_removeable. Rather than lift the rule
|
||||
// for every Token, a Token opts in by carrying this setcode on its cdb row.
|
||||
// A setcode is the ONLY carrier that works: field::is_player_can_spsummon_monster
|
||||
// probes a scratch temp_card built from card_data alone (no script, no registered
|
||||
// effects), so an effect-based opt-in is invisible to the legality check and the card
|
||||
// ends up unactivatable. A correctly typed Token is also TYPE_NORMAL, and
|
||||
// interpreter::is_load_script skips Normal monsters, so a Token cannot register
|
||||
// anything from its own Lua either.
|
||||
// card_data::is_setcode matches on the low 12 bits, so this permanently burns
|
||||
// archetype id 0xFDF -- never reuse it for a real archetype.
|
||||
// First user: "WANTED! Rushing Roulette" (810000327) and its two Tokens.
|
||||
#define SETCODE_FACEDOWN_TOKEN 0xFDF
|
||||
|
||||
#define TYPES_EXTRA_DECK (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)
|
||||
|
||||
//Attributes
|
||||
#define ATTRIBUTES_COUNT 7
|
||||
#define ATTRIBUTE_ALL 0x7f //
|
||||
#define ATTRIBUTE_EARTH 0x01 //
|
||||
#define ATTRIBUTE_WATER 0x02 //
|
||||
#define ATTRIBUTE_FIRE 0x04 //
|
||||
#define ATTRIBUTE_WIND 0x08 //
|
||||
#define ATTRIBUTE_LIGHT 0x10 //
|
||||
#define ATTRIBUTE_DARK 0x20 //
|
||||
#define ATTRIBUTE_DEVINE 0x40 //
|
||||
|
||||
//Races
|
||||
#define RACES_COUNT 26
|
||||
#define RACE_ALL 0x3ffffff
|
||||
#define RACE_WARRIOR 0x1 //
|
||||
#define RACE_SPELLCASTER 0x2 //
|
||||
#define RACE_FAIRY 0x4 //
|
||||
#define RACE_FIEND 0x8 //
|
||||
#define RACE_ZOMBIE 0x10 //
|
||||
#define RACE_MACHINE 0x20 //
|
||||
#define RACE_AQUA 0x40 //
|
||||
#define RACE_PYRO 0x80 //
|
||||
#define RACE_ROCK 0x100 //
|
||||
#define RACE_WINDBEAST 0x200 //
|
||||
#define RACE_PLANT 0x400 //
|
||||
#define RACE_INSECT 0x800 //
|
||||
#define RACE_THUNDER 0x1000 //
|
||||
#define RACE_DRAGON 0x2000 //
|
||||
#define RACE_BEAST 0x4000 //
|
||||
#define RACE_BEASTWARRIOR 0x8000 //
|
||||
#define RACE_DINOSAUR 0x10000 //
|
||||
#define RACE_FISH 0x20000 //
|
||||
#define RACE_SEASERPENT 0x40000 //
|
||||
#define RACE_REPTILE 0x80000 //
|
||||
#define RACE_PSYCHO 0x100000 //
|
||||
#define RACE_DEVINE 0x200000 //
|
||||
#define RACE_CREATORGOD 0x400000 //
|
||||
#define RACE_WYRM 0x800000 //
|
||||
#define RACE_CYBERSE 0x1000000 //
|
||||
#define RACE_ILLUSION 0x2000000 //
|
||||
|
||||
//Reason
|
||||
#define REASON_DESTROY 0x1 //
|
||||
#define REASON_RELEASE 0x2 //
|
||||
#define REASON_TEMPORARY 0x4 //
|
||||
#define REASON_MATERIAL 0x8 //
|
||||
#define REASON_SUMMON 0x10 //
|
||||
#define REASON_BATTLE 0x20 //
|
||||
#define REASON_EFFECT 0x40 //
|
||||
#define REASON_COST 0x80 //
|
||||
#define REASON_ADJUST 0x100 //
|
||||
#define REASON_LOST_TARGET 0x200 //
|
||||
#define REASON_RULE 0x400 //
|
||||
#define REASON_SPSUMMON 0x800 //
|
||||
#define REASON_DISSUMMON 0x1000 //
|
||||
#define REASON_FLIP 0x2000 //
|
||||
#define REASON_DISCARD 0x4000 //
|
||||
#define REASON_RDAMAGE 0x8000 //
|
||||
#define REASON_RRECOVER 0x10000 //
|
||||
#define REASON_RETURN 0x20000 //
|
||||
#define REASON_FUSION 0x40000 //
|
||||
#define REASON_SYNCHRO 0x80000 //
|
||||
#define REASON_RITUAL 0x100000 //
|
||||
#define REASON_XYZ 0x200000 //
|
||||
#define REASON_REPLACE 0x1000000 //
|
||||
#define REASON_DRAW 0x2000000 //
|
||||
#define REASON_REDIRECT 0x4000000 //
|
||||
#define REASON_REVEAL 0x8000000 //
|
||||
#define REASON_LINK 0x10000000 //
|
||||
#define REASON_LOST_OVERLAY 0x20000000 //
|
||||
#define REASON_MAINTENANCE 0x40000000 //
|
||||
#define REASON_ACTION 0x80000000 //
|
||||
|
||||
#define REASONS_PROCEDURE (REASON_SYNCHRO | REASON_XYZ | REASON_LINK)
|
||||
|
||||
//Status
|
||||
#define STATUS_DISABLED 0x0001
|
||||
#define STATUS_TO_ENABLE 0x0002
|
||||
#define STATUS_TO_DISABLE 0x0004
|
||||
#define STATUS_PROC_COMPLETE 0x0008
|
||||
#define STATUS_SET_TURN 0x0010
|
||||
#define STATUS_NO_LEVEL 0x0020
|
||||
#define STATUS_BATTLE_RESULT 0x0040
|
||||
#define STATUS_SPSUMMON_STEP 0x0080
|
||||
#define STATUS_CANNOT_CHANGE_FORM 0x0100
|
||||
#define STATUS_SUMMONING 0x0200
|
||||
#define STATUS_EFFECT_ENABLED 0x0400
|
||||
#define STATUS_SUMMON_TURN 0x0800
|
||||
#define STATUS_DESTROY_CONFIRMED 0x1000
|
||||
#define STATUS_LEAVE_CONFIRMED 0x2000
|
||||
#define STATUS_BATTLE_DESTROYED 0x4000
|
||||
#define STATUS_COPYING_EFFECT 0x8000
|
||||
#define STATUS_CHAINING 0x10000
|
||||
#define STATUS_SUMMON_DISABLED 0x20000
|
||||
#define STATUS_ACTIVATE_DISABLED 0x40000
|
||||
#define STATUS_EFFECT_REPLACED 0x80000
|
||||
#define STATUS_FLIP_SUMMONING 0x100000
|
||||
#define STATUS_ATTACK_CANCELED 0x200000
|
||||
#define STATUS_INITIALIZING 0x400000
|
||||
#define STATUS_TO_HAND_WITHOUT_CONFIRM 0x800000
|
||||
#define STATUS_JUST_POS 0x1000000
|
||||
#define STATUS_CONTINUOUS_POS 0x2000000
|
||||
#define STATUS_FORBIDDEN 0x4000000
|
||||
#define STATUS_ACT_FROM_HAND 0x8000000
|
||||
#define STATUS_OPPO_BATTLE 0x10000000
|
||||
#define STATUS_FLIP_SUMMON_TURN 0x20000000
|
||||
#define STATUS_SPSUMMON_TURN 0x40000000
|
||||
#define STATUS_FLIP_SUMMON_DISABLED 0x80000000
|
||||
|
||||
//Query list
|
||||
#define QUERY_CODE 0x1
|
||||
#define QUERY_POSITION 0x2
|
||||
#define QUERY_ALIAS 0x4
|
||||
#define QUERY_TYPE 0x8
|
||||
#define QUERY_LEVEL 0x10
|
||||
#define QUERY_RANK 0x20
|
||||
#define QUERY_ATTRIBUTE 0x40
|
||||
#define QUERY_RACE 0x80
|
||||
#define QUERY_ATTACK 0x100
|
||||
#define QUERY_DEFENSE 0x200
|
||||
#define QUERY_BASE_ATTACK 0x400
|
||||
#define QUERY_BASE_DEFENSE 0x800
|
||||
#define QUERY_REASON 0x1000
|
||||
#define QUERY_REASON_CARD 0x2000
|
||||
#define QUERY_EQUIP_CARD 0x4000
|
||||
#define QUERY_TARGET_CARD 0x8000
|
||||
#define QUERY_OVERLAY_CARD 0x10000
|
||||
#define QUERY_COUNTERS 0x20000
|
||||
#define QUERY_OWNER 0x40000
|
||||
#define QUERY_STATUS 0x80000
|
||||
#define QUERY_LSCALE 0x200000
|
||||
#define QUERY_RSCALE 0x400000
|
||||
#define QUERY_LINK 0x800000
|
||||
|
||||
//Link markers
|
||||
#define LINK_MARKER_BOTTOM_LEFT 0x001
|
||||
#define LINK_MARKER_BOTTOM 0x002
|
||||
#define LINK_MARKER_BOTTOM_RIGHT 0x004
|
||||
#define LINK_MARKER_LEFT 0x008
|
||||
#define LINK_MARKER_RIGHT 0x020
|
||||
#define LINK_MARKER_TOP_LEFT 0x040
|
||||
#define LINK_MARKER_TOP 0x080
|
||||
#define LINK_MARKER_TOP_RIGHT 0x100
|
||||
|
||||
//Messages
|
||||
#define MSG_RETRY 1
|
||||
#define MSG_HINT 2
|
||||
//#define MSG_WAITING 3
|
||||
//#define MSG_START 4
|
||||
#define MSG_WIN 5
|
||||
//#define MSG_UPDATE_DATA 6
|
||||
#define MSG_UPDATE_CARD 7
|
||||
//#define MSG_REQUEST_DECK 8
|
||||
#define MSG_SELECT_BATTLECMD 10
|
||||
#define MSG_SELECT_IDLECMD 11
|
||||
#define MSG_SELECT_EFFECTYN 12
|
||||
#define MSG_SELECT_YESNO 13
|
||||
#define MSG_SELECT_OPTION 14
|
||||
#define MSG_SELECT_CARD 15
|
||||
#define MSG_SELECT_CHAIN 16
|
||||
#define MSG_SELECT_PLACE 18
|
||||
#define MSG_SELECT_POSITION 19
|
||||
#define MSG_SELECT_TRIBUTE 20
|
||||
#define MSG_SELECT_COUNTER 22
|
||||
#define MSG_SELECT_SUM 23
|
||||
#define MSG_SELECT_DISFIELD 24
|
||||
#define MSG_SORT_CARD 25
|
||||
#define MSG_SELECT_UNSELECT_CARD 26
|
||||
#define MSG_CONFIRM_DECKTOP 30
|
||||
#define MSG_CONFIRM_CARDS 31
|
||||
#define MSG_SHUFFLE_DECK 32
|
||||
#define MSG_SHUFFLE_HAND 33
|
||||
//#define MSG_REFRESH_DECK 34
|
||||
#define MSG_SWAP_GRAVE_DECK 35
|
||||
#define MSG_SHUFFLE_SET_CARD 36
|
||||
#define MSG_REVERSE_DECK 37
|
||||
#define MSG_DECK_TOP 38
|
||||
#define MSG_SHUFFLE_EXTRA 39
|
||||
#define MSG_NEW_TURN 40
|
||||
#define MSG_NEW_PHASE 41
|
||||
#define MSG_CONFIRM_EXTRATOP 42
|
||||
#define MSG_MOVE 50
|
||||
#define MSG_POS_CHANGE 53
|
||||
#define MSG_SET 54
|
||||
#define MSG_SWAP 55
|
||||
#define MSG_FIELD_DISABLED 56
|
||||
#define MSG_SUMMONING 60
|
||||
#define MSG_SUMMONED 61
|
||||
#define MSG_SPSUMMONING 62
|
||||
#define MSG_SPSUMMONED 63
|
||||
#define MSG_FLIPSUMMONING 64
|
||||
#define MSG_FLIPSUMMONED 65
|
||||
#define MSG_CHAINING 70
|
||||
#define MSG_CHAINED 71
|
||||
#define MSG_CHAIN_SOLVING 72
|
||||
#define MSG_CHAIN_SOLVED 73
|
||||
#define MSG_CHAIN_END 74
|
||||
#define MSG_CHAIN_NEGATED 75
|
||||
#define MSG_CHAIN_DISABLED 76
|
||||
//#define MSG_CARD_SELECTED 80
|
||||
#define MSG_RANDOM_SELECTED 81
|
||||
#define MSG_BECOME_TARGET 83
|
||||
#define MSG_DRAW 90
|
||||
#define MSG_DAMAGE 91
|
||||
#define MSG_RECOVER 92
|
||||
#define MSG_EQUIP 93
|
||||
#define MSG_LPUPDATE 94
|
||||
//#define MSG_UNEQUIP 95
|
||||
#define MSG_CARD_TARGET 96
|
||||
#define MSG_CANCEL_TARGET 97
|
||||
#define MSG_PAY_LPCOST 100
|
||||
#define MSG_ADD_COUNTER 101
|
||||
#define MSG_REMOVE_COUNTER 102
|
||||
#define MSG_ATTACK 110
|
||||
#define MSG_BATTLE 111
|
||||
#define MSG_ATTACK_DISABLED 112
|
||||
#define MSG_DAMAGE_STEP_START 113
|
||||
#define MSG_DAMAGE_STEP_END 114
|
||||
#define MSG_MISSED_EFFECT 120
|
||||
//#define MSG_BE_CHAIN_TARGET 121
|
||||
//#define MSG_CREATE_RELATION 122
|
||||
//#define MSG_RELEASE_RELATION 123
|
||||
#define MSG_TOSS_COIN 130
|
||||
#define MSG_TOSS_DICE 131
|
||||
#define MSG_ROCK_PAPER_SCISSORS 132
|
||||
#define MSG_HAND_RES 133
|
||||
#define MSG_ANNOUNCE_RACE 140
|
||||
#define MSG_ANNOUNCE_ATTRIB 141
|
||||
#define MSG_ANNOUNCE_CARD 142
|
||||
#define MSG_ANNOUNCE_NUMBER 143
|
||||
#define MSG_CARD_HINT 160
|
||||
#define MSG_TAG_SWAP 161
|
||||
#define MSG_RELOAD_FIELD 162 // Debug.ReloadFieldEnd() or query_field_info()
|
||||
#define MSG_AI_NAME 163 // Debug.AIName()
|
||||
#define MSG_SHOW_HINT 164 // Debug.ShowHint()
|
||||
#define MSG_PLAYER_HINT 165
|
||||
#define MSG_MATCH_KILL 170
|
||||
#define MSG_CUSTOM_MSG 180
|
||||
|
||||
#define MSG_RESET_TIME 221
|
||||
|
||||
//Hints
|
||||
#define HINT_EVENT 1
|
||||
#define HINT_MESSAGE 2
|
||||
#define HINT_SELECTMSG 3
|
||||
#define HINT_OPSELECTED 4
|
||||
#define HINT_EFFECT 5
|
||||
#define HINT_RACE 6
|
||||
#define HINT_ATTRIB 7
|
||||
#define HINT_CODE 8
|
||||
#define HINT_NUMBER 9
|
||||
#define HINT_CARD 10
|
||||
#define HINT_ZONE 11
|
||||
//custom hints in KoishiPro for custom sound
|
||||
#define HINT_MUSIC 21
|
||||
#define HINT_SOUND 22
|
||||
#define HINT_MUSIC_OGG 23
|
||||
//
|
||||
#define CHINT_TURN 1
|
||||
#define CHINT_CARD 2
|
||||
#define CHINT_RACE 3
|
||||
#define CHINT_ATTRIBUTE 4
|
||||
#define CHINT_NUMBER 5
|
||||
#define CHINT_DESC_ADD 6
|
||||
#define CHINT_DESC_REMOVE 7
|
||||
//
|
||||
#define PHINT_DESC_ADD 6
|
||||
#define PHINT_DESC_REMOVE 7
|
||||
//
|
||||
#define EDESC_OPERATION 1
|
||||
#define EDESC_RESET 2
|
||||
|
||||
//
|
||||
#define OPCODE_ADD 0x40000000
|
||||
#define OPCODE_SUB 0x40000001
|
||||
#define OPCODE_MUL 0x40000002
|
||||
#define OPCODE_DIV 0x40000003
|
||||
#define OPCODE_AND 0x40000004
|
||||
#define OPCODE_OR 0x40000005
|
||||
#define OPCODE_NEG 0x40000006
|
||||
#define OPCODE_NOT 0x40000007
|
||||
#define OPCODE_ISCODE 0x40000100
|
||||
#define OPCODE_ISSETCARD 0x40000101
|
||||
#define OPCODE_ISTYPE 0x40000102
|
||||
#define OPCODE_ISRACE 0x40000103
|
||||
#define OPCODE_ISATTRIBUTE 0x40000104
|
||||
|
||||
//Player
|
||||
#define PLAYER_NONE 2 //
|
||||
#define PLAYER_ALL 3 //
|
||||
#define PLAYER_SELFDES 5 //
|
||||
|
||||
//Phase
|
||||
#define PHASE_DRAW 0x01
|
||||
#define PHASE_STANDBY 0x02
|
||||
#define PHASE_MAIN1 0x04
|
||||
#define PHASE_BATTLE_START 0x08
|
||||
#define PHASE_BATTLE_STEP 0x10
|
||||
#define PHASE_DAMAGE 0x20
|
||||
#define PHASE_DAMAGE_CAL 0x40
|
||||
#define PHASE_BATTLE 0x80
|
||||
#define PHASE_MAIN2 0x100
|
||||
#define PHASE_END 0x200
|
||||
|
||||
//Options
|
||||
#define DUEL_TEST_MODE 0x01
|
||||
#define DUEL_ATTACK_FIRST_TURN 0x02
|
||||
//#define DUEL_OLD_REPLAY 0x04
|
||||
#define DUEL_OBSOLETE_RULING 0x08
|
||||
#define DUEL_PSEUDO_SHUFFLE 0x10
|
||||
#define DUEL_TAG_MODE 0x20
|
||||
#define DUEL_SIMPLE_AI 0x40
|
||||
#define DUEL_RETURN_DECK_TOP 0x80
|
||||
#define DUEL_REVEAL_DECK_SEQ 0x100
|
||||
|
||||
//Activity
|
||||
#define ACTIVITY_SUMMON 1
|
||||
#define ACTIVITY_NORMALSUMMON 2
|
||||
#define ACTIVITY_SPSUMMON 3
|
||||
#define ACTIVITY_FLIPSUMMON 4
|
||||
#define ACTIVITY_ATTACK 5
|
||||
#define ACTIVITY_BATTLE_PHASE 6
|
||||
#define ACTIVITY_CHAIN 7
|
||||
//card datas for Duel.ReadCard / Card.SetCardData, arranged by database format
|
||||
#define CARDDATA_CODE 1
|
||||
#define CARDDATA_ALIAS 2
|
||||
#define CARDDATA_SETCODE 3
|
||||
#define CARDDATA_TYPE 4
|
||||
#define CARDDATA_LEVEL 5
|
||||
#define CARDDATA_ATTRIBUTE 6
|
||||
#define CARDDATA_RACE 7
|
||||
#define CARDDATA_ATTACK 8
|
||||
#define CARDDATA_DEFENSE 9
|
||||
#define CARDDATA_LSCALE 10
|
||||
#define CARDDATA_RSCALE 11
|
||||
#define CARDDATA_LINK_MARKER 12
|
||||
|
||||
//get effects for Card.GetCardRegistered
|
||||
#define GETEFFECT_INITIAL 0x1
|
||||
#define GETEFFECT_GAIN 0x2
|
||||
#define GETEFFECT_COPY 0x4
|
||||
#define GETEFFECT_GRANT 0x8
|
||||
#define GETEFFECT_ALL 0xf
|
||||
|
||||
#endif /* COMMON_H_ */
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* duel.cpp
|
||||
*
|
||||
* Created on: 2010-5-2
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include "duel.h"
|
||||
#include "interpreter.h"
|
||||
#include "field.h"
|
||||
#include "card.h"
|
||||
#include "effect.h"
|
||||
#include "group.h"
|
||||
#include "ocgapi.h"
|
||||
#include "buffer.h"
|
||||
|
||||
duel::duel(uint32_t create_flags) {
|
||||
lua = new interpreter(this, false, create_flags);
|
||||
game_field = new field(this);
|
||||
game_field->temp_card = new_card(TEMP_CARD_ID);
|
||||
game_field->rose_card = 0;
|
||||
game_field->rose_level = 0;
|
||||
message_buffer.reserve(SIZE_MESSAGE_BUFFER);
|
||||
#ifdef _WIN32
|
||||
_set_error_mode(_OUT_TO_MSGBOX);
|
||||
#endif // _WIN32
|
||||
}
|
||||
duel::~duel() {
|
||||
for(auto& pcard : cards)
|
||||
delete pcard;
|
||||
for(auto& pgroup : groups)
|
||||
delete pgroup;
|
||||
for(auto& peffect : effects)
|
||||
delete peffect;
|
||||
delete game_field;
|
||||
delete lua;
|
||||
}
|
||||
void duel::clear() {
|
||||
for(auto& pcard : cards) {
|
||||
lua->unregister_card(pcard);
|
||||
delete pcard;
|
||||
}
|
||||
for(auto& pgroup : groups) {
|
||||
lua->unregister_group(pgroup);
|
||||
delete pgroup;
|
||||
}
|
||||
for(auto& peffect : effects) {
|
||||
lua->unregister_effect(peffect);
|
||||
delete peffect;
|
||||
}
|
||||
delete game_field;
|
||||
cards.clear();
|
||||
groups.clear();
|
||||
effects.clear();
|
||||
assumes.clear();
|
||||
sgroups.clear();
|
||||
uncopy.clear();
|
||||
game_field = new field(this);
|
||||
game_field->temp_card = new_card(TEMP_CARD_ID);
|
||||
game_field->rose_card = 0;
|
||||
game_field->rose_level = 0;
|
||||
}
|
||||
card* duel::new_card(uint32_t code) {
|
||||
card* pcard = new card(this);
|
||||
cards.insert(pcard);
|
||||
if (code != TEMP_CARD_ID)
|
||||
::read_card(code, &(pcard->data));
|
||||
pcard->data.code = code;
|
||||
lua->register_card(pcard);
|
||||
return pcard;
|
||||
}
|
||||
group* duel::register_group(group* pgroup) {
|
||||
groups.insert(pgroup);
|
||||
if(lua->call_depth)
|
||||
sgroups.insert(pgroup);
|
||||
lua->register_group(pgroup);
|
||||
return pgroup;
|
||||
}
|
||||
group* duel::new_group() {
|
||||
group* pgroup = new group(this);
|
||||
return register_group(pgroup);
|
||||
}
|
||||
group* duel::new_group(card* pcard) {
|
||||
group* pgroup = new group(this, pcard);
|
||||
return register_group(pgroup);
|
||||
}
|
||||
group* duel::new_group(const card_set& cset) {
|
||||
group* pgroup = new group(this, cset);
|
||||
return register_group(pgroup);
|
||||
}
|
||||
effect* duel::new_effect() {
|
||||
effect* peffect = new effect(this);
|
||||
effects.insert(peffect);
|
||||
lua->register_effect(peffect);
|
||||
return peffect;
|
||||
}
|
||||
void duel::delete_card(card* pcard) {
|
||||
lua->unregister_card(pcard);
|
||||
cards.erase(pcard);
|
||||
delete pcard;
|
||||
}
|
||||
void duel::delete_group(group* pgroup) {
|
||||
lua->unregister_group(pgroup);
|
||||
groups.erase(pgroup);
|
||||
sgroups.erase(pgroup);
|
||||
delete pgroup;
|
||||
}
|
||||
void duel::delete_effect(effect* peffect) {
|
||||
lua->unregister_effect(peffect);
|
||||
effects.erase(peffect);
|
||||
delete peffect;
|
||||
}
|
||||
int32_t duel::read_buffer(byte* buf) {
|
||||
auto size = buffer_size();
|
||||
if (size)
|
||||
std::memcpy(buf, message_buffer.data(), size);
|
||||
return (int32_t)size;
|
||||
}
|
||||
void duel::release_script_group() {
|
||||
for(auto& pgroup : sgroups) {
|
||||
if(pgroup->is_readonly == GTYPE_DEFAULT) {
|
||||
lua->unregister_group(pgroup);
|
||||
groups.erase(pgroup);
|
||||
delete pgroup;
|
||||
}
|
||||
}
|
||||
sgroups.clear();
|
||||
}
|
||||
void duel::restore_assumes() {
|
||||
for(auto& pcard : assumes)
|
||||
pcard->assume_type = 0;
|
||||
assumes.clear();
|
||||
}
|
||||
void duel::write_buffer(const void* data, size_t size) {
|
||||
vector_write_block(message_buffer, data, size);
|
||||
}
|
||||
void duel::write_buffer32(uint32_t value) {
|
||||
vector_write<uint32_t>(message_buffer, value);
|
||||
}
|
||||
void duel::write_buffer16(uint16_t value) {
|
||||
vector_write<uint16_t>(message_buffer, value);
|
||||
}
|
||||
void duel::write_buffer8(uint8_t value) {
|
||||
vector_write<unsigned char>(message_buffer, value);
|
||||
}
|
||||
void duel::clear_buffer() {
|
||||
message_buffer.clear();
|
||||
}
|
||||
void duel::set_responsei(int32_t resp) {
|
||||
game_field->returns.ivalue[0] = resp;
|
||||
}
|
||||
void duel::set_responseb(byte* resp) {
|
||||
std::memcpy(game_field->returns.bvalue, resp, SIZE_RETURN_VALUE);
|
||||
}
|
||||
int32_t duel::get_next_integer(int32_t l, int32_t h) {
|
||||
if (rng_version == 1)
|
||||
return random.get_random_integer_v1(l, h);
|
||||
return random.get_random_integer_v2(l, h);
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* duel.h
|
||||
*
|
||||
* Created on: 2010-4-8
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef DUEL_H_
|
||||
#define DUEL_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "sort.h"
|
||||
#include "mtrandom.h"
|
||||
#include "metadata.h"
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
class card;
|
||||
class group;
|
||||
class effect;
|
||||
class field;
|
||||
class interpreter;
|
||||
|
||||
using card_set = std::set<card*, card_sort>;
|
||||
|
||||
class duel {
|
||||
public:
|
||||
char strbuffer[256]{};
|
||||
int32_t rng_version{ 2 };
|
||||
interpreter* lua;
|
||||
field* game_field;
|
||||
mtrandom random;
|
||||
metadata meta;
|
||||
|
||||
std::vector<byte> message_buffer;
|
||||
std::unordered_set<card*> cards;
|
||||
std::unordered_set<card*> assumes;
|
||||
std::unordered_set<group*> groups;
|
||||
std::unordered_set<group*> sgroups;
|
||||
std::unordered_set<effect*> effects;
|
||||
std::unordered_set<effect*> uncopy;
|
||||
|
||||
std::unordered_map<std::string, std::string> registry;
|
||||
|
||||
explicit duel(uint32_t create_flags = 0);
|
||||
~duel();
|
||||
void clear();
|
||||
|
||||
uint32_t buffer_size() const {
|
||||
return (uint32_t)message_buffer.size() & PROCESSOR_BUFFER_LEN;
|
||||
}
|
||||
card* new_card(uint32_t code);
|
||||
group* new_group();
|
||||
group* new_group(card* pcard);
|
||||
group* new_group(const card_set& cset);
|
||||
effect* new_effect();
|
||||
void delete_card(card* pcard);
|
||||
void delete_group(group* pgroup);
|
||||
void delete_effect(effect* peffect);
|
||||
void release_script_group();
|
||||
void restore_assumes();
|
||||
int32_t read_buffer(byte* buf);
|
||||
void write_buffer(const void* data, size_t size);
|
||||
void write_buffer32(uint32_t value);
|
||||
void write_buffer16(uint16_t value);
|
||||
void write_buffer8(uint8_t value);
|
||||
void clear_buffer();
|
||||
void set_responsei(int32_t resp);
|
||||
void set_responseb(byte* resp);
|
||||
int32_t get_next_integer(int32_t l, int32_t h);
|
||||
private:
|
||||
group* register_group(group* pgroup);
|
||||
};
|
||||
|
||||
#endif /* DUEL_H_ */
|
||||
+891
@@ -0,0 +1,891 @@
|
||||
/*
|
||||
* effect.cpp
|
||||
*
|
||||
* Created on: 2010-5-7
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#include "effect.h"
|
||||
#include "card.h"
|
||||
#include "duel.h"
|
||||
#include "group.h"
|
||||
#include "interpreter.h"
|
||||
|
||||
bool effect_sort_id(const effect* e1, const effect* e2) {
|
||||
int32_t is_single1 = e1->is_initial_single();
|
||||
int32_t is_single2 = e2->is_initial_single();
|
||||
if (is_single1 != is_single2)
|
||||
return is_single1 > is_single2;
|
||||
return e1->id < e2->id;
|
||||
}
|
||||
// return: code is an event reserved for EFFECT_TYPE_CONTINUOUS or not
|
||||
bool is_continuous_event(uint32_t code) {
|
||||
if (code & EVENT_CUSTOM)
|
||||
return false;
|
||||
else if (code & 0xf0000) // EVENT_ADD_COUNTER, EVENT_REMOVE_COUNTER
|
||||
return false;
|
||||
else if (code & 0xf000) // EVENT_PHASE_START must be continuous, but other EVENT_PHASE must not be
|
||||
return !!(code & EVENT_PHASE_START);
|
||||
else
|
||||
return continuous_event.find(code) != continuous_event.end();
|
||||
}
|
||||
|
||||
effect::effect(duel* pd)
|
||||
: pduel(pd) {
|
||||
label.reserve(4);
|
||||
}
|
||||
int32_t effect::is_disable_related() const {
|
||||
if (code == EFFECT_IMMUNE_EFFECT || code == EFFECT_DISABLE || code == EFFECT_CANNOT_DISABLE || code == EFFECT_FORBIDDEN)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
int32_t effect::is_self_destroy_related() const {
|
||||
if(code == EFFECT_UNIQUE_CHECK || code == EFFECT_SELF_DESTROY || code == EFFECT_SELF_TOGRAVE)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
int32_t effect::is_can_be_forbidden() const {
|
||||
if (is_flag(EFFECT_FLAG_CANNOT_DISABLE) && !is_flag(EFFECT_FLAG_CANNOT_NEGATE))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
// check if a single/field/equip effect is available
|
||||
// check properties: range, EFFECT_FLAG_OWNER_RELATE, STATUS_BATTLE_DESTROYED, STATUS_EFFECT_ENABLED, disabled/forbidden
|
||||
// check fucntions: condition
|
||||
int32_t effect::is_available(int32_t neglect_disabled) {
|
||||
if (type & EFFECT_TYPE_ACTIONS)
|
||||
return FALSE;
|
||||
if ((type & (EFFECT_TYPE_SINGLE | EFFECT_TYPE_XMATERIAL)) && !(type & EFFECT_TYPE_FIELD)) {
|
||||
card* phandler = get_handler();
|
||||
card* powner = get_owner();
|
||||
if (phandler->current.controler == PLAYER_NONE)
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_SINGLE_RANGE) && !in_range(phandler))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_SINGLE_RANGE) && !phandler->get_status(STATUS_EFFECT_ENABLED) && !is_flag(EFFECT_FLAG_IMMEDIATELY_APPLY))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_SINGLE_RANGE) && (phandler->current.location & LOCATION_ONFIELD) && !phandler->is_position(POS_FACEUP))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && is_can_be_forbidden() && powner->is_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(powner == phandler && is_can_be_forbidden() && phandler->get_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && !(is_flag(EFFECT_FLAG_CANNOT_DISABLE) || neglect_disabled) && powner->is_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
if(powner == phandler && !(is_flag(EFFECT_FLAG_CANNOT_DISABLE) || neglect_disabled) && phandler->get_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
}
|
||||
if (type & EFFECT_TYPE_EQUIP) {
|
||||
if(handler->current.controler == PLAYER_NONE)
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && is_can_be_forbidden() && owner->is_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(owner == handler && is_can_be_forbidden() && handler->get_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && !(is_flag(EFFECT_FLAG_CANNOT_DISABLE) || neglect_disabled) && owner->is_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
if(owner == handler && !(is_flag(EFFECT_FLAG_CANNOT_DISABLE) || neglect_disabled) && handler->get_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
if(!is_flag(EFFECT_FLAG_SET_AVAILABLE)) {
|
||||
if(!(handler->get_status(STATUS_EFFECT_ENABLED)))
|
||||
return FALSE;
|
||||
if(!handler->is_position(POS_FACEUP))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if (type & (EFFECT_TYPE_FIELD | EFFECT_TYPE_TARGET)) {
|
||||
card* phandler = get_handler();
|
||||
card* powner = get_owner();
|
||||
if (!is_flag(EFFECT_FLAG_FIELD_ONLY)) {
|
||||
if(phandler->current.controler == PLAYER_NONE)
|
||||
return FALSE;
|
||||
if(!in_range(phandler))
|
||||
return FALSE;
|
||||
if(!phandler->get_status(STATUS_EFFECT_ENABLED) && !is_flag(EFFECT_FLAG_IMMEDIATELY_APPLY))
|
||||
return FALSE;
|
||||
if (phandler->current.is_location(LOCATION_ONFIELD) && !phandler->is_position(POS_FACEUP))
|
||||
return FALSE;
|
||||
if (phandler->current.is_stzone() && (phandler->data.type & (TYPE_SPELL | TYPE_TRAP)) && phandler->is_affected_by_effect(EFFECT_CHANGE_TYPE))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && is_can_be_forbidden() && powner->is_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(powner == phandler && is_can_be_forbidden() && phandler->get_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && !(is_flag(EFFECT_FLAG_CANNOT_DISABLE) || neglect_disabled) && powner->is_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
if(powner == phandler && !(is_flag(EFFECT_FLAG_CANNOT_DISABLE) || neglect_disabled) && phandler->get_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
if(phandler->is_status(STATUS_BATTLE_DESTROYED) && !is_flag(EFFECT_FLAG2_AVAILABLE_BD))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if (!condition)
|
||||
return TRUE;
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
int32_t res = pduel->lua->check_condition(condition, 1);
|
||||
if(res) {
|
||||
if(!(status & EFFECT_STATUS_AVAILABLE))
|
||||
id = pduel->game_field->infos.field_id++;
|
||||
status |= EFFECT_STATUS_AVAILABLE;
|
||||
} else
|
||||
status &= ~EFFECT_STATUS_AVAILABLE;
|
||||
return res;
|
||||
}
|
||||
// check if a count limit effect counter is available, which should be available even if the effect is disabled
|
||||
int32_t effect::limit_counter_is_available() {
|
||||
return is_available(TRUE);
|
||||
}
|
||||
// check if a effect is EFFECT_TYPE_SINGLE and is ready
|
||||
// check: range, enabled, condition
|
||||
int32_t effect::is_single_ready() {
|
||||
if(type & EFFECT_TYPE_ACTIONS)
|
||||
return FALSE;
|
||||
if((type & (EFFECT_TYPE_SINGLE | EFFECT_TYPE_XMATERIAL)) && !(type & EFFECT_TYPE_FIELD)) {
|
||||
card* phandler = get_handler();
|
||||
if(phandler->current.controler == PLAYER_NONE)
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_SINGLE_RANGE) && !in_range(phandler))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_SINGLE_RANGE) && !phandler->get_status(STATUS_EFFECT_ENABLED) && !is_flag(EFFECT_FLAG_IMMEDIATELY_APPLY))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_SINGLE_RANGE) && (phandler->current.location & LOCATION_ONFIELD) && !phandler->is_position(POS_FACEUP))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
if(!condition)
|
||||
return TRUE;
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
int32_t res = pduel->lua->check_condition(condition, 1);
|
||||
return res;
|
||||
}
|
||||
int32_t effect::check_count_limit(uint8_t playerid) {
|
||||
if(is_flag(EFFECT_FLAG_COUNT_LIMIT)) {
|
||||
if(count_limit == 0)
|
||||
return FALSE;
|
||||
if(count_code) {
|
||||
uint32_t limit_code = count_code & MAX_CARD_ID;
|
||||
uint32_t limit_type = count_code & 0xf0000000U;
|
||||
int32_t count = count_limit_max;
|
||||
if(limit_code == EFFECT_COUNT_CODE_SINGLE) {
|
||||
if(pduel->game_field->get_effect_code(limit_type | get_handler()->activate_count_id, PLAYER_NONE) >= count)
|
||||
return FALSE;
|
||||
} else {
|
||||
if(pduel->game_field->get_effect_code(count_code, playerid) >= count)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
// check activate in hand/in set turn
|
||||
int32_t effect::get_required_handorset_effects(effect_set* eset, uint8_t playerid, const tevent& e, int32_t neglect_loc) {
|
||||
eset->clear();
|
||||
if(!(type & EFFECT_TYPE_ACTIVATE))
|
||||
return 1;
|
||||
int32_t ecode = 0;
|
||||
if (handler->current.location == LOCATION_HAND && !neglect_loc)
|
||||
{
|
||||
if(handler->data.type & TYPE_TRAP)
|
||||
ecode = EFFECT_TRAP_ACT_IN_HAND;
|
||||
else if((handler->data.type & TYPE_SPELL) && pduel->game_field->infos.turn_player != playerid) {
|
||||
if(handler->data.type & TYPE_QUICKPLAY)
|
||||
ecode = EFFECT_QP_ACT_IN_NTPHAND;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else if((handler->data.type & TYPE_PENDULUM) && pduel->game_field->infos.turn_player != playerid && is_flag(EFFECT_FLAG2_SPOSITCH)) {
|
||||
ecode = EFFECT_QP_ACT_IN_NTPHAND;
|
||||
}
|
||||
}
|
||||
else if (handler->current.location == LOCATION_SZONE)
|
||||
{
|
||||
if((handler->data.type & TYPE_TRAP) && handler->get_status(STATUS_SET_TURN))
|
||||
ecode = EFFECT_TRAP_ACT_IN_SET_TURN;
|
||||
if((handler->data.type & TYPE_SPELL) && (handler->data.type & TYPE_QUICKPLAY) && handler->get_status(STATUS_SET_TURN))
|
||||
ecode = EFFECT_QP_ACT_IN_SET_TURN;
|
||||
}
|
||||
if (!ecode)
|
||||
return 1;
|
||||
int32_t available = 0;
|
||||
effect_set tmp_eset;
|
||||
handler->filter_effect(ecode, &tmp_eset);
|
||||
if(!tmp_eset.size())
|
||||
return available;
|
||||
effect* oreason = pduel->game_field->core.reason_effect;
|
||||
uint8_t op = pduel->game_field->core.reason_player;
|
||||
pduel->game_field->core.reason_player = playerid;
|
||||
pduel->game_field->save_lp_cost();
|
||||
for(effect_set::size_type i = 0; i < tmp_eset.size(); ++i) {
|
||||
auto peffect = tmp_eset[i];
|
||||
if(peffect->check_count_limit(playerid)) {
|
||||
pduel->game_field->core.reason_effect = peffect;
|
||||
pduel->lua->add_param(peffect, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_cards , PARAM_TYPE_GROUP);
|
||||
pduel->lua->add_param(e.event_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_value, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_effect , PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(e.reason, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(0, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
if(pduel->lua->check_condition(peffect->cost, 10)) {
|
||||
available = 2;
|
||||
eset->push_back(peffect);
|
||||
}
|
||||
}
|
||||
}
|
||||
pduel->game_field->core.reason_effect = oreason;
|
||||
pduel->game_field->core.reason_player = op;
|
||||
pduel->game_field->restore_lp_cost();
|
||||
return available;
|
||||
}
|
||||
// check if an EFFECT_TYPE_ACTIONS effect can be activated
|
||||
// for triggering effects, it checks EFFECT_FLAG_DAMAGE_STEP, EFFECT_FLAG_SET_AVAILABLE
|
||||
int32_t effect::is_activateable(uint8_t playerid, const tevent& e, int32_t neglect_cond, int32_t neglect_cost, int32_t neglect_target, int32_t neglect_loc, int32_t neglect_faceup) {
|
||||
if(!(type & EFFECT_TYPE_ACTIONS))
|
||||
return FALSE;
|
||||
if(!check_count_limit(playerid))
|
||||
return FALSE;
|
||||
if (!is_flag(EFFECT_FLAG_FIELD_ONLY)) {
|
||||
if (type & EFFECT_TYPE_ACTIVATE) {
|
||||
if(handler->current.controler != playerid)
|
||||
return FALSE;
|
||||
if(pduel->game_field->check_unique_onfield(handler, playerid, LOCATION_SZONE))
|
||||
return FALSE;
|
||||
if(!(handler->data.type & TYPE_COUNTER)) {
|
||||
if((code < 1132 || code > 1149) && pduel->game_field->infos.phase == PHASE_DAMAGE && !is_flag(EFFECT_FLAG_DAMAGE_STEP)
|
||||
&& !pduel->game_field->get_cteffect(this, playerid, FALSE))
|
||||
return FALSE;
|
||||
if((code < 1134 || code > 1136) && pduel->game_field->infos.phase == PHASE_DAMAGE_CAL && !is_flag(EFFECT_FLAG_DAMAGE_CAL)
|
||||
&& !pduel->game_field->get_cteffect(this, playerid, FALSE))
|
||||
return FALSE;
|
||||
}
|
||||
uint32_t zone = 0xff;
|
||||
if(!(handler->data.type & (TYPE_FIELD | TYPE_PENDULUM)) && is_flag(EFFECT_FLAG_LIMIT_ZONE)) {
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_cards , PARAM_TYPE_GROUP);
|
||||
pduel->lua->add_param(e.event_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_value, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_effect , PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(e.reason, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_player, PARAM_TYPE_INT);
|
||||
zone = get_value(7);
|
||||
if(!zone)
|
||||
zone = 0xff;
|
||||
}
|
||||
if(handler->current.location == LOCATION_SZONE) {
|
||||
if(handler->is_position(POS_FACEUP))
|
||||
return FALSE;
|
||||
if(handler->equiping_target)
|
||||
return FALSE;
|
||||
if(!(handler->data.type & (TYPE_FIELD | TYPE_PENDULUM)) && is_flag(EFFECT_FLAG_LIMIT_ZONE) && !(zone & (1u << handler->current.sequence)))
|
||||
return FALSE;
|
||||
} else {
|
||||
if((handler->data.type & TYPE_MONSTER) && !is_flag(EFFECT_FLAG2_ACTIVATE_MONSTER_SZONE)) {
|
||||
if(!(handler->data.type & TYPE_PENDULUM))
|
||||
return FALSE;
|
||||
if(!pduel->game_field->is_location_useable(playerid, LOCATION_PZONE, 0)
|
||||
&& !pduel->game_field->is_location_useable(playerid, LOCATION_PZONE, 1))
|
||||
return FALSE;
|
||||
} else if(!(handler->data.type & TYPE_FIELD)
|
||||
&& pduel->game_field->get_useable_count(handler, playerid, LOCATION_SZONE, playerid, LOCATION_REASON_TOFIELD, zone) <= 0)
|
||||
return FALSE;
|
||||
}
|
||||
// check activate in hand/in set turn
|
||||
effect_set eset;
|
||||
if(!get_required_handorset_effects(&eset, playerid, e, neglect_loc))
|
||||
return FALSE;
|
||||
if(handler->is_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(handler->is_affected_by_effect(EFFECT_CANNOT_TRIGGER))
|
||||
return FALSE;
|
||||
} else if(!(type & EFFECT_TYPE_CONTINUOUS)) {
|
||||
card* phandler = get_handler();
|
||||
if(!(phandler->get_type() & TYPE_MONSTER) && (get_active_type(FALSE) & TYPE_MONSTER))
|
||||
return FALSE;
|
||||
if((type & EFFECT_TYPE_QUICK_O) && is_flag(EFFECT_FLAG_DELAY) && !in_range(phandler))
|
||||
return FALSE;
|
||||
if(!neglect_faceup && (phandler->current.location & (LOCATION_ONFIELD | LOCATION_REMOVED))) {
|
||||
if(!phandler->is_position(POS_FACEUP) && !is_flag(EFFECT_FLAG_SET_AVAILABLE))
|
||||
return FALSE;
|
||||
if(phandler->is_position(POS_FACEUP) && !phandler->is_status(STATUS_EFFECT_ENABLED))
|
||||
return FALSE;
|
||||
}
|
||||
if(!(type & (EFFECT_TYPE_FLIP | EFFECT_TYPE_TRIGGER_F)) && !((type & EFFECT_TYPE_TRIGGER_O) && (type & EFFECT_TYPE_SINGLE))) {
|
||||
if((code < 1132 || code > 1149) && pduel->game_field->infos.phase == PHASE_DAMAGE && !is_flag(EFFECT_FLAG_DAMAGE_STEP))
|
||||
return FALSE;
|
||||
if((code < 1134 || code > 1136) && pduel->game_field->infos.phase == PHASE_DAMAGE_CAL && !is_flag(EFFECT_FLAG_DAMAGE_CAL))
|
||||
return FALSE;
|
||||
}
|
||||
if(phandler->current.location == LOCATION_OVERLAY)
|
||||
return FALSE;
|
||||
if(phandler->current.location == LOCATION_DECK
|
||||
|| pduel->game_field->core.duel_rule >= MASTER_RULE_2020 && phandler->current.location == LOCATION_EXTRA && (phandler->current.position & POS_FACEDOWN)) {
|
||||
if((type & EFFECT_TYPE_SINGLE) && code != EVENT_TO_DECK)
|
||||
return FALSE;
|
||||
if((type & EFFECT_TYPE_FIELD) && !(range & (LOCATION_DECK | LOCATION_EXTRA)))
|
||||
return FALSE;
|
||||
}
|
||||
if (phandler->current.is_stzone() && (phandler->data.type & (TYPE_SPELL|TYPE_TRAP)) && phandler->is_affected_by_effect(EFFECT_CHANGE_TYPE))
|
||||
return FALSE;
|
||||
if((type & EFFECT_TYPE_FIELD) && (phandler->current.controler != playerid) && !is_flag(EFFECT_FLAG_BOTH_SIDE | EFFECT_FLAG_EVENT_PLAYER))
|
||||
return FALSE;
|
||||
if(phandler->is_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(phandler->is_affected_by_effect(EFFECT_CANNOT_TRIGGER))
|
||||
return FALSE;
|
||||
} else {
|
||||
card* phandler = get_handler();
|
||||
if(!is_flag(EFFECT_FLAG2_AVAILABLE_BD) && (type & EFFECT_TYPE_FIELD) && phandler->is_status(STATUS_BATTLE_DESTROYED))
|
||||
return FALSE;
|
||||
if(((type & EFFECT_TYPE_FIELD) || ((type & EFFECT_TYPE_SINGLE) && is_flag(EFFECT_FLAG_SINGLE_RANGE)))
|
||||
&& (phandler->current.location & LOCATION_ONFIELD)
|
||||
&& (!phandler->is_position(POS_FACEUP) || !phandler->is_status(STATUS_EFFECT_ENABLED)))
|
||||
return FALSE;
|
||||
if((type & EFFECT_TYPE_SINGLE) && is_flag(EFFECT_FLAG_SINGLE_RANGE) && !in_range(phandler))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && is_can_be_forbidden() && owner->is_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(phandler == owner && is_can_be_forbidden() && phandler->is_status(STATUS_FORBIDDEN))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_OWNER_RELATE) && !is_flag(EFFECT_FLAG_CANNOT_DISABLE) && owner->is_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
if(phandler == owner && !is_flag(EFFECT_FLAG_CANNOT_DISABLE) && phandler->is_status(STATUS_DISABLED))
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if((get_owner_player() != playerid) && !is_flag(EFFECT_FLAG_BOTH_SIDE))
|
||||
return FALSE;
|
||||
}
|
||||
pduel->game_field->save_lp_cost();
|
||||
effect* oreason = pduel->game_field->core.reason_effect;
|
||||
uint8_t op = pduel->game_field->core.reason_player;
|
||||
pduel->game_field->core.reason_effect = this;
|
||||
pduel->game_field->core.reason_player = playerid;
|
||||
int32_t result = TRUE;
|
||||
if(!(type & EFFECT_TYPE_CONTINUOUS))
|
||||
result = is_action_check(playerid);
|
||||
if(result)
|
||||
result = is_activate_ready(playerid, e, neglect_cond, neglect_cost, neglect_target);
|
||||
pduel->game_field->core.reason_effect = oreason;
|
||||
pduel->game_field->core.reason_player = op;
|
||||
pduel->game_field->restore_lp_cost();
|
||||
return result;
|
||||
}
|
||||
// check functions: value of EFFECT_CANNOT_ACTIVATE, target, cost of EFFECT_ACTIVATE_COST
|
||||
int32_t effect::is_action_check(uint8_t playerid) {
|
||||
effect_set eset;
|
||||
pduel->game_field->filter_player_effect(playerid, EFFECT_CANNOT_ACTIVATE, &eset);
|
||||
for(effect_set::size_type i = 0; i < eset.size(); ++i) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
if(eset[i]->check_value_condition(2))
|
||||
return FALSE;
|
||||
}
|
||||
eset.clear();
|
||||
pduel->game_field->filter_player_effect(playerid, EFFECT_ACTIVATE_COST, &eset);
|
||||
for(effect_set::size_type i = 0; i < eset.size(); ++i) {
|
||||
pduel->lua->add_param(eset[i], PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(eset[i]->target, 3))
|
||||
continue;
|
||||
pduel->lua->add_param(eset[i], PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(eset[i]->cost, 3))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
// check functions: condition, cost(chk=0), target(chk=0)
|
||||
int32_t effect::is_activate_ready(effect* reason_effect, uint8_t playerid, const tevent& e, int32_t neglect_cond, int32_t neglect_cost, int32_t neglect_target) {
|
||||
if(!neglect_cond && condition) {
|
||||
pduel->lua->add_param(reason_effect, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_cards, PARAM_TYPE_GROUP);
|
||||
pduel->lua->add_param(e.event_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_value, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_effect, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(e.reason, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_player, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(condition, 8)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if(!neglect_cost && !(type & EFFECT_TYPE_CONTINUOUS)) {
|
||||
reason_effect->cost_checked = TRUE;
|
||||
if(cost) {
|
||||
pduel->lua->add_param(reason_effect, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_cards, PARAM_TYPE_GROUP);
|
||||
pduel->lua->add_param(e.event_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_value, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_effect, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(e.reason, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(0, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(cost, 9)) {
|
||||
reason_effect->cost_checked = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reason_effect->cost_checked = FALSE;
|
||||
}
|
||||
if(!neglect_target && target) {
|
||||
pduel->lua->add_param(reason_effect, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_cards, PARAM_TYPE_GROUP);
|
||||
pduel->lua->add_param(e.event_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_value, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_effect, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(e.reason, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(0, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(target, 9)) {
|
||||
reason_effect->cost_checked = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
reason_effect->cost_checked = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
int32_t effect::is_activate_ready(uint8_t playerid, const tevent& e, int32_t neglect_cond, int32_t neglect_cost, int32_t neglect_target) {
|
||||
return is_activate_ready(this, playerid, e, neglect_cond, neglect_cost, neglect_target);
|
||||
}
|
||||
// check functions: condition
|
||||
int32_t effect::is_condition_check(uint8_t playerid, const tevent& e) {
|
||||
card* phandler = get_handler();
|
||||
if(!(type & EFFECT_TYPE_ACTIVATE) && (phandler->current.location & (LOCATION_ONFIELD | LOCATION_REMOVED)) && !phandler->is_position(POS_FACEUP))
|
||||
return FALSE;
|
||||
if(!condition)
|
||||
return TRUE;
|
||||
effect* oreason = pduel->game_field->core.reason_effect;
|
||||
uint8_t op = pduel->game_field->core.reason_player;
|
||||
pduel->game_field->core.reason_effect = this;
|
||||
pduel->game_field->core.reason_player = playerid;
|
||||
pduel->game_field->save_lp_cost();
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(playerid, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_cards , PARAM_TYPE_GROUP);
|
||||
pduel->lua->add_param(e.event_player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.event_value, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_effect , PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(e.reason, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(e.reason_player, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(condition, 8)) {
|
||||
pduel->game_field->restore_lp_cost();
|
||||
pduel->game_field->core.reason_effect = oreason;
|
||||
pduel->game_field->core.reason_player = op;
|
||||
return FALSE;
|
||||
}
|
||||
pduel->game_field->restore_lp_cost();
|
||||
pduel->game_field->core.reason_effect = oreason;
|
||||
pduel->game_field->core.reason_player = op;
|
||||
return TRUE;
|
||||
}
|
||||
int32_t effect::is_activate_check(uint8_t playerid, const tevent& e, int32_t neglect_cond, int32_t neglect_cost, int32_t neglect_target) {
|
||||
pduel->game_field->save_lp_cost();
|
||||
effect* oreason = pduel->game_field->core.reason_effect;
|
||||
uint8_t op = pduel->game_field->core.reason_player;
|
||||
pduel->game_field->core.reason_effect = this;
|
||||
pduel->game_field->core.reason_player = playerid;
|
||||
int32_t result = is_activate_ready(playerid, e, neglect_cond, neglect_cost, neglect_target);
|
||||
pduel->game_field->core.reason_effect = oreason;
|
||||
pduel->game_field->core.reason_player = op;
|
||||
pduel->game_field->restore_lp_cost();
|
||||
return result;
|
||||
}
|
||||
int32_t effect::is_target(card* pcard) {
|
||||
if(type & EFFECT_TYPE_ACTIONS)
|
||||
return FALSE;
|
||||
if(type & (EFFECT_TYPE_SINGLE | EFFECT_TYPE_EQUIP | EFFECT_TYPE_XMATERIAL) && !(type & EFFECT_TYPE_FIELD))
|
||||
return TRUE;
|
||||
if((type & EFFECT_TYPE_TARGET) && !(type & EFFECT_TYPE_FIELD)) {
|
||||
return is_fit_target_function(pcard);
|
||||
}
|
||||
if(!is_flag(EFFECT_FLAG_SET_AVAILABLE) && code != EFFECT_REVEAL_ONFIELD
|
||||
&& (pcard->current.location & LOCATION_ONFIELD) && !pcard->is_position(POS_FACEUP))
|
||||
return FALSE;
|
||||
if(!is_flag(EFFECT_FLAG_IGNORE_RANGE)) {
|
||||
if(pcard->is_treated_as_not_on_field())
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_SPSUM_PARAM))
|
||||
return FALSE;
|
||||
if(is_flag(EFFECT_FLAG_ABSOLUTE_TARGET)) {
|
||||
if(pcard->current.controler == 0) {
|
||||
if(!pcard->current.is_location(s_range))
|
||||
return FALSE;
|
||||
} else {
|
||||
if(!pcard->current.is_location(o_range))
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if(pcard->current.controler == get_handler_player()) {
|
||||
if(!pcard->current.is_location(s_range))
|
||||
return FALSE;
|
||||
} else {
|
||||
if(!pcard->current.is_location(o_range))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return is_fit_target_function(pcard);
|
||||
}
|
||||
int32_t effect::is_fit_target_function(card* pcard) {
|
||||
if(target) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(pcard, PARAM_TYPE_CARD);
|
||||
if (!pduel->lua->check_condition(target, 2)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
int32_t effect::is_target_player(uint8_t playerid) {
|
||||
if(!is_flag(EFFECT_FLAG_PLAYER_TARGET))
|
||||
return FALSE;
|
||||
uint8_t self = get_handler_player();
|
||||
if(is_flag(EFFECT_FLAG_ABSOLUTE_TARGET)) {
|
||||
if(s_range && playerid == 0)
|
||||
return TRUE;
|
||||
if(o_range && playerid == 1)
|
||||
return TRUE;
|
||||
} else {
|
||||
if(s_range && self == playerid)
|
||||
return TRUE;
|
||||
if(o_range && self != playerid)
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
int32_t effect::is_player_effect_target(card* pcard) {
|
||||
if(target) {
|
||||
handler->pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
handler->pduel->lua->add_param(pcard, PARAM_TYPE_CARD);
|
||||
if(!handler->pduel->lua->check_condition(target, 2)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
int32_t effect::is_immuned(card* pcard) {
|
||||
const effect_set_v& effects = pcard->immune_effect;
|
||||
for (effect_set::size_type i = 0; i < effects.size(); ++i) {
|
||||
effect* peffect = effects[i];
|
||||
if(peffect->is_available() && peffect->value) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(pcard, PARAM_TYPE_CARD);
|
||||
if(peffect->check_value_condition(2))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
int32_t effect::is_chainable(uint8_t tp) {
|
||||
if(!(type & EFFECT_TYPE_ACTIONS))
|
||||
return FALSE;
|
||||
int32_t sp = get_speed();
|
||||
// Curse of Field is the exception
|
||||
if((type & EFFECT_TYPE_ACTIVATE) && (sp <= 1) && !is_flag(EFFECT_FLAG2_COF))
|
||||
return FALSE;
|
||||
if(pduel->game_field->core.current_chain.size()) {
|
||||
if(!is_flag(EFFECT_FLAG_FIELD_ONLY) && (type & EFFECT_TYPE_TRIGGER_O)
|
||||
&& (get_handler()->current.location == LOCATION_HAND)) {
|
||||
if(pduel->game_field->core.current_chain.rbegin()->triggering_effect->get_speed() > 2)
|
||||
return FALSE;
|
||||
} else if(sp < pduel->game_field->core.current_chain.rbegin()->triggering_effect->get_speed())
|
||||
return FALSE;
|
||||
}
|
||||
for(const auto& ch_lim : pduel->game_field->core.chain_limit) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(ch_lim.player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(tp, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(ch_lim.function, 3))
|
||||
return FALSE;
|
||||
}
|
||||
for(const auto& ch_lim_p : pduel->game_field->core.chain_limit_p) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
|
||||
pduel->lua->add_param(ch_lim_p.player, PARAM_TYPE_INT);
|
||||
pduel->lua->add_param(tp, PARAM_TYPE_INT);
|
||||
if(!pduel->lua->check_condition(ch_lim_p.function, 3))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
int32_t effect::is_hand_trigger() const {
|
||||
return (range & LOCATION_HAND) && (type & EFFECT_TYPE_TRIGGER_O) && get_code_type() != CODE_PHASE;
|
||||
}
|
||||
int32_t effect::is_initial_single() const {
|
||||
return (type & EFFECT_TYPE_SINGLE) && is_flag(EFFECT_FLAG_SINGLE_RANGE) && is_flag(EFFECT_FLAG_INITIAL);
|
||||
}
|
||||
int32_t effect::is_monster_effect() const {
|
||||
if (range & (LOCATION_SZONE | LOCATION_FZONE | LOCATION_PZONE))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
//return: this can be reset by reset_level or not
|
||||
//RESET_DISABLE is valid only when owner == handler
|
||||
int32_t effect::reset(uint32_t reset_level, uint32_t reset_type) {
|
||||
switch (reset_type) {
|
||||
case RESET_EVENT: {
|
||||
if(!(reset_flag & RESET_EVENT))
|
||||
return FALSE;
|
||||
if(owner != handler)
|
||||
reset_level &= ~RESET_DISABLE;
|
||||
if(reset_level & 0xffff0000 & reset_flag)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case RESET_CARD: {
|
||||
return owner && (owner->data.code == reset_level);
|
||||
break;
|
||||
}
|
||||
case RESET_PHASE: {
|
||||
if(!(reset_flag & RESET_PHASE))
|
||||
return FALSE;
|
||||
uint8_t pid = get_owner_player();
|
||||
uint8_t tp = handler->pduel->game_field->infos.turn_player;
|
||||
if((((reset_flag & RESET_SELF_TURN) && pid == tp) || ((reset_flag & RESET_OPPO_TURN) && pid != tp))
|
||||
&& (reset_level & 0x3ff & reset_flag))
|
||||
--reset_count;
|
||||
if(reset_count == 0)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case RESET_CODE: {
|
||||
return (code == reset_level) && (type & EFFECT_TYPE_SINGLE) && !(type & EFFECT_TYPE_ACTIONS);
|
||||
break;
|
||||
}
|
||||
case RESET_COPY: {
|
||||
return copy_id == reset_level;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
void effect::dec_count(uint8_t playerid) {
|
||||
if(!is_flag(EFFECT_FLAG_COUNT_LIMIT))
|
||||
return;
|
||||
if(count_limit == 0)
|
||||
return;
|
||||
if(count_code == 0 || is_flag(EFFECT_FLAG_NO_TURN_RESET))
|
||||
count_limit -= 1;
|
||||
if(count_code) {
|
||||
uint32_t limit_code = count_code & MAX_CARD_ID;
|
||||
uint32_t limit_type = count_code & 0xf0000000;
|
||||
if(limit_code == EFFECT_COUNT_CODE_SINGLE)
|
||||
pduel->game_field->add_effect_code(limit_type | get_handler()->activate_count_id, PLAYER_NONE);
|
||||
else
|
||||
pduel->game_field->add_effect_code(count_code, playerid);
|
||||
}
|
||||
}
|
||||
void effect::recharge() {
|
||||
if(is_flag(EFFECT_FLAG_COUNT_LIMIT)) {
|
||||
count_limit = count_limit_max;
|
||||
}
|
||||
}
|
||||
int32_t effect::get_value(uint32_t extraargs) {
|
||||
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
|
||||
int32_t res = pduel->lua->get_function_value(value, 1 + extraargs);
|
||||
return res;
|
||||
} else {
|
||||
pduel->lua->params.clear();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
int32_t effect::get_value(card* pcard, uint32_t extraargs) {
|
||||
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
|
||||
pduel->lua->add_param(pcard, PARAM_TYPE_CARD, TRUE);
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
|
||||
int32_t res = pduel->lua->get_function_value(value, 2 + extraargs);
|
||||
return res;
|
||||
} else {
|
||||
pduel->lua->params.clear();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
int32_t effect::get_value(effect* peffect, uint32_t extraargs) {
|
||||
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
|
||||
pduel->lua->add_param(peffect, PARAM_TYPE_EFFECT, TRUE);
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
|
||||
int32_t res = pduel->lua->get_function_value(value, 2 + extraargs);
|
||||
return res;
|
||||
} else {
|
||||
pduel->lua->params.clear();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
void effect::get_value(uint32_t extraargs, std::vector<lua_Integer>& result) {
|
||||
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
|
||||
pduel->lua->get_function_value(value, 1 + extraargs, result);
|
||||
} else {
|
||||
pduel->lua->params.clear();
|
||||
result.push_back(value);
|
||||
}
|
||||
}
|
||||
void effect::get_value(card* pcard, uint32_t extraargs, std::vector<lua_Integer>& result) {
|
||||
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
|
||||
pduel->lua->add_param(pcard, PARAM_TYPE_CARD, TRUE);
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
|
||||
pduel->lua->get_function_value(value, 2 + extraargs, result);
|
||||
} else {
|
||||
pduel->lua->params.clear();
|
||||
result.push_back(value);
|
||||
}
|
||||
}
|
||||
void effect::get_value(effect* peffect, uint32_t extraargs, std::vector<lua_Integer>& result) {
|
||||
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
|
||||
pduel->lua->add_param(peffect, PARAM_TYPE_EFFECT, TRUE);
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
|
||||
pduel->lua->get_function_value(value, 2 + extraargs, result);
|
||||
} else {
|
||||
pduel->lua->params.clear();
|
||||
result.push_back(value);
|
||||
}
|
||||
}
|
||||
int32_t effect::get_integer_value() {
|
||||
return is_flag(EFFECT_FLAG_FUNC_VALUE) ? 0 : value;
|
||||
}
|
||||
int32_t effect::check_value_condition(uint32_t extraargs) {
|
||||
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
|
||||
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
|
||||
int32_t res = pduel->lua->check_condition(value, 1 + extraargs);
|
||||
return res;
|
||||
} else {
|
||||
pduel->lua->params.clear();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
void* effect::get_label_object() {
|
||||
return pduel->lua->get_ref_object(label_object);
|
||||
}
|
||||
int32_t effect::get_speed() {
|
||||
if(!(type & EFFECT_TYPE_ACTIONS))
|
||||
return 0;
|
||||
if(type & (EFFECT_TYPE_TRIGGER_O | EFFECT_TYPE_TRIGGER_F | EFFECT_TYPE_IGNITION))
|
||||
return 1;
|
||||
else if(type & (EFFECT_TYPE_QUICK_O | EFFECT_TYPE_QUICK_F))
|
||||
return 2;
|
||||
else if(type & EFFECT_TYPE_ACTIVATE) {
|
||||
if(handler->data.type & TYPE_MONSTER)
|
||||
return 0;
|
||||
else if(handler->data.type & TYPE_SPELL) {
|
||||
if(handler->data.type & TYPE_QUICKPLAY)
|
||||
return 2;
|
||||
return 1;
|
||||
} else {
|
||||
if (handler->data.type & TYPE_COUNTER)
|
||||
return 3;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
effect* effect::clone() {
|
||||
effect* ceffect = pduel->new_effect();
|
||||
int32_t ref = ceffect->ref_handle;
|
||||
*ceffect = *this;
|
||||
ceffect->ref_handle = ref;
|
||||
ceffect->handler = 0;
|
||||
if(condition)
|
||||
ceffect->condition = pduel->lua->clone_function_ref(condition);
|
||||
if(cost)
|
||||
ceffect->cost = pduel->lua->clone_function_ref(cost);
|
||||
if(target)
|
||||
ceffect->target = pduel->lua->clone_function_ref(target);
|
||||
if(operation)
|
||||
ceffect->operation = pduel->lua->clone_function_ref(operation);
|
||||
if(value && is_flag(EFFECT_FLAG_FUNC_VALUE))
|
||||
ceffect->value = pduel->lua->clone_function_ref(value);
|
||||
return ceffect;
|
||||
}
|
||||
card* effect::get_owner() const {
|
||||
if (type & EFFECT_TYPE_XMATERIAL) {
|
||||
if (active_handler)
|
||||
return active_handler;
|
||||
if (handler->overlay_target)
|
||||
return handler->overlay_target;
|
||||
if (last_handler)
|
||||
return last_handler;
|
||||
}
|
||||
return owner;
|
||||
}
|
||||
uint8_t effect::get_owner_player() const {
|
||||
if(effect_owner != PLAYER_NONE)
|
||||
return effect_owner;
|
||||
return get_owner()->current.controler;
|
||||
}
|
||||
card* effect::get_handler() const {
|
||||
if (type & EFFECT_TYPE_XMATERIAL) {
|
||||
if (active_handler)
|
||||
return active_handler;
|
||||
if (handler->overlay_target)
|
||||
return handler->overlay_target;
|
||||
if (last_handler)
|
||||
return last_handler;
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
uint8_t effect::get_handler_player() const {
|
||||
if(is_flag(EFFECT_FLAG_FIELD_ONLY))
|
||||
return effect_owner;
|
||||
return get_handler()->current.controler;
|
||||
}
|
||||
int32_t effect::in_range(card* pcard) const {
|
||||
if(type & EFFECT_TYPE_XMATERIAL)
|
||||
return handler->overlay_target ? TRUE : FALSE;
|
||||
return pcard->current.is_location(range);
|
||||
}
|
||||
int32_t effect::in_range(const chain& ch) const {
|
||||
if(type & EFFECT_TYPE_XMATERIAL)
|
||||
return handler->overlay_target ? TRUE : FALSE;
|
||||
return range & ch.triggering_location;
|
||||
}
|
||||
void effect::set_activate_location() {
|
||||
card* phandler = get_handler();
|
||||
active_location = phandler->current.location;
|
||||
active_sequence = phandler->current.sequence;
|
||||
}
|
||||
void effect::set_active_type() {
|
||||
card* phandler = get_handler();
|
||||
active_type = phandler->get_type();
|
||||
if(active_type & TYPE_TRAPMONSTER)
|
||||
active_type &= ~TYPE_TRAP;
|
||||
if((type & EFFECT_TYPE_ACTIVATE) && is_flag(EFFECT_FLAG2_SPOSITCH))
|
||||
active_type |= TYPE_QUICKPLAY;
|
||||
}
|
||||
uint32_t effect::get_active_type(uint8_t uselast) {
|
||||
if(type & EFFECT_TYPES_CHAIN_LINK) {
|
||||
if(active_type && uselast)
|
||||
return active_type;
|
||||
else if((type & EFFECT_TYPE_ACTIVATE) && (get_handler()->data.type & TYPE_PENDULUM))
|
||||
{
|
||||
if(is_flag(EFFECT_FLAG2_SPOSITCH))
|
||||
return TYPE_PENDULUM + TYPE_SPELL + TYPE_QUICKPLAY;
|
||||
else
|
||||
return TYPE_PENDULUM + TYPE_SPELL;
|
||||
}
|
||||
else
|
||||
return get_handler()->get_type();
|
||||
} else
|
||||
return owner->get_type();
|
||||
}
|
||||
code_type effect::get_code_type() const {
|
||||
// start from the highest bit
|
||||
if (code & 0xf0000000)
|
||||
return CODE_CUSTOM;
|
||||
else if (code & 0xf0000)
|
||||
return CODE_COUNTER;
|
||||
else if (code & 0xf000)
|
||||
return CODE_PHASE;
|
||||
else
|
||||
return CODE_VALUE;
|
||||
}
|
||||
+668
@@ -0,0 +1,668 @@
|
||||
/*
|
||||
* effect.h
|
||||
*
|
||||
* Created on: 2010-3-13
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef EFFECT_H_
|
||||
#define EFFECT_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "field.h"
|
||||
#include "effectset.h"
|
||||
#include "metadata.h"
|
||||
#include <vector>
|
||||
|
||||
class card;
|
||||
class duel;
|
||||
class group;
|
||||
class effect;
|
||||
struct tevent;
|
||||
enum effect_flag : uint64_t;
|
||||
enum effect_flag2 : uint64_t;
|
||||
enum effect_category :uint64_t;
|
||||
enum code_type : int32_t;
|
||||
|
||||
bool is_continuous_event(uint32_t code);
|
||||
|
||||
class effect {
|
||||
public:
|
||||
int32_t ref_handle{ 0 };
|
||||
duel* pduel{ nullptr };
|
||||
card* owner{ nullptr };
|
||||
card* handler{ nullptr };
|
||||
uint8_t effect_owner{ PLAYER_NONE };
|
||||
uint32_t description{ 0 };
|
||||
uint32_t code{ 0 };
|
||||
uint32_t id{ 0 };
|
||||
uint32_t type{ 0 };
|
||||
uint16_t copy_id{ 0 };
|
||||
uint16_t range{ 0 };
|
||||
uint16_t s_range{ 0 };
|
||||
uint16_t o_range{ 0 };
|
||||
uint8_t count_limit{ 0 }; //left count of activation
|
||||
uint8_t count_limit_max{ 0 }; //max count of activation
|
||||
uint16_t status{ 0 };
|
||||
int32_t reset_count{ 0 };
|
||||
uint32_t reset_flag{ 0 };
|
||||
uint32_t count_code{ 0 };
|
||||
uint64_t category{ 0 };
|
||||
uint64_t flag[2]{};
|
||||
uint32_t hint_timing[2]{};
|
||||
uint32_t card_type{ 0 };
|
||||
uint32_t active_type{ 0 };
|
||||
uint16_t active_location{ 0 };
|
||||
uint16_t active_sequence{ 0 };
|
||||
card* active_handler{ nullptr };
|
||||
card* last_handler{ nullptr };
|
||||
std::vector<lua_Integer> label;
|
||||
int32_t label_object{ 0 };
|
||||
int32_t condition{ 0 };
|
||||
int32_t cost{ 0 };
|
||||
int32_t target{ 0 };
|
||||
int32_t value{ 0 };
|
||||
int32_t operation{ 0 };
|
||||
uint8_t cost_checked{ FALSE };
|
||||
uint8_t is_granted{ 0 };
|
||||
|
||||
effect_set required_handorset_effects;
|
||||
LuaParamType object_type{ PARAM_TYPE_INT };
|
||||
metadata meta;
|
||||
|
||||
explicit effect(duel* pd);
|
||||
~effect() = default;
|
||||
|
||||
int32_t is_disable_related() const;
|
||||
int32_t is_self_destroy_related() const;
|
||||
int32_t is_can_be_forbidden() const;
|
||||
int32_t is_available(int32_t neglect_disabled = FALSE);
|
||||
int32_t limit_counter_is_available();
|
||||
int32_t is_single_ready();
|
||||
int32_t check_count_limit(uint8_t playerid);
|
||||
int32_t get_required_handorset_effects(effect_set* eset, uint8_t playerid, const tevent& e, int32_t neglect_loc = FALSE);
|
||||
int32_t is_activateable(uint8_t playerid, const tevent &e, int32_t neglect_cond = FALSE, int32_t neglect_cost = FALSE, int32_t neglect_target = FALSE, int32_t neglect_loc = FALSE, int32_t neglect_faceup = FALSE);
|
||||
int32_t is_action_check(uint8_t playerid);
|
||||
int32_t is_activate_ready(effect* reason_effect, uint8_t playerid, const tevent& e, int32_t neglect_cond = FALSE, int32_t neglect_cost = FALSE, int32_t neglect_target = FALSE);
|
||||
int32_t is_activate_ready(uint8_t playerid, const tevent& e, int32_t neglect_cond = FALSE, int32_t neglect_cost = FALSE, int32_t neglect_target = FALSE);
|
||||
int32_t is_condition_check(uint8_t playerid, const tevent& e);
|
||||
int32_t is_activate_check(uint8_t playerid, const tevent& e, int32_t neglect_cond = FALSE, int32_t neglect_cost = FALSE, int32_t neglect_target = FALSE);
|
||||
int32_t is_target(card* pcard);
|
||||
int32_t is_fit_target_function(card* pcard);
|
||||
int32_t is_target_player(uint8_t playerid);
|
||||
int32_t is_player_effect_target(card* pcard);
|
||||
int32_t is_immuned(card* pcard);
|
||||
int32_t is_chainable(uint8_t tp);
|
||||
int32_t is_hand_trigger() const;
|
||||
int32_t is_initial_single() const;
|
||||
int32_t is_monster_effect() const;
|
||||
int32_t reset(uint32_t reset_level, uint32_t reset_type);
|
||||
void dec_count(uint8_t playerid = PLAYER_NONE);
|
||||
void recharge();
|
||||
int32_t get_value(uint32_t extraargs = 0);
|
||||
int32_t get_value(card* pcard, uint32_t extraargs = 0);
|
||||
int32_t get_value(effect* peffect, uint32_t extraargs = 0);
|
||||
void get_value(uint32_t extraargs, std::vector<lua_Integer>& result);
|
||||
void get_value(card* pcard, uint32_t extraargs, std::vector<lua_Integer>& result);
|
||||
void get_value(effect* peffect, uint32_t extraargs, std::vector<lua_Integer>& result);
|
||||
int32_t get_integer_value();
|
||||
int32_t check_value_condition(uint32_t extraargs = 0);
|
||||
void* get_label_object();
|
||||
int32_t get_speed();
|
||||
effect* clone();
|
||||
card* get_owner() const;
|
||||
uint8_t get_owner_player() const;
|
||||
card* get_handler() const;
|
||||
uint8_t get_handler_player() const;
|
||||
int32_t in_range(card* pcard) const;
|
||||
int32_t in_range(const chain& ch) const;
|
||||
void set_activate_location();
|
||||
void set_active_type();
|
||||
uint32_t get_active_type(uint8_t uselast = TRUE);
|
||||
code_type get_code_type() const;
|
||||
|
||||
bool is_flag(effect_flag x) const {
|
||||
return !!(flag[0] & x);
|
||||
}
|
||||
bool is_flag(effect_flag2 x) const {
|
||||
return !!(flag[1] & x);
|
||||
}
|
||||
};
|
||||
|
||||
// KoishiPro effects
|
||||
#define EFFECT_CHANGE_LINK_MARKER_KOISHI 710253
|
||||
#define EFFECT_ADD_LINK_MARKER_KOISHI 37564151
|
||||
#define EFFECT_REMOVE_LINK_MARKER_KOISHI 37564152
|
||||
#define EFFECT_CANNOT_LOSE_KOISHI 37564153
|
||||
#define EFFECT_EXTRA_TOMAIN_KOISHI 37564154
|
||||
#define EFFECT_OVERLAY_REMOVE_COST_CHANGE_KOISHI 37564155
|
||||
#define EFFECT_ADD_SUMMON_TYPE_KOISHI 37564158
|
||||
#define EFFECT_REMOVE_SUMMON_TYPE_KOISHI 37564159
|
||||
#define EFFECT_CHANGE_SUMMON_TYPE_KOISHI 37564160
|
||||
#define EFFECT_CHANGE_SUMMON_LOCATION_KOISHI 37564161
|
||||
#define EFFECT_LINK_SPELL_KOISHI 37564162
|
||||
#define EFFECT_MAP_OF_HEAVEN 77702007
|
||||
|
||||
//status
|
||||
#define EFFECT_STATUS_AVAILABLE 0x0001
|
||||
//#define EFFECT_STATUS_ACTIVATED 0x0002
|
||||
#define EFFECT_STATUS_SPSELF 0x0004
|
||||
|
||||
#define EFFECT_COUNT_CODE_OATH 0x10000000U
|
||||
#define EFFECT_COUNT_CODE_DUEL 0x20000000U
|
||||
#define EFFECT_COUNT_CODE_CHAIN 0x40000000U
|
||||
#define EFFECT_COUNT_CODE_SINGLE 0x1U
|
||||
|
||||
//========== Reset ==========
|
||||
#define RESET_SELF_TURN 0x10000000
|
||||
#define RESET_OPPO_TURN 0x20000000
|
||||
#define RESET_PHASE 0x40000000
|
||||
#define RESET_CHAIN 0x80000000
|
||||
#define RESET_EVENT 0x1000
|
||||
#define RESET_CARD 0x2000
|
||||
#define RESET_CODE 0x4000
|
||||
#define RESET_COPY 0x8000
|
||||
|
||||
#define RESET_DISABLE 0x00010000
|
||||
#define RESET_TURN_SET 0x00020000
|
||||
#define RESET_TOGRAVE 0x00040000
|
||||
#define RESET_REMOVE 0x00080000
|
||||
#define RESET_TEMP_REMOVE 0x00100000
|
||||
#define RESET_TOHAND 0x00200000
|
||||
#define RESET_TODECK 0x00400000
|
||||
#define RESET_LEAVE 0x00800000
|
||||
#define RESET_TOFIELD 0x01000000
|
||||
#define RESET_CONTROL 0x02000000
|
||||
#define RESET_OVERLAY 0x04000000
|
||||
#define RESET_MSCHANGE 0x08000000
|
||||
|
||||
constexpr uint32_t RESETS_STANDARD = RESET_TOFIELD | RESET_LEAVE | RESET_TODECK | RESET_TOHAND | RESET_TEMP_REMOVE | RESET_REMOVE | RESET_TOGRAVE | RESET_TURN_SET;
|
||||
|
||||
//========== Types ==========
|
||||
#define EFFECT_TYPE_SINGLE 0x0001 //
|
||||
#define EFFECT_TYPE_FIELD 0x0002 //
|
||||
#define EFFECT_TYPE_EQUIP 0x0004 //
|
||||
#define EFFECT_TYPE_ACTIONS 0x0008 //
|
||||
#define EFFECT_TYPE_ACTIVATE 0x0010 //
|
||||
#define EFFECT_TYPE_FLIP 0x0020 //
|
||||
#define EFFECT_TYPE_IGNITION 0x0040 //
|
||||
#define EFFECT_TYPE_TRIGGER_O 0x0080 //
|
||||
#define EFFECT_TYPE_QUICK_O 0x0100 //
|
||||
#define EFFECT_TYPE_TRIGGER_F 0x0200 //
|
||||
#define EFFECT_TYPE_QUICK_F 0x0400 //
|
||||
#define EFFECT_TYPE_CONTINUOUS 0x0800 //
|
||||
#define EFFECT_TYPE_XMATERIAL 0x1000 //
|
||||
#define EFFECT_TYPE_GRANT 0x2000 //
|
||||
#define EFFECT_TYPE_TARGET 0x4000 //
|
||||
|
||||
constexpr uint32_t EFFECT_TYPES_TRIGGER_LIKE = EFFECT_TYPE_ACTIVATE | EFFECT_TYPE_TRIGGER_O | EFFECT_TYPE_TRIGGER_F | EFFECT_TYPE_QUICK_O | EFFECT_TYPE_QUICK_F;
|
||||
constexpr uint32_t EFFECT_TYPES_CHAIN_LINK = EFFECT_TYPES_TRIGGER_LIKE | EFFECT_TYPE_FLIP | EFFECT_TYPE_IGNITION;
|
||||
|
||||
//========== Flags ==========
|
||||
enum effect_flag : uint64_t {
|
||||
EFFECT_FLAG_INITIAL = 0x0001,
|
||||
EFFECT_FLAG_FUNC_VALUE = 0x0002,
|
||||
EFFECT_FLAG_COUNT_LIMIT = 0x0004,
|
||||
EFFECT_FLAG_FIELD_ONLY = 0x0008,
|
||||
EFFECT_FLAG_CARD_TARGET = 0x0010,
|
||||
EFFECT_FLAG_IGNORE_RANGE = 0x0020,
|
||||
EFFECT_FLAG_ABSOLUTE_TARGET = 0x0040,
|
||||
EFFECT_FLAG_IGNORE_IMMUNE = 0x0080,
|
||||
EFFECT_FLAG_SET_AVAILABLE = 0x0100,
|
||||
EFFECT_FLAG_CANNOT_NEGATE = 0x0200,
|
||||
EFFECT_FLAG_CANNOT_DISABLE = 0x0400,
|
||||
EFFECT_FLAG_PLAYER_TARGET = 0x0800,
|
||||
EFFECT_FLAG_BOTH_SIDE = 0x1000,
|
||||
EFFECT_FLAG_COPY = 0x2000,
|
||||
EFFECT_FLAG_DAMAGE_STEP = 0x4000,
|
||||
EFFECT_FLAG_DAMAGE_CAL = 0x8000,
|
||||
EFFECT_FLAG_DELAY = 0x10000,
|
||||
EFFECT_FLAG_SINGLE_RANGE = 0x20000,
|
||||
EFFECT_FLAG_UNCOPYABLE = 0x40000,
|
||||
EFFECT_FLAG_OATH = 0x80000,
|
||||
EFFECT_FLAG_SPSUM_PARAM = 0x100000,
|
||||
// EFFECT_FLAG_REPEAT = 0x200000,
|
||||
EFFECT_FLAG_NO_TURN_RESET = 0x400000,
|
||||
EFFECT_FLAG_EVENT_PLAYER = 0x800000,
|
||||
EFFECT_FLAG_OWNER_RELATE = 0x1000000,
|
||||
EFFECT_FLAG_CANNOT_INACTIVATE = 0x2000000,
|
||||
EFFECT_FLAG_CLIENT_HINT = 0x4000000,
|
||||
EFFECT_FLAG_CONTINUOUS_TARGET = 0x8000000,
|
||||
EFFECT_FLAG_LIMIT_ZONE = 0x10000000,
|
||||
EFFECT_FLAG_ACTIVATE_CONDITION = 0x20000000,
|
||||
// EFFECT_FLAG_CVAL_CHECK = 0x40000000,
|
||||
EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000,
|
||||
EFFECT_FLAG_COIN = 0x100000000,
|
||||
EFFECT_FLAG_DICE = 0x200000000,
|
||||
EFFECT_FLAG_FUSION_SUMMON = 0x400000000,
|
||||
};
|
||||
enum effect_flag2 : uint64_t {
|
||||
EFFECT_FLAG2_REPEAT_UPDATE = 0x0001,
|
||||
EFFECT_FLAG2_COF = 0x0002,
|
||||
EFFECT_FLAG2_WICKED = 0x0004,
|
||||
EFFECT_FLAG2_OPTION = 0x0008,
|
||||
EFFECT_FLAG2_SPOSITCH = 0x0100, // flag2 from 0x0100 are koishipro use
|
||||
EFFECT_FLAG2_AVAILABLE_BD = 0x0200,
|
||||
EFFECT_FLAG2_ACTIVATE_MONSTER_SZONE = 0x0400,
|
||||
};
|
||||
constexpr effect_flag operator|(effect_flag flag1, effect_flag flag2) {
|
||||
return static_cast<effect_flag>(static_cast<uint64_t>(flag1) | static_cast<uint64_t>(flag2));
|
||||
}
|
||||
constexpr uint64_t INTERNAL_FLAGS = EFFECT_FLAG_INITIAL | EFFECT_FLAG_COPY | EFFECT_FLAG_FUNC_VALUE | EFFECT_FLAG_COUNT_LIMIT | EFFECT_FLAG_FIELD_ONLY | EFFECT_FLAG_ABSOLUTE_TARGET;
|
||||
|
||||
//Category
|
||||
enum effect_category : uint64_t {
|
||||
CATEGORY_DESTROY = 0x1,
|
||||
CATEGORY_RELEASE = 0x2,
|
||||
CATEGORY_REMOVE = 0x4,
|
||||
CATEGORY_TOHAND = 0x8,
|
||||
CATEGORY_TODECK = 0x10,
|
||||
CATEGORY_TOGRAVE = 0x20,
|
||||
CATEGORY_DECKDES = 0x40,
|
||||
CATEGORY_HANDES = 0x80,
|
||||
CATEGORY_SUMMON = 0x100,
|
||||
CATEGORY_SPECIAL_SUMMON = 0x200,
|
||||
CATEGORY_TOKEN = 0x400,
|
||||
CATEGORY_GRAVE_ACTION = 0x800,
|
||||
CATEGORY_POSITION = 0x1000,
|
||||
CATEGORY_CONTROL = 0x2000,
|
||||
CATEGORY_DISABLE = 0x4000,
|
||||
CATEGORY_DISABLE_SUMMON = 0x8000,
|
||||
CATEGORY_DRAW = 0x10000,
|
||||
CATEGORY_SEARCH = 0x20000,
|
||||
CATEGORY_EQUIP = 0x40000,
|
||||
CATEGORY_DAMAGE = 0x80000,
|
||||
CATEGORY_RECOVER = 0x100000,
|
||||
CATEGORY_ATKCHANGE = 0x200000,
|
||||
CATEGORY_DEFCHANGE = 0x400000,
|
||||
CATEGORY_COUNTER = 0x800000,
|
||||
CATEGORY_COIN = 0x1000000,
|
||||
CATEGORY_DICE = 0x2000000,
|
||||
CATEGORY_LEAVE_GRAVE = 0x4000000,
|
||||
CATEGORY_GRAVE_SPSUMMON = 0x8000000,
|
||||
CATEGORY_NEGATE = 0x10000000,
|
||||
CATEGORY_ANNOUNCE = 0x20000000,
|
||||
CATEGORY_FUSION_SUMMON = 0x40000000,
|
||||
CATEGORY_TOEXTRA = 0x80000000,
|
||||
CATEGORY_MSET = 0x100000000,
|
||||
CATEGORY_SSET = 0x200000000,
|
||||
};
|
||||
|
||||
const std::map<uint64_t, uint64_t> category_checklist{
|
||||
{CATEGORY_COIN, EFFECT_FLAG_COIN},
|
||||
{CATEGORY_DICE, EFFECT_FLAG_DICE},
|
||||
{CATEGORY_FUSION_SUMMON, EFFECT_FLAG_FUSION_SUMMON},
|
||||
};
|
||||
|
||||
//========== Codes ==========
|
||||
#define EFFECT_IMMUNE_EFFECT 1 //
|
||||
#define EFFECT_DISABLE 2 //
|
||||
#define EFFECT_CANNOT_DISABLE 3 //
|
||||
#define EFFECT_SET_CONTROL 4 //
|
||||
#define EFFECT_CANNOT_CHANGE_CONTROL 5 //
|
||||
#define EFFECT_CANNOT_ACTIVATE 6 //
|
||||
#define EFFECT_CANNOT_TRIGGER 7 //
|
||||
#define EFFECT_DISABLE_EFFECT 8 //
|
||||
#define EFFECT_DISABLE_CHAIN 9 //
|
||||
#define EFFECT_DISABLE_TRAPMONSTER 10 //
|
||||
#define EFFECT_CANNOT_INACTIVATE 12 //
|
||||
#define EFFECT_CANNOT_DISEFFECT 13 //
|
||||
#define EFFECT_CANNOT_CHANGE_POSITION 14 //
|
||||
#define EFFECT_TRAP_ACT_IN_HAND 15 //
|
||||
#define EFFECT_TRAP_ACT_IN_SET_TURN 16 //
|
||||
#define EFFECT_REMAIN_FIELD 17 //
|
||||
#define EFFECT_MONSTER_SSET 18 //
|
||||
#define EFFECT_CANNOT_SUMMON 20 //
|
||||
#define EFFECT_CANNOT_FLIP_SUMMON 21 //
|
||||
#define EFFECT_CANNOT_SPECIAL_SUMMON 22 //
|
||||
#define EFFECT_CANNOT_MSET 23 //
|
||||
#define EFFECT_CANNOT_SSET 24 //
|
||||
#define EFFECT_CANNOT_DRAW 25 //
|
||||
#define EFFECT_CANNOT_DISABLE_SUMMON 26 //
|
||||
#define EFFECT_CANNOT_DISABLE_SPSUMMON 27 //
|
||||
#define EFFECT_SET_SUMMON_COUNT_LIMIT 28 //
|
||||
#define EFFECT_EXTRA_SUMMON_COUNT 29 //
|
||||
#define EFFECT_SPSUMMON_CONDITION 30 //
|
||||
#define EFFECT_REVIVE_LIMIT 31 //
|
||||
#define EFFECT_SUMMON_PROC 32 //
|
||||
#define EFFECT_LIMIT_SUMMON_PROC 33 //
|
||||
#define EFFECT_SPSUMMON_PROC 34 //
|
||||
#define EFFECT_EXTRA_SET_COUNT 35 //
|
||||
#define EFFECT_SET_PROC 36 //
|
||||
#define EFFECT_LIMIT_SET_PROC 37 //
|
||||
#define EFFECT_DIVINE_LIGHT 38 //
|
||||
#define EFFECT_CANNOT_DISABLE_FLIP_SUMMON 39 //
|
||||
#define EFFECT_INDESTRUCTABLE 40 //
|
||||
#define EFFECT_INDESTRUCTABLE_EFFECT 41 //
|
||||
#define EFFECT_INDESTRUCTABLE_BATTLE 42 //
|
||||
#define EFFECT_UNRELEASABLE_SUM 43 //
|
||||
#define EFFECT_UNRELEASABLE_NONSUM 44 //
|
||||
#define EFFECT_DESTROY_SUBSTITUTE 45 //
|
||||
#define EFFECT_CANNOT_RELEASE 46 //
|
||||
#define EFFECT_INDESTRUCTABLE_COUNT 47 //
|
||||
#define EFFECT_UNRELEASABLE_EFFECT 48 //
|
||||
#define EFFECT_DESTROY_REPLACE 50 //
|
||||
#define EFFECT_RELEASE_REPLACE 51 //
|
||||
#define EFFECT_SEND_REPLACE 52 //
|
||||
#define EFFECT_CANNOT_DISCARD_HAND 55 //
|
||||
#define EFFECT_CANNOT_DISCARD_DECK 56 //
|
||||
#define EFFECT_CANNOT_USE_AS_COST 57 //
|
||||
#define EFFECT_CANNOT_PLACE_COUNTER 58 //
|
||||
#define EFFECT_CANNOT_TO_GRAVE_AS_COST 59 //
|
||||
#define EFFECT_LEAVE_FIELD_REDIRECT 60 //
|
||||
#define EFFECT_TO_HAND_REDIRECT 61 //
|
||||
#define EFFECT_TO_DECK_REDIRECT 62 //
|
||||
#define EFFECT_TO_GRAVE_REDIRECT 63 //
|
||||
#define EFFECT_REMOVE_REDIRECT 64 //
|
||||
#define EFFECT_CANNOT_TO_HAND 65 //
|
||||
#define EFFECT_CANNOT_TO_DECK 66 //
|
||||
#define EFFECT_CANNOT_REMOVE 67 //
|
||||
#define EFFECT_CANNOT_TO_GRAVE 68 //
|
||||
#define EFFECT_CANNOT_TURN_SET 69 //
|
||||
#define EFFECT_CANNOT_BE_BATTLE_TARGET 70 //
|
||||
#define EFFECT_CANNOT_BE_EFFECT_TARGET 71 //
|
||||
#define EFFECT_IGNORE_BATTLE_TARGET 72 //
|
||||
#define EFFECT_CANNOT_DIRECT_ATTACK 73 //
|
||||
#define EFFECT_DIRECT_ATTACK 74 //
|
||||
#define EFFECT_DUAL_STATUS 75 //
|
||||
#define EFFECT_EQUIP_LIMIT 76 //
|
||||
#define EFFECT_DUAL_SUMMONABLE 77 //
|
||||
#define EFFECT_UNION_LIMIT 78 //
|
||||
#define EFFECT_REVERSE_DAMAGE 80 //
|
||||
#define EFFECT_REVERSE_RECOVER 81 //
|
||||
#define EFFECT_CHANGE_DAMAGE 82 //
|
||||
#define EFFECT_REFLECT_DAMAGE 83 //
|
||||
#define EFFECT_CANNOT_ATTACK 85 //
|
||||
#define EFFECT_CANNOT_ATTACK_ANNOUNCE 86 //
|
||||
#define EFFECT_CANNOT_CHANGE_POS_E 87 //
|
||||
#define EFFECT_ACTIVATE_COST 90 //
|
||||
#define EFFECT_SUMMON_COST 91 //
|
||||
#define EFFECT_SPSUMMON_COST 92 //
|
||||
#define EFFECT_FLIPSUMMON_COST 93 //
|
||||
#define EFFECT_MSET_COST 94 //
|
||||
#define EFFECT_SSET_COST 95 //
|
||||
#define EFFECT_ATTACK_COST 96 //
|
||||
|
||||
#define EFFECT_UPDATE_ATTACK 100 //
|
||||
#define EFFECT_SET_ATTACK 101 //
|
||||
#define EFFECT_SET_ATTACK_FINAL 102 //
|
||||
#define EFFECT_SET_BASE_ATTACK 103 //
|
||||
#define EFFECT_UPDATE_DEFENSE 104 //
|
||||
#define EFFECT_SET_DEFENSE 105 //
|
||||
#define EFFECT_SET_DEFENSE_FINAL 106 //
|
||||
#define EFFECT_SET_BASE_DEFENSE 107 //
|
||||
#define EFFECT_REVERSE_UPDATE 108 //
|
||||
#define EFFECT_SWAP_AD 109 //
|
||||
#define EFFECT_SWAP_BASE_AD 110 //
|
||||
#define EFFECT_SET_BASE_ATTACK_FINAL 111 //
|
||||
#define EFFECT_SET_BASE_DEFENSE_FINAL 112 //
|
||||
#define EFFECT_ADD_CODE 113 //
|
||||
#define EFFECT_CHANGE_CODE 114 //
|
||||
#define EFFECT_ADD_TYPE 115 //
|
||||
#define EFFECT_REMOVE_TYPE 116 //
|
||||
#define EFFECT_CHANGE_TYPE 117 //
|
||||
#define EFFECT_ADD_RACE 120 //
|
||||
#define EFFECT_REMOVE_RACE 121 //
|
||||
#define EFFECT_CHANGE_RACE 122 //
|
||||
#define EFFECT_ADD_ATTRIBUTE 125 //
|
||||
#define EFFECT_REMOVE_ATTRIBUTE 126 //
|
||||
#define EFFECT_CHANGE_ATTRIBUTE 127 //
|
||||
#define EFFECT_UPDATE_LEVEL 130 //
|
||||
#define EFFECT_CHANGE_LEVEL 131 //
|
||||
#define EFFECT_UPDATE_RANK 132 //
|
||||
#define EFFECT_CHANGE_RANK 133 //
|
||||
#define EFFECT_UPDATE_LSCALE 134 //
|
||||
#define EFFECT_CHANGE_LSCALE 135 //
|
||||
#define EFFECT_UPDATE_RSCALE 136 //
|
||||
#define EFFECT_CHANGE_RSCALE 137 //
|
||||
#define EFFECT_SET_POSITION 140 //
|
||||
#define EFFECT_SELF_DESTROY 141 //
|
||||
#define EFFECT_SELF_TOGRAVE 142
|
||||
#define EFFECT_DOUBLE_TRIBUTE 150
|
||||
#define EFFECT_DECREASE_TRIBUTE 151
|
||||
#define EFFECT_DECREASE_TRIBUTE_SET 152
|
||||
#define EFFECT_EXTRA_RELEASE 153
|
||||
#define EFFECT_TRIBUTE_LIMIT 154
|
||||
#define EFFECT_EXTRA_RELEASE_SUM 155
|
||||
//#define EFFECT_TRIPLE_TRIBUTE 156
|
||||
#define EFFECT_ADD_EXTRA_TRIBUTE 157
|
||||
#define EFFECT_EXTRA_RELEASE_NONSUM 158
|
||||
#define EFFECT_PUBLIC 160
|
||||
#define EFFECT_COUNTER_PERMIT 0x10000
|
||||
#define EFFECT_COUNTER_LIMIT 0x20000
|
||||
#define EFFECT_RCOUNTER_REPLACE 0x30000
|
||||
#define EFFECT_LPCOST_CHANGE 170
|
||||
#define EFFECT_LPCOST_REPLACE 171
|
||||
#define EFFECT_SKIP_DP 180
|
||||
#define EFFECT_SKIP_SP 181
|
||||
#define EFFECT_SKIP_M1 182
|
||||
#define EFFECT_SKIP_BP 183
|
||||
#define EFFECT_SKIP_M2 184
|
||||
#define EFFECT_CANNOT_BP 185
|
||||
#define EFFECT_CANNOT_M2 186
|
||||
#define EFFECT_CANNOT_EP 187
|
||||
#define EFFECT_SKIP_TURN 188
|
||||
#define EFFECT_SKIP_EP 189
|
||||
#define EFFECT_DEFENSE_ATTACK 190
|
||||
#define EFFECT_MUST_ATTACK 191
|
||||
#define EFFECT_FIRST_ATTACK 192
|
||||
#define EFFECT_ATTACK_ALL 193
|
||||
#define EFFECT_EXTRA_ATTACK 194
|
||||
//#define EFFECT_MUST_BE_ATTACKED 195
|
||||
#define EFFECT_ONLY_BE_ATTACKED 196
|
||||
#define EFFECT_ATTACK_DISABLED 197
|
||||
#define EFFECT_NO_BATTLE_DAMAGE 200
|
||||
#define EFFECT_AVOID_BATTLE_DAMAGE 201
|
||||
#define EFFECT_REFLECT_BATTLE_DAMAGE 202
|
||||
#define EFFECT_PIERCE 203
|
||||
#define EFFECT_BATTLE_DESTROY_REDIRECT 204
|
||||
#define EFFECT_BATTLE_DAMAGE_TO_EFFECT 205
|
||||
#define EFFECT_BOTH_BATTLE_DAMAGE 206
|
||||
#define EFFECT_ALSO_BATTLE_DAMAGE 207
|
||||
#define EFFECT_CHANGE_BATTLE_DAMAGE 208
|
||||
#define EFFECT_TOSS_COIN_REPLACE 220
|
||||
#define EFFECT_TOSS_DICE_REPLACE 221
|
||||
#define EFFECT_FUSION_MATERIAL 230
|
||||
#define EFFECT_CHAIN_MATERIAL 231
|
||||
#define EFFECT_EXTRA_SYNCHRO_MATERIAL 232
|
||||
#define EFFECT_XYZ_MATERIAL 233
|
||||
#define EFFECT_FUSION_SUBSTITUTE 234
|
||||
#define EFFECT_CANNOT_BE_FUSION_MATERIAL 235
|
||||
#define EFFECT_CANNOT_BE_SYNCHRO_MATERIAL 236
|
||||
#define EFFECT_SYNCHRO_MATERIAL_CUSTOM 237
|
||||
#define EFFECT_CANNOT_BE_XYZ_MATERIAL 238
|
||||
#define EFFECT_CANNOT_BE_LINK_MATERIAL 239
|
||||
#define EFFECT_SYNCHRO_LEVEL 240
|
||||
#define EFFECT_RITUAL_LEVEL 241
|
||||
#define EFFECT_XYZ_LEVEL 242
|
||||
#define EFFECT_EXTRA_RITUAL_MATERIAL 243
|
||||
#define EFFECT_NONTUNER 244
|
||||
#define EFFECT_OVERLAY_REMOVE_REPLACE 245
|
||||
#define EFFECT_SCRAP_CHIMERA 246
|
||||
#define EFFECT_TUNE_MAGICIAN_X 247
|
||||
#define EFFECT_PRE_MONSTER 250
|
||||
#define EFFECT_MATERIAL_CHECK 251
|
||||
#define EFFECT_DISABLE_FIELD 260
|
||||
#define EFFECT_USE_EXTRA_MZONE 261
|
||||
#define EFFECT_USE_EXTRA_SZONE 262
|
||||
#define EFFECT_MAX_MZONE 263
|
||||
#define EFFECT_MAX_SZONE 264
|
||||
#define EFFECT_MUST_USE_MZONE 265
|
||||
#define EFFECT_HAND_LIMIT 270
|
||||
#define EFFECT_DRAW_COUNT 271
|
||||
#define EFFECT_SPIRIT_DONOT_RETURN 280
|
||||
#define EFFECT_SPIRIT_MAYNOT_RETURN 281
|
||||
#define EFFECT_CHANGE_ENVIRONMENT 290
|
||||
#define EFFECT_NECRO_VALLEY 291
|
||||
#define EFFECT_FORBIDDEN 292
|
||||
#define EFFECT_NECRO_VALLEY_IM 293
|
||||
#define EFFECT_REVERSE_DECK 294
|
||||
#define EFFECT_REMOVE_BRAINWASHING 295
|
||||
#define EFFECT_BP_TWICE 296
|
||||
#define EFFECT_UNIQUE_CHECK 297
|
||||
#define EFFECT_MATCH_KILL 300
|
||||
#define EFFECT_SYNCHRO_CHECK 310
|
||||
#define EFFECT_QP_ACT_IN_NTPHAND 311
|
||||
#define EFFECT_MUST_BE_SMATERIAL 312
|
||||
#define EFFECT_TO_GRAVE_REDIRECT_CB 313
|
||||
#define EFFECT_CHANGE_INVOLVING_BATTLE_DAMAGE 314
|
||||
//#define EFFECT_CHANGE_RANK_FINAL 315
|
||||
#define EFFECT_MUST_BE_FMATERIAL 316
|
||||
#define EFFECT_MUST_BE_XMATERIAL 317
|
||||
#define EFFECT_MUST_BE_LMATERIAL 318
|
||||
#define EFFECT_SPSUMMON_PROC_G 320
|
||||
#define EFFECT_SPSUMMON_COUNT_LIMIT 330
|
||||
#define EFFECT_LEFT_SPSUMMON_COUNT 331
|
||||
#define EFFECT_CANNOT_SELECT_BATTLE_TARGET 332
|
||||
#define EFFECT_CANNOT_SELECT_EFFECT_TARGET 333
|
||||
#define EFFECT_ADD_SETCODE 334
|
||||
#define EFFECT_NO_EFFECT_DAMAGE 335
|
||||
//#define EFFECT_UNSUMMONABLE_CARD 336
|
||||
#define EFFECT_DISCARD_COST_CHANGE 338
|
||||
#define EFFECT_HAND_SYNCHRO 339
|
||||
#define EFFECT_ADD_FUSION_CODE 340
|
||||
#define EFFECT_ADD_FUSION_SETCODE 341
|
||||
#define EFFECT_ONLY_ATTACK_MONSTER 343
|
||||
#define EFFECT_MUST_ATTACK_MONSTER 344
|
||||
#define EFFECT_PATRICIAN_OF_DARKNESS 345
|
||||
#define EFFECT_EXTRA_ATTACK_MONSTER 346
|
||||
#define EFFECT_UNION_STATUS 347
|
||||
#define EFFECT_OLDUNION_STATUS 348
|
||||
//#define EFFECT_ADD_FUSION_ATTRIBUTE 349
|
||||
//#define EFFECT_REMOVE_FUSION_ATTRIBUTE 350
|
||||
#define EFFECT_CHANGE_FUSION_ATTRIBUTE 351
|
||||
#define EFFECT_EXTRA_FUSION_MATERIAL 352
|
||||
#define EFFECT_TUNER_MATERIAL_LIMIT 353
|
||||
#define EFFECT_ADD_LINK_CODE 354
|
||||
//#define EFFECT_ADD_LINK_SETCODE 355
|
||||
#define EFFECT_ADD_LINK_ATTRIBUTE 356
|
||||
#define EFFECT_ADD_LINK_RACE 357
|
||||
#define EFFECT_EXTRA_LINK_MATERIAL 358
|
||||
#define EFFECT_QP_ACT_IN_SET_TURN 359
|
||||
#define EFFECT_EXTRA_PENDULUM_SUMMON 360
|
||||
#define EFFECT_MATERIAL_LIMIT 361
|
||||
#define EFFECT_SET_BATTLE_ATTACK 362
|
||||
#define EFFECT_SET_BATTLE_DEFENSE 363
|
||||
#define EFFECT_OVERLAY_RITUAL_MATERIAL 364
|
||||
#define EFFECT_CHANGE_GRAVE_ATTRIBUTE 365
|
||||
#define EFFECT_CHANGE_GRAVE_RACE 366
|
||||
#define EFFECT_ACTIVATION_COUNT_LIMIT 367
|
||||
#define EFFECT_LIMIT_SPECIAL_SUMMON_POSITION 368
|
||||
#define EFFECT_TUNER 369
|
||||
#define EFFECT_KAISER_COLOSSEUM 370
|
||||
#define EFFECT_REPLACE_DAMAGE 371
|
||||
#define EFFECT_XYZ_MIN_COUNT 372
|
||||
#define EFFECT_SYNCHRO_LEVEL_EX 373
|
||||
#define EFFECT_RITUAL_LEVEL_EX 374
|
||||
#define EFFECT_DOUBLE_XMATERIAL 375
|
||||
#define EFFECT_REVEAL_ONFIELD 376
|
||||
|
||||
//#define EVENT_STARTUP 1000
|
||||
#define EVENT_FLIP 1001
|
||||
#define EVENT_FREE_CHAIN 1002
|
||||
#define EVENT_DESTROY 1010
|
||||
#define EVENT_REMOVE 1011
|
||||
#define EVENT_TO_HAND 1012
|
||||
#define EVENT_TO_DECK 1013
|
||||
#define EVENT_TO_GRAVE 1014
|
||||
#define EVENT_LEAVE_FIELD 1015
|
||||
#define EVENT_CHANGE_POS 1016
|
||||
#define EVENT_RELEASE 1017
|
||||
#define EVENT_DISCARD 1018
|
||||
#define EVENT_LEAVE_FIELD_P 1019
|
||||
#define EVENT_CHAIN_SOLVING 1020
|
||||
#define EVENT_CHAIN_ACTIVATING 1021
|
||||
#define EVENT_CHAIN_SOLVED 1022
|
||||
//#define EVENT_CHAIN_ACTIVATED 1023
|
||||
#define EVENT_CHAIN_NEGATED 1024
|
||||
#define EVENT_CHAIN_DISABLED 1025
|
||||
#define EVENT_CHAIN_END 1026
|
||||
#define EVENT_CHAINING 1027
|
||||
#define EVENT_BECOME_TARGET 1028
|
||||
#define EVENT_DESTROYED 1029
|
||||
#define EVENT_MOVE 1030
|
||||
#define EVENT_LEAVE_GRAVE 1031
|
||||
#define EVENT_LEAVE_DECK 1032
|
||||
#define EVENT_ADJUST 1040
|
||||
#define EVENT_BREAK_EFFECT 1050
|
||||
#define EVENT_SUMMON_SUCCESS 1100
|
||||
#define EVENT_FLIP_SUMMON_SUCCESS 1101
|
||||
#define EVENT_SPSUMMON_SUCCESS 1102
|
||||
#define EVENT_SUMMON 1103
|
||||
#define EVENT_FLIP_SUMMON 1104
|
||||
#define EVENT_SPSUMMON 1105
|
||||
#define EVENT_MSET 1106
|
||||
#define EVENT_SSET 1107
|
||||
#define EVENT_BE_MATERIAL 1108
|
||||
#define EVENT_BE_PRE_MATERIAL 1109
|
||||
#define EVENT_DRAW 1110
|
||||
#define EVENT_DAMAGE 1111
|
||||
#define EVENT_RECOVER 1112
|
||||
#define EVENT_PREDRAW 1113
|
||||
#define EVENT_SUMMON_NEGATED 1114
|
||||
#define EVENT_FLIP_SUMMON_NEGATED 1115
|
||||
#define EVENT_SPSUMMON_NEGATED 1116
|
||||
#define EVENT_SPSUMMON_SUCCESS_G_P 1117
|
||||
#define EVENT_CONTROL_CHANGED 1120
|
||||
#define EVENT_EQUIP 1121
|
||||
#define EVENT_ATTACK_ANNOUNCE 1130
|
||||
#define EVENT_BE_BATTLE_TARGET 1131
|
||||
#define EVENT_BATTLE_START 1132
|
||||
#define EVENT_BATTLE_CONFIRM 1133
|
||||
#define EVENT_PRE_DAMAGE_CALCULATE 1134
|
||||
//#define EVENT_DAMAGE_CALCULATING 1135
|
||||
#define EVENT_PRE_BATTLE_DAMAGE 1136
|
||||
//#define EVENT_BATTLE_END 1137
|
||||
#define EVENT_BATTLED 1138
|
||||
#define EVENT_BATTLE_DESTROYING 1139
|
||||
#define EVENT_BATTLE_DESTROYED 1140
|
||||
#define EVENT_DAMAGE_STEP_END 1141
|
||||
#define EVENT_ATTACK_DISABLED 1142
|
||||
#define EVENT_BATTLE_DAMAGE 1143
|
||||
#define EVENT_TOSS_DICE 1150
|
||||
#define EVENT_TOSS_COIN 1151
|
||||
#define EVENT_TOSS_COIN_NEGATE 1152
|
||||
#define EVENT_TOSS_DICE_NEGATE 1153
|
||||
#define EVENT_LEVEL_UP 1200
|
||||
#define EVENT_PAY_LPCOST 1201
|
||||
#define EVENT_DETACH_MATERIAL 1202
|
||||
#define EVENT_TURN_END 1210
|
||||
#define EVENT_PHASE 0x1000
|
||||
#define EVENT_PHASE_START 0x2000
|
||||
#define EVENT_ADD_COUNTER 0x10000
|
||||
#define EVENT_REMOVE_COUNTER 0x20000
|
||||
#define EVENT_CUSTOM 0x10000000
|
||||
|
||||
constexpr int32_t DOUBLE_DAMAGE = INT32_MIN;
|
||||
constexpr int32_t HALF_DAMAGE = INT32_MIN + 1;
|
||||
|
||||
constexpr uint32_t MAX_PARAMETER = 0xffffU;
|
||||
constexpr uint32_t MAX_XYZ_LEVEL = 0x0fffU;
|
||||
|
||||
// flag effect
|
||||
#define EFFECT_FLAG_EFFECT 0x20000000U
|
||||
#define MAX_CARD_ID 0x0fffffffU
|
||||
|
||||
// The type of effect code
|
||||
enum code_type : int32_t {
|
||||
CODE_CUSTOM = 1, // header + id (28 bits)
|
||||
CODE_COUNTER, // header + counter_id (16 bits)
|
||||
CODE_PHASE, // header + phase_id (12 bits)
|
||||
CODE_VALUE, // numeric value, max = 4095
|
||||
};
|
||||
|
||||
const std::unordered_set<uint32_t> continuous_event{
|
||||
EVENT_ADJUST,
|
||||
EVENT_BREAK_EFFECT,
|
||||
EVENT_TURN_END,
|
||||
EVENT_PRE_BATTLE_DAMAGE,
|
||||
EVENT_SPSUMMON_SUCCESS_G_P,
|
||||
};
|
||||
|
||||
const std::unordered_set<uint32_t> affect_summoning_effect{
|
||||
EFFECT_CANNOT_DISABLE_SUMMON,
|
||||
EFFECT_CANNOT_DISABLE_SPSUMMON,
|
||||
EVENT_BE_PRE_MATERIAL,
|
||||
};
|
||||
|
||||
#endif /* EFFECT_H_ */
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* effectset.h
|
||||
*
|
||||
* Created on: 2011-10-8
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef EFFECTSET_H_
|
||||
#define EFFECTSET_H_
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
class effect;
|
||||
|
||||
bool effect_sort_id(const effect* e1, const effect* e2);
|
||||
|
||||
using effect_set = std::vector<effect*>;
|
||||
using effect_set_v = effect_set;
|
||||
|
||||
#endif //EFFECTSET_H_
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
extern "C" EMSCRIPTEN_KEEPALIVE void ocgcore_shutdown(int code) {
|
||||
emscripten_force_exit(code);
|
||||
}
|
||||
#endif
|
||||
+3711
File diff suppressed because it is too large.
Load diff
+858
@@ -0,0 +1,858 @@
|
||||
/*
|
||||
* field.h
|
||||
*
|
||||
* Created on: 2010-5-8
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef FIELD_H_
|
||||
#define FIELD_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "card.h"
|
||||
#include "effectset.h"
|
||||
#include "interpreter.h"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#define MAX_COIN_COUNT 20
|
||||
|
||||
//summon action type
|
||||
#define SUMMON_IN_IDLE 0
|
||||
#define SUMMON_IN_CHAIN 1
|
||||
|
||||
class card;
|
||||
struct card_data;
|
||||
class duel;
|
||||
class group;
|
||||
class effect;
|
||||
|
||||
using effect_vector = std::vector<effect*>;
|
||||
|
||||
struct tevent {
|
||||
card* trigger_card{ nullptr };
|
||||
group* event_cards{ nullptr };
|
||||
effect* reason_effect{ nullptr };
|
||||
uint32_t event_code{ 0 };
|
||||
uint32_t event_value{ 0 };
|
||||
uint32_t reason{ 0 };
|
||||
uint8_t event_player{ PLAYER_NONE };
|
||||
uint8_t reason_player{ PLAYER_NONE };
|
||||
|
||||
bool operator< (const tevent& v) const;
|
||||
};
|
||||
struct optarget {
|
||||
group* op_cards{ nullptr };
|
||||
uint8_t op_count{ 0 };
|
||||
uint8_t op_player{ PLAYER_NONE };
|
||||
int32_t op_param{ 0 };
|
||||
};
|
||||
struct chain {
|
||||
using opmap = std::unordered_map<uint32_t, optarget>;
|
||||
uint16_t chain_id{ 0 };
|
||||
uint8_t chain_count{ 0 };
|
||||
uint8_t triggering_player{ PLAYER_NONE };
|
||||
uint8_t triggering_controler{ PLAYER_NONE };
|
||||
uint16_t triggering_location{ 0 };
|
||||
uint8_t triggering_sequence{ 0 };
|
||||
uint8_t triggering_position{ 0 };
|
||||
card_state triggering_state;
|
||||
effect* triggering_effect{ nullptr };
|
||||
group* target_cards{ nullptr };
|
||||
int32_t replace_op{ 0 };
|
||||
uint8_t target_player{ PLAYER_NONE };
|
||||
int32_t target_param{ 0 };
|
||||
effect* disable_reason{ nullptr };
|
||||
uint8_t disable_player{ PLAYER_NONE };
|
||||
tevent evt;
|
||||
opmap opinfos;
|
||||
uint32_t flag{ 0 };
|
||||
effect_set required_handorset_effects;
|
||||
metadata meta;
|
||||
|
||||
static bool chain_operation_sort(const chain& c1, const chain& c2);
|
||||
void set_triggering_state(card* pcard);
|
||||
};
|
||||
|
||||
struct player_info {
|
||||
int32_t lp{ 8000 };
|
||||
int32_t start_count{ 5 };
|
||||
int32_t draw_count{ 1 };
|
||||
uint32_t used_location{ 0 };
|
||||
uint32_t disabled_location{ 0 };
|
||||
uint32_t extra_p_count{ 0 };
|
||||
uint32_t tag_extra_p_count{ 0 };
|
||||
int32_t szone_size{ 6 };
|
||||
card_vector list_mzone;
|
||||
card_vector list_szone;
|
||||
card_vector list_main;
|
||||
card_vector list_grave;
|
||||
card_vector list_hand;
|
||||
card_vector list_remove;
|
||||
card_vector list_extra;
|
||||
card_vector tag_list_main;
|
||||
card_vector tag_list_hand;
|
||||
card_vector tag_list_extra;
|
||||
};
|
||||
struct field_effect {
|
||||
using oath_effects = std::unordered_map<effect*, effect*>;
|
||||
using gain_effects = std::unordered_map<card*, effect*>;
|
||||
using grant_effect_container = std::unordered_map<effect*, gain_effects>;
|
||||
|
||||
effect_container aura_effect;
|
||||
effect_container ignition_effect;
|
||||
effect_container activate_effect;
|
||||
effect_container trigger_o_effect;
|
||||
effect_container trigger_f_effect;
|
||||
effect_container quick_o_effect;
|
||||
effect_container quick_f_effect;
|
||||
effect_container continuous_effect;
|
||||
effect_indexer indexer;
|
||||
oath_effects oath;
|
||||
effect_collection pheff;
|
||||
effect_collection cheff;
|
||||
effect_collection rechargeable;
|
||||
effect_collection spsummon_count_eff;
|
||||
|
||||
std::list<card*> disable_check_list;
|
||||
std::unordered_set<card*> disable_check_set;
|
||||
|
||||
grant_effect_container grant_effect;
|
||||
};
|
||||
struct field_info {
|
||||
uint64_t card_id{ 1 };
|
||||
int32_t field_id{ 1 };
|
||||
uint16_t copy_id{ 1 };
|
||||
uint16_t turn_id{};
|
||||
uint16_t turn_id_by_player[2]{};
|
||||
uint16_t phase{};
|
||||
uint8_t turn_player{};
|
||||
uint8_t priorities[2]{};
|
||||
uint8_t can_shuffle{ TRUE };
|
||||
};
|
||||
struct lpcost {
|
||||
int32_t count{};
|
||||
int32_t amount{};
|
||||
int32_t lpstack[8]{};
|
||||
};
|
||||
struct processor_unit {
|
||||
uint16_t type{ 0 };
|
||||
uint16_t step{ 0 };
|
||||
effect* peffect{ nullptr };
|
||||
group* ptarget{ nullptr };
|
||||
uint32_t arg1{ 0 };
|
||||
uint32_t arg2{ 0 };
|
||||
uint32_t arg3{ 0 };
|
||||
uint32_t arg4{ 0 };
|
||||
int32_t value1{ 0 };
|
||||
int32_t value2{ 0 };
|
||||
int32_t value3{ 0 };
|
||||
int32_t value4{ 0 };
|
||||
void* ptr1{ nullptr };
|
||||
void* ptr2{ nullptr };
|
||||
void* ptr3{ nullptr };
|
||||
void* ptr4{ nullptr };
|
||||
};
|
||||
constexpr size_t SIZE_SVALUE = SIZE_RETURN_VALUE / 2;
|
||||
constexpr size_t SIZE_IVALUE = SIZE_RETURN_VALUE / 4;
|
||||
constexpr size_t SIZE_LVALUE = SIZE_RETURN_VALUE / 8;
|
||||
union return_value {
|
||||
uint8_t bvalue[SIZE_RETURN_VALUE];
|
||||
uint16_t svalue[SIZE_SVALUE];
|
||||
int32_t ivalue[SIZE_IVALUE];
|
||||
int64_t lvalue[SIZE_LVALUE];
|
||||
};
|
||||
|
||||
using option_vector = std::vector<uint32_t>;
|
||||
using card_list = std::list<card*>;
|
||||
using event_list = std::list<tevent>;
|
||||
using chain_list = std::list<chain>;
|
||||
using instant_f_list = std::map<effect*, chain>;
|
||||
using chain_array = std::vector<chain>;
|
||||
using processor_list = std::list<processor_unit>;
|
||||
struct delayed_effect_sort {
|
||||
bool operator()(const std::pair<effect*, tevent>& lhs, const std::pair<effect*, tevent>& rhs) const;
|
||||
};
|
||||
using delayed_effect_collection = std::set<std::pair<effect*, tevent>, delayed_effect_sort>;
|
||||
using activity_map = std::unordered_map<int32_t, std::pair<int32_t, uint32_t>>; // (counter_id, (counter_filter, count[1]|count[0]))
|
||||
// [YGOL] patch 0022 (attack preview): what field::preview_battle answers for one attacker and one target.
|
||||
struct battle_preview {
|
||||
uint8_t attacker_destroyed{ FALSE };
|
||||
uint8_t target_destroyed{ FALSE };
|
||||
uint8_t pierce{ FALSE };
|
||||
int32_t attacker_value{ 0 };
|
||||
int32_t target_value{ 0 };
|
||||
int32_t damage[2]{};
|
||||
};
|
||||
struct processor {
|
||||
struct chain_limit_t {
|
||||
chain_limit_t(int32_t f, int32_t p): function(f), player(p) {}
|
||||
int32_t function{ 0 };
|
||||
int32_t player{ PLAYER_NONE };
|
||||
};
|
||||
using chain_limit_list = std::vector<chain_limit_t>;
|
||||
|
||||
processor_list units;
|
||||
processor_list subunits;
|
||||
processor_unit damage_step_reserved;
|
||||
processor_unit summon_reserved;
|
||||
card_vector select_cards;
|
||||
card_vector unselect_cards;
|
||||
card_vector summonable_cards;
|
||||
card_vector spsummonable_cards;
|
||||
card_vector repositionable_cards;
|
||||
card_vector msetable_cards;
|
||||
card_vector ssetable_cards;
|
||||
card_vector attackable_cards;
|
||||
effect_vector select_effects;
|
||||
option_vector select_options;
|
||||
card_vector must_select_cards;
|
||||
event_list point_event;
|
||||
event_list instant_event;
|
||||
event_list queue_event;
|
||||
event_list delayed_activate_event;
|
||||
event_list full_event;
|
||||
event_list used_event;
|
||||
event_list single_event;
|
||||
event_list solving_event;
|
||||
event_list sub_solving_event;
|
||||
chain_array select_chains;
|
||||
chain_array current_chain;
|
||||
chain_array ignition_priority_chains;
|
||||
chain_list continuous_chain;
|
||||
chain_list solving_continuous;
|
||||
chain_list sub_solving_continuous;
|
||||
chain_list delayed_continuous_tp;
|
||||
chain_list delayed_continuous_ntp;
|
||||
chain_list desrep_chain;
|
||||
chain_list new_fchain;
|
||||
chain_list new_fchain_s;
|
||||
chain_list new_ochain;
|
||||
chain_list new_ochain_s;
|
||||
chain_list new_fchain_b;
|
||||
chain_list new_ochain_b;
|
||||
chain_list new_ochain_h;
|
||||
chain_list new_chains;
|
||||
delayed_effect_collection delayed_quick_tmp;
|
||||
delayed_effect_collection delayed_quick;
|
||||
instant_f_list quick_f_chain;
|
||||
card_set leave_confirmed;
|
||||
card_set special_summoning;
|
||||
card_set unable_tofield_set;
|
||||
card_set equiping_cards;
|
||||
card_set control_adjust_set[2];
|
||||
card_set unique_destroy_set;
|
||||
card_set self_destroy_set;
|
||||
card_set self_tograve_set;
|
||||
card_set trap_monster_adjust_set[2];
|
||||
card_set release_cards;
|
||||
card_set release_cards_ex;
|
||||
card_set release_cards_ex_oneof;
|
||||
card_set battle_destroy_rep;
|
||||
card_set fusion_materials;
|
||||
card_set synchro_materials;
|
||||
card_set operated_set;
|
||||
card_set discarded_set;
|
||||
card_set destroy_canceled;
|
||||
card_set indestructable_count_set;
|
||||
card_set delayed_enable_set;
|
||||
card_set set_group_pre_set;
|
||||
card_set set_group_set;
|
||||
effect_set_v disfield_effects;
|
||||
effect_set_v extra_mzone_effects;
|
||||
effect_set_v extra_szone_effects;
|
||||
std::set<effect*> reseted_effects;
|
||||
std::unordered_map<card*, uint32_t> readjust_map;
|
||||
std::unordered_set<card*> unique_cards[2];
|
||||
std::unordered_map<uint32_t, int32_t> effect_count_code[3];
|
||||
std::unordered_map<uint32_t, int32_t> effect_count_code_duel[3];
|
||||
std::unordered_map<uint32_t, int32_t> effect_count_code_chain[3];
|
||||
std::unordered_map<uint32_t, uint32_t> spsummon_once_map[2];
|
||||
std::multimap<int32_t, card*, std::greater<int32_t>> xmaterial_lst;
|
||||
|
||||
int32_t temp_var[4]{};
|
||||
uint32_t global_flag{ 0 };
|
||||
uint16_t pre_field[2]{};
|
||||
std::set<uint16_t> opp_mzone;
|
||||
chain_limit_list chain_limit;
|
||||
chain_limit_list chain_limit_p;
|
||||
uint8_t chain_solving{ FALSE };
|
||||
uint8_t conti_solving{ FALSE };
|
||||
uint8_t win_player{ 5 };
|
||||
uint8_t win_reason{ 0 };
|
||||
uint8_t re_adjust{ FALSE };
|
||||
effect* reason_effect{ nullptr };
|
||||
uint8_t reason_player{ PLAYER_NONE };
|
||||
card* summoning_card{ nullptr };
|
||||
uint8_t summon_depth{ 0 };
|
||||
uint8_t summon_cancelable{ FALSE };
|
||||
card* attacker{ nullptr };
|
||||
card* attack_target{ nullptr };
|
||||
uint8_t attacker_player{ PLAYER_NONE };
|
||||
uint8_t attack_target_player{ PLAYER_NONE };
|
||||
uint32_t limit_extra_summon_zone{ 0 };
|
||||
uint32_t limit_extra_summon_releasable{ 0 };
|
||||
card* limit_tuner{ nullptr };
|
||||
group* limit_syn{ nullptr };
|
||||
int32_t limit_syn_minc{ 0 };
|
||||
int32_t limit_syn_maxc{ 0 };
|
||||
group* limit_xyz{ nullptr };
|
||||
int32_t limit_xyz_minc{ 0 };
|
||||
int32_t limit_xyz_maxc{ 0 };
|
||||
group* limit_link{ nullptr };
|
||||
card* limit_link_card{ nullptr };
|
||||
int32_t limit_link_minc{ 0 };
|
||||
int32_t limit_link_maxc{ 0 };
|
||||
uint8_t not_material{ FALSE };
|
||||
uint8_t attack_cancelable{ FALSE };
|
||||
uint8_t attack_rollback{ FALSE };
|
||||
uint8_t effect_damage_step{ 0 };
|
||||
int32_t battle_damage[2]{};
|
||||
int32_t summon_count[2]{};
|
||||
uint8_t extra_summon[2]{};
|
||||
int32_t spe_effect[2]{};
|
||||
int32_t last_select_hint[2]{ 0 };
|
||||
uint32_t duel_options{ 0 };
|
||||
int32_t duel_rule{ CURRENT_RULE };
|
||||
uint32_t copy_reset{ 0 };
|
||||
int32_t copy_reset_count{ 0 };
|
||||
uint32_t last_control_changed_id{ 0 };
|
||||
uint32_t set_group_used_zones{ 0 };
|
||||
uint8_t set_group_seq[7]{};
|
||||
uint8_t dice_result[5]{};
|
||||
uint32_t coin_result{ 0 };
|
||||
int32_t coin_count{ 0 };
|
||||
bool is_target_ready{ false };
|
||||
bool is_gemini_summoning{ false };
|
||||
bool is_summon_negated{ false };
|
||||
|
||||
uint8_t to_bp{ FALSE };
|
||||
uint8_t to_m2{ FALSE };
|
||||
uint8_t to_ep{ FALSE };
|
||||
uint8_t skip_m2{ FALSE };
|
||||
uint8_t chain_attack{ FALSE };
|
||||
uint32_t chain_attacker_id{ 0 };
|
||||
card* chain_attack_target{ nullptr };
|
||||
uint8_t attack_player{ PLAYER_NONE };
|
||||
uint8_t selfdes_disabled{ FALSE };
|
||||
uint8_t overdraw[2]{};
|
||||
int32_t check_level{ 0 };
|
||||
uint8_t shuffle_check_disabled{ FALSE };
|
||||
uint8_t shuffle_hand_check[2]{};
|
||||
uint8_t shuffle_deck_check[2]{};
|
||||
uint8_t deck_reversed{ FALSE };
|
||||
uint8_t remove_brainwashing{ FALSE };
|
||||
uint8_t flip_delayed{ FALSE };
|
||||
uint8_t damage_calculated{ FALSE };
|
||||
uint8_t hand_adjusted{ FALSE };
|
||||
uint8_t summon_state_count[2]{};
|
||||
uint8_t normalsummon_state_count[2]{};
|
||||
uint8_t flipsummon_state_count[2]{};
|
||||
uint8_t spsummon_state_count[2]{};
|
||||
uint8_t attack_state_count[2]{};
|
||||
uint8_t battle_phase_count[2]{};
|
||||
uint8_t battled_count[2]{};
|
||||
uint8_t phase_action{ FALSE };
|
||||
uint32_t hint_timing[2]{};
|
||||
uint8_t current_player{ PLAYER_NONE };
|
||||
uint8_t conti_player{ PLAYER_NONE };
|
||||
uint8_t select_deck_sequence_revealed{ FALSE };
|
||||
uint8_t selecting_player{ 0 };
|
||||
activity_map summon_counter;
|
||||
activity_map normalsummon_counter;
|
||||
activity_map spsummon_counter;
|
||||
activity_map flipsummon_counter;
|
||||
activity_map attack_counter;
|
||||
activity_map chain_counter;
|
||||
processor_list recover_damage_reserve;
|
||||
effect_vector dec_count_reserve;
|
||||
uint8_t announce_card_silent{ FALSE };
|
||||
};
|
||||
class field {
|
||||
public:
|
||||
duel* pduel{};
|
||||
player_info player[2];
|
||||
card* temp_card{};
|
||||
field_info infos;
|
||||
//lpcost cost[2];
|
||||
field_effect effects;
|
||||
processor core;
|
||||
return_value returns{};
|
||||
tevent nil_event;
|
||||
card* rose_card{};
|
||||
uint32_t rose_level{0};
|
||||
|
||||
static int32_t field_used_count[32];
|
||||
explicit field(duel* pd);
|
||||
~field() = default;
|
||||
void reload_field_info();
|
||||
|
||||
void add_card(uint8_t playerid, card* pcard, uint8_t location, uint8_t sequence, uint8_t pzone = FALSE);
|
||||
void remove_card(card* pcard);
|
||||
void move_card(uint8_t playerid, card* pcard, uint8_t location, uint8_t sequence, uint8_t pzone = FALSE);
|
||||
void swap_card(card* pcard1, card* pcard2, uint8_t new_sequence1, uint8_t new_sequence2);
|
||||
void swap_card(card* pcard1, card* pcard2);
|
||||
void set_control(card* pcard, uint8_t playerid, uint16_t reset_phase, uint8_t reset_count);
|
||||
|
||||
int32_t get_pzone_sequence(uint8_t pseq) const;
|
||||
const card_vector* get_field_vector(uint8_t playerid, uint8_t location) const;
|
||||
card* get_field_card(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
|
||||
int32_t is_location_useable(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
|
||||
int32_t get_useable_count(card* pcard, uint8_t playerid, uint8_t location, uint8_t uplayer, uint32_t reason, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_useable_count_fromex(card* pcard, uint8_t playerid, uint8_t uplayer, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_spsummonable_count(card* pcard, uint8_t playerid, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_spsummonable_count_fromex(card* pcard, uint8_t playerid, uint8_t uplayer, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_useable_count_other(card* pcard, uint8_t playerid, uint8_t location, uint8_t uplayer, uint32_t reason, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_tofield_count(card* pcard, uint8_t playerid, uint8_t location, uint32_t uplayer, uint32_t reason, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_useable_count_fromex_rule4(card* pcard, uint8_t playerid, uint8_t uplayer, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_spsummonable_count_fromex_rule4(card* pcard, uint8_t playerid, uint8_t uplayer, uint32_t zone = 0xff, uint32_t* list = nullptr);
|
||||
int32_t get_mzone_limit(uint8_t playerid, uint8_t uplayer, uint32_t reason);
|
||||
int32_t get_szone_limit(uint8_t playerid, uint8_t uplayer, uint32_t reason);
|
||||
uint32_t get_linked_zone(int32_t playerid);
|
||||
uint32_t get_rule_zone_fromex(int32_t playerid, card* pcard);
|
||||
void filter_must_use_mzone(uint8_t playerid, uint8_t uplayer, uint32_t reason, card* pcard, uint32_t* flag);
|
||||
void get_linked_cards(uint8_t self, uint8_t s, uint8_t o, card_set* cset);
|
||||
int32_t check_extra_link(int32_t playerid);
|
||||
int32_t check_extra_link(int32_t playerid, card* pcard, int32_t sequence);
|
||||
void get_cards_in_zone(card_set* cset, uint32_t zone, int32_t playerid, int32_t location);
|
||||
void shuffle(uint8_t playerid, uint8_t location);
|
||||
void reset_sequence(uint8_t playerid, uint8_t location);
|
||||
void swap_deck_and_grave(uint8_t playerid);
|
||||
void reverse_deck(uint8_t playerid);
|
||||
void refresh_player_info(uint8_t playerid);
|
||||
void tag_swap(uint8_t playerid);
|
||||
|
||||
void add_effect(effect* peffect, uint8_t owner_player = PLAYER_NONE);
|
||||
void remove_effect(effect* peffect);
|
||||
void remove_oath_effect(effect* reason_effect);
|
||||
void release_oath_relation(effect* reason_effect);
|
||||
void reset_phase(uint32_t phase);
|
||||
void reset_chain();
|
||||
void add_effect_code(uint32_t code, int32_t playerid);
|
||||
int32_t get_effect_code(uint32_t code, int32_t playerid);
|
||||
void dec_effect_code(uint32_t code, int32_t playerid);
|
||||
|
||||
void filter_field_effect(uint32_t code, effect_set* eset, uint8_t sort = TRUE);
|
||||
void filter_affected_cards(effect* peffect, card_set* cset);
|
||||
void filter_inrange_cards(effect* peffect, card_set* cset);
|
||||
void filter_player_effect(uint8_t playerid, uint32_t code, effect_set* eset, uint8_t sort = TRUE);
|
||||
int32_t filter_matching_card(lua_State* L, int32_t findex, uint8_t self, uint32_t location1, uint32_t location2, group* pgroup, card* pexception, group* pexgroup, uint32_t extraargs, card** pret = nullptr, int32_t fcount = 0, int32_t is_target = FALSE);
|
||||
int32_t filter_field_card(uint8_t self, uint32_t location, uint32_t location2, group* pgroup);
|
||||
effect* is_player_affected_by_effect(uint8_t playerid, uint32_t code);
|
||||
|
||||
int32_t get_release_list(lua_State* L, uint8_t playerid, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, int32_t use_con, int32_t use_hand, int32_t fun, int32_t exarg, card* exc, group* exg, uint32_t reason);
|
||||
int32_t check_release_list(lua_State* L, uint8_t playerid, int32_t count, int32_t use_con, int32_t use_hand, int32_t fun, int32_t exarg, card* exc, group* exg, uint32_t reason);
|
||||
int32_t get_summon_release_list(card* target, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, group* mg = nullptr, uint32_t ex = 0, uint32_t releasable = 0xff00ff, uint32_t pos = 0x1);
|
||||
int32_t get_summon_count_limit(uint8_t playerid);
|
||||
int32_t get_draw_count(uint8_t playerid);
|
||||
void get_ritual_material(uint8_t playerid, effect* peffect, card_set* material, uint8_t no_level = FALSE);
|
||||
void get_fusion_material(uint8_t playerid, card_set* material_all, card_set* material_base, uint32_t location);
|
||||
void ritual_release(const card_set& material);
|
||||
void get_xyz_material(lua_State* L, card* scard, int32_t findex, uint32_t lv, int32_t maxc, group* mg);
|
||||
void get_overlay_group(uint8_t self, uint8_t s, uint8_t o, card_set* pset);
|
||||
int32_t get_overlay_count(uint8_t self, uint8_t s, uint8_t o);
|
||||
void update_disable_check_list(effect* peffect);
|
||||
void add_to_disable_check_list(card* pcard);
|
||||
void adjust_disable_check_list();
|
||||
void adjust_self_destroy_set();
|
||||
void erase_grant_effect(effect* peffect);
|
||||
int32_t adjust_grant_effect();
|
||||
void add_unique_card(card* pcard);
|
||||
void remove_unique_card(card* pcard);
|
||||
effect* check_unique_onfield(card* pcard, uint8_t controler, uint8_t location, card* icard = nullptr);
|
||||
int32_t check_spsummon_once(card* pcard, uint8_t playerid);
|
||||
void check_card_counter(card* pcard, int32_t counter_type, int32_t playerid);
|
||||
void check_card_counter(group* pgroup, int32_t counter_type, int32_t playerid);
|
||||
void check_chain_counter(effect* peffect, int32_t playerid, int32_t chainid, bool cancel = false);
|
||||
void set_spsummon_counter(uint8_t playerid);
|
||||
int32_t check_spsummon_counter(uint8_t playerid, uint8_t ct = 1);
|
||||
bool is_select_hide_deck_sequence(uint8_t playerid);
|
||||
|
||||
int32_t check_lp_cost(uint8_t playerid, int32_t cost, uint32_t must_pay);
|
||||
void save_lp_cost() {}
|
||||
void restore_lp_cost() {}
|
||||
int32_t pay_lp_cost(uint32_t step, uint8_t playerid, uint32_t cost, uint32_t must_pay);
|
||||
|
||||
uint32_t get_field_counter(uint8_t self, uint8_t s, uint8_t o, uint16_t countertype);
|
||||
int32_t effect_replace_check(uint32_t code, const tevent& e);
|
||||
int32_t get_attack_target(card* pcard, card_vector* v, uint8_t chain_attack = FALSE, bool select_target = true);
|
||||
bool confirm_attack_target();
|
||||
void attack_all_target_check();
|
||||
int32_t get_must_material_list(uint8_t playerid, uint32_t limit, card_set* must_list);
|
||||
int32_t check_must_material(group* mg, uint8_t playerid, uint32_t limit);
|
||||
void get_synchro_material(uint8_t playerid, card_set* material, effect* tuner_limit = nullptr);
|
||||
|
||||
//check material
|
||||
int32_t check_synchro_material(lua_State* L, card* pcard, int32_t findex1, int32_t findex2, int32_t min, int32_t max, card* smat, group* mg);
|
||||
int32_t check_tuner_material(lua_State* L, card* pcard, card* tuner, int32_t findex1, int32_t findex2, int32_t min, int32_t max, card* smat, group* mg);
|
||||
int32_t check_other_synchro_material(const card_vector& nsyn, int32_t lv, int32_t min, int32_t max, int32_t mcount);
|
||||
int32_t check_tribute(card* pcard, int32_t min, int32_t max, group* mg, uint8_t toplayer, uint32_t zone = 0x1f, uint32_t releasable = 0xff00ff, uint32_t pos = 0x1);
|
||||
static void get_sum_params(uint32_t sum_param, int32_t& op1, int32_t& op2);
|
||||
static int32_t check_with_sum_limit(const card_vector& mats, int32_t acc, int32_t index, int32_t count, int32_t min, int32_t max, int32_t opmin);
|
||||
static int32_t check_with_sum_limit_m(const card_vector& mats, int32_t acc, int32_t index, int32_t min, int32_t max, int32_t opmin, int32_t must_count);
|
||||
static int32_t check_with_sum_greater_limit(const card_vector& mats, int32_t acc, int32_t index, int32_t opmin);
|
||||
static int32_t check_with_sum_greater_limit_m(const card_vector& mats, int32_t acc, int32_t index, int32_t opmin, int32_t must_count);
|
||||
int32_t check_xyz_material(lua_State* L, card* pcard, int32_t findex, int32_t lv, int32_t min, int32_t max, group* mg);
|
||||
|
||||
int32_t is_player_can_draw(uint8_t playerid);
|
||||
int32_t is_player_can_discard_deck(uint8_t playerid, int32_t count);
|
||||
int32_t is_player_can_discard_deck_as_cost(uint8_t playerid, int32_t count);
|
||||
int32_t is_player_can_discard_hand(uint8_t playerid, card* pcard, effect* reason_effect, uint32_t reason);
|
||||
int32_t is_player_can_action(uint8_t playerid, uint32_t actionlimit);
|
||||
int32_t is_player_can_summon(uint32_t sumtype, uint8_t playerid, card* pcard, uint8_t toplayer);
|
||||
int32_t is_player_can_mset(uint32_t sumtype, uint8_t playerid, card* pcard, uint8_t toplayer);
|
||||
int32_t is_player_can_sset(uint8_t playerid, card* pcard);
|
||||
int32_t is_player_can_spsummon(uint8_t playerid);
|
||||
int32_t is_player_can_spsummon(effect* reason_effect, uint32_t sumtype, uint8_t sumpos, uint8_t playerid, uint8_t toplayer, card* pcard);
|
||||
int32_t is_player_can_flipsummon(uint8_t playerid, card* pcard);
|
||||
int32_t is_player_can_spsummon_monster(uint8_t playerid, uint8_t toplayer, uint8_t sumpos, uint32_t sumtype, card_data* pdata);
|
||||
int32_t is_player_can_spsummon_count(uint8_t playerid, uint32_t count);
|
||||
int32_t is_player_can_release(uint8_t playerid, card* pcard, uint32_t reason);
|
||||
int32_t is_player_can_place_counter(uint8_t playerid, card* pcard, uint16_t countertype, uint16_t count);
|
||||
int32_t is_player_can_remove_counter(uint8_t playerid, card* pcard, uint8_t s, uint8_t o, uint16_t countertype, uint16_t count, uint32_t reason);
|
||||
int32_t is_player_can_remove_overlay_card(uint8_t playerid, card* pcard, uint8_t s, uint8_t o, uint16_t count, uint32_t reason);
|
||||
int32_t is_player_can_send_to_grave(uint8_t playerid, card* pcard);
|
||||
int32_t is_player_can_send_to_hand(uint8_t playerid, card* pcard);
|
||||
int32_t is_player_can_send_to_deck(uint8_t playerid, card* pcard);
|
||||
int32_t is_player_can_remove(uint8_t playerid, card* pcard, uint32_t reason, effect* reason_effect = nullptr);
|
||||
int32_t is_chain_negatable(uint8_t chaincount);
|
||||
int32_t is_chain_disablable(uint8_t chaincount);
|
||||
int32_t is_chain_disabled(uint8_t chaincount);
|
||||
int32_t check_chain_target(uint8_t chaincount, card* pcard);
|
||||
chain* get_chain(uint32_t chaincount);
|
||||
int32_t get_cteffect(effect* peffect, int32_t playerid, int32_t store);
|
||||
int32_t get_cteffect_evt(effect* feffect, int32_t playerid, const tevent& e, int32_t store);
|
||||
int32_t check_cteffect_hint(effect* peffect, uint8_t playerid);
|
||||
int32_t check_nonpublic_trigger(chain& ch);
|
||||
int32_t check_trigger_effect(const chain& ch) const;
|
||||
int32_t check_spself_from_hand_trigger(const chain& ch) const;
|
||||
int32_t is_able_to_enter_bp();
|
||||
|
||||
void add_process(uint16_t type, uint16_t step, effect* peffect, group* target, int32_t arg1, int32_t arg2, int32_t arg3 = 0, int32_t arg4 = 0, void* ptr1 = nullptr, void* ptr2 = nullptr);
|
||||
uint32_t process();
|
||||
int32_t execute_cost(uint16_t step, effect* peffect, uint8_t triggering_player);
|
||||
int32_t execute_operation(uint16_t step, effect* peffect, uint8_t triggering_player);
|
||||
int32_t execute_target(uint16_t step, effect* peffect, uint8_t triggering_player);
|
||||
void raise_event(card* event_card, uint32_t event_code, effect* reason_effect, uint32_t reason, uint8_t reason_player, uint8_t event_player, uint32_t event_value);
|
||||
void raise_event(const card_set& event_cards, uint32_t event_code, effect* reason_effect, uint32_t reason, uint8_t reason_player, uint8_t event_player, uint32_t event_value);
|
||||
void raise_single_event(card* trigger_card, card_set* event_cards, uint32_t event_code, effect* reason_effect, uint32_t reason, uint8_t reason_player, uint8_t event_player, uint32_t event_value);
|
||||
int32_t check_event(uint32_t code, tevent* pe = nullptr);
|
||||
int32_t check_event_c(effect* peffect, uint8_t playerid, int32_t neglect_con, int32_t neglect_cost, int32_t copy_info, tevent* pe = nullptr);
|
||||
int32_t check_hint_timing(effect* peffect);
|
||||
int32_t process_phase_event(int16_t step, int32_t phase_event);
|
||||
int32_t process_point_event(int16_t step, int32_t skip_trigger, int32_t skip_freechain, int32_t skip_new);
|
||||
int32_t process_quick_effect(int16_t step, int32_t skip_freechain, uint8_t priority);
|
||||
int32_t process_instant_event();
|
||||
int32_t process_single_event();
|
||||
int32_t process_single_event(effect* peffect, const tevent& e, chain_list& tp, chain_list& ntp);
|
||||
int32_t process_idle_command(uint16_t step);
|
||||
int32_t process_battle_command(uint16_t step);
|
||||
int32_t process_damage_step(uint16_t step, uint32_t new_attack);
|
||||
void calculate_battle_damage(effect** pdamchange, card** preason_card, uint8_t* battle_destroyed);
|
||||
void preview_battle(card* attacker, card* target, battle_preview* out);
|
||||
int32_t process_turn(uint16_t step, uint8_t turn_player);
|
||||
|
||||
int32_t add_chain(uint16_t step);
|
||||
void solve_continuous(uint8_t playerid, effect* peffect, const tevent& e);
|
||||
int32_t solve_continuous(uint16_t step);
|
||||
int32_t solve_chain(uint16_t step, uint32_t chainend_arg1, uint32_t chainend_arg2);
|
||||
int32_t break_effect();
|
||||
void adjust_instant();
|
||||
void adjust_all();
|
||||
void refresh_location_info_instant();
|
||||
int32_t refresh_location_info(uint16_t step);
|
||||
int32_t adjust_step(uint16_t step);
|
||||
|
||||
//operations
|
||||
int32_t negate_chain(uint8_t chaincount);
|
||||
int32_t disable_chain(uint8_t chaincount, uint8_t forced);
|
||||
void change_chain_effect(uint8_t chaincount, int32_t replace_op);
|
||||
void change_target(uint8_t chaincount, group* targets);
|
||||
void change_target_player(uint8_t chaincount, uint8_t playerid);
|
||||
void change_target_param(uint8_t chaincount, int32_t param);
|
||||
void remove_counter(uint32_t reason, card* pcard, uint32_t rplayer, uint32_t s, uint32_t o, uint32_t countertype, uint32_t count);
|
||||
void remove_overlay_card(uint32_t reason, card* pcard, uint32_t rplayer, uint32_t s, uint32_t o, uint16_t min, uint16_t max);
|
||||
void get_control(const card_set& targets, effect* reason_effect, uint32_t reason_player, uint32_t playerid, uint32_t reset_phase, uint32_t reset_count, uint32_t zone);
|
||||
void get_control(card* target, effect* reason_effect, uint32_t reason_player, uint32_t playerid, uint32_t reset_phase, uint32_t reset_count, uint32_t zone);
|
||||
void swap_control(effect* reason_effect, uint32_t reason_player, const card_set& targets1, const card_set& targets2, uint32_t reset_phase, uint32_t reset_count);
|
||||
void swap_control(effect* reason_effect, uint32_t reason_player, card* pcard1, card* pcard2, uint32_t reset_phase, uint32_t reset_count);
|
||||
void equip(uint32_t equip_player, card* equip_card, card* target, uint32_t up, uint32_t is_step);
|
||||
void draw(effect* reason_effect, uint32_t reason, uint32_t reason_player, uint32_t playerid, int32_t count);
|
||||
void damage(effect* reason_effect, uint32_t reason, uint32_t reason_player, card* reason_card, uint32_t playerid, int32_t amount, uint32_t is_step = FALSE);
|
||||
void recover(effect* reason_effect, uint32_t reason, uint32_t reason_player, uint32_t playerid, int32_t amount, uint32_t is_step = FALSE);
|
||||
void summon(uint32_t sumplayer, card* target, effect* proc, uint32_t ignore_count, uint32_t min_tribute, uint32_t zone = 0x1f, uint32_t action_type = SUMMON_IN_IDLE);
|
||||
void mset(uint32_t setplayer, card* target, effect* proc, uint32_t ignore_count, uint32_t min_tribute, uint32_t zone = 0x1f, uint32_t action_type = SUMMON_IN_IDLE);
|
||||
void special_summon_rule(uint32_t sumplayer, card* target, uint32_t summon_type, uint32_t action_type = SUMMON_IN_IDLE);
|
||||
void special_summon(const card_set& target, uint32_t sumtype, uint32_t sumplayer, uint32_t playerid, uint32_t nocheck, uint32_t nolimit, uint32_t positions, uint32_t zone);
|
||||
void special_summon_step(card* target, uint32_t sumtype, uint32_t sumplayer, uint32_t playerid, uint32_t nocheck, uint32_t nolimit, uint32_t positions, uint32_t zone);
|
||||
void special_summon_complete(effect* reason_effect, uint8_t reason_player);
|
||||
void destroy(card_set& targets, effect* reason_effect, uint32_t reason, uint32_t reason_player, uint32_t playerid = 2, uint32_t destination = 0, uint32_t sequence = 0);
|
||||
void destroy(card* target, effect* reason_effect, uint32_t reason, uint32_t reason_player, uint32_t playerid = 2, uint32_t destination = 0, uint32_t sequence = 0);
|
||||
void release(const card_set& targets, effect* reason_effect, uint32_t reason, uint32_t reason_player);
|
||||
void release(card* target, effect* reason_effect, uint32_t reason, uint32_t reason_player);
|
||||
void send_to(const card_set& targets, effect* reason_effect, uint32_t reason, uint32_t reason_player, uint32_t playerid, uint32_t destination, uint32_t sequence, uint32_t position, uint8_t send_activating = FALSE);
|
||||
void send_to(card* target, effect* reason_effect, uint32_t reason, uint32_t reason_player, uint32_t playerid, uint32_t destination, uint32_t sequence, uint32_t position, uint8_t send_activating = FALSE);
|
||||
void move_to_field(card* target, uint32_t move_player, uint32_t playerid, uint32_t destination, uint32_t positions, uint32_t enable = FALSE, uint32_t ret = 0, uint32_t pzone = FALSE, uint32_t zone = 0xff);
|
||||
void change_position(const card_set& targets, effect* reason_effect, uint32_t reason_player, uint32_t au, uint32_t ad, uint32_t du, uint32_t dd, uint32_t flag, uint32_t enable = FALSE);
|
||||
void change_position(card* target, effect* reason_effect, uint32_t reason_player, uint32_t npos, uint32_t flag, uint32_t enable = FALSE);
|
||||
void operation_replace(int32_t type, int32_t step, group* targets);
|
||||
void select_tribute_cards(card* target, uint8_t playerid, uint8_t cancelable, int32_t min, int32_t max, uint8_t toplayer, uint32_t zone);
|
||||
|
||||
// summon
|
||||
int32_t summon(uint16_t step, uint8_t sumplayer, card* target, effect* proc, uint8_t ignore_count, uint8_t min_tribute, uint32_t zone, uint32_t action_type);
|
||||
int32_t mset(uint16_t step, uint8_t setplayer, card* ptarget, effect* proc, uint8_t ignore_count, uint8_t min_tribute, uint32_t zone, uint32_t action_type);
|
||||
int32_t flip_summon(uint16_t step, uint8_t sumplayer, card* target, uint32_t action_type);
|
||||
int32_t special_summon_rule(uint16_t step, uint8_t sumplayer, card* target, uint32_t summon_type, uint32_t action_type);
|
||||
|
||||
int32_t remove_counter(uint16_t step, uint32_t reason, card* pcard, uint8_t rplayer, uint8_t s, uint8_t o, uint16_t countertype, uint16_t count);
|
||||
int32_t remove_overlay_card(uint16_t step, uint32_t reason, card* pcard, uint8_t rplayer, uint8_t s, uint8_t o, uint16_t min, uint16_t max);
|
||||
int32_t get_control(uint16_t step, effect* reason_effect, uint8_t reason_player, group* targets, uint8_t playerid, uint16_t reset_phase, uint8_t reset_count, uint32_t zone);
|
||||
int32_t swap_control(uint16_t step, effect* reason_effect, uint8_t reason_player, group* targets1, group* targets2, uint16_t reset_phase, uint8_t reset_count);
|
||||
int32_t self_destroy(uint16_t step, card* ucard, int32_t p);
|
||||
int32_t trap_monster_adjust(uint16_t step);
|
||||
int32_t equip(uint16_t step, uint8_t equip_player, card* equip_card, card* target, uint32_t up, uint32_t is_step);
|
||||
int32_t draw(uint16_t step, effect* reason_effect, uint32_t reason, uint8_t reason_player, uint8_t playerid, int32_t count);
|
||||
int32_t damage(uint16_t step, effect* reason_effect, uint32_t reason, uint8_t reason_player, card* reason_card, uint8_t playerid, int32_t amount, uint32_t is_step);
|
||||
int32_t recover(uint16_t step, effect* reason_effect, uint32_t reason, uint8_t reason_player, uint8_t playerid, int32_t amount, uint32_t is_step);
|
||||
int32_t sset(uint16_t step, uint8_t setplayer, uint8_t toplayer, card* ptarget, effect* reason_effect, uint32_t zone = 0xff);
|
||||
int32_t sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group* ptarget, uint8_t confirm, effect* reason_effect, uint32_t zone = 0xff);
|
||||
int32_t special_summon_step(uint16_t step, group* targets, card* target, uint32_t zone);
|
||||
int32_t special_summon(uint16_t step, effect* reason_effect, uint8_t reason_player, group* targets, uint32_t zone);
|
||||
int32_t destroy_replace(uint16_t step, group* targets, card* target, uint8_t battle);
|
||||
int32_t destroy(uint16_t step, group* targets, effect* reason_effect, uint32_t reason, uint8_t reason_player);
|
||||
int32_t release_replace(uint16_t step, group* targets, card* target);
|
||||
int32_t release(uint16_t step, group* targets, effect* reason_effect, uint32_t reason, uint8_t reason_player);
|
||||
int32_t send_replace(uint16_t step, group* targets, card* target);
|
||||
int32_t send_to(uint16_t step, group* targets, effect* reason_effect, uint32_t reason, uint8_t reason_player, uint8_t send_activating);
|
||||
int32_t discard_deck(uint16_t step, uint8_t playerid, uint8_t count, uint32_t reason);
|
||||
int32_t move_to_field(uint16_t step, card* target, uint32_t enable, uint32_t ret, uint32_t pzone, uint32_t zone);
|
||||
int32_t change_position(uint16_t step, group* targets, effect* reason_effect, uint8_t reason_player, uint32_t enable);
|
||||
int32_t operation_replace(uint16_t step, effect* replace_effect, group* targets, card* target, int32_t is_destroy);
|
||||
int32_t activate_effect(uint16_t step, effect* peffect);
|
||||
int32_t select_synchro_material(int16_t step, uint8_t playerid, card* pcard, int32_t min, int32_t max, card* smat, group* mg, int32_t filter1, int32_t filter2);
|
||||
int32_t select_xyz_material(int16_t step, uint8_t playerid, uint32_t lv, card* pcard, int32_t min, int32_t max);
|
||||
int32_t select_release_cards(int16_t step, uint8_t playerid, uint8_t cancelable, int32_t min, int32_t max);
|
||||
int32_t select_tribute_cards(int16_t step, card* target, uint8_t playerid, uint8_t cancelable, int32_t min, int32_t max, uint8_t toplayer, uint32_t zone);
|
||||
int32_t toss_coin(uint16_t step, effect* reason_effect, uint8_t reason_player, uint8_t playerid, int32_t count);
|
||||
int32_t toss_dice(uint16_t step, effect* reason_effect, uint8_t reason_player, uint8_t playerid, uint8_t count1, uint8_t count2);
|
||||
int32_t rock_paper_scissors(uint16_t step, uint8_t repeat);
|
||||
|
||||
bool check_response(size_t vector_size, int32_t min_len, int32_t max_len) const;
|
||||
int32_t select_battle_command(uint16_t step, uint8_t playerid);
|
||||
int32_t select_idle_command(uint16_t step, uint8_t playerid);
|
||||
int32_t select_effect_yes_no(uint16_t step, uint8_t playerid, uint32_t description, card* pcard);
|
||||
int32_t select_yes_no(uint16_t step, uint8_t playerid, uint32_t description);
|
||||
int32_t select_option(uint16_t step, uint8_t playerid);
|
||||
int32_t select_card(uint16_t step, uint8_t playerid, uint8_t cancelable, uint8_t min, uint8_t max);
|
||||
int32_t select_unselect_card(uint16_t step, uint8_t playerid, uint8_t cancelable, uint8_t min, uint8_t max, uint8_t finishable);
|
||||
int32_t select_chain(uint16_t step, uint8_t playerid, uint8_t spe_count);
|
||||
int32_t select_place(uint16_t step, uint8_t playerid, uint32_t flag, uint8_t count);
|
||||
int32_t select_position(uint16_t step, uint8_t playerid, uint32_t code, uint8_t positions);
|
||||
int32_t select_tribute(uint16_t step, uint8_t playerid, uint8_t cancelable, uint8_t min, uint8_t max);
|
||||
int32_t select_counter(uint16_t step, uint8_t playerid, uint16_t countertype, uint16_t count, uint8_t s, uint8_t o);
|
||||
int32_t select_with_sum_limit(int16_t step, uint8_t playerid, int32_t acc, int32_t min, int32_t max);
|
||||
int32_t sort_card(int16_t step, uint8_t playerid);
|
||||
int32_t announce_race(int16_t step, uint8_t playerid, int32_t count, int32_t available);
|
||||
int32_t announce_attribute(int16_t step, uint8_t playerid, int32_t count, int32_t available);
|
||||
int32_t announce_card(int16_t step, uint8_t playerid);
|
||||
int32_t announce_number(int16_t step, uint8_t playerid);
|
||||
};
|
||||
|
||||
//Location Use Reason
|
||||
#define LOCATION_REASON_TOFIELD 0x1
|
||||
#define LOCATION_REASON_CONTROL 0x2
|
||||
//Chain Info
|
||||
#define CHAIN_DISABLE_ACTIVATE 0x01
|
||||
#define CHAIN_DISABLE_EFFECT 0x02
|
||||
#define CHAIN_HAND_EFFECT 0x04
|
||||
#define CHAIN_CONTINUOUS_CARD 0x08
|
||||
#define CHAIN_ACTIVATING 0x10
|
||||
#define CHAIN_HAND_TRIGGER 0x20
|
||||
#define CHAIN_FORCED 0x40
|
||||
#define CHAININFO_CHAIN_COUNT 0x01
|
||||
#define CHAININFO_TRIGGERING_EFFECT 0x02
|
||||
#define CHAININFO_TRIGGERING_PLAYER 0x04
|
||||
#define CHAININFO_TRIGGERING_CONTROLER 0x08
|
||||
#define CHAININFO_TRIGGERING_LOCATION 0x10
|
||||
#define CHAININFO_TRIGGERING_SEQUENCE 0x20
|
||||
#define CHAININFO_TARGET_CARDS 0x40
|
||||
#define CHAININFO_TARGET_PLAYER 0x80
|
||||
#define CHAININFO_TARGET_PARAM 0x100
|
||||
#define CHAININFO_DISABLE_REASON 0x200
|
||||
#define CHAININFO_DISABLE_PLAYER 0x400
|
||||
#define CHAININFO_CHAIN_ID 0x800
|
||||
#define CHAININFO_TYPE 0x1000
|
||||
#define CHAININFO_EXTTYPE 0x2000
|
||||
#define CHAININFO_TRIGGERING_POSITION 0x4000
|
||||
#define CHAININFO_TRIGGERING_CODE 0x8000
|
||||
#define CHAININFO_TRIGGERING_CODE2 0x10000
|
||||
//#define CHAININFO_TRIGGERING_TYPE 0x20000
|
||||
#define CHAININFO_TRIGGERING_LEVEL 0x40000
|
||||
#define CHAININFO_TRIGGERING_RANK 0x80000
|
||||
#define CHAININFO_TRIGGERING_ATTRIBUTE 0x100000
|
||||
#define CHAININFO_TRIGGERING_RACE 0x200000
|
||||
#define CHAININFO_TRIGGERING_ATTACK 0x400000
|
||||
#define CHAININFO_TRIGGERING_DEFENSE 0x800000
|
||||
//Timing
|
||||
#define TIMING_DRAW_PHASE 0x1
|
||||
#define TIMING_STANDBY_PHASE 0x2
|
||||
#define TIMING_MAIN_END 0x4
|
||||
#define TIMING_BATTLE_START 0x8
|
||||
#define TIMING_BATTLE_END 0x10
|
||||
#define TIMING_END_PHASE 0x20
|
||||
#define TIMING_SUMMON 0x40
|
||||
#define TIMING_SPSUMMON 0x80
|
||||
#define TIMING_FLIPSUMMON 0x100
|
||||
#define TIMING_MSET 0x200
|
||||
#define TIMING_SSET 0x400
|
||||
#define TIMING_POS_CHANGE 0x800
|
||||
#define TIMING_ATTACK 0x1000
|
||||
#define TIMING_DAMAGE_STEP 0x2000
|
||||
#define TIMING_DAMAGE_CAL 0x4000
|
||||
#define TIMING_CHAIN_END 0x8000
|
||||
#define TIMING_DRAW 0x10000
|
||||
#define TIMING_DAMAGE 0x20000
|
||||
#define TIMING_RECOVER 0x40000
|
||||
#define TIMING_DESTROY 0x80000
|
||||
#define TIMING_REMOVE 0x100000
|
||||
#define TIMING_TOHAND 0x200000
|
||||
#define TIMING_TODECK 0x400000
|
||||
#define TIMING_TOGRAVE 0x800000
|
||||
#define TIMING_BATTLE_PHASE 0x1000000
|
||||
#define TIMING_EQUIP 0x2000000
|
||||
#define TIMING_BATTLE_STEP_END 0x4000000
|
||||
#define TIMING_BATTLED 0x8000000
|
||||
|
||||
#define GLOBALFLAG_DECK_REVERSE_CHECK 0x1
|
||||
#define GLOBALFLAG_BRAINWASHING_CHECK 0x2
|
||||
#define GLOBALFLAG_SCRAP_CHIMERA 0x4
|
||||
//#define GLOBALFLAG_DELAYED_QUICKEFFECT 0x8
|
||||
#define GLOBALFLAG_DETACH_EVENT 0x10
|
||||
//#define GLOBALFLAG_MUST_BE_SMATERIAL 0x20
|
||||
#define GLOBALFLAG_SPSUMMON_COUNT 0x40
|
||||
#define GLOBALFLAG_XMAT_COUNT_LIMIT 0x80
|
||||
#define GLOBALFLAG_SELF_TOGRAVE 0x100
|
||||
#define GLOBALFLAG_SPSUMMON_ONCE 0x200
|
||||
#define GLOBALFLAG_TUNE_MAGICIAN 0x400
|
||||
#define GLOBALFLAG_ACTIVATION_COUNT 0x800
|
||||
//
|
||||
|
||||
#define PROCESSOR_ADJUST 1
|
||||
#define PROCESSOR_HINT 2
|
||||
#define PROCESSOR_TURN 3
|
||||
#define PROCESSOR_WAIT 4
|
||||
#define PROCESSOR_REFRESH_LOC 5
|
||||
#define PROCESSOR_SELECT_IDLECMD 10
|
||||
#define PROCESSOR_SELECT_EFFECTYN 11
|
||||
#define PROCESSOR_SELECT_BATTLECMD 12
|
||||
#define PROCESSOR_SELECT_YESNO 13
|
||||
#define PROCESSOR_SELECT_OPTION 14
|
||||
#define PROCESSOR_SELECT_CARD 15
|
||||
#define PROCESSOR_SELECT_CHAIN 16
|
||||
#define PROCESSOR_SELECT_UNSELECT_CARD 17
|
||||
#define PROCESSOR_SELECT_PLACE 18
|
||||
#define PROCESSOR_SELECT_POSITION 19
|
||||
#define PROCESSOR_SELECT_TRIBUTE_P 20
|
||||
#define PROCESSOR_SELECT_COUNTER 22
|
||||
#define PROCESSOR_SELECT_SUM 23
|
||||
#define PROCESSOR_SELECT_DISFIELD 24
|
||||
#define PROCESSOR_SORT_CARD 25
|
||||
#define PROCESSOR_SELECT_RELEASE 26
|
||||
#define PROCESSOR_SELECT_TRIBUTE 27
|
||||
#define PROCESSOR_POINT_EVENT 30
|
||||
#define PROCESSOR_QUICK_EFFECT 31
|
||||
#define PROCESSOR_IDLE_COMMAND 32
|
||||
#define PROCESSOR_PHASE_EVENT 33
|
||||
#define PROCESSOR_BATTLE_COMMAND 34
|
||||
#define PROCESSOR_DAMAGE_STEP 35
|
||||
#define PROCESSOR_ADD_CHAIN 40
|
||||
#define PROCESSOR_SOLVE_CHAIN 42
|
||||
#define PROCESSOR_SOLVE_CONTINUOUS 43
|
||||
#define PROCESSOR_EXECUTE_COST 44
|
||||
#define PROCESSOR_EXECUTE_OPERATION 45
|
||||
#define PROCESSOR_EXECUTE_TARGET 46
|
||||
#define PROCESSOR_DESTROY 50
|
||||
#define PROCESSOR_RELEASE 51
|
||||
#define PROCESSOR_SENDTO 52
|
||||
#define PROCESSOR_MOVETOFIELD 53
|
||||
#define PROCESSOR_CHANGEPOS 54
|
||||
#define PROCESSOR_OPERATION_REPLACE 55
|
||||
#define PROCESSOR_DESTROY_REPLACE 56
|
||||
#define PROCESSOR_RELEASE_REPLACE 57
|
||||
#define PROCESSOR_SENDTO_REPLACE 58
|
||||
#define PROCESSOR_SUMMON_RULE 60
|
||||
#define PROCESSOR_SPSUMMON_RULE 61
|
||||
#define PROCESSOR_SPSUMMON 62
|
||||
#define PROCESSOR_FLIP_SUMMON 63
|
||||
#define PROCESSOR_MSET 64
|
||||
#define PROCESSOR_SSET 65
|
||||
#define PROCESSOR_SPSUMMON_STEP 66
|
||||
#define PROCESSOR_SSET_G 67
|
||||
#define PROCESSOR_DRAW 70
|
||||
#define PROCESSOR_DAMAGE 71
|
||||
#define PROCESSOR_RECOVER 72
|
||||
#define PROCESSOR_EQUIP 73
|
||||
#define PROCESSOR_GET_CONTROL 74
|
||||
#define PROCESSOR_SWAP_CONTROL 75
|
||||
//#define PROCESSOR_CONTROL_ADJUST 76
|
||||
#define PROCESSOR_SELF_DESTROY 77
|
||||
#define PROCESSOR_TRAP_MONSTER_ADJUST 78
|
||||
#define PROCESSOR_PAY_LPCOST 80
|
||||
#define PROCESSOR_REMOVE_COUNTER 81
|
||||
#define PROCESSOR_ATTACK_DISABLE 82
|
||||
#define PROCESSOR_ACTIVATE_EFFECT 83
|
||||
|
||||
#define PROCESSOR_ANNOUNCE_RACE 110
|
||||
#define PROCESSOR_ANNOUNCE_ATTRIB 111
|
||||
#define PROCESSOR_ANNOUNCE_LEVEL 112
|
||||
#define PROCESSOR_ANNOUNCE_CARD 113
|
||||
#define PROCESSOR_ANNOUNCE_TYPE 114
|
||||
#define PROCESSOR_ANNOUNCE_NUMBER 115
|
||||
#define PROCESSOR_ANNOUNCE_COIN 116
|
||||
#define PROCESSOR_TOSS_DICE 117
|
||||
#define PROCESSOR_TOSS_COIN 118
|
||||
#define PROCESSOR_ROCK_PAPER_SCISSORS 119
|
||||
|
||||
#define PROCESSOR_SELECT_FUSION 131
|
||||
#define PROCESSOR_SELECT_SYNCHRO 132
|
||||
#define PROCESSOR_SELECT_XMATERIAL 139
|
||||
#define PROCESSOR_DISCARD_HAND 150
|
||||
#define PROCESSOR_DISCARD_DECK 151
|
||||
#define PROCESSOR_SORT_DECK 152
|
||||
#define PROCESSOR_REMOVE_OVERLAY 160
|
||||
|
||||
//#define PROCESSOR_SORT_CHAIN 21
|
||||
//#define PROCESSOR_DESTROY_S 100
|
||||
//#define PROCESSOR_RELEASE_S 101
|
||||
//#define PROCESSOR_SENDTO_S 102
|
||||
//#define PROCESSOR_CHANGEPOS_S 103
|
||||
//#define PROCESSOR_SELECT_YESNO_S 120
|
||||
//#define PROCESSOR_SELECT_OPTION_S 121
|
||||
//#define PROCESSOR_SELECT_CARD_S 122
|
||||
//#define PROCESSOR_SELECT_EFFECTYN_S 123
|
||||
//#define PROCESSOR_SELECT_UNSELECT_CARD_S 124
|
||||
//#define PROCESSOR_SELECT_PLACE_S 125
|
||||
//#define PROCESSOR_SELECT_POSITION_S 126
|
||||
//#define PROCESSOR_SELECT_TRIBUTE_S 127
|
||||
//#define PROCESSOR_SORT_CARDS_S 128
|
||||
//#define PROCESSOR_SELECT_RELEASE_S 129
|
||||
//#define PROCESSOR_SELECT_TARGET 130
|
||||
//#define PROCESSOR_SELECT_SUM_S 133
|
||||
//#define PROCESSOR_SELECT_DISFIELD_S 134
|
||||
//#define PROCESSOR_SPSUMMON_S 135
|
||||
//#define PROCESSOR_SPSUMMON_STEP_S 136
|
||||
//#define PROCESSOR_SPSUMMON_COMP_S 137
|
||||
//#define PROCESSOR_RANDOM_SELECT_S 138
|
||||
//#define PROCESSOR_DRAW_S 140
|
||||
//#define PROCESSOR_DAMAGE_S 141
|
||||
//#define PROCESSOR_RECOVER_S 142
|
||||
//#define PROCESSOR_EQUIP_S 143
|
||||
//#define PROCESSOR_GET_CONTROL_S 144
|
||||
//#define PROCESSOR_SWAP_CONTROL_S 145
|
||||
//#define PROCESSOR_MOVETOFIELD_S 161
|
||||
|
||||
#endif /* FIELD_H_ */
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* group.cpp
|
||||
*
|
||||
* Created on: 2010-8-3
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#include "group.h"
|
||||
#include "card.h"
|
||||
#include "duel.h"
|
||||
|
||||
group::group(duel* pd) {
|
||||
pduel = pd;
|
||||
it = container.begin();
|
||||
}
|
||||
group::group(duel* pd, card* pcard) {
|
||||
container.insert(pcard);
|
||||
pduel = pd;
|
||||
it = container.begin();
|
||||
}
|
||||
group::group(duel* pd, const card_set& cset): container(cset) {
|
||||
pduel = pd;
|
||||
it = container.begin();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* group.h
|
||||
*
|
||||
* Created on: 2010-5-6
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef GROUP_H_
|
||||
#define GROUP_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "sort.h"
|
||||
#include "metadata.h"
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
class card;
|
||||
class duel;
|
||||
|
||||
using card_set = std::set<card*, card_sort>;
|
||||
|
||||
constexpr uint32_t GTYPE_DEFAULT = 0;
|
||||
constexpr uint32_t GTYPE_READ_ONLY = 1;
|
||||
constexpr uint32_t GTYPE_KEEP_ALIVE = 2;
|
||||
|
||||
class alignas(8) group {
|
||||
public:
|
||||
int32_t ref_handle{ 0 };
|
||||
uint32_t is_readonly{ GTYPE_DEFAULT };
|
||||
duel* pduel;
|
||||
metadata meta;
|
||||
card_set container;
|
||||
card_set::iterator it;
|
||||
bool is_iterator_dirty{ true };
|
||||
|
||||
bool has_card(card* c) {
|
||||
return container.find(c) != container.end();
|
||||
}
|
||||
|
||||
explicit group(duel* pd);
|
||||
group(duel* pd, card* pcard);
|
||||
group(duel* pd, const card_set& cset);
|
||||
~group() = default;
|
||||
};
|
||||
|
||||
#endif /* GROUP_H_ */
|
||||
@@ -0,0 +1,831 @@
|
||||
/*
|
||||
* interpreter.cpp
|
||||
*
|
||||
* Created on: 2010-4-28
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include "duel.h"
|
||||
#include "group.h"
|
||||
#include "card.h"
|
||||
#include "effect.h"
|
||||
#include "scriptlib.h"
|
||||
#include "ocgapi.h"
|
||||
#include "interpreter.h"
|
||||
|
||||
interpreter::interpreter(duel* pd, bool enable_unsafe_libraries, uint32_t create_flags)
|
||||
: coroutines(256), pduel(pd), enable_unsafe_feature(enable_unsafe_libraries) {
|
||||
mem_tracker = new LuaMemTracker(YGOPRO_LUA_MEMORY_SIZE);
|
||||
lua_state = lua_newstate(LuaMemTracker::AllocThunk, mem_tracker);
|
||||
current_state = lua_state;
|
||||
std::memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info
|
||||
if (create_flags & OCGCORE_CREATE_ENABLE_LUA_COVERAGE)
|
||||
lua_coverage.enable(lua_state);
|
||||
//Initial
|
||||
#ifdef YGOPRO_NO_LUA_SAFE
|
||||
luaL_openlibs(lua_state);
|
||||
#else
|
||||
luaL_requiref(lua_state, "base", luaopen_base, 0);
|
||||
lua_pop(lua_state, 1);
|
||||
luaL_requiref(lua_state, "string", luaopen_string, 1);
|
||||
lua_pop(lua_state, 1);
|
||||
luaL_requiref(lua_state, "utf8", luaopen_utf8, 1);
|
||||
lua_pop(lua_state, 1);
|
||||
luaL_requiref(lua_state, "table", luaopen_table, 1);
|
||||
lua_pop(lua_state, 1);
|
||||
luaL_requiref(lua_state, "math", luaopen_math, 1);
|
||||
lua_pop(lua_state, 1);
|
||||
luaL_requiref(lua_state, "coroutine", luaopen_coroutine, 1);
|
||||
lua_pop(lua_state, 1);
|
||||
if (enable_unsafe_libraries) {
|
||||
luaL_requiref(lua_state, "io", luaopen_io, 1);
|
||||
lua_pop(lua_state, 1);
|
||||
}
|
||||
|
||||
auto nil_out = [&](const char* name) {
|
||||
lua_pushnil(lua_state);
|
||||
lua_setglobal(lua_state, name);
|
||||
};
|
||||
nil_out("collectgarbage");
|
||||
if (!enable_unsafe_libraries) {
|
||||
nil_out("dofile");
|
||||
nil_out("loadfile");
|
||||
}
|
||||
#endif
|
||||
//open all libs
|
||||
scriptlib::open_cardlib(lua_state);
|
||||
scriptlib::open_effectlib(lua_state);
|
||||
scriptlib::open_grouplib(lua_state);
|
||||
scriptlib::open_duellib(lua_state);
|
||||
scriptlib::open_debuglib(lua_state);
|
||||
//extra scripts
|
||||
load_script("./script/constant.lua");
|
||||
load_script("./script/utility.lua");
|
||||
load_script("./script/procedure.lua");
|
||||
//load kpro constant
|
||||
//card data constants
|
||||
lua_pushinteger(lua_state, CARDDATA_CODE);
|
||||
lua_setglobal(lua_state, "CARDDATA_CODE");
|
||||
lua_pushinteger(lua_state, CARDDATA_ALIAS);
|
||||
lua_setglobal(lua_state, "CARDDATA_ALIAS");
|
||||
lua_pushinteger(lua_state, CARDDATA_SETCODE);
|
||||
lua_setglobal(lua_state, "CARDDATA_SETCODE");
|
||||
lua_pushinteger(lua_state, CARDDATA_TYPE);
|
||||
lua_setglobal(lua_state, "CARDDATA_TYPE");
|
||||
lua_pushinteger(lua_state, CARDDATA_LEVEL);
|
||||
lua_setglobal(lua_state, "CARDDATA_LEVEL");
|
||||
lua_pushinteger(lua_state, CARDDATA_ATTRIBUTE);
|
||||
lua_setglobal(lua_state, "CARDDATA_ATTRIBUTE");
|
||||
lua_pushinteger(lua_state, CARDDATA_ATTRIBUTE);
|
||||
lua_setglobal(lua_state, "CARDDATA_ATTRIBUTE");
|
||||
lua_pushinteger(lua_state, CARDDATA_RACE);
|
||||
lua_setglobal(lua_state, "CARDDATA_RACE");
|
||||
lua_pushinteger(lua_state, CARDDATA_ATTACK);
|
||||
lua_setglobal(lua_state, "CARDDATA_ATTACK");
|
||||
lua_pushinteger(lua_state, CARDDATA_DEFENSE);
|
||||
lua_setglobal(lua_state, "CARDDATA_DEFENSE");
|
||||
lua_pushinteger(lua_state, CARDDATA_LSCALE);
|
||||
lua_setglobal(lua_state, "CARDDATA_LSCALE");
|
||||
lua_pushinteger(lua_state, CARDDATA_RSCALE);
|
||||
lua_setglobal(lua_state, "CARDDATA_RSCALE");
|
||||
lua_pushinteger(lua_state, CARDDATA_LINK_MARKER);
|
||||
lua_setglobal(lua_state, "CARDDATA_LINK_MARKER");
|
||||
//effect flag2s
|
||||
lua_pushinteger(lua_state, EFFECT_FLAG2_SPOSITCH);
|
||||
lua_setglobal(lua_state, "EFFECT_FLAG2_SPOSITCH");
|
||||
lua_pushinteger(lua_state, EFFECT_FLAG2_AVAILABLE_BD);
|
||||
lua_setglobal(lua_state, "EFFECT_FLAG2_AVAILABLE_BD");
|
||||
lua_pushinteger(lua_state, EFFECT_FLAG2_ACTIVATE_MONSTER_SZONE);
|
||||
lua_setglobal(lua_state, "EFFECT_FLAG2_ACTIVATE_MONSTER_SZONE");
|
||||
//effects
|
||||
lua_pushinteger(lua_state, EFFECT_CHANGE_LINK_MARKER_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_CHANGE_LINK_MARKER_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_ADD_LINK_MARKER_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_ADD_LINK_MARKER_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_REMOVE_LINK_MARKER_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_REMOVE_LINK_MARKER_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_CANNOT_LOSE_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_CANNOT_LOSE_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_EXTRA_TOMAIN_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_EXTRA_TOMAIN_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_OVERLAY_REMOVE_COST_CHANGE_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_OVERLAY_REMOVE_COST_CHANGE_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_SYNCHRO_LEVEL_EX);
|
||||
lua_setglobal(lua_state, "EFFECT_ALLOW_SYNCHRO_KOISHI"); // for compat only
|
||||
// lua_pushinteger(lua_state, EFFECT_MINIATURE_GARDEN_GIRL);
|
||||
// lua_setglobal(lua_state, "EFFECT_MINIATURE_GARDEN_GIRL");
|
||||
lua_pushinteger(lua_state, EFFECT_ADD_SUMMON_TYPE_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_ADD_SUMMON_TYPE_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_REMOVE_SUMMON_TYPE_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_REMOVE_SUMMON_TYPE_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_CHANGE_SUMMON_TYPE_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_CHANGE_SUMMON_TYPE_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_CHANGE_SUMMON_LOCATION_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_CHANGE_SUMMON_LOCATION_KOISHI");
|
||||
lua_pushinteger(lua_state, EFFECT_LINK_SPELL_KOISHI);
|
||||
lua_setglobal(lua_state, "EFFECT_LINK_SPELL_KOISHI");
|
||||
|
||||
lua_pushinteger(lua_state, GETEFFECT_ALL);
|
||||
lua_setglobal(lua_state, "GETEFFECT_ALL");
|
||||
lua_pushinteger(lua_state, GETEFFECT_INITIAL);
|
||||
lua_setglobal(lua_state, "GETEFFECT_INITIAL");
|
||||
lua_pushinteger(lua_state, GETEFFECT_COPY);
|
||||
lua_setglobal(lua_state, "GETEFFECT_COPY");
|
||||
lua_pushinteger(lua_state, GETEFFECT_GAIN);
|
||||
lua_setglobal(lua_state, "GETEFFECT_GAIN");
|
||||
lua_pushinteger(lua_state, GETEFFECT_GRANT);
|
||||
lua_setglobal(lua_state, "GETEFFECT_GRANT");
|
||||
|
||||
// lua_pushinteger(lua_state, EFFECT_SEA_PULSE);
|
||||
// lua_setglobal(lua_state, "EFFECT_SEA_PULSE");
|
||||
lua_pushinteger(lua_state, EFFECT_MAP_OF_HEAVEN);
|
||||
lua_setglobal(lua_state, "EFFECT_MAP_OF_HEAVEN");
|
||||
|
||||
//music hints
|
||||
lua_pushinteger(lua_state, HINT_MUSIC);
|
||||
lua_setglobal(lua_state, "HINT_MUSIC");
|
||||
lua_pushinteger(lua_state, HINT_SOUND);
|
||||
lua_setglobal(lua_state, "HINT_SOUND");
|
||||
lua_pushinteger(lua_state, HINT_MUSIC_OGG);
|
||||
lua_setglobal(lua_state, "HINT_MUSIC_OGG");
|
||||
//detect operating system
|
||||
#ifdef _WIN32
|
||||
lua_pushboolean(lua_state, 1);
|
||||
lua_setglobal(lua_state, "_WIN32");
|
||||
#endif
|
||||
}
|
||||
interpreter::~interpreter() {
|
||||
lua_close(lua_state);
|
||||
delete mem_tracker;
|
||||
}
|
||||
void interpreter::register_card(card *pcard) {
|
||||
if (!pcard)
|
||||
return;
|
||||
//create a card in by userdata
|
||||
luaL_checkstack(lua_state, 1, nullptr);
|
||||
card ** ppcard = (card**) lua_newuserdata(lua_state, sizeof(card*)); //+1 userdata
|
||||
*ppcard = pcard;
|
||||
pcard->ref_handle = luaL_ref(lua_state, LUA_REGISTRYINDEX); //-1
|
||||
//some userdata may be created in script like token so use current_state
|
||||
luaL_checkstack(current_state, 1, nullptr);
|
||||
lua_rawgeti(current_state, LUA_REGISTRYINDEX, pcard->ref_handle); //+1 userdata
|
||||
load_card_script(pcard->data.get_original_code());
|
||||
//stack: table cxxx, userdata
|
||||
//set metatable of pointer to base script
|
||||
lua_setmetatable(current_state, -2); //-1
|
||||
lua_pop(current_state, 1); //-1
|
||||
//Initial
|
||||
if(is_load_script(pcard->data)) {
|
||||
pcard->set_status(STATUS_INITIALIZING, TRUE);
|
||||
add_param(pcard, PARAM_TYPE_CARD);
|
||||
call_card_function(pcard, "initial_effect", 1, 0);
|
||||
pcard->set_status(STATUS_INITIALIZING, FALSE);
|
||||
}
|
||||
pcard->cardid = pduel->game_field->infos.card_id++;
|
||||
}
|
||||
void interpreter::unregister_card(card *pcard) {
|
||||
if (!pcard)
|
||||
return;
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, pcard->ref_handle);
|
||||
pcard->ref_handle = 0;
|
||||
}
|
||||
void interpreter::register_effect(effect *peffect) {
|
||||
if (!peffect)
|
||||
return;
|
||||
//create a effect in userdata
|
||||
luaL_checkstack(lua_state, 3, nullptr);
|
||||
effect ** ppeffect = (effect**) lua_newuserdata(lua_state, sizeof(effect*));
|
||||
*ppeffect = peffect;
|
||||
peffect->ref_handle = luaL_ref(lua_state, LUA_REGISTRYINDEX);
|
||||
//set metatable of pointer to base script
|
||||
lua_rawgeti(lua_state, LUA_REGISTRYINDEX, peffect->ref_handle);
|
||||
lua_getglobal(lua_state, "Effect");
|
||||
lua_setmetatable(lua_state, -2);
|
||||
lua_pop(lua_state, 1);
|
||||
}
|
||||
void interpreter::unregister_effect(effect *peffect) {
|
||||
if (!peffect)
|
||||
return;
|
||||
if(peffect->condition)
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->condition);
|
||||
if(peffect->cost)
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->cost);
|
||||
if(peffect->target)
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->target);
|
||||
if(peffect->operation)
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->operation);
|
||||
if(peffect->value && peffect->is_flag(EFFECT_FLAG_FUNC_VALUE))
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->value);
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->ref_handle);
|
||||
peffect->ref_handle = 0;
|
||||
}
|
||||
void interpreter::register_group(group *pgroup) {
|
||||
if (!pgroup)
|
||||
return;
|
||||
//create a group in by userdata
|
||||
luaL_checkstack(lua_state, 3, nullptr);
|
||||
group ** ppgroup = (group**) lua_newuserdata(lua_state, sizeof(group*));
|
||||
*ppgroup = pgroup;
|
||||
pgroup->ref_handle = luaL_ref(lua_state, LUA_REGISTRYINDEX);
|
||||
//set metatable of pointer to base script
|
||||
lua_rawgeti(lua_state, LUA_REGISTRYINDEX, pgroup->ref_handle);
|
||||
lua_getglobal(lua_state, "Group");
|
||||
lua_setmetatable(lua_state, -2);
|
||||
lua_pop(lua_state, 1);
|
||||
}
|
||||
void interpreter::unregister_group(group *pgroup) {
|
||||
if (!pgroup)
|
||||
return;
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, pgroup->ref_handle);
|
||||
pgroup->ref_handle = 0;
|
||||
}
|
||||
int32_t interpreter::is_effect_check(lua_State* L, effect* peffect, int32_t findex, int32_t extraargs) {
|
||||
if (!findex || lua_isnil(L, findex))
|
||||
return TRUE;
|
||||
luaL_checkstack(L, 1 + extraargs, nullptr);
|
||||
lua_pushvalue(L, findex);
|
||||
interpreter::effect2value(L, peffect);
|
||||
for (int32_t i = 0; i < extraargs; ++i)
|
||||
lua_pushvalue(L, (int32_t)(-extraargs - 2));
|
||||
if (lua_pcall(L, 1 + extraargs, 1, 0)) {
|
||||
sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(L, 1);
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
int32_t result = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
return result;
|
||||
}
|
||||
int32_t interpreter::load_script(const char* script_name) {
|
||||
int len = 0;
|
||||
byte* buffer = ::read_script(script_name, &len);
|
||||
if (!buffer)
|
||||
return OPERATION_FAIL;
|
||||
++no_action;
|
||||
luaL_checkstack(current_state, 2, nullptr);
|
||||
int32_t error = 0;
|
||||
if (enable_unsafe_feature && true)
|
||||
error = luaL_loadbuffer(current_state, (const char*)buffer, len, script_name) || lua_pcall(current_state, 0, 0, 0);
|
||||
else
|
||||
error = luaL_loadbufferx(current_state, (const char*)buffer, len, script_name, "t") || lua_pcall(current_state, 0, 0, 0);
|
||||
if (error) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(current_state, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
--no_action;
|
||||
return OPERATION_SUCCESS;
|
||||
}
|
||||
//push table cxxx onto the stack of current_state
|
||||
int32_t interpreter::load_card_script(uint32_t code) {
|
||||
char class_name[20];
|
||||
interpreter::sprintf(class_name, "c%d", code);
|
||||
luaL_checkstack(current_state, 1, nullptr);
|
||||
lua_getglobal(current_state, class_name); //+1 table cxxx
|
||||
if (lua_isnil(current_state, -1)) {
|
||||
luaL_checkstack(current_state, 5, nullptr);
|
||||
lua_pop(current_state, 1); //-1
|
||||
//create a table & set metatable
|
||||
lua_createtable(current_state, 0, 0); //+1, {}
|
||||
lua_setglobal(current_state, class_name); //-1
|
||||
lua_getglobal(current_state, class_name); //+1 table cxxx
|
||||
lua_getglobal(current_state, "Card"); //+1 Card, table cxxx
|
||||
lua_setmetatable(current_state, -2); //-1 table cxxx
|
||||
lua_pushstring(current_state, "__index"); //+1 "__index", table cxxx
|
||||
lua_pushvalue(current_state, -2); //+1 table cxxx, "__index", table cxxx
|
||||
lua_rawset(current_state, -3); //-2 table cxxx
|
||||
card_data cdata;
|
||||
int32_t res = OPERATION_SUCCESS;
|
||||
::read_card(code, &cdata);
|
||||
if (is_load_script(cdata)) {
|
||||
lua_getglobal(current_state, class_name); //+1
|
||||
lua_setglobal(current_state, "self_table"); //-1
|
||||
lua_pushinteger(current_state, code); //+1
|
||||
lua_setglobal(current_state, "self_code"); //-1
|
||||
char script_name[64];
|
||||
interpreter::sprintf(script_name, "./script/c%d.lua", code);
|
||||
res = load_script(script_name);
|
||||
lua_pushnil(current_state); //+1
|
||||
lua_setglobal(current_state, "self_table"); //-1
|
||||
lua_pushnil(current_state); //+1
|
||||
lua_setglobal(current_state, "self_code"); //-1 table cxxx {__index: cxxx }
|
||||
}
|
||||
if(!res) {
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
}
|
||||
return OPERATION_SUCCESS;
|
||||
}
|
||||
void interpreter::add_param(void* param, LuaParamType type, bool front) {
|
||||
lua_param p;
|
||||
p.ptr = param;
|
||||
if(front)
|
||||
params.emplace_front(p, type);
|
||||
else
|
||||
params.emplace_back(p, type);
|
||||
}
|
||||
void interpreter::add_param(int32_t param, LuaParamType type, bool front) {
|
||||
lua_param p;
|
||||
p.integer = param;
|
||||
if(front)
|
||||
params.emplace_front(p, type);
|
||||
else
|
||||
params.emplace_back(p, type);
|
||||
}
|
||||
void interpreter::push_param(lua_State* L, bool is_coroutine) {
|
||||
int32_t pushed = 0;
|
||||
for (const auto& it : params) {
|
||||
luaL_checkstack(L, 1, nullptr);
|
||||
auto type = it.second;
|
||||
switch(type) {
|
||||
case PARAM_TYPE_INT:
|
||||
lua_pushinteger(L, it.first.integer);
|
||||
break;
|
||||
case PARAM_TYPE_STRING:
|
||||
lua_pushstring(L, (const char*)it.first.ptr);
|
||||
break;
|
||||
case PARAM_TYPE_BOOLEAN:
|
||||
lua_pushboolean(L, it.first.integer);
|
||||
break;
|
||||
case PARAM_TYPE_CARD: {
|
||||
if (it.first.ptr)
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((card*)it.first.ptr)->ref_handle);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_EFFECT: {
|
||||
if (it.first.ptr)
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((effect*)it.first.ptr)->ref_handle);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_GROUP: {
|
||||
if (it.first.ptr)
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((group*)it.first.ptr)->ref_handle);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_FUNCTION: {
|
||||
function2value(L, it.first.integer);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_INDEX: {
|
||||
int32_t index = it.first.integer;
|
||||
if(index > 0)
|
||||
lua_pushvalue(L, index);
|
||||
else if(is_coroutine) {
|
||||
//copy value from current_state to new stack
|
||||
lua_pushvalue(current_state, index);
|
||||
lua_xmove(current_state, L, 1);
|
||||
} else {
|
||||
//the calling function is pushed before the params, so the actual index is: index - pushed -1
|
||||
lua_pushvalue(L, index - pushed - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
++pushed;
|
||||
}
|
||||
params.clear();
|
||||
}
|
||||
int32_t interpreter::call_function(int32_t f, uint32_t param_count, int32_t ret_count) {
|
||||
if (!f) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", "\"CallFunction\": attempt to call a null function.");
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
if (param_count != params.size()) {
|
||||
interpreter::sprintf(pduel->strbuffer, "\"CallFunction\": incorrect parameter count (%d expected, %zu pushed)", param_count, params.size());
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
function2value(current_state, f);
|
||||
if (!lua_isfunction(current_state, -1)) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", "\"CallFunction\": attempt to call an error function");
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
++no_action;
|
||||
++call_depth;
|
||||
push_param(current_state);
|
||||
if (lua_pcall(current_state, param_count, ret_count, 0)) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(current_state, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_SUCCESS;
|
||||
}
|
||||
int32_t interpreter::call_card_function(card* pcard, const char* f, uint32_t param_count, int32_t ret_count) {
|
||||
if (param_count != params.size()) {
|
||||
interpreter::sprintf(pduel->strbuffer, "\"CallCardFunction\"(c%d.%s): incorrect parameter count", pcard->data.get_original_code(), f);
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
card2value(current_state, pcard);
|
||||
luaL_checkstack(current_state, 1, nullptr);
|
||||
lua_getfield(current_state, -1, f);
|
||||
if (!lua_isfunction(current_state, -1)) {
|
||||
interpreter::sprintf(pduel->strbuffer, "\"CallCardFunction\"(c%d.%s): attempt to call an error function", pcard->data.get_original_code(), f);
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 2);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
++no_action;
|
||||
++call_depth;
|
||||
lua_remove(current_state, -2);
|
||||
push_param(current_state);
|
||||
if (lua_pcall(current_state, param_count, ret_count, 0)) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(current_state, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_SUCCESS;
|
||||
}
|
||||
int32_t interpreter::call_code_function(uint32_t code, const char* f, uint32_t param_count, int32_t ret_count) {
|
||||
if (param_count != params.size()) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", "\"CallCodeFunction\": incorrect parameter count");
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
if (code)
|
||||
load_card_script(code);
|
||||
else
|
||||
lua_getglobal(current_state, "Auxiliary");
|
||||
luaL_checkstack(current_state, 1, nullptr);
|
||||
lua_getfield(current_state, -1, f);
|
||||
if (!lua_isfunction(current_state, -1)) {
|
||||
if(!code) {
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
interpreter::sprintf(pduel->strbuffer, "\"CallCodeFunction\": attempt to call an error function");
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 2);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
lua_remove(current_state, -2);
|
||||
++no_action;
|
||||
++call_depth;
|
||||
push_param(current_state);
|
||||
if (lua_pcall(current_state, param_count, ret_count, 0)) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(current_state, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_SUCCESS;
|
||||
}
|
||||
int32_t interpreter::check_condition(int32_t f, uint32_t param_count) {
|
||||
if(!f) {
|
||||
params.clear();
|
||||
return TRUE;
|
||||
}
|
||||
++no_action;
|
||||
++call_depth;
|
||||
if (call_function(f, param_count, 1)) {
|
||||
int32_t result = lua_toboolean(current_state, -1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
int32_t interpreter::check_filter(lua_State* L, card* pcard, int32_t findex, int32_t extraargs) {
|
||||
if (!findex || lua_isnil(L, findex))
|
||||
return TRUE;
|
||||
++no_action;
|
||||
++call_depth;
|
||||
luaL_checkstack(L, 1 + extraargs, nullptr);
|
||||
lua_pushvalue(L, findex);
|
||||
card2value(L, pcard);
|
||||
for (int32_t i = 0; i < extraargs; ++i)
|
||||
lua_pushvalue(L, (int32_t)(-extraargs - 2));
|
||||
if (lua_pcall(L, 1 + extraargs, 1, 0)) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(L, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if (call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
int32_t result = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if (call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int32_t interpreter::get_operation_value(card* pcard, int32_t findex, int32_t extraargs) {
|
||||
if(!findex || lua_isnil(current_state, findex))
|
||||
return 0;
|
||||
++no_action;
|
||||
++call_depth;
|
||||
luaL_checkstack(current_state, 1 + extraargs, nullptr);
|
||||
lua_pushvalue(current_state, findex);
|
||||
interpreter::card2value(current_state, pcard);
|
||||
for(int32_t i = 0; i < extraargs; ++i)
|
||||
lua_pushvalue(current_state, (int32_t)(-extraargs - 2));
|
||||
if (lua_pcall(current_state, 1 + extraargs, 1, 0)) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(current_state, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
int32_t result = lua_isinteger(current_state, -1) ? (int32_t)lua_tointeger(current_state, -1) : (int32_t)lua_tonumber(current_state, -1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int32_t interpreter::get_function_value(int32_t f, uint32_t param_count) {
|
||||
if(!f) {
|
||||
params.clear();
|
||||
return 0;
|
||||
}
|
||||
++no_action;
|
||||
++call_depth;
|
||||
if (call_function(f, param_count, 1)) {
|
||||
int32_t result = 0;
|
||||
if(lua_isboolean(current_state, -1))
|
||||
result = lua_toboolean(current_state, -1);
|
||||
else if(lua_isinteger(current_state, -1))
|
||||
result = (int32_t)lua_tointeger(current_state, -1);
|
||||
else
|
||||
result = (int32_t)lua_tonumber(current_state, -1);
|
||||
lua_pop(current_state, 1);
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
int32_t interpreter::get_function_value(int32_t f, uint32_t param_count, std::vector<lua_Integer>& result) {
|
||||
int32_t is_success = OPERATION_FAIL;
|
||||
if(!f) {
|
||||
params.clear();
|
||||
return is_success;
|
||||
}
|
||||
int32_t stack_top = lua_gettop(current_state);
|
||||
++no_action;
|
||||
++call_depth;
|
||||
if (call_function(f, param_count, LUA_MULTRET)) {
|
||||
int32_t stack_newtop = lua_gettop(current_state);
|
||||
for (int32_t index = stack_top + 1; index <= stack_newtop; ++index) {
|
||||
lua_Integer return_value = 0;
|
||||
if(lua_isboolean(current_state, index))
|
||||
return_value = lua_toboolean(current_state, index);
|
||||
else if(lua_isinteger(current_state, index))
|
||||
return_value = lua_tointeger(current_state, index);
|
||||
else
|
||||
return_value = static_cast<lua_Integer>(lua_tonumber(current_state, index));
|
||||
result.push_back(return_value);
|
||||
}
|
||||
lua_settop(current_state, stack_top);
|
||||
is_success = OPERATION_SUCCESS;
|
||||
}
|
||||
--no_action;
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return is_success;
|
||||
}
|
||||
int32_t interpreter::call_coroutine(int32_t f, uint32_t param_count, int32_t* yield_value, uint16_t step) {
|
||||
*yield_value = 0;
|
||||
if (!f) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", "\"CallCoroutine\": attempt to call a null function");
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
if (param_count != params.size()) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", "\"CallCoroutine\": incorrect parameter count");
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
auto it = coroutines.find(f);
|
||||
lua_State* rthread;
|
||||
if (it == coroutines.end()) {
|
||||
rthread = lua_newthread(lua_state);
|
||||
std::memcpy(lua_getextraspace(rthread), lua_getextraspace(lua_state), LUA_EXTRASPACE);
|
||||
lua_coverage.install_hook(rthread);
|
||||
const auto threadref = luaL_ref(lua_state, LUA_REGISTRYINDEX);
|
||||
function2value(rthread, f);
|
||||
if(!lua_isfunction(rthread, -1)) {
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, threadref);
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", "\"CallCoroutine\": attempt to call an error function");
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
++call_depth;
|
||||
auto ret = coroutines.emplace(f, coroutine_map::mapped_type(rthread, threadref));
|
||||
it = ret.first;
|
||||
} else {
|
||||
if(step == 0) {
|
||||
auto threadref = it->second.second;
|
||||
coroutines.erase(it);
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, threadref);
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", "recursive event trigger detected");
|
||||
handle_message(pduel, 1);
|
||||
params.clear();
|
||||
--call_depth;
|
||||
if(call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return OPERATION_FAIL;
|
||||
}
|
||||
rthread = it->second.first;
|
||||
}
|
||||
push_param(rthread, true);
|
||||
int32_t result = 0, nresults = 0;
|
||||
{
|
||||
auto prev_state = current_state;
|
||||
current_state = rthread;
|
||||
#if (LUA_VERSION_NUM >= 504)
|
||||
result = lua_resume(rthread, prev_state, param_count, &nresults);
|
||||
#else
|
||||
result = lua_resume(rthread, prev_state, param_count);
|
||||
nresults = lua_gettop(rthread);
|
||||
#endif
|
||||
current_state = prev_state;
|
||||
}
|
||||
if (result == LUA_YIELD)
|
||||
return COROUTINE_YIELD;
|
||||
if (result != LUA_OK) {
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(rthread, -1));
|
||||
handle_message(pduel, 1);
|
||||
lua_pop(rthread, 1);
|
||||
}
|
||||
else if (yield_value) {
|
||||
if (nresults == 0)
|
||||
*yield_value = 0;
|
||||
else if (lua_isboolean(rthread, -1))
|
||||
*yield_value = lua_toboolean(rthread, -1);
|
||||
else
|
||||
*yield_value = (int32_t)lua_tointeger(rthread, -1);
|
||||
}
|
||||
auto threadref = it->second.second;
|
||||
coroutines.erase(it);
|
||||
luaL_unref(lua_state, LUA_REGISTRYINDEX, threadref);
|
||||
--call_depth;
|
||||
if (call_depth == 0) {
|
||||
pduel->release_script_group();
|
||||
pduel->restore_assumes();
|
||||
}
|
||||
return (result == LUA_OK) ? COROUTINE_FINISH : COROUTINE_ERROR;
|
||||
}
|
||||
int32_t interpreter::clone_function_ref(int32_t func_ref) {
|
||||
luaL_checkstack(current_state, 1, nullptr);
|
||||
lua_rawgeti(current_state, LUA_REGISTRYINDEX, func_ref);
|
||||
int32_t ref = luaL_ref(current_state, LUA_REGISTRYINDEX);
|
||||
return ref;
|
||||
}
|
||||
void* interpreter::get_ref_object(int32_t ref_handler) {
|
||||
if(ref_handler == 0)
|
||||
return nullptr;
|
||||
luaL_checkstack(current_state, 1, nullptr);
|
||||
lua_rawgeti(current_state, LUA_REGISTRYINDEX, ref_handler);
|
||||
void* p = *(void**)lua_touserdata(current_state, -1);
|
||||
lua_pop(current_state, 1);
|
||||
return p;
|
||||
}
|
||||
//push the object onto the stack of L, +1
|
||||
void interpreter::card2value(lua_State* L, card* pcard) {
|
||||
luaL_checkstack(L, 1, nullptr);
|
||||
if (!pcard || pcard->ref_handle == 0)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, pcard->ref_handle);
|
||||
}
|
||||
void interpreter::group2value(lua_State* L, group* pgroup) {
|
||||
luaL_checkstack(L, 1, nullptr);
|
||||
if (!pgroup || pgroup->ref_handle == 0)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, pgroup->ref_handle);
|
||||
}
|
||||
void interpreter::effect2value(lua_State* L, effect* peffect) {
|
||||
luaL_checkstack(L, 1, nullptr);
|
||||
if (!peffect || peffect->ref_handle == 0)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, peffect->ref_handle);
|
||||
}
|
||||
void interpreter::function2value(lua_State* L, int32_t func_ref) {
|
||||
luaL_checkstack(L, 1, nullptr);
|
||||
if (!func_ref)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, func_ref);
|
||||
}
|
||||
int32_t interpreter::get_function_handle(lua_State* L, int32_t index) {
|
||||
luaL_checkstack(L, 1, nullptr);
|
||||
lua_pushvalue(L, index);
|
||||
int32_t ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
return ref;
|
||||
}
|
||||
duel* interpreter::get_duel_info(lua_State* L) {
|
||||
duel* pduel;
|
||||
std::memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
|
||||
return pduel;
|
||||
}
|
||||
bool interpreter::is_load_script(const card_data& data) {
|
||||
if(data.code == TEMP_CARD_ID)
|
||||
return false;
|
||||
return !(data.type & TYPE_NORMAL) || (data.type & TYPE_PENDULUM);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* interpreter.h
|
||||
*
|
||||
* Created on: 2010-4-28
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef INTERPRETER_H_
|
||||
#define INTERPRETER_H_
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include "common.h"
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include "LuaMemTracker.h"
|
||||
#include "lua_coverage.h"
|
||||
|
||||
class card;
|
||||
struct card_data;
|
||||
class effect;
|
||||
class group;
|
||||
class duel;
|
||||
|
||||
class interpreter {
|
||||
public:
|
||||
union lua_param {
|
||||
void* ptr;
|
||||
int32_t integer;
|
||||
};
|
||||
using coroutine_map = std::unordered_map<int32_t, std::pair<lua_State*, int32_t>>;
|
||||
using param_list = std::list<std::pair<lua_param, LuaParamType>>;
|
||||
|
||||
duel* pduel;
|
||||
char msgbuf[64]{};
|
||||
lua_State* lua_state;
|
||||
lua_State* current_state;
|
||||
LuaMemTracker* mem_tracker;
|
||||
param_list params;
|
||||
param_list resumes;
|
||||
coroutine_map coroutines;
|
||||
int32_t no_action{};
|
||||
int32_t call_depth{};
|
||||
bool enable_unsafe_feature{};
|
||||
int32_t disable_action_check{};
|
||||
int32_t preloaded{};
|
||||
lua_coverage_state lua_coverage;
|
||||
|
||||
explicit interpreter(duel* pd, bool enable_unsafe_libraries, uint32_t create_flags = 0);
|
||||
~interpreter();
|
||||
|
||||
void register_card(card* pcard);
|
||||
void unregister_card(card* pcard);
|
||||
void register_effect(effect* peffect);
|
||||
void unregister_effect(effect* peffect);
|
||||
void register_group(group* pgroup);
|
||||
void unregister_group(group* pgroup);
|
||||
|
||||
int32_t is_effect_check(lua_State *L, effect *peffect, int32_t findex, int32_t extraargs);
|
||||
int32_t load_script(const char* script_name);
|
||||
int32_t load_card_script(uint32_t code);
|
||||
void add_param(void* param, LuaParamType type, bool front = false);
|
||||
void add_param(int32_t param, LuaParamType type, bool front = false);
|
||||
void push_param(lua_State* L, bool is_coroutine = false);
|
||||
int32_t call_function(int32_t f, uint32_t param_count, int32_t ret_count);
|
||||
int32_t call_card_function(card* pcard, const char* f, uint32_t param_count, int32_t ret_count);
|
||||
int32_t call_code_function(uint32_t code, const char* f, uint32_t param_count, int32_t ret_count);
|
||||
int32_t check_condition(int32_t f, uint32_t param_count);
|
||||
int32_t check_filter(lua_State* L, card* pcard, int32_t findex, int32_t extraargs);
|
||||
int32_t get_operation_value(card* pcard, int32_t findex, int32_t extraargs);
|
||||
int32_t get_function_value(int32_t f, uint32_t param_count);
|
||||
int32_t get_function_value(int32_t f, uint32_t param_count, std::vector<lua_Integer>& result);
|
||||
int32_t call_coroutine(int32_t f, uint32_t param_count, int32_t* yield_value, uint16_t step);
|
||||
int32_t clone_function_ref(int32_t func_ref);
|
||||
void* get_ref_object(int32_t ref_handler);
|
||||
|
||||
static void card2value(lua_State* L, card* pcard);
|
||||
static void group2value(lua_State* L, group* pgroup);
|
||||
static void effect2value(lua_State* L, effect* peffect);
|
||||
static void function2value(lua_State* L, int32_t func_ref);
|
||||
static int32_t get_function_handle(lua_State* L, int32_t index);
|
||||
static duel* get_duel_info(lua_State* L);
|
||||
static bool is_load_script(const card_data& data);
|
||||
|
||||
template <size_t N, typename... TR>
|
||||
static int sprintf(char (&buffer)[N], const char* format, TR... args) {
|
||||
return std::snprintf(buffer, N, format, args...);
|
||||
}
|
||||
};
|
||||
|
||||
#define COROUTINE_FINISH 1
|
||||
#define COROUTINE_YIELD 2
|
||||
#define COROUTINE_ERROR 3
|
||||
|
||||
#ifndef YGOPRO_LUA_MEMORY_SIZE
|
||||
#define YGOPRO_LUA_MEMORY_SIZE 0 // disable memory limit by default
|
||||
#endif
|
||||
|
||||
#endif /* INTERPRETER_H_ */
|
||||
+3946
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* libdebug.cpp
|
||||
*
|
||||
* Created on: 2012-2-8
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include "scriptlib.h"
|
||||
#include "duel.h"
|
||||
#include "field.h"
|
||||
#include "card.h"
|
||||
#include "effect.h"
|
||||
#include "ocgapi.h"
|
||||
|
||||
int32_t scriptlib::debug_message(lua_State *L) {
|
||||
#if !defined(YGOPRO_SERVER_MODE) || defined(YGOPRO_ENABLE_DEBUG_FUNC)
|
||||
check_param_count(L, 1);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
lua_getglobal(L, "tostring");
|
||||
lua_pushvalue(L, -2);
|
||||
lua_pcall(L, 1, 1, 0);
|
||||
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1));
|
||||
handle_message(pduel, 2);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_add_card(lua_State *L) {
|
||||
check_param_count(L, 6);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
int32_t code = (int32_t)lua_tointeger(L, 1);
|
||||
int32_t owner = (int32_t)lua_tointeger(L, 2);
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 3);
|
||||
int32_t location = (int32_t)lua_tointeger(L, 4);
|
||||
int32_t sequence = (int32_t)lua_tointeger(L, 5);
|
||||
int32_t position = (int32_t)lua_tointeger(L, 6);
|
||||
int32_t proc = lua_toboolean(L, 7);
|
||||
if (!check_playerid(owner))
|
||||
return 0;
|
||||
if (!check_playerid(playerid))
|
||||
return 0;
|
||||
if(!pduel->lua->preloaded) {
|
||||
pduel->lua->preloaded = TRUE;
|
||||
pduel->lua->call_code_function(0, (char*) "PreloadUds", 0, 0);
|
||||
}
|
||||
if(pduel->game_field->is_location_useable(playerid, location, sequence)) {
|
||||
card* pcard = pduel->new_card(code);
|
||||
pcard->owner = owner;
|
||||
if(location == LOCATION_EXTRA && position == 0)
|
||||
position = POS_FACEDOWN_DEFENSE;
|
||||
pcard->sendto_param.position = position;
|
||||
if(location == LOCATION_PZONE) {
|
||||
int32_t seq = pduel->game_field->get_pzone_sequence(sequence);
|
||||
pduel->game_field->add_card(playerid, pcard, LOCATION_SZONE, seq, TRUE);
|
||||
} else {
|
||||
pduel->game_field->add_card(playerid, pcard, location, sequence);
|
||||
}
|
||||
pcard->current.position = position;
|
||||
if(!(location & (LOCATION_ONFIELD | LOCATION_PZONE)) || (position & POS_FACEUP)) {
|
||||
pcard->enable_field_effect(true);
|
||||
pduel->game_field->adjust_instant();
|
||||
}
|
||||
if(proc)
|
||||
pcard->set_status(STATUS_PROC_COMPLETE, TRUE);
|
||||
interpreter::card2value(L, pcard);
|
||||
return 1;
|
||||
} else if(location == LOCATION_MZONE) {
|
||||
card* fcard = pduel->game_field->get_field_card(playerid, location, sequence);
|
||||
if (!fcard || !(fcard->data.type & TYPE_XYZ))
|
||||
return 0;
|
||||
card* pcard = pduel->new_card(code);
|
||||
pcard->owner = owner;
|
||||
fcard->xyz_add(pcard);
|
||||
if(proc)
|
||||
pcard->set_status(STATUS_PROC_COMPLETE, TRUE);
|
||||
interpreter::card2value(L, pcard);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_set_player_info(lua_State *L) {
|
||||
check_param_count(L, 4);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 1);
|
||||
int32_t lp = (int32_t)lua_tointeger(L, 2);
|
||||
int32_t startcount = (int32_t)lua_tointeger(L, 3);
|
||||
int32_t drawcount = (int32_t)lua_tointeger(L, 4);
|
||||
if(playerid != 0 && playerid != 1)
|
||||
return 0;
|
||||
pduel->game_field->player[playerid].lp = lp;
|
||||
pduel->game_field->player[playerid].start_count = startcount;
|
||||
pduel->game_field->player[playerid].draw_count = drawcount;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_pre_summon(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_CARD, 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, 1);
|
||||
uint32_t summon_type = (uint32_t)lua_tointeger(L, 2);
|
||||
uint8_t summon_location = 0;
|
||||
if(lua_gettop(L) > 2)
|
||||
summon_location = (uint8_t)lua_tointeger(L, 3);
|
||||
pcard->summon_info = summon_type | (summon_location << 16);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_pre_equip(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_CARD, 1);
|
||||
check_param(L, PARAM_TYPE_CARD, 2);
|
||||
card* equip_card = *(card**) lua_touserdata(L, 1);
|
||||
card* target = *(card**) lua_touserdata(L, 2);
|
||||
if((equip_card->current.location != LOCATION_SZONE)
|
||||
|| (target->current.location != LOCATION_MZONE)
|
||||
|| (target->current.position & POS_FACEDOWN))
|
||||
lua_pushboolean(L, 0);
|
||||
else {
|
||||
equip_card->equip(target, FALSE);
|
||||
equip_card->effect_target_cards.insert(target);
|
||||
target->effect_target_owner.insert(equip_card);
|
||||
lua_pushboolean(L, 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::debug_pre_set_target(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_CARD, 1);
|
||||
check_param(L, PARAM_TYPE_CARD, 2);
|
||||
card* t_card = *(card**) lua_touserdata(L, 1);
|
||||
card* target = *(card**) lua_touserdata(L, 2);
|
||||
t_card->add_card_target(target);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_pre_add_counter(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_CARD, 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, 1);
|
||||
uint16_t countertype = (uint16_t)lua_tointeger(L, 2);
|
||||
uint16_t count = 1;
|
||||
if(lua_gettop(L) >= 3)
|
||||
count = (uint16_t)lua_tointeger(L, 3);
|
||||
auto pr = pcard->counters.emplace(countertype, 0);
|
||||
auto cmit = pr.first;
|
||||
cmit->second += count;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_reload_field_begin(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
uint32_t flag = (uint32_t)lua_tointeger(L, 1);
|
||||
int32_t rule = (int32_t)lua_tointeger(L, 2);
|
||||
pduel->clear();
|
||||
pduel->game_field->core.duel_options |= flag;
|
||||
if (rule)
|
||||
pduel->game_field->core.duel_rule = rule;
|
||||
else if (flag & DUEL_OBSOLETE_RULING)
|
||||
pduel->game_field->core.duel_rule = 1;
|
||||
else
|
||||
pduel->game_field->core.duel_rule = CURRENT_RULE;
|
||||
if (pduel->game_field->core.duel_rule == MASTER_RULE3) {
|
||||
pduel->game_field->player[0].szone_size = 8;
|
||||
pduel->game_field->player[1].szone_size = 8;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_reload_field_end(lua_State *L) {
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
pduel->game_field->core.shuffle_hand_check[0] = FALSE;
|
||||
pduel->game_field->core.shuffle_hand_check[1] = FALSE;
|
||||
pduel->game_field->core.shuffle_deck_check[0] = FALSE;
|
||||
pduel->game_field->core.shuffle_deck_check[1] = FALSE;
|
||||
pduel->game_field->reload_field_info();
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_set_ai_name(lua_State *L) {
|
||||
#ifndef YGOPRO_SERVER_MODE
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_STRING, 1);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
pduel->write_buffer8(MSG_AI_NAME);
|
||||
const char* pstr = lua_tostring(L, 1);
|
||||
size_t length = std::strlen(pstr);
|
||||
if(length > SIZE_AI_NAME - 1)
|
||||
length = SIZE_AI_NAME - 1;
|
||||
uint16_t len = (uint16_t)length;
|
||||
pduel->write_buffer16(len);
|
||||
pduel->write_buffer(pstr, len);
|
||||
pduel->write_buffer8(0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::debug_show_hint(lua_State *L) {
|
||||
#if !defined(YGOPRO_SERVER_MODE) || defined(YGOPRO_ENABLE_DEBUG_FUNC)
|
||||
check_param_count(L, 1);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
lua_getglobal(L, "tostring");
|
||||
lua_pushvalue(L, -2);
|
||||
lua_pcall(L, 1, 1, 0);
|
||||
pduel->write_buffer8(MSG_SHOW_HINT);
|
||||
const char* pstr = lua_tostring(L, -1);
|
||||
size_t length = std::strlen(pstr);
|
||||
if (length > SIZE_HINT_MSG - 1)
|
||||
length = SIZE_HINT_MSG - 1;
|
||||
uint16_t len = (uint16_t)length;
|
||||
pduel->write_buffer16(len);
|
||||
pduel->write_buffer(pstr, len);
|
||||
pduel->write_buffer8(0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg debuglib[] = {
|
||||
{ "Message", scriptlib::debug_message },
|
||||
{ "AddCard", scriptlib::debug_add_card },
|
||||
{ "SetPlayerInfo", scriptlib::debug_set_player_info },
|
||||
{ "PreSummon", scriptlib::debug_pre_summon },
|
||||
{ "PreEquip", scriptlib::debug_pre_equip },
|
||||
{ "PreSetTarget", scriptlib::debug_pre_set_target },
|
||||
{ "PreAddCounter", scriptlib::debug_pre_add_counter },
|
||||
{ "ReloadFieldBegin", scriptlib::debug_reload_field_begin },
|
||||
{ "ReloadFieldEnd", scriptlib::debug_reload_field_end },
|
||||
{ "SetAIName", scriptlib::debug_set_ai_name },
|
||||
{ "ShowHint", scriptlib::debug_show_hint },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
void scriptlib::open_debuglib(lua_State *L) {
|
||||
luaL_newlib(L, debuglib);
|
||||
lua_setglobal(L, "Debug");
|
||||
}
|
||||
+5603
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,732 @@
|
||||
/*
|
||||
* libeffect.cpp
|
||||
*
|
||||
* Created on: 2010-7-20
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#include "scriptlib.h"
|
||||
#include "duel.h"
|
||||
#include "field.h"
|
||||
#include "card.h"
|
||||
#include "effect.h"
|
||||
#include "group.h"
|
||||
int32_t scriptlib::effect_set_owner(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
check_param(L, PARAM_TYPE_CARD, 2);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, 2);
|
||||
peffect->owner = pcard;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_get_count_limit(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t args = 0;
|
||||
if (peffect && (peffect->flag[0] & EFFECT_FLAG_COUNT_LIMIT)) {
|
||||
args = args + 1;
|
||||
lua_pushinteger(L, peffect->count_limit_max);
|
||||
if (peffect->count_code) {
|
||||
args = args + 1;
|
||||
lua_pushinteger(L, peffect->count_code);
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
int32_t scriptlib::get_effect_property(lua_State* L, effect_member type) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**)lua_touserdata(L, 1);
|
||||
lua_Integer value{};
|
||||
if (peffect) {
|
||||
switch (type) {
|
||||
case MEMBER_CATEGORY:
|
||||
value = (lua_Integer)peffect->category;
|
||||
break;
|
||||
case MEMBER_CODE:
|
||||
value = peffect->code;
|
||||
break;
|
||||
case MEMBER_DESCRIPTION:
|
||||
value = peffect->description;
|
||||
break;
|
||||
case MEMBER_ID:
|
||||
value = peffect->id;
|
||||
break;
|
||||
case MEMBER_RANGE:
|
||||
value = peffect->range;
|
||||
break;
|
||||
case MEMBER_TYPE:
|
||||
value = peffect->type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lua_pushinteger(L, value);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::is_effect_has_property(lua_State* L, effect_member type) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**)lua_touserdata(L, 1);
|
||||
uint64_t value{};
|
||||
if (peffect) {
|
||||
switch (type) {
|
||||
case MEMBER_CATEGORY:
|
||||
value = peffect->category;
|
||||
break;
|
||||
case MEMBER_RANGE:
|
||||
value = peffect->range;
|
||||
break;
|
||||
case MEMBER_TYPE:
|
||||
value = peffect->type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint64_t x = lua_tointeger(L, 2);
|
||||
if (value & x)
|
||||
lua_pushboolean(L, 1);
|
||||
else
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_new(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_CARD, 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, 1);
|
||||
duel* pduel = pcard->pduel;
|
||||
effect* peffect = pduel->new_effect();
|
||||
peffect->effect_owner = pduel->game_field->core.reason_player;
|
||||
peffect->owner = pcard;
|
||||
interpreter::effect2value(L, peffect);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_newex(lua_State *L) {
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
effect* peffect = pduel->new_effect();
|
||||
peffect->effect_owner = 0;
|
||||
peffect->owner = pduel->game_field->temp_card;
|
||||
interpreter::effect2value(L, peffect);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_clone(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
effect* ceffect = peffect->clone();
|
||||
interpreter::effect2value(L, ceffect);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_reset(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(peffect->owner == 0 || peffect->handler == 0)
|
||||
return 0;
|
||||
if(peffect->is_flag(EFFECT_FLAG_FIELD_ONLY))
|
||||
peffect->pduel->game_field->remove_effect(peffect);
|
||||
else
|
||||
peffect->handler->remove_effect(peffect);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_get_field_id(lua_State *L) {
|
||||
return get_effect_property(L, MEMBER_ID);
|
||||
}
|
||||
int32_t scriptlib::effect_set_description(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t v = (uint32_t)lua_tointeger(L, 2);
|
||||
peffect->description = v;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_code(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t v = (uint32_t)lua_tointeger(L, 2);
|
||||
peffect->code = v;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_range(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t v = (uint32_t)lua_tointeger(L, 2);
|
||||
peffect->range = v;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_target_range(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t s = (uint32_t)lua_tointeger(L, 2);
|
||||
uint32_t o = (uint32_t)lua_tointeger(L, 3);
|
||||
peffect->s_range = s;
|
||||
peffect->o_range = o;
|
||||
peffect->flag[0] &= ~EFFECT_FLAG_ABSOLUTE_TARGET;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_absolute_range(lua_State *L) {
|
||||
check_param_count(L, 4);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
uint32_t s = (uint32_t)lua_tointeger(L, 3);
|
||||
uint32_t o = (uint32_t)lua_tointeger(L, 4);
|
||||
if(playerid == 0) {
|
||||
peffect->s_range = s;
|
||||
peffect->o_range = o;
|
||||
} else {
|
||||
peffect->s_range = o;
|
||||
peffect->o_range = s;
|
||||
}
|
||||
peffect->flag[0] |= EFFECT_FLAG_ABSOLUTE_TARGET;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_count_limit(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t v = (uint32_t)lua_tointeger(L, 2);
|
||||
uint32_t code = 0;
|
||||
if(lua_gettop(L) >= 3)
|
||||
code = (uint32_t)lua_tointeger(L, 3);
|
||||
if(v == 0)
|
||||
v = 1;
|
||||
if(code == EFFECT_COUNT_CODE_CHAIN)
|
||||
code = EFFECT_COUNT_CODE_CHAIN | EFFECT_COUNT_CODE_SINGLE;
|
||||
peffect->flag[0] |= EFFECT_FLAG_COUNT_LIMIT;
|
||||
peffect->count_limit = v;
|
||||
peffect->count_limit_max = v;
|
||||
peffect->count_code = code;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_reset(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t v = (uint32_t)lua_tointeger(L, 2);
|
||||
int32_t c = (int32_t)lua_tointeger(L, 3);
|
||||
if(c == 0)
|
||||
c = 1;
|
||||
if(v & (RESET_PHASE) && !(v & (RESET_SELF_TURN | RESET_OPPO_TURN)))
|
||||
v |= (RESET_SELF_TURN | RESET_OPPO_TURN);
|
||||
peffect->reset_flag = v;
|
||||
peffect->reset_count = c;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_type(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t v = (uint32_t)lua_tointeger(L, 2);
|
||||
if (v & EFFECT_TYPE_ACTIVATE) {
|
||||
v = EFFECT_TYPE_FIELD | EFFECT_TYPE_ACTIVATE;
|
||||
peffect->range = LOCATION_SZONE + LOCATION_FZONE + LOCATION_HAND;
|
||||
}
|
||||
else if(v & EFFECT_TYPE_FLIP) {
|
||||
peffect->code = EVENT_FLIP;
|
||||
if (v & EFFECT_TYPE_TRIGGER_O) {
|
||||
v = EFFECT_TYPE_SINGLE | EFFECT_TYPE_FLIP | EFFECT_TYPE_TRIGGER_O;
|
||||
peffect->flag[0] |= EFFECT_FLAG_DELAY;
|
||||
}
|
||||
else {
|
||||
v = EFFECT_TYPE_SINGLE | EFFECT_TYPE_FLIP | EFFECT_TYPE_TRIGGER_F;
|
||||
}
|
||||
}
|
||||
else if (v & (EFFECT_TYPE_IGNITION | EFFECT_TYPE_QUICK_O | EFFECT_TYPE_QUICK_F)) {
|
||||
v |= EFFECT_TYPE_FIELD;
|
||||
}
|
||||
if (v & (EFFECT_TYPES_CHAIN_LINK | EFFECT_TYPE_CONTINUOUS))
|
||||
v |= EFFECT_TYPE_ACTIONS;
|
||||
else
|
||||
v &= ~EFFECT_TYPE_ACTIONS;
|
||||
peffect->type = v;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_property(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint64_t v1 = lua_tointeger(L, 2);
|
||||
uint64_t v2 = lua_tointeger(L, 3);
|
||||
peffect->flag[0] = (peffect->flag[0] & INTERNAL_FLAGS) | (v1 & ~INTERNAL_FLAGS);
|
||||
peffect->flag[1] = v2;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_label(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
peffect->label.clear();
|
||||
for(int32_t i = 2; i <= lua_gettop(L); ++i) {
|
||||
peffect->label.push_back(lua_tointeger(L, i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_label_object(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(lua_isnil(L, 2)) {
|
||||
peffect->label_object = 0;
|
||||
peffect->object_type = PARAM_TYPE_INT;
|
||||
return 0;
|
||||
}
|
||||
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
|
||||
card* p = *(card**)lua_touserdata(L, 2);
|
||||
peffect->label_object = p->ref_handle;
|
||||
peffect->object_type = PARAM_TYPE_CARD;
|
||||
} else if(check_param(L, PARAM_TYPE_EFFECT, 2, TRUE)) {
|
||||
effect* p = *(effect**)lua_touserdata(L, 2);
|
||||
peffect->label_object = p->ref_handle;
|
||||
peffect->object_type = PARAM_TYPE_EFFECT;
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
|
||||
group* p = *(group**)lua_touserdata(L, 2);
|
||||
peffect->label_object = p->ref_handle;
|
||||
peffect->object_type = PARAM_TYPE_GROUP;
|
||||
} else
|
||||
return luaL_error(L, "Parameter 2 should be \"Card\" or \"Effect\" or \"Group\".");
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_category(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint64_t v = (uint64_t)lua_tointeger(L, 2);
|
||||
peffect->category = v;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_hint_timing(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t vs = (uint32_t)lua_tointeger(L, 2);
|
||||
uint32_t vo = vs;
|
||||
if(lua_gettop(L) >= 3)
|
||||
vo = (uint32_t)lua_tointeger(L, 3);
|
||||
peffect->hint_timing[0] = vs;
|
||||
peffect->hint_timing[1] = vo;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_condition(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(peffect->condition)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, peffect->condition);
|
||||
peffect->condition = interpreter::get_function_handle(L, 2);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_target(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(peffect->target)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, peffect->target);
|
||||
peffect->target = interpreter::get_function_handle(L, 2);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_cost(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(peffect->cost)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, peffect->cost);
|
||||
peffect->cost = interpreter::get_function_handle(L, 2);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_value(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(peffect->value && peffect->is_flag(EFFECT_FLAG_FUNC_VALUE))
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, peffect->value);
|
||||
if (lua_isfunction(L, 2)) {
|
||||
peffect->value = interpreter::get_function_handle(L, 2);
|
||||
peffect->flag[0] |= EFFECT_FLAG_FUNC_VALUE;
|
||||
} else {
|
||||
peffect->flag[0] &= ~EFFECT_FLAG_FUNC_VALUE;
|
||||
if(lua_isboolean(L, 2))
|
||||
peffect->value = lua_toboolean(L, 2);
|
||||
else if(lua_isinteger(L, 2))
|
||||
peffect->value = (int32_t)lua_tointeger(L, 2);
|
||||
else
|
||||
peffect->value = (int32_t)lua_tonumber(L, 2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_operation(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(peffect->operation)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, peffect->operation);
|
||||
if(!lua_isnil(L, 2)) {
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
peffect->operation = interpreter::get_function_handle(L, 2);
|
||||
} else
|
||||
peffect->operation = 0;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_set_owner_player(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
int32_t p = (int32_t)lua_tointeger(L, 2);
|
||||
if(p != 0 && p != 1)
|
||||
return 0;
|
||||
peffect->effect_owner = p;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_get_description(lua_State *L) {
|
||||
return get_effect_property(L, MEMBER_DESCRIPTION);
|
||||
}
|
||||
int32_t scriptlib::effect_get_code(lua_State *L) {
|
||||
return get_effect_property(L, MEMBER_CODE);
|
||||
}
|
||||
int32_t scriptlib::effect_get_type(lua_State *L) {
|
||||
return get_effect_property(L, MEMBER_TYPE);
|
||||
}
|
||||
int32_t scriptlib::effect_get_property(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if (peffect) {
|
||||
lua_pushinteger(L, peffect->flag[0]);
|
||||
lua_pushinteger(L, peffect->flag[1]);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_get_label(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if (peffect) {
|
||||
if(peffect->label.empty()) {
|
||||
lua_pushinteger(L, 0);
|
||||
return 1;
|
||||
}
|
||||
for(const auto& lab : peffect->label)
|
||||
lua_pushinteger(L, lab);
|
||||
return (int32_t)peffect->label.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_get_label_object(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if (!peffect->label_object) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, peffect->label_object);
|
||||
if(lua_isuserdata(L, -1))
|
||||
return 1;
|
||||
else {
|
||||
lua_pop(L, 1);
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
int32_t scriptlib::effect_get_category(lua_State *L) {
|
||||
return get_effect_property(L, MEMBER_CATEGORY);
|
||||
}
|
||||
int32_t scriptlib::effect_get_range(lua_State* L) {
|
||||
return get_effect_property(L, MEMBER_RANGE);
|
||||
}
|
||||
int32_t scriptlib::effect_get_owner(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
interpreter::card2value(L, peffect->get_owner());
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_handler(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
interpreter::card2value(L, peffect->get_handler());
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_owner_player(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, peffect->get_owner_player());
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_handler_player(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, peffect->get_handler_player());
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_condition(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
interpreter::function2value(L, peffect->condition);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_target(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
interpreter::function2value(L, peffect->target);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_cost(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
interpreter::function2value(L, peffect->cost);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_value(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
if(peffect->is_flag(EFFECT_FLAG_FUNC_VALUE))
|
||||
interpreter::function2value(L, peffect->value);
|
||||
else
|
||||
lua_pushinteger(L, (int32_t)peffect->value);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_operation(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
interpreter::function2value(L, peffect->operation);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_active_type(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, peffect->get_active_type());
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_is_active_type(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t type = (uint32_t)lua_tointeger(L, 2);
|
||||
if(peffect->get_active_type() & type)
|
||||
lua_pushboolean(L, 1);
|
||||
else
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_is_has_property(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint64_t tflag1 = lua_tointeger(L, 2);
|
||||
uint64_t tflag2 = lua_tointeger(L, 3);
|
||||
if (peffect && (!tflag1 || (peffect->flag[0] & tflag1)) && (!tflag2 || (peffect->flag[1] & tflag2)))
|
||||
lua_pushboolean(L, 1);
|
||||
else
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_is_has_category(lua_State *L) {
|
||||
return is_effect_has_property(L, MEMBER_CATEGORY);
|
||||
}
|
||||
int32_t scriptlib::effect_is_has_type(lua_State *L) {
|
||||
return is_effect_has_property(L, MEMBER_TYPE);
|
||||
}
|
||||
int32_t scriptlib::effect_is_has_range(lua_State* L) {
|
||||
return is_effect_has_property(L, MEMBER_RANGE);
|
||||
}
|
||||
int32_t scriptlib::effect_is_activatable(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint32_t neglect_loc = 0;
|
||||
uint32_t neglect_target = 0;
|
||||
if(lua_gettop(L) > 2) {
|
||||
neglect_loc = lua_toboolean(L, 3);
|
||||
if (lua_gettop(L) > 3)
|
||||
neglect_target = lua_toboolean(L, 4);
|
||||
}
|
||||
lua_pushboolean(L, peffect->is_activateable(playerid, peffect->pduel->game_field->nil_event, 0, 0, neglect_target, neglect_loc));
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_is_activated(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
lua_pushboolean(L, (peffect->type & EFFECT_TYPES_CHAIN_LINK));
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_is_cost_checked(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**)lua_touserdata(L, 1);
|
||||
lua_pushboolean(L, peffect->cost_checked);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_set_cost_check(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
uint8_t cost_check = lua_toboolean(L, 2);
|
||||
peffect->cost_checked = cost_check;
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_get_activate_location(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, peffect->active_location);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_get_activate_sequence(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, peffect->active_sequence);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_check_count_limit(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
int32_t p = (int32_t)lua_tointeger(L, 2);
|
||||
lua_pushboolean(L, peffect->check_count_limit(p));
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::effect_use_count_limit(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
int32_t p = (int32_t)lua_tointeger(L, 2);
|
||||
int32_t count = 1;
|
||||
int32_t oath_only = 0;
|
||||
uint32_t code = peffect->count_code;
|
||||
if(lua_gettop(L) > 2) {
|
||||
count = (int32_t)lua_tointeger(L, 3);
|
||||
if (lua_gettop(L) > 3)
|
||||
oath_only = lua_toboolean(L, 4);
|
||||
}
|
||||
if (!oath_only || code & EFFECT_COUNT_CODE_OATH)
|
||||
while(count) {
|
||||
peffect->dec_count(p);
|
||||
--count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::effect_get_meta_value(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
return peffect->meta.luaop_get(L, 1);
|
||||
}
|
||||
int32_t scriptlib::effect_set_meta_value(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
return peffect->meta.luaop_set(L, 1);
|
||||
}
|
||||
int32_t scriptlib::effect_has_meta_value(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
return peffect->meta.luaop_has(L, 1);
|
||||
}
|
||||
int32_t scriptlib::effect_get_meta_keys(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
return peffect->meta.luaop_keys(L);
|
||||
}
|
||||
int32_t scriptlib::effect_clear_meta(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_EFFECT, 1);
|
||||
effect* peffect = *(effect**) lua_touserdata(L, 1);
|
||||
return peffect->meta.luaop_clear();
|
||||
}
|
||||
|
||||
static const struct luaL_Reg effectlib[] = {
|
||||
{ "SetOwner", scriptlib::effect_set_owner },
|
||||
{ "GetCountLimit", scriptlib::effect_get_count_limit },
|
||||
|
||||
{ "CreateEffect", scriptlib::effect_new },
|
||||
{ "GlobalEffect", scriptlib::effect_newex },
|
||||
{ "Clone", scriptlib::effect_clone },
|
||||
{ "Reset", scriptlib::effect_reset },
|
||||
{ "GetFieldID", scriptlib::effect_get_field_id },
|
||||
{ "SetDescription", scriptlib::effect_set_description },
|
||||
{ "SetCode", scriptlib::effect_set_code },
|
||||
{ "SetRange", scriptlib::effect_set_range },
|
||||
{ "SetTargetRange", scriptlib::effect_set_target_range },
|
||||
{ "SetAbsoluteRange", scriptlib::effect_set_absolute_range },
|
||||
{ "SetCountLimit", scriptlib::effect_set_count_limit },
|
||||
{ "SetReset", scriptlib::effect_set_reset },
|
||||
{ "SetType", scriptlib::effect_set_type },
|
||||
{ "SetProperty", scriptlib::effect_set_property },
|
||||
{ "SetLabel", scriptlib::effect_set_label },
|
||||
{ "SetLabelObject", scriptlib::effect_set_label_object },
|
||||
{ "SetCategory", scriptlib::effect_set_category },
|
||||
{ "SetHintTiming", scriptlib::effect_set_hint_timing },
|
||||
{ "SetCondition", scriptlib::effect_set_condition },
|
||||
{ "SetTarget", scriptlib::effect_set_target },
|
||||
{ "SetCost", scriptlib::effect_set_cost },
|
||||
{ "SetValue", scriptlib::effect_set_value },
|
||||
{ "SetOperation", scriptlib::effect_set_operation },
|
||||
{ "SetOwnerPlayer", scriptlib::effect_set_owner_player },
|
||||
{ "GetDescription", scriptlib::effect_get_description },
|
||||
{ "GetCode", scriptlib::effect_get_code },
|
||||
{ "GetType", scriptlib::effect_get_type },
|
||||
{ "GetProperty", scriptlib::effect_get_property },
|
||||
{ "GetLabel", scriptlib::effect_get_label },
|
||||
{ "GetLabelObject", scriptlib::effect_get_label_object },
|
||||
{ "GetCategory", scriptlib::effect_get_category },
|
||||
{ "GetRange", scriptlib::effect_get_range },
|
||||
{ "GetOwner", scriptlib::effect_get_owner },
|
||||
{ "GetHandler", scriptlib::effect_get_handler },
|
||||
{ "GetCondition", scriptlib::effect_get_condition },
|
||||
{ "GetTarget", scriptlib::effect_get_target },
|
||||
{ "GetCost", scriptlib::effect_get_cost },
|
||||
{ "GetValue", scriptlib::effect_get_value },
|
||||
{ "GetOperation", scriptlib::effect_get_operation },
|
||||
{ "GetActiveType", scriptlib::effect_get_active_type },
|
||||
{ "IsActiveType", scriptlib::effect_is_active_type },
|
||||
{ "GetOwnerPlayer", scriptlib::effect_get_owner_player },
|
||||
{ "GetHandlerPlayer", scriptlib::effect_get_handler_player },
|
||||
{ "IsHasProperty", scriptlib::effect_is_has_property },
|
||||
{ "IsHasCategory", scriptlib::effect_is_has_category },
|
||||
{ "IsHasType", scriptlib::effect_is_has_type },
|
||||
{ "IsHasRange", scriptlib::effect_is_has_range },
|
||||
{ "IsActivatable", scriptlib::effect_is_activatable },
|
||||
{ "IsActivated", scriptlib::effect_is_activated },
|
||||
{ "IsCostChecked", scriptlib::effect_is_cost_checked },
|
||||
{ "SetCostCheck", scriptlib::effect_set_cost_check },
|
||||
{ "GetActivateLocation", scriptlib::effect_get_activate_location },
|
||||
{ "GetActivateSequence", scriptlib::effect_get_activate_sequence },
|
||||
{ "CheckCountLimit", scriptlib::effect_check_count_limit },
|
||||
{ "UseCountLimit", scriptlib::effect_use_count_limit },
|
||||
{ "GetMetaValue", scriptlib::effect_get_meta_value },
|
||||
{ "SetMetaValue", scriptlib::effect_set_meta_value },
|
||||
{ "HasMetaValue", scriptlib::effect_has_meta_value },
|
||||
{ "ClearMeta", scriptlib::effect_clear_meta },
|
||||
{ "GetMetaKeys", scriptlib::effect_get_meta_keys },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
void scriptlib::open_effectlib(lua_State *L) {
|
||||
luaL_newlib(L, effectlib);
|
||||
lua_pushstring(L, "__index");
|
||||
lua_pushvalue(L, -2);
|
||||
lua_rawset(L, -3);
|
||||
lua_setglobal(L, "Effect");
|
||||
}
|
||||
@@ -0,0 +1,999 @@
|
||||
/*
|
||||
* libgroup.cpp
|
||||
*
|
||||
* Created on: 2010-5-6
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#include "scriptlib.h"
|
||||
#include "group.h"
|
||||
#include "card.h"
|
||||
#include "effect.h"
|
||||
#include "duel.h"
|
||||
|
||||
int32_t scriptlib::group_new(lua_State *L) {
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = pduel->new_group();
|
||||
for(int32_t i = 1; i <= lua_gettop(L); ++i) {
|
||||
if(!lua_isnil(L, i)) {
|
||||
if(check_param(L, PARAM_TYPE_CARD, i, TRUE)) {
|
||||
card* pcard = *(card**) lua_touserdata(L, i);
|
||||
pgroup->container.insert(pcard);
|
||||
} else if (check_param(L, PARAM_TYPE_GROUP, i, TRUE)) {
|
||||
group* mgroup = *(group**) lua_touserdata(L, i);
|
||||
pgroup->container.insert(mgroup->container.begin(), mgroup->container.end());
|
||||
} else {
|
||||
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_clone(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
group* newgroup = pduel->new_group(pgroup->container);
|
||||
interpreter::group2value(L, newgroup);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_from_cards(lua_State *L) {
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = pduel->new_group();
|
||||
for(int32_t i = 0; i < lua_gettop(L); ++i) {
|
||||
if(!lua_isnil(L, i + 1)) {
|
||||
check_param(L, PARAM_TYPE_CARD, i + 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, i + 1);
|
||||
pgroup->container.insert(pcard);
|
||||
}
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_delete(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
if(pgroup->is_readonly != GTYPE_KEEP_ALIVE)
|
||||
return 0;
|
||||
pgroup->is_iterator_dirty = true;
|
||||
pgroup->is_readonly = GTYPE_DEFAULT;
|
||||
pduel->sgroups.insert(pgroup);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::group_keep_alive(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
if(pgroup->is_readonly == GTYPE_READ_ONLY)
|
||||
return 0;
|
||||
pgroup->is_readonly = GTYPE_KEEP_ALIVE;
|
||||
pduel->sgroups.erase(pgroup);
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::group_clear(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
if (pgroup->is_readonly != GTYPE_READ_ONLY) {
|
||||
pgroup->is_iterator_dirty = true;
|
||||
pgroup->container.clear();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::group_add_card(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, 2);
|
||||
if (pgroup->is_readonly != GTYPE_READ_ONLY) {
|
||||
pgroup->is_iterator_dirty = true;
|
||||
for(int32_t i = 2; i <= lua_gettop(L); ++i) {
|
||||
if(!lua_isnil(L, i)) {
|
||||
if(check_param(L, PARAM_TYPE_CARD, i, TRUE)) {
|
||||
card* pcard = *(card**) lua_touserdata(L, i);
|
||||
pgroup->container.insert(pcard);
|
||||
} else if (check_param(L, PARAM_TYPE_GROUP, i, TRUE)) {
|
||||
group* mgroup = *(group**) lua_touserdata(L, i);
|
||||
pgroup->container.insert(mgroup->container.begin(), mgroup->container.end());
|
||||
} else {
|
||||
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::group_remove_card(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, 2);
|
||||
if (pgroup->is_readonly != GTYPE_READ_ONLY) {
|
||||
pgroup->is_iterator_dirty = true;
|
||||
for(int32_t i = 2; i <= lua_gettop(L); ++i) {
|
||||
if(!lua_isnil(L, i)) {
|
||||
if(check_param(L, PARAM_TYPE_CARD, i, TRUE)) {
|
||||
card* pcard = *(card**) lua_touserdata(L, i);
|
||||
pgroup->container.erase(pcard);
|
||||
} else if (check_param(L, PARAM_TYPE_GROUP, i, TRUE)) {
|
||||
group* sgroup = *(group**) lua_touserdata(L, i);
|
||||
for (auto& pcard : sgroup->container) {
|
||||
pgroup->container.erase(pcard);
|
||||
}
|
||||
} else {
|
||||
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::group_get_next(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
if (pgroup->is_iterator_dirty) {
|
||||
return luaL_error(L, "Called Group.GetNext without calling Group.GetFirst first.");
|
||||
}
|
||||
if(pgroup->it == pgroup->container.end())
|
||||
lua_pushnil(L);
|
||||
else {
|
||||
++pgroup->it;
|
||||
if (pgroup->it == pgroup->container.end())
|
||||
lua_pushnil(L);
|
||||
else
|
||||
interpreter::card2value(L, (*(pgroup->it)));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_get_first(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
pgroup->is_iterator_dirty = false;
|
||||
if (pgroup->container.size()) {
|
||||
pgroup->it = pgroup->container.begin();
|
||||
interpreter::card2value(L, (*(pgroup->it)));
|
||||
} else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_get_count(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, pgroup->container.size());
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_filter(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card_set cset(pgroup->container);
|
||||
if(check_param(L, PARAM_TYPE_CARD, 3, TRUE)) {
|
||||
card* pexception = *(card**) lua_touserdata(L, 3);
|
||||
cset.erase(pexception);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 3, TRUE)) {
|
||||
group* pexgroup = *(group**) lua_touserdata(L, 3);
|
||||
for(auto& pcard : pexgroup->container)
|
||||
cset.erase(pcard);
|
||||
}
|
||||
duel* pduel = pgroup->pduel;
|
||||
group* new_group = pduel->new_group();
|
||||
uint32_t extraargs = lua_gettop(L) - 3;
|
||||
for(auto& pcard : cset) {
|
||||
if(pduel->lua->check_filter(L, pcard, 2, extraargs)) {
|
||||
new_group->container.insert(pcard);
|
||||
}
|
||||
}
|
||||
interpreter::group2value(L, new_group);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_filter_count(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card_set cset(pgroup->container);
|
||||
if(check_param(L, PARAM_TYPE_CARD, 3, TRUE)) {
|
||||
card* pexception = *(card**) lua_touserdata(L, 3);
|
||||
cset.erase(pexception);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 3, TRUE)) {
|
||||
group* pexgroup = *(group**) lua_touserdata(L, 3);
|
||||
for(auto& pcard : pexgroup->container)
|
||||
cset.erase(pcard);
|
||||
}
|
||||
duel* pduel = pgroup->pduel;
|
||||
uint32_t extraargs = lua_gettop(L) - 3;
|
||||
uint32_t count = 0;
|
||||
for (auto& pcard : cset) {
|
||||
if(pduel->lua->check_filter(L, pcard, 2, extraargs))
|
||||
++count;
|
||||
}
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_filter_select(lua_State *L) {
|
||||
check_action_permission(L);
|
||||
check_param_count(L, 6);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 3);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card_set cset(pgroup->container);
|
||||
if(check_param(L, PARAM_TYPE_CARD, 6, TRUE)) {
|
||||
card* pexception = *(card**) lua_touserdata(L, 6);
|
||||
cset.erase(pexception);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 6, TRUE)) {
|
||||
group* pexgroup = *(group**) lua_touserdata(L, 6);
|
||||
for(auto& pcard : pexgroup->container)
|
||||
cset.erase(pcard);
|
||||
}
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
if(playerid != 0 && playerid != 1)
|
||||
return 0;
|
||||
uint32_t min = (uint32_t)lua_tointeger(L, 4);
|
||||
uint32_t max = (uint32_t)lua_tointeger(L, 5);
|
||||
uint32_t extraargs = lua_gettop(L) - 6;
|
||||
pduel->game_field->core.select_cards.clear();
|
||||
for (auto& pcard : cset) {
|
||||
if(pduel->lua->check_filter(L, pcard, 3, extraargs))
|
||||
pduel->game_field->core.select_cards.push_back(pcard);
|
||||
}
|
||||
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
|
||||
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32_t status, lua_KContext ctx) {
|
||||
duel* pduel = (duel*)ctx;
|
||||
group* pgroup = pduel->new_group();
|
||||
for(int32_t i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
|
||||
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
|
||||
pgroup->container.insert(pcard);
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
int32_t scriptlib::group_select(lua_State *L) {
|
||||
check_action_permission(L);
|
||||
check_param_count(L, 5);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card_set cset(pgroup->container);
|
||||
if(check_param(L, PARAM_TYPE_CARD, 5, TRUE)) {
|
||||
card* pexception = *(card**) lua_touserdata(L, 5);
|
||||
cset.erase(pexception);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 5, TRUE)) {
|
||||
group* pexgroup = *(group**) lua_touserdata(L, 5);
|
||||
for(auto& pcard : pexgroup->container)
|
||||
cset.erase(pcard);
|
||||
}
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
if(playerid != 0 && playerid != 1)
|
||||
return 0;
|
||||
uint32_t min = (uint32_t)lua_tointeger(L, 3);
|
||||
uint32_t max = (uint32_t)lua_tointeger(L, 4);
|
||||
pduel->game_field->core.select_cards.clear();
|
||||
for (auto& pcard : cset) {
|
||||
pduel->game_field->core.select_cards.push_back(pcard);
|
||||
}
|
||||
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
|
||||
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32_t status, lua_KContext ctx) {
|
||||
duel* pduel = (duel*)ctx;
|
||||
group* pgroup = pduel->new_group();
|
||||
for(int32_t i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
|
||||
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
|
||||
pgroup->container.insert(pcard);
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
int32_t scriptlib::group_select_unselect(lua_State *L) {
|
||||
check_action_permission(L);
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* select_group = *(group**)lua_touserdata(L, 1);
|
||||
group* unselect_group = nullptr;
|
||||
if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE))
|
||||
unselect_group = *(group**)lua_touserdata(L, 2);
|
||||
duel* pduel = select_group->pduel;
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 3);
|
||||
if(playerid != 0 && playerid != 1)
|
||||
return 0;
|
||||
if(select_group->container.size() == 0 && (!unselect_group || unselect_group->container.size() == 0))
|
||||
return 0;
|
||||
if(unselect_group) {
|
||||
for(auto it = unselect_group->container.begin(); it != unselect_group->container.end(); ++it) {
|
||||
card* pcard = *it;
|
||||
for(auto it2 = select_group->container.begin(); it2 != select_group->container.end(); ++it2) {
|
||||
if((*it2) == pcard) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uint32_t finishable = FALSE;
|
||||
if(lua_gettop(L) > 3) {
|
||||
finishable = lua_toboolean(L, 4);
|
||||
}
|
||||
uint32_t cancelable = FALSE;
|
||||
if(lua_gettop(L) > 4) {
|
||||
cancelable = lua_toboolean(L, 5);
|
||||
}
|
||||
uint32_t min = 1;
|
||||
if(lua_gettop(L) > 5) {
|
||||
min = (uint32_t)lua_tointeger(L, 6);
|
||||
}
|
||||
uint32_t max = 1;
|
||||
if(lua_gettop(L) > 6) {
|
||||
max = (uint32_t)lua_tointeger(L, 7);
|
||||
}
|
||||
if(min > max)
|
||||
min = max;
|
||||
pduel->game_field->core.select_cards.clear();
|
||||
pduel->game_field->core.unselect_cards.clear();
|
||||
for(auto it = select_group->container.begin(); it != select_group->container.end(); ++it) {
|
||||
pduel->game_field->core.select_cards.push_back(*it);
|
||||
}
|
||||
if(unselect_group) {
|
||||
for(auto it = unselect_group->container.begin(); it != unselect_group->container.end(); ++it) {
|
||||
pduel->game_field->core.unselect_cards.push_back(*it);
|
||||
}
|
||||
}
|
||||
pduel->game_field->add_process(PROCESSOR_SELECT_UNSELECT_CARD, 0, 0, 0, playerid + (cancelable << 16), min + (max << 16), finishable);
|
||||
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32_t status, lua_KContext ctx) {
|
||||
duel* pduel = (duel*)ctx;
|
||||
if(pduel->game_field->returns.ivalue[0] == -1) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
card* pcard;
|
||||
const int32_t index = pduel->game_field->returns.bvalue[1];
|
||||
if(index < (int32_t)pduel->game_field->core.select_cards.size())
|
||||
pcard = pduel->game_field->core.select_cards[index];
|
||||
else
|
||||
pcard = pduel->game_field->core.unselect_cards[index - pduel->game_field->core.select_cards.size()];
|
||||
interpreter::card2value(L, pcard);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
int32_t scriptlib::group_random_select(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
int32_t count = (int32_t)lua_tointeger(L, 3);
|
||||
int32_t no_hint = lua_toboolean(L, 4);
|
||||
duel* pduel = pgroup->pduel;
|
||||
group* newgroup = pduel->new_group();
|
||||
if (count > (int32_t)pgroup->container.size())
|
||||
count = (int32_t)pgroup->container.size();
|
||||
if(count == 0) {
|
||||
interpreter::group2value(L, newgroup);
|
||||
return 1;
|
||||
}
|
||||
if(count == pgroup->container.size())
|
||||
newgroup->container = pgroup->container;
|
||||
else {
|
||||
card_vector cv(pgroup->container.begin(), pgroup->container.end());
|
||||
int32_t back = (int32_t)cv.size() - 1;
|
||||
for (int32_t i = 0; i < count; ++i) {
|
||||
int32_t r = pduel->get_next_integer(i, back);
|
||||
std::swap(cv[i], cv[r]);
|
||||
}
|
||||
newgroup->container.insert(cv.begin(), cv.begin() + count);
|
||||
}
|
||||
if(no_hint) {
|
||||
interpreter::group2value(L, newgroup);
|
||||
return 1;
|
||||
}
|
||||
pduel->write_buffer8(MSG_RANDOM_SELECTED);
|
||||
pduel->write_buffer8(playerid);
|
||||
pduel->write_buffer8(count);
|
||||
for(auto& pcard : newgroup->container) {
|
||||
pduel->write_buffer32(pcard->get_info_location());
|
||||
}
|
||||
interpreter::group2value(L, newgroup);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_cancelable_select(lua_State *L) {
|
||||
check_action_permission(L);
|
||||
check_param_count(L, 5);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card_set cset(pgroup->container);
|
||||
if(check_param(L, PARAM_TYPE_CARD, 5, TRUE)) {
|
||||
card* pexception = *(card**) lua_touserdata(L, 5);
|
||||
cset.erase(pexception);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 5, TRUE)) {
|
||||
group* pexgroup = *(group**) lua_touserdata(L, 5);
|
||||
for(auto& pcard : pexgroup->container)
|
||||
cset.erase(pcard);
|
||||
}
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
if(playerid != 0 && playerid != 1)
|
||||
return 0;
|
||||
uint32_t min = (uint32_t)lua_tointeger(L, 3);
|
||||
uint32_t max = (uint32_t)lua_tointeger(L, 4);
|
||||
pduel->game_field->core.select_cards.clear();
|
||||
for (auto& pcard : cset) {
|
||||
pduel->game_field->core.select_cards.push_back(pcard);
|
||||
}
|
||||
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid + 0x10000, min + (max << 16));
|
||||
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32_t status, lua_KContext ctx) {
|
||||
duel* pduel = (duel*)ctx;
|
||||
if(pduel->game_field->returns.ivalue[0] == -1) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
group* pgroup = pduel->new_group();
|
||||
for(int32_t i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
|
||||
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
|
||||
pgroup->container.insert(pcard);
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
int32_t scriptlib::group_is_exists(lua_State *L) {
|
||||
check_param_count(L, 4);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card_set cset(pgroup->container);
|
||||
if(check_param(L, PARAM_TYPE_CARD, 4, TRUE)) {
|
||||
card* pexception = *(card**) lua_touserdata(L, 4);
|
||||
cset.erase(pexception);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 4, TRUE)) {
|
||||
group* pexgroup = *(group**) lua_touserdata(L, 4);
|
||||
for(auto& pcard : pexgroup->container)
|
||||
cset.erase(pcard);
|
||||
}
|
||||
duel* pduel = pgroup->pduel;
|
||||
uint32_t count = (uint32_t)lua_tointeger(L, 3);
|
||||
uint32_t extraargs = lua_gettop(L) - 4;
|
||||
uint32_t fcount = 0;
|
||||
uint32_t result = FALSE;
|
||||
if (count > pgroup->container.size()) {
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
for (auto& pcard : cset) {
|
||||
if(pduel->lua->check_filter(L, pcard, 2, extraargs)) {
|
||||
++fcount;
|
||||
if(fcount >= count) {
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_pushboolean(L, result);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_check_with_sum_equal(lua_State *L) {
|
||||
check_param_count(L, 5);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t acc = (int32_t)lua_tointeger(L, 3);
|
||||
int32_t min = (int32_t)lua_tointeger(L, 4);
|
||||
int32_t max = (int32_t)lua_tointeger(L, 5);
|
||||
if(min < 0)
|
||||
min = 0;
|
||||
if(max < min)
|
||||
max = min;
|
||||
int32_t extraargs = lua_gettop(L) - 5;
|
||||
card_vector cv(pduel->game_field->core.must_select_cards);
|
||||
int32_t mcount = (int32_t)cv.size();
|
||||
for(auto& pcard : pgroup->container) {
|
||||
auto it = std::find(pduel->game_field->core.must_select_cards.begin(), pduel->game_field->core.must_select_cards.end(), pcard);
|
||||
if(it == pduel->game_field->core.must_select_cards.end())
|
||||
cv.push_back(pcard);
|
||||
}
|
||||
pduel->game_field->core.must_select_cards.clear();
|
||||
for(auto& pcard : cv)
|
||||
pcard->sum_param = pduel->lua->get_operation_value(pcard, 2, extraargs);
|
||||
lua_pushboolean(L, field::check_with_sum_limit_m(cv, acc, 0, min, max, 0xffff, mcount));
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_select_with_sum_equal(lua_State *L) {
|
||||
check_action_permission(L);
|
||||
check_param_count(L, 6);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 3);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
if(playerid != 0 && playerid != 1)
|
||||
return 0;
|
||||
int32_t acc = (int32_t)lua_tointeger(L, 4);
|
||||
int32_t min = (int32_t)lua_tointeger(L, 5);
|
||||
int32_t max = (int32_t)lua_tointeger(L, 6);
|
||||
if(min < 0)
|
||||
min = 0;
|
||||
if(max < min)
|
||||
max = min;
|
||||
if(max > UINT8_MAX)
|
||||
return luaL_error(L, "Parameter \"max\" exceeded 255.");
|
||||
int32_t extraargs = lua_gettop(L) - 6;
|
||||
pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end());
|
||||
for(auto& pcard : pduel->game_field->core.must_select_cards) {
|
||||
auto it = std::remove(pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end(), pcard);
|
||||
pduel->game_field->core.select_cards.erase(it, pduel->game_field->core.select_cards.end());
|
||||
}
|
||||
card_vector cv(pduel->game_field->core.must_select_cards);
|
||||
int32_t mcount = (int32_t)cv.size();
|
||||
cv.insert(cv.end(), pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end());
|
||||
for(auto& pcard : cv)
|
||||
pcard->sum_param = pduel->lua->get_operation_value(pcard, 3, extraargs);
|
||||
if(!field::check_with_sum_limit_m(cv, acc, 0, min, max, 0xffff, mcount)) {
|
||||
pduel->game_field->core.must_select_cards.clear();
|
||||
group* empty_group = pduel->new_group();
|
||||
interpreter::group2value(L, empty_group);
|
||||
return 1;
|
||||
}
|
||||
pduel->game_field->add_process(PROCESSOR_SELECT_SUM, 0, 0, 0, acc, playerid, min, max);
|
||||
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32_t status, lua_KContext ctx) {
|
||||
duel* pduel = (duel*)ctx;
|
||||
group* pgroup = pduel->new_group();
|
||||
int32_t mcount = (int32_t)pduel->game_field->core.must_select_cards.size();
|
||||
for(int32_t i = mcount; i < pduel->game_field->returns.bvalue[0]; ++i) {
|
||||
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
|
||||
pgroup->container.insert(pcard);
|
||||
}
|
||||
pduel->game_field->core.must_select_cards.clear();
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
int32_t scriptlib::group_check_with_sum_greater(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t acc = (int32_t)lua_tointeger(L, 3);
|
||||
int32_t extraargs = lua_gettop(L) - 3;
|
||||
card_vector cv(pduel->game_field->core.must_select_cards);
|
||||
int32_t mcount = (int32_t)cv.size();
|
||||
for(auto& pcard : pgroup->container) {
|
||||
auto it = std::find(pduel->game_field->core.must_select_cards.begin(), pduel->game_field->core.must_select_cards.end(), pcard);
|
||||
if(it == pduel->game_field->core.must_select_cards.end())
|
||||
cv.push_back(pcard);
|
||||
}
|
||||
pduel->game_field->core.must_select_cards.clear();
|
||||
for(auto& pcard : cv)
|
||||
pcard->sum_param = pduel->lua->get_operation_value(pcard, 2, extraargs);
|
||||
lua_pushboolean(L, field::check_with_sum_greater_limit_m(cv, acc, 0, 0xffff, mcount));
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_select_with_sum_greater(lua_State *L) {
|
||||
check_action_permission(L);
|
||||
check_param_count(L, 4);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 3);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t playerid = (int32_t)lua_tointeger(L, 2);
|
||||
if(playerid != 0 && playerid != 1)
|
||||
return 0;
|
||||
int32_t acc = (int32_t)lua_tointeger(L, 4);
|
||||
int32_t extraargs = lua_gettop(L) - 4;
|
||||
pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end());
|
||||
for(auto& pcard : pduel->game_field->core.must_select_cards) {
|
||||
auto it = std::remove(pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end(), pcard);
|
||||
pduel->game_field->core.select_cards.erase(it, pduel->game_field->core.select_cards.end());
|
||||
}
|
||||
card_vector cv(pduel->game_field->core.must_select_cards);
|
||||
int32_t mcount = (int32_t)cv.size();
|
||||
cv.insert(cv.end(), pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end());
|
||||
for(auto& pcard : cv)
|
||||
pcard->sum_param = pduel->lua->get_operation_value(pcard, 3, extraargs);
|
||||
if(!field::check_with_sum_greater_limit_m(cv, acc, 0, 0xffff, mcount)) {
|
||||
pduel->game_field->core.must_select_cards.clear();
|
||||
group* empty_group = pduel->new_group();
|
||||
interpreter::group2value(L, empty_group);
|
||||
return 1;
|
||||
}
|
||||
pduel->game_field->add_process(PROCESSOR_SELECT_SUM, 0, 0, 0, acc, playerid);
|
||||
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32_t status, lua_KContext ctx) {
|
||||
duel* pduel = (duel*)ctx;
|
||||
group* pgroup = pduel->new_group();
|
||||
int32_t mcount = (int32_t)pduel->game_field->core.must_select_cards.size();
|
||||
for(int32_t i = mcount; i < pduel->game_field->returns.bvalue[0]; ++i) {
|
||||
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
|
||||
pgroup->container.insert(pcard);
|
||||
}
|
||||
pduel->game_field->core.must_select_cards.clear();
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
int32_t scriptlib::group_get_min_group(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
if(pgroup->container.size() == 0)
|
||||
return 0;
|
||||
group* newgroup = pduel->new_group();
|
||||
int32_t min, op;
|
||||
int32_t extraargs = lua_gettop(L) - 2;
|
||||
auto cit = pgroup->container.begin();
|
||||
min = pduel->lua->get_operation_value(*cit, 2, extraargs);
|
||||
newgroup->container.insert(*cit);
|
||||
++cit;
|
||||
for(; cit != pgroup->container.end(); ++cit) {
|
||||
op = pduel->lua->get_operation_value(*cit, 2, extraargs);
|
||||
if(op == min)
|
||||
newgroup->container.insert(*cit);
|
||||
else if(op < min) {
|
||||
newgroup->container.clear();
|
||||
newgroup->container.insert(*cit);
|
||||
min = op;
|
||||
}
|
||||
}
|
||||
interpreter::group2value(L, newgroup);
|
||||
lua_pushinteger(L, min);
|
||||
return 2;
|
||||
}
|
||||
int32_t scriptlib::group_get_max_group(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
if(pgroup->container.size() == 0)
|
||||
return 0;
|
||||
group* newgroup = pduel->new_group();
|
||||
int32_t max, op;
|
||||
int32_t extraargs = lua_gettop(L) - 2;
|
||||
auto cit = pgroup->container.begin();
|
||||
max = pduel->lua->get_operation_value(*cit, 2, extraargs);
|
||||
newgroup->container.insert(*cit);
|
||||
++cit;
|
||||
for(; cit != pgroup->container.end(); ++cit) {
|
||||
op = pduel->lua->get_operation_value(*cit, 2, extraargs);
|
||||
if(op == max)
|
||||
newgroup->container.insert(*cit);
|
||||
else if(op > max) {
|
||||
newgroup->container.clear();
|
||||
newgroup->container.insert(*cit);
|
||||
max = op;
|
||||
}
|
||||
}
|
||||
interpreter::group2value(L, newgroup);
|
||||
lua_pushinteger(L, max);
|
||||
return 2;
|
||||
}
|
||||
int32_t scriptlib::group_get_sum(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t extraargs = lua_gettop(L) - 2;
|
||||
int32_t sum = 0;
|
||||
for(auto& pcard : pgroup->container) {
|
||||
sum += pduel->lua->get_operation_value(pcard, 2, extraargs);
|
||||
}
|
||||
lua_pushinteger(L, sum);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_get_class_count(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t extraargs = lua_gettop(L) - 2;
|
||||
std::set<uint32_t> er;
|
||||
for(auto& pcard : pgroup->container) {
|
||||
er.insert(pduel->lua->get_operation_value(pcard, 2, extraargs));
|
||||
}
|
||||
lua_pushinteger(L, er.size());
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_remove(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
card* pexception = nullptr;
|
||||
if(!lua_isnil(L, 3)) {
|
||||
check_param(L, PARAM_TYPE_CARD, 3);
|
||||
pexception = *(card**) lua_touserdata(L, 3);
|
||||
}
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
uint32_t extraargs = lua_gettop(L) - 3;
|
||||
if(pgroup->is_readonly == GTYPE_READ_ONLY)
|
||||
return 0;
|
||||
pgroup->is_iterator_dirty = true;
|
||||
for (auto cit = pgroup->container.begin(); cit != pgroup->container.end();) {
|
||||
if((*cit) != pexception && pduel->lua->check_filter(L, *cit, 2, extraargs)) {
|
||||
cit = pgroup->container.erase(cit);
|
||||
}
|
||||
else
|
||||
++cit;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::group_equal(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
group* sgroup = *(group**) lua_touserdata(L, 2);
|
||||
if(pgroup->container.size() != sgroup->container.size()) {
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
auto pit = pgroup->container.begin();
|
||||
auto sit = sgroup->container.begin();
|
||||
for (; pit != pgroup->container.end(); ++pit, ++sit) {
|
||||
if((*pit) != (*sit)) {
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pushboolean(L, 1);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_is_contains(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_CARD, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
card* pcard = *(card**) lua_touserdata(L, 2);
|
||||
if(pgroup->container.find(pcard) != pgroup->container.end())
|
||||
lua_pushboolean(L, 1);
|
||||
else
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_search_card(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
uint32_t extraargs = lua_gettop(L) - 2;
|
||||
for (auto& pcard : pgroup->container) {
|
||||
if (pduel->lua->check_filter(L, pcard, 2, extraargs)) {
|
||||
interpreter::card2value(L, pcard);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t scriptlib::group_get_bin_class_count(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
check_param(L, PARAM_TYPE_FUNCTION, 2);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
duel* pduel = pgroup->pduel;
|
||||
int32_t extraargs = lua_gettop(L) - 2;
|
||||
int32_t er = 0;
|
||||
for(auto& pcard : pgroup->container) {
|
||||
er |= pduel->lua->get_operation_value(pcard, 2, extraargs);
|
||||
}
|
||||
int32_t ans = 0;
|
||||
while(er) {
|
||||
er &= er - 1;
|
||||
++ans;
|
||||
}
|
||||
lua_pushinteger(L, ans);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_get_meta_value(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
return pgroup->meta.luaop_get(L, 1);
|
||||
}
|
||||
int32_t scriptlib::group_set_meta_value(lua_State *L) {
|
||||
check_param_count(L, 3);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
return pgroup->meta.luaop_set(L, 1);
|
||||
}
|
||||
int32_t scriptlib::group_has_meta_value(lua_State *L) {
|
||||
check_param_count(L, 2);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
return pgroup->meta.luaop_has(L, 1);
|
||||
}
|
||||
int32_t scriptlib::group_get_meta_keys(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
return pgroup->meta.luaop_keys(L);
|
||||
}
|
||||
int32_t scriptlib::group_clear_meta(lua_State *L) {
|
||||
check_param_count(L, 1);
|
||||
check_param(L, PARAM_TYPE_GROUP, 1);
|
||||
group* pgroup = *(group**) lua_touserdata(L, 1);
|
||||
return pgroup->meta.luaop_clear();
|
||||
}
|
||||
int32_t scriptlib::group_meta_add(lua_State* L) {
|
||||
check_param_count(L, 2);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 1, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 1, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 1);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 2, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 2, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = pduel->new_group();
|
||||
if(check_param(L, PARAM_TYPE_CARD, 1, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 1);
|
||||
pgroup->container.insert(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 1, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 1);
|
||||
for(auto cit = cgroup->container.begin(); cit != cgroup->container.end(); ++cit)
|
||||
pgroup->container.insert(*cit);
|
||||
}
|
||||
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 2);
|
||||
pgroup->container.insert(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 2);
|
||||
for(auto cit = cgroup->container.begin(); cit != cgroup->container.end(); ++cit)
|
||||
pgroup->container.insert(*cit);
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_meta_sub(lua_State* L) {
|
||||
check_param_count(L, 2);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 1, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 1, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 1);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 2, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 2, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = pduel->new_group();
|
||||
if(check_param(L, PARAM_TYPE_CARD, 1, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 1);
|
||||
pgroup->container.insert(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 1, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 1);
|
||||
for(auto cit = cgroup->container.begin(); cit != cgroup->container.end(); ++cit)
|
||||
pgroup->container.insert(*cit);
|
||||
}
|
||||
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 2);
|
||||
pgroup->container.erase(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 2);
|
||||
for(auto cit = cgroup->container.begin(); cit != cgroup->container.end(); ++cit)
|
||||
pgroup->container.erase(*cit);
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_meta_band(lua_State* L) {
|
||||
check_param_count(L, 2);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 1, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 1, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 1);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 2, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 2, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = pduel->new_group();
|
||||
card_set check_set;
|
||||
if(check_param(L, PARAM_TYPE_CARD, 1, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 1);
|
||||
check_set.insert(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 1, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 1);
|
||||
check_set = cgroup->container;
|
||||
}
|
||||
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 2);
|
||||
if(check_set.find(ccard) != check_set.end())
|
||||
pgroup->container.insert(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 2);
|
||||
for(auto cit = cgroup->container.begin(); cit != cgroup->container.end(); ++cit)
|
||||
if(check_set.find(*cit) != check_set.end())
|
||||
pgroup->container.insert(*cit);
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
}
|
||||
int32_t scriptlib::group_meta_bxor(lua_State* L) {
|
||||
check_param_count(L, 2);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 1, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 1, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 1);
|
||||
if(!check_param(L, PARAM_TYPE_CARD, 2, TRUE) && !check_param(L, PARAM_TYPE_GROUP, 2, TRUE))
|
||||
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2);
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
group* pgroup = pduel->new_group();
|
||||
if(check_param(L, PARAM_TYPE_CARD, 1, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 1);
|
||||
pgroup->container.insert(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 1, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 1);
|
||||
for(auto cit = cgroup->container.begin(); cit != cgroup->container.end(); ++cit)
|
||||
pgroup->container.insert(*cit);
|
||||
}
|
||||
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
|
||||
card* ccard = *(card**) lua_touserdata(L, 2);
|
||||
if(pgroup->container.find(ccard) != pgroup->container.end())
|
||||
pgroup->container.erase(ccard);
|
||||
else
|
||||
pgroup->container.insert(ccard);
|
||||
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
|
||||
group* cgroup = *(group**) lua_touserdata(L, 2);
|
||||
for(auto cit = cgroup->container.begin(); cit != cgroup->container.end(); ++cit) {
|
||||
if(pgroup->container.find(*cit) != pgroup->container.end())
|
||||
pgroup->container.erase(*cit);
|
||||
else
|
||||
pgroup->container.insert(*cit);
|
||||
}
|
||||
}
|
||||
interpreter::group2value(L, pgroup);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg grouplib[] = {
|
||||
{ "CreateGroup", scriptlib::group_new },
|
||||
{ "FromCards", scriptlib::group_new },
|
||||
{ "KeepAlive", scriptlib::group_keep_alive },
|
||||
{ "DeleteGroup", scriptlib::group_delete },
|
||||
{ "Clone", scriptlib::group_clone },
|
||||
{ "Clear", scriptlib::group_clear },
|
||||
{ "AddCard", scriptlib::group_add_card },
|
||||
{ "Merge", scriptlib::group_add_card },
|
||||
{ "RemoveCard", scriptlib::group_remove_card },
|
||||
{ "Sub", scriptlib::group_remove_card },
|
||||
{ "GetNext", scriptlib::group_get_next },
|
||||
{ "GetFirst", scriptlib::group_get_first },
|
||||
{ "GetCount", scriptlib::group_get_count },
|
||||
{ "__len", scriptlib::group_get_count },
|
||||
{ "Filter", scriptlib::group_filter },
|
||||
{ "FilterCount", scriptlib::group_filter_count },
|
||||
{ "FilterSelect", scriptlib::group_filter_select },
|
||||
{ "Select", scriptlib::group_select },
|
||||
{ "SelectUnselect", scriptlib::group_select_unselect },
|
||||
{ "RandomSelect", scriptlib::group_random_select },
|
||||
{ "CancelableSelect", scriptlib::group_cancelable_select },
|
||||
{ "IsExists", scriptlib::group_is_exists },
|
||||
{ "CheckWithSumEqual", scriptlib::group_check_with_sum_equal },
|
||||
{ "SelectWithSumEqual", scriptlib::group_select_with_sum_equal },
|
||||
{ "CheckWithSumGreater", scriptlib::group_check_with_sum_greater },
|
||||
{ "SelectWithSumGreater", scriptlib::group_select_with_sum_greater },
|
||||
{ "GetMinGroup", scriptlib::group_get_min_group },
|
||||
{ "GetMaxGroup", scriptlib::group_get_max_group },
|
||||
{ "GetSum", scriptlib::group_get_sum },
|
||||
{ "GetClassCount", scriptlib::group_get_class_count },
|
||||
{ "Remove", scriptlib::group_remove },
|
||||
{ "Equal", scriptlib::group_equal },
|
||||
{ "IsContains", scriptlib::group_is_contains },
|
||||
{ "SearchCard", scriptlib::group_search_card },
|
||||
{ "GetBinClassCount", scriptlib::group_get_bin_class_count },
|
||||
{ "GetMetaValue", scriptlib::group_get_meta_value },
|
||||
{ "SetMetaValue", scriptlib::group_set_meta_value },
|
||||
{ "HasMetaValue", scriptlib::group_has_meta_value },
|
||||
{ "ClearMeta", scriptlib::group_clear_meta },
|
||||
{ "GetMetaKeys", scriptlib::group_get_meta_keys },
|
||||
{ "__add", scriptlib::group_meta_add },
|
||||
{ "__bor", scriptlib::group_meta_add },
|
||||
{ "__sub", scriptlib::group_meta_sub },
|
||||
{ "__band", scriptlib::group_meta_band },
|
||||
{ "__bxor", scriptlib::group_meta_bxor },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
void scriptlib::open_grouplib(lua_State *L) {
|
||||
luaL_newlib(L, grouplib);
|
||||
lua_pushstring(L, "__index");
|
||||
lua_pushvalue(L, -2);
|
||||
lua_rawset(L, -3);
|
||||
lua_setglobal(L, "Group");
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
#include "lua_coverage.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <lauxlib.h>
|
||||
#include "buffer.h"
|
||||
#include "duel.h"
|
||||
#include "interpreter.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool starts_with(const std::string& text, const char* prefix) {
|
||||
const size_t len = std::strlen(prefix);
|
||||
return text.size() >= len && text.compare(0, len, prefix) == 0;
|
||||
}
|
||||
|
||||
std::vector<std::pair<int32_t, uint32_t>> sorted_hits(const lua_coverage_file& file) {
|
||||
std::vector<std::pair<int32_t, uint32_t>> records;
|
||||
records.reserve(file.line_hits.size());
|
||||
for (const auto& hit : file.line_hits)
|
||||
records.emplace_back(hit.first, hit.second);
|
||||
std::sort(records.begin(), records.end(), [](const auto& left, const auto& right) {
|
||||
return left.first < right.first;
|
||||
});
|
||||
return records;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string lua_coverage_state::normalize_name(const char* source) {
|
||||
std::string name = source ? source : "";
|
||||
if (!name.empty() && name[0] == '@')
|
||||
name.erase(0, 1);
|
||||
std::replace(name.begin(), name.end(), '\\', '/');
|
||||
if (starts_with(name, "./script/"))
|
||||
name.erase(0, std::strlen("./script/"));
|
||||
else if (starts_with(name, "script/"))
|
||||
name.erase(0, std::strlen("script/"));
|
||||
else if (starts_with(name, "./"))
|
||||
name.erase(0, std::strlen("./"));
|
||||
return name;
|
||||
}
|
||||
|
||||
void lua_coverage_state::line_hook(lua_State* L, lua_Debug* ar) {
|
||||
if (ar->event != LUA_HOOKLINE || ar->currentline <= 0)
|
||||
return;
|
||||
duel* pd = interpreter::get_duel_info(L);
|
||||
if (!pd || !pd->lua || !pd->lua->lua_coverage.enabled)
|
||||
return;
|
||||
lua_getinfo(L, "S", ar);
|
||||
pd->lua->lua_coverage.record(ar->source, ar->currentline);
|
||||
}
|
||||
|
||||
void lua_coverage_state::enable(lua_State* L) {
|
||||
enabled = true;
|
||||
install_hook(L);
|
||||
}
|
||||
|
||||
void lua_coverage_state::install_hook(lua_State* L) const {
|
||||
if (enabled)
|
||||
lua_sethook(L, lua_coverage_state::line_hook, LUA_MASKLINE, 0);
|
||||
}
|
||||
|
||||
void lua_coverage_state::record(const char* source, int32_t line) {
|
||||
if (!enabled || line <= 0)
|
||||
return;
|
||||
auto name = normalize_name(source);
|
||||
if (name.empty())
|
||||
return;
|
||||
auto& file = files[name];
|
||||
if (file.name.empty())
|
||||
file.name = name;
|
||||
auto& count = file.line_hits[line];
|
||||
if (count != UINT32_MAX)
|
||||
++count;
|
||||
}
|
||||
|
||||
void lua_coverage_state::clear(const char* name) {
|
||||
files.erase(normalize_name(name));
|
||||
}
|
||||
|
||||
void lua_coverage_state::clear_all() {
|
||||
files.clear();
|
||||
}
|
||||
|
||||
int32_t lua_coverage_state::get_dump_size(const char* name) const {
|
||||
if (!enabled)
|
||||
return 0;
|
||||
const auto it = files.find(normalize_name(name));
|
||||
if (it == files.end())
|
||||
return 0;
|
||||
return static_cast<int32_t>(it->second.line_hits.size() * sizeof(uint32_t) * 2);
|
||||
}
|
||||
|
||||
int32_t lua_coverage_state::dump(const char* name, byte* out_buf, int32_t out_len) const {
|
||||
const auto required = get_dump_size(name);
|
||||
if (required <= 0)
|
||||
return 0;
|
||||
if (out_len < required)
|
||||
return required;
|
||||
const auto it = files.find(normalize_name(name));
|
||||
if (it == files.end())
|
||||
return 0;
|
||||
byte* p = out_buf;
|
||||
for (const auto& hit : sorted_hits(it->second)) {
|
||||
buffer_write<uint32_t>(p, static_cast<uint32_t>(hit.first));
|
||||
buffer_write<uint32_t>(p, hit.second);
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
int32_t lua_coverage_state::get_all_dump_size() const {
|
||||
if (!enabled || files.empty())
|
||||
return 0;
|
||||
size_t size = sizeof(uint32_t);
|
||||
for (const auto& entry : files) {
|
||||
size += sizeof(uint16_t);
|
||||
size += entry.first.size();
|
||||
size += sizeof(uint32_t);
|
||||
size += entry.second.line_hits.size() * sizeof(uint32_t) * 2;
|
||||
}
|
||||
return static_cast<int32_t>(size);
|
||||
}
|
||||
|
||||
int32_t lua_coverage_state::dump_all(byte* out_buf, int32_t out_len) const {
|
||||
const auto required = get_all_dump_size();
|
||||
if (required <= 0)
|
||||
return 0;
|
||||
if (out_len < required)
|
||||
return required;
|
||||
|
||||
std::vector<const lua_coverage_file*> ordered;
|
||||
ordered.reserve(files.size());
|
||||
for (const auto& entry : files)
|
||||
ordered.push_back(&entry.second);
|
||||
std::sort(ordered.begin(), ordered.end(), [](const auto* left, const auto* right) {
|
||||
return left->name < right->name;
|
||||
});
|
||||
|
||||
byte* p = out_buf;
|
||||
buffer_write<uint32_t>(p, static_cast<uint32_t>(ordered.size()));
|
||||
for (const auto* file : ordered) {
|
||||
const auto name_length = static_cast<uint16_t>(file->name.size());
|
||||
buffer_write<uint16_t>(p, name_length);
|
||||
buffer_write_block(p, file->name.data(), name_length);
|
||||
const auto hits = sorted_hits(*file);
|
||||
buffer_write<uint32_t>(p, static_cast<uint32_t>(hits.size()));
|
||||
for (const auto& hit : hits) {
|
||||
buffer_write<uint32_t>(p, static_cast<uint32_t>(hit.first));
|
||||
buffer_write<uint32_t>(p, hit.second);
|
||||
}
|
||||
}
|
||||
return required;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef LUA_COVERAGE_H_
|
||||
#define LUA_COVERAGE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <lua.h>
|
||||
#include "common.h"
|
||||
|
||||
struct lua_coverage_file {
|
||||
std::string name;
|
||||
std::unordered_map<int32_t, uint32_t> line_hits;
|
||||
};
|
||||
|
||||
class lua_coverage_state {
|
||||
public:
|
||||
bool enabled{};
|
||||
std::unordered_map<std::string, lua_coverage_file> files;
|
||||
|
||||
static std::string normalize_name(const char* source);
|
||||
static void line_hook(lua_State* L, lua_Debug* ar);
|
||||
|
||||
void enable(lua_State* L);
|
||||
void install_hook(lua_State* L) const;
|
||||
void record(const char* source, int32_t line);
|
||||
void clear(const char* name);
|
||||
void clear_all();
|
||||
|
||||
int32_t get_dump_size(const char* name) const;
|
||||
int32_t dump(const char* name, byte* out_buf, int32_t out_len) const;
|
||||
int32_t get_all_dump_size() const;
|
||||
int32_t dump_all(byte* out_buf, int32_t out_len) const;
|
||||
};
|
||||
|
||||
#endif /* LUA_COVERAGE_H_ */
|
||||
@@ -0,0 +1,231 @@
|
||||
#include "metadata.h"
|
||||
#include "interpreter.h"
|
||||
#include "scriptlib.h"
|
||||
#include <cstring>
|
||||
|
||||
metadata_entry::metadata_entry() {
|
||||
type = PARAM_TYPE_INT;
|
||||
value = 0;
|
||||
}
|
||||
|
||||
metadata_entry::~metadata_entry() {
|
||||
reset();
|
||||
}
|
||||
|
||||
metadata_entry::metadata_entry(metadata_entry&& other) noexcept {
|
||||
type = other.type;
|
||||
value = other.value;
|
||||
other.type = PARAM_TYPE_INT;
|
||||
other.value = 0;
|
||||
}
|
||||
|
||||
metadata_entry& metadata_entry::operator=(metadata_entry&& other) noexcept {
|
||||
if (this != &other) {
|
||||
reset();
|
||||
type = other.type;
|
||||
value = other.value;
|
||||
other.type = PARAM_TYPE_INT;
|
||||
other.value = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
int32_t metadata_entry::luaop_get(lua_State *L) {
|
||||
if (type == PARAM_TYPE_INT) {
|
||||
lua_pushinteger(L, static_cast<int32_t>(value));
|
||||
return 1;
|
||||
}
|
||||
if (type == PARAM_TYPE_INDEX) {
|
||||
lua_pushnumber(L, *reinterpret_cast<double*>(value));
|
||||
return 1;
|
||||
}
|
||||
if (type == PARAM_TYPE_STRING) {
|
||||
lua_pushstring(L, reinterpret_cast<const char*>(value));
|
||||
return 1;
|
||||
}
|
||||
if (type == PARAM_TYPE_BOOLEAN) {
|
||||
lua_pushboolean(L, value != 0);
|
||||
return 1;
|
||||
}
|
||||
if (type == PARAM_TYPE_CARD) {
|
||||
interpreter::card2value(L, reinterpret_cast<card*>(value));
|
||||
return 1;
|
||||
}
|
||||
if (type == PARAM_TYPE_GROUP) {
|
||||
interpreter::group2value(L, reinterpret_cast<group*>(value));
|
||||
return 1;
|
||||
}
|
||||
if (type == PARAM_TYPE_EFFECT) {
|
||||
interpreter::effect2value(L, reinterpret_cast<effect*>(value));
|
||||
return 1;
|
||||
}
|
||||
if (type == PARAM_TYPE_FUNCTION) {
|
||||
interpreter::function2value(L, value);
|
||||
return 1;
|
||||
}
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t metadata_entry::luaop_set(lua_State *L, int32_t index) {
|
||||
reset();
|
||||
if (lua_isnil(L, index)) {
|
||||
// should never reach here because nil would remove the entry
|
||||
value = 0;
|
||||
type = PARAM_TYPE_INT;
|
||||
return 0;
|
||||
}
|
||||
if (lua_isboolean(L, index)) {
|
||||
value = lua_toboolean(L, index);
|
||||
type = PARAM_TYPE_BOOLEAN;
|
||||
return 0;
|
||||
}
|
||||
if (lua_isinteger(L, index)) {
|
||||
value = lua_tointeger(L, index);
|
||||
type = PARAM_TYPE_INT;
|
||||
return 0;
|
||||
}
|
||||
if (lua_isnumber(L, index)) {
|
||||
auto num = lua_tonumber(L, index);
|
||||
auto saved_num = new double(num);
|
||||
value = reinterpret_cast<intptr_t>(saved_num);
|
||||
type = PARAM_TYPE_INDEX;
|
||||
return 0;
|
||||
}
|
||||
if (lua_isstring(L, index)) {
|
||||
auto str = lua_tostring(L, index);
|
||||
auto saved_str = new char[strlen(str) + 1];
|
||||
strcpy(saved_str, str);
|
||||
value = reinterpret_cast<intptr_t>(saved_str);
|
||||
type = PARAM_TYPE_STRING;
|
||||
return 0;
|
||||
}
|
||||
if(lua_isfunction(L, index)) {
|
||||
value = interpreter::get_function_handle(L, index);
|
||||
type = PARAM_TYPE_FUNCTION;
|
||||
return 0;
|
||||
}
|
||||
if (lua_isuserdata(L, index)) {
|
||||
void* raw_ud = lua_touserdata(L, index);
|
||||
void* obj = *(void**)raw_ud;
|
||||
|
||||
LuaParamType type_list[] = {
|
||||
PARAM_TYPE_CARD,
|
||||
PARAM_TYPE_GROUP,
|
||||
PARAM_TYPE_EFFECT
|
||||
};
|
||||
|
||||
for (auto t : type_list) {
|
||||
if (scriptlib::check_param(L, t, index, TRUE)) {
|
||||
value = reinterpret_cast<intptr_t>(obj);
|
||||
type = t;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return luaL_error(L, "Unsupported userdata for metadata entry.");
|
||||
}
|
||||
|
||||
return luaL_error(L, "Unsupported type for metadata entry.");
|
||||
}
|
||||
|
||||
void metadata_entry::copy_from(const metadata_entry& other) {
|
||||
type = other.type;
|
||||
switch (type) {
|
||||
case PARAM_TYPE_STRING: {
|
||||
const char* str = reinterpret_cast<const char*>(other.value);
|
||||
char* dup = new char[strlen(str) + 1];
|
||||
strcpy(dup, str);
|
||||
value = reinterpret_cast<intptr_t>(dup);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_INDEX: {
|
||||
const double* pd = reinterpret_cast<const double*>(other.value);
|
||||
value = reinterpret_cast<intptr_t>(new double(*pd));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// for int, bool, function handle, and userdata pointer types
|
||||
value = other.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
metadata_entry::metadata_entry(const metadata_entry& other) {
|
||||
copy_from(other);
|
||||
}
|
||||
|
||||
metadata_entry& metadata_entry::operator=(const metadata_entry& other) {
|
||||
if (this != &other) {
|
||||
reset();
|
||||
copy_from(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void metadata_entry::reset() {
|
||||
if (type == PARAM_TYPE_STRING) {
|
||||
delete[] reinterpret_cast<char*>(value);
|
||||
} else if (type == PARAM_TYPE_INDEX) {
|
||||
delete reinterpret_cast<double*>(value);
|
||||
}
|
||||
value = 0;
|
||||
type = PARAM_TYPE_INT;
|
||||
}
|
||||
|
||||
int32_t metadata::luaop_clear() {
|
||||
entries.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t metadata::luaop_get(lua_State *L, int32_t offset) {
|
||||
scriptlib::check_param_count(L, 1 + offset);
|
||||
scriptlib::check_param(L, PARAM_TYPE_STRING, 1 + offset);
|
||||
auto key = lua_tostring(L, 1 + offset);
|
||||
auto it = entries.find(key);
|
||||
if (it == entries.end()) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
return it->second.luaop_get(L);
|
||||
}
|
||||
|
||||
int32_t metadata::luaop_set(lua_State *L, int32_t offset) {
|
||||
scriptlib::check_param_count(L, 2 + offset);
|
||||
scriptlib::check_param(L, PARAM_TYPE_STRING, 1 + offset);
|
||||
auto key = lua_tostring(L, 1 + offset);
|
||||
|
||||
if(lua_isnil(L, 2 + offset)) {
|
||||
entries.erase(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto existing = entries.find(key);
|
||||
if (existing != entries.end()) {
|
||||
return existing->second.luaop_set(L, 2 + offset);
|
||||
}
|
||||
|
||||
entries[key] = metadata_entry();
|
||||
return entries[key].luaop_set(L, 2 + offset);
|
||||
}
|
||||
|
||||
int32_t metadata::luaop_has(lua_State *L, int32_t offset) {
|
||||
scriptlib::check_param_count(L, 1 + offset);
|
||||
scriptlib::check_param(L, PARAM_TYPE_STRING, 1 + offset);
|
||||
auto key = lua_tostring(L, 1 + offset);
|
||||
lua_pushboolean(L, entries.find(key) != entries.end());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t metadata::luaop_keys(lua_State *L) {
|
||||
if(entries.empty()) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t count = 0;
|
||||
for (const auto& pair : entries) {
|
||||
lua_pushstring(L, pair.first.c_str());
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef METADATA_H_
|
||||
#define METADATA_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <lua.h>
|
||||
|
||||
class metadata_entry {
|
||||
public:
|
||||
metadata_entry();
|
||||
~metadata_entry();
|
||||
|
||||
metadata_entry(const metadata_entry& other);
|
||||
metadata_entry& operator=(const metadata_entry& other);
|
||||
|
||||
metadata_entry(metadata_entry&& other) noexcept;
|
||||
metadata_entry& operator=(metadata_entry&& other) noexcept;
|
||||
|
||||
int32_t luaop_get(lua_State *L);
|
||||
int32_t luaop_set(lua_State *L, int32_t index);
|
||||
|
||||
private:
|
||||
void reset();
|
||||
void copy_from(const metadata_entry& other);
|
||||
LuaParamType type;
|
||||
intptr_t value;
|
||||
};
|
||||
|
||||
using metadata_entry_map = std::unordered_map<std::string, metadata_entry>;
|
||||
|
||||
class metadata {
|
||||
public:
|
||||
int32_t luaop_clear();
|
||||
int32_t luaop_get(lua_State *L, int32_t offset = 0);
|
||||
int32_t luaop_set(lua_State *L, int32_t offset = 0);
|
||||
int32_t luaop_has(lua_State *L, int32_t offset = 0);
|
||||
int32_t luaop_keys(lua_State *L);
|
||||
|
||||
private:
|
||||
metadata_entry_map entries;
|
||||
};
|
||||
|
||||
#endif /* METADATA_H_ */
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* mtrandom.h
|
||||
*
|
||||
* Created on: 2009-10-18
|
||||
* Author: Argon.Sun
|
||||
*/
|
||||
|
||||
#ifndef MTRANDOM_H_
|
||||
#define MTRANDOM_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
class mtrandom {
|
||||
public:
|
||||
const unsigned int rand_max{ std::mt19937::max() };
|
||||
|
||||
mtrandom() = default;
|
||||
explicit mtrandom(uint_fast32_t value)
|
||||
: rng(value) {}
|
||||
explicit mtrandom(std::seed_seq& q)
|
||||
: rng(q) {}
|
||||
explicit mtrandom(std::seed_seq&& q)
|
||||
: rng(q) {}
|
||||
mtrandom(const uint32_t seq[], size_t len)
|
||||
: mtrandom(std::seed_seq(seq, seq + len)) {}
|
||||
|
||||
mtrandom(const mtrandom& other) = delete;
|
||||
void operator=(const mtrandom& other) = delete;
|
||||
|
||||
// mersenne_twister_engine
|
||||
void seed(const uint32_t seq[], size_t len) {
|
||||
std::seed_seq q(seq, seq + len);
|
||||
rng.seed(q);
|
||||
}
|
||||
void seed(uint_fast32_t value) {
|
||||
rng.seed(value);
|
||||
}
|
||||
void seed(std::seed_seq& q) {
|
||||
rng.seed(q);
|
||||
}
|
||||
uint_fast32_t rand() {
|
||||
return rng();
|
||||
}
|
||||
void discard(unsigned long long z) {
|
||||
rng.discard(z);
|
||||
}
|
||||
|
||||
// old vesion, discard too many numbers
|
||||
int get_random_integer_v1(int l, int h) {
|
||||
uint32_t range = (h - l + 1);
|
||||
uint32_t secureMax = rand_max - rand_max % range;
|
||||
uint_fast32_t x;
|
||||
do {
|
||||
x = rng();
|
||||
} while (x >= secureMax);
|
||||
return l + (int)(x % range);
|
||||
}
|
||||
|
||||
#pragma warning(disable:4146)
|
||||
// N % k = (N - k) % k = (-k) % k
|
||||
// discard (N % range) numbers from the left end so that it is a multiple of range
|
||||
int get_random_integer_v2(int l, int h) {
|
||||
uint32_t range = (h - l + 1);
|
||||
uint32_t bound = -range % range;
|
||||
auto x = rng();
|
||||
while (x < bound) {
|
||||
x = rng();
|
||||
}
|
||||
return l + (int)(x % range);
|
||||
}
|
||||
#pragma warning(default:4146)
|
||||
|
||||
// Fisher-Yates shuffle [first, last)
|
||||
template<typename T>
|
||||
void shuffle_vector(std::vector<T>& v, int first, int last, int version) {
|
||||
if ((size_t)last > v.size())
|
||||
last = (int)v.size();
|
||||
auto shuffle = [&](auto&& distribution) {
|
||||
for (int i = first; i < last - 1; ++i) {
|
||||
int r = distribution(i, last - 1);
|
||||
std::swap(v[i], v[r]);
|
||||
}
|
||||
};
|
||||
if (version == 1)
|
||||
shuffle([this](int l, int h) { return get_random_integer_v1(l, h); });
|
||||
else
|
||||
shuffle([this](int l, int h) { return get_random_integer_v2(l, h); });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void shuffle_vector(std::vector<T>& v) {
|
||||
shuffle_vector(v, 0, (int)v.size(), 2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void shuffle_vector(std::vector<T>& v, int first, int last) {
|
||||
shuffle_vector(v, first, last, 2);
|
||||
}
|
||||
|
||||
private:
|
||||
std::mt19937 rng;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MTRANDOM_H_ */
|
||||
+830
@@ -0,0 +1,830 @@
|
||||
/*
|
||||
* interface.cpp
|
||||
*
|
||||
* Created on: 2010-5-2
|
||||
* Author: Argon
|
||||
*/
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include "ocgapi.h"
|
||||
#include "duel.h"
|
||||
#include "card.h"
|
||||
#include "group.h"
|
||||
#include "effect.h"
|
||||
#include "field.h"
|
||||
#include "interpreter.h"
|
||||
#include "buffer.h"
|
||||
|
||||
static uint32_t default_card_reader(uint32_t code, card_data* data) {
|
||||
return 0;
|
||||
}
|
||||
static uint32_t default_message_handler(intptr_t pduel, uint32_t message_type) {
|
||||
return 0;
|
||||
}
|
||||
static script_reader sreader = default_script_reader;
|
||||
static card_reader creader = default_card_reader;
|
||||
static message_handler mhandler = default_message_handler;
|
||||
static byte buffer[0x100000];
|
||||
static std::set<duel*> duel_set;
|
||||
|
||||
OCGCORE_API void set_script_reader(script_reader f) {
|
||||
sreader = f;
|
||||
}
|
||||
OCGCORE_API void set_card_reader(card_reader f) {
|
||||
creader = f;
|
||||
}
|
||||
OCGCORE_API void set_message_handler(message_handler f) {
|
||||
mhandler = f;
|
||||
}
|
||||
byte* read_script(const char* script_name, int* len) {
|
||||
return sreader(script_name, len);
|
||||
}
|
||||
uint32_t read_card(uint32_t code, card_data* data) {
|
||||
if (code == TEMP_CARD_ID) {
|
||||
data->clear();
|
||||
return 0;
|
||||
}
|
||||
return creader(code, data);
|
||||
}
|
||||
uint32_t handle_message(void* pduel, uint32_t message_type) {
|
||||
return mhandler((intptr_t)pduel, message_type);
|
||||
}
|
||||
OCGCORE_API byte* default_script_reader(const char* script_name, int* slen) {
|
||||
FILE *fp;
|
||||
fp = std::fopen(script_name, "rb");
|
||||
if (!fp)
|
||||
return nullptr;
|
||||
size_t len = std::fread(buffer, 1, sizeof buffer, fp);
|
||||
std::fclose(fp);
|
||||
if (len >= sizeof buffer)
|
||||
return nullptr;
|
||||
*slen = (int)len;
|
||||
return buffer;
|
||||
}
|
||||
OCGCORE_API intptr_t create_duel(uint_fast32_t seed) {
|
||||
return create_duel_ex(seed, 0);
|
||||
}
|
||||
OCGCORE_API intptr_t create_duel_ex(uint_fast32_t seed, uint32_t create_flags) {
|
||||
duel* pduel = new duel(create_flags);
|
||||
duel_set.insert(pduel);
|
||||
pduel->random.seed(seed);
|
||||
pduel->rng_version = 1;
|
||||
pduel->lua->preloaded = FALSE;
|
||||
return (intptr_t)pduel;
|
||||
}
|
||||
OCGCORE_API intptr_t create_duel_v2(uint32_t seed_sequence[]) {
|
||||
return create_duel_v2_ex(seed_sequence, 0);
|
||||
}
|
||||
OCGCORE_API intptr_t create_duel_v2_ex(uint32_t seed_sequence[], uint32_t create_flags) {
|
||||
duel* pduel = new duel(create_flags);
|
||||
duel_set.insert(pduel);
|
||||
pduel->random.seed(seed_sequence, SEED_COUNT);
|
||||
pduel->rng_version = 2;
|
||||
pduel->lua->preloaded = FALSE;
|
||||
return (intptr_t)pduel;
|
||||
}
|
||||
OCGCORE_API void start_duel(intptr_t pduel, uint32_t options) {
|
||||
duel* pd = (duel*)pduel;
|
||||
if(!pd->lua->preloaded) {
|
||||
pd->lua->preloaded = TRUE;
|
||||
pd->lua->call_code_function(0, (char*) "PreloadUds", 0, 0);
|
||||
}
|
||||
uint16_t duel_rule = options >> 16;
|
||||
uint16_t duel_options = options & 0xffff;
|
||||
pd->game_field->core.duel_options |= duel_options;
|
||||
if (duel_rule >= 1 && duel_rule <= CURRENT_RULE)
|
||||
pd->game_field->core.duel_rule = duel_rule;
|
||||
else if(options & DUEL_OBSOLETE_RULING) //provide backward compatibility with replay
|
||||
pd->game_field->core.duel_rule = 1;
|
||||
if (pd->game_field->core.duel_rule < 1 || pd->game_field->core.duel_rule > CURRENT_RULE)
|
||||
pd->game_field->core.duel_rule = CURRENT_RULE;
|
||||
if (pd->game_field->core.duel_rule == MASTER_RULE3) {
|
||||
pd->game_field->player[0].szone_size = 8;
|
||||
pd->game_field->player[1].szone_size = 8;
|
||||
}
|
||||
pd->game_field->core.shuffle_hand_check[0] = FALSE;
|
||||
pd->game_field->core.shuffle_hand_check[1] = FALSE;
|
||||
pd->game_field->core.shuffle_deck_check[0] = FALSE;
|
||||
pd->game_field->core.shuffle_deck_check[1] = FALSE;
|
||||
if(pd->game_field->player[0].start_count > 0)
|
||||
pd->game_field->draw(0, REASON_RULE, PLAYER_NONE, 0, pd->game_field->player[0].start_count);
|
||||
if(pd->game_field->player[1].start_count > 0)
|
||||
pd->game_field->draw(0, REASON_RULE, PLAYER_NONE, 1, pd->game_field->player[1].start_count);
|
||||
if(options & DUEL_TAG_MODE) {
|
||||
for(int i = 0; i < pd->game_field->player[0].start_count && pd->game_field->player[0].tag_list_main.size(); ++i) {
|
||||
card* pcard = pd->game_field->player[0].tag_list_main.back();
|
||||
pd->game_field->player[0].tag_list_main.pop_back();
|
||||
pd->game_field->player[0].tag_list_hand.push_back(pcard);
|
||||
pcard->current.controler = 0;
|
||||
pcard->current.location = LOCATION_HAND;
|
||||
pcard->current.sequence = (uint8_t)pd->game_field->player[0].tag_list_hand.size() - 1;
|
||||
pcard->current.position = POS_FACEDOWN;
|
||||
}
|
||||
for(int i = 0; i < pd->game_field->player[1].start_count && pd->game_field->player[1].tag_list_main.size(); ++i) {
|
||||
card* pcard = pd->game_field->player[1].tag_list_main.back();
|
||||
pd->game_field->player[1].tag_list_main.pop_back();
|
||||
pd->game_field->player[1].tag_list_hand.push_back(pcard);
|
||||
pcard->current.controler = 1;
|
||||
pcard->current.location = LOCATION_HAND;
|
||||
pcard->current.sequence = (uint8_t)pd->game_field->player[1].tag_list_hand.size() - 1;
|
||||
pcard->current.position = POS_FACEDOWN;
|
||||
}
|
||||
}
|
||||
pd->game_field->add_process(PROCESSOR_TURN, 0, 0, 0, 0, 0);
|
||||
}
|
||||
OCGCORE_API void end_duel(intptr_t pduel) {
|
||||
duel* pd = (duel*)pduel;
|
||||
if(duel_set.count(pd)) {
|
||||
duel_set.erase(pd);
|
||||
delete pd;
|
||||
}
|
||||
}
|
||||
OCGCORE_API void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount) {
|
||||
if (!check_playerid(playerid))
|
||||
return;
|
||||
duel* pd = (duel*)pduel;
|
||||
if(lp > 0)
|
||||
pd->game_field->player[playerid].lp = lp;
|
||||
if(startcount >= 0)
|
||||
pd->game_field->player[playerid].start_count = startcount;
|
||||
if(drawcount >= 0)
|
||||
pd->game_field->player[playerid].draw_count = drawcount;
|
||||
}
|
||||
OCGCORE_API void get_log_message(intptr_t pduel, char* buf) {
|
||||
duel* pd = (duel*)pduel;
|
||||
std::strncpy(buf, pd->strbuffer, sizeof pd->strbuffer - 1);
|
||||
buf[sizeof pd->strbuffer - 1] = 0;
|
||||
}
|
||||
OCGCORE_API int32_t get_message(intptr_t pduel, byte* buf) {
|
||||
int32_t len = ((duel*)pduel)->read_buffer(buf);
|
||||
((duel*)pduel)->clear_buffer();
|
||||
return len;
|
||||
}
|
||||
OCGCORE_API uint32_t process(intptr_t pduel) {
|
||||
duel* pd = (duel*)pduel;
|
||||
uint32_t result = 0;
|
||||
do {
|
||||
result = pd->game_field->process();
|
||||
} while ((result & PROCESSOR_BUFFER_LEN) == 0 && (result & PROCESSOR_FLAG) == 0);
|
||||
return result;
|
||||
}
|
||||
OCGCORE_API void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position) {
|
||||
if (!check_playerid(owner) || !check_playerid(playerid))
|
||||
return;
|
||||
duel* ptduel = (duel*)pduel;
|
||||
if(!ptduel->lua->preloaded) {
|
||||
ptduel->lua->preloaded = TRUE;
|
||||
ptduel->lua->call_code_function(0, (char*) "PreloadUds", 0, 0);
|
||||
}
|
||||
if(ptduel->game_field->is_location_useable(playerid, location, sequence)) {
|
||||
card* pcard = ptduel->new_card(code);
|
||||
pcard->owner = owner;
|
||||
ptduel->game_field->add_card(playerid, pcard, location, sequence);
|
||||
pcard->current.position = position;
|
||||
if(!(location & LOCATION_ONFIELD) || (position & POS_FACEUP)) {
|
||||
pcard->enable_field_effect(true);
|
||||
ptduel->game_field->adjust_instant();
|
||||
} if(location & LOCATION_ONFIELD) {
|
||||
if(location == LOCATION_MZONE)
|
||||
pcard->set_status(STATUS_PROC_COMPLETE, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
OCGCORE_API void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location) {
|
||||
duel* ptduel = (duel*)pduel;
|
||||
if(owner > 1 || !(location & (LOCATION_DECK | LOCATION_EXTRA)))
|
||||
return;
|
||||
card* pcard = ptduel->new_card(code);
|
||||
switch(location) {
|
||||
case LOCATION_DECK:
|
||||
ptduel->game_field->player[owner].tag_list_main.push_back(pcard);
|
||||
pcard->owner = owner;
|
||||
pcard->current.controler = owner;
|
||||
pcard->current.location = LOCATION_DECK;
|
||||
pcard->current.sequence = (uint8_t)ptduel->game_field->player[owner].tag_list_main.size() - 1;
|
||||
pcard->current.position = POS_FACEDOWN_DEFENSE;
|
||||
break;
|
||||
case LOCATION_EXTRA:
|
||||
ptduel->game_field->player[owner].tag_list_extra.push_back(pcard);
|
||||
pcard->owner = owner;
|
||||
pcard->current.controler = owner;
|
||||
pcard->current.location = LOCATION_EXTRA;
|
||||
pcard->current.sequence = (uint8_t)ptduel->game_field->player[owner].tag_list_extra.size() - 1;
|
||||
pcard->current.position = POS_FACEDOWN_DEFENSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Get card information.
|
||||
* @param buf int32_t array
|
||||
* @return buffer length in bytes
|
||||
*/
|
||||
OCGCORE_API int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint32_t query_flag, byte* buf, int32_t use_cache) {
|
||||
if (!check_playerid(playerid))
|
||||
return LEN_FAIL;
|
||||
duel* ptduel = (duel*)pduel;
|
||||
card* pcard = nullptr;
|
||||
location &= 0x7f;
|
||||
if (location == LOCATION_MZONE || location == LOCATION_SZONE)
|
||||
pcard = ptduel->game_field->get_field_card(playerid, location, sequence);
|
||||
else {
|
||||
auto ptr = ptduel->game_field->get_field_vector(playerid, location);
|
||||
if(!ptr)
|
||||
return LEN_FAIL;
|
||||
auto& lst = *ptr;
|
||||
if (sequence >= lst.size())
|
||||
return LEN_FAIL;
|
||||
pcard = lst[sequence];
|
||||
}
|
||||
if (pcard) {
|
||||
return pcard->get_infos(buf, query_flag, use_cache);
|
||||
}
|
||||
else {
|
||||
buffer_write<int32_t>(buf, LEN_EMPTY);
|
||||
return LEN_EMPTY;
|
||||
}
|
||||
}
|
||||
OCGCORE_API int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location) {
|
||||
duel* ptduel = (duel*)pduel;
|
||||
if (!check_playerid(playerid))
|
||||
return 0;
|
||||
auto& player = ptduel->game_field->player[playerid];
|
||||
if(location == LOCATION_HAND)
|
||||
return (int32_t)player.list_hand.size();
|
||||
if(location == LOCATION_GRAVE)
|
||||
return (int32_t)player.list_grave.size();
|
||||
if(location == LOCATION_REMOVED)
|
||||
return (int32_t)player.list_remove.size();
|
||||
if(location == LOCATION_EXTRA)
|
||||
return (int32_t)player.list_extra.size();
|
||||
if(location == LOCATION_DECK)
|
||||
return (int32_t)player.list_main.size();
|
||||
if(location == LOCATION_MZONE) {
|
||||
int32_t count = 0;
|
||||
for(auto& pcard : player.list_mzone)
|
||||
if(pcard)
|
||||
++count;
|
||||
return count;
|
||||
}
|
||||
if(location == LOCATION_SZONE) {
|
||||
int32_t count = 0;
|
||||
for(auto& pcard : player.list_szone)
|
||||
if(pcard)
|
||||
++count;
|
||||
return count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
OCGCORE_API int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache) {
|
||||
if (!check_playerid(playerid))
|
||||
return LEN_FAIL;
|
||||
duel* ptduel = (duel*)pduel;
|
||||
auto& player = ptduel->game_field->player[playerid];
|
||||
byte* p = buf;
|
||||
if(location == LOCATION_MZONE) {
|
||||
for(auto& pcard : player.list_mzone) {
|
||||
if(pcard) {
|
||||
int32_t clen = pcard->get_infos(p, query_flag, use_cache);
|
||||
p += clen;
|
||||
} else {
|
||||
buffer_write<int32_t>(p, LEN_EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(location == LOCATION_SZONE) {
|
||||
for(auto& pcard : player.list_szone) {
|
||||
if(pcard) {
|
||||
int32_t clen = pcard->get_infos(p, query_flag, use_cache);
|
||||
p += clen;
|
||||
} else {
|
||||
buffer_write<int32_t>(p, LEN_EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
card_vector* lst = nullptr;
|
||||
if(location == LOCATION_HAND)
|
||||
lst = &player.list_hand;
|
||||
else if(location == LOCATION_GRAVE)
|
||||
lst = &player.list_grave;
|
||||
else if(location == LOCATION_REMOVED)
|
||||
lst = &player.list_remove;
|
||||
else if(location == LOCATION_EXTRA)
|
||||
lst = &player.list_extra;
|
||||
else if(location == LOCATION_DECK)
|
||||
lst = &player.list_main;
|
||||
else
|
||||
return LEN_FAIL;
|
||||
for(auto& pcard : *lst) {
|
||||
int32_t clen = pcard->get_infos(p, query_flag, use_cache);
|
||||
p += clen;
|
||||
}
|
||||
}
|
||||
return (int32_t)(p - buf);
|
||||
}
|
||||
OCGCORE_API int32_t query_field_info(intptr_t pduel, byte* buf) {
|
||||
duel* ptduel = (duel*)pduel;
|
||||
byte* p = buf;
|
||||
*p++ = MSG_RELOAD_FIELD;
|
||||
*p++ = (uint8_t)ptduel->game_field->core.duel_rule;
|
||||
for(int playerid = 0; playerid < 2; ++playerid) {
|
||||
auto& player = ptduel->game_field->player[playerid];
|
||||
buffer_write<int32_t>(p, player.lp);
|
||||
for(auto& pcard : player.list_mzone) {
|
||||
if(pcard) {
|
||||
*p++ = 1;
|
||||
*p++ = pcard->current.position;
|
||||
*p++ = (uint8_t)pcard->xyz_materials.size();
|
||||
} else {
|
||||
*p++ = 0;
|
||||
}
|
||||
}
|
||||
for(auto& pcard : player.list_szone) {
|
||||
if(pcard) {
|
||||
*p++ = 1;
|
||||
*p++ = pcard->current.position;
|
||||
} else {
|
||||
*p++ = 0;
|
||||
}
|
||||
}
|
||||
*p++ = (uint8_t)player.list_main.size();
|
||||
*p++ = (uint8_t)player.list_hand.size();
|
||||
*p++ = (uint8_t)player.list_grave.size();
|
||||
*p++ = (uint8_t)player.list_remove.size();
|
||||
*p++ = (uint8_t)player.list_extra.size();
|
||||
*p++ = (uint8_t)player.extra_p_count;
|
||||
}
|
||||
*p++ = (uint8_t)ptduel->game_field->core.current_chain.size();
|
||||
for(const auto& ch : ptduel->game_field->core.current_chain) {
|
||||
effect* peffect = ch.triggering_effect;
|
||||
buffer_write<uint32_t>(p, peffect->get_handler()->data.code);
|
||||
buffer_write<uint32_t>(p, peffect->get_handler()->get_info_location());
|
||||
*p++ = ch.triggering_controler;
|
||||
*p++ = (uint8_t)ch.triggering_location;
|
||||
*p++ = ch.triggering_sequence;
|
||||
buffer_write<uint32_t>(p, peffect->description);
|
||||
}
|
||||
return (int32_t)(p - buf);
|
||||
}
|
||||
OCGCORE_API void set_responsei(intptr_t pduel, int32_t value) {
|
||||
((duel*)pduel)->set_responsei(value);
|
||||
}
|
||||
OCGCORE_API void set_responseb(intptr_t pduel, byte* buf) {
|
||||
((duel*)pduel)->set_responseb(buf);
|
||||
}
|
||||
OCGCORE_API int32_t preload_script(intptr_t pduel, const char* script_name) {
|
||||
return ((duel*)pduel)->lua->load_script(script_name);
|
||||
}
|
||||
// [YGOL] patch 0022 (attack preview) -- see ocgapi.h. Looks the two cards up, asks field::get_attack_target
|
||||
// whether the pair is legal (patch 0024, flag bit 5), answers unknown for a face-down target, else asks
|
||||
// field::preview_battle (processor.cpp) and writes the 24-byte answer.
|
||||
OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t target_location, uint8_t target_sequence, uint8_t* out) {
|
||||
duel* pd = (duel*)pduel;
|
||||
if(!pd || !out || !duel_set.count(pd) || !pd->game_field)
|
||||
return 0;
|
||||
if(!check_playerid(playerid) || location != LOCATION_MZONE)
|
||||
return 0;
|
||||
field* f = pd->game_field;
|
||||
card* attacker = f->get_field_card(playerid, LOCATION_MZONE, sequence);
|
||||
if(!attacker || attacker->current.controler != playerid || !attacker->is_position(POS_FACEUP))
|
||||
return 0;
|
||||
card* target = nullptr;
|
||||
if(target_location != 0xFF) {
|
||||
if(target_location != LOCATION_MZONE)
|
||||
return 0;
|
||||
target = f->get_field_card(1 - playerid, LOCATION_MZONE, target_sequence);
|
||||
if(!target || target->current.controler != 1 - playerid)
|
||||
return 0;
|
||||
}
|
||||
uint8_t flags = 0;
|
||||
battle_preview preview;
|
||||
// [YGOL] patch 0024: the legality read of process_battle_command step 4 (field.cpp get_attack_target),
|
||||
// framed the same way (core.attacker set, attack_player cleared) and put back; v is a local list.
|
||||
card* saved_attacker = f->core.attacker;
|
||||
uint8_t saved_attack_player = f->core.attack_player;
|
||||
uint8_t saved_direct = attacker->direct_attackable;
|
||||
card_vector legal;
|
||||
f->core.attacker = attacker;
|
||||
f->core.attack_player = FALSE;
|
||||
f->get_attack_target(attacker, &legal, f->core.chain_attack, true);
|
||||
bool illegal = target ? std::find(legal.begin(), legal.end(), target) == legal.end()
|
||||
: !attacker->direct_attackable;
|
||||
attacker->direct_attackable = saved_direct;
|
||||
f->core.attack_player = saved_attack_player;
|
||||
f->core.attacker = saved_attacker;
|
||||
if(illegal)
|
||||
flags |= 0x20;
|
||||
else if(target && target->is_position(POS_FACEDOWN))
|
||||
flags |= 0x2;
|
||||
else {
|
||||
if(!target)
|
||||
flags |= 0x1;
|
||||
f->preview_battle(attacker, target, &preview);
|
||||
if(preview.attacker_destroyed)
|
||||
flags |= 0x4;
|
||||
if(preview.target_destroyed)
|
||||
flags |= 0x8;
|
||||
if(preview.pierce)
|
||||
flags |= 0x10;
|
||||
}
|
||||
byte* ptr = out;
|
||||
buffer_write<uint8_t>(ptr, 1);
|
||||
buffer_write<uint8_t>(ptr, flags);
|
||||
buffer_write<uint16_t>(ptr, 0);
|
||||
buffer_write<int32_t>(ptr, preview.attacker_value);
|
||||
buffer_write<int32_t>(ptr, preview.target_value);
|
||||
buffer_write<int32_t>(ptr, preview.damage[0]);
|
||||
buffer_write<int32_t>(ptr, preview.damage[1]);
|
||||
buffer_write<int32_t>(ptr, 0);
|
||||
return 1;
|
||||
}
|
||||
OCGCORE_API int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf) {
|
||||
if (!pduel || !key || !out_buf) return -1;
|
||||
|
||||
duel* d = (duel*)pduel;
|
||||
auto it = d->registry.find(key);
|
||||
if (it == d->registry.end())
|
||||
return -1;
|
||||
|
||||
const std::string& val = it->second;
|
||||
std::memcpy(out_buf, val.c_str(), val.size());
|
||||
return static_cast<int32_t>(val.size());
|
||||
}
|
||||
OCGCORE_API void set_registry_value(intptr_t pduel, const char* key, const char* value) {
|
||||
if (!pduel || !key) return;
|
||||
duel* d = (duel*)pduel;
|
||||
if (value) {
|
||||
d->registry[key] = value;
|
||||
} else {
|
||||
d->registry.erase(key);
|
||||
}
|
||||
}
|
||||
OCGCORE_API int32_t get_registry_keys(intptr_t pduel, byte* out_buf) {
|
||||
if (!pduel || !out_buf) return -1;
|
||||
|
||||
duel* d = (duel*)pduel;
|
||||
byte* ptr = out_buf;
|
||||
|
||||
for (const auto& pair : d->registry) {
|
||||
const std::string& key = pair.first;
|
||||
uint16_t len = static_cast<uint16_t>(std::min<size_t>(key.size(), 0xFFFF));
|
||||
|
||||
// 写入长度(2字节,小端序)
|
||||
buffer_write(ptr, len);
|
||||
|
||||
std::memcpy(ptr, key.data(), len);
|
||||
ptr += len;
|
||||
}
|
||||
|
||||
return ptr - out_buf;
|
||||
}
|
||||
OCGCORE_API void clear_registry(intptr_t pduel) {
|
||||
if (!pduel) return;
|
||||
duel* d = (duel*)pduel;
|
||||
d->registry.clear();
|
||||
}
|
||||
|
||||
OCGCORE_API int32_t dump_registry(intptr_t pduel, byte* out_buf) {
|
||||
if (!pduel || !out_buf) return -1;
|
||||
|
||||
duel* d = (duel*)pduel;
|
||||
byte* ptr = out_buf;
|
||||
|
||||
for (const auto& pair : d->registry) {
|
||||
const std::string& key = pair.first;
|
||||
const std::string& value = pair.second;
|
||||
|
||||
uint16_t key_len = static_cast<uint16_t>(std::min<size_t>(key.size(), 0xFFFF));
|
||||
uint16_t val_len = static_cast<uint16_t>(std::min<size_t>(value.size(), 0xFFFF));
|
||||
|
||||
// 写入 key_len 和 val_len(每次调用后 ptr 自动推进)
|
||||
buffer_write(ptr, key_len);
|
||||
buffer_write(ptr, val_len);
|
||||
|
||||
// 写入 key 内容
|
||||
std::memcpy(ptr, key.data(), key_len);
|
||||
ptr += key_len;
|
||||
|
||||
// 写入 value 内容
|
||||
std::memcpy(ptr, value.data(), val_len);
|
||||
ptr += val_len;
|
||||
}
|
||||
|
||||
return ptr - out_buf; // 返回写入的总字节数
|
||||
}
|
||||
OCGCORE_API void load_registry(intptr_t pduel, const byte* in_buf, int32_t in_len) {
|
||||
if (!pduel || !in_buf || in_len <= 0) return;
|
||||
|
||||
duel* d = (duel*)pduel;
|
||||
|
||||
byte* ptr = const_cast<byte*>(in_buf); // buffer_read 要求非 const
|
||||
byte* end = ptr + in_len;
|
||||
|
||||
while (ptr + 4 <= end) { // 至少要读取 key_len 和 val_len(2 + 2 字节)
|
||||
uint16_t key_len = buffer_read<uint16_t>(ptr);
|
||||
uint16_t val_len = buffer_read<uint16_t>(ptr);
|
||||
|
||||
if (ptr + key_len + val_len > end) {
|
||||
break; // 数据不完整,退出
|
||||
}
|
||||
|
||||
std::string key(reinterpret_cast<const char*>(ptr), key_len);
|
||||
ptr += key_len;
|
||||
|
||||
std::string value(reinterpret_cast<const char*>(ptr), val_len);
|
||||
ptr += val_len;
|
||||
|
||||
d->registry[std::move(key)] = std::move(value);
|
||||
}
|
||||
}
|
||||
OCGCORE_API int32_t get_lua_coverage_dump_size(intptr_t pduel, const char* name) {
|
||||
if (!pduel || !name)
|
||||
return 0;
|
||||
return ((duel*)pduel)->lua->lua_coverage.get_dump_size(name);
|
||||
}
|
||||
OCGCORE_API int32_t dump_lua_coverage(intptr_t pduel, const char* name, byte* out_buf, int32_t out_len) {
|
||||
if (!pduel || !name || !out_buf || out_len <= 0)
|
||||
return 0;
|
||||
return ((duel*)pduel)->lua->lua_coverage.dump(name, out_buf, out_len);
|
||||
}
|
||||
OCGCORE_API int32_t get_all_lua_coverages_dump_size(intptr_t pduel) {
|
||||
if (!pduel)
|
||||
return 0;
|
||||
return ((duel*)pduel)->lua->lua_coverage.get_all_dump_size();
|
||||
}
|
||||
OCGCORE_API int32_t dump_all_lua_coverages(intptr_t pduel, byte* out_buf, int32_t out_len) {
|
||||
if (!pduel || !out_buf || out_len <= 0)
|
||||
return 0;
|
||||
return ((duel*)pduel)->lua->lua_coverage.dump_all(out_buf, out_len);
|
||||
}
|
||||
OCGCORE_API void clear_lua_coverage(intptr_t pduel, const char* name) {
|
||||
if (!pduel || !name)
|
||||
return;
|
||||
((duel*)pduel)->lua->lua_coverage.clear(name);
|
||||
}
|
||||
OCGCORE_API void clear_all_lua_coverages(intptr_t pduel) {
|
||||
if (!pduel)
|
||||
return;
|
||||
((duel*)pduel)->lua->lua_coverage.clear_all();
|
||||
}
|
||||
|
||||
// [YGOL] patch 0008 (sandbox god mode) -- see ocgapi.h. Helpers first, the six exports after.
|
||||
static duel* ygol_sb_duel(intptr_t pduel) {
|
||||
duel* pd = (duel*)pduel;
|
||||
if(!pd || !duel_set.count(pd) || !pd->game_field)
|
||||
return nullptr;
|
||||
return pd;
|
||||
}
|
||||
static int32_t ygol_sb_location_ok(uint8_t location) {
|
||||
switch(location) {
|
||||
case LOCATION_DECK:
|
||||
case LOCATION_HAND:
|
||||
case LOCATION_MZONE:
|
||||
case LOCATION_SZONE:
|
||||
case LOCATION_GRAVE:
|
||||
case LOCATION_REMOVED:
|
||||
case LOCATION_EXTRA:
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
static card* ygol_sb_find(field* f, uint8_t playerid, uint8_t location, uint8_t sequence) {
|
||||
if(!check_playerid(playerid) || !ygol_sb_location_ok(location))
|
||||
return nullptr;
|
||||
return f->get_field_card(playerid, location, sequence);
|
||||
}
|
||||
static void ygol_sb_write_move(duel* pd, card* pcard, uint32_t previous, uint32_t current) {
|
||||
pd->write_buffer8(MSG_MOVE);
|
||||
pd->write_buffer32(pcard->data.code);
|
||||
pd->write_buffer32(previous);
|
||||
pd->write_buffer32(current);
|
||||
pd->write_buffer32(0);
|
||||
}
|
||||
// The card must not be something the running duel still points at: a chain in flight, the
|
||||
// attacker or its target, a summon in progress, or an overlay unit (address its Xyz instead).
|
||||
static int32_t ygol_sb_can_touch(field* f, card* pcard) {
|
||||
auto& core = f->core;
|
||||
if(!core.current_chain.empty() || core.chain_solving || core.conti_solving)
|
||||
return FALSE;
|
||||
if(pcard == core.attacker || pcard == core.attack_target || pcard == core.summoning_card)
|
||||
return FALSE;
|
||||
if(pcard->overlay_target)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
static void ygol_sb_erase(card_vector& v, card* pcard) {
|
||||
v.erase(std::remove(v.begin(), v.end(), pcard), v.end());
|
||||
}
|
||||
// Drop the card from every core.* container that can outlive a prompt.
|
||||
static void ygol_sb_forget(field* f, card* pcard) {
|
||||
auto& core = f->core;
|
||||
card_set* sets[] = {
|
||||
&core.leave_confirmed, &core.special_summoning, &core.unable_tofield_set, &core.equiping_cards,
|
||||
&core.control_adjust_set[0], &core.control_adjust_set[1], &core.unique_destroy_set,
|
||||
&core.self_destroy_set, &core.self_tograve_set, &core.trap_monster_adjust_set[0],
|
||||
&core.trap_monster_adjust_set[1], &core.release_cards, &core.release_cards_ex,
|
||||
&core.release_cards_ex_oneof, &core.battle_destroy_rep, &core.fusion_materials,
|
||||
&core.synchro_materials, &core.operated_set, &core.discarded_set, &core.destroy_canceled,
|
||||
&core.indestructable_count_set, &core.delayed_enable_set, &core.set_group_pre_set,
|
||||
&core.set_group_set,
|
||||
};
|
||||
for(auto* s : sets)
|
||||
s->erase(pcard);
|
||||
core.readjust_map.erase(pcard);
|
||||
for(auto it = core.xmaterial_lst.begin(); it != core.xmaterial_lst.end();) {
|
||||
if(it->second == pcard)
|
||||
it = core.xmaterial_lst.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
ygol_sb_erase(core.select_cards, pcard);
|
||||
ygol_sb_erase(core.unselect_cards, pcard);
|
||||
ygol_sb_erase(core.must_select_cards, pcard);
|
||||
}
|
||||
// Cut every link a card on the field holds: overlays go to their owner's GY (each with its own
|
||||
// MSG_MOVE), equips both ways are released, targets cleared, field-gained effects reset.
|
||||
static void ygol_sb_detach(duel* pd, field* f, card* pcard) {
|
||||
if(pcard->xyz_materials.size()) {
|
||||
card_vector overlays(pcard->xyz_materials.begin(), pcard->xyz_materials.end());
|
||||
for(auto& mat : overlays) {
|
||||
uint32_t previous = mat->get_info_location();
|
||||
pcard->xyz_remove(mat);
|
||||
mat->sendto_param.position = POS_FACEUP;
|
||||
f->move_card(mat->owner, mat, LOCATION_GRAVE, 0);
|
||||
mat->current.position = POS_FACEUP;
|
||||
mat->reset(RESET_TOGRAVE, RESET_EVENT);
|
||||
mat->enable_field_effect(true);
|
||||
mat->refresh_disable_status();
|
||||
ygol_sb_write_move(pd, mat, previous, mat->get_info_location());
|
||||
}
|
||||
pcard->xyz_materials_previous_count_onfield = 0;
|
||||
}
|
||||
for(auto it = pcard->equiping_cards.begin(); it != pcard->equiping_cards.end();) {
|
||||
card* equip = *it++;
|
||||
equip->unequip();
|
||||
}
|
||||
pcard->unequip();
|
||||
pcard->clear_card_target();
|
||||
if(pcard->current.location & LOCATION_ONFIELD)
|
||||
pcard->reset(RESET_LEAVE + RESET_MSCHANGE, RESET_EVENT);
|
||||
}
|
||||
OCGCORE_API int32_t ygol_sb_add(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position) {
|
||||
duel* pd = ygol_sb_duel(pduel);
|
||||
if(!pd || !check_playerid(owner) || !check_playerid(playerid) || !ygol_sb_location_ok(location))
|
||||
return FALSE;
|
||||
field* f = pd->game_field;
|
||||
if(!f->is_location_useable(playerid, location, sequence))
|
||||
return FALSE;
|
||||
if((location & LOCATION_ONFIELD) && f->get_field_card(playerid, location, sequence))
|
||||
return FALSE;
|
||||
if(!pd->lua->preloaded) {
|
||||
pd->lua->preloaded = TRUE;
|
||||
pd->lua->call_code_function(0, (char*) "PreloadUds", 0, 0);
|
||||
}
|
||||
card* pcard = pd->new_card(code);
|
||||
pcard->owner = owner;
|
||||
f->add_card(playerid, pcard, location, sequence);
|
||||
if(pcard->current.location == 0)
|
||||
return FALSE;
|
||||
pcard->current.position = pcard->current.location == location ? position : pcard->sendto_param.position;
|
||||
if(!(pcard->current.location & LOCATION_ONFIELD) || (pcard->current.position & POS_FACEUP)) {
|
||||
pcard->enable_field_effect(true);
|
||||
f->adjust_instant();
|
||||
}
|
||||
if(pcard->current.location == LOCATION_MZONE)
|
||||
pcard->set_status(STATUS_PROC_COMPLETE, TRUE);
|
||||
ygol_sb_write_move(pd, pcard, 0, pcard->get_info_location());
|
||||
return TRUE;
|
||||
}
|
||||
OCGCORE_API int32_t ygol_sb_move(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t dst_playerid, uint8_t dst_location, uint8_t dst_sequence, uint8_t position) {
|
||||
duel* pd = ygol_sb_duel(pduel);
|
||||
if(!pd || !check_playerid(dst_playerid) || !ygol_sb_location_ok(dst_location))
|
||||
return FALSE;
|
||||
field* f = pd->game_field;
|
||||
card* pcard = ygol_sb_find(f, playerid, location, sequence);
|
||||
if(!pcard || !ygol_sb_can_touch(f, pcard))
|
||||
return FALSE;
|
||||
if(pcard->current.controler == dst_playerid && pcard->current.location == dst_location
|
||||
&& (dst_location & LOCATION_ONFIELD) && pcard->current.sequence == dst_sequence)
|
||||
return FALSE;
|
||||
if(!f->is_location_useable(dst_playerid, dst_location, dst_sequence))
|
||||
return FALSE;
|
||||
if((dst_location & LOCATION_ONFIELD) && f->get_field_card(dst_playerid, dst_location, dst_sequence))
|
||||
return FALSE;
|
||||
uint32_t previous = pcard->get_info_location();
|
||||
ygol_sb_detach(pd, f, pcard);
|
||||
ygol_sb_forget(f, pcard);
|
||||
if(dst_location & LOCATION_ONFIELD)
|
||||
pcard->sendto_param.position = position ? position : POS_FACEUP_ATTACK;
|
||||
else if(dst_location == LOCATION_EXTRA)
|
||||
pcard->sendto_param.position = (position & POS_FACEUP) ? POS_FACEUP_DEFENSE : POS_FACEDOWN_DEFENSE;
|
||||
else
|
||||
pcard->sendto_param.position = position ? position : POS_FACEUP;
|
||||
f->move_card(dst_playerid, pcard, dst_location, dst_sequence);
|
||||
if(pcard->current.location == 0)
|
||||
return FALSE;
|
||||
pcard->current.position = pcard->sendto_param.position;
|
||||
uint8_t nloc = pcard->current.location;
|
||||
if(nloc == LOCATION_HAND)
|
||||
pcard->reset(RESET_TOHAND, RESET_EVENT);
|
||||
if(nloc == LOCATION_DECK || nloc == LOCATION_EXTRA)
|
||||
pcard->reset(RESET_TODECK, RESET_EVENT);
|
||||
if(nloc == LOCATION_GRAVE)
|
||||
pcard->reset(RESET_TOGRAVE, RESET_EVENT);
|
||||
if(nloc == LOCATION_REMOVED)
|
||||
pcard->reset(RESET_REMOVE, RESET_EVENT);
|
||||
if(!(nloc & LOCATION_ONFIELD) || (pcard->current.position & POS_FACEUP))
|
||||
pcard->enable_field_effect(true);
|
||||
else
|
||||
pcard->enable_field_effect(false);
|
||||
pcard->refresh_disable_status();
|
||||
if(nloc == LOCATION_MZONE)
|
||||
pcard->set_status(STATUS_PROC_COMPLETE, TRUE);
|
||||
ygol_sb_write_move(pd, pcard, previous, pcard->get_info_location());
|
||||
f->adjust_instant();
|
||||
return TRUE;
|
||||
}
|
||||
OCGCORE_API int32_t ygol_sb_remove(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence) {
|
||||
duel* pd = ygol_sb_duel(pduel);
|
||||
if(!pd)
|
||||
return FALSE;
|
||||
field* f = pd->game_field;
|
||||
card* pcard = ygol_sb_find(f, playerid, location, sequence);
|
||||
if(!pcard || !ygol_sb_can_touch(f, pcard))
|
||||
return FALSE;
|
||||
uint32_t previous = pcard->get_info_location();
|
||||
ygol_sb_detach(pd, f, pcard);
|
||||
ygol_sb_forget(f, pcard);
|
||||
f->remove_card(pcard);
|
||||
if(pcard->current.location != 0)
|
||||
return FALSE;
|
||||
pcard->set_status(STATUS_PROC_COMPLETE, FALSE);
|
||||
ygol_sb_write_move(pd, pcard, previous, 0);
|
||||
f->adjust_instant();
|
||||
return TRUE;
|
||||
}
|
||||
OCGCORE_API int32_t ygol_sb_set_position(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position) {
|
||||
duel* pd = ygol_sb_duel(pduel);
|
||||
if(!pd || !(location & LOCATION_ONFIELD) || !position || (position & ~0xf))
|
||||
return FALSE;
|
||||
field* f = pd->game_field;
|
||||
card* pcard = ygol_sb_find(f, playerid, location, sequence);
|
||||
if(!pcard || !ygol_sb_can_touch(f, pcard))
|
||||
return FALSE;
|
||||
uint8_t opos = pcard->current.position;
|
||||
if(opos == position)
|
||||
return FALSE;
|
||||
pcard->previous.position = opos;
|
||||
pcard->current.position = position;
|
||||
if((opos & POS_FACEDOWN) && (position & POS_FACEUP)) {
|
||||
pcard->fieldid = f->infos.field_id++;
|
||||
pcard->activate_count_id = pcard->fieldid;
|
||||
if(f->check_unique_onfield(pcard, pcard->current.controler, pcard->current.location))
|
||||
pcard->unique_fieldid = UINT_MAX;
|
||||
}
|
||||
pcard->enable_field_effect(!!(position & POS_FACEUP));
|
||||
pcard->refresh_disable_status();
|
||||
pd->write_buffer8(MSG_POS_CHANGE);
|
||||
pd->write_buffer32(pcard->data.code);
|
||||
pd->write_buffer8(pcard->current.controler);
|
||||
pd->write_buffer8(pcard->current.location);
|
||||
pd->write_buffer8(pcard->current.sequence);
|
||||
pd->write_buffer8(pcard->previous.position);
|
||||
pd->write_buffer8(pcard->current.position);
|
||||
f->adjust_instant();
|
||||
return TRUE;
|
||||
}
|
||||
OCGCORE_API int32_t ygol_sb_set_lp(intptr_t pduel, uint8_t playerid, int32_t lp) {
|
||||
duel* pd = ygol_sb_duel(pduel);
|
||||
if(!pd || !check_playerid(playerid))
|
||||
return FALSE;
|
||||
if(lp < 0)
|
||||
lp = 0;
|
||||
pd->game_field->player[playerid].lp = lp;
|
||||
pd->write_buffer8(MSG_LPUPDATE);
|
||||
pd->write_buffer8(playerid);
|
||||
pd->write_buffer32(lp);
|
||||
return TRUE;
|
||||
}
|
||||
// The prompt only writes the lists its parent command built at step 0, so the parked prompt is
|
||||
// dropped and the parent rewound: process() rebuilds the lists from the field and re-sends it.
|
||||
OCGCORE_API int32_t ygol_sb_reask(intptr_t pduel) {
|
||||
duel* pd = ygol_sb_duel(pduel);
|
||||
if(!pd)
|
||||
return FALSE;
|
||||
auto& core = pd->game_field->core;
|
||||
if(core.units.size() < 2 || !core.subunits.empty())
|
||||
return FALSE;
|
||||
auto front = core.units.begin();
|
||||
auto parent = std::next(front);
|
||||
bool idle = front->type == PROCESSOR_SELECT_IDLECMD && parent->type == PROCESSOR_IDLE_COMMAND;
|
||||
bool battle = front->type == PROCESSOR_SELECT_BATTLECMD && parent->type == PROCESSOR_BATTLE_COMMAND;
|
||||
if(!(idle || battle) || front->step != 1 || parent->step != 1)
|
||||
return FALSE;
|
||||
core.units.pop_front();
|
||||
parent->step = 0;
|
||||
return TRUE;
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* interface.h
|
||||
*
|
||||
* Created on: 2010-4-28
|
||||
* Author: Argon
|
||||
*/
|
||||
|
||||
#ifndef OCGAPI_H_
|
||||
#define OCGAPI_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN_C extern "C"
|
||||
#else
|
||||
#define EXTERN_C
|
||||
#endif
|
||||
|
||||
#ifndef OCGCORE_API
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#include <emscripten/emscripten.h>
|
||||
#define OCGCORE_API EXTERN_C EMSCRIPTEN_KEEPALIVE
|
||||
#elif defined(_WIN32)
|
||||
#define OCGCORE_API EXTERN_C __declspec(dllexport)
|
||||
#else
|
||||
#define OCGCORE_API EXTERN_C __attribute__ ((visibility ("default")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define SEED_COUNT 8
|
||||
|
||||
#define LEN_FAIL 0
|
||||
#define LEN_EMPTY 4
|
||||
#define LEN_HEADER 8
|
||||
#define TEMP_CARD_ID 0
|
||||
|
||||
struct card_data;
|
||||
|
||||
typedef byte* (*script_reader)(const char* script_name, int* len);
|
||||
typedef uint32_t (*card_reader)(uint32_t code, card_data* data);
|
||||
typedef uint32_t (*message_handler)(intptr_t pduel, uint32_t msg_type);
|
||||
|
||||
OCGCORE_API void set_script_reader(script_reader f);
|
||||
OCGCORE_API void set_card_reader(card_reader f);
|
||||
OCGCORE_API void set_message_handler(message_handler f);
|
||||
|
||||
byte* read_script(const char* script_name, int* len);
|
||||
uint32_t read_card(uint32_t code, card_data* data);
|
||||
uint32_t handle_message(void* pduel, uint32_t message_type);
|
||||
|
||||
OCGCORE_API intptr_t create_duel(uint_fast32_t seed);
|
||||
OCGCORE_API intptr_t create_duel_v2(uint32_t seed_sequence[]);
|
||||
OCGCORE_API intptr_t create_duel_ex(uint_fast32_t seed, uint32_t create_flags);
|
||||
OCGCORE_API intptr_t create_duel_v2_ex(uint32_t seed_sequence[], uint32_t create_flags);
|
||||
OCGCORE_API void start_duel(intptr_t pduel, uint32_t options);
|
||||
OCGCORE_API void end_duel(intptr_t pduel);
|
||||
OCGCORE_API void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount);
|
||||
OCGCORE_API void get_log_message(intptr_t pduel, char* buf);
|
||||
OCGCORE_API int32_t get_message(intptr_t pduel, byte* buf);
|
||||
OCGCORE_API uint32_t process(intptr_t pduel);
|
||||
OCGCORE_API void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
|
||||
OCGCORE_API void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location);
|
||||
OCGCORE_API int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint32_t query_flag, byte* buf, int32_t use_cache);
|
||||
OCGCORE_API int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location);
|
||||
OCGCORE_API int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);
|
||||
OCGCORE_API int32_t query_field_info(intptr_t pduel, byte* buf);
|
||||
OCGCORE_API void set_responsei(intptr_t pduel, int32_t value);
|
||||
OCGCORE_API void set_responseb(intptr_t pduel, byte* buf);
|
||||
OCGCORE_API int32_t preload_script(intptr_t pduel, const char* script_name);
|
||||
OCGCORE_API byte* default_script_reader(const char* script_name, int* len);
|
||||
|
||||
// [YGOL] patch 0022 (attack preview): a read-only dry run of the damage step for one attacker and one
|
||||
// target (target_location 0xFF = direct). Returns 1 answered, 0 refused (bad pointer, no such card,
|
||||
// attacker not a face-up monster on playerid's field, target not a monster on the other field); a
|
||||
// refusal writes nothing. out is 24 bytes: version (1), flags (bit 0 direct, bit 1 unknown, bit 2
|
||||
// attacker destroyed, bit 3 target destroyed, bit 4 pierce, bit 5 illegal), 2 pad bytes, then five
|
||||
// int32: attacker value, target value, damage to player 0, damage to player 1, reserved 0. A face-down
|
||||
// target answers unknown with every number 0. A pair field::get_attack_target would not offer answers
|
||||
// illegal alone with every number 0 (patch 0024). Call it only while the engine is parked on a prompt;
|
||||
// the duel is byte-identical afterwards (proposal 43).
|
||||
OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t target_location, uint8_t target_sequence, uint8_t* out);
|
||||
|
||||
// koishi specific
|
||||
OCGCORE_API int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf);
|
||||
OCGCORE_API void set_registry_value(intptr_t pduel, const char* key, const char* value);
|
||||
OCGCORE_API int32_t get_registry_keys(intptr_t pduel, byte* out_buf);
|
||||
OCGCORE_API void clear_registry(intptr_t pduel);
|
||||
OCGCORE_API int32_t dump_registry(intptr_t pduel, byte* out_buf);
|
||||
OCGCORE_API void load_registry(intptr_t pduel, const byte* in_buf, int32_t in_len);
|
||||
OCGCORE_API int32_t get_lua_coverage_dump_size(intptr_t pduel, const char* name);
|
||||
OCGCORE_API int32_t dump_lua_coverage(intptr_t pduel, const char* name, byte* out_buf, int32_t out_len);
|
||||
OCGCORE_API int32_t get_all_lua_coverages_dump_size(intptr_t pduel);
|
||||
OCGCORE_API int32_t dump_all_lua_coverages(intptr_t pduel, byte* out_buf, int32_t out_len);
|
||||
OCGCORE_API void clear_lua_coverage(intptr_t pduel, const char* name);
|
||||
OCGCORE_API void clear_all_lua_coverages(intptr_t pduel);
|
||||
|
||||
|
||||
// [YGOL] patch 0008 (sandbox god mode): additive, Sandbox-only exports. Nothing a normal
|
||||
// duel, replay, BotArena or YGOSharp calls. Each returns 1 when it did the work, 0 when it
|
||||
// refused and changed nothing.
|
||||
OCGCORE_API int32_t ygol_sb_add(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
|
||||
OCGCORE_API int32_t ygol_sb_move(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t dst_playerid, uint8_t dst_location, uint8_t dst_sequence, uint8_t position);
|
||||
OCGCORE_API int32_t ygol_sb_remove(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence);
|
||||
OCGCORE_API int32_t ygol_sb_set_position(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
|
||||
OCGCORE_API int32_t ygol_sb_set_lp(intptr_t pduel, uint8_t playerid, int32_t lp);
|
||||
OCGCORE_API int32_t ygol_sb_reask(intptr_t pduel);
|
||||
|
||||
#endif /* OCGAPI_H_ */
|
||||
+6574
File diff suppressed because it is too large.
Load diff
+1109
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,232 @@
|
||||
LUA_DIR = "./lua"
|
||||
|
||||
newoption { trigger = "lua-dir", description = "", value = "PATH" }
|
||||
newoption { trigger = "sqlite3-dir", description = "", value = "PATH" }
|
||||
newoption { trigger = "ndk-dir", category = "YGOPro - android", description = "", value = "PATH" }
|
||||
newoption { trigger = "android-api-level", category = "YGOPro - android", description = "", value = "LEVEL" }
|
||||
newoption { trigger = "no-longjmp", description = "Disable use of longjmp for error handling in Lua" }
|
||||
|
||||
boolOptions = {
|
||||
"no-lua-safe",
|
||||
}
|
||||
|
||||
for _, boolOption in ipairs(boolOptions) do
|
||||
newoption { trigger = boolOption, category = "YGOPro - options", description = "" }
|
||||
end
|
||||
|
||||
function GetParam(param)
|
||||
return _OPTIONS[param] or os.getenv(string.upper(string.gsub(param,"-","_")))
|
||||
end
|
||||
|
||||
LUA_DIR = GetParam("lua-dir") or LUA_DIR
|
||||
if not os.isdir(LUA_DIR) then
|
||||
LUA_DIR = "../lua"
|
||||
end
|
||||
|
||||
SQLITE3_DIR=GetParam("sqlite3-dir")
|
||||
USE_LONGJMP=not GetParam("no-longjmp")
|
||||
ANDROID_NDK_DIR=GetParam("ndk-dir")
|
||||
|
||||
function QuoteIfNeeded(value)
|
||||
if string.find(value, " ", 1, true) then
|
||||
return "\"" .. value .. "\""
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
function FindAndroidToolchainBin(ndkDir)
|
||||
local prebuiltDir = path.join(ndkDir, "toolchains/llvm/prebuilt")
|
||||
local prebuilts = os.matchdirs(path.join(prebuiltDir, "*"))
|
||||
table.sort(prebuilts)
|
||||
if #prebuilts == 0 then
|
||||
error("Android NDK toolchain not found under " .. prebuiltDir)
|
||||
end
|
||||
return path.join(prebuilts[1], "bin")
|
||||
end
|
||||
|
||||
ANDROID_ENABLED=false
|
||||
ANDROID_API_LEVEL_TEXT=GetParam("android-api-level") or "26"
|
||||
ANDROID_API_LEVEL=tonumber(ANDROID_API_LEVEL_TEXT)
|
||||
if not ANDROID_API_LEVEL then
|
||||
error("Invalid android api level: " .. ANDROID_API_LEVEL_TEXT)
|
||||
end
|
||||
if ANDROID_NDK_DIR then
|
||||
ANDROID_NDK_DIR=path.getabsolute(ANDROID_NDK_DIR)
|
||||
if not os.isdir(ANDROID_NDK_DIR) then
|
||||
error("Android NDK directory not found: " .. ANDROID_NDK_DIR)
|
||||
end
|
||||
ANDROID_ENABLED=true
|
||||
ANDROID_TOOLCHAIN_BIN=FindAndroidToolchainBin(ANDROID_NDK_DIR)
|
||||
ANDROID_TARGET="aarch64-linux-android" .. ANDROID_API_LEVEL
|
||||
premake.override(premake.tools.clang, "gettoolname", function(base, cfg, tool)
|
||||
if cfg.system == premake.ANDROID then
|
||||
if tool == "cc" then
|
||||
return QuoteIfNeeded(path.join(ANDROID_TOOLCHAIN_BIN, "clang")) .. " --target=" .. ANDROID_TARGET
|
||||
elseif tool == "cxx" then
|
||||
return QuoteIfNeeded(path.join(ANDROID_TOOLCHAIN_BIN, "clang++")) .. " --target=" .. ANDROID_TARGET
|
||||
elseif tool == "ar" then
|
||||
return QuoteIfNeeded(path.join(ANDROID_TOOLCHAIN_BIN, "llvm-ar"))
|
||||
end
|
||||
end
|
||||
return base(cfg, tool)
|
||||
end)
|
||||
end
|
||||
|
||||
function ApplyBoolean(param)
|
||||
if GetParam(param) then
|
||||
defines { "YGOPRO_" .. string.upper(string.gsub(param,"-","_")) }
|
||||
end
|
||||
end
|
||||
|
||||
local workspacePlatforms = { "x64", "x32", "arm64", "wasm_cjs", "wasm_esm" }
|
||||
if ANDROID_ENABLED then
|
||||
table.insert(workspacePlatforms, "android_arm64")
|
||||
end
|
||||
|
||||
workspace "ocgcoredll"
|
||||
location "build"
|
||||
language "C++"
|
||||
cppdialect "C++14"
|
||||
configurations { "Release", "Debug" }
|
||||
platforms(workspacePlatforms)
|
||||
|
||||
if USE_LONGJMP then
|
||||
defines { "LUA_USE_LONGJMP" }
|
||||
end
|
||||
|
||||
for _, boolOption in ipairs(boolOptions) do
|
||||
ApplyBoolean(boolOption)
|
||||
end
|
||||
|
||||
filter "platforms:x32"
|
||||
architecture "x32"
|
||||
|
||||
filter "platforms:x64"
|
||||
architecture "x64"
|
||||
|
||||
filter "platforms:arm64"
|
||||
architecture "ARM64"
|
||||
|
||||
filter "platforms:android_arm64"
|
||||
architecture "ARM64"
|
||||
system "android"
|
||||
toolset "clang"
|
||||
pic "On"
|
||||
|
||||
filter "configurations:Release"
|
||||
optimize "Speed"
|
||||
|
||||
filter "configurations:Debug"
|
||||
symbols "On"
|
||||
defines "_DEBUG"
|
||||
|
||||
filter "system:windows"
|
||||
systemversion "latest"
|
||||
startproject "ocgcore"
|
||||
|
||||
filter { "system:windows", "action:vs2026" }
|
||||
toolset "v143"
|
||||
|
||||
filter { "configurations:Release", "action:vs*" }
|
||||
linktimeoptimization "On"
|
||||
staticruntime "On"
|
||||
disablewarnings { "4334" }
|
||||
|
||||
filter "action:vs*"
|
||||
cdialect "C11"
|
||||
conformancemode "On"
|
||||
buildoptions { "/utf-8" }
|
||||
defines { "_CRT_SECURE_NO_WARNINGS" }
|
||||
|
||||
filter "system:bsd"
|
||||
defines { "LUA_USE_POSIX" }
|
||||
|
||||
filter "system:macosx"
|
||||
defines { "LUA_USE_MACOSX" }
|
||||
|
||||
filter "system:linux"
|
||||
defines { "LUA_USE_LINUX" }
|
||||
pic "On"
|
||||
if USE_LONGJMP then
|
||||
linkoptions { "-static-libstdc++", "-static-libgcc" }
|
||||
end
|
||||
|
||||
filter { "system:android", "language:C++" }
|
||||
linkoptions { "-static-libstdc++" }
|
||||
|
||||
filter "platforms:wasm_cjs or platforms:wasm_esm"
|
||||
toolset "emcc"
|
||||
-- defines { "LUA_USE_C89" }
|
||||
pic "On"
|
||||
|
||||
filter {}
|
||||
|
||||
include(LUA_DIR)
|
||||
|
||||
project "ocgcore"
|
||||
|
||||
kind "SharedLib"
|
||||
|
||||
files { "*.cpp", "*.h" }
|
||||
links { "lua" }
|
||||
|
||||
includedirs { LUA_DIR .. "/src" }
|
||||
|
||||
filter "platforms:wasm_cjs or platforms:wasm_esm"
|
||||
-- Avoid -shared so emcc emits JS glue + .wasm.
|
||||
kind "ConsoleApp"
|
||||
targetprefix "lib"
|
||||
local wasmLinkOptions = {
|
||||
"-s MODULARIZE=1",
|
||||
"-s EXPORT_NAME=\"createOcgcore\"",
|
||||
"--no-entry",
|
||||
"-s EXIT_RUNTIME=1",
|
||||
"-s ENVIRONMENT=web,worker,node",
|
||||
"-s EXPORTED_RUNTIME_METHODS=[\"ccall\",\"cwrap\",\"addFunction\",\"removeFunction\"]",
|
||||
"-s EXPORTED_FUNCTIONS=[\"_malloc\",\"_free\"]",
|
||||
"-s ALLOW_TABLE_GROWTH=1",
|
||||
"-s ALLOW_MEMORY_GROWTH=1",
|
||||
"-s ASSERTIONS=0",
|
||||
"-s SAFE_HEAP=0",
|
||||
"-s DEMANGLE_SUPPORT=0",
|
||||
}
|
||||
linkoptions(wasmLinkOptions)
|
||||
|
||||
filter "platforms:wasm_esm"
|
||||
-- Build as ES module
|
||||
targetextension ".mjs"
|
||||
linkoptions { "-s EXPORT_ES6=1" }
|
||||
|
||||
filter "platforms:wasm_cjs"
|
||||
targetextension ".cjs"
|
||||
|
||||
filter {}
|
||||
|
||||
if not WASM and SQLITE3_DIR and os.isdir(SQLITE3_DIR) then
|
||||
project "sqlite3"
|
||||
kind "SharedLib"
|
||||
language "C"
|
||||
|
||||
files {
|
||||
SQLITE3_DIR .. "/sqlite3.c",
|
||||
SQLITE3_DIR .. "/sqlite3.h"
|
||||
}
|
||||
|
||||
filter "system:windows"
|
||||
systemversion "latest"
|
||||
defines { "SQLITE_API=__declspec(dllexport)" }
|
||||
|
||||
filter "system:linux or system:macosx"
|
||||
pic "On"
|
||||
|
||||
filter "system:linux"
|
||||
linkoptions { "-static-libstdc++", "-static-libgcc" }
|
||||
|
||||
filter "configurations:Debug"
|
||||
symbols "On"
|
||||
defines { "DEBUG" }
|
||||
|
||||
filter "configurations:Release"
|
||||
optimize "On"
|
||||
defines { "NDEBUG" }
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
project "lua"
|
||||
kind "StaticLib"
|
||||
compileas "C++"
|
||||
|
||||
files { "src/*.c", "src/*.h" }
|
||||
removefiles { "src/lua.c", "src/luac.c", "src/onelua.c" }
|
||||
|
||||
if not GetParam("no-lua-safe") then
|
||||
removefiles { "src/linit.c" }
|
||||
end
|
||||
|
||||
filter "configurations:Debug"
|
||||
defines { "LUA_USE_APICHECK" }
|
||||
|
||||
filter "system:bsd"
|
||||
defines { "LUA_USE_POSIX" }
|
||||
|
||||
filter "system:macosx"
|
||||
defines { "LUA_USE_MACOSX" }
|
||||
|
||||
filter "system:android"
|
||||
defines { "LUA_USE_POSIX" }
|
||||
|
||||
filter "system:linux"
|
||||
defines { "LUA_USE_LINUX" }
|
||||
@@ -0,0 +1,20 @@
|
||||
--step 1: add new column
|
||||
ALTER TABLE datas ADD COLUMN rule_code INTEGER DEFAULT 0;
|
||||
|
||||
--step 2: update "treated as X" cards
|
||||
UPDATE datas
|
||||
SET rule_code = alias, alias = 0
|
||||
WHERE id IN (
|
||||
SELECT id
|
||||
FROM datas
|
||||
WHERE NOT (type & 0x4000) AND alias != 0 AND abs(id - alias) >= 20
|
||||
);
|
||||
|
||||
--step 3: update special cards
|
||||
UPDATE datas
|
||||
SET rule_code = alias, alias = 0
|
||||
WHERE id = 5405695;
|
||||
|
||||
UPDATE datas
|
||||
SET rule_code = 13331639
|
||||
WHERE alias = 6218704;
|
||||
@@ -0,0 +1,38 @@
|
||||
project "ocgcore"
|
||||
if OCGCORE_DYNAMIC then
|
||||
kind "SharedLib"
|
||||
links { LUA_LIB_NAME }
|
||||
libdirs { LUA_LIB_DIR }
|
||||
else
|
||||
kind "StaticLib"
|
||||
end
|
||||
|
||||
files { "*.cpp", "*.h" }
|
||||
|
||||
if BUILD_LUA then
|
||||
includedirs { "../lua/src" }
|
||||
else
|
||||
includedirs { LUA_INCLUDE_DIR }
|
||||
end
|
||||
|
||||
filter "not action:vs*"
|
||||
cppdialect "C++14"
|
||||
|
||||
filter "system:bsd"
|
||||
defines { "LUA_USE_POSIX" }
|
||||
|
||||
filter "system:macosx"
|
||||
defines { "LUA_USE_MACOSX" }
|
||||
|
||||
filter "system:android"
|
||||
defines { "LUA_USE_POSIX" }
|
||||
if OCGCORE_DYNAMIC then
|
||||
pic "On"
|
||||
end
|
||||
|
||||
filter "system:linux"
|
||||
defines { "LUA_USE_LINUX" }
|
||||
if OCGCORE_DYNAMIC then
|
||||
pic "On"
|
||||
-- linkoptions { "-static-libstdc++", "-static-libgcc" }
|
||||
end
|
||||
+5272
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* scriptlib.cpp
|
||||
*
|
||||
* Created on: 2010-7-29
|
||||
* Author: Argon
|
||||
*/
|
||||
#include "scriptlib.h"
|
||||
#include "duel.h"
|
||||
|
||||
static int32_t check_data_type(lua_State* L, int32_t index, const char* tname) {
|
||||
luaL_checkstack(L, 2, nullptr);
|
||||
int32_t result = FALSE;
|
||||
if(lua_getmetatable(L, index)) {
|
||||
lua_getglobal(L, tname);
|
||||
if(lua_rawequal(L, -1, -2))
|
||||
result = TRUE;
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int32_t scriptlib::check_param(lua_State* L, int32_t param_type, int32_t index, int32_t retfalse) {
|
||||
switch (param_type) {
|
||||
case PARAM_TYPE_CARD: {
|
||||
luaL_checkstack(L, 1, nullptr);
|
||||
int32_t result = FALSE;
|
||||
if(lua_isuserdata(L, index) && lua_getmetatable(L, index)) {
|
||||
result = check_data_type(L, -1, "Card");
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
if(result)
|
||||
return TRUE;
|
||||
if(retfalse)
|
||||
return FALSE;
|
||||
return luaL_error(L, "Parameter %d should be \"Card\".", index);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_GROUP: {
|
||||
if(lua_isuserdata(L, index) && check_data_type(L, index, "Group"))
|
||||
return TRUE;
|
||||
if(retfalse)
|
||||
return FALSE;
|
||||
return luaL_error(L, "Parameter %d should be \"Group\".", index);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_EFFECT: {
|
||||
if(lua_isuserdata(L, index) && check_data_type(L, index, "Effect"))
|
||||
return TRUE;
|
||||
if(retfalse)
|
||||
return FALSE;
|
||||
return luaL_error(L, "Parameter %d should be \"Effect\".", index);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_FUNCTION: {
|
||||
if(lua_isfunction(L, index))
|
||||
return TRUE;
|
||||
if(retfalse)
|
||||
return FALSE;
|
||||
return luaL_error(L, "Parameter %d should be \"Function\".", index);
|
||||
break;
|
||||
}
|
||||
case PARAM_TYPE_STRING: {
|
||||
if(lua_isstring(L, index))
|
||||
return TRUE;
|
||||
if(retfalse)
|
||||
return FALSE;
|
||||
return luaL_error(L, "Parameter %d should be \"String\".", index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int32_t scriptlib::check_param_count(lua_State* L, int32_t count) {
|
||||
if (lua_gettop(L) < count)
|
||||
return luaL_error(L, "%d Parameters are needed.", count);
|
||||
return TRUE;
|
||||
}
|
||||
int32_t scriptlib::check_action_permission(lua_State* L) {
|
||||
duel* pduel = interpreter::get_duel_info(L);
|
||||
if(pduel->lua->no_action && !pduel->lua->disable_action_check)
|
||||
return luaL_error(L, "Action is not allowed here.");
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,728 @@
|
||||
/*
|
||||
* scriptlib.h
|
||||
*
|
||||
* Created on: 2009-1-20
|
||||
* Author: Argon.Sun
|
||||
*/
|
||||
|
||||
#ifndef SCRIPTLIB_H_
|
||||
#define SCRIPTLIB_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "interpreter.h"
|
||||
|
||||
constexpr bool match_all(uint32_t x, uint32_t y) {
|
||||
return (x & y) == y;
|
||||
}
|
||||
|
||||
class scriptlib {
|
||||
public:
|
||||
enum effect_member : int32_t {
|
||||
MEMBER_CATEGORY,
|
||||
MEMBER_CODE,
|
||||
MEMBER_DESCRIPTION,
|
||||
MEMBER_ID,
|
||||
MEMBER_RANGE,
|
||||
MEMBER_TYPE,
|
||||
};
|
||||
static int32_t check_param(lua_State* L, int32_t param_type, int32_t index, int32_t retfalse = FALSE);
|
||||
static int32_t check_param_count(lua_State* L, int32_t count);
|
||||
static int32_t check_action_permission(lua_State* L);
|
||||
//millux
|
||||
static int32_t card_get_card_registered(lua_State *L);
|
||||
static int32_t card_is_ritual_type(lua_State *L);
|
||||
static int32_t card_set_entity_code(lua_State *L);
|
||||
static int32_t card_set_card_data(lua_State *L);
|
||||
static int32_t card_get_link_marker(lua_State *L);
|
||||
static int32_t card_get_origin_link_marker(lua_State *L);
|
||||
static int32_t card_is_xyz_summonable_by_rose(lua_State *L);
|
||||
static int32_t card_get_removed_overlay_count(lua_State *L);
|
||||
static int32_t card_check_spsummon_once(lua_State *L);
|
||||
static int32_t effect_set_owner(lua_State *L);
|
||||
static int32_t effect_get_count_limit(lua_State *L);
|
||||
static int32_t duel_get_master_rule(lua_State *L);
|
||||
static int32_t duel_read_card(lua_State *L);
|
||||
static int32_t duel_exile(lua_State *L);
|
||||
static int32_t duel_disable_action_check(lua_State *L);
|
||||
static int32_t duel_setmetatable(lua_State *L);
|
||||
static int32_t duel_move_turn_count(lua_State *L);
|
||||
static int32_t duel_get_cards_in_zone(lua_State *L);
|
||||
static int32_t duel_xyz_summon_by_rose(lua_State *L);
|
||||
static int32_t duel_load_script(lua_State *L);
|
||||
static int32_t duel_reset_time_limit(lua_State *L);
|
||||
static int32_t duel_set_summon_cancelable(lua_State *L);
|
||||
static int32_t duel_get_random_number(lua_State *L);
|
||||
static int32_t duel_get_registry_value(lua_State *L);
|
||||
static int32_t duel_set_registry_value(lua_State *L);
|
||||
static int32_t duel_get_registry_keys(lua_State *L);
|
||||
static int32_t duel_set_registry(lua_State *L);
|
||||
static int32_t duel_get_registry(lua_State *L);
|
||||
static int32_t duel_clear_registry(lua_State *L);
|
||||
static int32_t duel_is_global_flag(lua_State *L);
|
||||
//card lib
|
||||
static int32_t card_get_code(lua_State *L);
|
||||
static int32_t card_get_origin_code(lua_State *L);
|
||||
static int32_t card_get_origin_code_rule(lua_State *L);
|
||||
static int32_t card_get_fusion_code(lua_State *L);
|
||||
static int32_t card_get_link_code(lua_State *L);
|
||||
static int32_t card_is_fusion_code(lua_State *L);
|
||||
static int32_t card_is_link_code(lua_State *L);
|
||||
static int32_t card_is_set_card(lua_State *L);
|
||||
static int32_t card_is_origin_set_card(lua_State *L);
|
||||
static int32_t card_is_pre_set_card(lua_State *L);
|
||||
static int32_t card_is_fusion_set_card(lua_State *L);
|
||||
static int32_t card_is_link_set_card(lua_State *L);
|
||||
static int32_t card_is_special_summon_set_card(lua_State *L);
|
||||
static int32_t card_get_type(lua_State *L);
|
||||
static int32_t card_get_origin_type(lua_State *L);
|
||||
static int32_t card_get_fusion_type(lua_State *L);
|
||||
static int32_t card_get_synchro_type(lua_State *L);
|
||||
static int32_t card_get_xyz_type(lua_State *L);
|
||||
static int32_t card_get_link_type(lua_State *L);
|
||||
static int32_t card_get_level(lua_State *L);
|
||||
static int32_t card_get_rank(lua_State *L);
|
||||
static int32_t card_get_link(lua_State *L);
|
||||
static int32_t card_get_synchro_level(lua_State *L);
|
||||
static int32_t card_get_ritual_level(lua_State *L);
|
||||
static int32_t card_get_origin_level(lua_State *L);
|
||||
static int32_t card_get_origin_rank(lua_State *L);
|
||||
static int32_t card_is_xyz_level(lua_State *L);
|
||||
static int32_t card_get_lscale(lua_State *L);
|
||||
static int32_t card_get_origin_lscale(lua_State *L);
|
||||
static int32_t card_get_rscale(lua_State *L);
|
||||
static int32_t card_get_origin_rscale(lua_State *L);
|
||||
static int32_t card_get_current_scale(lua_State *L);
|
||||
static int32_t card_is_link_marker(lua_State *L);
|
||||
static int32_t card_get_linked_group(lua_State *L);
|
||||
static int32_t card_get_linked_group_count(lua_State *L);
|
||||
static int32_t card_get_linked_zone(lua_State *L);
|
||||
static int32_t card_get_mutual_linked_group(lua_State *L);
|
||||
static int32_t card_get_mutual_linked_group_count(lua_State *L);
|
||||
static int32_t card_get_mutual_linked_zone(lua_State *L);
|
||||
static int32_t card_is_link_state(lua_State *L);
|
||||
static int32_t card_is_extra_link_state(lua_State *L);
|
||||
static int32_t card_get_column_group(lua_State *L);
|
||||
static int32_t card_get_column_group_count(lua_State *L);
|
||||
static int32_t card_get_column_zone(lua_State *L);
|
||||
static int32_t card_is_all_column(lua_State *L);
|
||||
static int32_t card_get_attribute(lua_State *L);
|
||||
static int32_t card_get_origin_attribute(lua_State *L);
|
||||
static int32_t card_get_fusion_attribute(lua_State *L);
|
||||
static int32_t card_get_link_attribute(lua_State *L);
|
||||
static int32_t card_get_attribute_in_grave(lua_State *L);
|
||||
static int32_t card_get_race(lua_State *L);
|
||||
static int32_t card_get_origin_race(lua_State *L);
|
||||
static int32_t card_get_link_race(lua_State *L);
|
||||
static int32_t card_get_race_in_grave(lua_State *L);
|
||||
static int32_t card_get_attack(lua_State *L);
|
||||
static int32_t card_get_origin_attack(lua_State *L);
|
||||
static int32_t card_get_text_attack(lua_State *L);
|
||||
static int32_t card_get_defense(lua_State *L);
|
||||
static int32_t card_get_origin_defense(lua_State *L);
|
||||
static int32_t card_get_text_defense(lua_State *L);
|
||||
static int32_t card_get_previous_code_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_type_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_level_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_rank_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_attribute_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_race_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_attack_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_defense_onfield(lua_State *L);
|
||||
static int32_t card_get_previous_overlay_count_onfield(lua_State *L);
|
||||
static int32_t card_get_owner(lua_State *L);
|
||||
static int32_t card_get_controler(lua_State *L);
|
||||
static int32_t card_get_previous_controler(lua_State *L);
|
||||
static int32_t card_set_reason(lua_State *L);
|
||||
static int32_t card_get_reason(lua_State *L);
|
||||
static int32_t card_get_reason_card(lua_State *L);
|
||||
static int32_t card_get_reason_player(lua_State *L);
|
||||
static int32_t card_get_reason_effect(lua_State *L);
|
||||
static int32_t card_get_position(lua_State *L);
|
||||
static int32_t card_get_previous_position(lua_State *L);
|
||||
static int32_t card_get_battle_position(lua_State *L);
|
||||
static int32_t card_get_location(lua_State *L);
|
||||
static int32_t card_get_previous_location(lua_State *L);
|
||||
static int32_t card_get_sequence(lua_State *L);
|
||||
static int32_t card_get_previous_sequence(lua_State *L);
|
||||
static int32_t card_get_summon_type(lua_State *L);
|
||||
static int32_t card_get_summon_location(lua_State *L);
|
||||
static int32_t card_get_summon_player(lua_State *L);
|
||||
static int32_t card_get_destination(lua_State *L);
|
||||
static int32_t card_get_leave_field_dest(lua_State *L);
|
||||
static int32_t card_get_turnid(lua_State *L);
|
||||
static int32_t card_get_fieldid(lua_State *L);
|
||||
static int32_t card_get_fieldidr(lua_State *L);
|
||||
static int32_t card_is_origin_code_rule(lua_State *L);
|
||||
static int32_t card_is_code(lua_State *L);
|
||||
static int32_t card_is_type(lua_State *L);
|
||||
static int32_t card_is_all_types(lua_State *L);
|
||||
static int32_t card_is_fusion_type(lua_State *L);
|
||||
static int32_t card_is_synchro_type(lua_State *L);
|
||||
static int32_t card_is_xyz_type(lua_State *L);
|
||||
static int32_t card_is_link_type(lua_State *L);
|
||||
static int32_t card_is_level(lua_State *L);
|
||||
static int32_t card_is_rank(lua_State *L);
|
||||
static int32_t card_is_link(lua_State *L);
|
||||
static int32_t card_is_attack(lua_State *L);
|
||||
static int32_t card_is_defense(lua_State *L);
|
||||
static int32_t card_is_race(lua_State *L);
|
||||
static int32_t card_is_link_race(lua_State *L);
|
||||
static int32_t card_is_attribute(lua_State *L);
|
||||
static int32_t card_is_fusion_attribute(lua_State *L);
|
||||
static int32_t card_is_link_attribute(lua_State *L);
|
||||
static int32_t card_is_non_attribute(lua_State *L);
|
||||
static int32_t card_is_extra_deck_monster(lua_State *L);
|
||||
static int32_t card_is_reason(lua_State *L);
|
||||
static int32_t card_is_all_reasons(lua_State *L);
|
||||
static int32_t card_is_summon_type(lua_State *L);
|
||||
static int32_t card_is_summon_location(lua_State *L);
|
||||
static int32_t card_is_summon_player(lua_State *L);
|
||||
static int32_t card_get_special_summon_info(lua_State *L);
|
||||
static int32_t card_is_status(lua_State *L);
|
||||
static int32_t card_is_not_tuner(lua_State *L);
|
||||
static int32_t card_is_tuner(lua_State* L);
|
||||
static int32_t card_is_original_effect_property(lua_State* L);
|
||||
static int32_t card_is_effect_property(lua_State* L);
|
||||
static int32_t card_set_status(lua_State *L);
|
||||
static int32_t card_is_dual_state(lua_State *L);
|
||||
static int32_t card_enable_dual_state(lua_State *L);
|
||||
static int32_t card_set_turn_counter(lua_State *L);
|
||||
static int32_t card_get_turn_counter(lua_State *L);
|
||||
static int32_t card_set_material(lua_State *L);
|
||||
static int32_t card_get_material(lua_State *L);
|
||||
static int32_t card_get_material_count(lua_State *L);
|
||||
static int32_t card_get_equip_group(lua_State *L);
|
||||
static int32_t card_get_equip_count(lua_State *L);
|
||||
static int32_t card_get_equip_target(lua_State *L);
|
||||
static int32_t card_get_pre_equip_target(lua_State *L);
|
||||
static int32_t card_check_equip_target(lua_State *L);
|
||||
static int32_t card_check_union_target(lua_State *L);
|
||||
static int32_t card_get_union_count(lua_State *L);
|
||||
static int32_t card_get_overlay_group(lua_State *L);
|
||||
static int32_t card_get_overlay_count(lua_State *L);
|
||||
static int32_t card_get_overlay_target(lua_State *L);
|
||||
static int32_t card_check_remove_overlay_card(lua_State *L);
|
||||
static int32_t card_remove_overlay_card(lua_State *L);
|
||||
static int32_t card_get_attacked_group(lua_State *L);
|
||||
static int32_t card_get_attacked_group_count(lua_State *L);
|
||||
static int32_t card_get_attacked_count(lua_State *L);
|
||||
static int32_t card_get_battled_group(lua_State *L);
|
||||
static int32_t card_get_battled_group_count(lua_State *L);
|
||||
static int32_t card_get_attack_announced_count(lua_State *L);
|
||||
static int32_t card_is_direct_attacked(lua_State *L);
|
||||
static int32_t card_set_card_target(lua_State *L);
|
||||
static int32_t card_get_card_target(lua_State *L);
|
||||
static int32_t card_get_first_card_target(lua_State *L);
|
||||
static int32_t card_get_card_target_count(lua_State *L);
|
||||
static int32_t card_is_has_card_target(lua_State *L);
|
||||
static int32_t card_cancel_card_target(lua_State *L);
|
||||
static int32_t card_get_owner_target(lua_State *L);
|
||||
static int32_t card_get_owner_target_count(lua_State *L);
|
||||
static int32_t card_get_activate_effect(lua_State *L);
|
||||
static int32_t card_check_activate_effect(lua_State *L);
|
||||
static int32_t card_get_tuner_limit(lua_State * L);
|
||||
static int32_t card_get_hand_synchro(lua_State * L);
|
||||
static int32_t card_register_effect(lua_State *L);
|
||||
static int32_t card_is_has_effect(lua_State *L);
|
||||
static int32_t card_reset_effect(lua_State *L);
|
||||
static int32_t card_get_effect_count(lua_State *L);
|
||||
static int32_t card_register_flag_effect(lua_State *L);
|
||||
static int32_t card_get_flag_effect(lua_State *L);
|
||||
static int32_t card_reset_flag_effect(lua_State *L);
|
||||
static int32_t card_set_flag_effect_label(lua_State *L);
|
||||
static int32_t card_get_flag_effect_label(lua_State *L);
|
||||
static int32_t card_create_relation(lua_State *L);
|
||||
static int32_t card_release_relation(lua_State *L);
|
||||
static int32_t card_create_effect_relation(lua_State *L);
|
||||
static int32_t card_release_effect_relation(lua_State *L);
|
||||
static int32_t card_clear_effect_relation(lua_State *L);
|
||||
static int32_t card_is_relate_to_effect(lua_State *L);
|
||||
static int32_t card_is_relate_to_chain(lua_State *L);
|
||||
static int32_t card_is_relate_to_card(lua_State *L);
|
||||
static int32_t card_is_relate_to_battle(lua_State *L);
|
||||
static int32_t card_copy_effect(lua_State *L);
|
||||
static int32_t card_replace_effect(lua_State *L);
|
||||
static int32_t card_enable_revive_limit(lua_State *L);
|
||||
static int32_t card_complete_procedure(lua_State *L);
|
||||
static int32_t card_is_disabled(lua_State *L);
|
||||
static int32_t card_is_destructable(lua_State *L);
|
||||
static int32_t card_is_summonable(lua_State *L);
|
||||
static int32_t card_is_special_summonable_card(lua_State *L);
|
||||
static int32_t card_is_fusion_summonable_card(lua_State *L);
|
||||
static int32_t card_is_msetable(lua_State *L);
|
||||
static int32_t card_is_ssetable(lua_State *L);
|
||||
static int32_t card_is_special_summonable(lua_State *L);
|
||||
static int32_t card_is_synchro_summonable(lua_State *L);
|
||||
static int32_t card_is_xyz_summonable(lua_State *L);
|
||||
static int32_t card_is_link_summonable(lua_State *L);
|
||||
static int32_t card_is_can_be_summoned(lua_State *L);
|
||||
static int32_t card_is_can_be_special_summoned(lua_State *L);
|
||||
static int32_t card_is_can_be_placed_on_field(lua_State *L);
|
||||
static int32_t card_is_able_to_hand(lua_State *L);
|
||||
static int32_t card_is_able_to_grave(lua_State *L);
|
||||
static int32_t card_is_able_to_deck(lua_State *L);
|
||||
static int32_t card_is_able_to_extra(lua_State *L);
|
||||
static int32_t card_is_able_to_remove(lua_State *L);
|
||||
static int32_t card_is_able_to_hand_as_cost(lua_State *L);
|
||||
static int32_t card_is_able_to_grave_as_cost(lua_State *L);
|
||||
static int32_t card_is_able_to_deck_as_cost(lua_State *L);
|
||||
static int32_t card_is_able_to_extra_as_cost(lua_State *L);
|
||||
static int32_t card_is_able_to_deck_or_extra_as_cost(lua_State *L);
|
||||
static int32_t card_is_able_to_remove_as_cost(lua_State *L);
|
||||
static int32_t card_is_able_to_decrease_attack_as_cost(lua_State *L);
|
||||
static int32_t card_is_able_to_decrease_defense_as_cost(lua_State *L);
|
||||
static int32_t card_is_releasable(lua_State *L);
|
||||
static int32_t card_is_releasable_by_effect(lua_State *L);
|
||||
static int32_t card_is_discardable(lua_State *L);
|
||||
static int32_t card_is_attackable(lua_State *L);
|
||||
static int32_t card_is_chain_attackable(lua_State *L);
|
||||
static int32_t card_is_faceup(lua_State *L);
|
||||
static int32_t card_is_faceup_ex(lua_State *L);
|
||||
static int32_t card_is_attack_pos(lua_State *L);
|
||||
static int32_t card_is_facedown(lua_State *L);
|
||||
static int32_t card_is_defense_pos(lua_State *L);
|
||||
static int32_t card_is_position(lua_State *L);
|
||||
static int32_t card_is_pre_position(lua_State *L);
|
||||
static int32_t card_is_controler(lua_State *L);
|
||||
static int32_t card_is_pre_controler(lua_State *L);
|
||||
static int32_t card_is_onfield(lua_State *L);
|
||||
static int32_t card_is_location(lua_State *L);
|
||||
static int32_t card_is_pre_location(lua_State *L);
|
||||
static int32_t card_is_level_below(lua_State *L);
|
||||
static int32_t card_is_level_above(lua_State *L);
|
||||
static int32_t card_is_rank_below(lua_State *L);
|
||||
static int32_t card_is_rank_above(lua_State *L);
|
||||
static int32_t card_is_link_below(lua_State *L);
|
||||
static int32_t card_is_link_above(lua_State *L);
|
||||
static int32_t card_is_attack_below(lua_State *L);
|
||||
static int32_t card_is_attack_above(lua_State *L);
|
||||
static int32_t card_is_defense_below(lua_State *L);
|
||||
static int32_t card_is_defense_above(lua_State *L);
|
||||
static int32_t card_is_has_level(lua_State *L);
|
||||
static int32_t card_is_has_defense(lua_State *L);
|
||||
static int32_t card_is_public(lua_State *L);
|
||||
static int32_t card_is_forbidden(lua_State *L);
|
||||
static int32_t card_is_able_to_change_controler(lua_State *L);
|
||||
static int32_t card_is_controler_can_be_changed(lua_State *L);
|
||||
static int32_t card_add_counter(lua_State *L);
|
||||
static int32_t card_remove_counter(lua_State *L);
|
||||
static int32_t card_get_counter(lua_State *L);
|
||||
static int32_t card_enable_counter_permit(lua_State *L);
|
||||
static int32_t card_set_counter_limit(lua_State *L);
|
||||
static int32_t card_is_can_change_position(lua_State *L);
|
||||
static int32_t card_is_can_turn_set(lua_State *L);
|
||||
static int32_t card_is_can_add_counter(lua_State *L);
|
||||
static int32_t card_is_can_remove_counter(lua_State *L);
|
||||
static int32_t card_is_can_have_counter(lua_State* L);
|
||||
static int32_t card_is_can_overlay(lua_State *L);
|
||||
static int32_t card_is_can_be_fusion_material(lua_State *L);
|
||||
static int32_t card_is_can_be_synchro_material(lua_State *L);
|
||||
static int32_t card_is_can_be_ritual_material(lua_State *L);
|
||||
static int32_t card_is_can_be_xyz_material(lua_State *L);
|
||||
static int32_t card_is_can_be_link_material(lua_State *L);
|
||||
static int32_t card_check_fusion_material(lua_State *L);
|
||||
static int32_t card_check_fusion_substitute(lua_State *L);
|
||||
static int32_t card_is_immune_to_effect(lua_State *L);
|
||||
static int32_t card_is_can_be_disabled_by_effect(lua_State* L);
|
||||
static int32_t card_is_can_be_effect_target(lua_State *L);
|
||||
static int32_t card_is_can_be_battle_target(lua_State *L);
|
||||
static int32_t card_add_monster_attribute(lua_State *L);
|
||||
static int32_t card_cancel_to_grave(lua_State *L);
|
||||
static int32_t card_get_tribute_requirement(lua_State *L);
|
||||
static int32_t card_get_battle_target(lua_State *L);
|
||||
static int32_t card_get_attackable_target(lua_State *L);
|
||||
static int32_t card_set_hint(lua_State *L);
|
||||
static int32_t card_reverse_in_deck(lua_State *L);
|
||||
static int32_t card_set_unique_onfield(lua_State *L);
|
||||
static int32_t card_check_unique_onfield(lua_State *L);
|
||||
static int32_t card_reset_negate_effect(lua_State *L);
|
||||
static int32_t card_assume_prop(lua_State *L);
|
||||
static int32_t card_set_spsummon_once(lua_State *L);
|
||||
static void open_cardlib(lua_State *L);
|
||||
|
||||
//Effect functions
|
||||
static int32_t get_effect_property(lua_State* L, effect_member type);
|
||||
static int32_t is_effect_has_property(lua_State* L, effect_member type);
|
||||
static int32_t effect_new(lua_State *L);
|
||||
static int32_t effect_newex(lua_State *L);
|
||||
static int32_t effect_clone(lua_State *L);
|
||||
static int32_t effect_reset(lua_State *L);
|
||||
static int32_t effect_get_field_id(lua_State *L);
|
||||
static int32_t effect_set_description(lua_State *L);
|
||||
static int32_t effect_set_code(lua_State *L);
|
||||
static int32_t effect_set_range(lua_State *L);
|
||||
static int32_t effect_set_target_range(lua_State *L);
|
||||
static int32_t effect_set_absolute_range(lua_State *L);
|
||||
static int32_t effect_set_count_limit(lua_State *L);
|
||||
static int32_t effect_set_reset(lua_State *L);
|
||||
static int32_t effect_set_type(lua_State *L);
|
||||
static int32_t effect_set_property(lua_State *L);
|
||||
static int32_t effect_set_label(lua_State *L);
|
||||
static int32_t effect_set_label_object(lua_State *L);
|
||||
static int32_t effect_set_category(lua_State *L);
|
||||
static int32_t effect_set_hint_timing(lua_State *L);
|
||||
static int32_t effect_set_condition(lua_State *L);
|
||||
static int32_t effect_set_target(lua_State *L);
|
||||
static int32_t effect_set_cost(lua_State *L);
|
||||
static int32_t effect_set_value(lua_State *L);
|
||||
static int32_t effect_set_operation(lua_State *L);
|
||||
static int32_t effect_set_owner_player(lua_State *L);
|
||||
static int32_t effect_get_description(lua_State *L);
|
||||
static int32_t effect_get_code(lua_State *L);
|
||||
static int32_t effect_get_type(lua_State *L);
|
||||
static int32_t effect_get_property(lua_State *L);
|
||||
static int32_t effect_get_label(lua_State *L);
|
||||
static int32_t effect_get_label_object(lua_State *L);
|
||||
static int32_t effect_get_category(lua_State *L);
|
||||
static int32_t effect_get_range(lua_State* L);
|
||||
static int32_t effect_get_owner(lua_State *L);
|
||||
static int32_t effect_get_handler(lua_State *L);
|
||||
static int32_t effect_get_owner_player(lua_State *L);
|
||||
static int32_t effect_get_handler_player(lua_State *L);
|
||||
static int32_t effect_get_condition(lua_State *L);
|
||||
static int32_t effect_get_target(lua_State *L);
|
||||
static int32_t effect_get_cost(lua_State *L);
|
||||
static int32_t effect_get_value(lua_State *L);
|
||||
static int32_t effect_get_operation(lua_State *L);
|
||||
static int32_t effect_get_active_type(lua_State *L);
|
||||
static int32_t effect_is_active_type(lua_State *L);
|
||||
static int32_t effect_is_has_property(lua_State *L);
|
||||
static int32_t effect_is_has_category(lua_State *L);
|
||||
static int32_t effect_is_has_range(lua_State* L);
|
||||
static int32_t effect_is_has_type(lua_State *L);
|
||||
static int32_t effect_is_activatable(lua_State *L);
|
||||
static int32_t effect_is_activated(lua_State *L);
|
||||
static int32_t effect_is_cost_checked(lua_State *L);
|
||||
static int32_t effect_set_cost_check(lua_State *L);
|
||||
static int32_t effect_get_activate_location(lua_State *L);
|
||||
static int32_t effect_get_activate_sequence(lua_State *L);
|
||||
static int32_t effect_check_count_limit(lua_State *L);
|
||||
static int32_t effect_use_count_limit(lua_State *L);
|
||||
static void open_effectlib(lua_State *L);
|
||||
|
||||
//Group functions
|
||||
static int32_t group_new(lua_State *L);
|
||||
static int32_t group_clone(lua_State *L);
|
||||
static int32_t group_from_cards(lua_State *L);
|
||||
static int32_t group_delete(lua_State *L);
|
||||
static int32_t group_keep_alive(lua_State *L);
|
||||
static int32_t group_clear(lua_State *L);
|
||||
static int32_t group_add_card(lua_State *L);
|
||||
static int32_t group_remove_card(lua_State *L);
|
||||
static int32_t group_get_next(lua_State *L);
|
||||
static int32_t group_get_first(lua_State *L);
|
||||
static int32_t group_get_count(lua_State *L);
|
||||
static int32_t group_filter(lua_State *L);
|
||||
static int32_t group_filter_count(lua_State *L);
|
||||
static int32_t group_filter_select(lua_State *L);
|
||||
static int32_t group_select(lua_State *L);
|
||||
static int32_t group_select_unselect(lua_State *L);
|
||||
static int32_t group_random_select(lua_State *L);
|
||||
static int32_t group_cancelable_select(lua_State *L);
|
||||
static int32_t group_is_exists(lua_State *L);
|
||||
static int32_t group_check_with_sum_equal(lua_State *L);
|
||||
static int32_t group_select_with_sum_equal(lua_State *L);
|
||||
static int32_t group_check_with_sum_greater(lua_State *L);
|
||||
static int32_t group_select_with_sum_greater(lua_State *L);
|
||||
static int32_t group_get_min_group(lua_State *L);
|
||||
static int32_t group_get_max_group(lua_State *L);
|
||||
static int32_t group_get_sum(lua_State *L);
|
||||
static int32_t group_get_class_count(lua_State *L);
|
||||
static int32_t group_remove(lua_State *L);
|
||||
static int32_t group_equal(lua_State *L);
|
||||
static int32_t group_is_contains(lua_State *L);
|
||||
static int32_t group_search_card(lua_State *L);
|
||||
static int32_t group_get_bin_class_count(lua_State *L);
|
||||
static void open_grouplib(lua_State *L);
|
||||
|
||||
//Duel functions
|
||||
static int32_t duel_enable_global_flag(lua_State *L);
|
||||
static int32_t duel_get_lp(lua_State *L);
|
||||
static int32_t duel_set_lp(lua_State *L);
|
||||
static int32_t duel_is_turn_player(lua_State *L);
|
||||
static int32_t duel_get_turn_player(lua_State *L);
|
||||
static int32_t duel_get_turn_count(lua_State *L);
|
||||
static int32_t duel_get_draw_count(lua_State *L);
|
||||
static int32_t duel_register_effect(lua_State *L);
|
||||
static int32_t duel_register_flag_effect(lua_State *L);
|
||||
static int32_t duel_get_flag_effect(lua_State *L);
|
||||
static int32_t duel_reset_flag_effect(lua_State *L);
|
||||
static int32_t duel_set_flag_effect_label(lua_State *L);
|
||||
static int32_t duel_get_flag_effect_label(lua_State *L);
|
||||
static int32_t duel_destroy(lua_State *L);
|
||||
static int32_t duel_remove(lua_State *L);
|
||||
static int32_t duel_sendto_grave(lua_State *L);
|
||||
static int32_t duel_summon(lua_State *L);
|
||||
static int32_t duel_special_summon_rule(lua_State *L);
|
||||
static int32_t duel_synchro_summon(lua_State *L);
|
||||
static int32_t duel_xyz_summon(lua_State *L);
|
||||
static int32_t duel_link_summon(lua_State *L);
|
||||
static int32_t duel_setm(lua_State *L);
|
||||
static int32_t duel_sets(lua_State *L);
|
||||
static int32_t duel_create_token(lua_State *L);
|
||||
static int32_t duel_special_summon(lua_State *L);
|
||||
static int32_t duel_special_summon_step(lua_State *L);
|
||||
static int32_t duel_special_summon_complete(lua_State *L);
|
||||
static int32_t duel_sendto_hand(lua_State *L);
|
||||
static int32_t duel_sendto_deck(lua_State *L);
|
||||
static int32_t duel_sendto_extra(lua_State *L);
|
||||
static int32_t duel_get_operated_group(lua_State *L);
|
||||
static int32_t duel_is_can_add_counter(lua_State *L);
|
||||
static int32_t duel_remove_counter(lua_State *L);
|
||||
static int32_t duel_is_can_remove_counter(lua_State *L);
|
||||
static int32_t duel_get_counter(lua_State *L);
|
||||
static int32_t duel_change_form(lua_State *L);
|
||||
static int32_t duel_release(lua_State *L);
|
||||
static int32_t duel_move_to_field(lua_State *L);
|
||||
static int32_t duel_return_to_field(lua_State *L);
|
||||
static int32_t duel_move_sequence(lua_State *L);
|
||||
static int32_t duel_swap_sequence(lua_State *L);
|
||||
static int32_t duel_activate_effect(lua_State *L);
|
||||
static int32_t duel_set_chain_limit(lua_State *L);
|
||||
static int32_t duel_set_chain_limit_p(lua_State *L);
|
||||
static int32_t duel_get_chain_material(lua_State *L);
|
||||
static int32_t duel_confirm_decktop(lua_State *L);
|
||||
static int32_t duel_confirm_extratop(lua_State *L);
|
||||
static int32_t duel_confirm_cards(lua_State *L);
|
||||
static int32_t duel_sort_decktop(lua_State *L);
|
||||
static int32_t duel_check_event(lua_State *L);
|
||||
static int32_t duel_raise_event(lua_State *L);
|
||||
static int32_t duel_raise_single_event(lua_State *L);
|
||||
static int32_t duel_check_timing(lua_State *L);
|
||||
static int32_t duel_is_environment(lua_State *L);
|
||||
|
||||
static int32_t duel_win(lua_State *L);
|
||||
static int32_t duel_draw(lua_State *L);
|
||||
static int32_t duel_damage(lua_State *L);
|
||||
static int32_t duel_recover(lua_State *L);
|
||||
static int32_t duel_rd_complete(lua_State *L);
|
||||
static int32_t duel_equip(lua_State *L);
|
||||
static int32_t duel_equip_complete(lua_State *L);
|
||||
static int32_t duel_get_control(lua_State *L);
|
||||
static int32_t duel_swap_control(lua_State *L);
|
||||
static int32_t duel_check_lp_cost(lua_State *L);
|
||||
static int32_t duel_pay_lp_cost(lua_State *L);
|
||||
static int32_t duel_discard_deck(lua_State *L);
|
||||
static int32_t duel_discard_hand(lua_State *L);
|
||||
static int32_t duel_disable_shuffle_check(lua_State *L);
|
||||
static int32_t duel_disable_self_destroy_check(lua_State *L);
|
||||
static int32_t duel_reveal_select_deck_sequence(lua_State *L);
|
||||
static int32_t duel_shuffle_deck(lua_State *L);
|
||||
static int32_t duel_shuffle_extra(lua_State *L);
|
||||
static int32_t duel_shuffle_hand(lua_State *L);
|
||||
static int32_t duel_shuffle_setcard(lua_State *L);
|
||||
static int32_t duel_change_attacker(lua_State *L);
|
||||
static int32_t duel_change_attack_target(lua_State *L);
|
||||
static int32_t duel_calculate_damage(lua_State *L);
|
||||
static int32_t duel_get_battle_damage(lua_State *L);
|
||||
static int32_t duel_change_battle_damage(lua_State *L);
|
||||
static int32_t duel_change_target(lua_State *L);
|
||||
static int32_t duel_change_target_player(lua_State *L);
|
||||
static int32_t duel_change_target_param(lua_State *L);
|
||||
static int32_t duel_break_effect(lua_State *L);
|
||||
static int32_t duel_change_effect(lua_State *L);
|
||||
static int32_t duel_negate_activate(lua_State *L);
|
||||
static int32_t duel_negate_effect(lua_State *L);
|
||||
static int32_t duel_negate_related_chain(lua_State *L);
|
||||
static int32_t duel_disable_summon(lua_State *L);
|
||||
static int32_t duel_increase_summon_count(lua_State *L);
|
||||
static int32_t duel_check_summon_count(lua_State *L);
|
||||
static int32_t duel_get_location_count(lua_State *L);
|
||||
static int32_t duel_get_mzone_count(lua_State *L);
|
||||
static int32_t duel_get_szone_count(lua_State *L);
|
||||
static int32_t duel_get_location_count_fromex(lua_State *L);
|
||||
static int32_t duel_get_usable_mzone_count(lua_State *L);
|
||||
static int32_t duel_get_linked_group(lua_State *L);
|
||||
static int32_t duel_get_linked_group_count(lua_State *L);
|
||||
static int32_t duel_get_linked_zone(lua_State *L);
|
||||
static int32_t duel_get_field_card(lua_State *L);
|
||||
static int32_t duel_check_location(lua_State *L);
|
||||
static int32_t duel_get_current_chain(lua_State *L);
|
||||
static int32_t duel_get_ready_chain(lua_State* L);
|
||||
static int32_t duel_get_chain_info(lua_State *L);
|
||||
static int32_t duel_get_chain_event(lua_State *L);
|
||||
static int32_t duel_get_first_target(lua_State *L);
|
||||
static int32_t duel_get_targets_relate_to_chain(lua_State *L);
|
||||
static int32_t duel_is_phase(lua_State *L);
|
||||
static int32_t duel_is_main_phase(lua_State *L);
|
||||
static int32_t duel_is_battle_phase(lua_State *L);
|
||||
static int32_t duel_get_current_phase(lua_State *L);
|
||||
static int32_t duel_skip_phase(lua_State *L);
|
||||
static int32_t duel_is_damage_calculated(lua_State *L);
|
||||
static int32_t duel_get_attacker(lua_State *L);
|
||||
static int32_t duel_get_attack_target(lua_State* L);
|
||||
static int32_t duel_get_battle_monster(lua_State* L);
|
||||
static int32_t duel_disable_attack(lua_State *L);
|
||||
static int32_t duel_chain_attack(lua_State *L);
|
||||
static int32_t duel_readjust(lua_State *L);
|
||||
static int32_t duel_adjust_instantly(lua_State *L);
|
||||
static int32_t duel_adjust_all(lua_State *L);
|
||||
|
||||
static int32_t duel_get_field_group(lua_State *L);
|
||||
static int32_t duel_get_field_group_count(lua_State *L);
|
||||
static int32_t duel_get_decktop_group(lua_State *L);
|
||||
static int32_t duel_get_extratop_group(lua_State *L);
|
||||
static int32_t duel_get_matching_group(lua_State *L);
|
||||
static int32_t duel_get_matching_count(lua_State *L);
|
||||
static int32_t duel_get_first_matching_card(lua_State *L);
|
||||
static int32_t duel_is_existing_matching_card(lua_State *L);
|
||||
static int32_t duel_select_matching_cards(lua_State *L);
|
||||
static int32_t duel_get_release_group(lua_State *L);
|
||||
static int32_t duel_get_release_group_count(lua_State *L);
|
||||
static int32_t duel_check_release_group(lua_State *L);
|
||||
static int32_t duel_select_release_group(lua_State *L);
|
||||
static int32_t duel_check_release_group_ex(lua_State *L);
|
||||
static int32_t duel_select_release_group_ex(lua_State *L);
|
||||
static int32_t duel_get_tribute_group(lua_State *L);
|
||||
static int32_t duel_get_tribute_count(lua_State *L);
|
||||
static int32_t duel_check_tribute(lua_State *L);
|
||||
static int32_t duel_select_tribute(lua_State *L);
|
||||
static int32_t duel_get_target_count(lua_State *L);
|
||||
static int32_t duel_is_existing_target(lua_State *L);
|
||||
static int32_t duel_select_target(lua_State *L);
|
||||
static int32_t duel_get_must_material(lua_State *L);
|
||||
static int32_t duel_check_must_material(lua_State *L);
|
||||
static int32_t duel_select_fusion_material(lua_State *L);
|
||||
static int32_t duel_set_fusion_material(lua_State *L);
|
||||
static int32_t duel_set_synchro_material(lua_State *L);
|
||||
static int32_t duel_get_synchro_material(lua_State *L);
|
||||
static int32_t duel_select_synchro_material(lua_State *L);
|
||||
static int32_t duel_check_synchro_material(lua_State *L);
|
||||
static int32_t duel_select_tuner_material(lua_State *L);
|
||||
static int32_t duel_check_tuner_material(lua_State *L);
|
||||
static int32_t duel_get_ritual_material(lua_State *L);
|
||||
static int32_t duel_get_ritual_material_ex(lua_State *L);
|
||||
static int32_t duel_release_ritual_material(lua_State *L);
|
||||
static int32_t duel_get_fusion_material(lua_State *L);
|
||||
static int32_t duel_is_summon_cancelable(lua_State *L);
|
||||
static int32_t duel_set_must_select_cards(lua_State *L);
|
||||
static int32_t duel_grab_must_select_cards(lua_State *L);
|
||||
static int32_t duel_set_target_card(lua_State *L);
|
||||
static int32_t duel_clear_target_card(lua_State *L);
|
||||
static int32_t duel_set_target_player(lua_State *L);
|
||||
static int32_t duel_set_target_param(lua_State *L);
|
||||
static int32_t duel_set_operation_info(lua_State *L);
|
||||
static int32_t duel_get_operation_info(lua_State *L);
|
||||
static int32_t duel_get_operation_count(lua_State *L);
|
||||
static int32_t duel_clear_operation_info(lua_State *L);
|
||||
static int32_t duel_check_xyz_material(lua_State *L);
|
||||
static int32_t duel_select_xyz_material(lua_State *L);
|
||||
static int32_t duel_overlay(lua_State *L);
|
||||
static int32_t duel_get_overlay_group(lua_State *L);
|
||||
static int32_t duel_get_overlay_count(lua_State *L);
|
||||
static int32_t duel_check_remove_overlay_card(lua_State *L);
|
||||
static int32_t duel_remove_overlay_card(lua_State *L);
|
||||
static int32_t duel_get_disable_field(lua_State *L);
|
||||
|
||||
static int32_t duel_hint(lua_State *L);
|
||||
static int32_t duel_get_last_select_hint(lua_State *L);
|
||||
static int32_t duel_hint_selection(lua_State *L);
|
||||
static int32_t duel_select_effect_yesno(lua_State *L);
|
||||
static int32_t duel_select_yesno(lua_State *L);
|
||||
static int32_t duel_select_option(lua_State *L);
|
||||
static int32_t duel_select_sequence(lua_State *L);
|
||||
static int32_t duel_select_position(lua_State *L);
|
||||
static int32_t duel_select_disable_field(lua_State *L);
|
||||
static int32_t duel_select_field(lua_State *L);
|
||||
static int32_t duel_announce_race(lua_State *L);
|
||||
static int32_t duel_announce_attribute(lua_State *L);
|
||||
static int32_t duel_announce_level(lua_State *L);
|
||||
static int32_t duel_announce_card(lua_State *L);
|
||||
static int32_t duel_announce_card_silent(lua_State *L);
|
||||
static int32_t duel_announce_type(lua_State *L);
|
||||
static int32_t duel_announce_number(lua_State *L);
|
||||
static int32_t duel_announce_coin(lua_State *L);
|
||||
static int32_t duel_toss_coin(lua_State *L);
|
||||
static int32_t duel_toss_dice(lua_State *L);
|
||||
static int32_t duel_rock_paper_scissors(lua_State *L);
|
||||
static int32_t duel_get_coin_result(lua_State *L);
|
||||
static int32_t duel_get_dice_result(lua_State *L);
|
||||
static int32_t duel_set_coin_result(lua_State *L);
|
||||
static int32_t duel_set_dice_result(lua_State *L);
|
||||
|
||||
static int32_t duel_is_player_affected_by_effect(lua_State *L);
|
||||
static int32_t duel_is_player_can_draw(lua_State *L);
|
||||
static int32_t duel_is_player_can_discard_deck(lua_State *L);
|
||||
static int32_t duel_is_player_can_discard_deck_as_cost(lua_State *L);
|
||||
static int32_t duel_is_player_can_summon(lua_State *L);
|
||||
static int32_t duel_is_player_can_mset(lua_State *L);
|
||||
static int32_t duel_is_player_can_sset(lua_State *L);
|
||||
static int32_t duel_is_player_can_spsummon(lua_State *L);
|
||||
static int32_t duel_is_player_can_flipsummon(lua_State *L);
|
||||
static int32_t duel_is_player_can_spsummon_monster(lua_State *L);
|
||||
static int32_t duel_is_player_can_spsummon_count(lua_State *L);
|
||||
static int32_t duel_is_player_can_release(lua_State *L);
|
||||
static int32_t duel_is_player_can_remove(lua_State *L);
|
||||
static int32_t duel_is_player_can_send_to_hand(lua_State *L);
|
||||
static int32_t duel_is_player_can_send_to_grave(lua_State *L);
|
||||
static int32_t duel_is_player_can_send_to_deck(lua_State *L);
|
||||
static int32_t duel_is_player_can_additional_summon(lua_State *L);
|
||||
static int32_t duel_is_chain_solving(lua_State *L);
|
||||
static int32_t duel_is_chain_negatable(lua_State *L);
|
||||
static int32_t duel_is_chain_disablable(lua_State *L);
|
||||
static int32_t duel_is_chain_disabled(lua_State *L);
|
||||
static int32_t duel_check_chain_target(lua_State *L);
|
||||
static int32_t duel_check_chain_uniqueness(lua_State *L);
|
||||
static int32_t duel_get_activity_count(lua_State *L);
|
||||
static int32_t duel_check_phase_activity(lua_State *L);
|
||||
static int32_t duel_add_custom_activity_counter(lua_State *L);
|
||||
static int32_t duel_get_custom_activity_count(lua_State *L);
|
||||
static int32_t duel_is_able_to_enter_bp(lua_State *L);
|
||||
static int32_t duel_get_battled_count(lua_State *L);
|
||||
|
||||
//specific card functions
|
||||
static int32_t duel_swap_deck_and_grave(lua_State *L);
|
||||
static int32_t duel_majestic_copy(lua_State *L);
|
||||
|
||||
static void open_duellib(lua_State *L);
|
||||
|
||||
//group metamethods
|
||||
//__len is in the group lib, which is same as group_get_count
|
||||
static int32_t group_meta_add(lua_State *L);
|
||||
static int32_t group_meta_sub(lua_State *L);
|
||||
static int32_t group_meta_band(lua_State *L);
|
||||
static int32_t group_meta_bxor(lua_State *L);
|
||||
|
||||
//meta-related methods
|
||||
static int32_t duel_get_meta_value(lua_State *L);
|
||||
static int32_t duel_set_meta_value(lua_State *L);
|
||||
static int32_t duel_has_meta_value(lua_State *L);
|
||||
static int32_t duel_get_meta_keys(lua_State *L);
|
||||
static int32_t duel_clear_meta(lua_State *L);
|
||||
static int32_t duel_get_chain_meta_value(lua_State *L);
|
||||
static int32_t duel_set_chain_meta_value(lua_State *L);
|
||||
static int32_t duel_has_chain_meta_value(lua_State *L);
|
||||
static int32_t duel_get_chain_meta_keys(lua_State *L);
|
||||
static int32_t duel_clear_chain_meta(lua_State *L);
|
||||
static int32_t card_get_meta_value(lua_State *L);
|
||||
static int32_t card_set_meta_value(lua_State *L);
|
||||
static int32_t card_has_meta_value(lua_State *L);
|
||||
static int32_t card_get_meta_keys(lua_State *L);
|
||||
static int32_t card_clear_meta(lua_State *L);
|
||||
static int32_t group_get_meta_value(lua_State *L);
|
||||
static int32_t group_set_meta_value(lua_State *L);
|
||||
static int32_t group_has_meta_value(lua_State *L);
|
||||
static int32_t group_get_meta_keys(lua_State *L);
|
||||
static int32_t group_clear_meta(lua_State *L);
|
||||
static int32_t effect_get_meta_value(lua_State *L);
|
||||
static int32_t effect_set_meta_value(lua_State *L);
|
||||
static int32_t effect_has_meta_value(lua_State *L);
|
||||
static int32_t effect_get_meta_keys(lua_State *L);
|
||||
static int32_t effect_clear_meta(lua_State *L);
|
||||
|
||||
//preload
|
||||
static int32_t debug_message(lua_State *L);
|
||||
static int32_t debug_add_card(lua_State *L);
|
||||
static int32_t debug_set_player_info(lua_State *L);
|
||||
static int32_t debug_pre_summon(lua_State *L);
|
||||
static int32_t debug_pre_equip(lua_State *L);
|
||||
static int32_t debug_pre_set_target(lua_State *L);
|
||||
static int32_t debug_pre_add_counter(lua_State *L);
|
||||
static int32_t debug_reload_field_begin(lua_State *L);
|
||||
static int32_t debug_reload_field_end(lua_State *L);
|
||||
static int32_t debug_set_ai_name(lua_State *L);
|
||||
static int32_t debug_show_hint(lua_State *L);
|
||||
static void open_debuglib(lua_State *L);
|
||||
};
|
||||
|
||||
#endif /* SCRIPTLIB_H_ */
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
#ifndef SORT_H_
|
||||
#define SORT_H_
|
||||
|
||||
class card;
|
||||
|
||||
struct card_sort {
|
||||
bool operator()(card* const& c1, card* const& c2) const;
|
||||
};
|
||||
|
||||
#endif /* SORT_H_ */
|
||||
Reference in new issue
Block a user