public void UpdatePlayers(GuildObject tempGuild) { PlayerObject player = null; Packet p; if (tempGuild == null) { return; } for (int i = 0; i < tempGuild.Ranks.Count; i++) { for (int j = 0; j < tempGuild.Ranks[i].Members.Count; j++) { player = (PlayerObject)tempGuild.Ranks[i].Members[j].Player; if (player != null) { tempGuild.SendGuildStatus(player); p = new ServerPackets.ObjectGuildNameChanged { ObjectID = player.ObjectID, GuildName = player.MyGuild.GetName() }; BroadcastGuildName(player, p); } } } }
public void Spawn() { NPCInfo npcInfo = new NPCInfo { Name = Info.Name, FileName = Info.FileName, Location = Info.Location, Image = 1000 }; if (Conquest.Guild != null) { Guild = Conquest.Guild; npcInfo.Image = Guild.FlagImage; npcInfo.Colour = Guild.FlagColour; } Flag = new NPCObject(npcInfo) { CurrentMap = Conquest.ConquestMap }; Flag.CurrentMap.AddObject(Flag); Flag.Spawned(); }
public void ChangeOwner(GuildObject guild) { Guild = guild; UpdateImage(); UpdateColour(); }
public GuildAtWar(GuildObject a, GuildObject b) { GuildA = a; GuildB = b; GuildA.WarringGuilds.Add(GuildB); GuildB.WarringGuilds.Add(GuildA); TimeRemaining = Settings.Minute * Settings.Guild_WarTime; //make this changable in server form }
public GuildAtWar(GuildObject a, GuildObject b) { GuildA = a; GuildB = b; GuildA.WarringGuilds.Add(GuildB); GuildB.WarringGuilds.Add(GuildA); TimeRemaining = Settings.Minute * Settings.Guild_WarTime; }
public void EndWar(ConquestGame type) { WarIsOn = false; switch (type) { case ConquestGame.ControlPoints: Dictionary <GuildObject, int> controlledPoints = new Dictionary <GuildObject, int>(); int count = 0; foreach (KeyValuePair <ConquestGuildFlagInfo, Dictionary <GuildObject, int> > item in ControlPoints) { controlledPoints.TryGetValue(item.Key.Guild, out count); if (count == 0) { controlledPoints[item.Key.Guild] = 1; } else { controlledPoints[item.Key.Guild] += 1; } } GuildObject tempWinning = Guild; int tempInt; List <GuildObject> guilds = controlledPoints.Keys.ToList(); //Check Scores for (int i = 0; i < guilds.Count; i++) { controlledPoints.TryGetValue(guilds[i], out count); if (tempWinning != null) { controlledPoints.TryGetValue(tempWinning, out tempInt); } else { tempInt = 0; } if (count > tempInt) { tempWinning = Envir.Guilds[i]; } } TakeConquest(null, tempWinning); break; } }
public void ChangeConquestOwner(GuildObject gObj, PlayerObject pObj) { GuildObject tmpPrevious = null; Owner = pObj.MyGuild.Guildindex; Guild = pObj.MyGuild; pObj.MyGuild.Conquest = this; UpdatePlayers(Guild); if (tmpPrevious != null) { UpdatePlayers(tmpPrevious); } NeedSave = true; }
public bool GoToWar(GuildObject enemyGuild) { if (enemyGuild == null) { return(false); } if (Envir.GuildsAtWar.Where(e => e.GuildA == this && e.GuildB == enemyGuild).Any() || Envir.GuildsAtWar.Where(e => e.GuildA == enemyGuild && e.GuildB == this).Any()) { return(false); } Envir.GuildsAtWar.Add(new GuildAtWar(this, enemyGuild)); UpdatePlayersColours(); enemyGuild.UpdatePlayersColours(); return(true); }
public bool IsEnemy(GuildObject enemyGuild) { if (enemyGuild == null) { return(false); } if (enemyGuild.IsAtWar() != true) { return(false); } for (int i = 0; i < WarringGuilds.Count; i++) { if (WarringGuilds[i] == enemyGuild) { return(true); } } return(false); }
public void CalculateGuildWarPoints(GuildObject winner, GuildObject loser) { int Points = 10; float ratio;; if (winner.WarPoints == 0 || loser.WarPoints == 0) { ratio = 1f; } else { ratio = Math.Min((float)loser.WarPoints / (float)winner.WarPoints, 1.5f); } Points = Points * 15; winner.WarPoints = Math.Min(winner.WarPoints + Points, 10000); loser.WarPoints = Math.Max(loser.WarPoints - Points, 0); }
public void SendGuildStatus(PlayerObject member) { string gName = Name; string conquest = ""; if (Conquest != null) { conquest = "[" + Conquest.Info.Name + "]"; gName = gName + conquest; } GuildObject warGuild = null; if (WarringGuilds != null && WarringGuilds.Count > 0) { warGuild = WarringGuilds.First(); } member.Enqueue(new ServerPackets.GuildStatus() { GuildName = gName, GuildRankName = member.MyGuildRank != null ? member.MyGuildRank.Name : "", Experience = Experience, MaxExperience = MaxExperience, MemberCount = Membercount, MaxMembers = MemberCap, Gold = Gold, Level = Level, Voting = Voting, SparePoints = SparePoints, ItemCount = (byte)StoredItems.Length, BuffCount = (byte)0,//(byte)BuffList.Count, MyOptions = member.MyGuildRank != null ? member.MyGuildRank.Options : 0, MyRankId = member.MyGuildRank != null ? member.MyGuildRank.Index : 256, WarLoses = WarLoses, WarPoints = WarPoints, WarWins = WarWins, EnemyGuild = warGuild != null ? warGuild.Name : "None", TaxRate = TaxRate }); }
public void Reset() { Owner = -1; AttackerID = -1; GoldStorage = 0; npcRate = 0; if (Guild != null) { Guild.Conquest = null; UpdatePlayers(Guild); Guild = null; } for (int i = 0; i < ArcherList.Count; i++) { ArcherList[i].Spawn(); } for (int i = 0; i < GateList.Count; i++) { GateList[i].Repair(); } for (int i = 0; i < WallList.Count; i++) { WallList[i].Repair(); } for (int i = 0; i < SiegeList.Count; i++) { //SiegeList[i].Repair(); } NeedSave = true; }
private void StartGameSuccess() { Connection.Stage = GameStage.Game; Enqueue(new S.StartGame { Result = 4 }); ReceiveChat("Welcome to the Legend of Mir 2 C# Server.", ChatType.Hint); if (Info.GuildIndex != -1) { MyGuild = Envir.GetGuild(Info.GuildIndex); if (MyGuild == null) { Info.GuildIndex = -1; ReceiveChat("You have been removed from the guild.", ChatType.System); } else { MyGuildRank = MyGuild.FindRank(Info.Name); if (MyGuildRank == null) { MyGuild = null; Info.GuildIndex = -1; ReceiveChat("You have been removed from the guild.", ChatType.System); } } } Spawned(); SetLevelEffects(); GetItemInfo(); GetMapInfo(); GetUserInfo(); GetQuestInfo(); GetCompletedQuests(); GetMail(); for (int i = 0; i < CurrentQuests.Count; i++) { QuestProgressInfo quest = CurrentQuests[i]; quest.ResyncTasks(); SendUpdateQuest(quest, QuestState.Add); } Enqueue(new S.BaseStatsInfo { Stats = Settings.ClassBaseStats[(byte)Class] }); GetObjectsPassive(); Enqueue(new S.TimeOfDay { Lights = Envir.Lights }); Enqueue(new S.ChangeAMode { Mode = AMode }); if (Class == MirClass.Wizard || Class == MirClass.Taoist) Enqueue(new S.ChangePMode { Mode = PMode }); Enqueue(new S.SwitchGroup { AllowGroup = AllowGroup }); Enqueue(new S.DefaultNPC { ObjectID = DefaultNPC.ObjectID }); if (Info.Thrusting) Enqueue(new S.SpellToggle { Spell = Spell.Thrusting, CanUse = true }); if (Info.HalfMoon) Enqueue(new S.SpellToggle { Spell = Spell.HalfMoon, CanUse = true }); if (Info.CrossHalfMoon) Enqueue(new S.SpellToggle { Spell = Spell.CrossHalfMoon, CanUse = true }); if (Info.DoubleSlash) Enqueue(new S.SpellToggle { Spell = Spell.DoubleSlash, CanUse = true }); for (int i = 0; i < Info.Pets.Count; i++) { PetInfo info = Info.Pets[i]; MonsterObject monster = MonsterObject.GetMonster(Envir.GetMonsterInfo(info.MonsterIndex)); monster.PetLevel = info.Level; monster.MaxPetLevel = info.MaxPetLevel; monster.PetExperience = info.Experience; monster.Master = this; Pets.Add(monster); monster.RefreshAll(); if (!monster.Spawn(CurrentMap, Back)) monster.Spawn(CurrentMap, CurrentLocation); monster.SetHP(info.HP); if (!Settings.PetSave) { if (info.Time < 1 || (Envir.Time > info.Time + (Settings.PetTimeOut * Settings.Minute))) monster.Die(); } } Info.Pets.Clear(); for (int i = 0; i < Info.Buffs.Count; i++) { Buff buff = Info.Buffs[i]; buff.ExpireTime += Envir.Time; //buff.Caster = this; AddBuff(buff); } Info.Buffs.Clear(); for (int i = 0; i < Info.Poisons.Count; i++) { Poison poison = Info.Poisons[i]; poison.TickTime += Envir.Time; //poison.Owner = this; ApplyPoison(poison, poison.Owner); } Info.Poisons.Clear(); if (MyGuild != null) MyGuild.PlayerLogged(this, true); Report.Connected(Connection.IPAddress); SMain.Enqueue(string.Format("{0} has connected.", Info.Name)); }
public PlayerObject(CharacterInfo info, MirConnection connection) { if (info.Player != null) throw new InvalidOperationException("Player.Info not Null."); info.Player = this; info.Mount = new MountInfo(this); Connection = connection; Info = info; Account = Connection.Account; Report = new Reporting(this); if (Account.AdminAccount) { IsGM = true; SMain.Enqueue(string.Format("{0} is now a GM", Name)); } if (Level == 0) NewCharacter(); if (Info.GuildIndex != -1) { MyGuild = Envir.GetGuild(Info.GuildIndex); } RefreshStats(); if (HP == 0) { SetHP(MaxHP); SetMP(MaxMP); CurrentLocation = BindLocation; CurrentMapIndex = BindMapIndex; if (Info.PKPoints >= 200) { Map temp = Envir.GetMapByNameAndInstance(Settings.PKTownMapName, 1); Point tempLocation = new Point(Settings.PKTownPositionX, Settings.PKTownPositionY); if (temp != null && temp.ValidPoint(tempLocation)) { CurrentMapIndex = temp.Info.Index; CurrentLocation = tempLocation; } } } }
private void StartGameSuccess() { Connection.Stage = GameStage.Game; Enqueue(new S.StartGame { Result = 4, Resolution = Settings.AllowedResolution }); ReceiveChat("Welcome to the Legend of Mir 2 Crystal Server.", ChatType.Hint); if (Settings.TestServer) { ReceiveChat("Game is currently in test mode.", ChatType.Hint); Chat("@GAMEMASTER"); } if (Info.GuildIndex != -1) { //MyGuild = Envir.GetGuild(Info.GuildIndex); if (MyGuild == null) { Info.GuildIndex = -1; ReceiveChat("You have been removed from the guild.", ChatType.System); } else { MyGuildRank = MyGuild.FindRank(Info.Name); if (MyGuildRank == null) { MyGuild = null; Info.GuildIndex = -1; ReceiveChat("You have been removed from the guild.", ChatType.System); } } } Spawned(); SetLevelEffects(); GetItemInfo(); GetMapInfo(); GetUserInfo(); GetQuestInfo(); GetCompletedQuests(); GetMail(); GetFriends(); GetRelationship(); if ((Info.Mentor != 0) && (Info.MentorDate.AddDays(Settings.MentorLength) < DateTime.Now)) MentorBreak(); else GetMentor(); CheckConquest(); GetGameShop(); for (int i = 0; i < CurrentQuests.Count; i++) { CurrentQuests[i].ResyncTasks(); SendUpdateQuest(CurrentQuests[i], QuestState.Add); } Enqueue(new S.BaseStatsInfo { Stats = Settings.ClassBaseStats[(byte)Class] }); GetObjectsPassive(); Enqueue(new S.TimeOfDay { Lights = Envir.Lights }); Enqueue(new S.ChangeAMode { Mode = AMode }); if (Class == MirClass.Wizard || Class == MirClass.Taoist) Enqueue(new S.ChangePMode { Mode = PMode }); Enqueue(new S.SwitchGroup { AllowGroup = AllowGroup }); Enqueue(new S.DefaultNPC { ObjectID = DefaultNPC.ObjectID }); Enqueue(new S.GuildBuffList() { GuildBuffs = Settings.Guild_BuffList }); RequestedGuildBuffInfo = true; if (Info.Thrusting) Enqueue(new S.SpellToggle { Spell = Spell.Thrusting, CanUse = true }); if (Info.HalfMoon) Enqueue(new S.SpellToggle { Spell = Spell.HalfMoon, CanUse = true }); if (Info.CrossHalfMoon) Enqueue(new S.SpellToggle { Spell = Spell.CrossHalfMoon, CanUse = true }); if (Info.DoubleSlash) Enqueue(new S.SpellToggle { Spell = Spell.DoubleSlash, CanUse = true }); for (int i = 0; i < Info.Pets.Count; i++) { PetInfo info = Info.Pets[i]; MonsterObject monster = MonsterObject.GetMonster(Envir.GetMonsterInfo(info.MonsterIndex)); if (monster == null) continue; monster.PetLevel = info.Level; monster.MaxPetLevel = info.MaxPetLevel; monster.PetExperience = info.Experience; monster.Master = this; Pets.Add(monster); monster.RefreshAll(); if (!monster.Spawn(CurrentMap, Back)) monster.Spawn(CurrentMap, CurrentLocation); monster.SetHP(info.HP); if (!Settings.PetSave) { if (info.Time < 1 || (Envir.Time > info.Time + (Settings.PetTimeOut * Settings.Minute))) monster.Die(); } } Info.Pets.Clear(); for (int i = 0; i < Info.Buffs.Count; i++) { Buff buff = Info.Buffs[i]; buff.ExpireTime += Envir.Time; buff.Paused = false; AddBuff(buff); } Info.Buffs.Clear(); for (int i = 0; i < Info.Poisons.Count; i++) { Poison poison = Info.Poisons[i]; poison.TickTime += Envir.Time; //poison.Owner = this; ApplyPoison(poison, poison.Owner); } Info.Poisons.Clear(); if (MyGuild != null) { MyGuild.PlayerLogged(this, true); if (MyGuild.BuffList.Count > 0) Enqueue(new S.GuildBuffList() { ActiveBuffs = MyGuild.BuffList}); } if (InSafeZone && Info.LastDate > DateTime.MinValue) { double totalMinutes = (Envir.Now - Info.LastDate).TotalMinutes; _restedCounter = (int)(totalMinutes * 60); } Report.Connected(Connection.IPAddress); SMain.Enqueue(string.Format("{0} has connected.", Info.Name)); }
public void GuildInvite(bool accept) { if (PendingGuildInvite == null) { ReceiveChat("You have not been invited to a guild.", ChatType.System); return; } if (!accept) return; if (!PendingGuildInvite.HasRoom()) { ReceiveChat(String.Format("{0} is full.", PendingGuildInvite.Name), ChatType.System); return; } PendingGuildInvite.NewMember(this); Info.GuildIndex = PendingGuildInvite.Guildindex; MyGuild = PendingGuildInvite; MyGuildRank = PendingGuildInvite.FindRank(Name); GuildMembersChanged = true; GuildNoticeChanged = true; //tell us we now have a guild BroadcastInfo(); MyGuild.SendGuildStatus(this); PendingGuildInvite = null; EnableGuildInvite = false; GuildCanRequestItems = true; }
public void ScorePoints() { bool PointsChanged = false; switch (GameType) { case ConquestGame.KingOfHill: for (int i = 0; i < ConquestMap.Players.Count; i++) { if (ConquestMap.Players[i].WarZone && ConquestMap.GetInnerConquest(ConquestMap.Players[i].CurrentLocation) != null) { if (ConquestMap.Players[i].MyGuild != null) { if (StartType == ConquestType.Request && ConquestMap.Players[i].MyGuild.Guildindex != AttackerID) { continue; } if (ConquestMap.Players[i].MyGuild.Conquest != null && ConquestMap.Players[i].MyGuild.Conquest != this) { continue; } Points.TryGetValue(ConquestMap.Players[i].MyGuild, out points); if (points == 0) { Points[ConquestMap.Players[i].MyGuild] = 1; } else if (points < 15) { Points[ConquestMap.Players[i].MyGuild] += 1; } List <GuildObject> tempList = Points.Keys.ToList(); foreach (var item in tempList) { if (ConquestMap.Players[i].MyGuild == item) { continue; } Points.TryGetValue(ConquestMap.Players[i].MyGuild, out points); if (points > 0) { Points[item] -= 1; } } PointsChanged = true; } } } if (PointsChanged) { GuildObject tempWinning = Guild; int tempInt; //Check Scores for (int i = 0; i < Envir.GuildList.Count; i++) { Points.TryGetValue(Envir.GuildList[i], out points); if (tempWinning != null) { Points.TryGetValue(tempWinning, out tempInt); } else { tempInt = 0; } if (points > tempInt) { tempWinning = Envir.GuildList[i]; } } if (tempWinning != Guild) { TakeConquest(null, tempWinning); } } break; case ConquestGame.Classic: int GuildCounter = 0; GuildObject TakingGuild = null; for (int i = 0; i < PalaceMap.Players.Count; i++) { 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 != AttackerID) { return; } TakeConquest(null, TakingGuild); } break; default: return; } }
public void LoadGuilds() { lock (LoadLock) { int count = 0; GuildList.Clear(); for (int i = 0; i < GuildCount; i++) { GuildObject newGuild; if (File.Exists(Settings.GuildPath + i.ToString() + ".mgd")) { using (FileStream stream = File.OpenRead(Settings.GuildPath + i.ToString() + ".mgd")) using (BinaryReader reader = new BinaryReader(stream)) newGuild = new GuildObject(reader); //if (!newGuild.Ranks.Any(a => (byte)a.Options == 255)) continue; //if (GuildList.Any(e => e.Name == newGuild.Name)) continue; GuildList.Add(newGuild); count++; } } if (count != GuildCount) GuildCount = count; } }
public void UpdatePlayers(GuildObject tempGuild) { PlayerObject player = null; Packet p; for (int i = 0; i < tempGuild.Ranks.Count; i++) for (int j = 0; j < tempGuild.Ranks[i].Members.Count; j++) { player = (PlayerObject)tempGuild.Ranks[i].Members[j].Player; if (player != null) { tempGuild.SendGuildStatus(player); p = new ServerPackets.ObjectGuildNameChanged { ObjectID = player.ObjectID, GuildName = player.MyGuild.GetName()}; BroadcastGuildName(player, p); } } }
public void TakeConquest(PlayerObject player = null, GuildObject winningGuild = null) { if (winningGuild == null && (player == null || player.MyGuild == null || player.MyGuild.Conquest != null)) return; if (winningGuild != null && winningGuild.Conquest != null) return; if (player != null && player.MyGuild != null && player.MyGuild.Conquest != null) return; GuildObject tmpPrevious = null; switch (GameType) { case ConquestGame.CapturePalace: if (player == null) return; if (StartType == ConquestType.Request) if (player.MyGuild.Guildindex != AttackerID) break; if (Guild != null) { tmpPrevious = Guild; Guild.Conquest = null; AttackerID = tmpPrevious.Guildindex; } Owner = player.MyGuild.Guildindex; Guild = player.MyGuild; player.MyGuild.Conquest = this; WarIsOn = false; break; case ConquestGame.KingOfHill: case ConquestGame.Classic: if (StartType == ConquestType.Request) if (winningGuild.Guildindex != AttackerID) break; if (Guild != null) { tmpPrevious = Guild; Guild.Conquest = null; AttackerID = tmpPrevious.Guildindex; } Owner = winningGuild.Guildindex; Guild = winningGuild; Guild.Conquest = this; break; } UpdatePlayers(Guild); if (tmpPrevious != null) UpdatePlayers(tmpPrevious); NeedSave = true; }
public void TakeConquest(PlayerObject player = null, GuildObject winningGuild = null) { if (winningGuild == null && (player == null || player.MyGuild == null || player.MyGuild.Conquest != null)) { return; } if (winningGuild != null && winningGuild.Conquest != null) { return; } if (player != null && player.MyGuild != null && player.MyGuild.Conquest != null) { return; } GuildObject tmpPrevious = null; switch (GameType) { case ConquestGame.CapturePalace: if (player == null) { return; } if (StartType == ConquestType.Request) { if (player.MyGuild.Guildindex != AttackerID) { break; } } if (Guild != null) { tmpPrevious = Guild; Guild.Conquest = null; AttackerID = tmpPrevious.Guildindex; } Owner = player.MyGuild.Guildindex; Guild = player.MyGuild; player.MyGuild.Conquest = this; WarIsOn = false; break; case ConquestGame.KingOfHill: case ConquestGame.Classic: if (StartType == ConquestType.Request) { if (winningGuild.Guildindex != AttackerID) { break; } } if (Guild != null) { tmpPrevious = Guild; Guild.Conquest = null; AttackerID = tmpPrevious.Guildindex; } Owner = winningGuild.Guildindex; Guild = winningGuild; Guild.Conquest = this; break; } UpdatePlayers(Guild); if (tmpPrevious != null) { UpdatePlayers(tmpPrevious); } NeedSave = true; }
public void ScorePoints() { bool PointsChanged = false; switch (GameType) { case ConquestGame.ControlPoints: { int points; foreach (KeyValuePair <ConquestFlagObject, Dictionary <GuildObject, int> > item in ControlPoints) { PointsChanged = false; ConquestFlagObject 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.GuildList.Count; i++) { controlFlagPoints.TryGetValue(Envir.GuildList[i], out points); if (tempWinning != null) { controlFlagPoints.TryGetValue(tempWinning, out tempInt); } else { tempInt = 0; } if (points > tempInt) { tempWinning = Envir.GuildList[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 != 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.GuildList.Count; i++) { KingPoints.TryGetValue(Envir.GuildList[i], out points); if (tempWinning != null) { KingPoints.TryGetValue(tempWinning, out tempInt); } else { tempInt = 0; } if (points > tempInt) { tempWinning = Envir.GuildList[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 != AttackerID) { return; } TakeConquest(null, TakingGuild); } break; default: return; } }
public void TakeConquest(PlayerObject player = null, GuildObject winningGuild = null) { if (winningGuild == null && (player == null || player.MyGuild == null || player.MyGuild.Conquest != null)) { return; } if (winningGuild != null && winningGuild.Conquest != null) { return; } if (player != null && player.MyGuild != null && player.MyGuild.Conquest != null) { return; } GuildObject tmpPrevious = null; switch (GameType) { case ConquestGame.CapturePalace: if (player == null) { return; } if (StartType == ConquestType.Request) { if (player.MyGuild.Guildindex != AttackerID) { break; } } if (Guild != null) { tmpPrevious = Guild; Guild.Conquest = null; AttackerID = tmpPrevious.Guildindex; } Owner = player.MyGuild.Guildindex; Guild = player.MyGuild; player.MyGuild.Conquest = this; EndWar(GameType); break; case ConquestGame.KingOfHill: case ConquestGame.Classic: if (StartType == ConquestType.Request) { if (winningGuild.Guildindex != AttackerID) { break; } } if (Guild != null) { tmpPrevious = Guild; Guild.Conquest = null; AttackerID = tmpPrevious.Guildindex; } Owner = winningGuild.Guildindex; Guild = winningGuild; Guild.Conquest = this; break; case ConquestGame.ControlPoints: Owner = winningGuild.Guildindex; Guild = winningGuild; Guild.Conquest = this; List <ConquestFlagObject> keys = new List <ConquestFlagObject>(ControlPoints.Keys); foreach (ConquestFlagObject key in keys) { key.ChangeOwner(Guild); ControlPoints[key] = new Dictionary <GuildObject, int>(); } break; } for (int i = 0; i < FlagList.Count; i++) { FlagList[i].Guild = Guild; FlagList[i].UpdateImage(); FlagList[i].UpdateColour(); } if (Guild != null) { UpdatePlayers(Guild); if (tmpPrevious != null) { UpdatePlayers(tmpPrevious); } NeedSave = true; } }
public bool GoToWar(GuildObject enemyGuild) { if(enemyGuild == null) { return false; } if (Envir.GuildsAtWar.Where(e => e.GuildA == this && e.GuildB == enemyGuild).Any() || Envir.GuildsAtWar.Where(e => e.GuildA == enemyGuild || e.GuildB == this).Any()) { return false; } Envir.GuildsAtWar.Add(new GuildAtWar(this, enemyGuild)); UpdatePlayersColours(); enemyGuild.UpdatePlayersColours(); return true; }
public bool IsEnemy(GuildObject enemyGuild) { if (enemyGuild == null) return false; if (enemyGuild.IsAtWar() != true) return false; for (int i = 0; i < WarringGuilds.Count; i++) { if (WarringGuilds[i] == enemyGuild) return true; } return false; }
public void LoadGuilds() { lock (LoadLock) { for (int i = 0; i < GuildCount; i++) { GuildObject newGuild; if (!File.Exists(GuildPath + i.ToString() + ".mgd")) newGuild = new GuildObject(); else { using (FileStream stream = File.OpenRead(GuildPath + i.ToString() + ".mgd")) using (BinaryReader reader = new BinaryReader(stream)) newGuild = new GuildObject(reader); } GuildList.Add(newGuild); } } }
public void CreateNewbieGuild(string GuildName) { if (Envir.GetGuild(GuildName) != null) return; //make the guild GuildObject guild = new GuildObject(this, GuildName) { Guildindex = ++Envir.NextGuildID }; guild.Ranks[0].Members.Clear(); guild.Membercount--; Envir.GuildList.Add(guild); }
public bool CreateGuild(string GuildName) { if ((MyGuild != null) || (Info.GuildIndex != -1)) return false; if (Envir.GetGuild(GuildName) != null) return false; if (Info.Level < Settings.Guild_RequiredLevel) { ReceiveChat(String.Format("Your level is not high enough to create a guild, required: {0}", Settings.Guild_RequiredLevel), ChatType.System); return false; } //check if we have the required items for (int i = 0; i < Settings.Guild_CreationCostList.Count; i++) { ItemVolume Required = Settings.Guild_CreationCostList[i]; if (Required.Item == null) { if (Info.AccountInfo.Gold < Required.Amount) { ReceiveChat(String.Format("Insufficient gold. Creating a guild requires {0} gold.", Required.Amount), ChatType.System); return false; } } else { uint count = Required.Amount; foreach (var item in Info.Inventory.Where(item => item != null && item.Info == Required.Item)) { if ((Required.Item.Type == ItemType.Ore) && (item.CurrentDura / 1000 > Required.Amount)) { count = 0; break; } if (item.Count > count) count = 0; else count = count - item.Count; if (count == 0) break; } if (count != 0) { if (Required.Amount == 1) ReceiveChat(String.Format("{0} is required to create a guild.", Required.Item.Name), ChatType.System); else { if (Required.Item.Type == ItemType.Ore) ReceiveChat(string.Format("{0} with purity {1} is recuired to create a guild.", Required.Item.Name, Required.Amount / 1000), ChatType.System); else ReceiveChat(string.Format("Insufficient {0}, you need {1} to create a guild.", Required.Item.Name, Required.Amount), ChatType.System); } return false; } } } //take the required items for (int i = 0; i < Settings.Guild_CreationCostList.Count; i++) { ItemVolume Required = Settings.Guild_CreationCostList[i]; if (Required.Item == null) { if (Info.AccountInfo.Gold >= Required.Amount) { Info.AccountInfo.Gold -= Required.Amount; Enqueue(new S.LoseGold { Gold = Required.Amount }); } } else { uint count = Required.Amount; for (int o = 0; o < Info.Inventory.Length; o++) { UserItem item = Info.Inventory[o]; if (item == null) continue; if (item.Info != Required.Item) continue; if ((Required.Item.Type == ItemType.Ore) && (item.CurrentDura / 1000 > Required.Amount)) { Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = item.Count }); Info.Inventory[o] = null; break; } if (count > item.Count) { Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = item.Count }); Info.Inventory[o] = null; count -= item.Count; continue; } Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = count }); if (count == item.Count) Info.Inventory[o] = null; else item.Count -= count; break; } } } RefreshStats(); //make the guild GuildObject guild = new GuildObject(this, GuildName) { Guildindex = ++Envir.NextGuildID }; Envir.GuildList.Add(guild); Info.GuildIndex = guild.Guildindex; MyGuild = guild; MyGuildRank = guild.FindRank(Name); GuildMembersChanged = true; GuildNoticeChanged = true; GuildCanRequestItems = true; //tell us we now have a guild BroadcastInfo(); MyGuild.SendGuildStatus(this); return true; }
private void StartGameSuccess() { Connection.Stage = GameStage.Game; Enqueue(new S.StartGame { Result = 4 }); ReceiveChat("Welcome to the Legend of Mir 2 C# Server.", ChatType.Hint); if (Info.GuildIndex != -1) { MyGuild = Envir.GetGuild(Info.GuildIndex); if (MyGuild == null) { Info.GuildIndex = -1; ReceiveChat("You have been removed from the guild.", ChatType.System); } else { MyGuildRank = MyGuild.FindRank(Info.Name); if (MyGuildRank == null) { MyGuild = null; Info.GuildIndex = -1; ReceiveChat("You have been removed from the guild.", ChatType.System); } } } Spawned(); GetItemInfo(); GetMapInfo(); GetUserInfo(); Enqueue(new S.BaseStatsInfo { Stats = Settings.ClassBaseStats[(byte)Class] }); GetObjectsPassive(); Enqueue(new S.TimeOfDay { Lights = Envir.Lights }); Enqueue(new S.ChangeAMode { Mode = AMode }); if (Class == MirClass.Wizard || Class == MirClass.Taoist) Enqueue(new S.ChangePMode {Mode = PMode}); Enqueue(new S.SwitchGroup { AllowGroup = AllowGroup }); if (Info.Thrusting) Enqueue(new S.SpellToggle { Spell = Spell.Thrusting, CanUse = true }); if (Info.HalfMoon) Enqueue(new S.SpellToggle { Spell = Spell.HalfMoon, CanUse = true }); if (Info.CrossHalfMoon) Enqueue(new S.SpellToggle { Spell = Spell.CrossHalfMoon, CanUse = true }); if (Info.DoubleSlash) Enqueue(new S.SpellToggle { Spell = Spell.DoubleSlash, CanUse = true }); for (int i = 0; i < Info.Pets.Count; i++) { PetInfo info = Info.Pets[i]; MonsterObject monster = MonsterObject.GetMonster(Envir.GetMonsterInfo(info.MonsterIndex)); monster.PetLevel = info.Level; monster.MaxPetLevel = info.MaxPetLevel; monster.PetExperience = info.Experience; monster.Master = this; Pets.Add(monster); monster.RefreshAll(); if (!monster.Spawn(CurrentMap, Back)) monster.Spawn(CurrentMap, CurrentLocation); monster.SetHP(info.HP); } Info.Pets.Clear(); if (MyGuild != null) MyGuild.PlayerLogged(this, true); SMain.Enqueue(string.Format("{0} has connected.", Info.Name)); }