Ejemplo n.º 1
0
        public AttackHostFromSrv AttackOnlineHost(AttackHostToSrv fromClient)
        {
            Loger.Log("Client AttackOnlineHost " + fromClient.State);
            var stat = TransObject <AttackHostFromSrv>(fromClient, 29, 30);

            return(stat);
        }
Ejemplo n.º 2
0
        public AttackHostFromSrv AttackOnlineHost(AttackHostToSrv fromClient)
        {
            if (Player == null)
            {
                return(null);
            }

            lock (Player)
            {
                var timeNow = DateTime.UtcNow;
                var data    = Repository.GetData;
                var res     = new AttackHostFromSrv()
                {
                };

                if (Player.AttackData == null)
                {
                    res.ErrorText = "Unexpected error, no data";
                    return(res);
                }

                //передаем управление общему объекту
                res = Player.AttackData.RequestHost(fromClient);

                return(res);
            }
        }
Ejemplo n.º 3
0
        public AttackHostFromSrv AttackOnlineHost(AttackHostToSrv fromClient)
        {
            //Loger.Log("Client AttackOnlineHost " + fromClient.State);
            var stat = TransObject <AttackHostFromSrv>(fromClient, (int)PackageType.Request29, (int)PackageType.Response30);

            return(stat);
        }
Ejemplo n.º 4
0
        private AttackHostFromSrv attackOnlineHost(AttackHostToSrv fromClient, ServiceContext context)
        {
            lock (context.Player)
            {
                var timeNow = DateTime.UtcNow;
                var data    = Repository.GetData;
                var res     = new AttackHostFromSrv()
                {
                };

                if (context.Player.AttackData == null)
                {
                    Loger.Log("Server AttackOnlineHost Unexpected error, no data");
                    res.ErrorText = "Unexpected error, no data";
                    return(res);
                }

                //передаем управление общему объекту
                res = context.Player.AttackData.RequestHost(fromClient);

                return(res);
            }
        }
Ejemplo n.º 5
0
        public AttackHostFromSrv RequestHost(AttackHostToSrv fromClient)
        {
            //Loger.Log($"Server AttackOnlineHost RequestHost State: {State} -> {fromClient.State}");
            lock (SyncObj)
            {
                //первые 5 минут не проверяем на отключения, т.к. загрузка может быть долгой (а дисконектит уже после 10 сек)
                if ((fromClient.State == 10 || (DateTime.UtcNow - CreateTime).TotalSeconds > 8 * 60) &&
                    CheckConnect(false))
                {
                    return(new AttackHostFromSrv()
                    {
                        State = State
                    });
                }
                if (fromClient.State < State)
                {
                    return(new AttackHostFromSrv()
                    {
                        ErrorText = "Unexpected request " + fromClient.State.ToString() + ". Was expected" + State.ToString()
                    });
                }

                if (fromClient.State == 2)
                {
                    State = 2;
                    return(new AttackHostFromSrv()
                    {
                        State = State,
                        HostPlaceServerId = HostPlaceServerId,
                        InitiatorPlaceServerId = InitiatorPlaceServerId,
                        StartInitiatorPlayer = Attacker.Public.Login,
                        TestMode = TestMode,
                    });
                }

                if (fromClient.State == 4)
                {
                    MapSize            = fromClient.MapSize;
                    TerrainDefNameCell = fromClient.TerrainDefNameCell;
                    TerrainDefName     = fromClient.TerrainDefName;
                    Thing     = fromClient.Thing;
                    ThingCell = fromClient.ThingCell;
                    State     = 4;
                    return(new AttackHostFromSrv()
                    {
                        State = State,
                    });
                }

                if (fromClient.State == 5)
                {
                    State = 5;
                    return(new AttackHostFromSrv()
                    {
                        State = State,
                        Pawns = Pawns
                    });
                }

                if (fromClient.State == 10)
                {
                    State = 10;

                    if (VictoryAttacker == null)
                    {
                        VictoryAttacker = fromClient.VictoryAttacker;
                    }

                    if (fromClient.NewPawnsId.Count > 0 ||
                        fromClient.NewThingsId.Count > 0 ||
                        fromClient.NewCorpses.Count > 0 ||
                        fromClient.Delete.Count > 0)
                    {
                        //удаляем из Delete если сейчас команда добавить с таким id
                        foreach (var n in fromClient.NewPawnsId)
                        {
                            var index = Delete.IndexOf(n);
                            if (index >= 0)
                            {
                                Delete.RemoveAt(index);
                            }
                        }
                        foreach (var n in fromClient.NewThingsId)
                        {
                            var index = Delete.IndexOf(n);
                            if (index >= 0)
                            {
                                Delete.RemoveAt(index);
                            }
                        }
                        foreach (var corps in fromClient.NewCorpses)
                        {
                            var index = Delete.IndexOf(corps.CorpseId);
                            if (index >= 0)
                            {
                                Delete.RemoveAt(index);
                            }
                        }

                        //объединяем
                        for (int i = 0; i < fromClient.NewPawnsId.Count; i++)
                        {
                            if (NewPawnsId.Contains(fromClient.NewPawnsId[i]))
                            {
                                continue;
                            }
                            NewPawnsId.Add(fromClient.NewPawnsId[i]);
                            NewPawns.Add(fromClient.NewPawns[i]);
                        }
                        for (int i = 0; i < fromClient.NewThingsId.Count; i++)
                        {
                            if (NewThingsId.Contains(fromClient.NewThingsId[i]))
                            {
                                continue;
                            }
                            NewThingsId.Add(fromClient.NewThingsId[i]);
                            NewThings.Add(fromClient.NewThings[i]);
                        }
                        for (int i = 0; i < NewCorpses.Count; i++)
                        {
                            if (fromClient.NewCorpses.Any(c => c.PawnId == NewCorpses[i].PawnId || c.CorpseId == NewCorpses[i].CorpseId))
                            {
                                NewCorpses.RemoveAt(i--);
                            }
                        }
                        for (int i = 0; i < fromClient.NewCorpses.Count; i++)
                        {
                            NewCorpses.Add(fromClient.NewCorpses[i]);
                        }
                        for (int i = 0; i < fromClient.Delete.Count; i++)
                        {
                            if (Delete.Contains(fromClient.Delete[i]))
                            {
                                continue;
                            }
                            Delete.Add(fromClient.Delete[i]);
                        }
                        for (int i = 0; i < fromClient.NewCorpses.Count; i++)
                        {
                            if (Delete.Contains(fromClient.NewCorpses[i].PawnId))
                            {
                                continue;
                            }
                            Delete.Add(fromClient.NewCorpses[i].PawnId);
                        }

                        //на всякий случай корректируем: удаляем из добавляемых те, что на удаление
                        foreach (var n in Delete)
                        {
                            var index = NewPawnsId.IndexOf(n);
                            if (index >= 0)
                            {
                                NewPawnsId.RemoveAt(index);
                                NewPawns.RemoveAt(index);
                            }
                            index = NewThingsId.IndexOf(n);
                            if (index >= 0)
                            {
                                NewThingsId.RemoveAt(index);
                                NewThings.RemoveAt(index);
                            }

                            for (int i = 0; i < NewCorpses.Count; i++)
                            {
                                if (n == NewCorpses[i].CorpseId)
                                {
                                    NewCorpses.RemoveAt(i--);
                                }
                            }
                        }
                    }


                    if (fromClient.UpdateState.Count > 0)
                    {
                        //объединяем
                        for (int i = 0; i < fromClient.UpdateState.Count; i++)
                        {
                            var id = fromClient.UpdateState[i].HostThingID;
                            UpdateState[id] = fromClient.UpdateState[i];
                        }
                    }

                    var res = new AttackHostFromSrv()
                    {
                        State              = State,
                        UpdateCommand      = UpdateCommand.Values.ToList(),
                        NeedNewThingIDs    = NeedNewThingIDs.ToList(),
                        SetPauseOnTime     = SetPauseOnTimeToHost == null ? DateTime.MinValue : SetPauseOnTimeToHost.Value,
                        VictoryHost        = VictoryHostToHost,
                        TerribleFatalError = TerribleFatalError,
                    };

                    UpdateCommand   = new Dictionary <int, AttackPawnCommand>();
                    NeedNewThingIDs = new HashSet <int>();

                    if (SetPauseOnTimeToHost != null)
                    {
                        Loger.Log("Server Send SetPauseOnTimeToHost=" + SetPauseOnTimeToHost.Value.ToGoodUtcString());
                    }

                    Host.PVPHostLastTime = DateTime.UtcNow;
                    SetPauseOnTimeToHost = null;
                    VictoryHostToHost    = false;
                    return(res);
                }

                return(new AttackHostFromSrv()
                {
                    ErrorText = "Unexpected request " + fromClient.State.ToString() + "! Was expected" + State.ToString()
                });
            }
        }
Ejemplo n.º 6
0
        public AttackHostFromSrv RequestHost(AttackHostToSrv fromClient)
        {
            lock (SyncObj)
            {
                if (fromClient.State < State)
                {
                    return(new AttackHostFromSrv()
                    {
                        ErrorText = "Unexpected request " + fromClient.State.ToString() + ". Was expected" + State.ToString()
                    });
                }

                if (fromClient.State == 2)
                {
                    State = 2;
                    return(new AttackHostFromSrv()
                    {
                        State = State,
                        HostPlaceServerId = HostPlaceServerId,
                        InitiatorPlaceServerId = InitiatorPlaceServerId,
                        StartInitiatorPlayer = Attacker.Public.Login
                    });
                }

                if (fromClient.State == 4)
                {
                    State              = 4;
                    MapSize            = fromClient.MapSize;
                    TerrainDefNameCell = fromClient.TerrainDefNameCell;
                    TerrainDefName     = fromClient.TerrainDefName;
                    Thing              = fromClient.Thing;
                    ThingCell          = fromClient.ThingCell;
                    return(new AttackHostFromSrv()
                    {
                        State = State,
                    });
                }

                if (fromClient.State == 5)
                {
                    State = 5;
                    return(new AttackHostFromSrv()
                    {
                        State = State,
                        Pawns = Pawns
                    });
                }

                if (fromClient.State == 10)
                {
                    State = 10;

                    if (fromClient.NewPawnsId.Count > 0 ||
                        fromClient.NewThingsId.Count > 0 ||
                        fromClient.Delete.Count > 0)
                    {
                        //удаляем из Delete если сейчас команда добавитьс таким id
                        foreach (var n in fromClient.NewPawnsId)
                        {
                            var index = Delete.IndexOf(n);
                            if (index >= 0)
                            {
                                Delete.RemoveAt(index);
                            }
                        }
                        foreach (var n in fromClient.NewThingsId)
                        {
                            var index = Delete.IndexOf(n);
                            if (index >= 0)
                            {
                                Delete.RemoveAt(index);
                            }
                        }

                        //объединяем
                        for (int i = 0; i < fromClient.NewPawnsId.Count; i++)
                        {
                            if (NewPawnsId.Contains(fromClient.NewPawnsId[i]))
                            {
                                continue;
                            }
                            NewPawnsId.Add(fromClient.NewPawnsId[i]);
                            NewPawns.Add(fromClient.NewPawns[i]);
                        }
                        for (int i = 0; i < fromClient.NewThingsId.Count; i++)
                        {
                            if (NewThingsId.Contains(fromClient.NewThingsId[i]))
                            {
                                continue;
                            }
                            NewThingsId.Add(fromClient.NewThingsId[i]);
                            NewThings.Add(fromClient.NewThings[i]);
                        }
                        for (int i = 0; i < fromClient.Delete.Count; i++)
                        {
                            if (Delete.Contains(fromClient.Delete[i]))
                            {
                                continue;
                            }
                            Delete.Add(fromClient.Delete[i]);
                        }

                        //на всякий случай корректируем: удаляем из добавляемых те, что на удаление
                        foreach (var n in Delete)
                        {
                            var index = NewPawnsId.IndexOf(n);
                            if (index >= 0)
                            {
                                NewPawnsId.RemoveAt(index);
                                NewPawns.RemoveAt(index);
                            }
                            index = NewThingsId.IndexOf(n);
                            if (index >= 0)
                            {
                                NewThingsId.RemoveAt(index);
                                NewThings.RemoveAt(index);
                            }
                        }
                    }


                    if (fromClient.UpdateState.Count > 0)
                    {
                        //объединяем
                        for (int i = 0; i < fromClient.UpdateState.Count; i++)
                        {
                            var id = fromClient.UpdateState[i].HostThingID;
                            UpdateState[id] = fromClient.UpdateState[i];
                        }
                    }

                    var res = new AttackHostFromSrv()
                    {
                        State         = State,
                        UpdateCommand = UpdateCommand.Values.ToList(),
                    };

                    UpdateCommand = new Dictionary <int, AttackPawnCommand>();
                    return(res);
                }

                return(new AttackHostFromSrv()
                {
                    ErrorText = "Unexpected request " + fromClient.State.ToString() + "! Was expected" + State.ToString()
                });
            }
        }
Ejemplo n.º 7
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);
        }