PoisonTurretProjectile::PoisonTurretProjectile(unsigned int _master, unsigned int _target, unsigned int _mentalDamage) { m_master = _master; m_target = _target; m_visible = false; this->m_type = OtherType; ServerEntity* master = EntityHandler::getServerEntity(m_master); ServerEntity* target = EntityHandler::getServerEntity(m_target); m_timeToImpact = (target->getPosition() - master->getPosition()).length()/PoisonTurretProjectile::VELOCITY; this->m_masterOwner = ((Turret*)master)->getOwnerId(); this->m_messageQueue->pushOutgoingMessage(new CreateActionTargetMessage(Skill::POISON_TURRET_PROJECTILE, m_master, m_target, master->getPosition())); this->m_mentalDamage = _mentalDamage; }
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 ReadyAimFire::updateSpecificSkill(float dt) { ServerEntity *caster = EntityHandler::getServerEntity(this->m_senderId); if(caster != NULL) { FLOAT3 position = caster->getPosition(); vector<ServerEntity*> turrets = EntityHandler::getEntitiesByType(ServerEntity::TowerType); for(int i = 0; i < turrets.size(); i++) { if((turrets[i]->getPosition() - position).length() <= ReadyAimFire::RANGE) { ((Turret*)turrets[i])->setReadyAimFire(0.05f * ((UnitEntity*)caster)->getAgility()); } else { ((Turret*)turrets[i])->setReadyAimFire(0.0f); } } } }
DemonicPresenceEffect::DemonicPresenceEffect(unsigned int _caster) { m_caster = _caster; this->m_obb = NULL; FLOAT3 pos = EntityHandler::getServerEntity(_caster)->getPosition(); this->m_bs = new BoundingSphere(XMFLOAT3(pos.x, 0.0f, pos.z), 0.01f); m_visible = false; m_timer = 0.0f; m_type = OtherType; ServerEntity* caster = EntityHandler::getServerEntity(m_caster); vector<ServerEntity*> heroes = EntityHandler::getAllHeroes(); for(int i = 0; i < heroes.size(); i++) { bool alreadyAffected = false; for(int j = 0; j < m_affectedGuys.size(); j++) { if(heroes[i]->getId() == m_affectedGuys[j]) { alreadyAffected = true; j = m_affectedGuys.size(); } } if(!alreadyAffected) { if((caster->getPosition()-heroes[i]->getPosition()).length() <= AOE) { m_affectedGuys.push_back(heroes[i]->getId()); ((UnitEntity*)heroes.at(i))->alterMovementSpeed(MOVEMENT_SPEED_BOOST); ((UnitEntity*)heroes.at(i))->alterAttackSpeed(ATTACK_SPEED_BOOST); this->m_messageQueue->pushOutgoingMessage(new CreateActionTargetMessage(Skill::DEMONIC_PRESENCE, 0, heroes[i]->getId(), heroes[i]->getPosition())); } } } }
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; } }
void DemonicPresenceEffect::update(float _dt) { ServerEntity* caster = EntityHandler::getServerEntity(m_caster); if(caster) { m_timer += _dt; // If the spell duration has expired, remove all affected dudes and buffs. if(m_timer >= LIFETIME) { for(int i = 0; i < m_affectedGuys.size(); i++) { ServerEntity* se = EntityHandler::getServerEntity(m_affectedGuys[i]); if(se && (caster->getPosition()-se->getPosition()).length() <= AOE) { ((UnitEntity*)se)->alterMovementSpeed(-MOVEMENT_SPEED_BOOST); ((UnitEntity*)se)->alterAttackSpeed(-ATTACK_SPEED_BOOST); this->m_messageQueue->pushOutgoingMessage(new RemoveActionTargetMessage(Skill::DEMONIC_PRESENCE, 0, se->getId())); m_affectedGuys.erase(m_affectedGuys.begin()+i); i--; } } this->m_messageQueue->pushOutgoingMessage(new RemoveServerEntityMessage(0, EntityHandler::getId(), this->m_id)); } else { // Check if any of the affected guys have died or escaped the aura area. for(int i = 0; i < m_affectedGuys.size(); i++) { // Dont mind the caster, he is taken care of elsewhere i hope(?). if(m_affectedGuys[i] != m_caster) { ServerEntity* se = EntityHandler::getServerEntity(m_affectedGuys[i]); // Check if the affected guy has died recently then remove it. if(!se) { m_affectedGuys.erase(m_affectedGuys.begin()+i); i--; this->m_messageQueue->pushOutgoingMessage(new RemoveActionTargetMessage(Skill::DEMONIC_PRESENCE, 0, se->getId())); } // Else the affected guys is still alive and might have escaped the aura area and needs to be taken down! else if((caster->getPosition()-se->getPosition()).length() > AOE) { ((UnitEntity*)se)->alterMovementSpeed(-MOVEMENT_SPEED_BOOST); ((UnitEntity*)se)->alterAttackSpeed(-ATTACK_SPEED_BOOST); m_affectedGuys.erase(m_affectedGuys.begin()+i); i--; this->m_messageQueue->pushOutgoingMessage(new RemoveActionTargetMessage(Skill::DEMONIC_PRESENCE, 0, se->getId())); } } } // Check if any newcomers want to join in on the oral (aural) fun. vector<ServerEntity*> heroes = EntityHandler::getAllHeroes(); for(int i = 0; i < heroes.size(); i++) { if(heroes[i]->getId() != m_caster) { bool alreadyAffected = false; for(int j = 0; j < m_affectedGuys.size(); j++) { if(heroes[i]->getId() == m_affectedGuys[j]) { alreadyAffected = true; j = m_affectedGuys.size(); } } if(!alreadyAffected) { if((caster->getPosition()-heroes[i]->getPosition()).length() <= AOE) { m_affectedGuys.push_back(heroes[i]->getId()); ((UnitEntity*)heroes.at(i))->alterMovementSpeed(MOVEMENT_SPEED_BOOST); ((UnitEntity*)heroes.at(i))->alterAttackSpeed(ATTACK_SPEED_BOOST); this->m_messageQueue->pushOutgoingMessage(new CreateActionTargetMessage(Skill::DEMONIC_PRESENCE, 0, heroes[i]->getId(), heroes[i]->getPosition())); } } } } } } }
bool SwiftAsACatPowerfulAsABoar::activate(unsigned int _senderId) { if(this->getCurrentCooldown() == 0) { ServerEntity *e = EntityHandler::getServerEntity(_senderId); if(e) { UnitEntity* ue = (UnitEntity*)e; ue->setSwiftAsACatPowerfulAsABear(true); this->resetCooldown();; e->getMessageQueue()->pushOutgoingMessage(new CreateActionMessage(Skill::SWIFT_AS_A_CAT_POWERFUL_AS_A_BEAR, e->getId(), e->getPosition())); return true; } else return false; } else return false; }