-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntitySystem_Core.cs
1251 lines (1052 loc) · 40.2 KB
/
EntitySystem_Core.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.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameSystem;
using LibrarySystem;
using AKUtilities;
using BlueprintSystem;
using MyBox;
namespace EntitySystem
{
/// <summary>
/// This is a universal access script for everything needing to deal with entities. Damage? This. Stats? This. It checks and filters all interactions and goes on every entity; players, sentries, machines, even tiles.
/// </summary>
public class EntitySystem_Core : MonoBehaviour
{
#region ENUMS
/// <summary>
/// This is the type of entity and is used to determine what the core should do and how it's interacted with.
/// </summary>
internal enum EntityType
{
Player,
Sentry,
Proxy,
Machine,
MachineSentry,
Tile,
Pawn
}
/// <summary>
/// This is the type of interaction being done. It allows us to route to the appropriate scripts.
/// </summary>
internal enum InteractionType
{
Damaging,
Healing,
Stunning
}
internal enum StatCalcType
{
TypeOne,
TypeTwo,
TypeThree
}
#endregion
#region CONFIGURATION
[Space(3)]
[Header("Core Configuration")]
[Space]
[SerializeField]
internal EntityType thisType;
[SerializeField]
internal bool hasRigidbody { get; } //Unsure if the "get;" is needed here.
[SerializeField]
internal GameObject visibleBody;
[SerializeField]
internal EnumLibrary.Aspects entityAspect; //NOT IMPLEMENTED YET
#endregion
#region SIGHT MANAGEMENT
[Space(3)]
[Header("Special Configuration")]
[Tooltip("If true, the entity will need to have line of sight of it's target or a unique behavior will be run.")]
[SerializeField]
private bool needsToCheckForSightOfTarget;
[ConditionalField(nameof(needsToCheckForSightOfTarget))]
[Tooltip("This is the layermask used by the sight raycast to determine obstruction.")]
[SerializeField]
private LayerMask sightCheckingMask;
#endregion
#region STATS
#endregion
#region COMBAT
[Space(3)]
[Header("Combat Configuration")]
[Space]
[SerializeField]
private float base_baseDamage; //The starting damage done by the character before being processed.
internal float active_baseDamage; //The current damage done by the character before being processed.
[SerializeField]
private float base_aggressionRating; //The normal aggro level for this entity.
internal float active_aggressionRating; //The active/modified aggro level for this entity.
[Space]
[SerializeField]
internal string hitTextIdentity; //The id for the hitText pool.
internal bool canBeTargeted = true;
internal bool isStunned;
#endregion
#region TARGETING CONFIGURATION
[Space(3)]
[Header("Targeting Configuration")]
[SerializeField]
private EnumLibrary.TargetAcquisitionMethod targetingMethod; //How will we get our targets?
[ConditionalField(nameof(targetingMethod), false, EnumLibrary.TargetAcquisitionMethod.ForwardFromPoint)]
[Tooltip("This is used to determine where the entity should 'fire' the spherecast check for a forward target.")]
[SerializeField]
private Transform targetingOutpoint; //The starting point for raycast based target checking.
[ConditionalField(nameof(targetingMethod), false, EnumLibrary.TargetAcquisitionMethod.Closest, EnumLibrary.TargetAcquisitionMethod.FromPlayerList)]
[Tooltip("This is used for multiple targeting methods. The special case is when pulling directly from a list, which will do a proximity check if the list is empty.")]
[SerializeField]
private float sphericalCheckRadius;
[ConditionalField(nameof(targetingMethod), false, EnumLibrary.TargetAcquisitionMethod.Closest, EnumLibrary.TargetAcquisitionMethod.FromPlayerList)]
[Tooltip("This is used for multiple targeting methods. The special case is when pulling directly from a list, which will do a proximity check if the list is empty.")]
[SerializeField]
private LayerMask targetableLayers; //Only check for tags on these layers.
[ConditionalField(nameof(targetingMethod), false, EnumLibrary.TargetAcquisitionMethod.ForwardFromPoint)]
[Tooltip("This is used for the sphere cast.")]
[SerializeField]
private float targetingSpherecastRadius; //10 for players
[ConditionalField(nameof(targetingMethod), false, EnumLibrary.TargetAcquisitionMethod.ForwardFromPoint)]
[Tooltip("This is used for the sphere cast.")]
[SerializeField]
private float targetingRange; //1000 for players
[Space]
[SerializeField]
internal EnumLibrary.TargetingType targetingType; //THIS IS CHANGED BY THE ACTIVE BLUEPRINT OR AI STATE!
[SerializeField]
internal string[] friendlyTags; //What tags are considered friendly?
[SerializeField]
internal string[] hostileTags; //What tags are considered hostile?
[Space]
[SerializeField]
internal Transform activeTarget;
private string[] currentTags; //Uses friendly or hostile depending on the target type.
#endregion
#region REWARDS
[Space(3)]
[Header("DEATH CONFIGURATION")]
[Space]
[SerializeField]
private float dropChance;
[Space]
[SerializeField]
private float base_killExp; //Exp given on kill
private float active_killExp;
[SerializeField]
private float base_killFlux; //Flux given on kill
private float active_killFlux;
private bool isDead;
[SerializeField]
private float base_threatOnKill;
private float active_threatOnKill;
#endregion
#region READ ONLY SCANS
internal float active_entityMaxVitality;
internal float active_entityVitality;
internal float entityLevel;
#endregion
#region CONDITIONALLY SET
internal Transform thisEntity;
internal Rigidbody thisRigidbody;
internal GameSystem_EntityManager.Spawner spawner;
[SerializeField]
internal Animator thisAnimator;
[SerializeField]
internal SkinnedMeshRenderer[] entityRenderers;
#endregion
#region UNIVERSAL SCRIPTS
internal EntitySystem_Info entityInfo;
internal BlueprintControlSystem blueprintControlSystem;
#endregion
#region CONDITIONAL SCRIPTS
internal Player player;
private Sentry sentry;
private Machine.Proxy proxy;
private Machine machine;
private Sentry.MachineSentry machineSentry;
private Tile tile;
private Pawn pawn;
#endregion
void OnEnable()
{
isDead = false;
canBeTargeted = true;
AddToRelativeEntityList();
if (entityInfo == null)
{
return;
}
if(thisType == EntityType.Player)
{
}
SetLevel();
if (thisType == EntityType.Machine)
{
UpdateMachineStats();
}
}
void Start()
{
#region UNIVERSAL START CALLS
thisEntity = this.transform; //Set our entity here.
if (hasRigidbody == true)
{
thisRigidbody = thisEntity.GetComponent<Rigidbody>();
}
entityInfo = this.gameObject.GetComponent<EntitySystem_Info>();
blueprintControlSystem = this.gameObject.GetComponent<BlueprintControlSystem>();
SetupStats();
entityRenderers = visibleBody.GetComponentsInChildren<SkinnedMeshRenderer>();
#endregion
#region CONDITIONAL START CALLS
LinkToEntityCore();
#endregion
}
void Update()
{
CheckForDeath();
}
#region INTERACTION FUNCTIONS
internal void Contact(EntitySystem_Core origin, InteractionType iType, float applicableValue)
{
if (CheckOwnership(origin) == true) //ONLY POSITIVE SELF INFLICTIONS ARE ALLOWED.
{
if (CanSelfInflict(iType) == true) //ONLY HEALING SO FAR. BUFFS ARE NEXT
{
DoAction(origin, iType, applicableValue); //DO THE ACTION TO OURSELVES OR GET IT FROM OUR PROXY OR SENTRY
}
else
{
return;
}
}
else //We don't own this, so we check if we're in PvP
{
// if (AK_GameSystems.GameSystem_Core.Instance.pvpEnabled == true) //If so, we don't run any blocks. What's acting on us isn't ours and anything can act on us.
// {
// DoAction(origin, iType, applicableValue); //Do the action as intended.
// }
// else
// {
DoAction(origin, iType, applicableValue); //Check for PvP conflicts before doing the action.
// }
}
}
private void DoAction(EntitySystem_Core origin, InteractionType iType, float applicableValue)
{
if (thisType == EntityType.Player) //Run player-only actions
{
if (iType == InteractionType.Damaging)
{
DamageAction(player, applicableValue);
}
if(iType == InteractionType.Healing)
{
HealingAction();
}
}
else if (thisType == EntityType.Sentry) //Run sentry-only actions
{
if (iType == InteractionType.Damaging)
{
DamageAction(sentry, applicableValue);
}
if (iType == InteractionType.Healing)
{
}
}
else if (thisType == EntityType.Proxy) //Run proxy-only actions
{
if (iType == InteractionType.Damaging)
{
DamageAction(proxy, applicableValue);
}
if (iType == InteractionType.Healing)
{
}
}
else if (thisType == EntityType.Machine) //Run machine-only actions
{
if (iType == InteractionType.Damaging)
{
DamageAction(machine, applicableValue);
}
if (iType == InteractionType.Healing)
{
}
if(iType == InteractionType.Stunning)
{
StunningAction(machine, applicableValue);
}
}
else if (thisType == EntityType.MachineSentry) //Run machine sentry-only actions
{
if (iType == InteractionType.Damaging)
{
DamageAction(machineSentry, applicableValue);
}
if (iType == InteractionType.Healing)
{
}
}
else if (thisType == EntityType.Tile) //Run tile-only actions
{
if (iType == InteractionType.Damaging)
{
DamageAction(tile, applicableValue);
}
if (iType == InteractionType.Healing)
{
}
}
else if(thisType == EntityType.Pawn)
{
if(iType == InteractionType.Damaging)
{
DamageAction(pawn, applicableValue);
}
if (iType == InteractionType.Healing)
{
}
}
}
#endregion
#region START CALLS
/// <summary>
/// Setup all the references the core is going to need to do it's job.
/// </summary>
private void LinkToEntityCore()
{
if (thisType == EntityType.Player)
{
player = this.gameObject.GetComponent<Player>();
}
else if (thisType == EntityType.Sentry)
{
sentry = this.gameObject.GetComponent<Sentry>();
}
else if (thisType == EntityType.Proxy)
{
proxy = this.gameObject.GetComponent<Machine>().machineAsProxy;
}
else if (thisType == EntityType.Machine)
{
machine = this.gameObject.GetComponent<Machine>();
}
else if (thisType == EntityType.MachineSentry)
{
machineSentry = this.gameObject.GetComponent<Sentry>().machineSentry;
}
else if (thisType == EntityType.Tile)
{
tile = this.gameObject.GetComponent<Tile>();
}
else if(thisType == EntityType.Pawn)
{
pawn = this.gameObject.GetComponent<Pawn>();
}
}
/// <summary>
/// Set our active variables to equal the base variables.
/// </summary>
private void SetupStats()
{
active_aggressionRating = base_aggressionRating;
active_baseDamage = base_baseDamage;
active_killExp = base_killExp;
active_killFlux = base_killFlux;
}
#endregion
#region ENABLED CALLS
private void SetLevel()
{
if (thisType == EntityType.Player)
{
//Player levels are done using a collective calculation.
}
else if (thisType == EntityType.Sentry)
{
//Sentries derive their power not from level, but from the player that places them and the blueprint they're placed with.
}
else if (thisType == EntityType.Proxy)
{
//Proxies use the same method as the sentries.
}
else if (thisType == EntityType.Machine)
{
entityInfo.CalculateNewLevel();
}
else if (thisType == EntityType.MachineSentry)
{
}
else if (thisType == EntityType.Tile)
{
}
}
#endregion
#region ACTIONS
#region DAMAGE
private static void DamageAction(Player playerScript, float rawDamage)
{
playerScript.Damaged(rawDamage);
}
private static void DamageAction(Sentry sentryScript, float rawDamage)
{
}
private static void DamageAction(Machine.Proxy proxyScript, float rawDamage)
{
}
private static void DamageAction(Machine machineScript, float rawDamage)
{
machineScript.Damaged(rawDamage);
}
private static void DamageAction(Sentry.MachineSentry machineSentryScript, float rawDamage)
{
}
private static void DamageAction(Tile tileScript, float rawDamage)
{
}
private static void DamageAction(Pawn pawnScript, float rawDamage)
{
pawnScript.TakeDamage(rawDamage);
}
#endregion
private void HealingAction()
{
}
#region STUNNING
private static void StunningAction(Machine machineScript, float duration)
{
machineScript.Stunned(duration);
}
#endregion
#endregion
#region CHECKING
/// <summary>
/// Filter the action taking place based on the type of action. Do one additional filter if PVP mode is disabled.
/// </summary>
/// <param name="origin">Entity doing the action.</param>
/// <param name="iType">Type of action.</param>
/// <param name="applicableValue">The value used in the action, if needed.</param>
private void ActionChecking(EntitySystem_Core origin, InteractionType iType, float applicableValue)
{
if (iType == InteractionType.Damaging)
{
if (BlockPVPAction(origin) == false) //Prevent PVP type damage if the origin belongs to an unowned player/sentry/proxy.
{
return;
}
else
{
DoAction(origin, iType, applicableValue); //If damage is from machine or machine sentry, we can do what it wanted to do.
}
}
else if (iType == InteractionType.Healing)
{
DoAction(origin, iType, applicableValue);
}
}
/// <summary>
/// This script checks to see if certain entities are trying to negatively impact eachother. When PvP is disabled, Players cannot hurt other players, sentries, or proxies. And Vice versa.
/// Note: Tiles can be damaged by almost every entity.
/// </summary>
/// <param name="origin"></param>
/// <returns></returns>
internal bool BlockPVPAction(EntitySystem_Core origin)
{
if (thisType == EntityType.Player)
{
if (origin.thisType == EntityType.Player)
{
return false; //Another player is attempting to do a negative thing to this player.
}
else if (origin.thisType == EntityType.Sentry)
{
return false; //Another player's sentry is attempting to do a negative thing to this player.
}
else if (origin.thisType == EntityType.Proxy)
{
return false;
}
else if (origin.thisType == EntityType.Machine)
{
return true;
}
else if (origin.thisType == EntityType.MachineSentry)
{
return true;
}
else if(origin.thisType == EntityType.Pawn)
{
return true;
}
else
{
return false;
}
}
else if (thisType == EntityType.Sentry)
{
if (origin.thisType == EntityType.Player)
{
return false;
}
else if (origin.thisType == EntityType.Sentry)
{
return false;
}
else if (origin.thisType == EntityType.Proxy)
{
return false;
}
else if (origin.thisType == EntityType.Machine)
{
return true;
}
else if (origin.thisType == EntityType.MachineSentry)
{
return true;
}
else if (origin.thisType == EntityType.Pawn)
{
return true;
}
else
{
return false;
}
}
else if (thisType == EntityType.Proxy)
{
if (origin.thisType == EntityType.Player)
{
return false;
}
else if (origin.thisType == EntityType.Sentry)
{
return false;
}
else if (origin.thisType == EntityType.Proxy)
{
return false;
}
else if (origin.thisType == EntityType.Machine)
{
return true;
}
else if (origin.thisType == EntityType.MachineSentry)
{
return true;
}
else if (origin.thisType == EntityType.Pawn)
{
return true;
}
else
{
return false;
}
}
else if (thisType == EntityType.Machine)
{
if (origin.thisType == EntityType.Player)
{
return true;
}
else if (origin.thisType == EntityType.Sentry)
{
return true;
}
else if (origin.thisType == EntityType.Proxy)
{
return true;
}
else if (origin.thisType == EntityType.Machine)
{
return false;
}
else if (origin.thisType == EntityType.MachineSentry)
{
return false;
}
else if (origin.thisType == EntityType.Pawn)
{
return true;
}
else
{
return false;
}
}
else if (thisType == EntityType.MachineSentry)
{
if (origin.thisType == EntityType.Player)
{
return true;
}
else if (origin.thisType == EntityType.Sentry)
{
return true;
}
else if (origin.thisType == EntityType.Proxy)
{
return true;
}
else if (origin.thisType == EntityType.Machine)
{
return false;
}
else if (origin.thisType == EntityType.MachineSentry)
{
return false;
}
else if (origin.thisType == EntityType.Pawn)
{
return true;
}
else
{
return false;
}
}
else if (thisType == EntityType.Tile) //Everything can damage tiles.
{
if (origin.thisType == EntityType.Player)
{
return true;
}
else if (origin.thisType == EntityType.Sentry)
{
return true;
}
else if (origin.thisType == EntityType.Proxy)
{
return true;
}
else if (origin.thisType == EntityType.Machine)
{
return true;
}
else if (origin.thisType == EntityType.MachineSentry)
{
return true;
}
else if (origin.thisType == EntityType.Pawn)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
/// <summary>
/// Self inflicted negative actions are prohibited here, by checking the action and blocking it if it would do something harmful.
/// </summary>
/// <param name="iType">Type of action.</param>
/// <returns></returns>
private bool CanSelfInflict(InteractionType iType)
{
if (iType == InteractionType.Damaging)
{
return false;
}
else if (iType == InteractionType.Healing)
{
return true;
}
else
{
return false;
}
}
#endregion
#region GENERAL FUNCTIONS
/// <summary>
/// Compare the IDs between two entities to see if they're the same. Returns TRUE if SAME, FALSE if NOT SAME.
/// </summary>
/// <param name="origin">The entity initiating the action.</param>
/// <returns></returns>
private bool CompareIDs(EntitySystem_Core origin)
{
if (origin.entityInfo.entityId == entityInfo.entityId)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Compare the Ownership ID between two entities to see if the entity being acted upon is owned by the origin entity. Returns TRUE if SAME, FALSE if NOT SAME.
/// </summary>
/// <param name="origin">The entity initiating the action.</param>
/// <returns></returns>
internal bool CheckOwnership(EntitySystem_Core origin)
{
if(origin.entityInfo == null)
{
return false;
}
if (this == origin || origin.entityInfo.entityOwner == entityInfo.entityId || entityInfo.entityOwner == origin.entityInfo.entityId)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Checks leading up to this have taken place, and the entity is to drop a blueprint on death.
/// </summary>
/// <param name="blueprintType">The type of blueprint that gets dropped. 0: Common, 1: Uncommon, 2: Rare, 3: Epic, 4: Legendary</param>
private void DropBlueprint(int blueprintType)
{
if (blueprintType == 0) //Drop common BP
{
int _selection = Random.Range(0, GameSystem_EntityManager.Instance.blueprintSpawnables_common.Length);
GameObject blueprint = Instantiate(GameSystem_EntityManager.Instance.blueprintSpawnables_common[_selection], this.gameObject.transform.position, Quaternion.identity);
}
else if (blueprintType == 1) //Drop uncommon BP, etc
{
int _selection = Random.Range(0, GameSystem_EntityManager.Instance.blueprintSpawnables_uncommon.Length);
GameObject blueprint = Instantiate(GameSystem_EntityManager.Instance.blueprintSpawnables_uncommon[_selection], this.gameObject.transform.position, Quaternion.identity);
}
else if (blueprintType == 2)
{
int _selection = Random.Range(0, GameSystem_EntityManager.Instance.blueprintSpawnables_rare.Length);
GameObject blueprint = Instantiate(GameSystem_EntityManager.Instance.blueprintSpawnables_rare[_selection], this.gameObject.transform.position, Quaternion.identity);
}
else if (blueprintType == 3)
{
int _selection = Random.Range(0, GameSystem_EntityManager.Instance.blueprintSpawnables_epic.Length);
GameObject blueprint = Instantiate(GameSystem_EntityManager.Instance.blueprintSpawnables_epic[_selection], this.gameObject.transform.position, Quaternion.identity);
}
else if (blueprintType == 4)
{
int _selection = Random.Range(0, GameSystem_EntityManager.Instance.blueprintSpawnables_legendary.Length);
GameObject blueprint = Instantiate(GameSystem_EntityManager.Instance.blueprintSpawnables_legendary[_selection], this.gameObject.transform.position, Quaternion.identity);
}
}
#endregion
#region DEATH FUNCTIONS
private void CheckForDeath()
{
if(isDead == true)
{
return;
}
if (thisType == EntityType.Player)
{
if(player.active_currentVitality <= 0)
{
Death();
}
}
else if (thisType == EntityType.Sentry)
{
}
else if (thisType == EntityType.Proxy)
{
}
else if (thisType == EntityType.Machine)
{
if(machine.active_currentVitality <= 0)
{
Death();
}
}
else if (thisType == EntityType.MachineSentry)
{
}
else
{
}
}
private void Death()
{
RemoveFromRelativeList();
if (thisType == EntityType.Player)
{
player.Die();
}
else if (thisType == EntityType.Sentry)
{
}
else if (thisType == EntityType.Proxy)
{
}
else if (thisType == EntityType.Machine)
{
CheckForDrop();
this.gameObject.SetActive(false);
machine.active_currentVitality = 1;
GameSystem_EntityManager.Instance.currentTotalEntities -= 1;
GameSystem_EntityManager.Instance.collectivePlayerExperience += active_killExp;
GameSystem_EntityManager.Instance.AddThreat(active_threatOnKill);
GameSystem_EntityManager.Instance.AddFlux(active_killFlux);
spawner.currentSpawned -= 1;
}
else if (thisType == EntityType.MachineSentry)
{
CheckForDrop();
}
else
{
}
}
/// <summary>
/// Role the dice to see if this entity drops a blueprint.
/// </summary>
private void CheckForDrop()
{
if (AKUtilities.Utilities.DiceRoll(dropChance) == true)
{
DropBlueprint(AKUtilities.Utilities.RollForBlueprintDrop());
}
else
{
return;
}
}
#endregion
#region STAT CHANGES
internal void UpdatePlayerStats()
{
active_baseDamage = (GameSystem_EntityManager.Instance.collectivePlayerLevel + GameSystem_EntityManager.Instance.collectivePlayerLevel * base_baseDamage) - Mathf.Sqrt(active_baseDamage);
player.active_meleeDamage = 1.5f * (GameSystem_EntityManager.Instance.collectivePlayerLevel * GameSystem_EntityManager.Instance.collectivePlayerLevel * base_baseDamage) - Mathf.Sqrt(player.active_meleeDamage);
}
private void UpdateMachineStats()
{
machine.UpdateStats();
active_killExp = StatCalc(this, base_killExp, active_killExp, StatCalcType.TypeTwo);
active_killFlux = StatCalc(this, base_killFlux, active_killFlux, StatCalcType.TypeTwo);
active_baseDamage = StatCalc(this, base_baseDamage, active_baseDamage, StatCalcType.TypeThree);
active_aggressionRating = Mathf.RoundToInt(base_aggressionRating * entityInfo.active_entityLevel);
active_threatOnKill = StatCalc(this, base_threatOnKill, active_threatOnKill, StatCalcType.TypeOne);
}
#region CALCULATIONS
internal static float StatCalc(EntitySystem_Core core, float baseFactor, float activeFactor, StatCalcType type)
{
float newValue = 0;
if (type == StatCalcType.TypeOne)
{
newValue = core.entityInfo.active_entityLevel * (baseFactor + Mathf.Sqrt(activeFactor));
}
else if(type == StatCalcType.TypeTwo)
{
newValue = baseFactor + (core.entityInfo.active_entityLevel * Mathf.Sqrt(activeFactor));
}
else if(type == StatCalcType.TypeThree)
{
newValue = baseFactor * core.entityInfo.active_entityLevel / 1 + Mathf.RoundToInt(Mathf.Sqrt(activeFactor));
}
newValue = Mathf.RoundToInt(newValue);
return newValue;
}
#endregion
#endregion
private void AddToRelativeEntityList()
{
if (thisType == EntityType.Player)
{
Debug.Log("Add player to player list");
//Happens based on progression and player status.
GameSystem_EntityManager.Instance.players.Add(this);
}
else if (thisType == EntityType.Sentry)
{