im pretty sure the scripts are correct if someone could dumb it down how to make them complete like equiping a weapon ive re watched multiple time and followed but its not working on my end here the quest stuff just incase
public class QuestList : MonoBehaviour, ISaveable, IPredicateEvaluator
{
List<QuestStatus> statuses = new List<QuestStatus>();
public event Action onUpdate;
private void Update()
{
CompleteObjectivesByPredicate();
}
public void AddQuest(Quest quest)
{
if (HasQuest(quest)) return;
QuestStatus newStatus = new QuestStatus(quest);
statuses.Add(newStatus);
if (onUpdate != null)
{
onUpdate();
}
}
public void CompleteObjective(Quest quest, string objective)
{
QuestStatus status = GetQuestStatus(quest);
status.CompleteObjective(objective);
if (status.IsComplete())
{
GiveReward(quest);
}
if (onUpdate != null)
{
onUpdate();
}
}
public bool HasQuest(Quest quest)
{
return GetQuestStatus(quest) != null;
}
public IEnumerable<QuestStatus> GetStatuses()
{
return statuses;
}
private QuestStatus GetQuestStatus(Quest quest)
{
foreach (QuestStatus status in statuses)
{
if (status.GetQuest() == quest)
{
return status;
}
}
return null;
}
private void GiveReward(Quest quest)
{
foreach (var reward in quest.GetRewards())
{
bool success = GetComponent<Inventory>().AddToFirstEmptySlot(reward.item, reward.number);
if (!success)
{
GetComponent<ItemDropper>().DropItem(reward.item, reward.number);
}
}
}
private void CompleteObjectivesByPredicate()
{
foreach (QuestStatus status in statuses)
{
if (status.IsComplete()) continue;
Quest quest = status.GetQuest();
foreach(var objective in status.GetQuest().GetObjectives())
{
if (status.IsObjectiveComplete(objective.reference)) continue;
if (!objective.usesCondition) continue;
if (objective.completionCondition.Check(GetComponents<IPredicateEvaluator>()))
{
CompleteObjective(quest, objective.reference);
}
}
}
}
public object CaptureState()
{
List<object> state = new List<object>();
foreach (QuestStatus status in statuses)
{
state.Add(status.CaptureState());
}
return state;
}
public void RestoreState(object state)
{
List<object> stateList = state as List<object>;
if (stateList == null) return;
statuses.Clear();
foreach (object objectState in stateList)
{
statuses.Add(new QuestStatus(objectState));
}
}
//implement this whenever i use evaulate
public bool? Evaluate(string predicate, string[] parameters)
{
switch (predicate)
{
case "HasQuest":
return HasQuest(Quest.GetByName(parameters[0]));
case "CompletedQuest":
return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();
}
return null;
}