Esempio n. 1
0
        public static void MakeMember(Player member, MissionConvoy convoy)
        {
            if (!IasPlayerAllowedToJoin(member))
            {
                return;
            }

            if (convoy.Members.Count >= Configuration.Instance.MaximumConvoyMembers)
            {
                return;
            }

            convoy.SendMessage($"Player {{00FF00}}{member.Name}{{FFFFFF}} has joined the convoy.");

            member.SendClientMessage(Color.White, "{00FF00}You have joined the convoy");

            convoy.Members.Add(member);

            member.IsInConvoy = true;
            member.Convoy     = convoy;

            if (convoy.Members.Count == Configuration.Instance.MaximumConvoyMembers)
            {
                convoy.Status = ConvoyStatus.Full;
            }

            convoy.MemberText.Text = "Waiting for the leader to start a job.";
        }
Esempio n. 2
0
        public static async Task CancelConvoyAsync(MissionConvoy convoy)
        {
            foreach (var member in convoy.Members)
            {
                member.Convoy     = null;
                member.IsInConvoy = false;

                convoy.MemberText.Hide(member);
                convoy.LeaderText.Hide(member);

                await MissionsController.ClassEndMissionAsync(member);

                member.SendClientMessage(Color.White, "{FF0000}The leader cancelled the convoy.");
            }

            convoy.MissionCargo       = null;
            convoy.FromLocation       = null;
            convoy.ToLocation         = null;
            convoy.Status             = ConvoyStatus.Empty;
            convoy.MissionStep        = 0;
            convoy.ConvoyTrailerModel = 0;
            convoy.IsLeaderInformed   = false;
            convoy.Members.Clear();
            convoy.Timer.Dispose();
        }
Esempio n. 3
0
        public static void ConvoyListDialog_Response(object sender, DialogResponseEventArgs e)
        {
            if (e.DialogButton == DialogButton.Right)
            {
                return;
            }

            var player = e.Player as Player;
            var convoy = MissionConvoy.Convoys[e.ListItem];

            switch (convoy.Status)
            {
            case ConvoyStatus.Empty:
                MissionConvoy.MakeLeader(player, convoy);
                break;

            case ConvoyStatus.Open:
                MissionConvoy.MakeMember(player, convoy);
                break;

            case ConvoyStatus.Full:
                player?.SendClientMessage(Color.Red, Messages.MissionConvoyAlreadyFull);
                break;

            case ConvoyStatus.Closed:
                player?.SendClientMessage(Color.Red, Messages.MissionConvoyAlreadyOnRoute);
                break;
            }
        }
Esempio n. 4
0
        public static void MakeLeader(Player leader, MissionConvoy convoy)
        {
            if (!IasPlayerAllowedToJoin(leader))
            {
                return;
            }

            convoy.Status = ConvoyStatus.Open;
            convoy.Members.Add(leader);

            leader.IsInConvoy = true;
            leader.Convoy     = convoy;

            convoy.Timer       = new Timer(TimeSpan.FromSeconds(1), true);
            convoy.Timer.Tick += (sender, e) => ConvoyController.ConvoyTimer_Tick(sender, e, convoy);

            foreach (var basePlayer in Player.All)
            {
                var player = (Player)basePlayer;

                if (player.PlayerClass == PlayerClassType.TruckDriver)
                {
                    player.SendClientMessage(Color.White, Messages.MissionConvoyOpened, leader.Name);
                }
            }
        }
Esempio n. 5
0
        public static async void OnConvoyLeaveCommand(Player sender)
        {
            if (!sender.IsInConvoy)
            {
                sender.SendClientMessage(Color.Red, Messages.PlayerNotPartOfAnyConvoy);
                return;
            }

            await MissionConvoy.PlayerLeaveConvoyAsync(sender);

            sender.SendClientMessage(Color.GreenYellow, "You left the convoy.");
        }
Esempio n. 6
0
        public static async void OnConvoyCancelCommand(Player sender)
        {
            if (!sender.IsInConvoy)
            {
                sender.SendClientMessage(Color.Red, "You are not part of any convoy.");
                return;
            }

            var convoy = sender.Convoy;
            var leader = convoy.Members[0];

            if (leader != sender)
            {
                sender.SendClientMessage(Color.Red, Messages.CommandOnlyAllowedAsConvoyLeader);
                return;
            }

            await MissionConvoy.CancelConvoyAsync(convoy);
        }
Esempio n. 7
0
        public static async void OnConvoyKickCommand(Player sender, Player target)
        {
            if (!sender.IsInConvoy)
            {
                sender.SendClientMessage(Color.Red, Messages.PlayerNotPartOfAnyConvoy);
                return;
            }

            var convoy = sender.Convoy;
            var leader = convoy.Members[0];

            if (leader != sender)
            {
                sender.SendClientMessage(Color.Red, Messages.CommandOnlyAllowedAsConvoyLeader);
                return;
            }

            if (target == sender)
            {
                sender.SendClientMessage(Color.Red, Messages.CommandNotAllowedOnSelf);
                return;
            }

            if (target.IsInConvoy && target.Convoy == convoy)
            {
                await MissionConvoy.PlayerLeaveConvoyAsync(target);

                sender.SendClientMessage(Color.GreenYellow,
                                         $"You've kicked {{0000FF}}{target.Name}{{00FF00}} from the convoy.");
                target.SendClientMessage(Color.GreenYellow,
                                         $"Leader {{0000FF}}{sender.Name}{{00FF00}} kicked you from the convoy.");
            }
            else
            {
                sender.SendClientMessage(Color.Red, "You cannot kick a player that's not part of your convoy.");
            }
        }
Esempio n. 8
0
        public static async void ConvoyTimer_Tick(object sender, EventArgs e, MissionConvoy convoy)
        {
            convoy.UpdateTextDraw();

            var leader = convoy.Members[0];

            switch (convoy.MissionStep)
            {
            case 0:
                var isSameTrailer = true;

                if (leader.IsDoingMission)
                {
                    convoy.MissionCargo       = leader.MissionCargo;
                    convoy.FromLocation       = leader.FromLocation;
                    convoy.ToLocation         = leader.ToLocation;
                    convoy.ConvoyTrailerModel = leader.Vehicle?.Trailer?.Model ?? 0;

                    if (convoy.ConvoyTrailerModel != 0)
                    {
                        foreach (var member in convoy.Members)
                        {
                            if (member == leader)
                            {
                                continue;
                            }

                            if (member.Vehicle?.Trailer?.Model == convoy.ConvoyTrailerModel)
                            {
                                continue;
                            }

                            switch (convoy.ConvoyTrailerModel)
                            {
                            case VehicleModelType.ArticleTrailer:
                            case VehicleModelType.ArticleTrailer3:
                                member.MissionTextDraw.Text = Messages.MissionConvoyCargoTrailerNeeded;
                                break;

                            case VehicleModelType.ArticleTrailer2:
                                member.MissionTextDraw.Text = Messages.MissionConvoyOreTrailerNeeded;
                                break;

                            case VehicleModelType.PetrolTrailer:
                                member.MissionTextDraw.Text = Messages.MissionConvoyFluidsTrailerNeeded;
                                break;
                            }

                            isSameTrailer = false;
                        }
                    }
                    else
                    {
                        foreach (var member in convoy.Members)
                        {
                            if (member == leader)
                            {
                                continue;
                            }

                            if (member.Vehicle?.Model == VehicleModelType.DFT30 &&
                                member.Vehicle?.Model == VehicleModelType.Flatbed)
                            {
                                continue;
                            }

                            isSameTrailer = false;
                            member.MissionTextDraw.Text = Messages.MissionConvoyNoTrailerVehicleNeeded;
                        }
                    }

                    if (isSameTrailer)
                    {
                        leader.SendClientMessage(Color.GreenYellow, Messages.MissionConvoyReadyToGo);

                        foreach (var member in convoy.Members)
                        {
                            if (member == leader)
                            {
                                continue;
                            }

                            convoy.StartMemberJob(member);
                        }

                        convoy.MissionStep = 1;
                        convoy.Status      = ConvoyStatus.Closed;
                    }
                    else
                    {
                        if (!convoy.IsLeaderInformed)
                        {
                            leader.SendClientMessage(Color.Red, Messages.MissionConvoyCantGo);
                            convoy.IsLeaderInformed = true;
                        }
                    }
                }

                break;

            case 1:
                var areAllMembersLoaded = true;

                foreach (var member in convoy.Members)
                {
                    if (member.MissionStep != 2)
                    {
                        areAllMembersLoaded = false;
                    }
                }

                if (areAllMembersLoaded)
                {
                    leader.SendClientMessage(Color.GreenYellow, Messages.MissionConvoyMembersLoaded);

                    foreach (var member in convoy.Members)
                    {
                        convoy.UpdateMemberJob(member);
                    }

                    convoy.MissionStep = 2;
                }

                break;

            case 2:
                var didAllMembersUnloaded = true;

                foreach (var member in convoy.Members)
                {
                    if (member.MissionStep != 4)
                    {
                        didAllMembersUnloaded = false;
                    }
                }

                if (didAllMembersUnloaded)
                {
                    convoy.MissionStep = 3;
                }
                break;

            case 3:
                var numberOfMembers = convoy.Members.Count;

                var payment = MissionsController.CalculatePayment(convoy.FromLocation, convoy.ToLocation,
                                                                  convoy.MissionCargo);

                if (!BonusMission.IsMissionFinished &&
                    BonusMission.RandomCargo == convoy.MissionCargo &&
                    BonusMission.RandomFromLocation == convoy.FromLocation &&
                    BonusMission.RandomToLocation == convoy.ToLocation)
                {
                    payment *= 2;
                    BonusMission.IsMissionFinished = true;
                    BasePlayer.SendClientMessageToAll(
                        $"{{00BBFF}}Convoy with leader {{FFBB00}}{leader.Name}{{00BBFF}} has finished the bonus mission.");
                }

                var bonus = numberOfMembers * 25 + 100;
                payment = payment * bonus / 100;

                foreach (var member in convoy.Members)
                {
                    await member.RewardAsync(payment, 5);

                    var memberAccount = member.Account;
                    memberAccount.ConvoyJobs++;
                    await AccountRepository.UpdateAsync(memberAccount);

                    await MissionsController.ClassEndMissionAsync(member);

                    member.SendClientMessage(Color.White,
                                             $"{{00FF00}}You finished the convoy and earned ${payment}");

                    if (member != convoy.Members[0])
                    {
                        member.MissionTextDraw.Text = Messages.MissionConvoyWaitingForLeader;
                    }
                }

                convoy.MissionCargo       = null;
                convoy.FromLocation       = null;
                convoy.ToLocation         = null;
                convoy.Status             = ConvoyStatus.Open;
                convoy.MissionStep        = 0;
                convoy.ConvoyTrailerModel = 0;
                convoy.IsLeaderInformed   = false;
                break;
            }
        }
Esempio n. 9
0
 private async void Convoy_PlayerDisconnected(object sender, DisconnectEventArgs e)
 {
     var player = sender as Player;
     await MissionConvoy.PlayerLeaveConvoyAsync(player);
 }