package com.qiwu.inference.dto; import com.qiwu.inference.common.Constants; import com.qiwu.inference.common.TimingAcquisition; import com.qiwu.inference.common.utils.FastJsonUtil; import com.qiwu.inference.common.utils.RandomUtil; import lombok.Getter; import lombok.Setter; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Getter @Setter public class Player { /** * 会话id */ private String sid; /** * 关卡编号 */ private String gateNo; /** * 关卡等级 */ private String level; /** * 当前等级通关总次数 */ private String total; /** * 当前关卡已完成次数 */ private String finished; /** * 玩家在线状态 */ private Integer status = Constants.OFFLINE; /** * 玩家上线时间 */ private String onlineTime; /** * 玩家下线时间 */ private String offlineTime; /** * 玩家所在场所 */ private String location; /** * 玩家当前对话的人物 */ private Integer personId; /** * 人物集合 */ private Map personMap; /** * 人物的姓名和编号转换 map */ private Map name2IdMap; /** * 当前关卡的货币 */ private Double currency = 1000.0; /** * 当前关卡的积分 */ private Integer point = 0; /** * 总货币 */ private Double totalCurrency = 0.0; /** * 总积分 */ private Integer totalPoint = 0; /** * 已获得人物线索: Map<人物id, Map<线索类型id, List<线索>>。没有线索则仅仅对话过 */ private Map>> clueMap = new HashMap<>(); /** * 线索集合表 */ private List clues = new ArrayList<>(); /** * 已完成任务集合表: Map<人物id, Map<任务id, 任务状态>> */ private Map> taskMap = new HashMap<>(); public Player(){ //初始化推理游戏人物 List keys = new ArrayList<>(TimingAcquisition.gateInfoMap.keySet()); int index = RandomUtil.randomInt(keys.size()); this.gateNo = keys.get(index); List personList = TimingAcquisition.gateInfoMap.get(keys.get(index)); personMap = new HashMap<>(); name2IdMap = new HashMap<>(); for (Person person : personList) { taskMap.put(person.getId(), new HashMap<>()); personMap.put(person.getId(), person); name2IdMap.put(person.getName(), person.getId()); } } /** * 读取json文件数据 * @param jsonPath json文件路径 * @return 字符串 */ private static String readJson(String jsonPath) { File jsonFile = new File(jsonPath); try { FileReader fileReader = new FileReader(jsonFile); BufferedReader reader = new BufferedReader(fileReader); StringBuilder sb = new StringBuilder(); while (true) { int ch = reader.read(); if (ch != -1) { sb.append((char) ch); } else { break; } } fileReader.close(); reader.close(); return sb.toString(); } catch (IOException e) { return ""; } } }