Add pre attack event #4075

This commit is contained in:
spixi 2019-05-17 00:11:07 +02:00 committed by Pentarctagon
parent cf49f6e230
commit 0f763cfdd6
2 changed files with 39 additions and 15 deletions

View File

@ -122,6 +122,26 @@
[/do_command]
{ASSERT_NO_9_5}
[event]
name = pre attack
first_time_only = yes
{ASSERT_YES_9_5}
[move_unit]
x,y=9,5
to_x,to_y=10,5
[/move_unit]
[/event]
[event]
name = attack
first_time_only = yes
{ASSERT_NO_9_5}
[move_unit]
x,y=10,5
to_x,to_y=9,5
[/move_unit]
[/event]
{UNIT 2 "Spearman" 9 5 (id=steve7)}
{ASSERT_YES_9_5}
[do_command]

View File

@ -1367,6 +1367,25 @@ void attack::perform()
return;
}
bc_.reset(new battle_context(units_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_));
a_stats_ = &bc_->get_attacker_stats();
d_stats_ = &bc_->get_defender_stats();
if(a_stats_->weapon) {
a_.weap_id_ = a_stats_->weapon->id();
}
if(d_stats_->weapon) {
d_.weap_id_ = d_stats_->weapon->id();
}
try {
fire_event("pre_attack");
} catch(const attack_end_exception&) {
return;
}
a_.get_unit().set_facing(a_.loc_.get_relative_dir(d_.loc_));
d_.get_unit().set_facing(d_.loc_.get_relative_dir(a_.loc_));
@ -1383,32 +1402,17 @@ void attack::perform()
// If the attacker was invisible, she isn't anymore!
a_.get_unit().set_state(unit::STATE_UNCOVERED, true);
bc_.reset(new battle_context(units_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_));
a_stats_ = &bc_->get_attacker_stats();
d_stats_ = &bc_->get_defender_stats();
if(a_stats_->disable) {
LOG_NG << "attack::perform(): tried to attack with a disabled attack.";
return;
}
if(a_stats_->weapon) {
a_.weap_id_ = a_stats_->weapon->id();
}
if(d_stats_->weapon) {
d_.weap_id_ = d_stats_->weapon->id();
}
try {
fire_event("attack");
} catch(const attack_end_exception&) {
return;
}
refresh_bc();
DBG_NG << "getting attack statistics";
statistics::attack_context attack_stats(
a_.get_unit(), d_.get_unit(), a_stats_->chance_to_hit, d_stats_->chance_to_hit);