97 lines
2.8 KiB
ActionScript
97 lines
2.8 KiB
ActionScript
package net.pixvi.myr.net
|
|
{
|
|
import net.pixvi.common.utils.Alert;
|
|
import net.pixvi.common.utils.mobi.MobiTools;
|
|
import net.pixvi.pfw.utils.core.Singleton;
|
|
|
|
public class NetGacha
|
|
{
|
|
|
|
private static const GACHA:String = "gachaService/gachaGetEggs";
|
|
|
|
private static const TIME_EGG_GACHA:String = "gachaService/gachaTimeEgg";
|
|
|
|
private static const TIME_EGG_BUY:String = "gachaService/gachaBuyTimeEgg";
|
|
|
|
private var onTimeEggGachaComplete:Function;
|
|
|
|
private var onTimeEggBuyComplete:Function;
|
|
|
|
private var onGachaComplete:Function;
|
|
|
|
public function NetGacha()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function getIns() : NetGacha
|
|
{
|
|
return Singleton.getInstanceOrCreate(NetGacha) as NetGacha;
|
|
}
|
|
|
|
public function timeEggGacha(onComplete:Function) : void
|
|
{
|
|
onTimeEggGachaComplete = onComplete;
|
|
var para:Object = {};
|
|
NetCenter.getIns().send("gachaService/gachaTimeEgg",para,timeEggGachaHandler);
|
|
}
|
|
|
|
public function timeEggGachaHandler(re:Object) : void
|
|
{
|
|
if(onTimeEggGachaComplete != null)
|
|
{
|
|
onTimeEggGachaComplete(re);
|
|
onTimeEggGachaComplete = null;
|
|
}
|
|
}
|
|
|
|
public function timeEggBuy(timeEggId:uint, onComplete:Function) : void
|
|
{
|
|
onTimeEggBuyComplete = onComplete;
|
|
var para:Object = {"timeEggId":timeEggId};
|
|
NetCenter.getIns().send("gachaService/gachaBuyTimeEgg",para,timeEggBuyHandler);
|
|
}
|
|
|
|
public function timeEggBuyHandler(re:Object) : void
|
|
{
|
|
if(Boolean(onTimeEggBuyComplete))
|
|
{
|
|
onTimeEggBuyComplete(re);
|
|
onTimeEggBuyComplete = null;
|
|
}
|
|
}
|
|
|
|
public function gacha(gachaId:String, num:Number, voucherNum:int, onComplete:Function, traceInfo:Object = null) : void
|
|
{
|
|
onGachaComplete = onComplete;
|
|
if(num < 1 || num > 1000)
|
|
{
|
|
Alert.yes("非法","特殊的非法操作。",MobiTools.getIns().exit);
|
|
return;
|
|
}
|
|
if(voucherNum < 0 || voucherNum > 1000)
|
|
{
|
|
Alert.yes("非法","特殊的非法操作。",MobiTools.getIns().exit);
|
|
return;
|
|
}
|
|
var msg:Object = {
|
|
"id":gachaId,
|
|
"num":num,
|
|
"voucherNum":voucherNum,
|
|
"traceInfo":traceInfo
|
|
};
|
|
NetCenter.getIns().send("gachaService/gachaGetEggs",msg,gachaHandler);
|
|
}
|
|
|
|
private function gachaHandler(re:Object) : void
|
|
{
|
|
if(onGachaComplete != null)
|
|
{
|
|
onGachaComplete(re.eggs,re.getMoney,re.getItem);
|
|
onGachaComplete = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|