using System.Collections.Generic; using ColdMint.scripts.debug; 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) { LogCat.Log("camp_is_null", label: LogCat.LogLabel.CampManager); return false; } if (camp.Id != Config.CampId.Default) return false; _defaultCamp = camp; AddCamp(camp); LogCat.LogWithFormat("set_default_camp", label: LogCat.LogLabel.CampManager, LogCat.UploadFormat, camp.Id); return true; } /// /// Whether camp A can damage camp B /// 阵营A是否可伤害阵营B /// /// /// /// public static bool CanCauseHarm(Camp? attacker, Camp? target) { if (attacker == null || target == null) { LogCat.Log("attacker_or_target_is_null", label: LogCat.LogLabel.CampManager); return false; } if (attacker.Id == target.Id) { //In the same camp, return whether friendly fire is allowed //在同一阵营内,返回是否允许友伤 LogCat.Log("in_the_same_camp", label: LogCat.LogLabel.CampManager); 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 //攻击者认为目标友好,我们不能伤害友好的目标 LogCat.Log("friendly_target", label: LogCat.LogLabel.CampManager); return false; } } } LogCat.Log("can_cause_harm", label: LogCat.LogLabel.CampManager); 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); } }