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

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

View File

@@ -23,7 +23,7 @@ import static mindustry.Vars.*;
@Component
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 UnitType type;
@@ -85,16 +85,9 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
@Override
public void type(UnitType type){
this.type = type;
this.maxHealth = type.health;
this.drag = type.drag;
this.elevation = type.flying ? 1f : type.baseElevation;
this.armor = type.armor;
if(this.type == type) return;
heal();
hitSize(type.hitsize);
controller(type.createController());
setupWeapons(type);
setStats(type);
}
@Override
@@ -118,10 +111,28 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
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
public void afterRead(){
//set up type info after reading
type(this.type);
setStats(this.type);
}
@Override

View File

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

View File

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

View File

@@ -208,11 +208,8 @@ public class Block extends UnlockableContent{
public float percentSolid(int x, int y){
Tile tile = world.tile(x, y);
if(tile == null) return 0;
float sum = 0;
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
sum += !other.floor().isLiquid ? 1f : 0f;
}
return sum / size / size;
return tile.getLinkedTilesAs(this, tempTiles)
.sumf(other -> !other.floor().isLiquid ? 1f : 0f) / size / size;
}
/** 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){
Tile tile = world.tile(x, y);
if(tile == null) return 0;
float sum = 0;
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
sum += other.floor().attributes.get(attr);
}
return sum;
return tile.getLinkedTilesAs(this, tempTiles)
.sumf(other -> other.floor().attributes.get(attr));
}
public TextureRegion getDisplayIcon(Tile tile){
@@ -666,7 +660,7 @@ public class Block extends UnlockableContent{
outer:
for(int rx = -radius; rx <= radius; rx++){
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;
break outer;
}