|
@@ -30,22 +30,16 @@ export class GameModel extends DataModel {
|
|
|
/**
|
|
|
* 当前武器格子
|
|
|
*/
|
|
|
- private __currentWeaponCell: WeaponCell;
|
|
|
+ currentWeaponCell: WeaponCell;
|
|
|
|
|
|
constructor() {
|
|
|
super();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 设置默认属性
|
|
|
- */
|
|
|
+ * 设置默认属性
|
|
|
+ */
|
|
|
SetDefaultPropertys(): void {
|
|
|
- //默认武器
|
|
|
- this.__currentWeaponCell = new WeaponCell();
|
|
|
- this.__currentWeaponCell.cellId = -1;
|
|
|
- this.__currentWeaponCell.lastOutputTime = director.getCurrentTime();
|
|
|
- this.__currentWeaponCell.weaponId = 10101;
|
|
|
-
|
|
|
//默认关卡
|
|
|
this.currentLevel = 1;
|
|
|
//默认栅栏
|
|
@@ -65,6 +59,8 @@ export class GameModel extends DataModel {
|
|
|
weaponCell.lastOutputTime = 0;
|
|
|
this.__weaponCells.push(weaponCell);
|
|
|
}
|
|
|
+ //默认武器
|
|
|
+ this.currentWeaponCell=this.__weaponCells[0];
|
|
|
|
|
|
//保存到本地
|
|
|
this.SaveToLoacl();
|
|
@@ -101,9 +97,6 @@ export class GameModel extends DataModel {
|
|
|
result += weaponCell.weaponConfig.earnings;
|
|
|
}
|
|
|
});
|
|
|
- if (this.__currentWeaponCell.weaponId >= 0) {
|
|
|
- result += this.__currentWeaponCell.weaponConfig.earnings;
|
|
|
- }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -113,7 +106,7 @@ export class GameModel extends DataModel {
|
|
|
get earningsInterval(): number {
|
|
|
return GameConfigManager.getGlobalValue("earningsInterval");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 收益间隔时间
|
|
|
*/
|
|
@@ -162,16 +155,19 @@ export class GameModel extends DataModel {
|
|
|
this.DataChanged = true;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设置当前武器ID
|
|
|
- */
|
|
|
- set currentWeaponId(value: number) {
|
|
|
- this.__currentWeaponCell.weaponId = value;
|
|
|
- this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
|
|
|
- }
|
|
|
+ // /**
|
|
|
+ // * 设置当前武器ID
|
|
|
+ // */
|
|
|
+ // set currentWeaponId(value: number) {
|
|
|
+ // this.__currentWeaponCell.weaponId = value;
|
|
|
+ // this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
|
|
|
+ // }
|
|
|
|
|
|
get currentWeaponId(): number {
|
|
|
- return this.__currentWeaponCell.weaponId;
|
|
|
+ if(this.currentWeaponCell==null){
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return this.currentWeaponCell.weaponId;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -213,10 +209,18 @@ export class GameModel extends DataModel {
|
|
|
weChat.branchAnalytics(branchIdType.Synthetic, String(level))
|
|
|
}
|
|
|
|
|
|
- //如果比手上的好
|
|
|
- if (this.__currentWeaponCell.weaponConfig && newWeaponConfig.level > this.__currentWeaponCell.weaponConfig.level) {
|
|
|
- this.EquipWeapon(targetCellId);
|
|
|
- return;
|
|
|
+ if(this.currentWeaponCell!=null){
|
|
|
+ if(this.currentWeaponCell==sourceCell){
|
|
|
+ this.currentWeaponCell=null;
|
|
|
+ this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
|
|
|
+ }else if(this.currentWeaponCell==targetCell){
|
|
|
+ this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
|
|
|
+ //如果比手上的好
|
|
|
+ if(this.currentWeaponCell.weaponConfig && newWeaponConfig.level > this.currentWeaponCell.weaponConfig.level){
|
|
|
+ this.EquipWeapon(targetCell);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
|
|
|
|
|
@@ -244,41 +248,33 @@ export class GameModel extends DataModel {
|
|
|
* @param cellId
|
|
|
*/
|
|
|
public RemoveWeapon(cellId: number): void {
|
|
|
- for (let index = 0; index < this.__weaponCells.length; index++) {
|
|
|
- const element = this.__weaponCells[index];
|
|
|
- if (element.cellId == cellId) {
|
|
|
- element.weaponId = -1;
|
|
|
- this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
|
|
|
- return;
|
|
|
- }
|
|
|
+ let cell:WeaponCell=this.FindCell(cellId);
|
|
|
+ cell.weaponId=-1;
|
|
|
+ if(cell==this.currentWeaponCell){
|
|
|
+ this.currentWeaponCell=null;
|
|
|
+ this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
|
|
|
}
|
|
|
+ this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 卸下武器
|
|
|
- */
|
|
|
- public UnequipWeapon(cellId: number): void {
|
|
|
- let id: number = this.__currentWeaponCell.weaponId;
|
|
|
- this.currentWeaponId = -1;
|
|
|
- this.__currentWeaponCell.lastOutputTime = 0;
|
|
|
- this.AddWeapon(cellId, id);
|
|
|
- }
|
|
|
+ // /**
|
|
|
+ // * 卸下武器
|
|
|
+ // */
|
|
|
+ // public UnequipWeapon(cellId: number): void {
|
|
|
+ // let id: number = this.__currentWeaponCell.weaponId;
|
|
|
+ // this.currentWeaponId = -1;
|
|
|
+ // this.__currentWeaponCell.lastOutputTime = 0;
|
|
|
+ // this.AddWeapon(cellId, id);
|
|
|
+ // }
|
|
|
|
|
|
/**
|
|
|
* 装配武器
|
|
|
* @param weaponId
|
|
|
*/
|
|
|
- public EquipWeapon(sourceCellId: number): void {
|
|
|
- let cell: WeaponCell = this.FindCell(sourceCellId);
|
|
|
- if (cell == null) {
|
|
|
- throw new Error("找不到武器槽:" + sourceCellId);
|
|
|
- }
|
|
|
- let oldWeaponId = this.currentWeaponId;
|
|
|
- this.currentWeaponId = cell.weaponId;
|
|
|
- this.__currentWeaponCell.lastOutputTime = cell.lastOutputTime;
|
|
|
- cell.weaponId = oldWeaponId;
|
|
|
- cell.lastOutputTime = 0;
|
|
|
+ public EquipWeapon(sourceCell:WeaponCell): void {
|
|
|
+ this.currentWeaponCell=sourceCell;
|
|
|
this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
|
|
|
+ this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -432,15 +428,7 @@ export class GameModel extends DataModel {
|
|
|
|
|
|
protected OnReadByLocal(data: any): void {
|
|
|
let currentTime: number = director.getCurrentTime();
|
|
|
- //当前武器格
|
|
|
- this.__currentWeaponCell = new WeaponCell();
|
|
|
- for (const key in data.currentWeaponCell) {
|
|
|
- if (Object.prototype.hasOwnProperty.call(data.currentWeaponCell, key) && Object.prototype.hasOwnProperty.call(this.__currentWeaponCell, key)) {
|
|
|
- const element = data.currentWeaponCell[key];
|
|
|
- this.__currentWeaponCell[key] = element;
|
|
|
- }
|
|
|
- }
|
|
|
- this.__currentWeaponCell.lastOutputTime = currentTime;
|
|
|
+
|
|
|
//武器格子
|
|
|
let weaponCells: any[] = data.weaponCells;
|
|
|
this.__weaponCells = [];
|
|
@@ -458,6 +446,13 @@ export class GameModel extends DataModel {
|
|
|
this.__weaponCells.push(weaponCell);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ //当前武器格
|
|
|
+ if(data.currentWeaponCellId>0){
|
|
|
+ this.currentWeaponCell=this.FindCell(data.currentWeaponCellId);
|
|
|
+ this.currentWeaponCell.lastOutputTime = currentTime;
|
|
|
+ }
|
|
|
+
|
|
|
//自动合成Buffer剩余时间
|
|
|
if (data.autoSynthesisTime > 0) {
|
|
|
let buffer: AutoSyntheticBuffer = new AutoSyntheticBuffer("AutoSynthesis", data.autoSynthesisTime);
|
|
@@ -472,7 +467,11 @@ export class GameModel extends DataModel {
|
|
|
|
|
|
protected OnSaveToLocal(data: any): void {
|
|
|
data.weaponCells = this.__weaponCells;
|
|
|
- data.currentWeaponCell = this.__currentWeaponCell;
|
|
|
+ if(this.currentWeaponCell!=null){
|
|
|
+ data.currentWeaponCellId = this.currentWeaponCell.cellId;
|
|
|
+ }else{
|
|
|
+ data.currentWeaponCellId=-1;
|
|
|
+ }
|
|
|
//自动合成Buffer剩余时间
|
|
|
let buffers: IBuffer[] = BufferManager.GetBufferGroup("AutoSynthesis");
|
|
|
if (buffers != null && buffers.length > 0) {
|