So, looking through the code, when it comes to fooling around in class, the relevant bits are that, at the start of the fooling around, a random number between 1 and 15 (inclusive) is chosen and assigned to the variable D20. Various actions will increase the value of D20. If D20 reaches greater than or equal to 15 and another girl is in the room with you, said girl will notice. If D20 reaches greater than or equal to 21, the teacher will notice. If D20 reaches greater than or equal to 31, the class will notice you (and be wondering about what the teacher is doing behind the podium). If D20 reaches greater than or equal to 50, the class stops paying attention to the lecture and enjoys the show you and the teacher are putting on.
- If you begin touching the pussy of a girl who you haven't touched the pussy of outside this event (since this event doesn't trigger the flag that you've touched her pussy already), D20 is increased by 2.
- If you fondle her pussy, D20 increases by 5 (this is potentially in addition to the above +2).
- If you begin fondling the breasts of a girl you've not previously fondled the breasts of outside this event, D20 increases by 5.
- If you fondle her breasts, D20 increases by 7.
- If the girl orgasms (triggered at 95 lust or more), D20 increases by 15.
- If you push a girl too far, D20 increases by 20. If the teacher has already spotted what you're doing and started playing with herself, the event ends.
- If a second girl is present who sees your actions and doesn't approve, the value is increased by 15. If the teacher has already spotted what you're doing and started playing with herself, the event ends.
- If a second girl is present who joined in and orgasms (triggered at 95 lust or more), D20 increases by 15.
- If the teacher has started playing with herself and orgasms (triggered at 95 lust or more), D20 increases by 15.
As noted, at D20 >= 15, a second girl will notice if one is present. When she sees you, the game will check if she has at least 1500 total stats, and that her like value for the girl you are fooling around with is at least 600. If so she will be into it and not interrupt. If she additionally has at least 800 Inhibition or the exhibitionist trait, she will start playing with herself for the remainder of the event. If she did not have at least 1500 total stats or did not like the girl you're fooling around with enough, she will disapprove, adding 15 to D20 as noted when she first notices, and if you keep going after that, she will leave after your next action.
When D20 hits 21 or greater, there will first be a check to see if the girl has either the exhibitionist trait, or at least 700 inhibition. If not, it will count as going too far and she won't continue. After that check (regardless of outcome), the teacher will notice. If the teacher has combine stats of at least 1500 and her value for liking the girl is at least 600, she will let things continue (or not mind if the girl stops from considering things to have gone too far). Further, if the teacher has at least 800 inhibition or the exhibitionist trait, she'll start playing with herself behind the podium. If the teacher does not have combine stats of at least 1500 or doesn't like the girl you're playing with enough (or if the teacher is Dr. McCoy), she'll stop what you are doing and send you to the headmasters office (if you have executed the plan for the girl to make the headmaster stop caring what you do with her, you'll both go back to your room instead).
Oddly, the teacher catching you and letting you continue, but deciding not to join in does not add the "go on" flag which causes a few things to end the event immediately. Additionally, getting D20 to the 31 and 50 break points has no impact outside some descriptive text of what the class seeing you and their reactions (the specific lines noted for those each action are randomly selected).
Regarding the time the event takes, the Round variable tracks how long you have before being forced to progress to the next time slot (as normal) with a value of 100 meaning that you just started the time slot, and a value of 0 meaning that you are out of time. Starting out flirting with the girl will subtract 20 from Round. Each action performed will subtract 7. If Round gets to 15 or less (after the 7 is subtracted for the current action), you will run out of time as class wraps up.