quests fix resources

This commit is contained in:
Nim-XD
2024-12-30 15:56:25 +05:30
parent 825f15670f
commit edf82b4337
19 changed files with 1065 additions and 126 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -6,38 +7,76 @@ using UnityEngine.Events;
public class QuestAction : MonoBehaviour
{
public QuestScriptable questData;
bool isRegistered =false;
bool isRegistered = false;
public UnityEvent OnComplete;
public bool isFinalAction = true;
private void OnTriggerEnter2D(Collider2D other) {
if(other.CompareTag("Player") && other.transform == playerNetwork.localPlayerTransform){
OnComplete.Invoke();
if(isFinalAction){
public List<QuestCompleteResourceCheckEntry> resourceCheckEntries;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player") && other.transform == playerNetwork.localPlayerTransform)
{
OnComplete.Invoke();
Debug.Log("QuestAction: QuestAction completed");
if (isFinalAction)
{
foreach(QuestCompleteResourceCheckEntry entry in resourceCheckEntries)
{
if(playerNetwork.localPlayerTransform.GetComponent<Inventory>().GetStock(entry.resourceName) < entry.amount)
{
Debug.Log("QuestAction: Resource check failed");
return;
}else{
for(int i=0; i < entry.amount; i++)
{
playerNetwork.localPlayerTransform.GetComponent<Inventory>().RemoveItem(entry.resourceName);
}
}
}
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().CompleteQuest(questData);
}
}
gameObject.SetActive(false);
}
}
public void activate(){
public void activate()
{
gameObject.SetActive(true);
}
void Update()
{
if(playerNetwork.localPlayerTransform != null && !isRegistered){
if (playerNetwork.localPlayerTransform != null && !isRegistered)
{
Register();
}
}
void Register(){
void Register()
{
playerNetwork.registerQuestAction(this);
isRegistered = true;
gameObject.SetActive(false);
}
}
[Serializable ]
public class QuestCompleteResourceCheckEntry
{
public string resourceName;
public int amount;
}

View File

@@ -20,8 +20,9 @@ public class npcScript : MonoBehaviour
//public GameObject questUI;
public float textspeed = 0.10f;
public float textspeed = 0.15f;
public bool isPlayerClose;
[SerializeField] private BoxCollider2D rtrnActionCollider;
void Update()
{
@@ -64,7 +65,8 @@ public class npcScript : MonoBehaviour
//Start quest
// questUI.SetActive(true);
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().SetActiveQuest(questData[activeQuest]);
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().SetActiveQuest(questData[activeQuest]); // set the quest
rtrnActionCollider.isTrigger = false;
}
}

View File

@@ -178,7 +178,7 @@ public class playerNetwork : NetworkBehaviour
completedQuests.Add(currentQuest.questName);
currentQuest = null;
questText.text = "Quest Completed! Found 1000 coins from Cave-Chest";
questText.text = "Quest Completed!";
playerCoin += questData.rewardAmount;
coinText.text = playerCoin.ToString();
//add delay