Пример #1
0
            static bool Prefix(ref Pawn __instance, DamageInfo?dinfo, Verse.Hediff exactCulprit = null)
            {
                bool hasBondageBed = false;//没有被束缚床束缚

                for (int i = 0; i < __instance.health.hediffSet.hediffs.Count; i++)
                {
                    if (__instance.health.hediffSet.hediffs[i].def == SR.DA.Hediff.HediffDefOf.SR_Hediff_BondageBed)
                    {
                        hasBondageBed = true;
                        break;
                    }
                }
                //如果已经被束缚
                if (hasBondageBed)
                {
                    Building_BondageBed        bbb   = (Building_BondageBed)__instance.CurrentBed();//获取当前躺着的束缚床
                    CompRemoveEffectBondageBed crebb = bbb.GetComp <CompRemoveEffectBondageBed>();
                    if (crebb != null)
                    {
                        crebb.DoEffect(__instance); //解除束缚
                        return(false);              //解除成功是会通知Pawn_HealthTracker重新检测死亡性,所以本次跳过,否则会多次kill
                    }
                }
                return(true);
            }
 static bool Prefix(ref bool __result, Verse.Thing item)
 {
     if (item != null)
     {
         if (item.GetType() == typeof(Pawn))
         {
             Pawn p             = (Pawn)item; //搬运的是人形
             bool hasBondageBed = false;      //没有被束缚床束缚
             for (int i = 0; i < p.health.hediffSet.hediffs.Count; i++)
             {
                 if (p.health.hediffSet.hediffs[i].def == SR.DA.Hediff.HediffDefOf.SR_Hediff_BondageBed)
                 {
                     hasBondageBed = true;
                     break;
                 }
             }
             //如果已经被束缚
             if (hasBondageBed)
             {
                 Building_Bed bbb = (Building_BondageBed)p.CurrentBed();//获取当前躺着的束缚床
                 if (bbb != null)
                 {
                     CompRemoveEffectBondageBed crebb = bbb.GetComp <CompRemoveEffectBondageBed>();
                     if (crebb != null)
                     {
                         crebb.DoEffect(p);//解除束缚
                     }
                 }
             }
         }
     }
     return(true);
 }
        /// <summary>
        /// 行为过程
        /// </summary>
        /// <returns></returns>
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);                                                         //床被禁止使用
            this.FailOnAggroMentalStateAndHostile(TargetIndex.B);                                                       //B精神不正常
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A)); //走到dark家具旁边

            Pawn prisoner = (Pawn)Target;

            //捆绑操作
            if (!prisoner.Dead)
            {
                yield return(Toils_General.WaitWith(TargetIndex.A, 60, true, true)); //交互1秒

                yield return(Toils_Reserve.Release(TargetIndex.B));

                //解除效果
                yield return(new Toil
                {
                    initAction = delegate()
                    {
                        if (Thing != null)
                        {
                            CompRemoveEffectBondageBed compUseEffect = Thing.TryGetComp <CompRemoveEffectBondageBed>();//解除束缚床效果
                            if (compUseEffect != null)
                            {
                                compUseEffect.DoEffect(prisoner);
                                MoteMaker.ThrowText(Target.PositionHeld.ToVector3(), Target.MapHeld, "SR_Release".Translate(), 4f);
                            }
                        }
                    },
                    defaultCompleteMode = ToilCompleteMode.Instant
                });
            }
            yield break;
        }