活动:大富翁
This commit is contained in:
73
shared/domain/activityField/monopolyField.ts
Normal file
73
shared/domain/activityField/monopolyField.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityMonopolyModelType } from '../../db/ActivityMonopoly';
|
||||
import { ActivityMonopolyLandModelType } from '../../db/ActivityMonopolyLand';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 地块数据
|
||||
export class LandItem {
|
||||
position: number; // 位置
|
||||
name: string; // 名字
|
||||
level: number; // 等级
|
||||
rewards: string[]; // 奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
landType: number //土地性质 LAND_TYPE
|
||||
saveMax: number //银行存钱最大数额
|
||||
takeOutMax: number //银行取钱最大次数
|
||||
shopActivityId: number //商店对应的商店id
|
||||
|
||||
record: any[] = []; //历史操作
|
||||
stopCount: number //停留次数
|
||||
|
||||
constructor(data: any) {
|
||||
this.position = data.position;
|
||||
this.name = data.name;
|
||||
this.level = data.level;
|
||||
this.rewards = data.rewards;
|
||||
this.landType = data.landType;
|
||||
this.saveMax = data.saveMax;
|
||||
this.takeOutMax = data.takeOutMax;
|
||||
this.shopActivityId = data.shopActivityId;
|
||||
this.record = [];
|
||||
this.stopCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 活动数据
|
||||
export class MonopolyData extends ActivityBase {
|
||||
curPosition: number; // 当前位置
|
||||
roundIndex: number; // 回合数
|
||||
list: Array<LandItem> = [];
|
||||
|
||||
public findMonopolyItem(position: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.position == position })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityMonopolyModelType, landDataArray: ActivityMonopolyLandModelType[]) {
|
||||
this.curPosition = (data && data.curPosition) ? data.curPosition : 0;
|
||||
this.roundIndex = (data && data.roundIndex) ? data.roundIndex : 0;
|
||||
|
||||
for (let landData of landDataArray) {
|
||||
let index = this.list.findIndex(item => { return item.position == landData.position })
|
||||
if (index != -1) {
|
||||
this.list[index].level = landData.level;
|
||||
this.list[index].record = landData.record ? landData.record : [];
|
||||
this.list[index].stopCount = landData.stopCount ? landData.stopCount : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let arr = JSON.parse(data);
|
||||
for (let obj of arr) {
|
||||
this.list.push(new LandItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user