/// <summary>
    /// Damage the Player, if not invunverable
    /// </summary>
    /// <param name="damage">Health to remove from the player</param>
    public void DamagePlayer(float damage)
    {
        if (!isInvunerable)
        {
            //Reduce Score when damaged
            ScoreKeeper.CurrentScore -= damageScoreReduction;

            //Calculate the resultant health and make sure that it doesn't
            //go below zero
            float resultantHealth = playerHealth - damage;

            if (resultantHealth > 0)
            {
                //Call damage events and functionality
                playerHealth = resultantHealth;
                PlayerDamaged?.Invoke(playerHealth);

                //Set player to be invunerable for an amount of time
                //so they don't take damage 100 times while clipping through a wall
                StartCoroutine(DoInvunerableSequence(playerInvunerableTime));
            }
            else
            {
                //Call game over/death events
                playerHealth = 0;
                PlayerKilled?.Invoke();
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Disable the Player Car
    /// </summary>
    protected override void DisableCar()
    {
        if (currentState == CarState.Enabled)
        {
            //Call Event
            PlayerKilled?.Invoke();


            //Call base function
            base.DisableCar();

            //Disable our movement
            if (playerControl)
            {
                playerControl.enabled = false;
            }

            if (controllingCar)
            {
                controllingCar.CarAccelerateInput = 0f;
                controllingCar.CarSteerInput      = 0f;
            }

            //Disable this data
            this.enabled = false;
        }
    }
 private void OnPlayerKilled()
 {
     // If there are no subscribed objects,
     // the PlayerKilled EventHandler will be null,
     // and nothing will be notified of this event.
     PlayerKilled?.Invoke(this, EventArgs.Empty);
 }
 //Collision with crater
 private void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.GetComponent <Crater>())
     {
         //Call Player Killed Event
         PlayerKilled?.Invoke();
         Destroy(gameObject);
     }
 }
Beispiel #5
0
 public override void Update(GameTime gameTime)
 {
     timer = (timer >= 500) ? 0 : timer + gameTime.ElapsedGameTime.TotalMilliseconds;
     if (timer == 0 && killed)
     {
         PlayerKilled?.Invoke(Owner, null);
     }
     base.Update(gameTime);
 }
Beispiel #6
0
 public void Die()
 {
     if (!isDead)
     {
         AudioManager.PlaySound(AudioManager.Sound.PlayerDeath, transform.position);
         canMove = false;
         canRun  = false;
         PlayerKilled?.Invoke();
         Cursor.lockState = CursorLockMode.None;
         Cursor.visible   = true;
         isDead           = true;
     }
 }
    //Check for collision with a fox and thus triggering the player killed event
    private void OnTriggerEnter(Collider collision)
    {
        //Check if we have collided with a fox
        if (collision.gameObject.GetComponent <FoxAI>())
        {
            //Trigger Player Killed Event
            PlayerKilled?.Invoke();

            //We have collided with a fox and have been caught
            //Call game over from the game state manager
            Destroy(gameObject);
        }
    }
Beispiel #8
0
        public void HandleKilled(NetworkMessage msg)
        {
            MsgKilled killed = msg as MsgKilled;

            KilledEventArgs args = new KilledEventArgs();

            args.Victim       = GetPlayerByID(killed.VictimID);
            args.Killer       = GetPlayerByID(killed.KillerID);
            args.Reason       = killed.Reason;
            args.KilledByFlag = FlagTypeList.GetFromAbriv(killed.FlagAbreviation);
            if (killed.Reason == BlowedUpReasons.DeathTouch)
            {
                args.InstrumentID = killed.PhysicsDriverID;
            }
            else
            {
                args.InstrumentID = killed.ShotID;

                if (killed.ShotID > 0)
                {
                    // kill shot
                    int bzfsShotID = (killed.KillerID * byte.MaxValue) + killed.ShotID;
                    // tell the shot manager to kill that thar shot
                }
            }

            if (args.Victim != null)
            {
                args.Victim.SetTeleport(-1, null, null);
                args.Victim.Active   = false;
                args.Victim.IsRabbit = false;
            }


            if (PlayerKilled != null)
            {
                PlayerKilled.Invoke(this, args);
            }
        }
Beispiel #9
0
 private void PublishPlayerKilledEvent() => PlayerKilledEvent?.Invoke();
Beispiel #10
0
        public void KillPlayer(ServerPlayer player, KilledEventArgs args)
        {
            if (args == null || player == null)
            {
                return;
            }

            if (!player.Info.Alive)
            {
                Logger.Log0("Player " + player.Callsign + " killed while dead");
            }

            player.Info.Alive = false;

            PlayerKilled?.Invoke(this, args);

            Logger.Log4("Player " + player.Callsign + " killed by " + args.KillInfo.Reason.ToString());

            bool wasFromAFlag = false;

            switch (args.KillInfo.Reason)
            {
            case BlowedUpReasons.GotKilledMsg:
                break;

            case BlowedUpReasons.GotShot:
                wasFromAFlag = true;
                Shots.RemoveShotForDeath(player, args.KillInfo.KillerID, args.KillInfo.ShotID);

                if (args.Shot != null)    // tell the flag it took a hit
                {
                    Flags.HandlePlayerTakeHit(player, args.Killer, args.Shot);
                }
                break;

            case BlowedUpReasons.GotRunOver:
                wasFromAFlag = true;
                break;

            case BlowedUpReasons.GotCaptured:
                break;

            case BlowedUpReasons.GenocideEffect:
                break;

            case BlowedUpReasons.SelfDestruct:
                break;

            case BlowedUpReasons.WaterDeath:
                break;

            case BlowedUpReasons.DeathTouch:
                break;

            case BlowedUpReasons.LastReason:
            case BlowedUpReasons.Unknown:
                Logger.Log0("Player " + player.Callsign + " killed by a method that should not happen");
                break;
            }

            if (wasFromAFlag)   // tell the flag it killed
            {
                Flags.HandlePlayerDoDamage(player, args.Killer, FlagTypeList.GetFromAbriv(args.KillInfo.FlagAbreviation));
            }

            // process any scores
            PlayerInfo.ScoreInfo vicScores    = new PlayerInfo.ScoreInfo();
            PlayerInfo.ScoreInfo killerScores = new PlayerInfo.ScoreInfo();
            if (ComputeScores(args.Victim, ref vicScores, args.Killer, ref killerScores, args.KillInfo.Reason))
            {
                args.Victim.Info.Score.ApplyScore(vicScores);
                if (args.Killer != null)
                {
                    args.Killer.Info.Score.ApplyScore(killerScores);
                }

                MsgScore scoreMessage = new MsgScore();
                if (!vicScores.Empty)
                {
                    Logger.Log3("Player " + player.Callsign + " score updated by " + vicScores.ToString());

                    ScoreUpdated?.Invoke(this, args.Victim);
                    args.Victim.Info.Score.Pack(args.Victim.PlayerID, scoreMessage);
                }

                if (args.Killer != null && !killerScores.Empty)
                {
                    Logger.Log3("Player " + player.Callsign + " score updated by " + killerScores.ToString());

                    ScoreUpdated?.Invoke(this, args.Killer);
                    args.Killer.Info.Score.Pack(args.Killer.PlayerID, scoreMessage);
                }

                if (scoreMessage.Scores.Count > 0)
                {
                    SendToAll(scoreMessage, false);
                }
            }

            MsgKilled killedMessage = new MsgKilled();

            killedMessage.VictimID        = args.Victim.PlayerID;
            killedMessage.KillerID        = args.Killer != null ? args.Killer.PlayerID : PlayerConstants.ServerPlayerID;
            killedMessage.ShotID          = args.Shot != null ? args.Shot.PlayerShotID : -1;
            killedMessage.Reason          = args.KillInfo.Reason;
            killedMessage.FlagAbreviation = (args.Shot != null && args.Shot.SourceFlag != null) ? args.Shot.SourceFlag.FlagAbbv : string.Empty;
            killedMessage.PhysicsDriverID = args.KillInfo.PhysicsDriverID;

            SendToAll(killedMessage, false);
        }
Beispiel #11
0
 public static void CallPlayerKilled()
 {
     PlayerKilled?.Invoke();
 }
Beispiel #12
0
 private void ActorMap_PlayerKilled(object sender, EventArgs e)
 {
     PlayerKilled?.Invoke(sender, null);
 }
Beispiel #13
0
        private void HandleCurrentEvents()
        {
            foreach (BaseEvent baseEvent in currentTick.Events)
            {
                switch (baseEvent.Type)
                {
                case EventType.MatchStarted:
                    MatchStarted?.Invoke(this, baseEvent);
                    break;

                case EventType.RoundAnnounceMatchStarted:

                    break;

                case EventType.RoundStart:
                    RoundStart?.Invoke(this, (RoundStartEvent)baseEvent);
                    break;

                case EventType.RoundEnd:
                    RoundEnd?.Invoke(this, (RoundEndEvent)baseEvent);
                    break;

                case EventType.WinPanelMatch:
                    WinPanelMatch?.Invoke(this, baseEvent);
                    break;

                case EventType.RoundFinal:
                    break;

                case EventType.LastRoundHalf:
                    break;

                case EventType.RoundOfficiallyEnd:
                    RoundOfficiallyEnd?.Invoke(this, baseEvent);
                    break;

                case EventType.RoundMVP:
                    RoundMVP?.Invoke(this, (RoundMVPEvent)baseEvent);
                    break;

                case EventType.FreezetimeEnded:
                    FreezetimeEnded?.Invoke(this, baseEvent);
                    break;

                case EventType.PlayerKilled:
                    PlayerKilled?.Invoke(this, (PlayerKilledEvent)baseEvent);
                    break;

                case EventType.PlayerTeam:
                    PlayerTeam?.Invoke(this, (PlayerTeamEvent)baseEvent);
                    break;

                case EventType.WeaponFired:
                    WeaponFired?.Invoke(this, (WeaponFiredEvent)baseEvent);
                    break;

                case EventType.SmokeNadeStarted:
                    SmokeNadeStarted?.Invoke(this, (SmokeNadeStartedEvent)baseEvent);
                    break;

                case EventType.SmokeNadeEnded:
                    SmokeNadeEnded?.Invoke(this, (SmokeNadeEndedEvent)baseEvent);
                    break;

                case EventType.DecoyNadeStarted:
                    DecoyNadeStarted?.Invoke(this, (DecoyNadeStartedEvent)baseEvent);
                    break;

                case EventType.DecoyNadeEnded:
                    DecoyNadeEnded?.Invoke(this, (DecoyNadeEndedEvent)baseEvent);
                    break;

                case EventType.FireNadeStarted:
                    FireNadeStarted?.Invoke(this, (FireNadeStartedEvent)baseEvent);
                    break;

                case EventType.FireNadeWithOwnerStarted:
                    FireNadeWithOwnerStarted?.Invoke(this, (FireNadeWithOwnerStartedEvent)baseEvent);
                    break;

                case EventType.FireNadeEnded:
                    FireNadeEnded?.Invoke(this, (FireNadeEndedEvent)baseEvent);
                    break;

                case EventType.FlashNadeExploded:
                    FlashNadeExploded?.Invoke(this, (FlashNadeExplodedEvent)baseEvent);
                    break;

                case EventType.ExplosiveNadeExploded:
                    ExplosiveNadeExploded?.Invoke(this, (ExplosiveNadeExplodedEvent)baseEvent);
                    break;

                case EventType.NadeReachedTarget:
                    NadeReachedTarget?.Invoke(this, (NadeReachedTargetEvent)baseEvent);
                    break;

                case EventType.BombBeginPlant:
                    BombBeginPlant?.Invoke(this, (BombBeginPlantEvent)baseEvent);
                    break;

                case EventType.BombAbortPlant:
                    BombAbortPlant?.Invoke(this, (BombAbortPlantEvent)baseEvent);
                    break;

                case EventType.BombPlanted:
                    BombPlanted?.Invoke(this, (BombPlantedEvent)baseEvent);
                    break;

                case EventType.BombDefused:
                    BombDefused?.Invoke(this, (BombDefusedEvent)baseEvent);
                    break;

                case EventType.BombExploded:
                    BombExploded?.Invoke(this, (BombExplodedEvent)baseEvent);
                    break;

                case EventType.BombBeginDefuse:
                    BombBeginDefuse?.Invoke(this, (BombBeginDefuseEvent)baseEvent);
                    break;

                case EventType.BombAbortDefuse:
                    BombAbortDefuse?.Invoke(this, (BombAbortDefuseEvent)baseEvent);
                    break;

                case EventType.PlayerHurt:
                    PlayerHurt?.Invoke(this, (PlayerHurtEvent)baseEvent);
                    break;

                case EventType.Blind:
                    Blind?.Invoke(this, (BlindEvent)baseEvent);
                    break;

                case EventType.PlayerBind:
                    PlayerBind?.Invoke(this, (PlayerBindEvent)baseEvent);
                    break;

                case EventType.PlayerDisconnect:
                    PlayerDisconnect?.Invoke(this, (PlayerDisconnectEvent)baseEvent);
                    break;

                case EventType.SayText:
                    SayText?.Invoke(this, (SayTextEvent)baseEvent);
                    break;

                case EventType.SayText2:
                    SayText2?.Invoke(this, (SayText2Event)baseEvent);
                    break;

                case EventType.PlayerJump:
                    PlayerJump?.Invoke(this, (PlayerJumpEvent)baseEvent);
                    break;

                case EventType.PlayerFootstep:
                    PlayerFootstep?.Invoke(this, (PlayerFootstepEvent)baseEvent);
                    break;

                case EventType.OtherDeath:
                    OtherDeath?.Invoke(this, (OtherDeathEvent)baseEvent);
                    break;

                case EventType.EntitySpawned:
                    EntitySpawned?.Invoke(this, (EntitySpawnedEvent)baseEvent);
                    break;

                case EventType.EntityRemoved:
                    EntityRemoved?.Invoke(this, (EntityRemovedEvent)baseEvent);
                    break;

                default:
                    break;
                }
            }
        }