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

Function pickPatchyIdleAction

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

Source from the content-addressed store, hash-verified

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