833 lines
31 KiB
JavaScript
833 lines
31 KiB
JavaScript
var game;
|
|
|
|
function battlePetInt(value, fallback) {
|
|
const parsed = parseInt(value, 10);
|
|
return Number.isFinite(parsed) ? parsed : fallback || 0;
|
|
}
|
|
|
|
function battlePetTable(tableName) {
|
|
return Global.gameProxy && Global.gameProxy.getTabelConfigByType
|
|
? Global.gameProxy.getTabelConfigByType(tableName) || {}
|
|
: {};
|
|
}
|
|
|
|
function battlePetConfig(tableName, id) {
|
|
const table = battlePetTable(tableName);
|
|
return table && table[id] ? table[id] : null;
|
|
}
|
|
|
|
function battlePetSkin(name) {
|
|
return window[name] || name;
|
|
}
|
|
|
|
function battlePetServerMessage(response, fallback) {
|
|
return (response && GameConfig.ServerCode && GameConfig.ServerCode[response.status]) || fallback || "操作失败";
|
|
}
|
|
|
|
function battlePetShowResponse(response, fallback) {
|
|
response && response.status === 0
|
|
? TipsUtils.showTipsDownToUp(fallback || "操作成功")
|
|
: TipsUtils.showTipsDownToUp(battlePetServerMessage(response, fallback));
|
|
}
|
|
|
|
function battlePetPetConfig(id) {
|
|
return (
|
|
battlePetConfig("pet", id) || {
|
|
id: id,
|
|
name: "未知战宠",
|
|
type: 0,
|
|
blood: 0,
|
|
attack: 0,
|
|
anti: 0,
|
|
crit: 0,
|
|
dodge: 0,
|
|
graphical_id: 11001,
|
|
max_level: 1,
|
|
hunger: 0,
|
|
desc: "本地配置缺少该战宠"
|
|
}
|
|
);
|
|
}
|
|
|
|
function battlePetLevelConfig(level) {
|
|
return (
|
|
battlePetConfig("pet_level", level) ||
|
|
battlePetConfig("pet_level", 60) || {
|
|
id: level,
|
|
exp: 1,
|
|
blood: 0,
|
|
attack: 0,
|
|
anti: 0,
|
|
crit: 0,
|
|
dodge: 0
|
|
}
|
|
);
|
|
}
|
|
|
|
function battlePetEvolutionConfig(id) {
|
|
return battlePetConfig("evolution_list", id);
|
|
}
|
|
|
|
function battlePetCultureConfig(id) {
|
|
return (
|
|
battlePetConfig("culture", id) || {
|
|
id: id,
|
|
consume_id: "201002:1,201003:1,201004:1,201005:1,201006:1",
|
|
blood: 0,
|
|
attack: 0,
|
|
anti: 0,
|
|
crit: 0,
|
|
dodge: 0
|
|
}
|
|
);
|
|
}
|
|
|
|
function battlePetIconSource(graphicalId) {
|
|
return "resource/assets/icon/petIcon/" + battlePetInt(graphicalId, 11001) + ".png";
|
|
}
|
|
|
|
function battlePetItemIconSource(itemId) {
|
|
const iconId = Global.gameProxy.getItemImageId(itemId);
|
|
return game.URLConfig.getIcon(iconId);
|
|
}
|
|
|
|
function battlePetFormatSeconds(seconds) {
|
|
const safeSeconds = Math.max(0, battlePetInt(seconds));
|
|
return game.Utils && game.Utils.showTimeFormat ? game.Utils.showTimeFormat(1000 * safeSeconds) : safeSeconds + "秒";
|
|
}
|
|
|
|
function installBattlePetConfigAccessors() {
|
|
if (!game || !game.GameProxy || !game.GameProxy.prototype) return;
|
|
const proto = game.GameProxy.prototype;
|
|
proto.getPetBaseConfigForID ||
|
|
(proto.getPetBaseConfigForID = function (id) {
|
|
return battlePetPetConfig(id);
|
|
});
|
|
proto.getPetJinConfigForID ||
|
|
(proto.getPetJinConfigForID = function (id) {
|
|
return battlePetEvolutionConfig(id);
|
|
});
|
|
proto.getPetUpConfigForID ||
|
|
(proto.getPetUpConfigForID = function (level) {
|
|
return battlePetLevelConfig(level);
|
|
});
|
|
proto.getPetXiaohaoConfigForID ||
|
|
(proto.getPetXiaohaoConfigForID = function (id) {
|
|
return battlePetCultureConfig(id);
|
|
});
|
|
}
|
|
|
|
installBattlePetConfigAccessors();
|
|
|
|
function ensureBattlePetRuntimeConfig() {
|
|
installBattlePetConfigAccessors();
|
|
const serverMessages = {
|
|
1063: "战宠饥饿度不足",
|
|
1064: "请先设置出战战宠",
|
|
1065: "昵称重复",
|
|
1066: "已达到最大等级",
|
|
1067: "已经领取过",
|
|
1068: "战宠等级不能超过玩家等级",
|
|
1069: "战宠需要升到当前形态满级",
|
|
1070: "战宠培养次数需要全部达到当前等级",
|
|
1071: "战宠已达到最大等级"
|
|
};
|
|
Object.keys(serverMessages).forEach(function (code) {
|
|
GameConfig.ServerCode[code] || (GameConfig.ServerCode[code] = serverMessages[code]);
|
|
});
|
|
if (!Global.gameProxy || !Global.gameProxy.gameConfig) return;
|
|
const itemList = battlePetTable("item_list"),
|
|
storeList = battlePetTable("store_list"),
|
|
petTable = battlePetTable("pet"),
|
|
evolutionTable = battlePetTable("evolution_list"),
|
|
eggs = [
|
|
{ id: 201021, storeId: 701, gold: 10, gem: 0 },
|
|
{ id: 201017, storeId: 702, gold: 30, gem: 0 },
|
|
{ id: 201018, storeId: 703, gold: 60, gem: 0 },
|
|
{ id: 201019, storeId: 704, gold: 0, gem: 20 },
|
|
{ id: 201020, storeId: 705, gold: 0, gem: 30 }
|
|
];
|
|
eggs.forEach(function (egg, index) {
|
|
const petEggConfig = petTable[egg.id] || {},
|
|
evolutionConfig = evolutionTable[egg.id] || {};
|
|
itemList[egg.id] ||
|
|
(itemList[egg.id] = {
|
|
id: egg.id,
|
|
type1: 3,
|
|
type2: 500,
|
|
name: petEggConfig.name || "宠物蛋",
|
|
graphical_id: petEggConfig.graphical_id || 8022,
|
|
player_level: petEggConfig.player_level || 1,
|
|
sell_gold: 0,
|
|
effect_id: evolutionConfig.next_id || 0,
|
|
desc: petEggConfig.desc || "孵化后可获得战宠。"
|
|
});
|
|
storeList[egg.storeId] ||
|
|
(storeList[egg.storeId] = {
|
|
id: egg.storeId,
|
|
type: 3,
|
|
item_id: egg.id,
|
|
priority_type1: 70 + index,
|
|
player_level: itemList[egg.id].player_level || 1,
|
|
gold: egg.gold,
|
|
gem: egg.gem
|
|
});
|
|
});
|
|
Object.keys(evolutionTable).forEach(function (id) {
|
|
const evolution = evolutionTable[id],
|
|
drawingId = battlePetInt(evolution && evolution.drawing_id);
|
|
if (drawingId > 0 && !itemList[drawingId]) {
|
|
itemList[drawingId] = {
|
|
id: drawingId,
|
|
type1: 3,
|
|
type2: 700,
|
|
name: "战宠进化图纸",
|
|
graphical_id: 3002,
|
|
player_level: 1,
|
|
sell_gold: 0,
|
|
effect_id: 0,
|
|
desc: "战宠进化所需图纸。"
|
|
};
|
|
}
|
|
});
|
|
}
|
|
|
|
var PetData = class PetData {};
|
|
__reflect(PetData.prototype, "PetData");
|
|
|
|
var PetPro = class PetPro {};
|
|
PetPro.ketArr = ["blood", "attack", "anti", "crit", "dodge"];
|
|
PetPro.ketArrd = ["blood_add", "attack_add", "anti_add", "crit_add", "dodge_add"];
|
|
PetPro.petProStr = ["血量", "攻击", "防御", "暴击", "闪避"];
|
|
PetPro.petWay = ["无类型", "近身攻击", "远程攻击"];
|
|
PetPro.PET_HP = 0;
|
|
PetPro.ATTACK = 1;
|
|
PetPro.DEFENT = 2;
|
|
PetPro.CRIT = 3;
|
|
PetPro.DODGE = 4;
|
|
PetPro.POWER = 5;
|
|
__reflect(PetPro.prototype, "PetPro");
|
|
|
|
var PetWar;
|
|
!(function (PetWar) {
|
|
PetWar[(PetWar.PET_FIGHT = 1)] = "PET_FIGHT";
|
|
PetWar[(PetWar.PET_NOFIGHT = 0)] = "PET_NOFIGHT";
|
|
})(PetWar || (PetWar = {}));
|
|
|
|
var Pet = class Pet {
|
|
constructor() {
|
|
this.trainArr = [0, 0, 0, 0, 0];
|
|
this.accelerate_brooding_gem = 0;
|
|
this.curBlood = 0;
|
|
this.index = 0;
|
|
this.petData = new PetData();
|
|
}
|
|
readData(data) {
|
|
this.id = data.id;
|
|
this.pet_config_id = data.pet_config_id;
|
|
this.name = data.name;
|
|
this.level = Math.max(1, battlePetInt(data.level, 1));
|
|
this.exp = battlePetInt(data.exp);
|
|
this.feed = battlePetInt(data.feed);
|
|
this.feed_max = battlePetInt(data.feed_max);
|
|
this.last_updata_feed_time = data.last_updata_feed_time;
|
|
this.fighting_capacity = battlePetInt(data.fighting_capacity);
|
|
this.is_enter_war = battlePetInt(data.is_enter_war);
|
|
this.index = battlePetInt(data.index);
|
|
this.end_brooding_time = battlePetInt(data.end_brooding_time);
|
|
this.last_feed_update_time = data.last_feed_update_time;
|
|
this.accelerate_brooding_gem = battlePetInt(data.accelerate_brooding_gem);
|
|
this.petData.blood = battlePetInt(data.blood) + battlePetInt(data.blood_add);
|
|
this.curBlood = this.petData.blood;
|
|
this.petData.attack = battlePetInt(data.attack) + battlePetInt(data.attack_add);
|
|
this.petData.anti = battlePetInt(data.anti) + battlePetInt(data.anti_add);
|
|
this.petData.crit = battlePetInt(data.crit) + battlePetInt(data.crit_add);
|
|
this.petData.dodge = battlePetInt(data.dodge) + battlePetInt(data.dodge_add);
|
|
this.trainArr[PetPro.PET_HP] = battlePetInt(data.blood_train_count);
|
|
this.trainArr[PetPro.ATTACK] = battlePetInt(data.attack_train_count);
|
|
this.trainArr[PetPro.DEFENT] = battlePetInt(data.anti_train_count);
|
|
this.trainArr[PetPro.CRIT] = battlePetInt(data.crit_train_count);
|
|
this.trainArr[PetPro.DODGE] = battlePetInt(data.dodge_train_count);
|
|
if (!this.fighting_capacity) this.fighting_capacity = BattlePetManager.getInstance().alaysPower(this.petData);
|
|
this.updateBroodingTime();
|
|
}
|
|
updateBroodingTime() {
|
|
const now = DateTimer && DateTimer.instance ? DateTimer.instance.now : Math.floor(Date.now() / 1000);
|
|
this.has_end_brooding_time = Math.max(0, battlePetInt(this.end_brooding_time) - now);
|
|
}
|
|
};
|
|
__reflect(Pet.prototype, "Pet");
|
|
|
|
var BattlePetManager = class BattlePetManager extends egret.EventDispatcher {
|
|
constructor() {
|
|
super();
|
|
this.petArr = [];
|
|
this.isjin = 0;
|
|
}
|
|
static getInstance() {
|
|
return BattlePetManager._instance || (BattlePetManager._instance = new BattlePetManager()), BattlePetManager._instance;
|
|
}
|
|
bindPanel(panel) {
|
|
this.panel = panel;
|
|
}
|
|
unbindPanel(panel) {
|
|
this.panel === panel && (this.panel = null);
|
|
}
|
|
request(route, data, callback) {
|
|
Global.netProxy.sendRequest(GameConfig.SERVER_PATH + route, data || {}, callback.bind(this));
|
|
}
|
|
initPet(list) {
|
|
this.petArr.length = 0;
|
|
(list || []).forEach(
|
|
function (row) {
|
|
const pet = new Pet();
|
|
pet.readData(row);
|
|
this.petArr.push(pet);
|
|
}.bind(this)
|
|
);
|
|
this.petArr.sort(function (left, right) {
|
|
return battlePetInt(right.is_enter_war) - battlePetInt(left.is_enter_war) || battlePetInt(left.id) - battlePetInt(right.id);
|
|
});
|
|
if (!this.getPetForID(this.curID) && this.petArr.length) this.curID = this.petArr[0].id;
|
|
}
|
|
getPetForID(id) {
|
|
for (let index = 0; index < this.petArr.length; index++) {
|
|
if (battlePetInt(this.petArr[index].id) === battlePetInt(id)) return this.petArr[index];
|
|
}
|
|
return null;
|
|
}
|
|
currentPet() {
|
|
return this.getPetForID(this.curID);
|
|
}
|
|
alaysPower(data) {
|
|
return Math.ceil(0.2 * battlePetInt(data.blood) + battlePetInt(data.attack) + 2 * battlePetInt(data.anti) + 3 * battlePetInt(data.crit) + 3 * battlePetInt(data.dodge));
|
|
}
|
|
notifyPanel() {
|
|
this.panel && this.panel.onPetDataChanged && this.panel.onPetDataChanged();
|
|
game.EventManager &&
|
|
game.EventManager.instance &&
|
|
game.EventManager.instance.dispatch &&
|
|
game.EventManager.instance.dispatch(SysNotify.TOPLAYER_INFO_UPDATE);
|
|
}
|
|
sendGetpet() {
|
|
this.request("pet/get-list", {}, this.onSendNetGetPet);
|
|
}
|
|
onSendNetGetPet(response) {
|
|
if (response.status === 0) {
|
|
this.initPet((response.data && response.data.list) || []);
|
|
this.notifyPanel();
|
|
this.petArr.length || TipsUtils.showTipsDownToUp("您没有宠物");
|
|
} else battlePetShowResponse(response, "战宠列表读取失败");
|
|
}
|
|
sendNetAdd() {
|
|
const pet = this.currentPet();
|
|
if (!pet) return;
|
|
const needGem = battlePetInt(pet.accelerate_brooding_gem);
|
|
if (battlePetInt(Global.playerProxy.playerData.gem) < needGem) {
|
|
TipsUtils.showTipsDownToUp("钻石不够,请充值");
|
|
return;
|
|
}
|
|
this.request("pet/accelerate-brooding-egg", { pet_id: this.curID }, this.onSendNetAdd);
|
|
}
|
|
onSendNetAdd(response) {
|
|
if (response.status === 0) {
|
|
const pet = this.currentPet();
|
|
pet && (Global.playerProxy.playerData.gem = battlePetInt(Global.playerProxy.playerData.gem) - battlePetInt(pet.accelerate_brooding_gem));
|
|
this.sendGetpet();
|
|
TipsUtils.showTipsDownToUp("加速成功");
|
|
} else battlePetShowResponse(response, "加速失败");
|
|
}
|
|
sendNetWar() {
|
|
this.curID && this.request("pet/set-enter-war", { pet_id: this.curID }, this.onSendNetWar);
|
|
}
|
|
onSendNetWar(response) {
|
|
response.status === 0 ? (this.sendGetpet(), TipsUtils.showTipsDownToUp("参战成功")) : battlePetShowResponse(response, "参战失败");
|
|
}
|
|
sendNetPeiyang() {
|
|
this.curID && this.request("pet/train", { pet_id: this.curID, type: this.curType }, this.onSendNetPeiyang);
|
|
}
|
|
onSendNetPeiyang(response) {
|
|
if (response.status === 0) {
|
|
const pet = this.currentPet(),
|
|
cultureConfig = pet && battlePetCultureConfig(pet.pet_config_id),
|
|
cost = cultureConfig && String(cultureConfig.consume_id || "").split(",")[this.curType - 1];
|
|
cost && Global.playerProxy.sellWareHouseItem1(cost);
|
|
this.sendGetpet();
|
|
TipsUtils.showTipsDownToUp("培养成功");
|
|
} else battlePetShowResponse(response, "培养失败");
|
|
}
|
|
sendNetUpLevel() {
|
|
this.curID && this.request("pet/upgrade", { pet_id: this.curID, gold: this.curGold }, this.onSendNetUpLevel);
|
|
}
|
|
onSendNetUpLevel(response) {
|
|
if (response.status === 0) {
|
|
Global.playerProxy.playerData.gold = battlePetInt(Global.playerProxy.playerData.gold) - battlePetInt(this.curGold);
|
|
this.sendGetpet();
|
|
TipsUtils.showTipsDownToUp("升级成功");
|
|
} else battlePetShowResponse(response, "升级失败");
|
|
}
|
|
sendNetJinhua() {
|
|
this.curID && this.request("pet/evolution", { pet_id: this.curID }, this.onSendNetJinhua);
|
|
}
|
|
onSendNetJinhua(response) {
|
|
if (response.status === 0) {
|
|
const pet = this.currentPet(),
|
|
evolutionConfig = pet && battlePetEvolutionConfig(pet.pet_config_id),
|
|
costs = [];
|
|
evolutionConfig && evolutionConfig.crystal_id && costs.push(evolutionConfig.crystal_id);
|
|
evolutionConfig && battlePetInt(evolutionConfig.drawing_id) > 0 && costs.push(evolutionConfig.drawing_id + ":1");
|
|
costs.length && Global.playerProxy.sellWareHouseItem1(costs.join(","));
|
|
this.isjin = 1;
|
|
this.sendGetpet();
|
|
this.showEvolutionTips();
|
|
} else battlePetShowResponse(response, "进化失败");
|
|
}
|
|
sendNetFeend() {
|
|
this.feedItemID && this.curID
|
|
? this.request("pet/feed", { pet_id: this.curID, item_id: this.feedItemID }, this.onSendNetFeed)
|
|
: TipsUtils.showTipsDownToUp("没有狗粮");
|
|
}
|
|
onSendNetFeed(response) {
|
|
if (response.status === 0) {
|
|
this.feedItemID && Global.playerProxy.sellWareHouseItem({ id: this.feedItemID }, 1);
|
|
this.sendGetpet();
|
|
TipsUtils.showTipsDownToUp("喂养成功");
|
|
} else battlePetShowResponse(response, "喂养失败");
|
|
}
|
|
getFeed(itemId) {
|
|
const item = Global.playerProxy.getHasItemByItemId(itemId);
|
|
return item || null;
|
|
}
|
|
showEvolutionTips() {
|
|
if (!PopUpManager || !PopUpManager.addPopUp) return;
|
|
const tips = new BattlePetJinhuaTips();
|
|
PopUpManager.addPopUp(tips, true, 0, 0, 7);
|
|
}
|
|
};
|
|
__reflect(BattlePetManager.prototype, "BattlePetManager");
|
|
|
|
var BattleBaseCompoment = class BattleBaseCompoment extends eui.Component {
|
|
constructor() {
|
|
super();
|
|
this.isUpdata = false;
|
|
}
|
|
childrenCreated() {
|
|
super.childrenCreated();
|
|
this.jiasuButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onJiasu, this);
|
|
this.sleepButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onSleep, this);
|
|
this.battleButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBattle, this);
|
|
}
|
|
onRemovedFromStage() {
|
|
this.jiasuButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onJiasu, this);
|
|
this.sleepButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onSleep, this);
|
|
this.battleButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onBattle, this);
|
|
}
|
|
updata() {
|
|
const pet = BattlePetManager.getInstance().currentPet();
|
|
if (!pet) return;
|
|
pet.updateBroodingTime();
|
|
const petConfig = battlePetPetConfig(pet.pet_config_id),
|
|
nextLevelConfig = battlePetLevelConfig(Math.min(60, pet.level + 1));
|
|
this.headImg.source = battlePetIconSource(petConfig.graphical_id);
|
|
this.fightFeedLabel.text = battlePetInt(petConfig.hunger) + "";
|
|
this.petPoerLabel.text = battlePetInt(pet.fighting_capacity) + "";
|
|
this.petWay.text = PetPro.petWay[battlePetInt(petConfig.type)] || PetPro.petWay[0];
|
|
this.petLevelLabel.text = pet.level + "";
|
|
this.g1.visible = false;
|
|
this.g2.visible = false;
|
|
if (pet.has_end_brooding_time > 0) {
|
|
this.isUpdata = true;
|
|
this.g2.visible = true;
|
|
this.timeLabel.text = battlePetFormatSeconds(pet.has_end_brooding_time);
|
|
this.gemNumLabel.text = battlePetInt(pet.accelerate_brooding_gem) + "";
|
|
} else {
|
|
this.isUpdata = false;
|
|
this.g1.visible = true;
|
|
this.bar1.setPross(pet.exp, battlePetInt(nextLevelConfig.exp, 1));
|
|
this.curhungerLabel.text = pet.feed + "";
|
|
}
|
|
this.hoLabel.text = pet.petData.blood + "";
|
|
this.attrackLabel.text = pet.petData.attack + "";
|
|
this.critLabel.text = pet.petData.crit + "";
|
|
this.dodgeLabel.text = pet.petData.dodge + "";
|
|
this.defenselabel.text = pet.petData.anti + "";
|
|
this.desLabel.text = petConfig.desc || "";
|
|
if (pet.is_enter_war == PetWar.PET_NOFIGHT) {
|
|
this.battleButton.visible = true;
|
|
this.sleepButton.visible = false;
|
|
} else {
|
|
this.battleButton.visible = false;
|
|
this.sleepButton.visible = true;
|
|
}
|
|
}
|
|
enterFrame() {
|
|
const pet = BattlePetManager.getInstance().currentPet();
|
|
if (!pet) return;
|
|
pet.updateBroodingTime();
|
|
if (this.isUpdata) this.timeLabel.text = battlePetFormatSeconds(pet.has_end_brooding_time);
|
|
else if (pet.is_enter_war == PetWar.PET_FIGHT) this.curhungerLabel.text = pet.feed + "";
|
|
}
|
|
onJiasu(event) {
|
|
event && event.stopPropagation();
|
|
BattlePetManager.getInstance().sendNetAdd();
|
|
}
|
|
onSleep(event) {
|
|
event && event.stopPropagation();
|
|
}
|
|
onBattle(event) {
|
|
event && event.stopPropagation();
|
|
BattlePetManager.getInstance().sendNetWar();
|
|
}
|
|
};
|
|
__reflect(BattleBaseCompoment.prototype, "BattleBaseCompoment");
|
|
|
|
var BattlePetItem2 = class BattlePetItem2 extends eui.Component {
|
|
constructor() {
|
|
super();
|
|
this.skinName = battlePetSkin("BattlePetItem2Skin");
|
|
}
|
|
setImgScale(scale) {
|
|
this.headImg.scaleX = scale;
|
|
this.headImg.scaleY = scale;
|
|
}
|
|
};
|
|
__reflect(BattlePetItem2.prototype, "BattlePetItem2");
|
|
|
|
var BattlePetProItem1 = class BattlePetProItem1 extends eui.Component {
|
|
constructor() {
|
|
super();
|
|
this.skinName = battlePetSkin("BattleProItem1Skin");
|
|
}
|
|
};
|
|
__reflect(BattlePetProItem1.prototype, "BattlePetProItem1");
|
|
|
|
var BattlePetProItem = class BattlePetProItem extends eui.Component {
|
|
constructor(type) {
|
|
super();
|
|
this.type = type || 0;
|
|
this.skinName = battlePetSkin("BattleProItemSkin");
|
|
this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemove, this);
|
|
}
|
|
childrenCreated() {
|
|
super.childrenCreated();
|
|
this.peiyangButton.touchEnabled = true;
|
|
this.peiyangButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onPeiyang, this);
|
|
}
|
|
onRemove() {
|
|
this.peiyangButton && this.peiyangButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onPeiyang, this);
|
|
this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemove, this);
|
|
}
|
|
onPeiyang(event) {
|
|
event && event.stopPropagation();
|
|
const manager = BattlePetManager.getInstance(),
|
|
pet = manager.currentPet();
|
|
manager.curType = this.type + 1;
|
|
pet && pet.trainArr[this.type] < pet.level ? manager.sendNetPeiyang() : TipsUtils.showTipsDownToUp("当前宠物等级不足");
|
|
}
|
|
};
|
|
__reflect(BattlePetProItem.prototype, "BattlePetProItem");
|
|
|
|
var BattlePetRadioButton = class BattlePetRadioButton extends eui.RadioButton {
|
|
constructor() {
|
|
super();
|
|
this.skinName = battlePetSkin("BattlePetRadioButtonSkin");
|
|
}
|
|
updatePet(pet) {
|
|
const petConfig = battlePetPetConfig(pet.pet_config_id);
|
|
this.value = pet.id;
|
|
this.headImg.source = battlePetIconSource(petConfig.graphical_id);
|
|
this.nameLabel.text = petConfig.name || pet.name || "";
|
|
}
|
|
};
|
|
__reflect(BattlePetRadioButton.prototype, "BattlePetRadioButton");
|
|
|
|
var BattlePetJinhuaCompoment = class BattlePetJinhuaCompoment extends eui.Component {
|
|
childrenCreated() {
|
|
super.childrenCreated();
|
|
this.jinhuaButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onJinHua, this);
|
|
}
|
|
onJinHua(event) {
|
|
event && event.stopPropagation();
|
|
BattlePetManager.getInstance().isjin = 0;
|
|
BattlePetManager.getInstance().showEvolutionTips();
|
|
}
|
|
updata() {
|
|
const pet = BattlePetManager.getInstance().currentPet();
|
|
if (!pet) return;
|
|
const petConfig = battlePetPetConfig(pet.pet_config_id),
|
|
evolutionConfig = battlePetEvolutionConfig(pet.pet_config_id),
|
|
nextPetConfig = evolutionConfig && battlePetPetConfig(evolutionConfig.next_id);
|
|
this.headImg1.source = battlePetIconSource(petConfig.graphical_id);
|
|
this.nameLabel1.text = petConfig.name || "";
|
|
this.headImg2.source = battlePetIconSource((nextPetConfig || petConfig).graphical_id);
|
|
this.nameLabel2.text = nextPetConfig ? nextPetConfig.name || "" : "MAX";
|
|
this.jinhuaButton.visible = !!nextPetConfig;
|
|
this.setCompareItem(this.item0, "等级上限", petConfig.max_level, nextPetConfig ? nextPetConfig.max_level : petConfig.max_level);
|
|
this.setCompareItem(this.item1, "血量", pet.petData.blood, pet.petData.blood + (nextPetConfig ? battlePetInt(nextPetConfig.blood) - battlePetInt(petConfig.blood) : 0));
|
|
this.setCompareItem(this.item2, "攻击", pet.petData.attack, pet.petData.attack + (nextPetConfig ? battlePetInt(nextPetConfig.attack) - battlePetInt(petConfig.attack) : 0));
|
|
this.setCompareItem(this.item3, "防御", pet.petData.anti, pet.petData.anti + (nextPetConfig ? battlePetInt(nextPetConfig.anti) - battlePetInt(petConfig.anti) : 0));
|
|
this.setCompareItem(this.item4, "暴击", pet.petData.crit, pet.petData.crit + (nextPetConfig ? battlePetInt(nextPetConfig.crit) - battlePetInt(petConfig.crit) : 0));
|
|
this.setCompareItem(this.item5, "闪避", pet.petData.dodge, pet.petData.dodge + (nextPetConfig ? battlePetInt(nextPetConfig.dodge) - battlePetInt(petConfig.dodge) : 0));
|
|
const currentPower = BattlePetManager.getInstance().alaysPower(pet.petData),
|
|
nextPower = BattlePetManager.getInstance().alaysPower({
|
|
blood: battlePetInt(this.item1.titleNumLabel1.text),
|
|
attack: battlePetInt(this.item2.titleNumLabel1.text),
|
|
anti: battlePetInt(this.item3.titleNumLabel1.text),
|
|
crit: battlePetInt(this.item4.titleNumLabel1.text),
|
|
dodge: battlePetInt(this.item5.titleNumLabel1.text)
|
|
});
|
|
this.setCompareItem(this.item6, "战力", currentPower, nextPower);
|
|
}
|
|
setCompareItem(item, name, left, right) {
|
|
item.titleNameLabel.text = name;
|
|
item.titleNumLabel.text = left + "";
|
|
item.titleNumLabel.x = item.titleNameLabel.x + item.titleNameLabel.width + 10;
|
|
item.titleNameLabel1.text = name;
|
|
item.titleNumLabel1.text = right + "";
|
|
item.titleNumLabel1.x = item.titleNameLabel1.x + item.titleNameLabel1.width + 10;
|
|
}
|
|
};
|
|
__reflect(BattlePetJinhuaCompoment.prototype, "BattlePetJinhuaCompoment");
|
|
|
|
var BattlePetJinhuaTips = class BattlePetJinhuaTips extends eui.Component {
|
|
constructor() {
|
|
super();
|
|
this.skinName = battlePetSkin("BattlePetJinhuaTipSkin");
|
|
this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemove, this);
|
|
}
|
|
childrenCreated() {
|
|
super.childrenCreated();
|
|
this.closeButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
|
|
this.okButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
|
|
this.jinhuaButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onJinhua, this);
|
|
this.g1.visible = BattlePetManager.getInstance().isjin === 0;
|
|
this.g2.visible = BattlePetManager.getInstance().isjin !== 0;
|
|
this.g1.visible ? this.updataItem() : this.updateSuccess();
|
|
}
|
|
onRemove() {
|
|
this.closeButton && this.closeButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
|
|
this.okButton && this.okButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
|
|
this.jinhuaButton && this.jinhuaButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onJinhua, this);
|
|
this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemove, this);
|
|
}
|
|
onJinhua(event) {
|
|
event && event.stopPropagation();
|
|
BattlePetManager.getInstance().sendNetJinhua();
|
|
game.UIUtils.removeSelf(this);
|
|
}
|
|
onClose(event) {
|
|
event && event.stopPropagation();
|
|
game.UIUtils.removeSelf(this);
|
|
}
|
|
updateSuccess() {
|
|
const pet = BattlePetManager.getInstance().currentPet(),
|
|
petConfig = pet && battlePetPetConfig(pet.pet_config_id);
|
|
if (!petConfig) return;
|
|
this.nameLabel.text = petConfig.name || "";
|
|
this.headImg.source = battlePetIconSource(petConfig.graphical_id);
|
|
}
|
|
updataItem() {
|
|
const pet = BattlePetManager.getInstance().currentPet(),
|
|
evolutionConfig = pet && battlePetEvolutionConfig(pet.pet_config_id);
|
|
if (!evolutionConfig) return;
|
|
const crystals = String(evolutionConfig.crystal_id || "").split(",");
|
|
for (let index = 1; index < 6; index++) {
|
|
const parts = String(crystals[index - 1] || "").split(":"),
|
|
itemId = parts[0],
|
|
count = parts[1] || 0,
|
|
item = this["item" + index];
|
|
if (!item) continue;
|
|
item.headImg.source = battlePetItemIconSource(itemId);
|
|
item.numLaebl.text = "X" + count;
|
|
}
|
|
this.item0.headImg.source = battlePetItemIconSource(evolutionConfig.drawing_id);
|
|
this.item0.numLaebl.text = "X1";
|
|
}
|
|
};
|
|
__reflect(BattlePetJinhuaTips.prototype, "BattlePetJinhuaTips");
|
|
|
|
var BattlePetUpLevelCompoment = class BattlePetUpLevelCompoment extends eui.Component {
|
|
childrenCreated() {
|
|
super.childrenCreated();
|
|
this.initItem();
|
|
this.changeButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onChange, this);
|
|
this.scrolls.touchEnabled = true;
|
|
this.goldEditLabel.restrict = "0-9";
|
|
}
|
|
initItem() {
|
|
this.gs.removeChildren();
|
|
for (let index = 0; index < 5; index++) {
|
|
const item = new BattlePetProItem(index);
|
|
this.gs.addChild(item);
|
|
item.y = item.height * index + 0.1 * item.height;
|
|
}
|
|
}
|
|
updata() {
|
|
const pet = BattlePetManager.getInstance().currentPet();
|
|
if (!pet) return;
|
|
this.levelLabel.text = pet.level + "";
|
|
const nextLevel = Math.min(60, pet.level + 1),
|
|
levelConfig = battlePetLevelConfig(nextLevel),
|
|
cultureConfig = battlePetCultureConfig(pet.pet_config_id),
|
|
rate = battlePetInt((battlePetConfig("common", 18) || {}).min, 100),
|
|
currentExp = battlePetInt(pet.exp),
|
|
targetExp = battlePetInt(levelConfig.exp, 1);
|
|
this.desLabel1.text = "注:金币兑换经验值的比例为" + rate + ":1,只能输入倍数为" + rate + "的金币";
|
|
this.prossbar.setPross(currentExp, targetExp);
|
|
this.goldEditLabel.text = "" + Math.max(0, targetExp - currentExp) * rate;
|
|
const consumeItems = String(cultureConfig.consume_id || "").split(",");
|
|
for (let index = 0; index < this.gs.numChildren; index++) {
|
|
const item = this.gs.getChildAt(index),
|
|
propertyName = PetPro.ketArr[item.type],
|
|
consumeParts = String(consumeItems[item.type] || "201002:1").split(":"),
|
|
itemId = consumeParts[0],
|
|
count = battlePetInt(consumeParts[1], 1);
|
|
item.proNameLabel.text = PetPro.petProStr[item.type];
|
|
item.titleNameLabel.text = pet.petData[propertyName] + "";
|
|
item.proLabel.text = battlePetInt(cultureConfig[propertyName]) + "";
|
|
item.countLabel.text = pet.trainArr[item.type] + "/" + pet.level;
|
|
item.icons.source = battlePetItemIconSource(itemId);
|
|
item.countLabel0.text = "X" + count;
|
|
}
|
|
}
|
|
onChange(event) {
|
|
event && event.stopPropagation();
|
|
const gold = battlePetInt(this.goldEditLabel.text),
|
|
rate = battlePetInt((battlePetConfig("common", 18) || {}).min, 100),
|
|
pet = BattlePetManager.getInstance().currentPet();
|
|
if (!pet) return;
|
|
const targetExp = battlePetInt(battlePetLevelConfig(Math.min(60, pet.level + 1)).exp, 1),
|
|
needGold = Math.max(0, targetExp - battlePetInt(pet.exp)) * rate;
|
|
if (gold % rate === 0 && gold >= rate) {
|
|
if (needGold >= gold) {
|
|
BattlePetManager.getInstance().curGold = gold;
|
|
BattlePetManager.getInstance().sendNetUpLevel();
|
|
} else TipsUtils.showTipsDownToUp("当前金币大于当前升级经验所需金币");
|
|
} else TipsUtils.showTipsDownToUp("请输入" + rate + "的倍数");
|
|
}
|
|
};
|
|
__reflect(BattlePetUpLevelCompoment.prototype, "BattlePetUpLevelCompoment");
|
|
|
|
var BattlePanel = class BattlePanel extends game.BasePanel {
|
|
constructor() {
|
|
super();
|
|
this.isFullScreen = true;
|
|
this.isVisibleAnimate = true;
|
|
this.skinName = battlePetSkin("BattlePetPanelSkin");
|
|
}
|
|
createChildren() {
|
|
super.createChildren();
|
|
this.commonPanel.setPanelWidth(640);
|
|
this.commonPanel.setPanelHeight(940);
|
|
this.commonPanel.setTitleIcon("");
|
|
this.commonPanel.setTitle("battle_pet_json.battle_pet_canzhan12_png");
|
|
}
|
|
childrenCreated() {
|
|
super.childrenCreated();
|
|
ensureBattlePetRuntimeConfig();
|
|
BattlePetManager.getInstance().bindPanel(this);
|
|
this.initTab();
|
|
this.initRadioGroup();
|
|
this.tab.setSelectIndex(0);
|
|
this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
|
|
BattlePetManager.getInstance().sendGetpet();
|
|
}
|
|
onRemoved() {
|
|
BattlePetManager.getInstance().unbindPanel(this);
|
|
this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
|
|
super.onRemoved();
|
|
}
|
|
initTab() {
|
|
const tabs = ["基本属性", "战力升级", "宠物进化"];
|
|
this.tab = new game.Tab(tabs, this.onTabItemClickCallback.bind(this));
|
|
this.groupbar.addChild(this.tab);
|
|
}
|
|
initRadioGroup() {
|
|
this.radioButtonGroup &&
|
|
this.radioButtonGroup.removeEventListener(egret.Event.CHANGE, this.change, this);
|
|
this.radioButtonGroup = new eui.RadioButtonGroup();
|
|
this.radioButtonGroup.addEventListener(egret.Event.CHANGE, this.change, this);
|
|
this.gs.removeChildren();
|
|
const pets = BattlePetManager.getInstance().petArr,
|
|
selectedId = BattlePetManager.getInstance().curID || (pets[0] && pets[0].id);
|
|
pets.forEach(
|
|
function (pet, index) {
|
|
const radio = new BattlePetRadioButton();
|
|
radio.group = this.radioButtonGroup;
|
|
radio.updatePet(pet);
|
|
radio.x = index * radio.width + index * radio.width * 0.4;
|
|
this.gs.addChild(radio);
|
|
if (battlePetInt(pet.id) === battlePetInt(selectedId)) {
|
|
radio.selected = true;
|
|
BattlePetManager.getInstance().curID = pet.id;
|
|
}
|
|
}.bind(this)
|
|
);
|
|
}
|
|
onEnterFrame() {
|
|
this.baseC && this.baseC.enterFrame();
|
|
}
|
|
onTabItemClickCallback(index) {
|
|
this.updata();
|
|
}
|
|
change() {
|
|
BattlePetManager.getInstance().curID = this.radioButtonGroup.selectedValue;
|
|
this.updata();
|
|
}
|
|
onPetDataChanged() {
|
|
this.initRadioGroup();
|
|
this.updata();
|
|
}
|
|
updataRadioGroup() {
|
|
for (let index = 0; index < this.gs.numChildren; index++) {
|
|
const radio = this.gs.getChildAt(index),
|
|
pet = BattlePetManager.getInstance().getPetForID(radio.value);
|
|
pet && radio.updatePet(pet);
|
|
radio.selected = battlePetInt(radio.value) === battlePetInt(BattlePetManager.getInstance().curID);
|
|
}
|
|
}
|
|
updata() {
|
|
this.baseC.visible = false;
|
|
this.upLevelc.visible = false;
|
|
this.jinhuaC.visible = false;
|
|
const pet = BattlePetManager.getInstance().currentPet();
|
|
if (!pet) return;
|
|
pet.updateBroodingTime();
|
|
const index = this.tab.selectIndex;
|
|
switch (index) {
|
|
case 0:
|
|
this.baseC.visible = true;
|
|
this.baseC.updata();
|
|
break;
|
|
case 1:
|
|
if (pet.has_end_brooding_time > 0) {
|
|
this.tab.setSelectIndex(0);
|
|
TipsUtils.showTipsDownToUp("宠物正在孵化");
|
|
return;
|
|
}
|
|
this.upLevelc.visible = true;
|
|
this.upLevelc.updata();
|
|
break;
|
|
case 2:
|
|
if (pet.has_end_brooding_time > 0) {
|
|
this.tab.setSelectIndex(0);
|
|
TipsUtils.showTipsDownToUp("宠物正在孵化");
|
|
return;
|
|
}
|
|
this.jinhuaC.visible = true;
|
|
this.jinhuaC.updata();
|
|
break;
|
|
}
|
|
this.updataRadioGroup();
|
|
}
|
|
btnCloseTouchEnded() {
|
|
game.AppFacade.getInstance().sendNotification(PanelNotify.CLOSE_BATTLEPET);
|
|
}
|
|
};
|
|
__reflect(BattlePanel.prototype, "BattlePanel");
|
|
|
|
!(function (game) {
|
|
game.WorldPetPanel = BattlePanel;
|
|
__reflect(BattlePanel.prototype, "game.WorldPetPanel");
|
|
})(game || (game = {}));
|