Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 6a03666

Browse files
committed
Item conditions and effects. Tak log on game progress.
1 parent 300fe34 commit 6a03666

7 files changed

Lines changed: 336 additions & 9 deletions

File tree

Diplomata/Editor/Diplomata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Diplomata : ScriptableObject {
1717

1818
public static void Instantiate() {
1919
if (DiplomataLib.Diplomata.instance == null && FindObjectsOfType<DiplomataLib.Diplomata>().Length < 1) {
20-
GameObject obj = new GameObject("[ Diplomata ]");
20+
GameObject obj = new GameObject("[Diplomata]");
2121
obj.AddComponent<DiplomataLib.Diplomata>();
2222
}
2323

Diplomata/Editor/MessagesEditor.cs

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ public static void Main() {
292292
case Effect.Type.SetAnimatorAttribute:
293293
text += effect.DisplaySetAnimatorAttribute();
294294
break;
295+
case Effect.Type.GetItem:
296+
var itemName = "";
297+
if (Item.Find(diplomataEditor.inventory.items, effect.itemId) != null) {
298+
itemName = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, effect.itemId).name,
299+
diplomataEditor.preferences.currentLanguage).value;
300+
}
301+
text += effect.DisplayGetItem(itemName);
302+
break;
303+
case Effect.Type.DiscardItem:
304+
var discardItemName = "";
305+
if (Item.Find(diplomataEditor.inventory.items, effect.itemId) != null) {
306+
discardItemName = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, effect.itemId).name,
307+
diplomataEditor.preferences.currentLanguage).value;
308+
}
309+
text += effect.DisplayDiscardItem(discardItemName);
310+
break;
295311
}
296312

297313
if (k < currentMessage.effects.Length - 1) {
@@ -328,10 +344,10 @@ public static void Main() {
328344
DGUI.labelStyle.alignment = TextAnchor.UpperLeft;
329345
}
330346

331-
if (GUI.GetNameOfFocusedControl() == "title" + currentMessage.id ||
347+
/*if (GUI.GetNameOfFocusedControl() == "title" + currentMessage.id ||
332348
GUI.GetNameOfFocusedControl() == "content" + currentMessage.id) {
333349
SetMessage(currentMessage);
334-
}
350+
}*/
335351

336352
if (GUI.Button(boxRect, "", buttonStyle)) {
337353
SetMessage(currentMessage);
@@ -414,7 +430,7 @@ public static void Sidebar() {
414430
GUILayout.Label("Message Color:");
415431
message.color = EditorGUILayout.ColorField(message.color);
416432

417-
EditorGUILayout.Separator(); // <- Layout bug here
433+
EditorGUILayout.Separator();
418434

419435
var disposable = message.disposable;
420436
var isAChoice = message.isAChoice;
@@ -989,6 +1005,62 @@ public static void Sidebar() {
9891005
GUILayout.EndHorizontal();
9901006

9911007
break;
1008+
1009+
case Effect.Type.GetItem:
1010+
GUILayout.BeginHorizontal();
1011+
UpdateItemList();
1012+
1013+
var itemName = "";
1014+
1015+
if (itemList.Length > 0) {
1016+
itemName = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, effect.itemId).name, diplomataEditor.preferences.currentLanguage).value;
1017+
}
1018+
1019+
EditorGUI.BeginChangeCheck();
1020+
1021+
itemName = DGUI.Popup("Get item ", itemName, itemList);
1022+
1023+
if (EditorGUI.EndChangeCheck()) {
1024+
foreach (Item item in diplomataEditor.inventory.items) {
1025+
1026+
if (DictHandler.ContainsKey(item.name, diplomataEditor.preferences.currentLanguage).value == itemName) {
1027+
effect.itemId = item.id;
1028+
break;
1029+
}
1030+
1031+
}
1032+
}
1033+
1034+
GUILayout.EndHorizontal();
1035+
break;
1036+
1037+
case Effect.Type.DiscardItem:
1038+
GUILayout.BeginHorizontal();
1039+
UpdateItemList();
1040+
1041+
var discardItemName = "";
1042+
1043+
if (itemList.Length > 0) {
1044+
discardItemName = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, effect.itemId).name, diplomataEditor.preferences.currentLanguage).value;
1045+
}
1046+
1047+
EditorGUI.BeginChangeCheck();
1048+
1049+
discardItemName = DGUI.Popup("Discard item ", discardItemName, itemList);
1050+
1051+
if (EditorGUI.EndChangeCheck()) {
1052+
foreach (Item item in diplomataEditor.inventory.items) {
1053+
1054+
if (DictHandler.ContainsKey(item.name, diplomataEditor.preferences.currentLanguage).value == discardItemName) {
1055+
effect.itemId = item.id;
1056+
break;
1057+
}
1058+
1059+
}
1060+
}
1061+
1062+
GUILayout.EndHorizontal();
1063+
break;
9921064
}
9931065

9941066
if (GUILayout.Button("Delete Effect", GUILayout.Height(DGUI.BUTTON_HEIGHT_SMALL))) {

Diplomata/Lib/DiplomataCharacter.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,27 @@ private void Next(bool hasFate) {
153153
if (character.influence >= condition.comparedInfluence) {
154154
condition.proceed = false;
155155
}
156+
break;
157+
case Condition.Type.HasItem:
158+
var item = Item.Find(Diplomata.inventory.items, condition.itemId);
159+
160+
if (item != null) {
161+
162+
if (item.have) {
163+
condition.proceed = true;
164+
}
165+
166+
else {
167+
condition.proceed = false;
168+
}
169+
170+
}
171+
172+
else {
173+
Debug.LogWarning("Cannot find the item with id " + condition.itemId + " to check.");
174+
condition.proceed = false;
175+
}
176+
156177
break;
157178
}
158179

@@ -242,6 +263,15 @@ public string ShowMessageContentSubtitle() {
242263

243264
if (talking) {
244265
if (currentMessage != null) {
266+
var talkLog = TalkLog.Find(Diplomata.gameProgress.talkLog, character.name);
267+
268+
if (talkLog == null) {
269+
Diplomata.gameProgress.talkLog = ArrayHandler.Add(Diplomata.gameProgress.talkLog, new TalkLog(character.name));
270+
talkLog = TalkLog.Find(Diplomata.gameProgress.talkLog, character.name);
271+
}
272+
273+
talkLog.messagesIds = ArrayHandler.Add(talkLog.messagesIds, (uint) currentMessage.id);
274+
245275
return DictHandler.ContainsKey(currentMessage.content, Diplomata.gameProgress.options.currentSubtitledLanguage).value;
246276
}
247277

@@ -446,6 +476,32 @@ public void NextMessage() {
446476
Debug.LogWarning("You have a animation attributes setter effect in this message, but the game object don't have a Animator.");
447477
}
448478

479+
break;
480+
481+
case Effect.Type.GetItem:
482+
var getItem = Item.Find(Diplomata.inventory.items, effect.itemId);
483+
484+
if (getItem != null) {
485+
getItem.have = true;
486+
}
487+
488+
else {
489+
Debug.LogError("Cannot find the item with id " + effect.itemId + " to get.");
490+
}
491+
492+
break;
493+
494+
case Effect.Type.DiscardItem:
495+
var discardItem = Item.Find(Diplomata.inventory.items, effect.itemId);
496+
497+
if (discardItem != null) {
498+
discardItem.discarded = true;
499+
}
500+
501+
else {
502+
Debug.LogError("Cannot find the item with id " + effect.itemId + " to discard.");
503+
}
504+
449505
break;
450506
}
451507

Diplomata/Lib/Effect.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Effect {
99
public EndOfContext endOfContext;
1010
public GoTo goTo;
1111
public AnimatorAttributeSetter animatorAttributeSetter = new AnimatorAttributeSetter();
12+
public int itemId;
1213

1314
[System.NonSerialized]
1415
public Events onStart = new Events();
@@ -21,7 +22,8 @@ public enum Type {
2122
EndOfContext,
2223
GoTo,
2324
SetAnimatorAttribute,
24-
GetItem
25+
GetItem,
26+
DiscardItem
2527
}
2628

2729
[System.Serializable]
@@ -104,6 +106,14 @@ public string DisplaySetAnimatorAttribute() {
104106
return "Animator attribute setter not found.";
105107
}
106108
}
109+
110+
public string DisplayGetItem(string itemName) {
111+
return "Get the item: " + itemName;
112+
}
113+
114+
public string DisplayDiscardItem(string itemName) {
115+
return "Discard the item: " + itemName;
116+
}
107117
}
108118

109119
}

Diplomata/Lib/GameProgress.cs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,34 @@ public Options() {
2828
}
2929
}
3030

31+
[Serializable]
32+
public class TalkLog {
33+
public string characterName;
34+
public uint[] messagesIds = new uint[0];
35+
36+
public TalkLog() { }
37+
38+
public TalkLog(string characterName) {
39+
this.characterName = characterName;
40+
}
41+
42+
public static TalkLog Find(TalkLog[] array, string characterName) {
43+
foreach (TalkLog talkLog in array) {
44+
if (talkLog.characterName == characterName) {
45+
return talkLog;
46+
}
47+
}
48+
49+
return null;
50+
}
51+
}
52+
3153
[Serializable]
3254
public class CharacterProgress {
3355
public string name;
3456
public byte influence;
3557
public ContextProgress[] contexts = new ContextProgress[0];
36-
58+
3759
public CharacterProgress() { }
3860

3961
public CharacterProgress(string name, byte influence) {
@@ -81,6 +103,21 @@ public MessageProgress(int id, bool alreadySpoked) {
81103
}
82104
}
83105

106+
[Serializable]
107+
public class ItemProgress {
108+
public uint id;
109+
public bool have;
110+
public bool discarded;
111+
112+
public ItemProgress() { }
113+
114+
public ItemProgress(int id, bool have, bool discarded) {
115+
this.id = (uint)id;
116+
this.have = have;
117+
this.discarded = discarded;
118+
}
119+
}
120+
84121
public enum Method {
85122
XML,
86123
JSON
@@ -91,10 +128,13 @@ public class GameProgress {
91128

92129
public Options options;
93130
public CharacterProgress[] characters = new CharacterProgress[0];
131+
public ItemProgress[] inventory = new ItemProgress[0];
132+
public TalkLog[] talkLog = new TalkLog[0];
94133

95134
public void Start() {
96135
options = new Options();
97136
SaveCharacters();
137+
SaveInventory();
98138
}
99139

100140
public void SaveCharacters() {
@@ -144,6 +184,22 @@ public void LoadCharacters() {
144184
}
145185
}
146186

187+
public void SaveInventory() {
188+
inventory = new ItemProgress[0];
189+
190+
foreach (Item item in Diplomata.inventory.items) {
191+
inventory = ArrayHandler.Add(inventory, new ItemProgress(item.id, item.have, item.discarded));
192+
}
193+
}
194+
195+
public void LoadInventory() {
196+
foreach (ItemProgress item in inventory) {
197+
var itemTemp = Item.Find(Diplomata.inventory.items, (int) item.id);
198+
itemTemp.have = item.have;
199+
itemTemp.discarded = item.discarded;
200+
}
201+
}
202+
147203
public string Serialize(Method method) {
148204
switch (method) {
149205
case Method.JSON:
@@ -189,6 +245,7 @@ public void Save(string extension = ".sav") {
189245
BinaryFormatter binaryFormatter = new BinaryFormatter();
190246

191247
SaveCharacters();
248+
SaveInventory();
192249

193250
using (FileStream fileStream = new FileStream(Application.persistentDataPath + "/diplomata_gameProgress" + extension, FileMode.Create)) {
194251
binaryFormatter.Serialize(fileStream, Diplomata.gameProgress);
@@ -203,6 +260,7 @@ public void Load(string extension = ".sav") {
203260
}
204261

205262
LoadCharacters();
263+
LoadInventory();
206264
}
207265

208266
public IEnumerator SaveWeb(string url, string extension = ".sav") {

Diplomata/Lib/Inventory.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public class Item {
1515
[System.NonSerialized]
1616
public bool have;
1717

18-
[System.NonSerialized]
19-
public bool used;
20-
2118
[System.NonSerialized]
2219
public bool discarded;
2320

0 commit comments

Comments
 (0)