View Single Post
  #26  
Old 09-10-2011, 01:03 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

New Version, added Player Countdown, changed Player in Prisoncell from object refence to Playername, so the penalty should be still active, even the player reconnected.

Code:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;


public class Mission : AMission
{

    const int TotalArrestTime = 30;  // Time in seconds

    public class prisonCell
    {
        public string PrisonerName { get; set; }
        public DateTime ArrestBeginTime { get; set; }
        public DateTime ArrestEndTime { get; set; }
        public bool Removable { get; set; }
    }

    public List<prisonCell> PrisonCamp = new List<prisonCell>();


    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);

        if (actor == null) // if player bailed out the actor is null so remove the player from prison if he is in
        {
            if (PrisonCamp.Count != 0)
            {
                foreach (prisonCell pri in PrisonCamp)
                {
                    if (pri.PrisonerName.Equals(player.Name()))
                    {
                            pri.Removable = true;
                    }
                }
                PrisonCamp.RemoveAll(item => item.Removable == true);
            }
        }

        if (PrisonCamp.Count != 0)
        {
            foreach (prisonCell pri in PrisonCamp)
            {
                if (pri.PrisonerName.Equals(player.Name()))
                {
                    TimeSpan ArrestTime = DateTime.Now.Subtract(pri.ArrestBeginTime);

                    if (ArrestTime.TotalSeconds < TotalArrestTime)
                    {
                        TimeSpan RestTime = pri.ArrestEndTime.Subtract(DateTime.Now);
                        GamePlay.gpLogServer(null, "Player: {0} get a time penalty for leaving Airplane in flight\n", new object[] { player.Name() });
                        (actor as AiAircraft).hitNamed(part.NamedDamageTypes.FuelPumpFailure);
                    }
                    else
                    {
                        pri.Removable = true;
                    }
                }
            }
            PrisonCamp.RemoveAll(item => item.Removable == true);
        }
    }


    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);

        if ((actor as AiAircraft).IsAirborne())
        {
            prisonCell NewPrisoner = new prisonCell();
            NewPrisoner.PrisonerName = player.Name();
            NewPrisoner.ArrestBeginTime = DateTime.Now;
            NewPrisoner.ArrestEndTime = DateTime.Now.AddSeconds(TotalArrestTime);

            PrisonCamp.Add(NewPrisoner);
        }
    }


    public override void OnTickGame()
    {
        base.OnTickGame();

        if (Time.tickCounter() % 34 == 0) // 34 Ticks should be a second
        {
            if (PrisonCamp.Count != 0)
            {
                foreach (prisonCell pri in PrisonCamp)
                {
                    foreach (Player aktplayer in GamePlay.gpRemotePlayers())
                    {
                        if (pri.PrisonerName.Equals(aktplayer.Name()))
                        {
                            TimeSpan RestTime = pri.ArrestEndTime.Subtract(DateTime.Now);
                            if (RestTime.TotalSeconds > 0.0)
                            {
                                GamePlay.gpHUDLogCenter(new Player[] { aktplayer }, "{0} Arrest ends in {1:00} min. {2:00} sec.", new object[] { aktplayer.Name(), RestTime.Minutes, RestTime.Seconds });
                            }
                            else
                            {
                                GamePlay.gpHUDLogCenter(new Player[] { aktplayer }, "{0} Arrest over - Have Fun!", new object[] { aktplayer.Name() });
                                pri.Removable = true;
                            }
                        }
                    }
                }
                PrisonCamp.RemoveAll(item => item.Removable == true);
            }
        }
    }
}
Reply With Quote