<commit_before>define(["UpgradeCard", "process/PilotAbility1", "process/PilotAbility2", "process/PilotAbility3", "process/PilotAbility4", "process/Observer", "process/UpgradeAbility1", "process/UpgradeAbility2", "process/UpgradeAbility3", "process/UpgradeAbility4"],
    function(UpgradeCard, PilotAbility1, PilotAbility2, PilotAbility3, PilotAbility4, Observer, UpgradeAbility1, UpgradeAbility2, UpgradeAbility3, UpgradeAbility4)
    {
        "use strict";

        function PhaseObserver(store)
        {
            InputValidator.validateNotNull("store", store);

            this.onChange = function(phaseKey)
            {
                this.performPilotAbilities(phaseKey);
                this.performUpgradeAbilities(phaseKey);
            };

            this.performPilotAbilities = function(phaseKey)
            {
                [PilotAbility1, PilotAbility2, PilotAbility3, PilotAbility4].forEach(function(pilotAbility)
                {
                    var abilities = pilotAbility[phaseKey];

                    if (abilities !== undefined)
                    {
                        var tokens = Object.values(store.getState().tokens);

                        tokens.forEach(function(token)
                        {
                            var pilotKey = token.pilotKey();
                            var pilot = token.pilot();
                            var ability = abilities[pilotKey];

                            if (ability !== undefined && !pilot.agentInput)
                            {
                                if (ability.condition && ability.consequent)
                                {
                                    if (ability.condition(store, token))
                                    {
                                        ability.consequent(store, token);
                                    }
                                }
                                else
                                {
                                    ability(store, token);
                                }
                            }
                        });
                    }
                });
            };

            this.performUpgradeAbilities = function(phaseKey)
            {
                [UpgradeAbility1, UpgradeAbility2, UpgradeAbility3, UpgradeAbility4].forEach(function(upgradeAbility)
                {
                    var abilities = upgradeAbility[phaseKey];

                    if (abilities !== undefined)
                    {
                        var tokens = Object.values(store.getState().tokens);

                        tokens.forEach(function(token)
                        {
                            token.upgradeKeys().forEach(function(upgradeKey)
                            {
                                var ability = abilities[upgradeKey];
                                var upgrade = UpgradeCard.properties[upgradeKey];

                                if (ability !== undefined && !upgrade.agentInput)
                                {
                                    if (ability.condition && ability.consequent)
                                    {
                                        if (ability.condition(store, token))
                                        {
                                            ability.consequent(store, token);
                                        }
                                    }
                                    else
                                    {
                                        ability(store, token);
                                    }
                                }
                            });
                        });
                    }
                });
            };

            this.select = function(state)
            {
                return state.phaseKey;
            };

            var unsubscribe = Observer.observeStore(store, this.select, this.onChange.bind(this), false);<commit_msg>Avoided a bug where token.upgradeKeys was missing.<commit_after>define(["UpgradeCard", "process/PilotAbility1", "process/PilotAbility2", "process/PilotAbility3", "process/PilotAbility4", "process/Observer", "process/UpgradeAbility1", "process/UpgradeAbility2", "process/UpgradeAbility3", "process/UpgradeAbility4"],
    function(UpgradeCard, PilotAbility1, PilotAbility2, PilotAbility3, PilotAbility4, Observer, UpgradeAbility1, UpgradeAbility2, UpgradeAbility3, UpgradeAbility4)
    {
        "use strict";

        function PhaseObserver(store)
        {
            InputValidator.validateNotNull("store", store);

            this.onChange = function(phaseKey)
            {
                this.performPilotAbilities(phaseKey);
                this.performUpgradeAbilities(phaseKey);
            };

            this.performPilotAbilities = function(phaseKey)
            {
                [PilotAbility1, PilotAbility2, PilotAbility3, PilotAbility4].forEach(function(pilotAbility)
                {
                    var abilities = pilotAbility[phaseKey];

                    if (abilities !== undefined)
                    {
                        var tokens = Object.values(store.getState().tokens);

                        tokens.forEach(function(token)
                        {
                            var pilotKey = token.pilotKey();
                            var pilot = token.pilot();
                            var ability = abilities[pilotKey];

                            if (ability !== undefined && !pilot.agentInput)
                            {
                                if (ability.condition && ability.consequent)
                                {
                                    if (ability.condition(store, token))
                                    {
                                        ability.consequent(store, token);
                                    }
                                }
                                else
                                {
                                    ability(store, token);
                                }
                            }
                        });
                    }
                });
            };

            this.performUpgradeAbilities = function(phaseKey)
            {
                [UpgradeAbility1, UpgradeAbility2, UpgradeAbility3, UpgradeAbility4].forEach(function(upgradeAbility)
                {
                    var abilities = upgradeAbility[phaseKey];

                    if (abilities !== undefined)
                    {
                        var tokens = Object.values(store.getState().tokens);

                        tokens.forEach(function(token)
                        {
                            if (token.upgradeKeys)
                            {
                                token.upgradeKeys().forEach(function(upgradeKey)
                                {
                                    var ability = abilities[upgradeKey];
                                    var upgrade = UpgradeCard.properties[upgradeKey];

                                    if (ability !== undefined && !upgrade.agentInput)
                                    {
                                        if (ability.condition && ability.consequent)
                                        {
                                            if (ability.condition(store, token))
                                            {
                                                ability.consequent(store, token);
                                            }
                                        }
                                        else
                                        {
                                            ability(store, token);
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
            };

            this.select = function(state)
            {
                return state.phaseKey;
            };

            var unsubscribe = Observer.observeStore(store, this.select, this.onChange.bind(this), false);
{'fraction_non_alphanumeric': 0.07665294260111408, 'fraction_numerical': 0.00581254541051102, 'mean_word_length': 0.8534560143626571, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 50, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '936254', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1587, 'n_words': 243}