Client LuaCsForBarotrauma
FishAnimations.cs
1 using Microsoft.Xna.Framework;
2 using System.Collections.Generic;
3 
4 namespace Barotrauma
5 {
7  {
8  public static FishWalkParams GetDefaultAnimParams(Character character)
9  {
10  return Check(character) ? GetDefaultAnimParams<FishWalkParams>(character, AnimationType.Walk) : Empty;
11  }
12  public static FishWalkParams GetAnimParams(Character character, Either<string, ContentPath> file, bool throwErrors = true)
13  {
14  return Check(character) ? GetAnimParams<FishWalkParams>(character, AnimationType.Walk, file, throwErrors) : null;
15  }
16 
17  protected static readonly FishWalkParams Empty = new FishWalkParams();
18 
19  public override void StoreSnapshot() => StoreSnapshot<FishWalkParams>();
20  }
21 
23  {
24  public static FishRunParams GetDefaultAnimParams(Character character)
25  {
26  return Check(character) ? GetDefaultAnimParams<FishRunParams>(character, AnimationType.Run) : Empty;
27  }
28  public static FishRunParams GetAnimParams(Character character, Either<string, ContentPath> file, bool throwErrors = true)
29  {
30  return Check(character) ? GetAnimParams<FishRunParams>(character, AnimationType.Run, file, throwErrors) : null;
31  }
32 
33  protected static readonly FishRunParams Empty = new FishRunParams();
34 
35  public override void StoreSnapshot() => StoreSnapshot<FishRunParams>();
36  }
37 
39  {
40  public static FishSwimFastParams GetDefaultAnimParams(Character character) => GetDefaultAnimParams<FishSwimFastParams>(character, AnimationType.SwimFast);
41  public static FishSwimFastParams GetAnimParams(Character character, Either<string, ContentPath> file, bool throwErrors = true)
42  {
43  return GetAnimParams<FishSwimFastParams>(character, AnimationType.SwimFast, file, throwErrors);
44  }
45 
46  public override void StoreSnapshot() => StoreSnapshot<FishSwimFastParams>();
47  }
48 
50  {
51  public static FishSwimSlowParams GetDefaultAnimParams(Character character) => GetDefaultAnimParams<FishSwimSlowParams>(character, AnimationType.SwimSlow);
52  public static FishSwimSlowParams GetAnimParams(Character character, Either<string, ContentPath> file, bool throwErrors = true)
53  {
54  return GetAnimParams<FishSwimSlowParams>(character, AnimationType.SwimSlow, file, throwErrors);
55  }
56 
57  public override void StoreSnapshot() => StoreSnapshot<FishSwimSlowParams>();
58  }
59 
61  {
62  protected static bool Check(Character character)
63  {
64  if (!character.AnimController.CanWalk)
65  {
66  DebugConsole.ThrowError($"{character.SpeciesName} cannot use run animations!",
67  contentPackage: character.Prefab.ContentPackage);
68  return false;
69  }
70  return true;
71  }
72 
73  [Editable, Serialize(true, IsPropertySaveable.Yes, description: "Should the character be flipped depending on which direction it faces. Should usually be enabled on all characters that have distinctive upper and lower sides.")]
74  public bool Flip { get; set; }
75 
76  [Serialize(1f, IsPropertySaveable.Yes, description: "Reduces continuous flipping when the character abruptly changes direction."), Editable]
77  public float FlipCooldown { get; set; }
78 
79  [Serialize(0.5f, IsPropertySaveable.Yes, description: "How much it takes before the character flips. The timer starts when the character starts to move in the different direction."), Editable]
80  public float FlipDelay { get; set; }
81 
82  [Serialize(10.0f, IsPropertySaveable.Yes, description: "How much force is used to move the head to the correct position."), Editable(MinValueFloat = 0, MaxValueFloat = 100)]
83  public float HeadMoveForce { get; set; }
84 
85  [Serialize(10.0f, IsPropertySaveable.Yes, description: "How much force is used to move the torso to the correct position."), Editable(MinValueFloat = 0, MaxValueFloat = 100)]
86  public float TorsoMoveForce { get; set; }
87 
88  [Serialize(8.0f, IsPropertySaveable.Yes, description: "How much force is used to move the feet to the correct position."), Editable(MinValueFloat = 0, MaxValueFloat = 100)]
89  public float FootMoveForce { get; set; }
90 
91  [Serialize(50.0f, IsPropertySaveable.Yes, description: "How much torque is used to rotate the tail to the correct orientation."), Editable(MinValueFloat = 0, MaxValueFloat = 1000, ValueStep = 1)]
92  public float TailTorque { get; set; }
93 
94  [Serialize(0.0f, IsPropertySaveable.Yes, description: "Optional torque that's constantly applied to legs."), Editable(MinValueFloat = 0, MaxValueFloat = 1000)]
95  public float LegTorque { get; set; }
96 
101  [Serialize(0f, IsPropertySaveable.Yes, description: "The angle of the character's collider when standing."), Editable(MinValueFloat = -360, MaxValueFloat = 360)]
102  public float ColliderStandAngle
103  {
104  get => MathHelper.ToDegrees(ColliderStandAngleInRadians);
105  set => ColliderStandAngleInRadians = MathHelper.ToRadians(value);
106  }
107  public float ColliderStandAngleInRadians { get; private set; }
108 
110  public string FootAngles
111  {
113  set => SetFootAngles(FootAnglesInRadians, value);
114  }
115 
119  public Dictionary<int, float> FootAnglesInRadians { get; set; } = new Dictionary<int, float>();
120 
124  [Serialize(float.NaN, IsPropertySaveable.Yes), Editable(-360f, 360f)]
125  public float TailAngle
126  {
127  get => float.IsNaN(TailAngleInRadians) ? float.NaN : MathHelper.ToDegrees(TailAngleInRadians);
128  set
129  {
130  if (!float.IsNaN(value))
131  {
132  TailAngleInRadians = MathHelper.ToRadians(value);
133  }
134  }
135  }
136  public float TailAngleInRadians { get; private set; } = float.NaN;
137  }
138 
140  {
141  [Serialize(false, IsPropertySaveable.Yes, description: "Instead of linear movement (default), use a wave-like movement. Note: WaveAmplitude and WaveLength don't have any effect on this. It's synced with the movement speed."), Editable]
142  public bool UseSineMovement { get; set; }
143 
144  [Editable, Serialize(true, IsPropertySaveable.Yes, description: "Should the character be flipped depending on which direction it faces. Should usually be enabled on all characters that have distinctive upper and lower sides.")]
145  public bool Flip { get; set; }
146 
147  [Serialize(1f, IsPropertySaveable.Yes, description: "Reduces continuous flipping when the character abruptly changes direction."), Editable]
148  public float FlipCooldown { get; set; }
149 
150  [Serialize(0.5f, IsPropertySaveable.Yes, description: "How much it takes before the character flips. The timer starts when the character starts to move in the different direction."), Editable]
151  public float FlipDelay { get; set; }
152 
153  [Editable, Serialize(true, IsPropertySaveable.Yes, description: "If enabled, the character will simply be mirrored horizontally when it wants to turn around. If disabled, it will rotate itself to face the other direction.")]
154  public bool Mirror { get; set; }
155 
156  [Editable, Serialize(true, IsPropertySaveable.Yes, description: "Disabling this will make mirroring instantaneous.")]
157  public bool MirrorLerp { get; set; }
158 
160  public float WaveAmplitude { get; set; }
161 
162  [Serialize(10.0f, IsPropertySaveable.Yes), Editable]
163  public float WaveLength { get; set; }
164 
165  [Editable, Serialize(true, IsPropertySaveable.Yes, description: "Should the character face towards the direction it's heading.")]
166  public bool RotateTowardsMovement { get; set; }
167 
168  [Serialize(50.0f, IsPropertySaveable.Yes, description: "How much torque is used to rotate the tail to the correct orientation."), Editable(MinValueFloat = 0, MaxValueFloat = 2000, ValueStep = 1)]
169  public float TailTorque { get; set; }
170 
171  [Serialize(1f, IsPropertySaveable.Yes, description: "Multiplier applied based on the angle difference between the tail and the main limb. Increasing the value prevents snake-like characters from getting tangled on themselves. Default = 1 (no boost)"), Editable(MinValueFloat = 1, MaxValueFloat = 100)]
172  public float TailTorqueMultiplier { get; set; }
173 
175  public string FootAngles
176  {
178  set => SetFootAngles(FootAnglesInRadians, value);
179  }
180 
181  [Serialize(false, IsPropertySaveable.Yes, description: "Should the animation be updated even if the character is not moving?"), Editable]
182  public bool UpdateAnimationWhenNotMoving { get; set; }
183 
187  public Dictionary<int, float> FootAnglesInRadians { get; set; } = new Dictionary<int, float>();
188 
192  [Serialize(float.NaN, IsPropertySaveable.Yes), Editable(-360f, 360f)]
193  public float TailAngle
194  {
195  get => float.IsNaN(TailAngleInRadians) ? float.NaN : MathHelper.ToDegrees(TailAngleInRadians);
196  set
197  {
198  if (!float.IsNaN(value))
199  {
200  TailAngleInRadians = MathHelper.ToRadians(value);
201  }
202  }
203  }
204  public float TailAngleInRadians { get; private set; } = float.NaN;
205  }
206 
207  interface IFishAnimation
208  {
209  string FootAngles { get; set; }
210  Dictionary<int, float> FootAnglesInRadians { get; set; }
211  float TailAngle { get; set; }
212  float TailAngleInRadians { get; }
213  float TailTorque { get; set; }
214  bool Flip { get; set; }
215  float FlipCooldown { get; set; }
216  float FlipDelay { get; set; }
217  }
218 }
static string ParseFootAngles(Dictionary< int, float > footAngles)
static void SetFootAngles(Dictionary< int, float > footAngles, string value)
Dictionary< int, float > FootAnglesInRadians
Key = limb id, value = angle in radians
static bool Check(Character character)
float ColliderStandAngle
The angle of the collider when standing (i.e. out of water). In degrees.
static FishRunParams GetDefaultAnimParams(Character character)
static FishRunParams GetAnimParams(Character character, Either< string, ContentPath > file, bool throwErrors=true)
static readonly FishRunParams Empty
override void StoreSnapshot()
static FishSwimFastParams GetAnimParams(Character character, Either< string, ContentPath > file, bool throwErrors=true)
static FishSwimFastParams GetDefaultAnimParams(Character character)
override void StoreSnapshot()
float? TailAngle
In degrees.
Dictionary< int, float > FootAnglesInRadians
Key = limb id, value = angle in radians
static FishSwimSlowParams GetAnimParams(Character character, Either< string, ContentPath > file, bool throwErrors=true)
static FishSwimSlowParams GetDefaultAnimParams(Character character)
override void StoreSnapshot()
static readonly FishWalkParams Empty
static FishWalkParams GetAnimParams(Character character, Either< string, ContentPath > file, bool throwErrors=true)
override void StoreSnapshot()
static FishWalkParams GetDefaultAnimParams(Character character)
ContentPackage? ContentPackage
Definition: Prefab.cs:37
Dictionary< int, float > FootAnglesInRadians