Esempio n. 1
0
        /// <summary>
        /// Calculate a value for the weapon verbs
        /// </summary>
        /// <param name="verb"></param>
        /// <returns></returns>
        public static float CalcVerbValue(Verb verb)
        {
            float value = 0;

            if (verb == null || verb.verbProps == null)
            {
                return(0f);
            }

            ThingDef thingDef = (verb.ownerEquipment == null ? verb.caster.def : verb.ownerEquipment.def);

            try
            {
                Verb_Shoot verbShoot = verb as Verb_Shoot;

                //if (verbShoot != null && !verb.verbProps.MeleeRange && verb.verbProps.projectileDef != null)
                if (verbShoot != null && verb.verbProps.range > 1 && verb.verbProps.projectileDef != null)
                {
                    // Gun
                    float burstCount = verb.verbProps.burstShotCount;
                    float damage     = verb.verbProps.projectileDef.projectile.damageAmountBase;
                    float cooldown   = verb.ownerEquipment == null ? (float)verb.verbProps.defaultCooldownTicks : verb.ownerEquipment.GetStatValue(StatDefOf.RangedWeapon_Cooldown, true);
                    float warmup     = GenDate.TicksToSeconds(verb.verbProps.warmupTicks);
                    float accuracy   = verb.ownerEquipment == null ? (float)verb.verbProps.accuracyMedium : verb.ownerEquipment.GetStatValue(StatDefOf.AccuracyMedium, true);
                    //verb.verbProps.accuracyMedium; //(verb.verbProps.accuracyLong + verb.verbProps.accuracyMedium + verb.verbProps.accuracyShort) / 3;

                    // calculate gun value
                    value = ((burstCount * damage) / (warmup + cooldown)) * accuracy;

                    // offset
                    value *= 3f;

                    //Log.Error("Gun: " + thingDef.defName + " " + burstCount.ToString() + " " + damage.ToString() + " " + cooldown.ToString() + " " + warmup.ToString() + " " + accuracy.ToString() + " = " + value.ToString());
                }
                else
                {
                    // Melee Weapon
                    float damage   = verb.ownerEquipment == null ? (float)verb.verbProps.meleeDamageBaseAmount : verb.ownerEquipment.GetStatValue(StatDefOf.MeleeWeapon_DamageAmount, true);
                    float cooldown = verb.ownerEquipment == null?GenDate.TicksToSeconds(verb.verbProps.defaultCooldownTicks) : verb.ownerEquipment.GetStatValue(StatDefOf.MeleeWeapon_Cooldown, true);

                    float accuracy = verb.ownerEquipment == null ? (float)verb.verbProps.accuracyTouch : verb.ownerEquipment.GetStatValue(StatDefOf.AccuracyTouch, true);
                    //verb.verbProps.accuracyTouch;

                    // calculate melee value
                    value = (damage / cooldown) * accuracy;

                    // offset
                    value *= 2f;

                    //Log.Error("Melee: " + thingDef.defName + " " + damage.ToString() + " " + cooldown.ToString() + " " + accuracy.ToString() + " = " + value.ToString());
                }
            } catch (Exception ex) {
                // Error happening? return 0
                // Some mod weapons throw an error when trying to get the GetStatValue..
                if (thingDef != null)
                {
                    Log.Warning("Couldn't calculate the weapon value of verb " + thingDef + " -> using 0. Exception:" + ex.Message + "\n" + ex.StackTrace);
                }
                else
                {
                    Log.Warning("Couldn't calculate the weapon value (thing == null) -> using 0. Exception:" + ex.Message + "\n" + ex.StackTrace);
                }

                return(0f);
            }

            value = (value > 1 ? value : 1);
            return(value);
        }