(
roll: number,
{ isReading, isEvening }: PickContext,
)
| 41 | // makes him read along; evenings make him yawn more; chasing his tail is |
| 42 | // rare on purpose. |
| 43 | export 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. |
| 69 | const ACTION_EVERY_MS: [number, number] = [9000, 20000]; |
no outgoing calls