bool ItemPrototypeMgr::need_broad_cast( int proto_id ) { const PropsData* proto = GetItemPrototype(proto_id); if (proto != 0) { return proto->need_broadcast(); } return false; }
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); }
void CUser::Attack(Packet & pkt) { Packet result; int16 sid = -1, tid = -1, damage, delaytime, distance; uint8 bType, bResult; CUser* pTUser = NULL; pkt >> bType >> bResult >> tid >> delaytime >> distance; // delaytime = delaytime / 100.0f; // distance = distance / 10.0f; if (isBlinking() || isDead()) return; _ITEM_TABLE *pTable = GetItemPrototype(RIGHTHAND); if (pTable == NULL) return; // If you're holding a weapon, do a client-based (ugh, do not trust!) delay check. if (pTable && (delaytime < pTable->m_sDelay || distance > pTable->m_sRange)) return; // Empty handed. else if (delaytime < 100) return; // We're attacking a player... if (tid < NPC_BAND) { pTUser = g_pMain->GetUserPtr(tid); if (pTUser == NULL || pTUser->isDead() || pTUser->isBlinking() || (pTUser->GetNation() == GetNation() && GetZoneID() != 48 /* TO-DO: implement better checks */) || !isAttackZone()) bResult = 0; else { damage = GetDamage(pTUser, NULL); if (GetZoneID() == ZONE_SNOW_BATTLE && g_pMain->m_byBattleOpen == SNOW_BATTLE) damage = 0; if (damage <= 0) bResult = 0; else { // TO-DO: Move all this redundant code into appropriate event-based methods so that all the other cases don't have to copypasta (and forget stuff). pTUser->HpChange(-damage, this); if (pTUser->isDead()) bResult = 2; ItemWoreOut(ATTACK, damage); pTUser->ItemWoreOut(DEFENCE, damage); SendTargetHP(0, tid, -damage); } } } // We're attacking an NPC... else if (tid >= NPC_BAND) { // AI hasn't loaded yet if (g_pMain->m_bPointCheckFlag == FALSE) return; CNpc *pNpc = g_pMain->m_arNpcArray.GetData(tid); if (pNpc != NULL && pNpc->isAlive() && (pNpc->GetNation() == 0 || pNpc->GetNation() == GetNation())) { result.SetOpcode(AG_ATTACK_REQ); result << bType << bResult << GetSocketID() << tid << uint16(m_sTotalHit * m_bAttackAmount / 100) << uint16(m_sTotalAc + m_sACAmount) << m_sTotalHitrate /* this is actually a float. screwed up naming... */ << m_sTotalEvasionrate /* also a float */ << m_sItemAc << m_bMagicTypeLeftHand << m_bMagicTypeRightHand << m_sMagicAmountLeftHand << m_sMagicAmountRightHand; g_pMain->Send_AIServer(&result); return; } } result.SetOpcode(WIZ_ATTACK); result << bType << bResult << GetSocketID() << tid; SendToRegion(&result); if (tid < NPC_BAND && bResult == 2 // 2 means a player died. && pTUser) { pTUser->Send(&result); TRACE("*** User Attack Dead, id=%s, result=%d, type=%d, HP=%d\n", pTUser->m_pUserData->m_id, bResult, pTUser->m_bResHpType, pTUser->m_pUserData->m_sHp); } }