添加技能次數
This commit is contained in:
parent
87960564a3
commit
034fe8de3c
@ -10,7 +10,19 @@ void Skill::Initialzie()
|
||||
switch (meta->i->skill_type()) {
|
||||
case kActiveSkill:
|
||||
{
|
||||
|
||||
inc_times_timer_ = owner->room->xtimer.AddRepeatTimerAndAttach
|
||||
(
|
||||
GetCd() / FRAME_RATE_MS,
|
||||
a8::XParams()
|
||||
.SetSender(this),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Skill* skill = (Skill*)param.sender.GetUserData();
|
||||
if (skill->GetCurrTimes() < skill->GetMaxTimes()) {
|
||||
skill->curr_times_++;
|
||||
}
|
||||
},
|
||||
&xtimer_attacher.timer_list_);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -27,8 +39,17 @@ int Skill::GetCd()
|
||||
|
||||
int Skill::GetPassedTime()
|
||||
{
|
||||
int passed_time = (owner->room->GetFrameNo() - last_use_frameno) * FRAME_RATE_MS;
|
||||
return passed_time;
|
||||
if (!inc_times_timer_) {
|
||||
abort();
|
||||
}
|
||||
if (GetCurrTimes() >= GetMaxTimes()) {
|
||||
return GetCd();
|
||||
} else {
|
||||
int remain_time = owner->room->xtimer.GetRemainTime(inc_times_timer_);
|
||||
int passed_time = GetCd() - remain_time * FRAME_RATE_MS;
|
||||
passed_time = std::max(0, passed_time);
|
||||
return passed_time;
|
||||
}
|
||||
}
|
||||
|
||||
int Skill::GetLeftTime()
|
||||
@ -44,7 +65,7 @@ void Skill::FillMFSkill(cs::MFSkill* skill_pb)
|
||||
skill_pb->set_left_time(GetLeftTime());
|
||||
skill_pb->set_cd_time(GetCd());
|
||||
skill_pb->set_curr_times(GetCurrTimes());
|
||||
skill_pb->set_max_times(meta->i->max_times());
|
||||
skill_pb->set_max_times(GetMaxTimes());
|
||||
}
|
||||
|
||||
void Skill::ClearPassiveSkillBuff()
|
||||
@ -77,6 +98,12 @@ void Skill::AddPassiveSkillBuff()
|
||||
|
||||
void Skill::DecTimes()
|
||||
{
|
||||
if (!inc_times_timer_) {
|
||||
abort();
|
||||
}
|
||||
if (GetCurrTimes() >= GetMaxTimes()) {
|
||||
owner->room->xtimer.ModifyTimer(inc_times_timer_, GetCd() / FRAME_RATE_MS);
|
||||
}
|
||||
--curr_times_;
|
||||
if (curr_times_ < 0) {
|
||||
curr_times_ = 0;
|
||||
@ -87,3 +114,8 @@ int Skill::GetCurrTimes()
|
||||
{
|
||||
return curr_times_;
|
||||
}
|
||||
|
||||
int Skill::GetMaxTimes()
|
||||
{
|
||||
return meta->i->max_times();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ enum SkillType_e
|
||||
kPassiveSkill = 2
|
||||
};
|
||||
|
||||
struct xtimer_list;
|
||||
class Creature;
|
||||
class Skill
|
||||
{
|
||||
@ -30,6 +31,7 @@ class Skill
|
||||
int GetLeftTime();
|
||||
int GetPassedTime();
|
||||
int GetCurrTimes();
|
||||
int GetMaxTimes();
|
||||
void DecTimes();
|
||||
void FillMFSkill(cs::MFSkill* skill_pb);
|
||||
|
||||
@ -38,4 +40,5 @@ class Skill
|
||||
|
||||
private:
|
||||
int curr_times_ = 0;
|
||||
xtimer_list* inc_times_timer_ = nullptr;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user