feat: he mechanics

This commit is contained in:
TrèsAbhi committed 2024-02-29 10:40:36 -06:00
1 parent bf6991ce06
commit fa8922e0a6
3 files changed
+33 -20

No files matched your search

@@ -26,6 +26,9 @@ const LENGTH_INFINITY = 4;
export function ShotDisplay() {
const shot = useTankopediaTemporary((state) => state.shot);
const hasMultipleLayers = shot?.some(
(layer, index) => index !== 0 && layer.type !== null,
);
console.log(shot);
@@ -40,6 +43,9 @@ export function ShotDisplay() {
J_HAT.angleTo(layer.shellNormal),
),
);
const nextLayer = shot[index + 1] as ShotLayerGap | undefined;
const trueStatus =
nextLayer?.status === 'wasted' ? 'blocked' : layer.status;
return (
<>
@@ -52,16 +58,16 @@ export function ShotDisplay() {
<Card
style={{
backgroundColor:
layer.status === 'penetration'
trueStatus === 'penetration'
? '#00ff0080'
: layer.status === 'blocked'
: trueStatus === 'blocked'
? '#ff000080'
: '#ffff0080',
border: 'none',
}}
>
<Inset>
{shot.length > 1 && (
{hasMultipleLayers && (
<Text
style={{
width: '100%',
@@ -92,6 +92,7 @@ export function SpacedArmorSceneComponent({
const hasEnhancedArmor = await hasEquipment(110);
const thicknessCoefficient = hasEnhancedArmor ? 1.04 : 1;
const shell = useDuel.getState().antagonist!.shell;
const explosive = isExplosive(shell.type);
const penetration =
resolveNearPenetration(shell.penetration) *
(hasCalibratedShells
@@ -117,18 +118,6 @@ export function SpacedArmorSceneComponent({
0,
);
// console.clear();
// console.log(
// JSON.stringify(
// shot.map((i) => ({
// ...i,
// ...(i.angle ? { angle: radToDeg(i.angle) } : {}),
// })),
// null,
// 2,
// ),
// );
function filterIntersections(intersectionsRaw: Intersection[]) {
const intersectionsAll = intersectionsRaw.filter(
({ object }) => object.userData.type !== undefined,
@@ -183,12 +172,20 @@ export function SpacedArmorSceneComponent({
let loopIndex = 0;
if (layerIndex !== 0 && intersections.length > 0) {
const distance = (
shot.at(-1) as ShotLayerBase
).point.distanceTo(intersections[0].point);
if (explosive)
remainingPenetration -= 0.5 * remainingPenetration * distance;
const wasted = remainingPenetration < 0;
shot.push({
type: null,
distance: (shot.at(-1) as ShotLayerBase).point.distanceTo(
intersections[0].point,
),
status: wasted ? 'wasted' : 'nominal',
distance,
});
if (wasted) return;
}
for (const intersection of intersections) {
@@ -202,11 +199,20 @@ export function SpacedArmorSceneComponent({
if (layerIndex !== 0 && startingIndex === 0) {
const previousIntersection = intersections[layerIndex - 1];
const distance =
intersection.distance - previousIntersection.distance;
if (explosive)
remainingPenetration -=
0.5 * remainingPenetration * distance;
const wasted = remainingPenetration < 0;
shot.push({
type: null,
distance:
intersection.distance - previousIntersection.distance,
status: wasted ? 'wasted' : 'nominal',
distance,
});
if (wasted) return;
}
if (intersection.object.userData.type === ArmorType.External) {