Exemplo n.º 1
0
        private Toil Store()
        {
            Toil toil = new Toil();

            toil.initAction = delegate {
                Pawn  actor       = toil.actor;
                Job   curJob      = actor.jobs.curJob;
                Thing objectThing = curJob.GetTarget(objectTI).Thing;

                if (curJob.bill.GetStoreMode() != BillStoreMode.DropOnFloor)
                {
                    IntVec3 vec;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(objectThing, actor, actor.Map, StoragePriority.Unstored, actor.Faction, out vec, true))
                    {
                        actor.carryTracker.TryStartCarry(objectThing);
                        curJob.SetTarget(haulTI, vec);
                        curJob.count = 99999;
                        return;
                    }
                }

                actor.carryTracker.TryStartCarry(objectThing);
                actor.carryTracker.TryDropCarriedThing(actor.Position, ThingPlaceMode.Near, out objectThing);

                actor.jobs.EndCurrentJob(JobCondition.Succeeded);
            };
            return(toil);
        }
Exemplo n.º 2
0
        public override void OnSucessfullCast(Saveable_Caster caster, IEnumerable <Thing> targets, IExposable effectState)
        {
            MapComponent_Ability component = MapComponent_Ability.GetOrCreate();

            foreach (Pawn target in targets)
            {
                AbilityEffect_UtilityChangeKind evolveItem = this.items.First(i => i.from.Contains(target.def));


                Brain brain = target.GetSquadBrain();
                foreach (PawnKindDef kind in evolveItem.to)
                {
                    Pawn newPawn = AbilityEffect_Revive.Copy(caster.pawn, kind, target.Faction);
                    GenSpawn.Spawn(newPawn, target.Position);

                    if (brain != null)
                    {
                        brain.AddPawn(newPawn);
                    }
                }

                Building building = StoreUtility.StoringBuilding(target);
                if (building != null)
                {
                    ((Building_Storage)building).Notify_LostThing(target);
                }
                target.Destroy(DestroyMode.Vanish);
            }
        }
            public static Job HaulBeforeCarry(Pawn pawn, IntVec3 dest, Thing th)
            {
                if (th.IsInValidStorage())
                {
                    return(null);
                }
                if (!StoreUtility.TryFindBestBetterStoreCellFor(th, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out var storeCell, false))
                {
                    return(null);
                }

                var supplyFromHereDist  = th.Position.DistanceTo(dest);
                var supplyFromStoreDist = storeCell.DistanceTo(dest);

                Debug.WriteLine($"Carry from here: {supplyFromHereDist}; carry from store: {supplyFromStoreDist}");

                // [KV] Infinite Storage https://steamcommunity.com/sharedfiles/filedetails/?id=1233893175
                // infinite storage has an interaction spot 1 tile away from itself
                if (supplyFromStoreDist + 1 < supplyFromHereDist)
                {
                    Debug.WriteLine($"'{pawn}' prefixed job with storage haul for '{th.Label}' because '{storeCell.GetSlotGroup(pawn.Map)}' is closer to original destination '{dest}'.");
                    return(PuahJob(pawn, dest, th, storeCell) ?? HaulAIUtility.HaulToCellStorageJob(pawn, th, storeCell, false));
                }

                return(null);
            }
Exemplo n.º 4
0
        private static bool AllowToolHaulUrgentlyJobOnThing_PreFix(ref Job __result, Pawn pawn, Thing t, bool forced = false)
        {
            if (ModCompatibilityCheck.AllowToolIsActive)
            {
                //allowTool HaulUrgently
                CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>();

                if (pawn.RaceProps.Humanlike &&
                    pawn.Faction == Faction.OfPlayer &&
                    t is Corpse == false &&
                    takenToInventory != null &&
                    !(t.def.defName.Contains("Chunk"))    //most of the time we don't have space for it
                    )
                {
                    StoragePriority currentPriority = HaulAIUtility.StoragePriorityAtFor(t.Position, t);
                    if (!StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
                    {
                        JobFailReason.Is("NoEmptyPlaceLower".Translate());
                        return(false);
                    }

                    Job haul = new Job(PickUpAndHaulJobDefOf.HaulToInventory, t)
                    {
                        count = t.stackCount
                    };
                    __result = haul;
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(BarrelInd);
            this.FailOnBurningImmobile(BarrelInd);
            yield return(Toils_Goto.GotoThing(BarrelInd, PathEndMode.Touch));

            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(BarrelInd)
                         .FailOnCannotTouch(BarrelInd, PathEndMode.Touch).FailOn(() => !MeadBarrel.Fermented)
                         .WithProgressBarToilDelay(BarrelInd));

            yield return(new Toil
            {
                initAction = delegate
                {
                    var thing = MeadBarrel.TakeOutMead();
                    GenPlace.TryPlaceThing(thing, pawn.Position, Map, ThingPlaceMode.Near);
                    var currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing,
                                                                   pawn, Map, currentPriority, pawn.Faction, out var c))
                    {
                        job.SetTarget(TargetIndex.C, c);
                        job.SetTarget(TargetIndex.B, thing);
                        job.count = thing.stackCount;
                    }
                    else
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                },
Exemplo n.º 6
0
        Toil Store()
        {
            return(new Toil()
            {
                initAction = delegate {
                    var objectThing = job.GetTarget(objectTI).Thing;

                    if (job.bill.GetStoreMode() != BillStoreModeDefOf.DropOnFloor)
                    {
                        IntVec3 vec;
                        if (StoreUtility.TryFindBestBetterStoreCellFor(objectThing, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out vec, true))
                        {
                            pawn.carryTracker.TryStartCarry(objectThing, objectThing.stackCount);
                            job.SetTarget(haulTI, vec);
                            job.count = 99999;
                            return;
                        }
                    }
                    pawn.carryTracker.TryStartCarry(objectThing, objectThing.stackCount);
                    pawn.carryTracker.TryDropCarriedThing(pawn.Position, ThingPlaceMode.Near, out objectThing);

                    pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                }
            });
        }
Exemplo n.º 7
0
                static void TempReduceStoragePriorityForHaulBeforeCarry(WorkGiver_Scanner __instance, ref bool __state, Pawn pawn, Thing thing)
                {
                    if (!haulToInventory.Value || !enabled.Value)
                    {
                        return;
                    }
                    if (!haulToEqualPriority.Value)
                    {
                        return;
                    }

                    var haulTracker = haulTrackers.GetValueSafe(pawn);

                    if (haulTracker == null || haulTracker.haulType != SpecialHaulType.HaulBeforeCarry)
                    {
                        return;
                    }

                    var currentHaulDestination = StoreUtility.CurrentHaulDestinationOf(thing);

                    if (currentHaulDestination == null)
                    {
                        return;
                    }

                    var storeSettings = currentHaulDestination.GetStoreSettings();

                    if (storeSettings.Priority > StoragePriority.Unstored)
                    {
                        storeSettings.Priority -= 1;
                        __state = true;
                    }
                }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin;

            yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell));

            yield return(Toils_General.Wait(120).WithProgressBarToilDelay(aquacultureBasinIndex));

            Toil getAquacultureBasinProduction = new Toil()
            {
                initAction = () =>
                {
                    Job curJob = this.pawn.jobs.curJob;

                    Thing product = aquacultureBasin.GetProduction();
                    if (product == null)
                    {
                        this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                    else
                    {
                        while (product.stackCount > product.def.stackLimit)
                        {
                            Thing meatStack = ThingMaker.MakeThing(product.def);
                            meatStack.stackCount = product.def.stackLimit;
                            GenPlace.TryPlaceThing(meatStack, this.GetActor().Position, this.Map, ThingPlaceMode.Near);
                            product.stackCount -= product.def.stackLimit;
                        }
                        GenSpawn.Spawn(product, aquacultureBasin.InteractionCell, this.Map);

                        IntVec3 storageCell;
                        if (StoreUtility.TryFindBestBetterStoreCellFor(product, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true))
                        {
                            this.pawn.Reserve(product, this.job);
                            this.pawn.Reserve(storageCell, this.job, 1);
                            this.pawn.CurJob.SetTarget(TargetIndex.B, storageCell);
                            this.pawn.CurJob.SetTarget(TargetIndex.A, product);
                            this.pawn.CurJob.count    = 99999;
                            this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;
                        }
                        else
                        {
                            this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                        }
                    }
                }
            };

            yield return(getAquacultureBasinProduction);

            yield return(Toils_Reserve.Release(aquacultureBasinIndex));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true));
        }
 /// <summary>
 /// Handles the Click event of the btnCoupon control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
 protected void btnCoupon_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtCouponCode.Text))
     {
         CouponService couponService = new CouponService();
         couponService.ApplyCoupon(txtCouponCode.Text, order);
         lblCouponInformationDisplay.Text = StoreUtility.GetFormattedAmount(order.DiscountAmount, true);
         ReloadOrder();
     }
     else
     {
         foreach (OrderItem orderItem in order.OrderItemCollection)
         {
             orderItem.DiscountAmount = 0.00M;
             orderItem.Save("CouponService");
         }
         lblCouponInformationDisplay.Text = StoreUtility.GetFormattedAmount(0.00M, true);
     }
     //re-calculate the tax
     OrderController.CalculateTax(WebUtility.GetUserName());
     //reload the order
     orderSummary.Order = new OrderController().FetchOrder(WebUtility.GetUserName());
     orderSummary.LoadOrder();
     acCheckout.SelectedIndex = acCheckout.SelectedIndex + 1;
     SetProcessOrderEnablement();
 }
Exemplo n.º 10
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(1400).WithProgressBarToilDelay(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    var thing = ThingMaker.MakeThing(ThingDef.Named("RawCompost"));
                    thing.stackCount = SewageProcessing.EmptySewage();
                    GenPlace.TryPlaceThing(thing, pawn.Position, Map, ThingPlaceMode.Near);
                    //StoragePriority currentPriority = StoreUtility.StoragePriorityAtFor(thing.Position, thing);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, Map, StoragePriority.Normal,
                                                                   pawn.Faction, out var c))
                    {
                        job.SetTarget(TargetIndex.C, c);
                        job.SetTarget(TargetIndex.B, thing);
                        job.count = thing.stackCount;
                    }
                    else
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                },
Exemplo n.º 11
0
        public static Job HaulToStorageJob(Pawn p, Thing t)
        {
            StoragePriority  currentPriority = StoreUtility.CurrentStoragePriorityOf(t);
            IntVec3          storeCell;
            IHaulDestination haulDestination;
            Job result;

            if (!StoreUtility.TryFindBestBetterStorageFor(t, p, p.Map, currentPriority, p.Faction, out storeCell, out haulDestination, true))
            {
                JobFailReason.Is(HaulAIUtility.NoEmptyPlaceLowerTrans, null);
                result = null;
            }
            else if (haulDestination is ISlotGroupParent)
            {
                result = HaulAIUtility.HaulToCellStorageJob(p, t, storeCell, false);
            }
            else
            {
                Thing thing = haulDestination as Thing;
                if (thing != null && thing.TryGetInnerInteractableThingOwner() != null)
                {
                    result = HaulAIUtility.HaulToContainerJob(p, t, thing);
                }
                else
                {
                    Log.Error("Don't know how to handle HaulToStorageJob for storage " + haulDestination.ToStringSafe <IHaulDestination>() + ". thing=" + t.ToStringSafe <Thing>(), false);
                    result = null;
                }
            }
            return(result);
        }
Exemplo n.º 12
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(200, TargetIndex.None).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).FailOn(() => !this.OniWineBarrel.Fermented).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing = this.OniWineBarrel.TakeOutAOniWine();
                    GenPlace.TryPlaceThing(thing, this.pawn.Position, base.Map, ThingPlaceMode.Near, null, null, default);
                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, this.pawn, base.Map, currentPriority, this.pawn.Faction, out IntVec3 c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, thing);
                        this.job.count = thing.stackCount;
                        return;
                    }
                    base.EndJobWith(JobCondition.Incompletable);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
Exemplo n.º 13
0
        public static Job SmartBuild(Pawn p, Job job)
        {
            if (p.story.WorkTagIsDisabled(WorkTags.Hauling))
            {
                return(job);
            }
            var carryCapacity   = p.GetStatValue(StatDefOf.CarryingCapacity);
            var itemCount       = job.count;
            var thing           = job.targetA.Thing;
            var storagePriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing);


            IntVec3 storePos;

            if (StoreUtility.TryFindBestBetterStoreCellFor(thing, p, thing.Map, storagePriority, p.Faction, out storePos) && carryCapacity >= itemCount)
            {
                var targetPos = thing.Position;
                var destPos   = job.targetB.Thing.Position;
                if ((targetPos - destPos).LengthHorizontalSquared > (targetPos - storePos).LengthHorizontalSquared)
                {
                    return(HaulAIUtility.HaulMaxNumToCellJob(p, thing, storePos, false));
                }
            }

            return(job);
        }
Exemplo n.º 14
0
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            Pawn            pawn           = base.pawn;
            LocalTargetInfo target         = base.job.GetTarget(TargetIndex.B);
            Job             job            = base.job;
            bool            errorOnFailed2 = errorOnFailed;
            bool            result         = false;

            if (!target.Cell.IsValidStorageFor(pawn.Map, pawn.carryTracker.CarriedThing))
            {
                StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(TargetThingA);
                if (!StoreUtility.TryFindBestBetterStorageFor(TargetThingA, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 foundCell, out IHaulDestination haulDestination))
                {
                    return(false);
                }
            }


            if (pawn.Reserve(target, job, 1, -1, null, errorOnFailed2))
            {
                pawn           = base.pawn;
                target         = base.job.GetTarget(TargetIndex.A);
                job            = base.job;
                errorOnFailed2 = errorOnFailed;
                result         = pawn.Reserve(target, job, 1, -1, null, errorOnFailed2);
            }
            Log.Message("Make Reservation result: " + result);
            return(result);
        }
Exemplo n.º 15
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(BuildingInd);
            this.FailOnBurningImmobile(BuildingInd);
            yield return(Toils_Goto.GotoThing(BuildingInd, PathEndMode.Touch));

            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(BuildingInd).FailOnCannotTouch(BuildingInd, PathEndMode.Touch).FailOn(() => !Building.Completed).WithProgressBarToilDelay(BuildingInd));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing product = Building.TakeOutProduct();
                    GenPlace.TryPlaceThing(product, pawn.Position, Map, ThingPlaceMode.Near);
                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(product);
                    if (StoreUtility.TryFindBestBetterStoreCellFor(product, pawn, Map, currentPriority, pawn.Faction, out IntVec3 cell))
                    {
                        job.SetTarget(StorageCellInd, cell);
                        job.SetTarget(ProductInd, product);
                        job.count = product.stackCount;
                    }
                    else
                    {
                        EndJobWith(JobCondition.Incompletable);
                    }
                },
Exemplo n.º 16
0
 /// <summary>
 /// Gets the shipping rates.
 /// </summary>
 private void GetShippingRates()
 {
     if (!ThisPage.SiteSettings.DisplayShippingOnCart || this.Order.ShippingAmount > 0 || Request.Url.AbsolutePath.Contains("checkout.aspx"))
     {
         lblShippingAmount.Text = StoreUtility.GetFormattedAmount(this.Order.ShippingAmount, true);
         lblTotalAmount.Text    = StoreUtility.GetFormattedAmount(this.Order.Total, true);
     }
     else
     {
         // Get Shipping Options
         ShippingOptionCollection shippingOptionCollection = OrderController.FetchShippingOptions(this.Order);
         if (shippingOptionCollection.Count > 0)
         {
             if (shippingOptionCollection.Count > 1)
             {
                 ddlShipping.Visible = true;
                 foreach (ShippingOption shippingOption in shippingOptionCollection)
                 {
                     ddlShipping.Items.Add(new ListItem(shippingOption.Service, shippingOption.Rate.ToString()));
                 }
             }
             lblShippingAmount.Text = StoreUtility.GetFormattedAmount(shippingOptionCollection[0].Rate.ToString(), true);
             lblTotalAmount.Text    = StoreUtility.GetFormattedAmount(this.Order.Total + shippingOptionCollection[0].Rate, true);
         }
         else
         {
             lblShippingAmount.Text = StoreUtility.GetFormattedAmount(this.Order.ShippingAmount, true);
             lblTotalAmount.Text    = StoreUtility.GetFormattedAmount(this.Order.Total, true);
         }
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Loads the page title.
        /// </summary>
        private void LoadPageTitle()
        {
            string pageTitle = string.Empty;

            foreach (DataRow dr in breadCrumbs.Tables[0].Rows)
            {
                if (string.IsNullOrEmpty(pageTitle.Trim()))
                {
                    pageTitle = dr["Name"].ToString();
                }
                else
                {
                    pageTitle += string.Format(" :: {0}", dr["Name"]);
                }
            }
            if (manufacturerId > 0)
            {
                Manufacturer manufacturer = new Manufacturer(manufacturerId);
                pageTitle += string.Format(" :: {0}", manufacturer.Name);
            }
            if (priceStart >= 0 && priceEnd > 0)
            {
                pageTitle += string.Format(" :: {0} - {1}", StoreUtility.GetFormattedAmount(priceStart, true), StoreUtility.GetFormattedAmount(priceEnd, true));
            }
            Page.Title = string.Format(WebUtility.MainTitleTemplate, Master.SiteSettings.SiteName, pageTitle);
        }
Exemplo n.º 18
0
        private static bool AllowToolHaulUrgentlyJobOnThing_PreFix(ref Job __result, Pawn pawn, Thing t, bool forced = false)
        {
            if (ModCompatibilityCheck.AllowToolIsActive)
            {
                //allowTool HaulUrgently
                CompHauledToInventory takenToInventory = pawn.TryGetComp <CompHauledToInventory>();

                if (pawn.RaceProps.Humanlike &&
                    pawn.Faction == Faction.OfPlayer &&
                    t is Corpse == false &&
                    takenToInventory != null &&
                    !(t.def.defName.Contains("Chunk"))    //most of the time we don't have space for it
                    )
                {
                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(t);
                    if (!StoreUtility.TryFindBestBetterStoreCellFor(t, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true))
                    {
                        JobFailReason.Is("NoEmptyPlaceLower".Translate());
                        return(false);
                    }

                    WorkGiver_HaulToInventory haulWG = (WorkGiver_HaulToInventory)pawn.workSettings.WorkGiversInOrderNormal.Find(wg => wg is WorkGiver_HaulToInventory);

                    Job haul = haulWG.JobOnThing(pawn, t, forced);
                    __result = haul;
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 19
0
        static void DoIt()
        {
            Store storey = new Store();

            var thingy = BuildMeOne();

            var id = storey.Create(thingy);

            storey.SaveChanges();

            var rebuilt = storey.TryRetrieve <SimplePoco>(id);

            rebuilt.RootName = "Update now!!!";
            storey.Update(id, rebuilt);
            storey.SaveChanges();

            //storey.Delete<SimplePoco>(id);
            //storey.SaveChanges();
            var firstEntryId = (new NoSQLContext()).Store.OrderBy(a => a.DateCreated).First().StoreId;
            var firstItem    = StoreUtility.TryRetrieve <SimplePoco>(firstEntryId);

            firstItem.RootName += " and reborn!!!";
            StoreUtility.Update(firstEntryId, firstItem);

            Console.ReadKey();
        }
        public override string GetReport()
        {
            Thing hauledThing = TargetThingA;

            IntVec3   destLoc   = pawn.jobs.curJob.targetB.Cell;
            string    destName  = null;
            SlotGroup destGroup = StoreUtility.GetSlotGroup(destLoc);

            if (destGroup != null)
            {
                destName = destGroup.parent.SlotYielderLabel();
            }

            string repString;

            if (destName != null)
            {
                repString = "ReportHaulingTo".Translate(hauledThing.LabelCap, destName);
            }
            else
            {
                repString = "ReportHauling".Translate(hauledThing.LabelCap);
            }

            return(repString);
        }
Exemplo n.º 21
0
        public override string GetReport()
        {
            Vehicle_Cart cart = TargetThingA as Vehicle_Cart;

            IntVec3   destLoc   = new IntVec3(-1000, -1000, -1000);
            string    destName  = null;
            SlotGroup destGroup = null;

            if (pawn.jobs.curJob.targetB != null)
            {
                destLoc   = pawn.jobs.curJob.targetB.Cell;
                destGroup = StoreUtility.GetSlotGroup(destLoc);
            }

            if (destGroup != null)
            {
                destName = destGroup.parent.SlotYielderLabel();
            }

            string repString;

            if (destName != null)
            {
                repString = "ReportDismountingOn".Translate(cart.LabelCap, destName);
            }
            else
            {
                repString = "ReportDismounting".Translate(cart.LabelCap);
            }

            return(repString);
        }
        public static bool Prefix(Pawn pawn, Thing thing, WorkGiver_HaulToInventory __instance, bool forced, ref bool __result)
        {
            #region PickUpAndHaul code
            //bulky gear (power armor + minigun) so don't bother.
            if (MassUtility.GearMass(pawn) / MassUtility.Capacity(pawn) >= 0.8f)
            {
                return(false);
            }

            if (!WorkGiver_HaulToInventory.GoodThingToHaul(thing, pawn) || !HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, forced))
            {
                return(false);
            }

            StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing);
            bool            foundCell       = StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out IntVec3 storeCell, true);
            #endregion

            if (!foundCell)
            {
                __result = false;
            }
            else
            {
                SlotGroup slotGroup = pawn.Map.haulDestinationManager.SlotGroupAt(storeCell);
                __result = !(slotGroup != null && Limits.HasLimit(slotGroup.Settings) && Limits.GetLimit(slotGroup.Settings) >= slotGroup.TotalPrecalculatedItemsStack());
            }

            return(false);
        }
Exemplo n.º 23
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Log.Message("I am inside the job now, with "+pawn.ToString(), false);
            Building_ItemProcessor building_processor = (Building_ItemProcessor)this.job.GetTarget(TargetIndex.A).Thing;

            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_General.DoAtomic(delegate
            {
                this.job.count = 1;
            }));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(240).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing newProduct;
                    if (building_processor.productsToTurnInto != null && building_processor.productsToTurnInto.Count > 0)
                    {
                        newProduct = ThingMaker.MakeThing(ThingDef.Named(building_processor.productsToTurnInto[(int)building_processor.qualityNow]));
                    }
                    else
                    {
                        newProduct = ThingMaker.MakeThing(ThingDef.Named(building_processor.productToTurnInto));
                    }

                    newProduct.stackCount = building_processor.amount;

                    if ((newProduct.TryGetComp <CompIngredients>() is CompIngredients ingredientComp) && !building_processor.compItemProcessor.Props.ignoresIngredientLists)
                    {
                        ingredientComp.ingredients = building_processor.ingredients;
                    }
                    if (building_processor.usingQualityIncreasing && newProduct.TryGetComp <CompQuality>() is CompQuality qualityComp)
                    {
                        qualityComp.SetQuality(building_processor.qualityNow, ArtGenerationContext.Colony);
                    }

                    GenSpawn.Spawn(newProduct, building_processor.InteractionCell, building_processor.Map);
                    building_processor.processorStage = ProcessorStage.ProductRemoved;
                    building_processor.ResetEverything();
                    building_processor.DestroyIngredients();

                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(newProduct);
                    IntVec3 c;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(newProduct, this.pawn, this.Map, currentPriority, this.pawn.Faction, out c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, newProduct);
                        this.job.count = newProduct.stackCount;
                    }
                    else
                    {
                        this.EndJobWith(JobCondition.Incompletable);
                    }
                },
Exemplo n.º 24
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Log.Message(pawn + " JobGiver_StockUp");
            if (pawn.StockUpIsFull())
            {
                return(null);
            }

            Log.Message("Skip need tend?");
            if (pawn.Map.mapPawns.AllPawnsSpawned.Any(p => HealthAIUtility.ShouldBeTendedNow(p) && pawn.CanReserveAndReach(p, PathEndMode.ClosestTouch, Danger.Deadly)))
            {
                return(null);
            }

            Log.Message("any things?");
            IEnumerable <Thing> things    = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableEver);
            Predicate <Thing>   validator = (Thing t) => pawn.StockingUpOn(t) && pawn.StockUpNeeds(t) > 0 && pawn.CanReserve(t, FindBestMedicine.maxPawns, 1) && !t.IsForbidden(pawn);
            Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999, validator);

            if (thing != null)
            {
                int pickupCount = Math.Min(pawn.StockUpNeeds(thing), MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing));
                Log.Message(pawn + " stock thing is " + thing + ", count " + pickupCount);
                if (pickupCount > 0)
                {
                    return new Job(SmartMedicineJobDefOf.StockUp, thing)
                           {
                               count = pickupCount
                           }
                }
                ;
            }

            Log.Message(pawn + " looking to return");
            Thing toReturn = pawn.StockUpThingToReturn();

            if (toReturn == null)
            {
                return(null);
            }
            Log.Message("returning " + toReturn);

            int dropCount = -pawn.StockUpNeeds(toReturn);

            Log.Message("dropping " + dropCount);
            if (StoreUtility.TryFindBestBetterStoreCellFor(toReturn, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 dropLoc, true))
            {
                return new Job(SmartMedicineJobDefOf.StockDown, toReturn, dropLoc)
                       {
                           count = dropCount
                       }
            }
            ;
            Log.Message("nowhere to store");
            return(null);
        }
    }
}
Exemplo n.º 25
0
 /// <summary>
 /// Sets the coupon display.
 /// </summary>
 private void SetCouponDisplay()
 {
     if (order.DiscountAmount > 0)
     {
         lblCouponInformationDisplay.Text      = StoreUtility.GetFormattedAmount(order.DiscountAmount, true);
         cpeCouponInformationDisplay.Collapsed = false;
         //acCheckout.SelectedIndex = acCheckout.SelectedIndex + 1; //Dont advance this because they may have adjusted the cart.
     }
 }
Exemplo n.º 26
0
        public static int TotalHeldItemsStack(this SlotGroup slotGroup)
        {
            if (slotGroup == null)
            {
                return(0);
            }

            return(slotGroup.HeldThings.Where(x => StoreUtility.IsInValidStorage(x)).Sum(y => y.stackCount));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve(aquacultureBasinIndex));

            Building_AquacultureBasin aquacultureBasin = this.TargetThingA as Building_AquacultureBasin;

            yield return(Toils_Goto.GotoThing(aquacultureBasinIndex, PathEndMode.InteractionCell));

            yield return(Toils_General.Wait(120).WithProgressBarToilDelay(aquacultureBasinIndex));

            Toil getAquacultureBasinProduction = new Toil()
            {
                initAction = () =>
                {
                    Job curJob = this.pawn.jobs.curJob;

                    Thing product = aquacultureBasin.GetProduction();
                    if (product == null)
                    {
                        this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                    else
                    {
                        GenSpawn.Spawn(product, aquacultureBasin.InteractionCell, this.Map);

                        IntVec3 storageCell;
                        if (StoreUtility.TryFindBestBetterStoreCellFor(product, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true))
                        {
                            this.pawn.carryTracker.TryStartCarry(product);
                            curJob.targetB = storageCell;
                            curJob.targetC = product;
                            curJob.count   = 99999;
                        }
                        else
                        {
                            this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                        }
                    }
                }
            };

            yield return(getAquacultureBasinProduction);

            // Reserve the product and storage cell.
            yield return(Toils_Reserve.Reserve(TargetIndex.B));

            yield return(Toils_Reserve.Reserve(TargetIndex.C));

            yield return(Toils_Reserve.Release(aquacultureBasinIndex));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true));
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.StockUpIsFull())
            {
                return(null);
            }
            Log.Message($"{pawn} needs stocking up");

            if (Skip(pawn))
            {
                return(null);
            }

            Log.Message($"any things?");
            Predicate <Thing> validator = (Thing t) => pawn.StockingUpOn(t) && pawn.StockUpNeeds(t) > 0 && pawn.CanReserve(t, FindBestMedicine.maxPawns, 1) && !t.IsForbidden(pawn);
            Thing             thing     = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999, validator);

            if (thing != null)
            {
                int pickupCount = Math.Min(pawn.StockUpNeeds(thing), MassUtility.CountToPickUpUntilOverEncumbered(pawn, thing));
                Log.Message($"{pawn} stock thing is {thing}, count {pickupCount}");
                if (pickupCount > 0)
                {
                    return new Job(SmartMedicineJobDefOf.StockUp, thing)
                           {
                               count = pickupCount
                           }
                }
                ;
            }

            Log.Message($"{pawn} looking to return");
            Thing toReturn = pawn.StockUpThingToReturn();

            if (toReturn == null)
            {
                return(null);
            }
            Log.Message($"returning {toReturn}");

            int dropCount = -pawn.StockUpNeeds(toReturn);

            Log.Message($"dropping {dropCount}");
            if (StoreUtility.TryFindBestBetterStoreCellFor(toReturn, pawn, pawn.Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 dropLoc, true))
            {
                return new Job(SmartMedicineJobDefOf.StockDown, toReturn, dropLoc)
                       {
                           count = dropCount
                       }
            }
            ;
            Log.Message($"nowhere to store");
            return(null);
        }
    }
}
Exemplo n.º 29
0
        /// <summary>
        /// Handles the ItemDataBound event of the dlCatalog control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataListItemEventArgs"/> instance containing the event data.</param>
        void dlCatalog_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Product product = e.Item.DataItem as Product;
                if (product == null)
                {
                    return;
                }
                HyperLink imageLink  = e.Item.FindControl("hlImageLink") as HyperLink;
                site      masterPage = this.Page.Master as site;
                if (imageLink != null && !string.IsNullOrEmpty(product.DefaultImagePath))
                {
                    imageLink.ImageUrl = ImageProcess.GetProductThumbnailUrl(product.DefaultImagePath);
                }

                Label retailPrice = e.Item.FindControl("lblRetailPrice") as Label;
                if (masterPage != null)
                {
                    if (masterPage.SiteSettings.DisplayRetailPrice && product.RetailPrice != 0)
                    {
                        if (retailPrice != null)
                        {
                            retailPrice.Text = StoreUtility.GetFormattedAmount(product.RetailPrice, true);
                        }
                    }
                    else
                    {
                        retailPrice.Visible = false;
                    }
                }
                Label ourPrice = e.Item.FindControl("lblOurPrice") as Label;
                if (ourPrice != null)
                {
                    ourPrice.Text = StoreUtility.GetFormattedAmount(product.DisplayPrice, true);
                }
                if (masterPage.SiteSettings.AddTaxToPrice && TaxService.GetDefaultTaxProvider().IsProductLevelTaxProvider)
                {
                    Label taxApplied = e.Item.FindControl("lblTaxApplied") as Label;
                    if (taxApplied != null)
                    {
                        taxApplied.Visible = true;
                    }
                }
                AjaxControlToolkit.Rating ajaxRating = e.Item.FindControl("ajaxRating") as AjaxControlToolkit.Rating;
                if (ajaxRating != null && masterPage.SiteSettings.DisplayRatings)
                {
                    ajaxRating.GroupingText  = LocalizationUtility.GetText("lblAverageRating");
                    ajaxRating.CurrentRating = product.Rating;
                }
                else
                {
                    ajaxRating.Visible = false;
                }
            }
        }
Exemplo n.º 30
0
        public static void DeregisterHaulableItem(Thing haulableThing)
        {
            Map map = haulableThing.Map;

            if (map != null)
            {
                int storagePriority = (int)StoreUtility.CurrentStoragePriorityOf(haulableThing);
                getWaitingForZoneBetterThan(map)[storagePriority].Remove(haulableThing);
                RemoveThingFromAwaitingHaulingHashSets(haulableThing);
            }
        }