328 lines
10 KiB
ActionScript
328 lines
10 KiB
ActionScript
package net.pixvi.myr.center
|
|
{
|
|
import net.pixvi.common.utils.Alert;
|
|
import net.pixvi.myr.GameMath;
|
|
import net.pixvi.myr.battle.view.BattleMon;
|
|
import net.pixvi.myr.element.battle.BattleData;
|
|
import net.pixvi.myr.element.battle.BattleTeamVo;
|
|
import net.pixvi.myr.element.mon.MonsterVo;
|
|
import net.pixvi.myr.element.pve.PveAreaInfoVo;
|
|
import net.pixvi.myr.element.pve.PveCharaDataVo;
|
|
import net.pixvi.myr.element.pve.PveInfoVo;
|
|
import net.pixvi.myr.element.pve.PveRankVo;
|
|
import net.pixvi.myr.element.reward.RewardResultVo;
|
|
import net.pixvi.myr.net.NetPve;
|
|
import net.pixvi.pfw.utils.Random;
|
|
import net.pixvi.pfw.utils.core.Singleton;
|
|
|
|
public class PveCenter extends Singleton
|
|
{
|
|
|
|
public var botInited:Boolean = false;
|
|
|
|
private var onGetPveInfoComplete:Function;
|
|
|
|
private var onStartPveComplete:Function;
|
|
|
|
public var pve_me:PveCharaDataVo;
|
|
|
|
public var pve_enemy:PveCharaDataVo;
|
|
|
|
public var cur_area:PveAreaInfoVo;
|
|
|
|
private var onFinishPveComplete:Function;
|
|
|
|
private var onWeekRewardComplete:Function;
|
|
|
|
private var weekReward_buff:Object;
|
|
|
|
public function PveCenter()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function getIns() : PveCenter
|
|
{
|
|
return Singleton.getInstanceOrCreate(PveCenter) as PveCenter;
|
|
}
|
|
|
|
public function buildCheckVoByBattleMon(battlemon:BattleMon) : Object
|
|
{
|
|
var i:int = 0;
|
|
var mon:Object = {};
|
|
var pveMonData:Object = battlemon.monVo;
|
|
mon.mid = pveMonData.monsterId;
|
|
mon.type = pveMonData.typeId;
|
|
mon.equips = [];
|
|
for(i = 1; i <= 5; )
|
|
{
|
|
if(pveMonData["equip" + i + "TypeId"] > 0)
|
|
{
|
|
mon.equips.push(pveMonData["equip" + i + "TypeId"]);
|
|
}
|
|
i++;
|
|
}
|
|
mon.atk = pveMonData.atk;
|
|
mon.def = pveMonData.def;
|
|
mon.hp = pveMonData.hp;
|
|
mon.dex = pveMonData.dex;
|
|
mon.crit = pveMonData.crit;
|
|
mon.spd_atk_add = pveMonData.atkSpd;
|
|
mon.atkVim = pveMonData.atkVim;
|
|
mon.selfCure = pveMonData.selfCure;
|
|
mon.deadBoom = pveMonData.deadBoom;
|
|
mon.atkStun = pveMonData.atkStun;
|
|
mon.defStun = pveMonData.defStun;
|
|
mon.atkPoi = pveMonData.atkPoi;
|
|
mon.atkPoiDmg = pveMonData.atkPoiDmg;
|
|
if(mon.apCost < 1)
|
|
{
|
|
mon.apCost = 1;
|
|
}
|
|
mon.skillCooldown = pveMonData.skillCooldown;
|
|
mon.sunFire = pveMonData.sunFire;
|
|
mon.moonHeal = pveMonData.moonHeal;
|
|
mon.thorns = pveMonData.thorns;
|
|
mon.equips = [];
|
|
return mon;
|
|
}
|
|
|
|
public function getPveAreaInfoByCity(city:int) : PveAreaInfoVo
|
|
{
|
|
switch(city - 1)
|
|
{
|
|
case 0:
|
|
return Master.pveInfo.pve_llts;
|
|
case 1:
|
|
return Master.pveInfo.pve_lah;
|
|
case 2:
|
|
return Master.pveInfo.pve_bslm;
|
|
case 3:
|
|
return Master.pveInfo.pve_nslm;
|
|
case 4:
|
|
return Master.pveInfo.pve_lrj;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function getPveInfo(onComplete:Function) : void
|
|
{
|
|
onGetPveInfoComplete = onComplete;
|
|
NetPve.getIns().getPveInfo(getPveInfoHandler);
|
|
}
|
|
|
|
private function getPveInfoHandler(re:Object) : void
|
|
{
|
|
var areaInfoVo:PveAreaInfoVo = null;
|
|
var infovo:PveInfoVo = new PveInfoVo();
|
|
if(re.pve_llts == null)
|
|
{
|
|
re.pve_llts = null;
|
|
}
|
|
for(var pveKey:String in re)
|
|
{
|
|
areaInfoVo = new PveAreaInfoVo();
|
|
areaInfoVo.onData(re[pveKey],pveKey);
|
|
infovo[pveKey] = areaInfoVo;
|
|
}
|
|
Master.pveInfo = infovo;
|
|
if(onGetPveInfoComplete != null)
|
|
{
|
|
onGetPveInfoComplete();
|
|
onGetPveInfoComplete = null;
|
|
}
|
|
}
|
|
|
|
public function startPve(pveAreaName:String, onComplete:Function) : void
|
|
{
|
|
trace("[pve开始匹配]");
|
|
onStartPveComplete = onComplete;
|
|
NetPve.getIns().startPve(pveAreaName,startPveHandler);
|
|
}
|
|
|
|
private function startPveHandler(re:Object) : void
|
|
{
|
|
if(re.resCode == 100)
|
|
{
|
|
Alert.yes("提示","挑战赛暂未开放,请稍后再来吧。");
|
|
}
|
|
pve_me = new PveCharaDataVo();
|
|
pve_me.onData(re.myself);
|
|
if(re.enemy.masterInfo == null)
|
|
{
|
|
trace("[pve没有匹配到玩家]");
|
|
pve_enemy = getBotVo(cur_area);
|
|
pve_enemy.isBot = true;
|
|
}
|
|
else
|
|
{
|
|
trace("[pve匹配到玩家]");
|
|
pve_enemy = new PveCharaDataVo();
|
|
pve_enemy.onData(re.enemy);
|
|
}
|
|
if(onStartPveComplete != null)
|
|
{
|
|
onStartPveComplete();
|
|
onStartPveComplete = null;
|
|
}
|
|
}
|
|
|
|
public function finishPve(battleData:BattleData, onComplete:Function) : void
|
|
{
|
|
onFinishPveComplete = onComplete;
|
|
NetPve.getIns().finishPve(cur_area.pveAreaType,battleData,finishPveHandler);
|
|
}
|
|
|
|
private function finishPveHandler(re:Object) : void
|
|
{
|
|
var reward:RewardResultVo = RewardCenter.getRewardResultVoByData(re.reward);
|
|
var finalScore:int = int(re.param.finalScore);
|
|
cur_area.num++;
|
|
if(cur_area.score != finalScore)
|
|
{
|
|
cur_area.oldScore = cur_area.score;
|
|
cur_area.score = finalScore;
|
|
cur_area.hasUpdate = true;
|
|
}
|
|
if(onFinishPveComplete != null)
|
|
{
|
|
onFinishPveComplete(reward);
|
|
onFinishPveComplete = null;
|
|
}
|
|
}
|
|
|
|
public function getBotsByStar(maxStar:int, botType:String = "all") : Array
|
|
{
|
|
var i:int = 0;
|
|
var pveBotData:Object = null;
|
|
var star:int = 0;
|
|
i = 0;
|
|
var pveBotData2:Object = null;
|
|
var bots:Array = [];
|
|
if(!botInited)
|
|
{
|
|
for(i = 0; i < Table.pve_bot.length; )
|
|
{
|
|
pveBotData = Table.pve_bot[i];
|
|
star = 0;
|
|
for each(var mondata:Object in pveBotData.teamData.mons)
|
|
{
|
|
star += MonsterVo.getStar(mondata.type);
|
|
}
|
|
pveBotData.star = star;
|
|
if(pveBotData.star <= maxStar && (pveBotData.botType == botType || botType == "all"))
|
|
{
|
|
bots.push(pveBotData);
|
|
}
|
|
i++;
|
|
}
|
|
Table.pve_bot.sortOn("zdl",16);
|
|
}
|
|
else
|
|
{
|
|
i = 0;
|
|
while(i < Table.pve_bot.length)
|
|
{
|
|
pveBotData2 = Table.pve_bot[i];
|
|
if(pveBotData2.star <= maxStar && (pveBotData2.botType == botType || botType == "all"))
|
|
{
|
|
bots.push(pveBotData2);
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
return bots;
|
|
}
|
|
|
|
public function getBotVo(area:PveAreaInfoVo) : PveCharaDataVo
|
|
{
|
|
var i:int = 0;
|
|
var getBots:Array = getBotsByStar(Table.pve_info.pveArea[area.pveAreaType].maxStar,Table.pve_info.pveArea[area.pveAreaType].botType);
|
|
var myTeamZdl:int = TeamCenter.getIns().getTeamZdl(area.pveAreaType);
|
|
trace("[pve我方总战力]",myTeamZdl);
|
|
var bots:Array = [];
|
|
for(i = 0; i < getBots.length; )
|
|
{
|
|
if(Math.abs(myTeamZdl - getBots[i].zdl) < myTeamZdl * 0.3)
|
|
{
|
|
bots.push(getBots[i]);
|
|
}
|
|
i++;
|
|
}
|
|
if(bots.length == 0)
|
|
{
|
|
if(myTeamZdl > getBots[getBots.length - 1])
|
|
{
|
|
trace("[pve触发上限机器人保底]");
|
|
bots.push(bots[bots.length - 1]);
|
|
}
|
|
else
|
|
{
|
|
trace("[pve触发下限机器人保底]");
|
|
bots.push(getBots[0],getBots[1],getBots[2]);
|
|
}
|
|
}
|
|
var bot:Object = Random.element(bots);
|
|
trace("[pve机器人战力]",bot.zdl);
|
|
var pveCharaDataVo:PveCharaDataVo = new PveCharaDataVo();
|
|
pveCharaDataVo.onBot(bot,area);
|
|
return pveCharaDataVo;
|
|
}
|
|
|
|
public function getPveBattleTeamVo(area:PveAreaInfoVo, enemyData:PveCharaDataVo) : BattleTeamVo
|
|
{
|
|
var enemyTeamVo:BattleTeamVo = new BattleTeamVo();
|
|
enemyTeamVo.ai = 2;
|
|
enemyTeamVo.ai_search = 2;
|
|
enemyTeamVo.apMax = enemyTeamVo.ap = GameMath.apByLevel(enemyData.masterInfo.level);
|
|
enemyTeamVo.numMax = area.getNumMax(GameMath.getStageNumByLevel(enemyData.masterInfo.level));
|
|
enemyTeamVo.team = 2;
|
|
enemyTeamVo.name = enemyData.masterInfo.roleName;
|
|
enemyTeamVo.mons = enemyData.pveBattleData.pveBattleMonVoArray;
|
|
return enemyTeamVo;
|
|
}
|
|
|
|
public function getRankByScore(score:int) : PveRankVo
|
|
{
|
|
var vo:Object = null;
|
|
var rankinfo:Object = null;
|
|
for(var keytype:String in Table.pve_info.rankInfo)
|
|
{
|
|
rankinfo = Table.pve_info.rankInfo[keytype];
|
|
if(score >= rankinfo.score && (vo == null || vo.score < rankinfo.score))
|
|
{
|
|
vo = rankinfo;
|
|
}
|
|
}
|
|
var rankvo:PveRankVo = new PveRankVo();
|
|
rankvo.rankType = vo.type;
|
|
return rankvo;
|
|
}
|
|
|
|
public function weekReward(pveAreaName:String, onComplete:Function) : void
|
|
{
|
|
onWeekRewardComplete = onComplete;
|
|
weekReward_buff = {"pveAreaName":pveAreaName};
|
|
NetPve.getIns().weekReward(pveAreaName,weekRewardHandler);
|
|
}
|
|
|
|
private function weekRewardHandler(re:Object) : void
|
|
{
|
|
RewardCenter.getIns().getRewardByData(re.reward,true,"panel");
|
|
getAreaByAreaType(weekReward_buff.pveAreaName).weekRewardGet = true;
|
|
if(onWeekRewardComplete != null)
|
|
{
|
|
onWeekRewardComplete();
|
|
onWeekRewardComplete = null;
|
|
}
|
|
}
|
|
|
|
public function getAreaByAreaType(type:String) : PveAreaInfoVo
|
|
{
|
|
return Master.pveInfo[type];
|
|
}
|
|
}
|
|
}
|
|
|