All files / my-screeps-repo visual.effects.js

92.19% Statements 130/141
77.46% Branches 55/71
100% Functions 14/14
99.18% Lines 121/122

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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413        4x     4x 4x           62x 4x 4x   62x     4x         6x 4x   4x 50x 50x 50x 50x   50x                       3x 3x 3x     3x 9x                   3x 36x 36x 36x   36x               3x                   4x 4x     4x                 4x 28x                   4x             4x                       4x 4x     4x 1x 3x 1x   2x     4x               4x 2x 2x               6x 6x     6x               6x         6x           6x                     5x 5x 5x 5x 5x 5x     5x             5x               5x 1x 4x   4x 2x   2x     5x           5x                       8x 5x 1x   5x   3x 3x                   3x 2x     3x   3x 1x     3x 12x 12x                       5x 5x   5x 5x 5x   5x             5x 2x 2x               2x 2x   2x 16x 16x 16x 16x   16x                     4x 4x 4x   4x 19x 19x 19x 19x   19x                   3x 3x   3x                       5x 4x   4x             4x                   7x 7x   7x                 7x   7x       7x                 4x  
/**
 * Visual Effects System - Z世代向けドーパミン爆発ビジュアル
 */
 
const adaptiveSystem = require('system.adaptive');
 
// ⚡ PERFORMANCE: Per-tick cache for visual effects enablement
let _isVfxEnabledTick = -1;
let _isVfxEnabledValue = true;
 
/**
 * Checks if visual effects are enabled, with per-tick caching.
 */
function isVfxEnabled() {
    if (typeof Game !== 'undefined' && Game.time !== _isVfxEnabledTick) {
        _isVfxEnabledTick = Game.time;
        _isVfxEnabledValue = adaptiveSystem.isEnabled('visualEffects');
    }
    return _isVfxEnabledValue;
}
 
const visualEffects = {
    /**
     * 派手なパーティクルエフェクト
     */
    particles: function (pos, color = '#FFD700', count = 20) {
        if (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        for (let i = 0; i < count; i++) {
            const angle = (Math.PI * 2 * i) / count;
            const distance = 0.5 + Math.random() * 0.5;
            const x = pos.x + Math.cos(angle) * distance;
            const y = pos.y + Math.sin(angle) * distance;
 
            visual.circle(x, y, {
                radius: 0.1 + Math.random() * 0.2,
                fill: color,
                opacity: 0.8,
            });
        }
    },
 
    /**
     * 成功時の爆発エフェクト
     */
    successExplosion: function (pos) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
        const colors = ['#FFD700', '#FFA500', '#FF69B4', '#00FF00', '#00FFFF'];
 
        // 外側の輪
        for (let ring = 1; ring <= 3; ring++) {
            visual.circle(pos.x, pos.y, {
                radius: ring * 0.5,
                fill: 'transparent',
                stroke: colors[ring % colors.length],
                strokeWidth: 0.1,
                opacity: 1 - ring * 0.2,
            });
        }
 
        // スターバースト
        for (let i = 0; i < 12; i++) {
            const angle = (Math.PI * 2 * i) / 12;
            const endX = pos.x + Math.cos(angle) * 1.5;
            const endY = pos.y + Math.sin(angle) * 1.5;
 
            visual.line(pos.x, pos.y, endX, endY, {
                color: colors[i % colors.length],
                width: 0.15,
                opacity: 0.8,
            });
        }
 
        // 中心の星
        visual.text('⭐', pos.x, pos.y, {
            color: '#FFD700',
            font: 1.5,
        });
    },
 
    /**
     * レベルアップエフェクト
     */
    levelUp: function (pos, level) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        // 虹色の輪
        const colors = [
            '#FF0000',
            '#FF7F00',
            '#FFFF00',
            '#00FF00',
            '#0000FF',
            '#4B0082',
            '#9400D3',
        ];
        for (let i = 0; i < colors.length; i++) {
            visual.circle(pos.x, pos.y, {
                radius: 2 + i * 0.2,
                fill: 'transparent',
                stroke: colors[i],
                strokeWidth: 0.15,
                opacity: 0.7,
            });
        }
 
        // LEVEL UP!
        visual.text('LEVEL UP!', pos.x, pos.y - 1.5, {
            color: '#FFD700',
            font: 1.2,
            stroke: '#000000',
            strokeWidth: 0.1,
        });
 
        visual.text(`Lv.${level}`, pos.x, pos.y + 1.5, {
            color: '#00FF00',
            font: 2,
            stroke: '#000000',
            strokeWidth: 0.15,
        });
    },
 
    /**
     * コンボカウンター
     */
    combo: function (pos, count) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        let color;
        if (count >= 10) {
            color = '#FF0000';
        } else if (count >= 5) {
            color = '#FF69B4';
        } else {
            color = '#FFD700';
        }
 
        visual.text(`${count}x COMBO!`, pos.x, pos.y, {
            color: color,
            font: 1 + count * 0.05,
            stroke: '#000000',
            strokeWidth: 0.1,
        });
 
        // 炎エフェクト
        if (count >= 5) {
            visual.text('🔥', pos.x - 2, pos.y, { font: 1 });
            visual.text('🔥', pos.x + 2, pos.y, { font: 1 });
        }
    },
 
    /**
     * 達成通知
     */
    achievement: function (pos, title, icon = '🏆') {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        // 背景ボックス
        visual.rect(pos.x - 3, pos.y - 1, 6, 2, {
            fill: '#000000',
            opacity: 0.8,
            stroke: '#FFD700',
            strokeWidth: 0.1,
        });
 
        // アイコン
        visual.text(icon, pos.x - 2, pos.y, {
            font: 1.5,
        });
 
        // タイトル
        visual.text(title, pos.x + 0.5, pos.y - 0.3, {
            color: '#FFD700',
            font: 0.8,
            align: 'left',
        });
 
        visual.text('Achievement Unlocked!', pos.x + 0.5, pos.y + 0.5, {
            color: '#FFFFFF',
            font: 0.5,
            align: 'left',
        });
    },
 
    /**
     * プログレスバー
     */
    progressBar: function (pos, current, max, label = '') {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
        const width = 3;
        const height = 0.3;
        const progress = max > 0 ? Math.min(current / max, 1) : 0;
        const percent = Math.floor(progress * 100);
 
        // 全体の背景(視認性向上)
        visual.rect(pos.x - width / 2 - 0.1, pos.y - 1.0, width + 0.2, 1.4, {
            fill: '#000000',
            opacity: 0.5,
            stroke: 'transparent',
        });
 
        // 背景
        visual.rect(pos.x - width / 2, pos.y - height / 2, width, height, {
            fill: '#333333',
            stroke: '#FFFFFF',
            strokeWidth: 0.05,
        });
 
        // プログレス
        let color;
        if (progress >= 1.0) {
            color = '#FFD700'; // Gold (Completed)
        } else Iif (progress >= 0.8) {
            color = '#00FF00'; // Green (Near Completion)
        } else if (progress >= 0.5) {
            color = '#FFFF00'; // Yellow (Midway)
        } else {
            color = '#FF0000'; // Red (Just Started)
        }
 
        visual.rect(pos.x - width / 2, pos.y - height / 2, width * progress, height, {
            fill: color,
            opacity: 0.8,
        });
 
        // テキスト
        visual.text(`${label} ${percent}%`, pos.x, pos.y - 0.65, {
            color: '#FFFFFF',
            font: 0.45,
            stroke: '#000000',
            strokeWidth: 0.05,
        });
    },
 
    /**
     * レインボートレイル
     */
    rainbowTrail: function (creep) {
        if (!isVfxEnabled()) {
            if (creep.memory.trailPositions) {
                delete creep.memory.trailPositions;
            }
            return;
        }
        const visual = new RoomVisual(creep.room.name);
        const colors = [
            '#FF0000',
            '#FF7F00',
            '#FFFF00',
            '#00FF00',
            '#0000FF',
            '#4B0082',
            '#9400D3',
        ];
 
        if (!creep.memory.trailPositions) {
            creep.memory.trailPositions = [];
        }
 
        creep.memory.trailPositions.push({ x: creep.pos.x, y: creep.pos.y });
 
        if (creep.memory.trailPositions.length > 10) {
            creep.memory.trailPositions.shift();
        }
 
        for (let i = 0; i < creep.memory.trailPositions.length; i++) {
            const trailPos = creep.memory.trailPositions[i];
            visual.circle(trailPos.x, trailPos.y, {
                radius: 0.2,
                fill: colors[i % colors.length],
                opacity: 0.3 + i * 0.07,
            });
        }
    },
 
    /**
     * ダメージ数字
     */
    damageNumber: function (pos, amount, isCritical = false) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        const color = isCritical ? '#FF0000' : '#FFA500';
        const size = isCritical ? 1.5 : 1;
        const text = isCritical ? `${amount} CRIT!` : `${amount}`;
 
        visual.text(text, pos.x, pos.y - 1, {
            color: color,
            font: size,
            stroke: '#000000',
            strokeWidth: 0.1,
        });
 
        if (isCritical) {
            visual.text('💥', pos.x - 0.5, pos.y - 1, { font: 1 });
            visual.text('💥', pos.x + 0.5, pos.y - 1, { font: 1 });
        }
    },
 
    /**
     * エネルギー回復エフェクト
     */
    healEffect: function (pos) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        for (let i = 0; i < 8; i++) {
            const angle = (Math.PI * 2 * i) / 8;
            const distance = 0.3 + (Game.time % 10) * 0.05;
            const x = pos.x + Math.cos(angle) * distance;
            const y = pos.y + Math.sin(angle) * distance;
 
            visual.text('💚', x, y, {
                font: 0.5,
                opacity: 1 - (Game.time % 10) * 0.1,
            });
        }
    },
 
    /**
     * スターエフェクト
     */
    stars: function (pos, count = 5) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
        const emojis = ['⭐', '✨', '🌟', '💫'];
 
        for (let i = 0; i < count; i++) {
            const angle = (Math.PI * 2 * i) / count + Game.time * 0.05;
            const distance = 0.8;
            const x = pos.x + Math.cos(angle) * distance;
            const y = pos.y + Math.sin(angle) * distance;
 
            visual.text(emojis[i % emojis.length], x, y, {
                font: 0.6,
            });
        }
    },
 
    /**
     * ストリークカウンター
     */
    streak: function (pos, days) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        visual.text(`🔥 ${days} DAY STREAK! 🔥`, pos.x, pos.y, {
            color: days >= 7 ? '#FF0000' : days >= 3 ? '#FF69B4' : '#FFD700',
            font: 1.2,
            stroke: '#000000',
            strokeWidth: 0.1,
        });
    },
 
    /**
     * スコアポップアップ
     */
    scorePopup: function (pos, points, label = 'POINTS') {
        if (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        visual.text(`+${points}`, pos.x, pos.y - 0.5, {
            color: '#FFD700',
            font: 1,
            stroke: '#000000',
            strokeWidth: 0.1,
        });
 
        visual.text(label, pos.x, pos.y + 0.5, {
            color: '#FFFFFF',
            font: 0.6,
        });
    },
 
    /**
     * ランクバッジ
     */
    rankBadge: function (pos, rank) {
        Iif (!isVfxEnabled()) return;
        const visual = new RoomVisual(pos.roomName);
 
        const badges = {
            Newbie: { icon: '🌱', color: '#90EE90' },
            Beginner: { icon: '🔰', color: '#87CEEB' },
            Intermediate: { icon: '⚡', color: '#FFD700' },
            Advanced: { icon: '🌟', color: '#FF69B4' },
            Expert: { icon: '💎', color: '#00CED1' },
            Master: { icon: '👑', color: '#FFD700' },
        };
 
        const badge = badges[rank] || badges['Newbie'];
 
        visual.text(badge.icon, pos.x, pos.y, {
            font: 1.5,
        });
 
        visual.text(rank, pos.x, pos.y + 1, {
            color: badge.color,
            font: 0.7,
            stroke: '#000000',
            strokeWidth: 0.05,
        });
    },
};
 
module.exports = visualEffects;