9 private float mentalStateTimer;
10 private const float MentalStateInterval = 7.5f;
12 private float mentalBehaviorTimer;
13 private const float MentalBehaviorInterval = 7.5f;
29 private const string MentalTeamChange =
"mental";
33 this.character = character;
34 this.humanAIController = humanAIController;
40 mentalStateTimer -= deltaTime;
41 if (mentalStateTimer <= 0.0f)
44 mentalStateTimer = MentalStateInterval * Rand.Range(0.75f, 1.25f);
47 mentalBehaviorTimer = Math.Max(0f, mentalBehaviorTimer - deltaTime);
50 private void UpdateMentalState()
52 MentalType newMentalType = GetMentalType(character.CharacterHealth.GetAffliction(
"psychosis"));
53 bool createdCombat =
false;
55 switch (newMentalType)
60 mentalBehaviorTimer = 0f;
85 character.TryRemoveTeamChange(MentalTeamChange);
91 private int mentalTypeCount;
92 private int MentalTypeCount
96 if (mentalTypeCount == 0)
98 mentalTypeCount = Enum.GetNames(typeof(
MentalType)).Length;
100 return mentalTypeCount;
104 private MentalType GetMentalType(Affliction affliction)
106 if (affliction ==
null)
110 int psychosisIndex = (int)(affliction.Strength / (affliction.Prefab.MaxStrength / MentalTypeCount) * Rand.Range(1f, 1.2f));
111 psychosisIndex = Math.Clamp(psychosisIndex, 0, 4);
119 _ =>
throw new ArgumentOutOfRangeException(psychosisIndex.ToString()),
128 (possibleTarget.TeamID != character.TeamID || mentalType ==
MentalType.Berserk) &&
129 humanAIController.VisibleHulls.Contains(possibleTarget.CurrentHull) &&
130 possibleTarget != character).GetRandomUnsynced();
132 if (mentalAttackTarget ==
null)
138 bool holdFire = mentalType ==
MentalType.Afraid && character.IsSecurity;
154 mentalBehaviorTimer = MentalBehaviorInterval;
155 humanAIController.AddCombatObjective(combatMode, mentalAttackTarget, allowHoldFire: holdFire, abortCondition: obj => mentalBehaviorTimer <= 0f);
156 Identifier textIdentifier = $
"dialogmentalstatereaction{combatMode}".ToIdentifier();
157 character.Speak(TextManager.Get(textIdentifier).Value, delay: Rand.Range(0.5f, 1.0f), identifier: textIdentifier, minDurationBetweenSimilar: 25f);
159 if (mentalType ==
MentalType.Berserk && !character.HasTeamChange(MentalTeamChange))
170 if (mentalType ==
MentalType.Normal) {
return; }
171 Identifier textIdentifier = $
"dialogmentalstate{mentalType}".ToIdentifier();
172 character.Speak(TextManager.Get(textIdentifier).Value, delay: Rand.Range(0.5f, 1.0f), identifier: textIdentifier, minDurationBetweenSimilar: 35f);
static readonly List< Character > CharacterList
static bool IsActive(Character c)
bool CreateCombatBehavior(MentalType mentalType)
MentalStateManager(Character character, HumanAIController humanAIController)
MentalType CurrentMentalType
void CreateDialogueBehavior(MentalType mentalType)
void Update(float deltaTime)