public override void Arrived(Caravan caravan)
        {
            if (mode == "exchangeOfGoods")
            {
                //Pawn bestNegotiator = CaravanVisitUtility.BestNegotiator(caravan);
                ThingOwner <Thing> сontainer = new ThingOwner <Thing>();
                Dialog_TradeOnline form      = null;
                if (сaravanOnline.OnlineWObject == null)
                {
                    Log.Error("OCity_Caravan_LOGNoData".Translate());
                    return;
                }

                var goods = CaravanInventoryUtility.AllInventoryItems(caravan).ToList().Concat(
                    caravan.PawnsListForReading
                    .Cast <Thing>()
                    ).ToList();

                form = new Dialog_TradeOnline(goods
                                              , сaravanOnline.OnlinePlayerLogin
                                              , сaravanOnline.OnlineWObject.FreeWeight
                                              , () =>
                {
                    var select            = form.GetSelect();
                    bool selectAllCaravan = caravan.PawnsListForReading.Count == select.Count(s => s.Key is Pawn);
                    if (selectAllCaravan)
                    {
                        Log.Message("OCity_Caravan_LOGSwap".Translate());
                        select = new Dictionary <Thing, int>();
                        foreach (var pawn in caravan.PawnsListForReading)
                        {
                            foreach (var item in pawn.inventory.innerContainer.ToDictionary(t => t, t => t.stackCount))
                            {
                                select.Add(item.Key, item.Value);
                            }
                            select.Add(pawn, 1);
                            pawn.inventory.innerContainer.Clear();
                        }
                    }
                    //передаем выбранные товары из caravan к другому игроку в сaravanOnline
                    var sendThings = new List <ThingEntry>();
                    foreach (var pair in select)
                    {
                        var thing     = pair.Key;
                        var numToTake = pair.Value;
                        if (thing is Pawn)
                        {
                            var pawn = thing as Pawn;
                            //если отдали пешку, то выкладываем все другим и удаляемся из каравана
                            var things = pawn.inventory.innerContainer.ToList();
                            pawn.inventory.innerContainer.Clear();
                            GameUtils.DeSpawnSetupOnCaravan(caravan, pawn);
                            foreach (var thin in things)
                            {
                                var p = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thin, caravan.PawnsListForReading, null);
                                if (p != null)
                                {
                                    p.inventory.innerContainer.TryAdd(thin, true);
                                }
                            }
                        }
                        sendThings.Add(new ThingEntry(thing, numToTake));
                    }
                    SessionClientController.Command((connect) =>
                    {
                        connect.SendThings(sendThings
                                           , SessionClientController.My.Login
                                           , сaravanOnline.OnlinePlayerLogin
                                           , сaravanOnline.OnlineWObject.ServerId
                                           , сaravanOnline.Tile
                                           );
                    });

                    if (selectAllCaravan)
                    {
                        //удаляем пешку из игры
                        foreach (var pawn in caravan.PawnsListForReading)
                        {
                            pawn.Destroy(DestroyMode.Vanish);
                        }

                        Find.WorldObjects.Remove(caravan);
                    }
                    else
                    {
                        foreach (var pair in select)
                        {
                            var thing     = pair.Key;
                            var numToTake = pair.Value;
                            if (thing is Pawn)
                            {
                                var pawn = thing as Pawn;
                                //удаляем пешку из игры
                                pawn.Destroy(DestroyMode.Vanish);
                                //Find.WorldPawns.RemovePawn(pawn); не проверенное не полное удаление, если её вернут назад
                            }
                            else
                            {
                                //если отдали вешь, то находим кто её тащит и убираем с него
                                Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(caravan, thing);
                                ownerOf.inventory.innerContainer.TryTransferToContainer(thing, сontainer, numToTake);
                            }
                        }
                    }
                });
                Find.WindowStack.Add(form);
            }
        }
Beispiel #2
0
        private void exchangeOfGoods(Caravan caravan)
        {
            //Pawn bestNegotiator = CaravanVisitUtility.BestNegotiator(caravan);
            ThingOwner <Thing> сontainer = new ThingOwner <Thing>();
            Dialog_TradeOnline form      = null;

            if (сaravanOnline.OnlineWObject == null)
            {
                Log.Error("OCity_Caravan_LOGNoData".Translate());
                return;
            }

            var goods = GameUtils.GetAllThings(caravan);

            form = new Dialog_TradeOnline(goods
                                          , сaravanOnline.OnlinePlayerLogin
                                          , сaravanOnline.OnlineWObject.FreeWeight
                                          , () =>
            {
                if (!SessionClientController.Data.BackgroundSaveGameOff)
                {
                    var select            = form.GetSelect();
                    bool selectAllCaravan = caravan.PawnsListForReading.Count == select.Count(s => s.Key is Pawn);
                    if (selectAllCaravan)
                    {
                        Log.Message("OCity_Caravan_LOGSwap".Translate());
                        select = new Dictionary <Thing, int>();
                        foreach (var pawn in caravan.PawnsListForReading)
                        {
                            foreach (var item in pawn.inventory.innerContainer.ToDictionary(t => t, t => t.stackCount))
                            {
                                select.Add(item.Key, item.Value);
                            }
                            select.Add(pawn, 1);
                            pawn.inventory.innerContainer.Clear();
                        }
                    }
                    //передаем выбранные товары из caravan к другому игроку в сaravanOnline
                    var sendThings = new List <ThingEntry>();
                    foreach (var pair in select)
                    {
                        var thing     = pair.Key;
                        var numToTake = pair.Value;
                        if (thing is Pawn)
                        {
                            var pawn = thing as Pawn;
                            //если отдали пешку, то выкладываем все другим и удаляемся из каравана
                            var things = pawn.inventory.innerContainer.ToList();
                            pawn.inventory.innerContainer.Clear();
                            GameUtils.DeSpawnSetupOnCaravan(caravan, pawn);
                            foreach (var thin in things)
                            {
                                var p = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thin, caravan.PawnsListForReading, null);
                                if (p != null)
                                {
                                    p.inventory.innerContainer.TryAdd(thin, true);
                                }
                            }
                        }
                        sendThings.Add(ThingEntry.CreateEntry(thing, numToTake));
                    }

                    if (selectAllCaravan)
                    {
                        //удаляем пешку из игры
                        foreach (var pawn in caravan.PawnsListForReading)
                        {
                            GameUtils.PawnDestroy(pawn);
                        }

                        Find.WorldObjects.Remove(caravan);
                    }
                    else
                    {
                        foreach (var pair in select)
                        {
                            var thing     = pair.Key;
                            var numToTake = pair.Value;
                            if (thing is Pawn)
                            {
                                var pawn = thing as Pawn;
                                //удаляем пешку из игры
                                GameUtils.PawnDestroy(pawn);
                            }
                            else
                            {
                                //если отдали вешь, то находим кто её тащит и убираем с него
                                Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(caravan, thing);
                                ownerOf.inventory.innerContainer.TryTransferToContainer(thing, сontainer, numToTake);
                            }
                        }
                    }

                    //После передачи сохраняем, чтобы нельзя было обузить, после чего передаем вещи
                    SessionClientController.SaveGameNowSingleAndCommandSafely(
                        (connect) =>
                    {
                        return(connect.SendThings(sendThings
                                                  , SessionClientController.My.Login
                                                  , сaravanOnline.OnlinePlayerLogin
                                                  , сaravanOnline.OnlineWObject.ServerId
                                                  , сaravanOnline.Tile
                                                  ));
                    },
                        null,
                        null); //если не удалось отправить письмо, то жопа так как сейв уже прошел
                }
            });
            Find.WindowStack.Add(form);
        }
Beispiel #3
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);
        }