/// <summary>
        /// 下面传上来的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void DoAction(object sender, EventArgs args)
        {
            // 处理抽卡完成的事件
            if (args is CardDrewEventArgs)
            {
                var arg = args as CardDrewEventArgs;
                UberDebug.LogDebugChannel("Frontend", $"卡{arg}抽出完毕");
                if (arg.CardRID == lastDrawCardRID)
                {
                    savedCallback?.Invoke(this, null);
                    lastDrawCardRID = -1;
                    savedCallback   = null;
                }
            }

            // 预览随从
            if (args is RetinuePreview)
            {
                servantPreviewInsert((args as RetinuePreview).Position);
            }

            if (args is IPlayerEventArgs)
            {
                (args as IPlayerEventArgs).PlayerID = SelfID;
                OnDeckAction?.Invoke(sender, args);
            }
        }
Ejemplo n.º 2
0
        public bool mod_CanBuild(BlueprintSettlementBuilding building)
        {
            if (!KingmakerPatchSettings.CurrencyFallback.Enabled)
            {
                return(this.source_CanBuild(building));
            }

            if (!KingdomCurrencyFallback.CanSpend(this.GetActualCost(building)))
            {
                UberDebug.LogSystem("[fireundubh] mod_CanBuild: Cannot spend");
                return(false);
            }

            SpecialSlotType specialSlot = building.SpecialSlot;

            if (specialSlot != SpecialSlotType.None)
            {
                if (this.IsSpecialSlotFilled(specialSlot))
                {
                    return(false);
                }
            }
            else if (this.alias_m_SlotsLeft < building.SlotCount)
            {
                return(false);
            }

            return(this.alias_CanBuildByLevel(building));
        }
Ejemplo n.º 3
0
        // Similar to `metamagic.DefaultCost()`, but returns the result before Bag of Tricks
        // modifies it to 0.
        public static int OriginalCost(this Metamagic metamagic)
        {
            // Inline this so Bag of Tricks can't mutate it.
            switch (metamagic)
            {
            case Metamagic.Empower:
                return(2);

            case Metamagic.Maximize:
                return(3);

            case Metamagic.Quicken:
                return(4);

            case Metamagic.Extend:
                return(1);

            case Metamagic.Heighten:
                return(0);

            case Metamagic.Reach:
                return(1);
            }
            UberDebug.LogError($"Unknown metamagic: {metamagic}");
            return(0);
        }
Ejemplo n.º 4
0
        public SettlementBuilding mod_UpgradeBuilding(SettlementBuilding building)
        {
            if (!KingmakerPatchSettings.CurrencyFallback.Enabled)
            {
                return(this.source_UpgradeBuilding(building));
            }

            if (!building.IsFinished || !this.alias_m_Buildings.HasFact(building) || !building.Blueprint.UpgradesTo)
            {
                return(null);
            }

            if (!KingdomCurrencyFallback.CanSpend(this.GetActualCost(building.Blueprint.UpgradesTo)))
            {
                UberDebug.LogWarning("Cannot upgrade " + building.Blueprint + ": not enough BP");
                return(null);
            }

            KingdomCurrencyFallback.SpendPoints(this.GetActualCost(building.Blueprint));

            SettlementBuilding result = this.alias_m_Buildings.Upgrade(building);

            this.Update();

            EventBus.RaiseEvent((ISettlementBuildUpdate h) => h.OnBuildUpdate(building));

            return(result);
        }
Ejemplo n.º 5
0
        void onSortMethodChange(int id)
        {
            UberDebug.Log($"Sort method change: {id}");
            sortMethod = (SortMethod)id;

            onSortChange?.Invoke();
        }
Ejemplo n.º 6
0
 public void log(string channel, string msg)
 {
     if (!enable)
     {
         return;
     }
     if (blackList.Contains(channel))
     {
         return;
     }
     if (channel == "Debug")
     {
         UberDebug.Log((string.IsNullOrEmpty(name) ? null : (name + ":")) + msg);
     }
     else if (channel == "Warning")
     {
         UberDebug.LogWarning((string.IsNullOrEmpty(name) ? null : (name + ":")) + msg);
     }
     else if (channel == "Error")
     {
         UberDebug.LogError((string.IsNullOrEmpty(name) ? null : (name + ":")) + msg);
     }
     else
     {
         UberDebug.LogChannel(channel, (string.IsNullOrEmpty(name) ? null : (name + ":")) + msg);
     }
 }
Ejemplo n.º 7
0
 public override void RunAction()
 {
     if (this.Target.Unit == null || this.Context.MaybeCaster == null)
     {
         UberDebug.LogError((object)"Target unit is missing", (object[])Array.Empty <object>());
     }
     else
     {
         int value = this.Target.Unit.Ensure <UnitPartSeedStorage>().getRandom(1, 100);
         if (this.Target.Unit.IsInCombat && in_combat_bonus != null)
         {
             value += in_combat_bonus.Calculate(this.Context);
         }
         //Main.logger.Log("Rolled: " + value.ToString());
         Common.AddBattleLogMessage(this.Target.Unit.CharacterName + " rolls " + value.ToString() + " on d100 for " + this.Context.Name);
         for (int i = 0; i < actions.Length; i++)
         {
             if (thresholds[i] >= value)
             {
                 if (actions[i] != null)
                 {
                     actions[i].Run();
                 }
                 return;
             }
         }
     }
 }
 public override void RunAction()
 {
     if (this.Context.MaybeCaster == null)
     {
         UberDebug.LogError((object)"Caster unit is missing", (object[])Array.Empty <object>());
     }
     else
     {
         int num = bonus.Calculate(this.Context);
         var rule_skill_check = new RuleSkillCheck(this.Context.MaybeCaster, this.Stat, this.UseCustomDC ? this.CustomDC.Calculate(this.Context) : ((this.Target.Unit?.Descriptor?.Progression.CharacterLevel).GetValueOrDefault() + 10));
         rule_skill_check.ShowAnyway = true;
         if (num != 0)
         {
             rule_skill_check.Bonus.AddModifier(num, null, Kingmaker.Enums.ModifierDescriptor.UntypedStackable);
         }
         if (this.Context.TriggerRule <RuleSkillCheck>(rule_skill_check).IsPassed)
         {
             this.Success.Run();
         }
         else
         {
             this.Failure.Run();
         }
     }
 }
Ejemplo n.º 9
0
        private async void Answers_onRequest(IRequest request)
        {
            if (game.answers == null)
            {
                return;
            }
            await Task.Delay(1000);

            switch (request)
            {
            case InitReplaceRequest _:
                _ = game.answers.answer(player.id, new InitReplaceResponse()
                {
                    cardsId = new int[0]
                });
                break;

            case FreeActRequest _:
                _ = game.answers.answer(player.id, calcNextAction(game, player));
                break;

            default:
                UberDebug.LogChannel("AI", "AI未处理的询问:" + request);
                break;
            }
        }
        public void Commit()
        {
            if (this.AutoCommit)
            {
                UberDebug.LogWarning("Trying to commit LevelUp with AutoCommit", Array.Empty <object>());
                return;
            }
            this.Preview.Unit.Dispose();

            var UnitPartImportableCompanionType = Type.GetType("Kingmaker.Dungeon.Units.UnitPartImportableCompanion, Assembly-CSharp");
            var unitPartImportableCompanion     = GetUnitPart(UnitPartImportableCompanionType, this.Unit);

            if (unitPartImportableCompanion != null)
            {
                var levels = (List <LevelPlanData>)AccessTools.Field(UnitPartImportableCompanionType, "Levels").GetValue(unitPartImportableCompanion);
                levels.Add(this.GetPlan());
            }
            this.ApplyLevelup(this.Unit);
            this.Unit.Unit.View.UpdateClassEquipment();
            LevelUpPreviewThread.Stop();
            if (this.State.IsFirstLevel)
            {
                this.SetupNewCharacher();
            }
            if (this.m_PlanChanged && !this.State.IsFirstLevel)
            {
                this.Unit.Progression.DropLevelPlans();
            }
            if (this.m_OnSuccess != null)
            {
                this.m_OnSuccess();
            }
        }
        public override string GetUIText()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if ((UnityEngine.Object) this.evolution == (UnityEngine.Object)null)
            {
                UberDebug.LogError((object)("Empty Feature field in prerequisite component: " + this.name), (object[])Array.Empty <object>());
            }
            else
            {
                if (string.IsNullOrEmpty(this.evolution.Name))
                {
                    UberDebug.LogError((object)string.Format("{0} has no Display Name", (object)this.evolution.name), (object[])Array.Empty <object>());
                }
                stringBuilder.Append(this.evolution.Name);
            }
            if (!not)
            {
                return("Has Personal Evolution: " + stringBuilder.ToString());
            }
            else
            {
                return("No Personal Evolution: " + stringBuilder.ToString());
            }
        }
Ejemplo n.º 12
0
        public override void RunAction()
        {
            if (this.Target.Unit == null)
            {
                UberDebug.LogError((UnityEngine.Object) this, (object)"Invalid target for effect '{0}'", (object)this.GetType().Name);
            }
            else if (this.Context.MaybeCaster == null)
            {
                UberDebug.LogError((UnityEngine.Object) this, (object)"Caster is missing", (object[])Array.Empty <object>());
            }
            else
            {
                int bonus = this.Value.Calculate(this.Context);
                int hps   = bonus;
                if (multiply_by_hd)
                {
                    hps = bonus * this.Target.Unit.Descriptor.Progression.CharacterLevel;
                }

                this.Context.TriggerRule <RuleHealDamage>(new RuleHealDamage(this.Context.MaybeCaster, this.Target.Unit, DiceFormula.Zero, hps));

                foreach (var s in stats_to_heal)
                {
                    this.Context.TriggerRule <RuleHealStatDamage>(new RuleHealStatDamage(this.Context.MaybeCaster, this.Target.Unit, s, bonus));
                }
            }
        }
        public override void RunAction()
        {
            var unit = this.Target?.Unit;

            if (unit == null)
            {
                UberDebug.LogError("Target is missing");
                return;
            }

            int val = amount.Calculate(this.Context);

            var unit_part_focus = unit.Get <UnitPartImplements>();

            if (unit_part_focus != null && !unit_part_focus.isLocked())
            {
                unit_part_focus.investFocus(school, val);
            }


            if (resource != null)
            {
                unit.Descriptor.Resources.Restore(resource, val);
            }
        }
Ejemplo n.º 14
0
        public override IEnumerator <AbilityDeliveryTarget> Deliver(AbilityExecutionContext context, TargetWrapper target)
        {
            UnitEntityData caster = context.MaybeCaster;

            if (caster == null)
            {
                UberDebug.LogError("Caster is missing", Array.Empty <object>());
                yield break;
            }

            RulebookEventContext rulebookContext      = context.RulebookContext;
            RuleAttackWithWeapon attackWithWeapon     = (rulebookContext != null) ? rulebookContext.AllEvents.LastOfType <RuleAttackWithWeapon>() : null;
            RuleAttackWithWeapon ruleAttackWithWeapon = attackWithWeapon;
            RuleAttackRoll       attackRoll           = (ruleAttackWithWeapon != null) ? ruleAttackWithWeapon.AttackRoll : null;

            attackRoll = (attackRoll ?? context.TriggerRule <RuleAttackRoll>(new RuleAttackRoll(caster, target.Unit, caster.GetFirstWeapon(), 0)));
            if (attackWithWeapon == null)
            {
                attackRoll.ConsumeMirrorImageIfNecessary();
            }
            yield return(new AbilityDeliveryTarget(target)
            {
                AttackRoll = attackRoll
            });

            yield break;
        }
Ejemplo n.º 15
0
        public static int GetEncounterCR()
        {
            var blueprint =
                Utilities.GetBlueprint <BlueprintStatProgression>(
                    "Assets/Mechanics/Blueprints/Classes/Basic/CRTable.asset");

            if (!(bool)(UnityEngine.Object)blueprint)
            {
                blueprint = Utilities.GetBlueprint <BlueprintStatProgression>("19b09eaa18b203645b6f1d5f2edcb1e4");
            }
            if ((bool)(UnityEngine.Object)blueprint)
            {
                return(Utilities.GetTotalChallengeRating(Game.Instance.State.Units.Where <UnitEntityData>(
                                                             (Func <UnitEntityData, bool>)(u =>
                {
                    if (u.IsInCombat)
                    {
                        return !u.IsPlayerFaction;
                    }
                    return false;
                })).Select <UnitEntityData, BlueprintUnit>(
                                                             (Func <UnitEntityData, BlueprintUnit>)(u => u.Blueprint))
                                                         .ToList <BlueprintUnit>()));
            }
            UberDebug.LogChannel("SmartConsole",
                                 string.Format("CR table not found at {0} or {1}, cannot calculate",
                                               (object)"Assets/Mechanics/Blueprints/Classes/Basic/CRTable.asset",
                                               (object)"19b09eaa18b203645b6f1d5f2edcb1e4"), (object[])Array.Empty <object>());
            return(-1);
        }
Ejemplo n.º 16
0
        private void reloadCardList()
        {
            BuildCardList.clearItems();
            foreach (CardDefine card in
                     cards.Where(
                         c => ui.getManager <CardManager>().isStandardCard(c)
                         )
                     )
            {
                if (parent.game.cards.tryGetSkin(card.id, out var skin))
                {
                    if (FilterPanel.cardFilter(card, skin))
                    {
                        var item = BuildCardList.addItem();
                        item.update(card, skin);
                    }
                }
                else
                {
                    UberDebug.LogErrorChannel("UI", "无法找到" + card + "的皮肤");
                }

                BuildCardList.sortItems(FilterPanel.sortCompareMethod);
            }
        }
Ejemplo n.º 17
0
        public override void RunAction()
        {
            if (this.Target.Unit == null || this.Context.MaybeCaster == null)
            {
                UberDebug.LogError((object)"Target unit is missing", (object[])Array.Empty <object>());
            }
            else
            {
                var dc          = !this.use_custom_dc ? this.Context.Params.DC : custom_dc.Calculate(this.Context);
                var skill_check = this.Context.TriggerRule <RuleSkillCheck>(new RuleSkillCheck(on_caster ? this.Context.MaybeCaster : this.Target.Unit, this.Stat, dc)
                {
                    ShowAnyway = true
                });

                if (skill_check.IsPassed)
                {
                    this.Success.Run();
                }
                else if (!skill_check.IsSuccessRoll(skill_check.D20, 9))
                {
                    this.Failure10.Run();
                }
                else if (!skill_check.IsSuccessRoll(skill_check.D20, 4))
                {
                    this.Failure5.Run();
                }
            }
        }
Ejemplo n.º 18
0
        public override void RunAction()
        {
            int            available_units = max_units;
            UnitEntityData unit            = this.Target.Unit;

            if (unit == null)
            {
                UberDebug.LogError((object)"Target is missing", (object[])Array.Empty <object>());
            }
            else
            {
                foreach (var u in unit.CombatState.EngagedBy)
                {
                    if (u == this.Context.MaybeCaster)
                    {
                        continue;
                    }
                    Game.Instance.CombatEngagementController.ForceAttackOfOpportunity(u, unit);
                    available_units--;
                    if (available_units <= 0)
                    {
                        return;
                    }
                }
            }
        }
 public void log(string msg)
 {
     if (!enable)
     {
         return;
     }
     UberDebug.Log(msg);
 }
Ejemplo n.º 20
0
 public void log(string msg)
 {
     if (!enable)
     {
         return;
     }
     UberDebug.Log((string.IsNullOrEmpty(name) ? null : (name + ":")) + msg);
 }
Ejemplo n.º 21
0
 public override void merge(CardDefine newVersion)
 {
     if (newVersion.type != type)
     {
         UberDebug.LogWarning(newVersion + "的类型与" + this + "不同,可能是一次非法的数据合并!");
     }
     cost = newVersion.getProp <int>(nameof(cost));
 }
Ejemplo n.º 22
0
        private int DealHitPointsDamage(ContextActionDealDamage2.DamageInfo info)
        {
            if (this.Context.MaybeCaster == null)
            {
                UberDebug.LogError(this, (object)"Caster is missing", (object[])Array.Empty <object>());
                return(0);
            }
            BaseDamage damage1 = this.DamageType.GetDamageDescriptor(info.Dices, info.Bonus).CreateDamage();

            damage1.EmpowerBonus = !info.Empower ? damage1.EmpowerBonus : 1.5f;
            damage1.Maximized    = info.Maximize || damage1.Maximized;
            BaseDamage baseDamage = damage1;
            DamageCriticalModifierType?criticalModifier = info.CriticalModifier;
            int?critModifier = criticalModifier.HasValue ? new int?(criticalModifier.GetValueOrDefault().IntValue()) : new int?();

            baseDamage.CriticalModifier = critModifier;
            damage1.Half           = this.Half;
            damage1.AlreadyHalved  = info.PreRolledValue.HasValue && this.Half && this.AlreadyHalved;
            damage1.PreRolledValue = info.PreRolledValue;
            if (this.IsAoE && !info.PreRolledValue.HasValue)
            {
                int?nullable2 = this.Context.AoEDamage.Get <ContextActionDealDamage, int?>(this, new int?());
                if (nullable2.HasValue)
                {
                    damage1.PreRolledValue = nullable2;
                }
            }
            ContextAttackData data    = ElementsContext.GetData <ContextAttackData>();
            DamageBundle      damage2 = (DamageBundle)damage1;

            damage2.Weapon = data?.AttackRoll?.Weapon;
            RuleDealDamage rule = new RuleDealDamage(this.Context.MaybeCaster, this.Target.Unit, damage2)
            {
                Projectile             = data?.Projectile,
                AttackRoll             = data?.AttackRoll,
                HalfBecauseSavingThrow = info.HalfBecauseSavingThrow,
                MinHPAfterDamage       = !this.UseMinHPAfterDamage ? new int?() : new int?(this.MinHPAfterDamage),
                SourceAbility          = this.Context.SourceAbility,
                SourceArea             = this.Context.AssociatedBlueprint as BlueprintAbilityAreaEffect
            };

            if (this.IsShadowEvocation)
            {
                RuleSavingThrow ruleSavingThrow = this.Context.TriggerRule(new RuleSavingThrow(this.Target.Unit, SavingThrowType.Will, this.Context.Params.DC));
                rule.ReducedBecauseOfShadowEvocation = ruleSavingThrow.IsPassed;
            }
            if (this.IsShadowEvocationGreater)
            {
                RuleSavingThrow ruleSavingThrow = this.Context.TriggerRule(new RuleSavingThrow(this.Target.Unit, SavingThrowType.Will, this.Context.Params.DC));
                rule.ReducedBecauseOfShadowEvocationGreater = ruleSavingThrow.IsPassed;
            }
            this.Context.TriggerRule <RuleDealDamage>(rule);
            if (this.IsAoE && !this.Context.AoEDamage.Get <ContextActionDealDamage, int?>(this, new int?()).HasValue)
            {
                this.Context.AoEDamage[this] = new int?(rule.Calculate.CalculatedDamage.FirstItem <DamageValue>().RolledValue);
            }
            return(rule.Damage);
        }
Ejemplo n.º 23
0
    private void Start()
    {
        collectables = new Collectables();
        Debug.Assert(collectables != null);
        collectables._grade    = MagicGrade.Diamond;
        collectables._duration = BonusDuration.Instant;

        UberDebug.LogChannel("Collectable", "Launch");
    }
        private void onRecvAction(object sender, EventArgs args, GenericAction callback)
        {
            if (args is OnAttackEventArgs)
            {
                var arg = args as OnAttackEventArgs;
                UberDebug.LogChannel(this, "Frontend", "ServantView收到攻击事件");
                callback += (a, b) => { UberDebug.LogChannel("Frontend", "ServantAttack动画播放完毕"); };

                var targetServant = cardVM.Board.Deck.GetCardByRID(arg.TargetRID);
                if (targetServant != null)
                {
                    ObjectPositionEventArgs target;
                    if (targetServant is CharacterInfoViewModel)
                    {
                        target = new SpecialCardPositionEventArgs(SpecialCardPositionEventArgs.CardType.MasterCard, !cardVM.Board.IsSelf);
                    }
                    else
                    {
                        target = new CardPositionEventArgs(cardVM.Board.ServantCount, cardVM.Index, !cardVM.Board.IsSelf);
                    }
                    PlayAnimation("ServantAttack", new ServantAttackEventArgs(
                                      new CardPositionEventArgs(cardVM.Board.ServantCount, cardVM.Index, cardVM.Board.IsSelf),
                                      target)
                                  , callback);
                }
                else
                {
                    throw new NullReferenceException($"没有找到rid为{arg.TargetRID}的卡");
                }
            }

            if (args is IndexChangeEventArgs && drawed)
            {
                var arg = args as IndexChangeEventArgs;
                PlayAnimation(this, new CardAnimationEventArgs()
                {
                    AnimationName = "RetinueMove",
                    EventArgs     = new CardPositionEventArgs(arg.Count > 0 ? arg.Count : cardVM.Board.ServantCount, arg.Index, cardVM.Board.IsSelf)
                }, callback);
            }

            if (args is RetinueSummonEventArgs)
            {
                callback += (a, b) => { drawed = true; };
                var arg = args as RetinueSummonEventArgs;
                PlayAnimation(this, new CardAnimationEventArgs()
                {
                    AnimationName = "RetinueSummon",
                    EventArgs     = new CardPositionEventArgs(cardVM.Board.ServantCount, cardVM.Index, cardVM.Board.IsSelf)
                }, callback);
            }

            if (args is CardAnimationEventArgs)
            {
                PlayAnimation(this, args, callback);
            }
        }
Ejemplo n.º 25
0
 void TestThreadEntry()
 {
     for (;;)
     {
         Debug.Log("Thread Log Message");
         UberDebug.Log("Thread ULog Message");
         Thread.Sleep(100);
     }
 }
        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);
        }
        /// <summary>
        /// 初始抽卡
        /// </summary>
        /// <param name="cards"></param>
        public void InitDraw(CardID[] cards)
        {
            GenericAction a = (evt, arg) =>
            {
                UberDebug.LogDebugChannel("Frontend", "准备进入抽卡选择模式");
                enterThrowingMode(0, 0);
            };

            DrawCard(cards, a);
        }
        public override void RunAction()
        {
            MechanicsContext           context     = ElementsContext.GetData <MechanicsContext.Data>()?.Context;
            EnchantPoolDataDescription description = new EnchantPoolDataDescription();

            if (context == null)
            {
                UberDebug.LogError((UnityEngine.Object) this, (object)"Unable to apply buff: no context found", (object[])Array.Empty <object>());
            }
            else
            {
                Rounds         rounds      = this.DurationValue.Calculate(context);
                UnitEntityData maybeCaster = context.MaybeCaster;
                if (maybeCaster == null)
                {
                    UberDebug.LogError((UnityEngine.Object) this, (object)"Can't apply buff: target is null", (object[])Array.Empty <object>());
                }
                else
                {
                    maybeCaster.Ensure <UnitPartEnchantPoolData>().ClearEnchantPool(this.EnchantPool);
                    ItemEntity itemEntity = maybeCaster.Body.PrimaryHand.HasWeapon ? (ItemEntity)maybeCaster.Body.PrimaryHand.MaybeWeapon : (ItemEntity)maybeCaster.Body.EmptyHandWeapon;
                    if (itemEntity == null)
                    {
                        return;
                    }
                    int num1      = 0;
                    int groupSize = maybeCaster.Descriptor.Progression.Features.GetRank(Feature);
                    description.EnchantedItem = itemEntity;
                    description.EnchantPool   = this.EnchantPool;
                    if (itemEntity.Enchantments.Any <ItemEnchantment>())
                    {
                        foreach (WeaponEnhancementBonus enhancementBonus in itemEntity.Enchantments.SelectMany <ItemEnchantment, WeaponEnhancementBonus>((Func <ItemEnchantment, IEnumerable <WeaponEnhancementBonus> >)(e => e.SelectComponents <WeaponEnhancementBonus>())))
                        {
                            num1 += enhancementBonus.EnhancementBonus;
                        }
                    }

                    foreach (AddBondProperty selectFactComponent in maybeCaster.Buffs.SelectFactComponents <AddBondProperty>())
                    {
                        if (selectFactComponent.EnchantPool == this.EnchantPool && !itemEntity.HasEnchantment(selectFactComponent.Enchant))
                        {
                            groupSize -= selectFactComponent.Enchant.EnchantmentCost;
                            description.Enchantments.Add(itemEntity.AddEnchantment(selectFactComponent.Enchant, context, new Rounds?(rounds)));
                        }
                    }

                    int num2 = Math.Min(Math.Max(0, 5 - num1), groupSize);
                    if (num2 > 0)
                    {
                        description.Enchantments.Add(itemEntity.AddEnchantment(this.DefaultEnchantments[num2 - 1], context, new Rounds?(rounds)));
                    }
                    maybeCaster.Ensure <UnitPartEnchantPoolData>().RecordEnchantPool(description);
                }
            }
        }
Ejemplo n.º 29
0
        public void mod_FoundSettlement(RegionSettlementLocation settlementLocation, string name = null)
        {
            if (!KingmakerPatchSettings.CurrencyFallback.Enabled)
            {
                this.source_FoundSettlement(settlementLocation, name);
                return;
            }

            if (!this.Blueprint.SettlementBuildArea)
            {
                UberDebug.LogError("Cannot found a settlement in {0}: no building area set up", settlementLocation);
                return;
            }

            if (this.Settlement != null)
            {
                UberDebug.LogError("Cannot found a settlement in {0}: already built", settlementLocation);
                return;
            }

            if (settlementLocation != null && settlementLocation.AssociatedLocation == null)
            {
                UberDebug.LogError("Cannot found a settlement in {0}: no globalmap location associated", settlementLocation);
                return;
            }

            if (settlementLocation == null && this.Blueprint.SettlementGlobalmapLocations.Length == 0)
            {
                UberDebug.LogError("Cannot found a settlement in {0}: no location specified and no default found", this.Blueprint);
                return;
            }

            KingdomCurrencyFallback.SpendPoints(KingdomRoot.Instance.SettlementBPCost);

            var settlementState = new SettlementState(SettlementState.LevelType.Village)
            {
                Region = this
            };

            SettlementState settlementState2 = settlementState;

            settlementState2.HasWaterSlot = settlementLocation?.HasWaterSlot == true;

            settlementState.Name = name ?? this.Blueprint.DefaultSettlementName;

            settlementState.Location = settlementLocation?.AssociatedLocation ?? this.Blueprint.SettlementGlobalmapLocations.FirstOrDefault();

            settlementState.SettlementLocation = settlementLocation;

            this.Settlement = settlementState;

            this.SetSettlementUIMarkers();

            EventBus.RaiseEvent((ISettlementFoundingHandler h) => h.OnSettlementFounded(this.Settlement));
        }
Ejemplo n.º 30
0
        protected override bool CheckCondition()
        {
            UnitEntityData unit = this.check_caster ? this.Context.MaybeCaster : this.Target.Unit;

            if (unit == null)
            {
                UberDebug.LogError((object)"Target is missing", (object[])Array.Empty <object>());
                return(false);
            }
            return(unit.Stats.GetStat <ModifiableValueSkill>(skill).BaseValue >= value);
        }