|
@@ -7,6 +7,7 @@ import { ServerManager, BlastToMerge } from "../Net/ServerManager";
|
|
|
import { AudioManager, MusicType } from "./AudioManager";
|
|
|
import { GamePool } from "./GamePool";
|
|
|
import { AssetManager } from "../Main/AssetManager";
|
|
|
+import Gift from "../Main/Gift";
|
|
|
|
|
|
export class DropRule{
|
|
|
private static ins:DropRule;
|
|
@@ -15,8 +16,9 @@ export class DropRule{
|
|
|
DropRule.ins = this;
|
|
|
this.Init();
|
|
|
this.InitEffect();
|
|
|
- // EventManager.StageOn(StageMode.ReStart,this,this.Init);
|
|
|
+ this.InitGift();
|
|
|
EventManager.StageOn(StageMode.Refresh,this,this.Init);
|
|
|
+ EventManager.StageOn(StageMode.ReStart,this,this.Pass);
|
|
|
}
|
|
|
public static get Instance():DropRule{
|
|
|
if(DropRule.ins){
|
|
@@ -26,6 +28,11 @@ export class DropRule{
|
|
|
return new DropRule();
|
|
|
}
|
|
|
}
|
|
|
+ //礼盒名字数组
|
|
|
+ public GiftName:string[] = new Array<string>("Gift","TimeGift");
|
|
|
+ //礼盒预制体数组
|
|
|
+ public GiftArray:Laya.Prefab[] = [];
|
|
|
+
|
|
|
//特效名字数组
|
|
|
public EffectName:string[] = new Array<string>("blue","yellow","purple","green");
|
|
|
//特效预制体数组
|
|
@@ -83,7 +90,6 @@ export class DropRule{
|
|
|
this.DropHeight = Number(Level.hight);
|
|
|
this.GoalScore = Number(Level.goal);
|
|
|
this.SizeIndex = Level.index.split(";");
|
|
|
- console.log(this.SizeIndex);
|
|
|
this.BallNum = Level.edge.split(";");
|
|
|
this.StartNum = Number(Level.start_number);
|
|
|
this.DropNum = Level.drop_number.split(";");
|
|
@@ -101,17 +107,32 @@ export class DropRule{
|
|
|
//特效
|
|
|
InitEffect(){
|
|
|
for (let i = 0; i < this.EffectName.length; i++) {
|
|
|
- this.ReadJson(i)
|
|
|
+ this.EffectReadJson(i)
|
|
|
}
|
|
|
}
|
|
|
- ReadJson(i:number){
|
|
|
- Laya.loader.create("Effect/"+this.EffectName[i]+".json",Laya.Handler.create(this,this.creat));
|
|
|
+ EffectReadJson(i:number){
|
|
|
+ Laya.loader.create("Effect/"+this.EffectName[i]+".json",Laya.Handler.create(this,this.EffectCreat));
|
|
|
}
|
|
|
- creat(Prefab:any){
|
|
|
+ EffectCreat(Prefab:any){
|
|
|
let obj = new Laya.Prefab();
|
|
|
obj.json = Prefab;
|
|
|
this.EffectArray.push(obj);
|
|
|
}
|
|
|
+
|
|
|
+ //礼盒
|
|
|
+ InitGift(){
|
|
|
+ for (let i = 0; i < this.GiftName.length; i++) {
|
|
|
+ this.GiftReadJson(i)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ GiftReadJson(i:number){
|
|
|
+ Laya.loader.create("GiftPrefab/"+this.GiftName[i]+".json",Laya.Handler.create(this,this.GiftCreat));
|
|
|
+ }
|
|
|
+ GiftCreat(Prefab:any){
|
|
|
+ let obj = new Laya.Prefab();
|
|
|
+ obj.json = Prefab;
|
|
|
+ this.GiftArray.push(obj);
|
|
|
+ }
|
|
|
|
|
|
/**传入分数及位置 克隆相应销毁特效 */
|
|
|
CreateEffect(_score:number,_pos:Laya.Vector2){
|
|
@@ -141,6 +162,134 @@ export class DropRule{
|
|
|
pre.destroy();
|
|
|
})
|
|
|
}
|
|
|
+ /**过关 2-7关 关卡开始掉落普通礼盒 数量2 第八关开始每关掉落普通礼盒 数量1*/
|
|
|
+ Pass(_data?){
|
|
|
+ if(_data){
|
|
|
+ if(this.STAGE >=2 && this.STAGE<=6){
|
|
|
+ let X = GameTools.RandomANumber(100,500);
|
|
|
+ let pos = new Laya.Vector2(X, 0);
|
|
|
+ switch (this.STAGE) {
|
|
|
+ case 2:
|
|
|
+ this.CreateGift(0,pos,5,2);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ this.CreateGift(0,pos,4,2);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ this.CreateGift(0,pos,3,2);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ this.CreateGift(0,pos,2,2);
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ this.CreateGift(0,pos,1,2);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(this.STAGE >= 9){
|
|
|
+ for (let i = 0; i < Laya.stage.numChildren; i++) {
|
|
|
+ if(Laya.stage.getChildAt(i).name == "Gift"){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ let X = GameTools.RandomANumber(100,500);
|
|
|
+ let pos = new Laya.Vector2(X, 0);
|
|
|
+ this.CreateGift(0,pos,this.JudgePropNum(),1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断玩家持有的各种道具的数量
|
|
|
+ JudgePropNum():number{
|
|
|
+ let proparray = [];
|
|
|
+ let one = {"key":"1","value":AccountManager.Instance.curplayerData.GetPropNum(1)};
|
|
|
+ let two = {"key":"2","value":AccountManager.Instance.curplayerData.GetPropNum(2)};
|
|
|
+ let three = {"key":"3","value":AccountManager.Instance.curplayerData.GetPropNum(3)};
|
|
|
+ let four = {"key":"4","value":AccountManager.Instance.curplayerData.GetPropNum(4)};
|
|
|
+ let five = {"key":"5","value":AccountManager.Instance.curplayerData.GetPropNum(5)};
|
|
|
+ proparray.push(one);
|
|
|
+ proparray.push(two);
|
|
|
+ proparray.push(three);
|
|
|
+ proparray.push(four);
|
|
|
+ proparray.push(five);
|
|
|
+ for (let i = 0; i < proparray.length; i++) {
|
|
|
+ for (let j = 0; j < proparray.length-i-1; j++) {
|
|
|
+ if(proparray[j].value < proparray[j+1].value){
|
|
|
+ let temp = proparray[j].value;
|
|
|
+ proparray[j].value = proparray[j+1].value;
|
|
|
+ proparray[j+1].value = temp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return proparray[0].value;
|
|
|
+ }
|
|
|
+ /** 传入盒子序号 传入道具类型 传入道具数量 创建礼盒 */
|
|
|
+ CreateGift(index:number,_pos:Laya.Vector2,giftindex:number,giftnum:number){
|
|
|
+ // let effect = this.GiftArray[index];
|
|
|
+ // let pre = Laya.Pool.getItemByCreateFun(this.GiftName[index],effect.create,effect) as Laya.Image;
|
|
|
+ //礼盒图片
|
|
|
+ let giftname = index == 0?"Gift":"TimeGift";
|
|
|
+ let pre = GamePool.Instance.GetModel(giftname);
|
|
|
+ pre.skin = "Game/res/Skin/"+ giftname + ".png";
|
|
|
+ pre.anchorX = 0.5;
|
|
|
+ pre.anchorY = 0.5;
|
|
|
+ pre.height = AccountManager.Instance.curplayerData.GiftSize;
|
|
|
+ pre.width = AccountManager.Instance.curplayerData.GiftSize;
|
|
|
+ pre.name = giftname;
|
|
|
+ //刚体碰撞器
|
|
|
+ let _rig = pre.getComponent(Laya.RigidBody) as Laya.RigidBody;
|
|
|
+ if(!_rig){
|
|
|
+ let rig = pre.addComponent(Laya.RigidBody) as Laya.RigidBody;
|
|
|
+ rig.gravityScale = 3;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ pre.getComponent(Laya.RigidBody).enabled = true;
|
|
|
+ }
|
|
|
+ let _collider = pre.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
|
|
|
+ if(!_collider){
|
|
|
+ let collider = pre.addComponent(Laya.CircleCollider) as Laya.CircleCollider;
|
|
|
+ collider.radius = AccountManager.Instance.curplayerData.GiftSize/2;
|
|
|
+ collider.restitution = AccountManager.Instance.curplayerData.Restitution;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ pre.getComponent(Laya.CircleCollider).enabled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(index == 1 ){
|
|
|
+ //倒计时框
|
|
|
+ let kuang:Laya.Image = new Laya.Image();
|
|
|
+ kuang.skin = "Game/res/Skin/kuang.png";
|
|
|
+ kuang.anchorX = 0.5;
|
|
|
+ kuang.anchorY = 0.5;
|
|
|
+ pre.addChild(kuang);
|
|
|
+ kuang.centerX = 0;
|
|
|
+ kuang.centerY = 0;
|
|
|
+ //文本
|
|
|
+ let countdown:Laya.Text = new Laya.Text();
|
|
|
+ countdown.width = 33;
|
|
|
+ countdown.height = 24;
|
|
|
+ countdown.color = "#ffffff";
|
|
|
+ countdown.align = "center";
|
|
|
+ countdown.valign = "middle";
|
|
|
+ countdown.fontSize = 20;
|
|
|
+ pre.addChild(countdown);
|
|
|
+ countdown.x = pre.x;
|
|
|
+ countdown.y = pre.y;
|
|
|
+ }
|
|
|
+ let script = pre.getComponent(Gift) as Gift;
|
|
|
+ if(!script){
|
|
|
+ let giftscript = pre.addComponent(Gift) as Gift;
|
|
|
+ //道具种类
|
|
|
+ giftscript.GiftIndex = giftindex;
|
|
|
+ //道具数量
|
|
|
+ giftscript.GiftNum = giftnum;
|
|
|
+ //礼盒种类
|
|
|
+ giftscript.type = index;
|
|
|
+ }
|
|
|
+ pre.pos(_pos.x,_pos.y);
|
|
|
+ Laya.stage.addChild(pre);
|
|
|
+ }
|
|
|
/** 传入分数获取球的序号*/
|
|
|
GetBallIndex(_score:number):number{
|
|
|
let num;
|
|
@@ -209,15 +358,13 @@ export class DropRule{
|
|
|
}
|
|
|
/**创建球的预制 合成克隆*/
|
|
|
CreatBall(_index:number,size:number,pos:Laya.Vector2){
|
|
|
- // let ball = GamePool.Instance.GetModel(AssetManager.Instance.Ball.get(_index),_index.toString());
|
|
|
let ball = GamePool.Instance.GetModel("img"+_index.toString());
|
|
|
- // let ball = Laya.Pool.getItemByClass("img" + _index.toString(),Laya.Image);
|
|
|
- // let ball:Laya.Image = new Laya.Image();
|
|
|
ball.skin = "Game/res/Ball/blast"+ _index + ".png";
|
|
|
ball.anchorX = 0.5;
|
|
|
ball.anchorY = 0.5;
|
|
|
ball.height = size;
|
|
|
ball.width = size;
|
|
|
+ ball.name = "ball";
|
|
|
//刚体碰撞器
|
|
|
let _rig = ball.getComponent(Laya.RigidBody) as Laya.RigidBody;
|
|
|
if(!_rig ){//|| _rig.destroyed
|
|
@@ -288,7 +435,6 @@ export class DropRule{
|
|
|
let script = ball.addComponent(Ball) as Ball;
|
|
|
}
|
|
|
ball.pos(pos.x,pos.y);
|
|
|
- // this.SetPosition(ball,pos);
|
|
|
Laya.timer.once(1,this,()=>{
|
|
|
EventManager.StageTrigger(StageMode.Clone,[ball]);
|
|
|
})
|
|
@@ -298,14 +444,12 @@ export class DropRule{
|
|
|
/**创建球的预制 自动掉球*/
|
|
|
CreatBall2(_index:number,size:number,pos:Laya.Vector2){
|
|
|
let ball = GamePool.Instance.GetModel("img"+_index.toString());
|
|
|
- // let ball = GamePool.Instance.GetModel(AssetManager.Instance.Ball.get(_index),_index.toString());
|
|
|
- // let ball = Laya.Pool.getItemByClass("img" +_index.toString(),Laya.Image);
|
|
|
- // let ball:Laya.Image = new Laya.Image();
|
|
|
ball.skin = "Game/res/Ball/blast"+ _index + ".png";
|
|
|
ball.anchorX = 0.5;
|
|
|
ball.anchorY = 0.5;
|
|
|
ball.height = size;
|
|
|
ball.width = size;
|
|
|
+ ball.name = "ball";
|
|
|
//碰撞器
|
|
|
let _collider = ball.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
|
|
|
if(!_collider ){//|| _collider.destroyed
|
|
@@ -381,7 +525,6 @@ export class DropRule{
|
|
|
let script = ball.addComponent(Ball) as Ball;
|
|
|
}
|
|
|
ball.pos(pos.x,pos.y);
|
|
|
- // this.SetPosition(ball,pos);
|
|
|
Laya.timer.once(1,this,()=>{
|
|
|
EventManager.StageTrigger(StageMode.Clone,[ball]);
|
|
|
})
|
|
@@ -574,13 +717,18 @@ export class DropRule{
|
|
|
RecoverScene(){
|
|
|
for (let i = 0; i < this.progress.length-3; i++) {
|
|
|
let item = this.progress[i];
|
|
|
- this.CreatBall2(Number(item.index)-1,Number(item.size),new Laya.Vector2(Number(item.pos.x),Number(item.pos.y)));
|
|
|
+ if(item.itemtype == 0){
|
|
|
+ this.CreatBall2(Number(item.index)-1,Number(item.size),new Laya.Vector2(Number(item.pos.x),Number(item.pos.y)));
|
|
|
+ }
|
|
|
+ else if(item.itemtype == 1){
|
|
|
+ this.CreateGift(item.type,new Laya.Vector2(Number(item.pos.x),Number(item.pos.y)),Number(item.proptype),Number(item.giftnum));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
/**读取进度*/
|
|
|
Read(){
|
|
|
if(this.STAGE>1){
|
|
|
- var args =[{"stage":"0"}]
|
|
|
+ let args =[{"stage":"0"}]
|
|
|
ServerManager.Instance.SendHttp(BlastToMerge.GetProgress,args,Laya.Handler.create(this,(res)=>{
|
|
|
let json =JSON.parse(res.user_game.detail);
|
|
|
this.progress = json;
|