Пример #1
0
        public void Bind()
        {
            //Bind Info to Saved Archer objects or create new objects
            for (var j = 0; j < Info.ConquestGuards.Count; j++)
            {
                var tempArcher = GuildInfo.ArcherList.FirstOrDefault(x => x.Index == Info.ConquestGuards[j].Index);

                if (tempArcher != null)
                {
                    tempArcher.Info     = Info.ConquestGuards[j];
                    tempArcher.Conquest = this;
                }
                else
                {
                    GuildInfo.ArcherList.Add(new ConquestGuildArcherInfo {
                        Info = Info.ConquestGuards[j], Alive = true, Index = Info.ConquestGuards[j].Index, Conquest = this
                    });
                }
            }

            //Remove archers that have been removed from DB
            for (var j = 0; j < GuildInfo.ArcherList.Count; j++)
            {
                if (GuildInfo.ArcherList[j].Info == null)
                {
                    GuildInfo.ArcherList.Remove(GuildInfo.ArcherList[j]);
                }
            }

            //Bind Info to Saved Gate objects or create new objects
            for (var j = 0; j < Info.ConquestGates.Count; j++)
            {
                var tempGate = GuildInfo.GateList.FirstOrDefault(x => x.Index == Info.ConquestGates[j].Index);

                if (tempGate != null)
                {
                    tempGate.Info     = Info.ConquestGates[j];
                    tempGate.Conquest = this;
                }
                else
                {
                    GuildInfo.GateList.Add(new ConquestGuildGateInfo {
                        Info = Info.ConquestGates[j], Health = int.MaxValue, Index = Info.ConquestGates[j].Index, Conquest = this
                    });
                }
            }

            //Bind Info to Saved Flag objects or create new objects
            for (var j = 0; j < Info.ConquestFlags.Count; j++)
            {
                GuildInfo.FlagList.Add(new ConquestGuildFlagInfo {
                    Info = Info.ConquestFlags[j], Index = Info.ConquestFlags[j].Index, Conquest = this
                });
            }

            //Remove Gates that have been removed from DB
            for (var j = 0; j < GuildInfo.GateList.Count; j++)
            {
                if (GuildInfo.GateList[j].Info == null)
                {
                    GuildInfo.GateList.Remove(GuildInfo.GateList[j]);
                }
            }

            //Bind Info to Saved Wall objects or create new objects
            for (var j = 0; j < Info.ConquestWalls.Count; j++)
            {
                var tempWall = GuildInfo.WallList.FirstOrDefault(x => x.Index == Info.ConquestWalls[j].Index);

                if (tempWall != null)
                {
                    tempWall.Info     = Info.ConquestWalls[j];
                    tempWall.Conquest = this;
                }
                else
                {
                    GuildInfo.WallList.Add(new ConquestGuildWallInfo {
                        Info = Info.ConquestWalls[j], Index = Info.ConquestWalls[j].Index, Health = int.MaxValue, Conquest = this
                    });
                }
            }

            //Remove Walls that have been removed from DB
            for (var j = 0; j < GuildInfo.WallList.Count; j++)
            {
                if (GuildInfo.WallList[j].Info == null)
                {
                    GuildInfo.WallList.Remove(GuildInfo.WallList[j]);
                }
            }


            //Bind Info to Saved Siege objects or create new objects
            for (var j = 0; j < Info.ConquestSieges.Count; j++)
            {
                var tempSiege = GuildInfo.SiegeList.FirstOrDefault(x => x.Index == Info.ConquestSieges[j].Index);

                if (tempSiege != null)
                {
                    tempSiege.Info     = Info.ConquestSieges[j];
                    tempSiege.Conquest = this;
                }
                else
                {
                    GuildInfo.SiegeList.Add(new ConquestGuildSiegeInfo {
                        Info = Info.ConquestSieges[j], Index = Info.ConquestSieges[j].Index, Health = int.MaxValue, Conquest = this
                    });
                }
            }

            //Remove Siege that have been removed from DB
            for (var j = 0; j < GuildInfo.SiegeList.Count; j++)
            {
                if (GuildInfo.SiegeList[j].Info == null)
                {
                    GuildInfo.SiegeList.Remove(GuildInfo.SiegeList[j]);
                }
            }

            //Bind Info to Saved Flag objects or create new objects
            for (var j = 0; j < Info.ControlPoints.Count; j++)
            {
                ConquestGuildFlagInfo cp;
                GuildInfo.ControlPoints.Add(cp = new ConquestGuildFlagInfo {
                    Info = Info.ControlPoints[j], Index = Info.ControlPoints[j].Index, Conquest = this
                }, new Dictionary <GuildObject, int>());
            }

            LoadArchers();
            LoadGates();
            LoadWalls();
            LoadSieges();
            LoadFlags();
            LoadNPCs();
            LoadControlPoints();
        }
Пример #2
0
        public void ScorePoints()
        {
            bool pointsChanged = false;

            switch (GameType)
            {
            case ConquestGame.ControlPoints:
            {
                int points;

                foreach (KeyValuePair <ConquestGuildFlagInfo, Dictionary <GuildObject, int> > item in ControlPoints)
                {
                    pointsChanged = false;

                    ConquestGuildFlagInfo         controlFlag       = null;
                    Dictionary <GuildObject, int> controlFlagPoints = null;

                    for (int i = 0; i < ConquestMap.Players.Count; i++)
                    {
                        if (!ConquestMap.Players[i].WarZone || ConquestMap.Players[i].MyGuild == null || ConquestMap.Players[i].Dead)
                        {
                            continue;
                        }

                        controlFlag       = item.Key;
                        controlFlagPoints = item.Value;

                        if (!Functions.InRange(controlFlag.Info.Location, ConquestMap.Players[i].CurrentLocation, 3))
                        {
                            continue;
                        }

                        controlFlagPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);

                        if (points == 0)
                        {
                            controlFlagPoints[ConquestMap.Players[i].MyGuild] = 1;
                            ConquestMap.Players[i].MyGuild.SendOutputMessage(string.Format("Gaining control of {1} {0:P0}", ((double)controlFlagPoints[ConquestMap.Players[i].MyGuild] / MAX_CONTROL_POINTS), controlFlag.Info.Name));
                        }
                        else if (points < MAX_CONTROL_POINTS)
                        {
                            controlFlagPoints[ConquestMap.Players[i].MyGuild] += 1;
                            ConquestMap.Players[i].MyGuild.SendOutputMessage(string.Format("Gaining control of {1} {0:P0}", ((double)controlFlagPoints[ConquestMap.Players[i].MyGuild] / MAX_CONTROL_POINTS), controlFlag.Info.Name));
                        }

                        List <GuildObject> guilds = controlFlagPoints.Keys.ToList();
                        foreach (var guild in guilds)
                        {
                            if (ConquestMap.Players[i].MyGuild == guild)
                            {
                                continue;
                            }
                            controlFlagPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);
                            if (controlFlagPoints[guild] > 0)
                            {
                                controlFlagPoints[guild] -= 1;
                            }
                        }

                        pointsChanged = true;
                    }

                    if (pointsChanged)
                    {
                        GuildObject tempWinning = Guild;
                        int         tempInt;

                        //Check Scores
                        for (int i = 0; i < Envir.Guilds.Count; i++)
                        {
                            controlFlagPoints.TryGetValue(Envir.Guilds[i], out points);
                            if (tempWinning != null)
                            {
                                controlFlagPoints.TryGetValue(tempWinning, out tempInt);
                            }
                            else
                            {
                                tempInt = 0;
                            }

                            if (points > tempInt)
                            {
                                tempWinning = Envir.Guilds[i];
                            }
                        }

                        if (tempWinning != controlFlag.Guild)
                        {
                            controlFlag.ChangeOwner(tempWinning);

                            for (int j = 0; j < ConquestMap.Players.Count; j++)
                            {
                                ConquestMap.Players[j].ReceiveChat(string.Format("{0} has captured {1} at {2}", tempWinning.Name, controlFlag.Info.Name, Info.Name), ChatType.System);
                            }
                        }
                    }
                }
            }
            break;

            case ConquestGame.KingOfHill:
            {
                int points;

                for (int i = 0; i < ConquestMap.Players.Count; i++)
                {
                    if (ConquestMap.Players[i].WarZone && ConquestMap.Players[i].MyGuild != null && !ConquestMap.Players[i].Dead && Functions.InRange(Info.KingLocation, ConquestMap.Players[i].CurrentLocation, Info.KingSize))
                    {
                        if (StartType == ConquestType.Request && ConquestMap.Players[i].MyGuild.Guildindex != GuildInfo.AttackerID)
                        {
                            continue;
                        }

                        if (ConquestMap.Players[i].MyGuild.Conquest != null && ConquestMap.Players[i].MyGuild.Conquest != this)
                        {
                            continue;
                        }

                        KingPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);

                        if (points == 0)
                        {
                            KingPoints[ConquestMap.Players[i].MyGuild] = 1;
                            ConquestMap.Players[i].MyGuild.SendOutputMessage(string.Format("Gaining control of {1} {0:P0}", ((double)KingPoints[ConquestMap.Players[i].MyGuild] / MAX_KING_POINTS), Info.Name));
                        }
                        else if (points < MAX_KING_POINTS)
                        {
                            KingPoints[ConquestMap.Players[i].MyGuild] += 1;
                            ConquestMap.Players[i].MyGuild.SendOutputMessage(string.Format("Gaining control of {1} {0:P0}", ((double)KingPoints[ConquestMap.Players[i].MyGuild] / MAX_KING_POINTS), Info.Name));
                        }

                        List <GuildObject> guilds = KingPoints.Keys.ToList();
                        foreach (var guild in guilds)
                        {
                            if (ConquestMap.Players[i].MyGuild == guild)
                            {
                                continue;
                            }
                            KingPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);
                            if (KingPoints[guild] > 0)
                            {
                                KingPoints[guild] -= 1;
                                guild.SendOutputMessage(string.Format("Losing control of {1} {0:P0}", ((double)KingPoints[guild] / MAX_KING_POINTS), Info.Name));
                            }
                        }

                        pointsChanged = true;
                    }
                }

                if (pointsChanged)
                {
                    GuildObject tempWinning = Guild;
                    int         tempInt;

                    //Check Scores
                    for (int i = 0; i < Envir.Guilds.Count; i++)
                    {
                        KingPoints.TryGetValue(Envir.Guilds[i], out points);
                        if (tempWinning != null)
                        {
                            KingPoints.TryGetValue(tempWinning, out tempInt);
                        }
                        else
                        {
                            tempInt = 0;
                        }

                        if (points > tempInt)
                        {
                            tempWinning = Envir.Guilds[i];
                        }
                    }

                    if (tempWinning != Guild)
                    {
                        TakeConquest(null, tempWinning);

                        for (int j = 0; j < ConquestMap.Players.Count; j++)
                        {
                            ConquestMap.Players[j].ReceiveChat(string.Format("{0} has captured the hill", tempWinning.Name), ChatType.System);
                        }
                    }
                }
            }
            break;

            case ConquestGame.Classic:
                int         guildCounter = 0;
                GuildObject takingGuild  = null;
                for (int i = 0; i < PalaceMap.Players.Count; i++)
                {
                    if (PalaceMap.Players[i].Dead)
                    {
                        continue;
                    }

                    if (PalaceMap.Players[i].MyGuild != null)
                    {
                        if (takingGuild == null || takingGuild != PalaceMap.Players[i].MyGuild)
                        {
                            guildCounter++;
                        }

                        takingGuild = PalaceMap.Players[i].MyGuild;
                    }
                    else
                    {
                        guildCounter++;
                    }
                }

                if (guildCounter == 1 && takingGuild != Guild)
                {
                    if (StartType == ConquestType.Request && takingGuild.Guildindex != GuildInfo.AttackerID)
                    {
                        return;
                    }

                    TakeConquest(null, takingGuild);
                }

                break;

            default:
                return;
            }
        }