Frame/Assets/Scripts/Dinosaurs/Room/RoomData.cs

90 lines
2.1 KiB
C#

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<IPlayer, float> playersDic;
public float jinBeiCount => this.jinBeiCountCache;
public IReadOnlyList<IPlayer> players => this.playersDic.Keys.ToList();
public Action<float> jinBeiCallback;
public RoomData(RoomType roomType) // , Vector2 down, Vector2 up
{
this.roomType = roomType;
this.playersDic = new Dictionary<IPlayer, float>();
}
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<IPlayer, float> 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,
,
,
,
,
殿,
,
,
,
}
}