[Door Opening] Rule to let configure Animal Door Opening (#1231)

* Add rule configuration for letting animals open doors or not

* Handle one more spot

* Make adjustments and add mob property that serves as a check as to whether a mob entity can open doors or not

* Push attribute to mob window
This commit is contained in:
Chris Miles 2021-02-07 19:52:58 -06:00 committed by GitHub
parent 672c09ee11
commit 694d380e66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 44 deletions

View File

@ -531,6 +531,7 @@ RULE_INT(NPC, NPCGateDistanceBind, 75, "Distance from bind before NPC will attem
RULE_BOOL(NPC, NPCHealOnGate, true, "Will the NPC Heal on Gate")
RULE_BOOL(NPC, UseMeditateBasedManaRegen, false, "Based NPC ooc regen on Meditate skill")
RULE_REAL(NPC, NPCHealOnGateAmount, 25, "How much the NPC will heal on gate if enabled")
RULE_BOOL(NPC, AnimalsOpenDoors, true, "Determines or not whether animals open doors or not when they approach them")
RULE_CATEGORY_END()
RULE_CATEGORY(Aggro)

View File

@ -3604,18 +3604,21 @@ void EntityList::AddHealAggro(Mob *target, Mob *caster, uint16 hate)
void EntityList::OpenDoorsNear(Mob *who)
{
if (!who->CanOpenDoors()) {
return;
}
for (auto it = door_list.begin();it != door_list.end(); ++it) {
Doors *cdoor = it->second;
if (!cdoor || cdoor->IsDoorOpen())
for (auto &it : door_list) {
Doors *door = it.second;
if (!door || door->IsDoorOpen()) {
continue;
}
auto diff = who->GetPosition() - cdoor->GetPosition();
float curdist = diff.x * diff.x + diff.y * diff.y;
if (diff.z * diff.z < 10 && curdist <= 100)
cdoor->Open(who);
auto diff = who->GetPosition() - door->GetPosition();
float distance = diff.x * diff.x + diff.y * diff.y;
if (diff.z * diff.z < 10 && distance <= 100) {
door->Open(who);
}
}
}

View File

@ -464,6 +464,8 @@ Mob::Mob(
#endif
mob_close_scan_timer.Trigger();
SetCanOpenDoors(true);
}
Mob::~Mob()
@ -5960,3 +5962,13 @@ float Mob::HealRotationExtendedHealFrequency()
return m_target_of_heal_rotation->ExtendedHealFrequency(this);
}
#endif
bool Mob::CanOpenDoors() const
{
return m_can_open_doors;
}
void Mob::SetCanOpenDoors(bool can_open)
{
m_can_open_doors = can_open;
}

View File

@ -1194,6 +1194,9 @@ public:
int32 GetHPRegen() const;
int32 GetManaRegen() const;
bool CanOpenDoors() const;
void SetCanOpenDoors(bool can_open);
#ifdef BOTS
// Bots HealRotation methods
@ -1587,12 +1590,15 @@ protected:
AuraMgr aura_mgr;
AuraMgr trap_mgr;
bool m_can_open_doors;
MobMovementManager *mMovementManager;
private:
void _StopSong(); //this is not what you think it is
Mob* target;
#ifdef BOTS
std::shared_ptr<HealRotation> m_target_of_heal_rotation;

View File

@ -442,7 +442,11 @@ void Mob::AI_Start(uint32 iMoveDelay) {
AI_movement_timer = std::unique_ptr<Timer>(new Timer(AImovement_duration));
AI_target_check_timer = std::unique_ptr<Timer>(new Timer(AItarget_check_duration));
AI_feign_remember_timer = std::unique_ptr<Timer>(new Timer(AIfeignremember_delay));
AI_scan_door_open_timer = std::unique_ptr<Timer>(new Timer(AI_scan_door_open_interval));
AI_scan_door_open_timer = std::make_unique<Timer>(AI_scan_door_open_interval);
if (GetBodyType() == BT_Animal && !RuleB(NPC, AnimalsOpenDoors)) {
SetCanOpenDoors(false);
}
if(!RuleB(Aggro, NPCAggroMaxDistanceEnabled)) {
hate_list_cleanup_timer.Disable();
@ -978,23 +982,25 @@ void Mob::AI_Process() {
engaged = false;
}
if (moving) {
if (moving && CanOpenDoors()) {
if (AI_scan_door_open_timer->Check()) {
auto &door_list = entity_list.GetDoorsList();
for (auto itr : door_list) {
Doors *door = itr.second;
if (door->GetKeyItem())
if (door->GetKeyItem()) {
continue;
}
if (door->GetLockpick())
if (door->GetLockpick()) {
continue;
}
if (door->IsDoorOpen())
if (door->IsDoorOpen()) {
continue;
}
float distance = DistanceSquared(this->m_Position, door->GetPosition());
float distance = DistanceSquared(m_Position, door->GetPosition());
float distance_scan_door_open = 20;
if (distance <= (distance_scan_door_open * distance_scan_door_open)) {
@ -1003,8 +1009,9 @@ void Mob::AI_Process() {
* Make sure we're opening a door within height relevance and not platforms
* above or below
*/
if (std::abs(this->m_Position.z - door->GetPosition().z) > 10)
if (std::abs(this->m_Position.z - door->GetPosition().z) > 10) {
continue;
}
door->ForceOpen(this);
}

View File

@ -225,6 +225,10 @@ inline std::string GetMobAttributeByString(Mob *mob, const std::string &attribut
return std::to_string(mob->GetMaxBuffSlots());
}
if (attribute == "can_open_doors") {
return std::to_string(mob->CanOpenDoors());
}
if (attribute == "curbuffslots") {
return std::to_string(mob->GetCurrentBuffSlots());
}
@ -770,6 +774,7 @@ void Mob::DisplayInfo(Mob *mob)
"spells_id",
"curbuffslots",
"maxbuffslots",
"can_open_doors",
};
window_text += WriteDisplayInfoSection(mob, "NPC Attributes", npc_attributes, 1, true);

View File

@ -409,6 +409,11 @@ NPC::NPC(const NPCType *npc_type_data, Spawn2 *in_respawn, const glm::vec4 &posi
AISpellVar.idle_no_sp_recast_min = static_cast<uint32>(RuleI(Spells, AI_IdleNoSpellMinRecast));
AISpellVar.idle_no_sp_recast_max = static_cast<uint32>(RuleI(Spells, AI_IdleNoSpellMaxRecast));
AISpellVar.idle_beneficial_chance = static_cast<uint8> (RuleI(Spells, AI_IdleBeneficialChance));
if (GetBodyType() == BT_Animal && !RuleB(NPC, AnimalsOpenDoors)) {
m_can_open_doors = false;
}
}
float NPC::GetRoamboxMaxX() const

View File

@ -643,7 +643,6 @@ private:
bool skip_global_loot;
bool skip_auto_scale;
bool p_depop;
};
#endif