core: ygol_query_prompt_context names the effect that asks a prompt (TICKET-451, v1.7.0)
field::execute_cost / execute_target / execute_operation push the running effect (handler, description, stable index, phase 1 / 2 / 3, chain link) on core.ygol_running at step 0 and pop it when the function finishes; the innermost entry is the effect that asks. effect::ygol_script_index is stamped in card::add_effect while the card loads (initial_effect.size()), 0xffff otherwise. The export writes 22 bytes; a handler the asking player does not control and that is not face-up answers code 0, index 0xffff, description 0. Export gates 335 / 856 / 850 -> 336 / 857 / 851. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4cd908d7af
commit
b6ef8a31bc
10 files changed
+109
-10
No files matched your search
+7
-3
@@ -1958,10 +1958,14 @@ int32_t card::add_effect(effect* peffect) {
|
||||
return 0;
|
||||
peffect->id = pduel->game_field->infos.field_id++;
|
||||
peffect->card_type = data.type;
|
||||
if (get_status(STATUS_INITIALIZING))
|
||||
if (get_status(STATUS_INITIALIZING)) {
|
||||
peffect->flag[0] |= EFFECT_FLAG_INITIAL;
|
||||
else if (get_status(STATUS_COPYING_EFFECT))
|
||||
peffect->flag[0] |= EFFECT_FLAG_COPY;
|
||||
peffect->ygol_script_index = (uint16_t)initial_effect.size(); // [YGOL] v1.7.0 prompt context: the script's registration order
|
||||
} else {
|
||||
peffect->ygol_script_index = 0xffff;
|
||||
if (get_status(STATUS_COPYING_EFFECT))
|
||||
peffect->flag[0] |= EFFECT_FLAG_COPY;
|
||||
}
|
||||
if (get_status(STATUS_COPYING_EFFECT)) {
|
||||
peffect->copy_id = pduel->game_field->infos.copy_id;
|
||||
peffect->reset_flag |= pduel->game_field->core.copy_reset;
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
int32_t operation{ 0 };
|
||||
uint8_t cost_checked{ FALSE };
|
||||
uint8_t is_granted{ 0 };
|
||||
uint16_t ygol_script_index{ 0xffff }; // [YGOL] v1.7.0 prompt context: registration order in the card's initial_effect, 0xffff = not from it
|
||||
|
||||
effect_set required_handorset_effects;
|
||||
LuaParamType object_type{ PARAM_TYPE_INT };
|
||||
|
||||
@@ -342,6 +342,15 @@ struct processor {
|
||||
uint8_t selfdes_disabled{ FALSE };
|
||||
uint8_t overdraw[2]{};
|
||||
int32_t check_level{ 0 };
|
||||
// [YGOL] v1.7.0 prompt context: the effect functions running now (cost / target / operation), innermost last
|
||||
struct ygol_running_effect {
|
||||
card* handler{ nullptr };
|
||||
uint32_t description{ 0 };
|
||||
uint16_t script_index{ 0xffff };
|
||||
uint8_t phase{ 0 };
|
||||
uint8_t chain_link{ 0 };
|
||||
};
|
||||
std::vector<ygol_running_effect> ygol_running;
|
||||
uint8_t shuffle_check_disabled{ FALSE };
|
||||
uint8_t shuffle_hand_check[2]{};
|
||||
uint8_t shuffle_deck_check[2]{};
|
||||
|
||||
@@ -482,6 +482,45 @@ OCGCORE_API int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8
|
||||
buffer_write<uint32_t>(ptr, code);
|
||||
return (int32_t)(ptr - out);
|
||||
}
|
||||
// [YGOL] v1.7.0 (prompt context) -- see ocgapi.h. Reads field::core.ygol_running, the cost / target / operation
|
||||
// functions running now (processor.cpp); the innermost one is the effect that asks.
|
||||
OCGCORE_API int32_t ygol_query_prompt_context(intptr_t pduel, uint8_t playerid, uint8_t* out) {
|
||||
duel* pd = (duel*)pduel;
|
||||
if(!pd || !out || !duel_set.count(pd) || !pd->game_field || !check_playerid(playerid))
|
||||
return 0;
|
||||
const auto& running = pd->game_field->core.ygol_running;
|
||||
card* handler = running.empty() ? nullptr : running.back().handler;
|
||||
if(handler && !pd->cards.count(handler))
|
||||
handler = nullptr;
|
||||
byte* ptr = out;
|
||||
buffer_write<uint8_t>(ptr, 1);
|
||||
if(!handler) {
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
buffer_write<uint32_t>(ptr, 0);
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
buffer_write<uint64_t>(ptr, 0);
|
||||
buffer_write<uint16_t>(ptr, 0xffff);
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
return (int32_t)(ptr - out);
|
||||
}
|
||||
const auto& top = running.back();
|
||||
const bool visible = handler->current.controler == playerid || handler->is_position(POS_FACEUP);
|
||||
buffer_write<uint8_t>(ptr, 1);
|
||||
buffer_write<uint32_t>(ptr, visible ? handler->get_code() : 0);
|
||||
buffer_write<uint8_t>(ptr, handler->current.controler);
|
||||
buffer_write<uint8_t>(ptr, handler->current.location);
|
||||
buffer_write<uint8_t>(ptr, handler->current.sequence);
|
||||
buffer_write<uint8_t>(ptr, handler->current.position);
|
||||
buffer_write<uint64_t>(ptr, visible ? top.description : 0);
|
||||
buffer_write<uint16_t>(ptr, visible ? top.script_index : 0xffff);
|
||||
buffer_write<uint8_t>(ptr, top.phase);
|
||||
buffer_write<uint8_t>(ptr, top.chain_link);
|
||||
return (int32_t)(ptr - out);
|
||||
}
|
||||
OCGCORE_API int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf) {
|
||||
if (!pduel || !key || !out_buf) return -1;
|
||||
|
||||
|
||||
@@ -87,6 +87,15 @@ OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_
|
||||
// tag duel); a refusal writes nothing. The duel is byte-identical afterwards (proposal 33 Rule 11).
|
||||
OCGCORE_API int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out);
|
||||
|
||||
// [YGOL] v1.7.0 (prompt context, TICKET-451): which effect asks the prompt the engine is parked on, read only.
|
||||
// playerid = the answering player. out (22 bytes): version (1), has_effect, uint32 code (the handler's current
|
||||
// code), controller, location, sequence, position, uint64 description, uint16 effect_index (the order the
|
||||
// card's script registered the effect in initial_effect; 0xffff unknown), phase (1 cost, 2 target, 3 operation),
|
||||
// chain link (0 none). has_effect 0 = no effect function runs: every other byte 0, effect_index 0xffff. A
|
||||
// handler playerid does not control and that is not face-up writes code 0, effect_index 0xffff, description 0.
|
||||
// Returns 22, 0 refused (bad pointer, bad player); a refusal writes nothing.
|
||||
OCGCORE_API int32_t ygol_query_prompt_context(intptr_t pduel, uint8_t playerid, 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);
|
||||
|
||||
@@ -727,6 +727,28 @@ uint32_t field::process() {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
// [YGOL] v1.7.0 prompt context: remember which effect function runs, so ygol_query_prompt_context can name it at a prompt
|
||||
static void ygol_push_running(field* pfield, effect* peffect, uint8_t phase) {
|
||||
processor::ygol_running_effect running;
|
||||
running.handler = peffect->get_handler();
|
||||
if(!running.handler)
|
||||
running.handler = peffect->owner;
|
||||
running.description = peffect->description;
|
||||
running.script_index = peffect->ygol_script_index;
|
||||
running.phase = phase;
|
||||
auto& chain = pfield->core.current_chain;
|
||||
for(auto it = chain.rbegin(); it != chain.rend(); ++it) {
|
||||
if(it->triggering_effect == peffect) {
|
||||
running.chain_link = it->chain_count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pfield->core.ygol_running.push_back(running);
|
||||
}
|
||||
static void ygol_pop_running(field* pfield) {
|
||||
if(!pfield->core.ygol_running.empty())
|
||||
pfield->core.ygol_running.pop_back();
|
||||
}
|
||||
int32_t field::execute_cost(uint16_t step, effect * triggering_effect, uint8_t triggering_player) {
|
||||
if(!triggering_effect->cost) {
|
||||
core.solving_event.splice(core.solving_event.begin(), core.sub_solving_event);
|
||||
@@ -754,6 +776,7 @@ int32_t field::execute_cost(uint16_t step, effect * triggering_effect, uint8_t t
|
||||
core.units.begin()->arg2 = core.shuffle_check_disabled;
|
||||
core.shuffle_check_disabled = FALSE;
|
||||
++core.check_level;
|
||||
ygol_push_running(this, triggering_effect, 1);
|
||||
}
|
||||
core.reason_effect = triggering_effect;
|
||||
core.reason_player = triggering_player;
|
||||
@@ -765,6 +788,7 @@ int32_t field::execute_cost(uint16_t step, effect * triggering_effect, uint8_t t
|
||||
core.reason_effect = 0;
|
||||
core.reason_player = PLAYER_NONE;
|
||||
--core.check_level;
|
||||
ygol_pop_running(this);
|
||||
if(core.check_level == 0) {
|
||||
if(core.shuffle_hand_check[0])
|
||||
shuffle(0, LOCATION_HAND);
|
||||
@@ -806,6 +830,7 @@ int32_t field::execute_operation(uint16_t step, effect * triggering_effect, uint
|
||||
core.units.begin()->arg2 = core.shuffle_check_disabled;
|
||||
core.shuffle_check_disabled = FALSE;
|
||||
++core.check_level;
|
||||
ygol_push_running(this, triggering_effect, 3);
|
||||
}
|
||||
core.reason_effect = triggering_effect;
|
||||
core.reason_player = triggering_player;
|
||||
@@ -817,6 +842,7 @@ int32_t field::execute_operation(uint16_t step, effect * triggering_effect, uint
|
||||
core.reason_effect = 0;
|
||||
core.reason_player = PLAYER_NONE;
|
||||
--core.check_level;
|
||||
ygol_pop_running(this);
|
||||
if(core.check_level == 0) {
|
||||
if(core.shuffle_hand_check[0])
|
||||
shuffle(0, LOCATION_HAND);
|
||||
@@ -863,6 +889,7 @@ int32_t field::execute_target(uint16_t step, effect * triggering_effect, uint8_t
|
||||
core.units.begin()->arg2 = core.shuffle_check_disabled;
|
||||
core.shuffle_check_disabled = FALSE;
|
||||
++core.check_level;
|
||||
ygol_push_running(this, triggering_effect, 2);
|
||||
}
|
||||
core.reason_effect = triggering_effect;
|
||||
core.reason_player = triggering_player;
|
||||
@@ -874,6 +901,7 @@ int32_t field::execute_target(uint16_t step, effect * triggering_effect, uint8_t
|
||||
core.reason_effect = 0;
|
||||
core.reason_player = PLAYER_NONE;
|
||||
--core.check_level;
|
||||
ygol_pop_running(this);
|
||||
if(core.check_level == 0) {
|
||||
if(core.shuffle_hand_check[0])
|
||||
shuffle(0, LOCATION_HAND);
|
||||
|
||||
Reference in new issue
Block a user