Missions - saving

This commit is contained in:
kabix09 2023-01-03 22:44:24 +01:00
parent b72537003b
commit db8589c61a
69 changed files with 1573 additions and 205 deletions

View File

@ -12,11 +12,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 67587597537a4344cad65ddbcebee119, type: 3}
m_Name: New Mission Dialogue
m_EditorClassIdentifier:
SpeakerName: Luberjack 2
CurrentStep: 0
SpeakerName: Lumberjack xd
CurrentStep: 2
DialogueSteps:
- Header: Luberjack 2
WasDisplayed: 0
- Header: Lumberjack xd
WasDisplayed: 1
ListOfSentences:
- Sentence: Could you help me?
Buttons: []
@ -56,14 +56,24 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- Sentence: Thank you very much, now go!
Buttons: []
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: FinishDialogue
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: ShowNextPanel
m_MethodName: GoToNextSentence
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
@ -73,58 +83,57 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- Header: Luberjack 2
WasDisplayed: 0
ListOfSentences:
- Sentence: Fantastic!!
Buttons: []
- Sentence: Please take this reward
Buttons:
- ButtonName: Take
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: GiveReward
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: GoToNextSentence
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: FinishMission
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- Header: Luberjack 2
- Header: Lumberjack xd
WasDisplayed: 1
ListOfSentences:
- Sentence: Thank you very much, now go!
Buttons: []
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls: []
- Header: Lumberjack xd
WasDisplayed: 0
ListOfSentences:
- Sentence: Have you ound it?
Buttons:
- ButtonName: yes
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: HandleCondition
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- ButtonName: no
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: BreakDialogueStep
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls: []
- Header: Lumberjack xd
WasDisplayed: 0
ListOfSentences:
- Sentence: Fantastic!!

View File

@ -0,0 +1,184 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 67587597537a4344cad65ddbcebee119, type: 3}
m_Name: New Mission Kill
m_EditorClassIdentifier:
SpeakerName: Lumberjack kill mission
CurrentStep: 1
DialogueSteps:
- Header: Lumberjack kill mission
WasDisplayed: 1
ListOfSentences:
- Sentence: Please kill 2 bats for me
Buttons:
- ButtonName: I dont want to kill them
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: RejectMission
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- ButtonName: I will kill them
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: AcceptMission
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: FinishDialogue
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: GoToNextSentence
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- Header: Lumberjack kill mission
WasDisplayed: 1
ListOfSentences:
- Sentence: Thank you very much, now go!
Buttons: []
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls: []
- Header: Lumberjack kill mission
WasDisplayed: 0
ListOfSentences:
- Sentence: Have you kill them?
Buttons:
- ButtonName: no
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: BreakDialogueStep
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- ButtonName: yes
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: HandleCondition
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls: []
- Header: Lumberjack kill mission
WasDisplayed: 0
ListOfSentences:
- Sentence: Fantastic!!
Buttons: []
- Sentence: Please take this reward
Buttons:
- ButtonName: Take
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: GiveReward
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: GoToNextSentence
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp
m_MethodName: FinishMission
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f78fd8078bd29a24dbe821cdde4c511b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0a3bcdd1e2dba0c4791bcb151c0df6c1, type: 3}
m_Name: TestMission
m_Name: TestCollectMission
m_EditorClassIdentifier:
MissionName: Test mission I
PlayerTask:
@ -18,13 +18,12 @@ MonoBehaviour:
title:
description:
difficulty: 0
SpeakerName:
Status: 0
SpeakerName: Lumberjack kill mission
Status: 3
CurrentStep: 0
MissionStepsList:
- SpeakerName:
Status: 0
DialogueStepTemplate: {fileID: 11400000, guid: fe2810d79ff17f74eab5cf9a916167b4, type: 2}
- SpeakerName: Lumberjack kill mission
Status: 2
DialogueStep: {fileID: 11400000, guid: fe2810d79ff17f74eab5cf9a916167b4, type: 2}
MissionConditions:
Key: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9e6ca23e6f35bc94891c0cdf2a450fae
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,39 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0a3bcdd1e2dba0c4791bcb151c0df6c1, type: 3}
m_Name: TestKillMission
m_EditorClassIdentifier:
MissionName: mission kill test
PlayerTask:
id: 0
title:
description:
difficulty: 0
SpeakerName: Lumberjack kill mission
Status: 3
CurrentStep: 0
MissionStepsList:
- SpeakerName: Lumberjack kill mission
Status: 2
DialogueStep: {fileID: 11400000, guid: f78fd8078bd29a24dbe821cdde4c511b, type: 2}
MissionConditions:
Key: 0
Value:
- Type: 1
RequiredElements:
- RequiredAmount: 2
RequiredObject: {fileID: 8184504007427166059, guid: 90bf7de365b8fee4993aa2e50b64fe14, type: 3}
Reward:
Items:
- {fileID: 11400000, guid: dc7fdbc8450965344914371023ddb0c5, type: 2}
- {fileID: 11400000, guid: 5ca5ea8918f15904c8bad3fe9694e5a5, type: 2}
Cash: 300

View File

@ -67,7 +67,9 @@ public class AnimatedDoorBehaviour : TriggerDoor
SaveController.GetComponent<SaveController>().SaveChests();
SaveController.GetComponent<SaveController>().SaveShops();
SaveController.GetComponent<SaveController>().SaveDialogues();
SaveController.GetComponent<SaveController>().SaveDialogues();
SaveController.GetComponent<SaveController>().SaveMissions();
// 2. Change scene
SceneManager.LoadScene(gateway.nextMapName);

View File

@ -49,6 +49,7 @@ public class DoorBehaviour : MonoBehaviour
SaveController.GetComponent<SaveController>().SaveChests();
SaveController.GetComponent<SaveController>().SaveShops();
SaveController.GetComponent<SaveController>().SaveDialogues();
SaveController.GetComponent<SaveController>().SaveMissions();
// 2. Change scene
SceneManager.LoadScene(gateway.nextMapName);

View File

@ -5,14 +5,16 @@ using UnityEngine;
public class Enemy : MonoBehaviour
{
public float moveSpeed;
public string enemyName;
public string enemyName; // var for name (must be unique (playerPrefs.set/get string "enemyName - s")
public FloatValue maxHealth;
public float health;
public float baseAttack;
public string MinionName; // var used for multiplied name - for mission poroggress (kill condition)
private void Awake()
{
health = maxHealth.initialValue;
health = maxHealth.initialValue;
}

View File

@ -222,7 +222,8 @@ public class FollowingEnemy : Enemy
other.GetComponent<Player>().GetExp(expValue);
// pass info about killing assigned enemy to mission manager listener
ConditionManager.Instance.UpdateKillCondition(gameObject.name);
// pass enemy name from script NOT object name (thats allow to have many different objects variantsa with this same aggregate key (private name - not preffab name) )
ConditionManager.Instance.UpdateKillCondition(gameObject.GetComponent<Enemy>().MinionName);
}
}

View File

@ -194,7 +194,8 @@ public class FollowingPatrollingEnemy : Enemy
other.GetComponent<Player>().GetExp(expValue);
// pass info about killing assigned enemy to mission manager listener
ConditionManager.Instance.UpdateKillCondition(gameObject.name);
// pass enemy name from script NOT object name (thats allow to have many different objects variantsa with this same aggregate key (private name - not preffab name) )
ConditionManager.Instance.UpdateKillCondition(gameObject.GetComponent<Enemy>().MinionName);
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
@ -266,10 +267,12 @@ public class Dialogue : ScriptableObject, IDialogue
/// </summary>
public void ResetDialogue()
{
CurrentStep = 0;
DialogueSteps.ForEach(step => step.WasDisplayed = false);
}
public void UpdateDialogueState(DialogueData dialogueData)
public virtual void UpdateDialogueState(DialogueData dialogueData)
{
// 1 Rule - speaker name shouldnt change !!! its our 'key'
@ -283,9 +286,15 @@ public class Dialogue : ScriptableObject, IDialogue
}
#endregion
public DialogueStepModel GetCurrentStep()
public DialogueStepModel? GetCurrentStep()
{// TODO - argument out of colection :/
return DialogueSteps[CurrentStep];
var currentStep = DialogueSteps.ElementAtOrDefault(CurrentStep);
if (currentStep != null && currentStep.WasDisplayed && CurrentStep < DialogueSteps.Count)
CurrentStep++;
return DialogueSteps.Count > CurrentStep ? DialogueSteps[CurrentStep] : null;
}

View File

@ -149,7 +149,7 @@ public class DialogueManager : MonoBehaviour
public virtual bool GetCurrentDialoguePanelStatus()
{
var multiDialStatius = Dialogue.DialogueStepStatus();
Debug.Log(multiDialStatius);
// parse result (dialoge no, step no)
// dialogue not exist - finished
// dialoge exists & step no > steps sum - finished

View File

@ -28,7 +28,8 @@ public class MissionDialogue : Dialogue
Parent.GetOriginMission().Accept();
// show next panel if exists
ShowNextPanel();
//ShowNextPanel();
// no we allow to decide programers which one use GoToNextSentence or ShowNextPanel
}
/// <summary>
@ -52,7 +53,6 @@ public class MissionDialogue : Dialogue
Debug.Log("Handle Conditoion");
var result = Parent.HanldeMissionStepCondition();
Debug.Log(CurrentStep);
if (result) GoToNextSentence();
else BreakDialogueStep();
}
@ -68,5 +68,19 @@ public class MissionDialogue : Dialogue
Parent.GetOriginMission().FinishMission();
}
#endregion
#region Dialogue Status API
public void UpdateDialogueState(MissionDialogueData dialogueData)
{
CurrentStep = dialogueData.CurrentStep;
for (int i = 0; i < dialogueData.DialogueStepModelDataList.Count; i++)
{
DialogueSteps[i].WasDisplayed = dialogueData.DialogueStepModelDataList[i].WasDisplayed;
}
}
#endregion
}

View File

@ -5,17 +5,12 @@ using System.Text;
using System.Threading.Tasks;
class CollectMissionCondition : MissionCondition
public class CollectMissionCondition : MissionCondition
{
public CollectMissionCondition()
{
Type = MissionTypeEnum.Collect;
}
public CollectMissionCondition() : base (MissionTypeEnum.Collect) {}
public CollectMissionCondition(MissionCondition missionCondition)
public CollectMissionCondition(MissionCondition missionCondition) : base (MissionTypeEnum.Collect)
{
Type = MissionTypeEnum.Collect;
// Convert base type Subject on specified sub-class (with own functions)
RequiredElements.Clear();
foreach (RequiredSubject requiredSubject in missionCondition.RequiredElements)

View File

@ -5,17 +5,12 @@ using System.Text;
using System.Threading.Tasks;
using UnityEngine;
class KillMissionCondion : MissionCondition
public class KillMissionCondition : MissionCondition
{
public KillMissionCondion()
{
Type = MissionTypeEnum.Kill;
}
public KillMissionCondition() : base(MissionTypeEnum.Kill) { }
public KillMissionCondion(MissionCondition missionCondition)
public KillMissionCondition(MissionCondition missionCondition) : base(MissionTypeEnum.Kill)
{
Type = MissionTypeEnum.Kill;
// Convert base type Subject on specified sub-class (with own functions)
RequiredElements.Clear();
foreach(RequiredSubject requiredSubject in missionCondition.RequiredElements)

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 65cb4fb8a7aa29641b4979c6ea2ad31f
guid: 99f1bc87bda30e042be2b016a67537f4
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -14,7 +14,7 @@ public class MissionCondition
[SerializeField]
public List<RequiredSubject> RequiredElements = new List<RequiredSubject>();
public MissionCondition() { }
public MissionCondition(MissionTypeEnum type) { Type = type; }
public bool IsConditionMeeted()
{
@ -28,7 +28,7 @@ public class MissionCondition
{
case MissionTypeEnum.Kill:
{
return new KillMissionCondion(this);
return new KillMissionCondition(this);
}
case MissionTypeEnum.Collect:
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
/// <summary>
@ -13,6 +9,8 @@ public class CollectRequiredSubject : RequiredSubject
{
protected override string MODEL_LOCALIZATION => "Items/";
public CollectRequiredSubject(int requiredAmount) : base(requiredAmount) { }
public CollectRequiredSubject(RequiredSubject requiredSubject) : base(requiredSubject.RequiredAmount, requiredSubject.RequiredObject) { }
public CollectRequiredSubject(int requiredAmount, GameObject enemy) : base(requiredAmount, enemy) { }
@ -31,4 +29,4 @@ public class CollectRequiredSubject : RequiredSubject
return isConditionMet;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
using UnityEngine;
[Serializable]
class KillRequiredSubject : RequiredSubject // Enemy - WTF is this class...
public class KillRequiredSubject : RequiredSubject // Enemy - WTF is this class...
{
protected override string MODEL_LOCALIZATION => "Enemies/";
@ -15,15 +15,18 @@ class KillRequiredSubject : RequiredSubject // Enemy - WTF is this class...
public KillRequiredSubject(RequiredSubject requiredSubject) : base(requiredSubject.RequiredAmount, requiredSubject.RequiredObject) { }
public KillRequiredSubject(int requiredAmount, GameObject enemy) : base(requiredAmount, enemy) { }
public KillRequiredSubject(int requiredAmount, GameObject enemy, int currentAmount) : base(requiredAmount, enemy) { CurrentAmount = currentAmount; }
public KillRequiredSubject(int requiredAmount, string enemyName) : base(requiredAmount, enemyName) { }
public KillRequiredSubject(int requiredAmount, string enemyName, int currentAmount) : base(requiredAmount, enemyName) { CurrentAmount = currentAmount; }
public KillRequiredSubject(int requiredAmount, int currentAmount) : base(requiredAmount) { CurrentAmount = currentAmount; }
public void IncreaseAmount()
{
Debug.Log("IncreaseAmount");
CurrentAmount += 1;
Debug.Log("New Amount: " + CurrentAmount);
}
public void IncreaseAmount(int amount)

View File

@ -16,6 +16,11 @@ public class RequiredSubject
[SerializeField]
public GameObject RequiredObject;
public RequiredSubject(int requiredAmount)
{
RequiredAmount = requiredAmount;
}
public RequiredSubject(int requiredAmount, GameObject _object)
{
RequiredAmount = requiredAmount;
@ -25,7 +30,7 @@ public class RequiredSubject
public RequiredSubject(int requiredAmount, string objectName)
{
RequiredAmount = requiredAmount;
RequiredObject = MonoBehaviour.Instantiate(FindObjectInResource(objectName));
RequiredObject = FindObjectInResource(objectName);
}
public GameObject FindObjectInResource(string modelName)
@ -33,10 +38,11 @@ public class RequiredSubject
var resource = Resources.Load<GameObject>(MODEL_LOCALIZATION + modelName);
if (!resource)
throw new System.Exception($"Resource {modelName} not found!!");
throw new System.Exception($"required Subject Resource {MODEL_LOCALIZATION + modelName} not found!!");
return resource;
}
public virtual bool CheckCondition() { return false; }
}

View File

@ -41,6 +41,8 @@ class ConditionManager : MonoBehaviour
{
if(HasMissionActiveCondition(missionName))
{
// Npc mission manager may try to register current condition - but player may have registered and saved it ealier
// and after loiading game system will read this condition and pass to list from memory files
Debug.LogError($"Mission '{missionName}' has currently active Condition");
return;
@ -52,8 +54,6 @@ class ConditionManager : MonoBehaviour
conditionsToContinue
)
);
Debug.Log("Condition registered :D");
}
/// <summary>
@ -68,7 +68,7 @@ class ConditionManager : MonoBehaviour
.Where(missionCondition => missionCondition.Type == MissionTypeEnum.Kill)
.ToList()
.ForEach(killCondition => killCondition.RequiredElements
.Where(element => element.RequiredObject.name == objectName)
.Where(element => element.RequiredObject.GetComponent<Enemy>().MinionName == objectName)
.ToList()
.ForEach(element => ((KillRequiredSubject)element).IncreaseAmount())
);
@ -87,7 +87,7 @@ class ConditionManager : MonoBehaviour
if(!HasMissionActiveCondition(missionName))
{
Debug.LogError($"Data inconsistency!!! Mission dont have any registered condition to check");
return true;
return false;
}
int unmeetedConditions = Conditions

View File

@ -27,7 +27,7 @@ public class Mission : ScriptableObject
public MissionStatusEnum Status = MissionStatusEnum.None;
[SerializeField]
int CurrentStep = 0;
public int CurrentStep = 0;
[SerializeField]
public List<MissionStepModel> MissionStepsList;
@ -54,7 +54,7 @@ public class Mission : ScriptableObject
}*/
// Set by hand as mission condition as final astion specyfic step
public void CheckMissionrequirements()
public void CheckMissionRequirements()
{
}
@ -181,7 +181,7 @@ public class Mission : ScriptableObject
foreach (var MissionStep in MissionStepsList)
{
// jesli krok jest aktywny & ma niewypowiedziane zdania
if ((MissionStep.Status == MissionStepStatusEnum.Active || MissionStep.Status == MissionStepStatusEnum.AfterCondition) && MissionStep.DialogueStep.GetCurrentStep().DialogueController.listOfDialogue.Count != 0)
if ((MissionStep.Status == MissionStepStatusEnum.Active || MissionStep.Status == MissionStepStatusEnum.AfterCondition) && MissionStep.DialogueStep.GetCurrentStep()?.DialogueController.listOfDialogue.Count != 0)
{
MissionStep.DialogueStep.StartDialogue();
@ -267,6 +267,35 @@ public class Mission : ScriptableObject
MissionStepsList[CurrentStep].ActivateStep();
}
#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
public MissionStepModel GetCurrentStep()
{

View File

@ -71,18 +71,13 @@ public class MissionStepModel
RegisterCondition();
((MissionDataManager)MissionDataManager.Instance).RegisterMission(MissionOrigin); // save mission status aftre each activating partial mission
}
#region Condition Mangment section
public void RegisterCondition()
{
Debug.Log(MissionConditions);
Debug.Log(MissionConditions.Value[0].Type);
ConditionManager.Instance.RegisterCondition(MissionOrigin.MissionName, BuildConditionsList());
Debug.Log("Condition registered");
}
/// <summary>
@ -137,6 +132,24 @@ public class MissionStepModel
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
}

View File

@ -23,11 +23,36 @@ public class NpcMissionManager : DialogueManager // ScriptableObject
//public List<IndexValuePair<IndexValuePair<int, int>, MissionCondition>> EndactionEventList;
public void Start()
public override void Start()
{
Mission = Instantiate(MissionTemplate);
Mission.SetSpeakerName(gameObject.GetComponent<NPC>().Name);
//Mission.BuildMission();
base.Start();
CanBeOpened = false;
OpenInDefaultWay = false;
CreateInstanceBasedOnLanguage();
// UPDATE DIALOGUE
// search in scene manager list
if (Mission != null)
{
var machedDialogueData = ((MissionDataManager)MissionDataManager.Instance).GetMission(Mission);
if (machedDialogueData != null)
{
UpdateMissionState(machedDialogueData);
}
else
{
Debug.Log("Start - UpdateProggres");
UpdateProggres();
}
}
Mission.BuildMission();
if (FreeDialogue != null)
FreeDialogue.Build();
@ -45,8 +70,6 @@ public class NpcMissionManager : DialogueManager // ScriptableObject
{
CanBeOpened = true;
SpeakerName = collision.gameObject.name;
Mission.StartDialogue();
}
}
@ -61,29 +84,56 @@ public class NpcMissionManager : DialogueManager // ScriptableObject
{
CanBeOpened = false;
if (GetCurrentDialoguePanelStatus())
if (Mission != null && GetCurrentDialoguePanelStatus())
{
Debug.Log("BreakDialogueStep");
Mission.BreakDialogueStep();
/* Debug.Log("BreakDialogueStep");
*/ Mission.BreakDialogueStep();
}
}
}
/* public void Talk()
public override void CreateInstanceBasedOnLanguage()
{
if (Mission == null || Mission.Status == MissionStatusEnum.Finished)
{
// show free dialogue
//if(FreeDialogue != null)
//FreeDialogue.DialogueController.
} else
{
// continue mission
Mission.StartDialogue();
}
// DONT CLONE TO HAVE CONSTANT DATA - init - deep copy - to prevent overwritting chil;dern :D
Mission = MissionTemplate;
Mission.ResetMission();
/* var cloneDialogues = new List<IndexValuePair<int, Dialogue>>(Dialogue.Dialogues);
Dialogue.Dialogues.Clear();
foreach (var dial in cloneDialogues)
{
Dialogue.Dialogues.Add(new IndexValuePair<int, Dialogue>(dial.Key, Instantiate(dial.Value)));
}*/
Mission.SetSpeakerName(gameObject.GetComponent<NPC>().Name);
// update dial state - sync in order to prepare to save
Mission.MissionStepsList.ForEach(dial => dial.DialogueStep.SetActionAfterEachDialogueStep(UpdateProggres));
// Add one more action - to reset proggress
//Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterEachDialogueStep(dial.Value.ResetDialogue)); // reset dial
}
*/
public void UpdateMissionState(MissionData missionState)
{
// 1 Rule - speaker name shouldnt change !!! its our 'key'
Mission.UpdateMissionState(missionState);
}
/// <summary>
/// Function to sync local dialogue state with remote one
/// Handled in Scene Manager
/// </summary>
public void UpdateProggres()
{
((MissionDataManager)MissionDataManager.Instance).RegisterMission(Mission);
}
protected override bool ComponentEnabledCondition()
{
return !gameObject.GetComponent<NpcMissionManager>().enabled;
@ -91,24 +141,11 @@ public class NpcMissionManager : DialogueManager // ScriptableObject
public override bool GetCurrentDialoguePanelStatus()
{
Debug.Log(Mission
.GetCurrentStep()
.DialogueStep.CurrentStep
);
Debug.Log(Mission
.GetCurrentStep()
.DialogueStep
.GetCurrentStep()
.DialogueController
.CurrentPanel
);
return Mission
.GetCurrentStep()
.DialogueStep
.GetCurrentStep() // ?
.DialogueController
.GetCurrentStep()
?.DialogueController
.CurrentPanel != null;
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 980c28d408eb117438efae51b5d2a416
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class MissionConditionDataListManager : DataListManager<IndexValuePair<string, List<MissionConditionData>>>
{
// WE DONT NEED HERE UI MANAGER - because dialoges ane;t associated with ui panels in way like inventory / chest or shop
public override void AddElementToList(IndexValuePair<string, List<MissionConditionData>> newElement)
{
Elements.Add(newElement);
}
public override void RemoveElementFromList(IndexValuePair<string, List<MissionConditionData>> element)
{
throw new NotImplementedException();
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 439e1e19b22afd4478b4c1151588c35b
guid: 8d515fca317b6ce4882ed8be7036497a
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class MissionConditionDataLoader : SceneBaseDataLoader<IndexValuePair<string, List<MissionConditionData>>>
{
public MissionConditionDataLoader(string _objectListName, string _objectFolderName)
{
SaveModelSystem = new SaveMissionConditionManager();
SaveModelSystem.ObjectFolderName = _objectFolderName;
SaveModelSystem.ObjectListName = _objectListName;
}
protected override List<IndexValuePair<string, List<MissionConditionData>>> LoadDynamicData()
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();
return SaveModelSystem.LoadModelList();
}
protected override bool SaveDynamicData(List<IndexValuePair<string, List<MissionConditionData>>> _elements)
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();
return base.SaveDynamicData(_elements);
}
protected override List<IndexValuePair<string, List<MissionConditionData>>> LoadGenericData()
{
throw new NotImplementedException();
}
protected override bool SaveGenericData(List<IndexValuePair<string, List<MissionConditionData>>> _elements)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 51a727db7d9c63642b9eb8e111adcc29
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[RequireComponent(typeof(ConditionManager))]
class MissionConditionDataManager : SceneBaseDataManager<IndexValuePair<string, List<MissionConditionData>>>
{
protected override string OBJECT_FOLDER_NAME { get { return "MissionCondition"; } }
protected override string OBJECT_LIST_NAME { get { return "MissionsConditionsList"; } }
[SerializeField]
public List<IndexValuePair<string, List<MissionConditionData>>> MissionConditionDataList;
public override void Awake()
{
if (Instance == null)
{
Instance = this;
// moved from start beacuse we need to prepare env before NpcMissionmanager start registering and uipdating mission model
Debug.Log("Start Mission manager");
DynamicDataList = new MissionConditionDataListManager();
DataLoader = new MissionConditionDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME);
base.Start(); // (afterStart invoking - to load saved data)
}
else
{
Destroy(gameObject);
}
}
// ZMIANA KONCEPCJI
// ZMIAST TRZYMAC SUROWE OBIEKTY TYM RAZEM ZAPISUJMY modele Datai updatujmy obiket w NPC Managerze
// nadpisujemy by nir duplikowac wywoałania i nadpisyuwanie MissionDataList z Awake
public override void Start()
{
}
protected override void AfterStart()
{
if (OnMapAppearanceMethod.GameStatus == GameStatus.NewGame)
{
if (OnMapAppearanceMethod.Gateway != OnMapAppearanceMethodEnum.NewGame)
UseDynamicSettings(); // if there is nothing saved we will use UseDefaultSettings
else
UseDefaultSettings();
}
else
{
UseDynamicSettings();
}
}
protected override void UseDefaultSettings()
{
DynamicDataList.SetList(new List<IndexValuePair<string, List<MissionConditionData>>>());
MissionConditionDataList = DynamicDataList.GetList();
gameObject.GetComponent<ConditionManager>().Conditions = SaveMissionConditionManager.ConvertListOfDataModelsToListOfObject(MissionConditionDataList);
// we dont need to convert anything
// Instead of build elements on scene we collect shops distracted on scene from npc's
}
protected override void UseDynamicSettings()
{
// when chest detect player in near arrea and player press "c"
// open panel -> chest controller handle Open panel in Scene Chest Manager passing info about what Chest Palyer want to open
// Manager Build panel and pass info about chest content
LoadDynamicData();
// VERy VERY provisional SOLUTION
if (DynamicDataList.GetList().Count == 0)
{
UseDefaultSettings();
}
MissionConditionDataList = DynamicDataList.GetList();
// map data to model
gameObject.GetComponent<ConditionManager>().Conditions = SaveMissionConditionManager.ConvertListOfDataModelsToListOfObject(MissionConditionDataList);
}
/* public MissionConditionData? GetMissionCondition(MissionCondition newMission)
{
return DynamicDataList.GetList().Where(mission => mission.SpeakerName == newMission.SpeakerName && mission.MissionName == newMission.MissionName).FirstOrDefault();
}*/
public override bool SaveDynamicData()
{
// fill local list by elements from ConditionManager list
MissionConditionDataList.Clear();
MissionConditionDataList = SaveMissionConditionManager.ConvertObjectsListToListOfDataModels(ConditionManager.Instance.Conditions);
return SaveData(MissionConditionDataList, SceneElementTypeEnum.Dynamic);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f16469a3a30fc8f43bec2fb2eeedd293
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
class SaveMissionConditionManager : SaveModelSystem<IndexValuePair<string, List<MissionConditionData>>> // TODO change MissionConditionData
{
public override bool SaveModelItem(IndexValuePair<string, List<MissionConditionData>> model)
{
return base.SaveModelItem(model);
}
public override bool SaveModelList(List<IndexValuePair<string, List<MissionConditionData>>> list)
{
BinaryFormatter formatter = new BinaryFormatter();
Debug.Log("Saved Mision Condition list at " + Path);
if (!Directory.Exists(Path)) Directory.CreateDirectory(Path);
/* Main logic of conversion data format */
var data = list; // ConvertObjectsListToListOfDataModels(list);
FileStream stream = new FileStream(
Path + GetFileName(ObjectListName),
FileMode.Create
);
formatter.Serialize(stream, data);
stream.Close();
return true;
}
public override IndexValuePair<string, List<MissionConditionData>> LoadModelItem()
{
return base.LoadModelItem();
}
public override List<IndexValuePair<string, List<MissionConditionData>>> LoadModelList()
{
string path = Path + GetFileName(ObjectListName);
if (File.Exists(path))
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
List<IndexValuePair<string, List<MissionConditionData>>> missionsList = formatter.Deserialize(stream) as List<IndexValuePair<string, List<MissionConditionData>>>;
stream.Close();
return missionsList; // ConvertListOfDataModelsToListOfObject(questsList);
}
else
{
Debug.Log("Save file not found in " + path);
}
return new List<IndexValuePair<string, List<MissionConditionData>>>();
}
// ----------------- USELLES IN THIS CLASS -----------------
#region unused
// Support function
// 1. From model to data format
public static MissionConditionData ConvertObjectToDataModel(MissionCondition model)
{
return MissionConditionData.Build(model);
}
public static List<IndexValuePair<string, List<MissionConditionData>>> ConvertObjectsListToListOfDataModels(List<IndexValuePair<string, List<MissionCondition>>> modelsList)
{
List<IndexValuePair<string, List<MissionConditionData>>> convertedList = new List<IndexValuePair<string, List<MissionConditionData>>>();
foreach (IndexValuePair<string, List<MissionCondition>> dataModel in modelsList)
{
IndexValuePair<string, List<MissionConditionData>> conditionsForMapList = new IndexValuePair<string, List<MissionConditionData>>(dataModel.Key, new List<MissionConditionData>());
foreach (MissionCondition condition in dataModel.Value)
{
conditionsForMapList.Value.Add(
ConvertObjectToDataModel(condition)
);
}
convertedList.Add(conditionsForMapList);
}
return convertedList;
}
// 2. From data to model format
public static MissionCondition ConvertDataModelToObject(MissionConditionData dataModel)
{
return dataModel.MapDataToObject();
}
public static List<IndexValuePair<string, List<MissionCondition>>> ConvertListOfDataModelsToListOfObject(List<IndexValuePair<string, List<MissionConditionData>>> dataModelsList)
{
List<IndexValuePair<string, List<MissionCondition>>> conditioncConvertedList = new List<IndexValuePair<string, List<MissionCondition>>>();
foreach (IndexValuePair<string, List<MissionConditionData>> dataModel in dataModelsList)
{
IndexValuePair<string, List<MissionCondition>> conditionsForMapList = new IndexValuePair<string, List<MissionCondition>>(dataModel.Key, new List<MissionCondition>());
foreach (MissionConditionData condition in dataModel.Value)
{
conditionsForMapList.Value.Add(
ConvertDataModelToObject(condition)
);
}
conditioncConvertedList.Add(conditionsForMapList);
}
return conditioncConvertedList;
}
#endregion
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2634054ce8ca494fb0c9a5363223117
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class MissionDataListManager : DataListManager<MissionData>
{
// WE DONT NEED HERE UI MANAGER - because dialoges ane;t associated with ui panels in way like inventory / chest or shop
public override void AddElementToList(MissionData newElement)
{
Elements.Add(newElement);
}
public override void RemoveElementFromList(MissionData element)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0869a13ed3dcbe94e9ea9ea5356913a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
class MissionDataLoader : SceneBaseDataLoader<MissionData>
{
public MissionDataLoader(string _objectListName, string _objectFolderName)
{
SaveModelSystem = new SaveMissionManager();
SaveModelSystem.ObjectFolderName = _objectFolderName;
SaveModelSystem.ObjectListName = _objectListName;
}
protected override List<MissionData> LoadDynamicData()
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString();
return SaveModelSystem.LoadModelList();
}
protected override bool SaveDynamicData(List<MissionData> _elements)
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString();
return base.SaveDynamicData(_elements);
}
protected override List<MissionData> LoadGenericData()
{
throw new NotImplementedException();
}
protected override bool SaveGenericData(List<MissionData> _elements)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6f38b619116e96a4fb4f31949ad37365
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
class MissionDataManager : SceneBaseDataManager<MissionData>
{
protected override string OBJECT_FOLDER_NAME { get { return "Mission"; } }
protected override string OBJECT_LIST_NAME { get { return "MissionsList"; } }
[SerializeField]
public List<MissionData> MissionDataList;
public override void Awake()
{
if (Instance == null)
{
Instance = this;
// moved from start beacuse we need to prepare env before NpcMissionmanager start registering and uipdating mission model
Debug.Log("Start Mission manager");
DynamicDataList = new MissionDataListManager();
DataLoader = new MissionDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME);
base.Start(); // (afterStart invoking - to load saved data)
}
else
{
Destroy(gameObject);
}
}
// ZMIANA KONCEPCJI
// ZMIAST TRZYMAC SUROWE OBIEKTY TYM RAZEM ZAPISUJMY modele Datai updatujmy obiket w NPC Managerze
// nadpisujemy by nir duplikowac wywoałania i nadpisyuwanie MissionDataList z Awake
public override void Start()
{
}
protected override void AfterStart()
{
if (OnMapAppearanceMethod.GameStatus == GameStatus.NewGame)
{
if (OnMapAppearanceMethod.Gateway != OnMapAppearanceMethodEnum.NewGame)
UseDynamicSettings(); // if there is nothing saved we will use UseDefaultSettings
else
UseDefaultSettings();
}
else
{
UseDynamicSettings();
}
}
protected SceneBaseDataManager<MissionData> GetObjectType()
{
return GameObject.FindObjectOfType<MissionDataManager>();
}
protected SceneBaseDataManager<MissionData> CreateInstance(ref GameObject managerGameObject)
{
return managerGameObject.AddComponent<MissionDataManager>();
}
protected override void UseDefaultSettings()
{
DynamicDataList.SetList(new List<MissionData>());
MissionDataList = DynamicDataList.GetList();
// we dont need to convert anything
// Instead of build elements on scene we collect shops distracted on scene from npc's
}
protected override void UseDynamicSettings()
{
// when chest detect player in near arrea and player press "c"
// open panel -> chest controller handle Open panel in Scene Chest Manager passing info about what Chest Palyer want to open
// Manager Build panel and pass info about chest content
Debug.Log("UseDynamicSettings");
LoadDynamicData();
// VERy VERY provisional SOLUTION
if (DynamicDataList.GetList().Count == 0)
{
UseDefaultSettings();
}
MissionDataList = DynamicDataList.GetList();
}
public void RegisterMission(Mission newMission)
{
if (DynamicDataList.GetList().Where(mission => mission.SpeakerName == newMission.SpeakerName && mission.MissionName == newMission.MissionName).Any())
{
// if dial is already registered - update it
UpdateMission(newMission);
}
else
{
var misssionData = SaveMissionManager.ConvertObjectToDataModel(newMission);
//DynamicDataList.AddElementToList(multiDialogueData); - nie dodwaca bo modyfikacja jednej duplikuje
MissionDataList.Add(misssionData);
}
}
// update proggress in dialogue - BUT FUNCTION BELOW SYNCH THIS ALREADY righhr???
public void UpdateMission(Mission newMission)
{
if (!DynamicDataList.GetList().Where(mission => mission.SpeakerName == newMission.SpeakerName && mission.MissionName == newMission.MissionName).Any())
Debug.LogError($"There is no registered dialoge like {newMission.SpeakerName}");
else
{
var missionData = SaveMissionManager.ConvertObjectToDataModel(newMission);
MissionDataList.RemoveAll(mission => mission.SpeakerName == newMission.SpeakerName && mission.MissionName == newMission.MissionName);
// duplicated from registerDialogue
MissionDataList.Add(missionData);
}
}
public MissionData? GetMission(Mission newMission)
{
return DynamicDataList.GetList().Where(mission => mission.SpeakerName == newMission.SpeakerName && mission.MissionName == newMission.MissionName).FirstOrDefault();
}
public override bool SaveDynamicData()
{
return SaveData(MissionDataList, SceneElementTypeEnum.Dynamic);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1278ade00000f84ba28d4671ff3f7f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,14 +4,14 @@ using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
class SaveMissionManager : SaveModelSystem<Mission>
class SaveMissionManager : SaveModelSystem<MissionData>
{
public override bool SaveModelItem(Mission model)
public override bool SaveModelItem(MissionData model)
{
return base.SaveModelItem(model);
}
public override bool SaveModelList(List<Mission> list)
public override bool SaveModelList(List<MissionData> list)
{
BinaryFormatter formatter = new BinaryFormatter();
@ -20,7 +20,7 @@ class SaveMissionManager : SaveModelSystem<Mission>
if (!Directory.Exists(Path)) Directory.CreateDirectory(Path);
/* Main logic of conversion data format */
var data = ConvertObjectsListToListOfDataModels(list);
var data = list; // ConvertObjectsListToListOfDataModels(list);
FileStream stream = new FileStream(
Path + GetFileName(ObjectListName),
@ -33,12 +33,12 @@ class SaveMissionManager : SaveModelSystem<Mission>
return true;
}
public override Mission LoadModelItem()
public override MissionData LoadModelItem()
{
return base.LoadModelItem();
}
public override List<Mission> LoadModelList()
public override List<MissionData> LoadModelList()
{
string path = Path + GetFileName(ObjectListName);
@ -47,25 +47,27 @@ class SaveMissionManager : SaveModelSystem<Mission>
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
List<MissionData> questsList = formatter.Deserialize(stream) as List<MissionData>;
List<MissionData> missionsList = formatter.Deserialize(stream) as List<MissionData>;
stream.Close();
return ConvertListOfDataModelsToListOfObject(questsList);
return missionsList; // ConvertListOfDataModelsToListOfObject(questsList);
}
else
{
Debug.Log("Save file not found in " + path);
}
return new List<Mission>();
return new List<MissionData>();
}
// ----------------- USELLES IN THIS CLASS -----------------
#region unused
// Support function
// 1. From model to data format
public static MissionData ConvertObjectToDataModel(Mission model)
{
return new MissionData(); //model
return new MissionData(model);
}
public static List<MissionData> ConvertObjectsListToListOfDataModels(List<Mission> modelsList)
@ -97,4 +99,5 @@ class SaveMissionManager : SaveModelSystem<Mission>
return convertedList;
}
#endregion
}

View File

@ -31,8 +31,10 @@ public class PlayerActions : MonoBehaviour
Debug.Log($"Give reward - {reward.Cash}");
// 3. Save changes
GameObject.FindObjectOfType<SaveController>().SavePlayerEquipmentItems();
GameObject.FindObjectOfType<SaveController>().SavePlayerInventory();
GameObject.FindObjectOfType<SaveController>().SaveAccountBalance();
// TODO - sync saving process reward / mission proggress
// currently its saving only after changing scene and saving manually by player
//GameObject.FindObjectOfType<SaveController>().SavePlayerEquipmentItems();
//GameObject.FindObjectOfType<SaveController>().SavePlayerInventory();
//GameObject.FindObjectOfType<SaveController>().SaveAccountBalance();
}
}

View File

@ -154,7 +154,6 @@ public abstract class SceneBaseDataManager<T> : MonoBehaviour
// approach:
// 1. get from outside, update local list && us it
// 2. Handle list synchronized all the time & pass local list
Debug.Log(DynamicDataList.GetList());
return SaveData(DynamicDataList.GetList(), SceneElementTypeEnum.Dynamic);
}
#endregion

View File

@ -57,15 +57,15 @@ public abstract class DraggablePanelController : PanelController<IndexValuePair<
return;
DraggedSlotController.Instance.RemoveDraggedSlot();
// Rebuild/apply UiManager content (list of items) base on slots values after its updating
for (int i = 0; i < ChildBoxList.Count; i++)
{
if (ChildBoxList[i].Item != null)
if (ChildBoxList[i].Item != null)
{
UiManager.Add(new IndexValuePair<int, EquippableItem>(i, ChildBoxList[i].Item));
}
else
else
{
UiManager.RemoveByPosition(i);
}
@ -86,9 +86,9 @@ public abstract class DraggablePanelController : PanelController<IndexValuePair<
// TODO insert child criterials
//draggedSlot.Item = (EquippableItem)new Item("test", "test desc", 1, null, null);
EquippableItem tmpDraggedItem = draggedSlot.Item == null ? null : new EquippableItem(draggedSlot.Item); // InventoryUIManager.Instance.DraggedSlot.Item; // remember temporary currently dragged item
UiManager.Add(new IndexValuePair<int, EquippableItem>(dropItemSlot.Number, tmpDraggedItem));
// !!! remember item from dropped position to future operation !!!

View File

@ -28,7 +28,6 @@ public abstract class WarehousePanelController : DraggablePanelController
public override void DoubleLeftMouseClick(ItemSlot itemSlot)
{
Debug.Log("Used item");
if(AllowToUseItemInPanel)
{
ItemEffectsManager.Instance.UseItemEffect(itemSlot, Type);

View File

@ -219,7 +219,6 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
public void Add(T model)
{
// throw new System.NotImplementedException();
Elements.Add(model);
UpdateList();

View File

@ -59,7 +59,11 @@ public abstract class UIWarehouseManager : UISlotPanelManager<IndexValuePair<int
public virtual void Add(EquippableItem item)
{
if(IsFull())
throw new System.Exception($"Warehouse is full!!!");
{
Debug.Log($"Warehouse is full!");
return;
}
// find first empty position / slot
var max = 0;

View File

@ -1,5 +1,5 @@

interface IModelMapper<T>
public interface IModelMapper<T>
{
public abstract T MapDataToObject(string prefarbAssetName);

View File

@ -89,8 +89,8 @@ public class EquipmentUIManager : UIWarehouseManager
if (!CheckIfSlotExists(keyPosition))
return; // throw new System.Exception($"Slot with number: {keyPosition} don't exist");
Debug.Log($"Remove from position: {keyPosition}");
/* Debug.Log($"Remove from position: {keyPosition}");
*/
Elements.RemoveAll(equipment => equipment.Key == keyPosition);
Elements.Add(new IndexValuePair<int, EquippableItem>(keyPosition, null));

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1da99894524baa749b93f9f38ff2acac
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[Serializable]
public class CollectMissionConditionData : MissionConditionData
{
public CollectMissionConditionData(MissionCondition missionCondition) : base(missionCondition.Type)
{
RequiredElements.Clear();
foreach (RequiredSubject requiredSubject in missionCondition.RequiredElements)
{
RequiredElements.Add(new CollectRequiredSubjectData((CollectRequiredSubject)requiredSubject));
}
}
public override MissionCondition MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();
}
public override MissionCondition MapDataToObject()
{
var mappedCondition = new MissionCondition(Type);
foreach(var requiredElement in RequiredElements)
{
mappedCondition.RequiredElements.Add(requiredElement.MapDataToObject());
}
return mappedCondition;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 81b8d315cf1ee3444b5630663cf64616
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
public class KillMissionConditionData : MissionConditionData
{
public KillMissionConditionData(MissionCondition missionCondition) : base(missionCondition.Type)
{
RequiredElements.Clear();
foreach (RequiredSubject requiredSubject in missionCondition.RequiredElements)
{
/* var abc = new KillRequiredSubjectData((KillRequiredSubject)requiredSubject);
var converter = TypeDescriptor.GetConverter(typeof(KillRequiredSubjectData));
var def = converter.ConvertFrom(abc);
Debug.Log(def);*/
RequiredElements.Add(new KillRequiredSubjectData((KillRequiredSubject)requiredSubject));
}
}
public override MissionCondition MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();
}
public override MissionCondition MapDataToObject()
{
var mappedCondition = new MissionCondition(Type);
foreach (var requiredElement in RequiredElements)
{
mappedCondition.RequiredElements.Add(requiredElement.MapDataToObject());
}
return mappedCondition;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0fa8be7390fbc1a4dad8aee8ac024e06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
//abstract - changed for Unity Inspector visualisation requirements
public class MissionConditionData : IModelMapper<MissionCondition>
{
[SerializeField]
public MissionTypeEnum Type;
[SerializeField]
public List<RequiredSubjectData> RequiredElements = new List<RequiredSubjectData>();
/// <summary>
/// Constructor implemented to create object in children classes in main purpose
///
/// We DON'T implement 'RequiredElements' list here because its MUST be FILLED by objects in specific subtyped (not base one) !!!
/// </summary>
/// <param name="type"></param>
protected MissionConditionData(MissionTypeEnum type)
{
Type = type;
}
// abstract
public virtual MissionCondition MapDataToObject(string prefarbAssetName) { return new MissionCondition(Type); }
// abstract
public virtual MissionCondition MapDataToObject() { return new MissionCondition(Type); }
/// <summary>
/// Function copied from MissionCondition::Build()
/// </summary>
//public abstract MissionConditionData<T, V, E> Build(T missionCondition);
//
public static MissionConditionData Build(MissionCondition missionCondition)
{
switch (missionCondition.Type)
{
case MissionTypeEnum.Kill:
{
Debug.Log("Build - KillMissionCondionData");
return new KillMissionConditionData(missionCondition);
}
case MissionTypeEnum.Collect:
{
Debug.Log("Build - CollectMissionConditionData");
return new CollectMissionConditionData(missionCondition);
}
default:
{
throw new NotImplementedException("Mission Collection data - constructor");
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 572ebb9d86c6e3942bfb6c32249af4db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,7 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
class MissionDialogueData : DialogueData<MissionDialogue>
[Serializable]
public class MissionDialogueData : DialogueData<MissionDialogue>
{
/// <summary>
/// build Data model based on Object
@ -24,6 +25,5 @@ class MissionDialogueData : DialogueData<MissionDialogue>
DialogueStepModelDataList.Add(new DialogueStepData(dialogueStepModelData.WasDisplayed));
}
}
}

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class MissionDialogueStepData
{
}

View File

@ -6,8 +6,14 @@ using System.Threading.Tasks;
using UnityEngine;
[Serializable]
class MissionData : ModelData<Mission>
public class MissionData : IModelMapper<Mission>
{
[SerializeField]
public string MissionName;
[SerializeField]
public string SpeakerName;
[SerializeField]
public MissionStatusEnum Status = MissionStatusEnum.None;
@ -17,18 +23,41 @@ class MissionData : ModelData<Mission>
[SerializeField]
public List<MissionStepData> MissionStepsDataList = new List<MissionStepData>();
public override Mission MapDataToObject(string prefarbAssetName)
/// <summary>
/// build Data model based on Object
/// </summary>
/// <param name="dialogue"></param>
public MissionData(Mission mission)
{
MissionName = mission.MissionName;
SpeakerName = mission.SpeakerName;
Status = mission.Status;
CurrentStep = mission.CurrentStep;
MissionStepsDataList.Clear();
foreach (MissionStepModel missionStepModelData in mission.MissionStepsList)
{
/*
* pass WasDisplayed value from model to data representative class
*/
MissionStepsDataList.Add(new MissionStepData(missionStepModelData));
}
}
#region NotImplemented
/*
* we dont want to map it here, we will mark fields in NpcDialogfeManager after each loading and fetching dialogue
*/
public Mission MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();
}
public override Mission MapDataToObject()
{
throw new NotImplementedException();
}
protected override Mission TryFindResource(string modelName)
public Mission MapDataToObject()
{
throw new NotImplementedException();
}
#endregion
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 726174bbf90a7ed44808fa10277f88bd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
public class CollectRequiredSubjectData : RequiredSubjectData
{
protected override string MODEL_LOCALIZATION => "Items/";
public CollectRequiredSubjectData(int requiredAmount) : base(requiredAmount) { }
public CollectRequiredSubjectData(int requiredAmount, string requiredObjectName) : base(requiredAmount, requiredObjectName) { }
public CollectRequiredSubjectData(CollectRequiredSubject requiredSubject) : base(requiredSubject) { }
public override RequiredSubject MapDataToObject(string prefarbAssetName)
{
var newCollectRequirement = new CollectRequiredSubject(RequiredAmount);
newCollectRequirement.RequiredObject = newCollectRequirement.FindObjectInResource(prefarbAssetName);
return newCollectRequirement;
}
public override RequiredSubject MapDataToObject()
{
return new CollectRequiredSubject(RequiredAmount, RequiredObjectName);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ed2e7fa34b0c2948aa8c87d1fafc0ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
/*[TypeConverter(typeof(KillRequiredSubjectDataTypeConverter))]
*/public class KillRequiredSubjectData : RequiredSubjectData
{
protected override string MODEL_LOCALIZATION => "Enemies/";
[SerializeField]
public int CurrentAmount = 0;
public KillRequiredSubjectData(int requiredAmount, string requiredObjectName) : base(requiredAmount, requiredObjectName) { }
public KillRequiredSubjectData(int requiredAmount, string requiredObjectName, int currentAmount) : base(requiredAmount, requiredObjectName)
{
CurrentAmount = currentAmount;
}
public KillRequiredSubjectData(int requiredAmount, int currentAmount) : base(requiredAmount) { CurrentAmount = currentAmount; }
public KillRequiredSubjectData(KillRequiredSubject requiredSubject) : base(requiredSubject) { CurrentAmount = requiredSubject.CurrentAmount; }
public override RequiredSubject MapDataToObject(string prefarbAssetName)
{
var newKillRequirement = new KillRequiredSubject(RequiredAmount, CurrentAmount);
newKillRequirement.RequiredObject = newKillRequirement.FindObjectInResource(prefarbAssetName);
return newKillRequirement;
}
public override RequiredSubject MapDataToObject()
{
return new KillRequiredSubject(RequiredAmount, RequiredObjectName, CurrentAmount);
}
}
/*[TypeConverter(typeof(KillRequiredSubjectDataTypeConverter))]
public class KillRequiredSubjectDataTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(RequiredSubjectData<RequiredSubject>) || base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var castedFrom = value as RequiredSubjectData<RequiredSubject>;
return castedFrom != null
? new KillRequiredSubjectData(castedFrom.RequiredAmount, castedFrom.RequiredObjectName)
: base.ConvertFrom(context, culture, value)
;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
var castedTo = value as KillRequiredSubjectData;
return destinationType == typeof(RequiredSubjectData<RequiredSubject>) && castedTo != null
? new RequiredSubjectData<RequiredSubject>(castedTo.RequiredAmount, castedTo.RequiredObjectName)
: base.ConvertTo(context, culture, value, destinationType)
;
}
}*/

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f1f1d299662039c4eaf78d604b8c76bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
//abstract - changed for Unity Inspector visualisation requirements
public class RequiredSubjectData : IModelMapper<RequiredSubject>
{
protected virtual string SPRITE_LOCALIZATION => "Sprites/Object Sprites/";
protected virtual string MODEL_LOCALIZATION => "";
[SerializeField]
public int RequiredAmount;
[SerializeField]
public string RequiredObjectName;
public RequiredSubjectData(int requiredAmount)
{
RequiredAmount = requiredAmount;
}
public RequiredSubjectData(int requiredAmount, string requiredObjectName)
{
RequiredAmount = requiredAmount;
RequiredObjectName = requiredObjectName;
}
public RequiredSubjectData(RequiredSubject requiredSubject)
{
RequiredAmount = requiredSubject.RequiredAmount;
RequiredObjectName = requiredSubject.RequiredObject.name; // NAME of the PREFAB
}
// abstract
public virtual RequiredSubject MapDataToObject(string prefarbAssetName) { return new RequiredSubject(0); } // { return new RequiredSubject(RequiredAmount, RequiredObjectName); }
// abstarct
public virtual RequiredSubject MapDataToObject() { return new RequiredSubject(0); } // { return new RequiredSubject(RequiredAmount, RequiredObjectName); }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3af6b21b3495e5742ab61a3a61e8854f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,14 +3,24 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
class MissionStepData : IModelMapper<MissionStepModel>
[Serializable]
public class MissionStepData : IModelMapper<MissionStepModel>
{
MissionStepStatusEnum Status;
[SerializeField]
public MissionStepStatusEnum Status;
MissionDialogueData MissionDialogueData;
[SerializeField]
public MissionDialogueData MissionDialogueData;
public MissionStepData(MissionStepModel missionStepModel)
{
Status = missionStepModel.Status;
MissionDialogueData = new MissionDialogueData(missionStepModel.DialogueStep);
}
public MissionStepModel MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();

View File

@ -74,4 +74,13 @@ public class SaveController : MonoBehaviour
if (MultiDialogueDataManager.Instance)
MultiDialogueDataManager.Instance.SaveDynamicData();
}
public void SaveMissions()
{
if (MissionDataManager.Instance ) //&& MissionConditionDataManager.Instance
{
MissionDataManager.Instance.SaveDynamicData();
MissionConditionDataManager.Instance.SaveDynamicData();
}
}
}