Skip to content

Commit ec061d2

Browse files
committed
Allow survivors to leave a team
1 parent 8812e55 commit ec061d2

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/DevChatter.Bot.Modules.WastefulGame/Commands/Operations/LeaveTeamOperation.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ namespace DevChatter.Bot.Modules.WastefulGame.Commands.Operations
77
{
88
public class LeaveTeamOperation : BaseGameCommandOperation
99
{
10+
private readonly IGameRepository _gameRepository;
11+
1012
public LeaveTeamOperation(IGameRepository gameRepository)
1113
{
14+
_gameRepository = gameRepository;
1215
}
1316

1417
public override List<string> OperandWords { get; }
@@ -17,7 +20,20 @@ public LeaveTeamOperation(IGameRepository gameRepository)
1720
public override string TryToExecute(CommandReceivedEventArgs eventArgs,
1821
Survivor survivor)
1922
{
20-
return "You cannot leave teams yet. Please wait for this feature.";
23+
Team team = survivor.Team;
24+
25+
if (team == null)
26+
{
27+
return "You are not currently on a team.";
28+
}
29+
30+
if (survivor.LeaveTeam())
31+
{
32+
_gameRepository.Update(survivor);
33+
return $"You left the {team.Name} team.";
34+
}
35+
36+
return $"Failed to leave the team.";
2137
}
2238
}
2339
}

src/DevChatter.Bot.Modules.WastefulGame/Model/Survivor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Survivor(string displayName, string userId)
2020
public string UserId { get; set; }
2121
public string DisplayName { get; set; }
2222
public Team Team { get; set; }
23-
public long Money { get; set; }
23+
public long Money { get; set; } = 100;
2424
public List<GameEndRecord> GameEndRecords { get; set; }
2525
= new List<GameEndRecord>();
2626

@@ -71,5 +71,16 @@ public bool BuyItem(ShopItem shopItem)
7171
}
7272
return false;
7373
}
74+
75+
public bool LeaveTeam()
76+
{
77+
if (Team == null)
78+
{
79+
return false;
80+
}
81+
82+
Team = null;
83+
return true;
84+
}
7485
}
7586
}

0 commit comments

Comments
 (0)