Ezzz-dev / OTHire

OpenTibia Server for Tibia 7.72
GNU General Public License v3.0
86 stars 76 forks source link

attack speed extra delay BUG #103

Open LuisPro opened 8 years ago

LuisPro commented 8 years ago

atk speed = 2 sec ofensive exhaust = 2 sec distance_weapon_interrupt_swing = true like on rl tibia

how its works now: auto attack on 0sec0ms then i shot sd on 0sec300ms so now i broke auto attack speed and next auto attack should go on 2sec300ms but its go on ~2sec900ms (more than half second later)

how its should work: testes on rl files: auto attack on 6sec12frame, next auto attack on 8sec12frame, so next auto attack should be on 10sec12frame but i shot rune on 9sec20frame and i broke auto attack speed, and next bolt go exacly on 11sec20frame

30frame = 1000ms = 1 second

peonso commented 8 years ago

I tried to look on it some days ago, couldnt find a solution. I think it has to do with creature onThink, as if it just check for a new attack on onThink, and when you mess with the interval between attacks with any action you fuck up attack speed, because there is no trigger for a next attack on 2 seconds, it will need to wait for onThink event. I'm not sure though, just a conjecture.

LuisPro commented 8 years ago

i still think its somewhere here: https://github.com/TwistedScorpio/OTHire/blob/master/source/player.cpp#L3713

i was think its becouse of OTSYS_TIME is not count miliseconds, i got similar problem here: https://otland.net/threads/othire-use-on-yourself-use-on-target.245154/page-2#post-2385392 in manafluid case, next fluid was drinked randomly 0.01 second to 0.99 second, it depend how much time left to new second (in os.time)

and in our atk delay case its ALWAYS around 666ms delay! // edit. not always! read new posts! never 100ms.. never 200ms, never 300ms and never 900ms... always 600-733 ms delay thats why now i think its not OTSYS_TIME related.

also its happend only when we use runes with offensive exhaust like sd, explo, magic wall, fire bomb. its not happend when we use: uh, destroy field, exura vita, mana fluid.

peonso commented 7 years ago

There is no relation at all with this other Lua issue you had, that was more related to proper use of Lua, OTSYS_TIME is not related to that in any way. Try to check when doAttacking is triggered, I'm nearby sure the actual issue is that it's triggered in an interval that is not related with attack speed once there is a interrupt swing action. As if what is happening is something along this lines:

0.0 sec -> whateverTriggerDoAttacking -> attack
1.0 sec -> whateverTriggerDoAttacking -> no
2.0 sec -> whateverTriggerDoAttacking -> attack
2.3 sec -> sd, interrupt attack, next one should be 4.3 sec
3.0 sec -> whateverTriggerDoAttacking -> no
4.0 sec -> whateverTriggerDoAttacking -> no
5.0 sec -> whateverTriggerDoAttacking -> attack

As if it never triggered in the proper time. Not that the interval is 1 sec, just to give the idea.

LuisPro commented 7 years ago

https://github.com/TwistedScorpio/OTHire/blob/master/source/player.cpp#L3743

if(!hasCondition(CONDITION_EXHAUST_COMBAT)){ result = weapon->useWeapon(this, tool, attackedCreature); }

Its clear say if not combat exhausted (2 sec in config) use weapon. And this shit is always do after ~2.66 sec.

Weird things happend when we change combat exhaust for example from 2 sec to 1.7, Its not lower our delay to 2.33. it will not change anything. Its working good, only when we decrese combat exhaust by ~0.6sec (our delay value). So when we set combat exhause in config to ~1.4sec. when we shot auto atack after sd after ~2 sec. But then out combat exhaust is focked up.

Its working like: if no combat exhaust then use weapon. How about make it to ignore combat exhaust? Something like; if ofensive rune/spell was used, sleep 2 sec. then use weapon? idk random ideas.

@up whateverTriggerDoAttacking, attackspeed trigger do attacking combat exhaust trigger delay if interrupt_swing = true its simply do if not combat exhaust then use weapons i dont know from where is that extra delay ;s

LaloHao commented 7 years ago

I think we can blame Spell::postCastSpell, it uses player->addCombatExhaust, adding the exhaust on any combat weapon.

Maybe create a different exhaust condition for magic spells?

LuisPro commented 7 years ago

There is not even single distro with this working... All developers dont give shit about this. Who care if idiots play anyway. I had same situation before, with other critical bug. Checked all distros everywhere was that bug "monsters casting spells through walls". Ekhm... Everyone got "distance_weapon_interrupt_swing = false" hardcoded to avoid this problem. And these distros are called "Real tibia ~7.7", "Cipsoft tibia" bla bla bla Someone ever play on ots with this stuff working properly? Let me know i want to check!

Hmm, i back to theory about its OTSYS_TIME() related. Becouse when i turn off interrupt. Then after shot sd, bolt got random delay (with interrupt off!) sometimes just 33ms and sometimes 966ms (depend how many time left to new second). examples with interrupt off: bolt > 2 sec > bolt bolt > 1.9 sec > sd > 0.9 sec > bolt bolt > 0.1 sec > sd > 2 sec > bolt

Then. I turn interrupt ON again and added print time in console every bolt (to more easy testing purposes, before i made video and do that on miliseconds in video editor). Then i just do observation. Results are WTF: 2017-01-24 00_38_00-d__pobrane firefox_othire-master_server exe Why when i add simple 'print attack time' this shit changed attack speed to 3 sec mostly (i dont touch anything more)(without shooting sd's) and just sometimes 2 sec. Can someone test it also to confirm it? wth is going on?

Btw. No diference, interrupt on or off, everything is wrong...

Double checked: 2017-01-24 01_04_12-d__pobrane firefox_othire-master_server exe

I again checked delays on video.. Sometimes are 200ms, sometimes 500 ms. depend on whitch moment i shoot sd beetween bolts. Before it was always ~666ms becouse i always shoot sd ~100ms before next bolt. So its next argument that it is related to otsys time.

LuisPro commented 7 years ago

May be related: https://github.com/otland/forgottenserver/pull/1305 https://github.com/otland/forgottenserver/issues/1605

diegorodriguesvieira commented 7 years ago

https://github.com/Mkalo/forgottenserver/commit/1f9a8c7b92a0beb0d65ff3413a4cd6b19190753d

LuisPro commented 7 years ago

nothing change, its just enchantment for fast attack ots's. still random delay (33ms-966ms) when i test it on rl files, in~99% delay never happen (it was perfect 2 sec to next auto attack after shot sd) and in ~1% there was 1 frame (33ms) delay

diegorodriguesvieira commented 7 years ago
void Player::doAttacking(uint32_t interval)
{
    if(lastAttack == 0){
        // - 1 to compensate for timer resolution etc.
        lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
    }

    // Can't attack while pacified
    if(hasCondition(CONDITION_PACIFIED))
    {
        return;
    }

    if((OTSYS_TIME() - lastAttack) >= getAttackSpeed() ){
        Item* tool = getWeapon();
        bool result = false;
        const Weapon* weapon = g_weapons->getWeapon(tool);
        uint32_t delay = getAttackSpeed();

        if(weapon){
            if(!weapon->interruptSwing()){
                result = weapon->useWeapon(this, tool, attackedCreature);
            }
            else if(!canDoAction()){
                delay = getNextActionTime();
            }
            else {
                // If the player is not exhausted OR if the player's weapon
                // does not have hasExhaust, use the weapon.
                if(!hasCondition(CONDITION_EXHAUST_COMBAT))
                {
                    result = weapon->useWeapon(this, tool, attackedCreature);
                }
            }
        }
        else{
            result = Weapon::useFist(this, attackedCreature);
        }

        SchedulerTask* task = createSchedulerTask(50, boost::bind(&Game::checkCreatureAttack,
                                                    &g_game, getID()));
                                                    setNextActionTask(task);

        if(result){
            lastAttack = OTSYS_TIME();
        }
    }
}

@LuisPro this works?

LuisPro commented 7 years ago

@diegorodriguesvieira yes looks rly nice, good job, works great, like on rl tibia mostly there is no delay or 33 ms (1 frame) delay like on rl tibia. sometimes 66 ms (2 frame) delay. and rare max delay i observed was 99 ms (3 frames) what is preety acceptable i think

diegorodriguesvieira commented 7 years ago

@peonso I'll make a pull request later. thanks!

diegorodriguesvieira commented 7 years ago

@peonso see here, https://github.com/otland/forgottenserver/pull/2109

diegorodriguesvieira commented 7 years ago

https://github.com/otland/forgottenserver/pull/2109/commits

peonso commented 7 years ago

160

peonso commented 7 years ago

Just updating the issue to say it's totally what I said earlier, since attacks are triggered on onThink event, things won't be correctly synchronized. onThink event will happens always each second despite some other event that should need it to resync at a different time frame.

Roniox12 commented 3 years ago

Good Morning,

Dear @peonso,

Can you convert this fix https://github.com/otland/forgottenserver/pull/2109 into OTHire? There are some difference e.g in configmanager.cpp there are all on "m_confInteger" not "boolean" and in luascript.cpp there aren't any line with "registerEnumIn". Thanks in advance