static bool Prefix(UnitEntityData unit) { if (IsInCombat()) { if (unit.IsCurrentUnit()) { UnitPartConfusion unitPartConfusion = unit.Get <UnitPartConfusion>(); if (unitPartConfusion && unitPartConfusion.RoundStartTime < Game.Instance.TimeController.GameTime) { unitPartConfusion.Cmd?.Interrupt(); unitPartConfusion.RoundStartTime = TimeSpan.Zero; } } else { return(IsPassing() && !unit.IsInCombat); } } return(true); }
private static void Postfix(UnitAttack __instance) { UnitEntityData unit = __instance.Executor; if (!StatusWrapper.IsInCombat() || !unit.IsCurrentUnit()) { return; } bool attackingNearest = unit.Descriptor.State.HasCondition(UnitCondition.AttackNearest); bool confusedAttackNearest = false; if (unit.Descriptor.State.HasCondition(UnitCondition.Confusion)) { UnitPartConfusion part = unit.Get <UnitPartConfusion>(); if (part.State == ConfusionState.AttackNearest) { confusedAttackNearest = true; } } if (attackingNearest || confusedAttackNearest) { StatusWrapper.CurrentTurn().ForceToEnd(); } }
static bool Prefix(UnitConfusionController __instance, UnitEntityData unit) { var allowed_states = new ConfusionState[0]; if (unit.Descriptor.State.HasCondition(UnitCondition.AttackNearest)) { allowed_states = new ConfusionState[] { ConfusionState.AttackNearest }; } else { allowed_states = unit.Ensure <UnitPartConfusionControl>().allowedConfusionStates(); } if (unit.Descriptor.State.HasCondition(UnitCondition.Confusion) || unit.Descriptor.State.HasCondition(UnitCondition.AttackNearest)) { var tr = Harmony12.Traverse.Create <UnitConfusionController>(); UnitPartConfusion part = unit.Ensure <UnitPartConfusion>(); bool flag = !unit.CombatState.HasCooldownForCommand(UnitCommand.CommandType.Standard); if (Game.Instance.TimeController.GameTime - part.RoundStartTime > tr.Field("RoundDuration").GetValue <TimeSpan>() && flag) { do { RuleRollDice ruleRollDice = Rulebook.Trigger <RuleRollDice>(new RuleRollDice(unit, new DiceFormula(1, DiceType.D100))); int num = ruleRollDice.Result; part.State = num >= 26 ? (num >= 51 ? (num >= 76 ? ConfusionState.AttackNearest : ConfusionState.SelfHarm) : ConfusionState.DoNothing) : ConfusionState.ActNormally; } while (!allowed_states.Contains(part.State)); if (part.State == ConfusionState.ActNormally) { part.ReleaseControl(); } else { part.RetainControl(); } part.RoundStartTime = Game.Instance.TimeController.GameTime; part.Cmd?.Interrupt(); part.Cmd = (UnitCommand)null; } if (part.Cmd != null || !unit.Descriptor.State.CanAct || part.State == ConfusionState.ActNormally) { return(false); } if (flag) { switch (part.State) { case ConfusionState.DoNothing: part.Cmd = tr.Method("DoNothing", part).GetValue <UnitCommand>(); break; case ConfusionState.SelfHarm: part.Cmd = tr.Method("SelfHarm", part).GetValue <UnitCommand>(); break; case ConfusionState.AttackNearest: part.Cmd = tr.Method("AttackNearest", part).GetValue <UnitCommand>(); break; default: throw new ArgumentOutOfRangeException(); } } else { part.Cmd = tr.Method("DoNothing", part).GetValue <UnitCommand>(); } if (part.Cmd == null) { return(false); } part.Owner.Unit.Commands.Run(part.Cmd); } else { unit.Remove <UnitPartConfusion>(); } return(false); }