Esempio n. 1
0
        partial void SetupDrawOrder()
        {
            //make sure every character gets drawn at a distinct "layer"
            //(instead of having some of the limbs appear behind and some in front of other characters)
            float startDepth = 0.1f;
            float increment  = 0.001f;

            foreach (Character otherCharacter in Character.CharacterList)
            {
                if (otherCharacter == character)
                {
                    continue;
                }
                startDepth += increment;
            }
            //make sure each limb has a distinct depth value
            List <Limb> depthSortedLimbs = Limbs.OrderBy(l => l.ActiveSprite == null ? 0.0f : l.ActiveSprite.Depth).ToList();

            foreach (Limb limb in Limbs)
            {
                if (limb.ActiveSprite != null)
                {
                    limb.ActiveSprite.Depth = startDepth + depthSortedLimbs.IndexOf(limb) * 0.00001f;
                }
            }
            depthSortedLimbs.Reverse();
            inversedLimbDrawOrder = depthSortedLimbs.ToArray();
        }
Esempio n. 2
0
 protected void CreateLimbs()
 {
     Limbs.Clear();
     foreach (var element in MainElement.Elements("limb"))
     {
         Limbs.Add(new LimbParams(element, this));
     }
     Limbs = Limbs.OrderBy(l => l.ID).ToList();
 }
    private void StartPutLimbIntoReceptacleAnimation(Limbs limb)
    {
        switch (limb)
        {
        case Limbs.RightArm:
            RightArmAnimator.Play(RightArmStateName);
            break;

        default:
            throw new InvalidEnumArgumentException();
        }
    }
Esempio n. 4
0
        public Dwarf() : base()
        {
            CharRepresentation = 'D';
            DrawColor          = libtcodWrapper.ColorPresets.Aqua;
            this.Type          = CreatureTypes.Dwarf;

            Head  MyHead    = new Head(this, "Head", 40);
            Foot  LeftFoot  = new Foot(this, "Left Foot", 20);
            Foot  RightFoot = new Foot(this, "Right Foot", 25);
            Leg   LeftLeg   = new Leg(this, "Left Leg", 75);
            Leg   RightLeg  = new Leg(this, "Right Leg", 75);
            Torso MyTorso   = new Torso(this, "Torso", 70);
            Arm   LeftArm   = new Arm(this, "Left Arm", 75);
            Arm   RightArm  = new Arm(this, "Right Arm", 75);
            Hand  LeftHand  = new Hand(this, "Left Hand", 20);
            Hand  RightHand = new Hand(this, "Right Hand", 25);

            LimbDependencies.Add(new LimbDependency(LeftHand, LeftArm));
            LimbDependencies.Add(new LimbDependency(RightHand, RightArm));
            LimbDependencies.Add(new LimbDependency(LeftFoot, LeftLeg));
            LimbDependencies.Add(new LimbDependency(RightFoot, RightLeg));
            LimbDependencies.Add(new LimbDependency(MyHead, MyTorso));
            LimbDependencies.Add(new LimbDependency(LeftLeg, MyTorso));
            LimbDependencies.Add(new LimbDependency(RightLeg, MyTorso));
            LimbDependencies.Add(new LimbDependency(LeftArm, MyTorso));
            LimbDependencies.Add(new LimbDependency(RightArm, MyTorso));
            LimbDependencies.Add(new LimbDependency(MyTorso, MyHead));

            //TODO: Enforce dependencies!

            Limbs.Add(MyTorso);
            Limbs.Add(MyHead);
            Limbs.Add(LeftArm);
            Limbs.Add(RightArm);
            Limbs.Add(LeftHand);
            Limbs.Add(RightHand);
            Limbs.Add(LeftLeg);
            Limbs.Add(RightLeg);
            Limbs.Add(LeftFoot);
            Limbs.Add(RightFoot);

            PreferredLimbAttackOrder.Add(RightHand);
            PreferredLimbAttackOrder.Add(LeftHand);
            PreferredLimbAttackOrder.Add(MyHead);
            PreferredLimbAttackOrder.Add(RightArm);
            PreferredLimbAttackOrder.Add(LeftArm);
            PreferredLimbAttackOrder.Add(RightFoot);
            PreferredLimbAttackOrder.Add(LeftFoot);
            PreferredLimbAttackOrder.Add(RightLeg);
            PreferredLimbAttackOrder.Add(LeftLeg);
            PreferredLimbAttackOrder.Add(MyTorso);
        }
Esempio n. 5
0
    public void Hit()
    {
        Limbs childLimb = transform.GetChild(0).GetComponentInChildren <Limbs>();

        if (childLimb)
        {
            childLimb.Hit();
        }

        transform.localScale = Vector3.zero;

        GameObject spawnLimb = Instantiate(limbPrefab, transform.parent);

        spawnLimb.transform.parent = null;
        Destroy(spawnLimb, 10);
        Destroy(this);
    }
Esempio n. 6
0
        /// <summary>
        /// 执行
        /// </summary>
        private void Execute()
        {
            TryCatch($"{Name} Spider Execute", async() =>
            {
                if (Result.Succeeded)
                {
                    await Limbs.Fetch();
                }

                if (Result.Succeeded)
                {
                    await Head.Analysis();
                }
            }, () => {
                Scheduler.Fail(Result);
            });
        }
        /// <summary>
        /// Apply IK to the limb.
        /// </summary>
        public void SetIK(Limbs limb, IKWeight ikData)
        {
            switch (limb)
            {
            case Limbs.LeftHand:
                leftHandIK = ikData;
                break;

            case Limbs.RightHand:
                rightHandIK = ikData;
                break;

            case Limbs.LeftFoot:
                leftFootIK = ikData;
                break;

            case Limbs.RightFoot:
                rightFootIK = ikData;
                break;
            }
        }
Esempio n. 8
0
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            if (Directions != null && Directions.Any())
            {
                if (CurrentLanguage == Language.English)
                {
                    result.Append(string.Join(",", Directions));
                }
                else if (CurrentLanguage == Language.Japanese)
                {
                    result.Append(string.Join("", Directions));
                }
            }
            if (Limbs != null && Limbs.Any())
            {
                switch (CurrentProperty)
                {
                case Property.Quick:
                    if (CurrentLanguage == Language.English)
                    {
                        result.Append('+');
                        result.Append(string.Join("~", Limbs));
                    }
                    else if (CurrentLanguage == Language.Japanese)
                    {
                        result.Append('【');
                        result.Append(string.Join(",", Limbs));
                        result.Append('】');
                    }
                    break;

                case Property.Normal:
                    result.Append(string.Join(",", Limbs));
                    break;
                }
            }
            return(result.ToString());
        }
Esempio n. 9
0
        public GiantRat()
            : base()
        {
            CharRepresentation = 'r';
            DrawColor          = libtcodWrapper.ColorPresets.Brown;
            Type = CreatureTypes.Giant_Rat;

            Head  MyHead        = new Head(this, "Head", 60);
            Torso MyTorso       = new Torso(this, "Torso", 70);
            Foot  FrontLeftPaw  = new Foot(this, "Front Left Paw", 50);
            Foot  FrontRightPaw = new Foot(this, "Front Right Paw", 50);
            Foot  RearLeftPaw   = new Foot(this, "Rear Left Paw", 35);
            Foot  RearRightPaw  = new Foot(this, "Rear Right Paw", 35);
            Tail  MyTail        = new Tail(this, "Tail", 20);

            LimbDependencies.Add(new LimbDependency(MyHead, MyTorso));
            LimbDependencies.Add(new LimbDependency(MyTorso, MyHead));
            LimbDependencies.Add(new LimbDependency(FrontLeftPaw, MyTorso));
            LimbDependencies.Add(new LimbDependency(FrontRightPaw, MyTorso));
            LimbDependencies.Add(new LimbDependency(RearLeftPaw, MyTorso));
            LimbDependencies.Add(new LimbDependency(RearRightPaw, MyTorso));
            LimbDependencies.Add(new LimbDependency(MyTail, MyTorso));

            PreferredLimbAttackOrder.Add(MyHead);
            PreferredLimbAttackOrder.Add(FrontRightPaw);
            PreferredLimbAttackOrder.Add(FrontLeftPaw);
            PreferredLimbAttackOrder.Add(MyTail);

            Limbs.Add(MyTorso);
            Limbs.Add(MyHead);
            Limbs.Add(FrontLeftPaw);
            Limbs.Add(FrontRightPaw);
            Limbs.Add(RearLeftPaw);
            Limbs.Add(RearRightPaw);
            Limbs.Add(MyTail);
        }
Esempio n. 10
0
 protected IEnumerable <RagdollSubParams> GetAllSubParams() =>
 ColliderParams.Select(c => c as RagdollSubParams)
 .Concat(Limbs.Select(j => j as RagdollSubParams)
         .Concat(Joints.Select(j => j as RagdollSubParams)));
 private void CutOffLimb(Limbs limb)
 {
     FpsControllerScript.DisableMovement();
     StartPutLimbIntoReceptacleAnimation(limb);
 }
Esempio n. 12
0
        public override void SetAndRefreshData(BlockBase blockBase)
        {
            base.SetAndRefreshData(blockBase);

            _costumeBlock = (Costume)blockBase;


            //General
            Header.Text = _costumeBlock.Header;
            Size.Text   = _costumeBlock.Size.ToString();
            Format.Text = _costumeBlock.Format.ToString();
            if (_costumeBlock.HasCloseByte)
            {
                CloseByte.Text = _costumeBlock.CloseByte.ToString();
            }
            else
            {
                CloseByte.Text = string.Empty;
            }

            //Animations
            NumAnimations.Text = _costumeBlock.NumAnim.ToString();
            AnimOffsets.Items.Clear();
            foreach (ushort animationOffset in _costumeBlock.AnimOffsets)
            {
                var item = AnimOffsets.Items.Add(animationOffset.ToString());
            }

            Animations.Nodes.Clear();
            foreach (Animation animation in _costumeBlock.Animations)
            {
                TreeNode nodeAnim = Animations.Nodes.Add(animation.Offset.ToString(), "Offset: " + animation.Offset.ToString());
                nodeAnim.Nodes.Add(string.Format("LimbMask: {0}", animation.LimbMask));
                nodeAnim.Nodes.Add(string.Format("Number of Limbs: {0}", animation.NumLimbs));

                int animationCount = 0;
                foreach (AnimationDefinition animationDefinition in animation.AnimDefinitions)
                {
                    animationCount++;
                    TreeNode definition = nodeAnim.Nodes.Add(string.Format("Animation {0}", animationCount));

                    definition.Nodes.Add(string.Format("Disabled: {0}", animationDefinition.Disabled));
                    definition.Nodes.Add(string.Format("Length: {0}", animationDefinition.Length));
                    definition.Nodes.Add(string.Format("NoLoop: {0}", animationDefinition.NoLoop));
                    definition.Nodes.Add(string.Format("Start: {0}", animationDefinition.Start));
                    definition.Nodes.Add(string.Format("NoLoopAndEndOffset Byte: {0}", animationDefinition.NoLoopAndEndOffset));
                }
            }
            Animations.ExpandAll();

            //Animation commands
            AnimationCommandsOffset.Text = _costumeBlock.AnimCommandsOffset.ToString();
            Commands.Items.Clear();
            foreach (byte command in _costumeBlock.Commands)
            {
                ListViewItem item = Commands.Items.Add(string.Format("{0} - (0x{1})", command, command.ToString("X")));
                if (command >= 0x71 && command <= 0x78)
                {
                    item.SubItems.Add("Add Sound");
                }
                if (command == 0x79)
                {
                    item.SubItems.Add("Stop");
                }
                if (command == 0x7A)
                {
                    item.SubItems.Add("Start");
                }
                if (command == 0x7B)
                {
                    item.SubItems.Add("Hide");
                }
                if (command == 0x7C)
                {
                    item.SubItems.Add("SkipFrame");
                }
            }

            //Limbs
            LimbsOffsets.Items.Clear();
            foreach (ushort limbsOffset in _costumeBlock.LimbsOffsets)
            {
                LimbsOffsets.Items.Add(limbsOffset.ToString());
            }

            int limbNumber = 0;

            Limbs.Nodes.Clear();
            foreach (Limb limb in _costumeBlock.Limbs)
            {
                limbNumber++;
                TreeNode nodeLimb = Limbs.Nodes.Add(string.Format("Limb {0}", limbNumber));
                nodeLimb.Nodes.Add(string.Format("Offset: {0}", limb.OffSet));
                nodeLimb.Nodes.Add(string.Format("Size: {0}", limb.Size));

                TreeNode imageOffsets = nodeLimb.Nodes.Add("Image Offsets:");
                foreach (ushort imageOffset in limb.ImageOffsets)
                {
                    imageOffsets.Nodes.Add(string.Format("Offset: {0}", imageOffset));
                }
            }
            Limbs.ExpandAll();

            //Pictures
            int pictureCount = 0;

            Pictures.Items.Clear();
            foreach (CostumeImageData picture in _costumeBlock.Pictures)
            {
                ListViewItem item = Pictures.Items.Add(pictureCount.ToString());
                item.SubItems.Add(picture.Width.ToString());
                item.SubItems.Add(picture.Height.ToString());
                item.SubItems.Add(picture.RelX.ToString());
                item.SubItems.Add(picture.RelY.ToString());
                item.SubItems.Add(picture.MoveX.ToString());
                item.SubItems.Add(picture.MoveY.ToString());
                item.SubItems.Add(picture.RedirLimb.ToString());
                item.SubItems.Add(picture.RedirPict.ToString());
                item.SubItems.Add(picture.ImageDataSize.ToString());

                pictureCount++;
            }
            Pictures.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

            //Palette Entrys
            PaletteTable.Controls.Clear();
            PaletteData defaultPallete = ((DiskBlock)_costumeBlock.Parent).GetROOM().GetDefaultPalette();

            for (int i = 0; i < _costumeBlock.Palette.Count; i++)
            {
                byte realPaletteIndex = _costumeBlock.Palette[i];


                PaletteColor paletteColor = new PaletteColor(i)
                {
                    BackColor   = defaultPallete.Colors[realPaletteIndex],
                    Width       = 24,
                    Height      = 24,
                    BorderStyle = BorderStyle.FixedSingle,
                    FullPalette = defaultPallete,
                    CanEdit     = true
                };

                paletteColor.PaletteIndex    = realPaletteIndex;
                paletteColor.PaletteChanged += (sender, index, paletteIndex) =>
                {
                    _costumeBlock.Palette[index]           = Convert.ToByte(paletteIndex);
                    PaletteTable.Controls[index].BackColor = defaultPallete.Colors[paletteIndex];
                    ((PaletteColor)PaletteTable.Controls[index]).PaletteIndex = paletteIndex;
                };

                toolTip1.SetToolTip(paletteColor, string.Format("R: {0}, G:{1}, B:{2}", paletteColor.BackColor.R, paletteColor.BackColor.G, paletteColor.BackColor.B));

                PaletteTable.Controls.Add(paletteColor);
            }
        }
Esempio n. 13
0
    void Update()
    {
        playerHealthBar.value = _playerStats.healthPoints;
        playerActionBar.value = _playerStats.actionPoints;

        Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);

        if (_enemies.Any(x => x.GetComponent <CharacterStats>().healthPoints <= 0))
        {
            EnemyMove deleteEnemy = _enemies.Where(x => x.GetComponent <CharacterStats>().healthPoints <= 0).First();
            _enemies.Remove(deleteEnemy);
            if (_enemiesInViewport.Contains(deleteEnemy))
            {
                _enemiesInViewport.Remove(deleteEnemy);
                if (_enemiesVisible.Contains(deleteEnemy))
                {
                    _enemiesVisible.Remove(deleteEnemy);
                }
            }
        }

        foreach (EnemyMove enemy in _enemies)
        {
            if (GeometryUtility.TestPlanesAABB(planes, enemy.GetComponent <CharacterController>().bounds) && !_enemiesInViewport.Contains(enemy) && !enemy.isDead)
            {
                _enemiesInViewport.Add(enemy);
            }
            else if ((!GeometryUtility.TestPlanesAABB(planes, enemy.GetComponent <CharacterController>().bounds) && _enemiesInViewport.Contains(enemy)) || enemy.isDead)
            {
                _enemiesInViewport.Remove(enemy);
            }
        }

        if (Input.GetButtonDown("Enter VATS") && _enemiesInViewport.Count > 0 && !_VATSactive)
        {
            _justEnteredVATS = _VATSactive = true;
        }
        if (Input.GetButtonDown("Exit VATS") && !_VATSSetupOrder.Any() && !_inAnimation)
        {
            _VATSactive = false;
        }

        VATSCamera.gameObject.SetActive(_VATSactive);

        switch (_VATSactive)
        {
        case true:
            Camera.main.depth = -99;

            if (!_inAnimation)
            {
                VATSEnemyHealthName.transform.parent.gameObject.SetActive(true);
                RaycastHit[] tempHit = new RaycastHit[_enemiesInViewport.Count];
                for (int i = 0; i < _enemiesInViewport.Count; i++)
                {
                    Vector3 origin    = _shootClass.weaponProjectilePos.position;
                    Vector3 direction = ((_enemiesInViewport[i].transform.position + (Vector3.up * (_enemiesInViewport[i].GetComponent <CharacterController>().height / 2))) - _shootClass.weaponProjectilePos.position).normalized * VATSRange;

                    if (Physics.Raycast(origin, direction, out tempHit[i], Mathf.Min(VATSRange, Vector3.Distance(_enemiesInViewport[i].transform.position, _shootClass.weaponProjectilePos.position))))
                    {
                        if (tempHit[i].collider == _enemiesInViewport[i].GetComponent <CapsuleCollider>())
                        {
                            Cursor.visible   = true;
                            Cursor.lockState = CursorLockMode.None;

                            if (!_enemiesVisible.Contains(_enemiesInViewport[i].GetComponent <EnemyMove>()))
                            {
                                _enemiesVisible.Add(_enemiesInViewport[i].GetComponent <EnemyMove>());
                            }
                            Debug.DrawRay(origin, direction);
                        }
                    }
                }

                for (int i = 0; i < _enemiesInViewport.Count; i++)
                {
                    if (tempHit[i].collider != null)
                    {
                        if (tempHit[i].collider.tag == "Level")
                        {
                            if (_enemiesVisible.Contains(_enemiesInViewport[i].GetComponent <EnemyMove>()))
                            {
                                _enemiesVisible.Remove(_enemiesInViewport[i].GetComponent <EnemyMove>());
                                _selectedEnemy = _selectedEnemy <= 0 ? 0 : _selectedEnemy - 1;
                                _previousEnemy = _previousEnemy <= 0 ? 0 : _previousEnemy - 1;
                                if (_enemiesVisible.Count <= 0)
                                {
                                    _VATSactive = false;
                                }
                            }
                        }
                    }
                }

                if (_enemiesVisible[_selectedEnemy].indicatorSelectors == null)
                {
                    _enemiesVisible[_selectedEnemy].indicatorSelectors = new Stack <RectTransform> [_enemiesVisible[_selectedEnemy].limbs.Length];
                    for (int i = 0; i < _enemiesVisible[_selectedEnemy].indicatorSelectors.Length; i++)
                    {
                        _enemiesVisible[_selectedEnemy].indicatorSelectors[i] = new Stack <RectTransform>();
                    }
                }

                Vector3 lerpedPosition = Vector3.Lerp(_enemiesVisible[_previousEnemy].transform.position + (Vector3.up * (_enemiesVisible[_previousEnemy].GetComponent <CharacterController>().height / 2)),
                                                      _enemiesVisible[_selectedEnemy].transform.position + (Vector3.up * (_enemiesVisible[_selectedEnemy].GetComponent <CharacterController>().height / 2)),
                                                      _moveLerpElapsed);

                VATSCamera.depth             = 99;
                _shootClass.mouseRestriction = true;
                _moveClass.mouseRestriction  = true;
                _moveClass.stationary        = true;

                Time.timeScale = 0.01f;

                VATSEnemyHealthName.text    = _enemiesVisible[_selectedEnemy].GetComponent <CharacterStats>().name.ToUpper();
                VATSEnemyHealthBar.maxValue = _enemiesVisible[_selectedEnemy].GetComponent <CharacterStats>().maxHealthPoints;
                VATSEnemyHealthBar.value    = _enemiesVisible[_selectedEnemy].GetComponent <CharacterStats>().healthPoints;

                VATSHitChanceIndicators.position = VATSCamera.WorldToScreenPoint(_enemiesVisible[_selectedEnemy].transform.position + (Vector3.up * (_enemiesVisible[_selectedEnemy].GetComponent <CharacterController>().height / 2)));
                for (int ii = 0; ii < _enemiesVisible[_selectedEnemy].limbs.Length; ii++)
                {
                    if (!_indicators.Exists(x => x.limb.bones == _enemiesVisible[_selectedEnemy].limbs[ii].bones))
                    {
                        _indicators.Add(new IndicatorLimbPairing()
                        {
                            indicator = Instantiate(VATSIndicator, VATSCamera.WorldToScreenPoint(_enemiesVisible[_selectedEnemy].limbs[ii].indicatorPosition.position), Quaternion.identity, VATSHitChanceIndicators).GetComponent <Indicator>(), limb = _enemiesVisible[_selectedEnemy].limbs[ii]
                        });
                        if (_enemiesVisible[_selectedEnemy].indicatorSelectors[ii].Any())
                        {
                            for (int iii = 0; iii < _enemiesVisible[_selectedEnemy].indicatorSelectors[ii].Count; iii++)
                            {
                                RectTransform newSelector = Instantiate(VATSIndicatorSelector, _indicators[ii].indicator.transform);
                                newSelector.offsetMin = new Vector2(-5 - (10 * iii), newSelector.offsetMin.y);
                                newSelector.offsetMax = new Vector2(5 + (10 * iii), newSelector.offsetMax.y);
                            }
                        }
                    }
                }

                for (int ii = 0; ii < _indicators.Count; ii++)
                {
                    _indicators[ii].indicator.transform.position = VATSCamera.WorldToScreenPoint(_indicators[ii].limb.indicatorPosition.position);
                    float hitChance = 100f;
                    foreach (Collider bone in _indicators[ii].limb.bones)
                    {
                        Ray tempRayTop    = new Ray(VATSCamera.transform.position, (bone.bounds.center + (bone.transform.up * bone.bounds.extents.y)) - VATSCamera.transform.position);
                        Ray tempRayCentre = new Ray(VATSCamera.transform.position, bone.bounds.center - VATSCamera.transform.position);
                        Ray tempRayBottom = new Ray(VATSCamera.transform.position, (bone.bounds.center - (bone.transform.up * bone.bounds.extents.y)) - VATSCamera.transform.position);

                        RaycastHit tempRayHitTop, tempRayHitCentre, tempRayHitBottom;

                        if (Physics.Raycast(tempRayTop, out tempRayHitTop, Mathf.Min(VATSRange, Vector3.Distance((bone.bounds.center + (bone.transform.up * bone.bounds.extents.y)), VATSCamera.transform.position)), ~LayerMask.GetMask("PlayerModel", "PlayerController", "EnemyController")))
                        {
                            if (_indicators[ii].limb.bones.Contains(tempRayHitTop.collider))
                            {
                                hitChance -= Mathf.Clamp(tempRayHitTop.distance * VATSHitChanceModifier / _indicators[ii].limb.bones.Length, 0f, ((1f / 3f) / _indicators[ii].limb.bones.Length) * 100f);
                            }
                            else
                            {
                                hitChance -= 100f * ((1f / 3f) / _indicators[ii].limb.bones.Length);
                            }
                        }

                        if (Physics.Raycast(tempRayCentre, out tempRayHitCentre, Mathf.Min(VATSRange, Vector3.Distance(bone.bounds.center, VATSCamera.transform.position)), ~LayerMask.GetMask("PlayerModel", "PlayerController", "EnemyController")))
                        {
                            if (_indicators[ii].limb.bones.Contains(tempRayHitCentre.collider))
                            {
                                hitChance -= Mathf.Clamp(tempRayHitCentre.distance * VATSHitChanceModifier / _indicators[ii].limb.bones.Length, 0f, ((1f / 3f) / _indicators[ii].limb.bones.Length) * 100f);
                            }
                            else
                            {
                                hitChance -= 100f * ((1f / 3f) / _indicators[ii].limb.bones.Length);
                            }
                        }

                        if (Physics.Raycast(tempRayBottom, out tempRayHitBottom, Mathf.Min(VATSRange, Vector3.Distance((bone.bounds.center - (bone.transform.up * bone.bounds.extents.y)), VATSCamera.transform.position)), ~LayerMask.GetMask("PlayerModel", "PlayerController", "EnemyController")))
                        {
                            if (_indicators[ii].limb.bones.Contains(tempRayHitBottom.collider))
                            {
                                hitChance -= Mathf.Clamp(tempRayHitBottom.distance * VATSHitChanceModifier / _indicators[ii].limb.bones.Length, 0f, ((1f / 3f) / _indicators[ii].limb.bones.Length) * 100f);
                            }
                            else
                            {
                                hitChance -= 100f * ((1f / 3f) / _indicators[ii].limb.bones.Length);
                            }
                        }
                    }
                    hitChance = Mathf.Clamp(hitChance, 0f, 100f);
                    _indicators[ii].indicator.hitChanceText.text = hitChance.ToString("0");
                    _indicators[ii].limb.hitChance = hitChance;
                }

                SetLayer(_enemiesVisible[_selectedEnemy].transform.GetChild(0).gameObject, LayerMask.NameToLayer("SelectedEnemy"), true);

                if (_mouseHoverMode)
                {
                    RaycastHit tempHit2;
                    Ray        tempRay = VATSCamera.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(tempRay, out tempHit2, VATSRange, LayerMask.GetMask("SelectedEnemy")))
                    {
                        if (tempHit2.transform.tag == "Enemy")
                        {
                            Limbs tempLimb = _enemiesVisible[_selectedEnemy].limbs.First(x => x.bones.Contains(tempHit2.collider));
                            _currentLimb = _enemiesVisible[_selectedEnemy].limbs.ToList().FindIndex(x => x.bones == tempLimb.bones);

                            tempLimb.joints.layer  = LayerMask.NameToLayer("VATSEnemy");
                            tempLimb.muscles.layer = LayerMask.NameToLayer("VATSEnemy");

                            if ((Input.GetMouseButtonDown(0) || Input.GetButtonDown("Enter VATS")) && !_justEnteredVATS && _currentVATSCost + VATSCost <= _playerStats.actionPoints)
                            {
                                GameObject tempAPIndicator = Instantiate(APIndicator, APIndicatorParent);
                                tempAPIndicator.GetComponent <RectTransform>().sizeDelta = new Vector2(APIndicatorParent.rect.width * (VATSCost / _playerStats.maxActionPoints) - APIndicatorParent.GetComponent <HorizontalLayoutGroup>().spacing, 0f);

                                _currentVATSCost += VATSCost;
                                _VATSSetupOrder.Push(tempLimb);

                                RectTransform selector = Instantiate(VATSIndicatorSelector, _indicators.First(x => x.limb.bones == tempLimb.bones).indicator.transform);
                                selector.offsetMin = new Vector2(-5 - (10 * _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Count), selector.offsetMin.y);
                                selector.offsetMax = new Vector2(5 + (10 * _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Count), selector.offsetMax.y);
                                _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Push(selector);
                            }
                            else if ((Input.GetMouseButtonDown(0) || Input.GetButtonDown("Enter VATS")) && _currentVATSCost + VATSCost > _playerStats.actionPoints)
                            {
                                _flashTimeStepMax = 0f;
                            }

                            if ((Input.GetMouseButtonDown(1) || Input.GetButtonDown("Exit VATS")) && _VATSSetupOrder.Any())
                            {
                                Destroy(APIndicatorParent.GetChild(APIndicatorParent.childCount - 1).gameObject);

                                _currentVATSCost -= VATSCost;
                                _VATSSetupOrder.Pop();
                                RectTransform selector = _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Pop();
                                Destroy(selector.gameObject);
                            }
                        }
                    }
                }
                else if (!Input.GetButtonDown("Vertical"))
                {
                    Limbs tempLimb = _enemiesVisible[_selectedEnemy].limbs[_currentLimb];

                    tempLimb.joints.layer  = LayerMask.NameToLayer("VATSEnemy");
                    tempLimb.muscles.layer = LayerMask.NameToLayer("VATSEnemy");

                    if ((Input.GetMouseButtonDown(0) || Input.GetButtonDown("Enter VATS")) && !_justEnteredVATS && _currentVATSCost + VATSCost <= _playerStats.actionPoints)
                    {
                        GameObject tempAPIndicator = Instantiate(APIndicator, APIndicatorParent);
                        tempAPIndicator.GetComponent <RectTransform>().sizeDelta = new Vector2(APIndicatorParent.rect.width * (VATSCost / _playerStats.maxActionPoints) - APIndicatorParent.GetComponent <HorizontalLayoutGroup>().spacing, 0f);

                        _currentVATSCost += VATSCost;
                        _VATSSetupOrder.Push(tempLimb);

                        RectTransform selector = Instantiate(VATSIndicatorSelector, _indicators.First(x => x.limb.bones == tempLimb.bones).indicator.transform);
                        selector.offsetMin = new Vector2(-5 - (10 * _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Count), selector.offsetMin.y);
                        selector.offsetMax = new Vector2(5 + (10 * _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Count), selector.offsetMax.y);
                        _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Push(selector);
                    }
                    else if ((Input.GetMouseButtonDown(0) || Input.GetButtonDown("Enter VATS")) && _currentVATSCost + VATSCost > _playerStats.actionPoints)
                    {
                        _flashTimeStepMax = 0f;
                    }

                    if ((Input.GetMouseButtonDown(1) || Input.GetButtonDown("Exit VATS")) && _VATSSetupOrder.Any())
                    {
                        Destroy(APIndicatorParent.GetChild(APIndicatorParent.childCount - 1).gameObject);

                        _currentVATSCost -= VATSCost;
                        _VATSSetupOrder.Pop();
                        RectTransform selector = _enemiesVisible[_selectedEnemy].indicatorSelectors[_currentLimb].Pop();
                        Destroy(selector.gameObject);
                    }
                }

                if (Input.GetButtonDown("Confirm VATS"))
                {
                    if (_VATSSetupOrder.Any())
                    {
                        _VATSShootingOrder = new Queue <Limbs>(_VATSSetupOrder.Reverse());
                        _VATSSetupOrder.Clear();
                        _inAnimation = true;
                    }
                    else
                    {
                        _VATSactive = false;
                    }
                }

                if (Input.GetButtonDown("Vertical"))
                {
                    _mouseHoverMode = false;
                }
                else if (Mathf.Abs(Input.GetAxisRaw("Mouse X") + Input.GetAxisRaw("Mouse Y")) > 0)
                {
                    _mouseHoverMode = true;
                }

                if (_moveLerpElapsed < 1 && _previousEnemy != _selectedEnemy)
                {
                    _moveLerpElapsed += Time.unscaledDeltaTime * lerpModifier;
                }
                VATSCamera.transform.LookAt(lerpedPosition);

                _newFOV = Mathf.Lerp(_previousFOV,
                                     2 * Mathf.Rad2Deg * Mathf.Acos(Mathf.Min(Vector3.Distance(VATSCamera.transform.position, _enemiesVisible[_selectedEnemy].transform.position + (Vector3.up * (_enemiesVisible[_selectedEnemy].GetComponent <CharacterController>().height / 2))),
                                                                              Vector3.Distance(VATSCamera.transform.position, _enemiesVisible[_selectedEnemy].transform.position)) /
                                                                    Mathf.Max(Vector3.Distance(VATSCamera.transform.position, _enemiesVisible[_selectedEnemy].transform.position + (Vector3.up * (_enemiesVisible[_selectedEnemy].GetComponent <CharacterController>().height / 2))),
                                                                              Vector3.Distance(VATSCamera.transform.position, _enemiesVisible[_selectedEnemy].transform.position))),
                                     _zoomChangeLerpElapsed);

                if (_zoomChangeLerpElapsed < 1)
                {
                    _zoomChangeLerpElapsed += Time.unscaledDeltaTime * lerpModifier;
                }
                if (_zoomLerpElapsed < 1)
                {
                    _zoomLerpElapsed += Time.unscaledDeltaTime * lerpModifier;
                }

                if (_flashTimeStepMax < 2)
                {
                    _flashTimeStepMax += ((2 / APFlashLength) * Time.unscaledDeltaTime);
                    if (_flashFlip)
                    {
                        _flashTimeStep += Mathf.Min((2 / APFlashLength) * Time.unscaledDeltaTime, 1f - _flashTimeStep);
                        if (_flashTimeStep >= 1f)
                        {
                            _flashFlip = false;
                        }
                    }
                    else
                    {
                        _flashTimeStep -= ((2 / APFlashLength) * Time.unscaledDeltaTime);
                        if (_flashTimeStep <= 0f)
                        {
                            _flashFlip = true;
                        }
                    }
                }
                else
                {
                    _flashFlip     = true;
                    _flashTimeStep = 0;
                }
                playerActionBar.fillRect.GetComponent <Image>().color = Color.Lerp(_sliderBaseColor, new Color(_sliderBaseColor.r, _sliderBaseColor.g, _sliderBaseColor.b, 0.25f), _flashTimeStep);
                _justEnteredVATS = false;
            }
            else
            {
                Cursor.visible = false;

                for (int i = 0; i < _indicators.Count; i++)
                {
                    Destroy(_indicators[i].indicator.gameObject);
                }

                _indicators.Clear();

                for (int i = APIndicatorParent.childCount - 1; i >= 0; i--)
                {
                    Destroy(APIndicatorParent.GetChild(i).gameObject);
                }

                if (!_animationPlaying)
                {
                    VATSCinemaCameraBrain.gameObject.SetActive(true);
                    StartCoroutine(PlayShot());
                    _animationPlaying = true;
                }
            }
            break;

        case false:
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
            {
                VATSEnemyHealthName.transform.parent.gameObject.SetActive(hit.transform.root.GetComponent <EnemyMove>() && !hit.transform.root.GetComponent <EnemyMove>().isDead);

                if (hit.transform.root.GetComponent <EnemyMove>() && !hit.transform.root.GetComponent <EnemyMove>().isDead)
                {
                    VATSEnemyHealthName.text    = hit.transform.root.GetComponent <CharacterStats>().name.ToUpper();
                    VATSEnemyHealthBar.maxValue = hit.transform.root.GetComponent <CharacterStats>().maxHealthPoints;
                    VATSEnemyHealthBar.value    = hit.transform.root.GetComponent <CharacterStats>().healthPoints;
                }
            }

            for (int i = 0; i < _indicators.Count; i++)
            {
                Destroy(_indicators[i].indicator.gameObject);
            }

            _indicators.Clear();
            Cursor.visible                = false;
            Cursor.lockState              = CursorLockMode.Locked;
            _selectedEnemy                = 0;
            _previousEnemy                = _selectedEnemy;
            _currentVATSCost              = 0;
            VATSCinemaCameraBrain.depth   = -99;
            VATSCamera.depth              = -99;
            Camera.main.depth             = 99;
            VATSCamera.transform.rotation = Camera.main.transform.rotation;
            _zoomLerpElapsed              = 0;
            for (int i = 0; i < _enemiesVisible.Count; i++)
            {
                SetLayer(_enemiesVisible[i].transform.GetChild(0).gameObject, LayerMask.NameToLayer("Default"), true);
            }
            _enemiesVisible.Clear();
            _shootClass.mouseRestriction = false;
            _moveClass.mouseRestriction  = false;
            _moveClass.stationary        = false;
            Time.timeScale = 1f;
            VATSCinemaCameraBrain.gameObject.SetActive(false);
            break;
        }
        Time.fixedDeltaTime = _fixedTimeStepBase * Time.timeScale;

        VATSHeadsUpDisplay.SetActive(_VATSactive);
        VATSCamera.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, _newFOV, _zoomLerpElapsed);

        if (_moveClass.mouseRestriction)
        {
            if (_enemiesVisible.Count > 1)
            {
                if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") > 0)
                {
                    for (int i = 0; i < _indicators.Count; i++)
                    {
                        Destroy(_indicators[i].indicator.gameObject);
                    }

                    _indicators.Clear();
                    _previousEnemy         = _selectedEnemy;
                    _previousFOV           = _newFOV;
                    _zoomChangeLerpElapsed = 0;
                    _moveLerpElapsed       = 0;
                    _selectedEnemy         = _selectedEnemy >= _enemiesVisible.Count - 1 ? 0 : _selectedEnemy + 1;

                    SetLayer(_enemiesVisible[_selectedEnemy].transform.GetChild(0).gameObject, LayerMask.NameToLayer("SelectedEnemy"), true);
                    SetLayer(_enemiesVisible[_previousEnemy].transform.GetChild(0).gameObject, LayerMask.NameToLayer("Default"), true);
                }
                else if (Input.GetButtonDown("Horizontal") && Input.GetAxisRaw("Horizontal") < 0)
                {
                    for (int i = 0; i < _indicators.Count; i++)
                    {
                        Destroy(_indicators[i].indicator.gameObject);
                    }

                    _indicators.Clear();
                    _previousEnemy         = _selectedEnemy;
                    _previousFOV           = _newFOV;
                    _zoomChangeLerpElapsed = 0;
                    _moveLerpElapsed       = 0;
                    _selectedEnemy         = _selectedEnemy <= 0 ? _enemiesVisible.Count - 1 : _selectedEnemy - 1;

                    SetLayer(_enemiesVisible[_selectedEnemy].transform.GetChild(0).gameObject, LayerMask.NameToLayer("SelectedEnemy"), true);
                    SetLayer(_enemiesVisible[_previousEnemy].transform.GetChild(0).gameObject, LayerMask.NameToLayer("Default"), true);
                }
            }

            if (Input.GetButtonDown("Vertical") && Input.GetAxisRaw("Vertical") > 0)
            {
                _currentLimb    = _currentLimb >= _enemiesVisible[_selectedEnemy].limbs.Length - 1 ? 0 : _currentLimb + 1;
                _mouseHoverMode = false;
            }
            else if (Input.GetButtonDown("Vertical") && Input.GetAxisRaw("Vertical") < 0)
            {
                _currentLimb    = _currentLimb <= 0 ? _enemiesVisible[_selectedEnemy].limbs.Length - 1 : _currentLimb - 1;
                _mouseHoverMode = false;
            }
        }
    }
Esempio n. 14
0
    IEnumerator PlayShot()
    {
        Time.timeScale = 0.001f;
        VATSCinemaCamera.GetCinemachineComponent <CinemachineBasicMultiChannelPerlin>().m_FrequencyGain = 1f / Time.timeScale;
        while (_VATSShootingOrder.Any())
        {
            _playerStats.actionPoints -= _currentVATSCost / _VATSShootingOrder.Count;
            _currentVATSCost          -= _currentVATSCost / _VATSShootingOrder.Count;
            Limbs limb = _VATSShootingOrder.Dequeue();

            VATSEnemyHealthName.text    = limb.bones[0].transform.root.GetComponent <CharacterStats>().name.ToUpper();
            VATSEnemyHealthBar.maxValue = limb.bones[0].transform.root.GetComponent <CharacterStats>().maxHealthPoints;
            VATSEnemyHealthBar.value    = limb.bones[0].transform.root.GetComponent <CharacterStats>().healthPoints;
            VATSCamera.depth            = -99;
            VATSCinemaCameraBrain.depth = 99;
            Camera.main.transform.LookAt(limb.indicatorPosition.transform);
            yield return(null);

            bool missed = (Random.Range(0f, 100f) > limb.hitChance);

            Bullet bullet = _shootClass.Fire(limb.indicatorPosition.transform, missed).GetComponent <Bullet>();
            if (bullet != null)
            {
                VATSCinemaCamera.LookAt = bullet.transform;

                bullet.missed    = false;
                bullet.startPos  = bullet.transform.position;
                bullet.targetPos = limb.indicatorPosition.transform.position;
                while (bullet != null && !bullet.missed)
                {
                    if (Vector3.Distance(bullet.transform.position, bullet.startPos) > Vector3.Distance(bullet.targetPos, bullet.startPos))
                    {
                        bullet.missed = true;
                    }
                    if (!missed && Physics.OverlapCapsule(bullet.GetComponent <CapsuleCollider>().bounds.center - new Vector3(0, bullet.GetComponent <CapsuleCollider>().bounds.extents.y, 0),
                                                          bullet.GetComponent <CapsuleCollider>().bounds.center + new Vector3(0, bullet.GetComponent <CapsuleCollider>().bounds.extents.y, 0),
                                                          bullet.GetComponent <CapsuleCollider>().radius).Any(x => limb.bones.Contains(x) || x == limb.bones[0].transform.root.GetComponent <CharacterController>()))
                    {
                        CharacterStats hitCharacter = limb.bones[0].transform.root.GetComponent <CharacterStats>();
                        if (hitCharacter != null)
                        {
                            hitCharacter.TakeDamage(10f);
                        }

                        Destroy(bullet.gameObject);
                    }
                    yield return(null);
                }
                if (!missed)
                {
                    VATSCinemaCamera.LookAt = limb.indicatorPosition;
                }
                if (bullet != null)
                {
                    Destroy(bullet.gameObject);
                }
            }

            VATSEnemyHealthName.text    = limb.bones[0].transform.root.GetComponent <CharacterStats>().name.ToUpper();
            VATSEnemyHealthBar.maxValue = limb.bones[0].transform.root.GetComponent <CharacterStats>().maxHealthPoints;
            VATSEnemyHealthBar.value    = limb.bones[0].transform.root.GetComponent <CharacterStats>().healthPoints;
            yield return(new WaitForSecondsRealtime(VATSHangTime));

            VATSCinemaCamera.LookAt = _shootClass.weaponProjectilePos;
        }

        VATSCinemaCamera.GetCinemachineComponent <CinemachineBasicMultiChannelPerlin>().m_FrequencyGain = 0;

        foreach (EnemyMove enemy in _enemiesVisible)
        {
            if (enemy.indicatorSelectors != null)
            {
                foreach (Stack <RectTransform> stack in enemy.indicatorSelectors)
                {
                    stack.Clear();
                }
            }
        }
        _inAnimation      = false;
        _VATSactive       = false;
        _animationPlaying = false;
    }
Esempio n. 15
0
 public static void SetLimb(Limbs limb)
 {
     _limb = limb;
 }