private static bool JustOverlapping(this UnitEntityData unit, UnitEntityData target)
        {
            UnitMovementAgent agentASP    = unit.View.AgentASP;
            Vector3?          destination = agentASP.GetDestination();

            if (!destination.HasValue)
            {
                return(false);
            }

            float minDistance = agentASP.Corpulence + target.View.AgentASP.Corpulence;

            // the destination is not where the unit is intended to stop at, so we have to step back
            destination = destination.Value - (destination.Value - unit.Position).normalized *
                          (agentASP.IsCharging ? unit.GetAttackApproachRadius(target) : agentASP.ApproachRadius);

            // if the destination is going to overlap with target, forbid this behavior
            if (target.DistanceTo(destination.Value) < minDistance)
            {
                return(true);
            }

            // if the unit doesn't have enough movement to go through the target, forbid it from going through
            if (unit.IsCurrentUnit() && !agentASP.GetIsInForceMode())
            {
                return(CurrentTurn().GetRemainingMovementRange(true) <
                       Math.Min(unit.DistanceTo(target) + minDistance, unit.DistanceTo(destination.Value)));
            }

            return(false);
        }
Пример #2
0
            static bool Prefix(UnitMovementAgent __instance, ref float deltaTime, ref float?__state)
            {
                if (IsInCombat())
                {
                    //                          passing     acting      ending      delaying
                    // not in combat            o           x           x           x
                    // in combat - not current  x           x           x           x
                    // in combat - current      x           o           x           x

                    bool           canMove       = default;
                    bool           isInForceMode = __instance.GetIsInForceMode();
                    UnitEntityView view          = __instance.Unit;

                    if (IsPassing())
                    {
                        canMove = !(view?.EntityData?.IsInCombat ?? false);
                    }
                    else
                    {
                        canMove = (view?.EntityData).IsCurrentUnit() && IsActing() &&
                                  !(view.AnimationManager?.IsPreventingMovement ?? false) &&
                                  !view.IsCommandsPreventMovement && __instance.IsReallyMoving;

                        if (canMove)
                        {
                            CurrentTurn().TickMovement(ref deltaTime, isInForceMode);

                            if (deltaTime <= 0f)
                            {
                                canMove = false;
                            }
                            else if (!isInForceMode)
                            {
                                // disable acceleration effect
                                __state = __instance.GetMinSpeed();
                                __instance.SetMinSpeed(1f);
                                __instance.SetWarmupTime(0f);
                                __instance.SetSlowDownTime(0f);
                            }
                        }
                    }

                    if (!canMove)
                    {
                        if (!isInForceMode)
                        {
                            __instance.Stop();
                        }
                        return(false);
                    }
                }
                return(true);
            }
Пример #3
0
            static bool Prefix(UnitMovementAgent __instance, ref float deltaTime)
            {
                if (IsInCombat())
                {
                    //                          passing     acting      ending      delaying
                    // not in combat            o           x           x           x
                    // in combat - not current  x           x           x           x
                    // in combat - current      x           o           x           x

                    bool           canMove       = default;
                    bool           isInForceMode = __instance.GetIsInForceMode();
                    UnitEntityView view          = __instance.Unit;

                    if (IsPassing())
                    {
                        canMove = !(view?.EntityData?.IsInCombat ?? false);
                    }
                    else
                    {
                        if (canMove = (view?.EntityData).IsCurrentUnit() && IsActing() &&
                                      !(view.AnimationManager?.IsPreventingMovement ?? false) &&
                                      !view.IsCommandsPreventMovement && __instance.IsReallyMoving)
                        {
                            CurrentTurn().TickMovement(ref deltaTime, isInForceMode);
                            canMove = deltaTime > 0f;
                        }
                        else
                        {
                            canMove = false;
                        }
                    }

                    if (!canMove)
                    {
                        if (!isInForceMode)
                        {
                            __instance.Stop();
                        }
                        return(false);
                    }
                }
                return(true);
            }