void FrostTurretProjectile::update(float _dt) { m_timeToImpact = max(m_timeToImpact-_dt, 0.0f); if(m_timeToImpact == 0.0f) { ServerEntity* target = EntityHandler::getServerEntity(m_target); if(target) { int damage = random(1, 5); int healthBefore = target->getHealth(); target->takeDamage(this->m_masterOwner, this->m_damage, 0); ((UnitEntity*)target)->applyFrostTurretSlowEffect(this->m_slowEffect); // dbg stringstream ss; target = EntityHandler::getServerEntity(m_target); if(target) ss << "Frost turret projectile did " << damage << " damage and reduced health from " << healthBefore << " to " << target->getHealth() << endl; else ss << "Frost turret projectile did " << damage << " damage and reduced health from " << healthBefore << " to death" << endl; OutputDebugString(ss.str().c_str()); // Remove me from server entity handler this->m_messageQueue->pushOutgoingMessage(new RemoveServerEntityMessage(0, EntityHandler::getId(), this->m_id)); } } }
void CloudOfDarknessEffect::tick() { vector<ServerEntity*> enemies = EntityHandler::getEntitiesByType(Type::EnemyType); for(int i = 0; i < enemies.size(); i++) { ServerEntity* enemy = enemies[i]; if(enemy->intersects(*m_bs)) { enemy->takeDamage(this->getId(), m_damage*0.5f, 0); } } }
void Hero::setTarget(unsigned int _target) { ServerEntity *se = EntityHandler::getServerEntity(_target); if(se != NULL && se->getType() == ServerEntity::EnemyType) { this->m_hasTarget = true; this->m_target = _target; this->m_reachedPosition = true; this->m_reallyReachedPosition = true; } }
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; }
bool Mission::handle(int atWave) { ServerEntity *boss = EntityHandler::getServerEntity(this->bossId); if(atWave>=this->startWave&&atWave<=this->endWave&&!this->missionStarted&&!missionRunning) { this->missionStarted=true; this->missionRunning=true; this->m_messageQueue->pushOutgoingMessage(new MissionMessage(this->missionName,"start")); this->startMission(); } if(boss != NULL && EntityHandler::getServerEntity(this->bossId)->getHealth()<=0) { this->missionComplete=true; if(boss != NULL) { boss->tellBossToDropGold(); boss->getMessageQueue()->pushOutgoingMessage(new RemoveServerEntityMessage(0, EntityHandler::getId(), boss->getId())); this->m_messageQueue->pushOutgoingMessage(new MissionMessage(this->missionName,"completed")); this->m_messageQueue->pushOutgoingMessage(new CreateActionMessage(Skill::DEATH, this->m_id, this->m_position)); } } if(this->missionRunning) { //missionTime+=dt; if(atWave>=this->endWave) { this->missionRunning=false; //if the enemy died this->missionTime=0.0f; ServerEntity *boss = EntityHandler::getServerEntity(this->bossId); if(boss != NULL) { boss->getMessageQueue()->pushOutgoingMessage(new RemoveServerEntityMessage(0, EntityHandler::getId(), boss->getId())); this->m_messageQueue->pushOutgoingMessage(new MissionMessage(this->missionName,"failed")); } } } return missionStarted; }
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; }
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())); } } } }
HypnoticStareEffect::HypnoticStareEffect(unsigned int _affectedUnit, unsigned int _casterId, int _wits) { m_affectedUnit = _affectedUnit; this->m_obb = NULL; this->m_bs = new BoundingSphere(); m_visible = false; m_type = OtherType; m_timer = _wits*2; m_mentalDamage = _wits; m_movementSpeed = EnigmaticPresenceEffect::MOVEMENT_SPEED_FACTOR*_wits; ServerEntity* affectedUnit = EntityHandler::getServerEntity(m_affectedUnit); if(affectedUnit) { ((UnitEntity*)affectedUnit)->alterMentalDamage(m_mentalDamage); ((UnitEntity*)affectedUnit)->alterMovementSpeed(m_movementSpeed); ((Enemy*)affectedUnit)->setTargetType(UnitEntity::EnemyType); this->m_messageQueue->pushOutgoingMessage(new CreateActionTargetMessage( Skill::HYPNOTIC_STARE, _casterId, affectedUnit->getId(), FLOAT3(m_timer, 0, 0))); // Set position.x to the duration so we use it as that instead mohahhaha >:D } else this->m_messageQueue->pushOutgoingMessage(new RemoveServerEntityMessage(0, EntityHandler::getId(), this->m_id)); }
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 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())); } } } } } } }