void Creature::addVolatileSquare(uint8 color) { m_showVolatileSquare = true; m_volatileSquareColor = Color::from8bit(color); // schedule removal auto self = asCreature(); g_dispatcher.scheduleEvent([self]() { self->removeVolatileSquare(); }, VOLATILE_SQUARE_DURATION); }
void Creature::updateShield() { m_showShieldTexture = !m_showShieldTexture; if(m_shield != Otc::ShieldNone && m_shieldBlink) { auto self = asCreature(); g_dispatcher.scheduleEvent([self]() { self->updateShield(); }, SHIELD_BLINK_TICKS); } else if(!m_shieldBlink) m_showShieldTexture = true; }
void Creature::setShieldTexture(const std::string& filename, bool blink) { m_shieldTexture = g_textures.getTexture(filename); m_showShieldTexture = true; if(blink && !m_shieldBlink) { auto self = asCreature(); g_dispatcher.scheduleEvent([self]() { self->updateShield(); }, SHIELD_BLINK_TICKS); } m_shieldBlink = blink; }
int Thing::getStackPriority() { if(isGround()) return 0; else if(isGroundBorder()) return 1; else if(isOnBottom()) return 2; else if(isOnTop()) return 3; else if(asCreature()) return 4; else // common items return 5; }
void Creature::cancelWalk(Otc::Direction direction) { if(m_walking) { auto self = asCreature(); g_dispatcher.scheduleEvent([=]() { if(!self->m_walking) self->m_animation = 0; }, m_walkTimePerPixel * 2); } m_walking = false; m_walkStartTicks = 0; m_walkOffset.x = 0; m_walkOffset.y = 0; m_direction = direction; }
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 = asCreature(); m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { self->m_walkUpdateEvent = nullptr; self->nextWalkUpdate(); }, m_walkAnimationInterval / 32); } }
void Creature::updateInvisibleAnimation() { if(!g_game.isOnline() || m_outfit.getCategory() != ThingsType::Effect) return; if(m_animation == 1) m_animation = 2; else if(m_animation == 2) m_animation = 3; else if(m_animation == 3) m_animation = 1; else m_animation = 1; auto self = asCreature(); g_dispatcher.scheduleEvent([self]() { self->updateInvisibleAnimation(); }, INVISIBLE_TICKS); }
void Creature::updateWalk() { if(m_walking) { int elapsedTicks = g_clock.ticksElapsed(m_walkStartTicks); int totalPixelsWalked = std::min((int)round(elapsedTicks / m_walkTimePerPixel), 32); if(m_inverseWalking) { if(m_direction == Otc::North || m_direction == Otc::NorthEast || m_direction == Otc::NorthWest) m_walkOffset.y = 32 - totalPixelsWalked; else if(m_direction == Otc::South || m_direction == Otc::SouthEast || m_direction == Otc::SouthWest) m_walkOffset.y = totalPixelsWalked - 32; if(m_direction == Otc::East || m_direction == Otc::NorthEast || m_direction == Otc::SouthEast) m_walkOffset.x = totalPixelsWalked - 32; else if(m_direction == Otc::West || m_direction == Otc::NorthWest || m_direction == Otc::SouthWest) m_walkOffset.x = 32 - totalPixelsWalked; if(m_walkOffset.x == 0 && m_walkOffset.y == 0) cancelWalk(m_direction); } else { if(m_direction == Otc::North || m_direction == Otc::NorthEast || m_direction == Otc::NorthWest) m_walkOffset.y = -totalPixelsWalked; else if(m_direction == Otc::South || m_direction == Otc::SouthEast || m_direction == Otc::SouthWest) m_walkOffset.y = totalPixelsWalked; if(m_direction == Otc::East || m_direction == Otc::NorthEast || m_direction == Otc::SouthEast) m_walkOffset.x = totalPixelsWalked; else if(m_direction == Otc::West || m_direction == Otc::NorthWest || m_direction == Otc::SouthWest) m_walkOffset.x = -totalPixelsWalked; } int totalWalkTileTicks = (int)m_walkTimePerPixel*32 * 0.5; if(m_type->dimensions[ThingType::AnimationPhases] > 0) m_animation = (g_clock.ticks() % totalWalkTileTicks) / (totalWalkTileTicks / (m_type->dimensions[ThingType::AnimationPhases] - 1)) + 1; else m_animation = 0; g_dispatcher.scheduleEvent(std::bind(&Creature::updateWalk, asCreature()), m_walkTimePerPixel); if(totalPixelsWalked == 32) cancelWalk(m_direction); } }
void Creature::setEmblem(uint8 emblem) { m_emblem = emblem; g_lua.callGlobalField("Creature","onEmblemChange", asCreature(), m_emblem); }
void Creature::setShield(uint8 shield) { m_shield = shield; g_lua.callGlobalField("Creature","onShieldChange", asCreature(), m_shield); }
void Creature::setSkull(uint8 skull) { m_skull = skull; g_lua.callGlobalField("Creature","onSkullChange", asCreature(), m_skull); }