Exemple #1
0
        private void ExecuteOrder66()
        {
            player = LocalPlayer.Locate(Engine.Instance.State.Area);

            if (player == null)
            {
                return;
            }

            busy = true;
            var options = new List <HappeningOption>();

            HappeningOption opt       = null;
            var             mostVotes = 0;

            foreach (var h in this.options)
            {
                if (opt == null || h.Votes > mostVotes)
                {
                    opt       = h;
                    mostVotes = h.Votes;
                    options.Clear();
                    options.Add(h);
                }
                else if (h.Votes == mostVotes)
                {
                    options.Add(h);
                }
            }

            if (options.Count > 1)
            {
                Log.Info($"Picking from the same vote candidates of size {options.Count}");
                opt = options[Rnd.Int(options.Count)];
            }

            if (opt == null)
            {
                Log.Error("The jedi have escaped");
                return;
            }

            var name = Locale.Get($"happening_{opt.Id}");

            lastName = name;
            Log.Debug($"Option #{opt.Num} ({name}) has won!");


            player.GetComponent <DialogComponent>().StartAndClose($"[cl purple]{name}[cl]", 3);

            last        = player;
            happeningRn = opt;
            voteDelay   = opt.Happening.GetVoteDelay();

            toHappen = 4f;
        }
Exemple #2
0
        private void AddOption(string id, int i)
        {
            var happening = HappeningRegistry.Get(id);

            if (happening == null)
            {
                return;
            }

            var option = new HappeningOption(id, i);

            options.Add(option);

            float x = Display.UiWidth;

            foreach (var o in options)
            {
                x -= o.LabelWidth + 8;
            }

            option.Position = new Vector2(x, 18);
        }
Exemple #3
0
        public void Update(float dt)
        {
            var state = Engine.Instance.State;

            if (!(state is InGameState ig) || state.Paused)
            {
                return;
            }

            if (ig.Died)
            {
                happeningRn = null;

                if (timeLeft < 1f)
                {
                    timeLeft = 1f;
                    GenerateOptions();
                }

                return;
            }

            if (busy)
            {
                toHappen -= dt;

                if (toHappen <= 0)
                {
                    try {
                        Log.Debug($"Happening {happeningRn.Id} {happeningRn.Happening.GetType().Name}");
                        happeningRn.Happening.Happen(player);
                        Log.Debug("Done");
                    } catch (Exception e) {
                        Log.Error(e);
                    }

                    busy = false;
                    return;
                }
            }
            else if (happeningRn != null)
            {
                voteDelay -= dt;
                happeningRn.Happening.Update(dt);

                if (voteDelay <= 0)
                {
                    try {
                        happeningRn.Happening.End(last);
                        last = null;
                    } catch (Exception e) {
                        Log.Error(e);
                    }

                    voteDelay   = 0;
                    happeningRn = null;
                    GenerateOptions();
                }
            }
            else
            {
                timeLeft -= dt / TotalTime;

                if (timeLeft <= 0)
                {
                    ExecuteOrder66();
                }
            }
        }