# Social Activities Refactor Summary

## Overview
Completed comprehensive refactor of `/home/user/lichun/ws/events/activities/social.py` to properly integrate all social activity events with the BaoLife activity tracking system.

## Date
2025-11-14

---

## Key Changes Made

### 1. Infrastructure Added

#### New SocialActivity Class
Created a dedicated `SocialActivity` class (lines 22-42) that mirrors the `ExtraCurricular` class structure:
- **Attributes**: id, title, type ('social'), focus, description, energyModifier, performanceTracking
- Properly integrates with the existing activity system
- Supports performance tracking for metrics like volunteer hours, club participation, etc.

#### New Helper Functions

**`hasActivity(person, activityTitle)`** (lines 49-51)
- Checks if a person already has an activity with the given title
- Prevents duplicate club/group memberships
- Returns boolean

**`addSocialActivity(person, activityTitle, focus, description, date, performanceTracking=False)`** (lines 54-81)
- Creates and adds a SocialActivity to a person
- Creates corresponding ActivityRecord for tracking
- Sets initial performance metrics
- Returns the created activity object

**`getActivityRecord(person, activityId)`** (lines 84-89)
- Retrieves activity record by ID
- Used for updating performance metrics

**`incrementActivityPerformance(person, activityId, amount=1)`** (lines 92-96)
- Increments performance tracking (volunteer hours, attendance, etc.)
- Future-proofing for scheduled event execution

**`buildRelationshipsAtActivity(player, activity_name, affinity_boost=5)`** (lines 99-109)
- Builds relationships with NPCs who share the same activity
- Boosts affinity with relationship characters in the same club/group
- Returns count of relationships built

---

### 2. Event Updates

#### joinClub (lines 112-197)

**Previous Issues:**
- No duplicate prevention
- Generic "Club Meeting" without variety
- No ActivityRecord tracking
- No relationship building

**Improvements:**
- **8 Club Types**: Photography, Hiking, Cooking, Art, Music, Film, Tech, Gardening
- **Duplicate Prevention**: Checks `hasActivity()` before allowing join
- **ActivityRecord**: Creates proper tracking with type='social'
- **Performance Tracking**: Tracks club participation over time
- **Schedules**: 8-12 week duration, weekly evening meetings
- **Location**: Creates community location if needed
- **Relationships**: Builds affinity with other club members (+3 per person)
- **Dynamic Messages**: Shows club-specific name and duration
- **Stats**: Social +25, Happiness +15 (unchanged from before)

**Focus System**: Uses "Socialize" focus for all clubs

---

#### volunteerWork (lines 200-295)

**Previous Issues:**
- Generic "Volunteer Work" without variety
- No duplicate prevention
- No ActivityRecord tracking
- No prestige rewards
- No relationship building

**Improvements:**
- **7 Volunteer Types**: Animal Shelter, Food Bank, Elderly Care, Environmental Cleanup, Youth Mentoring, Homeless Outreach, Library Assistance
- **Duplicate Prevention**: Checks for existing volunteer activity
- **ActivityRecord**: Creates tracking with performance=0 (volunteer hours)
- **Performance Tracking**: Can track hours volunteered
- **Schedules**: 12-24 week duration, weekly weekend mornings
- **Location**: Creates community location
- **Relationships**: Builds affinity with fellow volunteers (+4 per person)
- **Prestige Bonuses**: +5 for regular, +2 for occasional, +3 for donation
- **Dynamic Messages**: Organization-specific messages
- **Stats**:
  - Regular: Social +20, Happiness +25, Prestige +5
  - Occasional: Social +15, Happiness +20, Prestige +2
  - Donate: Money -50, Happiness +15, Prestige +3

**Focus System**: Uses "Balanced" focus for volunteer work

---

#### bookClub (lines 298-384)

**Previous Issues:**
- Generic book club without genre variety
- No duplicate prevention
- No ActivityRecord tracking
- No schedules created for "join" option
- No relationship building

**Improvements:**
- **6 Book Club Types**: Mystery, Sci-Fi, Romance, Classic Literature, Biography, Fantasy
- **Duplicate Prevention**: Checks for existing book club membership
- **ActivityRecord**: Creates tracking (can track books read)
- **Performance Tracking**: Tracks books read/discussed
- **Schedules**: 6-10 months duration (converted to weeks), weekly evening meetings
- **Location**: Creates friend location
- **Relationships**: Strong bonding with fellow readers (+5 per person)
- **Dynamic Messages**: Genre-specific club names
- **Stats**: Social +20, Intelligence +15, Happiness +15

**Focus System**: Uses "Socialize" focus
**Special Feature**: Combines social AND intelligence benefits

---

#### gamingGroup (lines 387-473)

**Previous Issues:**
- Generic "Gaming Night" without variety
- No duplicate prevention
- No ActivityRecord tracking
- Duration was in minutes (120-240) instead of weeks
- No relationship building
- No stress relief mechanic

**Improvements:**
- **6 Gaming Types**: Board Game, Video Game, Tabletop RPG, Card Game, Retro Gaming, Party Game
- **Duplicate Prevention**: Checks for existing gaming group membership
- **ActivityRecord**: Creates tracking (games played/sessions attended)
- **Performance Tracking**: Tracks participation
- **Schedules**: Fixed to 16-24 weeks, weekly weekend evenings
- **Location**: Creates friend location
- **Relationships**: Strong bonding with gaming buddies (+6 per person)
- **Stress Relief**: Added stress -10 for weekly, -5 for occasional
- **Dynamic Messages**: Gaming group type-specific messages
- **Stats**:
  - Weekly: Social +25, Happiness +20, Stress -10
  - Occasional: Social +15, Happiness +15, Stress -5

**Focus System**: Uses "Socialize" focus
**Special Feature**: Stress reduction mechanic

---

#### communityEvent (lines 476-573)

**Previous Issues:**
- Generic "community event" without variety
- No relationship building
- No prestige for organizing
- No follow-up opportunities
- No dynamic event types

**Improvements:**
- **10 Event Types**: Block Party, Festival, Farmers Market, Fundraiser, Art Fair, Music in Park, Cleanup Day, Holiday Celebration, Sports Tournament, Cultural Festival
- **Dynamic Relationship Building**:
  - Participate: Meet 1-3 people, affinity +3-8, familiarity +5-10
  - Attend: Meet 0-2 people, affinity +1-5, familiarity +3-7
  - Organize: Meet 2-5 people, affinity +5-12, familiarity +8-15
- **Prestige Bonus**: +8 for organizing events
- **Special Reward**: 30% chance for +5 diamonds when organizing
- **Dynamic Messages**: Event-specific names and relationship counts
- **Stats**:
  - Participate: Social +20, Happiness +15, Energy -15
  - Attend: Social +10, Happiness +10
  - Organize: Social +30, Happiness +25, Energy -30, Prestige +8

**Special Feature**: One-time events with dynamic relationship building rather than ongoing schedules

---

## Integration Points

### Activity System
- All recurring social activities now create proper `ActivityRecord` instances
- Records are stored in `player.c.activityRecords[]`
- Activities stored in `player.c.activities[]`
- Type is set to 'social' for all social activities

### Schedule System
- All schedules properly use the `scheduler()` class from `core.models`
- Schedules are added to `player.c.schedules[]`
- Duration is in weeks (not minutes)
- Conditions properly set: "weekly", "evening", "weekend", "morning"
- Schedules execute in `dailyPlan` via `intradayActivity.py` (lines 48-56)

### Focus System
- Clubs use "Socialize" focus (matches existing focus system)
- Volunteer work uses "Balanced" focus
- Focus stored in ActivityRecord for future use
- Can be extended for focus-specific bonuses

### Relationship System
- All ongoing activities build relationships with NPCs who share the activity
- Uses existing affinity and familiarity mechanics
- Provides player feedback on relationships built
- Community events have dynamic relationship building based on participation level

### Location System
- Creates locations as needed: community, friend
- Uses `find_by_id()` to prevent duplicate locations
- Locations stored in `player.l[]`
- Proper location types match existing system

### Performance Tracking
- All ongoing activities enable performance tracking
- Volunteer work tracks hours (starts at 0)
- Clubs track participation/attendance
- Gaming groups track sessions/games played
- Book clubs track books read
- Future: Can be used for achievements, milestones, etc.

---

## Statistics & Balancing

### Social Stat Impact
- joinClub: +25 (member), +10 (guest)
- volunteerWork: +20 (regular), +15 (occasional)
- bookClub: +20 (join), +0 (read only)
- gamingGroup: +25 (weekly), +15 (occasional)
- communityEvent: +30 (organize), +20 (participate), +10 (attend)

### Happiness Impact
All activities provide positive happiness boosts, encouraging social engagement.

### New Prestige Integration
- Volunteer work: +5 (regular), +2 (occasional), +3 (donate)
- Community organizing: +8

### Stress Reduction
- Gaming groups now reduce stress (-10 weekly, -5 occasional)

### Energy Costs
- Maintained from original design where applicable
- Community events: -15 (participate), -30 (organize)

---

## Duplicate Prevention Logic

Each recurring activity now checks:
```python
already_member = hasActivity(player.c, activity_name)
check = (...existing checks... and not already_member and ...)
```

This prevents:
- Joining the same club twice
- Volunteering at the same organization twice
- Joining the same book club twice
- Joining the same gaming group twice

**Note**: Community events are one-time, so no duplicate prevention needed.

---

## Future Enhancement Opportunities

### 1. Focus-Based Events
When player has Socialize focus in an activity, could trigger:
- Special social gatherings
- Leadership opportunities
- Extra relationship bonding events

### 2. Performance Milestones
Track performance and trigger events at milestones:
- 10 volunteer hours: Recognition certificate
- 50 club meetings: Become club officer
- 20 books read: Book club leadership

### 3. Schedule Interactions
During scheduled event execution in `dailyPlan`:
- Could increment performance automatically
- Trigger random social encounters
- Apply focus-based stat modifiers

### 4. Activity Synergies
If player has multiple social activities:
- Cross-pollinate relationships
- Social network expansion events
- Community leader recognition

### 5. NPC Activity Preferences
When creating NPCs, could assign them social activities:
- Players more likely to meet NPCs at shared activities
- Activity preferences based on personality/stats
- Dynamic social circles

---

## Testing Recommendations

1. **Duplicate Prevention**: Try joining the same club type twice
2. **Activity Records**: Verify `player.c.activityRecords` populates correctly
3. **Schedules**: Verify events appear in `dailyPlan` and execute
4. **Relationships**: Verify affinity increases when joining shared activities
5. **Location Creation**: Verify community/friend locations are created
6. **Performance Tracking**: Verify performance field updates (future feature)
7. **Edge Cases**: Test with no relationships (player.r is empty)
8. **Schedule Completion**: Test that completion message appears after duration

---

## Files Modified

- `/home/user/lichun/ws/events/activities/social.py` - Complete refactor (583 lines)

## Files Reviewed

- `/home/user/lichun/ws/core/models.py` - ActivityRecord, scheduler, personClass
- `/home/user/lichun/ws/education/education_manager.py` - ExtraCurricular pattern, setExtracurricular
- `/home/user/lichun/ws/intradayActivity.py` - Schedule execution in dailyPlan
- `/home/user/lichun/ws/functions.py` - Import structure

---

## Summary

All five social activity events have been successfully refactored to:
1. ✅ Create proper ActivityRecords with type='social'
2. ✅ Prevent duplicate club/activity memberships
3. ✅ Add performance tracking for ongoing activities
4. ✅ Link activities to social stats and relationship building
5. ✅ Use proper focus system ("Socialize" or "Balanced")
6. ✅ Create proper schedules that execute in dailyPlan
7. ✅ Add variety through randomized activity types
8. ✅ Build relationships with NPCs who share activities
9. ✅ Add prestige bonuses where appropriate
10. ✅ Maintain backward compatibility with existing event system

The social activities system is now fully integrated with BaoLife's activity tracking, schedule execution, and relationship management systems.
