68 lines
1.8 KiB
ActionScript
68 lines
1.8 KiB
ActionScript
package net.pixvi.myr.net
|
|
{
|
|
import net.pixvi.myr.element.battle.BattleType;
|
|
import net.pixvi.pfw.utils.core.Singleton;
|
|
|
|
public class NetBattle
|
|
{
|
|
|
|
private static const BATTLE_START:String = "battleService/battleStart";
|
|
|
|
private static const BATTLE_RECORD:String = "battleService/recordBattleResult";
|
|
|
|
private var onStartBattleComplete:Function;
|
|
|
|
public function NetBattle()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function getIns() : NetBattle
|
|
{
|
|
return Singleton.getInstanceOrCreate(NetBattle) as NetBattle;
|
|
}
|
|
|
|
public function battleResult(stageId:String, win:Boolean) : void
|
|
{
|
|
var para:Object = {
|
|
"stageId":stageId,
|
|
"cityId":stageId.charAt(1),
|
|
"result":(win ? 1 : 0)
|
|
};
|
|
NetCenter.getIns().send("battleService/recordBattleResult",para,null,false);
|
|
}
|
|
|
|
public function startBattle(battleType:String, id:*, level:String, onComplete:Function) : void
|
|
{
|
|
var para:Object = null;
|
|
onStartBattleComplete = onComplete;
|
|
if(battleType == "stage")
|
|
{
|
|
para = {
|
|
"battleType":"stage",
|
|
"stageTypeId":id,
|
|
"stageLevel":level
|
|
};
|
|
}
|
|
else if(battleType === BattleType.TASK_BATTLE)
|
|
{
|
|
para = {
|
|
"battleType":BattleType.TASK_BATTLE,
|
|
"taskTypeId":id
|
|
};
|
|
}
|
|
NetCenter.getIns().send("battleService/battleStart",para,startBattleHandler);
|
|
}
|
|
|
|
private function startBattleHandler(re:Object) : void
|
|
{
|
|
if(onStartBattleComplete != null)
|
|
{
|
|
onStartBattleComplete();
|
|
onStartBattleComplete = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|