/// <summary> /// 设置子状态 /// </summary> /// <param name="subState"></param> public void AddSubState(EnumSubState subState) { int offset = (int)subState; if (offset > SubStateBit) { return; } ulong state = 1UL << offset; m_HeroState |= state; }
/// <summary> /// 删除子状态 /// </summary> /// <param name="subState"></param> public void RemoveSubState(EnumSubState subState) { int offset = (int)subState; if (offset > SubStateBit) { return; } ulong state = 1UL << offset; state = ~state; m_HeroState &= state; }
/// <summary> /// 是否包含子状态 /// </summary> /// <param name="subState"></param> /// <returns></returns> public static bool IsHasSubState(ulong state, EnumSubState subState) { state &= 0xFFFFFFFFFFFFFFF; int offset = (int)subState; if (offset > SubStateBit) { return(false); } ulong ss = 1UL << offset; return((state & ss) != 0); }
public void OnExitSubState(EnumSubState subState) { if (m_Property.GetMotionMode() == EnumMotionMode.Dof6ReplaceOverload) { if (subState == EnumSubState.Overload) { SendEvent(ComponentEventName.ResetRotation, new ResetRotation() { Type = MotionType.Dof6 }); m_Property.SetMotionType(MotionType.Dof4); SendEvent(ComponentEventName.ChangeMotionType, null); GameFacade.Instance.SendNotification(NotificationName.Exit6DofMode); } } SendChangeState(); BehaviorManager.Instance.LogFormat(m_Agent, string.Format($"OnExitSubState subState:{subState}")); }
/// <summary> /// Internal logic of the defence. /// 防守逻辑 /// </summary> private void InternalDefence(IState doneState) { var ballHandler = _match.Status.BallHandler; bool dribbleFlag = ballHandler.Status.State is AI.States.DribbleState; double interception = _propCore[PlayerProperty.Interception]; double stealRate = 0d; double holdRate = 0d; IPlayer passFrom = null; ISubState subState = null; EnumSubState subStateVal = EnumSubState.None; if (!dribbleFlag) { subState = ballHandler.Status.SubState; subStateVal = subState.GetSubState(_match.Status.Round); if (subStateVal == EnumSubState.ShortPassAccepting || subStateVal == EnumSubState.LongPassAccepting) { passFrom = ballHandler.Status.PassStatus.PassFrom; } } if (!ballHandler.SkillEnable) { stealRate = 100; holdRate = 0; _status.DefenceStatus.RawSuccRate = (int)Math.Round(holdRate, 0); _status.DefenceStatus.NewSuccRate = (int)Math.Round(stealRate, 0); } else { if (null != passFrom) { double passing = passFrom.PropCore[PlayerProperty.Passing]; stealRate = Math.Pow(interception / passing, 2) * 20 + 10; holdRate = 100 - stealRate; if (holdRate > 0) { holdRate = passFrom.PropCore.GetActionRate(EnumBuffCode.PassSuccRate, holdRate); } } if (stealRate == 0) { double dribble = ballHandler.PropCore[PlayerProperty.Dribble]; //stealRate = Math.Pow(interception / dribble, 2) * 20 + 10; Old stealRate = Math.Pow(interception / dribble, 2) * 40 + 20; holdRate = 100 - stealRate; if (holdRate > 0) { holdRate = ballHandler.PropCore.GetActionRate(EnumBuffCode.DribbleSuccRate, holdRate); } } stealRate = _propCore.GetActionRate(EnumBuffCode.StealSuccRate, stealRate); _status.DefenceStatus.RawSuccRate = (int)Math.Round(holdRate, 0); _status.DefenceStatus.NewSuccRate = (int)Math.Round(stealRate, 0); if (holdRate >= 100 && stealRate < holdRate) { stealRate = 0; } else if (holdRate < 100 && stealRate < 100) { stealRate = (3 * stealRate + 2 * (100 - holdRate)) / 5; } } //_status.DefenceStatus.NewSuccRate = (int)stealRate; if (stealRate >= 100 || stealRate > 0 && _match.RandomPercent() <= stealRate) { if (dribbleFlag) { double turnStealRate = ballHandler.PropCore[(int)EnumBuffCode.TurnStealRate, -1, -1, true]; if (turnStealRate > 0 && _match.RandomPercent() < turnStealRate) { ballHandler.AddForceStateBuff((int)EnumForceState.DefenceState, 2); } else if (_match.RandomPercent() < (_propCore[PlayerProperty.Strength] - ballHandler.PropCore[PlayerProperty.Strength]) * 2) { ballHandler.AddFallDownBuff(4); } else { AddTargetInertia(ballHandler); } } _status.Hasball = true; _match.Football.Kick(_status.Destination, 15, this); // 断球后,球滚动 _match.Football.MoveTo(_match.Football.Current); _status.SetDoneState(doneState, EnumDoneStateFlag.Succ); _status.DefenceStatus.SuccFlag = 1; if (dribbleFlag) { ballHandler.Status.SetDoneState(AI.States.Dribble.BreakThroughState.Instance, EnumDoneStateFlag.Fail); } else { if (null != passFrom) { if (subStateVal == EnumSubState.ShortPassAccepting) { passFrom.Status.SetDoneState(AI.States.Pass.ShortPassState.Instance, EnumDoneStateFlag.Fail); } else { passFrom.Status.SetDoneState(AI.States.Pass.LongPassState.Instance, EnumDoneStateFlag.Fail); } subState.SetSubState(EnumSubState.None, 0); } } } else { AddTargetInertia(this); _status.SetDoneState(doneState, EnumDoneStateFlag.Fail); _status.DefenceStatus.SuccFlag = 0; if (dribbleFlag) { ballHandler.Status.SetDoneState(AI.States.Dribble.BreakThroughState.Instance, EnumDoneStateFlag.Succ); } } }
/// <summary> /// 是否包含子状态 /// </summary> /// <param name="subState"></param> /// <returns></returns> public bool IsHasSubState(EnumSubState subState) { return(IsHasSubState(m_HeroState, subState)); }
public void SetSubState(EnumSubState subState, int roundEnd, EnumAIState hostState = EnumAIState.None) { this._subState = subState; this._roundEnd = roundEnd; this._hostState = hostState; }
public bool IsHasSubState(EnumSubState subState) { return(m_Property.GetCurrentState().IsHasSubState(subState)); }
public void RemoveSubState(EnumSubState subState) { m_Property.GetCurrentState().RemoveSubState(subState); }
public void OnEnterSubState(EnumSubState subState) { m_Property.GetPreviousState().SetState(m_ServerPreviousState); m_Property.SetIsForceRefreshMotionMode(true); if (m_Property.GetMotionMode() == EnumMotionMode.Dof6ReplaceOverload) { if (subState == EnumSubState.Overload) { SendEvent(ComponentEventName.ResetRotation, new ResetRotation() { Type = MotionType.Dof4 }); m_Property.SetMotionType(MotionType.Dof6); SendEvent(ComponentEventName.ChangeMotionType, null); GameFacade.Instance.SendNotification(NotificationName.Enter6DofMode); } } bool isMain = m_Property.IsMain(); switch (subState) { case EnumSubState.Online: break; case EnumSubState.Relive: break; case EnumSubState.Peerless: if (isMain) { GameFacade.Instance.SendNotification(NotificationName.PlayerWeaponToggleEnd); } break; case EnumSubState.Overload: break; case EnumSubState.DeadLeap: break; case EnumSubState.DeadExplosion: break; case EnumSubState.DeadSlide: break; case EnumSubState.DeadCorpse: break; case EnumSubState.BackToanchor: break; case EnumSubState.LeapPrepare: break; case EnumSubState.Leaping: if (isMain) { MineDropItemManager.Instance.DestoryAllDropGameObject(); } /// 关闭碰撞 m_Property.SetSynceColliderEnable(false); break; case EnumSubState.LeapCancel: break; case EnumSubState.LeapArrive: if (isMain) { UIManager.Instance.OpenPanel(UIPanel.HudAreaNamePanel); GameFacade.Instance.SendNotification(NotificationName.ChangeArea); MineDropItemManager.Instance.CheckSyncDropItem(); } /// 开启碰撞 m_Property.SetSynceColliderEnable(true); /// 连续跃迁 (GameFacade.Instance.RetrieveProxy(ProxyName.AutoNavigationProxy) as AutoNavigationProxy)?.CheckNextAutoLeap(); break; default: break; } SendChangeState(); BehaviorManager.Instance.LogFormat(m_Agent, string.Format($"OnEnterSubState subState:{subState}")); }
/// <summary> /// Decides the nex <see cref="IState"/> /// </summary> /// <param name="player">Represents the current <see cref="IPlayer"/>.</param> /// <param name="preview">Represents the preview <see cref="IState"/></param> /// <returns></returns> public override IState QuickDecide(IPlayer player, IState preview) { var match = player.Match; if (player.Status.Hasball == false) { return(OffBallState.Instance); } else { if (player.Status.Holdball == false) { return(ChaceState.Instance); } if (player.Status.NeedRedecide == false) { return(ActionState.Instance); } #region 处理传球来源 int round = player.Match.Status.Round; var subState = player.Status.SubState; EnumSubState subStateVal = subState.GetSubState(round); if (subStateVal == EnumSubState.LongPassAccepting || subStateVal == EnumSubState.ShortPassAccepting) { var passFrom = player.Status.PassStatus.PassFrom; if (null == passFrom) { subState.SetSubState(EnumSubState.None, round); } else { if (subStateVal == EnumSubState.LongPassAccepting) { passFrom.Status.SetDoneState(AI.States.Pass.LongPassState.Instance, SkillEngine.Extern.Enum.EnumDoneStateFlag.Succ); subState.SetSubState(EnumSubState.LongPassAccepted, round + 1); } else if (subStateVal == EnumSubState.ShortPassAccepting) { passFrom.Status.SetDoneState(AI.States.Pass.ShortPassState.Instance, SkillEngine.Extern.Enum.EnumDoneStateFlag.Succ); subState.SetSubState(EnumSubState.None, round); } } } #endregion #region 守门员传球 if (player.Input.AsPosition == Position.Goalkeeper) { return(PassState.Instance); } #endregion #region 验证射门 var shootRegion = (player.Side == Side.Home) ? player.Match.Pitch.AwayShootRegion : player.Match.Pitch.HomeShootRegion; if (shootRegion.IsCoordinateInRegion(player.Current)) { if (subStateVal != EnumSubState.HeadBall) { player.AddFinishingBuff(1); } return(ShootState.Instance); } // while the player is not in the shooting area, can't to shoot if (subStateVal == EnumSubState.HeadBall && player.PropCore.CanHeadShoot(player.Manager.Opponent.Side) || subStateVal != EnumSubState.HeadBall && player.PropCore.CanShoot(player.Manager.Opponent.Side)) { if (match.RandomPercent() < player.PropCore.ShootChooseRate()) { return(ShootState.Instance); } } #endregion if (subStateVal != EnumSubState.HeadBall) { #region 底传中 if (player.Status.IsForceCross) { if (null != player.DecideCrossTarget()) { player.DecideEnd(); return(Pass.LongPassState.Instance); } } #endregion #region 单刀球 if (Decides.Utility.IfSolo(player)) { player.SetTarget(Decides.Utility.GetSoloPosition(player)); return(Dribble.DefaultDribbleState.Instance); } #endregion } #region 验证传球 //region = (player.Side == Side.Home) ? player.Match.Pitch.AwayForcePassRegion : player.Match.Pitch.HomeForcePassRegion; //if (region.IsCoordinateInRegion(player.Current)) //{ // if (RandomHelper.GetPercentage() < 40) // { // return PassState.Instance; // } //} double rawPassRate = 0; if (player.Input.AsPosition == Position.Midfielder || player.Input.AsPosition == Position.Forward) { if (player.PropCore[PlayerProperty.Dribble] - player.PropCore[PlayerProperty.Passing] >= 18) { rawPassRate = 30; } } double passRate = player.PropCore.PassChooseRate(rawPassRate); double dribbleRate = player.PropCore.DribbleChooseRate(); if (dribbleRate >= 100 && passRate < dribbleRate) { passRate = 0; } else if (dribbleRate < 100 && passRate < 100) { passRate = (3 * passRate + 2 * (100 - dribbleRate)) / 5; } if (passRate >= 100 || passRate > 0 && match.RandomPercent() <= passRate) { if (subStateVal == EnumSubState.HeadBall) { if (null != player.DecideShortPassTarget()) { return(Pass.ShortPassState.Instance); } return(DribbleState.Instance); } return(PassState.Instance); } #endregion return(DribbleState.Instance); } }