Example #1
0
        public static void DeconstructDropStuff(Thing oldThing)
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }

            ThingDef oldDef   = oldThing.def;
            ThingDef stuffDef = oldThing.Stuff;

            //preferably GenLeaving.DoLeavingsFor here, but don't want to drop non-stuff things.
            if (GenLeaving.CanBuildingLeaveResources(oldThing, DestroyMode.Deconstruct))
            {
                int count      = TotalStuffNeeded(oldDef, stuffDef);
                int leaveCount = GetBuildingResourcesLeaveCalculator(oldThing, DestroyMode.Deconstruct)(count);
                if (leaveCount > 0)
                {
                    Thing leftThing = ThingMaker.MakeThing(stuffDef);
                    leftThing.stackCount = leaveCount;
#pragma warning disable CS0618 // Type or member is obsolete
                    GenDrop.TryDropSpawn(leftThing, oldThing.Position, oldThing.Map, ThingPlaceMode.Near, out Thing dummyThing);
#pragma warning restore CS0618 // Type or member is obsolete
                }
            }
        }
Example #2
0
        private static void DropLoadedThing(Pawn thingHolder, Thing thing, int countToDrop)
        {
            var pos = thingHolder?.Position ?? (thing.PositionHeld.IsValid
                ? thing.PositionHeld
                : thing.Position);
            var map = thingHolder?.Map ?? thing.MapHeld ?? thing.Map;

            if (pos == null || !pos.IsValid || map == null)
            {
                Log.Error("Couldn't drop thing " + thing.ToString());
            }
            else
            {
                if (thing.stackCount == countToDrop)
                {
                    thing.holdingOwner.TryDrop(thing, pos, map, ThingPlaceMode.Near, out Thing _);
                }
                else
                {
                    var newThing = thing.SplitOff(countToDrop);
                    GenDrop.TryDropSpawn(newThing, pos, map, ThingPlaceMode.Near, out Thing _);
                }
                ShowDropMessage(thing.LabelNoCount, countToDrop);
            }
        }
Example #3
0
        private void DoItemsLists(Rect inRect, ref float curY)
        {
            CompTransporter transporter = this.Transporter;
            Rect            position    = new Rect(0f, curY, (inRect.width - 10f) / 2f, inRect.height);
            float           a           = 0f;

            GUI.BeginGroup(position);
            Widgets.ListSeparator(ref a, position.width, "ItemsToLoad".Translate());
            bool flag = false;

            if (transporter.leftToLoad != null)
            {
                for (int i = 0; i < transporter.leftToLoad.Count; i++)
                {
                    TransferableOneWay t = transporter.leftToLoad[i];
                    if (t.CountToTransfer > 0 && t.HasAnyThing)
                    {
                        flag = true;
                        this.DoThingRow(t.ThingDef, t.CountToTransfer, t.things, position.width, ref a, delegate(int x)
                        {
                            t.ForceTo(t.CountToTransfer - x);
                            this.EndJobForEveryoneHauling(t);
                        });
                    }
                }
            }
            if (!flag)
            {
                Widgets.NoneLabel(ref a, position.width, null);
            }
            GUI.EndGroup();
            Rect  position2 = new Rect((inRect.width + 10f) / 2f, curY, (inRect.width - 10f) / 2f, inRect.height);
            float b         = 0f;

            GUI.BeginGroup(position2);
            Widgets.ListSeparator(ref b, position2.width, "LoadedItems".Translate());
            bool flag2 = false;

            for (int j = 0; j < transporter.innerContainer.Count; j++)
            {
                Thing t = transporter.innerContainer[j];
                flag2 = true;
                ITab_TransporterContents.tmpSingleThing.Clear();
                ITab_TransporterContents.tmpSingleThing.Add(t);
                this.DoThingRow(t.def, t.stackCount, ITab_TransporterContents.tmpSingleThing, position2.width, ref b, delegate(int x)
                {
                    Thing thing;
                    GenDrop.TryDropSpawn(t.SplitOff(x), this.SelThing.Position, this.SelThing.Map, ThingPlaceMode.Near, out thing, null, null);
                });
                ITab_TransporterContents.tmpSingleThing.Clear();
            }
            if (!flag2)
            {
                Widgets.NoneLabel(ref b, position.width, null);
            }
            GUI.EndGroup();
            curY += Mathf.Max(a, b);
        }
Example #4
0
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            foreach (var pair in items)
            {
                GenDrop.TryDropSpawn(pair, this.Position, this.Map, ThingPlaceMode.Near, out Thing t);
            }

            items.Clear();

            base.Destroy(mode);
        }
Example #5
0
        private static void DropToWorldObject(WorldObject place, List <ThingEntry> things, string from)
        {
            GlobalTargetInfo ti = new GlobalTargetInfo(place);

            if (place is FactionBase && ((FactionBase)place).Map != null)
            {
                var cell = GameUtils.GetTradeCell(((FactionBase)place).Map);
                ti = new GlobalTargetInfo(cell, ((FactionBase)place).Map);
                Thing thinXZ;
                foreach (var thing in things)
                {
                    var thin = thing.CreateThing(false);
                    var map  = ((FactionBase)place).Map;
                    if (thin is Pawn)
                    {
                        GenSpawn.Spawn((Pawn)thin, cell, map);
                    }
                    else
                    {
                        GenDrop.TryDropSpawn(thin, cell, map, ThingPlaceMode.Near, out thinXZ, null);
                    }
                }
            }
            else if (place is Caravan)
            {
                var pawns = (place as Caravan).PawnsListForReading;
                foreach (var thing in things)
                {
                    var thin = thing.CreateThing(false);
                    if (thin is Pawn)
                    {
                        (place as Caravan).AddPawn(thin as Pawn, true);
                        GameUtils.SpawnSetupOnCaravan(thin as Pawn);
                    }
                    else
                    {
                        var p = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thin, pawns, null);
                        if (p != null)
                        {
                            p.inventory.innerContainer.TryAdd(thin, true);
                        }
                    }
                }
            }
            Find.LetterStack.ReceiveLetter("OCity_UpdateWorld_Trade".Translate()
                                           , string.Format("OCity_UpdateWorld_TradeDetails".Translate()
                                                           , from
                                                           , place.LabelCap
                                                           , things.Aggregate("", (r, i) => r + Environment.NewLine + i.Name + " x" + i.Count))
                                           , LetterDefOf.PositiveEvent
                                           , ti
                                           , null);
        }
 public static bool TryDropAndSetForbidden(Thing th, IntVec3 pos, Map map, ThingPlaceMode mode, out Thing resultingThing, bool forbidden)
 {
     if (GenDrop.TryDropSpawn(th, pos, map, ThingPlaceMode.Near, out resultingThing, (Action <Thing, int>)null))
     {
         if (resultingThing != null)
         {
             resultingThing.SetForbidden(forbidden, false);
         }
         return(true);
     }
     resultingThing = null;
     return(false);
 }
    public static void YieldExtra(Pawn pawn, ThingDef bitsdef)
    {
        var num       = Mathf.Max(1, Mathf.RoundToInt(RndBits(1, 3) * Find.Storyteller.difficulty.mineYieldFactor));
        var bitsthing = ThingMaker.MakeThing(bitsdef);

        bitsthing.stackCount = bitsthing.def.stackLimit > 1 ? num : 1;

        GenDrop.TryDropSpawn(bitsthing, pawn.Position, pawn.Map, ThingPlaceMode.Near, out var newbitsthing);
        if (!pawn.IsColonist && newbitsthing.def.EverHaulable &&
            !newbitsthing.def.designateHaulable)
        {
            newbitsthing.SetForbidden(true);
        }
    }
        public void DropResult()
        {
            if (result == null)
            {
                return;
            }

            GenDrop.TryDropSpawn(result, InteractionCell, Map, ThingPlaceMode.Near, out Thing resultingThing);
            result = null;

            if (!Infinity)
            {
                ProduceCount = Mathf.Clamp(ProduceCount - 1, 0, ProduceCount);
                buffer       = ProduceCount.ToString();
            }
        }
        private void DeconstructGunAndReset()
        {
            if (gun != null && PositionHeld != null && MapHeld != null)
            {
                Thing resultingThing;
                GenDrop.TryDropSpawn(gun, PositionHeld, MapHeld, ThingPlaceMode.Near, out resultingThing);
            }
            forceCreateGunAndTop = false;
            collectingGunAllowed = false;
            gun = null;
            top = null;

            ResetCurrentTarget();
            burstCooldownTicksLeft = 0;

            loaded   = false;
            holdFire = false;
        }
Example #10
0
        public static void dropSidearm(Pawn pawn, Thing weapon, bool intentionalDrop)
        {
            if (weapon == null)
            {
                return;
            }
            if (pawn.IsQuestLodger() && intentionalDrop)
            {
                return;
            }

            if (!intentionalDrop)
            {
                DoFumbleMote(pawn);
            }

            if (pawn.equipment.Primary == weapon)
            {
                Pawn_EquipmentTracker_TryDropEquipment.dropEquipmentSourcedBySimpleSidearms = true;
                pawn.equipment.TryDropEquipment(pawn.equipment.Primary, out _, pawn.Position, false);
                Pawn_EquipmentTracker_TryDropEquipment.dropEquipmentSourcedBySimpleSidearms = false;
            }
            else
            {
                if (weapon.stackCount > 1)
                {
                    var toDrop = weapon.SplitOff(1);
                    GenDrop.TryDropSpawn(toDrop, pawn.Position, pawn.Map, ThingPlaceMode.Near, out _);
                }
                else
                {
                    pawn.inventory.innerContainer.TryDrop(weapon, pawn.Position, pawn.Map, ThingPlaceMode.Near, out _, null);
                }
            }

            CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);

            if (pawnMemory == null)
            {
                return;
            }
            pawnMemory.InformOfDroppedSidearm(weapon, intentionalDrop);
        }
Example #11
0
        public static bool TryDropAndSetForbidden(Thing th, IntVec3 pos, Map map, ThingPlaceMode mode, out Thing resultingThing, bool forbidden)
        {
            bool result;

            if (GenDrop.TryDropSpawn(th, pos, map, ThingPlaceMode.Near, out resultingThing, null, null))
            {
                if (resultingThing != null)
                {
                    resultingThing.SetForbidden(forbidden, false);
                }
                result = true;
            }
            else
            {
                resultingThing = null;
                result         = false;
            }
            return(result);
        }
Example #12
0
        public void DropContainedResources()
        {
            for (int i = 0; i < ContainedResources.Count; i++)
            {
                var resource = ContainedResources.ElementAt(i);

                if (resource.Value > 0)
                {
                    if (CellFinder.TryFindRandomCellNear(Position, Map, 4, null, out IntVec3 result))
                    {
                        Thing t = ThingMaker.MakeThing(resource.Key);
                        t.stackCount = resource.Value;

                        GenDrop.TryDropSpawn(t, result, Map, ThingPlaceMode.Near, out Thing resultingThing);

                        ContainedResources[resource.Key] = 0;
                    }
                }
            }
        }
        public void DoVictory()
        {
            settlement.AttackRepelled = true;
            TransferColonists(false);

            int savedPawns = friendlyPawnsBeforeAttack - friendlyPawns.Where(p => p != null && p.Dead).Count();

            if (savedPawns <= 0)
            {
                DoLose(true);
                return;
            }

            settlement.Quest.EndQuest(null, QuestRim.EndCondition.Success);

            settlement.Faction.TryAffectGoodwillWith(Faction.OfPlayer, 2 + savedPawns);

            FloatRange value      = (RewardMarketValueRange * (int)settlement.Faction.def.techLevel);
            int        pawnsValue = savedPawns * 50;

            value.min += pawnsValue;
            value.max += pawnsValue;
            List <Thing>  rewards = GenerateRewards(value);
            StringBuilder builder = new StringBuilder();

            foreach (var thing in rewards)
            {
                builder.Append($"\n- {thing.LabelCap}");
                GenDrop.TryDropSpawn(thing, settlement.Map.Center, settlement.Map, ThingPlaceMode.Near, out Thing t);
            }
            DiaNode   node   = new DiaNode("AttackedFriendlySettlementDefendVictory".Translate(settlement.Faction, savedPawns, builder.ToString()));
            DiaOption option = new DiaOption("OK");

            node.options.Add(option);
            option.resolveTree = true;

            var dialog = new Dialog_NodeTree(node);

            Find.WindowStack.Add(dialog);
        }
 internal static bool TryDrop(this ThingContainer _this, Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, int count, out Thing resultingThing, Action <Thing, int> placedAction = null)
 {
     if (thing.stackCount < count)
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to drop ",
             count,
             " of ",
             thing,
             " while only having ",
             thing.stackCount
         }));
         count = thing.stackCount;
     }
     if (count == thing.stackCount)
     {
         if (GenDrop.TryDropSpawn(thing, dropLoc, map, mode, out resultingThing, placedAction))
         {
             _this.Remove(thing);
             CR_Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker);   // Thing dropped, update inventory
             return(true);
         }
         return(false);
     }
     else
     {
         Thing thing2 = thing.SplitOff(count);
         if (GenDrop.TryDropSpawn(thing2, dropLoc, map, mode, out resultingThing, placedAction))
         {
             CR_Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker);   // Thing dropped, update inventory
             return(true);
         }
         thing.stackCount += thing2.stackCount;
         return(false);
     }
 }
Example #15
0
        private float GenerateItems(Map map)
        {
            float points = 200;

            if (Rewards != null)
            {
                foreach (var item in Rewards)
                {
                    points += item.MarketValue * item.stackCount;

                    var pos = CellFinder.RandomClosewalkCellNear(map.Center, map, 5, x => x.Walkable(map) && !x.Fogged(map));
                    if (pos != IntVec3.Invalid)
                    {
                        GenDrop.TryDropSpawn(item, pos, map, ThingPlaceMode.Near, out Thing result);
                    }
                }

                points *= 0.6f;

                Rewards.Clear();
            }

            return(points);
        }
        public static Thing SpawnItem(ThingDef itemDef, ThingDef stuff, int quantity, IntVec3 position, Map map, float radius)
        {
            Thing item = null;
            int   remainingQuantity = quantity;

            while (remainingQuantity > 0)
            {
                int stackCount = 0;
                if (remainingQuantity > itemDef.stackLimit)
                {
                    stackCount = itemDef.stackLimit;
                }
                else
                {
                    stackCount = remainingQuantity;
                }
                remainingQuantity -= stackCount;
                item            = ThingMaker.MakeThing(itemDef, stuff);
                item.stackCount = stackCount;
                Thing placedItem = null;
                GenDrop.TryDropSpawn(item, position + IntVec3Utility.RandomHorizontalOffset(radius), map, ThingPlaceMode.Near, out placedItem);
            }
            return(item);
        }
Example #17
0
        private void DoItemsLists(Rect inRect, ref float curY)
        {
            CompPit transporter = this.Transporter;
            Rect    position    = new Rect(0f, curY, (inRect.width - 10f) / 2f, inRect.height);
            float   a           = 0f;

            /* GUI.BeginGroup(position);
             * Widgets.ListSeparator(ref a, position.width, "ItemsToLoad".Translate());
             * bool flag = false;
             * if (transporter.leftToLoad != null)
             * {
             *   for (int i = 0; i < transporter.leftToLoad.Count; i++)
             *   {
             *       TransferableOneWay t = transporter.leftToLoad[i];
             *       if (t.CountToTransfer > 0 && t.HasAnyThing)
             *       {
             *           flag = true;
             *           this.DoThingRow(t.ThingDef, t.CountToTransfer, t.things, position.width, ref a, delegate (int x)
             *           {
             *               t.ForceTo(t.CountToTransfer - x);
             *               this.EndJobForEveryoneHauling(t);
             *           });
             *       }
             *   }
             * }
             * if (!flag)
             * {
             *   Widgets.NoneLabel(ref a, position.width, null);
             * }
             * GUI.EndGroup();*/
            Rect  position2 = new Rect(0f, curY, (inRect.width - 10f), inRect.height);
            float b         = 0f;

            GUI.BeginGroup(position2);
            Widgets.ListSeparator(ref b, position2.width, "PD_PrisonersInThePit".Translate());
            bool flag2 = false;

            for (int j = 0; j < transporter.innerContainer.Count; j++)
            {
                Thing t = transporter.innerContainer[j];
                flag2 = true;
                ITab_PitContents.tmpSingleThing.Clear();
                ITab_PitContents.tmpSingleThing.Add(t);
                this.DoThingRow(t.def, t.stackCount, ITab_PitContents.tmpSingleThing, position2.width, ref b, delegate(int x)
                {
                    Thing thing;
                    GenDrop.TryDropSpawn(t.SplitOff(x), this.SelThing.Position, this.SelThing.Map, ThingPlaceMode.Near, out thing, null, null);
                    Pawn pawn          = t as Pawn;
                    System.Random rand = new System.Random();
                    if (pawn != null)
                    {
                        pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("PD_ThrownIntoPit"), null);
                        HealthUtility.DamageUntilDowned(pawn, false);
                        BodyPartRecord brain = pawn.health.hediffSet.GetBrain();
                        double number        = rand.NextDouble();
                        if (number > 0.75 && number < 0.85)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(HediffDefOf.Dementia, pawn, brain);
                            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
                            {
                                pawn.health.AddHediff(hediff, null, null, null);
                            }
                        }
                        else if (number > 0.85 && number < 0.95)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("PD_Psychosis"), pawn, brain);
                            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
                            {
                                pawn.health.AddHediff(hediff, null, null, null);
                            }
                        }
                        else if (number > 0.95)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("PD_BrainEatingParasites"), pawn, brain);
                            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
                            {
                                pawn.health.AddHediff(hediff, null, null, null);
                            }
                        }
                    }
                });
                ITab_PitContents.tmpSingleThing.Clear();
            }
            if (!flag2)
            {
                Widgets.NoneLabel(ref b, position.width, null);
            }
            GUI.EndGroup();
            curY += Mathf.Max(a, b);
        }
Example #18
0
        public static IntVec3 SpawnList <TE>(Map map, List <TE> pawns, bool attackCell
                                             , Func <TE, bool> getPirate
                                             , Action <Thing, TE> spawn      = null
                                             , Func <Thing, IntVec3> getCell = null)
            where TE : ThingEntry
        {
            if (MainHelper.DebugMode)
            {
                Loger.Log("SpawnList...");
            }

            //на основе UpdateWorldController.DropToWorldObjectDo
            var factionPirate = Find.FactionManager.AllFactions.FirstOrDefault(f => f.def.defName == "Pirate")
                                ?? Find.FactionManager.OfAncientsHostile; //SessionClientController.Data.FactionPirate;

            IntVec3 ret = new IntVec3();

            ModBaseData.RunMainThreadSync(() =>
            {
                Thing thinXZ;
                for (int i = 0; i < pawns.Count; i++)
                {
                    var thing = pawns[i];
                    //GenSpawn.Spawn(pawn, cell, map, Rot4.Random, WipeMode.Vanish, false);

                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Prepare...");
                    }
                    var thin = PrepareSpawnThingEntry(thing, factionPirate, getPirate(thing));

                    var cell = getCell != null ? getCell(thin) : thin.Position;
                    if (i == 0)
                    {
                        ret = cell;
                    }

                    //if (MainHelper.DebugMode)
                    try
                    {
                        Loger.Log("Spawn... " + thin.Label);
                    }
                    catch
                    {
                        Loger.Log("Spawn... ");
                    }
                    if (thin is Pawn)
                    {
                        if (MainHelper.DebugMode)
                        {
                            Loger.Log("Pawn... " + thin.Position.x + " " + thin.Position.y);
                        }
                        try
                        {
                            GenSpawn.Spawn((Pawn)thin, cell, map);
                        }
                        catch (Exception exp)
                        {
                            Loger.Log("SpawnList Exception " + thing.Name + ": " + exp.ToString());
                            Thread.Sleep(5);
                            GenSpawn.Spawn((Pawn)thin, cell, map);
                        }
                    }
                    else
                    {
                        GenDrop.TryDropSpawn(thin, cell, map, ThingPlaceMode.Near, out thinXZ, null);
                    }
                    if (spawn != null)
                    {
                        spawn(thin, thing);
                    }
                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Spawn...OK");
                    }
                }
            });
            return(ret);
        }
        private static void DropToWorldObjectDo(WorldObject place, List <ThingEntry> things, string from, string text)
        {
            GlobalTargetInfo ti = new GlobalTargetInfo(place);
            var factionPirate   = SessionClientController.Data.FactionPirate;

            if (MainHelper.DebugMode)
            {
                Loger.Log("Mail================================================= {");
            }

            if (place is Settlement && ((Settlement)place).Map != null)
            {
                var map  = ((Settlement)place).Map;
                var cell = GameUtils.GetTradeCell(map);
                ti = new GlobalTargetInfo(cell, map);
                Thing thinXZ;
                foreach (var thing in things)
                {
                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Mail------------------------------------------------- {" + Environment.NewLine
                                  + thing.Data + Environment.NewLine
                                  + "Mail------------------------------------------------- }" + Environment.NewLine);
                    }
                    var thin = PrepareSpawnThingEntry(thing, factionPirate);

                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Spawn...");
                    }
                    if (thin is Pawn)
                    {
                        GenSpawn.Spawn((Pawn)thin, cell, map);
                    }
                    else
                    {
                        GenDrop.TryDropSpawn(thin, cell, map, ThingPlaceMode.Near, out thinXZ, null);
                    }
                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Spawn...OK");
                    }
                }
            }
            else if (place is Caravan)
            {
                var pawns = (place as Caravan).PawnsListForReading;
                foreach (var thing in things)
                {
                    /*
                     * thing.SetFaction(factionColonistLoadID, factionPirateLoadID);
                     * var thin = thing.CreateThing(false);
                     */
                    var thin = PrepareSpawnThingEntry(thing, factionPirate);

                    if (thin is Pawn)
                    {
                        (place as Caravan).AddPawn(thin as Pawn, true);
                        GameUtils.SpawnSetupOnCaravan(thin as Pawn);
                    }
                    else
                    {
                        var p = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thin, pawns, null);
                        if (p != null)
                        {
                            p.inventory.innerContainer.TryAdd(thin, true);
                        }
                    }
                }
            }

            if (MainHelper.DebugMode)
            {
                Loger.Log("Mail================================================= }");
            }

            Find.LetterStack.ReceiveLetter("OCity_UpdateWorld_Trade".Translate()
                                           , text
                                           , LetterDefOf.PositiveEvent
                                           , ti
                                           , null);
        }
Example #20
0
        private static void DropToWorldObjectDo(WorldObject place, List <ThingEntry> things, string from, string text)
        {
            GlobalTargetInfo ti       = new GlobalTargetInfo(place);
            var factionColonistLoadID = Find.FactionManager.OfPlayer.GetUniqueLoadID();
            var factionPirate         = Find.FactionManager.AllFactions.FirstOrDefault(f => f.def.defName == "Pirate")
                                        ?? Find.FactionManager.OfAncientsHostile;
            var factionPirateLoadID = factionPirate.GetUniqueLoadID();

            if (MainHelper.DebugMode)
            {
                Loger.Log("Mail================================================= {");
            }

            if (place is Settlement && ((Settlement)place).Map != null)
            {
                var cell = GameUtils.GetTradeCell(((Settlement)place).Map);
                ti = new GlobalTargetInfo(cell, ((Settlement)place).Map);
                Thing thinXZ;
                foreach (var thing in things)
                {
                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Mail------------------------------------------------- {" + Environment.NewLine
                                  + thing.Data + Environment.NewLine
                                  + "Mail------------------------------------------------- }" + Environment.NewLine);
                    }

                    var   prisoner = thing.SetFaction(factionColonistLoadID, factionPirateLoadID);
                    Thing thin;
                    thin = thing.CreateThing(false);
                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("SetFaction...");
                    }
                    if (thin.def.CanHaveFaction)
                    {
                        if (prisoner && thin is Pawn)
                        {
                            thin.SetFaction(factionPirate);
                            var p = thin as Pawn;
                            p.guest.SetGuestStatus(factionPirate, true);
                        }
                        else
                        {
                            thin.SetFaction(Find.FactionManager.OfPlayer);
                        }
                    }


                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Spawn...");
                    }
                    var map = ((Settlement)place).Map;
                    if (thin is Pawn)
                    {
                        GenSpawn.Spawn((Pawn)thin, cell, map);
                    }
                    else
                    {
                        GenDrop.TryDropSpawn(thin, cell, map, ThingPlaceMode.Near, out thinXZ, null);
                    }
                    if (MainHelper.DebugMode)
                    {
                        Loger.Log("Spawn...OK");
                    }
                }
            }
            else if (place is Caravan)
            {
                var pawns = (place as Caravan).PawnsListForReading;
                foreach (var thing in things)
                {
                    thing.SetFaction(factionColonistLoadID, factionPirateLoadID);
                    var thin = thing.CreateThing(false);
                    if (thin is Pawn)
                    {
                        (place as Caravan).AddPawn(thin as Pawn, true);
                        GameUtils.SpawnSetupOnCaravan(thin as Pawn);
                    }
                    else
                    {
                        var p = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thin, pawns, null);
                        if (p != null)
                        {
                            p.inventory.innerContainer.TryAdd(thin, true);
                        }
                    }
                }
            }

            if (MainHelper.DebugMode)
            {
                Loger.Log("Mail================================================= }");
            }

            Find.LetterStack.ReceiveLetter("OCity_UpdateWorld_Trade".Translate()
                                           , text
                                           , LetterDefOf.PositiveEvent
                                           , ti
                                           , null);
        }
Example #21
0
        // Token: 0x06000016 RID: 22 RVA: 0x0000259C File Offset: 0x0000079C
        public static void DoSSVape(Pawn p, Thing t)
        {
            var HediffName = "";
            var defName    = t.def.defName;

            switch (defName)
            {
            case "SSVaperRegular":
                HediffName = "SSVape_Regular_High";
                break;

            case "SSVaperFruity":
                HediffName = "SSVape_Fruity_High";
                break;

            case "SSVaperMenthol":
                HediffName = "SSVape_Menthol_High";
                break;
            }

            if (!HediffName.StartsWith("SSVape"))
            {
                return;
            }

            var hediffdef = DefDatabase <HediffDef> .GetNamed(HediffName, false);

            var SLChemDef = DefDatabase <ChemicalDef> .GetNamed("Smokeleaf");

            if (hediffdef == null)
            {
                return;
            }

            var SeverityToApply = 0.5f;

            if (SSHediffEffecter.HediffEffect(hediffdef, SeverityToApply, p, null, out _))
            {
                var SLTol = DefDatabase <HediffDef> .GetNamed("SmokeleafTolerance");

                if (SLTol != null)
                {
                    var Sev = 0.02f / p.BodySize;
                    SSHediffEffecter.HediffEffect(SLTol, Sev, p, null, out _);
                }

                if (p.RaceProps.IsFlesh)
                {
                    var addictionHediffDef = DefDatabase <HediffDef> .GetNamed("SmokeleafAddiction");

                    var hediff_Addiction = AddictionUtility.FindAddictionHediff(p, SLChemDef);
                    var hediff           = AddictionUtility.FindToleranceHediff(p, SLChemDef);
                    var num = hediff?.Severity ?? 0f;
                    if (hediff_Addiction != null)
                    {
                        hediff_Addiction.Severity += 0.06f;
                    }
                    else if (Rand.Value < 0.01f && num >= 0.15f)
                    {
                        p.health.AddHediff(addictionHediffDef);
                        if (PawnUtility.ShouldSendNotificationAbout(p))
                        {
                            Find.LetterStack.ReceiveLetter(
                                "LetterLabelNewlyAddicted".Translate(SLChemDef.label).CapitalizeFirst(),
                                "LetterNewlyAddicted".Translate(p.LabelShort, SLChemDef.label, p.Named("PAWN"))
                                .AdjustedFor(p).CapitalizeFirst(), LetterDefOf.NegativeEvent, p);
                        }
                    }

                    if (addictionHediffDef.causesNeed != null)
                    {
                        var need = p.needs.AllNeeds.Find(x => x.def == addictionHediffDef.causesNeed);
                        if (need != null)
                        {
                            var effect = 1f;
                            AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(p, SLChemDef,
                                                                                         ref effect);
                            need.CurLevel += effect;
                        }
                    }
                }
            }

            if (p?.needs != null)
            {
                var need2 = p.needs.TryGetNeed(NeedDefOf.Rest);
                if (need2 != null)
                {
                    var effect2 = -0.1f;
                    AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(p, SLChemDef, ref effect2);
                    need2.CurLevel += effect2;
                }
            }

            bool joyNeed;

            if (p == null)
            {
                joyNeed = false;
            }
            else
            {
                var needs = p.needs;
                joyNeed = needs?.joy != null;
            }

            if (joyNeed)
            {
                var Chem = DefDatabase <JoyKindDef> .GetNamed("Chemical", false);

                var needs2 = p.needs;
                if (needs2 != null)
                {
                    needs2.joy.GainJoy(0.85f, Chem);
                }
            }

            if (p?.Map != null)
            {
                var BreathOffset = new Vector3(0f, 0f, -0.04f);
                var loc          = p.Drawer.DrawPos + p.Drawer.renderer.BaseHeadOffsetAt(p.Rotation) +
                                   (p.Rotation.FacingCell.ToVector3() * 0.21f) + BreathOffset;
                for (var i = 0; i < 4; i++)
                {
                    ThrowVapeBreathPuff(loc, p.Map, p.Rotation.AsAngle, p.Position.ToVector3());
                    FleckMaker.ThrowSmoke(p.Position.ToVector3(), p.Map, 0.5f);
                }
            }

            var usesLeft = ((SSVapeData)t).SSVapeUses;

            usesLeft--;
            ((SSVapeData)t).SSVapeUses = usesLeft;
            if (usesLeft > 0)
            {
                return;
            }

            t.Destroy();
            if (p == null)
            {
                return;
            }

            GenDrop.TryDropSpawn(
                ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("SSVaperEmpty", false)), p.Position,
                p.Map, ThingPlaceMode.Near, out var newVapeThing);
            ((SSVapeData)newVapeThing).SSVapeType = "empty";
            ((SSVapeData)newVapeThing).SSVapeUses = 0;
        }
Example #22
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            foreach (var toil in base.MakeNewToils())
            {
                yield return(toil);
            }
            yield return(new Toil()
            {
                initAction = delegate
                {
                    var armorRack = TargetThingA as ArmorRack;
                    var storedRackApparel = new List <Apparel>(armorRack.GetStoredApparel());
                    var storedRackWeapon = armorRack.GetStoredWeapon();
                    var storedPawnApparel = new List <Apparel>(pawn.apparel.WornApparel);
                    var storedPawnWeapon = pawn.equipment.Primary;
                    Thing lastResultingThing;

                    armorRack.InnerContainer.Clear();
                    foreach (var pawnApparel in storedPawnApparel)
                    {
                        if (armorRack.Accepts(pawnApparel))
                        {
                            pawn.apparel.Remove(pawnApparel);
                            armorRack.InnerContainer.TryAdd(pawnApparel);
                        }
                    }

                    var leftoverRackApparel = new List <Apparel>();
                    foreach (var rackApparel in storedRackApparel)
                    {
                        if (armorRack.Accepts(rackApparel))
                        {
                            armorRack.InnerContainer.TryAdd(rackApparel);
                        }
                        else
                        {
                            leftoverRackApparel.Add(rackApparel);
                        }
                    }

                    foreach (Apparel leftoverApparel in leftoverRackApparel)
                    {
                        if (ApparelUtility.HasPartsToWear(pawn, leftoverApparel.def) && pawn.apparel.CanWearWithoutDroppingAnything(leftoverApparel.def))
                        {
                            pawn.apparel.Wear(leftoverApparel);
                        }
                        else
                        {
                            GenDrop.TryDropSpawn(leftoverApparel, armorRack.Position, armorRack.Map,
                                                 ThingPlaceMode.Near, out lastResultingThing);
                        }
                    }

                    int hasRackWeapon = storedRackWeapon == null ? 0x00 : 0x01;
                    int hasPawnWeapon = storedPawnWeapon == null ? 0x00 : 0x10;
                    switch (hasRackWeapon | hasPawnWeapon)
                    {
                    case 0x11:
                        {
                            if (armorRack.Accepts(storedPawnWeapon))
                            {
                                pawn.equipment.Remove(storedPawnWeapon);
                                armorRack.InnerContainer.TryAdd(storedPawnWeapon);
                                pawn.equipment.MakeRoomFor((ThingWithComps)storedRackWeapon);
                                pawn.equipment.AddEquipment((ThingWithComps)storedRackWeapon);
                            }
                            else
                            {
                                armorRack.InnerContainer.TryAdd(storedRackWeapon);
                            }
                            break;
                        }

                    case 0x01:
                        armorRack.InnerContainer.TryAdd(storedRackWeapon);
                        break;

                    case 0x10:
                        {
                            if (armorRack.Accepts(storedPawnWeapon))
                            {
                                pawn.equipment.Remove(storedPawnWeapon);
                                armorRack.InnerContainer.TryAdd(storedPawnWeapon);
                            }
                            break;
                        }
                    }
                    ForbidUtility.SetForbidden(TargetThingA, false);
                    var useComp = pawn.GetComp <ArmorRackUseCommandComp>();
                    if (useComp != null)
                    {
                        useComp.CurArmorRackJobDef = ArmorRacksJobDefOf.ArmorRacks_JobWearRack;
                    }
                }
            });
        }
Example #23
0
        private void TakeThing(Toil toil)
        {
            Job curJob = toil.actor.jobs.curJob;

            //Toils_Haul.ErrorCheckForCarry(toil.actor, Item);
            if (curJob.count == 0)
            {
                throw new Exception(string.Concat("BuyItem job had count = ", curJob.count, ". Job: ", curJob));
            }

            if (Item.MarketValue <= 0)
            {
                return;
            }
            int maxSpace  = toil.actor.GetInventorySpaceFor(Item);
            var inventory = toil.actor.inventory.innerContainer;

            Thing silver = inventory.FirstOrDefault(i => i.def == ThingDefOf.Silver);

            if (silver == null)
            {
                return;
            }

            var itemCost      = Item.MarketValue * PriceFactor;
            var maxAffordable = Mathf.FloorToInt(silver.stackCount / itemCost);

            if (maxAffordable < 1)
            {
                return;
            }

            // Changed formula a bit, so guests are less likely to leave small stacks if they can afford it
            var maxWanted = Rand.RangeInclusive(1, maxAffordable);
            int count     = Mathf.Min(Item.stackCount, maxSpace, maxWanted);

            var price = Mathf.FloorToInt(count * itemCost);

            if (silver.stackCount < price)
            {
                return;
            }

            var map = toil.actor.MapHeld;
            var inventoryItemsBefore = inventory.ToArray();
            var thing = Item.SplitOff(count);
            int tookItems;

            if (thing.def.IsApparel && thing is Apparel)
            {
                toil.actor.apparel.Wear((Apparel)thing);
                tookItems = thing.stackCount;
            }
            else if (thing.def.IsWeapon && thing is ThingWithComps && thing.def.IsWithinCategory(ThingCategoryDefOf.Weapons))
            {
                var thingWithComps = (ThingWithComps)thing;
                var primary        = pawn.equipment.Primary;
                if (thing.def.equipmentType == EquipmentType.Primary && primary != null)
                {
                    if (!pawn.equipment.TryTransferEquipmentToContainer(primary, pawn.inventory.innerContainer))
                    {
                        Log.Message(pawn.Name.ToStringShort + " failed to take " + primary + " to his inventory.");
                    }
                }

                pawn.equipment.AddEquipment(thingWithComps);
                pawn.equipment.Notify_EquipmentAdded(thingWithComps);
                if (thingWithComps.def.soundInteract != null)
                {
                    thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
                }
                tookItems = thing.stackCount;
            }
            else
            {
                tookItems = inventory.TryAdd(thing, count);
            }

            var comp = toil.actor.GetComp <CompGuest>();

            if (tookItems > 0 && comp != null)
            {
                inventory.TryDrop(silver, toil.actor.Position, map, ThingPlaceMode.Near, price, out silver);

                // Check what's new in the inventory (TryAdd creates a copy of the original object!)
                var newItems = toil.actor.inventory.innerContainer.Except(inventoryItemsBefore).ToArray();
                foreach (var item in newItems)
                {
                    //Log.Message(pawn.NameStringShort + " bought " + item.Label);
                    comp.boughtItems.Add(item.thingIDNumber);

                    // Handle trade stuff
                    Trade(toil, item, map);
                }
            }
            else
            {
                // Failed to equip or take
                Thing resultingThing;
                if (!GenDrop.TryDropSpawn(thing, toil.actor.Position, map, ThingPlaceMode.Near, out resultingThing))
                {
                    Log.Warning(toil.actor.Name.ToStringShort + " failed to buy and failed to drop " + thing.Label);
                }
            }
        }
Example #24
0
        // Token: 0x06000083 RID: 131 RVA: 0x00004D85 File Offset: 0x00002F85

        // Token: 0x06000084 RID: 132 RVA: 0x00004D90 File Offset: 0x00002F90
        public void MakerEject(Building b, ThingDef t, int numProducts, List <Building> candidatesout, out int remaining)
        {
            remaining = numProducts;
            if (candidatesout.Count <= 0)
            {
                return;
            }

            for (var i = 0; i < candidatesout.Count; i++)
            {
                if (i == 0)
                {
                    var unused = candidatesout[i];
                }

                if (numProducts <= 0)
                {
                    continue;
                }

                var thingList = candidatesout[i].Position.GetThingList(candidatesout[i].Map);
                if (thingList.Count <= 0)
                {
                    continue;
                }

                var founditem = false;
                var blocked   = false;
                foreach (var thing in thingList)
                {
                    if (thing.def == t)
                    {
                        founditem = true;
                        var canPlace = thing.def.stackLimit - thing.stackCount;
                        if (canPlace <= 0)
                        {
                            continue;
                        }

                        if (canPlace >= numProducts)
                        {
                            thing.stackCount += numProducts;
                            remaining        -= numProducts;
                            numProducts       = 0;
                        }
                        else
                        {
                            thing.stackCount += canPlace;
                            numProducts      -= canPlace;
                            remaining        -= canPlace;
                        }
                    }
                    else if (!(thing is Building))
                    {
                        blocked = true;
                    }
                }

                if (founditem || blocked)
                {
                    continue;
                }

                var tStackLimit = t.stackLimit;
                var newProduct  = ThingMaker.MakeThing(t);
                if (!candidatesout[i].Position.IsValidStorageFor(candidatesout[i].Map, newProduct))
                {
                    continue;
                }

                if (tStackLimit >= numProducts)
                {
                    newProduct.stackCount = numProducts;
                    remaining            -= numProducts;
                    numProducts           = 0;
                }
                else
                {
                    newProduct.stackCount = tStackLimit;
                    numProducts          -= tStackLimit;
                    remaining            -= tStackLimit;
                }

                GenDrop.TryDropSpawn(newProduct, candidatesout[i].Position, candidatesout[i].Map,
                                     ThingPlaceMode.Direct, out _);
            }
        }
Example #25
0
        public bool Run()
        {
            /*
             * GameUtils.ShowDialodOKCancel("asdasda",
             *  () => Log.Message("Test OK"),
             *  () => Log.Message("Test Cancel")
             *  );
             * return true;
             */
            /*
             * var formm = new Dialog_Exchenge(Find.Maps[0]);
             * Find.WindowStack.Add(formm);
             * return true;
             * // */
            return(false);

            /*
             * var lll = ScenarioLister.ScenariosInCategory(ScenarioCategory.FromDef);
             *
             * File.WriteAllText(Loger.PathLog + @"ScenarioLister.txt", TextObj(lll), Encoding.UTF8);
             * return true;
             */
            try
            {
                Log.Message("DevelopTest Run");
                Loger.Log("");
                Loger.Log("DevelopTest Run");

                var pawns = Find.WorldPawns.AllPawnsAlive.ToList();

                //Fedon,Huntsman,Ally,Lilith,Tater,Jesse,Kentucky
                //Log.Message(string.Join(",", pawns.Select(p => p.NameStringShort).ToArray()));

                var pawn = pawns.Where(p => p.Name.ToStringShort == "Huntsman").FirstOrDefault();
                File.WriteAllText(Loger.PathLog + @"Huntsman.txt", TextObj(pawn), Encoding.UTF8);

                var   msg     = "";
                var   map     = Find.Maps[0];
                var   pawnsMy = map.mapPawns.AllPawnsSpawned.First();
                Thing thinXZ;
                var   cell = GameUtils.GetTradeCell(map);

                var gx = new GameXMLUtils();
                //var testPawn = Scribe.saver.DebugOutputFor(pawns[0]);
                var testPawn = gx.ToXml(pawnsMy);
                File.WriteAllText(@"c:\World\testPawn.xml", testPawn);

                gx.StartFromXml(@"c:\World\test.xml");
                var thin0 = gx.Test <Thing>();
                //PawnComponentsUtility.CreateInitialComponents((Pawn)thin0);
                gx.Finish();

                thin0.ThingID += "555";
                if (thin0 is Pawn)
                {
                    var refugee = (Pawn)thin0;
                    GenSpawn.Spawn(refugee, cell, map);
                    //refugee.SetFaction(Faction.OfPlayer, null);
                    refugee.PostMapInit();  //?
                    //map.mapPawns.UpdateRegistryForPawn((Pawn)thin0);
                }
                else
                {
                    GenDrop.TryDropSpawn(thin0, cell, map, ThingPlaceMode.Near, out thinXZ, null);
                }


                //MapComponentUtility.FinalizeInit(map); //????
                return(true);

                File.WriteAllText(Loger.PathLog + @"map.txt", TextObj(map, false), Encoding.UTF8);

                List <Thing>       listThing = CaravanFormingUtility.AllReachableColonyItems(Find.Maps[0]);
                Dialog_TradeOnline form      = null;
                form = new Dialog_TradeOnline(listThing, "OCity_DevTest_Test".Translate(), 3, () =>
                {
                    var select = form.GetSelect();
                    Thing thin = null;
                    var thins  = select.Select(p =>
                    {
                        return(ThingEntry.CreateEntry(thin = p.Key, p.Value));
                    }).ToList();
                    var outText = TextObj(thins, true);
                    File.WriteAllText(Loger.PathLog + @"Car.txt", outText, Encoding.UTF8);

                    var caravan = Find.WorldObjects.Caravans[0];
                    foreach (var t in select)
                    {
                        //t.Key

                        //ThingEntry the = new ThingEntry(t.Key, t.Value);
                        ///*
                        //thin = the.CreateThing();
                        //var p = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thin, caravan.PawnsListForReading, null);
                        //p.inventory.innerContainer.TryAdd(thin, true);
                        //*/
                        //thin = the.CreateThing();
                        GenDrop.TryDropSpawn(thin, cell, map, ThingPlaceMode.Near, out thinXZ, null);
                    }

                    /*
                     * File.WriteAllText(Loger.PathLog + @"ThingIn.txt", TextObj(thin, true), Encoding.UTF8);
                     * //if (thin.Spawned) thin.DeSpawn();
                     * ThingEntry the = new ThingEntry(thin, 1);
                     * thin = the.CreateThing();
                     * GenDrop.TryDropSpawn(thin, GameUtils.GetTradeCell(map), map, ThingPlaceMode.Near, out thinXZ, null);
                     * File.WriteAllText(Loger.PathLog + @"ThingXZ.txt", TextObj(thinXZ, true), Encoding.UTF8);
                     * File.WriteAllText(Loger.PathLog + @"ThingOut.txt", TextObj(thin, true), Encoding.UTF8);
                     */
                    /*
                     * if (thin != null)
                     * {
                     *  File.WriteAllText(Loger.PathLog + @"ThingIn.txt", TextObj(thin, true), Encoding.UTF8);
                     *  ThingEntry the = new ThingEntry(thin, 1);
                     *  File.WriteAllText(Loger.PathLog + @"ThingEntry.txt", TextObj(the, true), Encoding.UTF8);
                     *  File.WriteAllText(Loger.PathLog + @"ThingOut.txt", TextObj(the.CreateThing(), true), Encoding.UTF8);
                     * }*/
                });
                Find.WindowStack.Add(form);
                return(true);

                pawn = pawns.Where(p => p.Name.ToStringShort == "Jesse").FirstOrDefault();

                //msg += Find.Maps.Count.ToString() + Environment.NewLine;


                var pawnText = TextObj(pawn, true);
                File.WriteAllText(Loger.PathLog + @"Car.txt", pawnText, Encoding.UTF8);

                int directionTile = CaravanExitMapUtility.RandomBestExitTileFrom(Find.Maps[0]);
                //Find.Maps[0].Tile;

                //var destroyedFactionBase = (CaravanOnline)WorldObjectMaker.MakeWorldObject(ModDefOf.CaravanOnline);
                var destroyedFactionBase = (CaravanOnline)WorldObjectMaker.MakeWorldObject(ModDefOf.BaseOnline);
                destroyedFactionBase.Tile          = directionTile;
                destroyedFactionBase.OnlineWObject = new Model.WorldObjectEntry()
                {
                    LoginOwner = "OCity_DevTest_NameTestPlayer".Translate()
                };
                destroyedFactionBase.SetFaction(Faction.OfPlayer);
                Find.WorldObjects.Add(destroyedFactionBase);

                var cars    = Find.WorldObjects.AllWorldObjects.Where(o => o is Caravan).ToList();
                var seeText = TextObj(cars);
                File.WriteAllText(Loger.PathLog + @"See.txt", seeText, Encoding.UTF8);

                Loger.Log(msg);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
            return(true);
        }