/
GameSave.cs
625 lines (534 loc) · 18.7 KB
/
GameSave.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
using System;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
[Serializable]
public class GameSave
{
#region Saved Data
public static GameSave SavedData
{
get
{
if (savedData == null)
savedData = Load();
return savedData;
}
set
{
savedData = value;
}
}
private static GameSave savedData;
static string SaveName
{
get
{
if (MetaGameController.instance == null) return keyName;
int saveNum = MetaGameController.instance.saveNumber;
#if !UNITY_EDITOR
saveNum = 0;
#endif
return saveNum == 0 ? keyName : string.Concat(keyName, saveNum.ToString());
}
}
public const string keyName = "PlayerSave";
#endregion
#region Props
/// <summary>лучший результат за все время</summary>
public int bestLevel;
/// <summary>лучший результат за все время</summary>
public int bestDayLevel;
/// <summary>текущий день</summary>
public int day;
/// <summary>результат за прошлый раз</summary>
public int deathLevel;
/// <summary>текущее количество маны в игре</summary>
public int starCount;
/// <summary>сколько есть бесплатных бустеров</summary>
public int deleteBoosterFreeCount;
/// <summary>сколько есть бесплатных бустеров</summary>
public int doubleBoosterFreeCount;
/// <summary>текущий уровень в игре</summary>
public int turnCount;
/// <summary>текущее кол-во мячей в игре</summary>
public int ballCount;
/// <summary>использовал ли игрок бустеры в игре</summary>
public bool boostersUsed;
public GameItem[] itemList;
public int metaStarsCount;
public int ticketsCount;
/// <summary>список открытых драконов</summary>
public List<DragonSaveView> openedDragons;
/// <summary>текущий дракон</summary>
public DragonType selectedDragon;
public int campaignLevelsCompleted;
public int lastCollectedStarsWaveNumber;
public int additionalCampaignLevelsCompleted;
public bool tutorialCompleted;
public Achievements achievements;
public MagicalCaveProgress caveProgress;
public LocalizationLanguage gameLanguage;
public bool adsRemoved;
public List<MetaBuilderQuestSave> completedQuests;
public List<MetaBuilderFxSave> savedEffects;
public List<MetaBuilderCollectionSave> savedCollections;
public List<int> avaliableEffects;
public List<int> avaliableCollections;
public List<MetaBuilderQuestsPrizeProgressSave> colletedMetaQuestPrizes;
public int currentEffectPrizeNumber;
public int currentCollectionPrizeNumber;
public int currentFortuneRingRotationNumber;
public List<ItemType> shownItems;
/// <summary>было ли показано игроку окно с предложением поставить игре оценку</summary>
public bool PlayerRatedTheGame;
public long lastTimeRateWindowShowed;
public bool playerUnlockedPremiumPet;
#endregion
#region Sound And Music
public bool soundIsOn;
public bool musicIsOn;
#endregion
#region Meta Data
public long firstLaunchTime;
public long lastTimeSixHoursCollected;
public bool bonusLevelTipShowed;
public long lastTimeDailyBonusCollected;
public int dailyBonusGiftNumber;
public bool fortuneRingFreeRotationUsed;
public int nextSixHoursPrizeAmount;
public bool caveUIHighlighted;
public long lastTimeBonusLevelCompleted;
public int timesAdditionalPlayed;
public int timesCavePlayed;
public long lastTimeGatchaFreeSpin;
public int playerBannerAdsCohort;
#endregion
#region Notification
public List<NotificationInformation> notifications;
public long lastNotificationTimeAppeared;
#endregion
#region Modifiers
public List<Modifier> AppliedModifiers;
#endregion
#region Meta Tutorial
public bool HavePlayerCompletedMetaTutorial(MetaTutorialType mType)
{
return completedMetaTutorials.Contains(mType);
}
public void CompleteMetaTutorial(MetaTutorialType mType)
{
if (!completedMetaTutorials.Contains(mType))
{
completedMetaTutorials.Add(mType);
Save(this);
}
}
public List<MetaTutorialType> completedMetaTutorials;
public List<LittleTutorialType> littleTutorialsPassed;
public enum MetaTutorialType
{
BuildingTutorial,
ChangeAppearanceTutorial,
CaveFirstTutorial,
CavePrizeTutorial,
FortuneRingTutorial,
PetTutorial,
EffectsTutorial,
SixHourBonusTutorial,
BonusLevelsTutorial,
DragonWindowTutorial,
PremiumBuildingTutorial,
PremiumPetTutorial,
PremiumPetFirstDialogMapTutorial,
PremiumPetSecondDialogMapTutorial,
RateAppWindowFirstTime,
EggPrizeQuestTutotial,
Level3ShowQuestsMenuTutorial
}
public List<DragonBonusType> usedDragons;
#endregion
#region statistics
/// <summary>сколько потратили маны за всю игру</summary>
public int starsSpent;
/// <summary>максимальное число ударов на мяч за всю игру</summary>
public float maxReboundPerBall;
/// <summary>сколько раз зачистили все поле</summary>
public int allClearTimes;
#endregion
#region Save-Load
public static GameSave Load()
{
var jsonStr = PlayerPrefs.GetString(SaveName, string.Empty);
var result = JsonUtility.FromJson<GameSave>(jsonStr);
if (null == result)
{
result = GetEmpty();
}
if (result.itemList == null) result.itemList = new GameItem[] { };
savedData = result;
return result;
}
public static GameSave GetEmpty()
{
GameSave save = new GameSave()
{
bestLevel = 1,
day = 0,
bestDayLevel = 1,
deathLevel = 1,
starCount = 0,
metaStarsCount = 0,
ticketsCount = 0,
deleteBoosterFreeCount = 1,
doubleBoosterFreeCount = 1,
turnCount = 1,
ballCount = 1,
campaignLevelsCompleted = 0,
additionalCampaignLevelsCompleted = 0,
boostersUsed = false,
tutorialCompleted = false,
completedMetaTutorials = new List<MetaTutorialType>(),
achievements = new Achievements(),
caveProgress = new MagicalCaveProgress(),
openedDragons = new List<DragonSaveView>(),
completedQuests = new List<MetaBuilderQuestSave>(),
savedEffects = new List<MetaBuilderFxSave>(),
savedCollections = new List<MetaBuilderCollectionSave>(),
avaliableEffects = new List<int>(),
avaliableCollections = new List<int>(),
colletedMetaQuestPrizes = new List<MetaBuilderQuestsPrizeProgressSave>(),
shownItems = new List<ItemType>(),
littleTutorialsPassed = new List<LittleTutorialType>(),
AppliedModifiers = new List<Modifier>(),
musicIsOn = true,
soundIsOn = true,
currentEffectPrizeNumber = 0,
currentCollectionPrizeNumber = 0,
notifications = new List<NotificationInformation>(),
firstLaunchTime = DateTime.Now.ToFileTime(),
playerBannerAdsCohort = 2,
usedDragons = new List<DragonBonusType>()
};
save.gameLanguage = Localizator.GetSystemLanguage();
if (MetaGameController.instance != null)
MetaGameController.instance.achievementController.ResetData();
save.openedDragons.Add(new DragonSaveView(DragonType.DragonOne));
return save;
}
public static void SaveGameOver(GameSave saveData)
{
var current = Load();
current.deathLevel = saveData.deathLevel;
current.bestLevel = Mathf.Max(saveData.deathLevel, current.bestLevel);
var currentDay = DateTime.Today.DayOfYear;
if (currentDay == current.day)
current.bestDayLevel = Mathf.Max(saveData.deathLevel, current.bestDayLevel);
else
{
current.day = currentDay;
current.bestDayLevel = saveData.deathLevel;
}
current.boostersUsed = false;
current.deleteBoosterFreeCount = saveData.deleteBoosterFreeCount;
current.doubleBoosterFreeCount = saveData.doubleBoosterFreeCount;
current.starsSpent = saveData.starCount;
current.turnCount = 1;
current.ballCount = 1;
current.itemList = new GameItem[] { };
var jsonStr = JsonUtility.ToJson(current);
PlayerPrefs.SetString(SaveName, jsonStr);
}
public static void SaveMetaGameOver(GameSave saveData)
{
var current = Load();
current.deathLevel = saveData.deathLevel;
current.bestLevel = Mathf.Max(saveData.deathLevel, current.bestLevel);
var currentDay = DateTime.Today.DayOfYear;
if (currentDay == current.day)
current.bestDayLevel = Mathf.Max(saveData.deathLevel, current.bestDayLevel);
else
{
current.day = currentDay;
current.bestDayLevel = saveData.deathLevel;
}
current.boostersUsed = false;
current.deleteBoosterFreeCount = saveData.deleteBoosterFreeCount;
current.doubleBoosterFreeCount = saveData.doubleBoosterFreeCount;
current.starsSpent = saveData.starCount;
var jsonStr = JsonUtility.ToJson(current);
PlayerPrefs.SetString(SaveName, jsonStr);
}
public static void Save(GameController game)
{
var current = SavedData;
current.starCount = game.data.starCount;
current.metaStarsCount = game.data.metaStarsCount;
current.ticketsCount = game.data.ticketsCount;
current.turnCount = game.data.turnCount;
current.ballCount = game.data.ballCount;
current.itemList = game.cubeManager.Save().ToArray();
current.selectedDragon = game.data.selectedDragon;
current.campaignLevelsCompleted = game.data.campaignLevelsCompleted;
current.lastCollectedStarsWaveNumber = game.data.lastCollectedStarsWaveNumber;
current.additionalCampaignLevelsCompleted = game.data.additionalCampaignLevelsCompleted;
current.tutorialCompleted = game.data.tutorialCompleted;
current.colletedMetaQuestPrizes = game.data.colletedMetaQuestPrizes;
current.deleteBoosterFreeCount = game.data.deleteBoosterFreeCount;
current.doubleBoosterFreeCount = game.data.doubleBoosterFreeCount;
current.starsSpent = game.data.starsSpent;
current.boostersUsed = game.data.boostersUsed;
current.maxReboundPerBall = game.data.maxReboundPerBall;
current.allClearTimes = game.data.allClearTimes;
current.achievements = game.achievementController.currData;
current.caveProgress = game.data.caveProgress;
current.shownItems = game.data.shownItems;
Save(current);
}
public static void Save(GameSave saveData)
{
var current = saveData;
var jsonStr = JsonUtility.ToJson(current);
savedData = current;
PlayerPrefs.SetString(SaveName, jsonStr);
}
public static void SaveCurrData()
{
Save(SavedData);
}
#endregion
#region Json Serialization
/// <summary>преобразует текущий игровой прогресс в строку и возвращает ее</summary>
public static string GetJson(GameController game)
{
var current = Load();
current.starCount = game.data.starCount;
current.metaStarsCount = game.data.metaStarsCount;
current.ticketsCount = game.data.ticketsCount;
current.turnCount = game.data.turnCount;
current.ballCount = game.data.ballCount;
current.deleteBoosterFreeCount = game.data.deleteBoosterFreeCount;
current.doubleBoosterFreeCount = game.data.doubleBoosterFreeCount;
current.itemList = game.cubeManager.Save().ToArray();
current.campaignLevelsCompleted = game.data.campaignLevelsCompleted;
current.lastCollectedStarsWaveNumber = game.data.lastCollectedStarsWaveNumber;
current.additionalCampaignLevelsCompleted = game.data.additionalCampaignLevelsCompleted;
current.tutorialCompleted = game.data.tutorialCompleted;
current.achievements = game.data.achievements;
current.caveProgress = game.data.caveProgress;
current.shownItems = game.data.shownItems;
var jsonStr = JsonUtility.ToJson(current);
return jsonStr;
}
/// <summary>возвращает сейв после каста из указанной строки</summary>
public static GameSave FromJson(string progressJson)
{
var result = JsonUtility.FromJson<GameSave>(progressJson);
if (null == result)
{
result = GetEmpty();
result.achievements = new Achievements();
}
if (result.itemList == null) result.itemList = new GameItem[] { };
return result;
}
public string ToJson()
{
return JsonUtility.ToJson(this);
}
#endregion
#region Special Data Structs
[Serializable]
public enum ItemType
{
cube,
boss,
onion,
corner,
armoured,
dissapearing,
moving,
teleport,
ballCoin,
starCoin,
upForceCoin,
diffuseBallCoin,
dopelgangerCoin,
jumpBallCoin,
laserCoin,
crossLaserCoin,
killerCoin,
invunerable,
superBossWall,
superBossShield,
superBossExplosive,
explosive,
priest,
slime,
millCoin,
blackHoleCoin,
prizeBrick,
magicDustCoin,
removeBallCoin,
reduceBallsCountCoin
}
public enum BlockOrientation
{
left = 3,
right = 1,
up = 0,
down = 2
}
public enum BrickHp
{
singleHP,
doubleHP,
tripleHP,
quadrupleHP
}
[Serializable]
public struct GameItem
{
public ItemType itemType;
public int level;
public int index;
public int shiftDelay;
public int hitCounter;
public BlockOrientation orientation;
public BrickHp baseHP;
}
public enum itemBaseType
{
brick,
coin,
boss,
superBoss
}
public static itemBaseType GetItemType(ItemType type)
{
switch (type)
{
case ItemType.cube:
case ItemType.onion:
case ItemType.corner:
case ItemType.armoured:
case ItemType.dissapearing:
case ItemType.moving:
case ItemType.teleport:
case ItemType.explosive:
case ItemType.priest:
case ItemType.slime:
return itemBaseType.brick;
case ItemType.ballCoin:
case ItemType.starCoin:
case ItemType.laserCoin:
case ItemType.killerCoin:
case ItemType.upForceCoin:
case ItemType.diffuseBallCoin:
case ItemType.crossLaserCoin:
case ItemType.dopelgangerCoin:
case ItemType.jumpBallCoin:
case ItemType.millCoin:
return itemBaseType.coin;
case ItemType.boss:
return itemBaseType.boss;
case ItemType.superBossWall:
case ItemType.superBossShield:
case ItemType.superBossExplosive:
return itemBaseType.superBoss;
}
return itemBaseType.brick;
}
[Serializable]
public struct Achievements
{
public int cubeKilledTimes;
public int armouredKilledTimes;
public int cornerKilledTimes;
public int dissaperingKilledTimes;
public int movingKilledTimes;
public int onionKilledTimes;
public int teleportKilledTimes;
public int ballCoinTimesCollected;
public int crossLaserCoinTimesCollected;
public int diffuseCoinTimesCollected;
public int dopelgangerCoinTimesCollected;
public int jumpCoinTimesCollected;
public int killerCoinTimesCollected;
public int singleLaserCoinTimesCollected;
public int starCoinTimesCollected;
public int upForceCoinTimesCollected;
public int bossKilledTimes;
public int deleteBoosterTimesUsed;
public int doubleBoosterTimesUsed;
public int maxLevel;
public int maxLevelWithoutBoosters;
public int maxBalls;
public int skinsUnlocked;
public int allClearTimes;
public int maxMultikill;
public int killedWithLaser;
public int topLineKilled;
public int lastLineKilled;
public int bricksKilledWith3TimesRebounedBall;
}
[Serializable]
public struct MagicalCaveProgress
{
public bool caveOpened;
public long startTime;
public int currentDustAmount;
public int previousDustAmount;
public int currentMediumPrizeNumber;
public int currentBigPrizeNumber;
public bool prize1Collected;
public bool prize2Collected;
public bool prize3Collected;
public int currentBossNumber;
public int dustThisLevel;
public int dustTopOnLevel;
public int currentPrize1Number;
public int currentPrize2Number;
public int currentPrize3Number;
public bool caveTutorialCompleted;
//analytics
public float totalPlayTime;
public float doubleBoostersUsed;
public float deleteBoostersUsed;
public int currentLevel;
}
#endregion
#region Cloud Save/Load (in ALPHA)
public bool IsSimilarForCloudSaving(GameSave other)
{
return completedQuests.Count == other.completedQuests.Count && starCount == other.starCount && ticketsCount == other.ticketsCount;
}
public bool IsOtherHasBetterProgress(GameSave other)
{
return completedQuests.Count < other.completedQuests.Count;
}
#endregion
}
[System.Serializable]
public class DragonCrystal
{
public DragonCrystal()
{
}
public DragonCrystal(CrystalType type, int _count)
{
crystalType = type;
count = _count;
}
public CrystalType crystalType;
public int count;
}
public enum CrystalType
{
None,
Tutor,
Poison,
Electro,
Ice,
Elite
}