Esempio n. 1
0
        /// <summary>
        /// Checks whether we should send our packaged player actions to the server yet (we do
        /// so at regular intervals).
        /// </summary>
        void SendInput()
        {
            if (OurChampion != null)
            {
                TimeSinceLastInputSent += GameTime.ElapsedGameTime.TotalSeconds;

                if (TimeSinceLastInputSent >= SEND_INPUTS_TO_SERVER_INTERVAL.TotalSeconds)
                {
                    var package = OurChampion.GetActionPackage();

                    if (package.Count == 0)                       // no actions? send a heartbeat to say that we're connected
                    {
                        package.Enqueue(new PlayerAction(IDGenerator.GenerateID(),
                                                         PlayerActionType.Idle,
                                                         (float)Client.Instance.GetTime().TotalSeconds,
                                                         OurChampion.Champion.Position));
                    }

                    // Send packaged input
                    Client.SendPlayerActionPackage(package);
                    package.Clear();

                    TimeSinceLastInputSent = 0f;
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Package local input as actions to eventually send to the server.
 /// At the same time, we simulate the input locally for client-side prediction.
 /// </summary>
 void HandleInput()
 {
     if (OurChampion != null && OurChampion.Champion.Alive &&
         !WinLoseScreen.Visible)
     {
         InputTypeForAction.ForEach(pair =>
         {
             if (inputManager.IsActionFired(pair.Key))
             {
                 OurChampion.PackageAction(pair.Value, ActionTypeHelper.IsSpell(pair.Value) ? GetTargetWorldPosition() : null);
             }
         });
     }
 }