extends Resource
class_name MaskedChara

@export var character: CharacterResource
@export var face_mask: MaskResource
@export var mouth_mask: MaskResource

var pref_score_map: Dictionary[CharacterResource.Preference, float] = {
	CharacterResource.Preference.LOVE: 2.0,
	CharacterResource.Preference.APPROVE: 1.0,
	CharacterResource.Preference.DONT_CARE: 0.0,
	CharacterResource.Preference.DISAPPROVE: -1.0,
	CharacterResource.Preference.HATE: -2.0,
}

func _init(
	p_character: CharacterResource = CharacterResource.new(), 
	p_mask_face: MaskResource = MaskResource.new(),
	p_mask_mouth: MaskResource = MaskResource.new()):
	character = p_character
	face_mask = p_mask_face
	mouth_mask = p_mask_mouth


func compute_score(other_guests: Array[MaskedChara]) -> float:
	var overall_score = 0.0
	var preferences = character.preferences
	
	for guest in other_guests:
		if guest == null:
			continue
			
		var guest_mouth_mask = guest.mouth_mask
		var guest_traits = guest.character.traits
		
		var guest_appreciation = 0.0
		for guest_trait in guest_traits:
			var trait_strength = 0.0
			for stimuli in guest_trait.stimulis:
				var strength = stimuli
				if guest_mouth_mask != null and stimuli == guest_mouth_mask.stimuli:
					strength *= guest_mouth_mask.stimuli_multiplier
				if face_mask != null and stimuli == face_mask.stimuli:
					strength *= face_mask.stimuli_multiplier
				trait_strength += strength
			
			var preference = character.preferences.get(guest_trait) if guest_trait in character.preferences else CharacterResource.Preference.DONT_CARE
			var score_multiplier = pref_score_map.get(preference) if preference in pref_score_map else 0.0
			guest_appreciation += trait_strength*score_multiplier
			
			print("%s guest appreciation %s" % [character.name, guest_appreciation])
		
		overall_score += guest_appreciation
	
	print("%s score: %s" % [character.name, overall_score])
	return overall_score
