Scriptum/Assets/Scripts/REFACTORING/Application/Mission/Model/MissionStepModel.cs

183 lines
5.3 KiB
C#
Raw Permalink Normal View History

2022-12-04 18:42:34 +01:00
using UnityEditor;
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
using System;
2022-12-27 15:16:59 +01:00
using UnityEngine.Events;
2022-12-04 18:42:34 +01:00
2023-01-07 17:49:15 +01:00
2022-12-27 15:16:59 +01:00
/*
* 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
*/
2022-12-04 18:42:34 +01:00
[Serializable]
public class MissionStepModel
{
2022-12-27 15:16:59 +01:00
protected Mission MissionOrigin { get; private set; }
// Must be filled manually ! ! !
[SerializeField]
public string SpeakerName;
2022-12-04 18:42:34 +01:00
[SerializeField] // this flag tell whatewer dialoge ware already display to user
public MissionStepStatusEnum Status = MissionStepStatusEnum.None;
2023-01-07 17:49:15 +01:00
// new mission header (optional - deleted (string, string) ) & task content
[SerializeField]
public string MissionIssue;
2022-12-27 15:16:59 +01:00
/*
2022-12-04 18:42:34 +01:00
[SerializeField]
2022-12-27 15:16:59 +01:00
public MissionDialogue DialogueStepTemplate;*/
2022-12-04 18:42:34 +01:00
[SerializeField]
2022-12-27 15:16:59 +01:00
public MissionDialogue DialogueStep;
2022-12-04 18:42:34 +01:00
2022-12-27 15:16:59 +01:00
// Conditions must be assigned to specify dialogue step
[SerializeField]
public IndexValuePair<int, List<MissionCondition>> MissionConditions;
2022-12-04 18:42:34 +01:00
public MissionStepModel() { }
2022-12-27 15:16:59 +01:00
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;
2022-12-04 18:42:34 +01:00
2022-12-27 15:16:59 +01:00
RegisterCondition();
2023-01-03 22:44:24 +01:00
((MissionDataManager)MissionDataManager.Instance).RegisterMission(MissionOrigin); // save mission status aftre each activating partial mission
2022-12-27 15:16:59 +01:00
}
#region Condition Mangment section
public void RegisterCondition()
2022-12-04 18:42:34 +01:00
{
2022-12-27 15:16:59 +01:00
ConditionManager.Instance.RegisterCondition(MissionOrigin.MissionName, BuildConditionsList());
2022-12-04 18:42:34 +01:00
}
2022-12-27 15:16:59 +01:00
/// <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()
2022-12-04 18:42:34 +01:00
{
2022-12-27 15:16:59 +01:00
var buildedList = new List<MissionCondition>();
2022-12-04 18:42:34 +01:00
2022-12-27 15:16:59 +01:00
foreach (var baseCondition in MissionConditions.Value)
{
buildedList.Add(baseCondition.Build());
}
2022-12-04 18:42:34 +01:00
2022-12-27 15:16:59 +01:00
return buildedList;
2022-12-04 18:42:34 +01:00
}
2022-12-27 15:16:59 +01:00
// 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);
}
2023-01-07 17:49:15 +01:00
/*
public void FinishStep()
{
}*/
2022-12-27 15:16:59 +01:00
#endregion
2023-01-03 22:44:24 +01:00
#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
2023-01-07 17:49:15 +01:00
/// <summary>
/// Function to update Pkayer Quest description (and header optionaly) during mission progress
/// </summary>
public void PlayerQuestContentManage(string newContent)
{
MissionOrigin.PlayerQuestContentManage(newContent);
}
public void PlayerQuestContentManage()
{
MissionOrigin.PlayerQuestContentManage(MissionIssue);
}
2022-12-04 18:42:34 +01:00
}
2022-12-27 15:16:59 +01:00
2022-12-04 18:42:34 +01:00
// 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)