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;
|
2022-12-27 15:16:59 +01:00
|
|
|
|
/*
|
|
|
|
|
[SerializeField]
|
|
|
|
|
public MissionProcess missionProcess = null;*/
|
|
|
|
|
|
|
|
|
|
[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();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
public void AssignMissionProcessToStep(int stepNumber)
|
2022-12-04 18:42:34 +01:00
|
|
|
|
{
|
2022-12-27 15:16:59 +01:00
|
|
|
|
MissionStepsList[stepNumber].SetStepProcess(missionProcess);
|
2022-12-04 18:42:34 +01:00
|
|
|
|
}
|
2022-12-27 15:16:59 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* public void SetMissionCondition(string name)
|
|
|
|
|
{
|
|
|
|
|
//factory.CreateCondition(Type); //, name)
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
// 2. Add mission to Player Panel :D
|
|
|
|
|
TaskUIManager.Instance.Add(PlayerTask);
|
|
|
|
|
|
|
|
|
|
// 3. Save Player Quest Panel status & (somehow) mission status in game
|
|
|
|
|
|
|
|
|
|
var saveController = GameObject.FindObjectOfType<SaveController>();
|
|
|
|
|
if (saveController == null)
|
|
|
|
|
throw new Exception($"There is no SaveController component on scene!!!");
|
|
|
|
|
|
|
|
|
|
saveController.GetComponent<SaveController>().SavePlayerQuests();
|
|
|
|
|
|
|
|
|
|
//// 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
|
|
|
|
|
var task = TaskUIManager.Instance.FindTaskByName(PlayerTask.Title);
|
|
|
|
|
|
|
|
|
|
if (task.Count == 0)
|
|
|
|
|
Debug.LogError($"Task '{PlayerTask.Title}' not found");
|
|
|
|
|
else
|
|
|
|
|
TaskUIManager.Instance.RemoveByName(PlayerTask.Title);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 !!
|
|
|
|
|
|
|
|
|
|
if ((MissionStep.Status == MissionStepStatusEnum.Active || MissionStep.Status == MissionStepStatusEnum.AfterCondition) && MissionStep.DialogueStep.GetCurrentStep().DialogueController.CurrentPanel != null)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
// 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;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GoToNextStep()
|
|
|
|
|
{
|
|
|
|
|
foreach (var MissionStep in MissionStepsList)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Case I: Do nothing sepciaj just get first Step which wasn't invoked yet
|
|
|
|
|
if(MissionStep.Status == MissionStepStatusEnum.Pending)
|
|
|
|
|
{
|
|
|
|
|
/// var nextSentence = MissionStep.DialogueStep.DialogueController.ShowNextPanel(
|
|
|
|
|
// MissionStep.DialogueStep.DialogueController
|
|
|
|
|
//);
|
|
|
|
|
|
|
|
|
|
//If there is no sentence in Step - go to next one
|
|
|
|
|
/* if (!nextSentence)
|
|
|
|
|
{
|
|
|
|
|
MissionStep.Status = MissionStepStatusEnum.Finished;
|
|
|
|
|
|
|
|
|
|
ShowStep();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
if(conditionResult)
|
|
|
|
|
ShowStep();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-06 21:54:50 +01:00
|
|
|
|
Debug.Log("BuildMission - Activate step");
|
2022-12-27 15:16:59 +01:00
|
|
|
|
MissionStepsList[CurrentStep].ActivateStep();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|