Skip to content

Commit ed395bf

Browse files
committed
Implement fire on release fire type
1 parent 28465b2 commit ed395bf

File tree

1 file changed

+70
-10
lines changed

1 file changed

+70
-10
lines changed

Scripts/AimAtCursorPlayerCharacterController.cs

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ protected void UpdateWASDInput()
249249
Vector3 moveDirection = GetMoveDirection(InputManager.GetAxis("Horizontal", raw), InputManager.GetAxis("Vertical", raw));
250250
moveDirection.Normalize();
251251

252+
// Get fire type
253+
FireType fireType = FireType.SingleFire;
254+
IWeaponItem leftHandItem = PlayerCharacterEntity.EquipWeapons.GetLeftHandWeaponItem();
255+
IWeaponItem rightHandItem = PlayerCharacterEntity.EquipWeapons.GetRightHandWeaponItem();
256+
if (isLeftHandAttacking && leftHandItem != null)
257+
{
258+
fireType = leftHandItem.FireType;
259+
}
260+
else if (!isLeftHandAttacking && rightHandItem != null)
261+
{
262+
fireType = rightHandItem.FireType;
263+
}
264+
else
265+
{
266+
fireType = GameInstance.Singleton.DefaultWeaponItem.FireType;
267+
}
268+
252269
if (moveDirection.sqrMagnitude > 0f)
253270
{
254271
// Character start moving, so hide npc dialog
@@ -262,10 +279,47 @@ protected void UpdateWASDInput()
262279
avoidAttackWhileCursorOverUI = true;
263280

264281
// Attack when player pressed attack button
265-
if (!avoidAttackWhileCursorOverUI && !UICharacterHotkeys.UsingHotkey &&
266-
(InputManager.GetButton("Fire1") || InputManager.GetButton("Attack") ||
267-
InputManager.GetButtonUp("Fire1") || InputManager.GetButtonUp("Attack")))
268-
UpdateFireInput();
282+
if (!avoidAttackWhileCursorOverUI && !UICharacterHotkeys.UsingHotkey)
283+
{
284+
// NOTE: With this controller, single fire will do the same as automatic
285+
if (InputManager.GetButtonDown("Fire1") || InputManager.GetButtonDown("Attack"))
286+
{
287+
switch (fireType)
288+
{
289+
case FireType.SingleFire:
290+
case FireType.Automatic:
291+
Attack();
292+
break;
293+
case FireType.FireOnRelease:
294+
WeaponCharge();
295+
break;
296+
}
297+
}
298+
else if (InputManager.GetButton("Fire1") || InputManager.GetButtonUp("Attack"))
299+
{
300+
switch (fireType)
301+
{
302+
case FireType.SingleFire:
303+
case FireType.Automatic:
304+
Attack();
305+
break;
306+
case FireType.FireOnRelease:
307+
break;
308+
}
309+
}
310+
else if (InputManager.GetButtonUp("Fire1") || InputManager.GetButtonUp("Attack"))
311+
{
312+
switch (fireType)
313+
{
314+
case FireType.SingleFire:
315+
case FireType.Automatic:
316+
break;
317+
case FireType.FireOnRelease:
318+
Attack();
319+
break;
320+
}
321+
}
322+
}
269323

270324
// No pointer over ui and all attack key released, stop avoid attack inputs
271325
if (avoidAttackWhileCursorOverUI && !isPointerOverUIObject &&
@@ -280,13 +334,19 @@ protected void UpdateWASDInput()
280334
PlayerCharacterEntity.KeyMovement(moveDirection, movementState);
281335
}
282336

283-
protected void UpdateFireInput()
337+
protected void Attack()
284338
{
285-
if (!ConstructingBuildingEntity)
286-
{
287-
if (PlayerCharacterEntity.Attack(isLeftHandAttacking))
288-
isLeftHandAttacking = !isLeftHandAttacking;
289-
}
339+
if (ConstructingBuildingEntity)
340+
return;
341+
if (PlayerCharacterEntity.Attack(isLeftHandAttacking))
342+
isLeftHandAttacking = !isLeftHandAttacking;
343+
}
344+
345+
protected void WeaponCharge()
346+
{
347+
if (ConstructingBuildingEntity)
348+
return;
349+
PlayerCharacterEntity.StartCharge(isLeftHandAttacking);
290350
}
291351

292352
protected void UpdateLookInput()

0 commit comments

Comments
 (0)