-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity-abilities.js
More file actions
383 lines (318 loc) · 12.2 KB
/
Copy pathentity-abilities.js
File metadata and controls
383 lines (318 loc) · 12.2 KB
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
/**
* ENTITY-ABILITIES.JS
* Special abilities system for evolved entities
* Implements teleportation, phasing, splitting, merging, energy burst, and camouflage
*/
class EntityAbilities {
constructor() {
this.cooldowns = new Map(); // entity.id -> { abilityName: timestamp }
this.activeEffects = new Map(); // entity.id -> { effectName: data }
}
/**
* Check if ability is on cooldown
*/
isOnCooldown(entity, abilityName) {
const cooldowns = this.cooldowns.get(entity.id) || {};
const lastUsed = cooldowns[abilityName] || 0;
const cooldownDuration = this.getCooldownDuration(abilityName);
return Date.now() - lastUsed < cooldownDuration;
}
getCooldownDuration(abilityName) {
const durations = {
teleport: 3000, // 3 seconds
phase: 5000, // 5 seconds
split: 10000, // 10 seconds
merge: 5000, // 5 seconds
energyBurst: 4000, // 4 seconds
camouflage: 8000 // 8 seconds
};
return durations[abilityName] || 5000;
}
setCooldown(entity, abilityName) {
const cooldowns = this.cooldowns.get(entity.id) || {};
cooldowns[abilityName] = Date.now();
this.cooldowns.set(entity.id, cooldowns);
}
/**
* TELEPORTATION
* Instant short-range jump with particle effects
*/
teleport(entity, config = {}) {
if (this.isOnCooldown(entity, 'teleport')) return false;
if (entity.stage < 4) return false; // Only Transcendent and above
const maxDistance = config.maxDistance || 200;
const angle = Math.random() * Math.PI * 2;
const distance = 100 + Math.random() * maxDistance;
const newX = entity.position.x + Math.cos(angle) * distance;
const newY = entity.position.y + Math.sin(angle) * distance;
// Clamp to screen bounds
entity.teleportFrom = { ...entity.position };
entity.position.x = Math.max(0, Math.min(window.innerWidth, newX));
entity.position.y = Math.max(0, Math.min(window.innerHeight, newY));
entity.teleportTo = { ...entity.position };
this.setCooldown(entity, 'teleport');
// Create visual effect
entity.teleportEffect = {
active: true,
startTime: Date.now(),
duration: 500
};
console.log(`⚡ ${entity.id} teleported!`);
return true;
}
/**
* PHASING
* Become translucent and pass through others
*/
phase(entity, config = {}) {
if (this.isOnCooldown(entity, 'phase')) return false;
if (entity.stage < 4) return false;
const duration = config.duration || 2000;
entity.phasing = {
active: true,
startTime: Date.now(),
duration: duration,
opacity: 0.3
};
this.setCooldown(entity, 'phase');
console.log(`👻 ${entity.id} is phasing!`);
return true;
}
/**
* SPLITTING
* Divide into smaller clones
*/
split(entity, entityManager, config = {}) {
if (this.isOnCooldown(entity, 'split')) return false;
if (entity.stage < 3) return false; // Only Apex and above
if (entity.size < 40) return false; // Too small to split
const cloneCount = config.cloneCount || 2;
const clones = [];
// Reduce original size
entity.size *= 0.7;
entity.rebuild();
// Create clones
for (let i = 0; i < cloneCount; i++) {
const angle = (i / cloneCount) * Math.PI * 2;
const distance = entity.size * 2;
const clone = entityManager.spawn({
x: entity.position.x + Math.cos(angle) * distance,
y: entity.position.y + Math.sin(angle) * distance,
size: entity.size * 0.8,
color: entity.color,
shape: entity.shape,
tentacles: entity.tentacles,
speed: entity.speed * 1.2,
pattern: entity.skinPattern
});
clone.stage = Math.max(0, entity.stage - 1);
clone.personality = entity.personality;
clones.push(clone);
}
this.setCooldown(entity, 'split');
console.log(`🧬 ${entity.id} split into ${cloneCount} clones!`);
return clones;
}
/**
* MERGING
* Combine with another entity to grow larger
*/
merge(entity, target, entityManager) {
if (this.isOnCooldown(entity, 'merge')) return false;
if (!target || !target.alive) return false;
if (entity.stage < 2) return false;
const dx = target.position.x - entity.position.x;
const dy = target.position.y - entity.position.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance > entity.size + target.size) return false; // Too far
// Absorb target's mass
const combinedSize = Math.sqrt(entity.size * entity.size + target.size * target.size);
entity.size = Math.min(combinedSize, 200); // Cap max size
entity.tentacles = Math.min(entity.tentacles + Math.floor(target.tentacles / 2), 20);
entity.evolutionPoints += target.evolutionPoints;
// Rebuild with new properties
entity.rebuild();
// Remove target
entityManager.removeEntity(target);
this.setCooldown(entity, 'merge');
// Visual effect
entity.mergeEffect = {
active: true,
startTime: Date.now(),
duration: 1000,
absorbedColor: target.color
};
console.log(`🔗 ${entity.id} merged with ${target.id}!`);
return true;
}
/**
* ENERGY BURST
* Emit shockwave that pushes others away
*/
energyBurst(entity, allEntities, config = {}) {
if (this.isOnCooldown(entity, 'energyBurst')) return false;
if (entity.stage < 3) return false;
const burstRadius = config.burstRadius || 300;
const burstForce = config.burstForce || 15;
let affectedCount = 0;
allEntities.forEach(other => {
if (other.id === entity.id || !other.alive) return;
const dx = other.position.x - entity.position.x;
const dy = other.position.y - entity.position.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < burstRadius && distance > 0) {
const force = burstForce * (1 - distance / burstRadius);
other.velocity.x += (dx / distance) * force;
other.velocity.y += (dy / distance) * force;
affectedCount++;
}
});
this.setCooldown(entity, 'energyBurst');
// Visual effect
entity.burstEffect = {
active: true,
startTime: Date.now(),
duration: 800,
radius: burstRadius
};
console.log(`💥 ${entity.id} energy burst affected ${affectedCount} entities!`);
return true;
}
/**
* CAMOUFLAGE
* Blend with background colors
*/
camouflage(entity, config = {}) {
if (this.isOnCooldown(entity, 'camouflage')) return false;
if (entity.stage < 3) return false;
const duration = config.duration || 5000;
entity.camouflaged = {
active: true,
startTime: Date.now(),
duration: duration,
originalColor: entity.color,
targetColor: this.getBackgroundColor()
};
this.setCooldown(entity, 'camouflage');
console.log(`🦎 ${entity.id} is camouflaged!`);
return true;
}
getBackgroundColor() {
// Sample background color (simplified - could be more sophisticated)
const colors = [
'hsl(220, 20%, 15%)',
'hsl(200, 30%, 20%)',
'hsl(240, 15%, 18%)'
];
return colors[Math.floor(Math.random() * colors.length)];
}
/**
* Update active effects
*/
updateEffects(entity) {
const now = Date.now();
// Update phasing
if (entity.phasing && entity.phasing.active) {
if (now - entity.phasing.startTime > entity.phasing.duration) {
entity.phasing.active = false;
}
}
// Update camouflage
if (entity.camouflaged && entity.camouflaged.active) {
const elapsed = now - entity.camouflaged.startTime;
if (elapsed > entity.camouflaged.duration) {
entity.camouflaged.active = false;
entity.color = entity.camouflaged.originalColor;
} else {
// Blend colors
const progress = elapsed / entity.camouflaged.duration;
if (progress < 0.2) {
// Transition to camouflage
const blend = progress / 0.2;
entity.color = this.blendColors(entity.camouflaged.originalColor, entity.camouflaged.targetColor, blend);
} else if (progress > 0.8) {
// Transition back
const blend = (progress - 0.8) / 0.2;
entity.color = this.blendColors(entity.camouflaged.targetColor, entity.camouflaged.originalColor, blend);
} else {
entity.color = entity.camouflaged.targetColor;
}
}
}
// Update teleport effect
if (entity.teleportEffect && entity.teleportEffect.active) {
if (now - entity.teleportEffect.startTime > entity.teleportEffect.duration) {
entity.teleportEffect.active = false;
}
}
// Update burst effect
if (entity.burstEffect && entity.burstEffect.active) {
if (now - entity.burstEffect.startTime > entity.burstEffect.duration) {
entity.burstEffect.active = false;
}
}
// Update merge effect
if (entity.mergeEffect && entity.mergeEffect.active) {
if (now - entity.mergeEffect.startTime > entity.mergeEffect.duration) {
entity.mergeEffect.active = false;
}
}
}
blendColors(color1, color2, ratio) {
// Simple HSL color blending
const hsl1 = this.parseHSL(color1);
const hsl2 = this.parseHSL(color2);
if (!hsl1 || !hsl2) return color1;
const h = hsl1.h + (hsl2.h - hsl1.h) * ratio;
const s = hsl1.s + (hsl2.s - hsl1.s) * ratio;
const l = hsl1.l + (hsl2.l - hsl1.l) * ratio;
return `hsl(${Math.round(h)}, ${Math.round(s)}%, ${Math.round(l)}%)`;
}
parseHSL(color) {
const match = color.match(/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)/);
if (match) {
return {
h: parseInt(match[1]),
s: parseInt(match[2]),
l: parseInt(match[3])
};
}
return null;
}
/**
* Randomly trigger abilities for AI entities
*/
autoTriggerAbilities(entity, allEntities, entityManager) {
if (entity.stage < 3) return; // Only advanced entities use abilities
const abilities = ['teleport', 'phase', 'energyBurst', 'camouflage'];
// Random chance to use ability
if (Math.random() < 0.002) { // ~0.2% chance per frame
const ability = abilities[Math.floor(Math.random() * abilities.length)];
switch (ability) {
case 'teleport':
this.teleport(entity);
break;
case 'phase':
this.phase(entity);
break;
case 'energyBurst':
this.energyBurst(entity, allEntities);
break;
case 'camouflage':
this.camouflage(entity);
break;
}
}
// Special conditions for split/merge
if (entity.stage >= 4 && Math.random() < 0.0005) {
if (entity.size > 80 && Math.random() < 0.5) {
this.split(entity, entityManager);
}
}
}
}
// Export
if (typeof window !== 'undefined') {
window.EntityAbilities = EntityAbilities;
console.log('✨ EntityAbilities loaded!');
}