OSDN Git Service

Merge pull request #3569 from sikabane-works/release/3.0.0.88-alpha
[hengbandforosx/hengbandosx.git] / src / mspell / mspell-attack / abstract-mspell.cpp
1 #include "mspell/mspell-attack/abstract-mspell.h"
2 #include "monster/monster-update.h"
3 #include "mspell/mspell-damage-calculator.h"
4 #include "mspell/mspell-util.h"
5 #include "system/player-type-definition.h"
6
7 AbstractMSpellAttack::AbstractMSpellAttack(PlayerType *player_ptr, MONSTER_IDX m_idx, MonsterAbilityType ability, MSpellData data, int target_type, std::function<ProjectResult(POSITION, POSITION, int, AttributeType)> fire)
8     : player_ptr(player_ptr)
9     , m_idx(m_idx)
10     , t_idx(0)
11     , ability(ability)
12     , data(std::move(data))
13     , target_type(target_type)
14     , fire(std::move(fire))
15 {
16 }
17
18 AbstractMSpellAttack::AbstractMSpellAttack(PlayerType *player_ptr, MONSTER_IDX m_idx, MONSTER_IDX t_idx, MonsterAbilityType ability, MSpellData data, int target_type, std::function<ProjectResult(POSITION, POSITION, int, AttributeType)> fire)
19     : player_ptr(player_ptr)
20     , m_idx(m_idx)
21     , t_idx(t_idx)
22     , ability(ability)
23     , data(std::move(data))
24     , target_type(target_type)
25     , fire(std::move(fire))
26 {
27 }
28
29 MonsterSpellResult AbstractMSpellAttack::shoot(POSITION y, POSITION x)
30 {
31     if (!this->data.contain) {
32         return MonsterSpellResult::make_invalid();
33     }
34
35     this->data.msg.output(this->player_ptr, this->m_idx, this->t_idx, this->target_type);
36
37     const auto dam = monspell_damage(this->player_ptr, this->ability, this->m_idx, DAM_ROLL);
38     const auto proj_res = fire(y, x, dam, data.type);
39     if (this->target_type == MONSTER_TO_PLAYER) {
40         this->data.drs.execute(this->player_ptr, this->m_idx);
41     }
42
43     auto res = MonsterSpellResult::make_valid(dam);
44     res.learnable = proj_res.affected_player;
45
46     return res;
47 }