Skip to content

Commit

Permalink
Fixes and changes to factions
Browse files Browse the repository at this point in the history
  • Loading branch information
Byte-Nova committed Dec 28, 2024
1 parent 4183b57 commit 35a79fb
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 200 deletions.
66 changes: 33 additions & 33 deletions Source/Client/Managers/GuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ public static class GuildManager
{
public static void ParsePacket(Packet packet)
{
PlayerFactionData data = Serializer.ConvertBytesToObject<PlayerFactionData>(packet.contents);
PlayerGuildData data = Serializer.ConvertBytesToObject<PlayerGuildData>(packet.contents);

switch (data._stepMode)
{
case FactionStepMode.Create:
case GuildStepMode.Create:
OnCreateFaction();
break;

case FactionStepMode.Delete:
case GuildStepMode.Delete:
OnDeleteFaction();
break;

case FactionStepMode.NameInUse:
case GuildStepMode.NameInUse:
OnFactionNameInUse();
break;

case FactionStepMode.NoPower:
case GuildStepMode.NoPower:
OnFactionNoPower();
break;

case FactionStepMode.AddMember:
case GuildStepMode.AddMember:
OnFactionGetInvited(data);
break;

case FactionStepMode.RemoveMember:
case GuildStepMode.RemoveMember:
OnFactionGetKicked();
break;

case FactionStepMode.AdminProtection:
case GuildStepMode.AdminProtection:
OnFactionAdminProtection();
break;

case FactionStepMode.MemberList:
case GuildStepMode.MemberList:
OnFactionMemberList(data);
break;
}
Expand All @@ -56,17 +56,17 @@ public static void OnFactionOpen()
{
DialogManager.PushNewDialog(new RT_Dialog_Wait("Waiting for member list"));

PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.MemberList;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.MemberList;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Network.listener.EnqueuePacket(packet);
};

Action r2 = delegate
{
PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.RemoveMember;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.RemoveMember;
playerFactionData._dataInt = SessionValues.chosenSettlement.Tile;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Expand All @@ -77,8 +77,8 @@ public static void OnFactionOpen()
{
DialogManager.PushNewDialog(new RT_Dialog_Wait("Waiting for faction deletion"));

PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.Delete;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.Delete;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Network.listener.EnqueuePacket(packet);
Expand Down Expand Up @@ -111,9 +111,9 @@ public static void OnNoFactionOpen()
{
DialogManager.PushNewDialog(new RT_Dialog_Wait("Waiting for faction creation"));

PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.Create;
playerFactionData._factionFile.Name = DialogManager.dialog1ResultOne;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.Create;
playerFactionData._file.Name = DialogManager.dialog1ResultOne;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Network.listener.EnqueuePacket(packet);
Expand All @@ -131,8 +131,8 @@ public static void OnFactionOpenOnMember()
{
Action r1 = delegate
{
PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.Promote;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.Promote;
playerFactionData._dataInt = SessionValues.chosenSettlement.Tile;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Expand All @@ -141,8 +141,8 @@ public static void OnFactionOpenOnMember()

Action r2 = delegate
{
PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.Demote;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.Demote;
playerFactionData._dataInt = SessionValues.chosenSettlement.Tile;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Expand All @@ -151,8 +151,8 @@ public static void OnFactionOpenOnMember()

Action r3 = delegate
{
PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.RemoveMember;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.RemoveMember;
playerFactionData._dataInt = SessionValues.chosenSettlement.Tile;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Expand Down Expand Up @@ -190,8 +190,8 @@ public static void OnFactionOpenOnNonMember()
{
Action r1 = delegate
{
PlayerFactionData playerFactionData = new PlayerFactionData();
playerFactionData._stepMode = FactionStepMode.AddMember;
PlayerGuildData playerFactionData = new PlayerGuildData();
playerFactionData._stepMode = GuildStepMode.AddMember;
playerFactionData._dataInt = SessionValues.chosenSettlement.Tile;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), playerFactionData);
Expand Down Expand Up @@ -237,19 +237,19 @@ private static void OnFactionNoPower()
DialogManager.PushNewDialog(new RT_Dialog_Error("You don't have enough power for this action!"));
}

private static void OnFactionGetInvited(PlayerFactionData factionManifest)
private static void OnFactionGetInvited(PlayerGuildData factionManifest)
{
Action r1 = delegate
{
ServerValues.hasFaction = true;

factionManifest._stepMode = FactionStepMode.AcceptInvite;
factionManifest._stepMode = GuildStepMode.AcceptInvite;

Packet packet = Packet.CreatePacketFromObject(nameof(GuildManager), factionManifest);
Network.listener.EnqueuePacket(packet);
};

RT_Dialog_YesNo d1 = new RT_Dialog_YesNo($"Invited to {factionManifest._factionFile.Name}, accept?", r1, null);
RT_Dialog_YesNo d1 = new RT_Dialog_YesNo($"Invited to {factionManifest._file.Name}, accept?", r1, null);
DialogManager.PushNewDialog(d1);
}

Expand All @@ -265,15 +265,15 @@ private static void OnFactionAdminProtection()
DialogManager.PushNewDialog(new RT_Dialog_Error("You can't do this action as a faction admin!"));
}

private static void OnFactionMemberList(PlayerFactionData factionManifest)
private static void OnFactionMemberList(PlayerGuildData factionManifest)
{
DialogManager.PopWaitDialog();

List<string> toDisplay = new List<string>();
for (int i = 0; i < factionManifest._factionFile.CurrentMembers.Count; i++)
for (int i = 0; i < factionManifest._file.CurrentUids.Count; i++)
{
toDisplay.Add($"{factionManifest._factionFile.CurrentMembers[i]} " +
$"- {(FactionRanks)factionManifest._factionFile.CurrentRanks[i]}");
toDisplay.Add($"{factionManifest._file.CurrentLabels[i]} " +
$"- {(FactionRanks)factionManifest._file.CurrentRanks[i]}");
}

RT_Dialog_Listing d1 = new RT_Dialog_Listing("Faction Members",
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Managers/SiteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static void RequestSiteBuild(SiteInfoFile configFile)
siteData._stepMode = SiteStepMode.Build;
siteData._siteFile.Tile = SessionValues.chosenCaravan.Tile;
siteData._siteFile.Type.DefName = configFile.DefName;
if (ServerValues.hasFaction) siteData._siteFile.FactionFile = new FactionFile();
if (ServerValues.hasFaction) siteData._siteFile.File = new GuildFile();

Packet packet = Packet.CreatePacketFromObject(nameof(SiteManager), siteData);
Network.listener.EnqueuePacket(packet);
Expand Down
6 changes: 3 additions & 3 deletions Source/Server/Files/UserFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UserFile

public UserRelationshipsFile Relationships = new UserRelationshipsFile();

public FactionFile FactionFile;
public GuildFile GuildFile;

public SiteConfigFile[] SiteConfigs = Array.Empty<SiteConfigFile>();

Expand All @@ -40,9 +40,9 @@ public void SetLoginDetails(LoginData data)
Label = data._username;
}

public void UpdateFaction(FactionFile toUpdateWith)
public void UpdateFaction(GuildFile toUpdateWith)
{
FactionFile = toUpdateWith;
GuildFile = toUpdateWith;

UserManagerH.SaveUserFile(this);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Server/Managers/GlobalDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static ServerGlobalData GetClientValues(ServerClient client, ServerGlobal
{
globalData._isClientAdmin = client.userFile.IsAdmin;

globalData._isClientFactionMember = client.userFile.FactionFile != null;
globalData._isClientFactionMember = client.userFile.GuildFile != null;

return globalData;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public static ServerGlobalData GetServerSites(ServerClient client, ServerGlobalD
file.UID = site.UID;
file.Goodwill = GoodwillManager.GetSiteGoodwill(client, site);
file.Type = site.Type;
file.FactionFile = site.FactionFile;
file.File = site.File;

tempList.Add(file);
}
Expand Down
42 changes: 21 additions & 21 deletions Source/Server/Managers/GoodwillManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void ChangeUserGoodwills(ServerClient client, FactionGoodwillData
if (settlementFile != null) data._uid = settlementFile.UID;
else data._uid = siteFile.UID;

if (client.userFile.FactionFile != null && client.userFile.FactionFile.CurrentMembers.Contains(data._uid))
if (client.userFile.GuildFile != null && client.userFile.GuildFile.CurrentUids.Contains(data._uid))
{
ResponseShortcutManager.SendBreakPacket(client);
return;
Expand Down Expand Up @@ -90,7 +90,7 @@ public static Goodwill GetGoodwillFromTile(ServerClient client, int tileToCheck)
if (settlementFile != null) usernameToCheck = settlementFile.UID;
else usernameToCheck = siteFile.UID;

if (client.userFile.FactionFile != null && FactionManagerHelper.GetFactionFromFactionName(client.userFile.FactionFile.Name).CurrentMembers.Contains(usernameToCheck))
if (client.userFile.GuildFile != null && GuildManagerH.GetFactionFromFactionName(client.userFile.GuildFile.Name).CurrentUids.Contains(usernameToCheck))
{
if (usernameToCheck == client.userFile.Uid) return Goodwill.Personal;
else return Goodwill.Faction;
Expand All @@ -103,7 +103,7 @@ public static Goodwill GetGoodwillFromTile(ServerClient client, int tileToCheck)

public static Goodwill GetSettlementGoodwill(ServerClient client, SettlementFile settlement)
{
if (client.userFile.FactionFile != null && FactionManagerHelper.GetFactionFromFactionName(client.userFile.FactionFile.Name).CurrentMembers.Contains(settlement.UID))
if (client.userFile.GuildFile != null && GuildManagerH.GetFactionFromFactionName(client.userFile.GuildFile.Name).CurrentUids.Contains(settlement.UID))
{
if (settlement.UID == client.userFile.Uid) return Goodwill.Personal;
else return Goodwill.Faction;
Expand All @@ -119,23 +119,23 @@ public static Goodwill GetSiteGoodwill(ServerClient client, SiteIdendityFile sit
{
if (client.userFile.Uid == site.UID) return Goodwill.Personal; //We check if the players is the owner

if (site.FactionFile != null)
if (site.File != null)
{
FactionFile factionFile = FactionManagerHelper.GetFactionFromFactionName(site.FactionFile.Name);
GuildFile factionFile = GuildManagerH.GetFactionFromFactionName(site.File.Name);

if (client.userFile.FactionFile != null && client.userFile.FactionFile.Name == factionFile.Name) return Goodwill.Faction; // We check if the player is in the faction
if (client.userFile.GuildFile != null && client.userFile.GuildFile.Name == factionFile.Name) return Goodwill.Faction; // We check if the player is in the faction

foreach (string str in client.userFile.Relationships.EnemyPlayers) // We check if the player is enemy with the faction
{
if (FactionManagerHelper.CheckIfUserIsInFaction(factionFile, str))
if (GuildManagerH.CheckIfUserIsInFaction(factionFile, str))
{
return Goodwill.Enemy;
}
}

foreach (string str in client.userFile.Relationships.AllyPlayers) // We check if the player is allied with the faction
{
if (FactionManagerHelper.CheckIfUserIsInFaction(factionFile, str))
if (GuildManagerH.CheckIfUserIsInFaction(factionFile, str))
{
return Goodwill.Ally;
}
Expand All @@ -150,28 +150,28 @@ public static Goodwill GetSiteGoodwill(ServerClient client, SiteIdendityFile sit
return Goodwill.Neutral;
}

public static void ClearAllFactionMemberGoodwills(FactionFile factionFile)
public static void ClearAllFactionMemberGoodwills(GuildFile factionFile)
{
ServerClient[] clients = NetworkHelper.GetConnectedClientsSafe();
List<ServerClient> clientsToGet = new List<ServerClient>();

foreach (ServerClient client in clients)
{
if (factionFile.CurrentMembers.Contains(client.userFile.Uid)) clientsToGet.Add(client);
if (factionFile.CurrentUids.Contains(client.userFile.Uid)) clientsToGet.Add(client);
}

foreach (ServerClient client in clientsToGet)
{
for (int i = 0; i < factionFile.CurrentMembers.Count(); i++)
for (int i = 0; i < factionFile.CurrentUids.Count(); i++)
{
if (client.userFile.Relationships.EnemyPlayers.Contains(factionFile.CurrentMembers[i]))
if (client.userFile.Relationships.EnemyPlayers.Contains(factionFile.CurrentUids[i]))
{
client.userFile.Relationships.EnemyPlayers.Remove(factionFile.CurrentMembers[i]);
client.userFile.Relationships.EnemyPlayers.Remove(factionFile.CurrentUids[i]);
}

else if (client.userFile.Relationships.AllyPlayers.Contains(factionFile.CurrentMembers[i]))
else if (client.userFile.Relationships.AllyPlayers.Contains(factionFile.CurrentUids[i]))
{
client.userFile.Relationships.AllyPlayers.Remove(factionFile.CurrentMembers[i]);
client.userFile.Relationships.AllyPlayers.Remove(factionFile.CurrentUids[i]);
}
}
}
Expand All @@ -181,21 +181,21 @@ public static void ClearAllFactionMemberGoodwills(FactionFile factionFile)

foreach (UserFile file in userFiles)
{
if (factionFile.CurrentMembers.Contains(file.Uid)) usersToGet.Add(file);
if (factionFile.CurrentUids.Contains(file.Uid)) usersToGet.Add(file);
}

foreach (UserFile file in usersToGet)
{
for (int i = 0; i < factionFile.CurrentMembers.Count(); i++)
for (int i = 0; i < factionFile.CurrentUids.Count(); i++)
{
if (file.Relationships.EnemyPlayers.Contains(factionFile.CurrentMembers[i]))
if (file.Relationships.EnemyPlayers.Contains(factionFile.CurrentUids[i]))
{
file.Relationships.EnemyPlayers.Remove(factionFile.CurrentMembers[i]);
file.Relationships.EnemyPlayers.Remove(factionFile.CurrentUids[i]);
}

else if (file.Relationships.AllyPlayers.Contains(factionFile.CurrentMembers[i]))
else if (file.Relationships.AllyPlayers.Contains(factionFile.CurrentUids[i]))
{
file.Relationships.AllyPlayers.Remove(factionFile.CurrentMembers[i]);
file.Relationships.AllyPlayers.Remove(factionFile.CurrentUids[i]);
}
}

Expand Down
Loading

0 comments on commit 35a79fb

Please sign in to comment.