int32_t Creature::getStepDuration(Direction dir) const { if(dir == NORTHWEST || dir == NORTHEAST || dir == SOUTHWEST || dir == SOUTHEAST) return getStepDuration() << 1; return getStepDuration(); }
void Creature::updateWalkAnimation(int totalPixelsWalked) { // update outfit animation if(m_outfit.getCategory() != ThingCategoryCreature) return; int footAnimPhases = getAnimationPhases() - 1; int footDelay = getStepDuration(true) / 3; // Since mount is a different outfit we need to get the mount animation phases if(m_outfit.getMount() != 0) { ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory()); footAnimPhases = type->getAnimationPhases() - 1; } if(footAnimPhases == 0) m_walkAnimationPhase = 0; else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= footDelay && totalPixelsWalked < 32) { m_footStep++; m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases); m_footStepDrawn = false; m_footTimer.restart(); } else if(m_walkAnimationPhase == 0 && totalPixelsWalked < 32) { m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases); } if(totalPixelsWalked == 32 && !m_walkFinishAnimEvent) { auto self = static_self_cast<Creature>(); m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] { if(!self->m_walking || self->m_walkTimer.ticksElapsed() >= self->getStepDuration(true)) self->m_walkAnimationPhase = 0; self->m_walkFinishAnimEvent = nullptr; }, std::min<int>(footDelay, 200)); } }
void LocalPlayer::updateWalk() { int stepDuration = getStepDuration(); float walkTicksPerPixel = getStepDuration(true) / 32.0f; int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); // update walk animation and offsets updateWalkAnimation(totalPixelsWalked); updateWalkOffset(totalPixelsWalked); updateWalkingTile(); // terminate walk only when client and server side walk are completed if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= stepDuration) terminateWalk(); }
bool LocalPlayer::canWalk(Otc::Direction direction) { // cannot walk while locked if(m_walkLockExpiration != 0 && g_clock.millis() < m_walkLockExpiration) return false; // paralyzed if(m_speed == 0) return false; // last walk is not done yet if((m_walkTimer.ticksElapsed() < getStepDuration()) && !isAutoWalking()) return false; // prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration() + PREWALK_TIMEOUT; // avoid doing more walks than wanted when receiving a lot of walks from server if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted) return false; // cannot walk while already walking if((m_walking && !isAutoWalking()) && (!prewalkTimeouted || m_secondPreWalk)) return false; return true; }
int32_t Creature::getWalkDelay() const { if(lastStep) return getStepDuration() - (OTSYS_TIME() - lastStep); return 0; }
int64_t Creature::getStepDuration(Direction dir) const { int64_t stepDuration = getStepDuration(); if ((dir & DIRECTION_DIAGONAL_MASK) != 0) { stepDuration *= 3; } return stepDuration; }
void Creature::updateWalk() { float walkTicksPerPixel = getStepDuration(true) / 32; int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); // needed for paralyze effect m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked); // update walk animation and offsets updateWalkAnimation(totalPixelsWalked); updateWalkOffset(m_walkedPixels); updateWalkingTile(); // terminate walk if(m_walking && m_walkTimer.ticksElapsed() >= getStepDuration()) terminateWalk(); }
int64_t Creature::getEventStepTicks() const { int64_t ret = getWalkDelay(); if(ret > 0) return ret; return getStepDuration(); }
int64_t Creature::getStepDuration(Direction dir) const { int64_t stepDuration = getStepDuration(); if (dir == NORTHWEST || dir == NORTHEAST || dir == SOUTHWEST || dir == SOUTHEAST) { stepDuration *= 3; } return stepDuration; }
int32_t Creature::getWalkDelay(Direction dir) const { if (lastStep == 0) { return 0; } int64_t ct = OTSYS_TIME(); int64_t stepDuration = getStepDuration(dir); return stepDuration - (ct - lastStep); }
int32_t Creature::getWalkDelay() const { //Used for auto-walking if (lastStep == 0) { return 0; } int64_t ct = OTSYS_TIME(); int64_t stepDuration = getStepDuration() * lastStepCost; return stepDuration - (ct - lastStep); }
int64_t Creature::getEventStepTicks(bool onlyDelay/* = false*/) const { int64_t ret = getWalkDelay(); if(ret > 0) return ret; if(!onlyDelay) return getStepDuration(); return 1; }
int64_t Creature::getEventStepTicks(bool onlyDelay) const { int64_t ret = getWalkDelay(); if (ret <= 0) { int64_t stepDuration = getStepDuration(); if (onlyDelay && stepDuration > 0) { ret = 1; } else { ret = stepDuration * lastStepCost; } } return ret; }
void Creature::updateWalkAnimation(int totalPixelsWalked) { // update outfit animation if(m_outfit.getCategory() != ThingCategoryCreature) return; int footAnimPhases = getAnimationPhases() - 1; if(totalPixelsWalked == 32 || footAnimPhases == 0) m_walkAnimationPhase = 0; else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= getStepDuration() / 4 ) { m_footStep++; m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases); m_footStepDrawn = false; m_footTimer.restart(); } }
void Creature::nextWalkUpdate() { // remove any previous scheduled walk updates if(m_walkUpdateEvent) m_walkUpdateEvent->cancel(); // do the update updateWalk(); // schedules next update if(m_walking) { auto self = static_self_cast<Creature>(); m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { self->m_walkUpdateEvent = nullptr; self->nextWalkUpdate(); }, getStepDuration() / 32); } }
void LocalPlayer::preWalk(Otc::Direction direction) { Position newPos = m_position.translatedToDirection(direction); // avoid reanimating prewalks if(m_preWalking && m_lastPrewalkDestionation == newPos) return; m_waitingWalkPong = false; if(m_walkPingTimer.ticksElapsed() > getStepDuration() && m_idleTimer.ticksElapsed() > getStepDuration()*2) { m_waitingWalkPong = true; m_walkPingTimer.restart(); } m_preWalking = true; if(m_autoWalkEndEvent) m_autoWalkEndEvent->cancel(); // start walking to direction m_lastPrewalkDone = false; m_lastPrewalkDestionation = newPos; Creature::walk(m_position, newPos); }