quests fix resources
This commit is contained in:
parent
825f15670f
commit
edf82b4337
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -56,5 +56,5 @@
|
|||
"temp/": true,
|
||||
"Temp/": true
|
||||
},
|
||||
"dotnet.defaultSolution": "Archive.sln"
|
||||
"dotnet.defaultSolution": "2DMMOMirror.sln"
|
||||
}
|
||||
BIN
Assets/.DS_Store
vendored
BIN
Assets/.DS_Store
vendored
Binary file not shown.
126
Assets/LostNpc.cs
Normal file
126
Assets/LostNpc.cs
Normal 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
11
Assets/LostNpc.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e5c148fc2124c4630b218cf006e5727b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/ResourceQuestScript.cs
Normal file
8
Assets/ResourceQuestScript.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ResourceQuestScript : MonoBehaviour
|
||||
{
|
||||
}
|
||||
|
||||
11
Assets/ResourceQuestScript.cs.meta
Normal file
11
Assets/ResourceQuestScript.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e5371c32ad1cb46f19c3b260eb5e1237
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Resources/.DS_Store
vendored
BIN
Assets/Resources/.DS_Store
vendored
Binary file not shown.
|
|
@ -14,9 +14,8 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
questName: CookQuest
|
||||
questLines:
|
||||
- 'Hello There, I need your help '
|
||||
- I'm in need to find a cactus that only grows in desered areas
|
||||
- head west to the desert , and bring me the cactus
|
||||
- i will reward you 500 coins
|
||||
- I need Cactus plant
|
||||
- only grows in desert area
|
||||
- head west to the desert and bring me the cactus
|
||||
questTitle: Head West to desert and find the Cactus and bring it back to Cook
|
||||
rewardAmount: 500
|
||||
|
|
|
|||
|
|
@ -10,13 +10,10 @@ MonoBehaviour:
|
|||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: bb4f7aac1a911412f89952ac827aabad, type: 3}
|
||||
m_Name: Quest_4
|
||||
m_Name: LostNpc
|
||||
m_EditorClassIdentifier:
|
||||
questName: Quest_4
|
||||
questName: LostNpc
|
||||
questLines:
|
||||
- Quest 4
|
||||
- Quest 4Quest 4
|
||||
- Quest 4Quest 4Quest 4
|
||||
- Quest 4Quest 4Quest 4Quest 4
|
||||
questTitle: Quest 4
|
||||
rewardAmount: 500
|
||||
- LostNpc
|
||||
questTitle: LostNpc
|
||||
rewardAmount: 1000
|
||||
|
|
@ -12,11 +12,8 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: bb4f7aac1a911412f89952ac827aabad, type: 3}
|
||||
m_Name: Quest_3
|
||||
m_EditorClassIdentifier:
|
||||
questName: Quest_3
|
||||
questName: bye
|
||||
questLines:
|
||||
- Quest 3
|
||||
- Quest 3Quest 3
|
||||
- Quest 3Quest 3Quest 3
|
||||
- Quest 3Quest 3Quest 3Quest 3
|
||||
questTitle: Quest 3Quest 3Quest 3Quest 3Quest 3Quest 3
|
||||
rewardAmount: 500
|
||||
- come again later
|
||||
questTitle: quest
|
||||
rewardAmount: 100
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
|
@ -11,33 +12,71 @@ public class QuestAction : MonoBehaviour
|
|||
public UnityEvent OnComplete;
|
||||
public bool isFinalAction = true;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
if(other.CompareTag("Player") && other.transform == playerNetwork.localPlayerTransform){
|
||||
public List<QuestCompleteResourceCheckEntry> resourceCheckEntries;
|
||||
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player") && other.transform == playerNetwork.localPlayerTransform)
|
||||
{
|
||||
|
||||
|
||||
OnComplete.Invoke();
|
||||
if(isFinalAction){
|
||||
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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
21
Assets/autoDisableGameObj.cs
Normal file
21
Assets/autoDisableGameObj.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/autoDisableGameObj.cs.meta
Normal file
11
Assets/autoDisableGameObj.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: addf4c0af1b1f4baaac37d1dff0f423a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -8,11 +8,11 @@
|
|||
"hash": "f8c8347af3a144069dffd6120f1c4142f8120891"
|
||||
},
|
||||
"com.unity.2d.animation": {
|
||||
"version": "9.0.3",
|
||||
"version": "9.1.3",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.2d.common": "8.0.1",
|
||||
"com.unity.2d.common": "8.0.4",
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.collections": "1.1.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.2d.aseprite": {
|
||||
"version": "1.0.1",
|
||||
"version": "1.1.6",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.2d.common": {
|
||||
"version": "8.0.1",
|
||||
"version": "8.0.4",
|
||||
"depth": 2,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
|
@ -53,13 +53,13 @@
|
|||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.2d.psdimporter": {
|
||||
"version": "8.0.2",
|
||||
"version": "8.0.5",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"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.animation": "9.0.1"
|
||||
"com.unity.2d.animation": "9.1.1"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
|
|
@ -70,11 +70,11 @@
|
|||
"dependencies": {}
|
||||
},
|
||||
"com.unity.2d.spriteshape": {
|
||||
"version": "9.0.2",
|
||||
"version": "9.0.5",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.2d.common": "8.0.1",
|
||||
"com.unity.2d.common": "8.0.4",
|
||||
"com.unity.mathematics": "1.1.0",
|
||||
"com.unity.modules.physics2d": "1.0.0"
|
||||
},
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
}
|
||||
},
|
||||
"com.unity.2d.tilemap.extras": {
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.3",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
|
@ -102,11 +102,12 @@
|
|||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.burst": {
|
||||
"version": "1.8.8",
|
||||
"version": "1.8.18",
|
||||
"depth": 3,
|
||||
"source": "registry",
|
||||
"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"
|
||||
},
|
||||
|
|
@ -139,14 +140,14 @@
|
|||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"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.psdimporter": "8.0.2",
|
||||
"com.unity.2d.psdimporter": "8.0.5",
|
||||
"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.extras": "3.1.1",
|
||||
"com.unity.2d.aseprite": "1.0.1"
|
||||
"com.unity.2d.tilemap.extras": "3.1.3",
|
||||
"com.unity.2d.aseprite": "1.1.6"
|
||||
}
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user