Initialize local project and fix ranch growth synchronization
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
package net.pixvi.myr.center
|
||||
{
|
||||
import net.pixvi.common.system.language.lang;
|
||||
import net.pixvi.myr.element.bag.ItemVo;
|
||||
import net.pixvi.myr.element.gacha.GachaVo;
|
||||
import net.pixvi.myr.element.mon.EggVo;
|
||||
import net.pixvi.myr.net.NetGacha;
|
||||
import net.pixvi.myr.panel.reward.RewardShowPanel;
|
||||
import net.pixvi.myrane.MyrAne;
|
||||
import net.pixvi.myrloader.center.MyrCenter;
|
||||
import net.pixvi.pfw.utils.Random;
|
||||
import net.pixvi.pfw.utils.core.Singleton;
|
||||
|
||||
public class GachaCenter extends Singleton
|
||||
{
|
||||
|
||||
private var onGachaComplete:Function;
|
||||
|
||||
private var gacha_para:Object;
|
||||
|
||||
private var onTimeEggGachaComplete:Function;
|
||||
|
||||
private var onTimeEggBuyComplete:Function;
|
||||
|
||||
private var timeEggBuy_buffid:uint;
|
||||
|
||||
public function GachaCenter()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getIns() : GachaCenter
|
||||
{
|
||||
return Singleton.getInstanceOrCreate(GachaCenter) as GachaCenter;
|
||||
}
|
||||
|
||||
public function gacha(machineID:String = "", num:int = 0, useTicket:int = 0, onComplete:Function = null, traceInfo:Object = null, sliceEggs:Boolean = true) : void
|
||||
{
|
||||
onGachaComplete = onComplete;
|
||||
var cur:GachaVo = new GachaVo();
|
||||
cur.id = machineID;
|
||||
var needMoney:int = 0;
|
||||
var needKe:int = 0;
|
||||
var needTicket:int = useTicket;
|
||||
if(cur.money > 0)
|
||||
{
|
||||
needMoney = (num - useTicket) * cur.money;
|
||||
}
|
||||
else
|
||||
{
|
||||
needKe = (num - useTicket) * cur.ke;
|
||||
}
|
||||
gacha_para = {
|
||||
"sliceEggs":sliceEggs,
|
||||
"num":num,
|
||||
"useTicket":useTicket,
|
||||
"itemType":cur.item,
|
||||
"needKe":needKe,
|
||||
"needMoney":needMoney
|
||||
};
|
||||
if(MyrCenter.channel == "XDG" && !GuideCenter.getIns().checkFin("first10gacha") && cur.ke > 0 && num >= 10)
|
||||
{
|
||||
MyrAne.track("firstgacha");
|
||||
GuideCenter.getIns().fin("first10gacha");
|
||||
}
|
||||
NetGacha.getIns().gacha(machineID,num,needTicket,gachaHandler,traceInfo);
|
||||
}
|
||||
|
||||
private function gachaHandler(reEggs:Array, getMoney:int = 0, getItem:Object = null) : void
|
||||
{
|
||||
var j:int = 0;
|
||||
var egg:EggVo = null;
|
||||
var sliceEgg:EggVo = null;
|
||||
var getitemVo:ItemVo = null;
|
||||
var item:ItemVo = BagCenter.getIns().getByType(gacha_para.itemType);
|
||||
if(gacha_para.useTicket > 0)
|
||||
{
|
||||
BagCenter.getIns().subNum(item.id,gacha_para.useTicket,true);
|
||||
}
|
||||
if(gacha_para.needKe > 0)
|
||||
{
|
||||
MasterCenter.getIns().addKe(-gacha_para.needKe,true);
|
||||
}
|
||||
if(gacha_para.needMoney > 0)
|
||||
{
|
||||
MasterCenter.getIns().addMoney(-gacha_para.needMoney,true);
|
||||
}
|
||||
if(getMoney > 0)
|
||||
{
|
||||
MasterCenter.getIns().addMoney(getMoney,true);
|
||||
}
|
||||
var eggs:Array = [];
|
||||
for(j = 0; j < reEggs.length; )
|
||||
{
|
||||
egg = BagCenter.getItemByItemData(reEggs[j]) as EggVo;
|
||||
while(gacha_para.sliceEggs == true && egg.num > 1)
|
||||
{
|
||||
sliceEgg = new EggVo();
|
||||
sliceEgg.num = 1;
|
||||
sliceEgg.type = egg.type;
|
||||
sliceEgg.id = egg.id;
|
||||
egg.num--;
|
||||
eggs.push(sliceEgg);
|
||||
}
|
||||
trace(egg.num);
|
||||
eggs.push(egg);
|
||||
j++;
|
||||
}
|
||||
eggs = Random.randomArr(eggs);
|
||||
BagCenter.getIns().addItems(eggs);
|
||||
if(getItem != null)
|
||||
{
|
||||
getitemVo = new ItemVo();
|
||||
getitemVo.readObject(getItem);
|
||||
getitemVo.num = gacha_para.num;
|
||||
getitemVo.type = getItem.typeId;
|
||||
BagCenter.getIns().addItem(getitemVo);
|
||||
}
|
||||
onGachaComplete(eggs);
|
||||
}
|
||||
|
||||
public function timeEggGacha(onComplete:Function) : void
|
||||
{
|
||||
onTimeEggGachaComplete = onComplete;
|
||||
NetGacha.getIns().timeEggGacha(timeEggGachaHandler);
|
||||
}
|
||||
|
||||
public function timeEggGachaHandler(re:Object) : void
|
||||
{
|
||||
Master.history.timeEggItems.push(re.timeGacha);
|
||||
if(onTimeEggGachaComplete != null)
|
||||
{
|
||||
onTimeEggGachaComplete(re.timeGacha);
|
||||
onTimeEggGachaComplete = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function timeEggBuy(id:uint, onComplete:Function) : void
|
||||
{
|
||||
onTimeEggBuyComplete = onComplete;
|
||||
timeEggBuy_buffid = id;
|
||||
NetGacha.getIns().timeEggBuy(id,timeEggBuyHandler);
|
||||
}
|
||||
|
||||
public function timeEggBuyHandler(re:Object) : void
|
||||
{
|
||||
var resultStr:String = null;
|
||||
var i:int = 0;
|
||||
var showEggVo:EggVo = null;
|
||||
BagCenter.getIns().subNumByType(Table.game_setting["timeEggItem"],1,true,lang("使用了{0} 个 {1}"));
|
||||
RewardCenter.getIns().getRewardByData(re.reward,false);
|
||||
for each(var o:Object in Master.history.timeEggItems)
|
||||
{
|
||||
if(o.id == timeEggBuy_buffid)
|
||||
{
|
||||
o.selected = true;
|
||||
resultStr = o.result;
|
||||
}
|
||||
}
|
||||
var monEggTypes:Array = resultStr.split(",");
|
||||
var showEggs:Array = [];
|
||||
for(i = 0; i < monEggTypes.length; )
|
||||
{
|
||||
showEggVo = new EggVo();
|
||||
showEggVo.type = monEggTypes[i];
|
||||
showEggVo.num = 1;
|
||||
showEggs.push(showEggVo);
|
||||
i++;
|
||||
}
|
||||
RewardShowPanel.show(showEggs,null,false);
|
||||
if(Boolean(onTimeEggBuyComplete))
|
||||
{
|
||||
onTimeEggBuyComplete();
|
||||
onTimeEggBuyComplete = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTimeEggItemNum() : int
|
||||
{
|
||||
return BagCenter.getIns().getNum(Table.game_setting["timeEggItem"]);
|
||||
}
|
||||
|
||||
public function getTimeEggLeftGacha() : int
|
||||
{
|
||||
return Table.game_setting["timeEggNum"] - Master.history.timeEggItems.length;
|
||||
}
|
||||
|
||||
public function getSelectedTimeEggItem() : Object
|
||||
{
|
||||
for each(var o:Object in Master.history.timeEggItems)
|
||||
{
|
||||
if(o.selected == true)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user