mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: dynamic dispersion
This commit is contained in:
1 parent
db6d181f78
commit
23751fbdf3
4 files changed
+52
-49
No files matched your search
@@ -2,6 +2,7 @@ import {
|
|||||||
ShellUpgrageSingleChange_AttributeName,
|
ShellUpgrageSingleChange_AttributeName,
|
||||||
TankAttributeChange_AttributeName,
|
TankAttributeChange_AttributeName,
|
||||||
} from "@protos/blitz_static_tank_upgrade_single_stage";
|
} from "@protos/blitz_static_tank_upgrade_single_stage";
|
||||||
|
import type { TankState } from "./tankState";
|
||||||
|
|
||||||
export type CharacteristicOutput = number | null;
|
export type CharacteristicOutput = number | null;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ type Characteristic = (helpers: {
|
|||||||
attributeSafe: (name: TankAttributeChange_AttributeName) => number | null;
|
attributeSafe: (name: TankAttributeChange_AttributeName) => number | null;
|
||||||
shell: (name: ShellUpgrageSingleChange_AttributeName) => number;
|
shell: (name: ShellUpgrageSingleChange_AttributeName) => number;
|
||||||
shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null;
|
shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null;
|
||||||
|
state: TankState;
|
||||||
}) => CharacteristicOutput;
|
}) => CharacteristicOutput;
|
||||||
|
|
||||||
export type CharacteristicName = keyof typeof characteristics;
|
export type CharacteristicName = keyof typeof characteristics;
|
||||||
@@ -22,26 +24,32 @@ export enum GunType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const characteristics = {
|
export const characteristics = {
|
||||||
clip_size({ attribute }) {
|
gun_type({ attributeSafe, attribute }) {
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
gun_type({ attributeSafe, characteristic }) {
|
|
||||||
const isPump =
|
const isPump =
|
||||||
attributeSafe(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP) ??
|
attributeSafe(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP) ??
|
||||||
0;
|
0;
|
||||||
|
|
||||||
if (isPump === 1) return GunType.AutoReloader;
|
if (isPump === 1) return GunType.AutoReloader;
|
||||||
|
|
||||||
const clipSize = characteristic("clip_size")!;
|
const clipSize = attribute(
|
||||||
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE
|
||||||
|
);
|
||||||
|
|
||||||
if (clipSize === 1) return GunType.Regular;
|
if (clipSize === 1) return GunType.Regular;
|
||||||
|
|
||||||
return GunType.AutoLoader;
|
return GunType.AutoLoader;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clip_size({ attribute, characteristic }) {
|
||||||
|
const gunType = characteristic("gun_type")!;
|
||||||
|
|
||||||
|
if (gunType === GunType.Regular) return null;
|
||||||
|
|
||||||
|
return attribute(
|
||||||
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
damage({ shell }) {
|
damage({ shell }) {
|
||||||
return shell(
|
return shell(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE
|
||||||
@@ -106,7 +114,6 @@ export const characteristics = {
|
|||||||
|
|
||||||
case GunType.AutoReloader: {
|
case GunType.AutoReloader: {
|
||||||
return -Infinity;
|
return -Infinity;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -158,40 +165,47 @@ export const characteristics = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
dispersion_still({ attribute }) {
|
speed_forward({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FORWARD_MAX_SPEED
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
speed_backward({ attribute }) {
|
||||||
|
return attribute(
|
||||||
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_BACKWARD_MAX_SPEED
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
dispersion({ attribute, characteristic, state }) {
|
||||||
|
const base = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_ANGLE
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_ANGLE
|
||||||
);
|
);
|
||||||
},
|
const movement = attribute(
|
||||||
|
|
||||||
dispersion_moving({ attribute }) {
|
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_MOVEMENT
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_MOVEMENT
|
||||||
);
|
);
|
||||||
},
|
const vehicleRotation = attribute(
|
||||||
|
|
||||||
dispersion_hull_traversing({ attribute }) {
|
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_ROTATION
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_ROTATION
|
||||||
);
|
);
|
||||||
},
|
const turretRotation = attribute(
|
||||||
|
|
||||||
dispersion_turret_traversing({ attribute }) {
|
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_TURRET_ROTATION
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_TURRET_ROTATION
|
||||||
);
|
);
|
||||||
},
|
const afterShot = attribute(
|
||||||
|
|
||||||
dispersion_shooting({ attribute }) {
|
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_AFTER_SHOT
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_AFTER_SHOT
|
||||||
);
|
);
|
||||||
},
|
const gunDamaged = attribute(
|
||||||
|
|
||||||
dispersion_gun_damaged({ attribute }) {
|
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_WHILE_GUN_DAMAGED
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_WHILE_GUN_DAMAGED
|
||||||
);
|
);
|
||||||
|
const maxSpeed = characteristic("speed_forward") as number;
|
||||||
|
|
||||||
|
return (
|
||||||
|
(state.isGunDamaged ? gunDamaged : 1) *
|
||||||
|
(base +
|
||||||
|
(state.speed / maxSpeed) * movement +
|
||||||
|
(state.isHullTraversing ? vehicleRotation : 0) +
|
||||||
|
(state.isTurretTraversing ? turretRotation : 0) +
|
||||||
|
(state.isShooting ? afterShot : 0))
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
gun_depression({ attributeSafe }) {
|
gun_depression({ attributeSafe }) {
|
||||||
@@ -210,18 +224,6 @@ export const characteristics = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
speed_forward({ attribute }) {
|
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FORWARD_MAX_SPEED
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
speed_backward({ attribute }) {
|
|
||||||
return attribute(
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_BACKWARD_MAX_SPEED
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
engine_power({ attribute }) {
|
engine_power({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_ENGINE_POWER
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_ENGINE_POWER
|
||||||
|
|||||||
@@ -44,16 +44,11 @@ export const characteristicsOrder: CharacteristicsOrder = [
|
|||||||
{ name: "shell_range", units: "m" },
|
{ name: "shell_range", units: "m" },
|
||||||
{ name: "shell_capacity" },
|
{ name: "shell_capacity" },
|
||||||
|
|
||||||
{ name: "aim_time", units: "s" },
|
{ name: "aim_time", decimals: 1, units: "s" },
|
||||||
|
|
||||||
{ toy: "aim_time" },
|
{ toy: "aim_time" },
|
||||||
|
|
||||||
{ name: "dispersion_still", units: "m" },
|
{ name: "dispersion", decimals: 3, units: "m" },
|
||||||
{ name: "dispersion_moving", units: "m" },
|
|
||||||
{ name: "dispersion_hull_traversing", units: "m" },
|
|
||||||
{ name: "dispersion_turret_traversing", units: "m" },
|
|
||||||
{ name: "dispersion_shooting", units: "m" },
|
|
||||||
{ name: "dispersion_gun_damaged", units: "m" },
|
|
||||||
|
|
||||||
{ name: "gun_depression", units: "deg" },
|
{ name: "gun_depression", units: "deg" },
|
||||||
{ name: "gun_elevation", units: "deg" },
|
{ name: "gun_elevation", units: "deg" },
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ export function computeCharacteristics(
|
|||||||
attributeSafe,
|
attributeSafe,
|
||||||
shell,
|
shell,
|
||||||
shellSafe,
|
shellSafe,
|
||||||
|
state,
|
||||||
});
|
});
|
||||||
computed[name] = value;
|
computed[name] = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,9 @@ export interface TankState {
|
|||||||
stage: number;
|
stage: number;
|
||||||
|
|
||||||
shell: number;
|
shell: number;
|
||||||
|
speed: number;
|
||||||
|
isHullTraversing: boolean;
|
||||||
|
isTurretTraversing: boolean;
|
||||||
|
isShooting: boolean;
|
||||||
|
isGunDamaged: boolean;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user