package com.openosrs.client.core;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * OtherPlayer - Represents another player in the game world.
 */
public class OtherPlayer {
    private final int index;
    private final AtomicReference<String> username = new AtomicReference<>();
    private final AtomicInteger x = new AtomicInteger();
    private final AtomicInteger y = new AtomicInteger();
    private final AtomicInteger plane = new AtomicInteger();
    private final AtomicInteger combatLevel = new AtomicInteger();
    
    private final AtomicInteger animationId = new AtomicInteger(-1);
    private final AtomicInteger graphicId = new AtomicInteger(-1);
    private final AtomicInteger orientation = new AtomicInteger(0);
    private final AtomicReference<String> overheadText = new AtomicReference<>("");
    
    public OtherPlayer(int index, String username, int x, int y, int plane, int combatLevel) {
        this.index = index;
        this.username.set(username);
        this.x.set(x);
        this.y.set(y);
        this.plane.set(plane);
        this.combatLevel.set(combatLevel);
    }
    
    public void tick() {
        // Update player state each game tick
    }
    
    public void setPosition(int x, int y) {
        this.x.set(x);
        this.y.set(y);
    }
    
    public void setPosition(int x, int y, int plane) {
        this.x.set(x);
        this.y.set(y);
        this.plane.set(plane);
    }
    
    public int getIndex() { return index; }
    public String getUsername() { return username.get(); }
    public int getX() { return x.get(); }
    public int getY() { return y.get(); }
    public int getPlane() { return plane.get(); }
    public int getCombatLevel() { return combatLevel.get(); }
    
    public void setAnimation(int animationId) { this.animationId.set(animationId); }
    public void setGraphic(int graphicId) { this.graphicId.set(graphicId); }
    public void setOrientation(int orientation) { this.orientation.set(orientation); }
    public void setOverheadText(String text) { this.overheadText.set(text != null ? text : ""); }
    
    public int getAnimationId() { return animationId.get(); }
    public int getGraphicId() { return graphicId.get(); }
    public int getOrientation() { return orientation.get(); }
    public String getOverheadText() { return overheadText.get(); }
    
    @Override
    public String toString() {
        return String.format("Player[%d] '%s' pos=(%d,%d,%d) cb=%d", 
            index, username.get(), x.get(), y.get(), plane.get(), combatLevel.get());
    }
}