public async Task Party() { var idList = new ContextIds(Context); var user = UserHandler.GetUser(idList.UserId); //Tests each case to make sure all circumstances for the execution of this command are valid (character exists, in correct location) try { await UserHandler.CharacterExists(idList); await UserHandler.ValidCharacterLocation(idList); } catch (InvalidCharacterStateException) { return; } var count = 6; foreach (BasicMon mon in user.Char.Party) { await MessageHandler.SendEmbedMessage(idList, "", MonEmbedBuilder.FieldMon(mon)); count--; } await MessageHandler.SendEmbedMessage(idList, "", MonEmbedBuilder.EmptyPartySpot(count)); }
public async Task StartCombat() { //Make sure all users have a valid party foreach (Team t in Teams) { foreach (UserAccount u in t.Members) { if (!u.Char.HasLivingParty()) { ExitCombatAll(); await MessageHandler.SendMessage(Location, $"Duel canceled! {u.Mention} does not have a valid party."); return; } } } //Send out all mons. (NEEDS EDITING- COULD BE MORE THAN 2 TEAMS) await MessageHandler.SendMessage(Location, $"The battle between Team {Teams[0].TeamName} and Team {Teams[1].TeamName} will now begin!"); foreach (Team t in Teams) { foreach (UserAccount u in t.Members) { for (int i = 0; i < t.MultiNum; i++) { if (u.Char.HasUsableMon()) { BasicMon sentMon = u.Char.FirstUsableMon(); u.Char.ActiveMons.Add(sentMon); sentMon.IsCombatActive = true; //sentMon.OnEnteredCombat(this); await MessageHandler.SendEmbedMessage(Location, $"{u.Mention} sends out **{sentMon.Nickname}**!", MonEmbedBuilder.FieldMon(sentMon)); } } } } CombatPhase = 0; await ResolvePhase(); }
public async Task ResolvePhase() { //PHASE 0 if (CombatPhase == 0) { Console.WriteLine($"1"); //0- check if mons need sending out, activate abilities such as Intimidate //Enter this phase at combat start or when a Mon faints. //Decides whether or not to continue combat foreach (Team t in Teams) { Console.WriteLine($"2"); foreach (UserAccount u in t.Members) { Console.WriteLine($"3"); //If any mons are fainted, remove them from ActiveMons for (int i = u.Char.ActiveMons.Count - 1; i >= 0; i--) { Console.WriteLine($"4"); if (u.Char.ActiveMons[i].Fainted) { Console.WriteLine($"5"); u.Char.ActiveMons.RemoveAt(i); } } Console.WriteLine($"6"); //If the number of ActiveMons is less than the number allowed active, send out the first usable mon if a usable mon exists until the number of ActiveMons equals the number allowed active if (u.Char.ActiveMons.Count < t.MultiNum) { Console.WriteLine($"7"); for (int i = u.Char.ActiveMons.Count; i < t.MultiNum; i++) { Console.WriteLine($"8"); if (u.Char.HasUsableMon()) { Console.WriteLine($"9"); BasicMon sentMon = u.Char.FirstUsableMon(); Console.WriteLine($"10"); u.Char.ActiveMons.Add(sentMon); Console.WriteLine($"11"); sentMon.IsCombatActive = true; Console.WriteLine($"12"); //sentMon.OnEnteredCombat(this); await MessageHandler.SendEmbedMessage(Location, $"{u.Mention} sends out **{sentMon.Nickname}**!", MonEmbedBuilder.FieldMon(sentMon)); Console.WriteLine($"13"); } } } Console.WriteLine($"14"); if (u.Char.ActiveMons.Count == 0 || !u.Char.HasLivingParty()) { Console.WriteLine($"15"); u.Char.CombatEliminated = true; Console.WriteLine($"16"); await MessageHandler.SendMessage(Location, $"{u.Mention} has run out of mons!"); Console.WriteLine($"17"); await CheckTeamElimination(GetTeam(u)); if (CombatOver) { return; } Console.WriteLine($"18"); } } } Console.WriteLine($"19"); if (CombatOver) { return; } //Continue to the next phase if combat has not ended else { Console.WriteLine($"20"); CombatPhase = 1; await ResolvePhase(); } } //PHASE 1 else if (CombatPhase == 1) { Console.WriteLine($"21"); //1- Pre turn, activate weather effects... "It is still raining!" or "The rain cleared up!" foreach (Team t in Teams) { Console.WriteLine($"22"); foreach (UserAccount u in t.Members) { var allbuffered = true; foreach (BasicMon m in u.Char.ActiveMons) { if (m.BufferedMove == null) { allbuffered = false; } else { m.SelectedMove = m.BufferedMove; } } if (allbuffered) { u.Char.CombatMovesEntered = true; } else { u.Char.CombatMovesEntered = false; await MessageHandler.FightScreenNew(u.UserId); } } Console.WriteLine($"25"); } /*Send fight screens to both players and progress to Phase 2 (wait for input) * if(inst.PlayerOne.Char.ActiveMon.BufferedMove == null) * await MessageHandler.FightScreen(inst.PlayerOne.UserId); * else * { * inst.PlayerOne.Char.ActiveMon.SelectedMove = inst.PlayerOne.Char.ActiveMon.BufferedMove; * } * * if(inst.PlayerTwo.Char.ActiveMon.BufferedMove == null) * await MessageHandler.FightScreen(inst.PlayerTwo.UserId); * else * { * inst.PlayerTwo.Char.ActiveMon.SelectedMove = inst.PlayerTwo.Char.ActiveMon.BufferedMove; * }*/ CombatPhase = 2; } //PHASE 2 else if (CombatPhase == 2) { //2- Awaiting input from players var unready = 0; Console.WriteLine($"26"); foreach (Team t in Teams) { Console.WriteLine($"27"); foreach (UserAccount u in t.Members) { Console.WriteLine($"28"); foreach (BasicMon m in u.Char.ActiveMons) { Console.WriteLine($"29"); if (m.SelectedMove == null) { Console.WriteLine($"30"); unready++; Console.WriteLine($"31"); break; } } } } Console.WriteLine($"32"); var complete = true; foreach (Team t in Teams) { Console.WriteLine($"33"); foreach (UserAccount u in t.Members) { Console.WriteLine($"34"); var finished = true; foreach (BasicMon m in u.Char.ActiveMons) { Console.WriteLine($"35"); if (m.SelectedMove == null) { Console.WriteLine($"36"); finished = false; complete = false; break; } } Console.WriteLine($"37"); if (finished && !u.Char.CombatMovesEntered && unready != 0) { Console.WriteLine($"38"); await MessageHandler.AttackEnteredTextNew(Location, u, unready); Console.WriteLine($"39"); u.Char.CombatMovesEntered = true; Console.WriteLine($"40"); } } } Console.WriteLine($"41"); //If all players have entered a move, apply moves if (complete) { Console.WriteLine($"42"); CombatPhase = 3; Console.WriteLine($"43"); await ResolvePhase(); } } //PHASE 3 else if (CombatPhase == 3) { Console.WriteLine($"45"); //Pre-attack phase, activate necessary abilities if (!Environment.Clear) { await MessageHandler.SendMessage(Location, Environment.WeatherToString()); } Console.WriteLine($"46"); CombatPhase = 4; await ResolvePhase(); } //PHASE 4 else if (CombatPhase == 4) { Console.WriteLine($"47"); var mons = GetAllMons(); Console.WriteLine($"48"); //Sort all mons by their speed for (int j = mons.Count - 1; j > 0; j--) { Console.WriteLine($"49"); for (int i = 0; i < j; i++) { Console.WriteLine($"50"); if (mons[i].GetAdjustedSpd() > mons[i + 1].GetAdjustedSpd()) { Console.WriteLine($"51"); var temp = mons[i]; Console.WriteLine($"52"); mons[i] = mons[i + 1]; Console.WriteLine($"53"); mons[i + 1] = temp; Console.WriteLine($"54"); } Console.WriteLine($"55"); } Console.WriteLine($"56"); } Console.WriteLine($"57"); mons.Reverse(); Console.WriteLine($"58"); //4- Attacks register. Calculate whether it hit, damage, bonus effects of attacks foreach (BasicMon mon in mons) { Console.WriteLine($"59"); if (!mon.Fainted) { await ApplyMoves(mon); } Console.WriteLine($"60"); } Console.WriteLine($"61"); CombatPhase = 6; await ResolvePhase(); } else if (CombatPhase == 6) { Console.WriteLine($"62"); //6- Post turn phase. Reset necessary data //Mon post-turn ticks and resets foreach (BasicMon mon in GetAllMons()) { Console.WriteLine($"63"); //Check if sleepy, if they are, fall asleep if (mon.SleepyCheck()) { await MessageHandler.SendMessage(Location, $"{mon.Nickname} has been afflicted with *Sleep*"); } Console.WriteLine($"64"); var damageType = mon.StatusDamage(); Console.WriteLine($"65"); if (damageType == "Burn") { await MessageHandler.SendMessage(Location, $"{mon.Nickname} takes burn damage!"); } Console.WriteLine($"66"); if (mon.Status.Flinching) { mon.Status.Flinching = false; } Console.WriteLine($"67"); if (mon.SelectedMove != null) { if (!mon.SelectedMove.Buffered) { mon.SelectedMove.WipeTargets(); } } Console.WriteLine($"68"); mon.SelectedMove = null; Console.WriteLine($"69"); } CombatPhase = 0; await ResolvePhase(); } }
public static async Task StartCombat(CombatInstance main) { var other = GetOppositeInstance(main); var user = GetUserOfInstance(main); var otherUser = GetUserOfInstance(other); //Make sure both users have a valid party if (!PlayerHasValidParty(main)) { user.Char.ExitCombat(); otherUser.Char.ExitCombat(); await MessageHandler.SendMessage(main.Location, $"Duel canceled! {user.Mention} does not have a valid party."); return; } else if (!PlayerHasValidParty(other)) { user.Char.ExitCombat(); otherUser.Char.ExitCombat(); await MessageHandler.SendMessage(main.Location, $"Duel canceled! {otherUser.Mention} does not have a valid party."); return; } //Send out both mons. var mainMon = user.Char.FirstUsableMon(); var otherMon = otherUser.Char.FirstUsableMon(); main.ActiveMon = mainMon; other.EnemyMon = mainMon; await MessageHandler.SendEmbedMessage(main.Location, $"{user.Mention} sends out **{main.ActiveMon.Nickname}**!", MonEmbedBuilder.FieldMon(main.ActiveMon)); main.EnemyMon = otherMon; other.ActiveMon = otherMon; await MessageHandler.SendEmbedMessage(main.Location, $"{otherUser.Mention} sends out **{other.ActiveMon.Nickname}**!", MonEmbedBuilder.FieldMon(other.ActiveMon)); main.CombatPhase = 0; other.CombatPhase = 0; await NextStep(main); }