Guest User

Silly RPG Artifact Manager

a guest
Feb 19th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. class SillyRPGArtifactManager extends Info
  2. placeable;
  3.  
  4. struct ArtifactChance
  5. {
  6. var() class<RPGArtifact> ArtifactClass;
  7. var() int Chance;
  8. var() int MaxArtifacts;
  9. var() int LifeSpan;
  10. var int ArtifactsCreated;
  11. };
  12.  
  13. var() int ArtifactDelay; //spawn an artifact every this many seconds - zero disables
  14. var() array<ArtifactChance> AvailableArtifacts;
  15. var int TotalArtifactChance; // precalculated total Chance of all artifacts
  16. var array<PathNode> PathNodes;
  17.  
  18.  
  19. function PostBeginPlay()
  20. {
  21. local NavigationPoint N;
  22. local int x;
  23.  
  24. Super.PostBeginPlay();
  25.  
  26. for (x = 0; x < AvailableArtifacts.length; x++)
  27. if (AvailableArtifacts[x].ArtifactClass == None)
  28. {
  29. AvailableArtifacts.Remove(x, 1);
  30. x--;
  31. }
  32.  
  33. if (ArtifactDelay > 0 && AvailableArtifacts.length > 0)
  34. {
  35. for (N = Level.NavigationPointList; N != None; N = N.NextNavigationPoint)
  36. if (PathNode(N) != None && !N.IsA('FlyingPathNode'))
  37. PathNodes[PathNodes.length] = PathNode(N);
  38.  
  39. for (x = 0; x < AvailableArtifacts.length; x++)
  40. {
  41. TotalArtifactChance += AvailableArtifacts[x].Chance;
  42. }
  43. if (TotalArtifactChance <= 0)
  44. Destroy();
  45. }
  46. else
  47. Destroy();
  48. }
  49.  
  50. function MatchStarting()
  51. {
  52. SetTimer(ArtifactDelay, true);
  53. }
  54.  
  55. // select a random artifact based on the Chance entries in the artifact list and return its index
  56. function int GetRandomArtifactIndex()
  57. {
  58. local int i;
  59. local int Chance;
  60.  
  61. Chance = Rand(TotalArtifactChance);
  62. for (i = 0; i < AvailableArtifacts.Length; i++)
  63. {
  64. Chance -= AvailableArtifacts[i].Chance;
  65. if (Chance < 0)
  66. {
  67. return i;
  68. }
  69. }
  70. }
  71.  
  72. function Timer()
  73. {
  74. local int Chance;
  75.  
  76. Chance = GetRandomArtifactIndex();
  77. SpawnArtifact(Chance);
  78. }
  79.  
  80. function SpawnArtifact(int Index)
  81. {
  82. local Pickup APickup;
  83.  
  84. if (AvailableArtifacts[Index].MaxArtifacts <=0 || AvailableArtifacts[Index].MaxArtifacts > AvailableArtifacts[Index].ArtifactsCreated)
  85. {
  86. APickup = spawn(AvailableArtifacts[Index].ArtifactClass.default.PickupClass,,, PathNodes[Rand(PathNodes.length)].Location);
  87. if (APickup == None)
  88. return;
  89. APickup.RespawnEffect();
  90. APickup.RespawnTime = 0.0;
  91. APickup.AddToNavigation();
  92. APickup.bDropped = true;
  93. APickup.SetTimer(AvailableArtifacts[Index].LifeSpan, false);
  94. AvailableArtifacts[Index].ArtifactsCreated ++;
  95. }
  96.  
  97. }
  98.  
  99.  
  100. defaultproperties
  101. {
  102. ArtifactDelay=30
  103. AvailableArtifacts(0)=(ArtifactClass=Class'SillyRPGv1-1.ArtifactWeaponBasePlacer',Chance=1,MaxArtifacts=0,LifeSpan=120,ArtifactsCreated=0)
  104. bBlockZeroExtentTraces=False
  105. bBlockNonZeroExtentTraces=False
  106. }
Advertisement
Add Comment
Please, Sign In to add comment