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

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -56,5 +56,5 @@
"temp/": true, "temp/": true,
"Temp/": true "Temp/": true
}, },
"dotnet.defaultSolution": "Archive.sln" "dotnet.defaultSolution": "2DMMOMirror.sln"
} }

BIN
Assets/.DS_Store vendored

Binary file not shown.

126
Assets/LostNpc.cs Normal file
View File

@ -0,0 +1,126 @@
using System.Collections;
using System.Collections.Generic;
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
using Assets.HeroEditor4D.Common.Scripts.Enums;
using UnityEngine;
public class LostNpc : MonoBehaviour
{
//check if the quest is active on local player
public Character4D character;
[SerializeField] private bool _isQuestActive;
public QuestScriptable[] questData;
private playerNetwork player;
[SerializeField] private float followSpeed = 2f;
[SerializeField] private float stopDistance = 1f;
[SerializeField] private float maxDistance = 15f;
public bool _isFollowing;
void Update()
{
if (_isQuestActive)
{
FollowPlayer();
}
// if (player != null)
// {
// isPlayerInRange = Vector3.Distance(transform.position, player.transform.position) < followRadius;
// }
// else
// {
// isPlayerInRange = false;
// }
// if (player != null)
// {
// FollowPlayer();
// }
}
// check if the activequest is for finding the lost npc
// if the player is close to the npc - the npc will start following the player
// once the player go back to quest npc - the quest will be completed and npc will stop follow / destroy after few minutes
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
if (other.transform == playerNetwork.localPlayerTransform)
{
player = playerNetwork.localPlayerTransform.GetComponent<playerNetwork>();
//check if the quest match for finding lost npc
if (player.currentQuest == questData[0])
{
_isQuestActive = true;
_isFollowing = true;
npcFinalCollider.isTrigger = true;
}
}
}
}
float endTimer = 5f;
public void FollowPlayer()
{
float distance = Vector2.Distance(transform.position, player.transform.position);
if (distance <= stopDistance || distance >= maxDistance)
{
character.AnimationManager.SetState(CharacterState.Idle);
_isFollowing = false; // Stop following
return;
}
if(player.currentQuest==null){
if(endTimer > 0 ){
endTimer -= Time.deltaTime;
}else{
Destroy(gameObject);
}
character.AnimationManager.SetState(CharacterState.Idle);
_isFollowing = false;
return;
}
// Move
Vector2 direction = (player.transform.position - transform.position).normalized;
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, followSpeed * Time.deltaTime);
//
if (direction.x > 0) character.SetDirection(Vector2.right);
else if (direction.x < 0) character.SetDirection(Vector2.left);
else if (direction.y > 0) character.SetDirection(Vector2.up);
else if (direction.y < 0) character.SetDirection(Vector2.down);
//
character.AnimationManager.SetState(CharacterState.Walk);
}
public void StopFollowing()
{
_isFollowing = false;
character.AnimationManager.SetState(CharacterState.Idle);
}
public BoxCollider2D npcFinalCollider;
public void SetFinalQuestAction()
{
//enable npc is trigger
npcFinalCollider.isTrigger = true;
//StopFollowing();
//destroy npc after few minutes
}
}

11
Assets/LostNpc.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5c148fc2124c4630b218cf006e5727b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResourceQuestScript : MonoBehaviour
{
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5371c32ad1cb46f19c3b260eb5e1237
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -14,9 +14,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
questName: CookQuest questName: CookQuest
questLines: questLines:
- 'Hello There, I need your help ' - I need Cactus plant
- I'm in need to find a cactus that only grows in desered areas - only grows in desert area
- head west to the desert , and bring me the cactus - head west to the desert and bring me the cactus
- i will reward you 500 coins
questTitle: Head West to desert and find the Cactus and bring it back to Cook questTitle: Head West to desert and find the Cactus and bring it back to Cook
rewardAmount: 500 rewardAmount: 500

View File

@ -10,13 +10,10 @@ MonoBehaviour:
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bb4f7aac1a911412f89952ac827aabad, type: 3} m_Script: {fileID: 11500000, guid: bb4f7aac1a911412f89952ac827aabad, type: 3}
m_Name: Quest_4 m_Name: LostNpc
m_EditorClassIdentifier: m_EditorClassIdentifier:
questName: Quest_4 questName: LostNpc
questLines: questLines:
- Quest 4 - LostNpc
- Quest 4Quest 4 questTitle: LostNpc
- Quest 4Quest 4Quest 4 rewardAmount: 1000
- Quest 4Quest 4Quest 4Quest 4
questTitle: Quest 4
rewardAmount: 500

View File

@ -12,11 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: bb4f7aac1a911412f89952ac827aabad, type: 3} m_Script: {fileID: 11500000, guid: bb4f7aac1a911412f89952ac827aabad, type: 3}
m_Name: Quest_3 m_Name: Quest_3
m_EditorClassIdentifier: m_EditorClassIdentifier:
questName: Quest_3 questName: bye
questLines: questLines:
- Quest 3 - come again later
- Quest 3Quest 3 questTitle: quest
- Quest 3Quest 3Quest 3 rewardAmount: 100
- Quest 3Quest 3Quest 3Quest 3
questTitle: Quest 3Quest 3Quest 3Quest 3Quest 3Quest 3
rewardAmount: 500

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -6,38 +7,76 @@ using UnityEngine.Events;
public class QuestAction : MonoBehaviour public class QuestAction : MonoBehaviour
{ {
public QuestScriptable questData; public QuestScriptable questData;
bool isRegistered =false; bool isRegistered = false;
public UnityEvent OnComplete; public UnityEvent OnComplete;
public bool isFinalAction = true; public bool isFinalAction = true;
private void OnTriggerEnter2D(Collider2D other) { public List<QuestCompleteResourceCheckEntry> resourceCheckEntries;
if(other.CompareTag("Player") && other.transform == playerNetwork.localPlayerTransform){
OnComplete.Invoke();
if(isFinalAction){ 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); playerNetwork.localPlayerTransform.GetComponent<playerNetwork>().CompleteQuest(questData);
} }
gameObject.SetActive(false); gameObject.SetActive(false);
} }
} }
public void activate(){ public void activate()
{
gameObject.SetActive(true); gameObject.SetActive(true);
} }
void Update() void Update()
{ {
if(playerNetwork.localPlayerTransform != null && !isRegistered){ if (playerNetwork.localPlayerTransform != null && !isRegistered)
{
Register(); Register();
} }
} }
void Register(){ void Register()
{
playerNetwork.registerQuestAction(this); playerNetwork.registerQuestAction(this);
isRegistered = true; isRegistered = true;
gameObject.SetActive(false); 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 GameObject questUI;
public float textspeed = 0.10f; public float textspeed = 0.15f;
public bool isPlayerClose; public bool isPlayerClose;
[SerializeField] private BoxCollider2D rtrnActionCollider;
void Update() void Update()
{ {
@ -64,7 +65,8 @@ public class npcScript : MonoBehaviour
//Start quest //Start quest
// questUI.SetActive(true); // 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); completedQuests.Add(currentQuest.questName);
currentQuest = null; currentQuest = null;
questText.text = "Quest Completed! Found 1000 coins from Cave-Chest"; questText.text = "Quest Completed!";
playerCoin += questData.rewardAmount; playerCoin += questData.rewardAmount;
coinText.text = playerCoin.ToString(); coinText.text = playerCoin.ToString();
//add delay //add delay

View File

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class autoDisableGameObj : MonoBehaviour
{
public float disableTime = 5f;
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
void OnEnable()
{
StartCoroutine(DisableIteself());
}
private IEnumerator DisableIteself()
{
yield return new WaitForSeconds(disableTime);
gameObject.SetActive(false);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: addf4c0af1b1f4baaac37d1dff0f423a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -8,11 +8,11 @@
"hash": "f8c8347af3a144069dffd6120f1c4142f8120891" "hash": "f8c8347af3a144069dffd6120f1c4142f8120891"
}, },
"com.unity.2d.animation": { "com.unity.2d.animation": {
"version": "9.0.3", "version": "9.1.3",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.2d.common": "8.0.1", "com.unity.2d.common": "8.0.4",
"com.unity.2d.sprite": "1.0.0", "com.unity.2d.sprite": "1.0.0",
"com.unity.collections": "1.1.0", "com.unity.collections": "1.1.0",
"com.unity.modules.animation": "1.0.0", "com.unity.modules.animation": "1.0.0",
@ -21,7 +21,7 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.2d.aseprite": { "com.unity.2d.aseprite": {
"version": "1.0.1", "version": "1.1.6",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
@ -33,7 +33,7 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.2d.common": { "com.unity.2d.common": {
"version": "8.0.1", "version": "8.0.4",
"depth": 2, "depth": 2,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
@ -53,13 +53,13 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.2d.psdimporter": { "com.unity.2d.psdimporter": {
"version": "8.0.2", "version": "8.0.5",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.2d.common": "8.0.1", "com.unity.2d.common": "8.0.2",
"com.unity.2d.sprite": "1.0.0", "com.unity.2d.sprite": "1.0.0",
"com.unity.2d.animation": "9.0.1" "com.unity.2d.animation": "9.1.1"
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
@ -70,11 +70,11 @@
"dependencies": {} "dependencies": {}
}, },
"com.unity.2d.spriteshape": { "com.unity.2d.spriteshape": {
"version": "9.0.2", "version": "9.0.5",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.2d.common": "8.0.1", "com.unity.2d.common": "8.0.4",
"com.unity.mathematics": "1.1.0", "com.unity.mathematics": "1.1.0",
"com.unity.modules.physics2d": "1.0.0" "com.unity.modules.physics2d": "1.0.0"
}, },
@ -90,7 +90,7 @@
} }
}, },
"com.unity.2d.tilemap.extras": { "com.unity.2d.tilemap.extras": {
"version": "3.1.1", "version": "3.1.3",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
@ -102,11 +102,12 @@
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.burst": { "com.unity.burst": {
"version": "1.8.8", "version": "1.8.18",
"depth": 3, "depth": 3,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.mathematics": "1.2.1" "com.unity.mathematics": "1.2.1",
"com.unity.modules.jsonserialize": "1.0.0"
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
@ -139,14 +140,14 @@
"depth": 0, "depth": 0,
"source": "builtin", "source": "builtin",
"dependencies": { "dependencies": {
"com.unity.2d.animation": "9.0.3", "com.unity.2d.animation": "9.1.3",
"com.unity.2d.pixel-perfect": "5.0.3", "com.unity.2d.pixel-perfect": "5.0.3",
"com.unity.2d.psdimporter": "8.0.2", "com.unity.2d.psdimporter": "8.0.5",
"com.unity.2d.sprite": "1.0.0", "com.unity.2d.sprite": "1.0.0",
"com.unity.2d.spriteshape": "9.0.2", "com.unity.2d.spriteshape": "9.0.5",
"com.unity.2d.tilemap": "1.0.0", "com.unity.2d.tilemap": "1.0.0",
"com.unity.2d.tilemap.extras": "3.1.1", "com.unity.2d.tilemap.extras": "3.1.3",
"com.unity.2d.aseprite": "1.0.1" "com.unity.2d.aseprite": "1.1.6"
} }
}, },
"com.unity.ide.rider": { "com.unity.ide.rider": {