add doug to dialogue, start grandma quest
This commit is contained in:
@@ -0,0 +1,326 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public GameObject DougBody;
|
||||
|
||||
public Tool[] tools;
|
||||
float toolUseTimestamp = 0;
|
||||
|
||||
public float walkSpeed;
|
||||
public float sprintMultiplier = 1.5f;
|
||||
public float gravity = 10;
|
||||
|
||||
Interactable nearestInteractable;
|
||||
private CharacterController characterController;
|
||||
private CameraController cameraController;
|
||||
private Vector3 moveDir;
|
||||
private bool hasControl = true; // set this to false if we want to stop reading player inputs
|
||||
private bool isSprinting = false;
|
||||
|
||||
// Mathematical plane used to catch the raycast from camera to get direction for
|
||||
// looking at the mouse
|
||||
private Plane groundPlane;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
groundPlane = new Plane(Vector3.up, -DougBody.transform.position.y);
|
||||
characterController = GetComponent<CharacterController>();
|
||||
cameraController = GetComponent<CameraController>();
|
||||
SwitchTools(GameManager.Instance.PlayerManager.CurrentToolIndex);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
moveDir = Vector3.zero;
|
||||
groundPlane.distance = -DougBody.transform.position.y;
|
||||
|
||||
if (hasControl)
|
||||
{
|
||||
if (!tools[GameManager.Instance.PlayerManager.CurrentToolIndex].inUse)
|
||||
{
|
||||
RotatePlayerTowardMouse();
|
||||
TryInteract();
|
||||
}
|
||||
|
||||
ToolUseDetector();
|
||||
ApplyWalk();
|
||||
|
||||
// TODO: This is just for testing, remove or clean up if used
|
||||
if (Input.GetKeyDown(KeyCode.Q))
|
||||
{
|
||||
cameraController.RotateCam();
|
||||
}
|
||||
|
||||
// TODO: Add actual save feature later, this is just for test
|
||||
if (Input.GetKeyDown(KeyCode.I))
|
||||
{
|
||||
SaveSystem.Save();
|
||||
}
|
||||
}
|
||||
|
||||
CheckWeaponChange();
|
||||
CheckSprint();
|
||||
ApplyGravity();
|
||||
DoMovement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if shift is being held, isSprinting is true if it is
|
||||
/// </summary>
|
||||
private void CheckSprint()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
isSprinting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isSprinting = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if weapon is being switched by scroll wheel
|
||||
/// </summary>
|
||||
private void CheckWeaponChange()
|
||||
{
|
||||
if (Input.mouseScrollDelta.y > 0)
|
||||
{
|
||||
SwitchTools(true);
|
||||
}
|
||||
else if (Input.mouseScrollDelta.y < 0)
|
||||
{
|
||||
SwitchTools(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply walking inputs to moveDir
|
||||
/// </summary>
|
||||
void ApplyWalk()
|
||||
{
|
||||
float verticalMovement = 0;
|
||||
float horizontalMovement = 0;
|
||||
|
||||
if (!tools[GameManager.Instance.PlayerManager.CurrentToolIndex].inUse)
|
||||
{
|
||||
verticalMovement = Input.GetAxisRaw("Vertical");
|
||||
horizontalMovement = Input.GetAxisRaw("Horizontal");
|
||||
}
|
||||
|
||||
moveDir = new Vector3(horizontalMovement, 0, verticalMovement).normalized;
|
||||
|
||||
if (cameraController != null)
|
||||
{
|
||||
// re-matrix the rotation direction so movement is consistent no matter what
|
||||
// the camera rotation is
|
||||
|
||||
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, cameraController.playerCamHome.rotation.eulerAngles.y, 0));
|
||||
moveDir = matrix.MultiplyPoint3x4(moveDir);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply gravity and speed to moveDir
|
||||
/// </summary>
|
||||
void ApplyGravity()
|
||||
{
|
||||
if (isSprinting)
|
||||
moveDir *= (walkSpeed * sprintMultiplier);
|
||||
else
|
||||
moveDir *= walkSpeed;
|
||||
|
||||
moveDir.y += -gravity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move character with moveDir
|
||||
/// </summary>
|
||||
void DoMovement()
|
||||
{
|
||||
characterController.Move(moveDir * Time.deltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pass movement into character controller, lets us expose function without exposing
|
||||
/// whole char controller
|
||||
/// </summary>
|
||||
public void CharacterControllerMove(Vector3 movement)
|
||||
{
|
||||
characterController.Move(movement);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auto-walk the character in the specified direction. Uses character's walk
|
||||
/// speed and camera rotation (per-frame)
|
||||
/// </summary>
|
||||
public void WalkInDirection(Vector3 direction)
|
||||
{
|
||||
Vector3 forwardDir = direction;
|
||||
forwardDir.y = 0; // don't move on the y axis
|
||||
|
||||
forwardDir *= walkSpeed;
|
||||
|
||||
characterController.Move(forwardDir * Time.deltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect input for tool use
|
||||
/// </summary>
|
||||
void ToolUseDetector()
|
||||
{
|
||||
if (!tools[GameManager.Instance.PlayerManager.CurrentToolIndex].inUse)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].Use();
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].inUse = true;
|
||||
toolUseTimestamp = Time.time + tools[GameManager.Instance.PlayerManager.CurrentToolIndex].useTimeSec; // fuck coroutines fr fr
|
||||
}
|
||||
else if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].UseAlt();
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].inUse = true;
|
||||
toolUseTimestamp = Time.time + tools[GameManager.Instance.PlayerManager.CurrentToolIndex].altUseTimeSec;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Time.time > toolUseTimestamp)
|
||||
{
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].inUse = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Face character graphic toward mouse
|
||||
/// </summary>
|
||||
void RotatePlayerTowardMouse()
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
if (groundPlane.Raycast(ray, out var distance))
|
||||
{
|
||||
Vector3 hitPoint = ray.GetPoint(distance);
|
||||
|
||||
DougBody.transform.LookAt(new Vector3(hitPoint.x, DougBody.transform.position.y, hitPoint.z));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to interact by detecting nearest interactable
|
||||
/// </summary>
|
||||
void TryInteract()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E) && nearestInteractable != null)
|
||||
{
|
||||
nearestInteractable.Interact();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Interactable interactable = other.GetComponent<Interactable>();
|
||||
|
||||
// store nearest interactable if it exists
|
||||
if (interactable != null)
|
||||
{
|
||||
nearestInteractable = interactable;
|
||||
interactable.MoveInsideRange();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
// just null out interactables when we leave an interactable trigger (we cant and shouldn't overlap interactables)
|
||||
Interactable interactable = other.GetComponent<Interactable>();
|
||||
|
||||
// store nearest interactable if it exists
|
||||
if (interactable != null && nearestInteractable != null)
|
||||
{
|
||||
nearestInteractable.MoveOutsideRange();
|
||||
nearestInteractable = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the character's "hasControl" bool. All input is ignored when false
|
||||
/// </summary>
|
||||
public void SetCharacterControl(bool hasControl)
|
||||
{
|
||||
this.hasControl = hasControl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character's "hasControl" bool. All input is ignored when false
|
||||
/// </summary>
|
||||
public bool GetCharacterHasControl()
|
||||
{
|
||||
return hasControl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Expose the character controller's velocity
|
||||
/// </summary>
|
||||
public Vector3 GetVelocity()
|
||||
{
|
||||
return characterController.velocity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switches the tools in hand by taking an index
|
||||
///
|
||||
/// <param name="toolIndex">Index of the tool to switch to</param>
|
||||
/// </summary>
|
||||
private void SwitchTools(int toolIndex)
|
||||
{
|
||||
if (toolIndex < 0 || toolIndex >= tools.Length)
|
||||
{
|
||||
toolIndex = 0;
|
||||
}
|
||||
|
||||
// disable all tools
|
||||
foreach (Tool tool in tools)
|
||||
{
|
||||
tool.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// load new tool
|
||||
GameManager.Instance.PlayerManager.CurrentToolIndex = toolIndex;
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switches the tools in hand by moving up or down the list
|
||||
///
|
||||
/// <param name="up">Are we moving up (-1) the list?</param>
|
||||
/// </summary>
|
||||
private void SwitchTools(bool up)
|
||||
{
|
||||
// calculate index of next tool
|
||||
int newIndex = up ? GameManager.Instance.PlayerManager.CurrentToolIndex - 1 : GameManager.Instance.PlayerManager.CurrentToolIndex + 1;
|
||||
|
||||
if (newIndex < 0)
|
||||
{
|
||||
newIndex = tools.Length + newIndex;
|
||||
}
|
||||
else if (newIndex >= tools.Length)
|
||||
{
|
||||
newIndex = newIndex % tools.Length;
|
||||
}
|
||||
|
||||
// disable current tool
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(false);
|
||||
|
||||
// load new tool
|
||||
GameManager.Instance.PlayerManager.CurrentToolIndex = newIndex;
|
||||
tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd992e504b31cbc45b8efb17f51e5f50
|
||||
@@ -5,9 +5,9 @@ public class Quest : MonoBehaviour
|
||||
public bool hasStarted = false;
|
||||
public bool hasCompleted = false;
|
||||
|
||||
public string[] askText; // ask the player to complete the task
|
||||
public string[] duringText; // what to say to the player when the task is complete
|
||||
public string[] completionText; // what to say to the player upon completion
|
||||
public DialogueLine[] askText; // ask the player to complete the task
|
||||
public DialogueLine[] duringText; // what to say to the player when the task is complete
|
||||
public DialogueLine[] completionText; // what to say to the player upon completion
|
||||
|
||||
public int questID = 0; // connects the quest to the registry, which gives us conditions
|
||||
|
||||
|
||||
@@ -53,6 +53,36 @@ private void Awake()
|
||||
questBoolMap.Add(1, QID1_List);
|
||||
#endregion
|
||||
|
||||
#region 2 - (Story Quest #1) No More Freeloading
|
||||
// This is the first time we talk to grandma. She wants help around the house.
|
||||
// Quest is complete after we talk to the shop keeper and complete quest 3.
|
||||
|
||||
QuestBool[] QID2_List = new QuestBool[1];
|
||||
|
||||
// QID2_1_completedQuest3
|
||||
QID1_List[0] = new QuestBool(() =>
|
||||
{
|
||||
return CompletedQuests.Contains(3);
|
||||
});
|
||||
|
||||
questBoolMap.Add(2, QID1_List);
|
||||
#endregion
|
||||
|
||||
#region 3 - (Story Quest #1.5) First Paycheck
|
||||
// This is the first time we talk to the shopkeeper. He tells us to find a star
|
||||
// shard and bring it to him.
|
||||
|
||||
QuestBool[] QID3_List = new QuestBool[1];
|
||||
|
||||
// QID3_1_hasEnoughStarshards
|
||||
QID1_List[0] = new QuestBool(() =>
|
||||
{
|
||||
return GameManager.Instance.Inventory.GetItemQuantity(ItemIdEnum.STAR_SHARD) > 0;
|
||||
});
|
||||
|
||||
questBoolMap.Add(3, QID1_List);
|
||||
#endregion
|
||||
|
||||
return questBoolMap;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,4 +7,8 @@ public class Storybools
|
||||
#region QID1
|
||||
public bool hasHelpedSam = false;
|
||||
#endregion
|
||||
|
||||
#region QID3
|
||||
public bool talkedToShopkeep = false;
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user