namespace = board_games

##################################################
# # Playing a Board Game
# 0001 - 0010	The Greatest Game - Match
# 0011 - 0030	Processing & Invalidation events
# 0031 - 0030	The Greatest Game - Winner
# 0041 - 0040	The Greatest Game - Loser
##################################################










##################################################
# PLAYING CHESS

##################################################
# The Greatest Game
# by Ewan Cowhig Croft
# 0001 - 0010
##################################################

scripted_effect bg_play_move_type_effect = {
	# Set the move type played.
	## Either we're scope:bg_defender...
	if = {
		limit = { this = scope:bg_defender }
		save_scope_value_as = {
			name = bg_defender_move
			value = flag:$SKILL$
		}
	}
	## Or else we must be scope:bg_attacker.
	else = {
		save_scope_value_as = {
			name = bg_attacker_move
			value = flag:$SKILL$
		}
	}
	# Run the duel.
	duel = {
		skill = $SKILL$
		value = decent_skill_rating
		# Crit success.
		10 = {
			show_chance = no
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			bg_play_move_type_effect_extraneous_advantages_self_modifier = yes
			desc = board_games.0001.$LOC_KEY$.tt.crit_success
			custom_tooltip = board_games.0001.$LOC_KEY$.tt.crit_success.tt
			# Save the result.
			set_variable = {
				name = bg_move_result
				value = flag:crit_success
			}
		}
		# Success.
		40 = {
			show_chance = no
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			bg_play_move_type_effect_extraneous_advantages_self_modifier = yes
			desc = board_games.0001.$LOC_KEY$.tt.success
			custom_tooltip = board_games.0001.$LOC_KEY$.tt.success.tt
			# Save the result.
			set_variable = {
				name = bg_move_result
				value = flag:success
			}
		}
		# Failure.
		40 = {
			show_chance = no
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			bg_play_move_type_effect_extraneous_advantages_opponent_modifier = yes
			desc = board_games.0001.$LOC_KEY$.tt.failure
			custom_tooltip = board_games.0001.$LOC_KEY$.tt.failure.tt
			# Save the result.
			set_variable = {
				name = bg_move_result
				value = flag:failure
			}
		}
		# Crit failure.
		10 = {
			show_chance = no
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			bg_play_move_type_effect_extraneous_advantages_opponent_modifier = yes
			desc = board_games.0001.$LOC_KEY$.tt.crit_failure
			custom_tooltip = board_games.0001.$LOC_KEY$.tt.crit_failure.tt
			# Save the result.
			set_variable = {
				name = bg_move_result
				value = flag:crit_failure
			}
		}
	}
}

#	Main board game processing event.
board_games.0001 = {
	type = character_event
	window = duel_event
	title = board_games.0001.t
	desc = {
		# Intro section.
		first_valid = {
			# Is this our first move?
			triggered_desc = {
				trigger = {
					scope:bg_defender.var:bg_current_round = 1
					this = scope:bg_defender
				}
				desc = board_games.0001.desc.intro.opening.defender
			}
			triggered_desc = {
				trigger = {
					scope:bg_defender.var:bg_current_round = 1
					this = scope:bg_attacker
				}
				desc = board_games.0001.desc.intro.opening.attacker
			}
			# Otherwise, standard chained intro.
			desc = board_games.0001.desc.intro.subsequent
		}
		# What did our opponent play?
		first_valid = {
			## Diplomacy
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							exists = scope:bg_defender
							exists = scope:bg_attacker_move
							this = scope:bg_defender
							scope:bg_attacker_move = flag:diplomacy
						}
						AND = {
							exists = scope:bg_attacker
							exists = scope:bg_defender_move
							this = scope:bg_attacker
							scope:bg_defender_move = flag:diplomacy
						}
					}
				}
				desc = {
					first_valid = {
						# Crit Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_success
									}
								}
							}
							desc = board_games.0001.desc.intro.diplomacy.crit_success
						}
						# Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:success
									}
								}
							}
							desc = board_games.0001.desc.intro.diplomacy.success
						}
						# Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:failure
									}
								}
							}
							desc = board_games.0001.desc.intro.diplomacy.failure
						}
						# Crit Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_failure
									}
								}
							}
							desc = board_games.0001.desc.intro.diplomacy.crit_failure
						}
					}
				}
			}
			## Martial
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							exists = scope:bg_defender
							exists = scope:bg_attacker_move
							this = scope:bg_defender
							scope:bg_attacker_move = flag:martial
						}
						AND = {
							exists = scope:bg_attacker
							exists = scope:bg_defender_move
							this = scope:bg_attacker
							scope:bg_defender_move = flag:martial
						}
					}
				}
				desc = {
					first_valid = {
						# Crit Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_success
									}
								}
							}
							desc = board_games.0001.desc.intro.martial.crit_success
						}
						# Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:success
									}
								}
							}
							desc = board_games.0001.desc.intro.martial.success
						}
						# Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:failure
									}
								}
							}
							desc = board_games.0001.desc.intro.martial.failure
						}
						# Crit Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_failure
									}
								}
							}
							desc = board_games.0001.desc.intro.martial.crit_failure
						}
					}
				}
			}
			## Stewardship
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							exists = scope:bg_defender
							exists = scope:bg_attacker_move
							this = scope:bg_defender
							scope:bg_attacker_move = flag:stewardship
						}
						AND = {
							exists = scope:bg_attacker
							exists = scope:bg_defender_move
							this = scope:bg_attacker
							scope:bg_defender_move = flag:stewardship
						}
					}
				}
				desc = {
					first_valid = {
						# Crit Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_success
									}
								}
							}
							desc = board_games.0001.desc.intro.stewardship.crit_success
						}
						# Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:success
									}
								}
							}
							desc = board_games.0001.desc.intro.stewardship.success
						}
						# Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:failure
									}
								}
							}
							desc = board_games.0001.desc.intro.stewardship.failure
						}
						# Crit Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_failure
									}
								}
							}
							desc = board_games.0001.desc.intro.stewardship.crit_failure
						}
					}
				}
			}
			## Intrigue
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							exists = scope:bg_defender
							exists = scope:bg_attacker_move
							this = scope:bg_defender
							scope:bg_attacker_move = flag:intrigue
						}
						AND = {
							exists = scope:bg_attacker
							exists = scope:bg_defender_move
							this = scope:bg_attacker
							scope:bg_defender_move = flag:intrigue
						}
					}
				}
				desc = {
					first_valid = {
						# Crit Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_success
									}
								}
							}
							desc = board_games.0001.desc.intro.intrigue.crit_success
						}
						# Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:success
									}
								}
							}
							desc = board_games.0001.desc.intro.intrigue.success
						}
						# Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:failure
									}
								}
							}
							desc = board_games.0001.desc.intro.intrigue.failure
						}
						# Crit Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_failure
									}
								}
							}
							desc = board_games.0001.desc.intro.intrigue.crit_failure
						}
					}
				}
			}
			## Learning
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							exists = scope:bg_defender
							exists = scope:bg_attacker_move
							this = scope:bg_defender
							scope:bg_attacker_move = flag:learning
						}
						AND = {
							exists = scope:bg_attacker
							exists = scope:bg_defender_move
							this = scope:bg_attacker
							scope:bg_defender_move = flag:learning
						}
					}
				}
				desc = {
					first_valid = {
						# Crit Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_success
									}
								}
							}
							desc = board_games.0001.desc.intro.learning.crit_success
						}
						# Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:success
									}
								}
							}
							desc = board_games.0001.desc.intro.learning.success
						}
						# Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:failure
									}
								}
							}
							desc = board_games.0001.desc.intro.learning.failure
						}
						# Crit Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_failure
									}
								}
							}
							desc = board_games.0001.desc.intro.learning.crit_failure
						}
					}
				}
			}
			## Prowess
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							exists = scope:bg_defender
							exists = scope:bg_attacker_move
							this = scope:bg_defender
							scope:bg_attacker_move = flag:prowess
						}
						AND = {
							exists = scope:bg_attacker
							exists = scope:bg_defender_move
							this = scope:bg_attacker
							scope:bg_defender_move = flag:prowess
						}
					}
				}
				desc = {
					first_valid = {
						# Crit Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_success
									}
								}
							}
							desc = board_games.0001.desc.intro.prowess.crit_success
						}
						# Success
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:success
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:success
									}
								}
							}
							desc = board_games.0001.desc.intro.prowess.success
						}
						# Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:failure
									}
								}
							}
							desc = board_games.0001.desc.intro.prowess.failure
						}
						# Crit Failure
						triggered_desc = {
							trigger = {
								OR = {
									AND = {
										this = scope:bg_defender
										scope:bg_attacker.var:bg_move_result = flag:crit_failure
									}
									AND = {
										this = scope:bg_attacker
										scope:bg_defender.var:bg_move_result = flag:crit_failure
									}
								}
							}
							desc = board_games.0001.desc.intro.prowess.crit_failure
						}
					}
				}
			}
		}
		# Was someone countered?
		first_valid = {
			# Yes! I countered them.
			triggered_desc = {
				trigger = {
					exists = scope:bg_counterer
					this = scope:bg_counterer
				}
				desc = board_games.0001.desc.i_have_countered
			}
			# Yes! I have been countered.
			triggered_desc = {
				trigger = {
					exists = scope:bg_counterer
					this != scope:bg_counterer
				}
				desc = board_games.0001.desc.i_am_countered
			}
			# Nope, just the page breaks please.
			desc = board_games.0001.desc.no_counters
		}
		## How is the match going?
		### Us relative to each other.
		first_valid = {
			# I'm winning by miles.
			triggered_desc = {
				trigger = { var:bg_current_score >= bg_relative_score_heavy_difference_threshold_value }
				desc = board_games.0001.desc.relative_victory.winning_heavily
			}
			# I'm winning.
			triggered_desc = {
				trigger = { var:bg_current_score >= bg_relative_score_light_difference_threshold_value }
				desc = board_games.0001.desc.relative_victory.winning_somewhat
			}
			# We're essentially equal.
			triggered_desc = {
				trigger = {
					var:bg_current_score >= scope:bg_opponent.var:bg_current_score
				}
				desc = board_games.0001.desc.relative_victory.drawing
			}
			# I'm losing.
			triggered_desc = {
				trigger = { var:bg_current_score <= bg_relative_score_heavy_difference_threshold_value }
				desc = board_games.0001.desc.relative_victory.losing_somewhat
			}
			# I'm losing by miles.
			triggered_desc = {
				trigger = { var:bg_current_score <= bg_relative_score_light_difference_threshold_value }
				desc = board_games.0001.desc.relative_victory.losing_heavily
			}
		}
		### And either one of us towards actual victory.
		first_valid = {
			# Either of us could win.
			triggered_desc = {
				trigger = {
					var:bg_current_score >= bg_close_to_winning_threshold_value
					scope:bg_opponent.var:bg_current_score >= bg_close_to_winning_threshold_value
				}
				desc = board_games.0001.desc.actual_victory.both_close
			}
			# I could win.
			triggered_desc = {
				trigger = { var:bg_current_score >= bg_close_to_winning_threshold_value }
				desc = board_games.0001.desc.actual_victory.i_am_close
			}
			# They could win.
			triggered_desc = {
				trigger = { scope:bg_opponent.var:bg_current_score >= bg_close_to_winning_threshold_value }
				desc = board_games.0001.desc.actual_victory.they_are_close

			}
			# Sudden death is about to kick in.
			triggered_desc = {
				trigger = {
					scope:bg_defender.var:bg_current_round >= bg_round_cap_value
				}
				desc = board_games.0001.desc.actual_victory.sudden_death
			}
			# Neither of us are close.
			desc = board_games.0001.desc.actual_victory.neither_close
		}
		## Fluff segment.
		### Opponent Winning
		triggered_desc = {
			trigger = {
				# Since we're processing a whole mess o'random valids here, and they're *all* fluff, we restrict this to AI only.
				is_ai = no
				# We let the other player be haughty by making them the tie-breaker.
				trigger_if = {
					limit = { has_variable = bg_gib_only_losing_locs }
					always = yes
				}
				trigger_else = {
					var:bg_current_score <= scope:bg_opponent.var:bg_current_score
				}
			}
			desc = {
				random_valid = {
					# Categories
					## Attributes
					### Diplomacy
					triggered_desc = {
						trigger = { scope:bg_opponent.diplomacy <= mediocre_skill_rating }
						desc = board_games.0001.desc.opponent_winning.diplomacy.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.diplomacy > mediocre_skill_rating
							scope:bg_opponent.diplomacy < high_skill_rating
						}
						desc = board_games.0001.desc.opponent_winning.diplomacy.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.diplomacy >= high_skill_rating }
						desc = board_games.0001.desc.opponent_winning.diplomacy.high
					}
					### Martial
					#### These generally refer to the act of leading troops, so we put an extra filter on for being able to lead an army.
					triggered_desc = {
						trigger = {
							can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:bg_opponent }
						}
						desc = {
							random_valid = {
								triggered_desc = {
									trigger = {scope:bg_opponent.martial <= mediocre_skill_rating }
									desc = board_games.0001.desc.opponent_winning.martial.low
								}
								triggered_desc = {
									trigger = {
										scope:bg_opponent.martial > mediocre_skill_rating
										scope:bg_opponent.martial < high_skill_rating
									}
									desc = board_games.0001.desc.opponent_winning.martial.medium
								}
								triggered_desc = {
									trigger = { scope:bg_opponent.martial >= high_skill_rating }
									desc = board_games.0001.desc.opponent_winning.martial.high
								}
							}
						}
					}
					### Stewardship
					triggered_desc = {
						trigger = { scope:bg_opponent.stewardship <= mediocre_skill_rating }
						desc = board_games.0001.desc.opponent_winning.stewardship.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.stewardship > mediocre_skill_rating
							scope:bg_opponent.stewardship < high_skill_rating
						}
						desc = board_games.0001.desc.opponent_winning.stewardship.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.stewardship >= high_skill_rating }
						desc = board_games.0001.desc.opponent_winning.stewardship.high
					}
					### Intrigue
					triggered_desc = {
						trigger = { scope:bg_opponent.intrigue <= mediocre_skill_rating }
						desc = board_games.0001.desc.opponent_winning.intrigue.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.intrigue > mediocre_skill_rating
							scope:bg_opponent.intrigue < high_skill_rating
						}
						desc = board_games.0001.desc.opponent_winning.intrigue.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.intrigue >= high_skill_rating }
						desc = board_games.0001.desc.opponent_winning.intrigue.high
					}
					### Learning
					triggered_desc = {
						trigger = { scope:bg_opponent.learning <= mediocre_skill_rating }
						desc = board_games.0001.desc.opponent_winning.learning.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.learning > mediocre_skill_rating
							scope:bg_opponent.learning < high_skill_rating
						}
						desc = board_games.0001.desc.opponent_winning.learning.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.learning >= high_skill_rating }
						desc = board_games.0001.desc.opponent_winning.learning.high
					}
					## Trait Specifics
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = lustful }
						}
						desc = board_games.0001.desc.opponent_winning.trait.lustful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = chaste }
						}
						desc = board_games.0001.desc.opponent_winning.trait.chaste
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = gluttonous }
						}
						desc = board_games.0001.desc.opponent_winning.trait.gluttonous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = temperate }
						}
						desc = board_games.0001.desc.opponent_winning.trait.temperate
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = greedy }
						}
						desc = board_games.0001.desc.opponent_winning.trait.greedy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = generous }
						}
						desc = board_games.0001.desc.opponent_winning.trait.generous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = lazy }
						}
						desc = board_games.0001.desc.opponent_winning.trait.lazy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = diligent }
						}
						desc = board_games.0001.desc.opponent_winning.trait.diligent
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = wrathful }
						}
						desc = board_games.0001.desc.opponent_winning.trait.wrathful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = calm }
						}
						desc = board_games.0001.desc.opponent_winning.trait.calm
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = patient }
						}
						desc = board_games.0001.desc.opponent_winning.trait.patient
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = impatient }
						}
						desc = board_games.0001.desc.opponent_winning.trait.impatient
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = arrogant }
						}
						desc = board_games.0001.desc.opponent_winning.trait.arrogant
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = humble }
						}
						desc = board_games.0001.desc.opponent_winning.trait.humble
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = deceitful }
						}
						desc = board_games.0001.desc.opponent_winning.trait.deceitful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = honest }
						}
						desc = board_games.0001.desc.opponent_winning.trait.honest
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = craven }
						}
						desc = board_games.0001.desc.opponent_winning.trait.craven
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = brave }
						}
						desc = board_games.0001.desc.opponent_winning.trait.brave
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = shy }
						}
						desc = board_games.0001.desc.opponent_winning.trait.shy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = gregarious }
						}
						desc = board_games.0001.desc.opponent_winning.trait.gregarious
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = ambitious }
						}
						desc = board_games.0001.desc.opponent_winning.trait.ambitious
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = content }
						}
						desc = board_games.0001.desc.opponent_winning.trait.content
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = arbitrary }
						}
						desc = board_games.0001.desc.opponent_winning.trait.arbitrary
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = just }
						}
						desc = board_games.0001.desc.opponent_winning.trait.just
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = cynical }
						}
						desc = board_games.0001.desc.opponent_winning.trait.cynical
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = zealous }
						}
						desc = board_games.0001.desc.opponent_winning.trait.zealous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = paranoid }
						}
						desc = board_games.0001.desc.opponent_winning.trait.paranoid
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = trusting }
						}
						desc = board_games.0001.desc.opponent_winning.trait.trusting
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = compassionate }
						}
						desc = board_games.0001.desc.opponent_winning.trait.compassionate
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = callous }
						}
						desc = board_games.0001.desc.opponent_winning.trait.callous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = sadistic }
						}
						desc = board_games.0001.desc.opponent_winning.trait.sadistic
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = stubborn }
						}
						desc = board_games.0001.desc.opponent_winning.trait.stubborn
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = fickle }
						}
						desc = board_games.0001.desc.opponent_winning.trait.fickle
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = vengeful }
						}
						desc = board_games.0001.desc.opponent_winning.trait.vengeful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = forgiving }
						}
						desc = board_games.0001.desc.opponent_winning.trait.forgiving
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = rowdy }
						}
						desc = board_games.0001.desc.opponent_winning.trait.rowdy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = charming }
						}
						desc = board_games.0001.desc.opponent_winning.trait.charming
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = curious }
						}
						desc = board_games.0001.desc.opponent_winning.trait.curious
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = pensive }
						}
						desc = board_games.0001.desc.opponent_winning.trait.pensive
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = bossy }
						}
						desc = board_games.0001.desc.opponent_winning.trait.bossy
					}
					## Prior Matches & Relationships
					triggered_desc = {
						trigger = { has_relation_friend = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.friend
					}
					triggered_desc = {
						trigger = { has_relation_best_friend = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.best_friend
					}
					triggered_desc = {
						trigger = { has_relation_rival = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.rival
					}
					triggered_desc = {
						trigger = { has_relation_nemesis = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.nemesis
					}
					triggered_desc = {
						trigger = { has_relation_lover = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.lover
					}
					triggered_desc = {
						trigger = { has_relation_soulmate = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.soulmate
					}
					triggered_desc = {
						trigger = { has_relation_bully = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.bully
					}
					triggered_desc = {
						trigger = { has_relation_victim = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.victim
					}
					triggered_desc = {
						trigger = { has_relation_crush = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.crush
					}
					triggered_desc = {
						trigger = { has_relation_guardian = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.guardian
					}
					triggered_desc = {
						trigger = { has_relation_ward = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.relation.ward
					}
					## Miscs
					### Hooks
					triggered_desc = {
						trigger = { has_weak_hook = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.hook_on.weak
					}
					triggered_desc = {
						trigger = { has_strong_hook = scope:bg_opponent }
						desc = board_games.0001.desc.opponent_winning.hook_on.strong
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_weak_hook = scope:bg_myself}
						}
						desc = board_games.0001.desc.opponent_winning.hooked_by.weak
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_strong_hook = scope:bg_myself}
						}
						desc = board_games.0001.desc.opponent_winning.hooked_by.strong
					}
					### Prior Matches
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_default_loss_to
								var:bg_recent_default_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.opponent_winning.match_history.recently_won_against.default
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_land_loss_to
								var:bg_recent_land_loss_to = scope:bg_myself
								# Don't bring it up if you don't control it any more.
								var:bg_recent_land_loss_stake.holder = {
									OR = {
										this = scope:bg_opponent
										any_liege_or_above = { this = scope:bg_opponent }
									}
								}
							}
						}
						desc = board_games.0001.desc.opponent_winning.match_history.recently_won_against.county
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_gambling_loss_to
								var:bg_recent_gambling_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.opponent_winning.match_history.recently_won_against.gamble
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_default_loss_to
								var:bg_recent_default_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.opponent_winning.match_history.recently_lost_against.default
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_land_loss_to
								var:bg_recent_land_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.opponent_winning.match_history.recently_lost_against.county
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_gambling_loss_to
								var:bg_recent_gambling_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.opponent_winning.match_history.recently_lost_against.gamble
					}
					### Other
					#### A move for only the pro-est of board gamers.
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								has_trait = arrogant
								has_trait = reclusive
								OR = {
									learning <= mediocre_skill_rating
									# TIT-34022
								}
							}
						}
						desc = board_games.0001.desc.opponent_winning.other.pro_gamer
					}
					#### A move for an excellent one liner.
					triggered_desc = {
						trigger = {
							# TIT-34022; remove always = no after implementation.
							always = no
							scope:bg_opponent = {
								has_trait = arrogant
								has_trait = sadistic
								has_trait = arbitrary
								intrigue >= very_high_skill_rating
								prowess >= very_high_skill_rating
							}
						}
						desc = board_games.0001.desc.opponent_winning.other.avlf
					}
				}
			}
		}
		### Current Player Winning
		triggered_desc = {
			trigger = {
				# Since we're processing a whole mess o'random valids here, and they're *all* fluff, we restrict this to AI only.
				is_ai = no
				# We let the other player be haughty by making them the tie-breaker.
				trigger_if = {
					limit = { has_variable = bg_gib_only_winning_locs }
					always = yes
				}
				trigger_else = {
					var:bg_current_score > scope:bg_opponent.var:bg_current_score
				}
			}
			desc = {
				random_valid = {
					# Categories
					## Attributes
					### Diplomacy
					triggered_desc = {
						trigger = { scope:bg_opponent.diplomacy <= mediocre_skill_rating }
						desc = board_games.0001.desc.i_am_winning.diplomacy.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.diplomacy > mediocre_skill_rating
							scope:bg_opponent.diplomacy < high_skill_rating
						}
						desc = board_games.0001.desc.i_am_winning.diplomacy.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.diplomacy >= high_skill_rating }
						desc = board_games.0001.desc.i_am_winning.diplomacy.high
					}
					### Martial
					#### These generally refer to the act of leading troops, so we put an extra filter on for being able to lead an army.
					triggered_desc = {
						trigger = {
							can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:bg_opponent }
						}
						desc = {
							random_valid = {
								triggered_desc = {
									trigger = {scope:bg_opponent.martial <= mediocre_skill_rating }
									desc = board_games.0001.desc.i_am_winning.martial.low
								}
								triggered_desc = {
									trigger = {
										scope:bg_opponent.martial > mediocre_skill_rating
										scope:bg_opponent.martial < high_skill_rating
									}
									desc = board_games.0001.desc.i_am_winning.martial.medium
								}
								triggered_desc = {
									trigger = { scope:bg_opponent.martial >= high_skill_rating }
									desc = board_games.0001.desc.i_am_winning.martial.high
								}
							}
						}
					}
					### Stewardship
					triggered_desc = {
						trigger = { scope:bg_opponent.stewardship <= mediocre_skill_rating }
						desc = board_games.0001.desc.i_am_winning.stewardship.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.stewardship > mediocre_skill_rating
							scope:bg_opponent.stewardship < high_skill_rating
						}
						desc = board_games.0001.desc.i_am_winning.stewardship.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.stewardship >= high_skill_rating }
						desc = board_games.0001.desc.i_am_winning.stewardship.high
					}
					### Intrigue
					triggered_desc = {
						trigger = { scope:bg_opponent.intrigue <= mediocre_skill_rating }
						desc = board_games.0001.desc.i_am_winning.intrigue.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.intrigue > mediocre_skill_rating
							scope:bg_opponent.intrigue < high_skill_rating
						}
						desc = board_games.0001.desc.i_am_winning.intrigue.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.intrigue >= high_skill_rating }
						desc = board_games.0001.desc.i_am_winning.intrigue.high
					}
					### Learning
					triggered_desc = {
						trigger = { scope:bg_opponent.learning <= mediocre_skill_rating }
						desc = board_games.0001.desc.i_am_winning.learning.low
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent.learning > mediocre_skill_rating
							scope:bg_opponent.learning < high_skill_rating
						}
						desc = board_games.0001.desc.i_am_winning.learning.medium
					}
					triggered_desc = {
						trigger = { scope:bg_opponent.learning >= high_skill_rating }
						desc = board_games.0001.desc.i_am_winning.learning.high
					}
					## Trait Specifics
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = lustful }
						}
						desc = board_games.0001.desc.i_am_winning.trait.lustful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = chaste }
						}
						desc = board_games.0001.desc.i_am_winning.trait.chaste
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = gluttonous }
						}
						desc = board_games.0001.desc.i_am_winning.trait.gluttonous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = temperate }
						}
						desc = board_games.0001.desc.i_am_winning.trait.temperate
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = greedy }
						}
						desc = board_games.0001.desc.i_am_winning.trait.greedy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = generous }
						}
						desc = board_games.0001.desc.i_am_winning.trait.generous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = lazy }
						}
						desc = board_games.0001.desc.i_am_winning.trait.lazy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = diligent }
						}
						desc = board_games.0001.desc.i_am_winning.trait.diligent
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = wrathful }
						}
						desc = board_games.0001.desc.i_am_winning.trait.wrathful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = calm }
						}
						desc = board_games.0001.desc.i_am_winning.trait.calm
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = patient }
						}
						desc = board_games.0001.desc.i_am_winning.trait.patient
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = impatient }
						}
						desc = board_games.0001.desc.i_am_winning.trait.impatient
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = arrogant }
						}
						desc = board_games.0001.desc.i_am_winning.trait.arrogant
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = humble }
						}
						desc = board_games.0001.desc.i_am_winning.trait.humble
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = deceitful }
						}
						desc = board_games.0001.desc.i_am_winning.trait.deceitful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = honest }
						}
						desc = board_games.0001.desc.i_am_winning.trait.honest
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = craven }
						}
						desc = board_games.0001.desc.i_am_winning.trait.craven
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = brave }
						}
						desc = board_games.0001.desc.i_am_winning.trait.brave
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = shy }
						}
						desc = board_games.0001.desc.i_am_winning.trait.shy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = gregarious }
						}
						desc = board_games.0001.desc.i_am_winning.trait.gregarious
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = ambitious }
						}
						desc = board_games.0001.desc.i_am_winning.trait.ambitious
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = content }
						}
						desc = board_games.0001.desc.i_am_winning.trait.content
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = arbitrary }
						}
						desc = board_games.0001.desc.i_am_winning.trait.arbitrary
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = just }
						}
						desc = board_games.0001.desc.i_am_winning.trait.just
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = cynical }
						}
						desc = board_games.0001.desc.i_am_winning.trait.cynical
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = zealous }
						}
						desc = board_games.0001.desc.i_am_winning.trait.zealous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = paranoid }
						}
						desc = board_games.0001.desc.i_am_winning.trait.paranoid
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = trusting }
						}
						desc = board_games.0001.desc.i_am_winning.trait.trusting
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = compassionate }
						}
						desc = board_games.0001.desc.i_am_winning.trait.compassionate
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = callous }
						}
						desc = board_games.0001.desc.i_am_winning.trait.callous
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = sadistic }
						}
						desc = board_games.0001.desc.i_am_winning.trait.sadistic
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = stubborn }
						}
						desc = board_games.0001.desc.i_am_winning.trait.stubborn
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = fickle }
						}
						desc = board_games.0001.desc.i_am_winning.trait.fickle
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = vengeful }
						}
						desc = board_games.0001.desc.i_am_winning.trait.vengeful
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = forgiving }
						}
						desc = board_games.0001.desc.i_am_winning.trait.forgiving
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = rowdy }
						}
						desc = board_games.0001.desc.i_am_winning.trait.rowdy
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = charming }
						}
						desc = board_games.0001.desc.i_am_winning.trait.charming
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = curious }
						}
						desc = board_games.0001.desc.i_am_winning.trait.curious
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = pensive }
						}
						desc = board_games.0001.desc.i_am_winning.trait.pensive
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_trait = bossy }
						}
						desc = board_games.0001.desc.i_am_winning.trait.bossy
					}
					## Prior Matches & Relationships
					triggered_desc = {
						trigger = { has_relation_friend = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.friend
					}
					triggered_desc = {
						trigger = { has_relation_best_friend = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.best_friend
					}
					triggered_desc = {
						trigger = { has_relation_rival = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.rival
					}
					triggered_desc = {
						trigger = { has_relation_nemesis = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.nemesis
					}
					triggered_desc = {
						trigger = { has_relation_lover = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.lover
					}
					triggered_desc = {
						trigger = { has_relation_soulmate = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.soulmate
					}
					triggered_desc = {
						trigger = { has_relation_bully = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.bully
					}
					triggered_desc = {
						trigger = { has_relation_victim = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.victim
					}
					triggered_desc = {
						trigger = { has_relation_crush = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.crush
					}
					triggered_desc = {
						trigger = { has_relation_guardian = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.guardian
					}
					triggered_desc = {
						trigger = { has_relation_ward = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.relation.ward
					}
					## Miscs
					### Hooks
					triggered_desc = {
						trigger = { has_weak_hook = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.hook_on.weak
					}
					triggered_desc = {
						trigger = { has_strong_hook = scope:bg_opponent }
						desc = board_games.0001.desc.i_am_winning.hook_on.strong
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_weak_hook = scope:bg_myself}
						}
						desc = board_games.0001.desc.i_am_winning.hooked_by.weak
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = { has_strong_hook = scope:bg_myself}
						}
						desc = board_games.0001.desc.i_am_winning.hooked_by.strong
					}
					### Prior Matches
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_default_loss_to
								var:bg_recent_default_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.i_am_winning.match_history.recently_won_against.default
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_land_loss_to
								var:bg_recent_land_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.i_am_winning.match_history.recently_won_against.county
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_gambling_loss_to
								var:bg_recent_gambling_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.i_am_winning.match_history.recently_won_against.gamble
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_default_loss_to
								var:bg_recent_default_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.i_am_winning.match_history.recently_lost_against.default
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_land_loss_to
								var:bg_recent_land_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.i_am_winning.match_history.recently_lost_against.county
					}
					triggered_desc = {
						trigger = {
							scope:bg_opponent = {
								exists = var:bg_recent_gambling_loss_to
								var:bg_recent_gambling_loss_to = scope:bg_myself
							}
						}
						desc = board_games.0001.desc.i_am_winning.match_history.recently_lost_against.gamble
					}
					### Other
					#### [tumbleweeds]
				}
			}
		}
	}
	theme = martial_strategy_focus
	left_portrait = {
		character = scope:bg_myself
		triggered_animation = { # Winning by a large margin
			trigger = {
				scope:bg_myself = {
					NOT = { has_trait = humble }
					OR = {
						var:bg_current_score >= bg_relative_score_heavy_difference_threshold_value
						var:bg_current_score >= bg_close_to_winning_threshold_value
					}
				}
			}
  			animation = chess_certain_win
  		}
		triggered_animation = { # Winning by any margin
			trigger = {
				scope:bg_myself = {
					NOT = { has_trait = humble }
					var:bg_current_score >= bg_relative_score_light_difference_threshold_value
				}
			}
  			animation = chess_cocky
  		}
		animation = personality_rational
	}
	right_portrait = {
		character = scope:bg_opponent
		triggered_animation = {
			trigger = {
				scope:bg_opponent = {
					NOT = { has_trait = humble }
				}
				scope:bg_myself.var:bg_current_score < scope:bg_opponent.var:bg_current_score
				scope:bg_myself.var:bg_current_score <= bg_relative_score_heavy_difference_threshold_value
			}
  			animation = chess_cocky
  		}
		triggered_animation = {
			trigger = {
				scope:bg_opponent = {
					NOT = { has_trait = humble }
				}
				scope:bg_myself.var:bg_current_score < scope:bg_opponent.var:bg_current_score
				OR = {
					scope:bg_myself.var:bg_current_score <= bg_relative_score_light_difference_threshold_value
					scope:bg_opponent.var:bg_current_score >= bg_close_to_winning_threshold_value
				}
			}
  			animation = chess_certain_win
  		}
		animation = scheme
	}
	artifact = {
		target = scope:bg_chess_board
		position = lower_center_portrait
	}
	override_background = {
		trigger = { scope:bg_locale = flag:terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		trigger = { scope:bg_locale = flag:wilderness_scope }
		reference = wilderness_scope
	}
	override_background = {
		trigger = { scope:bg_locale = flag:battlefield }
		reference = battlefield
	}
	override_background = {
		trigger = { scope:bg_locale = flag:temple }
		reference = temple
	}
	override_background = {
		trigger = { scope:bg_locale = flag:council_chamber }
		reference = council_chamber
	}
	override_background = {
		trigger = { scope:bg_locale = flag:courtyard }
		reference = courtyard
	}
	override_background = {
		trigger = { scope:bg_locale = flag:dungeon }
		reference = dungeon
	}
	override_background = {
		trigger = { scope:bg_locale = flag:docks }
		reference = docks
	}
	override_background = {
		trigger = { scope:bg_locale = flag:feast }
		reference = feast
	}
	override_background = {
		trigger = { scope:bg_locale = flag:gallows }
		reference = gallows
	}
	override_background = {
		trigger = { scope:bg_locale = flag:garden }
		reference = garden
	}
	override_background = {
		trigger = { scope:bg_locale = flag:market }
		reference = market
	}
	override_background = {
		trigger = { scope:bg_locale = flag:sitting_room }
		reference = sitting_room
	}
	override_background = {
		trigger = { scope:bg_locale = flag:bedchamber }
		reference = bedchamber
	}
	override_background = {
		trigger = { scope:bg_locale = flag:study }
		reference = study
	}
	override_background = {
		trigger = { scope:bg_locale = flag:physicians_study }
		reference = physicians_study
	}
	override_background = {
		trigger = { scope:bg_locale = flag:tavern }
		reference = tavern
	}
	override_background = {
		trigger = { scope:bg_locale = flag:throne_room }
		reference = throne_room
	}
	override_background = {
		trigger = { scope:bg_locale = flag:army_camp }
		reference = army_camp
	}

	trigger = {
		scope:bg_defender = { can_start_board_game_eligibility_checks_trigger = yes }
		scope:bg_attacker = { can_start_board_game_eligibility_checks_trigger = yes }
		# Invalidate if there's a war for the wagered county or they leave your realm for any reason.
		trigger_if = {
			limit = {
				exists = scope:bg_stake_land_recipient
				exists = scope:bg_stake_land_actor
			}
			OR = {
				scope:bg_stake_land_recipient.holder = scope:recipient
				scope:bg_stake_land_actor.holder = scope:actor
				scope:recipient  ={
					is_at_war = yes
					any_character_war = {
						casus_belli = {
							any_target_title = { this =  scope:bg_stake_land_recipient }
						}
					}
				}
				scope:actor = {
					is_at_war = yes
					any_character_war = {
						casus_belli = {
							any_target_title = { this = scope:bg_stake_land_actor }
						}
					}
				}
			}
		}
	}
	on_trigger_fail = { bg_fire_clean_up_and_invalidate_effect = yes }

	immediate = {
		# Sort scopes for portraits & loc.
		save_scope_as = bg_myself
		if = {
			limit = { this = scope:bg_defender }
			scope:bg_attacker = { save_scope_as = bg_opponent }
		}
		else = {
			scope:bg_defender = { save_scope_as = bg_opponent }
		}
		# TIT-34135
	}

	# Diplomacy: fall back on social acumen.
	option = {
		name = {
			text = {
				random_valid = {
					desc = board_games.0001.a.random.a
					desc = board_games.0001.a.random.b
					desc = board_games.0001.a.random.c
					desc = board_games.0001.a.random.d
				}
			}
		}
		skill = diplomacy
		trigger = {
			OR = {
				scope:bg_skill_a = flag:diplomacy
				scope:bg_skill_b = flag:diplomacy
				scope:bg_skill_c = flag:diplomacy
			}
		}

		# Notify the player of the counter type.
		custom_tooltip = board_games.0001.a.tt
		# Duel-'em-up.
		bg_play_move_type_effect = {
			SKILL = diplomacy
			LOC_KEY = a
		}

		# No stress impact for picking moves, but we apply stress impact in the post-game.
		ai_chance = {
			base = 0

			bg_ai_weight_choices_by_skill_modifier = {
				SKILL = diplomacy
				CHARACTER = this
			}

			ai_value_modifier = {
				ai_sociability = 1
				ai_vengefulness = -1
			}
		}
	}

	# Martial: play strategically.
	option = {
		name = {
			text = {
				random_valid = {
					desc = board_games.0001.b.random.a
					desc = board_games.0001.b.random.b
					desc = board_games.0001.b.random.c
					desc = board_games.0001.b.random.d
				}
			}
		}
		skill = martial
		trigger = {
			OR = {
				scope:bg_skill_a = flag:martial
				scope:bg_skill_b = flag:martial
				scope:bg_skill_c = flag:martial
			}
		}

		# Notify the player of the counter type.
		custom_tooltip = board_games.0001.b.tt
		# Duel-'em-up.
		bg_play_move_type_effect = {
			SKILL = martial
			LOC_KEY = b
		}

		# No stress impact for picking moves, but we apply stress impact in the post-game.
		ai_chance = {
			base = 0

			bg_ai_weight_choices_by_skill_modifier = {
				SKILL = martial
				CHARACTER = this
			}

			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
		}
	}

	# Stewardship: play efficiently
	option = {
		name = {
			text = {
				random_valid = {
					desc = board_games.0001.c.random.a
					desc = board_games.0001.c.random.b
					desc = board_games.0001.c.random.c
					desc = board_games.0001.c.random.d
				}
			}
		}
		skill = stewardship
		trigger = {
			OR = {
				scope:bg_skill_a = flag:stewardship
				scope:bg_skill_b = flag:stewardship
				scope:bg_skill_c = flag:stewardship
			}
		}

		# Notify the player of the counter type.
		custom_tooltip = board_games.0001.c.tt
		# Duel-'em-up.
		bg_play_move_type_effect = {
			SKILL = stewardship
			LOC_KEY = c
		}

		# No stress impact for picking moves, but we apply stress impact in the post-game.
		ai_chance = {
			base = 100

			bg_ai_weight_choices_by_skill_modifier = {
				SKILL = stewardship
				CHARACTER = this
			}

			ai_value_modifier = {
				ai_rationality = 1
				# Greed isn't super fitting, tbh, but it's associated with higher stewardship so it makes it easier to judge someone based on their skills.
				ai_greed = 1
			}
		}
	}

	# Intrigue: play with cunning.
	option = {
		name = {
			text = {
				random_valid = {
					desc = board_games.0001.d.random.a
					desc = board_games.0001.d.random.b
					desc = board_games.0001.d.random.c
					desc = board_games.0001.d.random.d
				}
			}
		}
		skill = intrigue
		trigger = {
			OR = {
				scope:bg_skill_a = flag:intrigue
				scope:bg_skill_b = flag:intrigue
				scope:bg_skill_c = flag:intrigue
			}
		}

		# Notify the player of the counter type.
		custom_tooltip = board_games.0001.d.tt
		# Duel-'em-up.
		bg_play_move_type_effect = {
			SKILL = intrigue
			LOC_KEY = d
		}

		# No stress impact for picking moves, but we apply stress impact in the post-game.
		ai_chance = {
			base = 100

			bg_ai_weight_choices_by_skill_modifier = {
				SKILL = intrigue
				CHARACTER = this
			}

			ai_value_modifier = {
				ai_vengefulness = 1
				ai_honor = -1
			}
		}
	}

	# Learning: play by the (well thought-out) book.
	option = {
		name = {
			text = {
				random_valid = {
					desc = board_games.0001.e.random.a
					desc = board_games.0001.e.random.b
					desc = board_games.0001.e.random.c
					desc = board_games.0001.e.random.d
				}
			}
		}
		skill = learning
		trigger = {
			OR = {
				scope:bg_skill_a = flag:learning
				scope:bg_skill_b = flag:learning
				scope:bg_skill_c = flag:learning
			}
		}

		# Notify the player of the counter type.
		custom_tooltip = board_games.0001.e.tt
		# Duel-'em-up.
		bg_play_move_type_effect = {
			SKILL = learning
			LOC_KEY = e
		}

		# No stress impact for picking moves, but we apply stress impact in the post-game.
		ai_chance = {
			base = 100

			bg_ai_weight_choices_by_skill_modifier = {
				SKILL = learning
				CHARACTER = this
			}

			ai_value_modifier = {
				ai_boldness = -1
				# Sociability isn't anathema to good learning, but it does suggest a more bookish person.
				ai_sociability = -1
			}
		}
	}

	# Prowess: settle arguments over rules with fisticuffs mid-game.
	option = {
		name = {
			text = {
				random_valid = {
					desc = board_games.0001.f.random.a
					desc = board_games.0001.f.random.b
					desc = board_games.0001.f.random.c
					desc = board_games.0001.f.random.d
				}
			}
		}
		skill = prowess
		trigger = {
			OR = {
				scope:bg_skill_a = flag:prowess
				scope:bg_skill_b = flag:prowess
				scope:bg_skill_c = flag:prowess
			}
		}

		# Notify the player of the counter type.
		custom_tooltip = board_games.0001.f.tt
		# Duel-'em-up.
		bg_play_move_type_effect = {
			SKILL = prowess
			LOC_KEY = e
		}

		# No stress impact for picking moves, but we apply stress impact in the post-game.
		ai_chance = {
			base = 100

			bg_ai_weight_choices_by_skill_modifier = {
				SKILL = prowess
				CHARACTER = this
			}

			ai_value_modifier = {
				ai_boldness = 1
				ai_vengefulness = 1
			}
		}
	}

	after = {
		#If we're scope:bg_defender, send scope:bg_attacker their instance of the event.
		if = {
			limit = { this = scope:bg_defender }
			scope:bg_attacker = { trigger_event = board_games.0001 }
		}
		#Otherwise we're scope:bg_attacker, so end the round.
		else = { trigger_event = board_games.0011 }
	}
}

##################################################
# Round End Events
# by Ewan Cowhig Croft
# 0011 - 0020
##################################################

scripted_effect bg_calc_current_scores_effect = {
	$CURRENT_PLAYER$ = {
		set_variable = {
			name = bg_current_score
			value = {
				value = $CURRENT_PLAYER$.var:bg_current_score
				# Add results based on move score.
				## First, work out if we've been countered.
				if = {
					limit = {
						exists = scope:bg_counterer
						scope:bg_counterer = $OTHER_PLAYER$
					}
					# Lots'n'lots for crit successes.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:crit_success }
						add = {
							value = bg_crit_success_add_value
							multiply = bg_counter_mult_value
							round = yes
						}
					}
					# Lots for successes.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:success }
						add = {
							value = bg_success_add_value
							multiply = bg_counter_mult_value
							round = yes
						}
					}
					# Less for fails.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:failure }
						add = {
							value = bg_failure_add_value
							multiply = bg_counter_mult_value
							round = yes
						}
					}
					# Not-lots for crit fails.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:crit_failure }
						add = {
							value = bg_crit_failure_add_value
							multiply = bg_counter_mult_value
							round = yes
						}
					}
				}
				## Otherwise, we can use the normal values.
				if = {
					limit = {
						exists = scope:bg_counterer
						scope:bg_counterer = $CURRENT_PLAYER$
					}
					# Lots'n'lots for crit successes.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:crit_success }
						add = bg_crit_success_add_value
					}
					# Lots for successes.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:success }
						add = bg_success_add_value
					}
					# Less for fails.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:failure }
						add = bg_failure_add_value
					}
					#  for crit fails.
					if = {
						limit = { $CURRENT_PLAYER$.var:bg_move_result = flag:crit_failure }
						add = bg_crit_failure_add_value
					}
				}
			}
		}
	}
}

scripted_effect bg_finalise_match_end_effect = {
	# Track variables.
	## Is either character a player? If so, bookmark them on their opponent.
	if = {
		limit = {
			OR = {
				scope:bg_victor = { is_ai = no }
				scope:bg_loser = { is_ai = no }
			}
		}
		# Achievement tracking.
		if = {
			limit = { scope:chess_land ?= yes }
			add_achievement_global_variable_effect = {
				VARIABLE = fp2_high_stakes_chess_achievement_unlocked
				VALUE = yes
			}
		}
		# Process stakes from the interaction.
		scope:bg_loser = {
			# Mark land stakes especially.
			if = {
				limit = { scope:chess_land ?= yes }
				set_variable = {
					name = bg_recent_land_loss_to
					value = scope:bg_victor
					years = 10
				}
				if = {
					limit = { scope:bg_loser = scope:recipient }
					set_variable = {
						name = bg_recent_land_loss_stake
						value = scope:bg_stake_land_recipient
						years = 10
					}
				}
				if = {
					limit = { scope:bg_loser = scope:actor }
					set_variable = {
						name = bg_recent_land_loss_stake
						value = scope:bg_stake_land_actor
						years = 10
					}
				}
			}
			# But also regular gambling.
			else_if = {
				limit = {
					OR = {
						scope:chess_gold ?= yes
						scope:chess_prestige ?= yes
					}
				}
				set_variable = {
					name = bg_recent_gambling_loss_to
					value = scope:bg_victor
					years = 10
				}
			}
			# And otherwise we use the default.
			else = {
				set_variable = {
					name = bg_recent_default_loss_to
					value = scope:bg_victor
					years = 10
				}
			}
		}
	}
	## Is either character a player _or_ a game-master? If so, increment their tallies.
	scope:bg_victor = {
		if = {
			limit = {
				OR = {
					is_ai = no
					# TIT-34022
				}
			}
			# If they don't have a score tally already, create one.
			if = {
				limit = {
					NOT = { has_variable = bg_win_tally }
				}
				set_variable = {
					name = bg_win_tally
					value = 0
				}
			}
			# Now we make our changes.
			change_variable = {
				name = bg_win_tally
				add = 1
			}
		}
	}
	scope:bg_loser = {
		if = {
			limit = {
				OR = {
					is_ai = no
					# TIT-34022
				}
			}
			# If they don't have a score tally already, create one.
			if = {
				limit = {
					NOT = { has_variable = bg_loss_tally }
				}
				set_variable = {
					name = bg_loss_tally
					value = 0
				}
			}
			# Now we make our changes.
			change_variable = {
				name = bg_loss_tally
				add = 1
			}
		}
	}
	# Send out results events.
	scope:bg_victor = { trigger_event = board_games.0031 }
	scope:bg_loser = { trigger_event = board_games.0041 }
	# Clean up effects.
	remove_board_game_info_effect = yes
	## Including removing the in-progress match flag for invalidation if this was via interaction.
	if = {
		limit = {
			exists = scope:actor
			scope:actor = { has_character_flag = taken_challenge_to_chess_interaction }
		}
		scope:actor = { remove_character_flag = taken_challenge_to_chess_interaction }
	}
	# Finally, send out the post-match event for scope:sg_initiator.
	scope:bg_initiator = {
		trigger_event = { saved_event_id = scope:follow_up_event }
	}
}

#	Both players have moved, work out results.
board_games.0011 = {
	hidden = yes

	immediate = {
		# Work out counterers.
		## First, clear the prior counterer (if any).
		clear_saved_scope = bg_counterer
		## Scope:bg_defender.
		### Scope:bg_skill_a > scope:bg_skill_b.
		if = {
			limit = {
				scope:bg_defender_move = scope:bg_skill_a
				scope:bg_attacker_move = scope:bg_skill_b
			}
			scope:bg_defender = { save_scope_as = bg_counterer }
		}
		### Scope:bg_skill_b > scope:bg_skill_c.
		else_if = {
			limit = {
				scope:bg_defender_move = scope:bg_skill_b
				scope:bg_attacker_move = scope:bg_skill_c
			}
			scope:bg_defender = { save_scope_as = bg_counterer }
		}
		### Scope:bg_skill_c > scope:bg_skill_a.
		else_if = {
			limit = {
				scope:bg_defender_move = scope:bg_skill_c
				scope:bg_attacker_move = scope:bg_skill_a
			}
			scope:bg_defender = { save_scope_as = bg_counterer }
		}
		## Scope:bg_attacker.
		### Scope:bg_skill_a > scope:bg_skill_b.
		else_if = {
			limit = {
				scope:bg_attacker_move = scope:bg_skill_a
				scope:bg_defender_move = scope:bg_skill_b
			}
			scope:bg_attacker = { save_scope_as = bg_counterer }
		}
		### Scope:bg_skill_b > scope:bg_skill_c.
		else_if = {
			limit = {
				scope:bg_attacker_move = scope:bg_skill_b
				scope:bg_defender_move = scope:bg_skill_c
			}
			scope:bg_attacker = { save_scope_as = bg_counterer }
		}
		### Scope:bg_skill_c > scope:bg_skill_a.
		else_if = {
			limit = {
				scope:bg_attacker_move = scope:bg_skill_c
				scope:bg_defender_move = scope:bg_skill_a
			}
			scope:bg_attacker = { save_scope_as = bg_counterer }
		}
		# Calc new score totals.
		bg_calc_current_scores_effect = {
			CURRENT_PLAYER = scope:bg_defender
			OTHER_PLAYER = scope:bg_attacker
		}
		bg_calc_current_scores_effect = {
			CURRENT_PLAYER = scope:bg_attacker
			OTHER_PLAYER = scope:bg_defender
		}
		# Has anyone managed to win?
		## First we check scope:bg_defender.
		if = {
			limit = {
				scope:bg_defender.var:bg_current_score > bg_winning_threshold_value
				scope:bg_defender.var:bg_current_score >= scope:bg_attacker.var:bg_current_score
			}
			scope:bg_defender = { save_scope_as = bg_victor }
			scope:bg_attacker = { save_scope_as = bg_loser }
			save_scope_value_as = {
				name = bg_victory_type
				value = flag:skill
			}
			bg_finalise_match_end_effect = yes
		}
		## Then scope:bg_attacker.
		else_if = {
			limit = {
				scope:bg_attacker.var:bg_current_score > bg_winning_threshold_value
				scope:bg_attacker.var:bg_current_score > scope:bg_defender.var:bg_current_score
			}
			scope:bg_attacker = { save_scope_as = bg_victor }
			scope:bg_defender = { save_scope_as = bg_loser }
			save_scope_value_as = {
				name = bg_victory_type
				value = flag:skill
			}
			bg_finalise_match_end_effect = yes
		}
		## Then see if we're above the round limit and should default.
		else_if = {
			limit = {
				scope:bg_defender.var:bg_current_round >= bg_round_cap_value
			}
			scope:bg_defender = { save_scope_as = bg_victor }
			scope:bg_attacker = { save_scope_as = bg_loser }
			save_scope_value_as = {
				name = bg_victory_type
				value = flag:sudden_death
			}
			bg_finalise_match_end_effect = yes
		}
		## Finally, if none of that applies, we just want to spin on to the next event.
		else = {
			scope:bg_defender = {
				change_variable = {
					name = bg_current_round
					add = 1
				}
				trigger_event = board_games.0001
			}
		}
	}
}

##################################################
# Default Invalidation Event
# by Ewan Cowhig Croft
# 0021 - 0030
##################################################

#	The game has invalidated, inform affected parties.
board_games.0021 = {
	hidden = yes

	immediate = {
		# Inform scope:bg_defender that the game has invalidated.
		scope:bg_defender = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = board_games.0021.trigger_failure.bg_defender
				left_icon = scope:bg_attacker
			}
		}
		# If they're not the same person, inform scope:bg_initiator that the game scope:bg_attacker is playing has invalidated.
		if = {
			limit = {
				scope:bg_attacker != scope:bg_initiator
			}
			scope:bg_initiator = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = board_games.0021.trigger_failure.bg_initiator
					left_icon = scope:bg_attacker
					right_icon = scope:bg_defender
				}
			}
		}
		# Now inform scope:bg_attacker.
		scope:bg_attacker = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = board_games.0021.trigger_failure.bg_attacker
				left_icon = scope:bg_defender
			}
		}
		# Reset cooldowns if this was the interaction.
		if = {
			limit = {
				exists = scope:actor
				scope:actor = { has_character_flag = taken_challenge_to_chess_interaction }
			}
			scope:actor = {
				remove_interaction_cooldown = challenge_to_2p_chess_interaction
				remove_interaction_cooldown_against = {
					interaction = challenge_to_2p_chess_interaction
					target = scope:recipient
				}
			}
		}
	}
}

##################################################
# Conclusion Events
# by Ewan Cowhig Croft
# 0031 - 0050
##################################################
scripted_effect bg_make_friends_after_game_effect = {
	duel = {
		skill = diplomacy
		target = $RECIPIENT$
		# They'd love to play you again.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			opinion_modifier = {
				who = $RECIPIENT$
				opinion_target = $ACTOR$
				multiplier = 0.5
			}
			desc = board_games.0031.a.tt.success
			send_interface_toast = {
				type = event_toast_effect_good
				title = board_games.0031.a.tt.success
				left_icon = $RECIPIENT$
				progress_towards_friend_effect = {
					REASON = friend_good_boardgame
					CHARACTER = $RECIPIENT$
					OPINION = default_friend_opinion
				}
			}
		}
		# They think you suck.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			desc = board_games.0031.a.tt.failure
			send_interface_toast = {
				type = event_toast_effect_bad
				title = board_games.0031.a.tt.failure
				left_icon = $RECIPIENT$
				reverse_add_opinion = {
					modifier = unfriendly_opinion
					target = $RECIPIENT$
					opinion = -30
				}
			}
		}
	}
}

scripted_effect bg_victor_end_result_tooltip_effect = {
	#Clarify the results.
	if = {
		limit = { scope:bg_victory_type = flag:skill }
		custom_tooltip = board_games.0031.desc.result.skill
	}
	else_if = {
		limit = { scope:bg_victory_type = flag:sudden_death }
		custom_tooltip = board_games.0031.desc.result.sudden_death
	}
}

scripted_effect bg_loser_end_result_tooltip_effect = {
	#Clarify the results.
	if = {
		limit = { scope:bg_victory_type = flag:skill }
		custom_tooltip = board_games.0041.desc.result.skill
	}
	else_if = {
		limit = { scope:bg_victory_type = flag:sudden_death }
		custom_tooltip = board_games.0041.desc.result.sudden_death
	}
}

#	Scope:bg_victor notification event.
board_games.0031 = {
	type = character_event
	window = duel_event
	title = board_games.0031.t
	desc = {
		triggered_desc = { # This can be expanded upon with further content if desired, see MR/TIT-34157 comments for more details
			trigger = { always = yes }
			desc = { # To make it easy to modify and expand upon the dynamic description, it is divided into swappable chunks.
				desc = { # SECTION ONE: Descriptor of how you feel/awesome you are >Maximum Word Count: 20<
					random_valid = {
						desc = board_games.0031.desc.intro.02
						desc = board_games.0031.desc.intro.01
						desc = board_games.0031.desc.intro.03
					}
				}
				desc = { # SECTION TWO: Descriptor of what happened in the match >Maximum Word Count: 20<
					random_valid = {
						triggered_desc = {
							trigger = {
								learning > high_skill_rating
								learning > scope:bg_opponent.learning
							}
							desc = board_games.0031.desc.middle.02
						}
						triggered_desc = {
							trigger = {
								OR = {
									piety_level >= high_piety_level
									has_trait = zealous
									has_trait = holy_warrior
								}
							}
							desc = board_games.0031.desc.middle.03
						}
						desc = board_games.0031.desc.middle.01
					}
				}
				desc = { # SECTION THREE: Descriptor of how the opponent feels/reacts >Maximum Word Count: 20<
					random_valid = {
						triggered_desc = {
							trigger = { scope:bg_opponent = { has_trait = wrathful } }
							desc = board_games.0031.desc.end.03
						}
						desc = board_games.0031.desc.end.01
						desc = board_games.0031.desc.end.02
					}
				}
			}
		}
	}
	theme = martial_strategy_focus

	left_portrait = {
		character = scope:bg_victor
		animation = throne_room_cheer_2
	}
	right_portrait = {
		character = scope:bg_loser
		animation = fear
	}

	override_background = {
		trigger = { scope:bg_locale = flag:terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		trigger = { scope:bg_locale = flag:wilderness_scope }
		reference = wilderness_scope
	}
	override_background = {
		trigger = { scope:bg_locale = flag:battlefield }
		reference = battlefield
	}
	override_background = {
		trigger = { scope:bg_locale = flag:temple }
		reference = temple
	}
	override_background = {
		trigger = { scope:bg_locale = flag:council_chamber }
		reference = council_chamber
	}
	override_background = {
		trigger = { scope:bg_locale = flag:courtyard }
		reference = courtyard
	}
	override_background = {
		trigger = { scope:bg_locale = flag:dungeon }
		reference = dungeon
	}
	override_background = {
		trigger = { scope:bg_locale = flag:docks }
		reference = docks
	}
	override_background = {
		trigger = { scope:bg_locale = flag:feast }
		reference = feast
	}
	override_background = {
		trigger = { scope:bg_locale = flag:gallows }
		reference = gallows
	}
	override_background = {
		trigger = { scope:bg_locale = flag:garden }
		reference = garden
	}
	override_background = {
		trigger = { scope:bg_locale = flag:market }
		reference = market
	}
	override_background = {
		trigger = { scope:bg_locale = flag:sitting_room }
		reference = sitting_room
	}
	override_background = {
		trigger = { scope:bg_locale = flag:bedchamber }
		reference = bedchamber
	}
	override_background = {
		trigger = { scope:bg_locale = flag:study }
		reference = study
	}
	override_background = {
		trigger = { scope:bg_locale = flag:physicians_study }
		reference = physicians_study
	}
	override_background = {
		trigger = { scope:bg_locale = flag:tavern }
		reference = tavern
	}
	override_background = {
		trigger = { scope:bg_locale = flag:throne_room }
		reference = throne_room
	}
	override_background = {
		trigger = { scope:bg_locale = flag:army_camp }
		reference = army_camp
	}

	immediate = {
		#Hand out Hastiluder reward
		if = {
			limit = { has_trait = tourney_participant }
			add_trait_xp = {
				trait = tourney_participant
				track = wit
				value = {
					integer_range = {
						min = 1
						max = 5
					}
				}
			}
		}
	}

	# Good game!
	option = {
		name = {
			text = {
				random_valid = {
					desc = board_games.0031.a
					desc = board_games.0031.a.a # Untested if this is working
				}
			}
		}

		# Display ending type.
		bg_victor_end_result_tooltip_effect = yes

		stress_impact = {
			gregarious = miniscule_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
				ai_vengefulness = -1
			}
		}
	}

	# How does it feel to lose, little GetWomanMan?
	option = {
		name = { text = board_games.0031.b }
		name = { # I would *much* rather nest this, but due to script limitations, you cannot nest names like you can descs. It is very unfortuante.
			trigger = {
				OR = {
					has_trait = arrogant
					has_trait = wrathful
				}
			}
			text = board_games.0031.b.a
		}
		name = {
			trigger = {
				OR = {
					has_trait = arrogant
					has_trait = wrathful
				}
				learning > high_skill_rating
				learning > scope:bg_opponent.learning
			}
			text = board_games.0031.b.b
		}

		# Display ending type.
		bg_victor_end_result_tooltip_effect = yes
		# Progress towards rival.
		scope:bg_loser = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = board_games.0031.b.progress_towards_rival
				left_icon = scope:bg_victor
				scope:bg_victor = {
					progress_towards_rival_effect = {
						REASON = rival_you_won_boardgame_challenge
						CHARACTER = scope:bg_loser
						OPINION = default_rival_opinion
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			# Removed: Lustful
		}
		ai_chance = {
			# Low base chance so that only really sore losers will pick fights over simple games.
			base = 0
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_sociability = -1
			}
		}
	}

	# I'd love to play again some time...
	option = {
		name = board_games.0031.c
		# We don't let you try this against players, mostly for simplicity's sakes.
		trigger = { is_ai = no }

		# Display ending type.
		bg_victor_end_result_tooltip_effect = yes
		# Try to make friends by running a duel.
		bg_make_friends_after_game_effect = {
			ACTOR = scope:bg_victor
			RECIPIENT = scope:bg_loser
		}

		stress_impact = {
			humble = miniscule_stress_impact_loss
			forgiving = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			arrogant = medium_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
				ai_vengefulness = -1
			}
		}
	}

	# And perhaps, a lucky board...
	after = {
		# We only support chess boards at the moment.
		if = {
			limit = { scope:bg_system = flag:chess }
			# Hidden effect because random is a precious special snowflake that insists on telling you the percentage chance even when it has nothing to show >:(.
			hidden_effect = {
				random = {
					chance = {
						# Default odds are low.
						value = 5
						# But if we won a county, we boost 'em.
						if = {
							limit = { scope:chess_land ?= yes }
							multiply = 5
						}
					}
					trigger_event = {
						id = board_games.0051
						months = 6
					}
				}
			}
		}
	}
}

#	Scope:bg_loser notification event.
board_games.0041 = {
	type = character_event
	window = duel_event
	title = board_games.0041.t
	desc = {
		triggered_desc = { # Same comment applies above. When adding new content, I recommend adding an equal amount for both winning and losing.
			trigger = { always = yes }
			desc = { # To make it easy to modify and expand upon the dynamic description, it is divided into swappable chunks.
				desc = { # SECTION ONE: Descriptor of how the opponent feels/reacts >Maximum Word Count: 20<
					random_valid = {
						desc = board_games.0041.desc.intro.02
						desc = board_games.0041.desc.intro.01
						desc = board_games.0041.desc.intro.03
					}
				}
				desc = { # SECTION TWO: Descriptor of what happened in the match >Maximum Word Count: 20<
					random_valid = {
						triggered_desc = {
							trigger = { scope:bg_opponent = { learning < low_skill_rating } }
							desc = board_games.0041.desc.middle.02
						}
						triggered_desc = {
							trigger = {
								martial > very_high_skill_rating
								martial > scope:bg_opponent.martial
								has_trait = wrathful
							}
							desc = board_games.0041.desc.middle.03
						}
						desc = board_games.0041.desc.middle.01
					}
				}
				desc = { # SECTION THREE: Descriptor of how you feel/terrible you are >Maximum Word Count: 20<
					random_valid = {
						triggered_desc = {
							trigger = { has_trait = wrathful }
							desc = board_games.0041.desc.end.03
						}
						desc = board_games.0041.desc.end.01
						desc = board_games.0041.desc.end.02
					}
				}
			}
		}
	}
	theme = martial_strategy_focus

	left_portrait = {
		character = scope:bg_loser
		animation = fear
	}
	right_portrait = {
		character = scope:bg_victor
		animation = throne_room_cheer_2
	}

	override_background = {
		trigger = { scope:bg_locale = flag:terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		trigger = { scope:bg_locale = flag:wilderness_scope }
		reference = wilderness_scope
	}
	override_background = {
		trigger = { scope:bg_locale = flag:battlefield }
		reference = battlefield
	}
	override_background = {
		trigger = { scope:bg_locale = flag:temple }
		reference = temple
	}
	override_background = {
		trigger = { scope:bg_locale = flag:council_chamber }
		reference = council_chamber
	}
	override_background = {
		trigger = { scope:bg_locale = flag:courtyard }
		reference = courtyard
	}
	override_background = {
		trigger = { scope:bg_locale = flag:dungeon }
		reference = dungeon
	}
	override_background = {
		trigger = { scope:bg_locale = flag:docks }
		reference = docks
	}
	override_background = {
		trigger = { scope:bg_locale = flag:feast }
		reference = feast
	}
	override_background = {
		trigger = { scope:bg_locale = flag:gallows }
		reference = gallows
	}
	override_background = {
		trigger = { scope:bg_locale = flag:garden }
		reference = garden
	}
	override_background = {
		trigger = { scope:bg_locale = flag:market }
		reference = market
	}
	override_background = {
		trigger = { scope:bg_locale = flag:sitting_room }
		reference = sitting_room
	}
	override_background = {
		trigger = { scope:bg_locale = flag:bedchamber }
		reference = bedchamber
	}
	override_background = {
		trigger = { scope:bg_locale = flag:study }
		reference = study
	}
	override_background = {
		trigger = { scope:bg_locale = flag:physicians_study }
		reference = physicians_study
	}
	override_background = {
		trigger = { scope:bg_locale = flag:tavern }
		reference = tavern
	}
	override_background = {
		trigger = { scope:bg_locale = flag:throne_room }
		reference = throne_room
	}
	override_background = {
		trigger = { scope:bg_locale = flag:army_camp }
		reference = army_camp
	}

	immediate = {
		#Hand out Hastiluder reward
		if = {
			limit = { has_trait = tourney_participant }
			add_trait_xp = {
				trait = tourney_participant
				track = wit
				value = {
					integer_range = {
						min = 1
						max = 5
					}
				}
			}
		}
	}

	# We'll see who wins next time...
	option = {
		name = board_games.0041.a

		# Display ending type.
		bg_loser_end_result_tooltip_effect = yes

		stress_impact = {
			gregarious = miniscule_stress_impact_loss
			arrogant = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
				ai_vengefulness = -1
			}
		}
	}

	# You've made an enemy here today.
	option = {
		name = { text = board_games.0041.b }
		name = {
			trigger = {
				OR = {
					has_trait = arrogant
					has_trait = wrathful
				}
				OR = {
					has_trait = zealous
					has_trait = holy_warrior
					has_trait = heresiarch
					has_trait = devoted
				}
			}
			text = board_games.0041.b.b
		}

		# Display ending type.
		bg_loser_end_result_tooltip_effect = yes
		# Progress towards rival.
		scope:bg_victor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = board_games.0031.b.progress_towards_rival
				left_icon = scope:bg_loser
				scope:bg_loser = {
					progress_towards_rival_effect = {
						REASON = rival_won_boardgame_challenge
						CHARACTER = scope:bg_victor
						OPINION = default_rival_opinion
					}
				}
			}
		}

		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			vengeful = miniscule_stress_impact_loss
			humble = medium_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
		ai_chance = {
			# Low base chance so that only really sore losers will pick fights over simple games.
			base = 0
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_sociability = -1
			}
		}
	}

	# Well, the better GetWomanMan won!
	option = {
		name = board_games.0041.c
		# We don't let you try this against players, mostly for simplicity's sakes.
		trigger = { is_ai = no }

		# Display ending type.
		bg_loser_end_result_tooltip_effect = yes
		# Run the duel.
		bg_make_friends_after_game_effect = {
			ACTOR = scope:bg_loser
			RECIPIENT = scope:bg_victor
		}

		stress_impact = {
			humble = miniscule_stress_impact_loss
			forgiving = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			arrogant = medium_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
				ai_vengefulness = -1
			}
		}
	}
}

##################################################
# Lucky Chess Board
# by Ewan Cowhig Croft
# 0051 - 0060
##################################################

#	You favour a particular chess board after a lucky win.
board_games.0051 = {
	type = character_event
	title = board_games.0051.t
	desc = board_games.0051.desc
	theme = martial_strategy_focus
	left_portrait = {
		character = scope:bg_victor
		animation = admiration
	}
	right_portrait = {
		character = scope:bg_loser
		animation = dismissal
	}
	override_background = { reference = sitting_room }

	#cooldown = { years = 100 }

	trigger = {
		# DLC check.
		OR = {
			has_fp2_dlc_trigger = yes
			has_tgp_dlc_trigger = yes
		}
		# Standard checks.
		is_available_at_peace_adult = yes
		is_landed = yes
		# Doesn't have a suitable board game.
		NOT = {
			any_character_artifact = { has_variable = can_be_used_for_board_games }
		}
	}

	# Ahhh, sure to bring good luck forever more!
	option = {
		name = board_games.0051.a

		# You gain a standard 2p chess board!
		create_artifact_fp2_2p_chess_board_effect = { OWNER = scope:bg_victor }

		# No stress impact here.
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 1
				ai_rationality = 0.5
			}
		}
	}

	# Just a few more pieces and I could have a rare set...
	option = {
		name = board_games.0051.b
		trigger = {
			location = {
				bg_game_type_region_go_trigger = no
			}
		}

		remove_short_term_gold = medium_gold_value

		# You gain an exotic 4p chess board!
		create_artifact_fp2_4p_chess_board_effect = { OWNER = scope:bg_victor }

		# No stress impact here.
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 1
				ai_energy = 0.5
			}
		}
	}

	# I don't need special toys.
	option = {
		name = board_games.0051.c

		# You're truckin' along just fine without all these newfangled games.
		add_stress = minor_stress_loss

		# No stress impact here.
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = -0.25
				ai_sociability = -0.5
			}
		}
	}
}


##################################################
# Debug Events
# by Ewan Cowhig Croft
# 0101 - 0130
##################################################

#	Error suppression.
board_games.0101 = {
	hidden = yes
	orphan = yes

	immediate = {
		# Hidden effect blocks used for easy collapsing.
		# Types of game.
		hidden_effect = {
			save_scope_value_as = {
				name = bg_system
				value = flag:chess
			}
			save_scope_value_as = {
				name = bg_system
				value = flag:pachisi
			}
			save_scope_value_as = {
				name = bg_system
				value = flag:tabula
			}
			save_scope_value_as = {
				name = bg_system
				value = flag:hnefatafl
			}
			save_scope_value_as = {
				name = bg_system
				value = flag:go
			}
			save_scope_value_as = {
				name = bg_system
				value = flag:fidchell
			}
		}
		# Backgrounds.
		hidden_effect = {
			save_scope_value_as = {
				name = bg_locale
				value = flag:terrain_scope
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:wilderness_scope
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:battlefield
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:temple
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:council_chamber
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:courtyard
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:dungeon
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:docks
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:feast
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:gallows
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:garden
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:market
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:sitting_room
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:bedchamber
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:study
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:physicians_study
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:tavern
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:throne_room
			}
			save_scope_value_as = {
				name = bg_locale
				value = flag:army_camp
			}
		}
		# Random variables.
		hidden_effect = {
			if = {
				limit = { exists = var:bg_recent_land_loss_stake }
			}
		}
	}
}

#	Debug board games.
board_games.0102 = {
	type = character_event
	title = board_games.0102.t
	desc = board_games.0102.desc
	theme = martial_strategy_focus
	left_portrait = {
		character = scope:actor
		animation = throne_room_applaud_1
	}
	right_portrait = {
		character = scope:recipient
		animation = fear
	}
	override_background = { reference = sitting_room }

	# Ordinary game, please.
	option = {
		name = board_games.0102.a

		# No special anything needed.
	}

	# Foe only uses winning locs, please.
	option = {
		name = board_games.0102.b

		set_variable = bg_gib_only_winning_locs
	}

	# Foe only uses losing locs, please.
	option = {
		name = board_games.0102.c

		set_variable = bg_gib_only_losing_locs
	}

	after = {
		# Chess.
		if = {
			limit = { scope:board_game_chess = yes }
			configure_start_board_game_effect = {
				BG_INITIATOR = scope:actor
				BG_ATTACKER = scope:actor
				BG_DEFENDER = scope:recipient
				SYSTEM = chess
				LOCALE = random_nice_day
				OUTPUT_EVENT = perk_interaction.0121
				INVALIDATION_EVENT = board_games.0021
			}
		}
		# Pachisi.
		if = {
			limit = { scope:board_game_pachisi = yes }
			configure_start_board_game_effect = {
				BG_INITIATOR = scope:actor
				BG_ATTACKER = scope:actor
				BG_DEFENDER = scope:recipient
				SYSTEM = pachisi
				LOCALE = random_nice_day
				OUTPUT_EVENT = perk_interaction.0121
				INVALIDATION_EVENT = board_games.0021
			}
		}
		# Tabula.
		if = {
			limit = { scope:board_game_tabula = yes }
			configure_start_board_game_effect = {
				BG_INITIATOR = scope:actor
				BG_ATTACKER = scope:actor
				BG_DEFENDER = scope:recipient
				SYSTEM = tabula
				LOCALE = random_nice_day
				OUTPUT_EVENT = perk_interaction.0121
				INVALIDATION_EVENT = board_games.0021
			}
		}
		# Hnefatafl.
		if = {
			limit = { scope:board_game_hnefatafl = yes }
			configure_start_board_game_effect = {
				BG_INITIATOR = scope:actor
				BG_ATTACKER = scope:actor
				BG_DEFENDER = scope:recipient
				SYSTEM = hnefatafl
				LOCALE = random_nice_day
				OUTPUT_EVENT = perk_interaction.0121
				INVALIDATION_EVENT = board_games.0021
			}
		}
		# Go.
		if = {
			limit = { scope:board_game_go = yes }
			configure_start_board_game_effect = {
				BG_INITIATOR = scope:actor
				BG_ATTACKER = scope:actor
				BG_DEFENDER = scope:recipient
				SYSTEM = go
				LOCALE = random_nice_day
				OUTPUT_EVENT = perk_interaction.0121
				INVALIDATION_EVENT = board_games.0021
			}
		}
		# Fidchell.
		if = {
			limit = { scope:board_game_fidchell = yes }
			configure_start_board_game_effect = {
				BG_INITIATOR = scope:actor
				BG_ATTACKER = scope:actor
				BG_DEFENDER = scope:recipient
				SYSTEM = fidchell
				LOCALE = random_nice_day
				OUTPUT_EVENT = perk_interaction.0121
				INVALIDATION_EVENT = board_games.0021
			}
		}
	}
}
