123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- import { Zone } from "../../../area/Area";
- import i18n from "../../../i18n/i18n";
- import Main from "../../../main/Main";
- import { ReveData } from "../../../util/CHttp";
- import CHttpEvent from "../../../util/CHttpEvent";
- import FFCalAttr, { FFAttr } from "../FFCalAttr";
- /**
- * 设置数据
- */
- export interface SettingData {
- music_ON_OFF_1: boolean,
- music_Slider_1: number,
- music_ON_OFF_2: boolean,
- music_Slider_2: number,
- }
- /**
- * 账号数据
- */
- export interface UserData {
- id: number
- token: string
- zone: Zone
- }
- /**
- * 角色数据
- */
- export interface RoleAttr {
- id: string
- token: string
- name: string
- renameCount: number
- // level:number
- money: number
- gold: number
- zdl: number//战斗力
- icon: number//战队头像
- frame: number//战队框
- title: number//称号
- leader: number//队长
- power: number//体力
- openSkill: number//0,是否开启了技能
- // stageId:number//当前达到的关卡
- }
- export interface RoleIcon {
- data: Array<number>
- open: Array<number>
- }
- export interface FoodAttr {
- atk: number
- def: number
- hp: number
- sp: number
- water: number
- fire: number
- light: number
- earth: number
- dark: number
- wind: number
- thunder: number
- date: number
- count: number
- }
- /**
- * 道具
- */
- export interface GoodAttr {
- count: number
- }
- /**
- * 伙伴
- */
- export interface PetAttr {
- id: number,
- equips: Array<EquipAttr>
- }
- /**
- * 装备
- */
- export interface EquipAttr {
- __index: number,
- PI: number
- id: number
- qhMax: number
- star: number
- attr: Array<any>
- }
- /**
- * 关卡中的获得物品记录
- * good = {
- * "1009":1,
- * "1010":1
- * }
- */
- export interface StageGoodAttr {
- starCount: number,
- good: any
- }
- /**
- * 关卡
- */
- export interface StageAttr {
- stageIndex: number,
- element: Array<string>;
- extraStage: Array<number>;
- data: Map<number, StageGoodAttr>;
- }
- /**
- * 神卡
- */
- export interface GodCardAttr {
- id: number
- level: number //升星等级
- feature: number //获得的特征数量
- reborn: number //重生次数
- }
- /**
- * 角色数据
- */
- export default class Player implements CHttpEvent {
- /**
- * 游戏系统设置
- */
- public setting: SettingData;
- /**
- * 角色基础数据
- */
- public role: RoleAttr;
- /**
- * 头像/框/称号
- */
- public roleIcon: RoleIcon;
- /**
- * 伙伴数据
- */
- public pet: Map<string, PetAttr>;
- /**
- * 装备
- */
- public equip: Array<EquipAttr>;
- /**
- * 神卡数据
- */
- public godCard: Map<string, GodCardAttr>;
- /**
- * 道具背包
- */
- public pack: Map<string, number>;
- /**
- * 关卡数据
- */
- public stage: StageAttr;
- /**
- * 吃食物增加属性
- */
- public foodAttr: FoodAttr;
- /**
- * 第一次充值赠送的id
- */
- public firstPayGave:Array<number>;
- public isNew: boolean = true;
- constructor(data: any) {
- this.readSetting();
- if (data) {
- this.role = data.role;
- this.foodAttr = data.foodAttr
- if (!this.role.name) {
- this.role.name = i18n.t('冒险者')+this.role.id
- }
- this.roleIcon = data.roleIcon
- this.pet = data.pet;
- this.godCard = data.godCard
- this.flushID();
- this.equip = data.equip;
- this.pack = data.pack;
- this.firstPayGave = data.firstPayGave;
- this.isNew = data.isNew;
- // cc.log('装备数量:',this.equip.length)
- this.flushIndex();
- }
- }
- private settingKey = '__setting';
- public readSetting() {
- let str = cc.sys.localStorage.getItem(this.settingKey)
- if (str) {
- this.setting = JSON.parse(str);
- } else {
- this.setting = {
- music_ON_OFF_1: true,
- music_Slider_1: 0.5,
- music_ON_OFF_2: true,
- music_Slider_2: 0.5,
- }
- }
- }
- public saveSetting() {
- cc.sys.localStorage.setItem(this.settingKey, JSON.stringify(this.setting));
- }
- private flushID() {
- for (const id in this.pet) {
- let pet = this.pet[id];
- pet.id = parseInt(id);
- }
- }
- public getPet(id) {
- return this.pet[id]
- }
- private flushIndex() {
- for (let i = 0; i < this.equip.length; i++) {
- let element = this.equip[i];
- element.__index = i;
- }
- }
- public getGoodCount(id) {
- let count = this.pack['' + id]
- if (count == undefined) {
- return 0
- }
- return count
- }
- /**
- * 监听网络
- * @param reveData
- */
- public httpEvent(reveData: ReveData) {
- // cc.log('Player reve : ',this);
- // cc.log('reve : ',reveData);
- let data = reveData.data;
- //更新基础属性
- if (data._role != undefined) {
- if (data._role.power != undefined) {
- this.role.power = data._role.power;
- }
- if (data._role._money != undefined) {
- this.role.money += data._role._money;
- }
- if (data._role._gold != undefined) {
- this.role.gold += data._role._gold;
- }
- if (data._role.gold != undefined) {
- this.role.gold = data._role.gold;
- }
- if (data._role.renameCount != undefined) {
- this.role.renameCount += data._role.renameCount;
- }
- if(data._firstPayGave){
- this.firstPayGave = data._firstPayGave;
- }
- }
- //更新背包
- if (data._pack != undefined) {
- for (let i = 0; i < data._pack.length; i++) {
- const element = data._pack[i];
- let v = this.pack["" + element.id];
- if (v != undefined) {
- v += element.count;
- this.pack["" + element.id] = v;
- } else {
- this.pack["" + element.id] = element.count;
- }
- }
- }
- //移除装备
- let isFlush = false;
- if (data._equipRemove != undefined) {
- let tmp = []
- for (let i = 0; i < this.equip.length; i++) {
- if (data._equipRemove.indexOf(i) < 0) {
- const element = this.equip[i];
- tmp.push(element)
- }
- }
- this.equip = tmp
- isFlush = true;
- }
- //添加装备
- if (data._equip != undefined) {
- for (let i = 0; i < data._equip.length; i++) {
- const element = data._equip[i];
- this.equip.push(element);
- }
- isFlush = true;
- }
- //添加头像/头像框/称号
- if (data._roleIcon != undefined) {
- for (let i = 0; i < data._roleIcon.length; i++) {
- const element = data._roleIcon[i];
- this.roleIcon.data.push(element);
- }
- }
- // //更新装备
- // if(data._equipUpdate != undefined){
- // for (let i = 0; i < data._equipUpdate.length; i++) {
- // const element = data._equipUpdate[i];
- // this.equip.push(element);
- // }
- // isFlush = true;
- // }
- if (isFlush) {
- this.flushIndex();
- }
- //更新伙伴
- if (data._pet != undefined) {
- for (let id in data._pet) {
- let element: PetAttr = data._pet[id];
- let v = this.pet[id];
- if (v == undefined) {
- this.pet[id] = element;
- element.id = parseInt(id);
- } else {
- v.equips = element.equips;
- }
- }
- }
- //添加神卡
- if (data._godCard != undefined) {
- for (let i = 0; i < data._godCard.length; i++) {
- const element = data._godCard[i];
- this.godCard[element.id] = element;
- }
- }
- }
- public getFight(main: Main): Array<FFAttr> {
- let fds = [];
- for (const id in this.pet) {
- let data = this.pet[id];
- fds.push(FFCalAttr.getAttr(main, data));
- }
- return fds;
- }
- /**
- * 刷新战斗力
- */
- public flushZdl(main) {
- let petMap = this.pet;
- let zdl = 0
- for (const id in petMap) {
- let petAttr = petMap[id];
- let attrData = FFCalAttr.getAttr(main, petAttr)
- zdl += attrData.zdl
- }
- this.role.zdl = zdl
- return zdl
- }
- }
|