Exemplo n.º 1
0
        /// <summary>
        /// Combine damage amounts dictionary
        /// </summary>
        /// <param name="sourceDictionary"></param>
        /// <param name="newEntry"></param>
        /// <returns></returns>
        public static Dictionary <DamageElement, MinMaxFloat> CombineDamages(Dictionary <DamageElement, MinMaxFloat> sourceDictionary, KeyValuePair <DamageElement, MinMaxFloat> newEntry)
        {
            if (sourceDictionary == null)
            {
                sourceDictionary = new Dictionary <DamageElement, MinMaxFloat>();
            }
            GameInstance  gameInstance  = GameInstance.Singleton;
            DamageElement damageElement = newEntry.Key;

            if (damageElement == null)
            {
                damageElement = gameInstance.DefaultDamageElement;
            }
            MinMaxFloat value = newEntry.Value;

            if (!sourceDictionary.ContainsKey(damageElement))
            {
                sourceDictionary[damageElement] = value;
            }
            else
            {
                sourceDictionary[damageElement] += value;
            }
            return(sourceDictionary);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Make damage - amount key-value pair which calculates with damage inflictions
        /// </summary>
        /// <param name="source"></param>
        /// <param name="level"></param>
        /// <param name="rate"></param>
        /// <param name="effectiveness"></param>
        /// <param name="damageInflictions"></param>
        /// <returns></returns>
        public static Dictionary <DamageElement, MinMaxFloat> MakeDamageWithInflictions(DamageIncremental source, short level, float rate, float effectiveness, Dictionary <DamageElement, float> damageInflictions)
        {
            Dictionary <DamageElement, MinMaxFloat> result = new Dictionary <DamageElement, MinMaxFloat>();
            GameInstance gameInstance = GameInstance.Singleton;
            MinMaxFloat  baseDamage   = (source.amount.GetAmount(level) * rate) + effectiveness;

            if (damageInflictions != null && damageInflictions.Count > 0)
            {
                foreach (KeyValuePair <DamageElement, float> damageInflictionAmount in damageInflictions)
                {
                    DamageElement damageElement = damageInflictionAmount.Key;
                    result = CombineDamages(result, new KeyValuePair <DamageElement, MinMaxFloat>(damageElement, baseDamage * damageInflictionAmount.Value));
                }
            }
            else
            {
                DamageElement damageElement = source.damageElement;
                if (damageElement == null)
                {
                    damageElement = gameInstance.DefaultDamageElement;
                }
                result = CombineDamages(result, new KeyValuePair <DamageElement, MinMaxFloat>(damageElement, baseDamage));
            }
            return(result);
        }
Exemplo n.º 3
0
    private float EvaluateCurve(AnimationCurve curve, MinMaxFloat minMaxContainer)
    {
        float num  = UnityEngine.Random.Range(0f - AIController.instance.settings.curveVarianceMax, AIController.instance.settings.curveVarianceMax) * (minMaxContainer.max - minMaxContainer.min);
        float num2 = Mathf.Lerp(minMaxContainer.max, minMaxContainer.min, curve.Evaluate(DifficultyFactor));

        return(minMaxContainer.ClampInside(num2 + num));
    }
Exemplo n.º 4
0
        public override void ReceiveDamage(IAttackerEntity attacker, CharacterItem weapon, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, CharacterBuff debuff, uint hitEffectsId)
        {
            if (!IsServer || IsDead())
            {
                return;
            }

            base.ReceiveDamage(attacker, weapon, allDamageAmounts, debuff, hitEffectsId);
            float calculatingTotalDamage = 0f;

            if (allDamageAmounts.Count > 0)
            {
                foreach (KeyValuePair <DamageElement, MinMaxFloat> allDamageAmount in allDamageAmounts)
                {
                    DamageElement damageElement = allDamageAmount.Key;
                    MinMaxFloat   damageAmount  = allDamageAmount.Value;
                    calculatingTotalDamage += damageAmount.Random();
                }
            }
            // Apply damages
            int totalDamage = (int)calculatingTotalDamage;

            CurrentHp -= totalDamage;

            ReceivedDamage(attacker, CombatAmountType.NormalDamage, totalDamage);

            // If current hp <= 0, character dead
            if (IsDead())
            {
                NetworkDestroy();
            }
        }
Exemplo n.º 5
0
    public static MinMaxFloat operator -(MinMaxFloat a, float amount)
    {
        var result = new MinMaxFloat();

        result.min = a.min - amount;
        result.max = a.max - amount;
        return(result);
    }
Exemplo n.º 6
0
    public static MinMaxFloat operator *(MinMaxFloat a, float multiplier)
    {
        var result = new MinMaxFloat();

        result.min = a.min * multiplier;
        result.max = a.max * multiplier;
        return(result);
    }
Exemplo n.º 7
0
    public static MinMaxFloat operator /(MinMaxFloat a, float divider)
    {
        var result = new MinMaxFloat();

        result.min = a.min / divider;
        result.max = a.max / divider;
        return(result);
    }
Exemplo n.º 8
0
    public static MinMaxFloat operator +(MinMaxFloat a, MinMaxFloat b)
    {
        var result = new MinMaxFloat();

        result.min = a.min + b.min;
        result.max = a.max + b.max;
        return(result);
    }
Exemplo n.º 9
0
    public static MinMaxFloat operator +(MinMaxFloat a, float amount)
    {
        MinMaxFloat result = new MinMaxFloat();

        result.min = a.min + amount;
        result.max = a.max + amount;
        return(result);
    }
Exemplo n.º 10
0
    public static MinMaxFloat operator -(MinMaxFloat a, MinMaxFloat b)
    {
        MinMaxFloat result = new MinMaxFloat();

        result.min = a.min - b.min;
        result.max = a.max - b.max;
        return(result);
    }
Exemplo n.º 11
0
 protected void TestImplicitCast()
 {
     MinMaxInt        minMaxInt        = prefsMinMaxInt;
     MinMaxFloat      minMaxFloat      = prefsMinMaxFloat;
     MinMaxVector2    minMaxVector2    = prefsMinMaxVector2;
     MinMaxVector3    minMaxVector3    = prefsMinMaxVector3;
     MinMaxVector4    minMaxVector4    = prefsMinMaxVector4;
     MinMaxVector2Int minMaxVector2Int = prefsMinMaxVector2Int;
     MinMaxVector3Int minMaxVector3Int = prefsMinMaxVector3Int;
 }
Exemplo n.º 12
0
 protected override void UpdateData()
 {
     if (uiTextAmount != null)
     {
         DamageElement element = Data.damageElement;
         MinMaxFloat   amount  = Data.amount;
         uiTextAmount.text = string.Format(
             LanguageManager.GetText(formatKeyAmount),
             element.Title,
             amount.min.ToString("N0"),
             amount.max.ToString("N0"));
     }
 }
Exemplo n.º 13
0
        public TreeGenerationProperties(MinMaxInt entitiesCount, MinMaxFloat distance, MinMaxFloat size,
                                        int maxTreeLevel)
        {
            if (maxTreeLevel == 0)
            {
                maxTreeLevel++;
            }

            EntitiesCount = entitiesCount;
            Distance      = distance;
            MaxTreeLevel  = maxTreeLevel;
            Size          = size;
        }
Exemplo n.º 14
0
    protected override void UpdateData()
    {
        if (Data == null || Data.Count == 0)
        {
            if (textAllInfliction != null)
            {
                textAllInfliction.gameObject.SetActive(false);
            }

            foreach (var textAmount in CacheTextInflictions)
            {
                var element = textAmount.Key;
                var format  = element == GameInstance.Singleton.DefaultDamageElement ? defaultElementInflictionFormat : inflictionFormat;
                textAmount.Value.text = string.Format(format, element.title, "0");
            }
        }
        else
        {
            var text      = "";
            var sumDamage = new MinMaxFloat();
            foreach (var dataEntry in Data)
            {
                if (dataEntry.Key == null || dataEntry.Value == 0)
                {
                    continue;
                }
                var element = dataEntry.Key;
                var rate    = dataEntry.Value;
                if (!string.IsNullOrEmpty(text))
                {
                    text += "\n";
                }
                var format     = element == GameInstance.Singleton.DefaultDamageElement ? defaultElementInflictionFormat : inflictionFormat;
                var amountText = string.Format(format, element.title, (rate * 100f).ToString("N0"));
                text += amountText;
                Text textDamages;
                if (CacheTextInflictions.TryGetValue(dataEntry.Key, out textDamages))
                {
                    textDamages.text = amountText;
                }
                sumDamage += rate;
            }

            if (textAllInfliction != null)
            {
                textAllInfliction.gameObject.SetActive(!string.IsNullOrEmpty(text));
                textAllInfliction.text = text;
            }
        }
    }
Exemplo n.º 15
0
 protected new void Start()
 {
     base.Start();
     inGarage = (base.gameObject.layer == LayerMask.NameToLayer("GarageTank") || !TankGame.instance);
     if (!inGarage)
     {
         animator.SetFloat("Speed", 0f);
         base.Rigidbody.position = new Vector2(base.Rigidbody.position.x, TankGame.instance.GetGroundHeight(base.Rigidbody.position.x) + centerOffset.y);
         moveBoundaries          = new MinMaxFloat(TankGame.instance.backBlockerContainer.position.x, PlayerDataManager.IsSelectedGameModePvP ? TankGame.instance.frontBlockerContainer.position.x : float.PositiveInfinity);
         activeCollisions        = new Dictionary <TankContainer, float>();
         FixedUpdate();
         chassis.rotation = Quaternion.Euler(0f, chassis.rotation.eulerAngles.y, chassisRotationTarget);
         StartCoroutine(ChassisRotationRoutine());
     }
 }
Exemplo n.º 16
0
        public static MinMaxFloat GetSumDamages(Dictionary <DamageElement, MinMaxFloat> damages)
        {
            var damageAmount = new MinMaxFloat();

            damageAmount.min = 0;
            damageAmount.max = 0;
            if (damages == null || damages.Count == 0)
            {
                return(damageAmount);
            }
            foreach (var damage in damages)
            {
                damageAmount += damage.Value;
            }
            return(damageAmount);
        }
Exemplo n.º 17
0
    public static Vector3 RandomPointOnCircle(MinMaxFloat distanceFromCenter)
    {
        int maximumTries = 10;

        for (int i = 0; i < maximumTries; i++)
        {
            Vector2 point = Random.insideUnitCircle * distanceFromCenter.max;

            if (point.magnitude > distanceFromCenter.min)
            {
                return(new Vector3(point.x, 0.0f, point.y));
            }
        }

        return(Vector3.zero);
    }
        public override void GetAttackingData(
            ref bool isLeftHand,
            out AnimActionType animActionType,
            out int dataId,
            out int animationIndex,
            out CharacterItem weapon,
            out float triggerDuration,
            out float totalDuration,
            out DamageInfo damageInfo,
            out Dictionary <DamageElement, MinMaxFloat> allDamageAmounts)
        {
            // Initialize data
            isLeftHand     = false;
            animActionType = AnimActionType.AttackRightHand;

            // Monster will not have weapon type so set dataId to `0`, then random attack animation from default attack animtions
            dataId = 0;

            // Monster will not have weapon data
            weapon = null;

            // Random attack animation
            CharacterModel.GetRandomRightHandAttackAnimation(dataId, out animationIndex, out triggerDuration, out totalDuration);

            // Assign damage data
            damageInfo = monsterCharacter.damageInfo;

            // Assign damage amounts
            allDamageAmounts = new Dictionary <DamageElement, MinMaxFloat>();
            DamageElement damageElement = monsterCharacter.damageAmount.damageElement;
            MinMaxFloat   damageAmount  = monsterCharacter.damageAmount.amount.GetAmount(Level);

            if (damageElement == null)
            {
                damageElement = gameInstance.DefaultDamageElement;
            }
            allDamageAmounts.Add(damageElement, damageAmount);
        }
Exemplo n.º 19
0
    void Start()
    {
        if (!_audioSource)
        {
            _audioSource = GetComponent <AudioSource>();
        }
        if (_audioClip)
        {
            _audioSource.clip = _audioClip;
        }

        //Warn if settings results in a clip that will want to play more often than the clip length allows for
        MinMaxFloat clipLenght = new MinMaxFloat(CalculateClipLength(_rangeOfPitch.Min), CalculateClipLength(_rangeOfPitch.Max));
        MinMaxFloat clipDelay  = new MinMaxFloat(BPMToDelay(_rangeOfBPM.Min), BPMToDelay(_rangeOfBPM.Max));

        if (clipDelay.Min < clipLenght.Min)
        {
            Debug.LogWarning("Shortest clip length is longer than the shortest delay! Shortest Clip Length: " + clipLenght.Min + " Shortest Delay: " + clipDelay.Min);
        }
        if (clipDelay.Max < clipLenght.Max)
        {
            Debug.LogWarning("Longest clip length is longer than the longest delay! Longest Clip Length: " + clipLenght.Min + " Longest Delay: " + clipDelay.Min);
        }
    }
Exemplo n.º 20
0
        protected override void UpdateData()
        {
            cacheStats           = showStatsWithBuffs ? Data.GetStats() : Data.GetStats(true, false);
            cacheAttributes      = showAttributeWithBuffs ? Data.GetAttributes() : Data.GetAttributes(true, false);
            cacheResistances     = showResistanceWithBuffs ? Data.GetResistances() : Data.GetResistances(true, false);
            cacheIncreaseDamages = showDamageWithBuffs ? Data.GetIncreaseDamages() : Data.GetIncreaseDamages(true, false);
            cacheWeightLimit     = cacheStats.weightLimit;
            if (!showStatsWithBuffs)
            {
                // Always increase weight limit by buff bonus because it should always show real weight limit in UIs
                cacheWeightLimit += Data.GetBuffStats().weightLimit;
            }

            if (bonusAttributes == null)
            {
                bonusAttributes = new Dictionary <Attribute, short>();
            }
            if (bonusResistances == null)
            {
                bonusResistances = new Dictionary <DamageElement, float>();
            }
            if (bonusIncreaseDamages == null)
            {
                bonusIncreaseDamages = new Dictionary <DamageElement, MinMaxFloat>();
            }
            if (bonusSkills == null)
            {
                bonusSkills = new Dictionary <Skill, short>();
            }
            if (cacheEquipmentSets == null)
            {
                cacheEquipmentSets = new Dictionary <EquipmentSet, int>();
            }

            Data.GetEquipmentSetBonus(out bonusStats, bonusAttributes, bonusResistances, bonusIncreaseDamages, bonusSkills, cacheEquipmentSets);
            // Increase stats by equipment set bonus
            cacheStats          += bonusStats;
            cacheAttributes      = GameDataHelpers.CombineAttributes(cacheAttributes, bonusAttributes);
            cacheResistances     = GameDataHelpers.CombineResistances(cacheResistances, bonusResistances);
            cacheIncreaseDamages = GameDataHelpers.CombineDamages(cacheIncreaseDamages, bonusIncreaseDamages);
            cacheWeightLimit    += bonusStats.weightLimit;

            if (uiTextWeightLimit != null)
            {
                uiTextWeightLimit.text = string.Format(
                    LanguageManager.GetText(formatKeyWeightLimitStats),
                    GameInstance.Singleton.GameplayRule.GetTotalWeight(Data).ToString("N2"),
                    cacheWeightLimit.ToString("N2"));
            }

            CharacterItem rightHandItem   = Data.EquipWeapons.rightHand;
            CharacterItem leftHandItem    = Data.EquipWeapons.leftHand;
            Item          rightHandWeapon = rightHandItem.GetWeaponItem();
            Item          leftHandWeapon  = leftHandItem.GetWeaponItem();
            Dictionary <DamageElement, MinMaxFloat> rightHandDamages = rightHandWeapon != null?GameDataHelpers.CombineDamages(cacheIncreaseDamages, rightHandWeapon.GetDamageAmount(rightHandItem.level, rightHandItem.GetEquipmentBonusRate(), Data)) : null;

            Dictionary <DamageElement, MinMaxFloat> leftHandDamages = leftHandWeapon != null?GameDataHelpers.CombineDamages(cacheIncreaseDamages, leftHandWeapon.GetDamageAmount(leftHandItem.level, leftHandItem.GetEquipmentBonusRate(), Data)) : null;

            if (uiTextWeaponDamages != null)
            {
                string textDamages = "";
                if (rightHandWeapon != null)
                {
                    MinMaxFloat sumDamages = GameDataHelpers.GetSumDamages(rightHandDamages);
                    if (!string.IsNullOrEmpty(textDamages))
                    {
                        textDamages += "\n";
                    }
                    textDamages += string.Format(
                        LanguageManager.GetText(formatKeyWeaponDamage),
                        sumDamages.min.ToString("N0"),
                        sumDamages.max.ToString("N0"));
                }
                if (leftHandWeapon != null)
                {
                    MinMaxFloat sumDamages = GameDataHelpers.GetSumDamages(leftHandDamages);
                    if (!string.IsNullOrEmpty(textDamages))
                    {
                        textDamages += "\n";
                    }
                    textDamages += string.Format(
                        LanguageManager.GetText(formatKeyWeaponDamage),
                        sumDamages.min.ToString("N0"),
                        sumDamages.max.ToString("N0"));
                }
                if (rightHandWeapon == null && leftHandWeapon == null)
                {
                    Item defaultWeaponItem = GameInstance.Singleton.DefaultWeaponItem;
                    WeaponItemEquipType defaultWeaponItemType = defaultWeaponItem.EquipType;
                    KeyValuePair <DamageElement, MinMaxFloat> damageAmount = defaultWeaponItem.GetDamageAmount(1, 1f, Data);
                    textDamages = string.Format(
                        LanguageManager.GetText(formatKeyWeaponDamage),
                        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 = cacheStats;
            }

            if (uiCharacterResistances != null)
            {
                uiCharacterResistances.Data = cacheResistances;
            }

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

            if (uiCharacterBuffs != null)
            {
                uiCharacterBuffs.UpdateData(Data);
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Add another MinMax variable's values to this one
 /// </summary>
 /// <param name="newMinMax"></param>
 public virtual void Remove(MinMaxFloat newMinMax)
 {
     max   += newMinMax.max;
     value += newMinMax.value;
 }
        public static ChunkData GenerateChunkData(Vector2 startPoint, Vector2 chunkCoord, WorldSettings worldSettings)
        {
            int    width  = worldSettings.meshSettings.numVertsPerLine;
            int    height = worldSettings.meshSettings.numVertsPerLine;
            int    extraBorderSize;
            Region biomeMap       = GetBiomeMap(chunkCoord, worldSettings, out extraBorderSize);
            Region worldHeightMap = worldSettings.globalHeightMapSettings == null ? new Region(new float[width, height], 0, 0) : RegionGenerator.GenerateRegion(width, height, worldSettings.globalHeightMapSettings, startPoint);

            float[,] combinedHeightMap = new float[width, height];
            List <int>  activeBiomes       = new List <int>();
            MinMaxFloat minMax             = new MinMaxFloat();
            Material    material           = null;
            float       worldEdgeSmoothing = worldSettings.globalBiomeSettings.heightMapEdgeSmoothing;

            // Add global world height
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    combinedHeightMap[x, y] += worldHeightMap.values[x, y];
                }
            }
            //string debug = "";

            // Add biome height
            foreach (BiomeSettings biome in worldSettings.biomes)
            {
                // @TODO: apply masking to materials/texturing, too (one material/shader for entire world?)
                if (material == null)
                {
                    material = biome.TerrainMaterial;
                }

                Region heightMap = RegionGenerator.GenerateRegion(width, height, biome.heightSettings, startPoint);

                /*
                 * if (Mathf.Approximately(biome.worldMapBiomeValue, 0f) && startPoint.x >= -150 && startPoint.x <= -50 && startPoint.y >= -150 && startPoint.y <= -50)
                 * {
                 *  debug = "chunkPosition" + startPoint + " ";
                 * }
                 */

                float[,] biomeBlurMask = CalculateBlurredBiomeMask(biomeMap.values, width, height, biome.worldMapBiomeValue, worldEdgeSmoothing * biome.heightMapEdgeSmoothingModifier);//, debug);


                minMax.AddValue(heightMap.minValue + worldHeightMap.minValue);
                minMax.AddValue(heightMap.maxValue + worldHeightMap.maxValue);
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        float biomeBlurValue = biomeBlurMask[x, y];
                        if (biomeBlurValue <= 0)
                        {
                            continue;
                        }
                        activeBiomes.Add(biome.id);
                        combinedHeightMap[x, y] += heightMap.values[x, y] * biomeBlurValue;
                    }
                }
            }

            return(new ChunkData
            {
                heightMap = new Region(combinedHeightMap, minMax.Min, minMax.Max),
                material = material
            });
        }
 public bool GetCueInfo(out float duration, out int repeats)
 {
     duration = GetDuration();
     repeats  = repeat.forever ? -1 : repeat.count;
     return(duration > Mathf.Epsilon);
 }
Exemplo n.º 24
0
 public DamageElementAmountTuple(DamageElement damageElement, MinMaxFloat amount)
 {
     this.damageElement = damageElement;
     this.amount        = amount;
 }
Exemplo n.º 25
0
    public static bool CheckAllowedSlope(MinMaxFloat allowedAngles, Vector2 surfaceNormal)
    {
        float angle = Mathf.Atan2(surfaceNormal.y, surfaceNormal.x) * Mathf.Rad2Deg - 90f;

        return(angle >= allowedAngles.Min && angle <= allowedAngles.Max);
    }
Exemplo n.º 26
0
 public virtual void MatchValues(MinMaxFloat newMinMax)
 {
     min   = (int)newMinMax.min;
     max   = (int)newMinMax.max;
     value = (int)newMinMax.value;
 }
Exemplo n.º 27
0
 public DamageStat(DamageType type, MinMaxInt damage, MinMaxFloat modifier) : this(type, damage)
 {
     this.modifier = modifier;
 }