Ejemplo n.º 1
0
    protected IEnumerator MoveTo_CO(MoveToParams _params)
    {
        Vector2 start = contentOffset;
        Vector2 dest  = _params.dest;
        float   timer = 0.0f;

        if (_params.duration != 0.0f)
        {
            while (timer <= _params.duration)
            {
                float ratio = timer / _params.duration;
                contentOffset   = Vector2.Lerp(start, dest, ratio);
                contentOffset.x = Mathf.Clamp(contentOffset.x, minX, maxX);
                contentOffset.y = Mathf.Clamp(contentOffset.y, minY, maxY);
                SetOffset(contentOffset);

                yield return(0);

                timer += Time.deltaTime;
            }
        }

        contentOffset   = dest;
        contentOffset.x = Mathf.Clamp(contentOffset.x, minX, maxX);
        contentOffset.y = Mathf.Clamp(contentOffset.y, minY, maxY);
        SetOffset(contentOffset);
    }
Ejemplo n.º 2
0
        public void OnMoveComplete_MoveTo2(WeenieError status)
        {
            if (DebugPlayerMoveToStatePhysics)
            {
                Console.WriteLine($"{Name}.OnMoveComplete_MoveTo({status})");
            }

            IsPlayerMovingTo2 = false;

            if (MoveToParams.Callback == null)
            {
                // nothing to do -- we are done here
                MoveToParams = null;
                return;
            }

            var success = status == WeenieError.None;

            if (success)
            {
                MoveToParams.Callback(true);
                MoveToParams = null;
            }

            // if action cancelled, check again when player is stationary
            // through Player_Tick -> HandleMoveToCallback
        }
Ejemplo n.º 3
0
 void MoveTo(MoveToParams moveParams)
 {
     m_moveDirection = Vector3.ClampMagnitude(moveParams.direction, 1);
     if (moveParams.isRun)
     {
         m_moveDirection *= m_speedBoost;
     }
 }
Ejemplo n.º 4
0
        public void HandleMoveToCallback()
        {
            var isFacing = IsFacing(MoveToParams.Target);

            var withinUseRadius = MoveToParams.UseRadius == null || CurrentLandblock.WithinUseRadius(this, MoveToParams.Target.Guid, out _, MoveToParams.UseRadius);

            var success = isFacing && withinUseRadius;

            MoveToParams.Callback(success);

            MoveToParams = null;
        }
Ejemplo n.º 5
0
        public void CreateTurnToChain2(WorldObject target, Action <bool> callback, float?useRadius = null, bool stopCompletely = false, bool alwaysTurn = false)
        {
            if (IsPlayerMovingTo2)
            {
                StopExistingMoveToChains2();
            }

            if (MoveToParams != null)
            {
                CheckMoveToParams();
            }

            var rotateTarget = target.Wielder ?? target;

            if (rotateTarget.Location == null)
            {
                log.Error($"{Name}.TurnTo({target.Name}): target.Location is null");
                callback(false);
                return;
            }

            if (DebugPlayerMoveToStatePhysics)
            {
                Console.WriteLine("*** CreateTurnToChain ***");
            }

            // send command to client
            TurnToObject(rotateTarget, stopCompletely);

            // start on server
            // forward this to PhysicsObj.MoveManager.MoveToManager
            var mvp = GetTurnToParams(stopCompletely);

            if (!PhysicsObj.IsMovingOrAnimating)
            {
                //PhysicsObj.UpdateTime = PhysicsTimer.CurrentTime - PhysicsGlobals.MinQuantum;
                PhysicsObj.UpdateTime = PhysicsTimer.CurrentTime;
            }

            IsPlayerMovingTo2 = true;

            MoveToParams = new MoveToParams(callback, target, useRadius);

            PhysicsObj.MovementManager.MoveToManager.AlwaysTurn = alwaysTurn;

            PhysicsObj.TurnToObject(rotateTarget.PhysicsObj, mvp);
            //PhysicsObj.LastMoveWasAutonomous = false;

            PhysicsObj.update_object();

            PhysicsObj.MovementManager.MoveToManager.AlwaysTurn = false;
        }
Ejemplo n.º 6
0
        public void CheckMoveToParams()
        {
            // because of the additional gap, it is now possible to queue up actions
            // we don't want to queue up multiple actions, but we still need to process the queue,
            // to prevent busy state on client

            // fail pending action
            if (MoveToParams.Callback != null)
            {
                MoveToParams.Callback(false);
            }

            MoveToParams = null;
        }
Ejemplo n.º 7
0
        public static void Execute()
        {
            EnemyBuildingsHelper.UpdateTowersInfo();;
            Tick.Move.SkillToLearn = SkillsHelper.GetSkillToLearn();

            if (Tick.Self.IsMaster)
            {
                var messages = new[]
                {
                    new Message(LaneType.Top, null, new byte[0]),
                    new Message(LaneType.Middle, null, new byte[0]),
                    new Message(LaneType.Middle, null, new byte[0]),
                    new Message(LaneType.Bottom, null, new byte[0]),
                };
                Tick.Move.Messages   = messages;
                GameState.MyLaneType = LaneType.Middle;
            }
            else
            {
                //Первые 10 тиков ждем команду мастера, определяемся с лайном
                if (Tick.World.TickIndex < 10)
                {
                    if (Tick.Self.Messages != null && Tick.Self.Messages.Length > 0)
                    {
                        var message = Tick.Self.Messages.Last();
                        GameState.MyLaneType = message.Lane;
                    }
                    return;
                }

                if (GameState.MyLaneType == null)
                {
                    GameState.MyLaneType = LaneType.Middle;
                }
            }

            //DebugHelper.ConsoleWriteLite($"XP {Tick.Self.Xp} Level {Tick.Self.Level} Skills {string.Join(", ", Tick.Self.Skills)}");

            var pushPower = PushPowerHelper.GetPushPower();

            //var arrow = pushPower.FrienlyPower >= pushPower.EnemyPower ? "-->" : "<--";
            //DebugHelper.ConsoleWriteLite($"{pushPower.FrienlyPower.ToString("N3")} / {pushPower.EnemyPower.ToString("N3")} {arrow}");

            var evideableProjectiles = ProjectilesHelper.GetEvideableProjectiles();

            if (evideableProjectiles.Any())
            {
                //TODO: evide frostbolt first?
                var firstEvideableProjectile = evideableProjectiles.First();
                var evideVector = firstEvideableProjectile.EvadeVector;
                evideVector.Normalize();
                evideVector = 5 * evideVector;

                var evdePoint    = new Point2D(Tick.Self.X, Tick.Self.Y) + evideVector;
                var moveToParams = new MoveToParams()
                {
                    TargetPoint = evdePoint,
                    //LookAtPoint = new Point2D(0, Tick.Game.MapSize)
                };
                MoveHelper.MoveTo(moveToParams);
                return;
            }


            var target = GetOptimalTargetToAtack(Tick.Self.CastRange);

            if (pushPower.FrienlyPower >= pushPower.EnemyPower)
            {
                if (target != null)
                {
                    AtackTarget(target);
                    if (target.Faction != Faction.Neutral && target.Faction != Faction.Other &&
                        Tick.Self.GetDistanceTo(target) > Tick.Self.CastRange * 0.9)
                    {
                        MoveHelper.MoveTo(new MoveToParams()
                        {
                            TargetPoint = new Point2D(target.X, target.Y),
                            //TargetPoint = new Point2D(Tick.Game.MapSize - PathFindingHelper.gridStep, 0),
                            LookAtPoint = new Point2D(target.X, target.Y),
                        });
                    }
                }
                else
                {
                    var enemyBasePoint = new Point2D(Tick.Game.MapSize - PathFindingHelper.gridStep, 0);
                    var moveToParams   = new MoveToParams()
                    {
                        TargetPoint = enemyBasePoint,
                        //LookAtPoint = new Point2D(0, Tick.Game.MapSize)
                    };
                    MoveHelper.MoveTo(moveToParams);
                }
            }
            else
            {
                if (target == null)
                {
                    //Некого атаковать, но будем смотреть на ближайшего врага
                    target = GetOptimalTargetToAtack(Tick.Self.CastRange * 1.5);
                }
                else
                {
                    AtackTarget(target);
                }

                var moveToParams = new MoveToParams()
                {
                    TargetPoint = new Point2D(0, Tick.Game.MapSize - PathFindingHelper.gridStep),
                    LookAtPoint = target != null ? new Point2D(target.X, target.Y) : null
                };
                MoveHelper.MoveTo(moveToParams);
            }
        }
Ejemplo n.º 8
0
    void Update()
    {
        if (Mathf.Approximately(Time.timeScale, 0.0f))
        {
            return;
        }

        //Movement
        var          movement     = Vector3.ClampMagnitude(new Vector3(CrossPlatformInputManager.GetAxisRaw("Horizontal"), 0.0f, CrossPlatformInputManager.GetAxisRaw("Vertical")), 1.0f);
        MoveToParams moveToParams = new MoveToParams(movement, CrossPlatformInputManager.GetButton("Run"));

        playerPawn.BroadcastMessage("MoveTo", moveToParams, SendMessageOptions.DontRequireReceiver);//TODO: switch to new message system ?


        //Targeting
        Vector3?      lookToDirection   = null;
        ShootToParams shootToParameters = null;

        var joysticDir = new Vector3(CrossPlatformInputManager.GetAxisRaw("RightJoystickX"), 0.0f, CrossPlatformInputManager.GetAxisRaw("RightJoystickY"));

        if (joysticDir.magnitude > 0.01)
        {
            lookToDirection = joysticDir;
        }

        var camera         = GetComponent <Camera>();
        var mouseScreenPos = CrossPlatformInputManager.mousePosition;


        var weaponGroups = weaponsController.Weapons.GroupBy(x => x.socketType).ToDictionary(x => x.Key);

        //secondary weapon selection
        var direction = (int)Mathf.Clamp(CrossPlatformInputManager.GetAxisRaw("SwitchWeapon"), -1, 1);

        if (direction != 0)
        {
            selectedSecondaryGroupIndex++;
        }

        var secondaryGroups = weaponGroups.Where(x => !primaryGroupNames.Contains(x.Key)).Select(x => x.Value).ToArray();

        if (secondaryGroups.Length > 0)
        {
            selectedSecondaryGroupIndex %= secondaryGroups.Length;
        }


        if (Physics.Raycast(camera.ScreenPointToRay(mouseScreenPos), out var hitInfo))
        {
            lookToDirection = (hitInfo.point - playerPawn.transform.position).normalized;

            var target = (hitInfo.collider.tag == "Enemy") ? hitInfo.collider.transform : null;
            shootToParameters = new ShootToParams(hitInfo.point, target, weaponsController); //TODO: think about sending weaponsController

            //TODO: move some grouping functionality into socket/controller?
            bool Shoot(IGrouping <string, WeaponSocket> weaponGroup) => weaponGroup.SelectMany(x => x.weapon.GetComponentsInChildren <IShootable>()).Any(x => x.ShootTo(shootToParameters));

            //Right now weapon is subdivided by groups(setted by socket types), secondary group is selectable
            if (CrossPlatformInputManager.GetAxisRaw("Fire1") > 0.5f && weaponGroups.TryGetValue(mainGroupName, out var mainGroup))
            {
                Shoot(mainGroup);
            }
            if (CrossPlatformInputManager.GetButtonDown("Fire2") && weaponGroups.TryGetValue(alternateGroupName, out var alternateGroup))
            {
                Shoot(alternateGroup);
            }
            if (CrossPlatformInputManager.GetAxisRaw("Fire3") > 0.5f && secondaryGroups.Length > 0)
            {
                Shoot(secondaryGroups[selectedSecondaryGroupIndex]);
            }
        }

        foreach (var weaponSocket in weaponsController.Weapons)
        {
            if (lookToDirection?.magnitude > 0.01)
            {
                weaponSocket.weapon.BroadcastMessage("LookTo", lookToDirection.Value, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
Ejemplo n.º 9
0
    protected IEnumerator MoveTo_CO( MoveToParams _params )
    {
        Vector2 start = contentOffset;
        Vector2 dest = _params.dest;
        float timer = 0.0f;
        if ( _params.duration != 0.0f  ) {
            while ( timer <= _params.duration ) {
                float ratio = timer/_params.duration;
                contentOffset = Vector2.Lerp ( start, dest, ratio );
                contentOffset.x = Mathf.Clamp ( contentOffset.x, minX, maxX );
                contentOffset.y = Mathf.Clamp ( contentOffset.y, minY, maxY );
                SetOffset(contentOffset);

                yield return 0;
                timer += Time.deltaTime;
            }
        }

        contentOffset = dest;
        contentOffset.x = Mathf.Clamp ( contentOffset.x, minX, maxX );
        contentOffset.y = Mathf.Clamp ( contentOffset.y, minY, maxY );
        SetOffset(contentOffset);
    }
Ejemplo n.º 10
0
        public void CreateMoveToChain2(WorldObject target, Action <bool> callback, float?useRadius = null, bool rotate = true)
        {
            if (IsPlayerMovingTo2)
            {
                StopExistingMoveToChains2();
            }

            if (MoveToParams != null)
            {
                CheckMoveToParams();
            }

            if (target.Location == null)
            {
                log.Error($"{Name}.MoveTo({target.Name}): target.Location is null");
                callback(false);
                return;
            }

            if (useRadius == null)
            {
                useRadius = target.UseRadius ?? 0.6f;
            }

            var withinUseRadius = CurrentLandblock.WithinUseRadius(this, target.Guid, out var targetValid, useRadius);

            if (withinUseRadius)
            {
                if (rotate)
                {
                    CreateTurnToChain2(target, callback, useRadius);
                }
                else
                {
                    callback(true);
                }

                return;
            }

            // send command to client
            MoveToObject(target);

            // start on server
            // forward this to PhysicsObj.MoveManager.MoveToManager
            var mvp = GetMoveToParams(target, useRadius);

            if (!PhysicsObj.IsMovingOrAnimating)
            {
                //PhysicsObj.UpdateTime = PhysicsTimer.CurrentTime - PhysicsGlobals.MinQuantum;
                PhysicsObj.UpdateTime = PhysicsTimer.CurrentTime;
            }

            IsPlayerMovingTo2 = true;

            MoveToParams = new MoveToParams(callback, target, useRadius);

            PhysicsObj.MoveToObject(target.PhysicsObj, mvp);
            //PhysicsObj.LastMoveWasAutonomous = false;

            PhysicsObj.update_object();
        }