| 1336 | |
| 1337 | |
| 1338 | void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick) |
| 1339 | { |
| 1340 | // TODO: Let plugins interfere via a hook |
| 1341 | |
| 1342 | // If it is a right click, call the entity's OnRightClicked() handler: |
| 1343 | if (!a_IsLeftClick) |
| 1344 | { |
| 1345 | class cRclkEntity : public cEntityCallback |
| 1346 | { |
| 1347 | cPlayer & m_Player; |
| 1348 | virtual bool Item(cEntity * a_Entity) override |
| 1349 | { |
| 1350 | if (cPluginManager::Get()->CallHookPlayerRightClickingEntity(m_Player, *a_Entity)) |
| 1351 | { |
| 1352 | return false; |
| 1353 | } |
| 1354 | a_Entity->OnRightClicked(m_Player); |
| 1355 | return false; |
| 1356 | } |
| 1357 | public: |
| 1358 | cRclkEntity(cPlayer & a_Player) : m_Player(a_Player) {} |
| 1359 | } Callback (*m_Player); |
| 1360 | |
| 1361 | cWorld * World = m_Player->GetWorld(); |
| 1362 | World->DoWithEntityByID(a_TargetEntityID, Callback); |
| 1363 | return; |
| 1364 | } |
| 1365 | |
| 1366 | // If it is a left click, attack the entity: |
| 1367 | class cDamageEntity : public cEntityCallback |
| 1368 | { |
| 1369 | virtual bool Item(cEntity * a_Entity) override |
| 1370 | { |
| 1371 | if (!a_Entity->GetWorld()->IsPVPEnabled()) |
| 1372 | { |
| 1373 | // PVP is disabled, disallow players hurting other players: |
| 1374 | if (a_Entity->IsPlayer()) |
| 1375 | { |
| 1376 | // Player is hurting another player which is not allowed when PVP is disabled so ignore it |
| 1377 | return true; |
| 1378 | } |
| 1379 | } |
| 1380 | a_Entity->TakeDamage(*m_Attacker); |
| 1381 | return false; |
| 1382 | } |
| 1383 | public: |
| 1384 | cPawn * m_Attacker; |
| 1385 | } Callback; |
| 1386 | |
| 1387 | Callback.m_Attacker = m_Player; |
| 1388 | |
| 1389 | cWorld * World = m_Player->GetWorld(); |
| 1390 | if (World->DoWithEntityByID(a_TargetEntityID, Callback)) |
| 1391 | { |
| 1392 | // Any kind of an attack implies food exhaustion |
| 1393 | m_Player->AddFoodExhaustion(0.3); |
| 1394 | } |
| 1395 | } |
no test coverage detected