Esempio n. 1
0
        public void StartActivity(AllianceWar _this)
        {
            var am = ServerAllianceManager.GetAllianceByServer(_this.ServerId);

            if (am == null)
            {
                Logger.Error("StartActivity not find GetAllianceByServer!server={0},", _this.ServerId);
                return;
            }
            DBServerAllianceData data;

            if (!am.mDBData.TryGetValue(_this.ServerId, out data))
            {
                Logger.Error("In BidOver() can't find data!");
                return;
            }
            PlayerLog.WriteLog((ulong)LogType.AllianceWar, "StartActivity(), ServerId = {0}", _this.ServerId);
            _this.SetStatus((int)eAllianceWarState.WaitStart);
            var now = DateTime.Now;

            _this.StartHour = now.Hour;
            _this.StartMin  = now.Minute;

            _this.AllianceIds.Clear();
            _this.AlliancePlayers.Clear();
            _this.EnterPlayerCount.Clear();
            _this.AllianceIds.Add(data.Occupant);
            _this.AllianceIds.AddRange(data.Challengers);
            foreach (var id in _this.AllianceIds)
            {
                _this.AlliancePlayers.Add(id, new List <ulong>());
                _this.EnterPlayerCount.Add(id, 0);
            }
        }
Esempio n. 2
0
        //战斗结束
        public void BattleTimeOver(AllianceWar _this)
        {
            PlayerLog.WriteLog((ulong)LogType.AllianceWar, "BattleTimeOver(), ServerId = {0}", _this.ServerId);
            _this.SetStatus((int)eAllianceWarState.WaitBid);

            var allianceManager = ServerAllianceManager.GetAllianceByServer(_this.ServerId);

            if (allianceManager != null)
            {
                var dbData = allianceManager.GetServerData(_this.ServerId);
                if (dbData != null)
                {
                    dbData.Challengers.Clear();
                    dbData.LastBattleTime = DateTime.Now.ToBinary();
                }
                allianceManager.SetFlag(_this.ServerId);
            }

            ClearData(_this);
            Init(_this);
        }
Esempio n. 3
0
        //
        public void BidOver(AllianceWar _this)
        {
            var am = ServerAllianceManager.GetAllianceByServer(_this.ServerId);

            if (am == null)
            {
                Logger.Error("StartActivity not find GetAllianceByServer!server={0},", _this.ServerId);
                return;
            }
            DBServerAllianceData data;

            if (!am.mDBData.TryGetValue(_this.ServerId, out data))
            {
                Logger.Error("In BidOver() can't find data!");
                return;
            }
            am.BidOver();
            var msgData = new AllianceWarChallengerData();

            foreach (var id in data.Challengers)
            {
                var allliance = ServerAllianceManager.GetAllianceById(id);
                if (allliance == null)
                {
                    Logger.Error("In BidOver(). alliance == null!! id = {0}", id);
                    continue;
                }
                msgData.ChallengerId.Add(id);
                msgData.ChallengerName.Add(allliance.Name);
            }
            _this.SetStatus((int)eAllianceWarState.WaitEnter);

            var sId = SceneExtension.GetServerLogicId(_this.ServerId);

            TeamServer.Instance.TeamAgent.NotifyAllianceWarChallengerData((uint)sId, msgData);
            PlayerLog.WriteLog((ulong)LogType.AllianceWar, "BidOver(), ServerId = {0}, Challengers = {1}",
                               _this.ServerId, data.Challengers.GetDataString());
        }
Esempio n. 4
0
        public void Init(AllianceWar _this)
        {
            foreach (var trigger in _this.WarTrigger)
            {
                if (trigger != null)
                {
                    TeamServerControl.tm.DeleteTrigger(trigger);
                }
            }
            _this.WarTrigger.Clear();

            var tb = Table.GetServerName(_this.ServerId);

            if (1 != tb.IsClientDisplay)
            {
                return;
            }

            var am = ServerAllianceManager.GetAllianceByServer(_this.ServerId);

            if (am == null)
            {
                Logger.Error("StartActivity not find GetAllianceByServer!server={0},", _this.ServerId);
                return;
            }

            DBServerAllianceData data;

            if (!am.mDBData.TryGetValue(_this.ServerId, out data))
            {
                //热更后如果开放新服,这里需要new一个出来
                data          = new DBServerAllianceData();
                data.ServerId = _this.ServerId;
                data.Occupant = -1;
                am.mDBData[_this.ServerId] = data;
                am.SetFlag(_this.ServerId);
                NotifyAllianceWarInfo(_this, -1);
                //Logger.Error("In BidOver() can't find data!");
                //return;
            }
            _this.dbData = data;

            //特殊处理开服前11天
            int AllianceWarType = 200;
            // Debug.Assert(false);
            //为攻城战注册一些定时器
            var tbFuben = Table.GetFuben(Constants.AllianceWarDungeonId);
            var now     = DateTime.Now;
            //开服时间
            var serverOpenTime = DateTime.Parse(tb.OpenTime);
            var baseTime       = DateTime.Now.Date.AddDays(365);
            var TimeToday      = DateTime.Now > serverOpenTime ? DateTime.Now : serverOpenTime;
            var KaifuId        = (int)(DateTime.Now.Date - serverOpenTime.Date).TotalDays + 1;

            if (KaifuId < 1)
            {
                KaifuId = 1;
            }
            var tbKaifu  = Table.GetKaiFu(KaifuId);
            var openWeek = (int)serverOpenTime.DayOfWeek;


            //开放精确时间
            var opentime = tbFuben.OpenTime[0];
            var openhour = opentime / 100;
            var openmin  = opentime % 100;

            //Debug.Assert(false);

            var nextOpen = DateTime.Now.AddDays(-1);

            if (_this.dbData.OpenTime > 0)
            {
                nextOpen = DateTime.FromBinary(_this.dbData.OpenTime);
            }
            if (nextOpen < DateTime.Now)
            {
                bool b = false;
                while (tbKaifu != null)
                {
                    if (tbKaifu.Week[openWeek] == AllianceWarType &&
                        serverOpenTime.AddDays(KaifuId - 1).Date.AddHours(openhour).AddMinutes(openmin) > DateTime.Now)
                    {
                        b = true;
                        break;
                    }
                    tbKaifu = Table.GetKaiFu(++KaifuId);
                }
                if (b)
                {
//活动中找到了目标
                    baseTime = serverOpenTime.AddDays(KaifuId - 1).Date.AddHours(openhour).AddMinutes(openmin);
                }
                else
                {
//没有找到目标,按照自己的套路每周二六开放
                    var strConf0 = Table.GetServerConfig(901).Value;
                    var confs0   = strConf0.Split('|');
                    var tmp      = 7;
                    foreach (var v in confs0)
                    {
                        var n = int.Parse(v);
                        var d = n - (int)DateTime.Now.DayOfWeek;
                        if (d < 0)
                        {
                            d += 7;
                        }
                        if (d < tmp &&
                            DateTime.Now.AddDays(d).Date.AddHours(openhour).AddMinutes(openmin) > DateTime.Now)
                        {
                            tmp = d;
                        }
                    }
                    baseTime = DateTime.Now.AddDays(tmp).Date.AddHours(openhour).AddMinutes(openmin);
                }
                _this.SetStatus((int)eAllianceWarState.WaitBid);
            }
            else
            {
                baseTime = nextOpen;
            }


            //已经获得了开放的标准时间,下面只需要根据这个时间开放不同的计时器就可以了
            //开放竞标计时器  //清楚之前的竞标信息
            var bidTime       = baseTime.Date.AddDays(-1);                                               // 竞标时间(攻城战开始前一天)
            var waitEnterTime = baseTime.Date;                                                           // 等待进入战场时间(攻城战当天零点开始)
            var enterTime     = baseTime;                                                                // 开始进入时间
            var startTime     = baseTime.AddMinutes(tbFuben.OpenLastMinutes);                            // 开始战争时间
            var timeOverTime  = baseTime.AddMinutes(tbFuben.TimeLimitMinutes + tbFuben.OpenLastMinutes); // 超时时间

            if ((int)eAllianceWarState.WaitBid == _this.dbData.Status)
            {
                if (DateTime.Now >= bidTime) // 已经过了竞标时间了
                {
                    StartBid(_this);
                }
                else
                {
                    _this.WarTrigger.Add(TeamServerControl.tm.CreateTrigger(bidTime, () => { StartBid(_this); }));
                }
            }

            //每周二周六0点,竞标结束,算出参战公会
            if ((int)eAllianceWarState.Bid == _this.dbData.Status && DateTime.Now >= waitEnterTime)
            {
                BidOver(_this);
            }
            else
            {
                _this.WarTrigger.Add(TeamServerControl.tm.CreateTrigger(waitEnterTime, () => { BidOver(_this); }));
            }

            ////每周二周六攻城战开始进入时,进行相关处理
            _this.WarTrigger.Add(TeamServerControl.tm.CreateTrigger(enterTime, () => { StartActivity(_this); }));
            ////每周二周六攻城战开始打时,进行相关处理
            _this.WarTrigger.Add(TeamServerControl.tm.CreateTrigger(startTime, () => { StartFight(_this); }));
            ////每周二周六攻城战结束后,清理相关数据
            _this.WarTrigger.Add(TeamServerControl.tm.CreateTrigger(timeOverTime, () => { BattleTimeOver(_this); }));

            _this.dbData.OpenTime = baseTime.ToBinary();
            am.SetFlag(_this.ServerId);
        }
Esempio n. 5
0
        //战斗结束
        public void BattleOver(AllianceWar _this, int occupantId)
        {
            _this.SetStatus((int)eAllianceWarState.WaitBid);

            var allianceManager = ServerAllianceManager.GetAllianceByServer(_this.ServerId);
            var dbData          = allianceManager.GetServerData(_this.ServerId);
            var oldOccupant     = dbData.Occupant;

            dbData.Challengers.Clear();
            dbData.LastBattleTime = DateTime.Now.ToBinary();
            allianceManager.SetFlag(_this.ServerId);

            PlayerLog.WriteLog((ulong)LogType.AllianceWar,
                               "BattleOver(), ServerId = {0}, occupantId = {1}, old occupantId = {2}", _this.ServerId, occupantId,
                               dbData.Occupant);

            //如果城主没变就返回
            if (dbData.Occupant == occupantId)
            {
                return;
            }

            dbData.Occupant = occupantId;
            var alliance = ServerAllianceManager.GetAllianceById(occupantId);

            if (alliance != null)
            {
                //通知全服,城主变了
                var data = new AllianceWarOccupantData();
                data.OccupantId   = occupantId;
                data.OccupantName = alliance.Name;
                TeamServer.Instance.TeamAgent.NotifyAllianceWarOccupantData((uint)_this.ServerId, data);

                //修改玩家的称号
                var change0 = new Dict_int_int_Data();
                var tbTitle = Table.GetNameTitle(5000);
                change0.Data.Add(tbTitle.FlagId, 1);

                var change1 = new Dict_int_int_Data();
                tbTitle = Table.GetNameTitle(5001);
                change1.Data.Add(tbTitle.FlagId, 1);

                var dad = alliance.Dad;
                foreach (var id in alliance.mDBData.Members)
                {
                    var m = dad.GetCharacterData(id);
                    if (m == null)
                    {
                        continue;
                    }
                    if (m.Ladder == (int)eAllianceLadder.Chairman)
                    {
                        ChangeNameTitle(id, change0);
                    }
                    else
                    {
                        ChangeNameTitle(id, change1);
                    }
                }
            }

            //修改玩家的称号
            alliance = ServerAllianceManager.GetAllianceById(oldOccupant);
            if (alliance != null)
            {
                var change  = new Dict_int_int_Data();
                var tbTitle = Table.GetNameTitle(5000);
                change.Data.Add(tbTitle.FlagId, 0);
                tbTitle = Table.GetNameTitle(5001);
                change.Data.Add(tbTitle.FlagId, 0);
                foreach (var id in alliance.mDBData.Members)
                {
                    ChangeNameTitle(id, change);
                }
            }

            //通知logic,本服的王城占领者变了
            NotifyAllianceWarInfo(_this, occupantId);
            Init(_this);
        }
Esempio n. 6
0
 public void StartFight(AllianceWar _this)
 {
     PlayerLog.WriteLog((ulong)LogType.AllianceWar, "StartFight(), ServerId = {0}", _this.ServerId);
     _this.SetStatus((int)eAllianceWarState.Fight);
 }
Esempio n. 7
0
 public void StartBid(AllianceWar _this)
 {
     PlayerLog.WriteLog((ulong)LogType.AllianceWar, "StartBid(), ServerId = {0}", _this.ServerId);
     _this.SetStatus((int)eAllianceWarState.Bid);
     ClearData(_this);
 }