2025-04-24 17:03:28 +08:00

399 lines
13 KiB
JavaScript

import GameModel from "../ts/core/GameModel";
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
import VIPUtil from "../ts/game/role/VIPUtil";
import TeamPanel from "../ts/team/TeamPanel";
import FGAlert from "../ts/gear_2.3.4/fgui/FGAlert";
import MyModel from "../ts/core/MyModel";
export default class Player {
constructor(id) {
this.accountid = id;
this.serverid = 0;
this.onlyid = 0;
this.roleid = 0;
this.account = '';
this.token = '';
this.state = 0;
this.name = 0;
this.race = 0;
this.sex = 0;
this.mapid = 0;
this.x = 0;
this.y = 0;
this.relive = 0;
this.level = 0;
this.fplevel = 0;
this.level_reward = '';
this.weapon = '';
this.state = 0;
this.resid = 0;
this.tResid = 0;
this.bangid = 0;
this.bangdata = null;
this.chargesum = 0;
this.rewardrecord = 0;
this.sprewardrecord = 0;
this.exp = 0;
this.maxexp = 0;
this.node = null;
this.maxChatItems = 50;
this.chatItemList = {};
this.unreadInfoId = {};
this.teamInfo = {};
this.teamid = 0;
this.isleader = false;
this.livingtype = 1;
this.qianneng = 0;
this.gmlevel = 0;
// this.shane = 0;
this.prisonTime = 0;
this.itemList = {};
//稱謂
this.titleid = 0;
this.titletype = -1;
this.titleval = '';
this.bangname = '';
this.color1 = 0;
this.color2 = 0;
this.schemename = '';
this.safe_password = '';
this.safe_lock = 0;
this.wingId = 0;
// 背包格子
this.bagKindNum = 50;
// 倉庫格子
this.lockerKindNum = 100;
// 今日活躍
this.todayActive = 0;
// 需要隱藏的Icon
this.hideIconList = {};
// 最後補籤的日期
this.mendData = "";
// 充值dayMap
this.dayMap = null;
this.bodyEffectId = 0;
this.footEeffectId = 0;
this.tempLeave = false;
this.shane = 0;
this.offlinetime = 0;
this.getgift = 0;
this.bindInfo = null;
this.bplayerinfo = null;
this.headBorder = 0;
//天梯積分
this.tianti_integral = 0;
}
setTeam(info) {
if (info.teamid != null) {
this.teamInfo = info;
this.teamid = info.teamid;
this.isleader = info.leader == this.roleid;
var memberList = info.objlist;
for (let i in memberList) {
if (SKDataUtil.hasProperty(memberList[i], "onlyid")) {
if (memberList[i].roleid == GameModel.player.roleid) {
this.tempLeave = memberList[i].pause == 1;
if (TeamPanel.Instance)
TeamPanel.Instance.autoRecall = memberList[i].ischeck == 1;
break;
}
}
}
} else { GameModel.send('c2s_ask_partner_list', { nRoleID: GameModel.player.roleid }); }
let role = this.getLogic();
if (!role) {
cc.warn("$異常:設置隊伍異常,找不到角色類!");
} else {
if (this.teamid > 0 && this.isleader) {
role.addHeadStatus(info.teamcnt >= 5 ? 'zudui2' : 'zudui');
} else {
role.delHeadStatus('zudui');
role.delHeadStatus('zudui2');
}
}
let logic = this.getMainUILogic();
if (logic) {
logic.setTeamListInfo();
} else {
cc.warn("$異常:設置隊伍異常,主界面不存在!");
}
}
addFriendChatInfo(info) {
let index = info.toid + info.fromid;
if (!this.chatItemList[index]) {
this.chatItemList[index] = [];
}
this.chatItemList[index].push(info);
let length = this.chatItemList[index].length;
if (length > this.maxChatItems) {
this.chatItemList[index].splice(0, length - this.maxChatItems);
}
this.unreadInfoId[info.fromid] = 1;
let mainUI = this.getMainUILogic();
if (mainUI) {
mainUI.friendsChat(info);
}
}
setInfo(info) {
info.account && (this.account = info.account);
info.state && (this.state = info.state);
info.token && (this.token = info.token);
}
setUserInfo(data) {
// console.warn("人物信息修改")
this.gameData = data;
data.addattr1 && (this.gameData.addattr1 = JSON.parse(this.gameData.addattr1));
data.addattr2 && (this.gameData.addattr2 = JSON.parse(this.gameData.addattr2));
data.attr1 && (this.gameData.attr1 = JSON.parse(this.gameData.attr1));
data.serverid && (this.serverid = data.serverid);
data.onlyid && (this.onlyid = data.onlyid);
data.accountid && (this.accountid = data.accountid);
data.roleid && (this.roleid = data.roleid);
data.name && (this.name = data.name);
data.race && (this.race = data.race);
data.sex && (this.sex = data.sex);
data.mapid && (this.mapid = data.mapid);
data.x && (this.x = data.x);
data.y && (this.y = data.y);
data.relive && (this.relive = data.relive);
data.getgift && (this.getgift = data.getgift);
data.level && (this.level = data.level);
data.fplevel && (this.fplevel = data.fplevel);
data.levelreward && (this.level_reward = data.levelreward);
data.weapon && (this.weapon = data.weapon);
data.state && (this.state = data.state);
data.resid && (this.resid = data.resid);
data.changeid && (this.tResid = data.changeid);
data.bangid && (this.bangid = data.bangid);
if (this.bangid && this.bangid > 0) {
GameModel.send('c2s_getbanginfo', {
roleid: this.roleid,
bangid: this.bangid
});
}
data.shane && (this.shane = data.shane);
data.offlinetime && (this.offlinetime = data.offlinetime);
data.exp && (this.exp = data.exp);
data.maxexp && (this.maxexp = data.maxexp);
data.chargesum && (this.chargesum = data.chargesum);
data.rewardrecord && (this.rewardrecord = data.rewardrecord);
data.sprewardrecord && (this.sprewardrecord = data.sprewardrecord);
data.gmlevel && (this.gmlevel = data.gmlevel);
data.teamid && (this.teamid = data.teamid);
data.isleader && (this.isleader = data.isleader);
data.qianneng && (this.qianneng = data.qianneng);
data.bangname && (this.bangname = data.bangname);
data.titleid && (this.titleid = data.titleid);
data.titleval && (this.titleval = data.titleval);
data.titletype && (this.titletype = data.titletype);
data.schemename && (this.schemename = data.schemename);
data.bagKindNum && (this.bagKindNum = data.bagKindNum);
data.lockerKindNum && (this.lockerKindNum = data.lockerKindNum);
data.portrait && (this.headBorder = data.portrait);
data.iconList && (this.hideIconList = JSON.parse(data.iconList));
data.mendDate && (this.mendDate = data.mendDate.replace(/-/g, "/"));
data.dayMap && (this.dayMap = JSON.parse(data.dayMap));
data.babyList && (MyModel.shared.BabyList.UpdateBabyList(JSON.parse(data.babyList)))
data.starInfo && (MyModel.shared.StarData.UpdateStarData(JSON.parse(data.starInfo)))
data.xwList && (this.xwList = JSON.parse(data.xwList))
this.safe_password = data.safepassword || this.safe_password;
this.safe_lock = data.safelock || this.safe_lock;
data.tianti_integral && (this.tianti_integral = data.tianti_integral);//天梯積分
if (SKDataUtil.isNumber(data.color1)) {
this.color1 = data.color1;
}
if (SKDataUtil.isNumber(data.color2)) {
this.color2 = data.color2;
}
let wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", data.wingId, "id", 0);
this.wingId = wingId;
console.log("wingwingwingwinfgwinfnwfnwifwnifw", data.wingId, wingId)
// data.shane && (this.shane = data.shane);
// this.shanEChange(data.shane);
if (this.tResid > 0) {
var logic = this.getLogic();
if (logic)
logic.resetResid(this.tResid)
}
// 恢復變身
var roleLg = this.getLogic();
if (roleLg) {
if (roleLg.tResid != this.tResid && this.tResid == 0) {
roleLg.clearChange();
}
}
this.changeEff();
}
setNode(node) {
this.node = node;
}
getNode() {
return this.node;
}
getLogic() {
if (SKUIUtil.isValid(this.node)) {
let result = this.node.getComponent('role');
return result;
}
return null;
}
getMainLogic() {
if (this.mainGame == null) {
this.mainGame = cc.find('Canvas');
}
let logic = this.mainGame.getComponent('GameLogic');
return logic;
}
getMainUILogic() {
if (this.mainUI == null) {
this.mainUI = cc.find('Canvas/MainUI');
}
if (!SKUIUtil.isValid(this.mainUI)) {
let scene = cc.director.getScene();
cc.warn(`$警告:玩家獲得主界面異常,當前場景${scene.name}`);
return null;
}
let logic = this.mainUI.getComponent('MainUI');
return logic;
}
levelUp(level) {
this.getLogic().showLevelUp();
this.getMainUILogic().setRoleLevel(level);
}
changeExp(curexp, maxexp = 0) {
this.exp = curexp;
if (maxexp != 0) {
this.maxexp = maxexp;
if (GameModel.player.gameData) {
GameModel.player.gameData.maxexp = maxexp;
}
}
if (GameModel.player.gameData) {
GameModel.player.gameData.exp = curexp;
}
let logic = this.getMainUILogic();
if (!logic) {
cc.warn(`$警告:玩家設置經驗值[${curexp}/${maxexp}]無主界面`);
return;
}
logic.setExp(curexp, maxexp);
}
shanEChange(n) {
// this.shane = n;
// if (this.shane > 0 && this.mapid == 1011) {
// let mainLogic = this.getMainLogic();
// if (mainLogic) {
// mainLogic.mapLogic.changeMap(1201, cc.v2(59, 4));
// }
// }
// if (this.shane <= 0 && this.mapid == 1201) {
// let mainLogic = this.getMainLogic();
// if (mainLogic) {
// mainLogic.mapLogic.changeMap(1011);
// }
// // this.getLogic().setObjPos(41, 19);
// }
}
changePrisonTime(n) {
if (n < 0) {
this.getLogic().isShane = true;
this.getLogic().resetRoleTitle();
return;
}
if (n > 0) {
this.getLogic().isShane = false;
this.getLogic().resetRoleTitle();
}
this.prisonTime = n;
this.getMainUILogic().changePrisonTime(n);
}
getItemList() {
return this.itemList;
}
getItemNum() {
let n = 0;
for (const itemid in this.itemList) {
const itemnum = this.itemList[itemid];
if (itemnum > 0) {
n++;
}
}
return n;
}
send(event, data) {
GameModel.send(event, data);
}
changeEff() {
var playLog = this.getLogic()
if (!playLog) return;
playLog.bodyEffid = this.bodyEffectId;
playLog.footEffid = this.footEeffectId;
playLog.effectChange();
playLog.changeHeadBorder(this.headBorder);
}
getXwByItemID(itemID) {
if (!this.xwList || this.xwList.length == 0) return null;
for (let index = 0; index < this.xwList.length; index++) {
let xw = this.xwList[index];
if (xw.itemID == itemID) {
return xw
}
}
return null
}
updateXw(itemID, info) {
if (!this.xwList) {
this.xwList = []
}
for (let index = 0; index < this.xwList.length; index++) {
let xw = this.xwList[index];
if (xw.itemID == itemID) {
xw.attr1 = info.attr1
xw.attr2 = info.attr2
xw.attr3 = info.attr3
return xw
}
}
let xw = {
itemID: itemID,
attr1: info.attr1,
attr2: info.attr2,
attr3: info.attr3
}
this.xwList.push(xw)
}
}
module.exports = Player;