void CRole::damage(float damagePoint, CRole* attacker) { float curHP = getCurHP(); curHP = curHP - damagePoint; if (FLT_LE(curHP, 0.f)) { setCurHP(0.f); FIGHT_RELATION->removeAllRelation(dynamic_cast<IFightingRelation*>(this)); changeState(ROLE_STATE_DYING); } else { setCurHP(curHP); if (attacker) { if (getMovetarget().equals(Point(-1.f, -1.f))) { setMoveTarget(attacker->getLogicGrid()->getGridPos()); } } } m_pHPBar->setPercentage(getCurHP() / getMaxHP()); BF_MANAGER->wakeUpAllDefender(); }
FUNCTION void Q5VC(obj attacker) { obj n = createGlobalNPCAtSpecificLoc(0x0232, getLocation(this)); setHue(n, getHue(this)); int Q4XB = getCurHP(this); Q4XB = Q4XB / 0x02; setCurHP(n, Q4XB); setCurHP(this, Q4XB); attack(n, attacker); sfx(getLocation(this), random(0x01C8, 0x01CC), 0x00); bark(n, "*The slime splits when struck!*"); return; }
bool CRole::init(const string& unitId, bool editorMode) { do { m_isEditMode = editorMode; BREAK_IF(!CSpriteObject::init()); m_faceToPrefix.resize(FACE_TO_MAX); m_faceToPrefix[FACE_TO_LEFT_DOWN] = ROLE_FACE_TO_LEFT_PREFIX; m_faceToPrefix[FACE_TO_RIGHT_DOWN] = ROLE_FACE_TO_RIGHT_PREFIX; m_faceToPrefix[FACE_TO_LEFT_UP] = ROLE_BACK_TO_LEFT_PREFIX; m_faceToPrefix[FACE_TO_RIGHT_UP] = ROLE_BACK_TO_RIGHT_PREFIX; changeState(ROLE_STATE_MOVE); setUnitId(unitId); const DTUnit::_Data* unitData = DTUNIT->getData(getUnitId()); CC_ASSERT(unitData); setGridWidth(unitData->gridWidth); setGridHeight(unitData->gridHeight); setSpeed(unitData->speed); setMaxHP(unitData->hp); setCurHP(getMaxHP()); setATK(unitData->atk); setAtkSpeed(unitData->rate); BREAK_IF_FAILED(CSpriteObject::setSpriteFromCcbi(unitData->resourceID.c_str())); if (!editorMode) { BREAK_IF_FAILED(createHPBar()); m_pHPBar->setPercentage(1.f); Size sz = getSpriteContentSize(); m_pHPBar->setPosition(0, sz.height); } return true; } while (false); return false; }