Ejemplo n.º 1
0
//--------------------------------------------------------------------------------
//int LuaScene::CreateGeometryActor( lua_State* l )
//{
//	Scene* pScene =				LuaScene::CheckType( l, 1 );
//
//	// Create a user data in the size of a pointer to a geometry actor.
//	GeometryActor** udata = (GeometryActor**)lua_newuserdata( l, sizeof(GeometryActor*) );
//	*udata = new GeometryActor();
//
//	// Add the actor to the scene.
//	pScene->AddActor( *udata );
//
//	// Get the meta-table for the GeometryActor class in Lua.
//	luaL_getmetatable( l, "luaL_GeometryActor" );
//
//	// Lua stack looks like this now:
//	// 2 | -1 | metatable "luaL_GeometryActor"
//	// 1 | -2 | userdata
//	//
//	lua_setmetatable( l, -2 );
//
//	// Now the stack looks like this: 
//	// 1 | -1 | userdata
//	//
//	// We just return the user data to the calling function like so:
//
//	return( 1 );
//}
//--------------------------------------------------------------------------------
int LuaScene::AddActor( lua_State* l )
{
	Scene* pScene =	LuaScene::CheckType( l, 1 );
	
	// TODO: There is no error checking here - need to determine the best way
	//       to check if an object is a subclass of Actor...
	void *p = lua_touserdata( l, 2 );
	Actor* pActor = *(Actor**)p;

	// Add the actor to the scene.
	pScene->AddActor( pActor );

	return( 0 );
}
//----------------------------------------------------------------------------
void SkillStepLink::OnEnter (SkillInstance *instance)
{
	SkillStep::OnEnter(instance);

	Skill *skill = instance->GetSkill();
	Character *character = skill->GetCharacter();
	Scene *scene = character->GetScene();
	Node *sceneNode = DynamicCast<Node>(scene->GetSceneNode());
	APoint charPos = character->GetPosition();

	int aimTarget = instance->GetAimTarget();
	Character *aimTargetChar = DynamicCast<Character>(scene->GetActorByID(
		aimTarget));
	if (aimTargetChar)
	{
		SkillActorLinkPtr skillActorLink = new0 SkillActorLink();

		instance->AddSkillActor(aimTarget, skillActorLink);

		skillActorLink->SetID(10000+scene->GetNextID());

		skillActorLink->Initlize();

		if (!mSelfEffectFilename.empty())
			skillActorLink->SetMovableFilename(mSelfEffectFilename);

		skillActorLink->SetFromActorID(character->GetID());
		skillActorLink->SetFromActorAnchor(mSelfEffectAnchor);

		if (IsLinkToActor())
		{
			skillActorLink->SetTargetType(SkillActorLink::TT_ACTOR);
			skillActorLink->SetToActorID(aimTarget);
		}
		else
		{
			APoint toPos = charPos + mLinkDir * mSpeed * mLinkToTime; 

			skillActorLink->SetTargetType(SkillActorLink::TT_POSITION);
			skillActorLink->SetToPosition(toPos);
		}

		skillActorLink->SetPosition(charPos);
		skillActorLink->SetLinkSpeed(GetSpeed());

		skillActorLink->ShowHelpMovable(false);

		scene->AddActor(skillActorLink);

		skillActorLink->Start();

		if (!mSelfPosEffectFilename.empty())
		{
			APoint pos = character->GetPosition();
			Transform trans;
			trans.SetTranslate(pos);
			trans.SetRotate(character->GetMovable()->WorldTransform.GetRotate());

			if (!mSelfPosEffectFilename.empty())
			{
				Node *anchor = character->GetAnchor(mSelfPosEffectAnchor);
				if (anchor)
				{
					//trans = anchor->WorldTransform;
					trans.SetTranslate(anchor->WorldTransform.GetTranslate());
				}
			}

			Object *obj = PX2_RM.BlockLoadShareCopy(mSelfPosEffectFilename, false,
				false, true);
			if (obj)
			{
				EffectNode *effectNode = DynamicCast<EffectNode>(obj);
				if (effectNode)
				{
					effectNode->SetSelfCtrled(true);
					effectNode->WorldTransform = trans;
					effectNode->WorldTransformIsCurrent = true;
					sceneNode->AttachChild(effectNode);
					effectNode->ResetPlay();

					PX2_DM.AddDeletingObj(effectNode, mSelfPosEffectTime, 3.0f);
				}
			}
		}
	}
	else
	{
		if (PX2_PROJ.IsInEditor())
		{
			SkillActorLinkPtr skillActorLink = new0 SkillActorLink();

			instance->AddSkillActor(aimTarget, skillActorLink);

			skillActorLink->SetID(10000+scene->GetNextID());

			skillActorLink->Initlize();

			if (!mSelfEffectFilename.empty())
				skillActorLink->SetMovableFilename(mSelfEffectFilename);

			skillActorLink->SetFromActorID(character->GetID());
			skillActorLink->SetFromActorAnchor(mSelfEffectAnchor);

			if (IsLinkToActor())
			{
				skillActorLink->SetTargetType(SkillActorLink::TT_ACTOR);
				skillActorLink->SetToActorID(aimTarget);
			}
			else
			{
				APoint toPos = charPos + mLinkDir * mSpeed * mLinkToTime; 

				skillActorLink->SetTargetType(SkillActorLink::TT_POSITION);
				skillActorLink->SetToPosition(toPos);
			}

			skillActorLink->SetPosition(charPos);
			skillActorLink->SetLinkSpeed(GetSpeed());

			skillActorLink->ShowHelpMovable(false);

			scene->AddActor(skillActorLink);

			skillActorLink->Start();
		}
		else
		{
			// over
		}
	}
}