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 { import {
areInSamePath, areInSamePath,
changePlayerBallState, changePlayerBallState,
getComponent,
getOrigin, getOrigin,
getPlayerNextTo, getPlayerNextTo,
isNextInPath, isNextInPath,
@ -165,11 +166,9 @@ function alreadyHasAnAnteriorActionWith(
const targetIdx = targetOriginPath.indexOf(target.id) const targetIdx = targetOriginPath.indexOf(target.id)
for (let i = targetIdx; i < targetOriginPath.length; i++) { for (let i = targetIdx; i < targetOriginPath.length; i++) {
const phantom = components.find( const component = getComponent(targetOriginPath[i], components)
(c) => c.id === targetOriginPath[i],
)! as PlayerLike
if ( if (
phantom.actions.find( component.actions.find(
(a) => (a) =>
typeof a.target === "string" && typeof a.target === "string" &&
moves(a.type) && moves(a.type) &&
@ -467,9 +466,7 @@ export function spreadNewStateFromOriginStateChange(
continue continue
} }
const actionTarget = content.components.find( const actionTarget: PlayerLike = getComponent(action.target, content.components)
(c) => action.target === c.id,
)! as PlayerLike
let targetState: BallState = actionTarget.ballState let targetState: BallState = actionTarget.ballState
let deleteAction = false let deleteAction = false
@ -499,13 +496,16 @@ export function spreadNewStateFromOriginStateChange(
action.type === ActionKind.SCREEN action.type === ActionKind.SCREEN
) { ) {
targetState = BallState.HOLDS_BY_PASS 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) { if (deleteAction) {
content = removeAction(origin, i, content) content = removeAction(origin, i, content)
origin = content.components.find((c) => c.id === origin.id)! as origin = getComponent(origin.id, content.components)
| Player
| PlayerPhantom
i-- // step back i-- // step back
} else { } else {
// do not change the action type if it is a shoot action // 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 // remove the screen phantom
const result = targetIdx == 0 ? playerOrigin : getComponent<PlayerLike>(pathItems[targetIdx - 1], components) const result = targetIdx == 0 ? playerOrigin : getComponent<PlayerLike>(pathItems[targetIdx - 1], components)
console.log(result, targetIdx, idx, n)
return result return result
} }
@ -172,7 +171,6 @@ export function removePlayer(
if (pos.type === "follows") { if (pos.type === "follows") {
const playerBefore = getPlayerNextTo(player, -1, content.components)! const playerBefore = getPlayerNextTo(player, -1, content.components)!
const actionIdx = playerBefore.actions.findIndex(a => a.target === pos.attach) const actionIdx = playerBefore.actions.findIndex(a => a.target === pos.attach)
console.log(actionIdx, playerBefore)
content = updateComponent({ content = updateComponent({
...playerBefore, ...playerBefore,
actions: playerBefore.actions.toSpliced(actionIdx, 1) actions: playerBefore.actions.toSpliced(actionIdx, 1)
@ -180,7 +178,9 @@ export function removePlayer(
} }
const origin = getOrigin(player, content.components) 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) content = clearPlayerPath(player, content)

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

Loading…
Cancel
Save