literally half of the game

This commit is contained in:
Sylvia 2026-08-27 04:07:01 -07:00
parent 1590b5faa6
commit b842289076
77 changed files with 11904 additions and 72 deletions

View file

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
{
@ -21,31 +23,41 @@ public class DialogueManager : MonoBehaviour
#endregion
private class Choice
{
public string choiceName;
public DialogueScript choiceScript;
}
[Header("Player")]
public Player player;
[Header("Dialogue Script")]
[SerializeField] private DialogueScript currentDialogueScript;
public DialogueScript currentDialogueScript;
public DialogueScript[] allDialogue;
public bool clickingDisabled = false;
private int textProgress;
public string[] scriptLines;
[Header("UI")]
public GameObject uiCanvas;
public TextMeshProUGUI nameText;
public TextMeshProUGUI dialogueText;
private void Start()
{
StartDialogue(currentDialogueScript);
}
public Button choiceButton;
public Transform choicePanel;
public void StartDialogue(DialogueScript scriptToShow)
{
uiCanvas.SetActive(true);
textProgress = 0;
currentDialogueScript = scriptToShow;
scriptLines = currentDialogueScript.script.text.Split("\n");
player.abilitiesDisabled = true;
player.stalled = true;
UpdateDialogue();
}
private void ContinueDialogue()
{
textProgress++;
clickingDisabled = false;
UpdateDialogue();
}
@ -70,7 +82,73 @@ public class DialogueManager : MonoBehaviour
}
}
break;
case "TASK": //must use 3 words on these.
string taskModifier = words[1].ToUpper();
if (taskModifier == "ADD")
{
foreach (Task task in TaskManager.instance.taskList)
{
if (string.Equals(task.taskID, words[2], StringComparison.CurrentCultureIgnoreCase))
{
TaskManager.instance.AddTask(task);
break;
}
}
}
ContinueDialogue();
break;
case "ITEM":
string itemModifier = words[1].ToUpper();
if (itemModifier == "ADD")
{
foreach (Item item in InventoryManager.instance.itemList)
{
if (string.Equals(item.itemName, words[2], StringComparison.CurrentCultureIgnoreCase))
{
InventoryManager.instance.AddItem(item, Int32.Parse(words[3]));
break;
}
}
}
ContinueDialogue();
break;
case "#":
ContinueDialogue();
break;
case "CHOICE":
clickingDisabled = true;
List<Choice> choices = new();
for (int i = 1; i < words.Length; i++)
{
Choice newChoice = new Choice();
string[] c = words[i].Split(":");
newChoice.choiceName = c[0];
foreach (DialogueScript dialogueScript in allDialogue)
{
if (string.Equals(c[1], dialogueScript.dialogueID, StringComparison.CurrentCultureIgnoreCase))
{
newChoice.choiceScript = dialogueScript; //this is the worst way ever to find a matching id but WHATEVER
break;
}
}
if (!newChoice.choiceScript)
{
Debug.LogWarning("BRO WTF THERE IS NO MATCHING ID!!!");
}
else
{
choices.Add(newChoice);
}
}
foreach (Choice possibleChoice in choices)
{
Button newChoiceButton = Instantiate(choiceButton, choicePanel);
newChoiceButton.onClick.AddListener(() => StartDialogue(possibleChoice.choiceScript));
newChoiceButton.GetComponentInChildren<TextMeshProUGUI>().text = possibleChoice.choiceName;
}
break;
}
}
@ -80,6 +158,8 @@ public class DialogueManager : MonoBehaviour
uiCanvas.SetActive(false);
currentDialogueScript = null;
scriptLines = null;
player.abilitiesDisabled = false;
player.stalled = false;
}
private void Update()
{

View file

@ -4,6 +4,7 @@ using UnityEngine;
[CreateAssetMenu(fileName = "New Dialogue Script", menuName = "Dialogue/Script")]
public class DialogueScript : ScriptableObject
{
public string dialogueID;
public List<DialogueCharacter> characters;
public TextAsset script;
public Task taskToStart;

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c6dd5cc4a0f89b83f84fe63d4ac77341
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,46 @@
using System;
using Core.Extensions;
using UnityEngine;
public class Ability : MonoBehaviour
{
[Header("Flags")]
public bool cooldownBlocked;
public bool blocked;
[Header("Cooldown")]
public float cooldown;
protected float currentCooldown;
[Header("Stats")]
public float power;
public bool TryAbility()
{
if (!blocked && currentCooldown <= 0)
{
currentCooldown = cooldown;
AbilityEffects();
return true;
}
return false;
}
protected virtual void AbilityEffects()
{
}
private void Update()
{
if (currentCooldown > 0 && !cooldownBlocked)
{
currentCooldown -= Time.deltaTime;
}
}
protected void ShootBullet(Projectile projectile, Vector3 direction)
{
Projectile newProjectile = Instantiate(projectile, transform.position, Quaternion.identity);
newProjectile.transform.Lookat2D(direction);
newProjectile.tag = tag; //will have to figure out stats and projectile creation
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0057d0e1aa27e88a6922b74c1ef23cc8

View file

@ -0,0 +1,10 @@
using UnityEngine;
using UnityEngine.InputSystem.LowLevel;
public class PlayerAbility : Ability
{
[Header("Input")]
public KeyCode inputKey; //change to better input system later
public MouseButton mouseButton; //alternative input
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e1cd082fa4f5e51d6b807f4914aa021f

View file

@ -0,0 +1,12 @@
using UnityEngine;
public class ReisenShoot : PlayerAbility
{
[Header("Projectile")]
[SerializeField] private Projectile projectile;
protected override void AbilityEffects()
{
base.AbilityEffects();
ShootBullet(projectile, GameManager.instance.GetMouseWorldPos());
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d1ac34739e2f9c100901a9488a5d8218

View file

@ -6,6 +6,7 @@ public class CombatEntity : Entity
public float maxHealth;
public float health;
public bool invulnerable;
public bool isSafe;
public void TakeDamage(float damage)
{

View file

@ -2,4 +2,59 @@ using UnityEngine;
public class Enemy : CombatEntity
{
[Header("Targetting")]
public CombatEntity closestTarget; //actually get the detected target first
public bool detectedPlayer = false;
[Header("Direction")]
public Transform[] possibleDirections;
public float forwardPercent;
public float strafePercent;
public float directionVariance; //how much strafe/forward vary
protected float xSign = -1f;
protected float ySign = 1f;
private void Start()
{
if (Random.Range(0f, 2f) > 1f)
{
xSign = -xSign;
ySign = -ySign;
}
float newVariance = Random.Range(-directionVariance, directionVariance);
forwardPercent += newVariance;
strafePercent -= newVariance;
}
protected override void Movement()
{
if (stalled || !closestTarget || !detectedPlayer || closestTarget.isSafe)
{
moveDirection = Vector3.zero;
}
else
{
Vector2 directionToTarget = (closestTarget.transform.position - transform.position).normalized;
Vector2 directionToMove = directionToTarget;
float currentHighestScore = float.NegativeInfinity;
Vector2 strafeDirection = new Vector3(directionToTarget.y * ySign, directionToTarget.x * xSign);
foreach (Transform direction in possibleDirections)
{
Vector3 directionToPoint = (direction.position - transform.position).normalized;
float forwardScore = Vector3.Dot(directionToPoint, directionToTarget);
float strafeScore = Vector3.Dot(directionToPoint, strafeDirection);
float finalScore = (forwardScore * forwardPercent) + (strafeScore * strafePercent);
//Debug.Log($"Forward: {forwardScore} Strafe: {strafeScore} Final: {finalScore}");
if (finalScore > currentHighestScore)
{
//Debug.Log($"{finalScore} is higher than current score: {currentHighestScore}");
currentHighestScore = finalScore;
directionToMove = directionToPoint;
}
}
moveDirection = directionToMove;
//FlipSprite(directionToMove);
// ^ add when you actually draw sprites
}
}
}

View file

@ -0,0 +1,15 @@
using System;
using UnityEngine;
public class EnemyDetection : MonoBehaviour
{
public Enemy thisEnemy;
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag(thisEnemy.tag) && other.TryGetComponent(out Player isPlayer))
{
thisEnemy.detectedPlayer = true;
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 75cd0318c03eac209af986e5dffde52b

View file

@ -3,11 +3,27 @@ using UnityEngine;
public class Entity : MonoBehaviour
{
[Header("Sprite")]
public SpriteRenderer sprite;
[Header("Movement")]
public float speed;
[SerializeField] protected Rigidbody2D rb;
public Vector3 moveDirection;
public bool noMovement;
public bool stalled;
public bool isFacingRight;
protected void FlipSprite(Vector2 lookDirection)
{
if (lookDirection.x > 0f && isFacingRight)
{
sprite.flipX = true;
isFacingRight = !isFacingRight;
}
else if (lookDirection.x < 0f && !isFacingRight)
{
sprite.flipX = false;
isFacingRight = !isFacingRight;
}
}
protected virtual void Movement()
{
@ -15,10 +31,14 @@ public class Entity : MonoBehaviour
private void FixedUpdate()
{
if (!noMovement)
if (!stalled)
{
Movement();
rb.linearVelocity = moveDirection * speed;
}
else
{
rb.linearVelocity = Vector2.zero;
}
}
}

View file

@ -2,5 +2,10 @@ using UnityEngine;
public class NPC : Entity
{
[Header("Dialogue")]
public DialogueScript dialogueToShow; //supposed to be able to have different dialogue but we'll go with this for now
public void StartDialogue()
{
DialogueManager.instance.StartDialogue(dialogueToShow);
}
}

View file

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
public class Player : CombatEntity
{
@ -11,7 +13,10 @@ public class Player : CombatEntity
{
//moveAction = InputSystem.actions.FindAction("Move");
}*/
[Header("Abilities")]
public bool abilitiesDisabled;
public List<PlayerAbility> abilities = new();
protected override void Movement()
{
base.Movement();
@ -19,4 +24,20 @@ public class Player : CombatEntity
//moveDirection = moveAction.ReadValue<Vector2>();
moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
}
private void Update()
{
foreach (PlayerAbility ability in abilities)
{
if (Input.GetKeyDown(ability.inputKey))
{
ability.TryAbility();
}
else if (ability.inputKey == KeyCode.None && Input.GetMouseButtonDown((int)ability.mouseButton))
{
//really needs to be fixed to the new input system
ability.TryAbility();
}
}
}
}

View file

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public class PlayerTalkRange : MonoBehaviour
{
private List<NPC> npcsInRange = new(); //also indicate the npc you're closest to
[Header("UI")]
[SerializeField] private Transform talkPopupUI;
[SerializeField] private Vector3 uiOffset;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out NPC isNPC) && !npcsInRange.Contains(isNPC)) //placeholder key lol
{
npcsInRange.Add(isNPC);
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.TryGetComponent(out NPC isNPC) && npcsInRange.Contains(isNPC)) //placeholder key lol
{
npcsInRange.Remove(isNPC);
if (npcsInRange.Count == 0)
{
talkPopupUI.gameObject.SetActive(false);
}
}
}
private void Update()
{
if (npcsInRange.Count > 0)
{
NPC closestNPC = null;
foreach (NPC npc in npcsInRange)
{
if (!closestNPC || Vector3.Distance(closestNPC.transform.position, transform.position) >
Vector3.Distance(npc.transform.position, transform.position))
{
closestNPC = npc;
}
}
if (closestNPC)
{
if (!talkPopupUI.gameObject.activeSelf)
{
talkPopupUI.gameObject.SetActive(true);
}
talkPopupUI.position = closestNPC.transform.position + uiOffset;
}
if (DialogueManager.instance.currentDialogueScript == null && Input.GetKeyDown(KeyCode.E))
{
closestNPC.StartDialogue();
}
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a494e77da3dc9d4898d5429d915efbe4

View file

@ -0,0 +1,63 @@
using System;
using UnityEngine;
public class GameManager : MonoBehaviour
{
#region Statication
public static GameManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this);
instance = this;
}
#endregion
//this is just for general functions and variables that will be reused
public Camera camera;
public GameObject pauseMenu;
public Vector3 GetMouseWorldPos()
{
return camera.ScreenToWorldPoint(Input.mousePosition);
}
public void SetPause(bool state)
{
if (state)
{
Time.timeScale = 0f;
}
else
{
Time.timeScale = 1f;
}
}
public void SetPauseMenu()
{
if (!pauseMenu.activeSelf)
{
SetPause(true);
pauseMenu.SetActive(true);
}
else
{
pauseMenu.SetActive(false);
SetPause(false);
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
SetPauseMenu();
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 406f53e48d26986aa932abc4b34e5760

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public class GatheringSpot : MonoBehaviour
{
[Serializable]
public class ItemAmount
{
public Item item;
public int amount;
}
public List<ItemAmount> gatherableItems = new();
public bool hasGathered;
public void Gather()
{
foreach (ItemAmount item in gatherableItems)
{
InventoryManager.instance.AddItem(item.item, item.amount);
//needs check for if inventory cannot fit
}
hasGathered = true;
gameObject.SetActive(false);
}
private void OnMouseDown()
{
//placeholder function to add items
Gather();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e3cff17c13b8ba2208e650f32f4cb1fc

View file

@ -0,0 +1,30 @@
using System.Collections.Generic;
using UnityEngine;
public class CraftingSystem : MonoBehaviour
{
public bool TryCraftingItem(Item requestedItem)
{
List<InventoryManager.ItemAmount> missingItems = new();
foreach (InventoryManager.ItemAmount requiredMaterial in requestedItem.requiredMaterials)
{
if (InventoryManager.instance.CheckItemAmount(requiredMaterial.item) < requiredMaterial.amount)
{
InventoryManager.ItemAmount newMissingItem = new();
newMissingItem.item = requiredMaterial.item;
newMissingItem.amount = requiredMaterial.amount - InventoryManager.instance.CheckItemAmount(requiredMaterial.item);
}
}
if (missingItems.Count > 0)
{
return false; //supposed to return what items were missing
}
foreach (InventoryManager.ItemAmount requiredMaterial in requestedItem.requiredMaterials)
{
InventoryManager.instance.RemoveItem(requiredMaterial.item, requiredMaterial.amount);
}
InventoryManager.instance.AddItem(requestedItem, requestedItem.craftedAmount);
return true;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7d679797190d2f6689dcb050b4d2ace8

View file

@ -1,20 +1,56 @@
using System;
using System.Collections.Generic;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
public class InventoryManager : MonoBehaviour
{
#region Statication
public static InventoryManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this);
instance = this;
}
#endregion
[Serializable]
public class ItemAmount
{
public Item item;
public int amount;
}
public Item[] itemList; //list of all items in the game
public int maxCapacity;
public int currentlyStored;
public Dictionary<Item, int> storedItems = new();
public Item[] itemList;
public int money;
[Header("UI")]
public TextMeshProUGUI moneyUI;
public GameObject inventoryUI;
public InventoryUIObject templateUIObject;
public Transform inventoryGrid;
public Dictionary<Item, InventoryUIObject> allInventoryUIObjects = new();
private void Start()
{
UpdateMoneyUI();
}
public bool RemoveMoney(int change)
{
if (money - change >= 0)
{
money -= change;
UpdateMoneyUI();
return true;
}
return false;
@ -22,6 +58,12 @@ public class InventoryManager : MonoBehaviour
public void AddMoney(int change)
{
money += change;
UpdateMoneyUI();
}
public void UpdateMoneyUI()
{
moneyUI.text = $"Money: {money}";
}
public int AddItem(Item itemToAdd, int amount = 1)
@ -36,6 +78,8 @@ public class InventoryManager : MonoBehaviour
{
storedItems[itemToAdd] += amount;
currentlyStored += amount;
UpdateTaskTracker();
Debug.Log($"ADDED ALL {itemToAdd.itemName}");
return 0;
}
//return the amount that wasn't able to be stored.
@ -43,11 +87,21 @@ public class InventoryManager : MonoBehaviour
storedItems[itemToAdd] += stored;
currentlyStored += stored;
amount -= stored;
UpdateTaskTracker();
Debug.Log($"ADDED {stored} OF {itemToAdd.itemName} AND DROPPED {amount}");
return amount;
}
Debug.Log($"COULD NOT ADD {itemToAdd.itemName}; INVENTORY FULL");
return -1;
}
public void UpdateTaskTracker()
{
if (TaskManager.instance.activeTasks.Count > 0)
{
TaskManager.instance.CheckInventory();
}
}
public bool RemoveItem(Item itemToRemove, int amount = 1)
{
if (!storedItems.ContainsKey(itemToRemove) || storedItems[itemToRemove] < amount)
@ -57,4 +111,34 @@ public class InventoryManager : MonoBehaviour
storedItems[itemToRemove] -= amount;
return true;
}
public int CheckItemAmount(Item itemToCheck)
{
return storedItems[itemToCheck];
}
public void UpdateInventoryUI()
{
foreach (var item in storedItems)
{
if (allInventoryUIObjects.ContainsKey(item.Key))
{
if (item.Value == 0)
{
Destroy(allInventoryUIObjects[item.Key]);
allInventoryUIObjects.Remove(item.Key);
}
else
{
allInventoryUIObjects[item.Key].SetObject(item.Key);
}
}
else
{
InventoryUIObject newUIObject = Instantiate(templateUIObject, inventoryGrid);
newUIObject.gameObject.SetActive(true);
newUIObject.SetObject(item.Key);
allInventoryUIObjects[item.Key] = newUIObject;
}
}
}
}

View file

@ -0,0 +1,18 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class InventoryUIObject : MonoBehaviour
{
public TextMeshProUGUI itemNameText;
public TextMeshProUGUI amountText;
public Image itemIcon;
public void SetObject(Item itemToSet)
{
Debug.Log("here");
itemNameText.text = itemToSet.itemName; //it would be reset every time you open the inventory instead of updating only the amount but whatever it doesn't matter
amountText.text = $"x{InventoryManager.instance.CheckItemAmount(itemToSet)}";
itemIcon.sprite = itemToSet.icon;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6f2a88e73d2507a229d0c3d869826b39

View file

@ -1,8 +1,14 @@
using UnityEngine;
public class Item : MonoBehaviour
[CreateAssetMenu(fileName = "New Item", menuName = "Item")]
public class Item : ScriptableObject
{
[Header("Identification")]
public string itemName;
public string description;
public Sprite icon;
[Header("Crafting")]
public InventoryManager.ItemAmount[] requiredMaterials;
public int craftedAmount = 1; //amount of items received after being crafted
public int value; //items will be sold at a percentage of value?
}

View file

@ -0,0 +1,37 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelSwitcher : MonoBehaviour
{
#region Statication
public static LevelSwitcher instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this);
instance = this;
}
#endregion
[SerializeField] private int mapSceneIndex;
public void LoadMap(Map requestedMap, int exitIndex)
{
SceneManager.LoadScene(mapSceneIndex);
Map newMap = Instantiate(requestedMap);
newMap.Load();
//load player and set to exit position
}
public void SwitchMenu(int sceneIndex)
{
SceneManager.LoadScene(sceneIndex);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a5b5ba3ea60e917b5bb351a8dff7e24c

View file

@ -0,0 +1,24 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenuHandler : MonoBehaviour
{
public void ContinueSave()
{
}
public void NewSave()
{
SceneManager.LoadScene(1);
}
public void QuitGame()
{
Application.Quit();
}
public void ShowUI(GameObject openedUI, GameObject closedUI)
{
openedUI.gameObject.SetActive(true);
closedUI.gameObject.SetActive(false);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0ca32d5e19d4ccf01a6fcccb9ce39d28

16
Assets/Scripts/Map.cs Normal file
View file

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public class Map : MonoBehaviour
{
public List<NPC> npcs = new();
public GameObject mapObject;
public List<Enemy> enemies = new();
public List<GatheringSpot> gatheringSpots = new();
public List<Transform> exits;
public void Load()
{
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: cbc224f69699e27089513ee95064432e

View file

@ -0,0 +1,19 @@
using System;
using UnityEngine;
public class MapEntrance : MonoBehaviour
{
public Map mapToEnter;
public int exitIndex;
public void EnterMap()
{
LevelSwitcher.instance.LoadMap(mapToEnter, exitIndex);
}
private void OnTriggerEnter2D(Collider2D other)
{
//fade to black
EnterMap();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 758f961c2aa802a9fa448bbd19212c16

View file

@ -0,0 +1,32 @@
using UnityEngine;
public class MapManager : MonoBehaviour
{
#region Statication
public static MapManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this);
instance = this;
}
#endregion
public Player player;
public void TravelToLocation(Map mapToLoad)
{
//needs to fade to black beforehand and afterhand in reverse
mapToLoad.Load();
//add location parameter.
//needs a check for where the player entered from so the game knows where to spawn the player
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 42289cf891926f076bebc4464453ec50

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e3f63997870d80b05a765a7bfd83f03e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,40 @@
using System;
using UnityEngine;
public class Projectile : MonoBehaviour
{
[Header("Base Stats")]
public float lifetime;
public float damage;
[Header("Piercing")]
public int pierceAmount;
public int currentPierce;
[Header("Movement")]
[SerializeField] private Rigidbody2D rb;
public float speed;
private void Start()
{
Destroy(gameObject, lifetime);
}
private void FixedUpdate()
{
rb.linearVelocity = transform.right * speed;
}
protected void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag(tag) && other.TryGetComponent(out CombatEntity isEntity))
{
currentPierce++;
isEntity.TakeDamage(damage);
if (currentPierce > pierceAmount) //if 0 then no one pierced. if 1 then can pierce 1 enemy and gets destroyed by second enemy, and so on...
{
Destroy(gameObject);
}
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1d5cb9c244e3fb41ca6b3cbdc762432a

View file

@ -5,16 +5,21 @@ using UnityEngine;
[CreateAssetMenu(fileName = "New Task", menuName = "Task")]
public class Task : ScriptableObject
{
[Serializable]
public class ItemRequirment
{
public Item item;
public int amount;
}
[Header("Identification")]
public string taskName;
public string taskID;
public string description;
[Header("Requirements")]
public int deadline; //in days from started
public bool completed;
public ItemRequirment[] requirements;
public Dictionary<Item, int> itemProgress = new();
public InventoryManager.ItemAmount[] itemRequirements;
public Enemy[] enemyRequirements;
[Header("Rewards")]
public InventoryManager.ItemAmount[] itemRewards;
public int moneyReward;
public void FailTask()
{
}
}

View file

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class TaskManager : MonoBehaviour
@ -18,9 +20,18 @@ public class TaskManager : MonoBehaviour
}
#endregion
public List<Task> activeTasks = new();
public Task[] taskList; //list of all tasks in the game
public List<Task> activeTasks = new(); //it doesn't need to be serialized wtf are you talking about
public int maxTasksActive;
public Task startingTask;
[Header("UI")]
[SerializeField] private TaskUIObject templateTaskUI;
public Transform taskGrid;
public TextMeshProUGUI taskNameUI;
public TextMeshProUGUI taskDescriptionUI;
public Dictionary<Task, TaskUIObject> allTaskUIObjects = new();
public bool AddTask(Task taskToAdd)
{
if (activeTasks.Count >= maxTasksActive)
@ -28,6 +39,56 @@ public class TaskManager : MonoBehaviour
return false;
}
activeTasks.Add(taskToAdd);
AddTaskUIObject(taskToAdd);
return true;
}
private void Start()
{
//AddTask(startingTask);
}
public void CompleteTask(Task taskToComplete)
{
//remove items from inventory aswell. also need to
//activeTasks.Remove(taskToComplete);
Debug.Log($"{taskToComplete.taskName} COMPLETED");
foreach (InventoryManager.ItemAmount itemReward in taskToComplete.itemRewards)
{
InventoryManager.instance.AddItem(itemReward.item, itemReward.amount);
}
InventoryManager.instance.AddMoney(taskToComplete.moneyReward);
}
public void CheckInventory()
{
foreach (Task task in activeTasks)
{
bool skip = false;
foreach (InventoryManager.ItemAmount itemRequirment in task.itemRequirements)
{
if (InventoryManager.instance.storedItems[itemRequirment.item] < itemRequirment.amount) //doesn't track enemies killed yet but i haven't added combat yet
{
skip = true;
break;
}
}
if (!skip)
{
CompleteTask(task);
}
}
}
public void AddTaskUIObject(Task requestedTask)
{
TaskUIObject newTaskUIObject = Instantiate(templateTaskUI, taskGrid);
allTaskUIObjects[requestedTask] = newTaskUIObject;
newTaskUIObject.SetTask(requestedTask);
}
public void SetTaskUI(Task requestedTask)
{
taskNameUI.text = requestedTask.taskName;
taskDescriptionUI.text = requestedTask.description;
}
}

View file

@ -0,0 +1,17 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class TaskUIObject : MonoBehaviour
{
public Task taskToShow;
public TextMeshProUGUI taskTitle;
public Button thisButton;
public void SetTask(Task requestedTask)
{
taskToShow = requestedTask;
taskTitle.text = requestedTask.taskName;
thisButton.onClick.RemoveAllListeners();
thisButton.onClick.AddListener(() => TaskManager.instance.SetTaskUI(taskToShow)); //unsure if it should be on here or the new task ui function
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 853eb37676d17e28f8b73e4434f633e7

View file

@ -0,0 +1,56 @@
using System;
using TMPro;
using UnityEngine;
public class TimeManager : MonoBehaviour
{
#region Statication
public static TimeManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this);
instance = this;
}
#endregion
public Player player;
[Header("Time")]
public int currentDay;
public int currentTime; //measured in minutes
[Header("UI")]
public TextMeshProUGUI timeUI; //i might have to move the main ui off to a different scene?
private void Start()
{
UpdateTimeUI();
}
public void PassTime(int minutes)
{
currentTime += minutes;
UpdateTimeUI();
}
public void EndDay()
{
//full heal player
//reset gathering spots
currentDay++;
currentTime = 360;
UpdateTimeUI();
}
private void UpdateTimeUI()
{
string convertedTime = $"{TimeSpan.FromMinutes(currentTime):hh\\:mm}";
timeUI.text = $"Time: {convertedTime}";
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 85711fc00a7dda7aa82f04deb338e560

View file

@ -0,0 +1,29 @@
using UnityEngine;
public class UIHandler : MonoBehaviour
{
public GameObject mainHUD;
public void OpenUI(UIObject targetUI)
{
if (targetUI.willCloseMainUI && mainHUD.activeSelf)
{
mainHUD.SetActive(false);
}
targetUI.gameObject.SetActive(true);
}
public void CloseUI(UIObject targetUI)
{
if (!mainHUD.activeSelf)
{
mainHUD.SetActive(true);
}
targetUI.gameObject.SetActive(false);
}
public void ExitGame()
{
//LevelSwitcher.instance.SwitchMenu(0); //replace with main menu
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e078166b1e73bcc818073475826af5ca

View file

@ -0,0 +1,6 @@
using UnityEngine;
public class UIObject : MonoBehaviour
{
public bool willCloseMainUI;
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8b771646c61a1b3628d93ebf530f0f2e

View file

@ -0,0 +1,21 @@
using System;
using UnityEngine;
public class ZonePlayerFlagCollision : MonoBehaviour
{
public bool safeZone;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out Player isPlayer))
{
if (safeZone)
{
isPlayer.isSafe = true;
}
else
{
isPlayer.isSafe = false;
}
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d0c983f26b2c0e64e86e3440c18ee86e