-
Notifications
You must be signed in to change notification settings - Fork 1
/
HandManager.gd
246 lines (210 loc) · 7.67 KB
/
HandManager.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
class_name HandManager extends Node
@export var dealerAI : DealerIntelligence
@export var itemManager : ItemManager
@export var animator_hands : AnimationPlayer
@export var animator_dealerHeadLook : AnimationPlayer
@export var handArray_L : Array[Node3D]
@export var handArray_R : Array[Node3D]
@export var gridOffsetArray : Array[Vector3] #ITEM'S ACTIVE GRID INDEX STORED IN PICKUP INDICATOR: dealerGridIndex
@export var inter : ItemInteraction
@export var cam : CameraManager
@export var handParent_L : Node3D
@export var handParent_R : Node3D
@export var hand_defaultL : Node3D
@export var hand_defaultR : Node3D
@export var hand_cigarettepack : Node3D #L
@export var hand_beer : Node3D #L
@export var hand_medicine : Node3D #L
@export var hand_inverter : Node3D #L
@export var hand_adrenaline : Node3D #L
@export var hand_handcuffs : Node3D #R
@export var hand_handsaw : Node3D #R
@export var hand_magnifier : Node3D #R
@export var hand_burnerphone : Node3D #R
@export var lerpDuration : float
@export var handRot_left : Vector3 #hand rotation when grabing from left grids
@export var handRot_right : Vector3 #same shit
@export var parentOriginal_posL : Vector3
@export var parentOriginal_rotL : Vector3
@export var parentOriginal_posR : Vector3
@export var parentOriginal_rotR : Vector3
@export var amounts : Amounts
var moving = false
var lerping_L = false
var lerping_R = false
var pos_current
var pos_next
var rot_current
var rot_next
var elapsed = 0
var orig_pos
var orig_rot
var activeHandParent
var activeItemToGrab
func _process(delta):
LerpHandMovement()
var stealing = false
func PickupItemFromTable(itemName : String):
dealerAI.Speaker_HandCrack()
var activeIndex
var activeInstance
var whichHandToGrabWith
var whichGridSide
var matchIndex
activeItemToGrab = itemName
for i in range(itemManager.itemArray_instances_dealer.size()):
if (itemName == itemManager.itemArray_instances_dealer[i].get_child(1).itemName):
activeInstance = itemManager.itemArray_instances_dealer[i]
matchIndex = i
break
activeIndex = activeInstance.get_child(0).dealerGridIndex
ToggleHandVisible("BOTH", false)
hand_defaultL.visible = true
hand_defaultR.visible = true
if (itemName == "beer" or itemName == "cigarettes" or itemName == "expired medicine" or itemName == "inverter" or itemName == "adrenaline"): whichHandToGrabWith = "left"
else: whichHandToGrabWith = "right"
whichGridSide = activeInstance.get_child(0).whichSide
animator_hands.play("RESET")
BeginHandLerp(whichHandToGrabWith, activeIndex, whichGridSide)
if (whichGridSide == "right"): animator_dealerHeadLook.play("dealer look right")
else: animator_dealerHeadLook.play("dealer look left")
if (stealing):
if (whichGridSide == "right"): cam.BeginLerp("player item grid left")
else: cam.BeginLerp("player item grid right")
var amountArray : Array[AmountResource] = amounts.array_amounts
for res in amountArray:
if res.itemName == itemName: res.amount_player -= 1
break
await get_tree().create_timer(lerpDuration -.4, false).timeout
if (whichHandToGrabWith == "right"): hand_defaultR.visible = false
else: hand_defaultL.visible = false
dealerAI.Speaker_HandCrack()
match (itemName):
"handsaw":
hand_handsaw.visible = true
"magnifying glass":
hand_magnifier.visible = true
"handcuffs":
hand_handcuffs.visible = true
"cigarettes":
hand_cigarettepack.visible = true
itemManager.numberOfCigs_dealer -= 1
"beer":
hand_beer.visible = true
"expired medicine":
hand_medicine.visible = true
"inverter":
hand_inverter.visible = true
"burner phone":
hand_burnerphone.visible = true
"adrenaline":
hand_adrenaline.visible = true
itemManager.itemArray_instances_dealer.remove_at(matchIndex)
var tempindicator = activeInstance.get_child(0)
var gridname = tempindicator.dealerGridName
if (!stealing): itemManager.gridParentArray_enemy_available.append(gridname)
if (stealing): inter.RemovePlayerItemFromGrid(activeInstance)
activeInstance.queue_free()
await get_tree().create_timer(.2, false).timeout
ReturnHand()
if (stealing):
cam.BeginLerp("enemy")
if (whichGridSide == "right"): animator_dealerHeadLook.play("dealer look forward from right")
else: animator_dealerHeadLook.play("dealer look forward from left")
await get_tree().create_timer(lerpDuration + .01, false).timeout
HandFailsafe()
var animationName = "dealer use " + itemName
PlaySound(itemName)
animator_hands.play("RESET")
animator_hands.play(animationName)
var length = animator_hands.get_animation(animationName).get_length()
moving = false
await get_tree().create_timer(length, false).timeout
stealing = false
pass
@export var speaker_interaction : AudioStreamPlayer2D
@export var sound_adrenaline : AudioStream
@export var sound_medicine : AudioStream
@export var sound_burnerphone : AudioStream
@export var sound_inverter : AudioStream
func PlaySound(itemName : String):
match itemName:
"adrenaline":
speaker_interaction.stream = sound_adrenaline
speaker_interaction.play()
"expired medicine":
speaker_interaction.stream = sound_medicine
speaker_interaction.play()
"burner phone":
speaker_interaction.stream = sound_burnerphone
speaker_interaction.play()
"inverter":
speaker_interaction.stream = sound_inverter
speaker_interaction.play()
func RemoveItem_Remote(activeInstance : Node3D):
var activeIndex
var whichHandToGrabWith
var whichGridSide
var matchIndex
itemManager.itemArray_dealer.erase(activeInstance.get_child(1).itemName.to_lower())
itemManager.numberOfItemsGrabbed_enemy -= 1
activeIndex = activeInstance.get_child(0).dealerGridIndex
whichGridSide = activeInstance.get_child(0).whichSide
itemManager.itemArray_instances_dealer.erase(activeInstance)
var tempindicator = activeInstance.get_child(0)
var gridname = tempindicator.dealerGridName
itemManager.gridParentArray_enemy_available.append(gridname)
pass
func ToggleHandVisible(selectedHand : String, state : bool):
if (selectedHand == "L" or "BOTH"):
for i in range(handArray_L.size()):
if (state): handArray_L[i].visible = true
else: handArray_L[i].visible = false
if (selectedHand == "R" or "BOTH"):
for i in range(handArray_R.size()):
if (state): handArray_R[i].visible = true
else: handArray_R[i].visible = false
func BeginHandLerp(whichHand : String, gridIndex : int, whichSide : String):
if (whichHand == "right"): activeHandParent = handParent_R
else: activeHandParent = handParent_L
pos_current = activeHandParent.transform.origin
rot_current = activeHandParent.rotation_degrees
orig_pos = pos_current
orig_rot = rot_current
pos_next = gridOffsetArray[gridIndex]
lerping_L = false
lerping_R = false
if(whichSide == "right"): rot_next = handRot_right
else: rot_next = handRot_left
if(whichHand == "right"): lerping_R = true
else: lerping_L = true
elapsed = 0
moving = true
func ReturnHand():
pos_current = activeHandParent.transform.origin
rot_current = activeHandParent.rotation_degrees
pos_next = orig_pos
rot_next = orig_rot
elapsed = 0
moving = true
func HandFailsafe():
handParent_L.transform.origin = parentOriginal_posL
handParent_L.rotation_degrees = parentOriginal_rotL
handParent_R.transform.origin = parentOriginal_posR
handParent_R.rotation_degrees = parentOriginal_rotR
func LerpHandMovement():
if (moving):
elapsed += get_process_delta_time()
var c = clampf(elapsed / lerpDuration, 0.0, 1.0)
c = ease(c, 0.2)
if (lerping_L):
var pos = lerp(pos_current, pos_next, c)
var rot = lerp(rot_current, rot_next, c)
handParent_L.transform.origin = pos
handParent_L.rotation_degrees = rot
if (lerping_R):
var pos = lerp(pos_current, pos_next, c)
var rot = lerp(rot_current, rot_next, c)
handParent_R.transform.origin = pos
handParent_R.rotation_degrees = rot
pass