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

378 lines
11 KiB
C#
Raw Permalink Normal View History

2022-12-04 18:42:34 +01:00
using System;
using System.Collections.Generic;
2022-12-27 15:16:59 +01:00
using System.Linq;
2022-12-04 18:42:34 +01:00
using UnityEditor;
using UnityEngine;
[Serializable]
[CreateAssetMenu(fileName = "New Mission", menuName = "Mission/New Mission")]
public class Mission : ScriptableObject
{
2022-12-27 15:16:59 +01:00
[SerializeField]
public string MissionName;
[SerializeField]
public Task PlayerTask;
[SerializeField]
public string SpeakerName;
/* [SerializeField]
public MissionTypeEnum Type;*/
2022-12-04 18:42:34 +01:00
[SerializeField]
public MissionStatusEnum Status = MissionStatusEnum.None;
[SerializeField]
2023-01-03 22:44:24 +01:00
public int CurrentStep = 0;
2022-12-04 18:42:34 +01:00
[SerializeField]
public List<MissionStepModel> MissionStepsList;
2023-01-07 17:49:15 +01:00
/*
[SerializeField]
public MissionProcess missionProcess = null;*/
2022-12-27 15:16:59 +01:00
[SerializeField]
public MissionReward Reward;
2022-12-04 18:42:34 +01:00
2022-12-27 15:16:59 +01:00
//ConditionController . check condition
//private ConditionFactory factory = new ConditionFactory();
2023-01-07 17:49:15 +01:00
/*
public void AssignMissionProcessToStep(int stepNumber)
{
MissionStepsList[stepNumber].SetStepProcess(missionProcess);
}
*/
2022-12-27 15:16:59 +01:00
2023-01-07 17:49:15 +01:00
/* public void SetMissionCondition(string name)
{
//factory.CreateCondition(Type); //, name)
}*/
2022-12-27 15:16:59 +01:00
// Set by hand as mission condition as final astion specyfic step
2023-01-03 22:44:24 +01:00
public void CheckMissionRequirements()
2022-12-27 15:16:59 +01:00
{
}
public void SetSpeakerName(string speakerName) { SpeakerName = speakerName; }
2022-12-04 18:42:34 +01:00
public void Accept()
{
2022-12-27 15:16:59 +01:00
Debug.Log("Accepting mission");
2022-12-04 18:42:34 +01:00
Status = MissionStatusEnum.Accepted;
2022-12-27 15:16:59 +01:00
// ADD CONDITION LISTENING TO SPECIFY MISSION MANAGER missions list
2023-01-12 15:22:49 +01:00
// currently condition is registered after start scene and again after accpetiong
2022-12-27 15:16:59 +01:00
2023-01-07 17:49:15 +01:00
CreateQuestOnList();
2022-12-27 15:16:59 +01:00
//// TODO ! ! !
///saveController.SaveMissions();
///
2022-12-04 18:42:34 +01:00
}
public void Reject()
{
Status = MissionStatusEnum.Rejected;
2022-12-27 15:16:59 +01:00
ConditionManager.Instance.RemoveCondition(MissionName);
// 3. Save Mission status in game
//// TODO ! ! !
}
// Assign geting reward as Model End Action
// Bind by hand to specyfic mission step action
public void GiveReward()
{
// TODO status is overwritten during building
//if (Status != MissionStatusEnum.Accepted)
// return;
var Player = GameObject.FindGameObjectWithTag("Player");
if (!Player)
Debug.LogError("MissionStepModel::GetReward - There is no player on scene!!!");
Player.GetComponent<PlayerActions>().GetReward(Reward);
}
public void FinishMission()
{
Debug.Log("FinishMission");
Status = MissionStatusEnum.Finished;
// 3. remove quest from player list
2023-01-07 17:49:15 +01:00
RemoveQuestFromList();
}
2022-12-27 15:16:59 +01:00
2023-01-07 17:49:15 +01:00
/// <summary>
/// czy ta akcja ma by wywolywana w buttonie i ma wywoływac inn eakcje z 'end of step actions lsit'
/// czy ma byc jedna z nich i byc wywoływana przez 'go to next sentence' ....
/// </summary>
public void FinishMissionStep()
{
MissionStepsList[CurrentStep].Status = MissionStepStatusEnum.Finished;
CurrentStep++;
2022-12-27 15:16:59 +01:00
2023-01-07 17:49:15 +01:00
// build without starting
BuildMission(MissionStepsList);
}
/// <summary>
/// Alias dla tego co powinna robić logika 'GoToNextStep' w Missjach
/// </summary>
public void FinishMissionStepAndGoToNext()
{
MissionStepsList[CurrentStep].Status = MissionStepStatusEnum.Finished;
CurrentStep++;
// build & start
StartDialogue();
2022-12-27 15:16:59 +01:00
}
public bool CheckStepFinalCondition()
{
if (MissionStepsList[CurrentStep].CheckCondition())
{
//MissionStepsList[CurrentStep].GiveReward();
MissionStepsList[CurrentStep].Status = MissionStepStatusEnum.Finished;
}
else
{
// Show dialoge with sentence like "you dont compleeted requirements"
Debug.Log("Soprry you dont meet the criteria yet...");
return false;
}
return true;
}
// dialogue components
public void StartDialogue()
{
// 1. Build
BuildMission(MissionStepsList);
// 2. Show first step
ShowStep();
}
public void BreakDialogueStep()
{
foreach (var MissionStep in MissionStepsList)
{
// NIKE TYLKO ACTIVE !!
2023-01-07 17:49:15 +01:00
if ((MissionStep.Status == MissionStepStatusEnum.Active || MissionStep.Status == MissionStepStatusEnum.AfterCondition) && MissionStep.DialogueStep.GetCurrentStep().DialogueController.CurrentPanel != null)
2022-12-27 15:16:59 +01:00
{
MissionStep.DialogueStep.GetCurrentStep().DialogueController.CloseCurrentPanel(); // close panel
break;
}
}
}
public void ShowStep()
{
foreach (var MissionStep in MissionStepsList)
{
// jesli krok jest aktywny & ma niewypowiedziane zdania
2023-01-03 22:44:24 +01:00
if ((MissionStep.Status == MissionStepStatusEnum.Active || MissionStep.Status == MissionStepStatusEnum.AfterCondition) && MissionStep.DialogueStep.GetCurrentStep()?.DialogueController.listOfDialogue.Count != 0)
2022-12-27 15:16:59 +01:00
{
MissionStep.DialogueStep.StartDialogue();
break;
}
2023-01-07 17:49:15 +01:00
/*
// jesli stan jest oczekujacy && dialog nie został w całości przegadany
// jesli warnek jest zpeniony - idz dalej - nie, czeksaj
if (MissionStep.Status == MissionStepStatusEnum.Pending && MissionStep.DialogueStep.GetCurrentStep().DialogueController.listOfDialogue.Count != 0)
{
// Check or register condition.....
// 1. Register condition
//ConditionManager.Instance.RegisterCondition(MissionName, MissionStep.MissionConditions);
// 2. register next step action
// TODO
// 3. Open panel (dialogue) ???
MissionStep.DialogueStep.StartDialogue(); // create panel
break;
}*/
2022-12-27 15:16:59 +01:00
}
}
public void GoToNextStep()
{
foreach (var MissionStep in MissionStepsList)
{
// Case I: Do nothing sepciaj just get first Step which wasn't invoked yet
2023-01-07 17:49:15 +01:00
if (MissionStep.Status == MissionStepStatusEnum.Pending)
2022-12-27 15:16:59 +01:00
{
2023-01-07 17:49:15 +01:00
/// var nextSentence = MissionStep.DialogueStep.DialogueController.ShowNextPanel(
2022-12-27 15:16:59 +01:00
// MissionStep.DialogueStep.DialogueController
//);
//If there is no sentence in Step - go to next one
2023-01-07 17:49:15 +01:00
/* if (!nextSentence)
{
MissionStep.Status = MissionStepStatusEnum.Finished;
2022-12-27 15:16:59 +01:00
2023-01-07 17:49:15 +01:00
ShowStep();
}
*/
2022-12-27 15:16:59 +01:00
break;
}
// Case II: Before go foward we must check final condition
if (MissionStep.Status == MissionStepStatusEnum.Active)
{
// po co to ? ? ? - obecnie warunek misji jest sprawdazany nankoncu podanego stepu dialogu
// po spełnieniu step misji oznaczany jest jako ukończony
var conditionResult = CheckStepFinalCondition();
2023-01-07 17:49:15 +01:00
if (conditionResult)
2022-12-27 15:16:59 +01:00
ShowStep();
break;
2023-01-07 17:49:15 +01:00
}
2022-12-27 15:16:59 +01:00
}
}
public void BuildMission()
{
BuildMission(MissionStepsList);
}
private void BuildMission(List<MissionStepModel> Mission)
{
// Obligatory
if (Status == MissionStatusEnum.None)
Status = MissionStatusEnum.Available;
foreach (var missionStep in Mission)
{
missionStep.SetSpeakerName(SpeakerName);
missionStep.Build(this);
}
// Additionaly set first step as active
2023-01-07 17:49:15 +01:00
//Debug.Log("BuildMission - Activate step");
if (MissionStepsList.Count() > CurrentStep)
MissionStepsList[CurrentStep].ActivateStep();
else
Debug.Log($"Mission [{MissionName}] step {CurrentStep} out of steps list containing {MissionStepsList.Count()}");
2022-12-27 15:16:59 +01:00
}
2023-01-03 22:44:24 +01:00
#region Dialogue Status API
/// <summary>
/// Function to reset rememebered dialogue status
///
/// (Scriptable objects clones are overwritten during clone modification)
/// </summary>
public void ResetMission()
{
Status = MissionStatusEnum.None;
CurrentStep = 0;
MissionStepsList.ForEach(step => step.ResetMissionStep());
}
public void UpdateMissionState(MissionData missionData)
{
// 1 Rule - speaker name shouldnt change !!! its our 'key'
Status = missionData.Status;
CurrentStep = missionData.CurrentStep;
for (int i = 0; i < missionData.MissionStepsDataList.Count; i++)
{
MissionStepsList[i].UpdateMissionStepState(missionData.MissionStepsDataList[i]);
}
}
#endregion
2022-12-27 15:16:59 +01:00
public MissionStepModel GetCurrentStep()
{
return MissionStepsList[CurrentStep];
2022-12-04 18:42:34 +01:00
}
2023-01-07 17:49:15 +01:00
#region Quest managment
public void CreateQuestOnList()
{
// WHERE IS CONDITION TO CHECK IF MISSION ALREADY EXISTS ??? ??? ???
// 2. Add mission to Player Panel :D
TaskUIManager.Instance.Add(PlayerTask);
// 3. Save Player Quest Panel status & (somehow) mission status in game
// Don't save quest in this moement on list because mission proggrss isnt saved before using
// teleport or saving proggress by player - data consistency
/*
var saveController = GameObject.FindObjectOfType<SaveController>();
if (saveController == null)
throw new Exception($"There is no SaveController component on scene!!!");
saveController.GetComponent<SaveController>().SavePlayerQuests();
*/
}
public void RemoveQuestFromList()
{
var task = TaskUIManager.Instance.FindTaskByName(PlayerTask.Title);
if (task.Count == 0)
Debug.LogError($"Task '{PlayerTask.Title}' not found");
else
TaskUIManager.Instance.RemoveByName(PlayerTask.Title);
}
/// <summary>
/// Po co misja idwoluje sie do dziecka zamiast ustawic to samemu?
///
/// Wprzyszlosci ustawic nowy content w stepei!
///
/// IMPORANT:
/// nadpisanie w jednym kroku nadpisuje żródłowy Description w Taku obiektu Mission!!!
/// </summary>
/// <param name="newMissionissue"></param>
public void PlayerQuestContentManage(string newMissionissue)
{
var task = TaskUIManager.Instance.FindTaskByName(PlayerTask.Title);
if (task.Count() == 0)
CreateQuestOnList();
// manually setupped new contrent for wqizard first mission script
((TaskUIManager)TaskUIManager.Instance).ChangeTaskIssue(PlayerTask.Title, newMissionissue);
}
#endregion
2022-12-04 18:42:34 +01:00
}