Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from TheIdealShipAU/develop
Browse files Browse the repository at this point in the history
更新到0.3.3
  • Loading branch information
TianMengLucky authored Jan 26, 2023
2 parents 33ba85e + af4eff6 commit 292db7b
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 127 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/Release Action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ jobs:
- name: uzip
run: unzip TheIdealShip.zip


- uses: ncipollo/release-action@v1
with:
tag: v0.3.2 测试
tag: v0.3.3
bodyFile: "TheIdealShip.dll"
2 changes: 2 additions & 0 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: dotnet-build

on:
pull_request:
paths:
- '**.yml'
branches: [ "main" ]

jobs:
Expand Down
2 changes: 1 addition & 1 deletion TheIdealShip/Patches/EmergencyMinigamePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void Postfix(EmergencyMinigame __instance)
string statusText = "";

var player = CachedPlayer.LocalPlayer.PlayerControl;
var info = RoleInfo.GetRoleInfo(player);
var info = RoleHelpers.GetRoleInfo(player);
var id = info.roleId;

if (id == RoleId.Jester)
Expand Down
4 changes: 2 additions & 2 deletions TheIdealShip/Patches/ExileControllPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class ExileControllerBeginPatch
public static void Postfix(ExileController __instance, [HarmonyArgument(0)] ref GameData.PlayerInfo exiled, [HarmonyArgument(1)] bool tie)
{
var player = Helpers.GetPlayerForId(exiled.PlayerId);
var info = RoleInfo.GetRoleInfo(player);
var info = RoleHelpers.GetRoleInfo(player);
var eText = "\n" + string.Format(GetString("exileText"),exiled.PlayerName,info.name);
if (CustomOptionHolder.showExilePlayerConcreteRoleTeam.getBool())
{
eText += "\n" + string.Format(GetString("exileTeamText"),RoleInfo.GetRoleTeam(player));
eText += "\n" + string.Format(GetString("exileTeamText"),RoleHelpers.GetRoleTeam(player));
}
if (__instance.ImpostorText.text != null)
{
Expand Down
8 changes: 4 additions & 4 deletions TheIdealShip/Patches/HudPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class TaskPanelBehaviourPatch
public static void Postfix(TaskPanelBehaviour __instance)
{
var LPlayer = CachedPlayer.LocalPlayer.PlayerControl;
var roleInfo = RoleInfo.GetRoleInfo(LPlayer, false);
var modifierInfo = RoleInfo.GetRoleInfo(LPlayer, true);
var roleInfo = RoleHelpers.GetRoleInfo(LPlayer, false);
var modifierInfo = RoleHelpers.GetRoleInfo(LPlayer, true);
string roleText = "";
string modifierText = "";
if (roleInfo != null) roleText = Helpers.cs(roleInfo.color, GetString("Roles") + ":" + RoleInfo.GetRolesString(LPlayer, false) + "\n"+ roleInfo.TaskText +"\n");
if (modifierInfo != null) modifierText = Helpers.cs(modifierInfo.color, GetString("Modifiers") + ":" + RoleInfo.GetRolesString(LPlayer, false, true) + "\n" + modifierInfo.TaskText + "\n");
if (roleInfo != null) roleText = Helpers.cs(roleInfo.color, GetString("Roles") + ":" + RoleHelpers.GetRolesString(LPlayer, false) + "\n"+ roleInfo.TaskText +"\n");
if (modifierInfo != null) modifierText = Helpers.cs(modifierInfo.color, GetString("Modifiers") + ":" + RoleHelpers.GetRolesString(LPlayer, false, true) + "\n" + modifierInfo.TaskText + "\n");
__instance.taskText.text = roleText + modifierText + "\n" + __instance.taskText.text;
// __instance.taskText.text.Select(x => roleText + modifierText + ((roleInfo == null)&&(modifierInfo == null) ? "" : "\n") + x);
}
Expand Down
6 changes: 3 additions & 3 deletions TheIdealShip/Patches/IntroPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static void SetRoleTexts(IntroCutscene __instance)
{
var LocalP = CachedPlayer.LocalPlayer.PlayerControl;
// 获取本地玩家角色信息
RoleInfo roleInfo = RoleInfo.GetRoleInfo(LocalP, false);
RoleInfo modifierInfo = RoleInfo.GetRoleInfo(LocalP, true);
RoleInfo roleInfo = RoleHelpers.GetRoleInfo(LocalP, false);
RoleInfo modifierInfo = RoleHelpers.GetRoleInfo(LocalP, true);
if (roleInfo != null)
{
__instance.YouAreText.color = roleInfo.color;
Expand Down Expand Up @@ -46,7 +46,7 @@ class ShowTeamPatch
public static void setRoleTeamText(IntroCutscene __instance)
{
var LocalP = CachedPlayer.LocalPlayer.PlayerControl;
var teamText = RoleInfo.GetRoleTeam(LocalP);
var teamText = RoleHelpers.GetRoleTeam(LocalP);
__instance.TeamTitle.text = teamText;
}
public static bool Prefix(IntroCutscene __instance)
Expand Down
10 changes: 5 additions & 5 deletions TheIdealShip/Patches/MainUIPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ public static void Start_Prefix(MainMenuManager __instance)
DiscordButtonSprite.color = DiscordText.color = DiscordColor;
DiscordButton.gameObject.SetActive(true);

// 生成Kook按钮
// 生成Kook按钮 改为QQ频道
if (kookButton == null) kookButton = UnityEngine.Object.Instantiate(Template,Template.transform.parent);
kookButton.name = "KooKButton";
kookButton.name = "QQButton";
kookButton.transform.position = DiscordButton.transform.position + new Vector3(0, 0.65f);

var kookText = kookButton.transform.GetChild(0).GetComponent<TMPro.TMP_Text>();
Color kookColor = new Color32(122, 204, 53, byte.MaxValue);
Color kookColor = new Color32(187, 255, 255, byte.MaxValue);
PassiveButton kookPassiveButton = kookButton.GetComponent<PassiveButton>();
SpriteRenderer kookButtonSprite = kookButton.GetComponent<SpriteRenderer>();
kookPassiveButton.OnClick = new();
kookPassiveButton.OnClick.AddListener((Action)(() => Application.OpenURL(TheIdealShipPlugin.KOOKURL)));
kookPassiveButton.OnClick.AddListener((Action)(() => Application.OpenURL(TheIdealShipPlugin.QQURL)));
kookPassiveButton.OnMouseOut.AddListener((Action)(() => kookButtonSprite.color = kookText.color = kookColor));
__instance.StartCoroutine(Effects.Lerp(0.01f, new Action<float>((p) => kookText.SetText("KooK"))));
__instance.StartCoroutine(Effects.Lerp(0.01f, new Action<float>((p) => kookText.SetText("QQ频道"))));
kookButtonSprite.color = kookText.color = kookColor;
kookButton.gameObject.SetActive(true);

Expand Down
2 changes: 1 addition & 1 deletion TheIdealShip/Patches/PlayerControlPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void updatePlayerInfo()
playerInfo.color = playerInfo.color.SetAlpha(1f);
}

string roleNames = RoleInfo.GetRolesString(p, true);
string roleNames = RoleHelpers.GetRolesString(p, true);

string playerInfoText = "";
if (p == CachedPlayer.LocalPlayer.PlayerControl || p.isDummy)
Expand Down
63 changes: 4 additions & 59 deletions TheIdealShip/Patches/RoleAssignmentPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,7 @@ private enum RoleType
Neutral = 1,
Impostor = 2
}
public class RoleAssignmentData
{
public List<PlayerControl> crewmates { get; set; }
public List<PlayerControl> impostors { get; set; }
public Dictionary<byte, int> impSettings = new Dictionary<byte, int>();
public Dictionary<byte, int> neutralSettings = new Dictionary<byte, int>();
public Dictionary<byte, int> crewSettings = new Dictionary<byte, int>();
public int maxCrewmateRoles { get; set; }
public int maxNeutralRoles { get; set; }
public int maxImpostorRoles { get; set; }
}

private static int crewValues;
private static int impValues;
private static List<Tuple<byte, byte>> playerRoleMap = new List<Tuple<byte, byte>>();
Expand All @@ -60,58 +50,13 @@ private static void assignRoles()
// selectFactionForFactionIndependentRoles(data);
assignEnsuredRoles(data); // Assign roles that should always be in the game next
// assignDependentRoles(data); // Assign roles that may have a dependent role
// assignChanceRoles(data); // Assign roles that may or may not be in the game last
assignChanceRoles(data); // Assign roles that may or may not be in the game last
// assignRoleTargets(data); // Assign targets for Lawyer & Prosecutor
assignModifiers(); // Assign modifier
setRolesAgain();
}

public static RoleAssignmentData GetRoleAssignmentData()
{
List<PlayerControl> crewmates = PlayerControl.AllPlayerControls.ToArray().ToList().OrderBy(x => Guid.NewGuid()).ToList();
crewmates.RemoveAll(x => x.Data.Role.IsImpostor);
List<PlayerControl> impostors = PlayerControl.AllPlayerControls.ToArray().ToList().OrderBy(x => Guid.NewGuid()).ToList();
impostors.RemoveAll(x => !x.Data.Role.IsImpostor);

var crewmateMin = CustomOptionHolder.crewmateRolesCountMin.getSelection();
var crewmateMax = CustomOptionHolder.crewmateRolesCountMax.getSelection();
var neutralMin = CustomOptionHolder.neutralRolesCountMin.getSelection();
var neutralMax = CustomOptionHolder.neutralRolesCountMax.getSelection();
var impostorMin = CustomOptionHolder.impostorRolesCountMin.getSelection();
var impostorMax = CustomOptionHolder.impostorRolesCountMax.getSelection();

if (crewmateMin > crewmateMax) crewmateMin = crewmateMax;
if (neutralMin > neutralMax) neutralMin = neutralMax;
if (impostorMin > impostorMax) impostorMin = impostorMax;

int crewCountSettings = rnd.Next(crewmateMin, crewmateMax + 1);
int neutralCountSettings = rnd.Next(neutralMin, neutralMax + 1);
int impCountSettings = rnd.Next(impostorMin, impostorMax + 1);

int maxCrewmateRoles = Mathf.Min(crewmates.Count, crewCountSettings);
int maxNeutralRoles = Mathf.Min(crewmates.Count, neutralCountSettings);
int maxImpostorRoles = Mathf.Min(impostors.Count, impCountSettings);

Dictionary<byte, int> impSettings = new Dictionary<byte, int>();
Dictionary<byte, int> neutralSettings = new Dictionary<byte, int>();
Dictionary<byte, int> crewSettings = new Dictionary<byte, int>();

crewSettings.Add((byte)RoleId.Sheriff, CustomOptionHolder.sheriffSpawnRate.getSelection());

return new RoleAssignmentData
{
crewmates = crewmates,
impostors = impostors,
crewSettings = crewSettings,
neutralSettings = neutralSettings,
impSettings = impSettings,
maxCrewmateRoles = maxCrewmateRoles,
maxNeutralRoles = maxNeutralRoles,
maxImpostorRoles = maxImpostorRoles
};
}

private static void assignEnsuredRoles (RoleAssignmentData data)
private static void assignEnsuredRoles (Roles.RoleAssignmentData data)
{
List<byte> ensuredCrewmateRoles = data.crewSettings.Where(x => x.Value == 10).Select(x => x.Key).ToList();
List<byte> ensuredNeutralRoles = data.neutralSettings.Where(x => x.Value == 10).Select(x => x.Key).ToList();
Expand Down Expand Up @@ -189,7 +134,7 @@ private static void assignEnsuredRoles (RoleAssignmentData data)
}
}

private static void assignChanceRoles(RoleAssignmentData data)
private static void assignChanceRoles(Roles.RoleAssignmentData data)
{
// Get all roles where the chance to occur is set grater than 0% but not 100% and build a ticket pool based on their weight
List<byte> crewmateTickets = data.crewSettings.Where(x => x.Value > 0 && x.Value < 10).Select(x => Enumerable.Repeat(x.Key, x.Value)).SelectMany(x => x).ToList();
Expand Down
2 changes: 1 addition & 1 deletion TheIdealShip/Patches/UpdatePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void setPlayerNameColor(PlayerControl p,Color color)
static void SetNameColors()
{
var localPlayer = CachedPlayer.LocalPlayer.PlayerControl;
var localRoleInfo = RoleInfo.GetRoleInfo(localPlayer, false);
var localRoleInfo = RoleHelpers.GetRoleInfo(localPlayer, false);
setPlayerNameColor(localPlayer, localRoleInfo.color);
// if (localPlayer == Sheriff.sheriff)
// setPlayerNameColor(localPlayer, RoleInfo.sheriff.color);
Expand Down
2 changes: 1 addition & 1 deletion TheIdealShip/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void RestoreRole(byte id)
public static void ChangeRole(byte playerId, byte targetRoleId)
{
var player = Helpers.GetPlayerForId(playerId);
var info = RoleInfo.GetRoleInfo(player);
var info = RoleHelpers.GetRoleInfo(player);
RestoreRole((byte)info.roleId);
setRole(targetRoleId, playerId);
}
Expand Down
64 changes: 63 additions & 1 deletion TheIdealShip/Roles/Role.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using HarmonyLib;
using UnityEngine;
using System;
using System.Linq;
using System.Collections.Generic;

namespace TheIdealShip.Roles
{
Expand All @@ -18,9 +21,68 @@ public static void clearAndReloadRoles()
// Modifier 附加职业
Flash.clearAndReload();
}

public static RoleAssignmentData GetRoleAssignmentData()
{
List<PlayerControl> crewmates = PlayerControl.AllPlayerControls.ToArray().ToList().OrderBy(x => Guid.NewGuid()).ToList();
crewmates.RemoveAll(x => x.Data.Role.IsImpostor);
List<PlayerControl> impostors = PlayerControl.AllPlayerControls.ToArray().ToList().OrderBy(x => Guid.NewGuid()).ToList();
impostors.RemoveAll(x => !x.Data.Role.IsImpostor);

var crewmateMin = CustomOptionHolder.crewmateRolesCountMin.getSelection();
var crewmateMax = CustomOptionHolder.crewmateRolesCountMax.getSelection();
var neutralMin = CustomOptionHolder.neutralRolesCountMin.getSelection();
var neutralMax = CustomOptionHolder.neutralRolesCountMax.getSelection();
var impostorMin = CustomOptionHolder.impostorRolesCountMin.getSelection();
var impostorMax = CustomOptionHolder.impostorRolesCountMax.getSelection();

if (crewmateMin > crewmateMax) crewmateMin = crewmateMax;
if (neutralMin > neutralMax) neutralMin = neutralMax;
if (impostorMin > impostorMax) impostorMin = impostorMax;

int crewCountSettings = rnd.Next(crewmateMin, crewmateMax + 1);
int neutralCountSettings = rnd.Next(neutralMin, neutralMax + 1);
int impCountSettings = rnd.Next(impostorMin, impostorMax + 1);

int maxCrewmateRoles = Mathf.Min(crewmates.Count, crewCountSettings);
int maxNeutralRoles = Mathf.Min(crewmates.Count, neutralCountSettings);
int maxImpostorRoles = Mathf.Min(impostors.Count, impCountSettings);

Dictionary<byte, int> impSettings = new Dictionary<byte, int>();
Dictionary<byte, int> neutralSettings = new Dictionary<byte, int>();
Dictionary<byte, int> crewSettings = new Dictionary<byte, int>();

crewSettings.Add((byte)RoleId.Sheriff, CustomOptionHolder.sheriffSpawnRate.getSelection());

neutralSettings.Add((byte)RoleId.Jester, CustomOptionHolder.jesterSpawnRate.getSelection());

return new RoleAssignmentData
{
crewmates = crewmates,
impostors = impostors,
crewSettings = crewSettings,
neutralSettings = neutralSettings,
impSettings = impSettings,
maxCrewmateRoles = maxCrewmateRoles,
maxNeutralRoles = maxNeutralRoles,
maxImpostorRoles = maxImpostorRoles
};
}
}

public class RoleAssignmentData
{
public List<PlayerControl> crewmates { get; set; }
public List<PlayerControl> impostors { get; set; }
public Dictionary<byte, int> impSettings = new Dictionary<byte, int>();
public Dictionary<byte, int> neutralSettings = new Dictionary<byte, int>();
public Dictionary<byte, int> crewSettings = new Dictionary<byte, int>();
public int maxCrewmateRoles { get; set; }
public int maxNeutralRoles { get; set; }
public int maxImpostorRoles { get; set; }
}

enum RoleId
public enum RoleId
{
// Crewmate 船员
Crewmate,
Expand Down
71 changes: 71 additions & 0 deletions TheIdealShip/Roles/RoleHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Xml.Schema;
using System;
using System.Linq;
using System.Collections.Generic;
using static TheIdealShip.Languages.Language;
using static TheIdealShip.Roles.RoleInfo;
using RoleTeam = TheIdealShip.Roles.RoleInfo.RoleTeam;

namespace TheIdealShip.Roles
{
public static class RoleHelpers
{
public static RoleInfo GetRoleInfo(PlayerControl player, bool isModifier = false)
{
var info = getRoleInfoForPlayer(player, isModifier, false).FirstOrDefault();
return info;
}
public static string GetRoleTeam(PlayerControl p)
{
string roleTeam;
string cre = GetString("Crewmate");
string imp = GetString("Impostor");
string neu = GetString("Neutral");
var info = GetRoleInfo(p);
switch (info.team)
{
case RoleTeam.Crewmate:
roleTeam = cre;
break;

case RoleTeam.Impostor:
roleTeam = imp;
break;

case RoleTeam.Neutral:
roleTeam = neu;
break;

default:
roleTeam = "";
break;
}
return roleTeam;
}

public static bool Is(this PlayerControl player, RoleId id)
{
var info = GetRoleInfo(player);
return id == info.roleId;
}

public static bool Is(this PlayerControl player, RoleTeam team)
{
var info = GetRoleInfo(player);
return team == info.team;
}

public static bool Is(this RoleId id, RoleType type)
{
var info = allRoleInfos.Where(x => x.roleId == id).FirstOrDefault();
return info.type == type;
}

public static String GetRolesString(PlayerControl p, bool useColors = true, bool isModifier = false)
{
string roleName;
roleName = String.Join("", getRoleInfoForPlayer(p, isModifier).Select(x => useColors ? Helpers.cs(x.color, GetString(x.namekey)) : GetString(x.namekey)).ToArray());
return roleName;
}
}
}
Loading

0 comments on commit 292db7b

Please sign in to comment.