mirror of
https://github.com/ChuXunYu/OnlineRpg.git
synced 2026-01-31 16:55:46 +00:00
2
This commit is contained in:
169
src/core/Skills.cpp
Normal file
169
src/core/Skills.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
#include "Skills.h"
|
||||
#include "Characters.h"
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
|
||||
// 随机数生成器
|
||||
static std::random_device rd;
|
||||
static std::mt19937 gen(rd());
|
||||
|
||||
// ===== NormalAttack 实现 =====
|
||||
|
||||
NormalAttack::NormalAttack() {
|
||||
m_name = "Normal Attack";
|
||||
m_description = "Basic attack";
|
||||
m_manaCost = 0;
|
||||
m_cooldown = 0;
|
||||
}
|
||||
|
||||
std::string NormalAttack::execute(ICharacter& caster, ICharacter& target) {
|
||||
int damage = caster.getAttack();
|
||||
target.takeDamage(damage);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << caster.getName() << " attacks " << target.getName()
|
||||
<< " for " << damage << " damage!";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// ===== HeavyStrike 实现 =====
|
||||
|
||||
HeavyStrike::HeavyStrike() {
|
||||
m_name = "Heavy Strike";
|
||||
m_description = "Powerful strike consuming rage";
|
||||
m_manaCost = 10;
|
||||
m_cooldown = 0;
|
||||
}
|
||||
|
||||
std::string HeavyStrike::execute(ICharacter& caster, ICharacter& target) {
|
||||
Warrior* warrior = dynamic_cast<Warrior*>(&caster);
|
||||
if (!warrior || !caster.consumeMana(m_manaCost)) {
|
||||
return caster.getName() + " failed to use " + m_name + "!";
|
||||
}
|
||||
|
||||
// 造成 1.5 倍伤害
|
||||
int damage = static_cast<int>(caster.getAttack() * 1.5);
|
||||
target.takeDamage(damage);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << caster.getName() << " uses [Heavy Strike] on " << target.getName()
|
||||
<< " for " << damage << " damage!";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// ===== DefensiveStance 实现 =====
|
||||
|
||||
DefensiveStance::DefensiveStance() {
|
||||
m_name = "Defensive Stance";
|
||||
m_description = "Heal and boost defense";
|
||||
m_manaCost = 15;
|
||||
m_cooldown = 0;
|
||||
}
|
||||
|
||||
std::string DefensiveStance::execute(ICharacter& caster, ICharacter& target) {
|
||||
if (!caster.consumeMana(m_manaCost)) {
|
||||
return caster.getName() + " failed to use " + m_name + "!";
|
||||
}
|
||||
|
||||
int healAmount = 20;
|
||||
caster.heal(healAmount);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << caster.getName() << " uses [Defensive Stance] and heals "
|
||||
<< healAmount << " HP!";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// ===== Fireball 实现 =====
|
||||
|
||||
Fireball::Fireball() {
|
||||
m_name = "Fireball";
|
||||
m_description = "Launch a fireball";
|
||||
m_manaCost = 20;
|
||||
m_cooldown = 0;
|
||||
}
|
||||
|
||||
std::string Fireball::execute(ICharacter& caster, ICharacter& target) {
|
||||
if (!caster.consumeMana(m_manaCost)) {
|
||||
return caster.getName() + " failed to use " + m_name + "!";
|
||||
}
|
||||
|
||||
// 造成 1.8 倍魔法伤害
|
||||
int damage = static_cast<int>(caster.getAttack() * 1.8);
|
||||
target.takeDamage(damage);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << caster.getName() << " casts [Fireball] at " << target.getName()
|
||||
<< " for " << damage << " magic damage!";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// ===== FrostNova 实现 =====
|
||||
|
||||
FrostNova::FrostNova() {
|
||||
m_name = "Frost Nova";
|
||||
m_description = "Freeze and damage enemy";
|
||||
m_manaCost = 25;
|
||||
m_cooldown = 0;
|
||||
}
|
||||
|
||||
std::string FrostNova::execute(ICharacter& caster, ICharacter& target) {
|
||||
if (!caster.consumeMana(m_manaCost)) {
|
||||
return caster.getName() + " failed to use " + m_name + "!";
|
||||
}
|
||||
|
||||
int damage = static_cast<int>(caster.getAttack() * 1.3);
|
||||
target.takeDamage(damage);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << caster.getName() << " casts [Frost Nova] on " << target.getName()
|
||||
<< " for " << damage << " frost damage!";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// ===== ArcaneShield 实现 =====
|
||||
|
||||
ArcaneShield::ArcaneShield() {
|
||||
m_name = "Arcane Shield";
|
||||
m_description = "Create magical shield";
|
||||
m_manaCost = 30;
|
||||
m_cooldown = 0;
|
||||
}
|
||||
|
||||
std::string ArcaneShield::execute(ICharacter& caster, ICharacter& target) {
|
||||
Mage* mage = dynamic_cast<Mage*>(&caster);
|
||||
if (!mage || !caster.consumeMana(m_manaCost)) {
|
||||
return caster.getName() + " failed to use " + m_name + "!";
|
||||
}
|
||||
|
||||
int shieldAmount = 30;
|
||||
mage->addShield(shieldAmount);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << caster.getName() << " creates [Arcane Shield] absorbing "
|
||||
<< shieldAmount << " damage!";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// ===== Heal 实现 =====
|
||||
|
||||
Heal::Heal() {
|
||||
m_name = "Heal";
|
||||
m_description = "Restore health";
|
||||
m_manaCost = 15;
|
||||
m_cooldown = 0;
|
||||
}
|
||||
|
||||
std::string Heal::execute(ICharacter& caster, ICharacter& target) {
|
||||
if (!caster.consumeMana(m_manaCost)) {
|
||||
return caster.getName() + " failed to use " + m_name + "!";
|
||||
}
|
||||
|
||||
int healAmount = 30;
|
||||
target.heal(healAmount);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << caster.getName() << " casts [Heal] on " << target.getName()
|
||||
<< " restoring " << healAmount << " HP!";
|
||||
return oss.str();
|
||||
}
|
||||
Reference in New Issue
Block a user