Beispiel #1
0
        public bool UpgradeBuilding(MsgInformationEx MsgDTO, object[] param)
        {
            var buildingName = (string)param[0];
            var building     = CastleBuildingSvc[buildingName];

            if (building == null)
            {
                MsgSender.PushMsg(MsgDTO, "不认识的建筑呢!");
                return(false);
            }

            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);

            if (!castle.Buildings.ContainsKey(buildingName))
            {
                MsgSender.PushMsg(MsgDTO, "你尚未拥有该建筑!");
                return(false);
            }

            var buildingLvl = castle.SafeBuildings[buildingName];
            var goldNeed    = building.UpgradeGoldNeed(buildingLvl);

            if (castle.Golds < goldNeed)
            {
                MsgSender.PushMsg(MsgDTO, $"你没有足够多的金钱升级 {buildingName}!({castle.Golds}/{goldNeed})");
                return(false);
            }

            castle.Golds -= goldNeed;
            castle.UpgradeBuilding(buildingName);
            castle.Update();

            MsgSender.PushMsg(MsgDTO, $"升级成功!当前{buildingName}的等级为:{castle.SafeBuildings[buildingName]}");
            return(true);
        }
Beispiel #2
0
        private void RecruitCommissariat(KindomCastle castle, MsgSession session)
        {
            var GranaryLevel    = castle.SafeBuildings["粮仓"];
            var GranaryModel    = CastleBuildingSvc["粮仓"];
            var CommissariatGen = GranaryModel.CollecRate * GranaryLevel;

            castle.Commissariat += CommissariatGen;
            session.Add($"成功征粮{CommissariatGen}!当前粮食剩余{castle.Commissariat}");
        }
Beispiel #3
0
        private void CollectTaxes(KindomCastle castle, MsgSession session)
        {
            var townLevel = castle.SafeBuildings["城镇"];
            var townModel = CastleBuildingSvc["城镇"];
            var GoldGen   = townModel.CollecRate * townLevel;

            castle.Golds += GoldGen;
            session.Add($"成功征税{GoldGen}!当前金钱剩余{castle.Golds}");
        }
Beispiel #4
0
        private void Recruit(MsgInformation MsgDTO, MsgSession session)
        {
            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);

            CollectTaxes(castle, session);
            RecruitCommissariat(castle, session);

            castle.Update();
        }
Beispiel #5
0
        public bool RenameCastle(MsgInformationEx MsgDTO, object[] param)
        {
            var name   = param[0] as string;
            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);

            castle.CastleName = name;
            castle.Update();

            MsgSender.PushMsg(MsgDTO, "重命名成功!", true);
            return(true);
        }
Beispiel #6
0
        public bool Recruit(MsgInformationEx MsgDTO, object[] param)
        {
            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);

            var soldierGroups = SoldierGroup.Get(MsgDTO.FromQQ);
            var curTotal      = soldierGroups.Sum(g => g.Count);

            var remain = Math.Max(castle.SoldierMaxVolume - curTotal, 0);
            var msg    = $"你当前共拥有士兵 {curTotal}人,还可招募 {remain}人";

            if (remain == 0)
            {
                msg += "\r\n无法招募新的士兵!";
                MsgSender.PushMsg(MsgDTO, msg, true);
                return(false);
            }

            var golds = castle.Golds;

            msg += $"\r\n你当前拥有金钱 {golds},最多招募等量的士兵";
            if (golds == 0)
            {
                msg += "\r\n无法招募新的士兵!";
                MsgSender.PushMsg(MsgDTO, msg, true);
                return(false);
            }

            var maxRecruit = Math.Min(remain, golds);
            var num        = WaiterSvc.WaitForNum(MsgDTO.FromGroup, MsgDTO.FromQQ, $"请输入招募士兵的数量!(1~{maxRecruit})", p => p >= 1 && p <= maxRecruit, MsgDTO.BindAi);

            if (num <= 0)
            {
                MsgSender.PushMsg(MsgDTO, "操作取消!");
                return(false);
            }

            var group = new SoldierGroup()
            {
                Owner = MsgDTO.FromQQ,
                Count = num,
                State = SoldierState.Working,
                Name  = $"第{GroupNamingRec.GetNextNo(MsgDTO.FromQQ)}军"
            };

            group.Insert();

            castle.Golds -= num;
            castle.Update();

            MsgSender.PushMsg(MsgDTO, "招募成功!");
            return(true);
        }
Beispiel #7
0
        public bool UpgradeCastle(MsgInformationEx MsgDTO, object[] param)
        {
            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);

            if (castle.Golds < castle.LvlUpNeedGold)
            {
                MsgSender.PushMsg(MsgDTO, $"你没有足够多的金钱升级!({castle.Golds}/{castle.LvlUpNeedGold})");
                return(false);
            }

            castle.UpgradeCastle();
            castle.Update();

            MsgSender.PushMsg(MsgDTO, $"恭喜你升级成功!当前城堡等级:{castle.Level}");
            return(true);
        }
Beispiel #8
0
        public bool MyCastle(MsgInformationEx MsgDTO, object[] param)
        {
            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);
            var groups = SoldierGroup.Get(MsgDTO.FromQQ);

            var session = new MsgSession(MsgDTO);

            session.Add(castle.CastleName);
            session.Add($"城堡等级:{Utility.LevelEmoji(castle.Level)}");
            session.Add($"金钱:{castle.Golds}");
            session.Add($"粮草:{castle.Commissariat}");
            session.Add($"建筑:{string.Join(",", castle.Buildings.Select(p => $"{p.Key}(lv.{p.Value})"))}");
            session.Add($"军队:{groups.Count}支");
            session.Add($"士兵:{groups.Sum(g => g.Count)}人");

            session.Send();
            return(true);
        }
Beispiel #9
0
        protected override void Sign(MsgInformationEx MsgDTO)
        {
            var sign     = SignInSuccessiveRecord.Sign(MsgDTO.FromGroup, MsgDTO.FromQQ);
            var goldsGen = Math.Min(sign.SuccessiveDays * 5, 50);

            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);

            castle.Golds += goldsGen;
            castle.Update();

            var indexNo = SignInGroupInfo.GetAndUpdate(MsgDTO.FromGroup);

            var session = new MsgSession(MsgDTO);

            session.Add($"签到成功!你已连续签到 {sign.SuccessiveDays}天,获得 {goldsGen.CurencyFormat()}!");
            session.Add($"本群签到排名:【No.{indexNo}】");

            Recruit(MsgDTO, session);
            session.Send();
        }
Beispiel #10
0
        public static KindomCastle Get(long GroupNum, long QQNum)
        {
            var castle = MongoService <KindomCastle> .GetOnly(p => p.QQNum == QQNum);

            if (castle != null)
            {
                return(castle);
            }

            var group = AutofacSvc.Resolve <GroupSettingSvc>()[GroupNum];
            var info  = APIEx.GetQQInfo(QQNum, group.BindAi);

            castle = new KindomCastle()
            {
                QQNum = QQNum, CharactorName = info.nick, CastleName = $"{info.nick}的城堡", Buildings = CastleBuildingSvc.Buildings.ToDictionary(p => p.Name, p => 1)
            };
            MongoService <KindomCastle> .Insert(castle);

            return(castle);
        }
Beispiel #11
0
        public bool Supply(MsgInformationEx MsgDTO, object[] param)
        {
            var castle = KindomCastle.Get(MsgDTO.FromGroup, MsgDTO.FromQQ);

            var starvingGroups = SoldierGroup.StarvingGroups(MsgDTO.FromQQ);

            if (starvingGroups.IsNullOrEmpty())
            {
                MsgSender.PushMsg(MsgDTO, "你没有需要补给的军队!", true);
                return(false);
            }

            var totalConsume     = 0;
            var feededGroupCount = 0;

            foreach (var starvingGroup in starvingGroups)
            {
                if (castle.Commissariat < starvingGroup.Count)
                {
                    break;
                }

                castle.Commissariat -= starvingGroup.Count;
                starvingGroup.Feed();
                totalConsume += starvingGroup.Count;
                feededGroupCount++;
            }
            castle.Update();

            var session = new MsgSession(MsgDTO);

            session.Add("补给完成!");
            session.Add($"共补给 {feededGroupCount}支军队,共消耗粮草 {totalConsume}");
            session.Add($"当前剩余 {starvingGroups.Count - feededGroupCount}支军队尚未补给,当前剩余粮草 {castle.Commissariat}");

            session.Send();
            return(true);
        }