Esempio n. 1
0
    void Update()
    {
        //The player must have a positive amount of stamina and not already be attacking to perform a new attack
        AnimatorStateInfo StateInfo = AnimationController.GetCurrentAnimatorStateInfo(0);
        bool CurrentlyAttacking     = StateInfo.IsName("Attack 1") || StateInfo.IsName("Attack 2");
        bool CurrentlyRolling       = StateInfo.IsName("Rolling");
        //They must also be touching the ground
        bool CanAttack = Resources.CurrentStamina >= 1 && !CurrentlyAttacking && Controller.TouchingGround() && !CurrentlyRolling;

        if (Input.GetMouseButtonDown(1) && CanAttack)
        {
            //Normal Attacks take 20 Stamina, and delay regen by 0.5 seconds
            Resources.CurrentStamina   -= 20;
            Resources.StaminaRegenDelay = 0.5f;

            //Perform an attack during the first attacks recovery phase will perform the 2nd attack in the combo
            if (StateInfo.IsName("Attack 1 Recover"))
            {
                AnimationController.SetTrigger("Attack 2");
            }
            else
            {
                AnimationController.SetTrigger("Attack 1");
            }

            //Tell the game server where our attack landed
            if (ConnectionManager.Instance.IsConnected)
            {
                PlayerManagementPacketSender.SendPlayerAttack(AttackBox.transform.position, AttackBox.transform.localScale, AttackBox.transform.rotation);
            }
        }
    }
Esempio n. 2
0
    private void Update()
    {
        //Tell the animation controller how much distance the player has travelled since the last frame
        float FrameDistance = Vector3.Distance(transform.position, PreviousFramePosition);

        PreviousFramePosition = transform.position;
        AnimationController.SetFloat("Movement", FrameDistance);


        //Count down the interval timer
        NextUpdate -= Time.deltaTime;

        //Wait until the timer hits zero
        if (NextUpdate <= 0.0f)
        {
            //reset the timer
            NextUpdate = UpdateInterval;
            //If our current position is different to what was last sent to the server, when we need to update them
            if (transform.position != PreviousUpdatePosition)
            {
                //Before we update, remember what position was sent to the server
                PreviousUpdatePosition = transform.position;
                PlayerManagementPacketSender.SendPlayerUpdate(transform.position, transform.rotation);
            }
        }
    }
Esempio n. 3
0
    private void Update()
    {
        //Execute the correct controller function depending on what mode is currently active
        switch (ControllerState)
        {
        case (PlayerControllerState.FirstPersonMode):
            FirstPersonMode();
            break;

        case (PlayerControllerState.ThirdPersonMode):
            ThirdPersonMode();
            break;
        }

        //Keep the server up to date regarding where our character is positioned in the game world
        NextPositionUpdate -= Time.deltaTime;
        if (NextPositionUpdate <= 0.0f)
        {
            //Reset the timer every 0.25 seconds
            NextPositionUpdate = PositionUpdateInterval;
            //If our position or rotation has changed since the last time we told the server then we need to tell it again
            if (transform.position != PreviousUpdatePosition || transform.rotation != PreviousUpdateRotation)
            {
                //Tell the server our new position value
                if (ConnectionManager.Instance.IsConnected)
                {
                    PlayerManagementPacketSender.SendPlayerUpdate(transform.position, transform.rotation);
                }
                //Now remember what we last told the server our values where
                PreviousUpdatePosition = transform.position;
                PreviousUpdateRotation = transform.rotation;
            }
        }
    }
Esempio n. 4
0
 //Adds any clients into the game world who are waiting for it
 public static void AddNewClients(Simulation World)
 {
     foreach (ClientConnection NewClient in ClientSubsetFinder.GetClientsReadyToEnter())
     {
         NewClient.Character.InitializeBody(World, NewClient.Character.Position);
         NewClient.Character.WaitingToEnter = false;
         NewClient.Character.InGame         = true;
         PlayerManagementPacketSender.SendPlayerBegin(NewClient.ClientID);
         foreach (ClientConnection OtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(NewClient.ClientID))
         {
             PlayerManagementPacketSender.SendAddRemotePlayer(OtherClient.ClientID, NewClient.Character);
         }
     }
 }
Esempio n. 5
0
        public static void HandlePlayerRotationUpdate(int ClientID, ref NetworkPacket Packet)
        {
            Quaternion       Rotation = Packet.ReadQuaternion();
            ClientConnection Client   = ConnectionManager.GetClient(ClientID);

            if (Client != null)
            {
                Client.Character.Rotation    = Rotation;
                Client.Character.NewRotation = true;
                foreach (ClientConnection OtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(ClientID))
                {
                    PlayerManagementPacketSender.SendPlayerRotationUpdate(OtherClient.ClientID, Client.Character);
                }
            }
        }
Esempio n. 6
0
 //Cleans up any dead connections, removing their character from the world, and telling other clients to do the same on their end
 public static void CleanDeadClients(Simulation World)
 {
     foreach (ClientConnection DeadClient in ClientSubsetFinder.GetDeadClients())
     {
         //Backup / Remove from World and alert other clients about any ingame dead clients
         if (DeadClient.Character.InGame)
         {
             CharactersDatabase.SaveCharacterData(DeadClient.Character);
             DeadClient.Character.RemoveBody(World);
             foreach (ClientConnection LivingClient in ClientSubsetFinder.GetInGameLivingClientsExceptFor(DeadClient.ClientID))
             {
                 PlayerManagementPacketSender.SendRemoveRemotePlayer(LivingClient.ClientID, DeadClient.Character.Name, DeadClient.Character.IsAlive);
             }
         }
         ActiveConnections.Remove(DeadClient.ClientID);
     }
 }
Esempio n. 7
0
        public static void HandlePlayAnimationAlert(int ClientID, ref NetworkPacket Packet)
        {
            CommunicationLog.LogIn(ClientID + " Play Animation Alert");
            string           AnimationName = Packet.ReadString();
            ClientConnection Client        = ConnectionManager.GetClient(ClientID);

            if (Client == null)
            {
                MessageLog.Print("ERROR: Client not found, unable to handle play animation alert.");
                return;
            }
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(ClientID);

            foreach (ClientConnection OtherClient in OtherClients)
            {
                PlayerManagementPacketSender.SendPlayAnimationAlert(OtherClient.ClientID, Client.Character.Name, AnimationName);
            }
        }
Esempio n. 8
0
        //Tries using the command arguments for performing a player kick
        private void TryKickPlayer(string[] Input)
        {
            //Get the characters name
            string CharacterName = Input[1];

            //Make sure the character exists
            if (!CharactersDatabase.DoesCharacterExist(CharacterName))
            {
                MessageLog.Print("That character doesnt exist, cant kick them.");
                return;
            }

            //Get the client who this character belongs to
            ClientConnection Client = ClientSubsetFinder.GetClientUsingCharacter(CharacterName);

            //If the client couldnt be found then the character isnt logged in currently
            if (Client == null)
            {
                MessageLog.Print("That character is not in the game right now, cant kick them.");
                return;
            }

            //Show that the player is being kicked
            MessageLog.Print("Kicking " + CharacterName + " from the game...");

            //Tell the client that they have been kicked from the game and mark them to be cleaned up from the game
            SystemPacketSender.SendKickedFromServer(Client.ClientID);
            Client.ConnectionDead = true;

            //Tell everyone else to remove the client from their games
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(Client.ClientID);

            foreach (ClientConnection OtherClient in OtherClients)
            {
                PlayerManagementPacketSender.SendRemoveRemotePlayer(OtherClient.ClientID, Client.Character.Name, Client.Character.IsAlive);
            }
        }
Esempio n. 9
0
 //When we close the game send the server our disconnect notice
 private void OnApplicationQuit()
 {
     PlayerManagementPacketSender.SendDisconnectNotice();
 }
Esempio n. 10
0
 void Awake()
 {
     Instance = this;
 }