Add attacking behavior
This commit is contained in:
parent
0afb0b6aee
commit
1927c922d7
79
source/Behavior/Attacking.ts
Normal file
79
source/Behavior/Attacking.ts
Normal file
@ -0,0 +1,79 @@
|
||||
import { Behavior } from "@Model/Behavior";
|
||||
import { Group } from "@Model/Group";
|
||||
import { Individual } from "@Model/Individual";
|
||||
import { Model } from "@Model/Model";
|
||||
|
||||
type IAttackingBehaviorParameter = {
|
||||
target: "CLG",
|
||||
success: "number",
|
||||
range: "number"
|
||||
}
|
||||
|
||||
type IAttackingBehaviorEvent = {}
|
||||
|
||||
class Attacking extends Behavior<IAttackingBehaviorParameter, IAttackingBehaviorEvent> {
|
||||
|
||||
public override behaviorId: string = "Attacking";
|
||||
|
||||
public override behaviorName: string = "$Title";
|
||||
|
||||
public override iconName: string = "DefenderTVM";
|
||||
|
||||
public override describe: string = "$Intro";
|
||||
|
||||
public override category: string = "$Interactive";
|
||||
|
||||
public override parameterOption = {
|
||||
target: { type: "CLG", name: "$Target" },
|
||||
range: { type: "number", name: "$Range", defaultValue: .05, numberMin: 0, numberStep: .01 },
|
||||
success: { type: "number", name: "$Success", defaultValue: 90, numberMin: 0, numberMax: 100, numberStep: 5 }
|
||||
};
|
||||
|
||||
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
|
||||
|
||||
for (let i = 0; i < this.parameter.target.objects.length; i++) {
|
||||
const targetGroup = this.parameter.target.objects[i];
|
||||
|
||||
targetGroup.individuals.forEach((targetIndividual) => {
|
||||
|
||||
// 排除自己
|
||||
if (targetIndividual === individual) return;
|
||||
let dis = targetIndividual.distanceTo(individual);
|
||||
|
||||
// 进入攻击范围
|
||||
if (dis <= this.parameter.range) {
|
||||
|
||||
// 成功判定
|
||||
if (Math.random() * 100 < this.parameter.success) {
|
||||
targetIndividual.die();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public override terms: Record<string, Record<string, string>> = {
|
||||
"$Title": {
|
||||
"ZH_CN": "攻击",
|
||||
"EN_US": "Attacking"
|
||||
},
|
||||
"$Target": {
|
||||
"ZH_CN": "攻击目标",
|
||||
"EN_US": "Attacking target"
|
||||
},
|
||||
"$Range": {
|
||||
"ZH_CN": "攻击范围 (m)",
|
||||
"EN_US": "Attacking range (m)"
|
||||
},
|
||||
"$Success": {
|
||||
"ZH_CN": "成功率 (%)",
|
||||
"EN_US": "Success rate (%)"
|
||||
},
|
||||
"$Intro": {
|
||||
"ZH_CN": "攻击进入共进范围的目标群个体",
|
||||
"EN_US": "Attack the target group and individual entering the range"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { Attacking };
|
@ -4,6 +4,7 @@ import { PhysicsDynamics } from "@Behavior/PhysicsDynamics";
|
||||
import { Brownian } from "@Behavior/Brownian";
|
||||
import { BoundaryConstraint } from "@Behavior/BoundaryConstraint";
|
||||
import { Tracking } from "@Behavior/Tracking";
|
||||
import { Attacking } from "@Behavior/Attacking";
|
||||
|
||||
const AllBehaviors: IAnyBehaviorRecorder[] = [
|
||||
new BehaviorRecorder(Template),
|
||||
@ -11,6 +12,7 @@ const AllBehaviors: IAnyBehaviorRecorder[] = [
|
||||
new BehaviorRecorder(Brownian),
|
||||
new BehaviorRecorder(BoundaryConstraint),
|
||||
new BehaviorRecorder(Tracking),
|
||||
new BehaviorRecorder(Attacking),
|
||||
]
|
||||
|
||||
/**
|
||||
|
@ -27,14 +27,14 @@ class PhysicsDynamics extends Behavior<IPhysicsDynamicsBehaviorParameter, IPhysi
|
||||
|
||||
public override parameterOption = {
|
||||
mass: { name: "$Mass", type: "number", defaultValue: 1, numberStep: .01, numberMin: .001 },
|
||||
resistance: { name: "$Resistance", type: "number", defaultValue: 0.5, numberStep: .1, numberMin: 0 },
|
||||
resistance: { name: "$Resistance", type: "number", defaultValue: 2.8, numberStep: .1, numberMin: 0 },
|
||||
limit: { name: "$Limit", type: "boolean", defaultValue: true },
|
||||
maxAcceleration: {
|
||||
name: "$Max.Acceleration", type: "number", defaultValue: 5,
|
||||
name: "$Max.Acceleration", type: "number", defaultValue: 6.25,
|
||||
numberStep: .1, numberMin: 0, condition: { key: "limit", value: true }
|
||||
},
|
||||
maxVelocity: {
|
||||
name: "$Max.Velocity", type: "number", defaultValue: 10,
|
||||
name: "$Max.Velocity", type: "number", defaultValue: 12.5,
|
||||
numberStep: .1, numberMin: 0, condition: { key: "limit", value: true }
|
||||
},
|
||||
};
|
||||
|
@ -4,7 +4,7 @@ import { Individual } from "@Model/Individual";
|
||||
import { Model } from "@Model/Model";
|
||||
|
||||
type ITrackingBehaviorParameter = {
|
||||
target: "LG",
|
||||
target: "CLG",
|
||||
strength: "number",
|
||||
range: "number",
|
||||
lock: "boolean"
|
||||
@ -136,8 +136,8 @@ class Tracking extends Behavior<ITrackingBehaviorParameter, ITrackingBehaviorEve
|
||||
"EN_US": "Tracking lock"
|
||||
},
|
||||
"$Range": {
|
||||
"ZH_CN": "追踪范围",
|
||||
"EN_US": "Tracking range"
|
||||
"ZH_CN": "追踪范围 (m)",
|
||||
"EN_US": "Tracking range (m)"
|
||||
},
|
||||
"$Strength": {
|
||||
"ZH_CN": "追踪强度系数",
|
||||
|
@ -39,7 +39,7 @@ class Group extends CtrlObject {
|
||||
/**
|
||||
* 生成个数
|
||||
*/
|
||||
public genCount: number = 1;
|
||||
public genCount: number = 100;
|
||||
|
||||
/**
|
||||
* 生成错误信息
|
||||
@ -54,7 +54,7 @@ class Group extends CtrlObject {
|
||||
/**
|
||||
* 删除个数
|
||||
*/
|
||||
public killCount: number = 1;
|
||||
public killCount: number = 100;
|
||||
|
||||
private genInSingleRange(count: number, range: Range) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
|
@ -116,6 +116,9 @@ class SimulatorWeb extends Component {
|
||||
|
||||
let dynamicShark = this.status.model.addBehavior(getBehaviorById("PhysicsDynamics"));
|
||||
dynamicShark.name = "Dynamic Shark"; dynamicShark.color = [250, 200, 80];
|
||||
dynamicShark.parameter.maxAcceleration = 8.5;
|
||||
dynamicShark.parameter.maxVelocity = 15.8;
|
||||
dynamicShark.parameter.resistance = 3.6;
|
||||
|
||||
let brownian = this.status.model.addBehavior(getBehaviorById("Brownian"));
|
||||
brownian.name = "Brownian"; brownian.color = [200, 80, 250];
|
||||
@ -128,6 +131,10 @@ class SimulatorWeb extends Component {
|
||||
tracking.name = "Tracking"; tracking.color = [80, 200, 250];
|
||||
tracking.parameter.target.picker = fishLabel;
|
||||
|
||||
let attacking = this.status.model.addBehavior(getBehaviorById("Attacking"));
|
||||
attacking.name = "Attacking"; attacking.color = [120, 100, 250];
|
||||
attacking.parameter.target.picker = fishLabel;
|
||||
|
||||
fish1.addBehavior(dynamicFish);
|
||||
fish1.addBehavior(brownian);
|
||||
fish1.addBehavior(boundary);
|
||||
@ -139,6 +146,7 @@ class SimulatorWeb extends Component {
|
||||
shark.addBehavior(dynamicShark);
|
||||
shark.addBehavior(boundary);
|
||||
shark.addBehavior(tracking);
|
||||
shark.addBehavior(attacking);
|
||||
|
||||
setTimeout(() => {
|
||||
this.status.model.updateBehaviorParameter();
|
||||
|
Loading…
Reference in New Issue
Block a user