Skip to content

Commit

Permalink
Merge branch 'patch-filter' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
salix5 committed Nov 2, 2024
2 parents ab1af69 + a06a3f6 commit e375aca
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 209 deletions.
374 changes: 184 additions & 190 deletions card.cpp

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions card.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ using effect_container = std::multimap<uint32, 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 code{ 0 };
uint32 code2{ 0 };
Expand Down Expand Up @@ -210,6 +213,8 @@ class card {
effect_indexer indexer;
effect_relation relate_effect;
effect_set_v immune_effect;
effect_collection initial_effect;
effect_collection owning_effect;

explicit card(duel* pd);
~card() = default;
Expand Down Expand Up @@ -320,9 +325,11 @@ class card {
void clear_card_target();
void set_special_summon_status(effect* peffect);

void filter_effect(int32 code, effect_set* eset, uint8 sort = TRUE);
void filter_single_continuous_effect(int32 code, effect_set* eset, uint8 sort = TRUE);
void filter_self_effect(int32 code, effect_set* eset, uint8 sort = TRUE);
template<typename T>
void filter_effect_container(const effect_container& container, uint32 code, effect_filter f, T& eset);
void filter_effect(uint32 code, effect_set* eset, uint8 sort = TRUE);
void filter_single_continuous_effect(uint32 code, effect_set* eset, uint8 sort = TRUE);
void filter_self_effect(uint32 code, effect_set* eset, uint8 sort = TRUE);
void filter_immune_effect();
void filter_disable_related_cards();
int32 filter_summon_procedure(uint8 playerid, effect_set* eset, uint8 ignore_count, uint8 min_tribute, uint32 zone);
Expand All @@ -331,7 +338,9 @@ class card {
int32 check_set_procedure(effect* proc, uint8 playerid, uint8 ignore_count, uint8 min_tribute, uint32 zone);
void filter_spsummon_procedure(uint8 playerid, effect_set* eset, uint32 summon_type, material_info info = null_info);
void filter_spsummon_procedure_g(uint8 playerid, effect_set* eset);
effect* is_affected_by_effect(int32 code);
effect* find_effect(const effect_container& container, uint32 code, effect_filter f);
effect* find_effect_with_target(const effect_container& container, uint32 code, effect_filter_target f, card* target);
effect* is_affected_by_effect(uint32 code);
effect* is_affected_by_effect(int32 code, card* target);
int32 fusion_check(group* fusion_m, card* cg, uint32 chkf, uint8 not_material);
void fusion_select(uint8 playerid, group* fusion_m, card* cg, uint32 chkf, uint8 not_material);
Expand Down Expand Up @@ -392,6 +401,8 @@ class card {
int32 is_can_be_ritual_material(card* scard);
int32 is_can_be_xyz_material(card* scard);
int32 is_can_be_link_material(card* scard);
int32 is_original_effect_property(int32 filter);
int32 is_effect_property(int32 filter);
};

//Summon Type in summon_info
Expand Down
8 changes: 4 additions & 4 deletions effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#include "common.h"
#include "field.h"
#include "effectset.h"
#include <stdlib.h>
#include <vector>
#include <map>

class card;
class duel;
Expand Down Expand Up @@ -156,6 +154,8 @@ class effect {
#define RESET_OVERLAY 0x04000000
#define RESET_MSCHANGE 0x08000000

constexpr uint32 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 //
Expand Down Expand Up @@ -191,7 +191,7 @@ enum effect_flag : uint32 {
EFFECT_FLAG_CANNOT_DISABLE = 0x0400,
EFFECT_FLAG_PLAYER_TARGET = 0x0800,
EFFECT_FLAG_BOTH_SIDE = 0x1000,
// EFFECT_FLAG_COPY_INHERIT = 0x2000,
EFFECT_FLAG_COPY = 0x2000,
EFFECT_FLAG_DAMAGE_STEP = 0x4000,
EFFECT_FLAG_DAMAGE_CAL = 0x8000,
EFFECT_FLAG_DELAY = 0x10000,
Expand Down Expand Up @@ -220,7 +220,7 @@ enum effect_flag2 : uint32 {
constexpr effect_flag operator|(effect_flag flag1, effect_flag flag2) {
return static_cast<effect_flag>(static_cast<uint32>(flag1) | static_cast<uint32>(flag2));
}
constexpr uint32 INTERNAL_FLAGS = EFFECT_FLAG_INITIAL | EFFECT_FLAG_FUNC_VALUE | EFFECT_FLAG_COUNT_LIMIT | EFFECT_FLAG_FIELD_ONLY | EFFECT_FLAG_ABSOLUTE_TARGET;
constexpr uint32 INTERNAL_FLAGS = EFFECT_FLAG_INITIAL | EFFECT_FLAG_COPY | EFFECT_FLAG_FUNC_VALUE | EFFECT_FLAG_COUNT_LIMIT | EFFECT_FLAG_FIELD_ONLY | EFFECT_FLAG_ABSOLUTE_TARGET;
//========== Codes ==========
#define EFFECT_IMMUNE_EFFECT 1 //
#define EFFECT_DISABLE 2 //
Expand Down
9 changes: 1 addition & 8 deletions effectset.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ struct effect_set {
void remove_item(int index) {
if (index < 0 || index >= count)
return;
if(index == count - 1) {
--count;
return;
}
for(int i = index; i < count - 1; ++i)
container[i] = container[i + 1];
--count;
Expand Down Expand Up @@ -86,10 +82,7 @@ struct effect_set_v {
return (int)container.size();
}
void sort() {
int count = (int)container.size();
if(count < 2)
return;
std::sort(container.begin(), container.begin() + count, effect_sort_id);
std::sort(container.begin(), container.end(), effect_sort_id);
}
effect* const& get_last() const {
assert(container.size());
Expand Down
2 changes: 0 additions & 2 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <set>
#include <map>
#include <list>
#include <array>
#include <functional>
#include <unordered_map>
#include <unordered_set>

Expand Down
20 changes: 20 additions & 0 deletions libcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,24 @@ int32 scriptlib::card_is_tuner(lua_State* L) {
lua_pushboolean(L, pcard->is_tuner(scard));
return 1;
}
int32 scriptlib::card_is_original_effect_property(lua_State* L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
check_param(L, PARAM_TYPE_FUNCTION, 2);
card* pcard = *(card**)lua_touserdata(L, 1);
int32 filter = interpreter::get_function_handle(L, 2);
lua_pushboolean(L, pcard->is_original_effect_property(filter));
return 1;
}
int32 scriptlib::card_is_effect_property(lua_State* L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
check_param(L, PARAM_TYPE_FUNCTION, 2);
card* pcard = *(card**)lua_touserdata(L, 1);
int32 filter = interpreter::get_function_handle(L, 2);
lua_pushboolean(L, pcard->is_effect_property(filter));
return 1;
}
int32 scriptlib::card_set_status(lua_State *L) {
check_param_count(L, 3);
check_param(L, PARAM_TYPE_CARD, 1);
Expand Down Expand Up @@ -3527,6 +3545,8 @@ static const struct luaL_Reg cardlib[] = {
{ "IsStatus", scriptlib::card_is_status },
{ "IsNotTuner", scriptlib::card_is_not_tuner },
{ "IsTuner", scriptlib::card_is_tuner },
{ "IsOriginalEffectProperty", scriptlib::card_is_original_effect_property },
{ "IsEffectProperty", scriptlib::card_is_effect_property },
{ "SetStatus", scriptlib::card_set_status },
{ "IsDualState", scriptlib::card_is_dual_state },
{ "EnableDualState", scriptlib::card_enable_dual_state },
Expand Down
2 changes: 1 addition & 1 deletion libduel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4796,7 +4796,7 @@ int32 scriptlib::duel_majestic_copy(lua_State *L) {
ceffect->flag[0] &= ~EFFECT_FLAG_INITIAL;
ceffect->effect_owner = PLAYER_NONE;
ceffect->reset_flag = RESET_EVENT + 0x1fe0000 + RESET_PHASE + PHASE_END + RESET_SELF_TURN + RESET_OPPO_TURN;
ceffect->reset_count = 0x1;
ceffect->reset_count = 1;
ceffect->recharge();
if(ceffect->type & EFFECT_TYPE_TRIGGER_F) {
ceffect->type &= ~EFFECT_TYPE_TRIGGER_F;
Expand Down
2 changes: 2 additions & 0 deletions scriptlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class scriptlib {
static int32 card_is_status(lua_State *L);
static int32 card_is_not_tuner(lua_State *L);
static int32 card_is_tuner(lua_State* L);
static int32 card_is_original_effect_property(lua_State* L);
static int32 card_is_effect_property(lua_State* L);
static int32 card_set_status(lua_State *L);
static int32 card_is_dual_state(lua_State *L);
static int32 card_enable_dual_state(lua_State *L);
Expand Down

0 comments on commit e375aca

Please sign in to comment.