Beispiel #1
0
        /// <summary>
        /// Начинаем процесс, первые запросы информации
        /// </summary>
        /// <param name="connect"></param>
        public void Start(SessionClient connect)
        {
            Loger.Log("Client GameAttackHost Start 1");
            var tolient = connect.AttackOnlineHost(new AttackHostToSrv()
            {
                State = 2
            });

            if (!string.IsNullOrEmpty(connect.ErrorMessage))
            {
                ErrorBreak(connect.ErrorMessage);
                return;
            }

            AttackerLogin          = tolient.StartInitiatorPlayer;
            InitiatorPlaceServerId = tolient.InitiatorPlaceServerId;
            HostPlaceServerId      = tolient.HostPlaceServerId;

            Loger.Log("Client GameAttackHost Start 2 " + tolient.HostPlaceServerId);

            LongEventHandler.QueueLongEvent(delegate
            {
                try
                {
                    Loger.Log("Client GameAttackHost Start 3");
                    var hostPlace = UpdateWorldController.GetWOByServerId(HostPlaceServerId) as MapParent;
                    var cloneMap  = hostPlace.Map;

                    var toSrvMap = new AttackHostToSrv()
                    {
                        State = 4,
                        TerrainDefNameCell = new List <IntVec3S>(),
                        TerrainDefName     = new List <string>(),
                        Thing     = new List <ThingTrade>(),
                        ThingCell = new List <IntVec3S>()
                    };

                    toSrvMap.MapSize = new IntVec3S(cloneMap.Size);

                    CellRect cellRect = CellRect.WholeMap(cloneMap);
                    cellRect.ClipInsideMap(cloneMap);

                    //почва
                    Loger.Log("Client GameAttackHost Start 4");
                    foreach (IntVec3 current in cellRect)
                    {
                        var terr = cloneMap.terrainGrid.TerrainAt(current);
                        toSrvMap.TerrainDefNameCell.Add(new IntVec3S(current));
                        toSrvMap.TerrainDefName.Add(terr.defName);
                    }

                    //скалы, преграды и строения без пешек и без растений не деревьев, вывести кол-во
                    Loger.Log("Client GameAttackHost Start 5");
                    foreach (IntVec3 current in cellRect)
                    {
                        foreach (Thing thc in Find.CurrentMap.thingGrid.ThingsAt(current).ToList <Thing>())
                        {
                            if (thc is Pawn)
                            {
                                continue;
                            }

                            //из растений оставляем только деревья
                            if (thc.def.category == ThingCategory.Plant && !thc.def.plant.IsTree)
                            {
                                continue;
                            }

                            if (thc.Position != current)
                            {
                                continue;
                            }

                            var tt = ThingTrade.CreateTrade(thc, thc.stackCount, false);

                            toSrvMap.ThingCell.Add(new IntVec3S(current));
                            toSrvMap.Thing.Add(tt);
                        }
                    }

                    Loger.Log("Client GameAttackHost Start 6");
                    SessionClientController.Command((connect0) =>
                    {
                        Loger.Log("Client GameAttackHost Start 7");
                        connect0.AttackOnlineHost(toSrvMap);
                        if (!string.IsNullOrEmpty(connect0.ErrorMessage))
                        {
                            ErrorBreak(connect0.ErrorMessage);
                            return;
                        }

                        //Ждем и получаем пешки атакующего и добавляем их
                        Loger.Log("Client GameAttackHost Start 8");
                        List <ThingEntry> pawnsA = null;
                        var s1Time = DateTime.UtcNow;
                        while (true)
                        {
                            var toClient5 = connect0.AttackOnlineHost(new AttackHostToSrv()
                            {
                                State = 5
                            });
                            if (!string.IsNullOrEmpty(connect0.ErrorMessage))
                            {
                                ErrorBreak(connect0.ErrorMessage);
                                return;
                            }
                            pawnsA = toClient5.Pawns;
                            if (pawnsA != null && pawnsA.Count > 0)
                            {
                                break;
                            }
                            if ((DateTime.UtcNow - s1Time).TotalSeconds > 20)
                            {
                                ErrorBreak("Timeout");
                                return;
                            }
                        }
                        if (!string.IsNullOrEmpty(connect0.ErrorMessage))
                        {
                            ErrorBreak(connect0.ErrorMessage);
                            return;
                        }

                        Loger.Log("Client GameAttackHost Start 9");
                        //Потом добавляем список к отправке
                        SendedPawnsId       = new HashSet <int>();
                        SendedState         = new Dictionary <int, int>();
                        ToUpdateStateId     = new List <int>();
                        ToUpdateState       = new List <Thing>();
                        ToSendDeleteId      = new HashSet <int>();
                        ToSendAddId         = new HashSet <int>();
                        ToSendThingAdd      = new HashSet <Thing>();
                        AttackingPawns      = new List <Pawn>();
                        AttackingPawnDic    = new Dictionary <int, int>();
                        AttackingPawnJobDic = new Dictionary <int, AttackPawnCommand>();
                        AttackUpdateTick    = 0;
                        GameMap             = cloneMap;

                        UIEventNewJobDisable = true;
                        var cellPawns        = GameUtils.SpawnCaravanPirate(cloneMap, pawnsA,
                                                                            (th, te) =>
                        {
                            var p = th as Pawn;
                            if (p == null)
                            {
                                return;
                            }

                            AttackingPawns.Add(p);
                            AttackingPawnDic.Add(p.thingIDNumber, te.OriginalID);

                            //задаем команду стоять и не двигаться (но стрелять если кто в радиусе)
                            Loger.Log("Client GameAttackHost Start 9 StartJob Wait_Combat ");
                            p.playerSettings.hostilityResponse = HostilityResponseMode.Ignore;
                            p.jobs.StartJob(new Job(JobDefOf.Wait_Combat)
                            {
                                playerForced          = true,
                                expiryInterval        = int.MaxValue,
                                checkOverrideOnExpire = false,
                            }
                                            , JobCondition.InterruptForced);

                            /*
                             * if (p.Label == "Douglas, Клерк")
                             * {
                             *  //todo для теста не забыть удалить!
                             *  var pp = p;
                             *  var th = new Thread(() =>
                             *  {
                             *      Thread.Sleep(5000);
                             *      while (true)
                             *      {
                             *          Thread.Sleep(1000);
                             *          try
                             *          {
                             *              var jj = pp.jobs.curJob;
                             *              Loger.Log("Host ThreadTestJob " + pp.Label + " job=" + (jj == null ? "null" : jj.def.defName.ToString()));
                             *          }
                             *          catch
                             *          { }
                             *      }
                             *  });
                             *  th.IsBackground = true;
                             *  th.Start();
                             * }
                             */
                        });
                        UIEventNewJobDisable = false;

                        Loger.Log("Client GameAttackHost Start 10");

                        CameraJumper.TryJump(cellPawns, cloneMap);

                        TimerObj = SessionClientController.Timers.Add(200, AttackUpdate);

                        //включаем обработку событий урона и уничтожения объектов
                        GameAttackTrigger_Patch.ActiveAttackHost.Add(GameMap, this);

                        Loger.Log("Client GameAttackHost Start 11");
                    });
                }
                catch (Exception ext)
                {
                    Loger.Log("GameAttackHost Start() Exception " + ext.ToString());
                }
            }, "...", false, null);
        }
Beispiel #2
0
        public bool Run()
        {
            return(false);

            Log.Message("DevelopTest Run: " + UpdateWorldController.GetTestText());

            var hostPlace = UpdateWorldController.GetWOByServerId(7) as MapParent;

            Log.Message("DevelopTest Run: " + (hostPlace?.Label ?? "null"));
            return(true);

            /*
             * var mmap = Find.Maps[0];
             * var ppawn = mmap.mapPawns.AllPawnsSpawned.FirstOrDefault(i => i.thingIDNumber == 589);
             * var tpawn = mmap.mapPawns.AllPawnsSpawned.FirstOrDefault(i => i.thingIDNumber == 586);
             *
             * var pxml = ThingEntry.CreateEntry(ppawn, 1);
             * File.WriteAllText(Loger.PathLog + "RunTest" + (++tttt).ToString() + ".xml", pxml.Data);
             *
             * var place = Find.WorldObjects.Settlements
             *  .FirstOrDefault(f => f.Faction == Faction.OfPlayer);
             * var map_ = ((Settlement)place).Map;
             * var cell_ = GameUtils.GetTradeCell(map_);
             *
             * map_.terrainGrid.SetTerrain(cell_
             *  , (tttt++) % 2 == 1
             *  ? DefDatabase<TerrainDef>.GetNamed("TileGranite")
             *  : TerrainDefOf.WaterDeep);
             *
             * return true;
             */
            /////////////////////////////////////////////////////

            /*
             * 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);
        }