Search in sources :

Example 1 with Player

use of io.anuke.mindustry.entities.Player in project Mindustry by Anuken.

the class PlayerListFragment method rebuild.

public void rebuild() {
    content.clear();
    float h = 74f;
    for (Player player : playerGroup.all()) {
        NetConnection connection = gwt ? null : Net.getConnection(player.clientid);
        if (connection == null && Net.server() && !player.isLocal)
            continue;
        Table button = new Table("button");
        button.left();
        button.margin(5).marginBottom(10);
        Stack stack = new Stack();
        BorderImage image = new BorderImage(Draw.region(player.isAndroid ? "ship-standard" : "mech-standard-icon"), 3f);
        stack.add(image);
        if (!player.isAndroid) {
            stack.add(new Element() {

                public void draw() {
                    float s = getWidth() / 12f;
                    for (int i : Mathf.signs) {
                        Draw.rect((i < 0 ? player.weaponLeft.name : player.weaponRight.name) + "-equip", x + s * 6 + i * 3 * s, y + s * 6 + 2 * s, -8 * s * i, 8 * s);
                    }
                }
            });
        }
        button.add(stack).size(h);
        button.labelWrap("[#" + player.getColor().toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
        button.add().grow();
        button.addImage("icon-admin").size(14 * 2).visible(() -> player.isAdmin && !(!player.isLocal && Net.server())).padRight(5);
        if ((Net.server() || Vars.player.isAdmin) && !player.isLocal && (!player.isAdmin || Net.server())) {
            button.add().growY();
            float bs = (h + 14) / 2f;
            button.table(t -> {
                t.defaults().size(bs - 1, bs + 3);
                t.addImageButton("icon-ban", 14 * 2, () -> {
                    ui.showConfirm("$text.confirm", "$text.confirmban", () -> {
                        if (Net.server()) {
                            netServer.admins.banPlayerIP(connection.address);
                            netServer.kick(player.clientid, KickReason.banned);
                        } else {
                            NetEvents.handleAdministerRequest(player, AdminAction.ban);
                        }
                    });
                }).padBottom(-5.1f);
                t.addImageButton("icon-cancel", 14 * 2, () -> {
                    if (Net.server()) {
                        netServer.kick(player.clientid, KickReason.kick);
                    } else {
                        NetEvents.handleAdministerRequest(player, AdminAction.kick);
                    }
                }).padBottom(-5.1f);
                t.row();
                t.addImageButton("icon-admin", "toggle", 14 * 2, () -> {
                    if (Net.client())
                        return;
                    String id = netServer.admins.getTrace(connection.address).uuid;
                    if (netServer.admins.isAdmin(id, connection.address)) {
                        ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
                            netServer.admins.unAdminPlayer(id);
                            NetEvents.handleAdminSet(player, false);
                        });
                    } else {
                        ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> {
                            netServer.admins.adminPlayer(id, connection.address);
                            NetEvents.handleAdminSet(player, true);
                        });
                    }
                }).update(b -> {
                    b.setChecked(player.isAdmin);
                    b.setDisabled(Net.client());
                }).get().setTouchable(() -> Net.client() ? Touchable.disabled : Touchable.enabled);
                t.addImageButton("icon-zoom-small", 14 * 2, () -> NetEvents.handleTraceRequest(player));
            }).padRight(12).padTop(-5).padLeft(0).padBottom(-10).size(bs + 10f, bs);
        }
        content.add(button).padBottom(-6).width(350f).maxHeight(h + 14);
        content.row();
    }
    content.marginBottom(5);
}
Also used : Player(io.anuke.mindustry.entities.Player) KickReason(io.anuke.mindustry.net.Packets.KickReason) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table) io.anuke.ucore.scene.builders.button(io.anuke.ucore.scene.builders.button) Bundles(io.anuke.ucore.util.Bundles) Stack(io.anuke.ucore.scene.ui.layout.Stack) Net(io.anuke.mindustry.net.Net) AdminAction(io.anuke.mindustry.net.Packets.AdminAction) NetEvents(io.anuke.mindustry.net.NetEvents) BorderImage(io.anuke.mindustry.ui.BorderImage) Draw(io.anuke.ucore.graphics.Draw) Element(io.anuke.ucore.scene.Element) NetConnection(io.anuke.mindustry.net.NetConnection) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) Table(io.anuke.ucore.scene.ui.layout.Table) Mathf(io.anuke.ucore.util.Mathf) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) Vars(io.anuke.mindustry.Vars) State(io.anuke.mindustry.core.GameState.State) Inputs(io.anuke.ucore.core.Inputs) Touchable(io.anuke.ucore.scene.event.Touchable) Player(io.anuke.mindustry.entities.Player) NetConnection(io.anuke.mindustry.net.NetConnection) Table(io.anuke.ucore.scene.ui.layout.Table) Element(io.anuke.ucore.scene.Element) BorderImage(io.anuke.mindustry.ui.BorderImage) Stack(io.anuke.ucore.scene.ui.layout.Stack)

Example 2 with Player

use of io.anuke.mindustry.entities.Player in project Mindustry by Anuken.

the class Placement method validPlace.

public static boolean validPlace(int x, int y, Block type) {
    for (int i = 0; i < world.getSpawns().size; i++) {
        SpawnPoint spawn = world.getSpawns().get(i);
        if (Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace) {
            return false;
        }
    }
    Recipe recipe = Recipes.getByResult(type);
    if (recipe == null || !state.inventory.hasItems(recipe.requirements)) {
        return false;
    }
    rect.setSize(type.width * tilesize, type.height * tilesize);
    Vector2 offset = type.getPlaceOffset();
    rect.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
    synchronized (Entities.entityLock) {
        for (SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
            // not sure why this happens?
            if (e == null)
                continue;
            Rectangle rect = e.hitbox.getRect(e.x, e.y);
            if (Placement.rect.overlaps(rect)) {
                return false;
            }
        }
    }
    if (type.solid || type.solidifes) {
        for (Player player : playerGroup.all()) {
            if (!player.isAndroid && rect.overlaps(player.hitbox.getRect(player.x, player.y))) {
                return false;
            }
        }
    }
    Tile tile = world.tile(x, y);
    if (tile == null || (isSpawnPoint(tile) && (type.solidifes || type.solid)))
        return false;
    if (type.isMultiblock()) {
        int offsetx = -(type.width - 1) / 2;
        int offsety = -(type.height - 1) / 2;
        for (int dx = 0; dx < type.width; dx++) {
            for (int dy = 0; dy < type.height; dy++) {
                Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
                if (other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) || isSpawnPoint(other)) {
                    return false;
                }
            }
        }
        return true;
    } else {
        return tile.block() != type && (type.canReplace(tile.block()) || tile.block().alwaysReplace) && tile.block().isMultiblock() == type.isMultiblock() || tile.block() == Blocks.air;
    }
}
Also used : Player(io.anuke.mindustry.entities.Player) SolidEntity(io.anuke.ucore.entities.SolidEntity) Recipe(io.anuke.mindustry.resource.Recipe) Vector2(com.badlogic.gdx.math.Vector2) Rectangle(com.badlogic.gdx.math.Rectangle) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 3 with Player

use of io.anuke.mindustry.entities.Player in project Mindustry by Anuken.

the class Renderer method drawOverlay.

void drawOverlay() {
    // draw tutorial placement point
    if (world.getMap().name.equals("tutorial") && control.tutorial().showBlock()) {
        int x = world.getCore().x + control.tutorial().getPlacePoint().x;
        int y = world.getCore().y + control.tutorial().getPlacePoint().y;
        int rot = control.tutorial().getPlaceRotation();
        Lines.stroke(1f);
        Draw.color(Color.YELLOW);
        Lines.square(x * tilesize, y * tilesize, tilesize / 2f + Mathf.sin(Timers.time(), 4f, 1f));
        Draw.color(Color.ORANGE);
        Lines.stroke(2f);
        if (rot != -1) {
            Lines.lineAngle(x * tilesize, y * tilesize, rot * 90, 6);
        }
        Draw.reset();
    }
    // draw config selected block
    if (ui.configfrag.isShown()) {
        Tile tile = ui.configfrag.getSelectedTile();
        Draw.color(Colors.get("accent"));
        Lines.stroke(1f);
        Lines.square(tile.drawx(), tile.drawy(), tile.block().width * tilesize / 2f + 1f);
        Draw.reset();
    }
    int tilex = control.input().getBlockX();
    int tiley = control.input().getBlockY();
    if (android) {
        Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
        tilex = Mathf.scl2(vec.x, tilesize);
        tiley = Mathf.scl2(vec.y, tilesize);
    }
    InputHandler input = control.input();
    // draw placement box
    if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android) && control.input().drawPlace())) {
        input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
        Lines.stroke(1f);
        Draw.color(Color.SCARLET);
        for (SpawnPoint spawn : world.getSpawns()) {
            Lines.dashCircle(spawn.start.worldx(), spawn.start.worldy(), enemyspawnspace);
        }
        if (world.getCore() != null) {
            Draw.color(Color.LIME);
            Lines.poly(world.getSpawnX(), world.getSpawnY(), 4, 6f, Timers.time() * 2f);
        }
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
    } else if (input.breakMode.delete && control.input().drawPlace() && (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements)) && (input.placeMode.delete || input.breakMode.both || !android)) {
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
        else
            input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
    }
    if (ui.toolfrag.confirming) {
        ToolFragment t = ui.toolfrag;
        PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
    }
    Draw.reset();
    // draw selected block bars and info
    if (input.recipe == null && !ui.hasMouse()) {
        Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
        if (tile != null && tile.block() != Blocks.air) {
            Tile target = tile;
            if (tile.isLinked())
                target = tile.getLinked();
            if (showBlockDebug && target.entity != null) {
                Draw.color(Color.RED);
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Vector2 v = new Vector2();
                Draw.tcolor(Color.YELLOW);
                Draw.tscl(0.25f);
                Array<Object> arr = target.block().getDebugInfo(target);
                StringBuilder result = new StringBuilder();
                for (int i = 0; i < arr.size / 2; i++) {
                    result.append(arr.get(i * 2));
                    result.append(": ");
                    result.append(arr.get(i * 2 + 1));
                    result.append("\n");
                }
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.color(0f, 0f, 0f, 0.5f);
                Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.tscl(fontscale);
                Draw.reset();
            }
            if (Inputs.keyDown("block_info") && target.block().fullDescription != null) {
                Draw.color(Colors.get("accent"));
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Draw.color();
            }
            if (target.entity != null) {
                int bot = 0, top = 0;
                for (BlockBar bar : target.block().bars) {
                    float offset = Mathf.sign(bar.top) * (target.block().height / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) + (bar.top ? -1f : 0f);
                    float value = bar.value.get(target);
                    if (MathUtils.isEqual(value, -1f))
                        continue;
                    drawBar(bar.color, target.drawx(), target.drawy() + offset, value);
                    if (bar.top)
                        top++;
                    else
                        bot++;
                }
            }
            target.block().drawSelect(target);
        }
    }
    if ((!debug || showUI) && Settings.getBool("healthbars")) {
        // draw entity health bars
        for (Enemy entity : enemyGroup.all()) {
            drawHealth(entity);
        }
        for (Player player : playerGroup.all()) {
            if (!player.isDead() && !player.isAndroid)
                drawHealth(player);
        }
    }
}
Also used : InputHandler(io.anuke.mindustry.input.InputHandler) Player(io.anuke.mindustry.entities.Player) Tile(io.anuke.mindustry.world.Tile) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) ToolFragment(io.anuke.mindustry.ui.fragments.ToolFragment) Vector2(com.badlogic.gdx.math.Vector2) Enemy(io.anuke.mindustry.entities.enemies.Enemy) BlockBar(io.anuke.mindustry.world.BlockBar) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 4 with Player

use of io.anuke.mindustry.entities.Player in project Mindustry by Anuken.

the class DamageArea method damage.

public static void damage(boolean enemies, float x, float y, float radius, int damage) {
    Consumer<SolidEntity> cons = entity -> {
        DestructibleEntity enemy = (DestructibleEntity) entity;
        if (enemy.distanceTo(x, y) > radius || (entity instanceof Player && ((Player) entity).isAndroid)) {
            return;
        }
        int amount = calculateDamage(x, y, enemy.x, enemy.y, radius, damage);
        enemy.damage(amount);
    };
    if (enemies) {
        Entities.getNearby(enemyGroup, x, y, radius * 2, cons);
    } else {
        int trad = (int) (radius / tilesize);
        for (int dx = -trad; dx <= trad; dx++) {
            for (int dy = -trad; dy <= trad; dy++) {
                Tile tile = world.tile(Mathf.scl2(x, tilesize) + dx, Mathf.scl2(y, tilesize) + dy);
                if (tile != null && tile.entity != null && Vector2.dst(dx, dy, 0, 0) <= trad) {
                    int amount = calculateDamage(x, y, tile.worldx(), tile.worldy(), radius, damage);
                    tile.entity.damage(amount);
                }
            }
        }
        Entities.getNearby(playerGroup, x, y, radius * 2, cons);
    }
}
Also used : Player(io.anuke.mindustry.entities.Player) Effects(io.anuke.ucore.core.Effects) Entity(io.anuke.ucore.entities.Entity) Tile(io.anuke.mindustry.world.Tile) Translator(io.anuke.ucore.util.Translator) Entities(io.anuke.ucore.entities.Entities) Physics(io.anuke.ucore.util.Physics) Rectangle(com.badlogic.gdx.math.Rectangle) Effect(io.anuke.ucore.core.Effects.Effect) Consumer(io.anuke.ucore.function.Consumer) Vector2(com.badlogic.gdx.math.Vector2) SolidEntity(io.anuke.ucore.entities.SolidEntity) DestructibleEntity(io.anuke.ucore.entities.DestructibleEntity) Mathf(io.anuke.ucore.util.Mathf) Vars(io.anuke.mindustry.Vars) DestructibleEntity(io.anuke.ucore.entities.DestructibleEntity) Player(io.anuke.mindustry.entities.Player) SolidEntity(io.anuke.ucore.entities.SolidEntity) Tile(io.anuke.mindustry.world.Tile)

Example 5 with Player

use of io.anuke.mindustry.entities.Player in project Mindustry by Anuken.

the class DamageArea method damageEntities.

public static void damageEntities(float x, float y, float radius, int damage) {
    damage(true, x, y, radius, damage);
    for (Player player : playerGroup.all()) {
        if (player.isAndroid)
            continue;
        int amount = calculateDamage(x, y, player.x, player.y, radius, damage);
        player.damage(amount);
    }
}
Also used : Player(io.anuke.mindustry.entities.Player)

Aggregations

Player (io.anuke.mindustry.entities.Player)10 Vector2 (com.badlogic.gdx.math.Vector2)3 Tile (io.anuke.mindustry.world.Tile)3 Rectangle (com.badlogic.gdx.math.Rectangle)2 Vars (io.anuke.mindustry.Vars)2 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)2 PlayerInfo (io.anuke.mindustry.net.Administration.PlayerInfo)2 NetConnection (io.anuke.mindustry.net.NetConnection)2 SolidEntity (io.anuke.ucore.entities.SolidEntity)2 ScrollPane (io.anuke.ucore.scene.ui.ScrollPane)2 Table (io.anuke.ucore.scene.ui.layout.Table)2 Mathf (io.anuke.ucore.util.Mathf)2 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)1 State (io.anuke.mindustry.core.GameState.State)1 Enemy (io.anuke.mindustry.entities.enemies.Enemy)1 Difficulty (io.anuke.mindustry.game.Difficulty)1 GameMode (io.anuke.mindustry.game.GameMode)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 Net (io.anuke.mindustry.net.Net)1 NetEvents (io.anuke.mindustry.net.NetEvents)1