bool GossipSelect(Player* player, uint32 /*menuId*/, uint32 /*gossipListId*/) override { CloseGossipMenuFor(player); me->StopMoving(); StartFight(player); return true; }
/*********************************************************** hurt life ***********************************************************/ void NPCHandler::HurtLife(float amount, bool UseArmor, int HurtingActorType, Ice::Long HurtingActorId, bool forcelooselife) { if(!_aggresive) return; //check if can be hurt bool force = forcelooselife && _agentState->IsHurt(); if(!force && _agentState->IsImmuneHurt()) return; #ifdef _DEBUG_NPC_ filecheck<<SynchronizedTimeHandler::GetTimeString()<<" "<<"hurted by player"<<std::endl; #endif //target hurting player if((HurtingActorType == 2) && (HurtingActorId >= 0)) { StartFight(HurtingActorId); // add to hurt list if(std::find(_hurtingplayers.begin(), _hurtingplayers.end(), HurtingActorId) == _hurtingplayers.end()) _hurtingplayers.push_back(HurtingActorId); } if(!ChangeState(2)) // check if already hurt return; //remove armor if(UseArmor) amount += _armor; // if no hit then do nothing if(amount >= 0) return; // if not invincible if(_lifeinfo.MaxLife > 0) { //substract life _lifeinfo.CurrentLife += amount; if(_lifeinfo.CurrentLife <= 0) { _lifeinfo.CurrentLife = 0; Die(); } else { if(amount < -19.9) PlayHurt(3); else if(amount < -9.9) PlayHurt(2); else PlayHurt(1); } } }
/*********************************************************** check trigger on player move ***********************************************************/ void NPCHandler::PlayerMoved(Ice::Long PlayerId, const LbaNet::PlayerPosition &startposition, const LbaNet::PlayerPosition &endposition, const LbaNet::ModelState & state, const std::string & mode, bool cantarget) { if(!_fightscriptrunning && _aggresive && _agentState->CanChase() && cantarget) { boost::shared_ptr<PhysicalObjectHandlerBase> physo = _character->GetPhysicalObject(); if(!physo) return; // get current position float px, py, pz; physo->GetPosition(px, py, pz); bool conditionpassed = true; if(_attack_activation_condition && m_scripthandler) conditionpassed = _attack_activation_condition->Passed(m_scripthandler, 2, PlayerId); if(conditionpassed) { bool target = ShouldAttackPlayer(px, py, pz, endposition.X, endposition.Y, endposition.Z, state, mode); if(target) StartFight(PlayerId); } } if(_targetedattackplayer == PlayerId) { // record last position _lasttargetposition = endposition; // check if target out of reach if(_stop_attack_distance > 0) { boost::shared_ptr<PhysicalObjectHandlerBase> physo = _character->GetPhysicalObject(); if(!physo) return; // get current position float px, py, pz; physo->GetPosition(px, py, pz); float dx = (endposition.X - px); float dy = (endposition.Y - py); float dz = (endposition.Z - pz); float diff = dx*dx + dy*dy + dz*dz; if(diff >= (_stop_attack_distance*_stop_attack_distance)) { //stop target player UntargetAttackPlayer(PlayerId); return; } } //move chasing target if(_agentState->IsChasing()) { float diff = fabs(startposition.X - endposition.X) + fabs(startposition.Y - endposition.Y) + fabs(startposition.Z - endposition.Z); if(diff > 0.001 && m_NavMAgent) m_NavMAgent->SetTargetPosition(true, endposition.X, endposition.Y, endposition.Z); } } }
/*********************************************************** target player ***********************************************************/ void NPCHandler::ForceTargetAttackPlayer(Ice::Long PlayerId) { StartFight(PlayerId); }