예제 #1
0
        public static int CalledShotModifier(this AbstractActor actor)
        {
            int mod = 0;

            // Calculate the pilot mod, if any
            if (actor.GetPilot() != null)
            {
                Pilot  pilot    = actor.GetPilot();
                string pilotKey = pilot.CacheKey();
                bool   hasPilot = ModState.PilotCalledShotModifiers.TryGetValue(pilot.CacheKey(), out mod);
                if (!hasPilot)
                {
                    // Calculate the modifiers for the pilot
                    Mod.Log.Info?.Write($" Calculating calledShotModifier for actor: {actor.DistinctId()}");
                    int baseMod    = Mod.Config.Combat.CalledShot.BaseModifier;
                    int tacticsMod = Mod.Config.Combat.CalledShot.EnableTacticsModifier ?
                                     (-1 * SkillUtils.GetTacticsModifier(pilot)) : 0;
                    int tagsCSMod = SkillUtils.GetTagsModifier(pilot, Mod.Config.Combat.CalledShot.PilotTags);

                    // Calculate the actor mod, if any
                    int actorMod = actor.StatCollection.GetValue <int>(ModStats.CalledShot_AttackMod);

                    int calledShotMod = baseMod + tacticsMod + tagsCSMod + actorMod;
                    Mod.Log.Info?.Write($" -- calledShotMod: {calledShotMod} = defaultMod: {baseMod} + tacticsMod: {tacticsMod} + tagsCSMod: {tagsCSMod} + actorMod: {actorMod}");

                    ModState.PilotCalledShotModifiers[pilotKey] = calledShotMod;
                }
                else
                {
                    Mod.Log.Debug?.Write($"CalledShotModifier: {mod} for actor: {actor.DistinctId()}");
                }
            }

            return(mod);
        }
        public void LegacyGetModifier_Base()
        {
            FactionValue factionValue = new FactionValue();

            factionValue.Name = "1";

            HumanDescriptionDef humanDescDef = new HumanDescriptionDef("-1", "Test", "FNAME", "LNAME", "CSIGN", Gender.Male, factionValue, 1, "foo", "");

            Traverse.Create(humanDescDef).Field("factionValue").SetValue(factionValue);
            Traverse.Create(humanDescDef).Field("factionID").SetValue("1");

            // gun, pilot, guts, tactics
            PilotDef pilotDefHigh = new PilotDef(humanDescDef, 10, 9, 8, 7, 0, 3, false, 0, "voice",
                                                 new List <string>()
            {
            }, AIPersonality.Undefined, 0, 0, 0);
            Pilot pilotHigh = new Pilot(pilotDefHigh, "-1", false);

            Assert.AreEqual(5, SkillUtils.GetGunneryModifier(pilotHigh));
            Assert.AreEqual(4, SkillUtils.GetPilotingModifier(pilotHigh));
            Assert.AreEqual(4, SkillUtils.GetGutsModifier(pilotHigh));
            Assert.AreEqual(3, SkillUtils.GetTacticsModifier(pilotHigh));

            PilotDef pilotDefMed = new PilotDef(humanDescDef, 7, 6, 5, 4, 0, 3, false, 0, "voice",
                                                new List <string>()
            {
            }, AIPersonality.Undefined, 0, 0, 0);
            Pilot pilotMed = new Pilot(pilotDefMed, "-1", false);

            Assert.AreEqual(3, SkillUtils.GetGunneryModifier(pilotMed));
            Assert.AreEqual(3, SkillUtils.GetPilotingModifier(pilotMed));
            Assert.AreEqual(2, SkillUtils.GetGutsModifier(pilotMed));
            Assert.AreEqual(2, SkillUtils.GetTacticsModifier(pilotMed));

            PilotDef pilotDefLog = new PilotDef(humanDescDef, 4, 3, 2, 1, 0, 3, false, 0, "voice",
                                                new List <string>()
            {
            }, AIPersonality.Undefined, 0, 0, 0);
            Pilot pilotLow = new Pilot(pilotDefLog, "-1", false);

            Assert.AreEqual(2, SkillUtils.GetGunneryModifier(pilotLow));
            Assert.AreEqual(1, SkillUtils.GetPilotingModifier(pilotLow));
            Assert.AreEqual(1, SkillUtils.GetGutsModifier(pilotLow));
            Assert.AreEqual(0, SkillUtils.GetTacticsModifier(pilotLow));
        }
예제 #3
0
        public static int GetCalledShotModifier(Pilot pilot)
        {
            int mod = 0;

            string pilotKey = GetPilotKey(pilot);

            if (!ModState.PilotCalledShotModifiers.ContainsKey(pilotKey))
            {
                Mod.Log.Debug($" Calculating calledShotModifier for pilot:{pilotKey}");
                int defaultMod    = Mod.Config.Combat.CalledShot.Modifier;
                int tacticsMod    = SkillUtils.GetTacticsModifier(pilot);
                int tagsCSMod     = SkillUtils.GetTagsModifier(pilot, Mod.Config.Combat.CalledShot.PilotTags);
                int calledShotMod = defaultMod + (-1 * (tacticsMod + tagsCSMod));
                Mod.Log.Debug($" Pilot:{pilotKey} has calledShotMod:{calledShotMod} = defaultMod:{defaultMod} + (-1 * (tacticsMod:{tacticsMod} + tagsCSMod:{tagsCSMod}))");
                ModState.PilotCalledShotModifiers[pilotKey] = calledShotMod;
            }
            else
            {
                mod = ModState.PilotCalledShotModifiers[pilotKey];
            }

            return(mod);
        }
예제 #4
0
        // Normal Constructor
        public EWState(AbstractActor actor)
        {
            this.actor = actor;
            // Pilot effects; cache and only read once
            tacticsMod = actor.StatCollection.GetValue <int>(ModStats.TacticsMod);
            if (tacticsMod == 0 && actor.GetPilot() != null)
            {
                tacticsMod = SkillUtils.GetTacticsModifier(actor.GetPilot());
                actor.StatCollection.Set <int>(ModStats.TacticsMod, tacticsMod);
            }

            // Ephemeral round check
            ewCheck = actor.StatCollection.GetValue <int>(ModStats.CurrentRoundEWCheck);

            // ECM
            jammedByECMMod = actor.StatCollection.GetValue <int>(ModStats.ECMJamming);

            shieldedByECMMod = actor.StatCollection.GetValue <int>(ModStats.ECMShield);

            // Sensors
            advSensorsCarrierMod = actor.StatCollection.GetValue <int>(ModStats.AdvancedSensors);

            // Probes
            probeCarrierMod = actor.StatCollection.GetValue <int>(ModStats.ProbeCarrier);

            pingedByProbeMod = actor.StatCollection.GetValue <int>(ModStats.PingedByProbe);

            // Stealth - <signature_modifier>_<details_modifier>_<mediumAttackMod>_<longAttackmod>_<extremeAttackMod>
            string rawValue = actor.StatCollection.GetValue <string>(ModStats.StealthEffect);

            if (!string.IsNullOrEmpty(rawValue))
            {
                string[] tokens = rawValue.Split('_');
                if (tokens.Length == 5)
                {
                    try {
                        stealth = new Stealth {
                            SignatureMulti        = float.Parse(tokens[0]),
                            DetailsMod            = Int32.Parse(tokens[1]),
                            MediumRangeAttackMod  = Int32.Parse(tokens[2]),
                            LongRangeAttackMod    = Int32.Parse(tokens[3]),
                            ExtremeRangeAttackMod = Int32.Parse(tokens[4])
                        };
                    } catch (Exception) {
                        Mod.Log.Info?.Write($"Failed to tokenize StealthEffect value: ({rawValue}). Discarding!");
                        stealth = null;
                    }
                }
                else
                {
                    Mod.Log.Info?.Write($"WARNING: Invalid StealthEffect value: ({rawValue}) found. Discarding!");
                }
            }

            // Mimetic - <initialVisibility>_<initialModifier>_<stepsUntilDecay>
            rawValue = actor.StatCollection.GetValue <string>(ModStats.MimeticEffect);
            if (!string.IsNullOrEmpty(rawValue))
            {
                string[] tokens = rawValue.Split('_');
                if (tokens.Length == 3)
                {
                    try {
                        mimetic = new Mimetic {
                            VisibilityMulti = float.Parse(tokens[0]),
                            AttackMod       = Int32.Parse(tokens[1]),
                            HexesUntilDecay = Int32.Parse(tokens[2]),
                        };
                    } catch (Exception) {
                        Mod.Log.Info?.Write($"Failed to tokenize Mimetic value: ({rawValue}). Discarding!");
                        mimetic = null;
                    }
                }
                else
                {
                    Mod.Log.Info?.Write($"WARNING: Invalid Mimetic value: ({rawValue}) found. Discarding!");
                }
            }

            // ZoomVision - <initialAttackModifier>_<attackModifierCap>_<hexesUntilDecay>
            rawValue = actor.StatCollection.GetValue <string>(ModStats.ZoomVision);
            if (!string.IsNullOrEmpty(rawValue))
            {
                string[] tokens = rawValue.Split('_');
                if (tokens.Length == 3)
                {
                    try {
                        zoomVision = new ZoomVision(Int32.Parse(tokens[0]), Int32.Parse(tokens[1]), Int32.Parse(tokens[2]));
                    } catch (Exception) {
                        Mod.Log.Info?.Write($"Failed to tokenize ZoomVision value: ({rawValue}). Discarding!");
                        zoomVision = null;
                    }
                }
                else
                {
                    Mod.Log.Info?.Write($"WARNING: Invalid ZoomVision value: ({rawValue}) found. Discarding!");
                }
            }

            // HeatVision - <initialAttackModifier>_<heatDivisorForStep>__<maximumRange>
            rawValue = actor.StatCollection.GetValue <string>(ModStats.HeatVision);
            if (!string.IsNullOrEmpty(rawValue))
            {
                string[] tokens = rawValue.Split('_');
                if (tokens.Length == 3)
                {
                    try {
                        heatVision = new HeatVision {
                            AttackMod    = Int32.Parse(tokens[0]),
                            HeatDivisor  = float.Parse(tokens[1]),
                            MaximumRange = Int32.Parse(tokens[2])
                        };
                    } catch (Exception) {
                        Mod.Log.Info?.Write($"Failed to tokenize HeatVision value: ({rawValue}). Discarding!");
                        heatVision = null;
                    }
                }
                else
                {
                    Mod.Log.Info?.Write($"WARNING: Invalid HeatVision value: ({rawValue}) found. Discarding!");
                }
            }


            // Narc effect - <signatureMod>_<detailsMod>_<attackMod>
            rawValue = actor.StatCollection.GetValue <string>(ModStats.NarcEffect);
            if (!string.IsNullOrEmpty(rawValue))
            {
                string[] tokens = rawValue.Split('_');
                if (tokens.Length == 3)
                {
                    try {
                        narcEffect = new NarcEffect {
                            SignatureMod = float.Parse(tokens[0]),
                            DetailsMod   = Int32.Parse(tokens[1]),
                            AttackMod    = Int32.Parse(tokens[2]),
                        };
                    } catch (Exception) {
                        Mod.Log.Info?.Write($"Failed to tokenize NarcEffect value: ({rawValue}). Discarding!");
                        stealth = null;
                    }
                }
                else
                {
                    Mod.Log.Info?.Write($"WARNING: Invalid NarcEffect value: ({rawValue}) found. Discarding!");
                }
            }


            // Tag effect - <signatureMod>_<detailsMod>_<attackMod>
            rawValue = actor.StatCollection.GetValue <string>(ModStats.TagEffect);
            if (!string.IsNullOrEmpty(rawValue))
            {
                string[] tokens = rawValue.Split('_');
                if (tokens.Length == 3)
                {
                    try {
                        tagEffect = new TagEffect {
                            SignatureMod = float.Parse(tokens[0]),
                            DetailsMod   = Int32.Parse(tokens[1]),
                            AttackMod    = Int32.Parse(tokens[2]),
                        };
                    } catch (Exception) {
                        Mod.Log.Info?.Write($"Failed to tokenize TagEffect value: ({rawValue}). Discarding!");
                        stealth = null;
                    }
                }
                else
                {
                    Mod.Log.Info?.Write($"WARNING: Invalid TagEffect value: ({rawValue}) found. Discarding!");
                }
            }

            // Vision Sharing
            sharesVision = actor.StatCollection.GetValue <bool>(ModStats.SharesVision);

            // Night Vision
            nightVision = actor.StatCollection.GetValue <bool>(ModStats.NightVision);
        }
        public void LegacyGetModifier_Abilities()
        {
            AbilityDef gutsDef8 = new AbilityDef();

            Traverse.Create(gutsDef8).Property("Description").SetValue(new BaseDescriptionDef("AbilityDefG8", "ABC", "DEF", "-1"));
            AbilityDef gutsDef5 = new AbilityDef();

            Traverse.Create(gutsDef5).Property("Description").SetValue(new BaseDescriptionDef("AbilityDefG5", "ABC", "DEF", "-1"));

            FactionValue factionValue = new FactionValue();

            factionValue.Name = "1";

            HumanDescriptionDef humanDescDef = new HumanDescriptionDef("-1", "Test", "FNAME", "LNAME", "CSIGN", Gender.Male, factionValue, 1, "foo", "");

            Traverse.Create(humanDescDef).Field("factionValue").SetValue(factionValue);
            Traverse.Create(humanDescDef).Field("factionID").SetValue("1");

            // gun, pilot, guts, tactics
            PilotDef pilotDefHigh = new PilotDef(humanDescDef, 10, 9, 8, 7, 0, 3, false, 0, "voice",
                                                 new List <string>()
            {
            }, AIPersonality.Undefined, 0, 0, 0);
            Pilot pilotHigh = new Pilot(pilotDefHigh, "-1", false);

            Traverse.Create(pilotHigh).Property("Abilities").SetValue(new List <Ability>());

            pilotHigh.Abilities.Add(new Ability(gutsDef8));
            pilotHigh.Abilities.Add(new Ability(gutsDef5));

            Assert.AreEqual(7, SkillUtils.GetGunneryModifier(pilotHigh));
            Assert.AreEqual(4, SkillUtils.GetPilotingModifier(pilotHigh));
            Assert.AreEqual(4, SkillUtils.GetGutsModifier(pilotHigh));
            Assert.AreEqual(3, SkillUtils.GetTacticsModifier(pilotHigh));

            PilotDef pilotDefMed = new PilotDef(humanDescDef, 7, 6, 5, 4, 0, 3, false, 0, "voice",
                                                new List <string>()
            {
                "AbilityDefG5"
            }, AIPersonality.Undefined, 0, 0, 0);
            Pilot pilotMed = new Pilot(pilotDefMed, "-1", false);

            Traverse.Create(pilotMed).Property("Abilities").SetValue(new List <Ability>());

            pilotMed.Abilities.Add(new Ability(gutsDef5));

            Assert.AreEqual(4, SkillUtils.GetGunneryModifier(pilotMed));
            Assert.AreEqual(3, SkillUtils.GetPilotingModifier(pilotMed));
            Assert.AreEqual(2, SkillUtils.GetGutsModifier(pilotMed));
            Assert.AreEqual(2, SkillUtils.GetTacticsModifier(pilotMed));

            PilotDef pilotDefLog = new PilotDef(humanDescDef, 4, 3, 2, 1, 0, 3, false, 0, "voice",
                                                new List <string>()
            {
            }, AIPersonality.Undefined, 0, 0, 0);
            Pilot pilotLow = new Pilot(pilotDefLog, "-1", false);

            Assert.AreEqual(2, SkillUtils.GetGunneryModifier(pilotLow));
            Assert.AreEqual(1, SkillUtils.GetPilotingModifier(pilotLow));
            Assert.AreEqual(1, SkillUtils.GetGutsModifier(pilotLow));
            Assert.AreEqual(0, SkillUtils.GetTacticsModifier(pilotLow));
        }