/**
 *
 */
package com.xiugou.x1.game.server.module.battle.service;

import com.xiugou.x1.battle.constant.SpriteType;
import com.xiugou.x1.battle.sprite.Sprite;
import com.xiugou.x1.design.module.RobotListCache;
import com.xiugou.x1.design.module.autogen.RobotListAbstractCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiugou.x1.game.server.foundation.player.PlayerContext;
import com.xiugou.x1.game.server.foundation.player.PlayerContextManager;
import com.xiugou.x1.game.server.module.battle.message.BattleTickMessage;

import java.util.HashMap;
import java.util.Map;

/**
 * @author YY
 *
 */
@Service
public class BattleService {

    @Autowired
    private PlayerContextManager playerContextManager;

    @Autowired
    private RobotListCache robotListCache;

    protected void runInSchedule() {
        for (PlayerContext playerContext : playerContextManager.onlines()) {
            playerContext.tell(BattleTickMessage.of(playerContext.getId()));
        }
    }

    //获取机器人
    public Map<Integer, Sprite> getRobotList() {
        Map<Integer, Sprite> allSpriteMap = new HashMap<>();
        int count = 0;
        for (RobotListAbstractCache.RobotListCfg config : robotListCache.all()) {
            if (count > 10) break;
            Sprite sprite = new Sprite(config.getId(), SpriteType.HERO);
            sprite.setLevel(config.getLv());
            allSpriteMap.put(config.getId(), sprite);
            count++;
        }
        return allSpriteMap;
    }
}
