void CUser::Attack(Packet & pkt) { int16 sid = -1, tid = -1, damage, delaytime, distance; uint8 bType, bResult = 0; Unit * pTarget = nullptr; pkt >> bType >> bResult >> tid >> delaytime >> distance; // delaytime = delaytime / 100.0f; // distance = distance / 10.0f; if (isIncapacitated()) return; if (isInSafetyArea()) return; if (m_bInvisibilityType != INVIS_NONE) { CMagicProcess::RemoveStealth(this, INVIS_DISPEL_ON_MOVE); CMagicProcess::RemoveStealth(this, INVIS_DISPEL_ON_ATTACK); } // If you're holding a weapon, do a client-based (ugh, do not trust!) delay check. _ITEM_TABLE *pTable = GetItemPrototype(RIGHTHAND); if (pTable != nullptr) { if (delaytime < (pTable->m_sDelay + 10) // client adds 0.1 onto the interval (0.1 of 100 is 10) || distance > pTable->m_sRange) return; } // Empty handed. else if (delaytime < 100) return; pTarget = g_pMain->GetUnitPtr(tid); bResult = ATTACK_FAIL; if (pTarget != nullptr && isInAttackRange(pTarget) && CanAttack(pTarget)) { if (isAttackable(pTarget) && CanCastRHit(GetSocketID())) { if (isInTempleEventZone()) if (GetUserGroup() != -1 && !isSameUserGroup(pTarget)) return; CUser *pUser = g_pMain->GetUserPtr(GetSocketID()); if (pUser != nullptr) pUser->m_RHitRepeatList.insert(std::make_pair(GetSocketID(), UNIXTIME)); damage = GetDamage(pTarget); // Can't use R attacks in the Snow War. if (GetZoneID() == ZONE_SNOW_BATTLE && g_pMain->m_byBattleOpen == SNOW_BATTLE) damage = 0; if (damage > 0) { pTarget->HpChange(-damage, this); if (pTarget->isDead()) bResult = ATTACK_TARGET_DEAD; else bResult = ATTACK_SUCCESS; // Every attack takes a little of your weapon's durability. ItemWoreOut(ATTACK, damage); // Every hit takes a little of the defender's armour durability. if (pTarget->isPlayer()) TO_USER(pTarget)->ItemWoreOut(DEFENCE, damage); } } } Packet result(WIZ_ATTACK, bType); result << bResult << GetSocketID() << tid; SendToRegion(&result); }
//============================================================================= // // incap // void CreatureObject::incap() { // sanity check if (isIncapacitated() || isDead()) { return; } if (this->getType() == ObjType_Player) { // gLogger->logMsgF("Player incapped, mIncapCount = %u.", MSG_NORMAL, mIncapCount); // first incap, update the initial time uint64 localTime = Anh_Utils::Clock::getSingleton()->getLocalTime(); if(!mIncapCount) { mFirstIncapTime = localTime; } // reset the counter if the reset time has passed else if(mIncapCount != 0 && (localTime - mFirstIncapTime) >= gWorldConfig->getIncapResetTime() * 1000) { // gLogger->logMsgF("Time since first incap = %"PRIu64"", MSG_NORMAL, localTime - mFirstIncapTime); // gLogger->logMsgF("Resetting mFirstIncapTime", MSG_NORMAL); mIncapCount = 0; mFirstIncapTime = localTime; } /* if (mIncapCount != 0) { gLogger->logMsgF("Time since first incap = %"PRIu64"", MSG_NORMAL, localTime - mFirstIncapTime); } */ PlayerObject* player = dynamic_cast<PlayerObject*>(this); if (player) { player->disableAutoAttack(); } //See if our player is mounted -- if so dismount him if(player->checkIfMounted()) { //Get the player's mount if(Vehicle* vehicle = dynamic_cast<Vehicle*>(gWorldManager->getObjectById(player->getMount()->getPetController()))) { //Now dismount vehicle->dismountPlayer(); } } // advance incaps counter if(++mIncapCount < gWorldConfig->getConfiguration("Player_Incapacitation",3)) { // gLogger->logMsgF("Player incapped, mIncapCount set to = %u, setting timer..", MSG_NORMAL, mIncapCount); // update the posture mPosture = CreaturePosture_Incapacitated; // send timer updates mCurrentIncapTime = gWorldConfig->getBaseIncapTime() * 1000; gMessageLib->sendIncapTimerUpdate(this); // schedule recovery event mObjectController.addEvent(new IncapRecoveryEvent(),mCurrentIncapTime); // reset states mState = 0; // reset ham regeneration mHam.updateRegenRates(); gWorldManager->removeCreatureHamToProcess(mHam.getTaskId()); mHam.setTaskId(0); updateMovementProperties(); gMessageLib->sendPostureAndStateUpdate(this); if(PlayerObject* player = dynamic_cast<PlayerObject*>(this)) { gMessageLib->sendUpdateMovementProperties(player); gMessageLib->sendSelfPostureUpdate(player); } } // we hit the max -> death else { // gLogger->logMsgF("Player died.", MSG_NORMAL); die(); } } else if (this->getType() == ObjType_Creature) // A Creature. { die(); } else { gLogger->logMsgF("CreatureObject::incap Incapped unsupported type %u\n", MSG_NORMAL, this->getType()); } }