fix bug when a player got the ball while doing a screen to another player

pull/113/head
maxime.batista 1 year ago
parent b6f2a97d8f
commit 5963290f67

@ -7,6 +7,7 @@ import {removeBall, updateComponent} from "./TacticContentDomains"
import {
areInSamePath,
changePlayerBallState,
getComponent,
getOrigin,
getPlayerNextTo,
isNextInPath,
@ -165,11 +166,9 @@ function alreadyHasAnAnteriorActionWith(
const targetIdx = targetOriginPath.indexOf(target.id)
for (let i = targetIdx; i < targetOriginPath.length; i++) {
const phantom = components.find(
(c) => c.id === targetOriginPath[i],
)! as PlayerLike
const component = getComponent(targetOriginPath[i], components)
if (
phantom.actions.find(
component.actions.find(
(a) =>
typeof a.target === "string" &&
moves(a.type) &&
@ -467,9 +466,7 @@ export function spreadNewStateFromOriginStateChange(
continue
}
const actionTarget = content.components.find(
(c) => action.target === c.id,
)! as PlayerLike
const actionTarget: PlayerLike = getComponent(action.target, content.components)
let targetState: BallState = actionTarget.ballState
let deleteAction = false
@ -499,13 +496,16 @@ export function spreadNewStateFromOriginStateChange(
action.type === ActionKind.SCREEN
) {
targetState = BallState.HOLDS_BY_PASS
const screenPhantom = getPlayerNextTo(origin, 1, content.components)!
if (screenPhantom.type === "phantom" && screenPhantom.pos.type === "follows") {
content = removePlayer(screenPhantom, content)
origin = getComponent(origin.id, content.components)
}
}
if (deleteAction) {
content = removeAction(origin, i, content)
origin = content.components.find((c) => c.id === origin.id)! as
| Player
| PlayerPhantom
origin = getComponent(origin.id, content.components)
i-- // step back
} else {
// do not change the action type if it is a shoot action

@ -25,7 +25,6 @@ export function getPlayerNextTo(player: PlayerLike, n: number, components: Tacti
// remove the screen phantom
const result = targetIdx == 0 ? playerOrigin : getComponent<PlayerLike>(pathItems[targetIdx - 1], components)
console.log(result, targetIdx, idx, n)
return result
}
@ -172,7 +171,6 @@ export function removePlayer(
if (pos.type === "follows") {
const playerBefore = getPlayerNextTo(player, -1, content.components)!
const actionIdx = playerBefore.actions.findIndex(a => a.target === pos.attach)
console.log(actionIdx, playerBefore)
content = updateComponent({
...playerBefore,
actions: playerBefore.actions.toSpliced(actionIdx, 1)
@ -180,7 +178,9 @@ export function removePlayer(
}
const origin = getOrigin(player, content.components)
return truncatePlayerPath(origin, player, content)
content = truncatePlayerPath(origin, player, content)
console.log(content)
return content
}
content = clearPlayerPath(player, content)

@ -67,7 +67,8 @@ import { middlePos, Pos, ratioWithinBase } from "../geo/Pos"
import { Action, ActionKind } from "../model/tactic/Action"
import BallAction from "../components/actions/BallAction"
import {
changePlayerBallState, computePhantomPositioning,
changePlayerBallState,
computePhantomPositioning,
getOrigin,
removePlayer,
} from "../editor/PlayerDomains"

Loading…
Cancel
Save