package com.huangzj.server.module;

import com.huangzj.base.module.GeneralModule;
import com.huangzj.base.module.ModuleMetricsProvider;
import com.huangzj.base.module.PlayerModule;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.stereotype.Component;

@Component
@PlayerModule(order = 20)
public class DemoAuxModule extends GeneralModule<DemoPlayerHost> implements ModuleMetricsProvider {

    private final AtomicLong tickCount = new AtomicLong();

    public DemoAuxModule(DemoPlayerHost host) {
        super(host);
        enableTick();
    }

    /** 与 SamplePlayerModule 同一个宿主，playerId 一致。 */
    @Override
    public long getPlayerId() {
        return getPlayer().getPlayerId();
    }

    @Override
    protected void tick(long runAt) {
        tickCount.incrementAndGet();
    }

    @Override
    public Map<String, Object> metrics() {
        Map<String, Object> m = new LinkedHashMap<>();
        m.put("auxTickCount", tickCount.get());
        return m;
    }
}
