| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import { DataSystem } from "../../core/data/DataSystem";
- import { MapData } from "../../core/data/MapData";
- import { Http } from "../../core/net/Http";
- import { ConfigData } from "../../data/ConfigData";
- /**
- * 阵位数据
- * @description 阵位编号为key,武将数据为value
- * @author 袁浩
- */
- export class FormationData extends MapData<number, number> {
- /**
- * 从服务端拉取数据
- * @param http
- */
- public async pull(http: Http) {
- let result = await http.send("/api/formation/GetFormation");
- if (result && result.data) {
- this.set(1, null);
- this.set(2, null);
- this.set(3, null);
- this.set(4, null);
- this.set(5, null);
- this.copy(result.data);
- }
- }
- /**
- * 根据武将编号获取阵位
- * @param heroID 武将编号
- * @returns 返回1就是1号位,返回0就是武将不在阵上
- */
- public getIDByHero(heroID: number) {
- let obj = this.object;
- for (let key in obj) {
- if (parseInt(obj[key]) == heroID) {
- return parseInt(key);
- }
- }
- return 0;
- }
- /**
- * 根据武将编号获取下一个武将
- * @param heroID
- */
- public nextHexo(heroID: number) {
- let id = this.getIDByHero(heroID);
- while (true) {
- id = id == 5 ? 1 : id + 1;
- if (this.get(id)) {
- return this.get(id);
- }
- }
- }
- /**
- * 根据武将编号获取上一个武将
- * @param heroID
- */
- public preHero(heroID: number) {
- let id = this.getIDByHero(heroID);
- while (true) {
- id = id == 1 ? 5 : id - 1;
- if (this.get(id)) {
- return this.get(id);
- }
- }
- }
- /**
- * 羁绊配置获取
- */
- public getFetter() {
- let campCount: any = {};
- let formationData = this.object;
- for (let key in formationData) {
- if (formationData[key]) {
- let heroConfig = DataSystem.getData(ConfigData).get("general")[formationData[key]];
- console.log("Config: ",heroConfig);
- campCount[heroConfig.camp] = campCount[heroConfig.camp] || 0;
- campCount[heroConfig.camp]++;
- }
- }
- let countList: { camp: number, count: number }[] = [];
- for (let key in campCount) {
- countList.push({ camp: parseInt(key), count: campCount[key] });
- }
- countList.sort((a: { camp: number, count: number }, b: { camp: number, count: number }) => {
- return b.count - a.count;
- });
- let fetterID = 0;
- let attackPer = 0;
- let cri = 0;
- let nationID = 0;
- if (countList.length) {
- let camp = 0;
- if (countList[0].count == 2) {
- fetterID = 1;
- camp = countList[0].camp;
- }
- else if (countList[0].count == 4) {
- fetterID = 4;
- camp = countList[0].camp;
- }
- else if (countList[0].count == 5) {
- fetterID = 5;
- camp = countList[0].camp;
- }
- else if (countList[0].count == 3 && countList[1] && countList[1].count == 2) {
- fetterID = 3;
- camp = countList[0].camp;
- }
- else if (countList[0].count == 3) {
- fetterID = 2;
- camp = countList[0].camp;
- }
- if (fetterID) {
- let fetterConfig = DataSystem.getData(ConfigData).get("fetter")[fetterID];
- let buffConfig = DataSystem.getData(ConfigData).get("buff");
- let buffList = fetterConfig.activeBuff.split(",");
- for (let i = 0; i < buffList.length; i++) {
- attackPer += (buffConfig[buffList[i]].attackPer || 0);
- cri += (buffConfig[buffList[i]].cri || 0);
- }
- if (fetterConfig.nation) {
- let nationBuff = buffConfig[fetterConfig.nation.split(",")[camp - 1]];
- nationID = nationBuff.id;
- }
- }
- }
- return { fetterID: fetterID, attackPer: attackPer, cri: cri, nationID: nationID };
- }
- }
|