damagePercent for projectiles
all given damage percents from the projectiles must sum up to exactly 100%
This commit is contained in:
parent
da23e4c048
commit
7e81728fe8
|
@ -31,7 +31,7 @@ ProjectileType::ProjectileType() {
|
||||||
shakeVisible=true;
|
shakeVisible=true;
|
||||||
shakeInCameraView=true;
|
shakeInCameraView=true;
|
||||||
shakeCameraDistanceAffected=false;
|
shakeCameraDistanceAffected=false;
|
||||||
|
damagePercentage=100;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectileType::~ProjectileType() {
|
ProjectileType::~ProjectileType() {
|
||||||
|
@ -56,6 +56,10 @@ void ProjectileType::load(const XmlNode *projectileNode, const string &dir, cons
|
||||||
attackStartTime=0.0f;
|
attackStartTime=0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// damage percentage MUST be set!
|
||||||
|
damagePercentage =projectileNode->getAttribute("damage-percentage")->getIntValue();
|
||||||
|
|
||||||
|
|
||||||
// projectiles MUST have a particle system.
|
// projectiles MUST have a particle system.
|
||||||
const XmlNode *particleNode= projectileNode->getChild("particle");
|
const XmlNode *particleNode= projectileNode->getChild("particle");
|
||||||
string path= particleNode->getAttribute("path")->getRestrictedValue();
|
string path= particleNode->getAttribute("path")->getRestrictedValue();
|
||||||
|
|
|
@ -48,6 +48,7 @@ protected:
|
||||||
bool shakeVisible;
|
bool shakeVisible;
|
||||||
bool shakeInCameraView;
|
bool shakeInCameraView;
|
||||||
bool shakeCameraDistanceAffected;
|
bool shakeCameraDistanceAffected;
|
||||||
|
int damagePercentage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProjectileType();
|
ProjectileType();
|
||||||
|
@ -69,6 +70,8 @@ public:
|
||||||
bool isShakeInCameraView() const{return shakeInCameraView;}
|
bool isShakeInCameraView() const{return shakeInCameraView;}
|
||||||
int getShakeIntensity() const{return shakeIntensity;}
|
int getShakeIntensity() const{return shakeIntensity;}
|
||||||
bool isShakeVisible() const{return shakeVisible;}
|
bool isShakeVisible() const{return shakeVisible;}
|
||||||
|
int getDamagePercentage() const {return damagePercentage;}
|
||||||
|
void setDamagePercentage(int value) {damagePercentage=value;}
|
||||||
|
|
||||||
void setProjectileParticleSystemType(ParticleSystemTypeProjectile *pointer) {projectileParticleSystemType=pointer;}
|
void setProjectileParticleSystemType(ParticleSystemTypeProjectile *pointer) {projectileParticleSystemType=pointer;}
|
||||||
ParticleSystemTypeProjectile* getProjectileParticleSystemType() {return projectileParticleSystemType;}
|
ParticleSystemTypeProjectile* getProjectileParticleSystemType() {return projectileParticleSystemType;}
|
||||||
|
|
|
@ -910,6 +910,7 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
|
||||||
ProjectileType *projectileType=new ProjectileType();
|
ProjectileType *projectileType=new ProjectileType();
|
||||||
projectileTypes.push_back(projectileType);
|
projectileTypes.push_back(projectileType);
|
||||||
projectileType->setAttackStartTime(attackStartTime);
|
projectileType->setAttackStartTime(attackStartTime);
|
||||||
|
projectileType->setDamagePercentage(100);
|
||||||
//proj particle
|
//proj particle
|
||||||
if(projectileNode->hasChild("particle")){
|
if(projectileNode->hasChild("particle")){
|
||||||
const XmlNode *particleNode= projectileNode->getChild("particle");
|
const XmlNode *particleNode= projectileNode->getChild("particle");
|
||||||
|
@ -945,14 +946,20 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
|
||||||
else {
|
else {
|
||||||
const XmlNode *projectilesNode= sn->getChild("projectiles");
|
const XmlNode *projectilesNode= sn->getChild("projectiles");
|
||||||
vector<XmlNode *> projectilesNodeList = projectilesNode->getChildList("projectile");
|
vector<XmlNode *> projectilesNodeList = projectilesNode->getChildList("projectile");
|
||||||
|
int totalDamagePercentage=0;
|
||||||
for(unsigned int i = 0; i < projectilesNodeList.size(); ++i) {
|
for(unsigned int i = 0; i < projectilesNodeList.size(); ++i) {
|
||||||
const XmlNode *projectileNode= projectilesNodeList[i];
|
const XmlNode *projectileNode= projectilesNodeList[i];
|
||||||
ProjectileType *projectileType=new ProjectileType();
|
ProjectileType *projectileType=new ProjectileType();
|
||||||
projectileType->load(projectileNode,dir, tt->getPath(), loadedFileList, parentLoader);
|
projectileType->load(projectileNode,dir, tt->getPath(), loadedFileList, parentLoader);
|
||||||
|
totalDamagePercentage += projectileType->getDamagePercentage();
|
||||||
projectileTypes.push_back(projectileType);
|
projectileTypes.push_back(projectileType);
|
||||||
projectile=true;
|
projectile=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(totalDamagePercentage!=100){
|
||||||
|
throw megaglest_runtime_error("Damages percentages of projectiles don't sum up to 100 %");
|
||||||
|
}
|
||||||
|
|
||||||
//general hit sounds, individual ones can be set in projectiles
|
//general hit sounds, individual ones can be set in projectiles
|
||||||
const XmlNode *soundNode= sn->getChild("hitsound");
|
const XmlNode *soundNode= sn->getChild("hitsound");
|
||||||
if(soundNode->getAttribute("enabled")->getBoolValue()){
|
if(soundNode->getAttribute("enabled")->getBoolValue()){
|
||||||
|
|
|
@ -2501,10 +2501,10 @@ void UnitUpdater::updateSwitchTeam(Unit *unit, int frameIndex) {
|
||||||
// ==================== attack ====================
|
// ==================== attack ====================
|
||||||
|
|
||||||
void UnitUpdater::hit(Unit *attacker){
|
void UnitUpdater::hit(Unit *attacker){
|
||||||
hit(attacker, dynamic_cast<const AttackSkillType*>(attacker->getCurrSkill()), attacker->getTargetPos(), attacker->getTargetField());
|
hit(attacker, dynamic_cast<const AttackSkillType*>(attacker->getCurrSkill()), attacker->getTargetPos(), attacker->getTargetField(),100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField){
|
void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField, int damagePercent){
|
||||||
//hit attack positions
|
//hit attack positions
|
||||||
if(ast != NULL && ast->getSplash()) {
|
if(ast != NULL && ast->getSplash()) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
|
@ -2524,7 +2524,7 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
|
||||||
|
|
||||||
float distance = pci.getPos().dist(targetPos);
|
float distance = pci.getPos().dist(targetPos);
|
||||||
distance = truncateDecimal<float>(distance,6);
|
distance = truncateDecimal<float>(distance,6);
|
||||||
damage(attacker, ast, attacked, distance);
|
damage(attacker, ast, attacked, distance,damagePercent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2537,12 +2537,12 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
|
||||||
attacker->addNetworkCRCDecHp(szBuf);
|
attacker->addNetworkCRCDecHp(szBuf);
|
||||||
|
|
||||||
if(attacked != NULL) {
|
if(attacked != NULL) {
|
||||||
damage(attacker, ast, attacked, 0.f);
|
damage(attacker, ast, attacked, 0.f,damagePercent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance) {
|
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance, int damagePercent) {
|
||||||
if(attacker == NULL) {
|
if(attacker == NULL) {
|
||||||
throw megaglest_runtime_error("attacker == NULL");
|
throw megaglest_runtime_error("attacker == NULL");
|
||||||
}
|
}
|
||||||
|
@ -2568,6 +2568,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
|
||||||
damage *= damageMultiplier;
|
damage *= damageMultiplier;
|
||||||
damage = truncateDecimal<float>(damage,6);
|
damage = truncateDecimal<float>(damage,6);
|
||||||
|
|
||||||
|
damage = (damage*damagePercent)/100;
|
||||||
if(damage < 1) {
|
if(damage < 1) {
|
||||||
damage= 1;
|
damage= 1;
|
||||||
}
|
}
|
||||||
|
@ -3249,7 +3250,7 @@ void ParticleDamager::update(ParticleSystem *particleSystem) {
|
||||||
snprintf(szBuf,8095,"Unit hitting [ParticleDamager::update] [%s] targetField = %d",targetPos.getString().c_str(),targetField);
|
snprintf(szBuf,8095,"Unit hitting [ParticleDamager::update] [%s] targetField = %d",targetPos.getString().c_str(),targetField);
|
||||||
attacker->addNetworkCRCDecHp(szBuf);
|
attacker->addNetworkCRCDecHp(szBuf);
|
||||||
|
|
||||||
unitUpdater->hit(attacker, ast, targetPos, targetField);
|
unitUpdater->hit(attacker, ast, targetPos, targetField, projectileType->getDamagePercentage());
|
||||||
|
|
||||||
//char szBuf[8096]="";
|
//char szBuf[8096]="";
|
||||||
//snprintf(szBuf,8095,"ParticleDamager::update attacker particleSystem before: %s\nafter: %s",auditBeforeHit.c_str(),particleSystem->toString().c_str());
|
//snprintf(szBuf,8095,"ParticleDamager::update attacker particleSystem before: %s\nafter: %s",auditBeforeHit.c_str(),particleSystem->toString().c_str());
|
||||||
|
|
|
@ -141,8 +141,8 @@ public:
|
||||||
private:
|
private:
|
||||||
//attack
|
//attack
|
||||||
void hit(Unit *attacker);
|
void hit(Unit *attacker);
|
||||||
void hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField);
|
void hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField, int damagePercent);
|
||||||
void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance);
|
void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance, int damagePercent);
|
||||||
void startAttackParticleSystem(Unit *unit, float lastAnimProgress, float animProgress);
|
void startAttackParticleSystem(Unit *unit, float lastAnimProgress, float animProgress);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
|
Loading…
Reference in New Issue