Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GolfState.cs
Go to the documentation of this file.
2using Terraria.ID;
3
5
6public class GolfState
7{
8 private const int BALL_RETURN_PENALTY = 1;
9
10 private int golfScoreTime;
11
12 private int golfScoreTimeMax = 3600;
13
14 private int golfScoreDelay = 90;
15
16 private double _lastRecordedBallTime;
17
19
21
23
25
27
29
30 public float ScoreAdjustment => (float)golfScoreTime / (float)golfScoreTimeMax;
31
33
34 public bool IsTrackingBall
35 {
36 get
37 {
38 if (GetLastHitBall() != null)
39 {
41 }
42 return false;
43 }
44 }
45
47 {
48 get
49 {
50 if (_lastRecordedBallTime + 2.0 >= Main.gameTimeCache.TotalGameTime.TotalSeconds)
51 {
52 return GetLastHitBall() == null;
53 }
54 return false;
55 }
56 }
57
58 private void UpdateScoreTime()
59 {
61 {
63 }
64 }
65
66 public void ResetScoreTime()
67 {
68 golfScoreTime = 0;
69 }
70
71 public void SetScoreTime()
72 {
74 }
75
80
81 public void WorldClear()
82 {
83 _lastHitGolfBall = null;
88 }
89
90 public void CancelBallTracking()
91 {
93 }
94
95 public void RecordSwing(Projectile golfBall)
96 {
98 _lastHitGolfBall = golfBall;
99 _lastRecordedSwingCount = (int)golfBall.ai[1];
101 int golfBallId = GetGolfBallId(golfBall);
102 if (_hitRecords[golfBallId] == null || _lastRecordedSwingCount == 1)
103 {
104 _hitRecords[golfBallId] = new GolfBallTrackRecord();
105 }
106 _hitRecords[golfBallId].RecordHit(golfBall.position);
107 }
108
109 private int GetGolfBallId(Projectile golfBall)
110 {
111 return golfBall.whoAmI;
112 }
113
122
123 public void Update()
124 {
126 Projectile lastHitBall = GetLastHitBall();
127 if (lastHitBall == null)
128 {
130 return;
131 }
133 {
134 _waitingForBallToSettle = (int)lastHitBall.localAI[1] == 1;
135 }
136 bool flag = false;
137 int type = Main.LocalPlayer.HeldItem.type;
138 if (type == 3611)
139 {
140 flag = true;
141 }
142 if (!Item.IsAGolfingItem(Main.LocalPlayer.HeldItem) && !flag)
143 {
145 }
146 }
147
148 public void RecordBallInfo(Projectile golfBall)
149 {
150 if (GetLastHitBall() == golfBall && _waitingForBallToSettle)
151 {
153 _lastRecordedBallTime = Main.gameTimeCache.TotalGameTime.TotalSeconds;
154 }
155 }
156
157 public void LandBall(Projectile golfBall)
158 {
159 int golfBallId = GetGolfBallId(golfBall);
160 _hitRecords[golfBallId]?.RecordHit(golfBall.position);
161 }
162
163 public int GetGolfBallScore(Projectile golfBall)
164 {
165 int golfBallId = GetGolfBallId(golfBall);
166 GolfBallTrackRecord golfBallTrackRecord = _hitRecords[golfBallId];
167 if (golfBallTrackRecord == null)
168 {
169 return 0;
170 }
171 return (int)((float)golfBallTrackRecord.GetAccumulatedScore() * ScoreAdjustment);
172 }
173
174 public void ResetGolfBall()
175 {
176 Projectile lastHitBall = GetLastHitBall();
177 if (lastHitBall != null && !(Vector2.Distance(lastHitBall.position, _lastSwingPosition) < 1f))
178 {
179 lastHitBall.position = _lastSwingPosition;
180 lastHitBall.velocity = Vector2.Zero;
181 lastHitBall.ai[1] += 1f;
182 lastHitBall.netUpdate2 = true;
183 _lastRecordedSwingCount = (int)lastHitBall.ai[1];
184 }
185 }
186}
Vector2 Center
Definition Entity.cs:43
Vector2 position
Definition Entity.cs:14
GolfBallTrackRecord[] _hitRecords
Definition GolfState.cs:28
void RecordSwing(Projectile golfBall)
Definition GolfState.cs:95
void RecordBallInfo(Projectile golfBall)
Definition GolfState.cs:148
void LandBall(Projectile golfBall)
Definition GolfState.cs:157
int GetGolfBallId(Projectile golfBall)
Definition GolfState.cs:109
int GetGolfBallScore(Projectile golfBall)
Definition GolfState.cs:163
static bool IsAGolfingItem(Item item)
Definition Item.cs:46650
static GameTime gameTimeCache
Definition Main.cs:409
static int myPlayer
Definition Main.cs:1801
static Player LocalPlayer
Definition Main.cs:2829
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91