Beispiel #1
0
        public PwBar()
        {
            InitializeComponent();
            tas = Program.TasClient;
            timerLabel.AutoSize  = true;
            headerLabel.AutoSize = true;

            timer          = new Timer();
            timer.Interval = 1000;
            timer.Tick    += (sender, args) =>
            {
                if (Program.NotifySection.Contains(this))
                {
                    timerLabel.Text = PlasmaShared.Utils.PrintTimeRemaining((int)deadline.Subtract(DateTime.Now).TotalSeconds);
                }
            };
            timer.Start();

            pnl.Controls.Add(timerLabel);
            pnl.Controls.Add(headerLabel);

            tas.Extensions.JsonDataReceived += (sender, e) =>
            {
                var newPw = e as PwMatchCommand;
                if (newPw != null)
                {
                    pw = newPw;
                    UpdateGui();
                }
            };

            tas.MyExtensionsChanged += (sender, args) => UpdateGui();
        }
Beispiel #2
0
        public PwMatchCommand GenerateLobbyCommand()
        {
            PwMatchCommand command;

            if (Challenge == null)
            {
                command = new PwMatchCommand(PwMatchCommand.ModeType.Attack)
                {
                    Options         = AttackOptions.Select(x => x.ToVoteOption(PwMatchCommand.ModeType.Attack)).ToList(),
                    DeadlineSeconds = (int)GetAttackDeadline().Subtract(DateTime.UtcNow).TotalSeconds,
                    AttackerFaction = AttackingFaction.Shortcut
                };
            }
            else
            {
                command = new PwMatchCommand(PwMatchCommand.ModeType.Defend)
                {
                    Options = new List <PwMatchCommand.VoteOption> {
                        Challenge.ToVoteOption(PwMatchCommand.ModeType.Defend)
                    },
                    DeadlineSeconds  = (int)GetAcceptDeadline().Subtract(DateTime.UtcNow).TotalSeconds,
                    AttackerFaction  = AttackingFaction.Shortcut,
                    DefenderFactions = GetDefendingFactions(Challenge).Select(x => x.Shortcut).ToList()
                };
            }
            return(command);
        }
Beispiel #3
0
        public PwMatchCommand GenerateLobbyCommand()
        {
            PwMatchCommand command = null;

            try
            {
                if (GlobalConst.PlanetWarsMode != PlanetWarsModes.Running)
                {
                    return(new PwMatchCommand(PwMatchCommand.ModeType.Clear));
                }

                if (Challenge == null)
                {
                    command = new PwMatchCommand(PwMatchCommand.ModeType.Attack)
                    {
                        Options         = AttackOptions.Select(x => x.ToVoteOption(PwMatchCommand.ModeType.Attack)).ToList(),
                        Deadline        = GetAttackDeadline(),
                        DeadlineSeconds = (int)GetAttackDeadline().Subtract(DateTime.UtcNow).TotalSeconds,
                        AttackerFaction = AttackingFaction.Shortcut
                    }
                }
                ;
                else
                {
                    command = new PwMatchCommand(PwMatchCommand.ModeType.Defend)
                    {
                        Options = new List <PwMatchCommand.VoteOption> {
                            Challenge.ToVoteOption(PwMatchCommand.ModeType.Defend)
                        },
                        Deadline         = GetAcceptDeadline(),
                        DeadlineSeconds  = (int)GetAcceptDeadline().Subtract(DateTime.UtcNow).TotalSeconds,
                        AttackerFaction  = AttackingFaction.Shortcut,
                        DefenderFactions = GetDefendingFactions(Challenge).Select(x => x.Shortcut).ToList()
                    }
                };
            }
            catch (Exception ex)
            {
                Trace.TraceError("PlanetWars {0}: {1}", nameof(GenerateLobbyCommand), ex);
            }
            return(command);
        }