-
Notifications
You must be signed in to change notification settings - Fork 12
/
Character.cs
2745 lines (2335 loc) · 117 KB
/
Character.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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using RogueEssence.Data;
using RogueElements;
using RogueEssence.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Runtime.Serialization;
using RogueEssence.Script;
using NLua;
using Newtonsoft.Json;
using QuadTrees.QTreePoint;
using RogueEssence.Dev;
namespace RogueEssence.Dungeon
{
[Serializable]
public class Character : CharData, ICharSprite, IEntityWithLuaData, IPointQuadStorable, IPreviewable
{
public const int MAX_FULLNESS = 100;
public const int MAX_SPEED = 3;
public const int MIN_SPEED = -3;
public string ProxyName;
public string Name
{
get
{
if (ProxyName != "")
return ProxyName;
if (MemberTeam is ExplorerTeam)
{
if (!String.IsNullOrEmpty(Nickname))
return Nickname;
else
return DataManager.Instance.GetMonster(BaseForm.Species).Name.ToLocal();
}
else
{
if (!String.IsNullOrEmpty(Nickname))
return Nickname;
else
return GetFullFormName(BaseForm);
}
}
}
/// <summary>
/// Gets the name of the character, fully colored
/// </summary>
/// <param name="trueName">If set to true, uses Basename to bypass any alias or fake name.</param>
/// <returns></returns>
public string GetDisplayName(bool trueName)
{
string name = Name;
if (trueName)
{
if (MemberTeam is ExplorerTeam)
{
if (!String.IsNullOrEmpty(Nickname))
name = Nickname;
else
name = DataManager.Instance.GetMonster(BaseForm.Species).Name.ToLocal();
}
else
{
if (!String.IsNullOrEmpty(Nickname))
name = Nickname;
else
name = GetFullFormName(BaseForm);
}
}
Team team = MemberTeam;
if (Unidentifiable && team != DataManager.Instance.Save.ActiveTeam)
name = "???";
if (team == DataManager.Instance.Save.ActiveTeam)
{
if (this == team.Leader)
return String.Format("[color=#009CFF]{0}[color]", name);
return String.Format("[color=#FFFF00]{0}[color]", name);
}
string apparentSpecies = BaseForm.Species;
if (ProxySprite.IsValid() && ProxyName != "")
apparentSpecies = ProxySprite.Species;
GameProgress.UnlockState unlock;
if (DataManager.Instance.Save.Dex.TryGetValue(apparentSpecies, out unlock))
{
if (unlock == GameProgress.UnlockState.Completed)
return String.Format("[color=#00FF00]{0}[color]", name);
}
return String.Format("[color=#00FFFF]{0}[color]", name);
}
public MonsterID ProxySprite;
public MonsterID Appearance
{
get
{
if (ProxySprite.IsValid())
return ProxySprite;
else
return CurrentForm;
}
}
public MonsterID CurrentForm;
public int MaxHP { get { return DataManager.Instance.GetMonster(BaseForm.Species).Forms[BaseForm.Form].GetStat(Level, Stat.HP, MaxHPBonus); } }
public int ProxyAtk;
public int Atk
{
get
{
if (ProxyAtk > -1)
return ProxyAtk;
else
return BaseAtk;
}
}
public int BaseAtk { get { return DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].GetStat(Level, Stat.Attack, AtkBonus); } }
public int ProxyDef;
public int Def
{
get
{
if (ProxyDef > -1)
return ProxyDef;
else
return BaseDef;
}
}
public int BaseDef { get { return DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].GetStat(Level, Stat.Defense, DefBonus); } }
public int ProxyMAtk;
public int MAtk
{
get
{
if (ProxyMAtk > -1)
return ProxyMAtk;
else
return BaseMAtk;
}
}
public int BaseMAtk { get { return DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].GetStat(Level, Stat.MAtk, MAtkBonus); } }
public int ProxyMDef;
public int MDef
{
get
{
if (ProxyMDef > -1)
return ProxyMDef;
else
return BaseMDef;
}
}
public int BaseMDef { get { return DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].GetStat(Level, Stat.MDef, MDefBonus); } }
public int ProxySpeed;
public int Speed
{
get
{
if (ProxySpeed > -1)
return ProxySpeed;
else
return BaseSpeed;
}
}
public int BaseSpeed { get { return DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].GetStat(Level, Stat.Speed, SpeedBonus); } }
public List<BackReference<Skill>> Skills;
[JsonConverter(typeof(ElementConverter))]
public string Element1 { get; private set; }
[JsonConverter(typeof(ElementConverter))]
public string Element2 { get; private set; }
public List<BackReference<Intrinsic>> Intrinsics;
public InvItem EquippedItem;
/// <summary>
/// If turned on, this entity is considered NOT a part of the adventure for the duration of that adventure.
/// </summary>
public bool Absentee;
public LuaTable LuaData
{
get { return LuaDataTable; }
set { LuaDataTable = value; }
}
int movementSpeed;
public int MovementSpeed
{
get { return movementSpeed; }
set { movementSpeed = Math.Min(Math.Max(value, MIN_SPEED), MAX_SPEED); }
}
public int ChargeBoost;
/// <summary>
/// Position on the map grid in tiles.
/// </summary>
public Loc CharLoc
{
get { return currentCharAction.CharLoc; }
set
{
Loc oldLoc = currentCharAction.CharLoc;
currentCharAction.CharLoc = value;
updateLoc(oldLoc);
}
}
System.Drawing.Point IPointQuadStorable.Point { get { return new System.Drawing.Point(CharLoc.X, CharLoc.Y); } }
/// <summary>
/// Character's direction.
/// </summary>
public Dir8 CharDir
{
get { return currentCharAction.CharDir; }
set { currentCharAction.CharDir = value; }
}
public bool HideShadow
{
get { return currentCharAction.HideShadow; }
}
public int HP;
public int HPRemainder;
public int Fullness;
public int FullnessRemainder;
public int MaxFullness;
private bool dead;
public bool Dead
{
get { return dead; }
set
{
dead = value;
MemberTeam?.CharacterDeathChanged();
}
}
[JsonConverter(typeof(StatusDictConverter))]
public Dictionary<string, StatusEffect> StatusEffects;
/// <summary>
/// Guaranteed to hit next attack
/// </summary>
public bool MustHitNext;
/// <summary>
/// The number of turns this character must wait before being able to move again.
/// </summary>
public int TurnWait;
/// <summary>
/// The number of turn tiers that this character has moved OR acted on.
/// </summary>
public int TiersUsed;
/// <summary>
/// Whether the character has made an action during this map turn. Only one action per map turn permitted.
/// </summary>
public bool TurnUsed;
[NonSerialized]
public List<StatusRef> StatusesTargetingThis;
public bool EXPMarked;
public AITactic Tactic;
//calculable via save-loading
public TerrainData.Mobility Mobility;
public bool CantWalk;
//will prevent the passive item effects, as well as the "stick" effect
//does not affect active use
/// <summary>
/// Will prevent the passive item effects. Does not prevent active use.
/// </summary>
public bool ItemDisabled;
/// <summary>
/// Prevents passive intrinsic effects
/// </summary>
public bool IntrinsicDisabled;
public bool CanRemoveStuck;
public bool StopItemAtHit;
/// <summary>
/// Will move erratically
/// </summary>
public bool MovesScrambled;
public bool ChargeSaver;
/// <summary>
/// The Wait command translates to attack.
/// </summary>
public bool WaitToAttack;
/// <summary>
/// Can't pick up/place/equip/take items, cant interact with ground/people.
/// </summary>
public bool CantInteract;
/// <summary>
/// Treated as a foe by friends in combat
/// </summary>
public bool EnemyOfFriend;
/// <summary>
/// Treats friends as foes in and out of combat
/// </summary>
public bool AttackFriend;
//visibility and sight
public Map.SightRange TileSight;
public Map.SightRange CharSight;
//sprite is not visible and information about the entity is unavailable
public bool Unidentifiable;
//position is not visible
public bool Unlocatable;
public bool SeeAllChars;
public bool SeeItems;
public bool SeeWallItems;
public bool SeeTraps;
//miscellaneous traits
public StateCollection<CharState> CharStates;
//temporarily stores forced warp to prevent warp chains
[NonSerialized]
public List<Loc> WarpHistory;
[NonSerialized]
public Team MemberTeam;
[NonSerialized]
public int Proximity;
public TempCharBackRef BackRef;
public Character() : this(true)
{ }
[JsonConstructor]
public Character(bool populateSlots) : base(populateSlots)
{
Skills = new List<BackReference<Skill>>();
if (populateSlots)
{
for (int ii = 0; ii < MAX_SKILL_SLOTS; ii++)
Skills.Add(new BackReference<Skill>(new Skill()));
}
Element1 = "";
Element2 = "";
Intrinsics = new List<BackReference<Intrinsic>>();
if (populateSlots)
{
for (int ii = 0; ii < MAX_INTRINSIC_SLOTS; ii++)
Intrinsics.Add(new BackReference<Intrinsic>(new Intrinsic()));
}
EquippedItem = new InvItem();
Proximity = -1;
ProxyName = "";
ProxySprite = MonsterID.Invalid;
ProxyAtk = -1;
ProxyDef = -1;
ProxyMAtk = -1;
ProxyMDef = -1;
ProxySpeed = -1;
CharStates = new StateCollection<CharState>();
WarpHistory = new List<Loc>();
StatusEffects = new Dictionary<string, StatusEffect>();
IdleOverride = -1;
currentCharAction = new EmptyCharAction(new CharAnimIdle(new Loc(), Dir8.Down));
StatusesTargetingThis = new List<StatusRef>();
TileSight = Map.SightRange.Any;
CharSight = Map.SightRange.Any;
BackRef = new TempCharBackRef(false, -1);
}
public Character(CharData baseChar)
: this(baseChar, new Loc(), Dir8.Down) { }
public Character(CharData baseChar, Loc newLoc, Dir8 charDir)
: base(baseChar)
{
CurrentForm = BaseForm;
HP = MaxHP;
MaxFullness = MAX_FULLNESS;
Fullness = MaxFullness;
Skills = new List<BackReference<Skill>>();
for(int ii = 0; ii < BaseSkills.Count; ii++)
{
Skill newState = null;
if (!String.IsNullOrEmpty(BaseSkills[ii].SkillNum))
newState = new Skill(BaseSkills[ii].SkillNum, DataManager.Instance.GetSkill(BaseSkills[ii].SkillNum).BaseCharges);
else
newState = new Skill();
Skills.Add(new BackReference<Skill>(newState, ii));
BaseSkills[ii].Charges = newState.Charges;
}
Element1 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element1;
Element2 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element2;
Intrinsics = new List<BackReference<Intrinsic>>();
for(int ii = 0; ii < BaseIntrinsics.Count; ii++)
Intrinsics.Add(new BackReference<Intrinsic>(new Intrinsic(BaseIntrinsics[ii]), ii));
EquippedItem = new InvItem();
Proximity = -1;
ProxyName = "";
ProxySprite = MonsterID.Invalid;
ProxyAtk = -1;
ProxyDef = -1;
ProxyMAtk = -1;
ProxyMDef = -1;
ProxySpeed = -1;
CharStates = new StateCollection<CharState>();
WarpHistory = new List<Loc>();
StatusEffects = new Dictionary<string, StatusEffect>();
IdleOverride = -1;
currentCharAction = new EmptyCharAction(new CharAnimIdle(newLoc, charDir));
StatusesTargetingThis = new List<StatusRef>();
TileSight = Map.SightRange.Any;
CharSight = Map.SightRange.Any;
BackRef = new TempCharBackRef(false, -1);
UpdateFrame();
}
public Character Clone(Team team)
{
CharData character = new CharData();
character.BaseForm = this.BaseForm;
character.Nickname = this.Nickname;
character.Level = this.Level;
character.MaxHPBonus = this.MaxHPBonus;
character.AtkBonus = this.AtkBonus;
character.DefBonus = this.DefBonus;
character.MAtkBonus = this.MAtkBonus;
character.MDefBonus = this.MDefBonus;
character.SpeedBonus = this.SpeedBonus;
character.Unrecruitable = this.Unrecruitable;
for (int ii = 0; ii < CharData.MAX_SKILL_SLOTS; ii++)
character.BaseSkills[ii] = new SlotSkill(this.BaseSkills[ii]);
for (int ii = 0; ii < CharData.MAX_INTRINSIC_SLOTS; ii++)
character.BaseIntrinsics[ii] = this.BaseIntrinsics[ii];
Character new_mob = new Character(character);
team.Players.Add(new_mob);
new_mob.IdleOverride = IdleOverride;
CharAnimIdle idleAction = new CharAnimIdle(this.CharLoc, this.CharDir);
if (IdleOverride > -1)
idleAction.Override = IdleOverride;
new_mob.currentCharAction = new EmptyCharAction(idleAction);
new_mob.Tactic = new AITactic(this.Tactic);
new_mob.EquippedItem = new InvItem(this.EquippedItem);
for (int ii = 0; ii < CharData.MAX_SKILL_SLOTS; ii++)
new_mob.Skills[ii].Element.Enabled = this.Skills[ii].Element.Enabled;
foreach (string key in StatusEffects.Keys)
new_mob.StatusEffects.Add(key, StatusEffects[key].Clone());
return new_mob;
}
public void OnRemove()
{
//remove all status from this character without saying anything
List<string> keys = new List<string>();
keys.AddRange(StatusEffects.Keys);
for (int ii = 0; ii < keys.Count; ii++)
{
StatusEffect status = StatusEffects[keys[ii]];
StatusData data = (StatusData)status.GetData();
if (data.CarryOver)
continue;
StatusEffects.Remove(keys[ii]);
//need to remove the backreferences on their targets
removeTargetStatusRef(status);
//call all their OnTargetRemove one by one AFTER removal?
//status.OnRemove(this, false);
}
//remove all backreferences to targeted status from this character
while (StatusesTargetingThis.Count > 0)
{
StatusRef owner = StatusesTargetingThis[StatusesTargetingThis.Count - 1];
//call all their OnTargetRemoved one by one? Should we make an OnTargetRemoved event?
StatusesTargetingThis.RemoveAt(StatusesTargetingThis.Count - 1);
StatusEffect otherStatus = owner.TargetChar.GetStatusEffect(owner.ID);
if (otherStatus != null)
otherStatus.TargetChar = null;
}
RestoreForm();
}
private List<int> baseRestore()
{
HP = MaxHP;
HPRemainder = 0;
Fullness = MaxFullness;
FullnessRemainder = 0;
//record changed skills
List<int> skillIndices = new List<int>();
bool[] turnOn = new bool[MAX_SKILL_SLOTS];
for (int ii = 0; ii < MAX_SKILL_SLOTS; ii++)
{
skillIndices.Add(Skills[ii].BackRef);
turnOn[ii] = Skills[ii].Element.Enabled;
}
//restore the old skills with old use count
Skills.Clear();
for (int ii = 0; ii < BaseSkills.Count; ii++)
{
Skill newState = null;
if (!String.IsNullOrEmpty(BaseSkills[ii].SkillNum))
{
int baseCharges = DataManager.Instance.GetSkill(BaseSkills[ii].SkillNum).BaseCharges + ChargeBoost;
BaseSkills[ii].Charges = baseCharges;
newState = new Skill(BaseSkills[ii].SkillNum, baseCharges, turnOn[ii]);
}
else
newState = new Skill();
Skills.Add(new BackReference<Skill>(newState, ii));
}
Element1 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element1;
Element2 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element2;
Intrinsics.Clear();
for (int ii = 0; ii < BaseIntrinsics.Count; ii++)
Intrinsics.Add(new BackReference<Intrinsic>(new Intrinsic(BaseIntrinsics[ii]), ii));
ProxyAtk = -1;
ProxyDef = -1;
ProxyMAtk = -1;
ProxyMDef = -1;
ProxySpeed = -1;
StatusEffects = new Dictionary<string, StatusEffect>();
return skillIndices;
}
public void FullRestore()
{
if (Dead)
{
Dead = false;
DefeatAt = "";
}
List<int> skillIndices = baseRestore();
OnSkillsChanged(skillIndices.ToArray());
RefreshTraits();
}
public bool HasElement(string element)
{
return (element == Element1 || element == Element2);
}
public bool HasIntrinsic(string intrinsic)
{
foreach (BackReference<Intrinsic> checkIntrinsic in Intrinsics)
{
if (checkIntrinsic.Element.ID == intrinsic)
return true;
}
return false;
}
//for permanent change
public override void Promote(MonsterID data)
{
base.Promote(data);
RestoreForm();
}
//for transformations
public void Transform(MonsterID formData)
{
//set form data to formdata
CurrentForm = formData;
//update typing
Element1 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element1;
Element2 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element2;
//remap intrinsic to be the corresponding intrinsic of the new form
MonsterData dex = DataManager.Instance.GetMonster(BaseForm.Species);
BaseMonsterForm form = dex.Forms[BaseForm.Form];
int prevIndex = 0;
if (form.Intrinsic2 == BaseIntrinsics[0])
prevIndex = 1;
else if (form.Intrinsic3 == BaseIntrinsics[0])
prevIndex = 2;
MonsterData newDex = DataManager.Instance.GetMonster(CurrentForm.Species);
BaseMonsterForm newForm = newDex.Forms[CurrentForm.Form];
List<int> possibles = newForm.GetPossibleIntrinsicSlots();
if (!possibles.Contains(prevIndex))
prevIndex = 0;
Intrinsics.Clear();
if (prevIndex == 0)
Intrinsics.Add(new BackReference<Intrinsic>(new Intrinsic(newForm.Intrinsic1)));
else if (prevIndex == 1)
Intrinsics.Add(new BackReference<Intrinsic>(new Intrinsic(newForm.Intrinsic2)));
else if (prevIndex == 2)
Intrinsics.Add(new BackReference<Intrinsic>(new Intrinsic(newForm.Intrinsic3)));
//remove proxy stats
ProxyAtk = -1;
ProxyDef = -1;
ProxyMAtk = -1;
ProxyMDef = -1;
ProxySpeed = -1;
RefreshTraits();
}
public void RestoreForm()
{
CurrentForm = BaseForm;
List<int> skillIndices = new List<int>();
bool[] turnOn = new bool[MAX_SKILL_SLOTS];
for (int ii = 0; ii < MAX_SKILL_SLOTS; ii++)
{
skillIndices.Add(Skills[ii].BackRef);
turnOn[ii] = Skills[ii].Element.Enabled;
}
//restore the old skills with old use count
Skills.Clear();
for (int ii = 0; ii < BaseSkills.Count; ii++)
{
Skill newState = null;
if (!String.IsNullOrEmpty(BaseSkills[ii].SkillNum))
newState = new Skill(BaseSkills[ii].SkillNum, BaseSkills[ii].Charges, turnOn[ii]);
else
newState = new Skill();
Skills.Add(new BackReference<Skill>(newState, ii));
}
Element1 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element1;
Element2 = DataManager.Instance.GetMonster(CurrentForm.Species).Forms[CurrentForm.Form].Element2;
Intrinsics.Clear();
for (int ii = 0; ii < BaseIntrinsics.Count; ii++)
Intrinsics.Add(new BackReference<Intrinsic>(new Intrinsic(BaseIntrinsics[ii]), ii));
ProxyAtk = -1;
ProxyDef = -1;
ProxyMAtk = -1;
ProxyMDef = -1;
ProxySpeed = -1;
OnSkillsChanged(skillIndices.ToArray());
RefreshTraits();
}
public IEnumerator<YieldInstruction> UpdateFullness(bool combat)
{
int recovery = (combat ? 0 : 12);
int residual = 0;
if (MemberTeam == DungeonScene.Instance.ActiveTeam && MemberTeam.Leader == this)
{
residual = 80;
}
int prevFullness = Fullness;
Fullness -= (residual + FullnessRemainder) / 1000;
FullnessRemainder = (residual + FullnessRemainder) % 1000;
if (MemberTeam == DungeonScene.Instance.ActiveTeam)
{
if (Fullness <= 0 && prevFullness > 0)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_HUNGER_EMPTY", GetDisplayName(true)));
else if (Fullness <= 10 && prevFullness > 10)
{
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_HUNGER_CRITICAL", GetDisplayName(true)));
GameManager.Instance.SE(GraphicsManager.HungerSE);
}
else if (Fullness <= 20 && prevFullness > 20)
{
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_HUNGER_LOW", GetDisplayName(true)));
GameManager.Instance.SE(GraphicsManager.HungerSE);
}
}
else
{
if (Fullness <= 0 && prevFullness > 0)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_HUNGER_EMPTY_FOE", GetDisplayName(false)));
}
if (Fullness <= 0)
{
Fullness = 0;
FullnessRemainder = 0;
if (MemberTeam == DungeonScene.Instance.ActiveTeam)
GameManager.Instance.SE(GraphicsManager.HungerSE);
recovery = -60;
}
yield return CoroutineManager.Instance.StartCoroutine(ModifyHP(MaxHP * recovery));
}
public IEnumerator<YieldInstruction> ModifyHP(int residualHP)
{
OnModifyHP(ref residualHP);
HP += (residualHP + HPRemainder) / 1000;
HPRemainder = (residualHP + HPRemainder) % 1000;
if (HP > MaxHP)
HP = MaxHP;
else if (HP < 0)
HP = 0;
if (HP == 0)
yield return CoroutineManager.Instance.StartCoroutine(Die());
}
public IEnumerator<YieldInstruction> RestoreHP(int hp, bool anim = true)
{
if (Dead)
yield break;
OnRestoreHP(ref hp);
if (hp != 0)
{
HP += hp;
if (HP > MaxHP) HP = MaxHP;
if (anim)
yield return CoroutineManager.Instance.StartCoroutine(DungeonScene.Instance.ProcessBattleFX(this, this, DataManager.Instance.HealFX));
if (!Unidentifiable)
DungeonScene.Instance.MeterChanged(CharLoc, hp, false);
Loc? earshot = null;
if (!anim)
earshot = CharLoc;
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_HP_RESTORE", GetDisplayName(false), hp), true, false, this, null);
yield return new WaitForFrames(GameManager.Instance.ModifyBattleSpeed(10, CharLoc));
}
yield break;
}
//find a way to check for death in this method, or check for death at certain specific points
public IEnumerator<YieldInstruction> InflictDamage(int hp, bool anim = true, bool endure = false)
{
int takeHP = (hp < 0) ? HP : hp;
Loc? earshot = null;
if (!anim)
earshot = CharLoc;
if (takeHP == 0)
{
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_DAMAGE_ZERO", GetDisplayName(false)), false, false, this, null);
if (anim)
GameManager.Instance.SE(GraphicsManager.NullDmgSE);
yield break;
}
HP -= takeHP;
if (hp < 0)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_DAMAGE_INFINITY", GetDisplayName(false)), false, false, this, null);
else
{
if (!Unidentifiable)
DungeonScene.Instance.MeterChanged(CharLoc, -takeHP, false);
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_DAMAGE", GetDisplayName(false), takeHP), true, false, this, null);
}
int endureHP = endure ? 1 : 0;
if (HP < endureHP)
{
if (endure)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_DAMAGE_ENDURE", GetDisplayName(false)), false, false, this, null);
HP = endureHP;
}
//enqueue HP lost
if (HP == 0)
yield return CoroutineManager.Instance.StartCoroutine(Die());
else if (anim)
{
CharAnimHurt hurtAnim = new CharAnimHurt();
hurtAnim.CharLoc = CharLoc;
hurtAnim.CharDir = CharDir;
yield return CoroutineManager.Instance.StartCoroutine(this.StartAnim(hurtAnim));
yield return new WaitForFrames(GameManager.Instance.ModifyBattleSpeed(30, CharLoc));
}
}
/// <summary>
/// Makes the character disappear but also causes it to let go of its item.
/// Technically should be handled by the scripts calling it.
/// TODO: remove this method, after removing calls from rescue to script
/// </summary>
/// <returns></returns>
public IEnumerator<YieldInstruction> DieSilent()
{
HP = 0;
Dead = true;
//yield return CoroutineManager.Instance.StartCoroutine(OnDeath());
//if (Dead)
//{
if (MemberTeam is ExplorerTeam)
{
}
else
{
InvItem heldItem = EquippedItem;
if (!String.IsNullOrEmpty(heldItem.ID))
{
SilentDequipItem();
MapItem mapItem = new MapItem(heldItem);
yield return CoroutineManager.Instance.StartCoroutine(DungeonScene.Instance.DropMapItem(mapItem, CharLoc, CharLoc, true));
}
}
OnRemove();
DefeatAt = ZoneManager.Instance.CurrentMap.GetColoredName();
//}
}
public IEnumerator<YieldInstruction> Die()
{
SingleCharContext context = new SingleCharContext(this);
yield return CoroutineManager.Instance.StartCoroutine(OnDeath(context));
//TODO: refactor this code into OnDeath now that it can cancel properly
if (Dead)
{
if (MemberTeam is ExplorerTeam)
{
}
else
{
InvItem heldItem = EquippedItem;
if (!String.IsNullOrEmpty(heldItem.ID))
{
yield return CoroutineManager.Instance.StartCoroutine(DequipItem());
yield return CoroutineManager.Instance.StartCoroutine(DungeonScene.Instance.DropItem(heldItem, CharLoc));
}
}
OnRemove();
DefeatAt = ZoneManager.Instance.CurrentMap.GetColoredName();
//DefeatDungeon = ZoneManager.Instance.CurrentZoneID;
//DefeatFloor = ZoneManager.Instance.CurrentMapID;
}
}
public IEnumerator<YieldInstruction> RestoreCharges(int charges)
{
yield return CoroutineManager.Instance.StartCoroutine(RestoreCharges(-1, charges, true, true));
}
public IEnumerator<YieldInstruction> RestoreCharges(int skillSlot, int charges, bool effect, bool declare)
{
for (int ii = 0; ii < Skills.Count; ii++)
{
if (!String.IsNullOrEmpty(Skills[ii].Element.SkillNum))
{
if (skillSlot == ii || skillSlot == -1)
{
SkillData data = DataManager.Instance.GetSkill(Skills[ii].Element.SkillNum);
SetSkillCharges(ii, Math.Min(Skills[ii].Element.Charges + charges, data.BaseCharges + ChargeBoost));
}
}
}
if (declare)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_CHARGES_RESTORE", GetDisplayName(false)));
if (effect)
yield return CoroutineManager.Instance.StartCoroutine(DungeonScene.Instance.ProcessBattleFX(this, this, DataManager.Instance.RestoreChargeFX));
}
public IEnumerator<YieldInstruction> DeductCharges(int skillSlot, int charges)
{
yield return CoroutineManager.Instance.StartCoroutine(DeductCharges(skillSlot, charges, true, true, true));
}
public IEnumerator<YieldInstruction> DeductCharges(int skillSlot, int charges, bool effect, bool declare, bool force)
{
if (ChargeSaver && force)
{
if (declare)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_CHARGES_LOST_ZERO", GetDisplayName(false)));
yield break;
}
List<int> deductSlots = new List<int>();
if (skillSlot > -1)
{
if (Skills[skillSlot].Element.Charges == 0)
{
if (declare)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_CHARGES_LOST_NO_MORE", GetDisplayName(false), DataManager.Instance.GetSkill(Skills[skillSlot].Element.SkillNum).GetIconName()));
yield break;
}
SetSkillCharges(skillSlot, Math.Max(Skills[skillSlot].Element.Charges - charges, 0));
}
else
{
for (int ii = 0; ii < Skills.Count; ii++)
{
if (!String.IsNullOrEmpty(Skills[ii].Element.SkillNum))
{
if (Skills[ii].Element.Charges > 0)
{
deductSlots.Add(ii);
SetSkillCharges(ii, Math.Max(Skills[ii].Element.Charges - charges, 0));
}
}
}
if (deductSlots.Count == 0)
{
if (declare)
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_CHARGES_LOST_ALL_NO_MORE", GetDisplayName(false)));
yield break;
}
}
if (effect)
yield return CoroutineManager.Instance.StartCoroutine(DungeonScene.Instance.ProcessBattleFX(this, this, DataManager.Instance.LoseChargeFX));
if (declare)
{
if (skillSlot == -1)
{
DungeonScene.Instance.LogMsg(Text.FormatKey("MSG_CHARGES_LOST_ALL", GetDisplayName(false), charges));
yield return new WaitForFrames(GameManager.Instance.ModifyBattleSpeed(30, CharLoc));
for (int ii = deductSlots.Count-1; ii >= 0; ii--)
{
if (Skills[deductSlots[ii]].Element.Charges > 0)
deductSlots.RemoveAt(ii);
}