mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 05:27:13 +08:00
(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Linq; // 用于 LINQ 查询
|
||||
using System.Linq;
|
||||
|
||||
// 用于 LINQ 查询
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class ConditionalEvent : Define
|
||||
{
|
||||
public string parameter;
|
||||
public EventDef[] eventDefs;
|
||||
public EventDef[] eventDefs;
|
||||
public string parameter;
|
||||
}
|
||||
|
||||
// 实体事件类型枚举
|
||||
public enum EntityEventType
|
||||
{
|
||||
@@ -20,27 +23,26 @@ namespace Data
|
||||
OnMeleeAttack,
|
||||
OnRangedAttack,
|
||||
OnHit,
|
||||
OnDeath,
|
||||
OnDeath
|
||||
}
|
||||
|
||||
public class EntityEventDef : Define
|
||||
{
|
||||
public EventDef[] onSpawnEvents; // 生成时触发的事件
|
||||
public EventDef[] onMoveForwardEvents; // 向前移动时触发的事件
|
||||
public EventDef[] onMoveBackwardEvents; // 向后移动时触发的事件
|
||||
public EventDef[] onMoveLeftEvents; // 向左移动时触发的事件
|
||||
public EventDef[] onMoveRightEvents; // 向右移动时触发的事件
|
||||
public EventDef[] onMeleeAttackEvents; // 近战攻击时触发的事件
|
||||
public EventDef[] onRangedAttackEvents; // 远程攻击时触发的事件
|
||||
public EventDef[] onHitEvents; // 受击时触发的事件
|
||||
public EventDef[] onDeathEvents; // 死亡时触发的事件
|
||||
|
||||
public ConditionalEvent[] conditionalEvents; // 由和行为树相同的条件回调
|
||||
public EventDef[] onDeathEvents; // 死亡时触发的事件
|
||||
public EventDef[] onHitEvents; // 受击时触发的事件
|
||||
public EventDef[] onMeleeAttackEvents; // 近战攻击时触发的事件
|
||||
public EventDef[] onMoveBackwardEvents; // 向后移动时触发的事件
|
||||
public EventDef[] onMoveForwardEvents; // 向前移动时触发的事件
|
||||
public EventDef[] onMoveLeftEvents; // 向左移动时触发的事件
|
||||
public EventDef[] onMoveRightEvents; // 向右移动时触发的事件
|
||||
public EventDef[] onRangedAttackEvents; // 远程攻击时触发的事件
|
||||
public EventDef[] onSpawnEvents; // 生成时触发的事件
|
||||
|
||||
// =============== 查询函数 ===============
|
||||
|
||||
/// <summary>
|
||||
/// 获取特定事件类型下的所有事件定义。
|
||||
/// 获取特定事件类型下的所有事件定义。
|
||||
/// </summary>
|
||||
/// <param name="eventType">要查询的实体事件类型。</param>
|
||||
/// <returns>对应事件类型下的 EventDef 数组,如果不存在则返回空数组或 null (取决于设计)。</returns>
|
||||
@@ -72,7 +74,7 @@ namespace Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有条件事件定义。
|
||||
/// 获取所有条件事件定义。
|
||||
/// </summary>
|
||||
/// <returns>ConditionalEvent 数组,如果不存在则返回空数组。</returns>
|
||||
public ConditionalEvent[] GetAllConditionalEvents()
|
||||
@@ -81,31 +83,25 @@ namespace Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件参数获取特定的 ConditionalEvent。
|
||||
/// 根据条件参数获取特定的 ConditionalEvent。
|
||||
/// </summary>
|
||||
/// <param name="parameterName">条件参数的字符串名称。</param>
|
||||
/// <returns>匹配的 ConditionalEvent,如果未找到则返回 null。</returns>
|
||||
public ConditionalEvent GetConditionalEventByParameter(string parameterName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName) || conditionalEvents == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrEmpty(parameterName) || conditionalEvents == null) return null;
|
||||
return conditionalEvents.FirstOrDefault(ce => ce.parameter == parameterName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有事件中(包括通用和条件事件)是否存在特定 EventId 的事件。
|
||||
/// 这个查询可能比较耗时,取决于事件数量。
|
||||
/// 查询所有事件中(包括通用和条件事件)是否存在特定 EventId 的事件。
|
||||
/// 这个查询可能比较耗时,取决于事件数量。
|
||||
/// </summary>
|
||||
/// <param name="eventId">要查询的 EventDef 的 EventId。</param>
|
||||
/// <returns>如果找到,则返回第一个匹配的 EventDef,否则返回 null。</returns>
|
||||
public EventDef FindEventDefById(string eventId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(eventId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrEmpty(eventId)) return null;
|
||||
|
||||
// 查询通用事件
|
||||
foreach (EntityEventType type in Enum.GetValues(typeof(EntityEventType)))
|
||||
@@ -115,34 +111,25 @@ namespace Data
|
||||
if (events != null)
|
||||
{
|
||||
var foundEvent = events.Where(e => e != null).FirstOrDefault(e => e.defName == eventId);
|
||||
if (foundEvent != null)
|
||||
{
|
||||
return foundEvent;
|
||||
}
|
||||
if (foundEvent != null) return foundEvent;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询条件事件
|
||||
if (conditionalEvents != null)
|
||||
{
|
||||
foreach (var condEvent in conditionalEvents)
|
||||
{
|
||||
if (condEvent?.eventDefs != null)
|
||||
{
|
||||
var foundEvent = condEvent.eventDefs.Where(e => e != null).FirstOrDefault(e => e.defName == eventId);
|
||||
if (foundEvent != null)
|
||||
{
|
||||
return foundEvent;
|
||||
}
|
||||
var foundEvent = condEvent.eventDefs.Where(e => e != null)
|
||||
.FirstOrDefault(e => e.defName == eventId);
|
||||
if (foundEvent != null) return foundEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取属于特定事件类型下,并且描述包含特定关键字的所有事件。
|
||||
/// 获取属于特定事件类型下,并且描述包含特定关键字的所有事件。
|
||||
/// </summary>
|
||||
/// <param name="eventType">要查询的事件类型。</param>
|
||||
/// <param name="keyword">描述中需要包含的关键字。</param>
|
||||
@@ -150,12 +137,12 @@ namespace Data
|
||||
public EventDef[] GetEventsByTypeAndDescriptionKeyword(EntityEventType eventType, string keyword)
|
||||
{
|
||||
var events = GetEventsByType(eventType);
|
||||
if (events == null || string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
return Array.Empty<EventDef>();
|
||||
}
|
||||
if (events == null || string.IsNullOrEmpty(keyword)) return Array.Empty<EventDef>();
|
||||
|
||||
return events.Where(e => e is { description: not null } && e.description.Contains(keyword, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
return events.Where(e =>
|
||||
e is { description: not null } &&
|
||||
e.description.Contains(keyword, StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user