Fixed invalid healing effects

This commit is contained in:
Anuken 2021-06-08 09:14:54 -04:00
parent a7de30ba53
commit 8962992ef9
4 changed files with 37 additions and 22 deletions

View File

@ -49,7 +49,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
transient float healTime;
private transient float resupplyTime = Mathf.random(10f);
private transient boolean wasPlayer;
private transient float lastHealth;
private transient boolean wasHealed;
public void moveAt(Vec2 vector){
moveAt(vector, type.accel);
@ -320,16 +320,23 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
type.landed(self());
}
@Override
public void heal(float amount){
if(health < maxHealth && amount > 0){
wasHealed = true;
}
}
@Override
public void update(){
type.update(self());
if(health > lastHealth && lastHealth > 0 && healTime <= -1f){
if(wasHealed && healTime <= -1f){
healTime = 1f;
}
healTime -= Time.delta / 20f;
lastHealth = health;
wasHealed = false;
//check if environment is unsupported
if(!type.supportsEnv(state.rules.environment) && !dead){

View File

@ -188,24 +188,22 @@ public class ArcNetProvider implements NetProvider{
@Override
public void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> invalid){
executor.submit(() -> {
try{
DatagramSocket socket = new DatagramSocket();
long time = Time.millis();
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
socket.setSoTimeout(2000);
try{
DatagramSocket socket = new DatagramSocket();
long time = Time.millis();
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
socket.setSoTimeout(2000);
DatagramPacket packet = packetSupplier.get();
socket.receive(packet);
DatagramPacket packet = packetSupplier.get();
socket.receive(packet);
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
Core.app.post(() -> valid.get(host));
}catch(Exception e){
Core.app.post(() -> invalid.get(e));
}
});
Core.app.post(() -> valid.get(host));
}catch(Exception e){
Core.app.post(() -> invalid.get(e));
}
}
@Override

View File

@ -5,6 +5,7 @@ import arc.func.*;
import arc.net.*;
import arc.struct.*;
import arc.util.*;
import arc.util.async.*;
import mindustry.gen.*;
import mindustry.net.Packets.*;
import mindustry.net.Streamable.*;
@ -12,6 +13,7 @@ import mindustry.net.Streamable.*;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.util.concurrent.*;
import static arc.util.Log.*;
import static mindustry.Vars.*;
@ -31,6 +33,7 @@ public class Net{
private final ObjectMap<Class<?>, Cons> clientListeners = new ObjectMap<>();
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
private final IntMap<StreamBuilder> streams = new IntMap<>();
private final ExecutorService pingExecutor = Threads.executor(Math.max(Runtime.getRuntime().availableProcessors(), 6));
private final NetProvider provider;
@ -316,10 +319,17 @@ public class Net{
}
/**
* Pings a host in an new thread. If an error occured, failed() should be called with the exception.
* Pings a host in a pooled thread. If an error occurred, failed() should be called with the exception.
*/
public void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> failed){
provider.pingHost(address, port, valid, failed);
pingExecutor.submit(() -> provider.pingHost(address, port, valid, failed));
}
/**
* Pings a host in an new thread. If an error occurred, failed() should be called with the exception.
*/
public void pingHostThread(String address, int port, Cons<Host> valid, Cons<Exception> failed){
Threads.daemon(() -> provider.pingHost(address, port, valid, failed));
}
/**
@ -367,7 +377,7 @@ public class Net{
*/
void discoverServers(Cons<Host> callback, Runnable done);
/** Ping a host. If an error occurred, failed() should be called with the exception. */
/** Ping a host. If an error occurred, failed() should be called with the exception. This method should block. */
void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> failed);
/** Host a server at specified port. */

View File

@ -364,7 +364,7 @@ public class JoinDialog extends BaseDialog{
for(String address : group.addresses){
String resaddress = address.contains(":") ? address.split(":")[0] : address;
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
net.pingHost(resaddress, resport, res -> {
net.pingHostThread(resaddress, resport, res -> {
if(refreshes != cur) return;
res.port = resport;