Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #431 from cocosolos/claim-management
Browse files Browse the repository at this point in the history
Claim updates
  • Loading branch information
zircon-tpl authored Mar 26, 2020
2 parents 820f822 + 776bfee commit 285ebac
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 148 deletions.
54 changes: 27 additions & 27 deletions scripts/mixins/families/aern.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ g_mixins = g_mixins or {}
g_mixins.families = g_mixins.families or {}

g_mixins.families.aern = function(mob)
mob:addListener("DEATH", "AERN_DEATH", function(mob)
local reraises = mob:getLocalVar("AERN_RERAISE_MAX")
local curr_reraise = mob:getLocalVar("AERN_RERAISES")
if reraises == 0 then
if math.random() < 0.4 then
reraises = 1
end
end
if curr_reraise < reraises then
local dropid = mob:getDropID()
mob:setDropID(0)
local target = mob:getTarget()
local targetid = 0
if target then targetid = target:getShortID() end
mob:timer(12000, function(mob)
mob:setHP(mob:getMaxHP())
mob:setDropID(dropid)
mob:AnimationSub(3)
mob:setLocalVar("AERN_RERAISES", curr_reraise + 1)
mob:resetAI()
mob:stun(3000)
local new_target = mob:getEntity(targetid)
if new_target and mob:checkDistance(new_target) < 40 then
mob:updateClaim(new_target)
mob:updateEnmity(new_target)
mob:addListener("DEATH", "AERN_DEATH", function(mob, killer)
if killer then
local reraises = mob:getLocalVar("AERN_RERAISE_MAX")
local curr_reraise = mob:getLocalVar("AERN_RERAISES")
if reraises == 0 then
if math.random() < 0.4 then
reraises = 1
end
mob:triggerListener("AERN_RERAISE", mob, curr_reraise + 1)
end)
end
if curr_reraise < reraises then
local dropid = mob:getDropID()
mob:setDropID(0)
local target = mob:getTarget()
if target then killer = target end
mob:timer(12000, function(mob)
mob:setHP(mob:getMaxHP())
mob:setDropID(dropid)
mob:AnimationSub(3)
mob:setLocalVar("AERN_RERAISES", curr_reraise + 1)
mob:resetAI()
mob:stun(3000)
if mob:checkDistance(killer) < 40 then
mob:updateClaim(killer)
mob:updateEnmity(killer)
end
mob:triggerListener("AERN_RERAISE", mob, curr_reraise + 1)
end)
end
end
end)
end
Expand Down
2 changes: 2 additions & 0 deletions src/map/ai/controllers/mob_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ void CMobController::DoRoamTick(time_point tick)
if (PMob->GetHPP() == 100)
{
// at max health undirty exp
PMob->m_HiPCLvl = 0;
PMob->m_HiPartySize = 0;
PMob->m_giveExp = true;
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/map/ai/states/ability_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,8 @@ void CAbilityState::ApplyEnmity()
!(m_PAbility->getCE() == 0 && m_PAbility->getVE() == 0))
{
CMobEntity* mob = (CMobEntity*)PTarget;
if (!mob->CalledForHelp())
{
mob->m_OwnerID.id = m_PEntity->id;
mob->m_OwnerID.targid = m_PEntity->targid;
}
mob->updatemask |= UPDATE_STATUS;
battleutils::ClaimMob(mob, m_PEntity);
mob->PEnmityContainer->UpdateEnmity(m_PEntity, m_PAbility->getCE(), m_PAbility->getVE(), false, m_PAbility->getID() == ABILITY_CHARM);
if (mob->m_HiPCLvl < m_PEntity->GetMLevel())
mob->m_HiPCLvl = m_PEntity->GetMLevel();
}
}
else if (PTarget->allegiance == m_PEntity->allegiance)
Expand Down
16 changes: 4 additions & 12 deletions src/map/ai/states/magic_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,12 @@ void CMagicState::ApplyEnmity(CBattleEntity* PTarget, int ce, int ve)

if (!(m_PSpell->isHeal()) || m_PSpell->tookEffect()) //can't claim mob with cure unless it does damage
{
if (m_PEntity->objtype == TYPE_PC || (m_PEntity->PMaster && m_PEntity->PMaster->objtype == TYPE_PC))
{
auto claimer = m_PEntity->objtype == TYPE_PC ? m_PEntity : m_PEntity->PMaster;

if (!mob->CalledForHelp())
{
mob->m_OwnerID.id = claimer->id;
mob->m_OwnerID.targid = claimer->targid;
}
mob->updatemask |= UPDATE_STATUS;
if (PTarget->isDead())
{ // claim mob only on death (for aoe)
battleutils::ClaimMob(PTarget, m_PEntity);
}
battleutils::DirtyExp(PTarget, m_PEntity);
mob->PEnmityContainer->UpdateEnmity(m_PEntity, ce, ve);
if (mob->m_HiPCLvl < m_PEntity->GetMLevel())
mob->m_HiPCLvl = m_PEntity->GetMLevel();
enmityApplied = true;
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/map/entities/battleentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,20 @@ void CBattleEntity::Spawn()
void CBattleEntity::Die()
{
if (CBaseEntity* PKiller = GetEntity(m_OwnerID.targid))
{
static_cast<CBattleEntity*>(PKiller)->ForAlliance([this](CBattleEntity* PMember){
CCharEntity* member = static_cast<CCharEntity*>(PMember);
if (member->PClaimedMob == this)
{
member->PClaimedMob = nullptr;
}
});
PAI->EventHandler.triggerListener("DEATH", this, PKiller);
}
else
{
PAI->EventHandler.triggerListener("DEATH", this);
}
SetBattleTargetID(0);
}

Expand Down Expand Up @@ -1323,6 +1334,10 @@ void CBattleEntity::OnCastFinished(CMagicState& state, action_t& action)
luautils::OnMagicHit(this, PTarget, PSpell);
}
}
if ((!(PSpell->isHeal()) || PSpell->tookEffect()) && PActionTarget->isAlive())
{
battleutils::ClaimMob(PActionTarget, this);
}

// TODO: Pixies will probably break here, once they're added.
if (this->allegiance != PActionTarget->allegiance)
Expand Down
5 changes: 4 additions & 1 deletion src/map/entities/charentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ CCharEntity::CCharEntity()
PWideScanTarget = nullptr;

PAutomaton = nullptr;
PClaimedMob = nullptr;
PRecastContainer = std::make_unique<CCharRecastContainer>(this);
PLatentEffectContainer = new CLatentEffectContainer(this);

Expand Down Expand Up @@ -631,6 +632,7 @@ void CCharEntity::OnEngage(CAttackState& state)

void CCharEntity::OnDisengage(CAttackState& state)
{
battleutils::RelinquishClaim(this);
CBattleEntity::OnDisengage(state);
if (state.HasErrorMsg())
{
Expand Down Expand Up @@ -898,6 +900,7 @@ void CCharEntity::OnWeaponSkillFinished(CWeaponSkillState& state, action_t& acti
}
}
}
battleutils::ClaimMob(PBattleTarget, this);
}
else
{
Expand Down Expand Up @@ -1322,7 +1325,6 @@ void CCharEntity::OnRangedAttack(CRangeState& state, action_t& action)
actionTarget.messageID = 354;

battleutils::ClaimMob(PTarget, this);

hitCount = i; // end barrage, shot missed
}

Expand Down Expand Up @@ -1657,6 +1659,7 @@ void CCharEntity::Die()
else
loc.zone->PushPacket(this, CHAR_INRANGE_SELF, new CMessageBasicPacket(this, this, 0, 0, MSGBASIC_FALLS_TO_GROUND));

battleutils::RelinquishClaim(this);
Die(death_duration);
SetDeathTimestamp((uint32)time(nullptr));

Expand Down
3 changes: 2 additions & 1 deletion src/map/entities/charentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CCharEntity : public CBattleEntity
CAutomatonEntity* PAutomaton; // Automaton statistics

std::vector<CTrustEntity*> PTrusts; // Active trusts
CBattleEntity* PClaimedMob;


// Эти миссии не нуждаются в списке пройденных, т.к. клиент автоматически
Expand Down Expand Up @@ -321,7 +322,7 @@ class CCharEntity : public CBattleEntity

CItemEquipment* getEquip(SLOTTYPE slot);

void ReloadPartyInc();
void ReloadPartyInc();
void ReloadPartyDec();
bool ReloadParty();
void ClearTrusts();
Expand Down
22 changes: 12 additions & 10 deletions src/map/entities/mobentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ CMobEntity::CMobEntity()
m_EcoSystem = SYSTEM_UNCLASSIFIED;
m_Element = 0;
m_HiPCLvl = 0;
m_HiPartySize = 0;
m_THLvl = 0;
m_ItemStolen = false;

Expand Down Expand Up @@ -505,6 +506,7 @@ void CMobEntity::Spawn()
CBattleEntity::Spawn();
m_giveExp = true;
m_HiPCLvl = 0;
m_HiPartySize = 0;
m_THLvl = 0;
m_ItemStolen = false;
m_DropItemTime = 1000;
Expand Down Expand Up @@ -666,18 +668,11 @@ void CMobEntity::OnMobSkillFinished(CMobSkillState& state, action_t& action)
this->PAI->EventHandler.triggerListener("WEAPONSKILL_USE", this, PTarget, PSkill->getID(), state.GetSpentTP(), &action);
PTarget->PAI->EventHandler.triggerListener("WEAPONSKILL_TAKE", PTarget, this, PSkill->getID(), state.GetSpentTP(), &action);
}

if (objtype == TYPE_PET && PMaster && PMaster->objtype == TYPE_PC )
if (PTarget->isDead())
{
auto mob = dynamic_cast<CMobEntity *>(PTarget);
if (mob && !mob->CalledForHelp())
{
mob->m_OwnerID.id = PMaster->id;
mob->m_OwnerID.targid = PMaster->targid;
mob->updatemask |= UPDATE_STATUS; //This can go here because we only wanna call the updatemask if this happens
}
battleutils::ClaimMob(PTarget, this);
}

battleutils::DirtyExp(PTarget, this);
if (msg == 0)
{
msg = PSkill->getMsg();
Expand Down Expand Up @@ -732,6 +727,12 @@ void CMobEntity::OnMobSkillFinished(CMobSkillState& state, action_t& action)
}
PTarget->StatusEffectContainer->DelStatusEffectsByFlag(EFFECTFLAG_DETECTABLE);
}
PTarget = static_cast<CBattleEntity*>(state.GetTarget());
if (PTarget->isDead())
{
battleutils::ClaimMob(PTarget, this);
}
battleutils::DirtyExp(PTarget, this);
}

void CMobEntity::DistributeRewards()
Expand Down Expand Up @@ -1025,6 +1026,7 @@ void CMobEntity::Die()
loc.zone->PushPacket(this, CHAR_INRANGE, new CMessageBasicPacket(this, this, 0, 0, MSGBASIC_FALLS_TO_GROUND));

DistributeRewards();
m_OwnerID.clean();
}
}));
if (PMaster && PMaster->PPet == this && PMaster->objtype == TYPE_PC)
Expand Down
1 change: 1 addition & 0 deletions src/map/entities/mobentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class CMobEntity : public CBattleEntity

uint8 m_Element;
uint8 m_HiPCLvl; // Highest Level of Player Character that hit the Monster
uint8 m_HiPartySize; // Largest party size that hit the Monster
int16 m_THLvl; // Highest Level of Treasure Hunter that apply to drops
bool m_ItemStolen; // if true, mob has already been robbed. reset on respawn. also used for thf maat fight
uint16 m_Family;
Expand Down
Loading

0 comments on commit 285ebac

Please sign in to comment.