Пример #1
0
        public override void OnEndReceiver(RealmData realmData)
        {
            // Double check to ensure it wasn't bypassed by the sender
            if (!receiver.preferences.receiveItems)
            {
                state = TransactionResponse.DECLINED;
            }

            if (state == TransactionResponse.ACCEPTED)
            {
                // We spawn the new items !
                List <Thing> thingsToSpawn = new List <Thing>();
                foreach (KeyValuePair <RealmThing, int> entry in realmThings)
                {
                    RealmThing realmThing  = entry.Key;
                    Thing      thing       = realmData.FromRealmThing(realmThing);
                    int        leftToSpawn = entry.Value;
                    // We make new things until we create everything
                    // For example, if 180 granites blocks are sent (can be stacked by 75), we
                    // will create 3 Thing (2 full and 1 semi-full)
                    while (leftToSpawn > 0)
                    {
                        realmThing.stackCount = Math.Min(leftToSpawn, thing.def.stackLimit);

                        thingsToSpawn.Add(realmData.FromRealmThing(realmThing));

                        leftToSpawn -= realmThing.stackCount;
                    }
                }

                // We spawn the said item
                IntVec3 position = DropCellFinder.RandomDropSpot(Find.VisibleMap);
                DropPodUtility.DropThingsNear(position, Find.VisibleMap, thingsToSpawn);

                Find.LetterStack.ReceiveLetter(
                    "Ship pod",
                    "A pod was sent from " + sender.name + " containing items",
                    LetterDefOf.PositiveEvent,
                    new RimWorld.Planet.GlobalTargetInfo(position, Find.VisibleMap)
                    );
            }
            else if (state == TransactionResponse.INTERRUPTED)
            {
                Messages.Message("Unexpected interruption during item transaction with " + sender.name, MessageTypeDefOf.RejectInput);
            }
            else if (state == TransactionResponse.TOOFAST)
            {
                // This should never happen as the server rejects intercepted packets
            }
        }
Пример #2
0
        public override void OnEndReceiver(RealmData realmData)
        {
            if (state == TransactionResponse.ACCEPTED)
            {
                // We spawn the new items !
                List <Thing> thingsToSpawn = new List <Thing>();
                foreach (KeyValuePair <RealmThing, int> entry in realmThings)
                {
                    RealmThing realmThing  = entry.Key;
                    Thing      thing       = realmData.FromRealmThing(realmThing);
                    int        leftToSpawn = entry.Value;
                    // We make new things until we create everything
                    // For example, if 180 granites blocks are sent (can be stacked by 75), we
                    // will create 3 Thing (2 full and 1 semi-full)
                    while (leftToSpawn > 0)
                    {
                        realmThing.stackCount = Math.Min(leftToSpawn, thing.def.stackLimit);

                        thingsToSpawn.Add(realmData.FromRealmThing(realmThing));

                        leftToSpawn -= realmThing.stackCount;
                    }
                }

                // We spawn the said item
                IntVec3 position = DropCellFinder.RandomDropSpot();
                DropPodUtility.DropThingsNear(position, thingsToSpawn);

                Find.LetterStack.ReceiveLetter(
                    "Ship pod",
                    "A pod was sent from " + sender.name + " containing items",
                    LetterType.Good,
                    position
                    );
            }
            else if (state == TransactionResponse.INTERRUPTED)
            {
                Messages.Message("Unexpected interruption during item transaction with " + sender.name, MessageSound.RejectInput);
            }
        }