159 lines
4.8 KiB
C#
159 lines
4.8 KiB
C#
using UnityEditor;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using UnityEngine.Events;
|
|
|
|
/*
|
|
* In basic want to have 3 steps
|
|
* - first to say hello and accept/reject mission
|
|
* - secont - to check condition with plain dialogue
|
|
* - third - to get reward
|
|
*/
|
|
[Serializable]
|
|
public class MissionStepModel
|
|
{
|
|
protected Mission MissionOrigin { get; private set; }
|
|
|
|
// Must be filled manually ! ! !
|
|
[SerializeField]
|
|
public string SpeakerName;
|
|
|
|
[SerializeField] // this flag tell whatewer dialoge ware already display to user
|
|
public MissionStepStatusEnum Status = MissionStepStatusEnum.None;
|
|
/*
|
|
[SerializeField]
|
|
public MissionDialogue DialogueStepTemplate;*/
|
|
|
|
[SerializeField]
|
|
public MissionDialogue DialogueStep;
|
|
|
|
// Conditions must be assigned to specify dialogue step
|
|
[SerializeField]
|
|
public IndexValuePair<int, List<MissionCondition>> MissionConditions;
|
|
|
|
public MissionStepModel() { }
|
|
|
|
public void SetSpeakerName(string speakerName) { SpeakerName = speakerName; }
|
|
|
|
public Mission GetOriginMission()
|
|
{
|
|
return MissionOrigin;
|
|
}
|
|
|
|
public virtual void Build(Mission parent)
|
|
{
|
|
if(Status == MissionStepStatusEnum.None)
|
|
Status = MissionStepStatusEnum.Pending;
|
|
|
|
MissionOrigin = parent;
|
|
|
|
//DialogueStep = MonoBehaviour.Instantiate(DialogueStepTemplate); // create copy to prevent overwritting oryginal object! !
|
|
DialogueStep.BindParent(this);
|
|
DialogueStep.SetSpeakerName(SpeakerName);
|
|
DialogueStep.BuildDialogue();
|
|
//DialogueStep.SetActionAfterDialogueStep(MissionConditions.Key, HanldeMissionStepCondition);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Important: Mission Step must be previously builded by Build function!!!
|
|
/// </summary>
|
|
public void ActivateStep()
|
|
{
|
|
// Dialogue MUST be builded ALWAYS - Build dialogue without displayed panel
|
|
//DialogueStep.BuildDialogue(DialogueStep.DialogueSteps);
|
|
|
|
if (Status != MissionStepStatusEnum.Pending)
|
|
return;
|
|
|
|
Status = MissionStepStatusEnum.Active;
|
|
|
|
RegisterCondition();
|
|
|
|
((MissionDataManager)MissionDataManager.Instance).RegisterMission(MissionOrigin); // save mission status aftre each activating partial mission
|
|
}
|
|
|
|
#region Condition Mangment section
|
|
public void RegisterCondition()
|
|
{
|
|
ConditionManager.Instance.RegisterCondition(MissionOrigin.MissionName, BuildConditionsList());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Function to change Base Conditions objects put in list defaultly to specific
|
|
///
|
|
/// Note: This allow to cover base methods by this overwrittens in specific sub-class (like: CheckCondition method)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<MissionCondition> BuildConditionsList()
|
|
{
|
|
var buildedList = new List<MissionCondition>();
|
|
|
|
foreach (var baseCondition in MissionConditions.Value)
|
|
{
|
|
buildedList.Add(baseCondition.Build());
|
|
}
|
|
|
|
return buildedList;
|
|
}
|
|
|
|
|
|
// If mission's stem condition is fulified then mrak mission step as finished
|
|
// else do nothing - player MUST this loop step
|
|
// Its not required to condition be in last dialogue step
|
|
|
|
// Checking condition and handling after action is assigned by button in dialogue step
|
|
// If no then there is no possibility to go foward in proggress
|
|
public bool HanldeMissionStepCondition()
|
|
{
|
|
if(CheckCondition())
|
|
{
|
|
Status = MissionStepStatusEnum.AfterCondition;
|
|
|
|
// 2. Remove Misison Steps Conditon from global list
|
|
ConditionManager.Instance.RemoveCondition(MissionOrigin.MissionName);
|
|
|
|
// 3. Remove founded elements
|
|
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
|
|
Debug.Log("Dialogue - FinalAction - CheckCondition - HanldeMissionStepCondition - Condition not meeted");
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public bool CheckCondition()
|
|
{
|
|
return ConditionManager.Instance.CheckCondition(MissionOrigin.MissionName);
|
|
}
|
|
#endregion
|
|
|
|
#region Mission Status API
|
|
|
|
public void ResetMissionStep()
|
|
{
|
|
Status = MissionStepStatusEnum.None;
|
|
|
|
DialogueStep.ResetDialogue();
|
|
}
|
|
|
|
public void UpdateMissionStepState(MissionStepData dialogueData)
|
|
{
|
|
// 1 Rule - speaker name shouldnt change !!! its our 'key'
|
|
Status = dialogueData.Status;
|
|
|
|
DialogueStep.UpdateDialogueState(dialogueData.MissionDialogueData);
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
|
|
// TODO
|
|
// zapobieganie zniuknieciu itemow po otrzymaniu nagrody z poanelu gracza - WYKONANIE SAVE PO ZAKOŃCZENIU STEPU:
|
|
// -- zapisanie postępu misji w pliku z misjami
|
|
// -- zapisanie statusu panelu gracza (lista misji / content ekwipunku / magazynu) |