FrostTurretProjectile::FrostTurretProjectile(unsigned int _master, unsigned int _target, float _slowEffect, int _damage) { m_master = _master; m_target = _target; m_visible = false; this->m_type = OtherType; this->m_slowEffect = _slowEffect; ServerEntity* master = EntityHandler::getServerEntity(m_master); ServerEntity* target = EntityHandler::getServerEntity(m_target); m_timeToImpact = (target->getPosition() - master->getPosition()).length()/FrostTurretProjectile::VELOCITY; this->m_masterOwner = ((Turret*)master)->getOwnerId(); // Calc position of projectile with offset from the pipe of the turret and send network msg FLOAT3 distance = target->getPosition() - master->getPosition(); distance = distance/distance.length(); this->m_messageQueue->pushOutgoingMessage(new CreateActionTargetMessage(Skill::FROST_TURRET_PROJECTILE, m_master, m_target, master->getPosition()+distance*0.5f)); this->m_damage = _damage; }
void ArrowClientSkillEffect::update(float _dt) { Entity* target = ClientEntityHandler::getEntity(m_targetId); if(target && target->m_health > 0) { D3DXVECTOR3 newPos = D3DXVECTOR3(m_graphicalEffect->getPosition().x, m_graphicalEffect->getPosition().y, m_graphicalEffect->getPosition().z); this->m_particleSystem->setPosition(newPos); FLOAT3 dist = target->m_model->getPosition()-m_graphicalEffect->getPosition(); FLOAT3 movement = dist/dist.length()*RangedAttack::VELOCITY*_dt; if(dist.length() > movement.length()) { m_graphicalEffect->move(movement); m_graphicalEffect->setRotation(FLOAT3(atan2(-movement.x, -movement.z), 0.0f, 0.0f)); } else { m_active = false; if(target->m_type == UnitEntity::EnemyType) { int sound; switch(random(0, 2)) { case 0: sound = createSoundHandle("enemy/Monster_Imp_Damage_0.wav", false, false); break; case 1: sound = createSoundHandle("enemy/Monster_Imp_Damage_1.wav", false, false); break; case 2: sound = createSoundHandle("enemy/Monster_Imp_Damage_2.wav", false, false); break; } SpeechManager::speak(m_targetId, sound); // The unit must be killed on the client before on the server for this sound solution to actually work. deactivateSound(sound); } else if(target->m_type == UnitEntity::HeroType) { int sound; switch(target->m_subtype) { case Hero::RED_KNIGHT: switch(random(0, 2)) { case 0: sound = createSoundHandle("red_knight/RedKnight_Damage_0.wav", false, false); break; case 1: sound = createSoundHandle("red_knight/RedKnight_Damage_1.wav", false, false); break; case 2: sound = createSoundHandle("red_knight/RedKnight_Damage_2.wav", false, false); break; } break; case Hero::ENGINEER: switch(random(0, 2)) { case 0: sound = createSoundHandle("engineer/Engineer_Damage_0.wav", false, false); break; case 1: sound = createSoundHandle("engineer/Engineer_Damage_1.wav", false, false); break; case 2: sound = createSoundHandle("engineer/Engineer_Damage_2.wav", false, false); break; } break; case Hero::THE_MENTALIST: switch(random(0, 2)) { case 0: sound = createSoundHandle("mentalist/Mentalist_Damage_0.wav", false, false); break; case 1: sound = createSoundHandle("mentalist/Mentalist_Damage_1.wav", false, false); break; case 2: sound = createSoundHandle("mentalist/Mentalist_Damage_2.wav", false, false); break; } break; case Hero::OFFICER: switch(random(0, 2)) { case 0: sound = createSoundHandle("officer/Officer_Damage_0.wav", false, false); break; case 1: sound = createSoundHandle("officer/Officer_Damage_1.wav", false, false); break; case 2: sound = createSoundHandle("officer/Officer_Damage_2.wav", false, false); break; } break; case Hero::DOCTOR: switch(random(0, 2)) { case 0: sound = createSoundHandle("doctor/Doctor_Damage_0.wav", false, false); break; case 1: sound = createSoundHandle("doctor/Doctor_Damage_1.wav", false, false); break; case 2: sound = createSoundHandle("doctor/Doctor_Damage_2.wav", false, false); break; } break; } SpeechManager::speak(m_targetId, sound); // The unit must be killed on the client before on the server for this sound solution to actually work. deactivateSound(sound); } } } else { m_active = false; } }
void Hero::updateSpecificUnitEntity(float dt) { if(this->m_health > 0) { //Handle incoming messages Message *m; while(this->m_messageQueue->incomingQueueEmpty() == false) { m = this->m_messageQueue->pullIncomingMessage(); if(m->type == Message::Collision) { //this->m_position = FLOAT3(0.0f, 0.0f, 0.0f); } delete m; } if(this->m_attackCooldown > 0.0f) { this->m_attackCooldown = this->m_attackCooldown - dt; } if(this->m_hasTarget == true) { ServerEntity *se = EntityHandler::getServerEntity(this->m_target); if(se == NULL) { this->m_hasTarget = false; this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::IDLE, this->m_id, this->m_position)); } else { FLOAT3 distance = se->getPosition() - this->m_position; this->m_rotation.x = atan2(-distance.x, -distance.z); //If the hero is in range, KILL IT! if(se != NULL) { if((se->getPosition() - this->m_position).length() <= this->m_regularAttack->getRange()) { if(this->m_attackCooldown <= 0.0f) { //this->m_messageQueue->pushOutgoingMessage(new CreateActionTargetMessage(Skill::ATTACK, this->m_id, se->getId(), this->m_position)); //EntityHandler::addEntity(new Arrow((m_position-se->getPosition()).length(), se->getId(), m_id)); //this->dealDamage(se, this->m_physicalDamage, this->m_mentalDamage); // dont this->attack(this->m_target); this->m_attackCooldown = this->m_attackSpeed; this->m_nextPosition = this->m_position; this->m_messageQueue->pushOutgoingMessage(this->getUpdateEntityMessage()); } if(this->m_reachedPosition == false) { this->m_reachedPosition = true; this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::IDLE, this->m_id, this->m_position)); } } else //Otherwise you should find a way to get to the enemy { if(this->m_reachedPosition == true) { this->m_path = g_pathfinder->getPath(FLOAT2(this->m_position.x, this->m_position.z), FLOAT2(se->getPosition().x, se->getPosition().z)); if(this->m_path.nrOfPoints > 0) { this->m_pathCounter = 1; this->m_nextPosition = FLOAT3(this->m_path.points[0].x, 0.0f, this->m_path.points[0].y); this->m_reachedPosition = false; this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::MOVE, this->m_id, this->m_position)); this->m_messageQueue->pushOutgoingMessage(this->getUpdateEntityMessage()); } } else //Move along the path { distance = this->m_nextPosition - this->m_position; if(distance.length() - 0.125f > this->m_movementSpeed * dt) { distance = distance / distance.length(); this->m_position = this->m_position + (distance * this->m_movementSpeed * dt); this->m_rotation.x = atan2(-distance.x, -distance.z); } else { if(this->m_pathCounter < this->m_path.nrOfPoints) { this->m_nextPosition = FLOAT3(this->m_path.points[this->m_pathCounter].x, 0.0f, this->m_path.points[this->m_pathCounter].y); this->m_pathCounter++; this->m_messageQueue->pushOutgoingMessage(this->getUpdateEntityMessage()); } else if(this->m_reachedPosition == false) { this->m_position = this->m_nextPosition; this->m_reachedPosition = true; this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::IDLE, this->m_id, this->m_position)); this->m_messageQueue->pushOutgoingMessage(this->getUpdateEntityMessage()); this->m_messageQueue->pushOutgoingMessage(new UpdateEntityMessage(this->getId(),this->getPosition().x,this->getPosition().z,this->getRotation().x,0.0f,0.0f,0.0f,0.0f,this->getMovementSpeed())); } this->m_obb->Center = XMFLOAT3(this->m_position.x, this->m_position.y, this->m_position.z); } } } } else //The target doesn't exist { this->m_hasTarget = false; this->m_reachedPosition = true; this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::IDLE, this->m_id, this->m_position)); } } } else if(this->m_reachedPosition == false) { FLOAT3 distance = this->m_nextPosition - this->m_position; float lol = 0.0f; if(this->m_reallyReachedPosition == false) { lol = 0.125f; } if(distance.length() - lol > this->m_movementSpeed * dt) { distance = distance / distance.length(); this->m_position = this->m_position + (distance * this->m_movementSpeed * dt); } else { if(this->m_pathCounter < this->m_path.nrOfPoints) { this->m_nextPosition = FLOAT3(this->m_path.points[this->m_pathCounter].x, 0.0f, this->m_path.points[this->m_pathCounter].y); this->m_pathCounter++; this->m_obb->Center = XMFLOAT3(this->m_position.x, this->m_position.y, this->m_position.z); this->m_rotation.x = atan2(-distance.x, -distance.z); this->m_messageQueue->pushOutgoingMessage(this->getUpdateEntityMessage()); } else { this->m_nextPosition = this->m_position; this->m_reachedPosition = true; //this->m_startPos= m_nextPosition; this->m_messageQueue->pushOutgoingMessage(this->getUpdateEntityMessage()); this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::IDLE, this->m_id, this->m_position)); } } this->m_obb->Center = XMFLOAT3(this->m_position.x, this->m_position.y, this->m_position.z); this->m_rotation.x = atan2(-distance.x, -distance.z); } } else if(this->m_alive == true) { this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::DEATH, this->m_id, this->m_position)); this->m_position = FLOAT3(-1000.0f, 0.0f, -1000.0f); this->m_hasTarget = NULL; this->m_reachedPosition = true; this->m_messageQueue->pushOutgoingMessage(this->getUpdateEntityMessage()); this->m_messageQueue->pushOutgoingMessage(new HeroDiedMessage(this->m_id, this->m_playerId)); this->m_alive = false; } }