Example #1
0
bool EntityFactory::createSkillAttackEffect(const SkillEffectContext& context)
{
	EntityView* pSourceEntityView = (EntityView*)getHandleData(context.src);
	if ((pSourceEntityView == NULL) || (context.id == 0))
	{
		ASSERT(false);
		return false;
	}

	// 是否需调整光效方向
	long magicAngle = 0;
	if (getInt(context.id, SkillViewProperty_NotAdjustDir) == 1)
    {
       magicAngle = pSourceEntityView->getAngle();
    }

	// 生物发起攻击动作
	AttackContext ac;

	// 取得配置的多个攻击动作中随机的一个
	int nActionId;
	const IntArray & AttackActId = getIntArray(context.id, SkillViewProperty_AttackActId);
	int nCount = AttackActId.count;

	if (nCount == 1)
	{
		nActionId = AttackActId.data[0];
	}
	else if (nCount > 1)
	{
		int nIndex = getRand(1, nCount);
		nActionId = AttackActId.data[nIndex - 1];
	}
	else
	{
		nActionId = 0;
	}

	ac.actionId = nActionId;

	ac.loops = context.loops;
	ac.fAnimateSpeed = getFloat(context.id, SkillViewProperty_AttackActSpeed);
	ac.isSpellAttack = context.isSpellSkill;
    //  冲锋技能是在瞬移效果完成后再做攻击动作;
	ulong effectType = getInt(context.id, SkillViewProperty_EffectType);
	if ( effectType != EffectType_Jump
		/*&& effectType != EffectType_RapidMove*/) // modify by zjp;冲锋的过程中做动作
	{
		if (ac.actionId!=0)		
		{
			//bool bMounted = false;
			//pSourceEntityView->onCommand(EntityCommand_GetMount, (ulong)&bMounted);
			//if (bMounted)
			{
				pSourceEntityView->onCommand(EntityCommand_SetMount, 0);
			}
			pSourceEntityView->onCommand(EntityCommand_Attack, (ulong)&ac);
		}
	}
    //  捆仙索在完成后也不需要做动作  
	if (effectType == EffectType_DestRapidMove || effectType == EffectType_SrcDestRapidMove)
    {
        ac.actionId = 0;
    }

    //  施法光效;
    int nAttackMagicID = getInt(context.id, SkillViewProperty_AttackMagicId);
    if (nAttackMagicID != 0)
    {
        EffectContext_General ec;
        ec.magicId = nAttackMagicID;
        ec.loops = 1;
        ec.angle = magicAngle;
		//  读取一下光效是否绑定在源上;
		int nAttackMagicAttachToSource = getInt(context.id, SkillViewProperty_AttackMagicAttachToSource);
		if (nAttackMagicAttachToSource == 1)
		{
			ec.owner = context.src;
		}
		else
		{
			ec.owner = 0;
		}
		// modify by zjp.修改特效释放的位置
		//ec.tile = pSourceEntityView->getTile();
		ec.tile = context.ptCenter;

        EffectControl_General* ctrl = new EffectControl_General();
        if (!ctrl->create(ec))
        {
            delete ctrl;
            return false;
        }
        ctrl->setSrc(context.src);
        ctrl->setViewId(context.id);
        EffectControlManager::getInstance().add(ctrl);
    }

	//播放攻击声效
	const IntArray & nSoundIDArray = getIntArray(context.id,SkillViewProperty_SoundIDAttack);
	int nSoundCount = nSoundIDArray.count;
	int nSoundID = 0;
	if (nSoundCount == 1)
	{
		nSoundID = nSoundIDArray.data[0];
	}
	else if (nSoundCount > 1)
	{
		IEntity* pEntity = (IEntity*)pSourceEntityView->getUserData();
		if (pEntity && pEntity->GetEntityClass()->IsPerson())
		{
			int PersonSex = pEntity->GetNumProp(CREATURE_PROP_SEX);
			if (PersonSex == PERSON_SEX_MALE)
			{
				nSoundID = nSoundIDArray.data[0];
			}
			else if(PersonSex == PERSON_SEX_FEMALE)
			{
				nSoundID = nSoundIDArray.data[1];
			}
		}
	}
	int nSoundLoop = getInt(context.id,SkillViewProperty_bSoundLoopeAttack);
	if (nSoundID>1000)
	{
		IFormManager* pFormManger = gGlobalClient->getFormManager();
		if (pFormManger)
		{
			pFormManger->PlaySound(nSoundID,nSoundLoop,0.8,SOUNDRES_TYPE_SOUND);
		}
	}

	return true;
}