override public void Update(IM.Number fDeltaTime) { base.Update(fDeltaTime); if (m_player.m_StateMachine.m_curState.m_eState != PlayerState.State.eRequireBall) { if (m_lastState != null) { m_system.SetTransaction(m_lastState); } else { m_system.SetTransaction(Type.eIdle); } } if (GameUtils.HorizonalDistance(m_moveTarget, m_player.position) < new IM.Number(0, 100)) { int iCollideSector = RoadPathManager.Instance.CalcSectorIdx(m_moveTarget); if (iCollideSector == -1) { iCollideSector = 0; } RoadPathManager.Sector targetSector = RoadPathManager.Instance.Bounce(m_player.position.xz, RoadPathManager.Instance.m_Sectors[iCollideSector], m_player.m_favorSectors); RoadPathManager.Instance.AddDrawSector("targetSector", targetSector); m_moveTarget = targetSector.center.x0z; } }
public override void OnSectorCollided(RoadPathManager.Sector colSector) { if (m_player.m_team.m_role == GameMatch.MatchRole.eDefense) { return; } if (!m_enableColliding) { return; } if (m_player.m_team.m_role != GameMatch.MatchRole.eOffense) { return; } bool isFinalTime = m_curMatch.IsFinalTime(new IM.Number(3) - AI.devTime); if (isFinalTime) { return; } bool bCollideOnMember = false; foreach (Player player in colSector.holders) { if (player == m_player) { continue; } if (player.m_team.m_role != GameMatch.MatchRole.eOffense) { continue; } bCollideOnMember = true; } if (!bCollideOnMember) { return; } m_enableColliding = false; m_collideRefreshingTime = IM.Number.zero; RoadPathManager.Sector targetSector = RoadPathManager.Instance.Bounce(m_player.position.xz, colSector, m_player.m_bounceSectors); RoadPathManager.Instance.AddDrawSector("targetSector", targetSector); AIState positioning = m_arStateList[(int)AIState.Type.ePositioning]; positioning.m_moveTarget = targetSector.center.x0z; SetTransaction(positioning); }
void _UpdateSectorHolders(Player player) { GameMatch.MatchRole matchRole = player.m_team.m_role; int sectorColomns = RoadPathManager.Instance.m_AngleList.Count; int sectorRows = RoadPathManager.Instance.m_DistanceList.Count; int iCurPlayerSection = RoadPathManager.Instance.CalcSectorIdx(player.position); if (iCurPlayerSection == -1) { return; } int iCurColomn = iCurPlayerSection % sectorColomns; int iCurRow = iCurPlayerSection / sectorColomns; //Debug.Log("Column: " + iCurColomn + " Row:" + iCurRow); if (matchRole == GameMatch.MatchRole.eOffense) { foreach (Vector2 range in player.m_takenSectorRanges) { int iRangeColomn = iCurColomn + (int)range.x; int iRangeRow = iCurRow + (int)range.y; //colomn invalid, bounds collided if (iRangeColomn >= sectorColomns || iRangeColomn < 0) { continue; } //row invalid, bounds collided if (iRangeRow >= sectorRows || iRangeRow < 0) { continue; } int iNewColIdx = iRangeRow * sectorColomns + iRangeColomn; RoadPathManager.Sector sector = RoadPathManager.Instance.m_Sectors[iNewColIdx]; sector.holders.Add(player); m_takenSectors.Add(iNewColIdx); } } else { RoadPathManager.Sector sector = RoadPathManager.Instance.m_Sectors[iCurPlayerSection]; sector.holders.Add(player); m_takenSectors.Add(iCurPlayerSection); } }
IM.Vector3 GetPositionWithOutBall() { int colomn = RoadPathManager.Instance.m_AngleList.Count; IM.Vector2 dirRim2Player = (m_player.position - m_basket.m_rim.center).normalized.xy; int sectorIdx = 0; int iCol = 0; if (IM.Vector2.Dot(dirRim2Player, IM.Vector2.right) > IM.Number.zero) { iCol = IM.Random.Range(0, (int)m_player.m_favorSectors.range.x / 2); } else { iCol = IM.Random.Range((int)m_player.m_favorSectors.range.x / 2, (int)m_player.m_favorSectors.range.x); } int iRow = (int)m_player.m_favorSectors.start.y + IM.Random.Range(0, (int)m_player.m_favorSectors.range.y); sectorIdx = colomn * iRow + iCol; RoadPathManager.Sector sector = RoadPathManager.Instance.m_Sectors[sectorIdx]; IM.Number dev = m_system.AI.devFavArea; int count = 0; do { IM.Vector3 pos = new IM.Vector3(sector.center.x + IM.Random.Range(-dev, dev), IM.Number.zero, sector.center.y + IM.Random.Range(-dev, dev)); sectorIdx = RoadPathManager.Instance.CalcSectorIdx(pos); } while (sectorIdx == -1 && count++ < 10); if (sectorIdx != -1) { sector = RoadPathManager.Instance.m_Sectors[sectorIdx]; } else { Debug.LogError("AI_Positioning, sector(-1). Name:" + m_player.m_name + " SectorIdx:" + sector.idx + " Center:" + sector.center + " Dev:" + dev); } RoadPathManager.Instance.AddDrawSector(m_player.m_id + "_ToSector", sector); return(sector.center.x0z); }
public override void Update(IM.Number fDeltaTime) { base.Update(fDeltaTime); //状态切换 if (m_player.m_team.m_role != GameMatch.MatchRole.eOffense) { m_system.SetTransaction(AIState.Type.eDefense); return; } //到点 if (GameUtils.HorizonalDistance(m_moveTarget, m_player.position) < new IM.Number(0, 100)) { arriveFirstTarget = true; OnTick(); if (!m_player.m_bWithBall) { RoadPathManager.Sector targetSector = null; int iCollideSector = RoadPathManager.Instance.CalcSectorIdx(m_moveTarget); if (iCollideSector == -1) { targetSector = RoadPathManager.Instance.m_Sectors[0]; } else { targetSector = RoadPathManager.Instance.Bounce(m_player.position.xz, RoadPathManager.Instance.m_Sectors[iCollideSector], m_player.m_bounceSectors); } IM.Number dev = m_system.AI.devFavArea; int count = 0; int idx = -1; do { IM.Vector3 pos = targetSector.center.x0z + new IM.Vector3(IM.Random.Range(-dev, dev), IM.Number.zero, IM.Random.Range(-dev, dev)); idx = RoadPathManager.Instance.CalcSectorIdx(pos); } while (idx == -1 && count++ < 10); if (idx != -1) { targetSector = RoadPathManager.Instance.m_Sectors[idx]; } else { Debug.LogError("AI_Positioning, sector(-1). Name:" + m_player.m_name + " SectorIdx:" + targetSector.idx + " Center:" + targetSector.center + " Dev:" + dev); } RoadPathManager.Instance.AddDrawSector("targetSector", targetSector); m_moveTarget = targetSector.center.x0z; RoadPathManager.Instance.AddDrawSector(m_player.m_id + "_ToSector", targetSector); arriveFirstTarget = false; } } //卡死容错,静止超过一定时间后,强制重新决策 if (m_match.m_stateMachine.m_curState.m_eState == MatchState.State.ePlaying) { if (m_player.m_StateMachine.m_curState.m_eState == PlayerState.State.eRun || m_player.m_StateMachine.m_curState.m_eState == PlayerState.State.eRush || m_player.m_StateMachine.m_curState.m_eState == PlayerState.State.eStand) { IM.Vector3 curPosition = m_player.position; if (IM.Math.Abs(lastPosition.x - curPosition.x) < new IM.Number(0, 100) && IM.Math.Abs(lastPosition.z - lastPosition.z) < new IM.Number(0, 100)) { stillTime += fDeltaTime; if (stillTime > MAX_STILL_TIME) { //Debug.Log("AI_Positioning, " + m_player.m_name + " still time larger than " + MAX_STILL_TIME + " seconds"); //arriveFirstTarget = true; //OnTick(); m_system.SetTransaction(AIState.Type.ePositioning, new IM.Number(100), true); } } else { stillTime = IM.Number.zero; } } else { stillTime = IM.Number.zero; } } else { stillTime = IM.Number.zero; } lastPosition = m_player.position; if (m_player.m_bWithBall != lastWithBall) { arriveFirstTarget = true; } lastWithBall = m_player.m_bWithBall; }