-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core/SmartAI: AI change on charmed #26065
Core/SmartAI: AI change on charmed #26065
Conversation
one thing that I wonder is if for some reason SmartAI should still stay even when charmed. |
We have SMART_EVENT_FLAG_WHILE_CHARMED (Event can occur while player controlled) And since people used that flag in every script for years without any reason and that flag was added by mass update without any reason, we don't have a clear list of creatures which indeed should have that flag, but that's a different story |
It's too many logic in PetAI for commands, I think I can close this PR. |
we can leave it open for a while as a why to discuss about the issue. it makes no sense to me that every single SAI creature doesn't change AI when charmed but it might take some time before we can merge this |
@engilas we came up with a compromise: SmartAI::OnCharmed() should schedule an AI change if there are no events with SMART_EVENT_FLAG_WHILE_CHARMED flag (since there are quests that require SAI to trigger some script stuff when charmed). This should fix the issue in most of the cases, except for some cases where we still need SAI. I don't know if there is some sort of "IsThereAnyEventWithFlag(flag)" that we can use or if we need to implement it, is that something you would like to work on or should I assign it to myself ? |
@jackpoz Yes, I can try to implement it |
@jackpoz added check for flag SMART_EVENT_FLAG_WHILE_CHARMED |
SmartAI cant go, must stay, this way smart scripts can keep control on what happens. The problem is that, as discussed here and a couple years ago, there is no implementation for PetAI-like features, like commands and such. I remember rising this myself. Nothing was finally done, left as is. |
Aaaaand I didnt read that, sorry. Feels ok I guess. |
IMHO this introduces hard to follow behaviour when writing script. A small flag in one single event can change the behaviour of the whole script! I do not like it. I can imagine someone copies an event from another script which has that flag and unintentionally changes the behaviour when charmed (even if event seems unrelated). Or the other way around: someone fix the script by changing the events and unintentionally removes the event with the flag, because it is hard to spot. Wouldn't it be better to add action SMART_ACTION_USE_SMART_AI_WHEN_CHARMED that you would use in AIIntialize method? Thanks to this, there is no way someone will miss the fact the script has such behaviour. And you can automatically at such action to all scripts where at least one event has the flag to mimic the behaviour. But in the future scripts, it will be clear user choice to decide |
Personally I treat it as temp solution because it's indeed not really what we need simply because we are checking if creature has event with CHARMED flag but it's not correct in first place because that flag is linked to action id and not to creature entry. And there should be no such flag linked to creature entry because we already know some of those charmed creatures with SAI should attack in melee and their scripts should not be disabled if charmed. SAI just should not break Charmed AI logic but since it does and breaks hundreds and thousands creatures, that solution is better than nothing. |
Still, if we want to temporary hack, then imho it is better to do it explicitly (new action) than implicitly (with event flag). |
What is the actual problem with making creature attack in melee and use SAI if charmed? Too hard to implement? This is not about flags and only about conflicts between SAI logic and Charmed logic |
I agree with @offl , this temporal solution feels the most suitable
a new event is overkill imo also the final goal is to introduce PetAI implementations into SAI, lets not forget that, just as @offl pointed out |
Guardians are not charmed. Vehicle requires that flag only if player controls vehicle. It has absolutely no impact to creatures which are mind-controlable \ enslave-able. Their default AI is blocked during mind-control \ enslave as intended and you definitely don't want to make them cast spells from their SAI or execute any other action if they are mind-controlled or enslaved. Ref #26065
} | ||
mAllEventFlags |= scriptholder.event.event_flags; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should reset mAllEventFlags before this loop in case SAI table is reloaded at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't update instance of SmartScript, instead we create new instances
TrinityCore/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
Lines 335 to 343 in bf0975f
// creature entry / guid not found in storage, create empty event list for it and increase counters | |
if (mEventMap[source_type].find(temp.entryOrGuid) == mEventMap[source_type].end()) | |
{ | |
++count; | |
SmartAIEventList eventList; | |
mEventMap[source_type][temp.entryOrGuid] = eventList; | |
} | |
// store the new event | |
mEventMap[source_type][temp.entryOrGuid].push_back(temp); |
I think the creatures still have the old version of SAI after reload
I honestly don't want to re-implement PetAI (and PossessedAI) in SmartAI, have 2 different implementation for the same logic. Charming a creature is not just about "melee attacks", there's a lot more logic into it, which is why there are AI classes that do only that. This PR is supposed to be a compromise for the time being until someone feels like untangling this mess that SmartAI is based on, with "let's reimplement everything in SmartAI implementation ignoring everything that CreatureAI already handles". I've seen this already with starting/pausing/stopping a waypoint path. An alternative could be have SmartAI instantiate PossessedAI/PetAI and call its hooks and process the SMART_EVENT_FLAG_WHILE_CHARMED events, but it's just an idea. I'm not even sure if the scripters should be able to override PossessedAI/PetAI actions but that's another story. |
we're on the same page, I agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Thanks for the PR :) |
Guardians are not charmed. Vehicle requires that flag only if player controls vehicle. It has absolutely no impact to creatures which are mind-controlable \ enslave-able. Their default AI is blocked during mind-control \ enslave as intended and you definitely don't want to make them cast spells from their SAI or execute any other action if they are mind-controlled or enslaved. Ref #26065 (cherry picked from commit c00b055)
* Fix AI refresh on charmed * Remove unnecessary refresh * Check SMART_EVENT_FLAG_WHILE_CHARMED flag (cherry picked from commit f6e52f6)
Changes proposed:
Without this change, charmed creature can't update AI.
Target branch(es): 3.3.5/master
Issues addressed:
Closes #25982 (melee attack works correctly)
Partially #23582 (part 2: Enslaved demons should be able to attcak)
Tests performed:
Built and tested with warlock's 'Enslave Demon' spell, priest's 'Mind control' spell.