| 1023 | 1024 | if (talkativeness >= rollValue) { |
| 1024 | 1025 | activatedMembers.push(member); |
| 1025 | 1026 | } |
| 1027 | + if (talkativeness > 0){ |
| 1028 | + chattyMembers.push(member); |
| 1029 | + } |
| 1026 | 1030 | } |
| 1027 | 1031 | |
| 1028 | 1032 | // pick 1 at random if no one was activated |
| 1029 | 1033 | let retries = 0; |
| 1030 | | - while (activatedMembers.length === 0 && ++retries <= members.length) { |
| 1034 | + // try to limit the selected random character to those with talkativeness > 0 |
| 1031 | | - const randomIndex = Math.floor(Math.random() * members.length); |
| 1035 | + let randomPool = chattyMembers.length > 0? chattyMembers : members; |
| 1032 | | - const character = characters.find((x) => x.avatar === members[randomIndex]); |
| 1036 | + while (activatedMembers.length === 0 && ++retries <= randomPool.length) { |
| 1037 | + const randomIndex = Math.floor(Math.random() * randomPool.length); |
| 1038 | + const character = characters.find((x) => x.avatar === randomPool[randomIndex]); |
| 1033 | 1039 | |
| 1034 | 1040 | if (!character) { |
| 1035 | 1041 | continue; |
| 1036 | 1042 | } |
| 1037 | 1043 | |
| 1038 | 1044 | activatedMembers.push(membersrandomPool[randomIndex]); |
| 1039 | 1045 | } |
| 1040 | 1046 | |
| 1041 | 1047 | // de-duplicate array of character avatars |