Commit 7624c5c7 authored by Dark Zane's avatar Dark Zane Committed by GitHub

Merge branch 'fallenstardust:master' into master

parents 11121cbb 51cfd16c
......@@ -14,6 +14,14 @@
#include "ocgapi.h"
#include <algorithm>
const std::unordered_map<uint32, uint32> card::second_code = {
{CARD_MARINE_DOLPHIN, 17955766u},
{CARD_TWINKLE_MOSS, 17732278u},
{CARD_TIMAEUS, 10000050u},
{CARD_CRITIAS, 10000060u},
{CARD_HERMOS, 10000070u}
};
bool card_sort::operator()(void* const & p1, void* const & p2) const {
card* c1 = (card*)p1;
card* c2 = (card*)p2;
......@@ -411,55 +419,60 @@ uint32 card::get_info_location() {
return c + (l << 8) + (s << 16) + (ss << 24);
}
}
// mapping of double-name cards
uint32 card::second_code(uint32 code){
switch(code){
case CARD_MARINE_DOLPHIN:
return 17955766u;
case CARD_TWINKLE_MOSS:
return 17732278u;
default:
return 0;
// get the printed code on card
uint32 card::get_original_code() const {
if (data.alias && (data.alias < data.code + CARD_ARTWORK_VERSIONS_OFFSET) && (data.code < data.alias + CARD_ARTWORK_VERSIONS_OFFSET))
return data.alias;
else
return data.code;
}
// get the original code in duel (can be different from printed code)
std::tuple<uint32, uint32> card::get_original_code_rule() const {
auto it = second_code.find(data.code);
if (it != second_code.end()) {
return std::make_tuple(data.code, it->second);
}
else {
if (data.alias)
return std::make_tuple(data.alias, 0);
else
return std::make_tuple(data.code, 0);
}
}
// return: the current card name
// for double-name card, it returns printed name
// for double-name cards, it returns printed name
uint32 card::get_code() {
if(assume_type == ASSUME_CODE)
return assume_value;
if (temp.code != 0xffffffff)
return temp.code;
effect_set effects;
uint32 code = data.code;
temp.code = data.code;
uint32 code = std::get<0>(get_original_code_rule());
temp.code = code;
filter_effect(EFFECT_CHANGE_CODE, &effects);
if (effects.size())
code = effects.get_last()->get_value(this);
temp.code = 0xffffffff;
if (code == data.code) {
if(data.alias && !is_affected_by_effect(EFFECT_ADD_CODE))
code = data.alias;
} else {
card_data dat;
read_card(code, &dat);
if (dat.alias && !second_code(code))
code = dat.alias;
}
return code;
}
// return: the current second card name
// for double-name cards, it returns the name in description
uint32 card::get_another_code() {
uint32 code = get_code();
if(code != data.code){
return second_code(code);
uint32 code1 = get_code();
if (is_affected_by_effect(EFFECT_CHANGE_CODE)) {
auto it = second_code.find(code1);
if (it != second_code.end())
return it->second;
else
return 0;
}
uint32 code2 = std::get<1>(get_original_code_rule());
effect_set eset;
filter_effect(EFFECT_ADD_CODE, &eset);
if(!eset.size())
return 0;
return code2;
uint32 otcode = eset.get_last()->get_value(this);
if(code != otcode)
if(code1 != otcode)
return otcode;
return 0;
}
......@@ -2578,6 +2591,7 @@ void card::set_special_summon_status(effect* peffect) {
spsummon.defense = 0;
spsummon.setcode.clear();
spsummon.reason_effect = nullptr;
spsummon.reason_player = PLAYER_NONE;
return;
}
card* pcard = peffect->get_handler();
......@@ -2600,6 +2614,7 @@ void card::set_special_summon_status(effect* peffect) {
spsummon.setcode.push_back((uint32)eset[i]->get_value(pcard));
}
spsummon.reason_effect = peffect;
spsummon.reason_player = peffect->get_handler_player();
} else {
pcard = cait->triggering_effect->get_handler();
spsummon.code = cait->triggering_state.code;
......@@ -2618,6 +2633,7 @@ void card::set_special_summon_status(effect* peffect) {
spsummon.setcode.push_back((uint32)eset[i]->get_value(pcard));
}
spsummon.reason_effect = cait->triggering_effect;
spsummon.reason_player = cait->triggering_player;
}
}
void card::filter_effect(int32 code, effect_set* eset, uint8 sort) {
......@@ -3312,6 +3328,8 @@ int32 card::is_spsummonable_card() {
int32 card::is_fusion_summonable_card(uint32 summon_type) {
if(!(data.type & TYPE_FUSION))
return FALSE;
if((data.type & TYPE_PENDULUM) && current.location == LOCATION_EXTRA && (current.position & POS_FACEUP))
return FALSE;
summon_type |= SUMMON_TYPE_FUSION;
effect_set eset;
filter_effect(EFFECT_SPSUMMON_CONDITION, &eset);
......
......@@ -99,6 +99,12 @@ struct material_info {
};
const material_info null_info;
constexpr uint32 CARD_MARINE_DOLPHIN = 78734254;
constexpr uint32 CARD_TWINKLE_MOSS = 13857930;
constexpr uint32 CARD_TIMAEUS = 1784686;
constexpr uint32 CARD_CRITIAS = 11082056;
constexpr uint32 CARD_HERMOS = 46232525;
class card {
public:
struct effect_relation_hash {
......@@ -137,6 +143,8 @@ public:
uint8 location{ 0 };
uint8 sequence{ 0 };
};
static const std::unordered_map<uint32, uint32> second_code;
int32 ref_handle;
duel* pduel;
card_data data;
......@@ -206,7 +214,8 @@ public:
int32 get_infos(byte* buf, uint32 query_flag, int32 use_cache = TRUE);
uint32 get_info_location();
uint32 second_code(uint32 code);
uint32 get_original_code() const;
std::tuple<uint32, uint32> get_original_code_rule() const;
uint32 get_code();
uint32 get_another_code();
int32 is_set_card(uint32 set_code);
......@@ -389,6 +398,9 @@ public:
#define SUMMON_TYPE_PENDULUM 0x4a000000
#define SUMMON_TYPE_LINK 0x4c000000
#define SUMMON_TYPE_MAIN 0xf0000000
#define SUMMON_TYPE_LOCATION 0x00ff0000
//Counter
#define COUNTER_WITHOUT_PERMIT 0x1000
//#define COUNTER_NEED_ENABLE 0x2000
......@@ -403,7 +415,7 @@ public:
#define ASSUME_ATTACK 7
#define ASSUME_DEFENSE 8
//Summon info
//Special Summon effect info
#define SUMMON_INFO_CODE 0x01
#define SUMMON_INFO_CODE2 0x02
#define SUMMON_INFO_TYPE 0x04
......@@ -414,10 +426,7 @@ public:
#define SUMMON_INFO_ATTACK 0x80
#define SUMMON_INFO_DEFENSE 0x100
#define SUMMON_INFO_REASON_EFFECT 0x200
//double-name cards
#define CARD_MARINE_DOLPHIN 78734254
#define CARD_TWINKLE_MOSS 13857930
#define SUMMON_INFO_REASON_PLAYER 0x400
#define CARD_ARTWORK_VERSIONS_OFFSET 10
......
......@@ -24,10 +24,6 @@ typedef signed char int8;
#define ADD_BIT(x,y) ((x)|=(y))
#define REMOVE_BIT(x,y) ((x)&=~(y))
constexpr bool match_all(uint32 x, uint32 y) {
return (x & y) == y;
}
#define OPERATION_SUCCESS 1
#define OPERATION_FAIL 0
#define OPERATION_CANCELED -1
......
......@@ -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);
......
......@@ -43,8 +43,6 @@ int32 effect::is_self_destroy_related() {
int32 effect::is_can_be_forbidden() {
if (is_flag(EFFECT_FLAG_CANNOT_DISABLE) && !is_flag(EFFECT_FLAG_CANNOT_NEGATE))
return FALSE;
if (code == EFFECT_CHANGE_CODE)
return FALSE;
return TRUE;
}
// check if a single/field/equip effect is available
......
......@@ -533,10 +533,10 @@ card* field::get_field_card(uint32 playerid, uint32 location, uint32 sequence) {
case LOCATION_PZONE: {
if(sequence == 0) {
card* pcard = player[playerid].list_szone[core.duel_rule >= 4 ? 0 : 6];
return pcard && pcard->current.pzone ? pcard : 0;
return (pcard && pcard->current.pzone) ? pcard : 0;
} else if(sequence == 1) {
card* pcard = player[playerid].list_szone[core.duel_rule >= 4 ? 4 : 7];
return pcard && pcard->current.pzone ? pcard : 0;
return (pcard && pcard->current.pzone) ? pcard : 0;
} else
return nullptr;
break;
......@@ -1894,7 +1894,7 @@ void field::get_ritual_material(uint8 playerid, effect* peffect, card_set* mater
void field::get_fusion_material(uint8 playerid, card_set* material_all, card_set* material_base, uint32 location) {
if(location & LOCATION_MZONE) {
for(auto& pcard : player[playerid].list_mzone) {
if(pcard)
if(pcard && !pcard->is_status(STATUS_SUMMONING))
material_base->insert(pcard);
}
}
......
......@@ -24,40 +24,29 @@ int32 scriptlib::card_get_code(lua_State *L) {
}
return 1;
}
// GetOriginalCode(): get the original code printed on card
// return: 1 int
int32 scriptlib::card_get_origin_code(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
if(pcard->data.alias) {
if((pcard->data.alias < pcard->data.code + CARD_ARTWORK_VERSIONS_OFFSET) && (pcard->data.code < pcard->data.alias + CARD_ARTWORK_VERSIONS_OFFSET))
lua_pushinteger(L, pcard->data.alias);
else
lua_pushinteger(L, pcard->data.code);
} else
lua_pushinteger(L, pcard->data.code);
lua_pushinteger(L, pcard->get_original_code());
return 1;
}
// GetOriginalCodeRule(): get the original code in duel (can be different from printed code)
// return: 1-2 int
int32 scriptlib::card_get_origin_code_rule(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
effect_set eset;
pcard->filter_effect(EFFECT_ADD_CODE, &eset);
if(pcard->data.alias && !eset.size())
lua_pushinteger(L, pcard->data.alias);
auto codes = pcard->get_original_code_rule();
uint32 code1 = std::get<0>(codes);
uint32 code2 = std::get<1>(codes);
if (code2) {
lua_pushinteger(L, code1);
lua_pushinteger(L, code2);
return 2;
}
else {
lua_pushinteger(L, pcard->data.code);
if(eset.size()) {
uint32 otcode = eset.get_last()->get_value(pcard);
lua_pushinteger(L, otcode);
return 2;
}
lua_pushinteger(L, code1);
return 1;
}
return 1;
}
int32 scriptlib::card_get_fusion_code(lua_State *L) {
check_param_count(L, 1);
......@@ -921,6 +910,9 @@ int32 scriptlib::card_get_special_summon_info(lua_State *L) {
case SUMMON_INFO_REASON_EFFECT:
interpreter::effect2value(L, pcard->spsummon.reason_effect);
break;
case SUMMON_INFO_REASON_PLAYER:
lua_pushinteger(L, pcard->spsummon.reason_player);
break;
default:
lua_pushnil(L);
break;
......@@ -967,19 +959,9 @@ int32 scriptlib::card_is_origin_code_rule(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
uint32 code1 = 0;
uint32 code2 = 0;
effect_set eset;
pcard->filter_effect(EFFECT_ADD_CODE, &eset);
if(pcard->data.alias && !eset.size()){
code1 = pcard->data.alias;
code2 = 0;
}
else {
code1 = pcard->data.code;
if(eset.size())
code2 = eset.get_last()->get_value(pcard);
}
auto codes = pcard->get_original_code_rule();
uint32 code1 = std::get<0>(codes);
uint32 code2 = std::get<1>(codes);
uint32 count = lua_gettop(L) - 1;
uint32 result = FALSE;
for(uint32 i = 0; i < count; ++i) {
......
......@@ -1913,7 +1913,7 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
core.units.begin()->ptr2 = 0;
}
if(target->current.location == LOCATION_MZONE)
send_to(target, 0, REASON_RULE, sumplayer, sumplayer, LOCATION_GRAVE, 0, 0);
send_to(target, 0, REASON_RULE, PLAYER_NONE, sumplayer, LOCATION_GRAVE, 0, 0);
adjust_instant();
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, 0);
return TRUE;
......@@ -2020,7 +2020,7 @@ int32 field::flip_summon(uint16 step, uint8 sumplayer, card * target) {
core.units.begin()->ptr1 = 0;
}
if(target->current.location == LOCATION_MZONE)
send_to(target, 0, REASON_RULE, sumplayer, sumplayer, LOCATION_GRAVE, 0, 0);
send_to(target, 0, REASON_RULE, PLAYER_NONE, sumplayer, LOCATION_GRAVE, 0, 0);
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, 0);
return TRUE;
}
......@@ -2902,7 +2902,7 @@ int32 field::special_summon_rule(uint16 step, uint8 sumplayer, card* target, uin
core.units.begin()->ptr1 = 0;
}
if(target->current.location == LOCATION_MZONE)
send_to(target, 0, REASON_RULE, sumplayer, sumplayer, LOCATION_GRAVE, 0, 0);
send_to(target, 0, REASON_RULE, PLAYER_NONE, sumplayer, LOCATION_GRAVE, 0, 0);
adjust_instant();
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, 0);
return TRUE;
......@@ -2981,7 +2981,7 @@ int32 field::special_summon_rule(uint16 step, uint8 sumplayer, card* target, uin
|| check_unique_onfield(pcard, sumplayer, LOCATION_MZONE)
|| pcard->is_affected_by_effect(EFFECT_CANNOT_SPECIAL_SUMMON)) {
cit = pgroup->container.erase(cit);
continue;
continue;
}
effect_set eset;
pcard->filter_effect(EFFECT_SPSUMMON_COST, &eset);
......@@ -3091,7 +3091,7 @@ int32 field::special_summon_rule(uint16 step, uint8 sumplayer, card* target, uin
++cit;
}
if(cset.size()) {
send_to(&cset, 0, REASON_RULE, sumplayer, sumplayer, LOCATION_GRAVE, 0, 0);
send_to(&cset, 0, REASON_RULE, PLAYER_NONE, sumplayer, LOCATION_GRAVE, 0, 0);
adjust_instant();
}
if(pgroup->container.size() == 0) {
......@@ -3931,16 +3931,9 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
pcard->previous.defense = atk_def.second;
}
} else {
effect_set eset;
pcard->filter_effect(EFFECT_ADD_CODE, &eset);
if(pcard->data.alias && !eset.size())
pcard->previous.code = pcard->data.alias;
else
pcard->previous.code = pcard->data.code;
if(eset.size())
pcard->previous.code2 = eset.get_last()->get_value(pcard);
else
pcard->previous.code2 = 0;
auto codes = pcard->get_original_code_rule();
pcard->previous.code = std::get<0>(codes);
pcard->previous.code2 = std::get<1>(codes);
pcard->previous.type = pcard->data.type;
pcard->previous.level = pcard->data.level;
pcard->previous.rank = pcard->data.level;
......
......@@ -11,6 +11,10 @@
#include "common.h"
#include "interpreter.h"
constexpr bool match_all(uint32 x, uint32 y) {
return (x & y) == y;
}
class scriptlib {
public:
static int32 check_param(lua_State* L, int32 param_type, int32 index, int32 retfalse = FALSE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment