using System; using System.Collections.Generic; using System.Linq; using Game.Player; using Sirenix.OdinInspector; namespace Game.Room { [System.Serializable] public class RoomData { private float jinBeiCountCache; public RoomType roomType { get; } private Dictionary playersDic; public float jinBeiCount => this.jinBeiCountCache; public IReadOnlyList players => this.playersDic.Keys.ToList(); public Action jinBeiCallback; public RoomData(RoomType roomType) // , Vector2 down, Vector2 up { this.roomType = roomType; this.playersDic = new Dictionary(); } public void AddPlayer(IPlayer player) { this.playersDic.Add(player, 0); } public float RemovePlayer(IPlayer player) { if (this.playersDic.TryGetValue(player, out var value)) { UpdateJinBei(-value); this.playersDic.Remove(player); } return value; } public bool AddJinBei(IPlayer player, float jinBei) { if (this.playersDic.TryGetValue(player, out var value)) { value += jinBei; this.playersDic[player] = value; UpdateJinBei(jinBei); return true; } return false; } public Dictionary ReturnPlayerAndJinBei() { return this.playersDic; } public void Reset() { this.jinBeiCountCache = 0; UpdateJinBei(0); this.playersDic.Clear(); } void UpdateJinBei(float f) { this.jinBeiCountCache += f; this.jinBeiCallback?.Invoke(this.jinBeiCountCache); } } public enum RoomType { 出生点 = 0, 伏龙阁, 杂物室, 沙慕龙阁, 圣龙残骸, 英雄圣殿, 先祖大厅, 天池遗址, 训练堂, } }