Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluorohydride committed Mar 31, 2012
1 parent 98e32f9 commit 7f3a151
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 48 deletions.
8 changes: 4 additions & 4 deletions gframe/duelclient.cpp
Expand Up @@ -1691,10 +1691,8 @@ int DuelClient::ClientAnalyze(char* msg, unsigned int len) {
ClientCard* pcard = mainGame->dField.GetCard(pc, pl, ps);
if (code != 0 && pcard->code != code)
pcard->SetCode(code);
if((pl & LOCATION_ONFIELD) && (cl != pl))
pcard->counters.clear();
if(cl != pl)
pcard->ClearTarget();
pcard->counters.clear();
pcard->ClearTarget();
ClientCard* olcard = mainGame->dField.GetCard(cc, cl & 0x7f, cs);
mainGame->gMutex.Lock();
mainGame->dField.RemoveCard(pc, pl, ps);
Expand Down Expand Up @@ -2446,6 +2444,8 @@ int DuelClient::ClientAnalyze(char* msg, unsigned int len) {
int chtype = BufferIO::ReadInt8(pbuf);
int value = BufferIO::ReadInt32(pbuf);
ClientCard* pcard = mainGame->dField.GetCard(c, l, s);
if(!pcard)
return true;
pcard->cHint = chtype;
pcard->chValue = value;
if(chtype == CHINT_TURN) {
Expand Down
2 changes: 1 addition & 1 deletion gframe/single_duel.cpp
Expand Up @@ -546,7 +546,7 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
unsigned char engType = BufferIO::ReadUInt8(pbuf);
switch (engType) {
case MSG_RETRY: {
WaitforResponse(player);
WaitforResponse(last_response);
NetServer::SendBufferToPlayer(players[last_response], STOC_GAME_MSG, offset, pbuf - offset);
return 1;
}
Expand Down
11 changes: 4 additions & 7 deletions ocgcore/card.cpp
Expand Up @@ -588,18 +588,16 @@ void card::xyz_overlay(card_set* materials) {
return;
card_set des;
if(materials->size() == 1) {
(*materials->begin())->reset(RESET_LEAVE + RESET_OVERLAY, RESET_EVENT);
xyz_add(*materials->begin(), &des);
(*materials->begin())->reset(RESET_EVENT, RESET_OVERLAY);
} else {
field::card_vector cv;
field::card_vector::iterator cvit;
card_set::iterator cit;
for(cit = materials->begin(); cit != materials->end(); ++cit)
for(auto cit = materials->begin(); cit != materials->end(); ++cit)
cv.push_back(*cit);
std::sort(cv.begin(), cv.end(), card::card_operation_sort);
for(cvit = cv.begin(); cvit != cv.end(); ++cvit) {
for(auto cvit = cv.begin(); cvit != cv.end(); ++cvit) {
(*cvit)->reset(RESET_LEAVE + RESET_OVERLAY, RESET_EVENT);
xyz_add(*cvit, &des);
(*cvit)->reset(RESET_EVENT, RESET_OVERLAY);
}
}
if(des.size())
Expand All @@ -611,7 +609,6 @@ void card::xyz_add(card* mat, card_set* des) {
pduel->write_buffer8(MSG_MOVE);
pduel->write_buffer32(mat->data.code);
mat->enable_field_effect(false);
mat->reset(RESET_LEAVE, RESET_EVENT);
if(mat->overlay_target) {
pduel->write_buffer8(mat->overlay_target->current.controler);
pduel->write_buffer8(mat->overlay_target->current.location | LOCATION_OVERLAY);
Expand Down
1 change: 1 addition & 0 deletions ocgcore/field.cpp
Expand Up @@ -71,6 +71,7 @@ field::field(duel* pduel) {
core.attacker = 0;
core.attack_target = 0;
core.deck_reversed = FALSE;
core.effect_damage_step = FALSE;
nil_event.event_code = 0;
nil_event.event_cards = 0;
nil_event.event_player = PLAYER_NONE;
Expand Down
5 changes: 3 additions & 2 deletions ocgcore/field.h
Expand Up @@ -219,6 +219,7 @@ struct processor {
card* sub_attack_target;
card* limit_tuner;
uint8 attack_cancelable;
uint8 effect_damage_step;
int32 battle_damage[2];
int32 summon_count[2];
uint8 extra_summon[2];
Expand Down Expand Up @@ -370,7 +371,7 @@ class field {
int32 process_single_event();
int32 process_idle_command(uint16 step);
int32 process_battle_command(uint16 step);
int32 process_damage_phase(uint16 step);
int32 process_damage_step(uint16 step);
int32 process_turn(uint16 step, uint8 turn_player);

int32 add_chain(uint16 step);
Expand Down Expand Up @@ -540,7 +541,7 @@ class field {
#define PROCESSOR_IDLE_COMMAND 32
#define PROCESSOR_PHASE_EVENT 33
#define PROCESSOR_BATTLE_COMMAND 34
#define PROCESSOR_DAMAGE_PHASE 35
#define PROCESSOR_DAMAGE_STEP 35
#define PROCESSOR_ADD_CHAIN 40
#define PROCESSOR_SOLVE_CHAIN 42
#define PROCESSOR_SOLVE_CONTINUOUS 43
Expand Down
1 change: 1 addition & 0 deletions ocgcore/interpreter.cpp
Expand Up @@ -331,6 +331,7 @@ static const struct luaL_Reg duellib[] = {
{ "ReplaceAttacker", scriptlib::duel_replace_attacker },
{ "ChangeAttackTarget", scriptlib::duel_change_attack_target },
{ "ReplaceAttackTarget", scriptlib::duel_replace_attack_target },
{ "CalculateDamage", scriptlib::duel_calculate_damage },
{ "GetBattleDamage", scriptlib::duel_get_battle_damage },
{ "ChangeBattleDamage", scriptlib::duel_change_battle_damage },
{ "ChangeTargetCard", scriptlib::duel_change_target },
Expand Down
4 changes: 3 additions & 1 deletion ocgcore/libcard.cpp
Expand Up @@ -1191,7 +1191,9 @@ int32 scriptlib::card_is_chain_attackable(lua_State *L) {
if(lua_gettop(L) > 1)
ac = lua_tointeger(L, 2);
card* attacker = pduel->game_field->core.attacker;
if(attacker->is_status(STATUS_BATTLE_DESTROYED) || attacker->fieldid != pduel->game_field->core.pre_field[0]
if(pduel->game_field->core.effect_damage_step
|| attacker->is_status(STATUS_BATTLE_DESTROYED)
|| attacker->fieldid != pduel->game_field->core.pre_field[0]
|| !attacker->is_capable_attack_announce(pduel->game_field->infos.turn_player)
|| attacker->announce_count >= ac) {
lua_pushboolean(L, 0);
Expand Down
12 changes: 12 additions & 0 deletions ocgcore/libduel.cpp
Expand Up @@ -1015,6 +1015,18 @@ int32 scriptlib::duel_change_attack_target(lua_State *L) {
int32 scriptlib::duel_replace_attack_target(lua_State *L) {
return 0;
}
int32 scriptlib::duel_calculate_damage(lua_State *L) {
check_action_permission(L);
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
check_param(L, PARAM_TYPE_CARD, 2);
card* attacker = *(card**)lua_touserdata(L, 1);
card* attack_target = *(card**)lua_touserdata(L, 2);
if(attacker == attack_target)
return 0;
attacker->pduel->game_field->add_process(PROCESSOR_DAMAGE_STEP, 0, (effect*)attacker, (group*)attack_target, 0, 0);
return lua_yield(L, 0);
}
int32 scriptlib::duel_get_battle_damage(lua_State *L) {
check_param_count(L, 1);
duel* pduel = interpreter::get_duel_info(L);
Expand Down
116 changes: 94 additions & 22 deletions ocgcore/processor.cpp
Expand Up @@ -231,8 +231,8 @@ int32 field::process() {
core.units.begin()->step++;
return pduel->bufferlen;
}
case PROCESSOR_DAMAGE_PHASE: {
if(process_damage_phase(it->step))
case PROCESSOR_DAMAGE_STEP: {
if(process_damage_step(it->step))
core.units.pop_front();
else
core.units.begin()->step++;
Expand Down Expand Up @@ -3126,17 +3126,23 @@ int32 field::process_battle_command(uint16 step) {
}
process_single_event();
process_instant_event();
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_EVENT);
pduel->write_buffer8(0);
pduel->write_buffer32(43);
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_EVENT);
pduel->write_buffer8(1);
pduel->write_buffer32(43);
core.hint_timing[infos.turn_player] = TIMING_DAMAGE_CAL;
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, 0, 0);
if(!core.effect_damage_step) {
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_EVENT);
pduel->write_buffer8(0);
pduel->write_buffer32(43);
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_EVENT);
pduel->write_buffer8(1);
pduel->write_buffer32(43);
core.hint_timing[infos.turn_player] = TIMING_DAMAGE_CAL;
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, 0, 0);
} else {
break_effect();
}
core.damage_calculated = TRUE;
if(core.effect_damage_step && core.current_chain.size() <= 1)
return TRUE;
return FALSE;
}
case 27: {
Expand Down Expand Up @@ -3239,8 +3245,7 @@ int32 field::process_battle_command(uint16 step) {
group* des = core.units.begin()->ptarget;
if(!des || !des->container.size())
return FALSE;
card_set::iterator cit;
for(cit = des->container.begin(); cit != des->container.end(); ++cit) {
for(auto cit = des->container.begin(); cit != des->container.end(); ++cit) {
(*cit)->set_status(STATUS_BATTLE_DESTROYED, TRUE);
(*cit)->filter_disable_related_cards();
}
Expand All @@ -3254,8 +3259,12 @@ int32 field::process_battle_command(uint16 step) {
raise_event((card*)0, EVENT_BATTLE_END, 0, 0, PLAYER_NONE, 0, 0);
process_single_event();
process_instant_event();
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, TRUE);
core.units.begin()->arg1 = 1;
if(!core.effect_damage_step || core.current_chain.size() <= 1) {
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, TRUE);
core.units.begin()->arg1 = 1;
} else {
break_effect();
}
return FALSE;
}
case 31: {
Expand All @@ -3271,8 +3280,12 @@ int32 field::process_battle_command(uint16 step) {
process_single_event();
process_instant_event();
}
if(core.flip_chain.size() || core.new_fchain.size() || core.new_ochain.size())
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, FALSE);
if(!core.effect_damage_step || core.current_chain.size() <= 1) {
if(core.flip_chain.size() || core.new_fchain.size() || core.new_ochain.size())
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, FALSE);
} else {
break_effect();
}
return FALSE;
}
case 32: {
Expand Down Expand Up @@ -3321,8 +3334,12 @@ int32 field::process_battle_command(uint16 step) {
core.attacker->set_status(STATUS_BATTLE_DESTROYED, FALSE);
if(core.attack_target)
core.attack_target->set_status(STATUS_BATTLE_DESTROYED, FALSE);
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, FALSE);
core.units.begin()->step = 38;
if(!core.effect_damage_step || core.current_chain.size() <= 1) {
add_process(PROCESSOR_POINT_EVENT, 0, 0, 0, FALSE, FALSE);
core.units.begin()->step = 38;
} else {
break_effect();
}
return FALSE;
}
case 39: {
Expand All @@ -3331,6 +3348,8 @@ int32 field::process_battle_command(uint16 step) {
pduel->write_buffer8(MSG_DAMAGE_STEP_END);
reset_phase(PHASE_DAMAGE);
adjust_all();
if(core.effect_damage_step)
return TRUE;
if(core.chain_attack) {
if(core.attacker->is_status(STATUS_BATTLE_DESTROYED) || core.attacker->fieldid_r != core.pre_field[0]
|| !core.attacker->is_capable_attack_announce(infos.turn_player))
Expand Down Expand Up @@ -3365,7 +3384,60 @@ int32 field::process_battle_command(uint16 step) {
}
return TRUE;
}
int32 field::process_damage_phase(uint16 step) {
int32 field::process_damage_step(uint16 step) {
switch(step) {
case 0: {
core.effect_damage_step = 1;
card* tmp = core.attacker;
core.attacker = (card*)core.units.begin()->peffect;
core.units.begin()->peffect = (effect*)tmp;
tmp = core.attack_target;
core.attack_target = (card*)core.units.begin()->ptarget;
core.units.begin()->ptarget = (group*)tmp;
core.units.begin()->arg1 = infos.phase;
pduel->write_buffer8(MSG_ATTACK);
pduel->write_buffer32(core.attacker->get_info_location());
pduel->write_buffer32(core.attack_target->get_info_location());
infos.phase = PHASE_DAMAGE;
pduel->write_buffer8(MSG_DAMAGE_STEP_START);
core.pre_field[0] = core.attacker->fieldid_r;
if(core.attack_target)
core.pre_field[1] = core.attack_target->fieldid_r;
else
core.pre_field[1] = 0;
infos.phase = PHASE_DAMAGE_CAL;
raise_single_event(core.attacker, 0, EVENT_DAMAGE_CALCULATING, 0, 0, 0, 0, 0);
if(core.attack_target)
raise_single_event(core.attack_target, 0, EVENT_DAMAGE_CALCULATING, 0, 0, 0, 0, 1);
raise_event((card*)0, EVENT_DAMAGE_CALCULATING, 0, 0, 0, 0, 0);
process_single_event();
process_instant_event();
add_process(PROCESSOR_BATTLE_COMMAND, 26, 0, 0, 0, 0);
if(core.current_chain.size() > 1) {
core.units.begin()->step = 1;
return FALSE;
} else {
core.units.begin()->step = 1;
core.reserved = core.units.front();
return TRUE;
}
}
case 1: {
core.effect_damage_step = 2;
add_process(PROCESSOR_BATTLE_COMMAND, 27, 0, 0, 0, 0);
return FALSE;
}
case 2: {
core.attacker = (card*)core.units.begin()->peffect;
core.attack_target = (card*)core.units.begin()->ptarget;
core.attacker->set_status(STATUS_ATTACK_CANCELED, TRUE);
if(core.attack_target)
core.attack_target->set_status(STATUS_ATTACK_CANCELED, TRUE);
core.effect_damage_step = 0;
infos.phase = core.units.begin()->arg1;
return TRUE;
}
}
return TRUE;
}
int32 field::process_turn(uint16 step, uint8 turn_player) {
Expand Down Expand Up @@ -3975,7 +4047,7 @@ int32 field::solve_chain(uint16 step, uint32 skip_new) {
core.chain_limit_p = 0;
}
reset_chain();
if(core.summoning_card || core.spsummoning_card)
if(core.summoning_card || core.spsummoning_card || core.effect_damage_step == 1)
core.subunits.push_back(core.reserved);
return FALSE;
}
Expand Down
1 change: 1 addition & 0 deletions ocgcore/scriptlib.h
Expand Up @@ -327,6 +327,7 @@ class scriptlib {
static int32 duel_replace_attacker(lua_State *L);
static int32 duel_change_attack_target(lua_State *L);
static int32 duel_replace_attack_target(lua_State *L);
static int32 duel_calculate_damage(lua_State *L);
static int32 duel_get_battle_damage(lua_State *L);
static int32 duel_change_battle_damage(lua_State *L);
static int32 duel_change_target(lua_State *L);
Expand Down
4 changes: 2 additions & 2 deletions script/c17189677.lua
Expand Up @@ -18,8 +18,8 @@ function c17189677.tgfilter(c)
return c:IsRace(RACE_REPTILE) and c:IsType(TYPE_MONSTER) and c:IsAbleToGrave()
end
function c17189677.target(e,tp,eg,ep,ev,re,r,rp,chk)
if chk==0 then return Duel.IsExistingMatchingCard(c17189677.tgfilter,tp,LOCATION_DECK,0,2,nil) end
Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,2,tp,LOCATION_DECK)
if chk==0 then return Duel.IsExistingMatchingCard(c17189677.tgfilter,tp,LOCATION_DECK,0,4,nil) end
Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,4,tp,LOCATION_DECK)
end
function c17189677.activate(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.GetMatchingGroup(c17189677.tgfilter,tp,LOCATION_DECK,0,nil)
Expand Down
9 changes: 6 additions & 3 deletions script/c25341652.lua
Expand Up @@ -29,11 +29,14 @@ function c25341652.poscost(e,tp,eg,ep,ev,re,r,rp,chk)
if chk==0 then return e:GetHandler():CheckRemoveOverlayCard(tp,1,REASON_COST) end
e:GetHandler():RemoveOverlayCard(tp,1,1,REASON_COST)
end
function c25341652.posfilter(c)
return c:IsPosition(POS_FACEUP_ATTACK) and c:IsCanTurnSet()
end
function c25341652.postg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
if chkc then return chkc:IsControler(1-tp) and chkc:IsLocation(LOCATION_MZONE) and chkc:IsPosition(POS_FACEUP_ATTACK) end
if chk==0 then return Duel.IsExistingTarget(Card.IsPosition,tp,0,LOCATION_MZONE,1,nil,POS_FACEUP_ATTACK) end
if chkc then return chkc:IsControler(1-tp) and chkc:IsLocation(LOCATION_MZONE) and c25341652.posfilter(chkc) end
if chk==0 then return Duel.IsExistingTarget(c25341652.posfilter,tp,0,LOCATION_MZONE,1,nil) end
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUPATTACK)
local g=Duel.SelectTarget(tp,Card.IsPosition,tp,0,LOCATION_MZONE,1,1,nil,POS_FACEUP_ATTACK)
local g=Duel.SelectTarget(tp,c25341652.posfilter,tp,0,LOCATION_MZONE,1,1,nil)
Duel.SetOperationInfo(0,CATEGORY_POSITION,g,1,0,0)
end
function c25341652.posop(e,tp,eg,ep,ev,re,r,rp)
Expand Down
2 changes: 1 addition & 1 deletion script/c29888389.lua
Expand Up @@ -20,7 +20,7 @@ end
function c29888389.rlevel(e,c)
local lv=e:GetHandler():GetLevel()
if c:IsAttribute(ATTRIBUTE_WATER) then
local clv=c:GetOriginalLevel()
local clv=c:GetLevel()
return lv*65536+clv
else return lv end
end
Expand Down
2 changes: 1 addition & 1 deletion script/c47106439.lua
Expand Up @@ -20,7 +20,7 @@ end
function c47106439.rlevel(e,c)
local lv=e:GetHandler():GetLevel()
if c:IsAttribute(ATTRIBUTE_WATER) then
local clv=c:GetOriginalLevel()
local clv=c:GetLevel()
return lv*65536+clv
else return lv end
end
Expand Down
2 changes: 1 addition & 1 deletion script/c67987611.lua
Expand Up @@ -34,7 +34,7 @@ function c67987611.activate(e,tp,eg,ep,ev,re,r,rp)
e1:SetType(EFFECT_TYPE_SINGLE)
e1:SetCode(EFFECT_UPDATE_ATTACK)
e1:SetValue(-500)
e1:SetReset(RESET_EVENT+0x1fe0000+RESET_PHASE+PHASE_END)
e1:SetReset(RESET_EVENT+0x1fe0000)
tc:RegisterEffect(e1)
local e2=Effect.CreateEffect(e:GetHandler())
e2:SetType(EFFECT_TYPE_SINGLE)
Expand Down
2 changes: 1 addition & 1 deletion script/c69488544.lua
Expand Up @@ -35,7 +35,7 @@ function c69488544.filter(c,e,tp)
end
function c69488544.sptg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
if chkc then return chkc:IsLocation(LOCATION_GRAVE) and c69488544.filter(chkc,e,tp) end
if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)~=0
if chk==0 then return e:GetHandler():IsRelateToEffect(e) and Duel.GetLocationCount(tp,LOCATION_MZONE)~=0
and Duel.IsExistingTarget(c69488544.filter,tp,LOCATION_GRAVE,0,1,nil,e,tp) end
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
local g=Duel.SelectTarget(tp,c69488544.filter,tp,LOCATION_GRAVE,0,1,1,nil,e,tp)
Expand Down
5 changes: 4 additions & 1 deletion script/c93504463.lua
Expand Up @@ -29,6 +29,9 @@ end
function c93504463.activate(e,tp,eg,ep,ev,re,r,rp)
local tc=Duel.GetFirstTarget()
if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP)~=0 then
Duel.ChangeAttackTarget(tc)
local a=Duel.GetAttacker()
if a:IsOnField() and a:IsFaceup() then
Duel.CalculateDamage(a, tc)
end
end
end

0 comments on commit 7f3a151

Please sign in to comment.