183 lines
5.3 KiB
TypeScript
183 lines
5.3 KiB
TypeScript
//信物
|
|
export default class xwItem {
|
|
/**
|
|
* 道具ID
|
|
*/
|
|
itemID: number = 0;
|
|
/**
|
|
* 属性位置
|
|
*/
|
|
attr_pos: number[];
|
|
/**
|
|
* 属性标号
|
|
*/
|
|
attr_index: number[];
|
|
/**
|
|
* 属性标号
|
|
*/
|
|
attr_value: number[];
|
|
/**
|
|
* 洗练属性
|
|
*/
|
|
succinct_attr_pos: number[];
|
|
succinct_attr_index: number[];
|
|
succinct_attr_value: number[];
|
|
succinct_attr_max: number[];
|
|
|
|
attr_max: number[]
|
|
/**
|
|
* 构造函数
|
|
*/
|
|
constructor() {
|
|
this.itemID = 0
|
|
this.attr_index = []
|
|
this.attr_pos = []
|
|
this.attr_value = []
|
|
this.attr_max = []
|
|
|
|
this.succinct_attr_index = []
|
|
this.succinct_attr_pos = []
|
|
this.succinct_attr_value = []
|
|
this.succinct_attr_max = []
|
|
}
|
|
//设置道具ID
|
|
setXwItemID(itemID: number) {
|
|
this.itemID = itemID
|
|
}
|
|
//清空
|
|
clear() {
|
|
this.itemID = 0
|
|
this.ClearAttr(this.attr_pos, this.attr_index, this.attr_value, this.attr_max)
|
|
this.setXwItemInfo(0, -1, -1, -1, -1)
|
|
this.setXwItemInfo(1, -1, -1, -1, -1)
|
|
this.setXwItemInfo(2, -1, -1, -1, -1)
|
|
|
|
this.ClearAttr(this.succinct_attr_pos, this.succinct_attr_index,
|
|
this.succinct_attr_value, this.succinct_attr_max)
|
|
this.setNewAttr(0, -1, -1, -1, -1)
|
|
this.setNewAttr(1, -1, -1, -1, -1)
|
|
this.setNewAttr(2, -1, -1, -1, -1)
|
|
}
|
|
//是否拥有属性
|
|
isHasAttr() {
|
|
return (0 < this.attr_pos.length)
|
|
}
|
|
|
|
getItemID() {
|
|
return this.itemID
|
|
}
|
|
|
|
getItemPosByIndex(index: number) {
|
|
if (index < 0 || index >= this.attr_pos.length)
|
|
return -1
|
|
return this.attr_pos[index]
|
|
}
|
|
|
|
getItemAttrIndexByIndex(index: number) {
|
|
if (index < 0 || index >= this.attr_index.length)
|
|
return -1
|
|
return this.attr_index[index]
|
|
}
|
|
|
|
getItemAttrValueByIndex(index: number) {
|
|
if (index < 0 || index >= this.attr_value.length)
|
|
return -1
|
|
return this.attr_value[index]
|
|
}
|
|
|
|
getItemMaxByIndex(index: number) {
|
|
if (index < 0 || index >= this.attr_max.length)
|
|
return -1
|
|
return this.attr_max[index]
|
|
}
|
|
|
|
setXwItemInfo(_index: number, pos: number, index: number, value: number, max: number) {
|
|
if (0 >= this.attr_pos.length) {
|
|
this.attr_pos.push(pos)
|
|
this.attr_index.push(index)
|
|
this.attr_value.push(value)
|
|
this.attr_max.push(max)
|
|
} else {
|
|
this.attr_pos[_index] = pos
|
|
this.attr_index[_index] = index
|
|
this.attr_value[_index] = value
|
|
this.attr_max[_index] = max
|
|
}
|
|
}
|
|
|
|
getAttrInfo() {
|
|
var info = {
|
|
pos1: this.attr_pos[0],
|
|
attr1: this.attr_index[0],
|
|
value1: this.attr_value[0],
|
|
max1: this.attr_max[0],
|
|
|
|
pos2: this.attr_pos[1],
|
|
attr2: this.attr_index[1],
|
|
value2: this.attr_value[1],
|
|
max2: this.attr_max[1],
|
|
|
|
pos3: this.attr_pos[2],
|
|
attr3: this.attr_index[2],
|
|
value3: this.attr_value[2],
|
|
max3: this.attr_max[2],
|
|
}
|
|
return info
|
|
}
|
|
|
|
setNewAttr(index: number, pos: number, attr: number, attr_value: number, max: number) {
|
|
this.succinct_attr_pos[index] = pos
|
|
this.succinct_attr_index[index] = attr
|
|
this.succinct_attr_value[index] = attr_value
|
|
this.succinct_attr_max[index] = max
|
|
}
|
|
|
|
getNewAttrInfo() {
|
|
var info = {
|
|
pos1: this.succinct_attr_pos[0],
|
|
attr1: this.succinct_attr_index[0],
|
|
value1: this.succinct_attr_value[0],
|
|
max1: this.succinct_attr_max[0],
|
|
|
|
pos2: this.succinct_attr_pos[1],
|
|
attr2: this.succinct_attr_index[1],
|
|
value2: this.succinct_attr_value[1],
|
|
max2: this.succinct_attr_max[1],
|
|
|
|
pos3: this.succinct_attr_pos[2],
|
|
attr3: this.succinct_attr_index[2],
|
|
value3: this.succinct_attr_value[2],
|
|
max3: this.succinct_attr_max[2]
|
|
}
|
|
return info
|
|
}
|
|
//替换属性
|
|
replace_attr(): number {
|
|
if (-1 == this.succinct_attr_pos[0] || -1 == this.succinct_attr_pos[1] ||
|
|
-1 == this.succinct_attr_pos[2])
|
|
return 1
|
|
this.attr_pos.splice(0, this.attr_pos.length)
|
|
this.attr_index.splice(0, this.attr_index.length)
|
|
this.attr_value.splice(0, this.attr_value.length)
|
|
this.attr_max.splice(0, this.attr_max.length)
|
|
const size = this.succinct_attr_pos.length
|
|
for (var i = 0; i < size; ++i) {
|
|
this.attr_pos.push(this.succinct_attr_pos[i])
|
|
this.attr_index.push(this.succinct_attr_index[i])
|
|
this.attr_value.push(this.succinct_attr_value[i])
|
|
this.attr_max.push(this.succinct_attr_max[i])
|
|
}
|
|
return 0
|
|
}
|
|
//清空新属性
|
|
ClearAttr(pos_ary: any[], attr_ary: any[], attr_value_ary: any[], max_ary: any[]) {
|
|
pos_ary.splice(0, pos_ary.length)
|
|
attr_ary.splice(0, attr_ary.length)
|
|
attr_value_ary.splice(0, attr_value_ary.length)
|
|
max_ary.splice(0, max_ary.length)
|
|
this.setNewAttr(0, -1, -1, -1, -1)
|
|
this.setNewAttr(1, -1, -1, -1, -1)
|
|
this.setNewAttr(2, -1, -1, -1, -1)
|
|
}
|
|
}
|