MCPcopy Create free account
hub / github.com/dailydotdev/apps / pickPatchyIdleAction

Function pickPatchyIdleAction

packages/shared/src/features/patchy/patchyIdle.ts:43–66  ·  view source on GitHub ↗
(
  roll: number,
  { isReading, isEvening }: PickContext,
)

Source from the content-addressed store, hash-verified

41// makes him read along; evenings make him yawn more; chasing his tail is
42// rare on purpose.
43export const pickPatchyIdleAction = (
44 roll: number,
45 { isReading, isEvening }: PickContext,
46): PatchyIdleActionName => {
47 const weights: [PatchyIdleActionName, number][] = [
48 ['glance', isReading ? 1 : 4],
49 ['read', isReading ? 6 : 0],
50 ['earflop', 2],
51 ['tongue', 2],
52 ['wink', 1],
53 ['yawn', isEvening ? 3 : 1],
54 ['spin', 0.4],
55 ];
56 const total = weights.reduce((sum, [, weight]) => sum + weight, 0);
57 let left = Math.min(Math.max(roll, 0), 0.9999) * total;
58 for (let index = 0; index < weights.length; index += 1) {
59 const [name, weight] = weights[index];
60 if (left < weight) {
61 return name;
62 }
63 left -= weight;
64 }
65 return 'glance';
66};
67
68// Seconds between micro-actions, and between blinks.
69const ACTION_EVERY_MS: [number, number] = [9000, 20000];

Callers 3

shareFunction · 0.90
patchyIdle.spec.tsFile · 0.90
actionLoopFunction · 0.85

Calls

no outgoing calls

Tested by 1

shareFunction · 0.72