Some initial multiplayer bugfixes

This commit is contained in:
Anuken
2020-06-23 20:01:55 -04:00
parent fc8e1d5b6d
commit d095008e7c
6 changed files with 38 additions and 25 deletions

View File

@@ -142,7 +142,13 @@ public class EntityIO{
io(field.type, "this." + (sf ? field.name + targetSuf : field.name) + " = "); io(field.type, "this." + (sf ? field.name + targetSuf : field.name) + " = ");
if(sl) econt(); if(sl){
ncont("else" );
st("read.f()");
econt();
}
} }
st("afterSync()"); st("afterSync()");

View File

@@ -113,6 +113,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
//(this is not for balance) //(this is not for balance)
deathTimer += Time.delta(); deathTimer += Time.delta();
if(deathTimer >= deathDelay){ if(deathTimer >= deathDelay){
//request spawn - this happens serverside only
core.requestSpawn((Playerc)this); core.requestSpawn((Playerc)this);
deathTimer = 0; deathTimer = 0;
} }

View File

@@ -23,7 +23,7 @@ import static mindustry.Vars.*;
@Component @Component
abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Displayable{ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Displayable{
@Import float x, y, rotation, elevation, maxHealth, drag, armor; @Import float x, y, rotation, elevation, maxHealth, drag, armor, hitSize;
private UnitController controller; private UnitController controller;
private UnitType type; private UnitType type;
@@ -85,16 +85,9 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
@Override @Override
public void type(UnitType type){ public void type(UnitType type){
this.type = type; if(this.type == type) return;
this.maxHealth = type.health;
this.drag = type.drag;
this.elevation = type.flying ? 1f : type.baseElevation;
this.armor = type.armor;
heal(); setStats(type);
hitSize(type.hitsize);
controller(type.createController());
setupWeapons(type);
} }
@Override @Override
@@ -118,10 +111,28 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
return controller instanceof AIController; return controller instanceof AIController;
} }
private void setStats(UnitType type){
this.type = type;
this.maxHealth = type.health;
this.drag = type.drag;
this.elevation = type.flying ? 1f : type.baseElevation;
this.armor = type.armor;
this.hitSize = type.hitsize;
if(controller == null) controller(type.createController());
if(mounts().length != type.weapons.size) setupWeapons(type);
}
@Override
public void afterSync(){
//set up type info after reading
setStats(this.type);
}
@Override @Override
public void afterRead(){ public void afterRead(){
//set up type info after reading //set up type info after reading
type(this.type); setStats(this.type);
} }
@Override @Override

View File

@@ -245,8 +245,8 @@ public class TypeIO{
if(type == 0){ //is player if(type == 0){ //is player
int id = read.i(); int id = read.i();
Playerc player = Groups.player.getByID(id); Playerc player = Groups.player.getByID(id);
//local players will cause problems if assigned, since they may not know they are controlling the unit //make sure player exists
if(player == null || player.isLocal()) return prev; if(player == null) return prev;
return player; return player;
}else if(type == 1){ }else if(type == 1){
int id = read.i(); int id = read.i();

View File

@@ -89,6 +89,7 @@ public class UnitType extends UnlockableContent{
unit.team(team); unit.team(team);
unit.type(this); unit.type(this);
unit.ammo(ammoCapacity); //fill up on ammo upon creation unit.ammo(ammoCapacity); //fill up on ammo upon creation
unit.heal();
return unit; return unit;
} }

View File

@@ -208,11 +208,8 @@ public class Block extends UnlockableContent{
public float percentSolid(int x, int y){ public float percentSolid(int x, int y){
Tile tile = world.tile(x, y); Tile tile = world.tile(x, y);
if(tile == null) return 0; if(tile == null) return 0;
float sum = 0; return tile.getLinkedTilesAs(this, tempTiles)
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ .sumf(other -> !other.floor().isLiquid ? 1f : 0f) / size / size;
sum += !other.floor().isLiquid ? 1f : 0f;
}
return sum / size / size;
} }
/** Drawn when you are placing a block. */ /** Drawn when you are placing a block. */
@@ -253,11 +250,8 @@ public class Block extends UnlockableContent{
public float sumAttribute(Attribute attr, int x, int y){ public float sumAttribute(Attribute attr, int x, int y){
Tile tile = world.tile(x, y); Tile tile = world.tile(x, y);
if(tile == null) return 0; if(tile == null) return 0;
float sum = 0; return tile.getLinkedTilesAs(this, tempTiles)
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ .sumf(other -> other.floor().attributes.get(attr));
sum += other.floor().attributes.get(attr);
}
return sum;
} }
public TextureRegion getDisplayIcon(Tile tile){ public TextureRegion getDisplayIcon(Tile tile){
@@ -666,7 +660,7 @@ public class Block extends UnlockableContent{
outer: outer:
for(int rx = -radius; rx <= radius; rx++){ for(int rx = -radius; rx <= radius; rx++){
for(int ry = -radius; ry <= radius; ry++){ for(int ry = -radius; ry <= radius; ry++){
if(Structs.inBounds(rx + x, ry + y, region.width, region.height) && Mathf.dst2(rx, ry) <= radius*radius && color.set(region.getPixel(rx + x, ry + y)).a > 0.01f){ if(Structs.inBounds(rx + x, ry + y, region.width, region.height) && Mathf.within(rx, ry, radius) && color.set(region.getPixel(rx + x, ry + y)).a > 0.01f){
found = true; found = true;
break outer; break outer;
} }