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

70 lines
1.6 KiB
C#
Raw Normal View History

2024-04-10 16:18:32 +08:00
using System;
using System.Collections.Generic;
2024-04-06 11:59:18 +08:00
using Game.Player;
namespace Game.Room
2024-04-03 17:46:56 +08:00
{
2024-04-10 16:18:32 +08:00
[System.Serializable]
2024-04-03 17:46:56 +08:00
public class RoomData
{
2024-04-10 16:18:32 +08:00
private float jinBeiCountCache;
2024-05-05 17:02:33 +08:00
private List<IPlayer> _players;
2024-04-10 16:18:32 +08:00
public float jinBeiCount => this.jinBeiCountCache;
2024-05-05 17:02:33 +08:00
public IReadOnlyList<IPlayer> players => _players;
public RoomType roomType { get; }
2024-04-10 16:18:32 +08:00
public Action<float> jinBeiCallback;
2024-04-06 11:59:18 +08:00
2024-05-05 17:02:33 +08:00
public RoomData(RoomType roomType, float jinBei) // , Vector2 down, Vector2 up
2024-04-06 11:59:18 +08:00
{
2024-05-05 17:02:33 +08:00
this.jinBeiCountCache = jinBei;
2024-04-06 11:59:18 +08:00
this.roomType = roomType;
2024-05-05 17:02:33 +08:00
_players = new List<IPlayer>();
2024-04-06 11:59:18 +08:00
}
2024-04-09 18:16:37 +08:00
public void AddPlayer(IPlayer player)
{
2024-05-05 17:02:33 +08:00
this._players.Add(player);
2024-04-09 18:16:37 +08:00
}
2024-05-05 17:02:33 +08:00
public void RemovePlayer(IPlayer player)
2024-04-09 18:16:37 +08:00
{
2024-05-05 17:02:33 +08:00
if (this._players.Contains(player))
_players.Remove(player);
2024-04-10 16:18:32 +08:00
}
2024-05-05 17:02:33 +08:00
public bool RefreshMoney(float jinBei)
2024-04-10 16:18:32 +08:00
{
2024-05-05 17:02:33 +08:00
jinBeiCountCache = jinBei;
UpdateJinBei();
2024-04-10 16:18:32 +08:00
return false;
2024-04-09 18:16:37 +08:00
}
2024-04-10 16:18:32 +08:00
public void Reset()
{
this.jinBeiCountCache = 0;
2024-05-05 17:02:33 +08:00
UpdateJinBei();
this._players.Clear();
2024-04-10 16:18:32 +08:00
}
2024-05-05 17:02:33 +08:00
void UpdateJinBei()
2024-04-10 16:18:32 +08:00
{
this.jinBeiCallback?.Invoke(this.jinBeiCountCache);
}
2024-04-06 11:59:18 +08:00
}
public enum RoomType
{
= 0,
,
,
,
,
殿,
,
,
,
2024-04-03 17:46:56 +08:00
}
}