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

90 lines
2.1 KiB
C#
Raw Normal View History

2024-04-10 16:18:32 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2024-04-06 11:59:18 +08:00
using Game.Player;
2024-04-10 16:18:32 +08:00
using Sirenix.OdinInspector;
2024-04-06 11:59:18 +08:00
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;
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;
2024-04-06 11:59:18 +08:00
public RoomData(RoomType roomType) // , Vector2 down, Vector2 up
{
this.roomType = roomType;
2024-04-10 16:18:32 +08:00
this.playersDic = new Dictionary<IPlayer, float>();
2024-04-06 11:59:18 +08:00
}
2024-04-09 18:16:37 +08:00
public void AddPlayer(IPlayer player)
{
2024-04-10 16:18:32 +08:00
this.playersDic.Add(player, 0);
2024-04-09 18:16:37 +08:00
}
2024-04-11 14:44:39 +08:00
public float RemovePlayer(IPlayer player)
2024-04-09 18:16:37 +08:00
{
2024-04-10 16:18:32 +08:00
if (this.playersDic.TryGetValue(player, out var value))
{
UpdateJinBei(-value);
this.playersDic.Remove(player);
}
2024-04-11 14:44:39 +08:00
return value;
2024-04-10 16:18:32 +08:00
}
public bool AddJinBei(IPlayer player, float jinBei)
{
if (this.playersDic.TryGetValue(player, out var value))
{
value += jinBei;
this.playersDic[player] = value;
2024-04-10 16:18:32 +08:00
UpdateJinBei(jinBei);
return true;
}
return false;
2024-04-09 18:16:37 +08:00
}
2024-04-10 16:18:32 +08:00
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);
}
2024-04-06 11:59:18 +08:00
}
public enum RoomType
{
= 0,
,
,
,
,
殿,
,
,
,
2024-04-03 17:46:56 +08:00
}
}