mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
基础的数值计算
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import GAttribute, { GAttributeType } from "./attribute/GAttribute";
|
||||
import GAttributeBase from "./attribute/GAttributeBase";
|
||||
|
||||
//宠物攻击类
|
||||
export enum GRoleAttackType{
|
||||
NormalAttack,
|
||||
}
|
||||
|
||||
//宠物数值 核心类
|
||||
export default class GRoleValues {
|
||||
|
||||
//宠物属性
|
||||
attribute:GAttribute;
|
||||
|
||||
get attributes(){
|
||||
return this.attribute.info;
|
||||
}
|
||||
|
||||
constructor(){
|
||||
|
||||
//初始化属性
|
||||
this.attribute = new GAttribute();
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
//重置
|
||||
reset(){
|
||||
//初始化属性
|
||||
this.attribute = new GAttribute();
|
||||
this.update();
|
||||
}
|
||||
|
||||
//添加属性类
|
||||
add(info:GAttributeBase){
|
||||
this.attribute.add(info);
|
||||
}
|
||||
|
||||
//刷新属性
|
||||
update(){
|
||||
//刷新属性
|
||||
this.attribute.update();
|
||||
}
|
||||
|
||||
//普通攻击
|
||||
onNormalAttack(){
|
||||
|
||||
//普通攻击伤害 = 攻击
|
||||
return this.attributes[GAttributeType.Attack];
|
||||
|
||||
}
|
||||
|
||||
//受到普通攻击
|
||||
onUnderNormalAttack(under:number){
|
||||
|
||||
//受到普通攻击伤害 = 受到伤害 - 防御
|
||||
return Math.max(0,under - this.attributes[GAttributeType.Defend]);
|
||||
|
||||
}
|
||||
|
||||
//受到攻击 统一方法
|
||||
onUnderAttack(type:GRoleAttackType,under:number){
|
||||
if(type == GRoleAttackType.NormalAttack){
|
||||
//受到普通攻击
|
||||
return this.onUnderNormalAttack(under);
|
||||
}
|
||||
return under;
|
||||
}
|
||||
|
||||
//攻击 统一方法
|
||||
onAttack(type:GRoleAttackType){
|
||||
if(type == GRoleAttackType.NormalAttack){
|
||||
//普通攻击
|
||||
return this.onNormalAttack();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//普通攻击某个目标
|
||||
onNormalAttackTarget(values:GRoleValues){
|
||||
return values.onUnderNormalAttack(this.onNormalAttack());
|
||||
}
|
||||
|
||||
//血量
|
||||
onBlood(){
|
||||
|
||||
//总血量 = 血量
|
||||
return this.attributes[GAttributeType.Blood];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "52b4e441-2a5c-4d33-8d4e-2b96df25afc2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "e3df25b3-9781-42c1-9b3d-a74be923c931",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
import { TD } from "../../../../App";
|
||||
import GAttributeBase from "./GAttributeBase";
|
||||
|
||||
//属性类型
|
||||
export enum GAttributeType{
|
||||
Attack = 110001, //攻击
|
||||
Defend = 110002, //防御
|
||||
Blood = 110003, //血量
|
||||
}
|
||||
|
||||
//属性类
|
||||
export default class GAttribute {
|
||||
|
||||
attributes:GAttributeBase[] = [];
|
||||
|
||||
//属性最终信息 {属性Id:属性值}
|
||||
info:{[key:number]:number} = {};
|
||||
|
||||
//添加一个属性类
|
||||
add(info:GAttributeBase){
|
||||
this.attributes.push(info);
|
||||
}
|
||||
|
||||
//重置
|
||||
reset(){
|
||||
this.attributes = [];
|
||||
this.update();
|
||||
}
|
||||
|
||||
//刷新属性
|
||||
update(){
|
||||
|
||||
this.info = {};
|
||||
|
||||
TD.TbGAttribute.getDataList().forEach(attr => {
|
||||
//初始化属性
|
||||
this.info[attr.id] = 0;
|
||||
});
|
||||
|
||||
//累加全部属性
|
||||
this.attributes.forEach((attribute) => {
|
||||
attribute.update();
|
||||
for (const key in attribute.attributes) {
|
||||
if(this.info[key]){
|
||||
this.info[key] = this.info[key] + attribute.attributes[key];
|
||||
}else{
|
||||
this.info[key] = attribute.attributes[key];
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "72467729-defa-485b-bd75-3bbe791ebea3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
|
||||
//属性 基类
|
||||
export default abstract class GAttributeBase{
|
||||
|
||||
//属性 {属性Id:属性值}
|
||||
attributes:{[key:number]:number} = {};
|
||||
|
||||
//刷新属性
|
||||
abstract update();
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a0ef91dd-110a-4622-8a6d-4c16a6255d5f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "54170ba9-5142-4612-9335-28436a7ddc08",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
import { TD } from "../../../../../App";
|
||||
import { PlayerPetOV } from "../../../../../consts/API";
|
||||
import GAttributeBase from "../GAttributeBase";
|
||||
|
||||
//宠物属性
|
||||
export default class GPetAttribute extends GAttributeBase{
|
||||
|
||||
//宠物信息
|
||||
pet:PlayerPetOV;
|
||||
|
||||
constructor(pet:PlayerPetOV){
|
||||
|
||||
super();
|
||||
this.pet = pet;
|
||||
|
||||
//固定属性直接计算
|
||||
this.compute();
|
||||
|
||||
}
|
||||
|
||||
//计算属性
|
||||
compute(){
|
||||
|
||||
this.attributes = {};
|
||||
//*************** 宠物初始属性 **************************
|
||||
let baseAttribute = TD.TbGRoleBaseAttribute.get(this.pet.petTbId) || TD.TbGRoleBaseAttribute.get(0);
|
||||
|
||||
//获取全部属性信息
|
||||
TD.TbGAttribute.getDataList().forEach(attr => {
|
||||
//保存初始属性 如果没有默认 0
|
||||
this.attributes[attr.id] = baseAttribute[attr.sign] || 0;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//刷新属性
|
||||
update(): void { }
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a66f3d1e-b975-4cf3-a666-54194eeda220",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user