|
@@ -29,6 +29,40 @@ export class GameModel extends DataModel{
|
|
|
super();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置默认属性
|
|
|
+ */
|
|
|
+ SetDefaultPropertys():void{
|
|
|
+ //默认武器
|
|
|
+ this.__currentWeaponCell=new WeaponCell();
|
|
|
+ this.__currentWeaponCell.cellId=-1;
|
|
|
+ this.__currentWeaponCell.lastOutputTime=director.getCurrentTime();
|
|
|
+ this.__currentWeaponCell.weaponId=10101;
|
|
|
+
|
|
|
+ //默认关卡
|
|
|
+ this.currentLevel=1;
|
|
|
+ //默认栅栏
|
|
|
+ this.currentFenceId=30001;
|
|
|
+
|
|
|
+ //默认最大已合成枪ID
|
|
|
+ this.synthesisMaxWeaponId=10101;
|
|
|
+
|
|
|
+ this.gold=0;
|
|
|
+ this.diamond=0;
|
|
|
+ //12个默认格子
|
|
|
+ let weaponCell:WeaponCell;
|
|
|
+ for (let index = 0; index < 12; index++) {
|
|
|
+ weaponCell=new WeaponCell();
|
|
|
+ weaponCell.cellId=index;
|
|
|
+ weaponCell.weaponId=10101;
|
|
|
+ weaponCell.lastOutputTime=0;
|
|
|
+ this.__weaponCells.push(weaponCell);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存到本地
|
|
|
+ this.SaveToLoacl();
|
|
|
+ }
|
|
|
+
|
|
|
private lastTime:number=0;
|
|
|
|
|
|
/**
|
|
@@ -76,6 +110,16 @@ export class GameModel extends DataModel{
|
|
|
this.gold+=fullEarnings*earningsIntervarS;
|
|
|
}
|
|
|
this.fullEarnings=fullEarnings;
|
|
|
+
|
|
|
+ if(this.DataChanged){
|
|
|
+ this.SaveToLoacl();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DataChanged:boolean;
|
|
|
+ DispatchEvent(key: string, data?: any):void{
|
|
|
+ super.DispatchEvent(key,data);
|
|
|
+ this.DataChanged=true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -256,7 +300,7 @@ export class GameModel extends DataModel{
|
|
|
* @param type 0 金币购买 1钻石购买 2视频购买
|
|
|
* @param weaponId
|
|
|
*/
|
|
|
- public BuyWeapon(type:number,weaponId:number):void{
|
|
|
+ public BuyWeapon(type:number,weaponId:number):boolean{
|
|
|
let price:number;
|
|
|
let weaponConfig:any
|
|
|
|
|
@@ -264,14 +308,14 @@ export class GameModel extends DataModel{
|
|
|
let weaponCell:WeaponCell=this.FindWeaponEmptyCell();
|
|
|
if(weaponCell==null){
|
|
|
NoticeManager.ShowPrompt("没有空槽位了!");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
if(type==0){
|
|
|
price=this.GetWeaponBuyPrice(weaponId);
|
|
|
if(this.gold<price){
|
|
|
NoticeManager.ShowPrompt("金币不足,不能购买武器!");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
//扣钱
|
|
|
let currentGold:number=this.gold;
|
|
@@ -293,7 +337,7 @@ export class GameModel extends DataModel{
|
|
|
price=weaponConfig.consumeDiamond;
|
|
|
if(this.diamond<price){
|
|
|
NoticeManager.ShowPrompt("宝石不足,不能购买武器!");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
//扣钱
|
|
|
let currentDiamond:number=this.gold;
|
|
@@ -305,6 +349,7 @@ export class GameModel extends DataModel{
|
|
|
}
|
|
|
//发货
|
|
|
this.AddWeapon(weaponCell.cellId,weaponId);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -328,41 +373,8 @@ export class GameModel extends DataModel{
|
|
|
return this.__weaponCells;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设置默认属性
|
|
|
- */
|
|
|
- SetDefaultPropertys():void{
|
|
|
- //默认武器
|
|
|
- this.__currentWeaponCell=new WeaponCell();
|
|
|
- this.__currentWeaponCell.cellId=-1;
|
|
|
- this.__currentWeaponCell.lastOutputTime=director.getCurrentTime();
|
|
|
- this.__currentWeaponCell.weaponId=10101;
|
|
|
-
|
|
|
- //默认关卡
|
|
|
- this.currentLevel=1;
|
|
|
- //默认栅栏
|
|
|
- this.currentFenceId=30001;
|
|
|
-
|
|
|
- //默认最大已合成枪ID
|
|
|
- this.synthesisMaxWeaponId=10101;
|
|
|
-
|
|
|
- this.gold=0;
|
|
|
- this.diamond=0;
|
|
|
- //12个默认格子
|
|
|
- let weaponCell:WeaponCell;
|
|
|
- for (let index = 0; index < 12; index++) {
|
|
|
- weaponCell=new WeaponCell();
|
|
|
- weaponCell.cellId=index;
|
|
|
- weaponCell.weaponId=10101;
|
|
|
- weaponCell.lastOutputTime=0;
|
|
|
- this.__weaponCells.push(weaponCell);
|
|
|
- }
|
|
|
-
|
|
|
- //保存到本地
|
|
|
- this.SaveToLoacl();
|
|
|
- }
|
|
|
-
|
|
|
protected OnReadByLocal(data:any):void{
|
|
|
+ let currentTime:number=director.getCurrentTime();
|
|
|
//当前武器格
|
|
|
this.__currentWeaponCell=new WeaponCell();
|
|
|
for (const key in data.currentWeaponCell) {
|
|
@@ -371,6 +383,7 @@ export class GameModel extends DataModel{
|
|
|
this.__currentWeaponCell[key]=element;
|
|
|
}
|
|
|
}
|
|
|
+ this.__currentWeaponCell.lastOutputTime=currentTime;
|
|
|
//武器格子
|
|
|
let weaponCells:any[]=data.weaponCells;
|
|
|
this.__weaponCells=[];
|
|
@@ -382,9 +395,10 @@ export class GameModel extends DataModel{
|
|
|
if (Object.prototype.hasOwnProperty.call(element, key)&&Object.prototype.hasOwnProperty.call(weaponCell, key)) {
|
|
|
const item = element[key];
|
|
|
weaponCell[key]=item;
|
|
|
- this.__weaponCells.push(weaponCell);
|
|
|
}
|
|
|
}
|
|
|
+ weaponCell.lastOutputTime=currentTime;
|
|
|
+ this.__weaponCells.push(weaponCell);
|
|
|
});
|
|
|
}
|
|
|
}
|