7rodo

impnautractoruype

Jul 3rd, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. public class ImpactReactor extends PowerGenerator{
  2. public final int timerUse = timers++;
  3.  
  4. public float warmupSpeed = 0.001f;
  5. public float itemDuration = 60f;
  6. public int explosionRadius = 50;
  7. public int explosionDamage = 2000;
  8.  
  9. public Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
  10.  
  11. public @Load("@-bottom") TextureRegion bottomRegion;
  12. public @Load(value = "@-plasma-#", length = 4) TextureRegion[] plasmaRegions;
  13.  
  14. public ImpactReactor(String name){
  15. super(name);
  16. hasPower = true;
  17. hasLiquids = true;
  18. liquidCapacity = 30f;
  19. hasItems = true;
  20. outputsPower = consumesPower = true;
  21. }
  22.  
  23. @Override
  24. public void setBars(){
  25. super.setBars();
  26.  
  27. bars.add("poweroutput", (GeneratorEntity entity) -> new Bar(() ->
  28. Core.bundle.format("bar.poweroutput",
  29. Strings.fixed(Math.max(entity.getPowerProduction() - consumes.getPower().usage, 0) * 60 * entity.timeScale(), 1)),
  30. () -> Pal.powerBar,
  31. () -> entity.productionEfficiency));
  32. }
  33.  
  34. @Override
  35. public void setStats(){
  36. super.setStats();
  37.  
  38. if(hasItems){
  39. stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
  40. }
  41. }
  42.  
  43. @Override
  44. public TextureRegion[] icons(){
  45. return new TextureRegion[]{bottomRegion, region};
  46. }
  47.  
  48. public class FusionReactorEntity extends GeneratorEntity{
  49. public float warmup;
  50.  
  51.  
  52. @Override
  53. public void updateTile(){
  54. if(consValid() && power.status >= 0.99f){
  55. boolean prevOut = getPowerProduction() <= consumes.getPower().requestedPower(this);
  56.  
  57. warmup = Mathf.lerpDelta(warmup, 1f, warmupSpeed);
  58. if(Mathf.equal(warmup, 1f, 0.001f)){
  59. warmup = 1f;
  60. }
  61.  
  62. if(!prevOut && (getPowerProduction() > consumes.getPower().requestedPower(this))){
  63. Events.fire(Trigger.impactPower);
  64. }
  65.  
  66. if(timer(timerUse, itemDuration / timeScale())){
  67. consume();
  68. }
  69. }else{
  70. warmup = Mathf.lerpDelta(warmup, 0f, 0.01f);
  71. }
  72.  
  73. productionEfficiency = Mathf.pow(warmup, 5f);
  74. }
  75.  
  76. @Override
  77. public void draw(){
  78. Draw.rect(bottomRegion, x, y);
  79.  
  80. for(int i = 0; i < plasmaRegions.length; i++){
  81. float r = size * tilesize - 3f + Mathf.absin(Time.time(), 2f + i * 1f, 5f - i * 0.5f);
  82.  
  83. Draw.color(plasma1, plasma2, (float)i / plasmaRegions.length);
  84. Draw.alpha((0.3f + Mathf.absin(Time.time(), 2f + i * 2f, 0.3f + i * 0.05f)) * warmup);
  85. Draw.blend(Blending.additive);
  86. Draw.rect(plasmaRegions[i], x, y, r, r, Time.time() * (12 + i * 6f) * warmup);
  87. Draw.blend();
  88. }
  89.  
  90. Draw.color();
  91.  
  92. Draw.rect(region, x, y);
  93.  
  94. Draw.color();
  95. }
  96.  
  97. @Override
  98. public void drawLight(){
  99. Drawf.light(team, x, y, (110f + Mathf.absin(5, 5f)) * warmup, Tmp.c1.set(plasma2).lerp(plasma1, Mathf.absin(7f, 0.2f)), 0.8f * warmup);
  100. }
  101.  
  102. @Override
  103. public void onDestroyed(){
  104. super.onDestroyed();
  105.  
  106. if(warmup < 0.4f || !state.rules.reactorExplosions) return;
  107.  
  108. Sounds.explosionbig.at(tile);
  109.  
  110. Effects.shake(6f, 16f, x, y);
  111. Fx.impactShockwave.at(x, y);
  112. for(int i = 0; i < 6; i++){
  113. Time.run(Mathf.random(80), () -> Fx.impactcloud.at(x, y));
  114. }
  115.  
  116. Damage.damage(x, y, explosionRadius * tilesize, explosionDamage * 4);
  117.  
  118.  
  119. for(int i = 0; i < 20; i++){
  120. Time.run(Mathf.random(80), () -> {
  121. Tmp.v1.rnd(Mathf.random(40f));
  122. Fx.explosion.at(Tmp.v1.x + x, Tmp.v1.y + y);
  123. });
  124. }
  125.  
  126. for(int i = 0; i < 70; i++){
  127. Time.run(Mathf.random(90), () -> {
  128. Tmp.v1.rnd(Mathf.random(120f));
  129. Fx.impactsmoke.at(Tmp.v1.x + x, Tmp.v1.y + y);
  130. });
  131. }
  132. }
  133.  
  134. @Override
  135. public void write(Writes write){
  136. super.write(write);
  137. write.f(warmup);
  138. }
  139.  
  140. @Override
  141. public void read(Reads read, byte revision){
  142. super.read(read, revision);
  143. warmup = read.f();
  144. }
  145. }
  146. }
Add Comment
Please, Sign In to add comment