supervisor-simulator/scripts/Player.cs

130 lines
3.7 KiB
C#

using Godot;
using System;
using System.Collections.Generic;
public partial class Player : Node
{
/// <summary>
/// 预算类型,用于记录项目预算的不同类别费用。
/// </summary>
public class BudgetType
{
/// <summary>
/// 设备费:用于购买设备,升级实验室是指在项目实施过程中购置或试制专用仪
/// 器设备,对现有仪器设备进行升级改造,以及租赁外单位仪器设备而发生的费
/// 用。计算类仪器设备和软件工具可在设备费科目列支。应当严格控制设备购
/// 置,鼓励开放共享、自主研制、租赁专用仪器设备以及对现有仪器设备进行升
/// 级改造,避免重复购置。
/// </summary>
public int Facility { get; set; }
/// <summary>
/// 业务费:是指项目实施过程中消耗的各种材料、辅助材料等低值易耗品的采
/// 购、运输、装卸、整理等费用,发生的测试化验加工、燃料动力、出版/文献/
/// 信息传播/知识产权事务、会议/差旅/国际合作交流等费用,以及其他相关支
/// 出。
/// </summary>
public int Operational { get; set; }
/// <summary>
///劳务费:是指在项目实施过程中支付给参与项目研究的研究生、博士后、访问学
///者以及项目聘用的研究人员、科研辅助人员等的劳务性费用,以及支付给临时聘
///请的咨询专家的费用等。
///</summary>
public int Labor { get; set; }
/// <summary>
/// 总预算
/// </summary>
public int Total => Facility + Operational + Labor;
}
public class TimelineType
{
public DateOnly InternalDate { get; set; }
private Dictionary<DateOnly, HashSet<Guid>> _events;
public void Subscribe(DateOnly date, Guid eventUuid)
{
_events ??= new Dictionary<DateOnly, HashSet<Guid>>();
if (!_events.ContainsKey(date)) _events[date] = new HashSet<Guid>();
_events[date].Add(eventUuid);
}
public void Unsubscribe(DateOnly date, Guid eventUuid)
{
if (_events == null) return;
if (!_events.ContainsKey(date)) return;
_events[date].Remove(eventUuid);
}
private void NextDay()
{
if (_events == null) return;
_events.Remove(InternalDate);
InternalDate = InternalDate.AddDays(1);
OnDayChanged?.Invoke(InternalDate);
GD.Print("Today is: " + InternalDate.ToString("yyyy-MM-dd"));
if (_events.ContainsKey(InternalDate))
{
var events = _events[InternalDate];
foreach (var eventUuid in events)
{
// TODO: Trigger event
OnEventTriggered?.Invoke(InternalDate, eventUuid);
GD.Print("event triggered! eventUUID: " + eventUuid.ToString());
}
}
}
public void Attach(Timer ticker)
{
ticker.Timeout += NextDay;
}
public TimelineType(DateOnly startDate)
{
InternalDate = startDate;
}
public delegate void EventTriggeredEventHandler(DateOnly date, Guid eventUuid);
public event EventTriggeredEventHandler OnEventTriggered;
public delegate void DayChangedEventHandler(DateOnly date);
public event DayChangedEventHandler OnDayChanged;
}
public static BudgetType Budget { get; set; } = new();
public static readonly TimelineType Timeline = new(DateOnly.Parse("2024/11/17"));
/// <summary>
/// 名字
/// </summary>
public static string PlayerName { get; set; }
/// <summary>
/// 年龄
/// </summary>
public static uint Age { get; set; }
/// <summary>
/// 日期
/// </summary>
public static DateOnly Date { get; set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}