Skip to content

Commit

Permalink
add cost to EFFECT_TRAP_ACT_IN_HAND
Browse files Browse the repository at this point in the history
  • Loading branch information
purerosefallen committed Apr 7, 2024
1 parent 3f3ec1c commit 7c34692
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 63 deletions.
81 changes: 52 additions & 29 deletions effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,55 @@ 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);
if(pduel->lua->check_condition(peffect->cost, 9)) {
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 +279,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
4 changes: 3 additions & 1 deletion 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
1 change: 1 addition & 0 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct chain {
tevent evt;
opmap opinfos;
uint32 flag{ 0 };
effect_set required_handorset_effects;

static bool chain_operation_sort(const chain& c1, const chain& c2);
void set_triggering_state(card* pcard);
Expand Down
70 changes: 37 additions & 33 deletions processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3996,37 +3996,8 @@ int32 field::add_chain(uint16 step) {
}
}
if(peffect->type & EFFECT_TYPE_ACTIVATE) {
int32 ecode = 0;
if(phandler->current.location == LOCATION_HAND) {
if(phandler->data.type & TYPE_TRAP)
ecode = EFFECT_TRAP_ACT_IN_HAND;
else if((phandler->data.type & TYPE_SPELL) && (phandler->data.type & TYPE_QUICKPLAY)
&& infos.turn_player != phandler->current.controler)
ecode = EFFECT_QP_ACT_IN_NTPHAND;
} else if(phandler->current.location == LOCATION_SZONE) {
if((phandler->data.type & TYPE_TRAP) && phandler->get_status(STATUS_SET_TURN))
ecode = EFFECT_TRAP_ACT_IN_SET_TURN;
if((phandler->data.type & TYPE_SPELL) && (phandler->data.type & TYPE_QUICKPLAY) && phandler->get_status(STATUS_SET_TURN))
ecode = EFFECT_QP_ACT_IN_SET_TURN;
}
if(ecode) {
eset.clear();
phandler->filter_effect(ecode, &eset);
effect* pactin = nullptr;
for(int32 i = 0; i < eset.size(); ++i) {
if(!eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT)) {
pactin = eset[i];
break;
}
}
if(!pactin) {
for(int32 i = 0; i < eset.size(); ++i) {
if(eset[i]->check_count_limit(phandler->current.controler)) {
eset[i]->dec_count(phandler->current.controler);
break;
}
}
}
if(peffect->get_required_handorset_effects(&clit.required_handorset_effects, clit.triggering_player, clit.evt) != 2) {
clit.required_handorset_effects.clear();
}
if(phandler->current.location == LOCATION_HAND) {
uint32 zone = 0xff;
Expand Down Expand Up @@ -4171,6 +4142,39 @@ int32 field::add_chain(uint16 step) {
return FALSE;
}
case 5: {
auto& clit = core.current_chain.back();
if (!clit.required_handorset_effects.size()) {
core.units.begin()->step = 6;
return FALSE;
}
if(clit.required_handorset_effects.size() == 1) {
returns.ivalue[0] = 0;
return FALSE;
}
core.select_options.clear();
for(int32 i = 0; i < clit.required_handorset_effects.size(); ++i) {
core.select_options.push_back(clit.required_handorset_effects[i]->description);
}
add_process(PROCESSOR_SELECT_OPTION, 0, 0, 0, clit.triggering_player, 0);
return FALSE;
}
case 6: {
auto& clit = core.current_chain.back();
auto ceffect = clit.required_handorset_effects[returns.ivalue[0]];
ceffect->dec_count(clit.triggering_player);
if(ceffect->description) {
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_OPSELECTED);
pduel->write_buffer8(clit.triggering_player);
pduel->write_buffer32(ceffect->description);
}
if(ceffect->cost) {
core.sub_solving_event.push_back(clit.evt);
add_process(PROCESSOR_EXECUTE_COST, 0, ceffect, 0, clit.triggering_player, 0);
}
return FALSE;
}
case 7: {
auto& clit = core.current_chain.back();
effect* peffect = clit.triggering_effect;
peffect->cost_checked = TRUE;
Expand All @@ -4180,7 +4184,7 @@ int32 field::add_chain(uint16 step) {
}
return FALSE;
}
case 6: {
case 8: {
auto& clit = core.current_chain.back();
effect* peffect = clit.triggering_effect;
if(peffect->target) {
Expand All @@ -4189,7 +4193,7 @@ int32 field::add_chain(uint16 step) {
}
return FALSE;
}
case 7: {
case 9: {
break_effect();
core.is_target_ready = true;
auto& clit = core.current_chain.back();
Expand Down

0 comments on commit 7c34692

Please sign in to comment.