Ejemplo n.º 1
0
 private static float AdjustNonCombatRotation(Pawn pawn, float num, AdeptusMechanicus.CompOversizedWeapon compOversizedWeapon)
 {
     if (compOversizedWeapon == null)
     {
         return(num);
     }
     if (compOversizedWeapon.Props != null)
     {
         if (pawn.Rotation == Rot4.North)
         {
             num += compOversizedWeapon.Props.angleAdjustmentNorth;
         }
         else if (pawn.Rotation == Rot4.East)
         {
             num += compOversizedWeapon.Props.angleAdjustmentEast;
         }
         else if (pawn.Rotation == Rot4.West)
         {
             num += compOversizedWeapon.Props.angleAdjustmentWest;
         }
         else if (pawn.Rotation == Rot4.South)
         {
             num += compOversizedWeapon.Props.angleAdjustmentSouth;
         }
     }
     return(num);
 }
 public static bool PawnRenderer_DrawEquipmentAiming_Postfix(ref PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
 {
     if (!AdeptusIntergrationUtil.enabled_rooloDualWield)
     {
         Pawn pawn = eq.TryGetComp <CompEquippable>().PrimaryVerb.CasterPawn;
         if (pawn != null)
         {
             Pawn value2 = pawn;
             AdeptusMechanicus.CompActivatableEffect compActivatableEffect = eq.TryGetComp <AdeptusMechanicus.CompActivatableEffect>();
             AdeptusMechanicus.CompOversizedWeapon   compOversizedWeapon   = eq.TryGetComp <AdeptusMechanicus.CompOversizedWeapon>();
             if (compActivatableEffect != null && compOversizedWeapon != null)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 3
0
        ///// <summary>
        ///// Prevents the user from having damage with the verb.
        ///// </summary>
        ///// <param name="__instance"></param>
        ///// <param name="__result"></param>
        ///// <param name="pawn"></param>
        //public static void GetDamageFactorForPostFix(Verb __instance, ref float __result, Pawn pawn)
        //{
        //    Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment;
        //    if (pawn_EquipmentTracker != null)
        //    {
        //        //Log.Message("2");
        //        ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);

        //        if (thingWithComps != null)
        //        {
        //            //Log.Message("3");
        //            CompActivatableEffect compActivatableEffect = thingWithComps.GetComp<CompActivatableEffect>();
        //            if (compActivatableEffect != null)
        //            {
        //                if (compActivatableEffect.CurrentState != CompActivatableEffect.State.Activated)
        //                {
        //                    //Messages.Message("DeactivatedWarning".Translate(), MessageSound.RejectInput);
        //                    __result = 0f;
        //                }
        //            }
        //        }
        //    }
        //}


        /// <summary>
        ///     Adds another "layer" to the equipment aiming if they have a
        ///     weapon with a CompActivatableEffect.
        /// </summary>
        /// <param name="__instance"></param>
        /// <param name="eq"></param>
        /// <param name="drawLoc"></param>
        /// <param name="aimAngle"></param>
        public static void DrawEquipmentAimingPostFix(PawnRenderer __instance, Thing eq, Vector3 drawLoc, float aimAngle)
        {
            var pawn = (Pawn)AccessTools.Field(typeof(PawnRenderer), "pawn").GetValue(__instance);

            var pawn_EquipmentTracker = pawn.equipment;
            var thingWithComps        =
                pawn_EquipmentTracker?.Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);

            AdeptusMechanicus.CompOversizedWeapon compOversized = thingWithComps.TryGetComp <AdeptusMechanicus.CompOversizedWeapon>();
            var compActivatableEffect = thingWithComps?.GetComp <AdeptusMechanicus.CompActivatableEffect>();

            if (compActivatableEffect?.Graphic == null)
            {
                return;
            }
            if (compActivatableEffect.CurrentState != AdeptusMechanicus.CompActivatableEffect.State.Activated)
            {
                return;
            }
            var num  = aimAngle - 90f;
            var flip = false;

            if (aimAngle > 20f && aimAngle < 160f)
            {
                //mesh = MeshPool.GridPlaneFlip(thingWithComps.def.graphicData.drawSize);
                num += eq.def.equippedAngleOffset;
            }
            else if (aimAngle > 200f && aimAngle < 340f)
            {
                //mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize);
                flip = true;
                num -= 180f;
                num -= eq.def.equippedAngleOffset;
            }
            else
            {
                if (compOversized != null)
                {
                    num = AdjustOffsetAtPeace(eq, pawn, compOversized, num);
                }
                else
                {
                    num += eq.def.equippedAngleOffset;
                }
            }
            if (compOversized != null)
            {
                if (compOversized.Props != null && (!pawn.IsFighting() && (compOversized.Props.verticalFlipNorth && pawn.Rotation == Rot4.North)))
                {
                    num += 180f;
                }
                if (!pawn.IsFighting() || pawn.TargetCurrentlyAimingAt == null)
                {
                    num = AdjustNonCombatRotation(pawn, num, compOversized);
                }
            }

            Vector3 offset = Vector3.zero;

            if (eq is ThingWithComps eqComps)
            {
                if (compOversized != null)
                {
                    if (pawn.Rotation == Rot4.East)
                    {
                        offset = compOversized.Props.eastOffset;
                    }
                    else if (pawn.Rotation == Rot4.West)
                    {
                        offset = compOversized.Props.westOffset;
                    }
                    else if (pawn.Rotation == Rot4.North)
                    {
                        offset = compOversized.Props.northOffset;
                    }
                    else if (pawn.Rotation == Rot4.South)
                    {
                        offset = compOversized.Props.southOffset;
                    }
                    offset += compOversized.Props.offset;
                }


                var deflector = eqComps.AllComps.FirstOrDefault(y =>
                                                                y.GetType().ToString().Contains("Deflect"));
                if (deflector != null)
                {
                    var isActive = (bool)AccessTools
                                   .Property(deflector.GetType(), "IsAnimatingNow").GetValue(deflector, null);
                    if (isActive)
                    {
                        float numMod = (int)AccessTools
                                       .Property(deflector.GetType(), "AnimationDeflectionTicks")
                                       .GetValue(deflector, null);
                        //float numMod2 = new float();
                        //numMod2 = numMod;
                        if (numMod > 0)
                        {
                            if (!flip)
                            {
                                num += (numMod + 1) / 2;
                            }
                            else
                            {
                                num -= (numMod + 1) / 2;
                            }
                        }
                    }
                }
            }
            num %= 360f;

            //ThingWithComps eqComps = eq as ThingWithComps;
            //if (eqComps != null)
            //{
            //    ThingComp deflector = eqComps.AllComps.FirstOrDefault<ThingComp>((ThingComp y) => y.GetType().ToString() == "CompDeflector.CompDeflector");
            //    if (deflector != null)
            //    {
            //        float numMod = (float)((int)AccessTools.Property(deflector.GetType(), "AnimationDeflectionTicks").GetValue(deflector, null));
            //        //Log.ErrorOnce("NumMod " + numMod.ToString(), 1239);
            //numMod = (numMod + 1) / 2;
            //if (subtract) num -= numMod;
            //else num += numMod;
            //    }
            //}

            var matSingle = compActivatableEffect.Graphic.MatSingle;
            //if (mesh == null) mesh = MeshPool.GridPlane(thingWithComps.def.graphicData.drawSize);

            var s      = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y);
            var matrix = default(Matrix4x4);

            drawLoc.y = compActivatableEffect.Altitude(drawLoc);
            matrix.SetTRS(drawLoc + offset, Quaternion.AngleAxis(num, Vector3.up), s);
            if (!flip)
            {
                Graphics.DrawMesh(MeshPool.plane10, matrix, matSingle, 0);
            }
            else
            {
                Graphics.DrawMesh(MeshPool.plane10Flip, matrix, matSingle, 0);
            }
            //Graphics.DrawMesh(mesh, drawLoc, Quaternion.AngleAxis(num, Vector3.up), matSingle, 0);

            if (compOversized != null)
            {
                if (compOversized.Props != null && compOversized.Props.isDualWeapon)
                {
                    offset = new Vector3(-1f * offset.x, offset.y, offset.z);
                    Mesh curPool;
                    if (pawn.Rotation == Rot4.North || pawn.Rotation == Rot4.South)
                    {
                        num    += 135f;
                        num    %= 360f;
                        curPool = !flip ? MeshPool.plane10Flip : MeshPool.plane10;
                    }
                    else
                    {
                        offset  = new Vector3(offset.x, offset.y - 0.1f, offset.z + 0.15f);
                        curPool = !flip ? MeshPool.plane10 : MeshPool.plane10Flip;
                    }
                    matrix.SetTRS(drawLoc + offset, Quaternion.AngleAxis(num, Vector3.up), s);
                    Graphics.DrawMesh(curPool, matrix, matSingle, 0);
                }
            }
        }