Beispiel #1
0
        /// <summary>
        /// Is function will be called at server to order character to attack
        /// </summary>
        protected virtual void NetFuncAttack()
        {
            if (Time.unscaledTime - lastActionCommandReceivedTime < ACTION_COMMAND_DELAY)
            {
                return;
            }
            lastActionCommandReceivedTime = Time.unscaledTime;

            if (!CanMoveOrDoActions())
            {
                return;
            }

            // Prepare requires data
            AnimActionType animActionType;
            int            dataId;
            int            animationIndex;
            CharacterItem  weapon;
            float          triggerDuration;
            float          totalDuration;
            DamageInfo     damageInfo;
            Dictionary <DamageElement, MinMaxFloat> allDamageAmounts;

            GetAttackingData(
                out animActionType,
                out dataId,
                out animationIndex,
                out weapon,
                out triggerDuration,
                out totalDuration,
                out damageInfo,
                out allDamageAmounts);

            // Reduce ammo amount
            if (weapon != null)
            {
                var weaponType = weapon.GetWeaponItem().WeaponType;
                if (weaponType.requireAmmoType != null)
                {
                    Dictionary <CharacterItem, short> decreaseItems;
                    if (!this.DecreaseAmmos(weaponType.requireAmmoType, 1, out decreaseItems))
                    {
                        return;
                    }
                    var firstEntry    = decreaseItems.FirstOrDefault();
                    var characterItem = firstEntry.Key;
                    var item          = characterItem.GetItem();
                    if (item != null && firstEntry.Value > 0)
                    {
                        allDamageAmounts = GameDataHelpers.CombineDamageAmountsDictionary(allDamageAmounts, item.GetIncreaseDamages(characterItem.level, characterItem.GetEquipmentBonusRate()));
                    }
                }
            }

            // Play animation on clients
            RequestPlayActionAnimation(animActionType, dataId, (byte)animationIndex);

            // Start attack routine
            StartCoroutine(AttackRoutine(CacheTransform.position, triggerDuration, totalDuration, weapon, damageInfo, allDamageAmounts));
        }
Beispiel #2
0
        protected override void UpdateData()
        {
            cacheStatsWithBuffs      = Data.GetStats();
            cacheAttributesWithBuffs = Data.GetAttributes();
            displayingStats          = showStatsWithBuffs ? cacheStatsWithBuffs : Data.GetStats(true, false);
            displayingAttributes     = showAttributeWithBuffs ? cacheAttributesWithBuffs : Data.GetAttributes(true, false);

            if (uiTextWeightLimit != null)
            {
                uiTextWeightLimit.text = string.Format(weightLimitStatsFormat, Data.GetTotalItemWeight().ToString("N2"), cacheStatsWithBuffs.weightLimit.ToString("N2"));
            }

            var rightHandItem    = Data.EquipWeapons.rightHand;
            var leftHandItem     = Data.EquipWeapons.leftHand;
            var rightHandWeapon  = rightHandItem.GetWeaponItem();
            var leftHandWeapon   = leftHandItem.GetWeaponItem();
            var rightHandDamages = rightHandWeapon != null?GameDataHelpers.CombineDamageAmountsDictionary(Data.GetIncreaseDamages(), rightHandWeapon.GetDamageAmount(rightHandItem.level, rightHandItem.GetEquipmentBonusRate(), Data)) : null;

            var leftHandDamages = leftHandWeapon != null?GameDataHelpers.CombineDamageAmountsDictionary(Data.GetIncreaseDamages(), leftHandWeapon.GetDamageAmount(leftHandItem.level, leftHandItem.GetEquipmentBonusRate(), Data)) : null;

            if (uiTextWeaponDamages != null)
            {
                var textDamages = "";
                if (rightHandWeapon != null)
                {
                    var sumDamages = GameDataHelpers.GetSumDamages(rightHandDamages);
                    if (!string.IsNullOrEmpty(textDamages))
                    {
                        textDamages += "\n";
                    }
                    textDamages += string.Format(weaponDamageFormat, sumDamages.min.ToString("N0"), sumDamages.max.ToString("N0"));
                }
                if (leftHandWeapon != null)
                {
                    var sumDamages = GameDataHelpers.GetSumDamages(leftHandDamages);
                    if (!string.IsNullOrEmpty(textDamages))
                    {
                        textDamages += "\n";
                    }
                    textDamages += string.Format(weaponDamageFormat, sumDamages.min.ToString("N0"), sumDamages.max.ToString("N0"));
                }
                if (rightHandWeapon == null && leftHandWeapon == null)
                {
                    var defaultWeaponItem     = GameInstance.Singleton.DefaultWeaponItem;
                    var defaultWeaponItemType = defaultWeaponItem.EquipType;
                    var damageAmount          = defaultWeaponItem.GetDamageAmount(1, 1f, Data);
                    textDamages = string.Format(weaponDamageFormat, damageAmount.Value.min.ToString("N0"), damageAmount.Value.max.ToString("N0"));
                }
                uiTextWeaponDamages.text = textDamages;
            }

            if (uiRightHandDamages != null)
            {
                if (rightHandWeapon == null)
                {
                    uiRightHandDamages.Hide();
                }
                else
                {
                    uiRightHandDamages.Show();
                    uiRightHandDamages.Data = rightHandDamages;
                }
            }

            if (uiLeftHandDamages != null)
            {
                if (leftHandWeapon == null)
                {
                    uiLeftHandDamages.Hide();
                }
                else
                {
                    uiLeftHandDamages.Show();
                    uiLeftHandDamages.Data = leftHandDamages;
                }
            }

            if (uiCharacterStats != null)
            {
                uiCharacterStats.Data = displayingStats;
            }

            if (CacheUICharacterAttributes.Count > 0 && Data != null)
            {
                Attribute tempAttribute;
                short     tempAmount;
                var       characterAttributes = Data.Attributes;
                for (var indexOfData = 0; indexOfData < characterAttributes.Count; ++indexOfData)
                {
                    tempAttribute = characterAttributes[indexOfData].GetAttribute();
                    UICharacterAttribute cacheUICharacterAttribute;
                    tempAmount = 0;
                    if (CacheUICharacterAttributes.TryGetValue(tempAttribute, out cacheUICharacterAttribute))
                    {
                        if (displayingAttributes.ContainsKey(tempAttribute))
                        {
                            tempAmount = displayingAttributes[tempAttribute];
                        }
                        cacheUICharacterAttribute.Setup(new AttributeTuple(tempAttribute, tempAmount), Data, indexOfData);
                        cacheUICharacterAttribute.Show();
                    }
                }
            }

            if (uiCharacterBuffs != null)
            {
                uiCharacterBuffs.UpdateData(Data);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Is function will be called at server to order character to use skill
        /// </summary>
        /// <param name="position">Target position to apply skill at</param>
        /// <param name="dataId">Skill's data id which will be used</param>
        protected virtual void NetFuncUseSkill(Vector3 position, int dataId)
        {
            if (Time.unscaledTime - lastActionCommandReceivedTime < ACTION_COMMAND_DELAY)
            {
                return;
            }
            lastActionCommandReceivedTime = Time.unscaledTime;

            if (!CanMoveOrDoActions())
            {
                return;
            }

            var index = this.IndexOfSkill(dataId);

            if (index < 0)
            {
                return;
            }

            var characterSkill = skills[index];

            if (!characterSkill.CanUse(this))
            {
                return;
            }

            // Prepare requires data
            AnimActionType  animActionType;
            int             animationIndex;
            SkillAttackType skillAttackType;
            CharacterItem   weapon;
            float           triggerDuration;
            float           totalDuration;
            DamageInfo      damageInfo;
            Dictionary <DamageElement, MinMaxFloat> allDamageAmounts;

            GetUsingSkillData(
                characterSkill,
                out animActionType,
                out dataId,
                out animationIndex,
                out skillAttackType,
                out weapon,
                out triggerDuration,
                out totalDuration,
                out damageInfo,
                out allDamageAmounts);

            if (weapon != null)
            {
                var weaponType = weapon.GetWeaponItem().WeaponType;
                // Reduce ammo amount
                if (skillAttackType != SkillAttackType.None && weaponType.requireAmmoType != null)
                {
                    Dictionary <CharacterItem, short> decreaseItems;
                    if (!this.DecreaseAmmos(weaponType.requireAmmoType, 1, out decreaseItems))
                    {
                        return;
                    }
                    var firstEntry    = decreaseItems.FirstOrDefault();
                    var characterItem = firstEntry.Key;
                    var item          = characterItem.GetItem();
                    if (item != null && firstEntry.Value > 0)
                    {
                        allDamageAmounts = GameDataHelpers.CombineDamageAmountsDictionary(allDamageAmounts, item.GetIncreaseDamages(characterItem.level, characterItem.GetEquipmentBonusRate()));
                    }
                }
            }

            // Play animation on clients
            RequestPlayActionAnimation(animActionType, dataId, (byte)animationIndex);

            // Start use skill routine
            StartCoroutine(UseSkillRoutine(characterSkill, position, triggerDuration, totalDuration, skillAttackType, weapon, damageInfo, allDamageAmounts));
        }