This repository was archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.cs
More file actions
6002 lines (4617 loc) · 197 KB
/
Script.cs
File metadata and controls
6002 lines (4617 loc) · 197 KB
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 SFDGameScriptInterface;
namespace PowerupsDeluxe {
public partial class GameScript : GameScriptInterface {
public GameScript() : base(null) { }
private static readonly Random _rng = new Random();
public void OnStartup() {
Powerups.Enabled = true;
Events.UserMessageCallback.Start(HandleCommand);
Config.Update();
}
public void HandleCommand(UserMessageCallbackArgs args) {
IUser user = args.User;
if (!args.IsCommand)
return;
switch (args.Command) {
case "PD_HELP": {
int uid = user.UserIdentifier;
Game.ShowChatMessage("Available commands:",
Color.Green, uid);
Game.ShowChatMessage("PD_HELP - Shows command help.",
Color.Green, uid);
Game.ShowChatMessage("PD_POWERUPS - Displays all the power-ups with their codenames.",
Color.Green, uid);
Game.ShowChatMessage("PD_CRATE_CHANCE [chance] - Sets or gets the spawn chance of a power-up crate.",
Color.Green, uid);
Game.ShowChatMessage("PD_SYRINGE [player] - Gives a player a power-up syringe.",
Color.Green, uid);
Game.ShowChatMessage("PD_POWERUP <powerup> [player] - Gives a player a power-up.",
Color.Green, uid);
Game.ShowChatMessage("Required options are shown with <>, optional parameters are shown with [].",
Color.Yellow, uid);
}
break;
case "PD_POWERUPS": {
int uid = user.UserIdentifier;
Game.ShowChatMessage("Available power-ups:",
Color.Green, uid);
foreach (string powerUpName in typeof(Powerups.AvailablePowerups)
.GetNestedTypes()
.Select(t => t.Name)
.OrderBy(n => n))
Game.ShowChatMessage(powerUpName,
Color.Green, uid);
}
break;
case "PD_CRATE_CHANCE": {
if (!user.IsModerator && !user.IsHost) {
Game.ShowChatMessage("You don't have enough perms to execute this command.",
Color.Red, user.UserIdentifier);
break;
}
string arg = args.CommandArguments.Trim();
if (string.IsNullOrEmpty(arg)) {
Game.ShowChatMessage(string.Format("Special crate chance is set to {0}.", Config.SpecialCrateChance),
Color.Green, user.UserIdentifier);
break;
}
float crateChance;
if (float.TryParse(arg, out crateChance)) {
Config.SpecialCrateChance = crateChance;
Game.ShowChatMessage(string.Format("Set special crate chance to {0}.", Config.SpecialCrateChance),
Color.Green, user.UserIdentifier);
} else {
Game.ShowChatMessage("Specify a valid number.",
Color.Red, user.UserIdentifier);
}
}
break;
case "PD_SYRINGE": {
if (!user.IsModerator && !user.IsHost) {
Game.ShowChatMessage("You don't have enough perms to execute this command.",
Color.Red, user.UserIdentifier);
break;
}
IUser target = GetUser(args.CommandArguments.Trim());
IPlayer targetPlayer = target != null ? target.GetPlayer() : user.GetPlayer();
if (targetPlayer != null) {
OnPowerupSyringe(new TriggerArgs(null, targetPlayer, false));
} else {
Game.ShowChatMessage("Invalid player.",
Color.Red, user.UserIdentifier);
}
}
break;
case "PD_POWERUP": {
if (!user.IsModerator && !user.IsHost) {
Game.ShowChatMessage("You don't have enough perms to execute this command.",
Color.Red, user.UserIdentifier);
break;
}
string[] arg = args.CommandArguments.Split(' ');
Type powerUpType = GetPowerup(arg[0]);
if (powerUpType != null) {
IUser target = GetUser(arg.ElementAtOrDefault(1));
IPlayer targetPlayer = target != null ? target.GetPlayer() : user.GetPlayer();
if (targetPlayer != null) {
Powerup powerUp = (Powerup) Activator.CreateInstance(powerUpType, targetPlayer);
Game.ShowChatMessage(string.Format("{0} - {1}", powerUp.Name, powerUp.Author),
Color.Yellow, targetPlayer.UserIdentifier);
PlayPowerupEffect(targetPlayer.GetWorldPosition());
} else {
Game.ShowChatMessage("Invalid player.",
Color.Red, user.UserIdentifier);
}
} else {
Game.ShowChatMessage("Invalid power-up.",
Color.Red, user.UserIdentifier);
break;
}
}
break;
}
}
public static class Config {
private const string SPECIAL_CRATE_KEY = "SpecialCrateChance";
public static float SpecialCrateChance {
get {
return Powerups.SpawnChance;
}
set {
float val = MathHelper.Clamp(value, 0, 100);
Powerups.SpawnChance = val;
Game.LocalStorage.SetItem(SPECIAL_CRATE_KEY, val);
}
}
public static void Update() {
float specialCrateChance;
if (Game.LocalStorage.TryGetItemFloat(SPECIAL_CRATE_KEY, out specialCrateChance)) {
Powerups.SpawnChance = specialCrateChance;
}
}
}
public IUser GetUser(string arg) {
return string.IsNullOrEmpty(arg) ? null :
Game.GetActiveUsers()
.FirstOrDefault(u => u.AccountName == arg || u.Name == arg ||
(arg.All(char.IsDigit) ? u.GameSlotIndex == int.Parse(arg) : false));
}
public Type GetPowerup(string arg) {
string nest = "SFDScript.GameScript+Powerups+AvailablePowerups+" + arg;
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
return assembly.GetTypes()
.FirstOrDefault(t => t.FullName.Equals(nest, StringComparison.OrdinalIgnoreCase));
}
private static void PlayPowerupEffect(Vector2 pos) {
Game.PlaySound("LogoSlam", pos, 1);
Game.PlaySound("MuffledExplosion", pos, 1);
Game.PlayEffect(EffectName.Explosion, pos);
Game.PlayEffect(EffectName.CameraShaker, pos, 1f, 1000f, true);
}
public static void OnPowerupSyringe(TriggerArgs args) {
const WeaponItem POWERUP_WEAPONITEM = WeaponItem.STRENGTHBOOST;
IObjectActivateTrigger caller = args.Caller as IObjectActivateTrigger;
IPlayer sender = args.Sender as IPlayer;
if (sender == null) { // Get
sender = Game.GetObjectsByArea<IPlayer>(caller.GetAABB())
.FirstOrDefault(p => !p.IsDead && p.IsInputEnabled && p.IsBot);
}
Vector2 offset = new Vector2(0, 26);
if (sender.CurrentPowerupItem.WeaponItem == POWERUP_WEAPONITEM) {
Game.PlayEffect(EffectName.CustomFloatText, sender.GetWorldPosition() + offset, "CAN'T PICKUP");
return;
}
// Remove syringe
if (caller != null) {
caller.GetHighlightObject()
.Remove();
}
sender.GiveWeaponItem(POWERUP_WEAPONITEM);
Game.PlayEffect(EffectName.CustomFloatText, sender.GetWorldPosition() + offset, "POWER-UP BOOST");
Events.PlayerWeaponRemovedActionCallback weaponRemovedActionCallback = null;
weaponRemovedActionCallback = Events.PlayerWeaponRemovedActionCallback.Start(
(IPlayer player, PlayerWeaponRemovedArg arg) => {
if (player == sender && arg.WeaponItem == POWERUP_WEAPONITEM) {
IObject item = Game.GetObject(arg.TargetObjectID);
if (item != null) { // Powerup item dropped
IObject syringe = Powerups.CreatePowerupSyringe(sender.GetWorldPosition());
//Game.WriteToConsole("Created syringe", syringe.UniqueID);
// Set syringe
syringe.SetAngle(item.GetAngle());
syringe.SetLinearVelocity(item.GetLinearVelocity());
syringe.SetAngularVelocity(item.GetAngularVelocity());
item.Remove(); // Remove original item
weaponRemovedActionCallback.Stop();
weaponRemovedActionCallback = null;
} else { // Powerup item used
sender.SetStrengthBoostTime(0);
sender.SetSpeedBoostTime(0);
Type powerUpType = Powerups.GetRandomPowerupType(_rng);
Powerup powerUp = (Powerup) Activator.CreateInstance(powerUpType, sender); // Activate random powerup
Game.ShowChatMessage(string.Format("{0} - {1}", powerUp.Name, powerUp.Author), Color.Yellow, sender.UserIdentifier);
PlayPowerupEffect(sender.GetWorldPosition());
Game.PlayEffect(EffectName.CustomFloatText, sender.GetWorldPosition() + offset, powerUp.Name);
weaponRemovedActionCallback.Stop();
weaponRemovedActionCallback = null;
}
}
});
}
public static class Powerups {
private static readonly ObjectAITargetData _boxTargetData = new ObjectAITargetData(500, ObjectAITargetMode.MeleeOnly);
private static Events.ObjectCreatedCallback _objectCreatedCallback = null;
public static bool Enabled {
get {
return _objectCreatedCallback != null;
}
set {
if (value != Enabled)
if (value)
_objectCreatedCallback = Events.ObjectCreatedCallback.Start(OnObjectCreated);
else {
_objectCreatedCallback.Stop();
_objectCreatedCallback = null;
}
}
}
public static float SpawnChance = 33;
public static SupplyBox CreatePowerupBox(Vector2 pos) {
// Create box
IObject box = Game.CreateObject("CardboardBox00", pos);
// Create helmet
Vector2 helmOffset = new Vector2(2, -0.5f);
IObject helm = Game.CreateObject("Helmet00", pos + helmOffset);
// Create weld joint
IObjectWeldJoint weldJoint = (IObjectWeldJoint) Game.CreateObject("WeldJoint", pos);
// Set weld joint targets
weldJoint.AddTargetObject(box);
weldJoint.AddTargetObject(helm);
// Create destroy targets
IObjectDestroyTargets destroyTargets = (IObjectDestroyTargets) Game.CreateObject("DestroyTargets", pos);
// Set destroy targets
destroyTargets.AddTriggerDestroyObject(box);
destroyTargets.AddObjectToDestroy(helm);
destroyTargets.AddObjectToDestroy(weldJoint);
// Bot support
box.SetTargetAIData(_boxTargetData);
// Instance
SupplyBox supply = new SupplyBox(box) {
Effect = "ImpactDefault",
EffectCooldown = 300,
SlowFallMultiplier = 0.77f,
Destroyed = OnPowerupBoxDestroyed
};
return supply;
}
public static IObject CreatePowerupSyringe(Vector2 pos) {
// Create syringe
IObject syringe = Game.CreateObject("ItemStrengthBoostEmpty", pos);
// Create ActivateTrigger
IObjectActivateTrigger activateTrigger = (IObjectActivateTrigger) Game.CreateObject("ActivateTrigger", pos);
// Set ActivateTrigger
activateTrigger.SetBodyType(BodyType.Dynamic);
activateTrigger.SetHighlightObject(syringe);
activateTrigger.SetScriptMethod("OnPowerupSyringe");
// Create weld joint
IObjectWeldJoint weldJoint = (IObjectWeldJoint) Game.CreateObject("WeldJoint", pos);
// Set weld joint targets
weldJoint.AddTargetObject(syringe);
weldJoint.AddTargetObject(activateTrigger);
// Create destroy targets
IObjectDestroyTargets destroyTargets = (IObjectDestroyTargets) Game.CreateObject("DestroyTargets", pos);
// Set destroy targets
destroyTargets.AddTriggerDestroyObject(syringe);
destroyTargets.AddObjectToDestroy(activateTrigger);
destroyTargets.AddObjectToDestroy(weldJoint);
// Bot support
syringe.SetTargetAIData(_boxTargetData);
// Make pickupable for bots
new ActivateTriggerBot(activateTrigger);
return syringe;
}
public static Type GetRandomPowerupType(Random random) {
Type[] nestedPowerups = typeof(AvailablePowerups).GetNestedTypes()
.ToArray();
if (nestedPowerups.Length == 0)
throw new InvalidOperationException("No instantiable types found.");
Type randomType = nestedPowerups[random.Next(nestedPowerups.Length)];
return randomType;
}
private static void OnPowerupBoxDestroyed(IObject destroyed) {
CreatePowerupSyringe(destroyed.GetWorldPosition());
Game.PlaySound("DestroyWood", Vector2.Zero);
}
private static void OnObjectCreated(IObject[] objs) {
// Get random supply crates
foreach (IObject supplyCrate in objs) {
if (supplyCrate.Name != "SupplyCrate00" || _rng.Next(101) >= SpawnChance)
continue;
CreatePowerupBox(supplyCrate.GetWorldPosition());
supplyCrate.Remove();
}
}
public class SupplyBox {
private const float RAYCAST_COOLDOWN = 300;
private const float ANGULAR = 0;
private static readonly RayCastInput _collision = new RayCastInput(true) {
ProjectileHit = RayCastFilterMode.True,
BlockFire = RayCastFilterMode.True,
FilterOnMaskBits = true,
MaskBits = ushort.MaxValue
};
private static readonly Vector2 _rayCastOffset = new Vector2(0, -48);
private Events.UpdateCallback _updateCallback = null;
private Events.ObjectTerminatedCallback _objTerminatedCallback = null;
private float _elapsed = 0;
private bool _slowFall = true;
public IObject Box;
public string Effect = string.Empty;
public float EffectCooldown = 1000;
public float SlowFallMultiplier = 1;
public bool Enabled {
get {
return _updateCallback != null && _objTerminatedCallback != null;
}
set {
if (value != Enabled)
if (value) {
_updateCallback = Events.UpdateCallback.Start(Update);
_objTerminatedCallback = Events.ObjectTerminatedCallback.Start(OnObjectTerminated);
} else {
_updateCallback.Stop();
_updateCallback = null;
_objTerminatedCallback.Stop();
_objTerminatedCallback = null;
}
}
}
public delegate void DestroyedCallback(IObject destroyed);
public DestroyedCallback Destroyed;
public SupplyBox(IObject box) {
Box = box;
Enabled = true;
}
private void Update(float dlt) {
if (Box == null || Box.IsRemoved) {
Enabled = false;
return;
}
_elapsed += dlt;
Vector2 vel = Box.GetLinearVelocity();
if (_slowFall) {
if (vel.Y < 0) {
vel.Y *= SlowFallMultiplier;
Box.SetLinearVelocity(vel);
Box.SetAngle(ANGULAR);
Box.SetAngularVelocity(ANGULAR);
Box.SetHealth(Box.GetMaxHealth());
if (_elapsed % EffectCooldown == 0)
Game.PlayEffect(Effect, Box.GetWorldPosition());
}
if (_elapsed % RAYCAST_COOLDOWN == 0) {
Vector2 rayCastStart = Box.GetWorldPosition();
Vector2 rayCastEnd = rayCastStart + _rayCastOffset;
Game.DrawLine(rayCastStart, rayCastEnd, Color.Yellow);
RayCastResult result = Game.RayCast(rayCastStart, rayCastEnd, _collision)[0];
_slowFall = !result.Hit;
if (!_slowFall)
Box.SetLinearVelocity(Vector2.Zero);
}
}
}
private void OnObjectTerminated(IObject[] objs) {
if (objs.Any(o => o == Box)) {
Enabled = false;
if (Destroyed != null)
Destroyed.Invoke(Box);
}
}
}
public class ActivateTriggerBot {
private const uint UPDATE_DELAY = 50;
private readonly List<IPlayer> _activators = new List<IPlayer>();
private Events.UpdateCallback _updateCallback = null;
private IPlayer Activator {
get {
return Game.GetObjectsByArea<IPlayer>(Trigger.GetAABB())
.FirstOrDefault(p => p.IsBot && !p.IsDead && p.IsInputEnabled &&
!_activators.Contains(p) && (Trigger.GetUseType() == ActivateTriggerUseType.Individual || !_activators.Any()));
}
}
public IObjectActivateTrigger Trigger;
public bool Enabled {
get {
return _updateCallback != null;
}
set {
if (value != Enabled)
if (value)
_updateCallback = Events.UpdateCallback.Start(Update, UPDATE_DELAY);
else {
_updateCallback.Stop();
_updateCallback = null;
}
}
}
public ActivateTriggerBot(IObjectActivateTrigger trigger) {
Trigger = trigger;
Enabled = true;
}
private void Update(float delta) {
if (Trigger == null) {
Enabled = false;
return;
}
if (!Trigger.IsEnabled)
return;
IPlayer activator = Activator;
if (activator != null) {
Trigger.Trigger();
// List handling
_activators.Add(activator);
Events.UpdateCallback.Start(activatorRemovalElapsed => {
_activators.Remove(activator);
}, (uint) Trigger.GetCooldown(), 1);
}
}
}
public static class AvailablePowerups {
// FLAME - dsafxP
public class Flame : Powerup {
private static readonly PlayerModifiers _fireMod = new PlayerModifiers() {
FireDamageTakenModifier = 0
};
private BotBehaviorSet _set = null;
private PlayerModifiers _modifiers; // Stores original player modifiers
public override string Name {
get {
return "FLAME";
}
}
public override string Author {
get {
return "dsafxP";
}
}
public Flame(IPlayer player) : base(player) {
Time = 20000; // Set duration of powerup (20 seconds)
}
public override void Update(float dlt, float dltSecs) {
Player.SetMaxFire(); // Ensure player has maximum fire level while powerup is active
}
protected override void Activate() {
// Play visual effect at player's position indicating start of powerup
Game.PlayEffect("PLRB", Player.GetWorldPosition());
_modifiers = Player.GetModifiers(); // Store original player modifiers
_modifiers.CurrentHealth = -1;
_modifiers.CurrentEnergy = -1;
Player.SetModifiers(_fireMod);
if (Player.IsBot) {
BotBehaviorSet botSet = Player.GetBotBehaviorSet();
_set = botSet;
botSet.DefensiveRollFireLevel = 0;
Player.SetBotBehaviorSet(botSet);
}
}
public override void TimeOut() {
// Play effects indicating expiration of powerup
Game.PlaySound("StrengthBoostStop", Vector2.Zero);
Game.PlayEffect("PLRB", Player.GetWorldPosition());
}
public override void OnEnabled(bool enabled) {
if (!enabled) {
Player.ClearFire(); // Clear any fire effects on the player
// Restore original player modifiers
Player.SetModifiers(_modifiers);
// Restore behavior set
if (Player.IsBot && _set != null)
Player.SetBotBehaviorSet(_set);
}
}
}
// ADRENALINE - dsafxP
public class Adrenaline : Powerup {
private const uint EFFECT_COOLDOWN = 50; // Cooldown between each effect
private const float SPEED_MULT = 0.75f; // Moving while punching speed multiplier
private const float BOUNCE_SPEED = 9;
private static readonly Vector2 _jumpAttackSpeed = new Vector2(0, 2);
private static readonly VirtualKey[] _inputKeys = { // Keys that will trigger movement
VirtualKey.AIM_RUN_LEFT,
VirtualKey.AIM_RUN_RIGHT
};
private bool PlayerValid {
get {
return Player.IsOnGround &&
!Player.IsDiving &&
!Player.IsManualAiming &&
!Player.IsDisabled;
}
}
public override string Name {
get {
return "ADRENALINE";
}
}
public override string Author {
get {
return "dsafxP";
}
}
public Adrenaline(IPlayer player) : base(player) {
Time = 18000; // Set duration of powerup (18 seconds)
}
public override void Update(float dlt, float dltSecs) {
// Moving while attacking
if ((_inputKeys.Any(k => Player.KeyPressed(k)) || Player.IsBot) &&
(Player.IsMeleeAttacking || Player.IsKicking)) {
// Calculate offset
Vector2 offset = new Vector2((SPEED_MULT * Player.GetModifiers().RunSpeedModifier) *
Player.FacingDirection, 0);
// Apply offset
Player.SetWorldPosition(Player.GetWorldPosition() + offset);
}
// Bounce
if (Player.KeyPressed(VirtualKey.JUMP) && PlayerValid) {
Vector2 vel = Player.GetLinearVelocity();
vel.Y = BOUNCE_SPEED;
Player.SetLinearVelocity(vel);
}
// Jump attack spam
if ((Player.IsJumpAttacking || Player.IsJumpKicking) &&
Player.GetLinearVelocity().Y > _jumpAttackSpeed.Y)
Player.SetLinearVelocity(_jumpAttackSpeed);
// Play effect
if (Time % EFFECT_COOLDOWN == 0)
Game.PlayEffect(EffectName.ImpactDefault, Player.GetWorldPosition());
}
protected override void Activate() {
}
public override void TimeOut() {
// Play effects indicating expiration of powerup
Game.PlaySound("StrengthBoostStop", Vector2.Zero);
Game.PlayEffect(EffectName.PlayerLandFull, Player.GetWorldPosition());
}
}
// VORTEX - dsafxP
public class Vortex : Powerup {
private const uint VORTEX_COOLDOWN = 250;
private const float VORTEX_AREA_SIZE = 100;
private const float VORTEX_FORCE = 5;
private static readonly PlayerCommand _playerCommand = new PlayerCommand(PlayerCommandType.Fall);
private static readonly Type[] _objTypes = {
typeof(IObjectSupplyCrate),
typeof(IObjectStreetsweeperCrate),
typeof(IObjectWeaponItem)
};
private Area VortexArea {
get {
Area playerArea = Player.GetAABB();
playerArea.SetDimensions(VORTEX_AREA_SIZE, VORTEX_AREA_SIZE);
return playerArea;
}
}
private IPlayer[] PlayersInVortex {
get {
return Game.GetObjectsByArea<IPlayer>(VortexArea)
.Where(p => (p.GetTeam() == PlayerTeam.Independent || p.GetTeam() != Player.GetTeam())
&& !p.IsDisabled && p != Player)
.ToArray();
}
}
private IObject[] ObjectsInVortex {
get {
return Game.GetObjectsByArea(VortexArea)
.Where(o => _objTypes.Any(t => t.IsAssignableFrom(o.GetType())))
.ToArray();
}
}
public override string Name {
get {
return "VORTEX";
}
}
public override string Author {
get {
return "dsafxP";
}
}
public Vortex(IPlayer player) : base(player) {
Time = 17000; // 17 s
}
public override void Update(float dlt, float dltSecs) {
if (Time % 50 == 0) // every 50ms
Draw(Player.GetWorldPosition());
if (Time % VORTEX_COOLDOWN == 0) { // every 250ms
Game.DrawArea(VortexArea, Color.Red);
foreach (IPlayer pulled in PlayersInVortex) {
pulled.SetInputEnabled(false);
pulled.AddCommand(_playerCommand);
Events.UpdateCallback.Start((float _dlt) => {
pulled.SetInputEnabled(true);
}, 1, 1);
Vector2 pulledPos = pulled.GetWorldPosition();
pulled.SetWorldPosition(pulledPos + (Vector2Helper.Up * 2)); // Sticky feet
pulled.SetLinearVelocity(Vector2Helper.DirectionTo(pulledPos,
Player.GetWorldPosition()) * VORTEX_FORCE);
pulled.Disarm(pulled.CurrentWeaponDrawn);
Game.PlaySound("PlayerDive", Vector2.Zero);
}
foreach (IObject pulled in ObjectsInVortex) {
pulled.SetLinearVelocity(Vector2Helper.DirectionTo(pulled.GetWorldPosition(),
Player.GetWorldPosition()) * VORTEX_FORCE);
Game.PlaySound("PlayerDive", Vector2.Zero);
}
}
}
protected override void Activate() {
}
public override void TimeOut() {
// Play sound effect indicating expiration of powerup
Game.PlaySound("StrengthBoostStop", Vector2.Zero);
}
// This cool effect was made by Danger Ross!
private void Draw(Vector2 pos) {
PointShape.Swirl(
(v => Game.PlayEffect(EffectName.ItemGleam,
Vector2Helper.Rotated(v - pos,
(float) (Time % 1500 * (MathHelper.TwoPI / 1500)))
+ pos)),
pos, // Center Position
5, // Initial Radius
VORTEX_AREA_SIZE / 2, // End Radius
2, // Rotations
45 // Point count
);
}
}
// SPHERE - dsafxP
public class Sphere : Powerup {
private const uint EFFECT_COOLDOWN = 50;
private const float EFFECT_SEPARATION = 45;
private const float SPHERE_SIZE = 100;
private const float SPHERE_RADIUS = SPHERE_SIZE / 2;
private Area SphereArea {
get {
Area playerArea = Player.GetAABB();
playerArea.SetDimensions(SPHERE_SIZE, SPHERE_SIZE);
return playerArea;
}
}
private IProjectile[] ProjectilesInSphere {
get {
return Game.GetProjectiles()
.Where(pr => SphereArea.Contains(pr.Position) && pr.InitialOwnerPlayerID != Player.UniqueID &&
(GetTeamOrDefault(Game.GetPlayer(pr.InitialOwnerPlayerID)) != Player.GetTeam() ||
Player.GetTeam() == PlayerTeam.Independent) &&
!pr.PowerupBounceActive)
.ToArray();
}
}
public override string Name {
get {
return "SPHERE";
}
}
public override string Author {
get {
return "dsafxP";
}
}
public Sphere(IPlayer player) : base(player) {
Time = 24000; // 24 s
}
public override void Update(float dlt, float dltSecs) {
if (Time % EFFECT_COOLDOWN == 0) {
Draw(Player.GetWorldPosition());
Game.DrawArea(SphereArea, Color.Red);
}
foreach (IProjectile projs in ProjectilesInSphere) {
projs.Direction *= -1;
projs.CritChanceDealtModifier = 100;
projs.PowerupBounceActive = true;
Game.PlayEffect(EffectName.Electric, projs.Position);
Game.PlaySound("ShellBounce", Vector2.Zero, 1);
Game.PlaySound("ElectricSparks", Vector2.Zero, 1);
}
}
public override void TimeOut() {
// Play sound effect indicating expiration of powerup
Game.PlaySound("StrengthBoostStop", Vector2.Zero);
}
protected override void Activate() {
}
private void Draw(Vector2 pos) {
PointShape.Circle(v => {
Game.PlayEffect(EffectName.ItemGleam, Vector2Helper.Rotated(v - pos,
(float) (Time % 1500 * (MathHelper.TwoPI / 1500))) +
pos);
}, pos, SPHERE_RADIUS, EFFECT_SEPARATION);
}
private PlayerTeam GetTeamOrDefault(IPlayer player,
PlayerTeam defaultTeam = PlayerTeam.Independent) {
return player != null ? player.GetTeam() : defaultTeam;
}
}
// ROCKET SHOES - Ebomb09
public class RocketShoes : Powerup {
private const uint EFFECT_COOLDOWN = 25;
private const float IMPULSE = 0.2f;
private IObject[] _feet;
private bool PlayerValid {
get {
return !Player.IsDisabled &&
!Player.IsLedgeGrabbing &&
!Player.IsClimbing &&
!Player.IsDiving &&
!Player.IsGrabbing &&
Player.IsInputEnabled;
}
}
private bool Rocketing {
get {
return PlayerValid && Player.KeyPressed(VirtualKey.JUMP);
}
}
private Vector2 Impulse {
get {
Vector2 impulse = new Vector2(0, Player.GetLinearVelocity().Y + IMPULSE);
impulse.X += Player.KeyPressed(VirtualKey.AIM_RUN_RIGHT) ? 1 :
(Player.KeyPressed(VirtualKey.AIM_RUN_LEFT) ? -1 : 0);
impulse.X *= Player.KeyPressed(VirtualKey.SPRINT) ? 2 :
(Player.KeyPressed(VirtualKey.WALKING) ? 0.5f : 1);
return impulse;
}
}
public override string Name {
get {
return "ROCKET SHOES";
}
}
public override string Author {
get {
return "Ebomb09";
}
}
public RocketShoes(IPlayer player) : base(player) {
Time = 20000; // 20 s
}
protected override void Activate() {
_feet = new IObject[] {
Game.CreateObject("InvisibleBlockNoCollision", Vector2.Zero, 3 / 2 * MathHelper.PI),
Game.CreateObject("InvisibleBlockNoCollision", Vector2.Zero, 3 / 2 * MathHelper.PI)
};
_feet[0].SetBodyType(BodyType.Dynamic);
_feet[1].SetBodyType(BodyType.Dynamic);
}
public override void Update(float dlt, float dltSecs) {
Vector2 playerPos = Player.GetWorldPosition();
foreach (IObject obj in _feet) {
obj.SetLinearVelocity(Player.GetLinearVelocity());
obj.SetAngle(
Vector2Helper.AngleToPoint(
playerPos,
playerPos - new Vector2(Player.GetLinearVelocity().X, Math.Abs(Player.GetLinearVelocity().Y))
)
);
}
_feet[0].SetWorldPosition(playerPos + new Vector2(-5, -2));
_feet[1].SetWorldPosition(playerPos + new Vector2(5, -2));
if (Rocketing) {
Player.SetLinearVelocity(Impulse);