void Item::drawToImage(Point dest, ImagePtr image) { if(m_clientId == 0) return; int xPattern = 0, yPattern = 0, zPattern = 0; calculatePatterns(xPattern, yPattern, zPattern); rawGetThingType()->drawToImage(dest, xPattern, yPattern, zPattern, image); }
void Effect::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView) { if(m_id == 0) return; int animationPhase = 0; if(animate) animationPhase = std::min((int)(m_animationTimer.ticksElapsed() / m_phaseDuration), getAnimationPhases() - 1); rawGetThingType()->draw(dest, scaleFactor, 0, 0, 0, 0, animationPhase, lightView); }
void Item::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView) { if(m_clientId == 0) return; // determine animation phase int animationPhase = calculateAnimationPhase(animate); // determine x,y,z patterns int xPattern = 0, yPattern = 0, zPattern = 0; calculatePatterns(xPattern, yPattern, zPattern); rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase, lightView); }
void Effect::draw(const Point& dest, float scaleFactor, bool animate, int offsetX, int offsetY, LightView *lightView) { if(m_id == 0) return; int animationPhase = 0; if(animate) animationPhase = std::min<int>((int)(m_animationTimer.ticksElapsed() / m_phaseDuration), getAnimationPhases() - 1); int xPattern = offsetX % getNumPatternX(); if(xPattern < 0) xPattern += getNumPatternX(); int yPattern = offsetY % getNumPatternY(); if(yPattern < 0) yPattern += getNumPatternY(); rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, 0, animationPhase, lightView); }
void Item::draw(const Point& dest, float scaleFactor, bool animate) { if(m_clientId == 0) return; // determine animation phase int animationPhase = calculateAnimationPhase(animate); if(getAnimationPhases() > 1) { if(animate) animationPhase = (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME; else animationPhase = getAnimationPhases()-1; } // determine x,y,z patterns int xPattern = 0, yPattern = 0, zPattern = 0; calculatePatterns(xPattern, yPattern, zPattern); rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase); }
void Item::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView) { if(m_clientId == 0) return; // determine animation phase int animationPhase = calculateAnimationPhase(animate); // determine x,y,z patterns int xPattern = 0, yPattern = 0, zPattern = 0; calculatePatterns(xPattern, yPattern, zPattern); if(m_color != Color::alpha) g_painter->setColor(m_color); rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase, lightView); /// Sanity check /// This is just to ensure that we don't overwrite some color and /// screw up the whole rendering. if(m_color != Color::alpha) g_painter->resetColor(); }
void Creature::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView) { if(!canBeSeen()) return; Point animationOffset = animate ? m_walkOffset : Point(0,0); if(m_showTimedSquare && animate) { g_painter->setColor(m_timedSquareColor); g_painter->drawBoundingRect(Rect(dest + (animationOffset - getDisplacement() + 2)*scaleFactor, Size(28, 28)*scaleFactor), std::max<int>((int)(2*scaleFactor), 1)); g_painter->setColor(Color::white); } if(m_showStaticSquare && animate) { g_painter->setColor(m_staticSquareColor); g_painter->drawBoundingRect(Rect(dest + (animationOffset - getDisplacement())*scaleFactor, Size(Otc::TILE_PIXELS, Otc::TILE_PIXELS)*scaleFactor), std::max<int>((int)(2*scaleFactor), 1)); g_painter->setColor(Color::white); } internalDrawOutfit(dest + animationOffset * scaleFactor, scaleFactor, animate, animate, m_direction); m_footStepDrawn = true; if(lightView) { Light light = rawGetThingType()->getLight(); if(m_light.intensity != light.intensity || m_light.color != light.color) light = m_light; // local player always have a minimum light in complete darkness if(isLocalPlayer() && (g_map.getLight().intensity < 64 || m_position.z > Otc::SEA_FLOOR)) { light.intensity = std::max<uint8>(light.intensity, 3); if(light.color == 0 || light.color > 215) light.color = 215; } if(light.intensity > 0) lightView->addLightSource(dest + (animationOffset + Point(16,16)) * scaleFactor, scaleFactor, light); } }
void Missile::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView) { if(m_id == 0 || !animate) return; int xPattern = 0, yPattern = 0; if(m_direction == Otc::NorthWest) { xPattern = 0; yPattern = 0; } else if(m_direction == Otc::North) { xPattern = 1; yPattern = 0; } else if(m_direction == Otc::NorthEast) { xPattern = 2; yPattern = 0; } else if(m_direction == Otc::East) { xPattern = 2; yPattern = 1; } else if(m_direction == Otc::SouthEast) { xPattern = 2; yPattern = 2; } else if(m_direction == Otc::South) { xPattern = 1; yPattern = 2; } else if(m_direction == Otc::SouthWest) { xPattern = 0; yPattern = 2; } else if(m_direction == Otc::West) { xPattern = 0; yPattern = 1; } else { xPattern = 1; yPattern = 1; } float fraction = m_animationTimer.ticksElapsed() / m_duration; rawGetThingType()->draw(dest + m_delta * fraction * scaleFactor, scaleFactor, 0, xPattern, yPattern, 0, 0, lightView); }
bool Item::isGround() { return rawGetThingType()->isGround(); }
bool Item::isMoveable() { return !rawGetThingType()->isNotMoveable(); }
void Creature::internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction) { // outfit is a real creature if(m_outfit.getCategory() == ThingCategoryCreature) { int animationPhase = animateWalk ? m_walkAnimationPhase : 0; if(isAnimateAlways() && animateIdle) { int ticksPerFrame = 1000 / getAnimationPhases(); animationPhase = (g_clock.millis() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame; } // xPattern => creature direction int xPattern; if(direction == Otc::NorthEast || direction == Otc::SouthEast) xPattern = Otc::East; else if(direction == Otc::NorthWest || direction == Otc::SouthWest) xPattern = Otc::West; else xPattern = direction; int zPattern = 0; if(m_outfit.getMount() != 0) { auto datType = g_things.rawGetThingType(m_outfit.getMount(), ThingCategoryCreature); dest -= datType->getDisplacement() * scaleFactor; datType->draw(dest, scaleFactor, 0, xPattern, 0, 0, animationPhase); dest += getDisplacement() * scaleFactor; zPattern = 1; } // yPattern => creature addon for(int yPattern = 0; yPattern < getNumPatternY(); yPattern++) { // continue if we dont have this addon if(yPattern > 0 && !(m_outfit.getAddons() & (1 << (yPattern-1)))) continue; auto datType = rawGetThingType(); datType->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase); if(getLayers() > 1) { Color oldColor = g_painter->getColor(); Painter::CompositionMode oldComposition = g_painter->getCompositionMode(); g_painter->setCompositionMode(Painter::CompositionMode_Multiply); g_painter->setColor(m_outfit.getHeadColor()); datType->draw(dest, scaleFactor, SpriteMaskYellow, xPattern, yPattern, zPattern, animationPhase); g_painter->setColor(m_outfit.getBodyColor()); datType->draw(dest, scaleFactor, SpriteMaskRed, xPattern, yPattern, zPattern, animationPhase); g_painter->setColor(m_outfit.getLegsColor()); datType->draw(dest, scaleFactor, SpriteMaskGreen, xPattern, yPattern, zPattern, animationPhase); g_painter->setColor(m_outfit.getFeetColor()); datType->draw(dest, scaleFactor, SpriteMaskBlue, xPattern, yPattern, zPattern, animationPhase); g_painter->setColor(oldColor); g_painter->setCompositionMode(oldComposition); } } // outfit is a creature imitating an item or the invisible effect } else { ThingType *type = g_things.rawGetThingType(m_outfit.getAuxId(), m_outfit.getCategory()); int animationPhase = 0; int animationPhases = type->getAnimationPhases(); int animateTicks = Otc::ITEM_TICKS_PER_FRAME; // when creature is an effect we cant render the first and last animation phase, // instead we should loop in the phases between if(m_outfit.getCategory() == ThingCategoryEffect) { animationPhases = std::max(1, animationPhases-2); animateTicks = Otc::INVISIBLE_TICKS_PER_FRAME; } if(animationPhases > 1) { if(animateIdle) animationPhase = (g_clock.millis() % (animateTicks * animationPhases)) / animateTicks; else animationPhase = animationPhases-1; } if(m_outfit.getCategory() == ThingCategoryEffect) animationPhase = std::min(animationPhase+1, animationPhases); type->draw(dest - (getDisplacement() * scaleFactor), scaleFactor, 0, 0, 0, 0, animationPhase); } }