Code below has one bug: player will lose skull/pz lock, even if other players hit him. If he stops attacks, skull/pz lock will disappear after PZ_LOCK time.
It would require few changes to make it pass
pzLock = true
, when player gets attacked by other player or attacks other player. Now only killing other player or dealing damage to other player will extend
pzLock
time.
We need new condition:
CONDITION_INFIGHT_PVP
It should not be saveable in database, as its not possible to logout with PZ lock and server restart (force logout) should remove PZ lock.
C++:
void Player::addInFightTicks(bool pzLock, int32_t ticks/* = 0*/)
{
if(hasFlag(PlayerFlag_NotGainInFight) || getZone() == ZONE_PROTECTION)
return;
if(!ticks)
ticks = g_config.getNumber(ConfigManager::PZ_LOCKED);
else
ticks = std::max(-1, ticks);
if(pzLock) {
pzLocked = true;
// if given in-fight ticks are PvP related, extend pzLock time
if(Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT_PVP, ticks))
addCondition(condition);
}
if(Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, ticks))
addCondition(condition);
}
and:
C++:
void Player::onEndCondition(ConditionType_t type)
{
Creature::onEndCondition(type);
if(type == CONDITION_INFIGHT)
{
onIdleStatus();
clearAttacked();
// CONDITION_INFIGHT time should be longer or equal to CONDITION_INFIGHT_PVP
// so we don't need to remove skull here, just reset attackers and idle status
}
if(type == CONDITION_INFIGHT_PVP)
{
clearAttacked(); // this resets 'skull system' (yellow for attacking someone who killed you etc.)
pzLocked = false;
if(skull < SKULL_RED)
setSkull(SKULL_NONE);
g_game.updateCreatureSkull(this);
}
sendIcons();
}