105 lines
2.9 KiB
ActionScript
105 lines
2.9 KiB
ActionScript
package net.pixvi.myr.net
|
|
{
|
|
import net.pixvi.common.utils.Alert;
|
|
import net.pixvi.common.utils.mobi.MobiTools;
|
|
import net.pixvi.myr.center.AccountCenter;
|
|
import net.pixvi.myr.center.Master;
|
|
import net.pixvi.pfw.utils.core.Singleton;
|
|
|
|
public class NetItem
|
|
{
|
|
|
|
public var USE_ITEM:String = "itemService/itemUse";
|
|
|
|
public var SELL_ITEM:String = "itemService/itemSell";
|
|
|
|
public var GET_GIFTCODE:String = "giftService/useGiftCode";
|
|
|
|
private var onSellItemComplete:Function;
|
|
|
|
private var onUseItemComplete:Function;
|
|
|
|
private var onGiftCodeComplete:Function;
|
|
|
|
public function NetItem()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function getIns() : NetItem
|
|
{
|
|
return Singleton.getInstanceOrCreate(NetItem) as NetItem;
|
|
}
|
|
|
|
public function sellItem(itemId:Number, num:int, onComplete:Function) : void
|
|
{
|
|
onSellItemComplete = onComplete;
|
|
if(num < 1 || num > 100000)
|
|
{
|
|
Alert.yes("非法","特殊的非法操作。",MobiTools.getIns().exit);
|
|
return;
|
|
}
|
|
var para:Object = {
|
|
"itemId":itemId,
|
|
"num":num
|
|
};
|
|
NetCenter.getIns().send(SELL_ITEM,para,sellItemHandler);
|
|
}
|
|
|
|
private function sellItemHandler(re:Object) : void
|
|
{
|
|
if(onSellItemComplete != null)
|
|
{
|
|
onSellItemComplete(re.money);
|
|
onSellItemComplete = null;
|
|
}
|
|
}
|
|
|
|
public function useItem(itemId:Number, num:int, onComplete:Function) : void
|
|
{
|
|
onUseItemComplete = onComplete;
|
|
if(num < 1 || num > 100000)
|
|
{
|
|
Alert.yes("非法","特殊的非法操作。",MobiTools.getIns().exit);
|
|
return;
|
|
}
|
|
var para:Object = {
|
|
"itemId":itemId,
|
|
"num":num
|
|
};
|
|
NetCenter.getIns().send(USE_ITEM,para,useItemHandler);
|
|
}
|
|
|
|
private function useItemHandler(re:Object) : void
|
|
{
|
|
if(onUseItemComplete != null)
|
|
{
|
|
onUseItemComplete(re.reward,re.param);
|
|
onUseItemComplete = null;
|
|
}
|
|
}
|
|
|
|
public function giftCode(giftCode:String, onComplete:Function) : void
|
|
{
|
|
onGiftCodeComplete = onComplete;
|
|
var para:Object = {
|
|
"giftCode":giftCode,
|
|
"masterId":Master.id,
|
|
"serverId":AccountCenter.getIns().curServer.serverId,
|
|
"isMail":false
|
|
};
|
|
NetCenter.getIns().send(GET_GIFTCODE,para,giftCodeHandler,true,null,NetCenter.SERVER_MODE_CENTER);
|
|
}
|
|
|
|
private function giftCodeHandler(re:Object) : void
|
|
{
|
|
if(onGiftCodeComplete != null)
|
|
{
|
|
onGiftCodeComplete(re.rewardResult,re.resCode,re.resMsg);
|
|
onGiftCodeComplete = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|