Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wind2009-Louse committed May 11, 2024
2 parents dfef9c1 + 73f7723 commit 670cfc6
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 118 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Automated Test Build

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: windows-2022

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install lua
run: |
bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.lua.org/ftp/lua-5.4.6.tar.gz ; exit 0"
tar xzf lua-5.4.6.tar.gz
move lua-5.4.6 lua
- name: Premake
run: |
bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/premake/premake-core/releases/download/v5.0.0-beta2/premake-5.0.0-beta2-windows.zip ; exit 0"
7z x premake-5.0.0-beta2-windows.zip
move premake\lua.lua lua\premake5.lua
move premake\dll.lua dll.lua
.\premake5.exe vs2022 --file=dll.lua
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2

- name: Build
run: |
msbuild build\ocgcoredll.sln /t:Build /p:"Configuration=Release;Platform=Win32"
msbuild build\ocgcoredll.sln /t:Build /p:"Configuration=Release;Platform=x64"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
path: |
build\bin\x32\Release\ocgcore.dll
build\bin\x64\Release\ocgcore.dll
- name: GitHub Release
if: github.event_name == 'push'
uses: salix5/action-automatic-releases@node20
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Development Build"
files: |
build/bin/x64/Release/ocgcore.dll
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.vscode/
.vscode/
/premake5.exe
/build
/lua
64 changes: 57 additions & 7 deletions card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@ bool card::card_operation_sort(card* c1, card* c2) {
return c1->overlay_target->current.sequence < c2->overlay_target->current.sequence;
else
return c1->current.sequence < c2->current.sequence;
} else if (c1->current.location & LOCATION_DECK && !pduel->game_field->core.select_deck_seq_preserved) {
// faceup deck cards should go at the very first
if(c1->current.position != c2->current.position) {
if(c1->current.position & POS_FACEUP)
return false;
else
return true;
}
// if deck reversed and the card being at the top, it should go first
if(pduel->game_field->core.deck_reversed) {
if(c1->current.sequence == pduel->game_field->player[cp1].list_main.size() - 1)
return false;
if(c2->current.sequence == pduel->game_field->player[cp2].list_main.size() - 1)
return true;
}
// sort deck as card property
auto c1_type = c1->data.type & 0x7;
auto c2_type = c2->data.type & 0x7;
// monster should go before spell, and then trap
if(c1_type != c2_type)
return c1_type > c2_type;
if(c1_type & TYPE_MONSTER) {
// sort monster by level, then code
if(c1->data.level != c2->data.level)
return c1->data.level < c2->data.level;
else
return c1->data.code > c2->data.code;
} else
// spell and trap should go by code
return c1->data.code > c2->data.code;
} else {
if(c1->current.location & (LOCATION_DECK | LOCATION_EXTRA | LOCATION_GRAVE | LOCATION_REMOVED))
return c1->current.sequence > c2->current.sequence;
Expand Down Expand Up @@ -143,6 +173,7 @@ card::card(duel* pd) {
assume_type = 0;
assume_value = 0;
spsummon_code = 0;
xyz_materials_previous_count_onfield = 0;
current.controler = PLAYER_NONE;
}
inline void update_cache(uint32& tdata, uint32& cache, int32*& p, uint32& query_flag, const uint32 flag) {
Expand Down Expand Up @@ -1286,8 +1317,7 @@ int32 card::is_link_marker(uint32 dir) {
return (int32)(get_link_marker() & dir);
}
uint32 card::get_linked_zone() {
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE
|| get_status(STATUS_SUMMONING | STATUS_SUMMON_DISABLED | STATUS_SPSUMMON_STEP))
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field())
return 0;
int32 zones = 0;
int32 s = current.sequence;
Expand Down Expand Up @@ -1343,8 +1373,7 @@ void card::get_linked_cards(card_set* cset) {
pduel->game_field->get_cards_in_zone(cset, linked_zone >> 16, 1 - p, LOCATION_MZONE);
}
uint32 card::get_mutual_linked_zone() {
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE
|| get_status(STATUS_SUMMONING | STATUS_SUMMON_DISABLED | STATUS_SPSUMMON_STEP))
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field())
return 0;
int32 zones = 0;
int32 p = current.controler;
Expand Down Expand Up @@ -1507,6 +1536,27 @@ int32 card::is_all_column() {
return TRUE;
return FALSE;
}
uint8 card::get_select_sequence(uint8 *deck_seq_pointer) {
if(current.location == LOCATION_DECK && !pduel->game_field->core.select_deck_seq_preserved) {
return deck_seq_pointer[current.controler]++;
} else {
return current.sequence;
}
}
uint32 card::get_select_info_location(uint8 *deck_seq_pointer) {
if(current.location == LOCATION_DECK) {
uint32 c = current.controler;
uint32 l = current.location;
uint32 s = get_select_sequence(deck_seq_pointer);
uint32 ss = current.position;
return c + (l << 8) + (s << 16) + (ss << 24);
} else {
return get_info_location();
}
}
int32 card::is_treated_as_not_on_field() {
return get_status(STATUS_SUMMONING | STATUS_SUMMON_DISABLED | STATUS_ACTIVATE_DISABLED | STATUS_SPSUMMON_STEP);
}
void card::equip(card* target, uint32 send_msg) {
if (equiping_target)
return;
Expand Down Expand Up @@ -1996,7 +2046,7 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) {
}
int32 card::copy_effect(uint32 code, uint32 reset, uint32 count) {
card_data cdata;
read_card(code, &cdata);
::read_card(code, &cdata);
if(cdata.type & TYPE_NORMAL)
return -1;
set_status(STATUS_COPYING_EFFECT, TRUE);
Expand Down Expand Up @@ -2032,7 +2082,7 @@ int32 card::copy_effect(uint32 code, uint32 reset, uint32 count) {
}
int32 card::replace_effect(uint32 code, uint32 reset, uint32 count) {
card_data cdata;
read_card(code, &cdata);
::read_card(code, &cdata);
if(cdata.type & TYPE_NORMAL)
return -1;
if(is_status(STATUS_EFFECT_REPLACED))
Expand Down Expand Up @@ -2531,7 +2581,7 @@ void card::set_special_summon_status(effect* peffect) {
}
card* pcard = peffect->get_handler();
auto cait = pduel->game_field->core.current_chain.rbegin();
if(!(peffect->type & 0x7f0) || pcard->is_has_relation(*cait)) {
if(!(peffect->type & 0x7f0) || (pcard->is_has_relation(*cait) && !(pcard->get_type() & TYPE_TRAPMONSTER))) {
spsummon.code = pcard->get_code();
spsummon.code2 = pcard->get_another_code();
spsummon.type = pcard->get_type();
Expand Down
4 changes: 4 additions & 0 deletions card.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class card {
card_set effect_target_owner;
card_set effect_target_cards;
card_vector xyz_materials;
int32 xyz_materials_previous_count_onfield;
effect_container single_effect;
effect_container field_effect;
effect_container equip_effect;
Expand Down Expand Up @@ -268,6 +269,9 @@ class card {
uint32 get_column_zone(int32 location);
void get_column_cards(card_set* cset);
int32 is_all_column();
uint8 get_select_sequence(uint8 *deck_seq_pointer);
uint32 get_select_info_location(uint8 *deck_seq_pointer);
int32 is_treated_as_not_on_field();

void equip(card* target, uint32 send_msg = TRUE);
void unequip();
Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define COMMON_H_

#include <stdint.h>
#include <assert.h>
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef unsigned short uint16;
Expand Down
5 changes: 4 additions & 1 deletion duel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "group.h"
#include "ocgapi.h"

inline void write_buffer_vector(std::vector<byte>& buffer, const void*& data, int size) {
inline void write_buffer_vector(std::vector<byte>& buffer, const void* data, int size) {
if (size > 0) {
const auto len = buffer.size();
buffer.resize(len + size);
Expand All @@ -27,6 +27,9 @@ duel::duel() {
game_field = new field(this);
game_field->temp_card = new_card(0);
message_buffer.reserve(SIZE_MESSAGE_BUFFER);
#ifdef _WIN32
_set_error_mode(_OUT_TO_MSGBOX);
#endif // _WIN32
}
duel::~duel() {
for(auto& pcard : cards)
Expand Down
84 changes: 54 additions & 30 deletions effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,56 @@ int32 effect::check_count_limit(uint8 playerid) {
}
return TRUE;
}
// check activate in hand/in set turn
int32 effect::get_required_handorset_effects(effect_set* eset, uint8 playerid, const tevent& e, int32 neglect_loc) {
eset->clear();
if(!(type & EFFECT_TYPE_ACTIVATE))
return 1;
int32 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->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 available = 0;
effect_set tmp_eset;
handler->filter_effect(ecode, &tmp_eset);
for(int32 i = 0; i < tmp_eset.size(); ++i) {
auto peffect = tmp_eset[i];
if(peffect->check_count_limit(playerid)) {
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->add_item(peffect);
}
}
}
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 effect::is_activateable(uint8 playerid, const tevent& e, int32 neglect_cond, int32 neglect_cost, int32 neglect_target, int32 neglect_loc, int32 neglect_faceup) {
Expand Down Expand Up @@ -230,35 +280,9 @@ int32 effect::is_activateable(uint8 playerid, const tevent& e, int32 neglect_con
return FALSE;
}
// check activate in hand/in set turn
int32 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->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) {
bool available = false;
effect_set eset;
handler->filter_effect(ecode, &eset);
for(int32 i = 0; i < eset.size(); ++i) {
if(eset[i]->check_count_limit(playerid)) {
available = true;
break;
}
}
if(!available)
return FALSE;
}
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))
Expand Down Expand Up @@ -473,7 +497,7 @@ int32 effect::is_target(card* pcard) {
&& !pcard->is_position(POS_FACEUP))
return FALSE;
if(!is_flag(EFFECT_FLAG_IGNORE_RANGE)) {
if(pcard->get_status(STATUS_SUMMONING | STATUS_SUMMON_DISABLED | STATUS_ACTIVATE_DISABLED | STATUS_SPSUMMON_STEP))
if(pcard->is_treated_as_not_on_field())
return FALSE;
if(is_flag(EFFECT_FLAG_SPSUM_PARAM))
return FALSE;
Expand Down
6 changes: 4 additions & 2 deletions effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class effect {
int32 value{ 0 };
int32 operation{ 0 };
uint8 cost_checked{ FALSE };
effect_set required_handorset_effects;

explicit effect(duel* pd);
~effect() = default;
Expand All @@ -73,7 +74,8 @@ class effect {
int32 limit_counter_is_available();
int32 is_single_ready();
int32 check_count_limit(uint8 playerid);
int32 is_activateable(uint8 playerid, const tevent& e, int32 neglect_cond = FALSE, int32 neglect_cost = FALSE, int32 neglect_target = FALSE, int32 neglect_loc = FALSE, int32 neglect_faceup = FALSE);
int32 get_required_handorset_effects(effect_set* eset, uint8 playerid, const tevent& e, int32 neglect_loc = FALSE);
int32 is_activateable(uint8 playerid, const tevent &e, int32 neglect_cond = FALSE, int32 neglect_cost = FALSE, int32 neglect_target = FALSE, int32 neglect_loc = FALSE, int32 neglect_faceup = FALSE);
int32 is_action_check(uint8 playerid);
int32 is_activate_ready(effect* reason_effect, uint8 playerid, const tevent& e, int32 neglect_cond = FALSE, int32 neglect_cost = FALSE, int32 neglect_target = FALSE);
int32 is_activate_ready(uint8 playerid, const tevent& e, int32 neglect_cond = FALSE, int32 neglect_cost = FALSE, int32 neglect_target = FALSE);
Expand Down Expand Up @@ -201,7 +203,7 @@ enum effect_flag : uint32 {
EFFECT_FLAG_CLIENT_HINT = 0x4000000,
EFFECT_FLAG_CONTINUOUS_TARGET = 0x8000000,
EFFECT_FLAG_LIMIT_ZONE = 0x10000000,
// EFFECT_FLAG_COF = 0x20000000,
EFFECT_FLAG_ACTIVATE_CONDITION = 0x20000000,
// EFFECT_FLAG_CVAL_CHECK = 0x40000000,
EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000,
};
Expand Down
Loading

0 comments on commit 670cfc6

Please sign in to comment.