Beispiel #1
0
        public static Toil SipWater(Pawn drinker, Need_Water pawnNeed, CompWaterContainer waterContainer, bool wornByActor)
        {
            var toil = new Toil();
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration = sipTicks;
            toil.initAction = delegate
            {
                bool fromThing = toil.actor.jobs.curJob.GetTarget(TargetIndex.A).HasThing;
                if (fromThing)
                {
                    toil.FailOnForbidden(TargetIndex.A);
                    if (!wornByActor)
                    {
                        toil.FailOnDespawned(TargetIndex.A);
                    }
                }

                float wantDrink = Math.Min(pawnNeed.HydrationWantedLitres, sipLitres);
                float didDrink = pawnNeed.DrinkFrom(waterContainer, wantDrink);
            };
            toil.FailOn(() => waterContainer.IsEmpty);

            // TODO: toil.WithEffect();
            toil.WithSustainer(delegate
            {
                if (drinker.RaceProps.Humanlike)
                {
                    return DefDatabase<SoundDef>.GetNamed(drinkSoundName);
                }
                return null;
            });
            return toil;
        }
Beispiel #2
0
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, TargetIndex CarrierInd)
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn         actor   = toil.actor;
                Job          curJob  = actor.jobs.curJob;
                Vehicle_Cart carrier = actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;
                if (carrier.storage.Count <= 0)
                {
                    return;
                }
                toil.actor.jobs.curJob.SetTarget(TargetIndex.A, carrier.storage.First());
                Thing   dropThing = toil.actor.jobs.curJob.targetA.Thing;
                IntVec3 destLoc   = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
                Thing   dummy;

                if (destLoc.GetStorable() == null)
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                    carrier.storage.TryDrop(dropThing, destLoc, placeMode, out dummy);
                }

                //Check cell queue is adjacent
                List <TargetInfo> cells = curJob.GetTargetQueue(StoreCellInd);
                for (int i = 0; i < cells.Count && i < carrier.storage.Count; i++)
                {
                    if (destLoc.AdjacentTo8Way(cells[i].Cell) && cells[i].Cell.GetStorable() == null)
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage[i]);
                        carrier.storage.TryDrop(carrier.storage[i], cells[i].Cell, ThingPlaceMode.Direct, out dummy);
                        cells.RemoveAt(i);
                        i--;
                    }
                }
                //Check item queue is valid storage for adjacent cell
                foreach (IntVec3 adjCell in GenAdj.CellsAdjacent8Way(destLoc))
                {
                    if (carrier.storage.Count > 0 && adjCell.GetStorable() == null && StoreUtility.IsValidStorageFor(adjCell, carrier.storage.First()))
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage.First());
                        carrier.storage.TryDrop(carrier.storage.First(), adjCell, ThingPlaceMode.Direct, out dummy);
                    }
                }
            };
            toil.FailOnDespawned(CarrierInd);
            return(toil);
        }
Beispiel #3
0
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, TargetIndex CarrierInd)
        {
            Toil toil = new Toil();
            toil.initAction = () =>
            {
            Pawn actor = toil.actor;
            Job curJob = actor.jobs.curJob;
            Vehicle_Cart carrier = actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;
            if (carrier.storage.Count <= 0)
                return;
            toil.actor.jobs.curJob.SetTarget(TargetIndex.A, carrier.storage.First());
            Thing dropThing = toil.actor.jobs.curJob.targetA.Thing;
            IntVec3 destLoc = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
            Thing dummy;

            if (destLoc.GetStorable() == null)
            {
                Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                carrier.storage.TryDrop(dropThing, destLoc, placeMode, out dummy);
            }

            //Check cell queue is adjacent
            List<TargetInfo> cells = curJob.GetTargetQueue(StoreCellInd);
            for (int i = 0; i < cells.Count && i < carrier.storage.Count; i++)
                if (destLoc.AdjacentTo8Way(cells[i].Cell) && cells[i].Cell.GetStorable() == null)
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage[i]);
                    carrier.storage.TryDrop(carrier.storage[i], cells[i].Cell, ThingPlaceMode.Direct, out dummy);
                    cells.RemoveAt(i);
                    i--;
                }
            //Check item queue is valid storage for adjacent cell
            foreach (IntVec3 adjCell in GenAdj.CellsAdjacent8Way(destLoc))
                if (carrier.storage.Count > 0 && adjCell.GetStorable() == null && StoreUtility.IsValidStorageFor(adjCell, carrier.storage.First()))
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage.First());
                    carrier.storage.TryDrop(carrier.storage.First(), adjCell, ThingPlaceMode.Direct, out dummy);
                }
            };
            toil.FailOnDespawned(CarrierInd);
            return toil;
        }
Beispiel #4
0
        public static Toil CollectInCarrier(TargetIndex CarrierInd, TargetIndex HaulableInd)
        {
            Toil toil = new Toil();
            toil.initAction = () =>
            {
            Pawn actor = toil.actor;
            Job curJob = actor.jobs.curJob;
            Thing haulThing = curJob.GetTarget(HaulableInd).Thing;
            Vehicle_Cart carrier = curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;
            //Check haulThing is human_corpse. If other race has apparel, It need to change

            Find.DesignationManager.RemoveAllDesignationsOn(haulThing);
            if ((haulThing.ThingID.IndexOf("Human_Corpse") <= -1) ? false : true)
            {
                Corpse corpse = (Corpse)haulThing;
                var wornApparel = corpse.innerPawn.apparel.WornApparel;

                //Drop wornApparel. wornApparel cannot Add to container directly because it will be duplicated.
                corpse.innerPawn.apparel.DropAll(corpse.innerPawn.Position, false);

                //Transfer in container
                foreach (Thing apparel in wornApparel)
                {
                    if (carrier.storage.TryAdd(apparel))
                    {
                        apparel.holder = carrier.GetContainer();
                        apparel.holder.owner = carrier;
                    }
                }
            }
            //Collecting TargetIndex ind
            if (carrier.storage.TryAdd(haulThing))
            {
                haulThing.holder = carrier.GetContainer();
                haulThing.holder.owner = carrier;
            }

            List<TargetInfo> thingList = curJob.GetTargetQueue(HaulableInd);
            for (int i = 0; i < thingList.Count; i++)
                if (actor.Position.AdjacentTo8Way(thingList[i].Thing.Position))
                {
                    if (carrier.storage.TryAdd(thingList[i].Thing))
                    {
                        thingList[i].Thing.holder = carrier.GetContainer();
                        thingList[i].Thing.holder.owner = carrier;
                    }
                    thingList.RemoveAt(i);
                    i--;
                }

            };
            toil.FailOn(() =>
            {
            Pawn actor = toil.actor;
            Job curJob = actor.jobs.curJob;
            Thing haulThing = curJob.GetTarget(HaulableInd).Thing;
            Vehicle_Cart carrier = curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;

            if (!carrier.storage.CanAcceptAnyOf(haulThing)
                && actor.Position.IsAdjacentTo8WayOrInside(haulThing.Position, haulThing.Rotation, haulThing.RotatedSize))
                return true;
            return false;
            });
            toil.FailOnDespawned(CarrierInd);
            return toil;
        }
Beispiel #5
0
        public static Toil CollectInCarrier(TargetIndex CarrierInd, TargetIndex HaulableInd)
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn         actor     = toil.actor;
                Job          curJob    = actor.jobs.curJob;
                Thing        haulThing = curJob.GetTarget(HaulableInd).Thing;
                Vehicle_Cart carrier   = curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;
                //Check haulThing is human_corpse. If other race has apparel, It need to change

                Find.DesignationManager.RemoveAllDesignationsOn(haulThing);
                if ((haulThing.ThingID.IndexOf("Human_Corpse") <= -1) ? false : true)
                {
                    Corpse corpse      = (Corpse)haulThing;
                    var    wornApparel = corpse.innerPawn.apparel.WornApparel;

                    //Drop wornApparel. wornApparel cannot Add to container directly because it will be duplicated.
                    corpse.innerPawn.apparel.DropAll(corpse.innerPawn.Position, false);

                    //Transfer in container
                    foreach (Thing apparel in wornApparel)
                    {
                        if (carrier.storage.TryAdd(apparel))
                        {
                            apparel.holder       = carrier.GetContainer();
                            apparel.holder.owner = carrier;
                        }
                    }
                }
                //Collecting TargetIndex ind
                if (carrier.storage.TryAdd(haulThing))
                {
                    haulThing.holder       = carrier.GetContainer();
                    haulThing.holder.owner = carrier;
                }

                List <TargetInfo> thingList = curJob.GetTargetQueue(HaulableInd);
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (actor.Position.AdjacentTo8Way(thingList[i].Thing.Position))
                    {
                        if (carrier.storage.TryAdd(thingList[i].Thing))
                        {
                            thingList[i].Thing.holder       = carrier.GetContainer();
                            thingList[i].Thing.holder.owner = carrier;
                        }
                        thingList.RemoveAt(i);
                        i--;
                    }
                }
            };
            toil.FailOn(() =>
            {
                Pawn actor           = toil.actor;
                Job curJob           = actor.jobs.curJob;
                Thing haulThing      = curJob.GetTarget(HaulableInd).Thing;
                Vehicle_Cart carrier = curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;

                if (!carrier.storage.CanAcceptAnyOf(haulThing) &&
                    actor.Position.IsAdjacentTo8WayOrInside(haulThing.Position, haulThing.Rotation, haulThing.RotatedSize))
                {
                    return(true);
                }
                return(false);
            });
            toil.FailOnDespawned(CarrierInd);
            return(toil);
        }