示例#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);
            }
        }
示例#3
0
        // Token: 0x06000068 RID: 104 RVA: 0x000041E8 File Offset: 0x000023E8
        public override void OnEndReceiver(RealmData realmData)
        {
            if (!receiver.preferences.receiveItems)
            {
                state = TransactionResponse.DECLINED;
            }

            if (state == TransactionResponse.ACCEPTED)
            {
                var list = new List <Thing>();
                foreach (var keyValuePair in realmThings)
                {
                    var key   = keyValuePair.Key;
                    var thing = realmData.FromRealmThing(key);
                    for (var i = keyValuePair.Value; i > 0; i -= key.stackCount)
                    {
                        key.stackCount = Math.Min(i, thing.def.stackLimit);
                        list.Add(realmData.FromRealmThing(key));
                    }
                }

                var intVec = DropCellFinder.RandomDropSpot(Find.CurrentMap);
                DropPodUtility.DropThingsNear(intVec, Find.CurrentMap, list);
                Find.LetterStack.ReceiveLetter("Ship pod", "A pod was sent from " + sender.name + " containing items",
                                               LetterDefOf.PositiveEvent, new GlobalTargetInfo(intVec, Find.CurrentMap));
                return;
            }

            if (state == TransactionResponse.INTERRUPTED)
            {
                Messages.Message("Unexpected interruption during item transaction with " + sender.name,
                                 MessageTypeDefOf.RejectInput);
                return;
            }

            var unused = state;
        }
示例#4
0
        public override void OnStartReceiver(RealmData realmData)
        {
            // Double check to ensure it wasn't bypassed by the sender
            if (!receiver.preferences.receiveItems)
            {
                realmData.NotifyPacketToServer(new ConfirmServerTransactionPacket
                {
                    transaction = this,
                    response    = TransactionResponse.DECLINED
                });
                return;
            }

            // We generate a detailed list of what the pack contains
            List <KeyValuePair <Thing, int> > things = realmThings.Select((r) => new KeyValuePair <Thing, int>(realmData.FromRealmThing(r.Key), r.Value)).ToList();

            string thingLabels = string.Join("\n", things.Select((t) => t.Value.ToString() + "x " + t.Key.LabelCapNoCount).ToArray());

            // We ask for confirmation
            Dialog_GeneralChoice choiceDialog = new Dialog_GeneralChoice(new DialogChoiceConfig
            {
                text          = sender.name + " wants to ship you:\n" + thingLabels,
                buttonAText   = "Accept",
                buttonAAction = () =>
                {
                    realmData.NotifyPacketToServer(new ConfirmServerTransactionPacket
                    {
                        transaction = this,
                        response    = TransactionResponse.ACCEPTED
                    });
                },
                buttonBText   = "Refuse",
                buttonBAction = () =>
                {
                    realmData.NotifyPacketToServer(new ConfirmServerTransactionPacket
                    {
                        transaction = this,
                        response    = TransactionResponse.DECLINED
                    });
                }
            });

            Find.WindowStack.Add(choiceDialog);
        }