Events, triggers
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
|
||||
import static io.anuke.mindustry.Vars.waveTeam;
|
||||
|
||||
public class StatusEffects implements ContentList{
|
||||
public static StatusEffect none, burning, freezing, wet, melting, tarred, overdrive, shielded, shocked, corroded, boss;
|
||||
|
||||
@@ -37,7 +41,12 @@ public class StatusEffects implements ContentList{
|
||||
speedMultiplier = 0.9f;
|
||||
effect = Fx.wet;
|
||||
|
||||
trans(() -> shocked, ((unit, time, newTime, result) -> unit.damage(20f)));
|
||||
trans(() -> shocked, ((unit, time, newTime, result) -> {
|
||||
unit.damage(20f);
|
||||
if(unit.getTeam() == waveTeam){
|
||||
Events.fire(Trigger.shock);
|
||||
}
|
||||
}));
|
||||
opposite(() -> burning);
|
||||
}};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import io.anuke.annotations.Annotations.*;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
@@ -10,9 +11,9 @@ import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.impl.*;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.net.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -70,7 +71,11 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait{
|
||||
*/
|
||||
public static void extinguish(Tile tile, float intensity){
|
||||
if(tile != null && map.containsKey(tile.pos())){
|
||||
map.get(tile.pos()).time += intensity * Time.delta();
|
||||
Fire fire = map.get(tile.pos());
|
||||
fire.time += intensity * Time.delta();
|
||||
if(fire.time >= fire.lifetime()){
|
||||
Events.fire(Trigger.fireExtinguish);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import io.anuke.annotations.Annotations.*;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
@@ -9,6 +10,44 @@ import io.anuke.mindustry.entities.type.Player;
|
||||
|
||||
public class EventType{
|
||||
|
||||
//events that occur very often
|
||||
public enum Trigger{
|
||||
shock,
|
||||
impactPower,
|
||||
thoriumReactorOverheat,
|
||||
itemLaunch,
|
||||
fireExtinguish
|
||||
}
|
||||
|
||||
//TODO
|
||||
public static class WinEvent{}
|
||||
|
||||
//TODO
|
||||
public static class LoseEvent{}
|
||||
|
||||
//TODO
|
||||
public static class LaunchEvent{}
|
||||
|
||||
//TODO
|
||||
public static class PlayerDeathEvent{}
|
||||
|
||||
//TODO
|
||||
public static class MapMakeEvent{}
|
||||
|
||||
//TODO
|
||||
public static class MapPublishEvent{}
|
||||
|
||||
//TODO
|
||||
public static class PlayerChatEvent{
|
||||
public final Player player;
|
||||
public final String message;
|
||||
|
||||
public PlayerChatEvent(Player player, String message){
|
||||
this.player = player;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when a zone's requirements are met. */
|
||||
public static class ZoneRequireCompleteEvent{
|
||||
public final Zone zone, required;
|
||||
@@ -137,11 +176,13 @@ public class EventType{
|
||||
public static class BlockBuildEndEvent{
|
||||
public final Tile tile;
|
||||
public final Team team;
|
||||
public final @Nullable Player player;
|
||||
public final boolean breaking;
|
||||
|
||||
public BlockBuildEndEvent(Tile tile, Team team, boolean breaking){
|
||||
public BlockBuildEndEvent(Tile tile, @Nullable Player player, Team team, boolean breaking){
|
||||
this.tile = tile;
|
||||
this.team = team;
|
||||
this.player = player;
|
||||
this.breaking = breaking;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onDeconstructFinish(Tile tile, Block block){
|
||||
public static void onDeconstructFinish(Tile tile, Block block, int builderID){
|
||||
Team team = tile.getTeam();
|
||||
Effects.effect(Fx.breakBlock, tile.drawx(), tile.drawy(), block.size);
|
||||
world.removeBlock(tile);
|
||||
Events.fire(new BlockBuildEndEvent(tile, team, true));
|
||||
Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, true));
|
||||
Sounds.breaks.at(tile, Mathf.random(0.7f, 1.4f));
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class BuildBlock extends Block{
|
||||
//event first before they can recieve the placed() event modification results
|
||||
Core.app.post(() -> tile.block().playerPlaced(tile));
|
||||
}
|
||||
Core.app.post(() -> Events.fire(new BlockBuildEndEvent(tile, team, false)));
|
||||
Core.app.post(() -> Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, false)));
|
||||
Sounds.place.at(tile, Mathf.random(0.7f, 1.4f));
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public class BuildBlock extends Block{
|
||||
progress = Mathf.clamp(progress - amount);
|
||||
|
||||
if(progress <= 0 || state.rules.infiniteResources){
|
||||
Call.onDeconstructFinish(tile, this.cblock == null ? previous : this.cblock);
|
||||
Call.onDeconstructFinish(tile, this.cblock == null ? previous : this.cblock, builderID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
@@ -71,11 +72,17 @@ public class ImpactReactor extends PowerGenerator{
|
||||
FusionReactorEntity entity = tile.entity();
|
||||
|
||||
if(entity.cons.valid() && entity.power.satisfaction >= 0.99f){
|
||||
boolean prevOut = getPowerProduction(tile) <= consumes.getPower().requestedPower(entity);
|
||||
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||
if(Mathf.isEqual(entity.warmup, 1f, 0.001f)){
|
||||
entity.warmup = 1f;
|
||||
}
|
||||
|
||||
if(!prevOut && (getPowerProduction(tile) <= consumes.getPower().requestedPower(entity))){
|
||||
Events.fire(Trigger.impactPower);
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerUse, itemDuration / entity.timeScale)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
@@ -10,6 +10,7 @@ import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
@@ -111,6 +112,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
entity.heat = Mathf.clamp(entity.heat);
|
||||
|
||||
if(entity.heat >= 0.999f){
|
||||
Events.fire(Trigger.thoriumReactorOverheat);
|
||||
entity.kill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ public class PowerNode extends PowerBlock{
|
||||
float fract = 1f-tile.entity.power.graph.getSatisfaction();
|
||||
|
||||
Draw.color(Color.white, Pal.powerLight, fract*0.86f + Mathf.absin(3f, 0.1f));
|
||||
Drawf.laser(laser, laserEnd, x1, y1, x2, y2, 0.4f);
|
||||
Drawf.laser(laser, laserEnd, x1, y1, x2, y2, 0.3f);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.storage;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
@@ -8,6 +9,7 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemType;
|
||||
@@ -73,6 +75,7 @@ public class LaunchPad extends StorageBlock{
|
||||
|
||||
if(entity.cons.valid() && world.isZone() && entity.items.total() >= itemCapacity && entity.timer.get(timerLaunch, launchTime / entity.timeScale)){
|
||||
for(Item item : Vars.content.items()){
|
||||
Events.fire(Trigger.itemLaunch);
|
||||
Effects.effect(Fx.padlaunch, tile);
|
||||
data.addItem(item, entity.items.get(item));
|
||||
entity.items.set(item, 0);
|
||||
|
||||
Reference in New Issue
Block a user