void LocalPlayer::setHealth(double health, double maxHealth) { if(m_health != health || m_maxHealth != maxHealth) { double oldHealth = m_health; double oldMaxHealth = m_maxHealth; m_health = health; m_maxHealth = maxHealth; callLuaField("onHealthChange", health, maxHealth, oldHealth, oldMaxHealth); // cannot walk while dying if(health == 0) { if(isPreWalking()) stopWalk(); lockWalk(); } } }
void CreatureUI::Blit(int x, int y, float scale, int map_x, int map_y) const { if (!m_obj) return; if(map_x != 0 && map_y != 0) { x = x - std::floor(m_obj->xOffset * scale); y = y - std::floor(m_obj->yOffset * scale); } else { // shrink larger creatures to be 32x32 scale *= (32.f/(float)m_obj->rendersize); } if (!isLoaded()) { printf("Not loaded!\n"); return; } uint32_t activeframe = 0; uint32_t spriteSize, partSize, aniSize; spriteSize = m_obj->width * m_obj->height * m_obj->blendframes; partSize = spriteSize * m_obj->xdiv; aniSize = partSize * m_obj->ydiv; Creature* n = (Creature*)this; if(n->getOutfit().m_looktype != 0){ if(map_x != 0 && map_y != 0) activeframe = ((m_walkState == 1. && !isPreWalking()) ? n->getTurnDir() : n->getLookDir()) * spriteSize; // creature must have different turning direction and looking (moving) direction... if moving, moving direction takes precendence, if standing, turning direction takes precendence else activeframe = DIRECTION_SOUTH * spriteSize; } float walkoffx = 0.f, walkoffy = 0.f; if(map_x != 0 && map_y != 0) { getWalkOffset(walkoffx, walkoffy, scale); } //for(uint32_t k = 0; k < m_obj->blendframes; ++k){ // note: if it's anything except item, there won't be blendframes... { uint32_t aframes; if(m_obj->animcount == 3 && (map_x != 0 && map_y != 0)){ aframes = aniSize * (m_walkState == 1. ? 0 : (((int)(m_walkState*100) / 25) % 2 + 1)); } else if(m_obj->idleAnim){ // TODO (nfries88): all appearances that animate while idle. //aframes = 0; uint32_t animationTime = (g_frameTime - m_startTime)/100; aframes = 0;/*(map_x % m_obj->xdiv + (map_y % m_obj->ydiv)*m_obj->xdiv + (animationTime % m_obj->animcount)*m_obj->xdiv*m_obj->ydiv)* spriteSize;*/ } else if(n->getOutfit().m_looktype == 0 && n->getOutfit().m_lookitem == 0){ uint32_t animationTime = (g_frameTime - m_startTime)/100; aframes = (map_x % m_obj->xdiv + (map_y % m_obj->ydiv)*m_obj->xdiv + (animationTime % m_obj->animcount)*m_obj->xdiv*m_obj->ydiv)* spriteSize; activeframe = 0; } else { aframes = 0; } //Square around the creature if(g_frameTime - n->getSquareStart() < 1000){ g_engine->drawRectangleLines(x + walkoffx, y + walkoffy, 32*scale, 32*scale, oRGBA(0,0,0,0)); } //Red square around the attacked creature if(n->getID() == GlobalVariables::getAttackID()) { // "Faded Red" - right color. (Verified) g_engine->drawRectangleLines((x+1) + walkoffx, (y+1) + walkoffy, 32*scale, 32*scale, oRGBA(224, 64, 64, 255), 2*scale); } //Green square around the followed creature else if(n->getID() == GlobalVariables::getFollowID()) { // "Light Green" - right color. (Verified) g_engine->drawRectangleLines((x+2) + walkoffx, (y+2) + walkoffy, 32*scale, 32*scale, oRGBA(64, 224, 64, 255), 2*scale); } // "Creature Squares" sent by the server if((map_x != 0 && map_y != 0) && (n->getSquareStart() + 1000) >= g_frameTime) { g_engine->drawRectangleLines(x + walkoffx, y + walkoffy, 34*scale, 34*scale, n->getSquareColor(), 2*scale); } for(uint32_t i = 0; i < m_obj->height; ++i){ for(uint32_t j = 0; j < m_obj->width; ++j){ ASSERT(activeframe + aframes < m_obj->numsprites); int draw_x = (int)(x - j*32*scale + walkoffx); int draw_y = (int)(y - i*32*scale + walkoffy); if (m_gfx[activeframe + aframes]) m_gfx[activeframe + aframes]->Blit(draw_x, draw_y, 0, 0, 32, 32, 32*scale, 32*scale); else printf("Warning: rendering creature failed since sprite %d is NULL\n", activeframe+aframes); if(m_obj->ydiv != 1){ if(n->getOutfit().m_addons & 1){ m_gfx[activeframe + partSize + aframes]->Blit(draw_x, draw_y, 0, 0, 32, 32, 32*scale, 32*scale); } if(n->getOutfit().m_addons & 2){ m_gfx[activeframe + partSize*2 + aframes]->Blit(draw_x, draw_y, 0, 0, 32, 32, 32*scale, 32*scale); } } activeframe++; } } } }