mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-14 03:49:13 +07:00
Fixed invalid healing effects
This commit is contained in:
parent
a7de30ba53
commit
8962992ef9
@ -49,7 +49,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||||||
transient float healTime;
|
transient float healTime;
|
||||||
private transient float resupplyTime = Mathf.random(10f);
|
private transient float resupplyTime = Mathf.random(10f);
|
||||||
private transient boolean wasPlayer;
|
private transient boolean wasPlayer;
|
||||||
private transient float lastHealth;
|
private transient boolean wasHealed;
|
||||||
|
|
||||||
public void moveAt(Vec2 vector){
|
public void moveAt(Vec2 vector){
|
||||||
moveAt(vector, type.accel);
|
moveAt(vector, type.accel);
|
||||||
@ -320,16 +320,23 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||||||
type.landed(self());
|
type.landed(self());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(float amount){
|
||||||
|
if(health < maxHealth && amount > 0){
|
||||||
|
wasHealed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
type.update(self());
|
type.update(self());
|
||||||
|
|
||||||
if(health > lastHealth && lastHealth > 0 && healTime <= -1f){
|
if(wasHealed && healTime <= -1f){
|
||||||
healTime = 1f;
|
healTime = 1f;
|
||||||
}
|
}
|
||||||
healTime -= Time.delta / 20f;
|
healTime -= Time.delta / 20f;
|
||||||
lastHealth = health;
|
wasHealed = false;
|
||||||
|
|
||||||
//check if environment is unsupported
|
//check if environment is unsupported
|
||||||
if(!type.supportsEnv(state.rules.environment) && !dead){
|
if(!type.supportsEnv(state.rules.environment) && !dead){
|
||||||
|
@ -188,24 +188,22 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> invalid){
|
public void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> invalid){
|
||||||
executor.submit(() -> {
|
try{
|
||||||
try{
|
DatagramSocket socket = new DatagramSocket();
|
||||||
DatagramSocket socket = new DatagramSocket();
|
long time = Time.millis();
|
||||||
long time = Time.millis();
|
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
|
||||||
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
|
socket.setSoTimeout(2000);
|
||||||
socket.setSoTimeout(2000);
|
|
||||||
|
|
||||||
DatagramPacket packet = packetSupplier.get();
|
DatagramPacket packet = packetSupplier.get();
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
||||||
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
|
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
|
||||||
|
|
||||||
Core.app.post(() -> valid.get(host));
|
Core.app.post(() -> valid.get(host));
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
Core.app.post(() -> invalid.get(e));
|
Core.app.post(() -> invalid.get(e));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,6 +5,7 @@ import arc.func.*;
|
|||||||
import arc.net.*;
|
import arc.net.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.async.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.net.Packets.*;
|
import mindustry.net.Packets.*;
|
||||||
import mindustry.net.Streamable.*;
|
import mindustry.net.Streamable.*;
|
||||||
@ -12,6 +13,7 @@ import mindustry.net.Streamable.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
import static arc.util.Log.*;
|
import static arc.util.Log.*;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
@ -31,6 +33,7 @@ public class Net{
|
|||||||
private final ObjectMap<Class<?>, Cons> clientListeners = new ObjectMap<>();
|
private final ObjectMap<Class<?>, Cons> clientListeners = new ObjectMap<>();
|
||||||
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
||||||
private final IntMap<StreamBuilder> streams = new IntMap<>();
|
private final IntMap<StreamBuilder> streams = new IntMap<>();
|
||||||
|
private final ExecutorService pingExecutor = Threads.executor(Math.max(Runtime.getRuntime().availableProcessors(), 6));
|
||||||
|
|
||||||
private final NetProvider provider;
|
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){
|
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);
|
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);
|
void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> failed);
|
||||||
|
|
||||||
/** Host a server at specified port. */
|
/** Host a server at specified port. */
|
||||||
|
@ -364,7 +364,7 @@ public class JoinDialog extends BaseDialog{
|
|||||||
for(String address : group.addresses){
|
for(String address : group.addresses){
|
||||||
String resaddress = address.contains(":") ? address.split(":")[0] : address;
|
String resaddress = address.contains(":") ? address.split(":")[0] : address;
|
||||||
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
|
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
|
||||||
net.pingHost(resaddress, resport, res -> {
|
net.pingHostThread(resaddress, resport, res -> {
|
||||||
if(refreshes != cur) return;
|
if(refreshes != cur) return;
|
||||||
res.port = resport;
|
res.port = resport;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user