Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 KB | None | 0 0
  1. using HBS.Logging;
  2. using HBS.DebugConsole;
  3. using HBS.Pooling;
  4. using MonoMod.ModInterop;
  5. using ZekesNewThrowables;
  6.  
  7. class SpawnRandomActor : PartialityMod
  8. {
  9. Dictionary<string, Action<TextFieldParser, EffectDef>> methodParsers;
  10.  
  11.  
  12.  
  13.  
  14. public override void Init()
  15. {
  16. typeof(Utils).ModInterop();
  17. On.Necro.DataManager.Awake += (orig, instance) =>
  18. {
  19. methodParsers = Utils.GetMethodParsers();
  20. methodParsers["SpawnRandomZeke"] = new Action<TextFieldParser, EffectDef>(this.ParseGameEffect_SpawnRandomZeke);
  21. methodParsers["SpawnMinionThrow"] = new Action<TextFieldParser, EffectDef>(this.ParseGameEffect_SpawnMinionThrow);
  22. orig(instance);
  23. };
  24. //this.name = "Zekes New Throwables";
  25. //this.version = "1.0";
  26. base.Init();
  27. }
  28.  
  29. public override void OnLoad()
  30. {
  31. //this.guiWindowProperties.windowRect.size = new Vector2(500, 500);
  32. base.OnLoad();
  33. }
  34.  
  35. /*
  36. public void LoadParsers(object[] funStuff)
  37. {
  38. methodParsers = Utils.GetMethodParsers();
  39. methodParsers["SpawnRandomZeke"] = new Action<TextFieldParser, EffectDef>(this.ParseGameEffect_SpawnRandomZeke);
  40. methodParsers["SpawnMinionThrow"] = new Action<TextFieldParser, EffectDef>(this.ParseGameEffect_SpawnMinionThrow);
  41. }*/
  42.  
  43. private void ParseGameEffect_SpawnRandomZeke(TextFieldParser parser, EffectDef def)
  44. {
  45. Debug.Log("Hey are you parsing SpawnRandomZeke?");
  46. def.worldMethod = CreateMethod_SpawnRandomZeke();
  47. }
  48.  
  49. private void ParseGameEffect_SpawnMinionThrow(TextFieldParser parser, EffectDef def)
  50. {
  51. Debug.Log("Hey are you parsing SpawnMinonThrow?");
  52. TagWeights tagWeights = LazySingletonBehavior<patch_DataManager>.Instance.ParseTagWeightsProxy(parser, "Params", true);
  53. if (tagWeights == null)
  54. {
  55. def.worldMethod = GameEffectManager.CreateMethod_LogMessage(LogLevel.Error, "Broken SpawnMinionThrow GameEffect for: " + def.id);
  56. }
  57. else
  58. {
  59. int level;
  60. string tagAndWeight = tagWeights.GetTagAndWeight(0, out level);
  61. def.worldMethod = CreateMethod_SpawnMinionThrow(tagAndWeight, level, LazySingletonBehavior<patch_DataManager>.Instance.TryParseFloatProxy(parser, "Radius", null), LazySingletonBehavior<patch_DataManager>.Instance.TryParseFloatProxy(parser, "Duration", null));
  62. }
  63. }
  64.  
  65. private static GameEffectWorldMethod CreateMethod_SpawnRandomZeke()
  66. {
  67. return delegate (EffectContext context)
  68. {
  69. if (!LazySingletonBehavior<NetworkManager>.Instance.IsSimulationServer)
  70. {
  71. return;
  72. }
  73. string actorId;
  74. if (System.DateTime.Now.Millisecond % 11 == 0)
  75. actorId = "CrystalMantis";
  76. else if (System.DateTime.Now.Millisecond % 10 == 0)
  77. actorId = "GemeaterWelpMinion";
  78. else if (System.DateTime.Now.Millisecond % 9 == 0)
  79. actorId = "GemeaterWelp";
  80. else if (System.DateTime.Now.Millisecond % 8 == 0)
  81. actorId = "DropSpiderlingMinion";
  82. else if (System.DateTime.Now.Millisecond % 7 == 0)
  83. {
  84. float random = UnityEngine.Random.value;
  85. if(random < 0.33)
  86. actorId = "ScroungeNormal";
  87. else if(random >= 0.33 && random <= 0.66)
  88. actorId = "ScroungeFull";
  89. else
  90. actorId = "ScroungeBomb";
  91. }
  92. else if (System.DateTime.Now.Millisecond % 6 == 0)
  93. actorId = "DropSpiderlingMinion";
  94. else if (System.DateTime.Now.Millisecond % 5 == 0)
  95. actorId = "DropSpiderling";
  96. else if (System.DateTime.Now.Millisecond % 4 == 0)
  97. actorId = "ShadowBornJuvenile";
  98. else if (System.DateTime.Now.Millisecond % 3 == 0)
  99. actorId = "ShadowBornMinion";
  100. else if (System.DateTime.Now.Millisecond % 2 == 0)
  101. actorId = "BoneEffigy";
  102. else
  103. actorId = "BoneMinion";
  104. LazySingletonBehavior<ActorManager>.Instance.Spawn(actorId, 0, Actor.Faction.Enemy, context.hitPoint, context.hitRot, null);
  105. Debug.Log("Thrown Mystery Spawn -" + actorId);
  106.  
  107. Debug.Log("Hey you did it!");
  108. };
  109. }
  110.  
  111. private static GameEffectWorldMethod CreateMethod_SpawnMinionThrow(string actorDefId, int level, float range, float amount)
  112. {
  113. return delegate (EffectContext context)
  114. {
  115. Actor sourceActor = context.sourceActor;
  116. WeaponBody sourceWeapon = context.sourceWeapon;
  117. if (!LazySingletonBehavior<NetworkManager>.Instance.IsSimulationServer)
  118. {
  119. return;
  120. }
  121. SpawnMinions spawnMinions = sourceWeapon as SpawnMinions;
  122. for (int i = 0; i < (int)amount; i++)
  123. {
  124. Vector3 zero = Vector3.zero;
  125. Quaternion rotation = sourceActor.Rotation;
  126. if (!SpatialUtil.TryFindRandomSpotCircle(context.hitPoint, sourceActor.Radius, range, sourceActor.Height, out zero))
  127. {
  128. Debug.Log("Couln't find valid spawn spot");
  129. }
  130. else
  131. {
  132. LazySingletonBehavior<ActorManager>.Instance.Spawn(actorDefId, level, sourceActor.faction, context.hitPoint, context.hitRot, delegate (Actor actor)
  133. {
  134. if (spawnMinions != null && spawnMinions.minionPrefab != null)
  135. {
  136. GameObject gameObject = spawnMinions.minionPrefab.Spawn(actor.transform);
  137. Minion component = gameObject.GetComponent<Minion>();
  138. if (component != null)
  139. {
  140. spawnMinions.AttachMinion(component);
  141. }
  142. }
  143. Debug.Log(string.Concat(new object[]
  144. {
  145. "Spawned ",
  146. actor.DebugName,
  147. " at ",
  148. actor.transform.position
  149. }), actor);
  150. });
  151. }
  152. }
  153. };
  154. }
  155.  
  156. /*
  157. public override void OnGUI(int windowID)
  158. {
  159. GUILayout.Label("Why hello there Adventurer! I'm glad my message has been able to reach you successfully. My name is Zeke, creator of all things strange yet throwable! " +
  160. Environment.NewLine + Environment.NewLine + " I know you're probably wondering, 'Why has the great and mystical Zeke sent for my attention?' Well it just so happens that that my apprentice has managed to sneak in my" +
  161. " new wares past Brazen's all seeing eye, so I'm here to spread the good news to you! You should start to see a few new recipies and throwables around, such as: "
  162. + Environment.NewLine + Environment.NewLine + "Zeke's Brash Hatch Jar" + Environment.NewLine + "Zeke's Mystery Hatch Jar");
  163. }
  164. */
  165.  
  166.  
  167.  
  168.  
  169. }
  170.  
  171. [MonoMod.MonoModPatch("global::Necro.DataManager")]
  172. public class patch_DataManager : DataManager
  173. {
  174. [MonoMod.MonoModIgnore]
  175. private extern TagWeights ParseTagWeights(TextFieldParser parser, string fieldName, bool nullIfEmpty);
  176.  
  177. [MonoMod.MonoModIgnore]
  178. private extern float TryParseFloat(TextFieldParser parser, string fieldName, string varGroup);
  179.  
  180.  
  181. public float TryParseFloatProxy(TextFieldParser parser, string fieldName, string varGroup)
  182. {
  183. return TryParseFloat(parser, fieldName, varGroup);
  184. }
  185.  
  186. public TagWeights ParseTagWeightsProxy(TextFieldParser parser, string fieldName, bool nullIfEmpty)
  187. {
  188. return ParseTagWeights(parser, fieldName, nullIfEmpty);
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement