82 lines
2.1 KiB
C#
82 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class QuestAction : MonoBehaviour
|
|
{
|
|
public QuestScriptable questData;
|
|
bool isRegistered = false;
|
|
|
|
public UnityEvent OnComplete;
|
|
public bool isFinalAction = true;
|
|
|
|
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()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (playerNetwork.localPlayerTransform != null && !isRegistered)
|
|
{
|
|
Register();
|
|
}
|
|
}
|
|
|
|
void Register()
|
|
{
|
|
playerNetwork.registerQuestAction(this);
|
|
isRegistered = true;
|
|
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
[Serializable ]
|
|
public class QuestCompleteResourceCheckEntry
|
|
{
|
|
public string resourceName;
|
|
public int amount;
|
|
} |