using System.Collections.Generic; namespace ColdMint.scripts.camp; /// /// Camp manager /// 阵营管理器 /// public static class CampManager { private static readonly Dictionary Camps = new Dictionary(); /// /// The default camp is returned if no corresponding camp is obtained /// 当获取不到对应的阵营时,返回的默认阵营 /// private static Camp? _defaultCamp; /// /// SetDefaultCamp /// 设置默认阵营 /// /// ///Camp, whose ID must be the default camp ID. ///阵营,要求其ID必须为默认阵营ID。 /// /// ///Return whether the setting is successful ///返回是否设置成功 /// public static bool SetDefaultCamp(Camp? camp) { if (camp == null) { return false; } if (camp.Id != Config.CampId.Default) return false; _defaultCamp = camp; AddCamp(camp); return true; } /// /// Whether camp A can damage camp B /// 阵营A是否可伤害阵营B /// /// /// /// public static bool CanCauseHarm(Camp? attacker, Camp? target) { if (attacker == null || target == null) { return false; } if (attacker.Id == target.Id) { //In the same camp, return whether friendly fire is allowed //在同一阵营内,返回是否允许友伤 return attacker.FriendInjury; } //A camp ID that the attacker considers friendly //攻击者认为友好的阵营ID var friendlyCampIdArray = attacker.FriendlyCampIdArray; var targetId = target.Id; if (friendlyCampIdArray.Length > 0) { foreach (var friendlyCampId in friendlyCampIdArray) { if (friendlyCampId == targetId) { //The attacker thinks the target is friendly, and we can't hurt a friendly target //攻击者认为目标友好,我们不能伤害友好的目标 return false; } } } return true; } /// /// Add camp /// 添加阵营 /// /// /// public static bool AddCamp(Camp? camp) { return camp != null && Camps.TryAdd(camp.Id, camp); } /// /// Get camp based on ID /// 根据ID获取阵营 /// /// ///Cannot get back to default camp ///获取不到返回默认阵营 /// /// ///Camp ID ///阵营ID /// /// public static Camp? GetCamp(string? id) { if (id == null) { return _defaultCamp; } return Camps.GetValueOrDefault(id, _defaultCamp); } }