Commit 323b138d authored by mercury233's avatar mercury233
parents cfe8df33 13b28cd3
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
#include "ocgapi.h" #include "ocgapi.h"
#include <algorithm> #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 { bool card_sort::operator()(void* const & p1, void* const & p2) const {
card* c1 = (card*)p1; card* c1 = (card*)p1;
card* c2 = (card*)p2; card* c2 = (card*)p2;
...@@ -411,55 +419,60 @@ uint32 card::get_info_location() { ...@@ -411,55 +419,60 @@ uint32 card::get_info_location() {
return c + (l << 8) + (s << 16) + (ss << 24); return c + (l << 8) + (s << 16) + (ss << 24);
} }
} }
// mapping of double-name cards // get the printed code on card
uint32 card::second_code(uint32 code){ uint32 card::get_original_code() const {
switch(code){ if (data.alias && (data.alias < data.code + CARD_ARTWORK_VERSIONS_OFFSET) && (data.code < data.alias + CARD_ARTWORK_VERSIONS_OFFSET))
case CARD_MARINE_DOLPHIN: return data.alias;
return 17955766u; else
case CARD_TWINKLE_MOSS: return data.code;
return 17732278u; }
default: // get the original code in duel (can be different from printed code)
return 0; 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 // 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() { uint32 card::get_code() {
if(assume_type == ASSUME_CODE) if(assume_type == ASSUME_CODE)
return assume_value; return assume_value;
if (temp.code != 0xffffffff) if (temp.code != 0xffffffff)
return temp.code; return temp.code;
effect_set effects; effect_set effects;
uint32 code = data.code; uint32 code = std::get<0>(get_original_code_rule());
temp.code = data.code; temp.code = code;
filter_effect(EFFECT_CHANGE_CODE, &effects); filter_effect(EFFECT_CHANGE_CODE, &effects);
if (effects.size()) if (effects.size())
code = effects.get_last()->get_value(this); code = effects.get_last()->get_value(this);
temp.code = 0xffffffff; 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 code;
} }
// return: the current second card name // return: the current second card name
// for double-name cards, it returns the name in description // for double-name cards, it returns the name in description
uint32 card::get_another_code() { uint32 card::get_another_code() {
uint32 code = get_code(); uint32 code1 = get_code();
if(code != data.code){ if (is_affected_by_effect(EFFECT_CHANGE_CODE)) {
return second_code(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; effect_set eset;
filter_effect(EFFECT_ADD_CODE, &eset); filter_effect(EFFECT_ADD_CODE, &eset);
if(!eset.size()) if(!eset.size())
return 0; return code2;
uint32 otcode = eset.get_last()->get_value(this); uint32 otcode = eset.get_last()->get_value(this);
if(code != otcode) if(code1 != otcode)
return otcode; return otcode;
return 0; return 0;
} }
...@@ -2578,6 +2591,7 @@ void card::set_special_summon_status(effect* peffect) { ...@@ -2578,6 +2591,7 @@ void card::set_special_summon_status(effect* peffect) {
spsummon.defense = 0; spsummon.defense = 0;
spsummon.setcode.clear(); spsummon.setcode.clear();
spsummon.reason_effect = nullptr; spsummon.reason_effect = nullptr;
spsummon.reason_player = PLAYER_NONE;
return; return;
} }
card* pcard = peffect->get_handler(); card* pcard = peffect->get_handler();
...@@ -2600,6 +2614,7 @@ void card::set_special_summon_status(effect* peffect) { ...@@ -2600,6 +2614,7 @@ void card::set_special_summon_status(effect* peffect) {
spsummon.setcode.push_back((uint32)eset[i]->get_value(pcard)); spsummon.setcode.push_back((uint32)eset[i]->get_value(pcard));
} }
spsummon.reason_effect = peffect; spsummon.reason_effect = peffect;
spsummon.reason_player = peffect->get_handler_player();
} else { } else {
pcard = cait->triggering_effect->get_handler(); pcard = cait->triggering_effect->get_handler();
spsummon.code = cait->triggering_state.code; spsummon.code = cait->triggering_state.code;
...@@ -2618,6 +2633,7 @@ void card::set_special_summon_status(effect* peffect) { ...@@ -2618,6 +2633,7 @@ void card::set_special_summon_status(effect* peffect) {
spsummon.setcode.push_back((uint32)eset[i]->get_value(pcard)); spsummon.setcode.push_back((uint32)eset[i]->get_value(pcard));
} }
spsummon.reason_effect = cait->triggering_effect; spsummon.reason_effect = cait->triggering_effect;
spsummon.reason_player = cait->triggering_player;
} }
} }
void card::filter_effect(int32 code, effect_set* eset, uint8 sort) { void card::filter_effect(int32 code, effect_set* eset, uint8 sort) {
......
...@@ -99,6 +99,12 @@ struct material_info { ...@@ -99,6 +99,12 @@ struct material_info {
}; };
const material_info null_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 { class card {
public: public:
struct effect_relation_hash { struct effect_relation_hash {
...@@ -137,6 +143,8 @@ public: ...@@ -137,6 +143,8 @@ public:
uint8 location{ 0 }; uint8 location{ 0 };
uint8 sequence{ 0 }; uint8 sequence{ 0 };
}; };
static const std::unordered_map<uint32, uint32> second_code;
int32 ref_handle; int32 ref_handle;
duel* pduel; duel* pduel;
card_data data; card_data data;
...@@ -206,7 +214,8 @@ public: ...@@ -206,7 +214,8 @@ public:
int32 get_infos(byte* buf, uint32 query_flag, int32 use_cache = TRUE); int32 get_infos(byte* buf, uint32 query_flag, int32 use_cache = TRUE);
uint32 get_info_location(); 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_code();
uint32 get_another_code(); uint32 get_another_code();
int32 is_set_card(uint32 set_code); int32 is_set_card(uint32 set_code);
...@@ -417,10 +426,7 @@ public: ...@@ -417,10 +426,7 @@ public:
#define SUMMON_INFO_ATTACK 0x80 #define SUMMON_INFO_ATTACK 0x80
#define SUMMON_INFO_DEFENSE 0x100 #define SUMMON_INFO_DEFENSE 0x100
#define SUMMON_INFO_REASON_EFFECT 0x200 #define SUMMON_INFO_REASON_EFFECT 0x200
#define SUMMON_INFO_REASON_PLAYER 0x400
//double-name cards
#define CARD_MARINE_DOLPHIN 78734254
#define CARD_TWINKLE_MOSS 13857930
#define CARD_ARTWORK_VERSIONS_OFFSET 10 #define CARD_ARTWORK_VERSIONS_OFFSET 10
......
...@@ -24,40 +24,29 @@ int32 scriptlib::card_get_code(lua_State *L) { ...@@ -24,40 +24,29 @@ int32 scriptlib::card_get_code(lua_State *L) {
} }
return 1; return 1;
} }
// GetOriginalCode(): get the original code printed on card
// return: 1 int
int32 scriptlib::card_get_origin_code(lua_State *L) { int32 scriptlib::card_get_origin_code(lua_State *L) {
check_param_count(L, 1); check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1); check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
if(pcard->data.alias) { lua_pushinteger(L, pcard->get_original_code());
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);
return 1; 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) { int32 scriptlib::card_get_origin_code_rule(lua_State *L) {
check_param_count(L, 1); check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1); check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
effect_set eset; auto codes = pcard->get_original_code_rule();
pcard->filter_effect(EFFECT_ADD_CODE, &eset); uint32 code1 = std::get<0>(codes);
if(pcard->data.alias && !eset.size()) uint32 code2 = std::get<1>(codes);
lua_pushinteger(L, pcard->data.alias); if (code2) {
else { lua_pushinteger(L, code1);
lua_pushinteger(L, pcard->data.code); lua_pushinteger(L, code2);
if(eset.size()) {
uint32 otcode = eset.get_last()->get_value(pcard);
lua_pushinteger(L, otcode);
return 2; return 2;
} }
} else {
lua_pushinteger(L, code1);
return 1; return 1;
}
} }
int32 scriptlib::card_get_fusion_code(lua_State *L) { int32 scriptlib::card_get_fusion_code(lua_State *L) {
check_param_count(L, 1); check_param_count(L, 1);
...@@ -921,6 +910,9 @@ int32 scriptlib::card_get_special_summon_info(lua_State *L) { ...@@ -921,6 +910,9 @@ int32 scriptlib::card_get_special_summon_info(lua_State *L) {
case SUMMON_INFO_REASON_EFFECT: case SUMMON_INFO_REASON_EFFECT:
interpreter::effect2value(L, pcard->spsummon.reason_effect); interpreter::effect2value(L, pcard->spsummon.reason_effect);
break; break;
case SUMMON_INFO_REASON_PLAYER:
lua_pushinteger(L, pcard->spsummon.reason_player);
break;
default: default:
lua_pushnil(L); lua_pushnil(L);
break; break;
...@@ -967,19 +959,9 @@ int32 scriptlib::card_is_origin_code_rule(lua_State *L) { ...@@ -967,19 +959,9 @@ int32 scriptlib::card_is_origin_code_rule(lua_State *L) {
check_param_count(L, 2); check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1); check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
uint32 code1 = 0; auto codes = pcard->get_original_code_rule();
uint32 code2 = 0; uint32 code1 = std::get<0>(codes);
effect_set eset; uint32 code2 = std::get<1>(codes);
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);
}
uint32 count = lua_gettop(L) - 1; uint32 count = lua_gettop(L) - 1;
uint32 result = FALSE; uint32 result = FALSE;
for(uint32 i = 0; i < count; ++i) { for(uint32 i = 0; i < count; ++i) {
......
...@@ -3931,16 +3931,9 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 ...@@ -3931,16 +3931,9 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
pcard->previous.defense = atk_def.second; pcard->previous.defense = atk_def.second;
} }
} else { } else {
effect_set eset; auto codes = pcard->get_original_code_rule();
pcard->filter_effect(EFFECT_ADD_CODE, &eset); pcard->previous.code = std::get<0>(codes);
if(pcard->data.alias && !eset.size()) pcard->previous.code2 = std::get<1>(codes);
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;
pcard->previous.type = pcard->data.type; pcard->previous.type = pcard->data.type;
pcard->previous.level = pcard->data.level; pcard->previous.level = pcard->data.level;
pcard->previous.rank = pcard->data.level; pcard->previous.rank = pcard->data.level;
......
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