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.common.utils.Alert;
|
||||
import net.pixvi.myr.CP;
|
||||
import net.pixvi.myr.GameMath;
|
||||
import net.pixvi.myr.element.achi.AchiVo;
|
||||
import net.pixvi.myr.element.reward.RewardResultVo;
|
||||
import net.pixvi.myr.event.MYREvent;
|
||||
import net.pixvi.myr.net.NetAchi;
|
||||
import net.pixvi.pfw.utils.ArrayUtil;
|
||||
import net.pixvi.pfw.utils.broadcast.GlobalBroadcast;
|
||||
import net.pixvi.pfw.utils.core.Singleton;
|
||||
|
||||
public class AchiCenter extends Singleton
|
||||
{
|
||||
|
||||
private var finishAchi_achi:AchiVo;
|
||||
|
||||
private var onFinishAchiComplete:Function;
|
||||
|
||||
public function AchiCenter()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getIns() : AchiCenter
|
||||
{
|
||||
return Singleton.getInstanceOrCreate(AchiCenter) as AchiCenter;
|
||||
}
|
||||
|
||||
public function autoCheck(type:String = "all", show:Boolean = false) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var a:String = null;
|
||||
var j:int = 0;
|
||||
var typeachis:Array = [];
|
||||
for(i = 0; i < Master.achis.length; )
|
||||
{
|
||||
a = Master.achis[i].type;
|
||||
if(type == "all" || Master.achis[i].type == type)
|
||||
{
|
||||
typeachis.push(Master.achis[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
for(j = 0; j < typeachis.length; j++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if((typeachis[j] as AchiVo).closed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
}
|
||||
if((show || !typeachis[j].showComplete) && typeachis[j].canFinish())
|
||||
{
|
||||
typeachis[j].showComplete = true;
|
||||
Alert.showMsg(CP.task(lang("获得成就") + "【" + typeachis[j].name + "】!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function finishAchi(achi:AchiVo, onComplete:Function = null) : void
|
||||
{
|
||||
onFinishAchiComplete = onComplete;
|
||||
finishAchi_achi = achi;
|
||||
NetAchi.getIns().finishAchi(achi.id.toString(),finishAchiHandler);
|
||||
}
|
||||
|
||||
private function finishAchiHandler(rewardResult:RewardResultVo) : void
|
||||
{
|
||||
finishAchi_achi.isComplete = true;
|
||||
RewardCenter.getIns().getReward(rewardResult,true,"panel");
|
||||
ArrayUtil.remove(Master.achis,finishAchi_achi);
|
||||
Master.achispass.push(finishAchi_achi);
|
||||
Master.history.passAchi.push(finishAchi_achi.id);
|
||||
for each(var i:int in finishAchi_achi.next)
|
||||
{
|
||||
if(Table.achi_info[i] != null)
|
||||
{
|
||||
unlockLocalAchi(i);
|
||||
}
|
||||
}
|
||||
GlobalBroadcast.dispatchEvent(new MYREvent(MYREvent.ACHI_NUM_CHANGE));
|
||||
finishAchi_achi = null;
|
||||
if(onFinishAchiComplete != null)
|
||||
{
|
||||
onFinishAchiComplete();
|
||||
onFinishAchiComplete = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function unlockLocalAchi(achiid:int) : void
|
||||
{
|
||||
var na:AchiVo = null;
|
||||
if(!checkAchiFinished(achiid))
|
||||
{
|
||||
na = new AchiVo();
|
||||
na.init(achiid);
|
||||
Master.achis.push(na);
|
||||
}
|
||||
}
|
||||
|
||||
public function getShowAchis() : Array
|
||||
{
|
||||
var i:int = 0;
|
||||
var achis:Array = [];
|
||||
for(i = 0; i < Master.achis.length; )
|
||||
{
|
||||
if(GameMath.ModeTrace || !Master.achis[i].hide || Master.achis[i].canFinish())
|
||||
{
|
||||
if(!Master.achis[i].closed)
|
||||
{
|
||||
achis.push(Master.achis[i]);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
achis.sortOn("id");
|
||||
return achis;
|
||||
}
|
||||
|
||||
public function hasCompleteAchi() : Boolean
|
||||
{
|
||||
for each(var achivo:AchiVo in Master.achis)
|
||||
{
|
||||
if(!achivo.closed && !achivo.isComplete && achivo.canFinish())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkLocalAchiList() : void
|
||||
{
|
||||
var k:int = 0;
|
||||
var data:Object = null;
|
||||
var ua:AchiVo = null;
|
||||
var i:int = 0;
|
||||
var achiTypeId:int = 0;
|
||||
var achiData:AchiVo = null;
|
||||
var j:int = 0;
|
||||
var nextId:int = 0;
|
||||
var curAchiData:AchiVo = null;
|
||||
var curAchis:Array = [];
|
||||
var passAchis:Array = [];
|
||||
for(k = 0; k < Table.achi_infoArr.length; )
|
||||
{
|
||||
data = Table.achi_infoArr[k];
|
||||
if(data.unlock && Master.history.passAchi.indexOf(int(data.id)) == -1)
|
||||
{
|
||||
ua = new AchiVo();
|
||||
ua.id = data.id;
|
||||
curAchis.push(ua);
|
||||
}
|
||||
k++;
|
||||
}
|
||||
for(i = 0; i < Master.history.passAchi.length; )
|
||||
{
|
||||
achiTypeId = int(Master.history.passAchi[i]);
|
||||
achiData = new AchiVo();
|
||||
achiData.isComplete = true;
|
||||
achiData.showComplete = true;
|
||||
achiData.id = achiTypeId;
|
||||
for(j = 0; j < achiData.next.length; )
|
||||
{
|
||||
nextId = int(achiData.next[j]);
|
||||
if(Table.achi_info[nextId] != null && Master.history.passAchi.indexOf(nextId) == -1)
|
||||
{
|
||||
curAchiData = new AchiVo();
|
||||
curAchiData.id = nextId;
|
||||
if(!curAchiData.closed)
|
||||
{
|
||||
curAchis.push(curAchiData);
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
passAchis.push(achiData);
|
||||
i++;
|
||||
}
|
||||
Master.achis = curAchis;
|
||||
Master.achispass = passAchis;
|
||||
}
|
||||
|
||||
public function checkAchiFinished(id:int) : Boolean
|
||||
{
|
||||
if(Master.history.passAchi.indexOf(id) != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user