quests fixed

This commit is contained in:
2024-12-22 08:29:50 +05:30
parent d46e3350f7
commit 54f60c067e
10 changed files with 199 additions and 136 deletions

View File

@@ -11,9 +11,9 @@ public class npcScript : MonoBehaviour
public GameObject textBtn;
public TMP_Text npcText;
// public string[] texts;
public QuestScriptable [] questData;
public int activeQuest;
private int index;
public QuestScriptable[] questData;
public int activeQuest=0;
public int questLineIndex;
//public GameObject questUI;
@@ -22,99 +22,132 @@ public class npcScript : MonoBehaviour
void Update()
{
if(isPlayerClose){
// if(npcPanel.activeInHierarchy){
// ResetTexts();
// }else{
// npcPanel.SetActive(true);
// StartCoroutine(textLoad());
// }
if (isPlayerClose)
{
}
if(npcText.text == questData[activeQuest].questLines[index]){
if (npcText.text == questData[activeQuest].questLines[questLineIndex])
{
textBtn.SetActive(true);
}
}
public void ResetTexts(){
npcPanel.SetActive(false);
npcText.text = "";
index = 0;
}
bool isLooping = false;
IEnumerator textLoad(){
isLooping = true;
foreach(char letter in questData[activeQuest].questLines[index].ToCharArray()){
bool isLoadingText = false;
IEnumerator textLoad()
{
isLoadingText = true;
foreach (char letter in questData[activeQuest].questLines[questLineIndex].ToCharArray())
{
npcText.text += letter;
yield return new WaitForSecondsRealtime(textspeed);
}
isLooping=false;
isLoadingText = false;
}
Coroutine textLoopAsync ;
public void NextLine(){
Coroutine textLoopAsync;
public void NextLine()
{
textBtn.SetActive(false);
if(index < questData[activeQuest].questLines.Length -1 ){
index++;
if (questLineIndex < questData[activeQuest].questLines.Length - 1)
{
questLineIndex++;
npcText.text = "";
LoadText();
}else{
}
else
{
ResetTexts();
//Start quest
// questUI.SetActive(true);
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().QuestFunction(questData[activeQuest]);
playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().SetActiveQuest(questData[activeQuest]);
}
}
private void OnTriggerEnter2D(Collider2D other) {
if(other.CompareTag("Player")){
if(other.transform == playerNetwork.localPlayerTransform){
if(playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().currentQuest == questData[activeQuest]){
void ResetTexts(){
npcText.text = "";
npcPanel.SetActive(false);
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
if (other.transform == playerNetwork.localPlayerTransform)
{
playerNetwork pnet = playerNetwork.localPlayerTransform.GetComponent<playerNetwork>();
if (pnet.currentQuest == questData[activeQuest]) //Already doing this quest
{
return;
}
for(int i =0; i < questData.Length; i++){
bool isFound = false;
foreach(string questName in playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().completedQuests){
if(questName == questData[i].name){
isFound = true;
}
// for (int i = 0; i < questData.Length; i++)
// {
// bool isFound = false;
// foreach (string questName in playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().completedQuests)
// {
// if (questName == questData[i].name)
// {
// isFound = true;
// }
// }
// if (!isFound)
// {
// activeQuest = i;
// break;
// }
// }
if(pnet.completedQuests.Contains(questData[activeQuest].questName)){ //Set next quest if current one is completed
for(int i=0; i < questData.Length; i++){
if(pnet.completedQuests.Contains(questData[i].questName)){
continue;
}
}
if(!isFound){
activeQuest = i;
break;
}
}
isPlayerClose = true;
if(npcPanel.activeInHierarchy){
ResetTexts();
}else{
npcPanel.SetActive(true);
LoadText();
}
isPlayerClose = true;
if (npcPanel.activeInHierarchy)
{
ResetTexts();
}
else
{
questLineIndex=0;
npcPanel.SetActive(true);
LoadText();
}
}
}
}
}
void LoadText(){
void LoadText()
{
npcText.text = "";
if(textLoopAsync!=null){
if (textLoopAsync != null)
{
StopCoroutine(textLoopAsync);
}
textLoopAsync = StartCoroutine(textLoad());
}
private void OnTriggerExit2D(Collider2D other) {
if(other.CompareTag("Player")){
if(other.transform == playerNetwork.localPlayerTransform){
isPlayerClose = false;
ResetTexts();
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
if (other.transform == playerNetwork.localPlayerTransform)
{
isPlayerClose = false;
ResetTexts();
}
}
}

View File

@@ -158,7 +158,7 @@ public class playerNetwork : NetworkBehaviour
public string selectedCharacterJson = CharacterSelection.selectedCharJson;
public void QuestFunction(QuestScriptable questData){
public void SetActiveQuest(QuestScriptable questData){
currentQuest = questData;
questText.text = questData.questTitle;
questUI.SetActive(true);
@@ -175,7 +175,7 @@ public class playerNetwork : NetworkBehaviour
Debug.LogError("Completed a quest that wasnt active");
return;
}
completedQuests.Add(currentQuest.name);
completedQuests.Add(currentQuest.questName);
currentQuest = null;
questText.text = "Quest Completed! Found 1000 coins from Cave-Chest";