mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
基础的数值计算
This commit is contained in:
@@ -10,7 +10,7 @@ export enum GTowards{
|
||||
export default class GObject<T> extends JNGSyncProtoBase<T>{
|
||||
|
||||
//当前模式
|
||||
_mode:GBaseMode<{}>;
|
||||
_mode:GBaseMode<{},{}>;
|
||||
|
||||
//是否镜像
|
||||
_isMirror:boolean = false;
|
||||
@@ -26,10 +26,10 @@ export default class GObject<T> extends JNGSyncProtoBase<T>{
|
||||
this._isMirror = value;
|
||||
}
|
||||
|
||||
get mode():GBaseMode<{}>{
|
||||
get mode():GBaseMode<{},{}>{
|
||||
return this._mode;
|
||||
}
|
||||
set mode(value:GBaseMode<{}>){
|
||||
set mode(value:GBaseMode<{},{}>){
|
||||
this._mode = value;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import { TB } from "../../../../resources/config/data/schema";
|
||||
import GRoleAttack from "../common/GRoleAttack";
|
||||
import GRoleDefault from "../role/GRoleDefault";
|
||||
import { GRoleAttackType } from "../values/GRoleValues";
|
||||
import { GAttackBase } from "./GAttack";
|
||||
|
||||
|
||||
@@ -7,7 +9,7 @@ import { GAttackBase } from "./GAttack";
|
||||
export default class GAttackNormal implements GAttackBase{
|
||||
|
||||
attack(role: GRoleDefault, info: TB.TbGRoleAttack) {
|
||||
role.fsm.enemy.onHit();
|
||||
GRoleAttack.onNormalAttack(role,role.fsm.enemy); //普通攻击
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import GDetection from "../common/GDetection";
|
||||
import { rect } from "cc";
|
||||
import GRoleDefault from "../role/GRoleDefault";
|
||||
import { TB } from "../../../../resources/config/data/schema";
|
||||
import GRoleAttack from "../common/GRoleAttack";
|
||||
|
||||
/**
|
||||
* 抛物线 爆炸普攻
|
||||
@@ -76,12 +77,10 @@ export default class GAttackParabolicRemote implements GAttackBase{
|
||||
//销毁
|
||||
bullet.node.destroy();
|
||||
|
||||
// enemy.getComponent(BoxCollider2D).apply();
|
||||
|
||||
// console.log(enemy.v2World,enemy.getComponent(BoxCollider2D).worldPoints,enemy.getComponent(UITransform).getBoundingBoxToWorld());
|
||||
GDetection.testAABBRole(rect(effect.node.worldPosition.x,effect.node.worldPosition.y,aw,ah)).forEach(role =>{
|
||||
role.onHit();
|
||||
GDetection.testAABBCenterRole(rect(effect.node.worldPosition.x,effect.node.worldPosition.y,aw,ah)).forEach(enemy =>{
|
||||
GRoleAttack.onNormalAttack(role,enemy); //普通攻击
|
||||
});
|
||||
|
||||
})
|
||||
.start();
|
||||
|
||||
|
@@ -8,7 +8,9 @@ import { Vec2 } from "cc";
|
||||
export default class GDetection{
|
||||
|
||||
//检测角色
|
||||
static testAABBRole(rect:math.Rect):GRoleBase<{}>[]{
|
||||
static testAABBCenterRole(rect:math.Rect):GRoleBase<{}>[]{
|
||||
rect.x -= rect.width / 2;
|
||||
rect.y -= rect.height / 2;
|
||||
//@ts-ignore
|
||||
return PhysicsSystem2D.instance.testAABB(rect).map(item => item.getComponent(GRoleBase<any>));
|
||||
}
|
||||
|
@@ -0,0 +1,13 @@
|
||||
import GRoleBase from "../role/GRoleBase";
|
||||
import GRoleDefault from "../role/GRoleDefault";
|
||||
import { GRoleAttackType } from "../values/GRoleValues";
|
||||
|
||||
//宠物攻击 工具类
|
||||
export default class GRoleAttack{
|
||||
|
||||
//普通攻击
|
||||
static onNormalAttack(attack:GRoleBase<{}>,hit:GRoleBase<{}>){
|
||||
hit.onHit(GRoleAttackType.NormalAttack,attack.values.onAttack(GRoleAttackType.NormalAttack),attack);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d4ea04bc-bcfc-45ce-9753-126ac88604d1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -48,7 +48,7 @@ export default class GSpine{
|
||||
}
|
||||
|
||||
// 创建一个 Spine 并且 播放 销毁
|
||||
static onPlaySceneSpine(scene:GBaseMode<{}>,pos:Vec2,spine:sp.SkeletonData,play:string):JNSkeleton{
|
||||
static onPlaySceneSpine(scene:GBaseMode<{},{}>,pos:Vec2,spine:sp.SkeletonData,play:string):JNSkeleton{
|
||||
|
||||
let create = this.onCreateSpine(spine);
|
||||
scene.addGNode(create.node,pos);
|
||||
|
@@ -8,6 +8,8 @@ import { GFSMAnimBase } from "../fsm/GFSMAnimBase";
|
||||
import GFSMBase from "../fsm/GFSMBase";
|
||||
import { app } from "../../../App";
|
||||
import { TB } from "../../../../resources/config/data/schema";
|
||||
import GRoleValues, { GRoleAttackType } from "../values/GRoleValues";
|
||||
import GAttributeBase from "../values/attribute/GAttributeBase";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum GRoleAnimEvent{
|
||||
@@ -19,8 +21,6 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
|
||||
@property(JNSkeleton)
|
||||
spine:JNSkeleton;
|
||||
// @property(sp.Skeleton)
|
||||
// spine:sp.Skeleton;
|
||||
|
||||
//角色
|
||||
role:TB.TbGRole;
|
||||
@@ -63,6 +63,9 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
//添加攻击回调
|
||||
addAttackCallback(fun:Function){this.attackCallbacks.push(fun)};
|
||||
|
||||
//角色数值类
|
||||
values:GRoleValues;
|
||||
|
||||
get():this{
|
||||
if(this.isDie) return null;
|
||||
return this;
|
||||
@@ -82,6 +85,9 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
//创建角色动画状态机
|
||||
this.fsmAnim = this.fsmAnimCreate();
|
||||
|
||||
//创建数值类
|
||||
this.values = new GRoleValues();
|
||||
|
||||
}
|
||||
|
||||
//初始化
|
||||
@@ -145,11 +151,12 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
}
|
||||
}
|
||||
|
||||
//受击
|
||||
onHit(){
|
||||
//受击 伤害类型 伤害
|
||||
onHit(type:GRoleAttackType,harm:number,enemy:GRoleBase<{}>){
|
||||
// return;
|
||||
this.blood -= 10;
|
||||
this.hitCallbacks.forEach(fun => fun(this,10));
|
||||
harm = this.values.onUnderAttack(type,harm)
|
||||
this.blood -= harm;
|
||||
this.hitCallbacks.forEach(fun => fun(this,harm));
|
||||
//检测是否死亡
|
||||
if(this.blood <= 0){
|
||||
//关闭状态机
|
||||
@@ -170,6 +177,20 @@ export default abstract class GRoleBase<T> extends GObject<T>{
|
||||
}
|
||||
}
|
||||
|
||||
//生效数值
|
||||
onEffectiveValue(...values:GAttributeBase[]){
|
||||
|
||||
this.values.reset();
|
||||
values.forEach(value => {
|
||||
this.values.add(value);
|
||||
})
|
||||
this.values.update();
|
||||
|
||||
//赋值血量
|
||||
this.blood = this.fullBlood = this.values.onBlood();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -9,9 +9,7 @@ import { JEasing } from "../../../../../extensions/ngame/assets/ngame/sync/frame
|
||||
import { GAttack } from "../attack/GAttack";
|
||||
import { v2 } from "cc";
|
||||
import { GTactical } from "../../entity/GTactical";
|
||||
import { Vec2 } from "cc";
|
||||
import { GSkill, GSkillBase, GSkillState } from "../../skill/GSkill";
|
||||
import JNFrameTime from "../../../../../extensions/ngame/assets/ngame/sync/frame/game/time/JNFrameTime";
|
||||
import { TB } from "../../../../resources/config/data/schema";
|
||||
import { TD } from "../../../App";
|
||||
const { property,ccclass } = _decorator;
|
||||
|
9
JisolGameCocos/assets/script/battle/base/values.meta
Normal file
9
JisolGameCocos/assets/script/battle/base/values.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "84ccbb8f-b24a-4d98-91c1-dcd3f0201edb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -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