///////////////////////////////////////////////////////////////////////////// /// Function: Start ///////////////////////////////////////////////////////////////////////////// void Start() { string strFunction = "CProjectile::Start()"; // Initialize the projectile m_v3InitialPosition = gameObject.transform.position; // Calculate replication related values replicationError = FiringPosition - m_v3InitialPosition; startTime = Time.time; travelTime = Vector3.Distance(m_v3InitialPosition, firingPosition + m_v3Direction * Constants.DEFAULT_MAX_PROJECTILE_RANGE * 0.5f) / Constants.PROJECTILE_SPEED_BULLET; // Ignore collisions with the firing object Physics.IgnoreCollision(collider, Instantiator.collider); // Ignore collisions with other bullets. Physics.IgnoreLayerCollision(Constants.COLLISION_LAYER_BULLETS, Constants.COLLISION_LAYER_BULLETS, true); switch (m_eProjectileType) { case EProjectileType.PROJECTILE_BULLET: m_fSpeed = Constants.PROJECTILE_SPEED_BULLET; m_fDamage = Constants.PROJECTILE_DAMAGE_BULLET; CAudioControl.CreateAndPlayAudio(transform.position, Audio.AUDIO_EFFECT_GUNSHOT, false, true, false, 1.0f); break; case EProjectileType.PROJECTILE_MISSILE: m_fSpeed = Constants.PROJECTILE_SPEED_MISSILE; m_fDamage = Constants.PROJECTILE_DAMAGE_MISSILE; break; case EProjectileType.PROJECTILE_RAY: m_fSpeed = Constants.PROJECTILE_SPEED_RAY; m_fDamage = Constants.PROJECTILE_DAMAGE_RAY; break; default: // Could not identify projectile type, report error. Debug.LogError(string.Format("{0} {1}", strFunction, ErrorStrings.ERROR_UNASSIGNED_TYPE)); break; } }
public override void OnStateMessage(StateMessage message) { OnEnterState enter = message as OnEnterState; if (enter != null) { GamePlayStarted started = enter.Message as GamePlayStarted; if (started != null && clientManager.OnMatchStarted != null) { if (clientManager.OnGameDrivenEvent != null) { clientManager.OnGameDrivenEvent(LogEventMessages.EVENT_MATCH_STARTED); CAudioControl.CreateAndPlayAudio(Vector3.zero, Audio.AUDIO_MUSIC, true, true, false, 0.6f); } clientManager.OnMatchStarted(started.Delay); } return; } }
// Use this for initialization void Start() { CAudioControl.CreateAndPlayAudio(transform.position, Audio.AUDIO_EFFECT_EXPLOSION, false, true, false, 1f); m_fInstantiationTime = Time.time; }
public override void OnGameMessage(GameMessage message) { // Please not that the messages have been segmented intentionally as both // clients and AI characters are sending messages and the serverManager // does not differentiate between messages sent by AI or clients. // // For example, score should always be updated when an AI character has scored // a point, but as the AI has no ClientDataOnServer object there's no point // in updating client stats. // // Additionally, sometimes we may not want to forward certain messages to the clients, // therefore message forwarding is a separate RPC. MatchExpired expired = message as MatchExpired; if (expired != null) { if (serverManager.OnMatchEnded != null) { serverManager.OnMatchEnded(); } serverManager.ChangeState(serverManager.ServerGameEndState, new MsgScoreUpdate() { RedScore = m_iRedScore, BlueScore = m_iBlueScore }); return; } //MsgDamageClient msgDamageClient = message as MsgDamageClient; //if ( null != msgDamageClient ) //{ // // A client has been hit, we want to damage the client which the // // message specifies. // foreach ( ClientDataOnServer clientData in serverManager.RegisteredClients ) // { // if ( clientData.Profile.DisplayName == msgDamageClient.UserName ) // { // clientData.CurrentHealth -= msgDamageClient.Damage; // serverManager.networkManager.UpdateClientStats( clientData ); // break; // } // } //} MsgFlagPickedUp msgFlagPickedUp = message as MsgFlagPickedUp; if (null != msgFlagPickedUp) { // Forward this message to the clients so they log the event. serverManager.networkManager.ForwardFlagPickedUp(msgFlagPickedUp); ClientDataOnServer client = serverManager.RegisteredClients.FirstOrDefault(c => c.Profile.DisplayName == msgFlagPickedUp.PlayerName); if (client != null) { client.HasFlag = true; } } PlayerTakenDamage playerDamage = message as PlayerTakenDamage; if (playerDamage != null) { ClientDataOnServer clientData = serverManager.RegisteredClients.First(c => c.NetworkPlayer == playerDamage.Player); clientData.CurrentHealth -= playerDamage.Damage; // If client is dead if (clientData.CurrentHealth <= 0) { CAudioControl.CreateAndPlayAudio(playerDamage.PlayerPosition, Audio.AUDIO_EFFECT_EXPLOSION, false, true, false, 2f); Network.Instantiate(PrefabResource.ExplosionPrefab, playerDamage.PlayerPosition, Quaternion.identity, 0); serverManager.CountdownToPlayerRespawn(clientData.NetworkPlayer); serverManager.SendGameMessage(new MsgPlayerDied() { PlayerName = clientData.Profile.DisplayName, PlayerTeam = clientData.ClientTeam, KillerName = playerDamage.Attacker, KillerTeam = playerDamage.AttackerTeam }); } else // otherwise just send the updated stats { serverManager.networkManager.UpdateClientStats(clientData); } } PlayerHealed playerHeal = message as PlayerHealed; if (playerHeal != null) { ClientDataOnServer clientData = serverManager.RegisteredClients.FirstOrDefault(c => c.NetworkPlayer == playerDamage.Player); if (clientData != null) { clientData.CurrentHealth = Mathf.Min(clientData.CurrentHealth + playerHeal.Heal, Constants.DEFAULT_HEALTH_DRONE); serverManager.networkManager.UpdateClientStats(clientData); } return; } MsgPlayerDied msgPlayerDied = message as MsgPlayerDied; if (null != msgPlayerDied) { // Try to find the client data object for the scoring player and update his stats. foreach (ClientDataOnServer clientData in serverManager.RegisteredClients) { if (clientData.Profile.DisplayName == msgPlayerDied.PlayerName) { clientData.DeathCount += 1; clientData.CurrentHealth = 0; serverManager.networkManager.UpdateClientStats(clientData); if (clientData.HasFlag == true) { clientData.HasFlag = false; CSpawner.SpawnFlag(); } } if (clientData.Profile.DisplayName == msgPlayerDied.KillerName) { clientData.KillCount += 1; clientData.EXP += Constants.POINTS_ON_KILL; serverManager.networkManager.UpdateClientStats(clientData); } } // Forward this message to the clients so they log the event. serverManager.networkManager.ForwardCharacterDied(msgPlayerDied); } PlayerRespawn playerRespawn = message as PlayerRespawn; if (playerRespawn != null) { ClientDataOnServer client = serverManager.RegisteredClients.FirstOrDefault(c => c.NetworkPlayer == playerRespawn.Player); if (client != null) { client.CurrentHealth = Constants.DEFAULT_HEALTH_DRONE; serverManager.networkManager.RespawnPlayer(playerRespawn.Player); } } MsgFlagDelivered msgFlagDelivered = message as MsgFlagDelivered; if (null != msgFlagDelivered) { // Increase score depending on the player's team. switch (msgFlagDelivered.PlayerTeam) { case IAIBase.ETeam.TEAM_BLUE: m_iBlueScore += 1; break; case IAIBase.ETeam.TEAM_RED: m_iRedScore += 1; break; } // Update the score on the network. serverManager.networkManager.UpdateScore(m_iRedScore, m_iBlueScore); // Try to find the client data object for the scoring player and update his stats. foreach (ClientDataOnServer clientData in serverManager.RegisteredClients) { if (clientData.Profile.DisplayName == msgFlagDelivered.PlayerName) { clientData.CaptureCount += 1; clientData.EXP += Constants.POINTS_ON_CAPTURE; serverManager.networkManager.UpdateClientStats(clientData); break; } } // Forward this message to the clients so they log the event. serverManager.networkManager.ForwardFlagCaptured(msgFlagDelivered); } base.OnGameMessage(message); }