void Troop::kickOut(Pet* pet) { int index = pet->getIndex(); if (index >= cap) return; CCArray* vlink = (CCArray*)vlinks->objectAtIndex(pet->getVLink()); int v = vlink->indexOfObject(pet); vlink->removeObject(pet); while (vlink->count() > v) { Pet* p = (Pet*)vlink->lastObject(); p->setVLink(index + col); vlink->removeLastObject(); ((CCArray*)vlinks->objectAtIndex(index + col))->insertObject(p, 0); } CCArray* hlink = (CCArray*)hlinks->objectAtIndex(pet->getHLink()); int h = hlink->indexOfObject(pet); hlink->removeObject(pet); while (hlink->count() > h) { Pet* p = (Pet*)hlink->lastObject(); p->setHLink(index + 1); hlink->removeLastObject(); ((CCArray*)hlinks->objectAtIndex(index + 1))->insertObject(p, 0); } pets->replaceObjectAtIndex(index, Pet::createFakePet()); }
//// merge small piece asprite to a big one CCNode* UIPicture::MergeSmallASprite(CCSprite* sprite) { if (!sprite) return NULL; CCTexture2D* ptexture = RecursiveFindTexture(sprite); if (ptexture == NULL) return sprite; if(sprite->getChildrenCount() == 0) { return sprite; } CCArray* secondTextureSprite = CCArray::create(); while (sprite->getChildrenCount() > 0) { CCTexture2D* ptexture = RecursiveFindTexture(sprite); /// create new batch node which used to store a series of sprites CCSpriteBatchNode * pNode = CCSpriteBatchNode::createWithTexture(ptexture); CCSize size = sprite->getContentSize(); CCPoint pt = sprite->getPosition(); pNode->setContentSize(size); pNode->setAnchorPoint(ccp(0.0, 0.0)); secondTextureSprite->removeAllObjects(); int i = 0; while(sprite->getChildrenCount() > 0) { CCArray* children = sprite->getChildren(); CCSprite* s1 = (CCSprite*)(children->lastObject()); sprite->removeChild(s1, false); if (s1->getTexture() == ptexture) { pNode->addChild(s1, i--); }else { secondTextureSprite->addObject(s1); } } /// copy second texture sprite to sprite CCObject* pTemp; CCARRAY_FOREACH(secondTextureSprite, pTemp) { CCSprite* pPst = (CCSprite*) pTemp; sprite->addChild(pPst); } if (!m_pSpriteNode) { /// 第一次创建时,取第一个sprite位置为当前m_pSpriteNode的位置 m_pSpriteNode = CCNode::create(); m_pSpriteNode->setPosition(pt); m_pSpriteNode->setContentSize(size); m_pSpriteNode->setAnchorPoint(sprite->getAnchorPoint()); pNode->setPosition(CCPointZero); }else { /// convert other sprite to local position CCPoint ptOrgio = m_pSpriteNode->getPosition(); pt = ccpSub(pt , ptOrgio); pNode->setPosition(pt); } m_pSpriteNode->addChild(pNode); }
bool BattleCharacter::SimulationSkill(BattleCharacter* pInvoker,CCArray* pTargets) { CCArray* pEffectTargets =CCArray::createWithCapacity(pTargets->count()); pEffectTargets->retain(); bool bCommandSuc = false; for(unsigned int index = 0;index<pTargets->count();index++) { SkillDataLoader* pData = SkillDataLoader::instance(); int nID = pInvoker->m_nOnUseID; int nType = 0; pData->GetSkillValue(DATA_SKILL_TYPE,nID,&nType); BattleCharacter* pTarget = (BattleCharacter*)pTargets->objectAtIndex(index); //判断是否产生伤害 bool bDamage = (nType == SKILL_TYPE_DAMAGE)||(nType == SKILL_TYPE_DAMAGE_AND_HEALING); bool bHealing = (nType == SKILL_TYPE_HEALING)||(nType == SKILL_TYPE_DAMAGE_AND_HEALING); if(bDamage&&(!pInvoker->InSameRace(pTarget))) { int nDamage = BattleCharacter::GetSkillHPDam(pInvoker,pTarget); pTarget->m_nHP += -nDamage; pTarget->m_nHPoffset += -nDamage; //pTarget->ShowMapDam(nDamage); //pTarget->RefreshHPBar(); bCommandSuc = true; AquireExpFromAttack(pInvoker,pTarget); if (!pEffectTargets->containsObject(pTarget)) { pEffectTargets->addObject(pTarget); } } else if(bHealing&&pInvoker->InSameRace(pTarget)) { int nHealing = BattleCharacter::GetSkillHPHeal(pInvoker,pTarget); pTarget->m_nHP += nHealing; pTarget->m_nHPoffset += nHealing; bCommandSuc = true; AquireExpFromAttack(pInvoker,pTarget); if (!pEffectTargets->containsObject(pTarget)) { pEffectTargets->addObject(pTarget); } } } if(bCommandSuc) { CCArray* pAnimations = AnimationManager::instance()->CreateMapSkillAnimations(pInvoker->m_nOnUseID); CCAnimation* pMapSkillAnimation = (CCAnimation*)pAnimations->objectAtIndex(0); CCSprite* pMapSkillSprite = CCSprite::createWithSpriteFrame(dynamic_cast<CCAnimationFrame*>(pMapSkillAnimation->getFrames()->objectAtIndex(0))->getSpriteFrame()); CCSprite* pMapSkillBackgroundSprite = NULL; CCAnimation* pMapSkillBackgroundAniation = NULL; if (pAnimations->count()>1) { pMapSkillBackgroundAniation = (CCAnimation*)pAnimations->lastObject(); pMapSkillBackgroundSprite = CCSprite::createWithSpriteFrame(dynamic_cast<CCAnimationFrame*>(pMapSkillBackgroundAniation->getFrames()->objectAtIndex(0))->getSpriteFrame()); } if (pMapSkillBackgroundSprite!=NULL) { pMapSkillBackgroundSprite->setPosition(ccp(pInvoker->m_nCommandX,pInvoker->m_nCommandY)); CharacterStatus::m_pMap->addChild(pMapSkillBackgroundSprite,MAX_LAYER_ZORDER-1,LAYER_MAPSKILLBACKGROUND_ID); pMapSkillBackgroundSprite->runAction(CCRepeatForever::create(CCAnimate::create(pMapSkillBackgroundAniation))); pMapSkillSprite->setPosition(ccp(pMapSkillBackgroundSprite->getPositionX(),pMapSkillBackgroundSprite->getPositionY()+GetSpriteTextureHeight(pMapSkillBackgroundSprite))); } else { pMapSkillSprite->setPosition(ccp(pInvoker->m_nCommandX,pInvoker->m_nCommandY)); } CharacterStatus::m_pMap->addChild(pMapSkillSprite,MAX_LAYER_ZORDER); pMapSkillSprite->runAction(CCSequence::create(CCAnimate::create(pMapSkillAnimation),CCCallFuncND::create(pInvoker,callfuncND_selector(BattleCharacter::MapSkillEffectsCallBack),(void*)pEffectTargets),NULL)); } return bCommandSuc; }