コード例 #1
0
        static bool Prefix(UnitAttack __instance, AttackHandInfo attack)
        {
            var combatManeuver = Rulebook.Trigger(new RuleCheckCombatManeuverReplaceAttack(__instance.Executor, __instance.Target, attack)).Result;

            if (combatManeuver == CombatManeuver.None)
            {
                return(true);
            }


            var lastAttackRule = new RuleAttackWithWeapon(__instance.Executor, __instance.Target, attack.Weapon, attack.AttackBonusPenalty)
            {
                IsRend        = __instance.IsRend(__instance.PlannedAttack),
                IsFirstAttack = (attack.AttackNumber == 0),
                IsFullAttack  = __instance.IsFullAttack,
                IsCharge      = __instance.IsCharge,
                AttackNumber  = attack.AttackNumber,
                AttacksCount  = ((List <AttackHandInfo>)unitattack_get_m_AllAttacks(__instance)).Count
            };

            unitattack_set_LastAttackRule(__instance, lastAttackRule);

            attack.Target = __instance.Target;
            attack.IsHit  = __instance.Executor.TriggerAttackReplacementCombatManeuver(__instance.Target, attack.Weapon, attack.AttackBonusPenalty, combatManeuver);

            return(false);
        }
コード例 #2
0
        static bool Prefix(RuleCheckCastingDefensively __instance, RulebookEventContext context)
        {
            if (__instance.Spell.Blueprint.GetComponent <AbilityKineticist>() == null)
            {
                return(true);
            }
            var kineticist_part = __instance.Initiator.Get <UnitPartKineticist>();

            if (kineticist_part == null)
            {
                return(true);
            }

            var tr             = Harmony12.Traverse.Create(__instance);
            var rule           = Rulebook.Trigger <RuleCalculateAbilityParams>(new RuleCalculateAbilityParams(__instance.Initiator, __instance.Spell));
            var ability_params = rule.Result;

            tr.Property("DC").SetValue(15 + ability_params.SpellLevel * 2);

            var bonus_concentration = Helpers.GetField <int>(rule, "m_BonusConcentration");

            tr.Property("Concentration").SetValue(bonus_concentration + kineticist_part.ClassLevel + kineticist_part.MainStatBonus);
            tr.Property("ResultRollRaw").SetValue(RulebookEvent.Dice.D20);
            return(false);
        }
コード例 #3
0
 public override void RunAction()
 {
     try
     {
         //Log.Append($"{GetType().Name}.RunAction()");
         var context = Buff.Context.SourceAbilityContext;
         var ability = context.Ability;
         //Log.Append($"  ability {ability} caster {context.Caster.CharacterName} fact {ability.Fact}");
         //Log.Append($"  spellbook {ability.Spellbook?.Blueprint} main target {context.MainTarget}");
         //Log.Flush();
         var spellData = new AbilityData(Spell, context.Caster.Descriptor, ability.Fact, ability.Spellbook?.Blueprint);
         spellData.OverrideSpellLevel = Context.Params.SpellLevel;
         var castSpell = new RuleCastSpell(spellData, context.MainTarget);
         // Disable spell failure: we already cast the spell.
         castSpell.IsCutscene = true;
         castSpell            = Rulebook.Trigger(castSpell);
         if (IsInstant)
         {
             castSpell.ExecutionProcess.InstantDeliver();
         }
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
 }
コード例 #4
0
        public static void ApplyInstantRest(UnitEntityData unitEntityData)
        {
            if (unitEntityData.Descriptor.State.IsFinallyDead)
            {
                unitEntityData.Descriptor.Resurrect();
                unitEntityData.Position = Game.Instance.Player.MainCharacter.Value.Position;
            }

            RestController.RemoveNegativeEffects(unitEntityData.Descriptor);
            RestController.ApplyRest(unitEntityData.Descriptor);
            Rulebook.Trigger(new RuleHealDamage(unitEntityData, unitEntityData, new DiceFormula(),
                                                unitEntityData.Descriptor.Stats.HitPoints.ModifiedValue));
            foreach (var attribute in StatTypeHelper.Attributes)
            {
                Rulebook.Trigger(new RuleHealStatDamage(unitEntityData, unitEntityData, attribute));
            }

            foreach (var attribute in unitEntityData.Stats.Attributes)
            {
                attribute.Damage = 0;
                attribute.Drain  = 0;
            }

            RestoreAllItemCharges();
        }
コード例 #5
0
        public override void OnEventAboutToTrigger(RuleHealDamage evt)
        {
            var context = Helpers.GetMechanicsContext()?.SourceAbilityContext;
            var spell   = context?.SourceAbility;

            // According to the ability description, it must be from a healing spell
            // (not a supernatural ability like Energy Body, Channel Energy, etc.)
            Log.Append($"Spirit Boost: spell {spell?.name}, type {spell?.Type}, descriptor {spell.SpellDescriptor}");

            if (spell != null && spell.Type == AbilityType.Spell && !(evt is RuleHealDamageWithOverflow) &&
                (spell.SpellDescriptor & SpellDescriptor.RestoreHP) != 0)
            {
                // Disable the original heal roll.
                // We need to simulate it so we can get the temporary HP amount.
                evt.Modifier = 0;

                // Trigger the heal and collect the overflow heal amount, if any.
                int amount = Rulebook.Trigger(new RuleHealDamageWithOverflow(evt)).OverflowHealing;
                if (amount > 0)
                {
                    var oracleLevel = Owner.Progression.GetClassLevel(OracleClass.oracle);
                    amount = Math.Min(amount, oracleLevel);

                    context[HitPointValueToUpdate] = amount;
                    var duration = oracleLevel.Rounds().Seconds;
                    Log.Write($"Spirit Boost: apply {amount} temporary HP to {evt.Target.CharacterName} for {duration}, spell was {spell.name}");
                    evt.Target.Buffs.AddBuff(HitPointBuff, context, duration);
                }
            }
        }
コード例 #6
0
        public List <Discipline> ReadXmlDisciplines()
        {
            var file     = UtilityHelper.ReadStreamFromFile("OldRulebook.data");
            var rulebook = new Rulebook();

            var serializer = new XmlSerializer(rulebook.GetType());

            rulebook = (Rulebook)serializer.Deserialize(file);

            foreach (var rulebookDiscipline in rulebook.Disciplines)
            {
                var glossarySection = rulebookDiscipline.Chapters.SelectMany(o => o.Sections)
                                      .First(o => o.Name == "Glossary");

                var glossary = rulebookDiscipline.GlossaryList;

                foreach (var glossaryItem in glossary)
                {
                    glossarySection.Rules.Add(new Rule()
                    {
                        RuleId       = glossaryItem.GlossaryId,
                        Name         = glossaryItem.Name,
                        Description  = glossaryItem.Definition,
                        DisciplineId = rulebookDiscipline.DisciplineId
                    });
                }
            }

            return(rulebook.Disciplines);
        }
        public override void RunAction()
        {
            var target    = this.Target.Unit;
            var initiator = this.Context.MaybeCaster;

            if (!InspectUnitsHelper.IsInspectAllow(target))
            {
                return;
            }


            BlueprintUnit blueprintForInspection = target.Descriptor.BlueprintForInspection;

            InspectUnitsManager.UnitInfo info = Game.Instance.Player.InspectUnitsManager.GetInfo(blueprintForInspection);
            StatType statType = !(bool)((UnityEngine.Object)info.Blueprint.Type) ? StatType.SkillLoreNature : info.Blueprint.Type.KnowledgeStat;


            if (info == null)
            {
                return;
            }

            ModifiableValueSkill stat = initiator.Stats.GetStat <ModifiableValueSkill>(statType);
            int?nullable1;
            int?nullable2;

            if (stat == null)
            {
                nullable1 = new int?();
                nullable2 = nullable1;
            }
            else
            {
                nullable2 = new int?(stat.BaseValue);
            }
            nullable1 = nullable2;

            int dc    = info.DC;
            int bonus = value.Calculate(this.Context);

            if ((!nullable1.HasValue ? 0 : nullable1.Value) > 0 || (bool)initiator.Descriptor.State.Features.MakeKnowledgeCheckUntrained)
            {
                var skill_check = new RuleSkillCheck(initiator, statType, dc);
                skill_check.AddTemporaryModifier(initiator.Stats.GetStat(statType).AddModifier(bonus, null, descriptor));
                skill_check.IgnoreDifficultyBonusToDC = true;
                int rollResult = Rulebook.Trigger <RuleSkillCheck>(skill_check).RollResult;
                Common.AddBattleLogMessage($"{initiator.CharacterName} DC {dc} monster lore check: {rollResult}");

                if (dc <= rollResult && action_on_success != null)
                {
                    action_on_success.Run();
                }
                if (info.KnownPartsCount < 4)
                {
                    info.SetCheck(rollResult, initiator);
                    EventBus.RaiseEvent <IKnowledgeHandler>((Action <IKnowledgeHandler>)(h => h.HandleKnowledgeUpdated(info)));
                }
            }
        }
コード例 #8
0
            private void applySpell(SpellSlot spell_slot, AbilityExecutionContext context, TargetWrapper target)
            {
                var spell = getSpellOrVariant(spell_slot.Spell);

                spendSpellSlot(spell_slot);
                spell.SpendMaterialComponent();
                Rulebook.Trigger <RuleCastSpell>(new RuleCastSpell(spell, target));
            }
コード例 #9
0
 static bool Prefix(UnitBody __instance)
 {
     __instance.Owner.Unit.SetFreeEquipmentChange(Rulebook.Trigger(new RuleCheckFreeActionEquip(__instance.Owner.Unit)
     {
         IsHandsEquipmentSetChange = true
     }).IsFreeAction);
     return(true);
 }
コード例 #10
0
    void Start()
    {
        pm       = GameObject.Find("PlayerManager").GetComponent <PlayerManager>();
        rulebook = GameObject.Find("DifficultyManager").GetComponent <Rulebook>();

        playerlvl = pm.getPlayerLevel();
        playerExp = pm.getPlayerExperiencePoints();
    }
コード例 #11
0
 public void releaseSpellOnTarget(TargetWrapper target)
 {
     if (spell != null && (spell.CanTarget(target) || ignore_target_checkers))
     {
         Rulebook.Trigger <RuleCastSpell>(new RuleCastSpell(spell, target));
         Common.AddBattleLogMessage($"{this.Owner.CharacterName} released {spell.Blueprint.Name} from {this.Fact.Name}.");
         spell = null;
     }
 }
コード例 #12
0
        public void OnEventDidTrigger(RuleDealDamage evt)
        {
            var spell = Buff.Context.SourceAbilityContext?.Ability;

            if (spell != null && !Rulebook.Trigger(new RuleCheckConcentration(evt.Target, spell, evt)).Success)
            {
                RemoveBuff();
            }
        }
コード例 #13
0
 private void Awake()
 {
     // get the GameManager script component
     em       = GameObject.Find("EnemyManager").GetComponent <EnemyManager>();
     player   = GameObject.FindGameObjectWithTag("Player");
     pl       = GameObject.Find("PlayerManager").GetComponent <PlayerLevel>();
     rulebook = GameObject.Find("DifficultyManager").GetComponent <Rulebook>();
     ws       = GameObject.Find("DifficultyManager").GetComponent <WeightSystem>();
 }
コード例 #14
0
        public Rulebook ConfigureRulebooks()
        {
            var rulebook = new Rulebook();

            // Load Rulebook.data file
            var xmlReader = new XmlReader();

            _allDisciplines = xmlReader.ReadXmlDisciplines();
            _allSections    = _allDisciplines.SelectMany(o => o.Chapters).SelectMany(o => o.Sections).ToList();
            _allRules       = _allSections.SelectMany(o => o.Rules).ToList();
            _allSubRules    = _allRules.SelectMany(o => o.SubRules).ToList();

            // Load New Properties
            foreach (var discipline in _allDisciplines)
            {
                Console.WriteLine($"{discipline.Name} has started compiling...");
                // Add Glossaries (DisciplineId needs populating)
                discipline.GlossaryList.ForEach(o => o.DisciplineId = discipline.DisciplineId);
                _allGlossaries.AddRange(discipline.GlossaryList);

                foreach (var chapter in discipline.Chapters)
                {
                    Console.WriteLine($"--{chapter.Name} has started compiling...");

                    foreach (var section in chapter.Sections)
                    {
                        Console.WriteLine($"-- >>{section.Name} has started compiling...");

                        section.SearchableString = UtilityHelper.CreateSearchableString(section);

                        foreach (var rule in section.Rules)
                        {
                            rule.SearchableString = UtilityHelper.CreateSearchableString(rule);

                            rule.SpanList = CreateSpanList(rule.Description, rule.DisciplineId);

                            foreach (var subRule in rule.SubRules)
                            {
                                subRule.SearchableString = UtilityHelper.CreateSearchableString(subRule);

                                subRule.SpanList = CreateSpanList(subRule.Description, rule.DisciplineId);
                            }
                        }

                        Console.WriteLine($"-- >>{section.Name} has finished compiling...");
                    }

                    Console.WriteLine($"--{chapter.Name} has finished compiling...");
                }

                Console.WriteLine($"{discipline.Name} has finished compiling...");
            }

            rulebook.Disciplines = _allDisciplines;

            return(rulebook);
        }
コード例 #15
0
        static bool Prefix(RulePartySkillCheck __instance, bool isTrigger, ref int ___m_D20, ref int ___m_StatValue, StatType ___m_StatType, int ___m_DifficultyClass)
        {
            ___m_StatValue = int.MinValue;
            var tr = Harmony12.Traverse.Create(__instance);

            tr.Property("Roller").SetValue(null);
            RuleSkillCheck selected_evt = null;

            foreach (UnitEntityData unitEntityData in Game.Instance.Player.Party)
            {
                if (unitEntityData.Descriptor.State.CanAct)
                {
                    ModifiableValue stat = unitEntityData.Stats.GetStat(___m_StatType);
                    ModifiableValueAttributeStat valueAttributeStat = stat as ModifiableValueAttributeStat;
                    int            num = valueAttributeStat != null ? valueAttributeStat.Bonus : stat.ModifiedValue;
                    RuleSkillCheck evt = new RuleSkillCheck(unitEntityData, ___m_StatType, ___m_DifficultyClass)
                    {
                        Voice         = __instance.Voice,
                        EnsureSuccess = __instance.EnsureSuccess
                    };

                    if (isTrigger)
                    {
                        evt.Silent = true;;
                        Rulebook.Trigger <RuleSkillCheck>(evt);
                        num += (int)evt.Bonus;
                    }

                    if (___m_StatValue < num)
                    {
                        ___m_StatValue = num;
                        tr.Property("Roller").SetValue(unitEntityData);
                        selected_evt = evt;
                    }
                }
            }
            if (__instance.Roller == null)
            {
                UberDebug.Log("Roller is null, in the party skillcheck", (object[])Array.Empty <object>());
            }
            else
            {
                if (!isTrigger)
                {
                    selected_evt.Calculate();
                }
                else
                {
                    selected_evt.Silent = false;
                    EventBus.RaiseEvent <IRollSkillCheckHandler>((Action <IRollSkillCheckHandler>)(h => h.HandleOnRuleSkillCheck(selected_evt)));
                    //Game.Instance?.UI?.BattleLogManager?.HandleUnitSkillCheckRolled(selected_evt);
                }
                ___m_D20 = selected_evt.D20;
            }
            return(false);
        }
コード例 #16
0
        public void DoIt2()
        {
            var rulesReader    = new RulesReader();
            var glossaryReader = new GlossaryReader();
            var xmlParser      = new XmlParser();

            var rulebook = new Rulebook()
            {
                Disciplines = new List <Discipline>()
            };

            var root = AppDomain.CurrentDomain.BaseDirectory;

            string[] filenames     = { "ActionAir", "Handgun", "Shotgun", "Rifle", "MiniRifle", "PCC" };
            string[] languageNames = { "English", "Brazilian" };


            var converts   = new Dictionary <string, RulesReader.ConversionResult>();
            var glossaries = new Dictionary <string, List <Glossary> >();

            foreach (var languageName in languageNames)
            {
                var rootPath = $"{root}/{languageName}";

                if (!Directory.Exists(rootPath))
                {
                    continue;
                }

                foreach (var filename in filenames)
                {
                    if (File.Exists($"{rootPath}/{filename}.txt"))
                    {
                        converts.Add(filename, rulesReader.ConvertFromTxtFile($"{rootPath}/{filename}.txt"));
                    }

                    if (File.Exists($"{rootPath}/{filename} - Glossary.txt"))
                    {
                        glossaries.Add(filename, glossaryReader.ConvertFromTxtFile($"{rootPath}/{filename} - Glossary.txt"));
                    }
                }

                var disciplines = new List <Discipline>();

                foreach (var convert in converts)
                {
                    var glossaryList = glossaries[convert.Key];
                    disciplines.Add(rulesReader.CreateRuleChapters(convert.Value, convert.Key, glossaryList));
                }

                rulebook.Disciplines.AddRange(disciplines);
            }

            xmlParser.CreateXmlRulebook(rulebook);
        }
コード例 #17
0
        private void UpdateStateIcons()
        {
            UnitEntityData currentUnit;

            _markIsThisRound.SetActive(Unit != null && !_isCurrent && Unit.GetTimeToNextTurn() < Mod.Core.Combat.TimeToNextRound);
            _iconIsFlatFooted.SetActive(ShowIsFlatFootedIconOnUI &&
                                        Unit != null && !_isCurrent && (currentUnit = CurrentUnit()) != null &&
                                        Rulebook.Trigger(new RuleCheckTargetFlatFooted(currentUnit, Unit)).IsFlatFooted);
            _iconIsUnableToAct.SetActive(Unit != null && !Unit.IsAbleToAct());
            _iconIsSurprising.SetActive(Unit != null && !_isCurrent && Unit.IsSurprising());
        }
コード例 #18
0
        public static RulebookDTO Map(Rulebook rulebook)
        {
            var rulebookDTO = new RulebookDTO
            {
                Id          = rulebook.Id,
                Title       = rulebook.Title,
                PublishYear = rulebook.PublishYear
            };

            return(rulebookDTO);
        }
コード例 #19
0
            private void applySpell(SpellSlot spell_slot, AbilityExecutionContext context, TargetWrapper target)
            {
                var spell = getSpellOrVariant(spell_slot.Spell);

                spendSpellSlot(spell_slot);
                spell.SpendMaterialComponent();
                var rule_cast_spell = new RuleCastSpell(spell, target);

                rule_cast_spell.Context.AttackRoll = Rulebook.CurrentContext.AllEvents.LastOfType <RuleAttackWithWeapon>()?.AttackRoll;
                Rulebook.Trigger <RuleCastSpell>(rule_cast_spell);
            }
コード例 #20
0
        public override void OnEventAboutToTrigger(RuleCalculateDamage evt)
        {
            var initiator = evt.Initiator;
            var target    = evt.Target;
            var rule      = Rulebook.Trigger(new RuleCheckTargetFlatFooted(initiator, target));

            if (evt.Target.CombatState.IsFlanked || rule.IsFlatFooted)
            {
                base.Owner.Ensure <UnitPartStudiedTarget>().SetTarget(target.Descriptor);
            }
        }
コード例 #21
0
        static void Postfix(RuleCalculateCMD __instance)
        {
            //add attacker dependent ac bonuses/penalties
            var rule_ac  = new RuleCalculateAC(__instance.Initiator, __instance.Target, AttackType.Touch);
            var ac       = Rulebook.Trigger <RuleCalculateAC>(rule_ac).TargetAC;
            int delta_ac = ac - (__instance.IsTargetFlatFooted ? __instance.Target.Stats.AC.FlatFootedTouch : __instance.Target.Stats.AC.Touch);

            var tr = Harmony12.Traverse.Create(__instance);

            tr.Property("Result").SetValue(__instance.Result + delta_ac);
        }
コード例 #22
0
    public void playerTooManyDeaths_Test()
    {
        Rulebook rulebook = new Rulebook();

        Rulebook rb = rulebook;

        rb.playerDeathTimer    = 10.0f;
        rb.rulebookPlayerDeath = 5;
        Assert.Throws <NullReferenceException>(() => rb.PlayerTooManyDeaths());

        Assert.That(rb.rulebookPlayerDeath, Is.EqualTo(0));
    }
コード例 #23
0
        static RuleAttackWithWeapon performAttackOrManeuver(RuleAttackWithWeapon attack_rule)
        {
            var attack_replacement_part = attack_rule.Initiator.Get <UnitPartAttackReplacementWithAction>();

            if (attack_replacement_part != null && attack_replacement_part.maybeReplaceAttackWithAction(attack_rule))
            {
                return(attack_rule);
            }
            else
            {
                return(Rulebook.Trigger <RuleAttackWithWeapon>(attack_rule));
            }
        }
コード例 #24
0
        public override void OnTurnOn()
        {
            base.OnTurnOn();

            RuleCalculateAttacksCount calculateAttacksCount = Rulebook.Trigger <RuleCalculateAttacksCount>(new RuleCalculateAttacksCount(this.Owner.Unit)
            {
                ForceIterativeNaturealAttacks = true
            });

            this.m_MainAttacksCount      = calculateAttacksCount.PrimaryHand.MainAttacks;
            this.m_PenalizedAttacksCount = calculateAttacksCount.PrimaryHand.PenalizedAttacks;
            this.m_AttackPenalty         = 0;
        }
コード例 #25
0
    public void notEnoughEnemyDamage()
    {
        Rulebook rulebook = new Rulebook();

        Rulebook rb = rulebook;

        rb.notEnoughEnemyDamageTimer    = 30.0f;
        rb.rulebookIsPlayerNotHitEnough = 1;
        Assert.Throws <NullReferenceException>(() => rb.NotEnoughEnemyDamage());

        Assert.That(rb.notEnoughEnemyDamageTimer, Is.EqualTo(0.0f));
        Assert.That(rb.rulebookIsPlayerNotHitEnough, Is.EqualTo(0));
    }
コード例 #26
0
    public void playerKillsDeathCheck_Test()
    {
        Rulebook rulebook = new Rulebook();

        Rulebook rb = rulebook;

        rb.playerDeaths            = 0;
        rb.playerDeathCheck        = 0;
        rb.playerKillsDeathCounter = 20;
        Assert.Throws <NullReferenceException>(() => rb.PlayerKillsDeathsCheck());

        Assert.That(rb.playerKillsDeathCounter, Is.EqualTo(0));
    }
コード例 #27
0
    public void playerHitCheck()
    {
        Rulebook rulebook = new Rulebook();

        Rulebook rb = rulebook;

        rb.playerHitTimer  = 16.0f;
        rb.enemyHitPlayer  = 5;
        rb.enemyDamageHits = 5;
        Assert.Throws <NullReferenceException>(() => rb.PlayerHitCheck());

        Assert.That(rb.playerHitTimer, Is.EqualTo(0.0f));
    }
コード例 #28
0
    public void tooManyPlayerHits()
    {
        Rulebook rulebook = new Rulebook();

        Rulebook rb = rulebook;

        rb.tooManyPlayerHitsTimer = 5.0f;
        rb.isPlayerHitTooMuch     = 4;
        Assert.Throws <NullReferenceException>(() => rb.TooManyPlayerHits());

        Assert.That(rb.tooManyPlayerHitsTimer, Is.EqualTo(0.0f));
        Assert.That(rb.isPlayerHitTooMuch, Is.EqualTo(0));
    }
コード例 #29
0
 static void Postfix(UnitCombatState __instance, UnitEntityData target, ref bool __result)
 {
     if (Mod.Enabled && FixAcrobaticsMobility && __result)
     {
         if (target.Descriptor.State.HasCondition(UnitCondition.UseMobilityToNegateAttackOfOpportunity))
         {
             if (Rulebook.Trigger(new RuleSkillCheck(target, StatType.SkillMobility,
                                                     Rulebook.Trigger(new RuleCalculateCMD(target, __instance.Unit, CombatManeuver.None)).Result)).IsPassed)
             {
                 __result = false;
             }
         }
     }
 }
コード例 #30
0
        static bool Prefix(RuleCalculateAC __instance, RulebookEventContext context)
        {
            Cover cover = Rulebook.Trigger(new RuleCheckSoftCover(__instance.Initiator, __instance.Target, __instance.AttackType)).Result;

            if (cover == Cover.Full)
            {
                __instance.AddBonus(4, SoftCoverFact);
            }
            else if (cover == Cover.Partial)
            {
                __instance.AddBonus(2, SoftCoverPartialFact);
            }
            return(true);
        }