Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Monster::doAttacking(uint32_t interval)
- {
- if(!attackedCreature || (isSummon() && attackedCreature == this)) {
- return;
- }
- bool result = false;
- bool updateLook = true;
- bool outOfRange = true;
- resetTicks = interval != 0;
- attackTicks += interval;
- const Position& myPos = getPosition();
- const Position& targetPos = attackedCreature->getPosition();
- for(SpellList::iterator it = mType->spellAttackList.begin(); it != mType->spellAttackList.end(); ++it){
- bool inRange = false;
- if(canUseSpell(myPos, targetPos, *it, interval, inRange)){
- //if(it->chance >= (uint32_t)random_range(1, 100)){
- bool castChance = false;
- //if monster is fleeing it has 1/3 of default chance to cast the spell
- if (isFleeing()) {
- if (it->chance >= (uint32_t)random_range(1, 300)) {
- castChance = true;
- }
- } else {
- if (it->chance >= (uint32_t)random_range(1, 100)) {
- castChance = true;
- }
- }
- if (castChance) {
- if(updateLook) {
- updateLookDirection();
- updateLook = false;
- }
- double multiplier;
- minCombatValue = (int32_t)(it->minCombatValue * multiplier);
- maxCombatValue = (int32_t)(it->maxCombatValue * multiplier);
- it->spell->castSpell(this, attackedCreature);
- if (it->isMelee) {
- lastMeleeAttack = OTSYS_TIME() + 2000;
- extraMeleeAttack = false;
- }
- #ifdef __DEBUG__
- static uint64_t prevTicks = OTSYS_TIME();
- std::clog << "doAttacking ticks: " << OTSYS_TIME() - prevTicks << std::endl;
- prevTicks = OTSYS_TIME();
- #endif
- }
- }
- if (!inRange && it->isMelee) {
- //melee swing out of reach
- extraMeleeAttack = true;
- }
- }
- if(updateLook){
- updateLookDirection();
- }
- if(resetTicks) {
- attackTicks = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment