void execute(CItem *pItem) { _this->m_attacking = false; _this->m_slideKick = false; _this->m_netAttacking = false; _this->m_delayTimer = 0.0f; pItem->SetBusy(false); pItem->ForcePendingActions(); MeleeDebugLog ("CMelee<%p> StopAttackingAction is being executed!", _this); CActor* pActor(NULL); if(!gEnv->bMultiplayer) { if (IEntity* owner = pItem->GetOwner()) if (IAIObject* aiObject = owner->GetAI()) if (IAIActor* aiActor = aiObject->CastToIAIActor()) aiActor->SetSignal(0, "OnMeleePerformed"); } else if( g_pGameCVars->pl_melee.mp_melee_system_camera_lock_and_turn && s_meleeSnapTargetId && (pActor = pItem->GetOwnerActor()) && pActor->IsClient() ) { CActor* pOwnerActor = pItem->GetOwnerActor(); pOwnerActor->GetActorParams().viewLimits.ClearViewLimit(SViewLimitParams::eVLS_Item); s_meleeSnapTargetId = 0; CHANGED_NETWORK_STATE(pOwnerActor, CPlayer::ASPECT_SNAP_TARGET); } if(_this->m_pMeleeAction) { SAFE_RELEASE(_this->m_pMeleeAction); } }
int NFCActorManager::RequireActor() { //¶Ñactor NF_SHARE_PTR<NFIActor> pActor(NF_NEW NFCActor(*m_pFramework, this)); mxActorMap.insert(std::make_pair(pActor->GetAddress().AsInteger(), pActor)); return pActor->GetAddress().AsInteger(); }
int NFCActorModule::RequireActor() { NF_SHARE_PTR<NFIActor> pActor(NF_NEW NFCActor(*m_pFramework, this)); mxActorMap.AddElement(pActor->GetAddress().AsInteger(), pActor); return pActor->GetAddress().AsInteger(); }
void RemoteNetworkView::CreateActor(IEventDataPtr pEventData) { std::shared_ptr<EventData_CreateActor> pCastEventData = std::static_pointer_cast<EventData_CreateActor>(pEventData); ActorId id = pCastEventData->VGetActorId(); Vec3 position = pCastEventData->VGetPosition(); Actor* actor = GCC_NEW Actor(id, position); actor->SetName(pCastEventData->VGetActorName()); // With that Unity can safely call an Actor Name without messing up if there is simultaneous connection actor->SetIp(pCastEventData->VGetIp()); std::shared_ptr<Actor> pActor(actor); m_ActorManager->AddActor(pActor); }
int NFCActorManager::OnRequireActor(NFIComponent* pComponent) { //¶Ñactor if (pComponent) { NF_SHARE_PTR<NFIActor> pActor(NF_NEW NFCActor(*m_pFramework, this)); pActor->RegisterActorComponent(pComponent); mxActorMap.insert(std::make_pair(pActor->GetAddress().AsInteger(), pActor)); return pActor->GetAddress().AsInteger(); } return 0; }
bool nxNexteroidsGameLogicEventListener::HandleEvent( nxIEventData const & event ) { if(event.VGetEventType() == NX_EVENT_RequestNewGame) { log(NX_LOG_DEBUG, "New game event received"); // m_pGameLogic->VChangeState(NX_GS_LoadingGameEnvironment); m_pGameLogic->VChangeState(NX_GS_WaitingForPlayers); return true; } else if(event.VGetEventType() == NX_EVENT_GameState) { nxGameStateEventData* gameStateEvent = (nxGameStateEventData*)(&event); if(gameStateEvent->GetState() == NX_GS_LoadingGameEnvironment) { } else if(gameStateEvent->GetState() == NX_GS_LoadedLevel00) { m_pGameLogic->VBuildLevel00(); } return true; } else if(event.VGetEventType() == NX_EVENT_RequestNewActor) { //Check to make sure request is worthy const nxRequestNewActorEventData & castEvent = static_cast< const nxRequestNewActorEventData & >( event ); //Validate event and get a new actor id and generate a new actor event. nxIActor* pActor = castEvent.GetActor(); pActor->VCreate(); const nxIEventDataPtr eventPtr( NX_NEW nxNewActorEventData(pActor)); nxEventManager::GetInstance().VQueueEvent( eventPtr ); return true; } else if(event.VGetEventType() == NX_EVENT_NewActor) { const nxNewActorEventData & castEvent = static_cast< const nxNewActorEventData & >( event ); shared_ptr<nxIActor> pActor(castEvent.GetActor()->VClone()); m_pGameLogic->VAddActor(pActor); return true; } else if(event.VGetEventType() == NX_EVENT_Thrust) { const nxThrustEventData & castEvent = static_cast< const nxThrustEventData & >( event ); shared_ptr<nxIActor> pActor = m_pGameLogic->VGetActor(castEvent.GetActorId()); if( pActor ) { m_pGameLogic->VGetPhysics()->VApplyThrottle(pActor->VGetId(), castEvent.GetThrustAmount()); } return true; } else if(event.VGetEventType() == NX_EVENT_Steer) { const nxSteerEventData & castEvent = static_cast< const nxSteerEventData & >( event ); shared_ptr<nxIActor> pActor = m_pGameLogic->VGetActor(castEvent.GetActorId()); if( pActor ) { m_pGameLogic->VGetPhysics()->VApplySteering(pActor->VGetId(), castEvent.GetSteerAmount()); } return true; } else if(event.VGetEventType() == NX_EVENT_FireWeapon) { const nxFireWeaponEventData & castEvent = static_cast< const nxFireWeaponEventData & >( event ); shared_ptr<nxIActor> pActor = m_pGameLogic->VGetActor(castEvent.GetActorId()); if( pActor ) { float r = 30.0f; float bulletRadius = 1.0f; pActor->VSetRadius(bulletRadius); r += bulletRadius; float bulletSpeed = 40000.0f; nxPoint3 bulletPos(pActor->VGetPos().GetX() + (r * cos(pActor->VGetOrientation())), pActor->VGetPos().GetY() + (r * sin(pActor->VGetOrientation())), 0); nxReal bulletRot = pActor->VGetOrientation(); shared_ptr<nxBulletActor> pBullet(NX_NEW nxBulletActor(bulletRot, bulletPos, bulletRadius, bulletSpeed)); const nxActorId actorId = m_pGameLogic->GetNewActorId(); pBullet->VSetId(actorId); nxColour bulletColour; bulletColour.r = 1; bulletColour.g = 1; bulletColour.b = 0; //Server is always green! Best colour pBullet->VSetColour(bulletColour); pBullet->VSetViewId(-1); //Don't think I need this? const nxIEventDataPtr eventPtr( NX_NEW nxRequestNewActorEventData(pBullet)); nxEventManager::GetInstance().VQueueEvent(eventPtr); } return true; } else if(event.VGetEventType() == NX_EVENT_PhysCollision) { const nxPhysCollisionEventData & castEvent = static_cast< const nxPhysCollisionEventData & >( event ); shared_ptr<nxIActor> actorA = m_pGameLogic->VGetActor(castEvent.GetActorIdA()); shared_ptr<nxIActor> actorB = m_pGameLogic->VGetActor(castEvent.GetActorIdB()); if( actorA && actorB ) { if( ((actorA->VGetType() == NX_ACTOR_ROCK) && (actorB->VGetType() == NX_ACTOR_BULLET)) || ((actorA->VGetType() == NX_ACTOR_BULLET) && (actorB->VGetType() == NX_ACTOR_ROCK)) ) { shared_ptr<nxIActor> rock, bullet; //Rock hit bullet if(actorA->VGetType() == NX_ACTOR_BULLET) { bullet = actorA; rock = actorB; } else { rock = actorA; bullet = actorB; } //Now register hit and kill actor. m_pGameLogic->VRegisterHit(rock->VGetId(), bullet->VGetId()); const nxIEventDataPtr eventPtr( NX_NEW nxActorDeathEventData(bullet->VGetId())); nxEventManager::GetInstance().VQueueEvent(eventPtr); nxPoint3 rockPos = rock->VGetPos(); nxReal rockRot = rock->VGetOrientation(); nxReal rockRadius = rock->GetRadius(); // int rockType = ((nxRockActor*)(rock.get()))->VGetRockType(); const nxIEventDataPtr rockEventPtr( NX_NEW nxActorDeathEventData(rock->VGetId())); nxEventManager::GetInstance().VQueueEvent(rockEventPtr); //TODO:Blowing up sounds, effects, what have you. //If not a small rock, make smaller ones. if(rockRadius >= 20) { //Spawn 2 rocks in place //1st rock rockPos.SetX(rockPos.GetX() + 20 ); //TODO:Make more random nxReal rockSpeed = 4; nxReal rockRadius = 10; //Make a smaller rock shared_ptr<nxRockActor> pRock(NX_NEW nxRockActor(rockRot, rockPos, rockRadius, rockSpeed)); nxColour rockColour; rockColour.r = 1; rockColour.g = 1; rockColour.b = 1; //Server is always green! Best colour pRock->VSetColour(rockColour); pRock->VSetViewId(-1); //Don't need this I think pRock->VSetRockType(0); const nxActorId rockActorId = m_pGameLogic->GetNewActorId(); pRock->VSetId(rockActorId); const nxIEventDataPtr newRockEventPtr( NX_NEW nxRequestNewActorEventData(pRock)); nxEventManager::GetInstance().VQueueEvent(newRockEventPtr); //2nd rock rockPos.SetX(rockPos.GetX() - 40); //TODO:Make more random rockSpeed = 4; rockRadius = 10; //Make a smaller rock shared_ptr<nxRockActor> pRock2(NX_NEW nxRockActor(rockRot, rockPos, rockRadius, rockSpeed)); nxColour rockColour2; rockColour2.r = 1; rockColour2.g = 1; rockColour2.b = 1; //Server is always green! Best colour pRock2->VSetColour(rockColour2); pRock2->VSetViewId(-1); //Don't need this I think pRock2->VSetRockType(0); const nxActorId rock2ActorId = m_pGameLogic->GetNewActorId(); pRock2->VSetId(rock2ActorId); const nxIEventDataPtr newRock2EventPtr( NX_NEW nxRequestNewActorEventData(pRock2)); nxEventManager::GetInstance().VQueueEvent(newRock2EventPtr); } } else if( ((actorA->VGetType() == NX_ACTOR_BULLET) && (actorB->VGetType() == NX_ACTOR_SPACESHIP)) || ((actorA->VGetType() == NX_ACTOR_SPACESHIP) && (actorB->VGetType() == NX_ACTOR_BULLET)) ) { shared_ptr<nxIActor> ship, bullet; //Rock hit bullet if(actorA->VGetType() == NX_ACTOR_BULLET) { bullet = actorA; ship = actorB; } else { ship = actorA; bullet = actorB; } const nxIEventDataPtr bulletEventPtr( NX_NEW nxActorDeathEventData(bullet->VGetId())); nxEventManager::GetInstance().VQueueEvent(bulletEventPtr); const nxIEventDataPtr shipEventPtr( NX_NEW nxActorDeathEventData(ship->VGetId())); nxEventManager::GetInstance().VQueueEvent(shipEventPtr); } else if( ((actorA->VGetType() == NX_ACTOR_ROCK) && (actorB->VGetType() == NX_ACTOR_SPACESHIP)) || ((actorA->VGetType() == NX_ACTOR_SPACESHIP) && (actorB->VGetType() == NX_ACTOR_ROCK)) ) { shared_ptr<nxIActor> ship, rock; //Rock hit rock if(actorA->VGetType() == NX_ACTOR_ROCK) { rock = actorA; ship = actorB; } else { ship = actorA; rock = actorB; } const nxIEventDataPtr rockEventPtr( NX_NEW nxActorDeathEventData(rock->VGetId())); nxEventManager::GetInstance().VQueueEvent(rockEventPtr); const nxIEventDataPtr shipEventPtr( NX_NEW nxActorDeathEventData(ship->VGetId())); nxEventManager::GetInstance().VQueueEvent(shipEventPtr); } } return true; } else if(event.VGetEventType() == NX_EVENT_ActorDeath) { const nxActorDeathEventData & castEvent = static_cast< const nxActorDeathEventData & >( event ); nxActorId aid = castEvent.GetActorId(); shared_ptr<nxIActor> pActor = m_pGameLogic->VGetActor(aid); if(pActor) { //Spawn another one! // m_pGameLogic->SpawnActor(pActor->VGetType()); m_pGameLogic->VRemoveActor(aid); } return true; } else if(event.VGetEventType() == NX_EVENT_ActorMoved) { const nxActorMovedEventData & castEvent = static_cast< const nxActorMovedEventData & >( event ); m_pGameLogic->VMoveActor(castEvent.GetActorId(), castEvent.GetPos(), castEvent.GetOrientation()); } else if(event.VGetEventType() == NX_EVENT_RemoteClient) { const nxRemoteClientEventData & castEvent = static_cast< const nxRemoteClientEventData & >( event ); if(m_pGameLogic->IsProxy()) { //We need to create the real game view. //Now this will listen to all events from server, we can just kick back.:D int viewId = m_pGameLogic->GetIpInt(); shared_ptr<nxIGameView> gameView(NX_NEW nxNexteroidsGameView()); gameView->Init(); m_pGameLogic->VPopView(); // m_pGameLogic->VAddView(gameView, -1); //Should be set automagically over net! m_pGameLogic->VAddViewExplicit(gameView, viewId, -1); //Should be set automagically over net! } else { //Set the number of players connected up! m_pGameLogic->SetNRemotePlayers(m_pGameLogic->GetNRemotePlayers() + 1); m_pGameLogic->VAddConnectedClientId(castEvent.GetIpInt()); } } return false; }