Skip to content

Commit

Permalink
Allow games to override map rating system
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Dec 27, 2023
1 parent fd4fc71 commit c771fe7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
8 changes: 1 addition & 7 deletions MCGalaxy/Commands/Fun/RateMapCmds.cs
Expand Up @@ -44,15 +44,9 @@ public class CmdLike : Command2
p.Message("Cannot {0}like this map as you are an author of it.", prefix); return false;
}

if (like) p.level.Config.Likes++;
else p.level.Config.Dislikes++;

game.RateMap(p, like);
p.Game.RatedMap = true;
p.Game.LikedMap = like;
p.level.SaveSettings();

prefix = like ? "&a" : "&cdis";
p.Message("You have {0}liked &Sthis map.", prefix);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/Information/CmdMapInfo.cs
Expand Up @@ -123,7 +123,7 @@ public sealed class CmdMapInfo : Command2
IGame game = GetAssociatedGame(data.MapName);
if (game == null) return;

IGame.OutputMapSummary(p, cfg); // TODO: Always show this info?
game.OutputMapSummary(p, data.MapName, cfg); // TODO: Always show this info?
game.OutputMapInfo(p, data.MapName, cfg);
}

Expand Down
14 changes: 12 additions & 2 deletions MCGalaxy/Games/IGame.cs
Expand Up @@ -64,7 +64,7 @@ public abstract class IGame
/// that this game can be automatically played on </summary>
public virtual bool ClaimsMap(string map) { return false; }

public static void OutputMapSummary(Player p, LevelConfig cfg) {
public virtual void OutputMapSummary(Player p, string map, LevelConfig cfg) {
p.Message("This map has &a{0} likes &Sand &c{1} dislikes",
cfg.Likes, cfg.Dislikes);
string[] authors = cfg.Authors.SplitComma();
Expand Down Expand Up @@ -166,6 +166,16 @@ public abstract class IGame
if (reward == 0) return;
p.Message("&6You gained " + reward + " " + Server.Config.Currency);
p.SetMoney(p.money + reward);
}
}


public virtual void RateMap(Player p, bool like) {
if (like) Map.Config.Likes++;
else Map.Config.Dislikes++;
Map.SaveSettings();

string prefix = like ? "&a" : "&cdis";
p.Message("You have {0}liked &Sthis map.", prefix);
}
}
}
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Games/CTF/CtfGame.Plugin.cs
Expand Up @@ -137,7 +137,7 @@ public partial class CTFGame : RoundsGame

void HandleSentMap(Player p, Level prevLevel, Level level) {
if (level != Map) return;
OutputMapSummary(p, Map.Config);
OutputMapSummary(p, Map.name, Map.Config);
if (TeamOf(p) == null) AutoAssignTeam(p);
}

Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Games/LavaSurvival/LSGame.Plugin.cs
Expand Up @@ -61,7 +61,7 @@ public partial class LSGame : RoundsGame

if (Map != level) return;
ResetRoundState(p, Get(p)); // TODO: Check for /reload case?
OutputMapSummary(p, Map.Config);
OutputMapSummary(p, Map.name, Map.Config);
if (RoundInProgress) OutputStatus(p);
}

Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Games/TNTWars/TWGame.Plugin.cs
Expand Up @@ -114,7 +114,7 @@ public partial class TWGame : RoundsGame

void HandleSentMap(Player p, Level prevLevel, Level level) {
if (level != Map) return;
OutputMapSummary(p, Map.Config);
OutputMapSummary(p, Map.name, Map.Config);
if (TeamOf(p) == null) AutoAssignTeam(p);
}

Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Games/ZombieSurvival/ZSGame.Plugin.cs
Expand Up @@ -157,7 +157,7 @@ public partial class ZSGame : RoundsGame
p.Message("&a{0} &Sseconds left until the round starts. &aRun!", (int)startLeft);
}

OutputMapSummary(p, Map.Config);
OutputMapSummary(p, Map.name, Map.Config);
p.Message("This map's win chance is &a{0}&S%", Map.WinChance);
}

Expand Down

0 comments on commit c771fe7

Please sign in to comment.