All files / my-screeps-repo daily-challenge.js

95.45% Statements 21/22
91.66% Branches 11/12
100% Functions 3/3
95.45% Lines 21/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92      4x   14x   14x 6x                                                                           6x     6x   6x               14x       4x   4x 3x   3x 1x 1x               1x 1x 1x   1x 1x 1x   1x          
// Daily Challenge System
// Auto-generated by Daily Leaderboard workflow
 
module.exports = {
    getChallenge: function () {
        const today = new Date().toISOString().split('T')[0];
 
        if (!Memory.dailyChallenge || Memory.dailyChallenge.date !== today) {
            const challenges = [
                {
                    emoji: 'šŸš€',
                    name: 'Speed Demon',
                    desc: 'Move 500 tiles',
                    metric: 'moves',
                    target: 500,
                },
                {
                    emoji: 'ā›ļø',
                    name: 'Mining Master',
                    desc: 'Harvest 5000 energy',
                    metric: 'harvested',
                    target: 5000,
                },
                {
                    emoji: 'šŸ­',
                    name: 'Architect',
                    desc: 'Build 10 structures',
                    metric: 'built',
                    target: 10,
                },
                {
                    emoji: 'šŸ”§',
                    name: 'Repairman',
                    desc: 'Repair 3000 HP',
                    metric: 'repaired',
                    target: 3000,
                },
                {
                    emoji: '🌟',
                    name: 'Controller King',
                    desc: 'Upgrade 50 times',
                    metric: 'upgrades',
                    target: 50,
                },
            ];
 
            const dayOfYear = Math.floor(
                (new Date() - new Date(new Date().getFullYear(), 0, 0)) / 86400000
            );
            const challenge = challenges[dayOfYear % challenges.length];
 
            Memory.dailyChallenge = {
                date: today,
                challenge: challenge,
                progress: 0,
                completed: false,
            };
        }
 
        return Memory.dailyChallenge;
    },
 
    updateProgress: function (metric, amount) {
        const challenge = this.getChallenge();
 
        if (challenge.challenge.metric === metric && !challenge.completed) {
            challenge.progress += amount;
 
            if (challenge.progress >= challenge.challenge.target) {
                challenge.completed = true;
                console.log(
                    `šŸŽ‰ CHALLENGE COMPLETE! ${challenge.challenge.emoji} ${challenge.challenge.name}`
                );
            }
        }
    },
 
    displayChallenge: function () {
        const challenge = this.getChallenge();
        const c = challenge.challenge;
        const percent = Math.min(100, Math.floor((challenge.progress / c.target) * 100));
 
        console.log(`\nšŸŽÆ TODAY'S CHALLENGE: ${c.emoji} ${c.name}`);
        console.log(`   ${c.desc}`);
        console.log(`   Progress: ${challenge.progress}/${c.target} (${percent}%)`);
 
        Iif (challenge.completed) {
            console.log(`   āœ… COMPLETED!`);
        }
    },
};