public void PlantBomb(long serverPlayerID, float cellX, float cellY, long bombLeft)
    {
        GameObject characterObject = GameObject.Find("" + serverPlayerID);

        // If the player ID is me, then i update my own prefab bombleft

        if (characterObject)
        {
            CharacterAnimController playerController = characterObject.GetComponent <CharacterAnimController>();
            playerController.PlantBomb(cellX, cellY);

            if (serverPlayerID == PlayerID)
            {
                GameObject hud = GameObject.Find("UnityHUDPrefab");
                if (hud)
                {
                    HUD hudScript = hud.GetComponent <HUD>();
                    hudScript.SetBombLeft(playerController.BombLimit);
                }

                // Play Sound
                SoundManager soundManager = GameObject.Find("SoundManager").GetComponent <SoundManager>();
                soundManager.PlayPlantBombSound(new Vector3(ZooMap.GetHorizontalPos(cellX), ZooMap.GetVerticalPos(cellY), 0));
            }
        }
    }
Example #2
0
    void Awake()
    {
        animCont = GetComponent<CharacterAnimController>();
        rb = GetComponent<Rigidbody>();
        capsule = GetComponent<CapsuleCollider>();

        capsuleHeightOrig = capsule.height;
        capsuleCenterOrig = capsule.center;
        groundDist = groundDistance_g;
    }
Example #3
0
 public void Attack()
 {
     if (_currentWeapon.WeaponType != defaultWeapon.WeaponType)
     {
         CharacterAnimController.AttackPalkoi(animator);
     }
     else
     {
         CharacterAnimController.AttackHand(animator);
     }
 }
Example #4
0
    public void SetPlayerID(long serverPlayerID)
    {
        playerID = serverPlayerID;

        GameObject playerObj = GameObject.Find("" + playerID);

        if (playerObj)
        {
            playerController = playerObj.GetComponent <CharacterAnimController>();
        }
    }
Example #5
0
    private void SetWeapon(MeleeWeapon weapon)
    {
        Destroy(_currentWeapon.gameObject);
        _currentWeapon = weapon;
        _currentWeapon.transform.position = weaponPlaceTransform.position;
        _currentWeapon.transform.rotation = weaponPlaceTransform.rotation;
        _currentWeapon.transform.SetParent(weaponPlaceTransform);

        GameManager.Instance.FreeWeapons.Remove(weapon);
        CharacterAnimController.MeleeOneHandedWeapon(animator, true);
        _currentWeaponCollider = _currentWeapon.gameObject.GetComponent <Collider>();
    }
Example #6
0
 private void Walk()
 {
     _navAgent.SetDestination(_target.position);
     if (Mathf.Approximately(_navAgent.velocity.magnitude, 0f))
     {
         CharacterAnimController.Walk(_animator, false);
     }
     else
     {
         CharacterAnimController.Walk(_animator, true);
         float forwardSpeed = _navAgent.velocity.magnitude;
         CharacterAnimController.SpeedWalk(_animator, forwardSpeed);
     }
 }
 private void EndConversation(
     uint playerId,
     CharacterAnimController controller,
     CharacterDialogueTree tree)
 {
     QSBPlayerManager.GetPlayer(playerId).CurrentDialogueID = -1;
     controller.SetValue("_inConversation", false);
     controller.SetValue("_playerInHeadZone", false);
     if (controller.GetValue <bool>("_hasTalkAnimation"))
     {
         controller.GetValue <Animator>("_animator").SetTrigger("Idle");
     }
     tree.GetInteractVolume().EnableInteraction();
 }
Example #8
0
 private void CreateWeapon(MeleeWeapon weaponPrefab)
 {
     _currentWeapon = Instantiate(weaponPrefab, weaponPlaceTransform.position, weaponPlaceTransform.rotation);
     _currentWeapon.transform.SetParent(weaponPlaceTransform); // по другому привязать не получается
     _currentWeaponCollider = _currentWeapon.gameObject.GetComponent <Collider>();
     if (_currentWeapon.WeaponType == defaultWeapon.WeaponType)
     {
         CharacterAnimController.MeleeOneHandedWeapon(animator, false);
     }
     else
     {
         CharacterAnimController.MeleeOneHandedWeapon(animator, true);
     }
 }
    public void RespawnPlayer(long serverPlayerID, float cellX, float cellY)
    {
        GameObject characterObject = GameObject.Find("" + serverPlayerID);

        if (characterObject)
        {
            CharacterAnimController playerController = characterObject.GetComponent <CharacterAnimController>();

            SoundManager soundManager = GameObject.Find("SoundManager").GetComponent <SoundManager>();
            soundManager.PlayDeathSound(playerController.CharacterIcon, characterObject.transform.position);

            playerController.RespawnPlayer(cellX, cellY);
        }
    }
Example #10
0
    private void Update()
    {
        if (!IsInTeam && _commanderTransform)
        {
            if (Vector3.Distance(_commanderTransform.position, transform.position) < findRadius)
            {
                IsInTeam = true;
            }
        }
        else
        {
            if (isCommander)
            {
                if (Input.GetMouseButton(0))
                {
                    _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(_ray, out _hit, 100f))
                    {
                        _navAgent.SetDestination(_hit.point);
                    }
                }
            }
            else
            {
                if (_commanderTransform)
                {
                    _navAgent.SetDestination(_commanderTransform.position);
                }
            }
            if (Mathf.Approximately(_navAgent.velocity.magnitude, 0f))
            {
                CharacterAnimController.Walk(_animator, false);
            }
            else
            {
                CharacterAnimController.Walk(_animator, true);
                float forwardSpeed = _navAgent.velocity.magnitude;
                CharacterAnimController.SpeedWalk(_animator, forwardSpeed);
            }
        }

        foreach (EnemyUnit enemyUnit in GameManager.Instance.EnemyUnits)
        {
            if (Vector3.Distance(enemyUnit.transform.position, transform.position) < attackRange)
            {
                transform.LookAt(enemyUnit.transform.position);
                weaponPlace.Attack();
            }
        }
    }
 private void StartConversation(
     uint playerId,
     int characterId,
     CharacterAnimController controller,
     CharacterDialogueTree tree)
 {
     QSBPlayerManager.GetPlayer(playerId).CurrentDialogueID = characterId;
     controller.SetValue("_inConversation", true);
     controller.SetValue("_playerInHeadZone", true);
     if (controller.GetValue <bool>("_hasTalkAnimation"))
     {
         controller.GetValue <Animator>("_animator").SetTrigger("Talking");
     }
     tree.GetInteractVolume().DisableInteraction();
 }
    public void ExplodeBomb(long serverPlayerID, float cellX, float cellY, long explodeRange)
    {
        GameObject characterObject = GameObject.Find("" + serverPlayerID);

        if (characterObject)
        {
            CharacterAnimController playerController = characterObject.GetComponent <CharacterAnimController>();
            playerController.ExplodeBomb(cellX, cellY, explodeRange);

            // Update HUD
            if (serverPlayerID == PlayerID)
            {
                playerController.UpdateBombLeft();
            }
        }
    }
Example #13
0
 private void Update()
 {
     if (Input.GetMouseButton(0))
     {
         _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(_ray, out _hit, 100f))
         {
             navAgent.speed = 5;
             navAgent.SetDestination(_hit.point);
             navAgent.speed = moveSpeed;
         }
     }
     if (Mathf.Approximately(navAgent.velocity.magnitude, 0f))
     {
         CharacterAnimController.Walk(animator, false);
     }
     else
     {
         CharacterAnimController.Walk(animator, true);
         float forwardSpeed = navAgent.velocity.magnitude;
         CharacterAnimController.SpeedWalk(animator, forwardSpeed);
     }
 }
Example #14
0
    public void SetPlayerID(long serverPlayerID)
    {
        playerID = serverPlayerID;

        GameObject playerObj = GameObject.Find(""+playerID);
        if(playerObj)
        {
            playerController = playerObj.GetComponent<CharacterAnimController>();
        }
    }
        public static bool AnimatorIKReplacement(
            CharacterAnimController __instance)
        {
            if (!QSBWorldSync.AllObjectsReady || ConversationManager.Instance == null)
            {
                return(true);
            }

            var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(__instance._dialogueTree);
            var player   = QSBPlayerManager.GetPlayer(playerId);

            if (__instance.playerTrackingZone == null)
            {
                return(true);
            }

            var qsbObj = __instance.playerTrackingZone.GetWorldObject <QSBCharacterTrigger>();            // OPTIMIZE : maybe cache this somewhere... or assess how slow this is

            PlayerInfo playerToUse = null;

            if (__instance._inConversation)
            {
                if (playerId == uint.MaxValue)
                {
                    DebugLog.ToConsole($"Error - {__instance.name} is in conversation with a null player! Defaulting to active camera.", MessageType.Error);
                    playerToUse = QSBPlayerManager.LocalPlayer;
                }
                else
                {
                    playerToUse = player.CameraBody == null
                                                ? QSBPlayerManager.LocalPlayer
                                                : player;
                }
            }
            else if (!__instance.lookOnlyWhenTalking && qsbObj.Occupants.Count != 0)             // IDEA : maybe this would be more fun if characters looked between players at random times? :P
            {
                playerToUse = QSBPlayerManager.GetClosestPlayerToWorldPoint(qsbObj.Occupants, __instance.transform.position);
            }
            else if (QSBPlayerManager.PlayerList.Count != 0)
            {
                playerToUse = QSBPlayerManager.GetClosestPlayerToWorldPoint(__instance.transform.position, true);
            }

            var localPosition = playerToUse != null
                                ? __instance._animator.transform.InverseTransformPoint(playerToUse.CameraBody.transform.position)
                                : Vector3.zero;

            var targetWeight = __instance.headTrackingWeight;

            if (__instance.lookOnlyWhenTalking)
            {
                if (!__instance._inConversation ||
                    qsbObj.Occupants.Count == 0 ||
                    !qsbObj.Occupants.Contains(playerToUse))
                {
                    targetWeight *= 0;
                }
            }
            else
            {
                if (qsbObj.Occupants.Count == 0 ||
                    !qsbObj.Occupants.Contains(playerToUse))
                {
                    targetWeight *= 0;
                }
            }

            __instance._currentLookWeight = Mathf.Lerp(__instance._currentLookWeight, targetWeight, Time.deltaTime * 2f);
            __instance._currentLookTarget = __instance.lookSpring.Update(__instance._currentLookTarget, localPosition, Time.deltaTime);
            __instance._animator.SetLookAtPosition(__instance._animator.transform.TransformPoint(__instance._currentLookTarget));
            __instance._animator.SetLookAtWeight(__instance._currentLookWeight);
            return(false);
        }
    public void UpdatePosition(long serverPlayerID, float cellX, float cellY, string direction, float moveSpeed, float timeDifference, float serverDelay)
    {
        GameObject characterObject = GameObject.Find("" + serverPlayerID);

        // If player already been destroyed (e.g. dead)
        if (characterObject == null)
        {
            return;
        }

        float bufferTime = 0.05f;

        // If it is the enemy, add a local buffer time to handle jitter

        /*if(serverPlayerID != PlayerID)
         * {
         *      timeDifference += bufferTime;
         * }*/


        // If it is a player, add a local lag
        if (serverPlayerID == PlayerID)
        {
            timeDifference = 2 * serverDelay / 1000.0f;
        }

        timeDifference += bufferTime;

        CharacterAnimController movementController = characterObject.GetComponent <CharacterAnimController>();
        float defaultSpeed = moveSpeed;                 // movement speed from the server

        if (timeDifference < 0)
        {
            timeDifference *= -1;
        }

        // Delayed time here can be faster or slower
        float delayedTime = (ZooMap.cellWidth / defaultSpeed) + timeDifference;

        Debug.Log("DELAYED TIME!!!: " + delayedTime);
        Debug.Log("SERVER SEND SPEED!!!: " + moveSpeed);

        movementController.PlayerSpeed = ZooMap.cellWidth / delayedTime;

        Debug.Log("Time Difference: " + timeDifference);
        Debug.Log("LPF Speed is : " + movementController.PlayerSpeed);

        // If it is the player

        /*if(serverPlayerID == PlayerID)
         * {
         *      // set the local lag delay and player will move by it's own
         *      movementController.LOCAL_LAG_DELAY = (float) 2 * serverDelay/1000.0f;
         *      movementController.PlayerSpeed = moveSpeed;
         *
         *      //Debug.Log ("PLAYER LOCAL LAG DELAY IS: "+movementController.LOCAL_LAG_DELAY );
         * }
         */


        // If enemy, do LocalPerceptionFilter
        if (serverPlayerID != PlayerID)
        {
            switch (direction)
            {
            case "UP":
                movementController.MoveUp(cellX, cellY, false);
                break;

            case "DOWN":
                movementController.MoveDown(cellX, cellY, false);
                break;

            case "LEFT":
                movementController.MoveLeft(cellX, cellY, false);
                break;

            case "RIGHT":
                movementController.MoveRight(cellX, cellY, false);
                break;
            }
        }
    }
    public void UpdatePlayerStatus(string serverPlayerID, long bombLeft, bool isAlive,
                                   List <object> powerupList, long playerLives)
    {
        GameObject characterObject = GameObject.Find(serverPlayerID);
        GameObject hud             = GameObject.Find("UnityHUDPrefab");
        HUD        hudScript       = null;


        // If game object can be found
        if (characterObject)
        {
            // If server says player is dead
            if (isAlive == false)
            {
                // Make camera movable (Spectator Mode)
                if (serverPlayerID == PlayerID.ToString())
                {
                    GameObject cameraObject = GameObject.Find("tk2dCamera");
                    if (cameraObject)
                    {
                        cameraObject.GetComponent <SmoothCamera2D>().SetTargetAlive = false;
                    }
                }
                // Play Sound
                CharacterAnimController characterController = characterObject.GetComponent <CharacterAnimController>();
                Destroy(characterObject);
            }

            // If the character is myself. I Toggle the powerup
            if (serverPlayerID == PlayerID.ToString())
            {
                if (hud)
                {
                    hudScript = hud.GetComponent <HUD>();
                }

                // Update Lives
                hudScript.UpdateHealthStatus((int)playerLives);

                // no item - 0, 1 - bomb range, 2 - haste, 3 - invunerable, 4 - more bombs, 5 - shakable
                for (int powerupIndex = 0; powerupIndex < powerupList.Count; powerupIndex++)
                {
                    long powerupID = (long)powerupList[powerupIndex];

                    //Debug.Log ("Powerup Index IS: "+powerupIndex    +"    ID is: "+powerupID);

                    if (powerupIndex == 1)
                    {
                        hudScript.ToggleRange(powerupID != 0);
                    }
                    else if (powerupIndex == 2)
                    {
                        hudScript.ToggleHaste(powerupID != 0);
                    }
                    else if (powerupIndex == 3)
                    {
                        hudScript.ToggleInvulnerable(powerupID != 0);
                    }
                    else if (powerupIndex == 4)
                    {
                        hudScript.ToggleTrick(powerupID != 0);
                    }
                    else if (powerupIndex == 5)
                    {
                        hudScript.ToggleShake(powerupID != 0);
                    }
                }
            }
        }
    }
Example #18
0
 private void Awake()
 {
     _inputInfo      = GetComponent <InputInfo>();
     _animController = GetComponent <CharacterAnimController>();
     _transform      = transform;
 }