All files utils.missions.js

72.72% Statements 16/22
66.66% Branches 4/6
88.88% Functions 8/9
68.42% Lines 13/19

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 531x   3x 2x               1x               1x 1x       3x       2x 2x 1x 1x         2x                             1x  
const MissionSystem = {
    initMemory() {
        if (!Memory.missions) {
            Memory.missions = {
                active: [],
                completed: 0,
            };
        }
    },
 
    createMission(type, target, reward) {
        const mission = {
            id: Math.random().toString(36).substr(2, 9),
            type,
            target,
            reward,
            createdAt: Game.time,
            status: 'active',
        };
        Memory.missions.active.push(mission);
        return mission;
    },
 
    getMissionsForCreep(creep) {
        return Memory.missions.active.filter((m) => m.status === 'active');
    },
 
    completeMission(missionId) {
        const mission = Memory.missions.active.find((m) => m.id === missionId);
        if (mission) {
            mission.status = 'completed';
            Memory.missions.completed++;
        }
    },
 
    getActiveMissions() {
        return Memory.missions.active.filter((m) => m.status === 'active');
    },
 
    createRandomMission() {
        const types = ['scout', 'harvest_boost', 'defense_patrol', 'build_sprint'];
        const type = types[Math.floor(Math.random() * types.length)];
 
        const targets = Object.values(Game.rooms)[0];
        const rewards = [100, 250, 500];
        const reward = rewards[Math.floor(Math.random() * rewards.length)];
 
        return this.createMission(type, targets ? targets.name : 'sim', reward);
    },
};
 
module.exports = MissionSystem;