-
-
Notifications
You must be signed in to change notification settings - Fork 663
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
fix: creatures revision #3263
base: main
Are you sure you want to change the base?
fix: creatures revision #3263
Changes from 2 commits
b91bb0b
a239b81
9ab939b
e190aeb
70130fa
7742ebe
c40c935
31951f6
00a5e5c
19c290b
fd1e0d5
2c6d141
7166f51
769675b
f49b6f6
4cd310b
f1f3675
b4466a7
b30fd7d
313d16d
ba4c455
a94d04f
a8a8264
4f65332
57add95
9c87ea5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1115,65 +1115,68 @@ void Monster::onThink_async() { | |
} | ||
|
||
void Monster::doAttacking(uint32_t interval) { | ||
const auto &attackedCreature = getAttackedCreature(); | ||
if (!attackedCreature || attackedCreature->isLifeless() || (isSummon() && attackedCreature.get() == this)) { | ||
return; | ||
} | ||
|
||
const auto &player = attackedCreature->getPlayer(); | ||
if (player && player->isLoginProtected()) { | ||
return; | ||
} | ||
|
||
bool updateLook = true; | ||
bool resetTicks = interval != 0; | ||
attackTicks += interval; | ||
|
||
const Position &myPos = getPosition(); | ||
const Position &targetPos = attackedCreature->getPosition(); | ||
|
||
for (const spellBlock_t &spellBlock : mType->info.attackSpells) { | ||
bool inRange = false; | ||
|
||
if (spellBlock.spell == nullptr || (spellBlock.isMelee && isFleeing())) { | ||
continue; | ||
} | ||
|
||
if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) { | ||
if (spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100))) { | ||
if (updateLook) { | ||
updateLookDirection(); | ||
updateLook = false; | ||
} | ||
|
||
minCombatValue = spellBlock.minCombatValue; | ||
maxCombatValue = spellBlock.maxCombatValue; | ||
|
||
if (spellBlock.spell == nullptr) { | ||
continue; | ||
} | ||
|
||
spellBlock.spell->castSpell(getMonster(), attackedCreature); | ||
|
||
if (spellBlock.isMelee) { | ||
extraMeleeAttack = false; | ||
} | ||
} | ||
} | ||
|
||
if (!inRange && spellBlock.isMelee) { | ||
// melee swing out of reach | ||
extraMeleeAttack = true; | ||
} | ||
} | ||
|
||
if (updateLook) { | ||
updateLookDirection(); | ||
} | ||
|
||
if (resetTicks) { | ||
attackTicks = 0; | ||
} | ||
const auto &attackedCreature = getAttackedCreature(); | ||
if (!attackedCreature || (isSummon() && attackedCreature.get() == this)) { | ||
return; | ||
} | ||
|
||
bool updateLook = true; | ||
bool resetTicks = interval != 0; | ||
attackTicks += interval; | ||
|
||
const Position &myPos = getPosition(); | ||
const Position &targetPos = attackedCreature->getPosition(); | ||
|
||
std::map<uint32_t, std::vector<const spellBlock_t*>> groupSpells; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you do this "grouping" when inserting in mType->info.attackSpells, just order the spells at the end of the insertion. Well, I believe that would be it, I analyzed it superficially. This suggestion is to mitigate the cost of always creating a map with a vector every time doAttacking is executed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The isLifeless functionality has been reintroduced, along with a new flag to ensure that spells cast using the old method remain unaffected. My optimization expertise is limited, so any assistance or suggestions for improvement would be greatly appreciated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first, you just need to check if you have the hasGroupedSpells flag and sort the attackSpells by group. I think it would be here:
It's better to ask for help from someone who understands this part, I'm not very familiar with Canary. or even do it directly in c++, it's better to look for the best approach with someone who understands this part that registers monsters through lua. |
||
|
||
for (const spellBlock_t &spellBlock : mType->info.attackSpells) { | ||
if (spellBlock.spell == nullptr || (spellBlock.isMelee && isFleeing())) { | ||
continue; | ||
} | ||
|
||
uint32_t group = spellBlock.group > 0 ? spellBlock.group : 0; | ||
bool inRange = false; | ||
|
||
if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) { | ||
if (spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100))) { | ||
groupSpells[group].push_back(&spellBlock); | ||
} | ||
} | ||
|
||
if (!inRange && spellBlock.isMelee) { | ||
extraMeleeAttack = true; // melee swing out of reach | ||
} | ||
} | ||
|
||
for (const auto &[group, spells] : groupSpells) { | ||
if (!spells.empty()) { | ||
const spellBlock_t* selectedSpell = spells[uniform_random(0, spells.size() - 1)]; | ||
|
||
if (selectedSpell) { | ||
if (updateLook) { | ||
updateLookDirection(); | ||
updateLook = false; | ||
} | ||
|
||
minCombatValue = selectedSpell->minCombatValue; | ||
maxCombatValue = selectedSpell->maxCombatValue; | ||
|
||
selectedSpell->spell->castSpell(getMonster(), attackedCreature); | ||
|
||
if (selectedSpell->isMelee) { | ||
extraMeleeAttack = false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (updateLook) { | ||
updateLookDirection(); | ||
} | ||
|
||
if (resetTicks) { | ||
attackTicks = 0; | ||
} | ||
} | ||
|
||
bool Monster::hasExtraSwing() { | ||
|
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.
why did you remove isLifeless?
#3186
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.
removing lifeless in simultaneous attacks can be make a multiple dies of creatures ... its cannot be remmoved or nedded remake this function
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.
Oops, I'll fix that.
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.
Since it will take some time to be ready, considering that all creatures will be reviewed, I will create a new flag for the creatures
hasGroupedSpells = true,
We check it in the cpp, if it is not there we will continue with the old damage logic. I am making these adjustments and at the same time publishing the changes to the creatures on my live server, this way people can already take advantage of the changes and give the necessary feedback.