示例#1
0
            private static bool Prefix(UnitAlignment __instance, AlignmentShiftDirection direction, ref int value, IAlignmentShiftProvider provider)
            {
                try {
                    if (settings.togglePreventAlignmentChanges)
                    {
                        value = 0;
                    }

                    if (settings.toggleAlignmentFix)
                    {
                        if (value == 0)
                        {
                            return(false);
                        }
                        var vector          = __instance.m_Vector;
                        var num             = (float)value / 50f;
                        var directionVector = Traverse.Create(__instance).Method("GetDirection", new object[] { direction }).GetValue <Vector2>();
                        var newAlignment    = __instance.m_Vector + directionVector * num;
                        if (newAlignment.magnitude > 1f)
                        {
                            //Instead of normalizing towards true neutral, normalize opposite to the alignment vector
                            //to prevent sliding towards neutral
                            newAlignment -= (newAlignment.magnitude - newAlignment.normalized.magnitude) * directionVector;
                        }
                        if (direction == AlignmentShiftDirection.TrueNeutral && (Vector2.zero - __instance.m_Vector).magnitude < num)
                        {
                            newAlignment = Vector2.zero;
                        }
                        Traverse.Create(__instance).Property <Vector2>("Vector").Value = newAlignment;
                        Traverse.Create(__instance).Method("UpdateValue").GetValue();
                        //Traverse requires the parameter types to find interface parameters
                        Traverse.Create(__instance).Method("OnChanged",
                                                           new Type[] { typeof(AlignmentShiftDirection), typeof(Vector2), typeof(IAlignmentShiftProvider), typeof(bool) },
                                                           new object[] { direction, vector, provider, true }).GetValue();
                        return(false);
                    }
                }
                catch (Exception e) {
                    Mod.Error(e);
                }
                return(true);
            }
示例#2
0
 private static void Postfix(UnitAlignment __instance, ref Vector2 __result, AlignmentShiftDirection direction)
 {
     if (settings.toggleAlignmentFix)
     {
         if (direction == AlignmentShiftDirection.NeutralGood)
         {
             __result = new Vector2(0, 1);
         }
         if (direction == AlignmentShiftDirection.NeutralEvil)
         {
             __result = new Vector2(0, -1);
         }
         if (direction == AlignmentShiftDirection.LawfulNeutral)
         {
             __result = new Vector2(-1, 0);
         }
         if (direction == AlignmentShiftDirection.ChaoticNeutral)
         {
             __result = new Vector2(1, 0);
         }
     }
 }