Initial core unit dock implementation

This commit is contained in:
Anuken
2022-02-06 22:05:43 -05:00
parent ce82b3943e
commit 1fb88c13b0
5 changed files with 64 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ import mindustry.world.blocks.ConstructBlock.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.blocks.payloads.*;
import mindustry.world.blocks.storage.*;
import mindustry.world.meta.*;
import java.util.*;
@@ -419,8 +420,21 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
player.justSwitchTo = unit;
}
//TODO range check for docking
var before = player.unit();
player.unit(unit);
//TODO test this in multiplayer
if(unit.type.coreUnitDock && before != null && !before.isNull()){
if(before.spawnedByCore){
unit.dockedType = before.type;
}else if(before.dockedType != null){
//direct dock transfer???
unit.dockedType = before.dockedType;
}
}
Time.run(Fx.unitSpirit.lifetime, () -> Fx.unitControl.at(unit.x, unit.y, 0f, unit));
if(!player.dead()){
Fx.unitSpirit.at(player.x, player.y, 0f, unit);
@@ -437,6 +451,38 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public static void unitClear(Player player){
if(player == null) return;
//TODO test this in multiplayer
if(!player.dead() && player.unit().type.coreUnitDock && !player.unit().spawnedByCore){
//TODO respawn ON the unit, with an animation?
var docked = player.unit().dockedType;
if(docked == null){
var closest = player.bestCore();
if(closest != null){
docked = ((CoreBlock)closest.block).unitType;
}
}
if(docked != null){
//TODO animation, etc
Fx.spawn.at(player);
if(!net.client()){
Unit unit = docked.create(player.team());
unit.set(player.unit());
unit.rotation(player.unit().rotation);
//unit.impulse(0f, -3f);
//TODO should there be an impulse?
unit.controller(player);
unit.spawnedByCore(true);
unit.add();
}
return;
}
}
//should only get to this code if docking failed or this isn't a docking unit
//problem: this gets called on both ends. it shouldn't be.
Fx.spawn.at(player);
player.clearUnit();